mirror of
https://github.com/status-im/snorenotify.git
synced 2025-01-10 00:25:43 +00:00
improved code
This commit is contained in:
parent
8961a58a94
commit
2370fd47cc
@ -5,7 +5,6 @@ set ( SnoreNotify_SRCS ${SnoreNotify_SRCS}
|
||||
snoreserver.cpp
|
||||
application.cpp
|
||||
interface.cpp
|
||||
utils.cpp
|
||||
trayiconnotifer.cpp
|
||||
)
|
||||
|
||||
@ -14,7 +13,6 @@ set ( SnoreNotify_HDR ${SnoreNotify_HDR}
|
||||
application.h
|
||||
interface.h
|
||||
snore_exports.h
|
||||
utils.h
|
||||
)
|
||||
|
||||
automoc4_add_library( snorecore SHARED ${SnoreNotify_SRCS})
|
||||
|
@ -37,9 +37,13 @@ private:
|
||||
|
||||
};
|
||||
|
||||
Q_DECLARE_INTERFACE ( SnorePlugin,
|
||||
"org.Snore.SnorePlugin/1.0" )
|
||||
|
||||
class SNORE_EXPORT Notification_Backend:public SnorePlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(SnorePlugin)
|
||||
public:
|
||||
Notification_Backend ( QString name,class SnoreServer *snore=0 );
|
||||
virtual ~Notification_Backend();
|
||||
@ -62,6 +66,7 @@ public slots:
|
||||
class SNORE_EXPORT Notification_Frontend:public SnorePlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(SnorePlugin)
|
||||
public:
|
||||
Notification_Frontend ( QString name,class SnoreServer *snore=0 );
|
||||
virtual ~Notification_Frontend();
|
||||
@ -74,8 +79,7 @@ protected:
|
||||
|
||||
|
||||
|
||||
Q_DECLARE_INTERFACE ( SnorePlugin,
|
||||
"org.Snore.SnorePlugin/1.0" )
|
||||
|
||||
Q_DECLARE_INTERFACE ( Notification_Frontend,
|
||||
"org.Snore.NotificationFrontend/1.0" )
|
||||
Q_DECLARE_INTERFACE ( Notification_Backend,
|
||||
|
@ -71,16 +71,15 @@ SnoreServer::SnoreServer ( QSystemTrayIcon *trayIcon ) :
|
||||
void SnoreServer::publicatePlugin ( const QString &fileName )
|
||||
{
|
||||
QPluginLoader loader ( fileName );
|
||||
QObject *plugin = loader.instance();
|
||||
if ( plugin==NULL )
|
||||
if ( !loader.load())
|
||||
{
|
||||
qDebug() <<"Failed loading plugin: "<<loader.errorString();
|
||||
return;
|
||||
}
|
||||
SnorePlugin *sp = dynamic_cast<SnorePlugin*> ( plugin );
|
||||
if ( sp==NULL )
|
||||
SnorePlugin *sp = qobject_cast<SnorePlugin*> ( loader.instance());
|
||||
if ( sp == NULL )
|
||||
{
|
||||
std::cerr<<"Error:"<<fileName.toLatin1().data() <<"is not a snarl plugin"<<std::endl ;
|
||||
std::cerr<<"Error:"<<fileName.toLatin1().data() <<" is not a snarl plugin"<<std::endl ;
|
||||
return;
|
||||
}
|
||||
publicatePlugin ( sp );
|
||||
@ -98,22 +97,13 @@ void SnoreServer::publicatePlugin ( SnorePlugin *plugin )
|
||||
qDebug() <<pluginName<<"is a SnorePlugin";
|
||||
plugin->setSnore ( this );
|
||||
|
||||
Notification_Frontend *nf=qobject_cast<Notification_Frontend*> ( plugin );
|
||||
if ( nf )
|
||||
{
|
||||
qDebug() <<pluginName<<"is a Notification_Frontend";
|
||||
nf->setSnore ( this );
|
||||
|
||||
}
|
||||
|
||||
Notification_Backend * nb=qobject_cast<Notification_Backend *> ( plugin );
|
||||
if ( nb )
|
||||
{
|
||||
nb->setSnore ( this );
|
||||
qDebug() <<pluginName<<"is a Notification_Backend";
|
||||
if ( nb->isPrimaryNotificationBackend() )
|
||||
{
|
||||
_primaryNotificationBackends.insert ( pluginName,nb );
|
||||
_primaryNotificationBackends.append( pluginName);
|
||||
if ( _notificationBackend == NULL )
|
||||
{
|
||||
_notificationBackend = nb;
|
||||
@ -187,21 +177,21 @@ const ApplicationsList &SnoreServer::aplications() const
|
||||
}
|
||||
|
||||
|
||||
const QHash<QString,Notification_Backend*> &SnoreServer::primaryNotificationBackends() const
|
||||
const QStringList &SnoreServer::primaryNotificationBackends() const
|
||||
{
|
||||
return _primaryNotificationBackends;
|
||||
}
|
||||
|
||||
void SnoreServer::setPrimaryNotificationBackend ( Notification_Backend *backend )
|
||||
void SnoreServer::setPrimaryNotificationBackend ( const QString &backend )
|
||||
{
|
||||
if(!backend->isPrimaryNotificationBackend())
|
||||
if(!_primaryNotificationBackends.contains(backend))
|
||||
return;
|
||||
qDebug()<<"Setting Notification Backend to:"<<backend->name();
|
||||
_notificationBackend = backend;
|
||||
qDebug()<<"Setting Notification Backend to:"<<backend;
|
||||
_notificationBackend = qobject_cast<Notification_Backend*>(plugins[backend]);
|
||||
}
|
||||
|
||||
Notification_Backend * SnoreServer::primaryNotificationBackend(){
|
||||
return _notificationBackend;
|
||||
const QString &SnoreServer::primaryNotificationBackend(){
|
||||
return _notificationBackend->name();
|
||||
}
|
||||
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "application.h"
|
||||
#include "interface.h"
|
||||
|
||||
#include <QStringList>
|
||||
|
||||
class SNORE_EXPORT SnoreServer:public QObject
|
||||
{
|
||||
@ -46,19 +47,20 @@ public:
|
||||
void removeApplication ( const QString& appName );
|
||||
const ApplicationsList &aplications() const;
|
||||
|
||||
const QHash<QString,Notification_Backend*> &primaryNotificationBackends() const;
|
||||
void setPrimaryNotificationBackend ( Notification_Backend *backend );
|
||||
Notification_Backend* primaryNotificationBackend();
|
||||
const QStringList &primaryNotificationBackends() const;
|
||||
void setPrimaryNotificationBackend ( const QString &backend );
|
||||
const QString &primaryNotificationBackend();
|
||||
|
||||
|
||||
QHash<QString,SnorePlugin*> plugins;
|
||||
|
||||
private:
|
||||
ApplicationsList _applications;
|
||||
|
||||
|
||||
QHash<QString,Notification_Backend*> _notyfier;
|
||||
QHash<QString,Notification_Backend*> _primaryNotificationBackends;
|
||||
QStringList _primaryNotificationBackends;
|
||||
Notification_Backend * _notificationBackend;
|
||||
QHash<QString,SnorePlugin*> plugins;
|
||||
|
||||
class QSystemTrayIcon *_trayIcon;
|
||||
|
||||
|
@ -1,21 +0,0 @@
|
||||
#include "utils.h"
|
||||
|
||||
Utils::Utils()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
QString Utils::notificationToSNTPString ( Notification notification )
|
||||
{
|
||||
QString out ( "type=SNP#?version=1.1" );
|
||||
if ( notification.hintExists ( "SNaction" ) )
|
||||
out+=QString ( "#?action="+notification.hint ( "SNaction" ).value<QString>() );
|
||||
if ( !notification.application().isEmpty() )
|
||||
out+=QString ( "#?app="+notification.application() );
|
||||
if ( !notification.alert().isEmpty() )
|
||||
out+=QString ( "#?class="+notification.alert() );
|
||||
if ( notification.hintExists ( "SnarlIcon" ) )
|
||||
out+=QString ( "#?icon="+notification.hint ( "SnarlIcon" ).value<QString>() );
|
||||
out+=QString ( "#?title="+notification.title() +"#?text="+notification.text() +"#?timeout="+QString::number ( notification.timeout() ) );
|
||||
return out;
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
#ifndef UTILS_H
|
||||
#define UTILS_H
|
||||
|
||||
#include "snoreserver.h"
|
||||
|
||||
class SNORE_EXPORT Utils
|
||||
{
|
||||
public:
|
||||
Utils();
|
||||
static QString notificationToSNTPString ( Notification notification );
|
||||
};
|
||||
|
||||
#endif // UTILS_H
|
@ -1,3 +1,4 @@
|
||||
set(CMAKE_SHARED_MODULE_PREFIX)
|
||||
add_subdirectory(freedesktopnotification)
|
||||
add_subdirectory(freedesktopfrontend)
|
||||
add_subdirectory(snarlnetwork)
|
||||
|
@ -23,7 +23,7 @@
|
||||
class Growl_Backend:public Notification_Backend
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(Notification_Backend);
|
||||
Q_INTERFACES(Notification_Backend)
|
||||
public:
|
||||
Growl_Backend(class SnoreServer *snore=0);
|
||||
~Growl_Backend();
|
||||
|
@ -88,7 +88,7 @@ void SnoreNotify::load(){
|
||||
QDomElement root = doc.documentElement();
|
||||
QDomElement backend = root.elementsByTagName("notificationBackend").item(0).toElement();
|
||||
if(!backend.isNull())
|
||||
_snore->setPrimaryNotificationBackend(_snore->primaryNotificationBackends().value(backend.text()));
|
||||
_snore->setPrimaryNotificationBackend(backend.text());
|
||||
}
|
||||
|
||||
void SnoreNotify::save(){
|
||||
@ -96,7 +96,7 @@ void SnoreNotify::save(){
|
||||
QDomElement root = doc.createElement( "SnoreNotifyProfile" );
|
||||
doc.appendChild(root);
|
||||
QDomElement backend = doc.createElement( "notificationBackend");
|
||||
backend.appendChild(doc.createTextNode(_snore->primaryNotificationBackend()->name()));
|
||||
backend.appendChild(doc.createTextNode(_snore->primaryNotificationBackend()));
|
||||
root.appendChild(backend);
|
||||
|
||||
|
||||
|
@ -33,11 +33,11 @@ void TrayIcon::initConextMenu(SnoreServer *snore){
|
||||
_trayMenu = new QMenu("SnoreNotify");
|
||||
_trayMenu->addAction(QString("SnoreNotify ").append(_snore->version()));
|
||||
_trayMenu->addSeparator();
|
||||
foreach(Notification_Backend *back,_snore->primaryNotificationBackends()){
|
||||
QAction *b= new QAction(back->name(),this);
|
||||
foreach(const QString &back,_snore->primaryNotificationBackends()){
|
||||
QAction *b= new QAction(back,this);
|
||||
connect(b,SIGNAL(triggered()),this,SLOT(setPrimaryBackend()));
|
||||
b->setCheckable(true);
|
||||
if(back->name() == _snore->primaryNotificationBackend()->name())
|
||||
if(back == _snore->primaryNotificationBackend())
|
||||
b->setChecked(true);
|
||||
_backendActions.append(b);
|
||||
_trayMenu->addAction(b);
|
||||
@ -59,7 +59,7 @@ QSystemTrayIcon* TrayIcon::trayIcon(){
|
||||
|
||||
void TrayIcon::setPrimaryBackend(){
|
||||
QAction *a= dynamic_cast<QAction*>(sender());
|
||||
_snore->setPrimaryNotificationBackend(_snore->primaryNotificationBackends().value(a->text()));
|
||||
_snore->setPrimaryNotificationBackend(a->text());
|
||||
|
||||
foreach(QAction *action,_backendActions){
|
||||
action->setChecked(false);
|
||||
|
Loading…
x
Reference in New Issue
Block a user