2023-04-11 10:19:35 +08:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Copyright (C) 2023, KylinSoft Co., Ltd.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Authors: iaom <zhangpengfei@kylinos.cn>
|
|
|
|
*/
|
2021-06-17 14:08:55 +08:00
|
|
|
#include "app-search-plugin.h"
|
|
|
|
#include <gio/gdesktopappinfo.h>
|
2021-07-08 18:53:16 +08:00
|
|
|
#include <QWidget>
|
|
|
|
#include <QLabel>
|
2023-05-06 15:41:56 +08:00
|
|
|
#include <QDeadlineTimer>
|
2021-07-31 16:12:04 +08:00
|
|
|
#include "file-utils.h"
|
2023-11-01 10:56:16 +08:00
|
|
|
#include "data-collecter.h"
|
2021-12-14 14:43:35 +08:00
|
|
|
using namespace UkuiSearch;
|
2023-01-17 17:49:07 +08:00
|
|
|
|
2022-06-23 10:13:58 +08:00
|
|
|
AppSearchPlugin::AppSearchPlugin(QObject *parent) : QThread(parent), m_appSearchTask(new UkuiSearchTask(this))
|
2021-06-17 14:08:55 +08:00
|
|
|
{
|
|
|
|
SearchPluginIface::Actioninfo open { 0, tr("Open")};
|
|
|
|
SearchPluginIface::Actioninfo addtoDesktop { 1, tr("Add Shortcut to Desktop")};
|
|
|
|
SearchPluginIface::Actioninfo addtoPanel { 2, tr("Add Shortcut to Panel")};
|
|
|
|
SearchPluginIface::Actioninfo install { 0, tr("Install")};
|
|
|
|
m_actionInfo_installed << open << addtoDesktop << addtoPanel;
|
|
|
|
m_actionInfo_not_installed << install;
|
2022-06-23 10:13:58 +08:00
|
|
|
// m_pool.setMaxThreadCount(1);
|
|
|
|
// m_pool.setExpiryTimeout(1000);
|
2021-07-31 16:12:04 +08:00
|
|
|
initDetailPage();
|
2022-06-13 13:38:47 +08:00
|
|
|
m_appSearchResults = m_appSearchTask->init();
|
2023-03-15 16:39:38 +08:00
|
|
|
m_appSearchTask->initSearchPlugin(SearchProperty::SearchType::Application);
|
2022-06-13 13:38:47 +08:00
|
|
|
m_appSearchTask->setSearchOnlineApps(true);
|
2023-03-15 16:39:38 +08:00
|
|
|
m_appSearchTask->setResultProperties(SearchProperty::SearchType::Application,
|
|
|
|
SearchResultProperties{SearchProperty::SearchResultProperty::ApplicationDesktopPath,
|
|
|
|
SearchProperty::SearchResultProperty::ApplicationLocalName,
|
|
|
|
SearchProperty::SearchResultProperty::ApplicationIconName,
|
|
|
|
SearchProperty::SearchResultProperty::ApplicationDescription,
|
2023-05-05 17:24:05 +08:00
|
|
|
SearchProperty::SearchResultProperty::IsOnlineApplication,
|
|
|
|
SearchProperty::SearchResultProperty::ApplicationPkgName});
|
2021-06-17 14:08:55 +08:00
|
|
|
}
|
|
|
|
|
2022-11-22 10:17:36 +08:00
|
|
|
AppSearchPlugin::~AppSearchPlugin()
|
|
|
|
{
|
|
|
|
this->wait();
|
|
|
|
}
|
|
|
|
|
2021-06-17 14:08:55 +08:00
|
|
|
const QString AppSearchPlugin::name()
|
|
|
|
{
|
2021-10-27 11:37:55 +08:00
|
|
|
return "Applications Search";
|
2021-06-17 14:08:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const QString AppSearchPlugin::description()
|
|
|
|
{
|
|
|
|
return tr("Applications Search");
|
|
|
|
}
|
|
|
|
|
|
|
|
QString AppSearchPlugin::getPluginName()
|
|
|
|
{
|
|
|
|
return tr("Applications Search");
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppSearchPlugin::KeywordSearch(QString keyword, DataQueue<SearchPluginIface::ResultInfo> *searchResult)
|
|
|
|
{
|
2022-06-23 10:13:58 +08:00
|
|
|
if (!this->isRunning()) {
|
|
|
|
this->start();
|
|
|
|
}
|
|
|
|
m_searchResult = searchResult;
|
|
|
|
m_appSearchTask->clearKeyWords();
|
|
|
|
m_appSearchTask->addKeyword(keyword);
|
2023-03-15 16:39:38 +08:00
|
|
|
m_appSearchTask->startSearch(SearchProperty::SearchType::Application);
|
2022-06-23 10:13:58 +08:00
|
|
|
|
|
|
|
// AppSearch *appsearch = new AppSearch(searchResult, m_appSearchResults, m_appSearchTask, keyword, uniqueSymbol);
|
|
|
|
// m_pool.start(appsearch);
|
2021-06-17 14:08:55 +08:00
|
|
|
}
|
|
|
|
|
2022-02-12 14:20:55 +08:00
|
|
|
void AppSearchPlugin::stopSearch()
|
|
|
|
{
|
2023-01-17 17:49:07 +08:00
|
|
|
m_appSearchTask->stop();
|
2023-07-20 16:42:29 +08:00
|
|
|
this->requestInterruption();
|
|
|
|
this->wait();
|
2022-02-12 14:20:55 +08:00
|
|
|
}
|
|
|
|
|
2021-06-17 14:08:55 +08:00
|
|
|
QList<SearchPluginIface::Actioninfo> AppSearchPlugin::getActioninfo(int type)
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case 0:
|
|
|
|
return m_actionInfo_installed;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
return m_actionInfo_not_installed;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return QList<SearchPluginIface::Actioninfo>();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppSearchPlugin::openAction(int actionkey, QString key, int type)
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case 0:
|
|
|
|
switch (actionkey) {
|
|
|
|
case 0:
|
|
|
|
if(!launch(key)) {
|
|
|
|
qWarning() << "Fail to launch:" << key;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if(!addDesktopShortcut(key)) {
|
|
|
|
qWarning() << "Fail to add Desktop Shortcut:" << key;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if(!addPanelShortcut(key)) {
|
|
|
|
qWarning() << "Fail to add Panel Shortcut:" << key;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if(!installAppAction(key)) {
|
|
|
|
qWarning() << "Fail to install:" << key;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-31 16:12:04 +08:00
|
|
|
QWidget *AppSearchPlugin::detailPage(const ResultInfo &ri)
|
2021-07-08 18:53:16 +08:00
|
|
|
{
|
2021-07-31 16:12:04 +08:00
|
|
|
m_currentActionKey = ri.actionKey;
|
2023-01-21 19:52:40 +08:00
|
|
|
m_iconLabel->setPixmap(ri.icon.isNull() ? QIcon(":/res/icons/unknown.svg").pixmap(120, 120) : ri.icon.pixmap(120, 120));
|
2021-07-31 16:12:04 +08:00
|
|
|
QFontMetrics fontMetrics = m_nameLabel->fontMetrics();
|
2021-08-10 17:50:50 +08:00
|
|
|
QString showname = fontMetrics.elidedText(ri.name, Qt::ElideRight, 215); //当字体长度超过215时显示为省略号
|
2021-12-17 17:39:37 +08:00
|
|
|
m_nameLabel->setText(FileUtils::setAllTextBold(showname));
|
2021-07-31 16:12:04 +08:00
|
|
|
if(QString::compare(showname, ri.name)) {
|
|
|
|
m_nameLabel->setToolTip(ri.name);
|
2022-02-16 17:12:48 +08:00
|
|
|
} else {
|
|
|
|
m_nameLabel->setToolTip("");
|
2021-07-31 16:12:04 +08:00
|
|
|
}
|
|
|
|
m_pluginLabel->setText(tr("Application"));
|
|
|
|
if(ri.type == 1) {
|
|
|
|
m_actionLabel1->hide();
|
|
|
|
m_actionLabel2->hide();
|
|
|
|
m_actionLabel3->hide();
|
|
|
|
m_actionLabel4->show();
|
2023-10-27 15:06:55 +08:00
|
|
|
// QString showDesc = fontMetrics.elidedText(ri.description.at(0).key + " " + ri.description.at(0).value, Qt::ElideRight, 3114); //当字体长度超过215时显示为省略号
|
|
|
|
QString showDesc = FileUtils::getSnippetWithoutKeyword(ri.description.at(0).key + " " + ri.description.at(0).value, 10);
|
2021-07-31 16:12:04 +08:00
|
|
|
m_descLabel->setText(FileUtils::escapeHtml(showDesc));
|
2023-10-30 16:10:47 +08:00
|
|
|
m_descLabel->show();
|
2021-07-31 16:12:04 +08:00
|
|
|
m_line_2->show();
|
|
|
|
|
|
|
|
} else {
|
2023-10-30 16:10:47 +08:00
|
|
|
m_descLabel->hide();
|
2021-07-31 16:12:04 +08:00
|
|
|
m_line_2->hide();
|
|
|
|
m_actionLabel1->show();
|
|
|
|
m_actionLabel2->show();
|
|
|
|
m_actionLabel3->show();
|
|
|
|
m_actionLabel4->hide();
|
|
|
|
}
|
|
|
|
return m_detailPage;
|
2021-07-08 18:53:16 +08:00
|
|
|
}
|
|
|
|
|
2022-06-23 10:13:58 +08:00
|
|
|
void AppSearchPlugin::run()
|
|
|
|
{
|
2023-07-20 16:42:29 +08:00
|
|
|
QDeadlineTimer deadline(25000);
|
2023-01-21 11:37:39 +08:00
|
|
|
while(!isInterruptionRequested()) {
|
|
|
|
ResultItem oneResult = m_appSearchResults->tryDequeue();
|
2023-03-15 16:39:38 +08:00
|
|
|
SearchResultPropertyMap data = oneResult.getAllValue();
|
|
|
|
if(oneResult.getSearchId() == 0 && oneResult.getItemKey().isEmpty() && data.isEmpty()) {
|
2023-05-06 15:41:56 +08:00
|
|
|
if(deadline.remainingTime()) {
|
|
|
|
msleep(100);
|
|
|
|
} else {
|
|
|
|
this->requestInterruption();
|
2023-01-17 17:49:07 +08:00
|
|
|
}
|
2023-05-06 15:41:56 +08:00
|
|
|
|
2023-01-17 17:49:07 +08:00
|
|
|
} else {
|
2023-07-20 16:42:29 +08:00
|
|
|
deadline.setRemainingTime(25000);
|
2023-01-17 17:49:07 +08:00
|
|
|
SearchPluginIface::ResultInfo ri;
|
2023-05-06 15:41:56 +08:00
|
|
|
|
2023-03-15 16:39:38 +08:00
|
|
|
ri.name = data.value(SearchProperty::SearchResultProperty::ApplicationLocalName).toString();
|
2023-11-06 16:50:56 +08:00
|
|
|
ri.icon = IconLoader::loadIconXdg(data.value(SearchProperty::SearchResultProperty::ApplicationIconName).toString(), QIcon(":/res/icons/unknown.svg"));
|
2023-01-17 17:49:07 +08:00
|
|
|
SearchPluginIface::DescriptionInfo description;
|
|
|
|
description.key = QString(tr("Application Description:"));
|
2023-03-15 16:39:38 +08:00
|
|
|
description.value = data.value(SearchProperty::SearchResultProperty::ApplicationDescription).toString();
|
2023-01-17 17:49:07 +08:00
|
|
|
ri.description.append(description);
|
2023-03-15 16:39:38 +08:00
|
|
|
ri.type = data.value(SearchProperty::SearchResultProperty::IsOnlineApplication).toInt();
|
2023-05-05 17:24:05 +08:00
|
|
|
if (ri.type == 1) {
|
|
|
|
ri.actionKey = data.value(SearchProperty::SearchResultProperty::ApplicationPkgName).toString();
|
2023-05-06 15:41:56 +08:00
|
|
|
} else {
|
|
|
|
ri.actionKey = data.value(SearchProperty::SearchResultProperty::ApplicationDesktopPath).toString();
|
2023-05-05 17:24:05 +08:00
|
|
|
}
|
2023-01-17 17:49:07 +08:00
|
|
|
m_searchResult->enqueue(ri);
|
|
|
|
}
|
|
|
|
}
|
2023-09-01 11:07:57 +08:00
|
|
|
m_appSearchResults->clear();
|
2022-06-23 10:13:58 +08:00
|
|
|
}
|
|
|
|
|
2021-07-31 16:12:04 +08:00
|
|
|
void AppSearchPlugin::initDetailPage()
|
2021-07-08 18:53:16 +08:00
|
|
|
{
|
2021-07-31 16:12:04 +08:00
|
|
|
m_detailPage = new QWidget();
|
|
|
|
m_detailPage->setFixedWidth(360);
|
|
|
|
m_detailPage->setAttribute(Qt::WA_TranslucentBackground);
|
|
|
|
m_detailLyt = new QVBoxLayout(m_detailPage);
|
|
|
|
m_detailLyt->setContentsMargins(8, 0, 16, 0);
|
|
|
|
m_iconLabel = new QLabel(m_detailPage);
|
|
|
|
m_iconLabel->setAlignment(Qt::AlignCenter);
|
|
|
|
m_iconLabel->setFixedHeight(128);
|
|
|
|
|
|
|
|
m_nameFrame = new QFrame(m_detailPage);
|
|
|
|
m_nameFrameLyt = new QHBoxLayout(m_nameFrame);
|
|
|
|
m_nameFrame->setLayout(m_nameFrameLyt);
|
|
|
|
m_nameFrameLyt->setContentsMargins(8, 0, 0, 0);
|
|
|
|
m_nameLabel = new QLabel(m_nameFrame);
|
|
|
|
m_nameLabel->setMaximumWidth(280);
|
|
|
|
m_pluginLabel = new QLabel(m_nameFrame);
|
|
|
|
m_pluginLabel->setEnabled(false);
|
|
|
|
m_nameFrameLyt->addWidget(m_nameLabel);
|
|
|
|
m_nameFrameLyt->addStretch();
|
|
|
|
m_nameFrameLyt->addWidget(m_pluginLabel);
|
|
|
|
|
2021-12-09 13:57:19 +08:00
|
|
|
m_line_1 = new SeparationLine(m_detailPage);
|
2023-10-30 16:10:47 +08:00
|
|
|
|
|
|
|
m_descLabel = new QLabel(m_detailPage);
|
2021-07-31 16:12:04 +08:00
|
|
|
m_descLabel->setTextFormat(Qt::PlainText);
|
2023-10-30 16:10:47 +08:00
|
|
|
m_descLabel->setContentsMargins(8, 0, 8, 0);
|
2023-10-27 15:06:55 +08:00
|
|
|
// m_descLabel->setWordWrap(true);
|
2021-12-09 13:57:19 +08:00
|
|
|
m_line_2 = new SeparationLine(m_detailPage);
|
2021-07-31 16:12:04 +08:00
|
|
|
|
|
|
|
m_actionFrame = new QFrame(m_detailPage);
|
|
|
|
m_actionFrameLyt = new QVBoxLayout(m_actionFrame);
|
|
|
|
m_actionFrameLyt->setContentsMargins(8, 0, 0, 0);
|
|
|
|
m_actionLabel1 = new ActionLabel(tr("Open"), m_currentActionKey, m_actionFrame);
|
|
|
|
m_actionLabel2 = new ActionLabel(tr("Add Shortcut to Desktop"), m_currentActionKey, m_actionFrame);
|
|
|
|
m_actionLabel3 = new ActionLabel(tr("Add Shortcut to Panel"), m_currentActionKey, m_actionFrame);
|
|
|
|
m_actionLabel4 = new ActionLabel(tr("Install"), m_currentActionKey, m_actionFrame);
|
|
|
|
|
|
|
|
m_actionFrameLyt->addWidget(m_actionLabel1);
|
|
|
|
m_actionFrameLyt->addWidget(m_actionLabel2);
|
|
|
|
m_actionFrameLyt->addWidget(m_actionLabel3);
|
|
|
|
m_actionFrameLyt->addWidget(m_actionLabel4);
|
|
|
|
m_actionFrame->setLayout(m_actionFrameLyt);
|
|
|
|
|
|
|
|
m_detailLyt->addSpacing(50);
|
|
|
|
m_detailLyt->addWidget(m_iconLabel);
|
|
|
|
m_detailLyt->addWidget(m_nameFrame);
|
|
|
|
m_detailLyt->addWidget(m_line_1);
|
2023-10-30 16:10:47 +08:00
|
|
|
m_detailLyt->addWidget(m_descLabel);
|
2021-07-31 16:12:04 +08:00
|
|
|
m_detailLyt->addWidget(m_line_2);
|
|
|
|
m_detailLyt->addWidget(m_actionFrame);
|
|
|
|
m_detailPage->setLayout(m_detailLyt);
|
|
|
|
m_detailLyt->addStretch();
|
|
|
|
|
|
|
|
connect(m_actionLabel1, &ActionLabel::actionTriggered, [ & ](){
|
|
|
|
launch(m_currentActionKey);
|
|
|
|
});
|
|
|
|
connect(m_actionLabel2, &ActionLabel::actionTriggered, [ & ](){
|
|
|
|
addDesktopShortcut(m_currentActionKey);
|
|
|
|
});
|
|
|
|
connect(m_actionLabel3, &ActionLabel::actionTriggered, [ & ](){
|
|
|
|
addPanelShortcut(m_currentActionKey);
|
|
|
|
});
|
|
|
|
connect(m_actionLabel4, &ActionLabel::actionTriggered, [ & ](){
|
|
|
|
installAppAction(m_currentActionKey);
|
|
|
|
});
|
2021-07-08 18:53:16 +08:00
|
|
|
}
|
|
|
|
|
2021-06-17 14:08:55 +08:00
|
|
|
bool AppSearchPlugin::launch(const QString &path)
|
|
|
|
{
|
2023-11-01 10:56:16 +08:00
|
|
|
DataCollecter::collectLaunchEvent(QStringLiteral("Applications Search"), QStringLiteral("launch"));
|
2022-11-02 20:50:30 +08:00
|
|
|
if(QFileInfo(path).fileName() == "kylin-screenshot.desktop") {
|
|
|
|
invokeActions(InvokableAction::HideUI);
|
|
|
|
}
|
2022-05-10 13:49:54 +08:00
|
|
|
bool res(false);
|
2023-11-14 14:39:14 +08:00
|
|
|
QDBusInterface * appLaunchInterface = new QDBusInterface(QStringLiteral("com.kylin.ProcessManager"),
|
|
|
|
QStringLiteral("/com/kylin/ProcessManager/AppLauncher"),
|
|
|
|
QStringLiteral("com.kylin.ProcessManager.AppLauncher"),
|
2022-05-10 13:49:54 +08:00
|
|
|
QDBusConnection::sessionBus());
|
|
|
|
if(!appLaunchInterface->isValid()) {
|
|
|
|
qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message());
|
|
|
|
res = false;
|
|
|
|
} else {
|
|
|
|
appLaunchInterface->setTimeout(10000);
|
2023-11-14 14:39:14 +08:00
|
|
|
QDBusReply<void> reply = appLaunchInterface->call("LaunchApp", path);
|
2022-05-10 13:49:54 +08:00
|
|
|
if(reply.isValid()) {
|
2023-11-14 14:39:14 +08:00
|
|
|
res = true;
|
2022-05-10 13:49:54 +08:00
|
|
|
} else {
|
2023-11-14 14:39:14 +08:00
|
|
|
qWarning() << "ProcessManager dbus called failed!" << reply.error();
|
2022-05-10 13:49:54 +08:00
|
|
|
res = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(appLaunchInterface) {
|
|
|
|
delete appLaunchInterface;
|
|
|
|
}
|
|
|
|
appLaunchInterface = NULL;
|
|
|
|
if (res)
|
|
|
|
return true;
|
|
|
|
|
2021-06-17 14:08:55 +08:00
|
|
|
GDesktopAppInfo * desktopAppInfo = g_desktop_app_info_new_from_filename(path.toLocal8Bit().data());
|
2022-05-10 13:49:54 +08:00
|
|
|
res = static_cast<bool>(g_app_info_launch(G_APP_INFO(desktopAppInfo), nullptr, nullptr, nullptr));
|
2021-06-17 14:08:55 +08:00
|
|
|
g_object_unref(desktopAppInfo);
|
|
|
|
return res;
|
|
|
|
}
|
2023-01-17 17:49:07 +08:00
|
|
|
|
2023-11-01 10:56:16 +08:00
|
|
|
bool AppSearchPlugin::addPanelShortcut(const QString& path)
|
|
|
|
{
|
|
|
|
DataCollecter::collectLaunchEvent(QStringLiteral("Applications Search"), QStringLiteral("addPanelShortcut"));
|
2021-06-17 14:08:55 +08:00
|
|
|
QDBusInterface iface("com.ukui.panel.desktop",
|
|
|
|
"/",
|
|
|
|
"com.ukui.panel.desktop",
|
|
|
|
QDBusConnection::sessionBus());
|
|
|
|
if(iface.isValid()) {
|
|
|
|
QDBusReply<bool> isExist = iface.call("CheckIfExist", path);
|
|
|
|
if(isExist) {
|
2021-07-05 14:27:14 +08:00
|
|
|
qWarning() << "Add shortcut to panel failed, because it is already existed!";
|
2021-06-17 14:08:55 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
QDBusReply<QVariant> ret = iface.call("AddToTaskbar", path);
|
2021-07-05 14:27:14 +08:00
|
|
|
qDebug() << "Add shortcut to panel successed!";
|
2021-06-17 14:08:55 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-11-01 10:56:16 +08:00
|
|
|
bool AppSearchPlugin::addDesktopShortcut(const QString& path)
|
|
|
|
{
|
|
|
|
DataCollecter::collectLaunchEvent(QStringLiteral("Applications Search"), QStringLiteral("addDesktopShortcut"));
|
2021-06-17 14:08:55 +08:00
|
|
|
QString dirpath = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
|
|
|
|
QFileInfo fileInfo(path);
|
|
|
|
QString desktopfn = fileInfo.fileName();
|
|
|
|
QFile file(path);
|
|
|
|
QString newName = QString(dirpath + "/" + desktopfn);
|
|
|
|
bool ret = file.copy(QString(dirpath + "/" + desktopfn));
|
|
|
|
if(ret) {
|
2023-04-24 14:07:56 +08:00
|
|
|
QProcess::startDetached("chmod", {"a+x", newName});
|
2021-06-17 14:08:55 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-11-01 10:56:16 +08:00
|
|
|
bool AppSearchPlugin::installAppAction(const QString & name)
|
|
|
|
{
|
|
|
|
DataCollecter::collectLaunchEvent(QStringLiteral("Applications Search"), QStringLiteral("installAppAction"));
|
2021-06-17 14:08:55 +08:00
|
|
|
QDBusInterface * interface = new QDBusInterface("com.kylin.softwarecenter",
|
|
|
|
"/com/kylin/softwarecenter",
|
|
|
|
"com.kylin.utiliface",
|
|
|
|
QDBusConnection::sessionBus());
|
2022-10-19 17:11:05 +08:00
|
|
|
bool res(false);
|
2021-06-17 14:08:55 +08:00
|
|
|
if(interface->isValid()) {
|
|
|
|
//软件商店已打开,直接跳转
|
|
|
|
interface->call("show_search_result", name);
|
2022-10-19 17:11:05 +08:00
|
|
|
res = QDBusReply<bool>(interface->call(QString("show_search_result"), name));
|
2021-06-17 14:08:55 +08:00
|
|
|
} else {
|
|
|
|
//软件商店未打开,打开软件商店下载此软件
|
|
|
|
qDebug() << "Softwarecenter has not been launched, now launch it." << name;
|
2023-11-14 14:39:14 +08:00
|
|
|
QDBusInterface * appLaunchInterface = new QDBusInterface(QStringLiteral("com.kylin.ProcessManager"),
|
|
|
|
QStringLiteral("/com/kylin/ProcessManager/AppLauncher"),
|
|
|
|
QStringLiteral("com.kylin.ProcessManager.AppLauncher"),
|
2022-05-10 13:49:54 +08:00
|
|
|
QDBusConnection::sessionBus());
|
|
|
|
if(!appLaunchInterface->isValid()) {
|
|
|
|
qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message());
|
|
|
|
res = false;
|
|
|
|
} else {
|
|
|
|
appLaunchInterface->setTimeout(10000);
|
2023-11-14 14:39:14 +08:00
|
|
|
QDBusReply<void> reply = appLaunchInterface->call("LaunchAppWithArguments", "/usr/share/applications/kylin-software-center.desktop", QStringList() << "-find" << name);
|
2022-05-10 13:49:54 +08:00
|
|
|
if(reply.isValid()) {
|
2023-11-14 14:39:14 +08:00
|
|
|
res = true;
|
2022-05-10 13:49:54 +08:00
|
|
|
} else {
|
2023-11-14 14:39:14 +08:00
|
|
|
qWarning() << "ProcessManager dbus called failed!" << reply.error();
|
2022-05-10 13:49:54 +08:00
|
|
|
res = false;
|
|
|
|
}
|
|
|
|
}
|
2023-11-14 14:39:14 +08:00
|
|
|
if (appLaunchInterface) {
|
2022-05-10 13:49:54 +08:00
|
|
|
delete appLaunchInterface;
|
|
|
|
}
|
2022-10-19 17:11:05 +08:00
|
|
|
appLaunchInterface = nullptr;
|
|
|
|
if (!res) {
|
2023-04-24 14:07:56 +08:00
|
|
|
res = QProcess::startDetached("kylin-software-center", {"-find", name});
|
2022-10-19 17:11:05 +08:00
|
|
|
}
|
|
|
|
}
|
2023-11-14 14:39:14 +08:00
|
|
|
if (interface) {
|
2022-10-19 17:11:05 +08:00
|
|
|
delete interface;
|
2021-06-17 14:08:55 +08:00
|
|
|
}
|
2022-10-19 17:11:05 +08:00
|
|
|
interface = nullptr;
|
|
|
|
return res;
|
2021-06-17 14:08:55 +08:00
|
|
|
}
|
|
|
|
|
2022-06-23 10:13:58 +08:00
|
|
|
//AppSearch::AppSearch(DataQueue<SearchPluginIface::ResultInfo> *searchResult, DataQueue<ResultItem>* appSearchResults, UkuiSearchTask *appSearchTask, QString keyword, size_t uniqueSymbol)
|
|
|
|
//{
|
|
|
|
// this->setAutoDelete(true);
|
|
|
|
// m_search_result = searchResult;
|
|
|
|
// m_appSearchResults = appSearchResults;
|
|
|
|
// m_appSearchTask = appSearchTask;
|
|
|
|
// m_appSearchTask->clearKeyWords();
|
|
|
|
// m_appSearchTask->addKeyword(keyword);
|
|
|
|
// m_uniqueSymbol = uniqueSymbol;
|
|
|
|
//}
|
2021-06-17 14:08:55 +08:00
|
|
|
|
2022-06-23 10:13:58 +08:00
|
|
|
//AppSearch::~AppSearch()
|
|
|
|
//{
|
|
|
|
//}
|
2021-06-17 14:08:55 +08:00
|
|
|
|
2022-06-23 10:13:58 +08:00
|
|
|
//void AppSearch::run()
|
|
|
|
//{
|
|
|
|
//// m_appSearchTask->startSearch(SearchType::Application);
|
|
|
|
// QTimer timer;
|
|
|
|
// timer.setInterval(3000);
|
|
|
|
// bool is_empty;
|
|
|
|
// while(1) {
|
|
|
|
// is_empty = false;
|
|
|
|
// if(!m_appSearchResults->isEmpty()) {
|
2022-06-13 13:38:47 +08:00
|
|
|
|
2022-06-23 10:13:58 +08:00
|
|
|
// ResultItem oneResult = m_appSearchResults->dequeue();
|
|
|
|
|
|
|
|
// SearchPluginIface::ResultInfo ri;
|
|
|
|
// ri.actionKey = oneResult.getExtral().at(0).toString();
|
|
|
|
// ri.name = oneResult.getExtral().at(1).toString();
|
|
|
|
// ri.icon = oneResult.getExtral().at(2).value<QIcon>();
|
|
|
|
// SearchPluginIface::DescriptionInfo description;
|
|
|
|
// description.key = QString(tr("Application Description:"));
|
|
|
|
// description.value = oneResult.getExtral().at(3).toString();
|
|
|
|
// ri.description.append(description);
|
|
|
|
// ri.type = oneResult.getExtral().at(4).toInt();
|
|
|
|
//// if (isUniqueSymbolChanged()) {
|
|
|
|
//// m_appSearchResults->clear();
|
|
|
|
//// break;
|
|
|
|
//// }
|
|
|
|
// m_search_result->enqueue(ri);
|
|
|
|
// } else {
|
|
|
|
// is_empty = true;
|
|
|
|
// }
|
|
|
|
// if (isUniqueSymbolChanged()) {
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// if(timer.isActive() && timer.remainingTime() < 0.01) {
|
|
|
|
// qWarning()<<"-------------->stopped by itself";
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// if(is_empty && !timer.isActive()) {
|
|
|
|
// timer.start();
|
|
|
|
// } else if(!is_empty) {
|
|
|
|
// timer.stop();
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
// QThread::msleep(100);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
|
|
|
|
//bool AppSearch::isUniqueSymbolChanged()
|
|
|
|
//{
|
|
|
|
// QMutexLocker locker(&AppSearchPlugin::m_mutex);
|
|
|
|
// if (m_uniqueSymbol != AppSearchPlugin::uniqueSymbol) {
|
|
|
|
// qDebug() << "uniqueSymbol changged, app search finished!";
|
|
|
|
// return true;
|
|
|
|
// } else {
|
|
|
|
// return false;
|
|
|
|
// }
|
|
|
|
//}
|