Merge branch 'plugin-zdev' into 'dbus-interface'

Task #107168: 控制面板网络状态显示 网络连接/断开/删除入口功能优化

See merge request kylin-desktop/kylin-nm!707
This commit is contained in:
赵世旭 2022-10-18 04:00:08 +00:00
commit 3af4488c9a
14 changed files with 242 additions and 28 deletions

View File

@ -47,11 +47,28 @@ LanItem::LanItem(bool isAcitve, QWidget *parent)
statusLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
// statusLabel->setMinimumSize(36,36);
infoLabel = new GrayInfoButton(this);
//【更多】菜单
m_moreButton = new QToolButton(this);
m_moreButton->setProperty("useButtonPalette", true);
m_moreButton->setPopupMode(QToolButton::InstantPopup);
m_moreButton->setAutoRaise(true);
m_moreButton->setIcon(QIcon::fromTheme("view-more-horizontal-symbolic"));
m_moreMenu = new QMenu(m_moreButton);
m_connectAction = new QAction(m_moreMenu);
m_deleteAction = new QAction(tr("Delete"), m_moreMenu);
setConnectActionText(isAcitve);
m_moreMenu->addAction(m_connectAction);
m_moreMenu->addAction(m_deleteAction);
m_moreButton->setMenu(m_moreMenu);
mLanLyt->addWidget(iconLabel);
mLanLyt->addWidget(titileLabel,Qt::AlignLeft);
mLanLyt->addStretch();
mLanLyt->addWidget(statusLabel);
mLanLyt->addWidget(infoLabel);
mLanLyt->addWidget(m_moreButton);
loadIcons.append(QIcon::fromTheme("ukui-loading-1-symbolic"));
loadIcons.append(QIcon::fromTheme("ukui-loading-2-symbolic"));
@ -62,6 +79,10 @@ LanItem::LanItem(bool isAcitve, QWidget *parent)
loadIcons.append(QIcon::fromTheme("ukui-loading-7-symbolic"));
waitTimer = new QTimer(this);
connect(waitTimer, &QTimer::timeout, this, &LanItem::updateIcon);
connect(m_connectAction, &QAction::triggered, this, &LanItem::onConnectTriggered);
connect(m_deleteAction, &QAction::triggered, this, &LanItem::onDeletetTriggered);
m_moreMenu->installEventFilter(this);
}
LanItem::~LanItem()
@ -89,6 +110,40 @@ void LanItem::stopLoading(){
loading = false;
}
/**
* @brief LanItem::setConnectActionText
* /
* @param isAcitve
*/
void LanItem::setConnectActionText(bool isAcitve)
{
if (isAcitve) {
m_connectAction->setText(tr("Disconnect"));
} else {
m_connectAction->setText(tr("Connect"));
}
}
void LanItem::onConnectTriggered()
{
if (!m_connectAction) {
return;
}
if (m_connectAction->text() == tr("Connect")) {
Q_EMIT connectActionTriggered();
} else if (m_connectAction->text() == tr("Disconnect")) {
Q_EMIT disconnectActionTriggered();
}
}
void LanItem::onDeletetTriggered()
{
if (!m_deleteAction) {
return;
}
Q_EMIT deleteActionTriggered();
}
void LanItem::paintEvent(QPaintEvent *event)
{
QPalette pal = this->palette();
@ -104,3 +159,18 @@ void LanItem::paintEvent(QPaintEvent *event)
QPushButton::paintEvent(event);
}
bool LanItem::eventFilter(QObject *watched, QEvent *event)
{
//菜单右边界与按钮右边界对齐
if (event->type() == QEvent::Show && watched == m_moreMenu) {
int menuXPos = m_moreMenu->pos().x();
int menuWidth = m_moreMenu->size().width();
int btnWidth = m_moreButton->size().width();
QPoint pos = QPoint (menuXPos - menuWidth + btnWidth, m_moreMenu->pos().y());
m_moreMenu->move(pos);
return true;
}
return false;
}

View File

@ -29,12 +29,16 @@
#include <QDebug>
#include <QImage>
#include <QPainter>
#include <QToolButton>
#include <QMenu>
#include <QEvent>
#include "fixlabel.h"
//#include "infobutton.h"
#include "../component/AddBtn/grayinfobutton.h"
class LanItem : public QPushButton
{
Q_OBJECT
public:
LanItem(bool isAcitve, QWidget *parent = nullptr);
~LanItem();
@ -43,10 +47,15 @@ public:
GrayInfoButton * infoLabel = nullptr;
FixLabel * titileLabel = nullptr;
QLabel * statusLabel = nullptr;
QToolButton* m_moreButton = nullptr;
QMenu* m_moreMenu = nullptr;
QAction* m_connectAction = nullptr;
QAction* m_deleteAction = nullptr;
public:
void startLoading();
void stopLoading();
void setConnectActionText(bool isAcitve);
bool loading = false;
bool isAcitve = false;
@ -56,15 +65,23 @@ public:
protected:
void paintEvent(QPaintEvent *);
bool eventFilter(QObject *watched, QEvent *event);
private:
QTimer *waitTimer = nullptr;
QGSettings *themeGsettings = nullptr;
QList<QIcon> loadIcons;
int currentIconIndex=0;
int currentIconIndex=0;
private slots:
void updateIcon();
void updateIcon();
void onConnectTriggered();
void onDeletetTriggered();
Q_SIGNALS:
void connectActionTriggered();
void disconnectActionTriggered();
void deleteActionTriggered();
};

View File

@ -355,6 +355,14 @@ void NetConnect::runExternalApp() {
process.startDetached(cmd);
}
//刪除
void NetConnect::deleteOneLan(QString ssid, int type)
{
qDebug() << "[NetConnect]call deleteConnect" << __LINE__;
m_interface->call(QStringLiteral("deleteConnect"), type, ssid);
qDebug() << "[NetConnect]call deleteConnect respond" << __LINE__;
}
//激活
void NetConnect::activeConnect(QString ssid, QString deviceName, int type) {
qDebug() << "[NetConnect]call activateConnect" << __LINE__;
@ -423,12 +431,12 @@ void NetConnect::addLanItem(ItemFrame *frame, QString devName, QStringList infoL
return;
}
LanItem * lanItem = new LanItem(pluginWidget);
LanItem * lanItem = new LanItem(isActived, pluginWidget);
QString iconPath = KLanSymbolic;
if (isActived) {
lanItem->statusLabel->setText(tr("connected"));
} else {
lanItem->statusLabel->setText("");
lanItem->statusLabel->setText(tr("not connected"));
}
QIcon searchIcon = QIcon::fromTheme(iconPath);
// if (iconPath != KLanSymbolic && iconPath != NoNetSymbolic) {
@ -451,6 +459,7 @@ void NetConnect::addLanItem(ItemFrame *frame, QString devName, QStringList infoL
});
lanItem->isAcitve = isActived;
lanItem->setConnectActionText(lanItem->isAcitve);
connect(lanItem, &QPushButton::clicked, this, [=] {
if (lanItem->isAcitve || lanItem->loading) {
@ -460,6 +469,16 @@ void NetConnect::addLanItem(ItemFrame *frame, QString devName, QStringList infoL
}
});
connect(lanItem, &LanItem::connectActionTriggered, this, [=] {
activeConnect(lanItem->uuid, devName, WIRED_TYPE);
});
connect(lanItem, &LanItem::disconnectActionTriggered, this, [=] {
deActiveConnect(lanItem->uuid, devName, WIRED_TYPE);
});
connect(lanItem, &LanItem::deleteActionTriggered, this, [=] {
deleteOneLan(lanItem->uuid, WIRED_TYPE);
});
//记录到deviceFrame的itemMap中
deviceFrameMap[devName]->itemMap.insert(infoList.at(1), lanItem);
qDebug()<<"insert " << infoList.at(1) << " to " << devName << " list";
@ -709,7 +728,7 @@ void NetConnect::addOneLanFrame(ItemFrame *frame, QString deviceName, QStringLis
QString iconPath;
iconPath = KLanSymbolic;
lanItem->statusLabel->setText("");
lanItem->statusLabel->setText(tr("not connected"));
QIcon searchIcon = QIcon::fromTheme(iconPath);
// if (iconPath != KLanSymbolic && iconPath != NoNetSymbolic) {
@ -732,6 +751,7 @@ void NetConnect::addOneLanFrame(ItemFrame *frame, QString deviceName, QStringLis
});
lanItem->isAcitve = false;
lanItem->setConnectActionText(lanItem->isAcitve);
connect(lanItem, &QPushButton::clicked, this, [=] {
if (lanItem->isAcitve || lanItem->loading) {
@ -741,6 +761,16 @@ void NetConnect::addOneLanFrame(ItemFrame *frame, QString deviceName, QStringLis
}
});
connect(lanItem, &LanItem::connectActionTriggered, this, [=] {
activeConnect(lanItem->uuid, deviceName, WIRED_TYPE);
});
connect(lanItem, &LanItem::disconnectActionTriggered, this, [=] {
deActiveConnect(lanItem->uuid, deviceName, WIRED_TYPE);
});
connect(lanItem, &LanItem::deleteActionTriggered, this, [=] {
deleteOneLan(lanItem->uuid, WIRED_TYPE);
});
//记录到deviceFrame的itemMap中
deviceFrameMap[deviceName]->itemMap.insert(connUuid, lanItem);
int index = getInsertPos(connName, deviceName);
@ -855,7 +885,9 @@ void NetConnect::itemActiveConnectionStatusChanged(LanItem *item, int status)
item->statusLabel->setMaximumSize(16777215,16777215);
item->statusLabel->clear();
item->isAcitve = false;
item->statusLabel->setText(tr("not connected"));
}
item->setConnectActionText(item->isAcitve);
// QIcon searchIcon = QIcon::fromTheme(iconPath);
// item->iconLabel->setPixmap(searchIcon.pixmap(searchIcon.actualSize(QSize(24, 24))));

View File

@ -101,7 +101,7 @@ private:
int getInsertPos(QString connName, QString deviceName);
void deleteOneLan(QString ssid);
void deleteOneLan(QString ssid, int type);
void activeConnect(QString ssid, QString deviceName, int type);
void deActiveConnect(QString ssid, QString deviceName, int type);
@ -152,6 +152,7 @@ private slots:
void onDeviceStatusChanged();
void onDeviceNameChanged(QString, QString, int);
};
Q_DECLARE_METATYPE(QList<QDBusObjectPath>);

View File

@ -4,63 +4,94 @@
<context>
<name>AddNetBtn</name>
<message>
<location filename="../addnetbtn.cpp" line="22"/>
<location filename="../../component/AddBtn/addnetbtn.cpp" line="48"/>
<source>Add Others</source>
<translation></translation>
</message>
<message>
<location filename="../../component/AddBtn/addnetbtn.cpp" line="52"/>
<source>Add WiredNetork</source>
<translation></translation>
</message>
</context>
<context>
<name>LanItem</name>
<message>
<location filename="../lanitem.cpp" line="59"/>
<source>Delete</source>
<translation></translation>
</message>
<message>
<location filename="../lanitem.cpp" line="121"/>
<location filename="../lanitem.cpp" line="134"/>
<source>Disconnect</source>
<translation></translation>
</message>
<message>
<location filename="../lanitem.cpp" line="123"/>
<location filename="../lanitem.cpp" line="132"/>
<source>Connect</source>
<translation></translation>
</message>
</context>
<context>
<name>NetConnect</name>
<message>
<location filename="../netconnect.ui" line="50"/>
<location filename="../netconnect.cpp" line="152"/>
<location filename="../netconnect.cpp" line="153"/>
<source>Wired Network</source>
<translation></translation>
</message>
<message>
<location filename="../netconnect.ui" line="112"/>
<location filename="../netconnect.cpp" line="154"/>
<location filename="../netconnect.cpp" line="155"/>
<source>open</source>
<translation></translation>
<extra-contents_path>/netconnect/open</extra-contents_path>
</message>
<message>
<location filename="../netconnect.ui" line="198"/>
<location filename="../netconnect.cpp" line="151"/>
<location filename="../netconnect.cpp" line="152"/>
<source>Advanced settings</source>
<translation></translation>
<extra-contents_path>/netconnect/Advanced settings&quot;</extra-contents_path>
</message>
<message>
<location filename="../netconnect.cpp" line="63"/>
<location filename="../netconnect.cpp" line="64"/>
<source>ukui control center</source>
<translation></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="66"/>
<location filename="../netconnect.cpp" line="67"/>
<source>ukui control center desktop message</source>
<translation>ukui </translation>
</message>
<message>
<location filename="../netconnect.cpp" line="80"/>
<location filename="../netconnect.cpp" line="81"/>
<source>WiredConnect</source>
<translation></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="177"/>
<location filename="../netconnect.cpp" line="169"/>
<source>No ethernet device avaliable</source>
<translation></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="426"/>
<location filename="../netconnect.cpp" line="833"/>
<location filename="../netconnect.cpp" line="437"/>
<location filename="../netconnect.cpp" line="866"/>
<source>connected</source>
<translation></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="490"/>
<location filename="../netconnect.cpp" line="512"/>
<source>card</source>
<translation></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="439"/>
<location filename="../netconnect.cpp" line="876"/>
<source>not connected</source>
<translation></translation>
</message>
</context>
</TS>

View File

@ -4,63 +4,94 @@
<context>
<name>AddNetBtn</name>
<message>
<location filename="../addnetbtn.cpp" line="22"/>
<location filename="../../component/AddBtn/addnetbtn.cpp" line="48"/>
<source>Add Others</source>
<translation></translation>
</message>
<message>
<location filename="../../component/AddBtn/addnetbtn.cpp" line="52"/>
<source>Add WiredNetork</source>
<translation>线</translation>
</message>
</context>
<context>
<name>LanItem</name>
<message>
<location filename="../lanitem.cpp" line="59"/>
<source>Delete</source>
<translation></translation>
</message>
<message>
<location filename="../lanitem.cpp" line="121"/>
<location filename="../lanitem.cpp" line="134"/>
<source>Disconnect</source>
<translation></translation>
</message>
<message>
<location filename="../lanitem.cpp" line="123"/>
<location filename="../lanitem.cpp" line="132"/>
<source>Connect</source>
<translation></translation>
</message>
</context>
<context>
<name>NetConnect</name>
<message>
<location filename="../netconnect.ui" line="50"/>
<location filename="../netconnect.cpp" line="152"/>
<location filename="../netconnect.cpp" line="153"/>
<source>Wired Network</source>
<translation>线</translation>
</message>
<message>
<location filename="../netconnect.ui" line="112"/>
<location filename="../netconnect.cpp" line="154"/>
<location filename="../netconnect.cpp" line="155"/>
<source>open</source>
<translation></translation>
<extra-contents_path>/netconnect/open</extra-contents_path>
</message>
<message>
<location filename="../netconnect.ui" line="198"/>
<location filename="../netconnect.cpp" line="151"/>
<location filename="../netconnect.cpp" line="152"/>
<source>Advanced settings</source>
<translation></translation>
<extra-contents_path>/netconnect/Advanced settings&quot;</extra-contents_path>
</message>
<message>
<location filename="../netconnect.cpp" line="63"/>
<location filename="../netconnect.cpp" line="64"/>
<source>ukui control center</source>
<translation></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="66"/>
<location filename="../netconnect.cpp" line="67"/>
<source>ukui control center desktop message</source>
<translation></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="80"/>
<location filename="../netconnect.cpp" line="81"/>
<source>WiredConnect</source>
<translation>线</translation>
</message>
<message>
<location filename="../netconnect.cpp" line="177"/>
<location filename="../netconnect.cpp" line="169"/>
<source>No ethernet device avaliable</source>
<translation>线</translation>
</message>
<message>
<location filename="../netconnect.cpp" line="426"/>
<location filename="../netconnect.cpp" line="833"/>
<location filename="../netconnect.cpp" line="437"/>
<location filename="../netconnect.cpp" line="866"/>
<source>connected</source>
<translation></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="490"/>
<location filename="../netconnect.cpp" line="512"/>
<source>card</source>
<translation></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="439"/>
<location filename="../netconnect.cpp" line="876"/>
<source>not connected</source>
<translation></translation>
</message>
</context>
</TS>

View File

@ -147,6 +147,18 @@ void DbusAdaptor::setDeviceEnable(QString devName, bool enable)
// return deviceName;
//}
//删除
void DbusAdaptor::deleteConnect(int type, QString ssid)
{
if (type == WIRED) {
parent()->deleteWired(ssid);
} else if (type == WIRELESS) {
//待实现
} else {
qDebug() << "[DbusAdaptor] deleteConnect type is invalid";
}
}
//连接 根据网卡类型 参数1 0:lan 1:wlan 参数3 为ssid/uuid
void DbusAdaptor::activateConnect(int type, QString devName, QString ssid)
{

View File

@ -62,6 +62,8 @@ public Q_SLOTS: // METHODS
// QString getDefaultWiredDevice();
// Q_NOREPLY void setDefaultWirelessDevice(QString deviceName);
// QString getDefaultWirelessDevice();
//刪除 根据网络名称 参数1 0:lan 1:wlan 参数2 为ssid/uuid
Q_NOREPLY void deleteConnect(int type, QString ssid);
//连接 根据网卡类型 参数1 0:lan 1:wlan 参数3 为ssid/uuid
Q_NOREPLY void activateConnect(int type, QString devName, QString ssid);
//断开连接 根据网卡类型 参数1 0:lan 1:wlan 参数3 为ssid/uuid

View File

@ -879,6 +879,12 @@ void MainWindow::getWirelessDeviceCap(QMap<QString, int> &map)
m_wlanWidget->getWirelessDeviceCap(map);
}
//有线连接删除
void MainWindow::deleteWired(const QString &connUuid)
{
m_lanWidget->deleteWired(connUuid);
}
//有线连接断开
void MainWindow::activateWired(const QString& devName, const QString& connUuid)
{

View File

@ -81,6 +81,8 @@ public:
void getApConnectionPath(QString &path, QString uuid);
//获取热点ActivePath
void getActiveConnectionPath(QString &path, QString uuid);
//删除有线连接
void deleteWired(const QString& connUuid);
//有线连接断开
void activateWired(const QString& devName, const QString& connUuid);
void deactivateWired(const QString& devName, const QString& connUuid);

View File

@ -1202,6 +1202,15 @@ bool LanPage::eventFilter(QObject *watched, QEvent *event)
return QWidget::eventFilter(watched, event);
}
void LanPage::deleteWired(const QString &connUuid)
{
qDebug() << "[LanPage] deleteWired" << connUuid;
if (connUuid == nullptr) {
return;
}
m_wiredConnectOperation->deleteWiredConnect(connUuid);
}
void LanPage::onWiredEnabledChanged(bool enabled)
{
if (m_devList.isEmpty()) {

View File

@ -44,6 +44,7 @@ public:
//for dbus
void getWiredList(QMap<QString, QVector<QStringList> > &map);
void deleteWired(const QString& connUuid);
void activateWired(const QString& devName, const QString& connUuid);
void deactivateWired(const QString& devName, const QString& connUuid);
void showDetailPage(QString devName, QString uuid);