1
/* ============================================================
3
* This file is a part of digiKam project
4
* http://www.digikam.org
7
* Description : a widget to customize album name created by
10
* Copyright (C) 2011 by Gilles Caulier <caulier dot gilles at gmail dot com>
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)
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.
23
* ============================================================ */
25
#include "albumcustomizer.moc"
29
#include <QVBoxLayout>
32
#include <QToolButton>
36
#include <ksqueezedtextlabel.h>
39
#include <kcombobox.h>
41
#include <klineedit.h>
46
#include "tooltipdialog.h"
51
class AlbumCustomizer::AlbumCustomizerPriv
56
: autoAlbumDateCheck(0),
60
tooltipToggleButton(0),
67
QCheckBox* autoAlbumDateCheck;
68
QCheckBox* autoAlbumExtCheck;
70
QLabel* folderDateLabel;
72
QLineEdit* customizer;
74
QToolButton* tooltipToggleButton;
76
KSqueezedTextLabel* customExample;
78
KComboBox* folderDateFormat;
80
TooltipDialog* tooltipDialog;
83
AlbumCustomizer::AlbumCustomizer(QWidget* parent)
84
: QWidget(parent), d(new AlbumCustomizerPriv)
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>"
105
d->tooltipDialog->resize(650, 530);
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"));
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"));
124
d->customExample = new KSqueezedTextLabel(this);
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());
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."));
152
// --------------------------------------------------------------------------------------
154
connect(d->autoAlbumDateCheck, SIGNAL(toggled(bool)),
155
d->folderDateFormat, SLOT(setEnabled(bool)));
157
connect(d->autoAlbumDateCheck, SIGNAL(toggled(bool)),
158
d->folderDateLabel, SLOT(setEnabled(bool)));
160
connect(d->tooltipToggleButton, SIGNAL(clicked(bool)),
161
this, SLOT(slotToolTipButtonToggled(bool)));
163
connect(d->folderDateFormat, SIGNAL(activated(int)),
164
this, SLOT(slotFolderDateFormatChanged(int)));
166
connect(d->customizer, SIGNAL(textChanged(QString)),
167
this, SLOT(slotCustomizerChanged()));
170
AlbumCustomizer::~AlbumCustomizer()
175
void AlbumCustomizer::readSettings(KConfigGroup& group)
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()));
182
d->folderDateFormat->setEnabled(d->autoAlbumDateCheck->isChecked());
183
d->folderDateLabel->setEnabled(d->autoAlbumDateCheck->isChecked());
184
slotFolderDateFormatChanged(d->folderDateFormat->currentIndex());
187
void AlbumCustomizer::saveSettings(KConfigGroup& group)
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());
195
bool AlbumCustomizer::autoAlbumDateEnabled() const
197
return d->autoAlbumDateCheck->isChecked();
200
bool AlbumCustomizer::autoAlbumExtEnabled() const
202
return d->autoAlbumExtCheck->isChecked();
205
int AlbumCustomizer::folderDateFormat() const
207
return d->folderDateFormat->currentIndex();
210
QString AlbumCustomizer::customDateFormat() const
212
return d->customizer->text();
215
bool AlbumCustomizer::customDateFormatIsValid() const
217
QDate date(1968, 12, 26);
218
return !date.toString(customDateFormat()).isEmpty();
221
void AlbumCustomizer::slotToolTipButtonToggled(bool /*checked*/)
223
if (!d->tooltipDialog->isVisible())
225
d->tooltipDialog->show();
228
d->tooltipDialog->raise();
231
void AlbumCustomizer::slotFolderDateFormatChanged(int index)
233
bool b = (index == CustomDateFormat);
234
d->customizer->setEnabled(b);
235
d->tooltipToggleButton->setEnabled(b);
236
d->customExample->setEnabled(b);
237
slotCustomizerChanged();
240
void AlbumCustomizer::slotCustomizerChanged()
242
if (folderDateFormat() == CustomDateFormat)
244
QDate date(1968, 12, 26);
246
if (customDateFormatIsValid())
248
d->customExample->setText(i18n("Ex.: %1", date.toString(customDateFormat())));
252
d->customExample->setText(i18n("Format is not valid..."));
257
d->customExample->clear();
261
} // namespace Digikam