diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index e7c5543..2243c99 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -13,12 +13,14 @@ add_subdirectory(plugins) set ( SnoreNotify_SRCS ${SnoreNotify_SRCS} snore.cpp application.cpp + hint.cpp ${CMAKE_CURRENT_BINARY_DIR}/version.cpp ) set ( SnoreNotify_HDR ${SnoreNotify_HDR} snore.h application.h + hint.h snore_exports.h version.h ) diff --git a/src/core/application.h b/src/core/application.h index 6d120d6..48dc666 100644 --- a/src/core/application.h +++ b/src/core/application.h @@ -30,7 +30,7 @@ class Alert; typedef QHash ApplicationsList ; typedef QHash AlertList; -class SNORE_EXPORT Application:public QObject +class SNORE_EXPORT Application : public QObject { Q_OBJECT public: diff --git a/src/core/hint.cpp b/src/core/hint.cpp new file mode 100644 index 0000000..0aebf91 --- /dev/null +++ b/src/core/hint.cpp @@ -0,0 +1,48 @@ +/* + SnoreNotify is a Notification Framework based on Qt + Copyright (C) 2013 Patrick von Reth + + + 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 . +*/ +#include "hint.h" + +using namespace Snore; + +Hint::Hint(QObject *parent) : + QObject(parent) +{ +} + +void Hint::setValue(const QString &key, const QVariant &value) +{ + m_data[key] = value; +} + +QVariant Hint::value(const QString &key, const QVariant &defaultValue) const +{ + if(m_data.contains(key)) + { + return m_data[key]; + } + else + { + return defaultValue; + } +} + +bool Hint::contains(const QString &key) const +{ + return m_data.contains(key); +} diff --git a/src/core/hint.h b/src/core/hint.h new file mode 100644 index 0000000..b865f9b --- /dev/null +++ b/src/core/hint.h @@ -0,0 +1,46 @@ +/* + SnoreNotify is a Notification Framework based on Qt + Copyright (C) 2013 Patrick von Reth + + + 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 . +*/ +#ifndef HINT_H +#define HINT_H + +#include +#include + + +namespace Snore +{ + + +class Hint : public QObject +{ + Q_OBJECT +public: + explicit Hint(QObject *parent = 0); + + void setValue(const QString &key, const QVariant &value); + QVariant value(const QString & key, const QVariant & defaultValue = QVariant() ) const; + bool contains ( const QString & key ) const; + +private: + QVariantHash m_data; + +}; +} + +#endif // HINT_H diff --git a/src/core/notification/notification.cpp b/src/core/notification/notification.cpp index 6f8e872..96f846d 100644 --- a/src/core/notification/notification.cpp +++ b/src/core/notification/notification.cpp @@ -164,28 +164,14 @@ void Notification::setCloseReason(const NotificationEnums::CloseReasons::closeRe d->m_closeReason = r; } -const QVariant Notification::hint(const QString &key , const QVariant &defaultValue ) const +Hint &Notification::hints() { - if(d->m_hints.contains(key)) - { - return d->m_hints.value ( key ); - } - return defaultValue; -} - -bool Notification::hintExists ( const QString &key ) -{ - return d->m_hints.contains ( key ); -} - -void Notification::insertHint ( const QString &key, const QVariant &val ) -{ - d->m_hints.insert ( key,val ); + return d->m_hints; } void Notification::setSilent(bool silent) { - d->m_hints["silent"] = silent; + d->m_hints.setValue("silent", silent); } bool Notification::isValid() const diff --git a/src/core/notification/notification.h b/src/core/notification/notification.h index 1854362..dbc64e3 100644 --- a/src/core/notification/notification.h +++ b/src/core/notification/notification.h @@ -23,11 +23,10 @@ #include "icon.h" #include "notificationenums.h" +#include "../hint.h" #include #include -#include -#include @@ -79,9 +78,7 @@ public: void addAction(Action *a); const NotificationEnums::CloseReasons::closeReasons &closeReason(); void setCloseReason(const NotificationEnums::CloseReasons::closeReasons &r); - const QVariant hint(const QString &key , const QVariant &defaultValue ) const; - bool hintExists ( const QString &key ); - void insertHint ( const QString &key,const QVariant &val ); + Hint &hints(); void setSilent(bool silent); diff --git a/src/core/notification/notification_p.h b/src/core/notification/notification_p.h index b253012..741f207 100644 --- a/src/core/notification/notification_p.h +++ b/src/core/notification/notification_p.h @@ -4,6 +4,7 @@ #include "notification/icon.h" #include "notification/NotificationEnums.h" +#include "../hint.h" #include @@ -51,7 +52,7 @@ public: NotificationEnums::Prioritys::prioritys m_priority; NotificationEnums::CloseReasons::closeReasons m_closeReason; QHash m_actions; - QVariantHash m_hints; + Hint m_hints; static uint notificationCount; static uint m_idCount; diff --git a/src/core/snore.cpp b/src/core/snore.cpp index ab32dd1..1f6455b 100644 --- a/src/core/snore.cpp +++ b/src/core/snore.cpp @@ -359,3 +359,8 @@ bool SnoreCore::primaryBackendSupportsRichtext() { return m_notificationBackend->supportsRichtext(); } + +Hint &SnoreCore::hints() +{ + return m_hints; +} diff --git a/src/core/snore.h b/src/core/snore.h index 619c169..deb67e6 100644 --- a/src/core/snore.h +++ b/src/core/snore.h @@ -24,12 +24,15 @@ #include "application.h" #include "plugins/plugincontainer.h" #include "notification/notification.h" +#include "hint.h" #include +#include +#include +#include class QSystemTrayIcon; class QDir; -class QSettings; namespace Snore{ @@ -69,7 +72,17 @@ public: bool primaryBackendSupportsRichtext(); + Hint &hints(); +signals: + void applicationInitialized( Snore::Application* ); + void applicationRemoved( Snore::Application* ); + void notify( Snore::Notification noti ); + void actionInvoked( Snore::Notification ); + void notificationClosed(Snore::Notification ); + +private slots: + void slotNotificationClosed(Snore::Notification); private: @@ -78,6 +91,8 @@ private: static QHash s_pluginCache; + Hint m_hints; + ApplicationsList m_applications; @@ -89,18 +104,6 @@ private: QPointer m_notificationBackend; QSystemTrayIcon *m_trayIcon; - - -signals: - void applicationInitialized( Snore::Application* ); - void applicationRemoved( Snore::Application* ); - void notify( Snore::Notification noti ); - void actionInvoked( Snore::Notification ); - void notificationClosed(Snore::Notification ); - -private slots: - void slotNotificationClosed(Snore::Notification); - }; diff --git a/src/plugins/backends/snoretoast/snoretoast.cpp b/src/plugins/backends/snoretoast/snoretoast.cpp index c99550f..86b181d 100644 --- a/src/plugins/backends/snoretoast/snoretoast.cpp +++ b/src/plugins/backends/snoretoast/snoretoast.cpp @@ -32,22 +32,29 @@ bool SnoreToast::init(SnoreCore *snore) qDebug() << "SnoreToast does not work on windows" << QSysInfo::windowsVersion(); return false; } - m_appID = QString("%1.%2.SnoreToast").arg(qApp->organizationName(), qApp->applicationName()).replace(" ",""); + if(snore->hints().contains("WINDOWS_APP_ID")) + { + m_appID = snore->hints().value("WINDOWS_APP_ID"); + } + else + { + m_appID = QString("%1.%2.SnoreToast").arg(qApp->organizationName(), qApp->applicationName()).replace(" ",""); - QProcess *p = new QProcess(this); - p->setReadChannelMode(QProcess::MergedChannels); + QProcess *p = new QProcess(this); + p->setReadChannelMode(QProcess::MergedChannels); - QStringList arguements; - arguements << "-install" - << QString("SnoreNotify\\%1").arg(qApp->applicationName()) - << QDir::toNativeSeparators(qApp->applicationFilePath()) - << m_appID; - qDebug() << "SnoreToast" << arguements; - p->start("SnoreToast", arguements); - p->waitForFinished(-1); - qDebug() << p->readAll(); - if(p->exitCode() != 0) - return false; + QStringList arguements; + arguements << "-install" + << QString("SnoreNotify\\%1").arg(qApp->applicationName()) + << QDir::toNativeSeparators(qApp->applicationFilePath()) + << m_appID; + qDebug() << "SnoreToast" << arguements; + p->start("SnoreToast", arguements); + p->waitForFinished(-1); + qDebug() << p->readAll(); + if(p->exitCode() != 0) + return false; + } return SnoreBackend::init(snore); } @@ -82,7 +89,7 @@ void SnoreToast::slotNotify(Notification notification) << "-appID" << m_appID; ; - if(notification.hint("silent",true).toBool()) + if(notification.hints().value("silent",true).toBool()) { arguements << "-silent"; } diff --git a/src/plugins/frontends/snarlnetwork/parser.cpp b/src/plugins/frontends/snarlnetwork/parser.cpp index 6520e42..59dfaf7 100644 --- a/src/plugins/frontends/snarlnetwork/parser.cpp +++ b/src/plugins/frontends/snarlnetwork/parser.cpp @@ -118,7 +118,7 @@ SnarlNotification Parser::parse(QString &msg,QTcpSocket* client){ sNotification.notification = Notification(app,alert,title,text,icon,timeout); sNotification.notification.setSource(snarl); - sNotification.notification.insertHint("SnarlIcon",sntpIcon); + sNotification.notification.hints().setValue("SnarlIcon", sntpIcon); switch(action){ @@ -159,17 +159,21 @@ SnarlNotification Parser::parse(QString &msg,QTcpSocket* client){ sNotification.vailid=false; break; } - sNotification.notification.insertHint("SnarlAction",sNotification.action); + sNotification.notification.hints().setValue("SnarlAction", sNotification.action); return sNotification; } QString Parser::downloadIcon(const QString &address){ if(address=="") + { return ""; + } if(address.startsWith("file://")) + { return QString(address.mid(7)); + } QByteArray arr=address.toUtf8(); - QUrl url=QUrl::fromEncoded(arr); + QUrl url = QUrl::fromEncoded(arr); QCryptographicHash hash(QCryptographicHash::Md5); hash.addData(arr);