No issues found
1 /*
2 *
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2 of the License, or (at your option) version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with the program; if not, see <http://www.gnu.org/licenses/>
15 *
16 *
17 * Authors:
18 * Chris Lahey <clahey@ximian.com>
19 *
20 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
21 *
22 */
23
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27
28 #include <glib/gi18n.h>
29 #include "e-util/e-util.h"
30
31 #include "gal-view-etable.h"
32 #include "gal-view-factory-etable.h"
33
34 #define GAL_VIEW_FACTORY_ETABLE_GET_PRIVATE(obj) \
35 (G_TYPE_INSTANCE_GET_PRIVATE \
36 ((obj), GAL_TYPE_VIEW_FACTORY_ETABLE, GalViewFactoryEtablePrivate))
37
38 struct _GalViewFactoryEtablePrivate {
39 ETableSpecification *specification;
40 };
41
42 enum {
43 PROP_0,
44 PROP_SPECIFICATION
45 };
46
47 G_DEFINE_TYPE (
48 GalViewFactoryEtable,
49 gal_view_factory_etable, GAL_TYPE_VIEW_FACTORY)
50
51 static void
52 view_factory_etable_set_specification (GalViewFactoryEtable *factory,
53 ETableSpecification *specification)
54 {
55 g_return_if_fail (factory->priv->specification == NULL);
56 g_return_if_fail (E_IS_TABLE_SPECIFICATION (specification));
57
58 factory->priv->specification = g_object_ref (specification);
59 }
60
61 static void
62 view_factory_etable_set_property (GObject *object,
63 guint property_id,
64 const GValue *value,
65 GParamSpec *pspec)
66 {
67 switch (property_id) {
68 case PROP_SPECIFICATION:
69 view_factory_etable_set_specification (
70 GAL_VIEW_FACTORY_ETABLE (object),
71 g_value_get_object (value));
72 return;
73 }
74
75 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
76 }
77
78 static void
79 view_factory_etable_get_property (GObject *object,
80 guint property_id,
81 GValue *value,
82 GParamSpec *pspec)
83 {
84 switch (property_id) {
85 case PROP_SPECIFICATION:
86 g_value_set_object (
87 value,
88 gal_view_factory_etable_get_specification (
89 GAL_VIEW_FACTORY_ETABLE (object)));
90 return;
91 }
92
93 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
94 }
95
96 static void
97 view_factory_etable_dispose (GObject *object)
98 {
99 GalViewFactoryEtablePrivate *priv;
100
101 priv = GAL_VIEW_FACTORY_ETABLE_GET_PRIVATE (object);
102
103 if (priv->specification != NULL) {
104 g_object_unref (priv->specification);
105 priv->specification = NULL;
106 }
107
108 /* Chain up to parent's dispose() method. */
109 G_OBJECT_CLASS (gal_view_factory_etable_parent_class)->dispose (object);
110 }
111
112 static const gchar *
113 view_factory_etable_get_title (GalViewFactory *factory)
114 {
115 return _("Table");
116 }
117
118 static const gchar *
119 view_factory_etable_get_type_code (GalViewFactory *factory)
120 {
121 return "etable";
122 }
123
124 static GalView *
125 view_factory_etable_new_view (GalViewFactory *factory,
126 const gchar *name)
127 {
128 GalViewFactoryEtablePrivate *priv;
129
130 priv = GAL_VIEW_FACTORY_ETABLE_GET_PRIVATE (factory);
131
132 return gal_view_etable_new (priv->specification, name);
133 }
134
135 static void
136 gal_view_factory_etable_class_init (GalViewFactoryEtableClass *class)
137 {
138 GObjectClass *object_class;
139 GalViewFactoryClass *view_factory_class;
140
141 g_type_class_add_private (class, sizeof (GalViewFactoryEtablePrivate));
142
143 object_class = G_OBJECT_CLASS (class);
144 object_class->set_property = view_factory_etable_set_property;
145 object_class->get_property = view_factory_etable_get_property;
146 object_class->dispose = view_factory_etable_dispose;
147
148 view_factory_class = GAL_VIEW_FACTORY_CLASS (class);
149 view_factory_class->get_title = view_factory_etable_get_title;
150 view_factory_class->get_type_code = view_factory_etable_get_type_code;
151 view_factory_class->new_view = view_factory_etable_new_view;
152
153 g_object_class_install_property (
154 object_class,
155 PROP_SPECIFICATION,
156 g_param_spec_object (
157 "specification",
158 NULL,
159 NULL,
160 E_TYPE_TABLE_SPECIFICATION,
161 G_PARAM_READWRITE |
162 G_PARAM_CONSTRUCT_ONLY));
163 }
164
165 static void
166 gal_view_factory_etable_init (GalViewFactoryEtable *factory)
167 {
168 factory->priv = GAL_VIEW_FACTORY_ETABLE_GET_PRIVATE (factory);
169 }
170
171 /**
172 * gal_view_etable_new:
173 * @specification: The spec to create GalViewEtables based upon.
174 *
175 * A new GalViewFactory for creating ETable views. Create one of
176 * these and pass it to GalViewCollection for use.
177 *
178 * Returns: The new GalViewFactoryEtable.
179 */
180 GalViewFactory *
181 gal_view_factory_etable_new (ETableSpecification *specification)
182 {
183 g_return_val_if_fail (E_IS_TABLE_SPECIFICATION (specification), NULL);
184
185 return g_object_new (
186 GAL_TYPE_VIEW_FACTORY_ETABLE,
187 "specification", specification, NULL);
188 }
189
190 ETableSpecification *
191 gal_view_factory_etable_get_specification (GalViewFactoryEtable *factory)
192 {
193 g_return_val_if_fail (GAL_IS_VIEW_FACTORY_ETABLE (factory), NULL);
194
195 return factory->priv->specification;
196 }