diff --git a/src/frontend/netdetails/netdetail.h b/src/frontend/netdetails/netdetail.h index 7e6fa2a4..7a194cfd 100644 --- a/src/frontend/netdetails/netdetail.h +++ b/src/frontend/netdetails/netdetail.h @@ -109,7 +109,7 @@ private: // QPushButton * ipv6Btn; // QPushButton * securityBtn; QFrame * pageFrame; - KTabBar *m_netTabBar = nullptr; + KTabBar *m_netTabBar = nullptr; QString m_name; QString m_uuid; diff --git a/src/frontend/tab-pages/lanpage.cpp b/src/frontend/tab-pages/lanpage.cpp index b35ceed6..e4438791 100644 --- a/src/frontend/tab-pages/lanpage.cpp +++ b/src/frontend/tab-pages/lanpage.cpp @@ -120,7 +120,7 @@ void LanPage::initLanDeviceState() } KyWiredConnectOperation wiredOperation; - if (m_wiredSwitch) { + if (m_netSwitch->isChecked()) { for (int index = 0; index < disableDeviceList.count(); ++index) { wiredOperation.closeWiredNetworkWithDevice(disableDeviceList.at(index)); } @@ -135,12 +135,12 @@ void LanPage::initLanDeviceState() void LanPage::initNetSwitch() { - m_wiredSwitch = true; + bool wiredSwitch = true; if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA)) { m_switchGsettings = new QGSettings(GSETTINGS_SCHEMA); if (m_switchGsettings->keys().contains(WIRED_SWITCH)) { - m_wiredSwitch = m_switchGsettings->get(WIRED_SWITCH).toBool(); + wiredSwitch = m_switchGsettings->get(WIRED_SWITCH).toBool(); connect(m_switchGsettings, &QGSettings::changed, this, &LanPage::onSwithGsettingsChanged); } } else { @@ -149,16 +149,13 @@ void LanPage::initNetSwitch() if (m_devList.count() == 0) { qDebug() << "[wiredSwitch]:init not enable when no device"; - m_wiredSwitch = false; - m_netSwitch->setSwitchStatus(m_wiredSwitch); - m_netSwitch->setEnabled(false); + m_netSwitch->setChecked(false); + m_netSwitch->setCheckable(false); } - qDebug() << "[wiredSwitch]:init state:" << m_wiredSwitch; + qDebug() << "[wiredSwitch]:init state:" << wiredSwitch; - m_netSwitch->setSwitchStatus(m_wiredSwitch); - - connect(m_netSwitch, &SwitchButton::clicked, this, &LanPage::onLanSwitchClicked); + m_netSwitch->setChecked(wiredSwitch); return; } @@ -166,13 +163,16 @@ void LanPage::initNetSwitch() void LanPage::onSwithGsettingsChanged(const QString &key) { if (key == WIRED_SWITCH) { - m_netSwitch->blockSignals(true); - m_wiredSwitch = m_switchGsettings->get(WIRED_SWITCH).toBool(); - qDebug()<<"[LanPage] SwitchButton statue changed to:" << m_wiredSwitch; + bool wiredSwitch = m_switchGsettings->get(WIRED_SWITCH).toBool(); + qDebug()<<"[LanPage] SwitchButton statue changed to:" << wiredSwitch << m_netSwitch->isChecked(); + + if (wiredSwitch == m_netSwitch->isChecked()) { + return; + } KyWiredConnectOperation wiredOperation; - if (m_wiredSwitch) { + if (wiredSwitch) { for (int index = 0; index < m_enableDeviceList.size(); ++index) { qDebug()<<"[LanPage] open wired device "<< m_enableDeviceList.at(index); wiredOperation.openWiredNetworkWithDevice(m_enableDeviceList.at(index)); @@ -184,30 +184,10 @@ void LanPage::onSwithGsettingsChanged(const QString &key) } } + m_netSwitch->setChecked(wiredSwitch); + initDeviceCombox(); initLanArea(); - - m_netSwitch->setSwitchStatus(m_wiredSwitch); - - m_netSwitch->blockSignals(false); - } -} - -void LanPage::onLanSwitchClicked() -{ - qDebug()<<"[LanPage] On lan switch button clicked! Status:" <getSwitchStatus() - <<"devices count:"<showDesktopNotify(tr("No ethernet device avaliable"), "networkwrong"); - } else { - if (m_netSwitch->getSwitchStatus()) { - //qDebug() << "[wiredSwitch]set true after clicked"; - m_switchGsettings->set(WIRED_SWITCH, true); - } else { - //qDebug() << "[wiredSwitch]set false after clicked"; - m_switchGsettings->set(WIRED_SWITCH,false); - } } } @@ -266,7 +246,7 @@ void LanPage::initDeviceCombox() m_deviceComboBox->clear(); - if (m_wiredSwitch) { + if (m_netSwitch->isChecked()) { int enableDeviceCount = m_enableDeviceList.count(); if (enableDeviceCount > 1) { for (int index = 0; index < enableDeviceCount; ++index) { @@ -426,7 +406,7 @@ void LanPage::constructConnectionArea() void LanPage::initLanArea() { - if (!m_wiredSwitch || m_currentDeviceName.isEmpty()) { + if (!m_netSwitch->isChecked() || m_currentDeviceName.isEmpty()) { m_activatedNetDivider->hide(); m_activatedNetFrame->hide(); @@ -526,7 +506,7 @@ void LanPage::addDeviceForCombox(QString deviceName) disconnect(m_deviceComboBox, QOverload::of(&QComboBox::currentIndexChanged), this, &LanPage::onDeviceComboxIndexChanged); - if (m_wiredSwitch) { + if (m_netSwitch->isChecked()) { if (1 == m_enableDeviceList.count()) { //1、从无到有添加第一块有线网卡 //2、有多快网卡,但是没有使能 @@ -564,9 +544,9 @@ void LanPage::onDeviceAdd(QString deviceName, NetworkManager::Device::Type devic } if (m_devList.count() == 0) {// 有线网卡从无到有,打开开关 - m_netSwitch->setEnabled(true); - m_wiredSwitch = m_switchGsettings->get(WIRED_SWITCH).toBool(); - m_netSwitch->setSwitchStatus(m_wiredSwitch); + bool wiredSwitch = m_switchGsettings->get(WIRED_SWITCH).toBool(); + m_netSwitch->setCheckable(true); + m_netSwitch->setChecked(wiredSwitch); } qDebug() << "[LanPage] Begin add device:" << deviceName; @@ -590,7 +570,7 @@ void LanPage::deleteDeviceFromCombox(QString deviceName) disconnect(m_deviceComboBox, QOverload::of(&QComboBox::currentIndexChanged), this, &LanPage::onDeviceComboxIndexChanged); - if (m_wiredSwitch) { + if (m_netSwitch->isChecked()) { if (0 == m_enableDeviceList.count()) { //1、没有使能任何网卡 goto l_out; @@ -649,9 +629,8 @@ void LanPage::onDeviceRemove(QString deviceName) m_devList.removeOne(deviceName); if (m_devList.count() == 0) { - m_wiredSwitch = false; - m_netSwitch->setSwitchStatus(m_wiredSwitch); - m_netSwitch->setEnabled(false); + m_netSwitch->setCheckable(false); + m_netSwitch->setChecked(false); qDebug() << "[wiredSwitch]set not enable after device remove"; } @@ -727,7 +706,7 @@ void LanPage::onDeviceActiveChanage(QString deviceName, bool deviceActive) } if (deviceActive) { - if (!m_wiredSwitch || !m_enableDeviceList.contains(deviceName)) { + if (!m_netSwitch->isChecked() || !m_enableDeviceList.contains(deviceName)) { qDebug()<< LOG_FLAG << "close disabled device"; m_wiredConnectOperation->closeWiredNetworkWithDevice(deviceName); } @@ -781,6 +760,7 @@ void LanPage::initUI() m_inactivatedLanListWidget->setPalette(pal); m_settingsLabel->installEventFilter(this); + m_netSwitch->installEventFilter(this); } QListWidgetItem *LanPage::insertNewItem(KyConnectItem *itemData, QListWidget *listWidget) @@ -1196,6 +1176,28 @@ bool LanPage::eventFilter(QObject *watched, QEvent *event) if (event->type() == QEvent::MouseButtonRelease) { onShowControlCenter(); } + } else if(watched == m_netSwitch){ + if (event->type() == QEvent::MouseButtonRelease) { + qDebug()<<"[LanPage] On lan switch button clicked! Status:" <isChecked() + <<"devices count:"<showDesktopNotify(tr("No ethernet device avaliable"), "networkwrong"); + m_netSwitch->setCheckable(false); + m_netSwitch->setChecked(false); + } else { + m_netSwitch->setCheckable(true); + if (m_netSwitch->isChecked()) { +// qDebug() << "[wiredSwitch]set true after clicked"; + m_switchGsettings->set(WIRED_SWITCH, false); + } else { +// qDebug() << "[wiredSwitch]set false after clicked"; + m_switchGsettings->set(WIRED_SWITCH,true); + } + } + return true; + } + } return QWidget::eventFilter(watched, event); diff --git a/src/frontend/tab-pages/lanpage.h b/src/frontend/tab-pages/lanpage.h index ee2d6988..613be83a 100644 --- a/src/frontend/tab-pages/lanpage.h +++ b/src/frontend/tab-pages/lanpage.h @@ -98,7 +98,6 @@ private slots: void onUpdateConnection(QString uuid); void onSwithGsettingsChanged(const QString &key); - void onLanSwitchClicked(); void onDeviceAdd(QString deviceName, NetworkManager::Device::Type deviceType); void onDeviceRemove(QString deviceName); @@ -129,7 +128,6 @@ private: QGSettings *m_switchGsettings = nullptr; - bool m_wiredSwitch = true; }; #endif // LANPAGE_H diff --git a/src/frontend/tab-pages/tabpage.cpp b/src/frontend/tab-pages/tabpage.cpp index 6140352f..08f540d7 100644 --- a/src/frontend/tab-pages/tabpage.cpp +++ b/src/frontend/tab-pages/tabpage.cpp @@ -29,7 +29,7 @@ void TabPage::initUI() m_titleLayout = new QHBoxLayout(m_titleFrame); m_titleLayout->setContentsMargins(TITLE_LAYOUT_MARGINS); m_titleLabel = new QLabel(m_titleFrame); - m_netSwitch = new SwitchButton(m_titleFrame); + m_netSwitch = new KSwitchButton(m_titleFrame); m_titleLayout->addWidget(m_titleLabel); m_titleLayout->addStretch(); m_titleLayout->addWidget(m_netSwitch); diff --git a/src/frontend/tab-pages/tabpage.h b/src/frontend/tab-pages/tabpage.h index 599bfeb3..35d4fc3e 100644 --- a/src/frontend/tab-pages/tabpage.h +++ b/src/frontend/tab-pages/tabpage.h @@ -15,6 +15,10 @@ #include #include #include "kylinnetworkdeviceresource.h" +#include "kwidget.h" +#include "kswitchbutton.h" + +using namespace kdk; #define MAIN_LAYOUT_MARGINS 0,0,0,0 #define MAIN_LAYOUT_SPACING 0 @@ -93,7 +97,7 @@ protected: QFrame * m_titleFrame = nullptr; QHBoxLayout * m_titleLayout = nullptr; QLabel * m_titleLabel = nullptr; - SwitchButton * m_netSwitch = nullptr; + KSwitchButton * m_netSwitch = nullptr; Divider * m_titleDivider = nullptr; QFrame * m_activatedNetFrame = nullptr; diff --git a/src/frontend/tab-pages/wlanpage.cpp b/src/frontend/tab-pages/wlanpage.cpp index 7b03dcaa..99be027d 100644 --- a/src/frontend/tab-pages/wlanpage.cpp +++ b/src/frontend/tab-pages/wlanpage.cpp @@ -63,6 +63,16 @@ bool WlanPage::eventFilter(QObject *w, QEvent *e) //ZJP_TODO 打开控制面板 qDebug() << LOG_FLAG <<"recive event show control center"; showControlCenter(); + } else if (w == m_netSwitch) { + if (m_devList.isEmpty()) { + showDesktopNotify(tr("No wireless network card detected"), "networkwrong"); + //检测不到无线网卡不再触发click信号 + m_netSwitch->setCheckable(false); + m_netSwitch->setChecked(false); + } else { + m_wirelessConnectOpreation->setWirelessEnabled(!m_netSwitch->isChecked()); + } + return true; } } @@ -102,6 +112,7 @@ void WlanPage::initWlanUI() m_inactivatedNetListWidget->setPalette(pal); m_settingsLabel->installEventFilter(this); + m_netSwitch->installEventFilter(this); } @@ -110,7 +121,9 @@ void WlanPage::onWlanSwithGsettingsChanged(const QString &key) if (key == WIRELESS_SWITCH) { m_wlanSwitchEnable = m_switchGsettings->get(WIRELESS_SWITCH).toBool(); qDebug() << LOG_FLAG << "wlan switch state" << m_wlanSwitchEnable; - m_netSwitch->setSwitchStatus(m_wlanSwitchEnable); + + m_netSwitch->setChecked(m_wlanSwitchEnable); + initDeviceCombox(); initWlanArea(); } @@ -118,57 +131,26 @@ void WlanPage::onWlanSwithGsettingsChanged(const QString &key) return; } -/** - * @brief WlanPage::onWlanSwitchClicked 点击无线网开关 - */ -void WlanPage::onWlanSwitchClicked() -{ - if (m_devList.isEmpty()) { - showDesktopNotify(tr("No wireless network card detected"), "networkwrong"); - //检测不到无线网卡不再触发click信号 - m_netSwitch->setSwitchStatus(false); - m_netSwitch->setEnabled(false); - } else { - bool switchEnable = m_netSwitch->getSwitchStatus(); - if (m_wlanSwitchEnable != switchEnable) { - qDebug()<< LOG_FLAG << "wlan switch state " << switchEnable; - m_wirelessConnectOpreation->setWirelessEnabled(switchEnable); - if (!switchEnable) { - m_netSwitch->setEnabled(false); - m_activatedNetFrame->hide(); - m_activatedNetDivider->hide(); - m_inactivatedNetFrame->hide(); - m_deviceFrame->hide(); - } - } - } - - return; -} - void WlanPage::initWlanSwitchState() { - m_wlanSwitchEnable = m_wirelessConnectOpreation->getWirelessEnabled(); - if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA)) { m_switchGsettings = new QGSettings(GSETTINGS_SCHEMA); if (m_switchGsettings->keys().contains(WIRELESS_SWITCH)) { if (m_devList.isEmpty()) { - m_wlanSwitchEnable = false; - m_netSwitch->setSwitchStatus(m_wlanSwitchEnable); - m_netSwitch->setEnabled(false); + m_netSwitch->setCheckable(false); + m_netSwitch->setChecked(false); } else { - m_wlanSwitchEnable = m_switchGsettings->get(WIRELESS_SWITCH).toBool(); + bool wiredGsetting = m_switchGsettings->get(WIRELESS_SWITCH).toBool(); + if (m_wirelessConnectOpreation->getWirelessEnabled() + != wiredGsetting) { + //以gsetting为准 + m_wirelessConnectOpreation->setWirelessEnabled(wiredGsetting); + } + m_netSwitch->setChecked(wiredGsetting); } connect(m_switchGsettings, &QGSettings::changed, this, &WlanPage::onWlanSwithGsettingsChanged); } } - m_netSwitch->setSwitchStatus(m_wlanSwitchEnable); - - - connect(m_netSwitch, &SwitchButton::clicked, this, &WlanPage::onWlanSwitchClicked); - - return; } void WlanPage::initTimer() @@ -200,7 +182,7 @@ void WlanPage::initDeviceCombox() this, &WlanPage::onDeviceComboxIndexChanged); m_deviceComboBox->clear(); - if (m_wlanSwitchEnable) { + if (m_netSwitch->isChecked()) { if (0 == m_devList.count()) { m_deviceFrame->show(); m_tipsLabel->show(); @@ -472,7 +454,7 @@ void WlanPage::constructWirelessNetArea() void WlanPage::initWlanArea() { - if (m_wlanSwitchEnable) { + if (m_netSwitch->isChecked()) { m_activatedNetFrame->show(); m_activatedNetDivider->show(); constructActivateConnectionArea(); @@ -633,7 +615,7 @@ void WlanPage::addDeviceToCombox(QString deviceName) { disconnect(m_deviceComboBox, QOverload::of(&QComboBox::currentIndexChanged), this, &WlanPage::onDeviceComboxIndexChanged); - if (m_wlanSwitchEnable) { + if (m_netSwitch->isChecked()) { if (m_currentDevice.isEmpty()){ m_deviceFrame->hide(); m_currentDevice = deviceName; @@ -666,9 +648,9 @@ void WlanPage::onDeviceAdd(QString deviceName, NetworkManager::Device::Type devi } if (m_devList.isEmpty()) { - m_wlanSwitchEnable = m_switchGsettings->get(WIRELESS_SWITCH).toBool(); - m_netSwitch->setEnabled(true); - m_netSwitch->setSwitchStatus(m_wlanSwitchEnable); + bool wlanSwitch = m_switchGsettings->get(WIRELESS_SWITCH).toBool(); + m_netSwitch->setCheckable(true); + m_netSwitch->setChecked(wlanSwitch); } m_devList << deviceName; @@ -687,7 +669,7 @@ void WlanPage::deleteDeviceFromCombox(QString deviceName) disconnect(m_deviceComboBox, QOverload::of(&QComboBox::currentIndexChanged), this, &WlanPage::onDeviceComboxIndexChanged); - if (m_wlanSwitchEnable) { + if (m_netSwitch->isChecked()) { if (0 == m_devList.count()) { m_deviceFrame->hide(); //m_tipsLabel->show(); @@ -728,9 +710,8 @@ void WlanPage::onDeviceRemove(QString deviceName) deleteDeviceFromCombox(deviceName); if (m_devList.isEmpty()) { - m_wlanSwitchEnable = false; - m_netSwitch->setSwitchStatus(m_wlanSwitchEnable); - m_netSwitch->setEnabled(false); + m_netSwitch->setCheckable(false); + m_netSwitch->setChecked(false); } if (originalDeviceName == deviceName) { @@ -1042,8 +1023,8 @@ void WlanPage::onWifiEnabledChanged(bool isWifiOn) if (m_wlanSwitchEnable == isWifiOn) { return; } else { - if (!m_netSwitch->getEnabled()) { - m_netSwitch->setEnabled(true); + if (!m_netSwitch->isChecked()) { + m_netSwitch->setChecked(true); } m_switchGsettings->set(WIRELESS_SWITCH, isWifiOn); } @@ -1394,12 +1375,13 @@ void WlanPage::setWirelessSwitchEnable(bool enable) if (m_devList.isEmpty()) { qDebug() << "have no device to use " << Q_FUNC_INFO << __LINE__; //检测不到无线网卡不再触发click信号 - m_netSwitch->setSwitchStatus(false); - //m_netSwitch->setEnabled(false); +// m_netSwitch->setSwitchStatus(false); + m_netSwitch->setEnabled(false); }else{ m_wirelessConnectOpreation->setWirelessEnabled(enable); if (!enable) { - m_netSwitch->setEnabled(false); +// m_netSwitch->setEnabled(false); + m_netSwitch->setChecked(false); m_activatedNetFrame->hide(); m_activatedNetDivider->hide(); m_inactivatedNetFrame->hide(); diff --git a/src/frontend/tab-pages/wlanpage.h b/src/frontend/tab-pages/wlanpage.h index 270af216..7eea2d41 100644 --- a/src/frontend/tab-pages/wlanpage.h +++ b/src/frontend/tab-pages/wlanpage.h @@ -93,7 +93,7 @@ private slots: NetworkManager::ActiveConnection::Reason reason); void onItemHeightChanged(const bool isExpanded, const QString &ssid); - void onWlanSwitchClicked(); +// void onWlanSwitchClicked(); void onWlanSwithGsettingsChanged(const QString &key); void onDeviceComboxIndexChanged(int currentIndex);