From a771281f6b4cd44131449c12653a9ddda781d08d Mon Sep 17 00:00:00 2001 From: zhangyuanyuan1 Date: Tue, 29 Aug 2023 11:47:28 +0800 Subject: [PATCH] =?UTF-8?q?perf(plugins):=20=E8=B0=83=E6=95=B4=E6=8E=A7?= =?UTF-8?q?=E5=88=B6=E9=9D=A2=E6=9D=BF=E7=95=8C=E9=9D=A2=E5=8D=95=E7=BD=91?= =?UTF-8?q?=E5=8D=A1=E6=98=BE=E7=A4=BA(story#18148)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/netconnect/netconnect.cpp | 71 ++++++++++++++++++++++++++- plugins/netconnect/netconnect.h | 3 ++ plugins/wlanconnect/wlanconnect.cpp | 76 +++++++++++++++++++++++++++-- plugins/wlanconnect/wlanconnect.h | 3 +- 4 files changed, 147 insertions(+), 6 deletions(-) diff --git a/plugins/netconnect/netconnect.cpp b/plugins/netconnect/netconnect.cpp index 6dae527c..303edcd9 100644 --- a/plugins/netconnect/netconnect.cpp +++ b/plugins/netconnect/netconnect.cpp @@ -83,6 +83,16 @@ NetConnect::NetConnect() : mFirstLoad(true) { pluginName = tr("LAN"); pluginType = NETWORK; + + m_interface = new QDBusInterface("com.kylin.network", + "/com/kylin/network", + "com.kylin.network", + QDBusConnection::sessionBus()); + if(!m_interface->isValid()) { + qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message()); + } + updatePluginShowSettings(); + connect(m_interface, SIGNAL(deviceStatusChanged()), this, SLOT(updatePluginShowSettings()),Qt::QueuedConnection); } NetConnect::~NetConnect() { @@ -110,6 +120,7 @@ QWidget *NetConnect::pluginUi() { pluginWidget = new QWidget; pluginWidget->setAttribute(Qt::WA_DeleteOnClose); ui->setupUi(pluginWidget); + m_interface = new QDBusInterface("com.kylin.network", "/com/kylin/network", "com.kylin.network", @@ -117,6 +128,9 @@ QWidget *NetConnect::pluginUi() { if(!m_interface->isValid()) { qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message()); } + + qDBusRegisterMetaType>(); + initSearchText(); initComponent(); } @@ -130,7 +144,54 @@ const QString NetConnect::name() const { bool NetConnect::isEnable() const { - return true; + //get isEnable + QDBusInterface dbus("com.kylin.network", "/com/kylin/network", + "com.kylin.network", + QDBusConnection::sessionBus()); + if (!dbus.isValid()) { + return false; + } + + QMap map; + QDBusReply reply = dbus.call(QStringLiteral("getDeviceListAndEnabled"),0); + if(!reply.isValid()) + { + qWarning() << "[NetConnect]getWiredDeviceList error:" << reply.error().message(); + return false; + } + + QVariantMap::const_iterator item = reply.value().cbegin(); + while (item != reply.value().cend()) { + map.insert(item.key(), item.value().toBool()); + item ++; + } + + bool isEnabled = !map.isEmpty(); + + const QByteArray schema("org.ukui.control-center.plugins"); + if (QGSettings::isSchemaInstalled(schema)) { + return isEnabled; + } + + //get gsettings + QGSettings *showSettings; + QString path("/org/ukui/control-center/plugins/netconnect/"); + showSettings = new QGSettings(schema, path.toUtf8()); + + QVariant enabledState = showSettings->get("show"); + + //set gsettings + if (!enabledState.isValid() || enabledState.isNull()) { + qWarning() << "QGSettins get plugin show status error"; + } else { + if (enabledState.toBool() != isEnabled) { + showSettings->set("show", isEnabled); + } + } + delete showSettings; + showSettings = nullptr; + + return isEnabled; } @@ -154,7 +215,8 @@ void NetConnect::initSearchText() { ui->detailBtn->setText(tr("Advanced settings")); ui->titleLabel->setText(tr("LAN")); //~ contents_path /netconnect/open - ui->openLabel->setText(tr("open")); + tr("open"); + ui->openLabel->setText(tr("LAN")); } bool NetConnect::eventFilter(QObject *w, QEvent *e) { @@ -934,3 +996,8 @@ QMap> NetConnect::getWiredList() } return map; } + +void NetConnect::updatePluginShowSettings() +{ + isEnable(); +} diff --git a/plugins/netconnect/netconnect.h b/plugins/netconnect/netconnect.h index 1e94d05e..35fc9514 100644 --- a/plugins/netconnect/netconnect.h +++ b/plugins/netconnect/netconnect.h @@ -156,6 +156,9 @@ private slots: void onDeviceStatusChanged(); void onDeviceNameChanged(QString, QString, int); + + //更新控制面板插件Gsetting show + void updatePluginShowSettings(); }; Q_DECLARE_METATYPE(QList); diff --git a/plugins/wlanconnect/wlanconnect.cpp b/plugins/wlanconnect/wlanconnect.cpp index facdec20..4b794241 100644 --- a/plugins/wlanconnect/wlanconnect.cpp +++ b/plugins/wlanconnect/wlanconnect.cpp @@ -139,6 +139,15 @@ WlanConnect::WlanConnect() : m_firstLoad(true) { pluginName = tr("WLAN"); pluginType = NETWORK; + + m_interface = new QDBusInterface("com.kylin.network", "/com/kylin/network", + "com.kylin.network", + QDBusConnection::sessionBus()); + if(!m_interface->isValid()) { + qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message()); + } + updatePluginShowSettings(); + connect(m_interface, SIGNAL(wirelessDeviceStatusChanged()), this, SLOT(updatePluginShowSettings()), Qt::QueuedConnection); } WlanConnect::~WlanConnect() @@ -167,13 +176,14 @@ QWidget *WlanConnect::pluginUi() { pluginWidget->setAttribute(Qt::WA_DeleteOnClose); ui->setupUi(pluginWidget); qDBusRegisterMetaType>(); - qDBusRegisterMetaType(); + qDBusRegisterMetaType(); m_interface = new QDBusInterface("com.kylin.network", "/com/kylin/network", "com.kylin.network", QDBusConnection::sessionBus()); if(!m_interface->isValid()) { qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message()); } + initSearchText(); initComponent(); } @@ -187,7 +197,61 @@ const QString WlanConnect::name() const { bool WlanConnect::isEnable() const { - return true; + //get isEnable + QDBusInterface dbus("com.kylin.network", "/com/kylin/network", + "com.kylin.network", + QDBusConnection::sessionBus()); + if (!dbus.isValid()) { + return false; + } + QMap map; + QDBusReply reply = dbus.call(QStringLiteral("getDeviceListAndEnabled"), 1); + if(!reply.isValid()) + { + qWarning() << "[NetConnect]getWiredDeviceList error:" << reply.error().message(); + return false; + } + + QVariantMap::const_iterator item = reply.value().cbegin(); + while (item != reply.value().cend()) { + map.insert(item.key(), item.value().toBool()); + item ++; + } + //筛选已托管(managed)网卡 + QStringList list; + QMap::iterator iters; + for (iters = map.begin(); iters != map.end(); ++iters) { + if (iters.value() == true) { + list << iters.key(); + } + } + + bool isEnabled = !list.isEmpty(); + + const QByteArray schema("org.ukui.control-center.plugins"); + if (QGSettings::isSchemaInstalled(schema)) { + return isEnabled; + } + + //get gsettings + QGSettings *showSettings; + QString path("/org/ukui/control-center/plugins/wlanconnect/"); + showSettings = new QGSettings(schema, path.toUtf8()); + + QVariant enabledState = showSettings->get("show"); + + //set gsettings + if (!enabledState.isValid() || enabledState.isNull()) { + qWarning() << "QGSettins get plugin show status error"; + } else { + if (enabledState.toBool() != isEnabled) { + showSettings->set("show", isEnabled); + } + } + delete showSettings; + showSettings = nullptr; + + return isEnabled; } @@ -211,7 +275,8 @@ void WlanConnect::initSearchText() { ui->detailBtn->setText(tr("Advanced settings")); ui->titleLabel->setText(tr("WLAN")); //~ contents_path /wlanconnect/open - ui->openLabel->setText(tr("open")); + tr("open"); + ui->openLabel->setText(tr("WLAN")); } bool WlanConnect::eventFilter(QObject *w, QEvent *e) { @@ -1133,3 +1198,8 @@ QMap> WlanConnect::getWirelessList() return map; } +void WlanConnect::updatePluginShowSettings() +{ + isEnable(); +} + diff --git a/plugins/wlanconnect/wlanconnect.h b/plugins/wlanconnect/wlanconnect.h index a822a658..249d6431 100644 --- a/plugins/wlanconnect/wlanconnect.h +++ b/plugins/wlanconnect/wlanconnect.h @@ -194,6 +194,7 @@ private slots: void reScan(); - + //更新控制面板插件Gsetting show + void updatePluginShowSettings(); }; #endif // WLANCONNECT_H