add wifi list sort && dbus interface
This commit is contained in:
parent
0ec4d431ac
commit
5329b7ec69
|
@ -1,5 +1,18 @@
|
|||
#include "kywirelessnetresource.h"
|
||||
|
||||
static bool subWifiListSort(const KyWirelessNetItem info1, const KyWirelessNetItem info2)
|
||||
{
|
||||
if (info1.m_isConfigured == info2.m_isConfigured) {
|
||||
return info1.m_signalStrength >info2.m_signalStrength;
|
||||
}
|
||||
return info1.m_isConfigured;
|
||||
}
|
||||
|
||||
static void wifiListSort(QList<KyWirelessNetItem> &list)
|
||||
{
|
||||
qSort(list.begin(), list.end(), subWifiListSort);
|
||||
}
|
||||
|
||||
KyWirelessNetResource::KyWirelessNetResource(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
|
@ -32,6 +45,11 @@ bool KyWirelessNetResource::getAllDeviceWifiNetwork(QMap<QString,QList<KyWireles
|
|||
if (m_WifiNetworkList.isEmpty()) {
|
||||
return false;
|
||||
} else {
|
||||
QMap<QString, QList<KyWirelessNetItem> >::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, QList<KyW
|
|||
if (!m_WifiNetworkList.contains(devIfaceName)) {
|
||||
return false;
|
||||
} else {
|
||||
wifiListSort(m_WifiNetworkList[devIfaceName]);
|
||||
wirelessNetResource = m_WifiNetworkList[devIfaceName];
|
||||
return true;
|
||||
}
|
||||
|
@ -77,21 +96,17 @@ void KyWirelessNetResource::getWirelessActiveConnection(NetworkManager::ActiveCo
|
|||
map.clear();
|
||||
activeConnectionList.clear();
|
||||
activeConnectionList = m_networkResourceInstance->m_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 +145,12 @@ void KyWirelessNetResource::kyWirelessNetItemListInit()
|
|||
if (devIface.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
KyWirelessNetItem item(net);
|
||||
if (!m_WifiNetworkList.contains(devIface)){
|
||||
QList<KyWirelessNetItem> list;
|
||||
KyWirelessNetItem item(net);
|
||||
list.append(item);
|
||||
m_WifiNetworkList.insert(devIface,list);
|
||||
} else {
|
||||
KyWirelessNetItem item(net);
|
||||
m_WifiNetworkList[devIface].append(item);
|
||||
}
|
||||
}
|
||||
|
@ -147,14 +160,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 +205,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<KyWirelessNetItem> list;
|
||||
|
@ -222,19 +229,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 +251,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<KyWirelessNetItem>::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,26 +289,22 @@ 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<NetworkManager::WirelessSecuritySetting>();
|
||||
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<NetworkManager::Security8021xSetting>();
|
||||
if (setting.isNull())
|
||||
{
|
||||
if (setting.isNull()) {
|
||||
qDebug() << "don't have Security8021x connection";
|
||||
return false;
|
||||
}
|
||||
|
@ -319,8 +313,7 @@ bool KyWirelessNetResource::getEnterPriseInfoTls(QString &uuid, KyEapMethodTlsIn
|
|||
list.append(NetworkManager::Security8021xSetting::EapMethod::EapMethodTls);
|
||||
setting->setEapMethods(list);
|
||||
setting->setIdentity(info.identity);
|
||||
if(!info.domain.isEmpty())
|
||||
{
|
||||
if(!info.domain.isEmpty()) {
|
||||
setting->setDomainSuffixMatch(info.domain);
|
||||
}
|
||||
setting->setCaPath(info.caCertPath);
|
||||
|
@ -336,26 +329,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<NetworkManager::WirelessSecuritySetting>();
|
||||
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<NetworkManager::Security8021xSetting>();
|
||||
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 +359,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<NetworkManager::WirelessSecuritySetting>();
|
||||
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"<<security_sett->keyMgmt();
|
||||
return false;
|
||||
}
|
||||
|
||||
NetworkManager::Security8021xSetting::Ptr setting = conn->settings()->setting(NetworkManager::Setting::Security8021x).dynamicCast<NetworkManager::Security8021xSetting>();
|
||||
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 +385,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 +401,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<NetworkManager::WirelessSetting>();
|
||||
|
@ -469,8 +451,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 +485,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();
|
||||
|
|
|
@ -17,6 +17,62 @@
|
|||
#include <QtCore/QStringList>
|
||||
#include <QtCore/QVariant>
|
||||
|
||||
const QByteArray GSETTINGS_SCHEMA_SCREENSAVER = "org.ukui.kylin-nm.switch";
|
||||
const QString KEY_WIRELESS_SWITCH = "wirelessswitch";
|
||||
const QString KEY_WIRED_SWITCH = "wiredswitch";
|
||||
const QString CONFIG_FILE_PATH = QDir::homePath() + "/.config/ukui/kylin-nm.conf";
|
||||
|
||||
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<QString, bool> &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 +81,11 @@ DbusAdaptor::DbusAdaptor(MainWindow *parent)
|
|||
: QDBusAbstractAdaptor(parent)
|
||||
{
|
||||
// constructor
|
||||
qDBusRegisterMetaType<QVector<QStringList>>();
|
||||
qDBusRegisterMetaType<QMap<QString, bool> >();
|
||||
qDBusRegisterMetaType<WirelessInfo>();
|
||||
qDBusRegisterMetaType<WiredInfo>();
|
||||
qDBusRegisterMetaType<QList<WirelessInfo> >();
|
||||
qDBusRegisterMetaType<QList<WiredInfo> >();
|
||||
//setAutoRelaySignals(true)后会自动转发mainwindow发出的同名信号,因此不必再额外写一个转发
|
||||
setAutoRelaySignals(true);
|
||||
}
|
||||
|
@ -35,21 +95,133 @@ DbusAdaptor::~DbusAdaptor()
|
|||
// destructor
|
||||
}
|
||||
|
||||
void DbusAdaptor::showMainWindow()
|
||||
//无线列表
|
||||
QList<WirelessInfo> DbusAdaptor::getWirelessList(QString devName)
|
||||
{
|
||||
parent()->showMainwindow();
|
||||
|
||||
}
|
||||
|
||||
void DbusAdaptor::showPb(QString type, QString name)
|
||||
//有线列表
|
||||
QList<WiredInfo> DbusAdaptor::getWiredList(QString devName)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void DbusAdaptor::requestRefreshWifiList()
|
||||
//有线开关
|
||||
void DbusAdaptor::setWiredSwitchEnable(bool enable)
|
||||
{
|
||||
//todo mainwindow调用backend 对开关 打开/关闭
|
||||
if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA_SCREENSAVER)) {
|
||||
QGSettings *gsetting = new QGSettings(GSETTINGS_SCHEMA_SCREENSAVER);
|
||||
gsetting->set(KEY_WIRED_SWITCH, enable);
|
||||
} else {
|
||||
qDebug()<<"isSchemaInstalled false";
|
||||
}
|
||||
}
|
||||
|
||||
QVector<QStringList> DbusAdaptor::getWifiList()
|
||||
//无线开关
|
||||
void DbusAdaptor::setWirelessSwitchEnable(bool enable)
|
||||
{
|
||||
return QVector<QStringList>();
|
||||
//todo mainwindow调用backend 对开关 打开/关闭
|
||||
if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA_SCREENSAVER)) {
|
||||
QGSettings *gsetting = new QGSettings(GSETTINGS_SCHEMA_SCREENSAVER);
|
||||
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;
|
||||
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;
|
||||
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<QString, bool> DbusAdaptor::getDeviceListAndEnabled()
|
||||
{
|
||||
QMap<QString, bool> 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
#include <QtCore/QObject>
|
||||
#include <QtDBus/QtDBus>
|
||||
#include <QtDBus/QDBusMetaType>
|
||||
|
||||
#include "../dbus-interface/kylinnetworkdeviceresource.h"
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QByteArray;
|
||||
//template<class T> 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", ""
|
||||
" <interface name=\"com.kylin.network\">\n"
|
||||
" <method name=\"showMainWindow\"/>\n"
|
||||
" <method name=\"requestRefreshWifiList\"/>\n"
|
||||
" <method name=\"getWifiList\">\n"
|
||||
" <arg type=\"av\" direction=\"out\"/>\n"
|
||||
" </method>\n"
|
||||
" <method name=\"showPb\">\n"
|
||||
" <arg direction=\"in\" name=\"type\" type=\"s\"/>\n"
|
||||
" <arg direction=\"in\" name=\"name\" type=\"s\"/>\n"
|
||||
" </method>\n"
|
||||
" <signal name=\"getWifiListFinished\"/>\n"
|
||||
" <signal name=\"configurationChanged\"/>\n"
|
||||
" <signal name=\"wiredConnectionAdded\"/>\n"
|
||||
" <signal name=\"wiredConnectionRemoved\"/>\n"
|
||||
" <signal name=\"actWiredConnectionChanged\"/>\n"
|
||||
" </interface>\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<QStringList> getWifiList();
|
||||
//无线列表
|
||||
QList<WirelessInfo> getWirelessList(QString devName);
|
||||
//有线列表
|
||||
QList<WiredInfo> 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<QString, bool> 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
|
||||
|
|
|
@ -587,8 +587,6 @@ void NmDemo::getWifiList()
|
|||
m_wnr->getWirelessActiveConnection(NetworkManager::ActiveConnection::State::Deactivated, actMap);
|
||||
appendDebugLog("getWirelessActiveConnection Deactivated " +QString::number(actMap.size()));
|
||||
|
||||
return;
|
||||
|
||||
QMap<QString, QList<KyWirelessNetItem> > map;
|
||||
if (!m_wnr->getAllDeviceWifiNetwork(map))
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue