* e-shell-folder-title-bar.c: Remove some `#if 0'ed broken code. New members title_icon and title_button_icon in struct EShellFolderTitleBarPrivate. Remove member icon_widget. New static global variable empty_pixbuf. (init): Initialize these new members to NULL. Don't initialize icon_widget anymore since it's gone. (e_shell_folder_title_bar_construct): Create the title_button_icon and pack it into the title_button_hbox. Also, create the title_icon and pack that one as well. Retouched some of the hardcoded padding values. (size_allocate_icon): Rewritten to use the title_icon and return the allocated space like size_allocate_navigation_buttons. (e_shell_folder_title_bar_set_icon): Remove bogus const from the @icon arg. Ref the pixbuf, and update the two pixmap widgets from it. If @icon is NULL, use the empty_pixbuf. (impl_destroy): Renamed from destroy(). (realize): Removed. (unrealize): Removed. (impl_size_allocate): Renamed from size_allocate(). (class_init): Call it. (add_icon_widget): Removed. (new_empty_pixbuf): New. (new_empty_pixmap_widget): New. (size_allocate_navigation_buttons_and_title_icon): Renamed from size_allocate_navigation_buttons; set up the title_icon too. * e-shell-view.c (update_folder_title_bar): Unref the folder_icon after using it. * e-icon-factory.c (e_icon_factory_get_icon): Ref the returned pixbuf. svn path=/trunk/; revision=17419
163 lines
3.6 KiB
C
163 lines
3.6 KiB
C
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
|
||
/* e-icon-factory.c - Icon factory for the Evolution shell.
|
||
*
|
||
* Copyright (C) 2002 Ximian, Inc.
|
||
*
|
||
* This program is free software; you can redistribute it and/or
|
||
* modify it under the terms of version 2 of the GNU General Public
|
||
* License as published by the Free Software Foundation.
|
||
*
|
||
* This program is distributed in the hope that it will be useful,
|
||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
* General Public License for more details.
|
||
*
|
||
* You should have received a copy of the GNU General Public
|
||
* License along with this program; if not, write to the
|
||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||
* Boston, MA 02111-1307, USA.
|
||
*
|
||
* Author: Ettore Perazzoli <ettore@ximian.com>
|
||
*/
|
||
|
||
#ifdef HAVE_CONFIG_H
|
||
#include <config.h>
|
||
#endif
|
||
|
||
#include "e-icon-factory.h"
|
||
|
||
#include "e-shell-constants.h"
|
||
|
||
|
||
/* One icon. Keep both a small (16x16) and a large (48x48) version around. */
|
||
struct _Icon {
|
||
char *name;
|
||
GdkPixbuf *small_pixbuf;
|
||
GdkPixbuf *large_pixbuf;
|
||
};
|
||
typedef struct _Icon Icon;
|
||
|
||
/* Hash of all the icons. */
|
||
static GHashTable *name_to_icon = NULL;
|
||
|
||
|
||
/* Creating and destroying icons. */
|
||
|
||
static Icon *
|
||
icon_new (const char *name,
|
||
GdkPixbuf *small_pixbuf,
|
||
GdkPixbuf *large_pixbuf)
|
||
{
|
||
Icon *icon;
|
||
|
||
icon = g_new (Icon, 1);
|
||
icon->name = g_strdup (name);
|
||
icon->small_pixbuf = small_pixbuf;
|
||
icon->large_pixbuf = large_pixbuf;
|
||
|
||
if (small_pixbuf != NULL)
|
||
gdk_pixbuf_ref (small_pixbuf);
|
||
if (large_pixbuf != NULL)
|
||
gdk_pixbuf_ref (large_pixbuf);
|
||
|
||
return icon;
|
||
}
|
||
|
||
#if 0
|
||
|
||
/* (This is not currently used since we never prune icons out of the
|
||
cache.) */
|
||
static void
|
||
icon_free (Icon *icon)
|
||
{
|
||
g_free (icon->name);
|
||
|
||
if (icon->large_pixbuf != NULL)
|
||
gdk_pixbuf_unref (icon->large_pixbuf);
|
||
if (icon->small_pixbuf != NULL)
|
||
gdk_pixbuf_unref (icon->small_pixbuf);
|
||
|
||
g_free (icon);
|
||
}
|
||
|
||
#endif
|
||
|
||
|
||
/* Loading icons. */
|
||
|
||
static Icon *
|
||
load_icon (const char *icon_name)
|
||
{
|
||
GdkPixbuf *small_pixbuf;
|
||
GdkPixbuf *large_pixbuf;
|
||
Icon *icon;
|
||
char *path;
|
||
|
||
path = g_strconcat (EVOLUTION_IMAGES, "/", icon_name, "-mini.png", NULL);
|
||
small_pixbuf = gdk_pixbuf_new_from_file (path);
|
||
g_free (path);
|
||
|
||
path = g_strconcat (EVOLUTION_IMAGES, "/", icon_name, ".png", NULL);
|
||
large_pixbuf = gdk_pixbuf_new_from_file (path);
|
||
g_free (path);
|
||
|
||
if (large_pixbuf == NULL || small_pixbuf == NULL)
|
||
return NULL;
|
||
|
||
icon = icon_new (icon_name, small_pixbuf, large_pixbuf);
|
||
|
||
gdk_pixbuf_unref (small_pixbuf);
|
||
gdk_pixbuf_unref (large_pixbuf);
|
||
|
||
return icon;
|
||
}
|
||
|
||
|
||
/* Public API. */
|
||
|
||
void
|
||
e_icon_factory_init (void)
|
||
{
|
||
if (name_to_icon != NULL) {
|
||
/* Already initialized. */
|
||
return;
|
||
}
|
||
|
||
name_to_icon = g_hash_table_new (g_str_hash, g_str_equal);
|
||
}
|
||
|
||
GdkPixbuf *
|
||
e_icon_factory_get_icon (const char *icon_name,
|
||
gboolean mini)
|
||
{
|
||
Icon *icon;
|
||
|
||
g_return_val_if_fail (icon_name != NULL, NULL);
|
||
|
||
icon = g_hash_table_lookup (name_to_icon, icon_name);
|
||
if (icon == NULL) {
|
||
icon = load_icon (icon_name);
|
||
if (icon == NULL) {
|
||
g_warning ("Icon not found -- %s", icon_name);
|
||
|
||
/* Create an empty icon so that we don't keep spitting
|
||
out the same warning over and over, every time this
|
||
icon is requested. */
|
||
|
||
icon = icon_new (icon_name, NULL, NULL);
|
||
g_hash_table_insert (name_to_icon, icon->name, icon);
|
||
return NULL;
|
||
}
|
||
|
||
g_hash_table_insert (name_to_icon, icon->name, icon);
|
||
}
|
||
|
||
if (mini) {
|
||
gdk_pixbuf_ref (icon->small_pixbuf);
|
||
return icon->small_pixbuf;
|
||
} else {
|
||
gdk_pixbuf_ref (icon->large_pixbuf);
|
||
return icon->large_pixbuf;
|
||
}
|
||
}
|