[Pkg-owncloud-commits] [owncloud-client] 49/498: Account: Generate shorter account ids.
Sandro Knauß
hefee-guest at moszumanska.debian.org
Tue Aug 11 14:48:33 UTC 2015
This is an automated email from the git hooks/post-receive script.
hefee-guest pushed a commit to branch master
in repository owncloud-client.
commit a13a974e2d9c791168e261cc3e68d12410d475bf
Author: Christian Kamm <kamm at incasoftware.de>
Date: Fri Apr 24 07:02:51 2015 +0200
Account: Generate shorter account ids.
---
src/gui/accountmanager.cpp | 27 +++++++++++++++++++++++++++
src/gui/accountmanager.h | 3 +++
src/libsync/account.cpp | 2 --
3 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/src/gui/accountmanager.cpp b/src/gui/accountmanager.cpp
index b72af54..3be3c2c 100644
--- a/src/gui/accountmanager.cpp
+++ b/src/gui/accountmanager.cpp
@@ -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;
+ }
+}
}
diff --git a/src/gui/accountmanager.h b/src/gui/accountmanager.h
index 65a9ccc..228e54c 100644
--- a/src/gui/accountmanager.h
+++ b/src/gui/accountmanager.h
@@ -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);
diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp
index d0a4d22..3c1bcff 100644
--- a/src/libsync/account.cpp
+++ b/src/libsync/account.cpp
@@ -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()
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git
More information about the Pkg-owncloud-commits
mailing list