From c5f5969e7e18c02ad8efe5ebad5aeccec7db6199 Mon Sep 17 00:00:00 2001 From: chenlelin Date: Sat, 9 Jan 2021 16:58:44 +0800 Subject: [PATCH] Use dbus to realize single case --- kylin-nm.pro | 2 ++ src/dbusadaptor.cpp | 43 ++++++++++++++++++++++++++++++++++++ src/dbusadaptor.h | 54 +++++++++++++++++++++++++++++++++++++++++++++ src/main.cpp | 16 ++++++++++++++ src/mainwindow.cpp | 2 +- src/mainwindow.h | 3 ++- 6 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 src/dbusadaptor.cpp create mode 100644 src/dbusadaptor.h diff --git a/kylin-nm.pro b/kylin-nm.pro index 343cbbb1..98fb148a 100644 --- a/kylin-nm.pro +++ b/kylin-nm.pro @@ -56,6 +56,7 @@ QMAKE_LFLAGS *= $(shell dpkg-buildflags --get LDFLAGS) SOURCES += \ src/backthread.cpp \ src/confform.cpp \ + src/dbusadaptor.cpp \ src/ksimplenm.cpp \ src/kylin-dbus-interface.cpp \ src/kylin-network-interface.c \ @@ -85,6 +86,7 @@ SOURCES += \ HEADERS += \ src/backthread.h \ src/confform.h \ + src/dbusadaptor.h \ src/ksimplenm.h \ src/kylin-dbus-interface.h \ src/kylin-network-interface.h \ diff --git a/src/dbusadaptor.cpp b/src/dbusadaptor.cpp new file mode 100644 index 00000000..66d67a5e --- /dev/null +++ b/src/dbusadaptor.cpp @@ -0,0 +1,43 @@ +/* + * 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 + +/* + * Implementation of adaptor class DbusAdaptor + */ + +DbusAdaptor::DbusAdaptor(MainWindow *parent) + : QDBusAbstractAdaptor(parent) +{ + // constructor + setAutoRelaySignals(true); +} + +DbusAdaptor::~DbusAdaptor() +{ + // destructor +} + +void DbusAdaptor::showMainWindow() +{ + // handle method call com.kylin.weather.showMainWindow + //edited the code manually by lixiang + //parent()->handleIconClicked(); + parent()->on_showWindowAction(); +} + diff --git a/src/dbusadaptor.h b/src/dbusadaptor.h new file mode 100644 index 00000000..3c547575 --- /dev/null +++ b/src/dbusadaptor.h @@ -0,0 +1,54 @@ +/* + * 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. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#ifndef DBUSADAPTOR_H +#define DBUSADAPTOR_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.weather + */ + +#include "mainwindow.h"//added the code manually by lixiang + +class DbusAdaptor: public QDBusAbstractAdaptor +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "com.kylin.network") + Q_CLASSINFO("D-Bus Introspection", "" +" \n" +" \n" +" \n" + "") +public: + DbusAdaptor(MainWindow *parent); + virtual ~DbusAdaptor(); + + inline MainWindow *parent() const + { return static_cast(QObject::parent()); } + +public: // PROPERTIES +public Q_SLOTS: // METHODS + void showMainWindow(); +Q_SIGNALS: // SIGNALS +}; + +#endif diff --git a/src/main.cpp b/src/main.cpp index 3e60989e..193973c1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -20,6 +20,7 @@ #include "ksimplenm.h" #include "kylin-network-interface.h" #include "wireless-security/dlghidewifi.h" +#include "dbusadaptor.h" #include #include @@ -56,5 +57,20 @@ int main(int argc, char *argv[]) } MainWindow w; + + DbusAdaptor adaptor(&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(); + QDBusInterface iface("com.kylin.network", + "/com/kylin/network", + "com.kylin.network", + connection); + iface.call("showMainWindow"); + + return 0; + } + return a.exec(); } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 67928d01..bfb9937e 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -38,7 +38,7 @@ MainWindow::MainWindow(QWidget *parent) : { ui->setupUi(this); - checkSingle(); + //checkSingle(); syslog(LOG_DEBUG, "Using the icon theme named 'ukui-icon-theme-default'"); QIcon::setThemeName("ukui-icon-theme-default"); diff --git a/src/mainwindow.h b/src/mainwindow.h index 535e8a2a..74ea7902 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -189,6 +189,8 @@ public slots: //flag =0或1为普通点击、2为收到打开信息、3为收到关闭信息、4为无线网卡插入、5为无线网卡拔出 void onBtnWifiClicked(int flag = 0); + void on_showWindowAction(); + protected: bool eventFilter(QObject *obj, QEvent *event); void paintEvent(QPaintEvent *event); @@ -294,7 +296,6 @@ private slots: QString TranslateLanName(QString lanName); QString getMacByUuid(QString uuidName); - void on_showWindowAction(); void on_btnAdvConf_clicked(); void activeLanDisconn();