File indexing completed on 2024-05-12 05:38:23

0001 /*
0002     SPDX-FileCopyrightText: 2023 Fushan Wen <qydwhotmail@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include <cstdlib>
0008 #include <iostream>
0009 
0010 #include <KConfigGroup>
0011 #include <KSharedConfig>
0012 
0013 using namespace Qt::StringLiterals;
0014 
0015 /**
0016  * For Plasma 5 users, keep the existing panel floating settings.
0017  *
0018  * @see https://invent.kde.org/plasma/plasma-desktop/-/issues/73
0019  * @since 6.0
0020  */
0021 int main()
0022 {
0023     const KSharedConfigPtr configPtr = KSharedConfig::openConfig(QStringLiteral("plasmashellrc"), KConfig::FullConfig);
0024     KConfigGroup views(configPtr, QStringLiteral("PlasmaViews"));
0025     if (!views.exists() || views.groupList().empty()) {
0026         std::cout << "plasmashellrc doesn't have any PlasmaViews. No need to update config." << std::endl;
0027         return EXIT_SUCCESS;
0028     }
0029 
0030     // Update default floating setting in config groups like [PlasmaViews][Panel 114][Defaults]
0031     const QStringList groupList = views.groupList();
0032     for (const QString &name : groupList) {
0033         if (!name.startsWith(QLatin1String("Panel "))) {
0034             continue;
0035         }
0036 
0037         KConfigGroup panelConfigGroup(&views, name);
0038         if (!panelConfigGroup.hasGroup(u"Defaults"_s)) {
0039             continue;
0040         }
0041 
0042         KConfigGroup defaultConfigGroup(&panelConfigGroup, u"Defaults"_s);
0043         if (defaultConfigGroup.hasKey("floating")) {
0044             // Respect the manual setting
0045             continue;
0046         }
0047 
0048         // Explicitly set the old default floating setting for panels from Plasma 5
0049         defaultConfigGroup.writeEntry("floating", 0);
0050     }
0051 
0052     return configPtr->sync() ? EXIT_SUCCESS : EXIT_FAILURE;
0053 }