]> 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 c6642837343cde16256d26d36909da41a8011da2..21c294c09e253c9a278acbd8b22e1dc44ca1fb3e 100644 (file)
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
-#include <vlc/vlc.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
 
 #include <vlc_intf_strings.h>
 
@@ -50,10 +54,10 @@ static QActionGroup *currentGroup;
 // Add static entries to menus
 void addDPStaticEntry( QMenu *menu,
                        const QString text,
-                       char *help,
-                       char *icon,
+                       const char *help,
+                       const char *icon,
                        const char *member,
-                       char *shortcut )
+                       const char *shortcut )
 {
     if( !EMPTY_STR( icon ) > 0 )
     {
@@ -74,8 +78,8 @@ void addDPStaticEntry( QMenu *menu,
 void addMIMStaticEntry( intf_thread_t *p_intf,
                         QMenu *menu,
                         const QString text,
-                        char *help,
-                        char *icon,
+                        const char *help,
+                        const char *icon,
                         const char *member )
 {
     if( strlen( icon ) > 0 )
@@ -93,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" );
@@ -113,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" );
@@ -138,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" );
@@ -169,15 +173,19 @@ void QVLCMenu::createMenuBar( MainInterface *mi,
                               intf_thread_t *p_intf,
                               bool visual_selector_enabled )
 {
+    /* QMainWindows->menuBar()
+       gives the QProcess::destroyed timeout issue on Cleanlooks style with
+       setDesktopAware set to false */
     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 ), qtr( "&Tools" ) );
+    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
@@ -241,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" ),
@@ -260,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();
@@ -305,7 +314,7 @@ QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf,
                       SLOT( bookmarksDialog() ), "Ctrl+B" );
 #ifdef ENABLE_VLM
     addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", "", SLOT( vlmDialog() ),
-        "Ctrl+V" );
+        "Ctrl+W" );
 #endif
 
     menu->addSeparator();
@@ -319,25 +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 );
-
-    if( !p_intf->pf_show_dialog )
-    {
-        menu->addSeparator();
-        menu->addAction( qtr( "Switch to skins" ), THEDP, SLOT( switchToSkins() ),
-                QString( "Ctrl+Z" ) );
-        if( module_Exists( VLC_OBJECT( p_intf ), "wxwidgets" ) )
-        {
-            menu->addAction( qtr( "Switch to WxWidgets" ), THEDP,
-                    SLOT( switchToWx() ) );
-        }
-    }
+    QMenu *submenu = new QMenu( current );
+    QMenu *menu = Populate( p_intf, submenu, varnames, objects );
 
     CONNECT( menu, aboutToShow(), THEDP->menusUpdateMapper, map() );
     THEDP->menusUpdateMapper->setMapping( menu, 4 );
@@ -349,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,
@@ -377,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,
@@ -403,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,
@@ -418,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();
@@ -435,6 +433,9 @@ QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf )
     char **ppsz_longnames;
     char **ppsz_names = services_discovery_GetServicesNames( p_intf,
                                                              &ppsz_longnames );
+    if( !ppsz_names )
+        return menu;
+
     char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
     for( ; *ppsz_name; ppsz_name++, ppsz_longname++ )
     {
@@ -463,13 +464,13 @@ 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
-    addDPStaticEntry( menu, qtr( "Update" ) , "", "", SLOT( updateDialog() ), "");
+    addDPStaticEntry( menu, qtr( "Check for updates..." ) , "", "", SLOT( updateDialog() ), "");
 #endif
     menu->addSeparator();
     addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), "", "", SLOT( aboutDialog() ),
@@ -483,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();
 
@@ -509,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() ) );
 
@@ -523,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,
@@ -539,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 );
 
@@ -554,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 )
@@ -578,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 )
@@ -637,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 )
@@ -649,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 )
@@ -659,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();
@@ -731,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;
@@ -743,7 +746,7 @@ QMenu * QVLCMenu::Populate( intf_thread_t *p_intf,
     currentGroup = NULL;
 
     vlc_object_t *p_object;
-    vlc_bool_t b_section_empty = VLC_FALSE;
+    bool b_section_empty = false;
     int i;
 
 #define APPEND_EMPTY { QAction *action = menu->addAction( qtr( "Empty" ) ); \
@@ -756,28 +759,19 @@ QMenu * QVLCMenu::Populate( intf_thread_t *p_intf,
             if( b_section_empty )
                 APPEND_EMPTY;
             menu->addSeparator();
-            b_section_empty = VLC_TRUE;
+            b_section_empty = true;
             continue;
         }
 
-        if( objects[i] == 0 )
-        {
-            /// \bug What is this ?
-            // Append( menu, varnames[i], NULL );
-            b_section_empty = VLC_FALSE;
-            continue;
-        }
-
-        p_object = ( vlc_object_t * )vlc_object_get( p_intf, objects[i] );
+        p_object = objects[i];
         if( p_object == NULL ) continue;
 
-        b_section_empty = VLC_FALSE;
+        b_section_empty = false;
         /* Ugly specific stuff */
         if( strstr( varnames[i], "intf-add" ) )
             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 */
@@ -810,8 +804,6 @@ static bool IsMenuEmpty( const char *psz_var,
 
     if( ( i_type & VLC_VAR_TYPE ) != VLC_VAR_VARIABLE )
     {
-        /* Very evil hack ! intf-switch can have only one value */
-        if( !strcmp( psz_var, "intf-switch" ) ) return false;
         if( val.i_int == 1 && b_root ) return true;
         else return false;
     }
@@ -872,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 )
@@ -891,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 );
@@ -946,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 )
         {
@@ -961,11 +953,11 @@ 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 ) );
 
-                if( val.psz_string ) free( val.psz_string );
+                free( val.psz_string );
                 break;
 
             case VLC_VAR_INTEGER:
@@ -973,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;
 
@@ -982,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;
 
@@ -1004,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 )
 {
@@ -1028,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 );
@@ -1038,11 +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( p_intf,
-            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 );
 }