aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--widgets/shortcut-bar/e-shortcut-bar.c61
-rw-r--r--widgets/shortcut-bar/e-shortcut-bar.h19
-rw-r--r--widgets/shortcut-bar/test-shortcut-bar.c38
4 files changed, 85 insertions, 41 deletions
diff --git a/ChangeLog b/ChangeLog
index 2cccfb6734..f8dd591db2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2000-03-31 Damon Chaplin <damon@helixcode.com>
+
+ * widgets/shortcut-bar/e-shortcut-bar.[hc]: added support for a
+ callback function to set the icons.
+
+ * widgets/shortcut-bar/test-shortcut-bar.c: updated to use the
+ callback function.
+
2000-03-31 Christopher James Lahey <clahey@helixcode.com>
* addressbook/demo/demo.c, addressbook/demo/addressbook-widget.c:
diff --git a/widgets/shortcut-bar/e-shortcut-bar.c b/widgets/shortcut-bar/e-shortcut-bar.c
index 6225229d53..daa6bfde59 100644
--- a/widgets/shortcut-bar/e-shortcut-bar.c
+++ b/widgets/shortcut-bar/e-shortcut-bar.c
@@ -44,24 +44,9 @@ static GtkTargetEntry target_table[] = {
};
static guint n_targets = sizeof(target_table) / sizeof(target_table[0]);
-typedef struct _EShortcutBarBuiltinType EShortcutBarBuiltinType;
-struct _EShortcutBarBuiltinType {
- gchar *name;
- gchar *filename;
- GdkPixbuf *image;
-};
-
-EShortcutBarBuiltinType e_shortcut_bar_builtin_types[] = {
- { "folder:", "evolution/evolution-inbox.png", NULL },
- { "calendar:", "evolution/evolution-calendar.png", NULL },
- { "todo:", "evolution/evolution-tasks.png", NULL },
- { "contacts:", "evolution/evolution-contacts.png", NULL }
-};
-static gint e_shortcut_bar_num_builtin_types = sizeof (e_shortcut_bar_builtin_types) / sizeof (EShortcutBarBuiltinType);
-
-gboolean e_shortcut_bar_default_type_image_loaded = FALSE;
-GdkPixbuf *e_shortcut_bar_default_type_image = NULL;
-gchar *e_shortcut_bar_default_type_filename = "gnome-balsa2.png";
+gboolean e_shortcut_bar_default_icon_loaded = FALSE;
+GdkPixbuf *e_shortcut_bar_default_icon = NULL;
+gchar *e_shortcut_bar_default_icon_filename = "gnome-folder.png";
static void e_shortcut_bar_class_init (EShortcutBarClass *class);
static void e_shortcut_bar_init (EShortcutBar *shortcut_bar);
@@ -517,32 +502,34 @@ e_shortcut_bar_stop_editing (GtkWidget *button,
}
+/* Sets the callback which is called to return the icon to use for a particular
+ URL. */
+void
+e_shortcut_bar_set_icon_callback (EShortcutBar *shortcut_bar,
+ EShortcutBarIconCallback cb)
+{
+ shortcut_bar->icon_callback = cb;
+}
+
+
static GdkPixbuf *
e_shortcut_bar_get_image_from_url (EShortcutBar *shortcut_bar,
gchar *item_url)
{
- gchar *method_terminator;
- gint method_len, i;
-
- method_terminator = strchr (item_url, ':');
- if (method_terminator) {
- method_len = method_terminator - item_url + 1;
-
- /* Check if it is a builtin type. */
- for (i = 0; i < e_shortcut_bar_num_builtin_types; i++) {
- if (!strncmp (item_url, e_shortcut_bar_builtin_types[i].name, method_len)) {
- if (!e_shortcut_bar_builtin_types[i].image)
- e_shortcut_bar_builtin_types[i].image = e_shortcut_bar_load_image (e_shortcut_bar_builtin_types[i].filename);
- return e_shortcut_bar_builtin_types[i].image;
- }
+ GdkPixbuf *icon = NULL;
+
+ if (shortcut_bar->icon_callback)
+ icon = (*shortcut_bar->icon_callback) (shortcut_bar, item_url);
+
+ if (!icon) {
+ if (!e_shortcut_bar_default_icon_loaded) {
+ e_shortcut_bar_default_icon_loaded = TRUE;
+ e_shortcut_bar_default_icon = e_shortcut_bar_load_image (e_shortcut_bar_default_icon_filename);
}
+ icon = e_shortcut_bar_default_icon;
}
- if (!e_shortcut_bar_default_type_image_loaded) {
- e_shortcut_bar_default_type_image_loaded = TRUE;
- e_shortcut_bar_default_type_image = e_shortcut_bar_load_image (e_shortcut_bar_default_type_filename);
- }
- return e_shortcut_bar_default_type_image;
+ return icon;
}
diff --git a/widgets/shortcut-bar/e-shortcut-bar.h b/widgets/shortcut-bar/e-shortcut-bar.h
index ff7702f869..0164bf1c94 100644
--- a/widgets/shortcut-bar/e-shortcut-bar.h
+++ b/widgets/shortcut-bar/e-shortcut-bar.h
@@ -37,6 +37,12 @@ extern "C" {
* window so users can easily access items such as folders and files.
*/
+typedef struct _EShortcutBar EShortcutBar;
+typedef struct _EShortcutBarClass EShortcutBarClass;
+
+
+typedef GdkPixbuf* (*EShortcutBarIconCallback) (EShortcutBar *shortcut_bar,
+ gchar *url);
/* This contains information on one group. */
typedef struct _EShortcutBarGroup EShortcutBarGroup;
@@ -55,9 +61,6 @@ struct _EShortcutBarGroup
#define E_IS_SHORTCUT_BAR(obj) GTK_CHECK_TYPE (obj, e_shortcut_bar_get_type ())
-typedef struct _EShortcutBar EShortcutBar;
-typedef struct _EShortcutBarClass EShortcutBarClass;
-
struct _EShortcutBar
{
EGroupBar group_bar;
@@ -65,6 +68,10 @@ struct _EShortcutBar
/* This is an array of EShortcutBarGroup elements. */
GArray *groups;
+ /* The callback which the application sets to return the icon to use
+ for a given URL. */
+ EShortcutBarIconCallback icon_callback;
+
gchar *dragged_url;
gchar *dragged_name;
};
@@ -107,6 +114,12 @@ void e_shortcut_bar_remove_item (EShortcutBar *shortcut_bar,
gint group_num,
gint item_num);
+/* Sets the callback which is called to return the icon to use for a particular
+ URL. This callback must be set before any items are added. If the callback
+ returns NULL the default icon is used. */
+void e_shortcut_bar_set_icon_callback (EShortcutBar *shortcut_bar,
+ EShortcutBarIconCallback cb);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
diff --git a/widgets/shortcut-bar/test-shortcut-bar.c b/widgets/shortcut-bar/test-shortcut-bar.c
index 2018d614d1..250704d227 100644
--- a/widgets/shortcut-bar/test-shortcut-bar.c
+++ b/widgets/shortcut-bar/test-shortcut-bar.c
@@ -31,12 +31,19 @@
#include "e-shortcut-bar.h"
#define NUM_SHORTCUT_TYPES 5
-gchar *shortcut_types[] = {
+gchar *shortcut_types[NUM_SHORTCUT_TYPES] = {
"folder:", "file:", "calendar:", "todo:", "contacts:"
};
+gchar *icon_filenames[NUM_SHORTCUT_TYPES] = {
+ "gnome-balsa2.png", "gnome-folder.png", "gnome-calendar.png",
+ "gnome-cromagnon.png", "gnome-ccthemes.png"
+};
+GdkPixbuf *icon_pixbufs[NUM_SHORTCUT_TYPES];
GtkWidget *main_label;
+static GdkPixbuf* icon_callback (EShortcutBar *shortcut_bar,
+ gchar *url);
static void on_main_label_size_allocate (GtkWidget *widget,
GtkAllocation *allocation,
gpointer data);
@@ -74,6 +81,8 @@ int
main (int argc, char *argv[])
{
GtkWidget *window, *hpaned, *shortcut_bar;
+ gchar *pathname;
+ gint i;
gnome_init ("test-shortcut-bar", "0.1", argc, argv);
@@ -94,6 +103,8 @@ main (int argc, char *argv[])
shortcut_bar = e_shortcut_bar_new ();
gtk_paned_pack1 (GTK_PANED (hpaned), shortcut_bar, FALSE, TRUE);
gtk_widget_show (shortcut_bar);
+ e_shortcut_bar_set_icon_callback (E_SHORTCUT_BAR (shortcut_bar),
+ icon_callback);
#if 0
gtk_container_set_border_width (GTK_CONTAINER (shortcut_bar), 4);
@@ -113,6 +124,15 @@ main (int argc, char *argv[])
gtk_widget_pop_visual ();
gtk_widget_pop_colormap ();
+ /* Load our default icons. */
+ for (i = 0; i < NUM_SHORTCUT_TYPES; i++) {
+ pathname = gnome_pixmap_file (icon_filenames[i]);
+ if (pathname)
+ icon_pixbufs[i] = gdk_pixbuf_new_from_file (pathname);
+ else
+ icon_pixbufs[i] = NULL;
+ }
+
add_test_groups (E_SHORTCUT_BAR (shortcut_bar));
gtk_signal_connect (GTK_OBJECT (shortcut_bar), "item_selected",
@@ -125,6 +145,22 @@ main (int argc, char *argv[])
}
+static GdkPixbuf*
+icon_callback (EShortcutBar *shortcut_bar,
+ gchar *url)
+{
+ gint i;
+
+ for (i = 0; i < NUM_SHORTCUT_TYPES; i++) {
+ if (!strncmp (url, shortcut_types[i],
+ strlen (shortcut_types[i]))) {
+ return icon_pixbufs[i];
+ }
+ }
+
+ return NULL;
+}
+
static void
on_main_label_size_allocate (GtkWidget *widget,
GtkAllocation *allocation,