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( NULL ), 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( QMenu *parent )
363 addDPStaticEntry( menu, qtr( I_MENU_EXT ), ":/settings",
364 SLOT( extendedDialog() ), "Ctrl+E" );
366 addDPStaticEntry( menu, qtr( I_MENU_INFO ) , ":/info",
367 SLOT( mediaInfoDialog() ), "Ctrl+I" );
368 addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) ,
369 ":/info", SLOT( mediaCodecDialog() ), "Ctrl+J" );
371 addDPStaticEntry( menu, qtr( I_MENU_BOOKMARK ),"",
372 SLOT( bookmarksDialog() ), "Ctrl+B" );
374 addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", SLOT( vlmDialog() ),
378 addDPStaticEntry( menu, qtr( I_MENU_MSG ),
379 ":/messages", SLOT( messagesDialog() ),
382 addDPStaticEntry( menu, qtr( "Plu&gins and extensions" ),
383 "", SLOT( pluginDialog() ) );
384 menu->addSeparator();
386 addDPStaticEntry( menu, qtr( "&Preferences" ),
387 ":/preferences", SLOT( prefsDialog() ), "Ctrl+P" );
394 * This menu can be an interface menu but also a right click menu.
396 QMenu *QVLCMenu::ViewMenu( intf_thread_t *p_intf,
399 bool visual_selector_enabled,
402 QMenu *menu = new QMenu( current );
406 act = menu->addAction( QIcon( ":/playlist_menu" ),
407 qtr( "Play&list" ), mi,
408 SLOT( togglePlaylist() ), qtr( "Ctrl+L" ) );
409 act->setData( true );
411 act = menu->addMenu( SDMenu( p_intf ) );
412 act->setData( true );
413 /*menu->addSeparator();
414 menu->addAction( qtr( "Undock from Interface" ), mi,
415 SLOT( undockPlaylist() ), qtr( "Ctrl+U" ) );*/
418 menu->addSeparator();
422 QMenu *intfmenu = InterfacesMenu( p_intf, menu );
423 MenuFunc *f = new MenuFunc( intfmenu, 4 );
424 CONNECT( intfmenu, aboutToShow(), THEDP->menusUpdateMapper, map() );
425 THEDP->menusUpdateMapper->setMapping( intfmenu, f );
426 menu->addSeparator();
431 QAction *action = menu->addAction( qtr( "Mi&nimal View" ), mi,
432 SLOT( toggleMinimalView() ), qtr( "Ctrl+H" ) );
433 action->setCheckable( true );
434 action->setData( true );
435 if( mi->getControlsVisibilityStatus() & CONTROLS_VISIBLE )
436 action->setChecked( true );
437 minimalViewAction = action; /* HACK for minimalView */
439 /* FullScreen View */
440 action = menu->addAction( qtr( "&Fullscreen Interface" ), mi,
441 SLOT( toggleFullScreen() ), QString( "F11" ) );
442 action->setCheckable( true );
443 action->setData( true );
445 /* Advanced Controls */
446 action = menu->addAction( qtr( "&Advanced Controls" ), mi,
447 SLOT( toggleAdvanced() ) );
448 action->setCheckable( true );
449 action->setData( true );
450 if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
451 action->setChecked( true );
452 #if 0 /* For Visualisations. Not yet working */
453 adv = menu->addAction( qtr( "Visualizations selector" ),
454 mi, SLOT( visual() ) );
455 adv->setCheckable( true );
456 if( visual_selector_enabled ) adv->setChecked( true );
460 menu->addSeparator();
461 addDPStaticEntry( menu, qtr( "Customi&ze Interface..." ),
462 ":/preferences", SLOT( toolbarDialog() ) );
463 menu->addSeparator();
469 * Interface Sub-Menu, to list extras interface and skins
471 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
473 vector<vlc_object_t *> objects;
474 vector<const char *> varnames;
475 /** \todo add "switch to XXX" */
476 varnames.push_back( "intf-add" );
477 objects.push_back( VLC_OBJECT(p_intf) );
479 return Populate( p_intf, current, varnames, objects );
485 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
487 vector<vlc_object_t *> objects;
488 vector<const char *> varnames;
489 aout_instance_t *p_aout;
490 input_thread_t *p_input;
492 if( !current ) current = new QMenu();
494 if( current->isEmpty() )
496 ACT_ADD( current, "audio-es", qtr( "Audio &Track" ) );
497 ACT_ADD( current, "audio-device", qtr( "Audio &Device" ) );
498 ACT_ADD( current, "audio-channels", qtr( "Audio &Channels" ) );
499 current->addSeparator();
500 ACT_ADD( current, "visual", qtr( "&Visualizations" ) );
503 p_input = THEMIM->getInput();
505 vlc_object_hold( p_input );
506 p_aout = THEMIM->getAout();
507 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
508 EnableStaticEntries( current, ( p_aout != NULL ) );
511 vlc_object_release( p_aout );
514 vlc_object_release( p_input );
516 return Populate( p_intf, current, varnames, objects );
521 * Subtitles are part of Video.
523 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
525 vout_thread_t *p_vout;
526 input_thread_t *p_input;
527 vector<vlc_object_t *> objects;
528 vector<const char *> varnames;
530 if( !current ) current = new QMenu();
532 if( current->isEmpty() )
534 ACT_ADD( current, "video-es", qtr( "Video &Track" ) );
537 QMenu *submenu = new QMenu( qtr( "&Subtitles Track" ), current );
538 action = current->addMenu( submenu );
539 action->setData( "spu-es" );
540 addDPStaticEntry( submenu, qtr( "Open File..." ), "",
541 SLOT( loadSubtitlesFile() ) );
542 submenu->addSeparator();
544 ACT_ADD( current, "fullscreen", qtr( "&Fullscreen" ) );
545 ACT_ADD( current, "zoom", qtr( "&Zoom" ) );
546 ACT_ADD( current, "deinterlace", qtr( "&Deinterlace" ) );
547 ACT_ADD( current, "aspect-ratio", qtr( "&Aspect Ratio" ) );
548 ACT_ADD( current, "crop", qtr( "&Crop" ) );
549 ACT_ADD( current, "video-on-top", qtr( "Always &On Top" ) );
551 ACT_ADD( current, "directx-wallpaper", qtr( "DirectX Wallpaper" ) );
553 ACT_ADD( current, "video-snapshot", qtr( "Sna&pshot" ) );
554 ACT_ADD( current, "postproc-q", qtr( "Post processing" ) );
557 p_input = THEMIM->getInput();
559 vlc_object_hold( p_input );
561 p_vout = THEMIM->getVout();
562 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
563 EnableStaticEntries( current, ( p_vout != NULL ) );
566 vlc_object_release( p_vout );
569 vlc_object_release( p_input );
571 return Populate( p_intf, current, varnames, objects );
576 * For DVD, MP4, MOV and other chapter based format
578 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
580 if( !menu ) menu = new QMenu();
582 if( menu->isEmpty() )
584 addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ),"",
585 SLOT( gotoTimeDialog() ), "Ctrl+T" );
586 menu->addSeparator();
588 ACT_ADD( menu, "bookmark", qtr( "&Bookmarks" ) );
589 ACT_ADD( menu, "title", qtr( "T&itle" ) );
590 ACT_ADD( menu, "chapter", qtr( "&Chapter" ) );
591 ACT_ADD( menu, "program", qtr( "&Program" ) );
592 ACT_ADD( menu, "navigation", qtr( "&Navigation" ) );
595 input_thread_t *p_object;
596 vector<vlc_object_t *> objects;
597 vector<const char *> varnames;
599 p_object = THEMIM->getInput();
601 vlc_object_hold( p_object );
602 InputAutoMenuBuilder( p_object, objects, varnames );
603 PUSH_VAR( "prev-title" );
604 PUSH_VAR( "next-title" );
605 PUSH_VAR( "prev-chapter" );
606 PUSH_VAR( "next-chapter" );
607 EnableStaticEntries( menu, ( p_object != NULL ) );
610 vlc_object_release( p_object );
612 return Populate( p_intf, menu, varnames, objects );
616 * Service Discovery SubMenu
618 QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf )
620 QMenu *menu = new QMenu();
621 menu->setTitle( qtr( I_PL_SD ) );
622 char **ppsz_longnames;
623 char **ppsz_names = vlc_sd_GetNames( &ppsz_longnames );
627 char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
628 for( ; *ppsz_name; ppsz_name++, ppsz_longname++ )
630 QAction *a = new QAction( qfu( *ppsz_longname ), menu );
631 a->setCheckable( true );
632 if( playlist_IsServicesDiscoveryLoaded( THEPL, *ppsz_name ) )
633 a->setChecked( true );
634 CONNECT( a , triggered(), THEDP->SDMapper, map() );
635 THEDP->SDMapper->setMapping( a, QString( *ppsz_name ) );
636 menu->addAction( a );
638 if( !strcmp( *ppsz_name, "podcast" ) )
640 QAction *b = new QAction( qtr( "Configure podcasts..." ), menu );
641 //b->setEnabled( a->isChecked() );
642 menu->addAction( b );
643 CONNECT( b, triggered(), THEDP, podcastConfigureDialog() );
646 free( *ppsz_longname );
649 free( ppsz_longnames );
655 QMenu *QVLCMenu::HelpMenu( QMenu *current )
657 QMenu *menu = new QMenu( current );
658 addDPStaticEntry( menu, qtr( "&Help..." ) ,
659 ":/help", SLOT( helpDialog() ), "F1" );
661 addDPStaticEntry( menu, qtr( "Check for &Updates..." ) , "",
662 SLOT( updateDialog() ) );
664 menu->addSeparator();
665 addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), ":/info",
666 SLOT( aboutDialog() ), "Shift+F1" );
670 /*****************************************************************************
671 * Popup menus - Right Click menus *
672 *****************************************************************************/
673 #define POPUP_BOILERPLATE \
674 unsigned int i_last_separator = 0; \
675 vector<vlc_object_t *> objects; \
676 vector<const char *> varnames; \
677 input_thread_t *p_input = THEMIM->getInput();
679 #define CREATE_POPUP \
680 Populate( p_intf, menu, varnames, objects ); \
681 p_intf->p_sys->p_popup_menu = menu; \
682 menu->popup( QCursor::pos() ); \
683 p_intf->p_sys->p_popup_menu = NULL; \
684 i_last_separator = 0;
686 void QVLCMenu::PopupMenuControlEntries( QMenu *menu,
687 intf_thread_t *p_intf,
688 input_thread_t *p_input )
693 var_Get( p_input, "state", &val );
694 if( val.i_int == PLAYING_S )
695 addMIMStaticEntry( p_intf, menu, qtr( "Pause" ),
696 ":/pause", SLOT( togglePlayPause() ) );
698 addMIMStaticEntry( p_intf, menu, qtr( "Play" ),
699 ":/play", SLOT( togglePlayPause() ) );
701 else if( THEPL->items.i_size )
702 addMIMStaticEntry( p_intf, menu, qtr( "Play" ),
703 ":/play", SLOT( togglePlayPause() ) );
705 addDPStaticEntry( menu, qtr( "Play" ),
706 ":/play", SLOT( openDialog() ) );
708 addMIMStaticEntry( p_intf, menu, qtr( "Stop" ),
709 ":/stop", SLOT( stop() ) );
710 addMIMStaticEntry( p_intf, menu, qtr( "Previous" ),
711 ":/previous", SLOT( prev() ) );
712 addMIMStaticEntry( p_intf, menu, qtr( "Next" ),
713 ":/next", SLOT( next() ) );
716 void QVLCMenu::PopupMenuStaticEntries( QMenu *menu )
718 QMenu *openmenu = new QMenu( qtr( "Open Media" ), menu );
719 addDPStaticEntry( openmenu, qtr( "&Open File..." ),
720 ":/file-asym", SLOT( openFileDialog() ) );
721 addDPStaticEntry( openmenu, qtr( I_OPEN_FOLDER ),
722 ":/folder-grey", SLOT( PLOpenDir() ) );
723 addDPStaticEntry( openmenu, qtr( "Open &Disc..." ),
724 ":/disc", SLOT( openDiscDialog() ) );
725 addDPStaticEntry( openmenu, qtr( "Open &Network..." ),
726 ":/network", SLOT( openNetDialog() ) );
727 addDPStaticEntry( openmenu, qtr( "Open &Capture Device..." ),
728 ":/capture-card", SLOT( openCaptureDialog() ) );
729 menu->addMenu( openmenu );
731 menu->addSeparator();
733 QMenu *helpmenu = HelpMenu( menu );
734 helpmenu->setTitle( qtr( "Help" ) );
735 menu->addMenu( helpmenu );
738 addDPStaticEntry( menu, qtr( "Quit" ), ":/quit",
739 SLOT( quit() ), "Ctrl+Q" );
742 /* Video Tracks and Subtitles tracks */
743 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
748 vlc_object_hold( p_input );
749 vout_thread_t *p_vout = THEMIM->getVout();
752 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
753 vlc_object_release( p_vout );
755 vlc_object_release( p_input );
757 QMenu *menu = new QMenu();
762 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
767 vlc_object_hold( p_input );
768 aout_instance_t *p_aout = THEMIM->getAout();
769 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
771 vlc_object_release( p_aout );
772 vlc_object_release( p_input );
774 QMenu *menu = new QMenu();
778 /* Navigation stuff, and general menus ( open ) */
779 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
785 vlc_object_hold( p_input );
786 varnames.push_back( "audio-es" );
787 InputAutoMenuBuilder( p_input, objects, varnames );
791 QMenu *menu = new QMenu();
792 Populate( p_intf, menu, varnames, objects );
794 menu->addSeparator();
795 PopupMenuControlEntries( menu, p_intf, p_input );
797 menu->addSeparator();
798 PopupMenuStaticEntries( menu );
800 p_intf->p_sys->p_popup_menu = menu;
801 menu->popup( QCursor::pos() );
802 p_intf->p_sys->p_popup_menu = NULL;
805 /* Main Menu that sticks everything together */
806 void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
808 MainInterface *mi = p_intf->p_sys->p_mi;
811 /* Delete and recreate a popup if there is one */
812 if( p_intf->p_sys->p_popup_menu )
813 delete p_intf->p_sys->p_popup_menu;
815 QMenu *menu = new QMenu();
818 bool b_isFullscreen = false;
822 PopupMenuControlEntries( menu, p_intf, p_input );
823 menu->addSeparator();
827 vout_thread_t *p_vout = THEMIM->getVout();
829 /* Add a fullscreen switch button */
833 var_Get( p_vout, "fullscreen", &val );
834 b_isFullscreen = !( !val.b_bool );
836 CreateAndConnect( menu, "fullscreen",
837 qtr( "Leave Fullscreen" ),"" , ITEM_NORMAL,
838 VLC_OBJECT(p_vout), val, VLC_VAR_BOOL,
840 vlc_object_release( p_vout );
843 menu->addSeparator();
845 vlc_object_hold( p_input );
846 InputAutoMenuBuilder( p_input, objects, varnames );
847 vlc_object_release( p_input );
849 submenu = new QMenu( menu );
850 action = menu->addMenu( AudioMenu( p_intf, submenu ) );
851 action->setText( qtr( "&Audio" ) );
852 if( action->menu()->isEmpty() )
853 action->setEnabled( false );
855 submenu = new QMenu( menu );
856 action = menu->addMenu( VideoMenu( p_intf, submenu ) );
857 action->setText( qtr( "&Video" ) );
858 if( action->menu()->isEmpty() )
859 action->setEnabled( false );
861 submenu = new QMenu( menu );
862 action = menu->addMenu( NavigMenu( p_intf, submenu ) );
863 action->setText( qtr( "&Playback" ) );
864 if( action->menu()->isEmpty() )
865 action->setEnabled( false );
868 menu->addSeparator();
870 /* Add some special entries for windowed mode: Interface Menu */
871 if( !b_isFullscreen )
873 submenu = new QMenu( qtr( "Interface" ), menu );
876 submenu->addAction( QIcon( ":/playlist" ),
877 qtr( "Show Playlist" ), mi, SLOT( togglePlaylist() ) );
878 action = submenu->addAction( QIcon( "" ),
879 qtr( "Minimal View" ), mi, SLOT( toggleMinimalView() ) );
880 action->setCheckable( true );
881 action->setChecked( !( mi->getControlsVisibilityStatus() &
882 CONTROLS_VISIBLE ) );
883 action = submenu->addAction( QIcon( "" ),
884 qtr( "Toggle Fullscreen Interface" ),
885 mi, SLOT( toggleFullScreen() ) );
886 action->setCheckable( true );
887 action->setChecked( mi->isFullScreen() );
889 else /* We are using the skins interface.
890 If not, this entry will not show. */
893 QMenu *tools = ToolsMenu( submenu );
894 submenu->addSeparator();
897 vlc_object_t *p_object = ( vlc_object_t* )
898 vlc_object_find_name( p_intf, "skins2", FIND_PARENT );
901 objects.push_back( p_object );
902 varnames.push_back( "intf-skins" );
903 Populate( p_intf, submenu, varnames, objects );
904 vlc_object_release( p_object );
908 msg_Dbg( p_intf, "could not find parent interface" );
911 menu->addMenu( submenu );
914 PopupMenuStaticEntries( menu );
916 p_intf->p_sys->p_popup_menu = menu;
917 p_intf->p_sys->p_popup_menu->popup( QCursor::pos() );
921 // destroy popup if there is one
922 delete p_intf->p_sys->p_popup_menu;
923 p_intf->p_sys->p_popup_menu = NULL;
929 /************************************************************************
931 ************************************************************************/
933 void QVLCMenu::updateSystrayMenu( MainInterface *mi,
934 intf_thread_t *p_intf,
935 bool b_force_visible )
939 /* Get the systray menu and clean it */
940 QMenu *sysMenu = mi->getSysTrayMenu();
943 /* Hide / Show VLC and cone */
944 if( mi->isVisible() || b_force_visible )
946 sysMenu->addAction( QIcon( ":/vlc16.png" ),
947 qtr( "Hide VLC media player in taskbar" ), mi,
948 SLOT( toggleUpdateSystrayMenu() ) );
952 sysMenu->addAction( QIcon( ":/vlc16.png" ),
953 qtr( "Show VLC media player" ), mi,
954 SLOT( toggleUpdateSystrayMenu() ) );
957 sysMenu->addSeparator();
958 PopupMenuControlEntries( sysMenu, p_intf, p_input );
960 sysMenu->addSeparator();
961 addDPStaticEntry( sysMenu, qtr( "&Open Media" ),
962 ":/file-wide", SLOT( openFileDialog() ) );
963 addDPStaticEntry( sysMenu, qtr( "&Quit" ) ,
964 ":/quit", SLOT( quit() ) );
967 mi->getSysTray()->setContextMenu( sysMenu );
971 #undef PUSH_SEPARATOR
973 /*************************************************************************
974 * Builders for automenus
975 *************************************************************************/
976 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf,
978 vector< const char *> & varnames,
979 vector<vlc_object_t *> & objects )
981 QMenu *menu = current;
982 if( !menu ) menu = new QMenu();
986 vlc_object_t *p_object;
988 for( int i = 0; i < ( int )objects.size() ; i++ )
990 if( !varnames[i] || !*varnames[i] )
992 menu->addSeparator();
995 p_object = objects[i];
997 UpdateItem( p_intf, menu, varnames[i], p_object, true );
1002 /*****************************************************************************
1004 *****************************************************************************/
1006 static bool IsMenuEmpty( const char *psz_var,
1007 vlc_object_t *p_object,
1008 bool b_root = true )
1010 vlc_value_t val, val_list;
1011 int i_type, i_result, i;
1013 /* Check the type of the object variable */
1014 i_type = var_Type( p_object, psz_var );
1016 /* Check if we want to display the variable */
1017 if( !( i_type & VLC_VAR_HASCHOICE ) ) return false;
1019 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
1020 if( val.i_int == 0 ) return true;
1022 if( ( i_type & VLC_VAR_TYPE ) != VLC_VAR_VARIABLE )
1024 if( val.i_int == 1 && b_root ) return true;
1028 /* Check children variables in case of VLC_VAR_VARIABLE */
1029 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
1034 for( i = 0, i_result = true; i < val_list.p_list->i_count; i++ )
1036 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
1044 /* clean up everything */
1045 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
1050 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
1052 void QVLCMenu::UpdateItem( intf_thread_t *p_intf, QMenu *menu,
1053 const char *psz_var, vlc_object_t *p_object, bool b_submenu )
1055 vlc_value_t val, text;
1058 QAction *action = FindActionWithVar( menu, psz_var );
1060 DeleteNonStaticEntries( action->menu() );
1065 action->setEnabled( false );
1069 /* Check the type of the object variable */
1070 /* What is the following HACK needed for? */
1071 if( !strcmp( psz_var, "audio-es" )
1072 || !strcmp( psz_var, "video-es" )
1073 || !strcmp( psz_var, "postproc-q" ) )
1074 i_type = VLC_VAR_INTEGER | VLC_VAR_HASCHOICE;
1076 i_type = var_Type( p_object, psz_var );
1078 switch( i_type & VLC_VAR_TYPE )
1082 case VLC_VAR_VARIABLE:
1083 case VLC_VAR_STRING:
1084 case VLC_VAR_INTEGER:
1088 /* Variable doesn't exist or isn't handled */
1090 action->setEnabled( false );
1094 /* Make sure we want to display the variable */
1095 if( menu->isEmpty() && IsMenuEmpty( psz_var, p_object ) )
1098 action->setEnabled( false );
1102 /* Get the descriptive name of the variable */
1103 int i_ret = var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
1104 if( i_ret != VLC_SUCCESS )
1106 text.psz_string = NULL;
1111 action = new QAction( TEXT_OR_VAR, menu );
1112 menu->addAction( action );
1113 action->setData( psz_var );
1116 /* Some specific stuff */
1117 bool forceDisabled = false;
1118 if( !strcmp( psz_var, "spu-es" ) )
1120 vout_thread_t *p_vout = THEMIM->getVout();
1121 forceDisabled = ( p_vout == NULL );
1123 vlc_object_release( p_vout );
1126 if( i_type & VLC_VAR_HASCHOICE )
1128 /* Append choices menu */
1132 submenu = action->menu();
1135 submenu = new QMenu( menu );
1136 action->setMenu( submenu );
1140 CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0 );
1142 action->setEnabled( false );
1146 CreateChoicesMenu( menu, psz_var, p_object, true ) == 0 );
1147 FREENULL( text.psz_string );
1151 switch( i_type & VLC_VAR_TYPE )
1154 var_Get( p_object, psz_var, &val );
1155 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
1156 p_object, val, i_type );
1160 var_Get( p_object, psz_var, &val );
1161 val.b_bool = !val.b_bool;
1162 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
1163 p_object, val, i_type, !val.b_bool );
1166 FREENULL( text.psz_string );
1170 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
1171 vlc_object_t *p_object, bool b_root )
1173 vlc_value_t val, val_list, text_list;
1176 /* Check the type of the object variable */
1177 i_type = var_Type( p_object, psz_var );
1179 /* Make sure we want to display the variable */
1180 if( submenu->isEmpty() && IsMenuEmpty( psz_var, p_object, b_root ) )
1181 return VLC_EGENERIC;
1183 switch( i_type & VLC_VAR_TYPE )
1187 case VLC_VAR_VARIABLE:
1188 case VLC_VAR_STRING:
1189 case VLC_VAR_INTEGER:
1193 /* Variable doesn't exist or isn't handled */
1194 return VLC_EGENERIC;
1197 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
1198 &val_list, &text_list ) < 0 )
1200 return VLC_EGENERIC;
1203 #define CURVAL val_list.p_list->p_values[i]
1204 #define CURTEXT text_list.p_list->p_values[i].psz_string
1206 for( i = 0; i < val_list.p_list->i_count; i++ )
1208 vlc_value_t another_val;
1210 QMenu *subsubmenu = new QMenu( submenu );
1212 switch( i_type & VLC_VAR_TYPE )
1214 case VLC_VAR_VARIABLE:
1215 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
1216 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
1217 submenu->addMenu( subsubmenu );
1220 case VLC_VAR_STRING:
1221 var_Get( p_object, psz_var, &val );
1222 another_val.psz_string = strdup( CURVAL.psz_string );
1223 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
1224 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1225 p_object, another_val, i_type,
1226 val.psz_string && !strcmp( val.psz_string, CURVAL.psz_string ) );
1228 free( val.psz_string );
1231 case VLC_VAR_INTEGER:
1232 var_Get( p_object, psz_var, &val );
1233 if( CURTEXT ) menutext = qfu( CURTEXT );
1234 else menutext.sprintf( "%d", CURVAL.i_int );
1235 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1236 p_object, CURVAL, i_type,
1237 CURVAL.i_int == val.i_int );
1241 var_Get( p_object, psz_var, &val );
1242 if( CURTEXT ) menutext = qfu( CURTEXT );
1243 else menutext.sprintf( "%.2f", CURVAL.f_float );
1244 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1245 p_object, CURVAL, i_type,
1246 CURVAL.f_float == val.f_float );
1253 currentGroup = NULL;
1255 /* clean up everything */
1256 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
1260 return submenu->isEmpty() ? VLC_EGENERIC : VLC_SUCCESS;
1263 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
1264 QString text, QString help,
1265 int i_item_type, vlc_object_t *p_obj,
1266 vlc_value_t val, int i_val_type,
1269 QAction *action = FindActionWithVar( menu, psz_var );
1272 action = new QAction( text, menu );
1273 menu->addAction( action );
1276 action->setToolTip( help );
1277 action->setEnabled( p_obj != NULL );
1279 if( i_item_type == ITEM_CHECK )
1281 action->setCheckable( true );
1283 else if( i_item_type == ITEM_RADIO )
1285 action->setCheckable( true );
1287 currentGroup = new QActionGroup( menu );
1288 currentGroup->addAction( action );
1291 action->setChecked( checked );
1293 MenuItemData *itemData = new MenuItemData( THEDP->menusMapper, p_obj, i_val_type,
1295 CONNECT( action, triggered(), THEDP->menusMapper, map() );
1296 THEDP->menusMapper->setMapping( action, itemData );
1297 menu->addAction( action );
1300 void QVLCMenu::DoAction( QObject *data )
1302 MenuItemData *itemData = qobject_cast<MenuItemData *>( data );
1303 vlc_object_t *p_object = itemData->p_obj;
1304 if( p_object == NULL ) return;
1306 var_Set( p_object, itemData->psz_var, itemData->val );
1309 void QVLCMenu::updateRecents( intf_thread_t *p_intf )
1314 RecentsMRL* rmrl = RecentsMRL::getInstance( p_intf );
1315 QList<QString> l = rmrl->recents();
1317 recentsMenu->clear();
1320 action = recentsMenu->addAction( qtr(" - Empty - ") );
1321 action->setEnabled( false );
1325 for( int i = 0; i < l.size(); ++i )
1327 action = recentsMenu->addAction(
1328 QString( "&%1: " ).arg( i + 1 ) + l.at( i ),
1331 rmrl->signalMapper->setMapping( action, l.at( i ) );
1334 recentsMenu->addSeparator();
1335 recentsMenu->addAction( qtr("&Clear"), rmrl, SLOT( clear() ) );