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