Use dbus to realize single case

This commit is contained in:
chenlelin 2021-01-09 16:58:44 +08:00
parent 95f13cf087
commit c5f5969e7e
6 changed files with 118 additions and 2 deletions

View File

@ -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 \

43
src/dbusadaptor.cpp Normal file
View File

@ -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 <QtCore/QMetaObject>
#include <QtCore/QByteArray>
#include <QtCore/QList>
#include <QtCore/QMap>
#include <QtCore/QString>
#include <QtCore/QStringList>
#include <QtCore/QVariant>
/*
* 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();
}

54
src/dbusadaptor.h Normal file
View File

@ -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 <QtCore/QObject>
#include <QtDBus/QtDBus>
QT_BEGIN_NAMESPACE
class QByteArray;
template<class T> class QList;
template<class Key, class Value> 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", ""
" <interface name=\"com.kylin.network\">\n"
" <method name=\"showMainWindow\"/>\n"
" </interface>\n"
"")
public:
DbusAdaptor(MainWindow *parent);
virtual ~DbusAdaptor();
inline MainWindow *parent() const
{ return static_cast<MainWindow *>(QObject::parent()); }
public: // PROPERTIES
public Q_SLOTS: // METHODS
void showMainWindow();
Q_SIGNALS: // SIGNALS
};
#endif

View File

@ -20,6 +20,7 @@
#include "ksimplenm.h"
#include "kylin-network-interface.h"
#include "wireless-security/dlghidewifi.h"
#include "dbusadaptor.h"
#include <QTranslator>
#include <QLocale>
@ -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();
}

View File

@ -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");

View File

@ -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();