Skip to content

Commit

Permalink
fix: Modifying configuration errors can also set proxy issues
Browse files Browse the repository at this point in the history
When configuring incorrectly, setting the proxy did not take effect, resulting in asynchronous network proxy status on the taskbar

Issue: linuxdeepin/developer-center#9983
  • Loading branch information
caixr23 authored and deepin-bot[bot] committed Jul 26, 2024
1 parent f5aa55d commit 2091b96
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
22 changes: 20 additions & 2 deletions dcc-network-plugin/window/sysproxymodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ SysProxyModule::SysProxyModule(QObject *parent)
if (checked) {
uiMethodChanged(m_lastCombIndex == 0 ? ProxyMethod::Manual : ProxyMethod::Auto);
m_proxyTypeBox->comboBox()->setCurrentIndex(m_lastCombIndex);
checkConf();
} else {
// 关闭代理
NetworkController::instance()->proxyController()->setProxyMethod(ProxyMethod::None);
Expand Down Expand Up @@ -97,6 +98,7 @@ SysProxyModule::SysProxyModule(QObject *parent)
uiMethodChanged(ProxyMethod::Manual);
break;
}
checkConf();
m_buttonTuple->setEnabled(true);
});
}));
Expand All @@ -107,6 +109,7 @@ SysProxyModule::SysProxyModule(QObject *parent)
m_autoUrl->textEdit()->installEventFilter(this);
ProxyController *proxyController = NetworkController::instance()->proxyController();
connect(proxyController, &ProxyController::autoProxyChanged, m_autoUrl, &LineEditWidget::setText);
connect(m_autoUrl->textEdit(), &QLineEdit::textChanged, this, &SysProxyModule::checkConf);
autoGroup->appendItem(m_autoUrl);
resetData(ProxyMethod::Auto);
}));
Expand All @@ -119,6 +122,7 @@ SysProxyModule::SysProxyModule(QObject *parent)
m_buttonTuple->rightButton()->setText(tr("Save", "button"));
m_buttonTuple->setVisible(NetworkController::instance()->proxyController()->proxyMethod() != ProxyMethod::None);
m_buttonTuple->setEnabled(false);
checkConf();

connect(m_buttonTuple->rightButton(), &QPushButton::clicked, this, [this] {
m_lastCombIndex = m_proxyTypeBox->comboBox()->currentIndex();
Expand Down Expand Up @@ -160,7 +164,9 @@ void SysProxyModule::deactive()
m_socksPort = nullptr;
m_ignoreList = nullptr;
m_buttonTuple = nullptr;
uiMethodChanged(NetworkController::instance()->proxyController()->proxyMethod());
QTimer::singleShot(1, this, [this]() {
uiMethodChanged(NetworkController::instance()->proxyController()->proxyMethod());
});
}

void SysProxyModule::initManualView(QWidget *w)
Expand All @@ -177,13 +183,14 @@ void SysProxyModule::initManualView(QWidget *w)
portEdit->textEdit()->installEventFilter(this);
group->appendItem(proxyEdit);
group->appendItem(portEdit);
connect(portEdit->textEdit(), &QLineEdit::textChanged, this, [=](const QString &str) {
connect(portEdit->textEdit(), &QLineEdit::textChanged, this, [portEdit](const QString &str) {
if (str.toInt() < 0) {
portEdit->setText("0");
} else if (str.toInt() > 65535) {
portEdit->setText("65535");
}
});
connect(proxyEdit->textEdit(), &QLineEdit::textChanged, this, &SysProxyModule::checkConf);
};

// 手动代理编辑界面控件初始化
Expand Down Expand Up @@ -324,6 +331,17 @@ void SysProxyModule::resetData(ProxyMethod uiMethod)
}
}

void SysProxyModule::checkConf()
{
if (!m_proxyTypeBox || !m_buttonTuple)
return;
if (m_proxyTypeBox->comboBox()->currentIndex() == ProxyMethodIndex_Manual) {
m_buttonTuple->rightButton()->setEnabled(!m_httpAddr->text().isEmpty() || !m_httpsAddr->text().isEmpty() || !m_ftpAddr->text().isEmpty() || !m_socksAddr->text().isEmpty());
} else if (m_proxyTypeBox->comboBox()->currentIndex() == ProxyMethodIndex_Auto) {
m_buttonTuple->rightButton()->setEnabled(!m_autoUrl->text().isEmpty());
}
}

bool SysProxyModule::eventFilter(QObject *watched, QEvent *event)
{
// 实现鼠标点击编辑框,确定按钮激活,捕捉FocusIn消息,DTextEdit没有鼠标点击消息
Expand Down
1 change: 1 addition & 0 deletions dcc-network-plugin/window/sysproxymodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ private Q_SLOTS:
void applySettings();
void uiMethodChanged(dde::network::ProxyMethod uiMethod);
void resetData(dde::network::ProxyMethod uiMethod);
void checkConf();

private:
virtual bool eventFilter(QObject *watched, QEvent *event) override;
Expand Down

0 comments on commit 2091b96

Please sign in to comment.