diff --git a/ChangeLog b/ChangeLog index 6312bde06d..677ad3943f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Mon Sep 30 14:28:58 2002 Owen Taylor + + * gtk/gtkwindow.[ch]: Add gtk_window_set_icon_from_file(), + gtk_window_set_default_icon_from_file() convenience + functions (#75178, suggestion from Havoc Pennington) + 2002-09-30 Daniel Elstner * gtk/gtktextbuffer.c: Add construct-only property "tag_table" diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 6312bde06d..677ad3943f 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,9 @@ +Mon Sep 30 14:28:58 2002 Owen Taylor + + * gtk/gtkwindow.[ch]: Add gtk_window_set_icon_from_file(), + gtk_window_set_default_icon_from_file() convenience + functions (#75178, suggestion from Havoc Pennington) + 2002-09-30 Daniel Elstner * gtk/gtktextbuffer.c: Add construct-only property "tag_table" diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 6312bde06d..677ad3943f 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,9 @@ +Mon Sep 30 14:28:58 2002 Owen Taylor + + * gtk/gtkwindow.[ch]: Add gtk_window_set_icon_from_file(), + gtk_window_set_default_icon_from_file() convenience + functions (#75178, suggestion from Havoc Pennington) + 2002-09-30 Daniel Elstner * gtk/gtktextbuffer.c: Add construct-only property "tag_table" diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 6312bde06d..677ad3943f 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,9 @@ +Mon Sep 30 14:28:58 2002 Owen Taylor + + * gtk/gtkwindow.[ch]: Add gtk_window_set_icon_from_file(), + gtk_window_set_default_icon_from_file() convenience + functions (#75178, suggestion from Havoc Pennington) + 2002-09-30 Daniel Elstner * gtk/gtktextbuffer.c: Add construct-only property "tag_table" diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 6312bde06d..677ad3943f 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,9 @@ +Mon Sep 30 14:28:58 2002 Owen Taylor + + * gtk/gtkwindow.[ch]: Add gtk_window_set_icon_from_file(), + gtk_window_set_default_icon_from_file() convenience + functions (#75178, suggestion from Havoc Pennington) + 2002-09-30 Daniel Elstner * gtk/gtktextbuffer.c: Add construct-only property "tag_table" diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 6312bde06d..677ad3943f 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,9 @@ +Mon Sep 30 14:28:58 2002 Owen Taylor + + * gtk/gtkwindow.[ch]: Add gtk_window_set_icon_from_file(), + gtk_window_set_default_icon_from_file() convenience + functions (#75178, suggestion from Havoc Pennington) + 2002-09-30 Daniel Elstner * gtk/gtktextbuffer.c: Add construct-only property "tag_table" diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c index d78bed8e49..3ba62412c2 100644 --- a/gtk/gtkwindow.c +++ b/gtk/gtkwindow.c @@ -2557,7 +2557,10 @@ gtk_window_set_icon (GtkWindow *window, g_return_if_fail (icon == NULL || GDK_IS_PIXBUF (icon)); list = NULL; - list = g_list_append (list, icon); + + if (icon) + list = g_list_append (list, icon); + gtk_window_set_icon_list (window, list); g_list_free (list); } @@ -2586,6 +2589,62 @@ gtk_window_get_icon (GtkWindow *window) return NULL; } +/* Load pixbuf, printing warning on failure if error == NULL + */ +static GdkPixbuf * +load_pixbuf_verbosely (const char *filename, + GError **err) +{ + GError *local_err = NULL; + GdkPixbuf *pixbuf; + + pixbuf = gdk_pixbuf_new_from_file (filename, &local_err); + + if (!pixbuf) + { + if (err) + *err = local_err; + else + { + g_warning ("Error loading icon from file '%s':\n\t%s", + filename, local_err->message); + g_error_free (local_err); + } + } + + return pixbuf; +} + +/** + * gtk_window_set_icon_from_file: + * @window: a #GtkWindow + * @list: a list of #GdkPixbuf + * @err: location to store error, or %NULL. + * + * Sets the icon for @wi + * had gtk_window_set_icon_list() called on them as a single file. + * Warns on failure if @err is %NULL. + * + * Returns: %TRUE if setting the icon succeeded. + **/ +gboolean +gtk_window_set_icon_from_file (GtkWindow *window, + const gchar *filename, + GError **err) +{ + GdkPixbuf *pixbuf = load_pixbuf_verbosely (filename, err); + + if (pixbuf) + { + gtk_window_set_icon (window, pixbuf); + g_object_unref (pixbuf); + + return TRUE; + } + else + return FALSE; +} + /** * gtk_window_set_default_icon_list: * @list: a list of #GdkPixbuf @@ -2640,6 +2699,37 @@ gtk_window_set_default_icon_list (GList *list) g_list_free (toplevels); } +/** + * gtk_window_set_default_icon_from_file: + * @filename: location of icon file + * @err: location to store error, or %NULL. + * + * Sets an icon to be used as fallback for windows that haven't + * had gtk_window_set_icon_list() called on them from a file + * on disk. Warns on failure if @error is %NULL. + * + * Returns: %TRUE if setting the icon succeeded. + **/ +gboolean +gtk_window_set_default_icon_from_file (const gchar *filename, + GError **err) +{ + GdkPixbuf *pixbuf = load_pixbuf_verbosely (filename, err); + + if (pixbuf) + { + GList *list = g_list_prepend (NULL, pixbuf); + gtk_window_set_default_icon_list (list); + g_list_free (list); + + g_object_unref (pixbuf); + + return TRUE; + } + else + return FALSE; +} + /** * gtk_window_get_default_icon_list: * diff --git a/gtk/gtkwindow.h b/gtk/gtkwindow.h index d760933b78..35ff2ca8ea 100644 --- a/gtk/gtkwindow.h +++ b/gtk/gtkwindow.h @@ -246,9 +246,15 @@ void gtk_window_set_icon_list (GtkWindow *window, GList* gtk_window_get_icon_list (GtkWindow *window); void gtk_window_set_icon (GtkWindow *window, GdkPixbuf *icon); +gboolean gtk_window_set_icon_from_file (GtkWindow *window, + const gchar *filename, + GError **err); GdkPixbuf* gtk_window_get_icon (GtkWindow *window); void gtk_window_set_default_icon_list (GList *list); GList* gtk_window_get_default_icon_list (void); +gboolean gtk_window_set_default_icon_from_file (const gchar *filename, + GError **err); + /* If window is set modal, input will be grabbed when show and released when hide */ void gtk_window_set_modal (GtkWindow *window,