-
Notifications
You must be signed in to change notification settings - Fork 671
/
Copy pathaccountsettings.cpp
659 lines (572 loc) · 26.6 KB
/
accountsettings.cpp
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
/*
* Copyright (C) by Daniel Molkentin <danimo@owncloud.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 "accountsettings.h"
#include "ui_accountsettings.h"
#include "account.h"
#include "accountmanager.h"
#include "accountstate.h"
#include "application.h"
#include "common/utility.h"
#include "commonstrings.h"
#include "configfile.h"
#include "creds/httpcredentialsgui.h"
#include "folderman.h"
#include "folderstatusmodel.h"
#include "folderwizard/folderwizard.h"
#include "gui/accountmodalwidget.h"
#include "gui/models/models.h"
#include "gui/networkinformation.h"
#include "gui/qmlutils.h"
#include "gui/selectivesyncwidget.h"
#include "gui/spaces/spaceimageprovider.h"
#include "guiutility.h"
#include "libsync/graphapi/spacesmanager.h"
#include "oauthloginwidget.h"
#include "quotainfo.h"
#include "scheduling/syncscheduler.h"
#include "settingsdialog.h"
#include "theme.h"
#include <QAction>
#include <QMessageBox>
#include <QSortFilterProxyModel>
#include <QtQuickWidgets/QtQuickWidgets>
namespace {
constexpr auto modalWidgetStretchedMarginC = 50;
}
namespace OCC {
Q_LOGGING_CATEGORY(lcAccountSettings, "gui.account.settings", QtInfoMsg)
AccountSettings::AccountSettings(const AccountStatePtr &accountState, QWidget *parent)
: QWidget(parent)
, ui(new Ui::AccountSettings)
, _wasDisabledBefore(false)
, _accountState(accountState)
{
ui->setupUi(this);
_model = new FolderStatusModel(this);
_model->setAccountState(_accountState);
auto weightedModel = new QSortFilterProxyModel(this);
weightedModel->setSourceModel(_model);
weightedModel->setSortRole(static_cast<int>(FolderStatusModel::Roles::Priority));
weightedModel->sort(0, Qt::DescendingOrder);
_sortModel = weightedModel;
ui->quickWidget->engine()->addImageProvider(QStringLiteral("space"), new Spaces::SpaceImageProvider(_accountState->account()));
ui->quickWidget->setOCContext(QUrl(QStringLiteral("qrc:/qt/qml/org/ownCloud/gui/qml/FolderDelegate.qml")), this);
connect(FolderMan::instance(), &FolderMan::folderListChanged, _model, &FolderStatusModel::resetFolders);
if (accountsState()->supportsSpaces()) {
connect(accountsState()->account()->spacesManager(), &GraphApi::SpacesManager::updated, this, &AccountSettings::slotSpacesUpdated);
}
ui->connectionStatusLabel->clear();
connect(_accountState.data(), &AccountState::stateChanged, this, &AccountSettings::slotAccountStateChanged);
slotAccountStateChanged();
connect(ui->manageAccountButton, &QToolButton::clicked, this, [this] {
QMenu *menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose);
menu->setAccessibleName(tr("Account options menu"));
menu->addAction(_accountState->isSignedOut() ? tr("Log in") : tr("Log out"), this, &AccountSettings::slotToggleSignInState);
auto *reconnectAction = menu->addAction(tr("Reconnect"), this, [this] { _accountState->checkConnectivity(true); });
reconnectAction->setEnabled(!_accountState->isConnected() && !_accountState->isSignedOut());
menu->addAction(CommonStrings::showInWebBrowser(), this, [this] { QDesktopServices::openUrl(_accountState->account()->url()); });
menu->addAction(tr("Remove"), this, &AccountSettings::slotDeleteAccount);
menu->popup(mapToGlobal(ui->manageAccountButton->pos()));
// set the focus for accessability
menu->setFocus();
});
connect(_accountState.get(), &AccountState::isSettingUpChanged, this, [this] {
if (_accountState->isSettingUp()) {
ui->spinner->startAnimation();
ui->stackedWidget->setCurrentWidget(ui->loadingPage);
} else {
ui->spinner->stopAnimation();
ui->stackedWidget->setCurrentWidget(ui->quickWidget);
}
});
connect(ui->stackedWidget, &QStackedWidget::currentChanged, this,
[this] { ui->manageAccountButton->setEnabled(ui->stackedWidget->currentWidget() == ui->quickWidget); });
ui->stackedWidget->setCurrentWidget(ui->quickWidget);
}
void AccountSettings::slotToggleSignInState()
{
if (_accountState->isSignedOut()) {
_accountState->signIn();
} else {
_accountState->signOutByUi();
}
}
void AccountSettings::slotCustomContextMenuRequested(Folder *folder)
{
// qpointer for async calls
const auto isDeployed = folder->isDeployed();
const auto addRemoveFolderAction = [isDeployed, folder, this](QMenu *menu) {
Q_ASSERT(!isDeployed);
return menu->addAction(tr("Remove folder sync connection"), this, [folder, this] { slotRemoveCurrentFolder(folder); });
};
auto *menu = new QMenu(ui->quickWidget);
menu->setAccessibleName(tr("Sync options menu"));
menu->setAttribute(Qt::WA_DeleteOnClose);
connect(folder, &OCC::Folder::destroyed, menu, &QMenu::close);
// Only allow removal if the item isn't in "ready" state.
if (!folder->isReady() && !isDeployed) {
if (Theme::instance()->syncNewlyDiscoveredSpaces()) {
menu->addAction(tr("Folder is not ready yet"))->setEnabled(false);
} else {
addRemoveFolderAction(menu);
}
menu->popup(QCursor::pos());
// accassebility
menu->setFocus();
return;
}
// Add an action to open the folder in the system's file browser:
const QUrl folderUrl = QUrl::fromLocalFile(folder->path());
if (!folderUrl.isEmpty()) {
QAction *ac = menu->addAction(CommonStrings::showInFileBrowser(), [folderUrl]() {
qCInfo(lcAccountSettings) << "Opening local folder" << folderUrl;
if (!QDesktopServices::openUrl(folderUrl)) {
qCWarning(lcAccountSettings) << "QDesktopServices::openUrl failed for" << folderUrl;
}
});
if (!QFile::exists(folderUrl.toLocalFile())) {
ac->setEnabled(false);
}
}
// Add an action to open the folder on the server in a webbrowser:
if (folder->accountState()->account()->capabilities().privateLinkPropertyAvailable()) {
QString path = folder->remotePathTrailingSlash();
menu->addAction(CommonStrings::showInWebBrowser(), [path, davUrl = folder->webDavUrl(), this] {
fetchPrivateLinkUrl(_accountState->account(), davUrl, path, this, [](const QUrl &url) { Utility::openBrowser(url, nullptr); });
});
}
// Root-folder specific actions:
menu->addSeparator();
bool folderPaused = folder->syncPaused();
bool folderConnected = folder->accountState()->isConnected();
// qpointer for the async context menu
if (OC_ENSURE(folder->isReady())) {
if (!folderPaused) {
QAction *ac = menu->addAction(tr("Force sync now"));
if (folder->isSyncRunning()) {
ac->setText(tr("Restart sync"));
}
ac->setEnabled(folderConnected);
connect(ac, &QAction::triggered, this, [folder, this] { slotForceSyncCurrentFolder(folder); });
}
QAction *ac = menu->addAction(folderPaused ? tr("Resume sync") : tr("Pause sync"));
connect(ac, &QAction::triggered, this, [folder, this] { slotEnableCurrentFolder(folder, true); });
if (!isDeployed) {
if (!Theme::instance()->syncNewlyDiscoveredSpaces()) {
addRemoveFolderAction(menu);
}
if (Theme::instance()->showVirtualFilesOption()) {
if (folder->virtualFilesEnabled()) {
if (!Theme::instance()->forceVirtualFilesOption()) {
menu->addAction(tr("Disable virtual file support"), this, [folder, this] { slotDisableVfsCurrentFolder(folder); });
} else {
const auto mode = VfsPluginManager::instance().bestAvailableVfsMode();
if (FolderMan::instance()->checkVfsAvailability(folder->path(), mode)) {
if (mode == Vfs::WindowsCfApi) {
ac = menu->addAction(tr("Enable virtual file support"));
connect(ac, &QAction::triggered, this, [folder, this] { slotEnableVfsCurrentFolder(folder); });
}
}
}
}
}
if (!folder->virtualFilesEnabled()) {
menu->addAction(tr("Choose what to sync"), this, [folder, this] { showSelectiveSyncDialog(folder); });
}
menu->popup(QCursor::pos());
// accassebility
menu->setFocus();
} else {
menu->deleteLater();
}
}
}
void AccountSettings::showSelectiveSyncDialog(Folder *folder)
{
auto *selectiveSync = new SelectiveSyncWidget(_accountState->account(), this);
selectiveSync->setDavUrl(folder->webDavUrl());
bool ok;
selectiveSync->setFolderInfo(
folder->remotePath(), folder->displayName(), folder->journalDb()->getSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, &ok));
Q_ASSERT(ok);
auto *modalWidget = new AccountModalWidget(tr("Choose what to sync"), selectiveSync, this);
modalWidget->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
connect(modalWidget, &AccountModalWidget::accepted, this, [selectiveSync, folder, this] {
folder->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, selectiveSync->createBlackList());
doForceSyncCurrentFolder(folder);
});
addModalWidget(modalWidget);
}
void AccountSettings::slotAddFolder()
{
FolderMan::instance()->setSyncEnabled(false); // do not start more syncs.
FolderWizard *folderWizard = new FolderWizard(_accountState, this);
folderWizard->setAttribute(Qt::WA_DeleteOnClose);
connect(folderWizard, &QDialog::accepted, this, &AccountSettings::slotFolderWizardAccepted);
connect(folderWizard, &QDialog::rejected, this, [] {
qCInfo(lcAccountSettings) << "Folder wizard cancelled";
FolderMan::instance()->setSyncEnabled(true);
});
addModalLegacyDialog(folderWizard, AccountSettings::ModalWidgetSizePolicy::Expanding);
}
void AccountSettings::slotFolderWizardAccepted()
{
FolderWizard *folderWizard = qobject_cast<FolderWizard *>(sender());
qCInfo(lcAccountSettings) << "Folder wizard completed";
const auto config = folderWizard->result();
auto folder = FolderMan::instance()->addFolderFromFolderWizardResult(_accountState, config);
if (!config.selectiveSyncBlackList.isEmpty() && OC_ENSURE(folder && !config.useVirtualFiles)) {
folder->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, config.selectiveSyncBlackList);
// The user already accepted the selective sync dialog. everything is in the white list
folder->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncWhiteList, {QLatin1String("/")});
}
FolderMan::instance()->setSyncEnabled(true);
FolderMan::instance()->scheduleAllFolders();
}
void AccountSettings::slotRemoveCurrentFolder(Folder *folder)
{
qCInfo(lcAccountSettings) << "Remove Folder " << folder->path();
QString shortGuiLocalPath = folder->shortGuiLocalPath();
auto messageBox = new QMessageBox(QMessageBox::Question, tr("Confirm Folder Sync Connection Removal"),
tr("<p>Do you really want to stop syncing the folder <i>%1</i>?</p>"
"<p><b>Note:</b> This will <b>not</b> delete any files.</p>")
.arg(shortGuiLocalPath),
QMessageBox::NoButton, ocApp()->gui()->settingsDialog());
messageBox->setAttribute(Qt::WA_DeleteOnClose);
QPushButton *yesButton = messageBox->addButton(tr("Remove Folder Sync Connection"), QMessageBox::YesRole);
messageBox->addButton(tr("Cancel"), QMessageBox::NoRole);
connect(messageBox, &QMessageBox::finished, this, [messageBox, yesButton, folder, this] {
if (messageBox->clickedButton() == yesButton) {
FolderMan::instance()->removeFolder(folder);
QTimer::singleShot(0, this, &AccountSettings::slotSpacesUpdated);
}
});
messageBox->open();
}
void AccountSettings::slotEnableVfsCurrentFolder(Folder *folder)
{
if (OC_ENSURE(VfsPluginManager::instance().bestAvailableVfsMode() == Vfs::WindowsCfApi)) {
if (!folder) {
return;
}
qCInfo(lcAccountSettings) << "Enabling vfs support for folder" << folder->path();
// Change the folder vfs mode and load the plugin
folder->setVirtualFilesEnabled(true);
// don't schedule the folder, it might not be ready yet.
// it will schedule its self once set up
}
}
void AccountSettings::slotDisableVfsCurrentFolder(Folder *folder)
{
auto msgBox = new QMessageBox(
QMessageBox::Question,
tr("Disable virtual file support?"),
tr("This action will disable virtual file support. As a consequence contents of folders that "
"are currently marked as 'available online only' will be downloaded."
"\n\n"
"The only advantage of disabling virtual file support is that the selective sync feature "
"will become available again."
"\n\n"
"This action will abort any currently running synchronization."));
auto acceptButton = msgBox->addButton(tr("Disable support"), QMessageBox::AcceptRole);
msgBox->addButton(tr("Cancel"), QMessageBox::RejectRole);
connect(msgBox, &QMessageBox::finished, msgBox, [msgBox, folder, acceptButton] {
msgBox->deleteLater();
if (msgBox->clickedButton() != acceptButton || !folder) {
return;
}
qCInfo(lcAccountSettings) << "Disabling vfs support for folder" << folder->path();
// Also wipes virtual files, schedules remote discovery
folder->setVirtualFilesEnabled(false);
});
msgBox->open();
}
void AccountSettings::showConnectionLabel(const QString &message, QStringList errors)
{
if (errors.isEmpty()) {
ui->connectionStatusLabel->setText(message);
ui->connectionStatusLabel->setToolTip(QString());
} else {
errors.prepend(message);
const QString msg = errors.join(QLatin1String("\n"));
qCDebug(lcAccountSettings) << msg;
ui->connectionStatusLabel->setText(msg);
ui->connectionStatusLabel->setToolTip(QString());
}
ui->accountStatus->setVisible(!message.isEmpty());
ui->warningLabel->setVisible(!errors.isEmpty());
}
void AccountSettings::slotEnableCurrentFolder(Folder *folder, bool terminate)
{
Q_ASSERT(folder);
qCInfo(lcAccountSettings) << "Application: enable folder with alias " << folder->path();
bool currentlyPaused = false;
// this sets the folder status to disabled but does not interrupt it.
currentlyPaused = folder->syncPaused();
if (!currentlyPaused && !terminate) {
// check if a sync is still running and if so, ask if we should terminate.
if (folder->isSyncRunning()) { // its still running
auto msgbox = new QMessageBox(QMessageBox::Question, tr("Sync Running"), tr("The sync operation is running.<br/>Do you want to stop it?"),
QMessageBox::Yes | QMessageBox::No, this);
msgbox->setAttribute(Qt::WA_DeleteOnClose);
msgbox->setDefaultButton(QMessageBox::Yes);
connect(msgbox, &QMessageBox::accepted, this, [folder = QPointer<Folder>(folder), this] {
if (folder) {
slotEnableCurrentFolder(folder, true);
}
});
msgbox->open();
return;
}
}
// message box can return at any time while the thread keeps running,
// so better check again after the user has responded.
if (folder->isSyncRunning() && terminate) {
folder->slotTerminateSync(tr("Sync paused by user"));
}
folder->slotNextSyncFullLocalDiscovery(); // ensure we don't forget about local errors
folder->setSyncPaused(!currentlyPaused);
// keep state for the icon setting.
if (currentlyPaused)
_wasDisabledBefore = true;
_model->slotUpdateFolderState(folder);
}
void AccountSettings::slotForceSyncCurrentFolder(Folder *folder)
{
if (NetworkInformation::instance()->isMetered() && ConfigFile().pauseSyncWhenMetered()) {
auto messageBox = new QMessageBox(QMessageBox::Question, tr("Internet connection is metered"),
tr("Synchronization is paused because the Internet connection is a metered connection"
"<p>Do you really want to force a Synchronization now?"),
QMessageBox::Yes | QMessageBox::No, ocApp()->gui()->settingsDialog());
messageBox->setAttribute(Qt::WA_DeleteOnClose);
connect(messageBox, &QMessageBox::accepted, this, [folder = QPointer<Folder>(folder), this] {
if (folder) {
doForceSyncCurrentFolder(folder);
}
});
ownCloudGui::raise();
messageBox->open();
} else {
doForceSyncCurrentFolder(folder);
}
}
void AccountSettings::doForceSyncCurrentFolder(Folder *selectedFolder)
{
// Prevent new sync starts
FolderMan::instance()->scheduler()->stop();
// Terminate and reschedule any running sync
for (auto *folder : FolderMan::instance()->folders()) {
if (folder->isSyncRunning()) {
folder->slotTerminateSync(tr("User triggered force sync"));
FolderMan::instance()->scheduler()->enqueueFolder(folder);
}
}
selectedFolder->slotWipeErrorBlacklist(); // issue #6757
selectedFolder->slotNextSyncFullLocalDiscovery(); // ensure we don't forget about local errors
// Insert the selected folder at the front of the queue
FolderMan::instance()->scheduler()->enqueueFolder(selectedFolder, SyncScheduler::Priority::High);
// Restart scheduler
FolderMan::instance()->scheduler()->start();
}
void AccountSettings::slotAccountStateChanged()
{
const AccountState::State state = _accountState->state();
const AccountPtr account = _accountState->account();
qCDebug(lcAccountSettings) << "Account state changed to" << state << "for account" << account;
FolderMan *folderMan = FolderMan::instance();
for (auto *folder : folderMan->folders()) {
_model->slotUpdateFolderState(folder);
}
switch (state) {
case AccountState::Connected: {
QStringList errors;
if (account->serverSupportLevel() != Account::ServerSupportLevel::Supported) {
errors << tr("The server version %1 is unsupported! Proceed at your own risk.").arg(account->capabilities().status().versionString());
}
showConnectionLabel(tr("Connected"), errors);
break;
}
case AccountState::ServiceUnavailable:
showConnectionLabel(tr("Server is temporarily unavailable"));
break;
case AccountState::MaintenanceMode:
showConnectionLabel(tr("Server is currently in maintenance mode"));
break;
case AccountState::SignedOut:
showConnectionLabel(tr("Signed out"));
break;
case AccountState::AskingCredentials: {
showConnectionLabel(tr("Updating credentials..."));
break;
}
case AccountState::Connecting:
if (NetworkInformation::instance()->isBehindCaptivePortal()) {
showConnectionLabel(tr("Captive portal prevents connections to the server."));
} else if (NetworkInformation::instance()->isMetered() && ConfigFile().pauseSyncWhenMetered()) {
showConnectionLabel(tr("Sync is paused due to metered internet connection"));
} else {
showConnectionLabel(tr("Connecting..."));
}
break;
case AccountState::ConfigurationError:
showConnectionLabel(tr("Server configuration error"), _accountState->connectionErrors());
break;
case AccountState::NetworkError:
// don't display the error to the user, https://github.com/owncloud/client/issues/9790
[[fallthrough]];
case AccountState::Disconnected:
showConnectionLabel(tr("Disconnected"));
break;
}
}
void AccountSettings::slotSpacesUpdated()
{
auto spaces = accountsState()->account()->spacesManager()->spaces();
auto unsycnedSpaces = std::set<GraphApi::Space *>(spaces.cbegin(), spaces.cend());
for (const auto &f : std::as_const(FolderMan::instance()->folders())) {
unsycnedSpaces.erase(f->space());
}
// Check if we should add new spaces automagically, or only signal that there are unsynced spaces.
if (Theme::instance()->syncNewlyDiscoveredSpaces()) {
QTimer::singleShot(0, [this, unsycnedSpaces]() {
auto accountStatePtr = accountsState();
for (GraphApi::Space *newSpace : unsycnedSpaces) {
// TODO: Problem: when a space is manually removed, this will re-add it!
qCInfo(lcAccountSettings) << "Adding sync connection for newly discovered space" << newSpace->displayName();
const QString localDir(accountsState()->account()->defaultSyncRoot());
const QString folderName =
FolderMan::instance()->findGoodPathForNewSyncFolder(localDir, newSpace->displayName(), FolderMan::NewFolderType::SpacesFolder);
FolderMan::SyncConnectionDescription fwr;
fwr.davUrl = QUrl(newSpace->drive().getRoot().getWebDavUrl());
fwr.spaceId = newSpace->drive().getRoot().getId();
fwr.localPath = folderName;
fwr.displayName = newSpace->displayName();
fwr.useVirtualFiles = Utility::isWindows() ? Theme::instance()->showVirtualFilesOption() : false;
fwr.priority = newSpace->priority();
FolderMan::instance()->addFolderFromFolderWizardResult(accountStatePtr, fwr);
}
_unsyncedSpaces = 0;
_syncedSpaces = accountsState()->account()->spacesManager()->spaces().size();
Q_EMIT unsyncedSpacesChanged();
Q_EMIT syncedSpacesChanged();
});
} else {
if (_unsyncedSpaces != unsycnedSpaces.size()) {
_unsyncedSpaces = static_cast<uint>(unsycnedSpaces.size());
Q_EMIT unsyncedSpacesChanged();
}
uint syncedSpaces = spaces.size() - _unsyncedSpaces;
if (_syncedSpaces != syncedSpaces) {
_syncedSpaces = syncedSpaces;
Q_EMIT syncedSpacesChanged();
}
}
}
AccountSettings::~AccountSettings()
{
_goingDown = true;
delete ui;
}
void AccountSettings::addModalLegacyDialog(QWidget *widget, ModalWidgetSizePolicy sizePolicy)
{
if (!widget->testAttribute(Qt::WA_DeleteOnClose)) { // DEBUG CODE! See https://github.com/owncloud/client/issues/11673
// Early check to see if the attribute gets unset before the second/real check below
qCWarning(lcAccountSettings) << "Missing WA_DeleteOnClose! (1)" << widget->metaObject() << widget;
}
// create a widget filling the stacked widget
// this widget contains a wrapping group box with widget as content
auto *outerWidget = new QWidget;
auto *groupBox = new QGroupBox;
switch (sizePolicy) {
case ModalWidgetSizePolicy::Expanding: {
auto *outerLayout = new QHBoxLayout(outerWidget);
outerLayout->setContentsMargins(modalWidgetStretchedMarginC, modalWidgetStretchedMarginC, modalWidgetStretchedMarginC, modalWidgetStretchedMarginC);
outerLayout->addWidget(groupBox);
auto *layout = new QHBoxLayout(groupBox);
layout->addWidget(widget);
} break;
case ModalWidgetSizePolicy::Minimum: {
auto *outerLayout = new QGridLayout(outerWidget);
outerLayout->addWidget(groupBox, 0, 0, Qt::AlignCenter);
auto *layout = new QHBoxLayout(groupBox);
layout->addWidget(widget);
} break;
}
groupBox->setTitle(widget->windowTitle());
ui->stackedWidget->addWidget(outerWidget);
ui->stackedWidget->setCurrentWidget(outerWidget);
// the widget is supposed to behave like a dialog and we connect to its destuction
if (!widget->testAttribute(Qt::WA_DeleteOnClose)) { // DEBUG CODE! See https://github.com/owncloud/client/issues/11673
qCWarning(lcAccountSettings) << "Missing WA_DeleteOnClose! (2)" << widget->metaObject() << widget;
}
Q_ASSERT(widget->testAttribute(Qt::WA_DeleteOnClose));
connect(widget, &QWidget::destroyed, this, [this, outerWidget] {
outerWidget->deleteLater();
if (!_goingDown) {
ocApp()->gui()->settingsDialog()->ceaseModality(_accountState->account().get());
}
});
widget->setVisible(true);
ocApp()->gui()->settingsDialog()->requestModality(_accountState->account().get());
}
void AccountSettings::addModalWidget(AccountModalWidget *widget)
{
ui->stackedWidget->addWidget(widget);
ui->stackedWidget->setCurrentWidget(widget);
connect(widget, &AccountModalWidget::finished, this, [widget, this] {
widget->deleteLater();
ocApp()->gui()->settingsDialog()->ceaseModality(_accountState->account().get());
});
ocApp()->gui()->settingsDialog()->requestModality(_accountState->account().get());
}
uint AccountSettings::unsyncedSpaces() const
{
return _unsyncedSpaces;
}
uint AccountSettings::syncedSpaces() const
{
return _syncedSpaces;
}
void AccountSettings::slotDeleteAccount()
{
// Deleting the account potentially deletes 'this', so
// the QMessageBox should be destroyed before that happens.
auto messageBox = new QMessageBox(QMessageBox::Question, tr("Confirm Account Removal"),
tr("<p>Do you really want to remove the connection to the account <i>%1</i>?</p>"
"<p><b>Note:</b> This will <b>not</b> delete any files.</p>")
.arg(_accountState->account()->displayNameWithHost()),
QMessageBox::NoButton, this);
auto yesButton = messageBox->addButton(tr("Remove connection"), QMessageBox::YesRole);
messageBox->addButton(tr("Cancel"), QMessageBox::NoRole);
messageBox->setAttribute(Qt::WA_DeleteOnClose);
connect(messageBox, &QMessageBox::finished, this, [this, messageBox, yesButton]{
if (messageBox->clickedButton() == yesButton) {
auto manager = AccountManager::instance();
manager->deleteAccount(_accountState);
manager->save();
}
});
messageBox->open();
}
bool AccountSettings::event(QEvent *e)
{
if (e->type() == QEvent::Hide || e->type() == QEvent::Show) {
if (!_accountState->supportsSpaces()) {
_accountState->quotaInfo()->setActive(isVisible());
}
}
return QWidget::event(e);
}
} // namespace OCC