[Pkg-owncloud-commits] [owncloud-client] 159/498: Move Account::settings to AccountState::settings
Sandro Knauß
hefee-guest at moszumanska.debian.org
Tue Aug 11 14:48:46 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 6e337ad24235376a725d0b5add5d2fbe4bb17969
Author: Olivier Goffart <ogoffart at woboq.com>
Date: Mon Jun 15 15:04:39 2015 +0200
Move Account::settings to AccountState::settings
It is only used by the GUI. Also return a unique_ptr to make the ownership clearer
---
src/gui/accountmanager.cpp | 8 ++++----
src/gui/accountstate.cpp | 8 ++++++++
src/gui/accountstate.h | 7 +++++++
src/gui/folder.cpp | 4 ++--
src/gui/folderman.cpp | 2 +-
src/libsync/account.cpp | 11 ++---------
src/libsync/account.h | 6 ++----
src/libsync/creds/httpcredentials.cpp | 13 ++++++-------
src/libsync/creds/shibbolethcredentials.cpp | 10 +++++-----
9 files changed, 37 insertions(+), 32 deletions(-)
diff --git a/src/gui/accountmanager.cpp b/src/gui/accountmanager.cpp
index 33718af..d5a47d7 100644
--- a/src/gui/accountmanager.cpp
+++ b/src/gui/accountmanager.cpp
@@ -41,7 +41,7 @@ AccountManager *AccountManager::instance()
bool AccountManager::restore()
{
- QScopedPointer<QSettings> settings(Account::settingsWithGroup(QLatin1String(accountsC)));
+ auto settings = Account::settingsWithGroup(QLatin1String(accountsC));
// If there are no accounts, check the old format.
if (settings->childGroups().isEmpty()) {
@@ -63,7 +63,7 @@ bool AccountManager::restore()
bool AccountManager::restoreFromLegacySettings()
{
// try to open the correctly themed settings
- QScopedPointer<QSettings> settings(Account::settingsWithGroup(Theme::instance()->appName()));
+ auto settings = Account::settingsWithGroup(Theme::instance()->appName());
bool migratedCreds = false;
@@ -120,7 +120,7 @@ bool AccountManager::restoreFromLegacySettings()
void AccountManager::save()
{
- QScopedPointer<QSettings> settings(Account::settingsWithGroup(QLatin1String(accountsC)));
+ auto settings = Account::settingsWithGroup(QLatin1String(accountsC));
foreach (const auto &acc, _accounts) {
settings->beginGroup(acc->account()->id());
save(acc->account(), *settings);
@@ -213,7 +213,7 @@ void AccountManager::deleteAccount(AccountState* account)
auto copy = *it; // keep a reference to the shared pointer so it does not delete it just yet
_accounts.erase(it);
- QScopedPointer<QSettings> settings(Account::settingsWithGroup(QLatin1String(accountsC)));
+ auto settings = Account::settingsWithGroup(QLatin1String(accountsC));
settings->remove(account->account()->id());
accountRemoved(account);
diff --git a/src/gui/accountstate.cpp b/src/gui/accountstate.cpp
index b84a442..e95ec9b 100644
--- a/src/gui/accountstate.cpp
+++ b/src/gui/accountstate.cpp
@@ -18,6 +18,7 @@
#include "creds/abstractcredentials.h"
#include <QDebug>
+#include <QSettings>
namespace OCC {
@@ -250,5 +251,12 @@ void AccountState::slotCredentialsFetched(AbstractCredentials* credentials)
checkConnectivity();
}
+std::unique_ptr<QSettings> AccountState::settings()
+{
+ auto s = _account->settingsWithGroup(QLatin1String("Accounts"));
+ s->beginGroup(_account->id());
+ return s;
+}
+
} // namespace OCC
diff --git a/src/gui/accountstate.h b/src/gui/accountstate.h
index edf2ffb..a2c3c60 100644
--- a/src/gui/accountstate.h
+++ b/src/gui/accountstate.h
@@ -19,7 +19,9 @@
#include <QPointer>
#include "utility.h"
#include "connectionvalidator.h"
+#include <memory>
+class QSettings;
namespace OCC {
@@ -86,6 +88,11 @@ public:
/// connection status and errors.
void checkConnectivity();
+ /** Returns a new settings object for this account, already in the right groups. */
+ std::unique_ptr<QSettings> settings();
+
+
+
private:
void setState(State state);
diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp
index f51bfbb..5584fe1 100644
--- a/src/gui/folder.cpp
+++ b/src/gui/folder.cpp
@@ -634,14 +634,14 @@ bool Folder::estimateState(QString fn, csync_ftw_type_e t, SyncFileStatus* s)
void Folder::saveToSettings() const
{
- QScopedPointer<QSettings> settings(_accountState->account()->settings());
+ auto settings = _accountState->settings();
settings->beginGroup(QLatin1String("Folders"));
FolderDefinition::save(*settings, _definition);
}
void Folder::removeFromSettings() const
{
- QScopedPointer<QSettings> settings(_accountState->account()->settings());
+ auto settings = _accountState->settings();
settings->beginGroup(QLatin1String("Folders"));
settings->remove(_definition.alias);
}
diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp
index e25d61c..c488753 100644
--- a/src/gui/folderman.cpp
+++ b/src/gui/folderman.cpp
@@ -184,7 +184,7 @@ int FolderMan::setupFolders()
{
unloadAndDeleteAllFolders();
- QScopedPointer<QSettings> settings(Account::settingsWithGroup(QLatin1String("Accounts")));
+ auto settings = Account::settingsWithGroup(QLatin1String("Accounts"));
const auto accountsWithSettings = settings->childGroups();
if (accountsWithSettings.isEmpty()) {
return setupFoldersMigration();
diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp
index c565ba0..c116a3e 100644
--- a/src/libsync/account.cpp
+++ b/src/libsync/account.cpp
@@ -326,25 +326,18 @@ QUrl Account::concatUrlPath(const QUrl &url, const QString &concatPath,
QString Account::_configFileName;
-QSettings *Account::settingsWithGroup(const QString& group, QObject *parent)
+std::unique_ptr<QSettings> Account::settingsWithGroup(const QString& group, QObject *parent)
{
if (_configFileName.isEmpty()) {
// cache file name
ConfigFile cfg;
_configFileName = cfg.configFile();
}
- QSettings *settings = new QSettings(_configFileName, QSettings::IniFormat, parent);
+ std::unique_ptr<QSettings> settings(new QSettings(_configFileName, QSettings::IniFormat, parent));
settings->beginGroup(group);
return settings;
}
-QSettings* Account::settings()
-{
- auto s = settingsWithGroup(QLatin1String("Accounts"));
- s->beginGroup(id());
- return s;
-}
-
QVariant Account::credentialSetting(const QString &key) const
{
if (_credentials) {
diff --git a/src/libsync/account.h b/src/libsync/account.h
index 0c47d47..52e05cb 100644
--- a/src/libsync/account.h
+++ b/src/libsync/account.h
@@ -25,6 +25,7 @@
#include <QSslError>
#include <QSharedPointer>
#include "utility.h"
+#include <memory>
class QSettings;
class QNetworkReply;
@@ -124,10 +125,7 @@ public:
/** Returns a new settings pre-set in a specific group. The Settings will be created
with the given parent. If no parents is specified, the caller must destroy the settings */
- static QSettings* settingsWithGroup(const QString &group, QObject *parent = 0);
-
- /** Returns a new settings object for this account, already in the right groups. */
- QSettings* settings();
+ static std::unique_ptr<QSettings> settingsWithGroup(const QString& group, QObject* parent = 0);
// to be called by credentials only
QVariant credentialSetting(const QString& key) const;
diff --git a/src/libsync/creds/httpcredentials.cpp b/src/libsync/creds/httpcredentials.cpp
index bf88b69..2cd0f85 100644
--- a/src/libsync/creds/httpcredentials.cpp
+++ b/src/libsync/creds/httpcredentials.cpp
@@ -211,7 +211,7 @@ void HttpCredentials::fetch()
_certificatePath = _account->credentialSetting(QLatin1String(certifPathC)).toString();
_certificatePasswd = _account->credentialSetting(QLatin1String(certifPasswdC)).toString();
- QSettings *settings = _account->settingsWithGroup(Theme::instance()->appName());
+ auto settings = _account->settingsWithGroup(Theme::instance()->appName());
const QString kck = keychainKey(_account->url().toString(), _user );
QString key = QString::fromLatin1( "%1/data" ).arg( kck );
@@ -225,12 +225,11 @@ void HttpCredentials::fetch()
}
if (_ready) {
- settings->deleteLater();
Q_EMIT fetched();
} else {
ReadPasswordJob *job = new ReadPasswordJob(Theme::instance()->appName());
settings->setParent(job); // make the job parent to make setting deleted properly
- job->setSettings(settings);
+ job->setSettings(settings.release());
job->setInsecureFallback(false);
job->setKey(kck);
@@ -319,9 +318,9 @@ void HttpCredentials::invalidateToken()
}
DeletePasswordJob *job = new DeletePasswordJob(Theme::instance()->appName());
- QSettings *settings = _account->settingsWithGroup(Theme::instance()->appName());
+ auto settings = _account->settingsWithGroup(Theme::instance()->appName());
settings->setParent(job); // make the job parent to make setting deleted properly
- job->setSettings(settings);
+ job->setSettings(settings.release());
job->setInsecureFallback(true);
job->setKey(kck);
job->start();
@@ -347,9 +346,9 @@ void HttpCredentials::persist()
_account->setCredentialSetting(QLatin1String(certifPathC), _certificatePath);
_account->setCredentialSetting(QLatin1String(certifPasswdC), _certificatePasswd);
WritePasswordJob *job = new WritePasswordJob(Theme::instance()->appName());
- QSettings *settings = _account->settingsWithGroup(Theme::instance()->appName());
+ auto settings = _account->settingsWithGroup(Theme::instance()->appName());
settings->setParent(job); // make the job parent to make setting deleted properly
- job->setSettings(settings);
+ job->setSettings(settings.release());
job->setInsecureFallback(false);
connect(job, SIGNAL(finished(QKeychain::Job*)), SLOT(slotWriteJobDone(QKeychain::Job*)));
diff --git a/src/libsync/creds/shibbolethcredentials.cpp b/src/libsync/creds/shibbolethcredentials.cpp
index f1b97b9..9a98111 100644
--- a/src/libsync/creds/shibbolethcredentials.cpp
+++ b/src/libsync/creds/shibbolethcredentials.cpp
@@ -206,7 +206,7 @@ void ShibbolethCredentials::fetch()
} else {
_url = _account->url();
ReadPasswordJob *job = new ReadPasswordJob(Theme::instance()->appName());
- job->setSettings(_account->settingsWithGroup(Theme::instance()->appName(), job));
+ job->setSettings(_account->settingsWithGroup(Theme::instance()->appName(), job).release());
job->setInsecureFallback(false);
job->setKey(keychainKey(_account->url().toString(), "shibAssertion"));
connect(job, SIGNAL(finished(QKeychain::Job*)), SLOT(slotReadJobDone(QKeychain::Job*)));
@@ -315,7 +315,7 @@ void ShibbolethCredentials::invalidateAndFetch()
// delete the credentials, then in the slot fetch them again (which will trigger browser)
DeletePasswordJob *job = new DeletePasswordJob(Theme::instance()->appName());
- job->setSettings(_account->settingsWithGroup(Theme::instance()->appName(), job));
+ job->setSettings(_account->settingsWithGroup(Theme::instance()->appName(), job).release());
connect(job, SIGNAL(finished(QKeychain::Job*)), SLOT(slotInvalidateAndFetchInvalidateDone(QKeychain::Job*)));
job->setKey(keychainKey(_account->url().toString(), "shibAssertion"));
job->start();
@@ -351,7 +351,7 @@ void ShibbolethCredentials::slotReadJobDone(QKeychain::Job *job)
addToCookieJar(_shibCookie);
}
// access
- job->setSettings(_account->settingsWithGroup(Theme::instance()->appName(), job));
+ job->setSettings(_account->settingsWithGroup(Theme::instance()->appName(), job).release());
_ready = true;
_stillValid = true;
@@ -412,7 +412,7 @@ QByteArray ShibbolethCredentials::shibCookieName()
void ShibbolethCredentials::storeShibCookie(const QNetworkCookie &cookie)
{
WritePasswordJob *job = new WritePasswordJob(Theme::instance()->appName());
- job->setSettings(_account->settingsWithGroup(Theme::instance()->appName(), job));
+ job->setSettings(_account->settingsWithGroup(Theme::instance()->appName(), job).release());
// we don't really care if it works...
//connect(job, SIGNAL(finished(QKeychain::Job*)), SLOT(slotWriteJobDone(QKeychain::Job*)));
job->setKey(keychainKey(_account->url().toString(), "shibAssertion"));
@@ -423,7 +423,7 @@ void ShibbolethCredentials::storeShibCookie(const QNetworkCookie &cookie)
void ShibbolethCredentials::removeShibCookie()
{
DeletePasswordJob *job = new DeletePasswordJob(Theme::instance()->appName());
- job->setSettings(_account->settingsWithGroup(Theme::instance()->appName(), job));
+ job->setSettings(_account->settingsWithGroup(Theme::instance()->appName(), job).release());
job->setKey(keychainKey(_account->url().toString(), "shibAssertion"));
job->start();
}
--
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