Updated Finnish translation
[rhythmbox.git] / plugins / rb-plugin.c
blob652105146e93aa23f1e2a1aad565998b9773ec42
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
3 * heavily based on code from Gedit
5 * Copyright (C) 2002-2005 Paolo Maggi
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program 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
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301 USA.
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
27 #include <glib.h>
29 #include "rb-plugin.h"
30 #include "rb-util.h"
31 #include "rb-debug.h"
32 #include "rb-file-helpers.h"
33 #include "eel-gconf-extensions.h"
35 G_DEFINE_TYPE (RBPlugin, rb_plugin, G_TYPE_OBJECT)
36 #define RB_PLUGIN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RB_TYPE_PLUGIN, RBPluginPrivate))
38 static void rb_plugin_finalise (GObject *o);
39 static void rb_plugin_set_property (GObject *object,
40 guint prop_id,
41 const GValue *value,
42 GParamSpec *pspec);
43 static void rb_plugin_get_property (GObject *object,
44 guint prop_id,
45 GValue *value,
46 GParamSpec *pspec);
48 typedef struct {
49 char *name;
50 } RBPluginPrivate;
52 enum
54 PROP_0,
55 PROP_NAME,
58 static gboolean
59 is_configurable (RBPlugin *plugin)
61 return (RB_PLUGIN_GET_CLASS (plugin)->create_configure_dialog != NULL);
64 static void
65 rb_plugin_class_init (RBPluginClass *klass)
67 GObjectClass *object_class = G_OBJECT_CLASS (klass);
69 object_class->finalize = rb_plugin_finalise;
70 object_class->get_property = rb_plugin_get_property;
71 object_class->set_property = rb_plugin_set_property;
73 klass->activate = NULL;
74 klass->deactivate = NULL;
75 klass->create_configure_dialog = NULL;
76 klass->is_configurable = is_configurable;
78 /* this should be a construction property, but due to the python plugin hack can't be */
79 g_object_class_install_property (object_class,
80 PROP_NAME,
81 g_param_spec_string ("name",
82 "name",
83 "name",
84 NULL,
85 G_PARAM_READWRITE /*| G_PARAM_CONSTRUCT_ONLY*/));
87 g_type_class_add_private (klass, sizeof (RBPluginPrivate));
90 static void
91 rb_plugin_init (RBPlugin *plugin)
93 /* Empty */
96 static void
97 rb_plugin_finalise (GObject *object)
99 RBPluginPrivate *priv = RB_PLUGIN_GET_PRIVATE (object);
101 g_free (priv->name);
103 G_OBJECT_CLASS (rb_plugin_parent_class)->finalize (object);
106 static void
107 rb_plugin_set_property (GObject *object,
108 guint prop_id,
109 const GValue *value,
110 GParamSpec *pspec)
112 RBPluginPrivate *priv = RB_PLUGIN_GET_PRIVATE (object);
114 switch (prop_id)
116 case PROP_NAME:
117 g_free (priv->name);
118 priv->name = g_value_dup_string (value);
119 break;
120 default:
121 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
122 break;
126 static void
127 rb_plugin_get_property (GObject *object,
128 guint prop_id,
129 GValue *value,
130 GParamSpec *pspec)
132 RBPluginPrivate *priv = RB_PLUGIN_GET_PRIVATE (object);
134 switch (prop_id)
136 case PROP_NAME:
137 g_value_set_string (value, priv->name);
138 break;
139 default:
140 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
141 break;
145 void
146 rb_plugin_activate (RBPlugin *plugin,
147 RBShell *shell)
149 g_return_if_fail (RB_IS_PLUGIN (plugin));
150 g_return_if_fail (RB_IS_SHELL (shell));
152 if (RB_PLUGIN_GET_CLASS (plugin)->activate)
153 RB_PLUGIN_GET_CLASS (plugin)->activate (plugin, shell);
156 void
157 rb_plugin_deactivate (RBPlugin *plugin,
158 RBShell *shell)
160 g_return_if_fail (RB_IS_PLUGIN (plugin));
161 g_return_if_fail (RB_IS_SHELL (shell));
163 if (RB_PLUGIN_GET_CLASS (plugin)->deactivate)
164 RB_PLUGIN_GET_CLASS (plugin)->deactivate (plugin, shell);
167 gboolean
168 rb_plugin_is_configurable (RBPlugin *plugin)
170 g_return_val_if_fail (RB_IS_PLUGIN (plugin), FALSE);
172 return RB_PLUGIN_GET_CLASS (plugin)->is_configurable (plugin);
175 GtkWidget *
176 rb_plugin_create_configure_dialog (RBPlugin *plugin)
178 g_return_val_if_fail (RB_IS_PLUGIN (plugin), NULL);
180 if (RB_PLUGIN_GET_CLASS (plugin)->create_configure_dialog)
181 return RB_PLUGIN_GET_CLASS (plugin)->create_configure_dialog (plugin);
182 else
183 return NULL;
186 #define UNINSTALLED_PLUGINS_LOCATION "plugins"
188 GList *
189 rb_get_plugin_paths (void)
191 GList *paths;
192 char *path;
194 paths = NULL;
196 if (!eel_gconf_get_boolean (CONF_PLUGIN_DISABLE_USER)) {
197 path = g_build_filename (rb_dot_dir (), "plugins", NULL);
198 paths = g_list_prepend (paths, path);
201 #ifdef SHARE_UNINSTALLED_DIR
202 path = g_build_filename (UNINSTALLED_PLUGINS_LOCATION, NULL);
203 paths = g_list_prepend (paths, path);
204 path = g_build_filename ("..", UNINSTALLED_PLUGINS_LOCATION, NULL);
205 paths = g_list_prepend (paths, path);
206 #endif
208 path = g_strdup (RB_PLUGIN_DIR);
209 paths = g_list_prepend (paths, path);
211 paths = g_list_reverse (paths);
213 return paths;
217 char *
218 rb_plugin_find_file (RBPlugin *plugin,
219 const char *file)
221 RBPluginPrivate *priv = RB_PLUGIN_GET_PRIVATE (plugin);
222 GList *paths;
223 GList *l;
224 char *ret = NULL;
226 paths = rb_get_plugin_paths ();
228 for (l = paths; l != NULL; l = l->next) {
229 if (ret == NULL && priv->name) {
230 char *tmp;
232 tmp = g_build_filename (l->data, priv->name, file, NULL);
234 if (g_file_test (tmp, G_FILE_TEST_EXISTS)) {
235 ret = tmp;
236 break;
238 g_free (tmp);
242 g_list_foreach (paths, (GFunc)g_free, NULL);
243 g_list_free (paths);
245 /* global data files */
246 if (ret == NULL) {
247 const char *f;
249 f = rb_file (file);
250 if (f)
251 ret = g_strdup (f);
254 rb_debug ("found '%s' when searching for file '%s' for plugin '%s'",
255 ret, file, priv->name);
256 return ret;