diff --git a/src/backend/dbus-interface/kywirelessconnectoperation.cpp b/src/backend/dbus-interface/kywirelessconnectoperation.cpp index afa8593b..aa338bb0 100644 --- a/src/backend/dbus-interface/kywirelessconnectoperation.cpp +++ b/src/backend/dbus-interface/kywirelessconnectoperation.cpp @@ -365,7 +365,9 @@ void KyWirelessConnectOperation::addAndActiveWirelessConnect(QString & devIface, NetworkManager::WirelessNetwork::Ptr wifiNet = checkWifiNetExist(connSettingInfo.m_ssid, devIface); if (!isHidden && wifiNet.isNull()) { - qDebug() << "addAndActiveWirelessConnect can not find " << connSettingInfo.m_ssid << " in " << devIface; + QString errorMessage = "the ssid " + connSettingInfo.m_ssid + " is not exsit in " + devIface; + qWarning()<info2.m_signalStrength; + } + return info1.m_isConfigured; +} + +static void wifiListSort(QList &list) +{ + qSort(list.begin(), list.end(), subWifiListSort); +} + KyWirelessNetResource::KyWirelessNetResource(QObject *parent) : QObject(parent) { @@ -32,6 +45,11 @@ bool KyWirelessNetResource::getAllDeviceWifiNetwork(QMap >::iterator iter = m_WifiNetworkList.begin(); + while (iter != m_WifiNetworkList.end()) { + wifiListSort(m_WifiNetworkList[iter.key()]); + iter++; + } map = m_WifiNetworkList; return true; } @@ -45,6 +63,7 @@ bool KyWirelessNetResource::getDeviceWifiNetwork(QString devIfaceName, QListm_activeConns; - if (activeConnectionList.isEmpty()) - { + if (activeConnectionList.isEmpty()) { return; } NetworkManager::ActiveConnection::Ptr activeConnectionPtr = nullptr; - for (; index < activeConnectionList.size(); index++) - { + for (; index < activeConnectionList.size(); index++) { activeConnectionPtr = activeConnectionList.at(index); - if (NetworkManager::ConnectionSettings::ConnectionType::Wireless != activeConnectionPtr->type()) - { + if (NetworkManager::ConnectionSettings::ConnectionType::Wireless != activeConnectionPtr->type()) { continue; } - if (state != activeConnectionPtr->state()) - { + if (state != activeConnectionPtr->state()) { continue; } QString ssid; @@ -130,14 +144,12 @@ void KyWirelessNetResource::kyWirelessNetItemListInit() if (devIface.isEmpty()) { continue; } - + KyWirelessNetItem item(net); if (!m_WifiNetworkList.contains(devIface)){ QList list; - KyWirelessNetItem item(net); list.append(item); m_WifiNetworkList.insert(devIface,list); } else { - KyWirelessNetItem item(net); m_WifiNetworkList[devIface].append(item); } } @@ -147,14 +159,12 @@ void KyWirelessNetResource::kyWirelessNetItemListInit() QString KyWirelessNetResource::getDeviceIFace(NetworkManager::WirelessNetwork::Ptr net) { - if (net.isNull()) - { + if (net.isNull()) { return ""; } QString devUni = net->device(); NetworkManager::Device::Ptr dev = m_networkResourceInstance->findDeviceUni(devUni); - if (dev.isNull()) - { + if (dev.isNull()) { qDebug() << "KyWirelessNetResource: can't find " << net->ssid() << " find in device list"; return ""; } @@ -194,22 +204,18 @@ QString KyWirelessNetResource::getDeviceIFace(NetworkManager::WirelessNetwork::P void KyWirelessNetResource::onWifiNetworkAdded(QString devIfaceName, QString ssid) { NetworkManager::WirelessNetwork::Ptr wifi = nullptr; - for (auto const & net : m_networkResourceInstance->m_wifiNets) - { - if (net->ssid() == ssid && m_networkResourceInstance->findDeviceUni(net->device())->interfaceName() == devIfaceName ) - { + for (auto const & net : m_networkResourceInstance->m_wifiNets) { + if (net->ssid() == ssid && m_networkResourceInstance->findDeviceUni(net->device())->interfaceName() == devIfaceName) { wifi = net; } } - if (wifi.isNull()) - { + if (wifi.isNull()) { return; } KyWirelessNetItem item(wifi); - if (m_WifiNetworkList.contains(devIfaceName)) - { + if (m_WifiNetworkList.contains(devIfaceName)) { m_WifiNetworkList[devIfaceName].append(item); } else { QList list; @@ -222,19 +228,15 @@ void KyWirelessNetResource::onWifiNetworkAdded(QString devIfaceName, QString ssi void KyWirelessNetResource::onWifiNetworkRemoved(QString devIfaceName, QString ssid) { - if (m_WifiNetworkList.contains(devIfaceName)) - { + if (m_WifiNetworkList.contains(devIfaceName)) { int index = 0; - for ( ; index < m_WifiNetworkList.value(devIfaceName).size(); index++) - { - if ( m_WifiNetworkList[devIfaceName].at(index).m_NetSsid == ssid) - { + for ( ; index < m_WifiNetworkList.value(devIfaceName).size(); index++) { + if ( m_WifiNetworkList[devIfaceName].at(index).m_NetSsid == ssid) { m_WifiNetworkList[devIfaceName].removeAt(index); } } //remove后为空则删除 - if (m_WifiNetworkList.value(devIfaceName).isEmpty()) - { + if (m_WifiNetworkList.value(devIfaceName).isEmpty()) { m_WifiNetworkList.remove(devIfaceName); } emit wifiNetworkRemove(devIfaceName,ssid); @@ -248,29 +250,24 @@ void KyWirelessNetResource::onWifiNetworkPropertyChange(NetworkManager::Wireless } QString devIface = m_networkResourceInstance->findDeviceUni(net->device())->interfaceName(); - if (m_WifiNetworkList.contains(devIface)) - { + if (m_WifiNetworkList.contains(devIface)) { QList::iterator iter = m_WifiNetworkList[devIface].begin(); - while (iter != m_WifiNetworkList[devIface].end()) - { - if (iter->m_NetSsid == net->ssid()) - { + while (iter != m_WifiNetworkList[devIface].end()) { + if (iter->m_NetSsid == net->ssid()) { qDebug()<<"recive properity changed signal, sender is" << iter->m_NetSsid; - if (iter->m_signalStrength != net->signalStrength()) - { + if (iter->m_signalStrength != net->signalStrength()) { iter->m_signalStrength = net->signalStrength(); emit signalStrengthChange(devIface, net->ssid(), iter->m_signalStrength); } - if (iter->m_bssid != net->referenceAccessPoint()->hardwareAddress()) - { + if (iter->m_bssid != net->referenceAccessPoint()->hardwareAddress()) { iter->m_bssid = net->referenceAccessPoint()->hardwareAddress(); emit bssidChange(devIface, net->ssid(), iter->m_bssid); } - QString secuType = enumToQstring(net->referenceAccessPoint()->capabilities(), net->referenceAccessPoint()->wpaFlags(), net->referenceAccessPoint()->rsnFlags()); - if (iter->m_secuType != secuType) - { + QString secuType = enumToQstring(net->referenceAccessPoint()->capabilities(), + net->referenceAccessPoint()->wpaFlags(), net->referenceAccessPoint()->rsnFlags()); + if (iter->m_secuType != secuType) { iter->m_secuType = secuType; emit secuTypeChange(devIface, net->ssid(), secuType); } @@ -291,44 +288,33 @@ void KyWirelessNetResource::onWifiNetworkDeviceDisappear() bool KyWirelessNetResource::getEnterPriseInfoTls(QString &uuid, KyEapMethodTlsInfo &info) { NetworkManager::Connection::Ptr conn = m_networkResourceInstance->getConnect(uuid); - if (conn.isNull()) - { + if (conn.isNull()) { qDebug() << "modifyEnterPriseInfoTls connection missing"; return false; } NetworkManager::WirelessSecuritySetting::Ptr security_sett = conn->settings()->setting(NetworkManager::Setting::WirelessSecurity).dynamicCast(); - if (security_sett.isNull()) - { + if (security_sett.isNull()) { qDebug() << "don't have WirelessSecurity connection"; return false; } - if (security_sett->keyMgmt() != NetworkManager::WirelessSecuritySetting::WpaEap) - { + if (security_sett->keyMgmt() != NetworkManager::WirelessSecuritySetting::WpaEap) { return false; } NetworkManager::Security8021xSetting::Ptr setting = conn->settings()->setting(NetworkManager::Setting::Security8021x).dynamicCast(); - if (setting.isNull()) - { + if (setting.isNull()) { qDebug() << "don't have Security8021x connection"; return false; } - QList list; - list.append(NetworkManager::Security8021xSetting::EapMethod::EapMethodTls); - setting->setEapMethods(list); - setting->setIdentity(info.identity); - if(!info.domain.isEmpty()) - { - setting->setDomainSuffixMatch(info.domain); - } - setting->setCaPath(info.caCertPath); - setting->setClientCertificate(info.clientCertPath.toLocal8Bit()); - setting->setPrivateKey(info.clientPrivateKey.toLocal8Bit()); - setting->setPrivateKeyPassword(info.clientPrivateKeyPWD); + info.identity = setting->identity(); + info.domain = setting->domainSuffixMatch(); - conn->update(conn->settings()->toMap()); + info.caCertPath = setting->caPath(); + info.clientCertPath = setting->clientCertificate(); + info.clientPrivateKey = QString(setting->privateKey()); + info.clientPrivateKeyPWD = setting->privateKeyPassword(); return true; } @@ -336,26 +322,22 @@ bool KyWirelessNetResource::getEnterPriseInfoTls(QString &uuid, KyEapMethodTlsIn bool KyWirelessNetResource::getEnterPriseInfoPeap(QString &uuid, KyEapMethodPeapInfo &info) { NetworkManager::Connection::Ptr conn = m_networkResourceInstance->getConnect(uuid); - if (conn.isNull()) - { + if (conn.isNull()) { qDebug() << "getEnterPriseInfoPeap connection missing"; return false; } NetworkManager::WirelessSecuritySetting::Ptr security_sett = conn->settings()->setting(NetworkManager::Setting::WirelessSecurity).dynamicCast(); - if (security_sett.isNull()) - { + if (security_sett.isNull()) { qDebug() << "don't have WirelessSecurity connection"; return false; } - if (security_sett->keyMgmt() != NetworkManager::WirelessSecuritySetting::WpaEap) - { + if (security_sett->keyMgmt() != NetworkManager::WirelessSecuritySetting::WpaEap) { qDebug() << "keyMgmt not WpaEap " << security_sett->keyMgmt(); return false; } NetworkManager::Security8021xSetting::Ptr setting = conn->settings()->setting(NetworkManager::Setting::Security8021x).dynamicCast(); - if (setting.isNull() || !setting->eapMethods().contains(NetworkManager::Security8021xSetting::EapMethod::EapMethodPeap)) - { + if (setting.isNull() || !setting->eapMethods().contains(NetworkManager::Security8021xSetting::EapMethod::EapMethodPeap)) { qDebug() << "don't have Security8021x connection"; return false; } @@ -370,28 +352,24 @@ bool KyWirelessNetResource::getEnterPriseInfoPeap(QString &uuid, KyEapMethodPeap bool KyWirelessNetResource::getEnterPriseInfoTtls(QString &uuid, KyEapMethodTtlsInfo &info) { NetworkManager::Connection::Ptr conn = m_networkResourceInstance->getConnect(uuid); - if (conn.isNull()) - { + if (conn.isNull()) { qDebug() << "modifyEnterPriseInfoTtls connection missing"; return false; } NetworkManager::WirelessSecuritySetting::Ptr security_sett = conn->settings()->setting(NetworkManager::Setting::WirelessSecurity).dynamicCast(); - if (security_sett.isNull()) - { + if (security_sett.isNull()) { qDebug() << "don't have WirelessSecurity connection"; return false; } - if (security_sett->keyMgmt() != NetworkManager::WirelessSecuritySetting::WpaEap) - { + if (security_sett->keyMgmt() != NetworkManager::WirelessSecuritySetting::WpaEap) { qDebug() << "not wpaeap"<keyMgmt(); return false; } NetworkManager::Security8021xSetting::Ptr setting = conn->settings()->setting(NetworkManager::Setting::Security8021x).dynamicCast(); - if (setting.isNull() || !setting->eapMethods().contains(NetworkManager::Security8021xSetting::EapMethod::EapMethodTtls)) - { + if (setting.isNull() || !setting->eapMethods().contains(NetworkManager::Security8021xSetting::EapMethod::EapMethodTtls)) { qDebug() << "don't have Security8021x connection"; return false; } @@ -400,8 +378,7 @@ bool KyWirelessNetResource::getEnterPriseInfoTtls(QString &uuid, KyEapMethodTtls info.authNoEapMethod = (KyNoEapMethodAuth)setting->phase2AuthMethod(); info.authType = KyTtlsAuthMethod::AUTH_EAP; - if (info.authEapMethod != KyAuthEapMethodUnknown) - { + if (info.authEapMethod != KyAuthEapMethodUnknown) { info.authType = KyTtlsAuthMethod::AUTH_EAP; } else { info.authType = KyTtlsAuthMethod::AUTH_NO_EAP; @@ -417,14 +394,12 @@ void KyWirelessNetResource::onConnectionAdd(QString uuid) { qDebug() << "onConnectionAdd " << uuid; NetworkManager::Connection::Ptr conn = m_networkResourceInstance->getConnect(uuid); - if (conn.isNull()) - { + if (conn.isNull()) { qDebug() << "onConnectionAdd can not find connection" << uuid; return; } NetworkManager::ConnectionSettings::Ptr sett= conn->settings(); - if (sett->connectionType() != NetworkManager::ConnectionSettings::ConnectionType::Wireless) - { + if (sett->connectionType() != NetworkManager::ConnectionSettings::ConnectionType::Wireless) { return; } NetworkManager::WirelessSetting::Ptr wireless_sett = sett->setting(NetworkManager::Setting::Wireless).dynamicCast(); @@ -469,8 +444,7 @@ void KyWirelessNetResource::onConnectionRemove(QString path) while (iter != m_WifiNetworkList.end()) { qDebug() << iter.key(); - for(int i = 0; i < iter.value().size(); i++) - { + for(int i = 0; i < iter.value().size(); i++) { qDebug() << iter.value().at(i).m_connDbusPath; if (iter.value().at(i).m_connDbusPath == path) { @@ -504,14 +478,13 @@ void KyWirelessNetResource::onConnectionUpdate(QString uuid) { qDebug() << "onConnectionUpdate " << uuid; NetworkManager::Connection::Ptr conn = m_networkResourceInstance->getConnect(uuid); - if (conn.isNull()) - { + if (conn.isNull()) { qDebug() << "onConnectionAdd can not find connection" << uuid; return; } + NetworkManager::ConnectionSettings::Ptr sett= conn->settings(); - if (sett->connectionType() != NetworkManager::ConnectionSettings::ConnectionType::Wireless) - { + if (sett->connectionType() != NetworkManager::ConnectionSettings::ConnectionType::Wireless) { return; } m_WifiNetworkList.clear(); diff --git a/src/backend/dbusadaptor.cpp b/src/backend/dbusadaptor.cpp index 3f7bc2c0..e9f51e1a 100644 --- a/src/backend/dbusadaptor.cpp +++ b/src/backend/dbusadaptor.cpp @@ -17,6 +17,61 @@ #include #include +const QByteArray GSETTINGS_SCHEMA_KYLIN_NM = "org.ukui.kylin-nm.switch"; +const QString KEY_WIRELESS_SWITCH = "wirelessswitch"; +const QString KEY_WIRED_SWITCH = "wiredswitch"; + +void saveDeviceEnableState(QString deviceName, bool enable) +{ + QSettings * m_settings = new QSettings(CONFIG_FILE_PATH, QSettings::IniFormat); + m_settings->beginGroup("CARDEABLE"); + m_settings->setValue(deviceName, enable); + m_settings->endGroup(); + m_settings->sync(); + delete m_settings; + m_settings = nullptr; + return; +} + +bool getDeviceEnableState(QMap &map) +{ + if (!QFile::exists(CONFIG_FILE_PATH)) { + return false; + } + map.clear(); + + KyNetworkDeviceResourse * kdr = new KyNetworkDeviceResourse(); + QStringList wiredDevList,wirelessDevList; + wiredDevList.clear(); + wirelessDevList.clear(); + + QSettings * m_settings = new QSettings(CONFIG_FILE_PATH, QSettings::IniFormat); + m_settings->beginGroup("CARDEABLE"); + + kdr->getNetworkDeviceList(NetworkManager::Device::Type::Ethernet, wiredDevList); + if (!wiredDevList.isEmpty()) { + for (int i = 0; i < wiredDevList.size(); ++i) { + bool enable = m_settings->value(wiredDevList.at(i), true).toBool(); + map.insert(wiredDevList.at(i), enable); + } + } + + kdr->getNetworkDeviceList(NetworkManager::Device::Type::Wifi, wirelessDevList); + if (!wirelessDevList.isEmpty()) { + for (int i = 0; i < wirelessDevList.size(); ++i) { + bool enable = m_settings->value(wirelessDevList.at(i), true).toBool(); + map.insert(wirelessDevList.at(i), enable); + } + } + + m_settings->endGroup(); + delete m_settings; + m_settings = nullptr; + delete kdr; + kdr = nullptr; + return true; +} + /* * Implementation of adaptor class DbusAdaptor */ @@ -25,7 +80,11 @@ DbusAdaptor::DbusAdaptor(MainWindow *parent) : QDBusAbstractAdaptor(parent) { // constructor - qDBusRegisterMetaType>(); + qDBusRegisterMetaType >(); + qDBusRegisterMetaType(); + qDBusRegisterMetaType(); + qDBusRegisterMetaType >(); + qDBusRegisterMetaType >(); //setAutoRelaySignals(true)后会自动转发mainwindow发出的同名信号,因此不必再额外写一个转发 setAutoRelaySignals(true); } @@ -35,21 +94,135 @@ DbusAdaptor::~DbusAdaptor() // destructor } -void DbusAdaptor::showMainWindow() +//无线列表 +QList DbusAdaptor::getWirelessList(QString devName) { - parent()->showMainwindow(); + } -void DbusAdaptor::showPb(QString type, QString name) +//有线列表 +QList DbusAdaptor::getWiredList(QString devName) { + } -void DbusAdaptor::requestRefreshWifiList() +//有线开关 +void DbusAdaptor::setWiredSwitchEnable(bool enable) { + //todo mainwindow调用backend 对开关 打开/关闭 + if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA_KYLIN_NM)) { + QGSettings *gsetting = new QGSettings(GSETTINGS_SCHEMA_KYLIN_NM); + gsetting->set(KEY_WIRED_SWITCH, enable); + } else { + qDebug()<<"isSchemaInstalled false"; + } } -QVector DbusAdaptor::getWifiList() +//无线开关 +void DbusAdaptor::setWirelessSwitchEnable(bool enable) { - return QVector(); + //todo mainwindow调用backend 对开关 打开/关闭 + if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA_KYLIN_NM)) { + QGSettings *gsetting = new QGSettings(GSETTINGS_SCHEMA_KYLIN_NM); + gsetting->set(KEY_WIRELESS_SWITCH, enable); + delete gsetting; + gsetting = nullptr; + } else { + qDebug()<<"isSchemaInstalled false"; + } +} + +//启用/禁用网卡 +void DbusAdaptor::setDeviceEnable(QString devName, bool enable) +{ + saveDeviceEnableState(devName, enable); +} + +//设置默认网卡 +void DbusAdaptor::setDefaultWiredDevice(QString deviceName) +{ + QSettings * m_settings = new QSettings(CONFIG_FILE_PATH, QSettings::IniFormat); + m_settings->beginGroup("DEFAULTCARD"); + QString key("wired"); + m_settings->setValue(key, deviceName); + m_settings->endGroup(); + m_settings->sync(); + delete m_settings; + m_settings = nullptr; + parent()->setWiredDefaultDevice(deviceName); + return; +} + +QString DbusAdaptor::getDefaultWiredDevice() +{ + QSettings * m_settings = new QSettings(CONFIG_FILE_PATH, QSettings::IniFormat); + m_settings->beginGroup("DEFAULTCARD"); + QString key("wired"); + QString deviceName = m_settings->value(key, "").toString(); + m_settings->endGroup(); + delete m_settings; + m_settings = nullptr; + return deviceName; +} + +void DbusAdaptor::setDefaultWirelessDevice(QString deviceName) +{ + QSettings * m_settings = new QSettings(CONFIG_FILE_PATH, QSettings::IniFormat); + m_settings->beginGroup("DEFAULTCARD"); + QString key("wireless"); + m_settings->setValue(key, deviceName); + m_settings->endGroup(); + m_settings->sync(); + delete m_settings; + m_settings = nullptr; + parent()->setWirelessDefaultDevice(deviceName); + return; +} + +QString DbusAdaptor::getDefaultWirelessDevice() +{ + QSettings * m_settings = new QSettings(CONFIG_FILE_PATH, QSettings::IniFormat); + m_settings->beginGroup("DEFAULTCARD"); + QString key("wireless"); + QString deviceName = m_settings->value(key, "").toString(); + m_settings->endGroup(); + delete m_settings; + m_settings = nullptr; + return deviceName; +} + +//连接 根据网卡类型 参数2 为ssid/uuid +void DbusAdaptor::activateConnect(QString devName, QString ssid) +{ + +} + +//断开连接 根据网卡类型 参数2 为ssid/uuid +void DbusAdaptor::deActivateConnect(QString devName, QString ssid) +{ + +} + +//获取设备列表和启用/禁用状态 +QMap DbusAdaptor::getDeviceListAndEnabled() +{ + QMap map; + map.clear(); + getDeviceEnableState(map); + return map; +} + +//唤起属性页 根据网卡类型 参数2 为ssid/uuid +void DbusAdaptor::showPropertyWidget(QString devName, QString ssid) +{ + //todo + //parent()->showPropertyWidget(devName,ssid); +} + +//唤起新建有线连接界面 +void DbusAdaptor::showCreateWiredConnectWidget(QString devName, QString connectionName) +{ + //todo + //parent()->showCreateWiredConnectWidget(devName,connectionName); } diff --git a/src/backend/dbusadaptor.h b/src/backend/dbusadaptor.h index cab45841..7abc5c7f 100644 --- a/src/backend/dbusadaptor.h +++ b/src/backend/dbusadaptor.h @@ -15,6 +15,8 @@ #include #include #include + +#include "../dbus-interface/kylinnetworkdeviceresource.h" QT_BEGIN_NAMESPACE class QByteArray; //template class QList; @@ -31,28 +33,61 @@ QT_END_NAMESPACE #include "new-mainwindow.h" +class WiredInfo +{ + QString connName; + QString uuid; + + friend QDBusArgument&operator <<(QDBusArgument&argument, const WiredInfo&arg) + { + argument.beginStructure(); + argument << arg.connName; + argument << arg.uuid; + argument.endStructure(); + return argument; + } + friend const QDBusArgument &operator >>(const QDBusArgument &argument, WiredInfo &arg) + { + argument.beginStructure(); + argument >> arg.connName; + argument >> arg.uuid; + argument.endStructure(); + return argument; + } +}; +Q_DECLARE_METATYPE(WiredInfo) + +class WirelessInfo +{ + QString ssid; + uint signalStrength; + bool bSecu; + + friend QDBusArgument&operator <<(QDBusArgument&argument, const WirelessInfo&arg) + { + argument.beginStructure(); + argument << arg.ssid; + argument << arg.signalStrength; + argument << arg.bSecu; + argument.endStructure(); + return argument; + } + friend const QDBusArgument &operator >>(const QDBusArgument&argument, WirelessInfo&arg) + { + argument.beginStructure(); + argument >> arg.ssid; + argument >> arg.signalStrength; + argument >> arg.bSecu; + argument.endStructure(); + return argument; + } +}; +Q_DECLARE_METATYPE(WirelessInfo) + class DbusAdaptor: public QDBusAbstractAdaptor { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "com.kylin.network") - Q_CLASSINFO("D-Bus Introspection", "" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" - "") public: DbusAdaptor(MainWindow *parent); virtual ~DbusAdaptor(); @@ -62,16 +97,36 @@ public: public: // PROPERTIES public Q_SLOTS: // METHODS - void showMainWindow(); - void showPb(QString type, QString name); - void requestRefreshWifiList(); - QVector getWifiList(); + //无线列表 + QList getWirelessList(QString devName); + //有线列表 + QList getWiredList(QString devName); + //有线开关 + Q_NOREPLY void setWiredSwitchEnable(bool enable); + //无线开关 + Q_NOREPLY void setWirelessSwitchEnable(bool enable); + //启用/禁用网卡 + Q_NOREPLY void setDeviceEnable(QString devName, bool enable); + //设置默认网卡 + Q_NOREPLY void setDefaultWiredDevice(QString deviceName); + QString getDefaultWiredDevice(); + Q_NOREPLY void setDefaultWirelessDevice(QString deviceName); + QString getDefaultWirelessDevice(); + //连接 根据网卡类型 参数2 为ssid/uuid + Q_NOREPLY void activateConnect(QString devName, QString ssid); + //断开连接 根据网卡类型 参数2 为ssid/uuid + Q_NOREPLY void deActivateConnect(QString devName, QString ssid); + //获取设备列表和启用/禁用状态 + QMap getDeviceListAndEnabled(); + //唤起属性页 根据网卡类型 参数2 为ssid/uuid + Q_NOREPLY void showPropertyWidget(QString devName, QString ssid); + //唤起新建有线连接界面 + Q_NOREPLY void showCreateWiredConnectWidget(QString devName, QString connectionName); Q_SIGNALS: // SIGNALS - void getWifiListFinished(); - void configurationChanged(); - void wiredConnectionAdded(); - void wiredConnectionRemoved(); - void actWiredConnectionChanged(); + void listUpdate(QString devName); + void deviceUpdate(); + //仅失败,若成功直接发listUpdate + void activateFinish(QString devName, QString ssid); }; #endif diff --git a/src/frontend/new-mainwindow.cpp b/src/frontend/new-mainwindow.cpp index 15e1fbe7..b68f67bd 100644 --- a/src/frontend/new-mainwindow.cpp +++ b/src/frontend/new-mainwindow.cpp @@ -1,7 +1,5 @@ #include "new-mainwindow.h" #include "customstyle.h" -#include "lanpage.h" -#include "wlanpage.h" #include #include #include @@ -42,6 +40,22 @@ void MainWindow::hideMainwindow() this->hide(); } +/** + * @brief MainWindow::setWiredDefaultDevice 设置有线设备默认网卡 + */ +void MainWindow::setWiredDefaultDevice(QString deviceName) +{ + m_lanWidget->updateDefaultDevice(deviceName); +} + +/** + * @brief MainWindow::hideMainwindow 设置无线设备默认网卡 + */ +void MainWindow::setWirelessDefaultDevice(QString deviceName) +{ + m_wlanWidget->updateDefaultDevice(deviceName); +} + /** * @brief MainWindow::firstlyStart 一级启动,执行重要且不耗时的启动操作 */ @@ -94,8 +108,8 @@ void MainWindow::initUI() m_centralWidget = new QTabWidget(this); this->setCentralWidget(m_centralWidget); m_centralWidget->tabBar()->setFixedWidth(this->width()); - LanPage * m_lanWidget = new LanPage(m_centralWidget); - WlanPage * m_wlanWidget = new WlanPage(m_centralWidget); + m_lanWidget = new LanPage(m_centralWidget); + m_wlanWidget = new WlanPage(m_centralWidget); m_centralWidget->addTab(m_lanWidget, QIcon::fromTheme("network-wired-connected-symbolic", QIcon::fromTheme("network-wired-symbolic", QIcon(":/res/l/network-online.svg"))), tr("LAN")); m_centralWidget->addTab(m_wlanWidget, QIcon::fromTheme("network-wireless-signal-excellent-symbolic", QIcon(":/res/x/wifi-list-bg.svg")), tr("WLAN")); } diff --git a/src/frontend/new-mainwindow.h b/src/frontend/new-mainwindow.h index 981a9cea..25f7ca6d 100644 --- a/src/frontend/new-mainwindow.h +++ b/src/frontend/new-mainwindow.h @@ -9,6 +9,8 @@ #include #include #include +#include "lanpage.h" +#include "wlanpage.h" class MainWindow : public QMainWindow { @@ -18,6 +20,8 @@ public: void showMainwindow(); void hideMainwindow(); + void setWiredDefaultDevice(QString deviceName); + void setWirelessDefaultDevice(QString deviceName); signals: public slots: @@ -42,6 +46,9 @@ private: //主窗口的主要构成控件 QTabWidget * m_centralWidget = nullptr; + LanPage * m_lanWidget = nullptr; + WlanPage * m_wlanWidget = nullptr; + //监听主题的Gsettings QGSettings * m_styleGsettings = nullptr; diff --git a/src/frontend/nmdemo.cpp b/src/frontend/nmdemo.cpp index 1ad36969..bc825ce9 100644 --- a/src/frontend/nmdemo.cpp +++ b/src/frontend/nmdemo.cpp @@ -587,8 +587,6 @@ void NmDemo::getWifiList() m_wnr->getWirelessActiveConnection(NetworkManager::ActiveConnection::State::Deactivated, actMap); appendDebugLog("getWirelessActiveConnection Deactivated " +QString::number(actMap.size())); - return; - QMap > map; if (!m_wnr->getAllDeviceWifiNetwork(map)) { diff --git a/src/frontend/tab-pages/lanpage.cpp b/src/frontend/tab-pages/lanpage.cpp index 17da4097..76824791 100644 --- a/src/frontend/tab-pages/lanpage.cpp +++ b/src/frontend/tab-pages/lanpage.cpp @@ -1,10 +1,13 @@ #include "lanpage.h" +#include LanPage::LanPage(QWidget *parent) : TabPage(parent) { + initDevice(); initLanUI(); } + void LanPage::initLanUI() { m_titleLabel->setText(tr("LAN")); @@ -19,3 +22,33 @@ void LanPage::initLanUI() m_inactivatedNetListWidget->setSpacing(NET_LIST_SPACING); m_inactivatedNetListWidget->setFrameShape(QFrame::Shape::NoFrame); } + + +/** + * @brief WlanPage::initDevice 初始化默认网卡 + */ +void LanPage::initDevice() +{ + QSettings * m_settings = new QSettings(CONFIG_FILE_PATH, QSettings::IniFormat); + m_settings->beginGroup("DEFAULTCARD"); + QString key("wired"); + QString deviceName = m_settings->value(key, "").toString(); + if (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()) { + deviceName = list.at(0); + m_settings->setValue(key, deviceName); + } + } + updateDefaultDevice(deviceName); + qDebug() << "[LanPage] initDevice defaultDevice = " << deviceName; + + m_settings->endGroup(); + m_settings->sync(); + delete m_settings; + m_settings = nullptr; + +} diff --git a/src/frontend/tab-pages/lanpage.h b/src/frontend/tab-pages/lanpage.h index 4bb831ef..76db4e38 100644 --- a/src/frontend/tab-pages/lanpage.h +++ b/src/frontend/tab-pages/lanpage.h @@ -2,6 +2,7 @@ #define LANPAGE_H #include "tabpage.h" +#include "kylinnetworkdeviceresource.h" class LanPage : public TabPage { @@ -10,10 +11,11 @@ public: explicit LanPage(QWidget *parent = nullptr); ~LanPage()=default; -signals: - private: + KyNetworkDeviceResourse *m_device = nullptr; + void initLanUI(); + void initDevice();//初始化默认设备 }; #endif // LANPAGE_H diff --git a/src/frontend/tab-pages/tabpage.cpp b/src/frontend/tab-pages/tabpage.cpp index 2808b76f..87682c10 100644 --- a/src/frontend/tab-pages/tabpage.cpp +++ b/src/frontend/tab-pages/tabpage.cpp @@ -75,3 +75,15 @@ void TabPage::initUI() m_mainLayout->addWidget(m_inactivatedNetDivider); m_mainLayout->addWidget(m_settingsFrame); } + +void TabPage::updateDefaultDevice(QString &deviceName) +{ + qDebug() << "updateDefaultDevice" << deviceName; + defaultDevice = deviceName; +} + +QString TabPage::getDefaultDevice() +{ + qDebug() << "getDefaultDevice" << defaultDevice; + return defaultDevice; +} diff --git a/src/frontend/tab-pages/tabpage.h b/src/frontend/tab-pages/tabpage.h index 5c76042a..03644e58 100644 --- a/src/frontend/tab-pages/tabpage.h +++ b/src/frontend/tab-pages/tabpage.h @@ -8,6 +8,8 @@ #include #include #include +#include +#include "kylinnetworkdeviceresource.h" #define MAIN_LAYOUT_MARGINS 0,0,0,0 #define MAIN_LAYOUT_SPACING 0 @@ -21,6 +23,8 @@ #define SETTINGS_LAYOUT_MARGINS 24,16,24,16 #define TRANSPARENT_COLOR QColor(0,0,0,0) +const QString CONFIG_FILE_PATH = QDir::homePath() + "/.config/ukui/kylin-nm.conf"; + class TabPage : public QWidget { Q_OBJECT @@ -28,10 +32,14 @@ public: explicit TabPage(QWidget *parent = nullptr); ~TabPage(); + void updateDefaultDevice(QString &deviceName); + QString getDefaultDevice(); + signals: protected: void initUI(); + virtual void initDevice() = 0;//初始化默认设备 QVBoxLayout * m_mainLayout = nullptr; QFrame * m_titleFrame = nullptr; QHBoxLayout * m_titleLayout = nullptr; @@ -56,6 +64,8 @@ protected: QHBoxLayout * m_settingsLayout = nullptr; QLabel * m_settingsLabel = nullptr; + QString defaultDevice = ""; + }; #endif // TABPAGE_H diff --git a/src/frontend/tab-pages/wlanpage.cpp b/src/frontend/tab-pages/wlanpage.cpp index 12e47b9b..bc59e29d 100644 --- a/src/frontend/tab-pages/wlanpage.cpp +++ b/src/frontend/tab-pages/wlanpage.cpp @@ -4,6 +4,7 @@ #include #include #include +#include WlanPage::WlanPage(QWidget *parent) : TabPage(parent) { @@ -96,6 +97,34 @@ void WlanPage::getWirelessIface() return; } +/** + * @brief WlanPage::initDevice 初始化默认网卡 + */ +void WlanPage::initDevice() +{ + QSettings * m_settings = new QSettings(CONFIG_FILE_PATH, QSettings::IniFormat); + m_settings->beginGroup("DEFAULTCARD"); + QString key("wireless"); + QString deviceName = m_settings->value(key, "").toString(); + if (deviceName.isEmpty()) { + qDebug() << "initDevice but defalut wireless card is null"; + QStringList list; + list.empty(); + m_device->getNetworkDeviceList(NetworkManager::Device::Type::Wifi, list); + if (!list.isEmpty()) { + deviceName = list.at(0); + m_settings->setValue(key, deviceName); + } + } + updateDefaultDevice(deviceName); + qDebug() << "[WlanPage] initDevice defaultDevice = " << deviceName; + m_settings->endGroup(); + m_settings->sync(); + delete m_settings; + m_settings = nullptr; + +} + /** * @brief WlanPage::getActiveWlan 获取所有已激活连接 */ @@ -200,10 +229,9 @@ void WlanPage::onWlanRemoved(QString interface, QString ssid) { if (!m_itemsMap.contains(ssid)) { return; } qDebug() << "A Wlan Removed! interface = " << interface << "; ssid = " << ssid << Q_FUNC_INFO <<__LINE__; - m_inactivatedNetListWidget->removeItemWidget(m_itemsMap.value(ssid)); - m_inactivatedNetListWidget->setFixedHeight(m_inactivatedNetListWidget->height() - - m_inactivatedNetListWidget->itemWidget(m_itemsMap.value(ssid))->height() - - NET_LIST_SPACING); + int height = m_inactivatedNetListWidget->itemWidget(m_itemsMap.value(ssid))->height(); + m_inactivatedNetListWidget->takeItem(m_inactivatedNetListWidget->row(m_itemsMap.value(ssid))); + m_inactivatedNetListWidget->setFixedHeight(m_inactivatedNetListWidget->height() - height - NET_LIST_SPACING); m_inactivatedWlanListAreaCentralWidget->setFixedHeight(m_inactivatedNetListWidget->height() + m_hiddenWlanLabel->height()); m_itemsMap.remove(ssid); } diff --git a/src/frontend/tab-pages/wlanpage.h b/src/frontend/tab-pages/wlanpage.h index e19d21ef..09298fb9 100644 --- a/src/frontend/tab-pages/wlanpage.h +++ b/src/frontend/tab-pages/wlanpage.h @@ -5,6 +5,7 @@ #include "kywirelessnetresource.h" #include "kylinactiveconnectresource.h" #include "kylinnetworkdeviceresource.h" + //#define SCROLLAREA_HEIGHT 150 #define MORE_TEXT_MARGINS 16,0,0,0 @@ -15,6 +16,8 @@ public: explicit WlanPage(QWidget *parent = nullptr); ~WlanPage() = default; + void setDefaultDevice(QString deviceName) {defaultDevice = deviceName;} + signals: protected: @@ -35,6 +38,7 @@ private: QLabel * m_hiddenWlanLabel = nullptr; QString m_activatedWlanSSid; + QString defaultDevice = ""; KyWirelessNetResource *m_resource = nullptr; KyActiveConnectResourse *m_connectResource = nullptr; diff --git a/src/org.ukui.kylin-nm.switch.gschema.xml b/src/org.ukui.kylin-nm.switch.gschema.xml new file mode 100644 index 00000000..544f2cd0 --- /dev/null +++ b/src/org.ukui.kylin-nm.switch.gschema.xml @@ -0,0 +1,14 @@ + + + + true + wireless switch + Wireless switch.true is open,false is close. + + + true + wired switch + Wired switch.true is open,false is close. + + + diff --git a/src/src.pro b/src/src.pro index 09d39d21..a2f2b0a9 100644 --- a/src/src.pro +++ b/src/src.pro @@ -17,7 +17,7 @@ CONFIG += qt warn_on #CONFIG += release CONFIG += link_pkgconfig -PKGCONFIG +=gio-2.0 glib-2.0 gio-unix-2.0 libnm libnma libsecret-1 gtk+-3.0 +PKGCONFIG +=gio-2.0 glib-2.0 gio-unix-2.0 libnm libnma libsecret-1 gtk+-3.0 gsettings-qt INCLUDEPATH += /usr/include/KF5/NetworkManagerQt @@ -27,9 +27,12 @@ target.path = /usr/bin target.source += $$TARGET desktop.path = /etc/xdg/autostart/ desktop.files = kylin-nm.desktop +gschema.files = org.ukui.kylin-nm.switch.gschema.xml +gschema.path = /usr/share/glib-2.0/schemas/ INSTALLS += target \ desktop \ + gschema \ # The following define makes your compiler emit warnings if you use # any feature of Qt which has been marked as deprecated (the exact warnings @@ -63,3 +66,6 @@ unix { MOC_DIR = .moc OBJECTS_DIR = .obj } + +DISTFILES += \ + org.ukui.kylin-nm.switch.gschema.xml