more doc and cleanup

This commit is contained in:
Patrick von Reth 2014-01-20 11:27:14 +01:00
parent 0b46a81f35
commit 48ec634993
9 changed files with 86 additions and 83 deletions

View File

@ -733,7 +733,7 @@ WARN_LOGFILE =
# spaces. # spaces.
# Note: If this tag is empty the current directory is searched. # 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 # 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 # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses

View File

@ -44,6 +44,14 @@ public:
const QHash<QString,Alert> &alerts() const; const QHash<QString,Alert> &alerts() const;
bool isValid() const; bool isValid() const;
/**
* Application specific hints:
* <table>
* <tr><td>desktop-entry</td><td>The name of the desktop enty associated with the application</td><td>Used for The freedesktop backend</td></tr>
* <tr><td>windows-app-id</td><td>The app id associated with the application</td><td>Needed for the Windows 8 backend <a href="http://msdn.microsoft.com/en-us/library/windows/apps/dd378459.aspx">See MSDN</a></td></tr>
* </table>
* @return the hints
*/
Hint &hints(); Hint &hints();
const Hint &constHints() const; const Hint &constHints() const;
private: private:

View File

@ -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) 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)) if(m_data.contains(key))
{ {
return m_data[key]; return m_data.value(key);
} }
else else
{ {
@ -48,7 +44,32 @@ QVariant Hint::value(const QString &key, const QVariant &defaultValue) const
bool Hint::contains(const QString &key) 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<const void*,QString>(owner,key.toLower()), value);
}
QVariant Hint::privateValue(const void *owner, const QString &k, const QVariant &defaultValue) const
{
QPair<const void*,QString> 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<const void*,QString>(owner,key.toLower()));
} }
QDebug operator<<( QDebug debug, const Snore::Hint &hint ) QDebug operator<<( QDebug debug, const Snore::Hint &hint )
@ -73,29 +94,3 @@ QDebug operator<<( QDebug debug, const Snore::Hint &hint )
debug << ")" ; debug << ")" ;
return debug.maybeSpace(); return debug.maybeSpace();
} }
void Hint::setPrivateValue(const void *owner, const QString &key, const QVariant &value)
{
m_privateData.insert(QPair<const void*,QString>(owner,key), value);
}
QVariant Hint::privateValue(const void *owner, const QString &k, const QVariant &defaultValue) const
{
QPair<const void*,QString> 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<const void*,QString>(owner,key));
}

View File

@ -34,13 +34,14 @@ SNORE_EXPORT QDebug operator<< ( QDebug, const Snore::Hint &);
namespace Snore namespace Snore
{ {
/**
* Hint contains extra information for Notifications and Applications
*/
class SNORE_EXPORT Hint class SNORE_EXPORT Hint
{ {
public: public:
Hint(); Hint();
Hint(const Hint &other);
void setValue(const QString &key, const QVariant &value); void setValue(const QString &key, const QVariant &value);
QVariant value(const QString & key, const QVariant & defaultValue = QVariant() ) const; QVariant value(const QString & key, const QVariant & defaultValue = QVariant() ) const;

View File

@ -263,12 +263,6 @@ bool SnoreCore::primaryBackendSupportsRichtext()
return d->m_notificationBackend->supportsRichtext(); return d->m_notificationBackend->supportsRichtext();
} }
Hint &SnoreCore::hints()
{
Q_D(SnoreCore);
return d->m_hints;
}
const SnoreCorePrivate *SnoreCore::d() const SnoreCorePrivate *SnoreCore::d()
{ {
Q_D(SnoreCore); Q_D(SnoreCore);

View File

@ -166,12 +166,6 @@ public:
*/ */
bool primaryBackendSupportsRichtext(); 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. * @return a pointer to the private class, for internal use only.

View File

@ -60,7 +60,6 @@ private slots:
private: private:
SnoreCore *q_ptr; SnoreCore *q_ptr;
Hint m_hints;
QHash<QString,Application> m_applications; QHash<QString,Application> m_applications;

View File

@ -33,32 +33,6 @@ bool SnoreToast::initialize(SnoreCore *snore)
snoreDebug( SNORE_DEBUG ) << "SnoreToast does not work on windows" << QSysInfo::windowsVersion(); snoreDebug( SNORE_DEBUG ) << "SnoreToast does not work on windows" << QSysInfo::windowsVersion();
return false; 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); return SnoreBackend::initialize(snore);
} }
@ -83,7 +57,7 @@ void SnoreToast::slotNotify(Notification notification)
} }
arguements << "-w" arguements << "-w"
<< "-appID" << "-appID"
<< m_appID; << appId(notification.application());
; ;
if(notification.hints().value("silent",true).toBool()) if(notification.hints().value("silent",true).toBool())
{ {
@ -95,10 +69,36 @@ void SnoreToast::slotNotify(Notification notification)
p->setProperty("SNORE_NOTIFICATION_ID",notification.id()); 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) void SnoreToast::slotToastNotificationClosed(int code, QProcess::ExitStatus)
{ {
QProcess *p = qobject_cast<QProcess*>(sender()); QProcess *p = qobject_cast<QProcess*>(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; NotificationEnums::CloseReasons::closeReason reason = NotificationEnums::CloseReasons::CLOSED;
@ -126,3 +126,14 @@ void SnoreToast::slotToastNotificationClosed(int code, QProcess::ExitStatus)
closeNotification(n,reason); 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;
}

View File

@ -16,12 +16,13 @@ public:
public slots: public slots:
void slotNotify(Snore::Notification notification); void slotNotify(Snore::Notification notification);
void slotRegisterApplication(const Snore::Application &application);
private slots: private slots:
void slotToastNotificationClosed(int code, QProcess::ExitStatus); void slotToastNotificationClosed(int code, QProcess::ExitStatus);
private: private:
QString m_appID; QString appId(const Snore::Application &application);
}; };