From 577d4f60508a212f4b45cff771522ae2d4c690cc Mon Sep 17 00:00:00 2001 From: jixiaoxu Date: Mon, 7 Mar 2022 11:38:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=80=E5=A4=84gio?= =?UTF-8?q?=E8=B5=84=E6=BA=90=E9=87=8A=E6=94=BE=E9=97=AE=E9=A2=98=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libsearch/file-utils.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/libsearch/file-utils.cpp b/libsearch/file-utils.cpp index db5569f..6a359b0 100644 --- a/libsearch/file-utils.cpp +++ b/libsearch/file-utils.cpp @@ -773,6 +773,7 @@ void FileUtils::getTxtContent(QString &path, QString &textcontent) { int FileUtils::openFile(QString &path, bool openInDir) { + int res = -1; if(openInDir) { QStringList list; list.append(path); @@ -781,12 +782,12 @@ int FileUtils::openFile(QString &path, bool openInDir) "org.freedesktop.FileManager1", "ShowItems"); message.setArguments({list, "ukui-search"}); - QDBusMessage res = QDBusConnection::sessionBus().call(message); - if (QDBusMessage::ReplyMessage == res.ReplyMessage) { - return 0; + QDBusMessage messageRes = QDBusConnection::sessionBus().call(message); + if (QDBusMessage::ReplyMessage == messageRes.ReplyMessage) { + res = 0; } else { - qDebug() << "Error! QDBusMessage reply error! ReplyMessage:" << res.ReplyMessage; - return -1; + qDebug() << "Error! QDBusMessage reply error! ReplyMessage:" << messageRes.ReplyMessage; + res = -1; } } else { auto file = wrapGFile(g_file_new_for_uri(QUrl::fromLocalFile(path).toString().toUtf8().constData())); @@ -801,6 +802,7 @@ int FileUtils::openFile(QString &path, bool openInDir) mimeType = g_file_info_get_attribute_string(fileInfo.get()->get(), "standard::fast-content-type"); } } + GError *error = NULL; GAppInfo *info = NULL; /* @@ -826,11 +828,14 @@ int FileUtils::openFile(QString &path, bool openInDir) } g_key_file_free (keyfile); if(!G_IS_APP_INFO(info)) { - return -1; + res = -1; + } else { + QDesktopServices::openUrl(QUrl::fromLocalFile(path)); + res = 0; } - QDesktopServices::openUrl(QUrl::fromLocalFile(path)); - return 0; + g_object_unref(info); } + return res; } bool FileUtils::copyPath(QString &path)