Commit 82a5d4b4 authored by Nicolas Fella's avatar Nicolas Fella

[nextcloud] Add webengine profile and url intercepter

parent e280db03
...@@ -16,7 +16,7 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" ${ECM_MODULE_P ...@@ -16,7 +16,7 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" ${ECM_MODULE_P
find_package(Intltool REQUIRED) find_package(Intltool REQUIRED)
find_package(KAccounts REQUIRED) find_package(KAccounts REQUIRED)
find_package(Qt5 ${QT_REQUIRED_VERSION} CONFIG REQUIRED Core Qml WebEngineWidgets) find_package(Qt5 ${QT_REQUIRED_VERSION} CONFIG REQUIRED Core Qml WebEngineWidgets WebEngine)
find_package(KF5 ${KF5_MIN_VERSION} REQUIRED KIO I18n Declarative Package) find_package(KF5 ${KF5_MIN_VERSION} REQUIRED KIO I18n Declarative Package)
include(KDEInstallDirs) include(KDEInstallDirs)
......
...@@ -10,6 +10,7 @@ add_library(nextcloud_plugin_kaccounts MODULE ...@@ -10,6 +10,7 @@ add_library(nextcloud_plugin_kaccounts MODULE
target_link_libraries(nextcloud_plugin_kaccounts target_link_libraries(nextcloud_plugin_kaccounts
Qt5::Core Qt5::Core
Qt5::WebEngineWidgets Qt5::WebEngineWidgets
Qt5::WebEngine
KF5::KIOCore KF5::KIOCore
KF5::I18n KF5::I18n
KF5::Declarative KF5::Declarative
......
...@@ -22,9 +22,21 @@ ...@@ -22,9 +22,21 @@
#include <QFileSystemWatcher> #include <QFileSystemWatcher>
#include <QDesktopServices> #include <QDesktopServices>
// Document for login flow : https://docs.nextcloud.com/server/stable/developer_manual/client_apis/LoginFlow/index.html
void NextcloudUrlIntercepter::interceptRequest(QWebEngineUrlRequestInfo &info)
{
info.setHttpHeader("OCS-APIREQUEST", "true");
}
NextcloudController::NextcloudController(QObject *parent) NextcloudController::NextcloudController(QObject *parent)
: QObject(parent) : QObject(parent)
, m_webengineProfile(new QQuickWebEngineProfile(this))
{ {
m_webengineProfile->setUrlRequestInterceptor(&m_urlIntercepter);
m_webengineProfile->setHttpUserAgent(QStringLiteral("Mozilla/5.0 nextcloud-ui-plugin"));
QDesktopServices::setUrlHandler("nc", this, "finalUrlHandler");
} }
NextcloudController::~NextcloudController() NextcloudController::~NextcloudController()
...@@ -88,6 +100,9 @@ void NextcloudController::fileChecked(KJob* job) ...@@ -88,6 +100,9 @@ void NextcloudController::fileChecked(KJob* job)
QUrl url = KIO::upUrl(kJob->url()); QUrl url = KIO::upUrl(kJob->url());
m_server = url.toString(); m_server = url.toString();
m_loginUrl = m_server + QStringLiteral("/index.php/login/flow");
Q_EMIT loginUrlChanged();
m_state = WebLogin; m_state = WebLogin;
Q_EMIT stateChanged(); Q_EMIT stateChanged();
// Call webview for login // Call webview for login
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
#include <QWebEngineView> #include <QWebEngineView>
#include <QWebEnginePage> #include <QWebEnginePage>
#include <QWebEngineHttpRequest> #include <QWebEngineHttpRequest>
#include <QWebEngineUrlRequestInterceptor>
#include <QQuickWebEngineProfile>
namespace KIO namespace KIO
{ {
...@@ -22,6 +24,11 @@ namespace KIO ...@@ -22,6 +24,11 @@ namespace KIO
class KJob; class KJob;
class NextcloudUrlIntercepter : public QWebEngineUrlRequestInterceptor
{
void interceptRequest(QWebEngineUrlRequestInfo &info) override;
};
class NextcloudController : public QObject class NextcloudController : public QObject
{ {
Q_OBJECT Q_OBJECT
...@@ -29,6 +36,8 @@ class NextcloudController : public QObject ...@@ -29,6 +36,8 @@ class NextcloudController : public QObject
Q_PROPERTY(bool isLoginComplete READ isLoginComplete NOTIFY isLoginCompleteChanged) Q_PROPERTY(bool isLoginComplete READ isLoginComplete NOTIFY isLoginCompleteChanged)
Q_PROPERTY(QString errorMessage READ errorMessage NOTIFY errorMessageChanged) Q_PROPERTY(QString errorMessage READ errorMessage NOTIFY errorMessageChanged)
Q_PROPERTY(State state MEMBER m_state NOTIFY stateChanged) Q_PROPERTY(State state MEMBER m_state NOTIFY stateChanged)
Q_PROPERTY(QQuickWebEngineProfile *webengineProfile MEMBER m_webengineProfile CONSTANT)
Q_PROPERTY(QString loginUrl MEMBER m_loginUrl NOTIFY loginUrlChanged)
public: public:
...@@ -54,6 +63,7 @@ Q_SIGNALS: ...@@ -54,6 +63,7 @@ Q_SIGNALS:
void isLoginCompleteChanged(); void isLoginCompleteChanged();
void wizardFinished(const QString &username, const QString &password, const QVariantMap &data); void wizardFinished(const QString &username, const QString &password, const QVariantMap &data);
void stateChanged(); void stateChanged();
void loginUrlChanged();
private Q_SLOTS: private Q_SLOTS:
void fileChecked(KJob *job); void fileChecked(KJob *job);
...@@ -80,6 +90,9 @@ private: ...@@ -80,6 +90,9 @@ private:
bool m_isWorking = false; bool m_isWorking = false;
bool m_isLoginComplete = false; bool m_isLoginComplete = false;
State m_state = ServerUrl; State m_state = ServerUrl;
QQuickWebEngineProfile *m_webengineProfile;
NextcloudUrlIntercepter m_urlIntercepter;
QString m_loginUrl;
}; };
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment