mirror of
https://github.com/nextcloud/desktop.git
synced 2025-10-26 11:17:43 +00:00
Make use of the new Proxy handling class.
This commit is contained in:
parent
671100ce5c
commit
ec9efd7894
@ -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 <windows.h>
|
||||
#endif
|
||||
|
||||
#include <QTranslator>
|
||||
#include <QNetworkProxy>
|
||||
#include <QNetworkProxyFactory>
|
||||
#include <QMenu>
|
||||
#include <QMessageBox>
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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<QMessageBox> _connectionMsgBox;
|
||||
|
||||
ClientProxy _proxy;
|
||||
|
||||
friend class ownCloudGui; // for _startupNetworkError
|
||||
};
|
||||
|
||||
|
||||
@ -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<QNetworkProxy> 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<char*>(_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.";
|
||||
|
||||
@ -21,6 +21,9 @@
|
||||
#include "mirall/progressdispatcher.h"
|
||||
#include "mirall/csyncthread.h"
|
||||
#include "mirall/syncjournaldb.h"
|
||||
#include "mirall/clientproxy.h"
|
||||
|
||||
#include <csync.h>
|
||||
|
||||
#include <QDir>
|
||||
#include <QHash>
|
||||
@ -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;
|
||||
|
||||
@ -31,9 +31,6 @@ public:
|
||||
explicit GeneralSettings(QWidget *parent = 0);
|
||||
~GeneralSettings();
|
||||
|
||||
signals:
|
||||
void proxySettingsChanged();
|
||||
|
||||
private slots:
|
||||
void saveMiscSettings();
|
||||
void slotToggleLaunchOnStartup(bool);
|
||||
|
||||
@ -19,6 +19,7 @@
|
||||
#include "mirall/application.h"
|
||||
#include "mirall/utility.h"
|
||||
#include "mirall/mirallconfigfile.h"
|
||||
#include "mirall/folderman.h"
|
||||
|
||||
#include <QNetworkProxy>
|
||||
|
||||
@ -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()
|
||||
|
||||
@ -31,9 +31,6 @@ public:
|
||||
explicit NetworkSettings(QWidget *parent = 0);
|
||||
~NetworkSettings();
|
||||
|
||||
signals:
|
||||
void proxySettingsChanged();
|
||||
|
||||
private slots:
|
||||
void saveProxySettings();
|
||||
void saveBWLimitSettings();
|
||||
|
||||
@ -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)),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user