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>
|
2014-07-14 17:31:38 +04:00
|
|
|
#include <QPointer>
|
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;
|
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
|
|
|
|
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& );
|
|
|
|
|
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.
|
|
|
|
* Make sure that this folder, or any subfolder is not sync'ed alrady.
|
|
|
|
*
|
|
|
|
* @returns an empty string if it is allowed, or an error if it is not allowed
|
|
|
|
*/
|
|
|
|
QString checkPathValidityForNewFolder(const QString &path);
|
|
|
|
|
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-04-28 16:13:39 +03:00
|
|
|
* Attention: The folder may be zero. Do a general update of the state than.
|
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
|
|
|
|
2014-03-26 22:30:13 +04:00
|
|
|
void folderListLoaded(const Folder::Map &);
|
|
|
|
|
2012-02-17 12:48:31 +04:00
|
|
|
public slots:
|
2015-04-28 16:13:39 +03:00
|
|
|
void slotRemoveFolder( Folder* );
|
|
|
|
void slotSetFolderPaused(Folder *, bool paused);
|
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*);
|
2014-12-03 00:32:54 +03:00
|
|
|
// slot to scheule an ETag job
|
|
|
|
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();
|
|
|
|
|
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();
|
|
|
|
|
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
|
|
|
*/
|
2015-06-17 15:53:58 +03:00
|
|
|
Folder* addFolderInternal(const FolderDefinition& folderDefinition);
|
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
|
|
|
|
2012-10-17 17:13:55 +04:00
|
|
|
QString unescapeAlias( const QString& ) const;
|
|
|
|
|
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;
|
2014-07-14 17:31:38 +04:00
|
|
|
QPointer<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;
|
|
|
|
|
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
|