mirror of
https://github.com/status-im/snorenotify.git
synced 2025-02-20 03:58:10 +00:00
grr that was horrible
This commit is contained in:
parent
f5dba89ae0
commit
fddc6d1777
@ -112,7 +112,7 @@ void PluginContainer::updatePluginCache(){
|
|||||||
qDebug() << "Updating plugin cache";
|
qDebug() << "Updating plugin cache";
|
||||||
|
|
||||||
s_pluginCache.clear();
|
s_pluginCache.clear();
|
||||||
clear();
|
cache().remove("");
|
||||||
|
|
||||||
foreach(const QString &type,PluginContainer::types()){
|
foreach(const QString &type,PluginContainer::types()){
|
||||||
QDir plPath(SnoreCorePrivate::pluginDir().absoluteFilePath(type));
|
QDir plPath(SnoreCorePrivate::pluginDir().absoluteFilePath(type));
|
||||||
@ -140,43 +140,45 @@ void PluginContainer::updatePluginCache(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
qDebug()<<s_pluginCache.keys();
|
qDebug()<<s_pluginCache.keys();
|
||||||
setValue("version",Version::revision());
|
cache().setValue("version",Version::revision());
|
||||||
setValue("buildtime",Version::buildTime());
|
cache().setValue("buildtime",Version::buildTime());
|
||||||
setValue("pluginPath",SnoreCorePrivate::pluginDir().absolutePath());
|
cache().setValue("pluginPath",SnoreCorePrivate::pluginDir().absolutePath());
|
||||||
QList<PluginContainer*> plugins = s_pluginCache.values();
|
QList<PluginContainer*> plugins = s_pluginCache.values();
|
||||||
beginWriteArray("plugins");
|
cache().beginWriteArray("plugins");
|
||||||
for(int i=0;i< plugins.size();++i) {
|
for(int i=0;i< plugins.size();++i) {
|
||||||
setArrayIndex(i);
|
cache().setArrayIndex(i);
|
||||||
setValue("fileName",plugins[i]->file());
|
cache().setValue("fileName",plugins[i]->file());
|
||||||
setValue("name", plugins[i]->name());
|
cache().setValue("name", plugins[i]->name());
|
||||||
setValue("type",(int)plugins[i]->type());
|
cache().setValue("type",(int)plugins[i]->type());
|
||||||
}
|
}
|
||||||
endArray();
|
cache().endArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
QHash<QString, PluginContainer *> PluginContainer::pluginCache(){
|
QHash<QString, PluginContainer *> PluginContainer::pluginCache(){
|
||||||
if(!s_pluginCache.isEmpty())
|
if(!s_pluginCache.isEmpty())
|
||||||
|
{
|
||||||
return s_pluginCache;
|
return s_pluginCache;
|
||||||
QString version = value("version").toString();
|
}
|
||||||
QString buildTime = value("buildtime").toString();
|
QString version = cache().value("version").toString();
|
||||||
int size = beginReadArray("plugins");
|
QString buildTime = cache().value("buildtime").toString();
|
||||||
|
int size = cache().beginReadArray("plugins");
|
||||||
if(size == 0 ||
|
if(size == 0 ||
|
||||||
version != Version::revision() ||
|
version != Version::revision() ||
|
||||||
buildTime != Version::buildTime())
|
buildTime != Version::buildTime())
|
||||||
{
|
{
|
||||||
endArray();
|
cache().endArray();
|
||||||
updatePluginCache();
|
updatePluginCache();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for(int i=0;i<size;++i)
|
for(int i=0;i<size;++i)
|
||||||
{
|
{
|
||||||
setArrayIndex(i);
|
cache().setArrayIndex(i);
|
||||||
SnorePlugin::PluginType type = (SnorePlugin::PluginType)value("type").toInt();
|
SnorePlugin::PluginType type = (SnorePlugin::PluginType)cache().value("type").toInt();
|
||||||
PluginContainer *info = new PluginContainer(value("fileName").toString(),value("name").toString(),type);
|
PluginContainer *info = new PluginContainer(cache().value("fileName").toString(),cache().value("name").toString(),type);
|
||||||
s_pluginCache.insert(info->name(),info);
|
s_pluginCache.insert(info->name(),info);
|
||||||
}
|
}
|
||||||
endArray();
|
cache().endArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
return s_pluginCache;
|
return s_pluginCache;
|
||||||
|
@ -53,68 +53,21 @@ public:
|
|||||||
static SnorePlugin::PluginType typeFromString(const QString &t);
|
static SnorePlugin::PluginType typeFromString(const QString &t);
|
||||||
static const QStringList &types();
|
static const QStringList &types();
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
static inline QVariant value(const QString &key, const QVariant &defaultValue = QVariant())
|
|
||||||
{
|
|
||||||
return cache().value(pluginPathHash(key), defaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void setValue(const QString &key, const QVariant &value)
|
|
||||||
{
|
|
||||||
cache().setValue(pluginPathHash(key), value);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void clear()
|
|
||||||
{
|
|
||||||
cache().remove(pluginPathHash());
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void setArrayIndex(int i)
|
|
||||||
{
|
|
||||||
cache().setArrayIndex(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void beginWriteArray(const QString &prefix, int size = -1)
|
|
||||||
{
|
|
||||||
cache().beginWriteArray(pluginPathHash(prefix), size);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int beginReadArray(const QString &prefix)
|
|
||||||
{
|
|
||||||
return cache().beginReadArray(pluginPathHash(prefix));
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void endArray()
|
|
||||||
{
|
|
||||||
cache().endArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void static updatePluginCache();
|
void static updatePluginCache();
|
||||||
static QHash<QString,PluginContainer*> s_pluginCache;
|
static QHash<QString,PluginContainer*> s_pluginCache;
|
||||||
static inline QString pluginPathHash(const QString &key = QString())
|
|
||||||
{
|
|
||||||
static QString s;
|
|
||||||
if(s.isEmpty())
|
|
||||||
{
|
|
||||||
QCryptographicHash h(QCryptographicHash::Md5);
|
|
||||||
h.addData(SnoreCorePrivate::pluginDir().absolutePath().toLatin1());
|
|
||||||
s = h.result().toHex();
|
|
||||||
}
|
|
||||||
if(key.isEmpty())
|
|
||||||
{
|
|
||||||
return QString("%1/").arg(s);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return QString("%1/%2").arg(s, key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
static inline QSettings &cache()
|
static inline QSettings &cache()
|
||||||
{
|
{
|
||||||
static QSettings cache("SnoreNotify","libsnore");
|
static QSettings *_cache = NULL;
|
||||||
return cache;
|
if(_cache == NULL)
|
||||||
|
{
|
||||||
|
_cache = new QSettings("SnoreNotify","libsnore");
|
||||||
|
QCryptographicHash h(QCryptographicHash::Md5);
|
||||||
|
h.addData(SnoreCorePrivate::pluginDir().absolutePath().toLatin1());
|
||||||
|
_cache->beginGroup( h.result().toHex());
|
||||||
|
}
|
||||||
|
return *_cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString m_pluginFile;
|
QString m_pluginFile;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user