Merge branch '0902-newfrontend' into 'new-frontend'

Add pop up window for file search plugin.

See merge request kylin-desktop/ukui-search!145
This commit is contained in:
纪笑旭 2021-09-23 03:24:40 +00:00
commit 76cf09907d
9 changed files with 169 additions and 119 deletions

View File

@ -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();

View File

@ -46,10 +46,11 @@
#include <QSystemTrayIcon>
#include <QTimer>
#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

View File

@ -22,6 +22,7 @@
#include "file-utils.h"
#include <QXmlStreamReader>
#include <QMutexLocker>
#include <gio/gdesktopappinfo.h>
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"<<error->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;
}
}

View File

@ -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);

View File

@ -3,6 +3,7 @@
#include <QWidget>
#include <QLabel>
#include <QHBoxLayout>
#include <QMessageBox>
using namespace Zeeker;
FileSearchPlugin::FileSearchPlugin(QObject *parent) : QObject(parent)
@ -56,12 +57,22 @@ QList<SearchPluginIface::Actioninfo> 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);

View File

@ -4,7 +4,7 @@
<context>
<name>Zeeker::AppMatch</name>
<message>
<location filename="../../libsearch/appsearch/app-match.cpp" line="329"/>
<location filename="../../libsearch/appsearch/app-match.cpp" line="258"/>
<source>Application Description:</source>
<translation></translation>
</message>
@ -62,50 +62,50 @@
<context>
<name>Zeeker::DirSearchPlugin</name>
<message>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="199"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="336"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="218"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="355"/>
<source>Open</source>
<translation></translation>
</message>
<message>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="200"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="337"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="219"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="356"/>
<source>Open path</source>
<translation></translation>
</message>
<message>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="201"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="220"/>
<source>Copy Path</source>
<translation></translation>
</message>
<message>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="210"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="220"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="229"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="239"/>
<source>Dir Search</source>
<translation></translation>
</message>
<message>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="215"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="234"/>
<source>Dir search.</source>
<translation></translation>
</message>
<message>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="271"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="290"/>
<source>directory</source>
<translation></translation>
</message>
<message>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="311"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="330"/>
<source>Path</source>
<translation></translation>
</message>
<message>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="323"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="342"/>
<source>Last time modified</source>
<translation></translation>
</message>
<message>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="338"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="357"/>
<source>Copy path</source>
<translation></translation>
</message>
@ -113,54 +113,54 @@
<context>
<name>Zeeker::FileContengSearchPlugin</name>
<message>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="379"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="578"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="398"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="597"/>
<source>Open</source>
<translation></translation>
</message>
<message>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="380"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="579"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="399"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="598"/>
<source>Open path</source>
<translation></translation>
</message>
<message>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="381"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="400"/>
<source>Copy Path</source>
<translation></translation>
</message>
<message>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="390"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="409"/>
<source>File Content Search</source>
<translation></translation>
</message>
<message>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="395"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="414"/>
<source>File content search.</source>
<translation></translation>
</message>
<message>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="400"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="419"/>
<source>File content search</source>
<translation></translation>
</message>
<message>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="445"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="464"/>
<source>File</source>
<translation></translation>
</message>
<message>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="553"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="572"/>
<source>Path</source>
<translation></translation>
</message>
<message>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="565"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="584"/>
<source>Last time modified</source>
<translation></translation>
</message>
<message>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="580"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="599"/>
<source>Copy path</source>
<translation></translation>
</message>
@ -168,50 +168,62 @@
<context>
<name>Zeeker::FileSearchPlugin</name>
<message>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="10"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="147"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="11"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="158"/>
<source>Open</source>
<translation></translation>
</message>
<message>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="11"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="148"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="12"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="159"/>
<source>Open path</source>
<translation></translation>
</message>
<message>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="12"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="13"/>
<source>Copy Path</source>
<translation></translation>
</message>
<message>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="21"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="31"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="22"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="32"/>
<source>File Search</source>
<translation></translation>
</message>
<message>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="26"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="27"/>
<source>File search.</source>
<translation></translation>
</message>
<message>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="82"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="67"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="183"/>
<source>Yes</source>
<translation></translation>
</message>
<message>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="69"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="185"/>
<source>Can not get a default application for opening %1.</source>
<translation type="unfinished">%1</translation>
</message>
<message>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="93"/>
<source>File</source>
<translation></translation>
</message>
<message>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="122"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="133"/>
<source>Path</source>
<translation></translation>
</message>
<message>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="134"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="145"/>
<source>Last time modified</source>
<translation></translation>
</message>
<message>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="149"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="160"/>
<source>Copy path</source>
<translation></translation>
</message>
@ -219,7 +231,7 @@
<context>
<name>Zeeker::NoteSearch</name>
<message>
<location filename="../../libsearch/notesearch/note-search-plugin.cpp" line="188"/>
<location filename="../../libsearch/notesearch/note-search-plugin.cpp" line="190"/>
<source>Note Description:</source>
<translatorcomment>便</translatorcomment>
<translation>便</translation>
@ -228,28 +240,28 @@
<context>
<name>Zeeker::NoteSearchPlugin</name>
<message>
<location filename="../../libsearch/notesearch/note-search-plugin.cpp" line="11"/>
<location filename="../../libsearch/notesearch/note-search-plugin.cpp" line="126"/>
<location filename="../../libsearch/notesearch/note-search-plugin.cpp" line="12"/>
<location filename="../../libsearch/notesearch/note-search-plugin.cpp" line="128"/>
<source>Open</source>
<translatorcomment></translatorcomment>
<translation></translation>
</message>
<message>
<location filename="../../libsearch/notesearch/note-search-plugin.cpp" line="20"/>
<location filename="../../libsearch/notesearch/note-search-plugin.cpp" line="30"/>
<location filename="../../libsearch/notesearch/note-search-plugin.cpp" line="95"/>
<location filename="../../libsearch/notesearch/note-search-plugin.cpp" line="21"/>
<location filename="../../libsearch/notesearch/note-search-plugin.cpp" line="31"/>
<location filename="../../libsearch/notesearch/note-search-plugin.cpp" line="97"/>
<source>Note Search</source>
<translatorcomment>便</translatorcomment>
<translation>便</translation>
</message>
<message>
<location filename="../../libsearch/notesearch/note-search-plugin.cpp" line="25"/>
<location filename="../../libsearch/notesearch/note-search-plugin.cpp" line="26"/>
<source>Note Search.</source>
<translatorcomment>便.</translatorcomment>
<translation>便.</translation>
</message>
<message>
<location filename="../../libsearch/notesearch/note-search-plugin.cpp" line="69"/>
<location filename="../../libsearch/notesearch/note-search-plugin.cpp" line="71"/>
<source>Application</source>
<translatorcomment></translatorcomment>
<translation></translation>
@ -258,12 +270,12 @@
<context>
<name>Zeeker::SearchManager</name>
<message>
<location filename="../../libsearch/index/search-manager.cpp" line="100"/>
<location filename="../../libsearch/index/search-manager.cpp" line="98"/>
<source>Path:</source>
<translation></translation>
</message>
<message>
<location filename="../../libsearch/index/search-manager.cpp" line="101"/>
<location filename="../../libsearch/index/search-manager.cpp" line="99"/>
<source>Modified time:</source>
<translation></translation>
</message>

View File

@ -12,7 +12,7 @@
<context>
<name>Zeeker::BestListWidget</name>
<message>
<location filename="../../frontend/view/best-list-view.cpp" line="293"/>
<location filename="../../frontend/view/best-list-view.cpp" line="305"/>
<source>Best Matches</source>
<translation type="unfinished"></translation>
</message>
@ -58,45 +58,19 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Zeeker::HomePage</name>
<message>
<location filename="../../frontend/control/stack-pages/home-page.cpp" line="118"/>
<source>Open Quickly</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../frontend/control/stack-pages/home-page.cpp" line="120"/>
<source>Recently Opened</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../frontend/control/stack-pages/home-page.cpp" line="122"/>
<source>Commonly Used</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Zeeker::MainWindow</name>
<message>
<location filename="../../frontend/mainwindow.cpp" line="71"/>
<location filename="../../frontend/mainwindow.cpp" line="70"/>
<source>ukui-search</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../frontend/mainwindow.cpp" line="77"/>
<location filename="../../frontend/mainwindow.cpp" line="76"/>
<source>Global Search</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Zeeker::ResultArea</name>
<message>
<location filename="../../frontend/control/stack-pages/search-page-section.cpp" line="378"/>
<source>Web Page</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Zeeker::SearchLineEdit</name>
<message>
@ -266,4 +240,12 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Zeeker::WebSearchWidget</name>
<message>
<location filename="../../frontend/view/web-search-view.cpp" line="149"/>
<source>Web Page</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>

View File

@ -247,7 +247,7 @@
<context>
<name>Zeeker::BestListWidget</name>
<message>
<location filename="../../frontend/view/best-list-view.cpp" line="293"/>
<location filename="../../frontend/view/best-list-view.cpp" line="305"/>
<source>Best Matches</source>
<translation type="unfinished">En İyi Eşleşen</translation>
</message>
@ -339,30 +339,27 @@
<context>
<name>Zeeker::HomePage</name>
<message>
<location filename="../../frontend/control/stack-pages/home-page.cpp" line="118"/>
<source>Open Quickly</source>
<translation type="unfinished">Hızlı </translation>
<translation type="obsolete">Hızlı </translation>
</message>
<message>
<location filename="../../frontend/control/stack-pages/home-page.cpp" line="120"/>
<source>Recently Opened</source>
<translation type="unfinished">Yeni ılan</translation>
<translation type="obsolete">Yeni ılan</translation>
</message>
<message>
<location filename="../../frontend/control/stack-pages/home-page.cpp" line="122"/>
<source>Commonly Used</source>
<translation type="unfinished">Genel olarak kullanılan</translation>
<translation type="obsolete">Genel olarak kullanılan</translation>
</message>
</context>
<context>
<name>Zeeker::MainWindow</name>
<message>
<location filename="../../frontend/mainwindow.cpp" line="71"/>
<location filename="../../frontend/mainwindow.cpp" line="70"/>
<source>ukui-search</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../frontend/mainwindow.cpp" line="77"/>
<location filename="../../frontend/mainwindow.cpp" line="76"/>
<source>Global Search</source>
<translation type="unfinished">Genel Arama</translation>
</message>
@ -394,14 +391,6 @@
<translation type="obsolete">Yolu kopyala</translation>
</message>
</context>
<context>
<name>Zeeker::ResultArea</name>
<message>
<location filename="../../frontend/control/stack-pages/search-page-section.cpp" line="378"/>
<source>Web Page</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Zeeker::SearchBarHLayout</name>
<message>
@ -624,4 +613,12 @@
<translation type="obsolete">Yükleniyor...</translation>
</message>
</context>
<context>
<name>Zeeker::WebSearchWidget</name>
<message>
<location filename="../../frontend/view/web-search-view.cpp" line="149"/>
<source>Web Page</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>

View File

@ -12,7 +12,7 @@
<context>
<name>Zeeker::BestListWidget</name>
<message>
<location filename="../../frontend/view/best-list-view.cpp" line="293"/>
<location filename="../../frontend/view/best-list-view.cpp" line="305"/>
<source>Best Matches</source>
<translation></translation>
</message>
@ -108,30 +108,27 @@
<context>
<name>Zeeker::HomePage</name>
<message>
<location filename="../../frontend/control/stack-pages/home-page.cpp" line="118"/>
<source>Open Quickly</source>
<translation></translation>
<translation type="vanished"></translation>
</message>
<message>
<location filename="../../frontend/control/stack-pages/home-page.cpp" line="120"/>
<source>Recently Opened</source>
<translation></translation>
<translation type="vanished"></translation>
</message>
<message>
<location filename="../../frontend/control/stack-pages/home-page.cpp" line="122"/>
<source>Commonly Used</source>
<translation></translation>
<translation type="vanished"></translation>
</message>
</context>
<context>
<name>Zeeker::MainWindow</name>
<message>
<location filename="../../frontend/mainwindow.cpp" line="71"/>
<location filename="../../frontend/mainwindow.cpp" line="70"/>
<source>ukui-search</source>
<translation></translation>
</message>
<message>
<location filename="../../frontend/mainwindow.cpp" line="77"/>
<location filename="../../frontend/mainwindow.cpp" line="76"/>
<source>Global Search</source>
<translation></translation>
</message>
@ -167,14 +164,6 @@
<translation type="vanished"></translation>
</message>
</context>
<context>
<name>Zeeker::ResultArea</name>
<message>
<location filename="../../frontend/control/stack-pages/search-page-section.cpp" line="378"/>
<source>Web Page</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Zeeker::SearchBarHLayout</name>
<message>
@ -405,4 +394,12 @@
<translation type="vanished">...</translation>
</message>
</context>
<context>
<name>Zeeker::WebSearchWidget</name>
<message>
<location filename="../../frontend/view/web-search-view.cpp" line="149"/>
<source>Web Page</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>