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/>.
20 #include <QStringList>
27 // Edit "SettingKey" enum in nsettings.h also.
28 const char *key_strings
[] =
47 // Options: Appearance
48 "CustomApplicationIcon",
53 "KeepApplicationWindowOnTop",
54 "PlayWhenDoneDownloading",
55 "AskWhereToSaveMediaFile",
56 "ClearURLRecordAtExit",
57 "ReplaceExistingMedia",
67 static bool check_regexp(const QString
& regexp
, QStringList
& cap
)
69 QRegExp
rx("^\\/(.*)\\/(.*)$");
71 if (rx
.indexIn(regexp
) == -1)
74 cap
= rx
.capturedTexts();
79 static bool apply_regexp(const QString
& regexp
,
84 if (!check_regexp(regexp
, cap
))
87 const QString p
= cap
.at(1);
88 const bool g
= cap
.at(2).contains("g");
90 const bool i
= cap
.at(2).contains("i");
95 rx
.setCaseSensitivity(i
? Qt::CaseInsensitive
: Qt::CaseSensitive
);
99 while ((pos
= rx
.indexIn(title
, pos
)) != -1)
101 pos
+= rx
.matchedLength();
106 dst
= dst
.simplified();
111 bool format_filename(const QString
& regexp
,
112 const QString
& title
,
113 const QString
& media_id
,
114 const QString
& domain
,
115 const QString
& suffix
,
118 QString regexp_title
;
119 if (!apply_regexp(regexp
, title
, regexp_title
))
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();
135 /* vim: set ts=2 sw=2 tw=72 expandtab: */