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 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.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); - } } } 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);