]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/menus.cpp
Advanced controls bar
[vlc] / modules / gui / qt4 / menus.cpp
index d4902f290970bbcf891dc5d9c87fe2e2ac5cd36a..f00454417e118061ee7be7c5c61502bb2a871aba 100644 (file)
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
-#include "menus.hpp"
-#include "dialogs_provider.hpp"
-#include "input_manager.hpp"
 #include <QMenu>
 #include <QMenuBar>
 #include <QAction>
 #include <QActionGroup>
 #include <QSignalMapper>
 
+#include "main_interface.hpp"
+
+#include "menus.hpp"
+#include "dialogs_provider.hpp"
+#include "input_manager.hpp"
+
 enum
 {
     ITEM_NORMAL,
@@ -42,6 +45,7 @@ static QActionGroup *currentGroup;
 // Add static entries to menus
 #define DP_SADD( text, help, icon, slot ) { if( strlen(icon) > 0 ) { QAction *action = menu->addAction( text, THEDP, SLOT( slot ) ); action->setIcon(QIcon(icon));} else { menu->addAction( text, THEDP, SLOT( slot ) ); } }
 #define MIM_SADD( text, help, icon, slot ) { if( strlen(icon) > 0 ) { QAction *action = menu->addAction( text, THEMIM, SLOT( slot ) ); action->setIcon(QIcon(icon));} else { menu->addAction( text, THEMIM, SLOT( slot ) ); } }
+#define PL_SADD
 
 /*****************************************************************************
  * Definitions of variables for the dynamic menus
@@ -66,7 +70,7 @@ static int InputAutoMenuBuilder( vlc_object_t *p_object,
     return VLC_SUCCESS;
 }
 
-static int VideoAutoMenuBuilder( vlc_object_t *p_object, 
+static int VideoAutoMenuBuilder( vlc_object_t *p_object,
                                  vector<int> &objects,
                                  vector<const char *> &varnames )
 {
@@ -84,6 +88,7 @@ static int VideoAutoMenuBuilder( vlc_object_t *p_object,
                                                  FIND_PARENT );
     if( p_dec_obj != NULL )
     {
+        vlc_object_t *p_object = p_dec_obj;
         PUSH_VAR( "ffmpeg-pp-q" );
         vlc_object_release( p_dec_obj );
     }
@@ -105,55 +110,82 @@ static int AudioAutoMenuBuilder( vlc_object_t *p_object,
  * All normal menus
  *****************************************************************************/
 
-void QVLCMenu::createMenuBar( QMenuBar *bar, intf_thread_t *p_intf )
-{
 #define BAR_ADD( func, title ) { \
     QMenu *menu = func; menu->setTitle( title  ); bar->addMenu( menu ); }
 
 #define BAR_DADD( func, title, id ) { \
     QMenu *menu = func; menu->setTitle( title  ); bar->addMenu( menu ); \
     MenuFunc *f = new MenuFunc( menu, id ); \
-    connect( menu, SIGNAL( aboutToShow() ), \
-            THEDP->menusUpdateMapper, SLOT(map()) ); \
+    CONNECT( menu, aboutToShow(), THEDP->menusUpdateMapper, map() ); \
     THEDP->menusUpdateMapper->setMapping( menu, f ); }
 
-    BAR_ADD( FileMenu(), _("File") );
-    BAR_ADD( ToolsMenu( p_intf ), _("Tools") );
-    BAR_DADD( VideoMenu( p_intf, NULL ), _("Video"), 1 );
-    BAR_DADD( AudioMenu( p_intf, NULL ), _("Audio"), 2 );
-    BAR_DADD( NavigMenu( p_intf, NULL ), _("Navigation"), 3 );
+void QVLCMenu::createMenuBar( MainInterface *mi, intf_thread_t *p_intf,
+                              bool playlist, bool adv_controls_enabled )
+{
+    QMenuBar *bar = mi->menuBar();
+    BAR_ADD( FileMenu(), qtr("Media") );
+    if( playlist )
+    {
+        BAR_ADD( PlaylistMenu( mi,p_intf ), qtr("Playlist" ) );
+    }
+    BAR_ADD( ToolsMenu( p_intf, mi, adv_controls_enabled ), qtr("Tools") );
+    BAR_DADD( VideoMenu( p_intf, NULL ), qtr("Video"), 1 );
+    BAR_DADD( AudioMenu( p_intf, NULL ), qtr("Audio"), 2 );
+    BAR_DADD( NavigMenu( p_intf, NULL ), qtr("Navigation"), 3 );
 
-    //    BAR_ADD( HelpMenu(), _("Help" ) );
+    //    BAR_ADD( HelpMenu(), qtr("Help" ) );
 }
-
 QMenu *QVLCMenu::FileMenu()
 {
     QMenu *menu = new QMenu();
-    DP_SADD( _("Quick &Open File...") , "", "", simpleOpenDialog() );
-    DP_SADD( _("&Advanced Open..." ), "", "", openDialog() );
+    DP_SADD( qtr("Quick &Open File...") , "", "", simpleOpenDialog() );
+    DP_SADD( qtr("&Advanced Open..." ), "", "", openDialog() );
+    menu->addSeparator();
+    DP_SADD( qtr("Streaming..."), "", "", streamingDialog() );
+    menu->addSeparator();
+    DP_SADD( qtr("&Quit") , "", "", quit() );
+    return menu;
+}
+
+QMenu *QVLCMenu::PlaylistMenu( MainInterface *mi, intf_thread_t *p_intf )
+{
+    QMenu *menu = new QMenu();
+    menu->addMenu( SDMenu( p_intf ) );
     menu->addSeparator();
-    DP_SADD( _("Streaming..."), "", "", streamingDialog() );
+
+    DP_SADD( qtr( "Open playlist file"), "", "", openPlaylist() );
+//    DP_SADD( qtr( "Save playlist to file" ), "", "", savePlaylist() );
     menu->addSeparator();
-    DP_SADD( _("&Quit") , "", "", quit() );
+    menu->addAction( qtr("Undock from interface"), mi,
+                     SLOT( undockPlaylist() ) );
     return menu;
 }
 
-QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf, bool with_intf )
+QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf, MainInterface *mi,
+                            bool adv_controls_enabled, bool with_intf )
 {
     QMenu *menu = new QMenu();
     if( with_intf )
     {
         QMenu *intfmenu = InterfacesMenu( p_intf, NULL );
-        intfmenu->setTitle( _("Interfaces" ) );
+        intfmenu->setTitle( qtr("Interfaces" ) );
         menu->addMenu( intfmenu );
-        /** \todo ADD EXT GUI HERE */
         menu->addSeparator();
     }
-    DP_SADD( _("Messages" ), "", "", messagesDialog() );
-    DP_SADD( _("Information") , "", "", streaminfoDialog() );
-    DP_SADD( _("Bookmarks"), "", "", bookmarksDialog() );
+    DP_SADD( qtr("Messages" ), "", "", messagesDialog() );
+    DP_SADD( qtr("Information") , "", "", streaminfoDialog() );
+    DP_SADD( qtr("Bookmarks"), "", "", bookmarksDialog() );
+    DP_SADD( qtr("Extended settings"), "","",extendedDialog() );
+    if( mi )
+    {
+        menu->addSeparator();
+        QAction *adv = menu->addAction( qtr("Advanced controls" ),
+                                        mi, SLOT( advanced() ) );
+        adv->setCheckable( true );
+        if( adv_controls_enabled ) adv->setChecked( true );
+    }
     menu->addSeparator();
-    DP_SADD( _("Preferences"), "", "", prefsDialog() );
+    DP_SADD( qtr("Preferences"), "", "", prefsDialog() );
     return menu;
 }
 
@@ -164,10 +196,9 @@ QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
     /** \todo add "switch to XXX" */
     varnames.push_back( "intf-add" );
     objects.push_back( p_intf->i_object_id );
-    
+
     QMenu *menu = Populate( p_intf, current, varnames, objects );
-    connect( menu, SIGNAL( aboutToShow() ),
-             THEDP->menusUpdateMapper, SLOT(map()) );
+    CONNECT( menu, aboutToShow(), THEDP->menusUpdateMapper, map() );
     THEDP->menusUpdateMapper->setMapping( menu, 4 );
 
     return menu;
@@ -241,6 +272,44 @@ QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *current )
     return Populate( p_intf, current, varnames, objects );
 }
 
+QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf )
+{
+    QMenu *menu = new QMenu();
+    menu->setTitle( qtr( "Additional sources" ) );
+    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( !strcmp( p_parser->psz_capability, "services_discovery" ) )
+            i_num++;
+    }
+    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" ) )
+        {
+            QAction *a = new QAction( qfu( p_parser->psz_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] : p_parser->psz_object_name ) )
+            {
+                a->setChecked( true );
+            }
+            CONNECT( a , triggered(), THEDP->SDMapper, map() );
+            THEDP->SDMapper->setMapping( a, i>=0? p_parser->pp_shortcuts[i] :
+                                                  p_parser->psz_object_name );
+            menu->addAction( a );
+        }
+    }
+    vlc_list_release( p_list );
+    return menu;
+}
 
 /*****************************************************************************
  * Popup menus
@@ -261,28 +330,28 @@ QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *current )
 
 #define POPUP_STATIC_ENTRIES \
     vlc_value_t val; \
-    MIM_SADD( _("Stop"), "", "", stop() ); \
-    MIM_SADD( _("Previous"), "", "", prev() ); \
-    MIM_SADD( _("Next"), "", "", next() ); \
+    MIM_SADD( qtr("Stop"), "", "", stop() ); \
+    MIM_SADD( qtr("Previous"), "", "", prev() ); \
+    MIM_SADD( qtr("Next"), "", "", next() ); \
     if( p_input ) \
     { \
         var_Get( p_input, "state", &val ); \
         if( val.i_int == PAUSE_S ) \
-            MIM_SADD( _("Play"), "", "", togglePlayPause() ) \
+            MIM_SADD( qtr("Play"), "", "", togglePlayPause() ) \
         else \
-            MIM_SADD( _("Pause"), "", "", togglePlayPause() ) \
+            MIM_SADD( qtr("Pause"), "", "", togglePlayPause() ) \
     } \
     else if( THEPL->i_size && THEPL->i_enabled ) \
-        MIM_SADD( _("Play"), "", "", togglePlayPause() ) \
+        MIM_SADD( qtr("Play"), "", "", togglePlayPause() ) \
     \
     QMenu *intfmenu = InterfacesMenu( p_intf, NULL ); \
-    intfmenu->setTitle( _("Interfaces" ) ); \
+    intfmenu->setTitle( qtr("Interfaces" ) ); \
     menu->addMenu( intfmenu ); \
     \
-    QMenu *toolsmenu = ToolsMenu( p_intf, false ); \
-    toolsmenu->setTitle( _("Tools" ) ); \
+    QMenu *toolsmenu = ToolsMenu( p_intf, NULL, false, false ); \
+    toolsmenu->setTitle( qtr("Tools" ) ); \
     menu->addMenu( toolsmenu ); \
-     
+
 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
 {
     POPUP_BOILERPLATE;
@@ -413,7 +482,7 @@ QMenu * QVLCMenu::Populate( intf_thread_t *p_intf, QMenu *current,
     vlc_bool_t b_section_empty = VLC_FALSE;
     int i;
 
-#define APPEND_EMPTY { QAction *action = menu->addAction( _("Empty" ) ); \
+#define APPEND_EMPTY { QAction *action = menu->addAction( qtr("Empty" ) ); \
                        action->setEnabled( false ); }
 
     for( i = 0; i < (int)objects.size() ; i++ )
@@ -459,8 +528,6 @@ QMenu * QVLCMenu::Populate( intf_thread_t *p_intf, QMenu *current,
  * Private methods.
  *****************************************************************************/
 
-#define FREE(x) if(x) { free(x);x=NULL;}
-
 static bool IsMenuEmpty( const char *psz_var, vlc_object_t *p_object,
                          bool b_root = TRUE )
 {
@@ -478,7 +545,7 @@ static bool IsMenuEmpty( const char *psz_var, vlc_object_t *p_object,
 
     if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE )
     {
-        /* Very evil hack ! intf-switch can have only one value */ 
+        /* 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;
@@ -541,17 +608,18 @@ void QVLCMenu::CreateItem( QMenu *menu, const char *psz_var,
         if( b_submenu )
         {
             QMenu *submenu = new QMenu();
-            submenu->setTitle( text.psz_string ? text.psz_string : psz_var );
+            submenu->setTitle( qfu( text.psz_string ?
+                                    text.psz_string : psz_var ) );
             if( CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0)
                 menu->addMenu( submenu );
         }
         else
             CreateChoicesMenu( menu, psz_var, p_object, true );
-        FREE( text.psz_string );
+        FREENULL( text.psz_string );
         return;
     }
 
-#define TEXT_OR_VAR text.psz_string ? text.psz_string : psz_var
+#define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
 
     switch( i_type & VLC_VAR_TYPE )
     {
@@ -563,16 +631,15 @@ void QVLCMenu::CreateItem( QMenu *menu, const char *psz_var,
 
     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 );
         break;
     }
-    FREE( text.psz_string );
+    FREENULL( text.psz_string );
 }
 
 
-int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var, 
+int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
                                  vlc_object_t *p_object, bool b_root )
 {
     vlc_value_t val, val_list, text_list;
@@ -604,7 +671,7 @@ int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
         return VLC_EGENERIC;
     }
 #define NORMAL_OR_RADIO i_type & VLC_VAR_ISCOMMAND ? ITEM_NORMAL: ITEM_RADIO
-#define NOTCOMMAND !(i_type & VLC_VAR_ISCOMMAND) 
+#define NOTCOMMAND !(i_type & VLC_VAR_ISCOMMAND)
 #define CURVAL val_list.p_list->p_values[i]
 #define CURTEXT text_list.p_list->p_values[i].psz_string
 
@@ -618,17 +685,16 @@ int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
         {
         case VLC_VAR_VARIABLE:
             CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
-            subsubmenu->setTitle( CURTEXT ? CURTEXT : CURVAL.psz_string );
+            subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
             submenu->addMenu( subsubmenu );
             break;
 
         case VLC_VAR_STRING:
           var_Get( p_object, psz_var, &val );
           another_val.psz_string = strdup( CURVAL.psz_string );
-
-          menutext = CURTEXT ? CURTEXT : another_val.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->i_object_id, another_val, i_type,
                             NOTCOMMAND && val.psz_string &&
                             !strcmp( val.psz_string, CURVAL.psz_string ) );
 
@@ -637,7 +703,7 @@ int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
 
         case VLC_VAR_INTEGER:
           var_Get( p_object, psz_var, &val );
-          if( CURTEXT ) menutext = CURTEXT; 
+          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,
@@ -646,7 +712,7 @@ int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
 
         case VLC_VAR_FLOAT:
           var_Get( p_object, psz_var, &val );
-          if( CURTEXT ) menutext = CURTEXT ;
+          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,
@@ -657,6 +723,7 @@ int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
           break;
         }
     }
+    currentGroup = NULL;
 
     /* clean up everything */
     var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
@@ -670,7 +737,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, int i_object_id,
                                  vlc_value_t val, int i_val_type,
                                  bool checked )
 {
@@ -681,7 +748,6 @@ void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
     if( i_item_type == ITEM_CHECK )
     {
         action->setCheckable( true );
-        currentGroup = NULL;
     }
     else if( i_item_type == ITEM_RADIO )
     {
@@ -690,22 +756,21 @@ void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
             currentGroup = new QActionGroup(menu);
         currentGroup->addAction( action );
     }
-    else
-        currentGroup = NULL;
-    if( checked ) action->setChecked( true );
 
+    if( checked )
+    {
+        action->setChecked( true );
+    }
     MenuItemData *itemData = new MenuItemData( i_object_id, i_val_type,
                                                val, psz_var );
-    connect( action, SIGNAL(triggered()), THEDP->menusMapper, SLOT(map()) ); 
+    CONNECT( action, triggered(), THEDP->menusMapper, map() );
     THEDP->menusMapper->setMapping( action, itemData );
-    
     menu->addAction( action );
 }
 
 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;