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

fix instances of: c++11 range-loop might detach Qt container warnings #5089

Merged
merged 2 commits into from
Nov 18, 2022
Merged
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
15 changes: 10 additions & 5 deletions src/gui/accountmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ bool AccountManager::restore()
return true;
}

for (const auto &accountId : settings->childGroups()) {
const auto settingsChildGroups = settings->childGroups();
for (const auto &accountId : settingsChildGroups) {
settings->beginGroup(accountId);
if (!skipSettingsKeys.contains(settings->group())) {
if (const auto acc = loadAccountHelper(*settings)) {
Expand Down Expand Up @@ -121,7 +122,8 @@ void AccountManager::backwardMigrationSettingsKeys(QStringList *deleteKeys, QStr
const auto accountsVersion = settings->value(QLatin1String(versionC)).toInt();

if (accountsVersion <= maxAccountsVersion) {
for (const auto &accountId : settings->childGroups()) {
const auto settingsChildGroups = settings->childGroups();
for (const auto &accountId : settingsChildGroups) {
settings->beginGroup(accountId);
const auto accountVersion = settings->value(QLatin1String(versionC), 1).toInt();

Expand Down Expand Up @@ -263,7 +265,8 @@ void AccountManager::saveAccountHelper(Account *acc, QSettings &settings, bool s
settings.beginGroup(QLatin1String(generalC));
qCInfo(lcAccountManager) << "Saving " << acc->approvedCerts().count() << " unknown certs.";
QByteArray certs;
for (const auto &cert : acc->approvedCerts()) {
const auto approvedCerts = acc->approvedCerts();
for (const auto &cert : approvedCerts) {
certs += cert.toPem() + '\n';
}
if (!certs.isEmpty()) {
Expand Down Expand Up @@ -342,7 +345,8 @@ AccountPtr AccountManager::loadAccountHelper(QSettings &settings)
acc->_settingsMap.insert(QLatin1String(userC), settings.value(userC));
acc->_displayName = settings.value(QLatin1String(displayNameC), "").toString();
QString authTypePrefix = authType + "_";
for (const auto &key : settings.childKeys()) {
const auto settingsChildKeys = settings.childKeys();
for (const auto &key : settingsChildKeys) {
if (!key.startsWith(authTypePrefix))
continue;
acc->_settingsMap.insert(key, settings.value(key));
Expand Down Expand Up @@ -370,7 +374,8 @@ AccountStatePtr AccountManager::account(const QString &name)

AccountStatePtr AccountManager::accountFromUserId(const QString &id) const
{
for (const auto &account : accounts()) {
const auto accountsList = accounts();
for (const auto &account : accountsList) {
const auto isUserIdWithPort = id.split(QLatin1Char(':')).size() > 1;
const auto port = isUserIdWithPort ? account->account()->url().port() : -1;
const auto portString = (port > 0 && port != 80 && port != 443) ? QStringLiteral(":%1").arg(port) : QStringLiteral("");
Expand Down
3 changes: 2 additions & 1 deletion src/gui/accountsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1476,7 +1476,8 @@ void AccountSettings::removeActionFromEncryptionMessage(const QString &actionId)

QAction *AccountSettings::addActionToEncryptionMessage(const QString &actionTitle, const QString &actionId)
{
for (const auto &action : _ui->encryptionMessage->actions()) {
const auto encryptionActions = _ui->encryptionMessage->actions();
for (const auto &action : encryptionActions) {
if (action->property(e2eUiActionIdKey) == actionId) {
return action;
}
Expand Down
6 changes: 4 additions & 2 deletions src/gui/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,9 @@ bool Application::configVersionMigration()
settings->endGroup();

// Wipe confusing keys from the future, ignore the others
for (const auto &badKey : deleteKeys)
for (const auto &badKey : qAsConst(deleteKeys)) {
settings->remove(badKey);
}
}

configFile.setClientVersionString(MIRALL_VERSION_STRING);
Expand Down Expand Up @@ -370,7 +371,8 @@ Application::Application(int &argc, char **argv)
this, &Application::slotAccountStateAdded);
connect(AccountManager::instance(), &AccountManager::accountRemoved,
this, &Application::slotAccountStateRemoved);
for (const auto &ai : AccountManager::instance()->accounts()) {
const auto accounts = AccountManager::instance()->accounts();
for (const auto &ai : accounts) {
slotAccountStateAdded(ai.data());
}

Expand Down
2 changes: 1 addition & 1 deletion src/gui/filedetails/sharemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ void ShareModel::handlePlaceholderLinkShare()
auto linkSharePresent = false;
auto placeholderLinkSharePresent = false;

for (const auto &share : _shares) {
for (const auto &share : qAsConst(_shares)) {
const auto shareType = share->getShareType();

if (!linkSharePresent && shareType == Share::TypeLink) {
Expand Down
44 changes: 26 additions & 18 deletions src/gui/folderman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ int FolderMan::setupFolders()

qCInfo(lcFolderMan) << "Setup folders from settings file";

for (const auto &account : AccountManager::instance()->accounts()) {
const auto accounts = AccountManager::instance()->accounts();
for (const auto &account : accounts) {
const auto id = account->account()->id();
if (!accountsWithSettings.contains(id)) {
continue;
Expand Down Expand Up @@ -219,7 +220,7 @@ int FolderMan::setupFolders()

emit folderListChanged(_folderMap);

for (const auto folder : _folderMap) {
for (const auto folder : qAsConst(_folderMap)) {
folder->processSwitchedToVirtualFiles();
}

Expand All @@ -228,7 +229,8 @@ int FolderMan::setupFolders()

void FolderMan::setupFoldersHelper(QSettings &settings, AccountStatePtr account, const QStringList &ignoreKeys, bool backwardsCompatible, bool foldersWithPlaceholders)
{
for (const auto &folderAlias : settings.childGroups()) {
const auto settingsChildGroups = settings.childGroups();
for (const auto &folderAlias : settingsChildGroups) {
// Skip folders with too-new version
settings.beginGroup(folderAlias);
if (ignoreKeys.contains(settings.group())) {
Expand Down Expand Up @@ -392,7 +394,8 @@ void FolderMan::backwardMigrationSettingsKeys(QStringList *deleteKeys, QStringLi
settings->endGroup();
};

for (const auto &accountId : settings->childGroups()) {
const auto settingsChildGroups = settings->childGroups();
for (const auto &accountId : settingsChildGroups) {
settings->beginGroup(accountId);
processSubgroup("Folders");
processSubgroup("Multifolders");
Expand Down Expand Up @@ -598,7 +601,8 @@ Folder *FolderMan::folder(const QString &alias)

void FolderMan::scheduleAllFolders()
{
for (Folder *f : _folderMap.values()) {
const auto folderMapValues = _folderMap.values();
for (Folder *f : folderMapValues) {
mgallien marked this conversation as resolved.
Show resolved Hide resolved
if (f && f->canSync()) {
scheduleFolder(f);
}
Expand Down Expand Up @@ -741,7 +745,8 @@ void FolderMan::slotAccountStateChanged()
if (accountState->isConnected()) {
qCInfo(lcFolderMan) << "Account" << accountName << "connected, scheduling its folders";

for (Folder *f : _folderMap.values()) {
const auto folderMapValues = _folderMap.values();
for (Folder *f : folderMapValues) {
mgallien marked this conversation as resolved.
Show resolved Hide resolved
if (f
&& f->canSync()
&& f->accountState() == accountState) {
Expand Down Expand Up @@ -781,7 +786,7 @@ void FolderMan::setSyncEnabled(bool enabled)
}
_syncEnabled = enabled;
// force a redraw in case the network connect status changed
emit(folderSyncStateChange(nullptr));
emit folderSyncStateChange(nullptr);
}

void FolderMan::startScheduledSyncSoon()
Expand Down Expand Up @@ -837,7 +842,7 @@ void FolderMan::startScheduledSyncSoon()
void FolderMan::slotStartScheduledFolderSync()
{
if (isAnySyncRunning()) {
for (auto f : _folderMap) {
for (auto f : qAsConst(_folderMap)) {
if (f->isSyncRunning())
qCInfo(lcFolderMan) << "Currently folder " << f->remoteUrl().toString() << " is running, wait for finish!";
}
Expand Down Expand Up @@ -1223,7 +1228,8 @@ QStringList FolderMan::findFileInLocalFolders(const QString &relPath, const Acco
if (!serverPath.startsWith('/'))
serverPath.prepend('/');

for (Folder *folder : this->map().values()) {
const auto mapValues = map().values();
for (Folder *folder : mapValues) {
mgallien marked this conversation as resolved.
Show resolved Hide resolved
if (acc && folder->accountState()->account() != acc) {
continue;
}
Expand Down Expand Up @@ -1421,12 +1427,13 @@ void FolderMan::slotWipeFolderForAccount(AccountState *accountState)

void FolderMan::setDirtyProxy()
{
for (const Folder *f : _folderMap.values()) {
if (f) {
if (f->accountState() && f->accountState()->account()
&& f->accountState()->account()->networkAccessManager()) {
const auto folderMapValues = _folderMap.values();
for (const auto folder : folderMapValues) {
if (folder) {
if (folder->accountState() && folder->accountState()->account()
&& folder->accountState()->account()->networkAccessManager()) {
// Need to do this so we do not use the old determined system proxy
f->accountState()->account()->networkAccessManager()->setProxy(
folder->accountState()->account()->networkAccessManager()->setProxy(
QNetworkProxy(QNetworkProxy::DefaultProxy));
}
}
Expand All @@ -1435,10 +1442,11 @@ void FolderMan::setDirtyProxy()

void FolderMan::setDirtyNetworkLimits()
{
for (Folder *f : _folderMap.values()) {
const auto folderMapValues = _folderMap.values();
for (auto folder : folderMapValues) {
// set only in busy folders. Otherwise they read the config anyway.
if (f && f->isBusy()) {
f->setDirtyNetworkLimits();
if (folder && folder->isBusy()) {
folder->setDirtyNetworkLimits();
}
}
}
Expand Down Expand Up @@ -1784,7 +1792,7 @@ void FolderMan::slotProcessFilesPushNotification(Account *account)
{
qCInfo(lcFolderMan) << "Got files push notification for account" << account;

for (auto folder : _folderMap) {
for (auto folder : qAsConst(_folderMap)) {
// Just run on the folders that belong to this account
if (folder->accountState()->account() != account) {
continue;
Expand Down
3 changes: 2 additions & 1 deletion src/gui/networksettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ void NetworkSettings::checkAccountLocalhost()
if (_ui->manualProxyRadioButton->isChecked()) {
// Check if at least one account is using localhost, because Qt proxy settings have no
// effect for localhost (#7169)
for (const auto &account : AccountManager::instance()->accounts()) {
const auto accounts = AccountManager::instance()->accounts();
for (const auto &account : accounts) {
const auto host = account->account()->url().host();
// Some typical url for localhost
if (host == "localhost" || host.startsWith("127.") || host == "[::1]")
Expand Down
3 changes: 2 additions & 1 deletion src/gui/socketapi/socketapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,8 @@ void SocketApi::setFileLock(const QString &localFile, const SyncFileItem::LockSt
void SocketApi::command_V2_LIST_ACCOUNTS(const QSharedPointer<SocketApiJobV2> &job) const
{
QJsonArray out;
for (auto acc : AccountManager::instance()->accounts()) {
const auto accounts = AccountManager::instance()->accounts();
for (auto acc : accounts) {
// TODO: Use uuid once https://github.com/owncloud/client/pull/8397 is merged
out << QJsonObject({ { "name", acc->account()->displayName() }, { "id", acc->account()->id() } });
}
Expand Down
3 changes: 2 additions & 1 deletion src/gui/tray/asyncimageresponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ void AsyncImageResponse::processNextImage()

OCC::AccountPtr accountInRequestedServer;

for (const auto &account : OCC::AccountManager::instance()->accounts()) {
const auto accountsList = OCC::AccountManager::instance()->accounts();
for (const auto &account : accountsList) {
if (account && account->account() && imagePath.startsWith(account->account()->url().toString())) {
accountInRequestedServer = account->account();
}
Expand Down
3 changes: 2 additions & 1 deletion src/gui/tray/notificationhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ void ServerNotificationHandler::slotNotificationsReceived(const QJsonDocument &j

if(json.contains("subjectRichParameters")) {
const auto richParams = json.value("subjectRichParameters").toObject();
for(const auto &key : richParams.keys()) {
const auto richParamsKeys = richParams.keys();
for(const auto &key : richParamsKeys) {
const auto parameterJsonObject = richParams.value(key).toObject();
a._subjectRichParameters.insert(key, Activity::RichSubjectParameter{
parameterJsonObject.value(QStringLiteral("type")).toString(),
Expand Down
4 changes: 2 additions & 2 deletions src/gui/tray/unifiedsearchresultslistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ void UnifiedSearchResultsListModel::startSearch()
endResetModel();
}

for (const auto &provider : _providers) {
for (const auto &provider : qAsConst(_providers)) {
startSearchForProvider(provider._id);
}
}
Expand Down Expand Up @@ -724,7 +724,7 @@ void UnifiedSearchResultsListModel::removeFetchMoreTrigger(const QString &provid

void UnifiedSearchResultsListModel::disconnectAndClearSearchJobs()
{
for (const auto &connection : _searchJobConnections) {
for (const auto &connection : qAsConst(_searchJobConnections)) {
if (connection) {
QObject::disconnect(connection);
}
Expand Down
9 changes: 5 additions & 4 deletions src/gui/tray/usermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,15 @@ void User::slotBuildNotificationDisplay(const ActivityList &list)
showDesktopNotification(subject, message, -static_cast<int>(qHash(subject)));

// Set these activities as notified here, rather than in showDesktopNotification
for(const auto &activity : toNotifyList) {
for(const auto &activity : qAsConst(toNotifyList)) {
_notifiedNotifications.insert(activity._id);
_activityModel->addNotificationToActivityList(activity);
}

return;
}

for(const auto &activity : toNotifyList) {
for(const auto &activity : qAsConst(toNotifyList)) {
const auto message = activity._objectType == QStringLiteral("chat")
? activity._message : AccountManager::instance()->accounts().count() == 1 ? "" : activity._accName;

Expand Down Expand Up @@ -220,7 +220,8 @@ void User::slotReceivedPushActivity(Account *account)

void User::slotCheckExpiredActivities()
{
for (const Activity &activity : _activityModel->errorsList()) {
const auto errorsList = _activityModel->errorsList();
for (const Activity &activity : errorsList) {
mgallien marked this conversation as resolved.
Show resolved Hide resolved
if (activity._expireAtMsecs > 0 && QDateTime::currentDateTime().toMSecsSinceEpoch() >= activity._expireAtMsecs) {
_activityModel->removeActivityFromActivityList(activity);
}
Expand Down Expand Up @@ -1032,7 +1033,7 @@ void UserModel::setCurrentUserId(const int id)

const auto isCurrentUserChanged = !_users[id]->isCurrentUser();
if (isCurrentUserChanged) {
for (const auto user : _users) {
for (const auto user : qAsConst(_users)) {
user->setCurrentUser(false);
}
_users[id]->setCurrentUser(true);
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 @@ -448,7 +448,7 @@ bool HttpCredentials::refreshAccessToken()
persist();
}
_isRenewingOAuthToken = false;
for (const auto &job : _retryQueue) {
for (const auto &job : qAsConst(_retryQueue)) {
if (job)
job->retry();
}
Expand Down
2 changes: 1 addition & 1 deletion src/libsync/discovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1611,7 +1611,7 @@ bool ProcessDirectoryJob::checkPermissions(const OCC::SyncFileItemPtr &item)

bool ProcessDirectoryJob::isAnyParentBeingRestored(const QString &file) const
{
for (const auto &directoryNameToRestore : _discoveryData->_directoryNamesToRestoreOnPropagation) {
for (const auto &directoryNameToRestore : qAsConst(_discoveryData->_directoryNamesToRestoreOnPropagation)) {
if (file.startsWith(QString(directoryNameToRestore + QLatin1Char('/')))) {
qCWarning(lcDisco) << "File" << file << " is within the tree that's being restored" << directoryNameToRestore;
return true;
Expand Down
4 changes: 2 additions & 2 deletions src/libsync/syncengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,7 @@ void SyncEngine::slotScheduleFilesDelayedSync()
newTimer->callOnTimeout(this, [this, newTimer] {
qCInfo(lcEngine) << "Rescanning now that delayed sync run is scheduled for:" << newTimer->files;

for (const auto &file : newTimer->files) {
for (const auto &file : qAsConst(newTimer->files)) {
this->_filesScheduledForLaterSync.remove(file);
}

Expand Down Expand Up @@ -1308,7 +1308,7 @@ void SyncEngine::slotUnscheduleFilesDelayedSync()
return;
}

for (const auto &file : _discoveryPhase->_filesUnscheduleSync) {
for (const auto &file : qAsConst(_discoveryPhase->_filesUnscheduleSync)) {
const auto fileSyncRunTimer = _filesScheduledForLaterSync.value(file);

if (fileSyncRunTimer) {
Expand Down
3 changes: 2 additions & 1 deletion test/syncenginetestutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,8 @@ FileInfo *FakeChunkMoveReply::perform(FileInfo &uploadsFileInfo, FileInfo &remot
Q_ASSERT(!fileName.isEmpty());

// Compute the size and content from the chunks if possible
for (auto chunkName : sourceFolder->children.keys()) {
const auto childrenKeys = sourceFolder->children.keys();
for (auto chunkName : childrenKeys) {
auto &x = sourceFolder->children[chunkName];
Q_ASSERT(!x.isDir);
Q_ASSERT(x.size > 0); // There should not be empty chunks
Expand Down
16 changes: 11 additions & 5 deletions test/testallfilesdeleted.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ private slots:
});

auto &modifier = deleteOnRemote ? fakeFolder.remoteModifier() : fakeFolder.localModifier();
for (const auto &s : fakeFolder.currentRemoteState().children.keys())
modifier.remove(s);
const auto childrenKeys = fakeFolder.currentRemoteState().children.keys();
for (const auto &key : childrenKeys) {
modifier.remove(key);
}

QVERIFY(!fakeFolder.syncOnce()); // Should fail because we cancel the sync
QCOMPARE(aboutToRemoveAllFilesCalled, 1);
Expand Down Expand Up @@ -110,8 +112,10 @@ private slots:
});

auto &modifier = deleteOnRemote ? fakeFolder.remoteModifier() : fakeFolder.localModifier();
for (const auto &s : fakeFolder.currentRemoteState().children.keys())
modifier.remove(s);
const auto childrenKeys = fakeFolder.currentRemoteState().children.keys();
for (const auto &key : childrenKeys) {
modifier.remove(key);
}

QVERIFY(fakeFolder.syncOnce()); // Should succeed, and all files must then be deleted

Expand Down Expand Up @@ -139,8 +143,10 @@ private slots:
[&] { QVERIFY(false); });
QVERIFY(fakeFolder.syncOnce());

for (const auto &s : fakeFolder.currentRemoteState().children.keys())
const auto childrenKeys = fakeFolder.currentRemoteState().children.keys();
for (const auto &s : childrenKeys) {
mgallien marked this conversation as resolved.
Show resolved Hide resolved
fakeFolder.syncJournal().avoidRenamesOnNextSync(s); // clears all the fileid and inodes.
}
fakeFolder.localModifier().remove("A/a1");
auto expectedState = fakeFolder.currentLocalState();
QVERIFY(fakeFolder.syncOnce());
Expand Down
Loading