~ubuntu-branches/ubuntu/saucy/digikam/saucy

« back to all changes in this revision

Viewing changes to utilities/advancedrename/parser/options/dateoption.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-12-21 23:19:11 UTC
  • mfrom: (1.2.33 upstream) (3.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20101221231911-z9jip7s5aht1jqn9
Tags: 2:1.7.0-1ubuntu1
* Merge from Debian Experimental. Remaining Ubuntu changes:
  - Export .pot name and copy to plugins in debian/rules
  - Version build-depends on kipi-plugins-dev to ensure build is against the
    same version on all archs
* Drop debian/patches/kubuntu_01_linker.diff, incoporated upstream
* Remove patches directory and unused patches

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
 * Date        : 2009-08-08
7
7
 * Description : an option to provide date information to the parser
8
8
 *
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>
10
10
 *
11
11
 * This program is free software; you can redistribute it
12
12
 * and/or modify it under the terms of the GNU General
43
43
namespace Digikam
44
44
{
45
45
 
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);
49
49
 
50
50
// --------------------------------------------------------
51
51
 
52
52
DateFormat::DateFormat()
53
53
{
54
 
    m_map.clear();
55
 
 
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("")));
61
59
}
62
60
 
63
61
QString DateFormat::identifier(Type type)
64
62
{
65
 
    DateFormatDescriptor desc = m_map.at((int)type);
66
 
    return desc.first;
 
63
    return m_map.at((int)type).first;
67
64
}
68
65
 
69
66
QVariant DateFormat::formatType(Type type)
70
67
{
71
 
    DateFormatDescriptor desc = m_map.at((int)type);
72
 
    return desc.second;
 
68
    return m_map.at((int)type).second;
73
69
}
74
70
 
75
 
QVariant DateFormat::formatType(QString identifier)
 
71
QVariant DateFormat::formatType(const QString& identifier)
76
72
{
77
 
    QVariant v;
 
73
    if (identifier.isEmpty())
 
74
    {
 
75
        return m_map.at(Standard).second;
 
76
    }
 
77
 
78
78
    foreach (const DateFormatDescriptor& desc, m_map)
79
79
    {
80
80
        if (desc.first == identifier)
81
81
        {
82
 
            v = desc.second;
83
 
            break;
 
82
            return desc.second;
84
83
        }
85
84
    }
86
 
 
87
 
    if (identifier.isEmpty())
88
 
    {
89
 
        return m_map.at(Standard).second;
90
 
    }
91
 
 
92
 
    return v;
 
85
    return QVariant();
93
86
}
94
87
 
95
88
// --------------------------------------------------------
96
89
 
97
90
DateOptionDialog::DateOptionDialog(Parseable* parent)
98
 
                : ParseableDialog(parent), ui(new Ui::DateOptionDialogWidget)
 
91
    : ParseableDialog(parent), ui(new Ui::DateOptionDialogWidget)
99
92
{
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));
112
105
 
127
120
    ui->dateFormatLink->setText(dateFormatLink);
128
121
 
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"));
133
126
 
163
156
    bool ok    = true;
164
157
    int choice = v.toInt(&ok);
165
158
 
166
 
    return (DateSource)choice;
 
159
    return static_cast<DateSource>(choice);
167
160
}
168
161
 
169
162
QString DateOptionDialog::formattedDateTime(const QDateTime& date)
174
167
    }
175
168
 
176
169
    DateFormat df;
177
 
    QVariant v;
 
170
    QVariant   v;
178
171
 
179
 
    v = df.formatType((DateFormat::Type)ui->dateFormatPicker->currentIndex());
 
172
    v = df.formatType(static_cast<DateFormat::Type>(ui->dateFormatPicker->currentIndex()));
180
173
    QString result;
 
174
 
181
175
    if (v.type() == QVariant::String)
182
176
    {
183
177
        result = date.toString(v.toString());
186
180
    {
187
181
        result = date.toString((Qt::DateFormat)v.toInt());
188
182
    }
 
183
 
189
184
    return result;
190
185
}
191
186
 
192
187
void DateOptionDialog::slotDateSourceChanged(int index)
193
188
{
194
189
    Q_UNUSED(index)
195
 
 
196
 
    DateSource choice = dateSource();
197
 
    ui->fixedDateContainer->setEnabled( (choice == FixedDateTime) );
 
190
    ui->fixedDateContainer->setEnabled(dateSource() == FixedDateTime);
198
191
}
199
192
 
200
193
void DateOptionDialog::slotDateFormatChanged(int index)
201
194
{
202
195
    bool custom = (index == DateFormat::Custom);
203
 
 
204
196
    ui->customFormatInput->setEnabled(custom);
205
 
 
206
197
    ui->dateFormatLink->setEnabled(custom);
207
198
    ui->dateFormatLink->setVisible(custom);
208
199
 
223
214
// --------------------------------------------------------
224
215
 
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"))
229
220
{
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 + ')');
234
225
 
239
230
 
240
231
QString DateOption::parseOperation(ParseSettings& settings)
241
232
{
242
 
    QString result;
243
 
    DateFormat df;
244
 
 
245
233
    const QRegExp& reg = regExp();
246
234
 
247
235
    QString token = reg.cap(2);
248
236
 
249
237
    if ( !(token.isEmpty() || token.isNull()) &&
250
 
          (token.startsWith('"') && token.endsWith('"'))
 
238
         (token.startsWith('"') && token.endsWith('"'))
251
239
       )
252
240
    {
253
241
        token = token.remove(0, 1);
265
253
    {
266
254
        // lets try to re-read the file information
267
255
        ImageInfo info(settings.fileUrl);
 
256
 
268
257
        if (!info.isNull())
269
258
        {
270
259
            dateTime = info.dateTime();
284
273
        return QString();
285
274
    }
286
275
 
287
 
    QVariant v = df.formatType(token);
 
276
    QString    result;
 
277
    DateFormat df;
 
278
    QVariant   v = df.formatType(token);
 
279
 
288
280
    if (v.isNull())
289
281
    {
290
282
        result = dateTime.toString(token);
308
300
{
309
301
    Q_UNUSED(token)
310
302
 
311
 
    QVariant v;
312
 
    DateFormat df;
 
303
    QPointer<DateOptionDialog> dlg = new DateOptionDialog(this);
 
304
 
313
305
    QString dateString;
314
306
 
315
 
    QString tokenStr               = QString("[date:%1]");
316
 
    QPointer<DateOptionDialog> dlg = new DateOptionDialog(this);
317
 
 
318
307
    if (dlg->exec() == KDialog::Accepted)
319
308
    {
 
309
        DateFormat df;
320
310
        int index = dlg->ui->dateFormatPicker->currentIndex();
321
311
 
322
312
        // use custom date format?
326
316
            date.setDate(dlg->ui->datePicker->date());
327
317
            date.setTime(dlg->ui->timePicker->time());
328
318
 
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);
331
322
 
332
323
            if (v.type() == QVariant::String)
333
324
            {
338
329
                dateString = date.toString((Qt::DateFormat)v.toInt());
339
330
            }
340
331
        }
341
 
        else        // use predefined keywords for date formatting
 
332
        // use predefined keywords for date formatting
 
333
        else
342
334
        {
 
335
            QString tokenStr = QString("[date:%1]");
 
336
 
343
337
            switch (index)
344
338
            {
345
339
                case DateFormat::Standard: