diff --git a/src/core/hint.cpp b/src/core/hint.cpp index 0aebf91..a7f2b63 100644 --- a/src/core/hint.cpp +++ b/src/core/hint.cpp @@ -1,48 +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); -} +/* + 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 index 41a13ab..0df6a10 100644 --- a/src/core/hint.h +++ b/src/core/hint.h @@ -1,47 +1,47 @@ -/* - 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 - -#include "snore_exports.h" - -namespace Snore -{ - - -class SNORE_EXPORT 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 +/* + 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 + +#include "snore_exports.h" + +namespace Snore +{ + + +class SNORE_EXPORT 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/icon.cpp b/src/core/notification/icon.cpp index bb6a832..a269b86 100644 --- a/src/core/notification/icon.cpp +++ b/src/core/notification/icon.cpp @@ -1,117 +1,117 @@ -/**************************************************************************************** - * Copyright (c) 2011-2012 Patrick von Reth * - * * - * This program is free software; you can redistribute it and/or modify it under * - * the terms of the GNU General Public License as published by the Free Software * - * Foundation; either version 2 of the License, or (at your option) any later * - * version. * - * * - * This program 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 General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License along with * - * this program. If not, see . * - ****************************************************************************************/ - -#include "icon.h" -#include "../snore.h" - -#include "notification/icon_p.h" - -using namespace Snore; - - -QHash Icon::m_localImageCache; - -Icon::Icon() : - d(NULL) -{ -} - -Icon::Icon(const QImage &img): - d(new IconData(img)) -{ -} - -Icon::Icon(const QString &url): - d(new IconData(url)) -{ -} - -Icon::Icon(const Icon &other): - d(other.d) -{ -} - -Icon &Icon::operator=(const Icon &other) -{ - d = other.d; - return *this; -} - -Icon::~Icon() -{ - -} - -const QImage &Icon::image() const{ - if(d->m_img.isNull()){ - d->m_img = QImage(d->m_url); - } - return d->m_img; -} - -QString Icon::localUrl()const{ - if(d->m_localUrl.isEmpty()) - { - if(m_localImageCache.contains(hash())) - { - d->m_localUrl = m_localImageCache[hash()]; - } - else - { - d->m_localUrl = QString("%1%2.png").arg(SnoreCore::snoreTMP(), hash()); - image().save(d->m_localUrl ,"PNG"); - m_localImageCache[hash()] = d->m_localUrl; - } - } - return d->m_localUrl; -} - -const QByteArray &Icon::imageData() const{ - if(d->m_data.isEmpty() && !image().isNull()){ - d->setImageData(); - } - return d->m_data; -} - -QString Icon::hash() const{ - if(d->m_isLocalFile) - { - return ""; - } - if(d->m_hash.isEmpty() && !imageData().isNull()){ - d->m_hash = IconData::computeHash(imageData()); - } - return d->m_hash; -} - -bool Icon::isLocalFile() const -{ - return d->m_isLocalFile; -} - -bool Icon::isEmpty() const{ - return d->m_hash.isEmpty() && d->m_img.isNull() && d->m_localUrl.isEmpty(); -} - -bool Icon::isValid() const -{ - return d; -} - -QString Icon::url() const -{ - return d->m_url; -} +/**************************************************************************************** + * Copyright (c) 2011-2012 Patrick von Reth * + * * + * This program is free software; you can redistribute it and/or modify it under * + * the terms of the GNU General Public License as published by the Free Software * + * Foundation; either version 2 of the License, or (at your option) any later * + * version. * + * * + * This program 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License along with * + * this program. If not, see . * + ****************************************************************************************/ + +#include "icon.h" +#include "../snore.h" + +#include "notification/icon_p.h" + +using namespace Snore; + + +QHash Icon::m_localImageCache; + +Icon::Icon() : + d(NULL) +{ +} + +Icon::Icon(const QImage &img): + d(new IconData(img)) +{ +} + +Icon::Icon(const QString &url): + d(new IconData(url)) +{ +} + +Icon::Icon(const Icon &other): + d(other.d) +{ +} + +Icon &Icon::operator=(const Icon &other) +{ + d = other.d; + return *this; +} + +Icon::~Icon() +{ + +} + +const QImage &Icon::image() const{ + if(d->m_img.isNull()){ + d->m_img = QImage(d->m_url); + } + return d->m_img; +} + +QString Icon::localUrl()const{ + if(d->m_localUrl.isEmpty()) + { + if(m_localImageCache.contains(hash())) + { + d->m_localUrl = m_localImageCache[hash()]; + } + else + { + d->m_localUrl = QString("%1%2.png").arg(SnoreCore::snoreTMP(), hash()); + image().save(d->m_localUrl ,"PNG"); + m_localImageCache[hash()] = d->m_localUrl; + } + } + return d->m_localUrl; +} + +const QByteArray &Icon::imageData() const{ + if(d->m_data.isEmpty() && !image().isNull()){ + d->setImageData(); + } + return d->m_data; +} + +QString Icon::hash() const{ + if(d->m_isLocalFile) + { + return ""; + } + if(d->m_hash.isEmpty() && !imageData().isNull()){ + d->m_hash = IconData::computeHash(imageData()); + } + return d->m_hash; +} + +bool Icon::isLocalFile() const +{ + return d->m_isLocalFile; +} + +bool Icon::isEmpty() const{ + return d->m_hash.isEmpty() && d->m_img.isNull() && d->m_localUrl.isEmpty(); +} + +bool Icon::isValid() const +{ + return d; +} + +QString Icon::url() const +{ + return d->m_url; +} diff --git a/src/core/notification/icon.h b/src/core/notification/icon.h index ad8e6b9..36db79c 100644 --- a/src/core/notification/icon.h +++ b/src/core/notification/icon.h @@ -1,70 +1,70 @@ -/**************************************************************************************** - * Copyright (c) 2011-2012 Patrick von Reth * - * * - * This program is free software; you can redistribute it and/or modify it under * - * the terms of the GNU General Public License as published by the Free Software * - * Foundation; either version 2 of the License, or (at your option) any later * - * version. * - * * - * This program 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 General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License along with * - * this program. If not, see . * - ****************************************************************************************/ - -#ifndef NOTIFICATION_ICON_H -#define NOTIFICATION_ICON_H -#include "../snore_exports.h" - -#include -#include - -namespace Snore{ - -class IconData; - -class SNORE_EXPORT Icon -{ -public: - Icon(); - Icon(const QImage &img); - Icon(const class QString &url); - Icon(const Icon &other); - Icon &operator=(const Icon &other); - ~Icon(); - - const QImage &image() const; - QString localUrl() const; - QString url() const; - const QByteArray &imageData() const ; - QString hash() const; - bool isLocalFile() const; - bool isEmpty() const; - bool isValid() const; - - -private: - static QHash m_localImageCache; - - QExplicitlySharedDataPointer d; -}; -} - - -inline QDebug operator<< ( QDebug debug, const Snore::Icon &icon ) -{ - if(icon.isValid()) - { - debug << "Snore::Icon(" << icon.url() << ")" ; - } - else - { - debug << "Snore::Icon(0x00)" ; - } - return debug.maybeSpace(); -} - - -#endif // NOTIFICATION_ICON_H +/**************************************************************************************** + * Copyright (c) 2011-2012 Patrick von Reth * + * * + * This program is free software; you can redistribute it and/or modify it under * + * the terms of the GNU General Public License as published by the Free Software * + * Foundation; either version 2 of the License, or (at your option) any later * + * version. * + * * + * This program 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License along with * + * this program. If not, see . * + ****************************************************************************************/ + +#ifndef NOTIFICATION_ICON_H +#define NOTIFICATION_ICON_H +#include "../snore_exports.h" + +#include +#include + +namespace Snore{ + +class IconData; + +class SNORE_EXPORT Icon +{ +public: + Icon(); + Icon(const QImage &img); + Icon(const class QString &url); + Icon(const Icon &other); + Icon &operator=(const Icon &other); + ~Icon(); + + const QImage &image() const; + QString localUrl() const; + QString url() const; + const QByteArray &imageData() const ; + QString hash() const; + bool isLocalFile() const; + bool isEmpty() const; + bool isValid() const; + + +private: + static QHash m_localImageCache; + + QExplicitlySharedDataPointer d; +}; +} + + +inline QDebug operator<< ( QDebug debug, const Snore::Icon &icon ) +{ + if(icon.isValid()) + { + debug << "Snore::Icon(" << icon.url() << ")" ; + } + else + { + debug << "Snore::Icon(0x00)" ; + } + return debug.maybeSpace(); +} + + +#endif // NOTIFICATION_ICON_H diff --git a/src/core/notification/icon_p.h b/src/core/notification/icon_p.h index 4f1e57d..a8f0d60 100644 --- a/src/core/notification/icon_p.h +++ b/src/core/notification/icon_p.h @@ -1,79 +1,79 @@ -#ifndef ICONDATA_H -#define ICONDATA_H - - -#include "notification.h" - -#include -#include -#include -#include -#include -#include -#include - -namespace Snore{ - -class IconData : public QSharedData -{ -public: - IconData(const QString &url): - m_url(url), - m_isLocalFile(false) - { - if(m_url.startsWith(":/")) - { - m_hash = computeHash(m_url.toLatin1()); - } - else if(QFile(url).exists()) - { - m_isLocalFile = true; - m_localUrl = url; - } - } - - IconData(const QImage &img): - m_img(img), - m_isLocalFile(false) - { - setImageData(); - } - - ~IconData() - { - - } - - void setImageData() - { - QBuffer buffer( &m_data ); - buffer.open( QBuffer::WriteOnly ); - m_img.save( &buffer, "PNG" ); - - if(m_hash.isEmpty()) - { - m_hash = computeHash(m_data); - } - } - - static QString computeHash(const QByteArray &data) - { - QCryptographicHash h(QCryptographicHash::Md5); - h.addData(data); - return h.result().toHex(); - } - - QImage m_img; - QByteArray m_data; - QString m_localUrl; - QString m_url; - QString m_hash; - bool m_isLocalFile; - -private: - Q_DISABLE_COPY(IconData) - -}; - -} -#endif // ICONDATA_H +#ifndef ICONDATA_H +#define ICONDATA_H + + +#include "notification.h" + +#include +#include +#include +#include +#include +#include +#include + +namespace Snore{ + +class IconData : public QSharedData +{ +public: + IconData(const QString &url): + m_url(url), + m_isLocalFile(false) + { + if(m_url.startsWith(":/")) + { + m_hash = computeHash(m_url.toLatin1()); + } + else if(QFile(url).exists()) + { + m_isLocalFile = true; + m_localUrl = url; + } + } + + IconData(const QImage &img): + m_img(img), + m_isLocalFile(false) + { + setImageData(); + } + + ~IconData() + { + + } + + void setImageData() + { + QBuffer buffer( &m_data ); + buffer.open( QBuffer::WriteOnly ); + m_img.save( &buffer, "PNG" ); + + if(m_hash.isEmpty()) + { + m_hash = computeHash(m_data); + } + } + + static QString computeHash(const QByteArray &data) + { + QCryptographicHash h(QCryptographicHash::Md5); + h.addData(data); + return h.result().toHex(); + } + + QImage m_img; + QByteArray m_data; + QString m_localUrl; + QString m_url; + QString m_hash; + bool m_isLocalFile; + +private: + Q_DISABLE_COPY(IconData) + +}; + +} +#endif // ICONDATA_H diff --git a/src/core/notification/notification_p.h b/src/core/notification/notification_p.h index 50250c0..0940ca8 100644 --- a/src/core/notification/notification_p.h +++ b/src/core/notification/notification_p.h @@ -1,69 +1,69 @@ -#ifndef NOTIFICATIONDATA_H -#define NOTIFICATIONDATA_H - - -#include "notification/icon.h" -#include "notification/notificationenums.h" -#include "../hint.h" - -#include - -namespace Snore{ - -class NotificationData : public QSharedData -{ - -public: - NotificationData ( const QString &application,const QString &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_application ( application ), - m_alert ( alert ), - m_title ( title ), - m_text ( text ), - m_icon ( icon ), - m_priority(priority), - m_closeReason(NotificationEnums::CloseReasons::NONE), - m_actionInvoked( NULL ) - { - notificationCount++; - qDebug()<< "Creating Notification: ActiveNotifications" << notificationCount << "id" << m_id; - } - - ~NotificationData() - { - notificationCount--; - qDebug() << "Deleting Notification: ActiveNotifications" << notificationCount << "id" << m_id; - } - - - uint m_id; - uint m_updateID; - int m_timeout; - SnoreFrontend *m_source; - QString m_application; - QString m_alert; - QString m_title; - QString m_text; - Icon m_icon; - NotificationEnums::Prioritys::prioritys m_priority; - NotificationEnums::CloseReasons::closeReasons m_closeReason; - Notification::Action *m_actionInvoked; - QHash m_actions; - Hint m_hints; - - static uint notificationCount; - static uint m_idCount; - static int notificationMetaID; - -private: - Q_DISABLE_COPY(NotificationData) - -}; - -} - -#endif // NOTIFICATIONDATA_H +#ifndef NOTIFICATIONDATA_H +#define NOTIFICATIONDATA_H + + +#include "notification/icon.h" +#include "notification/notificationenums.h" +#include "../hint.h" + +#include + +namespace Snore{ + +class NotificationData : public QSharedData +{ + +public: + NotificationData ( const QString &application,const QString &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_application ( application ), + m_alert ( alert ), + m_title ( title ), + m_text ( text ), + m_icon ( icon ), + m_priority(priority), + m_closeReason(NotificationEnums::CloseReasons::NONE), + m_actionInvoked( NULL ) + { + notificationCount++; + qDebug()<< "Creating Notification: ActiveNotifications" << notificationCount << "id" << m_id; + } + + ~NotificationData() + { + notificationCount--; + qDebug() << "Deleting Notification: ActiveNotifications" << notificationCount << "id" << m_id; + } + + + uint m_id; + uint m_updateID; + int m_timeout; + SnoreFrontend *m_source; + QString m_application; + QString m_alert; + QString m_title; + QString m_text; + Icon m_icon; + NotificationEnums::Prioritys::prioritys m_priority; + NotificationEnums::CloseReasons::closeReasons m_closeReason; + Notification::Action *m_actionInvoked; + QHash m_actions; + Hint m_hints; + + static uint notificationCount; + static uint m_idCount; + static int notificationMetaID; + +private: + Q_DISABLE_COPY(NotificationData) + +}; + +} + +#endif // NOTIFICATIONDATA_H diff --git a/src/core/notification/notificationenums.h b/src/core/notification/notificationenums.h index 2b7c307..c9d23de 100644 --- a/src/core/notification/notificationenums.h +++ b/src/core/notification/notificationenums.h @@ -1,51 +1,51 @@ -/* - 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 NOTIFICATIONENUMS_H -#define NOTIFICATIONENUMS_H - -#include - -namespace Snore{ -namespace NotificationEnums{ - -namespace Prioritys{ -enum priority{ - LOW = -1, - NORMAL = 0, - HIGH = +1 -}; -Q_DECLARE_FLAGS(prioritys, priority) -Q_DECLARE_OPERATORS_FOR_FLAGS(prioritys) -} -namespace CloseReasons{ -enum closeReason -{ - NONE = 0, - TIMED_OUT, - DISMISSED, - CLOSED -}; -Q_DECLARE_FLAGS(closeReasons, closeReason) -Q_DECLARE_OPERATORS_FOR_FLAGS(closeReasons) -} -} -} -#endif // NOTIFICATIONENUMS_H +/* + 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 NOTIFICATIONENUMS_H +#define NOTIFICATIONENUMS_H + +#include + +namespace Snore{ +namespace NotificationEnums{ + +namespace Prioritys{ +enum priority{ + LOW = -1, + NORMAL = 0, + HIGH = +1 +}; +Q_DECLARE_FLAGS(prioritys, priority) +Q_DECLARE_OPERATORS_FOR_FLAGS(prioritys) +} +namespace CloseReasons{ +enum closeReason +{ + NONE = 0, + TIMED_OUT, + DISMISSED, + CLOSED +}; +Q_DECLARE_FLAGS(closeReasons, closeReason) +Q_DECLARE_OPERATORS_FOR_FLAGS(closeReasons) +} +} +} +#endif // NOTIFICATIONENUMS_H diff --git a/src/core/plugins/plugincontainer.h b/src/core/plugins/plugincontainer.h index 30025a7..b42f2d4 100644 --- a/src/core/plugins/plugincontainer.h +++ b/src/core/plugins/plugincontainer.h @@ -1,76 +1,76 @@ -/* - 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 PLUGINCONTAINER_H -#define PLUGINCONTAINER_H -#include "../snore_exports.h" - -#include -#include -#include - -namespace Snore{ -class SnoreCore; -class SnorePlugin; -class SnoreFrontend; -class SnoreBackend; -class SnoreSecondaryBackend; - -class SNORE_EXPORT PluginContainer{ -public: - enum PluginType{ - ALL = 0x0,//for loading plugins - BACKEND = 0x1, - SECONDARY_BACKEND = 0x2, - FRONTEND = 0x4, - PLUGIN = 0x8 - }; - Q_DECLARE_FLAGS(PluginTypes, PluginType) - - static QHash pluginCache(); - - PluginContainer(QString fileName,QString pluginName,PluginType type); - ~PluginContainer(); - SnorePlugin *load(); - void unload(); - const QString &file(); - const QString &name(); - PluginContainer::PluginType type(); - - - static PluginContainer::PluginType typeFromString(const QString &t); - static const QStringList &types(); - -private: - static void updatePluginCache(); - static QSettings &cacheFile(); - - static QHash s_pluginCache; - - QPointer m_instance; - QString m_pluginFile; - QString m_pluginName; - PluginContainer::PluginType m_pluginType; -}; -} - -Q_DECLARE_OPERATORS_FOR_FLAGS(Snore::PluginContainer::PluginTypes) - - -#endif//PLUGINCONTAINER_H +/* + 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 PLUGINCONTAINER_H +#define PLUGINCONTAINER_H +#include "../snore_exports.h" + +#include +#include +#include + +namespace Snore{ +class SnoreCore; +class SnorePlugin; +class SnoreFrontend; +class SnoreBackend; +class SnoreSecondaryBackend; + +class SNORE_EXPORT PluginContainer{ +public: + enum PluginType{ + ALL = 0x0,//for loading plugins + BACKEND = 0x1, + SECONDARY_BACKEND = 0x2, + FRONTEND = 0x4, + PLUGIN = 0x8 + }; + Q_DECLARE_FLAGS(PluginTypes, PluginType) + + static QHash pluginCache(); + + PluginContainer(QString fileName,QString pluginName,PluginType type); + ~PluginContainer(); + SnorePlugin *load(); + void unload(); + const QString &file(); + const QString &name(); + PluginContainer::PluginType type(); + + + static PluginContainer::PluginType typeFromString(const QString &t); + static const QStringList &types(); + +private: + static void updatePluginCache(); + static QSettings &cacheFile(); + + static QHash s_pluginCache; + + QPointer m_instance; + QString m_pluginFile; + QString m_pluginName; + PluginContainer::PluginType m_pluginType; +}; +} + +Q_DECLARE_OPERATORS_FOR_FLAGS(Snore::PluginContainer::PluginTypes) + + +#endif//PLUGINCONTAINER_H diff --git a/src/core/plugins/plugins.h b/src/core/plugins/plugins.h index ac152d1..17e588d 100644 --- a/src/core/plugins/plugins.h +++ b/src/core/plugins/plugins.h @@ -1,82 +1,82 @@ -/* - 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 SNORE_PLUGINS_H -#define SNORE_PLUGINS_H -#include "../snore_exports.h" - -#include -#include -#include -#include -#include - -namespace Snore{ -class Application; -class SnoreCore; - - -class SNORE_EXPORT SnorePlugin : public QObject -{ - Q_OBJECT -public: - SnorePlugin ( const QString &name); - virtual ~SnorePlugin(); - virtual bool init( SnoreCore *snore ); - bool isInitialized(); - SnoreCore* snore(); - const QString &name() const; - -protected: - void startTimeout(uint id,int timeout); -private slots: - void notificationTimedOut(); - -private: - SnorePlugin() {} - QString m_name; - bool m_initialized; - QPointer m_snore; - QHash m_timeouts; - QList m_timeout_order; - - -}; - -} -Q_DECLARE_INTERFACE ( Snore::SnorePlugin, - "org.Snore.SnorePlugin/1.0" ) - -//compatability defines to reduce the number of ifdefs to make fiat compile with qt4 and qt5 -#if QT_VERSION >= QT_VERSION_CHECK(5,0,0) -# if defined(Q_EXPORT_PLUGIN) -# undef Q_EXPORT_PLUGIN -# endif -# if defined(Q_EXPORT_PLUGIN2) -# undef Q_EXPORT_PLUGIN2 -# endif -# define Q_EXPORT_PLUGIN(a) -# define Q_EXPORT_PLUGIN2(a, b) -#else -# define Q_PLUGIN_METADATA(a) -#endif - - - -#endif//SNORE_PLUGINS_H +/* + 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 SNORE_PLUGINS_H +#define SNORE_PLUGINS_H +#include "../snore_exports.h" + +#include +#include +#include +#include +#include + +namespace Snore{ +class Application; +class SnoreCore; + + +class SNORE_EXPORT SnorePlugin : public QObject +{ + Q_OBJECT +public: + SnorePlugin ( const QString &name); + virtual ~SnorePlugin(); + virtual bool init( SnoreCore *snore ); + bool isInitialized(); + SnoreCore* snore(); + const QString &name() const; + +protected: + void startTimeout(uint id,int timeout); +private slots: + void notificationTimedOut(); + +private: + SnorePlugin() {} + QString m_name; + bool m_initialized; + QPointer m_snore; + QHash m_timeouts; + QList m_timeout_order; + + +}; + +} +Q_DECLARE_INTERFACE ( Snore::SnorePlugin, + "org.Snore.SnorePlugin/1.0" ) + +//compatability defines to reduce the number of ifdefs to make fiat compile with qt4 and qt5 +#if QT_VERSION >= QT_VERSION_CHECK(5,0,0) +# if defined(Q_EXPORT_PLUGIN) +# undef Q_EXPORT_PLUGIN +# endif +# if defined(Q_EXPORT_PLUGIN2) +# undef Q_EXPORT_PLUGIN2 +# endif +# define Q_EXPORT_PLUGIN(a) +# define Q_EXPORT_PLUGIN2(a, b) +#else +# define Q_PLUGIN_METADATA(a) +#endif + + + +#endif//SNORE_PLUGINS_H diff --git a/src/core/plugins/snorebackend.h b/src/core/plugins/snorebackend.h index 2b37929..9e386bd 100644 --- a/src/core/plugins/snorebackend.h +++ b/src/core/plugins/snorebackend.h @@ -1,96 +1,96 @@ -/* - 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 SNORE_BACKEND_H -#define SNORE_BACKEND_H -#include "../snore_exports.h" -#include "plugins.h" -#include "../notification/notification.h" -#include "../snore.h" - -#include -#include - -namespace Snore{ - -class SNORE_EXPORT SnoreBackend : public SnorePlugin -{ - Q_OBJECT - Q_INTERFACES(Snore::SnorePlugin) -public: - SnoreBackend(const QString &name, bool canCloseNotification, bool supportsRichtext ); - virtual ~SnoreBackend(); - virtual bool init(SnoreCore *snore); - - void requestCloseNotification( Snore::Notification notification,NotificationEnums::CloseReasons::closeReasons reason ); - - Snore::Notification getActiveNotificationByID(uint id); - - bool canCloseNotification(); - bool supportsRichtext(); - -signals: - void closeNotification( Snore::Notification ); - - -public slots: - virtual void slotRegisterApplication ( Snore::Application *application ) = 0; - virtual void slotUnregisterApplication ( Snore::Application *application ) = 0; - virtual void slotNotify ( Snore::Notification notification ) = 0; - virtual void slotCloseNotification ( Snore::Notification notification ); - -protected: - bool m_canCloseNotification; - bool m_supportsRichtext; - void closeNotification(Snore::Notification,Snore::NotificationEnums::CloseReasons::closeReasons); - - -private: - QHash m_activeNotifications; - - void addActiveNotification(Notification n); - friend void SnoreCore::broadcastNotification(Notification notification); - - -}; - -} -Q_DECLARE_INTERFACE ( Snore::SnoreBackend, - "org.Snore.NotificationBackend/1.0" ) - -namespace Snore{ -class SnoreCore; - -class SNORE_EXPORT SnoreSecondaryBackend:public SnoreBackend -{ - Q_OBJECT - Q_INTERFACES(Snore::SnorePlugin Snore::SnoreBackend) -public: - SnoreSecondaryBackend(const QString &name, bool supportsRhichtext); - virtual ~SnoreSecondaryBackend(); - virtual bool init(SnoreCore *snore); - -}; - -} - -Q_DECLARE_INTERFACE ( Snore::SnoreSecondaryBackend, - "org.Snore.SecondaryNotificationBackend/1.0" ) - -#endif//SNORE_BACKEND_H +/* + 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 SNORE_BACKEND_H +#define SNORE_BACKEND_H +#include "../snore_exports.h" +#include "plugins.h" +#include "../notification/notification.h" +#include "../snore.h" + +#include +#include + +namespace Snore{ + +class SNORE_EXPORT SnoreBackend : public SnorePlugin +{ + Q_OBJECT + Q_INTERFACES(Snore::SnorePlugin) +public: + SnoreBackend(const QString &name, bool canCloseNotification, bool supportsRichtext ); + virtual ~SnoreBackend(); + virtual bool init(SnoreCore *snore); + + void requestCloseNotification( Snore::Notification notification,NotificationEnums::CloseReasons::closeReasons reason ); + + Snore::Notification getActiveNotificationByID(uint id); + + bool canCloseNotification(); + bool supportsRichtext(); + +signals: + void closeNotification( Snore::Notification ); + + +public slots: + virtual void slotRegisterApplication ( Snore::Application *application ) = 0; + virtual void slotUnregisterApplication ( Snore::Application *application ) = 0; + virtual void slotNotify ( Snore::Notification notification ) = 0; + virtual void slotCloseNotification ( Snore::Notification notification ); + +protected: + bool m_canCloseNotification; + bool m_supportsRichtext; + void closeNotification(Snore::Notification,Snore::NotificationEnums::CloseReasons::closeReasons); + + +private: + QHash m_activeNotifications; + + void addActiveNotification(Notification n); + friend void SnoreCore::broadcastNotification(Notification notification); + + +}; + +} +Q_DECLARE_INTERFACE ( Snore::SnoreBackend, + "org.Snore.NotificationBackend/1.0" ) + +namespace Snore{ +class SnoreCore; + +class SNORE_EXPORT SnoreSecondaryBackend:public SnoreBackend +{ + Q_OBJECT + Q_INTERFACES(Snore::SnorePlugin Snore::SnoreBackend) +public: + SnoreSecondaryBackend(const QString &name, bool supportsRhichtext); + virtual ~SnoreSecondaryBackend(); + virtual bool init(SnoreCore *snore); + +}; + +} + +Q_DECLARE_INTERFACE ( Snore::SnoreSecondaryBackend, + "org.Snore.SecondaryNotificationBackend/1.0" ) + +#endif//SNORE_BACKEND_H diff --git a/src/core/plugins/snorefrontend.h b/src/core/plugins/snorefrontend.h index 7ccd227..9e4aa2a 100644 --- a/src/core/plugins/snorefrontend.h +++ b/src/core/plugins/snorefrontend.h @@ -1,54 +1,54 @@ -/* - 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 SNORE_FRONTEND_H -#define SNORE_FRONTEND_H -#include "../snore_exports.h" -#include "../notification/notification.h" -#include "plugins.h" - -#include -#include - -namespace Snore{ -class Application; -class SnoreCore; -class SnorePlugin; - - -class SNORE_EXPORT SnoreFrontend:public SnorePlugin -{ - Q_OBJECT - Q_INTERFACES(Snore::SnorePlugin) -public: - SnoreFrontend ( const QString &name); - virtual ~SnoreFrontend(); - virtual bool init(SnoreCore *snore); - -public slots: - virtual void actionInvoked( Snore::Notification notification )=0; - virtual void notificationClosed( Snore::Notification notification )=0; -}; - -} - -Q_DECLARE_INTERFACE ( Snore::SnoreFrontend, - "org.Snore.NotificationFrontend/1.0" ) - -#endif//SNORE_FRONTEND_H +/* + 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 SNORE_FRONTEND_H +#define SNORE_FRONTEND_H +#include "../snore_exports.h" +#include "../notification/notification.h" +#include "plugins.h" + +#include +#include + +namespace Snore{ +class Application; +class SnoreCore; +class SnorePlugin; + + +class SNORE_EXPORT SnoreFrontend:public SnorePlugin +{ + Q_OBJECT + Q_INTERFACES(Snore::SnorePlugin) +public: + SnoreFrontend ( const QString &name); + virtual ~SnoreFrontend(); + virtual bool init(SnoreCore *snore); + +public slots: + virtual void actionInvoked( Snore::Notification notification )=0; + virtual void notificationClosed( Snore::Notification notification )=0; +}; + +} + +Q_DECLARE_INTERFACE ( Snore::SnoreFrontend, + "org.Snore.NotificationFrontend/1.0" ) + +#endif//SNORE_FRONTEND_H diff --git a/src/core/snore.cpp b/src/core/snore.cpp index 1f91033..5972611 100644 --- a/src/core/snore.cpp +++ b/src/core/snore.cpp @@ -1,298 +1,298 @@ -/* - 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 "snore.h" -#include "notification/notification.h" -#include "plugins/plugincontainer.h" -#include "plugins/plugins.h" -#include "plugins/snorebackend.h" -#include "plugins/snorefrontend.h" - -#include "version.h" - -#include - -#include -#include -#include -#include -#include - -using namespace Snore; - -void SnoreCore::slotNotificationClosed(Notification n) -{ - emit notificationClosed(n); -} - -QString const SnoreCore::snoreTMP(){ - static const QString tmp = QString("%1/SnoreNotify/").arg(QDir::temp().path()); - return tmp; -} - - -SnoreCore::SnoreCore ( QSystemTrayIcon *trayIcon ) : - m_trayIcon ( trayIcon ) -{ - QDir home ( snoreTMP() ); - if ( !home.exists() ){ - home.cdUp(); - home.mkdir("SnoreNotify"); - } - -} - -const QDir &SnoreCore::pluginDir(){ - static QDir path(QString("%1/snoreplugins").arg(qApp->applicationDirPath())); - if(!path.exists()) - { - path = QDir(LIBSNORE_PLUGIN_PATH); - } - qDebug() << "PluginDir" << path.absolutePath(); - return path; -} - - -void SnoreCore::loadPlugins ( PluginContainer::PluginTypes types ) -{ - qDebug() << "PluginInfo" << PluginContainer::pluginCache().keys(); - foreach ( PluginContainer *info, PluginContainer::pluginCache().values()) - { - if(types == PluginContainer::ALL || types.testFlag(info->type())) - { - switch(info->type()) - { - case PluginContainer::BACKEND: - { - qDebug() <name()<<"is a Notification_Backend"; - m_notificationBackends.append( info->name()); - break; - } - case PluginContainer::SECONDARY_BACKEND: - { - if(!info->load()->init( this )){ - info->unload(); - break; - } - m_secondaryNotificationBackends.append(info->name()); - break; - } - case PluginContainer::FRONTEND: - { - qDebug() <name()<<"is a Notification_Frontend"; - if(!info->load()->init( this )){ - info->unload(); - break; - } - m_Frontends.append(info->name()); - break; - } - case PluginContainer::PLUGIN: - { - qDebug() <name()<<"is a SnorePlugin"; - if(!info->load()->init(this)){ - info->unload(); - break; - } - m_plugins.append(info->name()); - break; - } - default: - { - std::cerr<<"Plugin Cache corrupted"<file().toLocal8Bit().constData()<type()).toLatin1().constData()<file()<type(); - } - } -} - -void SnoreCore::broadcastNotification ( Notification notification ) -{ - qDebug()<<"Broadcasting"<isInitialized()){ - qDebug()<<"Notification backend "<quit(); - } - m_notificationBackend->slotNotify( notification ); - m_notificationBackend->addActiveNotification(notification); - } -} - - -void SnoreCore::notificationActionInvoked ( Notification notification ) -{ - emit actionInvoked(notification); - SnoreFrontend *nf = notification.source(); - if ( nf != NULL ) - { - nf->actionInvoked ( notification ); - } -} - -void SnoreCore::registerApplication(Application *application) -{ - if(!m_applications.contains(application->name())) - { - m_applications.insert ( application->name(),application ); - emit applicationInitialized ( application ); - } -} - -void SnoreCore::addApplication ( Application *application ) -{ - registerApplication(application); -} - -void SnoreCore::applicationIsInitialized ( Application *application ) -{ - registerApplication(application); -} - -void SnoreCore::removeApplication ( const QString& appName ) -{ - deregisterApplication( m_applications.value ( appName ) ); -} - -void SnoreCore::deregisterApplication(Application *application) -{ - emit applicationRemoved (application ); - m_applications.take ( application->name() ); - application->deleteLater(); -} - -const ApplicationsList &SnoreCore::aplications() const -{ - return m_applications; -} - - -const QStringList &SnoreCore::notificationBackends() const -{ - return m_notificationBackends; -} - -const QStringList &SnoreCore::notificationFrontends() const -{ - return m_Frontends; -} - -const QStringList &SnoreCore::secondaryNotificationBackends() const -{ - return m_secondaryNotificationBackends; -} - -bool SnoreCore::setPrimaryNotificationBackend ( const QString &backend ) -{ - if(!PluginContainer::pluginCache().contains(backend)){ - qDebug()<<"Unknown Backend:"<(PluginContainer::pluginCache()[backend]->load()); - if(!b->isInitialized()){ - if(!b->init(this)){ - qDebug()<<"Failed to initialize"<name(); - return false; - } - disconnect(m_notificationBackend,SIGNAL(closeNotification(Snore::Notification))); - connect(b,SIGNAL(closeNotification(Snore::Notification)),this,SLOT(slotNotificationClosed(Snore::Notification))); - } - m_notificationBackend = b; - return true; -} - -bool SnoreCore::setPrimaryNotificationBackend() -{ - QStringList backends = notificationBackends(); -#ifdef Q_OS_WIN - if(QSysInfo::windowsVersion() == QSysInfo::WV_WINDOWS8 && backends.contains("Windows 8")) - { - if(setPrimaryNotificationBackend("Windows 8")) - return true; - } - if( backends.contains("Growl")) - { - if(setPrimaryNotificationBackend("Growl")) - return true; - } - if( backends.contains("Snarl")) - { - if(setPrimaryNotificationBackend("Snarl")) - return true; - } -#elif defined(Q_OS_LINUX) - if( backends.contains("FreedesktopNotification_Backend")) - { - return setPrimaryNotificationBackend("FreedesktopNotification_Backend"); - } -#elif defined(Q_OS_MAC) - if( backends.contains("Growl")) - { - return setPrimaryNotificationBackend("Growl"); - } -#endif - if( trayIcon() && backends.contains("SystemTray")) - { - return setPrimaryNotificationBackend("SystemTray"); - } - return false; -} - -const QString SnoreCore::primaryNotificationBackend() const -{ - if(m_notificationBackend.isNull()) - { - return QString::null; - } - return m_notificationBackend->name(); -} - -QSystemTrayIcon *SnoreCore::trayIcon(){ - return m_trayIcon; -} - -Notification SnoreCore::getActiveNotificationByID(uint id) -{ - if(!m_notificationBackend->isInitialized()){ - qDebug()<<"Notification backend "<quit(); - } - return m_notificationBackend->getActiveNotificationByID(id); -} - -void SnoreCore::requestCloseNotification(Notification n, NotificationEnums::CloseReasons::closeReasons r) -{ - m_notificationBackend->requestCloseNotification(n,r); -} - -bool SnoreCore::primaryBackendSupportsRichtext() -{ - return m_notificationBackend->supportsRichtext(); -} - -Hint &SnoreCore::hints() -{ - return m_hints; -} +/* + 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 "snore.h" +#include "notification/notification.h" +#include "plugins/plugincontainer.h" +#include "plugins/plugins.h" +#include "plugins/snorebackend.h" +#include "plugins/snorefrontend.h" + +#include "version.h" + +#include + +#include +#include +#include +#include +#include + +using namespace Snore; + +void SnoreCore::slotNotificationClosed(Notification n) +{ + emit notificationClosed(n); +} + +QString const SnoreCore::snoreTMP(){ + static const QString tmp = QString("%1/SnoreNotify/").arg(QDir::temp().path()); + return tmp; +} + + +SnoreCore::SnoreCore ( QSystemTrayIcon *trayIcon ) : + m_trayIcon ( trayIcon ) +{ + QDir home ( snoreTMP() ); + if ( !home.exists() ){ + home.cdUp(); + home.mkdir("SnoreNotify"); + } + +} + +const QDir &SnoreCore::pluginDir(){ + static QDir path(QString("%1/snoreplugins").arg(qApp->applicationDirPath())); + if(!path.exists()) + { + path = QDir(LIBSNORE_PLUGIN_PATH); + } + qDebug() << "PluginDir" << path.absolutePath(); + return path; +} + + +void SnoreCore::loadPlugins ( PluginContainer::PluginTypes types ) +{ + qDebug() << "PluginInfo" << PluginContainer::pluginCache().keys(); + foreach ( PluginContainer *info, PluginContainer::pluginCache().values()) + { + if(types == PluginContainer::ALL || types.testFlag(info->type())) + { + switch(info->type()) + { + case PluginContainer::BACKEND: + { + qDebug() <name()<<"is a Notification_Backend"; + m_notificationBackends.append( info->name()); + break; + } + case PluginContainer::SECONDARY_BACKEND: + { + if(!info->load()->init( this )){ + info->unload(); + break; + } + m_secondaryNotificationBackends.append(info->name()); + break; + } + case PluginContainer::FRONTEND: + { + qDebug() <name()<<"is a Notification_Frontend"; + if(!info->load()->init( this )){ + info->unload(); + break; + } + m_Frontends.append(info->name()); + break; + } + case PluginContainer::PLUGIN: + { + qDebug() <name()<<"is a SnorePlugin"; + if(!info->load()->init(this)){ + info->unload(); + break; + } + m_plugins.append(info->name()); + break; + } + default: + { + std::cerr<<"Plugin Cache corrupted"<file().toLocal8Bit().constData()<type()).toLatin1().constData()<file()<type(); + } + } +} + +void SnoreCore::broadcastNotification ( Notification notification ) +{ + qDebug()<<"Broadcasting"<isInitialized()){ + qDebug()<<"Notification backend "<quit(); + } + m_notificationBackend->slotNotify( notification ); + m_notificationBackend->addActiveNotification(notification); + } +} + + +void SnoreCore::notificationActionInvoked ( Notification notification ) +{ + emit actionInvoked(notification); + SnoreFrontend *nf = notification.source(); + if ( nf != NULL ) + { + nf->actionInvoked ( notification ); + } +} + +void SnoreCore::registerApplication(Application *application) +{ + if(!m_applications.contains(application->name())) + { + m_applications.insert ( application->name(),application ); + emit applicationInitialized ( application ); + } +} + +void SnoreCore::addApplication ( Application *application ) +{ + registerApplication(application); +} + +void SnoreCore::applicationIsInitialized ( Application *application ) +{ + registerApplication(application); +} + +void SnoreCore::removeApplication ( const QString& appName ) +{ + deregisterApplication( m_applications.value ( appName ) ); +} + +void SnoreCore::deregisterApplication(Application *application) +{ + emit applicationRemoved (application ); + m_applications.take ( application->name() ); + application->deleteLater(); +} + +const ApplicationsList &SnoreCore::aplications() const +{ + return m_applications; +} + + +const QStringList &SnoreCore::notificationBackends() const +{ + return m_notificationBackends; +} + +const QStringList &SnoreCore::notificationFrontends() const +{ + return m_Frontends; +} + +const QStringList &SnoreCore::secondaryNotificationBackends() const +{ + return m_secondaryNotificationBackends; +} + +bool SnoreCore::setPrimaryNotificationBackend ( const QString &backend ) +{ + if(!PluginContainer::pluginCache().contains(backend)){ + qDebug()<<"Unknown Backend:"<(PluginContainer::pluginCache()[backend]->load()); + if(!b->isInitialized()){ + if(!b->init(this)){ + qDebug()<<"Failed to initialize"<name(); + return false; + } + disconnect(m_notificationBackend,SIGNAL(closeNotification(Snore::Notification))); + connect(b,SIGNAL(closeNotification(Snore::Notification)),this,SLOT(slotNotificationClosed(Snore::Notification))); + } + m_notificationBackend = b; + return true; +} + +bool SnoreCore::setPrimaryNotificationBackend() +{ + QStringList backends = notificationBackends(); +#ifdef Q_OS_WIN + if(QSysInfo::windowsVersion() == QSysInfo::WV_WINDOWS8 && backends.contains("Windows 8")) + { + if(setPrimaryNotificationBackend("Windows 8")) + return true; + } + if( backends.contains("Growl")) + { + if(setPrimaryNotificationBackend("Growl")) + return true; + } + if( backends.contains("Snarl")) + { + if(setPrimaryNotificationBackend("Snarl")) + return true; + } +#elif defined(Q_OS_LINUX) + if( backends.contains("FreedesktopNotification_Backend")) + { + return setPrimaryNotificationBackend("FreedesktopNotification_Backend"); + } +#elif defined(Q_OS_MAC) + if( backends.contains("Growl")) + { + return setPrimaryNotificationBackend("Growl"); + } +#endif + if( trayIcon() && backends.contains("SystemTray")) + { + return setPrimaryNotificationBackend("SystemTray"); + } + return false; +} + +const QString SnoreCore::primaryNotificationBackend() const +{ + if(m_notificationBackend.isNull()) + { + return QString::null; + } + return m_notificationBackend->name(); +} + +QSystemTrayIcon *SnoreCore::trayIcon(){ + return m_trayIcon; +} + +Notification SnoreCore::getActiveNotificationByID(uint id) +{ + if(!m_notificationBackend->isInitialized()){ + qDebug()<<"Notification backend "<quit(); + } + return m_notificationBackend->getActiveNotificationByID(id); +} + +void SnoreCore::requestCloseNotification(Notification n, NotificationEnums::CloseReasons::closeReasons r) +{ + m_notificationBackend->requestCloseNotification(n,r); +} + +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 6383a4c..8a2431c 100644 --- a/src/core/snore.h +++ b/src/core/snore.h @@ -1,121 +1,121 @@ -/* - 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 SNORESERVER_H -#define SNORESERVER_H - -#include "snore_exports.h" -#include "application.h" -#include "plugins/plugincontainer.h" -#include "notification/notification.h" -#include "hint.h" - -#include -#include -#include - -class QSystemTrayIcon; -class QDir; - - -namespace Snore{ -class SNORE_EXPORT SnoreCore : public QObject -{ - Q_OBJECT -public: - static const QString snoreTMP(); - static const QDir &pluginDir(); - -public: - SnoreCore (QSystemTrayIcon *trayIcon = NULL ); - void loadPlugins ( PluginContainer::PluginTypes types ); - - - void broadcastNotification( Notification notification ); - void notificationActionInvoked( Notification notification );//TODO: move to private header - - void registerApplication( Application *application ); - void deregisterApplication( Application *application ); - - void Q_DECL_DEPRECATED addApplication ( Application *application ); - void Q_DECL_DEPRECATED applicationIsInitialized ( Application* application ); - void Q_DECL_DEPRECATED removeApplication ( const QString& appName ); - - const ApplicationsList &aplications() const; - - const QStringList ¬ificationBackends() const; - const QStringList ¬ificationFrontends() const; - const QStringList &secondaryNotificationBackends() const; - - bool setPrimaryNotificationBackend( const QString &backend ); - bool setPrimaryNotificationBackend(); - const QString primaryNotificationBackend() const; - QSystemTrayIcon *trayIcon(); - - Notification getActiveNotificationByID(uint id); - - void requestCloseNotification(Notification,NotificationEnums::CloseReasons::closeReasons); - - 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: - Hint m_hints; - - ApplicationsList m_applications; - - - QStringList m_notificationBackends; - QStringList m_Frontends; - QStringList m_secondaryNotificationBackends; - QStringList m_plugins; - - QPointer m_notificationBackend; - - QSystemTrayIcon *m_trayIcon; -}; - - -static inline QString toPlainText ( const QString &string) -{ - if(Qt::mightBeRichText(string)) - { - return QTextDocumentFragment::fromHtml(string).toPlainText(); - } - else - { - return string; - } -} - -} - -#endif // SNORESERVER_H +/* + 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 SNORESERVER_H +#define SNORESERVER_H + +#include "snore_exports.h" +#include "application.h" +#include "plugins/plugincontainer.h" +#include "notification/notification.h" +#include "hint.h" + +#include +#include +#include + +class QSystemTrayIcon; +class QDir; + + +namespace Snore{ +class SNORE_EXPORT SnoreCore : public QObject +{ + Q_OBJECT +public: + static const QString snoreTMP(); + static const QDir &pluginDir(); + +public: + SnoreCore (QSystemTrayIcon *trayIcon = NULL ); + void loadPlugins ( PluginContainer::PluginTypes types ); + + + void broadcastNotification( Notification notification ); + void notificationActionInvoked( Notification notification );//TODO: move to private header + + void registerApplication( Application *application ); + void deregisterApplication( Application *application ); + + void Q_DECL_DEPRECATED addApplication ( Application *application ); + void Q_DECL_DEPRECATED applicationIsInitialized ( Application* application ); + void Q_DECL_DEPRECATED removeApplication ( const QString& appName ); + + const ApplicationsList &aplications() const; + + const QStringList ¬ificationBackends() const; + const QStringList ¬ificationFrontends() const; + const QStringList &secondaryNotificationBackends() const; + + bool setPrimaryNotificationBackend( const QString &backend ); + bool setPrimaryNotificationBackend(); + const QString primaryNotificationBackend() const; + QSystemTrayIcon *trayIcon(); + + Notification getActiveNotificationByID(uint id); + + void requestCloseNotification(Notification,NotificationEnums::CloseReasons::closeReasons); + + 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: + Hint m_hints; + + ApplicationsList m_applications; + + + QStringList m_notificationBackends; + QStringList m_Frontends; + QStringList m_secondaryNotificationBackends; + QStringList m_plugins; + + QPointer m_notificationBackend; + + QSystemTrayIcon *m_trayIcon; +}; + + +static inline QString toPlainText ( const QString &string) +{ + if(Qt::mightBeRichText(string)) + { + return QTextDocumentFragment::fromHtml(string).toPlainText(); + } + else + { + return string; + } +} + +} + +#endif // SNORESERVER_H diff --git a/src/core/snore_exports.h b/src/core/snore_exports.h index e926b35..fac3e12 100644 --- a/src/core/snore_exports.h +++ b/src/core/snore_exports.h @@ -1,33 +1,33 @@ -#ifndef SNORE_EXPORT_H -#define SNORE_EXPORT_H - - -#if defined(HAVE_KDE) -#include -#ifdef SNORECORE_DLL -# define SNORE_EXPORT KDE_EXPORT -#else -# define SNORE_EXPORT KDE_IMPORT -#endif -#else -#include -#ifdef SNORECORE_DLL -# define SNORE_EXPORT Q_DECL_EXPORT -#else -# define SNORE_EXPORT Q_DECL_IMPORT -#endif -#endif - - - -#ifndef SNORE_DEPRECATED -# ifdef Q_CC_GNU -# define SNORE_DEPRECATED __attribute__((deprecated)) -# elif defined(Q_CC_MSVC) -# define SNORE_DEPRECATED __declspec(deprecated) -# else -# define SNORE_DEPRECATED -# endif -#endif - -#endif//SNORE_EXPORT_H +#ifndef SNORE_EXPORT_H +#define SNORE_EXPORT_H + + +#if defined(HAVE_KDE) +#include +#ifdef SNORECORE_DLL +# define SNORE_EXPORT KDE_EXPORT +#else +# define SNORE_EXPORT KDE_IMPORT +#endif +#else +#include +#ifdef SNORECORE_DLL +# define SNORE_EXPORT Q_DECL_EXPORT +#else +# define SNORE_EXPORT Q_DECL_IMPORT +#endif +#endif + + + +#ifndef SNORE_DEPRECATED +# ifdef Q_CC_GNU +# define SNORE_DEPRECATED __attribute__((deprecated)) +# elif defined(Q_CC_MSVC) +# define SNORE_DEPRECATED __declspec(deprecated) +# else +# define SNORE_DEPRECATED +# endif +#endif + +#endif//SNORE_EXPORT_H diff --git a/src/core/version.h b/src/core/version.h index 95cba22..92c41cb 100644 --- a/src/core/version.h +++ b/src/core/version.h @@ -1,27 +1,27 @@ -#ifndef SNORE_VERSION_H -#define SNORE_VERSION_H -#undef major -#undef minor - -#include "snore_exports.h" - -#include - -namespace Snore{ - -class SNORE_EXPORT Version{ -public: -static const QString version(); - -static const QString major(); - -static const QString minor(); - -static const QString suffix(); - -static const QString revision(); - -}; - -} -#endif +#ifndef SNORE_VERSION_H +#define SNORE_VERSION_H +#undef major +#undef minor + +#include "snore_exports.h" + +#include + +namespace Snore{ + +class SNORE_EXPORT Version{ +public: +static const QString version(); + +static const QString major(); + +static const QString minor(); + +static const QString suffix(); + +static const QString revision(); + +}; + +} +#endif diff --git a/src/plugins/backends/freedesktop/fredesktopnotification.cpp b/src/plugins/backends/freedesktop/fredesktopnotification.cpp index 17b5a97..02c8f9f 100644 --- a/src/plugins/backends/freedesktop/fredesktopnotification.cpp +++ b/src/plugins/backends/freedesktop/fredesktopnotification.cpp @@ -1,75 +1,75 @@ -/* - 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 "fredesktopnotification.h" - -#include -#include - - -static int imageHintID = qDBusRegisterMetaType(); - - -FreedesktopImageHint::FreedesktopImageHint(){ - -} - -FreedesktopImageHint::FreedesktopImageHint(const QImage &img) -{ - QImage image(img.convertToFormat(QImage::Format_ARGB32)); - imageData = QByteArray((char*)image.rgbSwapped().bits(),image.numBytes()); - width = image.width(); - height = image.height(); - rowstride = image.bytesPerLine(); - hasAlpha = image.hasAlphaChannel(); - channels = image.isGrayscale()?1:hasAlpha?4:3; - bitsPerSample = image.depth()/channels; - -} - - -QImage FreedesktopImageHint::toQImage() const { - return QImage((uchar*)imageData.data(),width,height,QImage::Format_ARGB32 ).rgbSwapped(); -} - -QDBusArgument &operator<<(QDBusArgument &a, const FreedesktopImageHint &i) { - a.beginStructure(); - a << i.width << - i.height << - i.rowstride << - i.hasAlpha << - i.bitsPerSample << - i.channels << - i.imageData; - a.endStructure(); - return a; -} - -const QDBusArgument & operator >>(const QDBusArgument &a, FreedesktopImageHint &i) { - a.beginStructure(); - a >> i.width >> - i.height >> - i.rowstride >> - i.hasAlpha >> - i.bitsPerSample >> - i.channels >> - i.imageData; - a.endStructure(); - return a; -} +/* + 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 "fredesktopnotification.h" + +#include +#include + + +static int imageHintID = qDBusRegisterMetaType(); + + +FreedesktopImageHint::FreedesktopImageHint(){ + +} + +FreedesktopImageHint::FreedesktopImageHint(const QImage &img) +{ + QImage image(img.convertToFormat(QImage::Format_ARGB32)); + imageData = QByteArray((char*)image.rgbSwapped().bits(),image.numBytes()); + width = image.width(); + height = image.height(); + rowstride = image.bytesPerLine(); + hasAlpha = image.hasAlphaChannel(); + channels = image.isGrayscale()?1:hasAlpha?4:3; + bitsPerSample = image.depth()/channels; + +} + + +QImage FreedesktopImageHint::toQImage() const { + return QImage((uchar*)imageData.data(),width,height,QImage::Format_ARGB32 ).rgbSwapped(); +} + +QDBusArgument &operator<<(QDBusArgument &a, const FreedesktopImageHint &i) { + a.beginStructure(); + a << i.width << + i.height << + i.rowstride << + i.hasAlpha << + i.bitsPerSample << + i.channels << + i.imageData; + a.endStructure(); + return a; +} + +const QDBusArgument & operator >>(const QDBusArgument &a, FreedesktopImageHint &i) { + a.beginStructure(); + a >> i.width >> + i.height >> + i.rowstride >> + i.hasAlpha >> + i.bitsPerSample >> + i.channels >> + i.imageData; + a.endStructure(); + return a; +} diff --git a/src/plugins/backends/freedesktop/fredesktopnotification.h b/src/plugins/backends/freedesktop/fredesktopnotification.h index 8a5e750..0b45d25 100644 --- a/src/plugins/backends/freedesktop/fredesktopnotification.h +++ b/src/plugins/backends/freedesktop/fredesktopnotification.h @@ -1,55 +1,55 @@ -/* - 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 FreedesktopNotification_H -#define FreedesktopNotification_H - -#include "core/notification/notification.h" - -#include -#include - - -class FreedesktopImageHint -{ -public: - FreedesktopImageHint(); - FreedesktopImageHint(const QImage &img); - QString hash()const; - - QImage toQImage()const; - - int width; - int height; - int rowstride; - bool hasAlpha; - int bitsPerSample; - int channels; - QByteArray imageData; - QString _hash; - - -}; - -Q_DECLARE_METATYPE(FreedesktopImageHint); - -QDBusArgument &operator<<(QDBusArgument &a, const FreedesktopImageHint &i); -const QDBusArgument & operator >>(const QDBusArgument &a, FreedesktopImageHint &i) ; - -#endif // FreedesktopNotification_H +/* + 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 FreedesktopNotification_H +#define FreedesktopNotification_H + +#include "core/notification/notification.h" + +#include +#include + + +class FreedesktopImageHint +{ +public: + FreedesktopImageHint(); + FreedesktopImageHint(const QImage &img); + QString hash()const; + + QImage toQImage()const; + + int width; + int height; + int rowstride; + bool hasAlpha; + int bitsPerSample; + int channels; + QByteArray imageData; + QString _hash; + + +}; + +Q_DECLARE_METATYPE(FreedesktopImageHint); + +QDBusArgument &operator<<(QDBusArgument &a, const FreedesktopImageHint &i); +const QDBusArgument & operator >>(const QDBusArgument &a, FreedesktopImageHint &i) ; + +#endif // FreedesktopNotification_H diff --git a/src/plugins/backends/freedesktop/freedesktopnotification_backend.cpp b/src/plugins/backends/freedesktop/freedesktopnotification_backend.cpp index d90fa50..4117916 100644 --- a/src/plugins/backends/freedesktop/freedesktopnotification_backend.cpp +++ b/src/plugins/backends/freedesktop/freedesktopnotification_backend.cpp @@ -1,128 +1,128 @@ -#include "freedesktopnotification_backend.h" - -#include -#include -#include "core/notification/notification.h" -#include -#include -#include "fredesktopnotification.h" -#include "core/snore.h" - - -using namespace Snore; - -Q_EXPORT_PLUGIN2 ( freedesktopnotificationbackend,FreedesktopBackend ) - - -FreedesktopBackend::FreedesktopBackend () : - SnoreBackend ( "FreedesktopNotification_Backend",true,true) -{ -} - -bool FreedesktopBackend::init(SnoreCore *snore){ - - m_interface = new org::freedesktop::Notifications( "org.freedesktop.Notifications", "/org/freedesktop/Notifications", - QDBusConnection::sessionBus(), this ); - - QDBusPendingReply reply = m_interface->GetCapabilities(); - reply.waitForFinished(); - QStringList caps = reply.value(); - m_supportsRichtext = caps.contains( "body-markup" ); - connect(m_interface, SIGNAL(ActionInvoked(uint,QString)), this, SLOT(slotActionInvoked(uint,QString))); - connect(m_interface, SIGNAL(NotificationClosed(uint,uint)), this , SLOT(slotNotificationClosed(uint,uint))); - - return SnoreBackend::init(snore); -} - -void FreedesktopBackend::slotRegisterApplication ( Application *application ) -{ - Q_UNUSED ( application ); -} - -void FreedesktopBackend::slotUnregisterApplication ( Application *application ) -{ - Q_UNUSED ( application ); -} - -void FreedesktopBackend::slotNotify ( Notification noti ) -{ - QStringList actions; - foreach(int k,noti.actions().keys()) - { - actions << QString::number(k) << noti.actions()[k]->name; - } - - - - - QVariantMap hints; - if(noti.icon().isValid()) - { - FreedesktopImageHint image(noti.icon().image()); - hints["image_data"] = QVariant::fromValue(image); - } - - if(noti.priority() != NotificationEnums::Prioritys::NORMAL) - { - hints["urgency"] = (char)noti.priority()+1; - } - - - uint updateId = 0; - if(noti.updateID() != 0) - { - updateId = m_snoreIdMap[noti.updateID()]; - m_dbusIdMap[updateId] = noti.id(); - m_snoreIdMap[noti.id()] = updateId; - } - - QString title = QString("%1 - %2").arg(noti.application(), noti.title()); - QString body(noti.text()); - if(!supportsRichtext()) - { - title = Snore::toPlainText(title); - body = Snore::toPlainText(body); - } - QDBusPendingReply id = m_interface->Notify(noti.application(), updateId, "", title, - body, actions, hints, noti.sticky()?-1:noti.timeout()*1000); - - if(noti.updateID() == 0) - { - id.waitForFinished(); - m_snoreIdMap[noti.id()] = id.value(); - m_dbusIdMap[id.value()] = noti.id(); - } -} -void FreedesktopBackend::slotActionInvoked(const uint &id, const QString &actionID){ - Notification noti = getActiveNotificationByID(m_dbusIdMap[id]); - if(!noti.isValid()) - return; - noti.setActionInvoked ( actionID.toInt() ); - snore()->notificationActionInvoked ( noti ); -} - -void FreedesktopBackend::slotCloseNotification ( Notification notification ) -{ - if(!m_snoreIdMap.contains(notification.id())) - return; - uint id = m_snoreIdMap.take(notification.id()); - m_dbusIdMap.remove(id); - m_interface->CloseNotification(id); -} - - - -void FreedesktopBackend::slotNotificationClosed ( const uint &id,const uint &reason ) -{ - NotificationEnums::CloseReasons::closeReasons closeReason = NotificationEnums::CloseReasons::closeReasons(reason); - qDebug() << Q_FUNC_INFO << "Closed" << id << "|" << closeReason << reason; - if(id == 0) - return; - Notification noti = getActiveNotificationByID(m_dbusIdMap.take(id)); - m_snoreIdMap.remove(noti.id()); - closeNotification(noti, closeReason); -} - - - - +#include "freedesktopnotification_backend.h" + +#include +#include +#include "core/notification/notification.h" +#include +#include +#include "fredesktopnotification.h" +#include "core/snore.h" + + +using namespace Snore; + +Q_EXPORT_PLUGIN2 ( freedesktopnotificationbackend,FreedesktopBackend ) + + +FreedesktopBackend::FreedesktopBackend () : + SnoreBackend ( "FreedesktopNotification_Backend",true,true) +{ +} + +bool FreedesktopBackend::init(SnoreCore *snore){ + + m_interface = new org::freedesktop::Notifications( "org.freedesktop.Notifications", "/org/freedesktop/Notifications", + QDBusConnection::sessionBus(), this ); + + QDBusPendingReply reply = m_interface->GetCapabilities(); + reply.waitForFinished(); + QStringList caps = reply.value(); + m_supportsRichtext = caps.contains( "body-markup" ); + connect(m_interface, SIGNAL(ActionInvoked(uint,QString)), this, SLOT(slotActionInvoked(uint,QString))); + connect(m_interface, SIGNAL(NotificationClosed(uint,uint)), this , SLOT(slotNotificationClosed(uint,uint))); + + return SnoreBackend::init(snore); +} + +void FreedesktopBackend::slotRegisterApplication ( Application *application ) +{ + Q_UNUSED ( application ); +} + +void FreedesktopBackend::slotUnregisterApplication ( Application *application ) +{ + Q_UNUSED ( application ); +} + +void FreedesktopBackend::slotNotify ( Notification noti ) +{ + QStringList actions; + foreach(int k,noti.actions().keys()) + { + actions << QString::number(k) << noti.actions()[k]->name; + } + + + + + QVariantMap hints; + if(noti.icon().isValid()) + { + FreedesktopImageHint image(noti.icon().image()); + hints["image_data"] = QVariant::fromValue(image); + } + + if(noti.priority() != NotificationEnums::Prioritys::NORMAL) + { + hints["urgency"] = (char)noti.priority()+1; + } + + + uint updateId = 0; + if(noti.updateID() != 0) + { + updateId = m_snoreIdMap[noti.updateID()]; + m_dbusIdMap[updateId] = noti.id(); + m_snoreIdMap[noti.id()] = updateId; + } + + QString title = QString("%1 - %2").arg(noti.application(), noti.title()); + QString body(noti.text()); + if(!supportsRichtext()) + { + title = Snore::toPlainText(title); + body = Snore::toPlainText(body); + } + QDBusPendingReply id = m_interface->Notify(noti.application(), updateId, "", title, + body, actions, hints, noti.sticky()?-1:noti.timeout()*1000); + + if(noti.updateID() == 0) + { + id.waitForFinished(); + m_snoreIdMap[noti.id()] = id.value(); + m_dbusIdMap[id.value()] = noti.id(); + } +} +void FreedesktopBackend::slotActionInvoked(const uint &id, const QString &actionID){ + Notification noti = getActiveNotificationByID(m_dbusIdMap[id]); + if(!noti.isValid()) + return; + noti.setActionInvoked ( actionID.toInt() ); + snore()->notificationActionInvoked ( noti ); +} + +void FreedesktopBackend::slotCloseNotification ( Notification notification ) +{ + if(!m_snoreIdMap.contains(notification.id())) + return; + uint id = m_snoreIdMap.take(notification.id()); + m_dbusIdMap.remove(id); + m_interface->CloseNotification(id); +} + + + +void FreedesktopBackend::slotNotificationClosed ( const uint &id,const uint &reason ) +{ + NotificationEnums::CloseReasons::closeReasons closeReason = NotificationEnums::CloseReasons::closeReasons(reason); + qDebug() << Q_FUNC_INFO << "Closed" << id << "|" << closeReason << reason; + if(id == 0) + return; + Notification noti = getActiveNotificationByID(m_dbusIdMap.take(id)); + m_snoreIdMap.remove(noti.id()); + closeNotification(noti, closeReason); +} + + + + diff --git a/src/plugins/backends/freedesktop/freedesktopnotification_backend.h b/src/plugins/backends/freedesktop/freedesktopnotification_backend.h index 8f02c0e..901f701 100644 --- a/src/plugins/backends/freedesktop/freedesktopnotification_backend.h +++ b/src/plugins/backends/freedesktop/freedesktopnotification_backend.h @@ -1,33 +1,33 @@ -#ifndef FREEDESKTOPNOTIFICATION_H -#define FREEDESKTOPNOTIFICATION_H -#include "core/plugins/snorebackend.h" -#include "notificationinterface.h" - -class FreedesktopBackend:public Snore::SnoreBackend -{ - Q_OBJECT - Q_INTERFACES ( Snore::SnoreBackend ) - Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0") -public: - FreedesktopBackend(); - virtual bool init(Snore::SnoreCore *snore); - -public slots: - void slotNotify( Snore::Notification notification ); - void slotCloseNotification ( Snore::Notification notification ); - void slotRegisterApplication ( Snore::Application *application ); - void slotUnregisterApplication ( Snore::Application *application ); - - void slotActionInvoked(const uint &id,const QString &actionID); - void slotNotificationClosed ( const uint &id,const uint &reason ); - - -private: - org::freedesktop::Notifications* m_interface; - QHash m_dbusIdMap; - QHash m_snoreIdMap; - - -}; - -#endif // FREEDESKTOPNOTIFICATION_H +#ifndef FREEDESKTOPNOTIFICATION_H +#define FREEDESKTOPNOTIFICATION_H +#include "core/plugins/snorebackend.h" +#include "notificationinterface.h" + +class FreedesktopBackend:public Snore::SnoreBackend +{ + Q_OBJECT + Q_INTERFACES ( Snore::SnoreBackend ) + Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0") +public: + FreedesktopBackend(); + virtual bool init(Snore::SnoreCore *snore); + +public slots: + void slotNotify( Snore::Notification notification ); + void slotCloseNotification ( Snore::Notification notification ); + void slotRegisterApplication ( Snore::Application *application ); + void slotUnregisterApplication ( Snore::Application *application ); + + void slotActionInvoked(const uint &id,const QString &actionID); + void slotNotificationClosed ( const uint &id,const uint &reason ); + + +private: + org::freedesktop::Notifications* m_interface; + QHash m_dbusIdMap; + QHash m_snoreIdMap; + + +}; + +#endif // FREEDESKTOPNOTIFICATION_H diff --git a/src/plugins/backends/growl/growl.cpp b/src/plugins/backends/growl/growl.cpp index ab3a899..3f287b4 100644 --- a/src/plugins/backends/growl/growl.cpp +++ b/src/plugins/backends/growl/growl.cpp @@ -1,154 +1,154 @@ -/* - 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 "growl.h" -#include "gntp.h" - -#include "core/snore.h" - - -#include - -using namespace Snore; - -Q_EXPORT_PLUGIN2(growl,Growl) - -Growl *Growl::s_instance = NULL; - -Growl::Growl(): - SnoreBackend("Growl",false,false), - m_id(0), - m_defaultGNTP(NULL) -{ - s_instance = this; -} - -Growl::~Growl() -{ - if(snore() != NULL) - { - foreach(Application *a,snore()->aplications()) - { - this->slotUnregisterApplication(a); - } - } - delete m_defaultGNTP; -} - -bool Growl::init(SnoreCore *snore) -{ - Icon icon(":/root/snore.png"); - m_defaultGNTP = new gntp("SnoreNotify", icon.localUrl().toUtf8().constData()); - - std::vector alerts; - alerts.push_back("Default"); - try - { - m_defaultGNTP->regist(alerts); - } - catch(const std::exception& e) - { - qWarning() << Q_FUNC_INFO << e.what(); - delete m_defaultGNTP; - m_defaultGNTP = NULL; - return false; - } - return SnoreBackend::init(snore); -} - -void Growl::slotRegisterApplication(Application *application) -{ - gntp *growl = new gntp(application->name().toUtf8().constData(),application->icon().localUrl().toUtf8().constData()); - - gntp::gntp_callback callback(&Growl::gntpCallback); - growl->set_gntp_callback(callback); - -// qDebug() << Q_FUNC_INFO << application->name().toUtf8().constData(); - std::vector alerts; - foreach(Alert *a,application->alerts()) - { -// qDebug() << Q_FUNC_INFO << a->name().toUtf8().constData(); - alerts.push_back(a->name().toUtf8().constData()); - } - - try - { - growl->regist(alerts); - }catch(const std::exception& e) - { - qWarning() << Q_FUNC_INFO << e.what(); - } - m_applications.insert(application->name(),growl); -} - -void Growl::slotUnregisterApplication(Application *application) -{ - gntp *growl = m_applications.take(application->name()); - if(growl == NULL) - { - return; - } - delete growl; -} - -void Growl::slotNotify(Notification notification) -{ - gntp *growl = m_applications.value(notification.application()); - QString alert = notification.alert(); - if(growl == NULL) - { - growl = m_defaultGNTP; - alert = "Default"; - } -// qDebug() << "Notify Growl:" <notify(alert.toUtf8().constData(),notification.id(), - Snore::toPlainText(notification.title()).toUtf8().constData(), - Snore::toPlainText(notification.text()).toUtf8().constData(), - notification.icon().localUrl().isEmpty()?NULL:notification.icon().localUrl().toUtf8().constData(),NULL,"1"); - - } - catch(const std::exception& e) - { - qWarning() << Q_FUNC_INFO << e.what(); - } -} - -void Growl::gntpCallback(const int &id,const std::string &reason,const std::string &data) -{ -// qDebug() << Q_FUNC_INFO << id << QString(reason.c_str()) << QString(data.c_str()); - Notification n = s_instance->snore()->getActiveNotificationByID(id); - NotificationEnums::CloseReasons::closeReasons r = NotificationEnums::CloseReasons::NONE; - if(reason == "TIMEDOUT") - { - r = NotificationEnums::CloseReasons::TIMED_OUT; - } - else if(reason == "CLOSED") - { - r = NotificationEnums::CloseReasons::DISMISSED; - } - else if(reason == "CLICK") - { - r = NotificationEnums::CloseReasons::CLOSED; - s_instance->snore()->notificationActionInvoked(n); - } - s_instance->closeNotification(n,r); -} - +/* + 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 "growl.h" +#include "gntp.h" + +#include "core/snore.h" + + +#include + +using namespace Snore; + +Q_EXPORT_PLUGIN2(growl,Growl) + +Growl *Growl::s_instance = NULL; + +Growl::Growl(): + SnoreBackend("Growl",false,false), + m_id(0), + m_defaultGNTP(NULL) +{ + s_instance = this; +} + +Growl::~Growl() +{ + if(snore() != NULL) + { + foreach(Application *a,snore()->aplications()) + { + this->slotUnregisterApplication(a); + } + } + delete m_defaultGNTP; +} + +bool Growl::init(SnoreCore *snore) +{ + Icon icon(":/root/snore.png"); + m_defaultGNTP = new gntp("SnoreNotify", icon.localUrl().toUtf8().constData()); + + std::vector alerts; + alerts.push_back("Default"); + try + { + m_defaultGNTP->regist(alerts); + } + catch(const std::exception& e) + { + qWarning() << Q_FUNC_INFO << e.what(); + delete m_defaultGNTP; + m_defaultGNTP = NULL; + return false; + } + return SnoreBackend::init(snore); +} + +void Growl::slotRegisterApplication(Application *application) +{ + gntp *growl = new gntp(application->name().toUtf8().constData(),application->icon().localUrl().toUtf8().constData()); + + gntp::gntp_callback callback(&Growl::gntpCallback); + growl->set_gntp_callback(callback); + +// qDebug() << Q_FUNC_INFO << application->name().toUtf8().constData(); + std::vector alerts; + foreach(Alert *a,application->alerts()) + { +// qDebug() << Q_FUNC_INFO << a->name().toUtf8().constData(); + alerts.push_back(a->name().toUtf8().constData()); + } + + try + { + growl->regist(alerts); + }catch(const std::exception& e) + { + qWarning() << Q_FUNC_INFO << e.what(); + } + m_applications.insert(application->name(),growl); +} + +void Growl::slotUnregisterApplication(Application *application) +{ + gntp *growl = m_applications.take(application->name()); + if(growl == NULL) + { + return; + } + delete growl; +} + +void Growl::slotNotify(Notification notification) +{ + gntp *growl = m_applications.value(notification.application()); + QString alert = notification.alert(); + if(growl == NULL) + { + growl = m_defaultGNTP; + alert = "Default"; + } +// qDebug() << "Notify Growl:" <notify(alert.toUtf8().constData(),notification.id(), + Snore::toPlainText(notification.title()).toUtf8().constData(), + Snore::toPlainText(notification.text()).toUtf8().constData(), + notification.icon().localUrl().isEmpty()?NULL:notification.icon().localUrl().toUtf8().constData(),NULL,"1"); + + } + catch(const std::exception& e) + { + qWarning() << Q_FUNC_INFO << e.what(); + } +} + +void Growl::gntpCallback(const int &id,const std::string &reason,const std::string &data) +{ +// qDebug() << Q_FUNC_INFO << id << QString(reason.c_str()) << QString(data.c_str()); + Notification n = s_instance->snore()->getActiveNotificationByID(id); + NotificationEnums::CloseReasons::closeReasons r = NotificationEnums::CloseReasons::NONE; + if(reason == "TIMEDOUT") + { + r = NotificationEnums::CloseReasons::TIMED_OUT; + } + else if(reason == "CLOSED") + { + r = NotificationEnums::CloseReasons::DISMISSED; + } + else if(reason == "CLICK") + { + r = NotificationEnums::CloseReasons::CLOSED; + s_instance->snore()->notificationActionInvoked(n); + } + s_instance->closeNotification(n,r); +} + diff --git a/src/plugins/backends/growl/growl.h b/src/plugins/backends/growl/growl.h index fbd784f..1d98526 100644 --- a/src/plugins/backends/growl/growl.h +++ b/src/plugins/backends/growl/growl.h @@ -1,53 +1,53 @@ -/* - 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 GROWL_BACKEND_H -#define GROWL_BACKEND_H -#include "core/plugins/snorebackend.h" - -#include - -class Growl:public Snore::SnoreBackend -{ - Q_OBJECT - Q_INTERFACES(Snore::SnoreBackend) - Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0") - -public: - Growl(); - ~Growl(); - virtual bool init(Snore::SnoreCore *snore); - - static void gntpCallback(const int &id,const std::string &reason,const std::string &data); - -private: - //a static instance for the static callback methode - static Growl *s_instance; - uint m_id; - QHash m_applications; - gntp *m_defaultGNTP; - -public slots: - void slotRegisterApplication(Snore::Application *application); - void slotUnregisterApplication(Snore::Application *application); - void slotNotify(Snore::Notification notification); -}; - - -#endif // GROWL_BACKEND_H +/* + 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 GROWL_BACKEND_H +#define GROWL_BACKEND_H +#include "core/plugins/snorebackend.h" + +#include + +class Growl:public Snore::SnoreBackend +{ + Q_OBJECT + Q_INTERFACES(Snore::SnoreBackend) + Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0") + +public: + Growl(); + ~Growl(); + virtual bool init(Snore::SnoreCore *snore); + + static void gntpCallback(const int &id,const std::string &reason,const std::string &data); + +private: + //a static instance for the static callback methode + static Growl *s_instance; + uint m_id; + QHash m_applications; + gntp *m_defaultGNTP; + +public slots: + void slotRegisterApplication(Snore::Application *application); + void slotUnregisterApplication(Snore::Application *application); + void slotNotify(Snore::Notification notification); +}; + + +#endif // GROWL_BACKEND_H diff --git a/src/plugins/backends/snarl/SnarlInterface.cpp b/src/plugins/backends/snarl/SnarlInterface.cpp index c61a6a9..2407fc8 100644 --- a/src/plugins/backends/snarl/SnarlInterface.cpp +++ b/src/plugins/backends/snarl/SnarlInterface.cpp @@ -1,706 +1,706 @@ -/// -/// Snarl C++ interface implementation -/// API version 42 -/// -/// http://sourceforge.net/apps/mediawiki/snarlwin/index.php?title=Windows_API -/// https://sourceforge.net/apps/mediawiki/snarlwin/index.php?title=Generic_API -/// -/// Written and maintained by Toke Noer Nøttrup (toke@noer.it) -/// -/// Please note the following changes compared to the VB6 (official API) dokumentation: -/// - Function names doesn't have the prefix "sn". Naming of constants and variables are -/// generally changed to follow Microsoft C# standard. This naming convention is kept for -/// the C++ version, to keep them alike. -/// - Grouped variables like SNARL_LAUNCHED, SNARL_QUIT is enums in SnarlEnums namespace. -/// - Message events like SNARL_NOTIFICATION_CLICKED, is found in SnarlEnums::MessageEvent. -/// - Please note that string functions return NULL when they fail and not an empty string. -/// - Some functions in the VB API takes an appToken as first parameter. This token is a -/// member variable in C++ version, so it is omitted from the functions. -/// (Always call RegisterApp as first function!) -/// - Functions manipulating messages (Update, Hide etc.) still takes a message token as -/// parameter, but you can get the last message token calling GetLastMsgToken(); -/// Example: snarl.Hide(snarl.GetLastMsgToken()); -/// -/// The functions in SnarlInterface both have ANSI(UTF8) and UNICODE versions. -/// If the LPCWSTR (unicode) version of the functions are called, the strings -/// are converted to UTF8 by SnarlInterface before sent to Snarl. So using the -/// ANSI/UTF8/LPCSTR versions of the functions are faster! -/// -/// See https://sourceforge.net/apps/mediawiki/snarlwin/index.php?title=Windows_API#C.2B.2B -/// for example code etc. -/// -///---------------------------------------------------------------------------- -/// -/// 2011-07-31 : General update to match VB6 SVN rev. 232 -/// : Added AppFlags and MessagePriority enums. -/// 2011-07-12 : MingW64 fixes by Patrick von Reth -/// 2011-07-07 : Some changes to compile under VS2008 -/// - Changed vector iterators to begin/end instead of cbegin/cend -/// - Removed const in PairType -/// 2011-02-09 : Fix for wrong parameters in AddClass -/// 2011-02-06 : Updated to rev. 3 of the wiki documentation -/// 2011-02-02 : First release of V42 Snarl API implementation -/// -/// -/// -/// - - -#define _CRT_SECURE_NO_WARNINGS - -#include "SnarlInterface.h" - - -namespace Snarl { -namespace V42 { - - -// workaround for mingw-w64 bug -#ifdef __MINGW64_VERSION_MAJOR - extern "C" { - __declspec(dllimport) errno_t __cdecl strcpy_s(char * _Dst, size_t _SizeInBytes, const char *_Src); - __declspec(dllimport) errno_t __cdecl wcscpy_s(wchar_t * _Dst, size_t _SizeInBytes, const wchar_t *_Src); - __declspec(dllimport) errno_t __cdecl strncat_s(char *_Dst, size_t _DstSizeInChars, const char *_Src, size_t _MaxCount); - } -#endif //__MINGW64_VERSION_MAJOR - - -// ---------------------------------------------------------------------------- -// Static Snarl interface functions -// ---------------------------------------------------------------------------- - -UINT SnarlInterface::AppMsg() -{ - return RegisterWindowMessage(SnarlAppMsg); -} - -UINT SnarlInterface::Broadcast() -{ - return RegisterWindowMessage(SnarlGlobalMsg); -} - -LONG32 SnarlInterface::DoRequest(LPCSTR request, UINT replyTimeout) -{ - DWORD_PTR nResult = 0; - - HWND hWnd = GetSnarlWindow(); - if (!IsWindow(hWnd)) - return -SnarlEnums::ErrorNotRunning; - - // Create COPYDATASTRUCT - COPYDATASTRUCT cds; - cds.dwData = 0x534E4C03; // "SNL",3 - cds.cbData = (DWORD)strlen(request); // No knowledge of max string lenght - cds.lpData = const_cast(request); - - // Send message - if (SendMessageTimeout(hWnd, WM_COPYDATA, (WPARAM)GetCurrentProcessId(), (LPARAM)&cds, SMTO_ABORTIFHUNG | SMTO_NOTIMEOUTIFNOTHUNG, replyTimeout, &nResult) == 0) - { - // Handle error - DWORD nError = GetLastError(); - LONG32 errorResult = 0; - if (nError == ERROR_TIMEOUT) - errorResult = -SnarlEnums::ErrorTimedOut; - else - errorResult = -SnarlEnums::ErrorFailed; - - return errorResult; - } - else - return (LONG32)nResult; -} - -LONG32 SnarlInterface::DoRequest(LPCWSTR request, UINT replyTimeout) -{ - LONG32 nResult = 0; - - // Convert to UTF8 - LPSTR utf8Request = WideToUTF8(request); - if (utf8Request == NULL) - return -SnarlEnums::ErrorCppInterface; - - nResult = DoRequest(utf8Request, replyTimeout); - - // Cleanup and return result - FreeString(utf8Request); - return nResult; -} - -std::basic_string& SnarlInterface::Escape(std::basic_string& str) -{ - std::basic_string::size_type strLength = str.length(); - for (std::basic_string::size_type i = 0; i < strLength; ++i) - { - if (str.at(i) == '=') { - str.insert(++i, "="); - ++strLength; - } - else if (str[i] == '&') { - str.insert(++i, "&"); - ++strLength; - } - } - - return str; -} - -std::basic_string& SnarlInterface::Escape(std::basic_string& str) -{ - std::basic_string::size_type strLength = str.length(); - for (std::basic_string::size_type i = 0; i < strLength; ++i) - { - if (str.at(i) == L'=') { - str.insert(++i, L"="); - ++strLength; - } - else if (str[i] == L'&') { - str.insert(++i, L"&"); - ++strLength; - } - } - - return str; -} - -LPCTSTR SnarlInterface::GetAppPath() -{ - HWND hWnd = GetSnarlWindow(); - if (hWnd) - { - HWND hWndPath = FindWindowEx(hWnd, NULL, _T("static"), NULL); - if (hWndPath) - { - TCHAR strTmp[MAX_PATH] = {0}; - int nReturn = GetWindowText(hWndPath, strTmp, MAX_PATH-1); - if (nReturn > 0) { - TCHAR* strReturn = AllocateString(nReturn + 1); - _tcsncpy(strReturn, strTmp, nReturn + 1); - strReturn[nReturn] = 0; - return strReturn; - } - } - } - - return NULL; -} - -LPCTSTR SnarlInterface::GetIconsPath() -{ - TCHAR* szIconPath = NULL; - LPCTSTR szPath = GetAppPath(); - if (!szPath) - return NULL; - - size_t nLen = 0; - nLen = _tcsnlen(szPath, MAX_PATH); - if (nLen > 0) - { - nLen += 10 + 1; // etc\\icons\\ + NULL - szIconPath = AllocateString(nLen); - - _tcsncpy(szIconPath, szPath, nLen); - _tcsncat(szIconPath, _T("etc\\icons\\"), nLen); - } - - FreeString(szPath); - - return szIconPath; -} - -HWND SnarlInterface::GetSnarlWindow() -{ - return FindWindow(SnarlWindowClass, SnarlWindowTitle);; -} - -LONG32 SnarlInterface::GetVersion() -{ - return DoRequest(Requests::VersionA()); -} - -BOOL SnarlInterface::IsSnarlRunning() -{ - return IsWindow(GetSnarlWindow()); -} - - -// -------------------------------------------------------------------------------------------- -// SnarlInterface member functions -// -------------------------------------------------------------------------------------------- - -SnarlInterface::SnarlInterface() - : appToken(0), lastMsgToken(0), szPasswordA(NULL), szPasswordW(NULL) -{ -} - -SnarlInterface::~SnarlInterface() -{ - delete [] szPasswordA; - delete [] szPasswordW; -} - -//--------------------------------------------------------------------------------------------- - -LONG32 SnarlInterface::AddAction(LONG32 msgToken, LPCSTR label, LPCSTR cmd) -{ - // addaction?[token=|app-sig=&uid=][&password=]&label=