Skip to content

Commit

Permalink
result: Implement launching actions
Browse files Browse the repository at this point in the history
This commit builds on top of 7f1cbb8 to
provide the ability to launch matching actions.

Relates to #5.
  • Loading branch information
ernestask committed Jul 21, 2024
1 parent eb74f00 commit 5ae55e6
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
12 changes: 11 additions & 1 deletion src/jogg-application-window.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
7 changes: 5 additions & 2 deletions src/jogg-application.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions src/jogg-result.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions src/jogg-result.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/res/ui/result.ui
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
<child>
<object class='GtkLabel'>
<binding name='label'>
<lookup name='action' type='JoggResult'>
<closure type='gchararray' function='jogg_result_get_action_name'>
<lookup name='item'>GtkListItem</lookup>
</lookup>
</closure>
</binding>
</object>
</child>
Expand Down

0 comments on commit 5ae55e6

Please sign in to comment.