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_common.h>
36 #include <vlc_intf_strings.h>
38 #include "main_interface.hpp"
40 #include "dialogs_provider.hpp"
41 #include "input_manager.hpp"
46 #include <QActionGroup>
47 #include <QSignalMapper>
48 #include <QSystemTrayIcon>
51 This file defines the main menus and the pop-up menu (right-click menu)
52 and the systray menu (in that order in the file)
54 There are 3 menus that have to be rebuilt everytime there are called:
55 Audio, Video, Navigation
56 3 functions are building those menus: AudioMenu, VideoMenu, NavigMenu
57 and 3 functions associated are collecting the objects :
58 InputAutoMenuBuilder, AudioAutoMenuBuilder, VideoAutoMenuBuilder.
60 A QSignalMapper decides when to rebuild those menus cf MenuFunc in the .hpp
61 Just before one of those menus are aboutToShow(), they are rebuild.
73 static QActionGroup
*currentGroup
;
75 // Add static entries to menus
76 void addDPStaticEntry( QMenu
*menu
,
81 const char *shortcut
= NULL
)
83 QAction
*action
= NULL
;
84 if( !EMPTY_STR( icon
) > 0 )
86 if( !EMPTY_STR( shortcut
) > 0 )
87 action
= menu
->addAction( QIcon( icon
), text
, THEDP
,
88 member
, qtr( shortcut
) );
90 action
= menu
->addAction( QIcon( icon
), text
, THEDP
, member
);
94 if( !EMPTY_STR( shortcut
) > 0 )
95 action
= menu
->addAction( text
, THEDP
, member
, qtr( shortcut
) );
97 action
= menu
->addAction( text
, THEDP
, member
);
99 action
->setData( "_static_" );
102 void addMIMStaticEntry( intf_thread_t
*p_intf
,
109 if( strlen( icon
) > 0 )
111 QAction
*action
= menu
->addAction( text
, THEMIM
, member
);
112 action
->setIcon( QIcon( icon
) );
116 menu
->addAction( text
, THEMIM
, member
);
120 void EnableDPStaticEntries( QMenu
*menu
, bool enable
= true )
126 foreach( action
, menu
->actions() )
128 if( action
->data().toString() == "_static_" )
129 action
->setEnabled( enable
);
134 * \return Number of static entries
136 int DeleteNonStaticEntries( QMenu
*menu
)
142 foreach( action
, menu
->actions() )
144 if( action
->data().toString() != "_static_" )
151 /*****************************************************************************
152 * Definitions of variables for the dynamic menus
153 *****************************************************************************/
154 #define PUSH_VAR( var ) varnames.push_back( var ); \
155 objects.push_back( p_object ? p_object->i_object_id : 0 )
157 #define PUSH_INPUTVAR( var ) varnames.push_back( var ); \
158 objects.push_back( p_input ? p_input->i_object_id : 0 );
160 #define PUSH_SEPARATOR if( objects.size() != i_last_separator ) { \
161 objects.push_back( 0 ); varnames.push_back( "" ); \
162 i_last_separator = objects.size(); }
164 static int InputAutoMenuBuilder( vlc_object_t
*p_object
,
165 vector
<int> &objects
,
166 vector
<const char *> &varnames
)
168 PUSH_VAR( "bookmark" );
170 PUSH_VAR( "chapter" );
171 PUSH_VAR( "program" );
172 PUSH_VAR( "navigation" );
173 PUSH_VAR( "dvd_menus" );
177 static int VideoAutoMenuBuilder( vlc_object_t
*p_object
,
178 input_thread_t
*p_input
,
179 vector
<int> &objects
,
180 vector
<const char *> &varnames
)
182 PUSH_INPUTVAR( "video-es" );
183 PUSH_INPUTVAR( "spu-es" );
184 PUSH_VAR( "fullscreen" );
186 PUSH_VAR( "deinterlace" );
187 PUSH_VAR( "aspect-ratio" );
189 PUSH_VAR( "video-on-top" );
190 PUSH_VAR( "directx-wallpaper" );
191 PUSH_VAR( "video-snapshot" );
195 vlc_object_t
*p_dec_obj
= ( vlc_object_t
* )vlc_object_find( p_object
,
200 vlc_object_t
*p_object
= p_dec_obj
;
201 PUSH_VAR( "ffmpeg-pp-q" );
202 vlc_object_release( p_dec_obj
);
208 static int AudioAutoMenuBuilder( vlc_object_t
*p_object
,
209 input_thread_t
*p_input
,
210 vector
<int> &objects
,
211 vector
<const char *> &varnames
)
213 PUSH_INPUTVAR( "audio-es" );
214 PUSH_VAR( "audio-device" );
215 PUSH_VAR( "audio-channels" );
216 PUSH_VAR( "equalizer" );
217 PUSH_VAR( "visual" );
221 static QAction
* FindActionWithVar( QMenu
*menu
, const char *psz_var
)
224 foreach( action
, menu
->actions() )
226 if( action
->data().toString() == psz_var
)
232 static QAction
* FindActionWithText( QMenu
*menu
, QString
&text
)
235 foreach( action
, menu
->actions() )
237 if( action
->text() == text
)
243 /*****************************************************************************
246 *****************************************************************************/
248 #define BAR_ADD( func, title ) { \
249 QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); }
251 #define BAR_DADD( func, title, id ) { \
252 QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); \
253 MenuFunc *f = new MenuFunc( _menu, id ); \
254 CONNECT( _menu, aboutToShow(), THEDP->menusUpdateMapper, map() ); \
255 THEDP->menusUpdateMapper->setMapping( _menu, f ); }
257 #define ACT_ADD( _menu, val, title ) { \
258 QAction *_action = new QAction( title, _menu ); _action->setData( val ); \
259 _menu->addAction( _action ); }
262 * Main Menu Bar Creation
264 void QVLCMenu::createMenuBar( MainInterface
*mi
,
265 intf_thread_t
*p_intf
,
266 bool visual_selector_enabled
)
268 /* QMainWindows->menuBar()
269 gives the QProcess::destroyed timeout issue on Cleanlooks style with
270 setDesktopAware set to false */
271 QMenuBar
*bar
= mi
->menuBar();
272 BAR_ADD( FileMenu(), qtr( "&Media" ) );
273 BAR_ADD( PlaylistMenu( p_intf
, mi
), qtr( "&Playlist" ) );
274 BAR_ADD( ToolsMenu( p_intf
, NULL
, mi
, visual_selector_enabled
, true ),
276 BAR_DADD( AudioMenu( p_intf
, NULL
), qtr( "&Audio" ), 1 );
277 BAR_DADD( VideoMenu( p_intf
, NULL
), qtr( "&Video" ), 2 );
278 BAR_DADD( NavigMenu( p_intf
, NULL
), qtr( "&Playback" ), 3 );
279 BAR_ADD( HelpMenu( NULL
), qtr( "&Help" ) );
285 * Media ( File ) Menu
286 * Opening, streaming and quit
288 QMenu
*QVLCMenu::FileMenu()
290 QMenu
*menu
= new QMenu();
292 addDPStaticEntry( menu
, qtr( "&Open File..." ), "",
293 ":/pixmaps/file-asym_16px.png", SLOT( openFileDialog() ), "Ctrl+O" );
294 addDPStaticEntry( menu
, qtr( I_OPEN_FOLDER
), "",
295 ":/pixmaps/folder-grey_16px.png", SLOT( PLAppendDir() ), "Ctrl+F" );
296 addDPStaticEntry( menu
, qtr( "Open &Disc..." ), "",
297 ":/pixmaps/disc_16px.png", SLOT( openDiscDialog() ), "Ctrl+D" );
298 addDPStaticEntry( menu
, qtr( "Open &Network..." ), "",
299 ":/pixmaps/network_16px.png", SLOT( openNetDialog() ), "Ctrl+N" );
300 addDPStaticEntry( menu
, qtr( "Open &Capture Device..." ), "",
301 ":/pixmaps/capture-card_16px.png", SLOT( openCaptureDialog() ),
303 menu
->addSeparator();
305 addDPStaticEntry( menu
, qtr( "&Streaming..." ), "",
306 ":/pixmaps/menus_stream_16px.png", SLOT( openThenStreamingDialogs() ),
308 addDPStaticEntry( menu
, qtr( "Conve&rt / Save..." ), "", "",
309 SLOT( openThenTranscodingDialogs() ), "Ctrl+R" );
310 menu
->addSeparator();
312 addDPStaticEntry( menu
, qtr( "&Quit" ) , "",
313 ":/pixmaps/menus_quit_16px.png", SLOT( quit() ), "Ctrl+Q" );
317 /* Playlist/MediaLibrary Control */
318 QMenu
*QVLCMenu::PlaylistMenu( intf_thread_t
*p_intf
, MainInterface
*mi
)
320 QMenu
*menu
= new QMenu();
321 menu
->addMenu( SDMenu( p_intf
) );
322 menu
->addAction( QIcon( ":/pixmaps/playlist_16px.png" ),
323 qtr( "Show Playlist" ), mi
, SLOT( togglePlaylist() ) );
324 menu
->addSeparator();
326 addDPStaticEntry( menu
, qtr( I_PL_LOAD
), "", "", SLOT( openAPlaylist() ),
328 addDPStaticEntry( menu
, qtr( I_PL_SAVE
), "", "", SLOT( saveAPlaylist() ),
330 menu
->addSeparator();
331 menu
->addAction( qtr( "Undock from interface" ), mi
,
332 SLOT( undockPlaylist() ), qtr( "Ctrl+U" ) );
338 * This is kept in the same menu for now, but could change if it gets much
340 * This menu can be an interface menu but also a right click menu.
342 QMenu
*QVLCMenu::ToolsMenu( intf_thread_t
*p_intf
,
345 bool visual_selector_enabled
,
348 QMenu
*menu
= new QMenu( current
);
351 menu
->addAction( QIcon( ":/pixmaps/playlist_16px.png" ),
352 qtr( "Playlist..." ), mi
, SLOT( togglePlaylist() ),
355 addDPStaticEntry( menu
, qtr( I_MENU_EXT
), "",
356 ":/pixmaps/menus_settings_16px.png", SLOT( extendedDialog() ),
359 menu
->addSeparator();
363 QMenu
*intfmenu
= InterfacesMenu( p_intf
, menu
);
364 intfmenu
->setTitle( qtr( "Add Interfaces" ) );
365 MenuFunc
*f
= new MenuFunc( intfmenu
, 4 );
366 CONNECT( intfmenu
, aboutToShow(), THEDP
->menusUpdateMapper
, map() );
367 THEDP
->menusUpdateMapper
->setMapping( intfmenu
, f
);
368 menu
->addMenu( intfmenu
);
369 menu
->addSeparator();
374 QAction
*action
= menu
->addAction( qtr( "Minimal View..." ), mi
,
375 SLOT( toggleMinimalView() ), qtr( "Ctrl+H" ) );
376 action
->setCheckable( true );
377 if( mi
->getControlsVisibilityStatus() & CONTROLS_VISIBLE
)
378 action
->setChecked( true );
380 /* FullScreen View */
381 action
= menu
->addAction( qtr( "Toggle Fullscreen Interface" ), mi
,
382 SLOT( toggleFullScreen() ), QString( "F11" ) );
384 /* Advanced Controls */
385 action
= menu
->addAction( qtr( "Advanced controls" ), mi
,
386 SLOT( toggleAdvanced() ) );
387 action
->setCheckable( true );
388 if( mi
->getControlsVisibilityStatus() & CONTROLS_ADVANCED
)
389 action
->setChecked( true );
390 #if 0 /* For Visualisations. Not yet working */
391 adv
= menu
->addAction( qtr( "Visualizations selector" ),
392 mi
, SLOT( visual() ) );
393 adv
->setCheckable( true );
394 if( visual_selector_enabled
) adv
->setChecked( true );
398 menu
->addSeparator();
400 addDPStaticEntry( menu
, qtr( I_MENU_MSG
), "",
401 ":/pixmaps/menus_messages_16px.png", SLOT( messagesDialog() ),
403 addDPStaticEntry( menu
, qtr( I_MENU_INFO
) , "", "",
404 SLOT( mediaInfoDialog() ), "Ctrl+I" );
405 addDPStaticEntry( menu
, qtr( I_MENU_CODECINFO
) , "",
406 ":/pixmaps/menus_info_16px.png", SLOT( mediaCodecDialog() ), "Ctrl+J" );
407 addDPStaticEntry( menu
, qtr( I_MENU_BOOKMARK
), "","",
408 SLOT( bookmarksDialog() ), "Ctrl+B" );
410 addDPStaticEntry( menu
, qtr( I_MENU_VLM
), "", "", SLOT( vlmDialog() ),
414 menu
->addSeparator();
415 addDPStaticEntry( menu
, qtr( "Preferences..." ), "",
416 ":/pixmaps/menus_preferences_16px.png", SLOT( prefsDialog() ), "Ctrl+P" );
421 * Interface Sub-Menu, to list extras interface and skins
423 QMenu
*QVLCMenu::InterfacesMenu( intf_thread_t
*p_intf
, QMenu
*current
)
426 vector
<const char *> varnames
;
427 /** \todo add "switch to XXX" */
428 varnames
.push_back( "intf-add" );
429 objects
.push_back( p_intf
->i_object_id
);
431 QMenu
*submenu
= new QMenu( current
);
432 QMenu
*menu
= Populate( p_intf
, submenu
, varnames
, objects
);
440 QMenu
*QVLCMenu::AudioMenu( intf_thread_t
*p_intf
, QMenu
* current
)
443 vector
<const char *> varnames
;
444 vlc_object_t
*p_aout
;
445 input_thread_t
*p_input
;
447 if( !current
) current
= new QMenu();
449 if( current
->isEmpty() )
451 ACT_ADD( current
, "audio-es", qtr( "Audio &Track" ) );
452 ACT_ADD( current
, "audio-device", qtr( "Audio &Device" ) );
453 ACT_ADD( current
, "audio-channels", qtr( "Audio &Channels" ) );
454 ACT_ADD( current
, "equalizer", qtr( "&Equalizer" ) );
455 current
->addSeparator();
456 ACT_ADD( current
, "visual", qtr( "&Visualizations" ) );
459 p_input
= THEMIM
->getInput();
461 vlc_object_yield( p_input
);
462 p_aout
= ( vlc_object_t
* ) vlc_object_find( p_intf
,
466 AudioAutoMenuBuilder( p_aout
, p_input
, objects
, varnames
);
469 vlc_object_release( p_aout
);
471 vlc_object_release( p_input
);
473 return Populate( p_intf
, current
, varnames
, objects
);
478 * Subtitles are part of Video.
480 QMenu
*QVLCMenu::VideoMenu( intf_thread_t
*p_intf
, QMenu
*current
)
482 vlc_object_t
*p_vout
;
483 input_thread_t
*p_input
;
485 vector
<const char *> varnames
;
487 if( !current
) current
= new QMenu();
489 if( current
->isEmpty() )
491 ACT_ADD( current
, "video-es", qtr( "Video &Track" ) );
494 QMenu
*submenu
= new QMenu( qtr( "&Subtitles Track" ), current
);
495 action
= current
->addMenu( submenu
);
496 action
->setData( "spu-es" );
497 addDPStaticEntry( submenu
, qtr( "Load File..." ), "", "",
498 SLOT( loadSubtitlesFile() ) );
499 submenu
->addSeparator();
501 ACT_ADD( current
, "fullscreen", qtr( "Toggle &Fullscreen" ) );
502 ACT_ADD( current
, "zoom", qtr( "&Zoom" ) );
503 ACT_ADD( current
, "deinterlace", qtr( "&Deinterlace" ) );
504 ACT_ADD( current
, "aspect-ratio", qtr( "&Aspect Ratio" ) );
505 ACT_ADD( current
, "crop", qtr( "&Crop" ) );
506 ACT_ADD( current
, "video-on-top", qtr( "Always &On Top" ) );
507 /* ACT_ADD( current, "directx-wallpaper", qtr( "DirectX Wallpaper" ) ); */
508 ACT_ADD( current
, "video-snapshot", qtr( "Snapshot" ) );
509 /* ACT_ADD( current, "ffmpeg-pp-q", qtr( "Decoder" ) ); */
512 p_input
= THEMIM
->getInput();
514 vlc_object_yield( p_input
);
515 p_vout
= ( vlc_object_t
* )vlc_object_find( p_intf
, VLC_OBJECT_VOUT
,
518 VideoAutoMenuBuilder( p_vout
, p_input
, objects
, varnames
);
521 vlc_object_release( p_vout
);
523 vlc_object_release( p_input
);
525 return Populate( p_intf
, current
, varnames
, objects
);
530 * For DVD, MP4, MOV and other chapter based format
532 QMenu
*QVLCMenu::NavigMenu( intf_thread_t
*p_intf
, QMenu
*menu
)
534 vlc_object_t
*p_object
;
536 vector
<const char *> varnames
;
538 if( !menu
) menu
= new QMenu();
540 if( menu
->isEmpty() )
542 addDPStaticEntry( menu
, qtr( I_MENU_GOTOTIME
), "","",
543 SLOT( gotoTimeDialog() ), "Ctrl+T" );
544 menu
->addSeparator();
546 ACT_ADD( menu
, "bookmark", qtr( "&Bookmarks" ) );
547 ACT_ADD( menu
, "title", qtr( "&Title" ) );
548 ACT_ADD( menu
, "chapter", qtr( "&Chapter" ) );
549 ACT_ADD( menu
, "program", qtr( "&Program" ) );
550 ACT_ADD( menu
, "navigation", qtr( "&Navigation" ) );
553 p_object
= ( vlc_object_t
* )vlc_object_find( p_intf
, VLC_OBJECT_INPUT
,
555 InputAutoMenuBuilder( p_object
, objects
, varnames
);
556 PUSH_VAR( "prev-title" );
557 PUSH_VAR( "next-title" );
558 PUSH_VAR( "prev-chapter" );
559 PUSH_VAR( "next-chapter" );
560 EnableDPStaticEntries( menu
, ( p_object
!= NULL
) );
563 vlc_object_release( p_object
);
565 return Populate( p_intf
, menu
, varnames
, objects
, true );
569 * Service Discovery SubMenu
571 QMenu
*QVLCMenu::SDMenu( intf_thread_t
*p_intf
)
573 QMenu
*menu
= new QMenu();
574 menu
->setTitle( qtr( I_PL_SD
) );
575 char **ppsz_longnames
;
576 char **ppsz_names
= services_discovery_GetServicesNames( p_intf
,
581 char **ppsz_name
= ppsz_names
, **ppsz_longname
= ppsz_longnames
;
582 for( ; *ppsz_name
; ppsz_name
++, ppsz_longname
++ )
584 QAction
*a
= new QAction( qfu( *ppsz_longname
), menu
);
585 a
->setCheckable( true );
586 if( playlist_IsServicesDiscoveryLoaded( THEPL
, *ppsz_name
) )
587 a
->setChecked( true );
588 CONNECT( a
, triggered(), THEDP
->SDMapper
, map() );
589 THEDP
->SDMapper
->setMapping( a
, QString( *ppsz_name
) );
590 menu
->addAction( a
);
592 if( !strcmp( *ppsz_name
, "podcast" ) )
594 QAction
*b
= new QAction( qfu( "Configure podcasts..." ), menu
);
595 //b->setEnabled( a->isChecked() );
596 menu
->addAction( b
);
597 CONNECT( b
, triggered(), THEDP
, podcastConfigureDialog() );
600 free( *ppsz_longname
);
603 free( ppsz_longnames
);
609 QMenu
*QVLCMenu::HelpMenu( QMenu
*current
)
611 QMenu
*menu
= new QMenu( current
);
612 addDPStaticEntry( menu
, qtr( "Help..." ) , "",
613 ":/pixmaps/menus_help_16px.png", SLOT( helpDialog() ), "F1" );
615 addDPStaticEntry( menu
, qtr( "Check for updates..." ) , "", "",
616 SLOT( updateDialog() ), "");
618 menu
->addSeparator();
619 addDPStaticEntry( menu
, qtr( I_MENU_ABOUT
), "", "", SLOT( aboutDialog() ),
624 /*****************************************************************************
625 * Popup menus - Right Click menus *
626 *****************************************************************************/
627 #define POPUP_BOILERPLATE \
628 unsigned int i_last_separator = 0; \
629 vector<int> objects; \
630 vector<const char *> varnames; \
631 input_thread_t *p_input = THEMIM->getInput();
633 #define CREATE_POPUP \
634 Populate( p_intf, menu, varnames, objects ); \
635 p_intf->p_sys->p_popup_menu = menu; \
636 menu->popup( QCursor::pos() ); \
637 p_intf->p_sys->p_popup_menu = NULL; \
638 i_last_separator = 0;
640 void QVLCMenu::PopupMenuControlEntries( QMenu
*menu
,
641 intf_thread_t
*p_intf
,
642 input_thread_t
*p_input
)
647 var_Get( p_input
, "state", &val
);
648 if( val
.i_int
== PLAYING_S
)
649 addMIMStaticEntry( p_intf
, menu
, qtr( "Pause" ), "",
650 ":/pixmaps/pause_16px.png", SLOT( togglePlayPause() ) );
652 addMIMStaticEntry( p_intf
, menu
, qtr( "Play" ), "",
653 ":/pixmaps/play_16px.png", SLOT( togglePlayPause() ) );
655 else if( THEPL
->items
.i_size
)
656 addMIMStaticEntry( p_intf
, menu
, qtr( "Play" ), "",
657 ":/pixmaps/play_16px.png", SLOT( togglePlayPause() ) );
659 addDPStaticEntry( menu
, qtr( "Play" ), "",
660 ":/pixmaps/play_16px.png", SLOT( openDialog() ) );
662 addMIMStaticEntry( p_intf
, menu
, qtr( "Stop" ), "",
663 ":/pixmaps/stop_16px.png", SLOT( stop() ) );
664 addMIMStaticEntry( p_intf
, menu
, qtr( "Previous" ), "",
665 ":/pixmaps/previous_16px.png", SLOT( prev() ) );
666 addMIMStaticEntry( p_intf
, menu
, qtr( "Next" ), "",
667 ":/pixmaps/next_16px.png", SLOT( next() ) );
670 void QVLCMenu::PopupMenuStaticEntries( intf_thread_t
*p_intf
, QMenu
*menu
)
673 QMenu
*toolsmenu
= ToolsMenu( p_intf
, menu
, false, true );
674 toolsmenu
->setTitle( qtr( "Tools" ) );
675 menu
->addMenu( toolsmenu
);
678 QMenu
*openmenu
= new QMenu( qtr( "Open" ), menu
);
679 addDPStaticEntry( openmenu
, qtr( "&Open File..." ), "",
680 ":/pixmaps/file-asym_16px.png", SLOT( openFileDialog() ) );
681 addDPStaticEntry( openmenu
, qtr( I_OPEN_FOLDER
), "",
682 ":/pixmaps/folder-grey_16px.png", SLOT( PLAppendDir() ) );
683 addDPStaticEntry( openmenu
, qtr( "Open &Disc..." ), "",
684 ":/pixmaps/disc_16px.png", SLOT( openDiscDialog() ) );
685 addDPStaticEntry( openmenu
, qtr( "Open &Network..." ), "",
686 ":/pixmaps/network_16px.png", SLOT( openNetDialog() ) );
687 addDPStaticEntry( openmenu
, qtr( "Open &Capture Device..." ), "",
688 ":/pixmaps/capture-card_16px.png", SLOT( openCaptureDialog() ) );
689 menu
->addMenu( openmenu
);
691 menu
->addSeparator();
693 QMenu
*helpmenu
= HelpMenu( menu
);
694 helpmenu
->setTitle( qtr( "Help" ) );
695 menu
->addMenu( helpmenu
);
698 addDPStaticEntry( menu
, qtr( "Quit" ), "", ":/pixmaps/menus_quit_16px.png",
699 SLOT( quit() ), "Ctrl+Q" );
702 /* Video Tracks and Subtitles tracks */
703 void QVLCMenu::VideoPopupMenu( intf_thread_t
*p_intf
)
708 vlc_object_yield( p_input
);
709 vlc_object_t
*p_vout
= ( vlc_object_t
* )vlc_object_find( p_input
,
710 VLC_OBJECT_VOUT
, FIND_CHILD
);
713 VideoAutoMenuBuilder( p_vout
, p_input
, objects
, varnames
);
714 vlc_object_release( p_vout
);
716 vlc_object_release( p_input
);
718 QMenu
*menu
= new QMenu();
723 void QVLCMenu::AudioPopupMenu( intf_thread_t
*p_intf
)
728 vlc_object_yield( p_input
);
729 vlc_object_t
*p_aout
= ( vlc_object_t
* )vlc_object_find( p_input
,
730 VLC_OBJECT_AOUT
, FIND_ANYWHERE
);
731 AudioAutoMenuBuilder( p_aout
, p_input
, objects
, varnames
);
733 vlc_object_release( p_aout
);
734 vlc_object_release( p_input
);
736 QMenu
*menu
= new QMenu();
740 /* Navigation stuff, and general menus ( open ) */
741 void QVLCMenu::MiscPopupMenu( intf_thread_t
*p_intf
)
748 vlc_object_yield( p_input
);
749 varnames
.push_back( "audio-es" );
750 InputAutoMenuBuilder( VLC_OBJECT( p_input
), objects
, varnames
);
754 QMenu
*menu
= new QMenu();
755 Populate( p_intf
, menu
, varnames
, objects
);
757 menu
->addSeparator();
758 PopupMenuControlEntries( menu
, p_intf
, p_input
);
760 menu
->addSeparator();
761 PopupMenuStaticEntries( p_intf
, menu
);
763 p_intf
->p_sys
->p_popup_menu
= menu
;
764 menu
->popup( QCursor::pos() );
765 p_intf
->p_sys
->p_popup_menu
= NULL
;
768 /* Main Menu that sticks everything together */
769 void QVLCMenu::PopupMenu( intf_thread_t
*p_intf
, bool show
)
771 MainInterface
*mi
= p_intf
->p_sys
->p_mi
;
774 /* Delete and recreate a popup if there is one */
775 if( p_intf
->p_sys
->p_popup_menu
)
776 delete p_intf
->p_sys
->p_popup_menu
;
778 QMenu
*menu
= new QMenu();
781 bool b_isFullscreen
= false;
785 PopupMenuControlEntries( menu
, p_intf
, p_input
);
786 menu
->addSeparator();
790 vlc_object_t
*p_vout
= (vlc_object_t
*)
791 vlc_object_find( p_input
, VLC_OBJECT_VOUT
, FIND_CHILD
);
793 /* Add a fullscreen switch button */
797 var_Get( p_vout
, "fullscreen", &val
);
798 b_isFullscreen
= !( !val
.b_bool
);
800 CreateAndConnect( menu
, "fullscreen",
801 qtr( "Leave Fullscreen" ),"" , ITEM_NORMAL
,
802 p_vout
->i_object_id
, val
, VLC_VAR_BOOL
,
806 vlc_object_release( p_vout
);
807 menu
->addSeparator();
809 vlc_object_yield( p_input
);
810 InputAutoMenuBuilder( VLC_OBJECT( p_input
), objects
, varnames
);
811 vlc_object_release( p_input
);
813 submenu
= new QMenu( menu
);
814 action
= menu
->addMenu( AudioMenu( p_intf
, submenu
) );
815 action
->setText( qtr( "&Audio" ) );
816 if( action
->menu()->isEmpty() )
817 action
->setEnabled( false );
819 submenu
= new QMenu( menu
);
820 action
= menu
->addMenu( VideoMenu( p_intf
, submenu
) );
821 action
->setText( qtr( "&Video" ) );
822 if( action
->menu()->isEmpty() )
823 action
->setEnabled( false );
825 submenu
= new QMenu( menu
);
826 action
= menu
->addMenu( NavigMenu( p_intf
, submenu
) );
827 action
->setText( qtr( "&Playback" ) );
828 if( action
->menu()->isEmpty() )
829 action
->setEnabled( false );
832 menu
->addSeparator();
834 /* Add some special entries for windowed mode: Interface Menu */
835 if( !b_isFullscreen
)
837 submenu
= new QMenu( qtr( "Interface" ), menu
);
838 submenu
->addAction( QIcon( ":/pixmaps/playlist_16px.png" ),
839 qtr( "Show Playlist" ), mi
, SLOT( togglePlaylist() ) );
840 addDPStaticEntry( submenu
, qtr( I_MENU_EXT
), "",
841 ":/pixmaps/menus_settings_16px.png", SLOT( extendedDialog() ) );
842 action
= submenu
->addAction( QIcon( "" ),
843 qtr( "Minimal View..." ), mi
, SLOT( toggleMinimalView() ) );
844 action
->setCheckable( true );
845 action
->setChecked( !( mi
->getControlsVisibilityStatus() &
846 CONTROLS_VISIBLE
) );
847 action
= submenu
->addAction( QIcon( "" ),
848 qtr( "Toggle Fullscreen Interface" ),
849 mi
, SLOT( toggleFullScreen() ) );
850 action
->setCheckable( true );
851 action
->setChecked( mi
->isFullScreen() );
852 menu
->addMenu( submenu
);
855 PopupMenuStaticEntries( p_intf
, menu
);
857 p_intf
->p_sys
->p_popup_menu
= menu
;
858 p_intf
->p_sys
->p_popup_menu
->popup( QCursor::pos() );
862 // destroy popup if there is one
863 delete p_intf
->p_sys
->p_popup_menu
;
864 p_intf
->p_sys
->p_popup_menu
= NULL
;
870 /************************************************************************
872 ************************************************************************/
874 void QVLCMenu::updateSystrayMenu( MainInterface
*mi
,
875 intf_thread_t
*p_intf
,
876 bool b_force_visible
)
880 /* Get the systray menu and clean it */
881 QMenu
*sysMenu
= mi
->getSysTrayMenu();
884 /* Hide / Show VLC and cone */
885 if( mi
->isVisible() || b_force_visible
)
887 sysMenu
->addAction( QIcon( ":/vlc16.png" ),
888 qtr( "Hide VLC media player in taskbar" ), mi
,
889 SLOT( toggleUpdateSystrayMenu() ) );
893 sysMenu
->addAction( QIcon( ":/vlc16.png" ),
894 qtr( "Show VLC media player" ), mi
,
895 SLOT( toggleUpdateSystrayMenu() ) );
898 sysMenu
->addSeparator();
899 PopupMenuControlEntries( sysMenu
, p_intf
, p_input
);
901 sysMenu
->addSeparator();
902 addDPStaticEntry( sysMenu
, qtr( "&Open Media" ), "",
903 ":/pixmaps/file-wide_16px.png", SLOT( openFileDialog() ), "" );
904 addDPStaticEntry( sysMenu
, qtr( "&Quit" ) , "",
905 ":/pixmaps/menus_quit_16px.png", SLOT( quit() ), "" );
908 mi
->getSysTray()->setContextMenu( sysMenu
);
912 #undef PUSH_SEPARATOR
914 /*************************************************************************
915 * Builders for automenus
916 *************************************************************************/
917 QMenu
* QVLCMenu::Populate( intf_thread_t
*p_intf
,
919 vector
< const char *> & varnames
,
920 vector
<int> & objects
,
923 QMenu
*menu
= current
;
924 if( !menu
) menu
= new QMenu();
926 /* Disable all non static entries */
928 foreach( p_action
, menu
->actions() )
930 if( p_action
->data().toString() != "_static_" )
931 p_action
->setEnabled( false );
936 vlc_object_t
*p_object
;
939 for( i
= 0; i
< ( int )objects
.size() ; i
++ )
941 if( !varnames
[i
] || !*varnames
[i
] )
943 menu
->addSeparator();
947 if( objects
[i
] == 0 )
953 p_object
= ( vlc_object_t
* )vlc_object_get( objects
[i
] );
956 msg_Dbg( p_intf
, "object %d not found !", objects
[i
] );
961 /* Ugly specific stuff */
962 if( strstr( varnames
[i
], "intf-add" ) )
963 UpdateItem( p_intf
, menu
, varnames
[i
], p_object
, false );
965 UpdateItem( p_intf
, menu
, varnames
[i
], p_object
, true );
967 vlc_object_release( p_object
);
972 /*****************************************************************************
974 *****************************************************************************/
976 static bool IsMenuEmpty( const char *psz_var
,
977 vlc_object_t
*p_object
,
980 vlc_value_t val
, val_list
;
981 int i_type
, i_result
, i
;
983 /* Check the type of the object variable */
984 i_type
= var_Type( p_object
, psz_var
);
986 /* Check if we want to display the variable */
987 if( !( i_type
& VLC_VAR_HASCHOICE
) ) return false;
989 var_Change( p_object
, psz_var
, VLC_VAR_CHOICESCOUNT
, &val
, NULL
);
990 if( val
.i_int
== 0 ) return true;
992 if( ( i_type
& VLC_VAR_TYPE
) != VLC_VAR_VARIABLE
)
994 if( val
.i_int
== 1 && b_root
) return true;
998 /* Check children variables in case of VLC_VAR_VARIABLE */
999 if( var_Change( p_object
, psz_var
, VLC_VAR_GETLIST
, &val_list
, NULL
) < 0 )
1004 for( i
= 0, i_result
= true; i
< val_list
.p_list
->i_count
; i
++ )
1006 if( !IsMenuEmpty( val_list
.p_list
->p_values
[i
].psz_string
,
1014 /* clean up everything */
1015 var_Change( p_object
, psz_var
, VLC_VAR_FREELIST
, &val_list
, NULL
);
1020 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
1022 void QVLCMenu::UpdateItem( intf_thread_t
*p_intf
, QMenu
*menu
,
1023 const char *psz_var
, vlc_object_t
*p_object
, bool b_submenu
)
1025 vlc_value_t val
, text
;
1028 QAction
*action
= FindActionWithVar( menu
, psz_var
);
1030 DeleteNonStaticEntries( action
->menu() );
1035 /* Check the type of the object variable */
1036 if( !strcmp( psz_var
, "audio-es" )
1037 || !strcmp( psz_var
, "video-es" ) )
1038 i_type
= VLC_VAR_INTEGER
| VLC_VAR_HASCHOICE
;
1040 i_type
= var_Type( p_object
, psz_var
);
1042 switch( i_type
& VLC_VAR_TYPE
)
1046 case VLC_VAR_VARIABLE
:
1047 case VLC_VAR_STRING
:
1048 case VLC_VAR_INTEGER
:
1052 /* Variable doesn't exist or isn't handled */
1056 /* Make sure we want to display the variable */
1057 if( menu
->isEmpty() && IsMenuEmpty( psz_var
, p_object
) )
1060 /* Get the descriptive name of the variable */
1061 int i_ret
= var_Change( p_object
, psz_var
, VLC_VAR_GETTEXT
, &text
, NULL
);
1062 if( i_ret
!= VLC_SUCCESS
)
1064 text
.psz_string
= NULL
;
1069 action
= new QAction( TEXT_OR_VAR
, menu
);
1070 menu
->addAction( action
);
1071 action
->setData( psz_var
);
1074 /* Some specific stuff */
1075 bool forceDisabled
= false;
1076 if( !strcmp( psz_var
, "spu-es" ) )
1078 vlc_object_t
*p_vout
= ( vlc_object_t
* )( vlc_object_find( p_intf
,
1079 VLC_OBJECT_VOUT
, FIND_ANYWHERE
) );
1080 forceDisabled
= ( p_vout
== NULL
);
1082 vlc_object_release( p_vout
);
1085 if( i_type
& VLC_VAR_HASCHOICE
)
1087 /* Append choices menu */
1091 submenu
= action
->menu();
1094 submenu
= new QMenu( menu
);
1095 action
->setMenu( submenu
);
1099 CreateChoicesMenu( submenu
, psz_var
, p_object
, true ) == 0 );
1101 action
->setEnabled( false );
1104 CreateChoicesMenu( menu
, psz_var
, p_object
, true );
1105 FREENULL( text
.psz_string
);
1109 switch( i_type
& VLC_VAR_TYPE
)
1112 var_Get( p_object
, psz_var
, &val
);
1113 CreateAndConnect( menu
, psz_var
, TEXT_OR_VAR
, "", ITEM_NORMAL
,
1114 p_object
->i_object_id
, val
, i_type
);
1118 var_Get( p_object
, psz_var
, &val
);
1119 val
.b_bool
= !val
.b_bool
;
1120 CreateAndConnect( menu
, psz_var
, TEXT_OR_VAR
, "", ITEM_CHECK
,
1121 p_object
->i_object_id
, val
, i_type
, !val
.b_bool
);
1124 FREENULL( text
.psz_string
);
1128 int QVLCMenu::CreateChoicesMenu( QMenu
*submenu
, const char *psz_var
,
1129 vlc_object_t
*p_object
, bool b_root
)
1131 vlc_value_t val
, val_list
, text_list
;
1134 /* Check the type of the object variable */
1135 i_type
= var_Type( p_object
, psz_var
);
1137 /* Make sure we want to display the variable */
1138 if( submenu
->isEmpty() && IsMenuEmpty( psz_var
, p_object
, b_root
) )
1139 return VLC_EGENERIC
;
1141 switch( i_type
& VLC_VAR_TYPE
)
1145 case VLC_VAR_VARIABLE
:
1146 case VLC_VAR_STRING
:
1147 case VLC_VAR_INTEGER
:
1151 /* Variable doesn't exist or isn't handled */
1152 return VLC_EGENERIC
;
1155 if( var_Change( p_object
, psz_var
, VLC_VAR_GETLIST
,
1156 &val_list
, &text_list
) < 0 )
1158 return VLC_EGENERIC
;
1161 #define NORMAL_OR_RADIO i_type & VLC_VAR_ISCOMMAND ? ITEM_NORMAL: ITEM_RADIO
1162 #define NOTCOMMAND !( i_type & VLC_VAR_ISCOMMAND )
1163 #define CURVAL val_list.p_list->p_values[i]
1164 #define CURTEXT text_list.p_list->p_values[i].psz_string
1166 for( i
= 0; i
< val_list
.p_list
->i_count
; i
++ )
1168 vlc_value_t another_val
;
1170 QMenu
*subsubmenu
= new QMenu( submenu
);
1172 switch( i_type
& VLC_VAR_TYPE
)
1174 case VLC_VAR_VARIABLE
:
1175 CreateChoicesMenu( subsubmenu
, CURVAL
.psz_string
, p_object
, false );
1176 subsubmenu
->setTitle( qfu( CURTEXT
? CURTEXT
:CURVAL
.psz_string
) );
1177 submenu
->addMenu( subsubmenu
);
1180 case VLC_VAR_STRING
:
1181 var_Get( p_object
, psz_var
, &val
);
1182 another_val
.psz_string
= strdup( CURVAL
.psz_string
);
1183 menutext
= qfu( CURTEXT
? CURTEXT
: another_val
.psz_string
);
1184 CreateAndConnect( submenu
, psz_var
, menutext
, "", NORMAL_OR_RADIO
,
1185 p_object
->i_object_id
, another_val
, i_type
,
1186 NOTCOMMAND
&& val
.psz_string
&&
1187 !strcmp( val
.psz_string
, CURVAL
.psz_string
) );
1189 free( val
.psz_string
);
1192 case VLC_VAR_INTEGER
:
1193 var_Get( p_object
, psz_var
, &val
);
1194 if( CURTEXT
) menutext
= qfu( CURTEXT
);
1195 else menutext
.sprintf( "%d", CURVAL
.i_int
);
1196 CreateAndConnect( submenu
, psz_var
, menutext
, "", NORMAL_OR_RADIO
,
1197 p_object
->i_object_id
, CURVAL
, i_type
,
1198 NOTCOMMAND
&& CURVAL
.i_int
== val
.i_int
);
1202 var_Get( p_object
, psz_var
, &val
);
1203 if( CURTEXT
) menutext
= qfu( CURTEXT
);
1204 else menutext
.sprintf( "%.2f", CURVAL
.f_float
);
1205 CreateAndConnect( submenu
, psz_var
, menutext
, "", NORMAL_OR_RADIO
,
1206 p_object
->i_object_id
, CURVAL
, i_type
,
1207 NOTCOMMAND
&& CURVAL
.f_float
== val
.f_float
);
1214 currentGroup
= NULL
;
1216 /* clean up everything */
1217 var_Change( p_object
, psz_var
, VLC_VAR_FREELIST
, &val_list
, &text_list
);
1219 #undef NORMAL_OR_RADIO
1226 void QVLCMenu::CreateAndConnect( QMenu
*menu
, const char *psz_var
,
1227 QString text
, QString help
,
1228 int i_item_type
, int i_object_id
,
1229 vlc_value_t val
, int i_val_type
,
1232 QAction
*action
= FindActionWithVar( menu
, psz_var
);
1235 /* This is a value */
1236 action
= FindActionWithText( menu
, text
);
1239 action
= new QAction( text
, menu
);
1240 menu
->addAction( action
);
1244 action
->setText( text
);
1245 action
->setToolTip( help
);
1247 action
->setEnabled( i_object_id
!= 0 );
1249 if( i_item_type
== ITEM_CHECK
)
1251 action
->setCheckable( true );
1253 else if( i_item_type
== ITEM_RADIO
)
1255 action
->setCheckable( true );
1257 currentGroup
= new QActionGroup( menu
);
1258 currentGroup
->addAction( action
);
1261 action
->setChecked( checked
);
1263 MenuItemData
*itemData
= new MenuItemData( i_object_id
, i_val_type
,
1265 CONNECT( action
, triggered(), THEDP
->menusMapper
, map() );
1266 THEDP
->menusMapper
->setMapping( action
, itemData
);
1267 menu
->addAction( action
);
1270 void QVLCMenu::DoAction( intf_thread_t
*p_intf
, QObject
*data
)
1272 MenuItemData
*itemData
= qobject_cast
<MenuItemData
*>( data
);
1273 vlc_object_t
*p_object
= ( vlc_object_t
* )vlc_object_get( itemData
->i_object_id
);
1274 if( p_object
== NULL
) return;
1276 var_Set( p_object
, itemData
->psz_var
, itemData
->val
);
1277 vlc_object_release( p_object
);