1
/* ============================================================
3
* This file is a part of digiKam project
4
* http://www.digikam.org
7
* Description : helper class used to modify physical albums in views
9
* Copyright (C) 2009 by Johannes Wienke <languitar at semipol dot de>
11
* This program is free software; you can redistribute it
12
* and/or modify it under the terms of the GNU General
13
* Public License as published by the Free Software Foundation;
14
* either version 2, or (at your option)
17
* This program is distributed in the hope that it will be useful,
18
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
* GNU General Public License for more details.
22
* ============================================================ */
24
#include "albummodificationhelper.moc"
28
#include <kinputdialog.h>
29
#include <kio/jobuidelegate.h>
31
#include <kmessagebox.h>
35
#include "albummanager.h"
36
#include "albumpropsedit.h"
37
#include "albumsettings.h"
38
#include "collectionmanager.h"
39
#include "deletedialog.h"
45
class AlbumModificationHelperPriv
48
QWidget *dialogParent;
51
AlbumModificationHelper::AlbumModificationHelper(QObject *parent,
52
QWidget *dialogParent) :
53
QObject(parent), d(new AlbumModificationHelperPriv)
55
d->dialogParent = dialogParent;
58
AlbumModificationHelper::~AlbumModificationHelper()
63
PAlbum *AlbumModificationHelper::slotAlbumNew(PAlbum *parent)
65
AlbumSettings* settings = AlbumSettings::instance();
68
kWarning() << "could not get Album Settings";
73
QDir libraryDir(settings->getAlbumLibraryPath());
74
if(!libraryDir.exists())
77
i18n("The album library has not been set correctly.\n"
78
"Select \"Configure Digikam\" from the Settings "
79
"menu and choose a folder to use for the album "
85
// if we create an album under root, need to supply the album root path.
86
QString albumRootPath;
89
//TODO: Let user choose an album root
90
albumRootPath = CollectionManager::instance()->oneAlbumRootPath();
97
QStringList albumCategories;
99
if(!AlbumPropsEdit::createNew(parent, title, comments, date, category,
105
QStringList oldAlbumCategories(AlbumSettings::instance()->getAlbumCategoryNames());
106
if(albumCategories != oldAlbumCategories)
108
AlbumSettings::instance()->setAlbumCategoryNames(albumCategories);
113
if (parent->isRoot())
115
album = AlbumManager::instance()->createPAlbum(albumRootPath, title, comments,
116
date, category, errMsg);
120
album = AlbumManager::instance()->createPAlbum(parent, title, comments,
121
date, category, errMsg);
126
KMessageBox::error(0, errMsg);
134
void AlbumModificationHelper::slotAlbumDelete(PAlbum *album)
137
if(!album || album->isRoot() || album->isAlbumRoot())
141
KUrl::List childrenList;
142
addAlbumChildrenToList(childrenList, album);
144
DeleteDialog dialog(d->dialogParent);
146
// All subalbums will be presented in the list as well
147
if (!dialog.confirmDeleteList(childrenList,
148
childrenList.size() == 1 ?
149
DeleteDialogMode::Albums : DeleteDialogMode::Subalbums,
150
DeleteDialogMode::UserPreference))
153
bool useTrash = !dialog.shouldDelete();
155
// Currently trash kioslave can handle only full paths.
156
// pass full folder path to the trashing job
157
//TODO: Use digikamalbums:// url?
159
u.setProtocol("file");
160
u.setPath(album->folderPath());
161
KIO::Job* job = DIO::del(u, useTrash);
162
connect(job, SIGNAL(result(KJob *)),
163
this, SLOT(slotDIOResult(KJob *)));
167
void AlbumModificationHelper::slotAlbumRename(PAlbum *album)
175
QString oldTitle(album->title());
178
QString title = KInputDialog::getText(i18n("Rename Album (%1)", oldTitle),
179
i18n("Enter new album name:"),
180
oldTitle, &ok, d->dialogParent);
186
if(title != oldTitle)
189
if (!AlbumManager::instance()->renamePAlbum(album, title, errMsg))
190
KMessageBox::error(0, errMsg);
195
void AlbumModificationHelper::addAlbumChildrenToList(KUrl::List& list, Album *album)
197
// simple recursive helper function
200
list.append(album->databaseUrl());
201
AlbumIterator it(album);
204
addAlbumChildrenToList(list, *it);
211
void AlbumModificationHelper::slotDIOResult(KJob* kjob)
213
KIO::Job *job = static_cast<KIO::Job*>(kjob);
216
job->ui()->setWindow(d->dialogParent);
217
job->ui()->showErrorMessage();
221
void AlbumModificationHelper::slotAlbumEdit(PAlbum *album)
224
if (!album || album->isRoot() || album->isAlbumRoot())
229
QString oldTitle(album->title());
230
QString oldComments(album->caption());
231
QString oldCategory(album->category());
232
QDate oldDate(album->date());
233
QStringList oldAlbumCategories(AlbumSettings::instance()->getAlbumCategoryNames());
235
QString title, comments, category;
237
QStringList albumCategories;
239
if(AlbumPropsEdit::editProps(album, title, comments, date,
240
category, albumCategories))
242
if(comments != oldComments)
244
album->setCaption(comments);
247
if(date != oldDate && date.isValid())
249
album->setDate(date);
252
if(category != oldCategory)
254
album->setCategory(category);
257
AlbumSettings::instance()->setAlbumCategoryNames(albumCategories);
259
// Do this last : so that if anything else changed we can
260
// successfuly save to the db with the old name
262
if(title != oldTitle)
265
if (!AlbumManager::instance()->renamePAlbum(album, title, errMsg))
267
KMessageBox::error(d->dialogParent, errMsg);