[evolution] Convert ESorter to an interface.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution] Convert ESorter to an interface.
- Date: Thu, 20 Jun 2013 21:00:40 +0000 (UTC)
commit ad6b3f483d22a00070f60b69855e72563d9895ea
Author: Matthew Barnes <mbarnes redhat com>
Date: Thu Jun 20 15:58:05 2013 -0400
Convert ESorter to an interface.
.../evolution-util/evolution-util-sections.txt | 6 +-
e-util/e-sorter-array.c | 189 +++++++++----------
e-util/e-sorter-array.h | 4 +-
e-util/e-sorter.c | 96 +++-------
e-util/e-sorter.h | 29 +---
e-util/e-table-sorter.c | 198 ++++++++++----------
e-util/e-table-sorter.h | 4 +-
7 files changed, 232 insertions(+), 294 deletions(-)
---
diff --git a/doc/reference/evolution-util/evolution-util-sections.txt
b/doc/reference/evolution-util/evolution-util-sections.txt
index 67b961e..b15a763 100644
--- a/doc/reference/evolution-util/evolution-util-sections.txt
+++ b/doc/reference/evolution-util/evolution-util-sections.txt
@@ -3073,10 +3073,8 @@ e_sorter_needs_sorting
E_SORTER
E_IS_SORTER
E_TYPE_SORTER
-E_SORTER_CLASS
-E_IS_SORTER_CLASS
-E_SORTER_GET_CLASS
-ESorterClass
+E_SORTER_GET_INTERFACE
+ESorterInterface
e_sorter_get_type
</SECTION>
diff --git a/e-util/e-sorter-array.c b/e-util/e-sorter-array.c
index fc411e1..f5cd03a 100644
--- a/e-util/e-sorter-array.c
+++ b/e-util/e-sorter-array.c
@@ -35,25 +35,19 @@
#define INCREMENT_AMOUNT 100
-G_DEFINE_TYPE (
- ESorterArray,
- e_sorter_array,
- E_TYPE_SORTER)
-
static void esa_sort (ESorterArray *esa);
static void esa_backsort (ESorterArray *esa);
-static gint esa_model_to_sorted (ESorter *sorter, gint row);
-static gint esa_sorted_to_model (ESorter *sorter, gint row);
-static void esa_get_model_to_sorted_array (ESorter *sorter,
- gint **array,
- gint *count);
-static void esa_get_sorted_to_model_array (ESorter *sorter,
- gint **array,
- gint *count);
-static gboolean esa_needs_sorting (ESorter *esa);
+/* Forward Declarations */
+static void e_sorter_array_interface_init (ESorterInterface *interface);
-#define ESA_NEEDS_SORTING(esa) (((ESorterArray *) (esa))->compare != NULL)
+G_DEFINE_TYPE_WITH_CODE (
+ ESorterArray,
+ e_sorter_array,
+ G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (
+ E_TYPE_SORTER,
+ e_sorter_array_interface_init))
static gint
esort_callback (gconstpointer data1,
@@ -127,81 +121,6 @@ esa_backsort (ESorterArray *esa)
}
}
-static gint
-esa_model_to_sorted (ESorter *es,
- gint row)
-{
- ESorterArray *esa = E_SORTER_ARRAY (es);
-
- g_return_val_if_fail (row >= 0, -1);
- g_return_val_if_fail (row < esa->rows, -1);
-
- if (ESA_NEEDS_SORTING (es))
- esa_backsort (esa);
-
- if (esa->backsorted)
- return esa->backsorted[row];
- else
- return row;
-}
-
-static gint
-esa_sorted_to_model (ESorter *es,
- gint row)
-{
- ESorterArray *esa = (ESorterArray *) es;
-
- g_return_val_if_fail (row >= 0, -1);
- g_return_val_if_fail (row < esa->rows, -1);
-
- if (ESA_NEEDS_SORTING (es))
- esa_sort (esa);
-
- if (esa->sorted)
- return esa->sorted[row];
- else
- return row;
-}
-
-static void
-esa_get_model_to_sorted_array (ESorter *es,
- gint **array,
- gint *count)
-{
- ESorterArray *esa = E_SORTER_ARRAY (es);
- if (array || count) {
- esa_backsort (esa);
-
- if (array)
- *array = esa->backsorted;
- if (count)
- *count = esa->rows;
- }
-}
-
-static void
-esa_get_sorted_to_model_array (ESorter *es,
- gint **array,
- gint *count)
-{
- ESorterArray *esa = E_SORTER_ARRAY (es);
- if (array || count) {
- esa_sort (esa);
-
- if (array)
- *array = esa->sorted;
- if (count)
- *count = esa->rows;
- }
-}
-
-static gboolean
-esa_needs_sorting (ESorter *es)
-{
- ESorterArray *esa = E_SORTER_ARRAY (es);
- return esa->compare != NULL;
-}
-
void
e_sorter_array_clean (ESorterArray *esa)
{
@@ -283,19 +202,97 @@ e_sorter_array_new (ECreateCmpCacheFunc create_cmp_cache,
return e_sorter_array_construct (esa, create_cmp_cache, compare, closure);
}
+static gint
+sorter_array_model_to_sorted (ESorter *es,
+ gint row)
+{
+ ESorterArray *esa = E_SORTER_ARRAY (es);
+
+ g_return_val_if_fail (row >= 0, -1);
+ g_return_val_if_fail (row < esa->rows, -1);
+
+ if (e_sorter_needs_sorting (es))
+ esa_backsort (esa);
+
+ if (esa->backsorted)
+ return esa->backsorted[row];
+ else
+ return row;
+}
+
+static gint
+sorter_array_sorted_to_model (ESorter *es,
+ gint row)
+{
+ ESorterArray *esa = (ESorterArray *) es;
+
+ g_return_val_if_fail (row >= 0, -1);
+ g_return_val_if_fail (row < esa->rows, -1);
+
+ if (e_sorter_needs_sorting (es))
+ esa_sort (esa);
+
+ if (esa->sorted)
+ return esa->sorted[row];
+ else
+ return row;
+}
+
+static void
+sorter_array_get_model_to_sorted_array (ESorter *es,
+ gint **array,
+ gint *count)
+{
+ ESorterArray *esa = E_SORTER_ARRAY (es);
+ if (array || count) {
+ esa_backsort (esa);
+
+ if (array)
+ *array = esa->backsorted;
+ if (count)
+ *count = esa->rows;
+ }
+}
+
+static void
+sorter_array_get_sorted_to_model_array (ESorter *es,
+ gint **array,
+ gint *count)
+{
+ ESorterArray *esa = E_SORTER_ARRAY (es);
+ if (array || count) {
+ esa_sort (esa);
+
+ if (array)
+ *array = esa->sorted;
+ if (count)
+ *count = esa->rows;
+ }
+}
+
+static gboolean
+sorter_array_needs_sorting (ESorter *es)
+{
+ ESorterArray *esa = E_SORTER_ARRAY (es);
+ return esa->compare != NULL;
+}
+
static void
e_sorter_array_class_init (ESorterArrayClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
- ESorterClass *sorter_class = E_SORTER_CLASS (class);
object_class->finalize = esa_finalize;
+}
- sorter_class->model_to_sorted = esa_model_to_sorted;
- sorter_class->sorted_to_model = esa_sorted_to_model;
- sorter_class->get_model_to_sorted_array = esa_get_model_to_sorted_array;
- sorter_class->get_sorted_to_model_array = esa_get_sorted_to_model_array;
- sorter_class->needs_sorting = esa_needs_sorting;
+static void
+e_sorter_array_interface_init (ESorterInterface *interface)
+{
+ interface->model_to_sorted = sorter_array_model_to_sorted;
+ interface->sorted_to_model = sorter_array_sorted_to_model;
+ interface->get_model_to_sorted_array = sorter_array_get_model_to_sorted_array;
+ interface->get_sorted_to_model_array = sorter_array_get_sorted_to_model_array;
+ interface->needs_sorting = sorter_array_needs_sorting;
}
static void
diff --git a/e-util/e-sorter-array.h b/e-util/e-sorter-array.h
index 04899d2..468c320 100644
--- a/e-util/e-sorter-array.h
+++ b/e-util/e-sorter-array.h
@@ -61,7 +61,7 @@ typedef gint (*ECompareRowsFunc) (gint row1,
typedef GHashTable * (*ECreateCmpCacheFunc) (gpointer closure);
struct _ESorterArray {
- ESorter parent;
+ GObject parent;
GHashTable *cmp_cache;
ECreateCmpCacheFunc create_cmp_cache;
@@ -77,7 +77,7 @@ struct _ESorterArray {
};
struct _ESorterArrayClass {
- ESorterClass parent_class;
+ GObjectClass parent_class;
};
GType e_sorter_array_get_type (void) G_GNUC_CONST;
diff --git a/e-util/e-sorter.c b/e-util/e-sorter.c
index f2023d7..0534f21 100644
--- a/e-util/e-sorter.c
+++ b/e-util/e-sorter.c
@@ -1,4 +1,6 @@
/*
+ * e-sorter.h
+ *
* 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
@@ -12,64 +14,14 @@
* 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)
- *
*/
#include "e-sorter.h"
-G_DEFINE_TYPE (ESorter, e_sorter, G_TYPE_OBJECT)
-
-static gint
-sorter_model_to_sorted (ESorter *sorter,
- gint row)
-{
- return row;
-}
-
-static gint
-sorter_sorted_to_model (ESorter *sorter,
- gint row)
-{
- return row;
-}
-
-static void
-sorter_get_model_to_sorted_array (ESorter *sorter,
- gint **array,
- gint *count)
-{
-}
-
-static void
-sorter_get_sorted_to_model_array (ESorter *sorter,
- gint **array,
- gint *count)
-{
-}
-
-static gboolean
-sorter_needs_sorting (ESorter *sorter)
-{
- return FALSE;
-}
-
-static void
-e_sorter_class_init (ESorterClass *class)
-{
- class->model_to_sorted = sorter_model_to_sorted;
- class->sorted_to_model = sorter_sorted_to_model;
- class->get_model_to_sorted_array = sorter_get_model_to_sorted_array;
- class->get_sorted_to_model_array = sorter_get_sorted_to_model_array;
- class->needs_sorting = sorter_needs_sorting;
-}
+G_DEFINE_INTERFACE (ESorter, e_sorter, G_TYPE_OBJECT)
static void
-e_sorter_init (ESorter *sorter)
+e_sorter_default_init (ESorterInterface *interface)
{
}
@@ -77,30 +29,30 @@ gint
e_sorter_model_to_sorted (ESorter *sorter,
gint row)
{
- ESorterClass *class;
+ ESorterInterface *interface;
g_return_val_if_fail (E_IS_SORTER (sorter), -1);
g_return_val_if_fail (row >= 0, -1);
- class = E_SORTER_GET_CLASS (sorter);
- g_return_val_if_fail (class->model_to_sorted != NULL, -1);
+ interface = E_SORTER_GET_INTERFACE (sorter);
+ g_return_val_if_fail (interface->model_to_sorted != NULL, -1);
- return class->model_to_sorted (sorter, row);
+ return interface->model_to_sorted (sorter, row);
}
gint
e_sorter_sorted_to_model (ESorter *sorter,
gint row)
{
- ESorterClass *class;
+ ESorterInterface *interface;
g_return_val_if_fail (E_IS_SORTER (sorter), -1);
g_return_val_if_fail (row >= 0, -1);
- class = E_SORTER_GET_CLASS (sorter);
- g_return_val_if_fail (class->sorted_to_model != NULL, -1);
+ interface = E_SORTER_GET_INTERFACE (sorter);
+ g_return_val_if_fail (interface->sorted_to_model != NULL, -1);
- return class->sorted_to_model (sorter, row);
+ return interface->sorted_to_model (sorter, row);
}
void
@@ -108,14 +60,14 @@ e_sorter_get_model_to_sorted_array (ESorter *sorter,
gint **array,
gint *count)
{
- ESorterClass *class;
+ ESorterInterface *interface;
g_return_if_fail (E_IS_SORTER (sorter));
- class = E_SORTER_GET_CLASS (sorter);
- g_return_if_fail (class->get_model_to_sorted_array != NULL);
+ interface = E_SORTER_GET_INTERFACE (sorter);
+ g_return_if_fail (interface->get_model_to_sorted_array != NULL);
- class->get_model_to_sorted_array (sorter, array, count);
+ interface->get_model_to_sorted_array (sorter, array, count);
}
void
@@ -123,26 +75,26 @@ e_sorter_get_sorted_to_model_array (ESorter *sorter,
gint **array,
gint *count)
{
- ESorterClass *class;
+ ESorterInterface *interface;
g_return_if_fail (E_IS_SORTER (sorter));
- class = E_SORTER_GET_CLASS (sorter);
- g_return_if_fail (class->get_sorted_to_model_array != NULL);
+ interface = E_SORTER_GET_INTERFACE (sorter);
+ g_return_if_fail (interface->get_sorted_to_model_array != NULL);
- class->get_sorted_to_model_array (sorter, array, count);
+ interface->get_sorted_to_model_array (sorter, array, count);
}
gboolean
e_sorter_needs_sorting (ESorter *sorter)
{
- ESorterClass *class;
+ ESorterInterface *interface;
g_return_val_if_fail (E_IS_SORTER (sorter), FALSE);
- class = E_SORTER_GET_CLASS (sorter);
- g_return_val_if_fail (class->needs_sorting != NULL, FALSE);
+ interface = E_SORTER_GET_INTERFACE (sorter);
+ g_return_val_if_fail (interface->needs_sorting != NULL, FALSE);
- return class->needs_sorting (sorter);
+ return interface->needs_sorting (sorter);
}
diff --git a/e-util/e-sorter.h b/e-util/e-sorter.h
index 4ab5e84..7006030 100644
--- a/e-util/e-sorter.h
+++ b/e-util/e-sorter.h
@@ -1,4 +1,5 @@
/*
+ * e-sorter.h
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -13,12 +14,6 @@
* 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)
- *
*/
#if !defined (__E_UTIL_H_INSIDE__) && !defined (LIBEUTIL_COMPILATION)
@@ -36,30 +31,20 @@
#define E_SORTER(obj) \
(G_TYPE_CHECK_INSTANCE_CAST \
((obj), E_TYPE_SORTER, ESorter))
-#define E_SORTER_CLASS(cls) \
- (G_TYPE_CHECK_CLASS_CAST \
- ((cls), E_TYPE_SORTER, ESorterClass))
#define E_IS_SORTER(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE \
((obj), E_TYPE_SORTER))
-#define E_IS_SORTER_CLASS(cls) \
- (G_TYPE_CHECK_CLASS_TYPE \
- ((cls), E_TYPE_SORTER))
-#define E_SORTER_GET_CLASS(obj) \
- (G_TYPE_INSTANCE_GET_CLASS \
- ((obj), E_TYPE_SORTER, ESorterClass))
+#define E_SORTER_GET_INTERFACE(obj) \
+ (G_TYPE_INSTANCE_GET_INTERFACE \
+ ((obj), E_TYPE_SORTER, ESorterInterface))
G_BEGIN_DECLS
typedef struct _ESorter ESorter;
-typedef struct _ESorterClass ESorterClass;
-
-struct _ESorter {
- GObject parent;
-};
+typedef struct _ESorterInterface ESorterInterface;
-struct _ESorterClass {
- GObjectClass parent_class;
+struct _ESorterInterface {
+ GTypeInterface parent_interface;
gint (*model_to_sorted) (ESorter *sorter,
gint row);
diff --git a/e-util/e-table-sorter.c b/e-util/e-table-sorter.c
index 0ff30db..a74bc36 100644
--- a/e-util/e-table-sorter.c
+++ b/e-util/e-table-sorter.c
@@ -39,8 +39,6 @@ enum {
PROP_SORT_INFO
};
-G_DEFINE_TYPE (ETableSorter, e_table_sorter, E_TYPE_SORTER)
-
#define INCREMENT_AMOUNT 100
static void ets_model_changed (ETableModel *etm, ETableSorter *ets);
@@ -53,11 +51,16 @@ static void ets_clean (ETableSorter *ets);
static void ets_sort (ETableSorter *ets);
static void ets_backsort (ETableSorter *ets);
-static gint ets_model_to_sorted (ESorter *sorter, gint row);
-static gint ets_sorted_to_model (ESorter *sorter, gint row);
-static void ets_get_model_to_sorted_array (ESorter *sorter, gint **array, gint *count);
-static void ets_get_sorted_to_model_array (ESorter *sorter, gint **array, gint *count);
-static gboolean ets_needs_sorting (ESorter *ets);
+/* Forward Declarations */
+static void e_table_sorter_interface_init (ESorterInterface *interface);
+
+G_DEFINE_TYPE_WITH_CODE (
+ ETableSorter,
+ e_table_sorter,
+ G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (
+ E_TYPE_SORTER,
+ e_table_sorter_interface_init))
static void
ets_dispose (GObject *object)
@@ -165,22 +168,97 @@ ets_get_property (GObject *object,
}
}
+static gint
+table_sorter_model_to_sorted (ESorter *es,
+ gint row)
+{
+ ETableSorter *ets = E_TABLE_SORTER (es);
+ gint rows = e_table_model_row_count (ets->source);
+
+ g_return_val_if_fail (row >= 0, -1);
+ g_return_val_if_fail (row < rows, -1);
+
+ if (e_sorter_needs_sorting (es))
+ ets_backsort (ets);
+
+ if (ets->backsorted)
+ return ets->backsorted[row];
+ else
+ return row;
+}
+
+static gint
+table_sorter_sorted_to_model (ESorter *es,
+ gint row)
+{
+ ETableSorter *ets = E_TABLE_SORTER (es);
+ gint rows = e_table_model_row_count (ets->source);
+
+ g_return_val_if_fail (row >= 0, -1);
+ g_return_val_if_fail (row < rows, -1);
+
+ if (e_sorter_needs_sorting (es))
+ ets_sort (ets);
+
+ if (ets->sorted)
+ return ets->sorted[row];
+ else
+ return row;
+}
+
+static void
+table_sorter_get_model_to_sorted_array (ESorter *es,
+ gint **array,
+ gint *count)
+{
+ ETableSorter *ets = E_TABLE_SORTER (es);
+ if (array || count) {
+ ets_backsort (ets);
+
+ if (array)
+ *array = ets->backsorted;
+ if (count)
+ *count = e_table_model_row_count(ets->source);
+ }
+}
+
+static void
+table_sorter_get_sorted_to_model_array (ESorter *es,
+ gint **array,
+ gint *count)
+{
+ ETableSorter *ets = E_TABLE_SORTER (es);
+ if (array || count) {
+ ets_sort (ets);
+
+ if (array)
+ *array = ets->sorted;
+ if (count)
+ *count = e_table_model_row_count(ets->source);
+ }
+}
+
+static gboolean
+table_sorter_needs_sorting (ESorter *es)
+{
+ ETableSorter *ets = E_TABLE_SORTER (es);
+ if (ets->needs_sorting < 0) {
+ if (e_table_sort_info_sorting_get_count (ets->sort_info) +
e_table_sort_info_grouping_get_count (ets->sort_info))
+ ets->needs_sorting = 1;
+ else
+ ets->needs_sorting = 0;
+ }
+ return ets->needs_sorting;
+}
static void
e_table_sorter_class_init (ETableSorterClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
- ESorterClass *sorter_class = E_SORTER_CLASS (class);
object_class->dispose = ets_dispose;
object_class->set_property = ets_set_property;
object_class->get_property = ets_get_property;
- sorter_class->model_to_sorted = ets_model_to_sorted;
- sorter_class->sorted_to_model = ets_sorted_to_model;
- sorter_class->get_model_to_sorted_array = ets_get_model_to_sorted_array;
- sorter_class->get_sorted_to_model_array = ets_get_sorted_to_model_array;
- sorter_class->needs_sorting = ets_needs_sorting;
-
g_object_class_install_property (
object_class,
PROP_SORT_INFO,
@@ -193,6 +271,16 @@ e_table_sorter_class_init (ETableSorterClass *class)
}
static void
+e_table_sorter_interface_init (ESorterInterface *interface)
+{
+ interface->model_to_sorted = table_sorter_model_to_sorted;
+ interface->sorted_to_model = table_sorter_sorted_to_model;
+ interface->get_model_to_sorted_array = table_sorter_get_model_to_sorted_array;
+ interface->get_sorted_to_model_array = table_sorter_get_sorted_to_model_array;
+ interface->needs_sorting = table_sorter_needs_sorting;
+}
+
+static void
e_table_sorter_init (ETableSorter *ets)
{
ets->full_header = NULL;
@@ -433,85 +521,3 @@ ets_backsort (ETableSorter *ets)
}
}
-static gint
-ets_model_to_sorted (ESorter *es,
- gint row)
-{
- ETableSorter *ets = E_TABLE_SORTER (es);
- gint rows = e_table_model_row_count (ets->source);
-
- g_return_val_if_fail (row >= 0, -1);
- g_return_val_if_fail (row < rows, -1);
-
- if (ets_needs_sorting (es))
- ets_backsort (ets);
-
- if (ets->backsorted)
- return ets->backsorted[row];
- else
- return row;
-}
-
-static gint
-ets_sorted_to_model (ESorter *es,
- gint row)
-{
- ETableSorter *ets = E_TABLE_SORTER (es);
- gint rows = e_table_model_row_count (ets->source);
-
- g_return_val_if_fail (row >= 0, -1);
- g_return_val_if_fail (row < rows, -1);
-
- if (ets_needs_sorting (es))
- ets_sort (ets);
-
- if (ets->sorted)
- return ets->sorted[row];
- else
- return row;
-}
-
-static void
-ets_get_model_to_sorted_array (ESorter *es,
- gint **array,
- gint *count)
-{
- ETableSorter *ets = E_TABLE_SORTER (es);
- if (array || count) {
- ets_backsort (ets);
-
- if (array)
- *array = ets->backsorted;
- if (count)
- *count = e_table_model_row_count(ets->source);
- }
-}
-
-static void
-ets_get_sorted_to_model_array (ESorter *es,
- gint **array,
- gint *count)
-{
- ETableSorter *ets = E_TABLE_SORTER (es);
- if (array || count) {
- ets_sort (ets);
-
- if (array)
- *array = ets->sorted;
- if (count)
- *count = e_table_model_row_count(ets->source);
- }
-}
-
-static gboolean
-ets_needs_sorting (ESorter *es)
-{
- ETableSorter *ets = E_TABLE_SORTER (es);
- if (ets->needs_sorting < 0) {
- if (e_table_sort_info_sorting_get_count (ets->sort_info) +
e_table_sort_info_grouping_get_count (ets->sort_info))
- ets->needs_sorting = 1;
- else
- ets->needs_sorting = 0;
- }
- return ets->needs_sorting;
-}
diff --git a/e-util/e-table-sorter.h b/e-util/e-table-sorter.h
index 9615a9b..a32116e 100644
--- a/e-util/e-table-sorter.h
+++ b/e-util/e-table-sorter.h
@@ -58,7 +58,7 @@ typedef struct _ETableSorter ETableSorter;
typedef struct _ETableSorterClass ETableSorterClass;
struct _ETableSorter {
- ESorter parent;
+ GObject parent;
ETableModel *source;
ETableHeader *full_header;
@@ -81,7 +81,7 @@ struct _ETableSorter {
};
struct _ETableSorterClass {
- ESorterClass parent_class;
+ GObjectClass parent_class;
};
GType e_table_sorter_get_type (void) G_GNUC_CONST;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]