cleanup
This commit is contained in:
parent
caeb0493d7
commit
7f654e935f
|
@ -55,7 +55,6 @@ public:
|
|||
bool isRemoteFile() const;
|
||||
bool isValid() const;
|
||||
|
||||
|
||||
private:
|
||||
QExplicitlySharedDataPointer<IconData> d;
|
||||
friend SNORE_EXPORT QDebug (::operator<<) ( QDebug, const Snore::Icon &);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include <QBuffer>
|
||||
#include <QFile>
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
|
||||
#include <QMutex>
|
||||
|
||||
|
@ -46,14 +47,6 @@ public:
|
|||
QString localUrl();
|
||||
void download();
|
||||
|
||||
inline QByteArray dataFromImage(const QImage &image)
|
||||
{
|
||||
QByteArray data;
|
||||
QBuffer buffer( &data );
|
||||
buffer.open( QBuffer::WriteOnly );
|
||||
image.save( &buffer, "PNG" );
|
||||
return data;
|
||||
}
|
||||
|
||||
QImage m_img;
|
||||
QByteArray m_data;
|
||||
|
@ -64,9 +57,30 @@ public:
|
|||
bool m_isResource;
|
||||
bool m_isRemoteFile;
|
||||
QMutex m_mutex;
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(IconData)
|
||||
|
||||
inline QByteArray dataFromImage(const QImage &image)
|
||||
{
|
||||
QByteArray data;
|
||||
QBuffer buffer( &data );
|
||||
buffer.open( QBuffer::WriteOnly );
|
||||
image.save( &buffer, "PNG" );
|
||||
return data;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -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<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()
|
||||
{
|
||||
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<QString, PluginContainer *> PluginContainer::pluginCache(SnorePlugin
|
|||
QHash<QString, PluginContainer *> 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);
|
||||
|
|
|
@ -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<QString, PluginContainer *> 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<SnorePlugin::PluginTypes> &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<SnorePlugin::PluginTypes, QHash<QString,PluginContainer*> > s_pluginCache;
|
||||
|
||||
static inline QSettings &cache()
|
||||
|
|
|
@ -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"))
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
m_snore->setPrimaryNotificationBackend(m_settings.value("notificationBackend").toString());
|
||||
QString backend = m_settings.value("notificationBackend").toString();
|
||||
if(!backend.isEmpty())
|
||||
{
|
||||
if(!m_snore->setPrimaryNotificationBackend(backend))
|
||||
{
|
||||
m_snore->setPrimaryNotificationBackend();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue