1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175 | /* ============================================================
*
* This file is a part of digiKam project
* https://www.digikam.org
*
* Date : 2018-07-02
* Description : embedded web browser for web service authentication
*
* SPDX-FileCopyrightText: 2018 by Thanh Trung Dinh <dinhthanhtrung1996 at gmail dot com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* ============================================================ */
#ifndef DIGIKAM_WS_AUTHENTICATION_PAGE_H
#define DIGIKAM_WS_AUTHENTICATION_PAGE_H
#include "digikam_config.h"
// Qt includes
#include <QByteArray>
#include <QString>
#include <QUrl>
#include <QMap>
#ifdef HAVE_QWEBENGINE
# include <QWebEngineView>
# include <QWebEnginePage>
# include <QWebEngineProfile>
# include <QWebEngineCookieStore>
#else
# include <qwebview.h>
# include <qwebpage.h>
# include <qwebframe.h>
# include <QNetworkRequest>
#endif
// Local includes
#include "dwizardpage.h"
#include "dinfointerface.h"
#include "wsauthentication.h"
using namespace Digikam;
namespace DigikamGenericUnifiedPlugin
{
#ifdef HAVE_QWEBENGINE
class WSAuthenticationPage : public QWebEnginePage
#else
class WSAuthenticationPage : public QWebPage
#endif // #ifdef HAVE_QWEBENGINE
{
Q_OBJECT
public:
#ifdef HAVE_QWEBENGINE
explicit WSAuthenticationPage(QObject* const parent, QWebEngineProfile* profile, const QString& callbackUrl);
#else
explicit WSAuthenticationPage(QObject* const parent, const QString& callbackUrl);
#endif // #ifdef HAVE_QWEBENGINE
virtual ~WSAuthenticationPage();
void setCallbackUrl(const QString& url);
#ifdef HAVE_QWEBENGINE
bool acceptNavigationRequest(const QUrl& url, QWebEnginePage::NavigationType type, bool isMainFrame);
#else
private Q_SLOTS:
bool slotUrlChanged(const QUrl& url);
#endif // #ifdef HAVE_QWEBENGINE
Q_SIGNALS:
void callbackCatched(const QString&);
private:
QString m_callbackUrl;
};
// -------------------------------------------------------------------
#ifdef HAVE_QWEBENGINE
class WSAuthenticationPageView : public QWebEngineView
#else
class WSAuthenticationPageView : public QWebView
#endif
{
Q_OBJECT
public:
explicit WSAuthenticationPageView(QWidget* const parent,
WSAuthentication* const wsAuth,
const QString& callbackUrl);
~WSAuthenticationPageView();
bool authenticationComplete() const;
private:
/*
* Parse url into a hash map with key and value for each parameter
*/
QMap<QString, QString> parseUrlFragment(const QString& urlFragment);
Q_SIGNALS:
void signalAuthenticationComplete(bool);
private Q_SLOTS:
void slotCallbackCatched(const QString& callbackUrl);
void slotOpenBrowser(const QUrl& url);
void slotCloseBrowser();
private:
WSAuthentication* m_WSAuthentication;
};
// -------------------------------------------------------------------
class WSAuthenticationWizard : public DWizardPage
{
Q_OBJECT
public:
explicit WSAuthenticationWizard(QWizard* const dialog, const QString& title,
const QString& callback = QLatin1String("http://127.1.1.0:8000/")); // krazy:exclude=insecurenet
~WSAuthenticationWizard();
bool isComplete() const;<--- Function in derived class
void initializePage();
bool validatePage();
void cleanupPage();
public Q_SLOTS:
void slotAuthenticationComplete(bool isLinked);
private:
class Private;
Private* const d = nullptr;
};
} // namespace DigikamGenericUnifiedPlugin
#endif // DIGIKAM_WS_AUTHENTICATION_PAGE_H
|