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 : 2018-07-02 0007 * Description : embedded web browser for web service authentication 0008 * 0009 * SPDX-FileCopyrightText: 2018 by Thanh Trung Dinh <dinhthanhtrung1996 at gmail dot com> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #ifndef DIGIKAM_WS_AUTHENTICATION_PAGE_H 0016 #define DIGIKAM_WS_AUTHENTICATION_PAGE_H 0017 0018 #include "digikam_config.h" 0019 0020 // Qt includes 0021 0022 #include <QByteArray> 0023 #include <QString> 0024 #include <QUrl> 0025 #include <QMap> 0026 0027 #ifdef HAVE_QWEBENGINE 0028 # include <QWebEngineView> 0029 # include <QWebEnginePage> 0030 # include <QWebEngineProfile> 0031 # include <QWebEngineCookieStore> 0032 #else 0033 # include <qwebview.h> 0034 # include <qwebpage.h> 0035 # include <qwebframe.h> 0036 # include <QNetworkRequest> 0037 #endif 0038 0039 // Local includes 0040 0041 #include "dwizardpage.h" 0042 #include "dinfointerface.h" 0043 #include "wsauthentication.h" 0044 0045 using namespace Digikam; 0046 0047 namespace DigikamGenericUnifiedPlugin 0048 { 0049 0050 #ifdef HAVE_QWEBENGINE 0051 0052 class WSAuthenticationPage : public QWebEnginePage 0053 0054 #else 0055 0056 class WSAuthenticationPage : public QWebPage 0057 0058 #endif // #ifdef HAVE_QWEBENGINE 0059 0060 { 0061 Q_OBJECT 0062 0063 public: 0064 0065 #ifdef HAVE_QWEBENGINE 0066 0067 explicit WSAuthenticationPage(QObject* const parent, QWebEngineProfile* profile, const QString& callbackUrl); 0068 0069 #else 0070 0071 explicit WSAuthenticationPage(QObject* const parent, const QString& callbackUrl); 0072 0073 #endif // #ifdef HAVE_QWEBENGINE 0074 0075 virtual ~WSAuthenticationPage(); 0076 0077 void setCallbackUrl(const QString& url); 0078 0079 #ifdef HAVE_QWEBENGINE 0080 0081 bool acceptNavigationRequest(const QUrl& url, QWebEnginePage::NavigationType type, bool isMainFrame); 0082 0083 #else 0084 0085 private Q_SLOTS: 0086 0087 bool slotUrlChanged(const QUrl& url); 0088 0089 #endif // #ifdef HAVE_QWEBENGINE 0090 0091 Q_SIGNALS: 0092 0093 void callbackCatched(const QString&); 0094 0095 private: 0096 0097 QString m_callbackUrl; 0098 }; 0099 0100 // ------------------------------------------------------------------- 0101 0102 #ifdef HAVE_QWEBENGINE 0103 0104 class WSAuthenticationPageView : public QWebEngineView 0105 0106 #else 0107 0108 class WSAuthenticationPageView : public QWebView 0109 0110 #endif 0111 { 0112 Q_OBJECT 0113 0114 public: 0115 0116 explicit WSAuthenticationPageView(QWidget* const parent, 0117 WSAuthentication* const wsAuth, 0118 const QString& callbackUrl); 0119 ~WSAuthenticationPageView(); 0120 0121 bool authenticationComplete() const; 0122 0123 private: 0124 0125 /* 0126 * Parse url into a hash map with key and value for each parameter 0127 */ 0128 QMap<QString, QString> parseUrlFragment(const QString& urlFragment); 0129 0130 Q_SIGNALS: 0131 0132 void signalAuthenticationComplete(bool); 0133 0134 private Q_SLOTS: 0135 0136 void slotCallbackCatched(const QString& callbackUrl); 0137 void slotOpenBrowser(const QUrl& url); 0138 void slotCloseBrowser(); 0139 0140 private: 0141 0142 WSAuthentication* m_WSAuthentication; 0143 }; 0144 0145 // ------------------------------------------------------------------- 0146 0147 class WSAuthenticationWizard : public DWizardPage 0148 { 0149 Q_OBJECT 0150 0151 public: 0152 0153 explicit WSAuthenticationWizard(QWizard* const dialog, const QString& title, 0154 const QString& callback = QLatin1String("http://127.1.1.0:8000/")); // krazy:exclude=insecurenet 0155 ~WSAuthenticationWizard(); 0156 0157 bool isComplete() const; 0158 0159 void initializePage(); 0160 bool validatePage(); 0161 void cleanupPage(); 0162 0163 public Q_SLOTS: 0164 0165 void slotAuthenticationComplete(bool isLinked); 0166 0167 private: 0168 0169 class Private; 0170 Private* const d; 0171 }; 0172 0173 } // namespace DigikamGenericUnifiedPlugin 0174 0175 #endif // DIGIKAM_WS_AUTHENTICATION_PAGE_H