~ubuntu-branches/ubuntu/oneiric/rhythmbox/oneiric

« back to all changes in this revision

Viewing changes to shell/rb-plugins-engine.c

  • Committer: Bazaar Package Importer
  • Author(s): Rico Tzschichholz
  • Date: 2011-07-29 16:41:38 UTC
  • mto: This revision was merged to the branch mainline in revision 191.
  • Revision ID: james.westby@ubuntu.com-20110729164138-wwicy8nqalm18ck7
Tags: upstream-2.90.1~20110802
ImportĀ upstreamĀ versionĀ 2.90.1~20110802

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
2
 
 *
3
 
 * Plugin manager for Rhythmbox, based heavily on the code from gedit.
4
 
 *
5
 
 * Copyright (C) 2002-2005 Paolo Maggi
6
 
 *               2006 James Livingston  <doclivingston@gmail.com>
7
 
 *
8
 
 * This program is free software; you can redistribute it and/or modify
9
 
 * it under the terms of the GNU General Public License as published by
10
 
 * the Free Software Foundation; either version 2 of the License, or
11
 
 * (at your option) any later version.
12
 
 *
13
 
 *  The Rhythmbox authors hereby grant permission for non-GPL compatible
14
 
 *  GStreamer plugins to be used and distributed together with GStreamer
15
 
 *  and Rhythmbox. This permission is above and beyond the permissions granted
16
 
 *  by the GPL license by which Rhythmbox is covered. If you modify this code
17
 
 *  you may extend this exception to your version of the code, but you are not
18
 
 *  obligated to do so. If you do not wish to do so, delete this exception
19
 
 *  statement from your version.
20
 
 *
21
 
 * This program is distributed in the hope that it will be useful,
22
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
 
 * GNU General Public License for more details.
25
 
 *
26
 
 * You should have received a copy of the GNU General Public License
27
 
 * along with this program; if not, write to the Free Software
28
 
 * Foundation, Inc., 51 Franklin St, Fifth Floor,
29
 
 * Boston, MA 02110-1301  USA.
30
 
 */
31
 
 
32
 
#ifdef HAVE_CONFIG_H
33
 
#include <config.h>
34
 
#endif
35
 
 
36
 
#include <string.h>
37
 
 
38
 
#include <glib.h>
39
 
#include <glib/gi18n.h>
40
 
 
41
 
#include "eel-gconf-extensions.h"
42
 
#include "rb-file-helpers.h"
43
 
#include "rb-preferences.h"
44
 
#include "rb-util.h"
45
 
#include "rb-plugin.h"
46
 
#include "rb-debug.h"
47
 
#include "rb-dialog.h"
48
 
 
49
 
#include "rb-module.h"
50
 
#ifdef ENABLE_PYTHON
51
 
#include "rb-python-module.h"
52
 
#endif
53
 
 
54
 
#include "rb-plugins-engine.h"
55
 
 
56
 
#define PLUGIN_EXT      ".rb-plugin"
57
 
 
58
 
typedef enum
59
 
{
60
 
        RB_PLUGIN_LOADER_C,
61
 
        RB_PLUGIN_LOADER_PY,
62
 
} RBPluginLang;
63
 
 
64
 
struct _RBPluginInfo
65
 
{
66
 
        gchar        *file;
67
 
 
68
 
        gchar        *location;
69
 
        RBPluginLang lang;
70
 
        GTypeModule  *module;
71
 
 
72
 
        gchar        *name;
73
 
        gchar        *desc;
74
 
        gchar        **authors;
75
 
        gchar        *copyright;
76
 
        gchar        *website;
77
 
 
78
 
        gchar        *icon_name;
79
 
        GdkPixbuf    *icon_pixbuf;
80
 
 
81
 
        RBPlugin     *plugin;
82
 
 
83
 
        gboolean     active;
84
 
        gboolean     visible;
85
 
        guint        active_notification_id;
86
 
        guint        visible_notification_id;
87
 
};
88
 
 
89
 
static void rb_plugin_info_free (RBPluginInfo *info);
90
 
static void rb_plugins_engine_plugin_active_cb (GConfClient *client,
91
 
                                                guint cnxn_id,
92
 
                                                GConfEntry *entry,
93
 
                                                RBPluginInfo *info);
94
 
static void rb_plugins_engine_plugin_visible_cb (GConfClient *client,
95
 
                                                 guint cnxn_id,
96
 
                                                 GConfEntry *entry,
97
 
                                                 RBPluginInfo *info);
98
 
static gboolean rb_plugins_engine_activate_plugin_real (RBPluginInfo *info,
99
 
                                                        RBShell *shell);
100
 
static void rb_plugins_engine_deactivate_plugin_real (RBPluginInfo *info,
101
 
                                                      RBShell *shell);
102
 
 
103
 
static GHashTable *rb_plugins = NULL;
104
 
guint garbage_collect_id = 0;
105
 
RBShell *rb_plugins_shell = NULL;
106
 
 
107
 
static RBPluginInfo *
108
 
rb_plugins_engine_load (const gchar *file)
109
 
{
110
 
        RBPluginInfo *info;
111
 
        GKeyFile *plugin_file = NULL;
112
 
        gchar *str;
113
 
 
114
 
        g_return_val_if_fail (file != NULL, NULL);
115
 
 
116
 
        rb_debug ("Loading plugin: %s", file);
117
 
 
118
 
        info = g_new0 (RBPluginInfo, 1);
119
 
        info->file = g_strdup (file);
120
 
 
121
 
        plugin_file = g_key_file_new ();
122
 
        if (!g_key_file_load_from_file (plugin_file, file, G_KEY_FILE_NONE, NULL)) {
123
 
                g_warning ("Bad plugin file: %s", file);
124
 
                goto error;
125
 
        }
126
 
 
127
 
        if (!g_key_file_has_key (plugin_file,
128
 
                                 "RB Plugin",
129
 
                                 "IAge",
130
 
                                 NULL)) {
131
 
                rb_debug ("IAge key does not exist in file: %s", file);
132
 
                goto error;
133
 
        }
134
 
 
135
 
        /* Check IAge=1 */
136
 
        if (g_key_file_get_integer (plugin_file,
137
 
                                    "RB Plugin",
138
 
                                    "IAge",
139
 
                                    NULL) != 1) {
140
 
                rb_debug ("Wrong IAge in file: %s", file);
141
 
                goto error;
142
 
        }
143
 
 
144
 
        /* Get Location */
145
 
        str = g_key_file_get_string (plugin_file,
146
 
                                     "RB Plugin",
147
 
                                     "Module",
148
 
                                     NULL);
149
 
        if (str) {
150
 
                info->location = str;
151
 
 
152
 
                /* FIXME:
153
 
                 * Blacklist a few plugins that we know not to work,
154
 
                 * and cause crashes */
155
 
                if (g_str_equal (str, "upnp_coherence"))
156
 
                        goto error;
157
 
        } else {
158
 
                g_warning ("Could not find 'Module' in %s", file);
159
 
                goto error;
160
 
        }
161
 
 
162
 
        /* Get the loader for this plugin */
163
 
        str = g_key_file_get_string (plugin_file,
164
 
                                     "RB Plugin",
165
 
                                     "Loader",
166
 
                                     NULL);
167
 
        if (str && strcmp(str, "python") == 0) {
168
 
                info->lang = RB_PLUGIN_LOADER_PY;
169
 
#ifndef ENABLE_PYTHON
170
 
                rb_debug ("Cannot load python extension '%s', Rhythmbox was not "
171
 
                                        "compiled with python support", file);
172
 
                g_free (str);
173
 
                goto error;
174
 
#endif
175
 
        } else {
176
 
                info->lang = RB_PLUGIN_LOADER_C;
177
 
        }
178
 
        g_free (str);
179
 
 
180
 
        /* Get Name */
181
 
        str = g_key_file_get_locale_string (plugin_file,
182
 
                                            "RB Plugin",
183
 
                                            "Name",
184
 
                                            NULL, NULL);
185
 
        if (str) {
186
 
                info->name = str;
187
 
        } else {
188
 
                g_warning ("Could not find 'Name' in %s", file);
189
 
                goto error;
190
 
        }
191
 
 
192
 
        /* Get Description */
193
 
        str = g_key_file_get_locale_string (plugin_file,
194
 
                                            "RB Plugin",
195
 
                                            "Description",
196
 
                                            NULL, NULL);
197
 
        if (str) {
198
 
                info->desc = str;
199
 
        } else {
200
 
                rb_debug ("Could not find 'Description' in %s", file);
201
 
                info->desc = g_strdup ("");
202
 
        }
203
 
 
204
 
        /* Get icon name */
205
 
        str = g_key_file_get_string (plugin_file,
206
 
                                     "RB Plugin",
207
 
                                     "Icon",
208
 
                                     NULL);
209
 
        if (str) {
210
 
                info->icon_name = str;
211
 
        } else {
212
 
                rb_debug ("Could not find 'Icon' in %s", file);
213
 
                info->icon_name = g_strdup ("");
214
 
        }
215
 
 
216
 
        /* Get Authors */
217
 
        info->authors = g_key_file_get_string_list (plugin_file,
218
 
                                                    "RB Plugin",
219
 
                                                    "Authors",
220
 
                                                    NULL, NULL);
221
 
        if (info->authors == NULL)
222
 
                rb_debug ("Could not find 'Authors' in %s", file);
223
 
 
224
 
        /* Get Copyright */
225
 
        str = g_key_file_get_string (plugin_file,
226
 
                                     "RB Plugin",
227
 
                                     "Copyright",
228
 
                                     NULL);
229
 
        if (str) {
230
 
                info->copyright = str;
231
 
        } else {
232
 
                rb_debug ("Could not find 'Copyright' in %s", file);
233
 
                info->copyright = g_strdup ("");
234
 
        }
235
 
 
236
 
        /* Get Copyright */
237
 
        str = g_key_file_get_string (plugin_file,
238
 
                                     "RB Plugin",
239
 
                                     "Website",
240
 
                                     NULL);
241
 
        if (str) {
242
 
                info->website = str;
243
 
        } else {
244
 
                rb_debug ("Could not find 'Website' in %s", file);
245
 
                info->website = g_strdup ("");
246
 
        }
247
 
 
248
 
        g_key_file_free (plugin_file);
249
 
 
250
 
        return info;
251
 
 
252
 
error:
253
 
        g_free (info->file);
254
 
        g_free (info->location);
255
 
        g_free (info->name);
256
 
        g_free (info);
257
 
        g_key_file_free (plugin_file);
258
 
 
259
 
        return NULL;
260
 
}
261
 
 
262
 
static gboolean
263
 
rb_plugins_engine_load_cb (GFile *file, gboolean dir, gpointer userdata)
264
 
{
265
 
        char *plugin_path;
266
 
        RBPluginInfo *info;
267
 
        char *key_name;
268
 
        gboolean activate;
269
 
        const char *sep;
270
 
 
271
 
        plugin_path = g_file_get_path (file);
272
 
 
273
 
        sep = strrchr (plugin_path, G_DIR_SEPARATOR);
274
 
        if (sep == NULL)
275
 
                sep = plugin_path;
276
 
        else
277
 
                sep += 1;
278
 
 
279
 
        /* don't look inside version control system directories.
280
 
         * most are already covered by excluding hidden files/directories.
281
 
         */
282
 
        if (dir && (g_str_has_prefix (sep, "_darcs") || g_str_has_prefix (sep, "CVS"))) {
283
 
                rb_debug ("not loading plugin from hidden/VCS directory %s", plugin_path);
284
 
                g_free (plugin_path);
285
 
                return FALSE;
286
 
        }
287
 
 
288
 
        if (dir || !g_str_has_suffix (plugin_path, PLUGIN_EXT)) {
289
 
                g_free (plugin_path);
290
 
                return TRUE;
291
 
        }
292
 
 
293
 
        info = rb_plugins_engine_load (plugin_path);
294
 
        g_free (plugin_path);
295
 
 
296
 
        if (info == NULL)
297
 
                return TRUE;
298
 
 
299
 
        if (g_hash_table_lookup (rb_plugins, info->location)) {
300
 
                rb_plugin_info_free (info);
301
 
                return TRUE;
302
 
        }
303
 
 
304
 
        g_hash_table_insert (rb_plugins, info->location, info);
305
 
        rb_debug ("Plugin %s loaded", info->name);
306
 
 
307
 
        key_name = g_strdup_printf (CONF_PLUGIN_ACTIVE_KEY, info->location);
308
 
        info->active_notification_id = eel_gconf_notification_add (key_name,
309
 
                                                                   (GConfClientNotifyFunc)rb_plugins_engine_plugin_active_cb,
310
 
                                                                   info);
311
 
        activate = eel_gconf_get_boolean (key_name);
312
 
        g_free (key_name);
313
 
 
314
 
        key_name = g_strdup_printf (CONF_PLUGIN_HIDDEN_KEY, info->location);
315
 
        info->visible_notification_id = eel_gconf_notification_add (key_name,
316
 
                                                                    (GConfClientNotifyFunc)rb_plugins_engine_plugin_visible_cb,
317
 
                                                                    info);
318
 
        info->visible = !eel_gconf_get_boolean (key_name);
319
 
        g_free (key_name);
320
 
 
321
 
        if (activate)
322
 
                rb_plugins_engine_activate_plugin (info);
323
 
        return TRUE;
324
 
}
325
 
 
326
 
static void
327
 
rb_plugins_engine_load_dir (const char *path)
328
 
{
329
 
        GFile *plugindir;
330
 
        char *plugin_uri;
331
 
 
332
 
        plugindir = g_file_new_for_commandline_arg (path);
333
 
        plugin_uri = g_file_get_uri (plugindir);
334
 
 
335
 
        rb_uri_handle_recursively (plugin_uri, NULL, (RBUriRecurseFunc) rb_plugins_engine_load_cb, NULL);
336
 
 
337
 
        g_object_unref (plugindir);
338
 
        g_free (plugin_uri);
339
 
}
340
 
 
341
 
static void
342
 
rb_plugins_engine_load_all (void)
343
 
{
344
 
        GList *paths;
345
 
 
346
 
        paths = rb_get_plugin_paths ();
347
 
        while (paths != NULL) {
348
 
                rb_plugins_engine_load_dir (paths->data);
349
 
                g_free (paths->data);
350
 
                paths = g_list_delete_link (paths, paths);
351
 
        }
352
 
}
353
 
 
354
 
static gboolean
355
 
garbage_collect_cb (gpointer data)
356
 
{
357
 
        rb_plugins_engine_garbage_collect ();
358
 
        return TRUE;
359
 
}
360
 
 
361
 
gboolean
362
 
rb_plugins_engine_init (RBShell *shell)
363
 
{
364
 
        g_return_val_if_fail (rb_plugins == NULL, FALSE);
365
 
 
366
 
        if (!g_module_supported ())
367
 
        {
368
 
                g_warning ("rb is not able to initialize the plugins engine.");
369
 
                return FALSE;
370
 
        }
371
 
        rb_profile_start ("plugins engine init");
372
 
 
373
 
        rb_plugins = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify)rb_plugin_info_free);
374
 
 
375
 
        rb_plugins_shell = shell;
376
 
        g_object_ref (G_OBJECT (rb_plugins_shell));
377
 
#ifdef ENABLE_PYTHON
378
 
        rb_python_module_init_python ();
379
 
#endif
380
 
 
381
 
        rb_plugins_engine_load_all ();
382
 
 
383
 
        garbage_collect_id = g_timeout_add_seconds_full (G_PRIORITY_LOW, 20, garbage_collect_cb, NULL, NULL);
384
 
 
385
 
        rb_profile_end ("plugins engine init");
386
 
 
387
 
        return TRUE;
388
 
}
389
 
 
390
 
void
391
 
rb_plugins_engine_garbage_collect (void)
392
 
{
393
 
#ifdef ENABLE_PYTHON
394
 
        rb_python_garbage_collect ();
395
 
#endif
396
 
}
397
 
 
398
 
static void
399
 
rb_plugin_info_free (RBPluginInfo *info)
400
 
{
401
 
        if (info->active)
402
 
                rb_plugins_engine_deactivate_plugin_real (info, rb_plugins_shell);
403
 
 
404
 
        if (info->plugin != NULL) {
405
 
                rb_debug ("Unref plugin %s", info->name);
406
 
 
407
 
                g_object_unref (info->plugin);
408
 
 
409
 
                /* info->module must not be unref since it is not possible to finalize
410
 
                 * a type module */
411
 
        }
412
 
 
413
 
        eel_gconf_notification_remove (info->active_notification_id);
414
 
        eel_gconf_notification_remove (info->visible_notification_id);
415
 
 
416
 
        g_free (info->file);
417
 
        g_free (info->location);
418
 
        g_free (info->name);
419
 
        g_free (info->desc);
420
 
        g_free (info->website);
421
 
        g_free (info->copyright);
422
 
        g_free (info->icon_name);
423
 
 
424
 
        if (info->icon_pixbuf)
425
 
                g_object_unref (info->icon_pixbuf);
426
 
        g_strfreev (info->authors);
427
 
 
428
 
        g_free (info);
429
 
}
430
 
 
431
 
void
432
 
rb_plugins_engine_shutdown (void)
433
 
{
434
 
        g_hash_table_destroy (rb_plugins);
435
 
        rb_plugins = NULL;
436
 
 
437
 
        g_object_unref (rb_plugins_shell);
438
 
        rb_plugins_shell = NULL;
439
 
 
440
 
        g_source_remove (garbage_collect_id);
441
 
        rb_plugins_engine_garbage_collect ();
442
 
 
443
 
#ifdef ENABLE_PYTHON
444
 
        rb_python_shutdown ();
445
 
#endif
446
 
}
447
 
 
448
 
GList *
449
 
rb_plugins_engine_get_plugins_list (void)
450
 
{
451
 
        return rb_collate_hash_table_values (rb_plugins);
452
 
}
453
 
 
454
 
static gboolean
455
 
load_plugin_module (RBPluginInfo *info)
456
 
{
457
 
        gchar *path;
458
 
        gchar *dirname;
459
 
 
460
 
        g_return_val_if_fail (info != NULL, FALSE);
461
 
        g_return_val_if_fail (info->file != NULL, FALSE);
462
 
        g_return_val_if_fail (info->location != NULL, FALSE);
463
 
        g_return_val_if_fail (info->plugin == NULL, FALSE);
464
 
 
465
 
        switch (info->lang) {
466
 
                case RB_PLUGIN_LOADER_C:
467
 
                        dirname = g_path_get_dirname (info->file);
468
 
                        g_return_val_if_fail (dirname != NULL, FALSE);
469
 
 
470
 
                        path = g_module_build_path (dirname, info->location);
471
 
#ifdef USE_UNINSTALLED_DIRS
472
 
                        if (!g_file_test (path, G_FILE_TEST_EXISTS)) {
473
 
                                char *temp;
474
 
 
475
 
                                g_free (path);
476
 
                                temp = g_build_filename (dirname, ".libs", NULL);
477
 
 
478
 
                                path = g_module_build_path (temp, info->location);
479
 
                                g_free (temp);
480
 
                        }
481
 
#endif
482
 
 
483
 
                        g_free (dirname);
484
 
                        g_return_val_if_fail (path != NULL, FALSE);
485
 
 
486
 
                        info->module = G_TYPE_MODULE (rb_module_new (path, info->location));
487
 
                        g_free (path);
488
 
                        break;
489
 
                case RB_PLUGIN_LOADER_PY:
490
 
#ifdef ENABLE_PYTHON
491
 
                        info->module = G_TYPE_MODULE (rb_python_module_new (info->file, info->location));
492
 
#else
493
 
                        rb_debug ("cannot load plugin %s, python plugin support is disabled", info->location);
494
 
#endif
495
 
                        break;
496
 
        }
497
 
 
498
 
        if (g_type_module_use (info->module) == FALSE) {
499
 
                g_warning ("Could not load plugin %s\n", info->location);
500
 
 
501
 
                g_object_unref (G_OBJECT (info->module));
502
 
                info->module = NULL;
503
 
 
504
 
                return FALSE;
505
 
        }
506
 
 
507
 
        switch (info->lang) {
508
 
                case RB_PLUGIN_LOADER_C:
509
 
                        info->plugin = RB_PLUGIN (rb_module_new_object (RB_MODULE (info->module)));
510
 
                        break;
511
 
                case RB_PLUGIN_LOADER_PY:
512
 
#ifdef ENABLE_PYTHON
513
 
                        info->plugin = RB_PLUGIN (rb_python_module_new_object (RB_PYTHON_MODULE (info->module)));
514
 
#endif
515
 
                        break;
516
 
        }
517
 
 
518
 
        return TRUE;
519
 
}
520
 
 
521
 
static gboolean
522
 
rb_plugins_engine_activate_plugin_real (RBPluginInfo *info, RBShell *shell)
523
 
{
524
 
        gboolean res = TRUE;
525
 
 
526
 
        if (info->plugin == NULL)
527
 
                res = load_plugin_module (info);
528
 
 
529
 
        if (res)
530
 
                rb_plugin_activate (info->plugin, shell);
531
 
        else
532
 
                g_warning ("Error, impossible to activate plugin '%s'", info->name);
533
 
 
534
 
        return res;
535
 
}
536
 
 
537
 
gboolean
538
 
rb_plugins_engine_activate_plugin (RBPluginInfo *info)
539
 
{
540
 
        gboolean ret;
541
 
 
542
 
        g_return_val_if_fail (info != NULL, FALSE);
543
 
 
544
 
        if (info->active)
545
 
                return TRUE;
546
 
 
547
 
        ret = rb_plugins_engine_activate_plugin_real (info, rb_plugins_shell);
548
 
 
549
 
        if (info->visible != FALSE || ret != FALSE) {
550
 
                char *key_name;
551
 
 
552
 
                key_name = g_strdup_printf (CONF_PLUGIN_ACTIVE_KEY, info->location);
553
 
                eel_gconf_set_boolean (key_name, ret);
554
 
                g_free (key_name);
555
 
        }
556
 
        info->active = ret;
557
 
 
558
 
        if (ret != FALSE)
559
 
                return TRUE;
560
 
 
561
 
 
562
 
        rb_error_dialog (NULL, _("Plugin Error"), _("Unable to activate plugin %s"), info->name);
563
 
 
564
 
        return FALSE;
565
 
}
566
 
 
567
 
static void
568
 
rb_plugins_engine_deactivate_plugin_real (RBPluginInfo *info, RBShell *shell)
569
 
{
570
 
        rb_plugin_deactivate (info->plugin, rb_plugins_shell);
571
 
}
572
 
 
573
 
gboolean
574
 
rb_plugins_engine_deactivate_plugin (RBPluginInfo *info)
575
 
{
576
 
        char *key_name;
577
 
 
578
 
        g_return_val_if_fail (info != NULL, FALSE);
579
 
 
580
 
        if (!info->active)
581
 
                return TRUE;
582
 
 
583
 
        rb_plugins_engine_deactivate_plugin_real (info, rb_plugins_shell);
584
 
 
585
 
        /* Update plugin state */
586
 
        info->active = FALSE;
587
 
 
588
 
        key_name = g_strdup_printf (CONF_PLUGIN_ACTIVE_KEY, info->location);
589
 
        eel_gconf_set_boolean (key_name, FALSE);
590
 
        g_free (key_name);
591
 
 
592
 
        return TRUE;
593
 
}
594
 
 
595
 
gboolean
596
 
rb_plugins_engine_plugin_is_active (RBPluginInfo *info)
597
 
{
598
 
        g_return_val_if_fail (info != NULL, FALSE);
599
 
 
600
 
        return info->active;
601
 
}
602
 
 
603
 
gboolean
604
 
rb_plugins_engine_plugin_is_visible (RBPluginInfo *info)
605
 
{
606
 
        g_return_val_if_fail (info != NULL, FALSE);
607
 
 
608
 
        return info->visible;
609
 
}
610
 
 
611
 
gboolean
612
 
rb_plugins_engine_plugin_is_configurable (RBPluginInfo *info)
613
 
{
614
 
        g_return_val_if_fail (info != NULL, FALSE);
615
 
 
616
 
        if ((info->plugin == NULL) || !info->active)
617
 
                return FALSE;
618
 
 
619
 
        return rb_plugin_is_configurable (info->plugin);
620
 
}
621
 
 
622
 
void
623
 
rb_plugins_engine_configure_plugin (RBPluginInfo *info,
624
 
                                       GtkWindow       *parent)
625
 
{
626
 
        GtkWidget *conf_dlg;
627
 
 
628
 
        GtkWindowGroup *wg;
629
 
 
630
 
        g_return_if_fail (info != NULL);
631
 
 
632
 
        conf_dlg = rb_plugin_create_configure_dialog (info->plugin);
633
 
        g_return_if_fail (conf_dlg != NULL);
634
 
        gtk_window_set_transient_for (GTK_WINDOW (conf_dlg),
635
 
                                      parent);
636
 
        gtk_window_set_modal (GTK_WINDOW (conf_dlg), TRUE);
637
 
 
638
 
        if (!gtk_widget_get_mapped (conf_dlg))
639
 
                gtk_window_set_type_hint (GTK_WINDOW (conf_dlg), GDK_WINDOW_TYPE_HINT_DIALOG);
640
 
 
641
 
        wg = gtk_window_get_group (parent);
642
 
        if (wg == NULL)
643
 
        {
644
 
                wg = gtk_window_group_new ();
645
 
                gtk_window_group_add_window (wg, parent);
646
 
        }
647
 
 
648
 
        gtk_window_group_add_window (wg,
649
 
                                     GTK_WINDOW (conf_dlg));
650
 
        gtk_widget_show (conf_dlg);
651
 
}
652
 
 
653
 
static void
654
 
rb_plugins_engine_plugin_active_cb (GConfClient *client,
655
 
                                    guint cnxn_id,
656
 
                                    GConfEntry *entry,
657
 
                                    RBPluginInfo *info)
658
 
{
659
 
        if (gconf_value_get_bool (entry->value)) {
660
 
                rb_plugins_engine_activate_plugin (info);
661
 
        } else {
662
 
                rb_plugins_engine_deactivate_plugin (info);
663
 
        }
664
 
}
665
 
 
666
 
static void
667
 
rb_plugins_engine_plugin_visible_cb (GConfClient *client,
668
 
                                     guint cnxn_id,
669
 
                                     GConfEntry *entry,
670
 
                                     RBPluginInfo *info)
671
 
{
672
 
        info->visible = !gconf_value_get_bool (entry->value);
673
 
}
674
 
 
675
 
const gchar *
676
 
rb_plugins_engine_get_plugin_name (RBPluginInfo *info)
677
 
{
678
 
        g_return_val_if_fail (info != NULL, NULL);
679
 
 
680
 
        return info->name;
681
 
}
682
 
 
683
 
const gchar *
684
 
rb_plugins_engine_get_plugin_description (RBPluginInfo *info)
685
 
{
686
 
        g_return_val_if_fail (info != NULL, NULL);
687
 
 
688
 
        return info->desc;
689
 
}
690
 
 
691
 
const gchar **
692
 
rb_plugins_engine_get_plugin_authors (RBPluginInfo *info)
693
 
{
694
 
        g_return_val_if_fail (info != NULL, (const gchar **)NULL);
695
 
 
696
 
        return (const gchar **)info->authors;
697
 
}
698
 
 
699
 
const gchar *
700
 
rb_plugins_engine_get_plugin_website (RBPluginInfo *info)
701
 
{
702
 
        g_return_val_if_fail (info != NULL, NULL);
703
 
 
704
 
        return info->website;
705
 
}
706
 
 
707
 
const gchar *
708
 
rb_plugins_engine_get_plugin_copyright (RBPluginInfo *info)
709
 
{
710
 
        g_return_val_if_fail (info != NULL, NULL);
711
 
 
712
 
        return info->copyright;
713
 
}
714
 
 
715
 
GdkPixbuf *
716
 
rb_plugins_engine_get_plugin_icon (RBPluginInfo *info)
717
 
{
718
 
        g_return_val_if_fail (info != NULL, NULL);
719
 
 
720
 
        if (info->icon_name == NULL)
721
 
                return NULL;
722
 
 
723
 
        if (info->icon_pixbuf == NULL) {
724
 
                char *filename = NULL;
725
 
                char *dirname;
726
 
 
727
 
                dirname = g_path_get_dirname (info->file);
728
 
                filename = g_build_filename (dirname, info->icon_name, NULL);
729
 
                g_free (dirname);
730
 
 
731
 
                info->icon_pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
732
 
                g_free (filename);
733
 
        }
734
 
 
735
 
        return info->icon_pixbuf;
736
 
}