Warning, file /plasma/oxygen/kdecoration/oxygenexceptionlist.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 //////////////////////////////////////////////////////////////////////////////
0002 // oxygenexceptionlist.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 "oxygenexceptionlist.h"
0012 
0013 namespace Oxygen
0014 {
0015 
0016 //______________________________________________________________
0017 void ExceptionList::readConfig(KSharedConfig::Ptr config)
0018 {
0019     _exceptions.clear();
0020 
0021     QString groupName;
0022     for (int index = 0; config->hasGroup(groupName = exceptionGroupName(index)); ++index) {
0023         // create exception
0024         InternalSettings exception;
0025 
0026         // reset group
0027         readConfig(&exception, config.data(), groupName);
0028 
0029         // create new configuration
0030         InternalSettingsPtr configuration(new InternalSettings());
0031         configuration.data()->load();
0032 
0033         // apply changes from exception
0034         configuration->setEnabled(exception.enabled());
0035         configuration->setExceptionType(exception.exceptionType());
0036         configuration->setExceptionPattern(exception.exceptionPattern());
0037         configuration->setMask(exception.mask());
0038 
0039         // propagate all features found in mask to the output configuration
0040         if (exception.mask() & BorderSize)
0041             configuration->setBorderSize(exception.borderSize());
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 QStringLiteral("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     static const QStringList keys = {QStringLiteral("Enabled"),
0077                                      QStringLiteral("ExceptionPattern"),
0078                                      QStringLiteral("ExceptionType"),
0079                                      QStringLiteral("HideTitleBar"),
0080                                      QStringLiteral("Mask"),
0081                                      QStringLiteral("BorderSize")};
0082 
0083     // write all items
0084     for (const auto &key : keys) {
0085         KConfigSkeletonItem *item(skeleton->findItem(key));
0086         if (!item)
0087             continue;
0088 
0089         if (!groupName.isEmpty())
0090             item->setGroup(groupName);
0091         KConfigGroup configGroup(config, item->group());
0092         configGroup.writeEntry(item->key(), item->property());
0093     }
0094 }
0095 
0096 //______________________________________________________________
0097 void ExceptionList::readConfig(KCoreConfigSkeleton *skeleton, KConfig *config, const QString &groupName)
0098 {
0099     const auto skelItems = skeleton->items();
0100     for (KConfigSkeletonItem *item : skelItems) {
0101         if (!groupName.isEmpty())
0102             item->setGroup(groupName);
0103         item->readConfig(config);
0104     }
0105 }
0106 }