fixed initialisation of plugindir

This commit is contained in:
Patrick von Reth 2012-02-07 01:40:30 +01:00
parent adbe380b7a
commit 1e480c7e83
2 changed files with 27 additions and 17 deletions

View File

@ -36,7 +36,7 @@ namespace Snore{
QHash<QString,PluginContainer*> SnoreCore::s_pluginCache = QHash<QString,PluginContainer*>() ;
QString SnoreCore::s_pluginPath = QString(qApp->applicationDirPath()+"/snoreplugins");
QDir *SnoreCore::s_pluginDir = NULL;
QString const SnoreCore::version(){
return QString().append(Version::major()).append(".").append(Version::minor()).append(Version::suffix());
@ -80,9 +80,7 @@ QHash<QString, PluginContainer *> SnoreCore::pluginCache(){
return s_pluginCache;
}
void SnoreCore::updatePluginCache(const QString &pluginPath){
if(!pluginPath.isEmpty())
s_pluginPath = pluginPath;
void SnoreCore::updatePluginCache(){
QSettings cache(SnoreCore::pluginDir().absoluteFilePath("plugin.cache"),QSettings::IniFormat);
qDebug()<<"Updating plugin cache"<<cache.fileName();
@ -126,18 +124,29 @@ void SnoreCore::updatePluginCache(const QString &pluginPath){
cache.endArray();
}
const QDir &SnoreCore::pluginDir()
{
//TODO:fix logic
static QDir *plDir = NULL;
if(plDir == NULL){
qDebug()<<"PluginDir"<<s_pluginPath;
plDir = new QDir(s_pluginPath);
if(!plDir->exists())
plDir = new QDir(LIBSNORE_PLUGIN_PATH);
const QDir &SnoreCore::pluginDir(){
if(s_pluginDir == NULL)
setPluginDir();
qDebug()<<"SnorePluginDir:"<<s_pluginDir->path();
return *s_pluginDir;
}
void SnoreCore::setPluginDir(const QString &path){
if(!path.isEmpty()){//path is not empty
QDir *tmp = new QDir(path);
if(tmp->exists()){//path exists
s_pluginDir = tmp;
}else{
delete tmp;
}
}
//if pluginpath is not initialized try snoreplugins/ in application dir
if(s_pluginDir == NULL){
s_pluginDir = new QDir(qApp->applicationDirPath()+"/snoreplugins");
qDebug()<<"PluginDir"<<s_pluginDir->absolutePath();
if(!s_pluginDir->exists())//still not existing? use the path defined on compile time
s_pluginDir = new QDir(LIBSNORE_PLUGIN_PATH);
}
qDebug()<<"SnorePluginDir:"<<plDir->path();
return *plDir;
}
void SnoreCore::publicatePlugin ( PluginContainer::PluginTypes types )

View File

@ -34,8 +34,9 @@ class SNORE_EXPORT SnoreCore:public QObject
public:
static const QString version();
static const QString snoreTMP();
static void updatePluginCache(const QString &pluginPath = "");
static void updatePluginCache();
static const QDir &pluginDir();
static void setPluginDir(const QString &path = "");
public:
SnoreCore (QSystemTrayIcon *trayIcon=0 );
@ -65,6 +66,7 @@ private:
static QHash<QString,PluginContainer*> pluginCache();
static QHash<QString,PluginContainer*> s_pluginCache;
static QDir *s_pluginDir;
ApplicationsList m_applications;
@ -76,7 +78,6 @@ private:
QPointer<SnoreBackend> m_notificationBackend;
QSystemTrayIcon *m_trayIcon;
static QString s_pluginPath;
signals: