[evolution] ETableSortInfo: Add a "specification" construct-only property.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution] ETableSortInfo: Add a "specification" construct-only property.
- Date: Tue, 2 Jul 2013 15:26:17 +0000 (UTC)
commit 21998504a040f3c578a0e0478847cf95c50d6191
Author: Matthew Barnes <mbarnes redhat com>
Date: Wed Jun 26 23:08:18 2013 -0400
ETableSortInfo: Add a "specification" construct-only property.
ETableSortInfo now keeps a weak reference on the ETableSpecification to
which it's associated. The plan is to replace the column index numbers
with a direct reference to an ETableColumnSpecification from the spec.
New functions:
e_table_sort_info_ref_specification()
.../evolution-util/evolution-util-sections.txt | 1 +
e-util/e-table-sort-info.c | 113 +++++++++++++++++++-
e-util/e-table-sort-info.h | 8 ++-
e-util/e-table-state.c | 13 ++-
4 files changed, 126 insertions(+), 9 deletions(-)
---
diff --git a/doc/reference/evolution-util/evolution-util-sections.txt
b/doc/reference/evolution-util/evolution-util-sections.txt
index 84a88c5..d061eb0 100644
--- a/doc/reference/evolution-util/evolution-util-sections.txt
+++ b/doc/reference/evolution-util/evolution-util-sections.txt
@@ -3869,6 +3869,7 @@ e_table_sorter_get_type
<TITLE>ETableSortInfo</TITLE>
ETableSortInfo
e_table_sort_info_new
+e_table_sort_info_ref_specification
e_table_sort_info_get_can_group
e_table_sort_info_set_can_group
e_table_sort_info_grouping_get_count
diff --git a/e-util/e-table-sort-info.c b/e-util/e-table-sort-info.c
index 5262190..86ef1f7 100644
--- a/e-util/e-table-sort-info.c
+++ b/e-util/e-table-sort-info.c
@@ -20,6 +20,7 @@
#include <string.h>
+#include "e-table-specification.h"
#include "e-xml-utils.h"
#define E_TABLE_SORT_INFO_GET_PRIVATE(obj) \
@@ -27,7 +28,12 @@
((obj), E_TYPE_TABLE_SORT_INFO, ETableSortInfoPrivate))
struct _ETableSortInfoPrivate {
- gint placeholder;
+ GWeakRef specification;
+};
+
+enum {
+ PROP_0,
+ PROP_SPECIFICATION
};
enum {
@@ -41,6 +47,63 @@ static guint signals[LAST_SIGNAL];
G_DEFINE_TYPE (ETableSortInfo , e_table_sort_info, G_TYPE_OBJECT)
static void
+table_sort_info_set_specification (ETableSortInfo *sort_info,
+ ETableSpecification *specification)
+{
+ g_return_if_fail (E_IS_TABLE_SPECIFICATION (specification));
+
+ g_weak_ref_set (&sort_info->priv->specification, specification);
+}
+
+static void
+table_sort_info_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ switch (property_id) {
+ case PROP_SPECIFICATION:
+ table_sort_info_set_specification (
+ E_TABLE_SORT_INFO (object),
+ g_value_get_object (value));
+ return;
+ }
+
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+table_sort_info_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ switch (property_id) {
+ case PROP_SPECIFICATION:
+ g_value_take_object (
+ value,
+ e_table_sort_info_ref_specification (
+ E_TABLE_SORT_INFO (object)));
+ return;
+ }
+
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+table_sort_info_dispose (GObject *object)
+{
+ ETableSortInfoPrivate *priv;
+
+ priv = E_TABLE_SORT_INFO_GET_PRIVATE (object);
+
+ g_weak_ref_set (&priv->specification, NULL);
+
+ /* Chain up to parent's dispose() method. */
+ G_OBJECT_CLASS (e_table_sort_info_parent_class)->dispose (object);
+}
+
+static void
table_sort_info_finalize (GObject *object)
{
ETableSortInfo *sort_info = E_TABLE_SORT_INFO (object);
@@ -60,8 +123,23 @@ e_table_sort_info_class_init (ETableSortInfoClass *class)
g_type_class_add_private (class, sizeof (ETableSortInfoPrivate));
object_class = G_OBJECT_CLASS (class);
+ object_class->set_property = table_sort_info_set_property;
+ object_class->get_property = table_sort_info_get_property;
+ object_class->dispose = table_sort_info_dispose;
object_class->finalize = table_sort_info_finalize;
+ g_object_class_install_property (
+ object_class,
+ PROP_SPECIFICATION,
+ g_param_spec_object (
+ "specification",
+ "Table Specification",
+ "Specification for the table state",
+ E_TYPE_TABLE_SPECIFICATION,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+
signals[SORT_INFO_CHANGED] = g_signal_new (
"sort_info_changed",
G_TYPE_FROM_CLASS (object_class),
@@ -91,6 +169,7 @@ e_table_sort_info_init (ETableSortInfo *sort_info)
/**
* e_table_sort_info_new:
+ * @specification: an #ETableSpecification
*
* This creates a new #ETableSortInfo object that contains no
* grouping and no sorting defined as of yet. This object is used
@@ -100,9 +179,32 @@ e_table_sort_info_init (ETableSortInfo *sort_info)
* Returns: A new #ETableSortInfo object
*/
ETableSortInfo *
-e_table_sort_info_new (void)
+e_table_sort_info_new (ETableSpecification *specification)
{
- return g_object_new (E_TYPE_TABLE_SORT_INFO, NULL);
+ g_return_val_if_fail (E_IS_TABLE_SPECIFICATION (specification), NULL);
+
+ return g_object_new (
+ E_TYPE_TABLE_SORT_INFO,
+ "specification", specification, NULL);
+}
+
+/**
+ * e_table_sort_info_ref_specification:
+ * @sort_info: an #ETableSortInfo
+ *
+ * Returns the #ETableSpecification passed to e_table_sort_info_new().
+ *
+ * The returned #ETableSpecification is referenced for thread-safety and must
+ * be unreferenced with g_object_unref() when finished with it.
+ *
+ * Returns: an #ETableSpecification
+ **/
+ETableSpecification *
+e_table_sort_info_ref_specification (ETableSortInfo *sort_info)
+{
+ g_return_val_if_fail (E_IS_TABLE_SORT_INFO (sort_info), NULL);
+
+ return g_weak_ref_get (&sort_info->priv->specification);
}
gboolean
@@ -420,11 +522,14 @@ e_table_sort_info_save_to_node (ETableSortInfo *sort_info,
ETableSortInfo *
e_table_sort_info_duplicate (ETableSortInfo *sort_info)
{
+ ETableSpecification *specification;
ETableSortInfo *new_info;
g_return_val_if_fail (E_IS_TABLE_SORT_INFO (sort_info), NULL);
- new_info = e_table_sort_info_new ();
+ specification = e_table_sort_info_ref_specification (sort_info);
+ new_info = e_table_sort_info_new (specification);
+ g_object_unref (specification);
new_info->group_count = sort_info->group_count;
new_info->groupings = g_new (ETableSortColumn, new_info->group_count);
diff --git a/e-util/e-table-sort-info.h b/e-util/e-table-sort-info.h
index 87f4374..8e9f6f8 100644
--- a/e-util/e-table-sort-info.h
+++ b/e-util/e-table-sort-info.h
@@ -47,6 +47,9 @@
G_BEGIN_DECLS
+/* Avoid a circular dependency. */
+struct _ETableSpecification;
+
typedef struct _ETableSortColumn ETableSortColumn;
typedef struct _ETableSortInfo ETableSortInfo;
@@ -82,7 +85,10 @@ struct _ETableSortInfoClass {
};
GType e_table_sort_info_get_type (void) G_GNUC_CONST;
-ETableSortInfo *e_table_sort_info_new (void);
+ETableSortInfo *e_table_sort_info_new (struct _ETableSpecification *specification);
+struct _ETableSpecification *
+ e_table_sort_info_ref_specification
+ (ETableSortInfo *sort_info);
gboolean e_table_sort_info_get_can_group (ETableSortInfo *sort_info);
void e_table_sort_info_set_can_group (ETableSortInfo *sort_info,
gboolean can_group);
diff --git a/e-util/e-table-state.c b/e-util/e-table-state.c
index d37e708..54416a4 100644
--- a/e-util/e-table-state.c
+++ b/e-util/e-table-state.c
@@ -123,9 +123,13 @@ static void
table_state_constructed (GObject *object)
{
ETableState *state;
+ ETableSpecification *specification;
state = E_TABLE_STATE (object);
- state->sort_info = e_table_sort_info_new ();
+
+ specification = e_table_state_ref_specification (state);
+ state->sort_info = e_table_sort_info_new (specification);
+ g_object_unref (specification);
/* Chain up to parent's constructed() method. */
G_OBJECT_CLASS (e_table_state_parent_class)->constructed (object);
@@ -305,7 +309,8 @@ e_table_state_load_from_node (ETableState *state,
list = g_list_append (list, column_info);
} else if (state->sort_info == NULL &&
!strcmp ((gchar *) children->name, "grouping")) {
- state->sort_info = e_table_sort_info_new ();
+ state->sort_info =
+ e_table_sort_info_new (specification);
e_table_sort_info_load_from_node (
state->sort_info, children, state_version);
}
@@ -321,8 +326,8 @@ e_table_state_load_from_node (ETableState *state,
ETableColumnSpecification *, state->col_count);
state->expansions = g_new (double, state->col_count);
- if (!state->sort_info)
- state->sort_info = e_table_sort_info_new ();
+ if (state->sort_info == NULL)
+ state->sort_info = e_table_sort_info_new (specification);
e_table_sort_info_set_can_group (state->sort_info, can_group);
for (iterator = list, i = 0; iterator; i++) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]