1
// vim: set tabstop=4 shiftwidth=4 noexpandtab:
3
Gwenview: an image viewer
4
Copyright 2009 Aurélien Gâteau <agateau@kde.org>
6
This program is free software; you can redistribute it and/or
7
modify it under the terms of the GNU General Public License
8
as published by the Free Software Foundation; either version 2
9
of the License, or (at your option) any later version.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
22
#include "filenameformater.h"
28
#include <kdatetime.h>
36
typedef QHash<QString, QString> Dict;
38
struct FileNameFormaterPrivate {
43
FileNameFormater::FileNameFormater(const QString& format)
44
: d(new FileNameFormaterPrivate) {
49
FileNameFormater::~FileNameFormater() {
54
QString FileNameFormater::format(const KUrl& url, const KDateTime& dateTime) {
55
QFileInfo info(url.fileName());
57
// Keep in sync with helpMap()
59
dict["date"] = dateTime.toString("%Y-%m-%d");
60
dict["time"] = dateTime.toString("%H-%M-%S");
61
dict["ext"] = info.completeSuffix();
62
dict["ext.lower"] = info.completeSuffix().toLower();
63
dict["name"] = info.baseName();
64
dict["name.lower"] = info.baseName().toLower();
67
int length = d->mFormat.length();
68
for (int pos=0; pos < length; ++pos) {
69
QChar ch = d->mFormat[pos];
71
if (pos == length - 1) {
72
// We are at the end, ignore this
75
if (d->mFormat[pos + 1] == '{') {
76
// This is an escaped '{', skip one
81
int end = d->mFormat.indexOf('}', pos + 1);
83
// No '}' found, stop here
86
// Replace keyword with its value
87
QString keyword = d->mFormat.mid(pos + 1, end - pos - 1);
88
name += dict.value(keyword);
98
FileNameFormater::HelpMap FileNameFormater::helpMap() {
99
// Keep in sync with dict in format()
102
map["date"] = i18n("Shooting date");
103
map["time"] = i18n("Shooting time");
104
map["ext"] = i18n("Original extension");
105
map["ext.lower"] = i18n("Original extension, in lower case");
106
map["name"] = i18n("Original filename");
107
map["name.lower"] = i18n("Original filename, in lower case");