36
37
typedef QHash<QString, QString> Dict;
38
39
struct FileNameFormaterPrivate {
43
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");
44
: d(new FileNameFormaterPrivate)
49
FileNameFormater::~FileNameFormater()
54
QString FileNameFormater::format(const KUrl& url, const KDateTime& dateTime)
56
QFileInfo info(url.fileName());
58
// Keep in sync with helpMap()
60
dict["date"] = dateTime.toString("%Y-%m-%d");
61
dict["time"] = dateTime.toString("%H-%M-%S");
62
dict["ext"] = info.completeSuffix();
63
dict["ext.lower"] = info.completeSuffix().toLower();
64
dict["name"] = info.baseName();
65
dict["name.lower"] = info.baseName().toLower();
68
int length = d->mFormat.length();
69
for (int pos = 0; pos < length; ++pos) {
70
QChar ch = d->mFormat[pos];
72
if (pos == length - 1) {
73
// We are at the end, ignore this
76
if (d->mFormat[pos + 1] == '{') {
77
// This is an escaped '{', skip one
82
int end = d->mFormat.indexOf('}', pos + 1);
84
// No '}' found, stop here
87
// Replace keyword with its value
88
QString keyword = d->mFormat.mid(pos + 1, end - pos - 1);
89
name += dict.value(keyword);
98
FileNameFormater::HelpMap FileNameFormater::helpMap()
100
// Keep in sync with dict in format()
103
map["date"] = i18n("Shooting date");
104
map["time"] = i18n("Shooting time");
105
map["ext"] = i18n("Original extension");
106
map["ext.lower"] = i18n("Original extension, in lower case");
107
map["name"] = i18n("Original filename");
108
map["name.lower"] = i18n("Original filename, in lower case");