Qt4 - Remove the enqueue button and regroup it under the play button, since it is...
[vlc.git] / modules / services_discovery / upnp_intel.cpp
index 9b81e44..28513d9 100644 (file)
@@ -39,8 +39,7 @@
 
 #undef PACKAGE_NAME
 #include <vlc/vlc.h>
-#include <vlc/intf.h>
-
+#include <vlc_playlist.h>
 #include "vlc_strings.h"
 
 
@@ -48,8 +47,8 @@
 
 struct services_discovery_sys_t
 {
-    playlist_item_t *p_node;
-    playlist_t *p_playlist;
+    playlist_item_t *p_node_cat;
+    playlist_item_t *p_node_one;
 };
 
 
@@ -282,29 +281,13 @@ static int Open( vlc_object_t *p_this )
     services_discovery_sys_t *p_sys  = ( services_discovery_sys_t * )
     malloc( sizeof( services_discovery_sys_t ) );
 
-    playlist_view_t *p_view;
-    vlc_value_t val;
-
     p_sd->pf_run = Run;
     p_sd->p_sys = p_sys;
 
     /* Create our playlist node */
-    p_sys->p_playlist = ( playlist_t * )vlc_object_find( p_sd,
-                             VLC_OBJECT_PLAYLIST,
-                             FIND_ANYWHERE );
-    if( !p_sys->p_playlist )
-    {
-    msg_Warn( p_sd, "unable to find playlist, cancelling UPnP listening" );
-    return VLC_EGENERIC;
-    }
-
-    p_view = playlist_ViewFind( p_sys->p_playlist, VIEW_CATEGORY );
-    p_sys->p_node = playlist_NodeCreate( p_sys->p_playlist, VIEW_CATEGORY,
-                                         "UPnP", p_view->p_root );
-    p_sys->p_node->i_flags |= PLAYLIST_RO_FLAG;
-    p_sys->p_node->i_flags &= ~PLAYLIST_SKIP_FLAG;
-    val.b_bool = VLC_TRUE;
-    var_Set( p_sys->p_playlist, "intf-change", val );
+    playlist_NodesPairCreate( pl_Get( p_sd ), _("Devices"),
+                              &p_sys->p_node_cat, &p_sys->p_node_one,
+                              VLC_TRUE );
 
     return VLC_SUCCESS;
 }
@@ -314,12 +297,10 @@ 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;
 
-    if( p_sys->p_playlist )
-    {
-    playlist_NodeDelete( p_sys->p_playlist, p_sys->p_node, VLC_TRUE,
-                 VLC_TRUE );
-    vlc_object_release( p_sys->p_playlist );
-    }
+    playlist_NodeDelete( pl_Get( p_sd ), p_sys->p_node_one, VLC_TRUE,
+                         VLC_TRUE );
+    playlist_NodeDelete( pl_Get( p_sd ), p_sys->p_node_cat, VLC_TRUE,
+                         VLC_TRUE );
 
     free( p_sys );
 }
@@ -331,8 +312,8 @@ static void Run( services_discovery_t* p_sd )
     res = UpnpInit( 0, 0 );
     if( res != UPNP_E_SUCCESS )
     {
-    msg_Err( p_sd, "%s", UpnpGetErrorMessage( res ) );
-    return;
+        msg_Err( p_sd, "%s", UpnpGetErrorMessage( res ) );
+        return;
     }
 
     Cookie cookie;
@@ -344,21 +325,21 @@ static void Run( services_discovery_t* p_sd )
     res = UpnpRegisterClient( Callback, &cookie, &cookie.clientHandle );
     if( res != UPNP_E_SUCCESS )
     {
-    msg_Err( p_sd, "%s", UpnpGetErrorMessage( res ) );
-    goto shutDown;
+        msg_Err( p_sd, "%s", UpnpGetErrorMessage( res ) );
+        goto shutDown;
     }
 
     res = UpnpSearchAsync( cookie.clientHandle, 5, MEDIA_SERVER_DEVICE_TYPE, &cookie );
     if( res != UPNP_E_SUCCESS )
     {
-    msg_Err( p_sd, "%s", UpnpGetErrorMessage( res ) );
-    goto shutDown;
+        msg_Err( p_sd, "%s", UpnpGetErrorMessage( res ) );
+        goto shutDown;
     }
 
     msg_Dbg( p_sd, "UPnP discovery started" );
     while( !p_sd->b_die )
     {
-    msleep( 500 );
+        msleep( 500 );
     }
 
     msg_Dbg( p_sd, "UPnP discovery stopped" );
@@ -411,7 +392,9 @@ IXML_Document* parseBrowseResult( IXML_Document* doc )
     if ( !textNode ) return 0;
 
     const char* resultString = ixmlNode_getNodeValue( textNode );
-    char* resultXML = convert_xml_special_chars( resultString );
+    char* resultXML = strdup( resultString );
+
+    resolve_xml_special_chars( resultXML );
 
     IXML_Document* browseDoc = ixmlParseBuffer( resultXML );
 
@@ -480,6 +463,14 @@ static int Callback( Upnp_EventType eventType, void* event, void* pCookie )
     }
     break;
 
+    case UPNP_EVENT_SUBSCRIBE_COMPLETE:
+        msg_Warn( cookie->serviceDiscovery, "subscription complete" );
+        break;
+        
+    case UPNP_DISCOVERY_SEARCH_TIMEOUT:
+        msg_Warn( cookie->serviceDiscovery, "search timeout" );
+        break;
+        
     default:
     msg_Dbg( cookie->serviceDiscovery, "%s:%d: DEBUG: UNHANDLED EVENT ( TYPE=%d )", __FILE__, __LINE__, eventType );
     break;
@@ -628,10 +619,8 @@ MediaServer::~MediaServer()
 {
     if ( _contents )
     {
-    playlist_NodeDelete( _cookie->serviceDiscovery->p_sys->p_playlist,
-                _playlistNode,
-                true,
-                true );
+        playlist_NodeDelete( pl_Get( _cookie->serviceDiscovery ) ,
+                             _playlistNode, VLC_TRUE, VLC_TRUE );
     }
 
     delete _contents;
@@ -764,19 +753,15 @@ IXML_Document* MediaServer::_browseAction( const char* pObjectID, const char* pB
 void MediaServer::fetchContents()
 {
     Container* root = new Container( 0, "0", getFriendlyName() );
+    playlist_t * p_playlist = pl_Get( _cookie->serviceDiscovery );
     _fetchContents( root );
 
     if ( _contents )
     {
-    vlc_mutex_lock( &_cookie->serviceDiscovery->p_sys->p_playlist->object_lock );
-
-    playlist_NodeEmpty( _cookie->serviceDiscovery->p_sys->p_playlist,
-               _playlistNode,
-               true );
-
-    vlc_mutex_unlock( &_cookie->serviceDiscovery->p_sys->p_playlist->object_lock );
-
-    delete _contents;
+        PL_LOCK;
+        playlist_NodeEmpty( p_playlist, _playlistNode, VLC_TRUE );
+        PL_UNLOCK;
+        delete _contents;
     }
 
     _contents = root;
@@ -862,37 +847,36 @@ bool MediaServer::_fetchContents( Container* parent )
 
 void MediaServer::_buildPlaylist( Container* parent )
 {
+    playlist_t *p_playlist = pl_Get( _cookie->serviceDiscovery );
     for ( unsigned int i = 0; i < parent->getNumContainers(); i++ )
     {
-    Container* container = parent->getContainer( i );
-    playlist_item_t* parentNode = parent->getPlaylistNode();
-
-    char* title = strdup( container->getTitle() );
-    playlist_item_t* node = playlist_NodeCreate( _cookie->serviceDiscovery->p_sys->p_playlist,
-                             VIEW_CATEGORY,
-                             title,
-                             parentNode );
-    free( title );
-
-    container->setPlaylistNode( node );
-    _buildPlaylist( container );
+        Container* container = parent->getContainer( i );
+        playlist_item_t* parentNode = parent->getPlaylistNode();
+
+        char* title = strdup( container->getTitle() );
+        playlist_item_t* node = playlist_NodeCreate( p_playlist, title, parentNode, 0 );
+        free( title );
+
+        container->setPlaylistNode( node );
+        _buildPlaylist( container );
     }
 
     for ( unsigned int i = 0; i < parent->getNumItems(); i++ )
     {
-    Item* item = parent->getItem( i );
-    playlist_item_t* parentNode = parent->getPlaylistNode();
-
-    playlist_item_t* node = playlist_ItemNew( _cookie->serviceDiscovery,
-                         item->getResource(),
-                         item->getTitle() );
-
-    playlist_NodeAddItem( _cookie->serviceDiscovery->p_sys->p_playlist,
-                 node,
-                 VIEW_CATEGORY,
-                 parentNode, PLAYLIST_APPEND, PLAYLIST_END );
-
-    item->setPlaylistNode( node );
+        Item* item = parent->getItem( i );
+        playlist_item_t* parentNode = parent->getPlaylistNode();
+
+        input_item_t* p_input = input_ItemNew( _cookie->serviceDiscovery,
+                                               item->getResource(),
+                                               item->getTitle() );
+        int i_cat;
+        playlist_BothAddInput( p_playlist, p_input, parentNode,
+                               PLAYLIST_APPEND, PLAYLIST_END, &i_cat, NULL,
+                               VLC_FALSE );
+        /* TODO: do this better by storing ids */
+        playlist_item_t *p_node = playlist_ItemGetById( p_playlist, i_cat, VLC_FALSE );
+        assert( p_node );
+        item->setPlaylistNode( p_node );
     }
 }
 
@@ -931,10 +915,9 @@ bool MediaServerList::addServer( MediaServer* s )
     _list.push_back( s );
 
     char* name = strdup( s->getFriendlyName() );
-    playlist_item_t* node = playlist_NodeCreate( _cookie->serviceDiscovery->p_sys->p_playlist,
-                        VIEW_CATEGORY,
-                        name,
-                        _cookie->serviceDiscovery->p_sys->p_node );
+    playlist_item_t* node = playlist_NodeCreate( pl_Get( _cookie->serviceDiscovery ),
+                                                 name,
+                                          _cookie->serviceDiscovery->p_sys->p_node_cat, 0 );
     free( name );
     s->setPlaylistNode( node );