Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use AccountPtr in Account signals instead of raw pointer #5543

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/gui/accountmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,20 +297,20 @@ void AccountManager::save(bool saveCredentials)
settings->setValue(QLatin1String(versionC), maxAccountsVersion);
for (const auto &acc : qAsConst(_accounts)) {
settings->beginGroup(acc->account()->id());
saveAccountHelper(acc->account().data(), *settings, saveCredentials);
saveAccountHelper(acc->account(), *settings, saveCredentials);
settings->endGroup();
}

settings->sync();
qCInfo(lcAccountManager) << "Saved all account settings, status:" << settings->status();
}

void AccountManager::saveAccount(Account *a)
void AccountManager::saveAccount(const AccountPtr &account)
{
qCDebug(lcAccountManager) << "Saving account" << a->url().toString();
qCDebug(lcAccountManager) << "Saving account" << account->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(account->id());
saveAccountHelper(account, *settings, false); // don't save credentials they might not have been loaded yet
settings->endGroup();

settings->sync();
Expand All @@ -328,7 +328,7 @@ 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(const AccountPtr &acc, QSettings &settings, bool saveCredentials)
{
qCDebug(lcAccountManager) << "Saving settings to" << settings.fileName();
settings.setValue(QLatin1String(versionC), maxAccountVersion);
Expand Down
4 changes: 2 additions & 2 deletions src/gui/accountmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#pragma once

#include "account.h"

Check failure on line 17 in src/gui/accountmanager.h

View workflow job for this annotation

GitHub Actions / build

src/gui/accountmanager.h:17:10 [clang-diagnostic-error]

'account.h' file not found
#include "accountstate.h"

namespace OCC {
Expand Down Expand Up @@ -92,7 +92,7 @@

public slots:
/// Saves account data, not including the credentials
void saveAccount(OCC::Account *a);
void saveAccount(const OCC::AccountPtr &account);

/// Saves account state data, not including the account
void saveAccountState(OCC::AccountState *a);
Expand All @@ -118,7 +118,7 @@

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();
Expand Down
2 changes: 1 addition & 1 deletion src/gui/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,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()
Expand Down
2 changes: 1 addition & 1 deletion src/gui/connectionvalidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* for more details.
*/

#include <QJsonDocument>

Check failure on line 15 in src/gui/connectionvalidator.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/connectionvalidator.cpp:15:10 [clang-diagnostic-error]

'QJsonDocument' file not found
#include <QJsonObject>
#include <QJsonArray>
#include <QLoggingCategory>
Expand Down Expand Up @@ -138,7 +138,7 @@
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);

Check warning on line 141 in src/gui/connectionvalidator.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/connectionvalidator.cpp:141:14 [cppcoreguidelines-init-variables]

variable '_account' is not initialized
}

if (!serverVersion.isEmpty() && !setAndCheckServerVersion(serverVersion)) {
Expand Down
2 changes: 1 addition & 1 deletion src/gui/creds/webflowcredentials.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@
}

_account->setCredentialSetting(userC, _user);
emit _account->wantsAccountSaved(_account);
emit _account->wantsAccountSaved(_account->sharedFromThis());

Check warning on line 220 in src/gui/creds/webflowcredentials.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/creds/webflowcredentials.cpp:220:10 [cppcoreguidelines-init-variables]

variable '_account' is not initialized

// write cert if there is one
if (!_clientSslCertificate.isNull()) {
Expand Down
12 changes: 6 additions & 6 deletions src/gui/folderman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,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;
Expand Down Expand Up @@ -967,7 +967,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();
Expand Down Expand Up @@ -1009,7 +1009,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;
Expand Down Expand Up @@ -1057,7 +1057,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()) {
Expand Down Expand Up @@ -1997,7 +1997,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);
}
}
Expand All @@ -2017,7 +2017,7 @@ void FolderMan::slotProcessFilesPushNotification(Account *account)
}
}

void FolderMan::slotConnectToPushNotifications(Account *account)
void FolderMan::slotConnectToPushNotifications(const AccountPtr &account)
{
const auto pushNotifications = account->pushNotifications();

Expand Down
6 changes: 3 additions & 3 deletions src/gui/folderman.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#ifndef FOLDERMAN_H
#define FOLDERMAN_H

#include <QByteArray>

Check failure on line 19 in src/gui/folderman.h

View workflow job for this annotation

GitHub Actions / build

src/gui/folderman.h:19:10 [clang-diagnostic-error]

'QByteArray' file not found
#include <QObject>
#include <QQueue>
#include <QList>
Expand Down Expand Up @@ -306,7 +306,7 @@
// 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.
Expand All @@ -326,7 +326,7 @@

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 = {});

Expand Down Expand Up @@ -358,7 +358,7 @@
void runEtagJobsIfPossible(const QList<Folder *> &folderMap);
void runEtagJobIfPossible(Folder *folder);

bool pushNotificationsFilesReady(Account *account);
bool pushNotificationsFilesReady(const OCC::AccountPtr &account);

[[nodiscard]] bool isSwitchToVfsNeeded(const FolderDefinition &folderDefinition) const;

Expand Down
4 changes: 2 additions & 2 deletions src/gui/networksettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -275,7 +275,7 @@ void NetworkSettings::saveBWLimitSettings()
_account->setDownloadLimit(downloadLimit);
_account->setUploadLimitSetting(static_cast<Account::AccountNetworkTransferLimitSetting>(useUploadLimit));
_account->setUploadLimit(uploadLimit);
AccountManager::instance()->saveAccount(_account.data());
AccountManager::instance()->saveAccount(_account);
} else {
ConfigFile cfg;
cfg.setUseDownloadLimit(useDownloadLimit);
Expand Down
6 changes: 3 additions & 3 deletions src/gui/owncloudgui.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

Check notice on line 1 in src/gui/owncloudgui.cpp

View workflow job for this annotation

GitHub Actions / build

Run clang-format on src/gui/owncloudgui.cpp

File src/gui/owncloudgui.cpp does not conform to Custom style guidelines. (lines 288)
* Copyright (C) by Klaas Freitag <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -273,7 +273,7 @@
slotComputeOverallSyncStatus();
}

void ownCloudGui::slotTrayMessageIfServerUnsupported(Account *account)
void ownCloudGui::slotTrayMessageIfServerUnsupported(const AccountPtr &account)

Check warning on line 276 in src/gui/owncloudgui.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/owncloudgui.cpp:276:19 [readability-convert-member-functions-to-static]

method 'slotTrayMessageIfServerUnsupported' can be made static
{
if (account->serverVersionUnsupported()) {
slotShowTrayMessage(
Expand All @@ -285,8 +285,8 @@
}
}

void ownCloudGui::slotNeedToAcceptTermsOfService(OCC::AccountPtr account,
AccountState::State state)
void ownCloudGui::slotNeedToAcceptTermsOfService(const OCC::AccountPtr &account,

Check warning on line 288 in src/gui/owncloudgui.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/owncloudgui.cpp:288:19 [readability-convert-member-functions-to-static]

method 'slotNeedToAcceptTermsOfService' can be made static

Check warning on line 288 in src/gui/owncloudgui.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/owncloudgui.cpp:288:50 [bugprone-easily-swappable-parameters]

2 adjacent parameters of 'slotNeedToAcceptTermsOfService' of similar type are easily swapped by mistake
const OCC::AccountState::State state)
{
if (state == AccountState::NeedToSignTermsOfService) {
slotShowTrayMessage(
Expand Down
6 changes: 3 additions & 3 deletions src/gui/owncloudgui.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

Check notice on line 1 in src/gui/owncloudgui.h

View workflow job for this annotation

GitHub Actions / build

Run clang-format on src/gui/owncloudgui.h

File src/gui/owncloudgui.h does not conform to Custom style guidelines. (lines 97)
* Copyright (C) by Klaas Freitag <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -93,9 +93,9 @@
void slotHelp();
void slotOpenPath(const QString &path);
void slotAccountStateChanged();
void slotTrayMessageIfServerUnsupported(OCC::Account *account);
void slotNeedToAcceptTermsOfService(OCC::AccountPtr account,
OCC::AccountState::State state);
void slotTrayMessageIfServerUnsupported(const OCC::AccountPtr &account);
void slotNeedToAcceptTermsOfService(const OCC::AccountPtr &account,
const OCC::AccountState::State state);

/**
* Open a share dialog for a file or folder.
Expand Down
12 changes: 6 additions & 6 deletions src/libsync/account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ void Account::setDavUser(const QString &newDavUser)
if (_davUser == newDavUser)
return;
_davUser = newDavUser;
emit wantsAccountSaved(this);
emit wantsAccountSaved(sharedFromThis());
emit prettyNameChanged();
}

Expand Down Expand Up @@ -318,7 +318,7 @@ void Account::trySetupPushNotifications()

connect(_pushNotifications, &PushNotifications::ready, this, [this]() {
_pushNotificationsReconnectTimer.stop();
emit pushNotificationsReady(this);
emit pushNotificationsReady(sharedFromThis());
});

const auto disablePushNotifications = [this]() {
Expand All @@ -327,7 +327,7 @@ void Account::trySetupPushNotifications()
return;
}
if (!_pushNotifications->isReady()) {
emit pushNotificationsDisabled(this);
emit pushNotificationsDisabled(sharedFromThis());
}
if (!_pushNotificationsReconnectTimer.isActive()) {
_pushNotificationsReconnectTimer.start();
Expand Down Expand Up @@ -595,7 +595,7 @@ void Account::slotHandleSslErrors(QNetworkReply *reply, QList<QSslError> 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.";
Expand Down Expand Up @@ -723,7 +723,7 @@ bool Account::shouldSkipE2eeMetadataChecksumValidation() const
void Account::resetShouldSkipE2eeMetadataChecksumValidation()
{
_skipE2eeMetadataChecksumValidation = false;
emit wantsAccountSaved(this);
emit wantsAccountSaved(sharedFromThis());
}

int Account::serverVersionInt() const
Expand Down Expand Up @@ -790,7 +790,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){
Expand Down
8 changes: 4 additions & 4 deletions src/libsync/account.h
Original file line number Diff line number Diff line change
Expand Up @@ -432,9 +432,9 @@ 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 serverVersionChanged(OCC::Account *account, const QString &newVersion, const QString &oldVersion);
void serverVersionChanged(const OCC::AccountPtr &account, const QString &newVersion, const QString &oldVersion);

void accountChangedAvatar();
void accountChangedDisplayName();
Expand All @@ -444,8 +444,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();

Expand Down
2 changes: 1 addition & 1 deletion src/libsync/creds/httpcredentials.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* for more details.
*/

#include <QLoggingCategory>

Check failure on line 16 in src/libsync/creds/httpcredentials.cpp

View workflow job for this annotation

GitHub Actions / build

src/libsync/creds/httpcredentials.cpp:16:10 [clang-diagnostic-error]

'QLoggingCategory' file not found
#include <QMutex>
#include <QNetworkReply>
#include <QSettings>
Expand Down Expand Up @@ -434,7 +434,7 @@
// 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()) {
Expand Down
8 changes: 4 additions & 4 deletions test/testpushnotifications.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* for more details.
*/

#include <QTest>

Check failure on line 15 in test/testpushnotifications.cpp

View workflow job for this annotation

GitHub Actions / build

test/testpushnotifications.cpp:15:10 [clang-diagnostic-error]

'QTest' file not found
#include <QVector>
#include <QWebSocketServer>
#include <QSignalSpy>
Expand Down Expand Up @@ -257,8 +257,8 @@

QCOMPARE(connectionLostSpy.count(), 1);

auto accountSent = pushNotificationsDisabledSpy.at(0).at(0).value<OCC::Account *>();
QCOMPARE(accountSent, account.data());
const auto accountSent = pushNotificationsDisabledSpy.at(0).at(0).value<OCC::AccountPtr>();
QCOMPARE(accountSent.data(), account.data());
}

void testAccount_web_socket_authenticationFailed_emitNotificationsDisabled()
Expand All @@ -272,8 +272,8 @@

// Now the pushNotificationsDisabled Signal should be emitted
QCOMPARE(pushNotificationsDisabledSpy.count(), 1);
auto accountSent = pushNotificationsDisabledSpy.at(0).at(0).value<OCC::Account *>();
QCOMPARE(accountSent, account.data());
const auto accountSent = pushNotificationsDisabledSpy.at(0).at(0).value<OCC::AccountPtr>();
QCOMPARE(accountSent.data(), account.data());
}

void testPingTimeout_pingTimedOut_reconnect()
Expand Down
Loading