Update Finnish translation
[nomnom.git] / src / settings / nsettings.cpp
blob58b685a23dcc84489b160c51815b7a27c2ed02a0
1 /* NomNom
2 * Copyright (C) 2011 Toni Gundogdu <legatvs@gmail.com>
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "config.h"
20 #include <QStringList>
22 #include <NSettings>
24 namespace nn
27 // Edit "SettingKey" enum in nsettings.h also.
28 const char *key_strings[] =
30 // Commands
31 "ParseUsing",
32 "ParseUsingOther",
33 "DownloadUsing",
34 "DownloadUsingOther",
35 "PlayUsing",
36 "PlayUsingOther",
37 "FeedUsing",
38 "FeedUsingOther",
39 // Download
40 "FilenameFormat",
41 "FilenameRegExp",
42 "SaveMediaDirectory",
43 // Proxy
44 "ProxyType",
45 "ProxyHost",
46 "ProxyPort",
47 // Options: Appearance
48 "CustomApplicationIcon",
49 "CustomBusyIcon",
50 "CustomErrorIcon",
51 "Language",
52 // Options: Behaviour
53 "KeepApplicationWindowOnTop",
54 "PlayWhenDoneDownloading",
55 "AskWhereToSaveMediaFile",
56 "ClearURLRecordAtExit",
57 "ReplaceExistingMedia",
58 "GetBestFormat",
59 // Options: Systray
60 "ShowInTrayIcon",
61 "TerminateInstead",
62 "StartInTrayIcon",
63 // Must end with 0.
67 static bool check_regexp(const QString& regexp, QStringList& cap)
69 QRegExp rx("^\\/(.*)\\/(.*)$");
71 if (rx.indexIn(regexp) == -1)
72 return false;
74 cap = rx.capturedTexts();
76 return true;
79 static bool apply_regexp(const QString& regexp,
80 const QString& title,
81 QString& dst)
83 QStringList cap;
84 if (!check_regexp(regexp, cap))
85 return false;
87 const QString p = cap.at(1);
88 const bool g = cap.at(2).contains("g");
89 #ifdef _1
90 const bool i = cap.at(2).contains("i");
91 #endif
93 QRegExp rx(p);
94 #ifdef _1
95 rx.setCaseSensitivity(i ? Qt::CaseInsensitive : Qt::CaseSensitive);
96 #endif
98 int pos = 0;
99 while ((pos = rx.indexIn(title, pos)) != -1)
101 pos += rx.matchedLength();
102 dst += rx.cap(1);
103 if (!g) break;
106 dst = dst.simplified();
108 return true;
111 bool format_filename(const QString& regexp,
112 const QString& title,
113 const QString& media_id,
114 const QString& domain,
115 const QString& suffix,
116 QString& result)
118 QString regexp_title;
119 if (!apply_regexp(regexp, title, regexp_title))
120 return false;
122 result.replace("%t", regexp_title);
123 result.replace("%i", media_id);
124 result.replace("%d", domain);
125 result.replace("%s", suffix);
127 result = result.simplified();
129 return true;
133 } // namespace nn
135 /* vim: set ts=2 sw=2 tw=72 expandtab: */