mirror of
https://gitee.com/spark-store-project/spark-store
synced 2025-12-14 04:42:03 +08:00
添加dbus功能
This commit is contained in:
12
src/dbus/dbussparkstoreservice.cpp
Normal file
12
src/dbus/dbussparkstoreservice.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#include "dbussparkstoreservice.h"
|
||||
#include <QDebug>
|
||||
DBusSparkStoreService::DBusSparkStoreService(QObject *parent)
|
||||
: QDBusAbstractAdaptor(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void DBusSparkStoreService::activeWindow(const QString & arg)
|
||||
{
|
||||
emit sigOpenUrl(arg);
|
||||
}
|
||||
24
src/dbus/dbussparkstoreservice.h
Normal file
24
src/dbus/dbussparkstoreservice.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef DBUSSPARKSTORESERVICE_H
|
||||
#define DBUSSPARKSTORESERVICE_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QUrl>
|
||||
#include <QtDBus/QtDBus>
|
||||
|
||||
class Wallpaper;
|
||||
class DBusSparkStoreService : public QDBusAbstractAdaptor
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_CLASSINFO("D-Bus Interface", "com.gitee.spark.store")
|
||||
public:
|
||||
explicit DBusSparkStoreService(QObject *parent);
|
||||
|
||||
signals :
|
||||
void sigOpenUrl(const QString &url);
|
||||
|
||||
public Q_SLOTS:
|
||||
void activeWindow(const QString &arg);
|
||||
|
||||
};
|
||||
|
||||
#endif // DBUSSPARKSTORESERVICE_H
|
||||
@@ -196,6 +196,8 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
openUrl(spk);
|
||||
});
|
||||
emit DGuiApplicationHelper::instance()->themeTypeChanged(DGuiApplicationHelper::instance()->themeType());
|
||||
|
||||
initDbus();
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
@@ -205,6 +207,24 @@ MainWindow::~MainWindow()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void MainWindow::initDbus()
|
||||
{
|
||||
DBusSparkStoreService *dbusInter = new DBusSparkStoreService(this);
|
||||
|
||||
QDBusConnection::sessionBus().registerService("com.gitee.spark.store");
|
||||
QDBusConnection::sessionBus().registerObject("/com/gitee/spark/store", "com.gitee.spark.store", this);
|
||||
connect(dbusInter,&DBusSparkStoreService::sigOpenUrl,this,&MainWindow::onGetUrl);
|
||||
}
|
||||
|
||||
void MainWindow::onGetUrl(const QString &url)
|
||||
{
|
||||
if(url.left(6)=="spk://")
|
||||
{
|
||||
openUrl(QUrl(url));
|
||||
}
|
||||
activateWindow();
|
||||
}
|
||||
|
||||
void MainWindow::openUrl(QUrl url)
|
||||
{
|
||||
if (url.toString().startsWith("spk://")) {
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
#include "widgets/downloadlistwidget.h"
|
||||
#include "utils/widgetanimation.h"
|
||||
#include "dbus/dbussparkstoreservice.h"
|
||||
|
||||
DWIDGET_USE_NAMESPACE
|
||||
|
||||
@@ -32,6 +33,7 @@ public:
|
||||
void openUrl(QUrl);
|
||||
|
||||
private:
|
||||
void initDbus();
|
||||
void initConfig();
|
||||
void switchPage(int now);
|
||||
void updateUi(int now);
|
||||
@@ -44,6 +46,10 @@ private:
|
||||
QPushButton *backButtom;
|
||||
DSearchEdit *searchEdit = new DSearchEdit;
|
||||
Ui::MainWindow *ui;
|
||||
|
||||
private slots:
|
||||
//接受来自dbus的url
|
||||
void onGetUrl(const QString &url);
|
||||
};
|
||||
|
||||
#endif // MAINWINDOWDTK_H
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
QT += core gui network concurrent webenginewidgets
|
||||
QT += core gui network concurrent webenginewidgets dbus
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
|
||||
@@ -31,6 +31,7 @@ PKGCONFIG += dtkcore dtkgui dtkwidget libnotify
|
||||
CONFIG(release, debug|release): DEFINES += QT_NO_WARNING_OUTPUT QT_NO_DEBUG_OUTPUT
|
||||
|
||||
SOURCES += \
|
||||
dbus/dbussparkstoreservice.cpp \
|
||||
main.cpp \
|
||||
mainwindow-dtk.cpp \
|
||||
backend/sparkapi.cpp \
|
||||
@@ -50,6 +51,7 @@ SOURCES += \
|
||||
backend/image_show.cpp
|
||||
|
||||
HEADERS += \
|
||||
dbus/dbussparkstoreservice.h \
|
||||
mainwindow-dtk.h \
|
||||
backend/sparkapi.h \
|
||||
pages/settingspage.h \
|
||||
|
||||
Reference in New Issue
Block a user