Welcome to mirror list, hosted at ThFree Co, Russian Federation.

webviewpage.cpp « wizard « gui « src - github.com/nextcloud/desktop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7aae73fc8866eaf55404de953ca22919cfab9ea0 (plain)
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
#include "webviewpage.h"

#include <QWebEngineUrlRequestJob>
#include <QProgressBar>
#include <QVBoxLayout>
#include <QNetworkProxyFactory>
#include <QScreen>

#include "owncloudwizard.h"
#include "creds/webflowcredentials.h"
#include "webview.h"
#include "account.h"

namespace OCC {

Q_LOGGING_CATEGORY(lcWizardWebiewPage, "nextcloud.gui.wizard.webviewpage", QtInfoMsg)


WebViewPage::WebViewPage(QWidget *parent)
    : AbstractCredentialsWizardPage()
{
    _ocWizard = qobject_cast<OwncloudWizard *>(parent);

    qCInfo(lcWizardWebiewPage()) << "Time for a webview!";
    _webView = new WebView(this);

    auto *layout = new QVBoxLayout(this);
    layout->setMargin(0);
    layout->addWidget(_webView);
    setLayout(layout);

    connect(_webView, &WebView::urlCatched, this, &WebViewPage::urlCatched);

    //_useSystemProxy = QNetworkProxyFactory::usesSystemConfiguration();
}

WebViewPage::~WebViewPage() = default;
//{
//    QNetworkProxyFactory::setUseSystemConfiguration(_useSystemProxy);
//}

void WebViewPage::initializePage() {
    //QNetworkProxy::setApplicationProxy(QNetworkProxy::applicationProxy());

    QString url;
    if (_ocWizard->registration()) {
        url = "https://nextcloud.com/register";
    } else {
        url = _ocWizard->ocUrl();
        if (!url.endsWith('/')) {
            url += "/";
        }
        url += "index.php/login/flow";
    }
    qCInfo(lcWizardWebiewPage()) << "Url to auth at: " << url;
    _webView->setUrl(QUrl(url));

    _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();
}

int WebViewPage::nextId() const {
    return WizardCommon::Page_AdvancedSetup;
}

bool WebViewPage::isComplete() const {
    return false;
}

AbstractCredentials* WebViewPage::getCredentials() const {
    return new WebFlowCredentials(_user, _pass, _ocWizard->_clientSslCertificate, _ocWizard->_clientSslKey);
}

void WebViewPage::setConnected() {
    qCInfo(lcWizardWebiewPage()) << "YAY! we are connected!";
}

void WebViewPage::urlCatched(QString user, QString pass, QString host) {
    qCInfo(lcWizardWebiewPage()) << "Got user: " << user << ", server: " << host;

    _user = user;
    _pass = pass;

    AccountPtr account = _ocWizard->account();
    account->setUrl(host);

    qCInfo(lcWizardWebiewPage()) << "URL: " << field("OCUrl").toString();
    emit connectToOCUrl(host);
}

}