~ubuntu-branches/ubuntu/jaunty/digikam/jaunty

« back to all changes in this revision

Viewing changes to utilities/kipiiface/kipiuploadwidget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Luka Renko
  • Date: 2009-01-21 21:55:15 UTC
  • mfrom: (1.2.18 upstream)
  • Revision ID: james.westby@ubuntu.com-20090121215515-lry0s2pdep289o3u
Tags: 2:0.10.0~rc1-0ubuntu1
* New upstream release (release candididate 1)
* rules:
  - Simplify by including standard class/kde4.mk
* control:
  - Build-Depends on quilt (default patch system of kde4.mk)
  - Bump Standards-Version to 3.8.0
  - Bump debhelper dependancy to 7
  - Add ${misc:Depends} to make lintian happy
* {digikam|showfoto}.install:
  - Update icon paths
  - Do not package oxygen and apps icons: provided by kde-icons-oxygen
* patches/01-kubuntu-fix-armel.patch:
  - Fix cut&paste bug in the patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 *               to upload new items using digiKam album folder views
9
9
 *
10
10
 * Copyright (C) 2008 by Gilles Caulier <caulier dot gilles at gmail dot com>
 
11
 * Copyright (C) 2009 by Luka Renko <lure at kubuntu dot org>
11
12
 *
12
13
 * This program is free software; you can redistribute it
13
14
 * and/or modify it under the terms of the GNU General
29
30
 
30
31
#include <QHeaderView>
31
32
#include <QTreeWidget>
32
 
#include <QHBoxLayout>
 
33
#include <QGridLayout>
33
34
 
34
35
// KDE includes.
35
36
 
36
37
#include <kdialog.h>
37
38
#include <kdebug.h>
38
39
#include <klocale.h>
 
40
#include <kpushbutton.h>
 
41
#include <kmessagebox.h>
 
42
#include <kinputdialog.h>
39
43
 
40
44
// Local includes.
41
45
 
44
48
#include "albummanager.h"
45
49
#include "albumthumbnailloader.h"
46
50
#include "treefolderitem.h"
 
51
#include "collectionmanager.h"
47
52
#include "kipiinterface.h"
48
53
#include "kipiimagecollection.h"
49
54
 
59
64
        albumsView = 0;
60
65
        iface      = 0;
61
66
        searchBar  = 0;
 
67
        newAlbumBtn= 0;
62
68
    }
63
69
 
64
70
    QTreeWidget   *albumsView;
66
72
    KipiInterface *iface;
67
73
 
68
74
    SearchTextBar *searchBar;
 
75
 
 
76
    KPushButton   *newAlbumBtn;
69
77
};
70
78
 
71
79
KipiUploadWidget::KipiUploadWidget(KipiInterface* iface, QWidget *parent)
81
89
 
82
90
    d->searchBar      = new SearchTextBar(this, "KipiUploadWidgetSearchBar");
83
91
 
84
 
    QVBoxLayout *vlay = new QVBoxLayout(this);
85
 
    vlay->addWidget(d->albumsView, 10);
86
 
    vlay->addWidget(d->searchBar);
87
 
    vlay->setMargin(0);
88
 
    vlay->setSpacing(KDialog::spacingHint());
 
92
    d->newAlbumBtn    = new KPushButton(
 
93
                        KGuiItem(i18n("&New Album"), "albumfolder-new",
 
94
                                 i18n("Create new album")), this);
 
95
 
 
96
    QGridLayout *grid = new QGridLayout(this);
 
97
    grid->addWidget(d->albumsView,   0, 0, 10, 5);
 
98
    grid->addWidget(d->searchBar,   10, 0, 1, 4);
 
99
    grid->addWidget(d->newAlbumBtn, 10, 4, 1, 1);
 
100
    grid->setMargin(0);
 
101
    grid->setSpacing(KDialog::spacingHint());
89
102
 
90
103
    // ------------------------------------------------------------------------------------
91
104
 
93
106
 
94
107
    // ------------------------------------------------------------------------------------
95
108
 
 
109
    connect(AlbumManager::instance(), SIGNAL(signalAlbumAdded(Album*)),
 
110
            this, SLOT(slotAlbumAdded(Album*)));
 
111
 
96
112
    connect(d->albumsView, SIGNAL(itemSelectionChanged()),
97
113
            this, SIGNAL(selectionChanged()));
98
114
 
99
115
    connect(d->searchBar, SIGNAL(signalSearchTextSettings(const SearchTextSettings&)),
100
116
            this, SLOT(slotSearchTextChanged(const SearchTextSettings&)));
 
117
 
 
118
    connect(d->newAlbumBtn, SIGNAL(clicked()),
 
119
            this, SLOT(slotNewAlbum()));
101
120
}
102
121
 
103
122
KipiUploadWidget::~KipiUploadWidget()
230
249
    d->searchBar->slotSearchResult(atleastOneMatch);
231
250
}
232
251
 
 
252
void KipiUploadWidget::slotNewAlbum()
 
253
{
 
254
    QTreeWidgetItem* item = d->albumsView->currentItem();
 
255
    if (!item)
 
256
        item = d->albumsView->topLevelItem(0);
 
257
 
 
258
    if (!item)
 
259
        return;
 
260
 
 
261
    TreeAlbumItem* viewItem = dynamic_cast<TreeAlbumItem*>(item);
 
262
    if (!viewItem)
 
263
        return;
 
264
 
 
265
    PAlbum* album = dynamic_cast<PAlbum*>(viewItem->album());
 
266
    if (!album)
 
267
        return;
 
268
 
 
269
    bool ok;
 
270
    QString newAlbumName = KInputDialog::getText(i18n("New Album Name"),
 
271
                                                 i18n("Creating new album in '%1'\n"
 
272
                                                      "Enter album name:",
 
273
                                                      album->prettyUrl()),
 
274
                                                 QString(), &ok, this);
 
275
    if (!ok)
 
276
        return;
 
277
 
 
278
    PAlbum *newAlbum;
 
279
    QString errMsg;
 
280
    if (album->isRoot())
 
281
    {
 
282
        // if we create an album under root, need to supply the album root path.
 
283
        // TODO: Let user choose an album root
 
284
        newAlbum = AlbumManager::instance()->createPAlbum(CollectionManager::instance()->oneAlbumRootPath(),
 
285
                                                          newAlbumName, QString(), QDate::currentDate(), QString(), errMsg);
 
286
    }
 
287
    else
 
288
    {
 
289
        newAlbum = AlbumManager::instance()->createPAlbum(album, newAlbumName, QString(),
 
290
                                                          QDate::currentDate(), QString(), errMsg);
 
291
    }
 
292
 
 
293
    if (!newAlbum)
 
294
    {
 
295
        KMessageBox::error(this, errMsg);
 
296
        return;
 
297
    }
 
298
 
 
299
    TreeAlbumItem* newItem = (TreeAlbumItem*)newAlbum->extraData(d->albumsView);
 
300
    if (newItem)
 
301
    {
 
302
        d->albumsView->scrollToItem(newItem);
 
303
        d->albumsView->setCurrentItem(newItem);
 
304
        newItem->setSelected(true);
 
305
    }
 
306
}
 
307
 
 
308
void KipiUploadWidget::slotAlbumAdded(Album* album)
 
309
{
 
310
    if (!album || album->type() != Album::PHYSICAL)
 
311
        return;
 
312
 
 
313
    TreeAlbumItem* parentItem = (TreeAlbumItem*)(album->parent()->extraData(d->albumsView));
 
314
 
 
315
    if (!parentItem)
 
316
    {
 
317
        kWarning(50003) << "Failed to find parent for Album "
 
318
                        << album->title() << endl;
 
319
        return;
 
320
    }
 
321
 
 
322
    TreeAlbumItem* item = new TreeAlbumItem(parentItem, album);
 
323
    PAlbum* palbum      = dynamic_cast<PAlbum*>(album);
 
324
    if (palbum)
 
325
        item->setIcon(0, AlbumThumbnailLoader::instance()->getStandardAlbumIcon(palbum));
 
326
}
 
327
 
233
328
}  // namespace Digikam