]> git.sesse.net Git - vlc/blobdiff - modules/misc/notify/msn.c
Use var_Inherit* instead of var_CreateGet*.
[vlc] / modules / misc / notify / msn.c
index 78db5631f30e11552bd83653c306a15f79ce38cd..7a0d656f5640d8eee4bd352c5bbd256d708474b1 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * msn.c : msn title plugin
  *****************************************************************************
- * Copyright (C) 2005 the VideoLAN team
+ * Copyright (C) 2005-2010 the VideoLAN team
  * $Id$
  *
  * Authors: Antoine Cellerier <dionoea -at- videolan -dot- org>
@@ -35,6 +35,7 @@
 #include <vlc_meta.h>
 #include <vlc_playlist.h>
 #include <vlc_strings.h>
+#include <vlc_charset.h>
 
 /*****************************************************************************
  * intf_sys_t: description and status of log interface
@@ -93,7 +94,7 @@ static int Open( vlc_object_t *p_this )
     if( !p_intf->p_sys )
         return VLC_ENOMEM;
 
-    p_intf->p_sys->psz_format = config_GetPsz( p_intf, "msn-format" );
+    p_intf->p_sys->psz_format = var_InheritString( p_intf, "msn-format" );
     if( !p_intf->p_sys->psz_format )
     {
         msg_Dbg( p_intf, "no format provided" );
@@ -101,10 +102,9 @@ static int Open( vlc_object_t *p_this )
     }
     msg_Dbg( p_intf, "using format: %s", p_intf->p_sys->psz_format );
 
-    p_playlist = pl_Hold( p_intf );
+    p_playlist = pl_Get( p_intf );
     var_AddCallback( p_playlist, "item-change", ItemChange, p_intf );
-    var_AddCallback( p_playlist, "playlist-current", ItemChange, p_intf );
-    pl_Release( p_intf );
+    var_AddCallback( p_playlist, "item-current", ItemChange, p_intf );
 
     return VLC_SUCCESS;
 }
@@ -115,15 +115,14 @@ static int Open( vlc_object_t *p_this )
 static void Close( vlc_object_t *p_this )
 {
     intf_thread_t *p_intf = (intf_thread_t *)p_this;
-    playlist_t *p_playlist = pl_Hold( p_this );
+    playlist_t *p_playlist = pl_Get( p_this );
 
     /* clear the MSN stuff ... else it looks like we're still playing
      * something although VLC (or the MSN plugin) is closed */
     SendToMSN( "\\0Music\\01\\0\\0\\0\\0\\0\\0\\0" );
 
     var_DelCallback( p_playlist, "item-change", ItemChange, p_intf );
-    var_DelCallback( p_playlist, "playlist-current", ItemChange, p_intf );
-    pl_Release( p_this );
+    var_DelCallback( p_playlist, "item-current", ItemChange, p_intf );
 
     /* Destroy structure */
     free( p_intf->p_sys->psz_format );
@@ -139,10 +138,6 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
     (void)psz_var;    (void)oldval;    (void)newval;
     intf_thread_t *p_intf = (intf_thread_t *)param;
     char psz_tmp[MSN_MAX_LENGTH];
-    char *psz_title = NULL;
-    char *psz_artist = NULL;
-    char *psz_album = NULL;
-    char *psz_buf = NULL;
     input_thread_t *p_input =  playlist_CurrentInput( (playlist_t *) p_this );
 
     if( !p_input ) return VLC_SUCCESS;
@@ -156,22 +151,17 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
     }
 
     /* Playing something ... */
-    psz_artist = input_item_GetArtist( input_GetItem( p_input ) );
-    psz_album = input_item_GetAlbum( input_GetItem( p_input ) );
-    psz_title = input_item_GetTitle( input_GetItem( p_input ) );
-    if( !psz_artist ) psz_artist = strdup( "" );
-    if( !psz_album ) psz_album = strdup( "" );
-    if( !psz_title )
-        psz_title = input_item_GetName( input_GetItem( p_input ) );
-
-    psz_buf = str_format_meta( p_this, p_intf->p_sys->psz_format );
+    char *psz_artist = input_item_GetArtist( input_GetItem( p_input ) );
+    char *psz_album = input_item_GetAlbum( input_GetItem( p_input ) );
+    char *psz_title = input_item_GetTitleFbName( input_GetItem( p_input ) );
+    char *psz_buf = str_format_meta( p_intf, p_intf->p_sys->psz_format );
 
     snprintf( psz_tmp,
               MSN_MAX_LENGTH,
               "\\0Music\\01\\0%s\\0%s\\0%s\\0%s\\0\\0\\0",
               psz_buf,
-              psz_artist,
-              psz_title,
+              psz_artist ? psz_artist : "",
+              psz_title ? psz_title : "",
               psz_album );
     free( psz_buf );
     free( psz_title );
@@ -192,18 +182,18 @@ static int SendToMSN( const char *psz_msg )
     COPYDATASTRUCT msndata;
     HWND msnui = NULL;
 
-    wchar_t buffer[MSN_MAX_LENGTH];
-
-    mbstowcs( buffer, psz_msg, MSN_MAX_LENGTH );
+    wchar_t *wmsg = ToWide( psz_msg );
+    if( unlikely(wmsg == NULL) )
+        return VLC_ENOMEM;
 
     msndata.dwData = 0x547;
-    msndata.lpData = &buffer;
-    msndata.cbData = (lstrlenW(buffer)*2)+2;
+    msndata.lpData = wmsg;
+    msndata.cbData = (wcslen(wmsg) + 1) * 2;
 
     while( ( msnui = FindWindowEx( NULL, msnui, "MsnMsgrUIManager", NULL ) ) )
     {
         SendMessage(msnui, WM_COPYDATA, (WPARAM)NULL, (LPARAM)&msndata);
     }
-
+    free( wmsg );
     return VLC_SUCCESS;
 }