diff --git a/src/mirall/application.cpp b/src/mirall/application.cpp index 9d8faa45b9..68a2d18c3d 100644 --- a/src/mirall/application.cpp +++ b/src/mirall/application.cpp @@ -31,16 +31,15 @@ #include "mirall/theme.h" #include "mirall/updater.h" #include "mirall/utility.h" +#include "mirall/clientproxy.h" #include "creds/abstractcredentials.h" -#if defined(Q_OS_WIN) +#if defined(QOS_WIN) #include #endif #include -#include -#include #include #include @@ -123,13 +122,13 @@ Application::Application(int &argc, char **argv) : connect (_theme, SIGNAL(systrayUseMonoIconsChanged(bool)), SLOT(slotUseMonoIconsChanged(bool))); FolderMan::instance()->setupFolders(); - slotSetupProxy(); // folders have to be defined first. + _proxy.setupQtProxyFromConfig(); // folders have to be defined first, than we set up the Qt proxy. _gui = new ownCloudGui(this); if( _showLogWindow ) { _gui->slotToggleLogBrowser(); // _showLogWindow is set in parseOptions. } - connect( _gui, SIGNAL(setupProxy()), SLOT(slotSetupProxy())); + if (account) { connect(account, SIGNAL(stateChanged(int)), _gui, SLOT(slotAccountStateChanged())); } @@ -314,54 +313,6 @@ void Application::setupLogging() } -QNetworkProxy proxyFromConfig(const MirallConfigFile& cfg) -{ - QNetworkProxy proxy; - - if (cfg.proxyHostName().isEmpty()) - return QNetworkProxy(); - - proxy.setHostName(cfg.proxyHostName()); - proxy.setPort(cfg.proxyPort()); - if (cfg.proxyNeedsAuth()) { - proxy.setUser(cfg.proxyUser()); - proxy.setPassword(cfg.proxyPassword()); - } - return proxy; -} - -void Application::slotSetupProxy() -{ - Mirall::MirallConfigFile cfg; - int proxyType = cfg.proxyType(); - QNetworkProxy proxy = proxyFromConfig(cfg); - - switch(proxyType) { - case QNetworkProxy::NoProxy: - QNetworkProxyFactory::setUseSystemConfiguration(false); - QNetworkProxy::setApplicationProxy(QNetworkProxy::NoProxy); - break; - case QNetworkProxy::DefaultProxy: - QNetworkProxyFactory::setUseSystemConfiguration(true); - break; - case QNetworkProxy::Socks5Proxy: - proxy.setType(QNetworkProxy::Socks5Proxy); - QNetworkProxyFactory::setUseSystemConfiguration(false); - QNetworkProxy::setApplicationProxy(proxy); - break; - case QNetworkProxy::HttpProxy: - proxy.setType(QNetworkProxy::HttpProxy); - QNetworkProxyFactory::setUseSystemConfiguration(false); - QNetworkProxy::setApplicationProxy(proxy); - break; - default: - break; - } - - FolderMan::instance()->setDirtyProxy(true); - FolderMan::instance()->slotScheduleAllFolders(); -} - void Application::slotUseMonoIconsChanged(bool) { _gui->slotComputeOverallSyncStatus(); diff --git a/src/mirall/application.h b/src/mirall/application.h index 916c04069f..1f057cda03 100644 --- a/src/mirall/application.h +++ b/src/mirall/application.h @@ -26,6 +26,7 @@ #include "mirall/owncloudgui.h" #include "mirall/connectionvalidator.h" #include "mirall/progressdispatcher.h" +#include "mirall/clientproxy.h" class QMessageBox; class QSystemTrayIcon; @@ -71,7 +72,6 @@ protected slots: void slotCheckConnection(); void slotConnectionValidatorResult(ConnectionValidator::Status); void slotStartUpdateDetector(); - void slotSetupProxy(); void slotUseMonoIconsChanged( bool ); void slotCredentialsFetched(); void slotLogin(); @@ -102,6 +102,8 @@ private: bool _userTriggeredConnect; QPointer _connectionMsgBox; + ClientProxy _proxy; + friend class ownCloudGui; // for _startupNetworkError }; diff --git a/src/mirall/folder.cpp b/src/mirall/folder.cpp index 57e17538b4..04e1822396 100644 --- a/src/mirall/folder.cpp +++ b/src/mirall/folder.cpp @@ -24,6 +24,7 @@ #include "mirall/syncjournalfilerecord.h" #include "mirall/syncresult.h" #include "mirall/utility.h" +#include "mirall/clientproxy.h" #include "creds/abstractcredentials.h" @@ -520,30 +521,6 @@ void Folder::setIgnoredFiles() } } -void Folder::setProxy() -{ - - /* Store proxy */ - QUrl proxyUrl(AccountManager::instance()->account()->url()); - QList proxies = QNetworkProxyFactory::proxyForQuery(QNetworkProxyQuery(proxyUrl)); - // We set at least one in Application - Q_ASSERT(proxies.count() > 0); - QNetworkProxy proxy = proxies.first(); - if (proxy.type() == QNetworkProxy::NoProxy) { - qDebug() << "Passing NO proxy to csync for" << proxyUrl; - } else { - qDebug() << "Passing" << proxy.hostName() << "of proxy type " << proxy.type() - << " to csync for" << proxyUrl; - } - _proxy_type = proxyTypeToCStr(proxy.type()); - _proxy_host = proxy.hostName().toUtf8(); - _proxy_port = proxy.port(); - _proxy_user = proxy.user().toUtf8(); - _proxy_pwd = proxy.password().toUtf8(); - - setProxyDirty(false); -} - void Folder::setProxyDirty(bool value) { _proxyDirty = value; @@ -587,15 +564,11 @@ void Folder::startSync(const QStringList &pathList) QMetaObject::invokeMethod(this, "slotCSyncFinished", Qt::QueuedConnection); return; } - setProxy(); + _clientProxy.setCSyncProxy(AccountManager::instance()->account()->url(), _csync_ctx); } else if (proxyDirty()) { - setProxy(); + _clientProxy.setCSyncProxy(AccountManager::instance()->account()->url(), _csync_ctx); + setProxyDirty(false); } - csync_set_module_property(_csync_ctx, "proxy_type", const_cast(_proxy_type) ); - csync_set_module_property(_csync_ctx, "proxy_host", _proxy_host.data() ); - csync_set_module_property(_csync_ctx, "proxy_port", &_proxy_port ); - csync_set_module_property(_csync_ctx, "proxy_user", _proxy_user.data() ); - csync_set_module_property(_csync_ctx, "proxy_pwd", _proxy_pwd.data() ); if (_thread && _thread->isRunning()) { qCritical() << "* ERROR csync is still running and new sync requested."; diff --git a/src/mirall/folder.h b/src/mirall/folder.h index 6880d691dc..05bc0b9d58 100644 --- a/src/mirall/folder.h +++ b/src/mirall/folder.h @@ -21,6 +21,9 @@ #include "mirall/progressdispatcher.h" #include "mirall/csyncthread.h" #include "mirall/syncjournaldb.h" +#include "mirall/clientproxy.h" + +#include #include #include @@ -40,6 +43,7 @@ namespace Mirall { class FolderWatcher; + typedef enum SyncFileStatus_s { FILE_STATUS_NONE, FILE_STATUS_EVAL, @@ -188,7 +192,7 @@ private: void setIgnoredFiles(); - void setProxy(); + const char* proxyTypeToCStr(QNetworkProxy::ProxyType type); void bubbleUpSyncResult(); @@ -219,6 +223,8 @@ private: SyncJournalDb _journal; + ClientProxy _clientProxy; + CSYNC *_csync_ctx; const char *_proxy_type; diff --git a/src/mirall/generalsettings.h b/src/mirall/generalsettings.h index 16487de8e8..50dfd7a6ff 100644 --- a/src/mirall/generalsettings.h +++ b/src/mirall/generalsettings.h @@ -31,9 +31,6 @@ public: explicit GeneralSettings(QWidget *parent = 0); ~GeneralSettings(); -signals: - void proxySettingsChanged(); - private slots: void saveMiscSettings(); void slotToggleLaunchOnStartup(bool); diff --git a/src/mirall/networksettings.cpp b/src/mirall/networksettings.cpp index df1456b434..82a8cb163e 100644 --- a/src/mirall/networksettings.cpp +++ b/src/mirall/networksettings.cpp @@ -19,6 +19,7 @@ #include "mirall/application.h" #include "mirall/utility.h" #include "mirall/mirallconfigfile.h" +#include "mirall/folderman.h" #include @@ -138,7 +139,13 @@ void NetworkSettings::saveProxySettings() _ui->portSpinBox->value(), needsAuth, user, pass); } - emit proxySettingsChanged(); + ClientProxy proxy; + proxy.setupQtProxyFromConfig(); // Refresh the Qt proxy settings as the + // quota check can happen all the time. + + // ...and set the folders dirty, they refresh their proxy next time they + // start the sync. + FolderMan::instance()->setDirtyProxy(true); } void NetworkSettings::saveBWLimitSettings() diff --git a/src/mirall/networksettings.h b/src/mirall/networksettings.h index 9788ba554e..cb93e37826 100644 --- a/src/mirall/networksettings.h +++ b/src/mirall/networksettings.h @@ -31,9 +31,6 @@ public: explicit NetworkSettings(QWidget *parent = 0); ~NetworkSettings(); -signals: - void proxySettingsChanged(); - private slots: void saveProxySettings(); void saveBWLimitSettings(); diff --git a/src/mirall/settingsdialog.cpp b/src/mirall/settingsdialog.cpp index 7ce4d278f5..a6ad791c3d 100644 --- a/src/mirall/settingsdialog.cpp +++ b/src/mirall/settingsdialog.cpp @@ -73,7 +73,6 @@ SettingsDialog::SettingsDialog(ownCloudGui *gui, QWidget *parent) : _ui->labelWidget->addItem(network); NetworkSettings *networkSettings = new NetworkSettings; _ui->stack->addWidget(networkSettings); - connect(networkSettings, SIGNAL(proxySettingsChanged()), gui, SIGNAL(setupProxy())); FolderMan *folderMan = FolderMan::instance(); connect( folderMan, SIGNAL(folderSyncStateChange(QString)),