1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2006-2007 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Jean-Baptiste Kempf <jb@videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
29 #include <vlc_intf_strings.h>
31 #include "main_interface.hpp"
33 #include "dialogs_provider.hpp"
34 #include "input_manager.hpp"
39 #include <QActionGroup>
40 #include <QSignalMapper>
41 #include <QSystemTrayIcon>
50 static QActionGroup *currentGroup;
52 // Add static entries to menus
53 #define DP_SADD( menu, text, help, icon, slot, shortcut ) \
55 if( strlen( icon ) > 0 ) \
57 if( strlen( shortcut ) > 0 ) \
59 menu->addAction( QIcon( icon ), text, THEDP, SLOT( slot ), \
64 menu->addAction( QIcon( icon ), text, THEDP, SLOT( slot ) );\
69 if( strlen( shortcut ) > 0 ) \
71 menu->addAction( text, THEDP, SLOT( slot ), \
76 menu->addAction( text, THEDP, SLOT( slot ) ); \
80 #define MIM_SADD( menu, text, help, icon, slot ) \
82 if( strlen( icon ) > 0 ) \
84 QAction *action = menu->addAction( text, THEMIM, SLOT( slot ) ); \
85 action->setIcon( QIcon( icon ) ); \
89 menu->addAction( text, THEMIM, SLOT( slot ) ); \
94 /*****************************************************************************
95 * Definitions of variables for the dynamic menus
96 *****************************************************************************/
97 #define PUSH_VAR( var ) varnames.push_back( var ); \
98 objects.push_back( p_object->i_object_id )
100 #define PUSH_SEPARATOR if( objects.size() != i_last_separator ) { \
101 objects.push_back( 0 ); varnames.push_back( "" ); \
102 i_last_separator = objects.size(); }
104 static int InputAutoMenuBuilder( vlc_object_t *p_object,
105 vector<int> &objects,
106 vector<const char *> &varnames )
108 PUSH_VAR( "bookmark");
110 PUSH_VAR ("chapter" );
111 PUSH_VAR( "program" );
112 PUSH_VAR( "navigation" );
113 PUSH_VAR( "dvd_menus" );
117 static int VideoAutoMenuBuilder( vlc_object_t *p_object,
118 vector<int> &objects,
119 vector<const char *> &varnames )
121 PUSH_VAR( "fullscreen" );
123 PUSH_VAR( "deinterlace" );
124 PUSH_VAR( "aspect-ratio" );
126 PUSH_VAR( "video-on-top" );
127 PUSH_VAR( "directx-wallpaper" );
128 PUSH_VAR( "video-snapshot" );
130 vlc_object_t *p_dec_obj = (vlc_object_t *)vlc_object_find( p_object,
133 if( p_dec_obj != NULL )
135 vlc_object_t *p_object = p_dec_obj;
136 PUSH_VAR( "ffmpeg-pp-q" );
137 vlc_object_release( p_dec_obj );
142 static int AudioAutoMenuBuilder( vlc_object_t *p_object,
143 vector<int> &objects,
144 vector<const char *> &varnames )
146 PUSH_VAR( "audio-device" );
147 PUSH_VAR( "audio-channels" );
148 PUSH_VAR( "visual" );
149 PUSH_VAR( "equalizer" );
153 /*****************************************************************************
156 *****************************************************************************/
158 #define BAR_ADD( func, title ) { \
159 QMenu *menu = func; menu->setTitle( title ); bar->addMenu( menu ); }
161 #define BAR_DADD( func, title, id ) { \
162 QMenu *menu = func; menu->setTitle( title ); bar->addMenu( menu ); \
163 MenuFunc *f = new MenuFunc( menu, id ); \
164 CONNECT( menu, aboutToShow(), THEDP->menusUpdateMapper, map() ); \
165 THEDP->menusUpdateMapper->setMapping( menu, f ); }
168 * Main Menu Bar Creation
170 void QVLCMenu::createMenuBar( MainInterface *mi, intf_thread_t *p_intf,
171 bool playlist, bool adv_controls_enabled,
172 bool visual_selector_enabled )
176 * Remove SIGCHLD from the ignored signal the time to initialise
177 * Qt because it call gconf to get the icon theme */
181 sigaddset( &set, SIGCHLD );
182 pthread_sigmask( SIG_UNBLOCK, &set, NULL );
184 QMenuBar *bar = mi->menuBar();
186 pthread_sigmask( SIG_BLOCK, &set, NULL );
188 BAR_ADD( FileMenu(), qtr("&Media") );
191 BAR_ADD( PlaylistMenu( mi,p_intf ), qtr("&Playlist" ) );
193 BAR_ADD( ToolsMenu( p_intf, mi, adv_controls_enabled,
194 visual_selector_enabled ), qtr("&Tools") );
195 BAR_DADD( VideoMenu( p_intf, NULL ), qtr("&Video"), 1 );
196 BAR_DADD( AudioMenu( p_intf, NULL ), qtr("&Audio"), 2 );
197 BAR_DADD( NavigMenu( p_intf, NULL ), qtr("&Navigation"), 3 );
199 BAR_ADD( HelpMenu(), qtr("&Help" ) );
204 * Opening, streaming and quit
206 QMenu *QVLCMenu::FileMenu()
208 QMenu *menu = new QMenu();
209 DP_SADD( menu, qtr("Open &File..." ), "",
210 ":/pixmaps/vlc_file-asym_16px.png", openFileDialog(), "Ctrl+O" );
212 /* Folder vs. Directory */
214 DP_SADD( menu, qtr( "Open Folder..." ), "",
215 ":/pixmaps/vlc_folder-grey_16px.png", openDirDialog(), "Ctrl+F" );
217 DP_SADD( menu, qtr( "Open Directory..." ), "",
218 ":/pixmaps/vlc_folder-grey_16px.png", openDirDialog(), "Ctrl+F" );
221 DP_SADD( menu, qtr("Open &Disc..." ), "", ":/pixmaps/vlc_disc_16px.png",
222 openDiscDialog(), "Ctrl+D" );
223 DP_SADD( menu, qtr("Open &Network..." ), "",
224 ":/pixmaps/vlc_network_16px.png", openNetDialog(), "Ctrl+N" );
225 DP_SADD( menu, qtr("Open &Capture Device..." ), "",
226 ":/pixmaps/vlc_capture-card_16px.png", openCaptureDialog(),
228 menu->addSeparator();
229 DP_SADD( menu, qtr("&Streaming..."), "", ":/pixmaps/vlc_stream_16px.png",
230 openThenStreamingDialogs(), "Ctrl+S" );
231 DP_SADD( menu, qtr("Conve&rt / Save..."), "", "",
232 openThenTranscodingDialogs(), "Ctrl+R" );
233 menu->addSeparator();
234 DP_SADD( menu, qtr("&Quit") , "", ":/pixmaps/vlc_quit_16px.png", quit(),
239 /* Playlist Menu, undocked when playlist is undocked */
240 QMenu *QVLCMenu::PlaylistMenu( MainInterface *mi, intf_thread_t *p_intf )
242 QMenu *menu = new QMenu();
243 menu->addMenu( SDMenu( p_intf ) );
244 menu->addAction ( QIcon(":/pixmaps/vlc_playlist_16px.png"),
245 qtr( "Show Playlist"), mi, SLOT( playlist() ) );
246 menu->addSeparator();
248 DP_SADD( menu, qtr( I_PL_LOAD ), "", "", openPlaylist(), "Ctrl+X" );
249 DP_SADD( menu, qtr( I_PL_SAVE ), "", "", savePlaylist(), "Ctrl+Y" );
250 menu->addSeparator();
251 menu->addAction( qtr("Undock from interface"), mi,
252 SLOT( undockPlaylist() ), qtr("Ctrl+U") );
258 * This is kept in the same menu for now, but could change if it gets much
261 QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf, MainInterface *mi,
262 bool adv_controls_enabled,
263 bool visual_selector_enabled, bool with_intf )
265 QMenu *menu = new QMenu();
268 QMenu *intfmenu = InterfacesMenu( p_intf, NULL );
269 intfmenu->setTitle( qtr("Interfaces" ) );
270 menu->addMenu( intfmenu );
271 menu->addSeparator();
273 DP_SADD( menu, qtr( I_MENU_MSG ), "", ":/pixmaps/vlc_messages_16px.png",
274 messagesDialog(), "Ctrl+M" );
275 DP_SADD( menu, qtr( I_MENU_INFO ) , "", "", mediaInfoDialog(), "Ctrl+J" );
276 DP_SADD( menu, qtr( I_MENU_CODECINFO ) , "", ":/pixmaps/vlc_info_16px.png",
277 mediaCodecDialog(), "Ctrl+I" );
278 DP_SADD( menu, qtr( I_MENU_GOTOTIME ), "","", gotoTimeDialog(), "Ctrl+T" );
279 #if 0 /* Not Implemented yet */
280 DP_SADD( menu, qtr( I_MENU_BOOKMARK ), "","", bookmarksDialog(), "Ctrl+B" );
281 DP_SADD( menu, qtr( I_MENU_VLM ), "","", vlmDialog(), "Ctrl+V" );
284 menu->addSeparator();
287 QAction *adv = menu->addAction( qtr("Advanced controls" ),
288 mi, SLOT( advanced() ) );
289 adv->setCheckable( true );
290 if( adv_controls_enabled ) adv->setChecked( true );
292 menu->addAction( qtr( "Hide Menus..." ), mi, SLOT( toggleMenus() ),
294 menu->addSeparator();
296 #if 0 /* For Visualisations. Not yet working */
297 adv = menu->addAction( qtr("Visualizations selector" ),
298 mi, SLOT( visual() ) );
299 adv->setCheckable( true );
300 if( visual_selector_enabled ) adv->setChecked( true );
302 menu->addAction ( QIcon(":/pixmaps/vlc_playlist_16px.png"),
303 qtr( "Playlist"), mi, SLOT( playlist() ),
306 DP_SADD( menu, qtr( I_MENU_EXT ), "", ":/pixmaps/vlc_settings_16px.png",
307 extendedDialog() , "Ctrl+E" );
309 menu->addSeparator();
310 DP_SADD( menu, qtr("Preferences"), "", ":/pixmaps/vlc_preferences_16px.png",
311 prefsDialog(), "Ctrl+P" );
316 * Interface Sub-Menu, to list extras interface and skins
318 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
321 vector<const char *> varnames;
322 /** \todo add "switch to XXX" */
323 varnames.push_back( "intf-add" );
324 objects.push_back( p_intf->i_object_id );
326 QMenu *menu = Populate( p_intf, current, varnames, objects );
328 if( !p_intf->pf_show_dialog )
330 menu->addSeparator();
331 menu->addAction( qtr("Switch to skins"), THEDP, SLOT( switchToSkins() ),
335 CONNECT( menu, aboutToShow(), THEDP->menusUpdateMapper, map() );
336 THEDP->menusUpdateMapper->setMapping( menu, 4 );
343 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
346 vector<const char *> varnames;
348 vlc_object_t *p_object = (vlc_object_t *)vlc_object_find( p_intf,
349 VLC_OBJECT_INPUT, FIND_ANYWHERE );
350 if( p_object != NULL )
352 PUSH_VAR( "audio-es" );
353 vlc_object_release( p_object );
356 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
360 AudioAutoMenuBuilder( p_object, objects, varnames );
361 vlc_object_release( p_object );
363 return Populate( p_intf, current, varnames, objects );
368 * Subtitles are part of Video.
370 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
372 vlc_object_t *p_object;
374 vector<const char *> varnames;
376 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
378 if( p_object != NULL )
380 PUSH_VAR( "video-es" );
381 PUSH_VAR( "spu-es" );
382 vlc_object_release( p_object );
385 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
387 if( p_object != NULL )
389 VideoAutoMenuBuilder( p_object, objects, varnames );
390 vlc_object_release( p_object );
392 return Populate( p_intf, current, varnames, objects );
397 * For DVD, MP4, MOV and other chapter based format
399 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *current )
401 vlc_object_t *p_object;
403 vector<const char *> varnames;
406 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
408 if( p_object != NULL )
410 InputAutoMenuBuilder( p_object, objects, varnames );
411 PUSH_VAR( "prev-title"); PUSH_VAR ( "next-title" );
412 PUSH_VAR( "prev-chapter"); PUSH_VAR( "next-chapter" );
413 vlc_object_release( p_object );
415 return Populate( p_intf, current, varnames, objects );
419 * Service Discovery Menu
421 QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf )
423 QMenu *menu = new QMenu();
424 menu->setTitle( qtr( I_PL_SD ) );
425 vlc_list_t *p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE,
428 for( int i_index = 0 ; i_index < p_list->i_count; i_index++ )
430 module_t * p_parser = (module_t *)p_list->p_values[i_index].p_object ;
431 if( module_IsCapable( p_parser, "services_discovery" ) )
434 for( int i_index = 0 ; i_index < p_list->i_count; i_index++ )
436 module_t * p_parser = (module_t *)p_list->p_values[i_index].p_object;
437 if( !module_IsCapable( p_parser, "services_discovery" ) )
440 QAction *a = new QAction( qfu( module_GetLongName( p_parser ) ), menu );
441 a->setCheckable( true );
442 /* hack to handle submodules properly */
444 while( p_parser->pp_shortcuts[++i] != NULL );
446 if( playlist_IsServicesDiscoveryLoaded( THEPL,
447 p_parser->pp_shortcuts[i] ?: module_GetObjName( p_parser ) ) )
448 a->setChecked( true );
449 CONNECT( a , triggered(), THEDP->SDMapper, map() );
450 THEDP->SDMapper->setMapping( a, i>=0? p_parser->pp_shortcuts[i] :
451 module_GetObjName( p_parser ) );
452 menu->addAction( a );
454 vlc_list_release( p_list );
460 QMenu *QVLCMenu::HelpMenu()
462 QMenu *menu = new QMenu();
463 DP_SADD( menu, qtr("Help") , "", ":/pixmaps/vlc_help_16px.png",
464 helpDialog(), "F1" );
465 menu->addSeparator();
466 DP_SADD( menu, qtr( I_MENU_ABOUT ), "", "", aboutDialog(), "Ctrl+F1");
471 /*****************************************************************************
472 * Popup menus - Right Click menus *
473 *****************************************************************************/
474 #define POPUP_BOILERPLATE \
475 unsigned int i_last_separator = 0; \
476 vector<int> objects; \
477 vector<const char *> varnames; \
478 input_thread_t *p_input = THEMIM->getInput();
480 #define CREATE_POPUP \
481 QMenu *menu = new QMenu(); \
482 Populate( p_intf, menu, varnames, objects ); \
483 p_intf->p_sys->p_popup_menu = menu; \
484 menu->popup( QCursor::pos() ); \
485 p_intf->p_sys->p_popup_menu = NULL; \
486 i_last_separator = 0;
488 #define POPUP_PLAY_ENTRIES( menu )\
492 var_Get( p_input, "state", &val ); \
493 if( val.i_int == PLAYING_S ) \
494 MIM_SADD( menu, qtr("Pause"), "", ":/pixmaps/vlc_pause_16px.png", \
495 togglePlayPause() ) \
497 MIM_SADD( menu, qtr("Play"), "", ":/pixmaps/vlc_play_16px.png", \
498 togglePlayPause() ) \
500 else if( THEPL->items.i_size && THEPL->i_enabled ) \
501 MIM_SADD( menu, qtr("Play"), "", ":/pixmaps/vlc_play_16px.png", \
502 togglePlayPause() ); \
504 MIM_SADD( menu, qtr("Stop"), "", ":/pixmaps/vlc_stop_16px.png", stop() ); \
505 MIM_SADD( menu, qtr("Previous"), "", ":/pixmaps/vlc_previous_16px.png", \
507 MIM_SADD( menu, qtr("Next"), "", ":/pixmaps/vlc_next_16px.png", next() );
509 #define POPUP_STATIC_ENTRIES \
510 POPUP_PLAY_ENTRIES( menu ); \
512 menu->addSeparator(); \
513 QMenu *intfmenu = InterfacesMenu( p_intf, NULL ); \
514 intfmenu->setTitle( qtr("Interfaces" ) ); \
515 menu->addMenu( intfmenu ); \
517 QMenu *toolsmenu = ToolsMenu( p_intf, NULL, false, false, false ); \
518 toolsmenu->setTitle( qtr("Tools" ) ); \
519 menu->addMenu( toolsmenu ); \
521 QMenu *openmenu = new QMenu( qtr("Open") ); \
522 openmenu->addAction( qtr("Open &File..." ), THEDP, SLOT( openFileDialog() ) ); \
523 openmenu->addAction( qtr("Open &Disc..." ), THEDP, SLOT( openDiscDialog() ) ); \
524 openmenu->addAction( qtr("Open &Network..." ), THEDP, SLOT( openNetDialog() ) ); \
525 openmenu->addAction( qtr("Open &Capture Device..." ), THEDP, \
526 SLOT( openCaptureDialog() ) ); \
527 menu->addMenu( openmenu ); \
529 menu->addSeparator(); \
530 QMenu *helpmenu = HelpMenu(); \
531 helpmenu->setTitle( qtr("Help") ); \
532 menu->addMenu( helpmenu ); \
534 DP_SADD( menu, qtr("Quit"), "", "", quit() , "Ctrl+Q" );
536 /* Video Tracks and Subtitles tracks */
537 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
542 vlc_object_yield( p_input );
543 varnames.push_back( "video-es" );
544 objects.push_back( p_input->i_object_id );
545 varnames.push_back( "spu-es" );
546 objects.push_back( p_input->i_object_id );
547 vlc_object_t *p_vout = (vlc_object_t *)vlc_object_find( p_input,
548 VLC_OBJECT_VOUT, FIND_CHILD );
551 VideoAutoMenuBuilder( p_vout, objects, varnames );
552 vlc_object_release( p_vout );
554 vlc_object_release( p_input );
560 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
565 vlc_object_yield( p_input );
566 varnames.push_back( "audio-es" );
567 objects.push_back( p_input->i_object_id );
568 vlc_object_t *p_aout = (vlc_object_t *)vlc_object_find( p_input,
569 VLC_OBJECT_AOUT, FIND_ANYWHERE );
572 AudioAutoMenuBuilder( p_aout, objects, varnames );
573 vlc_object_release( p_aout );
575 vlc_object_release( p_input );
580 /* Navigation stuff, and general menus (open) */
581 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
586 vlc_object_yield( p_input );
587 varnames.push_back( "audio-es" );
588 InputAutoMenuBuilder( VLC_OBJECT(p_input), objects, varnames );
592 QMenu *menu = new QMenu();
593 Populate( p_intf, menu, varnames, objects );
594 menu->addSeparator();
595 POPUP_STATIC_ENTRIES;
597 p_intf->p_sys->p_popup_menu = menu;
598 menu->popup( QCursor::pos() );
599 p_intf->p_sys->p_popup_menu = NULL;
602 /* Main Menu that sticks everything together */
603 void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
607 // create a popup if there is none
608 if( ! p_intf->p_sys->p_popup_menu )
613 vlc_object_yield( p_input );
614 InputAutoMenuBuilder( VLC_OBJECT(p_input), objects, varnames );
618 varnames.push_back( "video-es" );
619 objects.push_back( p_input->i_object_id );
620 varnames.push_back( "spu-es" );
621 objects.push_back( p_input->i_object_id );
622 vlc_object_t *p_vout = (vlc_object_t *)vlc_object_find( p_input,
623 VLC_OBJECT_VOUT, FIND_CHILD );
626 VideoAutoMenuBuilder( p_vout, objects, varnames );
627 vlc_object_release( p_vout );
631 varnames.push_back( "audio-es" );
632 objects.push_back( p_input->i_object_id );
633 vlc_object_t *p_aout = (vlc_object_t *)vlc_object_find( p_input,
634 VLC_OBJECT_AOUT, FIND_ANYWHERE );
637 AudioAutoMenuBuilder( p_aout, objects, varnames );
638 vlc_object_release( p_aout );
642 QMenu *menu = new QMenu();
643 Populate( p_intf, menu, varnames, objects );
644 menu->addSeparator();
645 POPUP_STATIC_ENTRIES;
647 p_intf->p_sys->p_popup_menu = menu;
649 p_intf->p_sys->p_popup_menu->popup( QCursor::pos() );
653 // destroy popup if there is one
654 delete p_intf->p_sys->p_popup_menu;
655 p_intf->p_sys->p_popup_menu = NULL;
659 /************************************************************************
661 ************************************************************************/
663 void QVLCMenu::updateSystrayMenu( MainInterface *mi,
664 intf_thread_t *p_intf,
665 bool b_force_visible )
669 /* Get the systray menu and clean it */
670 QMenu *sysMenu = mi->getSysTrayMenu();
673 /* Hide / Show VLC and cone */
674 if( mi->isVisible() || b_force_visible )
676 sysMenu->addAction( QIcon( ":/vlc16.png" ),
677 qtr("Hide VLC media player"), mi,
678 SLOT( toggleUpdateSystrayMenu() ) );
682 sysMenu->addAction( QIcon( ":/vlc16.png" ),
683 qtr("Show VLC media player"), mi,
684 SLOT( toggleUpdateSystrayMenu() ) );
687 sysMenu->addSeparator();
688 POPUP_PLAY_ENTRIES( sysMenu );
690 sysMenu->addSeparator();
691 DP_SADD( sysMenu, qtr("&Open Media" ), "",
692 ":/pixmaps/vlc_file-wide_16px.png", openFileDialog(), "" );
693 DP_SADD( sysMenu, qtr("&Quit") , "", ":/pixmaps/vlc_quit_16px.png",
697 mi->getSysTray()->setContextMenu( sysMenu );
701 #undef PUSH_SEPARATOR
704 /*************************************************************************
705 * Builders for automenus
706 *************************************************************************/
707 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf, QMenu *current,
708 vector< const char *> & varnames,
709 vector<int> & objects, bool append )
711 QMenu *menu = current;
719 vlc_object_t *p_object;
720 vlc_bool_t b_section_empty = VLC_FALSE;
723 #define APPEND_EMPTY { QAction *action = menu->addAction( qtr("Empty" ) ); \
724 action->setEnabled( false ); }
726 for( i = 0; i < (int)objects.size() ; i++ )
728 if( !varnames[i] || !*varnames[i] )
730 if( b_section_empty )
732 menu->addSeparator();
733 b_section_empty = VLC_TRUE;
737 if( objects[i] == 0 )
739 /// \bug What is this ?
740 // Append( menu, varnames[i], NULL );
741 b_section_empty = VLC_FALSE;
745 p_object = (vlc_object_t *)vlc_object_get( p_intf,
747 if( p_object == NULL ) continue;
749 b_section_empty = VLC_FALSE;
750 /* Ugly specific stuff */
751 if( strstr(varnames[i], "intf-add" ) )
752 CreateItem( menu, varnames[i], p_object, false );
754 CreateItem( menu, varnames[i], p_object, true );
755 vlc_object_release( p_object );
758 /* Special case for empty menus */
759 if( menu->actions().size() == 0 || b_section_empty )
765 /*****************************************************************************
767 *****************************************************************************/
769 static bool IsMenuEmpty( const char *psz_var, vlc_object_t *p_object,
772 vlc_value_t val, val_list;
773 int i_type, i_result, i;
775 /* Check the type of the object variable */
776 i_type = var_Type( p_object, psz_var );
778 /* Check if we want to display the variable */
779 if( !(i_type & VLC_VAR_HASCHOICE) ) return FALSE;
781 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
782 if( val.i_int == 0 ) return TRUE;
784 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE )
786 /* Very evil hack ! intf-switch can have only one value */
787 if( !strcmp( psz_var, "intf-switch" ) ) return FALSE;
788 if( val.i_int == 1 && b_root ) return TRUE;
792 /* Check children variables in case of VLC_VAR_VARIABLE */
793 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
798 for( i = 0, i_result = TRUE; i < val_list.p_list->i_count; i++ )
800 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
808 /* clean up everything */
809 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
814 void QVLCMenu::CreateItem( QMenu *menu, const char *psz_var,
815 vlc_object_t *p_object, bool b_submenu )
817 vlc_value_t val, text;
820 /* Check the type of the object variable */
821 i_type = var_Type( p_object, psz_var );
823 switch( i_type & VLC_VAR_TYPE )
827 case VLC_VAR_VARIABLE:
829 case VLC_VAR_INTEGER:
833 /* Variable doesn't exist or isn't handled */
837 /* Make sure we want to display the variable */
838 if( IsMenuEmpty( psz_var, p_object ) ) return;
840 /* Get the descriptive name of the variable */
841 var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
843 if( i_type & VLC_VAR_HASCHOICE )
845 /* Append choices menu */
848 QMenu *submenu = new QMenu();
849 submenu->setTitle( qfu( text.psz_string ?
850 text.psz_string : psz_var ) );
851 if( CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0)
852 menu->addMenu( submenu );
855 CreateChoicesMenu( menu, psz_var, p_object, true );
856 FREENULL( text.psz_string );
860 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
862 switch( i_type & VLC_VAR_TYPE )
865 var_Get( p_object, psz_var, &val );
866 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
867 p_object->i_object_id, val, i_type );
871 var_Get( p_object, psz_var, &val );
872 val.b_bool = !val.b_bool;
873 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
874 p_object->i_object_id, val, i_type, !val.b_bool );
877 FREENULL( text.psz_string );
881 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
882 vlc_object_t *p_object, bool b_root )
884 vlc_value_t val, val_list, text_list;
887 /* Check the type of the object variable */
888 i_type = var_Type( p_object, psz_var );
890 /* Make sure we want to display the variable */
891 if( IsMenuEmpty( psz_var, p_object, b_root ) ) return VLC_EGENERIC;
893 switch( i_type & VLC_VAR_TYPE )
897 case VLC_VAR_VARIABLE:
899 case VLC_VAR_INTEGER:
903 /* Variable doesn't exist or isn't handled */
907 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
908 &val_list, &text_list ) < 0 )
912 #define NORMAL_OR_RADIO i_type & VLC_VAR_ISCOMMAND ? ITEM_NORMAL: ITEM_RADIO
913 #define NOTCOMMAND !(i_type & VLC_VAR_ISCOMMAND)
914 #define CURVAL val_list.p_list->p_values[i]
915 #define CURTEXT text_list.p_list->p_values[i].psz_string
917 for( i = 0; i < val_list.p_list->i_count; i++ )
919 vlc_value_t another_val;
921 QMenu *subsubmenu = new QMenu();
923 switch( i_type & VLC_VAR_TYPE )
925 case VLC_VAR_VARIABLE:
926 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
927 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
928 submenu->addMenu( subsubmenu );
932 var_Get( p_object, psz_var, &val );
933 another_val.psz_string = strdup( CURVAL.psz_string );
934 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
935 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
936 p_object->i_object_id, another_val, i_type,
937 NOTCOMMAND && val.psz_string &&
938 !strcmp( val.psz_string, CURVAL.psz_string ) );
940 if( val.psz_string ) free( val.psz_string );
943 case VLC_VAR_INTEGER:
944 var_Get( p_object, psz_var, &val );
945 if( CURTEXT ) menutext = qfu( CURTEXT );
946 else menutext.sprintf( "%d", CURVAL.i_int);
947 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
948 p_object->i_object_id, CURVAL, i_type,
949 NOTCOMMAND && CURVAL.i_int == val.i_int );
953 var_Get( p_object, psz_var, &val );
954 if( CURTEXT ) menutext = qfu( CURTEXT );
955 else menutext.sprintf( "%.2f", CURVAL.f_float );
956 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
957 p_object->i_object_id, CURVAL, i_type,
958 NOTCOMMAND && CURVAL.f_float == val.f_float );
967 /* clean up everything */
968 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
970 #undef NORMAL_OR_RADIO
977 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
978 QString text, QString help,
979 int i_item_type, int i_object_id,
980 vlc_value_t val, int i_val_type,
983 QAction *action = new QAction( text, menu );
984 action->setText( text );
985 action->setToolTip( help );
987 if( i_item_type == ITEM_CHECK )
989 action->setCheckable( true );
991 else if( i_item_type == ITEM_RADIO )
993 action->setCheckable( true );
995 currentGroup = new QActionGroup( menu );
996 currentGroup->addAction( action );
1001 action->setChecked( true );
1003 MenuItemData *itemData = new MenuItemData( i_object_id, i_val_type,
1005 CONNECT( action, triggered(), THEDP->menusMapper, map() );
1006 THEDP->menusMapper->setMapping( action, itemData );
1007 menu->addAction( action );
1010 void QVLCMenu::DoAction( intf_thread_t *p_intf, QObject *data )
1012 MenuItemData *itemData = qobject_cast<MenuItemData *>(data);
1013 vlc_object_t *p_object = (vlc_object_t *)vlc_object_get( p_intf,
1014 itemData->i_object_id );
1015 if( p_object == NULL ) return;
1017 var_Set( p_object, itemData->psz_var, itemData->val );
1018 vlc_object_release( p_object );}