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.cpp, code copied from there is copyrighted to its 0004 respective owners. 0005 0006 SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 // Own 0010 #include "policies.h" 0011 0012 // KDE 0013 #include <kconfiggroup.h> 0014 0015 // == class Policies == 0016 0017 Policies::Policies(KSharedConfig::Ptr config, const QString &group, 0018 bool global, const QString &domain, const QString &prefix, 0019 const QString &feature_key) : 0020 is_global(global), config(config), groupname(group), 0021 prefix(prefix), feature_key(feature_key) 0022 { 0023 0024 if (is_global) { 0025 this->prefix.clear(); // global keys have no prefix 0026 }/*end if*/ 0027 setDomain(domain); 0028 } 0029 0030 Policies::~Policies() 0031 { 0032 } 0033 0034 void Policies::setDomain(const QString &domain) 0035 { 0036 if (is_global) { 0037 return; 0038 } 0039 this->domain = domain.toLower(); 0040 groupname = this->domain; // group is domain in this case 0041 } 0042 0043 void Policies::load() 0044 { 0045 KConfigGroup cg(config, groupname); 0046 0047 QString key = prefix + feature_key; 0048 if (cg.hasKey(key)) { 0049 feature_enabled = cg.readEntry(key, false); 0050 } else { 0051 feature_enabled = is_global ? true : INHERIT_POLICY; 0052 } 0053 } 0054 0055 void Policies::defaults() 0056 { 0057 feature_enabled = is_global ? true : INHERIT_POLICY; 0058 } 0059 0060 void Policies::save() 0061 { 0062 KConfigGroup cg(config, groupname); 0063 0064 QString key = prefix + feature_key; 0065 if (feature_enabled != INHERIT_POLICY) { 0066 cg.writeEntry(key, (bool)feature_enabled); 0067 } else { 0068 cg.deleteEntry(key); 0069 } 0070 0071 // don't do a config->sync() here for sake of efficiency 0072 }