From 5ae55e65d8f832557523c734b53a61211918a289 Mon Sep 17 00:00:00 2001 From: Ernestas Kulik Date: Sun, 21 Jul 2024 16:29:58 +0300 Subject: [PATCH] result: Implement launching actions This commit builds on top of 7f1cbb874f6ba66124e8e21b3ced33ab41ce0d3f to provide the ability to launch matching actions. Relates to #5. --- src/jogg-application-window.c | 12 +++++++++++- src/jogg-application.c | 7 +++++-- src/jogg-result.c | 22 ++++++++++++++++++++++ src/jogg-result.h | 1 + src/res/ui/result.ui | 4 ++-- 5 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/jogg-application-window.c b/src/jogg-application-window.c index fdf3168..c386cd6 100644 --- a/src/jogg-application-window.c +++ b/src/jogg-application-window.c @@ -176,12 +176,22 @@ jogg_application_window_results_on_activate ( GtkListView *self GtkSelectionModel *model = NULL; JoggResult *item = NULL; g_autoptr (GDesktopAppInfo) app_info = NULL; + g_autofree char *action = NULL; model = gtk_list_view_get_model (self); item = g_list_model_get_item (G_LIST_MODEL (model), position); app_info = jogg_result_get_app_info (JOGG_RESULT (item)); + action = jogg_result_get_action (JOGG_RESULT (item)); + + if (action != NULL) + { + g_desktop_app_info_launch_action (app_info, action, NULL); + } + else + { + g_app_info_launch (G_APP_INFO (app_info), NULL, NULL, NULL); + } - g_app_info_launch (G_APP_INFO (app_info), NULL, NULL, NULL); jogg_application_window_quit (user_data); } diff --git a/src/jogg-application.c b/src/jogg-application.c index 57e5f0b..36b0711 100644 --- a/src/jogg-application.c +++ b/src/jogg-application.c @@ -170,9 +170,12 @@ jogg_application_app_info_search ( JoggApplication *self haystacks = g_desktop_app_info_list_actions (app_info); for (; haystacks != NULL && *haystacks != NULL; haystacks++) { - haystack = g_desktop_app_info_get_action_name (app_info, *haystacks); + g_autofree char *action_name = NULL; - if (jogg_has_substring (haystack, query, &prefix)) + haystack = *haystacks; + action_name = g_desktop_app_info_get_action_name (app_info, haystack); + + if (jogg_has_substring (action_name, query, &prefix)) { result = jogg_result_new ( app_info , haystack diff --git a/src/jogg-result.c b/src/jogg-result.c index 2fcd6d4..c52f762 100644 --- a/src/jogg-result.c +++ b/src/jogg-result.c @@ -30,6 +30,22 @@ static GParamSpec *properties[N_PROPERTIES]; G_DEFINE_TYPE (JoggResult, jogg_result, G_TYPE_OBJECT); +char * +jogg_result_get_action_name ( GObject *object + , JoggResult *self) +{ + if (NULL == self) + { + return NULL; + } + if (NULL == self->action) + { + return NULL; + } + + return g_desktop_app_info_get_action_name (self->app_info, self->action); +} + GIcon * jogg_result_get_icon ( GObject *object , JoggResult *self) @@ -229,6 +245,12 @@ jogg_result_class_init (JoggResultClass *klass) ); } +char * +jogg_result_get_action (JoggResult *self) +{ + return g_strdup (self->action); +} + GDesktopAppInfo * jogg_result_get_app_info (JoggResult *self) { diff --git a/src/jogg-result.h b/src/jogg-result.h index c156cd9..459023f 100644 --- a/src/jogg-result.h +++ b/src/jogg-result.h @@ -23,6 +23,7 @@ G_DECLARE_FINAL_TYPE ( JoggResult , GObject ); +char *jogg_result_get_action (JoggResult *self); GDesktopAppInfo *jogg_result_get_app_info (JoggResult *self); bool jogg_result_is_prefix_match (JoggResult *self); JoggMatchType jogg_result_get_match_type (JoggResult *self); diff --git a/src/res/ui/result.ui b/src/res/ui/result.ui index e80f532..ab8f0c8 100644 --- a/src/res/ui/result.ui +++ b/src/res/ui/result.ui @@ -53,9 +53,9 @@ - + GtkListItem - +