界面布局调整

This commit is contained in:
ksn 2021-09-02 18:51:41 +08:00
parent 16643e8d2a
commit 4ab98f7cda
13 changed files with 250 additions and 156 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

@ -72,54 +72,6 @@ bool getDeviceEnableState(QMap<QString, bool> &map)
return true; return true;
} }
//设置默认网卡
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;
@ -84,15 +85,6 @@ class WirelessInfo
}; };
Q_DECLARE_METATYPE(WirelessInfo) Q_DECLARE_METATYPE(WirelessInfo)
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

@ -45,8 +45,8 @@ bool LanListItem::eventFilter(QObject *watched, QEvent *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

@ -4,7 +4,7 @@
#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
@ -47,10 +47,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);

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;
@ -55,16 +104,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) {
if (newItem->m_itemType == NetworkManager::ConnectionSettings::ConnectionType::Wired) {
qDebug()<<"[LanPage] Add a new connection, name:"<<newItem->m_connectName; qDebug()<<"[LanPage] Add a new connection, name:"<<newItem->m_connectName;
LanListItem * newListItem = new LanListItem(newItem, m_deviceName); addNewItem(newItem, m_inactivatedLanListWidget);
newListItem->setFixedHeight(ITEM_HEIGHT);
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); m_deactiveMap.insert(newItem, m_listWidgetItem);
}
} else { } else {
qDebug()<<"[LanPage] GetConnectionItemByUuid is empty when add a new!"; qDebug()<<"[LanPage] GetConnectionItemByUuid is empty when add a new!";
} }
@ -78,11 +122,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);
} }
} }
@ -93,6 +134,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()
@ -103,22 +198,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();
@ -132,7 +233,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() //程序拉起,初始化显示
@ -140,15 +250,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);
} }
@ -157,16 +261,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);
} }
@ -180,23 +276,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;
} }
@ -205,8 +294,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;
@ -216,8 +305,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;
} }
@ -226,21 +315,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;
} }
@ -250,15 +332,3 @@ 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);
}

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"
@ -27,25 +28,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; //未激活的连接
@ -55,11 +48,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);
@ -81,3 +82,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,25 @@
#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)
enum KyDeviceType
{
WIRED,
WIRELESS
};
const QString CONFIG_FILE_PATH = QDir::homePath() + "/.config/ukui/kylin-nm.conf"; 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)
{ {
@ -63,6 +63,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);

View File

@ -1,8 +1,11 @@
#include "infobutton.h" #include "infobutton.h"
#include <QEvent> #include <QEvent>
#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); installEventFilter(this);
} }

View File

@ -1,8 +1,8 @@
#include "radioitembutton.h" #include "radioitembutton.h"
#include <QPainter> #include <QPainter>
#include <QStyle> #include <QStyle>
#define BUTTON_SIZE 32,32
#define ICON_SIZE 16,16 #define ICON_SIZE 16,16
#define BUTTON_SIZE 36,36
RadioItemButton::RadioItemButton(bool isActivated, QWidget *parent) : QPushButton(parent) RadioItemButton::RadioItemButton(bool isActivated, QWidget *parent) : QPushButton(parent)
{ {