summaryrefslogtreecommitdiff
path: root/gtk/gtkwindow.c
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@redhat.com>2002-09-30 18:58:27 +0000
committerOwen Taylor <otaylor@src.gnome.org>2002-09-30 18:58:27 +0000
commit41030b43c65612fef72f62ba24536ed951c43cf6 (patch)
tree2a90d9e3a7803cfed9ccf1bff1dd6a4911088511 /gtk/gtkwindow.c
parent22e3d3b937b84acd4f2d83e23ddb4f38d37c286a (diff)
downloadgtk+-41030b43c65612fef72f62ba24536ed951c43cf6.tar.gz
Add gtk_window_set_icon_from_file(),
Mon Sep 30 14:28:58 2002 Owen Taylor <otaylor@redhat.com> * gtk/gtkwindow.[ch]: Add gtk_window_set_icon_from_file(), gtk_window_set_default_icon_from_file() convenience functions (#75178, suggestion from Havoc Pennington)
Diffstat (limited to 'gtk/gtkwindow.c')
-rw-r--r--gtk/gtkwindow.c92
1 files changed, 91 insertions, 1 deletions
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
@@ -2641,6 +2700,37 @@ gtk_window_set_default_icon_list (GList *list)
}
/**
+ * 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:
*
* Gets the value set by gtk_window_set_default_icon_list().