reduce amount of pointers ...

This commit is contained in:
Patrick von Reth 2014-01-12 18:00:45 +01:00
parent 85d3c99fcf
commit a16e680bd5
22 changed files with 232 additions and 161 deletions

View File

@ -23,26 +23,32 @@
using namespace Snore; using namespace Snore;
Application::Application (const QString &name, const Icon &icon) : Application::Application (const QString &name, const Icon &icon) :
m_name ( name ), m_name(name),
m_icon(icon) m_icon(icon)
{ {
} }
Application::Application() : Application::Application(const Application &other):
m_name ( "Error: Uninitialized Application" ) m_name(other.m_name),
m_icon(other.m_icon),
m_alerts(other.m_alerts)
{
}
Application::Application()
{} {}
Application::~Application() Application::~Application()
{ {
} }
void Application::addAlert ( Alert *alert ) void Application::addAlert(const Alert &alert)
{ {
alert->setParent(this); m_alerts.insert(alert.name(), alert);
m_alerts.insert ( alert->name(),alert );
} }
const QString &Application::name() const QString Application::name() const
{ {
return m_name; return m_name;
} }
@ -52,29 +58,43 @@ const Icon &Application::icon()const
return m_icon; return m_icon;
} }
const AlertList &Application::alerts() const const QHash<QString, Alert> &Application::alerts() const
{ {
return m_alerts; return m_alerts;
} }
Alert::Alert (const QString &name, const QString &title, const Icon &icon, bool active) : bool Application::isValid() const
m_name ( name ), {
m_title ( title ), return m_name.isNull();
}
Alert::Alert (const QString &name, const QString &title, const Icon &icon, bool active):
m_name(name),
m_title(title),
m_icon(icon), m_icon(icon),
m_active ( active ) m_active(active)
{} {}
Alert::Alert(const Alert &other):
m_name(other.m_name),
m_title(other.m_title),
m_icon(other.m_icon),
m_active(other.m_active)
{
}
Alert::Alert() : Alert::Alert() :
m_active ( false ) m_active ( false )
{} {}
const QString &Alert::name() const QString Alert::name() const
{ {
return m_name; return m_name;
} }
const QString &Alert::title() const QString Alert::title() const
{ {
return m_title; return m_title;
} }
@ -89,3 +109,7 @@ bool Alert::isActive() const
return m_active; return m_active;
} }
bool Alert::isValid() const
{
return m_name.isNull();
}

View File

@ -24,43 +24,19 @@
#include <QHash> #include <QHash>
namespace Snore{ namespace Snore{
class Application;
class Alert;
typedef QHash<QString,Application*> ApplicationsList ; class SNORE_EXPORT Alert
typedef QHash<QString,Alert*> AlertList;
class SNORE_EXPORT Application : public QObject
{ {
Q_OBJECT
public: public:
Application ( const QString &name, const Icon &icon = Icon(":/root/snore.png"));
Application();
~Application();
void addAlert ( Alert *alert );
const QString &name() const;
const Icon &icon() const;
const AlertList &alerts() const;
private:
QString m_name;
Icon m_icon;
AlertList m_alerts;
};
class SNORE_EXPORT Alert:public QObject
{
Q_OBJECT
public:
Alert ( const QString &name,const QString &title="",const Icon &icon = Icon(":/root/snore.png"),bool active=true );
Alert(); Alert();
Alert ( const QString &name,const QString &title="",const Icon &icon = Icon(":/root/snore.png"),bool active=true );
Alert(const Alert &other);
const QString &name() const; QString name() const;
const QString &title() const; QString title() const;
const Icon &icon() const; const Icon &icon() const;
bool isActive() const; bool isActive() const;
bool isValid() const;
private: private:
QString m_name; QString m_name;
QString m_title; QString m_title;
@ -68,6 +44,29 @@ private:
bool m_active; bool m_active;
}; };
class SNORE_EXPORT Application
{
public:
Application();
Application ( const QString &name, const Icon &icon = Icon(":/root/snore.png"));
Application(const Application &other);
~Application();
void addAlert(const Alert &alert);
QString name() const;
const Icon &icon() const;
const QHash<QString,Alert> &alerts() const;
bool isValid() const;
private:
QString m_name;
Icon m_icon;
QHash<QString,Alert> m_alerts;
};
} }

View File

@ -31,17 +31,36 @@ int Notification::m_defaultTimeout = 10;
int NotificationData::notificationMetaID = qRegisterMetaType<Notification>(); int NotificationData::notificationMetaID = qRegisterMetaType<Notification>();
Notification::Action::Action():
m_id(-1)
{
}
Notification::Action::Action(int id, QString name): Notification::Action::Action(int id, QString name):
m_id(id), m_id(id),
m_name(name) m_name(name)
{ {
} }
Notification::Action::Action(const Notification::Action &other):
m_id(other.id()),
m_name(other.name())
{
}
QString Notification::Action::name() const QString Notification::Action::name() const
{ {
return m_name; return m_name;
} }
bool Notification::Action::isValid() const
{
return m_name.isNull();
}
int Notification::Action::id() const int Notification::Action::id() const
{ {
return m_id; return m_id;
@ -97,7 +116,7 @@ const uint &Notification::updateID() const
return d->m_updateID; return d->m_updateID;
} }
const Notification::Action *Notification::actionInvoked() const const Notification::Action &Notification::actionInvoked() const
{ {
return d->m_actionInvoked; return d->m_actionInvoked;
} }
@ -146,13 +165,13 @@ const NotificationEnums::Prioritys::prioritys &Notification::priority() const
return d->m_priority; return d->m_priority;
} }
void Notification::addAction(Notification::Action *a) void Notification::addAction(const Notification::Action &a)
{ {
d->m_actions.insert(a->id(),a); d->m_actions.insert(a.id(),a);
} }
const QHash<int, Notification::Action *> &Notification::actions() const const QHash<int, Notification::Action> &Notification::actions() const
{ {
return d->m_actions; return d->m_actions;
} }

View File

@ -41,10 +41,13 @@ public:
class SNORE_EXPORT Action class SNORE_EXPORT Action
{ {
public: public:
Action();
Action(int id,QString name); Action(int id,QString name);
Action(const Action &other);
int id() const; int id() const;
QString name() const; QString name() const;
bool isValid() const;
private: private:
int m_id; int m_id;
@ -67,7 +70,7 @@ public:
void setUpdateID(uint id); void setUpdateID(uint id);
const uint &updateID() const; const uint &updateID() const;
const Action* actionInvoked() const; const Action &actionInvoked() const;
void setSource(class SnoreFrontend *source); void setSource(class SnoreFrontend *source);
class SnoreFrontend *source() const; class SnoreFrontend *source() const;
const QString &application() const; const QString &application() const;
@ -78,8 +81,8 @@ public:
void setSticky(); void setSticky();
bool sticky() const; bool sticky() const;
const NotificationEnums::Prioritys::prioritys &priority() const; const NotificationEnums::Prioritys::prioritys &priority() const;
const QHash<int,Action*> &actions() const; const QHash<int, Action> &actions() const;
void addAction(Action *a); void addAction(const Action &a);
const NotificationEnums::CloseReasons::closeReasons &closeReason(); const NotificationEnums::CloseReasons::closeReasons &closeReason();
void setCloseReason(const NotificationEnums::CloseReasons::closeReasons &r); void setCloseReason(const NotificationEnums::CloseReasons::closeReasons &r);
Hint &hints(); Hint &hints();

View File

@ -43,8 +43,7 @@ NotificationData::NotificationData ( const QString &application,const QString &a
m_text ( text ), m_text ( text ),
m_icon ( icon ), m_icon ( icon ),
m_priority(priority), m_priority(priority),
m_closeReason(NotificationEnums::CloseReasons::NONE), m_closeReason(NotificationEnums::CloseReasons::NONE)
m_actionInvoked( NULL )
{ {
notificationCount++; notificationCount++;
qDebug()<< "Creating Notification: ActiveNotifications" << notificationCount << "id" << m_id; qDebug()<< "Creating Notification: ActiveNotifications" << notificationCount << "id" << m_id;
@ -57,7 +56,7 @@ NotificationData::~NotificationData()
} }
void NotificationData::setActionInvoked ( Notification::Action *action ) void NotificationData::setActionInvoked (const Snore::Notification::Action &action )
{ {
m_actionInvoked = action; m_actionInvoked = action;
} }

View File

@ -38,8 +38,8 @@ public:
int timeout,NotificationEnums::Prioritys::prioritys priority ); int timeout,NotificationEnums::Prioritys::prioritys priority );
~NotificationData(); ~NotificationData();
void setActionInvoked ( Notification::Action *action ); void setActionInvoked( const Notification::Action &action );
void setActionInvoked ( const int &actionID); void setActionInvoked( const int &actionID);
private: private:
Q_DISABLE_COPY(NotificationData) Q_DISABLE_COPY(NotificationData)
@ -55,8 +55,8 @@ private:
Icon m_icon; Icon m_icon;
NotificationEnums::Prioritys::prioritys m_priority; NotificationEnums::Prioritys::prioritys m_priority;
NotificationEnums::CloseReasons::closeReasons m_closeReason; NotificationEnums::CloseReasons::closeReasons m_closeReason;
Notification::Action *m_actionInvoked; Notification::Action m_actionInvoked;
QHash<int,Notification::Action*> m_actions; QHash<int,Notification::Action> m_actions;
Hint m_hints; Hint m_hints;
static uint notificationCount; static uint notificationCount;

View File

@ -62,7 +62,7 @@ private:
static QSettings *_cache = NULL; static QSettings *_cache = NULL;
if(_cache == NULL) if(_cache == NULL)
{ {
_cache = new QSettings("SnoreNotify","libsnore-plugin-cache"); _cache = new QSettings("SnoreNotify","libsnore");
QCryptographicHash h(QCryptographicHash::Md5); QCryptographicHash h(QCryptographicHash::Md5);
h.addData(SnoreCorePrivate::pluginDir().absolutePath().toLatin1()); h.addData(SnoreCorePrivate::pluginDir().absolutePath().toLatin1());
_cache->beginGroup( h.result().toHex()); _cache->beginGroup( h.result().toHex());

View File

@ -42,7 +42,7 @@ SnoreBackend::~SnoreBackend()
{ {
qDebug()<<"Deleting"<<name(); qDebug()<<"Deleting"<<name();
if(snore() != NULL){ if(snore() != NULL){
foreach(Application *a,snore()->aplications()){ foreach(const Application &a,snore()->aplications()){
slotDeregisterApplication(a); slotDeregisterApplication(a);
} }
} }
@ -55,10 +55,11 @@ bool SnoreBackend::init( SnoreCore *snore )
{ {
return false; return false;
} }
connect( snore->d(), SIGNAL(applicationRegistered(Snore::Application*)), this, SLOT(slotRegisterApplication(Snore::Application*))); connect( snore->d(), SIGNAL(applicationRegistered(const Snore::Application&)), this, SLOT(slotRegisterApplication(const Snore::Application&)));
connect( snore->d(), SIGNAL(applicationDeregistered(Snore::Application*)), this, SLOT(slotDeregisterApplication(Snore::Application*))); connect( snore->d(), SIGNAL(applicationDeregistered(const Snore::Application&)), this, SLOT(slotDeregisterApplication(const Snore::Application&)));
foreach(Application *a,snore->aplications()){ foreach(const Application &a,snore->aplications())
{
this->slotRegisterApplication(a); this->slotRegisterApplication(a);
} }
@ -127,12 +128,12 @@ bool SnoreBackend::supportsRichtext()
return m_supportsRichtext; return m_supportsRichtext;
} }
void SnoreBackend::slotRegisterApplication(Application *application) void SnoreBackend::slotRegisterApplication(const Application &application)
{ {
Q_UNUSED(application); Q_UNUSED(application);
} }
void SnoreBackend::slotDeregisterApplication(Application *application) void SnoreBackend::slotDeregisterApplication(const Application &application)
{ {
Q_UNUSED(application); Q_UNUSED(application);
} }

View File

@ -50,8 +50,8 @@ signals:
public slots: public slots:
virtual void slotRegisterApplication(Snore::Application *application ); virtual void slotRegisterApplication(const Snore::Application &application );
virtual void slotDeregisterApplication(Snore::Application *application ); virtual void slotDeregisterApplication(const Application &application );
virtual void slotNotify ( Snore::Notification notification ) = 0; virtual void slotNotify ( Snore::Notification notification ) = 0;
virtual void slotCloseNotification ( Snore::Notification notification ); virtual void slotCloseNotification ( Snore::Notification notification );

View File

@ -124,25 +124,24 @@ void SnoreCore::broadcastNotification ( Notification notification )
} }
} }
void SnoreCore::registerApplication(Application *application) void SnoreCore::registerApplication(const Application &application)
{ {
Q_D(SnoreCore); Q_D(SnoreCore);
if(!d->m_applications.contains(application->name())) if(!d->m_applications.contains(application.name()))
{ {
d->m_applications.insert ( application->name(),application ); d->m_applications.insert ( application.name(),application );
emit d->applicationRegistered ( application ); emit d->applicationRegistered ( application );
} }
} }
void SnoreCore::deregisterApplication(Application *application) void SnoreCore::deregisterApplication(const Application &application)
{ {
Q_D(SnoreCore); Q_D(SnoreCore);
emit d->applicationDeregistered (application ); emit d->applicationDeregistered (application );
d->m_applications.take ( application->name() ); d->m_applications.take ( application.name() );
application->deleteLater();
} }
const ApplicationsList &SnoreCore::aplications() const const QHash<QString, Application> &SnoreCore::aplications() const
{ {
Q_D(const SnoreCore); Q_D(const SnoreCore);
return d->m_applications; return d->m_applications;

View File

@ -48,10 +48,10 @@ public:
void broadcastNotification( Notification notification ); void broadcastNotification( Notification notification );
void registerApplication( Application *application ); void registerApplication(const Application &application );
void deregisterApplication( Application *application ); void deregisterApplication(const Application &application );
const ApplicationsList &aplications() const; const QHash<QString, Application> &aplications() const;
const QStringList &notificationBackends() const; const QStringList &notificationBackends() const;
const QStringList &notificationFrontends() const; const QStringList &notificationFrontends() const;

View File

@ -45,8 +45,8 @@ public:
void notificationActionInvoked(Notification notification) const; void notificationActionInvoked(Notification notification) const;
signals: signals:
void applicationRegistered(Snore::Application*); void applicationRegistered(const Snore::Application&);
void applicationDeregistered(Snore::Application*); void applicationDeregistered(const Snore::Application&);
void notify(Snore::Notification noti); void notify(Snore::Notification noti);
private slots: private slots:
@ -56,7 +56,7 @@ private:
SnoreCore *q_ptr; SnoreCore *q_ptr;
Hint m_hints; Hint m_hints;
ApplicationsList m_applications; QHash<QString,Application> m_applications;
QStringList m_notificationBackends; QStringList m_notificationBackends;

View File

@ -66,19 +66,19 @@ bool Growl::init(SnoreCore *snore)
return SnoreBackend::init(snore); return SnoreBackend::init(snore);
} }
void Growl::slotRegisterApplication(Application *application) void Growl::slotRegisterApplication(const Application &application)
{ {
gntp *growl = new gntp(application->name().toUtf8().constData(),application->icon().localUrl().toUtf8().constData()); gntp *growl = new gntp(application.name().toUtf8().constData(),application.icon().localUrl().toUtf8().constData());
gntp::gntp_callback callback(&Growl::gntpCallback); gntp::gntp_callback callback(&Growl::gntpCallback);
growl->set_gntp_callback(callback); growl->set_gntp_callback(callback);
// qDebug() << Q_FUNC_INFO << application->name().toUtf8().constData(); // qDebug() << Q_FUNC_INFO << application->name().toUtf8().constData();
std::vector<std::string> alerts; std::vector<std::string> alerts;
foreach(Alert *a,application->alerts()) foreach(const Alert &a,application.alerts())
{ {
// qDebug() << Q_FUNC_INFO << a->name().toUtf8().constData(); // qDebug() << Q_FUNC_INFO << a->name().toUtf8().constData();
alerts.push_back(a->name().toUtf8().constData()); alerts.push_back(a.name().toUtf8().constData());
} }
try try
@ -88,12 +88,12 @@ void Growl::slotRegisterApplication(Application *application)
{ {
qWarning() << Q_FUNC_INFO << e.what(); qWarning() << Q_FUNC_INFO << e.what();
} }
m_applications.insert(application->name(),growl); m_applications.insert(application.name(),growl);
} }
void Growl::slotDeregisterApplication(Application *application) void Growl::slotDeregisterApplication(const Application &application)
{ {
gntp *growl = m_applications.take(application->name()); gntp *growl = m_applications.take(application.name());
if(growl == NULL) if(growl == NULL)
{ {
return; return;

View File

@ -44,8 +44,8 @@ private:
gntp *m_defaultGNTP; gntp *m_defaultGNTP;
public slots: public slots:
void slotRegisterApplication(Snore::Application *application); void slotRegisterApplication(const Snore::Application &application);
void slotDeregisterApplication(Snore::Application *application); void slotDeregisterApplication(const Snore::Application &application);
void slotNotify(Snore::Notification notification); void slotNotify(Snore::Notification notification);
}; };

View File

@ -55,7 +55,8 @@ public:
if(msg->message == SNARL_GLOBAL_MESSAGE){ if(msg->message == SNARL_GLOBAL_MESSAGE){
int action = msg->wParam; int action = msg->wParam;
if(action == SnarlEnums::SnarlLaunched){ if(action == SnarlEnums::SnarlLaunched){
foreach(Application *a,m_snarl->snore()->aplications()){ foreach(const Application &a,m_snarl->snore()->aplications())
{
m_snarl->slotRegisterApplication(a); m_snarl->slotRegisterApplication(a);
} }
} }
@ -160,36 +161,38 @@ bool SnarlBackend::init(SnoreCore *snore){
return SnoreBackend::init(snore); return SnoreBackend::init(snore);
} }
void SnarlBackend::slotRegisterApplication(Application *application){ void SnarlBackend::slotRegisterApplication(const Application &application){
SnarlInterface *snarlInterface = NULL; SnarlInterface *snarlInterface = NULL;
if(m_applications.contains(application->name())){ if(m_applications.contains(application.name()))
snarlInterface = m_applications.value(application->name()); {
}else{ snarlInterface = m_applications.value(application.name());
snarlInterface = new SnarlInterface();
m_applications.insert(application->name(),snarlInterface);
} }
qDebug()<<"Register with Snarl"<<application->name(); else
QString appName = application->name(); {
appName = appName.replace(" ","_");//app sig must not contain spaces snarlInterface = new SnarlInterface();
m_applications.insert(application.name(),snarlInterface);
}
QString appName = application.name().replace(" ","_");//app sig must not contain spaces
snarlInterface->Register(appName.toUtf8().constData(), snarlInterface->Register(appName.toUtf8().constData(),
application->name().toUtf8().constData(), application.name().toUtf8().constData(),
application->icon().localUrl().toUtf8().constData(), application.icon().localUrl().toUtf8().constData(),
0,(HWND)m_eventLoop->winId(),SNORENOTIFIER_MESSAGE_ID); 0,(HWND)m_eventLoop->winId(),SNORENOTIFIER_MESSAGE_ID);
foreach(Alert *alert,application->alerts()){ foreach(const Alert &alert,application.alerts())
qDebug()<<"registering snarl alert"<<application->name(); {
snarlInterface->AddClass(alert->name().toUtf8().constData(), snarlInterface->AddClass(alert.name().toUtf8().constData(),
alert->name().toUtf8().constData(), alert.name().toUtf8().constData(),
0,0,alert->icon().localUrl().toUtf8().constData()); 0,0,alert.icon().localUrl().toUtf8().constData());
} }
} }
void SnarlBackend::slotDeregisterApplication(Application *application){ void SnarlBackend::slotDeregisterApplication(const Application &application){
SnarlInterface *snarlInterface = m_applications.take(application->name()); SnarlInterface *snarlInterface = m_applications.take(application.name());
if(snarlInterface == NULL) if(snarlInterface == NULL)
{
return; return;
QString appName = application->name(); }
appName = appName.replace(" ","_");//app sig must not contain spaces QString appName = application.name().replace(" ","_");//app sig must not contain spaces
snarlInterface->Unregister(appName.toUtf8().constData()); snarlInterface->Unregister(appName.toUtf8().constData());
delete snarlInterface; delete snarlInterface;
} }
@ -225,14 +228,17 @@ void SnarlBackend::slotNotify(Notification notification){
!notification.icon().isLocalFile()?notification.icon().imageData().toBase64().constData():0, !notification.icon().isLocalFile()?notification.icon().imageData().toBase64().constData():0,
priority); priority);
foreach(const Notification::Action *a, notification.actions()){ foreach(const Notification::Action &a, notification.actions())
snarlInterface->AddAction(id,a->name().toUtf8().constData(),QString("@").append(QString::number(a->id())).toUtf8().constData()); {
snarlInterface->AddAction(id,a.name().toUtf8().constData(),QString("@").append(QString::number(a.id())).toUtf8().constData());
} }
m_idMap[notification.id()] = id; m_idMap[notification.id()] = id;
qDebug() << "snarl" << id << notification.id(); qDebug() << "snarl" << id << notification.id();
startTimeout(notification.id(),notification.timeout()); startTimeout(notification.id(),notification.timeout());
}else{ }
else
{
//update message //update message
snarlInterface->Update(m_idMap[notification.updateID()], snarlInterface->Update(m_idMap[notification.updateID()],
notification.alert().toUtf8().constData(), notification.alert().toUtf8().constData(),

View File

@ -41,8 +41,8 @@ private:
Snarl::V42::SnarlInterface* m_defautSnarlinetrface; Snarl::V42::SnarlInterface* m_defautSnarlinetrface;
public slots: public slots:
void slotRegisterApplication(Snore::Application *application); void slotRegisterApplication(const Snore::Application &application);
void slotDeregisterApplication(Snore::Application *application); void slotDeregisterApplication(const Snore::Application &application);
void slotNotify(Snore::Notification notification); void slotNotify(Snore::Notification notification);
void slotCloseNotification(Snore::Notification notification); void slotCloseNotification(Snore::Notification notification);

View File

@ -55,9 +55,9 @@ bool FreedesktopFrontend::init(SnoreCore *snore){
} }
void FreedesktopFrontend::actionInvoked(Notification notification) { void FreedesktopFrontend::actionInvoked(Notification notification) {
if(notification.actionInvoked()) if(notification.actionInvoked().isValid())
{ {
emit ActionInvoked(notification.id(),QString::number(notification.actionInvoked()->id())); emit ActionInvoked(notification.id(),QString::number(notification.actionInvoked().id()));
} }
} }
@ -90,8 +90,8 @@ uint FreedesktopFrontend::Notify(const QString &app_name, uint replaces_id,
#else #else
Icon appIcon(":/root/images/freedesktop-dbus.png"); Icon appIcon(":/root/images/freedesktop-dbus.png");
#endif #endif
Application *a = new Application(app_name,appIcon); Application a(app_name,appIcon);
a->addAlert(new Alert("DBus Alert","DBus Alert",appIcon)); a.addAlert(Alert("DBus Alert","DBus Alert",appIcon));
snore()->registerApplication(a); snore()->registerApplication(a);
} }
@ -105,8 +105,9 @@ uint FreedesktopFrontend::Notify(const QString &app_name, uint replaces_id,
noti.setUpdateID(replaces_id); noti.setUpdateID(replaces_id);
} }
noti.setSource(this); noti.setSource(this);
for(int i = 0;i < actions.length(); i+=2){ for(int i = 0;i < actions.length(); i+=2)
noti.addAction(new Notification::Action(actions.at(i).toInt(),actions.at(i+1))); {
noti.addAction(Notification::Action(actions.at(i).toInt(),actions.at(i+1)));
} }
snore()->broadcastNotification(noti); snore()->broadcastNotification(noti);

View File

@ -122,21 +122,26 @@ SnarlNotification Parser::parse(QString &msg,QTcpSocket* client){
switch(action){ switch(action){
case NOTIFICATION:{ case NOTIFICATION:
{
qDebug() << sNotification.notification.application(); qDebug() << sNotification.notification.application();
Application * appl = snarl->snore()->aplications().value(sNotification.notification.application()); const Application &appl = snarl->snore()->aplications().value(sNotification.notification.application());
if(!snarl->snore()->aplications().contains(appl->name())){ if(!snarl->snore()->aplications().contains(appl.name()))
{
snarl->snore()->registerApplication(appl); snarl->snore()->registerApplication(appl);
} }
if(!appl->alerts().value(sNotification.notification.alert())->isActive()) if(!appl.alerts().value(sNotification.notification.alert()).isActive())
{
break; break;
}
sNotification.isNotification = true; sNotification.isNotification = true;
return sNotification; return sNotification;
break; break;
} }
case ADD_CLASS: case ADD_CLASS:
if(sNotification.notification.alert().isEmpty()){ if(sNotification.notification.alert().isEmpty())
{
qDebug()<<"Error registering alert with empty name"; qDebug()<<"Error registering alert with empty name";
break; break;
} }
@ -144,7 +149,7 @@ SnarlNotification Parser::parse(QString &msg,QTcpSocket* client){
{ {
title = alert; title = alert;
} }
snarl->m_applications.value(sNotification.notification.application())->addAlert(new Alert(alert,title)); snarl->m_applications.value(sNotification.notification.application())->addAlert(Alert(alert,title));
break; break;
case REGISTER: case REGISTER:
if(!sNotification.notification.application().isEmpty() && !snarl->m_applications.contains(sNotification.notification.application())){ if(!sNotification.notification.application().isEmpty() && !snarl->m_applications.contains(sNotification.notification.application())){

View File

@ -56,10 +56,14 @@ bool SnarlNetworkFrontend::init(SnoreCore *snore){
void SnarlNetworkFrontend::actionInvoked(Notification notification){ void SnarlNetworkFrontend::actionInvoked(Notification notification){
//TODO:fix callback //TODO:fix callback
SnarlNotification sn=notifications.value(notification.id()); SnarlNotification sn=notifications.value(notification.id());
if(notification.actionInvoked()->id() == 1 ) if(notification.actionInvoked().id() == 1 )
{
callback(sn,"SNP/1.1/304/Notification acknowledged/"); callback(sn,"SNP/1.1/304/Notification acknowledged/");
else if(notification.actionInvoked()->id() == 2) }
else if(notification.actionInvoked().id() == 2)
{
callback(sn,"SNP/1.1/302/Notification cancelled/"); callback(sn,"SNP/1.1/302/Notification cancelled/");
}
} }
void SnarlNetworkFrontend::notificationClosed(Notification notification){ void SnarlNetworkFrontend::notificationClosed(Notification notification){
SnarlNotification sn=notifications.value(notification.id()); SnarlNotification sn=notifications.value(notification.id());

View File

@ -70,7 +70,8 @@ void SnoreNotify::save(){
void SnoreNotify::exit(){ void SnoreNotify::exit(){
qDebug()<<"Saving snore settings"; qDebug()<<"Saving snore settings";
foreach(Application *a,m_snore->aplications()){ foreach(const Application &a,m_snore->aplications())
{
m_snore->deregisterApplication(a); m_snore->deregisterApplication(a);
} }
save(); save();

View File

@ -28,49 +28,54 @@
using namespace Snore; using namespace Snore;
TrayIcon::TrayIcon() TrayIcon::TrayIcon():
m_trayIcon(new QSystemTrayIcon(QIcon(":/root/snore.png")))
{ {
_trayIcon = new QSystemTrayIcon(QIcon(":/root/snore.png"));
} }
void TrayIcon::initConextMenu(SnoreCore *snore){ void TrayIcon::initConextMenu(SnoreCore *snore)
_snore = snore; {
_trayIcon->setVisible(true); m_snore = snore;
m_trayIcon->setVisible(true);
_trayMenu = new QMenu("SnoreNotify"); m_trayMenu = new QMenu("SnoreNotify");
_trayMenu->addAction(QString("SnoreNotify ").append(Version::version())); m_trayMenu->addAction(QString("SnoreNotify ").append(Version::version()));
_trayMenu->addSeparator(); m_trayMenu->addSeparator();
connect(_trayMenu->addAction(QString("Test")), SIGNAL(triggered()), this, SLOT(slotTestNotification())); m_trayMenu->addAction("Test Notification", this, SLOT(slotTestNotification()));
_trayMenu->addSeparator(); m_trayMenu->addSeparator();
foreach(const QString &back,_snore->notificationBackends()){ foreach(const QString &back,m_snore->notificationBackends())
QAction *b= new QAction(back,this); {
connect(b,SIGNAL(triggered()),this,SLOT(setPrimaryBackend())); QAction *b = m_trayMenu->addAction(back, this, SLOT(setPrimaryBackend()));
b->setCheckable(true); b->setCheckable(true);
if(back == _snore->primaryNotificationBackend()) if(back == m_snore->primaryNotificationBackend())
{
b->setChecked(true); b->setChecked(true);
_backendActions.append(b);
_trayMenu->addAction(b);
} }
_trayMenu->addSeparator(); m_backendActions.append(b);
_trayMenu->addAction("Exit",qApp,SLOT(quit())); }
m_trayMenu->addSeparator();
m_trayMenu->addAction("Exit",qApp,SLOT(quit()));
_trayIcon->setContextMenu(_trayMenu); m_trayIcon->setContextMenu(m_trayMenu);
} }
void TrayIcon::hide(){ void TrayIcon::hide()
_trayIcon->setVisible(false); {
m_trayIcon->setVisible(false);
} }
QSystemTrayIcon* TrayIcon::trayIcon(){ QSystemTrayIcon* TrayIcon::trayIcon()
return _trayIcon; {
return m_trayIcon;
} }
void TrayIcon::setPrimaryBackend(){ void TrayIcon::setPrimaryBackend(){
QAction *a= dynamic_cast<QAction*>(sender()); QAction *a = qobject_cast<QAction*>(sender());
_snore->setPrimaryNotificationBackend(a->text()); m_snore->setPrimaryNotificationBackend(a->text());
foreach(QAction *action,_backendActions){ foreach(QAction *action,m_backendActions)
{
action->setChecked(false); action->setChecked(false);
} }
a->setChecked(true); a->setChecked(true);
@ -79,7 +84,12 @@ void TrayIcon::setPrimaryBackend(){
void TrayIcon::slotTestNotification() void TrayIcon::slotTestNotification()
{ {
Application appl("SnoreNotify");
appl.addAlert(Alert("Default"));
m_snore->registerApplication(appl);
Notification n("SnoreNotify","Default","Hello World","This is Snore",Icon(":/root/snore.png")); Notification n("SnoreNotify","Default","Hello World","This is Snore",Icon(":/root/snore.png"));
_snore->broadcastNotification(n); n.addAction(Notification::Action(1,"Test Action"));
m_snore->broadcastNotification(n);
m_snore->deregisterApplication(appl);
} }

View File

@ -36,10 +36,10 @@ public:
class QSystemTrayIcon* trayIcon(); class QSystemTrayIcon* trayIcon();
private: private:
class QSystemTrayIcon *_trayIcon; class QSystemTrayIcon *m_trayIcon;
class QMenu *_trayMenu; class QMenu *m_trayMenu;
class QList<class QAction*> _backendActions; class QList<class QAction*> m_backendActions;
class Snore::SnoreCore *_snore; class Snore::SnoreCore *m_snore;
public slots: public slots: