File indexing completed on 2024-12-08 13:20:18

0001 /*
0002     KWin - the KDE window manager
0003     This file is part of the KDE project.
0004 
0005     SPDX-FileCopyrightText: 2005 Lubos Lunak <l.lunak@kde.org>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 // read additional window rules and add them to kwinrulesrc
0011 
0012 #include <QDebug>
0013 #include <QStandardPaths>
0014 #include <QtDBus>
0015 #include <kconfig.h>
0016 #include <kconfiggroup.h>
0017 
0018 int main(int argc, char *argv[])
0019 {
0020     if (argc != 2) {
0021         return 1;
0022     }
0023 
0024     QCoreApplication::setApplicationName("kwin_update_default_rules");
0025 
0026     QString file = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QString("kwin/default_rules/%1").arg(argv[1]));
0027     if (file.isEmpty()) {
0028         qWarning() << "File " << argv[1] << " not found!";
0029         return 1;
0030     }
0031     KConfig src_cfg(file);
0032     KConfig dest_cfg("kwinrulesrc", KConfig::NoGlobals);
0033     KConfigGroup scg(&src_cfg, "General");
0034     KConfigGroup dcg(&dest_cfg, "General");
0035     int count = scg.readEntry("count", 0);
0036     int pos = dcg.readEntry("count", 0);
0037     for (int group = 1;
0038          group <= count;
0039          ++group) {
0040         QMap<QString, QString> entries = src_cfg.entryMap(QString::number(group));
0041         ++pos;
0042         dest_cfg.deleteGroup(QString::number(pos));
0043         KConfigGroup dcg2(&dest_cfg, QString::number(pos));
0044         for (QMap<QString, QString>::ConstIterator it = entries.constBegin();
0045              it != entries.constEnd();
0046              ++it) {
0047             dcg2.writeEntry(it.key(), *it);
0048         }
0049     }
0050     dcg.writeEntry("count", pos);
0051     scg.sync();
0052     dcg.sync();
0053     // Send signal to all kwin instances
0054     QDBusMessage message =
0055         QDBusMessage::createSignal("/KWin", "org.kde.KWin", "reloadConfig");
0056     QDBusConnection::sessionBus().send(message);
0057 }