aboutsummaryrefslogtreecommitdiffstats
path: root/e-util/e-reflow-model.c
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2012-12-10 21:09:59 +0800
committerMatthew Barnes <mbarnes@redhat.com>2012-12-13 03:33:43 +0800
commitd09d8de870b6697c8a8b262e7e077b871a69b315 (patch)
tree3b718882e7a0bb0a996daf2967a033d91714c9b5 /e-util/e-reflow-model.c
parentb61331ed03ac1c7a9b8614e25510040b9c60ae02 (diff)
downloadgsoc2013-evolution-d09d8de870b6697c8a8b262e7e077b871a69b315.tar
gsoc2013-evolution-d09d8de870b6697c8a8b262e7e077b871a69b315.tar.gz
gsoc2013-evolution-d09d8de870b6697c8a8b262e7e077b871a69b315.tar.bz2
gsoc2013-evolution-d09d8de870b6697c8a8b262e7e077b871a69b315.tar.lz
gsoc2013-evolution-d09d8de870b6697c8a8b262e7e077b871a69b315.tar.xz
gsoc2013-evolution-d09d8de870b6697c8a8b262e7e077b871a69b315.tar.zst
gsoc2013-evolution-d09d8de870b6697c8a8b262e7e077b871a69b315.zip
Consolidate base utility libraries into libeutil.
Evolution consists of entirely too many small utility libraries, which increases linking and loading time, places a burden on higher layers of the application (e.g. modules) which has to remember to link to all the small in-tree utility libraries, and makes it difficult to generate API documentation for these utility libraries in one Gtk-Doc module. Merge the following utility libraries under the umbrella of libeutil, and enforce a single-include policy on libeutil so we can reorganize the files as desired without disrupting its pseudo-public API. libemail-utils/libemail-utils.la libevolution-utils/libevolution-utils.la filter/libfilter.la widgets/e-timezone-dialog/libetimezonedialog.la widgets/menus/libmenus.la widgets/misc/libemiscwidgets.la widgets/table/libetable.la widgets/text/libetext.la This also merges libedataserverui from the Evolution-Data-Server module, since Evolution is its only consumer nowadays, and I'd like to make some improvements to those APIs without concern for backward-compatibility. And finally, start a Gtk-Doc module for libeutil. It's going to be a project just getting all the symbols _listed_ much less _documented_. But the skeletal structure is in place and I'm off to a good start.
Diffstat (limited to 'e-util/e-reflow-model.c')
-rw-r--r--e-util/e-reflow-model.c411
1 files changed, 411 insertions, 0 deletions
diff --git a/e-util/e-reflow-model.c b/e-util/e-reflow-model.c
new file mode 100644
index 0000000000..4f5b219b90
--- /dev/null
+++ b/e-util/e-reflow-model.c
@@ -0,0 +1,411 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ *
+ * Authors:
+ * Chris Lahey <clahey@ximian.com>
+ * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "e-reflow-model.h"
+
+#include "e-misc-utils.h"
+
+G_DEFINE_TYPE (EReflowModel, e_reflow_model, G_TYPE_OBJECT)
+
+#define d(x)
+
+d (static gint depth = 0;)
+
+enum {
+ MODEL_CHANGED,
+ COMPARISON_CHANGED,
+ MODEL_ITEMS_INSERTED,
+ MODEL_ITEM_CHANGED,
+ MODEL_ITEM_REMOVED,
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0, };
+
+/**
+ * e_reflow_model_set_width:
+ * @e_reflow_model: The e-reflow-model to operate on
+ * @width: The new value for the width of each item.
+ */
+void
+e_reflow_model_set_width (EReflowModel *e_reflow_model,
+ gint width)
+{
+ EReflowModelClass *class;
+
+ g_return_if_fail (E_IS_REFLOW_MODEL (e_reflow_model));
+
+ class = E_REFLOW_MODEL_GET_CLASS (e_reflow_model);
+ g_return_if_fail (class->set_width != NULL);
+
+ class->set_width (e_reflow_model, width);
+}
+
+/**
+ * e_reflow_model_count:
+ * @e_reflow_model: The e-reflow-model to operate on
+ *
+ * Returns: the number of items in the reflow model.
+ */
+gint
+e_reflow_model_count (EReflowModel *e_reflow_model)
+{
+ EReflowModelClass *class;
+
+ g_return_val_if_fail (E_IS_REFLOW_MODEL (e_reflow_model), 0);
+
+ class = E_REFLOW_MODEL_GET_CLASS (e_reflow_model);
+ g_return_val_if_fail (class->count != NULL, 0);
+
+ return class->count (e_reflow_model);
+}
+
+/**
+ * e_reflow_model_height:
+ * @e_reflow_model: The e-reflow-model to operate on
+ * @n: The item number to get the height of.
+ * @parent: The parent GnomeCanvasItem.
+ *
+ * Returns: the height of the nth item.
+ */
+gint
+e_reflow_model_height (EReflowModel *e_reflow_model,
+ gint n,
+ GnomeCanvasGroup *parent)
+{
+ EReflowModelClass *class;
+
+ g_return_val_if_fail (E_IS_REFLOW_MODEL (e_reflow_model), 0);
+
+ class = E_REFLOW_MODEL_GET_CLASS (e_reflow_model);
+ g_return_val_if_fail (class->height != NULL, 0);
+
+ return class->height (e_reflow_model, n, parent);
+}
+
+/**
+ * e_reflow_model_incarnate:
+ * @e_reflow_model: The e-reflow-model to operate on
+ * @n: The item to create.
+ * @parent: The parent GnomeCanvasItem to create a child of.
+ *
+ * Create a GnomeCanvasItem to represent the nth piece of data.
+ *
+ * Returns: the new GnomeCanvasItem.
+ */
+GnomeCanvasItem *
+e_reflow_model_incarnate (EReflowModel *e_reflow_model,
+ gint n,
+ GnomeCanvasGroup *parent)
+{
+ EReflowModelClass *class;
+
+ g_return_val_if_fail (E_IS_REFLOW_MODEL (e_reflow_model), NULL);
+
+ class = E_REFLOW_MODEL_GET_CLASS (e_reflow_model);
+ g_return_val_if_fail (class->incarnate != NULL, NULL);
+
+ return class->incarnate (e_reflow_model, n, parent);
+}
+
+/**
+ * e_reflow_model_create_cmp_cache:
+ * @e_reflow_model: The e-reflow-model to operate on
+ *
+ * Creates a compare cache for quicker sorting. The sorting function
+ * may not depend on the cache, but it should benefit from it if available.
+ *
+ * Returns: Newly created GHashTable with cached compare values. This will be
+ * automatically freed with g_hash_table_destroy() when no longer needed.
+ **/
+GHashTable *
+e_reflow_model_create_cmp_cache (EReflowModel *e_reflow_model)
+{
+ EReflowModelClass *class;
+
+ g_return_val_if_fail (E_IS_REFLOW_MODEL (e_reflow_model), NULL);
+
+ class = E_REFLOW_MODEL_GET_CLASS (e_reflow_model);
+
+ if (class->create_cmp_cache == NULL)
+ return NULL;
+
+ return class->create_cmp_cache (e_reflow_model);
+}
+
+/**
+ * e_reflow_model_compare:
+ * @e_reflow_model: The e-reflow-model to operate on
+ * @n1: The first item to compare
+ * @n2: The second item to compare
+ * @cmp_cache: #GHashTable of cached compare values, created by
+ * e_reflow_model_create_cmp_cache(). This can be NULL, when
+ * caching is not available, even when @e_reflow_model defines
+ * the create_cmp_cache function.
+ *
+ * Compares item n1 and item n2 to see which should come first.
+ *
+ * Returns: strcmp like semantics for the comparison value.
+ */
+gint
+e_reflow_model_compare (EReflowModel *e_reflow_model,
+ gint n1,
+ gint n2,
+ GHashTable *cmp_cache)
+{
+ EReflowModelClass *class;
+
+ g_return_val_if_fail (E_IS_REFLOW_MODEL (e_reflow_model), 0);
+
+ class = E_REFLOW_MODEL_GET_CLASS (e_reflow_model);
+ g_return_val_if_fail (class->compare != NULL, 0);
+
+ return class->compare (e_reflow_model, n1, n2, cmp_cache);
+}
+
+/**
+ * e_reflow_model_reincarnate:
+ * @e_reflow_model: The e-reflow-model to operate on
+ * @n: The item to create.
+ * @item: The item to reuse.
+ *
+ * Update item to represent the nth piece of data.
+ */
+void
+e_reflow_model_reincarnate (EReflowModel *e_reflow_model,
+ gint n,
+ GnomeCanvasItem *item)
+{
+ EReflowModelClass *class;
+
+ g_return_if_fail (E_IS_REFLOW_MODEL (e_reflow_model));
+
+ class = E_REFLOW_MODEL_GET_CLASS (e_reflow_model);
+ g_return_if_fail (class->reincarnate != NULL);
+
+ class->reincarnate (e_reflow_model, n, item);
+}
+
+static void
+e_reflow_model_class_init (EReflowModelClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+ class->set_width = NULL;
+ class->count = NULL;
+ class->height = NULL;
+ class->incarnate = NULL;
+ class->reincarnate = NULL;
+
+ class->model_changed = NULL;
+ class->comparison_changed = NULL;
+ class->model_items_inserted = NULL;
+ class->model_item_removed = NULL;
+ class->model_item_changed = NULL;
+
+ signals[MODEL_CHANGED] = g_signal_new (
+ "model_changed",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (EReflowModelClass, model_changed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
+ signals[COMPARISON_CHANGED] = g_signal_new (
+ "comparison_changed",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (EReflowModelClass, comparison_changed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
+ signals[MODEL_ITEMS_INSERTED] = g_signal_new (
+ "model_items_inserted",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (EReflowModelClass, model_items_inserted),
+ NULL, NULL,
+ e_marshal_NONE__INT_INT,
+ G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT);
+
+ signals[MODEL_ITEM_CHANGED] = g_signal_new (
+ "model_item_changed",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (EReflowModelClass, model_item_changed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__INT,
+ G_TYPE_NONE, 1, G_TYPE_INT);
+
+ signals[MODEL_ITEM_REMOVED] = g_signal_new (
+ "model_item_removed",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (EReflowModelClass, model_item_removed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__INT,
+ G_TYPE_NONE, 1, G_TYPE_INT);
+}
+
+static void
+e_reflow_model_init (EReflowModel *e_reflow_model)
+{
+}
+
+#if d(!)0
+static void
+print_tabs (void)
+{
+ gint i;
+ for (i = 0; i < depth; i++)
+ g_print ("\t");
+}
+#endif
+
+/**
+ * e_reflow_model_changed:
+ * @e_reflow_model: the reflow model to notify of the change
+ *
+ * Use this function to notify any views of this reflow model that
+ * the contents of the reflow model have changed. This will emit
+ * the signal "model_changed" on the @e_reflow_model object.
+ *
+ * It is preferable to use the e_reflow_model_item_changed() signal to
+ * notify of smaller changes than to invalidate the entire model, as
+ * the views might have ways of caching the information they render
+ * from the model.
+ */
+void
+e_reflow_model_changed (EReflowModel *e_reflow_model)
+{
+ g_return_if_fail (e_reflow_model != NULL);
+ g_return_if_fail (E_IS_REFLOW_MODEL (e_reflow_model));
+
+ d (print_tabs ());
+ d (g_print ("Emitting model_changed on model 0x%p.\n", e_reflow_model));
+ d (depth++);
+ g_signal_emit (e_reflow_model, signals[MODEL_CHANGED], 0);
+ d (depth--);
+}
+
+/**
+ * e_reflow_model_comparison_changed:
+ * @e_reflow_model: the reflow model to notify of the change
+ *
+ * Use this function to notify any views of this reflow model that the
+ * sorting has changed. The actual contents of the items hasn't, so
+ * there's no need to re-query the model for the heights of the
+ * individual items.
+ */
+void
+e_reflow_model_comparison_changed (EReflowModel *e_reflow_model)
+{
+ g_return_if_fail (e_reflow_model != NULL);
+ g_return_if_fail (E_IS_REFLOW_MODEL (e_reflow_model));
+
+ d (print_tabs ());
+ d (g_print (
+ "Emitting comparison_changed on model 0x%p.\n",
+ e_reflow_model));
+ d (depth++);
+ g_signal_emit (e_reflow_model, signals[COMPARISON_CHANGED], 0);
+ d (depth--);
+}
+
+/**
+ * e_reflow_model_items_inserted:
+ * @e_reflow_model: The model changed.
+ * @position: The position the items were insert in.
+ * @count: The number of items inserted.
+ *
+ * Use this function to notify any views of the reflow model that a number
+ * of items have been inserted.
+ **/
+void
+e_reflow_model_items_inserted (EReflowModel *e_reflow_model,
+ gint position,
+ gint count)
+{
+ g_return_if_fail (e_reflow_model != NULL);
+ g_return_if_fail (E_IS_REFLOW_MODEL (e_reflow_model));
+
+ d (print_tabs ());
+ d (depth++);
+ g_signal_emit (
+ e_reflow_model,
+ signals[MODEL_ITEMS_INSERTED], 0,
+ position, count);
+ d (depth--);
+}
+
+/**
+ * e_reflow_model_item_removed:
+ * @e_reflow_model: The model changed.
+ * @n: The position from which the items were removed.
+ *
+ * Use this function to notify any views of the reflow model that an
+ * item has been removed.
+ **/
+void
+e_reflow_model_item_removed (EReflowModel *e_reflow_model,
+ gint n)
+{
+ g_return_if_fail (e_reflow_model != NULL);
+ g_return_if_fail (E_IS_REFLOW_MODEL (e_reflow_model));
+
+ d (print_tabs ());
+ d (depth++);
+ g_signal_emit (e_reflow_model, signals[MODEL_ITEM_REMOVED], 0, n);
+ d (depth--);
+}
+
+/**
+ * e_reflow_model_item_changed:
+ * @e_reflow_model: the reflow model to notify of the change
+ * @item: the item that was changed in the model.
+ *
+ * Use this function to notify any views of the reflow model that the
+ * contents of item @item have changed in model such that the height
+ * has changed or the item needs to be reincarnated. This function
+ * will emit the "model_item_changed" signal on the @e_reflow_model
+ * object
+ */
+void
+e_reflow_model_item_changed (EReflowModel *e_reflow_model,
+ gint n)
+{
+ g_return_if_fail (e_reflow_model != NULL);
+ g_return_if_fail (E_IS_REFLOW_MODEL (e_reflow_model));
+
+ d (print_tabs ());
+ d (g_print ("Emitting item_changed on model 0x%p, n=%d.\n", e_reflow_model, n));
+ d (depth++);
+ g_signal_emit (e_reflow_model, signals[MODEL_ITEM_CHANGED], 0, n);
+ d (depth--);
+}