~ubuntu-branches/ubuntu/edgy/digikam/edgy-updates

« back to all changes in this revision

Viewing changes to digikam/albumpropsedit.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Achim Bohnet
  • Date: 2005-03-10 02:39:02 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 hoary)
  • Revision ID: james.westby@ubuntu.com-20050310023902-023nymfst5mg696c
Tags: 0.7.2-2
* debian/TODO: clean
* digikam manpage: better --detect-camera description

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* ============================================================
2
 
 * File  : albumpropsedit.cpp
3
 
 * Author: Renchi Raju <renchi@pooh.tam.uiuc.edu>
4
 
 * Date  : 2003-03-09
5
 
 * Description :
6
 
 *
7
 
 * Copyright 2003 by Renchi Raju
8
 
 *
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)
13
 
 * any later version.
14
 
 *
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.
19
 
 *
20
 
 * ============================================================ */
21
 
 
22
 
#include <klocale.h>
23
 
#include <kurl.h>
24
 
#include <klineeditdlg.h>
25
 
 
26
 
#include <qgroupbox.h>
27
 
#include <qlayout.h>
28
 
#include <qlabel.h>
29
 
#include <qcheckbox.h>
30
 
#include <qlineedit.h>
31
 
#include <qdatetimeedit.h>
32
 
#include <qlistview.h>
33
 
#include <qframe.h>
34
 
#include <qpushbutton.h>
35
 
#include <qheader.h>
36
 
 
37
 
#include <interfaces/albuminfo.h>
38
 
 
39
 
#include "albumsettings.h"
40
 
#include "albumpropsedit.h"
41
 
 
42
 
AlbumPropsEdit::AlbumPropsEdit(const Digikam::AlbumInfo* albumInfo)
43
 
    : KDialogBase( Plain, QString::null, Ok|Cancel, Ok,
44
 
                   0, 0, true, true )
45
 
{
46
 
    albumInfo_ = albumInfo;
47
 
    
48
 
    QVBoxLayout *topLayout = new QVBoxLayout( plainPage(),
49
 
                                              0, spacingHint() );
50
 
 
51
 
    QLabel *topLabel = new QLabel( plainPage() );
52
 
    topLabel->setText( i18n( "Edit '%1' Album Properties").arg(albumInfo->getTitle()));
53
 
    topLayout->addWidget( topLabel  );
54
 
 
55
 
    // --------------------------------------------------------
56
 
 
57
 
    QFrame *topLine = new QFrame( plainPage() );
58
 
    topLine->setFrameShape( QFrame::HLine );
59
 
    topLine->setFrameShadow( QFrame::Sunken );
60
 
    topLayout->addWidget( topLine );
61
 
 
62
 
    // --------------------------------------------------------
63
 
    
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() );
69
 
                                                   
70
 
    QLabel *titleLabel = new QLabel( titleBox );
71
 
    titleLabel->setText( i18n( "Title: " ) );
72
 
    titleBoxLayout->addWidget( titleLabel, 0, 0 );
73
 
 
74
 
    titleEdit_ = new QLineEdit( titleBox );
75
 
    titleBoxLayout->addWidget( titleEdit_, 0, 1 );
76
 
 
77
 
    QLabel *commentsLabel = new QLabel( titleBox );
78
 
    commentsLabel->setText( i18n( "Comments: " ) );
79
 
    titleBoxLayout->addWidget( commentsLabel, 2, 0 );
80
 
 
81
 
    commentsEdit_ = new QLineEdit( titleBox );
82
 
    titleBoxLayout->addWidget( commentsEdit_, 2, 1 );
83
 
    
84
 
    topLayout->addWidget( titleBox );
85
 
 
86
 
    // ------------------------------------------------------
87
 
 
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() );
93
 
 
94
 
    dateEdit_ = new QDateEdit( dateBox );
95
 
    dateBoxLayout->addWidget( dateEdit_ );
96
 
 
97
 
    topLayout->addWidget( dateBox );
98
 
 
99
 
    // ------------------------------------------------------
100
 
 
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() );
106
 
 
107
 
    collectionEdit_ = new QListView( collectionBox );
108
 
    collectionEdit_->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,
109
 
                                               QSizePolicy::MinimumExpanding));
110
 
    collectionBoxLayout->addMultiCellWidget( collectionEdit_,
111
 
                                             0, 2, 0, 0 );
112
 
 
113
 
    QPushButton *addCollectionBtn = new QPushButton( i18n("Add"),
114
 
                                                     collectionBox );
115
 
    collectionBoxLayout->addWidget( addCollectionBtn, 0, 1);
116
 
    
117
 
    QPushButton *delCollectionBtn = new QPushButton( i18n("Delete"),
118
 
                                                     collectionBox );
119
 
    collectionBoxLayout->addWidget( delCollectionBtn, 1, 1);
120
 
 
121
 
    topLayout->addWidget( collectionBox );
122
 
        
123
 
    // Initialize ---------------------------------------------
124
 
 
125
 
    populateCollections();
126
 
 
127
 
    titleEdit_->setText( albumInfo->getTitle() );
128
 
    commentsEdit_->setText( albumInfo->getComments() );
129
 
    dateEdit_->setDate( albumInfo->getDate() );
130
 
 
131
 
    QCheckListItem *checkItem =
132
 
        (QCheckListItem*) collectionEdit_->findItem(albumInfo->getCollection(), 0);
133
 
    if (checkItem) checkItem->setOn(true);
134
 
 
135
 
    // Connections -------------------------------------------
136
 
 
137
 
    connect(addCollectionBtn, SIGNAL(clicked()),
138
 
            this, SLOT(slotAddCollection()));
139
 
 
140
 
    connect(delCollectionBtn, SIGNAL(clicked()),
141
 
            this, SLOT(slotDelCollection()));
142
 
    
143
 
    resize(500, 400);
144
 
}
145
 
 
146
 
AlbumPropsEdit::~AlbumPropsEdit()
147
 
{
148
 
}
149
 
 
150
 
void AlbumPropsEdit::populateCollections()
151
 
{
152
 
    AlbumSettings *settings = AlbumSettings::instance();
153
 
    if (!settings) return;
154
 
 
155
 
    collectionEdit_->addColumn("Collections");
156
 
    collectionEdit_->header()->hide();
157
 
    collectionEdit_->setColumnWidthMode(0, QListView::Maximum);
158
 
 
159
 
    rootCollectionItem_ =
160
 
        new QCheckListItem(collectionEdit_, i18n("Collections"));
161
 
    rootCollectionItem_->setSelectable(false);
162
 
    rootCollectionItem_->setOpen(true);
163
 
    
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);
169
 
    }
170
 
    
171
 
}
172
 
 
173
 
QString AlbumPropsEdit::title() const
174
 
{
175
 
    return titleEdit_->text();    
176
 
}
177
 
 
178
 
QString AlbumPropsEdit::comments() const
179
 
{
180
 
    return commentsEdit_->text();
181
 
}
182
 
 
183
 
QDate AlbumPropsEdit::date() const
184
 
{
185
 
    return dateEdit_->date();
186
 
}
187
 
 
188
 
QString AlbumPropsEdit::collection() const
189
 
{
190
 
    QString name;
191
 
 
192
 
    QListViewItemIterator it(collectionEdit_);
193
 
    for ( ; it.current(); ++it) {
194
 
        QCheckListItem *item =
195
 
            (QCheckListItem*)(it.current());
196
 
        if (item->type() == QCheckListItem::RadioButton &&
197
 
            item->isOn()) {
198
 
            name = item->text();
199
 
        }
200
 
    }
201
 
 
202
 
    if (name.isNull()) name = i18n( "Unknown" );
203
 
    
204
 
    return name;
205
 
}
206
 
 
207
 
QStringList AlbumPropsEdit::albumCollections() const
208
 
{
209
 
    return albumCollections_;    
210
 
}
211
 
 
212
 
void AlbumPropsEdit::slotAddCollection()
213
 
{
214
 
    bool ok;
215
 
    QString newCollection = KLineEditDlg::getText(i18n("Enter New Collection Name: "), "", &ok, this);
216
 
    if (!ok) return;
217
 
 
218
 
    if (!albumCollections_.contains(newCollection)) {
219
 
        new QCheckListItem(rootCollectionItem_, newCollection,
220
 
                           QCheckListItem::RadioButton);
221
 
        albumCollections_.append(newCollection);
222
 
    }
223
 
}
224
 
 
225
 
void AlbumPropsEdit::slotDelCollection()
226
 
{
227
 
    QListViewItem *item = collectionEdit_->selectedItem();
228
 
    if (!item) return;    
229
 
 
230
 
    QCheckListItem *checkItem = (QCheckListItem*) item;
231
 
    if (!checkItem || checkItem == rootCollectionItem_)
232
 
        return;
233
 
 
234
 
    albumCollections_.remove(checkItem->text(0));
235
 
    delete checkItem;
236
 
}
237
 
 
238
 
bool AlbumPropsEdit::editProps(const Digikam::AlbumInfo *albumInfo, QString& title,
239
 
                               QString& comments, QDate& date, QString& collection,
240
 
                               QStringList& albumCollections)
241
 
{
242
 
    AlbumPropsEdit dlg(albumInfo);
243
 
 
244
 
    bool ok = dlg.exec() == QDialog::Accepted;
245
 
 
246
 
    title            = dlg.title();
247
 
    comments         = dlg.comments();
248
 
    date             = dlg.date();
249
 
    collection       = dlg.collection();
250
 
    albumCollections = dlg.albumCollections();
251
 
 
252
 
    return ok;
253
 
}
254