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..." ), "", "", openDiscDialog(), "Ctrl+D" );
222 DP_SADD( menu, qtr("Open &Network..." ), "",
223 ":/pixmaps/vlc_network_16px.png", openNetDialog(), "Ctrl+N" );
224 DP_SADD( menu, qtr("Open &Capture Device..." ), "",
225 ":/pixmaps/vlc_capture-card_16px.png", openCaptureDialog(),
227 menu->addSeparator();
228 DP_SADD( menu, qtr("&Streaming..."), "", ":/pixmaps/vlc_stream_16px.png",
229 openThenStreamingDialogs(), "Ctrl+S" );
230 DP_SADD( menu, qtr("Conve&rt / Save..."), "", "",
231 openThenTranscodingDialogs(), "Ctrl+R" );
232 menu->addSeparator();
233 DP_SADD( menu, qtr("&Quit") , "", ":/pixmaps/vlc_quit_16px.png", quit(),
238 /* Playlist Menu, undocked when playlist is undocked */
239 QMenu *QVLCMenu::PlaylistMenu( MainInterface *mi, intf_thread_t *p_intf )
241 QMenu *menu = new QMenu();
242 menu->addMenu( SDMenu( p_intf ) );
243 menu->addSeparator();
245 DP_SADD( menu, qtr( I_PL_LOAD ), "", "", openPlaylist(), "Ctrl+L" );
246 DP_SADD( menu, qtr( I_PL_SAVE ), "", "", savePlaylist(), "Ctrl+K" );
247 menu->addSeparator();
248 menu->addAction( qtr("Undock from interface"), mi,
249 SLOT( undockPlaylist() ), qtr("Ctrl+U") );
255 * This is kept in the same menu for now, but could change if it gets much
258 QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf, MainInterface *mi,
259 bool adv_controls_enabled,
260 bool visual_selector_enabled, bool with_intf )
262 QMenu *menu = new QMenu();
265 QMenu *intfmenu = InterfacesMenu( p_intf, NULL );
266 intfmenu->setTitle( qtr("Interfaces" ) );
267 menu->addMenu( intfmenu );
268 menu->addSeparator();
270 DP_SADD( menu, qtr( I_MENU_MSG ), "", ":/pixmaps/vlc_messages_16px.png",
271 messagesDialog(), "Ctrl+M" );
272 DP_SADD( menu, qtr( I_MENU_INFO ) , "", "", mediaInfoDialog(), "Ctrl+J" );
273 DP_SADD( menu, qtr( I_MENU_CODECINFO ) , "", ":/pixmaps/vlc_info_16px.png",
274 mediaCodecDialog(), "Ctrl+I" );
275 DP_SADD( menu, qtr( I_MENU_GOTOTIME ), "","", gotoTimeDialog(), "Ctrl+T" );
276 #if 0 /* Not Implemented yet */
277 DP_SADD( menu, qtr( I_MENU_BOOKMARK ), "","", bookmarksDialog(), "Ctrl+B" );
278 DP_SADD( menu, qtr( I_MENU_VLM ), "","", vlmDialog(), "Ctrl+V" );
281 menu->addSeparator();
284 QAction *adv = menu->addAction( qtr("Advanced controls" ),
285 mi, SLOT( advanced() ) );
286 adv->setCheckable( true );
287 if( adv_controls_enabled ) adv->setChecked( true );
288 #if 0 /* For Visualisations. Not yet working */
289 adv = menu->addAction( qtr("Visualizations selector" ),
290 mi, SLOT( visual() ) );
291 adv->setCheckable( true );
292 if( visual_selector_enabled ) adv->setChecked( true );
294 menu->addAction ( qtr( "Playlist"), mi, SLOT( playlist() ) );
296 DP_SADD( menu, qtr( I_MENU_EXT ), "","",extendedDialog(), "Ctrl+E" );
297 DP_SADD( menu, qtr( "Hide Menus..." ), "","",hideMenus(), "Ctrl+H" );
299 menu->addSeparator();
300 DP_SADD( menu, qtr("Preferences"), "", ":/pixmaps/vlc_preferences_16px.png",
301 prefsDialog(), "Ctrl+P" );
306 * Interface Sub-Menu, to list extras interface and skins
308 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
311 vector<const char *> varnames;
312 /** \todo add "switch to XXX" */
313 varnames.push_back( "intf-add" );
314 objects.push_back( p_intf->i_object_id );
316 QMenu *menu = Populate( p_intf, current, varnames, objects );
318 if( !p_intf->pf_show_dialog )
320 menu->addSeparator();
321 menu->addAction( qtr("Switch to skins"), THEDP, SLOT( switchToSkins() ),
325 CONNECT( menu, aboutToShow(), THEDP->menusUpdateMapper, map() );
326 THEDP->menusUpdateMapper->setMapping( menu, 4 );
333 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
336 vector<const char *> varnames;
338 vlc_object_t *p_object = (vlc_object_t *)vlc_object_find( p_intf,
339 VLC_OBJECT_INPUT, FIND_ANYWHERE );
340 if( p_object != NULL )
342 PUSH_VAR( "audio-es" );
343 vlc_object_release( p_object );
346 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
350 AudioAutoMenuBuilder( p_object, objects, varnames );
351 vlc_object_release( p_object );
353 return Populate( p_intf, current, varnames, objects );
358 * Subtitles are part of Video.
360 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
362 vlc_object_t *p_object;
364 vector<const char *> varnames;
366 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
368 if( p_object != NULL )
370 PUSH_VAR( "video-es" );
371 PUSH_VAR( "spu-es" );
372 vlc_object_release( p_object );
375 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
377 if( p_object != NULL )
379 VideoAutoMenuBuilder( p_object, objects, varnames );
380 vlc_object_release( p_object );
382 return Populate( p_intf, current, varnames, objects );
387 * For DVD, MP4, MOV and other chapter based format
389 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *current )
391 vlc_object_t *p_object;
393 vector<const char *> varnames;
396 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
398 if( p_object != NULL )
400 InputAutoMenuBuilder( p_object, objects, varnames );
401 PUSH_VAR( "prev-title"); PUSH_VAR ( "next-title" );
402 PUSH_VAR( "prev-chapter"); PUSH_VAR( "next-chapter" );
403 vlc_object_release( p_object );
405 return Populate( p_intf, current, varnames, objects );
409 * Service Discovery Menu
411 QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf )
413 QMenu *menu = new QMenu();
414 menu->setTitle( qtr( I_PL_SD ) );
415 vlc_list_t *p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE,
418 for( int i_index = 0 ; i_index < p_list->i_count; i_index++ )
420 module_t * p_parser = (module_t *)p_list->p_values[i_index].p_object ;
421 if( !strcmp( p_parser->psz_capability, "services_discovery" ) )
424 for( int i_index = 0 ; i_index < p_list->i_count; i_index++ )
426 module_t * p_parser = (module_t *)p_list->p_values[i_index].p_object;
427 if( !strcmp( p_parser->psz_capability, "services_discovery" ) )
429 QAction *a = new QAction( qfu( p_parser->psz_longname ), menu );
430 a->setCheckable( true );
431 /* hack to handle submodules properly */
433 while( p_parser->pp_shortcuts[++i] != NULL );
435 if( playlist_IsServicesDiscoveryLoaded( THEPL,
436 i>=0?p_parser->pp_shortcuts[i]
437 : p_parser->psz_object_name ) )
439 a->setChecked( true );
441 CONNECT( a , triggered(), THEDP->SDMapper, map() );
442 THEDP->SDMapper->setMapping( a, i>=0? p_parser->pp_shortcuts[i] :
443 p_parser->psz_object_name );
444 menu->addAction( a );
447 vlc_list_release( p_list );
453 QMenu *QVLCMenu::HelpMenu()
455 QMenu *menu = new QMenu();
456 DP_SADD( menu, qtr("Help") , "", ":/pixmaps/vlc_help_16px.png",
457 helpDialog(), "F1" );
458 menu->addSeparator();
459 DP_SADD( menu, qtr( I_MENU_ABOUT ), "", "", aboutDialog(), "Ctrl+F1");
464 /*****************************************************************************
465 * Popup menus - Right Click menus *
466 *****************************************************************************/
467 #define POPUP_BOILERPLATE \
468 unsigned int i_last_separator = 0; \
469 vector<int> objects; \
470 vector<const char *> varnames; \
471 input_thread_t *p_input = THEMIM->getInput();
473 #define CREATE_POPUP \
474 QMenu *menu = new QMenu(); \
475 Populate( p_intf, menu, varnames, objects ); \
476 p_intf->p_sys->p_popup_menu = menu; \
477 menu->popup( QCursor::pos() ); \
478 p_intf->p_sys->p_popup_menu = NULL; \
479 i_last_separator = 0;
481 #define POPUP_PLAY_ENTRIES( menu )\
485 var_Get( p_input, "state", &val ); \
486 if( val.i_int == PLAYING_S ) \
487 MIM_SADD( menu, qtr("Pause"), "", ":/pixmaps/vlc_pause_16px.png", \
488 togglePlayPause() ) \
490 MIM_SADD( menu, qtr("Play"), "", ":/pixmaps/vlc_play_16px.png", \
491 togglePlayPause() ) \
493 else if( THEPL->items.i_size && THEPL->i_enabled ) \
494 MIM_SADD( menu, qtr("Play"), "", ":/pixmaps/vlc_play_16px.png", \
495 togglePlayPause() ); \
497 MIM_SADD( menu, qtr("Stop"), "", ":/pixmaps/vlc_stop_16px.png", stop() ); \
498 MIM_SADD( menu, qtr("Previous"), "", ":/pixmaps/vlc_previous_16px.png", \
500 MIM_SADD( menu, qtr("Next"), "", ":/pixmaps/vlc_next_16px.png", next() );
502 #define POPUP_STATIC_ENTRIES \
503 POPUP_PLAY_ENTRIES( menu ); \
505 menu->addSeparator(); \
506 QMenu *intfmenu = InterfacesMenu( p_intf, NULL ); \
507 intfmenu->setTitle( qtr("Interfaces" ) ); \
508 menu->addMenu( intfmenu ); \
510 QMenu *toolsmenu = ToolsMenu( p_intf, NULL, false, false, false ); \
511 toolsmenu->setTitle( qtr("Tools" ) ); \
512 menu->addMenu( toolsmenu ); \
514 QMenu *openmenu = new QMenu( qtr("Open") ); \
515 openmenu->addAction( qtr("Open &File..." ), THEDP, SLOT( openFileDialog() ) ); \
516 openmenu->addAction( qtr("Open &Disc..." ), THEDP, SLOT( openDiscDialog() ) ); \
517 openmenu->addAction( qtr("Open &Network..." ), THEDP, SLOT( openNetDialog() ) ); \
518 openmenu->addAction( qtr("Open &Capture Device..." ), THEDP, \
519 SLOT( openCaptureDialog() ) ); \
520 menu->addMenu( openmenu ); \
522 menu->addSeparator(); \
523 QMenu *helpmenu = HelpMenu(); \
524 helpmenu->setTitle( qtr("Help") ); \
525 menu->addMenu( helpmenu ); \
527 DP_SADD( menu, qtr("Quit"), "", "", quit() , "Ctrl+Q" );
529 /* Video Tracks and Subtitles tracks */
530 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
535 vlc_object_yield( p_input );
536 varnames.push_back( "video-es" );
537 objects.push_back( p_input->i_object_id );
538 varnames.push_back( "spu-es" );
539 objects.push_back( p_input->i_object_id );
540 vlc_object_t *p_vout = (vlc_object_t *)vlc_object_find( p_input,
541 VLC_OBJECT_VOUT, FIND_CHILD );
544 VideoAutoMenuBuilder( p_vout, objects, varnames );
545 vlc_object_release( p_vout );
547 vlc_object_release( p_input );
553 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
558 vlc_object_yield( p_input );
559 varnames.push_back( "audio-es" );
560 objects.push_back( p_input->i_object_id );
561 vlc_object_t *p_aout = (vlc_object_t *)vlc_object_find( p_input,
562 VLC_OBJECT_AOUT, FIND_ANYWHERE );
565 AudioAutoMenuBuilder( p_aout, objects, varnames );
566 vlc_object_release( p_aout );
568 vlc_object_release( p_input );
573 /* Navigation stuff, and general menus (open) */
574 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
579 vlc_object_yield( p_input );
580 varnames.push_back( "audio-es" );
581 InputAutoMenuBuilder( VLC_OBJECT(p_input), objects, varnames );
585 QMenu *menu = new QMenu();
586 Populate( p_intf, menu, varnames, objects );
587 menu->addSeparator();
588 POPUP_STATIC_ENTRIES;
590 p_intf->p_sys->p_popup_menu = menu;
591 menu->popup( QCursor::pos() );
592 p_intf->p_sys->p_popup_menu = NULL;
595 /* Main Menu that sticks everything together */
596 void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
600 // create a popup if there is none
601 if( ! p_intf->p_sys->p_popup_menu )
606 vlc_object_yield( p_input );
607 InputAutoMenuBuilder( VLC_OBJECT(p_input), objects, varnames );
611 varnames.push_back( "video-es" );
612 objects.push_back( p_input->i_object_id );
613 varnames.push_back( "spu-es" );
614 objects.push_back( p_input->i_object_id );
615 vlc_object_t *p_vout = (vlc_object_t *)vlc_object_find( p_input,
616 VLC_OBJECT_VOUT, FIND_CHILD );
619 VideoAutoMenuBuilder( p_vout, objects, varnames );
620 vlc_object_release( p_vout );
624 varnames.push_back( "audio-es" );
625 objects.push_back( p_input->i_object_id );
626 vlc_object_t *p_aout = (vlc_object_t *)vlc_object_find( p_input,
627 VLC_OBJECT_AOUT, FIND_ANYWHERE );
630 AudioAutoMenuBuilder( p_aout, objects, varnames );
631 vlc_object_release( p_aout );
635 QMenu *menu = new QMenu();
636 Populate( p_intf, menu, varnames, objects );
637 menu->addSeparator();
638 POPUP_STATIC_ENTRIES;
640 p_intf->p_sys->p_popup_menu = menu;
642 p_intf->p_sys->p_popup_menu->popup( QCursor::pos() );
646 // destroy popup if there is one
647 delete p_intf->p_sys->p_popup_menu;
648 p_intf->p_sys->p_popup_menu = NULL;
652 /************************************************************************
654 ************************************************************************/
656 void QVLCMenu::updateSystrayMenu( MainInterface *mi,
657 intf_thread_t *p_intf,
658 bool b_force_visible )
662 /* Get the systray menu and clean it */
663 QMenu *sysMenu = mi->getSysTrayMenu();
666 /* Hide / Show VLC and cone */
667 if( mi->isVisible() || b_force_visible )
669 sysMenu->addAction( QIcon( ":/vlc16.png" ),
670 qtr("Hide VLC media player"), mi,
671 SLOT( toggleUpdateSystrayMenu() ) );
675 sysMenu->addAction( QIcon( ":/vlc16.png" ),
676 qtr("Show VLC media player"), mi,
677 SLOT( toggleUpdateSystrayMenu() ) );
680 sysMenu->addSeparator();
681 POPUP_PLAY_ENTRIES( sysMenu );
683 sysMenu->addSeparator();
684 DP_SADD( sysMenu, qtr("&Open Media" ), "",
685 ":/pixmaps/vlc_file-wide_16px.png", openFileDialog(), "" );
686 DP_SADD( sysMenu, qtr("&Quit") , "", ":/pixmaps/vlc_quit_16px.png",
690 mi->getSysTray()->setContextMenu( sysMenu );
694 #undef PUSH_SEPARATOR
697 /*************************************************************************
698 * Builders for automenus
699 *************************************************************************/
700 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf, QMenu *current,
701 vector< const char *> & varnames,
702 vector<int> & objects, bool append )
704 QMenu *menu = current;
712 vlc_object_t *p_object;
713 vlc_bool_t b_section_empty = VLC_FALSE;
716 #define APPEND_EMPTY { QAction *action = menu->addAction( qtr("Empty" ) ); \
717 action->setEnabled( false ); }
719 for( i = 0; i < (int)objects.size() ; i++ )
721 if( !varnames[i] || !*varnames[i] )
723 if( b_section_empty )
725 menu->addSeparator();
726 b_section_empty = VLC_TRUE;
730 if( objects[i] == 0 )
732 /// \bug What is this ?
733 // Append( menu, varnames[i], NULL );
734 b_section_empty = VLC_FALSE;
738 p_object = (vlc_object_t *)vlc_object_get( p_intf,
740 if( p_object == NULL ) continue;
742 b_section_empty = VLC_FALSE;
743 /* Ugly specific stuff */
744 if( strstr(varnames[i], "intf-add" ) )
745 CreateItem( menu, varnames[i], p_object, false );
747 CreateItem( menu, varnames[i], p_object, true );
748 vlc_object_release( p_object );
751 /* Special case for empty menus */
752 if( menu->actions().size() == 0 || b_section_empty )
758 /*****************************************************************************
760 *****************************************************************************/
762 static bool IsMenuEmpty( const char *psz_var, vlc_object_t *p_object,
765 vlc_value_t val, val_list;
766 int i_type, i_result, i;
768 /* Check the type of the object variable */
769 i_type = var_Type( p_object, psz_var );
771 /* Check if we want to display the variable */
772 if( !(i_type & VLC_VAR_HASCHOICE) ) return FALSE;
774 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
775 if( val.i_int == 0 ) return TRUE;
777 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE )
779 /* Very evil hack ! intf-switch can have only one value */
780 if( !strcmp( psz_var, "intf-switch" ) ) return FALSE;
781 if( val.i_int == 1 && b_root ) return TRUE;
785 /* Check children variables in case of VLC_VAR_VARIABLE */
786 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
791 for( i = 0, i_result = TRUE; i < val_list.p_list->i_count; i++ )
793 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
801 /* clean up everything */
802 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
807 void QVLCMenu::CreateItem( QMenu *menu, const char *psz_var,
808 vlc_object_t *p_object, bool b_submenu )
810 vlc_value_t val, text;
813 /* Check the type of the object variable */
814 i_type = var_Type( p_object, psz_var );
816 switch( i_type & VLC_VAR_TYPE )
820 case VLC_VAR_VARIABLE:
822 case VLC_VAR_INTEGER:
826 /* Variable doesn't exist or isn't handled */
830 /* Make sure we want to display the variable */
831 if( IsMenuEmpty( psz_var, p_object ) ) return;
833 /* Get the descriptive name of the variable */
834 var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
836 if( i_type & VLC_VAR_HASCHOICE )
838 /* Append choices menu */
841 QMenu *submenu = new QMenu();
842 submenu->setTitle( qfu( text.psz_string ?
843 text.psz_string : psz_var ) );
844 if( CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0)
845 menu->addMenu( submenu );
848 CreateChoicesMenu( menu, psz_var, p_object, true );
849 FREENULL( text.psz_string );
853 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
855 switch( i_type & VLC_VAR_TYPE )
858 var_Get( p_object, psz_var, &val );
859 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
860 p_object->i_object_id, val, i_type );
864 var_Get( p_object, psz_var, &val );
865 val.b_bool = !val.b_bool;
866 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
867 p_object->i_object_id, val, i_type, !val.b_bool );
870 FREENULL( text.psz_string );
874 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
875 vlc_object_t *p_object, bool b_root )
877 vlc_value_t val, val_list, text_list;
880 /* Check the type of the object variable */
881 i_type = var_Type( p_object, psz_var );
883 /* Make sure we want to display the variable */
884 if( IsMenuEmpty( psz_var, p_object, b_root ) ) return VLC_EGENERIC;
886 switch( i_type & VLC_VAR_TYPE )
890 case VLC_VAR_VARIABLE:
892 case VLC_VAR_INTEGER:
896 /* Variable doesn't exist or isn't handled */
900 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
901 &val_list, &text_list ) < 0 )
905 #define NORMAL_OR_RADIO i_type & VLC_VAR_ISCOMMAND ? ITEM_NORMAL: ITEM_RADIO
906 #define NOTCOMMAND !(i_type & VLC_VAR_ISCOMMAND)
907 #define CURVAL val_list.p_list->p_values[i]
908 #define CURTEXT text_list.p_list->p_values[i].psz_string
910 for( i = 0; i < val_list.p_list->i_count; i++ )
912 vlc_value_t another_val;
914 QMenu *subsubmenu = new QMenu();
916 switch( i_type & VLC_VAR_TYPE )
918 case VLC_VAR_VARIABLE:
919 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
920 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
921 submenu->addMenu( subsubmenu );
925 var_Get( p_object, psz_var, &val );
926 another_val.psz_string = strdup( CURVAL.psz_string );
927 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
928 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
929 p_object->i_object_id, another_val, i_type,
930 NOTCOMMAND && val.psz_string &&
931 !strcmp( val.psz_string, CURVAL.psz_string ) );
933 if( val.psz_string ) free( val.psz_string );
936 case VLC_VAR_INTEGER:
937 var_Get( p_object, psz_var, &val );
938 if( CURTEXT ) menutext = qfu( CURTEXT );
939 else menutext.sprintf( "%d", CURVAL.i_int);
940 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
941 p_object->i_object_id, CURVAL, i_type,
942 NOTCOMMAND && CURVAL.i_int == val.i_int );
946 var_Get( p_object, psz_var, &val );
947 if( CURTEXT ) menutext = qfu( CURTEXT );
948 else menutext.sprintf( "%.2f", CURVAL.f_float );
949 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
950 p_object->i_object_id, CURVAL, i_type,
951 NOTCOMMAND && CURVAL.f_float == val.f_float );
960 /* clean up everything */
961 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
963 #undef NORMAL_OR_RADIO
970 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
971 QString text, QString help,
972 int i_item_type, int i_object_id,
973 vlc_value_t val, int i_val_type,
976 QAction *action = new QAction( text, menu );
977 action->setText( text );
978 action->setToolTip( help );
980 if( i_item_type == ITEM_CHECK )
982 action->setCheckable( true );
984 else if( i_item_type == ITEM_RADIO )
986 action->setCheckable( true );
988 currentGroup = new QActionGroup( menu );
989 currentGroup->addAction( action );
994 action->setChecked( true );
996 MenuItemData *itemData = new MenuItemData( i_object_id, i_val_type,
998 CONNECT( action, triggered(), THEDP->menusMapper, map() );
999 THEDP->menusMapper->setMapping( action, itemData );
1000 menu->addAction( action );
1003 void QVLCMenu::DoAction( intf_thread_t *p_intf, QObject *data )
1005 MenuItemData *itemData = qobject_cast<MenuItemData *>(data);
1006 vlc_object_t *p_object = (vlc_object_t *)vlc_object_get( p_intf,
1007 itemData->i_object_id );
1008 if( p_object == NULL ) return;
1010 var_Set( p_object, itemData->psz_var, itemData->val );
1011 vlc_object_release( p_object );}