Merge branch 'dbus-interface' of http://gitlab2.kylin.com/kylin-desktop/kylin-nm into up-dbus

This commit is contained in:
jzxc95 2021-09-03 17:40:27 +08:00
commit ddea801445
22 changed files with 415 additions and 394 deletions

View File

@ -166,7 +166,7 @@ void KyNetworkResourceManager::addActiveConnection(NetworkManager::ActiveConnect
connect(conn.data(), &NetworkManager::ActiveConnection::masterChanged, this, &KyNetworkResourceManager::onActiveConnectionUpdated); connect(conn.data(), &NetworkManager::ActiveConnection::masterChanged, this, &KyNetworkResourceManager::onActiveConnectionUpdated);
connect(conn.data(), &NetworkManager::ActiveConnection::specificObjectChanged, this, &KyNetworkResourceManager::onActiveConnectionUpdated); connect(conn.data(), &NetworkManager::ActiveConnection::specificObjectChanged, this, &KyNetworkResourceManager::onActiveConnectionUpdated);
connect(conn.data(), &NetworkManager::ActiveConnection::stateChangedReason, this, &KyNetworkResourceManager::onActiveConnectionChangedReason); connect(conn.data(), &NetworkManager::ActiveConnection::stateChangedReason, this, &KyNetworkResourceManager::onActiveConnectionChangedReason);
connect(conn.data(), &NetworkManager::ActiveConnection::stateChanged, this, &KyNetworkResourceManager::onActiveConnectionUpdated); connect(conn.data(), &NetworkManager::ActiveConnection::stateChanged, this, &KyNetworkResourceManager::onActiveConnectionChanged);
connect(conn.data(), &NetworkManager::ActiveConnection::vpnChanged, this, &KyNetworkResourceManager::onActiveConnectionUpdated); connect(conn.data(), &NetworkManager::ActiveConnection::vpnChanged, this, &KyNetworkResourceManager::onActiveConnectionUpdated);
connect(conn.data(), &NetworkManager::ActiveConnection::uuidChanged, this, &KyNetworkResourceManager::onActiveConnectionUpdated); connect(conn.data(), &NetworkManager::ActiveConnection::uuidChanged, this, &KyNetworkResourceManager::onActiveConnectionUpdated);
connect(conn.data(), &NetworkManager::ActiveConnection::devicesChanged, this, &KyNetworkResourceManager::onActiveConnectionUpdated); connect(conn.data(), &NetworkManager::ActiveConnection::devicesChanged, this, &KyNetworkResourceManager::onActiveConnectionUpdated);
@ -543,6 +543,21 @@ void KyNetworkResourceManager::onActiveConnectionChangedReason(
return; return;
} }
void KyNetworkResourceManager::onActiveConnectionChanged(
NetworkManager::ActiveConnection::State state)
{
NetworkManager::ActiveConnection * activeConnect =
qobject_cast<NetworkManager::ActiveConnection *>(sender());
if (activeConnect->isValid()) {
qDebug()<<"!New state change activate connect"<<activeConnect->uuid();
qDebug()<<"!New the active connect state"<<state;
} else {
}
return;
}
void KyNetworkResourceManager::onVpnActiveConnectChanagedReason(NetworkManager::VpnConnection::State state, void KyNetworkResourceManager::onVpnActiveConnectChanagedReason(NetworkManager::VpnConnection::State state,
NetworkManager::VpnConnection::StateChangeReason reason) NetworkManager::VpnConnection::StateChangeReason reason)
{ {

View File

@ -145,6 +145,8 @@ private slots:
void onActiveConnectionUpdated(); void onActiveConnectionUpdated();
void onActiveConnectionChangedReason(NetworkManager::ActiveConnection::State state, void onActiveConnectionChangedReason(NetworkManager::ActiveConnection::State state,
NetworkManager::ActiveConnection::Reason reason); NetworkManager::ActiveConnection::Reason reason);
void onActiveConnectionChanged(NetworkManager::ActiveConnection::State state);
void onVpnActiveConnectChanagedReason(NetworkManager::VpnConnection::State state, void onVpnActiveConnectChanagedReason(NetworkManager::VpnConnection::State state,
NetworkManager::VpnConnection::StateChangeReason reason); NetworkManager::VpnConnection::StateChangeReason reason);

View File

@ -78,54 +78,6 @@ void getDeviceEnableState(int type, QMap<QString, bool> &map)
return; return;
} }
//设置默认网卡
void setDefaultDevice(KyDeviceType deviceType, QString deviceName)
{
QString key;
switch (deviceType) {
case WIRED:
key = "wired";
break;
case WIRELESS:
key = "wireless";
break;
default:
return;
break;
}
QSettings * m_settings = new QSettings(CONFIG_FILE_PATH, QSettings::IniFormat);
m_settings->beginGroup("DEFAULTCARD");
m_settings->setValue(key, deviceName);
m_settings->endGroup();
m_settings->sync();
delete m_settings;
m_settings = nullptr;
return;
}
bool checkDeviceExist(KyDeviceType deviceType, QString deviceName)
{
NetworkManager::Device::Type type;
switch (deviceType) {
case WIRED:
type = NetworkManager::Device::Type::Ethernet;
break;
case WIRELESS:
type = NetworkManager::Device::Type::Wifi;
break;
default:
return false;
break;
}
KyNetworkDeviceResourse * kdr = new KyNetworkDeviceResourse();
QStringList devList;
devList.clear();
kdr->getNetworkDeviceList(type, devList);
return devList.contains(deviceName);
}
/* /*
* Implementation of adaptor class DbusAdaptor * Implementation of adaptor class DbusAdaptor
*/ */

View File

@ -16,6 +16,7 @@
#include <QtDBus/QtDBus> #include <QtDBus/QtDBus>
#include <QtDBus/QDBusMetaType> #include <QtDBus/QDBusMetaType>
#include "tabpage.h"
#include "../dbus-interface/kylinnetworkdeviceresource.h" #include "../dbus-interface/kylinnetworkdeviceresource.h"
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QByteArray; class QByteArray;
@ -33,15 +34,6 @@ QT_END_NAMESPACE
#include "new-mainwindow.h" #include "new-mainwindow.h"
enum KyDeviceType
{
WIRED,
WIRELESS
};
bool checkDeviceExist(KyDeviceType deviceType, QString deviceName);
void setDefaultDevice(KyDeviceType deviceType, QString deviceName);
class DbusAdaptor: public QDBusAbstractAdaptor class DbusAdaptor: public QDBusAbstractAdaptor
{ {
Q_OBJECT Q_OBJECT

View File

@ -10,43 +10,46 @@ LanListItem::LanListItem(KyConnectItem *data, QString deviceName, QWidget *paren
m_connectOperation = new KyWiredConnectOperation; m_connectOperation = new KyWiredConnectOperation;
m_data = data; m_data = data;
m_nameLabel->setText(m_data->m_connectName); m_nameLabel->setText(m_data->m_connectName);
if (m_data != nullptr) { if (m_data != nullptr) {
if (m_data->m_connectState == NetworkManager::ActiveConnection::State::Activated) { if (m_data->m_connectState == NetworkManager::ActiveConnection::State::Activated) {
setIcon(true); setIcon(true);
m_activated = true; m_isActive = true;
} else { } else {
setIcon(false); setIcon(false);
m_activated = false; m_isActive = false;
} }
} }
m_netButton->setActive(m_isActive);
m_itemFrame->installEventFilter(this); m_itemFrame->installEventFilter(this);
} }
bool LanListItem::eventFilter(QObject *watched, QEvent *event) void LanListItem::onInfoButtonClicked()
{ {
if (watched == m_itemFrame) {
if (event->type() == QEvent::MouseButtonPress) { }
if (!m_activated) {
//未连接,点击后连 void LanListItem::onNetButtonClicked()
m_connectOperation->activateWiredConnection(m_data->m_connectUuid, deviceName); {
qDebug() << m_data->m_connectName << "Connect after user clicked!"; if (!m_isActive) {
m_activated = true; //未连接,点击后连
} else { m_connectOperation->activateWiredConnection(m_data->m_connectUuid, deviceName);
//连接,点击后断开 qDebug() << m_data->m_connectName << "Connect after user clicked!";
m_connectOperation->deactivateWiredConnection(m_data->m_connectName, m_data->m_connectUuid); m_isActive = true;
qDebug() << m_data->m_connectName << "Disconnect after user clicked!"; } else {
m_activated = false; //连接,点击后断开
} m_connectOperation->deactivateWiredConnection(m_data->m_connectName, m_data->m_connectUuid);
} qDebug() << m_data->m_connectName << "Disconnect after user clicked!";
m_isActive = false;
} }
return ListItem::eventFilter(watched, event);
} }
void LanListItem::setIcon(bool isOn) void LanListItem::setIcon(bool isOn)
{ {
if (isOn) { if (isOn) {
m_netButton->setIcon(QIcon::fromTheme("network-wired-connected-symbolic")); m_netButton->setButtonIcon(QIcon::fromTheme("network-wired-connected-symbolic"));
} else { } else {
m_netButton->setIcon(QIcon::fromTheme("network-wired-disconnected-symbolic")); m_netButton->setButtonIcon(QIcon::fromTheme("network-wired-disconnected-symbolic"));
} }
} }

View File

@ -17,14 +17,16 @@ public:
protected: protected:
void setIcon(bool isOn); void setIcon(bool isOn);
bool eventFilter(QObject *watched, QEvent *event);
private: private:
KyConnectItem *m_data = nullptr; KyConnectItem *m_data = nullptr;
KyWiredConnectOperation *m_connectOperation = nullptr; KyWiredConnectOperation *m_connectOperation = nullptr;
bool m_activated = false;
QString deviceName = nullptr; QString deviceName = nullptr;
private slots:
void onInfoButtonClicked();
void onNetButtonClicked();
}; };
#endif // LANLISTITEM_H #endif // LANLISTITEM_H

View File

@ -1,10 +1,11 @@
#include "listitem.h" #include "listitem.h"
#include <QDebug>
#define MAIN_LAYOUT_MARGINS 0,0,0,0 #define MAIN_LAYOUT_MARGINS 0,0,0,0
#define MAIN_LAYOUT_SPACING 0 #define MAIN_LAYOUT_SPACING 0
#define ITEM_FRAME_MARGINS 16,6,16,6 #define ITEM_FRAME_MARGINS 16,6,16,6
#define ITEM_FRAME_SPACING 10 #define ITEM_FRAME_SPACING 10
#define FRAME_WIDTH 395
#define INFO_ICON_WIDTH 16 #define INFO_ICON_WIDTH 16
#define INFO_ICON_HEIGHT 16 #define INFO_ICON_HEIGHT 16
@ -12,6 +13,7 @@ ListItem::ListItem(QWidget *parent) : QFrame(parent)
{ {
initUI(); initUI();
initConnection(); initConnection();
m_itemFrame->installEventFilter(this);
} }
ListItem::~ListItem() ListItem::~ListItem()
@ -23,22 +25,28 @@ ListItem::~ListItem()
m_infoButton = NULL; m_infoButton = NULL;
} }
bool ListItem::eventFilter(QObject *watched, QEvent *event)
{
if (watched == this) {
if (event->type() == QEvent::MouseButtonPress) {
this->onNetButtonClicked();
}
}
return QFrame::eventFilter(watched, event);
}
void ListItem::setName(const QString &name) void ListItem::setName(const QString &name)
{ {
m_nameLabel->setText(name); m_nameLabel->setText(name);
} }
//仅无线调用,有线自己获取
void ListItem::setActive(const bool &isActive)
{
m_netButton->setActive(isActive);
m_isActive = isActive;
}
bool ListItem::eventFilter(QObject *watched, QEvent *event)
{
if (watched == m_itemFrame) {
if (event->type() == QEvent::MouseButtonPress) {
onNetButtonClicked();
}
}
return QFrame::eventFilter(watched, event);
}
void ListItem::initUI() void ListItem::initUI()
{ {
m_mainLayout = new QVBoxLayout(this); m_mainLayout = new QVBoxLayout(this);
@ -47,10 +55,11 @@ void ListItem::initUI()
this->setLayout(m_mainLayout); this->setLayout(m_mainLayout);
m_itemFrame = new QFrame(this); m_itemFrame = new QFrame(this);
m_itemFrame->setFixedWidth(FRAME_WIDTH);
m_hItemLayout = new QHBoxLayout(m_itemFrame); m_hItemLayout = new QHBoxLayout(m_itemFrame);
m_hItemLayout->setContentsMargins(ITEM_FRAME_MARGINS); m_hItemLayout->setContentsMargins(ITEM_FRAME_MARGINS);
m_hItemLayout->setSpacing(ITEM_FRAME_SPACING); // m_hItemLayout->setSpacing(ITEM_FRAME_SPACING);
m_netButton = new RadioItemButton(m_itemFrame); m_netButton = new RadioItemButton(m_itemFrame);
m_nameLabel = new QLabel(m_itemFrame); m_nameLabel = new QLabel(m_itemFrame);
@ -81,4 +90,3 @@ void ListItem::onNetButtonClicked()
{ {
} }

View File

@ -4,7 +4,6 @@
#include <QEvent> #include <QEvent>
#include <QHBoxLayout> #include <QHBoxLayout>
#include "radioitembutton.h" #include "radioitembutton.h"
#include "netbutton.h"
#include "infobutton.h" #include "infobutton.h"
class ListItem : public QFrame class ListItem : public QFrame
{ {
@ -13,6 +12,7 @@ public:
ListItem(QWidget *parent = nullptr); ListItem(QWidget *parent = nullptr);
~ListItem(); ~ListItem();
void setName(const QString &name); void setName(const QString &name);
void setActive(const bool &isActive);
protected: protected:
bool eventFilter(QObject *watched, QEvent *event); bool eventFilter(QObject *watched, QEvent *event);
@ -24,6 +24,8 @@ protected:
RadioItemButton * m_netButton = nullptr; RadioItemButton * m_netButton = nullptr;
InfoButton * m_infoButton = nullptr; InfoButton * m_infoButton = nullptr;
bool m_isActive = false;
public: public:
QVBoxLayout * m_mainLayout = nullptr; QVBoxLayout * m_mainLayout = nullptr;
QHBoxLayout * m_hItemLayout = nullptr; QHBoxLayout * m_hItemLayout = nullptr;

View File

@ -54,11 +54,6 @@ void WlanListItem::setExpanded(const bool &expanded)
emit this->itemHeightChanged(m_data->m_NetSsid); emit this->itemHeightChanged(m_data->m_NetSsid);
} }
void WlanListItem::setActivated(bool activated)
{
this->m_isActivated = activated;
}
void WlanListItem::resizeEvent(QResizeEvent *event) void WlanListItem::resizeEvent(QResizeEvent *event)
{ {
this->blockSignals(true); this->blockSignals(true);
@ -212,24 +207,9 @@ void WlanListItem::onNetButtonClicked()
qDebug() << "On wlan clicked! But there is no wlan connect!" << Q_FUNC_INFO << __LINE__; qDebug() << "On wlan clicked! But there is no wlan connect!" << Q_FUNC_INFO << __LINE__;
return; return;
} }
qDebug() << "On wlan clicked! ssid = " << m_data->m_NetSsid << "; name = " << m_data->m_connName << "." << Q_FUNC_INFO << __LINE__;
//判断当前item处于连接还是断开对比activessid
QString activedssid;
QMap<QString,QStringList> actMap;
m_resource->getWirelessActiveConnection(NetworkManager::ActiveConnection::State::Activated, actMap);
QMap<QString,QStringList>::iterator iter = actMap.begin();
while (iter != actMap.end()) {
if (iter.key() == m_wlanDevice && !iter.value().isEmpty()) {
activedssid = iter.value().at(0);
break;
}
iter ++;
}
qDebug()<<"Get activated wlan succeed! ssid = " << activedssid <<Q_FUNC_INFO << __LINE__;
//执行连接或断开 //执行连接或断开
if (m_data->m_NetSsid == activedssid) { if (m_isActive) {
m_connoperation->deActivateWirelessConnection(m_wlanDevice,m_data->m_connectUuid); m_connoperation->deActivateWirelessConnection(m_wlanDevice,m_data->m_connectUuid);
qDebug()<<"Clicked on connected wifi, it will be inactivated. ssid = " << m_data->m_NetSsid << Q_FUNC_INFO << __LINE__; qDebug()<<"Clicked on connected wifi, it will be inactivated. ssid = " << m_data->m_NetSsid << Q_FUNC_INFO << __LINE__;
return; return;

View File

@ -27,7 +27,6 @@ public:
void setWlanSignal(const int &signal); void setWlanSignal(const int &signal);
void setWlanState(const int &state); void setWlanState(const int &state);
void setExpanded(const bool &expanded); void setExpanded(const bool &expanded);
void setActivated(bool activated);
protected: protected:
void resizeEvent(QResizeEvent *event); void resizeEvent(QResizeEvent *event);
@ -46,7 +45,6 @@ private:
KyWirelessNetItem *m_data = nullptr; KyWirelessNetItem *m_data = nullptr;
KyWirelessConnectOperation *m_connoperation = nullptr; KyWirelessConnectOperation *m_connoperation = nullptr;
bool m_hasPwd = true; bool m_hasPwd = true;
bool m_isActivated = false;
QString m_wlanDevice; QString m_wlanDevice;
//密码输入区域的UI //密码输入区域的UI

View File

@ -14,17 +14,31 @@
#define SWITCH_HEIGHT 24 #define SWITCH_HEIGHT 24
#define ITEM_HEIGHT 48 #define ITEM_HEIGHT 48
const QString WIRED_SWITCH = "wiredswitch";
const QByteArray GSETTINGS_SCHEMA = "org.ukui.kylin-nm.switch";
LanPage::LanPage(QWidget *parent) : TabPage(parent) LanPage::LanPage(QWidget *parent) : TabPage(parent)
{ {
m_activeResourse = new KyActiveConnectResourse; m_activeResourse = new KyActiveConnectResourse;
m_connectResourse = new KyConnectResourse; m_connectResourse = new KyConnectResourse;
m_device = new KyNetworkDeviceResourse; m_device = new KyNetworkDeviceResourse;
devList.empty();
initDevice(); initDevice();
initUI(); initUI();
if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA)) {
m_switchGsettings = new QGSettings(GSETTINGS_SCHEMA);
initNetSwitch();
} else {
qDebug()<<"[LanPage] org.ukui.kylin-nm.switch is not installed!";
}
initList(); initList();
connect(m_activeResourse, &KyActiveConnectResourse::stateChangeReason, this, &LanPage::updateLanlist); connect(m_activeResourse, &KyActiveConnectResourse::stateChangeReason, this, &LanPage::updateLanlist);
connect(m_connectResourse, &KyConnectResourse::connectionAdd, this, &LanPage::addConnectionSlot); connect(m_connectResourse, &KyConnectResourse::connectionAdd, this, &LanPage::addConnectionSlot);
connect(m_connectResourse, &KyConnectResourse::connectionRemove, this, &LanPage::removeConnectionSlot); connect(m_connectResourse, &KyConnectResourse::connectionRemove, this, &LanPage::removeConnectionSlot);
connect(m_device, &KyNetworkDeviceResourse::deviceAdd, this, &LanPage::onDeviceAdd);
connect(m_device, &KyNetworkDeviceResourse::deviceRemove, this, &LanPage::onDeviceRemove);
connect(m_device, &KyNetworkDeviceResourse::deviceNameUpdate, this, &LanPage::onDeviceNameUpdate);
} }
LanPage::~LanPage() LanPage::~LanPage()
@ -32,6 +46,41 @@ LanPage::~LanPage()
} }
void LanPage::initNetSwitch()
{
if (m_switchGsettings->keys().contains(WIRED_SWITCH)) {
m_netSwitch->setSwitchStatus(m_switchGsettings->get(WIRED_SWITCH).toBool());
connect(m_switchGsettings, &QGSettings::changed, this, &LanPage::onSwithGsettingsChanged);
}
connect(m_netSwitch, &SwitchButton::clicked, this, &LanPage::onLanSwitchClicked);
}
void LanPage::onSwithGsettingsChanged(const QString &key)
{
if (key == WIRED_SWITCH) {
m_netSwitch->blockSignals(true);
qDebug()<<"[LanPage] SwitchButton statue changed to ::"<<m_switchGsettings->get(WIRED_SWITCH).toBool();
m_netSwitch->setSwitchStatus(m_switchGsettings->get(WIRED_SWITCH).toBool());
m_netSwitch->blockSignals(false);
}
}
void LanPage::onLanSwitchClicked()
{
qDebug()<<"[LanPage] On lan switch button clicked! Status:"<<m_netSwitch->getSwitchStatus();
if (m_netSwitch->getSwitchStatus()) {
m_device->setDeviceAutoConnect();
m_inactivatedLanListWidget->show();
m_switchGsettings->set(WIRED_SWITCH,true);
} else {
if (m_activeMap.count() != 0) {
m_device->disconnectDevice();
}
m_inactivatedLanListWidget->hide();
m_switchGsettings->set(WIRED_SWITCH,false);
}
}
void LanPage::removeConnectionSlot(QString path) //删除时后端会自动断开激活,将其从未激活列表中删除 void LanPage::removeConnectionSlot(QString path) //删除时后端会自动断开激活,将其从未激活列表中删除
{ {
qDebug()<<"[LanPage] Removing a connection, path:"<<path; qDebug()<<"[LanPage] Removing a connection, path:"<<path;
@ -60,17 +109,11 @@ void LanPage::addConnectionSlot(QString uuid) //新增一个有线
{ {
KyConnectItem * newItem = m_connectResourse->getConnectionItemByUuid(uuid, m_deviceName); KyConnectItem * newItem = m_connectResourse->getConnectionItemByUuid(uuid, m_deviceName);
if (newItem != nullptr) { if (newItem != nullptr) {
qDebug()<<"[LanPage] Add a new connection, name:"<<newItem->m_connectName; if (newItem->m_itemType == NetworkManager::ConnectionSettings::ConnectionType::Wired) {
LanListItem * newListItem = new LanListItem(newItem, m_deviceName); qDebug()<<"[LanPage] Add a new connection, name:"<<newItem->m_connectName;
newListItem->setFixedHeight(ITEM_HEIGHT); addNewItem(newItem, m_inactivatedLanListWidget);
m_deactiveMap.insert(newItem, m_listWidgetItem);
m_listWidgetItem = new QListWidgetItem(m_inactivatedLanListWidget); }
m_listWidgetItem->setSizeHint(QSize(m_inactivatedLanListWidget->width(),ITEM_HEIGHT));
m_inactivatedLanListWidget->addItem(m_listWidgetItem);
m_inactivatedLanListWidget->setItemWidget(m_listWidgetItem, newListItem);
m_deactiveMap.insert(newItem, m_listWidgetItem);
//for dbus //for dbus
qDebug() << "[LanPage] because addConnectionSlot " << newItem->m_ifaceName; qDebug() << "[LanPage] because addConnectionSlot " << newItem->m_ifaceName;
emit listUpdate(newItem->m_ifaceName); emit listUpdate(newItem->m_ifaceName);
@ -87,11 +130,8 @@ void LanPage::initDevice()
m_deviceName = m_settings->value(key, "").toString(); m_deviceName = m_settings->value(key, "").toString();
if (m_deviceName.isEmpty()) { if (m_deviceName.isEmpty()) {
qDebug() << "initDevice but defalut wired card is null"; qDebug() << "initDevice but defalut wired card is null";
QStringList list; if (!devList.isEmpty()) {
list.empty(); m_deviceName = devList.at(0);
m_device->getNetworkDeviceList(NetworkManager::Device::Type::Ethernet, list);
if (!list.isEmpty()) {
m_deviceName = list.at(0);
m_settings->setValue(key, m_deviceName); m_settings->setValue(key, m_deviceName);
} }
} }
@ -102,6 +142,60 @@ void LanPage::initDevice()
m_settings->sync(); m_settings->sync();
delete m_settings; delete m_settings;
m_settings = nullptr; m_settings = nullptr;
for (int i = 0; i < devList.size(); ++i) {
qDebug() << "[LanPage] Device: " << devList.at(i);
}
}
void LanPage::onDeviceAdd(QString deviceName, NetworkManager::Device::Type deviceType)
{
qDebug() << "[LanPage] Begin add device:" << deviceName;
if (deviceType != NetworkManager::Device::Type::Ethernet) {
return;
}
devList << deviceName;
if (getDefaultDevice().isEmpty())
{
updateDefaultDevice(deviceName);
setDefaultDevice(WIRED, deviceName);
}
emit deviceStatusChanged();
}
void LanPage::onDeviceRemove(QString deviceName)
{
qDebug() << "deviceRemove" << deviceName;
if (getDefaultDevice() == deviceName)
{
QStringList list;
QString newDefaultDevice = "";
list.empty();
m_device->getNetworkDeviceList(NetworkManager::Device::Type::Ethernet, list);
if (!list.isEmpty()) {
newDefaultDevice = list.at(0);
}
updateDefaultDevice(newDefaultDevice);
setDefaultDevice(WIRED, newDefaultDevice);
}
if (devList.contains(deviceName)) {
devList.removeOne(deviceName);
emit deviceStatusChanged();
}
}
void LanPage::onDeviceNameUpdate(QString oldName, QString newName)
{
if (getDefaultDevice() == oldName) {
updateDefaultDevice(newName);
setDefaultDevice(WIRED, newName);
}
if (devList.contains(oldName)) {
devList.removeOne(oldName);
devList.append(newName);
qDebug() << "LanPage emit deviceNameUpdate " << oldName << newName;
emit deviceNameChanged(oldName, newName);
}
} }
void LanPage::initUI() void LanPage::initUI()
@ -112,22 +206,28 @@ void LanPage::initUI()
m_activatedNetLabel->setText(tr("Activated LAN")); m_activatedNetLabel->setText(tr("Activated LAN"));
m_activatedLanListWidget = new QListWidget(m_activatedNetFrame); m_activatedLanListWidget = new QListWidget(m_activatedNetFrame);
m_activatedLanListWidget->setFrameShape(QFrame::Shape::NoFrame); m_activatedLanListWidget->setFrameShape(QFrame::Shape::NoFrame);
// m_activatedLanListWidget->setContentsMargins(MAIN_LAYOUT_MARGINS);
m_activatedLanListWidget->setSpacing(LAN_LIST_SPACING); m_activatedLanListWidget->setSpacing(LAN_LIST_SPACING);
m_activatedLanListWidget->setFixedHeight(ITEM_HEIGHT); //active区域固定高度,只显示一个条目 m_activatedLanListWidget->setFixedHeight(ITEM_HEIGHT); //active区域固定高度,只显示一个条目
m_activatedLanListWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_activatedNetLayout->addWidget(m_activatedLanListWidget); m_activatedNetLayout->addWidget(m_activatedLanListWidget);
m_inactivatedNetLabel->setText(tr("Inactivated LAN")); m_inactivatedNetLabel->setText(tr("Inactivated LAN"));
m_inactivatedNetListArea->setBackgroundRole(QPalette::Base); m_inactivatedNetListArea->setBackgroundRole(QPalette::Base);
m_inactivatedNetListArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); m_inactivatedNetListArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
m_inactivatedNetListArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); m_inactivatedNetListArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_inactivatedNetListArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); // m_inactivatedNetListArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
QVBoxLayout *inactiveLanListLayout = new QVBoxLayout(m_inactivatedNetListArea);
inactiveLanListLayout->setContentsMargins(MAIN_LAYOUT_MARGINS);
inactiveLanListLayout->setSpacing(MAIN_LAYOUT_SPACING);
m_inactivatedLanListWidget = new QListWidget(m_inactivatedNetListArea); m_inactivatedLanListWidget = new QListWidget(m_inactivatedNetListArea);
m_inactivatedLanListWidget->setFrameShape(QFrame::Shape::NoFrame); m_inactivatedLanListWidget->setFrameShape(QFrame::Shape::NoFrame);
// m_inactivatedLanListWidget->setContentsMargins(MAIN_LAYOUT_MARGINS);
m_inactivatedLanListWidget->setSpacing(LAN_LIST_SPACING); m_inactivatedLanListWidget->setSpacing(LAN_LIST_SPACING);
QVBoxLayout *inactiveLanListLayout = new QVBoxLayout(m_inactivatedNetListArea); m_inactivatedLanListWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
// m_inactivatedLanListWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); //用了listwidget的滚动条
inactiveLanListLayout->addWidget(m_inactivatedLanListWidget); inactiveLanListLayout->addWidget(m_inactivatedLanListWidget);
// KyConnectItem *activeConnectItem = new KyConnectItem(); // KyConnectItem *activeConnectItem = new KyConnectItem();
@ -141,7 +241,16 @@ void LanPage::initUI()
// m_listWidgetItem = new QListWidgetItem(m_inactivatedLanListWidget); // m_listWidgetItem = new QListWidgetItem(m_inactivatedLanListWidget);
// m_inactivatedLanListWidget->addItem(m_listWidgetItem); // m_inactivatedLanListWidget->addItem(m_listWidgetItem);
// m_inactivatedLanListWidget->setItemWidget(m_listWidgetItem, m_testLanItem); // m_inactivatedLanListWidget->setItemWidget(m_listWidgetItem, m_testLanItem);
}
void LanPage::addNewItem(KyConnectItem *itemData, QListWidget *listWidget)
{
m_listWidgetItem = new QListWidgetItem(listWidget);
m_listWidgetItem->setSizeHint(QSize(listWidget->width(),ITEM_HEIGHT));
listWidget->addItem(m_listWidgetItem);
m_testLanItem = new LanListItem(itemData, m_deviceName);
listWidget->setItemWidget(m_listWidgetItem, m_testLanItem);
} }
void LanPage::initList() //程序拉起,初始化显示 void LanPage::initList() //程序拉起,初始化显示
@ -149,15 +258,9 @@ void LanPage::initList() //程序拉起,初始化显示
m_activeResourse->getActiveConnectionList(m_deviceName,NetworkManager::ConnectionSettings::Wired,m_activedList); //激活列表的显示 m_activeResourse->getActiveConnectionList(m_deviceName,NetworkManager::ConnectionSettings::Wired,m_activedList); //激活列表的显示
if (!m_activedList.isEmpty()) { if (!m_activedList.isEmpty()) {
for (int i = 0; i < m_activedList.size(); i++) { for (int i = 0; i < m_activedList.size(); i++) {
m_listWidgetItem = new QListWidgetItem(m_activatedLanListWidget);
m_listWidgetItem->setSizeHint(QSize(m_activatedLanListWidget->width(),ITEM_HEIGHT));
m_activatedLanListWidget->addItem(m_listWidgetItem);
KyConnectItem *activeItemData = m_activedList.at(i); KyConnectItem *activeItemData = m_activedList.at(i);
addNewItem(activeItemData, m_activatedLanListWidget);
activeConnectItem = new LanListItem(activeItemData, m_deviceName);
m_activatedLanListWidget->setItemWidget(m_listWidgetItem, activeConnectItem);
m_activeMap.insert(activeItemData, m_listWidgetItem); m_activeMap.insert(activeItemData, m_listWidgetItem);
} }
@ -166,16 +269,8 @@ void LanPage::initList() //程序拉起,初始化显示
m_connectResourse->getConnectionList(m_deviceName, NetworkManager::ConnectionSettings::Wired, m_deactivedList); //未激活列表的显示 m_connectResourse->getConnectionList(m_deviceName, NetworkManager::ConnectionSettings::Wired, m_deactivedList); //未激活列表的显示
if (!m_deactivedList.isEmpty()) { if (!m_deactivedList.isEmpty()) {
for (int i = 0; i < m_deactivedList.size(); i++) { for (int i = 0; i < m_deactivedList.size(); i++) {
m_listWidgetItem = new QListWidgetItem(m_inactivatedLanListWidget);
m_listWidgetItem->setSizeHint(QSize(m_inactivatedLanListWidget->width(),ITEM_HEIGHT));
m_inactivatedLanListWidget->addItem(m_listWidgetItem);
KyConnectItem *deactiveItemData = m_deactivedList.at(i); KyConnectItem *deactiveItemData = m_deactivedList.at(i);
addNewItem(deactiveItemData, m_inactivatedLanListWidget);
deactiveConnectItem = new LanListItem(deactiveItemData ,m_deviceName);
// deactiveConnectItem->setFixedHeight(ITEM_HEIGHT);
m_inactivatedLanListWidget->setItemWidget(m_listWidgetItem, deactiveConnectItem);
m_deactiveMap.insert(deactiveItemData, m_listWidgetItem); m_deactiveMap.insert(deactiveItemData, m_listWidgetItem);
} }
@ -215,23 +310,16 @@ void LanPage::updateLanlist(QString uuid, NetworkManager::ActiveConnection::Stat
qDebug()<<"Get an actived connection, begin to move it from deactive to avtive!"; qDebug()<<"Get an actived connection, begin to move it from deactive to avtive!";
QMap<KyConnectItem *, QListWidgetItem *>::iterator iter; //在未激活列表里删除 QMap<KyConnectItem *, QListWidgetItem *>::iterator iter; //在未激活列表里删除
for (iter = m_deactiveMap.begin(); iter != m_deactiveMap.constEnd(); ++iter) { for (iter = m_deactiveMap.begin(); iter != m_deactiveMap.constEnd(); ++iter) {
KyConnectItem *m_Item = iter.key(); KyConnectItem *m_item = iter.key();
if (m_Item->m_connectUuid == uuid) { if (m_item->m_connectUuid == uuid) {
qDebug()<<"Add an active connection to activeList:"<<m_Item->m_connectName; qDebug()<<"Add an active connection to activeList:"<<m_item->m_connectName;
m_Item->m_connectState = state; m_item->m_connectState = state;
addNewItem(m_item, m_activatedLanListWidget);
m_listWidgetItem = new QListWidgetItem(m_activatedLanListWidget);
m_listWidgetItem->setSizeHint(QSize(m_inactivatedLanListWidget->width(),ITEM_HEIGHT));
m_activatedLanListWidget->addItem(iter.value());
m_activeItem = new LanListItem(m_Item ,m_deviceName);
m_activatedLanListWidget->setItemWidget(m_listWidgetItem, m_activeItem);
m_inactivatedLanListWidget->removeItemWidget(iter.value()); m_inactivatedLanListWidget->removeItemWidget(iter.value());
delete(iter.value()); delete(iter.value());
m_activeMap.insert(m_Item, m_listWidgetItem); m_activeMap.insert(m_item, m_listWidgetItem);
m_deactiveMap.erase(iter); m_deactiveMap.erase(iter);
break; break;
} }
@ -240,8 +328,8 @@ void LanPage::updateLanlist(QString uuid, NetworkManager::ActiveConnection::Stat
qDebug()<<"Get a deactivate, begin to remove it from activeList"; qDebug()<<"Get a deactivate, begin to remove it from activeList";
QMap<KyConnectItem *, QListWidgetItem *>::iterator i; QMap<KyConnectItem *, QListWidgetItem *>::iterator i;
for (i = m_activeMap.begin(); i != m_activeMap.constEnd(); ++i) { //有新断开,若在激活列表里则删掉 for (i = m_activeMap.begin(); i != m_activeMap.constEnd(); ++i) { //有新断开,若在激活列表里则删掉
KyConnectItem *m_Item = i.key(); KyConnectItem *m_item = i.key();
if (m_Item->m_connectUuid == uuid) { if (m_item->m_connectUuid == uuid) {
m_activatedLanListWidget->removeItemWidget(i.value()); m_activatedLanListWidget->removeItemWidget(i.value());
delete(i.value()); delete(i.value());
break; break;
@ -251,8 +339,8 @@ void LanPage::updateLanlist(QString uuid, NetworkManager::ActiveConnection::Stat
bool hasDeactiveNet = false; bool hasDeactiveNet = false;
QMap<KyConnectItem *, QListWidgetItem *>::iterator iter; QMap<KyConnectItem *, QListWidgetItem *>::iterator iter;
for (iter = m_deactiveMap.begin(); iter != m_deactiveMap.end(); ++iter) { //检查其是否已经在未激活列表中 for (iter = m_deactiveMap.begin(); iter != m_deactiveMap.end(); ++iter) { //检查其是否已经在未激活列表中
KyConnectItem *m_Item = iter.key(); KyConnectItem *m_item = iter.key();
if (m_Item->m_connectUuid == uuid) { if (m_item->m_connectUuid == uuid) {
hasDeactiveNet = true; hasDeactiveNet = true;
break; break;
} }
@ -261,21 +349,14 @@ void LanPage::updateLanlist(QString uuid, NetworkManager::ActiveConnection::Stat
QMap<KyConnectItem *, QListWidgetItem *>::iterator iters; QMap<KyConnectItem *, QListWidgetItem *>::iterator iters;
for (iters = m_activeMap.begin(); iters != m_activeMap.end(); ++iters) { //在未激活列表中增加一项连接 for (iters = m_activeMap.begin(); iters != m_activeMap.end(); ++iters) { //在未激活列表中增加一项连接
KyConnectItem *m_Item = iters.key(); KyConnectItem *m_item = iters.key();
if (m_Item->m_connectUuid == uuid && !hasDeactiveNet) { if (m_item->m_connectUuid == uuid && !hasDeactiveNet) {
qDebug()<<"Add a deactive connection to inactiveList:"<<m_Item->m_connectName; qDebug()<<"Add a deactive connection to inactiveList:"<<m_item->m_connectName;
m_Item->m_connectState = state; m_item->m_connectState = state;
m_deactiveItem = new LanListItem(m_Item ,m_deviceName);
m_deactiveItem->setFixedHeight(ITEM_HEIGHT);
m_listWidgetItem = new QListWidgetItem(m_inactivatedLanListWidget); addNewItem(m_item, m_inactivatedLanListWidget);
m_listWidgetItem->setSizeHint(QSize(m_inactivatedLanListWidget->width(),ITEM_HEIGHT));
m_inactivatedLanListWidget->addItem(m_listWidgetItem);
m_inactivatedLanListWidget->setItemWidget(m_listWidgetItem, m_deactiveItem);
m_deactiveMap.insert(m_Item, m_listWidgetItem);
m_deactiveMap.insert(m_item, m_listWidgetItem);
m_activeMap.erase(iters); m_activeMap.erase(iters);
break; break;
} }
@ -285,19 +366,6 @@ void LanPage::updateLanlist(QString uuid, NetworkManager::ActiveConnection::Stat
} }
} }
bool LanPage::eventFilter(QObject *watched, QEvent *event)
{
if (watched == m_netSwitch) {
// if(event == click)
// {
// }
}
return QWidget::eventFilter(watched, event);
}
void LanPage::getWiredList(QMap<QString, QVector<QStringList> > &map) void LanPage::getWiredList(QMap<QString, QVector<QStringList> > &map)
{ {
QStringList devlist; QStringList devlist;

View File

@ -9,6 +9,7 @@
#include <QScrollArea> #include <QScrollArea>
#include <QListWidget> #include <QListWidget>
#include <QMap> #include <QMap>
#include <QGSettings>
#include "list-items/listitem.h" #include "list-items/listitem.h"
#include "list-items/lanlistitem.h" #include "list-items/lanlistitem.h"
@ -33,25 +34,17 @@ private:
void initDevice();//初始化默认设备 void initDevice();//初始化默认设备
void initUI(); void initUI();
void initList(); void initList();
bool eventFilter(QObject *watched, QEvent *event);
void addNewItem(KyConnectItem *itemData, QListWidget *listWidget); void addNewItem(KyConnectItem *itemData, QListWidget *listWidget);
void initNetSwitch();
private: private:
KyNetworkDeviceResourse *m_device = nullptr;
QListWidget * m_activatedLanListWidget = nullptr; QListWidget * m_activatedLanListWidget = nullptr;
QListWidget * m_inactivatedLanListWidget = nullptr; QListWidget * m_inactivatedLanListWidget = nullptr;
LanListItem * m_testLanItem = nullptr; LanListItem * m_testLanItem = nullptr;
LanListItem * activeConnectItem = nullptr;
LanListItem * deactiveConnectItem = nullptr;
LanListItem * m_activeItem = nullptr;
LanListItem * m_deactiveItem = nullptr;
QListWidgetItem *m_listWidgetItem = nullptr; QListWidgetItem *m_listWidgetItem = nullptr;
KyNetworkDeviceResourse * m_deviceSource = nullptr; KyNetworkDeviceResourse *m_device = nullptr;
KyActiveConnectResourse *m_activeResourse = nullptr; //激活的连接 KyActiveConnectResourse *m_activeResourse = nullptr; //激活的连接
KyConnectResourse *m_connectResourse = nullptr; //未激活的连接 KyConnectResourse *m_connectResourse = nullptr; //未激活的连接
@ -61,11 +54,18 @@ private:
QMap<KyConnectItem *, QListWidgetItem *> m_deactiveMap; QMap<KyConnectItem *, QListWidgetItem *> m_deactiveMap;
QMap<KyConnectItem *, QListWidgetItem *> m_activeMap; QMap<KyConnectItem *, QListWidgetItem *> m_activeMap;
QString m_deviceName; QString m_deviceName;
QStringList devList;
QGSettings * m_switchGsettings = nullptr;
private slots: private slots:
void updateLanlist(QString uuid, NetworkManager::ActiveConnection::State state, NetworkManager::ActiveConnection::Reason reason); void updateLanlist(QString uuid, NetworkManager::ActiveConnection::State state, NetworkManager::ActiveConnection::Reason reason);
void addConnectionSlot(QString uuid); void addConnectionSlot(QString uuid);
void removeConnectionSlot(QString path); void removeConnectionSlot(QString path);
void onSwithGsettingsChanged(const QString &key);
void onLanSwitchClicked();
void onDeviceAdd(QString deviceName, NetworkManager::Device::Type deviceType);
void onDeviceRemove(QString deviceName);
void onDeviceNameUpdate(QString oldName, QString newName);
}; };
#endif // LANPAGE_H #endif // LANPAGE_H

View File

@ -1,4 +1,5 @@
#include "tabpage.h" #include "tabpage.h"
#include <qsettings.h>
TabPage::TabPage(QWidget *parent) : QWidget(parent) TabPage::TabPage(QWidget *parent) : QWidget(parent)
{ {
@ -32,7 +33,7 @@ void TabPage::initUI()
m_activatedNetFrame = new QFrame(this); m_activatedNetFrame = new QFrame(this);
m_activatedNetLayout = new QVBoxLayout(m_activatedNetFrame); m_activatedNetLayout = new QVBoxLayout(m_activatedNetFrame);
m_activatedNetLayout->setContentsMargins(NET_LAYOUT_MARGINS); m_activatedNetLayout->setContentsMargins(ACTIVE_NET_LAYOUT_MARGINS);
m_activatedNetLayout->setSpacing(NET_LAYOUT_SPACING); m_activatedNetLayout->setSpacing(NET_LAYOUT_SPACING);
m_activatedNetLabel = new QLabel(m_activatedNetFrame); m_activatedNetLabel = new QLabel(m_activatedNetFrame);
m_activatedNetLabel->setContentsMargins(TEXT_MARGINS); m_activatedNetLabel->setContentsMargins(TEXT_MARGINS);
@ -40,6 +41,7 @@ void TabPage::initUI()
m_activatedNetDivider = new Divider(this); m_activatedNetDivider = new Divider(this);
m_inactivatedNetFrame = new QFrame(this); m_inactivatedNetFrame = new QFrame(this);
m_inactivatedNetFrame->setMinimumHeight(INACTIVE_AREA_MIN_HEIGHT);
m_inactivatedNetLayout = new QVBoxLayout(m_inactivatedNetFrame); m_inactivatedNetLayout = new QVBoxLayout(m_inactivatedNetFrame);
m_inactivatedNetLayout->setContentsMargins(NET_LAYOUT_MARGINS); m_inactivatedNetLayout->setContentsMargins(NET_LAYOUT_MARGINS);
m_inactivatedNetLayout->setSpacing(NET_LAYOUT_SPACING); m_inactivatedNetLayout->setSpacing(NET_LAYOUT_SPACING);
@ -81,3 +83,51 @@ QString TabPage::getDefaultDevice()
qDebug() << "getDefaultDevice" << defaultDevice; qDebug() << "getDefaultDevice" << defaultDevice;
return defaultDevice; return defaultDevice;
} }
void setDefaultDevice(KyDeviceType deviceType, QString deviceName)
{
QString key;
switch (deviceType) {
case WIRED:
key = "wired";
break;
case WIRELESS:
key = "wireless";
break;
default:
return;
break;
}
QSettings * m_settings = new QSettings(CONFIG_FILE_PATH, QSettings::IniFormat);
m_settings->beginGroup("DEFAULTCARD");
m_settings->setValue(key, deviceName);
m_settings->endGroup();
m_settings->sync();
delete m_settings;
m_settings = nullptr;
return;
}
bool checkDeviceExist(KyDeviceType deviceType, QString deviceName)
{
NetworkManager::Device::Type type;
switch (deviceType) {
case WIRED:
type = NetworkManager::Device::Type::Ethernet;
break;
case WIRELESS:
type = NetworkManager::Device::Type::Wifi;
break;
default:
return false;
break;
}
KyNetworkDeviceResourse * kdr = new KyNetworkDeviceResourse();
QStringList devList;
devList.clear();
kdr->getNetworkDeviceList(type, devList);
delete kdr;
return devList.contains(deviceName);
}

View File

@ -14,16 +14,26 @@
#define MAIN_LAYOUT_MARGINS 0,0,0,0 #define MAIN_LAYOUT_MARGINS 0,0,0,0
#define MAIN_LAYOUT_SPACING 0 #define MAIN_LAYOUT_SPACING 0
#define TITLE_FRAME_HEIGHT 52 #define TITLE_FRAME_HEIGHT 52
#define TITLE_LAYOUT_MARGINS 24,0,0,0 #define TITLE_LAYOUT_MARGINS 24,0,24,0
#define NET_LAYOUT_MARGINS 8,8,8,8 #define ACTIVE_NET_LAYOUT_MARGINS 8,8,8,8
#define NET_LAYOUT_MARGINS 8,8,0,8
#define NET_LAYOUT_SPACING 8 #define NET_LAYOUT_SPACING 8
#define NET_LIST_SPACING 1 #define NET_LIST_SPACING 2
#define TEXT_MARGINS 16,0,0,0 #define TEXT_MARGINS 16,0,0,0
//#define SCROLL_AREA_HEIGHT 200 //#define SCROLL_AREA_HEIGHT 200
#define SETTINGS_LAYOUT_MARGINS 24,16,24,16 #define SETTINGS_LAYOUT_MARGINS 24,16,24,16
#define TRANSPARENT_COLOR QColor(0,0,0,0) #define TRANSPARENT_COLOR QColor(0,0,0,0)
#define INACTIVE_AREA_MIN_HEIGHT 200
const QString CONFIG_FILE_PATH = QDir::homePath() + "/.config/ukui/kylin-nm.conf"; enum KyDeviceType
{
WIRED,
WIRELESS
};
const QString CONFIG_FILE_PATH = QDir::homePath() + "/.config/ukui/kylin-nm.conf";
bool checkDeviceExist(KyDeviceType deviceType, QString deviceName);
void setDefaultDevice(KyDeviceType deviceType, QString deviceName);
class TabPage : public QWidget class TabPage : public QWidget
{ {

View File

@ -1,10 +1,10 @@
#include "wlanpage.h" #include "wlanpage.h"
#include "kywirelessnetitem.h" #include "kywirelessnetitem.h"
#include "dbusadaptor.h"
#include <QEvent> #include <QEvent>
#include <QDateTime> #include <QDateTime>
#include <QDebug> #include <QDebug>
#include <QSettings> #include <QSettings>
#include <QScrollBar>
WlanPage::WlanPage(QWidget *parent) : TabPage(parent) WlanPage::WlanPage(QWidget *parent) : TabPage(parent)
{ {
@ -68,6 +68,7 @@ void WlanPage::initWlanUI()
m_inactivatedNetListWidget->setSpacing(NET_LIST_SPACING); m_inactivatedNetListWidget->setSpacing(NET_LIST_SPACING);
m_inactivatedNetListWidget->setFrameShape(QFrame::Shape::NoFrame); m_inactivatedNetListWidget->setFrameShape(QFrame::Shape::NoFrame);
m_inactivatedNetListWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); m_inactivatedNetListWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_inactivatedNetListWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); //用了SCrollArea的滚动条
m_hiddenWlanWidget = new QFrame(m_inactivatedWlanListAreaCentralWidget); m_hiddenWlanWidget = new QFrame(m_inactivatedWlanListAreaCentralWidget);
m_hiddenWlanLayout = new QHBoxLayout(m_hiddenWlanWidget); m_hiddenWlanLayout = new QHBoxLayout(m_hiddenWlanWidget);
@ -189,12 +190,12 @@ void WlanPage::appendActiveWlan(const QString &ssid, int &height)
} }
KyWirelessNetItem *item_data = new KyWirelessNetItem(data); KyWirelessNetItem *item_data = new KyWirelessNetItem(data);
WlanListItem *wlanItemWidget = new WlanListItem(m_resource, item_data, defaultDevice); WlanListItem *wlanItemWidget = new WlanListItem(m_resource, item_data, defaultDevice);
wlanItemWidget->setActivated(true);
qDebug() << "Activated wlan: ssid = " << item_data->m_NetSsid; qDebug() << "Activated wlan: ssid = " << item_data->m_NetSsid;
QListWidgetItem *wlanItem = new QListWidgetItem(m_activatedNetListWidget); QListWidgetItem *wlanItem = new QListWidgetItem(m_activatedNetListWidget);
wlanItem->setSizeHint(QSize(m_activatedNetListWidget->width(), wlanItemWidget->height())); wlanItem->setSizeHint(QSize(m_activatedNetListWidget->width(), wlanItemWidget->height()));
m_activatedNetListWidget->addItem(wlanItem); m_activatedNetListWidget->addItem(wlanItem);
m_activatedNetListWidget->setItemWidget(wlanItem, wlanItemWidget); m_activatedNetListWidget->setItemWidget(wlanItem, wlanItemWidget);
wlanItemWidget->setActive(true);
height += wlanItemWidget->height(); height += wlanItemWidget->height();
} }

View File

@ -1,61 +1,83 @@
#include "infobutton.h" #include "infobutton.h"
#include <QEvent> #include <QEvent>
#include <QPainter>
#define BUTTON_SIZE 36,36
#define ICON_SIZE 16,16
#define BACKGROUND_COLOR QColor(0,0,0,0)
#define FOREGROUND_COLOR_NORMAL QColor(0,0,0,255)
#define FOREGROUND_COLOR_HOVER QColor(55,144,250,255)
#define FOREGROUND_COLOR_PRESS QColor(36,109,212,255)
#define OUTER_PATH 8,8,16,16
#define INNER_PATH 9,9,14,14
#define TEXT_POS 14,5,16,16,0
#define BUTTON_SIZE 36,36
InfoButton::InfoButton(QWidget *parent) : QPushButton(parent) InfoButton::InfoButton(QWidget *parent) : QPushButton(parent)
{ {
this->setFixedSize(BUTTON_SIZE);
initUI(); initUI();
installEventFilter(this);
} }
void InfoButton::initUI() void InfoButton::initUI()
{ {
info_img = QIcon::fromTheme("network-wired-connected-symbolic", QIcon::fromTheme("network-wired-symbolic", QIcon(":/res/l/network-online.svg"))); this->setFixedSize(BUTTON_SIZE);
info_imgHover = QIcon::fromTheme("network-wireless-signal-excellent-symbolic", QIcon(":/res/x/wifi-list-bg.svg")); m_backgroundColor = BACKGROUND_COLOR;
info_imgPressed = QIcon::fromTheme("document-page-setup-symbolic", QIcon(":/res/x/setup.png")); m_foregroundColor = FOREGROUND_COLOR_NORMAL;
setIcon(info_img);
}
bool InfoButton::event(QEvent *event)
{
switch(event->type())
{
case QEvent::Enter:
setIcon(info_imgHover);
break;
case QEvent::Leave:
setIcon(info_img);
break;
case QEvent::MouseButtonPress:
setIcon(info_imgPressed);
break;
case QEvent::MouseButtonRelease:
setIcon(info_imgHover);
break;
default:
break;
}
return QPushButton::event(event);
}
void InfoButton::enterEvent(QEvent *)
{
}
void InfoButton::leaveEvent(QEvent *)
{
}
bool InfoButton::eventFilter(QObject *w, QEvent *e)
{
if(e->type() == QEvent::MouseButtonPress) {
}
return QPushButton::eventFilter(w, e);
} }
void InfoButton::paintEvent(QPaintEvent *event) void InfoButton::paintEvent(QPaintEvent *event)
{ {
QPalette pal = this->palette();
pal.setColor(QPalette::Base, m_backgroundColor);
pal.setColor(QPalette::Text, m_foregroundColor);
return QPushButton::paintEvent(event); QPainterPath cPath;
cPath.addRect(0, 0, ICON_SIZE);
cPath.addEllipse(0, 0, ICON_SIZE);
QPainterPath outerPath;
outerPath.addEllipse(OUTER_PATH);
QPainterPath innerPath;
innerPath.addEllipse(INNER_PATH);
outerPath -= innerPath;
QPainter painter(this);
painter.setRenderHint(QPainter:: Antialiasing, true); //设置渲染,启动反锯齿
painter.setPen(Qt::NoPen);
painter.setBrush(pal.color(QPalette::Base));
painter.drawPath(cPath);
painter.fillPath(outerPath, pal.color(QPalette::Text));
painter.setPen(m_foregroundColor);
painter.drawText(TEXT_POS, "i");
}
void InfoButton::enterEvent(QEvent *event)
{
m_foregroundColor = FOREGROUND_COLOR_HOVER;
this->repaint();
}
void InfoButton::leaveEvent(QEvent *event)
{
m_foregroundColor = FOREGROUND_COLOR_NORMAL;
this->repaint();
}
void InfoButton::mousePressEvent(QMouseEvent *event)
{
m_foregroundColor = FOREGROUND_COLOR_PRESS;
this->repaint();
return QPushButton::mousePressEvent(event);
}
void InfoButton::mouseReleaseEvent(QMouseEvent *event)
{
m_foregroundColor = FOREGROUND_COLOR_HOVER;
this->repaint();
return QPushButton::mouseReleaseEvent(event);
} }

View File

@ -10,18 +10,19 @@ public:
explicit InfoButton(QWidget * parent = nullptr); explicit InfoButton(QWidget * parent = nullptr);
~InfoButton() = default; ~InfoButton() = default;
protected:
void paintEvent(QPaintEvent *event);
void enterEvent(QEvent *event);
void leaveEvent(QEvent *event);
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
private: private:
void initUI(); void initUI();
QIcon info_img;
QIcon info_imgHover;
QIcon info_imgPressed;
protected: private:
bool event(QEvent *event); QColor m_backgroundColor;
virtual void enterEvent(QEvent *event) override; QColor m_foregroundColor;
virtual void leaveEvent(QEvent *event);
bool eventFilter(QObject *watched, QEvent *event);
void paintEvent(QPaintEvent *event);
}; };
#endif // INFOBUTTON_H #endif // INFOBUTTON_H

View File

@ -1,53 +0,0 @@
#include "netbutton.h"
NetButton::NetButton(bool isActivated, QWidget *parent) : QPushButton(parent)
{
connect(this, &NetButton::requestStartLoading, this, &NetButton::onLoadingStarted);
connect(this, &NetButton::requestStopLoading, this, &NetButton::onLoadingStopped);
m_isActivated = isActivated;
this->setAutoFillBackground(false);
m_iconLabel = new QLabel(this);
m_iconLabel->setScaledContents(true);
}
void NetButton::startLoading()
{
emit this->requestStartLoading();
}
void NetButton::stopLoading()
{
emit this->requestStopLoading();
}
void NetButton::setPressed()
{
//ZJP_TODO 设置颜色为点击颜色,注意区分已连接/未连接
if (m_isActivated)
;
;
}
void NetButton::setReleased()
{
//ZJP_TODO 设置颜色为未点击颜色,注意区分已连接/未连接
if (m_isActivated)
;
;
}
void NetButton::setButtonIcon(QIcon *icon)
{
if (!icon) { return; }
m_iconLabel->setPixmap(icon->pixmap(this->size()));
}
void NetButton::onLoadingStarted()
{
//ZJP_TODO 开始播放转圈动画
}
void NetButton::onLoadingStopped()
{
//ZJP_TODO 停止播放转圈动画
}

View File

@ -1,34 +0,0 @@
#ifndef NETBUTTON_H
#define NETBUTTON_H
#include <QPushButton>
#include <QIcon>
#include <QLabel>
#define ACTIVATED true
#define INACTIVATED false
class NetButton : public QPushButton
{
Q_OBJECT
public:
NetButton(bool isActivated = INACTIVATED, QWidget * parent = nullptr);
~NetButton() = default;
void startLoading();
void stopLoading();
void setPressed();
void setReleased();
void setButtonIcon(QIcon *);
signals:
void requestStartLoading();
void requestStopLoading();
private:
bool m_isActivated = INACTIVATED;
QLabel * m_iconLabel = nullptr;
private slots:
void onLoadingStarted();
void onLoadingStopped();
};
#endif // NETBUTTON_H

View File

@ -1,14 +1,19 @@
#include "radioitembutton.h" #include "radioitembutton.h"
#include <QPainter> #include <QPainter>
#include <QStyle> #include <QStyle>
#define BUTTON_SIZE 32,32
#define ICON_SIZE 16,16
RadioItemButton::RadioItemButton(bool isActivated, QWidget *parent) : QPushButton(parent) #define BUTTON_SIZE 36,36
#define ICON_SIZE 16,16
#define BACKGROUND_COLOR QColor(0,0,0,0)
#define FOREGROUND_COLOR_NORMAL_INACTIVE QColor(230,230,230,255)
#define FOREGROUND_COLOR_PRESS_INACTIVE QColor(217,217,217,255)
#define FOREGROUND_COLOR_NORMAL_ACTIVE QColor(55,144,250,255)
#define FOREGROUND_COLOR_PRESS_ACTIVE QColor(36,109,212,255)
RadioItemButton::RadioItemButton(QWidget *parent) : QPushButton(parent)
{ {
connect(this, &RadioItemButton::requestStartLoading, this, &RadioItemButton::onLoadingStarted); connect(this, &RadioItemButton::requestStartLoading, this, &RadioItemButton::onLoadingStarted);
connect(this, &RadioItemButton::requestStopLoading, this, &RadioItemButton::onLoadingStopped); connect(this, &RadioItemButton::requestStopLoading, this, &RadioItemButton::onLoadingStopped);
m_isActivated = isActivated;
this->setAutoFillBackground(false); this->setAutoFillBackground(false);
m_iconLabel = new QLabel(this); m_iconLabel = new QLabel(this);
@ -16,6 +21,7 @@ RadioItemButton::RadioItemButton(bool isActivated, QWidget *parent) : QPushButto
m_iconLabel->setFixedSize(BUTTON_SIZE); m_iconLabel->setFixedSize(BUTTON_SIZE);
m_iconLabel->setAlignment(Qt::AlignCenter); m_iconLabel->setAlignment(Qt::AlignCenter);
setActive(false);
//JXJ_TODO loading动画 //JXJ_TODO loading动画
// switchTimer = new QTimer(this); // switchTimer = new QTimer(this);
// connect(switchTimer, &QTimer::timeout, this, &RadioItemButton::onLoadingStarted); // connect(switchTimer, &QTimer::timeout, this, &RadioItemButton::onLoadingStarted);
@ -31,22 +37,6 @@ void RadioItemButton::stopLoading()
emit this->requestStopLoading(); emit this->requestStopLoading();
} }
void RadioItemButton::setPressed()
{
//ZJP_TODO 设置颜色为点击颜色,注意区分已连接/未连接
if (m_isActivated)
;
;
}
void RadioItemButton::setReleased()
{
//ZJP_TODO 设置颜色为未点击颜色,注意区分已连接/未连接
if (m_isActivated)
;
;
}
void RadioItemButton::setButtonIcon(const QIcon &icon) void RadioItemButton::setButtonIcon(const QIcon &icon)
{ {
if (icon.isNull()) { if (icon.isNull()) {
@ -55,6 +45,12 @@ void RadioItemButton::setButtonIcon(const QIcon &icon)
//ZJP_TODO 绘制圆形按钮 //ZJP_TODO 绘制圆形按钮
m_iconLabel->setPixmap(icon.pixmap(ICON_SIZE)); m_iconLabel->setPixmap(icon.pixmap(ICON_SIZE));
} }
void RadioItemButton::setActive(const bool &isActive)
{
m_isActivated = isActive;
m_backgroundColor = m_isActivated? FOREGROUND_COLOR_NORMAL_ACTIVE : FOREGROUND_COLOR_NORMAL_INACTIVE;
}
void RadioItemButton::onLoadingStarted() void RadioItemButton::onLoadingStarted()
{ {
//ZJP_TODO 开始播放转圈动画 //ZJP_TODO 开始播放转圈动画
@ -88,8 +84,8 @@ void RadioItemButton::onLoadingStopped()
void RadioItemButton::paintEvent(QPaintEvent *event) void RadioItemButton::paintEvent(QPaintEvent *event)
{ {
QPalette pal = this->palette(); QPalette pal = this->palette();
pal.setColor(QPalette::Base, QColor(0,0,0,0)); pal.setColor(QPalette::Base, BACKGROUND_COLOR);
pal.setColor(QPalette::Text, QColor(230,230,230,255)); pal.setColor(QPalette::Text, m_backgroundColor);
QPainterPath cPath; QPainterPath cPath;
cPath.addRect(0, 0, this->width(), this->height()); cPath.addRect(0, 0, this->width(), this->height());
@ -106,12 +102,18 @@ void RadioItemButton::paintEvent(QPaintEvent *event)
painter.drawPath(cPath); painter.drawPath(cPath);
painter.fillPath(innerPath, pal.color(QPalette::Text)); painter.fillPath(innerPath, pal.color(QPalette::Text));
}
// QRect iconRect;
// iconRect = this->rect(); void RadioItemButton::mousePressEvent(QMouseEvent *event)
// iconRect.adjust(8,8,-8,-8); {
// QPixmap pixmap = this->icon().pixmap(32,32); m_backgroundColor = m_isActivated? FOREGROUND_COLOR_PRESS_ACTIVE : FOREGROUND_COLOR_PRESS_INACTIVE;
// painter.drawPixmap(iconRect, pixmap); this->repaint();
return QPushButton::mousePressEvent(event);
// return QPushButton::paintEvent(event); }
void RadioItemButton::mouseReleaseEvent(QMouseEvent *event)
{
m_backgroundColor = m_isActivated? FOREGROUND_COLOR_NORMAL_ACTIVE : FOREGROUND_COLOR_NORMAL_INACTIVE;
this->repaint();
return QPushButton::mouseReleaseEvent(event);
} }

View File

@ -4,30 +4,32 @@
#include <QIcon> #include <QIcon>
#include <QLabel> #include <QLabel>
#include<QTimer> #include<QTimer>
#define ACTIVATED true
#define INACTIVATED false
class RadioItemButton : public QPushButton class RadioItemButton : public QPushButton
{ {
Q_OBJECT Q_OBJECT
public: public:
RadioItemButton(bool isActivated = INACTIVATED, QWidget * parent = nullptr); RadioItemButton(QWidget * parent = nullptr);
~RadioItemButton() = default; ~RadioItemButton() = default;
void startLoading(); void startLoading();
void stopLoading(); void stopLoading();
void setPressed();
void setReleased();
void setButtonIcon(const QIcon &icon); void setButtonIcon(const QIcon &icon);
void setActive(const bool &isActive);
signals: signals:
void requestStartLoading(); void requestStartLoading();
void requestStopLoading(); void requestStopLoading();
private: protected:
void paintEvent(QPaintEvent *event); void paintEvent(QPaintEvent *event);
bool m_isActivated = INACTIVATED; void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
private:
bool m_isActivated = false;
QLabel * m_iconLabel = nullptr; QLabel * m_iconLabel = nullptr;
QTimer * switchTimer = nullptr; QTimer * switchTimer = nullptr;
QColor m_backgroundColor;
int currentPage; int currentPage;
int countCurrentTime; int countCurrentTime;

View File

@ -4,7 +4,6 @@ HEADERS += \
$$PWD/divider.h \ $$PWD/divider.h \
$$PWD/infobutton.h \ $$PWD/infobutton.h \
$$PWD/loadingdiv.h \ $$PWD/loadingdiv.h \
$$PWD/netbutton.h \
$$PWD/radioitembutton.h \ $$PWD/radioitembutton.h \
$$PWD/switchbutton.h $$PWD/switchbutton.h
@ -13,6 +12,5 @@ SOURCES += \
$$PWD/divider.cpp \ $$PWD/divider.cpp \
$$PWD/infobutton.cpp \ $$PWD/infobutton.cpp \
$$PWD/loadingdiv.cpp \ $$PWD/loadingdiv.cpp \
$$PWD/netbutton.cpp \
$$PWD/radioitembutton.cpp \ $$PWD/radioitembutton.cpp \
$$PWD/switchbutton.cpp $$PWD/switchbutton.cpp