forked from openkylin/ukui-search
Merge pull request #11 from mammonsama666/zjp-option
feat(searchPage): Add options to opearte search result.
This commit is contained in:
commit
8cc3bf4448
|
@ -2,6 +2,15 @@
|
|||
#include <QPainter>
|
||||
#include <QStyleOption>
|
||||
#include <QDebug>
|
||||
#include <gio/gdesktopappinfo.h>
|
||||
#include <QDBusInterface>
|
||||
#include <QDBusReply>
|
||||
#include <QStandardPaths>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QProcess>
|
||||
#include <QClipboard>
|
||||
#include <QApplication>
|
||||
|
||||
SearchDetailView::SearchDetailView(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
|
@ -144,33 +153,96 @@ void SearchDetailView::execActions(const int& type, const int& option, const QSt
|
|||
* @brief SearchDetailView::openAction 执行“打开”动作
|
||||
* @return
|
||||
*/
|
||||
bool SearchDetailView::openAction(const int&, const QString&) {
|
||||
bool SearchDetailView::openAction(const int& type, const QString& path) {
|
||||
switch (type) {
|
||||
case SearchListView::ResType::App: {
|
||||
GDesktopAppInfo * desktopAppInfo = g_desktop_app_info_new_from_filename(path.toLocal8Bit().data());
|
||||
g_app_info_launch(G_APP_INFO(desktopAppInfo),nullptr, nullptr, nullptr);
|
||||
g_object_unref(desktopAppInfo);
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
case SearchListView::ResType::Dir:
|
||||
case SearchListView::ResType::File: {
|
||||
QProcess * process = new QProcess;
|
||||
process->start(QString("xdg-open %1").arg(path));
|
||||
connect(process, static_cast<void(QProcess::*)(int,QProcess::ExitStatus)>(&QProcess::finished), this, [ = ]() {
|
||||
process->deleteLater();
|
||||
});
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
case SearchListView::ResType::Setting: {
|
||||
//打开控制面板对应页面
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SearchDetailView::addDesktopShortcut 添加到桌面快捷方式
|
||||
* @return
|
||||
*/
|
||||
bool SearchDetailView::addDesktopShortcut(const QString&) {
|
||||
bool SearchDetailView::addDesktopShortcut(const QString& path) {
|
||||
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)
|
||||
{
|
||||
QProcess * process = new QProcess;
|
||||
process->start(QString("chmod a+x %1").arg(newName));
|
||||
connect(process, static_cast<void(QProcess::*)(int,QProcess::ExitStatus)>(&QProcess::finished), this, [ = ]() {
|
||||
process->deleteLater();
|
||||
});
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SearchDetailView::addPanelShortcut 添加到任务栏
|
||||
* @return
|
||||
*/
|
||||
bool SearchDetailView::addPanelShortcut(const QString&) {
|
||||
bool SearchDetailView::addPanelShortcut(const QString& path) {
|
||||
QDBusInterface iface("com.ukui.panel.desktop",
|
||||
"/",
|
||||
"com.ukui.panel.desktop",
|
||||
QDBusConnection::sessionBus());
|
||||
if (iface.isValid()) {
|
||||
QDBusReply<bool> isExist = iface.call("CheckIfExist",path);
|
||||
if (isExist) {
|
||||
qDebug()<<"qDebug: Add shortcut to panel failed, because it is already existed!";
|
||||
return false;
|
||||
}
|
||||
QDBusReply<QVariant> ret = iface.call("AddToTaskbar",path);
|
||||
qDebug()<<"qDebug: Add shortcut to panel successed!";
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SearchDetailView::openPathAction 打开文件所在路径
|
||||
* @return
|
||||
*/
|
||||
bool SearchDetailView::openPathAction(const QString&) {
|
||||
bool SearchDetailView::openPathAction(const QString& path) {
|
||||
QProcess * process = new QProcess;
|
||||
process->start(QString("xdg-open %1").arg(path.left(path.length() - path.lastIndexOf("/") + 1)));
|
||||
connect(process, static_cast<void(QProcess::*)(int,QProcess::ExitStatus)>(&QProcess::finished), this, [ = ]() {
|
||||
process->deleteLater();
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SearchDetailView::copyPathAction 复制文件所在路径
|
||||
* @return
|
||||
*/
|
||||
bool SearchDetailView::copyPathAction(const QString&) {
|
||||
bool SearchDetailView::copyPathAction(const QString& path) {
|
||||
QClipboard * clipboard = QApplication::clipboard(); //获取系统剪贴板指针
|
||||
clipboard->setText(path);
|
||||
}
|
||||
|
|
|
@ -209,7 +209,7 @@ void MainWindow::searchContent(QString searchcontent){
|
|||
|
||||
//测试用数据
|
||||
QStringList list;
|
||||
list<<"/usr/share/applications/peony.desktop"<<"/usr/share/applications/fcitx.desktop"<<"/usr/share/applications/info.desktop";
|
||||
list<<"/usr/share/applications/peony.desktop"<<"/usr/share/applications/ukui-control-center.desktop"<<"/usr/share/applications/wps-office-pdf.desktop";
|
||||
QStringList list2;
|
||||
list2<<"/home/zjp/下载/搜索结果.png"<<"/home/zjp/下载/显示不全.mp4"<<"/home/zjp/下载/dmesg.log"<<"/home/zjp/下载/WiFi_AP选择.docx";
|
||||
QStringList list3;
|
||||
|
|
Loading…
Reference in New Issue