Debian Codegraph @

core/libs/album/widgets/albumselectdialog.cpp

raw
1 /* ============================================================
2 *
3 * This file is a part of digiKam project
4 * https://www.digikam.org
5 *
6 * Date : 2005-06-16
7 * Description : a dialog to select a target album to download
8 * pictures from camera
9 *
10 * SPDX-FileCopyrightText: 2005 by Renchi Raju <renchi dot raju at gmail dot com>
11 * SPDX-FileCopyrightText: 2006-2026 by Gilles Caulier <caulier dot gilles at gmail dot com>
12 *
13 * SPDX-License-Identifier: GPL-2.0-or-later
14 *
15 * ============================================================ */
16
17 #include "albumselectdialog.h"
18
19 // Qt includes
20
21 #include <QLabel>
22 #include <QGridLayout>
23 #include <QPixmap>
24 #include <QPointer>
25 #include <QStandardPaths>
26 #include <QApplication>
27 #include <QStyle>
28 #include <QDialogButtonBox>
29 #include <QVBoxLayout>
30 #include <QPushButton>
31
32 // KDE includes
33
34 #include <klocalizedstring.h>
35 #include <ksharedconfig.h>
36 #include <kconfiggroup.h>
37
38 // Local includes
39
40 #include "digikam_globals.h"
41 #include "album.h"
42 #include "albummanager.h"
43 #include "albumselectwidget.h"
44 #include "albumthumbnailloader.h"
45 #include "collectionmanager.h"
46 #include "dxmlguiwindow.h"
47
48 namespace Digikam
49 {
50
51 class Q_DECL_HIDDEN AlbumSelectDialog::Private
52 {
53 public:
54
55 Private() = default;
56
57 public:
58
59 QDialogButtonBox* buttons = nullptr;
60
61 AlbumSelectWidget* albumSel = nullptr;
62
63 SearchTextBar* searchBar = nullptr;
64 };
65
66 AlbumSelectDialog::AlbumSelectDialog(QWidget* const parent, PAlbum* const albumToSelect, const QString& header)
67 : QDialog(parent),
68 d (new Private)
69 {
70 setWindowFlags((windowFlags() & ~Qt::Dialog) |
71 Qt::Window |
72 Qt::WindowCloseButtonHint |
73 Qt::WindowMinMaxButtonsHint);
74
75 setObjectName(QLatin1String("Select Album Dialog"));
76 setWindowTitle(i18nc("@title:window", "Select Album"));
77
78 d->buttons = new QDialogButtonBox(QDialogButtonBox::Help |
79 QDialogButtonBox::Ok |
80 QDialogButtonBox::Cancel, this);
81 d->buttons->button(QDialogButtonBox::Ok)->setDefault(true);
82
83 // -------------------------------------------------------------
84
85 QWidget* const page = new QWidget(this);
86 QGridLayout* const grid = new QGridLayout(page);
87 QLabel* const logo = new QLabel(page);
88 logo->setPixmap(QIcon::fromTheme(QLatin1String("digikam")).pixmap(QSize(48,48)));
89
90 QLabel* const message = new QLabel(page);
91 message->setWordWrap(true);
92
93 if (!header.isEmpty())
94 {
95 message->setText(header);
96 }
97
98 d->albumSel = new AlbumSelectWidget(page, albumToSelect, true);
99
100 grid->addWidget(logo, 0, 0, 1, 1);
101 grid->addWidget(message, 1, 0, 1, 1);
102 grid->addWidget(d->albumSel, 0, 1, 3, 1);
103 grid->setColumnStretch(0, 2);
104 grid->setColumnStretch(1, 10);
105 grid->setRowStretch(2, 10);
106 grid->setContentsMargins(QMargins());
107 grid->setSpacing(layoutSpacing());
108
109 QVBoxLayout* const vbx = new QVBoxLayout(this);
110 vbx->addWidget(page);
111 vbx->addWidget(d->buttons);
112 setLayout(vbx);
113
114 // -------------------------------------------------------------
115
116 connect(d->albumSel, SIGNAL(itemSelectionChanged()),
117 this, SLOT(slotSelectionChanged()));
118
119 connect(d->albumSel, SIGNAL(completerActivated()),
120 this, SLOT(accept()));
121
122 connect(d->buttons->button(QDialogButtonBox::Ok), SIGNAL(clicked()),
123 this, SLOT(accept()));
124
125 connect(d->buttons->button(QDialogButtonBox::Cancel), SIGNAL(clicked()),
126 this, SLOT(reject()));
127
128 connect(d->buttons->button(QDialogButtonBox::Help), SIGNAL(clicked()),
129 this, SLOT(slotHelp()));
130
131 // -------------------------------------------------------------
132
133 slotSelectionChanged();
134 }
135
136 AlbumSelectDialog::~AlbumSelectDialog()
137 {
138 KSharedConfigPtr config = KSharedConfig::openConfig();
139 KConfigGroup group = config->group(objectName());
140
141 DXmlGuiWindow::saveWindowSize(windowHandle(), group);
142
143 delete d;
144 }
145
146 void AlbumSelectDialog::slotSelectionChanged()
147 {
148 const PAlbum* const currentAlbum = d->albumSel->currentAlbum();
149
150 bool enabled = !(!currentAlbum || currentAlbum->isRoot());
151 d->buttons->button(QDialogButtonBox::Ok)->setEnabled(enabled);
152 }
153
154 PAlbum* AlbumSelectDialog::selectAlbum(QWidget* const parent, PAlbum* const albumToSelect, const QString& header)
155 {
156 QPointer<AlbumSelectDialog> dlg = new AlbumSelectDialog(parent, albumToSelect, header);
157
158 if (dialogExec(dlg) != QDialog::Accepted)
159 {
160 delete dlg;
161 return nullptr;
162 }
163
164 PAlbum* const selectedAlbum = dlg->d->albumSel->currentAlbum();
165
166 if (!selectedAlbum || (selectedAlbum->isRoot()))
167 {
168 delete dlg;
169 return nullptr;
170 }
171
172 delete dlg;
173
174 return selectedAlbum;
175 }
176
177 void AlbumSelectDialog::slotHelp()
178 {
179 openOnlineDocumentation(QLatin1String("left_sidebar"),
180 QLatin1String("albums_view"));
181 }
182
183 void AlbumSelectDialog::showEvent(QShowEvent* e)
184 {
185 KSharedConfigPtr config = KSharedConfig::openConfig();
186 KConfigGroup group = config->group(objectName());
187
188 DXmlGuiWindow::setGoodDefaultWindowSize(windowHandle());
189 DXmlGuiWindow::restoreWindowSize(windowHandle(), group);
190 resize(windowHandle()->size());
191
192 QDialog::showEvent(e);
193 }
194
195 } // namespace Digikam
196
197 #include "moc_albumselectdialog.cpp"