Read poll timer settings from config file.

This commit is contained in:
Klaas Freitag 2012-05-26 14:37:21 +02:00
parent dc7c6d1913
commit 3052506d31
5 changed files with 76 additions and 8 deletions

View file

@ -20,8 +20,6 @@
#include <QTimer>
#include <QUrl>
#define DEFAULT_POLL_INTERVAL_SEC 15000
namespace Mirall {
Folder::Folder(const QString &alias, const QString &path, const QString& secondPath, QObject *parent)
@ -37,9 +35,11 @@ Folder::Folder(const QString &alias, const QString &path, const QString& secondP
_enabled(true)
{
qsrand(QTime::currentTime().msec());
MirallConfigFile cfgFile;
_pollTimer->setSingleShot(true);
int polltime = DEFAULT_POLL_INTERVAL_SEC - 2000+ (int)( 4000.0*qrand()/(RAND_MAX+1.0));
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()));

View file

@ -31,6 +31,10 @@
#include <mach-o/dyld.h>
#endif
#define DEFAULT_REMOTE_POLL_INTERVAL 30000 // default remote poll time in milliseconds
#define DEFAULT_LOCAL_POLL_INTERVAL 10000 // default local poll time in milliseconds
#define DEFAULT_POLL_TIMER_EXEED 10
namespace Mirall {
QString MirallConfigFile::_passwd; // = QString();
@ -220,6 +224,61 @@ QString MirallConfigFile::ownCloudUser( const QString& connection ) const
return user;
}
int MirallConfigFile::remotePollInterval( const QString& connection ) const
{
QString con( connection );
if( connection.isEmpty() ) con = defaultConnection();
QSettings settings( configFile(), QSettings::IniFormat );
settings.beginGroup( con );
int remoteInterval = settings.value( "remotePollInterval", DEFAULT_REMOTE_POLL_INTERVAL ).toInt();
int localInterval = settings.value("localPollInterval", DEFAULT_LOCAL_POLL_INTERVAL ).toInt();
if( remoteInterval < 2*localInterval ) {
qDebug() << "WARN: remote poll Interval should at least be twice as local poll interval!";
}
if( remoteInterval < 5000 || remoteInterval < localInterval ) {
qDebug() << "Remote Interval is smaller than local Interval";
remoteInterval = DEFAULT_REMOTE_POLL_INTERVAL;
}
return remoteInterval;
}
int MirallConfigFile::localPollInterval( const QString& connection ) const
{
QString con( connection );
if( connection.isEmpty() ) con = defaultConnection();
QSettings settings( configFile(), QSettings::IniFormat );
settings.beginGroup( con );
int remoteInterval = settings.value( "remotePollInterval", DEFAULT_REMOTE_POLL_INTERVAL ).toInt();
int localInterval = settings.value("localPollInterval", DEFAULT_LOCAL_POLL_INTERVAL ).toInt();
if( remoteInterval < 2*localInterval ) {
qDebug() << "WARN: remote poll Interval should at least be twice as local poll interval!";
}
if( localInterval < 2500 || remoteInterval < localInterval ) {
qDebug() << "Remote Interval is smaller than local Interval";
localInterval = DEFAULT_LOCAL_POLL_INTERVAL;
}
return localInterval;
}
int MirallConfigFile::pollTimerExceedFactor( const QString& connection ) const
{
QString con( connection );
if( connection.isEmpty() ) con = defaultConnection();
QSettings settings( configFile(), QSettings::IniFormat );
settings.beginGroup( con );
int pte = settings.value( "pollTimerExeedFactor", DEFAULT_POLL_TIMER_EXEED).toInt();
if( pte < 1 ) pte = DEFAULT_POLL_TIMER_EXEED;
return pte;
}
QString MirallConfigFile::ownCloudPasswd( const QString& connection ) const
{
QString con( connection );

View file

@ -53,6 +53,11 @@ public:
bool ownCloudSkipUpdateCheck( const QString& connection = QString() ) const;
/* Poll intervals in milliseconds */
int localPollInterval ( const QString& connection = QString() ) const;
int remotePollInterval( const QString& connection = QString() ) const;
int pollTimerExceedFactor( const QString& connection = QString() ) const;
QByteArray basicAuthHeader() const;
private:

View file

@ -29,7 +29,6 @@
namespace Mirall {
#define POLL_TIMER_EXCEED 10
ownCloudFolder::ownCloudFolder(const QString &alias,
const QString &path,
@ -54,10 +53,14 @@ ownCloudFolder::ownCloudFolder(const QString &alias,
* remote poll interval, defined in slotPollTimerRemoteCheck
*/
MirallConfigFile cfgFile;
_pollTimer->stop();
connect( _pollTimer, SIGNAL(timeout()), this, SLOT(slotPollTimerRemoteCheck()));
setPollInterval( 2000 );
_pollTimerCnt = POLL_TIMER_EXCEED-1; // start the syncing quickly!
setPollInterval( cfgFile.localPollInterval()- 500 + (int)( 1000.0*qrand()/(RAND_MAX+1.0) ) );
_pollTimerExceed = cfgFile.pollTimerExceedFactor();
_pollTimerCnt = _pollTimerExceed-1; // start the syncing quickly!
_pollTimer->start();
qDebug() << "****** ownCloud folder using local poll *******";
#endif
@ -124,7 +127,7 @@ void ownCloudFolder::startSync(const QStringList &pathList)
_localCheckOnly = false;
#else
_localCheckOnly = true;
if( _pollTimerCnt >= POLL_TIMER_EXCEED || _localFileChanges ) {
if( _pollTimerCnt >= _pollTimerExceed || _localFileChanges ) {
_localCheckOnly = false;
_pollTimerCnt = 0;
_localFileChanges = false;
@ -177,7 +180,7 @@ void ownCloudFolder::slotThreadTreeWalkResult( WalkStats *wStats )
qDebug() << "*** Local changes, lets do a full sync!" ;
_localFileChanges = true;
}
if( _pollTimerCnt < POLL_TIMER_EXCEED ) {
if( _pollTimerCnt < _pollTimerExceed ) {
qDebug() << " *** No local changes, finalize, pollTimerCounter is "<< _pollTimerCnt ;
}
#endif

View file

@ -58,6 +58,7 @@ private:
bool _localCheckOnly;
bool _localFileChanges;
int _pollTimerCnt;
int _pollTimerExceed;
QStringList _errors;
bool _csyncError;
ulong _lastSeenFiles;