File indexing completed on 2025-01-05 03:53:45

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2017-06-27
0007  * Description : finish page of export tool, where user can watch upload process.
0008  *
0009  * SPDX-FileCopyrightText: 2017-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  * SPDX-FileCopyrightText: 2018      by Thanh Trung Dinh <dinhthanhtrung1996 at gmail dot com>
0011  *
0012  * SPDX-License-Identifier: GPL-2.0-or-later
0013  *
0014  * ============================================================ */
0015 
0016 #include "wsfinalpage.h"
0017 
0018 // Qt includes
0019 
0020 #include <QIcon>
0021 #include <QSpacerItem>
0022 #include <QVBoxLayout>
0023 #include <QDesktopServices>
0024 #include <QUrl>
0025 #include <QApplication>
0026 #include <QStyle>
0027 #include <QTimer>
0028 #include <QDir>
0029 
0030 // KDE includes
0031 
0032 #include <klocalizedstring.h>
0033 
0034 // Local includes
0035 
0036 #include "wswizard.h"
0037 #include "dlayoutbox.h"
0038 #include "digikam_debug.h"
0039 #include "dprogresswdg.h"
0040 #include "dhistoryview.h"
0041 #include "wsauthentication.h"
0042 
0043 namespace DigikamGenericUnifiedPlugin
0044 {
0045 
0046 class Q_DECL_HIDDEN WSFinalPage::Private
0047 {
0048 public:
0049 
0050     explicit Private(QWizard* const dialog)
0051       : progressView(0),
0052         progressBar(0),
0053         complete(false),
0054         wizard(0),
0055         iface(0),
0056         wsAuth(0)
0057     {
0058         wizard = dynamic_cast<WSWizard*>(dialog);
0059 
0060         if (wizard)
0061         {
0062             iface  = wizard->iface();
0063             wsAuth = wizard->wsAuth();
0064         }
0065     }
0066 
0067     DHistoryView*     progressView;
0068     DProgressWdg*     progressBar;
0069     bool              complete;
0070     WSWizard*         wizard;
0071     DInfoInterface*   iface;
0072     WSAuthentication* wsAuth;
0073 };
0074 
0075 WSFinalPage::WSFinalPage(QWizard* const dialog, const QString& title)
0076     : DWizardPage(dialog, title),
0077       d(new Private(dialog))
0078 {
0079     DVBox* const vbox = new DVBox(this);
0080     d->progressView   = new DHistoryView(vbox);
0081     d->progressBar    = new DProgressWdg(vbox);
0082 
0083     vbox->setStretchFactor(d->progressBar, 10);
0084     vbox->setContentsMargins(QMargins());
0085     vbox->setSpacing(qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing),
0086                              QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing)));
0087 
0088     setPageWidget(vbox);
0089     setLeftBottomPix(QIcon::fromTheme(QLatin1String("WS_send")));
0090 
0091     connect(d->wsAuth, SIGNAL(signalProgress(int)),
0092             d->progressBar, SLOT(setValue(int)));
0093 
0094     connect(d->wsAuth, SIGNAL(signalMessage(QString,bool)),
0095             this, SLOT(slotMessage(QString,bool)));
0096 
0097     connect(d->wsAuth, SIGNAL(signalDone()),
0098             this, SLOT(slotDone()));
0099 }
0100 
0101 WSFinalPage::~WSFinalPage()
0102 {
0103     if (d->wsAuth)
0104     {
0105         d->wsAuth->slotCancel();
0106     }
0107 
0108     delete d;
0109 }
0110 
0111 void WSFinalPage::initializePage()
0112 {
0113     d->complete = false;
0114     Q_EMIT completeChanged();
0115     QTimer::singleShot(0, this, SLOT(slotProcess()));
0116 }
0117 
0118 void WSFinalPage::slotDone()
0119 {
0120     d->complete = true;
0121     Q_EMIT completeChanged();
0122 }
0123 
0124 void WSFinalPage::slotProcess()
0125 {
0126     if (!d->wizard)
0127     {
0128         d->progressView->addEntry(i18n("Internal Error"), DHistoryView::ErrorEntry);
0129         return;
0130     }
0131 
0132     d->progressView->clear();
0133     d->progressBar->reset();
0134 
0135     d->progressView->addEntry(i18n("Preparing files..."), DHistoryView::ProgressEntry);
0136     d->wsAuth->prepareForUpload();
0137 
0138     d->progressView->addEntry(i18n("%1 input items to process", d->wsAuth->numberItemsUpload()),
0139                               DHistoryView::ProgressEntry);
0140 
0141     d->progressView->addEntry(i18n("Start transferring process..."), DHistoryView::ProgressEntry);
0142     d->wsAuth->startTransfer();
0143 
0144     d->progressBar->setMinimum(0);
0145     d->progressBar->setMaximum(d->wsAuth->numberItemsUpload());
0146 }
0147 
0148 void WSFinalPage::cleanupPage()
0149 {
0150     if (d->wsAuth)
0151     {
0152         d->wsAuth->slotCancel();
0153     }
0154 }
0155 
0156 void WSFinalPage::slotMessage(const QString& mess, bool err)
0157 {
0158     d->progressView->addEntry(mess, err ? DHistoryView::ErrorEntry
0159                                         : DHistoryView::ProgressEntry);
0160 }
0161 
0162 bool WSFinalPage::isComplete() const
0163 {
0164     return d->complete;
0165 }
0166 
0167 } // namespace DigikamGenericUnifiedPlugin
0168 
0169 #include "moc_wsfinalpage.cpp"