]> git.sesse.net Git - vlc/blobdiff - modules/services_discovery/upnp_cc.cpp
Fix menu removal of accelerators. This has yet to be more FIXMEd (jpeg :D)
[vlc] / modules / services_discovery / upnp_cc.cpp
index e05900b3fb956cb1e0e327c22363c7528adc33e9..91bec309b29de85bf476278a1a47c17014987484 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Authors: RĂ©mi Denis-Courmont <rem # videolan.org>
  *
- * Based on original wxWindows patch for VLC, and dependant on CyberLink
+ * Based on original wxWindows patch for VLC, and dependent on CyberLink
  * UPnP library from :
  *          Satoshi Konno <skonno@cybergarage.org>
  *
 /*****************************************************************************
  * Includes
  *****************************************************************************/
-#include <stdlib.h>                                      /* malloc(), free() */
 
 #include <cybergarage/upnp/media/player/MediaPlayer.h>
 
 #undef PACKAGE_NAME
-#include <vlc/vlc.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
 #include <vlc_playlist.h>
 
 /* FIXME: thread-safety ?? */
@@ -55,7 +59,7 @@ using namespace CyberLink;
 
 vlc_module_begin();
     set_shortname( "UPnP");
-    set_description( _("Universal Plug'n'Play discovery") );
+    set_description( N_("Universal Plug'n'Play discovery") );
     set_category( CAT_PLAYLIST );
     set_subcategory( SUBCAT_PLAYLIST_SD );
 
@@ -64,17 +68,6 @@ vlc_module_begin();
 
 vlc_module_end();
 
-
-/*****************************************************************************
- * Local structures
- *****************************************************************************/
-
-struct services_discovery_sys_t
-{
-    playlist_item_t *p_node_one;
-    playlist_item_t *p_node_cat;
-};
-
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
@@ -88,15 +81,11 @@ struct services_discovery_sys_t
 static int Open( vlc_object_t *p_this )
 {
     services_discovery_t *p_sd = ( services_discovery_t* )p_this;
-    services_discovery_sys_t *p_sys  = (services_discovery_sys_t *)
-                                malloc( sizeof( services_discovery_sys_t ) );
 
     p_sd->pf_run = Run;
-    p_sd->p_sys  = p_sys;
 
-    playlist_NodesPairCreate( pl_Get( p_sd ), _("Devices"),
-                              &p_sys->p_node_cat, &p_sys->p_node_one,
-                              VLC_TRUE );
+    services_discovery_SetLocalizedName( p_sd, _("Devices") );
+
     return VLC_SUCCESS;
 }
 
@@ -106,15 +95,6 @@ static int Open( vlc_object_t *p_this )
  *****************************************************************************/
 static void Close( vlc_object_t *p_this )
 {
-    services_discovery_t *p_sd = ( services_discovery_t* )p_this;
-    services_discovery_sys_t    *p_sys  = p_sd->p_sys;
-    playlist_t *p_playlist = pl_Yield( p_sd );
-    playlist_NodeDelete( p_playlist, p_sys->p_node_one, VLC_TRUE,
-                         VLC_TRUE );
-    playlist_NodeDelete( p_playlist, p_sys->p_node_cat, VLC_TRUE,
-                         VLC_TRUE );
-    pl_Release();
-    free( p_sys );
 }
 
 /*****************************************************************************
@@ -127,7 +107,6 @@ class UPnPHandler : public MediaPlayer, public DeviceChangeListener,
 {
     private:
         services_discovery_t *p_sd;
-        services_discovery_sys_t *p_sys;
 
         Device *GetDeviceFromUSN( const string& usn )
         {
@@ -136,7 +115,7 @@ class UPnPHandler : public MediaPlayer, public DeviceChangeListener,
 
         playlist_item_t *FindDeviceNode( Device *dev )
         {
-            return playlist_ChildSearchName( p_sys->p_node, dev->getFriendlyName() );
+            return playlist_ChildSearchName( p_sd->p_cat, dev->getFriendlyName() );
         }
 
         playlist_item_t *FindDeviceNode( const string &usn )
@@ -160,7 +139,7 @@ class UPnPHandler : public MediaPlayer, public DeviceChangeListener,
 
     public:
         UPnPHandler( services_discovery_t *p_this )
-            : p_sd( p_this ), p_sys( p_this->p_sys )
+            : p_sd( p_this )
         {
             addDeviceChangeListener( this );
             addSearchResponseListener( this );
@@ -177,7 +156,7 @@ static void Run( services_discovery_t *p_sd )
 
     msg_Dbg( p_sd, "UPnP discovery started" );
     /* read SAP packets */
-    while( !p_sd->b_die )
+    while( vlc_object_alive (p_sd) )
     {
         msleep( 500 );
     }
@@ -206,7 +185,7 @@ playlist_item_t *UPnPHandler::AddDevice( Device *dev )
      */
     char *str = strdup( dev->getFriendlyName( ) );
 
-    p_item = playlist_NodeCreate( p_sys->p_playlist, str, p_sys->p_node_cat,0 );
+    p_item = playlist_NodeCreate( p_playlist, str, p_sd->p_cat, 0, NULL );
     p_item->i_flags &= ~PLAYLIST_SKIP_FLAG;
     msg_Dbg( p_sd, "device %s added", str );
     free( str );
@@ -239,15 +218,18 @@ void UPnPHandler::AddContent( playlist_item_t *p_parent, ContentNode *node )
     {
         ItemNode *iNode = (ItemNode *)node;
         input_item_t *p_input = input_ItemNew( p_sd, iNode->getResource(), title );
-        playlist_BothAddInput( p_sys->p_playlist, p_input, p_parent,
-                               PLAYLIST_APPEND, PLAYLIST_END, NULL, NULL );
+        /* FIXME: playlist_AddInput() can fail */
+        playlist_BothAddInput( p_playlist, p_input, p_parent,
+                               PLAYLIST_APPEND, PLAYLIST_END, NULL, NULL,
+                               false );
+        vlc_gc_decref( p_input );
     } else if ( node->isContainerNode() )
     {
         ContainerNode *conNode = (ContainerNode *)node;
 
         char* p_name = strdup(title); /* See other comment on strdup */
-        playlist_item_t* p_node = playlist_NodeCreate( p_sys->p_playlist,
-                                                       p_name, p_parent, 0 );
+        playlist_item_t* p_node = playlist_NodeCreate( p_playlist, p_name,
+                                                       p_parent, 0, NULL );
         free(p_name);
 
         unsigned nContentNodes = conNode->getNContentNodes();
@@ -263,7 +245,7 @@ void UPnPHandler::RemoveDevice( Device *dev )
     playlist_item_t *p_item = FindDeviceNode( dev );
 
     if( p_item != NULL )
-        playlist_NodeDelete( p_sys->p_playlist, p_item, VLC_TRUE, VLC_TRUE );
+        playlist_NodeDelete( p_playlist, p_item, true, true );
 }