[Pkg-owncloud-commits] [owncloud-client] 177/498: Folder: Simplify Folder constructor: No need for AccountState.

Sandro Knauß hefee-guest at moszumanska.debian.org
Tue Aug 11 14:48:47 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 214bc6b29b30a4dc00529d4aac5dd5251b83fbf5
Author: Klaas Freitag <freitag at owncloud.com>
Date:   Wed Jun 17 14:53:58 2015 +0200

    Folder: Simplify Folder constructor: No need for AccountState.
    
    Do not pass AccountState in constructor of Folder, set with a
    new method called setAccountState after creation. Thus the
    parameter does not need to be passed through all over.
---
 src/gui/folder.cpp    | 18 +++++++++++++++---
 src/gui/folder.h      |  4 ++--
 src/gui/folderman.cpp | 51 ++++++++++++++++++++++++++++++---------------------
 src/gui/folderman.h   |  2 +-
 4 files changed, 48 insertions(+), 27 deletions(-)

diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp
index 5584fe1..6a4e9a9 100644
--- a/src/gui/folder.cpp
+++ b/src/gui/folder.cpp
@@ -54,11 +54,10 @@ static void csyncLogCatcher(int /*verbosity*/,
 }
 
 
-Folder::Folder(AccountState* accountState,
-               const FolderDefinition& definition,
+Folder::Folder(const FolderDefinition& definition,
                QObject* parent)
     : QObject(parent)
-      , _accountState(accountState)
+      , _accountState(0)
       , _definition(definition)
       , _csyncError(false)
       , _csyncUnavail(false)
@@ -107,6 +106,7 @@ bool Folder::init()
         csync_set_log_callback( csyncLogCatcher );
         csync_set_log_level( 11 );
 
+        Q_ASSERT( _accountState );
         _accountState->account()->credentials()->syncContextPreInit(_csync_ctx);
 
         if( csync_init( _csync_ctx ) < 0 ) {
@@ -135,6 +135,11 @@ Folder::~Folder()
     csync_destroy(_csync_ctx);
 }
 
+void Folder::setAccountState( AccountState *account )
+{
+    _accountState = account;
+}
+
 AccountState* Folder::accountState() const
 {
     return _accountState;
@@ -204,6 +209,7 @@ QString Folder::remotePath() const
 
 QUrl Folder::remoteUrl() const
 {
+    Q_ASSERT(_accountState);
     return Account::concatUrlPath(_accountState->account()->davUrl(), remotePath());
 }
 
@@ -254,6 +260,7 @@ void Folder::slotRunEtagJob()
 {
     qDebug() << "* Trying to check" << alias() << "for changes via ETag check. (time since last sync:" << (_timeSinceLastSyncDone.elapsed() / 1000) << "s)";
 
+    Q_ASSERT(_accountState );
 
     AccountPtr account = _accountState->account();
 
@@ -634,6 +641,7 @@ bool Folder::estimateState(QString fn, csync_ftw_type_e t, SyncFileStatus* s)
 
 void Folder::saveToSettings() const
 {
+    Q_ASSERT(_accountState);
     auto settings = _accountState->settings();
     settings->beginGroup(QLatin1String("Folders"));
     FolderDefinition::save(*settings, _definition);
@@ -641,6 +649,8 @@ void Folder::saveToSettings() const
 
 void Folder::removeFromSettings() const
 {
+    Q_ASSERT(_accountState);
+
     auto  settings = _accountState->settings();
     settings->beginGroup(QLatin1String("Folders"));
     settings->remove(_definition.alias);
@@ -750,6 +760,8 @@ bool Folder::proxyDirty()
 
 void Folder::startSync(const QStringList &pathList)
 {
+    Q_ASSERT(_accountState);
+
     Q_UNUSED(pathList)
     if (!_csync_ctx) {
         // no _csync_ctx yet,  initialize it.
diff --git a/src/gui/folder.h b/src/gui/folder.h
index 7bbc6cd..542c6e2 100644
--- a/src/gui/folder.h
+++ b/src/gui/folder.h
@@ -73,8 +73,7 @@ class Folder : public QObject
     Q_OBJECT
 
 public:
-    Folder(AccountState* accountState, const FolderDefinition& definition,
-           QObject* parent = 0L);
+    Folder(const FolderDefinition& definition, QObject* parent = 0L);
 
     ~Folder();
 
@@ -84,6 +83,7 @@ public:
     /**
      * The account the folder is configured on.
      */
+    void setAccountState( AccountState *account );
     AccountState* accountState() const;
 
     /**
diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp
index a793c04..428b315 100644
--- a/src/gui/folderman.cpp
+++ b/src/gui/folderman.cpp
@@ -203,8 +203,9 @@ int FolderMan::setupFolders()
         foreach (const auto& folderAlias, settings->childGroups()) {
             FolderDefinition folderDefinition;
             if (FolderDefinition::load(*settings, folderAlias, &folderDefinition)) {
-                Folder* f = addFolderInternal(account.data(), folderDefinition);
+                Folder* f = addFolderInternal(folderDefinition);
                 if (f) {
+                    f->setAccountState( account.data() );
                     slotScheduleSync(f);
                     emit folderSyncStateChange(f);
                 }
@@ -388,24 +389,30 @@ Folder* FolderMan::setupFolderFromOldConfigFile(const QString &file, AccountStat
     folderDefinition.alias = alias;
     folderDefinition.localPath = path;
     folderDefinition.targetPath = targetPath;
-    folder = new Folder( accountState, folderDefinition, this );
-    qDebug() << "Adding folder to Folder Map " << folder;
-    _folderMap[alias] = folder;
-    if (paused) {
-        folder->setSyncPaused(paused);
-        _disabledFolders.insert(folder);
-    }
+    folder = new Folder(folderDefinition, this );
+    if( folder ) {
+        folder->setAccountState(accountState);
+
+        qDebug() << "Adding folder to Folder Map " << folder;
+        _folderMap[alias] = folder;
+        if (paused) {
+            folder->setSyncPaused(paused);
+            _disabledFolders.insert(folder);
+        }
 
-    connect(folder, SIGNAL(scheduleToSync(Folder*)), SLOT(slotScheduleSync(Folder*)));
-    connect(folder, SIGNAL(syncStarted()), SLOT(slotFolderSyncStarted()));
-    connect(folder, SIGNAL(syncFinished(SyncResult)), SLOT(slotFolderSyncFinished(SyncResult)));
+        connect(folder, SIGNAL(scheduleToSync(Folder*)), SLOT(slotScheduleSync(Folder*)));
+        connect(folder, SIGNAL(syncStarted()), SLOT(slotFolderSyncStarted()));
+        connect(folder, SIGNAL(syncFinished(SyncResult)), SLOT(slotFolderSyncFinished(SyncResult)));
 
-    registerFolderMonitor(folder);
-    QStringList blackList = settings.value( QLatin1String("blackList")).toStringList();
-    if (!blackList.empty()) {
-        //migrate settings
-        folder->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, blackList);
-        settings.remove(QLatin1String("blackList"));
+        registerFolderMonitor(folder);
+        QStringList blackList = settings.value( QLatin1String("blackList")).toStringList();
+        if (!blackList.empty()) {
+            //migrate settings
+            folder->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, blackList);
+            settings.remove(QLatin1String("blackList"));
+        }
+
+        folder->saveToSettings();
     }
     return folder;
 }
@@ -710,14 +717,16 @@ Folder* FolderMan::addFolder(AccountState* accountState, const FolderDefinition&
         return 0;
     }
 
-    auto folder = addFolderInternal(accountState, folderDefinition);
-    folder->saveToSettings();
+    auto folder = addFolderInternal(folderDefinition);
+    if(folder) {
+        folder->setAccountState(accountState);
+    }
     return folder;
 }
 
-Folder* FolderMan::addFolderInternal(AccountState* accountState, const FolderDefinition& folderDefinition)
+Folder* FolderMan::addFolderInternal(const FolderDefinition& folderDefinition)
 {
-    auto folder = new Folder( accountState, folderDefinition, this );
+    auto folder = new Folder(folderDefinition, this );
 
     qDebug() << "Adding folder to Folder Map " << folder;
     _folderMap[folder->alias()] = folder;
diff --git a/src/gui/folderman.h b/src/gui/folderman.h
index e3bb5d5..6102bc7 100644
--- a/src/gui/folderman.h
+++ b/src/gui/folderman.h
@@ -138,7 +138,7 @@ private slots:
 private:
     /** Adds a folder for an account, does not add it to the account settings.
       */
-    Folder* addFolderInternal(AccountState* accountState, const FolderDefinition& folderDefinition);
+    Folder* addFolderInternal(const FolderDefinition& folderDefinition);
 
     /* unloads a folder object, does not delete it */
     void unloadFolder( Folder * );

-- 
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