2 Copyright (C) 2005-2006 by Olivier Goffart <ogoffart at kde.org>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "knotifyconfig.h"
23 #include <ksharedconfig.h>
24 #include <kconfiggroup.h>
29 typedef QCache
<QString
, KSharedConfig::Ptr
> ConfigCache
;
30 K_GLOBAL_STATIC_WITH_ARGS(ConfigCache
, static_cache
, (15))
32 static KSharedConfig::Ptr
retrieve_from_cache(const QString
& filename
, const char *resourceType
="config")
34 QCache
<QString
, KSharedConfig::Ptr
> &cache
= *static_cache
;
35 if (cache
.contains(filename
))
36 return *cache
[filename
];
37 KSharedConfig::Ptr m
= KSharedConfig::openConfig (filename
, KConfig::NoGlobals
, resourceType
);
38 cache
.insert(filename
, new KSharedConfig::Ptr(m
));
42 void KNotifyConfig::clearCache()
44 static_cache
->clear();
48 KNotifyConfig::KNotifyConfig( const QString
& _appname
, const ContextList
& _contexts
, const QString
& _eventid
)
50 eventsfile(retrieve_from_cache(_appname
+'/'+_appname
+ ".notifyrc" , "data" )),
51 configfile(retrieve_from_cache(_appname
+QString::fromAscii( ".notifyrc" ))),
52 contexts(_contexts
) , eventid(_eventid
)
54 // kDebug(300) << appname << " , " << eventid;
57 KNotifyConfig::~KNotifyConfig()
61 QString
KNotifyConfig::readEntry( const QString
& entry
, bool path
)
63 QPair
<QString
, QString
> context
;
64 foreach( context
, contexts
)
66 const QString group
="Event/" + eventid
+ '/' + context
.first
+ '/' + context
.second
;
67 if( configfile
->hasGroup( group
) )
69 KConfigGroup
cg(configfile
, group
);
70 QString p
=path
? cg
.readPathEntry(entry
, QString()) : cg
.readEntry(entry
,QString());
75 // kDebug(300) << entry << " not found in contexts ";
76 const QString group
="Event/" + eventid
;
77 if(configfile
->hasGroup( group
) )
79 KConfigGroup
cg(configfile
, group
);
80 QString p
=path
? cg
.readPathEntry(entry
, QString()) : cg
.readEntry(entry
,QString());
84 // kDebug(300) << entry << " not found in config ";
85 if(eventsfile
->hasGroup( group
) )
87 KConfigGroup
cg( eventsfile
, group
);
88 QString p
=path
? cg
.readPathEntry(entry
, QString()) : cg
.readEntry(entry
, QString());
92 // kDebug(300) << entry << " not found !!! ";