From db3e947e9524a16f63fd5d0d37dbbecfa01a908f Mon Sep 17 00:00:00 2001 From: zhangjiaping Date: Thu, 21 Jan 2021 11:31:53 +0800 Subject: [PATCH 1/2] fix(frontend): Optimize code for frontend. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Description: 优化前端Qprocess相关代码 Log: 优化前端Qprocess相关代码 --- src/control/home-page-item.cpp | 11 +++-------- src/control/search-detail-view.cpp | 18 +++++------------- 2 files changed, 8 insertions(+), 21 deletions(-) diff --git a/src/control/home-page-item.cpp b/src/control/home-page-item.cpp index 0e92bc1..9d24974 100644 --- a/src/control/home-page-item.cpp +++ b/src/control/home-page-item.cpp @@ -35,19 +35,14 @@ void HomePageItem::setupUi(const int& type, const QString& path) { case SearchListView::ResType::Dir: case SearchListView::ResType::File: { QProcess process; - process.start(QString("xdg-open %1").arg(path)); + process.startDetached(QString("xdg-open %1").arg(path)); process.waitForFinished(); break; } case SearchListView::ResType::Setting: { //打开控制面板对应页面 - QProcess * process = new QProcess; - connect(process, static_cast(&QProcess::finished), this, [ = ]() { - if (process) { - delete process; - } - }); - process->start(QString("ukui-control-center --%1").arg(path.left(path.indexOf("/")).toLower())); + QProcess process; + process.startDetached(QString("ukui-control-center --%1").arg(path.left(path.indexOf("/")).toLower())); break; } default: diff --git a/src/control/search-detail-view.cpp b/src/control/search-detail-view.cpp index a427d2f..76b102e 100644 --- a/src/control/search-detail-view.cpp +++ b/src/control/search-detail-view.cpp @@ -253,20 +253,14 @@ bool SearchDetailView::openAction(const int& type, const QString& path) { case SearchListView::ResType::Dir: case SearchListView::ResType::File: { QProcess process; - process.start(QString("xdg-open %1").arg(path)); - process.waitForFinished(); + process.startDetached(QString("xdg-open %1").arg(path)); return true; break; } case SearchListView::ResType::Setting: { //打开控制面板对应页面 - QProcess * process = new QProcess; - connect(process, static_cast(&QProcess::finished), this, [ = ]() { - if (process) { - delete process; - } - }); - process->start(QString("ukui-control-center --%1").arg(path.left(path.indexOf("/")).toLower())); + QProcess process; + process.startDetached(QString("ukui-control-center --%1").arg(path.left(path.indexOf("/")).toLower())); return true; break; } @@ -391,8 +385,7 @@ bool SearchDetailView::addDesktopShortcut(const QString& path) { if(ret) { QProcess process; - process.start(QString("chmod a+x %1").arg(newName)); - process.waitForFinished(); + process.startDetached(QString("chmod a+x %1").arg(newName)); return true; } return false; @@ -426,8 +419,7 @@ bool SearchDetailView::addPanelShortcut(const QString& path) { */ bool SearchDetailView::openPathAction(const QString& path) { QProcess process; - process.start(QString("xdg-open %1").arg(path.left(path.lastIndexOf("/")))); - process.waitForFinished(); + process.startDetached(QString("xdg-open %1").arg(path.left(path.lastIndexOf("/")))); return true; } From c93292bf4b86d996f1b1ffdfb4a2716b18b88d26 Mon Sep 17 00:00:00 2001 From: zhangjiaping Date: Thu, 21 Jan 2021 14:20:44 +0800 Subject: [PATCH 2/2] feat(frontend): Add keypress event. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Description: 添加esc按键监听隐藏主界面 Log: 添加esc按键监听隐藏主界面 --- src/mainwindow.cpp | 12 +++++++++++- src/mainwindow.h | 2 ++ translations/ukui-search/bo.ts | 24 ++++++++++++------------ translations/ukui-search/tr.ts | 24 ++++++++++++------------ translations/ukui-search/zh_CN.ts | 26 +++++++++++++------------- 5 files changed, 50 insertions(+), 38 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 740a7e3..fac4544 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -330,6 +330,16 @@ bool MainWindow::nativeEvent(const QByteArray &eventType, void *message, long *r return false; } +void MainWindow::keyPressEvent(QKeyEvent *event) +{ + if (event->key() == Qt::Key_Escape) { + this->hide(); + m_search_result_thread->requestInterruption(); + m_search_result_thread->quit(); + } + return QWidget::keyPressEvent(event); +} + void MainWindow::paintEvent(QPaintEvent *event) { Q_UNUSED(event) @@ -345,6 +355,6 @@ void MainWindow::paintEvent(QPaintEvent *event) { p.setOpacity(trans); p.setPen(Qt::NoPen); p.drawRoundedRect(rect, 6, 6); - QWidget::paintEvent(event); + return QWidget::paintEvent(event); } diff --git a/src/mainwindow.h b/src/mainwindow.h index 40d34bb..a1cafd5 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include "content-widget.h" @@ -94,6 +95,7 @@ private: protected: void paintEvent(QPaintEvent *); + void keyPressEvent(QKeyEvent *event); void initUi(); public Q_SLOTS: diff --git a/translations/ukui-search/bo.ts b/translations/ukui-search/bo.ts index f053037..59eb3ab 100644 --- a/translations/ukui-search/bo.ts +++ b/translations/ukui-search/bo.ts @@ -19,37 +19,37 @@ - + Apps - + Settings - + Files - + Dirs - + File Contents - + Best Matches - + Unknown @@ -65,12 +65,12 @@ MainWindow - + Global Search - + Search @@ -106,7 +106,7 @@ QObject - + ukui-search is already running! @@ -122,12 +122,12 @@ SearchDetailView - + Path - + Last time modified diff --git a/translations/ukui-search/tr.ts b/translations/ukui-search/tr.ts index f053037..59eb3ab 100644 --- a/translations/ukui-search/tr.ts +++ b/translations/ukui-search/tr.ts @@ -19,37 +19,37 @@ - + Apps - + Settings - + Files - + Dirs - + File Contents - + Best Matches - + Unknown @@ -65,12 +65,12 @@ MainWindow - + Global Search - + Search @@ -106,7 +106,7 @@ QObject - + ukui-search is already running! @@ -122,12 +122,12 @@ SearchDetailView - + Path - + Last time modified diff --git a/translations/ukui-search/zh_CN.ts b/translations/ukui-search/zh_CN.ts index 5467d46..e5d0d35 100644 --- a/translations/ukui-search/zh_CN.ts +++ b/translations/ukui-search/zh_CN.ts @@ -19,37 +19,37 @@ 常用 - + Apps 应用 - + Settings 配置项 - + Files 文件 - + Dirs 文件夹 - + File Contents 文件内容 - + Best Matches 最佳匹配 - + Unknown 未知 @@ -65,14 +65,14 @@ MainWindow - + Global Search 搜索 - + Search - 从列表搜索 + 搜索 @@ -106,7 +106,7 @@ QObject - + ukui-search is already running! @@ -122,12 +122,12 @@ SearchDetailView - + Path 路径 - + Last time modified 上次修改时间