diff --git a/src/frontend/list-items/lanlistitem.h b/src/frontend/list-items/lanlistitem.h index bd46ae9e..4c7ff28a 100644 --- a/src/frontend/list-items/lanlistitem.h +++ b/src/frontend/list-items/lanlistitem.h @@ -22,6 +22,7 @@ public: KyConnectResourse *m_connectResource = nullptr; QString deviceName = ""; + void refreshIcon(); protected: void setIcon(bool isOn); diff --git a/src/frontend/list-items/wlanlistitem.cpp b/src/frontend/list-items/wlanlistitem.cpp index 05bfc8b4..7c42e596 100644 --- a/src/frontend/list-items/wlanlistitem.cpp +++ b/src/frontend/list-items/wlanlistitem.cpp @@ -270,8 +270,8 @@ void WlanListItem::onNetButtonClicked() qDebug()<<"Clicked on connected wifi, it will be inactivated. ssid = " << m_data->m_NetSsid << Q_FUNC_INFO << __LINE__; return; } - - if (m_data->m_isConfigured) { +//有配置或者无密码的wifi直接连接 + if (m_data->m_isConfigured || m_hasPwd == false) { m_connoperation->activeWirelessConnect(m_wlanDevice,m_data->m_connectUuid); qDebug()<<"Has configuration, will be activated. ssid = " << m_data->m_NetSsid << Q_FUNC_INFO << __LINE__; return; @@ -399,35 +399,6 @@ void WlanListItem::onWlanStatusChange(QString uuid, NetworkManager::ActiveConnec m_netButton->stopLoading(); } } - - //TODO 网络状态改变的通知 -// if (state == NetworkManager::ActiveConnection::State::Activated) { -//// this->showDesktopNotify(tr("WLAN Connected Successfully")); -// } else if (state == NetworkManager::ActiveConnection::State::Deactivated) { -// switch (reason) { -// case NetworkManager::ActiveConnection::Reason::UserDisconnected: -// this->showDesktopNotify(tr("WLAN Disconnected Successfully")); -// break; -// case NetworkManager::ActiveConnection::Reason::ServiceStopped: -// this->showDesktopNotify(tr("The service providing the VPN connection was stopped")); -// break; -// case NetworkManager::ActiveConnection::Reason::IpConfigInvalid: -// this->showDesktopNotify(tr("The IP config of the active connection was invalid")); -// break; -// case NetworkManager::ActiveConnection::Reason::ConnectTimeout: -// this->showDesktopNotify(tr("The connection attempt to the VPN service timed out")); -// break; -// case NetworkManager::ActiveConnection::Reason::NoSecrets: -// this->showDesktopNotify(tr("Necessary secrets for the connection were not provided")); -// break; -// case NetworkManager::ActiveConnection::Reason::LoginFailed: -// this->showDesktopNotify(tr("Authentication to the server failed")); -// break; -// default: -// qDebug() << "Wlan disconnected with unkown reason." << Q_FUNC_INFO << __LINE__; -// break; -// } -// } } void WlanListItem::onMenuTriggered(QAction *action) diff --git a/src/frontend/new-mainwindow.cpp b/src/frontend/new-mainwindow.cpp index 8a897273..53f0f40c 100644 --- a/src/frontend/new-mainwindow.cpp +++ b/src/frontend/new-mainwindow.cpp @@ -146,7 +146,7 @@ void MainWindow::initTrayIcon() m_trayIconMenu->addAction(m_showMainwindowAction); m_trayIconMenu->addAction(m_showSettingsAction); m_trayIcon->setContextMenu(m_trayIconMenu); - m_trayIcon->setIcon(QIcon::fromTheme("network-wireless-signal-excellent-symbolic")); + m_trayIcon->setIcon(QIcon::fromTheme("network-wired-signal-excellent-symbolic")); connect(m_trayIcon, &QSystemTrayIcon::activated, this, &MainWindow::onTrayIconActivated); connect(m_showMainwindowAction, &QAction::triggered, this, &MainWindow::onShowMainwindowActionTriggled); @@ -170,6 +170,7 @@ void MainWindow::initDbusConnnect() connect(m_lanWidget, &LanPage::lanRemove, this, &MainWindow::lanRemove); connect(m_lanWidget, &LanPage::lanUpdate, this, &MainWindow::lanUpdate); connect(m_lanWidget, &LanPage::lanActiveConnectionStateChanged, this, &MainWindow::lanActiveConnectionStateChanged); + connect(m_lanWidget, &LanPage::lanConnectChanged, this, &MainWindow::onRefreshTrayIcon); connect(m_wlanWidget, &WlanPage::wlanAdd, this, &MainWindow::wlanAdd); @@ -179,6 +180,7 @@ void MainWindow::initDbusConnnect() connect(m_wlanWidget, &WlanPage::hotspotActivated, this, &MainWindow::hotspotActivated); connect(m_wlanWidget, &WlanPage::secuTypeChange, this, &MainWindow::secuTypeChange); connect(m_wlanWidget, &WlanPage::signalStrengthChange, this, &MainWindow::signalStrengthChange); + connect(m_wlanWidget, &WlanPage::wlanConnectChanged, this, &MainWindow::onRefreshTrayIcon); } /** @@ -301,7 +303,11 @@ void MainWindow::resetWindowTheme() void MainWindow::showControlCenter() { QProcess process; - process.startDetached("ukui-control-center --netconnect"); + if (m_lanWidget->m_isLanConnected == false && m_wlanWidget->wlanIsConnected == true){ + process.startDetached("ukui-control-center --wlanconnect"); + } else { + process.startDetached("ukui-control-center --wiredconnect"); + } } /** @@ -338,6 +344,18 @@ void MainWindow::onThemeChanged(const QString &key) } } +void MainWindow::onRefreshTrayIcon() +{ + //更新托盘图标显示 + if (m_lanWidget->m_isLanConnected == true){ + m_trayIcon->setIcon(QIcon::fromTheme("network-wired-signal-excellent-symbolic")); + } else if (m_wlanWidget->wlanIsConnected == true && m_lanWidget->m_isLanConnected == false){ + m_trayIcon->setIcon(QIcon::fromTheme("network-wireless-signal-excellent-symbolic")); + } else if (m_wlanWidget->wlanIsConnected == false && m_lanWidget->m_isLanConnected == false){ + m_trayIcon->setIcon(QIcon::fromTheme("network-wired-signal-excellent-symbolic")); + } +} + /** * @brief MainWindow::keyPressEvent 按esc键关闭主界面 * @param event @@ -466,7 +484,6 @@ void MainWindow::activateWired(const QString& devName, const QString& connUuid) { m_lanWidget->activateWired(devName, connUuid); } - void MainWindow::deactivateWired(const QString& devName, const QString& connUuid) { m_lanWidget->deactivateWired(devName, connUuid); diff --git a/src/frontend/new-mainwindow.h b/src/frontend/new-mainwindow.h index 71feb051..da6185f1 100644 --- a/src/frontend/new-mainwindow.h +++ b/src/frontend/new-mainwindow.h @@ -117,6 +117,7 @@ private slots: void onShowMainwindowActionTriggled(); void onShowSettingsActionTriggled(); void onThemeChanged(const QString &key); + void onRefreshTrayIcon(); }; #endif // MAINWINDOW_H diff --git a/src/frontend/tab-pages/lanpage.cpp b/src/frontend/tab-pages/lanpage.cpp index bc4f54b3..ddcea066 100644 --- a/src/frontend/tab-pages/lanpage.cpp +++ b/src/frontend/tab-pages/lanpage.cpp @@ -333,6 +333,7 @@ void LanPage::initUI() // m_inactivatedLanListWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); //用了listwidget的滚动条 inactiveLanListLayout->addWidget(m_inactivatedLanListWidget); +// emit this->lanConnectChanged(); } void LanPage::addNewItem(KyConnectItem *itemData, QListWidget *listWidget) @@ -362,6 +363,7 @@ void LanPage::initList(QString m_deviceName) //程序拉起,初始化显 for (int i = 0; i < m_activedList.size(); i++) { KyConnectItem *activeItemData = m_activedList.at(i); addNewItem(activeItemData, m_activatedLanListWidget); + emit this->lanConnectChanged(); m_activeMap.insert(activeItemData, m_listWidgetItem); } @@ -387,9 +389,24 @@ void LanPage::initList(QString m_deviceName) //程序拉起,初始化显 void LanPage::updateLanlist(QString uuid, NetworkManager::ActiveConnection::State state, NetworkManager::ActiveConnection::Reason reason) { - qDebug()<<"[LanPage] State change slot:"<getInterfaceByUuid(devName, type, uuid)) { + if (type != NetworkManager::ConnectionSettings::ConnectionType::Wired) { + return; + } + } + if (NetworkManager::ActiveConnection::State::Activated == state){ + m_isLanConnected = true; + qDebug() << "[lanpage]lanIsConnected status : " << m_isLanConnected << Q_FUNC_INFO << __LINE__ ; + } else { + m_isLanConnected = false; + qDebug() << "=[lanpage]lanIsConnected status : " << m_isLanConnected << Q_FUNC_INFO << __LINE__ ; + } + qDebug()<<"[LanPage] State change slot:"<getInterfaceByUuid(devName, type, uuid)) { if (type != NetworkManager::ConnectionSettings::ConnectionType::Wired) { @@ -426,6 +443,7 @@ void LanPage::updateLanlist(QString uuid, NetworkManager::ActiveConnection::Stat if (m_item->m_connectUuid == uuid) { m_activatedLanListWidget->removeItemWidget(i.value()); delete(i.value()); + emit this->lanConnectChanged(); break; } } diff --git a/src/frontend/tab-pages/lanpage.h b/src/frontend/tab-pages/lanpage.h index d2d97f5e..25e904c1 100644 --- a/src/frontend/tab-pages/lanpage.h +++ b/src/frontend/tab-pages/lanpage.h @@ -21,6 +21,7 @@ class LanPage : public TabPage public: explicit LanPage(QWidget *parent = nullptr); ~LanPage(); + bool m_isLanConnected = false; //for dbus void getWiredList(QMap > &map); @@ -33,6 +34,7 @@ signals: void lanRemove(QString dbusPath); void lanUpdate(QString devName, QStringList info); void lanActiveConnectionStateChanged(QString interface, QString uuid, int status); + void lanConnectChanged(); private: void initDeviceCombox(); void initUI(); diff --git a/src/frontend/tab-pages/tabpage.cpp b/src/frontend/tab-pages/tabpage.cpp index 02b181f6..7e5e9312 100644 --- a/src/frontend/tab-pages/tabpage.cpp +++ b/src/frontend/tab-pages/tabpage.cpp @@ -109,6 +109,24 @@ QString TabPage::getDefaultDevice() return m_defaultDevice; } +void TabPage::showDesktopNotify(const QString &message) +{ + QDBusInterface iface("org.freedesktop.Notifications", + "/org/freedesktop/Notifications", + "org.freedesktop.Notifications", + QDBusConnection::sessionBus()); + QList args; + args<<(tr("Kylin NM")) + <<((unsigned int) 0) + < &map) map.clear(); if (!QFile::exists(CONFIG_FILE_PATH)) { qDebug() << "CONFIG_FILE_PATH not exist"; + return; } if (type != WIRED && type != WIRELESS) { qDebug() << "getDeviceEnableState but wrong type"; diff --git a/src/frontend/tab-pages/tabpage.h b/src/frontend/tab-pages/tabpage.h index 2aee84a8..7088fb8c 100644 --- a/src/frontend/tab-pages/tabpage.h +++ b/src/frontend/tab-pages/tabpage.h @@ -10,6 +10,9 @@ #include #include #include +#include +#include +#include #include "kylinnetworkdeviceresource.h" #define MAIN_LAYOUT_MARGINS 0,0,0,0 @@ -50,6 +53,7 @@ public: void updateDefaultDevice(QString &deviceName); QString getDefaultDevice(); + static void showDesktopNotify(const QString &message); signals: void deviceStatusChanged(); diff --git a/src/frontend/tab-pages/wlanpage.cpp b/src/frontend/tab-pages/wlanpage.cpp index 72a99922..96287136 100644 --- a/src/frontend/tab-pages/wlanpage.cpp +++ b/src/frontend/tab-pages/wlanpage.cpp @@ -17,6 +17,8 @@ WlanPage::WlanPage(QWidget *parent) : TabPage(parent) initDevice(); m_wirelessConnectOpreation = new KyWirelessConnectOperation(this); m_connectoperation = new KyConnectOperation(this); + m_settingsLabel->installEventFilter(this); + m_connectResource = new KyActiveConnectResourse(); initWlanUI(); //要在initUI之后调用,保证UI的信号槽顺利绑定 initConnections(); @@ -33,6 +35,8 @@ WlanPage::WlanPage(QWidget *parent) : TabPage(parent) connect(m_wirelessConnectOpreation, &KyWirelessConnectOperation::deactivateConnectionError, this, &WlanPage::deactivateFailed); connect(this, &WlanPage::hiddenWlanClicked, this, &WlanPage::onHiddenWlanClicked); + connect(this, &WlanPage::settingsClicked, this, &WlanPage::showControlCenter); + connect(m_wirelessConnectOpreation, &KyWirelessConnectOperation::wifinEnabledChanged, this, &WlanPage::onWifiEnabledChanged); } //QString WlanPage::getSsidFromUuid(const QString &uuid) @@ -48,6 +52,7 @@ bool WlanPage::eventFilter(QObject *w, QEvent *e) emit this->hiddenWlanClicked(); } else if (w == m_settingsLabel) { //ZJP_TODO 打开控制面板 + emit this->settingsClicked(); } } return QWidget::eventFilter(w,e); @@ -154,6 +159,11 @@ void WlanPage::initDevice() if (!m_devList.isEmpty()) { deviceName = m_devList.at(0); m_settings->setValue(key, deviceName); + } else { + qDebug() << "have no device to use " << Q_FUNC_INFO << __LINE__; + //检测不到无线网卡不再触发click信号 + m_netSwitch->setSwitchStatus(false); + m_netSwitch->setEnabled(false); } updateDefaultDevice(deviceName); qDebug() << "[WlanPage] initDevice defaultDevice = " << deviceName; @@ -217,6 +227,7 @@ void WlanPage::getActiveWlan() QListWidgetItem *wlanItem = new QListWidgetItem(m_activatedNetListWidget); wlanItem->setSizeHint(QSize(m_activatedNetListWidget->width(), wlanItemWidget->height())); m_activatedNetListWidget->addItem(wlanItem); +// emit this->wlanConnectChanged(); m_activatedNetListWidget->setItemWidget(wlanItem, wlanItemWidget); height += wlanItemWidget->height(); } @@ -239,6 +250,8 @@ void WlanPage::appendActiveWlan(const QString &uuid, int &height) QListWidgetItem *wlanItem = new QListWidgetItem(m_activatedNetListWidget); wlanItem->setSizeHint(QSize(m_activatedNetListWidget->width(), wlanItemWidget->height())); m_activatedNetListWidget->addItem(wlanItem); + emit this->wlanConnectChanged(); + qDebug() << "[wlanpage]emit wlanConnectChanged()" << Q_FUNC_INFO << __LINE__ ; m_activatedNetListWidget->setItemWidget(wlanItem, wlanItemWidget); wlanItemWidget->setActive(true); @@ -253,7 +266,7 @@ void WlanPage::getAllWlan() if (!m_inactivatedNetListWidget) { return; } - qDebug() << "Started loading wlan list! time=" << QDateTime::currentDateTime().toString("hh:mm:ss.zzzz"); + qDebug() << "Started loading wlan list!" << QDateTime::currentDateTime().toString("hh:mm:ss.zzzz"); m_inactivatedNetListWidget->clear(); m_itemsMap.clear(); QList wlanList; @@ -293,8 +306,6 @@ void WlanPage::onWlanAdded(QString interface, KyWirelessNetItem &item) QStringList info; info <setEnabled(true); + m_netSwitch->setSwitchStatus(true); m_devList << deviceName; if (getDefaultDevice().isEmpty()) { @@ -375,6 +388,9 @@ void WlanPage::onDeviceRemove(QString deviceName) m_netDeviceResource->getNetworkDeviceList(NetworkManager::Device::Type::Wifi, list); if (!list.isEmpty()) { newDefaultDevice = list.at(0); + } else { + m_netSwitch->setSwitchStatus(false); + m_netSwitch->setEnabled(false); } updateDefaultDevice(newDefaultDevice); setDefaultDevice(WIRELESS, newDefaultDevice); @@ -419,8 +435,48 @@ void WlanPage::onActivatedWlanChanged(QString uuid, NetworkManager::ActiveConnec { qDebug()<< "Activated wlan changed, uuid = " << uuid << "; state = " << state << "; reason = " << reason << Q_FUNC_INFO <<__LINE__; - QString ssid,devName; + //wlanpage函数内持续监听连接状态的变化并记录供其他函数调用获取状态 + QString devName,ssid; NetworkManager::ConnectionSettings::ConnectionType type; + if(m_apConnectResource->getInterfaceByUuid(devName, type, uuid)) { + if (type != NetworkManager::ConnectionSettings::ConnectionType::Wireless) { + return; + } + } + if(NetworkManager::ActiveConnection::State::Activated == state){ + wlanIsConnected = true; + qDebug() << "[wlanpage] wlanIsConnected status : " << wlanIsConnected << Q_FUNC_INFO << __LINE__ ; + } else { + wlanIsConnected = false; + qDebug() << "[wlanpage] wlanIsConnected status : " << wlanIsConnected << Q_FUNC_INFO << __LINE__ ; + } + + //弹窗显示wifi连接状况 + qDebug() << "[WlanPage] State changed to :" << state << reason << Q_FUNC_INFO <<__LINE__; + //QString ssid; + m_resource->getSsidByUuid(uuid, ssid, m_defaultDevice); + if (m_activatedWlanSSid == ssid && state == NetworkManager::ActiveConnection::State::Activated) { + if(m_activedssid != m_activatedWlanSSid){ + m_activedssid = m_activatedWlanSSid; + qDebug() << "[WlanPage] State changed to :" << state << ssid << reason << Q_FUNC_INFO <<__LINE__; + this->showDesktopNotify(tr("WLAN Connected Successfully")); + } + } + if (state == NetworkManager::ActiveConnection::State::Deactivating){ + m_disconnectuuid = uuid; + m_disconnectingflag = true; + } + if (state == NetworkManager::ActiveConnection::State::Deactivated && m_disconnectuuid == uuid){ + if(m_disconnectingflag){ + m_disconnectingflag = false; + this->showDesktopNotify(tr("WLAN Disconnected Successfully")); + qDebug() << "clear the activessid" << Q_FUNC_INFO <<__LINE__; + m_activedssid = ""; + } + } + + //QString ssid,devName; + //NetworkManager::ConnectionSettings::ConnectionType type; if(m_apConnectResource->getInterfaceByUuid(devName, type, uuid)) { if (type != NetworkManager::ConnectionSettings::ConnectionType::Wireless) { @@ -469,6 +525,7 @@ void WlanPage::onActivatedWlanChanged(QString uuid, NetworkManager::ActiveConnec m_activatedNetListWidget->clear(); int height = 0; appendActiveWlan(uuid, height); +// emit this->wlanConnectChanged(); onWlanRemoved(m_defaultDevice, ssid); // this->showDesktopNotify(tr("Connect WLAN succeed")); } else if (state == NetworkManager::ActiveConnection::State::Deactivated && (uuid.isEmpty() || (!uuid.isEmpty() && uuid == m_activatedWlanUuid))) { @@ -525,12 +582,20 @@ void WlanPage::onConnectButtonClicked(KyWirelessConnectSetting &connSettingInfo, void WlanPage::onWlanSwitchClicked() { qDebug() << "On wlan switch button clicked! old state = " << !m_netSwitch->getSwitchStatus() << Q_FUNC_INFO << __LINE__; - m_wirelessConnectOpreation->setWirelessEnabled(m_netSwitch->getSwitchStatus()); + //应该先检测是否有无线网卡可用,才改变开关状态 + m_netDeviceResource->getNetworkDeviceList(NetworkManager::Device::Type::Wifi, m_devList); + if (m_devList.isEmpty()) { + qDebug() << "have no device to use " << Q_FUNC_INFO << __LINE__; + //检测不到无线网卡不再触发click信号 + m_netSwitch->setSwitchStatus(false); + m_netSwitch->setEnabled(false); + }else{ + m_wirelessConnectOpreation->setWirelessEnabled(m_netSwitch->getSwitchStatus()); + } } void WlanPage::onWlanSwitchStatusChanged(const bool &checked) { - m_netSwitch->setSwitchStatus(checked); qDebug() << "On wlan switch status changed! new state = " << m_netSwitch->getSwitchStatus() << Q_FUNC_INFO << __LINE__; onWlanUpdated(); } @@ -553,6 +618,7 @@ void WlanPage::requestScan() { if (!m_wirelessConnectOpreation) { qWarning() << "Scan failed! m_wirelessConnectOpreation is nullptr!" << Q_FUNC_INFO << __LINE__; + return; } m_wirelessConnectOpreation->requestWirelessScan(); } @@ -564,6 +630,29 @@ void WlanPage::onHiddenWlanClicked() netDetail->show(); } +void WlanPage::showControlCenter() +{ + QProcess process; + process.startDetached("ukui-control-center --wlanconnect"); +} +void WlanPage::onWifiEnabledChanged(bool isWifiOn) +{ +//监听外部命令导致wifi状态变化,更新界面 + //应该先检测是否有无线网卡可用,才改变开关状态 + m_netDeviceResource->getNetworkDeviceList(NetworkManager::Device::Type::Wifi, m_devList); + if (m_devList.isEmpty()) { + qDebug() << "have no device to use " << Q_FUNC_INFO << __LINE__; + return; + } + if(m_netSwitch->getSwitchStatus() == isWifiOn){ + return; + }else{ + //m_wirelessConnectOpreation->setWirelessEnabled(isWifiOn); + m_netSwitch->setSwitchStatus(isWifiOn); + //外部命令导致连接状态发生变化,通知主界面刷新图标 + emit this->wlanConnectChanged(); + } +} //for dbus void WlanPage::getWirelessList(QMap > &map) @@ -714,6 +803,7 @@ void WlanPage::onMainWindowVisibleChanged(const bool &visible) m_scanTimer->stop(); } } + void WlanPage::showDetailPage(QString devName, QString ssid) { KyWirelessNetItem data; @@ -724,8 +814,13 @@ void WlanPage::showDetailPage(QString devName, QString ssid) QMap actMap; m_resource->getWirelessActiveConnection(NetworkManager::ActiveConnection::State::Activated, actMap); + if (!actMap.contains(devName)) { + qDebug()<<"[WlanPage] " << devName << " is missing when showDetailPage"; + return; + } bool isActive = actMap[devName].contains(ssid); NetDetail *netDetail = new NetDetail(devName, ssid, data.m_connectUuid, isActive, true, false, this); netDetail->show(); } + diff --git a/src/frontend/tab-pages/wlanpage.h b/src/frontend/tab-pages/wlanpage.h index a7aceaa1..47cad272 100644 --- a/src/frontend/tab-pages/wlanpage.h +++ b/src/frontend/tab-pages/wlanpage.h @@ -10,6 +10,9 @@ #include "kylinconnectoperation.h" #include #include "netdetails/netdetail.h" +#include +#include "kylinactiveconnectresource.h" +#include "kywirelessnetresource.h" //#define SCROLLAREA_HEIGHT 150 #define MORE_TEXT_MARGINS 16,0,0,0 @@ -21,6 +24,7 @@ class WlanPage : public TabPage public: explicit WlanPage(QWidget *parent = nullptr); ~WlanPage() = default; + bool wlanIsConnected = false; //for dbus void getWirelessList(QMap > &map); @@ -44,6 +48,8 @@ signals: void signalStrengthChange(QString devName, QString ssid, int strength); void secuTypeChange(QString devName, QString ssid, QString secuType); void hiddenWlanClicked(); + void settingsClicked(); + void wlanConnectChanged(); public slots: void onMainWindowVisibleChanged(const bool &visible); @@ -54,6 +60,10 @@ protected: private: void initWlanUI(); void initConnections(); + QString m_activedssid; + QString m_disconnectuuid; + int m_disconnecting; + bool m_disconnectingflag = false; //定时触发扫描的定时器 void initTimer(); @@ -106,6 +116,8 @@ private slots: void onDeviceComboxIndexChanged(int currentIndex); void requestScan(); void onHiddenWlanClicked(); + void showControlCenter(); + void onWifiEnabledChanged(bool isWifiOn); }; #endif // WLANPAGE_H