Skip to content

Commit 38ece2e

Browse files
committed
dbhub: Add proxy configuration support
This adds a new dialog, accessible from the Remote tab in the Preferences Dialog, which allows the user to configure the proxy to use for all network connections. The new default is to use the system-wide proxy settings. See issue #979.
1 parent 4cf6cb7 commit 38ece2e

File tree

10 files changed

+397
-7
lines changed

10 files changed

+397
-7
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ set(SQLB_MOC_HDR
158158
src/Palette.h
159159
src/CondFormat.h
160160
src/RunSql.h
161+
src/ProxyDialog.h
161162
)
162163

163164
set(SQLB_SRC
@@ -211,6 +212,7 @@ set(SQLB_SRC
211212
src/Palette.cpp
212213
src/CondFormat.cpp
213214
src/RunSql.cpp
215+
src/ProxyDialog.cpp
214216
)
215217

216218
set(SQLB_FORMS
@@ -234,6 +236,7 @@ set(SQLB_FORMS
234236
src/FindReplaceDialog.ui
235237
src/FileExtensionManager.ui
236238
src/CondFormatManager.ui
239+
src/ProxyDialog.ui
237240
)
238241

239242
set(SQLB_RESOURCES

src/PreferencesDialog.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "MainWindow.h"
77
#include "RemoteDatabase.h"
88
#include "FileExtensionManager.h"
9+
#include "ProxyDialog.h"
910

1011
#include <QDir>
1112
#include <QColorDialog>
@@ -16,6 +17,7 @@
1617
PreferencesDialog::PreferencesDialog(QWidget* parent, Tabs tab)
1718
: QDialog(parent),
1819
ui(new Ui::PreferencesDialog),
20+
m_proxyDialog(new ProxyDialog(this)),
1921
m_dbFileExtensions(Settings::getValue("General", "DBFileExtensions").toString().split(";;"))
2022
{
2123
ui->setupUi(this);
@@ -326,6 +328,8 @@ void PreferencesDialog::saveSettings()
326328

327329
Settings::setValue("General", "DBFileExtensions", m_dbFileExtensions.join(";;") );
328330

331+
m_proxyDialog->saveSettings();
332+
329333
accept();
330334

331335
QApplication::restoreOverrideCursor();
@@ -672,3 +676,8 @@ void PreferencesDialog::on_buttonBox_clicked(QAbstractButton* button)
672676
}
673677
}
674678
}
679+
680+
void PreferencesDialog::configureProxy()
681+
{
682+
m_proxyDialog->show();
683+
}

src/PreferencesDialog.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ class QFrame;
88
class QSslCertificate;
99
class QAbstractButton;
1010

11+
class ProxyDialog;
12+
1113
namespace Ui {
1214
class PreferencesDialog;
1315
}
@@ -44,12 +46,15 @@ private slots:
4446
void chooseRemoteCloneDirectory();
4547
void updatePreviewFont();
4648
void adjustColorsToStyle(int style);
49+
void configureProxy();
4750

4851
void on_buttonManageFileExtension_clicked();
4952
void on_buttonBox_clicked(QAbstractButton* button);
5053

5154
private:
52-
Ui::PreferencesDialog *ui;
55+
Ui::PreferencesDialog* ui;
56+
57+
ProxyDialog* m_proxyDialog;
5358

5459
QStringList m_dbFileExtensions;
5560

src/PreferencesDialog.ui

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,14 +1788,14 @@ Can be set to 0 for disabling completion.</string>
17881788
</item>
17891789
<item>
17901790
<layout class="QFormLayout" name="formLayout_5">
1791-
<item row="0" column="0">
1791+
<item row="1" column="0">
17921792
<widget class="QLabel" name="label_23">
17931793
<property name="text">
17941794
<string>Clone databases into</string>
17951795
</property>
17961796
</widget>
17971797
</item>
1798-
<item row="0" column="1">
1798+
<item row="1" column="1">
17991799
<layout class="QHBoxLayout" name="horizontalLayout_4">
18001800
<item>
18011801
<widget class="QLineEdit" name="editRemoteCloneDirectory">
@@ -1825,6 +1825,20 @@ Can be set to 0 for disabling completion.</string>
18251825
</item>
18261826
</layout>
18271827
</item>
1828+
<item row="0" column="0">
1829+
<widget class="QLabel" name="label_21">
1830+
<property name="text">
1831+
<string>Proxy</string>
1832+
</property>
1833+
</widget>
1834+
</item>
1835+
<item row="0" column="1">
1836+
<widget class="QToolButton" name="buttonProxy">
1837+
<property name="text">
1838+
<string>Configure</string>
1839+
</property>
1840+
</widget>
1841+
</item>
18281842
</layout>
18291843
</item>
18301844
</layout>
@@ -2099,6 +2113,22 @@ Can be set to 0 for disabling completion.</string>
20992113
</hint>
21002114
</hints>
21012115
</connection>
2116+
<connection>
2117+
<sender>buttonProxy</sender>
2118+
<signal>clicked()</signal>
2119+
<receiver>PreferencesDialog</receiver>
2120+
<slot>configureProxy()</slot>
2121+
<hints>
2122+
<hint type="sourcelabel">
2123+
<x>385</x>
2124+
<y>591</y>
2125+
</hint>
2126+
<hint type="destinationlabel">
2127+
<x>385</x>
2128+
<y>306</y>
2129+
</hint>
2130+
</hints>
2131+
</connection>
21022132
</connections>
21032133
<slots>
21042134
<slot>saveSettings()</slot>
@@ -2110,5 +2140,6 @@ Can be set to 0 for disabling completion.</string>
21102140
<slot>addClientCertificate()</slot>
21112141
<slot>removeClientCertificate()</slot>
21122142
<slot>chooseRemoteCloneDirectory()</slot>
2143+
<slot>configureProxy()</slot>
21132144
</slots>
21142145
</ui>

src/ProxyDialog.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#include "ProxyDialog.h"
2+
#include "ui_ProxyDialog.h"
3+
#include "Settings.h"
4+
5+
ProxyDialog::ProxyDialog(QWidget *parent) :
6+
QDialog(parent),
7+
ui(new Ui::ProxyDialog)
8+
{
9+
ui->setupUi(this);
10+
11+
// Add different proxy types. We use user data strings for addressing them later
12+
ui->comboType->addItem(tr("None"), "none");
13+
ui->comboType->addItem(tr("System settings"), "system");
14+
ui->comboType->addItem(tr("HTTP"), "http");
15+
ui->comboType->addItem(tr("Socks v5"), "socks5");
16+
17+
// Load current settings
18+
ui->comboType->setCurrentIndex(ui->comboType->findData(Settings::getValue("proxy", "type").toString()));
19+
ui->editHost->setText(Settings::getValue("proxy", "host").toString());
20+
ui->spinPort->setValue(Settings::getValue("proxy", "port").toInt());
21+
ui->checkAuthentication->setChecked(Settings::getValue("proxy", "authentication").toBool());
22+
ui->editUser->setText(Settings::getValue("proxy", "user").toString());
23+
ui->editPassword->setText(Settings::getValue("proxy", "password").toString());
24+
}
25+
26+
ProxyDialog::~ProxyDialog()
27+
{
28+
delete ui;
29+
}
30+
31+
void ProxyDialog::proxyTypeChanged(int /*new_index*/)
32+
{
33+
// When selecting the "None" or "System settings" proxy types, disable all the other input fields
34+
bool proxy_configuration = (ui->comboType->currentData() != "none" && ui->comboType->currentData() != "system");
35+
36+
ui->editHost->setEnabled(proxy_configuration);
37+
ui->spinPort->setEnabled(proxy_configuration);
38+
ui->checkAuthentication->setEnabled(proxy_configuration);
39+
ui->editUser->setEnabled(ui->checkAuthentication->isChecked() && proxy_configuration); // Enable user name and password only if the...
40+
ui->editPassword->setEnabled(ui->checkAuthentication->isChecked() && proxy_configuration); // ... Authentication Required checkbox is checked
41+
}
42+
43+
void ProxyDialog::authenticationRequiredChanged(bool required)
44+
{
45+
ui->editUser->setEnabled(required);
46+
ui->editPassword->setEnabled(required);
47+
}
48+
49+
void ProxyDialog::saveSettings() const
50+
{
51+
Settings::setValue("proxy", "type", ui->comboType->currentData());
52+
Settings::setValue("proxy", "host", ui->editHost->text());
53+
Settings::setValue("proxy", "port", ui->spinPort->value());
54+
Settings::setValue("proxy", "authentication", ui->checkAuthentication->isChecked());
55+
Settings::setValue("proxy", "user", ui->editUser->text());
56+
Settings::setValue("proxy", "password", ui->editPassword->text());
57+
}

src/ProxyDialog.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#ifndef PROXYDIALOG_H
2+
#define PROXYDIALOG_H
3+
4+
#include <QDialog>
5+
6+
namespace Ui {
7+
class ProxyDialog;
8+
}
9+
10+
class ProxyDialog : public QDialog
11+
{
12+
Q_OBJECT
13+
14+
public:
15+
explicit ProxyDialog(QWidget* parent = nullptr);
16+
~ProxyDialog();
17+
18+
void saveSettings() const;
19+
20+
private slots:
21+
void proxyTypeChanged(int new_index);
22+
void authenticationRequiredChanged(bool required);
23+
24+
private:
25+
Ui::ProxyDialog* ui;
26+
};
27+
28+
#endif

0 commit comments

Comments
 (0)