File indexing completed on 2024-05-12 17:09:53
0001 /* 0002 SPDX-FileCopyrightText: 2020 Alexander Lohnau <alexander.lohnau@gmx.de> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include <QCoreApplication> 0008 #include <QTimer> 0009 0010 #include <KActivities/Consumer> 0011 #include <KConfigGroup> 0012 #include <KSharedConfig> 0013 0014 int main(int argc, char **argv) 0015 { 0016 QCoreApplication app(argc, argv); 0017 0018 // Migrate data to state data file 0019 KSharedConfigPtr krunnerrc = KSharedConfig::openConfig("krunnerrc"); 0020 KConfigGroup stateData = krunnerrc->group("PlasmaRunnerManager"); 0021 KSharedConfigPtr newStateLocation = KSharedConfig::openConfig("krunnerstaterc", KConfig::NoGlobals, QStandardPaths::GenericDataLocation); 0022 stateData.reparent(newStateLocation.data()); 0023 stateData.sync(); 0024 0025 // Migrate history to activity aware config 0026 auto consumer = new KActivities::Consumer(); 0027 // Wait a bit for consumer to be initialized 0028 QObject::connect(consumer, &KActivities::Consumer::serviceStatusChanged, consumer, [consumer, newStateLocation, krunnerrc]() { 0029 const QString history = krunnerrc->group("General").readEntry("history"); 0030 QStringList activities = consumer->activities(); 0031 if (activities.isEmpty()) { 0032 activities.append(QStringLiteral("00000000-0000-0000-0000-000000000000")); 0033 } 0034 KConfigGroup newHistory = newStateLocation->group("PlasmaRunnerManager").group("History"); 0035 for (const QString &activity : qAsConst(activities)) { 0036 newHistory.writeEntry(activity, history); 0037 } 0038 newHistory.sync(); 0039 // Delete old values 0040 krunnerrc->group("General").deleteEntry("history"); 0041 krunnerrc->deleteGroup("PlasmaRunnerManager"); 0042 krunnerrc->group("PlasmaRunnerManager").writeEntry("migrated", true); 0043 krunnerrc->sync(); 0044 qApp->exit(); 0045 }); 0046 0047 return QCoreApplication::exec(); 0048 }