From 44bdae41f77f732f1e0347f32872ecde23984974 Mon Sep 17 00:00:00 2001 From: Rodrigo Moya Date: Mon, 2 Jul 2001 19:36:08 +0000 Subject: new file for a set of functions for managing category-related (icons, 2001-07-02 Rodrigo Moya * e-categories-config.[ch]: new file for a set of functions for managing category-related (icons, colors) configuration svn path=/trunk/; revision=10698 --- e-util/ChangeLog | 5 ++ e-util/Makefile.am | 2 + e-util/e-categories-config.c | 207 +++++++++++++++++++++++++++++++++++++++++++ e-util/e-categories-config.h | 34 +++++++ 4 files changed, 248 insertions(+) create mode 100644 e-util/e-categories-config.c create mode 100644 e-util/e-categories-config.h (limited to 'e-util') diff --git a/e-util/ChangeLog b/e-util/ChangeLog index 5b4627448e..1f7b49db1c 100644 --- a/e-util/ChangeLog +++ b/e-util/ChangeLog @@ -1,3 +1,8 @@ +2001-07-02 Rodrigo Moya + + * e-categories-config.[ch]: new file for a set of functions for + managing category-related (icons, colors) configuration + 2001-07-01 Ettore Perazzoli * e-request.c: New. diff --git a/e-util/Makefile.am b/e-util/Makefile.am index 390b2507a4..08b1f19b0b 100644 --- a/e-util/Makefile.am +++ b/e-util/Makefile.am @@ -16,6 +16,8 @@ noinst_LTLIBRARIES = libeutil.la libeutil-static.la \ libedb3util.la libeutil_la_SOURCES = \ + e-categories-config.c \ + e-categories-config.h \ e-corba-utils.c \ e-corba-utils.h \ e-dialog-widgets.c \ diff --git a/e-util/e-categories-config.c b/e-util/e-categories-config.c new file mode 100644 index 0000000000..9fe3a1e84a --- /dev/null +++ b/e-util/e-categories-config.c @@ -0,0 +1,207 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Categories configuration. + * + * Author: + * Rodrigo Moya + * + * Copyright 2001, Ximian, Inc. + */ + +#include +#include +#include +#include "e-categories-config.h" + +typedef struct { + GdkPixmap *pixmap; + GdkBitmap *mask; +} icon_data_t; + +static GHashTable *cat_colors = NULL; +static GHashTable *cat_icons = NULL; +static gboolean initialized = FALSE; + +static void +initialize_categories_config (void) +{ + g_return_if_fail (initialized == FALSE); + + cat_colors = g_hash_table_new (g_str_hash, g_str_equal); + cat_icons = g_hash_table_new (g_str_hash, g_str_equal); + + initialized = TRUE; +} + +/** + * e_categories_config_get_color_for: + * @category: Category to get the color for. + * + * Returns the representation of the color configured for the given + * category + * + * Returns: An X color specification. + */ +const char * +e_categories_config_get_color_for (const char *category) +{ + char *color; + + g_return_val_if_fail (category != NULL, NULL); + + if (!initialized) + initialize_categories_config (); + + color = g_hash_table_lookup (cat_colors, category); + if (color) + return (const char *) color; + + /* not found, so get it from configuration */ + /* FIXME: use BonoboConf here? */ + + return NULL; +} + +/** + * e_categories_config_set_color_for + */ +void +e_categories_config_set_color_for (const char *category, const char *color) +{ + char *tmp_color; + + g_return_if_fail (category != NULL); + g_return_if_fail (color != NULL); + + if (!initialized) + initialize_categories_config (); + + tmp_color = g_hash_table_lookup (cat_colors, category); + if (tmp_color != NULL) { + g_hash_table_remove (cat_colors, category); + g_free (tmp_color); + } + + /* add new color to the hash table */ + tmp_color = g_strdup (color); + g_hash_table_insert (cat_colors, (gpointer) category, (gpointer) category); + + /* FIXME: ...and to the configuration */ +} + +/** + * e_categories_config_get_icon_for: + * @category: Category for which to get the icon. + * @icon: A pointer to where the pixmap will be returned. + * @mask: A pointer to where the mask will be returned. + * + * Returns the icon (and associated mask) configured for the + * given category. + */ +void +e_categories_config_get_icon_for (const char *category, GdkPixmap **pixmap, GdkBitmap **mask) +{ + icon_data_t *icon_data; + + g_return_if_fail (category != NULL); + g_return_if_fail (pixmap != NULL); + + if (!initialized) + initialize_categories_config (); + + icon_data = g_hash_table_lookup (cat_icons, category); + if (icon_data != NULL) { + *pixmap = icon_data->pixmap; + if (mask != NULL) + *mask = icon_data->mask; + return; + } + + /* not found, so look in the configuration */ + /* FIXME: use BonoboConf here */ + + *pixmap = NULL; + if (mask != NULL) + *mask = NULL; +} + +/** + * e_categories_config_set_icon_for + * @category: Category for which to set the icon. + * @pixmap_file: Full path of the pixmap file. + */ +void +e_categories_config_set_icon_for (const char *category, const char *pixmap_file) +{ + icon_data_t *icon_data; + + g_return_if_fail (category != NULL); + g_return_if_fail (pixmap_file != NULL); + + if (!initialized) + initialize_categories_config (); + + icon_data = g_hash_table_lookup (cat_icons, category); + if (icon_data != NULL) { + g_hash_table_remove (cat_icons, category); + + gdk_pixmap_unref (icon_data->pixmap); + gdk_bitmap_unref (icon_data->mask); + g_free (icon_data); + } + + /* add new pixmap from file to the list */ + icon_data = g_new (icon_data_t, 1); + icon_data->pixmap = gdk_pixmap_create_from_xpm (NULL, &icon_data->mask, NULL, pixmap_file); + g_hash_table_insert (cat_icons, (gpointer) category, (gpointer) icon_data); + + /* FIXME: ...and to the configuration */ +} + +/** + * e_categories_config_open_dialog_for_entry: + * entry: A GtkEntry on which to get/set the categories list. + * + * This is a self-contained function that lets you open a popup dialog for + * the user to select a list of categories. + * + * The @entry parameter is used, at initialization time, as the list of + * initial categories that are selected in the categories selection dialog. + * Then, when the user commits its changes, the list of selected categories + * is put back on the entry widget. + */ +void +e_categories_config_open_dialog_for_entry (GtkEntry *entry) +{ + char *categories; + GnomeDialog *dialog; + int result; + GString *cat_icons; + GString *cat_colors; + + g_return_if_fail (entry != NULL); + g_return_if_fail (GTK_IS_ENTRY (entry)); + + categories = e_utf8_gtk_entry_get_text (GTK_ENTRY (entry)); + dialog = GNOME_DIALOG (e_categories_new (categories)); + + /* FIXME: get icons/colors per category from configuration + and pass them to the ECategories widget */ + + /* run the dialog */ + result = gnome_dialog_run (dialog); + g_free (categories); + + if (result == 0) { + gtk_object_get (GTK_OBJECT (dialog), + "categories", &categories, + NULL); + e_utf8_gtk_entry_set_text (GTK_ENTRY (entry), categories); + g_free (categories); + } + + /* FIXME: now get icons/colors associated with each category from the + ECategories widget, and set them to the configuration */ + + gtk_object_destroy (GTK_OBJECT (dialog)); +} diff --git a/e-util/e-categories-config.h b/e-util/e-categories-config.h new file mode 100644 index 0000000000..9ad0b5fe09 --- /dev/null +++ b/e-util/e-categories-config.h @@ -0,0 +1,34 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Categories configuration. + * + * Author: + * Rodrigo Moya + * + * Copyright 2001, Ximian, Inc. + */ + +#ifndef __E_CATEGORIES_CONFIG_H__ +#define __E_CATEGORIES_CONFIG_H__ + +#include +#include +#include +#include + +BEGIN_GNOME_DECLS + +const char *e_categories_config_get_color_for (const char *category); +void e_categories_config_set_color_for (const char *category, const char *color); + +void e_categories_config_get_icon_for (const char *category, + GdkPixmap **icon, + GdkBitmap **mask); +void e_categories_config_set_icon_for (const char *category, + const char *pixmap_file); + +void e_categories_config_open_dialog_for_entry (GtkEntry *entry); + +END_GNOME_DECLS + +#endif -- cgit v1.2.3