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
|
|
|
|
|
|
|
#include "mirall/folder.h"
|
|
|
|
#include "mirall/folderwatcher.h"
|
2013-01-15 23:41:52 +04:00
|
|
|
#include "mirall/syncfileitem.h"
|
2012-02-17 12:48:31 +04:00
|
|
|
|
2012-02-19 00:21:58 +04:00
|
|
|
class QSignalMapper;
|
|
|
|
|
2012-02-17 12:48:31 +04:00
|
|
|
class SyncResult;
|
|
|
|
|
2013-07-22 14:10:13 +04:00
|
|
|
namespace Mirall {
|
|
|
|
|
2012-02-17 12:48:31 +04:00
|
|
|
class FolderMan : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2013-07-22 15:59:52 +04:00
|
|
|
static FolderMan* instance();
|
2012-02-17 12:48:31 +04:00
|
|
|
~FolderMan();
|
|
|
|
|
|
|
|
int setupFolders();
|
|
|
|
|
|
|
|
Mirall::Folder::Map map();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a folder definition to the config
|
|
|
|
* Params:
|
|
|
|
* QString alias
|
|
|
|
* QString sourceFolder on local machine
|
|
|
|
* QString targetPath on remote
|
|
|
|
*/
|
2013-07-22 22:27:42 +04:00
|
|
|
void addFolderDefinition(const QString&, const QString&, const QString& );
|
2013-10-03 19:04:55 +04:00
|
|
|
|
|
|
|
/** Returns the folder which the file or directory stored in path is in */
|
|
|
|
Folder* folderForPath(const QUrl& 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& );
|
|
|
|
|
2013-07-24 16:16:52 +04:00
|
|
|
/** Returns the last sync result by alias */
|
2012-02-17 12:48:31 +04:00
|
|
|
SyncResult syncResult( const QString& );
|
2012-02-19 00:21:58 +04:00
|
|
|
|
2013-07-24 16:16:52 +04:00
|
|
|
/** Returns the last sync result by Folder */
|
2013-07-04 21:59:40 +04:00
|
|
|
SyncResult syncResult( Folder* );
|
|
|
|
|
2013-07-24 16:16:52 +04:00
|
|
|
/** Creates a folder for a specific configuration, identified by alias. */
|
2012-04-02 15:21:13 +04:00
|
|
|
Folder* setupFolderFromConfigFile(const QString & );
|
|
|
|
|
2013-07-24 16:16:52 +04:00
|
|
|
/** Wipes all folder defintions. No way back! */
|
2012-06-12 14:29:39 +04:00
|
|
|
void removeAllFolderDefinitions();
|
|
|
|
|
2013-07-24 16:16:52 +04:00
|
|
|
/** Removes csync journals from all folders. */
|
2013-02-10 23:04:03 +04:00
|
|
|
void wipeAllJournals();
|
|
|
|
|
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& );
|
|
|
|
|
2013-08-05 15:34:36 +04:00
|
|
|
QString statusToString( SyncResult, bool enabled ) const;
|
2013-07-22 14:10:13 +04:00
|
|
|
|
|
|
|
static SyncResult accountStatus( const QList<Folder*> &folders );
|
|
|
|
|
2012-02-17 12:48:31 +04:00
|
|
|
signals:
|
2012-02-19 00:21:58 +04:00
|
|
|
/**
|
|
|
|
* signal to indicate a folder named by alias has changed its sync state.
|
|
|
|
* Get the state via the Folder Map or the syncResult and syncState methods.
|
|
|
|
*/
|
|
|
|
void folderSyncStateChange( const QString & );
|
2012-02-17 12:48:31 +04:00
|
|
|
|
|
|
|
public slots:
|
|
|
|
void slotRemoveFolder( const QString& );
|
|
|
|
void slotEnableFolder( const QString&, bool );
|
|
|
|
|
|
|
|
void slotFolderSyncStarted();
|
|
|
|
void slotFolderSyncFinished( const SyncResult& );
|
|
|
|
|
2013-06-03 17:46:11 +04:00
|
|
|
void terminateSyncProcess( const QString& alias = QString::null );
|
2012-04-30 10:56:56 +04:00
|
|
|
|
2013-06-03 19:26:48 +04:00
|
|
|
/* delete all folder objects */
|
|
|
|
int unloadAllFolders();
|
|
|
|
|
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);
|
2013-08-27 12:02:59 +04:00
|
|
|
|
2012-03-22 19:22:08 +04:00
|
|
|
private slots:
|
|
|
|
// slot to add a folder to the syncing queue
|
2012-03-29 12:13:19 +04:00
|
|
|
void slotScheduleSync( const QString & );
|
2012-03-22 19:22:08 +04:00
|
|
|
|
|
|
|
// slot to take the next folder from queue and start syncing.
|
|
|
|
void slotScheduleFolderSync();
|
|
|
|
|
2012-02-17 12:48:31 +04:00
|
|
|
private:
|
|
|
|
// finds all folder configuration files
|
|
|
|
// and create the folders
|
2013-02-10 23:04:03 +04:00
|
|
|
void terminateCurrentSync();
|
2013-05-26 15:56:51 +04:00
|
|
|
QString getBackupName( const QString& ) const;
|
2012-02-17 12:48:31 +04:00
|
|
|
|
2012-10-17 17:13:55 +04:00
|
|
|
// Escaping of the alias which is used in QSettings AND the file
|
|
|
|
// system, thus need to be escaped.
|
|
|
|
QString escapeAlias( const QString& ) const;
|
|
|
|
QString unescapeAlias( const QString& ) const;
|
|
|
|
|
2012-03-29 12:13:19 +04:00
|
|
|
void removeFolder( const QString& );
|
|
|
|
|
2013-11-13 21:58:06 +04:00
|
|
|
QSet<Folder*> _disabledFolders;
|
2012-03-29 12:13:19 +04:00
|
|
|
Folder::Map _folderMap;
|
|
|
|
QString _folderConfigPath;
|
2012-02-19 00:21:58 +04:00
|
|
|
QSignalMapper *_folderChangeSignalMapper;
|
2012-03-29 12:13:19 +04:00
|
|
|
QString _currentSyncFolder;
|
2013-02-10 14:01:24 +04:00
|
|
|
bool _syncEnabled;
|
2013-08-05 15:34:36 +04:00
|
|
|
QQueue<QString> _scheduleQueue;
|
2013-08-27 12:02:59 +04:00
|
|
|
bool _dirtyProxy; // If the proxy need to be re-configured
|
2013-07-22 15:59:52 +04:00
|
|
|
|
|
|
|
explicit FolderMan(QObject *parent = 0);
|
|
|
|
static FolderMan *_instance;
|
|
|
|
|
2012-02-17 12:48:31 +04:00
|
|
|
};
|
|
|
|
|
2013-07-22 14:10:13 +04:00
|
|
|
} // namespace Mirall
|
2012-02-17 12:48:31 +04:00
|
|
|
#endif // FOLDERMAN_H
|