From 48ec6349931c460558913ad683efc529567e6b23 Mon Sep 17 00:00:00 2001 From: Patrick von Reth Date: Mon, 20 Jan 2014 11:27:14 +0100 Subject: [PATCH] more doc and cleanup --- Doxyfile.in | 4 +- src/core/application.h | 8 +++ src/core/hint.cpp | 65 +++++++++--------- src/core/hint.h | 9 +-- src/core/snore.cpp | 6 -- src/core/snore.h | 6 -- src/core/snore_p.h | 1 - .../backends/snoretoast/snoretoast.cpp | 67 +++++++++++-------- src/plugins/backends/snoretoast/snoretoast.h | 3 +- 9 files changed, 86 insertions(+), 83 deletions(-) diff --git a/Doxyfile.in b/Doxyfile.in index 695929f..a5809e4 100644 --- a/Doxyfile.in +++ b/Doxyfile.in @@ -733,7 +733,7 @@ WARN_LOGFILE = # spaces. # Note: If this tag is empty the current directory is searched. -INPUT = "@CMAKE_CURRENT_SOURCE_DIR@/src/" +INPUT = "@CMAKE_CURRENT_SOURCE_DIR@/src/core" # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses @@ -768,7 +768,7 @@ RECURSIVE = YES # Note that relative paths are relative to the directory from which doxygen is # run. -EXCLUDE = +EXCLUDE = # The EXCLUDE_SYMLINKS tag can be used to select whether or not files or # directories that are symbolic links (a Unix file system feature) are excluded diff --git a/src/core/application.h b/src/core/application.h index cb29ad7..2b6cb6a 100644 --- a/src/core/application.h +++ b/src/core/application.h @@ -44,6 +44,14 @@ public: const QHash &alerts() const; bool isValid() const; + /** + * Application specific hints: + * + * + * + *
desktop-entryThe name of the desktop enty associated with the applicationUsed for The freedesktop backend
windows-app-idThe app id associated with the applicationNeeded for the Windows 8 backend See MSDN
+ * @return the hints + */ Hint &hints(); const Hint &constHints() const; private: diff --git a/src/core/hint.cpp b/src/core/hint.cpp index aef00a6..55cd5d9 100644 --- a/src/core/hint.cpp +++ b/src/core/hint.cpp @@ -24,21 +24,17 @@ Hint::Hint() { } -Hint::Hint(const Hint &other): - m_data(other.m_data) -{ -} - void Hint::setValue(const QString &key, const QVariant &value) { - m_data[key] = value; + m_data.insert(key.toLower(), value); } -QVariant Hint::value(const QString &key, const QVariant &defaultValue) const +QVariant Hint::value(const QString &k, const QVariant &defaultValue) const { + QString key(k.toLower()); if(m_data.contains(key)) { - return m_data[key]; + return m_data.value(key); } else { @@ -48,7 +44,32 @@ QVariant Hint::value(const QString &key, const QVariant &defaultValue) const bool Hint::contains(const QString &key) const { - return m_data.contains(key); + return m_data.contains(key.toLower()); +} + +void Hint::setPrivateValue(const void *owner, const QString &key, const QVariant &value) +{ + m_privateData.insert(QPair(owner,key.toLower()), value); +} + + +QVariant Hint::privateValue(const void *owner, const QString &k, const QVariant &defaultValue) const +{ + QPair key(owner,k.toLower()); + if(m_privateData.contains(key)) + { + return m_privateData.value(key); + } + else + { + return defaultValue; + } +} + + +bool Hint::containsPrivateValue(const void *owner, const QString &key) const +{ + return m_privateData.contains(QPair(owner,key.toLower())); } QDebug operator<<( QDebug debug, const Snore::Hint &hint ) @@ -73,29 +94,3 @@ QDebug operator<<( QDebug debug, const Snore::Hint &hint ) debug << ")" ; return debug.maybeSpace(); } - - -void Hint::setPrivateValue(const void *owner, const QString &key, const QVariant &value) -{ - m_privateData.insert(QPair(owner,key), value); -} - - -QVariant Hint::privateValue(const void *owner, const QString &k, const QVariant &defaultValue) const -{ - QPair key(owner,k); - if(m_privateData.contains(key)) - { - return m_privateData.value(key); - } - else - { - return defaultValue; - } -} - - -bool Hint::containsPrivateValue(const void *owner, const QString &key) const -{ - return m_privateData.contains(QPair(owner,key)); -} diff --git a/src/core/hint.h b/src/core/hint.h index b76c5d8..4347b39 100644 --- a/src/core/hint.h +++ b/src/core/hint.h @@ -34,13 +34,14 @@ SNORE_EXPORT QDebug operator<< ( QDebug, const Snore::Hint &); namespace Snore { - +/** + * Hint contains extra information for Notifications and Applications + */ class SNORE_EXPORT Hint { public: Hint(); - Hint(const Hint &other); void setValue(const QString &key, const QVariant &value); QVariant value(const QString & key, const QVariant & defaultValue = QVariant() ) const; @@ -49,13 +50,13 @@ public: void setPrivateValue(const void *owner, const QString &key, const QVariant &value); QVariant privateValue(const void *owner, const QString & key, const QVariant & defaultValue = QVariant() ) const; bool containsPrivateValue(const void *owner, const QString & key ) const; - + private: QVariantHash m_data; QHash, QVariant> m_privateData; friend SNORE_EXPORT QDebug (::operator<<) ( QDebug, const Snore::Hint &); - + }; diff --git a/src/core/snore.cpp b/src/core/snore.cpp index c2af0d2..8e3ddc7 100644 --- a/src/core/snore.cpp +++ b/src/core/snore.cpp @@ -263,12 +263,6 @@ bool SnoreCore::primaryBackendSupportsRichtext() return d->m_notificationBackend->supportsRichtext(); } -Hint &SnoreCore::hints() -{ - Q_D(SnoreCore); - return d->m_hints; -} - const SnoreCorePrivate *SnoreCore::d() { Q_D(SnoreCore); diff --git a/src/core/snore.h b/src/core/snore.h index 6e94f47..262ecb6 100644 --- a/src/core/snore.h +++ b/src/core/snore.h @@ -166,12 +166,6 @@ public: */ bool primaryBackendSupportsRichtext(); - /** - * @deprecated Use Application::hints() instead - * @return a Hint object which contains extra information used by the backends etc. - */ - SNORE_DEPRECATED Hint &hints(); - /** * * @return a pointer to the private class, for internal use only. diff --git a/src/core/snore_p.h b/src/core/snore_p.h index 404ea81..e55b13d 100644 --- a/src/core/snore_p.h +++ b/src/core/snore_p.h @@ -60,7 +60,6 @@ private slots: private: SnoreCore *q_ptr; - Hint m_hints; QHash m_applications; diff --git a/src/plugins/backends/snoretoast/snoretoast.cpp b/src/plugins/backends/snoretoast/snoretoast.cpp index af87e92..0f9e640 100644 --- a/src/plugins/backends/snoretoast/snoretoast.cpp +++ b/src/plugins/backends/snoretoast/snoretoast.cpp @@ -33,32 +33,6 @@ bool SnoreToast::initialize(SnoreCore *snore) snoreDebug( SNORE_DEBUG ) << "SnoreToast does not work on windows" << QSysInfo::windowsVersion(); return false; } - if(snore->hints().contains("WINDOWS_APP_ID")) - { - m_appID = snore->hints().value("WINDOWS_APP_ID").toString(); - } - else - { - m_appID = QString("%1.%2.SnoreToast").arg(qApp->organizationName(), qApp->applicationName()).remove(" "); - - 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; - snoreDebug( SNORE_DEBUG ) << "SnoreToast" << arguements; - p->start("SnoreToast", arguements); - p->waitForFinished(-1); - snoreDebug( SNORE_DEBUG ) << p->readAll(); - if(p->exitCode() != 0) - { - return false; - } - } - return SnoreBackend::initialize(snore); } @@ -83,7 +57,7 @@ void SnoreToast::slotNotify(Notification notification) } arguements << "-w" << "-appID" - << m_appID; + << appId(notification.application()); ; if(notification.hints().value("silent",true).toBool()) { @@ -95,10 +69,36 @@ void SnoreToast::slotNotify(Notification notification) p->setProperty("SNORE_NOTIFICATION_ID",notification.id()); } +void SnoreToast::slotRegisterApplication(const Application &application) +{ + if(!application.constHints().contains("windows_app_id")) + { + QProcess *p = new QProcess(this); + p->setReadChannelMode(QProcess::MergedChannels); + + QStringList arguements; + arguements << "-install" + << QString("SnoreNotify\\%1").arg(qApp->applicationName()) + << QDir::toNativeSeparators(qApp->applicationFilePath()) + << appId(application); + snoreDebug( SNORE_DEBUG ) << "SnoreToast" << arguements; + p->start("SnoreToast", arguements); + + connect(p,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(slotToastNotificationClosed(int,QProcess::ExitStatus))); + connect(qApp,SIGNAL(aboutToQuit()),p,SLOT(kill())); + } +} + void SnoreToast::slotToastNotificationClosed(int code, QProcess::ExitStatus) { QProcess *p = qobject_cast(sender()); - Notification n = getActiveNotificationByID(p->property("SNORE_NOTIFICATION_ID").toUInt()); + bool ok; + Notification n = getActiveNotificationByID(p->property("SNORE_NOTIFICATION_ID").toUInt(&ok)); + snoreDebug( SNORE_DEBUG ) << p->readAll(); + if(!ok) + { + return; + } NotificationEnums::CloseReasons::closeReason reason = NotificationEnums::CloseReasons::CLOSED; @@ -126,3 +126,14 @@ void SnoreToast::slotToastNotificationClosed(int code, QProcess::ExitStatus) closeNotification(n,reason); } + +QString SnoreToast::appId(const Application &application) +{ + + QString appID = application.constHints().value("windows_app_id").toString(); + if(appID.isEmpty()) + { + appID = QString("%1.%2.SnoreToast").arg(qApp->organizationName(), qApp->applicationName()).remove(" "); + } + return appID; +} diff --git a/src/plugins/backends/snoretoast/snoretoast.h b/src/plugins/backends/snoretoast/snoretoast.h index 13dc954..5a2357a 100644 --- a/src/plugins/backends/snoretoast/snoretoast.h +++ b/src/plugins/backends/snoretoast/snoretoast.h @@ -16,12 +16,13 @@ public: public slots: void slotNotify(Snore::Notification notification); + void slotRegisterApplication(const Snore::Application &application); private slots: void slotToastNotificationClosed(int code, QProcess::ExitStatus); private: - QString m_appID; + QString appId(const Snore::Application &application); };