make a notification not only contain the name of alert and application but the objects themselfe
This commit is contained in:
parent
570208f8dd
commit
5ef936cfb2
|
@ -16,6 +16,9 @@ set ( SnoreNotify_SRCS ${SnoreNotify_SRCS}
|
|||
snore.cpp
|
||||
snore_p.cpp
|
||||
application.cpp
|
||||
application_p.cpp
|
||||
alert.cpp
|
||||
alert_p.cpp
|
||||
hint.cpp
|
||||
${CMAKE_CURRENT_BINARY_DIR}/version.cpp
|
||||
${SNORENOTIFY_RCS}
|
||||
|
@ -25,6 +28,7 @@ set ( SnoreNotify_HDR ${SnoreNotify_HDR}
|
|||
snore.h
|
||||
snore_p.h
|
||||
application.h
|
||||
alert.h
|
||||
hint.h
|
||||
snore_exports.h
|
||||
version.h
|
||||
|
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2014 Patrick von Reth <vonreth@kde.org>
|
||||
|
||||
|
||||
SnoreNotify is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
SnoreNotify is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with SnoreNotify. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "alert.h"
|
||||
#include "alert_p.h"
|
||||
|
||||
using namespace Snore;
|
||||
|
||||
Alert::Alert() :
|
||||
d(NULL)
|
||||
{}
|
||||
|
||||
Alert::Alert (const QString &name, const QString &title, const Icon &icon, bool active):
|
||||
d(new AlertData(name, title, icon, active))
|
||||
{}
|
||||
|
||||
Alert::Alert(const Alert &other):
|
||||
d(other.d)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Alert &Alert::operator=(const Alert &other)
|
||||
{
|
||||
d = other.d;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Alert::~Alert()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
QString Alert::name() const
|
||||
{
|
||||
return d->m_name;
|
||||
}
|
||||
|
||||
QString Alert::title() const
|
||||
{
|
||||
return d->m_title;
|
||||
}
|
||||
|
||||
const Icon &Alert::icon() const
|
||||
{
|
||||
return d->m_icon;
|
||||
}
|
||||
|
||||
bool Alert::isActive() const
|
||||
{
|
||||
return d->m_active;
|
||||
}
|
||||
|
||||
bool Alert::isValid() const
|
||||
{
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
QDebug operator<<(QDebug debug, const Alert &alert)
|
||||
{
|
||||
if(alert.isValid())
|
||||
{
|
||||
debug << "Snore::Alert(" << alert.name() << ", " << alert.title() << ")" ;
|
||||
}
|
||||
else
|
||||
{
|
||||
debug << "Snore::Alert(0x00)" ;
|
||||
}
|
||||
return debug.maybeSpace();
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2014 Patrick von Reth <vonreth@kde.org>
|
||||
|
||||
|
||||
SnoreNotify is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
SnoreNotify is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with SnoreNotify. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef ALERT_H
|
||||
#define ALERT_H
|
||||
|
||||
#include "snore_exports.h"
|
||||
#include "notification/icon.h"
|
||||
|
||||
#include <QSharedData>
|
||||
|
||||
namespace Snore{
|
||||
|
||||
class AlertData;
|
||||
|
||||
class SNORE_EXPORT Alert
|
||||
{
|
||||
friend class AlertData;
|
||||
public:
|
||||
Alert();
|
||||
Alert(const QString &name, const QString &title="", const Icon &icon = Icon(":/root/snore.png"), bool active=true );
|
||||
Alert(const Alert &other);
|
||||
Alert &operator=(const Alert &other);
|
||||
~Alert();
|
||||
|
||||
QString name() const;
|
||||
QString title() const;
|
||||
const Icon &icon() const;
|
||||
bool isActive() const;
|
||||
bool isValid() const;
|
||||
private:
|
||||
QExplicitlySharedDataPointer<AlertData> d;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
QDebug operator<< ( QDebug debug, const Snore::Alert &alert );
|
||||
|
||||
|
||||
#endif // ALERT_H
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2014 Patrick von Reth <vonreth@kde.org>
|
||||
|
||||
|
||||
SnoreNotify is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
SnoreNotify is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with SnoreNotify. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "alert_p.h"
|
||||
|
||||
using namespace Snore;
|
||||
|
||||
AlertData::AlertData(const QString &name, const QString &title, const Icon &icon, bool active):
|
||||
m_name(name),
|
||||
m_title(title),
|
||||
m_icon(icon),
|
||||
m_active(active)
|
||||
{
|
||||
}
|
||||
|
||||
AlertData::~AlertData()
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2014 Patrick von Reth <vonreth@kde.org>
|
||||
|
||||
|
||||
SnoreNotify is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
SnoreNotify is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with SnoreNotify. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef ALERT_P_H
|
||||
#define ALERT_P_H
|
||||
|
||||
#include <QString>
|
||||
#include <QSharedData>
|
||||
|
||||
#include "alert.h"
|
||||
|
||||
namespace Snore
|
||||
{
|
||||
class AlertData : public QSharedData
|
||||
{
|
||||
friend class Alert;
|
||||
public:
|
||||
AlertData(const QString &name, const QString &title, const Icon &icon, bool active);
|
||||
~AlertData();
|
||||
|
||||
QString m_name;
|
||||
QString m_title;
|
||||
Icon m_icon;
|
||||
bool m_active;
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(AlertData)
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif // ALERT_P_H
|
|
@ -18,27 +18,32 @@
|
|||
*/
|
||||
|
||||
#include "application.h"
|
||||
#include "application_p.h"
|
||||
|
||||
|
||||
using namespace Snore;
|
||||
|
||||
Application::Application():
|
||||
d(NULL)
|
||||
{}
|
||||
|
||||
Application::Application (const QString &name, const Icon &icon) :
|
||||
m_name(name),
|
||||
m_icon(icon)
|
||||
d(new ApplicationData(name,icon))
|
||||
|
||||
{
|
||||
}
|
||||
|
||||
Application::Application(const Application &other):
|
||||
m_name(other.m_name),
|
||||
m_icon(other.m_icon),
|
||||
m_alerts(other.m_alerts),
|
||||
m_hint(other.m_hint)
|
||||
d(other.d)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Application::Application()
|
||||
{}
|
||||
Application &Application::operator=(const Application &other)
|
||||
{
|
||||
d = other.d;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Application::~Application()
|
||||
{
|
||||
|
@ -46,81 +51,35 @@ Application::~Application()
|
|||
|
||||
void Application::addAlert(const Alert &alert)
|
||||
{
|
||||
m_alerts.insert(alert.name(), alert);
|
||||
d->m_alerts.insert(alert.name(), alert);
|
||||
}
|
||||
|
||||
QString Application::name() const
|
||||
{
|
||||
return m_name;
|
||||
return d->m_name;
|
||||
}
|
||||
|
||||
const Icon &Application::icon()const
|
||||
{
|
||||
return m_icon;
|
||||
return d->m_icon;
|
||||
}
|
||||
|
||||
const QHash<QString, Alert> &Application::alerts() const
|
||||
{
|
||||
return m_alerts;
|
||||
return d->m_alerts;
|
||||
}
|
||||
|
||||
bool Application::isValid() const
|
||||
{
|
||||
return m_name.isNull();
|
||||
return d;
|
||||
}
|
||||
|
||||
Hint &Application::hints()
|
||||
{
|
||||
return m_hint;
|
||||
return d->m_hint;
|
||||
}
|
||||
|
||||
const Hint &Application::hints() const
|
||||
{
|
||||
return m_hint;
|
||||
}
|
||||
|
||||
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)
|
||||
{}
|
||||
|
||||
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 )
|
||||
{}
|
||||
|
||||
|
||||
QString Alert::name() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
QString Alert::title() const
|
||||
{
|
||||
return m_title;
|
||||
}
|
||||
|
||||
const Icon &Alert::icon() const
|
||||
{
|
||||
return m_icon;
|
||||
}
|
||||
|
||||
bool Alert::isActive() const
|
||||
{
|
||||
return m_active;
|
||||
}
|
||||
|
||||
bool Alert::isValid() const
|
||||
{
|
||||
return m_name.isNull();
|
||||
return d->m_hint;
|
||||
}
|
||||
|
|
|
@ -22,28 +22,12 @@
|
|||
#include "snore_exports.h"
|
||||
#include "hint.h"
|
||||
#include "notification/icon.h"
|
||||
#include "alert.h"
|
||||
|
||||
#include <QHash>
|
||||
namespace Snore{
|
||||
|
||||
class SNORE_EXPORT Alert
|
||||
{
|
||||
public:
|
||||
Alert();
|
||||
Alert ( const QString &name,const QString &title="",const Icon &icon = Icon(":/root/snore.png"),bool active=true );
|
||||
Alert(const Alert &other);
|
||||
|
||||
QString name() const;
|
||||
QString title() const;
|
||||
const Icon &icon() const;
|
||||
bool isActive() const;
|
||||
bool isValid() const;
|
||||
private:
|
||||
QString m_name;
|
||||
QString m_title;
|
||||
Icon m_icon;
|
||||
bool m_active;
|
||||
};
|
||||
class ApplicationData;
|
||||
|
||||
class SNORE_EXPORT Application
|
||||
{
|
||||
|
@ -51,6 +35,7 @@ public:
|
|||
Application();
|
||||
Application ( const QString &name, const Icon &icon = Icon(":/root/snore.png"));
|
||||
Application(const Application &other);
|
||||
Application &operator=(const Application &other);
|
||||
~Application();
|
||||
|
||||
void addAlert(const Alert &alert);
|
||||
|
@ -62,14 +47,24 @@ public:
|
|||
Hint &hints();
|
||||
const Hint &hints() const;
|
||||
private:
|
||||
QString m_name;
|
||||
Icon m_icon;
|
||||
QHash<QString,Alert> m_alerts;
|
||||
Hint m_hint;
|
||||
QExplicitlySharedDataPointer<ApplicationData> d;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
inline QDebug operator<< ( QDebug debug, const Snore::Application &app )
|
||||
{
|
||||
if(app.isValid())
|
||||
{
|
||||
debug << "Snore::Application(" << app.name() << ", " << app.alerts() << ")";//," << app.hints() << ")" ;
|
||||
}
|
||||
else
|
||||
{
|
||||
debug << "Snore::Application(0x00)" ;
|
||||
}
|
||||
return debug.maybeSpace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2014 Patrick von Reth <vonreth@kde.org>
|
||||
|
||||
|
||||
SnoreNotify is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
SnoreNotify is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with SnoreNotify. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "application_p.h"
|
||||
|
||||
using namespace Snore;
|
||||
|
||||
ApplicationData::ApplicationData(const QString &name, const Icon &icon):
|
||||
m_name(name),
|
||||
m_icon(icon)
|
||||
{
|
||||
}
|
||||
|
||||
ApplicationData::~ApplicationData()
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2014 Patrick von Reth <vonreth@kde.org>
|
||||
|
||||
|
||||
SnoreNotify is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
SnoreNotify is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with SnoreNotify. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef APPLICATION_P_H
|
||||
#define APPLICATION_P_H
|
||||
|
||||
#include <QString>
|
||||
#include <QSharedData>
|
||||
|
||||
#include "application.h"
|
||||
|
||||
namespace Snore
|
||||
{
|
||||
class ApplicationData : public QSharedData
|
||||
{
|
||||
public:
|
||||
ApplicationData(const QString &name, const Icon &icon);
|
||||
~ApplicationData();
|
||||
|
||||
QString m_name;
|
||||
Icon m_icon;
|
||||
QHash<QString,Alert> m_alerts;
|
||||
Hint m_hint;
|
||||
};
|
||||
|
||||
}
|
||||
#endif // APPLICATION_P_H
|
|
@ -50,3 +50,9 @@ bool Hint::contains(const QString &key) const
|
|||
{
|
||||
return m_data.contains(key);
|
||||
}
|
||||
|
||||
//QDebug operator<<( QDebug debug, const Snore::Hint &hint )
|
||||
//{
|
||||
// debug << "Snore::Hint(" << hint.m_data << ")" ;
|
||||
// return debug.maybeSpace();
|
||||
//}
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
#include <QObject>
|
||||
#include <QVariantHash>
|
||||
#include <QDebug>
|
||||
|
||||
#include "snore_exports.h"
|
||||
|
||||
|
@ -42,6 +43,10 @@ private:
|
|||
QVariantHash m_data;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // HINT_H
|
||||
|
|
|
@ -71,9 +71,10 @@ Notification::Notification () :
|
|||
{
|
||||
}
|
||||
|
||||
Notification::Notification ( const QString &application, const QString &alert, const QString &title, const QString &text, const Icon &icon, int timeout,NotificationEnums::Prioritys::prioritys priority ):
|
||||
Notification::Notification(const Application &application, const Alert &alert, const QString &title, const QString &text, const Icon &icon, int timeout, NotificationEnums::Prioritys::prioritys priority):
|
||||
d(new NotificationData(application,alert,title,text,icon,timeout,priority))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Notification::Notification ( const Notification &other ) :
|
||||
|
@ -130,7 +131,7 @@ SnoreFrontend *Notification::source() const
|
|||
return d->m_source;
|
||||
}
|
||||
|
||||
QString Notification::application() const
|
||||
Application Notification::application() const
|
||||
{
|
||||
return d->m_application;
|
||||
}
|
||||
|
@ -145,7 +146,7 @@ QString Notification::text() const
|
|||
return d->m_text;
|
||||
}
|
||||
|
||||
QString Notification::alert() const
|
||||
Alert Notification::alert() const
|
||||
{
|
||||
return d->m_alert;
|
||||
}
|
||||
|
|
|
@ -21,9 +21,9 @@
|
|||
#define NOTIFICATION_H
|
||||
#include "../snore_exports.h"
|
||||
#include "icon.h"
|
||||
|
||||
#include "notificationenums.h"
|
||||
#include "../hint.h"
|
||||
#include "../application.h"
|
||||
|
||||
#include <QVariant>
|
||||
#include <QDebug>
|
||||
|
@ -57,7 +57,7 @@ public:
|
|||
|
||||
public:
|
||||
Notification();
|
||||
Notification(const QString &application,const QString &alert,const QString &title,const QString &text,const Icon &icon,int timeout=10, NotificationEnums::Prioritys::prioritys priority = NotificationEnums::Prioritys::NORMAL );
|
||||
Notification(const Application &application,const Alert &alert,const QString &title,const QString &text,const Icon &icon,int timeout=10, NotificationEnums::Prioritys::prioritys priority = NotificationEnums::Prioritys::NORMAL );
|
||||
Notification(const Notification &other );
|
||||
Notification &operator=(const Notification &other);
|
||||
~Notification();
|
||||
|
@ -73,11 +73,11 @@ public:
|
|||
const Action &actionInvoked() const;
|
||||
void setSource(class SnoreFrontend *source);
|
||||
class SnoreFrontend *source() const;
|
||||
QString application() const;
|
||||
Application application() const;
|
||||
QString title() const;
|
||||
QString text() const;
|
||||
const Icon &icon() const;
|
||||
QString alert() const;
|
||||
Alert alert() const;
|
||||
void setSticky();
|
||||
bool sticky() const;
|
||||
const NotificationEnums::Prioritys::prioritys &priority() const;
|
||||
|
|
|
@ -31,17 +31,17 @@ uint NotificationData::notificationCount = 0;
|
|||
|
||||
uint NotificationData::m_idCount = 1;
|
||||
|
||||
NotificationData::NotificationData ( const QString &application,const QString &alert,const QString &title,const QString &text,const Icon &icon,
|
||||
int timeout,NotificationEnums::Prioritys::prioritys priority ):
|
||||
NotificationData::NotificationData (const Snore::Application &application, const Snore::Alert &alert, const QString &title, const QString &text, const Icon &icon,
|
||||
int timeout, NotificationEnums::Prioritys::prioritys priority ):
|
||||
m_id ( m_idCount++ ),
|
||||
m_updateID(0),
|
||||
m_timeout ( timeout ),
|
||||
m_source ( NULL),
|
||||
m_timeout( timeout ),
|
||||
m_source( NULL),
|
||||
m_application ( application ),
|
||||
m_alert ( alert ),
|
||||
m_title ( title ),
|
||||
m_text ( text ),
|
||||
m_icon ( icon ),
|
||||
m_alert( alert ),
|
||||
m_title( title ),
|
||||
m_text( text ),
|
||||
m_icon( icon ),
|
||||
m_priority(priority),
|
||||
m_closeReason(NotificationEnums::CloseReasons::NONE)
|
||||
{
|
||||
|
|
|
@ -34,7 +34,7 @@ class SNORE_EXPORT NotificationData : public QSharedData
|
|||
{
|
||||
friend class Notification;
|
||||
public:
|
||||
NotificationData ( const QString &application,const QString &alert,const QString &title,const QString &text,const Icon &icon,
|
||||
NotificationData ( const Application &application,const Alert &alert,const QString &title,const QString &text,const Icon &icon,
|
||||
int timeout,NotificationEnums::Prioritys::prioritys priority );
|
||||
|
||||
~NotificationData();
|
||||
|
@ -47,9 +47,9 @@ private:
|
|||
uint m_id;
|
||||
uint m_updateID;
|
||||
int m_timeout;
|
||||
SnoreFrontend *m_source;
|
||||
QString m_application;
|
||||
QString m_alert;
|
||||
SnoreFrontend *m_source;
|
||||
Application m_application;
|
||||
Alert m_alert;
|
||||
QString m_title;
|
||||
QString m_text;
|
||||
Icon m_icon;
|
||||
|
@ -59,6 +59,8 @@ private:
|
|||
QHash<int,Notification::Action> m_actions;
|
||||
Hint m_hints;
|
||||
|
||||
|
||||
|
||||
static uint notificationCount;
|
||||
static uint m_idCount;
|
||||
static int notificationMetaID;
|
||||
|
|
|
@ -103,8 +103,8 @@ void Growl::slotDeregisterApplication(const Application &application)
|
|||
|
||||
void Growl::slotNotify(Notification notification)
|
||||
{
|
||||
gntp *growl = m_applications.value(notification.application());
|
||||
QString alert = notification.alert();
|
||||
gntp *growl = m_applications.value(notification.application().name());
|
||||
QString alert = notification.alert().name();
|
||||
if(growl == NULL)
|
||||
{
|
||||
growl = m_defaultGNTP;
|
||||
|
|
|
@ -198,7 +198,7 @@ void SnarlBackend::slotDeregisterApplication(const Application &application){
|
|||
}
|
||||
|
||||
void SnarlBackend::slotNotify(Notification notification){
|
||||
SnarlInterface *snarlInterface = m_applications.value(notification.application());
|
||||
SnarlInterface *snarlInterface = m_applications.value(notification.application().name());
|
||||
if(snarlInterface == NULL){
|
||||
qDebug()<<notification.application()<<"not in snarl interfaces, defaulting";
|
||||
qDebug()<<m_applications.keys();
|
||||
|
@ -220,7 +220,7 @@ void SnarlBackend::slotNotify(Notification notification){
|
|||
}
|
||||
|
||||
if(notification.updateID() == 0){
|
||||
ULONG32 id = snarlInterface->Notify(notification.alert().toUtf8().constData(),
|
||||
ULONG32 id = snarlInterface->Notify(notification.alert().name().toUtf8().constData(),
|
||||
Snore::toPlainText(notification.title()).toUtf8().constData(),
|
||||
Snore::toPlainText(notification.text()).toUtf8().constData(),
|
||||
notification.timeout(),
|
||||
|
@ -241,7 +241,7 @@ void SnarlBackend::slotNotify(Notification notification){
|
|||
{
|
||||
//update message
|
||||
snarlInterface->Update(m_idMap[notification.updateID()],
|
||||
notification.alert().toUtf8().constData(),
|
||||
notification.alert().name().toUtf8().constData(),
|
||||
Snore::toPlainText(notification.title()).toUtf8().constData(),
|
||||
Snore::toPlainText(notification.text()).toUtf8().constData(),
|
||||
notification.timeout(),
|
||||
|
|
|
@ -39,6 +39,7 @@ FreedesktopFrontend::FreedesktopFrontend():
|
|||
SnoreFrontend("Freedesktop")
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
FreedesktopFrontend::~FreedesktopFrontend(){
|
||||
|
@ -72,6 +73,7 @@ uint FreedesktopFrontend::Notify(const QString &app_name, uint replaces_id,
|
|||
const QStringList &actions, const QVariantMap &hints, int timeout)
|
||||
{
|
||||
Icon icon;
|
||||
Application app;
|
||||
NotificationEnums::Prioritys::prioritys priotity = NotificationEnums::Prioritys::NORMAL;
|
||||
|
||||
if(hints.contains("image_data")){
|
||||
|
@ -84,22 +86,28 @@ uint FreedesktopFrontend::Notify(const QString &app_name, uint replaces_id,
|
|||
icon = Icon(":/root/images/freedesktop-dbus.png");
|
||||
}
|
||||
|
||||
if(!snore()->aplications().contains(app_name)){
|
||||
if(!snore()->aplications().contains(app_name))
|
||||
{
|
||||
#ifdef HAVE_KDE
|
||||
Icon appIcon(KIconLoader::global()->iconPath(app_icon, KIconLoader::Desktop));
|
||||
#else
|
||||
Icon appIcon(":/root/images/freedesktop-dbus.png");
|
||||
#endif
|
||||
Application a(app_name,appIcon);
|
||||
a.addAlert(Alert("DBus Alert","DBus Alert",appIcon));
|
||||
snore()->registerApplication(a);
|
||||
Alert alert("DBus Alert","DBus Alert",appIcon);
|
||||
app = Application(app_name,appIcon);
|
||||
app.addAlert(alert);
|
||||
snore()->registerApplication(app);
|
||||
}
|
||||
else
|
||||
{
|
||||
app = snore()->aplications()[app_name];
|
||||
}
|
||||
|
||||
if (hints.contains("urgency")) {
|
||||
priotity = NotificationEnums::Prioritys::prioritys(hints["urgency"].toInt()-1);
|
||||
}
|
||||
|
||||
Notification noti(app_name,"DBus Alert",summary,body,icon,timeout==-1?Notification::defaultTimeout():timeout/1000,priotity);
|
||||
Notification noti(app, *app.alerts().begin(), summary, body, icon, timeout==-1?Notification::defaultTimeout():timeout/1000, priotity);
|
||||
if(replaces_id != 0)
|
||||
{
|
||||
noti.setUpdateID(replaces_id);
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#ifndef FREEDESKTOPNOTIFICATION_FRONTEND_H
|
||||
#define FREEDESKTOPNOTIFICATION_FRONTEND_H
|
||||
#include "core/plugins/snorefrontend.h"
|
||||
#include "core/application.h"
|
||||
#include <QtDBus>
|
||||
|
||||
class FreedesktopFrontend:public Snore::SnoreFrontend{
|
||||
|
@ -43,6 +44,10 @@ signals:
|
|||
void NotificationClosed( uint id, uint reason );
|
||||
void ActionInvoked( uint id, const QString& actionKey );
|
||||
|
||||
private:
|
||||
Snore::Alert m_alert;
|
||||
Snore::Icon m_icon;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -73,48 +73,76 @@ SnarlNotification Parser::parse(QString &msg,QTcpSocket* client){
|
|||
sNotification.httpClient=true;
|
||||
}
|
||||
|
||||
QString app;
|
||||
QString appName;
|
||||
QString title;
|
||||
QString text;
|
||||
QString sntpIcon;
|
||||
QString icon;
|
||||
QString alert;
|
||||
QString alertName;
|
||||
int timeout=10;
|
||||
|
||||
QString key;
|
||||
QString value;
|
||||
QStringList splitted=msg.split("#?");
|
||||
foreach(QString s,splitted){
|
||||
key=s.mid(0,s.indexOf("=")).toLower();
|
||||
value=s.mid(s.indexOf("=")+1);
|
||||
key = s.mid(0,s.indexOf("=")).toLower();
|
||||
value = s.mid(s.indexOf("=")+1);
|
||||
switch(getSnpType.value(key)){
|
||||
case APP:
|
||||
app=value;
|
||||
appName = value;
|
||||
break;
|
||||
case ACTION:
|
||||
action=getSnpType.value(value);
|
||||
sNotification.action=value;
|
||||
action = getSnpType.value(value);
|
||||
sNotification.action = value;
|
||||
break;
|
||||
case TITLE:
|
||||
title=value;
|
||||
title = value;
|
||||
break;
|
||||
case TEXT:
|
||||
text=value;
|
||||
text = value;
|
||||
break;
|
||||
case ICON:
|
||||
sntpIcon=value;
|
||||
icon=downloadIcon(value);
|
||||
sntpIcon = value;
|
||||
icon = downloadIcon(value);
|
||||
break;
|
||||
case CLASS:
|
||||
alert=value;
|
||||
alertName = value;
|
||||
case TIMEOUT:
|
||||
timeout=value.toInt();
|
||||
timeout = value.toInt();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Application app;
|
||||
Alert alert;
|
||||
if(snarl->m_applications.contains(value))
|
||||
{
|
||||
app = snarl->m_applications[value];
|
||||
}
|
||||
else
|
||||
{
|
||||
app = Application(value, icon);
|
||||
}
|
||||
|
||||
if(app.alerts().contains(alertName))
|
||||
{
|
||||
alert = app.alerts()[alertName];
|
||||
}
|
||||
else
|
||||
{
|
||||
if(title.isEmpty())
|
||||
{
|
||||
alert = Alert(alertName, alertName);
|
||||
}
|
||||
else
|
||||
{
|
||||
alert = Alert(alertName, title);
|
||||
}
|
||||
}
|
||||
|
||||
sNotification.notification = Notification(app,alert,title,text,icon,timeout);
|
||||
sNotification.notification.setSource(snarl);
|
||||
|
||||
|
@ -125,13 +153,13 @@ SnarlNotification Parser::parse(QString &msg,QTcpSocket* client){
|
|||
case NOTIFICATION:
|
||||
{
|
||||
qDebug() << sNotification.notification.application();
|
||||
const Application &appl = snarl->snore()->aplications().value(sNotification.notification.application());
|
||||
const Application &appl = sNotification.notification.application();
|
||||
if(!snarl->snore()->aplications().contains(appl.name()))
|
||||
{
|
||||
snarl->snore()->registerApplication(appl);
|
||||
}
|
||||
|
||||
if(!appl.alerts().value(sNotification.notification.alert()).isActive())
|
||||
if(!sNotification.notification.alert().isActive())
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
@ -140,26 +168,25 @@ SnarlNotification Parser::parse(QString &msg,QTcpSocket* client){
|
|||
break;
|
||||
}
|
||||
case ADD_CLASS:
|
||||
if(sNotification.notification.alert().isEmpty())
|
||||
if(!sNotification.notification.alert().isValid())
|
||||
{
|
||||
qDebug()<<"Error registering alert with empty name";
|
||||
break;
|
||||
}
|
||||
if(title.isEmpty())
|
||||
{
|
||||
title = alert;
|
||||
}
|
||||
snarl->m_applications.value(sNotification.notification.application())->addAlert(Alert(alert,title));
|
||||
sNotification.notification.application().addAlert(sNotification.notification.alert());
|
||||
break;
|
||||
case REGISTER:
|
||||
if(!sNotification.notification.application().isEmpty() && !snarl->m_applications.contains(sNotification.notification.application())){
|
||||
snarl->m_applications.insert(sNotification.notification.application(), new Application(sNotification.notification.application()));
|
||||
if(sNotification.notification.application().isValid() && !snarl->m_applications.contains(sNotification.notification.application().name()))
|
||||
{
|
||||
snarl->m_applications.insert(sNotification.notification.application().name(), sNotification.notification.application());
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug()<<sNotification.notification.application()<<"already registred";
|
||||
}
|
||||
break;
|
||||
case UNREGISTER:
|
||||
snarl->snore()->deregisterApplication( snarl->snore()->aplications().value(sNotification.notification.application()) );
|
||||
snarl->snore()->deregisterApplication( sNotification.notification.application());
|
||||
break;
|
||||
case ERROR:
|
||||
default:
|
||||
|
|
|
@ -61,7 +61,7 @@ private:
|
|||
class QTcpServer *tcpServer;
|
||||
Parser *parser;
|
||||
QHash<uint,SnarlNotification> notifications;
|
||||
QHash<QString,Snore::Application*> m_applications;
|
||||
QHash<QString,Snore::Application> m_applications;
|
||||
|
||||
void callback(const SnarlNotification &sn,QString msg);
|
||||
|
||||
|
|
|
@ -85,9 +85,10 @@ void TrayIcon::setPrimaryBackend(){
|
|||
void TrayIcon::slotTestNotification()
|
||||
{
|
||||
Application appl("SnoreNotify");
|
||||
appl.addAlert(Alert("Default"));
|
||||
Alert alert("Default");
|
||||
appl.addAlert(alert);
|
||||
m_snore->registerApplication(appl);
|
||||
Notification n("SnoreNotify","Default","Hello World","This is Snore",Icon(":/root/snore.png"));
|
||||
Notification n(appl, alert, "Hello World", "This is Snore", Icon(":/root/snore.png"));
|
||||
n.addAction(Notification::Action(1,"Test Action"));
|
||||
m_snore->broadcastNotification(n);
|
||||
m_snore->deregisterApplication(appl);
|
||||
|
|
Loading…
Reference in New Issue