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 * */ +#include #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 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 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(g_app_info_launch(G_APP_INFO(desktopAppInfo), nullptr, nullptr, nullptr)); + res = static_cast(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 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 #include #include +#include +#include #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 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 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 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 #include #include +#include +#include #include "settings-search-plugin.h" #include "file-utils.h" @@ -59,13 +61,38 @@ QList 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 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 #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 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); }