~ubuntu-branches/ubuntu/saucy/digikam/saucy

« back to all changes in this revision

Viewing changes to digikam/albummodificationhelper.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Christian Mangold
  • Date: 2010-04-09 21:30:01 UTC
  • mfrom: (1.2.28 upstream)
  • Revision ID: james.westby@ubuntu.com-20100409213001-4bfyibrd359rn7o3
Tags: 2:1.2.0-0ubuntu1
* New upstream release (LP: #560576)
* Remove all patches, fixed upstream
  - Remove quilt build-depend

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ============================================================
 
2
 *
 
3
 * This file is a part of digiKam project
 
4
 * http://www.digikam.org
 
5
 *
 
6
 * Date        : 2000-12-05
 
7
 * Description : helper class used to modify physical albums in views
 
8
 *
 
9
 * Copyright (C) 2009 by Johannes Wienke <languitar at semipol dot de>
 
10
 *
 
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)
 
15
 * any later version.
 
16
 *
 
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.
 
21
 *
 
22
 * ============================================================ */
 
23
 
 
24
#include "albummodificationhelper.moc"
 
25
 
 
26
// KDE includes
 
27
#include <kdebug.h>
 
28
#include <kinputdialog.h>
 
29
#include <kio/jobuidelegate.h>
 
30
#include <klocale.h>
 
31
#include <kmessagebox.h>
 
32
#include <kurl.h>
 
33
 
 
34
// Local includes
 
35
#include "albummanager.h"
 
36
#include "albumpropsedit.h"
 
37
#include "albumsettings.h"
 
38
#include "collectionmanager.h"
 
39
#include "deletedialog.h"
 
40
#include "dio.h"
 
41
 
 
42
namespace Digikam
 
43
{
 
44
 
 
45
class AlbumModificationHelperPriv
 
46
{
 
47
public:
 
48
    QWidget *dialogParent;
 
49
};
 
50
 
 
51
AlbumModificationHelper::AlbumModificationHelper(QObject *parent,
 
52
                QWidget *dialogParent) :
 
53
    QObject(parent), d(new AlbumModificationHelperPriv)
 
54
{
 
55
    d->dialogParent = dialogParent;
 
56
}
 
57
 
 
58
AlbumModificationHelper::~AlbumModificationHelper()
 
59
{
 
60
    delete d;
 
61
}
 
62
 
 
63
PAlbum *AlbumModificationHelper::slotAlbumNew(PAlbum *parent)
 
64
{
 
65
    AlbumSettings* settings = AlbumSettings::instance();
 
66
    if(!settings)
 
67
    {
 
68
        kWarning() << "could not get Album Settings";
 
69
        return 0;
 
70
    }
 
71
 
 
72
    /*
 
73
    QDir libraryDir(settings->getAlbumLibraryPath());
 
74
    if(!libraryDir.exists())
 
75
    {
 
76
        KMessageBox::error(0,
 
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 "
 
80
                                "library."));
 
81
        return;
 
82
    }
 
83
    */
 
84
 
 
85
    // if we create an album under root, need to supply the album root path.
 
86
    QString albumRootPath;
 
87
    if (parent->isRoot())
 
88
    {
 
89
        //TODO: Let user choose an album root
 
90
        albumRootPath = CollectionManager::instance()->oneAlbumRootPath();
 
91
    }
 
92
 
 
93
    QString     title;
 
94
    QString     comments;
 
95
    QString     category;
 
96
    QDate       date;
 
97
    QStringList albumCategories;
 
98
 
 
99
    if(!AlbumPropsEdit::createNew(parent, title, comments, date, category,
 
100
                                  albumCategories))
 
101
    {
 
102
        return 0;
 
103
    }
 
104
 
 
105
    QStringList oldAlbumCategories(AlbumSettings::instance()->getAlbumCategoryNames());
 
106
    if(albumCategories != oldAlbumCategories)
 
107
    {
 
108
        AlbumSettings::instance()->setAlbumCategoryNames(albumCategories);
 
109
    }
 
110
 
 
111
    QString errMsg;
 
112
    PAlbum* album;
 
113
    if (parent->isRoot())
 
114
    {
 
115
        album = AlbumManager::instance()->createPAlbum(albumRootPath, title, comments,
 
116
                                          date, category, errMsg);
 
117
    }
 
118
    else
 
119
    {
 
120
        album = AlbumManager::instance()->createPAlbum(parent, title, comments,
 
121
                                          date, category, errMsg);
 
122
    }
 
123
 
 
124
    if (!album)
 
125
    {
 
126
        KMessageBox::error(0, errMsg);
 
127
        return 0;
 
128
    }
 
129
 
 
130
    return album;
 
131
 
 
132
}
 
133
 
 
134
void AlbumModificationHelper::slotAlbumDelete(PAlbum *album)
 
135
{
 
136
 
 
137
    if(!album || album->isRoot() || album->isAlbumRoot())
 
138
        return;
 
139
 
 
140
    // find subalbums
 
141
    KUrl::List childrenList;
 
142
    addAlbumChildrenToList(childrenList, album);
 
143
 
 
144
    DeleteDialog dialog(d->dialogParent);
 
145
 
 
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))
 
151
        return;
 
152
 
 
153
    bool useTrash = !dialog.shouldDelete();
 
154
 
 
155
    // Currently trash kioslave can handle only full paths.
 
156
    // pass full folder path to the trashing job
 
157
    //TODO: Use digikamalbums:// url?
 
158
    KUrl u;
 
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 *)));
 
164
 
 
165
}
 
166
 
 
167
void AlbumModificationHelper::slotAlbumRename(PAlbum *album)
 
168
{
 
169
 
 
170
    if (!album)
 
171
    {
 
172
        return;
 
173
    }
 
174
 
 
175
    QString oldTitle(album->title());
 
176
    bool    ok;
 
177
 
 
178
    QString title = KInputDialog::getText(i18n("Rename Album (%1)", oldTitle),
 
179
                                          i18n("Enter new album name:"),
 
180
                                          oldTitle, &ok, d->dialogParent);
 
181
    if (!ok)
 
182
    {
 
183
        return;
 
184
    }
 
185
 
 
186
    if(title != oldTitle)
 
187
    {
 
188
        QString errMsg;
 
189
        if (!AlbumManager::instance()->renamePAlbum(album, title, errMsg))
 
190
            KMessageBox::error(0, errMsg);
 
191
    }
 
192
 
 
193
}
 
194
 
 
195
void AlbumModificationHelper::addAlbumChildrenToList(KUrl::List& list, Album *album)
 
196
{
 
197
    // simple recursive helper function
 
198
    if (album)
 
199
    {
 
200
        list.append(album->databaseUrl());
 
201
        AlbumIterator it(album);
 
202
        while(it.current())
 
203
        {
 
204
            addAlbumChildrenToList(list, *it);
 
205
            ++it;
 
206
        }
 
207
    }
 
208
 
 
209
}
 
210
 
 
211
void AlbumModificationHelper::slotDIOResult(KJob* kjob)
 
212
{
 
213
    KIO::Job *job = static_cast<KIO::Job*>(kjob);
 
214
    if (job->error())
 
215
    {
 
216
        job->ui()->setWindow(d->dialogParent);
 
217
        job->ui()->showErrorMessage();
 
218
    }
 
219
}
 
220
 
 
221
void AlbumModificationHelper::slotAlbumEdit(PAlbum *album)
 
222
{
 
223
 
 
224
    if (!album || album->isRoot() || album->isAlbumRoot())
 
225
    {
 
226
        return;
 
227
    }
 
228
 
 
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());
 
234
 
 
235
    QString     title, comments, category;
 
236
    QDate       date;
 
237
    QStringList albumCategories;
 
238
 
 
239
    if(AlbumPropsEdit::editProps(album, title, comments, date,
 
240
                                 category, albumCategories))
 
241
    {
 
242
        if(comments != oldComments)
 
243
        {
 
244
            album->setCaption(comments);
 
245
        }
 
246
 
 
247
        if(date != oldDate && date.isValid())
 
248
        {
 
249
            album->setDate(date);
 
250
        }
 
251
 
 
252
        if(category != oldCategory)
 
253
        {
 
254
            album->setCategory(category);
 
255
        }
 
256
 
 
257
        AlbumSettings::instance()->setAlbumCategoryNames(albumCategories);
 
258
 
 
259
        // Do this last : so that if anything else changed we can
 
260
        // successfuly save to the db with the old name
 
261
 
 
262
        if(title != oldTitle)
 
263
        {
 
264
            QString errMsg;
 
265
            if (!AlbumManager::instance()->renamePAlbum(album, title, errMsg))
 
266
            {
 
267
                KMessageBox::error(d->dialogParent, errMsg);
 
268
            }
 
269
        }
 
270
 
 
271
    }
 
272
 
 
273
}
 
274
 
 
275
}