reduce amount of pointers ...
This commit is contained in:
parent
85d3c99fcf
commit
a16e680bd5
|
@ -23,26 +23,32 @@
|
|||
using namespace Snore;
|
||||
|
||||
Application::Application (const QString &name, const Icon &icon) :
|
||||
m_name ( name ),
|
||||
m_name(name),
|
||||
m_icon(icon)
|
||||
{
|
||||
}
|
||||
|
||||
Application::Application() :
|
||||
m_name ( "Error: Uninitialized Application" )
|
||||
Application::Application(const Application &other):
|
||||
m_name(other.m_name),
|
||||
m_icon(other.m_icon),
|
||||
m_alerts(other.m_alerts)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -52,29 +58,43 @@ const Icon &Application::icon()const
|
|||
return m_icon;
|
||||
}
|
||||
|
||||
const AlertList &Application::alerts() const
|
||||
const QHash<QString, Alert> &Application::alerts() const
|
||||
{
|
||||
return m_alerts;
|
||||
}
|
||||
|
||||
Alert::Alert (const QString &name, const QString &title, const Icon &icon, bool active) :
|
||||
m_name ( name ),
|
||||
m_title ( title ),
|
||||
bool Application::isValid() const
|
||||
{
|
||||
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_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() :
|
||||
m_active ( false )
|
||||
{}
|
||||
|
||||
|
||||
const QString &Alert::name() const
|
||||
QString Alert::name() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
const QString &Alert::title() const
|
||||
QString Alert::title() const
|
||||
{
|
||||
return m_title;
|
||||
}
|
||||
|
@ -89,3 +109,7 @@ bool Alert::isActive() const
|
|||
return m_active;
|
||||
}
|
||||
|
||||
bool Alert::isValid() const
|
||||
{
|
||||
return m_name.isNull();
|
||||
}
|
||||
|
|
|
@ -24,43 +24,19 @@
|
|||
|
||||
#include <QHash>
|
||||
namespace Snore{
|
||||
class Application;
|
||||
class Alert;
|
||||
|
||||
typedef QHash<QString,Application*> ApplicationsList ;
|
||||
typedef QHash<QString,Alert*> AlertList;
|
||||
|
||||
class SNORE_EXPORT Application : public QObject
|
||||
class SNORE_EXPORT Alert
|
||||
{
|
||||
Q_OBJECT
|
||||
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 ( const QString &name,const QString &title="",const Icon &icon = Icon(":/root/snore.png"),bool active=true );
|
||||
Alert(const Alert &other);
|
||||
|
||||
const QString &name() const;
|
||||
const QString &title() const;
|
||||
QString name() const;
|
||||
QString title() const;
|
||||
const Icon &icon() const;
|
||||
bool isActive() const;
|
||||
bool isValid() const;
|
||||
private:
|
||||
QString m_name;
|
||||
QString m_title;
|
||||
|
@ -68,6 +44,29 @@ private:
|
|||
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;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -31,17 +31,36 @@ int Notification::m_defaultTimeout = 10;
|
|||
|
||||
int NotificationData::notificationMetaID = qRegisterMetaType<Notification>();
|
||||
|
||||
Notification::Action::Action():
|
||||
m_id(-1)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Notification::Action::Action(int id, QString name):
|
||||
m_id(id),
|
||||
m_name(name)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Notification::Action::Action(const Notification::Action &other):
|
||||
m_id(other.id()),
|
||||
m_name(other.name())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QString Notification::Action::name() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
bool Notification::Action::isValid() const
|
||||
{
|
||||
return m_name.isNull();
|
||||
}
|
||||
|
||||
int Notification::Action::id() const
|
||||
{
|
||||
return m_id;
|
||||
|
@ -97,7 +116,7 @@ const uint &Notification::updateID() const
|
|||
return d->m_updateID;
|
||||
}
|
||||
|
||||
const Notification::Action *Notification::actionInvoked() const
|
||||
const Notification::Action &Notification::actionInvoked() const
|
||||
{
|
||||
return d->m_actionInvoked;
|
||||
}
|
||||
|
@ -146,13 +165,13 @@ const NotificationEnums::Prioritys::prioritys &Notification::priority() const
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -41,10 +41,13 @@ public:
|
|||
class SNORE_EXPORT Action
|
||||
{
|
||||
public:
|
||||
Action();
|
||||
Action(int id,QString name);
|
||||
Action(const Action &other);
|
||||
|
||||
int id() const;
|
||||
QString name() const;
|
||||
bool isValid() const;
|
||||
|
||||
private:
|
||||
int m_id;
|
||||
|
@ -67,7 +70,7 @@ public:
|
|||
void setUpdateID(uint id);
|
||||
const uint &updateID() const;
|
||||
|
||||
const Action* actionInvoked() const;
|
||||
const Action &actionInvoked() const;
|
||||
void setSource(class SnoreFrontend *source);
|
||||
class SnoreFrontend *source() const;
|
||||
const QString &application() const;
|
||||
|
@ -78,8 +81,8 @@ public:
|
|||
void setSticky();
|
||||
bool sticky() const;
|
||||
const NotificationEnums::Prioritys::prioritys &priority() const;
|
||||
const QHash<int,Action*> &actions() const;
|
||||
void addAction(Action *a);
|
||||
const QHash<int, Action> &actions() const;
|
||||
void addAction(const Action &a);
|
||||
const NotificationEnums::CloseReasons::closeReasons &closeReason();
|
||||
void setCloseReason(const NotificationEnums::CloseReasons::closeReasons &r);
|
||||
Hint &hints();
|
||||
|
|
|
@ -43,8 +43,7 @@ NotificationData::NotificationData ( const QString &application,const QString &a
|
|||
m_text ( text ),
|
||||
m_icon ( icon ),
|
||||
m_priority(priority),
|
||||
m_closeReason(NotificationEnums::CloseReasons::NONE),
|
||||
m_actionInvoked( NULL )
|
||||
m_closeReason(NotificationEnums::CloseReasons::NONE)
|
||||
{
|
||||
notificationCount++;
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -38,8 +38,8 @@ public:
|
|||
int timeout,NotificationEnums::Prioritys::prioritys priority );
|
||||
|
||||
~NotificationData();
|
||||
void setActionInvoked ( Notification::Action *action );
|
||||
void setActionInvoked ( const int &actionID);
|
||||
void setActionInvoked( const Notification::Action &action );
|
||||
void setActionInvoked( const int &actionID);
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(NotificationData)
|
||||
|
@ -55,8 +55,8 @@ private:
|
|||
Icon m_icon;
|
||||
NotificationEnums::Prioritys::prioritys m_priority;
|
||||
NotificationEnums::CloseReasons::closeReasons m_closeReason;
|
||||
Notification::Action *m_actionInvoked;
|
||||
QHash<int,Notification::Action*> m_actions;
|
||||
Notification::Action m_actionInvoked;
|
||||
QHash<int,Notification::Action> m_actions;
|
||||
Hint m_hints;
|
||||
|
||||
static uint notificationCount;
|
||||
|
|
|
@ -62,7 +62,7 @@ private:
|
|||
static QSettings *_cache = NULL;
|
||||
if(_cache == NULL)
|
||||
{
|
||||
_cache = new QSettings("SnoreNotify","libsnore-plugin-cache");
|
||||
_cache = new QSettings("SnoreNotify","libsnore");
|
||||
QCryptographicHash h(QCryptographicHash::Md5);
|
||||
h.addData(SnoreCorePrivate::pluginDir().absolutePath().toLatin1());
|
||||
_cache->beginGroup( h.result().toHex());
|
||||
|
|
|
@ -42,7 +42,7 @@ SnoreBackend::~SnoreBackend()
|
|||
{
|
||||
qDebug()<<"Deleting"<<name();
|
||||
if(snore() != NULL){
|
||||
foreach(Application *a,snore()->aplications()){
|
||||
foreach(const Application &a,snore()->aplications()){
|
||||
slotDeregisterApplication(a);
|
||||
}
|
||||
}
|
||||
|
@ -55,10 +55,11 @@ bool SnoreBackend::init( SnoreCore *snore )
|
|||
{
|
||||
return false;
|
||||
}
|
||||
connect( snore->d(), SIGNAL(applicationRegistered(Snore::Application*)), this, SLOT(slotRegisterApplication(Snore::Application*)));
|
||||
connect( snore->d(), SIGNAL(applicationDeregistered(Snore::Application*)), this, SLOT(slotDeregisterApplication(Snore::Application*)));
|
||||
connect( snore->d(), SIGNAL(applicationRegistered(const Snore::Application&)), this, SLOT(slotRegisterApplication(const 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);
|
||||
}
|
||||
|
||||
|
@ -127,12 +128,12 @@ bool SnoreBackend::supportsRichtext()
|
|||
return m_supportsRichtext;
|
||||
}
|
||||
|
||||
void SnoreBackend::slotRegisterApplication(Application *application)
|
||||
void SnoreBackend::slotRegisterApplication(const Application &application)
|
||||
{
|
||||
Q_UNUSED(application);
|
||||
}
|
||||
|
||||
void SnoreBackend::slotDeregisterApplication(Application *application)
|
||||
void SnoreBackend::slotDeregisterApplication(const Application &application)
|
||||
{
|
||||
Q_UNUSED(application);
|
||||
}
|
||||
|
|
|
@ -50,8 +50,8 @@ signals:
|
|||
|
||||
|
||||
public slots:
|
||||
virtual void slotRegisterApplication(Snore::Application *application );
|
||||
virtual void slotDeregisterApplication(Snore::Application *application );
|
||||
virtual void slotRegisterApplication(const Snore::Application &application );
|
||||
virtual void slotDeregisterApplication(const Application &application );
|
||||
virtual void slotNotify ( Snore::Notification notification ) = 0;
|
||||
virtual void slotCloseNotification ( Snore::Notification notification );
|
||||
|
||||
|
|
|
@ -124,25 +124,24 @@ void SnoreCore::broadcastNotification ( Notification notification )
|
|||
}
|
||||
}
|
||||
|
||||
void SnoreCore::registerApplication(Application *application)
|
||||
void SnoreCore::registerApplication(const Application &application)
|
||||
{
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
||||
void SnoreCore::deregisterApplication(Application *application)
|
||||
void SnoreCore::deregisterApplication(const Application &application)
|
||||
{
|
||||
Q_D(SnoreCore);
|
||||
emit d->applicationDeregistered (application );
|
||||
d->m_applications.take ( application->name() );
|
||||
application->deleteLater();
|
||||
d->m_applications.take ( application.name() );
|
||||
}
|
||||
|
||||
const ApplicationsList &SnoreCore::aplications() const
|
||||
const QHash<QString, Application> &SnoreCore::aplications() const
|
||||
{
|
||||
Q_D(const SnoreCore);
|
||||
return d->m_applications;
|
||||
|
|
|
@ -48,10 +48,10 @@ public:
|
|||
|
||||
void broadcastNotification( Notification notification );
|
||||
|
||||
void registerApplication( Application *application );
|
||||
void deregisterApplication( Application *application );
|
||||
void registerApplication(const Application &application );
|
||||
void deregisterApplication(const Application &application );
|
||||
|
||||
const ApplicationsList &aplications() const;
|
||||
const QHash<QString, Application> &aplications() const;
|
||||
|
||||
const QStringList ¬ificationBackends() const;
|
||||
const QStringList ¬ificationFrontends() const;
|
||||
|
|
|
@ -45,8 +45,8 @@ public:
|
|||
void notificationActionInvoked(Notification notification) const;
|
||||
|
||||
signals:
|
||||
void applicationRegistered(Snore::Application*);
|
||||
void applicationDeregistered(Snore::Application*);
|
||||
void applicationRegistered(const Snore::Application&);
|
||||
void applicationDeregistered(const Snore::Application&);
|
||||
void notify(Snore::Notification noti);
|
||||
|
||||
private slots:
|
||||
|
@ -56,7 +56,7 @@ private:
|
|||
SnoreCore *q_ptr;
|
||||
Hint m_hints;
|
||||
|
||||
ApplicationsList m_applications;
|
||||
QHash<QString,Application> m_applications;
|
||||
|
||||
|
||||
QStringList m_notificationBackends;
|
||||
|
|
|
@ -66,19 +66,19 @@ bool Growl::init(SnoreCore *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);
|
||||
growl->set_gntp_callback(callback);
|
||||
|
||||
// qDebug() << Q_FUNC_INFO << application->name().toUtf8().constData();
|
||||
std::vector<std::string> alerts;
|
||||
foreach(Alert *a,application->alerts())
|
||||
foreach(const Alert &a,application.alerts())
|
||||
{
|
||||
// qDebug() << Q_FUNC_INFO << a->name().toUtf8().constData();
|
||||
alerts.push_back(a->name().toUtf8().constData());
|
||||
alerts.push_back(a.name().toUtf8().constData());
|
||||
}
|
||||
|
||||
try
|
||||
|
@ -88,12 +88,12 @@ void Growl::slotRegisterApplication(Application *application)
|
|||
{
|
||||
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)
|
||||
{
|
||||
return;
|
||||
|
|
|
@ -44,8 +44,8 @@ private:
|
|||
gntp *m_defaultGNTP;
|
||||
|
||||
public slots:
|
||||
void slotRegisterApplication(Snore::Application *application);
|
||||
void slotDeregisterApplication(Snore::Application *application);
|
||||
void slotRegisterApplication(const Snore::Application &application);
|
||||
void slotDeregisterApplication(const Snore::Application &application);
|
||||
void slotNotify(Snore::Notification notification);
|
||||
};
|
||||
|
||||
|
|
|
@ -55,7 +55,8 @@ public:
|
|||
if(msg->message == SNARL_GLOBAL_MESSAGE){
|
||||
int action = msg->wParam;
|
||||
if(action == SnarlEnums::SnarlLaunched){
|
||||
foreach(Application *a,m_snarl->snore()->aplications()){
|
||||
foreach(const Application &a,m_snarl->snore()->aplications())
|
||||
{
|
||||
m_snarl->slotRegisterApplication(a);
|
||||
}
|
||||
}
|
||||
|
@ -160,36 +161,38 @@ bool SnarlBackend::init(SnoreCore *snore){
|
|||
return SnoreBackend::init(snore);
|
||||
}
|
||||
|
||||
void SnarlBackend::slotRegisterApplication(Application *application){
|
||||
void SnarlBackend::slotRegisterApplication(const Application &application){
|
||||
SnarlInterface *snarlInterface = NULL;
|
||||
if(m_applications.contains(application->name())){
|
||||
snarlInterface = m_applications.value(application->name());
|
||||
}else{
|
||||
snarlInterface = new SnarlInterface();
|
||||
m_applications.insert(application->name(),snarlInterface);
|
||||
if(m_applications.contains(application.name()))
|
||||
{
|
||||
snarlInterface = m_applications.value(application.name());
|
||||
}
|
||||
qDebug()<<"Register with Snarl"<<application->name();
|
||||
QString appName = application->name();
|
||||
appName = appName.replace(" ","_");//app sig must not contain spaces
|
||||
else
|
||||
{
|
||||
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(),
|
||||
application->name().toUtf8().constData(),
|
||||
application->icon().localUrl().toUtf8().constData(),
|
||||
application.name().toUtf8().constData(),
|
||||
application.icon().localUrl().toUtf8().constData(),
|
||||
0,(HWND)m_eventLoop->winId(),SNORENOTIFIER_MESSAGE_ID);
|
||||
|
||||
foreach(Alert *alert,application->alerts()){
|
||||
qDebug()<<"registering snarl alert"<<application->name();
|
||||
snarlInterface->AddClass(alert->name().toUtf8().constData(),
|
||||
alert->name().toUtf8().constData(),
|
||||
0,0,alert->icon().localUrl().toUtf8().constData());
|
||||
foreach(const Alert &alert,application.alerts())
|
||||
{
|
||||
snarlInterface->AddClass(alert.name().toUtf8().constData(),
|
||||
alert.name().toUtf8().constData(),
|
||||
0,0,alert.icon().localUrl().toUtf8().constData());
|
||||
}
|
||||
}
|
||||
|
||||
void SnarlBackend::slotDeregisterApplication(Application *application){
|
||||
SnarlInterface *snarlInterface = m_applications.take(application->name());
|
||||
void SnarlBackend::slotDeregisterApplication(const Application &application){
|
||||
SnarlInterface *snarlInterface = m_applications.take(application.name());
|
||||
if(snarlInterface == NULL)
|
||||
{
|
||||
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());
|
||||
delete snarlInterface;
|
||||
}
|
||||
|
@ -225,14 +228,17 @@ void SnarlBackend::slotNotify(Notification notification){
|
|||
!notification.icon().isLocalFile()?notification.icon().imageData().toBase64().constData():0,
|
||||
priority);
|
||||
|
||||
foreach(const Notification::Action *a, notification.actions()){
|
||||
snarlInterface->AddAction(id,a->name().toUtf8().constData(),QString("@").append(QString::number(a->id())).toUtf8().constData());
|
||||
foreach(const Notification::Action &a, notification.actions())
|
||||
{
|
||||
snarlInterface->AddAction(id,a.name().toUtf8().constData(),QString("@").append(QString::number(a.id())).toUtf8().constData());
|
||||
}
|
||||
m_idMap[notification.id()] = id;
|
||||
qDebug() << "snarl" << id << notification.id();
|
||||
startTimeout(notification.id(),notification.timeout());
|
||||
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
//update message
|
||||
snarlInterface->Update(m_idMap[notification.updateID()],
|
||||
notification.alert().toUtf8().constData(),
|
||||
|
|
|
@ -41,8 +41,8 @@ private:
|
|||
Snarl::V42::SnarlInterface* m_defautSnarlinetrface;
|
||||
|
||||
public slots:
|
||||
void slotRegisterApplication(Snore::Application *application);
|
||||
void slotDeregisterApplication(Snore::Application *application);
|
||||
void slotRegisterApplication(const Snore::Application &application);
|
||||
void slotDeregisterApplication(const Snore::Application &application);
|
||||
void slotNotify(Snore::Notification notification);
|
||||
void slotCloseNotification(Snore::Notification notification);
|
||||
|
||||
|
|
|
@ -55,9 +55,9 @@ bool FreedesktopFrontend::init(SnoreCore *snore){
|
|||
}
|
||||
|
||||
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
|
||||
Icon appIcon(":/root/images/freedesktop-dbus.png");
|
||||
#endif
|
||||
Application *a = new Application(app_name,appIcon);
|
||||
a->addAlert(new Alert("DBus Alert","DBus Alert",appIcon));
|
||||
Application a(app_name,appIcon);
|
||||
a.addAlert(Alert("DBus Alert","DBus Alert",appIcon));
|
||||
snore()->registerApplication(a);
|
||||
}
|
||||
|
||||
|
@ -105,8 +105,9 @@ uint FreedesktopFrontend::Notify(const QString &app_name, uint replaces_id,
|
|||
noti.setUpdateID(replaces_id);
|
||||
}
|
||||
noti.setSource(this);
|
||||
for(int i = 0;i < actions.length(); i+=2){
|
||||
noti.addAction(new Notification::Action(actions.at(i).toInt(),actions.at(i+1)));
|
||||
for(int i = 0;i < actions.length(); i+=2)
|
||||
{
|
||||
noti.addAction(Notification::Action(actions.at(i).toInt(),actions.at(i+1)));
|
||||
}
|
||||
|
||||
snore()->broadcastNotification(noti);
|
||||
|
|
|
@ -122,21 +122,26 @@ SnarlNotification Parser::parse(QString &msg,QTcpSocket* client){
|
|||
|
||||
|
||||
switch(action){
|
||||
case NOTIFICATION:{
|
||||
case NOTIFICATION:
|
||||
{
|
||||
qDebug() << sNotification.notification.application();
|
||||
Application * appl = snarl->snore()->aplications().value(sNotification.notification.application());
|
||||
if(!snarl->snore()->aplications().contains(appl->name())){
|
||||
const Application &appl = snarl->snore()->aplications().value(sNotification.notification.application());
|
||||
if(!snarl->snore()->aplications().contains(appl.name()))
|
||||
{
|
||||
snarl->snore()->registerApplication(appl);
|
||||
}
|
||||
|
||||
if(!appl->alerts().value(sNotification.notification.alert())->isActive())
|
||||
if(!appl.alerts().value(sNotification.notification.alert()).isActive())
|
||||
{
|
||||
break;
|
||||
}
|
||||
sNotification.isNotification = true;
|
||||
return sNotification;
|
||||
break;
|
||||
}
|
||||
case ADD_CLASS:
|
||||
if(sNotification.notification.alert().isEmpty()){
|
||||
if(sNotification.notification.alert().isEmpty())
|
||||
{
|
||||
qDebug()<<"Error registering alert with empty name";
|
||||
break;
|
||||
}
|
||||
|
@ -144,7 +149,7 @@ SnarlNotification Parser::parse(QString &msg,QTcpSocket* client){
|
|||
{
|
||||
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;
|
||||
case REGISTER:
|
||||
if(!sNotification.notification.application().isEmpty() && !snarl->m_applications.contains(sNotification.notification.application())){
|
||||
|
|
|
@ -56,10 +56,14 @@ bool SnarlNetworkFrontend::init(SnoreCore *snore){
|
|||
void SnarlNetworkFrontend::actionInvoked(Notification notification){
|
||||
//TODO:fix callback
|
||||
SnarlNotification sn=notifications.value(notification.id());
|
||||
if(notification.actionInvoked()->id() == 1 )
|
||||
if(notification.actionInvoked().id() == 1 )
|
||||
{
|
||||
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/");
|
||||
}
|
||||
}
|
||||
void SnarlNetworkFrontend::notificationClosed(Notification notification){
|
||||
SnarlNotification sn=notifications.value(notification.id());
|
||||
|
|
|
@ -70,7 +70,8 @@ void SnoreNotify::save(){
|
|||
|
||||
void SnoreNotify::exit(){
|
||||
qDebug()<<"Saving snore settings";
|
||||
foreach(Application *a,m_snore->aplications()){
|
||||
foreach(const Application &a,m_snore->aplications())
|
||||
{
|
||||
m_snore->deregisterApplication(a);
|
||||
}
|
||||
save();
|
||||
|
|
|
@ -28,49 +28,54 @@
|
|||
|
||||
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){
|
||||
_snore = snore;
|
||||
_trayIcon->setVisible(true);
|
||||
void TrayIcon::initConextMenu(SnoreCore *snore)
|
||||
{
|
||||
m_snore = snore;
|
||||
m_trayIcon->setVisible(true);
|
||||
|
||||
_trayMenu = new QMenu("SnoreNotify");
|
||||
_trayMenu->addAction(QString("SnoreNotify ").append(Version::version()));
|
||||
_trayMenu->addSeparator();
|
||||
connect(_trayMenu->addAction(QString("Test")), SIGNAL(triggered()), this, SLOT(slotTestNotification()));
|
||||
_trayMenu->addSeparator();
|
||||
foreach(const QString &back,_snore->notificationBackends()){
|
||||
QAction *b= new QAction(back,this);
|
||||
connect(b,SIGNAL(triggered()),this,SLOT(setPrimaryBackend()));
|
||||
m_trayMenu = new QMenu("SnoreNotify");
|
||||
m_trayMenu->addAction(QString("SnoreNotify ").append(Version::version()));
|
||||
m_trayMenu->addSeparator();
|
||||
m_trayMenu->addAction("Test Notification", this, SLOT(slotTestNotification()));
|
||||
m_trayMenu->addSeparator();
|
||||
foreach(const QString &back,m_snore->notificationBackends())
|
||||
{
|
||||
QAction *b = m_trayMenu->addAction(back, this, SLOT(setPrimaryBackend()));
|
||||
b->setCheckable(true);
|
||||
if(back == _snore->primaryNotificationBackend())
|
||||
if(back == m_snore->primaryNotificationBackend())
|
||||
{
|
||||
b->setChecked(true);
|
||||
_backendActions.append(b);
|
||||
_trayMenu->addAction(b);
|
||||
}
|
||||
m_backendActions.append(b);
|
||||
}
|
||||
_trayMenu->addSeparator();
|
||||
_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(){
|
||||
_trayIcon->setVisible(false);
|
||||
void TrayIcon::hide()
|
||||
{
|
||||
m_trayIcon->setVisible(false);
|
||||
}
|
||||
|
||||
QSystemTrayIcon* TrayIcon::trayIcon(){
|
||||
return _trayIcon;
|
||||
QSystemTrayIcon* TrayIcon::trayIcon()
|
||||
{
|
||||
return m_trayIcon;
|
||||
}
|
||||
|
||||
void TrayIcon::setPrimaryBackend(){
|
||||
QAction *a= dynamic_cast<QAction*>(sender());
|
||||
_snore->setPrimaryNotificationBackend(a->text());
|
||||
QAction *a = qobject_cast<QAction*>(sender());
|
||||
m_snore->setPrimaryNotificationBackend(a->text());
|
||||
|
||||
foreach(QAction *action,_backendActions){
|
||||
foreach(QAction *action,m_backendActions)
|
||||
{
|
||||
action->setChecked(false);
|
||||
}
|
||||
a->setChecked(true);
|
||||
|
@ -79,7 +84,12 @@ void TrayIcon::setPrimaryBackend(){
|
|||
|
||||
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"));
|
||||
_snore->broadcastNotification(n);
|
||||
n.addAction(Notification::Action(1,"Test Action"));
|
||||
m_snore->broadcastNotification(n);
|
||||
m_snore->deregisterApplication(appl);
|
||||
}
|
||||
|
||||
|
|
|
@ -36,10 +36,10 @@ public:
|
|||
class QSystemTrayIcon* trayIcon();
|
||||
|
||||
private:
|
||||
class QSystemTrayIcon *_trayIcon;
|
||||
class QMenu *_trayMenu;
|
||||
class QList<class QAction*> _backendActions;
|
||||
class Snore::SnoreCore *_snore;
|
||||
class QSystemTrayIcon *m_trayIcon;
|
||||
class QMenu *m_trayMenu;
|
||||
class QList<class QAction*> m_backendActions;
|
||||
class Snore::SnoreCore *m_snore;
|
||||
|
||||
|
||||
public slots:
|
||||
|
|
Loading…
Reference in New Issue