diff --git a/src/mirall/csyncthread.cpp b/src/mirall/csyncthread.cpp index 135396b2b..d3b1cca35 100644 --- a/src/mirall/csyncthread.cpp +++ b/src/mirall/csyncthread.cpp @@ -29,10 +29,25 @@ namespace Mirall { /* static variables to hold the credentials */ QString CSyncThread::_user; QString CSyncThread::_passwd; +QString CSyncThread::_proxyType; +QString CSyncThread::_proxyPwd; +QString CSyncThread::_proxyPort; +QString CSyncThread::_proxyHost; +QString CSyncThread::_proxyUser; + QString CSyncThread::_csyncConfigDir; // to be able to remove the lock file. QMutex CSyncThread::_mutex; + +struct ProxyInfo { + char *proxyType; + char *proxyHost; + char *proxyPort; + char *proxyUser; + char *proxyPwd; +}; + int CSyncThread::checkPermissions( TREE_WALK_FILE* file, void *data ) { WalkStats *wStats = static_cast(data); @@ -122,7 +137,6 @@ CSyncThread::~CSyncThread() void CSyncThread::run() { CSYNC *csync; - WalkStats *wStats = new WalkStats; QTime walkTime; @@ -137,9 +151,16 @@ void CSyncThread::run() wStats->seenFiles = 0; wStats->conflicts = 0; wStats->error = 0; - const char *statedb = 0; + + ProxyInfo *proxyInfo = new ProxyInfo; _mutex.lock(); + proxyInfo->proxyType = qstrdup( _proxyType.toAscii().constData() ); + proxyInfo->proxyHost = qstrdup( _proxyHost.toAscii().constData() ); + proxyInfo->proxyPort = qstrdup( _proxyPort.toAscii().constData() ); + proxyInfo->proxyUser = qstrdup( _proxyUser.toAscii().constData() ); + proxyInfo->proxyPwd = qstrdup( _proxyPwd.toAscii().constData() ); + if( csync_create(&csync, _source.toUtf8().data(), _target.toUtf8().data()) < 0 ) { @@ -170,6 +191,7 @@ void CSyncThread::run() if( _localCheckOnly ) { csync_set_local_only( csync, true ); } + csync_set_userdata(csync, (void*) proxyInfo); _mutex.unlock(); if( csync_init(csync) < 0 ) { @@ -223,7 +245,7 @@ void CSyncThread::run() qDebug() << "############################################################### >>"; if( csync_update(csync) < 0 ) { - emit csyncError(tr("CSync Update failed.")); + emit csyncError(tr("CSync Update failed wiht errno.")); goto cleanup; } qDebug() << "<<###############################################################"; @@ -272,6 +294,15 @@ void CSyncThread::run() } cleanup: csync_destroy(csync); + + if( proxyInfo->proxyType ) free( proxyInfo->proxyType ); + if( proxyInfo->proxyHost ) free( proxyInfo->proxyHost ); + if( proxyInfo->proxyPort ) free( proxyInfo->proxyPort ); + if( proxyInfo->proxyUser ) free( proxyInfo->proxyUser ); + if( proxyInfo->proxyPwd ) free( proxyInfo->proxyPwd ); + + free( proxyInfo ); + /* * Attention: do not delete the wStat memory here. it is deleted in the * slot catching the signel treeWalkResult because this thread can faster @@ -294,11 +325,18 @@ void CSyncThread::emitStateDb( CSYNC *csync ) } } -void CSyncThread::setUserPwd( const QString& user, const QString& passwd ) +void CSyncThread::setConnectionDetails( const QString& user, const QString& passwd, + const QString& proxyType, const QString& proxyHost, + int proxyPort , const QString& proxyUser, const QString& proxyPwd ) { _mutex.lock(); _user = user; _passwd = passwd; + _proxyType = proxyType; + _proxyHost = proxyHost; + _proxyPort = proxyPort; + _proxyUser = proxyUser; + _proxyPwd = proxyPwd; _mutex.unlock(); } diff --git a/src/mirall/csyncthread.h b/src/mirall/csyncthread.h index 0ae99d948..32aaac6b8 100644 --- a/src/mirall/csyncthread.h +++ b/src/mirall/csyncthread.h @@ -62,7 +62,9 @@ public: virtual void run(); - static void setUserPwd( const QString&, const QString& ); + static void setConnectionDetails( const QString&, const QString&, + const QString&, const QString&, int, + const QString&, const QString& ); static int checkPermissions( TREE_WALK_FILE* file, void *data); static QString csyncConfigDir(); @@ -87,6 +89,12 @@ private: static QMutex _mutex; static QString _user; static QString _passwd; + static QString _proxyType; + static QString _proxyHost; + static QString _proxyPort; + static QString _proxyUser; + static QString _proxyPwd; + static QString _csyncConfigDir; QString _source; diff --git a/src/mirall/owncloudfolder.cpp b/src/mirall/owncloudfolder.cpp index 284622819..55e268d73 100644 --- a/src/mirall/owncloudfolder.cpp +++ b/src/mirall/owncloudfolder.cpp @@ -26,6 +26,7 @@ #include #include #include +#include namespace Mirall { @@ -141,8 +142,28 @@ void ownCloudFolder::startSync(const QStringList &pathList) qDebug() << "*** Start syncing url to ownCloud: " << url.toString() << ", with localOnly: " << _localCheckOnly; + _csync = new CSyncThread( path(), url.toString(), _localCheckOnly ); - _csync->setUserPwd( cfgFile.ownCloudUser(), cfgFile.ownCloudPasswd() ); + + // Proxy settings. Proceed them as strings to csync thread. + QNetworkProxy proxy = QNetworkProxy::applicationProxy(); + QString proxyType; + if( proxy.type() == QNetworkProxy::NoProxy ) + proxyType = QLatin1String("NoProxy"); + else if( proxy.type() == QNetworkProxy::DefaultProxy ) + proxyType = QLatin1String("DefaultProxy"); + else if( proxy.type() == QNetworkProxy::Socks5Proxy ) + proxyType = QLatin1String("Socks5Proxy"); + else if( proxy.type() == QNetworkProxy::HttpProxy ) + proxyType = QLatin1String("HttpProxy"); + else if( proxy.type() == QNetworkProxy::HttpCachingProxy ) + proxyType = QLatin1String("HttpCachingProxy"); + else if( proxy.type() == QNetworkProxy::FtpCachingProxy ) + proxyType = QLatin1String("FtpCachingProxy"); + + _csync->setConnectionDetails( cfgFile.ownCloudUser(), cfgFile.ownCloudPasswd(), proxyType, + proxy.hostName(), proxy.port(), proxy.user(), proxy.password() ); + QObject::connect(_csync, SIGNAL(started()), SLOT(slotCSyncStarted())); QObject::connect(_csync, SIGNAL(finished()), SLOT(slotCSyncFinished())); QObject::connect(_csync, SIGNAL(terminated()), SLOT(slotCSyncTerminated()));