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 *****************************************************************************/
25 #include <vlc_intf_strings.h>
27 #include "main_interface.hpp"
29 #include "dialogs_provider.hpp"
30 #include "input_manager.hpp"
35 #include <QActionGroup>
36 #include <QSignalMapper>
37 #include <QSystemTrayIcon>
46 static QActionGroup *currentGroup;
48 // Add static entries to menus
49 #define DP_SADD( menu, text, help, icon, slot, shortcut ) \
51 if( strlen( icon ) > 0 ) \
53 if( strlen( shortcut ) > 0 ) \
55 menu->addAction( QIcon( icon ), text, THEDP, SLOT( slot ), \
60 menu->addAction( QIcon( icon ), text, THEDP, SLOT( slot ) );\
65 if( strlen( shortcut ) > 0 ) \
67 menu->addAction( text, THEDP, SLOT( slot ), \
72 menu->addAction( text, THEDP, SLOT( slot ) ); \
76 #define MIM_SADD( menu, text, help, icon, slot ) \
78 if( strlen( icon ) > 0 ) \
80 QAction *action = menu->addAction( text, THEMIM, SLOT( slot ) ); \
81 action->setIcon( QIcon( icon ) ); \
85 menu->addAction( text, THEMIM, SLOT( slot ) ); \
90 /*****************************************************************************
91 * Definitions of variables for the dynamic menus
92 *****************************************************************************/
93 #define PUSH_VAR( var ) varnames.push_back( var ); \
94 objects.push_back( p_object->i_object_id )
96 #define PUSH_SEPARATOR if( objects.size() != i_last_separator ) { \
97 objects.push_back( 0 ); varnames.push_back( "" ); \
98 i_last_separator = objects.size(); }
100 static int InputAutoMenuBuilder( vlc_object_t *p_object,
101 vector<int> &objects,
102 vector<const char *> &varnames )
104 PUSH_VAR( "bookmark" );
106 PUSH_VAR ( "chapter" );
107 PUSH_VAR( "program" );
108 PUSH_VAR( "navigation" );
109 PUSH_VAR( "dvd_menus" );
113 static int VideoAutoMenuBuilder( vlc_object_t *p_object,
114 vector<int> &objects,
115 vector<const char *> &varnames )
117 PUSH_VAR( "fullscreen" );
119 PUSH_VAR( "deinterlace" );
120 PUSH_VAR( "aspect-ratio" );
122 PUSH_VAR( "video-on-top" );
123 PUSH_VAR( "directx-wallpaper" );
124 PUSH_VAR( "video-snapshot" );
126 vlc_object_t *p_dec_obj = ( vlc_object_t * )vlc_object_find( p_object,
129 if( p_dec_obj != NULL )
131 vlc_object_t *p_object = p_dec_obj;
132 PUSH_VAR( "ffmpeg-pp-q" );
133 vlc_object_release( p_dec_obj );
138 static int AudioAutoMenuBuilder( vlc_object_t *p_object,
139 vector<int> &objects,
140 vector<const char *> &varnames )
142 PUSH_VAR( "audio-device" );
143 PUSH_VAR( "audio-channels" );
144 PUSH_VAR( "visual" );
145 PUSH_VAR( "equalizer" );
149 /*****************************************************************************
152 *****************************************************************************/
154 #define BAR_ADD( func, title ) { \
155 QMenu *menu = func; menu->setTitle( title ); bar->addMenu( menu ); }
157 #define BAR_DADD( func, title, id ) { \
158 QMenu *menu = func; menu->setTitle( title ); bar->addMenu( menu ); \
159 MenuFunc *f = new MenuFunc( menu, id ); \
160 CONNECT( menu, aboutToShow(), THEDP->menusUpdateMapper, map() ); \
161 THEDP->menusUpdateMapper->setMapping( menu, f ); }
164 * Main Menu Bar Creation
166 void QVLCMenu::createMenuBar( MainInterface *mi, intf_thread_t *p_intf,
167 bool visual_selector_enabled )
169 QMenuBar *bar = mi->menuBar();
170 BAR_ADD( FileMenu(), qtr( "&Media" ) );
171 BAR_ADD( PlaylistMenu( p_intf, mi ), qtr( "&Playlist" ) );
172 BAR_ADD( ToolsMenu( p_intf, mi, visual_selector_enabled, true ), qtr( "&Tools" ) );
173 BAR_DADD( AudioMenu( p_intf, NULL ), qtr( "&Audio" ), 2 );
174 BAR_DADD( VideoMenu( p_intf, NULL ), qtr( "&Video" ), 1 );
175 BAR_DADD( NavigMenu( p_intf, NULL ), qtr( "&Playback" ), 3 );
177 BAR_ADD( HelpMenu(), qtr( "&Help" ) );
181 * Media ( File ) Menu
182 * Opening, streaming and quit
184 QMenu *QVLCMenu::FileMenu()
186 QMenu *menu = new QMenu();
188 DP_SADD( menu, qtr( "&Open File..." ), "",
189 ":/pixmaps/file-asym_16px.png", openFileDialog(), "Ctrl+O" );
190 DP_SADD( menu, qtr( I_OPEN_FOLDER ), "",
191 ":/pixmaps/folder-grey_16px.png", PLAppendDir(), "Ctrl+F" );
192 DP_SADD( menu, qtr( "Open &Disc..." ), "", ":/pixmaps/disc_16px.png",
193 openDiscDialog(), "Ctrl+D" );
194 DP_SADD( menu, qtr( "Open &Network..." ), "",
195 ":/pixmaps/network_16px.png", openNetDialog(), "Ctrl+N" );
196 DP_SADD( menu, qtr( "Open &Capture Device..." ), "",
197 ":/pixmaps/capture-card_16px.png", openCaptureDialog(),
199 menu->addSeparator();
201 DP_SADD( menu, qtr( "&Streaming..." ), "", ":/pixmaps/menus_stream_16px.png",
202 openThenStreamingDialogs(), "Ctrl+S" );
203 DP_SADD( menu, qtr( "Conve&rt / Save..." ), "", "",
204 openThenTranscodingDialogs(), "Ctrl+R" );
206 menu->addSeparator();
207 DP_SADD( menu, qtr( "&Quit" ) , "", ":/pixmaps/menus_quit_16px.png", quit(),
212 QMenu *QVLCMenu::PlaylistMenu( intf_thread_t *p_intf, MainInterface *mi )
214 QMenu *menu = new QMenu();
215 menu->addMenu( SDMenu( p_intf ) );
216 menu->addAction( QIcon( ":/pixmaps/playlist_16px.png" ),
217 qtr( "Show Playlist" ), mi, SLOT( togglePlaylist() ) );
218 menu->addSeparator();
220 DP_SADD( menu, qtr( I_PL_LOAD ), "", "", openPlaylist(), "Ctrl+X" );
221 DP_SADD( menu, qtr( I_PL_SAVE ), "", "", savePlaylist(), "Ctrl+Y" );
222 menu->addSeparator();
223 menu->addAction( qtr( "Undock from interface" ), mi,
224 SLOT( undockPlaylist() ), qtr( "Ctrl+U" ) );
230 * This is kept in the same menu for now, but could change if it gets much
233 QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf, MainInterface *mi,
234 bool visual_selector_enabled,
237 QMenu *menu = new QMenu;
240 menu->addAction( QIcon( ":/pixmaps/playlist_16px.png" ),
241 qtr( "Playlist..." ), mi, SLOT( togglePlaylist() ),
244 DP_SADD( menu, qtr( I_MENU_EXT ), "", ":/pixmaps/menus_settings_16px.png",
245 extendedDialog() , "Ctrl+E" );
247 menu->addSeparator();
251 QMenu *intfmenu = InterfacesMenu( p_intf, NULL );
252 intfmenu->setTitle( qtr( "Add Interfaces" ) );
253 menu->addMenu( intfmenu );
254 menu->addSeparator();
259 QAction *action=menu->addAction( qtr( "Minimal View..." ), mi,
260 SLOT( toggleMinimalView() ), qtr( "Ctrl+H" ) );
261 //FIXME: remove useless thing. But keep it until the release, pls.
262 action->setCheckable( true );
263 if( mi->getControlsVisibilityStatus() & CONTROLS_VISIBLE )
264 action->setChecked( true );
266 /* Advanced Controls */
267 action = menu->addAction( qtr( "Advanced controls" ), mi,
268 SLOT( toggleAdvanced() ) );
269 action->setCheckable( true );
270 if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
271 action->setChecked( true );
272 #if 0 /* For Visualisations. Not yet working */
273 adv = menu->addAction( qtr( "Visualizations selector" ),
274 mi, SLOT( visual() ) );
275 adv->setCheckable( true );
276 if( visual_selector_enabled ) adv->setChecked( true );
280 menu->addSeparator();
283 DP_SADD( menu, qtr( I_MENU_MSG ), "", ":/pixmaps/menus_messages_16px.png",
284 messagesDialog(), "Ctrl+M" );
285 DP_SADD( menu, qtr( I_MENU_INFO ) , "", "", mediaInfoDialog(), "Ctrl+I" );
286 DP_SADD( menu, qtr( I_MENU_CODECINFO ) , "", ":/pixmaps/menus_info_16px.png",
287 mediaCodecDialog(), "Ctrl+J" );
289 #if 0 /* Not Implemented yet */
290 DP_SADD( menu, qtr( I_MENU_BOOKMARK ), "","", bookmarksDialog(), "Ctrl+B" );
292 DP_SADD( menu, qtr( I_MENU_VLM ), "","", vlmDialog(), "Ctrl+V" );
295 menu->addSeparator();
296 DP_SADD( menu, qtr( "Preferences..." ), "", ":/pixmaps/menus_preferences_16px.png",
297 prefsDialog(), "Ctrl+P" );
302 * Interface Sub-Menu, to list extras interface and skins
304 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
307 vector<const char *> varnames;
308 /** \todo add "switch to XXX" */
309 varnames.push_back( "intf-add" );
310 objects.push_back( p_intf->i_object_id );
312 QMenu *menu = Populate( p_intf, current, varnames, objects );
314 if( !p_intf->pf_show_dialog )
316 menu->addSeparator();
317 menu->addAction( qtr( "Switch to skins" ), THEDP, SLOT( switchToSkins() ),
318 QString( "Ctrl+Z" ) );
321 CONNECT( menu, aboutToShow(), THEDP->menusUpdateMapper, map() );
322 THEDP->menusUpdateMapper->setMapping( menu, 4 );
329 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
332 vector<const char *> varnames;
334 vlc_object_t *p_object = ( vlc_object_t * )vlc_object_find( p_intf,
335 VLC_OBJECT_INPUT, FIND_ANYWHERE );
336 if( p_object != NULL )
338 PUSH_VAR( "audio-es" );
339 vlc_object_release( p_object );
342 p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_AOUT,
346 AudioAutoMenuBuilder( p_object, objects, varnames );
347 vlc_object_release( p_object );
349 return Populate( p_intf, current, varnames, objects );
354 * Subtitles are part of Video.
356 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
358 vlc_object_t *p_object;
360 vector<const char *> varnames;
362 p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_INPUT,
364 if( p_object != NULL )
366 PUSH_VAR( "video-es" );
367 PUSH_VAR( "spu-es" );
368 vlc_object_release( p_object );
371 p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_VOUT,
373 if( p_object != NULL )
375 VideoAutoMenuBuilder( p_object, objects, varnames );
376 vlc_object_release( p_object );
378 return Populate( p_intf, current, varnames, objects );
383 * For DVD, MP4, MOV and other chapter based format
385 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *navMenu )
387 vlc_object_t *p_object;
389 vector<const char *> varnames;
392 p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_INPUT,
394 if( p_object != NULL )
396 InputAutoMenuBuilder( p_object, objects, varnames );
397 PUSH_VAR( "prev-title" ); PUSH_VAR ( "next-title" );
398 PUSH_VAR( "prev-chapter" ); PUSH_VAR( "next-chapter" );
399 vlc_object_release( p_object );
401 navMenu = new QMenu();
402 DP_SADD( navMenu, qtr( I_MENU_GOTOTIME ), "","", gotoTimeDialog(),
404 navMenu->addSeparator();
405 return Populate( p_intf, navMenu, varnames, objects, true );
409 * Service Discovery SubMenu
411 QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf )
413 QMenu *menu = new QMenu();
414 menu->setTitle( qtr( I_PL_SD ) );
415 char **ppsz_longnames;
416 char **ppsz_names = services_discovery_GetServicesNames( p_intf,
418 char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
419 for( ; *ppsz_name; ppsz_name++, ppsz_longname++ )
421 QAction *a = new QAction( qfu( *ppsz_longname ), menu );
422 a->setCheckable( true );
423 if( playlist_IsServicesDiscoveryLoaded( THEPL, *ppsz_name ) )
424 a->setChecked( true );
425 CONNECT( a , triggered(), THEDP->SDMapper, map() );
426 THEDP->SDMapper->setMapping( a, QString( *ppsz_name ) );
427 menu->addAction( a );
429 if( !strcmp( *ppsz_name, "podcast" ) )
431 QAction *b = new QAction( qfu( "Configure podcasts..." ), menu );
432 //b->setEnabled( a->isChecked() );
433 menu->addAction( b );
434 CONNECT( b, triggered(), THEDP, podcastConfigureDialog() );
437 free( *ppsz_longname );
440 free( ppsz_longnames );
446 QMenu *QVLCMenu::HelpMenu()
448 QMenu *menu = new QMenu();
449 DP_SADD( menu, qtr( "Help..." ) , "", ":/pixmaps/menus_help_16px.png",
450 helpDialog(), "F1" );
451 menu->addSeparator();
452 DP_SADD( menu, qtr( I_MENU_ABOUT ), "", "", aboutDialog(), "Ctrl+F1" );
457 /*****************************************************************************
458 * Popup menus - Right Click menus *
459 *****************************************************************************/
460 #define POPUP_BOILERPLATE \
461 unsigned int i_last_separator = 0; \
462 vector<int> objects; \
463 vector<const char *> varnames; \
464 input_thread_t *p_input = THEMIM->getInput();
466 #define CREATE_POPUP \
467 Populate( p_intf, menu, varnames, objects ); \
468 p_intf->p_sys->p_popup_menu = menu; \
469 menu->popup( QCursor::pos() ); \
470 p_intf->p_sys->p_popup_menu = NULL; \
471 i_last_separator = 0;
473 #define POPUP_PLAY_ENTRIES( menu )\
477 var_Get( p_input, "state", &val ); \
478 if( val.i_int == PLAYING_S ) \
479 MIM_SADD( menu, qtr( "Pause" ), "", ":/pixmaps/pause_16px.png", \
480 togglePlayPause() ) \
482 MIM_SADD( menu, qtr( "Play" ), "", ":/pixmaps/play_16px.png", \
483 togglePlayPause() ) \
485 else if( THEPL->items.i_size && THEPL->i_enabled ) \
486 MIM_SADD( menu, qtr( "Play" ), "", ":/pixmaps/play_16px.png", \
487 togglePlayPause() ); \
489 MIM_SADD( menu, qtr( "Stop" ), "", ":/pixmaps/stop_16px.png", stop() ); \
490 MIM_SADD( menu, qtr( "Previous" ), "", ":/pixmaps/previous_16px.png", \
492 MIM_SADD( menu, qtr( "Next" ), "", ":/pixmaps/next_16px.png", next() );
494 #define POPUP_STATIC_ENTRIES( menu ) \
495 QMenu *toolsmenu = ToolsMenu( p_intf, NULL, false, true ); \
496 toolsmenu->setTitle( qtr( "Tools" ) ); \
497 menu->addMenu( toolsmenu ); \
499 QMenu *openmenu = new QMenu( qtr( "Open" ) ); \
500 openmenu->addAction( qtr( "Open &File..." ), THEDP, SLOT( openFileDialog() ) ); \
501 openmenu->addAction( qtr( "Open &Disc..." ), THEDP, SLOT( openDiscDialog() ) ); \
502 openmenu->addAction( qtr( "Open &Network..." ), THEDP, SLOT( openNetDialog() ) ); \
503 openmenu->addAction( qtr( "Open &Capture Device..." ), THEDP, \
504 SLOT( openCaptureDialog() ) ); \
505 menu->addMenu( openmenu ); \
507 menu->addSeparator(); \
508 QMenu *helpmenu = HelpMenu(); \
509 helpmenu->setTitle( qtr( "Help" ) ); \
510 menu->addMenu( helpmenu ); \
512 DP_SADD( menu, qtr( "Quit" ), "", "", quit() , "Ctrl+Q" );
514 /* Video Tracks and Subtitles tracks */
515 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
520 vlc_object_yield( p_input );
521 varnames.push_back( "video-es" );
522 objects.push_back( p_input->i_object_id );
523 varnames.push_back( "spu-es" );
524 objects.push_back( p_input->i_object_id );
525 vlc_object_t *p_vout = ( vlc_object_t * )vlc_object_find( p_input,
526 VLC_OBJECT_VOUT, FIND_CHILD );
529 VideoAutoMenuBuilder( p_vout, objects, varnames );
530 vlc_object_release( p_vout );
532 vlc_object_release( p_input );
534 QMenu *menu = new QMenu();
539 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
544 vlc_object_yield( p_input );
545 varnames.push_back( "audio-es" );
546 objects.push_back( p_input->i_object_id );
547 vlc_object_t *p_aout = ( vlc_object_t * )vlc_object_find( p_input,
548 VLC_OBJECT_AOUT, FIND_ANYWHERE );
551 AudioAutoMenuBuilder( p_aout, objects, varnames );
552 vlc_object_release( p_aout );
554 vlc_object_release( p_input );
556 QMenu *menu = new QMenu();
560 /* Navigation stuff, and general menus ( open ) */
561 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
568 vlc_object_yield( p_input );
569 varnames.push_back( "audio-es" );
570 InputAutoMenuBuilder( VLC_OBJECT( p_input ), objects, varnames );
574 QMenu *menu = new QMenu();
575 Populate( p_intf, menu, varnames, objects );
577 menu->addSeparator();
578 POPUP_PLAY_ENTRIES( menu );
580 menu->addSeparator();
581 POPUP_STATIC_ENTRIES( menu );
583 p_intf->p_sys->p_popup_menu = menu;
584 menu->popup( QCursor::pos() );
585 p_intf->p_sys->p_popup_menu = NULL;
588 /* Main Menu that sticks everything together */
589 void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
593 // create a popup if there is none
594 if( ! p_intf->p_sys->p_popup_menu )
599 vlc_object_yield( p_input );
600 InputAutoMenuBuilder( VLC_OBJECT( p_input ), objects, varnames );
604 varnames.push_back( "audio-es" );
605 objects.push_back( p_input->i_object_id );
606 vlc_object_t *p_aout = ( vlc_object_t * )vlc_object_find( p_input,
607 VLC_OBJECT_AOUT, FIND_ANYWHERE );
610 AudioAutoMenuBuilder( p_aout, objects, varnames );
611 vlc_object_release( p_aout );
616 varnames.push_back( "video-es" );
617 objects.push_back( p_input->i_object_id );
618 varnames.push_back( "spu-es" );
619 objects.push_back( p_input->i_object_id );
620 vlc_object_t *p_vout = ( vlc_object_t * )vlc_object_find( p_input,
621 VLC_OBJECT_VOUT, FIND_CHILD );
624 VideoAutoMenuBuilder( p_vout, objects, varnames );
625 vlc_object_release( p_vout );
629 QMenu *menu = new QMenu();
630 Populate( p_intf, menu, varnames, objects );
631 menu->addSeparator();
632 POPUP_PLAY_ENTRIES( menu );
633 menu->addSeparator();
634 POPUP_STATIC_ENTRIES( menu );
636 p_intf->p_sys->p_popup_menu = menu;
638 p_intf->p_sys->p_popup_menu->popup( QCursor::pos() );
642 // destroy popup if there is one
643 delete p_intf->p_sys->p_popup_menu;
644 p_intf->p_sys->p_popup_menu = NULL;
648 /************************************************************************
650 ************************************************************************/
652 void QVLCMenu::updateSystrayMenu( MainInterface *mi,
653 intf_thread_t *p_intf,
654 bool b_force_visible )
658 /* Get the systray menu and clean it */
659 QMenu *sysMenu = mi->getSysTrayMenu();
662 /* Hide / Show VLC and cone */
663 if( mi->isVisible() || b_force_visible )
665 sysMenu->addAction( QIcon( ":/vlc16.png" ),
666 qtr( "Hide VLC media player in taskbar" ), mi,
667 SLOT( toggleUpdateSystrayMenu() ) );
671 sysMenu->addAction( QIcon( ":/vlc16.png" ),
672 qtr( "Show VLC media player" ), mi,
673 SLOT( toggleUpdateSystrayMenu() ) );
676 sysMenu->addSeparator();
677 POPUP_PLAY_ENTRIES( sysMenu );
679 sysMenu->addSeparator();
680 DP_SADD( sysMenu, qtr( "&Open Media" ), "",
681 ":/pixmaps/file-wide_16px.png", openFileDialog(), "" );
682 DP_SADD( sysMenu, qtr( "&Quit" ) , "", ":/pixmaps/menus_quit_16px.png",
686 mi->getSysTray()->setContextMenu( sysMenu );
690 #undef PUSH_SEPARATOR
693 /*************************************************************************
694 * Builders for automenus
695 *************************************************************************/
696 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf, QMenu *current,
697 vector< const char *> & varnames,
698 vector<int> & objects, bool append )
700 QMenu *menu = current;
708 vlc_object_t *p_object;
709 vlc_bool_t b_section_empty = VLC_FALSE;
712 #define APPEND_EMPTY { QAction *action = menu->addAction( qtr( "Empty" ) ); \
713 action->setEnabled( false ); }
715 for( i = 0; i < ( int )objects.size() ; i++ )
717 if( !varnames[i] || !*varnames[i] )
719 if( b_section_empty )
721 menu->addSeparator();
722 b_section_empty = VLC_TRUE;
726 if( objects[i] == 0 )
728 /// \bug What is this ?
729 // Append( menu, varnames[i], NULL );
730 b_section_empty = VLC_FALSE;
734 p_object = ( vlc_object_t * )vlc_object_get( p_intf,
736 if( p_object == NULL ) continue;
738 b_section_empty = VLC_FALSE;
739 /* Ugly specific stuff */
740 if( strstr( varnames[i], "intf-add" ) )
741 CreateItem( menu, varnames[i], p_object, false );
743 CreateItem( menu, varnames[i], p_object, true );
744 vlc_object_release( p_object );
747 /* Special case for empty menus */
748 if( menu->actions().size() == 0 || b_section_empty )
754 /*****************************************************************************
756 *****************************************************************************/
758 static bool IsMenuEmpty( const char *psz_var, vlc_object_t *p_object,
761 vlc_value_t val, val_list;
762 int i_type, i_result, i;
764 /* Check the type of the object variable */
765 i_type = var_Type( p_object, psz_var );
767 /* Check if we want to display the variable */
768 if( !( i_type & VLC_VAR_HASCHOICE ) ) return FALSE;
770 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
771 if( val.i_int == 0 ) return TRUE;
773 if( ( i_type & VLC_VAR_TYPE ) != VLC_VAR_VARIABLE )
775 /* Very evil hack ! intf-switch can have only one value */
776 if( !strcmp( psz_var, "intf-switch" ) ) return FALSE;
777 if( val.i_int == 1 && b_root ) return TRUE;
781 /* Check children variables in case of VLC_VAR_VARIABLE */
782 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
787 for( i = 0, i_result = TRUE; i < val_list.p_list->i_count; i++ )
789 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
797 /* clean up everything */
798 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
803 void QVLCMenu::CreateItem( QMenu *menu, const char *psz_var,
804 vlc_object_t *p_object, bool b_submenu )
806 vlc_value_t val, text;
809 /* Check the type of the object variable */
810 i_type = var_Type( p_object, psz_var );
812 switch( i_type & VLC_VAR_TYPE )
816 case VLC_VAR_VARIABLE:
818 case VLC_VAR_INTEGER:
822 /* Variable doesn't exist or isn't handled */
826 /* Make sure we want to display the variable */
827 if( IsMenuEmpty( psz_var, p_object ) ) return;
829 /* Get the descriptive name of the variable */
830 var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
832 if( i_type & VLC_VAR_HASCHOICE )
834 /* Append choices menu */
837 QMenu *submenu = new QMenu();
838 submenu->setTitle( qfu( text.psz_string ?
839 text.psz_string : psz_var ) );
840 if( CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0 )
841 menu->addMenu( submenu );
844 CreateChoicesMenu( menu, psz_var, p_object, true );
845 FREENULL( text.psz_string );
849 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
851 switch( i_type & VLC_VAR_TYPE )
854 var_Get( p_object, psz_var, &val );
855 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
856 p_object->i_object_id, val, i_type );
860 var_Get( p_object, psz_var, &val );
861 val.b_bool = !val.b_bool;
862 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
863 p_object->i_object_id, val, i_type, !val.b_bool );
866 FREENULL( text.psz_string );
870 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
871 vlc_object_t *p_object, bool b_root )
873 vlc_value_t val, val_list, text_list;
876 /* Check the type of the object variable */
877 i_type = var_Type( p_object, psz_var );
879 /* Make sure we want to display the variable */
880 if( IsMenuEmpty( psz_var, p_object, b_root ) ) return VLC_EGENERIC;
882 switch( i_type & VLC_VAR_TYPE )
886 case VLC_VAR_VARIABLE:
888 case VLC_VAR_INTEGER:
892 /* Variable doesn't exist or isn't handled */
896 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
897 &val_list, &text_list ) < 0 )
901 #define NORMAL_OR_RADIO i_type & VLC_VAR_ISCOMMAND ? ITEM_NORMAL: ITEM_RADIO
902 #define NOTCOMMAND !( i_type & VLC_VAR_ISCOMMAND )
903 #define CURVAL val_list.p_list->p_values[i]
904 #define CURTEXT text_list.p_list->p_values[i].psz_string
906 for( i = 0; i < val_list.p_list->i_count; i++ )
908 vlc_value_t another_val;
910 QMenu *subsubmenu = new QMenu();
912 switch( i_type & VLC_VAR_TYPE )
914 case VLC_VAR_VARIABLE:
915 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
916 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
917 submenu->addMenu( subsubmenu );
921 var_Get( p_object, psz_var, &val );
922 another_val.psz_string = strdup( CURVAL.psz_string );
923 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
924 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
925 p_object->i_object_id, another_val, i_type,
926 NOTCOMMAND && val.psz_string &&
927 !strcmp( val.psz_string, CURVAL.psz_string ) );
929 if( val.psz_string ) free( val.psz_string );
932 case VLC_VAR_INTEGER:
933 var_Get( p_object, psz_var, &val );
934 if( CURTEXT ) menutext = qfu( CURTEXT );
935 else menutext.sprintf( "%d", CURVAL.i_int );
936 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
937 p_object->i_object_id, CURVAL, i_type,
938 NOTCOMMAND && CURVAL.i_int == val.i_int );
942 var_Get( p_object, psz_var, &val );
943 if( CURTEXT ) menutext = qfu( CURTEXT );
944 else menutext.sprintf( "%.2f", CURVAL.f_float );
945 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
946 p_object->i_object_id, CURVAL, i_type,
947 NOTCOMMAND && CURVAL.f_float == val.f_float );
956 /* clean up everything */
957 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
959 #undef NORMAL_OR_RADIO
966 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
967 QString text, QString help,
968 int i_item_type, int i_object_id,
969 vlc_value_t val, int i_val_type,
972 QAction *action = new QAction( text, menu );
973 action->setText( text );
974 action->setToolTip( help );
976 if( i_item_type == ITEM_CHECK )
978 action->setCheckable( true );
980 else if( i_item_type == ITEM_RADIO )
982 action->setCheckable( true );
984 currentGroup = new QActionGroup( menu );
985 currentGroup->addAction( action );
990 action->setChecked( true );
992 MenuItemData *itemData = new MenuItemData( i_object_id, i_val_type,
994 CONNECT( action, triggered(), THEDP->menusMapper, map() );
995 THEDP->menusMapper->setMapping( action, itemData );
996 menu->addAction( action );
999 void QVLCMenu::DoAction( intf_thread_t *p_intf, QObject *data )
1001 MenuItemData *itemData = qobject_cast<MenuItemData *>( data );
1002 vlc_object_t *p_object = ( vlc_object_t * )vlc_object_get( p_intf,
1003 itemData->i_object_id );
1004 if( p_object == NULL ) return;
1006 var_Set( p_object, itemData->psz_var, itemData->val );
1007 vlc_object_release( p_object );