@@ -17,6 +17,7 @@ namespace {
17
17
18
18
const QLatin1String falseString (" false" );
19
19
const QLatin1String trueString (" true" );
20
+ const QRegularExpression nameLocalizationRe (R"( ^Name(?:_(.*))?$)" );
20
21
21
22
void normalizeLineBreaks (QString &cmd)
22
23
{
@@ -32,51 +33,70 @@ void normalizeLineBreaks(QString &cmd)
32
33
void loadCommand (const QSettings &settings, Commands *commands)
33
34
{
34
35
Command c;
35
- c.enable = settings.value (QStringLiteral (" Enable" ), true ).toBool ();
36
-
37
- c.name = settings.value (QStringLiteral (" Name" )).toString ();
38
- c.re = QRegularExpression ( settings.value (QStringLiteral (" Match" )).toString () );
39
- c.wndre = QRegularExpression ( settings.value (QStringLiteral (" Window" )).toString () );
40
- c.matchCmd = settings.value (QStringLiteral (" MatchCommand" )).toString ();
41
- c.cmd = settings.value (QStringLiteral (" Command" )).toString ();
42
- c.sep = settings.value (QStringLiteral (" Separator" )).toString ();
43
-
44
- c.input = settings.value (QStringLiteral (" Input" )).toString ();
45
- if (c.input == falseString || c.input == trueString)
46
- c.input = c.input == trueString ? mimeText : QLatin1String ();
47
-
48
- c.output = settings.value (QStringLiteral (" Output" )).toString ();
49
- if (c.output == falseString || c.output == trueString)
50
- c.output = c.output == trueString ? mimeText : QLatin1String ();
51
-
52
- c.wait = settings.value (QStringLiteral (" Wait" )).toBool ();
53
- c.automatic = settings.value (QStringLiteral (" Automatic" )).toBool ();
54
- c.display = settings.value (QStringLiteral (" Display" )).toBool ();
55
- c.transform = settings.value (QStringLiteral (" Transform" )).toBool ();
56
- c.hideWindow = settings.value (QStringLiteral (" HideWindow" )).toBool ();
57
- c.icon = settings.value (QStringLiteral (" Icon" )).toString ();
58
- c.shortcuts = settings.value (QStringLiteral (" Shortcut" )).toStringList ();
59
- c.globalShortcuts = settings.value (QStringLiteral (" GlobalShortcut" )).toStringList ();
60
- c.tab = settings.value (QStringLiteral (" Tab" )).toString ();
61
- c.outputTab = settings.value (QStringLiteral (" OutputTab" )).toString ();
62
- c.internalId = settings.value (QStringLiteral (" InternalId" )).toString ();
63
- c.inMenu = settings.value (QStringLiteral (" InMenu" )).toBool ();
64
- c.isScript = settings.value (QStringLiteral (" IsScript" )).toBool ();
65
-
66
- const auto globalShortcutsOption = settings.value (QStringLiteral (" IsGlobalShortcut" ));
67
- if ( globalShortcutsOption.isValid () ) {
68
- c.isGlobalShortcut = globalShortcutsOption.toBool ();
69
- } else {
70
- // Backwards compatibility with v3.1.2 and below.
71
- if ( c.globalShortcuts .contains (QLatin1String (" DISABLED" )) )
72
- c.globalShortcuts .clear ();
73
- c.isGlobalShortcut = !c.globalShortcuts .isEmpty ();
74
- }
75
36
76
- if (settings.value (QStringLiteral (" Ignore" )).toBool ())
77
- c.remove = c.automatic = true ;
78
- else
79
- c.remove = settings.value (QStringLiteral (" Remove" )).toBool ();
37
+ for (auto &&key : settings.childKeys ()) {
38
+ if (key == QLatin1String (" Enable" )) {
39
+ c.enable = settings.value (key).toBool ();
40
+ } else if (auto match = nameLocalizationRe.match (key); match.hasMatch ()) {
41
+ const QString languageCode = match.captured (1 );
42
+ const QString value = settings.value (key).toString ();
43
+ if (languageCode.isEmpty ())
44
+ c.name = value;
45
+ else
46
+ c.nameLocalization [languageCode] = value;
47
+ } else if (key == QLatin1String (" Match" )) {
48
+ c.re = QRegularExpression ( settings.value (key).toString () );
49
+ } else if (key == QLatin1String (" Window" )) {
50
+ c.wndre = QRegularExpression ( settings.value (key).toString () );
51
+ } else if (key == QLatin1String (" MatchCommand" )) {
52
+ c.matchCmd = settings.value (key).toString ();
53
+ } else if (key == QLatin1String (" Command" )) {
54
+ c.cmd = settings.value (key).toString ();
55
+ } else if (key == QLatin1String (" Separator" )) {
56
+ c.sep = settings.value (key).toString ();
57
+ } else if (key == QLatin1String (" Input" )) {
58
+ c.input = settings.value (key).toString ();
59
+ if (c.input == falseString || c.input == trueString)
60
+ c.input = c.input == trueString ? mimeText : QLatin1String ();
61
+ } else if (key == QLatin1String (" Output" )) {
62
+ c.output = settings.value (key).toString ();
63
+ if (c.output == falseString || c.output == trueString)
64
+ c.output = c.output == trueString ? mimeText : QLatin1String ();
65
+ } else if (key == QLatin1String (" Wait" )) {
66
+ c.wait = settings.value (key).toBool ();
67
+ } else if (key == QLatin1String (" Automatic" )) {
68
+ c.automatic = settings.value (key).toBool ();
69
+ } else if (key == QLatin1String (" Display" )) {
70
+ c.display = settings.value (key).toBool ();
71
+ } else if (key == QLatin1String (" Transform" )) {
72
+ c.transform = settings.value (key).toBool ();
73
+ } else if (key == QLatin1String (" HideWindow" )) {
74
+ c.hideWindow = settings.value (key).toBool ();
75
+ } else if (key == QLatin1String (" Icon" )) {
76
+ c.icon = settings.value (key).toString ();
77
+ } else if (key == QLatin1String (" Shortcut" )) {
78
+ c.shortcuts = settings.value (key).toStringList ();
79
+ } else if (key == QLatin1String (" GlobalShortcut" )) {
80
+ c.globalShortcuts = settings.value (key).toStringList ();
81
+ } else if (key == QLatin1String (" Tab" )) {
82
+ c.tab = settings.value (key).toString ();
83
+ } else if (key == QLatin1String (" OutputTab" )) {
84
+ c.outputTab = settings.value (key).toString ();
85
+ } else if (key == QLatin1String (" InternalId" )) {
86
+ c.internalId = settings.value (key).toString ();
87
+ } else if (key == QLatin1String (" InMenu" )) {
88
+ c.inMenu = settings.value (key).toBool ();
89
+ } else if (key == QLatin1String (" IsScript" )) {
90
+ c.isScript = settings.value (key).toBool ();
91
+ } else if (key == QLatin1String (" IsGlobalShortcut" )) {
92
+ c.isGlobalShortcut = settings.value (key).toBool ();
93
+ } else if (key == QLatin1String (" Remove" )) {
94
+ c.remove = settings.value (key).toBool ();
95
+ } else if (key == QLatin1String (" Ignore" )) {
96
+ if (settings.value (key).toBool ())
97
+ c.remove = c.automatic = true ;
98
+ }
99
+ }
80
100
81
101
commands->append (c);
82
102
}
@@ -130,6 +150,11 @@ void saveCommand(const Command &c, QSettings *settings)
130
150
saveNewValue (QStringLiteral (" Tab" ), c, &Command::tab, settings);
131
151
saveNewValue (QStringLiteral (" OutputTab" ), c, &Command::outputTab, settings);
132
152
saveNewValue (QStringLiteral (" InternalId" ), c, &Command::internalId, settings);
153
+
154
+ for (auto it = c.nameLocalization .constBegin (); it != c.nameLocalization .constEnd (); ++it) {
155
+ const auto key = QStringLiteral (" Name_%1" ).arg (it.key ());
156
+ saveValue (key, it.value (), settings);
157
+ }
133
158
}
134
159
135
160
Commands importCommands (QSettings *settings)
0 commit comments