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"
|
|
|
|
#include "syncfilestatus.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
|
|
|
|
2013-07-22 22:27:42 +04:00
|
|
|
#include <QDir>
|
|
|
|
#include <QHash>
|
2014-10-13 19:23:42 +04:00
|
|
|
#include <QSet>
|
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-07-22 22:27:42 +04:00
|
|
|
#include <QDebug>
|
2013-08-05 19:01:08 +04:00
|
|
|
#include <QTimer>
|
2013-08-08 16:30:45 +04:00
|
|
|
#include <qelapsedtimer.h>
|
2011-04-08 13:36:53 +04: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;
|
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;
|
|
|
|
/// 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);
|
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:
|
2015-06-17 15:53:58 +03:00
|
|
|
Folder(const FolderDefinition& definition, 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.
|
|
|
|
*/
|
2015-06-17 15:53:58 +03:00
|
|
|
void setAccountState( AccountState *account );
|
2014-12-18 14:09:48 +03:00
|
|
|
AccountState* accountState() const;
|
|
|
|
|
2011-04-06 11:52:02 +04:00
|
|
|
/**
|
|
|
|
* alias or nickname
|
|
|
|
*/
|
|
|
|
QString alias() const;
|
2015-08-11 16:12:43 +03:00
|
|
|
QString aliasGui() 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
|
|
|
/**
|
|
|
|
* short path to display on the GUI (native separators)
|
|
|
|
*/
|
|
|
|
QString shortGuiPath() const;
|
|
|
|
|
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
|
|
|
|
*/
|
2015-05-05 18:34:01 +03:00
|
|
|
QString cleanPath();
|
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
|
|
|
|
* If the sync is switched off, the startSync method is not going to
|
|
|
|
* be called.
|
|
|
|
*/
|
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.
|
|
|
|
*
|
|
|
|
* !syncPaused() && accountState->isConnected().
|
|
|
|
*/
|
|
|
|
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; }
|
|
|
|
|
2014-10-13 19:23:42 +04:00
|
|
|
bool estimateState(QString fn, csync_ftw_type_e t, SyncFileStatus* s);
|
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; }
|
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;
|
|
|
|
|
2013-02-09 17:03:05 +04:00
|
|
|
signals:
|
|
|
|
void syncStateChange();
|
|
|
|
void syncStarted();
|
|
|
|
void syncFinished(const SyncResult &result);
|
2015-04-28 16:13:39 +03:00
|
|
|
void scheduleToSync(Folder*);
|
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
|
2013-02-09 17:03:05 +04:00
|
|
|
|
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
|
|
|
|
2013-07-22 22:27:42 +04:00
|
|
|
void slotAboutToRemoveAllFiles(SyncFileItem::Direction, 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();
|
2014-03-17 14:47:23 +04:00
|
|
|
void slotSyncFinished();
|
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);
|
2015-08-11 14:45:02 +03:00
|
|
|
void slotItemCompleted(const SyncFileItem&, const PropagatorJob&);
|
2014-08-27 21:05:26 +04:00
|
|
|
void slotSyncItemDiscovered(const SyncFileItem & item);
|
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
|
|
|
|
2015-02-16 18:31:49 +03:00
|
|
|
void slotAboutToPropagate(SyncFileItemVector& );
|
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();
|
|
|
|
|
2014-10-13 19:23:42 +04:00
|
|
|
void watcherSlot(QString);
|
2015-07-27 10:54:20 +03:00
|
|
|
void slotNewBigFolderDiscovered(const QString &);
|
2014-10-13 19:23:42 +04:00
|
|
|
|
2013-11-08 19:21:59 +04:00
|
|
|
private:
|
2013-07-22 22:27:42 +04:00
|
|
|
bool init();
|
|
|
|
|
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
|
|
|
|
2014-03-11 13:55:20 +04:00
|
|
|
void createGuiLog(const QString& filename, SyncFileStatus status, int count,
|
|
|
|
const QString& renameTarget = QString::null );
|
2013-11-08 19:21:59 +04:00
|
|
|
|
2014-12-18 14:09:48 +03:00
|
|
|
AccountState* _accountState;
|
2015-04-24 11:18:33 +03:00
|
|
|
FolderDefinition _definition;
|
|
|
|
|
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;
|
2014-10-08 12:41:03 +04:00
|
|
|
bool _forceSyncOnPollTimeout;
|
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;
|
|
|
|
|
2014-10-13 19:23:42 +04:00
|
|
|
// For the SocketAPI folder states
|
|
|
|
QSet<QString> _stateLastSyncItemsWithErrorNew; // gets moved to _stateLastSyncItemsWithError at end of sync
|
|
|
|
QSet<QString> _stateLastSyncItemsWithError;
|
|
|
|
QSet<QString> _stateTaintedFolders;
|
2013-07-22 22:27:42 +04:00
|
|
|
|
2013-10-03 17:28:56 +04:00
|
|
|
SyncJournalDb _journal;
|
|
|
|
|
2014-01-16 15:07:58 +04:00
|
|
|
ClientProxy _clientProxy;
|
|
|
|
|
2013-07-22 22:27:42 +04:00
|
|
|
CSYNC *_csync_ctx;
|
2011-02-17 02:21:45 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|