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

« back to all changes in this revision

Viewing changes to plugins/notification/rb-notification-plugin.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
/*
 
2
 * rb-notification-plugin.c
 
3
 *
 
4
 *  Copyright (C) 2010  Jonathan Matthew  <jonathan@d14n.org>
 
5
 *
 
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, or (at your option)
 
9
 * any later version.
 
10
 *
 
11
 * The Rhythmbox authors hereby grant permission for non-GPL compatible
 
12
 * GStreamer plugins to be used and distributed together with GStreamer
 
13
 * and Rhythmbox. This permission is above and beyond the permissions granted
 
14
 * by the GPL license by which Rhythmbox is covered. If you modify this code
 
15
 * you may extend this exception to your version of the code, but you are not
 
16
 * obligated to do so. If you do not wish to do so, delete this exception
 
17
 * statement from your version.
 
18
 *
 
19
 * This program is distributed in the hope that it will be useful,
 
20
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
21
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
22
 * GNU General Public License for more details.
 
23
 *
 
24
 * You should have received a copy of the GNU General Public License
 
25
 * along with this program; if not, write to the Free Software
 
26
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
 
27
 */
 
28
 
 
29
#include <config.h>
 
30
 
 
31
#include <string.h>
 
32
#include <glib/gi18n-lib.h>
 
33
#include <gtk/gtk.h>
 
34
#include <glib.h>
 
35
#include <glib-object.h>
 
36
#include <pango/pango-bidi-type.h>
 
37
#include <libnotify/notify.h>
 
38
 
 
39
#include "rb-util.h"
 
40
#include "rb-plugin-macros.h"
 
41
#include "rb-debug.h"
 
42
#include "rb-shell.h"
 
43
#include "rb-shell-player.h"
 
44
#include "rb-stock-icons.h"
 
45
 
 
46
#define PLAYING_ENTRY_NOTIFY_TIME       4
 
47
 
 
48
#define RB_TYPE_NOTIFICATION_PLUGIN             (rb_notification_plugin_get_type ())
 
49
#define RB_NOTIFICATION_PLUGIN(o)               (G_TYPE_CHECK_INSTANCE_CAST ((o), RB_TYPE_NOTIFICATION_PLUGIN, RBNotificationPlugin))
 
50
#define RB_NOTIFICATION_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), RB_TYPE_NOTIFICATION_PLUGIN, RBNotificationPluginClass))
 
51
#define RB_IS_NOTIFICATION_PLUGIN(o)            (G_TYPE_CHECK_INSTANCE_TYPE ((o), RB_TYPE_NOTIFICATION_PLUGIN))
 
52
#define RB_IS_NOTIFICATION_PLUGIN_CLASS(k)      (G_TYPE_CHECK_CLASS_TYPE ((k), RB_TYPE_NOTIFICATION_PLUGIN))
 
53
#define RB_NOTIFICATION_PLUGIN_GET_CLASS(o)     (G_TYPE_INSTANCE_GET_CLASS ((o), RB_TYPE_NOTIFICATION_PLUGIN, RBNotificationPluginClass))
 
54
 
 
55
typedef struct
 
56
{
 
57
        PeasExtensionBase parent;
 
58
 
 
59
        /* current playing data */
 
60
        char *current_title;
 
61
        char *current_album_and_artist; /* from _album_ by _artist_ */
 
62
 
 
63
        gchar *notify_art_path;
 
64
        NotifyNotification *notification;
 
65
        gboolean notify_supports_actions;
 
66
        gboolean notify_supports_icon_buttons;
 
67
        gboolean notify_supports_persistence;
 
68
 
 
69
        RBShellPlayer *shell_player;
 
70
        RhythmDB *db;
 
71
} RBNotificationPlugin;
 
72
 
 
73
typedef struct
 
74
{
 
75
        PeasExtensionBaseClass parent_class;
 
76
} RBNotificationPluginClass;
 
77
 
 
78
G_MODULE_EXPORT void peas_register_types (PeasObjectModule  *module);
 
79
 
 
80
RB_DEFINE_PLUGIN(RB_TYPE_NOTIFICATION_PLUGIN, RBNotificationPlugin, rb_notification_plugin,)
 
81
 
 
82
static gchar *
 
83
markup_escape (const char *text)
 
84
{
 
85
        return (text == NULL) ? NULL : g_markup_escape_text (text, -1);
 
86
}
 
87
 
 
88
static void
 
89
notification_closed_cb (NotifyNotification *notification,
 
90
                        RBNotificationPlugin *plugin)
 
91
{
 
92
        rb_debug ("notification closed");
 
93
}
 
94
 
 
95
static void
 
96
notification_next_cb (NotifyNotification *notification,
 
97
                      const char *action,
 
98
                      RBNotificationPlugin *plugin)
 
99
{
 
100
        rb_debug ("notification action: %s", action);
 
101
        rb_shell_player_do_next (plugin->shell_player, NULL);
 
102
}
 
103
 
 
104
static void
 
105
notification_playpause_cb (NotifyNotification *notification,
 
106
                           const char *action,
 
107
                           RBNotificationPlugin *plugin)
 
108
{
 
109
        rb_debug ("notification action: %s", action);
 
110
        rb_shell_player_playpause (plugin->shell_player, FALSE, NULL);
 
111
}
 
112
 
 
113
static void
 
114
notification_previous_cb (NotifyNotification *notification,
 
115
                          const char *action,
 
116
                          RBNotificationPlugin *plugin)
 
117
{
 
118
        rb_debug ("notification action: %s", action);
 
119
        rb_shell_player_do_previous (plugin->shell_player, NULL);
 
120
}
 
121
 
 
122
static void
 
123
do_notify (RBNotificationPlugin *plugin,
 
124
           guint timeout,
 
125
           const char *primary,
 
126
           const char *secondary,
 
127
           const char *image_uri,
 
128
           gboolean playback)
 
129
{
 
130
        GError *error = NULL;
 
131
        NotifyNotification *notification;
 
132
 
 
133
        if (notify_is_initted () == FALSE) {
 
134
                GList *caps;
 
135
 
 
136
                if (notify_init ("Rhythmbox") == FALSE) {
 
137
                        g_warning ("libnotify initialization failed");
 
138
                        return;
 
139
                }
 
140
 
 
141
                /* ask the notification server if it supports actions */
 
142
                caps = notify_get_server_caps ();
 
143
                if (g_list_find_custom (caps, "actions", (GCompareFunc)g_strcmp0) != NULL) {
 
144
                        rb_debug ("notification server supports actions");
 
145
                        plugin->notify_supports_actions = TRUE;
 
146
 
 
147
                        if (g_list_find_custom (caps, "action-icons", (GCompareFunc)g_strcmp0) != NULL) {
 
148
                                rb_debug ("notifiction server supports icon buttons");
 
149
                                plugin->notify_supports_icon_buttons = TRUE;
 
150
                        }
 
151
                } else {
 
152
                        rb_debug ("notification server does not support actions");
 
153
                }
 
154
                if (g_list_find_custom (caps, "persistence", (GCompareFunc)g_strcmp0) != NULL) {
 
155
                        rb_debug ("notification server supports persistence");
 
156
                        plugin->notify_supports_persistence = TRUE;
 
157
                } else {
 
158
                        rb_debug ("notification server does not support persistence");
 
159
                }
 
160
 
 
161
                rb_list_deep_free (caps);
 
162
        }
 
163
 
 
164
        if (primary == NULL)
 
165
                primary = "";
 
166
 
 
167
        if (secondary == NULL)
 
168
                secondary = "";
 
169
 
 
170
        if (playback) {
 
171
                notification = plugin->notification;
 
172
        } else {
 
173
                notification = NULL;
 
174
        }
 
175
 
 
176
        if (notification == NULL) {
 
177
                notification = notify_notification_new (primary, secondary, RB_APP_ICON);
 
178
 
 
179
                g_signal_connect_object (notification,
 
180
                                         "closed",
 
181
                                         G_CALLBACK (notification_closed_cb),
 
182
                                         plugin, 0);
 
183
                if (playback) {
 
184
                        plugin->notification = notification;
 
185
                }
 
186
        } else {
 
187
                notify_notification_clear_hints (notification);
 
188
                notify_notification_update (notification, primary, secondary, RB_APP_ICON);
 
189
        }
 
190
 
 
191
        notify_notification_set_timeout (notification, timeout);
 
192
 
 
193
        if (image_uri != NULL) {
 
194
                notify_notification_clear_hints (notification);
 
195
                notify_notification_set_hint_string (notification,
 
196
                                                     "image_path",
 
197
                                                     image_uri);
 
198
        }
 
199
 
 
200
        notify_notification_clear_actions (notification);
 
201
        if (playback && plugin->notify_supports_actions) {
 
202
                if (plugin->notify_supports_icon_buttons) {
 
203
                        gboolean playing = FALSE;
 
204
                        rb_shell_player_get_playing (plugin->shell_player, &playing, NULL);
 
205
 
 
206
                        notify_notification_add_action (notification,
 
207
                                                        "media-skip-backward",
 
208
                                                        _("Previous"),
 
209
                                                        (NotifyActionCallback) notification_previous_cb,
 
210
                                                        plugin,
 
211
                                                        NULL);
 
212
                        notify_notification_add_action (notification,
 
213
                                                        playing ? "media-playback-pause" : "media-playback-start",
 
214
                                                        playing ? _("Pause") : _("Play"),
 
215
                                                        (NotifyActionCallback) notification_playpause_cb,
 
216
                                                        plugin,
 
217
                                                        NULL);
 
218
                        notify_notification_set_hint_byte (notification,
 
219
                                                           "action-icons",
 
220
                                                           1);
 
221
                }
 
222
 
 
223
                notify_notification_add_action (notification,
 
224
                                                "media-skip-forward",
 
225
                                                _("Next"),
 
226
                                                (NotifyActionCallback) notification_next_cb,
 
227
                                                plugin,
 
228
                                                NULL);
 
229
        }
 
230
 
 
231
        if (plugin->notify_supports_persistence) {
 
232
                const char *hint;
 
233
 
 
234
                if (playback) {
 
235
                        hint = "resident";
 
236
                } else {
 
237
                        hint = "transient";
 
238
                }
 
239
                notify_notification_set_hint_byte (notification,
 
240
                                                   hint,
 
241
                                                   1);
 
242
        }
 
243
 
 
244
        if (notify_notification_show (notification, &error) == FALSE) {
 
245
                g_warning ("Failed to send notification (%s): %s", primary, error->message);
 
246
                g_error_free (error);
 
247
        }
 
248
}
 
249
 
 
250
static void
 
251
notify_playing_entry (RBNotificationPlugin *plugin, gboolean requested)
 
252
{
 
253
        do_notify (plugin,
 
254
                   PLAYING_ENTRY_NOTIFY_TIME * 1000,
 
255
                   plugin->current_title,
 
256
                   plugin->current_album_and_artist,
 
257
                   plugin->notify_art_path,
 
258
                   TRUE);
 
259
}
 
260
 
 
261
static void
 
262
notify_custom (RBNotificationPlugin *plugin,
 
263
               guint timeout,
 
264
               const char *primary,
 
265
               const char *secondary,
 
266
               const char *image_uri,
 
267
               gboolean requested)
 
268
{
 
269
        do_notify (plugin, timeout, primary, secondary, image_uri, FALSE);
 
270
}
 
271
 
 
272
static void
 
273
cleanup_notification (RBNotificationPlugin *plugin)
 
274
{
 
275
        if (plugin->notification != NULL) {
 
276
                g_signal_handlers_disconnect_by_func (plugin->notification,
 
277
                                                      G_CALLBACK (notification_closed_cb),
 
278
                                                      plugin);
 
279
                notify_notification_close (plugin->notification, NULL);
 
280
                plugin->notification = NULL;
 
281
        }
 
282
}
 
283
 
 
284
static void
 
285
shell_notify_playing_cb (RBShell *shell, gboolean requested, RBNotificationPlugin *plugin)
 
286
{
 
287
        notify_playing_entry (plugin, requested);
 
288
}
 
289
 
 
290
static void
 
291
shell_notify_custom_cb (RBShell *shell,
 
292
                        guint timeout,
 
293
                        const char *primary,
 
294
                        const char *secondary,
 
295
                        const char *image_uri,
 
296
                        gboolean requested,
 
297
                        RBNotificationPlugin *plugin)
 
298
{
 
299
        notify_custom (plugin, timeout, primary, secondary, image_uri, requested);
 
300
}
 
301
 
 
302
static void
 
303
get_artist_album_templates (const char *artist,
 
304
                            const char *album,
 
305
                            const char **artist_template,
 
306
                            const char **album_template)
 
307
{
 
308
        PangoDirection tag_dir;
 
309
        PangoDirection template_dir;
 
310
 
 
311
        /* Translators: by Artist */
 
312
        *artist_template = _("by <i>%s</i>");
 
313
        /* Translators: from Album */
 
314
        *album_template = _("from <i>%s</i>");
 
315
 
 
316
        /* find the direction (left-to-right or right-to-left) of the
 
317
         * track's tags and the localized templates
 
318
         */
 
319
        if (artist != NULL && artist[0] != '\0') {
 
320
                tag_dir = pango_find_base_dir (artist, -1);
 
321
                template_dir = pango_find_base_dir (*artist_template, -1);
 
322
        } else if (album != NULL && album[0] != '\0') {
 
323
                tag_dir = pango_find_base_dir (album, -1);
 
324
                template_dir = pango_find_base_dir (*album_template, -1);
 
325
        } else {
 
326
                return;
 
327
        }
 
328
 
 
329
        /* if the track's tags and the localized templates have a different
 
330
         * direction, switch to direction-neutral templates in order to improve
 
331
         * display.
 
332
         * text can have a neutral direction, this condition only applies when
 
333
         * both directions are defined and they are conflicting.
 
334
         * https://bugzilla.gnome.org/show_bug.cgi?id=609767
 
335
         */
 
336
        if (((tag_dir == PANGO_DIRECTION_LTR) && (template_dir == PANGO_DIRECTION_RTL)) ||
 
337
            ((tag_dir == PANGO_DIRECTION_RTL) && (template_dir == PANGO_DIRECTION_LTR))) {
 
338
                /* these strings should not be localized, they must be
 
339
                 * locale-neutral and direction-neutral
 
340
                 */
 
341
                *artist_template = "<i>%s</i>";
 
342
                *album_template = "/ <i>%s</i>";
 
343
        }
 
344
}
 
345
 
 
346
static void
 
347
update_current_playing_data (RBNotificationPlugin *plugin, RhythmDBEntry *entry)
 
348
{
 
349
        GValue *value;
 
350
        const char *stream_title = NULL;
 
351
        char *artist = NULL;
 
352
        char *album = NULL;
 
353
        char *title = NULL;
 
354
        GString *secondary;
 
355
 
 
356
        const char *artist_template = NULL;
 
357
        const char *album_template = NULL;
 
358
 
 
359
        g_free (plugin->current_title);
 
360
        g_free (plugin->current_album_and_artist);
 
361
        g_free (plugin->notify_art_path);
 
362
        plugin->current_title = NULL;
 
363
        plugin->current_album_and_artist = NULL;
 
364
        plugin->notify_art_path = NULL;
 
365
 
 
366
        if (entry == NULL) {
 
367
                plugin->current_title = g_strdup (_("Not Playing"));
 
368
                plugin->current_album_and_artist = g_strdup ("");
 
369
                return;
 
370
        }
 
371
 
 
372
        secondary = g_string_sized_new (100);
 
373
 
 
374
        /* get artist, preferring streaming song details */
 
375
        value = rhythmdb_entry_request_extra_metadata (plugin->db,
 
376
                                                       entry,
 
377
                                                       RHYTHMDB_PROP_STREAM_SONG_ARTIST);
 
378
        if (value != NULL) {
 
379
                artist = markup_escape (g_value_get_string (value));
 
380
                g_value_unset (value);
 
381
                g_free (value);
 
382
        } else {
 
383
                artist = markup_escape (rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_ARTIST));
 
384
        }
 
385
 
 
386
        /* get album, preferring streaming song details */
 
387
        value = rhythmdb_entry_request_extra_metadata (plugin->db,
 
388
                                                       entry,
 
389
                                                       RHYTHMDB_PROP_STREAM_SONG_ALBUM);
 
390
        if (value != NULL) {
 
391
                album = markup_escape (g_value_get_string (value));
 
392
                g_value_unset (value);
 
393
                g_free (value);
 
394
        } else {
 
395
                album = markup_escape (rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_ALBUM));
 
396
        }
 
397
 
 
398
        get_artist_album_templates (artist, album, &artist_template, &album_template);
 
399
 
 
400
        if (artist != NULL && artist[0] != '\0') {
 
401
                g_string_append_printf (secondary, artist_template, artist);
 
402
        }
 
403
        g_free (artist);
 
404
 
 
405
        if (album != NULL && album[0] != '\0') {
 
406
                if (secondary->len != 0)
 
407
                        g_string_append_c (secondary, ' ');
 
408
 
 
409
                g_string_append_printf (secondary, album_template, album);
 
410
        }
 
411
        g_free (album);
 
412
 
 
413
        /* get title and possibly stream name.
 
414
         * if we have a streaming song title, the entry's title
 
415
         * property is the stream name.
 
416
         */
 
417
        value = rhythmdb_entry_request_extra_metadata (plugin->db,
 
418
                                                       entry,
 
419
                                                       RHYTHMDB_PROP_STREAM_SONG_TITLE);
 
420
        if (value != NULL) {
 
421
                title = g_value_dup_string (value);
 
422
                g_value_unset (value);
 
423
                g_free (value);
 
424
 
 
425
                stream_title = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_TITLE);
 
426
        } else {
 
427
                title = g_strdup (rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_TITLE));
 
428
        }
 
429
 
 
430
        if (stream_title != NULL && stream_title[0] != '\0') {
 
431
                char *escaped;
 
432
 
 
433
                escaped = markup_escape (stream_title);
 
434
                if (secondary->len == 0)
 
435
                        g_string_append (secondary, escaped);
 
436
                else
 
437
                        g_string_append_printf (secondary, " (%s)", escaped);
 
438
                g_free (escaped);
 
439
        }
 
440
 
 
441
        if (title == NULL) {
 
442
                /* Translators: unknown track title */
 
443
                title = g_strdup (_("Unknown"));
 
444
        }
 
445
 
 
446
        plugin->current_title = title;
 
447
        plugin->current_album_and_artist = g_string_free (secondary, FALSE);
 
448
}
 
449
 
 
450
static void
 
451
playing_entry_changed_cb (RBShellPlayer *player,
 
452
                          RhythmDBEntry *entry,
 
453
                          RBNotificationPlugin *plugin)
 
454
{
 
455
        update_current_playing_data (plugin, entry);
 
456
 
 
457
        if (entry != NULL) {
 
458
                notify_playing_entry (plugin, FALSE);
 
459
        }
 
460
}
 
461
 
 
462
static gboolean
 
463
is_playing_entry (RBNotificationPlugin *plugin, RhythmDBEntry *entry)
 
464
{
 
465
        RhythmDBEntry *playing;
 
466
 
 
467
        playing = rb_shell_player_get_playing_entry (plugin->shell_player);
 
468
        if (playing == NULL) {
 
469
                return FALSE;
 
470
        }
 
471
 
 
472
        rhythmdb_entry_unref (playing);
 
473
        return (entry == playing);
 
474
}
 
475
 
 
476
static void
 
477
db_art_uri_metadata_cb (RhythmDB *db,
 
478
                        RhythmDBEntry *entry,
 
479
                        const char *field,
 
480
                        GValue *metadata,
 
481
                        RBNotificationPlugin *plugin)
 
482
{
 
483
        guint time;
 
484
 
 
485
        if (is_playing_entry (plugin, entry) == FALSE)
 
486
                return;
 
487
 
 
488
        if (G_VALUE_HOLDS (metadata, G_TYPE_STRING)) {
 
489
                const char *uri = g_value_get_string (metadata);
 
490
                if (g_str_has_prefix (uri, "file://")) {
 
491
                        char *path = g_filename_from_uri (uri, NULL, NULL);
 
492
                        if (g_strcmp0 (path, plugin->notify_art_path) != 0) {
 
493
                                g_free (plugin->notify_art_path);
 
494
                                plugin->notify_art_path = path;
 
495
                        } else {
 
496
                                /* same art URI, ignore it */
 
497
                                g_free (path);
 
498
                                return;
 
499
                        }
 
500
                } else {
 
501
                        /* unsupported art URI, ignore it */
 
502
                        return;
 
503
                }
 
504
        } else {
 
505
                g_free (plugin->notify_art_path);
 
506
                plugin->notify_art_path = NULL;
 
507
        }
 
508
 
 
509
        if (rb_shell_player_get_playing_time (plugin->shell_player, &time, NULL)) {
 
510
                if (time < PLAYING_ENTRY_NOTIFY_TIME) {
 
511
                        notify_playing_entry (plugin, FALSE);
 
512
                }
 
513
        } else {
 
514
                notify_playing_entry (plugin, FALSE);
 
515
        }
 
516
}
 
517
 
 
518
static void
 
519
db_stream_metadata_cb (RhythmDB *db,
 
520
                       RhythmDBEntry *entry,
 
521
                       const char *field,
 
522
                       GValue *metadata,
 
523
                       RBNotificationPlugin *plugin)
 
524
{
 
525
        if (is_playing_entry (plugin, entry) == FALSE)
 
526
                return;
 
527
 
 
528
        update_current_playing_data (plugin, entry);
 
529
}
 
530
 
 
531
/* plugin infrastructure */
 
532
 
 
533
static void
 
534
impl_activate (PeasActivatable *bplugin)
 
535
{
 
536
        RBNotificationPlugin *plugin;
 
537
        RBShell *shell;
 
538
 
 
539
        rb_debug ("activating notification plugin");
 
540
 
 
541
        plugin = RB_NOTIFICATION_PLUGIN (bplugin);
 
542
        g_object_get (plugin, "object", &shell, NULL);
 
543
        g_object_get (shell,
 
544
                      "shell-player", &plugin->shell_player,
 
545
                      "db", &plugin->db,
 
546
                      NULL);
 
547
 
 
548
        /* connect various things */
 
549
        g_signal_connect_object (shell, "notify-playing-entry", G_CALLBACK (shell_notify_playing_cb), plugin, 0);
 
550
        g_signal_connect_object (shell, "notify-custom", G_CALLBACK (shell_notify_custom_cb), plugin, 0);
 
551
 
 
552
        g_signal_connect_object (plugin->shell_player, "playing-song-changed", G_CALLBACK (playing_entry_changed_cb), plugin, 0);
 
553
 
 
554
        g_signal_connect_object (plugin->db, "entry_extra_metadata_notify::" RHYTHMDB_PROP_COVER_ART_URI,
 
555
                                 G_CALLBACK (db_art_uri_metadata_cb), plugin, 0);
 
556
        g_signal_connect_object (plugin->db, "entry_extra_metadata_notify::" RHYTHMDB_PROP_STREAM_SONG_TITLE,
 
557
                                 G_CALLBACK (db_stream_metadata_cb), plugin, 0);
 
558
        g_signal_connect_object (plugin->db, "entry_extra_metadata_notify::" RHYTHMDB_PROP_STREAM_SONG_ARTIST,
 
559
                                 G_CALLBACK (db_stream_metadata_cb), plugin, 0);
 
560
        g_signal_connect_object (plugin->db, "entry_extra_metadata_notify::" RHYTHMDB_PROP_STREAM_SONG_ALBUM,
 
561
                                 G_CALLBACK (db_stream_metadata_cb), plugin, 0);
 
562
 
 
563
        /* hook into shell preferences so we can poke stuff into the general prefs page? */
 
564
 
 
565
        g_object_unref (shell);
 
566
}
 
567
 
 
568
static void
 
569
impl_deactivate (PeasActivatable *bplugin)
 
570
{
 
571
        RBNotificationPlugin *plugin;
 
572
        RBShell *shell;
 
573
 
 
574
        plugin = RB_NOTIFICATION_PLUGIN (bplugin);
 
575
 
 
576
        g_object_get (plugin, "object", &shell, NULL);
 
577
 
 
578
        cleanup_notification (plugin);
 
579
 
 
580
        /* disconnect signal handlers used to update the icon */
 
581
        if (plugin->shell_player != NULL) {
 
582
                g_signal_handlers_disconnect_by_func (plugin->shell_player, playing_entry_changed_cb, plugin);
 
583
 
 
584
                g_object_unref (plugin->shell_player);
 
585
                plugin->shell_player = NULL;
 
586
        }
 
587
 
 
588
        if (plugin->db != NULL) {
 
589
                g_signal_handlers_disconnect_by_func (plugin->db, db_art_uri_metadata_cb, plugin);
 
590
                g_signal_handlers_disconnect_by_func (plugin->db, db_stream_metadata_cb, plugin);
 
591
 
 
592
                g_object_unref (plugin->db);
 
593
                plugin->db = NULL;
 
594
        }
 
595
 
 
596
        g_signal_handlers_disconnect_by_func (shell, shell_notify_playing_cb, plugin);
 
597
        g_signal_handlers_disconnect_by_func (shell, shell_notify_custom_cb, plugin);
 
598
 
 
599
        /* forget what's playing */
 
600
        g_free (plugin->current_title);
 
601
        g_free (plugin->current_album_and_artist);
 
602
        g_free (plugin->notify_art_path);
 
603
        plugin->current_title = NULL;
 
604
        plugin->current_album_and_artist = NULL;
 
605
        plugin->notify_art_path = NULL;
 
606
 
 
607
        g_object_unref (shell);
 
608
}
 
609
 
 
610
static void
 
611
rb_notification_plugin_init (RBNotificationPlugin *plugin)
 
612
{
 
613
}
 
614
 
 
615
G_MODULE_EXPORT void
 
616
peas_register_types (PeasObjectModule *module)
 
617
{
 
618
        rb_notification_plugin_register_type (G_TYPE_MODULE (module));
 
619
        peas_object_module_register_extension_type (module,
 
620
                                                    PEAS_TYPE_ACTIVATABLE,
 
621
                                                    RB_TYPE_NOTIFICATION_PLUGIN);
 
622
}