2011-04-06 13:48:02 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Duncan Mac-Vicar P. <duncan@kde.org>
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
|
2012-07-20 19:13:23 +04:00
|
|
|
#include "config.h"
|
|
|
|
|
2011-02-17 02:21:45 +03:00
|
|
|
#include <QObject>
|
|
|
|
#include <QString>
|
2011-03-23 01:03:43 +03:00
|
|
|
#include <QStringList>
|
2011-10-11 16:23:32 +04:00
|
|
|
#include <QHash>
|
2012-12-05 21:23:35 +04:00
|
|
|
#include <QTimer>
|
2011-02-17 02:21:45 +03:00
|
|
|
|
2012-04-21 23:03:29 +04:00
|
|
|
#if QT_VERSION >= 0x040700
|
|
|
|
#include <QNetworkConfigurationManager>
|
|
|
|
#endif
|
|
|
|
|
2011-04-08 13:36:53 +04:00
|
|
|
#include "mirall/syncresult.h"
|
|
|
|
|
2011-02-17 02:21:45 +03:00
|
|
|
class QAction;
|
2011-10-19 15:10:43 +04:00
|
|
|
class QIcon;
|
2012-06-25 17:31:13 +04:00
|
|
|
class QFileSystemWatcher;
|
2011-02-17 02:21:45 +03:00
|
|
|
|
|
|
|
namespace Mirall {
|
|
|
|
|
|
|
|
class FolderWatcher;
|
|
|
|
|
|
|
|
class Folder : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2012-03-26 15:20:15 +04:00
|
|
|
Folder(const QString&, const QString&, const QString& , QObject*parent = 0L);
|
2011-02-17 02:21:45 +03:00
|
|
|
virtual ~Folder();
|
|
|
|
|
2011-10-11 16:23:32 +04:00
|
|
|
typedef QHash<QString, Folder*> Map;
|
|
|
|
|
2011-04-06 11:52:02 +04:00
|
|
|
/**
|
|
|
|
* alias or nickname
|
|
|
|
*/
|
|
|
|
QString alias() const;
|
|
|
|
|
2011-02-17 17:10:06 +03:00
|
|
|
/**
|
|
|
|
* local folder path
|
|
|
|
*/
|
|
|
|
QString path() const;
|
2012-03-26 15:20:15 +04:00
|
|
|
virtual QString secondPath() const;
|
2011-02-17 17:10:06 +03:00
|
|
|
|
2012-08-15 19:16:44 +04:00
|
|
|
/**
|
|
|
|
* local folder path with native separators
|
|
|
|
*/
|
|
|
|
QString nativePath() const;
|
|
|
|
virtual QString nativeSecondPath() const;
|
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.
|
|
|
|
*/
|
|
|
|
void setSyncEnabled( bool );
|
|
|
|
|
|
|
|
bool syncEnabled() const;
|
|
|
|
|
2011-02-17 02:21:45 +03:00
|
|
|
/**
|
2011-04-05 14:16:24 +04:00
|
|
|
* Starts a sync operation
|
|
|
|
*
|
|
|
|
* If the list of changed files is known, it is passed.
|
|
|
|
*
|
|
|
|
* If the list of changed files is empty, the folder
|
|
|
|
* implementation should figure it by itself of
|
|
|
|
* perform a full scan of changes
|
2011-02-17 02:21:45 +03:00
|
|
|
*/
|
2011-03-25 20:25:56 +03:00
|
|
|
virtual void startSync(const QStringList &pathList) = 0;
|
2011-02-17 02:21:45 +03:00
|
|
|
|
2011-03-27 04:26:41 +04:00
|
|
|
/**
|
|
|
|
* True if the folder is busy and can't initiate
|
|
|
|
* a synchronization
|
|
|
|
*/
|
|
|
|
virtual bool isBusy() const = 0;
|
2011-03-23 01:03:43 +03:00
|
|
|
|
2011-04-06 17:22:40 +04:00
|
|
|
/**
|
|
|
|
* only sync when online in the network
|
|
|
|
*/
|
|
|
|
bool onlyOnlineEnabled() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see onlyOnlineEnabled
|
|
|
|
*/
|
|
|
|
void setOnlyOnlineEnabled(bool enabled);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* only sync when online in the same LAN
|
|
|
|
* as the one used during setup
|
|
|
|
*/
|
|
|
|
bool onlyThisLANEnabled() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see onlyThisLANEnabled
|
|
|
|
*/
|
|
|
|
void setOnlyThisLANEnabled(bool enabled);
|
|
|
|
|
|
|
|
|
2011-09-27 10:15:30 +04:00
|
|
|
/**
|
|
|
|
* error counter, stop syncing after the counter reaches a certain
|
|
|
|
* number.
|
|
|
|
*/
|
|
|
|
int errorCount();
|
|
|
|
|
|
|
|
void resetErrorCount();
|
|
|
|
|
|
|
|
void incrementErrorCount();
|
|
|
|
|
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
|
|
|
|
2011-10-18 12:22:24 +04:00
|
|
|
/**
|
|
|
|
* set the backend description string.
|
|
|
|
*/
|
|
|
|
void setBackend( const QString& );
|
|
|
|
/**
|
|
|
|
* get the backend description string.
|
|
|
|
*/
|
|
|
|
QString backend() const;
|
|
|
|
|
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();
|
|
|
|
|
2011-10-19 15:10:43 +04:00
|
|
|
QIcon icon( int size ) const;
|
2012-04-30 10:56:56 +04:00
|
|
|
QTimer *_pollTimer;
|
2011-11-04 14:41:49 +04:00
|
|
|
|
2013-02-09 17:03:05 +04:00
|
|
|
signals:
|
|
|
|
void syncStateChange();
|
|
|
|
void syncStarted();
|
|
|
|
void syncFinished(const SyncResult &result);
|
|
|
|
void scheduleToSync( const QString& );
|
|
|
|
|
2011-11-04 14:41:49 +04:00
|
|
|
public slots:
|
|
|
|
void slotSyncFinished(const SyncResult &);
|
2012-04-30 10:56:56 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2012-02-20 19:45:27 +04:00
|
|
|
void slotChanged(const QStringList &pathList = QStringList() );
|
2011-11-04 14:41:49 +04:00
|
|
|
|
2012-04-30 10:56:56 +04:00
|
|
|
/**
|
|
|
|
* terminate the current sync run
|
|
|
|
*/
|
|
|
|
virtual void slotTerminateSync() = 0;
|
|
|
|
|
2013-02-09 17:03:05 +04:00
|
|
|
/**
|
|
|
|
* Sets minimum amounts of milliseconds that will separate
|
|
|
|
* poll intervals
|
|
|
|
*/
|
|
|
|
void setPollInterval( uint );
|
|
|
|
|
2011-04-05 14:16:24 +04:00
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* The minimum amounts of seconds to wait before
|
|
|
|
* doing a full sync to see if the remote changed
|
|
|
|
*/
|
2013-02-09 17:03:05 +04:00
|
|
|
uint pollInterval() const;
|
2011-02-17 02:21:45 +03:00
|
|
|
|
2011-04-04 20:41:14 +04:00
|
|
|
FolderWatcher *_watcher;
|
2012-04-17 15:16:48 +04:00
|
|
|
int _errorCount;
|
|
|
|
SyncResult _syncResult;
|
2011-04-05 14:16:24 +04:00
|
|
|
|
2013-02-09 17:03:05 +04:00
|
|
|
protected slots:
|
|
|
|
|
|
|
|
void slotOnlineChanged(bool online);
|
|
|
|
|
|
|
|
void slotPollTimerTimeout();
|
|
|
|
|
|
|
|
/* called when the watcher detect a list of changed
|
|
|
|
paths */
|
|
|
|
|
|
|
|
void slotSyncStarted();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Triggered by a file system watcher on the local sync dir
|
|
|
|
*/
|
|
|
|
virtual void slotLocalPathChanged( const QString& );
|
|
|
|
|
2011-02-17 02:21:45 +03:00
|
|
|
private:
|
2011-04-05 14:16:24 +04:00
|
|
|
|
2011-04-06 17:57:18 +04:00
|
|
|
/**
|
|
|
|
* Starts a sync (calling startSync)
|
|
|
|
* if the policies allow for it
|
|
|
|
*/
|
|
|
|
void evaluateSync(const QStringList &pathList);
|
|
|
|
|
2012-10-30 15:42:17 +04:00
|
|
|
virtual void checkLocalPath();
|
|
|
|
|
2011-11-04 14:41:49 +04:00
|
|
|
QString _path;
|
2012-03-26 15:20:15 +04:00
|
|
|
QString _secondPath;
|
2011-11-04 14:41:49 +04:00
|
|
|
QString _alias;
|
|
|
|
bool _onlyOnlineEnabled;
|
|
|
|
bool _onlyThisLANEnabled;
|
2012-11-22 15:29:50 +04:00
|
|
|
QString _configFile;
|
2012-06-25 17:31:13 +04:00
|
|
|
|
|
|
|
QFileSystemWatcher *_pathWatcher;
|
|
|
|
|
2012-04-21 23:03:29 +04:00
|
|
|
#if QT_VERSION >= 0x040700
|
2011-04-06 17:57:18 +04:00
|
|
|
QNetworkConfigurationManager _networkMgr;
|
2012-04-21 23:03:29 +04:00
|
|
|
#endif
|
2012-02-19 00:21:58 +04:00
|
|
|
bool _online;
|
|
|
|
bool _enabled;
|
|
|
|
QString _backend;
|
2011-10-13 18:41:24 +04:00
|
|
|
|
2011-02-17 02:21:45 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|