diff options
author | Jason Conti <jason.conti@gmail.com> | 2011-05-15 14:05:25 -0400 |
---|---|---|
committer | Jason Conti <jason.conti@gmail.com> | 2011-05-15 14:05:25 -0400 |
commit | 4e29fce998872fa1cf3972d2e1e348327f43714c (patch) | |
tree | 5a1e272c7b1f4af9e62039cfa676f428716e88d8 /src | |
parent | 21ce1c3575c319c2aa230af7f20cc72efbb44094 (diff) | |
download | ayatana-indicator-notifications-4e29fce998872fa1cf3972d2e1e348327f43714c.tar.gz ayatana-indicator-notifications-4e29fce998872fa1cf3972d2e1e348327f43714c.tar.bz2 ayatana-indicator-notifications-4e29fce998872fa1cf3972d2e1e348327f43714c.zip |
Loading the read and unread icons when the image is first requested. TODO: Need to reload them when the icon theme changes.
Diffstat (limited to 'src')
-rw-r--r-- | src/indicator-notifications.c | 58 |
1 files changed, 52 insertions, 6 deletions
diff --git a/src/indicator-notifications.c b/src/indicator-notifications.c index 89c6783..8238e02 100644 --- a/src/indicator-notifications.c +++ b/src/indicator-notifications.c @@ -70,6 +70,9 @@ struct _IndicatorNotifications { struct _IndicatorNotificationsPrivate { GtkImage *image; + GdkPixbuf *pixbuf_read; + GdkPixbuf *pixbuf_unread; + IndicatorServiceManager *sm; DbusmenuGtkMenu *menu; @@ -82,6 +85,8 @@ struct _IndicatorNotificationsPrivate { #define INDICATOR_NOTIFICATIONS_GET_PRIVATE(o) \ (G_TYPE_INSTANCE_GET_PRIVATE ((o), INDICATOR_NOTIFICATIONS_TYPE, IndicatorNotificationsPrivate)) +#define INDICATOR_ICON_SIZE 22 + GType indicator_notifications_get_type(void); static void indicator_notifications_class_init(IndicatorNotificationsClass *klass); @@ -91,6 +96,7 @@ static void indicator_notifications_finalize(GObject *object); static GtkImage *get_image(IndicatorObject *io); static GtkMenu *get_menu(IndicatorObject *io); static const gchar *get_accessible_desc(IndicatorObject *io); +static GdkPixbuf *load_icon(const gchar *, guint); static void receive_signal(GDBusProxy *proxy, gchar *sender_name, gchar *signal_name, GVariant *parameters, gpointer user_data); static void service_proxy_cb(GObject *object, GAsyncResult *res, gpointer user_data); @@ -145,6 +151,10 @@ indicator_notifications_init(IndicatorNotifications *self) self->priv->sm = NULL; self->priv->menu = NULL; + self->priv->image = NULL; + self->priv->pixbuf_read = NULL; + self->priv->pixbuf_unread = NULL; + self->priv->accessible_desc = _("Notifications"); self->priv->sm = indicator_service_manager_new_version(SERVICE_NAME, SERVICE_VERSION); @@ -215,6 +225,16 @@ indicator_notifications_dispose(GObject *object) self->priv->image = NULL; } + if(self->priv->pixbuf_read != NULL) { + g_object_unref(G_OBJECT(self->priv->pixbuf_read)); + self->priv->pixbuf_read = NULL; + } + + if(self->priv->pixbuf_unread != NULL) { + g_object_unref(G_OBJECT(self->priv->pixbuf_unread)); + self->priv->pixbuf_unread = NULL; + } + if(self->priv->menu != NULL) { g_object_unref(G_OBJECT(self->priv->menu)); self->priv->menu = NULL; @@ -253,6 +273,28 @@ receive_signal(GDBusProxy *proxy, gchar *sender_name, gchar *signal_name, return; } +static GdkPixbuf * +load_icon(const gchar *name, guint size) +{ + /* TODO: + * Try to load icon from icon theme before falling back to absolute paths + */ + + GError *error = NULL; + + gchar *path = g_strdup_printf(ICONS_DIR "/%s.svg", name); + GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file_at_scale(path, size, size, FALSE, &error); + + if(error != NULL) { + g_warning("Failed to load icon at '%s': %s", path, error->message); + pixbuf = NULL; + } + + g_free(path); + + return pixbuf; +} + static GtkImage * get_image(IndicatorObject *io) { @@ -261,17 +303,21 @@ get_image(IndicatorObject *io) if(self->priv->image == NULL) { self->priv->image = GTK_IMAGE(gtk_image_new()); - GError *error = NULL; + self->priv->pixbuf_read = load_icon("notification-read", INDICATOR_ICON_SIZE); + + if(self->priv->pixbuf_read == NULL) { + g_error("Failed to load read icon"); + return NULL; + } - GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file_at_scale(ICONS_DIR "/notification-read.svg", 22, 22, FALSE, &error); + self->priv->pixbuf_unread = load_icon("notification-unread", INDICATOR_ICON_SIZE); - if(error != NULL) { - g_error("Failed to load icon: %s", error->message); + if(self->priv->pixbuf_unread == NULL) { + g_error("Failed to load unread icon"); return NULL; } - gtk_image_set_from_pixbuf(self->priv->image, pixbuf); - g_object_unref(pixbuf); + gtk_image_set_from_pixbuf(self->priv->image, self->priv->pixbuf_read); gtk_widget_show(GTK_WIDGET(self->priv->image)); } |