Reputation: 2035
all. I'm trying to display an icon in my notification, see relevant code:
GIcon* gicon_from_path (const gchar* path)
{
GFile *file = NULL;
GIcon *tmp = NULL;
file = g_file_new_for_path (path);
tmp = g_file_icon_new (file);
g_object_unref (file);
return tmp;
}
GIcon* gicon_from_resource (const gchar* res)
{
GFile *file = NULL;
GIcon *tmp = NULL;
file = g_file_new_for_uri (res);
tmp = g_file_icon_new (file);
g_object_unref (file);
return tmp;
}
void send_notification (GApplication *application)
{
GNotification *notification;
GIcon *icon;
//icon = gicon_from_path (PACKAGE_DATADIR "/gtk3-demo-icon_32.png");
icon = gicon_from_resource ("resource:///button/icons/tray.png");
notification = g_notification_new ("Hola");
g_notification_set_body (notification, "Probando");
if (icon)
{
g_print ("Have icon");
g_notification_set_icon (notification, icon);
}
g_application_send_notification (application, "lunch-is-ready", notification);
g_object_unref (icon);
g_object_unref (notification);
}
void on_clicked (GtkWidget *self, gpointer user_data)
{
PMYDATA pD = user_data; // my app data
send_notification (G_APPLICATION (pD->app));
}
If I use gicon_from_path the icon is showed as expected. But with gicon_from_resource not only the icon is not showed, I get this messages:
(gtk3_single:3256): GLib-CRITICAL **: 07:18:23.627: g_variant_new_take_string: assertion 'string != NULL' failed
(gtk3_single:3256): GLib-CRITICAL **: 07:18:23.627: g_variant_new_variant: assertion 'value != NULL' failed
(gtk3_single:3256): GLib-CRITICAL **: 07:18:23.627: g_variant_get_type: assertion 'value != NULL' failed
(gtk3_single:3256): GLib-CRITICAL **: 07:18:23.628: g_variant_type_is_subtype_of: assertion 'g_variant_type_check (type)' failed
(gtk3_single:3256): GLib-CRITICAL **: 07:18:23.628: g_variant_builder_add_value: assertion '!GVSB(builder)->expected_type || g_variant_is_of_type (value, GVSB(builder)->expected_type)' failed
(gtk3_single:3256): GLib-CRITICAL **: 07:18:23.628: g_variant_builder_end: assertion 'GVSB(builder)->offset >= GVSB(builder)->min_items' failed
(gtk3_single:3256): GLib-CRITICAL **: 07:18:23.628: g_variant_get_type: assertion 'value != NULL' failed
(gtk3_single:3256): GLib-CRITICAL **: 07:18:23.628: g_variant_type_is_subtype_of: assertion 'g_variant_type_check (type)' failed
(gtk3_single:3256): GLib-CRITICAL **: 07:18:23.628: g_variant_builder_add_value: assertion '!GVSB(builder)->expected_type || g_variant_is_of_type (value, GVSB(builder)->expected_type)' failed
In both cases, I can see the message Have icon from g_print
. So I guess is something in g_file_new_for_uri
. Btw, this is my .gresource.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<!-- to use with gtk3 -->
<gresources>
<gresource prefix="/main/icons/">
<file alias="16x16/apps/gtk3_single.png">gtk3-demo-icon_16.png</file>
<file alias="32x32/apps/gtk3_single.png">Cat-icon_32.png</file>
<file alias="48x48/apps/gtk3_single.png">cat-food-hearts-icon_48.png</file>
</gresource>
<gresource prefix="/button/icons">
<file alias="home.png">Home-icon_24.png</file>
<file alias="tray.png">gtk3-demo-icon_32.png</file>
</gresource>
<gresource prefix="/menu/icons">
<file alias="quit">Actions-application-exit-icon_20.png</file>
</gresource>
</gresources>
My OS is Archlinux using gtk3 3.24.34. So, any help or ideas?
Upvotes: 0
Views: 133