forked from owncloud/client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathowncloudwizard.cpp
More file actions
300 lines (251 loc) · 8.96 KB
/
Copy pathowncloudwizard.cpp
File metadata and controls
300 lines (251 loc) · 8.96 KB
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
/*
* Copyright (C) by Klaas Freitag <freitag@owncloud.com>
* Copyright (C) by Krzesimir Nowak <krzesimir@endocode.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include "account.h"
#include "config.h"
#include "configfile.h"
#include "theme.h"
#include "application.h"
#include "settingsdialog.h"
#include "wizard/owncloudwizard.h"
#include "wizard/owncloudsetuppage.h"
#include "wizard/owncloudhttpcredspage.h"
#include "wizard/owncloudoauthcredspage.h"
#include "wizard/owncloudadvancedsetuppage.h"
#include "common/vfs.h"
#include "QProgressIndicator.h"
#include <QtCore>
#include <QtGui>
#include <QMessageBox>
#include <owncloudgui.h>
#include <stdlib.h>
namespace {
auto initLocalFolder()
{
auto localFolder = OCC::Theme::instance()->defaultClientFolder();
// Update the local folder - this is not guaranteed to find a good one
// if its a relative path, prepend with users home dir, otherwise use as absolute path
if (!QDir(localFolder).isAbsolute()) {
localFolder = QDir::homePath() + QDir::separator() + localFolder;
}
return OCC::FolderMan::instance()->findGoodPathForNewSyncFolder(localFolder);
}
}
namespace OCC {
Q_LOGGING_CATEGORY(lcWizard, "gui.wizard", QtInfoMsg)
OwncloudWizard::OwncloudWizard(QWidget *parent)
: QWizard(parent, Qt::WindowFlags() & ~Qt::WindowContextHelpButtonHint)
, _remoteFolder(Theme::instance()->defaultServerFolder())
, _localFolder(initLocalFolder())
, _useVirtualFileSync(bestAvailableVfsMode() == Vfs::WindowsCfApi)
, _account(nullptr)
, _setupPage(new OwncloudSetupPage(this))
, _httpCredsPage(new OwncloudHttpCredsPage(this))
, _oauthCredsPage(new OwncloudOAuthCredsPage)
, _advancedSetupPage(new OwncloudAdvancedSetupPage)
, _credentialsPage(nullptr)
{
setObjectName("owncloudWizard");
setPage(WizardCommon::Page_ServerSetup, _setupPage);
setPage(WizardCommon::Page_HttpCreds, _httpCredsPage);
setPage(WizardCommon::Page_OAuthCreds, _oauthCredsPage);
setPage(WizardCommon::Page_AdvancedSetup, _advancedSetupPage);
connect(this, &QDialog::finished, this, &OwncloudWizard::basicSetupFinished);
// note: start Id is set by the calling class depending on if the
// welcome text is to be shown or not.
setWizardStyle(QWizard::ModernStyle);
connect(this, &QWizard::currentIdChanged, this, &OwncloudWizard::slotCurrentPageChanged);
connect(_setupPage, &OwncloudSetupPage::determineAuthType, this, &OwncloudWizard::determineAuthType);
connect(_httpCredsPage, &OwncloudHttpCredsPage::connectToOCUrl, this, &OwncloudWizard::connectToOCUrl);
connect(_oauthCredsPage, &OwncloudOAuthCredsPage::connectToOCUrl, this, &OwncloudWizard::connectToOCUrl);
// banner size requires a fixed size
setFixedSize(ocApp()->gui()->settingsDialog()->sizeHintForChild());
Theme *theme = Theme::instance();
setWindowTitle(tr("%1 Connection Wizard").arg(theme->appNameGUI()));
setWizardStyle(QWizard::ModernStyle);
setPixmap(QWizard::BannerPixmap, theme->wizardHeaderBanner({ width(), 78 }));
setPixmap(QWizard::LogoPixmap, theme->wizardHeaderLogo().pixmap(132, 63));
setOption(QWizard::NoBackButtonOnStartPage);
setOption(QWizard::NoBackButtonOnLastPage);
setOption(QWizard::NoCancelButton, false);
setOption(QWizard::CancelButtonOnLeft);
setTitleFormat(Qt::RichText);
setSubTitleFormat(Qt::RichText);
}
void OwncloudWizard::setAccount(AccountPtr account)
{
_account = account;
}
AccountPtr OwncloudWizard::account() const
{
return _account;
}
const QString &OwncloudWizard::localFolder() const
{
return _localFolder;
}
void OwncloudWizard::setLocalFolder(const QString &newLocalFolder)
{
_localFolder = newLocalFolder;
}
QStringList OwncloudWizard::selectiveSyncBlacklist() const
{
return _advancedSetupPage->selectiveSyncBlacklist();
}
bool OwncloudWizard::useVirtualFileSync() const
{
return _useVirtualFileSync;
}
bool OwncloudWizard::manualFolderConfig() const
{
return _advancedSetupPage->manualFolderConfig();
}
bool OwncloudWizard::isConfirmBigFolderChecked() const
{
return _advancedSetupPage->isConfirmBigFolderChecked();
}
QString OwncloudWizard::ocUrl() const
{
QString url = field("OCUrl").toString().simplified();
return url;
}
void OwncloudWizard::setRemoteFolder(const QString &remoteFolder)
{
_remoteFolder = remoteFolder;
}
void OwncloudWizard::successfulStep()
{
const int id(currentId());
switch (id) {
case WizardCommon::Page_HttpCreds:
_httpCredsPage->setConnected();
break;
case WizardCommon::Page_OAuthCreds:
_oauthCredsPage->setConnected();
break;
case WizardCommon::Page_AdvancedSetup:
_advancedSetupPage->directoriesCreated();
break;
case WizardCommon::Page_ServerSetup:
qCWarning(lcWizard, "Should not happen at this stage.");
break;
}
ownCloudGui::raiseDialog(this);
if (nextId() == -1) {
disconnect(this, &QDialog::finished, this, &OwncloudWizard::basicSetupFinished);
emit basicSetupFinished(QDialog::Accepted);
} else {
next();
}
}
void OwncloudWizard::setUseVirtualFileSync(bool newUseVirtualFileSync)
{
_useVirtualFileSync = newUseVirtualFileSync;
}
const QString &OwncloudWizard::remoteFolder() const
{
return _remoteFolder;
}
void OwncloudWizard::resetRemoteFolder()
{
_remoteFolder = Theme::instance()->defaultServerFolder();
}
DetermineAuthTypeJob::AuthType OwncloudWizard::authType() const
{
return _authType;
}
void OwncloudWizard::setAuthType(DetermineAuthTypeJob::AuthType type)
{
_authType = type;
_setupPage->setAuthType();
if (type == DetermineAuthTypeJob::AuthType::OAuth) {
_credentialsPage = _oauthCredsPage;
} else { // try Basic auth even for "Unknown"
_credentialsPage = _httpCredsPage;
}
next();
}
// TODO: update this function
void OwncloudWizard::slotCurrentPageChanged(int id)
{
qCDebug(lcWizard) << "Current Wizard page changed to " << id;
if (id == WizardCommon::Page_ServerSetup) {
emit clearPendingRequests();
}
}
void OwncloudWizard::displayError(const QString &msg)
{
switch (currentId()) {
case WizardCommon::Page_ServerSetup:
_setupPage->setErrorString(msg);
break;
case WizardCommon::Page_HttpCreds:
_httpCredsPage->setErrorString(msg);
break;
case WizardCommon::Page_AdvancedSetup:
_advancedSetupPage->setErrorString(msg);
break;
}
}
void OwncloudWizard::setOCUrl(const QString &url)
{
_setupPage->setServerUrl(url);
}
AbstractCredentials *OwncloudWizard::getCredentials() const
{
if (_credentialsPage) {
return _credentialsPage->getCredentials();
}
return nullptr;
}
void OwncloudWizard::askExperimentalVirtualFilesFeature(QWidget *receiver, const std::function<void(bool enable)> &callback)
{
const auto bestVfsMode = bestAvailableVfsMode();
QMessageBox *msgBox = nullptr;
QPushButton *acceptButton = nullptr;
switch (bestVfsMode)
{
case Vfs::WindowsCfApi:
callback(true);
return;
case Vfs::WithSuffix:
msgBox = new QMessageBox(
QMessageBox::Warning,
tr("Enable experimental feature?"),
tr("When the \"virtual files\" mode is enabled no files will be downloaded initially. "
"Instead, a tiny \"%1\" file will be created for each file that exists on the server. "
"The contents can be downloaded by running these files or by using their context menu."
"\n\n"
"The virtual files mode is mutually exclusive with selective sync. "
"Currently unselected folders will be translated to online-only folders "
"and your selective sync settings will be reset."
"\n\n"
"Switching to this mode will abort any currently running synchronization."
"\n\n"
"This is a new, experimental mode. If you decide to use it, please report any "
"issues that come up.")
.arg(APPLICATION_DOTVIRTUALFILE_SUFFIX), QMessageBox::NoButton, receiver);
acceptButton = msgBox->addButton(tr("Enable experimental placeholder mode"), QMessageBox::AcceptRole);
msgBox->addButton(tr("Stay safe"), QMessageBox::RejectRole);
break;
case Vfs::Off:
Q_UNREACHABLE();
}
connect(msgBox, &QMessageBox::accepted, receiver, [callback, msgBox, acceptButton] {
callback(msgBox->clickedButton() == acceptButton);
msgBox->deleteLater();
});
msgBox->open();
}
} // end namespace