1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright ( C ) 2006-2007 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Jean-Baptiste Kempf <jb@videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * ( at your option ) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
27 #include <vlc_intf_strings.h>
29 #include "main_interface.hpp"
31 #include "dialogs_provider.hpp"
32 #include "input_manager.hpp"
37 #include <QActionGroup>
38 #include <QSignalMapper>
39 #include <QSystemTrayIcon>
48 static QActionGroup *currentGroup;
50 // Add static entries to menus
51 void addDPStaticEntry( QMenu *menu,
58 if( !EMPTY_STR( icon ) > 0 )
60 if( !EMPTY_STR( shortcut ) > 0 )
61 menu->addAction( QIcon( icon ), text, THEDP, member, qtr( shortcut ) );
63 menu->addAction( QIcon( icon ), text, THEDP, member );
67 if( !EMPTY_STR( shortcut ) > 0 )
68 menu->addAction( text, THEDP, member, qtr( shortcut ) );
70 menu->addAction( text, THEDP, member );
74 void addMIMStaticEntry( intf_thread_t *p_intf,
81 if( strlen( icon ) > 0 )
83 QAction *action = menu->addAction( text, THEMIM, member );
84 action->setIcon( QIcon( icon ) );
88 menu->addAction( text, THEMIM, member );
92 /*****************************************************************************
93 * Definitions of variables for the dynamic menus
94 *****************************************************************************/
95 #define PUSH_VAR( var ) varnames.push_back( var ); \
96 objects.push_back( p_object->i_object_id )
98 #define PUSH_SEPARATOR if( objects.size() != i_last_separator ) { \
99 objects.push_back( 0 ); varnames.push_back( "" ); \
100 i_last_separator = objects.size(); }
102 static int InputAutoMenuBuilder( vlc_object_t *p_object,
103 vector<int> &objects,
104 vector<const char *> &varnames )
106 PUSH_VAR( "bookmark" );
108 PUSH_VAR( "chapter" );
109 PUSH_VAR( "program" );
110 PUSH_VAR( "navigation" );
111 PUSH_VAR( "dvd_menus" );
115 static int VideoAutoMenuBuilder( vlc_object_t *p_object,
116 vector<int> &objects,
117 vector<const char *> &varnames )
119 PUSH_VAR( "fullscreen" );
121 PUSH_VAR( "deinterlace" );
122 PUSH_VAR( "aspect-ratio" );
124 PUSH_VAR( "video-on-top" );
125 PUSH_VAR( "directx-wallpaper" );
126 PUSH_VAR( "video-snapshot" );
128 vlc_object_t *p_dec_obj = ( vlc_object_t * )vlc_object_find( p_object,
131 if( p_dec_obj != NULL )
133 vlc_object_t *p_object = p_dec_obj;
134 PUSH_VAR( "ffmpeg-pp-q" );
135 vlc_object_release( p_dec_obj );
140 static int AudioAutoMenuBuilder( vlc_object_t *p_object,
141 vector<int> &objects,
142 vector<const char *> &varnames )
144 PUSH_VAR( "audio-device" );
145 PUSH_VAR( "audio-channels" );
146 PUSH_VAR( "visual" );
147 PUSH_VAR( "equalizer" );
151 /*****************************************************************************
154 *****************************************************************************/
156 #define BAR_ADD( func, title ) { \
157 QMenu *menu = func; menu->setTitle( title ); bar->addMenu( menu ); }
159 #define BAR_DADD( func, title, id ) { \
160 QMenu *menu = func; menu->setTitle( title ); bar->addMenu( menu ); \
161 MenuFunc *f = new MenuFunc( menu, id ); \
162 CONNECT( menu, aboutToShow(), THEDP->menusUpdateMapper, map() ); \
163 THEDP->menusUpdateMapper->setMapping( menu, f ); }
166 * Main Menu Bar Creation
168 void QVLCMenu::createMenuBar( MainInterface *mi,
169 intf_thread_t *p_intf,
170 bool visual_selector_enabled )
172 QMenuBar *bar = mi->menuBar();
173 BAR_ADD( FileMenu(), qtr( "&Media" ) );
174 BAR_ADD( PlaylistMenu( p_intf, mi ), qtr( "&Playlist" ) );
175 BAR_ADD( ToolsMenu( p_intf, mi, visual_selector_enabled, true ),
177 BAR_DADD( AudioMenu( p_intf, NULL ), qtr( "&Audio" ), 2 );
178 BAR_DADD( VideoMenu( p_intf, NULL ), qtr( "&Video" ), 1 );
179 BAR_DADD( NavigMenu( p_intf, NULL ), qtr( "&Playback" ), 3 );
181 BAR_ADD( HelpMenu(), qtr( "&Help" ) );
187 * Media ( File ) Menu
188 * Opening, streaming and quit
190 QMenu *QVLCMenu::FileMenu()
192 QMenu *menu = new QMenu();
194 addDPStaticEntry( menu, qtr( "&Open File..." ), "",
195 ":/pixmaps/file-asym_16px.png", SLOT( openFileDialog() ), "Ctrl+O" );
196 addDPStaticEntry( menu, qtr( I_OPEN_FOLDER ), "",
197 ":/pixmaps/folder-grey_16px.png", SLOT( PLAppendDir() ), "Ctrl+F" );
198 addDPStaticEntry( menu, qtr( "Open &Disc..." ), "",
199 ":/pixmaps/disc_16px.png", SLOT( openDiscDialog() ), "Ctrl+D" );
200 addDPStaticEntry( menu, qtr( "Open &Network..." ), "",
201 ":/pixmaps/network_16px.png", SLOT( openNetDialog() ), "Ctrl+N" );
202 addDPStaticEntry( menu, qtr( "Open &Capture Device..." ), "",
203 ":/pixmaps/capture-card_16px.png", SLOT( openCaptureDialog() ),
205 menu->addSeparator();
207 addDPStaticEntry( menu, qtr( "&Streaming..." ), "",
208 ":/pixmaps/menus_stream_16px.png", SLOT( openThenStreamingDialogs() ),
210 addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "", "",
211 SLOT( openThenTranscodingDialogs() ), "Ctrl+R" );
212 menu->addSeparator();
214 addDPStaticEntry( menu, qtr( "&Quit" ) , "",
215 ":/pixmaps/menus_quit_16px.png", SLOT( quit() ), "Ctrl+Q" );
219 /* Playlist/MediaLibrary Control */
220 QMenu *QVLCMenu::PlaylistMenu( intf_thread_t *p_intf, MainInterface *mi )
222 QMenu *menu = new QMenu();
223 menu->addMenu( SDMenu( p_intf ) );
224 menu->addAction( QIcon( ":/pixmaps/playlist_16px.png" ),
225 qtr( "Show Playlist" ), mi, SLOT( togglePlaylist() ) );
226 menu->addSeparator();
228 addDPStaticEntry( menu, qtr( I_PL_LOAD ), "", "", SLOT( openAPlaylist() ),
230 addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", "", SLOT( saveAPlaylist() ),
232 menu->addSeparator();
233 menu->addAction( qtr( "Undock from interface" ), mi,
234 SLOT( undockPlaylist() ), qtr( "Ctrl+U" ) );
240 * This is kept in the same menu for now, but could change if it gets much
242 * This menu can be an interface menu but also a right click menu.
244 QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf,
246 bool visual_selector_enabled,
249 QMenu *menu = new QMenu;
252 menu->addAction( QIcon( ":/pixmaps/playlist_16px.png" ),
253 qtr( "Playlist..." ), mi, SLOT( togglePlaylist() ),
256 addDPStaticEntry( menu, qtr( I_MENU_EXT ), "",
257 ":/pixmaps/menus_settings_16px.png", SLOT( extendedDialog() ),
260 menu->addSeparator();
264 QMenu *intfmenu = InterfacesMenu( p_intf, NULL );
265 intfmenu->setTitle( qtr( "Add Interfaces" ) );
266 menu->addMenu( intfmenu );
267 menu->addSeparator();
272 QAction *action=menu->addAction( qtr( "Minimal View..." ), mi,
273 SLOT( toggleMinimalView() ), qtr( "Ctrl+H" ) );
274 action->setCheckable( true );
275 if( mi->getControlsVisibilityStatus() & CONTROLS_VISIBLE )
276 action->setChecked( true );
278 /* FullScreen View */
279 action = menu->addAction( qtr( "Toggle Fullscreen Interface" ), mi,
280 SLOT( toggleFullScreen() ), qtr( "F11" ) );
282 /* Advanced Controls */
283 action = menu->addAction( qtr( "Advanced controls" ), mi,
284 SLOT( toggleAdvanced() ) );
285 action->setCheckable( true );
286 if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
287 action->setChecked( true );
288 #if 0 /* For Visualisations. Not yet working */
289 adv = menu->addAction( qtr( "Visualizations selector" ),
290 mi, SLOT( visual() ) );
291 adv->setCheckable( true );
292 if( visual_selector_enabled ) adv->setChecked( true );
296 menu->addSeparator();
298 addDPStaticEntry( menu, qtr( I_MENU_MSG ), "",
299 ":/pixmaps/menus_messages_16px.png", SLOT( messagesDialog() ),
301 addDPStaticEntry( menu, qtr( I_MENU_INFO ) , "", "",
302 SLOT( mediaInfoDialog() ), "Ctrl+I" );
303 addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) , "",
304 ":/pixmaps/menus_info_16px.png", SLOT( mediaCodecDialog() ), "Ctrl+J" );
305 addDPStaticEntry( menu, qtr( I_MENU_BOOKMARK ), "","",
306 SLOT( bookmarksDialog() ), "Ctrl+B" );
308 addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", "", SLOT( vlmDialog() ),
312 menu->addSeparator();
313 addDPStaticEntry( menu, qtr( "Preferences..." ), "",
314 ":/pixmaps/menus_preferences_16px.png", SLOT( prefsDialog() ), "Ctrl+P" );
319 * Interface Sub-Menu, to list extras interface and skins
321 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
324 vector<const char *> varnames;
325 /** \todo add "switch to XXX" */
326 varnames.push_back( "intf-add" );
327 objects.push_back( p_intf->i_object_id );
329 QMenu *menu = Populate( p_intf, current, varnames, objects );
331 if( !p_intf->pf_show_dialog )
333 menu->addSeparator();
334 menu->addAction( qtr( "Switch to skins" ), THEDP,
335 SLOT( switchToSkins() ), QString( "Ctrl+Z" ) );
337 if( module_Exists( VLC_OBJECT( p_intf ), "wxwidgets" ) )
339 menu->addAction( qtr( "Switch to WxWidgets" ), THEDP,
340 SLOT( switchToWx() ) );
345 CONNECT( menu, aboutToShow(), THEDP->menusUpdateMapper, map() );
346 THEDP->menusUpdateMapper->setMapping( menu, 4 );
353 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
356 vector<const char *> varnames;
358 vlc_object_t *p_object = ( vlc_object_t * )vlc_object_find( p_intf,
359 VLC_OBJECT_INPUT, FIND_ANYWHERE );
360 if( p_object != NULL )
362 PUSH_VAR( "audio-es" );
363 vlc_object_release( p_object );
366 p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_AOUT,
370 AudioAutoMenuBuilder( p_object, objects, varnames );
371 vlc_object_release( p_object );
373 return Populate( p_intf, current, varnames, objects );
378 * Subtitles are part of Video.
380 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
382 vlc_object_t *p_object;
384 vector<const char *> varnames;
386 p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_INPUT,
388 if( p_object != NULL )
390 PUSH_VAR( "video-es" );
391 PUSH_VAR( "spu-es" );
392 vlc_object_release( p_object );
395 p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_VOUT,
397 if( p_object != NULL )
399 VideoAutoMenuBuilder( p_object, objects, varnames );
400 vlc_object_release( p_object );
402 return Populate( p_intf, current, varnames, objects );
407 * For DVD, MP4, MOV and other chapter based format
409 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *navMenu )
411 vlc_object_t *p_object;
413 vector<const char *> varnames;
415 p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_INPUT,
417 if( p_object != NULL )
419 InputAutoMenuBuilder( p_object, objects, varnames );
420 PUSH_VAR( "prev-title" ); PUSH_VAR ( "next-title" );
421 PUSH_VAR( "prev-chapter" ); PUSH_VAR( "next-chapter" );
422 vlc_object_release( p_object );
424 navMenu = new QMenu();
425 addDPStaticEntry( navMenu, qtr( I_MENU_GOTOTIME ), "","",
426 SLOT( gotoTimeDialog() ), "Ctrl+T" );
427 navMenu->addSeparator();
428 return Populate( p_intf, navMenu, varnames, objects, true );
432 * Service Discovery SubMenu
434 QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf )
436 QMenu *menu = new QMenu();
437 menu->setTitle( qtr( I_PL_SD ) );
438 char **ppsz_longnames;
439 char **ppsz_names = services_discovery_GetServicesNames( p_intf,
441 char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
442 for( ; *ppsz_name; ppsz_name++, ppsz_longname++ )
444 QAction *a = new QAction( qfu( *ppsz_longname ), menu );
445 a->setCheckable( true );
446 if( playlist_IsServicesDiscoveryLoaded( THEPL, *ppsz_name ) )
447 a->setChecked( true );
448 CONNECT( a , triggered(), THEDP->SDMapper, map() );
449 THEDP->SDMapper->setMapping( a, QString( *ppsz_name ) );
450 menu->addAction( a );
452 if( !strcmp( *ppsz_name, "podcast" ) )
454 QAction *b = new QAction( qfu( "Configure podcasts..." ), menu );
455 //b->setEnabled( a->isChecked() );
456 menu->addAction( b );
457 CONNECT( b, triggered(), THEDP, podcastConfigureDialog() );
460 free( *ppsz_longname );
463 free( ppsz_longnames );
469 QMenu *QVLCMenu::HelpMenu()
471 QMenu *menu = new QMenu();
472 addDPStaticEntry( menu, qtr( "Help..." ) , "",
473 ":/pixmaps/menus_help_16px.png", SLOT( helpDialog() ), "F1" );
475 addDPStaticEntry( menu, qtr( "Update" ) , "", "", SLOT( updateDialog() ), "");
477 menu->addSeparator();
478 addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), "", "", SLOT( aboutDialog() ),
484 /*****************************************************************************
485 * Popup menus - Right Click menus *
486 *****************************************************************************/
487 #define POPUP_BOILERPLATE \
488 unsigned int i_last_separator = 0; \
489 vector<int> objects; \
490 vector<const char *> varnames; \
491 input_thread_t *p_input = THEMIM->getInput();
493 #define CREATE_POPUP \
494 Populate( p_intf, menu, varnames, objects ); \
495 p_intf->p_sys->p_popup_menu = menu; \
496 menu->popup( QCursor::pos() ); \
497 p_intf->p_sys->p_popup_menu = NULL; \
498 i_last_separator = 0;
500 void QVLCMenu::PopupMenuControlEntries( QMenu *menu,
501 intf_thread_t *p_intf,
502 input_thread_t *p_input )
507 var_Get( p_input, "state", &val );
508 if( val.i_int == PLAYING_S )
509 addMIMStaticEntry( p_intf, menu, qtr( "Pause" ), "",
510 ":/pixmaps/pause_16px.png", SLOT( togglePlayPause() ) );
512 addMIMStaticEntry( p_intf, menu, qtr( "Play" ), "",
513 ":/pixmaps/play_16px.png", SLOT( togglePlayPause() ) );
515 else if( THEPL->items.i_size && THEPL->i_enabled )
516 addMIMStaticEntry( p_intf, menu, qtr( "Play" ), "",
517 ":/pixmaps/play_16px.png", SLOT( togglePlayPause() ) );
519 addMIMStaticEntry( p_intf, menu, qtr( "Stop" ), "",
520 ":/pixmaps/stop_16px.png", SLOT( stop() ) );
521 addMIMStaticEntry( p_intf, menu, qtr( "Previous" ), "",
522 ":/pixmaps/previous_16px.png", SLOT( prev() ) );
523 addMIMStaticEntry( p_intf, menu, qtr( "Next" ), "",
524 ":/pixmaps/next_16px.png", SLOT( next() ) );
527 void QVLCMenu::PopupMenuStaticEntries( intf_thread_t *p_intf, QMenu *menu )
529 QMenu *toolsmenu = ToolsMenu( p_intf, NULL, false, true );
530 toolsmenu->setTitle( qtr( "Tools" ) );
531 menu->addMenu( toolsmenu );
533 QMenu *openmenu = new QMenu( qtr( "Open" ) );
534 openmenu->addAction( qtr( "Open &File..." ), THEDP,
535 SLOT( openFileDialog() ) );
536 openmenu->addAction( qtr( "Open &Disc..." ), THEDP,
537 SLOT( openDiscDialog() ) );
538 openmenu->addAction( qtr( "Open &Network..." ), THEDP,
539 SLOT( openNetDialog() ) );
540 openmenu->addAction( qtr( "Open &Capture Device..." ), THEDP,
541 SLOT( openCaptureDialog() ) );
542 menu->addMenu( openmenu );
544 menu->addSeparator();
545 QMenu *helpmenu = HelpMenu();
546 helpmenu->setTitle( qtr( "Help" ) );
547 menu->addMenu( helpmenu );
549 addDPStaticEntry( menu, qtr( "Quit" ), "", "", SLOT( quit() ) , "Ctrl+Q" );
552 /* Video Tracks and Subtitles tracks */
553 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
558 vlc_object_yield( p_input );
559 varnames.push_back( "video-es" );
560 objects.push_back( p_input->i_object_id );
561 varnames.push_back( "spu-es" );
562 objects.push_back( p_input->i_object_id );
563 vlc_object_t *p_vout = ( vlc_object_t * )vlc_object_find( p_input,
564 VLC_OBJECT_VOUT, FIND_CHILD );
567 VideoAutoMenuBuilder( p_vout, objects, varnames );
568 vlc_object_release( p_vout );
570 vlc_object_release( p_input );
572 QMenu *menu = new QMenu();
577 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
582 vlc_object_yield( p_input );
583 varnames.push_back( "audio-es" );
584 objects.push_back( p_input->i_object_id );
585 vlc_object_t *p_aout = ( vlc_object_t * )vlc_object_find( p_input,
586 VLC_OBJECT_AOUT, FIND_ANYWHERE );
589 AudioAutoMenuBuilder( p_aout, objects, varnames );
590 vlc_object_release( p_aout );
592 vlc_object_release( p_input );
594 QMenu *menu = new QMenu();
598 /* Navigation stuff, and general menus ( open ) */
599 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
606 vlc_object_yield( p_input );
607 varnames.push_back( "audio-es" );
608 InputAutoMenuBuilder( VLC_OBJECT( p_input ), objects, varnames );
612 QMenu *menu = new QMenu();
613 Populate( p_intf, menu, varnames, objects );
615 menu->addSeparator();
616 PopupMenuControlEntries( menu, p_intf, p_input );
618 menu->addSeparator();
619 PopupMenuStaticEntries( p_intf, menu );
621 p_intf->p_sys->p_popup_menu = menu;
622 menu->popup( QCursor::pos() );
623 p_intf->p_sys->p_popup_menu = NULL;
626 /* Main Menu that sticks everything together */
627 void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
631 // create a popup if there is none
632 if( ! p_intf->p_sys->p_popup_menu )
637 vlc_object_yield( p_input );
638 InputAutoMenuBuilder( VLC_OBJECT( p_input ), objects, varnames );
642 varnames.push_back( "audio-es" );
643 objects.push_back( p_input->i_object_id );
644 vlc_object_t *p_aout = ( vlc_object_t * )
645 vlc_object_find( p_input, VLC_OBJECT_AOUT, FIND_ANYWHERE );
648 AudioAutoMenuBuilder( p_aout, objects, varnames );
649 vlc_object_release( p_aout );
654 varnames.push_back( "video-es" );
655 objects.push_back( p_input->i_object_id );
656 varnames.push_back( "spu-es" );
657 objects.push_back( p_input->i_object_id );
658 vlc_object_t *p_vout = ( vlc_object_t * )
659 vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD );
662 VideoAutoMenuBuilder( p_vout, objects, varnames );
663 vlc_object_release( p_vout );
667 QMenu *menu = new QMenu();
668 Populate( p_intf, menu, varnames, objects );
669 menu->addSeparator();
670 PopupMenuControlEntries( menu, p_intf, p_input );
671 menu->addSeparator();
672 PopupMenuStaticEntries( p_intf, menu );
674 p_intf->p_sys->p_popup_menu = menu;
676 p_intf->p_sys->p_popup_menu->popup( QCursor::pos() );
680 // destroy popup if there is one
681 delete p_intf->p_sys->p_popup_menu;
682 p_intf->p_sys->p_popup_menu = NULL;
686 /************************************************************************
688 ************************************************************************/
690 void QVLCMenu::updateSystrayMenu( MainInterface *mi,
691 intf_thread_t *p_intf,
692 bool b_force_visible )
696 /* Get the systray menu and clean it */
697 QMenu *sysMenu = mi->getSysTrayMenu();
700 /* Hide / Show VLC and cone */
701 if( mi->isVisible() || b_force_visible )
703 sysMenu->addAction( QIcon( ":/vlc16.png" ),
704 qtr( "Hide VLC media player in taskbar" ), mi,
705 SLOT( toggleUpdateSystrayMenu() ) );
709 sysMenu->addAction( QIcon( ":/vlc16.png" ),
710 qtr( "Show VLC media player" ), mi,
711 SLOT( toggleUpdateSystrayMenu() ) );
714 sysMenu->addSeparator();
715 PopupMenuControlEntries( sysMenu, p_intf, p_input );
717 sysMenu->addSeparator();
718 addDPStaticEntry( sysMenu, qtr( "&Open Media" ), "",
719 ":/pixmaps/file-wide_16px.png", SLOT( openFileDialog() ), "" );
720 addDPStaticEntry( sysMenu, qtr( "&Quit" ) , "",
721 ":/pixmaps/menus_quit_16px.png", SLOT( quit() ), "" );
724 mi->getSysTray()->setContextMenu( sysMenu );
728 #undef PUSH_SEPARATOR
731 /*************************************************************************
732 * Builders for automenus
733 *************************************************************************/
734 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf,
736 vector< const char *> & varnames,
737 vector<int> & objects,
740 QMenu *menu = current;
748 vlc_object_t *p_object;
749 vlc_bool_t b_section_empty = VLC_FALSE;
752 #define APPEND_EMPTY { QAction *action = menu->addAction( qtr( "Empty" ) ); \
753 action->setEnabled( false ); }
755 for( i = 0; i < ( int )objects.size() ; i++ )
757 if( !varnames[i] || !*varnames[i] )
759 if( b_section_empty )
761 menu->addSeparator();
762 b_section_empty = VLC_TRUE;
766 if( objects[i] == 0 )
768 /// \bug What is this ?
769 // Append( menu, varnames[i], NULL );
770 b_section_empty = VLC_FALSE;
774 p_object = ( vlc_object_t * )vlc_object_get( p_intf, objects[i] );
775 if( p_object == NULL ) continue;
777 b_section_empty = VLC_FALSE;
778 /* Ugly specific stuff */
779 if( strstr( varnames[i], "intf-add" ) )
780 CreateItem( menu, varnames[i], p_object, false );
782 CreateItem( menu, varnames[i], p_object, true );
783 vlc_object_release( p_object );
786 /* Special case for empty menus */
787 if( menu->actions().size() == 0 || b_section_empty )
794 /*****************************************************************************
796 *****************************************************************************/
798 static bool IsMenuEmpty( const char *psz_var,
799 vlc_object_t *p_object,
802 vlc_value_t val, val_list;
803 int i_type, i_result, i;
805 /* Check the type of the object variable */
806 i_type = var_Type( p_object, psz_var );
808 /* Check if we want to display the variable */
809 if( !( i_type & VLC_VAR_HASCHOICE ) ) return false;
811 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
812 if( val.i_int == 0 ) return true;
814 if( ( i_type & VLC_VAR_TYPE ) != VLC_VAR_VARIABLE )
816 /* Very evil hack ! intf-switch can have only one value */
817 if( !strcmp( psz_var, "intf-switch" ) ) return false;
818 if( val.i_int == 1 && b_root ) return true;
822 /* Check children variables in case of VLC_VAR_VARIABLE */
823 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
828 for( i = 0, i_result = true; i < val_list.p_list->i_count; i++ )
830 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
838 /* clean up everything */
839 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
844 void QVLCMenu::CreateItem( QMenu *menu, const char *psz_var,
845 vlc_object_t *p_object, bool b_submenu )
847 vlc_value_t val, text;
850 /* Check the type of the object variable */
851 i_type = var_Type( p_object, psz_var );
853 switch( i_type & VLC_VAR_TYPE )
857 case VLC_VAR_VARIABLE:
859 case VLC_VAR_INTEGER:
863 /* Variable doesn't exist or isn't handled */
867 /* Make sure we want to display the variable */
868 if( IsMenuEmpty( psz_var, p_object ) ) return;
870 /* Get the descriptive name of the variable */
871 var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
873 if( i_type & VLC_VAR_HASCHOICE )
875 /* Append choices menu */
878 QMenu *submenu = new QMenu();
879 submenu->setTitle( qfu( text.psz_string ?
880 text.psz_string : psz_var ) );
881 if( CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0 )
882 menu->addMenu( submenu );
885 CreateChoicesMenu( menu, psz_var, p_object, true );
886 FREENULL( text.psz_string );
890 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
892 switch( i_type & VLC_VAR_TYPE )
895 var_Get( p_object, psz_var, &val );
896 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
897 p_object->i_object_id, val, i_type );
901 var_Get( p_object, psz_var, &val );
902 val.b_bool = !val.b_bool;
903 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
904 p_object->i_object_id, val, i_type, !val.b_bool );
907 FREENULL( text.psz_string );
911 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
912 vlc_object_t *p_object, bool b_root )
914 vlc_value_t val, val_list, text_list;
917 /* Check the type of the object variable */
918 i_type = var_Type( p_object, psz_var );
920 /* Make sure we want to display the variable */
921 if( IsMenuEmpty( psz_var, p_object, b_root ) ) return VLC_EGENERIC;
923 switch( i_type & VLC_VAR_TYPE )
927 case VLC_VAR_VARIABLE:
929 case VLC_VAR_INTEGER:
933 /* Variable doesn't exist or isn't handled */
937 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
938 &val_list, &text_list ) < 0 )
943 #define NORMAL_OR_RADIO i_type & VLC_VAR_ISCOMMAND ? ITEM_NORMAL: ITEM_RADIO
944 #define NOTCOMMAND !( i_type & VLC_VAR_ISCOMMAND )
945 #define CURVAL val_list.p_list->p_values[i]
946 #define CURTEXT text_list.p_list->p_values[i].psz_string
948 for( i = 0; i < val_list.p_list->i_count; i++ )
950 vlc_value_t another_val;
952 QMenu *subsubmenu = new QMenu();
954 switch( i_type & VLC_VAR_TYPE )
956 case VLC_VAR_VARIABLE:
957 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
958 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
959 submenu->addMenu( subsubmenu );
963 var_Get( p_object, psz_var, &val );
964 another_val.psz_string = strdup( CURVAL.psz_string );
965 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
966 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
967 p_object->i_object_id, another_val, i_type,
968 NOTCOMMAND && val.psz_string &&
969 !strcmp( val.psz_string, CURVAL.psz_string ) );
971 if( val.psz_string ) free( val.psz_string );
974 case VLC_VAR_INTEGER:
975 var_Get( p_object, psz_var, &val );
976 if( CURTEXT ) menutext = qfu( CURTEXT );
977 else menutext.sprintf( "%d", CURVAL.i_int );
978 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
979 p_object->i_object_id, CURVAL, i_type,
980 NOTCOMMAND && CURVAL.i_int == val.i_int );
984 var_Get( p_object, psz_var, &val );
985 if( CURTEXT ) menutext = qfu( CURTEXT );
986 else menutext.sprintf( "%.2f", CURVAL.f_float );
987 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
988 p_object->i_object_id, CURVAL, i_type,
989 NOTCOMMAND && CURVAL.f_float == val.f_float );
998 /* clean up everything */
999 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
1001 #undef NORMAL_OR_RADIO
1008 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
1009 QString text, QString help,
1010 int i_item_type, int i_object_id,
1011 vlc_value_t val, int i_val_type,
1014 QAction *action = new QAction( text, menu );
1015 action->setText( text );
1016 action->setToolTip( help );
1018 if( i_item_type == ITEM_CHECK )
1020 action->setCheckable( true );
1022 else if( i_item_type == ITEM_RADIO )
1024 action->setCheckable( true );
1026 currentGroup = new QActionGroup( menu );
1027 currentGroup->addAction( action );
1032 action->setChecked( true );
1034 MenuItemData *itemData = new MenuItemData( i_object_id, i_val_type,
1036 CONNECT( action, triggered(), THEDP->menusMapper, map() );
1037 THEDP->menusMapper->setMapping( action, itemData );
1038 menu->addAction( action );
1041 void QVLCMenu::DoAction( intf_thread_t *p_intf, QObject *data )
1043 MenuItemData *itemData = qobject_cast<MenuItemData *>( data );
1044 vlc_object_t *p_object = ( vlc_object_t * )vlc_object_get( p_intf,
1045 itemData->i_object_id );
1046 if( p_object == NULL ) return;
1048 var_Set( p_object, itemData->psz_var, itemData->val );
1049 vlc_object_release( p_object );