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     auto general = spectaclerc->group(QStringLiteral("General"));
0017     KeyMap generalOldNewMap{
0018         // Using a name that doesn't look like a signal handler.
0019         {"onLaunchAction", "launchAction"},
0020         // printKeyActionRunning looks like a bool
0021         {"printKeyActionRunning", "printKeyRunningAction"},
0022         // shorten name and make it consistent with selectionRect
0023         {"rememberLastRectangularRegion", "rememberSelectionRect"},
0024     };
0025     replaceEntryKeys(general, generalOldNewMap);
0026     // Fix spelling
0027     replaceEntryValues(general, "launchAction",
0028                        {{u"UseLastUsedCapturemode"_s, u"UseLastUsedCaptureMode"_s}});
0029     // Shorten enum values
0030     replaceEntryValues(general, "rememberSelectionRect",
0031                        {{u"UntilSpectacleIsClosed"_s, u"UntilClosed"_s}});
0032 
0033     auto guiConfig = spectaclerc->group(QStringLiteral("GuiConfig"));
0034     KeyMap guiConfigOldNewMap{
0035         // More in line with naming elsewhere.
0036         {"cropRegion", "selectionRect"},
0037         // Using a name that doesn't look like a signal handler.
0038         {"onClickChecked", "captureOnClick"},
0039         // Using a consistent spelling for color in code.
0040         {"useLightMaskColour", "useLightMaskColor"},
0041     };
0042     replaceEntryKeys(guiConfig, guiConfigOldNewMap);
0043 
0044     auto imageSave = spectaclerc->group(QStringLiteral("ImageSave"));
0045     replaceEntryKeys(imageSave, {{"imageFilenameFormat", "imageFilenameTemplate"}});
0046 
0047     auto videoSave = spectaclerc->group(QStringLiteral("VideoSave"));
0048     replaceEntryKeys(videoSave, {{"videoFilenameFormat", "videoFilenameTemplate"}});
0049 
0050     return spectaclerc->sync() ? 0 : 1;
0051 }