diff --git a/src/core/application.cpp b/src/core/application.cpp index b6f7fbd..0262649 100644 --- a/src/core/application.cpp +++ b/src/core/application.cpp @@ -18,9 +18,10 @@ */ #include "application.h" -namespace Snore{ +using namespace Snore; + Application::Application (const QString &name, const Icon &icon) : m_name ( name ), m_icon(icon), @@ -34,14 +35,11 @@ Application::Application() : Application::~Application() { - foreach ( Alert *a,m_alerts ) - { - a->deleteLater(); - } } void Application::addAlert ( Alert *alert ) { + alert->setParent(this); m_alerts.insert ( alert->name(),alert ); } @@ -102,4 +100,3 @@ bool Alert::isActive() const return m_active; } -} diff --git a/src/core/notification/icon_p.h b/src/core/notification/icon_p.h index bdb71c2..4f1e57d 100644 --- a/src/core/notification/icon_p.h +++ b/src/core/notification/icon_p.h @@ -70,6 +70,9 @@ public: QString m_hash; bool m_isLocalFile; +private: + Q_DISABLE_COPY(IconData) + }; } diff --git a/src/core/plugins/plugincontainer.cpp b/src/core/plugins/plugincontainer.cpp index b0bf467..771836c 100644 --- a/src/core/plugins/plugincontainer.cpp +++ b/src/core/plugins/plugincontainer.cpp @@ -23,34 +23,36 @@ #include "snorebackend.h" #include "snorefrontend.h" - -#include #include #include #include -namespace Snore{ +using namespace Snore; -PluginContainer::PluginContainer(QString fileName, QString pluginName, PluginContainer::PluginType type) - :m_pluginFile(fileName), - m_pluginName(pluginName), - m_pluginType(type) +PluginContainer::PluginContainer(QString fileName, QString pluginName, PluginContainer::PluginType type): + m_pluginFile(fileName), + m_pluginName(pluginName), + m_pluginType(type) { } -PluginContainer::~PluginContainer(){ +PluginContainer::~PluginContainer() +{ if(m_instance) + { m_instance->deleteLater(); + } } -SnorePlugin *PluginContainer::load(){ +SnorePlugin *PluginContainer::load() +{ if(m_instance != NULL) return m_instance; QPluginLoader loader ( SnoreCore::pluginDir().absoluteFilePath(file())); - qDebug()<<"Trying to load"< #include -namespace Snore{ +using namespace Snore; QHash SnoreCore::s_pluginCache = QHash() ; -QDir *SnoreCore::s_pluginDir = NULL; - -QSettings *SnoreCore::cacheFile(){ +QSettings &SnoreCore::cacheFile(){ #ifdef Q_OS_LINUX - return new QSettings("TheOneRing","libsnore"); + static QSettings cache("TheOneRing","libsnore"); #else - return new QSettings(SnoreCore::pluginDir().absoluteFilePath("plugin.cache"),QSettings::IniFormat); + static QSettings cache(SnoreCore::pluginDir().absoluteFilePath("plugin.cache"),QSettings::IniFormat); #endif + return cache; } void SnoreCore::slotNotificationClosed(Notification n) @@ -54,11 +53,6 @@ void SnoreCore::slotNotificationClosed(Notification n) emit notificationClosed(n); } -QString const SnoreCore::version(){ - static QString ver(QString().append(Version::major()).append(".").append(Version::minor()).append(Version::suffix())); - return ver; -} - QString const SnoreCore::snoreTMP(){ static const QString tmp = QString("%1/SnoreNotify/").arg(QDir::temp().path()); return tmp; @@ -79,30 +73,30 @@ SnoreCore::SnoreCore ( QSystemTrayIcon *trayIcon ) : QHash SnoreCore::pluginCache(){ if(!s_pluginCache.isEmpty()) return s_pluginCache; - QSettings *cache = cacheFile(); - QString version = cache->value("version").toString(); - QString path = cache->value("pluginPath").toString(); - int size = cache->beginReadArray("plugins"); + QSettings &cache = cacheFile(); + QString version = cache.value("version").toString(); + QString path = cache.value("pluginPath").toString(); + int size = cache.beginReadArray("plugins"); if(size == 0 || version != Version::revision() || path != pluginDir().path()){ qDebug() << version << "!=" << Version::revision(); qDebug() << path << "!=" << pluginDir().path(); updatePluginCache(); }else{ for(int i=0;isetArrayIndex(i); - PluginContainer::PluginType type = (PluginContainer::PluginType)cache->value("type").toInt(); - PluginContainer *info = new PluginContainer(cache->value("fileName").toString(),cache->value("name").toString(),type); + cache.setArrayIndex(i); + PluginContainer::PluginType type = (PluginContainer::PluginType)cache.value("type").toInt(); + PluginContainer *info = new PluginContainer(cache.value("fileName").toString(),cache.value("name").toString(),type); s_pluginCache.insert(info->name(),info); } - cache->endArray(); + cache.endArray(); } return s_pluginCache; } void SnoreCore::updatePluginCache(){ - QSettings *cache = cacheFile(); - qDebug() << "Updating plugin cache" << cache->fileName(); + QSettings &cache = cacheFile(); + qDebug() << "Updating plugin cache" << cache.fileName(); s_pluginCache.clear(); @@ -132,57 +126,47 @@ void SnoreCore::updatePluginCache(){ } qDebug()<setValue("version",Version::revision()); - cache->setValue("pluginPath",pluginDir().path()); + cache.setValue("version",Version::revision()); + cache.setValue("pluginPath",pluginDir().path()); QList plugins = s_pluginCache.values(); - cache->beginWriteArray("plugins"); + cache.beginWriteArray("plugins"); for(int i=0;i< plugins.size();++i) { - cache->setArrayIndex(i); - cache->setValue("fileName",plugins[i]->file()); - cache->setValue("name", plugins[i]->name()); - cache->setValue("type",(int)plugins[i]->type()); + cache.setArrayIndex(i); + cache.setValue("fileName",plugins[i]->file()); + cache.setValue("name", plugins[i]->name()); + cache.setValue("type",(int)plugins[i]->type()); } - cache->endArray(); + cache.endArray(); } const QDir &SnoreCore::pluginDir(){ - if(s_pluginDir == NULL) - setPluginDir(); - qDebug()<<"SnorePluginDir:"<path(); - return *s_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::setPluginDir(const QString &path){ - if(!path.isEmpty()){//path is not empty - QDir *tmp = new QDir(path); - if(tmp->exists()){//path exists - s_pluginDir = tmp; - }else{ - delete tmp; - } - } - //if pluginpath is not initialized try snoreplugins/ in application dir - if(s_pluginDir == NULL){ - s_pluginDir = new QDir(qApp->applicationDirPath()+"/snoreplugins"); - qDebug()<<"PluginDir"<absolutePath(); - if(!s_pluginDir->exists())//still not existing? use the path defined on compile time - s_pluginDir = new QDir(LIBSNORE_PLUGIN_PATH); - } -} void SnoreCore::loadPlugins ( PluginContainer::PluginTypes types ) { - qDebug()<<"PluginInfo"<type())){ - switch(info->type()){ - case PluginContainer::BACKEND:{ + if(types == PluginContainer::ALL or 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:{ + case PluginContainer::SECONDARY_BACKEND: + { SnoreSecondaryBackend *nb = qobject_cast ( info->load() ); if(!nb->init( this )){ nb->deleteLater(); @@ -191,7 +175,8 @@ void SnoreCore::loadPlugins ( PluginContainer::PluginTypes types ) m_secondaryNotificationBackends.append(info->name()); break; } - case PluginContainer::FRONTEND:{ + case PluginContainer::FRONTEND: + { SnoreFrontend * nf = qobject_cast (info->load()); qDebug() <name()<<"is a Notification_Frontend"; if(!nf->init( this )){ @@ -201,7 +186,8 @@ void SnoreCore::loadPlugins ( PluginContainer::PluginTypes types ) m_Frontends.append(info->name()); break; } - case PluginContainer::PLUGIN:{ + case PluginContainer::PLUGIN: + { qDebug() <name()<<"is a SnorePlugin"; if(!info->load()->init(this)){ info->load()->deleteLater(); @@ -210,9 +196,10 @@ void SnoreCore::loadPlugins ( PluginContainer::PluginTypes types ) m_plugins.append(info->name()); break; } - default:{ + default: + { std::cerr<<"Plugin Cache corrupted"<file().toLatin1().constData()<type()).toLatin1().constData()<file().toLocal8Bit().constData()<type()).toLatin1().constData()<actionInvoked ( notification ); @@ -372,5 +359,3 @@ bool SnoreCore::primaryBackendSupportsRichtext() { return m_notificationBackend->supportsRichtext(); } - -} diff --git a/src/core/snore.h b/src/core/snore.h index 3582b12..619c169 100644 --- a/src/core/snore.h +++ b/src/core/snore.h @@ -33,15 +33,13 @@ class QSettings; namespace Snore{ -class SNORE_EXPORT SnoreCore:public QObject +class SNORE_EXPORT SnoreCore : public QObject { Q_OBJECT public: - static const QString version(); static const QString snoreTMP(); static void updatePluginCache(); static const QDir &pluginDir(); - static void setPluginDir(const QString &path = ""); public: SnoreCore (QSystemTrayIcon *trayIcon = NULL ); @@ -76,10 +74,9 @@ public: private: static QHash pluginCache(); - static QSettings *cacheFile(); + static QSettings &cacheFile(); static QHash s_pluginCache; - static QDir *s_pluginDir; ApplicationsList m_applications; diff --git a/src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.cpp b/src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.cpp index f96ef1b..da74a12 100644 --- a/src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.cpp +++ b/src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.cpp @@ -22,6 +22,7 @@ #include "plugins/backends/freedesktop/fredesktopnotification.h" #include "core/snore.h" +#include "core/version.h" #include #include @@ -126,16 +127,15 @@ QStringList FreedesktopFrontend::GetCapabilities() return QStringList() << "body" // << "body-hyperlinks" - // << "body-markup" + << "body-markup" << "icon-static" - << "actions" - ; + << "actions"; } QString FreedesktopFrontend::GetServerInformation(QString& vendor, QString& version, QString& specVersion) { vendor = "Snore"; - version = snore()->version(); + version = Version::version(); specVersion = "0"; return "Snore"; } diff --git a/src/trayicon.cpp b/src/trayicon.cpp index 481a856..9903a8f 100644 --- a/src/trayicon.cpp +++ b/src/trayicon.cpp @@ -24,6 +24,8 @@ #include #include +#include "core/version.h" + using namespace Snore; TrayIcon::TrayIcon() @@ -36,7 +38,7 @@ void TrayIcon::initConextMenu(SnoreCore *snore){ _trayIcon->setVisible(true); _trayMenu = new QMenu("SnoreNotify"); - _trayMenu->addAction(QString("SnoreNotify ").append(_snore->version())); + _trayMenu->addAction(QString("SnoreNotify ").append(Version::version())); _trayMenu->addSeparator(); foreach(const QString &back,_snore->notificationBackends()){ QAction *b= new QAction(back,this);