KNotify
knotifyconfig.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "knotifyconfig.h"
00022
00023 #include <ksharedconfig.h>
00024 #include <kconfiggroup.h>
00025 #include <kdebug.h>
00026 #include <kglobal.h>
00027 #include <QCache>
00028
00029 typedef QCache<QString, KSharedConfig::Ptr> ConfigCache;
00030 K_GLOBAL_STATIC_WITH_ARGS(ConfigCache , static_cache, (15))
00031
00032 static KSharedConfig::Ptr retrieve_from_cache(const QString& filename, const char *resourceType="config")
00033 {
00034 QCache<QString, KSharedConfig::Ptr> &cache = *static_cache;
00035 if (cache.contains(filename))
00036 return *cache[filename];
00037 KSharedConfig::Ptr m = KSharedConfig::openConfig (filename , KConfig::NoGlobals, resourceType );
00038 cache.insert(filename, new KSharedConfig::Ptr(m));
00039 return m;
00040 }
00041
00042 void KNotifyConfig::clearCache()
00043 {
00044 static_cache->clear();
00045 }
00046
00047
00048 KNotifyConfig::KNotifyConfig( const QString & _appname, const ContextList & _contexts, const QString & _eventid )
00049 : appname (_appname),
00050 eventsfile(retrieve_from_cache(_appname+'/'+_appname + ".notifyrc" , "data" )),
00051 configfile(retrieve_from_cache(_appname+QString::fromAscii( ".notifyrc" ))),
00052 contexts(_contexts) , eventid(_eventid)
00053 {
00054
00055 }
00056
00057 KNotifyConfig::~KNotifyConfig()
00058 {
00059 }
00060
00061 QString KNotifyConfig::readEntry( const QString & entry, bool path )
00062 {
00063 QPair<QString , QString> context;
00064 foreach( context , contexts )
00065 {
00066 const QString group="Event/" + eventid + '/' + context.first + '/' + context.second;
00067 if( configfile->hasGroup( group ) )
00068 {
00069 KConfigGroup cg(configfile, group);
00070 QString p=path ? cg.readPathEntry(entry, QString()) : cg.readEntry(entry,QString());
00071 if(!p.isNull())
00072 return p;
00073 }
00074 }
00075
00076 const QString group="Event/" + eventid ;
00077 if(configfile->hasGroup( group ) )
00078 {
00079 KConfigGroup cg(configfile, group);
00080 QString p=path ? cg.readPathEntry(entry, QString()) : cg.readEntry(entry,QString());
00081 if(!p.isNull())
00082 return p;
00083 }
00084
00085 if(eventsfile->hasGroup( group ) )
00086 {
00087 KConfigGroup cg( eventsfile, group);
00088 QString p=path ? cg.readPathEntry(entry, QString()) : cg.readEntry(entry, QString());
00089 if(!p.isNull())
00090 return p;
00091 }
00092
00093
00094 return QString();
00095 }
00096