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 : a tool to export items to web services.
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 "wswizard.h"
0017 
0018 // Qt includes
0019 
0020 #include <QCheckBox>
0021 #include <QLabel>
0022 #include <QMenu>
0023 #include <QApplication>
0024 #include <QComboBox>
0025 #include <QListWidget>
0026 #include <QTextBrowser>
0027 
0028 // KDE includes
0029 
0030 #include <klocalizedstring.h>
0031 #include <ksharedconfig.h>
0032 #include <kconfiggroup.h>
0033 
0034 // Local includes
0035 
0036 #include "dwizardpage.h"
0037 #include "digikam_debug.h"
0038 #include "wsintropage.h"
0039 #include "wsauthenticationpage.h"
0040 #include "wsalbumspage.h"
0041 #include "wsimagespage.h"
0042 #include "wssettingspage.h"
0043 #include "wsfinalpage.h"
0044 #include "wstoolutils.h"
0045 
0046 namespace DigikamGenericUnifiedPlugin
0047 {
0048 
0049 class Q_DECL_HIDDEN WSWizard::Private
0050 {
0051 public:
0052 
0053     explicit Private()
0054       : iface(0),
0055         settings(0),
0056         introPage(0),
0057         authPage(0),
0058         albumsPage(0),
0059         imagesPage(0),
0060         settingsPage(0),
0061         finalPage(0),
0062         wsAuth(0)
0063     {
0064     }
0065 
0066     DInfoInterface*             iface;
0067 
0068     WSSettings*                 settings;
0069     WSIntroPage*                introPage;
0070     WSAuthenticationWizard*     authPage;
0071     WSAlbumsPage*               albumsPage;
0072     WSImagesPage*               imagesPage;
0073     WSSettingsPage*             settingsPage;
0074     WSFinalPage*                finalPage;
0075 
0076     WSAuthentication*           wsAuth;
0077 };
0078 
0079 WSWizard::WSWizard(DInfoInterface* const iface, QWidget* const parent)
0080     : DWizardDlg(parent, QLatin1String("Web Services Dialog")),
0081       d(new Private)
0082 {
0083     setOptions(QWizard::NoBackButtonOnStartPage | QWizard::NoCancelButtonOnLastPage);
0084     setWindowTitle(i18nc("@title:window", "Export to Web Services"));
0085 
0086     d->iface                = iface;
0087     d->settings             = new WSSettings(this);
0088 
0089     d->wsAuth               = new WSAuthentication(this, d->iface);
0090 
0091     KSharedConfigPtr config = KSharedConfig::openConfig();
0092     KConfigGroup group      = config->group(QLatin1String("Web Services Dialog Settings"));
0093     d->settings->readSettings(group);
0094 
0095     d->introPage            = new WSIntroPage(this,    i18n("Welcome to Web Services Tool"));
0096     d->authPage             = new WSAuthenticationWizard(this, i18n("Authentication dialog"));
0097     d->albumsPage           = new WSAlbumsPage(this,   i18n("Albums Selection"));
0098     d->imagesPage           = new WSImagesPage(this,   i18n("Images List"));
0099     d->settingsPage         = new WSSettingsPage(this, i18n("Web Service Settings"));
0100     d->finalPage            = new WSFinalPage(this,    i18n("Export by Web Service"));
0101 }
0102 
0103 WSWizard::~WSWizard()
0104 {
0105     KSharedConfigPtr config = KSharedConfig::openConfig();
0106     KConfigGroup group      = config->group(QLatin1String("Web Services Dialog Settings"));
0107     d->settings->writeSettings(group);
0108 
0109     delete d;
0110 }
0111 
0112 void WSWizard::setItemsList(const QList<QUrl>& urls)
0113 {
0114     d->imagesPage->setItemsList(urls);
0115 }
0116 
0117 DInfoInterface* WSWizard::iface() const
0118 {
0119     return d->iface;
0120 }
0121 
0122 WSSettings* WSWizard::settings() const
0123 {
0124     return d->settings;
0125 }
0126 
0127 WSAuthentication* WSWizard::wsAuth() const
0128 {
0129     return d->wsAuth;
0130 }
0131 
0132 QSettings* WSWizard::oauthSettings() const
0133 {
0134     return d->settings->oauthSettings;
0135 }
0136 
0137 O0SettingsStore* WSWizard::oauthSettingsStore() const
0138 {
0139     return d->settings->oauthSettingsStore;
0140 }
0141 
0142 bool WSWizard::validateCurrentPage()
0143 {
0144     if (!DWizardDlg::validateCurrentPage())
0145         return false;
0146 
0147     return true;
0148 }
0149 
0150 int WSWizard::nextId() const
0151 {
0152     if (currentPage() == d->authPage)
0153     {
0154         if (d->settings->selMode == WSSettings::IMPORT)
0155         {
0156             return d->albumsPage->id();
0157         }
0158         else
0159         {
0160             return d->imagesPage->id();
0161         }
0162     }
0163 
0164     return DWizardDlg::nextId();
0165 }
0166 
0167 void WSWizard::slotBusy(bool val)
0168 {
0169     if (val)
0170     {
0171         setCursor(Qt::WaitCursor);
0172     }
0173     else
0174     {
0175         setCursor(Qt::ArrowCursor);
0176     }
0177 }
0178 
0179 } // namespace DigikamGenericUnifiedPlugin
0180 
0181 #include "moc_wswizard.cpp"