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 : intro page to export tool where user can choose web service to export,
0008  *               existent accounts and function mode (export/import).
0009  *
0010  * SPDX-FileCopyrightText: 2017-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0011  * SPDX-FileCopyrightText: 2018      by Thanh Trung Dinh <dinhthanhtrung1996 at gmail dot com>
0012  *
0013  * SPDX-License-Identifier: GPL-2.0-or-later
0014  *
0015  * ============================================================ */
0016 
0017 #include "wsintropage.h"
0018 
0019 // Qt includes
0020 
0021 #include <QLabel>
0022 #include <QPixmap>
0023 #include <QComboBox>
0024 #include <QIcon>
0025 #include <QGroupBox>
0026 #include <QGridLayout>
0027 #include <QRadioButton>
0028 #include <QButtonGroup>
0029 #include <QSettings>
0030 
0031 // KDE includes
0032 
0033 #include <klocalizedstring.h>
0034 
0035 // Local includes
0036 
0037 #include "digikam_debug.h"
0038 #include "dlayoutbox.h"
0039 #include "wswizard.h"
0040 #include "wssettings.h"
0041 
0042 namespace DigikamGenericUnifiedPlugin
0043 {
0044 
0045 class Q_DECL_HIDDEN WSIntroPage::Private
0046 {
0047 public:
0048 
0049     explicit Private(QWizard* const dialog)
0050       : imageGetOption(0),
0051         hbox(0),
0052         wizard(0),
0053         iface(0),
0054         wsOption(0),
0055         accountOption(0)
0056     {
0057         wizard = dynamic_cast<WSWizard*>(dialog);
0058 
0059         if (wizard)
0060         {
0061             iface    = wizard->iface();
0062             settings = wizard->settings();
0063         }
0064 
0065     }
0066 
0067     QComboBox*      imageGetOption;
0068     DHBox*          hbox;
0069     WSWizard*       wizard;
0070     WSSettings*     settings;
0071     DInfoInterface* iface;
0072     QComboBox*      wsOption;
0073     QComboBox*      accountOption;
0074 };
0075 
0076 WSIntroPage::WSIntroPage(QWizard* const dialog, const QString& title)
0077     : DWizardPage(dialog, title),
0078       d(new Private(dialog))
0079 {
0080     DVBox* const vbox  = new DVBox(this);
0081     QLabel* const desc = new QLabel(vbox);
0082 
0083     desc->setWordWrap(true);
0084     desc->setOpenExternalLinks(true);
0085     desc->setText(i18n("<qt>"
0086                        "<p><h1><b>Welcome to Web Services Tool</b></h1></p>"
0087                        "<p>This assistant will guide you step by step, to export "
0088                        "your items to popular Internet data hosting service.</p>"
0089                        "<p>Before exporting contents, you will be able to adjust items' properties "
0090                        "according to your remote Web service capabilities.</p>"
0091                        "</qt>"));
0092 
0093     /* --------------------
0094      * ComboBox for image selection method
0095      */
0096 
0097     d->hbox                     = new DHBox(vbox);
0098     QLabel* const getImageLabel = new QLabel(i18n("&Choose operation:"), d->hbox);
0099     d->imageGetOption           = new QComboBox(d->hbox);
0100     d->imageGetOption->insertItem(WSSettings::EXPORT, i18n("Export to web services"));
0101     d->imageGetOption->insertItem(WSSettings::IMPORT, i18n("Import from web services"));
0102     getImageLabel->setBuddy(d->imageGetOption);
0103 
0104     connect(d->imageGetOption, SIGNAL(currentIndexChanged(int)),
0105             this, SLOT(slotImageGetOptionChanged(int)));
0106 
0107     /* --------------------
0108      * ComboBox for web service selection
0109      */
0110 
0111     DHBox* const wsBox          = new DHBox(vbox);
0112     QLabel* const wsLabel       = new QLabel(i18n("&Choose remote Web Service:"), wsBox);
0113     d->wsOption                 = new QComboBox(wsBox);
0114     QMap<WSSettings::WebService, QString> map                = WSSettings::webServiceNames();
0115     QMap<WSSettings::WebService, QString>::const_iterator it = map.constBegin();
0116 
0117     while (it != map.constEnd())
0118     {
0119         QString wsName = it.value().toLower();
0120         QIcon icon     = QIcon::fromTheme(wsName.remove(QLatin1Char(' ')));
0121         d->wsOption->addItem(icon, it.value(), (int)it.key());
0122         ++it;
0123     }
0124 
0125     wsLabel->setBuddy(d->wsOption);
0126 
0127     connect(d->wsOption, SIGNAL(currentTextChanged(QString)),
0128             this, SLOT(slotWebServiceOptionChanged(QString)));
0129 
0130     /* --------------------
0131      * ComboBox for user account selection
0132      *
0133      * An empty option is added to accounts, so that user can choose to login with new account
0134      */
0135 
0136     DHBox* const accountBox     = new DHBox(vbox);
0137     QLabel* const accountLabel  = new QLabel(i18n("&Choose account:"), accountBox);
0138     d->accountOption            = new QComboBox(accountBox);
0139 
0140     QStringList accounts        = QStringList(QString())
0141                                   << d->settings->allUserNames(map.constBegin().value());
0142 
0143     Q_FOREACH (const QString& account, accounts)
0144     {
0145         d->accountOption->addItem(account);
0146     }
0147 
0148     accountLabel->setBuddy(d->accountOption);
0149 
0150     /* --------------------
0151      * Place widget in the view
0152      */
0153 
0154     vbox->setStretchFactor(desc,       3);
0155     vbox->setStretchFactor(d->hbox,    1);
0156     vbox->setStretchFactor(wsBox,      3);
0157     vbox->setStretchFactor(accountBox, 3);
0158 
0159     setPageWidget(vbox);
0160     setLeftBottomPix(QIcon::fromTheme(QLatin1String("folder-html")));
0161 }
0162 
0163 WSIntroPage::~WSIntroPage()
0164 {
0165     delete d;
0166 }
0167 
0168 void WSIntroPage::slotImageGetOptionChanged(int index)
0169 {
0170     QMap<WSSettings::WebService, QString> map   = WSSettings::webServiceNames();
0171 
0172     d->wsOption->clear();
0173 
0174     /*
0175      * index == 0 <=> Export
0176      * index == 1 <=> Import, for now we only have Google Photo and Smugmug in this option
0177      */
0178     if (index == 0)
0179     {
0180         QMap<WSSettings::WebService, QString>::const_iterator it = map.constBegin();
0181 
0182         while (it != map.constEnd())
0183         {
0184             QString wsName = it.value().toLower();
0185             QIcon icon = QIcon::fromTheme(wsName.remove(QLatin1Char(' ')));
0186             qCDebug(DIGIKAM_WEBSERVICES_LOG) << wsName.remove(QLatin1Char(' '));
0187             d->wsOption->addItem(icon, it.value(), (int)it.key());
0188             ++it;
0189         }
0190     }
0191     else
0192     {
0193         d->wsOption->addItem(QIcon::fromTheme(QLatin1String("dk-smugmug")),
0194                              map[WSSettings::WebService::SMUGMUG],
0195                              WSSettings::WebService::SMUGMUG);
0196         d->wsOption->addItem(QIcon::fromTheme(QLatin1String("dk-googlephoto")),
0197                              map[WSSettings::WebService::GPHOTO],
0198                              WSSettings::WebService::GPHOTO);
0199     }
0200 }
0201 
0202 void WSIntroPage::slotWebServiceOptionChanged(const QString& serviceName)
0203 {
0204     d->accountOption->clear();
0205 
0206     // An empty option is added to accounts, so that user can choose to login with new account
0207     QStringList accounts = QStringList(QString())
0208                            << d->settings->allUserNames(serviceName);
0209 
0210     Q_FOREACH (const QString& account, accounts)
0211     {
0212         d->accountOption->addItem(account);
0213     }
0214 }
0215 
0216 void WSIntroPage::initializePage()
0217 {
0218     d->imageGetOption->setCurrentIndex(d->wizard->settings()->selMode);
0219 }
0220 
0221 bool WSIntroPage::validatePage()
0222 {
0223     d->wizard->settings()->selMode    = (WSSettings::Selection)d->imageGetOption->currentIndex();
0224     d->wizard->settings()->webService = (WSSettings::WebService)d->wsOption->currentIndex();
0225     d->wizard->settings()->userName   = d->accountOption->currentText();
0226 
0227     return true;
0228 }
0229 
0230 } // namespace DigikamGenericUnifiedPlugin
0231 
0232 #include "moc_wsintropage.cpp"