Warning, file /plasma/plasma-workspace/kcms/nightcolor/kcm.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: 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 <QIcon>
0010 #include <QStandardPaths>
0011 #include <QDBusConnection>
0012 #include <QDBusMessage>
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, const QVariantList &args)
0024     : KQuickAddons::ManagedConfigModule(parent, data, args)
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     worldMapFile = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("plasma/nightcolor/worldmap.png"), QStandardPaths::LocateFile);
0031 
0032     minDayTemp = nightColorSettings()->findItem("DayTemperature")->minValue().toInt();
0033     maxDayTemp = nightColorSettings()->findItem("DayTemperature")->maxValue().toInt();
0034     minNightTemp = nightColorSettings()->findItem("NightTemperature")->minValue().toInt();
0035     maxNightTemp = nightColorSettings()->findItem("NightTemperature")->maxValue().toInt();
0036 
0037     setButtons(Apply | Default);
0038 }
0039 
0040 NightColorSettings *KCMNightColor::nightColorSettings() const
0041 {
0042     return m_data->settings();
0043 }
0044 
0045 // FIXME: This was added to work around the nonstandardness of the Breeze zoom icons
0046 // remove once https://bugs.kde.org/show_bug.cgi?id=435671 is fixed
0047 bool KCMNightColor::isIconThemeBreeze()
0048 {
0049     return QIcon::themeName().contains(QStringLiteral("breeze"));
0050 }
0051 
0052 void KCMNightColor::save()
0053 {
0054     KQuickAddons::ManagedConfigModule::save();
0055 
0056     // load/unload colorcorrectlocationupdater based on whether user set it to automatic location
0057     QDBusConnection dbus = QDBusConnection::sessionBus();
0058 
0059     bool enableUpdater = (nightColorSettings()->mode() == NightColorMode::Automatic);
0060 
0061     QDBusMessage loadMsg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.kded5"),
0062                                                           QStringLiteral("/kded"),
0063                                                           QStringLiteral("org.kde.kded5"),
0064                                                           (enableUpdater ? QStringLiteral("loadModule") : QStringLiteral("unloadModule")));
0065     loadMsg.setArguments({QVariant(QStringLiteral("colorcorrectlocationupdater"))});
0066     dbus.call(loadMsg, QDBus::NoBlock);
0067 }
0068 }
0069 #include "kcm.moc"