1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright © 2006-2008 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Jean-Baptiste Kempf <jb@videolan.org>
9 * Jean-Philippe André <jpeg@videolan.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * ( at your option ) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
27 * - Remove static currentGroup
34 #include <vlc_common.h>
36 #include <vlc_intf_strings.h>
38 #include "main_interface.hpp"
40 #include "dialogs_provider.hpp"
41 #include "input_manager.hpp"
42 #include "recents.hpp"
47 #include <QActionGroup>
48 #include <QSignalMapper>
49 #include <QSystemTrayIcon>
53 This file defines the main menus and the pop-up menu (right-click menu)
54 and the systray menu (in that order in the file)
56 There are 3 menus that have to be rebuilt everytime there are called:
57 Audio, Video, Navigation
58 3 functions are building those menus: AudioMenu, VideoMenu, NavigMenu
59 and 3 functions associated are collecting the objects :
60 InputAutoMenuBuilder, AudioAutoMenuBuilder, VideoAutoMenuBuilder.
62 A QSignalMapper decides when to rebuild those menus cf MenuFunc in the .hpp
63 Just before one of those menus are aboutToShow(), they are rebuild.
73 static QActionGroup *currentGroup;
75 /* HACK for minimalView to go around a Qt bug/feature
76 * that doesn't update the QAction checked state when QMenu is hidden */
77 QAction *QVLCMenu::minimalViewAction = NULL;
79 QMenu *QVLCMenu::recentsMenu = NULL;
81 /****************************************************************************
83 ****************************************************************************
84 * Add static entries to DP in menus
85 ***************************************************************************/
86 void addDPStaticEntry( QMenu *menu,
91 const char *shortcut = NULL )
93 QAction *action = NULL;
94 if( !EMPTY_STR( icon ) > 0 )
96 if( !EMPTY_STR( shortcut ) > 0 )
97 action = menu->addAction( QIcon( icon ), text, THEDP,
98 member, qtr( shortcut ) );
100 action = menu->addAction( QIcon( icon ), text, THEDP, member );
104 if( !EMPTY_STR( shortcut ) > 0 )
105 action = menu->addAction( text, THEDP, member, qtr( shortcut ) );
107 action = menu->addAction( text, THEDP, member );
109 action->setData( "_static_" );
112 void EnableDPStaticEntries( QMenu *menu, bool enable = true )
117 foreach( action, menu->actions() )
119 if( action->data().toString() == "_static_" )
120 action->setEnabled( enable );
125 * \return Number of static entries
127 int DeleteNonStaticEntries( QMenu *menu )
133 foreach( action, menu->actions() )
135 if( action->data().toString() != "_static_" )
145 void addMIMStaticEntry( intf_thread_t *p_intf,
152 if( strlen( icon ) > 0 )
154 QAction *action = menu->addAction( text, THEMIM, member );
155 action->setIcon( QIcon( icon ) );
159 menu->addAction( text, THEMIM, member );
163 /*****************************************************************************
164 * Definitions of variables for the dynamic menus
165 *****************************************************************************/
166 #define PUSH_VAR( var ) varnames.push_back( var ); \
167 objects.push_back( VLC_OBJECT(p_object) )
169 #define PUSH_INPUTVAR( var ) varnames.push_back( var ); \
170 objects.push_back( VLC_OBJECT(p_input) );
172 #define PUSH_SEPARATOR if( objects.size() != i_last_separator ) { \
173 objects.push_back( 0 ); varnames.push_back( "" ); \
174 i_last_separator = objects.size(); }
176 static int InputAutoMenuBuilder( vlc_object_t *p_object,
177 vector<vlc_object_t *> &objects,
178 vector<const char *> &varnames )
180 PUSH_VAR( "bookmark" );
182 PUSH_VAR( "chapter" );
183 PUSH_VAR( "program" );
184 PUSH_VAR( "navigation" );
185 PUSH_VAR( "dvd_menus" );
189 static int VideoAutoMenuBuilder( vlc_object_t *p_object,
190 input_thread_t *p_input,
191 vector<vlc_object_t *> &objects,
192 vector<const char *> &varnames )
194 PUSH_INPUTVAR( "video-es" );
195 PUSH_INPUTVAR( "spu-es" );
196 PUSH_VAR( "fullscreen" );
198 PUSH_VAR( "deinterlace" );
199 PUSH_VAR( "aspect-ratio" );
201 PUSH_VAR( "video-on-top" );
203 PUSH_VAR( "directx-wallpaper" );
205 PUSH_VAR( "video-snapshot" );
207 /* Special case for postproc */
210 /* p_object is the vout, so the decoder is our parent and the
211 * postproc filter one of the decoder's children */
212 vlc_object_t *p_dec = (vlc_object_t *)
213 vlc_object_find( p_object, VLC_OBJECT_DECODER,
217 vlc_object_t *p_pp = (vlc_object_t *)
218 vlc_object_find_name( p_dec, "postproc",
223 PUSH_VAR( "postproc-q" );
224 vlc_object_release( p_pp );
227 vlc_object_release( p_dec );
233 static int AudioAutoMenuBuilder( vlc_object_t *p_object,
234 input_thread_t *p_input,
235 vector<vlc_object_t *> &objects,
236 vector<const char *> &varnames )
238 PUSH_INPUTVAR( "audio-es" );
239 PUSH_VAR( "audio-device" );
240 PUSH_VAR( "audio-channels" );
241 PUSH_VAR( "visual" );
245 static QAction * FindActionWithVar( QMenu *menu, const char *psz_var )
248 foreach( action, menu->actions() )
250 if( action->data().toString() == psz_var )
256 /*****************************************************************************
259 *****************************************************************************/
261 #define BAR_ADD( func, title ) { \
262 QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); }
264 #define BAR_DADD( func, title, id ) { \
265 QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); \
266 MenuFunc *f = new MenuFunc( _menu, id ); \
267 CONNECT( _menu, aboutToShow(), THEDP->menusUpdateMapper, map() ); \
268 THEDP->menusUpdateMapper->setMapping( _menu, f ); }
270 #define ACT_ADD( _menu, val, title ) { \
271 QAction *_action = new QAction( title, _menu ); _action->setData( val ); \
272 _menu->addAction( _action ); }
275 * Main Menu Bar Creation
277 void QVLCMenu::createMenuBar( MainInterface *mi,
278 intf_thread_t *p_intf,
279 bool visual_selector_enabled )
281 /* QMainWindows->menuBar()
282 gives the QProcess::destroyed timeout issue on Cleanlooks style with
283 setDesktopAware set to false */
284 QMenuBar *bar = mi->menuBar();
285 BAR_ADD( FileMenu( p_intf ), qtr( "&Media" ) );
287 BAR_DADD( AudioMenu( p_intf, NULL ), qtr( "&Audio" ), 1 );
288 BAR_DADD( VideoMenu( p_intf, NULL ), qtr( "&Video" ), 2 );
289 BAR_DADD( NavigMenu( p_intf, NULL ), qtr( "P&layback" ), 3 );
291 BAR_ADD( ToolsMenu( p_intf ), qtr( "&Tools" ) );
292 BAR_ADD( ViewMenu( p_intf, NULL, mi, visual_selector_enabled, true ),
295 BAR_ADD( HelpMenu( NULL ), qtr( "&Help" ) );
301 * Media ( File ) Menu
302 * Opening, streaming and quit
304 QMenu *QVLCMenu::FileMenu( intf_thread_t *p_intf )
306 QMenu *menu = new QMenu();
308 addDPStaticEntry( menu, qtr( "&Open File..." ), "",
310 ":/file-asym", SLOT( simpleOpenDialog() ), "Ctrl+O" );
311 addDPStaticEntry( menu, qtr( "Advanced Open File..." ), "",
312 ":/file-asym", SLOT( openFileDialog() ), "" );
314 ":/file-asym", SLOT( openFileDialog() ), "Ctrl+0" );
316 addDPStaticEntry( menu, qtr( I_OPEN_FOLDER ), "",
317 ":/folder-grey", SLOT( PLOpenDir() ), "Ctrl+F" );
318 addDPStaticEntry( menu, qtr( "Open &Disc..." ), "",
319 ":/disc", SLOT( openDiscDialog() ), "Ctrl+D" );
320 addDPStaticEntry( menu, qtr( "Open &Network..." ), "",
321 ":/network", SLOT( openNetDialog() ), "Ctrl+N" );
322 addDPStaticEntry( menu, qtr( "Open &Capture Device..." ), "",
323 ":/capture-card", SLOT( openCaptureDialog() ),
326 recentsMenu = new QMenu( qtr( "Recently played" ), menu );
327 updateRecents( p_intf );
328 menu->addMenu( recentsMenu );
329 menu->addSeparator();
331 addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "", "",
332 SLOT( openAndTranscodingDialogs() ), "Ctrl+R" );
333 addDPStaticEntry( menu, qtr( "&Streaming..." ), "",
334 ":/stream", SLOT( openAndStreamingDialogs() ),
336 menu->addSeparator();
338 addDPStaticEntry( menu, qtr( "&Quit" ) , "",
339 ":/quit", SLOT( quit() ), "Ctrl+Q" );
343 /* Playlist/MediaLibrary Control */
344 QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf )
346 QMenu *menu = new QMenu();
348 addDPStaticEntry( menu, qtr( I_MENU_EXT ), "", ":/settings",
349 SLOT( extendedDialog() ), "Ctrl+E" );
350 addDPStaticEntry( menu, qtr( I_MENU_MSG ), "",
351 ":/messages", SLOT( messagesDialog() ),
353 addDPStaticEntry( menu, qtr( I_MENU_INFO ) , "", ":/info",
354 SLOT( mediaInfoDialog() ), "Ctrl+I" );
355 addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) , "",
356 ":/info", SLOT( mediaCodecDialog() ), "Ctrl+J" );
357 addDPStaticEntry( menu, qtr( I_MENU_BOOKMARK ), "","",
358 SLOT( bookmarksDialog() ), "Ctrl+B" );
360 addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", "", SLOT( vlmDialog() ),
363 menu->addSeparator();
365 addDPStaticEntry( menu, qtr( "&Preferences..." ), "",
366 ":/preferences", SLOT( prefsDialog() ), "Ctrl+P" );
373 * This is kept in the same menu for now, but could change if it gets much
375 * This menu can be an interface menu but also a right click menu.
377 QMenu *QVLCMenu::ViewMenu( intf_thread_t *p_intf,
380 bool visual_selector_enabled,
383 QMenu *menu = new QMenu( current );
387 menu->addAction( QIcon( ":/playlist_menu" ), qtr( "Play&list..." ),
388 mi, SLOT( togglePlaylist() ), qtr( "Ctrl+L" ) );
389 act->setData( "_static_" );
391 menu->addMenu( SDMenu( p_intf ) );
392 menu->addSeparator();
394 addDPStaticEntry( menu, qtr( I_PL_LOAD ), "", "", SLOT( openAPlaylist() ),
396 addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", "", SLOT( saveAPlaylist() ),
398 /*menu->addSeparator();
399 menu->addAction( qtr( "Undock from Interface" ), mi,
400 SLOT( undockPlaylist() ), qtr( "Ctrl+U" ) );*/
403 menu->addSeparator();
407 QMenu *intfmenu = InterfacesMenu( p_intf, menu );
408 MenuFunc *f = new MenuFunc( intfmenu, 4 );
409 CONNECT( intfmenu, aboutToShow(), THEDP->menusUpdateMapper, map() );
410 THEDP->menusUpdateMapper->setMapping( intfmenu, f );
411 menu->addSeparator();
416 QAction *action = menu->addAction( qtr( "Mi&nimal View" ), mi,
417 SLOT( toggleMinimalView() ), qtr( "Ctrl+H" ) );
418 action->setCheckable( true );
419 action->setData( "_static_" );
420 if( mi->getControlsVisibilityStatus() & CONTROLS_VISIBLE )
421 action->setChecked( true );
422 minimalViewAction = action; /* HACK for minimalView */
424 /* FullScreen View */
425 action = menu->addAction( qtr( "&Fullscreen Interface" ), mi,
426 SLOT( toggleFullScreen() ), QString( "F11" ) );
427 action->setCheckable( true );
428 action->setData( "_static_" );
430 /* Advanced Controls */
431 action = menu->addAction( qtr( "&Advanced Controls" ), mi,
432 SLOT( toggleAdvanced() ) );
433 action->setCheckable( true );
434 action->setData( "_static_" );
435 if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
436 action->setChecked( true );
437 #if 0 /* For Visualisations. Not yet working */
438 adv = menu->addAction( qtr( "Visualizations selector" ),
439 mi, SLOT( visual() ) );
440 adv->setCheckable( true );
441 if( visual_selector_enabled ) adv->setChecked( true );
445 menu->addSeparator();
451 * Interface Sub-Menu, to list extras interface and skins
453 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
455 vector<vlc_object_t *> objects;
456 vector<const char *> varnames;
457 /** \todo add "switch to XXX" */
458 varnames.push_back( "intf-add" );
459 objects.push_back( VLC_OBJECT(p_intf) );
461 return Populate( p_intf, current, varnames, objects );
467 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
469 vector<vlc_object_t *> objects;
470 vector<const char *> varnames;
471 vlc_object_t *p_aout;
472 input_thread_t *p_input;
474 if( !current ) current = new QMenu();
476 if( current->isEmpty() )
478 ACT_ADD( current, "audio-es", qtr( "Audio &Track" ) );
479 ACT_ADD( current, "audio-device", qtr( "Audio &Device" ) );
480 ACT_ADD( current, "audio-channels", qtr( "Audio &Channels" ) );
481 current->addSeparator();
482 ACT_ADD( current, "visual", qtr( "&Visualizations" ) );
485 p_input = THEMIM->getInput();
487 vlc_object_hold( p_input );
488 p_aout = ( vlc_object_t * ) vlc_object_find( p_intf,
492 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
495 vlc_object_release( p_aout );
497 vlc_object_release( p_input );
499 return Populate( p_intf, current, varnames, objects );
504 * Subtitles are part of Video.
506 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
508 vlc_object_t *p_vout;
509 input_thread_t *p_input;
510 vector<vlc_object_t *> objects;
511 vector<const char *> varnames;
513 if( !current ) current = new QMenu();
515 if( current->isEmpty() )
517 ACT_ADD( current, "video-es", qtr( "Video &Track" ) );
520 QMenu *submenu = new QMenu( qtr( "&Subtitles Track" ), current );
521 action = current->addMenu( submenu );
522 action->setData( "spu-es" );
523 addDPStaticEntry( submenu, qtr( "Open File..." ), "", "",
524 SLOT( loadSubtitlesFile() ) );
525 submenu->addSeparator();
527 ACT_ADD( current, "fullscreen", qtr( "&Fullscreen" ) );
528 ACT_ADD( current, "zoom", qtr( "&Zoom" ) );
529 ACT_ADD( current, "deinterlace", qtr( "&Deinterlace" ) );
530 ACT_ADD( current, "aspect-ratio", qtr( "&Aspect Ratio" ) );
531 ACT_ADD( current, "crop", qtr( "&Crop" ) );
532 ACT_ADD( current, "video-on-top", qtr( "Always &On Top" ) );
534 ACT_ADD( current, "directx-wallpaper", qtr( "DirectX Wallpaper" ) );
536 ACT_ADD( current, "video-snapshot", qtr( "Sna&pshot" ) );
537 ACT_ADD( current, "postproc-q", qtr( "Post processing" ) );
540 p_input = THEMIM->getInput();
542 vlc_object_hold( p_input );
543 p_vout = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_VOUT,
546 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
549 vlc_object_release( p_vout );
551 vlc_object_release( p_input );
553 return Populate( p_intf, current, varnames, objects );
558 * For DVD, MP4, MOV and other chapter based format
560 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
562 vlc_object_t *p_object;
563 vector<vlc_object_t *> objects;
564 vector<const char *> varnames;
566 if( !menu ) menu = new QMenu();
568 if( menu->isEmpty() )
570 addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ), "","",
571 SLOT( gotoTimeDialog() ), "Ctrl+T" );
572 menu->addSeparator();
574 ACT_ADD( menu, "bookmark", qtr( "&Bookmarks" ) );
575 ACT_ADD( menu, "title", qtr( "T&itle" ) );
576 ACT_ADD( menu, "chapter", qtr( "&Chapter" ) );
577 ACT_ADD( menu, "program", qtr( "&Program" ) );
578 ACT_ADD( menu, "navigation", qtr( "&Navigation" ) );
581 p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_INPUT,
583 InputAutoMenuBuilder( p_object, objects, varnames );
584 PUSH_VAR( "prev-title" );
585 PUSH_VAR( "next-title" );
586 PUSH_VAR( "prev-chapter" );
587 PUSH_VAR( "next-chapter" );
588 EnableDPStaticEntries( menu, ( p_object != NULL ) );
591 vlc_object_release( p_object );
593 return Populate( p_intf, menu, varnames, objects, true );
597 * Service Discovery SubMenu
599 QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf )
601 QMenu *menu = new QMenu();
602 menu->setTitle( qtr( I_PL_SD ) );
603 char **ppsz_longnames;
604 char **ppsz_names = services_discovery_GetServicesNames( p_intf,
609 char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
610 for( ; *ppsz_name; ppsz_name++, ppsz_longname++ )
612 QAction *a = new QAction( qfu( *ppsz_longname ), menu );
613 a->setCheckable( true );
614 if( playlist_IsServicesDiscoveryLoaded( THEPL, *ppsz_name ) )
615 a->setChecked( true );
616 CONNECT( a , triggered(), THEDP->SDMapper, map() );
617 THEDP->SDMapper->setMapping( a, QString( *ppsz_name ) );
618 menu->addAction( a );
620 if( !strcmp( *ppsz_name, "podcast" ) )
622 QAction *b = new QAction( qtr( "Configure podcasts..." ), menu );
623 //b->setEnabled( a->isChecked() );
624 menu->addAction( b );
625 CONNECT( b, triggered(), THEDP, podcastConfigureDialog() );
628 free( *ppsz_longname );
631 free( ppsz_longnames );
637 QMenu *QVLCMenu::HelpMenu( QMenu *current )
639 QMenu *menu = new QMenu( current );
640 addDPStaticEntry( menu, qtr( "&Help..." ) , "",
641 ":/help", SLOT( helpDialog() ), "F1" );
643 addDPStaticEntry( menu, qtr( "Check for &Updates..." ) , "", "",
644 SLOT( updateDialog() ), "");
646 menu->addSeparator();
647 addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), "", ":/info",
648 SLOT( aboutDialog() ), "Shift+F1" );
652 /*****************************************************************************
653 * Popup menus - Right Click menus *
654 *****************************************************************************/
655 #define POPUP_BOILERPLATE \
656 unsigned int i_last_separator = 0; \
657 vector<vlc_object_t *> objects; \
658 vector<const char *> varnames; \
659 input_thread_t *p_input = THEMIM->getInput();
661 #define CREATE_POPUP \
662 Populate( p_intf, menu, varnames, objects ); \
663 p_intf->p_sys->p_popup_menu = menu; \
664 menu->popup( QCursor::pos() ); \
665 p_intf->p_sys->p_popup_menu = NULL; \
666 i_last_separator = 0;
668 void QVLCMenu::PopupMenuControlEntries( QMenu *menu,
669 intf_thread_t *p_intf,
670 input_thread_t *p_input )
675 var_Get( p_input, "state", &val );
676 if( val.i_int == PLAYING_S )
677 addMIMStaticEntry( p_intf, menu, qtr( "Pause" ), "",
678 ":/pause", SLOT( togglePlayPause() ) );
680 addMIMStaticEntry( p_intf, menu, qtr( "Play" ), "",
681 ":/play", SLOT( togglePlayPause() ) );
683 else if( THEPL->items.i_size )
684 addMIMStaticEntry( p_intf, menu, qtr( "Play" ), "",
685 ":/play", SLOT( togglePlayPause() ) );
687 addDPStaticEntry( menu, qtr( "Play" ), "",
688 ":/play", SLOT( openDialog() ) );
690 addMIMStaticEntry( p_intf, menu, qtr( "Stop" ), "",
691 ":/stop", SLOT( stop() ) );
692 addMIMStaticEntry( p_intf, menu, qtr( "Previous" ), "",
693 ":/previous", SLOT( prev() ) );
694 addMIMStaticEntry( p_intf, menu, qtr( "Next" ), "",
695 ":/next", SLOT( next() ) );
698 void QVLCMenu::PopupMenuStaticEntries( intf_thread_t *p_intf, QMenu *menu )
701 QMenu *toolsmenu = ToolsMenu( p_intf, menu, false, true );
702 toolsmenu->setTitle( qtr( "Tools" ) );
703 menu->addMenu( toolsmenu );
706 QMenu *openmenu = new QMenu( qtr( "Open" ), menu );
707 addDPStaticEntry( openmenu, qtr( "&Open File..." ), "",
708 ":/file-asym", SLOT( openFileDialog() ) );
709 addDPStaticEntry( openmenu, qtr( I_OPEN_FOLDER ), "",
710 ":/folder-grey", SLOT( PLOpenDir() ) );
711 addDPStaticEntry( openmenu, qtr( "Open &Disc..." ), "",
712 ":/disc", SLOT( openDiscDialog() ) );
713 addDPStaticEntry( openmenu, qtr( "Open &Network..." ), "",
714 ":/network", SLOT( openNetDialog() ) );
715 addDPStaticEntry( openmenu, qtr( "Open &Capture Device..." ), "",
716 ":/capture-card", SLOT( openCaptureDialog() ) );
717 menu->addMenu( openmenu );
719 menu->addSeparator();
721 QMenu *helpmenu = HelpMenu( menu );
722 helpmenu->setTitle( qtr( "Help" ) );
723 menu->addMenu( helpmenu );
726 addDPStaticEntry( menu, qtr( "Quit" ), "", ":/quit",
727 SLOT( quit() ), "Ctrl+Q" );
730 /* Video Tracks and Subtitles tracks */
731 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
736 vlc_object_hold( p_input );
737 vlc_object_t *p_vout = ( vlc_object_t * )vlc_object_find( p_input,
738 VLC_OBJECT_VOUT, FIND_CHILD );
741 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
742 vlc_object_release( p_vout );
744 vlc_object_release( p_input );
746 QMenu *menu = new QMenu();
751 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
756 vlc_object_hold( p_input );
757 vlc_object_t *p_aout = ( vlc_object_t * )vlc_object_find( p_input,
758 VLC_OBJECT_AOUT, FIND_ANYWHERE );
759 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
761 vlc_object_release( p_aout );
762 vlc_object_release( p_input );
764 QMenu *menu = new QMenu();
768 /* Navigation stuff, and general menus ( open ) */
769 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
776 vlc_object_hold( p_input );
777 varnames.push_back( "audio-es" );
778 InputAutoMenuBuilder( VLC_OBJECT( p_input ), objects, varnames );
782 QMenu *menu = new QMenu();
783 Populate( p_intf, menu, varnames, objects );
785 menu->addSeparator();
786 PopupMenuControlEntries( menu, p_intf, p_input );
788 menu->addSeparator();
789 PopupMenuStaticEntries( p_intf, menu );
791 p_intf->p_sys->p_popup_menu = menu;
792 menu->popup( QCursor::pos() );
793 p_intf->p_sys->p_popup_menu = NULL;
796 /* Main Menu that sticks everything together */
797 void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
799 MainInterface *mi = p_intf->p_sys->p_mi;
802 /* Delete and recreate a popup if there is one */
803 if( p_intf->p_sys->p_popup_menu )
804 delete p_intf->p_sys->p_popup_menu;
806 QMenu *menu = new QMenu();
809 bool b_isFullscreen = false;
813 PopupMenuControlEntries( menu, p_intf, p_input );
814 menu->addSeparator();
818 vlc_object_t *p_vout = (vlc_object_t *)
819 vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD );
821 /* Add a fullscreen switch button */
825 var_Get( p_vout, "fullscreen", &val );
826 b_isFullscreen = !( !val.b_bool );
828 CreateAndConnect( menu, "fullscreen",
829 qtr( "Leave Fullscreen" ),"" , ITEM_NORMAL,
830 VLC_OBJECT(p_vout), val, VLC_VAR_BOOL,
832 vlc_object_release( p_vout );
835 menu->addSeparator();
837 vlc_object_hold( p_input );
838 InputAutoMenuBuilder( VLC_OBJECT( p_input ), objects, varnames );
839 vlc_object_release( p_input );
841 submenu = new QMenu( menu );
842 action = menu->addMenu( AudioMenu( p_intf, submenu ) );
843 action->setText( qtr( "&Audio" ) );
844 if( action->menu()->isEmpty() )
845 action->setEnabled( false );
847 submenu = new QMenu( menu );
848 action = menu->addMenu( VideoMenu( p_intf, submenu ) );
849 action->setText( qtr( "&Video" ) );
850 if( action->menu()->isEmpty() )
851 action->setEnabled( false );
853 submenu = new QMenu( menu );
854 action = menu->addMenu( NavigMenu( p_intf, submenu ) );
855 action->setText( qtr( "&Playback" ) );
856 if( action->menu()->isEmpty() )
857 action->setEnabled( false );
860 menu->addSeparator();
862 /* Add some special entries for windowed mode: Interface Menu */
863 if( !b_isFullscreen )
865 submenu = new QMenu( qtr( "Interface" ), menu );
868 submenu->addAction( QIcon( ":/playlist" ),
869 qtr( "Show Playlist" ), mi, SLOT( togglePlaylist() ) );
871 addDPStaticEntry( submenu, qtr( I_MENU_EXT ), "",
872 ":/settings", SLOT( extendedDialog() ) );
873 addDPStaticEntry( submenu, qtr( I_MENU_INFO ) , "", ":/info",
874 SLOT( mediaInfoDialog() ), "Ctrl+I" );
877 action = submenu->addAction( QIcon( "" ),
878 qtr( "Minimal View" ), mi, SLOT( toggleMinimalView() ) );
879 action->setCheckable( true );
880 action->setChecked( !( mi->getControlsVisibilityStatus() &
881 CONTROLS_VISIBLE ) );
882 action = submenu->addAction( QIcon( "" ),
883 qtr( "Toggle Fullscreen Interface" ),
884 mi, SLOT( toggleFullScreen() ) );
885 action->setCheckable( true );
886 action->setChecked( mi->isFullScreen() );
888 else /* We are using the skins interface.
889 If not, this entry will not show. */
891 addDPStaticEntry( submenu, qtr( "&Preferences..." ), "",
892 ":/preferences", SLOT( prefsDialog() ), "Ctrl+P" );
893 submenu->addSeparator();
896 vlc_object_t *p_object = ( vlc_object_t* )
897 vlc_object_find( p_intf, VLC_OBJECT_INTF, FIND_PARENT );
900 objects.push_back( p_object );
901 varnames.push_back( "intf-skins" );
902 Populate( p_intf, submenu, varnames, objects );
903 vlc_object_release( p_object );
907 msg_Dbg( p_intf, "could not find parent interface" );
910 menu->addMenu( submenu );
913 PopupMenuStaticEntries( p_intf, menu );
915 p_intf->p_sys->p_popup_menu = menu;
916 p_intf->p_sys->p_popup_menu->popup( QCursor::pos() );
920 // destroy popup if there is one
921 delete p_intf->p_sys->p_popup_menu;
922 p_intf->p_sys->p_popup_menu = NULL;
928 /************************************************************************
930 ************************************************************************/
932 void QVLCMenu::updateSystrayMenu( MainInterface *mi,
933 intf_thread_t *p_intf,
934 bool b_force_visible )
938 /* Get the systray menu and clean it */
939 QMenu *sysMenu = mi->getSysTrayMenu();
942 /* Hide / Show VLC and cone */
943 if( mi->isVisible() || b_force_visible )
945 sysMenu->addAction( QIcon( ":/vlc16.png" ),
946 qtr( "Hide VLC media player in taskbar" ), mi,
947 SLOT( toggleUpdateSystrayMenu() ) );
951 sysMenu->addAction( QIcon( ":/vlc16.png" ),
952 qtr( "Show VLC media player" ), mi,
953 SLOT( toggleUpdateSystrayMenu() ) );
956 sysMenu->addSeparator();
957 PopupMenuControlEntries( sysMenu, p_intf, p_input );
959 sysMenu->addSeparator();
960 addDPStaticEntry( sysMenu, qtr( "&Open Media" ), "",
961 ":/file-wide", SLOT( openFileDialog() ), "" );
962 addDPStaticEntry( sysMenu, qtr( "&Quit" ) , "",
963 ":/quit", SLOT( quit() ), "" );
966 mi->getSysTray()->setContextMenu( sysMenu );
970 #undef PUSH_SEPARATOR
972 /*************************************************************************
973 * Builders for automenus
974 *************************************************************************/
975 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf,
977 vector< const char *> & varnames,
978 vector<vlc_object_t *> & objects,
981 QMenu *menu = current;
982 if( !menu ) menu = new QMenu();
984 /* Disable all non static entries */
986 foreach( p_action, menu->actions() )
988 if( p_action->data().toString() != "_static_" )
989 p_action->setEnabled( false );
994 vlc_object_t *p_object;
997 for( i = 0; i < ( int )objects.size() ; i++ )
999 if( !varnames[i] || !*varnames[i] )
1001 menu->addSeparator();
1004 p_object = objects[i];
1006 UpdateItem( p_intf, menu, varnames[i], p_object, true );
1011 /*****************************************************************************
1013 *****************************************************************************/
1015 static bool IsMenuEmpty( const char *psz_var,
1016 vlc_object_t *p_object,
1017 bool b_root = true )
1019 vlc_value_t val, val_list;
1020 int i_type, i_result, i;
1022 /* Check the type of the object variable */
1023 i_type = var_Type( p_object, psz_var );
1025 /* Check if we want to display the variable */
1026 if( !( i_type & VLC_VAR_HASCHOICE ) ) return false;
1028 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
1029 if( val.i_int == 0 ) return true;
1031 if( ( i_type & VLC_VAR_TYPE ) != VLC_VAR_VARIABLE )
1033 if( val.i_int == 1 && b_root ) return true;
1037 /* Check children variables in case of VLC_VAR_VARIABLE */
1038 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
1043 for( i = 0, i_result = true; i < val_list.p_list->i_count; i++ )
1045 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
1053 /* clean up everything */
1054 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
1059 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
1061 void QVLCMenu::UpdateItem( intf_thread_t *p_intf, QMenu *menu,
1062 const char *psz_var, vlc_object_t *p_object, bool b_submenu )
1064 vlc_value_t val, text;
1067 QAction *action = FindActionWithVar( menu, psz_var );
1069 DeleteNonStaticEntries( action->menu() );
1074 /* Check the type of the object variable */
1075 if( !strcmp( psz_var, "audio-es" )
1076 || !strcmp( psz_var, "video-es" )
1077 || !strcmp( psz_var, "postproc-q" ) )
1078 i_type = VLC_VAR_INTEGER | VLC_VAR_HASCHOICE;
1080 i_type = var_Type( p_object, psz_var );
1082 switch( i_type & VLC_VAR_TYPE )
1086 case VLC_VAR_VARIABLE:
1087 case VLC_VAR_STRING:
1088 case VLC_VAR_INTEGER:
1092 /* Variable doesn't exist or isn't handled */
1096 /* Make sure we want to display the variable */
1097 if( menu->isEmpty() && IsMenuEmpty( psz_var, p_object ) )
1100 /* Get the descriptive name of the variable */
1101 int i_ret = var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
1102 if( i_ret != VLC_SUCCESS )
1104 text.psz_string = NULL;
1109 action = new QAction( TEXT_OR_VAR, menu );
1110 menu->addAction( action );
1111 action->setData( psz_var );
1114 /* Some specific stuff */
1115 bool forceDisabled = false;
1116 if( !strcmp( psz_var, "spu-es" ) )
1118 vlc_object_t *p_vout = ( vlc_object_t* )( vlc_object_find( p_intf,
1119 VLC_OBJECT_VOUT, FIND_ANYWHERE ) );
1120 forceDisabled = ( p_vout == NULL );
1122 vlc_object_release( p_vout );
1125 if( i_type & VLC_VAR_HASCHOICE )
1127 /* Append choices menu */
1131 submenu = action->menu();
1134 submenu = new QMenu( menu );
1135 action->setMenu( submenu );
1139 CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0 );
1141 action->setEnabled( false );
1144 CreateChoicesMenu( menu, psz_var, p_object, true );
1145 FREENULL( text.psz_string );
1149 switch( i_type & VLC_VAR_TYPE )
1152 var_Get( p_object, psz_var, &val );
1153 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
1154 p_object, val, i_type );
1158 var_Get( p_object, psz_var, &val );
1159 val.b_bool = !val.b_bool;
1160 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
1161 p_object, val, i_type, !val.b_bool );
1164 FREENULL( text.psz_string );
1168 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
1169 vlc_object_t *p_object, bool b_root )
1171 vlc_value_t val, val_list, text_list;
1174 /* Check the type of the object variable */
1175 i_type = var_Type( p_object, psz_var );
1177 /* Make sure we want to display the variable */
1178 if( submenu->isEmpty() && IsMenuEmpty( psz_var, p_object, b_root ) )
1179 return VLC_EGENERIC;
1181 switch( i_type & VLC_VAR_TYPE )
1185 case VLC_VAR_VARIABLE:
1186 case VLC_VAR_STRING:
1187 case VLC_VAR_INTEGER:
1191 /* Variable doesn't exist or isn't handled */
1192 return VLC_EGENERIC;
1195 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
1196 &val_list, &text_list ) < 0 )
1198 return VLC_EGENERIC;
1201 #define CURVAL val_list.p_list->p_values[i]
1202 #define CURTEXT text_list.p_list->p_values[i].psz_string
1204 for( i = 0; i < val_list.p_list->i_count; i++ )
1206 vlc_value_t another_val;
1208 QMenu *subsubmenu = new QMenu( submenu );
1210 switch( i_type & VLC_VAR_TYPE )
1212 case VLC_VAR_VARIABLE:
1213 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
1214 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
1215 submenu->addMenu( subsubmenu );
1218 case VLC_VAR_STRING:
1219 var_Get( p_object, psz_var, &val );
1220 another_val.psz_string = strdup( CURVAL.psz_string );
1221 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
1222 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1223 p_object, another_val, i_type,
1224 val.psz_string && !strcmp( val.psz_string, CURVAL.psz_string ) );
1226 free( val.psz_string );
1229 case VLC_VAR_INTEGER:
1230 var_Get( p_object, psz_var, &val );
1231 if( CURTEXT ) menutext = qfu( CURTEXT );
1232 else menutext.sprintf( "%d", CURVAL.i_int );
1233 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1234 p_object, CURVAL, i_type,
1235 CURVAL.i_int == val.i_int );
1239 var_Get( p_object, psz_var, &val );
1240 if( CURTEXT ) menutext = qfu( CURTEXT );
1241 else menutext.sprintf( "%.2f", CURVAL.f_float );
1242 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1243 p_object, CURVAL, i_type,
1244 CURVAL.f_float == val.f_float );
1251 currentGroup = NULL;
1253 /* clean up everything */
1254 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
1261 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
1262 QString text, QString help,
1263 int i_item_type, vlc_object_t *p_obj,
1264 vlc_value_t val, int i_val_type,
1267 QAction *action = FindActionWithVar( menu, psz_var );
1270 action = new QAction( text, menu );
1271 menu->addAction( action );
1274 action->setToolTip( help );
1275 action->setEnabled( p_obj != NULL );
1277 if( i_item_type == ITEM_CHECK )
1279 action->setCheckable( true );
1281 else if( i_item_type == ITEM_RADIO )
1283 action->setCheckable( true );
1285 currentGroup = new QActionGroup( menu );
1286 currentGroup->addAction( action );
1289 action->setChecked( checked );
1291 MenuItemData *itemData = new MenuItemData( THEDP->menusMapper, p_obj, i_val_type,
1293 CONNECT( action, triggered(), THEDP->menusMapper, map() );
1294 THEDP->menusMapper->setMapping( action, itemData );
1295 menu->addAction( action );
1298 void QVLCMenu::DoAction( intf_thread_t *p_intf, QObject *data )
1300 MenuItemData *itemData = qobject_cast<MenuItemData *>( data );
1301 vlc_object_t *p_object = itemData->p_obj;
1302 if( p_object == NULL ) return;
1304 var_Set( p_object, itemData->psz_var, itemData->val );
1307 void QVLCMenu::updateRecents( intf_thread_t *p_intf )
1312 RecentsMRL* rmrl = RecentsMRL::getInstance( p_intf );
1313 QList<QString> l = rmrl->recents();
1315 recentsMenu->clear();
1318 action = recentsMenu->addAction( " - Empty - " );
1319 action->setEnabled( false );
1323 for( int i = 0; i < l.size(); ++i )
1325 action = recentsMenu->addAction( l.at( i ),
1328 rmrl->signalMapper->setMapping( action, l.at( i ) );
1331 recentsMenu->addSeparator();
1332 recentsMenu->addAction( "Clear", rmrl, SLOT( clear() ) );