File indexing completed on 2024-05-05 05:00:09
0001 /* 0002 SPDX-FileCopyrightText: 2002 Leo Savernik <l.savernik@aon.at> 0003 Derived from jsopt.h, code copied from there is copyrighted to its 0004 respective owners. 0005 0006 SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #ifndef __POLICIES_H__ 0010 #define __POLICIES_H__ 0011 0012 #include <ksharedconfig.h> 0013 0014 // special value for inheriting a global policy 0015 #define INHERIT_POLICY 32767 0016 0017 /** 0018 * @short Contains the basic policies and methods for their manipulation. 0019 * 0020 * This class provides access to the basic policies that are common 0021 * to all features. 0022 * 0023 * @author Leo Savernik 0024 */ 0025 class Policies 0026 { 0027 public: 0028 /** 0029 * constructor 0030 * @param config configuration to initialize this instance from 0031 * @param group config group to use if this instance contains the global 0032 * policies (global == true) 0033 * @param global true if this instance contains the global policy settings, 0034 * false if it contains policies specific to a domain. 0035 * @param domain name of the domain this instance is used to configure the 0036 * policies for (case insensitive, ignored if global == true) 0037 * @param prefix prefix to use for configuration keys. The domain-specific 0038 * policies use of the format "<feature>." (note the trailing dot). 0039 * Global policies have no prefix, it is ignored if global == true. 0040 * @param feature_key key of the "feature enabled" policy. The final 0041 * key the policy is stored under will be prefix + featureKey. 0042 */ 0043 Policies(KSharedConfig::Ptr config, const QString &group, bool global, 0044 const QString &domain, const QString &prefix, 0045 const QString &feature_key); 0046 0047 virtual ~Policies(); 0048 0049 /** 0050 * Returns true if this is the global policies object 0051 */ 0052 bool isGlobal() const 0053 { 0054 return is_global; 0055 } 0056 0057 /** sets a new domain for this policy 0058 * @param domain domain name, will be converted to lowercase 0059 */ 0060 void setDomain(const QString &domain); 0061 0062 /** 0063 * Returns whether the "feature enabled" policy is inherited. 0064 */ 0065 bool isFeatureEnabledPolicyInherited() const 0066 { 0067 return feature_enabled == INHERIT_POLICY; 0068 } 0069 /** inherits "feature enabled" policy */ 0070 void inheritFeatureEnabledPolicy() 0071 { 0072 feature_enabled = INHERIT_POLICY; 0073 } 0074 /** 0075 * Returns whether this feature is enabled. 0076 * 0077 * This will return an illegal value if isFeatureEnabledPolicyInherited 0078 * is true. 0079 */ 0080 bool isFeatureEnabled() const 0081 { 0082 return (bool)feature_enabled; 0083 } 0084 /** 0085 * Enables/disables this feature 0086 * @param on true will enable it, false disable it 0087 */ 0088 void setFeatureEnabled(int on) 0089 { 0090 feature_enabled = on; 0091 } 0092 0093 /** 0094 * (re)loads settings from configuration file given in the constructor. 0095 * 0096 * Implicitly sets the group given in the constructor. Don't forget to 0097 * call this method from derived methods. 0098 */ 0099 virtual void load(); 0100 /** 0101 * saves current settings to the configuration file given in the constructor 0102 * 0103 * Implicitly sets the group given in the constructor. Don't forget to 0104 * call this method from derived methods. 0105 */ 0106 virtual void save(); 0107 /** 0108 * restores the default settings 0109 */ 0110 virtual void defaults(); 0111 0112 protected: 0113 // true or false or INHERIT_POLICY 0114 unsigned int feature_enabled; 0115 0116 bool is_global; 0117 KSharedConfig::Ptr config; 0118 QString groupname; 0119 QString domain; 0120 QString prefix; 0121 QString feature_key; 0122 }; 0123 0124 #endif // __POLICIES_H__ 0125