!1 适配应用管理接口

This commit is contained in:
iaom 2022-06-23 06:22:13 +00:00 committed by cckylin-cibot
parent e28faf1a2c
commit 4c26f6e7ac
2 changed files with 310 additions and 0 deletions

309
debian/patches/0001-1.patch vendored Normal file
View File

@ -0,0 +1,309 @@
From: cckylin-cibot <cckylin-cibot@kylinos.cn>
Date: Thu, 23 Jun 2022 06:22:13 +0000
Subject: =?utf-8?b?ITEg6YCC6YWN5bqU55So566h55CG5o6l5Y+j?=
---
frontend/view/web-search-view.cpp | 25 +++++++++++
libsearch/appsearch/app-search-plugin.cpp | 51 +++++++++++++++++++++-
libsearch/file-utils.cpp | 28 +++++++++++-
libsearch/notesearch/note-search-plugin.cpp | 28 +++++++++++-
libsearch/settingsearch/settings-search-plugin.cpp | 31 ++++++++++++-
libsearch/websearch/web-search-plugin.cpp | 25 +++++++++++
6 files changed, 183 insertions(+), 5 deletions(-)
diff --git a/frontend/view/web-search-view.cpp b/frontend/view/web-search-view.cpp
index 7be0bea..3c05f71 100644
--- a/frontend/view/web-search-view.cpp
+++ b/frontend/view/web-search-view.cpp
@@ -18,6 +18,7 @@
* Authors: jixiaoxu <jixiaoxu@kylinos.cn>
*
*/
+#include <QDBusReply>
#include "web-search-view.h"
#define MAIN_MARGINS 0,0,0,0
#define MAIN_SPACING 0
@@ -97,6 +98,30 @@ void WebSearchView::LaunchBrowser()
} else { //默认值
address = "http://baidu.com/s?word=" + m_keyWord ; //百度
}
+ bool res(false);
+ QDBusInterface * appLaunchInterface = new QDBusInterface("com.kylin.AppManager",
+ "/com/kylin/AppManager",
+ "com.kylin.AppManager",
+ QDBusConnection::sessionBus());
+ if(!appLaunchInterface->isValid()) {
+ qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message());
+ res = false;
+ } else {
+ appLaunchInterface->setTimeout(10000);
+ QDBusReply<bool> reply = appLaunchInterface->call("LaunchDefaultAppWithUrl", address);
+ if(reply.isValid()) {
+ res = reply;
+ } else {
+ qWarning() << "SoftWareCenter dbus called failed!";
+ res = false;
+ }
+ }
+ if(appLaunchInterface) {
+ delete appLaunchInterface;
+ }
+ appLaunchInterface = NULL;
+ if (res)
+ return;
QDesktopServices::openUrl(address);
}
diff --git a/libsearch/appsearch/app-search-plugin.cpp b/libsearch/appsearch/app-search-plugin.cpp
index a52ebf0..9484b46 100644
--- a/libsearch/appsearch/app-search-plugin.cpp
+++ b/libsearch/appsearch/app-search-plugin.cpp
@@ -218,8 +218,33 @@ void AppSearchPlugin::initDetailPage()
bool AppSearchPlugin::launch(const QString &path)
{
+ bool res(false);
+ QDBusInterface * appLaunchInterface = new QDBusInterface("com.kylin.AppManager",
+ "/com/kylin/AppManager",
+ "com.kylin.AppManager",
+ QDBusConnection::sessionBus());
+ if(!appLaunchInterface->isValid()) {
+ qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message());
+ res = false;
+ } else {
+ appLaunchInterface->setTimeout(10000);
+ QDBusReply<bool> reply = appLaunchInterface->call("LaunchApp", path);
+ if(reply.isValid()) {
+ res = reply;
+ } else {
+ qWarning() << "SoftWareCenter dbus called failed!";
+ res = false;
+ }
+ }
+ if(appLaunchInterface) {
+ delete appLaunchInterface;
+ }
+ appLaunchInterface = NULL;
+ if (res)
+ return true;
+
GDesktopAppInfo * desktopAppInfo = g_desktop_app_info_new_from_filename(path.toLocal8Bit().data());
- bool res = static_cast<bool>(g_app_info_launch(G_APP_INFO(desktopAppInfo), nullptr, nullptr, nullptr));
+ res = static_cast<bool>(g_app_info_launch(G_APP_INFO(desktopAppInfo), nullptr, nullptr, nullptr));
g_object_unref(desktopAppInfo);
return res;
}
@@ -270,6 +295,30 @@ bool AppSearchPlugin::installAppAction(const QString & name) {
} else {
//软件商店未打开,打开软件商店下载此软件
qDebug() << "Softwarecenter has not been launched, now launch it." << name;
+ bool res(false);
+ QDBusInterface * appLaunchInterface = new QDBusInterface("com.kylin.AppManager",
+ "/com/kylin/AppManager",
+ "com.kylin.AppManager",
+ QDBusConnection::sessionBus());
+ if(!appLaunchInterface->isValid()) {
+ qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message());
+ res = false;
+ } else {
+ appLaunchInterface->setTimeout(10000);
+ QDBusReply<bool> reply = appLaunchInterface->call("LaunchAppWithArguments", "kylin-software-center.desktop", QStringList() << "-find" << name);
+ if(reply.isValid()) {
+ res = reply;
+ } else {
+ qWarning() << "SoftWareCenter dbus called failed!";
+ res = false;
+ }
+ }
+ if(appLaunchInterface) {
+ delete appLaunchInterface;
+ }
+ appLaunchInterface = NULL;
+ if (res)
+ return true;
QProcess process;
return process.startDetached(QString("kylin-software-center -find %1").arg(name));
}
diff --git a/libsearch/file-utils.cpp b/libsearch/file-utils.cpp
index ef6640d..262d032 100644
--- a/libsearch/file-utils.cpp
+++ b/libsearch/file-utils.cpp
@@ -26,6 +26,8 @@
#include <QDBusMessage>
#include <QDBusConnection>
#include <QDomDocument>
+#include <QDBusInterface>
+#include <QDBusReply>
#include "gobject-template.h"
#include "pinyinmanager.h"
@@ -829,7 +831,31 @@ int FileUtils::openFile(QString &path, bool openInDir)
if(!G_IS_APP_INFO(info)) {
res = -1;
} else {
- QDesktopServices::openUrl(QUrl::fromLocalFile(path));
+ bool isSuccess(false);
+ QDBusInterface * appLaunchInterface = new QDBusInterface("com.kylin.AppManager",
+ "/com/kylin/AppManager",
+ "com.kylin.AppManager",
+ QDBusConnection::sessionBus());
+ if(!appLaunchInterface->isValid()) {
+ qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message());
+ isSuccess = false;
+ } else {
+ appLaunchInterface->setTimeout(10000);
+ QDBusReply<bool> reply = appLaunchInterface->call("LaunchDefaultAppWithUrl", QUrl::fromLocalFile(path));
+ if(reply.isValid()) {
+ isSuccess = reply;
+ } else {
+ qWarning() << "SoftWareCenter dbus called failed!";
+ isSuccess = false;
+ }
+ }
+ if(appLaunchInterface) {
+ delete appLaunchInterface;
+ }
+ appLaunchInterface = NULL;
+ if (!isSuccess){
+ QDesktopServices::openUrl(QUrl::fromLocalFile(path));
+ }
res = 0;
}
g_object_unref(info);
diff --git a/libsearch/notesearch/note-search-plugin.cpp b/libsearch/notesearch/note-search-plugin.cpp
index caee694..5173bd2 100644
--- a/libsearch/notesearch/note-search-plugin.cpp
+++ b/libsearch/notesearch/note-search-plugin.cpp
@@ -55,11 +55,37 @@ QList<SearchPluginIface::Actioninfo> NoteSearchPlugin::getActioninfo(int type)
void NoteSearchPlugin::openAction(int actionkey, QString key, int type)
{
- QProcess process;
switch (actionkey) {
case 0:
+ {
+ bool res(false);
+ QDBusInterface * appLaunchInterface = new QDBusInterface("com.kylin.AppManager",
+ "/com/kylin/AppManager",
+ "com.kylin.AppManager",
+ QDBusConnection::sessionBus());
+ if(!appLaunchInterface->isValid()) {
+ qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message());
+ res = false;
+ } else {
+ appLaunchInterface->setTimeout(10000);
+ QDBusReply<bool> reply = appLaunchInterface->call("LaunchAppWithArguments", "ukui-notebook.desktop", QStringList() << "--show" << key);
+ if(reply.isValid()) {
+ res = reply;
+ } else {
+ qWarning() << "SoftWareCenter dbus called failed!";
+ res = false;
+ }
+ }
+ if(appLaunchInterface) {
+ delete appLaunchInterface;
+ }
+ appLaunchInterface = NULL;
+ if (res)
+ break;
+ QProcess process;
process.startDetached(QString("ukui-notebook --show %1").arg(key.toInt()));
break;
+ }
default:
break;
}
diff --git a/libsearch/settingsearch/settings-search-plugin.cpp b/libsearch/settingsearch/settings-search-plugin.cpp
index a4018f3..9afb472 100644
--- a/libsearch/settingsearch/settings-search-plugin.cpp
+++ b/libsearch/settingsearch/settings-search-plugin.cpp
@@ -2,6 +2,8 @@
#include <QDomDocument>
#include <QProcessEnvironment>
#include <QWidget>
+#include <QDBusInterface>
+#include <QDBusReply>
#include "settings-search-plugin.h"
#include "file-utils.h"
@@ -59,13 +61,38 @@ QList<SearchPluginIface::Actioninfo> SettingsSearchPlugin::getActioninfo(int typ
void SettingsSearchPlugin::openAction(int actionkey, QString key, int type)
{
//TODO add some return message here.
- QProcess process;
switch (actionkey) {
case 0:
+ {
+ bool res(false);
+ QDBusInterface * appLaunchInterface = new QDBusInterface("com.kylin.AppManager",
+ "/com/kylin/AppManager",
+ "com.kylin.AppManager",
+ QDBusConnection::sessionBus());
+ if(!appLaunchInterface->isValid()) {
+ qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message());
+ res = false;
+ } else {
+ appLaunchInterface->setTimeout(10000);
+ QDBusReply<bool> reply = appLaunchInterface->call("LaunchAppWithArguments", "ukui-control-center.desktop", QStringList() << "-m" << key.toLower());
+ if(reply.isValid()) {
+ res = reply;
+ } else {
+ qWarning() << "SoftWareCenter dbus called failed!";
+ res = false;
+ }
+ }
+ if(appLaunchInterface) {
+ delete appLaunchInterface;
+ }
+ appLaunchInterface = NULL;
+ if (res)
+ break;
//打开控制面板对应页面
+ QProcess process;
process.startDetached(QString("ukui-control-center -m %1").arg(key.toLower()));
break;
-
+ }
default:
break;
}
diff --git a/libsearch/websearch/web-search-plugin.cpp b/libsearch/websearch/web-search-plugin.cpp
index 347d18c..925d9c0 100644
--- a/libsearch/websearch/web-search-plugin.cpp
+++ b/libsearch/websearch/web-search-plugin.cpp
@@ -1,3 +1,4 @@
+#include <QDBusReply>
#include "web-search-plugin.h"
#include "global-settings.h"
#define WEB_ENGINE_KEY "webEngine"
@@ -75,6 +76,30 @@ void UkuiSearch::WebSearchPlugin::openAction(int actionkey, QString key, int typ
} else { //默认值
address = "http://baidu.com/s?word=" + m_keyWord ; //百度
}
+ bool res(false);
+ QDBusInterface * appLaunchInterface = new QDBusInterface("com.kylin.AppManager",
+ "/com/kylin/AppManager",
+ "com.kylin.AppManager",
+ QDBusConnection::sessionBus());
+ if(!appLaunchInterface->isValid()) {
+ qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message());
+ res = false;
+ } else {
+ appLaunchInterface->setTimeout(10000);
+ QDBusReply<bool> reply = appLaunchInterface->call("LaunchDefaultAppWithUrl", address);
+ if(reply.isValid()) {
+ res = reply;
+ } else {
+ qWarning() << "SoftWareCenter dbus called failed!";
+ res = false;
+ }
+ }
+ if(appLaunchInterface) {
+ delete appLaunchInterface;
+ }
+ appLaunchInterface = NULL;
+ if (res)
+ return;
QDesktopServices::openUrl(address);
}

1
debian/patches/series vendored Normal file
View File

@ -0,0 +1 @@
0001-1.patch