00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <QCheckBox>
00029 #include <QDateTime>
00030 #include <QDir>
00031 #include <QFileInfo>
00032 #include <QFrame>
00033 #include <QGridLayout>
00034 #include <QGroupBox>
00035 #include <QLabel>
00036 #include <QPushButton>
00037 #include <QTextEdit>
00038
00039
00040
00041 #include <kcombobox.h>
00042 #include <kcursor.h>
00043 #include <kdatepicker.h>
00044 #include <kdeversion.h>
00045 #include <khbox.h>
00046 #include <kinputdialog.h>
00047 #include <klineedit.h>
00048 #include <klocale.h>
00049 #include <kmessagebox.h>
00050 #include <ktextedit.h>
00051 #include <kurl.h>
00052
00053
00054
00055 #include "album.h"
00056 #include "albumdb.h"
00057 #include "albummanager.h"
00058 #include "albumsettings.h"
00059 #include "databaseaccess.h"
00060 #include "albumpropsedit.h"
00061 #include "albumpropsedit.moc"
00062
00063 namespace Digikam
00064 {
00065
00066 class AlbumPropsEditPriv
00067 {
00068
00069 public:
00070
00071 AlbumPropsEditPriv()
00072 {
00073 titleEdit = 0;
00074 collectionCombo = 0;
00075 commentsEdit = 0;
00076 datePicker = 0;
00077 album = 0;
00078 }
00079
00080 QStringList albumCollections;
00081
00082 KComboBox *collectionCombo;
00083
00084 KLineEdit *titleEdit;
00085
00086 KTextEdit *commentsEdit;
00087
00088 KDatePicker *datePicker;
00089
00090 PAlbum *album;
00091 };
00092
00093 AlbumPropsEdit::AlbumPropsEdit(PAlbum* album, bool create)
00094 : KDialog( 0L )
00095 {
00096 setCaption(create ? i18n("New Album") : i18n("Edit Album"));
00097 setButtons(Help|Ok|Cancel);
00098 setDefaultButton(Ok);
00099 setModal(true);
00100 setHelp("albumpropsedit.anchor", "digikam");
00101
00102 d = new AlbumPropsEditPriv;
00103 d->album = album;
00104
00105 QWidget *page = new QWidget(this);
00106 setMainWidget(page);
00107
00108 QGridLayout *topLayout = new QGridLayout(page);
00109
00110 QLabel *topLabel = new QLabel( page );
00111 if (create)
00112 {
00113 topLabel->setText(i18n("<b>Create new Album in \"<i>%1</i>\"</b>", album->title()));
00114 }
00115 else
00116 {
00117 topLabel->setText(i18n("<b>\"<i>%1</i>\" Album Properties</b>", album->title()));
00118 }
00119 topLabel->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
00120 topLabel->setWordWrap(false);
00121
00122
00123
00124 QFrame *topLine = new QFrame(page);
00125 topLine->setFrameShape(QFrame::HLine);
00126 topLine->setFrameShadow(QFrame::Sunken);
00127
00128
00129
00130 QLabel *titleLabel = new QLabel(page);
00131 titleLabel->setText(i18n("&Title:"));
00132
00133 d->titleEdit = new KLineEdit(page);
00134 d->titleEdit->setClearButtonShown(true);
00135 titleLabel->setBuddy(d->titleEdit);
00136
00137 QLabel *collectionLabel = new QLabel(page);
00138 collectionLabel->setText(i18n("Co&llection:"));
00139
00140 d->collectionCombo = new KComboBox(page);
00141 d->collectionCombo->setEditable(true);
00142 collectionLabel->setBuddy(d->collectionCombo);
00143
00144 QLabel *commentsLabel = new QLabel(page);
00145 commentsLabel->setText(i18n("Co&mments:"));
00146
00147 d->commentsEdit = new KTextEdit(page);
00148 commentsLabel->setBuddy(d->commentsEdit);
00149 d->commentsEdit->setCheckSpellingEnabled(true);
00150 d->commentsEdit->setWordWrapMode(QTextOption::WordWrap);
00151
00152 QLabel *dateLabel = new QLabel(page);
00153 dateLabel->setText(i18n("Album &date:"));
00154
00155 d->datePicker = new KDatePicker(page);
00156 dateLabel->setBuddy(d->datePicker);
00157
00158 KHBox *buttonRow = new KHBox(page);
00159 QPushButton *dateLowButton = new QPushButton(i18nc("Selects the date of the oldest image",
00160 "&Oldest"), buttonRow);
00161 QPushButton *dateAvgButton = new QPushButton(i18nc("Calculates the average date",
00162 "&Average"), buttonRow);
00163 QPushButton *dateHighButton = new QPushButton(i18nc("Selects the date of the newest image",
00164 "Newest"), buttonRow);
00165
00166 setTabOrder(d->titleEdit, d->collectionCombo);
00167 setTabOrder(d->collectionCombo, d->commentsEdit);
00168 setTabOrder(d->commentsEdit, d->datePicker);
00169 d->commentsEdit->setTabChangesFocus(true);
00170 d->titleEdit->selectAll();
00171 d->titleEdit->setFocus();
00172
00173
00174
00175 topLayout->addWidget(topLabel, 0, 0, 1, 2);
00176 topLayout->addWidget(topLine, 1, 0, 1, 2);
00177 topLayout->addWidget(titleLabel, 2, 0, 1, 1);
00178 topLayout->addWidget(d->titleEdit, 2, 1, 1, 1);
00179 topLayout->addWidget(collectionLabel, 3, 0, 1, 1);
00180 topLayout->addWidget(d->collectionCombo, 3, 1, 1, 1);
00181 topLayout->addWidget(commentsLabel, 4, 0, 1, 1, Qt::AlignLeft | Qt::AlignTop);
00182 topLayout->addWidget(d->commentsEdit, 4, 1, 1, 1);
00183 topLayout->addWidget(dateLabel, 5, 0, 1, 1, Qt::AlignLeft | Qt::AlignTop);
00184 topLayout->addWidget(d->datePicker, 5, 1, 1, 1);
00185 topLayout->addWidget(buttonRow, 6, 1, 1, 1);
00186 topLayout->setMargin(0);
00187 topLayout->setSpacing(KDialog::spacingHint());
00188
00189
00190
00191 AlbumSettings *settings = AlbumSettings::instance();
00192 if (settings)
00193 {
00194 d->collectionCombo->addItem( QString() );
00195 QStringList collections = settings->getAlbumCollectionNames();
00196 d->collectionCombo->addItems( collections );
00197 int collectionIndex = collections.indexOf( album->collection() );
00198
00199 if ( collectionIndex != -1 )
00200 {
00201
00202 d->collectionCombo->setCurrentIndex(collectionIndex + 1);
00203 }
00204 }
00205
00206 if (create)
00207 {
00208 d->titleEdit->setText( i18n("New Album") );
00209 d->datePicker->setDate( QDate::currentDate() );
00210 }
00211 else
00212 {
00213 d->titleEdit->setText( album->title() );
00214 d->commentsEdit->setText( album->caption() );
00215 d->datePicker->setDate( album->date() );
00216 }
00217
00218
00219
00220 connect(d->titleEdit, SIGNAL(textChanged(const QString&)),
00221 this, SLOT(slotTitleChanged(const QString&)));
00222
00223 connect(dateLowButton, SIGNAL( clicked() ),
00224 this, SLOT( slotDateLowButtonClicked()));
00225
00226 connect(dateAvgButton, SIGNAL( clicked() ),
00227 this, SLOT( slotDateAverageButtonClicked()));
00228
00229 connect(dateHighButton, SIGNAL( clicked() ),
00230 this, SLOT( slotDateHighButtonClicked()));
00231
00232 adjustSize();
00233 }
00234
00235 AlbumPropsEdit::~AlbumPropsEdit()
00236 {
00237 delete d;
00238 }
00239
00240 QString AlbumPropsEdit::title() const
00241 {
00242 return d->titleEdit->text();
00243 }
00244
00245 QString AlbumPropsEdit::comments() const
00246 {
00247 return d->commentsEdit->document()->toPlainText();
00248 }
00249
00250 QDate AlbumPropsEdit::date() const
00251 {
00252 return d->datePicker->date();
00253 }
00254
00255 QString AlbumPropsEdit::collection() const
00256 {
00257 QString name = d->collectionCombo->currentText();
00258
00259 if (name.isEmpty())
00260 {
00261 name = i18n( "Uncategorized Album" );
00262 }
00263
00264 return name;
00265 }
00266
00267 QStringList AlbumPropsEdit::albumCollections() const
00268 {
00269 QStringList collections;
00270 AlbumSettings *settings = AlbumSettings::instance();
00271 if (settings)
00272 {
00273 collections = settings->getAlbumCollectionNames();
00274 }
00275
00276 QString currentCollection = d->collectionCombo->currentText();
00277 if ( collections.indexOf( currentCollection ) == -1 )
00278 {
00279 collections.append(currentCollection);
00280 }
00281
00282 collections.sort();
00283 return collections;
00284 }
00285
00286 bool AlbumPropsEdit::editProps(PAlbum *album, QString& title,
00287 QString& comments, QDate& date, QString& collection,
00288 QStringList& albumCollections)
00289 {
00290 AlbumPropsEdit dlg(album);
00291
00292 bool ok = dlg.exec() == QDialog::Accepted;
00293
00294 title = dlg.title();
00295 comments = dlg.comments();
00296 date = dlg.date();
00297 collection = dlg.collection();
00298 albumCollections = dlg.albumCollections();
00299
00300 return ok;
00301 }
00302
00303 bool AlbumPropsEdit::createNew(PAlbum *parent, QString& title, QString& comments,
00304 QDate& date, QString& collection, QStringList& albumCollections)
00305 {
00306 AlbumPropsEdit dlg(parent, true);
00307
00308 bool ok = dlg.exec() == QDialog::Accepted;
00309
00310 title = dlg.title();
00311 comments = dlg.comments();
00312 date = dlg.date();
00313 collection = dlg.collection();
00314 albumCollections = dlg.albumCollections();
00315
00316 return ok;
00317 }
00318
00319 void AlbumPropsEdit::slotTitleChanged(const QString& newtitle)
00320 {
00321 enableButtonOk(!newtitle.isEmpty());
00322 }
00323
00324 void AlbumPropsEdit::slotDateLowButtonClicked()
00325 {
00326 setCursor( Qt::WaitCursor );
00327
00328 QDate lowDate = DatabaseAccess().db()->getAlbumLowestDate( d->album->id() );
00329
00330 setCursor( Qt::ArrowCursor );
00331
00332 if ( lowDate.isValid() )
00333 d->datePicker->setDate( lowDate );
00334 }
00335
00336 void AlbumPropsEdit::slotDateHighButtonClicked()
00337 {
00338 setCursor( Qt::WaitCursor );
00339
00340 QDate highDate = DatabaseAccess().db()->getAlbumHighestDate( d->album->id() );
00341
00342 setCursor( Qt::ArrowCursor );
00343
00344 if ( highDate.isValid() )
00345 d->datePicker->setDate( highDate );
00346 }
00347
00348 void AlbumPropsEdit::slotDateAverageButtonClicked()
00349 {
00350 setCursor( Qt::WaitCursor );
00351
00352 QDate avDate = DatabaseAccess().db()->getAlbumAverageDate( d->album->id() );
00353
00354 setCursor( Qt::ArrowCursor );
00355
00356 if ( avDate.isValid() )
00357 d->datePicker->setDate( avDate );
00358 else
00359 KMessageBox::error( this,
00360 i18n( "Could not calculate an average."),
00361 i18n( "Could Not Calculate Average" ) );
00362 }
00363
00364 }