nextcloud-desktop/src/mirall/folder.h

201 lines
4.2 KiB
C
Raw Normal View History

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
#include <QObject>
#include <QString>
#include <QStringList>
#include <QHash>
2011-02-17 02:21:45 +03: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;
class QTimer;
2011-10-19 15:10:43 +04:00
class QIcon;
2011-02-17 02:21:45 +03:00
namespace Mirall {
2012-04-15 16:47:43 +04:00
#ifdef USE_INOTIFY
2011-02-17 02:21:45 +03:00
class FolderWatcher;
#endif
2011-02-17 02:21:45 +03:00
class Folder : public QObject
{
Q_OBJECT
public:
Folder(const QString&, const QString&, const QString& , QObject*parent = 0L);
2011-02-17 02:21:45 +03:00
virtual ~Folder();
typedef QHash<QString, Folder*> Map;
2011-04-06 11:52:02 +04:00
/**
* alias or nickname
*/
QString alias() const;
/**
* local folder path
*/
QString path() const;
virtual QString secondPath() 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
/**
* 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
*/
virtual void startSync(const QStringList &pathList) = 0;
2011-02-17 02:21:45 +03:00
/**
* True if the folder is busy and can't initiate
* a synchronization
*/
virtual bool isBusy() const = 0;
/**
* 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
*/
SyncResult syncResult() const;
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;
2011-10-19 15:10:43 +04:00
QIcon icon( int size ) const;
QTimer *_pollTimer;
2011-11-04 14:41:49 +04:00
public slots:
void slotSyncFinished(const SyncResult &);
void slotChanged(const QStringList &pathList = QStringList() );
2011-11-04 14:41:49 +04:00
protected:
/**
* The minimum amounts of seconds to wait before
* doing a full sync to see if the remote changed
*/
int pollInterval() const;
/**
* Sets minimum amounts of milliseconds that will separate
* poll intervals
*/
void setPollInterval( int );
2011-02-17 02:21:45 +03:00
signals:
void syncStateChange();
2011-02-17 02:21:45 +03:00
void syncStarted();
2011-04-08 13:36:53 +04:00
void syncFinished(const SyncResult &result);
void scheduleToSync( const QString& );
2011-02-17 02:21:45 +03:00
protected:
2012-04-15 16:47:43 +04:00
#ifdef USE_INOTIFY
FolderWatcher *_watcher;
#endif
int _errorCount;
SyncResult _syncResult;
2011-02-17 02:21:45 +03:00
private:
2011-04-06 17:57:18 +04:00
/**
* Starts a sync (calling startSync)
* if the policies allow for it
*/
void evaluateSync(const QStringList &pathList);
2011-11-04 14:41:49 +04:00
QString _path;
QString _secondPath;
2011-11-04 14:41:49 +04:00
QString _alias;
bool _onlyOnlineEnabled;
bool _onlyThisLANEnabled;
#if QT_VERSION >= 0x040700
2011-04-06 17:57:18 +04:00
QNetworkConfigurationManager _networkMgr;
#endif
bool _online;
bool _enabled;
QString _backend;
2011-10-13 18:41:24 +04:00
protected slots:
2011-04-06 17:57:18 +04:00
void slotOnlineChanged(bool online);
void slotPollTimerTimeout();
/* called when the watcher detect a list of changed
paths */
void slotSyncStarted();
2011-11-04 14:41:49 +04:00
2011-02-17 02:21:45 +03:00
};
}
#endif