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( "_static_" );
111 void EnableDPStaticEntries( QMenu *menu, bool enable = true )
116 foreach( action, menu->actions() )
118 if( action->data().toString() == "_static_" )
119 action->setEnabled( enable );
124 * \return Number of static entries
126 int DeleteNonStaticEntries( QMenu *menu )
132 foreach( action, menu->actions() )
134 if( action->data().toString() != "_static_" )
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( "deinterlace" );
198 PUSH_VAR( "aspect-ratio" );
200 PUSH_VAR( "video-on-top" );
202 PUSH_VAR( "directx-wallpaper" );
204 PUSH_VAR( "video-snapshot" );
206 /* Special case for postproc */
210 /* p_object is the vout, so the decoder is our parent and the
211 * postproc filter one of the decoder's children */
212 vlc_object_t *p_dec = (vlc_object_t *)
213 vlc_object_find( p_object, VLC_OBJECT_DECODER,
217 vlc_object_t *p_pp = (vlc_object_t *)
218 vlc_object_find_name( p_dec, "postproc",
222 vlc_object_t *p_object = p_pp;
223 PUSH_VAR( "postproc-q" );
224 vlc_object_release( p_pp );
227 vlc_object_release( p_dec );
233 static int AudioAutoMenuBuilder( aout_instance_t *p_object,
234 input_thread_t *p_input,
235 vector<vlc_object_t *> &objects,
236 vector<const char *> &varnames )
238 PUSH_INPUTVAR( "audio-es" );
239 PUSH_VAR( "audio-device" );
240 PUSH_VAR( "audio-channels" );
241 PUSH_VAR( "visual" );
245 static QAction * FindActionWithVar( QMenu *menu, const char *psz_var )
248 foreach( action, menu->actions() )
250 if( action->data().toString() == psz_var )
256 /*****************************************************************************
259 *****************************************************************************/
261 #define BAR_ADD( func, title ) { \
262 QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); }
264 #define BAR_DADD( func, title, id ) { \
265 QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); \
266 MenuFunc *f = new MenuFunc( _menu, id ); \
267 CONNECT( _menu, aboutToShow(), THEDP->menusUpdateMapper, map() ); \
268 THEDP->menusUpdateMapper->setMapping( _menu, f ); }
270 #define ACT_ADD( _menu, val, title ) { \
271 QAction *_action = new QAction( title, _menu ); _action->setData( val ); \
272 _menu->addAction( _action ); }
275 * Main Menu Bar Creation
277 void QVLCMenu::createMenuBar( MainInterface *mi,
278 intf_thread_t *p_intf,
279 bool visual_selector_enabled )
280 /* FIXME remove this visual dependency */
282 /* QMainWindows->menuBar()
283 gives the QProcess::destroyed timeout issue on Cleanlooks style with
284 setDesktopAware set to false */
285 QMenuBar *bar = mi->menuBar();
286 BAR_ADD( FileMenu( p_intf ), qtr( "&Media" ) );
288 BAR_DADD( AudioMenu( p_intf, NULL ), qtr( "&Audio" ), 1 );
289 BAR_DADD( VideoMenu( p_intf, NULL ), qtr( "&Video" ), 2 );
290 BAR_DADD( NavigMenu( p_intf, NULL ), qtr( "P&layback" ), 3 );
292 BAR_ADD( ToolsMenu( p_intf ), qtr( "&Tools" ) );
293 BAR_ADD( ViewMenu( p_intf, NULL, mi, visual_selector_enabled, true ),
296 BAR_ADD( HelpMenu( NULL ), qtr( "&Help" ) );
302 * Media ( File ) Menu
303 * Opening, streaming and quit
305 QMenu *QVLCMenu::FileMenu( intf_thread_t *p_intf )
307 QMenu *menu = new QMenu();
309 addDPStaticEntry( menu, qtr( "&Open File..." ),
311 ":/file-asym", SLOT( simpleOpenDialog() ), "Ctrl+O" );
312 addDPStaticEntry( menu, qtr( "Advanced Open File..." ),
313 ":/file-asym", SLOT( openFileDialog() ) );
315 ":/file-asym", SLOT( openFileDialog() ), "Ctrl+O" );
317 addDPStaticEntry( menu, qtr( "Open &URL" ),
318 NULL, SLOT( openUrlDialog() ), "Ctrl+V" );
319 addDPStaticEntry( menu, qtr( I_OPEN_FOLDER ),
320 ":/folder-grey", SLOT( PLOpenDir() ), "Ctrl+F" );
321 addDPStaticEntry( menu, qtr( "Open &Disc..." ),
322 ":/disc", SLOT( openDiscDialog() ), "Ctrl+D" );
323 addDPStaticEntry( menu, qtr( "Open &Network..." ),
324 ":/network", SLOT( openNetDialog() ), "Ctrl+N" );
325 addDPStaticEntry( menu, qtr( "Open &Capture Device..." ),
326 ":/capture-card", SLOT( openCaptureDialog() ),
329 menu->addSeparator();
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( "_static_" );
413 act = menu->addMenu( SDMenu( p_intf ) );
414 act->setData( "_static_" );
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( "_static_" );
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( "_static_" );
447 /* Advanced Controls */
448 action = menu->addAction( qtr( "&Advanced Controls" ), mi,
449 SLOT( toggleAdvanced() ) );
450 action->setCheckable( true );
451 action->setData( "_static_" );
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();
508 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
509 vlc_object_release( p_aout );
512 vlc_object_release( p_input );
514 return Populate( p_intf, current, varnames, objects );
519 * Subtitles are part of Video.
521 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
523 vout_thread_t *p_vout;
524 input_thread_t *p_input;
525 vector<vlc_object_t *> objects;
526 vector<const char *> varnames;
528 if( !current ) current = new QMenu();
530 if( current->isEmpty() )
532 ACT_ADD( current, "video-es", qtr( "Video &Track" ) );
535 QMenu *submenu = new QMenu( qtr( "&Subtitles Track" ), current );
536 action = current->addMenu( submenu );
537 action->setData( "spu-es" );
538 addDPStaticEntry( submenu, qtr( "Open File..." ), "",
539 SLOT( loadSubtitlesFile() ) );
540 submenu->addSeparator();
542 ACT_ADD( current, "fullscreen", qtr( "&Fullscreen" ) );
543 ACT_ADD( current, "zoom", qtr( "&Zoom" ) );
544 ACT_ADD( current, "deinterlace", qtr( "&Deinterlace" ) );
545 ACT_ADD( current, "aspect-ratio", qtr( "&Aspect Ratio" ) );
546 ACT_ADD( current, "crop", qtr( "&Crop" ) );
547 ACT_ADD( current, "video-on-top", qtr( "Always &On Top" ) );
549 ACT_ADD( current, "directx-wallpaper", qtr( "DirectX Wallpaper" ) );
551 ACT_ADD( current, "video-snapshot", qtr( "Sna&pshot" ) );
552 ACT_ADD( current, "postproc-q", qtr( "Post processing" ) );
555 p_input = THEMIM->getInput();
557 vlc_object_hold( p_input );
559 p_vout = THEMIM->getVout();
562 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
563 vlc_object_release( p_vout );
566 vlc_object_release( p_input );
568 return Populate( p_intf, current, varnames, objects );
573 * For DVD, MP4, MOV and other chapter based format
575 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
577 if( !menu ) menu = new QMenu();
579 if( menu->isEmpty() )
581 addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ),"",
582 SLOT( gotoTimeDialog() ), "Ctrl+T" );
583 menu->addSeparator();
585 ACT_ADD( menu, "bookmark", qtr( "&Bookmarks" ) );
586 ACT_ADD( menu, "title", qtr( "T&itle" ) );
587 ACT_ADD( menu, "chapter", qtr( "&Chapter" ) );
588 ACT_ADD( menu, "program", qtr( "&Program" ) );
589 ACT_ADD( menu, "navigation", qtr( "&Navigation" ) );
592 input_thread_t *p_object;
593 vector<vlc_object_t *> objects;
594 vector<const char *> varnames;
596 p_object = THEMIM->getInput();
598 vlc_object_hold( p_object );
599 InputAutoMenuBuilder( p_object, objects, varnames );
600 PUSH_VAR( "prev-title" );
601 PUSH_VAR( "next-title" );
602 PUSH_VAR( "prev-chapter" );
603 PUSH_VAR( "next-chapter" );
604 EnableDPStaticEntries( menu, ( p_object != NULL ) );
607 vlc_object_release( p_object );
609 return Populate( p_intf, menu, varnames, objects );
613 * Service Discovery SubMenu
615 QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf )
617 QMenu *menu = new QMenu();
618 menu->setTitle( qtr( I_PL_SD ) );
619 char **ppsz_longnames;
620 char **ppsz_names = vlc_sd_GetNames( &ppsz_longnames );
624 char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
625 for( ; *ppsz_name; ppsz_name++, ppsz_longname++ )
627 QAction *a = new QAction( qfu( *ppsz_longname ), menu );
628 a->setCheckable( true );
629 if( playlist_IsServicesDiscoveryLoaded( THEPL, *ppsz_name ) )
630 a->setChecked( true );
631 CONNECT( a , triggered(), THEDP->SDMapper, map() );
632 THEDP->SDMapper->setMapping( a, QString( *ppsz_name ) );
633 menu->addAction( a );
635 if( !strcmp( *ppsz_name, "podcast" ) )
637 QAction *b = new QAction( qtr( "Configure podcasts..." ), menu );
638 //b->setEnabled( a->isChecked() );
639 menu->addAction( b );
640 CONNECT( b, triggered(), THEDP, podcastConfigureDialog() );
643 free( *ppsz_longname );
646 free( ppsz_longnames );
652 QMenu *QVLCMenu::HelpMenu( QMenu *current )
654 QMenu *menu = new QMenu( current );
655 addDPStaticEntry( menu, qtr( "&Help..." ) ,
656 ":/help", SLOT( helpDialog() ), "F1" );
658 addDPStaticEntry( menu, qtr( "Check for &Updates..." ) , "",
659 SLOT( updateDialog() ) );
661 menu->addSeparator();
662 addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), ":/info",
663 SLOT( aboutDialog() ), "Shift+F1" );
667 /*****************************************************************************
668 * Popup menus - Right Click menus *
669 *****************************************************************************/
670 #define POPUP_BOILERPLATE \
671 unsigned int i_last_separator = 0; \
672 vector<vlc_object_t *> objects; \
673 vector<const char *> varnames; \
674 input_thread_t *p_input = THEMIM->getInput();
676 #define CREATE_POPUP \
677 Populate( p_intf, menu, varnames, objects ); \
678 p_intf->p_sys->p_popup_menu = menu; \
679 menu->popup( QCursor::pos() ); \
680 p_intf->p_sys->p_popup_menu = NULL; \
681 i_last_separator = 0;
683 void QVLCMenu::PopupMenuControlEntries( QMenu *menu,
684 intf_thread_t *p_intf,
685 input_thread_t *p_input )
690 var_Get( p_input, "state", &val );
691 if( val.i_int == PLAYING_S )
692 addMIMStaticEntry( p_intf, menu, qtr( "Pause" ),
693 ":/pause", SLOT( togglePlayPause() ) );
695 addMIMStaticEntry( p_intf, menu, qtr( "Play" ),
696 ":/play", SLOT( togglePlayPause() ) );
698 else if( THEPL->items.i_size )
699 addMIMStaticEntry( p_intf, menu, qtr( "Play" ),
700 ":/play", SLOT( togglePlayPause() ) );
702 addDPStaticEntry( menu, qtr( "Play" ),
703 ":/play", SLOT( openDialog() ) );
705 addMIMStaticEntry( p_intf, menu, qtr( "Stop" ),
706 ":/stop", SLOT( stop() ) );
707 addMIMStaticEntry( p_intf, menu, qtr( "Previous" ),
708 ":/previous", SLOT( prev() ) );
709 addMIMStaticEntry( p_intf, menu, qtr( "Next" ),
710 ":/next", SLOT( next() ) );
713 void QVLCMenu::PopupMenuStaticEntries( QMenu *menu )
716 QMenu *toolsmenu = ToolsMenu( p_intf, menu, false, true );
717 toolsmenu->setTitle( qtr( "Tools" ) );
718 menu->addMenu( toolsmenu );
721 QMenu *openmenu = new QMenu( qtr( "Open Media" ), menu );
722 addDPStaticEntry( openmenu, qtr( "&Open File..." ),
723 ":/file-asym", SLOT( openFileDialog() ) );
724 addDPStaticEntry( openmenu, qtr( I_OPEN_FOLDER ),
725 ":/folder-grey", SLOT( PLOpenDir() ) );
726 addDPStaticEntry( openmenu, qtr( "Open &Disc..." ),
727 ":/disc", SLOT( openDiscDialog() ) );
728 addDPStaticEntry( openmenu, qtr( "Open &Network..." ),
729 ":/network", SLOT( openNetDialog() ) );
730 addDPStaticEntry( openmenu, qtr( "Open &Capture Device..." ),
731 ":/capture-card", SLOT( openCaptureDialog() ) );
732 menu->addMenu( openmenu );
734 menu->addSeparator();
736 QMenu *helpmenu = HelpMenu( menu );
737 helpmenu->setTitle( qtr( "Help" ) );
738 menu->addMenu( helpmenu );
741 addDPStaticEntry( menu, qtr( "Quit" ), ":/quit",
742 SLOT( quit() ), "Ctrl+Q" );
745 /* Video Tracks and Subtitles tracks */
746 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
751 vlc_object_hold( p_input );
752 vout_thread_t *p_vout = THEMIM->getVout();
755 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
756 vlc_object_release( p_vout );
758 vlc_object_release( p_input );
760 QMenu *menu = new QMenu();
765 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
770 vlc_object_hold( p_input );
771 aout_instance_t *p_aout = THEMIM->getAout();
772 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
774 vlc_object_release( p_aout );
775 vlc_object_release( p_input );
777 QMenu *menu = new QMenu();
781 /* Navigation stuff, and general menus ( open ) */
782 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
788 vlc_object_hold( p_input );
789 varnames.push_back( "audio-es" );
790 InputAutoMenuBuilder( p_input, objects, varnames );
794 QMenu *menu = new QMenu();
795 Populate( p_intf, menu, varnames, objects );
797 menu->addSeparator();
798 PopupMenuControlEntries( menu, p_intf, p_input );
800 menu->addSeparator();
801 PopupMenuStaticEntries( menu );
803 p_intf->p_sys->p_popup_menu = menu;
804 menu->popup( QCursor::pos() );
805 p_intf->p_sys->p_popup_menu = NULL;
808 /* Main Menu that sticks everything together */
809 void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
811 MainInterface *mi = p_intf->p_sys->p_mi;
814 /* Delete and recreate a popup if there is one */
815 if( p_intf->p_sys->p_popup_menu )
816 delete p_intf->p_sys->p_popup_menu;
818 QMenu *menu = new QMenu();
821 bool b_isFullscreen = false;
825 PopupMenuControlEntries( menu, p_intf, p_input );
826 menu->addSeparator();
830 vout_thread_t *p_vout = THEMIM->getVout();
832 /* Add a fullscreen switch button */
836 var_Get( p_vout, "fullscreen", &val );
837 b_isFullscreen = !( !val.b_bool );
839 CreateAndConnect( menu, "fullscreen",
840 qtr( "Leave Fullscreen" ),"" , ITEM_NORMAL,
841 VLC_OBJECT(p_vout), val, VLC_VAR_BOOL,
843 vlc_object_release( p_vout );
846 menu->addSeparator();
848 vlc_object_hold( p_input );
849 InputAutoMenuBuilder( p_input, objects, varnames );
850 vlc_object_release( p_input );
852 submenu = new QMenu( menu );
853 action = menu->addMenu( AudioMenu( p_intf, submenu ) );
854 action->setText( qtr( "&Audio" ) );
855 if( action->menu()->isEmpty() )
856 action->setEnabled( false );
858 submenu = new QMenu( menu );
859 action = menu->addMenu( VideoMenu( p_intf, submenu ) );
860 action->setText( qtr( "&Video" ) );
861 if( action->menu()->isEmpty() )
862 action->setEnabled( false );
864 submenu = new QMenu( menu );
865 action = menu->addMenu( NavigMenu( p_intf, submenu ) );
866 action->setText( qtr( "&Playback" ) );
867 if( action->menu()->isEmpty() )
868 action->setEnabled( false );
871 menu->addSeparator();
873 /* Add some special entries for windowed mode: Interface Menu */
874 if( !b_isFullscreen )
876 submenu = new QMenu( qtr( "Interface" ), menu );
879 submenu->addAction( QIcon( ":/playlist" ),
880 qtr( "Show Playlist" ), mi, SLOT( togglePlaylist() ) );
882 addDPStaticEntry( submenu, qtr( I_MENU_EXT ),
883 ":/settings", SLOT( extendedDialog() ) );
884 addDPStaticEntry( submenu, qtr( I_MENU_INFO ) , ":/info",
885 SLOT( mediaInfoDialog() ), "Ctrl+I" );
888 action = submenu->addAction( QIcon( "" ),
889 qtr( "Minimal View" ), mi, SLOT( toggleMinimalView() ) );
890 action->setCheckable( true );
891 action->setChecked( !( mi->getControlsVisibilityStatus() &
892 CONTROLS_VISIBLE ) );
893 action = submenu->addAction( QIcon( "" ),
894 qtr( "Toggle Fullscreen Interface" ),
895 mi, SLOT( toggleFullScreen() ) );
896 action->setCheckable( true );
897 action->setChecked( mi->isFullScreen() );
899 else /* We are using the skins interface.
900 If not, this entry will not show. */
902 addDPStaticEntry( submenu, qtr( "&Preferences..." ),
903 ":/preferences", SLOT( prefsDialog() ), "Ctrl+P" );
904 submenu->addSeparator();
907 vlc_object_t *p_object = ( vlc_object_t* )
908 vlc_object_find_name( p_intf, "skins2", FIND_PARENT );
911 objects.push_back( p_object );
912 varnames.push_back( "intf-skins" );
913 Populate( p_intf, submenu, varnames, objects );
914 vlc_object_release( p_object );
918 msg_Dbg( p_intf, "could not find parent interface" );
921 menu->addMenu( submenu );
924 PopupMenuStaticEntries( menu );
926 p_intf->p_sys->p_popup_menu = menu;
927 p_intf->p_sys->p_popup_menu->popup( QCursor::pos() );
931 // destroy popup if there is one
932 delete p_intf->p_sys->p_popup_menu;
933 p_intf->p_sys->p_popup_menu = NULL;
939 /************************************************************************
941 ************************************************************************/
943 void QVLCMenu::updateSystrayMenu( MainInterface *mi,
944 intf_thread_t *p_intf,
945 bool b_force_visible )
949 /* Get the systray menu and clean it */
950 QMenu *sysMenu = mi->getSysTrayMenu();
953 /* Hide / Show VLC and cone */
954 if( mi->isVisible() || b_force_visible )
956 sysMenu->addAction( QIcon( ":/vlc16.png" ),
957 qtr( "Hide VLC media player in taskbar" ), mi,
958 SLOT( toggleUpdateSystrayMenu() ) );
962 sysMenu->addAction( QIcon( ":/vlc16.png" ),
963 qtr( "Show VLC media player" ), mi,
964 SLOT( toggleUpdateSystrayMenu() ) );
967 sysMenu->addSeparator();
968 PopupMenuControlEntries( sysMenu, p_intf, p_input );
970 sysMenu->addSeparator();
971 addDPStaticEntry( sysMenu, qtr( "&Open Media" ),
972 ":/file-wide", SLOT( openFileDialog() ) );
973 addDPStaticEntry( sysMenu, qtr( "&Quit" ) ,
974 ":/quit", SLOT( quit() ) );
977 mi->getSysTray()->setContextMenu( sysMenu );
981 #undef PUSH_SEPARATOR
983 /*************************************************************************
984 * Builders for automenus
985 *************************************************************************/
986 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf,
988 vector< const char *> & varnames,
989 vector<vlc_object_t *> & objects )
991 QMenu *menu = current;
992 if( !menu ) menu = new QMenu();
994 /* Disable all non static entries */
996 foreach( p_action, menu->actions() )
998 if( p_action->data().toString() != "_static_" )
999 p_action->setEnabled( false );
1002 currentGroup = NULL;
1004 vlc_object_t *p_object;
1007 for( i = 0; i < ( int )objects.size() ; i++ )
1009 if( !varnames[i] || !*varnames[i] )
1011 menu->addSeparator();
1014 p_object = objects[i];
1016 UpdateItem( p_intf, menu, varnames[i], p_object, true );
1021 /*****************************************************************************
1023 *****************************************************************************/
1025 static bool IsMenuEmpty( const char *psz_var,
1026 vlc_object_t *p_object,
1027 bool b_root = true )
1029 vlc_value_t val, val_list;
1030 int i_type, i_result, i;
1032 /* Check the type of the object variable */
1033 i_type = var_Type( p_object, psz_var );
1035 /* Check if we want to display the variable */
1036 if( !( i_type & VLC_VAR_HASCHOICE ) ) return false;
1038 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
1039 if( val.i_int == 0 ) return true;
1041 if( ( i_type & VLC_VAR_TYPE ) != VLC_VAR_VARIABLE )
1043 if( val.i_int == 1 && b_root ) return true;
1047 /* Check children variables in case of VLC_VAR_VARIABLE */
1048 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
1053 for( i = 0, i_result = true; i < val_list.p_list->i_count; i++ )
1055 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
1063 /* clean up everything */
1064 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
1069 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
1071 void QVLCMenu::UpdateItem( intf_thread_t *p_intf, QMenu *menu,
1072 const char *psz_var, vlc_object_t *p_object, bool b_submenu )
1074 vlc_value_t val, text;
1077 QAction *action = FindActionWithVar( menu, psz_var );
1079 DeleteNonStaticEntries( action->menu() );
1084 /* Check the type of the object variable */
1085 if( !strcmp( psz_var, "audio-es" )
1086 || !strcmp( psz_var, "video-es" )
1087 || !strcmp( psz_var, "postproc-q" ) )
1088 i_type = VLC_VAR_INTEGER | VLC_VAR_HASCHOICE;
1090 i_type = var_Type( p_object, psz_var );
1092 switch( i_type & VLC_VAR_TYPE )
1096 case VLC_VAR_VARIABLE:
1097 case VLC_VAR_STRING:
1098 case VLC_VAR_INTEGER:
1102 /* Variable doesn't exist or isn't handled */
1106 /* Make sure we want to display the variable */
1107 if( menu->isEmpty() && IsMenuEmpty( psz_var, p_object ) )
1110 /* Get the descriptive name of the variable */
1111 int i_ret = var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
1112 if( i_ret != VLC_SUCCESS )
1114 text.psz_string = NULL;
1119 action = new QAction( TEXT_OR_VAR, menu );
1120 menu->addAction( action );
1121 action->setData( psz_var );
1124 /* Some specific stuff */
1125 bool forceDisabled = false;
1126 if( !strcmp( psz_var, "spu-es" ) )
1128 vout_thread_t *p_vout = THEMIM->getVout();
1129 forceDisabled = ( p_vout == NULL );
1131 vlc_object_release( p_vout );
1134 if( i_type & VLC_VAR_HASCHOICE )
1136 /* Append choices menu */
1140 submenu = action->menu();
1143 submenu = new QMenu( menu );
1144 action->setMenu( submenu );
1148 CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0 );
1150 action->setEnabled( false );
1153 CreateChoicesMenu( menu, psz_var, p_object, true );
1154 FREENULL( text.psz_string );
1158 switch( i_type & VLC_VAR_TYPE )
1161 var_Get( p_object, psz_var, &val );
1162 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
1163 p_object, val, i_type );
1167 var_Get( p_object, psz_var, &val );
1168 val.b_bool = !val.b_bool;
1169 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
1170 p_object, val, i_type, !val.b_bool );
1173 FREENULL( text.psz_string );
1177 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
1178 vlc_object_t *p_object, bool b_root )
1180 vlc_value_t val, val_list, text_list;
1183 /* Check the type of the object variable */
1184 i_type = var_Type( p_object, psz_var );
1186 /* Make sure we want to display the variable */
1187 if( submenu->isEmpty() && IsMenuEmpty( psz_var, p_object, b_root ) )
1188 return VLC_EGENERIC;
1190 switch( i_type & VLC_VAR_TYPE )
1194 case VLC_VAR_VARIABLE:
1195 case VLC_VAR_STRING:
1196 case VLC_VAR_INTEGER:
1200 /* Variable doesn't exist or isn't handled */
1201 return VLC_EGENERIC;
1204 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
1205 &val_list, &text_list ) < 0 )
1207 return VLC_EGENERIC;
1210 #define CURVAL val_list.p_list->p_values[i]
1211 #define CURTEXT text_list.p_list->p_values[i].psz_string
1213 for( i = 0; i < val_list.p_list->i_count; i++ )
1215 vlc_value_t another_val;
1217 QMenu *subsubmenu = new QMenu( submenu );
1219 switch( i_type & VLC_VAR_TYPE )
1221 case VLC_VAR_VARIABLE:
1222 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
1223 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
1224 submenu->addMenu( subsubmenu );
1227 case VLC_VAR_STRING:
1228 var_Get( p_object, psz_var, &val );
1229 another_val.psz_string = strdup( CURVAL.psz_string );
1230 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
1231 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1232 p_object, another_val, i_type,
1233 val.psz_string && !strcmp( val.psz_string, CURVAL.psz_string ) );
1235 free( val.psz_string );
1238 case VLC_VAR_INTEGER:
1239 var_Get( p_object, psz_var, &val );
1240 if( CURTEXT ) menutext = qfu( CURTEXT );
1241 else menutext.sprintf( "%d", CURVAL.i_int );
1242 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1243 p_object, CURVAL, i_type,
1244 CURVAL.i_int == val.i_int );
1248 var_Get( p_object, psz_var, &val );
1249 if( CURTEXT ) menutext = qfu( CURTEXT );
1250 else menutext.sprintf( "%.2f", CURVAL.f_float );
1251 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1252 p_object, CURVAL, i_type,
1253 CURVAL.f_float == val.f_float );
1260 currentGroup = NULL;
1262 /* clean up everything */
1263 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
1270 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
1271 QString text, QString help,
1272 int i_item_type, vlc_object_t *p_obj,
1273 vlc_value_t val, int i_val_type,
1276 QAction *action = FindActionWithVar( menu, psz_var );
1279 action = new QAction( text, menu );
1280 menu->addAction( action );
1283 action->setToolTip( help );
1284 action->setEnabled( p_obj != NULL );
1286 if( i_item_type == ITEM_CHECK )
1288 action->setCheckable( true );
1290 else if( i_item_type == ITEM_RADIO )
1292 action->setCheckable( true );
1294 currentGroup = new QActionGroup( menu );
1295 currentGroup->addAction( action );
1298 action->setChecked( checked );
1300 MenuItemData *itemData = new MenuItemData( THEDP->menusMapper, p_obj, i_val_type,
1302 CONNECT( action, triggered(), THEDP->menusMapper, map() );
1303 THEDP->menusMapper->setMapping( action, itemData );
1304 menu->addAction( action );
1307 void QVLCMenu::DoAction( QObject *data )
1309 MenuItemData *itemData = qobject_cast<MenuItemData *>( data );
1310 vlc_object_t *p_object = itemData->p_obj;
1311 if( p_object == NULL ) return;
1313 var_Set( p_object, itemData->psz_var, itemData->val );
1316 void QVLCMenu::updateRecents( intf_thread_t *p_intf )
1321 RecentsMRL* rmrl = RecentsMRL::getInstance( p_intf );
1322 QList<QString> l = rmrl->recents();
1324 recentsMenu->clear();
1327 action = recentsMenu->addAction( " - Empty - " );
1328 action->setEnabled( false );
1332 for( int i = 0; i < l.size(); ++i )
1334 action = recentsMenu->addAction(
1335 QString( "&%1: " ).arg( i + 1 ) + l.at( i ),
1338 rmrl->signalMapper->setMapping( action, l.at( i ) );
1341 recentsMenu->addSeparator();
1342 recentsMenu->addAction( "&Clear", rmrl, SLOT( clear() ) );