Debian Codegraph @

peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.c

raw
1 /*
2 * peasdemo-hello-world-plugin.c
3 * This file is part of libpeas
4 *
5 * Copyright (C) 2009-2010 Steve Frécinaux
6 *
7 * libpeas is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * libpeas is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <glib.h>
27 #include <glib-object.h>
28 #include <gmodule.h>
29 #include <gtk/gtk.h>
30
31 #include <libpeas/peas.h>
32 #include <libpeas-gtk/peas-gtk.h>
33
34 #include "peasdemo-hello-world-plugin.h"
35 #include "peasdemo-hello-world-configurable.h"
36
37 static void peas_activatable_iface_init (PeasActivatableInterface *iface);
38
39 G_DEFINE_DYNAMIC_TYPE_EXTENDED (PeasDemoHelloWorldPlugin,
40 peasdemo_hello_world_plugin,
41 PEAS_TYPE_EXTENSION_BASE,
42 0,
43 G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_TYPE_ACTIVATABLE,
44 peas_activatable_iface_init))
45
46 enum {
47 PROP_0,
48 PROP_OBJECT
49 };
50
51 static void
52 peasdemo_hello_world_plugin_set_property (GObject *object,
53 guint prop_id,
54 const GValue *value,
55 GParamSpec *pspec)
56 {
57 PeasDemoHelloWorldPlugin *plugin = PEASDEMO_HELLO_WORLD_PLUGIN (object);
58
59 switch (prop_id)
60 {
61 case PROP_OBJECT:
62 plugin->window = GTK_WIDGET (g_value_dup_object (value));
63 break;
64
65 default:
66 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
67 break;
68 }
69 }
70
71 static void
72 peasdemo_hello_world_plugin_get_property (GObject *object,
73 guint prop_id,
74 GValue *value,
75 GParamSpec *pspec)
76 {
77 PeasDemoHelloWorldPlugin *plugin = PEASDEMO_HELLO_WORLD_PLUGIN (object);
78
79 switch (prop_id)
80 {
81 case PROP_OBJECT:
82 g_value_set_object (value, plugin->window);
83 break;
84
85 default:
86 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
87 break;
88 }
89 }
90
91
92 static void
93 peasdemo_hello_world_plugin_init (PeasDemoHelloWorldPlugin *plugin)
94 {
95 g_debug ("%s", G_STRFUNC);
96 }
97
98 static void
99 peasdemo_hello_world_plugin_finalize (GObject *object)
100 {
101 PeasDemoHelloWorldPlugin *plugin = PEASDEMO_HELLO_WORLD_PLUGIN (object);
102
103 g_debug ("%s", G_STRFUNC);
104
105 g_object_unref (plugin->label);
106 g_object_unref (plugin->window);
107
108 G_OBJECT_CLASS (peasdemo_hello_world_plugin_parent_class)->finalize (object);
109 }
110
111 static GtkBox *
112 get_box (GtkWidget *window)
113 {
114 return GTK_BOX (gtk_bin_get_child (GTK_BIN (window)));
115 }
116
117 static void
118 peasdemo_hello_world_plugin_activate (PeasActivatable *activatable)
119 {
120 PeasDemoHelloWorldPlugin *plugin = PEASDEMO_HELLO_WORLD_PLUGIN (activatable);
121
122 g_debug ("%s", G_STRFUNC);
123
124 plugin->label = gtk_label_new ("Hello World!");
125 gtk_box_pack_start (get_box (plugin->window), plugin->label, 1, 1, 0);
126 gtk_widget_show (plugin->label);
127 g_object_ref (plugin->label);
128 }
129
130 static void
131 peasdemo_hello_world_plugin_deactivate (PeasActivatable *activatable)
132 {
133 PeasDemoHelloWorldPlugin *plugin = PEASDEMO_HELLO_WORLD_PLUGIN (activatable);
134
135 g_debug ("%s", G_STRFUNC);
136
137 gtk_container_remove (GTK_CONTAINER (get_box (plugin->window)), plugin->label);
138 }
139
140 static void
141 peasdemo_hello_world_plugin_class_init (PeasDemoHelloWorldPluginClass *klass)
142 {
143 GObjectClass *object_class = G_OBJECT_CLASS (klass);
144
145 object_class->set_property = peasdemo_hello_world_plugin_set_property;
146 object_class->get_property = peasdemo_hello_world_plugin_get_property;
147 object_class->finalize = peasdemo_hello_world_plugin_finalize;
148
149 g_object_class_override_property (object_class, PROP_OBJECT, "object");
150 }
151
152 static void
153 peas_activatable_iface_init (PeasActivatableInterface *iface)
154 {
155 iface->activate = peasdemo_hello_world_plugin_activate;
156 iface->deactivate = peasdemo_hello_world_plugin_deactivate;
157 }
158
159 static void
160 peasdemo_hello_world_plugin_class_finalize (PeasDemoHelloWorldPluginClass *klass)
161 {
162 }
163
164 G_MODULE_EXPORT void
165 peas_register_types (PeasObjectModule *module)
166 {
167 peasdemo_hello_world_plugin_register_type (G_TYPE_MODULE (module));
168 peasdemo_hello_world_configurable_register (G_TYPE_MODULE (module));
169
170 peas_object_module_register_extension_type (module,
171 PEAS_TYPE_ACTIVATABLE,
172 PEASDEMO_TYPE_HELLO_WORLD_PLUGIN);
173 peas_object_module_register_extension_type (module,
174 PEAS_GTK_TYPE_CONFIGURABLE,
175 PEASDEMO_TYPE_HELLO_WORLD_CONFIGURABLE);
176 }