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
197
198
199
200
201
202
203
204
205
206 | /* ============================================================
*
* This file is a part of digiKam project
* https://www.digikam.org
*
* Date : 2009-09-28
* Description : a tool to export image to a KIO accessible
* location
*
* SPDX-FileCopyrightText: 2006-2009 by Johannes Wienke <languitar at semipol dot de>
* SPDX-FileCopyrightText: 2011-2025 by Gilles Caulier <caulier dot gilles at gmail dot com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* ============================================================ */
#include "ftexportwindow.h"
// Qt includes
#include <QCloseEvent>
#include <QMessageBox>
// KDE includes
#include <klocalizedstring.h>
#include <ksharedconfig.h>
#include <kconfiggroup.h>
#include <kio/job.h>
#include <kio/copyjob.h>
// Local includes
#include "digikam_debug.h"
#include "digikam_version.h"
#include "ditemslist.h"
#include "ftexportwidget.h"
namespace DigikamGenericFileTransferPlugin
{
class Q_DECL_HIDDEN FTExportWindow::Private
{
public:
Private() = default;
const QString TARGET_URL_PROPERTY = QLatin1String("targetUrl");
const QString HISTORY_URL_PROPERTY = QLatin1String("historyUrls");
const QString CONFIG_GROUP = QLatin1String("KioExport");
FTExportWidget* exportWidget = nullptr;
};
FTExportWindow::FTExportWindow(DInfoInterface* const iface, QWidget* const /*parent*/)
: WSToolDialog(nullptr, QLatin1String("Kio Export Dialog")),
d (new Private)
{
d->exportWidget = new FTExportWidget(iface, this);
setMainWidget(d->exportWidget);
// -- Window setup ------------------------------------------------------
setWindowTitle(i18nc("@title:window", "Export to Remote Storage"));
setModal(false);
startButton()->setText(i18nc("@action:button", "Start Export"));
startButton()->setToolTip(i18nc("@info:tooltip, button", "Start export to the specified target"));
connect(startButton(), SIGNAL(clicked()),
this, SLOT(slotUpload()));
connect(this, SIGNAL(finished(int)),
this, SLOT(slotFinished()));
connect(d->exportWidget->imagesList(), SIGNAL(signalImageListChanged()),
this, SLOT(slotImageListChanged()));
connect(d->exportWidget, SIGNAL(signalTargetUrlChanged(QUrl)),
this, SLOT(slotTargetUrlChanged(QUrl)));
// -- initial sync ------------------------------------------------------
restoreSettings();
updateUploadButton();
}
FTExportWindow::~FTExportWindow()
{
delete d;
}
void FTExportWindow::slotFinished()
{
saveSettings();
d->exportWidget->imagesList()->listView()->clear();
}
void FTExportWindow::closeEvent(QCloseEvent* e)
{
if (!e)
{
return;
}
slotFinished();
e->accept();
}
void FTExportWindow::reactivate()
{
d->exportWidget->imagesList()->loadImagesFromCurrentSelection();
show();
}
void FTExportWindow::restoreSettings()
{
KSharedConfigPtr config = KSharedConfig::openConfig();
KConfigGroup group = config->group(d->CONFIG_GROUP);
d->exportWidget->setHistory(group.readEntry(d->HISTORY_URL_PROPERTY, QList<QUrl>()));
d->exportWidget->setTargetUrl(group.readEntry(d->TARGET_URL_PROPERTY, QUrl()));
}
void FTExportWindow::saveSettings()
{
KSharedConfigPtr config = KSharedConfig::openConfig();
KConfigGroup group = config->group(d->CONFIG_GROUP);
group.writeEntry(d->HISTORY_URL_PROPERTY, d->exportWidget->history());
group.writeEntry(d->TARGET_URL_PROPERTY, d->exportWidget->targetUrl().url());
}
void FTExportWindow::slotImageListChanged()
{
updateUploadButton();
}
void FTExportWindow::slotTargetUrlChanged(const QUrl& target)
{
Q_UNUSED(target);
updateUploadButton();
}
void FTExportWindow::updateUploadButton()
{
bool listNotEmpty = !d->exportWidget->imagesList()->imageUrls().isEmpty();
startButton()->setEnabled(listNotEmpty && d->exportWidget->targetUrl().isValid());
qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Updated upload button with listNotEmpty = "
<< listNotEmpty << ", targetUrl().isValid() = "
<< d->exportWidget->targetUrl().isValid();
}
void FTExportWindow::slotCopyingDone(KIO::Job* job,
const QUrl& from,
const QUrl& to,
const QDateTime& mtime,
bool directory,
bool renamed)
{
Q_UNUSED(job);
Q_UNUSED(to);
Q_UNUSED(mtime);
Q_UNUSED(directory);
Q_UNUSED(renamed);
qCDebug(DIGIKAM_WEBSERVICES_LOG) << "copied " << to.toDisplayString();
d->exportWidget->imagesList()->removeItemByUrl(from);
}
void FTExportWindow::slotCopyingFinished(KJob* job)
{
Q_UNUSED(job);
setEnabled(true);
if (!d->exportWidget->imagesList()->imageUrls().isEmpty())
{
QMessageBox::information(this, i18nc("@title:window", "Upload not Completed"),
i18n("Some of the images have not been transferred "
"and are still in the list. "
"You can retry to export these images now."));
}
}
void FTExportWindow::slotUpload()
{
saveSettings();
// start copying and react on signals
setEnabled(false);
KIO::CopyJob* const copyJob = KIO::copy(d->exportWidget->imagesList()->imageUrls(),<--- Variable 'copyJob' can be declared as pointer to const
d->exportWidget->targetUrl());
connect(copyJob, SIGNAL(copyingDone(KIO::Job*,QUrl,QUrl,QDateTime,bool,bool)),
this, SLOT(slotCopyingDone(KIO::Job*,QUrl,QUrl,QDateTime,bool,bool)));
connect(copyJob, SIGNAL(result(KJob*)),
this, SLOT(slotCopyingFinished(KJob*)));
}
} // namespace DigikamGenericFileTransferPlugin
#include "moc_ftexportwindow.cpp"
|