2
* * Copyright (C) 2012 Sean Davis <smd.seandavis@gmail.com>
4
* Licensed under the GNU General Public License Version 2
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 Street, Fifth Floor, Boston, MA 02110-1301 USA
28
#include <src/misc/parole.h>
30
#include <libnotify/notify.h>
32
#include "notify-provider.h"
34
#define RESOURCE_FILE "xfce4/src/misc/parole-plugins/notify.rc"
36
static void notify_provider_iface_init (ParoleProviderPluginIface *iface);
37
static void notify_provider_finalize (GObject *object);
40
struct _NotifyProviderClass
42
GObjectClass parent_class;
45
struct _NotifyProvider
48
ParoleProviderPlayer *player;
50
NotifyNotification *notification;
53
PAROLE_DEFINE_TYPE_WITH_CODE (NotifyProvider,
56
PAROLE_IMPLEMENT_INTERFACE (PAROLE_TYPE_PROVIDER_PLUGIN,
57
notify_provider_iface_init));
60
notification_closed_cb (NotifyNotification *n, NotifyProvider *notify)
62
g_object_unref (notify->notification);
63
notify->notification = NULL;
67
close_notification (NotifyProvider *notify)
69
if ( notify->notification )
72
notify_notification_close (notify->notification, &error);
75
g_warning ("Failed to close notification : %s", error->message);
78
g_object_unref (notify->notification);
79
notify->notification = NULL;
84
notify_playing (NotifyProvider *notify, const ParoleStream *stream)
88
gchar *title, *album, *artist, *year;
90
ParoleMediaType media_type;
92
g_object_get (G_OBJECT (stream),
97
"has-video", &has_video,
98
"media-type", &media_type,
108
g_object_get (G_OBJECT (stream),
112
filename = g_filename_from_uri (uri, NULL, NULL);
116
title = g_path_get_basename (filename);
124
album = g_strdup( _("Unknown Album") );
126
artist = g_strdup( _("Unknown Artist") );
129
message = g_strdup_printf ("%s %s\n%s %s", _("<i>on</i>"), album, _("<i>by</i>"), artist);
132
message = g_strdup_printf ("%s %s (%s)\n%s %s", _("<i>on</i>"), album, year, _("<i>by</i>"), artist);
139
#ifdef NOTIFY_CHECK_VERSION
140
#if NOTIFY_CHECK_VERSION (0, 7, 0)
141
notify->notification = notify_notification_new (title, message, NULL);
143
notify->notification = notify_notification_new (title, message, NULL, NULL);
146
notify->notification = notify_notification_new (title, message, NULL, NULL);
151
if (media_type == PAROLE_MEDIA_TYPE_CDDA)
152
pix = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
155
GTK_ICON_LOOKUP_USE_BUILTIN,
158
pix = parole_stream_get_image(G_OBJECT(stream));
161
pix = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
164
GTK_ICON_LOOKUP_USE_BUILTIN,
169
notify_notification_set_icon_from_pixbuf (notify->notification, pix);
170
g_object_unref (pix);
172
notify_notification_set_urgency (notify->notification, NOTIFY_URGENCY_LOW);
173
notify_notification_set_timeout (notify->notification, 5000);
175
notify_notification_show (notify->notification, NULL);
176
g_signal_connect (notify->notification, "closed",
177
G_CALLBACK (notification_closed_cb), notify);
181
state_changed_cb (ParoleProviderPlayer *player, const ParoleStream *stream, ParoleState state, NotifyProvider *notify)
183
if ( state == PAROLE_STATE_PLAYING )
184
notify_playing (notify, stream);
186
else if ( state <= PAROLE_STATE_PAUSED )
187
close_notification (notify);
190
static gboolean notify_provider_is_configurable (ParoleProviderPlugin *plugin)
196
notify_provider_set_player (ParoleProviderPlugin *plugin, ParoleProviderPlayer *player)
198
NotifyProvider *notify;
200
notify = NOTIFY_PROVIDER (plugin);
202
notify->player = player;
204
notify->notification = NULL;
205
notify_init ("parole-notify");
207
g_signal_connect (player, "state_changed",
208
G_CALLBACK (state_changed_cb), notify);
212
notify_provider_iface_init (ParoleProviderPluginIface *iface)
214
iface->get_is_configurable = notify_provider_is_configurable;
215
iface->set_player = notify_provider_set_player;
218
static void notify_provider_class_init (NotifyProviderClass *klass)
220
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
222
gobject_class->finalize = notify_provider_finalize;
225
static void notify_provider_init (NotifyProvider *provider)
227
provider->player = NULL;
230
static void notify_provider_finalize (GObject *object)
232
NotifyProvider *notify;
234
notify = NOTIFY_PROVIDER (object);
236
close_notification (notify);
238
G_OBJECT_CLASS (notify_provider_parent_class)->finalize (object);