mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-30 07:48:31 +03:00
Account: Generate shorter account ids.
This commit is contained in:
parent
f184d66ea2
commit
a13a974e2d
3 changed files with 30 additions and 2 deletions
|
@ -192,6 +192,12 @@ AccountPtr AccountManager::load(const QScopedPointer<QSettings>& settings)
|
|||
|
||||
void AccountManager::addAccount(const AccountPtr& newAccount)
|
||||
{
|
||||
auto id = newAccount->id();
|
||||
if (id.isEmpty() || !isAccountIdAvailable(id)) {
|
||||
id = generateFreeAccountId();
|
||||
}
|
||||
newAccount->_id = id;
|
||||
|
||||
AccountStatePtr newAccountState(new AccountState(newAccount));
|
||||
_accounts << newAccountState;
|
||||
emit accountAdded(newAccountState.data());
|
||||
|
@ -206,5 +212,26 @@ void AccountManager::shutdown()
|
|||
}
|
||||
}
|
||||
|
||||
bool AccountManager::isAccountIdAvailable(const QString& id) const
|
||||
{
|
||||
foreach (const auto& acc, _accounts) {
|
||||
if (acc->account()->id() == id) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
QString AccountManager::generateFreeAccountId() const
|
||||
{
|
||||
int i = 0;
|
||||
forever {
|
||||
QString id = QString::number(i);
|
||||
if (isAccountIdAvailable(id)) {
|
||||
return id;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -55,6 +55,9 @@ private:
|
|||
AccountPtr load(const QScopedPointer<QSettings>& settings);
|
||||
bool restoreFromLegacySettings();
|
||||
|
||||
bool isAccountIdAvailable(const QString& id) const;
|
||||
QString generateFreeAccountId() const;
|
||||
|
||||
|
||||
Q_SIGNALS:
|
||||
void accountAdded(AccountState *account);
|
||||
|
|
|
@ -32,7 +32,6 @@
|
|||
#include <QDir>
|
||||
#include <QDebug>
|
||||
#include <QSslKey>
|
||||
#include <QUuid>
|
||||
|
||||
namespace OCC {
|
||||
|
||||
|
@ -46,7 +45,6 @@ Account::Account(QObject *parent)
|
|||
, _wasMigrated(false)
|
||||
{
|
||||
qRegisterMetaType<AccountPtr>("AccountPtr");
|
||||
_id = QUuid::createUuid().toString();
|
||||
}
|
||||
|
||||
AccountPtr Account::create()
|
||||
|
|
Loading…
Reference in a new issue