2011-04-06 13:48:02 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Duncan Mac-Vicar P. <duncan@kde.org>
|
2013-07-22 22:27:42 +04:00
|
|
|
* Copyright (C) by Daniel Molkentin <danimo@owncloud.com>
|
|
|
|
* Copyright (C) by Klaas Freitag <freitag@owncloud.com>
|
2011-04-06 13:48:02 +04:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
|
2011-02-17 02:21:45 +03:00
|
|
|
#ifndef MIRALL_FOLDER_H
|
|
|
|
#define MIRALL_FOLDER_H
|
|
|
|
|
2014-07-11 02:31:24 +04:00
|
|
|
#include "syncresult.h"
|
|
|
|
#include "progressdispatcher.h"
|
|
|
|
#include "syncjournaldb.h"
|
|
|
|
#include "clientproxy.h"
|
2014-12-10 15:01:36 +03:00
|
|
|
#include "networkjobs.h"
|
2014-01-16 15:07:58 +04:00
|
|
|
|
|
|
|
#include <csync.h>
|
2012-07-20 19:13:23 +04:00
|
|
|
|
2011-02-17 02:21:45 +03:00
|
|
|
#include <QObject>
|
2011-03-23 01:03:43 +03:00
|
|
|
#include <QStringList>
|
2011-02-17 02:21:45 +03:00
|
|
|
|
2013-08-05 15:34:36 +04:00
|
|
|
class QThread;
|
2015-04-24 11:18:33 +03:00
|
|
|
class QSettings;
|
2011-02-17 02:21:45 +03:00
|
|
|
|
2014-11-10 00:34:07 +03:00
|
|
|
namespace OCC {
|
2011-02-17 02:21:45 +03:00
|
|
|
|
2014-03-17 14:34:51 +04:00
|
|
|
class SyncEngine;
|
2014-12-18 14:09:48 +03:00
|
|
|
class AccountState;
|
2016-06-09 15:10:47 +03:00
|
|
|
class SyncRunFileLog;
|
2014-03-17 14:34:51 +04:00
|
|
|
|
2015-06-29 19:56:09 +03:00
|
|
|
/**
|
|
|
|
* @brief The FolderDefinition class
|
|
|
|
* @ingroup gui
|
2015-06-26 18:07:47 +03:00
|
|
|
*/
|
2015-04-24 11:18:33 +03:00
|
|
|
class FolderDefinition
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FolderDefinition()
|
2015-08-10 12:03:57 +03:00
|
|
|
: paused(false)
|
|
|
|
, ignoreHiddenFiles(true)
|
2015-04-24 11:18:33 +03:00
|
|
|
{}
|
|
|
|
|
|
|
|
/// The name of the folder in the ui and internally
|
|
|
|
QString alias;
|
|
|
|
/// path on local machine
|
|
|
|
QString localPath;
|
2016-11-23 12:40:17 +03:00
|
|
|
/// path to the journal, usually relative to localPath
|
|
|
|
QString journalPath;
|
2015-04-24 11:18:33 +03:00
|
|
|
/// path on remote
|
|
|
|
QString targetPath;
|
|
|
|
/// whether the folder is paused
|
|
|
|
bool paused;
|
2015-07-13 23:15:02 +03:00
|
|
|
/// whether the folder syncs hidden files
|
|
|
|
bool ignoreHiddenFiles;
|
2015-04-24 11:18:33 +03:00
|
|
|
|
|
|
|
/// Saves the folder definition, creating a new settings group.
|
|
|
|
static void save(QSettings& settings, const FolderDefinition& folder);
|
|
|
|
|
|
|
|
/// Reads a folder definition from a settings group with the name 'alias'.
|
|
|
|
static bool load(QSettings& settings, const QString& alias,
|
|
|
|
FolderDefinition* folder);
|
2015-09-17 13:14:35 +03:00
|
|
|
|
|
|
|
/// Ensure / as separator and trailing /.
|
|
|
|
static QString prepareLocalPath(const QString& path);
|
2016-11-23 12:40:17 +03:00
|
|
|
|
|
|
|
/// Ensure starting / and no ending /.
|
|
|
|
static QString prepareTargetPath(const QString& path);
|
|
|
|
|
|
|
|
/// journalPath relative to localPath.
|
|
|
|
QString absoluteJournalPath() const;
|
|
|
|
|
|
|
|
/// Returns the relative journal path that's appropriate for this folder and account.
|
|
|
|
QString defaultJournalPath(AccountPtr account);
|
2015-04-24 11:18:33 +03:00
|
|
|
};
|
|
|
|
|
2015-06-29 19:56:09 +03:00
|
|
|
/**
|
|
|
|
* @brief The Folder class
|
|
|
|
* @ingroup gui
|
2015-06-26 18:07:47 +03:00
|
|
|
*/
|
2014-07-11 00:58:58 +04:00
|
|
|
class Folder : public QObject
|
2011-02-17 02:21:45 +03:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
2013-09-06 19:19:56 +04:00
|
|
|
public:
|
2016-03-16 21:07:40 +03:00
|
|
|
Folder(const FolderDefinition& definition, AccountState* accountState, QObject* parent = 0L);
|
2013-07-22 22:27:42 +04:00
|
|
|
|
|
|
|
~Folder();
|
2011-02-17 02:21:45 +03:00
|
|
|
|
2015-06-29 16:49:47 +03:00
|
|
|
typedef QMap<QString, Folder*> Map;
|
|
|
|
typedef QMapIterator<QString, Folder*> MapIterator;
|
2011-10-11 16:23:32 +04:00
|
|
|
|
2014-12-18 14:09:48 +03:00
|
|
|
/**
|
|
|
|
* The account the folder is configured on.
|
|
|
|
*/
|
2016-03-16 21:07:40 +03:00
|
|
|
AccountState* accountState() const { return _accountState.data(); }
|
2014-12-18 14:09:48 +03:00
|
|
|
|
2011-04-06 11:52:02 +04:00
|
|
|
/**
|
|
|
|
* alias or nickname
|
|
|
|
*/
|
|
|
|
QString alias() const;
|
2016-04-26 17:38:03 +03:00
|
|
|
QString shortGuiRemotePathOrAppName() const; // since 2.0 we don't want to show aliases anymore, show the path instead
|
2011-04-06 11:52:02 +04:00
|
|
|
|
2015-08-17 12:39:45 +03:00
|
|
|
/**
|
2016-04-26 17:38:03 +03:00
|
|
|
* short local path to display on the GUI (native separators)
|
2015-08-17 12:39:45 +03:00
|
|
|
*/
|
2016-04-26 17:38:03 +03:00
|
|
|
QString shortGuiLocalPath() const;
|
2015-08-17 12:39:45 +03:00
|
|
|
|
2011-02-17 17:10:06 +03:00
|
|
|
/**
|
|
|
|
* local folder path
|
|
|
|
*/
|
|
|
|
QString path() const;
|
2013-10-21 23:42:52 +04:00
|
|
|
|
2015-05-03 14:34:23 +03:00
|
|
|
/**
|
|
|
|
* wrapper for QDir::cleanPath("Z:\\"), which returns "Z:\\", but we need "Z:" instead
|
|
|
|
*/
|
2016-11-22 17:30:12 +03:00
|
|
|
QString cleanPath() const;
|
2015-05-03 14:34:23 +03:00
|
|
|
|
2013-07-22 22:27:42 +04:00
|
|
|
/**
|
|
|
|
* remote folder path
|
|
|
|
*/
|
2013-10-21 23:42:52 +04:00
|
|
|
QString remotePath() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* remote folder path with server url
|
|
|
|
*/
|
|
|
|
QUrl remoteUrl() const;
|
2011-02-17 17:10:06 +03:00
|
|
|
|
2011-10-13 18:41:24 +04:00
|
|
|
/**
|
|
|
|
* switch sync on or off
|
|
|
|
*/
|
2015-07-01 12:39:57 +03:00
|
|
|
void setSyncPaused( bool );
|
2011-10-13 18:41:24 +04:00
|
|
|
|
2015-07-01 12:39:57 +03:00
|
|
|
bool syncPaused() const;
|
2011-10-13 18:41:24 +04:00
|
|
|
|
2015-07-01 12:39:57 +03:00
|
|
|
/**
|
|
|
|
* Returns true when the folder may sync.
|
|
|
|
*/
|
|
|
|
bool canSync() const;
|
|
|
|
|
|
|
|
void prepareToSync();
|
2014-01-11 23:35:16 +04:00
|
|
|
|
2011-03-27 04:26:41 +04:00
|
|
|
/**
|
|
|
|
* True if the folder is busy and can't initiate
|
|
|
|
* a synchronization
|
|
|
|
*/
|
2013-07-22 22:27:42 +04:00
|
|
|
virtual bool isBusy() const;
|
2011-09-27 10:15:30 +04:00
|
|
|
|
2011-10-13 18:41:24 +04:00
|
|
|
/**
|
|
|
|
* return the last sync result with error message and status
|
|
|
|
*/
|
2012-02-20 19:45:27 +04:00
|
|
|
SyncResult syncResult() const;
|
2012-02-19 00:21:58 +04:00
|
|
|
|
2012-11-22 15:29:50 +04:00
|
|
|
/**
|
|
|
|
* set the config file name.
|
|
|
|
*/
|
|
|
|
void setConfigFile( const QString& );
|
|
|
|
QString configFile();
|
|
|
|
|
2012-06-11 12:10:07 +04:00
|
|
|
/**
|
|
|
|
* This is called if the sync folder definition is removed. Do cleanups here.
|
|
|
|
*/
|
|
|
|
virtual void wipe();
|
|
|
|
|
2014-01-11 23:35:16 +04:00
|
|
|
void setSyncState(SyncResult::Status state);
|
|
|
|
|
2014-01-31 20:29:50 +04:00
|
|
|
void setDirtyNetworkLimits();
|
|
|
|
|
2015-07-14 17:56:55 +03:00
|
|
|
/**
|
|
|
|
* Ignore syncing of hidden files or not. This is defined in the
|
|
|
|
* folder definition
|
|
|
|
*/
|
|
|
|
bool ignoreHiddenFiles();
|
|
|
|
void setIgnoreHiddenFiles(bool ignore);
|
|
|
|
|
2014-06-19 16:08:30 +04:00
|
|
|
// Used by the Socket API
|
|
|
|
SyncJournalDb *journalDb() { return &_journal; }
|
2016-03-17 14:26:44 +03:00
|
|
|
SyncEngine &syncEngine() { return *_engine; }
|
2014-06-19 16:08:30 +04:00
|
|
|
|
2014-12-03 00:32:54 +03:00
|
|
|
RequestEtagJob *etagJob() { return _requestEtagJob; }
|
2015-01-16 12:52:26 +03:00
|
|
|
qint64 msecSinceLastSync() const { return _timeSinceLastSyncDone.elapsed(); }
|
|
|
|
qint64 msecLastSyncDuration() const { return _lastSyncDuration; }
|
2015-01-16 14:45:12 +03:00
|
|
|
int consecutiveFollowUpSyncs() const { return _consecutiveFollowUpSyncs; }
|
2016-10-18 17:04:25 +03:00
|
|
|
int consecutiveFailingSyncs() const { return _consecutiveFailingSyncs; }
|
2014-12-03 00:32:54 +03:00
|
|
|
|
2015-04-24 11:18:33 +03:00
|
|
|
/// Saves the folder data in the account's settings.
|
|
|
|
void saveToSettings() const;
|
|
|
|
/// Removes the folder from the account's settings.
|
|
|
|
void removeFromSettings() const;
|
|
|
|
|
2016-09-12 16:02:54 +03:00
|
|
|
/**
|
|
|
|
* Returns whether a file inside this folder should be excluded.
|
|
|
|
*/
|
|
|
|
bool isFileExcludedAbsolute(const QString& fullPath) const;
|
|
|
|
|
2015-10-13 13:53:38 +03:00
|
|
|
/**
|
|
|
|
* Returns whether a file inside this folder should be excluded.
|
|
|
|
*/
|
|
|
|
bool isFileExcludedRelative(const QString& relativePath) const;
|
2015-10-02 10:40:44 +03:00
|
|
|
|
2016-10-18 17:04:25 +03:00
|
|
|
/** Calls schedules this folder on the FolderMan after a short delay.
|
|
|
|
*
|
|
|
|
* This should be used in situations where a sync should be triggered
|
|
|
|
* because a local file was modified. Syncs don't upload files that were
|
|
|
|
* modified too recently, and this delay ensures the modification is
|
|
|
|
* far enough in the past.
|
|
|
|
*
|
|
|
|
* The delay doesn't reset with subsequent calls.
|
|
|
|
*/
|
|
|
|
void scheduleThisFolderSoon();
|
|
|
|
|
2016-11-23 12:40:17 +03:00
|
|
|
/**
|
|
|
|
* Migration: When this flag is true, this folder will save to
|
|
|
|
* the backwards-compatible 'Folders' section in the config file.
|
|
|
|
*/
|
|
|
|
void setSaveBackwardsCompatible(bool save);
|
|
|
|
|
2013-02-09 17:03:05 +04:00
|
|
|
signals:
|
|
|
|
void syncStateChange();
|
|
|
|
void syncStarted();
|
|
|
|
void syncFinished(const SyncResult &result);
|
2015-06-02 20:45:23 +03:00
|
|
|
void progressInfo(const ProgressInfo& progress);
|
2015-07-27 10:54:20 +03:00
|
|
|
void newBigFolderDiscovered(const QString &); // A new folder bigger than the threshold was discovered
|
2016-03-02 13:06:03 +03:00
|
|
|
void syncPausedChanged(Folder*, bool paused);
|
2016-04-28 23:43:53 +03:00
|
|
|
void canSyncChanged();
|
2013-02-09 17:03:05 +04:00
|
|
|
|
2016-04-14 16:15:08 +03:00
|
|
|
/**
|
|
|
|
* Fires for each change inside this folder that wasn't caused
|
|
|
|
* by sync activity.
|
|
|
|
*/
|
|
|
|
void watchedFileChangedExternally(const QString& path);
|
|
|
|
|
2011-11-04 14:41:49 +04:00
|
|
|
public slots:
|
2012-04-30 10:56:56 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* terminate the current sync run
|
|
|
|
*/
|
2014-05-13 15:39:00 +04:00
|
|
|
void slotTerminateSync();
|
2012-04-30 10:56:56 +04:00
|
|
|
|
2016-01-05 13:47:17 +03:00
|
|
|
// connected to the corresponding signals in the SyncEngine
|
2013-07-22 22:27:42 +04:00
|
|
|
void slotAboutToRemoveAllFiles(SyncFileItem::Direction, bool*);
|
2016-01-05 13:47:17 +03:00
|
|
|
void slotAboutToRestoreBackup(bool*);
|
2011-02-17 02:21:45 +03:00
|
|
|
|
2011-04-05 14:16:24 +04:00
|
|
|
|
2013-07-22 22:27:42 +04:00
|
|
|
/**
|
|
|
|
* Starts a sync operation
|
|
|
|
*
|
|
|
|
* If the list of changed files is known, it is passed.
|
|
|
|
*/
|
|
|
|
void startSync(const QStringList &pathList = QStringList());
|
|
|
|
|
2013-10-14 18:11:15 +04:00
|
|
|
void setProxyDirty(bool value);
|
|
|
|
bool proxyDirty();
|
|
|
|
|
2014-11-05 16:52:57 +03:00
|
|
|
int slotDiscardDownloadProgress();
|
|
|
|
int downloadInfoCount();
|
2015-01-16 12:17:19 +03:00
|
|
|
int slotWipeErrorBlacklist();
|
|
|
|
int errorBlackListEntryCount();
|
2013-12-03 17:02:44 +04:00
|
|
|
|
2014-11-07 13:41:21 +03:00
|
|
|
/**
|
|
|
|
* Triggered by the folder watcher when a file/dir in this folder
|
|
|
|
* changes. Needs to check whether this change should trigger a new
|
|
|
|
* sync run to be scheduled.
|
|
|
|
*/
|
|
|
|
void slotWatchedPathChanged(const QString& path);
|
|
|
|
|
2013-07-22 22:27:42 +04:00
|
|
|
private slots:
|
2014-03-17 14:47:23 +04:00
|
|
|
void slotSyncStarted();
|
|
|
|
void slotSyncError(const QString& );
|
2013-07-22 22:27:42 +04:00
|
|
|
void slotCsyncUnavailable();
|
2015-10-29 18:43:30 +03:00
|
|
|
void slotSyncFinished(bool);
|
2013-07-22 22:27:42 +04:00
|
|
|
|
2014-08-15 17:00:10 +04:00
|
|
|
void slotFolderDiscovered(bool local, QString folderName);
|
2015-01-30 15:36:20 +03:00
|
|
|
void slotTransmissionProgress(const ProgressInfo& pi);
|
2017-01-25 13:12:38 +03:00
|
|
|
void slotItemCompleted(const SyncFileItemPtr&);
|
2013-02-09 17:03:05 +04:00
|
|
|
|
2014-12-03 00:32:54 +03:00
|
|
|
void slotRunEtagJob();
|
2013-08-05 21:53:58 +04:00
|
|
|
void etagRetreived(const QString &);
|
2015-01-23 17:30:00 +03:00
|
|
|
void etagRetreivedFromSyncEngine(const QString &);
|
2013-02-09 17:03:05 +04:00
|
|
|
|
2014-10-13 19:23:42 +04:00
|
|
|
void slotThreadTreeWalkResult(const SyncFileItemVector& ); // after sync is done
|
2013-02-09 17:03:05 +04:00
|
|
|
|
2014-05-27 13:33:08 +04:00
|
|
|
void slotEmitFinishedDelayed();
|
|
|
|
|
2015-07-27 10:54:20 +03:00
|
|
|
void slotNewBigFolderDiscovered(const QString &);
|
2014-10-13 19:23:42 +04:00
|
|
|
|
2016-06-09 15:28:15 +03:00
|
|
|
void slotLogPropagationStart();
|
|
|
|
|
2016-10-18 17:04:25 +03:00
|
|
|
/** Adds this folder to the list of scheduled folders in the
|
|
|
|
* FolderMan.
|
|
|
|
*/
|
|
|
|
void slotScheduleThisFolder();
|
|
|
|
|
2013-11-08 19:21:59 +04:00
|
|
|
private:
|
2014-09-03 16:25:14 +04:00
|
|
|
bool setIgnoredFiles();
|
2014-01-16 15:07:58 +04:00
|
|
|
|
2013-08-14 18:55:43 +04:00
|
|
|
void bubbleUpSyncResult();
|
|
|
|
|
2013-07-22 22:27:42 +04:00
|
|
|
void checkLocalPath();
|
2012-10-30 15:42:17 +04:00
|
|
|
|
2016-03-24 20:20:49 +03:00
|
|
|
enum LogStatus {
|
|
|
|
LogStatusRemove,
|
|
|
|
LogStatusRename,
|
|
|
|
LogStatusMove,
|
|
|
|
LogStatusNew,
|
|
|
|
LogStatusError,
|
2016-04-05 17:37:54 +03:00
|
|
|
LogStatusConflict,
|
2016-03-24 20:20:49 +03:00
|
|
|
LogStatusUpdated
|
|
|
|
};
|
|
|
|
|
|
|
|
void createGuiLog(const QString& filename, LogStatus status, int count,
|
2014-03-11 13:55:20 +04:00
|
|
|
const QString& renameTarget = QString::null );
|
2013-11-08 19:21:59 +04:00
|
|
|
|
2016-03-16 21:07:40 +03:00
|
|
|
AccountStatePtr _accountState;
|
2015-04-24 11:18:33 +03:00
|
|
|
FolderDefinition _definition;
|
2016-09-12 16:17:21 +03:00
|
|
|
QString _canonicalLocalPath; // As returned with QFileInfo:canonicalFilePath. Always ends with "/"
|
2015-04-24 11:18:33 +03:00
|
|
|
|
2013-07-22 22:27:42 +04:00
|
|
|
SyncResult _syncResult;
|
2014-03-17 14:47:23 +04:00
|
|
|
QScopedPointer<SyncEngine> _engine;
|
2013-07-22 22:27:42 +04:00
|
|
|
QStringList _errors;
|
|
|
|
bool _csyncError;
|
|
|
|
bool _csyncUnavail;
|
|
|
|
bool _wipeDb;
|
2013-10-14 18:11:15 +04:00
|
|
|
bool _proxyDirty;
|
2014-12-03 00:32:54 +03:00
|
|
|
QPointer<RequestEtagJob> _requestEtagJob;
|
2013-08-05 21:53:58 +04:00
|
|
|
QString _lastEtag;
|
2015-01-16 12:52:26 +03:00
|
|
|
QElapsedTimer _timeSinceLastSyncDone;
|
|
|
|
QElapsedTimer _timeSinceLastSyncStart;
|
|
|
|
qint64 _lastSyncDuration;
|
2013-07-22 22:27:42 +04:00
|
|
|
|
2014-10-24 14:52:24 +04:00
|
|
|
/// The number of syncs that failed in a row.
|
|
|
|
/// Reset when a sync is successful.
|
2014-10-24 12:57:16 +04:00
|
|
|
int _consecutiveFailingSyncs;
|
2013-07-22 22:27:42 +04:00
|
|
|
|
2014-10-24 14:52:24 +04:00
|
|
|
/// The number of requested follow-up syncs.
|
|
|
|
/// Reset when no follow-up is requested.
|
|
|
|
int _consecutiveFollowUpSyncs;
|
|
|
|
|
2013-10-03 17:28:56 +04:00
|
|
|
SyncJournalDb _journal;
|
|
|
|
|
2014-01-16 15:07:58 +04:00
|
|
|
ClientProxy _clientProxy;
|
2016-06-09 15:10:47 +03:00
|
|
|
|
|
|
|
QScopedPointer<SyncRunFileLog> _fileLog;
|
2016-10-18 17:04:25 +03:00
|
|
|
|
|
|
|
QTimer _scheduleSelfTimer;
|
2016-11-23 12:40:17 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* When the same local path is synced to multiple accounts, only one
|
|
|
|
* of them can be stored in the settings in a way that's compatible
|
|
|
|
* with old clients that don't support it. This flag marks folders
|
|
|
|
* that shall be written in a backwards-compatible way, by being set
|
|
|
|
* on the *first* Folder instance that was configured for each local
|
|
|
|
* path.
|
|
|
|
*/
|
|
|
|
bool _saveBackwardsCompatible;
|
2011-02-17 02:21:45 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|