File indexing completed on 2024-05-19 05:38:22
0001 /* 0002 SPDX-FileCopyrightText: 2017 Roman Gilg <subdiff@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "kcm.h" 0008 0009 #include <QDBusConnection> 0010 #include <QDBusMessage> 0011 #include <QIcon> 0012 #include <QStandardPaths> 0013 0014 #include <KLocalizedString> 0015 #include <KPluginFactory> 0016 0017 #include "nightcolordata.h" 0018 0019 namespace ColorCorrect 0020 { 0021 K_PLUGIN_FACTORY_WITH_JSON(KCMNightColorFactory, "kcm_nightcolor.json", registerPlugin<KCMNightColor>(); registerPlugin<NightColorData>();) 0022 0023 KCMNightColor::KCMNightColor(QObject *parent, const KPluginMetaData &data) 0024 : KQuickManagedConfigModule(parent, data) 0025 , m_data(new NightColorData(this)) 0026 { 0027 qmlRegisterAnonymousType<NightColorSettings>("org.kde.private.kcms.nightcolor", 1); 0028 qmlRegisterUncreatableMetaObject(ColorCorrect::staticMetaObject, "org.kde.private.kcms.nightcolor", 1, 0, "NightColorMode", "Error: only enums"); 0029 0030 minDayTemp = nightColorSettings()->findItem("DayTemperature")->minValue().toInt(); 0031 maxDayTemp = nightColorSettings()->findItem("DayTemperature")->maxValue().toInt(); 0032 minNightTemp = nightColorSettings()->findItem("NightTemperature")->minValue().toInt(); 0033 maxNightTemp = nightColorSettings()->findItem("NightTemperature")->maxValue().toInt(); 0034 0035 setButtons(Apply | Default); 0036 } 0037 0038 NightColorSettings *KCMNightColor::nightColorSettings() const 0039 { 0040 return m_data->settings(); 0041 } 0042 0043 // FIXME: This was added to work around the nonstandardness of the Breeze zoom icons 0044 // remove once https://bugs.kde.org/show_bug.cgi?id=435671 is fixed 0045 bool KCMNightColor::isIconThemeBreeze() 0046 { 0047 return QIcon::themeName().contains(QStringLiteral("breeze")); 0048 } 0049 0050 void KCMNightColor::save() 0051 { 0052 KQuickManagedConfigModule::save(); 0053 0054 // load/unload colorcorrectlocationupdater based on whether user set it to automatic location 0055 QDBusConnection dbus = QDBusConnection::sessionBus(); 0056 0057 bool enableUpdater = (nightColorSettings()->mode() == NightColorMode::Automatic); 0058 0059 QDBusMessage loadMsg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.kded6"), 0060 QStringLiteral("/kded"), 0061 QStringLiteral("org.kde.kded6"), 0062 (enableUpdater ? QStringLiteral("loadModule") : QStringLiteral("unloadModule"))); 0063 loadMsg.setArguments({QVariant(QStringLiteral("colorcorrectlocationupdater"))}); 0064 dbus.call(loadMsg, QDBus::NoBlock); 0065 } 0066 } 0067 #include "kcm.moc"