Skip to content

Commit

Permalink
result: Use closure for icons
Browse files Browse the repository at this point in the history
The indirection via a property isn’t really needed.
  • Loading branch information
ernestask committed Jul 21, 2024
1 parent 7f1cbb8 commit 13297ee
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
43 changes: 24 additions & 19 deletions src/jogg-result.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ enum { PROP_APP_INFO = 1
, PROP_MATCH_TYPE
, PROP_PREFIX_MATCH
, PROP_HIDDEN
, PROP_ICON
, PROP_LABEL
, N_PROPERTIES
};
Expand All @@ -31,6 +30,30 @@ static GParamSpec *properties[N_PROPERTIES];

G_DEFINE_TYPE (JoggResult, jogg_result, G_TYPE_OBJECT);

GIcon *
jogg_result_get_icon ( GObject *object
, JoggResult *self)
{
GIcon *icon = NULL;

if (NULL == self)
{
return NULL;
}

icon = g_app_info_get_icon (G_APP_INFO (self->app_info));
if (NULL == icon)
{
icon = g_icon_new_for_string ("application-x-executable", NULL);
}
else
{
icon = g_object_ref (icon);
}

return icon;
}

gboolean
jogg_result_is_action_visible (GObject *object,
JoggResult *self)
Expand Down Expand Up @@ -71,7 +94,6 @@ jogg_result_get_property ( GObject *object
{
JoggResult *self = NULL;
gboolean nodisplay = false;
GIcon *icon = NULL;
const char *name = NULL;

self = JOGG_RESULT (object);
Expand All @@ -95,15 +117,6 @@ jogg_result_get_property ( GObject *object

g_value_set_boolean (value, nodisplay);
break;
case PROP_ICON:
icon = g_app_info_get_icon (G_APP_INFO (self->app_info));
if (NULL == icon)
{
icon = g_icon_new_for_string ("application-x-executable", NULL);
}

g_value_set_object (value, icon);
break;
case PROP_LABEL:
name = g_app_info_get_name (G_APP_INFO (self->app_info));

Expand Down Expand Up @@ -197,14 +210,6 @@ jogg_result_class_init (JoggResultClass *klass)
| G_PARAM_STATIC_STRINGS
)
);
properties[PROP_ICON] = g_param_spec_object ( "icon"
, NULL
, NULL
, G_TYPE_ICON
, ( G_PARAM_READABLE
| G_PARAM_STATIC_STRINGS
)
);
properties[PROP_LABEL] = g_param_spec_string ( "label"
, NULL
, NULL
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 @@ -13,9 +13,9 @@
<child>
<object class='GtkImage'>
<binding name='gicon'>
<lookup name='icon' type='JoggResult'>
<closure type='GIcon' function='jogg_result_get_icon'>
<lookup name='item'>GtkListItem</lookup>
</lookup>
</closure>
</binding>
<property name='icon-size'>large</property>
</object>
Expand Down

0 comments on commit 13297ee

Please sign in to comment.