Merge branch '0607-dev' into 'main'

Some new functions

See merge request kylin-desktop/kylin-nm!14
This commit is contained in:
chen lelin 2021-06-08 03:14:36 +00:00
commit b6587dd2cf
9 changed files with 229 additions and 11 deletions

16
debian/changelog vendored
View File

@ -1,3 +1,19 @@
kylin-nm (3.0.1-1kylin50) v101; urgency=medium
* BUG号
* 需求号:#33373 #33309 #33960
* 其他改动:无
-- zhangjiaping <zhangjiaping@kylinos.cn> Mon, 07 Jun 2021 16:17:18 +0800
kylin-nm (3.0.1-1kylin49hw1) v101; urgency=medium
* BUG号#56269 #54745 #54354 #50457
* 需求号:无
* 其他改动:无
-- zhangjiaping <zhangjiaping@kylinos.cn> Sat, 05 Jun 2021 14:43:32 +0800
kylin-nm (3.0.1-1kylin49) v101; urgency=medium
* BUG号

View File

@ -82,7 +82,9 @@ IFace* BackThread::execGetIface()
if (istateStr == "unmanaged") {
iface->lstate = 2; //switch of wired device is off
} else if (istateStr == "disconnected" || istateStr == "unavailable") {
} else if (istateStr == "unavailable") {
iface->lstate = 4;
} else if (istateStr == "disconnected") {
iface->lstate = 1; //wired network is disconnected
} else if (istateStr == "connected" || istateStr == "connecting (getting IP configuration)") {
iface->lstate = 0; //wired network is connected
@ -112,6 +114,25 @@ IFace* BackThread::execGetIface()
return iface;
}
void BackThread::saveSwitchButtonState(const QString &key, const QVariant &value)
{
QSettings * m_settings = new QSettings(CONFIG_FILE_PATH, QSettings::IniFormat);
m_settings->setValue(key, value);
m_settings->sync();
delete m_settings;
return;
}
QVariant BackThread::getSwitchState(const QString &key)
{
QSettings * m_settings = new QSettings(CONFIG_FILE_PATH, QSettings::IniFormat);
QVariant value = m_settings->value(key);
delete m_settings;
if (!value.isValid())
return QVariant();
return value;
}
//turn on the switch of network
void BackThread::execEnNet()
{

View File

@ -29,6 +29,11 @@
#include <QDBusInterface>
#include <QDBusMessage>
#include <QDBusArgument>
#include <QSettings>
#define CONFIG_FILE_PATH QDir::homePath() + "/.config/ukui/kylin-nm.conf"
#define WIFI_SWITCH_OPENED "wifi_switch_opened"
#define LAN_SWITCH_OPENED "lan_switch_opened"
class IFace{
public:
@ -45,7 +50,9 @@ public:
explicit BackThread(QObject *parent = nullptr);
~BackThread();
IFace* execGetIface();
static IFace* execGetIface();
static void saveSwitchButtonState(const QString &key, const QVariant &value);
static QVariant getSwitchState(const QString &key);
QString getConnProp(QString connName);
QString execChkLanWidth(QString ethName);
QProcess *cmdProcessWifi = nullptr;

View File

@ -294,6 +294,7 @@ void ConfForm::on_btnCreate_clicked()
}
}
}
cmdStr += " connection.autoconnect yes connection.autoconnect-priority 0";
Utils::m_system(cmdStr.toUtf8().data());
if (ui->cbType->currentIndex() == 1) {

View File

@ -129,6 +129,37 @@ MainWindow::MainWindow(QWidget *parent) :
qDebug()<<"Init button connections...";
connect(ui->btnNetList, &QPushButton::clicked, this, &MainWindow::onBtnNetListClicked);
connect(btnWireless, &SwitchButton::clicked,this, &MainWindow::onBtnWifiClicked);
connect(btnWired, &SwitchButton::clicked, this, &MainWindow::onBtnLanClicked);
connect(this, &MainWindow::onWiredDeviceChanged, this, &MainWindow::setLanSwitchStatus);
QVariant wifi_state = BackThread::getSwitchState(WIFI_SWITCH_OPENED);
QVariant lan_state = BackThread::getSwitchState(LAN_SWITCH_OPENED);
if (!wifi_state.isNull() && wifi_state.isValid()) {
//设置WiFi开关状态
if (wifi_state.toBool() && !btnWireless->getSwitchStatus())
onBtnWifiClicked(1);
else if (!wifi_state.toBool() && btnWireless->getSwitchStatus())
onBtnWifiClicked(0);
}
if (!lan_state.isNull() && lan_state.isValid()) {
//设置lan开关状态
if (lan_state.toBool() && !btnWired->getSwitchStatus())
onBtnLanClicked(1);
else if (!lan_state.toBool() && btnWired->getSwitchStatus())
onBtnLanClicked(0);
}
connect(btnWired, &SwitchButton::switchStatusChanged, this, [ = ]() {
BackThread::saveSwitchButtonState(LAN_SWITCH_OPENED, btnWired->getSwitchStatus());
});
connect(btnWireless, &SwitchButton::switchStatusChanged, this, [ = ]() {
BackThread::saveSwitchButtonState(WIFI_SWITCH_OPENED, btnWireless->getSwitchStatus());
});
if (!objKyDBus->isWiredCableOn) {
btnWired->blockSignals(true);
btnWired->setSwitchStatus(false);
btnWired->setEnabled(false);
btnWired->blockSignals(false);
}
ui->btnNetList->setAttribute(Qt::WA_Hover,true);
ui->btnNetList->installEventFilter(this);
@ -365,6 +396,8 @@ void MainWindow::createLeftAreaUI()
qDebug()<<"Creating Left Area Ui...";
btnWireless = new SwitchButton(this);
btnWireless->setStyleSheet("SwitchButton{border:none;background-color:rgba(255,255,255,0.12);}");
btnWired = new SwitchButton(this);
btnWired->setStyleSheet("SwitchButton{border:none;background-color:rgba(255,255,255,0.12);}");
ui->btnNetList->setFocusPolicy(Qt::NoFocus);
QString txtEthernet(tr("Ethernet"));
ui->btnNetList->setToolTip(txtEthernet);
@ -375,10 +408,13 @@ void MainWindow::createLeftAreaUI()
paletteLan.setBrush(QPalette::Button, QBrush(QColor(1,1,1,0)));
ui->btnNetListImg->setPalette(paletteLan);
//添加PushButton的svg图片
if (!QIcon::fromTheme("network-wired-symbolic").isNull())
if (!QIcon::fromTheme("network-wired-connected-symbolic").isNull()) {
ui->btnNetListImg->setIcon(QIcon::fromTheme("network-wired-connected-symbolic"));
} else if (!QIcon::fromTheme("network-wired-symbolic").isNull()) {
ui->btnNetListImg->setIcon(QIcon::fromTheme("network-wired-symbolic"));
else
} else {
ui->btnNetListImg->setIcon(QIcon(":/res/x/net-list-bg.svg"));
}
ui->btnNetListImg->setProperty("useIconHighlightEffect", true);
ui->btnNetListImg->setProperty("iconHighlightEffectMode", true);
@ -402,6 +438,7 @@ void MainWindow::createLeftAreaUI()
ui->btnNet->hide();
btnWireless->setGeometry(412,20,50,24);
btnWired->setGeometry(412,20,50,24);
ui->btnHotspot->setStyleSheet(leftBtnQss);
ui->btnHotspot->setFocusPolicy(Qt::NoFocus);
@ -644,8 +681,18 @@ void MainWindow::createTrayIcon()
trayIcon->setContextMenu(trayIconMenu);
// 初始化托盘所有Icon
iconLanOnline = QIcon::fromTheme("network-wired-symbolic");
iconLanOffline = QIcon::fromTheme("network-wired-offline-symbolic");
if (!QIcon::fromTheme("network-wired-connected-symbolic").isNull()) {
iconLanOnline = QIcon::fromTheme("network-wired-connected-symbolic");
} else if (!QIcon::fromTheme("network-wired-symbolic").isNull()) {
iconLanOnline = QIcon::fromTheme("network-wired-symbolic");
} else {
iconLanOnline = QIcon(":/res/x/net-list-bg.svg");
}
if (!QIcon::fromTheme("network-wired-disconnected-symbolic").isNull()) {
iconLanOffline = QIcon::fromTheme("network-wired-disconnected-symbolic");
} else {
iconLanOffline = QIcon::fromTheme("network-wired-offline-symbolic");
}
iconWifiFull = QIcon::fromTheme("network-wireless-signal-excellent-symbolic");
iconWifiHigh = QIcon::fromTheme("network-wireless-signal-good-symbolic");
iconWifiMedium = QIcon::fromTheme("network-wireless-signal-ok");
@ -999,6 +1046,7 @@ void MainWindow::onPhysicalCarrierChanged(bool flag)
qDebug()<<"wired physical cable is already plug in";
//syslog(LOG_DEBUG,"wired physical cable is already plug in");
wiredCableUpTimer->start(4000);
// onBtnLanClicked(4);
} else {
qDebug()<<"wired physical cable is already plug out";
//syslog(LOG_DEBUG,"wired physical cable is already plug out");
@ -1011,6 +1059,7 @@ void MainWindow::onPhysicalCarrierChanged(bool flag)
sleep(2);
//wiredCableDownTimer->start(2000);
emit carrierDownHandle();
emit btnWired->clicked(5);
delete iface;
bt->deleteLater();
break;
@ -1034,6 +1083,7 @@ void MainWindow::onCarrierUpHandle()
onBtnNetListClicked(1);
is_stop_check_net_state = 0;
isHandlingWiredCableOn = false;
emit btnWired->clicked(4);
}
void MainWindow::onCarrierDownHandle()
@ -1090,6 +1140,8 @@ void MainWindow::onNetworkDeviceAdded(QDBusObjectPath objPath)
//仅处理无线网卡插入情况
objKyDBus->isWirelessCardOn = false;
objKyDBus->getObjectPath();
if (objKyDBus->multiWirelessPaths.isEmpty())
return;
if (objKyDBus->multiWirelessPaths.at(0).path() == objPath.path()) { //证明添加的是无线网卡
is_wireless_adapter_ready = 0;
@ -1105,6 +1157,8 @@ void MainWindow::onNetworkDeviceAdded(QDBusObjectPath objPath)
void MainWindow::onNetworkDeviceRemoved(QDBusObjectPath objPath)
{
if (objKyDBus->multiWirelessPaths.isEmpty())
return;
//仅处理无线网卡拔出情况
if (objKyDBus->multiWirelessPaths.at(0).path() == objPath.path()) {
objKyDBus->isWirelessCardOn = false;
@ -1304,6 +1358,82 @@ void MainWindow::onBtnWifiClicked(int flag)
}
}
/**
* @brief MainWindow::onBtnLanClicked 线
* @param flag falg=0 0 UI关闭 1 UI打开 234线5线
*/
void MainWindow::onBtnLanClicked(int flag)
{
switch (flag) {
case 0: {
qDebug()<<"On btnWired clicked! will close switch button";
QtConcurrent::run([=]() {
QString close_device_cmd = "nmcli device set " + llname + " managed false";
int res = system(close_device_cmd.toUtf8().data());
qDebug()<<"Trying to close ethernet device : "<<llname<<". res="<<res;
if (res == 0) {
emit this->onWiredDeviceChanged(false);
} else {
qWarning()<<"Close ethernet device failed!";
}
});
break;
}
case 1: {
qDebug()<<"On btnWired clicked! will open switch button";
QtConcurrent::run([=]() {
QString open_device_cmd = "nmcli device set " + llname + " managed true";
int res = system(open_device_cmd.toUtf8().data());
qDebug()<<"Trying to open ethernet device : "<<llname<<". res="<<res;
if (res == 0) {
emit this->onWiredDeviceChanged(true);
} else {
qWarning()<<"Open ethernet device failed!";
}
});
break;
}
case 2: {
emit this->onWiredDeviceChanged(true);
break;
}
case 3: {
emit this->onWiredDeviceChanged(false);
break;
}
case 4: {
btnWired->setEnabled(true);
qDebug()<<"Set btnwired enabled=true!";
//获取有线设备托管状态,是否需要打开开关
if (BackThread::execGetIface()->lstate != 2) {
emit this->onWiredDeviceChanged(true);
}
break;
}
case 5: {
btnWired->blockSignals(true);
btnWired->setSwitchStatus(false);
qDebug()<<"Set btnwired enabled=false!";
btnWired->setEnabled(false);
btnWired->blockSignals(false);
break;
}
default:
break;
}
}
void MainWindow::setLanSwitchStatus(bool is_opened)
{
if (is_opened) {
btnWired->setSwitchStatus(true);
ksnm->execGetLanList();
} else {
btnWired->setSwitchStatus(false);
ksnm->execGetLanList();
}
}
void MainWindow::onBtnNetListClicked(int flag)
{
this->is_btnLanList_clicked = 1;
@ -1326,6 +1456,7 @@ void MainWindow::onBtnNetListClicked(int flag)
ui->lbNetwork->setText(tr("Ethernet"));
btnWireless->hide();
btnWired->show();
// 强行设置为打开
if (flag == 1) {
@ -1338,7 +1469,7 @@ void MainWindow::onBtnNetListClicked(int flag)
return;
}
if (iface->lstate == 0 || iface->lstate == 1) {
if (iface->lstate == 0 || iface->lstate == 1 || iface->lstate == 4) {
this->startLoading();
this->ksnm->execGetLanList();
} else if (iface->lstate == 3) {
@ -1393,6 +1524,7 @@ void MainWindow::on_btnWifiList_clicked()
ui->lbNetwork->setText("WLAN");
btnWireless->show();
btnWired->hide();
if (iface->wstate == 0 || iface->wstate == 1) {
qDebug()<<"现在的WiFi的开关是已经打开状态";
@ -1774,6 +1906,13 @@ void MainWindow::getLanListDone(QStringList slist)
this->stopLoading();
oldLanSlist = slist;
is_stop_check_net_state = 0;
//有线网按钮状态校准
if (btnWired->isEnabled() && !objKyDBus->isWiredCableOn) {
emit btnWired->clicked(5);
}
if (btnWired->isEnabled() && !btnWired->getSwitchStatus() && BackThread::execGetIface()->lstate != 2) {
btnWired->setSwitchStatus(true);
}
}
// 获取wifi列表回调
@ -3526,6 +3665,7 @@ void MainWindow::disNetDone()
ui->lbNetwork->setText(tr("Ethernet"));
btnWireless->hide();
btnWired->show();
delete topLanListWidget; // 清空top列表
createTopLanUI(); //创建顶部有线网item

View File

@ -160,7 +160,8 @@ public:
QString mwBandWidth;
KylinDBus *objKyDBus = nullptr;
NetworkSpeed *objNetSpeed = nullptr;
SwitchButton *btnWireless;
SwitchButton *btnWireless = nullptr;
SwitchButton *btnWired = nullptr;
//状态设置,0为假1为真
int current_wifi_list_state = LOAD_WIFI_LIST;
@ -241,6 +242,9 @@ public slots:
//flag =0或1为普通点击、2为收到打开信息、3为收到关闭信息、4为无线网卡插入、5为无线网卡拔出
void onBtnWifiClicked(int flag = 0);
//falg=0 UI点击1收到打开信息2收到关闭信息3有线设备插入4有线设备拔出
void onBtnLanClicked(int flag = 0);
void setLanSwitchStatus(bool is_opened);
void on_showWindowAction();
@ -430,6 +434,7 @@ signals:
void wiredConnectionRemoved();
void actWiredConnectionChanged();
void requestReconnecWifi();
void onWiredDeviceChanged(const bool&);
};
#endif // MAINWINDOW_H

View File

@ -282,9 +282,17 @@ void OneLancForm::setLanInfo(QString str1, QString str2, QString str3, QString s
void OneLancForm::setIcon(bool isOn)
{
if (isOn) {
ui->lbIcon->setStyleSheet("QLabel{border-radius:0px;background:url(:/res/l/network-online.png);}");
if (!QIcon::fromTheme("network-wired-connected-symbolic").isNull()) {
ui->lbIcon->setPixmap(QIcon::fromTheme("network-wired-connected-symbolic").pixmap(32,32));
} else {
ui->lbIcon->setPixmap(QIcon(":/res/l/network-online.png").pixmap(32,32));
}
} else {
ui->lbIcon->setStyleSheet("QLabel{border-radius:0px;background:url(:/res/l/network-offline.png);}");
if (!QIcon::fromTheme("network-wired-disconnected-symbolic").isNull()) {
ui->lbIcon->setPixmap(QIcon::fromTheme("network-wired-disconnected-symbolic").pixmap(32,32));
} else {
ui->lbIcon->setPixmap(QIcon(":/res/l/network-offline.png").pixmap(32,32));
}
}
}

View File

@ -38,15 +38,29 @@ SwitchButton::SwitchButton(QWidget *parent) : QWidget(parent)
}
void SwitchButton::setSwitchStatus(bool check) {
if (!m_enabled)
return;
if(check == true) {
m_bIsOn = 1;
} else {
m_bIsOn = 0;
}
emit this->switchStatusChanged();
m_cTimer->start(); //开始播放动画
}
bool SwitchButton::getSwitchStatus()
{
if (m_bIsOn == 1)
return true;
return false;
}
void SwitchButton::setEnabled(bool enabled)
{
m_enabled = enabled;
}
/* 播放按钮开启关闭动画 */
void SwitchButton::startAnimation() { //滑动按钮动作播放
@ -72,6 +86,8 @@ void SwitchButton::startAnimation() { //滑动按钮动作播放
/* 按钮按下处理 */
void SwitchButton::mousePressEvent(QMouseEvent *event) {
Q_UNUSED(event);
if (!m_enabled)
return QWidget::mousePressEvent(event);
m_bIsOn = !m_bIsOn;
Q_EMIT clicked(m_bIsOn);

View File

@ -29,6 +29,8 @@ class SwitchButton : public QWidget
public:
explicit SwitchButton(QWidget *parent = nullptr);
void setSwitchStatus(bool check);
bool getSwitchStatus();
void setEnabled(bool enabled);
private:
int m_bIsOn = 1;
@ -38,9 +40,11 @@ private:
float m_fCurrentValue;
void paintEvent(QPaintEvent *event);
void mousePressEvent(QMouseEvent *event);
bool m_enabled = true;
Q_SIGNALS:
void clicked(int check);
void switchStatusChanged();
private Q_SLOTS:
void startAnimation();