summaryrefslogtreecommitdiff
blob: 92b45be432fbb1b818200e28b27ca257973ca080 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
From 4923f860094787d14052e9dc416c9388ff1bb53b Mon Sep 17 00:00:00 2001
From: Tsu Jan <tsujan2000@gmail.com>
Date: Thu, 7 Jun 2018 06:10:37 +0430
Subject: [PATCH] Check if the opening app exists before using it

Also, show an error message if there's no app.
---
 src/core/basicfilelauncher.cpp | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/src/core/basicfilelauncher.cpp b/src/core/basicfilelauncher.cpp
index 8390531..2c7f00e 100644
--- a/src/core/basicfilelauncher.cpp
+++ b/src/core/basicfilelauncher.cpp
@@ -256,18 +256,25 @@ FilePath BasicFileLauncher::handleShortcut(const FileInfoPtr& fileInfo, GAppLaun
                 || strcmp(scheme.get(), "trash") == 0
                 || strcmp(scheme.get(), "network") == 0
                 || strcmp(scheme.get(), "computer") == 0) {
-            return FilePath::fromUri(fileInfo->target().c_str());
+            return FilePath::fromUri(target.c_str());
         }
         else {
             // ask gio to launch the default handler for the uri scheme
-            GAppInfoPtr app{g_app_info_get_default_for_uri_scheme(scheme.get()), false};
-            FilePathList uris{FilePath::fromUri(fileInfo->target().c_str())};
-            launchWithApp(app.get(), uris, ctx);
+            if(GAppInfoPtr app{g_app_info_get_default_for_uri_scheme(scheme.get()), false}) {
+                FilePathList uris{FilePath::fromUri(target.c_str())};
+                launchWithApp(app.get(), uris, ctx);
+            }
+            else {
+                GErrorPtr err{G_IO_ERROR, G_IO_ERROR_FAILED,
+                              QObject::tr("No default application is set to launch '%1'")
+                              .arg(target.c_str())};
+                showError(nullptr, err);
+            }
         }
     }
     else {
         // see it as a local path
-        return FilePath::fromLocalPath(fileInfo->target().c_str());
+        return FilePath::fromLocalPath(target.c_str());
     }
     return FilePath();
 }