1
/* ============================================================
2
* File : albumpropsedit.cpp
3
* Author: Renchi Raju <renchi@pooh.tam.uiuc.edu>
7
* Copyright 2003 by Renchi Raju
9
* This program is free software; you can redistribute it
10
* and/or modify it under the terms of the GNU General
11
* Public License as published bythe Free Software Foundation;
12
* either version 2, or (at your option)
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU General Public License for more details.
20
* ============================================================ */
24
#include <klineeditdlg.h>
26
#include <qgroupbox.h>
29
#include <qcheckbox.h>
30
#include <qlineedit.h>
31
#include <qdatetimeedit.h>
32
#include <qlistview.h>
34
#include <qpushbutton.h>
37
#include <interfaces/albuminfo.h>
39
#include "albumsettings.h"
40
#include "albumpropsedit.h"
42
AlbumPropsEdit::AlbumPropsEdit(const Digikam::AlbumInfo* albumInfo)
43
: KDialogBase( Plain, QString::null, Ok|Cancel, Ok,
46
albumInfo_ = albumInfo;
48
QVBoxLayout *topLayout = new QVBoxLayout( plainPage(),
51
QLabel *topLabel = new QLabel( plainPage() );
52
topLabel->setText( i18n( "Edit '%1' Album Properties").arg(albumInfo->getTitle()));
53
topLayout->addWidget( topLabel );
55
// --------------------------------------------------------
57
QFrame *topLine = new QFrame( plainPage() );
58
topLine->setFrameShape( QFrame::HLine );
59
topLine->setFrameShadow( QFrame::Sunken );
60
topLayout->addWidget( topLine );
62
// --------------------------------------------------------
64
QGroupBox *titleBox = new QGroupBox( plainPage() );
65
titleBox->setTitle( i18n( "Edit Album Description" ) );
66
titleBox->setColumnLayout( 0, Qt::Horizontal );
67
QGridLayout *titleBoxLayout =
68
new QGridLayout( titleBox->layout(), spacingHint() );
70
QLabel *titleLabel = new QLabel( titleBox );
71
titleLabel->setText( i18n( "Title: " ) );
72
titleBoxLayout->addWidget( titleLabel, 0, 0 );
74
titleEdit_ = new QLineEdit( titleBox );
75
titleBoxLayout->addWidget( titleEdit_, 0, 1 );
77
QLabel *commentsLabel = new QLabel( titleBox );
78
commentsLabel->setText( i18n( "Comments: " ) );
79
titleBoxLayout->addWidget( commentsLabel, 2, 0 );
81
commentsEdit_ = new QLineEdit( titleBox );
82
titleBoxLayout->addWidget( commentsEdit_, 2, 1 );
84
topLayout->addWidget( titleBox );
86
// ------------------------------------------------------
88
QGroupBox *dateBox = new QGroupBox( plainPage() );
89
dateBox->setTitle( i18n( "Change Album Date" ) );
90
dateBox->setColumnLayout( 0, Qt::Horizontal );
91
QVBoxLayout *dateBoxLayout =
92
new QVBoxLayout( dateBox->layout(), spacingHint() );
94
dateEdit_ = new QDateEdit( dateBox );
95
dateBoxLayout->addWidget( dateEdit_ );
97
topLayout->addWidget( dateBox );
99
// ------------------------------------------------------
101
QGroupBox *collectionBox = new QGroupBox( plainPage() );
102
collectionBox->setTitle( i18n( "Change Album Collection" ) );
103
collectionBox->setColumnLayout(0, Qt::Horizontal );
104
QGridLayout *collectionBoxLayout =
105
new QGridLayout( collectionBox->layout(), spacingHint() );
107
collectionEdit_ = new QListView( collectionBox );
108
collectionEdit_->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,
109
QSizePolicy::MinimumExpanding));
110
collectionBoxLayout->addMultiCellWidget( collectionEdit_,
113
QPushButton *addCollectionBtn = new QPushButton( i18n("Add"),
115
collectionBoxLayout->addWidget( addCollectionBtn, 0, 1);
117
QPushButton *delCollectionBtn = new QPushButton( i18n("Delete"),
119
collectionBoxLayout->addWidget( delCollectionBtn, 1, 1);
121
topLayout->addWidget( collectionBox );
123
// Initialize ---------------------------------------------
125
populateCollections();
127
titleEdit_->setText( albumInfo->getTitle() );
128
commentsEdit_->setText( albumInfo->getComments() );
129
dateEdit_->setDate( albumInfo->getDate() );
131
QCheckListItem *checkItem =
132
(QCheckListItem*) collectionEdit_->findItem(albumInfo->getCollection(), 0);
133
if (checkItem) checkItem->setOn(true);
135
// Connections -------------------------------------------
137
connect(addCollectionBtn, SIGNAL(clicked()),
138
this, SLOT(slotAddCollection()));
140
connect(delCollectionBtn, SIGNAL(clicked()),
141
this, SLOT(slotDelCollection()));
146
AlbumPropsEdit::~AlbumPropsEdit()
150
void AlbumPropsEdit::populateCollections()
152
AlbumSettings *settings = AlbumSettings::instance();
153
if (!settings) return;
155
collectionEdit_->addColumn("Collections");
156
collectionEdit_->header()->hide();
157
collectionEdit_->setColumnWidthMode(0, QListView::Maximum);
159
rootCollectionItem_ =
160
new QCheckListItem(collectionEdit_, i18n("Collections"));
161
rootCollectionItem_->setSelectable(false);
162
rootCollectionItem_->setOpen(true);
164
albumCollections_ = settings->getAlbumCollectionNames();
165
for (QStringList::const_iterator it = albumCollections_.begin();
166
it != albumCollections_.end(); ++it ) {
167
new QCheckListItem(rootCollectionItem_, *it,
168
QCheckListItem::RadioButton);
173
QString AlbumPropsEdit::title() const
175
return titleEdit_->text();
178
QString AlbumPropsEdit::comments() const
180
return commentsEdit_->text();
183
QDate AlbumPropsEdit::date() const
185
return dateEdit_->date();
188
QString AlbumPropsEdit::collection() const
192
QListViewItemIterator it(collectionEdit_);
193
for ( ; it.current(); ++it) {
194
QCheckListItem *item =
195
(QCheckListItem*)(it.current());
196
if (item->type() == QCheckListItem::RadioButton &&
202
if (name.isNull()) name = i18n( "Unknown" );
207
QStringList AlbumPropsEdit::albumCollections() const
209
return albumCollections_;
212
void AlbumPropsEdit::slotAddCollection()
215
QString newCollection = KLineEditDlg::getText(i18n("Enter New Collection Name: "), "", &ok, this);
218
if (!albumCollections_.contains(newCollection)) {
219
new QCheckListItem(rootCollectionItem_, newCollection,
220
QCheckListItem::RadioButton);
221
albumCollections_.append(newCollection);
225
void AlbumPropsEdit::slotDelCollection()
227
QListViewItem *item = collectionEdit_->selectedItem();
230
QCheckListItem *checkItem = (QCheckListItem*) item;
231
if (!checkItem || checkItem == rootCollectionItem_)
234
albumCollections_.remove(checkItem->text(0));
238
bool AlbumPropsEdit::editProps(const Digikam::AlbumInfo *albumInfo, QString& title,
239
QString& comments, QDate& date, QString& collection,
240
QStringList& albumCollections)
242
AlbumPropsEdit dlg(albumInfo);
244
bool ok = dlg.exec() == QDialog::Accepted;
247
comments = dlg.comments();
249
collection = dlg.collection();
250
albumCollections = dlg.albumCollections();