aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2013-06-26 21:54:34 +0800
committerMatthew Barnes <mbarnes@redhat.com>2013-06-26 23:36:12 +0800
commit81a8e910972ab7963c2131cd6bcb0c47e776fd0f (patch)
tree4be9a91a70cc7d74d9eec1df2a20ff340fbd64f2
parentaec739f87470d98a3b653709ea91ba0f3061c8f1 (diff)
downloadgsoc2013-evolution-81a8e910972ab7963c2131cd6bcb0c47e776fd0f.tar
gsoc2013-evolution-81a8e910972ab7963c2131cd6bcb0c47e776fd0f.tar.gz
gsoc2013-evolution-81a8e910972ab7963c2131cd6bcb0c47e776fd0f.tar.bz2
gsoc2013-evolution-81a8e910972ab7963c2131cd6bcb0c47e776fd0f.tar.lz
gsoc2013-evolution-81a8e910972ab7963c2131cd6bcb0c47e776fd0f.tar.xz
gsoc2013-evolution-81a8e910972ab7963c2131cd6bcb0c47e776fd0f.tar.zst
gsoc2013-evolution-81a8e910972ab7963c2131cd6bcb0c47e776fd0f.zip
ETableState cleanups.
-rw-r--r--e-util/e-table-state.c79
-rw-r--r--e-util/e-table-state.h14
2 files changed, 40 insertions, 53 deletions
diff --git a/e-util/e-table-state.c b/e-util/e-table-state.c
index e5253be7c9..20137f65a9 100644
--- a/e-util/e-table-state.c
+++ b/e-util/e-table-state.c
@@ -1,4 +1,6 @@
/*
+ * e-table-state.c
+ *
* 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,18 +14,8 @@
* 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-table-state.h"
#include <stdlib.h>
@@ -41,33 +33,25 @@
G_DEFINE_TYPE (ETableState, e_table_state, G_TYPE_OBJECT)
static void
-etst_dispose (GObject *object)
+table_state_dispose (GObject *object)
{
- ETableState *etst = E_TABLE_STATE (object);
+ ETableState *state = E_TABLE_STATE (object);
- if (etst->sort_info) {
- g_object_unref (etst->sort_info);
- etst->sort_info = NULL;
- }
+ g_clear_object (&state->sort_info);
+ /* Chain up to parent's dispose() method. */
G_OBJECT_CLASS (e_table_state_parent_class)->dispose (object);
}
static void
-etst_finalize (GObject *object)
+table_state_finalize (GObject *object)
{
- ETableState *etst = E_TABLE_STATE (object);
+ ETableState *state = E_TABLE_STATE (object);
- if (etst->columns) {
- g_free (etst->columns);
- etst->columns = NULL;
- }
-
- if (etst->expansions) {
- g_free (etst->expansions);
- etst->expansions = NULL;
- }
+ g_free (state->columns);
+ g_free (state->expansions);
+ /* Chain up to parent's finalize() method. */
G_OBJECT_CLASS (e_table_state_parent_class)->finalize (object);
}
@@ -76,15 +60,13 @@ e_table_state_class_init (ETableStateClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
- object_class->dispose = etst_dispose;
- object_class->finalize = etst_finalize;
+ object_class->dispose = table_state_dispose;
+ object_class->finalize = table_state_finalize;
}
static void
e_table_state_init (ETableState *state)
{
- state->columns = NULL;
- state->expansions = NULL;
state->sort_info = e_table_sort_info_new ();
}
@@ -119,18 +101,20 @@ e_table_state_load_from_file (ETableState *state,
const gchar *filename)
{
xmlDoc *doc;
+ gboolean success = FALSE;
g_return_val_if_fail (E_IS_TABLE_STATE (state), FALSE);
g_return_val_if_fail (filename != NULL, FALSE);
doc = e_xml_parse_file (filename);
- if (doc) {
+ if (doc != NULL) {
xmlNode *node = xmlDocGetRootElement (doc);
e_table_state_load_from_node (state, node);
xmlFreeDoc (doc);
- return TRUE;
+ success = TRUE;
}
- return FALSE;
+
+ return success;
}
void
@@ -143,7 +127,7 @@ e_table_state_load_from_string (ETableState *state,
g_return_if_fail (xml != NULL);
doc = xmlParseMemory ((gchar *) xml, strlen (xml));
- if (doc) {
+ if (doc != NULL) {
xmlNode *node = xmlDocGetRootElement (doc);
e_table_state_load_from_node (state, node);
xmlFreeDoc (doc);
@@ -222,11 +206,12 @@ e_table_state_save_to_file (ETableState *state,
const gchar *filename)
{
xmlDoc *doc;
+ xmlNode *node;
- if ((doc = xmlNewDoc ((const guchar *)"1.0")) == NULL)
- return;
+ doc = xmlNewDoc ((const guchar *)"1.0");
- xmlDocSetRootElement (doc, e_table_state_save_to_node (state, NULL));
+ node = e_table_state_save_to_node (state, NULL);
+ xmlDocSetRootElement (doc, node);
e_xml_save_file (filename, doc);
@@ -240,16 +225,21 @@ e_table_state_save_to_string (ETableState *state)
xmlChar *string;
gint length;
xmlDoc *doc;
+ xmlNode *node;
g_return_val_if_fail (E_IS_TABLE_STATE (state), NULL);
doc = xmlNewDoc ((const guchar *)"1.0");
- xmlDocSetRootElement (doc, e_table_state_save_to_node (state, NULL));
- xmlDocDumpMemory (doc, &string, &length);
- xmlFreeDoc (doc);
+ node = e_table_state_save_to_node (state, NULL);
+ xmlDocSetRootElement (doc, node);
+
+ xmlDocDumpMemory (doc, &string, &length);
ret_val = g_strdup ((gchar *) string);
xmlFree (string);
+
+ xmlFreeDoc (doc);
+
return ret_val;
}
@@ -293,11 +283,11 @@ e_table_state_save_to_node (ETableState *state,
/**
* e_table_state_duplicate:
- * @state: The ETableState to duplicate
+ * @state: an #ETableState
*
- * This creates a copy of the %ETableState @state
+ * Creates a new #ETableState cloned from @state.
*
- * Returns: The duplicated %ETableState.
+ * Returns: a new #ETableState
*/
ETableState *
e_table_state_duplicate (ETableState *state)
@@ -308,6 +298,7 @@ e_table_state_duplicate (ETableState *state)
g_return_val_if_fail (E_IS_TABLE_STATE (state), NULL);
new_state = e_table_state_new ();
+
copy = e_table_state_save_to_string (state);
e_table_state_load_from_string (new_state, copy);
g_free (copy);
diff --git a/e-util/e-table-state.h b/e-util/e-table-state.h
index ac3cfc2879..2129e2a65c 100644
--- a/e-util/e-table-state.h
+++ b/e-util/e-table-state.h
@@ -1,4 +1,6 @@
/*
+ * e-table-state.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,20 +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)
- *
*/
#if !defined (__E_UTIL_H_INSIDE__) && !defined (LIBEUTIL_COMPILATION)
#error "Only <e-util/e-util.h> should be included directly."
#endif
-#ifndef _E_TABLE_STATE_H_
-#define _E_TABLE_STATE_H_
+#ifndef E_TABLE_STATE_H
+#define E_TABLE_STATE_H
#include <libxml/tree.h>
@@ -86,4 +82,4 @@ ETableState * e_table_state_duplicate (ETableState *state);
G_END_DECLS
-#endif /* _E_TABLE_STATE_H_ */
+#endif /* E_TABLE_STATE_H */