diff --git a/src/gui/accountmanager.cpp b/src/gui/accountmanager.cpp index f89085664ceda..1ff8dc4fba8f3 100644 --- a/src/gui/accountmanager.cpp +++ b/src/gui/accountmanager.cpp @@ -280,7 +280,7 @@ void AccountManager::save(bool saveCredentials) settings->setValue(QLatin1String(versionC), maxAccountsVersion); for (const auto &acc : std::as_const(_accounts)) { settings->beginGroup(acc->account()->id()); - saveAccountHelper(acc->account().data(), *settings, saveCredentials); + saveAccountHelper(acc->account(), *settings, saveCredentials); settings->endGroup(); } @@ -288,7 +288,7 @@ void AccountManager::save(bool saveCredentials) qCInfo(lcAccountManager) << "Saved all account settings, status:" << settings->status(); } -void AccountManager::saveAccount(Account *newAccountData) +void AccountManager::saveAccount(const AccountPtr &newAccountData) { qCDebug(lcAccountManager) << "Saving account" << newAccountData->url().toString(); const auto settings = ConfigFile::settingsWithGroup(QLatin1String(accountsC)); @@ -311,7 +311,7 @@ void AccountManager::saveAccountState(AccountState *a) qCDebug(lcAccountManager) << "Saved account state settings, status:" << settings->status(); } -void AccountManager::saveAccountHelper(Account *account, QSettings &settings, bool saveCredentials) +void AccountManager::saveAccountHelper(const AccountPtr &account, QSettings &settings, bool saveCredentials) { qCDebug(lcAccountManager) << "Saving settings to" << settings.fileName(); settings.setValue(QLatin1String(versionC), maxAccountVersion); diff --git a/src/gui/accountmanager.h b/src/gui/accountmanager.h index ceb357f09a96a..cc405fec17ce0 100644 --- a/src/gui/accountmanager.h +++ b/src/gui/accountmanager.h @@ -92,7 +92,7 @@ class AccountManager : public QObject public slots: /// Saves account data when adding user, when updating e.g. dav user, not including the credentials - void saveAccount(OCC::Account *newAccountData); + void saveAccount(const OCC::AccountPtr &newAccountData); /// Saves account state data, not including the account void saveAccountState(OCC::AccountState *a); @@ -118,7 +118,7 @@ public slots: private: // saving and loading Account to settings - void saveAccountHelper(Account *account, QSettings &settings, bool saveCredentials = true); + void saveAccountHelper(const AccountPtr &account, QSettings &settings, bool saveCredentials = true); AccountPtr loadAccountHelper(QSettings &settings); bool restoreFromLegacySettings(); diff --git a/src/gui/application.cpp b/src/gui/application.cpp index 53c85e4b21370..ecaca4fb37a1b 100644 --- a/src/gui/application.cpp +++ b/src/gui/application.cpp @@ -655,7 +655,7 @@ void Application::slotAccountStateAdded(AccountState *accountState) connect(accountState->account().data(), &Account::serverVersionChanged, _folderManager.data(), &FolderMan::slotServerVersionChanged); - _gui->slotTrayMessageIfServerUnsupported(accountState->account().data()); + _gui->slotTrayMessageIfServerUnsupported(accountState->account()); } void Application::slotCleanup() diff --git a/src/gui/connectionvalidator.cpp b/src/gui/connectionvalidator.cpp index 61ba6ee447510..6c1bec008ad41 100644 --- a/src/gui/connectionvalidator.cpp +++ b/src/gui/connectionvalidator.cpp @@ -138,7 +138,7 @@ void ConnectionValidator::slotStatusFound(const QUrl &url, const QJsonObject &in if (_account->url() != url) { qCInfo(lcConnectionValidator()) << "status.php was redirected to" << url.toString(); _account->setUrl(url); - emit _account->wantsAccountSaved(_account.data()); + emit _account->wantsAccountSaved(_account); } if (!serverVersion.isEmpty() && !setAndCheckServerVersion(serverVersion)) { diff --git a/src/gui/creds/webflowcredentials.cpp b/src/gui/creds/webflowcredentials.cpp index bd2eb458eb07c..d5618307247be 100644 --- a/src/gui/creds/webflowcredentials.cpp +++ b/src/gui/creds/webflowcredentials.cpp @@ -218,7 +218,7 @@ void WebFlowCredentials::persist() { } _account->setCredentialSetting(userC, _user); - emit _account->wantsAccountSaved(_account); + emit _account->wantsAccountSaved(_account->sharedFromThis()); // write cert if there is one if (!_clientSslCertificate.isNull()) { diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp index 892c4fef0f441..4abfe8458599e 100644 --- a/src/gui/folderman.cpp +++ b/src/gui/folderman.cpp @@ -982,7 +982,7 @@ void FolderMan::slotStartScheduledFolderSync() } } -bool FolderMan::pushNotificationsFilesReady(Account *account) +bool FolderMan::pushNotificationsFilesReady(const AccountPtr &account) { const auto pushNotifications = account->pushNotifications(); const auto pushFilesAvailable = account->capabilities().availablePushNotifications() & PushNotificationType::Files; @@ -1017,7 +1017,7 @@ void FolderMan::slotEtagPollTimerTimeout() // Some folders need not to be checked because they use the push notifications std::copy_if(folderMapValues.begin(), folderMapValues.end(), std::back_inserter(foldersToRun), [this](Folder *folder) -> bool { const auto account = folder->accountState()->account(); - return !pushNotificationsFilesReady(account.data()); + return !pushNotificationsFilesReady(account); }); qCInfo(lcFolderMan) << "Number of folders that don't use push notifications:" << foldersToRun.size(); @@ -1059,7 +1059,7 @@ void FolderMan::runEtagJobIfPossible(Folder *folder) return; } // When not using push notifications, make sure polltime is reached - if (!pushNotificationsFilesReady(folder->accountState()->account().data())) { + if (!pushNotificationsFilesReady(folder->accountState()->account())) { if (folder->msecSinceLastSync() < polltime) { qCInfo(lcFolderMan) << "Can not run etag job: Polltime not reached"; return; @@ -1107,7 +1107,7 @@ void FolderMan::slotForwardFolderSyncStateChange() } } -void FolderMan::slotServerVersionChanged(Account *account) +void FolderMan::slotServerVersionChanged(const OCC::AccountPtr &account) { // Pause folders if the server version is unsupported if (account->serverVersionUnsupported()) { @@ -2059,7 +2059,7 @@ void FolderMan::slotSetupPushNotifications(const Folder::Map &folderMap) // See if the account already provides the PushNotifications object and if yes connect to it. // If we can't connect at this point, the signals will be connected in slotPushNotificationsReady() // after the PushNotification object emitted the ready signal - slotConnectToPushNotifications(account.data()); + slotConnectToPushNotifications(account); connect(account.data(), &Account::pushNotificationsReady, this, &FolderMan::slotConnectToPushNotifications, Qt::UniqueConnection); } } @@ -2079,7 +2079,7 @@ void FolderMan::slotProcessFilesPushNotification(Account *account) } } -void FolderMan::slotConnectToPushNotifications(Account *account) +void FolderMan::slotConnectToPushNotifications(const AccountPtr &account) { const auto pushNotifications = account->pushNotifications(); diff --git a/src/gui/folderman.h b/src/gui/folderman.h index 9ab08c9ab4bc4..a1fdf81b74c14 100644 --- a/src/gui/folderman.h +++ b/src/gui/folderman.h @@ -317,7 +317,7 @@ private slots: // FolderMan::folderSyncStateChange(Folder*) signal. void slotForwardFolderSyncStateChange(); - void slotServerVersionChanged(OCC::Account *account); + void slotServerVersionChanged(const OCC::AccountPtr &account); /** * A file whose locks were being monitored has become unlocked. @@ -337,7 +337,7 @@ private slots: void slotSetupPushNotifications(const OCC::Folder::Map &); void slotProcessFilesPushNotification(OCC::Account *account); - void slotConnectToPushNotifications(OCC::Account *account); + void slotConnectToPushNotifications(const OCC::AccountPtr &account); void slotLeaveShare(const QString &localFile, const QByteArray &folderToken = {}); @@ -369,7 +369,7 @@ private slots: void runEtagJobsIfPossible(const QList &folderMap); void runEtagJobIfPossible(Folder *folder); - bool pushNotificationsFilesReady(Account *account); + bool pushNotificationsFilesReady(const OCC::AccountPtr &account); [[nodiscard]] bool isSwitchToVfsNeeded(const FolderDefinition &folderDefinition) const; diff --git a/src/gui/networksettings.cpp b/src/gui/networksettings.cpp index c0f60b7bb1f37..60eacf479f37e 100644 --- a/src/gui/networksettings.cpp +++ b/src/gui/networksettings.cpp @@ -222,7 +222,7 @@ void NetworkSettings::saveProxySettings() _account->setProxySettings(proxySetting, proxyType, host, port, needsAuth, user, password); const auto accountState = AccountManager::instance()->accountFromUserId(_account->userIdAtHostWithPort()); accountState->freshConnectionAttempt(); - AccountManager::instance()->saveAccount(_account.data()); + AccountManager::instance()->saveAccount(_account); } else { ConfigFile().setProxyType(proxyType, host, port, needsAuth, user, password); ClientProxy proxy; @@ -275,7 +275,7 @@ void NetworkSettings::saveBWLimitSettings() _account->setDownloadLimit(downloadLimit); _account->setUploadLimitSetting(static_cast(useUploadLimit)); _account->setUploadLimit(uploadLimit); - AccountManager::instance()->saveAccount(_account.data()); + AccountManager::instance()->saveAccount(_account); } else { ConfigFile cfg; cfg.setUseDownloadLimit(useDownloadLimit); diff --git a/src/gui/owncloudgui.cpp b/src/gui/owncloudgui.cpp index 5f5478260ea28..e387275968cad 100644 --- a/src/gui/owncloudgui.cpp +++ b/src/gui/owncloudgui.cpp @@ -264,7 +264,7 @@ void ownCloudGui::slotOpenPath(const QString &path) showInFileManager(path); } -void ownCloudGui::slotTrayMessageIfServerUnsupported(Account *account) +void ownCloudGui::slotTrayMessageIfServerUnsupported(const AccountPtr &account) { if (account->serverVersionUnsupported()) { slotShowTrayMessage( @@ -276,8 +276,8 @@ void ownCloudGui::slotTrayMessageIfServerUnsupported(Account *account) } } -void ownCloudGui::slotNeedToAcceptTermsOfService(OCC::AccountPtr account, - AccountState::State state) +void ownCloudGui::slotNeedToAcceptTermsOfService(const OCC::AccountPtr &account, + const OCC::AccountState::State state) { if (state == AccountState::NeedToSignTermsOfService) { slotShowTrayMessage( diff --git a/src/gui/owncloudgui.h b/src/gui/owncloudgui.h index 446b58a9c19be..d02d7d12402df 100644 --- a/src/gui/owncloudgui.h +++ b/src/gui/owncloudgui.h @@ -91,8 +91,8 @@ public slots: void slotSettingsDialogActivated(); void slotHelp(); void slotOpenPath(const QString &path); - void slotTrayMessageIfServerUnsupported(OCC::Account *account); - void slotNeedToAcceptTermsOfService(OCC::AccountPtr account, + void slotTrayMessageIfServerUnsupported(const OCC::AccountPtr &account); + void slotNeedToAcceptTermsOfService(const OCC::AccountPtr &account, OCC::AccountState::State state); /** diff --git a/src/gui/owncloudsetupwizard.cpp b/src/gui/owncloudsetupwizard.cpp index 50a5fce6cbd74..49eae7fe314ce 100644 --- a/src/gui/owncloudsetupwizard.cpp +++ b/src/gui/owncloudsetupwizard.cpp @@ -777,7 +777,7 @@ AccountState *OwncloudSetupWizard::applyAccountChanges() auto manager = AccountManager::instance(); auto newState = manager->addAccount(newAccount); - manager->saveAccount(newAccount.data()); + manager->saveAccount(newAccount); return newState; } diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp index fc7af4d1eb0f3..bb0a0e117b803 100644 --- a/src/libsync/account.cpp +++ b/src/libsync/account.cpp @@ -146,7 +146,7 @@ void Account::setDavUser(const QString &newDavUser) _davUser = newDavUser; - emit wantsAccountSaved(this); + emit wantsAccountSaved(sharedFromThis()); emit prettyNameChanged(); } @@ -332,7 +332,7 @@ void Account::trySetupPushNotifications() connect(_pushNotifications, &PushNotifications::ready, this, [this]() { _pushNotificationsReconnectTimer.stop(); - emit pushNotificationsReady(this); + emit pushNotificationsReady(sharedFromThis()); }); const auto disablePushNotifications = [this]() { @@ -341,7 +341,7 @@ void Account::trySetupPushNotifications() return; } if (!_pushNotifications->isReady()) { - emit pushNotificationsDisabled(this); + emit pushNotificationsDisabled(sharedFromThis()); } if (!_pushNotificationsReconnectTimer.isActive()) { _pushNotificationsReconnectTimer.start(); @@ -609,7 +609,7 @@ void Account::slotHandleSslErrors(QNetworkReply *reply, QList errors) if (!approvedCerts.isEmpty()) { QSslConfiguration::defaultConfiguration().addCaCertificates(approvedCerts); addApprovedCerts(approvedCerts); - emit wantsAccountSaved(this); + emit wantsAccountSaved(sharedFromThis()); // all ssl certs are known and accepted. We can ignore the problems right away. qCInfo(lcAccount) << out << "Certs are known and trusted! This is not an actual error."; @@ -737,7 +737,7 @@ bool Account::shouldSkipE2eeMetadataChecksumValidation() const void Account::resetShouldSkipE2eeMetadataChecksumValidation() { _skipE2eeMetadataChecksumValidation = false; - emit wantsAccountSaved(this); + emit wantsAccountSaved(sharedFromThis()); } int Account::serverVersionInt() const @@ -809,7 +809,7 @@ void Account::setServerVersion(const QString &version) auto oldServerVersion = _serverVersion; _serverVersion = version; - emit serverVersionChanged(this, oldServerVersion, version); + emit serverVersionChanged(sharedFromThis(), oldServerVersion, version); } void Account::writeAppPasswordOnce(QString appPassword){ @@ -1122,7 +1122,7 @@ void Account::setEncryptionCertificateFingerprint(const QByteArray &fingerprint) _encryptionCertificateFingerprint = fingerprint; _e2e.usbTokenInformation()->setSha256Fingerprint(fingerprint); Q_EMIT encryptionCertificateFingerprintChanged(); - Q_EMIT wantsAccountSaved(this); + Q_EMIT wantsAccountSaved(sharedFromThis()); } void Account::setAskUserForMnemonic(const bool ask) diff --git a/src/libsync/account.h b/src/libsync/account.h index 49d9d20e58aed..041144387d454 100644 --- a/src/libsync/account.h +++ b/src/libsync/account.h @@ -444,11 +444,11 @@ public slots: void proxyAuthenticationRequired(const QNetworkProxy &, QAuthenticator *); // e.g. when the approved SSL certificates changed - void wantsAccountSaved(OCC::Account *acc); + void wantsAccountSaved(const OCC::AccountPtr &acc); void wantsFoldersSynced(); - void serverVersionChanged(OCC::Account *account, const QString &newVersion, const QString &oldVersion); + void serverVersionChanged(const AccountPtr &account, const QString &newVersion, const QString &oldVersion); void accountChangedAvatar(); void accountChangedDisplayName(); @@ -460,8 +460,8 @@ public slots: /// Used in RemoteWipe void appPasswordRetrieved(QString); - void pushNotificationsReady(OCC::Account *account); - void pushNotificationsDisabled(OCC::Account *account); + void pushNotificationsReady(const OCC::AccountPtr &account); + void pushNotificationsDisabled(const OCC::AccountPtr &account); void userStatusChanged(); diff --git a/src/libsync/creds/httpcredentials.cpp b/src/libsync/creds/httpcredentials.cpp index ef1c4c5e8f7a8..2480cb9236f06 100644 --- a/src/libsync/creds/httpcredentials.cpp +++ b/src/libsync/creds/httpcredentials.cpp @@ -434,7 +434,7 @@ void HttpCredentials::persist() // it's just written if it gets passed into the constructor. _account->setCredentialSetting(QLatin1String(clientCertBundleC), _clientCertBundle); } - emit _account->wantsAccountSaved(_account); + emit _account->wantsAccountSaved(_account->sharedFromThis()); // write secrets to the keychain if (!_clientCertBundle.isEmpty()) { diff --git a/test/testpushnotifications.cpp b/test/testpushnotifications.cpp index ee7e0c4fcc56f..e8a2ab08cf120 100644 --- a/test/testpushnotifications.cpp +++ b/test/testpushnotifications.cpp @@ -257,8 +257,8 @@ private slots: QCOMPARE(connectionLostSpy.count(), 1); - auto accountSent = pushNotificationsDisabledSpy.at(0).at(0).value(); - QCOMPARE(accountSent, account.data()); + const auto accountSent = pushNotificationsDisabledSpy.at(0).at(0).value(); + QCOMPARE(accountSent.data(), account.data()); } void testAccount_web_socket_authenticationFailed_emitNotificationsDisabled() @@ -272,8 +272,8 @@ private slots: // Now the pushNotificationsDisabled Signal should be emitted QCOMPARE(pushNotificationsDisabledSpy.count(), 1); - auto accountSent = pushNotificationsDisabledSpy.at(0).at(0).value(); - QCOMPARE(accountSent, account.data()); + const auto accountSent = pushNotificationsDisabledSpy.at(0).at(0).value(); + QCOMPARE(accountSent.data(), account.data()); } void testPingTimeout_pingTimedOut_reconnect()