File indexing completed on 2024-05-05 05:28:59

0001 //////////////////////////////////////////////////////////////////////////////
0002 // breezeexceptionlist.cpp
0003 // window decoration exceptions
0004 // -------------------
0005 //
0006 // SPDX-FileCopyrightText: 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
0007 //
0008 // SPDX-License-Identifier: MIT
0009 //////////////////////////////////////////////////////////////////////////////
0010 
0011 #include "breezeexceptionlist.h"
0012 
0013 namespace Breeze
0014 {
0015 //______________________________________________________________
0016 void ExceptionList::readConfig(KSharedConfig::Ptr config)
0017 {
0018     _exceptions.clear();
0019 
0020     QString groupName;
0021     for (int index = 0; config->hasGroup(groupName = exceptionGroupName(index)); ++index) {
0022         // create exception
0023         InternalSettings exception;
0024 
0025         // reset group
0026         readConfig(&exception, config.data(), groupName);
0027 
0028         // create new configuration
0029         InternalSettingsPtr configuration(new InternalSettings());
0030         configuration.data()->load();
0031 
0032         // apply changes from exception
0033         configuration->setEnabled(exception.enabled());
0034         configuration->setExceptionType(exception.exceptionType());
0035         configuration->setExceptionPattern(exception.exceptionPattern());
0036         configuration->setMask(exception.mask());
0037 
0038         // propagate all features found in mask to the output configuration
0039         if (exception.mask() & BorderSize) {
0040             configuration->setBorderSize(exception.borderSize());
0041         }
0042         configuration->setHideTitleBar(exception.hideTitleBar());
0043 
0044         // append to exceptions
0045         _exceptions.append(configuration);
0046     }
0047 }
0048 
0049 //______________________________________________________________
0050 void ExceptionList::writeConfig(KSharedConfig::Ptr config)
0051 {
0052     // remove all existing exceptions
0053     QString groupName;
0054     for (int index = 0; config->hasGroup(groupName = exceptionGroupName(index)); ++index) {
0055         config->deleteGroup(groupName);
0056     }
0057 
0058     // rewrite current exceptions
0059     int index = 0;
0060     for (const InternalSettingsPtr &exception : std::as_const(_exceptions)) {
0061         writeConfig(exception.data(), config.data(), exceptionGroupName(index));
0062         ++index;
0063     }
0064 }
0065 
0066 //_______________________________________________________________________
0067 QString ExceptionList::exceptionGroupName(int index)
0068 {
0069     return QString("Windeco Exception %1").arg(index);
0070 }
0071 
0072 //______________________________________________________________
0073 void ExceptionList::writeConfig(KCoreConfigSkeleton *skeleton, KConfig *config, const QString &groupName)
0074 {
0075     // list of items to be written
0076     const QStringList keys = {"Enabled", "ExceptionPattern", "ExceptionType", "HideTitleBar", "Mask", "BorderSize"};
0077 
0078     // write all items
0079     for (auto key : keys) {
0080         KConfigSkeletonItem *item(skeleton->findItem(key));
0081         if (!item) {
0082             continue;
0083         }
0084 
0085         if (!groupName.isEmpty()) {
0086             item->setGroup(groupName);
0087         }
0088         KConfigGroup configGroup(config, item->group());
0089         configGroup.writeEntry(item->key(), item->property());
0090     }
0091 }
0092 
0093 //______________________________________________________________
0094 void ExceptionList::readConfig(KCoreConfigSkeleton *skeleton, KConfig *config, const QString &groupName)
0095 {
0096     const auto items = skeleton->items();
0097     for (KConfigSkeletonItem *item : items) {
0098         if (!groupName.isEmpty()) {
0099             item->setGroup(groupName);
0100         }
0101         item->readConfig(config);
0102     }
0103 }
0104 
0105 }