From a771281f6b4cd44131449c12653a9ddda781d08d Mon Sep 17 00:00:00 2001 From: zhangyuanyuan1 Date: Tue, 29 Aug 2023 11:47:28 +0800 Subject: [PATCH 1/3] =?UTF-8?q?perf(plugins):=20=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E6=8E=A7=E5=88=B6=E9=9D=A2=E6=9D=BF=E7=95=8C=E9=9D=A2=E5=8D=95?= =?UTF-8?q?=E7=BD=91=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 From 7ce857f0c848ae1446976f697765583cc587734a Mon Sep 17 00:00:00 2001 From: zhangyuanyuan1 Date: Sun, 8 Oct 2023 17:41:06 +0800 Subject: [PATCH 2/3] =?UTF-8?q?pref(=E6=89=98=E7=9B=98=E7=95=8C=E9=9D=A2):?= =?UTF-8?q?=20=E8=B0=83=E6=95=B4=E6=89=98=E7=9B=98=E7=95=8C=E9=9D=A2?= =?UTF-8?q?=E5=8D=95=E7=BD=91=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 --- src/frontend/mainwindow.cpp | 54 +++++++++++++++++++++++++++++++ src/frontend/mainwindow.h | 5 +++ src/frontend/tab-pages/lanpage.h | 4 +++ src/frontend/tab-pages/wlanpage.h | 4 +++ 4 files changed, 67 insertions(+) diff --git a/src/frontend/mainwindow.cpp b/src/frontend/mainwindow.cpp index 2696b29e..803a0e38 100644 --- a/src/frontend/mainwindow.cpp +++ b/src/frontend/mainwindow.cpp @@ -38,6 +38,7 @@ #define MAINWINDOW_HEIGHT 476 #define LAYOUT_MARGINS 0,0,0,0 #define LOADING_TRAYICON_TIMER_MS 60 +#define TABBAR_HEIGHT 30 #define THEME_SCHAME "org.ukui.style" #define COLOR_THEME "styleName" @@ -174,6 +175,11 @@ void MainWindow::firstlyStart() //加载key ring agent_init(); + + //单网卡显示 + setCentralWidgetPages(); + connect(m_lanWidget, &LanPage::deviceStatusChanged, this, &MainWindow::setCentralWidgetPages); + connect(m_wlanWidget, &LanPage::wirelessDeviceStatusChanged, this, &MainWindow::setCentralWidgetPages); } /** @@ -826,8 +832,56 @@ void MainWindow::onRefreshTrayIconTooltip() m_trayIcon->setToolTip(trayIconToolTip); } +void MainWindow::setCentralWidgetPages() +{ + bool isChanged = false; + if (m_isWiredUsable != m_lanWidget->isWiredDeviceUsable()) { + if (m_lanWidget->isWiredDeviceUsable()) { + m_centralWidget->insertTab(LANPAGE, m_lanWidget, ""); + m_isWiredUsable = true; + } else { + m_centralWidget->removeTab(LANPAGE); + m_isWiredUsable = false; + } + isChanged = true; + } + + if (m_isWirelessUsable != m_wlanWidget->isWirelessDeviceUsable()) { + if (m_wlanWidget->isWirelessDeviceUsable()) { + m_centralWidget->insertTab(WLANPAGE, m_wlanWidget, ""); + m_isWirelessUsable = true; + } else { + m_centralWidget->removeTab(WLANPAGE); + m_isWirelessUsable = false; + } + isChanged = true; + } + + if (!isChanged) { + return; + } + + if (m_isWiredUsable && m_isWirelessUsable) { + m_centralWidget->tabBar()->show(); + this->setFixedHeight(MAINWINDOW_HEIGHT); + resetWindowPosition(); + } else { + m_centralWidget->tabBar()->hide(); + this->setFixedHeight(MAINWINDOW_HEIGHT - TABBAR_HEIGHT); + resetWindowPosition(); + } + + if (m_trayIcon) { + m_trayIcon->setVisible(m_isWiredUsable || m_isWirelessUsable); + } +} + void MainWindow::onShowMainWindow(int type) { + if (!m_trayIcon->isVisible()) { + qWarning() << "no valid network card, do not show kylin-nm mainwindow"; + return; + } if (type == LANPAGE || type == WLANPAGE) { m_centralWidget->setCurrentIndex(type); diff --git a/src/frontend/mainwindow.h b/src/frontend/mainwindow.h index 01962c21..11fafd1e 100644 --- a/src/frontend/mainwindow.h +++ b/src/frontend/mainwindow.h @@ -206,6 +206,9 @@ private: QString m_display; + bool m_isWiredUsable = true; + bool m_isWirelessUsable = true; + public Q_SLOTS: void onShowMainWindow(int type); @@ -231,6 +234,8 @@ private Q_SLOTS: void onShowCreateWiredConnectWidgetSlot(QString display, QString devName); //唤起加入其他无线网络界面 void onShowAddOtherWlanWidgetSlot(QString display, QString devName); + //设置界面显示 单网卡/多网卡 + void setCentralWidgetPages(); }; #endif // MAINWINDOW_H diff --git a/src/frontend/tab-pages/lanpage.h b/src/frontend/tab-pages/lanpage.h index 76ade9f6..ca06e5cc 100644 --- a/src/frontend/tab-pages/lanpage.h +++ b/src/frontend/tab-pages/lanpage.h @@ -52,6 +52,10 @@ public: bool lanIsConnected(); void getWiredDeviceConnectState(QMap &map); + bool isWiredDeviceUsable() { + return !m_devList.isEmpty(); + } + protected: bool eventFilter(QObject *watched, QEvent *event); diff --git a/src/frontend/tab-pages/wlanpage.h b/src/frontend/tab-pages/wlanpage.h index 85256044..089b3461 100644 --- a/src/frontend/tab-pages/wlanpage.h +++ b/src/frontend/tab-pages/wlanpage.h @@ -88,6 +88,10 @@ public: return m_currentDevice; } + bool isWirelessDeviceUsable() { + return !m_devList.isEmpty(); + } + Q_SIGNALS: void oneItemExpanded(const QString &ssid); void wlanAdd(QString devName, QStringList info); From a85a5490828aa504efd38f6d9022594b8bbd57d4 Mon Sep 17 00:00:00 2001 From: zhangyuanyuan1 Date: Mon, 9 Oct 2023 10:17:53 +0800 Subject: [PATCH 3/3] fix(wlan device combobox): modify logic of device combobox display --- src/frontend/tab-pages/wlanpage.cpp | 39 +++++++++++++---------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/src/frontend/tab-pages/wlanpage.cpp b/src/frontend/tab-pages/wlanpage.cpp index fc5aecf2..31b05b35 100644 --- a/src/frontend/tab-pages/wlanpage.cpp +++ b/src/frontend/tab-pages/wlanpage.cpp @@ -294,9 +294,8 @@ void WlanPage::initDeviceCombox() } } else { m_deviceFrame->hide(); - //解决因m_currentDevice被置空,安全中心网络显示BUG -// m_currentDevice = ""; -// setDefaultDevice(WIRELESS, m_currentDevice); + m_currentDevice = ""; + setDefaultDevice(WIRELESS, m_currentDevice); } connect(m_deviceComboBox, QOverload::of(&QComboBox::currentIndexChanged), @@ -780,25 +779,23 @@ void WlanPage::deleteDeviceFromCombox(QString deviceName) disconnect(m_deviceComboBox, QOverload::of(&QComboBox::currentIndexChanged), this, &WlanPage::onDeviceComboxIndexChanged); - if (getSwitchBtnState()) { - if (0 == m_devList.count()) { - m_deviceFrame->hide(); - //m_tipsLabel->show(); - //m_deviceComboBox->hide(); - m_currentDevice = ""; + if (0 == m_devList.count()) { + m_deviceFrame->hide(); + //m_tipsLabel->show(); + //m_deviceComboBox->hide(); + m_currentDevice = ""; + setDefaultDevice(WIRELESS, m_currentDevice); + } else if (1 == m_devList.count()) { + m_deviceFrame->hide(); + m_deviceComboBox->clear(); + m_currentDevice = m_devList.at(0); + setDefaultDevice(WIRELESS, m_currentDevice); + } else { + int index = m_deviceComboBox->findText(deviceName); + if (-1 != index) { + m_deviceComboBox->removeItem(index); + m_currentDevice = m_deviceComboBox->currentText(); setDefaultDevice(WIRELESS, m_currentDevice); - } else if (1 == m_devList.count()) { - m_deviceFrame->hide(); - m_deviceComboBox->clear(); - m_currentDevice = m_devList.at(0); - setDefaultDevice(WIRELESS, m_currentDevice); - } else { - int index = m_deviceComboBox->findText(deviceName); - if (-1 != index) { - m_deviceComboBox->removeItem(index); - m_currentDevice = m_deviceComboBox->currentText(); - setDefaultDevice(WIRELESS, m_currentDevice); - } } }