summaryrefslogtreecommitdiffstats
path: root/kcontrol/konqhtml/policies.h
blob: a9814396aa58231766f7cc8ce121f0cfeb1c12ae (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
  Copyright (c) 2002 Leo Savernik <l.savernik@aon.at>
  Derived from jsopt.h, 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.

*/

#ifndef __POLICIES_H__
#define __POLICIES_H__

#include <tqstring.h>

class KConfig;

// special value for inheriting a global policy
#define INHERIT_POLICY		32767

/**
 * @short Contains the basic policies and methods for their manipulation.
 *
 * This class provides access to the basic policies that are common
 * to all features.
 *
 * @author Leo Savernik
 */
class Policies {
public:
  /**
   * constructor
   * @param config configuration to initialize this instance from
   * @param group config group to use if this instance contains the global
   *	policies (global == true)
   * @param global true if this instance contains the global policy settings,
   *	false if it contains policies specific to a domain.
   * @param domain name of the domain this instance is used to configure the
   *	policies for (case insensitive, ignored if global == true)
   * @param prefix prefix to use for configuration keys. The domain-specific
   *	policies use of the format "&lt;feature&gt;." (note the trailing dot).
   *	Global policies have no prefix, it is ignored if global == true.
   * @param feature_key key of the "feature enabled" policy. The final
   *	key the policy is stored under will be prefix + featureKey.
   */
  Policies(KConfig* config, const TQString &group, bool global,
  		const TQString &domain, const TQString &prefix,
		const TQString &feature_key);

  virtual ~Policies();

  /**
   * Returns true if this is the global policies object
   */
  bool isGlobal() const {
    return is_global;
  }

  /** sets a new domain for this policy
   * @param domain domain name, will be converted to lowercase
   */
  void setDomain(const TQString &domain);

  /**
   * Returns whether the "feature enabled" policy is inherited.
   */
  bool isFeatureEnabledPolicyInherited() const {
    return feature_enabled == INHERIT_POLICY;
  }
  /** inherits "feature enabled" policy */
  void inheritFeatureEnabledPolicy() {
    feature_enabled = INHERIT_POLICY;
  }
  /**
   * Returns whether this feature is enabled.
   *
   * This will return an illegal value if isFeatureEnabledPolicyInherited
   * is true.
   */
  bool isFeatureEnabled() const {
    return (bool)feature_enabled;
  }
  /**
   * Enables/disables this feature
   * @param on true will enable it, false disable it
   */
  void setFeatureEnabled(int on) {
    feature_enabled = on;
  }

  /**
   * (re)loads settings from configuration file given in the constructor.
   *
   * Implicitely sets the group given in the constructor. Don't forget to
   * call this method from derived methods.
   */
  virtual void load();
  /**
   * saves current settings to the configuration file given in the constructor
   *
   * Implicitely sets the group given in the constructor. Don't forget to
   * call this method from derived methods.
   */
  virtual void save();
  /**
   * restores the default settings
   */
  virtual void defaults();

protected:
  // true or false or INHERIT_POLICY
  unsigned int feature_enabled;

  bool is_global;
  KConfig *config;
  TQString groupname;
  TQString domain;
  TQString prefix;
  TQString feature_key;
};

#endif		// __POLICIES_H__