diff --git a/src/backend/dbus-interface/kylinnetworkresourcemanager.cpp b/src/backend/dbus-interface/kylinnetworkresourcemanager.cpp index 87bdbfeb..119847d8 100644 --- a/src/backend/dbus-interface/kylinnetworkresourcemanager.cpp +++ b/src/backend/dbus-interface/kylinnetworkresourcemanager.cpp @@ -166,7 +166,7 @@ void KyNetworkResourceManager::addActiveConnection(NetworkManager::ActiveConnect connect(conn.data(), &NetworkManager::ActiveConnection::masterChanged, 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::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::uuidChanged, this, &KyNetworkResourceManager::onActiveConnectionUpdated); connect(conn.data(), &NetworkManager::ActiveConnection::devicesChanged, this, &KyNetworkResourceManager::onActiveConnectionUpdated); @@ -543,6 +543,21 @@ void KyNetworkResourceManager::onActiveConnectionChangedReason( return; } +void KyNetworkResourceManager::onActiveConnectionChanged( + NetworkManager::ActiveConnection::State state) +{ + NetworkManager::ActiveConnection * activeConnect = + qobject_cast(sender()); + if (activeConnect->isValid()) { + qDebug()<<"!New state change activate connect"<uuid(); + qDebug()<<"!New the active connect state"< &map) 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 */ diff --git a/src/backend/dbusadaptor.h b/src/backend/dbusadaptor.h index be0f1fbd..124bde0d 100644 --- a/src/backend/dbusadaptor.h +++ b/src/backend/dbusadaptor.h @@ -16,6 +16,7 @@ #include #include +#include "tabpage.h" #include "../dbus-interface/kylinnetworkdeviceresource.h" QT_BEGIN_NAMESPACE class QByteArray; @@ -84,15 +85,6 @@ class 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 { Q_OBJECT diff --git a/src/frontend/list-items/listitem.cpp b/src/frontend/list-items/listitem.cpp index 6e3b8da2..0102288d 100644 --- a/src/frontend/list-items/listitem.cpp +++ b/src/frontend/list-items/listitem.cpp @@ -5,7 +5,7 @@ #define MAIN_LAYOUT_SPACING 0 #define ITEM_FRAME_MARGINS 16,6,16,6 #define ITEM_FRAME_SPACING 10 - +#define FRAME_WIDTH 395 #define INFO_ICON_WIDTH 16 #define INFO_ICON_HEIGHT 16 @@ -55,10 +55,11 @@ void ListItem::initUI() this->setLayout(m_mainLayout); m_itemFrame = new QFrame(this); + m_itemFrame->setFixedWidth(FRAME_WIDTH); m_hItemLayout = new QHBoxLayout(m_itemFrame); 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_nameLabel = new QLabel(m_itemFrame); diff --git a/src/frontend/tab-pages/lanpage.cpp b/src/frontend/tab-pages/lanpage.cpp index 126e8b1f..e70544ff 100644 --- a/src/frontend/tab-pages/lanpage.cpp +++ b/src/frontend/tab-pages/lanpage.cpp @@ -14,17 +14,31 @@ #define SWITCH_HEIGHT 24 #define ITEM_HEIGHT 48 +const QString WIRED_SWITCH = "wiredswitch"; +const QByteArray GSETTINGS_SCHEMA = "org.ukui.kylin-nm.switch"; + LanPage::LanPage(QWidget *parent) : TabPage(parent) { m_activeResourse = new KyActiveConnectResourse; m_connectResourse = new KyConnectResourse; m_device = new KyNetworkDeviceResourse; + devList.empty(); + initDevice(); 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(); connect(m_activeResourse, &KyActiveConnectResourse::stateChangeReason, this, &LanPage::updateLanlist); connect(m_connectResourse, &KyConnectResourse::connectionAdd, this, &LanPage::addConnectionSlot); 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() @@ -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 ::"<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:"<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) //删除时后端会自动断开激活,将其从未激活列表中删除 { qDebug()<<"[LanPage] Removing a connection, path:"<getConnectionItemByUuid(uuid, m_deviceName); if (newItem != nullptr) { - qDebug()<<"[LanPage] Add a new connection, name:"<m_connectName; - LanListItem * newListItem = new LanListItem(newItem, m_deviceName); - 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); + if (newItem->m_itemType == NetworkManager::ConnectionSettings::ConnectionType::Wired) { + qDebug()<<"[LanPage] Add a new connection, name:"<m_connectName; + addNewItem(newItem, m_inactivatedLanListWidget); + m_deactiveMap.insert(newItem, m_listWidgetItem); + } } else { qDebug()<<"[LanPage] GetConnectionItemByUuid is empty when add a new!"; } @@ -78,11 +122,8 @@ void LanPage::initDevice() m_deviceName = m_settings->value(key, "").toString(); if (m_deviceName.isEmpty()) { qDebug() << "initDevice but defalut wired card is null"; - QStringList list; - list.empty(); - m_device->getNetworkDeviceList(NetworkManager::Device::Type::Ethernet, list); - if (!list.isEmpty()) { - m_deviceName = list.at(0); + if (!devList.isEmpty()) { + m_deviceName = devList.at(0); m_settings->setValue(key, m_deviceName); } } @@ -93,6 +134,60 @@ void LanPage::initDevice() m_settings->sync(); delete m_settings; 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() @@ -103,22 +198,28 @@ void LanPage::initUI() m_activatedNetLabel->setText(tr("Activated LAN")); m_activatedLanListWidget = new QListWidget(m_activatedNetFrame); m_activatedLanListWidget->setFrameShape(QFrame::Shape::NoFrame); -// m_activatedLanListWidget->setContentsMargins(MAIN_LAYOUT_MARGINS); m_activatedLanListWidget->setSpacing(LAN_LIST_SPACING); m_activatedLanListWidget->setFixedHeight(ITEM_HEIGHT); //active区域固定高度,只显示一个条目 + m_activatedLanListWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); m_activatedNetLayout->addWidget(m_activatedLanListWidget); m_inactivatedNetLabel->setText(tr("Inactivated LAN")); + m_inactivatedNetListArea->setBackgroundRole(QPalette::Base); m_inactivatedNetListArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); 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->setFrameShape(QFrame::Shape::NoFrame); -// m_inactivatedLanListWidget->setContentsMargins(MAIN_LAYOUT_MARGINS); 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); // KyConnectItem *activeConnectItem = new KyConnectItem(); @@ -132,7 +233,16 @@ void LanPage::initUI() // m_listWidgetItem = new QListWidgetItem(m_inactivatedLanListWidget); // m_inactivatedLanListWidget->addItem(m_listWidgetItem); // 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() //程序拉起,初始化显示 @@ -140,15 +250,9 @@ void LanPage::initList() //程序拉起,初始化显示 m_activeResourse->getActiveConnectionList(m_deviceName,NetworkManager::ConnectionSettings::Wired,m_activedList); //激活列表的显示 if (!m_activedList.isEmpty()) { 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); - - activeConnectItem = new LanListItem(activeItemData, m_deviceName); - - m_activatedLanListWidget->setItemWidget(m_listWidgetItem, activeConnectItem); + addNewItem(activeItemData, m_activatedLanListWidget); m_activeMap.insert(activeItemData, m_listWidgetItem); } @@ -157,16 +261,8 @@ void LanPage::initList() //程序拉起,初始化显示 m_connectResourse->getConnectionList(m_deviceName, NetworkManager::ConnectionSettings::Wired, m_deactivedList); //未激活列表的显示 if (!m_deactivedList.isEmpty()) { 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); - - deactiveConnectItem = new LanListItem(deactiveItemData ,m_deviceName); - -// deactiveConnectItem->setFixedHeight(ITEM_HEIGHT); - m_inactivatedLanListWidget->setItemWidget(m_listWidgetItem, deactiveConnectItem); + addNewItem(deactiveItemData, m_inactivatedLanListWidget); 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!"; QMap::iterator iter; //在未激活列表里删除 for (iter = m_deactiveMap.begin(); iter != m_deactiveMap.constEnd(); ++iter) { - KyConnectItem *m_Item = iter.key(); - if (m_Item->m_connectUuid == uuid) { - qDebug()<<"Add an active connection to activeList:"<m_connectName; - m_Item->m_connectState = state; - - 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); + KyConnectItem *m_item = iter.key(); + if (m_item->m_connectUuid == uuid) { + qDebug()<<"Add an active connection to activeList:"<m_connectName; + m_item->m_connectState = state; + addNewItem(m_item, m_activatedLanListWidget); m_inactivatedLanListWidget->removeItemWidget(iter.value()); delete(iter.value()); - m_activeMap.insert(m_Item, m_listWidgetItem); + m_activeMap.insert(m_item, m_listWidgetItem); m_deactiveMap.erase(iter); break; } @@ -205,8 +294,8 @@ void LanPage::updateLanlist(QString uuid, NetworkManager::ActiveConnection::Stat qDebug()<<"Get a deactivate, begin to remove it from activeList"; QMap::iterator i; for (i = m_activeMap.begin(); i != m_activeMap.constEnd(); ++i) { //有新断开,若在激活列表里则删掉 - KyConnectItem *m_Item = i.key(); - if (m_Item->m_connectUuid == uuid) { + KyConnectItem *m_item = i.key(); + if (m_item->m_connectUuid == uuid) { m_activatedLanListWidget->removeItemWidget(i.value()); delete(i.value()); break; @@ -216,8 +305,8 @@ void LanPage::updateLanlist(QString uuid, NetworkManager::ActiveConnection::Stat bool hasDeactiveNet = false; QMap::iterator iter; for (iter = m_deactiveMap.begin(); iter != m_deactiveMap.end(); ++iter) { //检查其是否已经在未激活列表中 - KyConnectItem *m_Item = iter.key(); - if (m_Item->m_connectUuid == uuid) { + KyConnectItem *m_item = iter.key(); + if (m_item->m_connectUuid == uuid) { hasDeactiveNet = true; break; } @@ -226,21 +315,14 @@ void LanPage::updateLanlist(QString uuid, NetworkManager::ActiveConnection::Stat QMap::iterator iters; for (iters = m_activeMap.begin(); iters != m_activeMap.end(); ++iters) { //在未激活列表中增加一项连接 - KyConnectItem *m_Item = iters.key(); - if (m_Item->m_connectUuid == uuid && !hasDeactiveNet) { - qDebug()<<"Add a deactive connection to inactiveList:"<m_connectName; - m_Item->m_connectState = state; - m_deactiveItem = new LanListItem(m_Item ,m_deviceName); - m_deactiveItem->setFixedHeight(ITEM_HEIGHT); + KyConnectItem *m_item = iters.key(); + if (m_item->m_connectUuid == uuid && !hasDeactiveNet) { + qDebug()<<"Add a deactive connection to inactiveList:"<m_connectName; + m_item->m_connectState = state; - 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, m_deactiveItem); - - m_deactiveMap.insert(m_Item, m_listWidgetItem); + addNewItem(m_item, m_inactivatedLanListWidget); + m_deactiveMap.insert(m_item, m_listWidgetItem); m_activeMap.erase(iters); 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); -} - diff --git a/src/frontend/tab-pages/lanpage.h b/src/frontend/tab-pages/lanpage.h index aedc004b..65c8ffd2 100644 --- a/src/frontend/tab-pages/lanpage.h +++ b/src/frontend/tab-pages/lanpage.h @@ -9,6 +9,7 @@ #include #include #include +#include #include "list-items/listitem.h" #include "list-items/lanlistitem.h" @@ -27,25 +28,17 @@ private: void initDevice();//初始化默认设备 void initUI(); void initList(); - bool eventFilter(QObject *watched, QEvent *event); void addNewItem(KyConnectItem *itemData, QListWidget *listWidget); - + void initNetSwitch(); private: - KyNetworkDeviceResourse *m_device = nullptr; - QListWidget * m_activatedLanListWidget = nullptr; QListWidget * m_inactivatedLanListWidget = nullptr; LanListItem * m_testLanItem = nullptr; - LanListItem * activeConnectItem = nullptr; - LanListItem * deactiveConnectItem = nullptr; - LanListItem * m_activeItem = nullptr; - LanListItem * m_deactiveItem = nullptr; - QListWidgetItem *m_listWidgetItem = nullptr; - KyNetworkDeviceResourse * m_deviceSource = nullptr; + KyNetworkDeviceResourse *m_device = nullptr; KyActiveConnectResourse *m_activeResourse = nullptr; //激活的连接 KyConnectResourse *m_connectResourse = nullptr; //未激活的连接 @@ -55,11 +48,18 @@ private: QMap m_deactiveMap; QMap m_activeMap; QString m_deviceName; + QStringList devList; + QGSettings * m_switchGsettings = nullptr; private slots: void updateLanlist(QString uuid, NetworkManager::ActiveConnection::State state, NetworkManager::ActiveConnection::Reason reason); void addConnectionSlot(QString uuid); 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 diff --git a/src/frontend/tab-pages/tabpage.cpp b/src/frontend/tab-pages/tabpage.cpp index 9ec33860..bc7a3e36 100644 --- a/src/frontend/tab-pages/tabpage.cpp +++ b/src/frontend/tab-pages/tabpage.cpp @@ -1,4 +1,5 @@ #include "tabpage.h" +#include TabPage::TabPage(QWidget *parent) : QWidget(parent) { @@ -32,7 +33,7 @@ void TabPage::initUI() m_activatedNetFrame = new QFrame(this); 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_activatedNetLabel = new QLabel(m_activatedNetFrame); m_activatedNetLabel->setContentsMargins(TEXT_MARGINS); @@ -82,3 +83,51 @@ QString TabPage::getDefaultDevice() qDebug() << "getDefaultDevice" << 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); +} diff --git a/src/frontend/tab-pages/tabpage.h b/src/frontend/tab-pages/tabpage.h index 0b39df7a..9bec0fa3 100644 --- a/src/frontend/tab-pages/tabpage.h +++ b/src/frontend/tab-pages/tabpage.h @@ -14,17 +14,26 @@ #define MAIN_LAYOUT_MARGINS 0,0,0,0 #define MAIN_LAYOUT_SPACING 0 #define TITLE_FRAME_HEIGHT 52 -#define TITLE_LAYOUT_MARGINS 24,0,0,0 -#define NET_LAYOUT_MARGINS 8,8,8,8 +#define TITLE_LAYOUT_MARGINS 24,0,24,0 +#define ACTIVE_NET_LAYOUT_MARGINS 8,8,8,8 +#define NET_LAYOUT_MARGINS 8,8,0,8 #define NET_LAYOUT_SPACING 8 -#define NET_LIST_SPACING 1 +#define NET_LIST_SPACING 2 #define TEXT_MARGINS 16,0,0,0 //#define SCROLL_AREA_HEIGHT 200 #define SETTINGS_LAYOUT_MARGINS 24,16,24,16 #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 { diff --git a/src/frontend/tab-pages/wlanpage.cpp b/src/frontend/tab-pages/wlanpage.cpp index 3bff6cce..1635d421 100644 --- a/src/frontend/tab-pages/wlanpage.cpp +++ b/src/frontend/tab-pages/wlanpage.cpp @@ -1,10 +1,10 @@ #include "wlanpage.h" #include "kywirelessnetitem.h" -#include "dbusadaptor.h" #include #include #include #include +#include WlanPage::WlanPage(QWidget *parent) : TabPage(parent) { @@ -63,6 +63,7 @@ void WlanPage::initWlanUI() m_inactivatedNetListWidget->setSpacing(NET_LIST_SPACING); m_inactivatedNetListWidget->setFrameShape(QFrame::Shape::NoFrame); m_inactivatedNetListWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + m_inactivatedNetListWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); //用了SCrollArea的滚动条 m_hiddenWlanWidget = new QFrame(m_inactivatedWlanListAreaCentralWidget); m_hiddenWlanLayout = new QHBoxLayout(m_hiddenWlanWidget); diff --git a/src/frontend/tools/infobutton.cpp b/src/frontend/tools/infobutton.cpp index 1c91e936..50cad55b 100644 --- a/src/frontend/tools/infobutton.cpp +++ b/src/frontend/tools/infobutton.cpp @@ -12,8 +12,11 @@ #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) { + this->setFixedSize(BUTTON_SIZE); initUI(); } diff --git a/src/frontend/tools/radioitembutton.cpp b/src/frontend/tools/radioitembutton.cpp index 727469b4..5bc65558 100644 --- a/src/frontend/tools/radioitembutton.cpp +++ b/src/frontend/tools/radioitembutton.cpp @@ -1,6 +1,7 @@ #include "radioitembutton.h" #include #include + #define BUTTON_SIZE 36,36 #define ICON_SIZE 16,16 #define BACKGROUND_COLOR QColor(0,0,0,0)