gnome-window-icon.[ch], again



hello,

here is my proposed gnome-window-icon api.  the differences between it
and the gnome 1 version are that the _from_imlib() versions are gone,
and there are _from_file_list() versions added, and _set_from_default()
does nothing (since gtk 2.0 does this for us).

there are no _from_pixbuf() since there is gtk api to do this.

this is basically a wrapper around the gtk window functions, except
these take string arguments and load the pixbufs for you (which is much
simpler imho).

if you want to ask about api freezes, this should be added now because
it was in gnome 1.2+, but it was not in gnome-libs when the original
gnome 2.0 branches were made, so hasn't been in libgnomeui 2 yet.



jacob
-- 
"It drains me, and it shakes me, and hurts like hell everytime I play
it, looking out at thousands of people cheering and smiling, oblivious
to the tragedy of it's meaning, like when you're going to have your
dog put down and it's wagging it's tail on the way there." - Thom Yorke
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/*
 * gnome-window-icon.h: convenience functions for window mini-icons
 *
 * Copyright 2000 Helix Code, Inc.
 *
 * Author:  Jacob Berkman  <jacob helixcode com>
 */

/*
 * These functions are a convenience wrapper for the gdk_window_set_icon()
 * function.  They allow setting a default icon, which is used by many
 * top level windows in libgnomeui, such as GnomeApp and GnomeDialog
 * windows.
 *
 * They also handle drawing the icon on the iconified window's icon in
 * window managers such as TWM and Window Maker.
 *
 * These functions were added with the 1.2.0 release of the GNOME libraries
 * in May, 2000.  This means that not all users will have this functionality
 * in the GNOME libraries, and should only be used accordingly.  The header file
 * must be explicitely included, also (#include <libgnomeui/gnome-window-icon.h>).
 */

#ifndef GNOME_WINDOW_ICON_H
#define GNOME_WINDOW_ICON_H

#include <gtk/gtkwindow.h>

G_BEGIN_DECLS

/* set an icon on a window */
void gnome_window_icon_set_from_default   (GtkWindow *w);
void gnome_window_icon_set_from_file      (GtkWindow *w, const char  *filename);
void gnome_window_icon_set_from_file_list (GtkWindow *w, const char **filenames);

/* set the default icon used */
void gnome_window_icon_set_default_from_file      (const char  *filename);
void gnome_window_icon_set_default_from_file_list (const char **filenames);

/* check for the GNOME_DESKTOP_ICON environment variable */
void gnome_window_icon_init (void);

G_END_DECLS

#endif /* GNOME_WINDOW_ICON_H */
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/*
 * gnome-window-icon.c: convenience functions for window mini-icons
 *
 * Copyright 2000, 2001 Ximian, Inc.
 *
 * Author:  Jacob Berkman  <jacob ximian com>
 */

#include "config.h"

#include "libgnomeui/gnome-window-icon.h"

#include <gdk/gdkpixbuf.h>
#include "libgnomeui/gnome-client.h"

#include <stdlib.h>

#define GNOME_DESKTOP_ICON "GNOME_DESKTOP_ICON"

static GList *
list_from_char_array (const char **s)
{
	GList *list = NULL;
	int i;
	
	for (i = 0; s[i]; i++) {
		GdkPixbuf *pb;

		pb = gdk_pixbuf_new_from_file (s[i], NULL);
		if (pb)
			list = g_list_prepend (list, pb);
	}

	return list;
}

static void
free_list (GList *list)
{
	g_list_foreach (list, (GFunc) g_object_unref, NULL);
	g_list_free (list);
}

/**
 * gnome_window_icon_set_from_default:
 * @w: the #GtkWidget to set the icon on
 *
 * Description: Makes the #GtkWindow @w use the default icon.
 */
void
gnome_window_icon_set_from_default (GtkWindow *w)
{
}

/**
 * gnome_window_icon_set_from_file_list:
 * @w: window to set icons on
 * @filenames: NULL terminated string array
 * 
 * Description: Convenience wrapper around gtk_window_set_icon_list(),
 * which loads the icons in @filenames.
 **/
void
gnome_window_icon_set_from_file_list (GtkWindow *w, const char **filenames)
{
	GList *list;

	list = list_from_char_array (filenames);
	gtk_window_set_icon_list (w, list);
	free_list (list);
}

/**
 * gnome_window_icon_set_from_file:
 * @w: the #GtkWidget to set the icon on
 * @filename: the name of the file to load
 *
 * Description: Makes the #GtkWindow @w use the icon in @filename.
 */
void
gnome_window_icon_set_from_file (GtkWindow *w, const char *filename)
{
	const char *filenames[2] = { NULL };

	filenames[0] = filename;
	gnome_window_icon_set_from_file_list (w, filenames);
}

/**
 * gnome_window_icon_set_default_from_file_list:
 * @filenames: NULL terminated string array
 * 
 * Description: Wrapper around gtk_window_set_default_icon_list(),
 * which loads the icons in @filenames.
 **/
void
gnome_window_icon_set_default_from_file_list (const char **filenames)
{
	GList *list;

	list = list_from_char_array (filenames);
	gtk_window_set_default_icon_list (list);
	free_list (list);
}

/**
 * gnome_window_icon_set_default_from_file:
 * @filename: filename for the default window icon
 *
 * Description: Set the default icon to the image in @filename, if one 
 * of the gnome_window_icon_set_default_from* functions have not already
 * been called.
 */
void
gnome_window_icon_set_default_from_file (const char *filename)
{	
	const char **filenames[2] = { NULL };

	filenames[0] = filename;
	gnome_window_icon_set_default_from_file_list (filenames);
}

/**
 * gnome_window_icon_init:
 *
 * Description: Initialize the gnome window icon by checking the
 * GNOME_DESKTOP_ICON environment variable.  This function is 
 * automatically called by the gnome_init process.
 */
void
gnome_window_icon_init ()
{
	GnomeClient *client;
	char *filename;

	filename = getenv (GNOME_DESKTOP_ICON);
        if (!filename || !filename[0])
		return;

	gnome_window_icon_set_default_from_file (filename);

	/* remove it from our environment */
	putenv (GNOME_DESKTOP_ICON);

	client = gnome_master_client ();
	if (!GNOME_CLIENT_CONNECTED (client))
		return;
	
	/* save it for restarts */
	gnome_client_set_environment (client, GNOME_DESKTOP_ICON, filename);
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]