From 58f5d4d27a2fd9b0b9a8dc1de7390c1f806f6588 Mon Sep 17 00:00:00 2001 From: jzxc95 <907297917@qq.com> Date: Thu, 28 Sep 2023 14:05:23 +0800 Subject: [PATCH] =?UTF-8?q?fix(display):=E5=A4=9Adisplay=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E9=80=82=E9=85=8D(#194718)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/mobilehotspot/mobilehotspot.cpp | 24 +- plugins/mobilehotspot/mobilehotspotwidget.cpp | 68 +-- plugins/netconnect/netconnect.cpp | 91 ++-- plugins/netconnect/netconnect.h | 2 + plugins/wlanconnect/wlanconnect.cpp | 96 ++-- plugins/wlanconnect/wlanconnect.h | 4 +- src/backend/backend.pri | 8 +- src/backend/dbus.cpp | 419 ++++++++++++++++++ src/backend/{dbusadaptor.h => dbus.h} | 41 +- src/backend/dbus.xml | 186 ++++++++ src/backend/dbus_adaptor.cpp | 191 ++++++++ src/backend/dbus_adaptor.h | 266 +++++++++++ src/backend/dbus_interface.cpp | 26 ++ src/backend/dbus_interface.h | 224 ++++++++++ src/backend/dbusadaptor.cpp | 279 ------------ src/frontend/mainwindow.cpp | 66 ++- src/frontend/mainwindow.h | 16 +- src/frontend/tab-pages/lanpage.cpp | 37 +- src/frontend/tab-pages/lanpage.h | 2 +- src/frontend/tab-pages/wlanpage.cpp | 97 ++-- src/frontend/tab-pages/wlanpage.h | 2 +- src/main.cpp | 43 +- 22 files changed, 1670 insertions(+), 518 deletions(-) create mode 100644 src/backend/dbus.cpp rename src/backend/{dbusadaptor.h => dbus.h} (78%) create mode 100644 src/backend/dbus.xml create mode 100644 src/backend/dbus_adaptor.cpp create mode 100644 src/backend/dbus_adaptor.h create mode 100644 src/backend/dbus_interface.cpp create mode 100644 src/backend/dbus_interface.h delete mode 100644 src/backend/dbusadaptor.cpp diff --git a/plugins/mobilehotspot/mobilehotspot.cpp b/plugins/mobilehotspot/mobilehotspot.cpp index 46bd4409..cc127cfc 100644 --- a/plugins/mobilehotspot/mobilehotspot.cpp +++ b/plugins/mobilehotspot/mobilehotspot.cpp @@ -21,7 +21,7 @@ #include - +#include MobileHotspot::MobileHotspot() : mFirstLoad(true) { @@ -113,23 +113,31 @@ bool MobileHotspot::isExitWirelessDevice() return false; } - QDBusMessage result = interface->call(QStringLiteral("getDeviceListAndEnabled"),1); - if(result.type() == QDBusMessage::ErrorMessage) { - qWarning() << "getWirelessDeviceList error:" << result.errorMessage(); + QDBusReply reply = interface->call(QStringLiteral("getDeviceListAndEnabled"),1); + if(!reply.isValid()) { + qWarning() << "getWirelessDeviceList error:" << reply.error().message(); return false; } - auto dbusArg = result.arguments().at(0).value(); QMap deviceListMap; - dbusArg >> deviceListMap; + QVariantMap::const_iterator itemIter = reply.value().cbegin(); + while (itemIter != reply.value().cend()) { + deviceListMap.insert(itemIter.key(), itemIter.value().toBool()); + itemIter ++; + } - QDBusReply > capReply = interface->call("getWirelessDeviceCap"); + QDBusReply capReply = interface->call("getWirelessDeviceCap"); if (!capReply.isValid()) { qDebug()<<"execute dbus method 'getWirelessDeviceCap' is invalid in func initInterfaceInfo()" < devCapMap = capReply.value(); + QMap devCapMap; + QVariantMap::const_iterator item = reply.value().cbegin(); + while (item != reply.value().cend()) { + devCapMap.insert(item.key(), item.value().toInt()); + item ++; + } if (deviceListMap.isEmpty()) { qDebug() << "no wireless device"; diff --git a/plugins/mobilehotspot/mobilehotspotwidget.cpp b/plugins/mobilehotspot/mobilehotspotwidget.cpp index 8682d7ab..39fd251d 100644 --- a/plugins/mobilehotspot/mobilehotspotwidget.cpp +++ b/plugins/mobilehotspot/mobilehotspotwidget.cpp @@ -314,31 +314,26 @@ void MobileHotspotWidget::onInterfaceChanged() { m_interfaceName = m_interfaceComboBox->currentText(); if(m_interface->isValid()) { - QDBusMessage result = m_interface->call(QStringLiteral("getWirelessList")); - if(result.type() == QDBusMessage::ErrorMessage) + QDBusReply reply = m_interface->call(QStringLiteral("getWirelessList"), m_interfaceName); + if(!reply.isValid()) { - qWarning() << "getWirelessList error:" << result.errorMessage(); + qWarning() << "getWirelessList error:" << reply.error().message(); return; } bool flag = false; - auto dbusArg = result.arguments().at(0).value(); - QMap> variantList; - dbusArg >> variantList; - if (variantList.size() != 0) { - QMap>::iterator iter; - for (iter = variantList.begin(); iter != variantList.end(); iter++) { - if (m_interfaceName == iter.key()) { - QVector wlanListInfo = iter.value(); - if (!wlanListInfo.isEmpty() && wlanListInfo.at(0).size() > 1) { - flag = true; - } - break; - } - } + + QList variantList; + for (int j = 0; j < reply.value().size(); ++j) { + variantList << reply.value().at(j).toStringList(); } + + if (!variantList.isEmpty() && variantList.at(0).size() > 1) { + flag = true; + } + if (flag) { m_interfaceWarnLabel->setText(tr("use ") + m_interfaceName + - tr(" share network, will interrupt local wireless connection")); + tr(" share network, will interrupt local wireless connection")); m_interfaceFrame->setFixedHeight(PASSWORD_FRAME_FIX_HIGHT); m_warnWidget->show(); } else { @@ -390,22 +385,32 @@ void MobileHotspotWidget::initInterfaceInfo() m_interfaceComboBox->hidePopup(); } m_interfaceComboBox->clear(); - QDBusReply > reply = m_interface->call("getDeviceListAndEnabled",WIRELESS); - - if (!reply.isValid()) { - qDebug() << LOG_HEAD <<"execute dbus method 'getDeviceListAndEnabled' is invalid in func initInterfaceInfo()"; - setWidgetHidden(true); + QDBusReply reply = m_interface->call(QStringLiteral("getDeviceListAndEnabled"),WIRELESS); + if(!reply.isValid()) { + qWarning() << "[WlanConnect]getWirelessDeviceList error:" << reply.error().message(); return; } - QMap devMap = reply.value(); - QDBusReply > capReply = m_interface->call("getWirelessDeviceCap"); + QMap devMap; + QVariantMap::const_iterator item = reply.value().cbegin(); + while (item != reply.value().cend()) { + devMap.insert(item.key(), item.value().toBool()); + item ++; + } + + + QDBusReply capReply = m_interface->call("getWirelessDeviceCap"); if (!capReply.isValid()) { qDebug() << LOG_HEAD <<"execute dbus method 'getWirelessDeviceCap' is invalid in func initInterfaceInfo()" < devCapMap = capReply.value(); + QMap devCapMap; + QVariantMap::const_iterator itemIter = capReply.value().cbegin(); + while (itemIter != capReply.value().cend()) { + devCapMap.insert(itemIter.key(), itemIter.value().toInt()); + itemIter ++; + } if (devMap.isEmpty()) { qDebug() << LOG_HEAD << "no wireless device"; @@ -824,14 +829,21 @@ void MobileHotspotWidget::updateBandCombox() { QString tmp = m_freqBandComboBox->currentText(); m_freqBandComboBox->clear(); - QDBusReply > capReply = m_interface->call("getWirelessDeviceCap"); + QDBusReply capReply = m_interface->call("getWirelessDeviceCap"); if (!capReply.isValid()) { qDebug()<<"execute dbus method 'getWirelessDeviceCap' is invalid in func initInterfaceInfo()" << capReply.error().message(); setWidgetHidden(true); return; } m_isUserSelect = false; - QMap devCapMap = capReply.value(); + + QMap devCapMap; + QVariantMap::const_iterator itemIter = capReply.value().cbegin(); + while (itemIter != capReply.value().cend()) { + devCapMap.insert(itemIter.key(), itemIter.value().toInt()); + itemIter ++; + } + if (devCapMap[m_interfaceName] & 0x02) { m_freqBandComboBox->addItem("2.4GHz"); } diff --git a/plugins/netconnect/netconnect.cpp b/plugins/netconnect/netconnect.cpp index fa3c268b..6dae527c 100644 --- a/plugins/netconnect/netconnect.cpp +++ b/plugins/netconnect/netconnect.cpp @@ -74,6 +74,9 @@ void NetConnect::showDesktopNotify(const QString &message) NetConnect::NetConnect() : mFirstLoad(true) { + qDBusRegisterMetaType(); + qDBusRegisterMetaType>(); + QTranslator* translator = new QTranslator(this); translator->load("/usr/share/kylin-nm/netconnect/" + QLocale::system().name()); QApplication::installTranslator(translator); @@ -107,7 +110,6 @@ QWidget *NetConnect::pluginUi() { pluginWidget = new QWidget; pluginWidget->setAttribute(Qt::WA_DeleteOnClose); ui->setupUi(pluginWidget); - qDBusRegisterMetaType>(); m_interface = new QDBusInterface("com.kylin.network", "/com/kylin/network", "com.kylin.network", @@ -249,16 +251,21 @@ void NetConnect::getDeviceStatusMap(QMap &map) if (m_interface == nullptr || !m_interface->isValid()) { return; } + map.clear(); qDebug() << "[NetConnect]call getDeviceListAndEnabled" << __LINE__; - QDBusMessage result = m_interface->call(QStringLiteral("getDeviceListAndEnabled"),0); + QDBusReply reply = m_interface->call(QStringLiteral("getDeviceListAndEnabled"),0); qDebug() << "[NetConnect]call getDeviceListAndEnabled Respond" << __LINE__; - if(result.type() == QDBusMessage::ErrorMessage) + if(!reply.isValid()) { - qWarning() << "[NetConnect]getWiredDeviceList error:" << result.errorMessage(); + qWarning() << "[NetConnect]getWiredDeviceList error:" << reply.error().message(); return; } - auto dbusArg = result.arguments().at(0).value(); - dbusArg >> map; + + QVariantMap::const_iterator item = reply.value().cbegin(); + while (item != reply.value().cend()) { + map.insert(item.key(), item.value().toBool()); + item ++; + } } //lanUpdate @@ -390,26 +397,17 @@ void NetConnect::initNetListFromDevice(QString deviceName) if (m_interface == nullptr || !m_interface->isValid()) { return; } - qDebug() << "[NetConnect]call getWiredList" << __LINE__; - QDBusMessage result = m_interface->call(QStringLiteral("getWiredList")); - qDebug() << "[NetConnect]call getWiredList respond" << __LINE__; - if(result.type() == QDBusMessage::ErrorMessage) - { - qWarning() << "getWiredList error:" << result.errorMessage(); - return; - } - auto dbusArg = result.arguments().at(0).value(); - QMap> variantList; - dbusArg >> variantList; + + QMap> variantList = getWiredList(); if (variantList.size() == 0) { qDebug() << "[NetConnect]initNetListFromDevice " << deviceName << " list empty"; return; } - QMap>::iterator iter; + QMap>::iterator iter; for (iter = variantList.begin(); iter != variantList.end(); iter++) { if (deviceName == iter.key()) { - QVector wlanListInfo = iter.value(); + QList wlanListInfo = iter.value(); //处理列表 已连接 qDebug() << "[NetConnect]initNetListFromDevice " << deviceName << " acitved lan " << wlanListInfo.at(0); addLanItem(deviceFrameMap[deviceName], deviceName, wlanListInfo.at(0), true); @@ -486,22 +484,25 @@ void NetConnect::addDeviceFrame(QString devName) qDebug() << "[NetConnect]addDeviceFrame " << devName; qDebug() << "[NetConnect]call getDeviceListAndEnabled" << __LINE__; - QDBusMessage result = m_interface->call(QStringLiteral("getDeviceListAndEnabled"),0); + QDBusReply reply = m_interface->call(QStringLiteral("getDeviceListAndEnabled"),0); qDebug() << "[NetConnect]call getDeviceListAndEnabled Respond" << __LINE__; - if(result.type() == QDBusMessage::ErrorMessage) - { - qWarning() << "[NetConnect]getWiredDeviceList error:" << result.errorMessage(); + if(!reply.isValid()) { + qWarning() << "[NetConnect]getWiredDeviceList error:" << reply.error().message(); return; } - auto dbusArg = result.arguments().at(0).value(); QMap map; - dbusArg >> map; + QVariantMap::const_iterator item = reply.value().cbegin(); + while (item != reply.value().cend()) { + map.insert(item.key(), item.value().toBool()); + item ++; + } bool enable = true; if (map.contains(devName)) { enable = map[devName]; } + ItemFrame *itemFrame = new ItemFrame(devName, pluginWidget); ui->availableLayout->addWidget(itemFrame); itemFrame->deviceFrame->deviceLabel->setText(tr("card")+/*QString("%1").arg(count)+*/":"+devName); @@ -887,17 +888,9 @@ int NetConnect::getInsertPos(QString connName, QString deviceName) if(m_interface == nullptr || !m_interface->isValid()) { index = 0; } else { - qDebug() << "[NetConnect]call getWiredList" << __LINE__; - QDBusMessage result = m_interface->call(QStringLiteral("getWiredList")); - qDebug() << "[NetConnect]call getWiredList respond" << __LINE__; - if(result.type() == QDBusMessage::ErrorMessage) - { - qWarning() << "getWiredList error:" << result.errorMessage(); - return 0; - } - auto dbusArg = result.arguments().at(0).value(); - QMap> variantList; - dbusArg >> variantList; + + QMap> variantList = getWiredList(); + if (!variantList.contains(deviceName)) { qDebug() << "[NetConnect] getInsertPos but " << deviceName << "not exist"; return 0; @@ -915,3 +908,29 @@ int NetConnect::getInsertPos(QString connName, QString deviceName) } return index; } + +QMap> NetConnect::getWiredList() +{ + QMap> map; + + QMap statusMap; + getDeviceStatusMap(statusMap); + + for (int i = 0; i < statusMap.keys().size(); ++i) { + qDebug() << "[NetConnect]call getWiredList" << __LINE__; + QDBusReply reply = m_interface->call(QStringLiteral("getWiredList"), statusMap.keys().at(i)); + qDebug() << "[NetConnect]call getWiredList respond" << __LINE__; + if(!reply.isValid()) + { + qWarning() << "getWiredList error:" << reply.error().message(); + break; + } + + QList list; + for (int j = 0; j < reply.value().size(); ++j) { + list << reply.value().at(j).toStringList(); + } + map.insert(statusMap.keys().at(i), list); + } + return map; +} diff --git a/plugins/netconnect/netconnect.h b/plugins/netconnect/netconnect.h index 7fbc9814..1e94d05e 100644 --- a/plugins/netconnect/netconnect.h +++ b/plugins/netconnect/netconnect.h @@ -144,6 +144,8 @@ private: QMap deviceStatusMap; QMap deviceFrameMap; + QMap> getWiredList(); + private slots: void updateLanInfo(QString deviceName, QStringList lanInfo); diff --git a/plugins/wlanconnect/wlanconnect.cpp b/plugins/wlanconnect/wlanconnect.cpp index e1b01309..facdec20 100644 --- a/plugins/wlanconnect/wlanconnect.cpp +++ b/plugins/wlanconnect/wlanconnect.cpp @@ -167,6 +167,7 @@ QWidget *WlanConnect::pluginUi() { pluginWidget->setAttribute(Qt::WA_DeleteOnClose); ui->setupUi(pluginWidget); qDBusRegisterMetaType>(); + qDBusRegisterMetaType(); m_interface = new QDBusInterface("com.kylin.network", "/com/kylin/network", "com.kylin.network", QDBusConnection::sessionBus()); @@ -317,28 +318,18 @@ void WlanConnect::updateList() } qDebug() << "update list"; if(m_interface != nullptr && m_interface->isValid()) { - qDebug() << "[WlanConnect]call getWirelessList" << __LINE__; - QDBusMessage result = m_interface->call(QStringLiteral("getWirelessList")); - qDebug() << "[WlanConnect]call getWirelessList respond" << __LINE__; - if(result.type() == QDBusMessage::ErrorMessage) - { - qWarning() << "getWirelessList error:" << result.errorMessage(); - return; - } - auto dbusArg = result.arguments().at(0).value(); - QMap> variantList; - dbusArg >> variantList; + QMap> variantList = getWirelessList(); if (variantList.size() == 0) { qDebug() << "[WlanConnect]updateList " << " list empty"; return; } - QMap>::iterator iter; + QMap>::iterator iter; for (iter = variantList.begin(); iter != variantList.end(); iter++) { if (deviceFrameMap.contains(iter.key())) { - QVector wifiList = iter.value(); + QList wifiList = iter.value(); resortWifiList(deviceFrameMap[iter.key()], wifiList); deviceFrameMap[iter.key()]->filletStyleChange(); } @@ -346,7 +337,7 @@ void WlanConnect::updateList() } } -void WlanConnect::resortWifiList(ItemFrame *frame, QVector list) +void WlanConnect::resortWifiList(ItemFrame *frame, QList list) { if(nullptr == frame || frame->lanItemLayout->count() <= 0 || list.isEmpty()) { return; @@ -702,16 +693,20 @@ void WlanConnect::getDeviceList(QStringList &list) return; } qDebug() << "[WlanConnect]call getDeviceListAndEnabled" << __LINE__; - QDBusMessage result = m_interface->call(QStringLiteral("getDeviceListAndEnabled"),1); + QDBusReply reply = m_interface->call(QStringLiteral("getDeviceListAndEnabled"),1); qDebug() << "[WlanConnect]call getDeviceListAndEnabled respond" << __LINE__; - if(result.type() == QDBusMessage::ErrorMessage) + if(!reply.isValid()) { - qWarning() << "[WlanConnect]getWirelessDeviceList error:" << result.errorMessage(); + qWarning() << "[WlanConnect]getWirelessDeviceList error:" << reply.error().message(); return; } - auto dbusArg = result.arguments().at(0).value(); + QMap map; - dbusArg >> map; + QVariantMap::const_iterator item = reply.value().cbegin(); + while (item != reply.value().cend()) { + map.insert(item.key(), item.value().toBool()); + item ++; + } //筛选已托管(managed)网卡 QMap::iterator iters; @@ -770,26 +765,20 @@ void WlanConnect::initNetListFromDevice(QString deviceName) if (m_interface == nullptr || !m_interface->isValid()) { return; } - qDebug() << "[WlanConnect]call getWirelessList" << __LINE__; - QDBusMessage result = m_interface->call(QStringLiteral("getWirelessList")); - qDebug() << "[WlanConnect]call getWirelessList respond" << __LINE__; - if(result.type() == QDBusMessage::ErrorMessage) - { - qWarning() << "getWirelessList error:" << result.errorMessage(); - return; - } - auto dbusArg = result.arguments().at(0).value(); - QMap> variantList; - dbusArg >> variantList; + + QMap> variantList = getWirelessList(); if (variantList.size() == 0) { qDebug() << "[WlanConnect]initNetListFromDevice " << deviceName << " list empty"; return; } - QMap>::iterator iter; + QMap>::iterator iter; for (iter = variantList.begin(); iter != variantList.end(); iter++) { if (deviceName == iter.key()) { - QVector wlanListInfo = iter.value(); + QList wlanListInfo = iter.value(); + if (wlanListInfo.size() <= 0) { + break; + } //处理列表 已连接 qDebug() << "[WlanConnect]initNetListFromDevice " << deviceName << " acitved wifi " << wlanListInfo.at(0); addActiveItem(deviceFrameMap[deviceName], deviceName, wlanListInfo.at(0)); @@ -903,21 +892,13 @@ int WlanConnect::sortWlanNet(QString deviceName, QString name, QString signal) if (m_interface == nullptr || !m_interface->isValid()) { return 0; } - qDebug() << "[WlanConnect]call getWirelessList" << __LINE__; - QDBusMessage result = m_interface->call(QStringLiteral("getWirelessList")); - qDebug() << "[WlanConnect]call getWirelessList respond" << __LINE__; - if(result.type() == QDBusMessage::ErrorMessage) - { - qWarning() << "getWirelessList error:" << result.errorMessage(); - return 0; - } - auto dbusArg = result.arguments().at(0).value(); - QMap> variantList; - dbusArg >> variantList; - QMap>::iterator iter; + + QMap> variantList = getWirelessList(); + + QMap>::iterator iter; for (iter = variantList.begin(); iter != variantList.end(); iter++) { if (deviceName == iter.key()) { - QVector wlanListInfo = iter.value(); + QList wlanListInfo = iter.value(); for (int i = 0; i < wlanListInfo.size(); i++) { if (name == wlanListInfo.at(i).at(0)) { return i; @@ -1127,3 +1108,28 @@ void WlanConnect::itemActiveConnectionStatusChanged(WlanItem *item, int status) } } +QMap> WlanConnect::getWirelessList() +{ + QMap> map; + QStringList list; + getDeviceList(list); + + for (int i = 0; i < list.size(); ++i) { + qDebug() << "[NetConnect]call getWirelessList" << __LINE__; + QDBusReply reply = m_interface->call(QStringLiteral("getWirelessList"), list.at(i)); + qDebug() << "[NetConnect]call getWirelessList respond" << __LINE__; + if(!reply.isValid()) + { + qWarning() << "getWirelessList error:" << reply.error().message(); + break; + } + + QList llist; + for (int j = 0; j < reply.value().size(); ++j) { + llist << reply.value().at(j).toStringList(); + } + map.insert(list.at(i), llist); + } + return map; +} + diff --git a/plugins/wlanconnect/wlanconnect.h b/plugins/wlanconnect/wlanconnect.h index 734dc0d7..a822a658 100644 --- a/plugins/wlanconnect/wlanconnect.h +++ b/plugins/wlanconnect/wlanconnect.h @@ -91,7 +91,7 @@ private: int sortWlanNet(QString deviceName, QString name, QString signal); void updateIcon(WlanItem *item, QString signalStrength, QString security, QString isApConnection, int category); - void resortWifiList(ItemFrame *frame, QVector list); + void resortWifiList(ItemFrame *frame, QList list); //单wifi图标 @@ -174,6 +174,8 @@ private: QTimer * m_scanTimer = nullptr; // QTimer * m_updateTimer = nullptr; + + QMap> getWirelessList(); private: KSwitchButton *m_wifiSwitch; bool m_firstLoad; diff --git a/src/backend/backend.pri b/src/backend/backend.pri index 0d383624..103a0db0 100644 --- a/src/backend/backend.pri +++ b/src/backend/backend.pri @@ -3,13 +3,17 @@ include(hotspot/hotspot.pri) include(dbus-interface/dbus-interface.pri) HEADERS += \ - $$PWD/dbusadaptor.h \ + $$PWD/dbus.h \ + $$PWD/dbus_adaptor.h \ + $$PWD/dbus_interface.h \ $$PWD/sysdbusregister.h \ $$PWD/utils.h \ $$PWD/wifi-auth-thread.h SOURCES += \ - $$PWD/dbusadaptor.cpp \ + $$PWD/dbus.cpp \ + $$PWD/dbus_adaptor.cpp \ + $$PWD/dbus_interface.cpp \ $$PWD/sysdbusregister.cpp \ $$PWD/utils.cpp \ $$PWD/wifi-auth-thread.cpp diff --git a/src/backend/dbus.cpp b/src/backend/dbus.cpp new file mode 100644 index 00000000..5f27b092 --- /dev/null +++ b/src/backend/dbus.cpp @@ -0,0 +1,419 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: qdbusxml2cpp com.kylin.weather.xml -a dbusadaptor -c DbusAdaptor -l MainWindow + * + * qdbusxml2cpp is Copyright (C) 2015 The Qt Company Ltd. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#include "dbus.h" +#include +#include +#include +#include +#include +#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"; + +/* + * Implementation of adaptor class DbusAdaptor + */ + +DbusAdaptor::DbusAdaptor(QString display, MainWindow *m, QObject *parent) + : QObject(parent), + m_display(display), + m_mainWindow(m) +{ + // constructor + qDBusRegisterMetaType >(); + qDBusRegisterMetaType >(); + qDBusRegisterMetaType >(); + qDBusRegisterMetaType >>(); + + bool isServiceRegistered = QDBusConnection::sessionBus().interface()->isServiceRegistered(QStringLiteral("com.kylin.network")); + if(!isServiceRegistered) { + registerService(); + } + + m_watcher = new QDBusServiceWatcher(QStringLiteral("com.kylin.network"),QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForOwnerChange, this); + connect(m_watcher, &QDBusServiceWatcher::serviceOwnerChanged, this, &DbusAdaptor::onServiceOwnerChanged); + + connectToMainwindow(); +} + +void DbusAdaptor::onServiceOwnerChanged(const QString &service, const QString &oldOwner, const QString &newOwner) +{ + if (newOwner.isEmpty()) { + bool success = registerService(); + if (success) { + m_watcher->deleteLater(); + } + qDebug() << "try to register service:" << success; + return; + } + + uint newOwnerPid = QDBusConnection::sessionBus().interface()->servicePid(newOwner); + qDebug() << "newOwnerPid:" << newOwnerPid << ", myPid:" << QCoreApplication::applicationPid() << ", display:" << m_display; +} + +bool DbusAdaptor::registerService() +{ + new NetworkAdaptor(this); + + QDBusConnection conn = QDBusConnection::sessionBus(); + auto reply = conn.interface()->registerService(QStringLiteral("com.kylin.network"), + QDBusConnectionInterface::ReplaceExistingService, + QDBusConnectionInterface::DontAllowReplacement); + if (reply.value() == QDBusConnectionInterface::ServiceNotRegistered) { + return false; + } + + bool res = QDBusConnection::sessionBus().registerObject("/com/kylin/network", this); + if (!res) { + QDBusConnection::sessionBus().interface()->unregisterService(QStringLiteral("com.kylin.network")); + } + return res; +} + + +//无线列表 +QVariantList DbusAdaptor::getWirelessList(QString devName) +{ + QList list; + m_mainWindow->getWirelessList(devName, list); + QVariantList vList; + for (int i = 0; i < list.size(); ++i) { + vList.append(QVariant::fromValue(list.at(i))); + } + return vList; +} + +bool DbusAdaptor::getWirelessSwitchBtnState() +{ + return m_mainWindow->getWirelessSwitchBtnState(); +} + +//有线列表 +QVariantList DbusAdaptor::getWiredList(QString devName) +{ + QList list; + m_mainWindow->getWiredList(devName, list); + QVariantList vList; + for (int i = 0; i < list.size(); ++i) { + vList.append(QVariant::fromValue(list.at(i))); + } + return vList; + +} + +//有线开关 +void DbusAdaptor::setWiredSwitchEnable(bool enable) +{ + //todo mainwindow调用backend 对开关 打开/关闭 + if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA_KYLIN_NM)) { + QGSettings *gsetting = new QGSettings(GSETTINGS_SCHEMA_KYLIN_NM); + if (gsetting->get(KEY_WIRED_SWITCH).toBool() != enable) { + gsetting->set(KEY_WIRED_SWITCH, enable); + } + delete gsetting; + gsetting = nullptr; + } else { + qDebug()<<"isSchemaInstalled false"; + } +} + +//无线开关 +void DbusAdaptor::setWirelessSwitchEnable(bool enable) +{ + //todo mainwindow调用backend 对开关 打开/关闭 +// if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA_KYLIN_NM)) { +// QGSettings *gsetting = new QGSettings(GSETTINGS_SCHEMA_KYLIN_NM); +// if (gsetting->get(KEY_WIRELESS_SWITCH).toBool() != enable) { +// gsetting->set(KEY_WIRELESS_SWITCH, enable); +// } +// delete gsetting; +// gsetting = nullptr; +// } else { +// qDebug()<<"isSchemaInstalled false"; +// } + m_mainWindow->setWirelessSwitchEnable(enable); +} + +//启用/禁用网卡 +void DbusAdaptor::setDeviceEnable(QString devName, bool enable) +{ + m_mainWindow->setWiredDeviceEnable(devName, enable); +} + +//设置默认网卡 +//void DbusAdaptor::setDefaultWiredDevice(QString deviceName) +//{ +// if (!checkDeviceExist(WIRED, deviceName)) { +// return; +// } +// setDefaultDevice(WIRED, deviceName); +// 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) +//{ +// if (!checkDeviceExist(WIRED, deviceName)) { +// return; +// } +// setDefaultDevice(WIRELESS, deviceName); +// 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; +//} + +//连接 根据网卡类型 参数1 0:lan 1:wlan 参数3 为ssid/uuid +void DbusAdaptor::activateConnect(int type, QString devName, QString ssid) +{ + if (type == WIRED) { + m_mainWindow->activateWired(devName,ssid); + } else if (type == WIRELESS) { + m_mainWindow->activateWireless(devName,ssid); + } else { + qDebug() << "[DbusAdaptor] activateConnect type is invalid"; + } +} + +//断开连接 根据网卡类型 参数1 0:lan 1:wlan 参数3 为ssid/uuid +void DbusAdaptor::deActivateConnect(int type, QString devName, QString ssid) +{ + if (type == WIRED) { + qDebug() << "deactivateWired"; + m_mainWindow->deactivateWired(devName,ssid); + } else if (type == WIRELESS) { + m_mainWindow->deactivateWireless(devName,ssid); + } else { + qDebug() << "[DbusAdaptor] deactivateConnect type is invalid"; + } +} + +//获取设备列表和启用/禁用状态 +QVariantMap DbusAdaptor::getDeviceListAndEnabled(int devType) +{ + QMap map; + map.clear(); + getDeviceEnableState(devType, map); + QVariantMap vMap; + QMap::const_iterator item = map.cbegin(); + while (item != map.cend()) { + vMap.insert(item.key(), QVariant::fromValue(item.value())); + item ++; + } + return vMap; +} + +//获取无线设备能力 +QVariantMap DbusAdaptor::getWirelessDeviceCap() +{ + QMap map; + m_mainWindow->getWirelessDeviceCap(map); + QVariantMap vMap; + QMap::const_iterator item = map.cbegin(); + while (item != map.cend()) { + vMap.insert(item.key(), QVariant::fromValue(item.value())); + item ++; + } + return vMap; +} + +//唤起属性页 根据网卡类型 参数2 为ssid/uuid +void DbusAdaptor::showPropertyWidget(QString devName, QString ssid) +{ + QString display = checkDisplay(); + if (m_display == display) { + m_mainWindow->showPropertyWidget(devName,ssid); + } else { + Q_EMIT showPropertyWidgetSignal(display, devName, ssid); + } +} + +//唤起新建有线连接界面 +void DbusAdaptor::showCreateWiredConnectWidget(QString devName) +{ + QString display = checkDisplay(); + if (m_display == display) { + m_mainWindow->showCreateWiredConnectWidget(devName); + } else { + Q_EMIT showCreateWiredConnectWidgetSignal(display, devName); + } +} + +//唤起加入其他无线网络界面 +void DbusAdaptor::showAddOtherWlanWidget(QString devName) +{ + QString display = checkDisplay(); + if (m_display == display) { + qDebug() << "showAddOtherWlanWidget"; + m_mainWindow->showAddOtherWlanWidget(devName); + } else { + qDebug() << display; + Q_EMIT showAddOtherWlanWidgetSignal(display, devName); + } +} + +//开启热点 +void DbusAdaptor::activeWirelessAp(const QString apName, const QString apPassword, const QString band, const QString apDevice) +{ + m_mainWindow->activeWirelessAp(apName, apPassword, band, apDevice); +} + +//断开热点 +void DbusAdaptor::deactiveWirelessAp(const QString apName, const QString uuid) +{ + m_mainWindow->deactiveWirelessAp(apName, uuid); +} + +//获取热点 +QStringList DbusAdaptor::getStoredApInfo() +{ + QStringList list; + list.clear(); + m_mainWindow->getStoredApInfo(list); + return list; +} + +//获取热点path +QString DbusAdaptor::getApConnectionPath(QString uuid) +{ + QString path; + path.clear(); + m_mainWindow->getApConnectionPath(path, uuid); + return path; +} + +//获取热点path +QString DbusAdaptor::getActiveConnectionPath(QString uuid) +{ + QString path; + path.clear(); + m_mainWindow->getActiveConnectionPath(path, uuid); + return path; +} + +QStringList DbusAdaptor::getApInfoBySsid(QString devName, QString ssid) +{ + QStringList list; + list.clear(); + m_mainWindow->getApInfoBySsid(devName, ssid, list); + return list; +} + +void DbusAdaptor::showKylinNM(int type) +{ + qDebug() << "display" << checkDisplay(); + QString display = checkDisplay(); + if (m_display == display) { + m_mainWindow->onShowMainWindow(type); + } else { + + Q_EMIT showKylinNMSignal(display, type); + } +} + +//扫描 +void DbusAdaptor::reScan() +{ + m_mainWindow->rescan(); +} + +void DbusAdaptor::keyRingInit() +{ + m_mainWindow->keyRingInit(); +} + +void DbusAdaptor::keyRingClear() +{ + m_mainWindow->keyRingClear(); +} + +void DbusAdaptor::connectToMainwindow() +{ + connect(m_mainWindow, &MainWindow::lanAdd, this, &DbusAdaptor::lanAdd); + connect(m_mainWindow, &MainWindow::lanRemove, this, &DbusAdaptor::lanRemove); + connect(m_mainWindow, &MainWindow::lanUpdate, this, &DbusAdaptor::lanUpdate); + connect(m_mainWindow, &MainWindow::wlanAdd, this, &DbusAdaptor::wlanAdd); + connect(m_mainWindow, &MainWindow::wlanRemove, this, &DbusAdaptor::wlanRemove); + connect(m_mainWindow, &MainWindow::wlanactiveConnectionStateChanged, this, &DbusAdaptor::wlanactiveConnectionStateChanged); + connect(m_mainWindow, &MainWindow::lanActiveConnectionStateChanged, this, &DbusAdaptor::lanActiveConnectionStateChanged); + connect(m_mainWindow, &MainWindow::activateFailed, this, &DbusAdaptor::activateFailed); + connect(m_mainWindow, &MainWindow::deactivateFailed, this, &DbusAdaptor::deactivateFailed); + connect(m_mainWindow, &MainWindow::deviceStatusChanged, this, &DbusAdaptor::deviceStatusChanged); + connect(m_mainWindow, &MainWindow::wirelessDeviceStatusChanged, this, &DbusAdaptor::wirelessDeviceStatusChanged); + connect(m_mainWindow, &MainWindow::deviceNameChanged, this, &DbusAdaptor::deviceNameChanged); + connect(m_mainWindow, &MainWindow::wirelessSwitchBtnChanged, this, &DbusAdaptor::wirelessSwitchBtnChanged); + connect(m_mainWindow, &MainWindow::hotspotDeactivated, this, &DbusAdaptor::hotspotDeactivated); + connect(m_mainWindow, &MainWindow::hotspotActivated, this, &DbusAdaptor::hotspotActivated); + connect(m_mainWindow, &MainWindow::signalStrengthChange, this, &DbusAdaptor::signalStrengthChange); + connect(m_mainWindow, &MainWindow::secuTypeChange, this, &DbusAdaptor::secuTypeChange); + connect(m_mainWindow, &MainWindow::timeToUpdate, this, &DbusAdaptor::timeToUpdate); +} + +QString DbusAdaptor::checkDisplay() +{ + uint pid = 0; + QDBusReply pidReply = connection().interface()->servicePid(message().service()); + qDebug() << "caller pid: " << pidReply.value(); + if(pidReply.isValid()) { + pid = pidReply.value(); + } else { + return {}; + } + return displayFromPid(pid);; +} + +QString DbusAdaptor::displayFromPid(uint pid) +{ + QFile environFile(QStringLiteral("/proc/%1/environ").arg(QString::number(pid))); + if (environFile.open(QIODevice::ReadOnly | QIODevice::Text)) { + const QByteArray DISPLAY = qApp->property("sessionType").toString() == "wayland" ? QByteArrayLiteral("WAYLAND_DISPLAY") + : QByteArrayLiteral("DISPLAY"); + const auto lines = environFile.readAll().split('\0'); + for (const QByteArray &line : lines) { + const int equalsIdx = line.indexOf('='); + if (equalsIdx <= 0) { + continue; + } + const QByteArray key = line.left(equalsIdx); + if (key == DISPLAY) { + const QByteArray value = line.mid(equalsIdx + 1); + return value; + } + } + } + return {}; +} + diff --git a/src/backend/dbusadaptor.h b/src/backend/dbus.h similarity index 78% rename from src/backend/dbusadaptor.h rename to src/backend/dbus.h index a6fa6a8d..5115146d 100644 --- a/src/backend/dbusadaptor.h +++ b/src/backend/dbus.h @@ -15,6 +15,8 @@ #include #include #include +#include "dbus_adaptor.h" +#include "dbus_interface.h" #include "tabpage.h" #include "../dbus-interface/kylinnetworkdeviceresource.h" @@ -34,23 +36,19 @@ QT_END_NAMESPACE #include "mainwindow.h" -class DbusAdaptor: public QDBusAbstractAdaptor +class DbusAdaptor: public QObject, protected QDBusContext { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "com.kylin.network") public: - DbusAdaptor(MainWindow *parent); - virtual ~DbusAdaptor(); - - inline MainWindow *parent() const - { return static_cast(QObject::parent()); } + explicit DbusAdaptor(QString display, MainWindow *m, QObject *parent = nullptr); public: // PROPERTIES public Q_SLOTS: // METHODS //无线列表 - QMap > getWirelessList(); + QVariantList getWirelessList(QString devName); //有线列表 - QMap> getWiredList(); + QVariantList getWiredList(QString devName); //有线总开关 Q_NOREPLY void setWiredSwitchEnable(bool enable); //无线总开关 @@ -67,9 +65,9 @@ public Q_SLOTS: // METHODS //断开连接 根据网卡类型 参数1 0:lan 1:wlan 参数3 为ssid/uuid Q_NOREPLY void deActivateConnect(int type, QString devName, QString ssid); //获取设备列表和启用/禁用状态 - QMap getDeviceListAndEnabled(int devType); + QVariantMap getDeviceListAndEnabled(int devType); //获取无线设备能力 - QMap getWirelessDeviceCap(); + QVariantMap getWirelessDeviceCap(); //唤起属性页 根据网卡类型 参数2 为ssid/uuid Q_NOREPLY void showPropertyWidget(QString devName, QString ssid); //唤起新建有线连接界面 @@ -124,6 +122,29 @@ Q_SIGNALS: // SIGNALS void secuTypeChange(QString devName, QString ssid, QString secuType); //列表排序 void timeToUpdate(); + + + + void showKylinNMSignal(QString display, int type); + + //唤起属性页 根据网卡类型 参数2 为ssid/uuid + void showPropertyWidgetSignal(QString display, QString devName, QString ssid); + //唤起新建有线连接界面 + void showCreateWiredConnectWidgetSignal(QString display, QString devName); + //唤起加入其他无线网络界面 + void showAddOtherWlanWidgetSignal(QString display, QString devName); + +private: + MainWindow *m_mainWindow; + QString m_display; + QDBusServiceWatcher *m_watcher = nullptr; + + QString checkDisplay(); + QString displayFromPid(uint pid); + void connectToMainwindow(); + bool registerService(); +private Q_SLOT: + void onServiceOwnerChanged(const QString &service, const QString &oldOwner, const QString &newOwner); }; #endif diff --git a/src/backend/dbus.xml b/src/backend/dbus.xml new file mode 100644 index 00000000..59d36c32 --- /dev/null +++ b/src/backend/dbus.xml @@ -0,0 +1,186 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/backend/dbus_adaptor.cpp b/src/backend/dbus_adaptor.cpp new file mode 100644 index 00000000..56e99012 --- /dev/null +++ b/src/backend/dbus_adaptor.cpp @@ -0,0 +1,191 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: qdbusxml2cpp dbus.xml -a dbus_adaptor + * + * qdbusxml2cpp is Copyright (C) 2020 The Qt Company Ltd. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#include "dbus_adaptor.h" +#include +#include +#include +#include +#include +#include +#include + +/* + * Implementation of adaptor class NetworkAdaptor + */ + +NetworkAdaptor::NetworkAdaptor(QObject *parent) + : QDBusAbstractAdaptor(parent) +{ + // constructor + setAutoRelaySignals(true); +} + +NetworkAdaptor::~NetworkAdaptor() +{ + // destructor +} + +void NetworkAdaptor::activateConnect(int type, const QString &devName, const QString &ssid) +{ + // handle method call com.kylin.network.activateConnect + QMetaObject::invokeMethod(parent(), "activateConnect", Q_ARG(int, type), Q_ARG(QString, devName), Q_ARG(QString, ssid)); +} + +void NetworkAdaptor::activeWirelessAp(const QString &apName, const QString &apPassword, const QString &band, const QString &apDevice) +{ + // handle method call com.kylin.network.activeWirelessAp + QMetaObject::invokeMethod(parent(), "activeWirelessAp", Q_ARG(QString, apName), Q_ARG(QString, apPassword), Q_ARG(QString, band), Q_ARG(QString, apDevice)); +} + +void NetworkAdaptor::deActivateConnect(int type, const QString &devName, const QString &ssid) +{ + // handle method call com.kylin.network.deActivateConnect + QMetaObject::invokeMethod(parent(), "deActivateConnect", Q_ARG(int, type), Q_ARG(QString, devName), Q_ARG(QString, ssid)); +} + +void NetworkAdaptor::deactiveWirelessAp(const QString &apName, const QString &uuid) +{ + // handle method call com.kylin.network.deactiveWirelessAp + QMetaObject::invokeMethod(parent(), "deactiveWirelessAp", Q_ARG(QString, apName), Q_ARG(QString, uuid)); +} + +QString NetworkAdaptor::getActiveConnectionPath(const QString &uuid) +{ + // handle method call com.kylin.network.getActiveConnectionPath + QString out0; + QMetaObject::invokeMethod(parent(), "getActiveConnectionPath", Q_RETURN_ARG(QString, out0), Q_ARG(QString, uuid)); + return out0; +} + +QString NetworkAdaptor::getApConnectionPath(const QString &uuid) +{ + // handle method call com.kylin.network.getApConnectionPath + QString out0; + QMetaObject::invokeMethod(parent(), "getApConnectionPath", Q_RETURN_ARG(QString, out0), Q_ARG(QString, uuid)); + return out0; +} + +QStringList NetworkAdaptor::getApInfoBySsid(const QString &devName, const QString &ssid) +{ + // handle method call com.kylin.network.getApInfoBySsid + QStringList out0; + QMetaObject::invokeMethod(parent(), "getApInfoBySsid", Q_RETURN_ARG(QStringList, out0), Q_ARG(QString, devName), Q_ARG(QString, ssid)); + return out0; +} + +QVariantMap NetworkAdaptor::getDeviceListAndEnabled(int devType) +{ + // handle method call com.kylin.network.getDeviceListAndEnabled + QVariantMap out0; + QMetaObject::invokeMethod(parent(), "getDeviceListAndEnabled", Q_RETURN_ARG(QVariantMap, out0), Q_ARG(int, devType)); + return out0; +} + +QStringList NetworkAdaptor::getStoredApInfo() +{ + // handle method call com.kylin.network.getStoredApInfo + QStringList out0; + QMetaObject::invokeMethod(parent(), "getStoredApInfo", Q_RETURN_ARG(QStringList, out0)); + return out0; +} + +QVariantList NetworkAdaptor::getWiredList(const QString &devName) +{ + // handle method call com.kylin.network.getWiredList + QVariantList out0; + QMetaObject::invokeMethod(parent(), "getWiredList", Q_RETURN_ARG(QVariantList, out0), Q_ARG(QString, devName)); + return out0; +} + +QVariantMap NetworkAdaptor::getWirelessDeviceCap() +{ + // handle method call com.kylin.network.getWirelessDeviceCap + QVariantMap out0; + QMetaObject::invokeMethod(parent(), "getWirelessDeviceCap", Q_RETURN_ARG(QVariantMap, out0)); + return out0; +} + +QVariantList NetworkAdaptor::getWirelessList(const QString &devName) +{ + // handle method call com.kylin.network.getWirelessList + QVariantList out0; + QMetaObject::invokeMethod(parent(), "getWirelessList", Q_RETURN_ARG(QVariantList, out0), Q_ARG(QString, devName)); + return out0; +} + +bool NetworkAdaptor::getWirelessSwitchBtnState() +{ + // handle method call com.kylin.network.getWirelessSwitchBtnState + bool out0; + QMetaObject::invokeMethod(parent(), "getWirelessSwitchBtnState", Q_RETURN_ARG(bool, out0)); + return out0; +} + +void NetworkAdaptor::keyRingClear() +{ + // handle method call com.kylin.network.keyRingClear + QMetaObject::invokeMethod(parent(), "keyRingClear"); +} + +void NetworkAdaptor::keyRingInit() +{ + // handle method call com.kylin.network.keyRingInit + QMetaObject::invokeMethod(parent(), "keyRingInit"); +} + +void NetworkAdaptor::reScan() +{ + // handle method call com.kylin.network.reScan + QMetaObject::invokeMethod(parent(), "reScan"); +} + +void NetworkAdaptor::setDeviceEnable(const QString &devName, bool enable) +{ + // handle method call com.kylin.network.setDeviceEnable + QMetaObject::invokeMethod(parent(), "setDeviceEnable", Q_ARG(QString, devName), Q_ARG(bool, enable)); +} + +void NetworkAdaptor::setWiredSwitchEnable(bool enable) +{ + // handle method call com.kylin.network.setWiredSwitchEnable + QMetaObject::invokeMethod(parent(), "setWiredSwitchEnable", Q_ARG(bool, enable)); +} + +void NetworkAdaptor::setWirelessSwitchEnable(bool enable) +{ + // handle method call com.kylin.network.setWirelessSwitchEnable + QMetaObject::invokeMethod(parent(), "setWirelessSwitchEnable", Q_ARG(bool, enable)); +} + +void NetworkAdaptor::showAddOtherWlanWidget(const QString &devName) +{ + // handle method call com.kylin.network.showAddOtherWlanWidget + QMetaObject::invokeMethod(parent(), "showAddOtherWlanWidget", Q_ARG(QString, devName)); +} + +void NetworkAdaptor::showCreateWiredConnectWidget(const QString &devName) +{ + // handle method call com.kylin.network.showCreateWiredConnectWidget + QMetaObject::invokeMethod(parent(), "showCreateWiredConnectWidget", Q_ARG(QString, devName)); +} + +void NetworkAdaptor::showKylinNM(int type) +{ + // handle method call com.kylin.network.showKylinNM + QMetaObject::invokeMethod(parent(), "showKylinNM", Q_ARG(int, type)); +} + +void NetworkAdaptor::showPropertyWidget(const QString &devName, const QString &ssid) +{ + // handle method call com.kylin.network.showPropertyWidget + QMetaObject::invokeMethod(parent(), "showPropertyWidget", Q_ARG(QString, devName), Q_ARG(QString, ssid)); +} + diff --git a/src/backend/dbus_adaptor.h b/src/backend/dbus_adaptor.h new file mode 100644 index 00000000..e562a2d3 --- /dev/null +++ b/src/backend/dbus_adaptor.h @@ -0,0 +1,266 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: qdbusxml2cpp dbus.xml -a dbus_adaptor + * + * qdbusxml2cpp is Copyright (C) 2020 The Qt Company Ltd. + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#ifndef DBUS_ADAPTOR_H +#define DBUS_ADAPTOR_H + +#include +#include +QT_BEGIN_NAMESPACE +class QByteArray; +template class QList; +template class QMap; +class QString; +class QStringList; +class QVariant; +QT_END_NAMESPACE + +/* + * Adaptor class for interface com.kylin.network + */ +class NetworkAdaptor: 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" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" + "") +public: + NetworkAdaptor(QObject *parent); + virtual ~NetworkAdaptor(); + +public: // PROPERTIES +public Q_SLOTS: // METHODS + Q_NOREPLY void activateConnect(int type, const QString &devName, const QString &ssid); + void activeWirelessAp(const QString &apName, const QString &apPassword, const QString &band, const QString &apDevice); + Q_NOREPLY void deActivateConnect(int type, const QString &devName, const QString &ssid); + void deactiveWirelessAp(const QString &apName, const QString &uuid); + QString getActiveConnectionPath(const QString &uuid); + QString getApConnectionPath(const QString &uuid); + QStringList getApInfoBySsid(const QString &devName, const QString &ssid); + QVariantMap getDeviceListAndEnabled(int devType); + QStringList getStoredApInfo(); + QVariantList getWiredList(const QString &devName); + QVariantMap getWirelessDeviceCap(); + QVariantList getWirelessList(const QString &devName); + bool getWirelessSwitchBtnState(); + void keyRingClear(); + void keyRingInit(); + void reScan(); + Q_NOREPLY void setDeviceEnable(const QString &devName, bool enable); + Q_NOREPLY void setWiredSwitchEnable(bool enable); + Q_NOREPLY void setWirelessSwitchEnable(bool enable); + Q_NOREPLY void showAddOtherWlanWidget(const QString &devName); + Q_NOREPLY void showCreateWiredConnectWidget(const QString &devName); + void showKylinNM(int type); + Q_NOREPLY void showPropertyWidget(const QString &devName, const QString &ssid); +Q_SIGNALS: // SIGNALS + void activateFailed(const QString &errorMessage); + void deactivateFailed(const QString &errorMessage); + void deviceNameChanged(const QString &oldName, const QString &newName, int type); + void deviceStatusChanged(); + void hotspotActivated(const QString &devName, const QString &ssid, const QString &uuid, const QString &activePath, const QString &settingPath); + void hotspotDeactivated(const QString &devName, const QString &ssid); + void lanActiveConnectionStateChanged(const QString &devName, const QString &uuid, int status); + void lanAdd(const QString &devName, const QStringList &info); + void lanRemove(const QString &dbusPath); + void lanUpdate(const QString &devName, const QStringList &info); + void secuTypeChange(const QString &devName, const QString &ssid, const QString &secuType); + void showAddOtherWlanWidgetSignal(const QString &display, const QString &devName); + void showCreateWiredConnectWidgetSignal(const QString &display, const QString &devName); + void showKylinNMSignal(const QString &display, int type); + void showPropertyWidgetSignal(const QString &display, const QString &devName, const QString &ssid); + void signalStrengthChange(const QString &devName, const QString &ssid, int strength); + void timeToUpdate(); + void wirelessDeviceStatusChanged(); + void wirelessSwitchBtnChanged(bool state); + void wlanAdd(const QString &devName, const QStringList &info); + void wlanRemove(const QString &devName, const QString &ssid); + void wlanactiveConnectionStateChanged(const QString &devName, const QString &ssid, const QString &uuid, int status); +}; + +#endif diff --git a/src/backend/dbus_interface.cpp b/src/backend/dbus_interface.cpp new file mode 100644 index 00000000..1f04e21e --- /dev/null +++ b/src/backend/dbus_interface.cpp @@ -0,0 +1,26 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: qdbusxml2cpp dbus.xml -p dbus_interface + * + * qdbusxml2cpp is Copyright (C) 2020 The Qt Company Ltd. + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "dbus_interface.h" + +/* + * Implementation of interface class ComKylinNetworkInterface + */ + +ComKylinNetworkInterface::ComKylinNetworkInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +ComKylinNetworkInterface::~ComKylinNetworkInterface() +{ +} + diff --git a/src/backend/dbus_interface.h b/src/backend/dbus_interface.h new file mode 100644 index 00000000..f8a73c64 --- /dev/null +++ b/src/backend/dbus_interface.h @@ -0,0 +1,224 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: qdbusxml2cpp dbus.xml -p dbus_interface + * + * qdbusxml2cpp is Copyright (C) 2020 The Qt Company Ltd. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef DBUS_INTERFACE_H +#define DBUS_INTERFACE_H + +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * Proxy class for interface com.kylin.network + */ +class ComKylinNetworkInterface: public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() + { return "com.kylin.network"; } + +public: + ComKylinNetworkInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = nullptr); + + ~ComKylinNetworkInterface(); + +public Q_SLOTS: // METHODS + inline Q_NOREPLY void activateConnect(int type, const QString &devName, const QString &ssid) + { + QList argumentList; + argumentList << QVariant::fromValue(type) << QVariant::fromValue(devName) << QVariant::fromValue(ssid); + callWithArgumentList(QDBus::NoBlock, QStringLiteral("activateConnect"), argumentList); + } + + inline QDBusPendingReply<> activeWirelessAp(const QString &apName, const QString &apPassword, const QString &band, const QString &apDevice) + { + QList argumentList; + argumentList << QVariant::fromValue(apName) << QVariant::fromValue(apPassword) << QVariant::fromValue(band) << QVariant::fromValue(apDevice); + return asyncCallWithArgumentList(QStringLiteral("activeWirelessAp"), argumentList); + } + + inline Q_NOREPLY void deActivateConnect(int type, const QString &devName, const QString &ssid) + { + QList argumentList; + argumentList << QVariant::fromValue(type) << QVariant::fromValue(devName) << QVariant::fromValue(ssid); + callWithArgumentList(QDBus::NoBlock, QStringLiteral("deActivateConnect"), argumentList); + } + + inline QDBusPendingReply<> deactiveWirelessAp(const QString &apName, const QString &uuid) + { + QList argumentList; + argumentList << QVariant::fromValue(apName) << QVariant::fromValue(uuid); + return asyncCallWithArgumentList(QStringLiteral("deactiveWirelessAp"), argumentList); + } + + inline QDBusPendingReply getActiveConnectionPath(const QString &uuid) + { + QList argumentList; + argumentList << QVariant::fromValue(uuid); + return asyncCallWithArgumentList(QStringLiteral("getActiveConnectionPath"), argumentList); + } + + inline QDBusPendingReply getApConnectionPath(const QString &uuid) + { + QList argumentList; + argumentList << QVariant::fromValue(uuid); + return asyncCallWithArgumentList(QStringLiteral("getApConnectionPath"), argumentList); + } + + inline QDBusPendingReply getApInfoBySsid(const QString &devName, const QString &ssid) + { + QList argumentList; + argumentList << QVariant::fromValue(devName) << QVariant::fromValue(ssid); + return asyncCallWithArgumentList(QStringLiteral("getApInfoBySsid"), argumentList); + } + + inline QDBusPendingReply getDeviceListAndEnabled(int devType) + { + QList argumentList; + argumentList << QVariant::fromValue(devType); + return asyncCallWithArgumentList(QStringLiteral("getDeviceListAndEnabled"), argumentList); + } + + inline QDBusPendingReply getStoredApInfo() + { + QList argumentList; + return asyncCallWithArgumentList(QStringLiteral("getStoredApInfo"), argumentList); + } + + inline QDBusPendingReply getWiredList(const QString &devName) + { + QList argumentList; + argumentList << QVariant::fromValue(devName); + return asyncCallWithArgumentList(QStringLiteral("getWiredList"), argumentList); + } + + inline QDBusPendingReply getWirelessDeviceCap() + { + QList argumentList; + return asyncCallWithArgumentList(QStringLiteral("getWirelessDeviceCap"), argumentList); + } + + inline QDBusPendingReply getWirelessList(const QString &devName) + { + QList argumentList; + argumentList << QVariant::fromValue(devName); + return asyncCallWithArgumentList(QStringLiteral("getWirelessList"), argumentList); + } + + inline QDBusPendingReply getWirelessSwitchBtnState() + { + QList argumentList; + return asyncCallWithArgumentList(QStringLiteral("getWirelessSwitchBtnState"), argumentList); + } + + inline QDBusPendingReply<> keyRingClear() + { + QList argumentList; + return asyncCallWithArgumentList(QStringLiteral("keyRingClear"), argumentList); + } + + inline QDBusPendingReply<> keyRingInit() + { + QList argumentList; + return asyncCallWithArgumentList(QStringLiteral("keyRingInit"), argumentList); + } + + inline QDBusPendingReply<> reScan() + { + QList argumentList; + return asyncCallWithArgumentList(QStringLiteral("reScan"), argumentList); + } + + inline Q_NOREPLY void setDeviceEnable(const QString &devName, bool enable) + { + QList argumentList; + argumentList << QVariant::fromValue(devName) << QVariant::fromValue(enable); + callWithArgumentList(QDBus::NoBlock, QStringLiteral("setDeviceEnable"), argumentList); + } + + inline Q_NOREPLY void setWiredSwitchEnable(bool enable) + { + QList argumentList; + argumentList << QVariant::fromValue(enable); + callWithArgumentList(QDBus::NoBlock, QStringLiteral("setWiredSwitchEnable"), argumentList); + } + + inline Q_NOREPLY void setWirelessSwitchEnable(bool enable) + { + QList argumentList; + argumentList << QVariant::fromValue(enable); + callWithArgumentList(QDBus::NoBlock, QStringLiteral("setWirelessSwitchEnable"), argumentList); + } + + inline Q_NOREPLY void showAddOtherWlanWidget(const QString &devName) + { + QList argumentList; + argumentList << QVariant::fromValue(devName); + callWithArgumentList(QDBus::NoBlock, QStringLiteral("showAddOtherWlanWidget"), argumentList); + } + + inline Q_NOREPLY void showCreateWiredConnectWidget(const QString &devName) + { + QList argumentList; + argumentList << QVariant::fromValue(devName); + callWithArgumentList(QDBus::NoBlock, QStringLiteral("showCreateWiredConnectWidget"), argumentList); + } + + inline QDBusPendingReply<> showKylinNM(int type) + { + QList argumentList; + argumentList << QVariant::fromValue(type); + return asyncCallWithArgumentList(QStringLiteral("showKylinNM"), argumentList); + } + + inline Q_NOREPLY void showPropertyWidget(const QString &devName, const QString &ssid) + { + QList argumentList; + argumentList << QVariant::fromValue(devName) << QVariant::fromValue(ssid); + callWithArgumentList(QDBus::NoBlock, QStringLiteral("showPropertyWidget"), argumentList); + } + +Q_SIGNALS: // SIGNALS + void activateFailed(const QString &errorMessage); + void deactivateFailed(const QString &errorMessage); + void deviceNameChanged(const QString &oldName, const QString &newName, int type); + void deviceStatusChanged(); + void hotspotActivated(const QString &devName, const QString &ssid, const QString &uuid, const QString &activePath, const QString &settingPath); + void hotspotDeactivated(const QString &devName, const QString &ssid); + void lanActiveConnectionStateChanged(const QString &devName, const QString &uuid, int status); + void lanAdd(const QString &devName, const QStringList &info); + void lanRemove(const QString &dbusPath); + void lanUpdate(const QString &devName, const QStringList &info); + void secuTypeChange(const QString &devName, const QString &ssid, const QString &secuType); + void showAddOtherWlanWidgetSignal(const QString &display, const QString &devName); + void showCreateWiredConnectWidgetSignal(const QString &display, const QString &devName); + void showKylinNMSignal(const QString &display, int type); + void showPropertyWidgetSignal(const QString &display, const QString &devName, const QString &ssid); + void signalStrengthChange(const QString &devName, const QString &ssid, int strength); + void timeToUpdate(); + void wirelessDeviceStatusChanged(); + void wirelessSwitchBtnChanged(bool state); + void wlanAdd(const QString &devName, const QStringList &info); + void wlanRemove(const QString &devName, const QString &ssid); + void wlanactiveConnectionStateChanged(const QString &devName, const QString &ssid, const QString &uuid, int status); +}; + +namespace com { + namespace kylin { + typedef ::ComKylinNetworkInterface network; + } +} +#endif diff --git a/src/backend/dbusadaptor.cpp b/src/backend/dbusadaptor.cpp deleted file mode 100644 index 0f22c845..00000000 --- a/src/backend/dbusadaptor.cpp +++ /dev/null @@ -1,279 +0,0 @@ -/* - * This file was generated by qdbusxml2cpp version 0.8 - * Command line was: qdbusxml2cpp com.kylin.weather.xml -a dbusadaptor -c DbusAdaptor -l MainWindow - * - * qdbusxml2cpp is Copyright (C) 2015 The Qt Company Ltd. - * - * This is an auto-generated file. - * Do not edit! All changes made to it will be lost. - */ - -#include "dbusadaptor.h" -#include -#include -#include -#include -#include -#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"; - -/* - * Implementation of adaptor class DbusAdaptor - */ - -DbusAdaptor::DbusAdaptor(MainWindow *parent) - : QDBusAbstractAdaptor(parent) -{ - // constructor - qDBusRegisterMetaType >(); - qDBusRegisterMetaType >(); - qDBusRegisterMetaType >(); - qDBusRegisterMetaType >>(); - //setAutoRelaySignals(true)后会自动转发mainwindow发出的同名信号,因此不必再额外写一个转发 - setAutoRelaySignals(true); -} - -DbusAdaptor::~DbusAdaptor() -{ - // destructor -} - -//无线列表 -QMap > DbusAdaptor::getWirelessList() -{ - QMap > map; - parent()->getWirelessList(map); - return map; -} - -bool DbusAdaptor::getWirelessSwitchBtnState() -{ - return parent()->getWirelessSwitchBtnState(); -} - -//有线列表 -QMap> DbusAdaptor::getWiredList() -{ - QMap> map; - parent()->getWiredList(map); - return map; -} - -//有线开关 -void DbusAdaptor::setWiredSwitchEnable(bool enable) -{ - //todo mainwindow调用backend 对开关 打开/关闭 - if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA_KYLIN_NM)) { - QGSettings *gsetting = new QGSettings(GSETTINGS_SCHEMA_KYLIN_NM); - if (gsetting->get(KEY_WIRED_SWITCH).toBool() != enable) { - gsetting->set(KEY_WIRED_SWITCH, enable); - } - delete gsetting; - gsetting = nullptr; - } else { - qDebug()<<"isSchemaInstalled false"; - } -} - -//无线开关 -void DbusAdaptor::setWirelessSwitchEnable(bool enable) -{ - //todo mainwindow调用backend 对开关 打开/关闭 -// if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA_KYLIN_NM)) { -// QGSettings *gsetting = new QGSettings(GSETTINGS_SCHEMA_KYLIN_NM); -// if (gsetting->get(KEY_WIRELESS_SWITCH).toBool() != enable) { -// gsetting->set(KEY_WIRELESS_SWITCH, enable); -// } -// delete gsetting; -// gsetting = nullptr; -// } else { -// qDebug()<<"isSchemaInstalled false"; -// } - parent()->setWirelessSwitchEnable(enable); -} - -//启用/禁用网卡 -void DbusAdaptor::setDeviceEnable(QString devName, bool enable) -{ - parent()->setWiredDeviceEnable(devName, enable); -} - -//设置默认网卡 -//void DbusAdaptor::setDefaultWiredDevice(QString deviceName) -//{ -// if (!checkDeviceExist(WIRED, deviceName)) { -// return; -// } -// setDefaultDevice(WIRED, deviceName); -// 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) -//{ -// if (!checkDeviceExist(WIRED, deviceName)) { -// return; -// } -// setDefaultDevice(WIRELESS, deviceName); -// 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; -//} - -//连接 根据网卡类型 参数1 0:lan 1:wlan 参数3 为ssid/uuid -void DbusAdaptor::activateConnect(int type, QString devName, QString ssid) -{ - if (type == WIRED) { - parent()->activateWired(devName,ssid); - } else if (type == WIRELESS) { - parent()->activateWireless(devName,ssid); - } else { - qDebug() << "[DbusAdaptor] activateConnect type is invalid"; - } -} - -//断开连接 根据网卡类型 参数1 0:lan 1:wlan 参数3 为ssid/uuid -void DbusAdaptor::deActivateConnect(int type, QString devName, QString ssid) -{ - if (type == WIRED) { - qDebug() << "deactivateWired"; - parent()->deactivateWired(devName,ssid); - } else if (type == WIRELESS) { - parent()->deactivateWireless(devName,ssid); - } else { - qDebug() << "[DbusAdaptor] deactivateConnect type is invalid"; - } -} - -//获取设备列表和启用/禁用状态 -QMap DbusAdaptor::getDeviceListAndEnabled(int devType) -{ - QMap map; - map.clear(); - getDeviceEnableState(devType, map); - return map; -} - -//获取无线设备能力 -QMap DbusAdaptor::getWirelessDeviceCap() -{ - QMap map; - parent()->getWirelessDeviceCap(map); - return map; -} - -//唤起属性页 根据网卡类型 参数2 为ssid/uuid -void DbusAdaptor::showPropertyWidget(QString devName, QString ssid) -{ - qDebug() << "showPropertyWidget"; - parent()->showPropertyWidget(devName,ssid); -} - -//唤起新建有线连接界面 -void DbusAdaptor::showCreateWiredConnectWidget(QString devName) -{ - qDebug() << "showCreateWiredConnectWidget"; - parent()->showCreateWiredConnectWidget(devName); -} - -//唤起加入其他无线网络界面 -void DbusAdaptor::showAddOtherWlanWidget(QString devName) -{ - qDebug() << "showAddOtherWlanWidget"; - parent()->showAddOtherWlanWidget(devName); -} - -//开启热点 -void DbusAdaptor::activeWirelessAp(const QString apName, const QString apPassword, const QString band, const QString apDevice) -{ - parent()->activeWirelessAp(apName, apPassword, band, apDevice); -} - -//断开热点 -void DbusAdaptor::deactiveWirelessAp(const QString apName, const QString uuid) -{ - parent()->deactiveWirelessAp(apName, uuid); -} - -//获取热点 -QStringList DbusAdaptor::getStoredApInfo() -{ - QStringList list; - list.clear(); - parent()->getStoredApInfo(list); - return list; -} - -//获取热点path -QString DbusAdaptor::getApConnectionPath(QString uuid) -{ - QString path; - path.clear(); - parent()->getApConnectionPath(path, uuid); - return path; -} - -//获取热点path -QString DbusAdaptor::getActiveConnectionPath(QString uuid) -{ - QString path; - path.clear(); - parent()->getActiveConnectionPath(path, uuid); - return path; -} - -QStringList DbusAdaptor::getApInfoBySsid(QString devName, QString ssid) -{ - QStringList list; - list.clear(); - parent()->getApInfoBySsid(devName, ssid, list); - return list; -} - -void DbusAdaptor::showKylinNM(int type) -{ - parent()->onShowMainWindow(type); -} - -//扫描 -void DbusAdaptor::reScan() -{ - parent()->rescan(); -} - -void DbusAdaptor::keyRingInit() -{ - parent()->keyRingInit(); -} - -void DbusAdaptor::keyRingClear() -{ - parent()->keyRingClear(); -} diff --git a/src/frontend/mainwindow.cpp b/src/frontend/mainwindow.cpp index d172a46c..2696b29e 100644 --- a/src/frontend/mainwindow.cpp +++ b/src/frontend/mainwindow.cpp @@ -71,7 +71,7 @@ const QString intel = "V10SP1-edu"; #include #include -MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) +MainWindow::MainWindow(QString display, QWidget *parent) : QMainWindow(parent), m_display(display) { firstlyStart(); } @@ -396,6 +396,26 @@ void MainWindow::initDbusConnnect() } }); + QDBusConnection::sessionBus().connect(QString("com.kylin.network"), + QString("/com/kylin/network"), + QString("com.kylin.network"), + QString("showKylinNMSignal"), this, SLOT(onShowKylinNMSlot(QString,int))); + + QDBusConnection::sessionBus().connect(QString("com.kylin.network"), + QString("/com/kylin/network"), + QString("com.kylin.network"), + QString("showPropertyWidgetSignal"), this, SLOT(onShowPropertyWidgetSlot(QString,QString,QString))); + + QDBusConnection::sessionBus().connect(QString("com.kylin.network"), + QString("/com/kylin/network"), + QString("com.kylin.network"), + QString("showCreateWiredConnectWidgetSignal"), this, SLOT(onShowCreateWiredConnectWidgetSlot(QString,QString))); + + QDBusConnection::sessionBus().connect(QString("com.kylin.network"), + QString("/com/kylin/network"), + QString("com.kylin.network"), + QString("showAddOtherWlanWidgetSignal"), this, SLOT(onShowAddOtherWlanWidgetSlot(QString,QString))); + } /** @@ -861,13 +881,14 @@ void MainWindow::keyPressEvent(QKeyEvent *event) /** * @brief MainWindow::getWirelessList 获取wifi列表,供dbus调用 - * @param map + * @param devName + * @param list */ -void MainWindow::getWirelessList(QMap > &map) +void MainWindow::getWirelessList(QString devName, QList &list) { - map.clear(); + list.clear(); if (nullptr != m_wlanWidget) { - m_wlanWidget->getWirelessList(map); + m_wlanWidget->getWirelessList(devName, list); } } @@ -882,11 +903,11 @@ bool MainWindow::getWirelessSwitchBtnState() * @brief MainWindow::getWiredList 获取lan列表,供dbus调用 * @param map */ -void MainWindow::getWiredList(QMap> &map) +void MainWindow::getWiredList(QString devName, QList &list) { - map.clear(); + list.clear(); if (nullptr != m_lanWidget) { - m_lanWidget->getWiredList(map); + m_lanWidget->getWiredList(devName, list); } } @@ -1041,3 +1062,32 @@ void MainWindow::keyRingClear() { agent_clear(); } + +void MainWindow::onShowKylinNMSlot(QString display, int type) +{ + if (display == m_display) { + onShowMainWindow(type); + } +} + +//唤起属性页 根据网卡类型 参数2 为ssid/uuid +void MainWindow::onShowPropertyWidgetSlot(QString display, QString devName, QString ssid) +{ + if (display == m_display) { + showPropertyWidget(devName, ssid); + } +} +//唤起新建有线连接界面 +void MainWindow::onShowCreateWiredConnectWidgetSlot(QString display, QString devName) +{ + if (display == m_display) { + showCreateWiredConnectWidget(devName); + } +} +//唤起加入其他无线网络界面 +void MainWindow::onShowAddOtherWlanWidgetSlot(QString display, QString devName) +{ + if (display == m_display) { + showAddOtherWlanWidget(devName); + } +} diff --git a/src/frontend/mainwindow.h b/src/frontend/mainwindow.h index dd2d8191..01962c21 100644 --- a/src/frontend/mainwindow.h +++ b/src/frontend/mainwindow.h @@ -61,7 +61,7 @@ class MainWindow : public QMainWindow { Q_OBJECT public: - explicit MainWindow(QWidget *parent = nullptr); + explicit MainWindow(QString display, QWidget *parent = nullptr); void showMainwindow(); void hideMainwindow(); @@ -69,8 +69,8 @@ public: void setWirelessDefaultDevice(QString deviceName); //for dbus - void getWirelessList(QMap > &map); - void getWiredList(QMap> &map); + void getWirelessList(QString devName, QList &list); + void getWiredList(QString devName, QList &list); //开启热点 void activeWirelessAp(const QString apName, const QString apPassword, const QString wirelessBand, const QString apDevice); //断开热点 @@ -204,6 +204,8 @@ private: NetworkMode *m_networkMode; + QString m_display; + public Q_SLOTS: void onShowMainWindow(int type); @@ -221,6 +223,14 @@ private Q_SLOTS: void onTimeUpdateTrayIcon(); void onTabletModeChanged(bool mode); void onRefreshTrayIconTooltip(); + + void onShowKylinNMSlot(QString display, int type); + //唤起属性页 根据网卡类型 参数2 为ssid/uuid + void onShowPropertyWidgetSlot(QString display, QString devName, QString ssid); + //唤起新建有线连接界面 + void onShowCreateWiredConnectWidgetSlot(QString display, QString devName); + //唤起加入其他无线网络界面 + void onShowAddOtherWlanWidgetSlot(QString display, QString devName); }; #endif // MAINWINDOW_H diff --git a/src/frontend/tab-pages/lanpage.cpp b/src/frontend/tab-pages/lanpage.cpp index 8152c46a..07f60e89 100644 --- a/src/frontend/tab-pages/lanpage.cpp +++ b/src/frontend/tab-pages/lanpage.cpp @@ -991,34 +991,29 @@ void LanPage::onConnectionStateChange(QString uuid, } -void LanPage::getWiredList(QMap > &map) +void LanPage::getWiredList(QString devName, QList &list) { QStringList devlist; m_deviceResource->getNetworkDeviceList(NetworkManager::Device::Type::Ethernet, devlist); - if (devlist.isEmpty()) { + if (!devlist.contains(devName)) { return; } - Q_FOREACH (auto deviceName, devlist) { - QList activedList; - QList deactivedList; - QVector vector; - m_activeResourse->getActiveConnectionList(deviceName,NetworkManager::ConnectionSettings::Wired,activedList); - if (!activedList.isEmpty()) { - vector.append(QStringList() << activedList.at(0)->m_connectName << activedList.at(0)->m_connectUuid << activedList.at(0)->m_connectPath); - } else { - vector.append(QStringList()<<("--")); - } - - m_connectResourse->getConnectionList(deviceName, NetworkManager::ConnectionSettings::Wired, deactivedList); //未激活列表的显示 - if (!deactivedList.isEmpty()) { - for (int i = 0; i < deactivedList.size(); i++) { - vector.append(QStringList()<m_connectName<m_connectUuid << deactivedList.at(i)->m_connectPath); - } - } - map.insert(deviceName, vector); + QList activedList; + QList deactivedList; + m_activeResourse->getActiveConnectionList(devName,NetworkManager::ConnectionSettings::Wired,activedList); + if (!activedList.isEmpty()) { + list.append(QStringList() << activedList.at(0)->m_connectName << activedList.at(0)->m_connectUuid << activedList.at(0)->m_connectPath); + } else { + list.append(QStringList()<<("--")); + } + + m_connectResourse->getConnectionList(devName, NetworkManager::ConnectionSettings::Wired, deactivedList); //未激活列表的显示 + if (!deactivedList.isEmpty()) { + for (int i = 0; i < deactivedList.size(); i++) { + list.append(QStringList()<m_connectName<m_connectUuid << deactivedList.at(i)->m_connectPath); + } } - return; } void LanPage::sendLanUpdateSignal(KyConnectItem *p_connectItem) diff --git a/src/frontend/tab-pages/lanpage.h b/src/frontend/tab-pages/lanpage.h index bbb3c8b5..76ade9f6 100644 --- a/src/frontend/tab-pages/lanpage.h +++ b/src/frontend/tab-pages/lanpage.h @@ -43,7 +43,7 @@ public: ~LanPage(); //for dbus - void getWiredList(QMap > &map); + void getWiredList(QString devName, QList &list); void activateWired(const QString& devName, const QString& connUuid); void deactivateWired(const QString& devName, const QString& connUuid); void showDetailPage(QString devName, QString uuid); diff --git a/src/frontend/tab-pages/wlanpage.cpp b/src/frontend/tab-pages/wlanpage.cpp index fdc0ecfb..fc5aecf2 100644 --- a/src/frontend/tab-pages/wlanpage.cpp +++ b/src/frontend/tab-pages/wlanpage.cpp @@ -1359,72 +1359,61 @@ void WlanPage::onRefreshIconTimer() } //for dbus -void WlanPage::getWirelessList(QMap > &map) +void WlanPage::getWirelessList(QString devName, QList &list) { - QMap actMap; - m_wirelessNetResource->getWirelessActiveConnection(NetworkManager::ActiveConnection::State::Activated, actMap); + KyWirelessNetItem data; - QMap > wlanMap; - if (!m_wirelessNetResource->getAllDeviceWifiNetwork(wlanMap)) { + QList wlanList; + if (!m_wirelessNetResource->getDeviceWifiNetwork(devName, wlanList)) { return; } - QMap >::iterator iter = wlanMap.begin(); - while (iter != wlanMap.end()) { - QVector vector; - QString activeSsid ; - //先是已连接 - if (actMap.contains(iter.key())) { - qDebug() << "find " <getSsidByUuid(actMap[iter.key()].at(0), ssid); - if (m_wirelessNetResource->getWifiNetwork(iter.key(), ssid, data)) { - int category = 0; - int signalStrength; - QString uni,secuType; - - if (m_netDeviceResource->getActiveConnectionInfo(iter.key(), signalStrength, uni, secuType)) { - category = data.getCategory(uni); - } - if (!m_showWifi6Plus && category == 2) { - category = 1; - } - vector.append(QStringList() << data.m_NetSsid - << QString::number(signalStrength) - << secuType - << data.m_connectUuid - << (m_connectResource->isApConnection(data.m_connectUuid) ? IsApConnection : NotApConnection) - << QString::number(category)); - activeSsid = data.m_NetSsid; - } else { - vector.append(QStringList("--")); - } - } else { - vector.append(QStringList("--")); - } - //未连接 - Q_FOREACH (auto itemData, iter.value()) { - if (itemData.m_NetSsid == activeSsid) { - continue; - } + QString activeSsid ; + //先是已连接 + if (m_wirelessNetResource->getActiveWirelessNetItem(devName, data)) { + qDebug() << "find " << devName; + QString ssid =""; + m_wirelessNetResource->getSsidByUuid(data.m_connectUuid, ssid); + if (m_wirelessNetResource->getWifiNetwork(devName, ssid, data)) { int category = 0; - category = itemData.getCategory(itemData.m_uni); + int signalStrength; + QString uni,secuType; + + if (m_netDeviceResource->getActiveConnectionInfo(devName, signalStrength, uni, secuType)) { + category = data.getCategory(uni); + } if (!m_showWifi6Plus && category == 2) { category = 1; } - vector.append(QStringList()<isApConnection(itemData.m_connectUuid) ? IsApConnection : NotApConnection) + list.append(QStringList() << data.m_NetSsid + << QString::number(signalStrength) + << secuType + << data.m_connectUuid + << (m_connectResource->isApConnection(data.m_connectUuid) ? IsApConnection : NotApConnection) << QString::number(category)); + activeSsid = data.m_NetSsid; + } else { + list.append(QStringList("--")); } - - map.insert(iter.key(), vector); - iter++; + } else { + list.append(QStringList("--")); + } + //未连接 + Q_FOREACH (auto itemData, wlanList) { + if (itemData.m_NetSsid == activeSsid) { + continue; + } + int category = 0; + category = itemData.getCategory(itemData.m_uni); + if (!m_showWifi6Plus && category == 2) { + category = 1; + } + list.append(QStringList()<isApConnection(itemData.m_connectUuid) ? IsApConnection : NotApConnection) + << QString::number(category)); } - - return; } //for dbus diff --git a/src/frontend/tab-pages/wlanpage.h b/src/frontend/tab-pages/wlanpage.h index 41d55246..85256044 100644 --- a/src/frontend/tab-pages/wlanpage.h +++ b/src/frontend/tab-pages/wlanpage.h @@ -52,7 +52,7 @@ public: ~WlanPage() = default; //for dbus - void getWirelessList(QMap > &map); + void getWirelessList(QString devName, QList &list); //开启热点 void activeWirelessAp(const QString apName, const QString apPassword, const QString wirelessBand, const QString apDevice); //断开热点 diff --git a/src/main.cpp b/src/main.cpp index f7482b41..c6aa7de9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,7 +18,7 @@ //#include "mainwindow.h" #include "mainwindow.h" -#include "dbusadaptor.h" +#include "dbus.h" #include #include #include "qt-single-application.h" @@ -125,23 +125,29 @@ int main(int argc, char *argv[]) parser.addOptions({swOption,snOption}); parser.process(a); + QString display; + QString sessionType; + if(QString(getenv("XDG_SESSION_TYPE")) == "wayland") { + sessionType = "wayland"; + display = getenv("WAYLAND_DISPLAY"); + } else { + sessionType = "x11"; + display = getenv("DISPLAY"); + } + qDebug() << display; + QDBusInterface interface("com.kylin.network", "/com/kylin/network", "com.kylin.network", QDBusConnection::sessionBus()); - if(interface.isValid()) { - if (parser.isSet(swOption)) - { - interface.call(QStringLiteral("showKylinNM"), 1); - } else if (parser.isSet(snOption)){ - interface.call(QStringLiteral("showKylinNM"), 0); - } else { - const QString serviceName = "com.kylin.network"; - QDBusConnectionInterface *interface1 = QDBusConnection::sessionBus().interface(); - QDBusReply pid = interface1->servicePid(serviceName); - qDebug() << "current display " << getenv("DISPLAY") << QApplication::applicationPid() - << "exist kylin-nm display" << displayFromPid(pid.value()); - if (getenv("DISPLAY") == displayFromPid(pid.value())) { + + if (a.isRunning()) { + if(interface.isValid()) { + if (parser.isSet(swOption)) { + interface.call(QStringLiteral("showKylinNM"), 1); + } else if (parser.isSet(snOption)) { + interface.call(QStringLiteral("showKylinNM"), 0); + } else { interface.call(QStringLiteral("showKylinNM"), 2); } } @@ -190,7 +196,7 @@ int main(int argc, char *argv[]) ::usleep(1000); } - MainWindow w; + MainWindow w(display, nullptr); a.setActivationWindow(&w); w.setProperty("useStyleWindowManager", false); //禁用拖动 a.setWindowIcon(QIcon::fromTheme("kylin-network")); @@ -205,13 +211,8 @@ int main(int argc, char *argv[]) // w.setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint /*| Qt::X11BypassWindowManagerHint*/); - DbusAdaptor adaptor(&w); + DbusAdaptor adaptor(display, &w); Q_UNUSED(adaptor); - auto connection = QDBusConnection::sessionBus(); - if (!connection.registerService("com.kylin.network") || !connection.registerObject("/com/kylin/network", &w)) { - qCritical() << "QDbus register service failed reason:" << connection.lastError(); - } - return a.exec(); }