2 Copyright (c) 2002 Leo Savernik <l.savernik@aon.at>
3 Derived from jsopt.cpp, code copied from there is copyrighted to its
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 #include <ksharedconfig.h>
27 #include <kconfiggroup.h>
31 // == class Policies ==
33 Policies::Policies(KSharedConfig::Ptr config
,const QString
&group
,
34 bool global
,const QString
&domain
, const QString
&prefix
,
35 const QString
&feature_key
) :
36 is_global(global
), config(config
), groupname(group
),
37 prefix(prefix
), feature_key(feature_key
) {
40 this->prefix
.clear(); // global keys have no prefix
45 Policies::~Policies() {
48 void Policies::setDomain(const QString
&domain
) {
49 if (is_global
) return;
50 this->domain
= domain
.toLower();
51 groupname
= this->domain
; // group is domain in this case
54 void Policies::load() {
55 KConfigGroup
cg(config
, groupname
);
57 QString key
= prefix
+ feature_key
;
59 feature_enabled
= cg
.readEntry(key
, false);
61 feature_enabled
= is_global
? true : INHERIT_POLICY
;
64 void Policies::defaults() {
65 feature_enabled
= is_global
? true : INHERIT_POLICY
;
68 void Policies::save() {
69 KConfigGroup
cg(config
, groupname
);
71 QString key
= prefix
+ feature_key
;
72 if (feature_enabled
!= INHERIT_POLICY
)
73 cg
.writeEntry(key
, (bool)feature_enabled
);
77 // don't do a config->sync() here for sake of efficiency