SDK替换switchbutton
This commit is contained in:
parent
01ed3caba8
commit
7ee7420473
|
@ -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:" <<m_netSwitch->getSwitchStatus()
|
||||
<<"devices count:"<<m_devList.count();
|
||||
|
||||
if (m_devList.count() == 0) {
|
||||
this->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<int>::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<int>::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:" <<m_netSwitch->isChecked()
|
||||
<<"devices count:"<<m_devList.count();
|
||||
|
||||
if (m_devList.count() == 0) {
|
||||
this->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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -15,6 +15,10 @@
|
|||
#include <QProcess>
|
||||
#include <QDebug>
|
||||
#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;
|
||||
|
|
|
@ -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<int>::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<int>::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();
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue