1 /*****************************************************************************
2 * notify.c : libnotify notification plugin
3 *****************************************************************************
4 * Copyright (C) 2006 the VideoLAN team
7 * Authors: Christophe Mutricy <xtophe -at- videolan -dot- org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
30 #include <libnotify/notify.h>
36 /*****************************************************************************
38 *****************************************************************************/
39 static int Open ( vlc_object_t * );
40 static void Close ( vlc_object_t * );
41 static void Run ( intf_thread_t * );
43 static int ItemChange( vlc_object_t *, const char *,
44 vlc_value_t, vlc_value_t, void * );
45 static int Notify( vlc_object_t *, const char * );
46 #define MAX_LENGTH 256
48 /*****************************************************************************
50 ****************************************************************************/
53 #define APPLICATION_NAME "VLC media player"
55 #define TIMEOUT_TEXT N_("Timeout (ms)")
56 #define TIMEOUT_LONGTEXT N_("How long the notification will be displayed ")
59 set_category( CAT_INTERFACE );
60 set_subcategory( SUBCAT_INTERFACE_CONTROL );
61 set_shortname( N_( "Notify" ) );
62 set_description( _("LibNotify Notification Plugin") );
64 add_integer( "notify-timeout", 4000,NULL,
65 TIMEOUT_TEXT, TIMEOUT_LONGTEXT, VLC_TRUE );
67 set_capability( "interface", 0 );
68 set_callbacks( Open, Close );
71 /*****************************************************************************
72 * Open: initialize and create stuff
73 *****************************************************************************/
74 static int Open( vlc_object_t *p_this )
76 intf_thread_t *p_intf = (intf_thread_t *)p_this;
77 playlist_t *p_playlist;
79 if( !notify_init( APPLICATION_NAME ) )
81 msg_Err( p_intf, "can't find notification daemon" );
85 p_playlist = pl_Yield( p_intf );
86 var_AddCallback( p_playlist, "playlist-current", ItemChange, p_intf );
93 /*****************************************************************************
94 * Close: destroy interface stuff
95 *****************************************************************************/
96 static void Close( vlc_object_t *p_this )
98 playlist_t *p_playlist = pl_Yield( p_this );
99 var_DelCallback( p_playlist, "playlist-current", ItemChange, p_this );
100 pl_Release( p_this );
105 /*****************************************************************************
107 *****************************************************************************/
108 static void Run( intf_thread_t *p_this )
110 msleep( 10*INTF_IDLE_SLEEP );
113 /*****************************************************************************
114 * ItemChange: Playlist item change callback
115 *****************************************************************************/
116 static int ItemChange( vlc_object_t *p_this, const char *psz_var,
117 vlc_value_t oldval, vlc_value_t newval, void *param )
119 char psz_tmp[MAX_LENGTH];
120 char *psz_title = NULL;
121 char *psz_artist = NULL;
122 char *psz_album = NULL;
123 input_thread_t *p_input=NULL;
124 playlist_t * p_playlist = pl_Yield( p_this );
126 p_input = p_playlist->p_input;
127 vlc_object_release( p_playlist );
129 if( !p_input ) return VLC_SUCCESS;
130 vlc_object_yield( p_input );
132 if( p_input->b_dead || !p_input->input.p_item->psz_name )
134 /* Not playing anything ... */
135 vlc_object_release( p_input );
139 /* Playing something ... */
140 psz_artist = p_input->input.p_item->p_meta->psz_artist ?
141 strdup( p_input->input.p_item->p_meta->psz_artist ) :
142 strdup( _("no artist") );
143 psz_album = p_input->input.p_item->p_meta->psz_album ?
144 strdup( p_input->input.p_item->p_meta->psz_album ) :
145 strdup( _("no album") );
146 psz_title = strdup( p_input->input.p_item->psz_name );
147 if( psz_title == NULL ) psz_title = strdup( N_("(no title)") );
148 snprintf( psz_tmp, MAX_LENGTH, "<b>%s</b>\n%s - %s",
149 psz_title, psz_artist, psz_album );
154 Notify( p_this, psz_tmp );
156 vlc_object_release( p_input );
160 static int Notify( vlc_object_t *p_this, const char *psz_temp )
162 NotifyNotification * notification;
163 notification = notify_notification_new( _("Now Playing"),
165 DATA_PATH "/vlc128x128.png",NULL);
166 notify_notification_set_timeout( notification,
167 config_GetInt(p_this, "notify-timeout") );
168 notify_notification_set_urgency( notification, NOTIFY_URGENCY_LOW );
169 notify_notification_show( notification, NULL);