Finished proxy

pull/55/head
reionwong 4 years ago
parent cfa63637e7
commit e1e83fbfdd

@ -1,4 +1,7 @@
#include "networkproxy.h"
#include <QDBusInterface>
#include <QDBusPendingCall>
#include <QTimer>
NetworkProxy::NetworkProxy(QObject *parent)
: QObject(parent)
@ -25,6 +28,7 @@ void NetworkProxy::setFlag(int flag)
if (m_flag != flag) {
m_flag = flag;
m_settings.setValue("ProxyFlag", flag);
delayUpdateProxy();
emit flagChanged();
}
}
@ -39,6 +43,7 @@ void NetworkProxy::setUseSameProxy(bool enabled)
if (m_useSameProxy != enabled) {
m_useSameProxy = enabled;
m_settings.setValue("UseSameProxy", enabled);
delayUpdateProxy();
emit useSameProxyChanged();
}
}
@ -53,6 +58,7 @@ void NetworkProxy::setScriptProxy(const QString &path)
if (m_scriptProxy != path) {
m_scriptProxy = path;
m_settings.setValue("ProxyScriptProxy", path);
delayUpdateProxy();
emit scriptProxyChanged();
}
}
@ -67,6 +73,7 @@ void NetworkProxy::setHttpProxy(const QString &path)
if (m_httpProxy != path) {
m_httpProxy = path;
m_settings.setValue("HttpProxy", path);
delayUpdateProxy();
emit httpProxyChanged();
}
}
@ -81,6 +88,7 @@ void NetworkProxy::setFtpProxy(const QString &path)
if (m_ftpProxy != path) {
m_ftpProxy = path;
m_settings.setValue("FtpProxy", path);
delayUpdateProxy();
emit ftpProxyChanged();
}
}
@ -95,6 +103,7 @@ void NetworkProxy::setSocksProxy(const QString &path)
if (m_socksProxy != path) {
m_socksProxy = path;
m_settings.setValue("SocksProxy", path);
delayUpdateProxy();
emit socksProxyChanged();
}
}
@ -109,6 +118,7 @@ void NetworkProxy::setHttpProxyPort(const QString &port)
if (m_httpProxyPort != port) {
m_httpProxyPort = port;
m_settings.setValue("HttpProxyPort", port);
delayUpdateProxy();
emit httpProxyPortChanged();
}
}
@ -123,6 +133,7 @@ void NetworkProxy::setFtpProxyPort(const QString &port)
if (m_ftpProxyPort != port) {
m_ftpProxyPort = port;
m_settings.setValue("FtpProxyPort", port);
delayUpdateProxy();
emit ftpProxyPortChanged();
}
}
@ -137,6 +148,21 @@ void NetworkProxy::setSocksProxyPort(const QString &port)
if (m_socksProxyPort != port) {
m_socksProxyPort = port;
m_settings.setValue("SocksProxyPort", port);
delayUpdateProxy();
emit socksProxyPortChanged();
}
}
void NetworkProxy::updateProxy()
{
QDBusInterface iface("com.cutefish.Session", "/Session", "com.cutefish.Session");
if (iface.isValid()) {
iface.asyncCall("updateNetworkProxy");
}
}
void NetworkProxy::delayUpdateProxy()
{
QTimer::singleShot(50, this, &NetworkProxy::updateProxy);
}

@ -47,6 +47,9 @@ public:
QString socksProxyPort() const;
void setSocksProxyPort(const QString &port);
Q_INVOKABLE void updateProxy();
Q_INVOKABLE void delayUpdateProxy();
signals:
void flagChanged();
void useSameProxyChanged();

@ -72,37 +72,28 @@ ItemPage {
}
}
RadioButton {
id: autoDiscoverProxyRadioButton
checked: networkProxy.flag === 1
text: qsTr("Detect proxy configuration automatically")
onClicked: {
networkProxy.flag = 1
}
}
RadioButton {
id: autoScriptProxyRadioButton
checked: networkProxy.flag === 2
checked: networkProxy.flag === 1
text: qsTr("Use proxy auto configuration URL")
onClicked: {
networkProxy.flag = 2
networkProxy.flag = 1
}
}
RadioButton {
id: manualProxyRadioButton
checked: networkProxy.flag === 3
checked: networkProxy.flag === 2
text: qsTr("Use manually specified proxy configuration")
onClicked: {
networkProxy.flag = 3
networkProxy.flag = 2
}
}
}
RoundedItem {
id: proxyItem
visible: !noProxyRadioButton.checked && !autoDiscoverProxyRadioButton.checked
visible: !noProxyRadioButton.checked
RowLayout {
id: autoScriptProxyLayout
@ -143,6 +134,9 @@ ItemPage {
Layout.fillWidth: true
height: 40
text: networkProxy.httpProxy
validator: RegExpValidator {
regExp: /(?=(\b|\D))(((\d{1,2})|(1\d{1,2})|(2[0-4]\d)|(25[0-5]))\.){3}((\d{1,2})|(1\d{1,2})|(2[0-4]\d)|(25[0-5]))(?=(\b|\D))/
}
onEditingFinished: {
networkProxy.httpProxy = httpProxyField.text
@ -160,6 +154,8 @@ ItemPage {
text: networkProxy.httpProxyPort
validator: IntValidator { bottom: 0; top: 999999}
onEditingFinished: {
networkProxy.httpProxyPort = httpProxyPortField.text
}
@ -174,7 +170,9 @@ ItemPage {
text: qsTr("Also use this proxy for FTP")
Layout.fillWidth: true
checked: networkProxy.useSameProxy
onClicked: networkProxy.useSameProxy = forFtpCheckBox.checked
onClicked: {
networkProxy.useSameProxy = forFtpCheckBox.checked
}
}
Item {
@ -195,9 +193,10 @@ ItemPage {
Layout.fillWidth: true
height: 40
enabled: !forFtpCheckBox.checked
text: networkProxy.ftpProxy
validator: RegExpValidator {
regExp: /(?=(\b|\D))(((\d{1,2})|(1\d{1,2})|(2[0-4]\d)|(25[0-5]))\.){3}((\d{1,2})|(1\d{1,2})|(2[0-4]\d)|(25[0-5]))(?=(\b|\D))/
}
onEditingFinished: {
networkProxy.ftpProxy = ftpProxyTextField.text
}
@ -214,6 +213,7 @@ ItemPage {
enabled: !forFtpCheckBox.checked
text: networkProxy.ftpProxyPort
validator: IntValidator { bottom: 0; top: 999999}
onEditingFinished: {
networkProxy.ftpProxyPort = ftpProxyPortField.text
@ -230,6 +230,9 @@ ItemPage {
Layout.fillWidth: true
height: 40
validator: RegExpValidator {
regExp: /(?=(\b|\D))(((\d{1,2})|(1\d{1,2})|(2[0-4]\d)|(25[0-5]))\.){3}((\d{1,2})|(1\d{1,2})|(2[0-4]\d)|(25[0-5]))(?=(\b|\D))/
}
text: networkProxy.socksProxy
onEditingFinished: {
@ -247,6 +250,7 @@ ItemPage {
Layout.preferredWidth: 80
text: networkProxy.socksProxyPort
validator: IntValidator { bottom: 0; top: 999999}
onEditingFinished: {
networkProxy.socksProxyPort = socksProxyPortField.text

@ -704,48 +704,43 @@
</message>
<message>
<location filename="../src/qml/Proxy/Main.qml" line="78"/>
<source>Detect proxy configuration automatically</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/qml/Proxy/Main.qml" line="87"/>
<source>Use proxy auto configuration URL</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/qml/Proxy/Main.qml" line="96"/>
<location filename="../src/qml/Proxy/Main.qml" line="87"/>
<source>Use manually specified proxy configuration</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/qml/Proxy/Main.qml" line="124"/>
<location filename="../src/qml/Proxy/Main.qml" line="115"/>
<source>Select file</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/qml/Proxy/Main.qml" line="138"/>
<location filename="../src/qml/Proxy/Main.qml" line="129"/>
<source>HTTP Proxy</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/qml/Proxy/Main.qml" line="153"/>
<location filename="../src/qml/Proxy/Main.qml" line="207"/>
<location filename="../src/qml/Proxy/Main.qml" line="241"/>
<location filename="../src/qml/Proxy/Main.qml" line="144"/>
<location filename="../src/qml/Proxy/Main.qml" line="198"/>
<location filename="../src/qml/Proxy/Main.qml" line="232"/>
<source>Port</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/qml/Proxy/Main.qml" line="174"/>
<location filename="../src/qml/Proxy/Main.qml" line="165"/>
<source>Also use this proxy for FTP</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/qml/Proxy/Main.qml" line="190"/>
<location filename="../src/qml/Proxy/Main.qml" line="181"/>
<source>FTP Proxy</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/qml/Proxy/Main.qml" line="225"/>
<location filename="../src/qml/Proxy/Main.qml" line="216"/>
<source>SOCKS Proxy</source>
<translation type="unfinished"></translation>
</message>

@ -704,48 +704,43 @@
</message>
<message>
<location filename="../src/qml/Proxy/Main.qml" line="78"/>
<source>Detect proxy configuration automatically</source>
<translation></translation>
</message>
<message>
<location filename="../src/qml/Proxy/Main.qml" line="87"/>
<source>Use proxy auto configuration URL</source>
<translation>使 URL</translation>
</message>
<message>
<location filename="../src/qml/Proxy/Main.qml" line="96"/>
<location filename="../src/qml/Proxy/Main.qml" line="87"/>
<source>Use manually specified proxy configuration</source>
<translation>使</translation>
</message>
<message>
<location filename="../src/qml/Proxy/Main.qml" line="124"/>
<location filename="../src/qml/Proxy/Main.qml" line="115"/>
<source>Select file</source>
<translation></translation>
</message>
<message>
<location filename="../src/qml/Proxy/Main.qml" line="138"/>
<location filename="../src/qml/Proxy/Main.qml" line="129"/>
<source>HTTP Proxy</source>
<translation>HTTP </translation>
</message>
<message>
<location filename="../src/qml/Proxy/Main.qml" line="153"/>
<location filename="../src/qml/Proxy/Main.qml" line="207"/>
<location filename="../src/qml/Proxy/Main.qml" line="241"/>
<location filename="../src/qml/Proxy/Main.qml" line="144"/>
<location filename="../src/qml/Proxy/Main.qml" line="198"/>
<location filename="../src/qml/Proxy/Main.qml" line="232"/>
<source>Port</source>
<translation></translation>
</message>
<message>
<location filename="../src/qml/Proxy/Main.qml" line="174"/>
<location filename="../src/qml/Proxy/Main.qml" line="165"/>
<source>Also use this proxy for FTP</source>
<translation> FTP</translation>
</message>
<message>
<location filename="../src/qml/Proxy/Main.qml" line="190"/>
<location filename="../src/qml/Proxy/Main.qml" line="181"/>
<source>FTP Proxy</source>
<translation>FTP </translation>
</message>
<message>
<location filename="../src/qml/Proxy/Main.qml" line="225"/>
<location filename="../src/qml/Proxy/Main.qml" line="216"/>
<source>SOCKS Proxy</source>
<translation>SOCKS </translation>
</message>

Loading…
Cancel
Save