Merge pull request !128 from depend/dev
This commit is contained in:
shenmo 2022-10-15 12:03:18 +00:00 committed by Gitee
commit 43ae031131
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
6 changed files with 81 additions and 2 deletions

View File

@ -0,0 +1,12 @@
#include "dbussparkstore.h"
#include <QDebug>
DBusSparkStoreService::DBusSparkStoreService(QObject *parent)
: QDBusAbstractAdaptor(parent)
{
}
void DBusSparkStoreService::activeWindow(const QString & arg)
{
emit sigOpenUrl(arg);
}

24
src/dbus/dbussparkstore.h Normal file
View File

@ -0,0 +1,24 @@
#ifndef DBUSSPARKSTORE_H
#define DBUSSPARKSTORE_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 // DBUSSPARKSTORE_H

View File

@ -4,6 +4,9 @@
#include <DAboutDialog>
#include <QVector>
#include <QScreen>
//新增dbus
#include <QDBusInterface>
#include <QDBusPendingCall>
#include "widget.h"
@ -69,6 +72,17 @@ int main(int argc, char *argv[])
// 限制单实例运行
if(!a.setSingleInstance("spark-store"))
{
qDebug() << "The application is already running!";
QDBusInterface iface("com.gitee.spark.store",
"/com/gitee/spark/store",
"com.gitee.spark.store",
QDBusConnection::sessionBus());
QString arg1 = argv[1];
iface.asyncCall("activeWindow",arg1);
return -1;
}

View File

@ -8,6 +8,7 @@ QT += core gui network concurrent webenginewidgets
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
QT += dbus
TARGET = spark-store
TEMPLATE = app
@ -41,7 +42,8 @@ SOURCES += \
main.cpp \
progressload.cpp \
widget.cpp \
workerthreads.cpp
workerthreads.cpp \
dbus/dbussparkstore.cpp
HEADERS += \
appitem.h \
@ -52,7 +54,8 @@ HEADERS += \
image_show.h \
progressload.h \
widget.h \
workerthreads.h
workerthreads.h \
dbus/dbussparkstore.h
FORMS += \
appitem.ui \

View File

@ -33,6 +33,7 @@
#include "HttpClient.h"
#include "downloadworker.h"
#include "./dbus/dbussparkstore.h"
DWIDGET_USE_NAMESPACE
Widget::Widget(DBlurEffectWidget *parent) :
@ -138,6 +139,9 @@ Widget::Widget(DBlurEffectWidget *parent) :
});
notify_init(tr("Spark\\ Store").toLocal8Bit());
//初始化dbus服务
initDbus();
}
Widget::~Widget()
@ -452,6 +456,15 @@ void Widget::sendNotification(const char *message, const int msTimeout, const QS
notify_notification_show(_notify, nullptr);
}
void Widget::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,&Widget::onGetUrl);
}
void Widget::updateUI()
{
if(themeIsDark)
@ -1354,3 +1367,12 @@ void Widget::on_pushButton_update_clicked()
QDesktopServices::openUrl(QUrl("https://www.deepinos.org/"));
}
void Widget::onGetUrl(const QString &url)
{
if(url.left(6)=="spk://")
{
openUrl(QUrl(url));
}
activateWindow();
}

View File

@ -64,6 +64,7 @@ public:
static void sendNotification(const QString &message, const int msTimeout = 5000, const QString &icon = "spark-store");
static void sendNotification(const char *message, const int msTimeout = 5000, const QString &icon = "spark-store");
void initDbus();
private slots:
void httpFinished();
@ -103,6 +104,9 @@ private slots:
void on_pushButton_refresh_clicked();
void on_pushButton_update_clicked();
//接受来自dbus的url
void onGetUrl(const QString &url);
public:
QUrl url;
QString cdnSeverUrl;