1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright © 2006-2009 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_intf_strings.h>
35 #include <vlc_services_discovery.h>
39 #include "main_interface.hpp" /* View modifications */
40 #include "dialogs_provider.hpp" /* Dialogs display */
41 #include "input_manager.hpp" /* Input Management */
42 #include "recents.hpp" /* Recent Items */
43 #include "actions_manager.hpp"
48 #include <QActionGroup>
49 #include <QSignalMapper>
50 #include <QSystemTrayIcon>
54 This file defines the main menus and the pop-up menu (right-click menu)
55 and the systray menu (in that order in the file)
57 There are 3 menus that have to be rebuilt everytime there are called:
58 Audio, Video, Navigation
59 3 functions are building those menus: AudioMenu, VideoMenu, NavigMenu
60 and 3 functions associated are collecting the objects :
61 InputAutoMenuBuilder, AudioAutoMenuBuilder, VideoAutoMenuBuilder.
63 A QSignalMapper decides when to rebuild those menus cf MenuFunc in the .hpp
64 Just before one of those menus are aboutToShow(), they are rebuild.
74 static QActionGroup *currentGroup;
76 /* HACK for minimalView to go around a Qt bug/feature
77 * that doesn't update the QAction checked state when QMenu is hidden */
78 QAction *QVLCMenu::minimalViewAction = NULL;
79 QAction *QVLCMenu::fullscreenViewAction = NULL;
81 QMenu *QVLCMenu::recentsMenu = NULL;
83 /****************************************************************************
85 ****************************************************************************
86 * Add static entries to DP in menus
87 ***************************************************************************/
88 void addDPStaticEntry( QMenu *menu,
92 const char *shortcut = NULL )
94 QAction *action = NULL;
95 if( !EMPTY_STR( icon ) > 0 )
97 if( !EMPTY_STR( shortcut ) > 0 )
98 action = menu->addAction( QIcon( icon ), text, THEDP,
99 member, qtr( shortcut ) );
101 action = menu->addAction( QIcon( icon ), text, THEDP, member );
105 if( !EMPTY_STR( shortcut ) > 0 )
106 action = menu->addAction( text, THEDP, member, qtr( shortcut ) );
108 action = menu->addAction( text, THEDP, member );
110 action->setData( true );
114 * @brief Enable all static entries, disable the others
115 * @param enable if false, disable all entries
117 void EnableStaticEntries( QMenu *menu, bool enable = true )
121 QList< QAction* > actions = menu->actions();
122 for( int i = 0; i < actions.size(); ++i )
124 actions[i]->setEnabled( enable && actions[i]->data().toBool() );
129 * \return Number of static entries
131 int DeleteNonStaticEntries( QMenu *menu )
136 QList< QAction* > actions = menu->actions();
137 for( int i = 0; i < actions.size(); ++i )
139 if( !actions[i]->data().toBool() )
150 void addMIMStaticEntry( intf_thread_t *p_intf,
156 if( strlen( icon ) > 0 )
158 QAction *action = menu->addAction( text, THEMIM, member );
159 action->setIcon( QIcon( icon ) );
163 menu->addAction( text, THEMIM, member );
167 /*****************************************************************************
168 * Definitions of variables for the dynamic menus
169 *****************************************************************************/
170 #define PUSH_VAR( var ) varnames.push_back( var ); \
171 objects.push_back( VLC_OBJECT(p_object) )
173 #define PUSH_INPUTVAR( var ) varnames.push_back( var ); \
174 objects.push_back( VLC_OBJECT(p_input) );
176 #define PUSH_SEPARATOR if( objects.size() != i_last_separator ) { \
177 objects.push_back( 0 ); varnames.push_back( "" ); \
178 i_last_separator = objects.size(); }
180 static int InputAutoMenuBuilder( input_thread_t *p_object,
181 vector<vlc_object_t *> &objects,
182 vector<const char *> &varnames )
184 PUSH_VAR( "bookmark" );
186 PUSH_VAR( "chapter" );
187 PUSH_VAR( "navigation" );
188 PUSH_VAR( "program" );
189 PUSH_VAR( "dvd_menus" );
193 static int VideoAutoMenuBuilder( vout_thread_t *p_object,
194 input_thread_t *p_input,
195 vector<vlc_object_t *> &objects,
196 vector<const char *> &varnames )
198 PUSH_INPUTVAR( "video-es" );
199 PUSH_INPUTVAR( "spu-es" );
200 PUSH_VAR( "fullscreen" );
201 PUSH_VAR( "video-on-top" );
203 PUSH_VAR( "directx-wallpaper" );
205 PUSH_VAR( "video-snapshot" );
207 PUSH_VAR( "autoscale" );
208 PUSH_VAR( "aspect-ratio" );
210 PUSH_VAR( "deinterlace" );
212 /* Special case for postproc */
216 /* p_object is the vout, so the decoder is our parent and the
217 * postproc filter one of the decoder's children */
218 vlc_object_t *p_dec = (vlc_object_t *)
219 vlc_object_find( p_object, VLC_OBJECT_DECODER,
223 vlc_object_t *p_pp = (vlc_object_t *)
224 vlc_object_find_name( p_dec, "postproc",
228 vlc_object_t *p_object = p_pp;
229 PUSH_VAR( "postproc-q" );
230 vlc_object_release( p_pp );
233 vlc_object_release( p_dec );
240 static int AudioAutoMenuBuilder( aout_instance_t *p_object,
241 input_thread_t *p_input,
242 vector<vlc_object_t *> &objects,
243 vector<const char *> &varnames )
245 PUSH_INPUTVAR( "audio-es" );
246 PUSH_VAR( "audio-channels" );
247 PUSH_VAR( "audio-device" );
248 PUSH_VAR( "visual" );
252 static QAction * FindActionWithVar( QMenu *menu, const char *psz_var )
254 QList< QAction* > actions = menu->actions();
255 for( int i = 0; i < actions.size(); ++i )
257 if( actions[i]->data().toString() == psz_var )
263 /*****************************************************************************
266 *****************************************************************************/
268 #define BAR_ADD( func, title ) { \
269 QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); }
271 #define BAR_DADD( func, title, id ) { \
272 QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); \
273 MenuFunc *f = new MenuFunc( _menu, id ); \
274 CONNECT( _menu, aboutToShow(), THEDP->menusUpdateMapper, map() ); \
275 THEDP->menusUpdateMapper->setMapping( _menu, f ); }
277 #define ACT_ADD( _menu, val, title ) { \
278 QAction *_action = new QAction( title, _menu ); _action->setData( val ); \
279 _menu->addAction( _action ); }
281 #define ACT_ADDMENU( _menu, val, title ) { \
282 QAction *_action = new QAction( title, _menu ); _action->setData( val ); \
283 _action->setMenu( new QMenu() ); _menu->addAction( _action ); }
285 #define ACT_ADDCHECK( _menu, val, title ) { \
286 QAction *_action = new QAction( title, _menu ); _action->setData( val ); \
287 _action->setCheckable( true ); _menu->addAction( _action ); }
290 * Main Menu Bar Creation
292 void QVLCMenu::createMenuBar( MainInterface *mi,
293 intf_thread_t *p_intf,
294 bool visual_selector_enabled )
295 /* FIXME remove this visual dependency */
297 /* QMainWindows->menuBar()
298 gives the QProcess::destroyed timeout issue on Cleanlooks style with
299 setDesktopAware set to false */
300 QMenuBar *bar = mi->menuBar();
301 BAR_ADD( FileMenu( p_intf, bar ), qtr( "&Media" ) );
303 BAR_DADD( NavigMenu( p_intf, bar ), qtr( "P&layback" ), 3 );
304 BAR_DADD( AudioMenu( p_intf, bar ), qtr( "&Audio" ), 1 );
305 BAR_DADD( VideoMenu( p_intf, bar ), qtr( "&Video" ), 2 );
307 BAR_ADD( ToolsMenu( bar ), qtr( "&Tools" ) );
308 BAR_ADD( ViewMenu( p_intf, NULL, mi, visual_selector_enabled, true ),
311 BAR_ADD( HelpMenu( bar ), qtr( "&Help" ) );
317 * Media ( File ) Menu
318 * Opening, streaming and quit
320 QMenu *QVLCMenu::FileMenu( intf_thread_t *p_intf, QWidget *parent )
322 QMenu *menu = new QMenu( parent );
324 addDPStaticEntry( menu, qtr( "&Open File..." ),
325 ":/file-asym", SLOT( simpleOpenDialog() ), "Ctrl+O" );
326 addDPStaticEntry( menu, qtr( "Advanced Open File..." ),
327 ":/file-asym", SLOT( openFileDialog() ), "Ctrl+Shift+O" );
328 addDPStaticEntry( menu, qtr( I_OPEN_FOLDER ),
329 ":/folder-grey", SLOT( PLOpenDir() ), "Ctrl+F" );
330 addDPStaticEntry( menu, qtr( "Open &Disc..." ),
331 ":/disc", SLOT( openDiscDialog() ), "Ctrl+D" );
332 addDPStaticEntry( menu, qtr( "Open &Network..." ),
333 ":/network", SLOT( openNetDialog() ), "Ctrl+N" );
334 addDPStaticEntry( menu, qtr( "Open &Capture Device..." ),
335 ":/capture-card", SLOT( openCaptureDialog() ),
338 menu->addSeparator();
339 addDPStaticEntry( menu, qtr( "Paste &MRL" ),
340 NULL, SLOT( openUrlDialog() ), "Ctrl+V" );
342 recentsMenu = new QMenu( qtr( "&Recent Media" ), menu );
343 updateRecents( p_intf );
344 menu->addMenu( recentsMenu );
345 menu->addSeparator();
346 menu->addMenu( SDMenu( p_intf, menu ) );
347 menu->addSeparator();
349 addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", SLOT( saveAPlaylist() ),
351 menu->addSeparator();
353 addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "",
354 SLOT( openAndTranscodingDialogs() ), "Ctrl+R" );
355 addDPStaticEntry( menu, qtr( "&Streaming..." ),
356 ":/stream", SLOT( openAndStreamingDialogs() ),
358 menu->addSeparator();
360 addDPStaticEntry( menu, qtr( "&Quit" ) ,
361 ":/quit", SLOT( quit() ), "Ctrl+Q" );
365 /* Playlist/MediaLibrary Control */
366 QMenu *QVLCMenu::ToolsMenu( QMenu *menu )
368 addDPStaticEntry( menu, qtr( I_MENU_EXT ), ":/settings",
369 SLOT( extendedDialog() ), "Ctrl+E" );
371 addDPStaticEntry( menu, qtr( I_MENU_INFO ) , ":/info",
372 SLOT( mediaInfoDialog() ), "Ctrl+I" );
373 addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) ,
374 ":/info", SLOT( mediaCodecDialog() ), "Ctrl+J" );
376 addDPStaticEntry( menu, qtr( I_MENU_BOOKMARK ),"",
377 SLOT( bookmarksDialog() ), "Ctrl+B" );
379 addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", SLOT( vlmDialog() ),
383 addDPStaticEntry( menu, qtr( I_MENU_MSG ),
384 ":/messages", SLOT( messagesDialog() ),
387 addDPStaticEntry( menu, qtr( "Plu&gins and extensions" ),
388 "", SLOT( pluginDialog() ) );
389 menu->addSeparator();
391 addDPStaticEntry( menu, qtr( "&Preferences" ),
392 ":/preferences", SLOT( prefsDialog() ), "Ctrl+P" );
397 QMenu *QVLCMenu::ToolsMenu( QWidget *parent )
399 return ToolsMenu( new QMenu( parent ) );
404 * This menu can be an interface menu but also a right click menu.
406 QMenu *QVLCMenu::ViewMenu( intf_thread_t *p_intf,
409 bool visual_selector_enabled,
414 menu = new QMenu( current );
416 menu = new QMenu( mi );
420 act = menu->addAction( QIcon( ":/playlist_menu" ),
421 qtr( "Play&list" ), mi,
422 SLOT( togglePlaylist() ), qtr( "Ctrl+L" ) );
423 act->setData( true );
425 /*menu->addSeparator();
426 menu->addAction( qtr( "Undock from Interface" ), mi,
427 SLOT( undockPlaylist() ), qtr( "Ctrl+U" ) );*/
430 menu->addSeparator();
434 QMenu *intfmenu = InterfacesMenu( p_intf, menu );
435 MenuFunc *f = new MenuFunc( intfmenu, 4 );
436 CONNECT( intfmenu, aboutToShow(), THEDP->menusUpdateMapper, map() );
437 THEDP->menusUpdateMapper->setMapping( intfmenu, f );
438 menu->addSeparator();
443 QAction *action = menu->addAction( qtr( "Mi&nimal View" ), mi,
444 SLOT( toggleMinimalView() ), qtr( "Ctrl+H" ) );
445 action->setCheckable( true );
446 action->setData( true );
447 if( mi->getControlsVisibilityStatus() & CONTROLS_VISIBLE )
448 action->setChecked( true );
449 minimalViewAction = action; /* HACK for minimalView */
451 /* FullScreen View */
452 action = menu->addAction( qtr( "&Fullscreen Interface" ), mi,
453 SLOT( toggleFullScreen() ), QString( "F11" ) );
454 fullscreenViewAction = action;
455 action->setCheckable( true );
456 action->setData( true );
458 /* Advanced Controls */
459 action = menu->addAction( qtr( "&Advanced Controls" ), mi,
460 SLOT( toggleAdvanced() ) );
461 action->setCheckable( true );
462 action->setData( true );
463 if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
464 action->setChecked( true );
465 #if 0 /* For Visualisations. Not yet working */
466 adv = menu->addAction( qtr( "Visualizations selector" ),
467 mi, SLOT( visual() ) );
468 adv->setCheckable( true );
469 if( visual_selector_enabled ) adv->setChecked( true );
473 menu->addSeparator();
474 addDPStaticEntry( menu, qtr( "Customi&ze Interface..." ),
475 ":/preferences", SLOT( toolbarDialog() ) );
476 menu->addSeparator();
482 * Interface Sub-Menu, to list extras interface and skins
484 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
486 vector<vlc_object_t *> objects;
487 vector<const char *> varnames;
488 /** \todo add "switch to XXX" */
489 varnames.push_back( "intf-add" );
490 objects.push_back( VLC_OBJECT(p_intf) );
492 return Populate( p_intf, current, varnames, objects );
498 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
500 vector<vlc_object_t *> objects;
501 vector<const char *> varnames;
502 aout_instance_t *p_aout;
503 input_thread_t *p_input;
505 if( current->isEmpty() )
507 ACT_ADDMENU( current, "audio-es", qtr( "Audio &Track" ) );
508 ACT_ADDMENU( current, "audio-channels", qtr( "Audio &Channels" ) );
509 ACT_ADDMENU( current, "audio-device", qtr( "Audio &Device" ) );
510 current->addSeparator();
512 ACT_ADDMENU( current, "visual", qtr( "&Visualizations" ) );
513 current->addSeparator();
515 QAction *action = current->addAction( qtr( "Increase Volume" ),
516 ActionsManager::getInstance( p_intf ), SLOT( AudioUp() ) );
517 action->setData( true );
518 action = current->addAction( qtr( "Decrease Volume" ),
519 ActionsManager::getInstance( p_intf ), SLOT( AudioDown() ) );
520 action->setData( true );
521 action = current->addAction( qtr( "Mute" ),
522 ActionsManager::getInstance( p_intf ), SLOT( toggleMuteAudio() ) );
523 action->setData( true );
526 p_input = THEMIM->getInput();
528 vlc_object_hold( p_input );
529 p_aout = THEMIM->getAout();
530 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
531 EnableStaticEntries( current, ( p_aout != NULL ) );
534 vlc_object_release( p_aout );
537 vlc_object_release( p_input );
539 return Populate( p_intf, current, varnames, objects );
542 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QWidget *parent )
544 return AudioMenu( p_intf, new QMenu( parent ) );
549 * Subtitles are part of Video.
551 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
553 vout_thread_t *p_vout;
554 input_thread_t *p_input;
555 vector<vlc_object_t *> objects;
556 vector<const char *> varnames;
558 if( current->isEmpty() )
560 ACT_ADDMENU( current, "video-es", qtr( "Video &Track" ) );
563 QMenu *submenu = new QMenu( qtr( "&Subtitles Track" ), current );
564 action = current->addMenu( submenu );
565 action->setData( "spu-es" );
566 addDPStaticEntry( submenu, qtr( "Open File..." ), "",
567 SLOT( loadSubtitlesFile() ) );
568 submenu->addSeparator();
569 current->addSeparator();
571 ACT_ADDCHECK( current, "fullscreen", qtr( "&Fullscreen" ) );
572 ACT_ADDCHECK( current, "video-on-top", qtr( "Always &On Top" ) );
574 ACT_ADDCHECK( current, "directx-wallpaper", qtr( "DirectX Wallpaper" ) );
576 ACT_ADD( current, "video-snapshot", qtr( "Sna&pshot" ) );
578 current->addSeparator();
580 ACT_ADDMENU( current, "zoom", qtr( "&Zoom" ) );
581 ACT_ADDCHECK( current, "autoscale", qtr( "Sca&le" ) );
582 ACT_ADDMENU( current, "aspect-ratio", qtr( "&Aspect Ratio" ) );
583 ACT_ADDMENU( current, "crop", qtr( "&Crop" ) );
584 ACT_ADDMENU( current, "deinterlace", qtr( "&Deinterlace" ) );
585 ACT_ADDMENU( current, "postproc-q", qtr( "&Post processing" ) );
588 p_input = THEMIM->getInput();
590 vlc_object_hold( p_input );
592 p_vout = THEMIM->getVout();
593 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
594 EnableStaticEntries( current, ( p_vout != NULL ) );
597 vlc_object_release( p_vout );
600 vlc_object_release( p_input );
602 return Populate( p_intf, current, varnames, objects );
605 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QWidget *parent )
607 return VideoMenu( p_intf, new QMenu( parent ) );
612 * For DVD, MP4, MOV and other chapter based format
614 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
616 if( menu->isEmpty() )
618 ACT_ADDMENU( menu, "bookmark", qtr( "&Bookmarks" ) );
619 ACT_ADDMENU( menu, "title", qtr( "T&itle" ) );
620 ACT_ADDMENU( menu, "chapter", qtr( "&Chapter" ) );
621 ACT_ADDMENU( menu, "navigation", qtr( "&Navigation" ) );
622 ACT_ADDMENU( menu, "program", qtr( "&Program" ) );
624 menu->addSeparator();
625 addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ),"",
626 SLOT( gotoTimeDialog() ), "Ctrl+T" );
630 input_thread_t *p_object;
631 vector<vlc_object_t *> objects;
632 vector<const char *> varnames;
634 p_object = THEMIM->getInput();
636 vlc_object_hold( p_object );
637 InputAutoMenuBuilder( p_object, objects, varnames );
638 PUSH_VAR( "prev-title" );
639 PUSH_VAR( "next-title" );
640 PUSH_VAR( "prev-chapter" );
641 PUSH_VAR( "next-chapter" );
642 EnableStaticEntries( menu, ( p_object != NULL ) );
645 vlc_object_release( p_object );
647 return Populate( p_intf, menu, varnames, objects );
650 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QWidget *parent )
652 return NavigMenu( p_intf, new QMenu( parent ) );
656 * Service Discovery SubMenu
658 QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf, QWidget *parent )
660 QMenu *menu = new QMenu( parent );
661 menu->setTitle( qtr( I_PL_SD ) );
662 char **ppsz_longnames;
663 char **ppsz_names = vlc_sd_GetNames( &ppsz_longnames );
667 char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
668 for( ; *ppsz_name; ppsz_name++, ppsz_longname++ )
670 QAction *a = new QAction( qfu( *ppsz_longname ), menu );
671 a->setCheckable( true );
672 if( playlist_IsServicesDiscoveryLoaded( THEPL, *ppsz_name ) )
673 a->setChecked( true );
674 CONNECT( a , triggered(), THEDP->SDMapper, map() );
675 THEDP->SDMapper->setMapping( a, QString( *ppsz_name ) );
676 menu->addAction( a );
678 if( !strcmp( *ppsz_name, "podcast" ) )
680 QAction *b = new QAction( qtr( "Configure podcasts..." ), menu );
681 //b->setEnabled( a->isChecked() );
682 menu->addAction( b );
683 CONNECT( b, triggered(), THEDP, podcastConfigureDialog() );
686 free( *ppsz_longname );
689 free( ppsz_longnames );
696 QMenu *QVLCMenu::HelpMenu( QWidget *parent )
698 QMenu *menu = new QMenu( parent );
699 addDPStaticEntry( menu, qtr( "&Help..." ) ,
700 ":/help", SLOT( helpDialog() ), "F1" );
702 addDPStaticEntry( menu, qtr( "Check for &Updates..." ) , "",
703 SLOT( updateDialog() ) );
705 menu->addSeparator();
706 addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), ":/info",
707 SLOT( aboutDialog() ), "Shift+F1" );
711 /*****************************************************************************
712 * Popup menus - Right Click menus *
713 *****************************************************************************/
714 #define POPUP_BOILERPLATE \
715 unsigned int i_last_separator = 0; \
716 vector<vlc_object_t *> objects; \
717 vector<const char *> varnames; \
718 input_thread_t *p_input = THEMIM->getInput();
720 #define CREATE_POPUP \
721 Populate( p_intf, menu, varnames, objects ); \
722 p_intf->p_sys->p_popup_menu = menu; \
723 menu->popup( QCursor::pos() ); \
724 p_intf->p_sys->p_popup_menu = NULL; \
725 i_last_separator = 0;
727 void QVLCMenu::PopupMenuControlEntries( QMenu *menu,
728 intf_thread_t *p_intf,
729 input_thread_t *p_input )
734 var_Get( p_input, "state", &val );
735 if( val.i_int == PLAYING_S )
736 addMIMStaticEntry( p_intf, menu, qtr( "Pause" ),
737 ":/pause", SLOT( togglePlayPause() ) );
739 addMIMStaticEntry( p_intf, menu, qtr( "Play" ),
740 ":/play", SLOT( togglePlayPause() ) );
742 else if( THEPL->items.i_size )
743 addMIMStaticEntry( p_intf, menu, qtr( "Play" ),
744 ":/play", SLOT( togglePlayPause() ) );
746 addDPStaticEntry( menu, qtr( "Play" ),
747 ":/play", SLOT( openDialog() ) );
749 addMIMStaticEntry( p_intf, menu, qtr( "Stop" ),
750 ":/stop", SLOT( stop() ) );
751 addMIMStaticEntry( p_intf, menu, qtr( "Previous" ),
752 ":/previous", SLOT( prev() ) );
753 addMIMStaticEntry( p_intf, menu, qtr( "Next" ),
754 ":/next", SLOT( next() ) );
757 void QVLCMenu::PopupMenuStaticEntries( QMenu *menu )
759 QMenu *openmenu = new QMenu( qtr( "Open Media" ), menu );
760 addDPStaticEntry( openmenu, qtr( "&Open File..." ),
761 ":/file-asym", SLOT( openFileDialog() ) );
762 addDPStaticEntry( openmenu, qtr( I_OPEN_FOLDER ),
763 ":/folder-grey", SLOT( PLOpenDir() ) );
764 addDPStaticEntry( openmenu, qtr( "Open &Disc..." ),
765 ":/disc", SLOT( openDiscDialog() ) );
766 addDPStaticEntry( openmenu, qtr( "Open &Network..." ),
767 ":/network", SLOT( openNetDialog() ) );
768 addDPStaticEntry( openmenu, qtr( "Open &Capture Device..." ),
769 ":/capture-card", SLOT( openCaptureDialog() ) );
770 menu->addMenu( openmenu );
772 menu->addSeparator();
774 QMenu *helpmenu = HelpMenu( menu );
775 helpmenu->setTitle( qtr( "Help" ) );
776 menu->addMenu( helpmenu );
779 addDPStaticEntry( menu, qtr( "Quit" ), ":/quit",
780 SLOT( quit() ), "Ctrl+Q" );
783 /* Video Tracks and Subtitles tracks */
784 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
789 vlc_object_hold( p_input );
790 vout_thread_t *p_vout = THEMIM->getVout();
793 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
794 vlc_object_release( p_vout );
796 vlc_object_release( p_input );
798 QMenu *menu = new QMenu();
803 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
808 vlc_object_hold( p_input );
809 aout_instance_t *p_aout = THEMIM->getAout();
810 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
812 vlc_object_release( p_aout );
813 vlc_object_release( p_input );
815 QMenu *menu = new QMenu();
819 /* Navigation stuff, and general menus ( open ) */
820 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
826 vlc_object_hold( p_input );
827 varnames.push_back( "audio-es" );
828 InputAutoMenuBuilder( p_input, objects, varnames );
832 QMenu *menu = new QMenu();
833 Populate( p_intf, menu, varnames, objects );
835 menu->addSeparator();
836 PopupMenuControlEntries( menu, p_intf, p_input );
838 menu->addSeparator();
839 PopupMenuStaticEntries( menu );
841 p_intf->p_sys->p_popup_menu = menu;
842 menu->popup( QCursor::pos() );
843 p_intf->p_sys->p_popup_menu = NULL;
846 /* Main Menu that sticks everything together */
847 void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
849 MainInterface *mi = p_intf->p_sys->p_mi;
852 /* Delete and recreate a popup if there is one */
853 if( p_intf->p_sys->p_popup_menu )
854 delete p_intf->p_sys->p_popup_menu;
856 QMenu *menu = new QMenu();
859 bool b_isFullscreen = false;
863 PopupMenuControlEntries( menu, p_intf, p_input );
864 menu->addSeparator();
868 vout_thread_t *p_vout = THEMIM->getVout();
870 /* Add a fullscreen switch button */
874 var_Get( p_vout, "fullscreen", &val );
875 b_isFullscreen = !( !val.b_bool );
877 CreateAndConnect( menu, "fullscreen",
878 qtr( "Leave Fullscreen" ),"" , ITEM_NORMAL,
879 VLC_OBJECT(p_vout), val, VLC_VAR_BOOL,
881 vlc_object_release( p_vout );
884 menu->addSeparator();
887 vlc_object_hold( p_input );
888 InputAutoMenuBuilder( p_input, objects, varnames );
889 vlc_object_release( p_input );
892 submenu = new QMenu( menu );
893 action = menu->addMenu( AudioMenu( p_intf, submenu ) );
894 action->setText( qtr( "&Audio" ) );
895 if( action->menu()->isEmpty() )
896 action->setEnabled( false );
899 submenu = new QMenu( menu );
900 action = menu->addMenu( VideoMenu( p_intf, submenu ) );
901 action->setText( qtr( "&Video" ) );
902 if( action->menu()->isEmpty() )
903 action->setEnabled( false );
905 /* Playback menu for chapters */
906 submenu = new QMenu( menu );
907 action = menu->addMenu( NavigMenu( p_intf, submenu ) );
908 action->setText( qtr( "&Playback" ) );
909 if( action->menu()->isEmpty() )
910 action->setEnabled( false );
913 menu->addSeparator();
915 /* Add some special entries for windowed mode: Interface Menu */
916 if( !b_isFullscreen )
918 submenu = new QMenu( qtr( "Interface" ), menu );
921 submenu->addAction( QIcon( ":/playlist" ),
922 qtr( "Show Playlist" ), mi, SLOT( togglePlaylist() ) );
923 action = submenu->addAction( QIcon( "" ),
924 qtr( "Minimal View" ), mi, SLOT( toggleMinimalView() ) );
925 action->setCheckable( true );
926 action->setChecked( !( mi->getControlsVisibilityStatus() &
927 CONTROLS_VISIBLE ) );
928 action = submenu->addAction( QIcon( "" ),
929 qtr( "Fullscreen Interface" ),
930 mi, SLOT( toggleFullScreen() ) );
931 action->setCheckable( true );
932 action->setChecked( mi->isFullScreen() );
934 else /* We are using the skins interface.
935 If not, this entry will not show. */
938 QMenu *tools = ToolsMenu( submenu );
939 submenu->addSeparator();
942 vlc_object_t *p_object = ( vlc_object_t* )
943 vlc_object_find_name( p_intf, "skins2", FIND_PARENT );
946 objects.push_back( p_object );
947 varnames.push_back( "intf-skins" );
948 Populate( p_intf, submenu, varnames, objects );
949 vlc_object_release( p_object );
952 msg_Dbg( p_intf, "could not find parent interface" );
954 menu->addMenu( submenu );
957 /* Static entries for ending, like open */
958 PopupMenuStaticEntries( menu );
960 p_intf->p_sys->p_popup_menu = menu;
961 p_intf->p_sys->p_popup_menu->popup( QCursor::pos() );
965 // destroy popup if there is one
966 delete p_intf->p_sys->p_popup_menu;
967 p_intf->p_sys->p_popup_menu = NULL;
975 /************************************************************************
977 ************************************************************************/
979 void QVLCMenu::updateSystrayMenu( MainInterface *mi,
980 intf_thread_t *p_intf,
981 bool b_force_visible )
985 /* Get the systray menu and clean it */
986 QMenu *sysMenu = mi->getSysTrayMenu();
989 /* Hide / Show VLC and cone */
990 if( mi->isVisible() || b_force_visible )
992 sysMenu->addAction( QIcon( ":/vlc16.png" ),
993 qtr( "Hide VLC media player in taskbar" ), mi,
994 SLOT( toggleUpdateSystrayMenu() ) );
998 sysMenu->addAction( QIcon( ":/vlc16.png" ),
999 qtr( "Show VLC media player" ), mi,
1000 SLOT( toggleUpdateSystrayMenu() ) );
1003 sysMenu->addSeparator();
1004 PopupMenuControlEntries( sysMenu, p_intf, p_input );
1006 sysMenu->addSeparator();
1007 addDPStaticEntry( sysMenu, qtr( "&Open Media" ),
1008 ":/file-wide", SLOT( openFileDialog() ) );
1009 addDPStaticEntry( sysMenu, qtr( "&Quit" ) ,
1010 ":/quit", SLOT( quit() ) );
1013 mi->getSysTray()->setContextMenu( sysMenu );
1017 #undef PUSH_SEPARATOR
1019 /*************************************************************************
1020 * Builders for automenus
1021 *************************************************************************/
1022 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf,
1024 vector< const char *> & varnames,
1025 vector<vlc_object_t *> & objects )
1027 QMenu *menu = current;
1030 msg_Warn( p_intf, "%s leaking a menu", __func__ );
1034 currentGroup = NULL;
1036 vlc_object_t *p_object;
1038 for( int i = 0; i < ( int )objects.size() ; i++ )
1040 if( !varnames[i] || !*varnames[i] )
1042 menu->addSeparator();
1045 p_object = objects[i];
1047 UpdateItem( p_intf, menu, varnames[i], p_object, true );
1052 /*****************************************************************************
1054 *****************************************************************************/
1056 static bool IsMenuEmpty( const char *psz_var,
1057 vlc_object_t *p_object,
1058 bool b_root = true )
1060 vlc_value_t val, val_list;
1061 int i_type, i_result, i;
1063 /* Check the type of the object variable */
1064 i_type = var_Type( p_object, psz_var );
1066 /* Check if we want to display the variable */
1067 if( !( i_type & VLC_VAR_HASCHOICE ) ) return false;
1069 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
1070 if( val.i_int == 0 ) return true;
1072 if( ( i_type & VLC_VAR_TYPE ) != VLC_VAR_VARIABLE )
1074 if( val.i_int == 1 && b_root ) return true;
1078 /* Check children variables in case of VLC_VAR_VARIABLE */
1079 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
1084 for( i = 0, i_result = true; i < val_list.p_list->i_count; i++ )
1086 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
1094 /* clean up everything */
1095 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
1100 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
1102 void QVLCMenu::UpdateItem( intf_thread_t *p_intf, QMenu *menu,
1103 const char *psz_var, vlc_object_t *p_object, bool b_submenu )
1105 vlc_value_t val, text;
1108 QAction *action = FindActionWithVar( menu, psz_var );
1110 DeleteNonStaticEntries( action->menu() );
1115 action->setEnabled( false );
1119 /* Check the type of the object variable */
1120 /* What is the following HACK needed for? */
1121 if( !strcmp( psz_var, "audio-es" )
1122 || !strcmp( psz_var, "video-es" )
1123 || !strcmp( psz_var, "postproc-q" ) )
1124 i_type = VLC_VAR_INTEGER | VLC_VAR_HASCHOICE;
1126 i_type = var_Type( p_object, psz_var );
1128 switch( i_type & VLC_VAR_TYPE )
1132 case VLC_VAR_VARIABLE:
1133 case VLC_VAR_STRING:
1134 case VLC_VAR_INTEGER:
1138 /* Variable doesn't exist or isn't handled */
1140 action->setEnabled( false );
1144 /* Make sure we want to display the variable */
1145 if( menu->isEmpty() && IsMenuEmpty( psz_var, p_object ) )
1148 action->setEnabled( false );
1152 /* Get the descriptive name of the variable */
1153 int i_ret = var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
1154 if( i_ret != VLC_SUCCESS )
1156 text.psz_string = NULL;
1161 action = new QAction( TEXT_OR_VAR, menu );
1162 menu->addAction( action );
1163 action->setData( psz_var );
1166 /* Some specific stuff */
1167 bool forceDisabled = false;
1168 if( !strcmp( psz_var, "spu-es" ) )
1170 vout_thread_t *p_vout = THEMIM->getVout();
1171 forceDisabled = ( p_vout == NULL );
1173 vlc_object_release( p_vout );
1176 if( i_type & VLC_VAR_HASCHOICE )
1178 /* Append choices menu */
1182 submenu = action->menu();
1185 submenu = new QMenu( menu );
1186 action->setMenu( submenu );
1190 CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0 );
1192 action->setEnabled( false );
1197 CreateChoicesMenu( menu, psz_var, p_object, true ) == 0 );
1199 FREENULL( text.psz_string );
1203 switch( i_type & VLC_VAR_TYPE )
1206 var_Get( p_object, psz_var, &val );
1207 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
1208 p_object, val, i_type );
1212 var_Get( p_object, psz_var, &val );
1213 val.b_bool = !val.b_bool;
1214 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
1215 p_object, val, i_type, !val.b_bool );
1218 FREENULL( text.psz_string );
1222 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
1223 vlc_object_t *p_object, bool b_root )
1225 vlc_value_t val, val_list, text_list;
1228 /* Check the type of the object variable */
1229 i_type = var_Type( p_object, psz_var );
1231 /* Make sure we want to display the variable */
1232 if( submenu->isEmpty() && IsMenuEmpty( psz_var, p_object, b_root ) )
1233 return VLC_EGENERIC;
1235 switch( i_type & VLC_VAR_TYPE )
1239 case VLC_VAR_VARIABLE:
1240 case VLC_VAR_STRING:
1241 case VLC_VAR_INTEGER:
1245 /* Variable doesn't exist or isn't handled */
1246 return VLC_EGENERIC;
1249 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
1250 &val_list, &text_list ) < 0 )
1252 return VLC_EGENERIC;
1255 #define CURVAL val_list.p_list->p_values[i]
1256 #define CURTEXT text_list.p_list->p_values[i].psz_string
1258 for( i = 0; i < val_list.p_list->i_count; i++ )
1260 vlc_value_t another_val;
1262 QMenu *subsubmenu = new QMenu( submenu );
1264 switch( i_type & VLC_VAR_TYPE )
1266 case VLC_VAR_VARIABLE:
1267 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
1268 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
1269 submenu->addMenu( subsubmenu );
1272 case VLC_VAR_STRING:
1273 var_Get( p_object, psz_var, &val );
1274 another_val.psz_string = strdup( CURVAL.psz_string );
1275 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
1276 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1277 p_object, another_val, i_type,
1278 val.psz_string && !strcmp( val.psz_string, CURVAL.psz_string ) );
1280 free( val.psz_string );
1283 case VLC_VAR_INTEGER:
1284 var_Get( p_object, psz_var, &val );
1285 if( CURTEXT ) menutext = qfu( CURTEXT );
1286 else menutext.sprintf( "%d", CURVAL.i_int );
1287 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1288 p_object, CURVAL, i_type,
1289 CURVAL.i_int == val.i_int );
1293 var_Get( p_object, psz_var, &val );
1294 if( CURTEXT ) menutext = qfu( CURTEXT );
1295 else menutext.sprintf( "%.2f", CURVAL.f_float );
1296 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1297 p_object, CURVAL, i_type,
1298 CURVAL.f_float == val.f_float );
1305 currentGroup = NULL;
1307 /* clean up everything */
1308 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
1312 return submenu->isEmpty() ? VLC_EGENERIC : VLC_SUCCESS;
1315 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
1316 QString text, QString help,
1317 int i_item_type, vlc_object_t *p_obj,
1318 vlc_value_t val, int i_val_type,
1321 QAction *action = FindActionWithVar( menu, psz_var );
1326 action = new QAction( text, menu );
1327 menu->addAction( action );
1331 action->setToolTip( help );
1332 action->setEnabled( p_obj != NULL );
1334 if( i_item_type == ITEM_CHECK )
1336 action->setCheckable( true );
1338 else if( i_item_type == ITEM_RADIO )
1340 action->setCheckable( true );
1342 currentGroup = new QActionGroup( menu );
1343 currentGroup->addAction( action );
1346 action->setChecked( checked );
1348 MenuItemData *itemData = new MenuItemData( THEDP->menusMapper, p_obj, i_val_type,
1350 CONNECT( action, triggered(), THEDP->menusMapper, map() );
1351 THEDP->menusMapper->setMapping( action, itemData );
1354 menu->addAction( action );
1357 void QVLCMenu::DoAction( QObject *data )
1359 MenuItemData *itemData = qobject_cast<MenuItemData *>( data );
1360 vlc_object_t *p_object = itemData->p_obj;
1361 if( p_object == NULL ) return;
1363 var_Set( p_object, itemData->psz_var, itemData->val );
1366 void QVLCMenu::updateRecents( intf_thread_t *p_intf )
1371 RecentsMRL* rmrl = RecentsMRL::getInstance( p_intf );
1372 QList<QString> l = rmrl->recents();
1374 recentsMenu->clear();
1377 action = recentsMenu->addAction( qtr(" - Empty - ") );
1378 action->setEnabled( false );
1382 for( int i = 0; i < l.size(); ++i )
1384 action = recentsMenu->addAction(
1385 QString( "&%1: " ).arg( i + 1 ) + l.at( i ),
1388 rmrl->signalMapper->setMapping( action, l.at( i ) );
1391 recentsMenu->addSeparator();
1392 recentsMenu->addAction( qtr("&Clear"), rmrl, SLOT( clear() ) );