summaryrefslogtreecommitdiffstats
path: root/kcontrol/konqhtml/policies.cpp
blob: 153c80888f21b4fdd1808065c3f348f15475776f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
  Copyright (c) 2002 Leo Savernik <l.savernik@aon.at>
  Derived from jsopt.cpp, code copied from there is copyrighted to its
  respective owners.

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

*/

#include <kconfig.h>
#include <kdebug.h>

#include "policies.h"

// == class Policies ==

Policies::Policies(KConfig* config,const QString &group,
		bool global,const QString &domain, const QString &prefix,
		const QString &feature_key) :
	is_global(global), config(config), groupname(group),
	prefix(prefix), feature_key(feature_key) {

  if (is_global) {
    this->prefix = QString::null;	// global keys have no prefix
  }/*end if*/
  setDomain(domain);
}

Policies::~Policies() {
}

void Policies::setDomain(const QString &domain) {
  if (is_global) return;
  this->domain = domain.lower();
  groupname = this->domain;	// group is domain in this case
}

void Policies::load() {
  config->setGroup(groupname);

  QString key = prefix + feature_key;
  if (config->hasKey(key))
    feature_enabled = config->readBoolEntry(key);
  else
    feature_enabled = is_global ? true : INHERIT_POLICY;
}

void Policies::defaults() {
  feature_enabled = is_global ? true : INHERIT_POLICY;
}

void Policies::save() {
  config->setGroup(groupname);

  QString key = prefix + feature_key;
  if (feature_enabled != INHERIT_POLICY)
    config->writeEntry(key, (bool)feature_enabled);
  else
    config->deleteEntry(key);

  // don't do a config->sync() here for sake of efficiency
}