1 | // vim: set tabstop=4 shiftwidth=4 noexpandtab: |
2 | /* |
3 | Copyright 2010 Pau Garcia i Quiles <pgquiles@elpauer.org> |
4 | based on code for Gwenview by |
5 | Copyright 2008 Aurélien Gâteau <agateau@kde.org> |
6 | |
7 | This program is free software; you can redistribute it and/or |
8 | modify it under the terms of the GNU General Public License |
9 | as published by the Free Software Foundation; either version 2 |
10 | of the License, or (at your option) any later version. |
11 | |
12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | GNU General Public License for more details. |
16 | |
17 | You should have received a copy of the GNU General Public License |
18 | along with this program; if not, write to the Free Software |
19 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA. |
20 | |
21 | */ |
22 | // Self |
23 | #include "kipiimagecollectionselector.moc" |
24 | |
25 | // Qt |
26 | #include <QListWidget> |
27 | #include <QVBoxLayout> |
28 | |
29 | // KDE |
30 | #include <klocale.h> |
31 | |
32 | // Local |
33 | |
34 | struct KIPIImageCollectionSelectorPrivate { |
35 | KIPIInterface* mInterface; |
36 | QListWidget* mListWidget; |
37 | }; |
38 | |
39 | |
40 | KIPIImageCollectionSelector::KIPIImageCollectionSelector(KIPIInterface* interface, QWidget* parent) |
41 | : KIPI::ImageCollectionSelector(parent) |
42 | , d(new KIPIImageCollectionSelectorPrivate) { |
43 | d->mInterface = interface; |
44 | |
45 | d->mListWidget = new QListWidget; |
46 | QList<KIPI::ImageCollection> list = interface->allAlbums(); |
47 | Q_FOREACH(const KIPI::ImageCollection& collection, list) { |
48 | QListWidgetItem* item = new QListWidgetItem(d->mListWidget); |
49 | QString name = collection.name(); |
50 | int imageCount = collection.images().size(); |
51 | QString title = i18ncp("%1 is collection name, %2 is image count in collection" , |
52 | "%1 (%2 image)" , "%1 (%2 images)" , name, imageCount); |
53 | |
54 | item->setText(title); |
55 | item->setData(Qt::UserRole, name); |
56 | } |
57 | |
58 | connect(d->mListWidget, SIGNAL(currentRowChanged(int)), |
59 | SIGNAL(selectionChanged()) ); |
60 | |
61 | QVBoxLayout* layout = new QVBoxLayout(this); |
62 | layout->addWidget(d->mListWidget); |
63 | layout->setMargin(0); |
64 | } |
65 | |
66 | |
67 | KIPIImageCollectionSelector::~KIPIImageCollectionSelector() { |
68 | delete d; |
69 | } |
70 | |
71 | |
72 | |
73 | QList<KIPI::ImageCollection> KIPIImageCollectionSelector::selectedImageCollections() const { |
74 | QListWidgetItem* item = d->mListWidget->currentItem(); |
75 | QList<KIPI::ImageCollection> selectedList; |
76 | if (item) { |
77 | QString name = item->data(Qt::UserRole).toString(); |
78 | QList<KIPI::ImageCollection> list = d->mInterface->allAlbums(); |
79 | Q_FOREACH(const KIPI::ImageCollection& collection, list) { |
80 | if (collection.name() == name) { |
81 | selectedList << collection; |
82 | break; |
83 | } |
84 | } |
85 | } |
86 | return selectedList; |
87 | } |
88 | |