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 */
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 );
112 * @brief Enable all static entries, disable the others
113 * @param enable if false, disable all entries
115 void EnableStaticEntries( QMenu *menu, bool enable = true )
119 QList< QAction* > actions = menu->actions();
120 for( int i = 0; i < actions.size(); ++i )
122 actions[i]->setEnabled( enable && actions[i]->data().toBool() );
127 * \return Number of static entries
129 int DeleteNonStaticEntries( QMenu *menu )
134 QList< QAction* > actions = menu->actions();
135 for( int i = 0; i < actions.size(); ++i )
137 if( !actions[i]->data().toBool() )
148 void addMIMStaticEntry( intf_thread_t *p_intf,
154 if( strlen( icon ) > 0 )
156 QAction *action = menu->addAction( text, THEMIM, member );
157 action->setIcon( QIcon( icon ) );
161 menu->addAction( text, THEMIM, member );
165 /*****************************************************************************
166 * Definitions of variables for the dynamic menus
167 *****************************************************************************/
168 #define PUSH_VAR( var ) varnames.push_back( var ); \
169 objects.push_back( VLC_OBJECT(p_object) )
171 #define PUSH_INPUTVAR( var ) varnames.push_back( var ); \
172 objects.push_back( VLC_OBJECT(p_input) );
174 #define PUSH_SEPARATOR if( objects.size() != i_last_separator ) { \
175 objects.push_back( 0 ); varnames.push_back( "" ); \
176 i_last_separator = objects.size(); }
178 static int InputAutoMenuBuilder( input_thread_t *p_object,
179 vector<vlc_object_t *> &objects,
180 vector<const char *> &varnames )
182 PUSH_VAR( "bookmark" );
184 PUSH_VAR( "chapter" );
185 PUSH_VAR( "program" );
186 PUSH_VAR( "navigation" );
187 PUSH_VAR( "dvd_menus" );
191 static int VideoAutoMenuBuilder( vout_thread_t *p_object,
192 input_thread_t *p_input,
193 vector<vlc_object_t *> &objects,
194 vector<const char *> &varnames )
196 PUSH_INPUTVAR( "video-es" );
197 PUSH_INPUTVAR( "spu-es" );
198 PUSH_VAR( "fullscreen" );
200 PUSH_VAR( "scaling" );
201 PUSH_VAR( "deinterlace" );
202 PUSH_VAR( "aspect-ratio" );
204 PUSH_VAR( "video-on-top" );
206 PUSH_VAR( "directx-wallpaper" );
208 PUSH_VAR( "video-snapshot" );
210 /* Special case for postproc */
214 /* p_object is the vout, so the decoder is our parent and the
215 * postproc filter one of the decoder's children */
216 vlc_object_t *p_dec = (vlc_object_t *)
217 vlc_object_find( p_object, VLC_OBJECT_DECODER,
221 vlc_object_t *p_pp = (vlc_object_t *)
222 vlc_object_find_name( p_dec, "postproc",
226 vlc_object_t *p_object = p_pp;
227 PUSH_VAR( "postproc-q" );
228 vlc_object_release( p_pp );
231 vlc_object_release( p_dec );
237 static int AudioAutoMenuBuilder( aout_instance_t *p_object,
238 input_thread_t *p_input,
239 vector<vlc_object_t *> &objects,
240 vector<const char *> &varnames )
242 PUSH_INPUTVAR( "audio-es" );
243 PUSH_VAR( "audio-device" );
244 PUSH_VAR( "audio-channels" );
245 PUSH_VAR( "visual" );
249 static QAction * FindActionWithVar( QMenu *menu, const char *psz_var )
251 QList< QAction* > actions = menu->actions();
252 for( int i = 0; i < actions.size(); ++i )
254 if( actions[i]->data().toString() == psz_var )
260 /*****************************************************************************
263 *****************************************************************************/
265 #define BAR_ADD( func, title ) { \
266 QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); }
268 #define BAR_DADD( func, title, id ) { \
269 QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); \
270 MenuFunc *f = new MenuFunc( _menu, id ); \
271 CONNECT( _menu, aboutToShow(), THEDP->menusUpdateMapper, map() ); \
272 THEDP->menusUpdateMapper->setMapping( _menu, f ); }
274 #define ACT_ADD( _menu, val, title ) { \
275 QAction *_action = new QAction( title, _menu ); _action->setData( val ); \
276 _menu->addAction( _action ); }
279 * Main Menu Bar Creation
281 void QVLCMenu::createMenuBar( MainInterface *mi,
282 intf_thread_t *p_intf,
283 bool visual_selector_enabled )
284 /* FIXME remove this visual dependency */
286 /* QMainWindows->menuBar()
287 gives the QProcess::destroyed timeout issue on Cleanlooks style with
288 setDesktopAware set to false */
289 QMenuBar *bar = mi->menuBar();
290 BAR_ADD( FileMenu( p_intf ), qtr( "&Media" ) );
292 BAR_DADD( AudioMenu( p_intf, NULL ), qtr( "&Audio" ), 1 );
293 BAR_DADD( VideoMenu( p_intf, NULL ), qtr( "&Video" ), 2 );
294 BAR_DADD( NavigMenu( p_intf, NULL ), qtr( "P&layback" ), 3 );
296 BAR_ADD( ToolsMenu( p_intf ), qtr( "&Tools" ) );
297 BAR_ADD( ViewMenu( p_intf, NULL, mi, visual_selector_enabled, true ),
300 BAR_ADD( HelpMenu( NULL ), qtr( "&Help" ) );
306 * Media ( File ) Menu
307 * Opening, streaming and quit
309 QMenu *QVLCMenu::FileMenu( intf_thread_t *p_intf )
311 QMenu *menu = new QMenu();
313 addDPStaticEntry( menu, qtr( "&Open File..." ),
314 ":/file-asym", SLOT( simpleOpenDialog() ), "Ctrl+O" );
315 addDPStaticEntry( menu, qtr( "Advanced Open File..." ),
316 ":/file-asym", SLOT( openFileDialog() ), "Ctrl+Shift+O" );
317 addDPStaticEntry( menu, qtr( I_OPEN_FOLDER ),
318 ":/folder-grey", SLOT( PLOpenDir() ), "Ctrl+F" );
319 addDPStaticEntry( menu, qtr( "Open &Disc..." ),
320 ":/disc", SLOT( openDiscDialog() ), "Ctrl+D" );
321 addDPStaticEntry( menu, qtr( "Open &Network..." ),
322 ":/network", SLOT( openNetDialog() ), "Ctrl+N" );
323 addDPStaticEntry( menu, qtr( "Open &Capture Device..." ),
324 ":/capture-card", SLOT( openCaptureDialog() ),
327 menu->addSeparator();
328 addDPStaticEntry( menu, qtr( "Paste &MRL" ),
329 NULL, SLOT( openUrlDialog() ), "Ctrl+V" );
331 addDPStaticEntry( menu, qtr( I_PL_LOAD ), "", SLOT( openAPlaylist() ),
333 addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", SLOT( saveAPlaylist() ),
336 menu->addSeparator();
338 recentsMenu = new QMenu( qtr( "Recently &Played" ), menu );
339 updateRecents( p_intf );
340 menu->addMenu( recentsMenu );
341 menu->addSeparator();
343 addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "",
344 SLOT( openAndTranscodingDialogs() ), "Ctrl+R" );
345 addDPStaticEntry( menu, qtr( "&Streaming..." ),
346 ":/stream", SLOT( openAndStreamingDialogs() ),
348 menu->addSeparator();
350 addDPStaticEntry( menu, qtr( "&Quit" ) ,
351 ":/quit", SLOT( quit() ), "Ctrl+Q" );
355 /* Playlist/MediaLibrary Control */
356 QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf )
358 VLC_UNUSED( p_intf ); //TODO remove
359 QMenu *menu = new QMenu();
361 addDPStaticEntry( menu, qtr( I_MENU_EXT ), ":/settings",
362 SLOT( extendedDialog() ), "Ctrl+E" );
364 addDPStaticEntry( menu, qtr( I_MENU_INFO ) , ":/info",
365 SLOT( mediaInfoDialog() ), "Ctrl+I" );
366 addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) ,
367 ":/info", SLOT( mediaCodecDialog() ), "Ctrl+J" );
369 addDPStaticEntry( menu, qtr( I_MENU_BOOKMARK ),"",
370 SLOT( bookmarksDialog() ), "Ctrl+B" );
372 addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", SLOT( vlmDialog() ),
376 addDPStaticEntry( menu, qtr( I_MENU_MSG ),
377 ":/messages", SLOT( messagesDialog() ),
380 addDPStaticEntry( menu, qtr( "Plu&gins and extensions" ),
381 "", SLOT( pluginDialog() ) );
382 menu->addSeparator();
384 addDPStaticEntry( menu, qtr( "Customi&ze Interface..." ),
385 ":/preferences", SLOT( toolbarDialog() ) );
386 addDPStaticEntry( menu, qtr( "&Preferences" ),
387 ":/preferences", SLOT( prefsDialog() ), "Ctrl+P" );
394 * This is kept in the same menu for now, but could change if it gets much
396 * This menu can be an interface menu but also a right click menu.
398 QMenu *QVLCMenu::ViewMenu( intf_thread_t *p_intf,
401 bool visual_selector_enabled,
404 QMenu *menu = new QMenu( current );
408 act = menu->addAction( QIcon( ":/playlist_menu" ),
409 qtr( "Play&list" ), mi,
410 SLOT( togglePlaylist() ), qtr( "Ctrl+L" ) );
411 act->setData( true );
413 act = menu->addMenu( SDMenu( p_intf ) );
414 act->setData( true );
415 /*menu->addSeparator();
416 menu->addAction( qtr( "Undock from Interface" ), mi,
417 SLOT( undockPlaylist() ), qtr( "Ctrl+U" ) );*/
420 menu->addSeparator();
424 QMenu *intfmenu = InterfacesMenu( p_intf, menu );
425 MenuFunc *f = new MenuFunc( intfmenu, 4 );
426 CONNECT( intfmenu, aboutToShow(), THEDP->menusUpdateMapper, map() );
427 THEDP->menusUpdateMapper->setMapping( intfmenu, f );
428 menu->addSeparator();
433 QAction *action = menu->addAction( qtr( "Mi&nimal View" ), mi,
434 SLOT( toggleMinimalView() ), qtr( "Ctrl+H" ) );
435 action->setCheckable( true );
436 action->setData( true );
437 if( mi->getControlsVisibilityStatus() & CONTROLS_VISIBLE )
438 action->setChecked( true );
439 minimalViewAction = action; /* HACK for minimalView */
441 /* FullScreen View */
442 action = menu->addAction( qtr( "&Fullscreen Interface" ), mi,
443 SLOT( toggleFullScreen() ), QString( "F11" ) );
444 action->setCheckable( true );
445 action->setData( true );
447 /* Advanced Controls */
448 action = menu->addAction( qtr( "&Advanced Controls" ), mi,
449 SLOT( toggleAdvanced() ) );
450 action->setCheckable( true );
451 action->setData( true );
452 if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
453 action->setChecked( true );
454 #if 0 /* For Visualisations. Not yet working */
455 adv = menu->addAction( qtr( "Visualizations selector" ),
456 mi, SLOT( visual() ) );
457 adv->setCheckable( true );
458 if( visual_selector_enabled ) adv->setChecked( true );
462 menu->addSeparator();
468 * Interface Sub-Menu, to list extras interface and skins
470 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
472 vector<vlc_object_t *> objects;
473 vector<const char *> varnames;
474 /** \todo add "switch to XXX" */
475 varnames.push_back( "intf-add" );
476 objects.push_back( VLC_OBJECT(p_intf) );
478 return Populate( p_intf, current, varnames, objects );
484 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
486 vector<vlc_object_t *> objects;
487 vector<const char *> varnames;
488 aout_instance_t *p_aout;
489 input_thread_t *p_input;
491 if( !current ) current = new QMenu();
493 if( current->isEmpty() )
495 ACT_ADD( current, "audio-es", qtr( "Audio &Track" ) );
496 ACT_ADD( current, "audio-device", qtr( "Audio &Device" ) );
497 ACT_ADD( current, "audio-channels", qtr( "Audio &Channels" ) );
498 current->addSeparator();
499 ACT_ADD( current, "visual", qtr( "&Visualizations" ) );
502 p_input = THEMIM->getInput();
504 vlc_object_hold( p_input );
505 p_aout = THEMIM->getAout();
506 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
507 EnableStaticEntries( current, ( p_aout != NULL ) );
510 vlc_object_release( p_aout );
513 vlc_object_release( p_input );
515 return Populate( p_intf, current, varnames, objects );
520 * Subtitles are part of Video.
522 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
524 vout_thread_t *p_vout;
525 input_thread_t *p_input;
526 vector<vlc_object_t *> objects;
527 vector<const char *> varnames;
529 if( !current ) current = new QMenu();
531 if( current->isEmpty() )
533 ACT_ADD( current, "video-es", qtr( "Video &Track" ) );
536 QMenu *submenu = new QMenu( qtr( "&Subtitles Track" ), current );
537 action = current->addMenu( submenu );
538 action->setData( "spu-es" );
539 addDPStaticEntry( submenu, qtr( "Open File..." ), "",
540 SLOT( loadSubtitlesFile() ) );
541 submenu->addSeparator();
543 ACT_ADD( current, "fullscreen", qtr( "&Fullscreen" ) );
544 ACT_ADD( current, "zoom", qtr( "&Zoom" ) );
545 ACT_ADD( current, "deinterlace", qtr( "&Deinterlace" ) );
546 ACT_ADD( current, "aspect-ratio", qtr( "&Aspect Ratio" ) );
547 ACT_ADD( current, "crop", qtr( "&Crop" ) );
548 ACT_ADD( current, "video-on-top", qtr( "Always &On Top" ) );
550 ACT_ADD( current, "directx-wallpaper", qtr( "DirectX Wallpaper" ) );
552 ACT_ADD( current, "video-snapshot", qtr( "Sna&pshot" ) );
553 ACT_ADD( current, "postproc-q", qtr( "Post processing" ) );
556 p_input = THEMIM->getInput();
558 vlc_object_hold( p_input );
560 p_vout = THEMIM->getVout();
561 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
562 EnableStaticEntries( current, ( p_vout != NULL ) );
565 vlc_object_release( p_vout );
568 vlc_object_release( p_input );
570 return Populate( p_intf, current, varnames, objects );
575 * For DVD, MP4, MOV and other chapter based format
577 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
579 if( !menu ) menu = new QMenu();
581 if( menu->isEmpty() )
583 addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ),"",
584 SLOT( gotoTimeDialog() ), "Ctrl+T" );
585 menu->addSeparator();
587 ACT_ADD( menu, "bookmark", qtr( "&Bookmarks" ) );
588 ACT_ADD( menu, "title", qtr( "T&itle" ) );
589 ACT_ADD( menu, "chapter", qtr( "&Chapter" ) );
590 ACT_ADD( menu, "program", qtr( "&Program" ) );
591 ACT_ADD( menu, "navigation", qtr( "&Navigation" ) );
594 input_thread_t *p_object;
595 vector<vlc_object_t *> objects;
596 vector<const char *> varnames;
598 p_object = THEMIM->getInput();
600 vlc_object_hold( p_object );
601 InputAutoMenuBuilder( p_object, objects, varnames );
602 PUSH_VAR( "prev-title" );
603 PUSH_VAR( "next-title" );
604 PUSH_VAR( "prev-chapter" );
605 PUSH_VAR( "next-chapter" );
606 EnableStaticEntries( menu, ( p_object != NULL ) );
609 vlc_object_release( p_object );
611 return Populate( p_intf, menu, varnames, objects );
615 * Service Discovery SubMenu
617 QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf )
619 QMenu *menu = new QMenu();
620 menu->setTitle( qtr( I_PL_SD ) );
621 char **ppsz_longnames;
622 char **ppsz_names = vlc_sd_GetNames( &ppsz_longnames );
626 char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
627 for( ; *ppsz_name; ppsz_name++, ppsz_longname++ )
629 QAction *a = new QAction( qfu( *ppsz_longname ), menu );
630 a->setCheckable( true );
631 if( playlist_IsServicesDiscoveryLoaded( THEPL, *ppsz_name ) )
632 a->setChecked( true );
633 CONNECT( a , triggered(), THEDP->SDMapper, map() );
634 THEDP->SDMapper->setMapping( a, QString( *ppsz_name ) );
635 menu->addAction( a );
637 if( !strcmp( *ppsz_name, "podcast" ) )
639 QAction *b = new QAction( qtr( "Configure podcasts..." ), menu );
640 //b->setEnabled( a->isChecked() );
641 menu->addAction( b );
642 CONNECT( b, triggered(), THEDP, podcastConfigureDialog() );
645 free( *ppsz_longname );
648 free( ppsz_longnames );
654 QMenu *QVLCMenu::HelpMenu( QMenu *current )
656 QMenu *menu = new QMenu( current );
657 addDPStaticEntry( menu, qtr( "&Help..." ) ,
658 ":/help", SLOT( helpDialog() ), "F1" );
660 addDPStaticEntry( menu, qtr( "Check for &Updates..." ) , "",
661 SLOT( updateDialog() ) );
663 menu->addSeparator();
664 addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), ":/info",
665 SLOT( aboutDialog() ), "Shift+F1" );
669 /*****************************************************************************
670 * Popup menus - Right Click menus *
671 *****************************************************************************/
672 #define POPUP_BOILERPLATE \
673 unsigned int i_last_separator = 0; \
674 vector<vlc_object_t *> objects; \
675 vector<const char *> varnames; \
676 input_thread_t *p_input = THEMIM->getInput();
678 #define CREATE_POPUP \
679 Populate( p_intf, menu, varnames, objects ); \
680 p_intf->p_sys->p_popup_menu = menu; \
681 menu->popup( QCursor::pos() ); \
682 p_intf->p_sys->p_popup_menu = NULL; \
683 i_last_separator = 0;
685 void QVLCMenu::PopupMenuControlEntries( QMenu *menu,
686 intf_thread_t *p_intf,
687 input_thread_t *p_input )
692 var_Get( p_input, "state", &val );
693 if( val.i_int == PLAYING_S )
694 addMIMStaticEntry( p_intf, menu, qtr( "Pause" ),
695 ":/pause", SLOT( togglePlayPause() ) );
697 addMIMStaticEntry( p_intf, menu, qtr( "Play" ),
698 ":/play", SLOT( togglePlayPause() ) );
700 else if( THEPL->items.i_size )
701 addMIMStaticEntry( p_intf, menu, qtr( "Play" ),
702 ":/play", SLOT( togglePlayPause() ) );
704 addDPStaticEntry( menu, qtr( "Play" ),
705 ":/play", SLOT( openDialog() ) );
707 addMIMStaticEntry( p_intf, menu, qtr( "Stop" ),
708 ":/stop", SLOT( stop() ) );
709 addMIMStaticEntry( p_intf, menu, qtr( "Previous" ),
710 ":/previous", SLOT( prev() ) );
711 addMIMStaticEntry( p_intf, menu, qtr( "Next" ),
712 ":/next", SLOT( next() ) );
715 void QVLCMenu::PopupMenuStaticEntries( QMenu *menu )
718 QMenu *toolsmenu = ToolsMenu( p_intf, menu, false, true );
719 toolsmenu->setTitle( qtr( "Tools" ) );
720 menu->addMenu( toolsmenu );
723 QMenu *openmenu = new QMenu( qtr( "Open Media" ), menu );
724 addDPStaticEntry( openmenu, qtr( "&Open File..." ),
725 ":/file-asym", SLOT( openFileDialog() ) );
726 addDPStaticEntry( openmenu, qtr( I_OPEN_FOLDER ),
727 ":/folder-grey", SLOT( PLOpenDir() ) );
728 addDPStaticEntry( openmenu, qtr( "Open &Disc..." ),
729 ":/disc", SLOT( openDiscDialog() ) );
730 addDPStaticEntry( openmenu, qtr( "Open &Network..." ),
731 ":/network", SLOT( openNetDialog() ) );
732 addDPStaticEntry( openmenu, qtr( "Open &Capture Device..." ),
733 ":/capture-card", SLOT( openCaptureDialog() ) );
734 menu->addMenu( openmenu );
736 menu->addSeparator();
738 QMenu *helpmenu = HelpMenu( menu );
739 helpmenu->setTitle( qtr( "Help" ) );
740 menu->addMenu( helpmenu );
743 addDPStaticEntry( menu, qtr( "Quit" ), ":/quit",
744 SLOT( quit() ), "Ctrl+Q" );
747 /* Video Tracks and Subtitles tracks */
748 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
753 vlc_object_hold( p_input );
754 vout_thread_t *p_vout = THEMIM->getVout();
757 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
758 vlc_object_release( p_vout );
760 vlc_object_release( p_input );
762 QMenu *menu = new QMenu();
767 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
772 vlc_object_hold( p_input );
773 aout_instance_t *p_aout = THEMIM->getAout();
774 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
776 vlc_object_release( p_aout );
777 vlc_object_release( p_input );
779 QMenu *menu = new QMenu();
783 /* Navigation stuff, and general menus ( open ) */
784 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
790 vlc_object_hold( p_input );
791 varnames.push_back( "audio-es" );
792 InputAutoMenuBuilder( p_input, objects, varnames );
796 QMenu *menu = new QMenu();
797 Populate( p_intf, menu, varnames, objects );
799 menu->addSeparator();
800 PopupMenuControlEntries( menu, p_intf, p_input );
802 menu->addSeparator();
803 PopupMenuStaticEntries( menu );
805 p_intf->p_sys->p_popup_menu = menu;
806 menu->popup( QCursor::pos() );
807 p_intf->p_sys->p_popup_menu = NULL;
810 /* Main Menu that sticks everything together */
811 void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
813 MainInterface *mi = p_intf->p_sys->p_mi;
816 /* Delete and recreate a popup if there is one */
817 if( p_intf->p_sys->p_popup_menu )
818 delete p_intf->p_sys->p_popup_menu;
820 QMenu *menu = new QMenu();
823 bool b_isFullscreen = false;
827 PopupMenuControlEntries( menu, p_intf, p_input );
828 menu->addSeparator();
832 vout_thread_t *p_vout = THEMIM->getVout();
834 /* Add a fullscreen switch button */
838 var_Get( p_vout, "fullscreen", &val );
839 b_isFullscreen = !( !val.b_bool );
841 CreateAndConnect( menu, "fullscreen",
842 qtr( "Leave Fullscreen" ),"" , ITEM_NORMAL,
843 VLC_OBJECT(p_vout), val, VLC_VAR_BOOL,
845 vlc_object_release( p_vout );
848 menu->addSeparator();
850 vlc_object_hold( p_input );
851 InputAutoMenuBuilder( p_input, objects, varnames );
852 vlc_object_release( p_input );
854 submenu = new QMenu( menu );
855 action = menu->addMenu( AudioMenu( p_intf, submenu ) );
856 action->setText( qtr( "&Audio" ) );
857 if( action->menu()->isEmpty() )
858 action->setEnabled( false );
860 submenu = new QMenu( menu );
861 action = menu->addMenu( VideoMenu( p_intf, submenu ) );
862 action->setText( qtr( "&Video" ) );
863 if( action->menu()->isEmpty() )
864 action->setEnabled( false );
866 submenu = new QMenu( menu );
867 action = menu->addMenu( NavigMenu( p_intf, submenu ) );
868 action->setText( qtr( "&Playback" ) );
869 if( action->menu()->isEmpty() )
870 action->setEnabled( false );
873 menu->addSeparator();
875 /* Add some special entries for windowed mode: Interface Menu */
876 if( !b_isFullscreen )
878 submenu = new QMenu( qtr( "Interface" ), menu );
881 submenu->addAction( QIcon( ":/playlist" ),
882 qtr( "Show Playlist" ), mi, SLOT( togglePlaylist() ) );
884 addDPStaticEntry( submenu, qtr( I_MENU_EXT ),
885 ":/settings", SLOT( extendedDialog() ) );
886 addDPStaticEntry( submenu, qtr( I_MENU_INFO ) , ":/info",
887 SLOT( mediaInfoDialog() ), "Ctrl+I" );
890 action = submenu->addAction( QIcon( "" ),
891 qtr( "Minimal View" ), mi, SLOT( toggleMinimalView() ) );
892 action->setCheckable( true );
893 action->setChecked( !( mi->getControlsVisibilityStatus() &
894 CONTROLS_VISIBLE ) );
895 action = submenu->addAction( QIcon( "" ),
896 qtr( "Toggle Fullscreen Interface" ),
897 mi, SLOT( toggleFullScreen() ) );
898 action->setCheckable( true );
899 action->setChecked( mi->isFullScreen() );
901 else /* We are using the skins interface.
902 If not, this entry will not show. */
904 addDPStaticEntry( submenu, qtr( "&Preferences..." ),
905 ":/preferences", SLOT( prefsDialog() ), "Ctrl+P" );
906 submenu->addSeparator();
909 vlc_object_t *p_object = ( vlc_object_t* )
910 vlc_object_find_name( p_intf, "skins2", FIND_PARENT );
913 objects.push_back( p_object );
914 varnames.push_back( "intf-skins" );
915 Populate( p_intf, submenu, varnames, objects );
916 vlc_object_release( p_object );
920 msg_Dbg( p_intf, "could not find parent interface" );
923 menu->addMenu( submenu );
926 PopupMenuStaticEntries( menu );
928 p_intf->p_sys->p_popup_menu = menu;
929 p_intf->p_sys->p_popup_menu->popup( QCursor::pos() );
933 // destroy popup if there is one
934 delete p_intf->p_sys->p_popup_menu;
935 p_intf->p_sys->p_popup_menu = NULL;
941 /************************************************************************
943 ************************************************************************/
945 void QVLCMenu::updateSystrayMenu( MainInterface *mi,
946 intf_thread_t *p_intf,
947 bool b_force_visible )
951 /* Get the systray menu and clean it */
952 QMenu *sysMenu = mi->getSysTrayMenu();
955 /* Hide / Show VLC and cone */
956 if( mi->isVisible() || b_force_visible )
958 sysMenu->addAction( QIcon( ":/vlc16.png" ),
959 qtr( "Hide VLC media player in taskbar" ), mi,
960 SLOT( toggleUpdateSystrayMenu() ) );
964 sysMenu->addAction( QIcon( ":/vlc16.png" ),
965 qtr( "Show VLC media player" ), mi,
966 SLOT( toggleUpdateSystrayMenu() ) );
969 sysMenu->addSeparator();
970 PopupMenuControlEntries( sysMenu, p_intf, p_input );
972 sysMenu->addSeparator();
973 addDPStaticEntry( sysMenu, qtr( "&Open Media" ),
974 ":/file-wide", SLOT( openFileDialog() ) );
975 addDPStaticEntry( sysMenu, qtr( "&Quit" ) ,
976 ":/quit", SLOT( quit() ) );
979 mi->getSysTray()->setContextMenu( sysMenu );
983 #undef PUSH_SEPARATOR
985 /*************************************************************************
986 * Builders for automenus
987 *************************************************************************/
988 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf,
990 vector< const char *> & varnames,
991 vector<vlc_object_t *> & objects )
993 QMenu *menu = current;
994 if( !menu ) menu = new QMenu();
998 vlc_object_t *p_object;
1000 for( int i = 0; i < ( int )objects.size() ; i++ )
1002 if( !varnames[i] || !*varnames[i] )
1004 menu->addSeparator();
1007 p_object = objects[i];
1009 UpdateItem( p_intf, menu, varnames[i], p_object, true );
1014 /*****************************************************************************
1016 *****************************************************************************/
1018 static bool IsMenuEmpty( const char *psz_var,
1019 vlc_object_t *p_object,
1020 bool b_root = true )
1022 vlc_value_t val, val_list;
1023 int i_type, i_result, i;
1025 /* Check the type of the object variable */
1026 i_type = var_Type( p_object, psz_var );
1028 /* Check if we want to display the variable */
1029 if( !( i_type & VLC_VAR_HASCHOICE ) ) return false;
1031 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
1032 if( val.i_int == 0 ) return true;
1034 if( ( i_type & VLC_VAR_TYPE ) != VLC_VAR_VARIABLE )
1036 if( val.i_int == 1 && b_root ) return true;
1040 /* Check children variables in case of VLC_VAR_VARIABLE */
1041 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
1046 for( i = 0, i_result = true; i < val_list.p_list->i_count; i++ )
1048 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
1056 /* clean up everything */
1057 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
1062 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
1064 void QVLCMenu::UpdateItem( intf_thread_t *p_intf, QMenu *menu,
1065 const char *psz_var, vlc_object_t *p_object, bool b_submenu )
1067 vlc_value_t val, text;
1070 QAction *action = FindActionWithVar( menu, psz_var );
1072 DeleteNonStaticEntries( action->menu() );
1077 action->setEnabled( false );
1081 /* Check the type of the object variable */
1082 /* What is the following HACK needed for? */
1083 if( !strcmp( psz_var, "audio-es" )
1084 || !strcmp( psz_var, "video-es" )
1085 || !strcmp( psz_var, "postproc-q" ) )
1086 i_type = VLC_VAR_INTEGER | VLC_VAR_HASCHOICE;
1088 i_type = var_Type( p_object, psz_var );
1090 switch( i_type & VLC_VAR_TYPE )
1094 case VLC_VAR_VARIABLE:
1095 case VLC_VAR_STRING:
1096 case VLC_VAR_INTEGER:
1100 /* Variable doesn't exist or isn't handled */
1102 action->setEnabled( false );
1106 /* Make sure we want to display the variable */
1107 if( menu->isEmpty() && IsMenuEmpty( psz_var, p_object ) )
1110 action->setEnabled( false );
1114 /* Get the descriptive name of the variable */
1115 int i_ret = var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
1116 if( i_ret != VLC_SUCCESS )
1118 text.psz_string = NULL;
1123 action = new QAction( TEXT_OR_VAR, menu );
1124 menu->addAction( action );
1125 action->setData( psz_var );
1128 /* Some specific stuff */
1129 bool forceDisabled = false;
1130 if( !strcmp( psz_var, "spu-es" ) )
1132 vout_thread_t *p_vout = THEMIM->getVout();
1133 forceDisabled = ( p_vout == NULL );
1135 vlc_object_release( p_vout );
1138 if( i_type & VLC_VAR_HASCHOICE )
1140 /* Append choices menu */
1144 submenu = action->menu();
1147 submenu = new QMenu( menu );
1148 action->setMenu( submenu );
1152 CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0 );
1154 action->setEnabled( false );
1158 CreateChoicesMenu( menu, psz_var, p_object, true ) == 0 );
1159 FREENULL( text.psz_string );
1163 switch( i_type & VLC_VAR_TYPE )
1166 var_Get( p_object, psz_var, &val );
1167 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
1168 p_object, val, i_type );
1172 var_Get( p_object, psz_var, &val );
1173 val.b_bool = !val.b_bool;
1174 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
1175 p_object, val, i_type, !val.b_bool );
1178 FREENULL( text.psz_string );
1182 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
1183 vlc_object_t *p_object, bool b_root )
1185 vlc_value_t val, val_list, text_list;
1188 /* Check the type of the object variable */
1189 i_type = var_Type( p_object, psz_var );
1191 /* Make sure we want to display the variable */
1192 if( submenu->isEmpty() && IsMenuEmpty( psz_var, p_object, b_root ) )
1193 return VLC_EGENERIC;
1195 switch( i_type & VLC_VAR_TYPE )
1199 case VLC_VAR_VARIABLE:
1200 case VLC_VAR_STRING:
1201 case VLC_VAR_INTEGER:
1205 /* Variable doesn't exist or isn't handled */
1206 return VLC_EGENERIC;
1209 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
1210 &val_list, &text_list ) < 0 )
1212 return VLC_EGENERIC;
1215 #define CURVAL val_list.p_list->p_values[i]
1216 #define CURTEXT text_list.p_list->p_values[i].psz_string
1218 for( i = 0; i < val_list.p_list->i_count; i++ )
1220 vlc_value_t another_val;
1222 QMenu *subsubmenu = new QMenu( submenu );
1224 switch( i_type & VLC_VAR_TYPE )
1226 case VLC_VAR_VARIABLE:
1227 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
1228 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
1229 submenu->addMenu( subsubmenu );
1232 case VLC_VAR_STRING:
1233 var_Get( p_object, psz_var, &val );
1234 another_val.psz_string = strdup( CURVAL.psz_string );
1235 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
1236 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1237 p_object, another_val, i_type,
1238 val.psz_string && !strcmp( val.psz_string, CURVAL.psz_string ) );
1240 free( val.psz_string );
1243 case VLC_VAR_INTEGER:
1244 var_Get( p_object, psz_var, &val );
1245 if( CURTEXT ) menutext = qfu( CURTEXT );
1246 else menutext.sprintf( "%d", CURVAL.i_int );
1247 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1248 p_object, CURVAL, i_type,
1249 CURVAL.i_int == val.i_int );
1253 var_Get( p_object, psz_var, &val );
1254 if( CURTEXT ) menutext = qfu( CURTEXT );
1255 else menutext.sprintf( "%.2f", CURVAL.f_float );
1256 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1257 p_object, CURVAL, i_type,
1258 CURVAL.f_float == val.f_float );
1265 currentGroup = NULL;
1267 /* clean up everything */
1268 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
1272 return submenu->isEmpty() ? VLC_EGENERIC : VLC_SUCCESS;
1275 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
1276 QString text, QString help,
1277 int i_item_type, vlc_object_t *p_obj,
1278 vlc_value_t val, int i_val_type,
1281 QAction *action = FindActionWithVar( menu, psz_var );
1284 action = new QAction( text, menu );
1285 menu->addAction( action );
1288 action->setToolTip( help );
1289 action->setEnabled( p_obj != NULL );
1291 if( i_item_type == ITEM_CHECK )
1293 action->setCheckable( true );
1295 else if( i_item_type == ITEM_RADIO )
1297 action->setCheckable( true );
1299 currentGroup = new QActionGroup( menu );
1300 currentGroup->addAction( action );
1303 action->setChecked( checked );
1305 MenuItemData *itemData = new MenuItemData( THEDP->menusMapper, p_obj, i_val_type,
1307 CONNECT( action, triggered(), THEDP->menusMapper, map() );
1308 THEDP->menusMapper->setMapping( action, itemData );
1309 menu->addAction( action );
1312 void QVLCMenu::DoAction( QObject *data )
1314 MenuItemData *itemData = qobject_cast<MenuItemData *>( data );
1315 vlc_object_t *p_object = itemData->p_obj;
1316 if( p_object == NULL ) return;
1318 var_Set( p_object, itemData->psz_var, itemData->val );
1321 void QVLCMenu::updateRecents( intf_thread_t *p_intf )
1326 RecentsMRL* rmrl = RecentsMRL::getInstance( p_intf );
1327 QList<QString> l = rmrl->recents();
1329 recentsMenu->clear();
1332 action = recentsMenu->addAction( " - Empty - " );
1333 action->setEnabled( false );
1337 for( int i = 0; i < l.size(); ++i )
1339 action = recentsMenu->addAction(
1340 QString( "&%1: " ).arg( i + 1 ) + l.at( i ),
1343 rmrl->signalMapper->setMapping( action, l.at( i ) );
1346 recentsMenu->addSeparator();
1347 recentsMenu->addAction( "&Clear", rmrl, SLOT( clear() ) );