diff options
author | Damon Chaplin <damon@src.gnome.org> | 2000-07-17 14:30:33 +0800 |
---|---|---|
committer | Damon Chaplin <damon@src.gnome.org> | 2000-07-17 14:30:33 +0800 |
commit | b825d325372c69e604486e511526aaf0b227044e (patch) | |
tree | 20efcb5abecfb3bc3ca3a724da08131df53700f3 | |
parent | 81531f8286d0146ea2d8669a71d7587e6f5bbbbf (diff) | |
download | gsoc2013-evolution-b825d325372c69e604486e511526aaf0b227044e.tar gsoc2013-evolution-b825d325372c69e604486e511526aaf0b227044e.tar.gz gsoc2013-evolution-b825d325372c69e604486e511526aaf0b227044e.tar.bz2 gsoc2013-evolution-b825d325372c69e604486e511526aaf0b227044e.tar.lz gsoc2013-evolution-b825d325372c69e604486e511526aaf0b227044e.tar.xz gsoc2013-evolution-b825d325372c69e604486e511526aaf0b227044e.tar.zst gsoc2013-evolution-b825d325372c69e604486e511526aaf0b227044e.zip |
*** empty log message ***
svn path=/trunk/; revision=4188
-rw-r--r-- | widgets/shortcut-bar/e-shortcut-model.c | 556 | ||||
-rw-r--r-- | widgets/shortcut-bar/e-shortcut-model.h | 139 |
2 files changed, 695 insertions, 0 deletions
diff --git a/widgets/shortcut-bar/e-shortcut-model.c b/widgets/shortcut-bar/e-shortcut-model.c new file mode 100644 index 0000000000..61cfe54a4b --- /dev/null +++ b/widgets/shortcut-bar/e-shortcut-model.c @@ -0,0 +1,556 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ + +/* + * Author : + * Damon Chaplin <damon@helixcode.com> + * + * Copyright 1999, Helix Code, Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * 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 + */ + +/* + * EShortcutModel keeps track of a number of groups of shortcuts. + * Each shortcut has a URL and a short textual name. + * It is used as the model of the EShortcutBar. + */ + +#include <config.h> +#include <gtk/gtksignal.h> +#include <e-util/e-util.h> +#include "e-shortcut-model.h" + +/* This contains information on one item. */ +typedef struct _EShortcutModelItem EShortcutModelItem; +struct _EShortcutModelItem +{ + gchar *name; + gchar *url; +}; + + +/* This contains information on one group. */ +typedef struct _EShortcutModelGroup EShortcutModelGroup; +struct _EShortcutModelGroup +{ + gchar *name; + + /* An array of EShortcutModelItem. */ + GArray *items; +}; + +#define ESM_CLASS(e) ((EShortcutModelClass *)((GtkObject *)e)->klass) + + +static void e_shortcut_model_class_init (EShortcutModelClass *class); +static void e_shortcut_model_init (EShortcutModel *shortcut_model); +static void e_shortcut_model_destroy (GtkObject *object); +static void e_shortcut_model_free_group (EShortcutModel *shortcut_model, + gint group_num); + +static void e_shortcut_model_real_add_group (EShortcutModel *shortcut_model, + gint position, + const gchar *group_name); +static void e_shortcut_model_real_remove_group (EShortcutModel *shortcut_model, + gint group_num); +static void e_shortcut_model_real_add_item (EShortcutModel *shortcut_model, + gint group_num, + gint position, + const gchar *item_url, + const gchar *item_name); +static void e_shortcut_model_real_remove_item (EShortcutModel *shortcut_model, + gint group_num, + gint item_num); + +static void e_shortcut_model_marshal1 (GtkObject *object, + GtkSignalFunc func, + gpointer func_data, + GtkArg *args); +static void e_shortcut_model_marshal2 (GtkObject *object, + GtkSignalFunc func, + gpointer func_data, + GtkArg *args); + +static gint e_shortcut_model_real_get_num_groups(EShortcutModel *shortcut_model); +static gint e_shortcut_model_real_get_num_items (EShortcutModel *shortcut_model, + gint group_num); +static gchar* e_shortcut_model_real_get_group_name (EShortcutModel *shortcut_model, + gint group_num); +static void e_shortcut_model_real_get_item_info (EShortcutModel *shortcut_model, + gint group_num, + gint item_num, + gchar **item_url, + gchar **item_name); + +enum +{ + GROUP_ADDED, + GROUP_REMOVED, + ITEM_ADDED, + ITEM_REMOVED, + + LAST_SIGNAL +}; + +static guint e_shortcut_model_signals[LAST_SIGNAL] = {0}; + +static GtkObjectClass *parent_class; + + +E_MAKE_TYPE(e_shortcut_model, "EShortcutModel", EShortcutModel, + e_shortcut_model_class_init, e_shortcut_model_init, + GTK_TYPE_OBJECT) + + +static void +e_shortcut_model_class_init (EShortcutModelClass *class) +{ + GtkObjectClass *object_class; + + parent_class = gtk_type_class (GTK_TYPE_OBJECT); + + object_class = (GtkObjectClass *) class; + + e_shortcut_model_signals[GROUP_ADDED] = + gtk_signal_new ("group_added", + GTK_RUN_FIRST | GTK_RUN_ACTION, + object_class->type, + GTK_SIGNAL_OFFSET (EShortcutModelClass, + group_added), + e_shortcut_model_marshal1, + GTK_TYPE_NONE, 2, + GTK_TYPE_INT, GTK_TYPE_STRING); + + e_shortcut_model_signals[GROUP_REMOVED] = + gtk_signal_new ("group_removed", + GTK_RUN_FIRST | GTK_RUN_ACTION, + object_class->type, + GTK_SIGNAL_OFFSET (EShortcutModelClass, + group_removed), + gtk_marshal_NONE__INT, + GTK_TYPE_NONE, 1, + GTK_TYPE_INT); + + e_shortcut_model_signals[ITEM_ADDED] = + gtk_signal_new ("item_added", + GTK_RUN_FIRST | GTK_RUN_ACTION, + object_class->type, + GTK_SIGNAL_OFFSET (EShortcutModelClass, + item_added), + e_shortcut_model_marshal2, + GTK_TYPE_NONE, 4, + GTK_TYPE_INT, GTK_TYPE_INT, + GTK_TYPE_STRING, GTK_TYPE_STRING); + + e_shortcut_model_signals[ITEM_REMOVED] = + gtk_signal_new ("item_removed", + GTK_RUN_FIRST | GTK_RUN_ACTION, + object_class->type, + GTK_SIGNAL_OFFSET (EShortcutModelClass, + item_removed), + gtk_marshal_NONE__INT_INT, + GTK_TYPE_NONE, 2, + GTK_TYPE_INT, GTK_TYPE_INT); + + gtk_object_class_add_signals (object_class, e_shortcut_model_signals, + LAST_SIGNAL); + + /* Method override */ + object_class->destroy = e_shortcut_model_destroy; + + class->group_added = e_shortcut_model_real_add_group; + class->group_removed = e_shortcut_model_real_remove_group; + class->item_added = e_shortcut_model_real_add_item; + class->item_removed = e_shortcut_model_real_remove_item; + + class->get_num_groups = e_shortcut_model_real_get_num_groups; + class->get_num_items = e_shortcut_model_real_get_num_items; + class->get_group_name = e_shortcut_model_real_get_group_name; + class->get_item_info = e_shortcut_model_real_get_item_info; +} + + +static void +e_shortcut_model_init (EShortcutModel *shortcut_model) +{ + shortcut_model->groups = g_array_new (FALSE, FALSE, + sizeof (EShortcutModelGroup)); +} + + +EShortcutModel * +e_shortcut_model_new (void) +{ + EShortcutModel *shortcut_model; + + shortcut_model = E_SHORTCUT_MODEL (gtk_type_new (e_shortcut_model_get_type ())); + + return shortcut_model; +} + + +static void +e_shortcut_model_destroy (GtkObject *object) +{ + EShortcutModel *shortcut_model; + gint num_groups, group_num; + + shortcut_model = E_SHORTCUT_MODEL (object); + + num_groups = shortcut_model->groups->len; + for (group_num = 0; group_num < num_groups; group_num++) + e_shortcut_model_free_group (shortcut_model, group_num); + + g_array_free (shortcut_model->groups, TRUE); + shortcut_model->groups = NULL; + + GTK_OBJECT_CLASS (parent_class)->destroy (object); +} + + +static void +e_shortcut_model_free_group (EShortcutModel *shortcut_model, + gint group_num) +{ + EShortcutModelGroup *group; + EShortcutModelItem *item; + gint item_num; + + group = &g_array_index (shortcut_model->groups, + EShortcutModelGroup, group_num); + + g_free (group->name); + + for (item_num = 0; item_num < group->items->len; item_num++) { + item = &g_array_index (group->items, + EShortcutModelItem, item_num); + g_free (item->name); + g_free (item->url); + } +} + + +gint +e_shortcut_model_add_group (EShortcutModel *shortcut_model, + gint position, + const gchar *group_name) +{ + g_return_val_if_fail (E_IS_SHORTCUT_MODEL (shortcut_model), -1); + g_return_val_if_fail (group_name != NULL, -1); + + if (position == -1 || position > shortcut_model->groups->len) + position = shortcut_model->groups->len; + + gtk_signal_emit (GTK_OBJECT (shortcut_model), + e_shortcut_model_signals[GROUP_ADDED], + position, group_name); + + return position; +} + + +static void +e_shortcut_model_real_add_group (EShortcutModel *shortcut_model, + gint group_num, + const gchar *group_name) +{ + EShortcutModelGroup *group, tmp_group; + + g_return_if_fail (E_IS_SHORTCUT_MODEL (shortcut_model)); + g_return_if_fail (group_num >= 0); + g_return_if_fail (group_num <= shortcut_model->groups->len); + g_return_if_fail (group_name != NULL); + + g_array_insert_val (shortcut_model->groups, group_num, tmp_group); + + group = &g_array_index (shortcut_model->groups, + EShortcutModelGroup, group_num); + + group->name = g_strdup (group_name); + group->items = g_array_new (FALSE, FALSE, + sizeof (EShortcutModelItem)); +} + + +void +e_shortcut_model_remove_group (EShortcutModel *shortcut_model, + gint group_num) +{ + g_return_if_fail (E_IS_SHORTCUT_MODEL (shortcut_model)); + g_return_if_fail (group_num >= 0); + g_return_if_fail (group_num < shortcut_model->groups->len); + + gtk_signal_emit (GTK_OBJECT (shortcut_model), + e_shortcut_model_signals[GROUP_REMOVED], + group_num); +} + + +static void +e_shortcut_model_real_remove_group (EShortcutModel *shortcut_model, + gint group_num) +{ + g_return_if_fail (E_IS_SHORTCUT_MODEL (shortcut_model)); + g_return_if_fail (group_num >= 0); + g_return_if_fail (group_num < shortcut_model->groups->len); + + e_shortcut_model_free_group (shortcut_model, group_num); + g_array_remove_index (shortcut_model->groups, group_num); +} + + +gint +e_shortcut_model_add_item (EShortcutModel *shortcut_model, + gint group_num, + gint position, + const gchar *item_url, + const gchar *item_name) +{ + EShortcutModelGroup *group; + + g_return_val_if_fail (E_IS_SHORTCUT_MODEL (shortcut_model), -1); + g_return_val_if_fail (group_num >= 0, -1); + g_return_val_if_fail (group_num < shortcut_model->groups->len, -1); + g_return_val_if_fail (item_url != NULL, -1); + g_return_val_if_fail (item_name != NULL, -1); + + group = &g_array_index (shortcut_model->groups, + EShortcutModelGroup, group_num); + + if (position == -1 || position > group->items->len) + position = group->items->len; + + gtk_signal_emit (GTK_OBJECT (shortcut_model), + e_shortcut_model_signals[ITEM_ADDED], + group_num, position, item_url, item_name); + + return position; +} + + +static void +e_shortcut_model_real_add_item (EShortcutModel *shortcut_model, + gint group_num, + gint item_num, + const gchar *item_url, + const gchar *item_name) +{ + EShortcutModelGroup *group; + EShortcutModelItem *item, tmp_item; + + g_return_if_fail (E_IS_SHORTCUT_MODEL (shortcut_model)); + g_return_if_fail (group_num >= 0); + g_return_if_fail (group_num < shortcut_model->groups->len); + g_return_if_fail (item_url != NULL); + g_return_if_fail (item_name != NULL); + + group = &g_array_index (shortcut_model->groups, + EShortcutModelGroup, group_num); + + g_return_if_fail (item_num >= 0); + g_return_if_fail (item_num <= group->items->len); + + g_array_insert_val (group->items, item_num, tmp_item); + + item = &g_array_index (group->items, + EShortcutModelItem, item_num); + + item->name = g_strdup (item_name); + item->url = g_strdup (item_url); +} + + +void +e_shortcut_model_remove_item (EShortcutModel *shortcut_model, + gint group_num, + gint item_num) +{ + gtk_signal_emit (GTK_OBJECT (shortcut_model), + e_shortcut_model_signals[ITEM_REMOVED], + group_num, item_num); +} + + +static void +e_shortcut_model_real_remove_item (EShortcutModel *shortcut_model, + gint group_num, + gint item_num) +{ + EShortcutModelGroup *group; + EShortcutModelItem *item; + + g_return_if_fail (E_IS_SHORTCUT_MODEL (shortcut_model)); + g_return_if_fail (group_num >= 0); + g_return_if_fail (group_num < shortcut_model->groups->len); + + group = &g_array_index (shortcut_model->groups, + EShortcutModelGroup, group_num); + + g_return_if_fail (item_num >= 0); + g_return_if_fail (item_num < group->items->len); + + item = &g_array_index (group->items, + EShortcutModelItem, item_num); + + g_free (item->name); + g_free (item->url); + + g_array_remove_index (group->items, item_num); +} + + +static void +e_shortcut_model_marshal1 (GtkObject *object, + GtkSignalFunc func, + gpointer func_data, + GtkArg *args) +{ + void (*rfunc) (GtkObject*, gint, gpointer, gpointer); + rfunc = (void (*) (GtkObject*, gint, gpointer, gpointer)) func; + (*rfunc) (object, GTK_VALUE_INT (args[0]), GTK_VALUE_STRING (args[1]), + func_data); +} + + +static void +e_shortcut_model_marshal2 (GtkObject *object, + GtkSignalFunc func, + gpointer func_data, + GtkArg *args) +{ + void (*rfunc) (GtkObject*, gint, gint, gpointer, gpointer, gpointer); + rfunc = (void (*) (GtkObject*, gint, gint, gpointer, gpointer, + gpointer)) func; + (*rfunc) (object, GTK_VALUE_INT (args[0]), GTK_VALUE_INT (args[1]), + GTK_VALUE_STRING (args[2]), GTK_VALUE_STRING (args[3]), + func_data); +} + + +gint +e_shortcut_model_get_num_groups (EShortcutModel *shortcut_model) +{ + g_return_val_if_fail (E_IS_SHORTCUT_MODEL (shortcut_model), 0); + + return ESM_CLASS (shortcut_model)->get_num_groups (shortcut_model); +} + + +static gint +e_shortcut_model_real_get_num_groups (EShortcutModel *shortcut_model) +{ + return shortcut_model->groups->len; +} + + +gint +e_shortcut_model_get_num_items (EShortcutModel *shortcut_model, + gint group_num) +{ + g_return_val_if_fail (E_IS_SHORTCUT_MODEL (shortcut_model), 0); + + return ESM_CLASS (shortcut_model)->get_num_items (shortcut_model, + group_num); +} + + +static gint +e_shortcut_model_real_get_num_items (EShortcutModel *shortcut_model, + gint group_num) +{ + EShortcutModelGroup *group; + + g_return_val_if_fail (group_num >= 0, 0); + g_return_val_if_fail (group_num < shortcut_model->groups->len, 0); + + group = &g_array_index (shortcut_model->groups, + EShortcutModelGroup, group_num); + + return group->items->len; +} + + +gchar* +e_shortcut_model_get_group_name (EShortcutModel *shortcut_model, + gint group_num) +{ + g_return_val_if_fail (E_IS_SHORTCUT_MODEL (shortcut_model), NULL); + + return ESM_CLASS (shortcut_model)->get_group_name (shortcut_model, + group_num); +} + + +static gchar* +e_shortcut_model_real_get_group_name (EShortcutModel *shortcut_model, + gint group_num) +{ + EShortcutModelGroup *group; + + g_return_val_if_fail (group_num >= 0, NULL); + g_return_val_if_fail (group_num < shortcut_model->groups->len, NULL); + + group = &g_array_index (shortcut_model->groups, + EShortcutModelGroup, group_num); + + return g_strdup (group->name); +} + + +void +e_shortcut_model_get_item_info (EShortcutModel *shortcut_model, + gint group_num, + gint item_num, + gchar **item_url, + gchar **item_name) +{ + g_return_if_fail (E_IS_SHORTCUT_MODEL (shortcut_model)); + + ESM_CLASS (shortcut_model)->get_item_info (shortcut_model, + group_num, item_num, + item_url, item_name); +} + + +static void +e_shortcut_model_real_get_item_info (EShortcutModel *shortcut_model, + gint group_num, + gint item_num, + gchar **item_url, + gchar **item_name) +{ + EShortcutModelGroup *group; + EShortcutModelItem *item; + + g_return_if_fail (group_num >= 0); + g_return_if_fail (group_num < shortcut_model->groups->len); + + group = &g_array_index (shortcut_model->groups, + EShortcutModelGroup, group_num); + + g_return_if_fail (item_num >= 0); + g_return_if_fail (item_num < group->items->len); + + item = &g_array_index (group->items, + EShortcutModelItem, item_num); + + if (item_url) + *item_url = g_strdup (item->url); + + if (item_name) + *item_name = g_strdup (item->name); +} + diff --git a/widgets/shortcut-bar/e-shortcut-model.h b/widgets/shortcut-bar/e-shortcut-model.h new file mode 100644 index 0000000000..402874ef09 --- /dev/null +++ b/widgets/shortcut-bar/e-shortcut-model.h @@ -0,0 +1,139 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ + +/* + * Author : + * Damon Chaplin <damon@helixcode.com> + * + * Copyright 1999, Helix Code, Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * 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 + */ +#ifndef _E_SHORTCUT_MODEL_H_ +#define _E_SHORTCUT_MODEL_H_ + +#include <gtk/gtkobject.h> + + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* + * EShortcutModel keeps track of a number of groups of shortcuts. + * Each shortcut has a URL and a short textual name. + * It is used as the model of the EShortcutBar. + */ + +typedef struct _EShortcutModel EShortcutModel; +typedef struct _EShortcutModelClass EShortcutModelClass; + + +#define E_TYPE_SHORTCUT_MODEL (e_shortcut_model_get_type ()) +#define E_SHORTCUT_MODEL(obj) GTK_CHECK_CAST (obj, e_shortcut_model_get_type (), EShortcutModel) +#define E_SHORTCUT_MODEL_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, e_shortcut_model_get_type (), EShortcutModelClass) +#define E_IS_SHORTCUT_MODEL(obj) GTK_CHECK_TYPE (obj, e_shortcut_model_get_type ()) + + +struct _EShortcutModel +{ + GtkObject object; + + /* This is a private array of EShortcutModelGroup elements. */ + GArray *groups; +}; + +struct _EShortcutModelClass +{ + GtkObjectClass parent_class; + + /* + * Signals - These act like virtual functions as well as notification + * signals. The class function is run first and does the actual action. + */ + void (*group_added) (EShortcutModel *shortcut_model, + gint group_num, + const gchar *group_name); + void (*group_removed) (EShortcutModel *shortcut_model, + gint group_num); + + void (*item_added) (EShortcutModel *shortcut_model, + gint group_num, + gint item_num, + const gchar *item_url, + const gchar *item_name); + void (*item_removed) (EShortcutModel *shortcut_model, + gint group_num, + gint item_num); + + /* + * Virtual methods. + */ + gint (*get_num_groups) (EShortcutModel *shortcut_model); + gint (*get_num_items) (EShortcutModel *shortcut_model, + gint group_num); + /* This returns a copy of the group name. */ + gchar* (*get_group_name) (EShortcutModel *shortcut_model, + gint group_num); + /* This returns a copy of the item url and name. */ + void (*get_item_info) (EShortcutModel *shortcut_model, + gint group_num, + gint item_num, + gchar **item_url, + gchar **item_name); +}; + + +GtkType e_shortcut_model_get_type (void); +EShortcutModel* e_shortcut_model_new (void); + +/* Adds a new group at the given position, or last if position is -1. + It returns the index of the new group. */ +gint e_shortcut_model_add_group (EShortcutModel *shortcut_model, + gint position, + const gchar *group_name); +void e_shortcut_model_remove_group (EShortcutModel *shortcut_model, + gint group_num); + +/* Adds a new item to a group at the given position, or last if position is -1. + It returns the index of the new item within the group. */ +gint e_shortcut_model_add_item (EShortcutModel *shortcut_model, + gint group_num, + gint position, + const gchar *item_url, + const gchar *item_name); + +void e_shortcut_model_remove_item (EShortcutModel *shortcut_model, + gint group_num, + gint item_num); + +gint e_shortcut_model_get_num_groups(EShortcutModel *shortcut_model); +gint e_shortcut_model_get_num_items (EShortcutModel *shortcut_model, + gint group_num); +/* The group_name should be freed after use. */ +gchar* e_shortcut_model_get_group_name(EShortcutModel *shortcut_model, + gint group_num); +/* The item_url and item_name should be freed after use. */ +void e_shortcut_model_get_item_info (EShortcutModel *shortcut_model, + gint group_num, + gint item_num, + gchar **item_url, + gchar **item_name); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* _E_SHORTCUT_MODEL_H_ */ |