File indexing completed on 2025-03-09 03:52:14
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 04.10.2009 0007 * Description : A tool for importing images via KIO 0008 * 0009 * SPDX-FileCopyrightText: 2009 by Johannes Wienke <languitar at semipol dot de> 0010 * SPDX-FileCopyrightText: 2011-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0011 * 0012 * SPDX-License-Identifier: GPL-2.0-or-later 0013 * 0014 * ============================================================ */ 0015 0016 #include "ftimportwindow.h" 0017 0018 // Qt includes 0019 0020 #include <QAction> 0021 #include <QMenu> 0022 #include <QMessageBox> 0023 0024 // KDE includes 0025 0026 #include <kio/job.h> 0027 #include <kio/copyjob.h> 0028 #include <klocalizedstring.h> 0029 0030 // Local includes 0031 0032 #include "digikam_debug.h" 0033 #include "ftimportwidget.h" 0034 #include "ditemslist.h" 0035 0036 namespace DigikamGenericFileTransferPlugin 0037 { 0038 0039 class Q_DECL_HIDDEN FTImportWindow::Private 0040 { 0041 public: 0042 0043 explicit Private() 0044 { 0045 importWidget = nullptr; 0046 iface = nullptr; 0047 } 0048 0049 FTImportWidget* importWidget; 0050 DInfoInterface* iface; 0051 }; 0052 0053 FTImportWindow::FTImportWindow(DInfoInterface* const iface, QWidget* const /*parent*/) 0054 : WSToolDialog(nullptr, QLatin1String("Kio Import Dialog")), 0055 d (new Private) 0056 { 0057 d->iface = iface; 0058 d->importWidget = new FTImportWidget(this, d->iface); 0059 setMainWidget(d->importWidget); 0060 0061 // window setup 0062 0063 setWindowTitle(i18nc("@title:window", "Import from Remote Storage")); 0064 setModal(false); 0065 startButton()->setEnabled(false); 0066 0067 startButton()->setText(i18nc("@action:button", "Start Import")); 0068 startButton()->setToolTip(i18nc("@info:tooltip, button", "Start importing the specified images " 0069 "into the currently selected album.")); 0070 0071 // connections 0072 0073 connect(startButton(), SIGNAL(clicked()), 0074 this, SLOT(slotImport())); 0075 0076 connect(d->importWidget->imagesList(), SIGNAL(signalImageListChanged()), 0077 this, SLOT(slotSourceAndTargetUpdated())); 0078 0079 connect(d->iface, SIGNAL(signalUploadUrlChanged()), 0080 this, SLOT(slotSourceAndTargetUpdated())); 0081 0082 slotSourceAndTargetUpdated(); 0083 } 0084 0085 FTImportWindow::~FTImportWindow() 0086 { 0087 delete d; 0088 } 0089 0090 void FTImportWindow::slotImport() 0091 { 0092 QUrl url = d->iface->uploadUrl(); 0093 0094 if (!url.isEmpty()) 0095 { 0096 qCDebug(DIGIKAM_WEBSERVICES_LOG) << "starting to import urls: " << d->importWidget->sourceUrls(); 0097 0098 // start copying and react on signals 0099 0100 setEnabled(false); 0101 0102 KIO::CopyJob* const copyJob = KIO::copy(d->importWidget->imagesList()->imageUrls(), url); 0103 0104 connect(copyJob, SIGNAL(copyingDone(KIO::Job*,QUrl,QUrl,QDateTime,bool,bool)), 0105 this, SLOT(slotCopyingDone(KIO::Job*,QUrl,QUrl,QDateTime,bool,bool))); 0106 0107 connect(copyJob, SIGNAL(result(KJob*)), 0108 this, SLOT(slotCopyingFinished(KJob*))); 0109 } 0110 } 0111 0112 void FTImportWindow::slotCopyingDone(KIO::Job* job, 0113 const QUrl& from, 0114 const QUrl& to, 0115 const QDateTime& mtime, 0116 bool directory, 0117 bool renamed) 0118 { 0119 Q_UNUSED(job); 0120 Q_UNUSED(to); 0121 Q_UNUSED(mtime); 0122 Q_UNUSED(directory); 0123 Q_UNUSED(renamed); 0124 0125 qCDebug(DIGIKAM_WEBSERVICES_LOG) << "copied " << to.toDisplayString(); 0126 0127 d->importWidget->imagesList()->removeItemByUrl(from); 0128 } 0129 0130 void FTImportWindow::slotCopyingFinished(KJob* job) 0131 { 0132 Q_UNUSED(job); 0133 0134 setEnabled(true); 0135 0136 if (!d->importWidget->imagesList()->imageUrls().isEmpty()) 0137 { 0138 QMessageBox::information(this, i18nc("@title:window", "Import not Completed"), 0139 i18n("Some of the images have not been transferred " 0140 "and are still in the list. " 0141 "You can retry to import these images now.")); 0142 } 0143 } 0144 0145 void FTImportWindow::slotSourceAndTargetUpdated() 0146 { 0147 bool hasUrlToImport = !d->importWidget->sourceUrls().isEmpty(); 0148 bool hasTarget = !d->iface->uploadUrl().isEmpty(); 0149 0150 qCDebug(DIGIKAM_WEBSERVICES_LOG) << "switching import button activity with: hasUrlToImport = " 0151 << hasUrlToImport << ", hasTarget = " << hasTarget; 0152 0153 startButton()->setEnabled(hasUrlToImport && hasTarget); 0154 } 0155 0156 } // namespace DigikamGenericFileTransferPlugin 0157 0158 #include "moc_ftimportwindow.cpp"