Remove scheduler logic from folderman and moved it in folderman

Also fetch and parse the etag when doing a PROPFIND to get the quota

(Patch from danimo)
This commit is contained in:
Olivier Goffart 2013-08-05 13:34:36 +02:00
parent 99dea76fd1
commit 578bcc3522
7 changed files with 37 additions and 76 deletions

View file

@ -760,7 +760,7 @@ void Application::computeOverallSyncStatus()
QStringList allStatusStrings;
foreach(Folder* folder, map.values()) {
qDebug() << "Folder in overallStatus Message: " << folder << " with name " << folder->alias();
QString folderMessage = folderMan->statusToString(folder->syncResult().status());
QString folderMessage = folderMan->statusToString(folder->syncResult().status(), folder->syncEnabled());
allStatusStrings += tr("Folder %1: %2").arg(folder->alias(), folderMessage);
}

View file

@ -60,7 +60,6 @@ Folder::Folder(const QString &alias, const QString &path, const QString& secondP
: QObject(parent)
, _path(path)
, _secondPath(secondPath)
, _pollTimer(new QTimer(this))
, _alias(alias)
, _enabled(true)
, _thread(0)
@ -70,17 +69,8 @@ Folder::Folder(const QString &alias, const QString &path, const QString& secondP
, _csync_ctx(0)
{
qsrand(QTime::currentTime().msec());
MirallConfigFile cfgFile;
_pollTimer->setSingleShot(true);
int polltime = cfgFile.remotePollInterval()- 2000 + (int)( 4000.0*qrand()/(RAND_MAX+1.0));
qDebug() << "setting remote poll timer interval to" << polltime << "msec for folder " << alias;
_pollTimer->setInterval( polltime );
QObject::connect(_pollTimer, SIGNAL(timeout()), this, SLOT(slotPollTimerTimeout()));
_pollTimer->start();
_watcher = new Mirall::FolderWatcher(path, this);
_watcher = new FolderWatcher(path, this);
MirallConfigFile cfg;
_watcher->addIgnoreListFile( cfg.excludeFile(MirallConfigFile::SystemScope) );
@ -88,10 +78,6 @@ Folder::Folder(const QString &alias, const QString &path, const QString& secondP
QObject::connect(_watcher, SIGNAL(folderChanged(const QStringList &)),
SLOT(slotChanged(const QStringList &)));
QObject::connect(this, SIGNAL(syncStarted()),
SLOT(slotSyncStarted()));
QObject::connect(this, SIGNAL(syncFinished(const SyncResult &)),
SLOT(slotSyncFinished(const SyncResult &)));
_syncResult.setStatus( SyncResult::NotYetStarted );
@ -218,9 +204,6 @@ void Folder::setSyncEnabled( bool doit )
{
_enabled = doit;
_watcher->setEventsEnabled( doit );
if( doit && ! _pollTimer->isActive() ) {
_pollTimer->start();
}
qDebug() << "setSyncEnabled - ############################ " << doit;
if( doit ) {
@ -233,21 +216,11 @@ void Folder::setSyncEnabled( bool doit )
}
}
int Folder::pollInterval() const
{
return _pollTimer->interval();
}
void Folder::setSyncState(SyncResult::Status state)
{
_syncResult.setStatus(state);
}
void Folder::setPollInterval(int milliseconds)
{
_pollTimer->setInterval( milliseconds );
}
SyncResult Folder::syncResult() const
{
return _syncResult;
@ -260,11 +233,6 @@ void Folder::evaluateSync(const QStringList &pathList)
return;
}
// stop the poll timer here. Its started again in the slot of
// sync finished.
qDebug() << "* " << alias() << "Poll timer disabled";
_pollTimer->stop();
_syncResult.setStatus( SyncResult::NotYetStarted );
emit scheduleToSync( alias() );
@ -295,15 +263,6 @@ void Folder::slotSyncFinished(const SyncResult &result)
qDebug() << "OO folder slotSyncFinished: result: " << int(result.status());
emit syncStateChange();
// reenable the poll timer if folder is sync enabled
if( syncEnabled() ) {
qDebug() << "* " << alias() << "Poll timer enabled with " << _pollTimer->interval() << "milliseconds";
_pollTimer->start();
} else {
qDebug() << "* Not enabling poll timer for " << alias();
_pollTimer->stop();
}
}
void Folder::slotLocalPathChanged( const QString& dir )

View file

@ -25,15 +25,13 @@
#include <QHash>
#include <QNetworkAccessManager>
#include <QNetworkProxy>
#include <QNetworkProxyFactory>
#include <QObject>
#include <QStringList>
#include <QThread>
#include <QTimer>
#include <QDebug>
class QFileSystemWatcher;
class QThread;
namespace Mirall {
@ -135,8 +133,6 @@ public:
*/
virtual void wipe();
QTimer *_pollTimer;
signals:
void syncStateChange();
void syncStarted();
@ -156,12 +152,6 @@ public slots:
*/
void slotTerminateSync();
/**
* Sets minimum amounts of milliseconds that will separate
* poll intervals
*/
void setPollInterval( int );
void slotAboutToRemoveAllFiles(SyncFileItem::Direction, bool*);
@ -196,11 +186,6 @@ private slots:
protected:
bool init();
/**
* The minimum amounts of seconds to wait before
* doing a full sync to see if the remote changed
*/
int pollInterval() const;
void setSyncState(SyncResult::Status state);
void setIgnoredFiles();

View file

@ -37,7 +37,8 @@ FolderMan* FolderMan::_instance = 0;
FolderMan::FolderMan(QObject *parent) :
QObject(parent),
_syncEnabled( true )
_syncEnabled( true ),
_pollTimer(new QTimer(this))
{
// if QDir::mkpath would not be so stupid, I would not need to have this
// duplication of folderConfigPath() here
@ -49,6 +50,13 @@ FolderMan::FolderMan(QObject *parent) :
_folderChangeSignalMapper = new QSignalMapper(this);
connect(_folderChangeSignalMapper, SIGNAL(mapped(const QString &)),
this, SIGNAL(folderSyncStateChange(const QString &)));
_pollTimer->setSingleShot(true);
int polltime = cfg.remotePollInterval();
qDebug() << "setting remote poll timer interval to" << polltime << "msec";
_pollTimer->setInterval( polltime );
QObject::connect(_pollTimer, SIGNAL(timeout()), this, SLOT(slotScheduleAllFolders()));
_pollTimer->start();
}
FolderMan *FolderMan::instance()
@ -296,7 +304,7 @@ void FolderMan::terminateSyncProcess( const QString& alias )
f->slotTerminateSync();
if(_currentSyncFolder == folderAlias )
_currentSyncFolder = QString::null;
_currentSyncFolder.clear();
}
}
}
@ -325,7 +333,9 @@ SyncResult FolderMan::syncResult( Folder *f )
void FolderMan::slotScheduleAllFolders()
{
foreach( Folder *f, _folderMap.values() ) {
slotScheduleSync( f->alias() );
if (f->syncEnabled()) {
slotScheduleSync( f->alias() );
}
}
}
@ -344,13 +354,10 @@ void FolderMan::slotScheduleSync( const QString& alias )
}
if( ! _scheduleQueue.contains(alias )) {
_scheduleQueue.append(alias);
_scheduleQueue.enqueue(alias);
} else {
qDebug() << " II> Sync for folder " << alias << " already scheduled, do not enqueue!";
}
slotScheduleFolderSync();
}
void FolderMan::setSyncEnabled( bool enabled )
@ -377,12 +384,14 @@ void FolderMan::slotScheduleFolderSync()
qDebug() << "XX slotScheduleFolderSync: folderQueue size: " << _scheduleQueue.count();
if( ! _scheduleQueue.isEmpty() ) {
const QString alias = _scheduleQueue.takeFirst();
const QString alias = _scheduleQueue.dequeue();
if( _folderMap.contains( alias ) ) {
ownCloudInfo::instance()->getQuotaRequest("/");
Folder *f = _folderMap[alias];
_currentSyncFolder = alias;
f->startSync( QStringList() );
if (f->syncEnabled()) {
f->startSync( QStringList() );
}
}
}
}
@ -548,7 +557,7 @@ SyncResult FolderMan::accountStatus(const QList<Folder*> &folders)
return overallResult;
}
QString FolderMan::statusToString( SyncResult syncStatus ) const
QString FolderMan::statusToString( SyncResult syncStatus, bool enabled ) const
{
QString folderMessage;
switch( syncStatus.status() ) {
@ -578,11 +587,10 @@ QString FolderMan::statusToString( SyncResult syncStatus ) const
break;
// no default case on purpose, check compiler warnings
}
// FIXME!
// if( !folder->syncEnabled() ) {
// // sync is disabled.
// folderMessage = tr( "%1 (Sync is paused)" ).arg(folderMessage);
// }
if( !enabled ) {
// sync is disabled.
folderMessage = tr( "%1 (Sync is paused)" ).arg(folderMessage);
}
return folderMessage;
}

View file

@ -25,6 +25,7 @@
#include "mirall/syncfileitem.h"
class QSignalMapper;
class QTimer;
class SyncResult;
@ -78,7 +79,7 @@ public:
/** Creates a new and empty local directory. */
bool startFromScratch( const QString& );
QString statusToString( SyncResult ) const;
QString statusToString( SyncResult, bool enabled ) const;
static SyncResult accountStatus( const QList<Folder*> &folders );
@ -131,11 +132,12 @@ private:
void removeFolder( const QString& );
Folder::Map _folderMap;
QTimer *_pollTimer;
QString _folderConfigPath;
QSignalMapper *_folderChangeSignalMapper;
QString _currentSyncFolder;
QStringList _scheduleQueue;
bool _syncEnabled;
QQueue<QString> _scheduleQueue;
explicit FolderMan(QObject *parent = 0);
static FolderMan *_instance;

View file

@ -170,6 +170,7 @@ QNetworkReply* ownCloudInfo::getQuotaRequest( const QString& dir )
" <d:prop>\n"
" <d:quota-available-bytes/>\n"
" <d:quota-used-bytes/>\n"
" <d:getetag/>"
" </d:prop>\n"
"</d:propfind>\n");
QBuffer *buf = new QBuffer;
@ -245,6 +246,7 @@ void ownCloudInfo::slotGetQuotaFinished()
qint64 quotaUsedBytes = 0;
qint64 quotaAvailableBytes = 0;
QString etag;
while (!reader.atEnd()) {
QXmlStreamReader::TokenType type = reader.readNext();
@ -257,6 +259,8 @@ void ownCloudInfo::slotGetQuotaFinished()
} else if (name == QLatin1String("quota-available-bytes")) {
quotaAvailableBytes = reader.readElementText().toLongLong(&ok);
if (!ok) quotaAvailableBytes = 0;
} else if (name == QLatin1String("getetag")) {
etag = reader.readElementText();
}
}
}
@ -266,6 +270,7 @@ void ownCloudInfo::slotGetQuotaFinished()
_lastQuotaTotalBytes = total;
_lastQuotaUsedBytes = quotaUsedBytes;
emit quotaUpdated(total, quotaUsedBytes);
_lastEtag = etag;
} else {
_lastQuotaTotalBytes = 0;
_lastQuotaUsedBytes = 0;

View file

@ -116,6 +116,7 @@ public:
qint64 lastQuotaUsedBytes() const { return _lastQuotaUsedBytes; }
qint64 lastQuotaTotalBytes() const { return _lastQuotaTotalBytes; }
QString lastEtag() const { return _lastEtag; }
QList<QNetworkCookie> getLastAuthCookies();
@ -169,6 +170,7 @@ private:
int _redirectCount;
qint64 _lastQuotaUsedBytes;
qint64 _lastQuotaTotalBytes;
QString _lastEtag;
};
};