Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/owncloud/client.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJocelyn Turcotte <jturcotte@woboq.com>2016-03-16 21:07:40 +0300
committerJocelyn Turcotte <jturcotte@woboq.com>2016-03-28 14:07:28 +0300
commitdf386b64ba88c70f13cae2514e3dacda8540fb6a (patch)
treec0d25bbdf8d1a4dc658bf4c38c47d2e46904d6fa /src
parent80bd86a305f594c3846822c780f28edd3c860ba2 (diff)
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.
Diffstat (limited to 'src')
-rw-r--r--src/gui/accountmanager.h2
-rw-r--r--src/gui/accountstate.h6
-rw-r--r--src/gui/folder.cpp56
-rw-r--r--src/gui/folder.h7
-rw-r--r--src/gui/folderman.cpp16
-rw-r--r--src/gui/folderman.h2
-rw-r--r--src/gui/owncloudgui.cpp2
-rw-r--r--src/gui/owncloudgui.h1
-rw-r--r--src/gui/selectivesyncdialog.cpp13
-rw-r--r--src/libsync/accountfwd.h2
-rw-r--r--src/libsync/excludedfiles.cpp22
-rw-r--r--src/libsync/excludedfiles.h12
12 files changed, 44 insertions, 97 deletions
diff --git a/src/gui/accountmanager.h b/src/gui/accountmanager.h
index 321a6ec38..c500ef51e 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 d06262a56..6ba0add89 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 5935aad9c..d94552b39 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 cb13e8d8c..8a7976ac7 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 85bb94a47..4215ae0c5 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 c8fe41374..59b467acf 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 d5005cc9c..944b8ac40 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 9405fa577..74f658ba2 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 a6a80bd47..62461740c 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 28109f817..828199833 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 4f84fc0b5..3724c4880 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 da23c1bf0..3a71108b5 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: