Qt: open and open advanced for everyone.
[vlc.git] / modules / gui / qt4 / menus.cpp
blobb9d0ea1898fec799d90873420cfc0582caab3655
1 /*****************************************************************************
2 * menus.cpp : Qt menus
3 *****************************************************************************
4 * Copyright © 2006-2008 the VideoLAN team
5 * $Id$
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 *****************************************************************************/
26 /** \todo
27 * - Remove static currentGroup
30 #ifdef HAVE_CONFIG_H
31 # include "config.h"
32 #endif
34 #include <vlc_intf_strings.h>
35 #include <vlc_services_discovery.h>
37 #include "menus.hpp"
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 */
44 #include <QMenu>
45 #include <QMenuBar>
46 #include <QAction>
47 #include <QActionGroup>
48 #include <QSignalMapper>
49 #include <QSystemTrayIcon>
50 #include <QList>
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.
66 enum
68 ITEM_NORMAL,
69 ITEM_CHECK,
70 ITEM_RADIO
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 /****************************************************************************
82 * Menu code helpers:
83 ****************************************************************************
84 * Add static entries to DP in menus
85 ***************************************************************************/
86 void addDPStaticEntry( QMenu *menu,
87 const QString text,
88 const char *icon,
89 const char *member,
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 ) );
98 else
99 action = menu->addAction( QIcon( icon ), text, THEDP, member );
101 else
103 if( !EMPTY_STR( shortcut ) > 0 )
104 action = menu->addAction( text, THEDP, member, qtr( shortcut ) );
105 else
106 action = menu->addAction( text, THEDP, member );
108 action->setData( "_static_" );
111 void EnableDPStaticEntries( QMenu *menu, bool enable = true )
113 if( !menu ) return;
115 QAction *action;
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 )
128 int i_ret = 0;
129 QAction *action;
130 if( !menu )
131 return VLC_EGENERIC;
132 foreach( action, menu->actions() )
134 if( action->data().toString() != "_static_" )
135 delete action;
136 else
137 i_ret++;
139 return i_ret;
142 /***
143 * Same for MIM
144 ***/
145 void addMIMStaticEntry( intf_thread_t *p_intf,
146 QMenu *menu,
147 const QString text,
148 const char *icon,
149 const char *member )
151 if( strlen( icon ) > 0 )
153 QAction *action = menu->addAction( text, THEMIM, member );
154 action->setIcon( QIcon( icon ) );
156 else
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" );
180 PUSH_VAR( "title" );
181 PUSH_VAR( "chapter" );
182 PUSH_VAR( "program" );
183 PUSH_VAR( "navigation" );
184 PUSH_VAR( "dvd_menus" );
185 return VLC_SUCCESS;
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" );
196 PUSH_VAR( "zoom" );
197 PUSH_VAR( "deinterlace" );
198 PUSH_VAR( "aspect-ratio" );
199 PUSH_VAR( "crop" );
200 PUSH_VAR( "video-on-top" );
201 #ifdef WIN32
202 PUSH_VAR( "directx-wallpaper" );
203 #endif
204 PUSH_VAR( "video-snapshot" );
206 /* Special case for postproc */
207 // FIXME
208 if( p_object )
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,
214 FIND_PARENT );
215 if( p_dec )
217 vlc_object_t *p_pp = (vlc_object_t *)
218 vlc_object_find_name( p_dec, "postproc",
219 FIND_CHILD );
220 if( p_pp )
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 );
230 return VLC_SUCCESS;
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" );
242 return VLC_SUCCESS;
245 static QAction * FindActionWithVar( QMenu *menu, const char *psz_var )
247 QAction *action;
248 foreach( action, menu->actions() )
250 if( action->data().toString() == psz_var )
251 return action;
253 return NULL;
256 /*****************************************************************************
257 * All normal menus
258 * Simple Code
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 ),
294 qtr( "V&iew" ) );
296 BAR_ADD( HelpMenu( NULL ), qtr( "&Help" ) );
298 #undef BAR_ADD
299 #undef BAR_DADD
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..." ),
310 ":/file-asym", SLOT( simpleOpenDialog() ), "Ctrl+O" );
311 addDPStaticEntry( menu, qtr( "Advanced Open File..." ),
312 ":/file-asym", SLOT( openFileDialog() ), "Ctrl+Shift+O" );
313 addDPStaticEntry( menu, qtr( "Open &URL" ),
314 NULL, SLOT( openUrlDialog() ), "Ctrl+V" );
315 addDPStaticEntry( menu, qtr( I_OPEN_FOLDER ),
316 ":/folder-grey", SLOT( PLOpenDir() ), "Ctrl+F" );
317 addDPStaticEntry( menu, qtr( "Open &Disc..." ),
318 ":/disc", SLOT( openDiscDialog() ), "Ctrl+D" );
319 addDPStaticEntry( menu, qtr( "Open &Network..." ),
320 ":/network", SLOT( openNetDialog() ), "Ctrl+N" );
321 addDPStaticEntry( menu, qtr( "Open &Capture Device..." ),
322 ":/capture-card", SLOT( openCaptureDialog() ),
323 "Ctrl+C" );
325 menu->addSeparator();
327 addDPStaticEntry( menu, qtr( I_PL_LOAD ), "", SLOT( openAPlaylist() ),
328 "Ctrl+X" );
329 addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", SLOT( saveAPlaylist() ),
330 "Ctrl+Y" );
332 menu->addSeparator();
334 recentsMenu = new QMenu( qtr( "Recently &Played" ), menu );
335 updateRecents( p_intf );
336 menu->addMenu( recentsMenu );
337 menu->addSeparator();
339 addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "",
340 SLOT( openAndTranscodingDialogs() ), "Ctrl+R" );
341 addDPStaticEntry( menu, qtr( "&Streaming..." ),
342 ":/stream", SLOT( openAndStreamingDialogs() ),
343 "Ctrl+S" );
344 menu->addSeparator();
346 addDPStaticEntry( menu, qtr( "&Quit" ) ,
347 ":/quit", SLOT( quit() ), "Ctrl+Q" );
348 return menu;
351 /* Playlist/MediaLibrary Control */
352 QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf )
354 VLC_UNUSED( p_intf ); //TODO remove
355 QMenu *menu = new QMenu();
357 addDPStaticEntry( menu, qtr( I_MENU_EXT ), ":/settings",
358 SLOT( extendedDialog() ), "Ctrl+E" );
360 addDPStaticEntry( menu, qtr( I_MENU_INFO ) , ":/info",
361 SLOT( mediaInfoDialog() ), "Ctrl+I" );
362 addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) ,
363 ":/info", SLOT( mediaCodecDialog() ), "Ctrl+J" );
365 addDPStaticEntry( menu, qtr( I_MENU_BOOKMARK ),"",
366 SLOT( bookmarksDialog() ), "Ctrl+B" );
367 #ifdef ENABLE_VLM
368 addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", SLOT( vlmDialog() ),
369 "Ctrl+W" );
370 #endif
372 addDPStaticEntry( menu, qtr( I_MENU_MSG ),
373 ":/messages", SLOT( messagesDialog() ),
374 "Ctrl+M" );
376 addDPStaticEntry( menu, qtr( "Plu&gins and extensions" ),
377 "", SLOT( pluginDialog() ) );
378 menu->addSeparator();
380 addDPStaticEntry( menu, qtr( "Customi&ze Interface..." ),
381 ":/preferences", SLOT( toolbarDialog() ) );
382 addDPStaticEntry( menu, qtr( "&Preferences" ),
383 ":/preferences", SLOT( prefsDialog() ), "Ctrl+P" );
385 return menu;
389 * Tools/View Menu
390 * This is kept in the same menu for now, but could change if it gets much
391 * longer.
392 * This menu can be an interface menu but also a right click menu.
394 QMenu *QVLCMenu::ViewMenu( intf_thread_t *p_intf,
395 QMenu *current,
396 MainInterface *mi,
397 bool visual_selector_enabled,
398 bool with_intf )
400 QMenu *menu = new QMenu( current );
401 QAction *act;
402 if( mi )
404 act = menu->addAction( QIcon( ":/playlist_menu" ),
405 qtr( "Play&list" ), mi,
406 SLOT( togglePlaylist() ), qtr( "Ctrl+L" ) );
407 act->setData( "_static_" );
409 act = menu->addMenu( SDMenu( p_intf ) );
410 act->setData( "_static_" );
411 /*menu->addSeparator();
412 menu->addAction( qtr( "Undock from Interface" ), mi,
413 SLOT( undockPlaylist() ), qtr( "Ctrl+U" ) );*/
416 menu->addSeparator();
418 if( with_intf )
420 QMenu *intfmenu = InterfacesMenu( p_intf, menu );
421 MenuFunc *f = new MenuFunc( intfmenu, 4 );
422 CONNECT( intfmenu, aboutToShow(), THEDP->menusUpdateMapper, map() );
423 THEDP->menusUpdateMapper->setMapping( intfmenu, f );
424 menu->addSeparator();
426 if( mi )
428 /* Minimal View */
429 QAction *action = menu->addAction( qtr( "Mi&nimal View" ), mi,
430 SLOT( toggleMinimalView() ), qtr( "Ctrl+H" ) );
431 action->setCheckable( true );
432 action->setData( "_static_" );
433 if( mi->getControlsVisibilityStatus() & CONTROLS_VISIBLE )
434 action->setChecked( true );
435 minimalViewAction = action; /* HACK for minimalView */
437 /* FullScreen View */
438 action = menu->addAction( qtr( "&Fullscreen Interface" ), mi,
439 SLOT( toggleFullScreen() ), QString( "F11" ) );
440 action->setCheckable( true );
441 action->setData( "_static_" );
443 /* Advanced Controls */
444 action = menu->addAction( qtr( "&Advanced Controls" ), mi,
445 SLOT( toggleAdvanced() ) );
446 action->setCheckable( true );
447 action->setData( "_static_" );
448 if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
449 action->setChecked( true );
450 #if 0 /* For Visualisations. Not yet working */
451 adv = menu->addAction( qtr( "Visualizations selector" ),
452 mi, SLOT( visual() ) );
453 adv->setCheckable( true );
454 if( visual_selector_enabled ) adv->setChecked( true );
455 #endif
458 menu->addSeparator();
460 return menu;
464 * Interface Sub-Menu, to list extras interface and skins
466 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
468 vector<vlc_object_t *> objects;
469 vector<const char *> varnames;
470 /** \todo add "switch to XXX" */
471 varnames.push_back( "intf-add" );
472 objects.push_back( VLC_OBJECT(p_intf) );
474 return Populate( p_intf, current, varnames, objects );
478 * Main Audio Menu
480 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
482 vector<vlc_object_t *> objects;
483 vector<const char *> varnames;
484 aout_instance_t *p_aout;
485 input_thread_t *p_input;
487 if( !current ) current = new QMenu();
489 if( current->isEmpty() )
491 ACT_ADD( current, "audio-es", qtr( "Audio &Track" ) );
492 ACT_ADD( current, "audio-device", qtr( "Audio &Device" ) );
493 ACT_ADD( current, "audio-channels", qtr( "Audio &Channels" ) );
494 current->addSeparator();
495 ACT_ADD( current, "visual", qtr( "&Visualizations" ) );
498 p_input = THEMIM->getInput();
499 if( p_input )
500 vlc_object_hold( p_input );
501 p_aout = THEMIM->getAout();
502 if( p_aout )
504 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
505 vlc_object_release( p_aout );
507 if( p_input )
508 vlc_object_release( p_input );
510 return Populate( p_intf, current, varnames, objects );
514 * Main Video Menu
515 * Subtitles are part of Video.
517 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
519 vout_thread_t *p_vout;
520 input_thread_t *p_input;
521 vector<vlc_object_t *> objects;
522 vector<const char *> varnames;
524 if( !current ) current = new QMenu();
526 if( current->isEmpty() )
528 ACT_ADD( current, "video-es", qtr( "Video &Track" ) );
530 QAction *action;
531 QMenu *submenu = new QMenu( qtr( "&Subtitles Track" ), current );
532 action = current->addMenu( submenu );
533 action->setData( "spu-es" );
534 addDPStaticEntry( submenu, qtr( "Open File..." ), "",
535 SLOT( loadSubtitlesFile() ) );
536 submenu->addSeparator();
538 ACT_ADD( current, "fullscreen", qtr( "&Fullscreen" ) );
539 ACT_ADD( current, "zoom", qtr( "&Zoom" ) );
540 ACT_ADD( current, "deinterlace", qtr( "&Deinterlace" ) );
541 ACT_ADD( current, "aspect-ratio", qtr( "&Aspect Ratio" ) );
542 ACT_ADD( current, "crop", qtr( "&Crop" ) );
543 ACT_ADD( current, "video-on-top", qtr( "Always &On Top" ) );
544 #ifdef WIN32
545 ACT_ADD( current, "directx-wallpaper", qtr( "DirectX Wallpaper" ) );
546 #endif
547 ACT_ADD( current, "video-snapshot", qtr( "Sna&pshot" ) );
548 ACT_ADD( current, "postproc-q", qtr( "Post processing" ) );
551 p_input = THEMIM->getInput();
552 if( p_input )
553 vlc_object_hold( p_input );
555 p_vout = THEMIM->getVout();
556 if( p_vout )
558 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
559 vlc_object_release( p_vout );
561 if( p_input )
562 vlc_object_release( p_input );
564 return Populate( p_intf, current, varnames, objects );
568 * Navigation Menu
569 * For DVD, MP4, MOV and other chapter based format
571 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
573 if( !menu ) menu = new QMenu();
575 if( menu->isEmpty() )
577 addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ),"",
578 SLOT( gotoTimeDialog() ), "Ctrl+T" );
579 menu->addSeparator();
581 ACT_ADD( menu, "bookmark", qtr( "&Bookmarks" ) );
582 ACT_ADD( menu, "title", qtr( "T&itle" ) );
583 ACT_ADD( menu, "chapter", qtr( "&Chapter" ) );
584 ACT_ADD( menu, "program", qtr( "&Program" ) );
585 ACT_ADD( menu, "navigation", qtr( "&Navigation" ) );
588 input_thread_t *p_object;
589 vector<vlc_object_t *> objects;
590 vector<const char *> varnames;
592 p_object = THEMIM->getInput();
593 if( p_object )
594 vlc_object_hold( p_object );
595 InputAutoMenuBuilder( p_object, objects, varnames );
596 PUSH_VAR( "prev-title" );
597 PUSH_VAR( "next-title" );
598 PUSH_VAR( "prev-chapter" );
599 PUSH_VAR( "next-chapter" );
600 EnableDPStaticEntries( menu, ( p_object != NULL ) );
601 if( p_object )
603 vlc_object_release( p_object );
605 return Populate( p_intf, menu, varnames, objects );
609 * Service Discovery SubMenu
611 QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf )
613 QMenu *menu = new QMenu();
614 menu->setTitle( qtr( I_PL_SD ) );
615 char **ppsz_longnames;
616 char **ppsz_names = vlc_sd_GetNames( &ppsz_longnames );
617 if( !ppsz_names )
618 return menu;
620 char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
621 for( ; *ppsz_name; ppsz_name++, ppsz_longname++ )
623 QAction *a = new QAction( qfu( *ppsz_longname ), menu );
624 a->setCheckable( true );
625 if( playlist_IsServicesDiscoveryLoaded( THEPL, *ppsz_name ) )
626 a->setChecked( true );
627 CONNECT( a , triggered(), THEDP->SDMapper, map() );
628 THEDP->SDMapper->setMapping( a, QString( *ppsz_name ) );
629 menu->addAction( a );
631 if( !strcmp( *ppsz_name, "podcast" ) )
633 QAction *b = new QAction( qtr( "Configure podcasts..." ), menu );
634 //b->setEnabled( a->isChecked() );
635 menu->addAction( b );
636 CONNECT( b, triggered(), THEDP, podcastConfigureDialog() );
638 free( *ppsz_name );
639 free( *ppsz_longname );
641 free( ppsz_names );
642 free( ppsz_longnames );
643 return menu;
646 * Help/About Menu
648 QMenu *QVLCMenu::HelpMenu( QMenu *current )
650 QMenu *menu = new QMenu( current );
651 addDPStaticEntry( menu, qtr( "&Help..." ) ,
652 ":/help", SLOT( helpDialog() ), "F1" );
653 #ifdef UPDATE_CHECK
654 addDPStaticEntry( menu, qtr( "Check for &Updates..." ) , "",
655 SLOT( updateDialog() ) );
656 #endif
657 menu->addSeparator();
658 addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), ":/info",
659 SLOT( aboutDialog() ), "Shift+F1" );
660 return menu;
663 /*****************************************************************************
664 * Popup menus - Right Click menus *
665 *****************************************************************************/
666 #define POPUP_BOILERPLATE \
667 unsigned int i_last_separator = 0; \
668 vector<vlc_object_t *> objects; \
669 vector<const char *> varnames; \
670 input_thread_t *p_input = THEMIM->getInput();
672 #define CREATE_POPUP \
673 Populate( p_intf, menu, varnames, objects ); \
674 p_intf->p_sys->p_popup_menu = menu; \
675 menu->popup( QCursor::pos() ); \
676 p_intf->p_sys->p_popup_menu = NULL; \
677 i_last_separator = 0;
679 void QVLCMenu::PopupMenuControlEntries( QMenu *menu,
680 intf_thread_t *p_intf,
681 input_thread_t *p_input )
683 if( p_input )
685 vlc_value_t val;
686 var_Get( p_input, "state", &val );
687 if( val.i_int == PLAYING_S )
688 addMIMStaticEntry( p_intf, menu, qtr( "Pause" ),
689 ":/pause", SLOT( togglePlayPause() ) );
690 else
691 addMIMStaticEntry( p_intf, menu, qtr( "Play" ),
692 ":/play", SLOT( togglePlayPause() ) );
694 else if( THEPL->items.i_size )
695 addMIMStaticEntry( p_intf, menu, qtr( "Play" ),
696 ":/play", SLOT( togglePlayPause() ) );
697 else
698 addDPStaticEntry( menu, qtr( "Play" ),
699 ":/play", SLOT( openDialog() ) );
701 addMIMStaticEntry( p_intf, menu, qtr( "Stop" ),
702 ":/stop", SLOT( stop() ) );
703 addMIMStaticEntry( p_intf, menu, qtr( "Previous" ),
704 ":/previous", SLOT( prev() ) );
705 addMIMStaticEntry( p_intf, menu, qtr( "Next" ),
706 ":/next", SLOT( next() ) );
709 void QVLCMenu::PopupMenuStaticEntries( QMenu *menu )
711 #if 0
712 QMenu *toolsmenu = ToolsMenu( p_intf, menu, false, true );
713 toolsmenu->setTitle( qtr( "Tools" ) );
714 menu->addMenu( toolsmenu );
715 #endif
717 QMenu *openmenu = new QMenu( qtr( "Open Media" ), menu );
718 addDPStaticEntry( openmenu, qtr( "&Open File..." ),
719 ":/file-asym", SLOT( openFileDialog() ) );
720 addDPStaticEntry( openmenu, qtr( I_OPEN_FOLDER ),
721 ":/folder-grey", SLOT( PLOpenDir() ) );
722 addDPStaticEntry( openmenu, qtr( "Open &Disc..." ),
723 ":/disc", SLOT( openDiscDialog() ) );
724 addDPStaticEntry( openmenu, qtr( "Open &Network..." ),
725 ":/network", SLOT( openNetDialog() ) );
726 addDPStaticEntry( openmenu, qtr( "Open &Capture Device..." ),
727 ":/capture-card", SLOT( openCaptureDialog() ) );
728 menu->addMenu( openmenu );
730 menu->addSeparator();
731 #if 0
732 QMenu *helpmenu = HelpMenu( menu );
733 helpmenu->setTitle( qtr( "Help" ) );
734 menu->addMenu( helpmenu );
735 #endif
737 addDPStaticEntry( menu, qtr( "Quit" ), ":/quit",
738 SLOT( quit() ), "Ctrl+Q" );
741 /* Video Tracks and Subtitles tracks */
742 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
744 POPUP_BOILERPLATE;
745 if( p_input )
747 vlc_object_hold( p_input );
748 vout_thread_t *p_vout = THEMIM->getVout();
749 if( p_vout )
751 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
752 vlc_object_release( p_vout );
754 vlc_object_release( p_input );
756 QMenu *menu = new QMenu();
757 CREATE_POPUP;
760 /* Audio Tracks */
761 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
763 POPUP_BOILERPLATE;
764 if( p_input )
766 vlc_object_hold( p_input );
767 aout_instance_t *p_aout = THEMIM->getAout();
768 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
769 if( p_aout )
770 vlc_object_release( p_aout );
771 vlc_object_release( p_input );
773 QMenu *menu = new QMenu();
774 CREATE_POPUP;
777 /* Navigation stuff, and general menus ( open ) */
778 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
780 POPUP_BOILERPLATE;
782 if( p_input )
784 vlc_object_hold( p_input );
785 varnames.push_back( "audio-es" );
786 InputAutoMenuBuilder( p_input, objects, varnames );
787 PUSH_SEPARATOR;
790 QMenu *menu = new QMenu();
791 Populate( p_intf, menu, varnames, objects );
793 menu->addSeparator();
794 PopupMenuControlEntries( menu, p_intf, p_input );
796 menu->addSeparator();
797 PopupMenuStaticEntries( menu );
799 p_intf->p_sys->p_popup_menu = menu;
800 menu->popup( QCursor::pos() );
801 p_intf->p_sys->p_popup_menu = NULL;
804 /* Main Menu that sticks everything together */
805 void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
807 MainInterface *mi = p_intf->p_sys->p_mi;
808 if( show )
810 /* Delete and recreate a popup if there is one */
811 if( p_intf->p_sys->p_popup_menu )
812 delete p_intf->p_sys->p_popup_menu;
814 QMenu *menu = new QMenu();
815 QMenu *submenu;
816 QAction *action;
817 bool b_isFullscreen = false;
819 POPUP_BOILERPLATE;
821 PopupMenuControlEntries( menu, p_intf, p_input );
822 menu->addSeparator();
824 if( p_input )
826 vout_thread_t *p_vout = THEMIM->getVout();
828 /* Add a fullscreen switch button */
829 if( p_vout )
831 vlc_value_t val;
832 var_Get( p_vout, "fullscreen", &val );
833 b_isFullscreen = !( !val.b_bool );
834 if( b_isFullscreen )
835 CreateAndConnect( menu, "fullscreen",
836 qtr( "Leave Fullscreen" ),"" , ITEM_NORMAL,
837 VLC_OBJECT(p_vout), val, VLC_VAR_BOOL,
838 b_isFullscreen );
839 vlc_object_release( p_vout );
842 menu->addSeparator();
844 vlc_object_hold( p_input );
845 InputAutoMenuBuilder( p_input, objects, varnames );
846 vlc_object_release( p_input );
848 submenu = new QMenu( menu );
849 action = menu->addMenu( AudioMenu( p_intf, submenu ) );
850 action->setText( qtr( "&Audio" ) );
851 if( action->menu()->isEmpty() )
852 action->setEnabled( false );
854 submenu = new QMenu( menu );
855 action = menu->addMenu( VideoMenu( p_intf, submenu ) );
856 action->setText( qtr( "&Video" ) );
857 if( action->menu()->isEmpty() )
858 action->setEnabled( false );
860 submenu = new QMenu( menu );
861 action = menu->addMenu( NavigMenu( p_intf, submenu ) );
862 action->setText( qtr( "&Playback" ) );
863 if( action->menu()->isEmpty() )
864 action->setEnabled( false );
867 menu->addSeparator();
869 /* Add some special entries for windowed mode: Interface Menu */
870 if( !b_isFullscreen )
872 submenu = new QMenu( qtr( "Interface" ), menu );
873 if( mi )
875 submenu->addAction( QIcon( ":/playlist" ),
876 qtr( "Show Playlist" ), mi, SLOT( togglePlaylist() ) );
878 addDPStaticEntry( submenu, qtr( I_MENU_EXT ),
879 ":/settings", SLOT( extendedDialog() ) );
880 addDPStaticEntry( submenu, qtr( I_MENU_INFO ) , ":/info",
881 SLOT( mediaInfoDialog() ), "Ctrl+I" );
882 if( mi )
884 action = submenu->addAction( QIcon( "" ),
885 qtr( "Minimal View" ), mi, SLOT( toggleMinimalView() ) );
886 action->setCheckable( true );
887 action->setChecked( !( mi->getControlsVisibilityStatus() &
888 CONTROLS_VISIBLE ) );
889 action = submenu->addAction( QIcon( "" ),
890 qtr( "Toggle Fullscreen Interface" ),
891 mi, SLOT( toggleFullScreen() ) );
892 action->setCheckable( true );
893 action->setChecked( mi->isFullScreen() );
895 else /* We are using the skins interface.
896 If not, this entry will not show. */
898 addDPStaticEntry( submenu, qtr( "&Preferences..." ),
899 ":/preferences", SLOT( prefsDialog() ), "Ctrl+P" );
900 submenu->addSeparator();
901 objects.clear();
902 varnames.clear();
903 vlc_object_t *p_object = ( vlc_object_t* )
904 vlc_object_find_name( p_intf, "skins2", FIND_PARENT );
905 if( p_object )
907 objects.push_back( p_object );
908 varnames.push_back( "intf-skins" );
909 Populate( p_intf, submenu, varnames, objects );
910 vlc_object_release( p_object );
912 else
914 msg_Dbg( p_intf, "could not find parent interface" );
917 menu->addMenu( submenu );
920 PopupMenuStaticEntries( menu );
922 p_intf->p_sys->p_popup_menu = menu;
923 p_intf->p_sys->p_popup_menu->popup( QCursor::pos() );
925 else
927 // destroy popup if there is one
928 delete p_intf->p_sys->p_popup_menu;
929 p_intf->p_sys->p_popup_menu = NULL;
933 #undef ACT_ADD
935 /************************************************************************
936 * Systray Menu *
937 ************************************************************************/
939 void QVLCMenu::updateSystrayMenu( MainInterface *mi,
940 intf_thread_t *p_intf,
941 bool b_force_visible )
943 POPUP_BOILERPLATE;
945 /* Get the systray menu and clean it */
946 QMenu *sysMenu = mi->getSysTrayMenu();
947 sysMenu->clear();
949 /* Hide / Show VLC and cone */
950 if( mi->isVisible() || b_force_visible )
952 sysMenu->addAction( QIcon( ":/vlc16.png" ),
953 qtr( "Hide VLC media player in taskbar" ), mi,
954 SLOT( toggleUpdateSystrayMenu() ) );
956 else
958 sysMenu->addAction( QIcon( ":/vlc16.png" ),
959 qtr( "Show VLC media player" ), mi,
960 SLOT( toggleUpdateSystrayMenu() ) );
963 sysMenu->addSeparator();
964 PopupMenuControlEntries( sysMenu, p_intf, p_input );
966 sysMenu->addSeparator();
967 addDPStaticEntry( sysMenu, qtr( "&Open Media" ),
968 ":/file-wide", SLOT( openFileDialog() ) );
969 addDPStaticEntry( sysMenu, qtr( "&Quit" ) ,
970 ":/quit", SLOT( quit() ) );
972 /* Set the menu */
973 mi->getSysTray()->setContextMenu( sysMenu );
976 #undef PUSH_VAR
977 #undef PUSH_SEPARATOR
979 /*************************************************************************
980 * Builders for automenus
981 *************************************************************************/
982 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf,
983 QMenu *current,
984 vector< const char *> & varnames,
985 vector<vlc_object_t *> & objects )
987 QMenu *menu = current;
988 if( !menu ) menu = new QMenu();
990 /* Disable all non static entries */
991 QAction *p_action;
992 foreach( p_action, menu->actions() )
994 if( p_action->data().toString() != "_static_" )
995 p_action->setEnabled( false );
998 currentGroup = NULL;
1000 vlc_object_t *p_object;
1001 int i;
1003 for( i = 0; i < ( int )objects.size() ; i++ )
1005 if( !varnames[i] || !*varnames[i] )
1007 menu->addSeparator();
1008 continue;
1010 p_object = objects[i];
1012 UpdateItem( p_intf, menu, varnames[i], p_object, true );
1014 return menu;
1017 /*****************************************************************************
1018 * Private methods.
1019 *****************************************************************************/
1021 static bool IsMenuEmpty( const char *psz_var,
1022 vlc_object_t *p_object,
1023 bool b_root = true )
1025 vlc_value_t val, val_list;
1026 int i_type, i_result, i;
1028 /* Check the type of the object variable */
1029 i_type = var_Type( p_object, psz_var );
1031 /* Check if we want to display the variable */
1032 if( !( i_type & VLC_VAR_HASCHOICE ) ) return false;
1034 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
1035 if( val.i_int == 0 ) return true;
1037 if( ( i_type & VLC_VAR_TYPE ) != VLC_VAR_VARIABLE )
1039 if( val.i_int == 1 && b_root ) return true;
1040 else return false;
1043 /* Check children variables in case of VLC_VAR_VARIABLE */
1044 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
1046 return true;
1049 for( i = 0, i_result = true; i < val_list.p_list->i_count; i++ )
1051 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
1052 p_object, false ) )
1054 i_result = false;
1055 break;
1059 /* clean up everything */
1060 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
1062 return i_result;
1065 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
1067 void QVLCMenu::UpdateItem( intf_thread_t *p_intf, QMenu *menu,
1068 const char *psz_var, vlc_object_t *p_object, bool b_submenu )
1070 vlc_value_t val, text;
1071 int i_type;
1073 QAction *action = FindActionWithVar( menu, psz_var );
1074 if( action )
1075 DeleteNonStaticEntries( action->menu() );
1077 if( !p_object )
1078 return;
1080 /* Check the type of the object variable */
1081 if( !strcmp( psz_var, "audio-es" )
1082 || !strcmp( psz_var, "video-es" )
1083 || !strcmp( psz_var, "postproc-q" ) )
1084 i_type = VLC_VAR_INTEGER | VLC_VAR_HASCHOICE;
1085 else
1086 i_type = var_Type( p_object, psz_var );
1088 switch( i_type & VLC_VAR_TYPE )
1090 case VLC_VAR_VOID:
1091 case VLC_VAR_BOOL:
1092 case VLC_VAR_VARIABLE:
1093 case VLC_VAR_STRING:
1094 case VLC_VAR_INTEGER:
1095 case VLC_VAR_FLOAT:
1096 break;
1097 default:
1098 /* Variable doesn't exist or isn't handled */
1099 return;
1102 /* Make sure we want to display the variable */
1103 if( menu->isEmpty() && IsMenuEmpty( psz_var, p_object ) )
1104 return;
1106 /* Get the descriptive name of the variable */
1107 int i_ret = var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
1108 if( i_ret != VLC_SUCCESS )
1110 text.psz_string = NULL;
1113 if( !action )
1115 action = new QAction( TEXT_OR_VAR, menu );
1116 menu->addAction( action );
1117 action->setData( psz_var );
1120 /* Some specific stuff */
1121 bool forceDisabled = false;
1122 if( !strcmp( psz_var, "spu-es" ) )
1124 vout_thread_t *p_vout = THEMIM->getVout();
1125 forceDisabled = ( p_vout == NULL );
1126 if( p_vout )
1127 vlc_object_release( p_vout );
1130 if( i_type & VLC_VAR_HASCHOICE )
1132 /* Append choices menu */
1133 if( b_submenu )
1135 QMenu *submenu;
1136 submenu = action->menu();
1137 if( !submenu )
1139 submenu = new QMenu( menu );
1140 action->setMenu( submenu );
1143 action->setEnabled(
1144 CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0 );
1145 if( forceDisabled )
1146 action->setEnabled( false );
1148 else
1149 CreateChoicesMenu( menu, psz_var, p_object, true );
1150 FREENULL( text.psz_string );
1151 return;
1154 switch( i_type & VLC_VAR_TYPE )
1156 case VLC_VAR_VOID:
1157 var_Get( p_object, psz_var, &val );
1158 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
1159 p_object, val, i_type );
1160 break;
1162 case VLC_VAR_BOOL:
1163 var_Get( p_object, psz_var, &val );
1164 val.b_bool = !val.b_bool;
1165 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
1166 p_object, val, i_type, !val.b_bool );
1167 break;
1169 FREENULL( text.psz_string );
1173 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
1174 vlc_object_t *p_object, bool b_root )
1176 vlc_value_t val, val_list, text_list;
1177 int i_type, i;
1179 /* Check the type of the object variable */
1180 i_type = var_Type( p_object, psz_var );
1182 /* Make sure we want to display the variable */
1183 if( submenu->isEmpty() && IsMenuEmpty( psz_var, p_object, b_root ) )
1184 return VLC_EGENERIC;
1186 switch( i_type & VLC_VAR_TYPE )
1188 case VLC_VAR_VOID:
1189 case VLC_VAR_BOOL:
1190 case VLC_VAR_VARIABLE:
1191 case VLC_VAR_STRING:
1192 case VLC_VAR_INTEGER:
1193 case VLC_VAR_FLOAT:
1194 break;
1195 default:
1196 /* Variable doesn't exist or isn't handled */
1197 return VLC_EGENERIC;
1200 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
1201 &val_list, &text_list ) < 0 )
1203 return VLC_EGENERIC;
1206 #define CURVAL val_list.p_list->p_values[i]
1207 #define CURTEXT text_list.p_list->p_values[i].psz_string
1209 for( i = 0; i < val_list.p_list->i_count; i++ )
1211 vlc_value_t another_val;
1212 QString menutext;
1213 QMenu *subsubmenu = new QMenu( submenu );
1215 switch( i_type & VLC_VAR_TYPE )
1217 case VLC_VAR_VARIABLE:
1218 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
1219 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
1220 submenu->addMenu( subsubmenu );
1221 break;
1223 case VLC_VAR_STRING:
1224 var_Get( p_object, psz_var, &val );
1225 another_val.psz_string = strdup( CURVAL.psz_string );
1226 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
1227 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1228 p_object, another_val, i_type,
1229 val.psz_string && !strcmp( val.psz_string, CURVAL.psz_string ) );
1231 free( val.psz_string );
1232 break;
1234 case VLC_VAR_INTEGER:
1235 var_Get( p_object, psz_var, &val );
1236 if( CURTEXT ) menutext = qfu( CURTEXT );
1237 else menutext.sprintf( "%d", CURVAL.i_int );
1238 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1239 p_object, CURVAL, i_type,
1240 CURVAL.i_int == val.i_int );
1241 break;
1243 case VLC_VAR_FLOAT:
1244 var_Get( p_object, psz_var, &val );
1245 if( CURTEXT ) menutext = qfu( CURTEXT );
1246 else menutext.sprintf( "%.2f", CURVAL.f_float );
1247 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1248 p_object, CURVAL, i_type,
1249 CURVAL.f_float == val.f_float );
1250 break;
1252 default:
1253 break;
1256 currentGroup = NULL;
1258 /* clean up everything */
1259 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
1261 #undef CURVAL
1262 #undef CURTEXT
1263 return VLC_SUCCESS;
1266 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
1267 QString text, QString help,
1268 int i_item_type, vlc_object_t *p_obj,
1269 vlc_value_t val, int i_val_type,
1270 bool checked )
1272 QAction *action = FindActionWithVar( menu, psz_var );
1273 if( !action )
1275 action = new QAction( text, menu );
1276 menu->addAction( action );
1279 action->setToolTip( help );
1280 action->setEnabled( p_obj != NULL );
1282 if( i_item_type == ITEM_CHECK )
1284 action->setCheckable( true );
1286 else if( i_item_type == ITEM_RADIO )
1288 action->setCheckable( true );
1289 if( !currentGroup )
1290 currentGroup = new QActionGroup( menu );
1291 currentGroup->addAction( action );
1294 action->setChecked( checked );
1296 MenuItemData *itemData = new MenuItemData( THEDP->menusMapper, p_obj, i_val_type,
1297 val, psz_var );
1298 CONNECT( action, triggered(), THEDP->menusMapper, map() );
1299 THEDP->menusMapper->setMapping( action, itemData );
1300 menu->addAction( action );
1303 void QVLCMenu::DoAction( QObject *data )
1305 MenuItemData *itemData = qobject_cast<MenuItemData *>( data );
1306 vlc_object_t *p_object = itemData->p_obj;
1307 if( p_object == NULL ) return;
1309 var_Set( p_object, itemData->psz_var, itemData->val );
1312 void QVLCMenu::updateRecents( intf_thread_t *p_intf )
1314 if (recentsMenu)
1316 QAction* action;
1317 RecentsMRL* rmrl = RecentsMRL::getInstance( p_intf );
1318 QList<QString> l = rmrl->recents();
1320 recentsMenu->clear();
1321 if( !l.size() )
1323 action = recentsMenu->addAction( " - Empty - " );
1324 action->setEnabled( false );
1326 else
1328 for( int i = 0; i < l.size(); ++i )
1330 action = recentsMenu->addAction(
1331 QString( "&%1: " ).arg( i + 1 ) + l.at( i ),
1332 rmrl->signalMapper,
1333 SLOT( map() ) );
1334 rmrl->signalMapper->setMapping( action, l.at( i ) );
1337 recentsMenu->addSeparator();
1338 recentsMenu->addAction( "&Clear", rmrl, SLOT( clear() ) );