1 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * Copyright (C) 2007-2010 Kouhei Sutou <kou@clear-code.com>
4 *
5 * This library is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 */
19
20 #ifdef HAVE_CONFIG_H
21 # include <config.h>
22 #endif /* HAVE_CONFIG_H */
23
24 #include <stdlib.h>
25 #include <string.h>
26 #include <glib.h>
27 #include <glib/gi18n-lib.h>
28 #include <gmodule.h>
29
30 #include <cutter/cut-module-impl.h>
31 #include <cutter/cut-report.h>
32 #include <cutter/cut-module-factory.h>
33 #include <cutter/cut-enum-types.h>
34
35 #define CUT_TYPE_XML_REPORT_FACTORY cut_type_xml_report_factory
36 #define CUT_XML_REPORT_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CUT_TYPE_XML_REPORT_FACTORY, CutXMLReportFactory))
37 #define CUT_XML_REPORT_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CUT_TYPE_XML_REPORT_FACTORY, CutXMLReportFactoryClass))
38 #define CUT_IS_XML_REPORT_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CUT_TYPE_XML_REPORT_FACTORY))
39 #define CUT_IS_XML_REPORT_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CUT_TYPE_XML_REPORT_FACTORY))
40 #define CUT_XML_REPORT_FACTORY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), CUT_TYPE_XML_REPORT_FACTORY, CutXMLReportFactoryClass))
41
42 typedef struct _CutXMLReportFactory CutXMLReportFactory;
43 typedef struct _CutXMLReportFactoryClass CutXMLReportFactoryClass;
44
45 struct _CutXMLReportFactory
46 {
47 CutModuleFactory object;
48 gchar *filename;
49 };
50
51 struct _CutXMLReportFactoryClass
52 {
53 CutModuleFactoryClass parent_class;
54 };
55
56 enum
57 {
58 PROP_0,
59 PROP_FILENAME
60 };
61
62 static GType cut_type_xml_report_factory = 0;
63 static CutModuleFactoryClass *parent_class;
64
65 static void dispose (GObject *object);
66 static void set_property (GObject *object,
67 guint prop_id,
68 const GValue *value,
69 GParamSpec *pspec);
70 static void get_property (GObject *object,
71 guint prop_id,
72 GValue *value,
73 GParamSpec *pspec);
74 static void set_option_group (CutModuleFactory *factory,
75 GOptionContext *context);
76 static GObject *create (CutModuleFactory *factory);
77
78 static void
class_init(CutModuleFactoryClass * klass)79 class_init (CutModuleFactoryClass *klass)
80 {
81 CutModuleFactoryClass *factory_class;
82 GObjectClass *gobject_class;
83 GParamSpec *spec;
84
85 parent_class = g_type_class_peek_parent(klass);
86 gobject_class = G_OBJECT_CLASS(klass);
87 factory_class = CUT_MODULE_FACTORY_CLASS(klass);
88
89 gobject_class->dispose = dispose;
90 gobject_class->set_property = set_property;
91 gobject_class->get_property = get_property;
92
93 factory_class->set_option_group = set_option_group;
94 factory_class->create = create;
95
96 spec = g_param_spec_string("filename",
97 "Filename",
98 "The name of output file",
99 NULL,
100 G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
101 g_object_class_install_property(gobject_class, PROP_FILENAME, spec);
102 }
103
104 static void
init(CutXMLReportFactory * xml)105 init (CutXMLReportFactory *xml)
106 {
107 xml->filename = NULL;
108 }
109
110 static void
dispose(GObject * object)111 dispose (GObject *object)
112 {
113 CutXMLReportFactory *xml = CUT_XML_REPORT_FACTORY(object);
114
115 if (xml->filename) {
116 g_free(xml->filename);
117 xml->filename = NULL;
118 }
119
120 G_OBJECT_CLASS(parent_class)->dispose(object);
121 }
122
123 static void
set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)124 set_property (GObject *object,
125 guint prop_id,
126 const GValue *value,
127 GParamSpec *pspec)
128 {
129 CutXMLReportFactory *xml = CUT_XML_REPORT_FACTORY(object);
130
131 switch (prop_id) {
132 case PROP_FILENAME:
133 if (xml->filename)
134 g_free(xml->filename);
135 xml->filename = g_value_dup_string(value);
136 break;
137 default:
138 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
139 break;
140 }
141 }
142
143 static void
get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)144 get_property (GObject *object,
145 guint prop_id,
146 GValue *value,
147 GParamSpec *pspec)
148 {
149 CutXMLReportFactory *xml = CUT_XML_REPORT_FACTORY(object);
150
151 switch (prop_id) {
152 case PROP_FILENAME:
153 g_value_set_string(value, xml->filename);
154 break;
155 default:
156 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
157 break;
158 }
159 }
160
161 static void
register_type(GTypeModule * type_module)162 register_type (GTypeModule *type_module)
163 {
164 static const GTypeInfo info =
165 {
166 sizeof (CutXMLReportFactoryClass),
167 (GBaseInitFunc) NULL,
168 (GBaseFinalizeFunc) NULL,
169 (GClassInitFunc) class_init,
170 NULL, /* class_finalize */
171 NULL, /* class_data */
172 sizeof(CutXMLReportFactory),
173 0,
174 (GInstanceInitFunc) init,
175 };
176
177 cut_type_xml_report_factory =
178 g_type_module_register_type(type_module,
179 CUT_TYPE_MODULE_FACTORY,
180 "CutXMLReportFactory",
181 &info, 0);
182 }
183
184 G_MODULE_EXPORT GList *
CUT_MODULE_IMPL_INIT(GTypeModule * type_module)185 CUT_MODULE_IMPL_INIT (GTypeModule *type_module)
186 {
187 GList *registered_types = NULL;
188
189 register_type(type_module);
190 if (cut_type_xml_report_factory)
191 registered_types =
192 g_list_prepend(registered_types,
193 (gchar *)g_type_name(cut_type_xml_report_factory));
194
195 return registered_types;
196 }
197
198 G_MODULE_EXPORT void
CUT_MODULE_IMPL_EXIT(void)199 CUT_MODULE_IMPL_EXIT (void)
200 {
201 }
202
203 G_MODULE_EXPORT GObject *
CUT_MODULE_IMPL_INSTANTIATE(const gchar * first_property,va_list var_args)204 CUT_MODULE_IMPL_INSTANTIATE (const gchar *first_property, va_list var_args)
205 {
206 return g_object_new_valist(CUT_TYPE_XML_REPORT_FACTORY, first_property, var_args);
207 }
208
209 static void
set_option_group(CutModuleFactory * factory,GOptionContext * context)210 set_option_group (CutModuleFactory *factory, GOptionContext *context)
211 {
212 CutXMLReportFactory *xml = CUT_XML_REPORT_FACTORY(factory);
213 GOptionGroup *group;
214 GOptionEntry entries[] = {
215 {NULL}
216 };
217
218 if (CUT_MODULE_FACTORY_CLASS(parent_class)->set_option_group)
219 CUT_MODULE_FACTORY_CLASS(parent_class)->set_option_group(factory, context);
220
221 group = g_option_group_new(("xml-report"),
222 _("XML Report Options"),
223 _("Show XML report options"),
224 xml, NULL);
225 g_option_group_add_entries(group, entries);
226 g_option_group_set_translation_domain(group, GETTEXT_PACKAGE);
227 g_option_context_add_group(context, group);
228 }
229
230 static GObject *
create(CutModuleFactory * factory)231 create (CutModuleFactory *factory)
232 {
233 CutXMLReportFactory *xml = CUT_XML_REPORT_FACTORY(factory);
234
235 return G_OBJECT(cut_report_new("xml",
236 "filename", xml->filename,
237 NULL));
238 }
239
240 /*
241 vi:ts=4:nowrap:ai:expandtab:sw=4
242 */
243