控制面板插件 代理前端代码增加dbus判空

This commit is contained in:
zhangyuanyuan1 2023-01-31 15:57:48 +08:00
parent e4336c606d
commit 95ae318fc5
3 changed files with 30 additions and 15 deletions

View File

@ -29,7 +29,7 @@ AppListWidget::AppListWidget(QString path, QWidget *parent)
AppListWidget::~AppListWidget()
{
delete m_dbusInterface;
}
/**
@ -79,8 +79,9 @@ void AppListWidget::onAppCheckStateChanged()
*/
void AppListWidget::AddAppProxyConfig()
{
if(!m_dbusInterface->isValid()) {
if(m_dbusInterface == nullptr || !m_dbusInterface->isValid()) {
qWarning ()<< "init AppProxy dbus error";
return;
}
qDebug() << "call QDBusInterface addAppIntoProxy";
@ -93,8 +94,9 @@ void AppListWidget::AddAppProxyConfig()
*/
void AppListWidget::RemoveAppProxyConfig()
{
if(!m_dbusInterface->isValid()) {
if(m_dbusInterface == nullptr || !m_dbusInterface->isValid()) {
qWarning ()<< "init AppProxy dbus error";
return;
}
qDebug() << "call QDBusInterface delAppIntoProxy";
@ -135,4 +137,7 @@ void AppListWidget::initDbus()
"/org/ukui/SettingsDaemon/AppProxy",
"org.ukui.SettingsDaemon.AppProxy",
QDBusConnection::sessionBus());
if(!m_dbusInterface->isValid()) {
qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message());
}
}

View File

@ -68,6 +68,7 @@ Proxy::~Proxy()
{
if (!mFirstLoad) {
plugin_leave();
delete m_appProxyDbus;
}
}
@ -702,6 +703,9 @@ void Proxy::initDbus()
"/org/ukui/SettingsDaemon/AppProxy",
"org.ukui.SettingsDaemon.AppProxy",
QDBusConnection::sessionBus());
if(!m_appProxyDbus->isValid()) {
qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message());
}
}
void Proxy::initAppProxyStatus()
@ -752,9 +756,12 @@ void Proxy::setAptProxy(QString host, QString port, bool status)
"/",
"com.control.center.interface",
QDBusConnection::systemBus());
if (mAptproxyDbus->isValid())
if (mAptproxyDbus->isValid()) {
QDBusReply<bool> reply = mAptproxyDbus->call("setaptproxy", host, port , status);
}
delete mAptproxyDbus;
mAptproxyDbus = nullptr;
}
QHash<QString, QVariant> Proxy::getAptProxy()
{
@ -786,6 +793,8 @@ QHash<QString, QVariant> Proxy::getAptProxy()
mAptInfo.insert(it.arg, it.out.variant());
}
}
delete mAptproxyDbus;
mAptproxyDbus = nullptr;
return mAptInfo;
}
@ -814,8 +823,9 @@ void Proxy::reboot()
"/org/gnome/SessionManager",
"org.gnome.SessionManager",
QDBusConnection::sessionBus());
if (rebootDbus->isValid()) {
rebootDbus->call("reboot");
}
delete rebootDbus;
rebootDbus = nullptr;
}
@ -841,8 +851,9 @@ QFrame *Proxy::setLine(QFrame *frame)
bool Proxy::getAppProxyState()
{
bool state = true;
if(!m_appProxyDbus->isValid()) {
if(m_appProxyDbus == nullptr || !m_appProxyDbus->isValid()) {
qWarning ()<< "init AppProxy dbus error";
return false;
}
//获取应用代理开启状态
@ -859,7 +870,7 @@ bool Proxy::getAppProxyState()
void Proxy::setAppProxyState(bool state)
{
if(!m_appProxyDbus->isValid()) {
if(m_appProxyDbus == nullptr || !m_appProxyDbus->isValid()) {
qWarning ()<< "init AppProxy dbus error";
return;
}
@ -881,6 +892,7 @@ QStringList Proxy::getAppProxyConf()
if(!dbusInterface.isValid()) {
qWarning ()<< "init AppProxy dbus error";
return info;
}
//获取应用代理配置信息
@ -903,11 +915,12 @@ QStringList Proxy::getAppProxyConf()
void Proxy::setAppProxyConf(QStringList list)
{
//AppProxyConf 必填项数量为3
if (list.count() < 3) {
return;
}
if(!m_appProxyDbus->isValid()) {
if(m_appProxyDbus == nullptr || !m_appProxyDbus->isValid()) {
qWarning ()<< "init AppProxy dbus error";
return;
}
@ -1244,7 +1257,6 @@ void Proxy::onAppProxyConfChanged()
{
if (!getipEditState(m_ipAddressLineEdit->text()) || m_portLineEdit->text().isEmpty()) {
return;
qDebug() << "onAppProxyConfChanged return";
}
if (m_ipAddressLineEdit->text().isEmpty()) {
@ -1261,8 +1273,6 @@ void Proxy::onAppProxyConfChanged()
m_appProxyInfo.append("");
m_appProxyInfo.append("");
}
qDebug() << m_appProxyInfo << Q_FUNC_INFO << __LINE__;
}
}

View File

@ -262,8 +262,8 @@ private:
QFileSystemWatcher *mfileWatch_1;
QFileSystemWatcher *mfileWatch_2;
QDBusInterface *mAptproxyDbus;
QDBusInterface *m_appProxyDbus;
// QDBusInterface *mAptproxyDbus;
QDBusInterface *m_appProxyDbus = nullptr;
bool isExistSettings = false;
bool settingsCreate;