revorked hints system, added hints to snorecore

This commit is contained in:
Patrick von Reth 2013-07-23 12:00:51 +02:00
parent bfe963cb64
commit 6fb3f561ff
11 changed files with 154 additions and 55 deletions

View File

@ -13,12 +13,14 @@ add_subdirectory(plugins)
set ( SnoreNotify_SRCS ${SnoreNotify_SRCS} set ( SnoreNotify_SRCS ${SnoreNotify_SRCS}
snore.cpp snore.cpp
application.cpp application.cpp
hint.cpp
${CMAKE_CURRENT_BINARY_DIR}/version.cpp ${CMAKE_CURRENT_BINARY_DIR}/version.cpp
) )
set ( SnoreNotify_HDR ${SnoreNotify_HDR} set ( SnoreNotify_HDR ${SnoreNotify_HDR}
snore.h snore.h
application.h application.h
hint.h
snore_exports.h snore_exports.h
version.h version.h
) )

View File

@ -30,7 +30,7 @@ class Alert;
typedef QHash<QString,Application*> ApplicationsList ; typedef QHash<QString,Application*> ApplicationsList ;
typedef QHash<QString,Alert*> AlertList; typedef QHash<QString,Alert*> AlertList;
class SNORE_EXPORT Application:public QObject class SNORE_EXPORT Application : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:

48
src/core/hint.cpp Normal file
View File

@ -0,0 +1,48 @@
/*
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013 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 "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);
}

46
src/core/hint.h Normal file
View File

@ -0,0 +1,46 @@
/*
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013 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 HINT_H
#define HINT_H
#include <QObject>
#include <QVariantHash>
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

View File

@ -164,28 +164,14 @@ void Notification::setCloseReason(const NotificationEnums::CloseReasons::closeRe
d->m_closeReason = r; 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;
{
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 );
} }
void Notification::setSilent(bool silent) void Notification::setSilent(bool silent)
{ {
d->m_hints["silent"] = silent; d->m_hints.setValue("silent", silent);
} }
bool Notification::isValid() const bool Notification::isValid() const

View File

@ -23,11 +23,10 @@
#include "icon.h" #include "icon.h"
#include "notificationenums.h" #include "notificationenums.h"
#include "../hint.h"
#include <QVariant> #include <QVariant>
#include <QDebug> #include <QDebug>
#include <QTextDocumentFragment>
#include <QTextDocument>
@ -79,9 +78,7 @@ public:
void addAction(Action *a); void addAction(Action *a);
const NotificationEnums::CloseReasons::closeReasons &closeReason(); const NotificationEnums::CloseReasons::closeReasons &closeReason();
void setCloseReason(const NotificationEnums::CloseReasons::closeReasons &r); void setCloseReason(const NotificationEnums::CloseReasons::closeReasons &r);
const QVariant hint(const QString &key , const QVariant &defaultValue ) const; Hint &hints();
bool hintExists ( const QString &key );
void insertHint ( const QString &key,const QVariant &val );
void setSilent(bool silent); void setSilent(bool silent);

View File

@ -4,6 +4,7 @@
#include "notification/icon.h" #include "notification/icon.h"
#include "notification/NotificationEnums.h" #include "notification/NotificationEnums.h"
#include "../hint.h"
#include <QSharedData> #include <QSharedData>
@ -51,7 +52,7 @@ public:
NotificationEnums::Prioritys::prioritys m_priority; NotificationEnums::Prioritys::prioritys m_priority;
NotificationEnums::CloseReasons::closeReasons m_closeReason; NotificationEnums::CloseReasons::closeReasons m_closeReason;
QHash<int,Notification::Action*> m_actions; QHash<int,Notification::Action*> m_actions;
QVariantHash m_hints; Hint m_hints;
static uint notificationCount; static uint notificationCount;
static uint m_idCount; static uint m_idCount;

View File

@ -359,3 +359,8 @@ bool SnoreCore::primaryBackendSupportsRichtext()
{ {
return m_notificationBackend->supportsRichtext(); return m_notificationBackend->supportsRichtext();
} }
Hint &SnoreCore::hints()
{
return m_hints;
}

View File

@ -24,12 +24,15 @@
#include "application.h" #include "application.h"
#include "plugins/plugincontainer.h" #include "plugins/plugincontainer.h"
#include "notification/notification.h" #include "notification/notification.h"
#include "hint.h"
#include <QStringList> #include <QStringList>
#include <QSettings>
#include <QTextDocument>
#include <QTextDocumentFragment>
class QSystemTrayIcon; class QSystemTrayIcon;
class QDir; class QDir;
class QSettings;
namespace Snore{ namespace Snore{
@ -69,7 +72,17 @@ public:
bool primaryBackendSupportsRichtext(); 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: private:
@ -78,6 +91,8 @@ private:
static QHash<QString,PluginContainer*> s_pluginCache; static QHash<QString,PluginContainer*> s_pluginCache;
Hint m_hints;
ApplicationsList m_applications; ApplicationsList m_applications;
@ -89,18 +104,6 @@ private:
QPointer<SnoreBackend> m_notificationBackend; QPointer<SnoreBackend> m_notificationBackend;
QSystemTrayIcon *m_trayIcon; 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);
}; };

View File

@ -32,22 +32,29 @@ bool SnoreToast::init(SnoreCore *snore)
qDebug() << "SnoreToast does not work on windows" << QSysInfo::windowsVersion(); qDebug() << "SnoreToast does not work on windows" << QSysInfo::windowsVersion();
return false; 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); QProcess *p = new QProcess(this);
p->setReadChannelMode(QProcess::MergedChannels); p->setReadChannelMode(QProcess::MergedChannels);
QStringList arguements; QStringList arguements;
arguements << "-install" arguements << "-install"
<< QString("SnoreNotify\\%1").arg(qApp->applicationName()) << QString("SnoreNotify\\%1").arg(qApp->applicationName())
<< QDir::toNativeSeparators(qApp->applicationFilePath()) << QDir::toNativeSeparators(qApp->applicationFilePath())
<< m_appID; << m_appID;
qDebug() << "SnoreToast" << arguements; qDebug() << "SnoreToast" << arguements;
p->start("SnoreToast", arguements); p->start("SnoreToast", arguements);
p->waitForFinished(-1); p->waitForFinished(-1);
qDebug() << p->readAll(); qDebug() << p->readAll();
if(p->exitCode() != 0) if(p->exitCode() != 0)
return false; return false;
}
return SnoreBackend::init(snore); return SnoreBackend::init(snore);
} }
@ -82,7 +89,7 @@ void SnoreToast::slotNotify(Notification notification)
<< "-appID" << "-appID"
<< m_appID; << m_appID;
; ;
if(notification.hint("silent",true).toBool()) if(notification.hints().value("silent",true).toBool())
{ {
arguements << "-silent"; arguements << "-silent";
} }

View File

@ -118,7 +118,7 @@ SnarlNotification Parser::parse(QString &msg,QTcpSocket* client){
sNotification.notification = Notification(app,alert,title,text,icon,timeout); sNotification.notification = Notification(app,alert,title,text,icon,timeout);
sNotification.notification.setSource(snarl); sNotification.notification.setSource(snarl);
sNotification.notification.insertHint("SnarlIcon",sntpIcon); sNotification.notification.hints().setValue("SnarlIcon", sntpIcon);
switch(action){ switch(action){
@ -159,17 +159,21 @@ SnarlNotification Parser::parse(QString &msg,QTcpSocket* client){
sNotification.vailid=false; sNotification.vailid=false;
break; break;
} }
sNotification.notification.insertHint("SnarlAction",sNotification.action); sNotification.notification.hints().setValue("SnarlAction", sNotification.action);
return sNotification; return sNotification;
} }
QString Parser::downloadIcon(const QString &address){ QString Parser::downloadIcon(const QString &address){
if(address=="") if(address=="")
{
return ""; return "";
}
if(address.startsWith("file://")) if(address.startsWith("file://"))
{
return QString(address.mid(7)); return QString(address.mid(7));
}
QByteArray arr=address.toUtf8(); QByteArray arr=address.toUtf8();
QUrl url=QUrl::fromEncoded(arr); QUrl url = QUrl::fromEncoded(arr);
QCryptographicHash hash(QCryptographicHash::Md5); QCryptographicHash hash(QCryptographicHash::Md5);
hash.addData(arr); hash.addData(arr);