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 *****************************************************************************/
31 #include <vlc_intf_strings.h>
33 #include "main_interface.hpp"
35 #include "dialogs_provider.hpp"
36 #include "input_manager.hpp"
41 #include <QActionGroup>
42 #include <QSignalMapper>
43 #include <QSystemTrayIcon>
52 static QActionGroup *currentGroup;
54 // Add static entries to menus
55 void addDPStaticEntry( QMenu *menu,
60 const char *shortcut )
62 if( !EMPTY_STR( icon ) > 0 )
64 if( !EMPTY_STR( shortcut ) > 0 )
65 menu->addAction( QIcon( icon ), text, THEDP, member, qtr( shortcut ) );
67 menu->addAction( QIcon( icon ), text, THEDP, member );
71 if( !EMPTY_STR( shortcut ) > 0 )
72 menu->addAction( text, THEDP, member, qtr( shortcut ) );
74 menu->addAction( text, THEDP, member );
78 void addMIMStaticEntry( intf_thread_t *p_intf,
85 if( strlen( icon ) > 0 )
87 QAction *action = menu->addAction( text, THEMIM, member );
88 action->setIcon( QIcon( icon ) );
92 menu->addAction( text, THEMIM, member );
96 /*****************************************************************************
97 * Definitions of variables for the dynamic menus
98 *****************************************************************************/
99 #define PUSH_VAR( var ) varnames.push_back( var ); \
100 objects.push_back( p_object->i_object_id )
102 #define PUSH_SEPARATOR if( objects.size() != i_last_separator ) { \
103 objects.push_back( 0 ); varnames.push_back( "" ); \
104 i_last_separator = objects.size(); }
106 static int InputAutoMenuBuilder( vlc_object_t *p_object,
107 vector<int> &objects,
108 vector<const char *> &varnames )
110 PUSH_VAR( "bookmark" );
112 PUSH_VAR( "chapter" );
113 PUSH_VAR( "program" );
114 PUSH_VAR( "navigation" );
115 PUSH_VAR( "dvd_menus" );
119 static int VideoAutoMenuBuilder( vlc_object_t *p_object,
120 vector<int> &objects,
121 vector<const char *> &varnames )
123 PUSH_VAR( "fullscreen" );
125 PUSH_VAR( "deinterlace" );
126 PUSH_VAR( "aspect-ratio" );
128 PUSH_VAR( "video-on-top" );
129 PUSH_VAR( "directx-wallpaper" );
130 PUSH_VAR( "video-snapshot" );
132 vlc_object_t *p_dec_obj = ( vlc_object_t * )vlc_object_find( p_object,
135 if( p_dec_obj != NULL )
137 vlc_object_t *p_object = p_dec_obj;
138 PUSH_VAR( "ffmpeg-pp-q" );
139 vlc_object_release( p_dec_obj );
144 static int AudioAutoMenuBuilder( vlc_object_t *p_object,
145 vector<int> &objects,
146 vector<const char *> &varnames )
148 PUSH_VAR( "audio-device" );
149 PUSH_VAR( "audio-channels" );
150 PUSH_VAR( "visual" );
151 PUSH_VAR( "equalizer" );
155 /*****************************************************************************
158 *****************************************************************************/
160 #define BAR_ADD( func, title ) { \
161 QMenu *menu = func; menu->setTitle( title ); bar->addMenu( menu ); }
163 #define BAR_DADD( func, title, id ) { \
164 QMenu *menu = func; menu->setTitle( title ); bar->addMenu( menu ); \
165 MenuFunc *f = new MenuFunc( menu, id ); \
166 CONNECT( menu, aboutToShow(), THEDP->menusUpdateMapper, map() ); \
167 THEDP->menusUpdateMapper->setMapping( menu, f ); }
170 * Main Menu Bar Creation
172 void QVLCMenu::createMenuBar( MainInterface *mi,
173 intf_thread_t *p_intf,
174 bool visual_selector_enabled )
176 QMenuBar *bar = mi->menuBar();
177 BAR_ADD( FileMenu(), qtr( "&Media" ) );
178 BAR_ADD( PlaylistMenu( p_intf, mi ), qtr( "&Playlist" ) );
179 BAR_ADD( ToolsMenu( p_intf, mi, visual_selector_enabled, true ),
181 BAR_DADD( AudioMenu( p_intf, NULL ), qtr( "&Audio" ), 2 );
182 BAR_DADD( VideoMenu( p_intf, NULL ), qtr( "&Video" ), 1 );
183 BAR_DADD( NavigMenu( p_intf, NULL ), qtr( "&Playback" ), 3 );
185 BAR_ADD( HelpMenu(), qtr( "&Help" ) );
191 * Media ( File ) Menu
192 * Opening, streaming and quit
194 QMenu *QVLCMenu::FileMenu()
196 QMenu *menu = new QMenu();
198 addDPStaticEntry( menu, qtr( "&Open File..." ), "",
199 ":/pixmaps/file-asym_16px.png", SLOT( openFileDialog() ), "Ctrl+O" );
200 addDPStaticEntry( menu, qtr( I_OPEN_FOLDER ), "",
201 ":/pixmaps/folder-grey_16px.png", SLOT( PLAppendDir() ), "Ctrl+F" );
202 addDPStaticEntry( menu, qtr( "Open &Disc..." ), "",
203 ":/pixmaps/disc_16px.png", SLOT( openDiscDialog() ), "Ctrl+D" );
204 addDPStaticEntry( menu, qtr( "Open &Network..." ), "",
205 ":/pixmaps/network_16px.png", SLOT( openNetDialog() ), "Ctrl+N" );
206 addDPStaticEntry( menu, qtr( "Open &Capture Device..." ), "",
207 ":/pixmaps/capture-card_16px.png", SLOT( openCaptureDialog() ),
209 menu->addSeparator();
211 addDPStaticEntry( menu, qtr( "&Streaming..." ), "",
212 ":/pixmaps/menus_stream_16px.png", SLOT( openThenStreamingDialogs() ),
214 addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "", "",
215 SLOT( openThenTranscodingDialogs() ), "Ctrl+R" );
216 menu->addSeparator();
218 addDPStaticEntry( menu, qtr( "&Quit" ) , "",
219 ":/pixmaps/menus_quit_16px.png", SLOT( quit() ), "Ctrl+Q" );
223 /* Playlist/MediaLibrary Control */
224 QMenu *QVLCMenu::PlaylistMenu( intf_thread_t *p_intf, MainInterface *mi )
226 QMenu *menu = new QMenu();
227 menu->addMenu( SDMenu( p_intf ) );
228 menu->addAction( QIcon( ":/pixmaps/playlist_16px.png" ),
229 qtr( "Show Playlist" ), mi, SLOT( togglePlaylist() ) );
230 menu->addSeparator();
232 addDPStaticEntry( menu, qtr( I_PL_LOAD ), "", "", SLOT( openAPlaylist() ),
234 addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", "", SLOT( saveAPlaylist() ),
236 menu->addSeparator();
237 menu->addAction( qtr( "Undock from interface" ), mi,
238 SLOT( undockPlaylist() ), qtr( "Ctrl+U" ) );
244 * This is kept in the same menu for now, but could change if it gets much
246 * This menu can be an interface menu but also a right click menu.
248 QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf,
250 bool visual_selector_enabled,
253 QMenu *menu = new QMenu;
256 menu->addAction( QIcon( ":/pixmaps/playlist_16px.png" ),
257 qtr( "Playlist..." ), mi, SLOT( togglePlaylist() ),
260 addDPStaticEntry( menu, qtr( I_MENU_EXT ), "",
261 ":/pixmaps/menus_settings_16px.png", SLOT( extendedDialog() ),
264 menu->addSeparator();
268 QMenu *intfmenu = InterfacesMenu( p_intf, NULL );
269 intfmenu->setTitle( qtr( "Interfaces" ) );
270 menu->addMenu( intfmenu );
271 menu->addSeparator();
276 QAction *action=menu->addAction( qtr( "Minimal View..." ), mi,
277 SLOT( toggleMinimalView() ), qtr( "Ctrl+H" ) );
278 action->setCheckable( true );
279 if( mi->getControlsVisibilityStatus() & CONTROLS_VISIBLE )
280 action->setChecked( true );
282 /* FullScreen View */
283 action = menu->addAction( qtr( "Toggle Fullscreen Interface" ), mi,
284 SLOT( toggleFullScreen() ), qtr( "F11" ) );
286 /* Advanced Controls */
287 action = menu->addAction( qtr( "Advanced controls" ), mi,
288 SLOT( toggleAdvanced() ) );
289 action->setCheckable( true );
290 if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
291 action->setChecked( true );
292 #if 0 /* For Visualisations. Not yet working */
293 adv = menu->addAction( qtr( "Visualizations selector" ),
294 mi, SLOT( visual() ) );
295 adv->setCheckable( true );
296 if( visual_selector_enabled ) adv->setChecked( true );
300 menu->addSeparator();
302 addDPStaticEntry( menu, qtr( I_MENU_MSG ), "",
303 ":/pixmaps/menus_messages_16px.png", SLOT( messagesDialog() ),
305 addDPStaticEntry( menu, qtr( I_MENU_INFO ) , "", "",
306 SLOT( mediaInfoDialog() ), "Ctrl+I" );
307 addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) , "",
308 ":/pixmaps/menus_info_16px.png", SLOT( mediaCodecDialog() ), "Ctrl+J" );
309 addDPStaticEntry( menu, qtr( I_MENU_BOOKMARK ), "","",
310 SLOT( bookmarksDialog() ), "Ctrl+B" );
312 addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", "", SLOT( vlmDialog() ),
316 menu->addSeparator();
317 addDPStaticEntry( menu, qtr( "Preferences..." ), "",
318 ":/pixmaps/menus_preferences_16px.png", SLOT( prefsDialog() ), "Ctrl+P" );
323 * Interface Sub-Menu, to list extras interface and skins
325 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
328 vector<const char *> varnames;
329 /** \todo add "switch to XXX" */
330 varnames.push_back( "intf-add" );
331 objects.push_back( p_intf->i_object_id );
333 QMenu *menu = Populate( p_intf, current, varnames, objects );
335 CONNECT( menu, aboutToShow(), THEDP->menusUpdateMapper, map() );
336 THEDP->menusUpdateMapper->setMapping( menu, 4 );
343 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
346 vector<const char *> varnames;
348 vlc_object_t *p_object = ( vlc_object_t * )vlc_object_find( p_intf,
349 VLC_OBJECT_INPUT, FIND_ANYWHERE );
350 if( p_object != NULL )
352 PUSH_VAR( "audio-es" );
353 vlc_object_release( p_object );
356 p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_AOUT,
360 AudioAutoMenuBuilder( p_object, objects, varnames );
361 vlc_object_release( p_object );
363 return Populate( p_intf, current, varnames, objects );
368 * Subtitles are part of Video.
370 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
372 vlc_object_t *p_object;
374 vector<const char *> varnames;
376 p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_INPUT,
378 if( p_object != NULL )
380 PUSH_VAR( "video-es" );
381 PUSH_VAR( "spu-es" );
382 vlc_object_release( p_object );
385 p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_VOUT,
387 if( p_object != NULL )
389 VideoAutoMenuBuilder( p_object, objects, varnames );
390 vlc_object_release( p_object );
392 return Populate( p_intf, current, varnames, objects );
397 * For DVD, MP4, MOV and other chapter based format
399 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *navMenu )
401 vlc_object_t *p_object;
403 vector<const char *> varnames;
405 p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_INPUT,
407 if( p_object != NULL )
409 InputAutoMenuBuilder( p_object, objects, varnames );
410 PUSH_VAR( "prev-title" ); PUSH_VAR ( "next-title" );
411 PUSH_VAR( "prev-chapter" ); PUSH_VAR( "next-chapter" );
412 vlc_object_release( p_object );
414 navMenu = new QMenu();
415 addDPStaticEntry( navMenu, qtr( I_MENU_GOTOTIME ), "","",
416 SLOT( gotoTimeDialog() ), "Ctrl+T" );
417 navMenu->addSeparator();
418 return Populate( p_intf, navMenu, varnames, objects, true );
422 * Service Discovery SubMenu
424 QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf )
426 QMenu *menu = new QMenu();
427 menu->setTitle( qtr( I_PL_SD ) );
428 char **ppsz_longnames;
429 char **ppsz_names = services_discovery_GetServicesNames( p_intf,
434 char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
435 for( ; *ppsz_name; ppsz_name++, ppsz_longname++ )
437 QAction *a = new QAction( qfu( *ppsz_longname ), menu );
438 a->setCheckable( true );
439 if( playlist_IsServicesDiscoveryLoaded( THEPL, *ppsz_name ) )
440 a->setChecked( true );
441 CONNECT( a , triggered(), THEDP->SDMapper, map() );
442 THEDP->SDMapper->setMapping( a, QString( *ppsz_name ) );
443 menu->addAction( a );
445 if( !strcmp( *ppsz_name, "podcast" ) )
447 QAction *b = new QAction( qfu( "Configure podcasts..." ), menu );
448 //b->setEnabled( a->isChecked() );
449 menu->addAction( b );
450 CONNECT( b, triggered(), THEDP, podcastConfigureDialog() );
453 free( *ppsz_longname );
456 free( ppsz_longnames );
462 QMenu *QVLCMenu::HelpMenu()
464 QMenu *menu = new QMenu();
465 addDPStaticEntry( menu, qtr( "Help..." ) , "",
466 ":/pixmaps/menus_help_16px.png", SLOT( helpDialog() ), "F1" );
468 addDPStaticEntry( menu, qtr( "Check for updates..." ) , "", "", SLOT( updateDialog() ), "");
470 menu->addSeparator();
471 addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), "", "", SLOT( aboutDialog() ),
477 /*****************************************************************************
478 * Popup menus - Right Click menus *
479 *****************************************************************************/
480 #define POPUP_BOILERPLATE \
481 unsigned int i_last_separator = 0; \
482 vector<int> objects; \
483 vector<const char *> varnames; \
484 input_thread_t *p_input = THEMIM->getInput();
486 #define CREATE_POPUP \
487 Populate( p_intf, menu, varnames, objects ); \
488 p_intf->p_sys->p_popup_menu = menu; \
489 menu->popup( QCursor::pos() ); \
490 p_intf->p_sys->p_popup_menu = NULL; \
491 i_last_separator = 0;
493 void QVLCMenu::PopupMenuControlEntries( QMenu *menu,
494 intf_thread_t *p_intf,
495 input_thread_t *p_input )
500 var_Get( p_input, "state", &val );
501 if( val.i_int == PLAYING_S )
502 addMIMStaticEntry( p_intf, menu, qtr( "Pause" ), "",
503 ":/pixmaps/pause_16px.png", SLOT( togglePlayPause() ) );
505 addMIMStaticEntry( p_intf, menu, qtr( "Play" ), "",
506 ":/pixmaps/play_16px.png", SLOT( togglePlayPause() ) );
508 else if( THEPL->items.i_size && THEPL->i_enabled )
509 addMIMStaticEntry( p_intf, menu, qtr( "Play" ), "",
510 ":/pixmaps/play_16px.png", SLOT( togglePlayPause() ) );
512 addMIMStaticEntry( p_intf, menu, qtr( "Stop" ), "",
513 ":/pixmaps/stop_16px.png", SLOT( stop() ) );
514 addMIMStaticEntry( p_intf, menu, qtr( "Previous" ), "",
515 ":/pixmaps/previous_16px.png", SLOT( prev() ) );
516 addMIMStaticEntry( p_intf, menu, qtr( "Next" ), "",
517 ":/pixmaps/next_16px.png", SLOT( next() ) );
520 void QVLCMenu::PopupMenuStaticEntries( intf_thread_t *p_intf, QMenu *menu )
522 QMenu *toolsmenu = ToolsMenu( p_intf, NULL, false, true );
523 toolsmenu->setTitle( qtr( "Tools" ) );
524 menu->addMenu( toolsmenu );
526 QMenu *openmenu = new QMenu( qtr( "Open" ) );
527 openmenu->addAction( qtr( "Open &File..." ), THEDP,
528 SLOT( openFileDialog() ) );
529 openmenu->addAction( qtr( "Open &Disc..." ), THEDP,
530 SLOT( openDiscDialog() ) );
531 openmenu->addAction( qtr( "Open &Network..." ), THEDP,
532 SLOT( openNetDialog() ) );
533 openmenu->addAction( qtr( "Open &Capture Device..." ), THEDP,
534 SLOT( openCaptureDialog() ) );
535 menu->addMenu( openmenu );
537 menu->addSeparator();
538 QMenu *helpmenu = HelpMenu();
539 helpmenu->setTitle( qtr( "Help" ) );
540 menu->addMenu( helpmenu );
542 addDPStaticEntry( menu, qtr( "Quit" ), "", "", SLOT( quit() ) , "Ctrl+Q" );
545 /* Video Tracks and Subtitles tracks */
546 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
551 vlc_object_yield( p_input );
552 varnames.push_back( "video-es" );
553 objects.push_back( p_input->i_object_id );
554 varnames.push_back( "spu-es" );
555 objects.push_back( p_input->i_object_id );
556 vlc_object_t *p_vout = ( vlc_object_t * )vlc_object_find( p_input,
557 VLC_OBJECT_VOUT, FIND_CHILD );
560 VideoAutoMenuBuilder( p_vout, objects, varnames );
561 vlc_object_release( p_vout );
563 vlc_object_release( p_input );
565 QMenu *menu = new QMenu();
570 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
575 vlc_object_yield( p_input );
576 varnames.push_back( "audio-es" );
577 objects.push_back( p_input->i_object_id );
578 vlc_object_t *p_aout = ( vlc_object_t * )vlc_object_find( p_input,
579 VLC_OBJECT_AOUT, FIND_ANYWHERE );
582 AudioAutoMenuBuilder( p_aout, objects, varnames );
583 vlc_object_release( p_aout );
585 vlc_object_release( p_input );
587 QMenu *menu = new QMenu();
591 /* Navigation stuff, and general menus ( open ) */
592 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
599 vlc_object_yield( p_input );
600 varnames.push_back( "audio-es" );
601 InputAutoMenuBuilder( VLC_OBJECT( p_input ), objects, varnames );
605 QMenu *menu = new QMenu();
606 Populate( p_intf, menu, varnames, objects );
608 menu->addSeparator();
609 PopupMenuControlEntries( menu, p_intf, p_input );
611 menu->addSeparator();
612 PopupMenuStaticEntries( p_intf, menu );
614 p_intf->p_sys->p_popup_menu = menu;
615 menu->popup( QCursor::pos() );
616 p_intf->p_sys->p_popup_menu = NULL;
619 /* Main Menu that sticks everything together */
620 void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
624 // create a popup if there is none
625 if( ! p_intf->p_sys->p_popup_menu )
630 vlc_object_yield( p_input );
631 InputAutoMenuBuilder( VLC_OBJECT( p_input ), objects, varnames );
635 varnames.push_back( "audio-es" );
636 objects.push_back( p_input->i_object_id );
637 vlc_object_t *p_aout = ( vlc_object_t * )
638 vlc_object_find( p_input, VLC_OBJECT_AOUT, FIND_ANYWHERE );
641 AudioAutoMenuBuilder( p_aout, objects, varnames );
642 vlc_object_release( p_aout );
647 varnames.push_back( "video-es" );
648 objects.push_back( p_input->i_object_id );
649 varnames.push_back( "spu-es" );
650 objects.push_back( p_input->i_object_id );
651 vlc_object_t *p_vout = ( vlc_object_t * )
652 vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD );
655 VideoAutoMenuBuilder( p_vout, objects, varnames );
656 vlc_object_release( p_vout );
660 QMenu *menu = new QMenu();
661 Populate( p_intf, menu, varnames, objects );
662 menu->addSeparator();
663 PopupMenuControlEntries( menu, p_intf, p_input );
664 menu->addSeparator();
665 PopupMenuStaticEntries( p_intf, menu );
667 p_intf->p_sys->p_popup_menu = menu;
669 p_intf->p_sys->p_popup_menu->popup( QCursor::pos() );
673 // destroy popup if there is one
674 delete p_intf->p_sys->p_popup_menu;
675 p_intf->p_sys->p_popup_menu = NULL;
679 /************************************************************************
681 ************************************************************************/
683 void QVLCMenu::updateSystrayMenu( MainInterface *mi,
684 intf_thread_t *p_intf,
685 bool b_force_visible )
689 /* Get the systray menu and clean it */
690 QMenu *sysMenu = mi->getSysTrayMenu();
693 /* Hide / Show VLC and cone */
694 if( mi->isVisible() || b_force_visible )
696 sysMenu->addAction( QIcon( ":/vlc16.png" ),
697 qtr( "Hide VLC media player in taskbar" ), mi,
698 SLOT( toggleUpdateSystrayMenu() ) );
702 sysMenu->addAction( QIcon( ":/vlc16.png" ),
703 qtr( "Show VLC media player" ), mi,
704 SLOT( toggleUpdateSystrayMenu() ) );
707 sysMenu->addSeparator();
708 PopupMenuControlEntries( sysMenu, p_intf, p_input );
710 sysMenu->addSeparator();
711 addDPStaticEntry( sysMenu, qtr( "&Open Media" ), "",
712 ":/pixmaps/file-wide_16px.png", SLOT( openFileDialog() ), "" );
713 addDPStaticEntry( sysMenu, qtr( "&Quit" ) , "",
714 ":/pixmaps/menus_quit_16px.png", SLOT( quit() ), "" );
717 mi->getSysTray()->setContextMenu( sysMenu );
721 #undef PUSH_SEPARATOR
724 /*************************************************************************
725 * Builders for automenus
726 *************************************************************************/
727 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf,
729 vector< const char *> & varnames,
730 vector<int> & objects,
733 QMenu *menu = current;
741 vlc_object_t *p_object;
742 vlc_bool_t b_section_empty = VLC_FALSE;
745 #define APPEND_EMPTY { QAction *action = menu->addAction( qtr( "Empty" ) ); \
746 action->setEnabled( false ); }
748 for( i = 0; i < ( int )objects.size() ; i++ )
750 if( !varnames[i] || !*varnames[i] )
752 if( b_section_empty )
754 menu->addSeparator();
755 b_section_empty = VLC_TRUE;
759 if( objects[i] == 0 )
761 /// \bug What is this ?
762 // Append( menu, varnames[i], NULL );
763 b_section_empty = VLC_FALSE;
767 p_object = ( vlc_object_t * )vlc_object_get( objects[i] );
768 if( p_object == NULL ) continue;
770 b_section_empty = VLC_FALSE;
771 /* Ugly specific stuff */
772 if( strstr( varnames[i], "intf-add" ) )
773 CreateItem( menu, varnames[i], p_object, false );
775 CreateItem( menu, varnames[i], p_object, true );
776 vlc_object_release( p_object );
779 /* Special case for empty menus */
780 if( menu->actions().size() == 0 || b_section_empty )
787 /*****************************************************************************
789 *****************************************************************************/
791 static bool IsMenuEmpty( const char *psz_var,
792 vlc_object_t *p_object,
795 vlc_value_t val, val_list;
796 int i_type, i_result, i;
798 /* Check the type of the object variable */
799 i_type = var_Type( p_object, psz_var );
801 /* Check if we want to display the variable */
802 if( !( i_type & VLC_VAR_HASCHOICE ) ) return false;
804 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
805 if( val.i_int == 0 ) return true;
807 if( ( i_type & VLC_VAR_TYPE ) != VLC_VAR_VARIABLE )
809 if( val.i_int == 1 && b_root ) return true;
813 /* Check children variables in case of VLC_VAR_VARIABLE */
814 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
819 for( i = 0, i_result = true; i < val_list.p_list->i_count; i++ )
821 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
829 /* clean up everything */
830 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
835 void QVLCMenu::CreateItem( QMenu *menu, const char *psz_var,
836 vlc_object_t *p_object, bool b_submenu )
838 vlc_value_t val, text;
841 /* Check the type of the object variable */
842 i_type = var_Type( p_object, psz_var );
844 switch( i_type & VLC_VAR_TYPE )
848 case VLC_VAR_VARIABLE:
850 case VLC_VAR_INTEGER:
854 /* Variable doesn't exist or isn't handled */
858 /* Make sure we want to display the variable */
859 if( IsMenuEmpty( psz_var, p_object ) ) return;
861 /* Get the descriptive name of the variable */
862 var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
864 if( i_type & VLC_VAR_HASCHOICE )
866 /* Append choices menu */
869 QMenu *submenu = new QMenu();
870 submenu->setTitle( qfu( text.psz_string ?
871 text.psz_string : psz_var ) );
872 if( CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0 )
873 menu->addMenu( submenu );
876 CreateChoicesMenu( menu, psz_var, p_object, true );
877 FREENULL( text.psz_string );
881 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
883 switch( i_type & VLC_VAR_TYPE )
886 var_Get( p_object, psz_var, &val );
887 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
888 p_object->i_object_id, val, i_type );
892 var_Get( p_object, psz_var, &val );
893 val.b_bool = !val.b_bool;
894 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
895 p_object->i_object_id, val, i_type, !val.b_bool );
898 FREENULL( text.psz_string );
902 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
903 vlc_object_t *p_object, bool b_root )
905 vlc_value_t val, val_list, text_list;
908 /* Check the type of the object variable */
909 i_type = var_Type( p_object, psz_var );
911 /* Make sure we want to display the variable */
912 if( IsMenuEmpty( psz_var, p_object, b_root ) ) return VLC_EGENERIC;
914 switch( i_type & VLC_VAR_TYPE )
918 case VLC_VAR_VARIABLE:
920 case VLC_VAR_INTEGER:
924 /* Variable doesn't exist or isn't handled */
928 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
929 &val_list, &text_list ) < 0 )
934 #define NORMAL_OR_RADIO i_type & VLC_VAR_ISCOMMAND ? ITEM_NORMAL: ITEM_RADIO
935 #define NOTCOMMAND !( i_type & VLC_VAR_ISCOMMAND )
936 #define CURVAL val_list.p_list->p_values[i]
937 #define CURTEXT text_list.p_list->p_values[i].psz_string
939 for( i = 0; i < val_list.p_list->i_count; i++ )
941 vlc_value_t another_val;
943 QMenu *subsubmenu = new QMenu();
945 switch( i_type & VLC_VAR_TYPE )
947 case VLC_VAR_VARIABLE:
948 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
949 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
950 submenu->addMenu( subsubmenu );
954 var_Get( p_object, psz_var, &val );
955 another_val.psz_string = strdup( CURVAL.psz_string );
956 menutext = qfu( "Add " ) /* If this function is more used, FIX*/
957 + 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 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( itemData->i_object_id );
1037 if( p_object == NULL ) return;
1039 var_Set( p_object, itemData->psz_var, itemData->val );
1040 vlc_object_release( p_object );