evolution-3.6.4/widgets/table/e-table-column-specification.c

No issues found

  1 /*
  2  * e-table-column-specification.c - Savable specification of a column.
  3  *
  4  * This program is free software; you can redistribute it and/or
  5  * modify it under the terms of the GNU Lesser General Public
  6  * License as published by the Free Software Foundation; either
  7  * version 2 of the License, or (at your option) version 3.
  8  *
  9  * This program is distributed in the hope that it will be useful,
 10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 12  * Lesser General Public License for more details.
 13  *
 14  * You should have received a copy of the GNU Lesser General Public
 15  * License along with the program; if not, see <http://www.gnu.org/licenses/>
 16  *
 17  *
 18  * Authors:
 19  *		Chris Lahey <clahey@ximian.com>
 20  *
 21  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 22  *
 23  */
 24 
 25 #ifdef HAVE_CONFIG_H
 26 #include <config.h>
 27 #endif
 28 
 29 #include <stdlib.h>
 30 
 31 #include <libxml/parser.h>
 32 #include <libxml/xmlmemory.h>
 33 
 34 #include "e-util/e-util.h"
 35 #include "libevolution-utils/e-xml-utils.h"
 36 
 37 #include "e-table-column-specification.h"
 38 
 39 /* workaround for avoiding API breakage */
 40 #define etcs_get_type e_table_column_specification_get_type
 41 G_DEFINE_TYPE (ETableColumnSpecification, etcs, G_TYPE_OBJECT)
 42 
 43 static void
 44 free_strings (ETableColumnSpecification *etcs)
 45 {
 46 	g_free (etcs->title);
 47 	etcs->title = NULL;
 48 	g_free (etcs->pixbuf);
 49 	etcs->pixbuf = NULL;
 50 	g_free (etcs->cell);
 51 	etcs->cell = NULL;
 52 	g_free (etcs->compare);
 53 	etcs->compare = NULL;
 54 	g_free (etcs->search);
 55 	etcs->search = NULL;
 56 	g_free (etcs->sortable);
 57 	etcs->sortable = NULL;
 58 }
 59 
 60 static void
 61 etcs_finalize (GObject *object)
 62 {
 63 	ETableColumnSpecification *etcs = E_TABLE_COLUMN_SPECIFICATION (object);
 64 
 65 	free_strings (etcs);
 66 
 67 	G_OBJECT_CLASS (etcs_parent_class)->finalize (object);
 68 }
 69 
 70 static void
 71 etcs_class_init (ETableColumnSpecificationClass *class)
 72 {
 73 	GObjectClass *object_class = G_OBJECT_CLASS (class);
 74 
 75 	object_class->finalize = etcs_finalize;
 76 }
 77 
 78 static void
 79 etcs_init (ETableColumnSpecification *specification)
 80 {
 81 	specification->model_col     = 0;
 82 	specification->compare_col   = 0;
 83 	specification->title         = g_strdup ("");
 84 	specification->pixbuf        = NULL;
 85 
 86 	specification->expansion     = 0;
 87 	specification->minimum_width = 0;
 88 	specification->resizable     = FALSE;
 89 	specification->disabled      = FALSE;
 90 
 91 	specification->cell          = NULL;
 92 	specification->compare       = NULL;
 93 	specification->search        = NULL;
 94 	specification->priority      = 0;
 95 }
 96 
 97 ETableColumnSpecification *
 98 e_table_column_specification_new (void)
 99 {
100 	return g_object_new (E_TYPE_TABLE_COLUMN_SPECIFICATION, NULL);
101 }
102 
103 void
104 e_table_column_specification_load_from_node (ETableColumnSpecification *etcs,
105                                              const xmlNode *node)
106 {
107 	free_strings (etcs);
108 
109 	etcs->model_col     = e_xml_get_integer_prop_by_name (node, (const guchar *)"model_col");
110 	etcs->compare_col   = e_xml_get_integer_prop_by_name_with_default (node, (const guchar *)"compare_col", etcs->model_col);
111 	etcs->title         = e_xml_get_string_prop_by_name (node, (const guchar *)"_title");
112 	etcs->pixbuf        = e_xml_get_string_prop_by_name (node, (const guchar *)"pixbuf");
113 
114 	etcs->expansion     = e_xml_get_double_prop_by_name (node, (const guchar *)"expansion");
115 	etcs->minimum_width = e_xml_get_integer_prop_by_name (node, (const guchar *)"minimum_width");
116 	etcs->resizable     = e_xml_get_bool_prop_by_name (node, (const guchar *)"resizable");
117 	etcs->disabled      = e_xml_get_bool_prop_by_name (node, (const guchar *)"disabled");
118 
119 	etcs->cell          = e_xml_get_string_prop_by_name (node, (const guchar *)"cell");
120 	etcs->compare       = e_xml_get_string_prop_by_name (node, (const guchar *)"compare");
121 	etcs->search        = e_xml_get_string_prop_by_name (node, (const guchar *)"search");
122 	etcs->sortable	    = e_xml_get_string_prop_by_name (node, (const guchar *)"sortable");
123 	etcs->priority      = e_xml_get_integer_prop_by_name_with_default (node, (const guchar *)"priority", 0);
124 
125 	if (etcs->title == NULL)
126 		etcs->title = g_strdup ("");
127 }
128 
129 xmlNode *
130 e_table_column_specification_save_to_node (ETableColumnSpecification *specification,
131                                            xmlNode *parent)
132 {
133 	xmlNode *node;
134 	if (parent)
135 		node = xmlNewChild (parent, NULL, (const guchar *)"ETableColumn", NULL);
136 	else
137 		node = xmlNewNode (NULL, (const guchar *)"ETableColumn");
138 
139 	e_xml_set_integer_prop_by_name (node, (const guchar *)"model_col", specification->model_col);
140 	if (specification->compare_col != specification->model_col)
141 		e_xml_set_integer_prop_by_name (node, (const guchar *)"compare_col", specification->compare_col);
142 	e_xml_set_string_prop_by_name (node, (const guchar *)"_title", specification->title);
143 	e_xml_set_string_prop_by_name (node, (const guchar *)"pixbuf", specification->pixbuf);
144 
145 	e_xml_set_double_prop_by_name (node, (const guchar *)"expansion", specification->expansion);
146 	e_xml_set_integer_prop_by_name (node, (const guchar *)"minimum_width", specification->minimum_width);
147 	e_xml_set_bool_prop_by_name (node, (const guchar *)"resizable", specification->resizable);
148 	e_xml_set_bool_prop_by_name (node, (const guchar *)"disabled", specification->disabled);
149 
150 	e_xml_set_string_prop_by_name (node, (const guchar *)"cell", specification->cell);
151 	e_xml_set_string_prop_by_name (node, (const guchar *)"compare", specification->compare);
152 	e_xml_set_string_prop_by_name (node, (const guchar *)"search", specification->search);
153 	if (specification->priority != 0)
154 		e_xml_set_integer_prop_by_name (node, (const guchar *)"priority", specification->priority);
155 
156 	return node;
157 }