2006-12-14 Francisco Javier F. Serrador <serrador@openshine.com>
[rhythmbox.git] / plugins / rb-plugin.h
blob84df1185440be5ca5cb7b7b4521af6c5e3bcaeee
1 /*
2 * heavily based on code from Gedit
4 * Copyright (C) 2002-2005 - Paolo Maggi
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301 USA.
22 #ifndef __RB_PLUGIN_H__
23 #define __RB_PLUGIN_H__
25 #include <glib-object.h>
27 #include "rb-shell.h"
29 G_BEGIN_DECLS
32 * Type checking and casting macros
34 #define RB_TYPE_PLUGIN (rb_plugin_get_type())
35 #define RB_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), RB_TYPE_PLUGIN, RBPlugin))
36 #define RB_PLUGIN_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), RB_TYPE_PLUGIN, RBPlugin const))
37 #define RB_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), RB_TYPE_PLUGIN, RBPluginClass))
38 #define RB_IS_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), RB_TYPE_PLUGIN))
39 #define RB_IS_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RB_TYPE_PLUGIN))
40 #define RB_PLUGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), RB_TYPE_PLUGIN, RBPluginClass))
43 * Main object structure
45 typedef struct
47 GObject parent;
48 } RBPlugin;
50 typedef void (*RBPluginActivationFunc) (RBPlugin *plugin, RBShell *shell);
51 typedef GtkWidget * (*RBPluginWidgetFunc) (RBPlugin *plugin);
52 typedef gboolean (*RBPluginBooleanFunc) (RBPlugin *plugin);
55 * Class definition
57 typedef struct
59 GObjectClass parent_class;
61 /* Virtual public methods */
63 RBPluginActivationFunc activate;
64 RBPluginActivationFunc deactivate;
65 RBPluginWidgetFunc create_configure_dialog;
67 /* Plugins should not override this, it's handled automatically by
68 the RbPluginClass */
69 RBPluginBooleanFunc is_configurable;
70 } RBPluginClass;
73 * Public methods
75 GType rb_plugin_get_type (void) G_GNUC_CONST;
77 void rb_plugin_activate (RBPlugin *plugin,
78 RBShell *shell);
79 void rb_plugin_deactivate (RBPlugin *plugin,
80 RBShell *shell);
82 gboolean rb_plugin_is_configurable (RBPlugin *plugin);
83 GtkWidget *rb_plugin_create_configure_dialog
84 (RBPlugin *plugin);
86 char * rb_plugin_find_file (RBPlugin *plugin,
87 const char *file);
89 GList * rb_get_plugin_paths (void);
92 * Utility macro used to register plugins
94 * use: RBT_PLUGIN_REGISTER(RBSamplePlugin, rb_sample_plugin)
97 #define RB_PLUGIN_REGISTER(PluginName, plugin_name) \
99 static GType plugin_name##_type = 0; \
100 static GTypeModule *plugin_module_type = 0; \
102 GType \
103 plugin_name##_get_type (void) \
105 return plugin_name##_type; \
108 static void plugin_name##_init (PluginName *self); \
109 static void plugin_name##_class_init (PluginName##Class *klass); \
110 static gpointer plugin_name##_parent_class = NULL; \
111 static void plugin_name##_class_intern_init (gpointer klass) \
113 plugin_name##_parent_class = g_type_class_peek_parent (klass); \
114 plugin_name##_class_init ((PluginName##Class *) klass); \
117 G_MODULE_EXPORT GType \
118 register_rb_plugin (GTypeModule *module) \
120 static const GTypeInfo our_info = \
122 sizeof (PluginName##Class), \
123 NULL, /* base_init */ \
124 NULL, /* base_finalize */ \
125 (GClassInitFunc) plugin_name##_class_intern_init, \
126 NULL, \
127 NULL, /* class_data */ \
128 sizeof (PluginName), \
129 0, /* n_preallocs */ \
130 (GInstanceInitFunc) plugin_name##_init \
131 }; \
133 rb_debug ("Registering plugin %s", #PluginName); \
135 /* Initialise the i18n stuff */ \
136 bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); \
137 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); \
139 plugin_module_type = module; \
140 plugin_name##_type = g_type_module_register_type (module, \
141 RB_TYPE_PLUGIN, \
142 #PluginName, \
143 &our_info, \
144 0); \
145 return plugin_name##_type; \
148 #define RB_PLUGIN_REGISTER_TYPE(type_name) \
149 type_name##_register_type (plugin_module_type)
151 #define RB_PLUGIN_DEFINE_TYPE(TypeName, type_name, TYPE_PARENT) \
152 static void type_name##_init (TypeName *self); \
153 static void type_name##_class_init (TypeName##Class *klass); \
154 static gpointer type_name##_parent_class = ((void *)0); \
155 static GType type_name##_type_id = 0; \
157 static void \
158 type_name##_class_intern_init (gpointer klass) \
160 type_name##_parent_class = g_type_class_peek_parent (klass); \
161 type_name##_class_init ((TypeName##Class*) klass); \
165 GType \
166 type_name##_get_type (void) \
168 g_assert (type_name##_type_id != 0); \
170 return type_name##_type_id; \
173 GType \
174 type_name##_register_type (GTypeModule *module) \
177 if ((type_name##_type_id == 0)) { \
178 static const GTypeInfo g_define_type_info = { \
179 sizeof (TypeName##Class), \
180 (GBaseInitFunc) ((void *)0), \
181 (GBaseFinalizeFunc) ((void *)0), \
182 (GClassInitFunc) type_name##_class_intern_init, \
183 (GClassFinalizeFunc) ((void *)0), \
184 ((void *)0), \
185 sizeof (TypeName), \
186 0, \
187 (GInstanceInitFunc) type_name##_init, \
188 ((void *)0) \
189 }; \
190 type_name##_type_id = \
191 g_type_module_register_type (module, \
192 TYPE_PARENT, \
193 #TypeName, \
194 &g_define_type_info, \
195 (GTypeFlags) 0); \
198 return type_name##_type_id; \
201 G_END_DECLS
203 #endif /* __GEDIT_PLUGIN_H__ */