aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2013-06-27 11:08:18 +0800
committerMatthew Barnes <mbarnes@redhat.com>2013-07-02 22:34:09 +0800
commit21998504a040f3c578a0e0478847cf95c50d6191 (patch)
treea874dcff0aae162a351216a26aab033291df1697
parentcf33c28a0e0fab775856df4c268c40eb4b67fe8b (diff)
downloadgsoc2013-evolution-21998504a040f3c578a0e0478847cf95c50d6191.tar
gsoc2013-evolution-21998504a040f3c578a0e0478847cf95c50d6191.tar.gz
gsoc2013-evolution-21998504a040f3c578a0e0478847cf95c50d6191.tar.bz2
gsoc2013-evolution-21998504a040f3c578a0e0478847cf95c50d6191.tar.lz
gsoc2013-evolution-21998504a040f3c578a0e0478847cf95c50d6191.tar.xz
gsoc2013-evolution-21998504a040f3c578a0e0478847cf95c50d6191.tar.zst
gsoc2013-evolution-21998504a040f3c578a0e0478847cf95c50d6191.zip
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()
-rw-r--r--doc/reference/evolution-util/evolution-util-sections.txt1
-rw-r--r--e-util/e-table-sort-info.c113
-rw-r--r--e-util/e-table-sort-info.h8
-rw-r--r--e-util/e-table-state.c13
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 84a88c5a0f..d061eb07d4 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 526219081b..86ef1f71c0 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 87f43748ee..8e9f6f8f4e 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 d37e7088c3..54416a42ba 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++) {