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.
29 #include "rb-plugin.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
,
43 static void rb_plugin_get_property (GObject
*object
,
59 is_configurable (RBPlugin
*plugin
)
61 return (RB_PLUGIN_GET_CLASS (plugin
)->create_configure_dialog
!= NULL
);
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
,
81 g_param_spec_string ("name",
85 G_PARAM_READWRITE
/*| G_PARAM_CONSTRUCT_ONLY*/));
87 g_type_class_add_private (klass
, sizeof (RBPluginPrivate
));
91 rb_plugin_init (RBPlugin
*plugin
)
97 rb_plugin_finalise (GObject
*object
)
99 RBPluginPrivate
*priv
= RB_PLUGIN_GET_PRIVATE (object
);
103 G_OBJECT_CLASS (rb_plugin_parent_class
)->finalize (object
);
107 rb_plugin_set_property (GObject
*object
,
112 RBPluginPrivate
*priv
= RB_PLUGIN_GET_PRIVATE (object
);
118 priv
->name
= g_value_dup_string (value
);
121 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
127 rb_plugin_get_property (GObject
*object
,
132 RBPluginPrivate
*priv
= RB_PLUGIN_GET_PRIVATE (object
);
137 g_value_set_string (value
, priv
->name
);
140 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
146 rb_plugin_activate (RBPlugin
*plugin
,
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
);
157 rb_plugin_deactivate (RBPlugin
*plugin
,
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
);
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
);
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
);
186 #define UNINSTALLED_PLUGINS_LOCATION "plugins"
189 rb_get_plugin_paths (void)
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
);
208 path
= g_strdup (RB_PLUGIN_DIR
);
209 paths
= g_list_prepend (paths
, path
);
211 paths
= g_list_reverse (paths
);
218 rb_plugin_find_file (RBPlugin
*plugin
,
221 RBPluginPrivate
*priv
= RB_PLUGIN_GET_PRIVATE (plugin
);
226 paths
= rb_get_plugin_paths ();
228 for (l
= paths
; l
!= NULL
; l
= l
->next
) {
229 if (ret
== NULL
&& priv
->name
) {
232 tmp
= g_build_filename (l
->data
, priv
->name
, file
, NULL
);
234 if (g_file_test (tmp
, G_FILE_TEST_EXISTS
)) {
242 g_list_foreach (paths
, (GFunc
)g_free
, NULL
);
245 /* global data files */
254 rb_debug ("found '%s' when searching for file '%s' for plugin '%s'",
255 ret
, file
, priv
->name
);