~ubuntu-branches/ubuntu/trusty/digikam/trusty

« back to all changes in this revision

Viewing changes to core/utilities/cameragui/widgets/albumcustomizer.cpp

  • Committer: Package Import Robot
  • Author(s): Rohan Garg
  • Date: 2012-11-26 18:24:20 UTC
  • mfrom: (1.9.1) (3.1.23 experimental)
  • Revision ID: package-import@ubuntu.com-20121126182420-qoy6z0nx4ai0wzcl
Tags: 4:3.0.0~beta3-0ubuntu1
* New upstream release
  - Add build-deps :  libhupnp-dev, libqtgstreamer-dev, libmagickcore-dev
* Merge from debian, remaining changes:
  - Make sure libqt4-opengl-dev, libgl1-mesa-dev and libglu1-mesa-dev only
    install on i386,amd64 and powerpc
  - Depend on libtiff-dev instead of libtiff4-dev
  - Drop digikam breaks/replaces kipi-plugins-common since we're past the
    LTS release now
  - digikam to recommend mplayerthumbs | ffmpegthumbs. We currently only
    have latter in the archives, even though former is also supposed to
    be part of kdemultimedia. (LP: #890059)
  - kipi-plugins to recommend www-browser rather than konqueror directly
    since 2.8 no direct usage of konqueror is present in the flickr
    plugin anymore (LP: #1011211)
  - Keep kubuntu_mysqld_executable_name.diff
  - Don't install libkipi translations
  - Keep deps on libcv-dev, libcvaux-dev
  - Keep split packaging of libraries
  - Replace icons from KDE 3 time in debian/xpm.d/*.xpm with the new
    versions (LP: #658047)
* Update debian/not-installed

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* ============================================================
2
 
 *
3
 
 * This file is a part of digiKam project
4
 
 * http://www.digikam.org
5
 
 *
6
 
 * Date        : 2011-08-11
7
 
 * Description : a widget to customize album name created by
8
 
 *               camera interface.
9
 
 *
10
 
 * Copyright (C) 2011 by Gilles Caulier <caulier dot gilles at gmail dot com>
11
 
 *
12
 
 * This program is free software; you can redistribute it
13
 
 * and/or modify it under the terms of the GNU General
14
 
 * Public License as published by the Free Software Foundation;
15
 
 * either version 2, or (at your option)
16
 
 * any later version.
17
 
 *
18
 
 * This program is distributed in the hope that it will be useful,
19
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 
 * GNU General Public License for more details.
22
 
 *
23
 
 * ============================================================ */
24
 
 
25
 
#include "albumcustomizer.moc"
26
 
 
27
 
// Qt includes
28
 
 
29
 
#include <QVBoxLayout>
30
 
#include <QLabel>
31
 
#include <QCheckBox>
32
 
#include <QToolButton>
33
 
 
34
 
// KDE includes
35
 
 
36
 
#include <ksqueezedtextlabel.h>
37
 
#include <kdialog.h>
38
 
#include <klocale.h>
39
 
#include <kcombobox.h>
40
 
#include <khbox.h>
41
 
#include <klineedit.h>
42
 
#include <kdebug.h>
43
 
 
44
 
// Local includes
45
 
 
46
 
#include "tooltipdialog.h"
47
 
 
48
 
namespace Digikam
49
 
{
50
 
 
51
 
class AlbumCustomizer::AlbumCustomizerPriv
52
 
{
53
 
public:
54
 
 
55
 
    AlbumCustomizerPriv()
56
 
        : autoAlbumDateCheck(0),
57
 
          autoAlbumExtCheck(0),
58
 
          folderDateLabel(0),
59
 
          customizer(0),
60
 
          tooltipToggleButton(0),
61
 
          customExample(0),
62
 
          folderDateFormat(0),
63
 
          tooltipDialog(0)
64
 
    {
65
 
    }
66
 
 
67
 
    QCheckBox*          autoAlbumDateCheck;
68
 
    QCheckBox*          autoAlbumExtCheck;
69
 
 
70
 
    QLabel*             folderDateLabel;
71
 
 
72
 
    QLineEdit*          customizer;
73
 
 
74
 
    QToolButton*        tooltipToggleButton;
75
 
 
76
 
    KSqueezedTextLabel* customExample;
77
 
 
78
 
    KComboBox*          folderDateFormat;
79
 
 
80
 
    TooltipDialog*      tooltipDialog;
81
 
};
82
 
 
83
 
AlbumCustomizer::AlbumCustomizer(QWidget* parent)
84
 
    : QWidget(parent), d(new AlbumCustomizerPriv)
85
 
{
86
 
    d->tooltipDialog = new TooltipDialog(this);
87
 
    d->tooltipDialog->setTooltip(i18n("<p>These expressions may be used to customize date format:</p>"
88
 
                                      "<p><b>d</b>: The day as a number without a leading zero (1 to 31)</p>"
89
 
                                      "<p><b>dd</b>: The day as a number with a leading zero (01 to 31)</p>"
90
 
                                      "<p><b>ddd</b>: The abbreviated localized day name (e.g. 'Mon' to 'Sun')</p>"
91
 
                                      "<p><b>dddd</b>: The long localized day name (e.g. 'Monday' to 'Sunday').</p>"
92
 
                                      "<p><b>M</b>: The month as a number without a leading zero (1 to 12)</p>"
93
 
                                      "<p><b>MM</b>: The month as a number with a leading zero (01 to 12)</p>"
94
 
                                      "<p><b>MMM</b>: The abbreviated localized month name (e.g. 'Jan' to 'Dec')</p>"
95
 
                                      "<p><b>MMMM</b>: The long localized month name (e.g. 'January' to 'December')</p>"
96
 
                                      "<p><b>yy</b>: The year as two digit number (eg. 00 to 99)</p>"
97
 
                                      "<p><b>yyyy</b>: The year as four digit number (eg. 2012)</p>"
98
 
                                      "<p>All other input characters will be treated as text. Any sequence of characters "
99
 
                                      "that are enclosed in singlequotes will be treated as text and not be used as an "
100
 
                                      "expression. Examples, if date is 20 July 1969:<p>"
101
 
                                      "<p><b>dd.MM.yyyy</b> : 20.07.1969</p>"
102
 
                                      "<p><b>ddd MMMM d yy</b> : Sun July 20 69</p>"
103
 
                                      "<p><b>'Photo shoted' dddd</b> : Photo shotted Sunday</p>"
104
 
                                     ));
105
 
    d->tooltipDialog->resize(650, 530);
106
 
 
107
 
    QVBoxLayout* albumVlay = new QVBoxLayout(this);
108
 
    d->autoAlbumExtCheck   = new QCheckBox(i18n("Extension-based sub-albums"), this);
109
 
    d->autoAlbumDateCheck  = new QCheckBox(i18n("Date-based sub-albums"), this);
110
 
    KHBox* hbox1           = new KHBox(this);
111
 
    d->folderDateLabel     = new QLabel(i18n("Date format:"), hbox1);
112
 
    d->folderDateFormat    = new KComboBox(hbox1);
113
 
    d->folderDateFormat->insertItem(IsoDateFormat,    i18n("ISO"));
114
 
    d->folderDateFormat->insertItem(TextDateFormat,   i18n("Full Text"));
115
 
    d->folderDateFormat->insertItem(LocalDateFormat,  i18n("Local Settings"));
116
 
    d->folderDateFormat->insertItem(CustomDateFormat, i18n("Custom"));
117
 
 
118
 
    KHBox* hbox2           = new KHBox(this);
119
 
    d->customizer          = new KLineEdit(hbox2);
120
 
    d->tooltipToggleButton = new QToolButton(hbox2);
121
 
    d->tooltipToggleButton->setIcon(SmallIcon("dialog-information"));
122
 
    d->tooltipToggleButton->setToolTip(i18n("Show a list of all available options"));
123
 
 
124
 
    d->customExample       = new KSqueezedTextLabel(this);
125
 
 
126
 
    albumVlay->addWidget(d->autoAlbumExtCheck);
127
 
    albumVlay->addWidget(d->autoAlbumDateCheck);
128
 
    albumVlay->addWidget(hbox1);
129
 
    albumVlay->addWidget(hbox2);
130
 
    albumVlay->addWidget(d->customExample);
131
 
    albumVlay->addStretch();
132
 
    albumVlay->setMargin(KDialog::spacingHint());
133
 
    albumVlay->setSpacing(KDialog::spacingHint());
134
 
 
135
 
    setWhatsThis(i18n("Set how digiKam creates albums automatically when downloading."));
136
 
    d->autoAlbumExtCheck->setWhatsThis(i18n("Enable this option if you want to download your "
137
 
                                            "pictures into automatically created file extension-based sub-albums of the destination "
138
 
                                            "album. This way, you can separate JPEG and RAW files as they are downloaded from your camera."));
139
 
    d->autoAlbumDateCheck->setWhatsThis(i18n("Enable this option if you want to "
140
 
                                             "download your pictures into automatically created file date-based sub-albums "
141
 
                                             "of the destination album."));
142
 
    d->folderDateFormat->setWhatsThis(i18n("<p>Select your preferred date format used to "
143
 
                                           "create new albums. The options available are:</p>"
144
 
                                           "<p><b>ISO</b>: the date format is in accordance with ISO 8601 "
145
 
                                           "(YYYY-MM-DD). E.g.: <i>2006-08-24</i></p>"
146
 
                                           "<p><b>Full Text</b>: the date format is in a user-readable string. "
147
 
                                           "E.g.: <i>Thu Aug 24 2006</i></p>"
148
 
                                           "<p><b>Local Settings</b>: the date format depending on KDE control panel settings.</p>"
149
 
                                           "<p><b>Custom</b>: use a customized format for date.</p>"));
150
 
    d->customExample->setWhatsThis(i18n("Show the result of converted date 1968-12-26 using your customized format."));
151
 
 
152
 
    // --------------------------------------------------------------------------------------
153
 
 
154
 
    connect(d->autoAlbumDateCheck, SIGNAL(toggled(bool)),
155
 
            d->folderDateFormat, SLOT(setEnabled(bool)));
156
 
 
157
 
    connect(d->autoAlbumDateCheck, SIGNAL(toggled(bool)),
158
 
            d->folderDateLabel, SLOT(setEnabled(bool)));
159
 
 
160
 
    connect(d->tooltipToggleButton, SIGNAL(clicked(bool)),
161
 
            this, SLOT(slotToolTipButtonToggled(bool)));
162
 
 
163
 
    connect(d->folderDateFormat, SIGNAL(activated(int)),
164
 
            this, SLOT(slotFolderDateFormatChanged(int)));
165
 
 
166
 
    connect(d->customizer, SIGNAL(textChanged(QString)),
167
 
            this, SLOT(slotCustomizerChanged()));
168
 
}
169
 
 
170
 
AlbumCustomizer::~AlbumCustomizer()
171
 
{
172
 
    delete d;
173
 
}
174
 
 
175
 
void AlbumCustomizer::readSettings(KConfigGroup& group)
176
 
{
177
 
    d->autoAlbumDateCheck->setChecked(group.readEntry("AutoAlbumDate",       false));
178
 
    d->autoAlbumExtCheck->setChecked(group.readEntry("AutoAlbumExt",         false));
179
 
    d->folderDateFormat->setCurrentIndex(group.readEntry("FolderDateFormat", (int)IsoDateFormat));
180
 
    d->customizer->setText(group.readEntry("CustomDateFormat",               QString()));
181
 
 
182
 
    d->folderDateFormat->setEnabled(d->autoAlbumDateCheck->isChecked());
183
 
    d->folderDateLabel->setEnabled(d->autoAlbumDateCheck->isChecked());
184
 
    slotFolderDateFormatChanged(d->folderDateFormat->currentIndex());
185
 
}
186
 
 
187
 
void AlbumCustomizer::saveSettings(KConfigGroup& group)
188
 
{
189
 
    group.writeEntry("AutoAlbumDate",    d->autoAlbumDateCheck->isChecked());
190
 
    group.writeEntry("AutoAlbumExt",     d->autoAlbumExtCheck->isChecked());
191
 
    group.writeEntry("FolderDateFormat", d->folderDateFormat->currentIndex());
192
 
    group.writeEntry("CustomDateFormat", d->customizer->text());
193
 
}
194
 
 
195
 
bool AlbumCustomizer::autoAlbumDateEnabled() const
196
 
{
197
 
    return d->autoAlbumDateCheck->isChecked();
198
 
}
199
 
 
200
 
bool AlbumCustomizer::autoAlbumExtEnabled() const
201
 
{
202
 
    return d->autoAlbumExtCheck->isChecked();
203
 
}
204
 
 
205
 
int AlbumCustomizer::folderDateFormat() const
206
 
{
207
 
    return d->folderDateFormat->currentIndex();
208
 
}
209
 
 
210
 
QString AlbumCustomizer::customDateFormat() const
211
 
{
212
 
    return d->customizer->text();
213
 
}
214
 
 
215
 
bool AlbumCustomizer::customDateFormatIsValid() const
216
 
{
217
 
    QDate date(1968, 12, 26);
218
 
    return !date.toString(customDateFormat()).isEmpty();
219
 
}
220
 
 
221
 
void AlbumCustomizer::slotToolTipButtonToggled(bool /*checked*/)
222
 
{
223
 
    if (!d->tooltipDialog->isVisible())
224
 
    {
225
 
        d->tooltipDialog->show();
226
 
    }
227
 
 
228
 
    d->tooltipDialog->raise();
229
 
}
230
 
 
231
 
void AlbumCustomizer::slotFolderDateFormatChanged(int index)
232
 
{
233
 
    bool b = (index == CustomDateFormat);
234
 
    d->customizer->setEnabled(b);
235
 
    d->tooltipToggleButton->setEnabled(b);
236
 
    d->customExample->setEnabled(b);
237
 
    slotCustomizerChanged();
238
 
}
239
 
 
240
 
void AlbumCustomizer::slotCustomizerChanged()
241
 
{
242
 
    if (folderDateFormat() == CustomDateFormat)
243
 
    {
244
 
        QDate date(1968, 12, 26);
245
 
 
246
 
        if (customDateFormatIsValid())
247
 
        {
248
 
            d->customExample->setText(i18n("Ex.: %1", date.toString(customDateFormat())));
249
 
        }
250
 
        else
251
 
        {
252
 
            d->customExample->setText(i18n("Format is not valid..."));
253
 
        }
254
 
    }
255
 
    else
256
 
    {
257
 
        d->customExample->clear();
258
 
    }
259
 
}
260
 
 
261
 
}  // namespace Digikam