1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date        : 2017-06-27
7  * Description : a tool to export items to web services.
8  *
9  * Copyright (C) 2017-2021 by Gilles Caulier <caulier dot gilles at gmail dot com>
10  * Copyright (C) 2018      by Thanh Trung Dinh <dinhthanhtrung1996 at gmail dot com>
11  *
12  * This program is free software; you can redistribute it
13  * and/or modify it under the terms of the GNU General
14  * Public License as published by the Free Software Foundation;
15  * either version 2, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * ============================================================ */
23 
24 #include "wswizard.h"
25 
26 // Qt includes
27 
28 #include <QCheckBox>
29 #include <QLabel>
30 #include <QMenu>
31 #include <QApplication>
32 #include <QComboBox>
33 #include <QListWidget>
34 #include <QTextBrowser>
35 
36 // KDE includes
37 
38 #include <klocalizedstring.h>
39 #include <ksharedconfig.h>
40 #include <kconfiggroup.h>
41 
42 // Local includes
43 
44 #include "dwizardpage.h"
45 #include "digikam_debug.h"
46 #include "wsintropage.h"
47 #include "wsauthenticationpage.h"
48 #include "wsalbumspage.h"
49 #include "wsimagespage.h"
50 #include "wssettingspage.h"
51 #include "wsfinalpage.h"
52 #include "wstoolutils.h"
53 
54 namespace DigikamGenericUnifiedPlugin
55 {
56 
57 class Q_DECL_HIDDEN WSWizard::Private
58 {
59 public:
60 
Private()61     explicit Private()
62       : iface(0),
63         settings(0),
64         introPage(0),
65         authPage(0),
66         albumsPage(0),
67         imagesPage(0),
68         settingsPage(0),
69         finalPage(0),
70         wsAuth(0)
71     {
72     }
73 
74     DInfoInterface*             iface;
75 
76     WSSettings*                 settings;
77     WSIntroPage*                introPage;
78     WSAuthenticationWizard*     authPage;
79     WSAlbumsPage*               albumsPage;
80     WSImagesPage*               imagesPage;
81     WSSettingsPage*             settingsPage;
82     WSFinalPage*                finalPage;
83 
84     WSAuthentication*           wsAuth;
85 };
86 
WSWizard(DInfoInterface * const iface,QWidget * const parent)87 WSWizard::WSWizard(DInfoInterface* const iface, QWidget* const parent)
88     : DWizardDlg(parent, QLatin1String("Web Services Dialog")),
89       d(new Private)
90 {
91     setOptions(QWizard::NoBackButtonOnStartPage | QWizard::NoCancelButtonOnLastPage);
92     setWindowTitle(i18n("Export to Web Services"));
93 
94     d->iface                = iface;
95     d->settings             = new WSSettings(this);
96 
97     d->wsAuth               = new WSAuthentication(this, d->iface);
98 
99     KSharedConfigPtr config = KSharedConfig::openConfig();
100     KConfigGroup group      = config->group("Web Services Dialog Settings");
101     d->settings->readSettings(group);
102 
103     d->introPage            = new WSIntroPage(this,    i18n("Welcome to Web Services Tool"));
104     d->authPage             = new WSAuthenticationWizard(this, i18n("Authentication dialog"));
105     d->albumsPage           = new WSAlbumsPage(this,   i18n("Albums Selection"));
106     d->imagesPage           = new WSImagesPage(this,   i18n("Images List"));
107     d->settingsPage         = new WSSettingsPage(this, i18n("Web Service Settings"));
108     d->finalPage            = new WSFinalPage(this,    i18n("Export by Web Service"));
109 }
110 
~WSWizard()111 WSWizard::~WSWizard()
112 {
113     KSharedConfigPtr config = KSharedConfig::openConfig();
114     KConfigGroup group      = config->group("Web Services Dialog Settings");
115     d->settings->writeSettings(group);
116 
117     delete d;
118 }
119 
setItemsList(const QList<QUrl> & urls)120 void WSWizard::setItemsList(const QList<QUrl>& urls)
121 {
122     d->imagesPage->setItemsList(urls);
123 }
124 
iface() const125 DInfoInterface* WSWizard::iface() const
126 {
127     return d->iface;
128 }
129 
settings() const130 WSSettings* WSWizard::settings() const
131 {
132     return d->settings;
133 }
134 
wsAuth() const135 WSAuthentication* WSWizard::wsAuth() const
136 {
137     return d->wsAuth;
138 }
139 
oauthSettings() const140 QSettings* WSWizard::oauthSettings() const
141 {
142     return d->settings->oauthSettings;
143 }
144 
oauthSettingsStore() const145 O0SettingsStore* WSWizard::oauthSettingsStore() const
146 {
147     return d->settings->oauthSettingsStore;
148 }
149 
validateCurrentPage()150 bool WSWizard::validateCurrentPage()
151 {
152     if (!DWizardDlg::validateCurrentPage())
153         return false;
154 
155     return true;
156 }
157 
nextId() const158 int WSWizard::nextId() const
159 {
160     if (currentPage() == d->authPage)
161     {
162         if (d->settings->selMode == WSSettings::IMPORT)
163         {
164             return d->albumsPage->id();
165         }
166         else
167         {
168             return d->imagesPage->id();
169         }
170     }
171 
172     return DWizardDlg::nextId();
173 }
174 
slotBusy(bool val)175 void WSWizard::slotBusy(bool val)
176 {
177     if (val)
178     {
179         setCursor(Qt::WaitCursor);
180     }
181     else
182     {
183         setCursor(Qt::ArrowCursor);
184     }
185 }
186 
187 } // namespace DigikamGenericUnifiedPlugin
188