Warning, file /plasma/oxygen/kdecoration/oxygensettingsprovider.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 SPDX-FileCopyrightText: 2014 Hugo Pereira Da Costa <hugo.pereira@free.fr> 0003 SPDX-FileCopyrightText: 2015 David Edmundson <davidedmundson@kde.org> 0004 0005 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0006 */ 0007 0008 #include "oxygensettingsprovider.h" 0009 0010 #include "oxygendecohelper.h" 0011 #include "oxygenshadowcache.h" 0012 0013 #include "oxygenexceptionlist.h" 0014 0015 #include <KWindowInfo> 0016 0017 #include <QRegularExpression> 0018 #include <QTextStream> 0019 0020 namespace Oxygen 0021 { 0022 0023 SettingsProvider *SettingsProvider::s_self = nullptr; 0024 0025 //__________________________________________________________________ 0026 SettingsProvider::SettingsProvider() 0027 : m_config(KSharedConfig::openConfig(QStringLiteral("oxygenrc"))) 0028 , m_decoHelper(new DecoHelper()) 0029 , m_shadowCache(new ShadowCache(*m_decoHelper)) 0030 { 0031 reconfigure(); 0032 } 0033 0034 //__________________________________________________________________ 0035 SettingsProvider::~SettingsProvider() 0036 { 0037 s_self = nullptr; 0038 delete m_shadowCache; 0039 delete m_decoHelper; 0040 } 0041 0042 //__________________________________________________________________ 0043 SettingsProvider *SettingsProvider::self() 0044 { 0045 // TODO: this is not thread safe! 0046 if (!s_self) { 0047 s_self = new SettingsProvider(); 0048 } 0049 0050 return s_self; 0051 } 0052 0053 //__________________________________________________________________ 0054 void SettingsProvider::reconfigure(void) 0055 { 0056 if (!m_defaultSettings) { 0057 m_defaultSettings = InternalSettingsPtr(new InternalSettings()); 0058 m_defaultSettings->setCurrentGroup(QStringLiteral("Windeco")); 0059 } 0060 0061 m_decoHelper->invalidateCaches(); 0062 m_decoHelper->loadConfig(); 0063 0064 m_shadowCache->readConfig(); 0065 m_defaultSettings->load(); 0066 0067 ExceptionList exceptions; 0068 exceptions.readConfig(m_config); 0069 m_exceptions = exceptions.get(); 0070 } 0071 0072 //__________________________________________________________________ 0073 InternalSettingsPtr SettingsProvider::internalSettings(const Decoration *decoration) const 0074 { 0075 QString windowTitle; 0076 QString className; 0077 0078 // get the client 0079 const auto clientPtr = decoration->client().toStrongRef(); 0080 0081 for (auto internalSettings : std::as_const(m_exceptions)) { 0082 // discard disabled exceptions 0083 if (!internalSettings->enabled()) 0084 continue; 0085 0086 // discard exceptions with empty exception pattern 0087 if (internalSettings->exceptionPattern().isEmpty()) 0088 continue; 0089 0090 /* 0091 decide which value is to be compared 0092 to the regular expression, based on exception type 0093 */ 0094 QString value; 0095 switch (internalSettings->exceptionType()) { 0096 case InternalSettings::ExceptionWindowTitle: { 0097 value = windowTitle.isEmpty() ? (windowTitle = clientPtr->caption()) : windowTitle; 0098 break; 0099 } 0100 0101 default: 0102 case InternalSettings::ExceptionWindowClassName: { 0103 if (className.isEmpty()) { 0104 // retrieve class name 0105 KWindowInfo info(clientPtr->windowId(), {}, NET::WM2WindowClass); 0106 QString window_className(QString::fromUtf8(info.windowClassName())); 0107 QString window_class(QString::fromUtf8(info.windowClassClass())); 0108 className = window_className + QStringLiteral(" ") + window_class; 0109 } 0110 0111 value = className; 0112 break; 0113 } 0114 } 0115 0116 // check matching 0117 if (value.contains(QRegularExpression(internalSettings->exceptionPattern()))) { 0118 return internalSettings; 0119 } 0120 } 0121 0122 return m_defaultSettings; 0123 } 0124 }