File indexing completed on 2024-11-10 04:56:26

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 <KConfig>
0013 #include <KConfigGroup>
0014 #include <QCoreApplication>
0015 #include <QDBusConnection>
0016 #include <QDBusMessage>
0017 #include <QDebug>
0018 #include <QStandardPaths>
0019 
0020 int main(int argc, char *argv[])
0021 {
0022     if (argc != 2) {
0023         return 1;
0024     }
0025 
0026     QCoreApplication::setApplicationName("kwin_update_default_rules");
0027 
0028     QString file = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QString("kwin/default_rules/%1").arg(argv[1]));
0029     if (file.isEmpty()) {
0030         qWarning() << "File " << argv[1] << " not found!";
0031         return 1;
0032     }
0033     KConfig src_cfg(file);
0034     KConfig dest_cfg(QStringLiteral("kwinrulesrc"), KConfig::NoGlobals);
0035     KConfigGroup scg(&src_cfg, QStringLiteral("General"));
0036     KConfigGroup dcg(&dest_cfg, QStringLiteral("General"));
0037     int count = scg.readEntry("count", 0);
0038     int pos = dcg.readEntry("count", 0);
0039     for (int group = 1;
0040          group <= count;
0041          ++group) {
0042         QMap<QString, QString> entries = src_cfg.entryMap(QString::number(group));
0043         ++pos;
0044         dest_cfg.deleteGroup(QString::number(pos));
0045         KConfigGroup dcg2(&dest_cfg, QString::number(pos));
0046         for (QMap<QString, QString>::ConstIterator it = entries.constBegin();
0047              it != entries.constEnd();
0048              ++it) {
0049             dcg2.writeEntry(it.key(), *it);
0050         }
0051     }
0052     dcg.writeEntry("count", pos);
0053     scg.sync();
0054     dcg.sync();
0055     // Send signal to all kwin instances
0056     QDBusMessage message =
0057         QDBusMessage::createSignal("/KWin", "org.kde.KWin", "reloadConfig");
0058     QDBusConnection::sessionBus().send(message);
0059 }