diff --git a/frontend/mainwindow.cpp b/frontend/mainwindow.cpp index 9c26169..aa8a4c3 100644 --- a/frontend/mainwindow.cpp +++ b/frontend/mainwindow.cpp @@ -482,7 +482,7 @@ void MainWindow::initTimer() { */ bool MainWindow::tryHideMainwindow() { - if (!m_isAskDialogVisible) { + if (!m_isAskDialogVisible && QApplication::activeModalWidget() == nullptr) { qDebug()<<"Mainwindow will be hidden"; m_currentSearchAsked = false; this->hide(); diff --git a/frontend/mainwindow.h b/frontend/mainwindow.h index 5b05a27..59aa48c 100644 --- a/frontend/mainwindow.h +++ b/frontend/mainwindow.h @@ -46,10 +46,11 @@ #include #include -#include "index/index-generator.h" +#include "index-generator.h" #include "libsearch.h" #include "create-index-ask-dialog.h" -#include "stacked-widget.h" +#include "search-line-edit.h" +#include "search-result-page.h" #if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)) #include "xatom-helper.h" #endif diff --git a/libsearch/file-utils.cpp b/libsearch/file-utils.cpp index 8e5d2fa..9958ed8 100644 --- a/libsearch/file-utils.cpp +++ b/libsearch/file-utils.cpp @@ -22,6 +22,7 @@ #include "file-utils.h" #include #include +#include using namespace Zeeker; size_t FileUtils::_max_index_count = 0; @@ -770,12 +771,53 @@ void FileUtils::getTxtContent(QString &path, QString &textcontent) { return; } -bool FileUtils::openFile(QString &path, bool openInDir) +int FileUtils::openFile(QString &path, bool openInDir) { if(openInDir) { - return QDesktopServices::openUrl(QUrl::fromLocalFile(path.left(path.lastIndexOf("/")))); + QDesktopServices::openUrl(QUrl::fromLocalFile(path.left(path.lastIndexOf("/")))); + return 0; } else { - return QDesktopServices::openUrl(QUrl::fromLocalFile(path)); + auto file = wrapGFile(g_file_new_for_uri(QUrl::fromLocalFile(path).toString().toUtf8().constData())); + auto fileInfo = wrapGFileInfo(g_file_query_info(file.get()->get(), + "standard::*," "time::*," "access::*," "mountable::*," "metadata::*," "trash::*," G_FILE_ATTRIBUTE_ID_FILE, + G_FILE_QUERY_INFO_NONE, + nullptr, + nullptr)); + QString mimeType = g_file_info_get_content_type (fileInfo.get()->get()); + if (mimeType == nullptr) { + if (g_file_info_has_attribute(fileInfo.get()->get(), "standard::fast-content-type")) { + mimeType = g_file_info_get_attribute_string(fileInfo.get()->get(), "standard::fast-content-type"); + } + } + GError *error = NULL; + GAppInfo *info = NULL; + /* + * g_app_info_get_default_for_type function get wrong default app, so we get the + * default app info from mimeapps.list, and chose the right default app for mimeType file + */ + QString mimeAppsListPath = QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + + "/.config/mimeapps.list"; + GKeyFile *keyfile = g_key_file_new(); + gboolean ret = g_key_file_load_from_file(keyfile, mimeAppsListPath.toUtf8(), G_KEY_FILE_NONE, &error); + if (false == ret) { + qWarning()<<"load mimeapps list error msg"<message; + info = g_app_info_get_default_for_type(mimeType.toUtf8().constData(), false); + g_error_free(error); + } else { + gchar *desktopApp = g_key_file_get_string(keyfile, "Default Applications", mimeType.toUtf8(), &error); + if (NULL != desktopApp) { + info = (GAppInfo*)g_desktop_app_info_new(desktopApp); + g_free (desktopApp); + } else { + info = g_app_info_get_default_for_type(mimeType.toUtf8().constData(), false); + } + } + g_key_file_free (keyfile); + if(!G_IS_APP_INFO(info)) { + return -1; + } + QDesktopServices::openUrl(QUrl::fromLocalFile(path)); + return 0; } } diff --git a/libsearch/file-utils.h b/libsearch/file-utils.h index 8db658c..ea935fa 100644 --- a/libsearch/file-utils.h +++ b/libsearch/file-utils.h @@ -90,7 +90,7 @@ public: static void getPdfTextContent(QString &path, QString &textcontent); static void getTxtContent(QString &path, QString &textcontent); - static bool openFile(QString &path, bool openInDir = false); + static int openFile(QString &path, bool openInDir = false); static bool copyPath(QString &path); static QString escapeHtml(const QString & str); static QString chineseSubString(const std::string &myStr,int start,int length); diff --git a/libsearch/index/file-search-plugin.cpp b/libsearch/index/file-search-plugin.cpp index 699535b..bf1a4db 100644 --- a/libsearch/index/file-search-plugin.cpp +++ b/libsearch/index/file-search-plugin.cpp @@ -3,6 +3,7 @@ #include #include #include +#include using namespace Zeeker; FileSearchPlugin::FileSearchPlugin(QObject *parent) : QObject(parent) @@ -56,12 +57,22 @@ QList FileSearchPlugin::getActioninfo(int type) void FileSearchPlugin::openAction(int actionkey, QString key, int type) { //TODO add some return message here. + qDebug() << "openAction!!!!!!!!"; switch (actionkey) { case 0: - FileUtils::openFile(key); + if(FileUtils::openFile(key) == -1) { + QMessageBox msgBox(m_detailPage); + msgBox.setWindowModality(Qt::WindowModal); + msgBox.setStandardButtons(QMessageBox::Yes); + msgBox.setButtonText(QMessageBox::Yes, tr("Yes")); + msgBox.setIcon(QMessageBox::Information); + msgBox.setText(tr("Can not get a default application for opening %1.").arg(key)); + msgBox.exec(); + } break; case 1: FileUtils::openFile(key, true); + break; case 2: FileUtils::copyPath(key); default: @@ -165,7 +176,15 @@ void FileSearchPlugin::initDetailPage() m_detailLyt->addStretch(); connect(m_actionLabel1, &ActionLabel::actionTriggered, [ & ](){ - FileUtils::openFile(m_currentActionKey); + if(FileUtils::openFile(m_currentActionKey) == -1) { + QMessageBox msgBox(m_detailPage); + msgBox.setWindowModality(Qt::WindowModal); + msgBox.setStandardButtons(QMessageBox::Yes); + msgBox.setButtonText(QMessageBox::Yes, tr("Yes")); + msgBox.setIcon(QMessageBox::Information); + msgBox.setText(tr("Can not get a default application for opening %1.").arg(m_currentActionKey)); + msgBox.exec(); + } }); connect(m_actionLabel2, &ActionLabel::actionTriggered, [ & ](){ FileUtils::openFile(m_currentActionKey, true); diff --git a/translations/libukui-search/libukui-search_zh_CN.ts b/translations/libukui-search/libukui-search_zh_CN.ts index c6678c8..e4fb3e8 100644 --- a/translations/libukui-search/libukui-search_zh_CN.ts +++ b/translations/libukui-search/libukui-search_zh_CN.ts @@ -4,7 +4,7 @@ Zeeker::AppMatch - + Application Description: 应用描述: @@ -62,50 +62,50 @@ Zeeker::DirSearchPlugin - - + + Open 打开 - - + + Open path 打开文件所在路径 - + Copy Path 复制文件路径 - - + + Dir Search 目录搜索 - + Dir search. 目录搜索。 - + directory 目录 - + Path 路径 - + Last time modified 上次修改时间 - + Copy path 复制路径 @@ -113,54 +113,54 @@ Zeeker::FileContengSearchPlugin - - + + Open 打开 - - + + Open path 打开文件所在路径 - + Copy Path 复制文件路径 - + File Content Search 文本内容搜索 - + File content search. 文本内容搜索。 - + File content search 文本内容搜索 - + File 文件 - + Path 路径 - + Last time modified 上次修改时间 - + Copy path 复制路径 @@ -168,50 +168,62 @@ Zeeker::FileSearchPlugin - - + + Open 打开 - - + + Open path 打开文件所在路径 - + Copy Path 复制文件路径 - - + + File Search 文件搜索 - + File search. 文件搜索。 - + + + Yes + 确定 + + + + + Can not get a default application for opening %1. + 没有找到默认打开%1的应用。 + + + File 文件 - + Path 路径 - + Last time modified 上次修改时间 - + Copy path 复制路径 @@ -219,7 +231,7 @@ Zeeker::NoteSearch - + Note Description: 便签内容: 便签内容: @@ -228,28 +240,28 @@ Zeeker::NoteSearchPlugin - - + + Open 打开 打开 - - - + + + Note Search 便签 便签 - + Note Search. 便签. 便签. - + Application 应用 应用 @@ -258,12 +270,12 @@ Zeeker::SearchManager - + Path: 路径: - + Modified time: 修改时间: diff --git a/translations/ukui-search/bo.ts b/translations/ukui-search/bo.ts index 49dd06a..03056e1 100644 --- a/translations/ukui-search/bo.ts +++ b/translations/ukui-search/bo.ts @@ -12,7 +12,7 @@ Zeeker::BestListWidget - + Best Matches @@ -58,45 +58,19 @@ - - Zeeker::HomePage - - - Open Quickly - - - - - Recently Opened - - - - - Commonly Used - - - Zeeker::MainWindow - + ukui-search - + Global Search - - Zeeker::ResultArea - - - Web Page - - - Zeeker::SearchLineEdit @@ -266,4 +240,12 @@ + + Zeeker::WebSearchWidget + + + Web Page + + + diff --git a/translations/ukui-search/tr.ts b/translations/ukui-search/tr.ts index 9fedb92..f6d15c1 100644 --- a/translations/ukui-search/tr.ts +++ b/translations/ukui-search/tr.ts @@ -247,7 +247,7 @@ Zeeker::BestListWidget - + Best Matches En İyi Eşleşen @@ -339,30 +339,27 @@ Zeeker::HomePage - Open Quickly - Hızlı Aç + Hızlı Aç - Recently Opened - Yeni Açılan + Yeni Açılan - Commonly Used - Genel olarak kullanılan + Genel olarak kullanılan Zeeker::MainWindow - + ukui-search - + Global Search Genel Arama @@ -394,14 +391,6 @@ Yolu kopyala - - Zeeker::ResultArea - - - Web Page - - - Zeeker::SearchBarHLayout @@ -624,4 +613,12 @@ Yükleniyor... + + Zeeker::WebSearchWidget + + + Web Page + + + diff --git a/translations/ukui-search/zh_CN.ts b/translations/ukui-search/zh_CN.ts index a4e74af..4679561 100644 --- a/translations/ukui-search/zh_CN.ts +++ b/translations/ukui-search/zh_CN.ts @@ -12,7 +12,7 @@ Zeeker::BestListWidget - + Best Matches 最佳匹配 @@ -108,30 +108,27 @@ Zeeker::HomePage - Open Quickly - 快速入口 + 快速入口 - Recently Opened - 最近 + 最近 - Commonly Used - 常用 + 常用 Zeeker::MainWindow - + ukui-search 搜索 - + Global Search 搜索 @@ -167,14 +164,6 @@ 安装 - - Zeeker::ResultArea - - - Web Page - - - Zeeker::SearchBarHLayout @@ -405,4 +394,12 @@ 加载中... + + Zeeker::WebSearchWidget + + + Web Page + + +