Skip to content

Commit

Permalink
try XDG when opening urls and no action is available
Browse files Browse the repository at this point in the history
Fix some memory leaks while at it

Proposed-by: Carl Philipp Klemm <philipp@uvos.xyz>
Signed-off-by: Ivaylo Dimitrov <ivo.g.dimitrov.75@gmail.com>
  • Loading branch information
IMbackK authored and freemangordon committed Mar 16, 2023
1 parent e7b076b commit 6b28559
Showing 1 changed file with 29 additions and 16 deletions.
45 changes: 29 additions & 16 deletions libhildonmime/hildon-uri.c
Expand Up @@ -23,6 +23,7 @@
#include <config.h>
#include <string.h>
#include <sys/stat.h>
#include <gio/gio.h>

#include "hildon-mime.h"

Expand Down Expand Up @@ -2285,7 +2286,7 @@ hildon_uri_open (const gchar *uri,
gchar *scheme;
GSList *uris = NULL;
const gchar *str;
gboolean ok;
gboolean ok = FALSE;
gboolean cleanup_action = FALSE;

DEBUG_MSG (("URI: Attempting to open URI:'%s' with %s action specified",
Expand All @@ -2307,7 +2308,7 @@ hildon_uri_open (const gchar *uri,

scheme = hildon_uri_get_scheme_from_uri (uri, error);
if (!scheme || scheme[0] == '\0') {
return FALSE;
goto cleanup;
}

action = action_to_try;
Expand Down Expand Up @@ -2346,30 +2347,38 @@ hildon_uri_open (const gchar *uri,
g_clear_error (error);

if (!action) {
gchar *error_str;

error_str = g_strdup_printf
("No actions exist for the scheme '%s'", scheme);
GAppInfo *app_info = g_app_info_get_default_for_uri_scheme (scheme);

if (app_info) {
GList *uri_list = g_list_append (NULL, (gchar*)uri);

g_app_info_launch_uris_async (app_info, uri_list, NULL, NULL, NULL, NULL);
g_list_free (uri_list);
g_object_unref (app_info);
/* Update the task navigator */
ok = uri_launch_show_animation (connection);
} else {
gchar *error_str = g_strdup_printf ("No actions or XDG applications "
"exist for the scheme '%s'", scheme);

DEBUG_MSG (("URI: %s", error_str));
DEBUG_MSG (("URI: %s", error_str));

g_set_error (error,
HILDON_URI_ERROR,
HILDON_URI_NO_ACTIONS,
"%s",
error_str);
g_set_error (error,
HILDON_URI_ERROR,
HILDON_URI_NO_ACTIONS,
"%s",
error_str);

g_free (error_str);
g_free (error_str);
}

return FALSE;
goto cleanup;
}

DEBUG_MSG (("URI: Using first action available for scheme:'%s'", scheme));
}
}

g_free (scheme);

uris = g_slist_append (uris, (gchar*)uri);
ok = uri_launch (connection, action, uris);
g_slist_free (uris);
Expand All @@ -2389,5 +2398,9 @@ hildon_uri_open (const gchar *uri,
str);
}

cleanup:
g_free(scheme);
dbus_connection_unref(connection);

return ok;
}

0 comments on commit 6b28559

Please sign in to comment.