2012-02-17 12:48:31 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Klaas Freitag <freitag@owncloud.com>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef FOLDERMAN_H
|
|
|
|
#define FOLDERMAN_H
|
|
|
|
|
|
|
|
#include <QObject>
|
2012-03-22 19:22:08 +04:00
|
|
|
#include <QQueue>
|
2013-07-22 14:10:13 +04:00
|
|
|
#include <QList>
|
2012-02-17 12:48:31 +04:00
|
|
|
|
2014-07-11 02:31:24 +04:00
|
|
|
#include "folder.h"
|
|
|
|
#include "folderwatcher.h"
|
|
|
|
#include "syncfileitem.h"
|
2012-02-17 12:48:31 +04:00
|
|
|
|
2012-02-19 00:21:58 +04:00
|
|
|
class QSignalMapper;
|
2015-07-13 15:35:19 +03:00
|
|
|
class TestFolderMan;
|
2012-02-19 00:21:58 +04:00
|
|
|
|
2014-11-10 00:34:07 +03:00
|
|
|
namespace OCC {
|
2013-07-22 14:10:13 +04:00
|
|
|
|
2014-05-26 16:34:08 +04:00
|
|
|
class Application;
|
2014-07-14 17:31:38 +04:00
|
|
|
class SyncResult;
|
|
|
|
class SocketApi;
|
2016-04-29 17:14:18 +03:00
|
|
|
class LockWatcher;
|
2014-05-26 16:34:08 +04:00
|
|
|
|
2015-06-29 19:56:09 +03:00
|
|
|
/**
|
|
|
|
* @brief The FolderMan class
|
|
|
|
* @ingroup gui
|
2015-06-26 18:07:47 +03:00
|
|
|
*/
|
2014-07-07 18:30:32 +04:00
|
|
|
class FolderMan : public QObject
|
2012-02-17 12:48:31 +04:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2015-01-08 18:52:23 +03:00
|
|
|
~FolderMan();
|
2013-07-22 15:59:52 +04:00
|
|
|
static FolderMan* instance();
|
2012-02-17 12:48:31 +04:00
|
|
|
|
|
|
|
int setupFolders();
|
2015-04-24 11:18:33 +03:00
|
|
|
int setupFoldersMigration();
|
2012-02-17 12:48:31 +04:00
|
|
|
|
2014-11-10 00:34:07 +03:00
|
|
|
OCC::Folder::Map map();
|
2012-02-17 12:48:31 +04:00
|
|
|
|
2015-04-24 11:18:33 +03:00
|
|
|
/** Adds a folder for an account, ensures the journal is gone and saves it in the settings.
|
2012-02-17 12:48:31 +04:00
|
|
|
*/
|
2015-04-24 11:18:33 +03:00
|
|
|
Folder* addFolder(AccountState* accountState, const FolderDefinition& folderDefinition);
|
2013-10-03 19:04:55 +04:00
|
|
|
|
|
|
|
/** Returns the folder which the file or directory stored in path is in */
|
2014-07-01 18:24:14 +04:00
|
|
|
Folder* folderForPath(const QString& path);
|
2012-02-17 12:48:31 +04:00
|
|
|
|
2015-11-16 17:04:59 +03:00
|
|
|
/**
|
|
|
|
* returns a list of local files that exist on the local harddisk for an
|
|
|
|
* incoming relative server path. The method checks with all existing sync
|
|
|
|
* folders.
|
|
|
|
*/
|
2015-11-24 16:24:18 +03:00
|
|
|
QStringList findFileInLocalFolders( const QString& relPath, const AccountPtr acc );
|
2015-11-16 17:04:59 +03:00
|
|
|
|
2013-07-24 16:16:52 +04:00
|
|
|
/** Returns the folder by alias or NULL if no folder with the alias exists. */
|
2012-02-21 14:50:19 +04:00
|
|
|
Folder *folder( const QString& );
|
|
|
|
|
2015-05-12 17:48:19 +03:00
|
|
|
/**
|
|
|
|
* Migrate accounts from owncloud < 2.0
|
|
|
|
* Creates a folder for a specific configuration, identified by alias.
|
|
|
|
*/
|
|
|
|
Folder* setupFolderFromOldConfigFile(const QString &, AccountState *account );
|
2012-04-02 15:21:13 +04:00
|
|
|
|
2013-06-06 19:59:50 +04:00
|
|
|
/**
|
|
|
|
* Ensures that a given directory does not contain a .csync_journal.
|
|
|
|
*
|
2013-07-24 16:16:52 +04:00
|
|
|
* @returns false if the journal could not be removed, true otherwise.
|
2013-06-06 19:59:50 +04:00
|
|
|
*/
|
|
|
|
static bool ensureJournalGone(const QString &path);
|
|
|
|
|
2013-07-24 16:16:52 +04:00
|
|
|
/** Creates a new and empty local directory. */
|
2013-05-26 15:56:51 +04:00
|
|
|
bool startFromScratch( const QString& );
|
|
|
|
|
2014-08-19 15:58:20 +04:00
|
|
|
QString statusToString(SyncResult, bool paused ) const;
|
2013-07-22 14:10:13 +04:00
|
|
|
|
|
|
|
static SyncResult accountStatus( const QList<Folder*> &folders );
|
|
|
|
|
2014-01-11 23:35:16 +04:00
|
|
|
void removeMonitorPath( const QString& alias, const QString& path );
|
|
|
|
void addMonitorPath( const QString& alias, const QString& path );
|
|
|
|
|
2014-08-11 17:09:17 +04:00
|
|
|
// Escaping of the alias which is used in QSettings AND the file
|
|
|
|
// system, thus need to be escaped.
|
|
|
|
static QString escapeAlias( const QString& );
|
2015-09-02 17:05:58 +03:00
|
|
|
static QString unescapeAlias( const QString& );
|
2014-08-11 17:09:17 +04:00
|
|
|
|
2014-09-03 18:12:21 +04:00
|
|
|
SocketApi *socketApi();
|
|
|
|
|
2015-07-13 15:35:19 +03:00
|
|
|
/**
|
|
|
|
* Check if @a path is a valid path for a new folder considering the already sync'ed items.
|
2015-10-05 07:21:19 +03:00
|
|
|
* Make sure that this folder, or any subfolder is not sync'ed already.
|
2015-07-13 15:35:19 +03:00
|
|
|
*
|
2015-07-28 13:14:52 +03:00
|
|
|
* \a forNewDirectory is internal and is used for recursion.
|
|
|
|
*
|
2015-07-13 15:35:19 +03:00
|
|
|
* @returns an empty string if it is allowed, or an error if it is not allowed
|
|
|
|
*/
|
2015-07-28 13:14:52 +03:00
|
|
|
QString checkPathValidityForNewFolder(const QString &path, bool forNewDirectory = false);
|
2015-07-13 15:35:19 +03:00
|
|
|
|
2015-08-10 12:03:57 +03:00
|
|
|
/**
|
|
|
|
* While ignoring hidden files can theoretically be switched per folder,
|
|
|
|
* it's currently a global setting that users can only change for all folders
|
|
|
|
* at once.
|
|
|
|
* These helper functions can be removed once it's properly per-folder.
|
|
|
|
*/
|
|
|
|
bool ignoreHiddenFiles() const;
|
|
|
|
void setIgnoreHiddenFiles(bool ignore);
|
|
|
|
|
2015-09-04 11:33:48 +03:00
|
|
|
/**
|
|
|
|
* Access to the current queue of scheduled folders.
|
|
|
|
*/
|
|
|
|
QQueue<Folder*> scheduleQueue() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Access to the currently syncing folder.
|
|
|
|
*/
|
|
|
|
Folder* currentSyncFolder() const;
|
|
|
|
|
2012-02-17 12:48:31 +04:00
|
|
|
signals:
|
2012-02-19 00:21:58 +04:00
|
|
|
/**
|
2015-04-28 16:13:39 +03:00
|
|
|
* signal to indicate a folder has changed its sync state.
|
2014-08-19 15:58:20 +04:00
|
|
|
*
|
2015-10-05 07:21:19 +03:00
|
|
|
* Attention: The folder may be zero. Do a general update of the state then.
|
2012-02-19 00:21:58 +04:00
|
|
|
*/
|
2015-04-28 16:13:39 +03:00
|
|
|
void folderSyncStateChange(Folder*);
|
2012-02-17 12:48:31 +04:00
|
|
|
|
2015-09-04 11:33:48 +03:00
|
|
|
/**
|
|
|
|
* Indicates when the schedule queue changes.
|
|
|
|
*/
|
|
|
|
void scheduleQueueChanged();
|
|
|
|
|
2015-12-08 16:37:37 +03:00
|
|
|
void folderListChanged(const Folder::Map &);
|
2014-03-26 22:30:13 +04:00
|
|
|
|
2012-02-17 12:48:31 +04:00
|
|
|
public slots:
|
2015-04-28 16:13:39 +03:00
|
|
|
void slotRemoveFolder( Folder* );
|
2016-03-02 13:06:03 +03:00
|
|
|
void slotFolderSyncPaused(Folder *, bool paused);
|
2016-04-28 23:43:53 +03:00
|
|
|
void slotFolderCanSyncChanged();
|
2012-02-17 12:48:31 +04:00
|
|
|
|
|
|
|
void slotFolderSyncStarted();
|
|
|
|
void slotFolderSyncFinished( const SyncResult& );
|
|
|
|
|
2014-09-04 12:12:54 +04:00
|
|
|
/**
|
2014-11-21 14:58:38 +03:00
|
|
|
* Terminates the current folder sync.
|
2014-09-04 12:12:54 +04:00
|
|
|
*
|
|
|
|
* It does not switch the folder to paused state.
|
|
|
|
*/
|
2014-11-21 14:58:38 +03:00
|
|
|
void terminateSyncProcess();
|
2012-04-30 10:56:56 +04:00
|
|
|
|
2013-06-03 19:26:48 +04:00
|
|
|
/* delete all folder objects */
|
2015-02-27 12:42:59 +03:00
|
|
|
int unloadAndDeleteAllFolders();
|
2013-06-03 19:26:48 +04:00
|
|
|
|
2013-02-10 14:01:24 +04:00
|
|
|
// if enabled is set to false, no new folders will start to sync.
|
|
|
|
// the current one will finish.
|
|
|
|
void setSyncEnabled( bool );
|
|
|
|
|
2013-02-19 20:24:10 +04:00
|
|
|
void slotScheduleAllFolders();
|
|
|
|
|
2013-10-14 18:11:15 +04:00
|
|
|
void setDirtyProxy(bool value = true);
|
2014-01-31 20:29:50 +04:00
|
|
|
void setDirtyNetworkLimits();
|
2013-08-27 12:02:59 +04:00
|
|
|
|
2012-03-22 19:22:08 +04:00
|
|
|
// slot to add a folder to the syncing queue
|
2015-04-28 16:13:39 +03:00
|
|
|
void slotScheduleSync(Folder*);
|
2015-10-05 07:21:19 +03:00
|
|
|
// slot to schedule an ETag job
|
2014-12-03 00:32:54 +03:00
|
|
|
void slotScheduleETagJob ( const QString &alias, RequestEtagJob *job);
|
|
|
|
void slotEtagJobDestroyed (QObject*);
|
|
|
|
void slotRunOneEtagJob();
|
2012-03-22 19:22:08 +04:00
|
|
|
|
2015-07-01 12:39:57 +03:00
|
|
|
/**
|
|
|
|
* Schedules folders of newly connected accounts, terminates and
|
|
|
|
* de-schedules folders of disconnected accounts.
|
|
|
|
*/
|
|
|
|
void slotAccountStateChanged();
|
|
|
|
|
2015-07-17 13:12:00 +03:00
|
|
|
/**
|
|
|
|
* restart the client as soon as it is possible, ie. no folders syncing.
|
|
|
|
*/
|
|
|
|
void slotScheduleAppRestart();
|
|
|
|
|
2016-04-29 17:14:18 +03:00
|
|
|
/**
|
|
|
|
* Triggers a sync run once the lock on the given file is removed.
|
|
|
|
*
|
|
|
|
* Automatically detemines the folder that's responsible for the file.
|
|
|
|
*/
|
|
|
|
void slotSyncOnceFileUnlocks(const QString& path);
|
|
|
|
|
2014-01-11 23:35:16 +04:00
|
|
|
private slots:
|
2012-03-22 19:22:08 +04:00
|
|
|
// slot to take the next folder from queue and start syncing.
|
2014-09-17 15:02:11 +04:00
|
|
|
void slotStartScheduledFolderSync();
|
2014-12-03 00:32:54 +03:00
|
|
|
void slotEtagPollTimerTimeout();
|
2015-04-24 11:18:33 +03:00
|
|
|
|
2014-12-18 14:09:48 +03:00
|
|
|
void slotRemoveFoldersForAccount(AccountState* accountState);
|
2012-03-22 19:22:08 +04:00
|
|
|
|
2015-06-17 16:55:48 +03:00
|
|
|
// Wraps the Folder::syncStateChange() signal into the
|
|
|
|
// FolderMan::folderSyncStateChange(Folder*) signal.
|
|
|
|
void slotForwardFolderSyncStateChange();
|
|
|
|
|
2016-03-02 13:59:36 +03:00
|
|
|
void slotServerVersionChanged(Account* account);
|
|
|
|
|
2016-04-29 17:14:18 +03:00
|
|
|
/**
|
|
|
|
* Schedules the folder for synchronization that contains
|
|
|
|
* the file with the given path.
|
|
|
|
*/
|
|
|
|
void slotScheduleFolderOwningFile(const QString& path);
|
|
|
|
|
2012-02-17 12:48:31 +04:00
|
|
|
private:
|
2015-06-17 16:55:48 +03:00
|
|
|
/** Adds a new folder, does not add it to the account settings and
|
|
|
|
* does not set an account on the new folder.
|
2015-04-24 11:18:33 +03:00
|
|
|
*/
|
2016-04-26 17:09:39 +03:00
|
|
|
Folder* addFolderInternal(FolderDefinition folderDefinition, AccountState* accountState);
|
2015-04-24 11:18:33 +03:00
|
|
|
|
2015-02-27 12:42:59 +03:00
|
|
|
/* unloads a folder object, does not delete it */
|
2015-04-28 16:13:39 +03:00
|
|
|
void unloadFolder( Folder * );
|
2015-02-27 12:42:59 +03:00
|
|
|
|
2015-01-16 14:23:15 +03:00
|
|
|
/** Will start a sync after a bit of delay. */
|
|
|
|
void startScheduledSyncSoon(qint64 msMinimumDelay = 0);
|
|
|
|
|
2012-02-17 12:48:31 +04:00
|
|
|
// finds all folder configuration files
|
|
|
|
// and create the folders
|
2014-09-15 15:49:13 +04:00
|
|
|
QString getBackupName( QString fullPathName ) const;
|
2014-01-11 23:35:16 +04:00
|
|
|
void registerFolderMonitor( Folder *folder );
|
2012-02-17 12:48:31 +04:00
|
|
|
|
2015-07-17 13:12:00 +03:00
|
|
|
// restarts the application (Linux only)
|
|
|
|
void restartApplication();
|
|
|
|
|
2013-11-13 21:58:06 +04:00
|
|
|
QSet<Folder*> _disabledFolders;
|
2012-03-29 12:13:19 +04:00
|
|
|
Folder::Map _folderMap;
|
|
|
|
QString _folderConfigPath;
|
2015-06-15 18:59:08 +03:00
|
|
|
Folder *_currentSyncFolder;
|
2015-04-28 16:13:39 +03:00
|
|
|
QPointer<Folder> _lastSyncFolder;
|
2013-02-10 14:01:24 +04:00
|
|
|
bool _syncEnabled;
|
2014-12-03 00:32:54 +03:00
|
|
|
QTimer _etagPollTimer;
|
|
|
|
QPointer<RequestEtagJob> _currentEtagJob; // alias of Folder running the current RequestEtagJob
|
|
|
|
|
2014-01-11 23:35:16 +04:00
|
|
|
QMap<QString, FolderWatcher*> _folderWatchers;
|
2016-04-29 17:14:18 +03:00
|
|
|
QScopedPointer<LockWatcher> _lockWatcher;
|
2016-03-18 20:31:01 +03:00
|
|
|
QScopedPointer<SocketApi> _socketApi;
|
2014-01-11 23:35:16 +04:00
|
|
|
|
2014-09-17 15:02:11 +04:00
|
|
|
/** The aliases of folders that shall be synced. */
|
2015-04-28 16:13:39 +03:00
|
|
|
QQueue<Folder*> _scheduleQueue;
|
2014-09-17 15:02:11 +04:00
|
|
|
|
2015-01-16 14:23:15 +03:00
|
|
|
/** When the timer expires one of the scheduled syncs will be started. */
|
|
|
|
QTimer _startScheduledSyncTimer;
|
|
|
|
|
2015-07-17 13:12:00 +03:00
|
|
|
bool _appRestartRequired;
|
|
|
|
|
2013-07-22 15:59:52 +04:00
|
|
|
static FolderMan *_instance;
|
2014-05-26 16:34:08 +04:00
|
|
|
explicit FolderMan(QObject *parent = 0);
|
2014-11-10 00:34:07 +03:00
|
|
|
friend class OCC::Application;
|
2015-07-13 15:35:19 +03:00
|
|
|
friend class ::TestFolderMan;
|
2012-02-17 12:48:31 +04:00
|
|
|
};
|
|
|
|
|
2014-11-10 00:34:07 +03:00
|
|
|
} // namespace OCC
|
2012-02-17 12:48:31 +04:00
|
|
|
#endif // FOLDERMAN_H
|