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 ), qtr( "&Tools" ) );
176 BAR_DADD( AudioMenu( p_intf, NULL ), qtr( "&Audio" ), 2 );
177 BAR_DADD( VideoMenu( p_intf, NULL ), qtr( "&Video" ), 1 );
178 BAR_DADD( NavigMenu( p_intf, NULL ), qtr( "&Playback" ), 3 );
180 BAR_ADD( HelpMenu(), qtr( "&Help" ) );
186 * Media ( File ) Menu
187 * Opening, streaming and quit
189 QMenu *QVLCMenu::FileMenu()
191 QMenu *menu = new QMenu();
193 addDPStaticEntry( menu, qtr( "&Open File..." ), "",
194 ":/pixmaps/file-asym_16px.png", SLOT( openFileDialog() ), "Ctrl+O" );
195 addDPStaticEntry( menu, qtr( I_OPEN_FOLDER ), "",
196 ":/pixmaps/folder-grey_16px.png", SLOT( PLAppendDir() ), "Ctrl+F" );
197 addDPStaticEntry( menu, qtr( "Open &Disc..." ), "",
198 ":/pixmaps/disc_16px.png", SLOT( openDiscDialog() ), "Ctrl+D" );
199 addDPStaticEntry( menu, qtr( "Open &Network..." ), "",
200 ":/pixmaps/network_16px.png", SLOT( openNetDialog() ), "Ctrl+N" );
201 addDPStaticEntry( menu, qtr( "Open &Capture Device..." ), "",
202 ":/pixmaps/capture-card_16px.png", SLOT( openCaptureDialog() ),
204 menu->addSeparator();
206 addDPStaticEntry( menu, qtr( "&Streaming..." ), "",
207 ":/pixmaps/menus_stream_16px.png", SLOT( openThenStreamingDialogs() ),
209 addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "", "",
210 SLOT( openThenTranscodingDialogs() ), "Ctrl+R" );
211 menu->addSeparator();
213 addDPStaticEntry( menu, qtr( "&Quit" ) , "",
214 ":/pixmaps/menus_quit_16px.png", SLOT( quit() ), "Ctrl+Q" );
218 /* Playlist/MediaLibrary Control */
219 QMenu *QVLCMenu::PlaylistMenu( intf_thread_t *p_intf, MainInterface *mi )
221 QMenu *menu = new QMenu();
222 menu->addMenu( SDMenu( p_intf ) );
223 menu->addAction( QIcon( ":/pixmaps/playlist_16px.png" ),
224 qtr( "Show Playlist" ), mi, SLOT( togglePlaylist() ) );
225 menu->addSeparator();
227 addDPStaticEntry( menu, qtr( I_PL_LOAD ), "", "", SLOT( openAPlaylist() ),
229 addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", "", SLOT( saveAPlaylist() ),
231 menu->addSeparator();
232 menu->addAction( qtr( "Undock from interface" ), mi,
233 SLOT( undockPlaylist() ), qtr( "Ctrl+U" ) );
239 * This is kept in the same menu for now, but could change if it gets much
241 * This menu can be an interface menu but also a right click menu.
243 QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf,
245 bool visual_selector_enabled,
248 QMenu *menu = new QMenu;
251 menu->addAction( QIcon( ":/pixmaps/playlist_16px.png" ),
252 qtr( "Playlist..." ), mi, SLOT( togglePlaylist() ),
255 addDPStaticEntry( menu, qtr( I_MENU_EXT ), "",
256 ":/pixmaps/menus_settings_16px.png", SLOT( extendedDialog() ),
259 menu->addSeparator();
263 QMenu *intfmenu = InterfacesMenu( p_intf, NULL );
264 intfmenu->setTitle( qtr( "Add Interfaces" ) );
265 menu->addMenu( intfmenu );
266 menu->addSeparator();
271 QAction *action=menu->addAction( qtr( "Minimal View..." ), mi,
272 SLOT( toggleMinimalView() ), qtr( "Ctrl+H" ) );
273 action->setCheckable( true );
274 if( mi->getControlsVisibilityStatus() & CONTROLS_VISIBLE )
275 action->setChecked( true );
277 /* FullScreen View */
278 action = menu->addAction( qtr( "Toggle Fullscreen Interface" ), mi,
279 SLOT( toggleFullScreen() ), qtr( "F11" ) );
281 /* Advanced Controls */
282 action = menu->addAction( qtr( "Advanced controls" ), mi,
283 SLOT( toggleAdvanced() ) );
284 action->setCheckable( true );
285 if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
286 action->setChecked( true );
287 #if 0 /* For Visualisations. Not yet working */
288 adv = menu->addAction( qtr( "Visualizations selector" ),
289 mi, SLOT( visual() ) );
290 adv->setCheckable( true );
291 if( visual_selector_enabled ) adv->setChecked( true );
295 menu->addSeparator();
297 addDPStaticEntry( menu, qtr( I_MENU_MSG ), "",
298 ":/pixmaps/menus_messages_16px.png", SLOT( messagesDialog() ),
300 addDPStaticEntry( menu, qtr( I_MENU_INFO ) , "", "",
301 SLOT( mediaInfoDialog() ), "Ctrl+I" );
302 addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) , "",
303 ":/pixmaps/menus_info_16px.png", SLOT( mediaCodecDialog() ), "Ctrl+J" );
304 addDPStaticEntry( menu, qtr( I_MENU_BOOKMARK ), "","",
305 SLOT( bookmarksDialog() ), "Ctrl+B" );
307 addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", "", SLOT( vlmDialog() ),
311 menu->addSeparator();
312 addDPStaticEntry( menu, qtr( "Preferences..." ), "",
313 ":/pixmaps/menus_preferences_16px.png", SLOT( prefsDialog() ), "Ctrl+P" );
318 * Interface Sub-Menu, to list extras interface and skins
320 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
323 vector<const char *> varnames;
324 /** \todo add "switch to XXX" */
325 varnames.push_back( "intf-add" );
326 objects.push_back( p_intf->i_object_id );
328 QMenu *menu = Populate( p_intf, current, varnames, objects );
330 if( !p_intf->pf_show_dialog )
332 menu->addSeparator();
333 menu->addAction( qtr( "Switch to skins" ), THEDP, SLOT( switchToSkins() ),
334 QString( "Ctrl+Z" ) );
337 CONNECT( menu, aboutToShow(), THEDP->menusUpdateMapper, map() );
338 THEDP->menusUpdateMapper->setMapping( menu, 4 );
345 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
348 vector<const char *> varnames;
350 vlc_object_t *p_object = ( vlc_object_t * )vlc_object_find( p_intf,
351 VLC_OBJECT_INPUT, FIND_ANYWHERE );
352 if( p_object != NULL )
354 PUSH_VAR( "audio-es" );
355 vlc_object_release( p_object );
358 p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_AOUT,
362 AudioAutoMenuBuilder( p_object, objects, varnames );
363 vlc_object_release( p_object );
365 return Populate( p_intf, current, varnames, objects );
370 * Subtitles are part of Video.
372 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
374 vlc_object_t *p_object;
376 vector<const char *> varnames;
378 p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_INPUT,
380 if( p_object != NULL )
382 PUSH_VAR( "video-es" );
383 PUSH_VAR( "spu-es" );
384 vlc_object_release( p_object );
387 p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_VOUT,
389 if( p_object != NULL )
391 VideoAutoMenuBuilder( p_object, objects, varnames );
392 vlc_object_release( p_object );
394 return Populate( p_intf, current, varnames, objects );
399 * For DVD, MP4, MOV and other chapter based format
401 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *navMenu )
403 vlc_object_t *p_object;
405 vector<const char *> varnames;
407 p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_INPUT,
409 if( p_object != NULL )
411 InputAutoMenuBuilder( p_object, objects, varnames );
412 PUSH_VAR( "prev-title" ); PUSH_VAR ( "next-title" );
413 PUSH_VAR( "prev-chapter" ); PUSH_VAR( "next-chapter" );
414 vlc_object_release( p_object );
416 navMenu = new QMenu();
417 addDPStaticEntry( navMenu, qtr( I_MENU_GOTOTIME ), "","",
418 SLOT( gotoTimeDialog() ), "Ctrl+T" );
419 navMenu->addSeparator();
420 return Populate( p_intf, navMenu, varnames, objects, true );
424 * Service Discovery SubMenu
426 QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf )
428 QMenu *menu = new QMenu();
429 menu->setTitle( qtr( I_PL_SD ) );
430 char **ppsz_longnames;
431 char **ppsz_names = services_discovery_GetServicesNames( p_intf,
433 char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
434 for( ; *ppsz_name; ppsz_name++, ppsz_longname++ )
436 QAction *a = new QAction( qfu( *ppsz_longname ), menu );
437 a->setCheckable( true );
438 if( playlist_IsServicesDiscoveryLoaded( THEPL, *ppsz_name ) )
439 a->setChecked( true );
440 CONNECT( a , triggered(), THEDP->SDMapper, map() );
441 THEDP->SDMapper->setMapping( a, QString( *ppsz_name ) );
442 menu->addAction( a );
444 if( !strcmp( *ppsz_name, "podcast" ) )
446 QAction *b = new QAction( qfu( "Configure podcasts..." ), menu );
447 //b->setEnabled( a->isChecked() );
448 menu->addAction( b );
449 CONNECT( b, triggered(), THEDP, podcastConfigureDialog() );
452 free( *ppsz_longname );
455 free( ppsz_longnames );
461 QMenu *QVLCMenu::HelpMenu()
463 QMenu *menu = new QMenu();
464 addDPStaticEntry( menu, qtr( "Help..." ) , "",
465 ":/pixmaps/menus_help_16px.png", SLOT( helpDialog() ), "F1" );
467 addDPStaticEntry( menu, qtr( "Update" ) , "", "", SLOT( updateDialog() ), "");
469 menu->addSeparator();
470 addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), "", "", SLOT( aboutDialog() ),
476 /*****************************************************************************
477 * Popup menus - Right Click menus *
478 *****************************************************************************/
479 #define POPUP_BOILERPLATE \
480 unsigned int i_last_separator = 0; \
481 vector<int> objects; \
482 vector<const char *> varnames; \
483 input_thread_t *p_input = THEMIM->getInput();
485 #define CREATE_POPUP \
486 Populate( p_intf, menu, varnames, objects ); \
487 p_intf->p_sys->p_popup_menu = menu; \
488 menu->popup( QCursor::pos() ); \
489 p_intf->p_sys->p_popup_menu = NULL; \
490 i_last_separator = 0;
492 void QVLCMenu::PopupMenuControlEntries( QMenu *menu,
493 intf_thread_t *p_intf,
494 input_thread_t *p_input )
499 var_Get( p_input, "state", &val );
500 if( val.i_int == PLAYING_S )
501 addMIMStaticEntry( p_intf, menu, qtr( "Pause" ), "",
502 ":/pixmaps/pause_16px.png", SLOT( togglePlayPause() ) );
504 addMIMStaticEntry( p_intf, menu, qtr( "Play" ), "",
505 ":/pixmaps/play_16px.png", SLOT( togglePlayPause() ) );
507 else if( THEPL->items.i_size && THEPL->i_enabled )
508 addMIMStaticEntry( p_intf, menu, qtr( "Play" ), "",
509 ":/pixmaps/play_16px.png", SLOT( togglePlayPause() ) );
511 addMIMStaticEntry( p_intf, menu, qtr( "Stop" ), "",
512 ":/pixmaps/stop_16px.png", SLOT( stop() ) );
513 addMIMStaticEntry( p_intf, menu, qtr( "Previous" ), "",
514 ":/pixmaps/previous_16px.png", SLOT( prev() ) );
515 addMIMStaticEntry( p_intf, menu, qtr( "Next" ), "",
516 ":/pixmaps/next_16px.png", SLOT( next() ) );
519 void QVLCMenu::PopupMenuStaticEntries( intf_thread_t *p_intf, QMenu *menu )
521 QMenu *toolsmenu = ToolsMenu( p_intf, NULL, false, true );
522 toolsmenu->setTitle( qtr( "Tools" ) );
523 menu->addMenu( toolsmenu );
525 QMenu *openmenu = new QMenu( qtr( "Open" ) );
526 openmenu->addAction( qtr( "Open &File..." ), THEDP,
527 SLOT( openFileDialog() ) );
528 openmenu->addAction( qtr( "Open &Disc..." ), THEDP,
529 SLOT( openDiscDialog() ) );
530 openmenu->addAction( qtr( "Open &Network..." ), THEDP,
531 SLOT( openNetDialog() ) );
532 openmenu->addAction( qtr( "Open &Capture Device..." ), THEDP,
533 SLOT( openCaptureDialog() ) );
534 menu->addMenu( openmenu );
536 menu->addSeparator();
537 QMenu *helpmenu = HelpMenu();
538 helpmenu->setTitle( qtr( "Help" ) );
539 menu->addMenu( helpmenu );
541 addDPStaticEntry( menu, qtr( "Quit" ), "", "", SLOT( quit() ) , "Ctrl+Q" );
544 /* Video Tracks and Subtitles tracks */
545 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
550 vlc_object_yield( p_input );
551 varnames.push_back( "video-es" );
552 objects.push_back( p_input->i_object_id );
553 varnames.push_back( "spu-es" );
554 objects.push_back( p_input->i_object_id );
555 vlc_object_t *p_vout = ( vlc_object_t * )vlc_object_find( p_input,
556 VLC_OBJECT_VOUT, FIND_CHILD );
559 VideoAutoMenuBuilder( p_vout, objects, varnames );
560 vlc_object_release( p_vout );
562 vlc_object_release( p_input );
564 QMenu *menu = new QMenu();
569 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
574 vlc_object_yield( p_input );
575 varnames.push_back( "audio-es" );
576 objects.push_back( p_input->i_object_id );
577 vlc_object_t *p_aout = ( vlc_object_t * )vlc_object_find( p_input,
578 VLC_OBJECT_AOUT, FIND_ANYWHERE );
581 AudioAutoMenuBuilder( p_aout, objects, varnames );
582 vlc_object_release( p_aout );
584 vlc_object_release( p_input );
586 QMenu *menu = new QMenu();
590 /* Navigation stuff, and general menus ( open ) */
591 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
598 vlc_object_yield( p_input );
599 varnames.push_back( "audio-es" );
600 InputAutoMenuBuilder( VLC_OBJECT( p_input ), objects, varnames );
604 QMenu *menu = new QMenu();
605 Populate( p_intf, menu, varnames, objects );
607 menu->addSeparator();
608 PopupMenuControlEntries( menu, p_intf, p_input );
610 menu->addSeparator();
611 PopupMenuStaticEntries( p_intf, menu );
613 p_intf->p_sys->p_popup_menu = menu;
614 menu->popup( QCursor::pos() );
615 p_intf->p_sys->p_popup_menu = NULL;
618 /* Main Menu that sticks everything together */
619 void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
623 // create a popup if there is none
624 if( ! p_intf->p_sys->p_popup_menu )
629 vlc_object_yield( p_input );
630 InputAutoMenuBuilder( VLC_OBJECT( p_input ), objects, varnames );
634 varnames.push_back( "audio-es" );
635 objects.push_back( p_input->i_object_id );
636 vlc_object_t *p_aout = ( vlc_object_t * )
637 vlc_object_find( p_input, VLC_OBJECT_AOUT, FIND_ANYWHERE );
640 AudioAutoMenuBuilder( p_aout, objects, varnames );
641 vlc_object_release( p_aout );
646 varnames.push_back( "video-es" );
647 objects.push_back( p_input->i_object_id );
648 varnames.push_back( "spu-es" );
649 objects.push_back( p_input->i_object_id );
650 vlc_object_t *p_vout = ( vlc_object_t * )
651 vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD );
654 VideoAutoMenuBuilder( p_vout, objects, varnames );
655 vlc_object_release( p_vout );
659 QMenu *menu = new QMenu();
660 Populate( p_intf, menu, varnames, objects );
661 menu->addSeparator();
662 PopupMenuControlEntries( menu, p_intf, p_input );
663 menu->addSeparator();
664 PopupMenuStaticEntries( p_intf, menu );
666 p_intf->p_sys->p_popup_menu = menu;
668 p_intf->p_sys->p_popup_menu->popup( QCursor::pos() );
672 // destroy popup if there is one
673 delete p_intf->p_sys->p_popup_menu;
674 p_intf->p_sys->p_popup_menu = NULL;
678 /************************************************************************
680 ************************************************************************/
682 void QVLCMenu::updateSystrayMenu( MainInterface *mi,
683 intf_thread_t *p_intf,
684 bool b_force_visible )
688 /* Get the systray menu and clean it */
689 QMenu *sysMenu = mi->getSysTrayMenu();
692 /* Hide / Show VLC and cone */
693 if( mi->isVisible() || b_force_visible )
695 sysMenu->addAction( QIcon( ":/vlc16.png" ),
696 qtr( "Hide VLC media player in taskbar" ), mi,
697 SLOT( toggleUpdateSystrayMenu() ) );
701 sysMenu->addAction( QIcon( ":/vlc16.png" ),
702 qtr( "Show VLC media player" ), mi,
703 SLOT( toggleUpdateSystrayMenu() ) );
706 sysMenu->addSeparator();
707 PopupMenuControlEntries( sysMenu, p_intf, p_input );
709 sysMenu->addSeparator();
710 addDPStaticEntry( sysMenu, qtr( "&Open Media" ), "",
711 ":/pixmaps/file-wide_16px.png", SLOT( openFileDialog() ), "" );
712 addDPStaticEntry( sysMenu, qtr( "&Quit" ) , "",
713 ":/pixmaps/menus_quit_16px.png", SLOT( quit() ), "" );
716 mi->getSysTray()->setContextMenu( sysMenu );
720 #undef PUSH_SEPARATOR
723 /*************************************************************************
724 * Builders for automenus
725 *************************************************************************/
726 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf,
728 vector< const char *> & varnames,
729 vector<int> & objects,
732 QMenu *menu = current;
740 vlc_object_t *p_object;
741 vlc_bool_t b_section_empty = VLC_FALSE;
744 #define APPEND_EMPTY { QAction *action = menu->addAction( qtr( "Empty" ) ); \
745 action->setEnabled( false ); }
747 for( i = 0; i < ( int )objects.size() ; i++ )
749 if( !varnames[i] || !*varnames[i] )
751 if( b_section_empty )
753 menu->addSeparator();
754 b_section_empty = VLC_TRUE;
758 if( objects[i] == 0 )
760 /// \bug What is this ?
761 // Append( menu, varnames[i], NULL );
762 b_section_empty = VLC_FALSE;
766 p_object = ( vlc_object_t * )vlc_object_get( p_intf, objects[i] );
767 if( p_object == NULL ) continue;
769 b_section_empty = VLC_FALSE;
770 /* Ugly specific stuff */
771 if( strstr( varnames[i], "intf-add" ) )
772 CreateItem( menu, varnames[i], p_object, false );
774 CreateItem( menu, varnames[i], p_object, true );
775 vlc_object_release( p_object );
778 /* Special case for empty menus */
779 if( menu->actions().size() == 0 || b_section_empty )
786 /*****************************************************************************
788 *****************************************************************************/
790 static bool IsMenuEmpty( const char *psz_var,
791 vlc_object_t *p_object,
794 vlc_value_t val, val_list;
795 int i_type, i_result, i;
797 /* Check the type of the object variable */
798 i_type = var_Type( p_object, psz_var );
800 /* Check if we want to display the variable */
801 if( !( i_type & VLC_VAR_HASCHOICE ) ) return false;
803 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
804 if( val.i_int == 0 ) return true;
806 if( ( i_type & VLC_VAR_TYPE ) != VLC_VAR_VARIABLE )
808 /* Very evil hack ! intf-switch can have only one value */
809 if( !strcmp( psz_var, "intf-switch" ) ) return false;
810 if( val.i_int == 1 && b_root ) return true;
814 /* Check children variables in case of VLC_VAR_VARIABLE */
815 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
820 for( i = 0, i_result = true; i < val_list.p_list->i_count; i++ )
822 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
830 /* clean up everything */
831 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
836 void QVLCMenu::CreateItem( QMenu *menu, const char *psz_var,
837 vlc_object_t *p_object, bool b_submenu )
839 vlc_value_t val, text;
842 /* Check the type of the object variable */
843 i_type = var_Type( p_object, psz_var );
845 switch( i_type & VLC_VAR_TYPE )
849 case VLC_VAR_VARIABLE:
851 case VLC_VAR_INTEGER:
855 /* Variable doesn't exist or isn't handled */
859 /* Make sure we want to display the variable */
860 if( IsMenuEmpty( psz_var, p_object ) ) return;
862 /* Get the descriptive name of the variable */
863 var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
865 if( i_type & VLC_VAR_HASCHOICE )
867 /* Append choices menu */
870 QMenu *submenu = new QMenu();
871 submenu->setTitle( qfu( text.psz_string ?
872 text.psz_string : psz_var ) );
873 if( CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0 )
874 menu->addMenu( submenu );
877 CreateChoicesMenu( menu, psz_var, p_object, true );
878 FREENULL( text.psz_string );
882 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
884 switch( i_type & VLC_VAR_TYPE )
887 var_Get( p_object, psz_var, &val );
888 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
889 p_object->i_object_id, val, i_type );
893 var_Get( p_object, psz_var, &val );
894 val.b_bool = !val.b_bool;
895 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
896 p_object->i_object_id, val, i_type, !val.b_bool );
899 FREENULL( text.psz_string );
903 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
904 vlc_object_t *p_object, bool b_root )
906 vlc_value_t val, val_list, text_list;
909 /* Check the type of the object variable */
910 i_type = var_Type( p_object, psz_var );
912 /* Make sure we want to display the variable */
913 if( IsMenuEmpty( psz_var, p_object, b_root ) ) return VLC_EGENERIC;
915 switch( i_type & VLC_VAR_TYPE )
919 case VLC_VAR_VARIABLE:
921 case VLC_VAR_INTEGER:
925 /* Variable doesn't exist or isn't handled */
929 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
930 &val_list, &text_list ) < 0 )
935 #define NORMAL_OR_RADIO i_type & VLC_VAR_ISCOMMAND ? ITEM_NORMAL: ITEM_RADIO
936 #define NOTCOMMAND !( i_type & VLC_VAR_ISCOMMAND )
937 #define CURVAL val_list.p_list->p_values[i]
938 #define CURTEXT text_list.p_list->p_values[i].psz_string
940 for( i = 0; i < val_list.p_list->i_count; i++ )
942 vlc_value_t another_val;
944 QMenu *subsubmenu = new QMenu();
946 switch( i_type & VLC_VAR_TYPE )
948 case VLC_VAR_VARIABLE:
949 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
950 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
951 submenu->addMenu( subsubmenu );
955 var_Get( p_object, psz_var, &val );
956 another_val.psz_string = strdup( CURVAL.psz_string );
957 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
958 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
959 p_object->i_object_id, another_val, i_type,
960 NOTCOMMAND && val.psz_string &&
961 !strcmp( val.psz_string, CURVAL.psz_string ) );
963 if( val.psz_string ) free( val.psz_string );
966 case VLC_VAR_INTEGER:
967 var_Get( p_object, psz_var, &val );
968 if( CURTEXT ) menutext = qfu( CURTEXT );
969 else menutext.sprintf( "%d", CURVAL.i_int );
970 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
971 p_object->i_object_id, CURVAL, i_type,
972 NOTCOMMAND && CURVAL.i_int == val.i_int );
976 var_Get( p_object, psz_var, &val );
977 if( CURTEXT ) menutext = qfu( CURTEXT );
978 else menutext.sprintf( "%.2f", CURVAL.f_float );
979 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
980 p_object->i_object_id, CURVAL, i_type,
981 NOTCOMMAND && CURVAL.f_float == val.f_float );
990 /* clean up everything */
991 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
993 #undef NORMAL_OR_RADIO
1000 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
1001 QString text, QString help,
1002 int i_item_type, int i_object_id,
1003 vlc_value_t val, int i_val_type,
1006 QAction *action = new QAction( text, menu );
1007 action->setText( text );
1008 action->setToolTip( help );
1010 if( i_item_type == ITEM_CHECK )
1012 action->setCheckable( true );
1014 else if( i_item_type == ITEM_RADIO )
1016 action->setCheckable( true );
1018 currentGroup = new QActionGroup( menu );
1019 currentGroup->addAction( action );
1024 action->setChecked( true );
1026 MenuItemData *itemData = new MenuItemData( i_object_id, i_val_type,
1028 CONNECT( action, triggered(), THEDP->menusMapper, map() );
1029 THEDP->menusMapper->setMapping( action, itemData );
1030 menu->addAction( action );
1033 void QVLCMenu::DoAction( intf_thread_t *p_intf, QObject *data )
1035 MenuItemData *itemData = qobject_cast<MenuItemData *>( data );
1036 vlc_object_t *p_object = ( vlc_object_t * )vlc_object_get( p_intf,
1037 itemData->i_object_id );
1038 if( p_object == NULL ) return;
1040 var_Set( p_object, itemData->psz_var, itemData->val );
1041 vlc_object_release( p_object );