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_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 */
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,
90 const char *shortcut = NULL )
92 QAction *action = NULL;
93 if( !EMPTY_STR( icon ) > 0 )
95 if( !EMPTY_STR( shortcut ) > 0 )
96 action = menu->addAction( QIcon( icon ), text, THEDP,
97 member, qtr( shortcut ) );
99 action = menu->addAction( QIcon( icon ), text, THEDP, member );
103 if( !EMPTY_STR( shortcut ) > 0 )
104 action = menu->addAction( text, THEDP, member, qtr( shortcut ) );
106 action = menu->addAction( text, THEDP, member );
108 action->setData( true );
111 void EnableDPStaticEntries( QMenu *menu, bool enable = true )
115 QList< QAction* > actions = menu->actions();
116 for( int i = 0; i < actions.size(); ++i )
118 if( actions[i]->data().toBool() )
119 actions[i]->setEnabled( enable );
124 * \return Number of static entries
126 int DeleteNonStaticEntries( QMenu *menu )
131 QList< QAction* > actions = menu->actions();
132 for( int i = 0; i < actions.size(); ++i )
134 if( !actions[i]->data().toBool() )
145 void addMIMStaticEntry( intf_thread_t *p_intf,
151 if( strlen( icon ) > 0 )
153 QAction *action = menu->addAction( text, THEMIM, member );
154 action->setIcon( QIcon( icon ) );
158 menu->addAction( text, THEMIM, member );
162 /*****************************************************************************
163 * Definitions of variables for the dynamic menus
164 *****************************************************************************/
165 #define PUSH_VAR( var ) varnames.push_back( var ); \
166 objects.push_back( VLC_OBJECT(p_object) )
168 #define PUSH_INPUTVAR( var ) varnames.push_back( var ); \
169 objects.push_back( VLC_OBJECT(p_input) );
171 #define PUSH_SEPARATOR if( objects.size() != i_last_separator ) { \
172 objects.push_back( 0 ); varnames.push_back( "" ); \
173 i_last_separator = objects.size(); }
175 static int InputAutoMenuBuilder( input_thread_t *p_object,
176 vector<vlc_object_t *> &objects,
177 vector<const char *> &varnames )
179 PUSH_VAR( "bookmark" );
181 PUSH_VAR( "chapter" );
182 PUSH_VAR( "program" );
183 PUSH_VAR( "navigation" );
184 PUSH_VAR( "dvd_menus" );
188 static int VideoAutoMenuBuilder( vout_thread_t *p_object,
189 input_thread_t *p_input,
190 vector<vlc_object_t *> &objects,
191 vector<const char *> &varnames )
193 PUSH_INPUTVAR( "video-es" );
194 PUSH_INPUTVAR( "spu-es" );
195 PUSH_VAR( "fullscreen" );
197 PUSH_VAR( "scaling" );
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 */
211 /* p_object is the vout, so the decoder is our parent and the
212 * postproc filter one of the decoder's children */
213 vlc_object_t *p_dec = (vlc_object_t *)
214 vlc_object_find( p_object, VLC_OBJECT_DECODER,
218 vlc_object_t *p_pp = (vlc_object_t *)
219 vlc_object_find_name( p_dec, "postproc",
223 vlc_object_t *p_object = p_pp;
224 PUSH_VAR( "postproc-q" );
225 vlc_object_release( p_pp );
228 vlc_object_release( p_dec );
234 static int AudioAutoMenuBuilder( aout_instance_t *p_object,
235 input_thread_t *p_input,
236 vector<vlc_object_t *> &objects,
237 vector<const char *> &varnames )
239 PUSH_INPUTVAR( "audio-es" );
240 PUSH_VAR( "audio-device" );
241 PUSH_VAR( "audio-channels" );
242 PUSH_VAR( "visual" );
246 static QAction * FindActionWithVar( QMenu *menu, const char *psz_var )
248 QList< QAction* > actions = menu->actions();
249 for( int i = 0; i < actions.size(); ++i )
251 if( actions[i]->data().toString() == psz_var )
257 /*****************************************************************************
260 *****************************************************************************/
262 #define BAR_ADD( func, title ) { \
263 QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); }
265 #define BAR_DADD( func, title, id ) { \
266 QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); \
267 MenuFunc *f = new MenuFunc( _menu, id ); \
268 CONNECT( _menu, aboutToShow(), THEDP->menusUpdateMapper, map() ); \
269 THEDP->menusUpdateMapper->setMapping( _menu, f ); }
271 #define ACT_ADD( _menu, val, title ) { \
272 QAction *_action = new QAction( title, _menu ); _action->setData( val ); \
273 _menu->addAction( _action ); }
276 * Main Menu Bar Creation
278 void QVLCMenu::createMenuBar( MainInterface *mi,
279 intf_thread_t *p_intf,
280 bool visual_selector_enabled )
281 /* FIXME remove this visual dependency */
283 /* QMainWindows->menuBar()
284 gives the QProcess::destroyed timeout issue on Cleanlooks style with
285 setDesktopAware set to false */
286 QMenuBar *bar = mi->menuBar();
287 BAR_ADD( FileMenu( p_intf ), qtr( "&Media" ) );
289 BAR_DADD( AudioMenu( p_intf, NULL ), qtr( "&Audio" ), 1 );
290 BAR_DADD( VideoMenu( p_intf, NULL ), qtr( "&Video" ), 2 );
291 BAR_DADD( NavigMenu( p_intf, NULL ), qtr( "P&layback" ), 3 );
293 BAR_ADD( ToolsMenu( p_intf ), qtr( "&Tools" ) );
294 BAR_ADD( ViewMenu( p_intf, NULL, mi, visual_selector_enabled, true ),
297 BAR_ADD( HelpMenu( NULL ), qtr( "&Help" ) );
303 * Media ( File ) Menu
304 * Opening, streaming and quit
306 QMenu *QVLCMenu::FileMenu( intf_thread_t *p_intf )
308 QMenu *menu = new QMenu();
310 addDPStaticEntry( menu, qtr( "&Open File..." ),
311 ":/file-asym", SLOT( simpleOpenDialog() ), "Ctrl+O" );
312 addDPStaticEntry( menu, qtr( "Advanced Open File..." ),
313 ":/file-asym", SLOT( openFileDialog() ), "Ctrl+Shift+O" );
314 addDPStaticEntry( menu, qtr( I_OPEN_FOLDER ),
315 ":/folder-grey", SLOT( PLOpenDir() ), "Ctrl+F" );
316 addDPStaticEntry( menu, qtr( "Open &Disc..." ),
317 ":/disc", SLOT( openDiscDialog() ), "Ctrl+D" );
318 addDPStaticEntry( menu, qtr( "Open &Network..." ),
319 ":/network", SLOT( openNetDialog() ), "Ctrl+N" );
320 addDPStaticEntry( menu, qtr( "Open &Capture Device..." ),
321 ":/capture-card", SLOT( openCaptureDialog() ),
324 menu->addSeparator();
325 addDPStaticEntry( menu, qtr( "Paste &MRL" ),
326 NULL, SLOT( openUrlDialog() ), "Ctrl+V" );
328 addDPStaticEntry( menu, qtr( I_PL_LOAD ), "", SLOT( openAPlaylist() ),
330 addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", SLOT( saveAPlaylist() ),
333 menu->addSeparator();
335 recentsMenu = new QMenu( qtr( "Recently &Played" ), menu );
336 updateRecents( p_intf );
337 menu->addMenu( recentsMenu );
338 menu->addSeparator();
340 addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "",
341 SLOT( openAndTranscodingDialogs() ), "Ctrl+R" );
342 addDPStaticEntry( menu, qtr( "&Streaming..." ),
343 ":/stream", SLOT( openAndStreamingDialogs() ),
345 menu->addSeparator();
347 addDPStaticEntry( menu, qtr( "&Quit" ) ,
348 ":/quit", SLOT( quit() ), "Ctrl+Q" );
352 /* Playlist/MediaLibrary Control */
353 QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf )
355 VLC_UNUSED( p_intf ); //TODO remove
356 QMenu *menu = new QMenu();
358 addDPStaticEntry( menu, qtr( I_MENU_EXT ), ":/settings",
359 SLOT( extendedDialog() ), "Ctrl+E" );
361 addDPStaticEntry( menu, qtr( I_MENU_INFO ) , ":/info",
362 SLOT( mediaInfoDialog() ), "Ctrl+I" );
363 addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) ,
364 ":/info", SLOT( mediaCodecDialog() ), "Ctrl+J" );
366 addDPStaticEntry( menu, qtr( I_MENU_BOOKMARK ),"",
367 SLOT( bookmarksDialog() ), "Ctrl+B" );
369 addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", SLOT( vlmDialog() ),
373 addDPStaticEntry( menu, qtr( I_MENU_MSG ),
374 ":/messages", SLOT( messagesDialog() ),
377 addDPStaticEntry( menu, qtr( "Plu&gins and extensions" ),
378 "", SLOT( pluginDialog() ) );
379 menu->addSeparator();
381 addDPStaticEntry( menu, qtr( "Customi&ze Interface..." ),
382 ":/preferences", SLOT( toolbarDialog() ) );
383 addDPStaticEntry( menu, qtr( "&Preferences" ),
384 ":/preferences", SLOT( prefsDialog() ), "Ctrl+P" );
391 * This is kept in the same menu for now, but could change if it gets much
393 * This menu can be an interface menu but also a right click menu.
395 QMenu *QVLCMenu::ViewMenu( intf_thread_t *p_intf,
398 bool visual_selector_enabled,
401 QMenu *menu = new QMenu( current );
405 act = menu->addAction( QIcon( ":/playlist_menu" ),
406 qtr( "Play&list" ), mi,
407 SLOT( togglePlaylist() ), qtr( "Ctrl+L" ) );
408 act->setData( true );
410 act = menu->addMenu( SDMenu( p_intf ) );
411 act->setData( true );
412 /*menu->addSeparator();
413 menu->addAction( qtr( "Undock from Interface" ), mi,
414 SLOT( undockPlaylist() ), qtr( "Ctrl+U" ) );*/
417 menu->addSeparator();
421 QMenu *intfmenu = InterfacesMenu( p_intf, menu );
422 MenuFunc *f = new MenuFunc( intfmenu, 4 );
423 CONNECT( intfmenu, aboutToShow(), THEDP->menusUpdateMapper, map() );
424 THEDP->menusUpdateMapper->setMapping( intfmenu, f );
425 menu->addSeparator();
430 QAction *action = menu->addAction( qtr( "Mi&nimal View" ), mi,
431 SLOT( toggleMinimalView() ), qtr( "Ctrl+H" ) );
432 action->setCheckable( true );
433 action->setData( true );
434 if( mi->getControlsVisibilityStatus() & CONTROLS_VISIBLE )
435 action->setChecked( true );
436 minimalViewAction = action; /* HACK for minimalView */
438 /* FullScreen View */
439 action = menu->addAction( qtr( "&Fullscreen Interface" ), mi,
440 SLOT( toggleFullScreen() ), QString( "F11" ) );
441 action->setCheckable( true );
442 action->setData( true );
444 /* Advanced Controls */
445 action = menu->addAction( qtr( "&Advanced Controls" ), mi,
446 SLOT( toggleAdvanced() ) );
447 action->setCheckable( true );
448 action->setData( true );
449 if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
450 action->setChecked( true );
451 #if 0 /* For Visualisations. Not yet working */
452 adv = menu->addAction( qtr( "Visualizations selector" ),
453 mi, SLOT( visual() ) );
454 adv->setCheckable( true );
455 if( visual_selector_enabled ) adv->setChecked( true );
459 menu->addSeparator();
465 * Interface Sub-Menu, to list extras interface and skins
467 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
469 vector<vlc_object_t *> objects;
470 vector<const char *> varnames;
471 /** \todo add "switch to XXX" */
472 varnames.push_back( "intf-add" );
473 objects.push_back( VLC_OBJECT(p_intf) );
475 return Populate( p_intf, current, varnames, objects );
481 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
483 vector<vlc_object_t *> objects;
484 vector<const char *> varnames;
485 aout_instance_t *p_aout;
486 input_thread_t *p_input;
488 if( !current ) current = new QMenu();
490 if( current->isEmpty() )
492 ACT_ADD( current, "audio-es", qtr( "Audio &Track" ) );
493 ACT_ADD( current, "audio-device", qtr( "Audio &Device" ) );
494 ACT_ADD( current, "audio-channels", qtr( "Audio &Channels" ) );
495 current->addSeparator();
496 ACT_ADD( current, "visual", qtr( "&Visualizations" ) );
499 p_input = THEMIM->getInput();
501 vlc_object_hold( p_input );
502 p_aout = THEMIM->getAout();
503 EnableDPStaticEntries( current, ( p_aout != NULL ) );
506 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
507 vlc_object_release( p_aout );
510 vlc_object_release( p_input );
512 return Populate( p_intf, current, varnames, objects );
517 * Subtitles are part of Video.
519 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
521 vout_thread_t *p_vout;
522 input_thread_t *p_input;
523 vector<vlc_object_t *> objects;
524 vector<const char *> varnames;
526 if( !current ) current = new QMenu();
528 if( current->isEmpty() )
530 ACT_ADD( current, "video-es", qtr( "Video &Track" ) );
533 QMenu *submenu = new QMenu( qtr( "&Subtitles Track" ), current );
534 action = current->addMenu( submenu );
535 action->setData( "spu-es" );
536 addDPStaticEntry( submenu, qtr( "Open File..." ), "",
537 SLOT( loadSubtitlesFile() ) );
538 submenu->addSeparator();
540 ACT_ADD( current, "fullscreen", qtr( "&Fullscreen" ) );
541 ACT_ADD( current, "zoom", qtr( "&Zoom" ) );
542 ACT_ADD( current, "deinterlace", qtr( "&Deinterlace" ) );
543 ACT_ADD( current, "aspect-ratio", qtr( "&Aspect Ratio" ) );
544 ACT_ADD( current, "crop", qtr( "&Crop" ) );
545 ACT_ADD( current, "video-on-top", qtr( "Always &On Top" ) );
547 ACT_ADD( current, "directx-wallpaper", qtr( "DirectX Wallpaper" ) );
549 ACT_ADD( current, "video-snapshot", qtr( "Sna&pshot" ) );
550 ACT_ADD( current, "postproc-q", qtr( "Post processing" ) );
553 p_input = THEMIM->getInput();
555 vlc_object_hold( p_input );
557 p_vout = THEMIM->getVout();
558 EnableDPStaticEntries( current, ( p_vout != NULL ) );
561 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
562 vlc_object_release( p_vout );
565 vlc_object_release( p_input );
567 return Populate( p_intf, current, varnames, objects );
572 * For DVD, MP4, MOV and other chapter based format
574 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
576 if( !menu ) menu = new QMenu();
578 if( menu->isEmpty() )
580 addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ),"",
581 SLOT( gotoTimeDialog() ), "Ctrl+T" );
582 menu->addSeparator();
584 ACT_ADD( menu, "bookmark", qtr( "&Bookmarks" ) );
585 ACT_ADD( menu, "title", qtr( "T&itle" ) );
586 ACT_ADD( menu, "chapter", qtr( "&Chapter" ) );
587 ACT_ADD( menu, "program", qtr( "&Program" ) );
588 ACT_ADD( menu, "navigation", qtr( "&Navigation" ) );
591 input_thread_t *p_object;
592 vector<vlc_object_t *> objects;
593 vector<const char *> varnames;
595 p_object = THEMIM->getInput();
597 vlc_object_hold( p_object );
598 InputAutoMenuBuilder( p_object, objects, varnames );
599 PUSH_VAR( "prev-title" );
600 PUSH_VAR( "next-title" );
601 PUSH_VAR( "prev-chapter" );
602 PUSH_VAR( "next-chapter" );
603 EnableDPStaticEntries( menu, ( p_object != NULL ) );
606 vlc_object_release( p_object );
608 return Populate( p_intf, menu, varnames, objects );
612 * Service Discovery SubMenu
614 QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf )
616 QMenu *menu = new QMenu();
617 menu->setTitle( qtr( I_PL_SD ) );
618 char **ppsz_longnames;
619 char **ppsz_names = vlc_sd_GetNames( &ppsz_longnames );
623 char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
624 for( ; *ppsz_name; ppsz_name++, ppsz_longname++ )
626 QAction *a = new QAction( qfu( *ppsz_longname ), menu );
627 a->setCheckable( true );
628 if( playlist_IsServicesDiscoveryLoaded( THEPL, *ppsz_name ) )
629 a->setChecked( true );
630 CONNECT( a , triggered(), THEDP->SDMapper, map() );
631 THEDP->SDMapper->setMapping( a, QString( *ppsz_name ) );
632 menu->addAction( a );
634 if( !strcmp( *ppsz_name, "podcast" ) )
636 QAction *b = new QAction( qtr( "Configure podcasts..." ), menu );
637 //b->setEnabled( a->isChecked() );
638 menu->addAction( b );
639 CONNECT( b, triggered(), THEDP, podcastConfigureDialog() );
642 free( *ppsz_longname );
645 free( ppsz_longnames );
651 QMenu *QVLCMenu::HelpMenu( QMenu *current )
653 QMenu *menu = new QMenu( current );
654 addDPStaticEntry( menu, qtr( "&Help..." ) ,
655 ":/help", SLOT( helpDialog() ), "F1" );
657 addDPStaticEntry( menu, qtr( "Check for &Updates..." ) , "",
658 SLOT( updateDialog() ) );
660 menu->addSeparator();
661 addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), ":/info",
662 SLOT( aboutDialog() ), "Shift+F1" );
666 /*****************************************************************************
667 * Popup menus - Right Click menus *
668 *****************************************************************************/
669 #define POPUP_BOILERPLATE \
670 unsigned int i_last_separator = 0; \
671 vector<vlc_object_t *> objects; \
672 vector<const char *> varnames; \
673 input_thread_t *p_input = THEMIM->getInput();
675 #define CREATE_POPUP \
676 Populate( p_intf, menu, varnames, objects ); \
677 p_intf->p_sys->p_popup_menu = menu; \
678 menu->popup( QCursor::pos() ); \
679 p_intf->p_sys->p_popup_menu = NULL; \
680 i_last_separator = 0;
682 void QVLCMenu::PopupMenuControlEntries( QMenu *menu,
683 intf_thread_t *p_intf,
684 input_thread_t *p_input )
689 var_Get( p_input, "state", &val );
690 if( val.i_int == PLAYING_S )
691 addMIMStaticEntry( p_intf, menu, qtr( "Pause" ),
692 ":/pause", SLOT( togglePlayPause() ) );
694 addMIMStaticEntry( p_intf, menu, qtr( "Play" ),
695 ":/play", SLOT( togglePlayPause() ) );
697 else if( THEPL->items.i_size )
698 addMIMStaticEntry( p_intf, menu, qtr( "Play" ),
699 ":/play", SLOT( togglePlayPause() ) );
701 addDPStaticEntry( menu, qtr( "Play" ),
702 ":/play", SLOT( openDialog() ) );
704 addMIMStaticEntry( p_intf, menu, qtr( "Stop" ),
705 ":/stop", SLOT( stop() ) );
706 addMIMStaticEntry( p_intf, menu, qtr( "Previous" ),
707 ":/previous", SLOT( prev() ) );
708 addMIMStaticEntry( p_intf, menu, qtr( "Next" ),
709 ":/next", SLOT( next() ) );
712 void QVLCMenu::PopupMenuStaticEntries( QMenu *menu )
715 QMenu *toolsmenu = ToolsMenu( p_intf, menu, false, true );
716 toolsmenu->setTitle( qtr( "Tools" ) );
717 menu->addMenu( toolsmenu );
720 QMenu *openmenu = new QMenu( qtr( "Open Media" ), menu );
721 addDPStaticEntry( openmenu, qtr( "&Open File..." ),
722 ":/file-asym", SLOT( openFileDialog() ) );
723 addDPStaticEntry( openmenu, qtr( I_OPEN_FOLDER ),
724 ":/folder-grey", SLOT( PLOpenDir() ) );
725 addDPStaticEntry( openmenu, qtr( "Open &Disc..." ),
726 ":/disc", SLOT( openDiscDialog() ) );
727 addDPStaticEntry( openmenu, qtr( "Open &Network..." ),
728 ":/network", SLOT( openNetDialog() ) );
729 addDPStaticEntry( openmenu, qtr( "Open &Capture Device..." ),
730 ":/capture-card", SLOT( openCaptureDialog() ) );
731 menu->addMenu( openmenu );
733 menu->addSeparator();
735 QMenu *helpmenu = HelpMenu( menu );
736 helpmenu->setTitle( qtr( "Help" ) );
737 menu->addMenu( helpmenu );
740 addDPStaticEntry( menu, qtr( "Quit" ), ":/quit",
741 SLOT( quit() ), "Ctrl+Q" );
744 /* Video Tracks and Subtitles tracks */
745 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
750 vlc_object_hold( p_input );
751 vout_thread_t *p_vout = THEMIM->getVout();
754 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
755 vlc_object_release( p_vout );
757 vlc_object_release( p_input );
759 QMenu *menu = new QMenu();
764 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
769 vlc_object_hold( p_input );
770 aout_instance_t *p_aout = THEMIM->getAout();
771 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
773 vlc_object_release( p_aout );
774 vlc_object_release( p_input );
776 QMenu *menu = new QMenu();
780 /* Navigation stuff, and general menus ( open ) */
781 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
787 vlc_object_hold( p_input );
788 varnames.push_back( "audio-es" );
789 InputAutoMenuBuilder( p_input, objects, varnames );
793 QMenu *menu = new QMenu();
794 Populate( p_intf, menu, varnames, objects );
796 menu->addSeparator();
797 PopupMenuControlEntries( menu, p_intf, p_input );
799 menu->addSeparator();
800 PopupMenuStaticEntries( menu );
802 p_intf->p_sys->p_popup_menu = menu;
803 menu->popup( QCursor::pos() );
804 p_intf->p_sys->p_popup_menu = NULL;
807 /* Main Menu that sticks everything together */
808 void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
810 MainInterface *mi = p_intf->p_sys->p_mi;
813 /* Delete and recreate a popup if there is one */
814 if( p_intf->p_sys->p_popup_menu )
815 delete p_intf->p_sys->p_popup_menu;
817 QMenu *menu = new QMenu();
820 bool b_isFullscreen = false;
824 PopupMenuControlEntries( menu, p_intf, p_input );
825 menu->addSeparator();
829 vout_thread_t *p_vout = THEMIM->getVout();
831 /* Add a fullscreen switch button */
835 var_Get( p_vout, "fullscreen", &val );
836 b_isFullscreen = !( !val.b_bool );
838 CreateAndConnect( menu, "fullscreen",
839 qtr( "Leave Fullscreen" ),"" , ITEM_NORMAL,
840 VLC_OBJECT(p_vout), val, VLC_VAR_BOOL,
842 vlc_object_release( p_vout );
845 menu->addSeparator();
847 vlc_object_hold( p_input );
848 InputAutoMenuBuilder( p_input, objects, varnames );
849 vlc_object_release( p_input );
851 submenu = new QMenu( menu );
852 action = menu->addMenu( AudioMenu( p_intf, submenu ) );
853 action->setText( qtr( "&Audio" ) );
854 if( action->menu()->isEmpty() )
855 action->setEnabled( false );
857 submenu = new QMenu( menu );
858 action = menu->addMenu( VideoMenu( p_intf, submenu ) );
859 action->setText( qtr( "&Video" ) );
860 if( action->menu()->isEmpty() )
861 action->setEnabled( false );
863 submenu = new QMenu( menu );
864 action = menu->addMenu( NavigMenu( p_intf, submenu ) );
865 action->setText( qtr( "&Playback" ) );
866 if( action->menu()->isEmpty() )
867 action->setEnabled( false );
870 menu->addSeparator();
872 /* Add some special entries for windowed mode: Interface Menu */
873 if( !b_isFullscreen )
875 submenu = new QMenu( qtr( "Interface" ), menu );
878 submenu->addAction( QIcon( ":/playlist" ),
879 qtr( "Show Playlist" ), mi, SLOT( togglePlaylist() ) );
881 addDPStaticEntry( submenu, qtr( I_MENU_EXT ),
882 ":/settings", SLOT( extendedDialog() ) );
883 addDPStaticEntry( submenu, qtr( I_MENU_INFO ) , ":/info",
884 SLOT( mediaInfoDialog() ), "Ctrl+I" );
887 action = submenu->addAction( QIcon( "" ),
888 qtr( "Minimal View" ), mi, SLOT( toggleMinimalView() ) );
889 action->setCheckable( true );
890 action->setChecked( !( mi->getControlsVisibilityStatus() &
891 CONTROLS_VISIBLE ) );
892 action = submenu->addAction( QIcon( "" ),
893 qtr( "Toggle Fullscreen Interface" ),
894 mi, SLOT( toggleFullScreen() ) );
895 action->setCheckable( true );
896 action->setChecked( mi->isFullScreen() );
898 else /* We are using the skins interface.
899 If not, this entry will not show. */
901 addDPStaticEntry( submenu, qtr( "&Preferences..." ),
902 ":/preferences", SLOT( prefsDialog() ), "Ctrl+P" );
903 submenu->addSeparator();
906 vlc_object_t *p_object = ( vlc_object_t* )
907 vlc_object_find_name( p_intf, "skins2", FIND_PARENT );
910 objects.push_back( p_object );
911 varnames.push_back( "intf-skins" );
912 Populate( p_intf, submenu, varnames, objects );
913 vlc_object_release( p_object );
917 msg_Dbg( p_intf, "could not find parent interface" );
920 menu->addMenu( submenu );
923 PopupMenuStaticEntries( menu );
925 p_intf->p_sys->p_popup_menu = menu;
926 p_intf->p_sys->p_popup_menu->popup( QCursor::pos() );
930 // destroy popup if there is one
931 delete p_intf->p_sys->p_popup_menu;
932 p_intf->p_sys->p_popup_menu = NULL;
938 /************************************************************************
940 ************************************************************************/
942 void QVLCMenu::updateSystrayMenu( MainInterface *mi,
943 intf_thread_t *p_intf,
944 bool b_force_visible )
948 /* Get the systray menu and clean it */
949 QMenu *sysMenu = mi->getSysTrayMenu();
952 /* Hide / Show VLC and cone */
953 if( mi->isVisible() || b_force_visible )
955 sysMenu->addAction( QIcon( ":/vlc16.png" ),
956 qtr( "Hide VLC media player in taskbar" ), mi,
957 SLOT( toggleUpdateSystrayMenu() ) );
961 sysMenu->addAction( QIcon( ":/vlc16.png" ),
962 qtr( "Show VLC media player" ), mi,
963 SLOT( toggleUpdateSystrayMenu() ) );
966 sysMenu->addSeparator();
967 PopupMenuControlEntries( sysMenu, p_intf, p_input );
969 sysMenu->addSeparator();
970 addDPStaticEntry( sysMenu, qtr( "&Open Media" ),
971 ":/file-wide", SLOT( openFileDialog() ) );
972 addDPStaticEntry( sysMenu, qtr( "&Quit" ) ,
973 ":/quit", SLOT( quit() ) );
976 mi->getSysTray()->setContextMenu( sysMenu );
980 #undef PUSH_SEPARATOR
982 /*************************************************************************
983 * Builders for automenus
984 *************************************************************************/
985 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf,
987 vector< const char *> & varnames,
988 vector<vlc_object_t *> & objects )
990 QMenu *menu = current;
991 if( !menu ) menu = new QMenu();
993 /* Disable all non static entries */
994 QList< QAction* > actions = menu->actions();
995 for( int i = 0; i < actions.size(); ++i )
997 if( !actions[i]->data().toBool() )
998 actions[i]->setEnabled( false );
1001 currentGroup = NULL;
1003 vlc_object_t *p_object;
1006 for( i = 0; i < ( int )objects.size() ; i++ )
1008 if( !varnames[i] || !*varnames[i] )
1010 menu->addSeparator();
1013 p_object = objects[i];
1015 UpdateItem( p_intf, menu, varnames[i], p_object, true );
1020 /*****************************************************************************
1022 *****************************************************************************/
1024 static bool IsMenuEmpty( const char *psz_var,
1025 vlc_object_t *p_object,
1026 bool b_root = true )
1028 vlc_value_t val, val_list;
1029 int i_type, i_result, i;
1031 /* Check the type of the object variable */
1032 i_type = var_Type( p_object, psz_var );
1034 /* Check if we want to display the variable */
1035 if( !( i_type & VLC_VAR_HASCHOICE ) ) return false;
1037 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
1038 if( val.i_int == 0 ) return true;
1040 if( ( i_type & VLC_VAR_TYPE ) != VLC_VAR_VARIABLE )
1042 if( val.i_int == 1 && b_root ) return true;
1046 /* Check children variables in case of VLC_VAR_VARIABLE */
1047 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
1052 for( i = 0, i_result = true; i < val_list.p_list->i_count; i++ )
1054 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
1062 /* clean up everything */
1063 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
1068 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
1070 void QVLCMenu::UpdateItem( intf_thread_t *p_intf, QMenu *menu,
1071 const char *psz_var, vlc_object_t *p_object, bool b_submenu )
1073 vlc_value_t val, text;
1076 QAction *action = FindActionWithVar( menu, psz_var );
1078 DeleteNonStaticEntries( action->menu() );
1083 /* Check the type of the object variable */
1084 if( !strcmp( psz_var, "audio-es" )
1085 || !strcmp( psz_var, "video-es" )
1086 || !strcmp( psz_var, "postproc-q" ) )
1087 i_type = VLC_VAR_INTEGER | VLC_VAR_HASCHOICE;
1089 i_type = var_Type( p_object, psz_var );
1091 switch( i_type & VLC_VAR_TYPE )
1095 case VLC_VAR_VARIABLE:
1096 case VLC_VAR_STRING:
1097 case VLC_VAR_INTEGER:
1101 /* Variable doesn't exist or isn't handled */
1105 /* Make sure we want to display the variable */
1106 if( menu->isEmpty() && IsMenuEmpty( psz_var, p_object ) )
1109 /* Get the descriptive name of the variable */
1110 int i_ret = var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
1111 if( i_ret != VLC_SUCCESS )
1113 text.psz_string = NULL;
1118 action = new QAction( TEXT_OR_VAR, menu );
1119 menu->addAction( action );
1120 action->setData( psz_var );
1123 /* Some specific stuff */
1124 bool forceDisabled = false;
1125 if( !strcmp( psz_var, "spu-es" ) )
1127 vout_thread_t *p_vout = THEMIM->getVout();
1128 forceDisabled = ( p_vout == NULL );
1130 vlc_object_release( p_vout );
1133 if( i_type & VLC_VAR_HASCHOICE )
1135 /* Append choices menu */
1139 submenu = action->menu();
1142 submenu = new QMenu( menu );
1143 action->setMenu( submenu );
1147 CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0 );
1149 action->setEnabled( false );
1152 CreateChoicesMenu( menu, psz_var, p_object, true );
1153 FREENULL( text.psz_string );
1157 switch( i_type & VLC_VAR_TYPE )
1160 var_Get( p_object, psz_var, &val );
1161 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
1162 p_object, val, i_type );
1166 var_Get( p_object, psz_var, &val );
1167 val.b_bool = !val.b_bool;
1168 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
1169 p_object, val, i_type, !val.b_bool );
1172 FREENULL( text.psz_string );
1176 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
1177 vlc_object_t *p_object, bool b_root )
1179 vlc_value_t val, val_list, text_list;
1182 /* Check the type of the object variable */
1183 i_type = var_Type( p_object, psz_var );
1185 /* Make sure we want to display the variable */
1186 if( submenu->isEmpty() && IsMenuEmpty( psz_var, p_object, b_root ) )
1187 return VLC_EGENERIC;
1189 switch( i_type & VLC_VAR_TYPE )
1193 case VLC_VAR_VARIABLE:
1194 case VLC_VAR_STRING:
1195 case VLC_VAR_INTEGER:
1199 /* Variable doesn't exist or isn't handled */
1200 return VLC_EGENERIC;
1203 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
1204 &val_list, &text_list ) < 0 )
1206 return VLC_EGENERIC;
1209 #define CURVAL val_list.p_list->p_values[i]
1210 #define CURTEXT text_list.p_list->p_values[i].psz_string
1212 for( i = 0; i < val_list.p_list->i_count; i++ )
1214 vlc_value_t another_val;
1216 QMenu *subsubmenu = new QMenu( submenu );
1218 switch( i_type & VLC_VAR_TYPE )
1220 case VLC_VAR_VARIABLE:
1221 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
1222 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
1223 submenu->addMenu( subsubmenu );
1226 case VLC_VAR_STRING:
1227 var_Get( p_object, psz_var, &val );
1228 another_val.psz_string = strdup( CURVAL.psz_string );
1229 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
1230 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1231 p_object, another_val, i_type,
1232 val.psz_string && !strcmp( val.psz_string, CURVAL.psz_string ) );
1234 free( val.psz_string );
1237 case VLC_VAR_INTEGER:
1238 var_Get( p_object, psz_var, &val );
1239 if( CURTEXT ) menutext = qfu( CURTEXT );
1240 else menutext.sprintf( "%d", CURVAL.i_int );
1241 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1242 p_object, CURVAL, i_type,
1243 CURVAL.i_int == val.i_int );
1247 var_Get( p_object, psz_var, &val );
1248 if( CURTEXT ) menutext = qfu( CURTEXT );
1249 else menutext.sprintf( "%.2f", CURVAL.f_float );
1250 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1251 p_object, CURVAL, i_type,
1252 CURVAL.f_float == val.f_float );
1259 currentGroup = NULL;
1261 /* clean up everything */
1262 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
1269 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
1270 QString text, QString help,
1271 int i_item_type, vlc_object_t *p_obj,
1272 vlc_value_t val, int i_val_type,
1275 QAction *action = FindActionWithVar( menu, psz_var );
1278 action = new QAction( text, menu );
1279 menu->addAction( action );
1282 action->setToolTip( help );
1283 action->setEnabled( p_obj != NULL );
1285 if( i_item_type == ITEM_CHECK )
1287 action->setCheckable( true );
1289 else if( i_item_type == ITEM_RADIO )
1291 action->setCheckable( true );
1293 currentGroup = new QActionGroup( menu );
1294 currentGroup->addAction( action );
1297 action->setChecked( checked );
1299 MenuItemData *itemData = new MenuItemData( THEDP->menusMapper, p_obj, i_val_type,
1301 CONNECT( action, triggered(), THEDP->menusMapper, map() );
1302 THEDP->menusMapper->setMapping( action, itemData );
1303 menu->addAction( action );
1306 void QVLCMenu::DoAction( QObject *data )
1308 MenuItemData *itemData = qobject_cast<MenuItemData *>( data );
1309 vlc_object_t *p_object = itemData->p_obj;
1310 if( p_object == NULL ) return;
1312 var_Set( p_object, itemData->psz_var, itemData->val );
1315 void QVLCMenu::updateRecents( intf_thread_t *p_intf )
1320 RecentsMRL* rmrl = RecentsMRL::getInstance( p_intf );
1321 QList<QString> l = rmrl->recents();
1323 recentsMenu->clear();
1326 action = recentsMenu->addAction( " - Empty - " );
1327 action->setEnabled( false );
1331 for( int i = 0; i < l.size(); ++i )
1333 action = recentsMenu->addAction(
1334 QString( "&%1: " ).arg( i + 1 ) + l.at( i ),
1337 rmrl->signalMapper->setMapping( action, l.at( i ) );
1340 recentsMenu->addSeparator();
1341 recentsMenu->addAction( "&Clear", rmrl, SLOT( clear() ) );