Skip to content
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
5 changes: 5 additions & 0 deletions src/gui/accountmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,21 @@ AccountManager::AccountsRestoreResult AccountManager::restore(const bool alsoRes
if (skipSettingsKeys.contains(settings->group())) {
// Should not happen: bad container keys should have been deleted
qCWarning(lcAccountManager) << "Accounts structure is too new, ignoring";
emit(accountListInitialized());
return AccountsRestoreSuccessWithSkipped;
}

// If there are no accounts, check the old format.
#if !DISABLE_ACCOUNT_MIGRATION
if (settings->childGroups().isEmpty() && !settings->contains(QLatin1String(versionC)) && alsoRestoreLegacySettings) {
restoreFromLegacySettings();
emit(accountListInitialized());
return AccountsRestoreSuccessFromLegacyVersion;
}
#endif

if (settings->childGroups().isEmpty()) {
emit(accountListInitialized());
return AccountsNotFound;
}

Expand Down Expand Up @@ -149,6 +152,8 @@ AccountManager::AccountsRestoreResult AccountManager::restore(const bool alsoRes
}
}

emit(accountListInitialized());

ConfigFile().cleanupGlobalNetworkConfiguration();
ClientProxy().cleanupGlobalNetworkConfiguration();

Expand Down
1 change: 1 addition & 0 deletions src/gui/accountmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#pragma once

#include "account.h"

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

View workflow job for this annotation

GitHub Actions / build

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

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

namespace OCC {
Expand Down Expand Up @@ -108,6 +108,7 @@
void removeAccountFolders(OCC::AccountState *account);
void forceLegacyImportChanged();
void capabilitiesChanged();
void accountListInitialized();

private:
// saving and loading Account to settings
Expand Down
46 changes: 40 additions & 6 deletions src/gui/tray/usermodel.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/*
* SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: GPL-2.0-or-later
Expand Down Expand Up @@ -1334,13 +1334,14 @@
UserModel::UserModel(QObject *parent)
: QAbstractListModel(parent)
{
// TODO: Remember selected user from last quit via settings file
if (AccountManager::instance()->accounts().size() > 0) {
buildUserList();
setInitialUser();
}

connect(AccountManager::instance(), &AccountManager::accountAdded,
this, &UserModel::buildUserList);
this, &UserModel::addAccsToUserList);
connect(AccountManager::instance(), &AccountManager::accountListInitialized,
this, &UserModel::setInitialUser);
}

void UserModel::buildUserList()
Expand All @@ -1349,10 +1350,41 @@
auto user = AccountManager::instance()->accounts().at(i);
addUser(user);
}
}

void UserModel::addAccsToUserList()
{
if (_init) {
_users.first()->setCurrentUser(true);
_init = false;
return;
}

buildUserList();
}

void UserModel::setInitialUser()
{
if (!_init) {
return;
}

buildUserList();

if(!_users.isEmpty()) {
ConfigFile cfg;

Check warning on line 1373 in src/gui/tray/usermodel.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/tray/usermodel.cpp:1373:20 [cppcoreguidelines-init-variables]

variable 'cfg' is not initialized
const uint lastSelectedAccountId = cfg.lastSelectedAccount();

Check warning on line 1374 in src/gui/tray/usermodel.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/tray/usermodel.cpp:1374:20 [cppcoreguidelines-init-variables]

variable 'lastSelectedAccountId' is not initialized

for (int i = 0; i < _users.size(); i++) {
if (_users.at(i)->account()->id().toUInt() == lastSelectedAccountId) {
setCurrentUserId(i);
}
}

if (_currentUserId < 0) {
setCurrentUserId(0);
}
}

_init = false;
}

int UserModel::numUsers()
Expand Down Expand Up @@ -1430,7 +1462,7 @@
});

_users << u;
if (isCurrent || _currentUserId < 0) {
if (isCurrent || (_currentUserId < 0 && !_init)) {
setCurrentUserId(_users.size() - 1);
}

Expand Down Expand Up @@ -1524,6 +1556,8 @@
// order has changed, index remained the same
emit currentUserChanged();
} else if (_currentUserId != id) {
ConfigFile cfg;

Check warning on line 1559 in src/gui/tray/usermodel.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/tray/usermodel.cpp:1559:20 [cppcoreguidelines-init-variables]

variable 'cfg' is not initialized
cfg.setLastSelectedAccount(_users[id]->account()->id().toUInt());
_currentUserId = id;
emit currentUserChanged();
}
Expand Down
2 changes: 2 additions & 0 deletions src/gui/tray/usermodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#ifndef USERMODEL_H
#define USERMODEL_H

#include <QAbstractListModel>

Check failure on line 9 in src/gui/tray/usermodel.h

View workflow job for this annotation

GitHub Actions / build

src/gui/tray/usermodel.h:9:10 [clang-diagnostic-error]

'QAbstractListModel' file not found
#include <QImage>
#include <QDateTime>
#include <QStringList>
Expand Down Expand Up @@ -292,6 +292,8 @@
bool _init = true;

void buildUserList();
void addAccsToUserList();
void setInitialUser();
};

class ImageProvider : public QQuickAsyncImageProvider
Expand Down
15 changes: 15 additions & 0 deletions src/libsync/configfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: GPL-2.0-or-later
*/

#include "config.h"

Check failure on line 7 in src/libsync/configfile.cpp

View workflow job for this annotation

GitHub Actions / build

src/libsync/configfile.cpp:7:10 [clang-diagnostic-error]

'config.h' file not found

#include "configfile.h"
#include "theme.h"
Expand Down Expand Up @@ -83,7 +83,10 @@
static const QString defaultEnterpriseChannel = "enterprise";

static constexpr char languageC[] = "language";

static constexpr char lastSelectedAccountC[] = "lastSelectedAccount";

Check warning on line 87 in src/libsync/configfile.cpp

View workflow job for this annotation

GitHub Actions / build

src/libsync/configfile.cpp:87:23 [readability-static-definition-in-anonymous-namespace]

'lastSelectedAccountC' is a static definition in anonymous namespace; static is redundant here

Check warning on line 87 in src/libsync/configfile.cpp

View workflow job for this annotation

GitHub Actions / build

src/libsync/configfile.cpp:87:18 [cppcoreguidelines-avoid-c-arrays]

do not declare C-style arrays, use std::array<> instead

static constexpr int deleteFilesThresholdDefaultValue = 100;

Check warning on line 89 in src/libsync/configfile.cpp

View workflow job for this annotation

GitHub Actions / build

src/libsync/configfile.cpp:89:22 [readability-static-definition-in-anonymous-namespace]

'deleteFilesThresholdDefaultValue' is a static definition in anonymous namespace; static is redundant here
}

namespace OCC {
Expand Down Expand Up @@ -1227,7 +1230,19 @@
settings.setValue(QLatin1String(languageC), language);
}

uint ConfigFile::lastSelectedAccount() const
{
QSettings settings(configFile(), QSettings::IniFormat);
return settings.value(QLatin1String(lastSelectedAccountC), QLatin1String("")).toUInt();
}

void ConfigFile::setLastSelectedAccount(const uint accountId)
{
QSettings settings(configFile(), QSettings::IniFormat);
settings.setValue(QLatin1String(lastSelectedAccountC), accountId);
}

Q_GLOBAL_STATIC(QString, g_configFileName)

Check warning on line 1245 in src/libsync/configfile.cpp

View workflow job for this annotation

GitHub Actions / build

src/libsync/configfile.cpp:1245:1 [modernize-use-trailing-return-type]

use a trailing return type for this function

std::unique_ptr<QSettings> ConfigFile::settingsWithGroup(const QString &group, QObject *parent)
{
Expand Down
4 changes: 4 additions & 0 deletions src/libsync/configfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#ifndef CONFIGFILE_H
#define CONFIGFILE_H

#include "owncloudlib.h"

Check failure on line 10 in src/libsync/configfile.h

View workflow job for this annotation

GitHub Actions / build

src/libsync/configfile.h:10:10 [clang-diagnostic-error]

'owncloudlib.h' file not found
#include <memory>
#include <QSharedPointer>
#include <QSettings>
Expand Down Expand Up @@ -242,6 +242,10 @@
[[nodiscard]] QString language() const;
void setLanguage(const QString &language);

/// Store and retrieve the last selected account identifier
[[nodiscard]] uint lastSelectedAccount() const;
void setLastSelectedAccount(const uint accountId);

/** Returns a new settings pre-set in a specific group. The Settings will be created
with the given parent. If no parent is specified, the caller must destroy the settings */
static std::unique_ptr<QSettings> settingsWithGroup(const QString &group, QObject *parent = nullptr);
Expand Down
Loading