• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

KNotify

knotifyconfig.cpp

Go to the documentation of this file.
00001 /*
00002    Copyright (C) 2005-2006 by Olivier Goffart <ogoffart at kde.org>
00003 
00004 
00005    This program is free software; you can redistribute it and/or modify
00006    it under the terms of the GNU General Public License as published by
00007    the Free Software Foundation; either version 2, or (at your option)
00008    any later version.
00009 
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013    GNU General Public License for more details.
00014 
00015    You should have received a copy of the GNU General Public License
00016    along with this program; if not, write to the Free Software
00017    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
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 //  kDebug(300) << appname << " , " << eventid;
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 //  kDebug(300) << entry << " not found in contexts ";
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 //  kDebug(300) << entry << " not found in config ";
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 //  kDebug(300) << entry << " not found !!! ";
00093 
00094     return QString();
00095 }
00096 

KNotify

Skip menu "KNotify"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • KCMShell
  • KNotify
  • KStyles
  • Nepomuk Daemons
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal