[Pkg-owncloud-commits] [owncloud-client] 212/470: Make the AccountState a construction argument of the Folder

Sandro Knauß hefee-guest at moszumanska.debian.org
Thu May 12 16:25:04 UTC 2016


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 df386b64ba88c70f13cae2514e3dacda8540fb6a
Author: Jocelyn Turcotte <jturcotte at woboq.com>
Date:   Wed Mar 16 19:07:40 2016 +0100

    Make the AccountState a construction argument of the Folder
    
    This will help moving the SyncEngine construction in the constructor
    and allow moving functionalities from Folder to SyncEngine or its
    delegated objects.
---
 src/gui/accountmanager.h        |  2 --
 src/gui/accountstate.h          |  6 +++--
 src/gui/folder.cpp              | 56 ++++-------------------------------------
 src/gui/folder.h                |  7 +++---
 src/gui/folderman.cpp           | 16 +++++-------
 src/gui/folderman.h             |  2 +-
 src/gui/owncloudgui.cpp         |  2 +-
 src/gui/owncloudgui.h           |  1 -
 src/gui/selectivesyncdialog.cpp | 13 ++--------
 src/libsync/accountfwd.h        |  2 +-
 src/libsync/excludedfiles.cpp   | 22 +++++++++++-----
 src/libsync/excludedfiles.h     | 12 ++++-----
 test/testfolderman.h            |  6 +++--
 13 files changed, 48 insertions(+), 99 deletions(-)

diff --git a/src/gui/accountmanager.h b/src/gui/accountmanager.h
index 321a6ec..c500ef5 100644
--- a/src/gui/accountmanager.h
+++ b/src/gui/accountmanager.h
@@ -18,8 +18,6 @@
 
 namespace OCC {
 
-typedef QSharedPointer<AccountState> AccountStatePtr;
-
 /**
    @brief The AccountManager class
    @ingroup gui
diff --git a/src/gui/accountstate.h b/src/gui/accountstate.h
index d06262a..6ba0add 100644
--- a/src/gui/accountstate.h
+++ b/src/gui/accountstate.h
@@ -29,11 +29,13 @@ namespace OCC {
 class AccountState;
 class Account;
 
+typedef QExplicitlySharedDataPointer<AccountState> AccountStatePtr;
+
 /**
  * @brief Extra info about an ownCloud server account.
  * @ingroup gui
  */
-class AccountState : public QObject {
+class AccountState : public QObject, public QSharedData {
     Q_OBJECT
 public:
     enum State {
@@ -148,6 +150,6 @@ private:
 }
 
 Q_DECLARE_METATYPE(OCC::AccountState*)
-Q_DECLARE_METATYPE(QSharedPointer<OCC::AccountState>)
+Q_DECLARE_METATYPE(OCC::AccountStatePtr)
 
 #endif //ACCOUNTINFO_H
diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp
index 5935aad..d94552b 100644
--- a/src/gui/folder.cpp
+++ b/src/gui/folder.cpp
@@ -56,9 +56,10 @@ static void csyncLogCatcher(int /*verbosity*/,
 
 
 Folder::Folder(const FolderDefinition& definition,
+               AccountState* accountState,
                QObject* parent)
     : QObject(parent)
-      , _accountState(0)
+      , _accountState(accountState)
       , _definition(definition)
       , _csyncError(false)
       , _csyncUnavail(false)
@@ -94,16 +95,6 @@ Folder::~Folder()
     }
 }
 
-void Folder::setAccountState( AccountState *account )
-{
-    _accountState = account;
-}
-
-AccountState* Folder::accountState() const
-{
-    return _accountState;
-}
-
 void Folder::checkLocalPath()
 {
     const QFileInfo fi(_definition.localPath);
@@ -202,9 +193,6 @@ QString Folder::remotePath() const
 
 QUrl Folder::remoteUrl() const
 {
-    if (!_accountState) {
-        return QUrl("http://deleted-account");
-    }
     return Account::concatUrlPath(_accountState->account()->davUrl(), remotePath());
 }
 
@@ -256,11 +244,6 @@ void Folder::slotRunEtagJob()
 {
     qDebug() << "* Trying to check" << remoteUrl().toString() << "for changes via ETag check. (time since last sync:" << (_timeSinceLastSyncDone.elapsed() / 1000) << "s)";
 
-    if (!_accountState) {
-        qDebug() << "Can't run EtagJob, account is deleted";
-        return;
-    }
-
     AccountPtr account = _accountState->account();
 
     if (!_requestEtagJob.isNull()) {
@@ -328,9 +311,7 @@ void Folder::etagRetreived(const QString& etag)
         emit scheduleToSync(this);
     }
 
-    if( _accountState ) {
-        _accountState->tagLastSuccessfullETagRequest();
-    }
+    _accountState->tagLastSuccessfullETagRequest();
 }
 
 void Folder::etagRetreivedFromSyncEngine(const QString& etag)
@@ -665,11 +646,6 @@ bool Folder::estimateState(QString fn, csync_ftw_type_e t, SyncFileStatus* s)
 
 void Folder::saveToSettings() const
 {
-    if (!_accountState) {
-        qDebug() << "Can't save folder to settings, account is deleted";
-        return;
-    }
-
     auto settings = _accountState->settings();
     settings->beginGroup(QLatin1String("Folders"));
     FolderDefinition::save(*settings, _definition);
@@ -680,11 +656,6 @@ void Folder::saveToSettings() const
 
 void Folder::removeFromSettings() const
 {
-    if (!_accountState) {
-        qDebug() << "Can't remove folder from settings, account is deleted";
-        return;
-    }
-
     auto  settings = _accountState->settings();
     settings->beginGroup(QLatin1String("Folders"));
     settings->remove(_definition.alias);
@@ -692,24 +663,12 @@ void Folder::removeFromSettings() const
 
 bool Folder::isFileExcludedAbsolute(const QString& fullPath) const
 {
-    if (!fullPath.startsWith(path())) {
-        // Mark paths we're not responsible for as excluded...
-        return true;
-    }
-
-    QString myFullPath = fullPath;
-    if (myFullPath.endsWith(QLatin1Char('/'))) {
-        myFullPath.chop(1);
-    }
-
-    QString relativePath = myFullPath.mid(path().size());
-    auto excl = ExcludedFiles::instance().isExcluded(myFullPath, relativePath, _definition.ignoreHiddenFiles);
-    return excl != CSYNC_NOT_EXCLUDED;
+    return ExcludedFiles::instance().isExcluded(fullPath, path(), _definition.ignoreHiddenFiles);
 }
 
 bool Folder::isFileExcludedRelative(const QString& relativePath) const
 {
-    return isFileExcludedAbsolute(path() + relativePath);
+    return ExcludedFiles::instance().isExcluded(path() + relativePath, path(), _definition.ignoreHiddenFiles);
 }
 
 void Folder::watcherSlot(QString fn)
@@ -814,11 +773,6 @@ bool Folder::proxyDirty()
 
 void Folder::startSync(const QStringList &pathList)
 {
-    if (!_accountState) {
-        qDebug() << "Can't startSync, account is deleted";
-        return;
-    }
-
     Q_UNUSED(pathList)
     if (proxyDirty()) {
         setProxyDirty(false);
diff --git a/src/gui/folder.h b/src/gui/folder.h
index cb13e8d..8a7976a 100644
--- a/src/gui/folder.h
+++ b/src/gui/folder.h
@@ -87,7 +87,7 @@ class Folder : public QObject
     Q_OBJECT
 
 public:
-    Folder(const FolderDefinition& definition, QObject* parent = 0L);
+    Folder(const FolderDefinition& definition, AccountState* accountState, QObject* parent = 0L);
 
     ~Folder();
 
@@ -97,8 +97,7 @@ public:
     /**
      * The account the folder is configured on.
      */
-    void setAccountState( AccountState *account );
-    AccountState* accountState() const;
+    AccountState* accountState() const { return _accountState.data(); }
 
     /**
      * alias or nickname
@@ -281,7 +280,7 @@ private:
     void createGuiLog(const QString& filename, SyncFileStatus status, int count,
                        const QString& renameTarget = QString::null );
 
-    QPointer<AccountState> _accountState;
+    AccountStatePtr _accountState;
     FolderDefinition _definition;
 
     SyncResult _syncResult;
diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp
index 85bb94a..4215ae0 100644
--- a/src/gui/folderman.cpp
+++ b/src/gui/folderman.cpp
@@ -206,9 +206,8 @@ int FolderMan::setupFolders()
         foreach (const auto& folderAlias, settings->childGroups()) {
             FolderDefinition folderDefinition;
             if (FolderDefinition::load(*settings, folderAlias, &folderDefinition)) {
-                Folder* f = addFolderInternal(folderDefinition);
+                Folder* f = addFolderInternal(folderDefinition, account.data());
                 if (f) {
-                    f->setAccountState( account.data() );
                     slotScheduleSync(f);
                     emit folderSyncStateChange(f);
                 }
@@ -395,10 +394,8 @@ Folder* FolderMan::setupFolderFromOldConfigFile(const QString &file, AccountStat
     folderDefinition.paused = paused;
     folderDefinition.ignoreHiddenFiles = ignoreHiddenFiles();
 
-    folder = addFolderInternal(folderDefinition);
+    folder = addFolderInternal(folderDefinition, accountState);
     if (folder) {
-        folder->setAccountState(accountState);
-
         QStringList blackList = settings.value( QLatin1String("blackList")).toStringList();
         if (!blackList.empty()) {
             //migrate settings
@@ -786,9 +783,8 @@ Folder* FolderMan::addFolder(AccountState* accountState, const FolderDefinition&
         return 0;
     }
 
-    auto folder = addFolderInternal(folderDefinition);
-    if(folder && accountState) {
-        folder->setAccountState(accountState);
+    auto folder = addFolderInternal(folderDefinition, accountState);
+    if(folder) {
         folder->saveToSettings();
         emit folderSyncStateChange(folder);
         emit folderListChanged(_folderMap);
@@ -796,9 +792,9 @@ Folder* FolderMan::addFolder(AccountState* accountState, const FolderDefinition&
     return folder;
 }
 
-Folder* FolderMan::addFolderInternal(const FolderDefinition& folderDefinition)
+Folder* FolderMan::addFolderInternal(const FolderDefinition& folderDefinition, AccountState* accountState)
 {
-    auto folder = new Folder(folderDefinition, this );
+    auto folder = new Folder(folderDefinition, accountState, 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 c8fe413..59b467a 100644
--- a/src/gui/folderman.h
+++ b/src/gui/folderman.h
@@ -202,7 +202,7 @@ private:
     /** Adds a new folder, does not add it to the account settings and
      *  does not set an account on the new folder.
       */
-    Folder* addFolderInternal(const FolderDefinition& folderDefinition);
+    Folder* addFolderInternal(const FolderDefinition& folderDefinition, AccountState* accountState);
 
     /* unloads a folder object, does not delete it */
     void unloadFolder( Folder * );
diff --git a/src/gui/owncloudgui.cpp b/src/gui/owncloudgui.cpp
index d5005cc..944b8ac 100644
--- a/src/gui/owncloudgui.cpp
+++ b/src/gui/owncloudgui.cpp
@@ -350,7 +350,7 @@ void ownCloudGui::addAccountContextMenu(AccountStatePtr accountState, QMenu *men
     bool onePaused = false;
     bool allPaused = true;
     foreach (Folder* folder, folderMan->map()) {
-        if (folder->accountState() != accountState) {
+        if (folder->accountState() != accountState.data()) {
             continue;
         }
 
diff --git a/src/gui/owncloudgui.h b/src/gui/owncloudgui.h
index 9405fa5..74f658b 100644
--- a/src/gui/owncloudgui.h
+++ b/src/gui/owncloudgui.h
@@ -35,7 +35,6 @@ class ShareDialog;
 class Application;
 class LogBrowser;
 class AccountState;
-typedef QSharedPointer<AccountState> AccountStatePtr;
 
 /**
  * @brief The ownCloudGui class
diff --git a/src/gui/selectivesyncdialog.cpp b/src/gui/selectivesyncdialog.cpp
index a6a80bd..6246174 100644
--- a/src/gui/selectivesyncdialog.cpp
+++ b/src/gui/selectivesyncdialog.cpp
@@ -14,6 +14,7 @@
 #include "selectivesyncdialog.h"
 #include "folder.h"
 #include "account.h"
+#include "excludedfiles.h"
 #include "networkjobs.h"
 #include "theme.h"
 #include "folderman.h"
@@ -176,21 +177,11 @@ void SelectiveSyncTreeView::slotUpdateDirectories(QStringList list)
         pathToRemove.append('/');
 
     // Check for excludes.
-    //
-    // We would like to use Folder::isFileExcluded, but the folder doesn't
-    // exist yet. So we just create one temporarily...
-    FolderDefinition def;
-    def.localPath = pathToRemove;
-    def.ignoreHiddenFiles = FolderMan::instance()->ignoreHiddenFiles();
-    Folder f(def);
     QMutableListIterator<QString> it(list);
     while (it.hasNext()) {
         it.next();
-        QString path = it.value();
-        path.remove(pathToRemove);
-        if (f.isFileExcludedRelative(path)) {
+        if (ExcludedFiles::instance().isExcluded(it.value(), pathToRemove, FolderMan::instance()->ignoreHiddenFiles()))
             it.remove();
-        }
     }
 
     // Since / cannot be in the blacklist, expand it to the actual
diff --git a/src/libsync/accountfwd.h b/src/libsync/accountfwd.h
index 28109f8..8281998 100644
--- a/src/libsync/accountfwd.h
+++ b/src/libsync/accountfwd.h
@@ -21,7 +21,7 @@ namespace OCC {
 class Account;
 typedef QSharedPointer<Account> AccountPtr;
 class AccountState;
-typedef QSharedPointer<AccountState> AccountStatePtr;
+typedef QExplicitlySharedDataPointer<AccountState> AccountStatePtr;
 
 } // namespace OCC
 
diff --git a/src/libsync/excludedfiles.cpp b/src/libsync/excludedfiles.cpp
index 4f84fc0..3724c48 100644
--- a/src/libsync/excludedfiles.cpp
+++ b/src/libsync/excludedfiles.cpp
@@ -62,16 +62,20 @@ bool ExcludedFiles::reloadExcludes()
     return success;
 }
 
-CSYNC_EXCLUDE_TYPE ExcludedFiles::isExcluded(
-        const QString& fullPath,
-        const QString& relativePath,
+bool ExcludedFiles::isExcluded(
+        const QString& filePath,
+        const QString& basePath,
         bool excludeHidden) const
 {
-    QFileInfo fi(fullPath);
+    if (!filePath.startsWith(basePath)) {
+        // Mark paths we're not responsible for as excluded...
+        return true;
+    }
 
+    QFileInfo fi(filePath);
     if( excludeHidden ) {
         if( fi.isHidden() || fi.fileName().startsWith(QLatin1Char('.')) ) {
-            return CSYNC_FILE_EXCLUDE_HIDDEN;
+            return true;
         }
     }
 
@@ -79,6 +83,12 @@ CSYNC_EXCLUDE_TYPE ExcludedFiles::isExcluded(
     if (fi.isDir()) {
         type = CSYNC_FTW_TYPE_DIR;
     }
+
+    QString relativePath = filePath.mid(basePath.size());
+    if (relativePath.endsWith(QLatin1Char('/'))) {
+        relativePath.chop(1);
+    }
+
     QReadLocker lock(&_mutex);
-    return csync_excluded_no_ctx(*_excludesPtr, relativePath.toUtf8(), type);
+    return csync_excluded_no_ctx(*_excludesPtr, relativePath.toUtf8(), type) != CSYNC_NOT_EXCLUDED;
 }
diff --git a/src/libsync/excludedfiles.h b/src/libsync/excludedfiles.h
index da23c1b..3a71108 100644
--- a/src/libsync/excludedfiles.h
+++ b/src/libsync/excludedfiles.h
@@ -49,14 +49,12 @@ public:
     /**
      * Checks whether a file or directory should be excluded.
      *
-     * @param fullPath     the absolute path to the file
-     * @param relativePath path relative to the folder
-     *
-     * For directories, the paths must not contain a trailing /.
+     * @param filePath     the absolute path to the file
+     * @param basePath     folder path from which to apply exclude rules
      */
-    CSYNC_EXCLUDE_TYPE isExcluded(
-            const QString& fullPath,
-            const QString& relativePath,
+    bool isExcluded(
+            const QString& filePath,
+            const QString& basePath,
             bool excludeHidden) const;
 
 public slots:
diff --git a/test/testfolderman.h b/test/testfolderman.h
index c1273ba..35ba8ba 100644
--- a/test/testfolderman.h
+++ b/test/testfolderman.h
@@ -15,6 +15,7 @@
 
 #include "utility.h"
 #include "folderman.h"
+#include "account.h"
 #include "accountstate.h"
 
 using namespace OCC;
@@ -52,10 +53,11 @@ private slots:
             f.write("hello");
         }
 
+        AccountStatePtr newAccountState(new AccountState(Account::create()));
         FolderMan *folderman = FolderMan::instance();
         QCOMPARE(folderman, &_fm);
-        QVERIFY(folderman->addFolder(0, folderDefinition(dir.path() + "/sub/ownCloud1")));
-        QVERIFY(folderman->addFolder(0, folderDefinition(dir.path() + "/ownCloud2")));
+        QVERIFY(folderman->addFolder(newAccountState.data(), folderDefinition(dir.path() + "/sub/ownCloud1")));
+        QVERIFY(folderman->addFolder(newAccountState.data(), folderDefinition(dir.path() + "/ownCloud2")));
 
 
         // those should be allowed

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