Fix the strings.
[vlc.git] / modules / misc / notify / msn.c
blobdbb63024621cc33cc324d755e5b103e9763a6d17
1 /*****************************************************************************
2 * msn.c : msn title plugin
3 *****************************************************************************
4 * Copyright (C) 2005 the VideoLAN team
5 * $Id$
7 * Authors: Antoine Cellerier <dionoea -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 /*****************************************************************************
25 * Preamble
26 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
29 #include <vlc/vlc.h>
30 #include <vlc_interface.h>
31 #include <vlc_meta.h>
32 #include <vlc_playlist.h>
34 /*****************************************************************************
35 * intf_sys_t: description and status of log interface
36 *****************************************************************************/
37 struct intf_sys_t
39 char *psz_format;
42 /*****************************************************************************
43 * Local prototypes
44 *****************************************************************************/
45 static int Open ( vlc_object_t * );
46 static void Close ( vlc_object_t * );
48 static int ItemChange( vlc_object_t *, const char *,
49 vlc_value_t, vlc_value_t, void * );
50 static int SendToMSN( char * psz_msg );
52 #define MSN_MAX_LENGTH 256
54 /*****************************************************************************
55 * Module descriptor
56 *****************************************************************************
57 * This module should be used on windows with MSN (i think that you need to
58 * have MSN 7 or newer) to "advertise" what you are playing in VLC.
59 * You need to enable the "What I'm Listening To" option in MSN.
60 *****************************************************************************/
61 #define FORMAT_DEFAULT "{0} - {1}"
62 #define FORMAT_TEXT N_("Title format string")
63 #define FORMAT_LONGTEXT N_("Format of the string to send to MSN " \
64 "{0} Artist, {1} Title, {2} Album. Defaults to \"Artist - Title\" ({0} - {1}).")
66 vlc_module_begin();
67 set_category( CAT_INTERFACE );
68 set_subcategory( SUBCAT_INTERFACE_CONTROL );
69 set_shortname( "MSN" );
70 set_description( _("MSN Now-Playing") );
72 add_string( "msn-format", FORMAT_DEFAULT, NULL,
73 FORMAT_TEXT, FORMAT_LONGTEXT, VLC_FALSE );
75 set_capability( "interface", 0 );
76 set_callbacks( Open, Close );
77 vlc_module_end();
79 /*****************************************************************************
80 * Open: initialize and create stuff
81 *****************************************************************************/
82 static int Open( vlc_object_t *p_this )
84 intf_thread_t *p_intf = (intf_thread_t *)p_this;
85 playlist_t *p_playlist;
87 MALLOC_ERR( p_intf->p_sys, intf_sys_t );
89 p_intf->p_sys->psz_format = config_GetPsz( p_intf, "msn-format" );
90 if( !p_intf->p_sys->psz_format )
92 msg_Dbg( p_intf, "no format provided" );
93 p_intf->p_sys->psz_format = strdup( FORMAT_DEFAULT );
95 msg_Dbg( p_intf, "using format: %s", p_intf->p_sys->psz_format );
97 p_playlist = pl_Yield( p_intf );
98 var_AddCallback( p_playlist, "item-change", ItemChange, p_intf );
99 var_AddCallback( p_playlist, "playlist-current", ItemChange, p_intf );
100 pl_Release( p_intf );
102 return VLC_SUCCESS;
105 /*****************************************************************************
106 * Close: destroy interface stuff
107 *****************************************************************************/
108 static void Close( vlc_object_t *p_this )
110 intf_thread_t *p_intf = (intf_thread_t *)p_this;
111 playlist_t *p_playlist = pl_Yield( p_this );
113 /* clear the MSN stuff ... else it looks like we're still playing
114 * something although VLC (or the MSN plugin) is closed */
115 SendToMSN( "\\0Music\\01\\0\\0\\0\\0\\0\\0\\0" );
117 var_DelCallback( p_playlist, "item-change", ItemChange, p_intf );
118 var_DelCallback( p_playlist, "playlist-current", ItemChange, p_intf );
119 pl_Release( p_this );
121 /* Destroy structure */
122 free( p_intf->p_sys->psz_format );
123 free( p_intf->p_sys );
126 /*****************************************************************************
127 * ItemChange: Playlist item change callback
128 *****************************************************************************/
129 static int ItemChange( vlc_object_t *p_this, const char *psz_var,
130 vlc_value_t oldval, vlc_value_t newval, void *param )
132 intf_thread_t *p_intf = (intf_thread_t *)param;
133 char psz_tmp[MSN_MAX_LENGTH];
134 char *psz_title = NULL;
135 char *psz_artist = NULL;
136 char *psz_album = NULL;
137 input_thread_t *p_input;
138 playlist_t *p_playlist = pl_Yield( p_this );
140 p_input = p_playlist->p_input;
141 pl_Release( p_this );
143 if( !p_input ) return VLC_SUCCESS;
144 vlc_object_yield( p_input );
146 if( p_input->b_dead || !input_GetItem(p_input)->psz_name )
148 /* Not playing anything ... */
149 SendToMSN( "\\0Music\\01\\0\\0\\0\\0\\0\\0\\0" );
150 vlc_object_release( p_input );
151 return VLC_SUCCESS;
154 /* Playing something ... */
155 psz_artist = input_GetItem(p_input)->p_meta->psz_artist ?
156 strdup( input_GetItem(p_input)->p_meta->psz_artist ) :
157 strdup( "" );
158 psz_album = input_GetItem(p_input)->p_meta->psz_album ?
159 strdup( input_GetItem(p_input)->p_meta->psz_album ) :
160 strdup( "" );
161 psz_title = strdup( input_GetItem(p_input)->psz_name );
162 if( psz_title == NULL ) psz_title = strdup( N_("(no title)") );
163 if( psz_artist == NULL ) psz_artist = strdup( N_("(no artist)") );
164 if( psz_album == NULL ) psz_album = strdup( N_("(no album)") );
165 snprintf( psz_tmp,
166 MSN_MAX_LENGTH,
167 "\\0Music\\01\\0%s\\0%s\\0%s\\0%s\\0\\0\\0",
168 p_intf->p_sys->psz_format,
169 psz_artist,
170 psz_title,
171 psz_album );
172 free( psz_title );
173 free( psz_artist );
174 free( psz_album );
176 SendToMSN( psz_tmp );
177 vlc_object_release( p_input );
179 return VLC_SUCCESS;
182 /*****************************************************************************
183 * SendToMSN
184 *****************************************************************************/
185 static int SendToMSN( char *psz_msg )
187 COPYDATASTRUCT msndata;
188 HWND msnui = NULL;
190 wchar_t buffer[MSN_MAX_LENGTH];
192 mbstowcs( buffer, psz_msg, MSN_MAX_LENGTH );
194 msndata.dwData = 0x547;
195 msndata.lpData = &buffer;
196 msndata.cbData = (lstrlenW(buffer)*2)+2;
198 while( ( msnui = FindWindowEx( NULL, msnui, "MsnMsgrUIManager", NULL ) ) )
200 SendMessage(msnui, WM_COPYDATA, (WPARAM)NULL, (LPARAM)&msndata);
203 return VLC_SUCCESS;