File indexing completed on 2024-05-19 04:36:07

0001 /* SPDX-FileCopyrightText: 2023 Noah Davis <noahadvs@gmail.com>
0002  * SPDX-License-Identifier: LGPL-2.0-or-later
0003  */
0004 
0005 #include "ConfigUtils.h"
0006 #include <KConfigGroup>
0007 #include <KSharedConfig>
0008 
0009 using namespace Qt::StringLiterals;
0010 
0011 int main()
0012 {
0013     // We only need to read spectaclerc, so we use SimpleConfig.
0014     auto spectaclerc = KSharedConfig::openConfig("spectaclerc"_L1, KConfig::SimpleConfig);
0015 
0016     // Remove old settings.
0017     spectaclerc->group(QStringLiteral("GuiConfig")).deleteEntry("videoFormat");
0018     auto saveGroup = spectaclerc->group(QStringLiteral("Save"));
0019     // These couldn't be changed via the GUI, but removing them anyway just in case
0020     saveGroup.deleteEntry("defaultVideoSaveLocation");
0021     saveGroup.deleteEntry("defaultSaveVideoFormat");
0022     saveGroup.deleteEntry("saveVideoFormat");
0023 
0024     // Copy to new groups and remove old groups
0025     auto imageSaveGroup = spectaclerc->group(QStringLiteral("ImageSave"));
0026     saveGroup.copyTo(&imageSaveGroup);
0027     saveGroup.deleteGroup();
0028 
0029     // Rename settings
0030     KeyMap oldNewMap{
0031         {"defaultSaveLocation", "imageSaveLocation"},
0032         {"compressionQuality", "imageCompressionQuality"},
0033         {"defaultSaveImageFormat", "preferredImageFormat"},
0034         {"saveFilenameFormat", "imageFilenameFormat"},
0035         {"lastSaveLocation", "lastImageSaveLocation"},
0036         {"lastSaveAsLocation", "lastImageSaveAsLocation"},
0037     };
0038     replaceEntryKeys(imageSaveGroup, oldNewMap);
0039 
0040     return spectaclerc->sync() ? 0 : 1;
0041 }