diff --git a/src/core/notification/icon.h b/src/core/notification/icon.h index 00e2eef..4eed334 100644 --- a/src/core/notification/icon.h +++ b/src/core/notification/icon.h @@ -55,7 +55,6 @@ public: bool isRemoteFile() const; bool isValid() const; - private: QExplicitlySharedDataPointer d; friend SNORE_EXPORT QDebug (::operator<<) ( QDebug, const Snore::Icon &); diff --git a/src/core/notification/icon_p.cpp b/src/core/notification/icon_p.cpp index 962eece..f9e6c6e 100644 --- a/src/core/notification/icon_p.cpp +++ b/src/core/notification/icon_p.cpp @@ -27,10 +27,12 @@ using namespace Snore; + + IconData::IconData(const QString &url): m_url(url), m_hash(SnoreCorePrivate::computeHash(m_url.toLatin1())), - m_localUrl(QString("%1%2.png").arg(SnoreCorePrivate::snoreTMP(), m_hash)), + m_localUrl(createLocalFileName(m_hash)), m_isLocalFile(false), m_isResource(m_url.startsWith(":/")) { @@ -46,7 +48,7 @@ IconData::IconData(const QImage &img): m_img(img), m_data(dataFromImage(img)), m_hash(SnoreCorePrivate::computeHash(m_data)), - m_localUrl(QString("%1%2.png").arg(SnoreCorePrivate::snoreTMP(), m_hash)), + m_localUrl(createLocalFileName(m_hash)), m_isLocalFile(false), m_isResource(false), m_isRemoteFile(false) diff --git a/src/core/notification/icon_p.h b/src/core/notification/icon_p.h index d902dd5..c63d68e 100644 --- a/src/core/notification/icon_p.h +++ b/src/core/notification/icon_p.h @@ -28,6 +28,7 @@ #include #include #include +#include #include @@ -46,6 +47,20 @@ public: QString localUrl(); void download(); + + QImage m_img; + QByteArray m_data; + QString m_url; + QString m_hash; + QString m_localUrl; + bool m_isLocalFile; + bool m_isResource; + bool m_isRemoteFile; + QMutex m_mutex; + +private: + Q_DISABLE_COPY(IconData) + inline QByteArray dataFromImage(const QImage &image) { QByteArray data; @@ -55,17 +70,16 @@ public: return data; } - QImage m_img; - QByteArray m_data; - QString m_url; - QString m_hash; - QString m_localUrl; - bool m_isLocalFile; - bool m_isResource; - bool m_isRemoteFile; - QMutex m_mutex; -private: - Q_DISABLE_COPY(IconData) + inline QString createLocalFileName(const QString &hash) + { + static QString tmp; + if(tmp.isNull()) + { + tmp = QString("%1/libsnore/").arg(QDir::tempPath()); + QDir(tmp).mkpath("."); + } + return QString("%1%2.png").arg(tmp, hash); + } }; diff --git a/src/core/plugins/plugincontainer.cpp b/src/core/plugins/plugincontainer.cpp index 6e003bc..b7d55de 100644 --- a/src/core/plugins/plugincontainer.cpp +++ b/src/core/plugins/plugincontainer.cpp @@ -84,7 +84,7 @@ SnorePlugin::PluginTypes PluginContainer::typeFromString(const QString &t) return (SnorePlugin::PluginTypes)SnorePlugin::staticMetaObject.enumerator(SnorePlugin::staticMetaObject.indexOfEnumerator("PluginType")).keyToValue(t.toUpper().toLatin1()); } -const QStringList &PluginContainer::types() +const QStringList &PluginContainer::typeNames() { static QStringList out; if(out.isEmpty()) @@ -98,23 +98,29 @@ const QStringList &PluginContainer::types() return out; } +const QList &PluginContainer::types() +{ + static QList t; + if(t.isEmpty()) + { + QMetaEnum e = SnorePlugin::staticMetaObject.enumerator(SnorePlugin::staticMetaObject.indexOfEnumerator("PluginType")); + for (int i = 0; i < e.keyCount(); ++i) + { + t << (SnorePlugin::PluginTypes) e.value(i); + } + } + return t; +} void PluginContainer::updatePluginCache() { snoreDebug( SNORE_DEBUG ) << "Updating plugin cache"; cache().remove(""); -#if defined(Q_OS_LINUX) - const QString extensions = "so"; -#elif defined(Q_OS_WIN) - const QString extensions = "dll"; -#elif defined(Q_OS_MAC) - const QString extensions = "dylib"; -#endif - foreach(const QString &type,PluginContainer::types()) + foreach(const QString &type,PluginContainer::typeNames()) { - foreach (const QFileInfo &file, pluginDir().entryInfoList(QStringList(QString("libsnore_%1_*.%2").arg(type.toLower(), extensions)), QDir::Files, QDir::Name | QDir::IgnoreCase )) + foreach (const QFileInfo &file, pluginDir().entryInfoList(QStringList(QString("libsnore_%1_*.%2").arg(type.toLower(), pluginExtention())), QDir::Files, QDir::Name | QDir::IgnoreCase )) { snoreDebug( SNORE_DEBUG ) << "adding" << file.absoluteFilePath(); QPluginLoader loader(file.absoluteFilePath()); @@ -181,10 +187,9 @@ const QHash PluginContainer::pluginCache(SnorePlugin QHash out; if(type == SnorePlugin::ALL) { - QMetaEnum e = SnorePlugin::staticMetaObject.enumerator(SnorePlugin::staticMetaObject.indexOfEnumerator("PluginType")); - for (int i = 0; i < e.keyCount(); ++i) + foreach(const SnorePlugin::PluginTypes &t,types()) { - out.unite(s_pluginCache.value((SnorePlugin::PluginTypes) e.value(i))); + out.unite(s_pluginCache.value(t)); } } else @@ -204,7 +209,8 @@ const QDir PluginContainer::pluginDir() list << QString("%1/../lib/libsnore").arg(appDir) << QString("%1/../lib64/libsnore").arg(appDir) << QString("%1/libsnore").arg(appDir) - << QLatin1String(LIBSNORE_PLUGIN_PATH); + << QLatin1String(LIBSNORE_PLUGIN_PATH) + << appDir; foreach(const QString &p, list) { QDir dir(p); diff --git a/src/core/plugins/plugincontainer.h b/src/core/plugins/plugincontainer.h index 3798f54..8a082ce 100644 --- a/src/core/plugins/plugincontainer.h +++ b/src/core/plugins/plugincontainer.h @@ -29,14 +29,11 @@ -namespace Snore{ -class SnoreCore; -class SnorePlugin; -class SnoreFrontend; -class SnoreBackend; -class SnoreSecondaryBackend; +namespace Snore +{ -class SNORE_EXPORT PluginContainer{ +class SNORE_EXPORT PluginContainer +{ public: static const QHash pluginCache(SnorePlugin::PluginTypes type); @@ -50,11 +47,23 @@ public: static SnorePlugin::PluginTypes typeFromString(const QString &t); - static const QStringList &types(); + static const QStringList &typeNames(); + static const QList &types(); private: void static updatePluginCache(); static const QDir pluginDir(); + static inline const QString pluginExtention() + { +#if defined(Q_OS_LINUX) + return QLatin1String("so"); +#elif defined(Q_OS_WIN) + return QLatin1String("dll"); +#elif defined(Q_OS_MAC) + return QLatin1String("dylib"); +#endif + } + static QHash > s_pluginCache; static inline QSettings &cache() diff --git a/src/core/snore_p.cpp b/src/core/snore_p.cpp index 16d4946..ab7024a 100644 --- a/src/core/snore_p.cpp +++ b/src/core/snore_p.cpp @@ -27,18 +27,6 @@ using namespace Snore; - -QString const SnoreCorePrivate::snoreTMP() -{ - static QString tmp; - if(tmp.isNull()) - { - tmp = QString("%1/libsnore/").arg(QDir::tempPath()); - QDir(tmp).mkpath("."); - } - return tmp; -} - SnoreCorePrivate::SnoreCorePrivate(QSystemTrayIcon *trayIcon): m_trayIcon(trayIcon), m_defaultApp("SnoreNotify",Icon(":/root/snore.png")) diff --git a/src/core/snore_p.h b/src/core/snore_p.h index 91b124b..5c00b1e 100644 --- a/src/core/snore_p.h +++ b/src/core/snore_p.h @@ -36,7 +36,6 @@ class SNORE_EXPORT SnoreCorePrivate : public QObject Q_OBJECT public: - static const QString snoreTMP(); static inline QString computeHash(const QByteArray &data) { return QCryptographicHash::hash(data,QCryptographicHash::Md5).toHex(); diff --git a/src/snorenotify.cpp b/src/snorenotify.cpp index 462a1c3..3f6ec54 100644 --- a/src/snorenotify.cpp +++ b/src/snorenotify.cpp @@ -55,10 +55,15 @@ SnoreNotify::~SnoreNotify(){ delete m_trayIcon; } -void SnoreNotify::load(){ - if(m_settings.contains("notificationBackend") && !m_settings.value("notificationBackend").toString().isEmpty()) +void SnoreNotify::load() +{ + QString backend = m_settings.value("notificationBackend").toString(); + if(!backend.isEmpty()) { - m_snore->setPrimaryNotificationBackend(m_settings.value("notificationBackend").toString()); + if(!m_snore->setPrimaryNotificationBackend(backend)) + { + m_snore->setPrimaryNotificationBackend(); + } } else {