2017-11-23 01:00:57 +03:00
|
|
|
#include "webviewpage.h"
|
|
|
|
|
2017-11-23 13:32:08 +03:00
|
|
|
#include <QWebEngineUrlRequestJob>
|
2017-11-23 15:36:33 +03:00
|
|
|
#include <QProgressBar>
|
2017-11-29 00:25:35 +03:00
|
|
|
#include <QVBoxLayout>
|
2019-01-31 00:48:40 +03:00
|
|
|
#include <QNetworkProxyFactory>
|
2021-02-16 12:32:20 +03:00
|
|
|
#include <QScreen>
|
2017-11-23 13:32:08 +03:00
|
|
|
|
2023-07-10 12:51:24 +03:00
|
|
|
#include "account.h"
|
|
|
|
#include "common/utility.h"
|
2017-11-28 22:06:27 +03:00
|
|
|
#include "creds/webflowcredentials.h"
|
2023-07-10 12:51:24 +03:00
|
|
|
#include "owncloudwizard.h"
|
2017-11-29 00:25:35 +03:00
|
|
|
#include "webview.h"
|
2017-11-23 01:00:57 +03:00
|
|
|
|
|
|
|
namespace OCC {
|
|
|
|
|
2020-07-01 16:30:44 +03:00
|
|
|
Q_LOGGING_CATEGORY(lcWizardWebiewPage, "nextcloud.gui.wizard.webviewpage", QtInfoMsg)
|
2017-11-23 01:00:57 +03:00
|
|
|
|
2017-11-23 13:32:08 +03:00
|
|
|
|
2017-11-23 01:00:57 +03:00
|
|
|
WebViewPage::WebViewPage(QWidget *parent)
|
2017-11-29 00:25:35 +03:00
|
|
|
: AbstractCredentialsWizardPage()
|
2017-11-23 01:00:57 +03:00
|
|
|
{
|
2017-11-23 13:32:08 +03:00
|
|
|
_ocWizard = qobject_cast<OwncloudWizard *>(parent);
|
2017-11-23 01:00:57 +03:00
|
|
|
|
2017-11-29 00:25:35 +03:00
|
|
|
qCInfo(lcWizardWebiewPage()) << "Time for a webview!";
|
|
|
|
_webView = new WebView(this);
|
2017-11-23 01:00:57 +03:00
|
|
|
|
2020-05-18 21:54:23 +03:00
|
|
|
auto *layout = new QVBoxLayout(this);
|
2022-05-22 23:29:03 +03:00
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
2022-05-17 05:01:33 +03:00
|
|
|
layout->addWidget(_webView, 1);
|
2017-11-29 00:25:35 +03:00
|
|
|
setLayout(layout);
|
2017-11-23 01:00:57 +03:00
|
|
|
|
2017-11-29 00:25:35 +03:00
|
|
|
connect(_webView, &WebView::urlCatched, this, &WebViewPage::urlCatched);
|
2019-01-31 00:48:40 +03:00
|
|
|
|
2019-01-31 16:14:31 +03:00
|
|
|
//_useSystemProxy = QNetworkProxyFactory::usesSystemConfiguration();
|
2019-01-31 00:48:40 +03:00
|
|
|
}
|
|
|
|
|
2020-08-12 18:19:49 +03:00
|
|
|
WebViewPage::~WebViewPage() = default;
|
|
|
|
//{
|
|
|
|
// QNetworkProxyFactory::setUseSystemConfiguration(_useSystemProxy);
|
|
|
|
//}
|
2017-11-23 01:00:57 +03:00
|
|
|
|
|
|
|
void WebViewPage::initializePage() {
|
2019-01-31 16:14:31 +03:00
|
|
|
//QNetworkProxy::setApplicationProxy(QNetworkProxy::applicationProxy());
|
2019-01-31 00:48:40 +03:00
|
|
|
|
2018-06-21 17:15:30 +03:00
|
|
|
QString url;
|
|
|
|
if (_ocWizard->registration()) {
|
|
|
|
url = "https://nextcloud.com/register";
|
|
|
|
} else {
|
2023-07-10 12:51:24 +03:00
|
|
|
url = Utility::trailingSlashPath(_ocWizard->ocUrl()) + "index.php/login/flow";
|
2018-06-21 17:15:30 +03:00
|
|
|
}
|
2017-11-29 00:25:35 +03:00
|
|
|
qCInfo(lcWizardWebiewPage()) << "Url to auth at: " << url;
|
|
|
|
_webView->setUrl(QUrl(url));
|
2021-02-16 12:32:20 +03:00
|
|
|
|
|
|
|
_originalWizardSize = _ocWizard->size();
|
|
|
|
resizeWizard();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebViewPage::resizeWizard()
|
|
|
|
{
|
|
|
|
// The webview needs a little bit more space
|
|
|
|
auto wizardSizeChanged = tryToSetWizardSize(_originalWizardSize.width() * 2, _originalWizardSize.height() * 2);
|
|
|
|
|
|
|
|
if (!wizardSizeChanged) {
|
|
|
|
wizardSizeChanged = tryToSetWizardSize(static_cast<int>(_originalWizardSize.width() * 1.5), static_cast<int>(_originalWizardSize.height() * 1.5));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wizardSizeChanged) {
|
|
|
|
_ocWizard->centerWindow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WebViewPage::tryToSetWizardSize(int width, int height)
|
|
|
|
{
|
|
|
|
const auto window = _ocWizard->window();
|
|
|
|
const auto screenGeometry = QGuiApplication::screenAt(window->pos())->geometry();
|
|
|
|
const auto windowWidth = screenGeometry.width();
|
|
|
|
const auto windowHeight = screenGeometry.height();
|
|
|
|
|
|
|
|
if (width < windowWidth && height < windowHeight) {
|
|
|
|
_ocWizard->resize(width, height);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebViewPage::cleanupPage()
|
|
|
|
{
|
|
|
|
_ocWizard->resize(_originalWizardSize);
|
|
|
|
_ocWizard->centerWindow();
|
2017-11-23 01:00:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int WebViewPage::nextId() const {
|
|
|
|
return WizardCommon::Page_AdvancedSetup;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WebViewPage::isComplete() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
AbstractCredentials* WebViewPage::getCredentials() const {
|
2017-11-28 22:06:27 +03:00
|
|
|
return new WebFlowCredentials(_user, _pass, _ocWizard->_clientSslCertificate, _ocWizard->_clientSslKey);
|
2017-11-23 01:00:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebViewPage::setConnected() {
|
2017-11-23 15:36:33 +03:00
|
|
|
qCInfo(lcWizardWebiewPage()) << "YAY! we are connected!";
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebViewPage::urlCatched(QString user, QString pass, QString host) {
|
2018-04-23 22:28:03 +03:00
|
|
|
qCInfo(lcWizardWebiewPage()) << "Got user: " << user << ", server: " << host;
|
2017-11-23 15:36:33 +03:00
|
|
|
|
|
|
|
_user = user;
|
|
|
|
_pass = pass;
|
2017-11-23 01:00:57 +03:00
|
|
|
|
2018-03-29 13:39:04 +03:00
|
|
|
AccountPtr account = _ocWizard->account();
|
|
|
|
account->setUrl(host);
|
|
|
|
|
2017-11-23 15:36:33 +03:00
|
|
|
qCInfo(lcWizardWebiewPage()) << "URL: " << field("OCUrl").toString();
|
2018-03-29 13:39:04 +03:00
|
|
|
emit connectToOCUrl(host);
|
2017-11-23 01:00:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|