From 72f68aa9afc9cbb9f0890d5acfa2586a63c1158c Mon Sep 17 00:00:00 2001 From: Camila Ayres Date: Tue, 29 Oct 2024 18:00:52 +0100 Subject: [PATCH 01/14] Use slotComputeOverallSyncStatus as a slot. - Use qAsConst. Signed-off-by: Camila Ayres --- src/gui/owncloudgui.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gui/owncloudgui.cpp b/src/gui/owncloudgui.cpp index 52536d77add50..e4f07f2434604 100644 --- a/src/gui/owncloudgui.cpp +++ b/src/gui/owncloudgui.cpp @@ -118,6 +118,8 @@ ownCloudGui::ownCloudGui(Application *parent) FolderMan *folderMan = FolderMan::instance(); connect(folderMan, &FolderMan::folderSyncStateChange, this, &ownCloudGui::slotSyncStateChange); + connect(folderMan, &FolderMan::folderSyncStateChange, this, &ownCloudGui::slotComputeOverallSyncStatus); + #ifdef BUILD_FILE_PROVIDER_MODULE connect(Mac::FileProvider::instance()->socketServer(), &Mac::FileProviderSocketServer::syncStateChanged, this, &ownCloudGui::slotComputeOverallSyncStatus); @@ -240,8 +242,6 @@ void ownCloudGui::slotTrayClicked(QSystemTrayIcon::ActivationReason reason) void ownCloudGui::slotSyncStateChange(Folder *folder) { - slotComputeOverallSyncStatus(); - if (!folder) { return; // Valid, just a general GUI redraw was needed. } @@ -371,7 +371,7 @@ void ownCloudGui::slotComputeOverallSyncStatus() #else QStringList messages; messages.append(tr("Disconnected from accounts:")); - for (const auto &accountState : problemAccounts) { + for (const auto &accountState : qAsConst(problemAccounts)) { QString message = tr("Account %1: %2").arg(accountState->account()->displayName(), accountState->stateString(accountState->state())); if (!accountState->connectionErrors().empty()) { message += QLatin1String("\n"); From fc75626b58f0a419e7c2b4510895141245cf637c Mon Sep 17 00:00:00 2001 From: Camila Ayres Date: Tue, 29 Oct 2024 18:36:40 +0100 Subject: [PATCH 02/14] Fix warning "Calling C++ methods with 'this' objects different from the one they were retrieved from is broken" https://doc.qt.io/qt-6/qtqml-documents-structure.html#nativemethodbehavior Signed-off-by: Camila Ayres --- src/gui/tray/TrayFoldersMenuButton.qml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/gui/tray/TrayFoldersMenuButton.qml b/src/gui/tray/TrayFoldersMenuButton.qml index 85fa37d098ede..6da6f9ca914cb 100644 --- a/src/gui/tray/TrayFoldersMenuButton.qml +++ b/src/gui/tray/TrayFoldersMenuButton.qml @@ -11,6 +11,7 @@ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. */ +pragma NativeMethodBehavior: AcceptThisObject import QtQuick import QtQuick.Controls import QtQuick.Layouts From 27ad53810e906a86377e817020074f2ba5b0a1f4 Mon Sep 17 00:00:00 2001 From: Camila Ayres Date: Tue, 29 Oct 2024 18:45:03 +0100 Subject: [PATCH 03/14] Modernize Account::displayName(). Signed-off-by: Camila Ayres --- src/libsync/account.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp index 84c68b010db84..4d64876d541c9 100644 --- a/src/libsync/account.cpp +++ b/src/libsync/account.cpp @@ -156,13 +156,13 @@ void Account::setAvatar(const QImage &img) QString Account::displayName() const { - QString dn = QString("%1@%2").arg(credentials()->user(), _url.host()); - int port = url().port(); + auto displayName = QString("%1@%2").arg(credentials() ? credentials()->user() : "", _url.host()); + const auto port = url().port(); if (port > 0 && port != 80 && port != 443) { - dn.append(QLatin1Char(':')); - dn.append(QString::number(port)); + displayName.append(QLatin1Char(':')); + displayName.append(QString::number(port)); } - return dn; + return displayName; } QString Account::userIdAtHostWithPort() const From fc6ecf818620441b3f75141ca4db3884ae7b93f0 Mon Sep 17 00:00:00 2001 From: Camila Ayres Date: Tue, 29 Oct 2024 20:12:20 +0100 Subject: [PATCH 04/14] Use slots as slots. Signed-off-by: Camila Ayres --- src/gui/application.cpp | 11 +++-------- src/gui/application.h | 1 - src/gui/owncloudgui.cpp | 10 ---------- src/gui/owncloudgui.h | 2 -- src/gui/settingsdialog.cpp | 2 +- 5 files changed, 4 insertions(+), 22 deletions(-) diff --git a/src/gui/application.cpp b/src/gui/application.cpp index fb34647618350..ebcaa25fc0aa8 100644 --- a/src/gui/application.cpp +++ b/src/gui/application.cpp @@ -365,7 +365,7 @@ Application::Application(int &argc, char **argv) } _theme->setSystrayUseMonoIcons(ConfigFile().monoIcons()); - connect(_theme, &Theme::systrayUseMonoIconsChanged, this, &Application::slotUseMonoIconsChanged); + connect(_theme, &Theme::systrayUseMonoIconsChanged, _gui, &ownCloudGui::slotComputeOverallSyncStatus); connect(this, &Application::systemPaletteChanged, _theme, &Theme::systemPaletteHasChanged); @@ -589,7 +589,7 @@ void Application::slotAccountStateRemoved(AccountState *accountState) { if (_gui) { disconnect(accountState, &AccountState::stateChanged, - _gui.data(), &ownCloudGui::slotAccountStateChanged); + _gui.data(), &ownCloudGui::slotComputeOverallSyncStatus); disconnect(accountState->account().data(), &Account::serverVersionChanged, _gui.data(), &ownCloudGui::slotTrayMessageIfServerUnsupported); } @@ -611,7 +611,7 @@ void Application::slotAccountStateRemoved(AccountState *accountState) void Application::slotAccountStateAdded(AccountState *accountState) { connect(accountState, &AccountState::stateChanged, - _gui.data(), &ownCloudGui::slotAccountStateChanged); + _gui.data(), &ownCloudGui::slotComputeOverallSyncStatus); connect(accountState->account().data(), &Account::serverVersionChanged, _gui.data(), &ownCloudGui::slotTrayMessageIfServerUnsupported); connect(accountState, &AccountState::termsOfServiceChanged, @@ -716,11 +716,6 @@ void Application::setupLogging() qCInfo(lcApplication) << "Arguments:" << qApp->arguments(); } -void Application::slotUseMonoIconsChanged(bool) -{ - _gui->slotComputeOverallSyncStatus(); -} - void Application::slotParseMessage(const QString &msg, QObject *) { if (msg.startsWith(QLatin1String("MSG_PARSEOPTIONS:"))) { diff --git a/src/gui/application.h b/src/gui/application.h index f2c41fe453768..c3936da43a45e 100644 --- a/src/gui/application.h +++ b/src/gui/application.h @@ -101,7 +101,6 @@ public slots: protected slots: void slotParseMessage(const QString &, QObject *); void slotCheckConnection(); - void slotUseMonoIconsChanged(bool); void slotCleanup(); void slotAccountStateAdded(OCC::AccountState *accountState); void slotAccountStateRemoved(OCC::AccountState *accountState); diff --git a/src/gui/owncloudgui.cpp b/src/gui/owncloudgui.cpp index e4f07f2434604..dccdcc3a8c7f9 100644 --- a/src/gui/owncloudgui.cpp +++ b/src/gui/owncloudgui.cpp @@ -258,21 +258,11 @@ void ownCloudGui::slotSyncStateChange(Folder *folder) } } -void ownCloudGui::slotFoldersChanged() -{ - slotComputeOverallSyncStatus(); -} - void ownCloudGui::slotOpenPath(const QString &path) { showInFileManager(path); } -void ownCloudGui::slotAccountStateChanged() -{ - slotComputeOverallSyncStatus(); -} - void ownCloudGui::slotTrayMessageIfServerUnsupported(Account *account) { if (account->serverVersionUnsupported()) { diff --git a/src/gui/owncloudgui.h b/src/gui/owncloudgui.h index 2370d9d3f5614..446b58a9c19be 100644 --- a/src/gui/owncloudgui.h +++ b/src/gui/owncloudgui.h @@ -79,7 +79,6 @@ public slots: void slotFolderOpenAction(const QString &alias); void slotUpdateProgress(const QString &folder, const OCC::ProgressInfo &progress); void slotShowGuiMessage(const QString &title, const QString &message); - void slotFoldersChanged(); void slotShowSettings(); void slotShowSyncProtocol(); void slotShutdown(); @@ -92,7 +91,6 @@ public slots: void slotSettingsDialogActivated(); void slotHelp(); void slotOpenPath(const QString &path); - void slotAccountStateChanged(); void slotTrayMessageIfServerUnsupported(OCC::Account *account); void slotNeedToAcceptTermsOfService(OCC::AccountPtr account, OCC::AccountState::State state); diff --git a/src/gui/settingsdialog.cpp b/src/gui/settingsdialog.cpp index fc09c0cdce04d..7b4d778946f22 100644 --- a/src/gui/settingsdialog.cpp +++ b/src/gui/settingsdialog.cpp @@ -261,7 +261,7 @@ void SettingsDialog::accountAdded(AccountState *s) _actionForAccount.insert(s->account().data(), accountAction); accountAction->trigger(); - connect(accountSettings, &AccountSettings::folderChanged, _gui, &ownCloudGui::slotFoldersChanged); + connect(accountSettings, &AccountSettings::folderChanged, _gui, &ownCloudGui::slotComputeOverallSyncStatus); connect(accountSettings, &AccountSettings::openFolderAlias, _gui, &ownCloudGui::slotFolderOpenAction); connect(accountSettings, &AccountSettings::showIssuesList, this, &SettingsDialog::showIssuesList); From 1847a2e95c360cd6570fe722a2cdd6e2a5a3266e Mon Sep 17 00:00:00 2001 From: Camila Ayres Date: Tue, 29 Oct 2024 21:51:46 +0100 Subject: [PATCH 05/14] Diferentiate between display name and dav display name. Signed-off-by: Camila Ayres --- src/gui/accountmanager.cpp | 5 +++-- src/libsync/account.cpp | 18 ++++++++++++++---- src/libsync/account.h | 2 ++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/gui/accountmanager.cpp b/src/gui/accountmanager.cpp index 0c86f16a05fc3..67927066af2c7 100644 --- a/src/gui/accountmanager.cpp +++ b/src/gui/accountmanager.cpp @@ -334,7 +334,7 @@ void AccountManager::saveAccountHelper(Account *acc, QSettings &settings, bool s settings.setValue(QLatin1String(versionC), maxAccountVersion); settings.setValue(QLatin1String(urlC), acc->_url.toString()); settings.setValue(QLatin1String(davUserC), acc->_davUser); - settings.setValue(QLatin1String(displayNameC), acc->_displayName); + settings.setValue(QLatin1String(displayNameC), acc->davDisplayName()); settings.setValue(QLatin1String(serverVersionC), acc->_serverVersion); settings.setValue(QLatin1String(serverColorC), acc->_serverColor); settings.setValue(QLatin1String(serverTextColorC), acc->_serverTextColor); @@ -498,7 +498,7 @@ AccountPtr AccountManager::loadAccountHelper(QSettings &settings) acc->_davUser = settings.value(QLatin1String(davUserC)).toString(); acc->_settingsMap.insert(QLatin1String(userC), settings.value(userC)); - acc->_displayName = settings.value(QLatin1String(displayNameC), "").toString(); + acc->setDavDisplayName(settings.value(QLatin1String(displayNameC), "").toString()); const QString authTypePrefix = authType + "_"; const auto settingsChildKeys = settings.childKeys(); for (const auto &key : settingsChildKeys) { @@ -509,6 +509,7 @@ AccountPtr AccountManager::loadAccountHelper(QSettings &settings) } acc->setCredentials(CredentialsFactory::create(authType)); + acc->setDisplayName(acc->credentials()->user()); acc->setNetworkProxySetting(settings.value(networkProxySettingC).value()); acc->setProxyType(settings.value(networkProxyTypeC).value()); diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp index 4d64876d541c9..855eab03ee356 100644 --- a/src/libsync/account.cpp +++ b/src/libsync/account.cpp @@ -156,13 +156,23 @@ void Account::setAvatar(const QImage &img) QString Account::displayName() const { - auto displayName = QString("%1@%2").arg(credentials() ? credentials()->user() : "", _url.host()); + return _displayName; +} + +void Account::setDisplayName(const QString &username) +{ + auto displayName = QString("%1@%2").arg(username, _url.host()); const auto port = url().port(); if (port > 0 && port != 80 && port != 443) { displayName.append(QLatin1Char(':')); displayName.append(QString::number(port)); } - return displayName; + + if (displayName == _displayName) { + return; + } + + _displayName = displayName; } QString Account::userIdAtHostWithPort() const @@ -178,12 +188,12 @@ QString Account::userIdAtHostWithPort() const QString Account::davDisplayName() const { - return _displayName; + return _davDisplayName; } void Account::setDavDisplayName(const QString &newDisplayName) { - _displayName = newDisplayName; + _davDisplayName = newDisplayName; emit accountChangedDisplayName(); emit prettyNameChanged(); } diff --git a/src/libsync/account.h b/src/libsync/account.h index 6333164add153..b280a767b5e83 100644 --- a/src/libsync/account.h +++ b/src/libsync/account.h @@ -146,6 +146,7 @@ class OWNCLOUDSYNC_EXPORT Account : public QObject /// The name of the account as shown in the toolbar [[nodiscard]] QString displayName() const; + void setDisplayName(const QString &username); /// User id in a form 'user@example.de, optionally port is added (if it is not 80 or 443) [[nodiscard]] QString userIdAtHostWithPort() const; @@ -493,6 +494,7 @@ private slots: QWeakPointer _sharedThis; QString _id; QString _davUser; + QString _davDisplayName; QString _displayName; QTimer _pushNotificationsReconnectTimer; #ifndef TOKEN_AUTH_ONLY From f130e39cbc66efac0d48dee34e894ab0b1abd6ae Mon Sep 17 00:00:00 2001 From: Camila Ayres Date: Thu, 31 Oct 2024 16:28:32 +0100 Subject: [PATCH 06/14] Rename vars: _am => _networkAccessManager, a => newAccountData. Signed-off-by: Camila Ayres --- src/gui/accountmanager.cpp | 14 ++--- src/gui/accountmanager.h | 4 +- src/libsync/account.cpp | 107 +++++++++++++++++++------------------ src/libsync/account.h | 2 +- 4 files changed, 65 insertions(+), 62 deletions(-) diff --git a/src/gui/accountmanager.cpp b/src/gui/accountmanager.cpp index 67927066af2c7..d0361497961a7 100644 --- a/src/gui/accountmanager.cpp +++ b/src/gui/accountmanager.cpp @@ -123,7 +123,7 @@ AccountManager::AccountsRestoreResult AccountManager::restore(const bool alsoRes if (const auto acc = loadAccountHelper(*settings)) { acc->_id = accountId; const auto accState = new AccountState(acc); - const auto jar = qobject_cast(acc->_am->cookieJar()); + const auto jar = qobject_cast(acc->_networkAccessManager->cookieJar()); Q_ASSERT(jar); if (jar) { jar->restore(acc->cookieJarPath()); @@ -305,12 +305,12 @@ void AccountManager::save(bool saveCredentials) qCInfo(lcAccountManager) << "Saved all account settings, status:" << settings->status(); } -void AccountManager::saveAccount(Account *a) +void AccountManager::saveAccount(Account *newAccountData) { - qCDebug(lcAccountManager) << "Saving account" << a->url().toString(); + qCDebug(lcAccountManager) << "Saving account" << newAccountData->url().toString(); const auto settings = ConfigFile::settingsWithGroup(QLatin1String(accountsC)); - settings->beginGroup(a->id()); - saveAccountHelper(a, *settings, false); // don't save credentials they might not have been loaded yet + settings->beginGroup(newAccountData->id()); + saveAccountHelper(newAccountData, *settings, false); // don't save credentials they might not have been loaded yet settings->endGroup(); settings->sync(); @@ -424,8 +424,8 @@ void AccountManager::saveAccountHelper(Account *acc, QSettings &settings, bool s settings.endGroup(); // Save cookies. - if (acc->_am) { - auto *jar = qobject_cast(acc->_am->cookieJar()); + if (acc->_networkAccessManager) { + auto *jar = qobject_cast(acc->_networkAccessManager->cookieJar()); if (jar) { qCInfo(lcAccountManager) << "Saving cookies." << acc->cookieJarPath(); if (!jar->save(acc->cookieJarPath())) diff --git a/src/gui/accountmanager.h b/src/gui/accountmanager.h index 85a244ced4fb5..ceb357f09a96a 100644 --- a/src/gui/accountmanager.h +++ b/src/gui/accountmanager.h @@ -91,8 +91,8 @@ class AccountManager : public QObject static void backwardMigrationSettingsKeys(QStringList *deleteKeys, QStringList *ignoreKeys); public slots: - /// Saves account data, not including the credentials - void saveAccount(OCC::Account *a); + /// Saves account data when adding user, when updating e.g. dav user, not including the credentials + void saveAccount(OCC::Account *newAccountData); /// Saves account state data, not including the account void saveAccountState(OCC::AccountState *a); diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp index 855eab03ee356..03d2d2f937c10 100644 --- a/src/libsync/account.cpp +++ b/src/libsync/account.cpp @@ -135,9 +135,12 @@ QString Account::davUser() const void Account::setDavUser(const QString &newDavUser) { - if (_davUser == newDavUser) + if (_davUser == newDavUser) { return; + } + _davUser = newDavUser; + emit wantsAccountSaved(this); emit prettyNameChanged(); } @@ -253,14 +256,14 @@ void Account::setCredentials(AbstractCredentials *cred) QNetworkCookieJar *jar = nullptr; QNetworkProxy proxy; - if (_am) { - jar = _am->cookieJar(); + if (_networkAccessManager) { + jar = _networkAccessManager->cookieJar(); jar->setParent(nullptr); // Remember proxy (issue #2108) - proxy = _am->proxy(); + proxy = _networkAccessManager->proxy(); - _am = QSharedPointer(); + _networkAccessManager = QSharedPointer(); } // The order for these two is important! Reading the credential's @@ -271,17 +274,17 @@ void Account::setCredentials(AbstractCredentials *cred) // Note: This way the QNAM can outlive the Account and Credentials. // This is necessary to avoid issues with the QNAM being deleted while // processing slotHandleSslErrors(). - _am = QSharedPointer(_credentials->createQNAM(), &QObject::deleteLater); + _networkAccessManager = QSharedPointer(_credentials->createQNAM(), &QObject::deleteLater); if (jar) { - _am->setCookieJar(jar); + _networkAccessManager->setCookieJar(jar); } if (proxy.type() != QNetworkProxy::DefaultProxy) { - _am->setProxy(proxy); + _networkAccessManager->setProxy(proxy); } - connect(_am.data(), &QNetworkAccessManager::sslErrors, + connect(_networkAccessManager.data(), &QNetworkAccessManager::sslErrors, this, &Account::slotHandleSslErrors); - connect(_am.data(), &QNetworkAccessManager::proxyAuthenticationRequired, + connect(_networkAccessManager.data(), &QNetworkAccessManager::proxyAuthenticationRequired, this, &Account::proxyAuthenticationRequired); connect(_credentials.data(), &AbstractCredentials::fetched, this, &Account::slotCredentialsFetched); @@ -368,7 +371,7 @@ QUrl Account::deprecatedPrivateLinkUrl(const QByteArray &numericFileId) const */ void Account::clearCookieJar() { - const auto jar = qobject_cast(_am->cookieJar()); + const auto jar = qobject_cast(_networkAccessManager->cookieJar()); ASSERT(jar); jar->setAllCookies(QList()); } @@ -378,7 +381,7 @@ void Account::clearCookieJar() of not losing its ownership. */ void Account::lendCookieJarTo(QNetworkAccessManager *guest) { - auto jar = _am->cookieJar(); + auto jar = _networkAccessManager->cookieJar(); auto oldParent = jar->parent(); guest->setCookieJar(jar); // takes ownership of our precious cookie jar jar->setParent(oldParent); // takes it back @@ -391,35 +394,35 @@ QString Account::cookieJarPath() void Account::resetNetworkAccessManager() { - if (!_credentials || !_am) { + if (!_credentials || !_networkAccessManager) { return; } qCDebug(lcAccount) << "Resetting QNAM"; - QNetworkCookieJar *jar = _am->cookieJar(); - QNetworkProxy proxy = _am->proxy(); + QNetworkCookieJar *jar = _networkAccessManager->cookieJar(); + QNetworkProxy proxy = _networkAccessManager->proxy(); // Use a QSharedPointer to allow locking the life of the QNAM on the stack. // Make it call deleteLater to make sure that we can return to any QNAM stack frames safely. - _am = QSharedPointer(_credentials->createQNAM(), &QObject::deleteLater); + _networkAccessManager = QSharedPointer(_credentials->createQNAM(), &QObject::deleteLater); - _am->setCookieJar(jar); // takes ownership of the old cookie jar - _am->setProxy(proxy); // Remember proxy (issue #2108) + _networkAccessManager->setCookieJar(jar); // takes ownership of the old cookie jar + _networkAccessManager->setProxy(proxy); // Remember proxy (issue #2108) - connect(_am.data(), &QNetworkAccessManager::sslErrors, + connect(_networkAccessManager.data(), &QNetworkAccessManager::sslErrors, this, &Account::slotHandleSslErrors); - connect(_am.data(), &QNetworkAccessManager::proxyAuthenticationRequired, + connect(_networkAccessManager.data(), &QNetworkAccessManager::proxyAuthenticationRequired, this, &Account::proxyAuthenticationRequired); } QNetworkAccessManager *Account::networkAccessManager() { - return _am.data(); + return _networkAccessManager.data(); } QSharedPointer Account::sharedNetworkAccessManager() { - return _am; + return _networkAccessManager; } QNetworkReply *Account::sendRawRequest(const QByteArray &verb, const QUrl &url, QNetworkRequest req, QIODevice *data) @@ -427,17 +430,17 @@ QNetworkReply *Account::sendRawRequest(const QByteArray &verb, const QUrl &url, req.setUrl(url); req.setSslConfiguration(this->getOrCreateSslConfig()); if (verb == "HEAD" && !data) { - return _am->head(req); + return _networkAccessManager->head(req); } else if (verb == "GET" && !data) { - return _am->get(req); + return _networkAccessManager->get(req); } else if (verb == "POST") { - return _am->post(req, data); + return _networkAccessManager->post(req, data); } else if (verb == "PUT") { - return _am->put(req, data); + return _networkAccessManager->put(req, data); } else if (verb == "DELETE" && !data) { - return _am->deleteResource(req); + return _networkAccessManager->deleteResource(req); } - return _am->sendCustomRequest(req, verb, data); + return _networkAccessManager->sendCustomRequest(req, verb, data); } QNetworkReply *Account::sendRawRequest(const QByteArray &verb, const QUrl &url, QNetworkRequest req, const QByteArray &data) @@ -445,17 +448,17 @@ QNetworkReply *Account::sendRawRequest(const QByteArray &verb, const QUrl &url, req.setUrl(url); req.setSslConfiguration(this->getOrCreateSslConfig()); if (verb == "HEAD" && data.isEmpty()) { - return _am->head(req); + return _networkAccessManager->head(req); } else if (verb == "GET" && data.isEmpty()) { - return _am->get(req); + return _networkAccessManager->get(req); } else if (verb == "POST") { - return _am->post(req, data); + return _networkAccessManager->post(req, data); } else if (verb == "PUT") { - return _am->put(req, data); + return _networkAccessManager->put(req, data); } else if (verb == "DELETE" && data.isEmpty()) { - return _am->deleteResource(req); + return _networkAccessManager->deleteResource(req); } - return _am->sendCustomRequest(req, verb, data); + return _networkAccessManager->sendCustomRequest(req, verb, data); } QNetworkReply *Account::sendRawRequest(const QByteArray &verb, const QUrl &url, QNetworkRequest req, QHttpMultiPart *data) @@ -463,11 +466,11 @@ QNetworkReply *Account::sendRawRequest(const QByteArray &verb, const QUrl &url, req.setUrl(url); req.setSslConfiguration(this->getOrCreateSslConfig()); if (verb == "PUT") { - return _am->put(req, data); + return _networkAccessManager->put(req, data); } else if (verb == "POST") { - return _am->post(req, data); + return _networkAccessManager->post(req, data); } - return _am->sendCustomRequest(req, verb, data); + return _networkAccessManager->sendCustomRequest(req, verb, data); } SimpleNetworkJob *Account::sendRequest(const QByteArray &verb, const QUrl &url, QNetworkRequest req, QIODevice *data) @@ -595,7 +598,7 @@ void Account::slotHandleSslErrors(QNetworkReply *reply, QList errors) // the deleteLater() of the QNAM before we have the chance of unwinding our stack. // Keep a ref here on our stackframe to make sure that it doesn't get deleted before // handleErrors returns. - QSharedPointer qnamLock = _am; + QSharedPointer qnamLock = _networkAccessManager; QPointer guard = reply; if (_sslErrorHandler->handleErrors(errors, reply->sslConfiguration(), &approvedCerts, sharedFromThis())) { @@ -671,7 +674,7 @@ void Account::handleInvalidCredentials() void Account::clearQNAMCache() { - _am->clearAccessCache(); + _networkAccessManager->clearAccessCache(); } const Capabilities &Account::capabilities() const @@ -1130,16 +1133,16 @@ void Account::setNetworkProxySetting(const AccountNetworkProxySetting setting) _networkProxySetting = setting; if (setting == AccountNetworkProxySetting::AccountSpecificProxy) { - auto proxy = _am->proxy(); + auto proxy = _networkAccessManager->proxy(); proxy.setType(proxyType()); proxy.setHostName(proxyHostName()); proxy.setPort(proxyPort()); proxy.setUser(proxyUser()); proxy.setPassword(proxyPassword()); - _am->setProxy(proxy); + _networkAccessManager->setProxy(proxy); } else { const auto proxy = QNetworkProxy::applicationProxy(); - _am->setProxy(proxy); + _networkAccessManager->setProxy(proxy); setProxyType(proxy.type()); setProxyHostName(proxy.hostName()); setProxyPort(proxy.port()); @@ -1163,9 +1166,9 @@ void Account::setProxyType(QNetworkProxy::ProxyType proxyType) _proxyType = proxyType; if (networkProxySetting() == AccountNetworkProxySetting::AccountSpecificProxy) { - auto proxy = _am->proxy(); + auto proxy = _networkAccessManager->proxy(); proxy.setType(proxyType); - _am->setProxy(proxy); + _networkAccessManager->setProxy(proxy); } emit proxyTypeChanged(); @@ -1185,9 +1188,9 @@ void Account::setProxyHostName(const QString &hostName) _proxyHostName = hostName; if (networkProxySetting() == AccountNetworkProxySetting::AccountSpecificProxy) { - auto proxy = _am->proxy(); + auto proxy = _networkAccessManager->proxy(); proxy.setHostName(hostName); - _am->setProxy(proxy); + _networkAccessManager->setProxy(proxy); } emit proxyHostNameChanged(); @@ -1207,9 +1210,9 @@ void Account::setProxyPort(const int port) _proxyPort = port; if (networkProxySetting() == AccountNetworkProxySetting::AccountSpecificProxy) { - auto proxy = _am->proxy(); + auto proxy = _networkAccessManager->proxy(); proxy.setPort(port); - _am->setProxy(proxy); + _networkAccessManager->setProxy(proxy); } emit proxyPortChanged(); @@ -1244,9 +1247,9 @@ void Account::setProxyUser(const QString &user) _proxyUser = user; if (networkProxySetting() == AccountNetworkProxySetting::AccountSpecificProxy) { - auto proxy = _am->proxy(); + auto proxy = _networkAccessManager->proxy(); proxy.setUser(user); - _am->setProxy(proxy); + _networkAccessManager->setProxy(proxy); } emit proxyUserChanged(); @@ -1266,9 +1269,9 @@ void Account::setProxyPassword(const QString &password) _proxyPassword = password; if (networkProxySetting() == AccountNetworkProxySetting::AccountSpecificProxy) { - auto proxy = _am->proxy(); + auto proxy = _networkAccessManager->proxy(); proxy.setPassword(password); - _am->setProxy(proxy); + _networkAccessManager->setProxy(proxy); } emit proxyPasswordChanged(); diff --git a/src/libsync/account.h b/src/libsync/account.h index b280a767b5e83..a991daed9cd47 100644 --- a/src/libsync/account.h +++ b/src/libsync/account.h @@ -519,7 +519,7 @@ private slots: QColor _serverTextColor = QColorConstants::White; bool _skipE2eeMetadataChecksumValidation = false; QScopedPointer _sslErrorHandler; - QSharedPointer _am; + QSharedPointer _networkAccessManager; QScopedPointer _credentials; bool _http2Supported = false; From 9634f4ed1f41284909ae419f0328d3ace2544493 Mon Sep 17 00:00:00 2001 From: Camila Ayres Date: Thu, 31 Oct 2024 18:18:25 +0100 Subject: [PATCH 07/14] Use saveAccount for adding single account. Signed-off-by: Camila Ayres --- src/gui/owncloudsetupwizard.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/owncloudsetupwizard.cpp b/src/gui/owncloudsetupwizard.cpp index 09102f62429fc..7a3aa3668b693 100644 --- a/src/gui/owncloudsetupwizard.cpp +++ b/src/gui/owncloudsetupwizard.cpp @@ -727,7 +727,7 @@ AccountState *OwncloudSetupWizard::applyAccountChanges() auto manager = AccountManager::instance(); auto newState = manager->addAccount(newAccount); - manager->save(); + manager->saveAccount(newAccount.data()); return newState; } From 9649bd99f6df5920927a43106e25685b698978f9 Mon Sep 17 00:00:00 2001 From: Camila Ayres Date: Mon, 4 Nov 2024 19:08:03 +0100 Subject: [PATCH 08/14] Add {} to single line if. Signed-off-by: Camila Ayres --- src/gui/accountstate.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gui/accountstate.cpp b/src/gui/accountstate.cpp index e2fb2779413bd..d167f76f87ec3 100644 --- a/src/gui/accountstate.cpp +++ b/src/gui/accountstate.cpp @@ -202,8 +202,10 @@ void AccountState::signOutByUi() void AccountState::freshConnectionAttempt() { - if (isConnected()) + if (isConnected()) { setState(Disconnected); + } + checkConnectivity(); } From 77597af3ae5ebb7d20aef790b276ec75a1517851 Mon Sep 17 00:00:00 2001 From: Camila Ayres Date: Mon, 4 Nov 2024 19:17:15 +0100 Subject: [PATCH 09/14] acc => account. Signed-off-by: Camila Ayres --- src/gui/accountmanager.cpp | 76 +++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/src/gui/accountmanager.cpp b/src/gui/accountmanager.cpp index d0361497961a7..0cdcace834d60 100644 --- a/src/gui/accountmanager.cpp +++ b/src/gui/accountmanager.cpp @@ -328,36 +328,36 @@ void AccountManager::saveAccountState(AccountState *a) qCDebug(lcAccountManager) << "Saved account state settings, status:" << settings->status(); } -void AccountManager::saveAccountHelper(Account *acc, QSettings &settings, bool saveCredentials) +void AccountManager::saveAccountHelper(Account *account, QSettings &settings, bool saveCredentials) { qCDebug(lcAccountManager) << "Saving settings to" << settings.fileName(); settings.setValue(QLatin1String(versionC), maxAccountVersion); - settings.setValue(QLatin1String(urlC), acc->_url.toString()); - settings.setValue(QLatin1String(davUserC), acc->_davUser); - settings.setValue(QLatin1String(displayNameC), acc->davDisplayName()); - settings.setValue(QLatin1String(serverVersionC), acc->_serverVersion); - settings.setValue(QLatin1String(serverColorC), acc->_serverColor); - settings.setValue(QLatin1String(serverTextColorC), acc->_serverTextColor); - settings.setValue(QLatin1String(serverHasValidSubscriptionC), acc->serverHasValidSubscription()); - - if (!acc->_skipE2eeMetadataChecksumValidation) { + settings.setValue(QLatin1String(urlC), account->_url.toString()); + settings.setValue(QLatin1String(davUserC), account->_davUser); + settings.setValue(QLatin1String(displayNameC), account->davDisplayName()); + settings.setValue(QLatin1String(serverVersionC), account->_serverVersion); + settings.setValue(QLatin1String(serverColorC), account->_serverColor); + settings.setValue(QLatin1String(serverTextColorC), account->_serverTextColor); + settings.setValue(QLatin1String(serverHasValidSubscriptionC), account->serverHasValidSubscription()); + + if (!account->_skipE2eeMetadataChecksumValidation) { settings.remove(QLatin1String(skipE2eeMetadataChecksumValidationC)); } else { - settings.setValue(QLatin1String(skipE2eeMetadataChecksumValidationC), acc->_skipE2eeMetadataChecksumValidation); + settings.setValue(QLatin1String(skipE2eeMetadataChecksumValidationC), account->_skipE2eeMetadataChecksumValidation); } - settings.setValue(networkProxySettingC, static_cast>(acc->networkProxySetting())); - settings.setValue(networkProxyTypeC, acc->proxyType()); - settings.setValue(networkProxyHostNameC, acc->proxyHostName()); - settings.setValue(networkProxyPortC, acc->proxyPort()); - settings.setValue(networkProxyNeedsAuthC, acc->proxyNeedsAuth()); - settings.setValue(networkProxyUserC, acc->proxyUser()); - settings.setValue(networkUploadLimitSettingC, static_cast>(acc->uploadLimitSetting())); - settings.setValue(networkDownloadLimitSettingC, static_cast>(acc->downloadLimitSetting())); - settings.setValue(networkUploadLimitC, acc->uploadLimit()); - settings.setValue(networkDownloadLimitC, acc->downloadLimit()); - - const auto proxyPasswordKey = QString(acc->userIdAtHostWithPort() + networkProxyPasswordKeychainKeySuffixC); - if (const auto proxyPassword = acc->proxyPassword(); proxyPassword.isEmpty()) { + settings.setValue(networkProxySettingC, static_cast>(account->networkProxySetting())); + settings.setValue(networkProxyTypeC, account->proxyType()); + settings.setValue(networkProxyHostNameC, account->proxyHostName()); + settings.setValue(networkProxyPortC, account->proxyPort()); + settings.setValue(networkProxyNeedsAuthC, account->proxyNeedsAuth()); + settings.setValue(networkProxyUserC, account->proxyUser()); + settings.setValue(networkUploadLimitSettingC, static_cast>(account->uploadLimitSetting())); + settings.setValue(networkDownloadLimitSettingC, static_cast>(account->downloadLimitSetting())); + settings.setValue(networkUploadLimitC, account->uploadLimit()); + settings.setValue(networkDownloadLimitC, account->downloadLimit()); + + const auto proxyPasswordKey = QString(account->userIdAtHostWithPort() + networkProxyPasswordKeychainKeySuffixC); + if (const auto proxyPassword = account->proxyPassword(); proxyPassword.isEmpty()) { const auto job = new QKeychain::DeletePasswordJob(Theme::instance()->appName(), this); job->setKey(proxyPasswordKey); connect(job, &QKeychain::Job::finished, this, [](const QKeychain::Job *const incomingJob) { @@ -384,27 +384,27 @@ void AccountManager::saveAccountHelper(Account *acc, QSettings &settings, bool s job->start(); } - if (acc->_credentials) { + if (account->_credentials) { if (saveCredentials) { // Only persist the credentials if the parameter is set, on migration from 1.8.x // we want to save the accounts but not overwrite the credentials // (This is easier than asynchronously fetching the credentials from keychain and then // re-persisting them) - acc->_credentials->persist(); + account->_credentials->persist(); } - const auto settingsMapKeys = acc->_settingsMap.keys(); + const auto settingsMapKeys = account->_settingsMap.keys(); for (const auto &key : settingsMapKeys) { - if (!acc->_settingsMap.value(key).isValid()) { + if (!account->_settingsMap.value(key).isValid()) { continue; } - settings.setValue(key, acc->_settingsMap.value(key)); + settings.setValue(key, account->_settingsMap.value(key)); } - settings.setValue(QLatin1String(authTypeC), acc->_credentials->authType()); + settings.setValue(QLatin1String(authTypeC), account->_credentials->authType()); // HACK: Save http_user also as user - const auto settingsMap = acc->_settingsMap; + const auto settingsMap = account->_settingsMap; if (settingsMap.contains(httpUserC) && settingsMap.value(httpUserC).isValid()) { settings.setValue(userC, settingsMap.value(httpUserC)); } @@ -412,9 +412,9 @@ void AccountManager::saveAccountHelper(Account *acc, QSettings &settings, bool s // Save accepted certificates. settings.beginGroup(QLatin1String(generalC)); - qCInfo(lcAccountManager) << "Saving " << acc->approvedCerts().count() << " unknown certs."; + qCInfo(lcAccountManager) << "Saving " << account->approvedCerts().count() << " unknown certs."; QByteArray certs; - const auto approvedCerts = acc->approvedCerts(); + const auto approvedCerts = account->approvedCerts(); for (const auto &cert : approvedCerts) { certs += cert.toPem() + '\n'; } @@ -424,13 +424,13 @@ void AccountManager::saveAccountHelper(Account *acc, QSettings &settings, bool s settings.endGroup(); // Save cookies. - if (acc->_networkAccessManager) { - auto *jar = qobject_cast(acc->_networkAccessManager->cookieJar()); + if (account->_networkAccessManager) { + const auto jar = qobject_cast(account->_networkAccessManager->cookieJar()); if (jar) { - qCInfo(lcAccountManager) << "Saving cookies." << acc->cookieJarPath(); - if (!jar->save(acc->cookieJarPath())) + qCInfo(lcAccountManager) << "Saving cookies." << account->cookieJarPath(); + if (!jar->save(account->cookieJarPath())) { - qCWarning(lcAccountManager) << "Failed to save cookies to" << acc->cookieJarPath(); + qCWarning(lcAccountManager) << "Failed to save cookies to" << account->cookieJarPath(); } } } From df84d12b58ac408e2fd1ac992f2b8e6ff5c37ded Mon Sep 17 00:00:00 2001 From: Camila Ayres Date: Mon, 4 Nov 2024 20:15:43 +0100 Subject: [PATCH 10/14] wiz => owncloudSetupWizard. Signed-off-by: Camila Ayres --- src/gui/owncloudsetupwizard.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/gui/owncloudsetupwizard.cpp b/src/gui/owncloudsetupwizard.cpp index 7a3aa3668b693..ce44cf9a3388d 100644 --- a/src/gui/owncloudsetupwizard.cpp +++ b/src/gui/owncloudsetupwizard.cpp @@ -66,7 +66,7 @@ OwncloudSetupWizard::~OwncloudSetupWizard() _ocWizard->deleteLater(); } -static QPointer wiz = nullptr; +static QPointer owncloudSetupWizard = nullptr; void OwncloudSetupWizard::runWizard(QObject *obj, const char *amember, QWidget *parent) { @@ -78,25 +78,26 @@ void OwncloudSetupWizard::runWizard(QObject *obj, const char *amember, QWidget * Theme::instance()->setStartLoginFlowAutomatically(true); } - if (!wiz.isNull()) { + if (!owncloudSetupWizard.isNull()) { bringWizardToFrontIfVisible(); return; } - wiz = new OwncloudSetupWizard(parent); - connect(wiz, SIGNAL(ownCloudWizardDone(int)), obj, amember); - connect(wiz->_ocWizard, &OwncloudWizard::wizardClosed, obj, [] { wiz.clear(); }); + owncloudSetupWizard = new OwncloudSetupWizard(parent); + connect(owncloudSetupWizard, SIGNAL(ownCloudWizardDone(int)), obj, amember); + connect(owncloudSetupWizard->_ocWizard, &OwncloudWizard::wizardClosed, obj, [] { owncloudSetupWizard.clear(); }); + FolderMan::instance()->setSyncEnabled(false); - wiz->startWizard(); + owncloudSetupWizard->startWizard(); } bool OwncloudSetupWizard::bringWizardToFrontIfVisible() { - if (wiz.isNull()) { + if (owncloudSetupWizard.isNull()) { return false; } - ownCloudGui::raiseDialog(wiz->_ocWizard); + ownCloudGui::raiseDialog(owncloudSetupWizard->_ocWizard); return true; } From 932d61589cac85e8de016fbd59d4dde20422107d Mon Sep 17 00:00:00 2001 From: Camila Ayres Date: Mon, 4 Nov 2024 21:11:40 +0100 Subject: [PATCH 11/14] Call for done() when skipping folder configuration. Signed-off-by: Camila Ayres --- src/gui/owncloudsetupwizard.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/gui/owncloudsetupwizard.cpp b/src/gui/owncloudsetupwizard.cpp index ce44cf9a3388d..58a6d613f0475 100644 --- a/src/gui/owncloudsetupwizard.cpp +++ b/src/gui/owncloudsetupwizard.cpp @@ -701,7 +701,7 @@ void OwncloudSetupWizard::slotAssistantFinished(int result) } // notify others. - _ocWizard->done(QWizard::Accepted); + _ocWizard->done(result); emit ownCloudWizardDone(result); } @@ -711,7 +711,10 @@ void OwncloudSetupWizard::slotSkipFolderConfiguration() disconnect(_ocWizard, &OwncloudWizard::basicSetupFinished, this, &OwncloudSetupWizard::slotAssistantFinished); - _ocWizard->close(); + + _ocWizard->done(QDialog::Rejected); + + // Accept to check connectivity, only skip folder setup emit ownCloudWizardDone(QDialog::Accepted); } From fdbda5d59b8b66fc381ca05d49f97e403a6644a5 Mon Sep 17 00:00:00 2001 From: Camila Ayres Date: Wed, 6 Nov 2024 17:13:28 +0100 Subject: [PATCH 12/14] Remove check before setting display name. Signed-off-by: Camila Ayres --- src/libsync/account.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp index 03d2d2f937c10..3ecfd84e1eb95 100644 --- a/src/libsync/account.cpp +++ b/src/libsync/account.cpp @@ -171,10 +171,6 @@ void Account::setDisplayName(const QString &username) displayName.append(QString::number(port)); } - if (displayName == _displayName) { - return; - } - _displayName = displayName; } From 11cebc1e2a75286f7632f8553b174af1c5ad6b5c Mon Sep 17 00:00:00 2001 From: Camila Ayres Date: Thu, 14 Nov 2024 19:11:54 +0100 Subject: [PATCH 13/14] Fix tests: make sure displayName is not empty. Signed-off-by: Camila Ayres --- src/gui/accountmanager.cpp | 1 - src/libsync/account.cpp | 12 ++++++------ src/libsync/account.h | 1 - 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/gui/accountmanager.cpp b/src/gui/accountmanager.cpp index 0cdcace834d60..f27d2742703a7 100644 --- a/src/gui/accountmanager.cpp +++ b/src/gui/accountmanager.cpp @@ -509,7 +509,6 @@ AccountPtr AccountManager::loadAccountHelper(QSettings &settings) } acc->setCredentials(CredentialsFactory::create(authType)); - acc->setDisplayName(acc->credentials()->user()); acc->setNetworkProxySetting(settings.value(networkProxySettingC).value()); acc->setProxyType(settings.value(networkProxyTypeC).value()); diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp index 3ecfd84e1eb95..0b20a3551bdc9 100644 --- a/src/libsync/account.cpp +++ b/src/libsync/account.cpp @@ -159,19 +159,19 @@ void Account::setAvatar(const QImage &img) QString Account::displayName() const { - return _displayName; -} + auto credentialsUser = _davUser; + if (_credentials && !_credentials->user().isEmpty()) { + credentialsUser = _credentials->user(); + } -void Account::setDisplayName(const QString &username) -{ - auto displayName = QString("%1@%2").arg(username, _url.host()); + auto displayName = QString("%1@%2").arg(credentialsUser, _url.host()); const auto port = url().port(); if (port > 0 && port != 80 && port != 443) { displayName.append(QLatin1Char(':')); displayName.append(QString::number(port)); } - _displayName = displayName; + return displayName; } QString Account::userIdAtHostWithPort() const diff --git a/src/libsync/account.h b/src/libsync/account.h index a991daed9cd47..4979931bd870d 100644 --- a/src/libsync/account.h +++ b/src/libsync/account.h @@ -146,7 +146,6 @@ class OWNCLOUDSYNC_EXPORT Account : public QObject /// The name of the account as shown in the toolbar [[nodiscard]] QString displayName() const; - void setDisplayName(const QString &username); /// User id in a form 'user@example.de, optionally port is added (if it is not 80 or 443) [[nodiscard]] QString userIdAtHostWithPort() const; From a7be4d752c5e870471ac67e959e4fe15e56ad76e Mon Sep 17 00:00:00 2001 From: Camila Ayres Date: Thu, 14 Nov 2024 19:39:56 +0100 Subject: [PATCH 14/14] Correct Q_PROPERTY for _davDisplayName. Signed-off-by: Camila Ayres --- src/libsync/account.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libsync/account.h b/src/libsync/account.h index 4979931bd870d..28165f05320fd 100644 --- a/src/libsync/account.h +++ b/src/libsync/account.h @@ -86,7 +86,7 @@ class OWNCLOUDSYNC_EXPORT Account : public QObject Q_OBJECT Q_PROPERTY(QString id MEMBER _id) Q_PROPERTY(QString davUser MEMBER _davUser) - Q_PROPERTY(QString displayName MEMBER _displayName) + Q_PROPERTY(QString davDisplayName MEMBER _davDisplayName) Q_PROPERTY(QString prettyName READ prettyName NOTIFY prettyNameChanged) Q_PROPERTY(QUrl url MEMBER _url) Q_PROPERTY(bool e2eEncryptionKeysGenerationAllowed MEMBER _e2eEncryptionKeysGenerationAllowed)