This commit is contained in:
Patrick von Reth 2014-01-23 18:41:57 +01:00
parent caeb0493d7
commit 7f654e935f
8 changed files with 74 additions and 52 deletions

View File

@ -55,7 +55,6 @@ public:
bool isRemoteFile() const; bool isRemoteFile() const;
bool isValid() const; bool isValid() const;
private: private:
QExplicitlySharedDataPointer<IconData> d; QExplicitlySharedDataPointer<IconData> d;
friend SNORE_EXPORT QDebug (::operator<<) ( QDebug, const Snore::Icon &); friend SNORE_EXPORT QDebug (::operator<<) ( QDebug, const Snore::Icon &);

View File

@ -27,10 +27,12 @@
using namespace Snore; using namespace Snore;
IconData::IconData(const QString &url): IconData::IconData(const QString &url):
m_url(url), m_url(url),
m_hash(SnoreCorePrivate::computeHash(m_url.toLatin1())), 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_isLocalFile(false),
m_isResource(m_url.startsWith(":/")) m_isResource(m_url.startsWith(":/"))
{ {
@ -46,7 +48,7 @@ IconData::IconData(const QImage &img):
m_img(img), m_img(img),
m_data(dataFromImage(img)), m_data(dataFromImage(img)),
m_hash(SnoreCorePrivate::computeHash(m_data)), 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_isLocalFile(false),
m_isResource(false), m_isResource(false),
m_isRemoteFile(false) m_isRemoteFile(false)

View File

@ -28,6 +28,7 @@
#include <QBuffer> #include <QBuffer>
#include <QFile> #include <QFile>
#include <QDebug> #include <QDebug>
#include <QDir>
#include <QMutex> #include <QMutex>
@ -46,6 +47,20 @@ public:
QString localUrl(); QString localUrl();
void download(); 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) inline QByteArray dataFromImage(const QImage &image)
{ {
QByteArray data; QByteArray data;
@ -55,17 +70,16 @@ public:
return data; return data;
} }
QImage m_img; inline QString createLocalFileName(const QString &hash)
QByteArray m_data; {
QString m_url; static QString tmp;
QString m_hash; if(tmp.isNull())
QString m_localUrl; {
bool m_isLocalFile; tmp = QString("%1/libsnore/").arg(QDir::tempPath());
bool m_isResource; QDir(tmp).mkpath(".");
bool m_isRemoteFile; }
QMutex m_mutex; return QString("%1%2.png").arg(tmp, hash);
private: }
Q_DISABLE_COPY(IconData)
}; };

View File

@ -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()); 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; static QStringList out;
if(out.isEmpty()) if(out.isEmpty())
@ -98,23 +98,29 @@ const QStringList &PluginContainer::types()
return out; return out;
} }
const QList<SnorePlugin::PluginTypes> &PluginContainer::types()
{
static QList<SnorePlugin::PluginTypes> 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() void PluginContainer::updatePluginCache()
{ {
snoreDebug( SNORE_DEBUG ) << "Updating plugin cache"; snoreDebug( SNORE_DEBUG ) << "Updating plugin cache";
cache().remove(""); 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(); snoreDebug( SNORE_DEBUG ) << "adding" << file.absoluteFilePath();
QPluginLoader loader(file.absoluteFilePath()); QPluginLoader loader(file.absoluteFilePath());
@ -181,10 +187,9 @@ const QHash<QString, PluginContainer *> PluginContainer::pluginCache(SnorePlugin
QHash<QString, PluginContainer *> out; QHash<QString, PluginContainer *> out;
if(type == SnorePlugin::ALL) if(type == SnorePlugin::ALL)
{ {
QMetaEnum e = SnorePlugin::staticMetaObject.enumerator(SnorePlugin::staticMetaObject.indexOfEnumerator("PluginType")); foreach(const SnorePlugin::PluginTypes &t,types())
for (int i = 0; i < e.keyCount(); ++i)
{ {
out.unite(s_pluginCache.value((SnorePlugin::PluginTypes) e.value(i))); out.unite(s_pluginCache.value(t));
} }
} }
else else
@ -204,7 +209,8 @@ const QDir PluginContainer::pluginDir()
list << QString("%1/../lib/libsnore").arg(appDir) list << QString("%1/../lib/libsnore").arg(appDir)
<< QString("%1/../lib64/libsnore").arg(appDir) << QString("%1/../lib64/libsnore").arg(appDir)
<< QString("%1/libsnore").arg(appDir) << QString("%1/libsnore").arg(appDir)
<< QLatin1String(LIBSNORE_PLUGIN_PATH); << QLatin1String(LIBSNORE_PLUGIN_PATH)
<< appDir;
foreach(const QString &p, list) foreach(const QString &p, list)
{ {
QDir dir(p); QDir dir(p);

View File

@ -29,14 +29,11 @@
namespace Snore{ namespace Snore
class SnoreCore; {
class SnorePlugin;
class SnoreFrontend;
class SnoreBackend;
class SnoreSecondaryBackend;
class SNORE_EXPORT PluginContainer{ class SNORE_EXPORT PluginContainer
{
public: public:
static const QHash<QString, PluginContainer *> pluginCache(SnorePlugin::PluginTypes type); static const QHash<QString, PluginContainer *> pluginCache(SnorePlugin::PluginTypes type);
@ -50,11 +47,23 @@ public:
static SnorePlugin::PluginTypes typeFromString(const QString &t); static SnorePlugin::PluginTypes typeFromString(const QString &t);
static const QStringList &types(); static const QStringList &typeNames();
static const QList<SnorePlugin::PluginTypes> &types();
private: private:
void static updatePluginCache(); void static updatePluginCache();
static const QDir pluginDir(); 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<SnorePlugin::PluginTypes, QHash<QString,PluginContainer*> > s_pluginCache; static QHash<SnorePlugin::PluginTypes, QHash<QString,PluginContainer*> > s_pluginCache;
static inline QSettings &cache() static inline QSettings &cache()

View File

@ -27,18 +27,6 @@
using namespace Snore; 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): SnoreCorePrivate::SnoreCorePrivate(QSystemTrayIcon *trayIcon):
m_trayIcon(trayIcon), m_trayIcon(trayIcon),
m_defaultApp("SnoreNotify",Icon(":/root/snore.png")) m_defaultApp("SnoreNotify",Icon(":/root/snore.png"))

View File

@ -36,7 +36,6 @@ class SNORE_EXPORT SnoreCorePrivate : public QObject
Q_OBJECT Q_OBJECT
public: public:
static const QString snoreTMP();
static inline QString computeHash(const QByteArray &data) static inline QString computeHash(const QByteArray &data)
{ {
return QCryptographicHash::hash(data,QCryptographicHash::Md5).toHex(); return QCryptographicHash::hash(data,QCryptographicHash::Md5).toHex();

View File

@ -55,10 +55,15 @@ SnoreNotify::~SnoreNotify(){
delete m_trayIcon; delete m_trayIcon;
} }
void SnoreNotify::load(){ void SnoreNotify::load()
if(m_settings.contains("notificationBackend") && !m_settings.value("notificationBackend").toString().isEmpty()) {
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 else
{ {