1 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  *  Copyright (C) 2007  Kouhei Sutou <kou@cozmixng.org>
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 #include <gtk/gtk.h>
30 
31 #include <cutter/cut-module-impl.h>
32 #include <cutter/cut-ui.h>
33 #include <cutter/cut-module-factory.h>
34 #include <cutter/cut-enum-types.h>
35 
36 #define CUT_TYPE_GTK_UI_FACTORY            cut_type_gtk_ui_factory
37 #define CUT_GTK_UI_FACTORY(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), CUT_TYPE_GTK_UI_FACTORY, CutGtkUIFactory))
38 #define CUT_GTK_UI_FACTORY_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), CUT_TYPE_GTK_UI_FACTORY, CutGtkUIFactoryClass))
39 #define CUT_IS_GTK_UI_FACTORY(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CUT_TYPE_GTK_UI_FACTORY))
40 #define CUT_IS_GTK_UI_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CUT_TYPE_GTK_UI_FACTORY))
41 #define CUT_GTK_UI_FACTORY_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj), CUT_TYPE_GTK_UI_FACTORY, CutGtkUIFactoryClass))
42 
43 typedef struct _CutGtkUIFactory CutGtkUIFactory;
44 typedef struct _CutGtkUIFactoryClass CutGtkUIFactoryClass;
45 
46 struct _CutGtkUIFactory
47 {
48     CutModuleFactory     object;
49 };
50 
51 struct _CutGtkUIFactoryClass
52 {
53     CutModuleFactoryClass parent_class;
54 };
55 
56 enum
57 {
58     PROP_0
59 };
60 
61 static GType cut_type_gtk_ui_factory = 0;
62 static CutModuleFactoryClass *parent_class;
63 
64 static void dispose        (GObject         *object);
65 static void set_property   (GObject         *object,
66                             guint            prop_id,
67                             const GValue    *value,
68                             GParamSpec      *pspec);
69 static void get_property   (GObject         *object,
70                             guint            prop_id,
71                             GValue          *value,
72                             GParamSpec      *pspec);
73 
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     GObjectClass *gobject_class;
82     CutModuleFactoryClass *factory_class;
83 
84     parent_class = g_type_class_peek_parent(klass);
85 
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 
97 static void
init(CutGtkUIFactory * gtk)98 init (CutGtkUIFactory *gtk)
99 {
100 }
101 
102 static void
register_type(GTypeModule * type_module)103 register_type (GTypeModule *type_module)
104 {
105     static const GTypeInfo info =
106         {
107             sizeof (CutGtkUIFactoryClass),
108             (GBaseInitFunc) NULL,
109             (GBaseFinalizeFunc) NULL,
110             (GClassInitFunc) class_init,
111             NULL,           /* class_finalize */
112             NULL,           /* class_data */
113             sizeof(CutGtkUIFactory),
114             0,
115             (GInstanceInitFunc) init,
116         };
117 
118     cut_type_gtk_ui_factory =
119         g_type_module_register_type(type_module,
120                                     CUT_TYPE_MODULE_FACTORY,
121                                     "CutGtkUIFactory",
122                                     &info, 0);
123 }
124 
125 G_MODULE_EXPORT GList *
CUT_MODULE_IMPL_INIT(GTypeModule * type_module)126 CUT_MODULE_IMPL_INIT (GTypeModule *type_module)
127 {
128     GList *registered_types = NULL;
129 
130     register_type(type_module);
131     if (cut_type_gtk_ui_factory)
132         registered_types =
133             g_list_prepend(registered_types,
134                            (gchar *)g_type_name(cut_type_gtk_ui_factory));
135 
136     return registered_types;
137 }
138 
139 G_MODULE_EXPORT void
CUT_MODULE_IMPL_EXIT(void)140 CUT_MODULE_IMPL_EXIT (void)
141 {
142 }
143 
144 G_MODULE_EXPORT GObject *
CUT_MODULE_IMPL_INSTANTIATE(const gchar * first_property,va_list var_args)145 CUT_MODULE_IMPL_INSTANTIATE (const gchar *first_property, va_list var_args)
146 {
147     return g_object_new_valist(CUT_TYPE_GTK_UI_FACTORY, first_property, var_args);
148 }
149 
150 static void
dispose(GObject * object)151 dispose (GObject *object)
152 {
153     G_OBJECT_CLASS(parent_class)->dispose(object);
154 }
155 
156 static void
set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)157 set_property (GObject      *object,
158               guint         prop_id,
159               const GValue *value,
160               GParamSpec   *pspec)
161 {
162     switch (prop_id) {
163       default:
164         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
165         break;
166     }
167 }
168 
169 static void
get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)170 get_property (GObject    *object,
171               guint       prop_id,
172               GValue     *value,
173               GParamSpec *pspec)
174 {
175     switch (prop_id) {
176       default:
177         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
178         break;
179     }
180 }
181 
182 static void
set_option_group(CutModuleFactory * factory,GOptionContext * context)183 set_option_group (CutModuleFactory *factory, GOptionContext *context)
184 {
185     GOptionGroup *group;
186 
187     if (CUT_MODULE_FACTORY_CLASS(parent_class)->set_option_group)
188         CUT_MODULE_FACTORY_CLASS(parent_class)->set_option_group(factory, context);
189 
190     group = gtk_get_option_group(TRUE);
191     g_option_context_add_group(context, group);
192 }
193 
194 GObject *
create(CutModuleFactory * factory)195 create (CutModuleFactory *factory)
196 {
197     return G_OBJECT(cut_ui_new("gtk", NULL));
198 }
199 
200 /*
201 vi:ts=4:nowrap:ai:expandtab:sw=4
202 */
203