File indexing completed on 2024-06-23 05:31:11

0001 /*
0002     SPDX-FileCopyrightText: 2022 Tanbir Jishan <tantalising007@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include <KPluginFactory>
0008 #include <QDBusConnection>
0009 
0010 #include "../../kcms-common_p.h"
0011 #include "accentColorService.h"
0012 #include "accentcolor_service_adaptor.h"
0013 #include "colorsapplicator.h"
0014 
0015 K_PLUGIN_CLASS_WITH_JSON(AccentColorService, "accentColorService.json")
0016 
0017 AccentColorService::AccentColorService(QObject *parent, const QList<QVariant> &)
0018     : KDEDModule(parent)
0019     , m_settings(new ColorsSettings(this))
0020 {
0021     new AccentColorServiceAdaptor(this);
0022     QDBusConnection dbus = QDBusConnection::sessionBus();
0023     dbus.registerObject("/AccentColor", this);
0024     dbus.registerService("org.kde.plasmashell.accentColor");
0025 }
0026 
0027 void AccentColorService::setAccentColor(unsigned accentColor)
0028 {
0029     const QColor color = QColor::fromRgba(accentColor);
0030     if (!color.isValid()) {
0031         return;
0032     }
0033 
0034     m_settings->load();
0035     if (m_settings->accentColorFromWallpaper()) {
0036         const QString path =
0037             QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("color-schemes/%1.colors").arg(m_settings->colorScheme()));
0038 
0039         auto msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.KWin"),
0040                                                   QStringLiteral("/org/kde/KWin/BlendChanges"),
0041                                                   QStringLiteral("org.kde.KWin.BlendChanges"),
0042                                                   QStringLiteral("start"));
0043         msg << 300;
0044         // This is deliberately blocking so that we ensure Kwin has processed the
0045         // animation start event before we potentially trigger client side changes
0046         QDBusConnection::sessionBus().call(msg);
0047 
0048         m_settings->setAccentColor(color);
0049         applyScheme(path, m_settings->config(), KConfig::Notify, color);
0050         m_settings->save();
0051         notifyKcmChange(GlobalChangeType::PaletteChanged);
0052     }
0053 }
0054 
0055 #include "accentColorService.moc"