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 void addDPStaticEntry( QMenu *menu,
56 if( !EMPTY_STR( icon ) > 0 )
58 if( !EMPTY_STR( shortcut ) > 0 )
59 menu->addAction( QIcon( icon ), text, THEDP, member, qtr( shortcut ) );
61 menu->addAction( QIcon( icon ), text, THEDP, member );
65 if( !EMPTY_STR( shortcut ) > 0 )
66 menu->addAction( text, THEDP, member, qtr( shortcut ) );
68 menu->addAction( text, THEDP, member );
72 void addMIMStaticEntry( intf_thread_t *p_intf,
79 if( strlen( icon ) > 0 )
81 QAction *action = menu->addAction( text, THEMIM, member );
82 action->setIcon( QIcon( icon ) );
86 menu->addAction( text, THEMIM, member );
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,
167 intf_thread_t *p_intf,
168 bool visual_selector_enabled )
170 QMenuBar *bar = mi->menuBar();
171 BAR_ADD( FileMenu(), qtr( "&Media" ) );
172 BAR_ADD( PlaylistMenu( p_intf, mi ), qtr( "&Playlist" ) );
173 BAR_ADD( ToolsMenu( p_intf, mi, visual_selector_enabled, true ), qtr( "&Tools" ) );
174 BAR_DADD( AudioMenu( p_intf, NULL ), qtr( "&Audio" ), 2 );
175 BAR_DADD( VideoMenu( p_intf, NULL ), qtr( "&Video" ), 1 );
176 BAR_DADD( NavigMenu( p_intf, NULL ), qtr( "&Playback" ), 3 );
178 BAR_ADD( HelpMenu(), qtr( "&Help" ) );
184 * Media ( File ) Menu
185 * Opening, streaming and quit
187 QMenu *QVLCMenu::FileMenu()
189 QMenu *menu = new QMenu();
191 addDPStaticEntry( menu, qtr( "&Open File..." ), "",
192 ":/pixmaps/file-asym_16px.png", SLOT( openFileDialog() ), "Ctrl+O" );
193 addDPStaticEntry( menu, qtr( I_OPEN_FOLDER ), "",
194 ":/pixmaps/folder-grey_16px.png", SLOT( PLAppendDir() ), "Ctrl+F" );
195 addDPStaticEntry( menu, qtr( "Open &Disc..." ), "",
196 ":/pixmaps/disc_16px.png", SLOT( openDiscDialog() ), "Ctrl+D" );
197 addDPStaticEntry( menu, qtr( "Open &Network..." ), "",
198 ":/pixmaps/network_16px.png", SLOT( openNetDialog() ), "Ctrl+N" );
199 addDPStaticEntry( menu, qtr( "Open &Capture Device..." ), "",
200 ":/pixmaps/capture-card_16px.png", SLOT( openCaptureDialog() ),
202 menu->addSeparator();
204 addDPStaticEntry( menu, qtr( "&Streaming..." ), "",
205 ":/pixmaps/menus_stream_16px.png", SLOT( openThenStreamingDialogs() ),
207 addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "", "",
208 SLOT( openThenTranscodingDialogs() ), "Ctrl+R" );
209 menu->addSeparator();
211 addDPStaticEntry( menu, qtr( "&Quit" ) , "",
212 ":/pixmaps/menus_quit_16px.png", SLOT( quit() ), "Ctrl+Q" );
216 /* Playlist/MediaLibrary Control */
217 QMenu *QVLCMenu::PlaylistMenu( intf_thread_t *p_intf, MainInterface *mi )
219 QMenu *menu = new QMenu();
220 menu->addMenu( SDMenu( p_intf ) );
221 menu->addAction( QIcon( ":/pixmaps/playlist_16px.png" ),
222 qtr( "Show Playlist" ), mi, SLOT( togglePlaylist() ) );
223 menu->addSeparator();
225 addDPStaticEntry( menu, qtr( I_PL_LOAD ), "", "", SLOT( openAPlaylist() ),
227 addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", "", SLOT( saveAPlaylist() ),
229 menu->addSeparator();
230 menu->addAction( qtr( "Undock from interface" ), mi,
231 SLOT( undockPlaylist() ), qtr( "Ctrl+U" ) );
237 * This is kept in the same menu for now, but could change if it gets much
239 * This menu can be an interface menu but also a right click menu.
241 QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf,
243 bool visual_selector_enabled,
246 QMenu *menu = new QMenu;
249 menu->addAction( QIcon( ":/pixmaps/playlist_16px.png" ),
250 qtr( "Playlist..." ), mi, SLOT( togglePlaylist() ),
253 addDPStaticEntry( menu, qtr( I_MENU_EXT ), "",
254 ":/pixmaps/menus_settings_16px.png", SLOT( extendedDialog() ),
257 menu->addSeparator();
261 QMenu *intfmenu = InterfacesMenu( p_intf, NULL );
262 intfmenu->setTitle( qtr( "Add Interfaces" ) );
263 menu->addMenu( intfmenu );
264 menu->addSeparator();
269 QAction *action=menu->addAction( qtr( "Minimal View..." ), mi,
270 SLOT( toggleMinimalView() ), qtr( "Ctrl+H" ) );
271 action->setCheckable( true );
272 if( mi->getControlsVisibilityStatus() & CONTROLS_VISIBLE )
273 action->setChecked( true );
275 /* Advanced Controls */
276 action = menu->addAction( qtr( "Advanced controls" ), mi,
277 SLOT( toggleAdvanced() ) );
278 action->setCheckable( true );
279 if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
280 action->setChecked( true );
281 #if 0 /* For Visualisations. Not yet working */
282 adv = menu->addAction( qtr( "Visualizations selector" ),
283 mi, SLOT( visual() ) );
284 adv->setCheckable( true );
285 if( visual_selector_enabled ) adv->setChecked( true );
289 menu->addSeparator();
291 addDPStaticEntry( menu, qtr( I_MENU_MSG ), "",
292 ":/pixmaps/menus_messages_16px.png", SLOT( messagesDialog() ),
294 addDPStaticEntry( menu, qtr( I_MENU_INFO ) , "", "",
295 SLOT( mediaInfoDialog() ), "Ctrl+I" );
296 addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) , "",
297 ":/pixmaps/menus_info_16px.png", SLOT( mediaCodecDialog() ), "Ctrl+J" );
299 #if 0 /* Not Implemented yet */
300 addDPStaticEntry( menu, qtr( I_MENU_BOOKMARK ), "","", "bookmarksDialog()", "Ctrl+B" );
302 addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", "", SLOT( vlmDialog() ),
305 menu->addSeparator();
306 addDPStaticEntry( menu, qtr( "Preferences..." ), "",
307 ":/pixmaps/menus_preferences_16px.png", SLOT( prefsDialog() ), "Ctrl+P" );
312 * Interface Sub-Menu, to list extras interface and skins
314 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
317 vector<const char *> varnames;
318 /** \todo add "switch to XXX" */
319 varnames.push_back( "intf-add" );
320 objects.push_back( p_intf->i_object_id );
322 QMenu *menu = Populate( p_intf, current, varnames, objects );
324 if( !p_intf->pf_show_dialog )
326 menu->addSeparator();
327 menu->addAction( qtr( "Switch to skins" ), THEDP, SLOT( switchToSkins() ),
328 QString( "Ctrl+Z" ) );
331 CONNECT( menu, aboutToShow(), THEDP->menusUpdateMapper, map() );
332 THEDP->menusUpdateMapper->setMapping( menu, 4 );
339 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
342 vector<const char *> varnames;
344 vlc_object_t *p_object = ( vlc_object_t * )vlc_object_find( p_intf,
345 VLC_OBJECT_INPUT, FIND_ANYWHERE );
346 if( p_object != NULL )
348 PUSH_VAR( "audio-es" );
349 vlc_object_release( p_object );
352 p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_AOUT,
356 AudioAutoMenuBuilder( p_object, objects, varnames );
357 vlc_object_release( p_object );
359 return Populate( p_intf, current, varnames, objects );
364 * Subtitles are part of Video.
366 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
368 vlc_object_t *p_object;
370 vector<const char *> varnames;
372 p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_INPUT,
374 if( p_object != NULL )
376 PUSH_VAR( "video-es" );
377 PUSH_VAR( "spu-es" );
378 vlc_object_release( p_object );
381 p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_VOUT,
383 if( p_object != NULL )
385 VideoAutoMenuBuilder( p_object, objects, varnames );
386 vlc_object_release( p_object );
388 return Populate( p_intf, current, varnames, objects );
393 * For DVD, MP4, MOV and other chapter based format
395 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *navMenu )
397 vlc_object_t *p_object;
399 vector<const char *> varnames;
401 p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_INPUT,
403 if( p_object != NULL )
405 InputAutoMenuBuilder( p_object, objects, varnames );
406 PUSH_VAR( "prev-title" ); PUSH_VAR ( "next-title" );
407 PUSH_VAR( "prev-chapter" ); PUSH_VAR( "next-chapter" );
408 vlc_object_release( p_object );
410 navMenu = new QMenu();
411 addDPStaticEntry( navMenu, qtr( I_MENU_GOTOTIME ), "","",
412 SLOT( gotoTimeDialog() ), "Ctrl+T" );
413 navMenu->addSeparator();
414 return Populate( p_intf, navMenu, varnames, objects, true );
418 * Service Discovery SubMenu
420 QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf )
422 QMenu *menu = new QMenu();
423 menu->setTitle( qtr( I_PL_SD ) );
424 char **ppsz_longnames;
425 char **ppsz_names = services_discovery_GetServicesNames( p_intf,
427 char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
428 for( ; *ppsz_name; ppsz_name++, ppsz_longname++ )
430 QAction *a = new QAction( qfu( *ppsz_longname ), menu );
431 a->setCheckable( true );
432 if( playlist_IsServicesDiscoveryLoaded( THEPL, *ppsz_name ) )
433 a->setChecked( true );
434 CONNECT( a , triggered(), THEDP->SDMapper, map() );
435 THEDP->SDMapper->setMapping( a, QString( *ppsz_name ) );
436 menu->addAction( a );
438 if( !strcmp( *ppsz_name, "podcast" ) )
440 QAction *b = new QAction( qfu( "Configure podcasts..." ), menu );
441 //b->setEnabled( a->isChecked() );
442 menu->addAction( b );
443 CONNECT( b, triggered(), THEDP, podcastConfigureDialog() );
446 free( *ppsz_longname );
449 free( ppsz_longnames );
455 QMenu *QVLCMenu::HelpMenu()
457 QMenu *menu = new QMenu();
458 addDPStaticEntry( menu, qtr( "Help..." ) , "",
459 ":/pixmaps/menus_help_16px.png", SLOT( helpDialog() ), "F1" );
460 addDPStaticEntry( menu, qtr( "Update" ) , "", "", SLOT( updateDialog() ), "");
461 menu->addSeparator();
462 addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), "", "", SLOT( aboutDialog() ),
468 /*****************************************************************************
469 * Popup menus - Right Click menus *
470 *****************************************************************************/
471 #define POPUP_BOILERPLATE \
472 unsigned int i_last_separator = 0; \
473 vector<int> objects; \
474 vector<const char *> varnames; \
475 input_thread_t *p_input = THEMIM->getInput();
477 #define CREATE_POPUP \
478 Populate( p_intf, menu, varnames, objects ); \
479 p_intf->p_sys->p_popup_menu = menu; \
480 menu->popup( QCursor::pos() ); \
481 p_intf->p_sys->p_popup_menu = NULL; \
482 i_last_separator = 0;
484 void QVLCMenu::PopupMenuControlEntries( QMenu *menu,
485 intf_thread_t *p_intf,
486 input_thread_t *p_input )
491 var_Get( p_input, "state", &val );
492 if( val.i_int == PLAYING_S )
493 addMIMStaticEntry( p_intf, menu, qtr( "Pause" ), "",
494 ":/pixmaps/pause_16px.png", SLOT( togglePlayPause() ) );
496 addMIMStaticEntry( p_intf, menu, qtr( "Play" ), "",
497 ":/pixmaps/play_16px.png", SLOT( togglePlayPause() ) );
499 else if( THEPL->items.i_size && THEPL->i_enabled )
500 addMIMStaticEntry( p_intf, menu, qtr( "Play" ), "",
501 ":/pixmaps/play_16px.png", SLOT( togglePlayPause() ) );
503 addMIMStaticEntry( p_intf, menu, qtr( "Stop" ), "",
504 ":/pixmaps/stop_16px.png", SLOT( stop() ) );
505 addMIMStaticEntry( p_intf, menu, qtr( "Previous" ), "",
506 ":/pixmaps/previous_16px.png", SLOT( prev() ) );
507 addMIMStaticEntry( p_intf, menu, qtr( "Next" ), "",
508 ":/pixmaps/next_16px.png", SLOT( next() ) );
511 void QVLCMenu::PopupMenuStaticEntries( intf_thread_t *p_intf, QMenu *menu )
513 QMenu *toolsmenu = ToolsMenu( p_intf, NULL, false, true );
514 toolsmenu->setTitle( qtr( "Tools" ) );
515 menu->addMenu( toolsmenu );
517 QMenu *openmenu = new QMenu( qtr( "Open" ) );
518 openmenu->addAction( qtr( "Open &File..." ), THEDP,
519 SLOT( openFileDialog() ) );
520 openmenu->addAction( qtr( "Open &Disc..." ), THEDP,
521 SLOT( openDiscDialog() ) );
522 openmenu->addAction( qtr( "Open &Network..." ), THEDP,
523 SLOT( openNetDialog() ) );
524 openmenu->addAction( qtr( "Open &Capture Device..." ), THEDP,
525 SLOT( openCaptureDialog() ) );
526 menu->addMenu( openmenu );
528 menu->addSeparator();
529 QMenu *helpmenu = HelpMenu();
530 helpmenu->setTitle( qtr( "Help" ) );
531 menu->addMenu( helpmenu );
533 addDPStaticEntry( menu, qtr( "Quit" ), "", "", SLOT( 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 );
556 QMenu *menu = new QMenu();
561 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
566 vlc_object_yield( p_input );
567 varnames.push_back( "audio-es" );
568 objects.push_back( p_input->i_object_id );
569 vlc_object_t *p_aout = ( vlc_object_t * )vlc_object_find( p_input,
570 VLC_OBJECT_AOUT, FIND_ANYWHERE );
573 AudioAutoMenuBuilder( p_aout, objects, varnames );
574 vlc_object_release( p_aout );
576 vlc_object_release( p_input );
578 QMenu *menu = new QMenu();
582 /* Navigation stuff, and general menus ( open ) */
583 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
590 vlc_object_yield( p_input );
591 varnames.push_back( "audio-es" );
592 InputAutoMenuBuilder( VLC_OBJECT( p_input ), objects, varnames );
596 QMenu *menu = new QMenu();
597 Populate( p_intf, menu, varnames, objects );
599 menu->addSeparator();
600 PopupMenuControlEntries( menu, p_intf, p_input );
602 menu->addSeparator();
603 PopupMenuStaticEntries( p_intf, menu );
605 p_intf->p_sys->p_popup_menu = menu;
606 menu->popup( QCursor::pos() );
607 p_intf->p_sys->p_popup_menu = NULL;
610 /* Main Menu that sticks everything together */
611 void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
615 // create a popup if there is none
616 if( ! p_intf->p_sys->p_popup_menu )
621 vlc_object_yield( p_input );
622 InputAutoMenuBuilder( VLC_OBJECT( p_input ), objects, varnames );
626 varnames.push_back( "audio-es" );
627 objects.push_back( p_input->i_object_id );
628 vlc_object_t *p_aout = ( vlc_object_t * )
629 vlc_object_find( p_input, VLC_OBJECT_AOUT, FIND_ANYWHERE );
632 AudioAutoMenuBuilder( p_aout, objects, varnames );
633 vlc_object_release( p_aout );
638 varnames.push_back( "video-es" );
639 objects.push_back( p_input->i_object_id );
640 varnames.push_back( "spu-es" );
641 objects.push_back( p_input->i_object_id );
642 vlc_object_t *p_vout = ( vlc_object_t * )
643 vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD );
646 VideoAutoMenuBuilder( p_vout, objects, varnames );
647 vlc_object_release( p_vout );
651 QMenu *menu = new QMenu();
652 Populate( p_intf, menu, varnames, objects );
653 menu->addSeparator();
654 PopupMenuControlEntries( menu, p_intf, p_input );
655 menu->addSeparator();
656 PopupMenuStaticEntries( p_intf, menu );
658 p_intf->p_sys->p_popup_menu = menu;
660 p_intf->p_sys->p_popup_menu->popup( QCursor::pos() );
664 // destroy popup if there is one
665 delete p_intf->p_sys->p_popup_menu;
666 p_intf->p_sys->p_popup_menu = NULL;
670 /************************************************************************
672 ************************************************************************/
674 void QVLCMenu::updateSystrayMenu( MainInterface *mi,
675 intf_thread_t *p_intf,
676 bool b_force_visible )
680 /* Get the systray menu and clean it */
681 QMenu *sysMenu = mi->getSysTrayMenu();
684 /* Hide / Show VLC and cone */
685 if( mi->isVisible() || b_force_visible )
687 sysMenu->addAction( QIcon( ":/vlc16.png" ),
688 qtr( "Hide VLC media player in taskbar" ), mi,
689 SLOT( toggleUpdateSystrayMenu() ) );
693 sysMenu->addAction( QIcon( ":/vlc16.png" ),
694 qtr( "Show VLC media player" ), mi,
695 SLOT( toggleUpdateSystrayMenu() ) );
698 sysMenu->addSeparator();
699 PopupMenuControlEntries( sysMenu, p_intf, p_input );
701 sysMenu->addSeparator();
702 addDPStaticEntry( sysMenu, qtr( "&Open Media" ), "",
703 ":/pixmaps/file-wide_16px.png", SLOT( openFileDialog() ), "" );
704 addDPStaticEntry( sysMenu, qtr( "&Quit" ) , "",
705 ":/pixmaps/menus_quit_16px.png", SLOT( quit() ), "" );
708 mi->getSysTray()->setContextMenu( sysMenu );
712 #undef PUSH_SEPARATOR
715 /*************************************************************************
716 * Builders for automenus
717 *************************************************************************/
718 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf,
720 vector< const char *> & varnames,
721 vector<int> & objects,
724 QMenu *menu = current;
732 vlc_object_t *p_object;
733 vlc_bool_t b_section_empty = VLC_FALSE;
736 #define APPEND_EMPTY { QAction *action = menu->addAction( qtr( "Empty" ) ); \
737 action->setEnabled( false ); }
739 for( i = 0; i < ( int )objects.size() ; i++ )
741 if( !varnames[i] || !*varnames[i] )
743 if( b_section_empty )
745 menu->addSeparator();
746 b_section_empty = VLC_TRUE;
750 if( objects[i] == 0 )
752 /// \bug What is this ?
753 // Append( menu, varnames[i], NULL );
754 b_section_empty = VLC_FALSE;
758 p_object = ( vlc_object_t * )vlc_object_get( p_intf, objects[i] );
759 if( p_object == NULL ) continue;
761 b_section_empty = VLC_FALSE;
762 /* Ugly specific stuff */
763 if( strstr( varnames[i], "intf-add" ) )
764 CreateItem( menu, varnames[i], p_object, false );
766 CreateItem( menu, varnames[i], p_object, true );
767 vlc_object_release( p_object );
770 /* Special case for empty menus */
771 if( menu->actions().size() == 0 || b_section_empty )
778 /*****************************************************************************
780 *****************************************************************************/
782 static bool IsMenuEmpty( const char *psz_var,
783 vlc_object_t *p_object,
786 vlc_value_t val, val_list;
787 int i_type, i_result, i;
789 /* Check the type of the object variable */
790 i_type = var_Type( p_object, psz_var );
792 /* Check if we want to display the variable */
793 if( !( i_type & VLC_VAR_HASCHOICE ) ) return false;
795 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
796 if( val.i_int == 0 ) return true;
798 if( ( i_type & VLC_VAR_TYPE ) != VLC_VAR_VARIABLE )
800 /* Very evil hack ! intf-switch can have only one value */
801 if( !strcmp( psz_var, "intf-switch" ) ) return false;
802 if( val.i_int == 1 && b_root ) return true;
806 /* Check children variables in case of VLC_VAR_VARIABLE */
807 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
812 for( i = 0, i_result = true; i < val_list.p_list->i_count; i++ )
814 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
822 /* clean up everything */
823 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
828 void QVLCMenu::CreateItem( QMenu *menu, const char *psz_var,
829 vlc_object_t *p_object, bool b_submenu )
831 vlc_value_t val, text;
834 /* Check the type of the object variable */
835 i_type = var_Type( p_object, psz_var );
837 switch( i_type & VLC_VAR_TYPE )
841 case VLC_VAR_VARIABLE:
843 case VLC_VAR_INTEGER:
847 /* Variable doesn't exist or isn't handled */
851 /* Make sure we want to display the variable */
852 if( IsMenuEmpty( psz_var, p_object ) ) return;
854 /* Get the descriptive name of the variable */
855 var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
857 if( i_type & VLC_VAR_HASCHOICE )
859 /* Append choices menu */
862 QMenu *submenu = new QMenu();
863 submenu->setTitle( qfu( text.psz_string ?
864 text.psz_string : psz_var ) );
865 if( CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0 )
866 menu->addMenu( submenu );
869 CreateChoicesMenu( menu, psz_var, p_object, true );
870 FREENULL( text.psz_string );
874 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
876 switch( i_type & VLC_VAR_TYPE )
879 var_Get( p_object, psz_var, &val );
880 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
881 p_object->i_object_id, val, i_type );
885 var_Get( p_object, psz_var, &val );
886 val.b_bool = !val.b_bool;
887 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
888 p_object->i_object_id, val, i_type, !val.b_bool );
891 FREENULL( text.psz_string );
895 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
896 vlc_object_t *p_object, bool b_root )
898 vlc_value_t val, val_list, text_list;
901 /* Check the type of the object variable */
902 i_type = var_Type( p_object, psz_var );
904 /* Make sure we want to display the variable */
905 if( IsMenuEmpty( psz_var, p_object, b_root ) ) return VLC_EGENERIC;
907 switch( i_type & VLC_VAR_TYPE )
911 case VLC_VAR_VARIABLE:
913 case VLC_VAR_INTEGER:
917 /* Variable doesn't exist or isn't handled */
921 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
922 &val_list, &text_list ) < 0 )
927 #define NORMAL_OR_RADIO i_type & VLC_VAR_ISCOMMAND ? ITEM_NORMAL: ITEM_RADIO
928 #define NOTCOMMAND !( i_type & VLC_VAR_ISCOMMAND )
929 #define CURVAL val_list.p_list->p_values[i]
930 #define CURTEXT text_list.p_list->p_values[i].psz_string
932 for( i = 0; i < val_list.p_list->i_count; i++ )
934 vlc_value_t another_val;
936 QMenu *subsubmenu = new QMenu();
938 switch( i_type & VLC_VAR_TYPE )
940 case VLC_VAR_VARIABLE:
941 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
942 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
943 submenu->addMenu( subsubmenu );
947 var_Get( p_object, psz_var, &val );
948 another_val.psz_string = strdup( CURVAL.psz_string );
949 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
950 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
951 p_object->i_object_id, another_val, i_type,
952 NOTCOMMAND && val.psz_string &&
953 !strcmp( val.psz_string, CURVAL.psz_string ) );
955 if( val.psz_string ) free( val.psz_string );
958 case VLC_VAR_INTEGER:
959 var_Get( p_object, psz_var, &val );
960 if( CURTEXT ) menutext = qfu( CURTEXT );
961 else menutext.sprintf( "%d", CURVAL.i_int );
962 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
963 p_object->i_object_id, CURVAL, i_type,
964 NOTCOMMAND && CURVAL.i_int == val.i_int );
968 var_Get( p_object, psz_var, &val );
969 if( CURTEXT ) menutext = qfu( CURTEXT );
970 else menutext.sprintf( "%.2f", CURVAL.f_float );
971 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
972 p_object->i_object_id, CURVAL, i_type,
973 NOTCOMMAND && CURVAL.f_float == val.f_float );
982 /* clean up everything */
983 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
985 #undef NORMAL_OR_RADIO
992 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
993 QString text, QString help,
994 int i_item_type, int i_object_id,
995 vlc_value_t val, int i_val_type,
998 QAction *action = new QAction( text, menu );
999 action->setText( text );
1000 action->setToolTip( help );
1002 if( i_item_type == ITEM_CHECK )
1004 action->setCheckable( true );
1006 else if( i_item_type == ITEM_RADIO )
1008 action->setCheckable( true );
1010 currentGroup = new QActionGroup( menu );
1011 currentGroup->addAction( action );
1016 action->setChecked( true );
1018 MenuItemData *itemData = new MenuItemData( i_object_id, i_val_type,
1020 CONNECT( action, triggered(), THEDP->menusMapper, map() );
1021 THEDP->menusMapper->setMapping( action, itemData );
1022 menu->addAction( action );
1025 void QVLCMenu::DoAction( intf_thread_t *p_intf, QObject *data )
1027 MenuItemData *itemData = qobject_cast<MenuItemData *>( data );
1028 vlc_object_t *p_object = ( vlc_object_t * )vlc_object_get( p_intf,
1029 itemData->i_object_id );
1030 if( p_object == NULL ) return;
1032 var_Set( p_object, itemData->psz_var, itemData->val );
1033 vlc_object_release( p_object );