Use the services_discovery_GetServicesNames() function in the qt4 and wxwidgets ...
authorAntoine Cellerier <dionoea@videolan.org>
Sun, 11 Nov 2007 21:08:36 +0000 (21:08 +0000)
committerAntoine Cellerier <dionoea@videolan.org>
Sun, 11 Nov 2007 21:08:36 +0000 (21:08 +0000)
include/vlc_services_discovery.h
modules/gui/qt4/menus.cpp
modules/gui/wxwidgets/dialogs/playlist.cpp
src/playlist/services_discovery.c

index b2eb0a5..df8b32a 100644 (file)
@@ -62,7 +62,9 @@ struct services_discovery_t
 
 /* Get the services discovery modules names to use in Create(), in a null
  * terminated string array. Array and string must be freed after use. */
-VLC_EXPORT( char **, services_discovery_GetServicesNames, ( vlc_object_t * p_super, char ***pppsz_longnames ) );
+VLC_EXPORT( char **, __services_discovery_GetServicesNames, ( vlc_object_t * p_super, char ***pppsz_longnames ) );
+#define services_discovery_GetServicesNames(a,b) \
+        __services_discovery_GetServicesNames(VLC_OBJECT(a),b)
 
 /* Creation of a service_discovery object */
 VLC_EXPORT( services_discovery_t *, services_discovery_Create, ( vlc_object_t * p_super, const char * psz_service_name ) );
index c68999d..347a560 100644 (file)
@@ -213,15 +213,15 @@ QMenu *QVLCMenu::PlaylistMenu( intf_thread_t *p_intf, MainInterface *mi )
 {
     QMenu *menu = new QMenu();
     menu->addMenu( SDMenu( p_intf ) );
-    menu->addAction ( QIcon( ":/pixmaps/playlist_16px.png" ),
-                      qtr( "Show Playlist" ), mi, SLOT( togglePlaylist() ) );
+    menu->addAction( QIcon( ":/pixmaps/playlist_16px.png" ),
+                     qtr( "Show Playlist" ), mi, SLOT( togglePlaylist() ) );
     menu->addSeparator();
 
     DP_SADD( menu, qtr( I_PL_LOAD ), "", "", openPlaylist(), "Ctrl+X" );
     DP_SADD( menu, qtr( I_PL_SAVE ), "", "", savePlaylist(), "Ctrl+Y" );
     menu->addSeparator();
     menu->addAction( qtr( "Undock from interface" ), mi,
-            SLOT( undockPlaylist() ), qtr( "Ctrl+U" ) );
+                     SLOT( undockPlaylist() ), qtr( "Ctrl+U" ) );
     return menu;
 }
 
@@ -412,45 +412,32 @@ QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf )
 {
     QMenu *menu = new QMenu();
     menu->setTitle( qtr( I_PL_SD ) );
-    vlc_list_t *p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE,
-            FIND_ANYWHERE );
-    int i_num = 0;
-    for( int i_index = 0 ; i_index < p_list->i_count; i_index++ )
-    {
-        module_t * p_parser = ( module_t * )p_list->p_values[i_index].p_object ;
-        if( module_IsCapable( p_parser, "services_discovery" ) )
-            i_num++;
-    }
-    for( int i_index = 0 ; i_index < p_list->i_count; i_index++ )
+    char **ppsz_longnames;
+    char **ppsz_names = services_discovery_GetServicesNames( p_intf,
+                                                             &ppsz_longnames );
+    char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
+    for( ; *ppsz_name; ppsz_name++, ppsz_longname++ )
     {
-        module_t * p_parser = ( module_t * )p_list->p_values[i_index].p_object;
-        if( !module_IsCapable( p_parser, "services_discovery" ) )
-            continue;
-
-        QAction *a = new QAction( qfu( module_GetLongName( p_parser ) ), menu );
+        QAction *a = new QAction( qfu( *ppsz_longname ), menu );
         a->setCheckable( true );
-        /* hack to handle submodules properly */
-        int i = -1;
-        while( p_parser->pp_shortcuts[++i] != NULL );
-        i--;
-        if( playlist_IsServicesDiscoveryLoaded( THEPL,
-                    i>=0?p_parser->pp_shortcuts[i]
-                    : module_GetObjName( p_parser ) ) )
+        if( playlist_IsServicesDiscoveryLoaded( THEPL, *ppsz_name ) )
             a->setChecked( true );
         CONNECT( a , triggered(), THEDP->SDMapper, map() );
-        THEDP->SDMapper->setMapping( a, i>=0? p_parser->pp_shortcuts[i] :
-                                              module_GetObjName( p_parser ) );
+        THEDP->SDMapper->setMapping( a, QString( *ppsz_name ) );
         menu->addAction( a );
 
-        if( !strcmp( p_parser->psz_object_name, "podcast" ) )
+        if( !strcmp( *ppsz_name, "podcast" ) )
         {
             QAction *b = new QAction( qfu( "Configure podcasts..." ), menu );
             //b->setEnabled( a->isChecked() );
             menu->addAction( b );
             CONNECT( b, triggered(), THEDP, podcastConfigureDialog() );
         }
+        free( *ppsz_name );
+        free( *ppsz_longname );
     }
-    vlc_list_release( p_list );
+    free( ppsz_names );
+    free( ppsz_longnames );
     return menu;
 }
 /**
index b0c4cd3..d62cf9e 100644 (file)
@@ -411,7 +411,12 @@ Playlist::Playlist( intf_thread_t *_p_intf, wxWindow *p_parent ):
 
 Playlist::~Playlist()
 {
-    if( pp_sds != NULL ) free( pp_sds );
+    if( pp_sds != NULL )
+    {
+        char **pp_sd = pp_sds;
+        for( ; *pp_sd; pp_sd++ ) free( *pp_sd );
+        free( pp_sds );
+    }
 
     if( p_playlist == NULL ) return;
 
@@ -1400,47 +1405,23 @@ wxMenu *Playlist::SDMenu()
 {
     p_sd_menu = new wxMenu;
 
-    vlc_list_t *p_list = vlc_list_find( p_playlist, VLC_OBJECT_MODULE,
-                                        FIND_ANYWHERE );
-
-    int i_number = 0;
-    for( int i_index = 0; i_index < p_list->i_count; i_index++ )
-    {
-        module_t * p_parser = (module_t *)p_list->p_values[i_index].p_object ;
-
-        if( !strcmp( p_parser->psz_capability, "services_discovery" ) )
-            i_number++;
-    }
-    if( i_number ) pp_sds = (const char **)calloc( i_number, sizeof(void *) );
+    char **ppsz_longnames;
+    char **ppsz_names = services_discovery_GetServicesNames( p_playlist,
+                                                             &ppsz_longnames );
+    char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
 
-    i_number = 0;
-    for( int i_index = 0; i_index < p_list->i_count; i_index++ )
+    for( ; *ppsz_name; ppsz_name++, ppsz_longname++ )
     {
-        module_t * p_parser = (module_t *)p_list->p_values[i_index].p_object ;
+        p_sd_menu->AppendCheckItem( FirstSD_Event + i_number ,
+                                    wxU( *ppsz_longname ) );
 
-        if( !strcmp( p_parser->psz_capability, "services_discovery" ) )
-        {
-            p_sd_menu->AppendCheckItem( FirstSD_Event + i_number ,
-                wxU( p_parser->psz_longname ? p_parser->psz_longname :
-                     (p_parser->psz_shortname ?
-                      p_parser->psz_shortname : p_parser->psz_object_name) ) );
-
-            /* hack to handle submodules properly */
-            int i = -1;
-            while( p_parser->pp_shortcuts[++i] != NULL );
-            i--;
-            if( playlist_IsServicesDiscoveryLoaded( p_playlist,
-                                    i>=0?p_parser->pp_shortcuts[i]
-                                    :p_parser->psz_object_name ) )
-            {
-                p_sd_menu->Check( FirstSD_Event + i_number, TRUE );
-            }
+        if( playlist_IsServicesDiscoveryLoaded( p_playlist, *ppsz_name ) )
+            p_sd_menu->Check( FirstSD_Event + i_number, TRUE );
 
-            pp_sds[i_number++] = i>=0?p_parser->pp_shortcuts[i]
-                                 :p_parser->psz_object_name;
-        }
+        free( *ppsz_longname );
     }
-    vlc_list_release( p_list );
+    pp_sds = ppsz_names;
+    free( ppsz_longnames );
     return p_sd_menu;
 }
 
index 6481598..80ae946 100644 (file)
@@ -37,8 +37,8 @@ static void RunSD( services_discovery_t *p_sd );
 /***********************************************************************
  * GetServicesNames
  ***********************************************************************/
-char ** services_discovery_GetServicesNames( vlc_object_t * p_super,
-                                             char ***pppsz_longnames )
+char ** __services_discovery_GetServicesNames( vlc_object_t * p_super,
+                                               char ***pppsz_longnames )
 {
     return module_GetModulesNamesForCapability( p_super, "services_discovery",
                                                 pppsz_longnames );