From 5d92db014941daf0831694f00deb6c1f6cb22e69 Mon Sep 17 00:00:00 2001 From: Chris Toshok Date: Thu, 9 Jan 2003 02:31:46 +0000 Subject: add parent arg. 2003-01-08 Chris Toshok * gui/widgets/gal-view-minicard.c (gal_view_minicard_edit): add parent arg. * gui/widgets/e-addressbook-treeview-adapter.[ch]: new files, for a GtkTreeView view of contacts. * gui/widgets/gal-view-treeview.[ch]: same * gui/widgets/gal-view-favroty-treeview.[ch]: same svn path=/trunk/; revision=19299 --- .../gui/widgets/e-addressbook-treeview-adapter.c | 627 +++++++++++++++++++++ .../gui/widgets/e-addressbook-treeview-adapter.h | 44 ++ .../gui/widgets/gal-view-factory-treeview.c | 86 +++ .../gui/widgets/gal-view-factory-treeview.h | 35 ++ addressbook/gui/widgets/gal-view-minicard.c | 2 +- addressbook/gui/widgets/gal-view-treeview.c | 227 ++++++++ addressbook/gui/widgets/gal-view-treeview.h | 43 ++ 7 files changed, 1063 insertions(+), 1 deletion(-) create mode 100644 addressbook/gui/widgets/e-addressbook-treeview-adapter.c create mode 100644 addressbook/gui/widgets/e-addressbook-treeview-adapter.h create mode 100644 addressbook/gui/widgets/gal-view-factory-treeview.c create mode 100644 addressbook/gui/widgets/gal-view-factory-treeview.h create mode 100644 addressbook/gui/widgets/gal-view-treeview.c create mode 100644 addressbook/gui/widgets/gal-view-treeview.h (limited to 'addressbook/gui') diff --git a/addressbook/gui/widgets/e-addressbook-treeview-adapter.c b/addressbook/gui/widgets/e-addressbook-treeview-adapter.c new file mode 100644 index 0000000000..d6401133ec --- /dev/null +++ b/addressbook/gui/widgets/e-addressbook-treeview-adapter.c @@ -0,0 +1,627 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ + +#include +#include "e-addressbook-model.h" +#include "e-addressbook-treeview-adapter.h" +#include "e-card-merging.h" +#include "e-addressbook-util.h" +#include +#include +#include +#include + +struct _EAddressbookTreeViewAdapterPrivate { + EAddressbookModel *model; + + gint stamp; + + ECardSimple **simples; + int count; + + int create_card_id, remove_card_id, modify_card_id, model_changed_id; +}; + +#define PARENT_TYPE G_TYPE_OBJECT +GObjectClass *parent_class; + +#define COLS (E_CARD_SIMPLE_FIELD_LAST) + +static void +unlink_model(EAddressbookTreeViewAdapter *adapter) +{ + EAddressbookTreeViewAdapterPrivate *priv = adapter->priv; + int i; + + g_signal_handler_disconnect (priv->model, + priv->create_card_id); + g_signal_handler_disconnect (priv->model, + priv->remove_card_id); + g_signal_handler_disconnect (priv->model, + priv->modify_card_id); + g_signal_handler_disconnect (priv->model, + priv->model_changed_id); + + priv->create_card_id = 0; + priv->remove_card_id = 0; + priv->modify_card_id = 0; + priv->model_changed_id = 0; + + /* free up the existing mapping if there is one */ + if (priv->simples) { + for (i = 0; i < priv->count; i ++) + g_object_unref (priv->simples[i]); + g_free (priv->simples); + priv->simples = NULL; + } + + g_object_unref (priv->model); + + priv->model = NULL; +} + +static void +build_simple_mapping(EAddressbookTreeViewAdapter *adapter) +{ + EAddressbookTreeViewAdapterPrivate *priv = adapter->priv; + int i; + + /* free up the existing mapping if there is one */ + if (priv->simples) { + for (i = 0; i < priv->count; i ++) + g_object_unref (priv->simples[i]); + g_free (priv->simples); + } + + /* build up our mapping to ECardSimple*'s */ + priv->count = e_addressbook_model_card_count (priv->model); + priv->simples = g_new (ECardSimple*, priv->count); + for (i = 0; i < priv->count; i ++) { + priv->simples[i] = e_card_simple_new (e_addressbook_model_card_at (priv->model, i)); + g_object_ref (priv->simples[i]); + } +} + +static void +addressbook_destroy(GtkObject *object) +{ + EAddressbookTreeViewAdapter *adapter = E_ADDRESSBOOK_TREEVIEW_ADAPTER(object); + + unlink_model(adapter); + + g_free (adapter->priv); +} + +#if 0 +static void +addressbook_set_value_at (ETableModel *etc, int col, int row, const void *val) +{ + EAddressbookTreeViewAdapter *adapter = E_ADDRESSBOOK_TABLE_ADAPTER(etc); + EAddressbookTableAdapterPrivate *priv = adapter->priv; + if (e_addressbook_model_editable (priv->model)) { + ECard *card; + + if ( col >= COLS|| row >= e_addressbook_model_card_count (priv->model) ) + return; + + e_table_model_pre_change(etc); + + e_card_simple_set(priv->simples[row], + col, + val); + g_object_get(priv->simples[row], + "card", &card, + NULL); + + e_card_merging_book_commit_card(e_addressbook_model_get_ebook(priv->model), + card, card_modified_cb, NULL); + + /* XXX do we need this? shouldn't the commit_card generate a changed signal? */ + e_table_model_cell_changed(etc, col, row); + } +} + +/* This function returns whether a particular cell is editable. */ +static gboolean +addressbook_is_cell_editable (ETableModel *etc, int col, int row) +{ + EAddressbookTableAdapter *adapter = E_ADDRESSBOOK_TABLE_ADAPTER(etc); + EAddressbookTableAdapterPrivate *priv = adapter->priv; + ECard *card; + + if (row >= 0 && row < e_addressbook_model_card_count (priv->model)) + card = e_addressbook_model_card_at (priv->model, row); + else + card = NULL; + + if (!e_addressbook_model_editable(priv->model)) + return FALSE; + else if (card && e_card_evolution_list (card)) + /* we only allow editing of the name and file as for + lists */ + return col == E_CARD_SIMPLE_FIELD_FULL_NAME || col == E_CARD_SIMPLE_FIELD_FILE_AS; + else + return col < E_CARD_SIMPLE_FIELD_LAST_SIMPLE_STRING; +} + +static void +addressbook_append_row (ETableModel *etm, ETableModel *source, gint row) +{ + EAddressbookTableAdapter *adapter = E_ADDRESSBOOK_TABLE_ADAPTER(etm); + EAddressbookTableAdapterPrivate *priv = adapter->priv; + ECard *card; + ECardSimple *simple; + int col; + + card = e_card_new(""); + simple = e_card_simple_new(card); + + for (col = 0; col < E_CARD_SIMPLE_FIELD_LAST_SIMPLE_STRING; col++) { + const void *val = e_table_model_value_at(source, col, row); + e_card_simple_set(simple, col, val); + } + e_card_simple_sync_card(simple); + e_card_merging_book_add_card (e_addressbook_model_get_ebook (priv->model), card, NULL, NULL); + g_object_unref (simple); + g_object_unref (card); +} +#endif + +static void +e_addressbook_treeview_adapter_class_init (GtkObjectClass *object_class) +{ + parent_class = g_type_class_peek_parent (object_class); + + object_class->destroy = addressbook_destroy; +} + +static void +e_addressbook_treeview_adapter_init (GtkObject *object) +{ + EAddressbookTreeViewAdapter *adapter = E_ADDRESSBOOK_TREEVIEW_ADAPTER(object); + EAddressbookTreeViewAdapterPrivate *priv; + + priv = adapter->priv = g_new0 (EAddressbookTreeViewAdapterPrivate, 1); + + priv->create_card_id = 0; + priv->remove_card_id = 0; + priv->modify_card_id = 0; + priv->model_changed_id = 0; + priv->simples = NULL; + priv->count = 0; +} + +static void +get_iter (EAddressbookTreeViewAdapter *adapter, gint index, GtkTreeIter *iter) +{ + EAddressbookTreeViewAdapterPrivate *priv = adapter->priv; + + iter->stamp = priv->stamp; + iter->user_data = GINT_TO_POINTER (index); +} + +static void +create_card (EAddressbookModel *model, + gint index, gint count, + EAddressbookTreeViewAdapter *adapter) +{ + EAddressbookTreeViewAdapterPrivate *priv = adapter->priv; + int i; + + priv->count += count; + priv->simples = g_renew(ECardSimple *, priv->simples, priv->count); + memmove (priv->simples + index + count, priv->simples + index, (priv->count - index - count) * sizeof (ECardSimple *)); + + for (i = 0; i < count; i ++) { + GtkTreeIter iter; + GtkTreePath *path; + + priv->simples[index + i] = e_card_simple_new (e_addressbook_model_card_at (priv->model, index + i)); + + get_iter (adapter, index + i, &iter); + path = gtk_tree_model_get_path (GTK_TREE_MODEL (adapter), &iter); + + gtk_tree_model_row_inserted (GTK_TREE_MODEL (adapter), path, &iter); + gtk_tree_model_row_changed (GTK_TREE_MODEL (adapter), path, &iter); + + gtk_tree_path_free (path); + } +} + +static void +remove_card (EAddressbookModel *model, + gint index, + EAddressbookTreeViewAdapter *adapter) +{ + EAddressbookTreeViewAdapterPrivate *priv = adapter->priv; + GtkTreeIter iter; + GtkTreePath *path; + + g_object_unref (priv->simples[index]); + memmove (priv->simples + index, priv->simples + index + 1, (priv->count - index - 1) * sizeof (ECardSimple *)); + priv->count --; + get_iter (adapter, index, &iter); + path = gtk_tree_model_get_path (GTK_TREE_MODEL (adapter), &iter); + + gtk_tree_model_row_deleted (GTK_TREE_MODEL (adapter), path); + + gtk_tree_path_free (path); +} + +static void +modify_card (EAddressbookModel *model, + gint index, + EAddressbookTreeViewAdapter *adapter) +{ + EAddressbookTreeViewAdapterPrivate *priv = adapter->priv; + GtkTreeIter iter; + GtkTreePath *path; + + g_object_unref (priv->simples[index]); + priv->simples[index] = e_card_simple_new (e_addressbook_model_card_at (priv->model, index)); + + get_iter (adapter, index, &iter); + path = gtk_tree_model_get_path (GTK_TREE_MODEL (adapter), &iter); + + gtk_tree_model_row_changed (GTK_TREE_MODEL (adapter), path, &iter); + + gtk_tree_path_free (path); +} + +static void +model_changed (EAddressbookModel *model, + EAddressbookTreeViewAdapter *adapter) +{ + int i; + + /* there has *got* to be an easier/faster way to do this... */ + for (i = 0; i < adapter->priv->count; i++) { + remove_card (model, i, adapter); + } + + build_simple_mapping (adapter); + + if (adapter->priv->count) { + printf ("AIIEEEEEE\n"); + } + + /* XXX this isn't right either, we need to add the new cards */ +} + +static GtkTreeModelFlags +adapter_get_flags (GtkTreeModel *tree_model) +{ + g_return_val_if_fail (E_IS_ADDRESSBOOK_TREEVIEW_ADAPTER (tree_model), 0); + + return GTK_TREE_MODEL_LIST_ONLY; +} + +static gint +adapter_get_n_columns (GtkTreeModel *tree_model) +{ + g_return_val_if_fail (E_IS_ADDRESSBOOK_TREEVIEW_ADAPTER (tree_model), 0); + + return COLS; +} + +static GType +adapter_get_column_type (GtkTreeModel *tree_model, + gint index) +{ + g_return_val_if_fail (E_IS_ADDRESSBOOK_TREEVIEW_ADAPTER (tree_model), G_TYPE_INVALID); + g_return_val_if_fail (index < COLS && index >= 0, G_TYPE_INVALID); + + return G_TYPE_STRING; +} + +static gboolean +adapter_get_iter (GtkTreeModel *tree_model, + GtkTreeIter *iter, + GtkTreePath *path) +{ + EAddressbookTreeViewAdapter *adapter; + GSList *list; + gint i; + + g_return_val_if_fail (E_IS_ADDRESSBOOK_TREEVIEW_ADAPTER (tree_model), FALSE); + g_return_val_if_fail (gtk_tree_path_get_depth (path) > 0, FALSE); + + adapter = E_ADDRESSBOOK_TREEVIEW_ADAPTER (tree_model); + + i = gtk_tree_path_get_indices (path)[0]; + + if (i >= adapter->priv->count) + return FALSE; + + iter->stamp = adapter->priv->stamp; + iter->user_data = GINT_TO_POINTER (i); + + return TRUE; +} + +static GtkTreePath * +adapter_get_path (GtkTreeModel *tree_model, + GtkTreeIter *iter) +{ + EAddressbookTreeViewAdapter *adapter = E_ADDRESSBOOK_TREEVIEW_ADAPTER (tree_model); + GtkTreePath *retval; + + g_return_val_if_fail (E_IS_ADDRESSBOOK_TREEVIEW_ADAPTER (tree_model), NULL); + g_return_val_if_fail (iter->stamp == adapter->priv->stamp, NULL); + + + if (GPOINTER_TO_INT (iter->user_data) >= adapter->priv->count) + return NULL; + + retval = gtk_tree_path_new (); + gtk_tree_path_append_index (retval, GPOINTER_TO_INT (iter->user_data)); + return retval; +} + +static void +adapter_get_value (GtkTreeModel *tree_model, + GtkTreeIter *iter, + gint column, + GValue *value) +{ + EAddressbookTreeViewAdapter *adapter = E_ADDRESSBOOK_TREEVIEW_ADAPTER (tree_model); + ECardSimple *simple; + gint tmp_column = column; + const char *v; + + g_return_if_fail (E_IS_ADDRESSBOOK_TREEVIEW_ADAPTER (tree_model)); + g_return_if_fail (column < COLS); + g_return_if_fail (adapter->priv->stamp == iter->stamp); + + simple = adapter->priv->simples [ GPOINTER_TO_INT (iter->user_data) ]; + + v = e_card_simple_get_const(simple, column); + + if (v && !strncmp (v, "priv->stamp == iter->stamp, FALSE); + + adapter = E_ADDRESSBOOK_TREEVIEW_ADAPTER (tree_model); + + iter->user_data = GINT_TO_POINTER (GPOINTER_TO_INT (iter->user_data) + 1); + + return (GPOINTER_TO_INT (iter->user_data) < adapter->priv->count); +} + +static gboolean +adapter_iter_children (GtkTreeModel *tree_model, + GtkTreeIter *iter, + GtkTreeIter *parent) +{ + EAddressbookTreeViewAdapter *adapter = E_ADDRESSBOOK_TREEVIEW_ADAPTER (tree_model); + + /* this is a list, nodes have no children */ + if (parent) + return FALSE; + + /* but if parent == NULL we return the list itself as children of the + * "root" + */ + if (adapter->priv->count) { + iter->stamp = adapter->priv->stamp; + iter->user_data = GINT_TO_POINTER (0); + return TRUE; + } + else + return FALSE; +} + +static gboolean +adapter_iter_has_child (GtkTreeModel *tree_model, + GtkTreeIter *iter) +{ + return FALSE; +} + +static gint +adapter_iter_n_children (GtkTreeModel *tree_model, + GtkTreeIter *iter) +{ + EAddressbookTreeViewAdapter *adapter = E_ADDRESSBOOK_TREEVIEW_ADAPTER (tree_model); + + g_return_val_if_fail (E_IS_ADDRESSBOOK_TREEVIEW_ADAPTER (tree_model), -1); + if (iter == NULL) + return adapter->priv->count; + + g_return_val_if_fail (adapter->priv->stamp == iter->stamp, -1); + return 0; +} + +static gboolean +adapter_iter_nth_child (GtkTreeModel *tree_model, + GtkTreeIter *iter, + GtkTreeIter *parent, + gint n) +{ + EAddressbookTreeViewAdapter *adapter = E_ADDRESSBOOK_TREEVIEW_ADAPTER (tree_model); + + g_return_val_if_fail (E_IS_ADDRESSBOOK_TREEVIEW_ADAPTER (tree_model), FALSE); + + if (parent) + return FALSE; + + if (n < adapter->priv->count) { + iter->stamp = adapter->priv->stamp; + iter->user_data = GINT_TO_POINTER (n); + return TRUE; + } + else + return FALSE; +} + +static gboolean +adapter_iter_parent (GtkTreeModel *tree_model, + GtkTreeIter *iter, + GtkTreeIter *child) +{ + return FALSE; +} + +static void +adapter_tree_model_init (GtkTreeModelIface *iface) +{ + iface->get_flags = adapter_get_flags; + iface->get_n_columns = adapter_get_n_columns; + iface->get_column_type = adapter_get_column_type; + iface->get_iter = adapter_get_iter; + iface->get_path = adapter_get_path; + iface->get_value = adapter_get_value; + iface->iter_next = adapter_iter_next; + iface->iter_children = adapter_iter_children; + iface->iter_has_child = adapter_iter_has_child; + iface->iter_n_children = adapter_iter_n_children; + iface->iter_nth_child = adapter_iter_nth_child; + iface->iter_parent = adapter_iter_parent; +} + +static gboolean +adapter_drag_data_delete (GtkTreeDragSource *drag_source, + GtkTreePath *path) +{ + g_return_val_if_fail (E_IS_ADDRESSBOOK_TREEVIEW_ADAPTER (drag_source), FALSE); + + return FALSE; +} + +static gboolean +adapter_drag_data_get (GtkTreeDragSource *drag_source, + GtkTreePath *path, + GtkSelectionData *selection_data) +{ + g_return_val_if_fail (E_IS_ADDRESSBOOK_TREEVIEW_ADAPTER (drag_source), FALSE); + + /* Note that we don't need to handle the GTK_TREE_MODEL_ROW + * target, because the default handler does it for us, but + * we do anyway for the convenience of someone maybe overriding the + * default handler. + */ + + if (gtk_tree_set_row_drag_data (selection_data, + GTK_TREE_MODEL (drag_source), + path)) { + return TRUE; + } + else { + if (selection_data->target == gdk_atom_intern ("text/x-vcard", FALSE)) { + printf ("HI THERE\n"); + } + } + + return FALSE; +} + +static void +adapter_drag_source_init (GtkTreeDragSourceIface *iface) +{ + iface->drag_data_delete = adapter_drag_data_delete; + iface->drag_data_get = adapter_drag_data_get; +} + +GType +e_addressbook_treeview_adapter_get_type (void) +{ + static GType type = 0; + + if (!type) { + static const GTypeInfo adapter_info = { + sizeof (EAddressbookTreeViewAdapterClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) e_addressbook_treeview_adapter_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (EAddressbookTreeViewAdapter), + 0, /* n_preallocs */ + (GInstanceInitFunc) e_addressbook_treeview_adapter_init, + }; + + static const GInterfaceInfo tree_model_info = { + (GInterfaceInitFunc) adapter_tree_model_init, + NULL, + NULL + }; + + static const GInterfaceInfo drag_source_info = { + (GInterfaceInitFunc) adapter_drag_source_init, + NULL, + NULL + }; + + type = g_type_register_static (PARENT_TYPE, "EAddressbookTreeViewAdapter", &adapter_info, 0); + + g_type_add_interface_static (type, + GTK_TYPE_TREE_MODEL, + &tree_model_info); + + g_type_add_interface_static (type, + GTK_TYPE_TREE_DRAG_SOURCE, + &drag_source_info); + } + + return type; +} + +void +e_addressbook_treeview_adapter_construct (EAddressbookTreeViewAdapter *adapter, + EAddressbookModel *model) +{ + EAddressbookTreeViewAdapterPrivate *priv = adapter->priv; + + priv->model = model; + g_object_ref (priv->model); + + priv->stamp = g_random_int (); + + priv->create_card_id = g_signal_connect(priv->model, + "card_added", + G_CALLBACK(create_card), + adapter); + priv->remove_card_id = g_signal_connect(priv->model, + "card_removed", + G_CALLBACK(remove_card), + adapter); + priv->modify_card_id = g_signal_connect(priv->model, + "card_changed", + G_CALLBACK(modify_card), + adapter); + priv->model_changed_id = g_signal_connect(priv->model, + "model_changed", + G_CALLBACK(model_changed), + adapter); + + build_simple_mapping (adapter); +} + +GtkTreeModel * +e_addressbook_treeview_adapter_new (EAddressbookModel *model) +{ + EAddressbookTreeViewAdapter *et; + + et = g_object_new(E_TYPE_ADDRESSBOOK_TREEVIEW_ADAPTER, NULL); + + e_addressbook_treeview_adapter_construct (et, model); + + return (GtkTreeModel*)et; +} diff --git a/addressbook/gui/widgets/e-addressbook-treeview-adapter.h b/addressbook/gui/widgets/e-addressbook-treeview-adapter.h new file mode 100644 index 0000000000..2c4370dee3 --- /dev/null +++ b/addressbook/gui/widgets/e-addressbook-treeview-adapter.h @@ -0,0 +1,44 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +#ifndef _E_ADDRESSBOOK_TREEVIEW_ADAPTER_H_ +#define _E_ADDRESSBOOK_TREEVIEW_ADAPTER_H_ + +#include +#include "addressbook/backend/ebook/e-book.h" +#include "addressbook/backend/ebook/e-book-view.h" +#include "addressbook/backend/ebook/e-card-simple.h" + +#define E_TYPE_ADDRESSBOOK_TREEVIEW_ADAPTER (e_addressbook_treeview_adapter_get_type ()) +#define E_ADDRESSBOOK_TREEVIEW_ADAPTER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), E_TYPE_ADDRESSBOOK_TREEVIEW_ADAPTER, EAddressbookTreeViewAdapter)) +#define E_ADDRESSBOOK_TREEVIEW_ADAPTER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), E_TYPE_ADDRESSBOOK_TREEVIEW_ADAPTER, EAddressbookTreeViewAdapterClass)) +#define E_IS_ADDRESSBOOK_TREEVIEW_ADAPTER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), E_TYPE_ADDRESSBOOK_TREEVIEW_ADAPTER)) +#define E_IS_ADDRESSBOOK_TREEVIEW_ADAPTER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), E_TYPE_ADDRESSBOOK_TREEVIEW_ADAPTER)) + +/* Virtual Column list: + 0 Email + 1 Full Name + 2 Street + 3 Phone +*/ + +typedef struct _EAddressbookTreeViewAdapter EAddressbookTreeViewAdapter; +typedef struct _EAddressbookTreeViewAdapterPrivate EAddressbookTreeViewAdapterPrivate; +typedef struct _EAddressbookTreeViewAdapterClass EAddressbookTreeViewAdapterClass; + +struct _EAddressbookTreeViewAdapter { + GObject parent; + + EAddressbookTreeViewAdapterPrivate *priv; +}; + + +struct _EAddressbookTreeViewAdapterClass { + GObjectClass parent_class; +}; + + +GType e_addressbook_treeview_adapter_get_type (void); +void e_addressbook_treeview_adapter_construct (EAddressbookTreeViewAdapter *adapter, + EAddressbookModel *model); +GtkTreeModel *e_addressbook_treeview_adapter_new (EAddressbookModel *model); + +#endif /* _E_ADDRESSBOOK_TABLE_ADAPTER_H_ */ diff --git a/addressbook/gui/widgets/gal-view-factory-treeview.c b/addressbook/gui/widgets/gal-view-factory-treeview.c new file mode 100644 index 0000000000..b14c8dec59 --- /dev/null +++ b/addressbook/gui/widgets/gal-view-factory-treeview.c @@ -0,0 +1,86 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 + -*- */ +/* + * gal-view-factory-treeview.c: A View Factory + * + * Authors: + * Chris Lahey + * + * (C) 2000, 2001 Ximian, Inc. + */ +#include +#include +#include +#include +#include "gal-view-factory-treeview.h" +#include "gal-view-treeview.h" + +#define PARENT_TYPE GAL_VIEW_FACTORY_TYPE + +static GalViewFactoryClass *gal_view_factory_treeview_parent_class; + +static const char * +gal_view_factory_treeview_get_title (GalViewFactory *factory) +{ + return _("GTK Tree View"); +} + +static GalView * +gal_view_factory_treeview_new_view (GalViewFactory *factory, + const char *name) +{ + return gal_view_treeview_new(name); +} + +static const char * +gal_view_factory_treeview_get_type_code (GalViewFactory *factory) +{ + return "treeview"; +} + +static void +gal_view_factory_treeview_class_init (GObjectClass *object_class) +{ + GalViewFactoryClass *view_factory_class = GAL_VIEW_FACTORY_CLASS(object_class); + gal_view_factory_treeview_parent_class = g_type_class_ref (PARENT_TYPE); + + view_factory_class->get_title = gal_view_factory_treeview_get_title; + view_factory_class->new_view = gal_view_factory_treeview_new_view; + view_factory_class->get_type_code = gal_view_factory_treeview_get_type_code; +} + +static void +gal_view_factory_treeview_init (GalViewFactoryTreeView *factory) +{ +} + +/** + * gal_view_treeview_new + * + * A new GalViewFactory for creating TreeView views. Create one of + * these and pass it to GalViewCollection for use. + * + * Returns: The new GalViewFactoryTreeView. + */ +GalViewFactory * +gal_view_factory_treeview_new (void) +{ + return gal_view_factory_treeview_construct (g_object_new (GAL_TYPE_VIEW_FACTORY_TREEVIEW, NULL)); +} + +/** + * gal_view_treeview_construct + * @factory: The factory to construct + * + * constructs the GalViewFactoryTreeView. To be used by subclasses and + * language bindings. + * + * Returns: The GalViewFactoryTreeView. + */ +GalViewFactory * +gal_view_factory_treeview_construct (GalViewFactoryTreeView *factory) +{ + return GAL_VIEW_FACTORY(factory); +} + +E_MAKE_TYPE(gal_view_factory_treeview, "GalViewFactoryTreeView", GalViewFactoryTreeView, gal_view_factory_treeview_class_init, gal_view_factory_treeview_init, PARENT_TYPE) diff --git a/addressbook/gui/widgets/gal-view-factory-treeview.h b/addressbook/gui/widgets/gal-view-factory-treeview.h new file mode 100644 index 0000000000..4795c6d3aa --- /dev/null +++ b/addressbook/gui/widgets/gal-view-factory-treeview.h @@ -0,0 +1,35 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * gal-view-factory-treeview.c: A View Factory + * + * Authors: + * Chris Toshok + * + * (C) 2000, 2001 Ximian, Inc. + */ +#ifndef _GAL_VIEW_FACTORY_TREEVIEW_H_ +#define _GAL_VIEW_FACTORY_TREEVIEW_H_ + +#include +#include + +#define GAL_TYPE_VIEW_FACTORY_TREEVIEW (gal_view_factory_treeview_get_type ()) +#define GAL_VIEW_FACTORY_TREEVIEW(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GAL_TYPE_VIEW_FACTORY_TREEVIEW, GalViewFactoryTreeView)) +#define GAL_VIEW_FACTORY_TREEVIEW_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GAL_TYPE_VIEW_FACTORY_TREEVIEW, GalViewFactoryTreeViewClass)) +#define GAL_IS_VIEW_FACTORY_TREEVIEW(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GAL_TYPE_VIEW_FACTORY_TREEVIEW)) +#define GAL_IS_VIEW_FACTORY_TREEVIEW_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GAL_TYPE_VIEW_FACTORY_TREEVIEW)) + +typedef struct { + GalViewFactory base; +} GalViewFactoryTreeView; + +typedef struct { + GalViewFactoryClass parent_class; +} GalViewFactoryTreeViewClass; + +/* Standard functions */ +GType gal_view_factory_treeview_get_type (void); +GalViewFactory *gal_view_factory_treeview_new (void); +GalViewFactory *gal_view_factory_treeview_construct (GalViewFactoryTreeView *factory); + +#endif /* _GAL_VIEW_FACTORY_TREEVIEW_H_ */ diff --git a/addressbook/gui/widgets/gal-view-minicard.c b/addressbook/gui/widgets/gal-view-minicard.c index 4265af25ba..0d8e01c36b 100644 --- a/addressbook/gui/widgets/gal-view-minicard.c +++ b/addressbook/gui/widgets/gal-view-minicard.c @@ -18,7 +18,7 @@ static GalViewClass *gal_view_minicard_parent_class; static void -gal_view_minicard_edit (GalView *view) +gal_view_minicard_edit (GalView *view, GtkWindow *parent_window) { /* GalViewMinicard *minicard_view = GAL_VIEW_MINICARD(view); */ } diff --git a/addressbook/gui/widgets/gal-view-treeview.c b/addressbook/gui/widgets/gal-view-treeview.c new file mode 100644 index 0000000000..8d13d4aa26 --- /dev/null +++ b/addressbook/gui/widgets/gal-view-treeview.c @@ -0,0 +1,227 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * gal-view-treeview.c: An TreeView View + * + * Authors: + * Chris Lahey + * + * (C) 2000, 2001 Ximian, Inc. + */ +#include +#include "gal-view-treeview.h" +#include +#include + +#define PARENT_TYPE gal_view_get_type () +#define d(x) x + +static GalViewClass *gal_view_treeview_parent_class; + +static void +gal_view_treeview_edit (GalView *view, GtkWindow *parent_window) +{ + /* GalViewTreeView *treeview_view = GAL_VIEW_TREEVIEW(view); */ +} + +static void +gal_view_treeview_load (GalView *view, + const char *filename) +{ +#if 0 + xmlDoc *doc; + doc = xmlParseFile (filename); + if (doc) { + xmlNode *root = xmlDocGetRootElement(doc); + GAL_VIEW_TREEVIEW (view)->column_width = e_xml_get_double_prop_by_name_with_default (root, "column_width", 150); + xmlFreeDoc(doc); + } +#endif +} + +static void +gal_view_treeview_save (GalView *view, + const char *filename) +{ +#if 0 + xmlDoc *doc; + xmlNode *root; + + doc = xmlNewDoc("1.0"); + root = xmlNewNode (NULL, "ETreeViewViewState"); + e_xml_set_double_prop_by_name (root, "column_width", GAL_VIEW_TREEVIEW (view)->column_width); + xmlDocSetRootElement(doc, root); + xmlSaveFile(filename, doc); + xmlFreeDoc(doc); +#endif +} + +static const char * +gal_view_treeview_get_title (GalView *view) +{ + return GAL_VIEW_TREEVIEW(view)->title; +} + +static void +gal_view_treeview_set_title (GalView *view, + const char *title) +{ + g_free(GAL_VIEW_TREEVIEW(view)->title); + GAL_VIEW_TREEVIEW(view)->title = g_strdup(title); +} + +static const char * +gal_view_treeview_get_type_code (GalView *view) +{ + return "treeview"; +} + +static GalView * +gal_view_treeview_clone (GalView *view) +{ + GalViewTreeView *gvm, *new; + + gvm = GAL_VIEW_TREEVIEW(view); + + new = g_object_new (GAL_TYPE_VIEW_TREEVIEW, NULL); + new->title = g_strdup (gvm->title); + + return GAL_VIEW(new); +} + +static void +gal_view_treeview_dispose (GObject *object) +{ + GalViewTreeView *view = GAL_VIEW_TREEVIEW(object); + gal_view_treeview_detach (view); + g_free(view->title); +} + +static void +gal_view_treeview_class_init (GObjectClass *object_class) +{ + GalViewClass *gal_view_class = GAL_VIEW_CLASS(object_class); + gal_view_treeview_parent_class = g_type_class_ref (PARENT_TYPE); + + gal_view_class->edit = gal_view_treeview_edit ; + gal_view_class->load = gal_view_treeview_load ; + gal_view_class->save = gal_view_treeview_save ; + gal_view_class->get_title = gal_view_treeview_get_title ; + gal_view_class->set_title = gal_view_treeview_set_title ; + gal_view_class->get_type_code = gal_view_treeview_get_type_code; + gal_view_class->clone = gal_view_treeview_clone ; + + object_class->dispose = gal_view_treeview_dispose ; +} + +static void +gal_view_treeview_init (GalViewTreeView *gvm) +{ + gvm->title = NULL; + + gvm->tree = NULL; +} + +/** + * gal_view_treeview_new + * @title: The name of the new view. + * + * Returns a new GalViewTreeView. This is primarily for use by + * GalViewFactoryTreeView. + * + * Returns: The new GalViewTreeView. + */ +GalView * +gal_view_treeview_new (const gchar *title) +{ + return gal_view_treeview_construct (g_object_new (GAL_TYPE_VIEW_TREEVIEW, NULL), title); +} + +/** + * gal_view_treeview_construct + * @view: The view to construct. + * @title: The name of the new view. + * + * constructs the GalViewTreeView. To be used by subclasses and + * language bindings. + * + * Returns: The GalViewTreeView. + */ +GalView * +gal_view_treeview_construct (GalViewTreeView *view, + const gchar *title) +{ + view->title = g_strdup(title); + return GAL_VIEW(view); +} + +GType +gal_view_treeview_get_type (void) +{ + static GType type = 0; + + if (!type) { + static const GTypeInfo info = { + sizeof (GalViewTreeViewClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) gal_view_treeview_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (GalViewTreeView), + 0, /* n_preallocs */ + (GInstanceInitFunc) gal_view_treeview_init, + }; + + type = g_type_register_static (PARENT_TYPE, "GalViewTreeView", &info, 0); + } + + return type; +} + +#if 0 +static void +column_width_changed (ETable *table, double width, GalViewMinicard *view) +{ + d(g_print("%s: Old width = %f, New width = %f\n", __FUNCTION__, view->column_width, width)); + if (view->column_width != width) { + view->column_width = width; + gal_view_changed(GAL_VIEW(view)); + } +} +#endif + +void +gal_view_treeview_attach (GalViewTreeView *view, GtkTreeView *tree) +{ +#if 0 + gal_view_treeview_detach (view); + + view->emvw = emvw; + + g_object_ref (view->emvw); + + g_object_set (view->emvw, + "column_width", view->column_width, + NULL); + + view->emvw_column_width_changed_id = + g_signal_connect(view->emvw, "column_width_changed", + G_CALLBACK (column_width_changed), view); +#endif +} + +void +gal_view_treeview_detach (GalViewTreeView *view) +{ +#if 0 + if (view->emvw == NULL) + return; + if (view->emvw_column_width_changed_id) { + g_signal_handler_disconnect (view->emvw, + view->emvw_column_width_changed_id); + view->emvw_column_width_changed_id = 0; + } + g_object_unref (view->emvw); + view->emvw = NULL; +#endif +} diff --git a/addressbook/gui/widgets/gal-view-treeview.h b/addressbook/gui/widgets/gal-view-treeview.h new file mode 100644 index 0000000000..a0313856a6 --- /dev/null +++ b/addressbook/gui/widgets/gal-view-treeview.h @@ -0,0 +1,43 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * gal-view-treeview.h: An TreeView View + * + * Authors: + * Chris Toshok + * + * (C) 2000, 2001 Ximian, Inc. + */ +#ifndef _GAL_VIEW_TREEVIEW_H_ +#define _GAL_VIEW_TREEVIEW_H_ + +#include +#include + +#define GAL_TYPE_VIEW_TREEVIEW (gal_view_treeview_get_type ()) +#define GAL_VIEW_TREEVIEW(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GAL_TYPE_VIEW_TREEVIEW, GalViewTreeView)) +#define GAL_VIEW_TREEVIEW_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GAL_TYPE_VIEW_TREEVIEW, GalViewTreeViewClass)) +#define GAL_IS_VIEW_TREEVIEW(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GAL_TYPE_VIEW_TREEVIEW)) +#define GAL_IS_VIEW_TREEVIEW_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GAL_TYPE_VIEW_TREEVIEW)) + +typedef struct { + GalView base; + + char *title; + + GtkTreeView *tree; +} GalViewTreeView; + +typedef struct { + GalViewClass parent_class; +} GalViewTreeViewClass; + +/* Standard functions */ +GType gal_view_treeview_get_type (void); +GalView *gal_view_treeview_new (const gchar *title); +GalView *gal_view_treeview_construct (GalViewTreeView *view, + const gchar *title); +void gal_view_treeview_attach (GalViewTreeView *view, + GtkTreeView *tree); +void gal_view_treeview_detach (GalViewTreeView *view); + +#endif /* _GAL_VIEW_TREEVIEW_H_ */ -- cgit