mirror of
https://github.com/status-im/snorenotify.git
synced 2025-02-17 02:46:23 +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";
|
||||
|
||||
s_pluginCache.clear();
|
||||
clear();
|
||||
cache().remove("");
|
||||
|
||||
foreach(const QString &type,PluginContainer::types()){
|
||||
QDir plPath(SnoreCorePrivate::pluginDir().absoluteFilePath(type));
|
||||
@ -140,43 +140,45 @@ void PluginContainer::updatePluginCache(){
|
||||
}
|
||||
|
||||
qDebug()<<s_pluginCache.keys();
|
||||
setValue("version",Version::revision());
|
||||
setValue("buildtime",Version::buildTime());
|
||||
setValue("pluginPath",SnoreCorePrivate::pluginDir().absolutePath());
|
||||
cache().setValue("version",Version::revision());
|
||||
cache().setValue("buildtime",Version::buildTime());
|
||||
cache().setValue("pluginPath",SnoreCorePrivate::pluginDir().absolutePath());
|
||||
QList<PluginContainer*> plugins = s_pluginCache.values();
|
||||
beginWriteArray("plugins");
|
||||
cache().beginWriteArray("plugins");
|
||||
for(int i=0;i< plugins.size();++i) {
|
||||
setArrayIndex(i);
|
||||
setValue("fileName",plugins[i]->file());
|
||||
setValue("name", plugins[i]->name());
|
||||
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());
|
||||
}
|
||||
endArray();
|
||||
cache().endArray();
|
||||
}
|
||||
|
||||
QHash<QString, PluginContainer *> PluginContainer::pluginCache(){
|
||||
if(!s_pluginCache.isEmpty())
|
||||
{
|
||||
return s_pluginCache;
|
||||
QString version = value("version").toString();
|
||||
QString buildTime = value("buildtime").toString();
|
||||
int size = beginReadArray("plugins");
|
||||
}
|
||||
QString version = cache().value("version").toString();
|
||||
QString buildTime = cache().value("buildtime").toString();
|
||||
int size = cache().beginReadArray("plugins");
|
||||
if(size == 0 ||
|
||||
version != Version::revision() ||
|
||||
buildTime != Version::buildTime())
|
||||
{
|
||||
endArray();
|
||||
cache().endArray();
|
||||
updatePluginCache();
|
||||
}
|
||||
else
|
||||
{
|
||||
for(int i=0;i<size;++i)
|
||||
{
|
||||
setArrayIndex(i);
|
||||
SnorePlugin::PluginType type = (SnorePlugin::PluginType)value("type").toInt();
|
||||
PluginContainer *info = new PluginContainer(value("fileName").toString(),value("name").toString(),type);
|
||||
cache().setArrayIndex(i);
|
||||
SnorePlugin::PluginType type = (SnorePlugin::PluginType)cache().value("type").toInt();
|
||||
PluginContainer *info = new PluginContainer(cache().value("fileName").toString(),cache().value("name").toString(),type);
|
||||
s_pluginCache.insert(info->name(),info);
|
||||
}
|
||||
endArray();
|
||||
cache().endArray();
|
||||
}
|
||||
|
||||
return s_pluginCache;
|
||||
|
@ -53,68 +53,21 @@ public:
|
||||
static SnorePlugin::PluginType typeFromString(const QString &t);
|
||||
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:
|
||||
void static updatePluginCache();
|
||||
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 QSettings cache("SnoreNotify","libsnore");
|
||||
return cache;
|
||||
static QSettings *_cache = NULL;
|
||||
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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user