7
7
* Description : an option to provide date information to the parser
9
* Copyright (C) 2009 by Andi Clemens <andi dot clemens at gmx dot net>
9
* Copyright (C) 2009-2010 by Andi Clemens <andi dot clemens at gmx dot net>
11
11
* This program is free software; you can redistribute it
12
12
* and/or modify it under the terms of the GNU General
46
const QString dateFormatLinkDescr = i18nc("date format settings", "format settings");
47
const QString dateFormatLink = QString("<a href='http://doc.trolltech.com/latest/qdatetime.html#toString'>%1</a>")
48
.arg(dateFormatLinkDescr);
46
static const QString dateFormatLinkDescr = i18nc("date format settings", "format settings");
47
static const QString dateFormatLink =
48
QString("<a href='http://doc.trolltech.com/latest/qdatetime.html#toString'>%1</a>").arg(dateFormatLinkDescr);
50
50
// --------------------------------------------------------
52
52
DateFormat::DateFormat()
56
54
m_map.insert(Standard, DateFormatDescriptor(QString("Standard"), QString("yyyyMMddThhmmss")));
57
55
m_map.insert(ISO, DateFormatDescriptor(QString("ISO"), Qt::ISODate));
58
56
m_map.insert(FullText, DateFormatDescriptor(QString("Text"), Qt::TextDate));
59
// m_map.insert(Locale, DateFormatDescriptor(QString("Locale"), Qt::SystemLocaleShortDate));
57
// m_map.insert(Locale, DateFormatDescriptor(QString("Locale"), Qt::SystemLocaleShortDate));
60
58
m_map.insert(Custom, DateFormatDescriptor(QString("Custom"), QString("")));
63
61
QString DateFormat::identifier(Type type)
65
DateFormatDescriptor desc = m_map.at((int)type);
63
return m_map.at((int)type).first;
69
66
QVariant DateFormat::formatType(Type type)
71
DateFormatDescriptor desc = m_map.at((int)type);
68
return m_map.at((int)type).second;
75
QVariant DateFormat::formatType(QString identifier)
71
QVariant DateFormat::formatType(const QString& identifier)
73
if (identifier.isEmpty())
75
return m_map.at(Standard).second;
78
78
foreach (const DateFormatDescriptor& desc, m_map)
80
80
if (desc.first == identifier)
87
if (identifier.isEmpty())
89
return m_map.at(Standard).second;
95
88
// --------------------------------------------------------
97
90
DateOptionDialog::DateOptionDialog(Parseable* parent)
98
: ParseableDialog(parent), ui(new Ui::DateOptionDialogWidget)
91
: ParseableDialog(parent), ui(new Ui::DateOptionDialogWidget)
100
93
QWidget* mainWidget = new QWidget(this);
101
94
ui->setupUi(mainWidget);
105
98
// fill the date source combobox
106
99
ui->dateSourcePicker->addItem(i18nc("Get date information from the image", "Image"),
107
100
QVariant(FromImage));
108
// ui->dateSourcePicker->addItem(i18nc("Get date information from the current date", "Current Date"),
109
// QVariant(CurrentDateTime));
101
// ui->dateSourcePicker->addItem(i18nc("Get date information from the current date", "Current Date"),
102
// QVariant(CurrentDateTime));
110
103
ui->dateSourcePicker->addItem(i18nc("Set a fixed date", "Fixed Date"),
111
104
QVariant(FixedDateTime));
127
120
ui->dateFormatLink->setText(dateFormatLink);
129
122
QRegExp validRegExp("[^/]+");
130
QValidator *validator = new QRegExpValidator(validRegExp, this);
123
QValidator* validator = new QRegExpValidator(validRegExp, this);
131
124
ui->customFormatInput->setValidator(validator);
132
125
ui->customFormatInput->setClickMessage(i18n("Enter custom format"));
187
181
result = date.toString((Qt::DateFormat)v.toInt());
192
187
void DateOptionDialog::slotDateSourceChanged(int index)
196
DateSource choice = dateSource();
197
ui->fixedDateContainer->setEnabled( (choice == FixedDateTime) );
190
ui->fixedDateContainer->setEnabled(dateSource() == FixedDateTime);
200
193
void DateOptionDialog::slotDateFormatChanged(int index)
202
195
bool custom = (index == DateFormat::Custom);
204
196
ui->customFormatInput->setEnabled(custom);
206
197
ui->dateFormatLink->setEnabled(custom);
207
198
ui->dateFormatLink->setVisible(custom);
223
214
// --------------------------------------------------------
225
216
DateOption::DateOption()
226
: Option(i18n("Date && Time..."),
227
i18n("Add date and time information"),
228
SmallIcon("view-pim-calendar"))
217
: Option(i18n("Date && Time..."),
218
i18n("Add date and time information"),
219
SmallIcon("view-pim-calendar"))
230
221
addToken("[date]", i18n("Date and time (standard format)"));
231
// addToken("[date:||key||]", i18n("Date and time (||key|| = Standard|ISO|Text|Locale)"));
222
// addToken("[date:||key||]", i18n("Date and time (||key|| = Standard|ISO|Text|Locale)"));
232
223
addToken("[date:||key||]", i18n("Date and time (||key|| = Standard|ISO|Text)"));
233
224
addToken("[date:||format||]", i18n("Date and time") + " (" + dateFormatLink + ')');
240
231
QString DateOption::parseOperation(ParseSettings& settings)
245
233
const QRegExp& reg = regExp();
247
235
QString token = reg.cap(2);
249
237
if ( !(token.isEmpty() || token.isNull()) &&
250
(token.startsWith('"') && token.endsWith('"'))
238
(token.startsWith('"') && token.endsWith('"'))
253
241
token = token.remove(0, 1);
303
QPointer<DateOptionDialog> dlg = new DateOptionDialog(this);
313
305
QString dateString;
315
QString tokenStr = QString("[date:%1]");
316
QPointer<DateOptionDialog> dlg = new DateOptionDialog(this);
318
307
if (dlg->exec() == KDialog::Accepted)
320
310
int index = dlg->ui->dateFormatPicker->currentIndex();
322
312
// use custom date format?
326
316
date.setDate(dlg->ui->datePicker->date());
327
317
date.setTime(dlg->ui->timePicker->time());
329
v = (index == DateFormat::Custom) ? dlg->ui->customFormatInput->text()
330
: df.formatType((DateFormat::Type)index);
319
QVariant v = (index == DateFormat::Custom)
320
? dlg->ui->customFormatInput->text()
321
: df.formatType((DateFormat::Type)index);
332
323
if (v.type() == QVariant::String)
338
329
dateString = date.toString((Qt::DateFormat)v.toInt());
341
else // use predefined keywords for date formatting
332
// use predefined keywords for date formatting
335
QString tokenStr = QString("[date:%1]");
345
339
case DateFormat::Standard: