Fix crash if key bindings specified in profile cannot be found. Improve
[personal-kdebase.git] / apps / konqueror / settings / konqhtml / policies.cpp
blob085a6250c55c356331ec3ca963c0c80530e69d59
1 /*
2 Copyright (c) 2002 Leo Savernik <l.savernik@aon.at>
3 Derived from jsopt.cpp, code copied from there is copyrighted to its
4 respective owners.
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.
22 // Own
23 #include "policies.h"
25 // KDE
26 #include <ksharedconfig.h>
27 #include <kconfiggroup.h>
28 #include <kdebug.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) {
39 if (is_global) {
40 this->prefix.clear(); // global keys have no prefix
41 }/*end if*/
42 setDomain(domain);
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;
58 if (cg.hasKey(key))
59 feature_enabled = cg.readEntry(key, false);
60 else
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);
74 else
75 cg.deleteEntry(key);
77 // don't do a config->sync() here for sake of efficiency