]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/menus.cpp
Plugins: include vlc_common.h directly instead of vlc/vlc.h
[vlc] / modules / gui / qt4 / menus.cpp
index 0f83f9f9fa0ab2867daae7efd085ff786f2ef596..21c294c09e253c9a278acbd8b22e1dc44ca1fb3e 100644 (file)
@@ -26,7 +26,7 @@
 # include "config.h"
 #endif
 
-#include <vlc/vlc.h>
+#include <vlc_common.h>
 
 #include <vlc_intf_strings.h>
 
@@ -97,14 +97,14 @@ void addMIMStaticEntry( intf_thread_t *p_intf,
  * Definitions of variables for the dynamic menus
  *****************************************************************************/
 #define PUSH_VAR( var ) varnames.push_back( var ); \
-    objects.push_back( p_object->i_object_id )
+    objects.push_back( p_object )
 
 #define PUSH_SEPARATOR if( objects.size() != i_last_separator ) { \
-    objects.push_back( 0 ); varnames.push_back( "" ); \
+    objects.push_back( NULL ); varnames.push_back( "" ); \
     i_last_separator = objects.size(); }
 
 static int InputAutoMenuBuilder( vlc_object_t *p_object,
-        vector<int> &objects,
+        vector<vlc_object_t *> &objects,
         vector<const char *> &varnames )
 {
     PUSH_VAR( "bookmark" );
@@ -117,7 +117,7 @@ static int InputAutoMenuBuilder( vlc_object_t *p_object,
 }
 
 static int VideoAutoMenuBuilder( vlc_object_t *p_object,
-        vector<int> &objects,
+        vector<vlc_object_t *> &objects,
         vector<const char *> &varnames )
 {
     PUSH_VAR( "fullscreen" );
@@ -142,7 +142,7 @@ static int VideoAutoMenuBuilder( vlc_object_t *p_object,
 }
 
 static int AudioAutoMenuBuilder( vlc_object_t *p_object,
-        vector<int> &objects,
+        vector<vlc_object_t *> &objects,
         vector<const char *> &varnames )
 {
     PUSH_VAR( "audio-device" );
@@ -179,13 +179,13 @@ void QVLCMenu::createMenuBar( MainInterface *mi,
     QMenuBar *bar = mi->menuBar();
     BAR_ADD( FileMenu(), qtr( "&Media" ) );
     BAR_ADD( PlaylistMenu( p_intf, mi ), qtr( "&Playlist" ) );
-    BAR_ADD( ToolsMenu( p_intf, mi, visual_selector_enabled, true ),
+    BAR_ADD( ToolsMenu( p_intf, NULL, mi, visual_selector_enabled, true ),
              qtr( "&Tools" ) );
     BAR_DADD( AudioMenu( p_intf, NULL ), qtr( "&Audio" ), 2 );
     BAR_DADD( VideoMenu( p_intf, NULL ), qtr( "&Video" ), 1 );
     BAR_DADD( NavigMenu( p_intf, NULL ), qtr( "&Playback" ), 3 );
 
-    BAR_ADD( HelpMenu(), qtr( "&Help" ) );
+    BAR_ADD( HelpMenu( NULL ), qtr( "&Help" ) );
 }
 #undef BAR_ADD
 #undef BAR_DADD
@@ -249,11 +249,12 @@ QMenu *QVLCMenu::PlaylistMenu( intf_thread_t *p_intf, MainInterface *mi )
  * This menu can be an interface menu but also a right click menu.
  **/
 QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf,
+                            QMenu *current,
                             MainInterface *mi,
                             bool visual_selector_enabled,
                             bool with_intf )
 {
-    QMenu *menu = new QMenu;
+    QMenu *menu = new QMenu( current );
     if( mi )
     {
         menu->addAction( QIcon( ":/pixmaps/playlist_16px.png" ),
@@ -268,7 +269,7 @@ QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf,
 
     if( with_intf )
     {
-        QMenu *intfmenu = InterfacesMenu( p_intf, NULL );
+        QMenu *intfmenu = InterfacesMenu( p_intf, menu );
         intfmenu->setTitle( qtr( "Add Interfaces" ) );
         menu->addMenu( intfmenu );
         menu->addSeparator();
@@ -327,13 +328,14 @@ QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf,
  **/
 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
 {
-    vector<int> objects;
+    vector<vlc_object_t *> objects;
     vector<const char *> varnames;
     /** \todo add "switch to XXX" */
     varnames.push_back( "intf-add" );
-    objects.push_back( p_intf->i_object_id );
+    objects.push_back( VLC_OBJECT(p_intf) );
 
-    QMenu *menu = Populate( p_intf, current, varnames, objects );
+    QMenu *submenu = new QMenu( current );
+    QMenu *menu = Populate( p_intf, submenu, varnames, objects );
 
     CONNECT( menu, aboutToShow(), THEDP->menusUpdateMapper, map() );
     THEDP->menusUpdateMapper->setMapping( menu, 4 );
@@ -345,7 +347,7 @@ QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
  */
 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
 {
-    vector<int> objects;
+    vector<vlc_object_t *> objects;
     vector<const char *> varnames;
 
     vlc_object_t *p_object = ( vlc_object_t * )vlc_object_find( p_intf,
@@ -373,7 +375,7 @@ QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
 {
     vlc_object_t *p_object;
-    vector<int> objects;
+    vector<vlc_object_t *> objects;
     vector<const char *> varnames;
 
     p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_INPUT,
@@ -399,10 +401,10 @@ QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
  * Navigation Menu
  * For DVD, MP4, MOV and other chapter based format
  **/
-QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *navMenu )
+QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
 {
     vlc_object_t *p_object;
-    vector<int> objects;
+    vector<vlc_object_t *> objects;
     vector<const char *> varnames;
 
     p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_INPUT,
@@ -414,7 +416,7 @@ QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *navMenu )
         PUSH_VAR( "prev-chapter" ); PUSH_VAR( "next-chapter" );
         vlc_object_release( p_object );
     }
-    navMenu = new QMenu();
+    QMenu *navMenu = new QMenu( menu );
     addDPStaticEntry( navMenu, qtr( I_MENU_GOTOTIME ), "","",
         SLOT( gotoTimeDialog() ), "Ctrl+T" );
     navMenu->addSeparator();
@@ -462,9 +464,9 @@ QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf )
 /**
  * Help/About Menu
 **/
-QMenu *QVLCMenu::HelpMenu()
+QMenu *QVLCMenu::HelpMenu( QMenu *current )
 {
-    QMenu *menu = new QMenu();
+    QMenu *menu = new QMenu( current );
     addDPStaticEntry( menu, qtr( "Help..." ) , "",
         ":/pixmaps/menus_help_16px.png", SLOT( helpDialog() ), "F1" );
 #ifdef UPDATE_CHECK
@@ -482,7 +484,7 @@ QMenu *QVLCMenu::HelpMenu()
  *****************************************************************************/
 #define POPUP_BOILERPLATE \
     unsigned int i_last_separator = 0; \
-    vector<int> objects; \
+    vector<vlc_object_t *> objects; \
     vector<const char *> varnames; \
     input_thread_t *p_input = THEMIM->getInput();
 
@@ -508,7 +510,7 @@ void QVLCMenu::PopupMenuControlEntries( QMenu *menu,
             addMIMStaticEntry( p_intf, menu, qtr( "Play" ), "",
                     ":/pixmaps/play_16px.png", SLOT( togglePlayPause() ) );
     }
-    else if( THEPL->items.i_size && THEPL->i_enabled )
+    else if( THEPL->items.i_size )
         addMIMStaticEntry( p_intf, menu, qtr( "Play" ), "",
                 ":/pixmaps/play_16px.png", SLOT( togglePlayPause() ) );
 
@@ -522,11 +524,11 @@ void QVLCMenu::PopupMenuControlEntries( QMenu *menu,
 
 void QVLCMenu::PopupMenuStaticEntries( intf_thread_t *p_intf, QMenu *menu )
 {
-    QMenu *toolsmenu = ToolsMenu( p_intf, NULL, false, true );
+    QMenu *toolsmenu = ToolsMenu( p_intf, menu, false, true );
     toolsmenu->setTitle( qtr( "Tools" ) );
     menu->addMenu( toolsmenu );
 
-    QMenu *openmenu = new QMenu( qtr( "Open" ) );
+    QMenu *openmenu = new QMenu( qtr( "Open" ), menu );
     openmenu->addAction( qtr( "Open &File..." ), THEDP,
                          SLOT( openFileDialog() ) );
     openmenu->addAction( qtr( "Open &Disc..." ), THEDP,
@@ -538,7 +540,7 @@ void QVLCMenu::PopupMenuStaticEntries( intf_thread_t *p_intf, QMenu *menu )
     menu->addMenu( openmenu );
 
     menu->addSeparator();
-    QMenu *helpmenu = HelpMenu();
+    QMenu *helpmenu = HelpMenu( menu );
     helpmenu->setTitle( qtr( "Help" ) );
     menu->addMenu( helpmenu );
 
@@ -553,9 +555,9 @@ void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
     {
         vlc_object_yield( p_input );
         varnames.push_back( "video-es" );
-        objects.push_back( p_input->i_object_id );
+        objects.push_back( VLC_OBJECT(p_input) );
         varnames.push_back( "spu-es" );
-        objects.push_back( p_input->i_object_id );
+        objects.push_back( VLC_OBJECT(p_input) );
         vlc_object_t *p_vout = ( vlc_object_t * )vlc_object_find( p_input,
                 VLC_OBJECT_VOUT, FIND_CHILD );
         if( p_vout )
@@ -577,7 +579,7 @@ void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
     {
         vlc_object_yield( p_input );
         varnames.push_back( "audio-es" );
-        objects.push_back( p_input->i_object_id );
+        objects.push_back( VLC_OBJECT(p_input) );
         vlc_object_t *p_aout = ( vlc_object_t * )vlc_object_find( p_input,
                 VLC_OBJECT_AOUT, FIND_ANYWHERE );
         if( p_aout )
@@ -636,7 +638,7 @@ void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
                 /* Audio menu */
                 PUSH_SEPARATOR;
                 varnames.push_back( "audio-es" );
-                objects.push_back( p_input->i_object_id );
+                objects.push_back( VLC_OBJECT(p_input) );
                 vlc_object_t *p_aout = ( vlc_object_t * )
                     vlc_object_find( p_input, VLC_OBJECT_AOUT, FIND_ANYWHERE );
                 if( p_aout )
@@ -648,9 +650,9 @@ void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
                 /* Video menu */
                 PUSH_SEPARATOR;
                 varnames.push_back( "video-es" );
-                objects.push_back( p_input->i_object_id );
+                objects.push_back( VLC_OBJECT(p_input) );
                 varnames.push_back( "spu-es" );
-                objects.push_back( p_input->i_object_id );
+                objects.push_back( VLC_OBJECT(p_input) );
                 vlc_object_t *p_vout = ( vlc_object_t * )
                     vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD );
                 if( p_vout )
@@ -658,6 +660,8 @@ void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
                     VideoAutoMenuBuilder( p_vout, objects, varnames );
                     vlc_object_release( p_vout );
                 }
+
+                vlc_object_release( p_input );
             }
 
             QMenu *menu = new QMenu();
@@ -730,7 +734,7 @@ void QVLCMenu::updateSystrayMenu( MainInterface *mi,
 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf,
                             QMenu *current,
                             vector< const char *> & varnames,
-                            vector<int> & objects,
+                            vector<vlc_object_t *> & objects,
                             bool append )
 {
     QMenu *menu = current;
@@ -759,15 +763,7 @@ QMenu * QVLCMenu::Populate( intf_thread_t *p_intf,
             continue;
         }
 
-        if( objects[i] == 0 )
-        {
-            /// \bug What is this ?
-            // Append( menu, varnames[i], NULL );
-            b_section_empty = false;
-            continue;
-        }
-
-        p_object = ( vlc_object_t * )vlc_object_get( objects[i] );
+        p_object = objects[i];
         if( p_object == NULL ) continue;
 
         b_section_empty = false;
@@ -776,7 +772,6 @@ QMenu * QVLCMenu::Populate( intf_thread_t *p_intf,
             CreateItem( menu, varnames[i], p_object, false );
         else
             CreateItem( menu, varnames[i], p_object, true );
-        vlc_object_release( p_object );
     }
 
     /* Special case for empty menus */
@@ -869,7 +864,7 @@ void QVLCMenu::CreateItem( QMenu *menu, const char *psz_var,
         /* Append choices menu */
         if( b_submenu )
         {
-            QMenu *submenu = new QMenu();
+            QMenu *submenu = new QMenu( menu );
             submenu->setTitle( qfu( text.psz_string ?
                         text.psz_string : psz_var ) );
             if( CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0 )
@@ -888,14 +883,14 @@ void QVLCMenu::CreateItem( QMenu *menu, const char *psz_var,
         case VLC_VAR_VOID:
             var_Get( p_object, psz_var, &val );
             CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
-                    p_object->i_object_id, val, i_type );
+                    p_object, val, i_type );
             break;
 
         case VLC_VAR_BOOL:
             var_Get( p_object, psz_var, &val );
             val.b_bool = !val.b_bool;
             CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
-                    p_object->i_object_id, val, i_type, !val.b_bool );
+                    p_object, val, i_type, !val.b_bool );
             break;
     }
     FREENULL( text.psz_string );
@@ -943,7 +938,7 @@ int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
     {
         vlc_value_t another_val;
         QString menutext;
-        QMenu *subsubmenu = new QMenu();
+        QMenu *subsubmenu = new QMenu( submenu );
 
         switch( i_type & VLC_VAR_TYPE )
         {
@@ -958,7 +953,7 @@ int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
                 another_val.psz_string = strdup( CURVAL.psz_string );
                 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
                 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
-                        p_object->i_object_id, another_val, i_type,
+                        p_object, another_val, i_type,
                         NOTCOMMAND && val.psz_string &&
                         !strcmp( val.psz_string, CURVAL.psz_string ) );
 
@@ -970,7 +965,7 @@ int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
                 if( CURTEXT ) menutext = qfu( CURTEXT );
                 else menutext.sprintf( "%d", CURVAL.i_int );
                 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
-                        p_object->i_object_id, CURVAL, i_type,
+                        p_object, CURVAL, i_type,
                         NOTCOMMAND && CURVAL.i_int == val.i_int );
                 break;
 
@@ -979,7 +974,7 @@ int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
                 if( CURTEXT ) menutext = qfu( CURTEXT );
                 else menutext.sprintf( "%.2f", CURVAL.f_float );
                 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
-                        p_object->i_object_id, CURVAL, i_type,
+                        p_object, CURVAL, i_type,
                         NOTCOMMAND && CURVAL.f_float == val.f_float );
                 break;
 
@@ -1001,7 +996,7 @@ int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
 
 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
         QString text, QString help,
-        int i_item_type, int i_object_id,
+        int i_item_type, vlc_object_t *object,
         vlc_value_t val, int i_val_type,
         bool checked )
 {
@@ -1025,7 +1020,7 @@ void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
     {
         action->setChecked( true );
     }
-    MenuItemData *itemData = new MenuItemData( i_object_id, i_val_type,
+    MenuItemData *itemData = new MenuItemData( object, i_val_type,
             val, psz_var );
     CONNECT( action, triggered(), THEDP->menusMapper, map() );
     THEDP->menusMapper->setMapping( action, itemData );
@@ -1035,10 +1030,6 @@ void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
 void QVLCMenu::DoAction( intf_thread_t *p_intf, QObject *data )
 {
     MenuItemData *itemData = qobject_cast<MenuItemData *>( data );
-    vlc_object_t *p_object = ( vlc_object_t * )vlc_object_get( itemData->i_object_id );
-    if( p_object == NULL ) return;
-
-    var_Set( p_object, itemData->psz_var, itemData->val );
-    vlc_object_release( p_object );
+    var_Set( itemData->obj, itemData->psz_var, itemData->val );
 }