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 *****************************************************************************/
25 #include <vlc_intf_strings.h>
27 #include "main_interface.hpp"
29 #include "dialogs_provider.hpp"
30 #include "input_manager.hpp"
35 #include <QActionGroup>
36 #include <QSignalMapper>
37 #include <QSystemTrayIcon>
46 static QActionGroup *currentGroup;
48 // Add static entries to menus
49 void addDPStaticEntry( QMenu *menu,
56 if( !EMPTY_STR( icon ) > 0 )
58 if( !EMPTY_STR( shortcut ) > 0 )
59 menu->addAction( QIcon( icon ), text, THEDP, member, qtr( shortcut ) );
61 menu->addAction( QIcon( icon ), text, THEDP, member );
65 if( !EMPTY_STR( shortcut ) > 0 )
66 menu->addAction( text, THEDP, member, qtr( shortcut ) );
68 menu->addAction( text, THEDP, member );
72 void addMIMStaticEntry( intf_thread_t *p_intf,
79 if( strlen( icon ) > 0 )
81 QAction *action = menu->addAction( text, THEMIM, member );
82 action->setIcon( QIcon( icon ) );
86 menu->addAction( text, THEMIM, member );
90 /*****************************************************************************
91 * Definitions of variables for the dynamic menus
92 *****************************************************************************/
93 #define PUSH_VAR( var ) varnames.push_back( var ); \
94 objects.push_back( p_object->i_object_id )
96 #define PUSH_SEPARATOR if( objects.size() != i_last_separator ) { \
97 objects.push_back( 0 ); varnames.push_back( "" ); \
98 i_last_separator = objects.size(); }
100 static int InputAutoMenuBuilder( vlc_object_t *p_object,
101 vector<int> &objects,
102 vector<const char *> &varnames )
104 PUSH_VAR( "bookmark" );
106 PUSH_VAR( "chapter" );
107 PUSH_VAR( "program" );
108 PUSH_VAR( "navigation" );
109 PUSH_VAR( "dvd_menus" );
113 static int VideoAutoMenuBuilder( vlc_object_t *p_object,
114 vector<int> &objects,
115 vector<const char *> &varnames )
117 PUSH_VAR( "fullscreen" );
119 PUSH_VAR( "deinterlace" );
120 PUSH_VAR( "aspect-ratio" );
122 PUSH_VAR( "video-on-top" );
123 PUSH_VAR( "directx-wallpaper" );
124 PUSH_VAR( "video-snapshot" );
126 vlc_object_t *p_dec_obj = ( vlc_object_t * )vlc_object_find( p_object,
129 if( p_dec_obj != NULL )
131 vlc_object_t *p_object = p_dec_obj;
132 PUSH_VAR( "ffmpeg-pp-q" );
133 vlc_object_release( p_dec_obj );
138 static int AudioAutoMenuBuilder( vlc_object_t *p_object,
139 vector<int> &objects,
140 vector<const char *> &varnames )
142 PUSH_VAR( "audio-device" );
143 PUSH_VAR( "audio-channels" );
144 PUSH_VAR( "visual" );
145 PUSH_VAR( "equalizer" );
149 /*****************************************************************************
152 *****************************************************************************/
154 #define BAR_ADD( func, title ) { \
155 QMenu *menu = func; menu->setTitle( title ); bar->addMenu( menu ); }
157 #define BAR_DADD( func, title, id ) { \
158 QMenu *menu = func; menu->setTitle( title ); bar->addMenu( menu ); \
159 MenuFunc *f = new MenuFunc( menu, id ); \
160 CONNECT( menu, aboutToShow(), THEDP->menusUpdateMapper, map() ); \
161 THEDP->menusUpdateMapper->setMapping( menu, f ); }
164 * Main Menu Bar Creation
166 void QVLCMenu::createMenuBar( MainInterface *mi,
167 intf_thread_t *p_intf,
168 bool visual_selector_enabled )
170 QMenuBar *bar = mi->menuBar();
171 BAR_ADD( FileMenu(), qtr( "&Media" ) );
172 BAR_ADD( PlaylistMenu( p_intf, mi ), qtr( "&Playlist" ) );
173 BAR_ADD( ToolsMenu( p_intf, mi, visual_selector_enabled, true ), qtr( "&Tools" ) );
174 BAR_DADD( AudioMenu( p_intf, NULL ), qtr( "&Audio" ), 2 );
175 BAR_DADD( VideoMenu( p_intf, NULL ), qtr( "&Video" ), 1 );
176 BAR_DADD( NavigMenu( p_intf, NULL ), qtr( "&Playback" ), 3 );
178 BAR_ADD( HelpMenu(), qtr( "&Help" ) );
184 * Media ( File ) Menu
185 * Opening, streaming and quit
187 QMenu *QVLCMenu::FileMenu()
189 QMenu *menu = new QMenu();
191 addDPStaticEntry( menu, qtr( "&Open File..." ), "",
192 ":/pixmaps/file-asym_16px.png", SLOT( openFileDialog() ), "Ctrl+O" );
193 addDPStaticEntry( menu, qtr( I_OPEN_FOLDER ), "",
194 ":/pixmaps/folder-grey_16px.png", SLOT( PLAppendDir() ), "Ctrl+F" );
195 addDPStaticEntry( menu, qtr( "Open &Disc..." ), "",
196 ":/pixmaps/disc_16px.png", SLOT( openDiscDialog() ), "Ctrl+D" );
197 addDPStaticEntry( menu, qtr( "Open &Network..." ), "",
198 ":/pixmaps/network_16px.png", SLOT( openNetDialog() ), "Ctrl+N" );
199 addDPStaticEntry( menu, qtr( "Open &Capture Device..." ), "",
200 ":/pixmaps/capture-card_16px.png", SLOT( openCaptureDialog() ),
202 menu->addSeparator();
204 addDPStaticEntry( menu, qtr( "&Streaming..." ), "",
205 ":/pixmaps/menus_stream_16px.png", SLOT( openThenStreamingDialogs() ),
207 addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "", "",
208 SLOT( openThenTranscodingDialogs() ), "Ctrl+R" );
209 menu->addSeparator();
211 addDPStaticEntry( menu, qtr( "&Quit" ) , "",
212 ":/pixmaps/menus_quit_16px.png", SLOT( quit() ), "Ctrl+Q" );
216 /* Playlist/MediaLibrary Control */
217 QMenu *QVLCMenu::PlaylistMenu( intf_thread_t *p_intf, MainInterface *mi )
219 QMenu *menu = new QMenu();
220 menu->addMenu( SDMenu( p_intf ) );
221 menu->addAction( QIcon( ":/pixmaps/playlist_16px.png" ),
222 qtr( "Show Playlist" ), mi, SLOT( togglePlaylist() ) );
223 menu->addSeparator();
225 addDPStaticEntry( menu, qtr( I_PL_LOAD ), "", "", SLOT( openAPlaylist() ),
227 addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", "", SLOT( saveAPlaylist() ),
229 menu->addSeparator();
230 menu->addAction( qtr( "Undock from interface" ), mi,
231 SLOT( undockPlaylist() ), qtr( "Ctrl+U" ) );
237 * This is kept in the same menu for now, but could change if it gets much
239 * This menu can be an interface menu but also a right click menu.
241 QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf,
243 bool visual_selector_enabled,
246 QMenu *menu = new QMenu;
249 menu->addAction( QIcon( ":/pixmaps/playlist_16px.png" ),
250 qtr( "Playlist..." ), mi, SLOT( togglePlaylist() ),
253 addDPStaticEntry( menu, qtr( I_MENU_EXT ), "",
254 ":/pixmaps/menus_settings_16px.png", SLOT( extendedDialog() ),
257 menu->addSeparator();
261 QMenu *intfmenu = InterfacesMenu( p_intf, NULL );
262 intfmenu->setTitle( qtr( "Add Interfaces" ) );
263 menu->addMenu( intfmenu );
264 menu->addSeparator();
269 QAction *action=menu->addAction( qtr( "Minimal View..." ), mi,
270 SLOT( toggleMinimalView() ), qtr( "Ctrl+H" ) );
271 //FIXME: remove useless thing. But keep it until the release, pls.
272 action->setCheckable( true );
273 if( mi->getControlsVisibilityStatus() & CONTROLS_VISIBLE )
274 action->setChecked( true );
276 /* Advanced Controls */
277 action = menu->addAction( qtr( "Advanced controls" ), mi,
278 SLOT( toggleAdvanced() ) );
279 action->setCheckable( true );
280 if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
281 action->setChecked( true );
282 #if 0 /* For Visualisations. Not yet working */
283 adv = menu->addAction( qtr( "Visualizations selector" ),
284 mi, SLOT( visual() ) );
285 adv->setCheckable( true );
286 if( visual_selector_enabled ) adv->setChecked( true );
290 menu->addSeparator();
292 addDPStaticEntry( menu, qtr( I_MENU_MSG ), "",
293 ":/pixmaps/menus_messages_16px.png", SLOT( messagesDialog() ),
295 addDPStaticEntry( menu, qtr( I_MENU_INFO ) , "", "",
296 SLOT( mediaInfoDialog() ), "Ctrl+I" );
297 addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) , "",
298 ":/pixmaps/menus_info_16px.png", SLOT( mediaCodecDialog() ), "Ctrl+J" );
300 #if 0 /* Not Implemented yet */
301 addDPStaticEntry( menu, qtr( I_MENU_BOOKMARK ), "","", "bookmarksDialog()", "Ctrl+B" );
303 addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", "", SLOT( vlmDialog() ),
306 menu->addSeparator();
307 addDPStaticEntry( menu, qtr( "Preferences..." ), "",
308 ":/pixmaps/menus_preferences_16px.png", SLOT( prefsDialog() ), "Ctrl+P" );
313 * Interface Sub-Menu, to list extras interface and skins
315 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
318 vector<const char *> varnames;
319 /** \todo add "switch to XXX" */
320 varnames.push_back( "intf-add" );
321 objects.push_back( p_intf->i_object_id );
323 QMenu *menu = Populate( p_intf, current, varnames, objects );
325 if( !p_intf->pf_show_dialog )
327 menu->addSeparator();
328 menu->addAction( qtr( "Switch to skins" ), THEDP, SLOT( switchToSkins() ),
329 QString( "Ctrl+Z" ) );
332 CONNECT( menu, aboutToShow(), THEDP->menusUpdateMapper, map() );
333 THEDP->menusUpdateMapper->setMapping( menu, 4 );
340 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
343 vector<const char *> varnames;
345 vlc_object_t *p_object = ( vlc_object_t * )vlc_object_find( p_intf,
346 VLC_OBJECT_INPUT, FIND_ANYWHERE );
347 if( p_object != NULL )
349 PUSH_VAR( "audio-es" );
350 vlc_object_release( p_object );
353 p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_AOUT,
357 AudioAutoMenuBuilder( p_object, objects, varnames );
358 vlc_object_release( p_object );
360 return Populate( p_intf, current, varnames, objects );
365 * Subtitles are part of Video.
367 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
369 vlc_object_t *p_object;
371 vector<const char *> varnames;
373 p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_INPUT,
375 if( p_object != NULL )
377 PUSH_VAR( "video-es" );
378 PUSH_VAR( "spu-es" );
379 vlc_object_release( p_object );
382 p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_VOUT,
384 if( p_object != NULL )
386 VideoAutoMenuBuilder( p_object, objects, varnames );
387 vlc_object_release( p_object );
389 return Populate( p_intf, current, varnames, objects );
394 * For DVD, MP4, MOV and other chapter based format
396 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *navMenu )
398 vlc_object_t *p_object;
400 vector<const char *> varnames;
403 p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_INPUT,
405 if( p_object != NULL )
407 InputAutoMenuBuilder( p_object, objects, varnames );
408 PUSH_VAR( "prev-title" ); PUSH_VAR ( "next-title" );
409 PUSH_VAR( "prev-chapter" ); PUSH_VAR( "next-chapter" );
410 vlc_object_release( p_object );
412 navMenu = new QMenu();
413 addDPStaticEntry( navMenu, qtr( I_MENU_GOTOTIME ), "","",
414 SLOT( gotoTimeDialog() ), "Ctrl+T" );
415 navMenu->addSeparator();
416 return Populate( p_intf, navMenu, varnames, objects, true );
420 * Service Discovery SubMenu
422 QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf )
424 QMenu *menu = new QMenu();
425 menu->setTitle( qtr( I_PL_SD ) );
426 char **ppsz_longnames;
427 char **ppsz_names = services_discovery_GetServicesNames( p_intf,
429 char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
430 for( ; *ppsz_name; ppsz_name++, ppsz_longname++ )
432 QAction *a = new QAction( qfu( *ppsz_longname ), menu );
433 a->setCheckable( true );
434 if( playlist_IsServicesDiscoveryLoaded( THEPL, *ppsz_name ) )
435 a->setChecked( true );
436 CONNECT( a , triggered(), THEDP->SDMapper, map() );
437 THEDP->SDMapper->setMapping( a, QString( *ppsz_name ) );
438 menu->addAction( a );
440 if( !strcmp( *ppsz_name, "podcast" ) )
442 QAction *b = new QAction( qfu( "Configure podcasts..." ), menu );
443 //b->setEnabled( a->isChecked() );
444 menu->addAction( b );
445 CONNECT( b, triggered(), THEDP, podcastConfigureDialog() );
448 free( *ppsz_longname );
451 free( ppsz_longnames );
457 QMenu *QVLCMenu::HelpMenu()
459 QMenu *menu = new QMenu();
460 addDPStaticEntry( menu, qtr( "Help..." ) , "",
461 ":/pixmaps/menus_help_16px.png", SLOT( helpDialog() ), "F1" );
462 addDPStaticEntry( menu, qtr( "Update" ) , "", "", SLOT( updateDialog() ), "");
463 menu->addSeparator();
464 addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), "", "", SLOT( aboutDialog() ),
470 /*****************************************************************************
471 * Popup menus - Right Click menus *
472 *****************************************************************************/
473 #define POPUP_BOILERPLATE \
474 unsigned int i_last_separator = 0; \
475 vector<int> objects; \
476 vector<const char *> varnames; \
477 input_thread_t *p_input = THEMIM->getInput();
479 #define CREATE_POPUP \
480 Populate( p_intf, menu, varnames, objects ); \
481 p_intf->p_sys->p_popup_menu = menu; \
482 menu->popup( QCursor::pos() ); \
483 p_intf->p_sys->p_popup_menu = NULL; \
484 i_last_separator = 0;
486 void QVLCMenu::PopupMenuControlEntries( QMenu *menu,
487 intf_thread_t *p_intf,
488 input_thread_t *p_input )
493 var_Get( p_input, "state", &val );
494 if( val.i_int == PLAYING_S )
495 addMIMStaticEntry( p_intf, menu, qtr( "Pause" ), "",
496 ":/pixmaps/pause_16px.png", SLOT( togglePlayPause() ) );
498 addMIMStaticEntry( p_intf, menu, qtr( "Play" ), "",
499 ":/pixmaps/play_16px.png", SLOT( togglePlayPause() ) );
501 else if( THEPL->items.i_size && THEPL->i_enabled )
502 addMIMStaticEntry( p_intf, menu, qtr( "Play" ), "",
503 ":/pixmaps/play_16px.png", SLOT( togglePlayPause() ) );
505 addMIMStaticEntry( p_intf, menu, qtr( "Stop" ), "",
506 ":/pixmaps/stop_16px.png", SLOT( stop() ) );
507 addMIMStaticEntry( p_intf, menu, qtr( "Previous" ), "",
508 ":/pixmaps/previous_16px.png", SLOT( prev() ) );
509 addMIMStaticEntry( p_intf, menu, qtr( "Next" ), "",
510 ":/pixmaps/next_16px.png", SLOT( next() ) );
513 void QVLCMenu::PopupMenuStaticEntries( intf_thread_t *p_intf, QMenu *menu )
515 QMenu *toolsmenu = ToolsMenu( p_intf, NULL, false, true );
516 toolsmenu->setTitle( qtr( "Tools" ) );
517 menu->addMenu( toolsmenu );
519 QMenu *openmenu = new QMenu( qtr( "Open" ) );
520 openmenu->addAction( qtr( "Open &File..." ), THEDP,
521 SLOT( openFileDialog() ) );
522 openmenu->addAction( qtr( "Open &Disc..." ), THEDP,
523 SLOT( openDiscDialog() ) );
524 openmenu->addAction( qtr( "Open &Network..." ), THEDP,
525 SLOT( openNetDialog() ) );
526 openmenu->addAction( qtr( "Open &Capture Device..." ), THEDP,
527 SLOT( openCaptureDialog() ) );
528 menu->addMenu( openmenu );
530 menu->addSeparator();
531 QMenu *helpmenu = HelpMenu();
532 helpmenu->setTitle( qtr( "Help" ) );
533 menu->addMenu( helpmenu );
535 addDPStaticEntry( menu, qtr( "Quit" ), "", "", SLOT( quit() ) , "Ctrl+Q" );
538 /* Video Tracks and Subtitles tracks */
539 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
544 vlc_object_yield( p_input );
545 varnames.push_back( "video-es" );
546 objects.push_back( p_input->i_object_id );
547 varnames.push_back( "spu-es" );
548 objects.push_back( p_input->i_object_id );
549 vlc_object_t *p_vout = ( vlc_object_t * )vlc_object_find( p_input,
550 VLC_OBJECT_VOUT, FIND_CHILD );
553 VideoAutoMenuBuilder( p_vout, objects, varnames );
554 vlc_object_release( p_vout );
556 vlc_object_release( p_input );
558 QMenu *menu = new QMenu();
563 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
568 vlc_object_yield( p_input );
569 varnames.push_back( "audio-es" );
570 objects.push_back( p_input->i_object_id );
571 vlc_object_t *p_aout = ( vlc_object_t * )vlc_object_find( p_input,
572 VLC_OBJECT_AOUT, FIND_ANYWHERE );
575 AudioAutoMenuBuilder( p_aout, objects, varnames );
576 vlc_object_release( p_aout );
578 vlc_object_release( p_input );
580 QMenu *menu = new QMenu();
584 /* Navigation stuff, and general menus ( open ) */
585 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
592 vlc_object_yield( p_input );
593 varnames.push_back( "audio-es" );
594 InputAutoMenuBuilder( VLC_OBJECT( p_input ), objects, varnames );
598 QMenu *menu = new QMenu();
599 Populate( p_intf, menu, varnames, objects );
601 menu->addSeparator();
602 PopupMenuControlEntries( menu, p_intf, p_input );
604 menu->addSeparator();
605 PopupMenuStaticEntries( p_intf, menu );
607 p_intf->p_sys->p_popup_menu = menu;
608 menu->popup( QCursor::pos() );
609 p_intf->p_sys->p_popup_menu = NULL;
612 /* Main Menu that sticks everything together */
613 void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
617 // create a popup if there is none
618 if( ! p_intf->p_sys->p_popup_menu )
623 vlc_object_yield( p_input );
624 InputAutoMenuBuilder( VLC_OBJECT( p_input ), objects, varnames );
628 varnames.push_back( "audio-es" );
629 objects.push_back( p_input->i_object_id );
630 vlc_object_t *p_aout = ( vlc_object_t * )
631 vlc_object_find( p_input, VLC_OBJECT_AOUT, FIND_ANYWHERE );
634 AudioAutoMenuBuilder( p_aout, objects, varnames );
635 vlc_object_release( p_aout );
640 varnames.push_back( "video-es" );
641 objects.push_back( p_input->i_object_id );
642 varnames.push_back( "spu-es" );
643 objects.push_back( p_input->i_object_id );
644 vlc_object_t *p_vout = ( vlc_object_t * )
645 vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD );
648 VideoAutoMenuBuilder( p_vout, objects, varnames );
649 vlc_object_release( p_vout );
653 QMenu *menu = new QMenu();
654 Populate( p_intf, menu, varnames, objects );
655 menu->addSeparator();
656 PopupMenuControlEntries( menu, p_intf, p_input );
657 menu->addSeparator();
658 PopupMenuStaticEntries( p_intf, menu );
660 p_intf->p_sys->p_popup_menu = menu;
662 p_intf->p_sys->p_popup_menu->popup( QCursor::pos() );
666 // destroy popup if there is one
667 delete p_intf->p_sys->p_popup_menu;
668 p_intf->p_sys->p_popup_menu = NULL;
672 /************************************************************************
674 ************************************************************************/
676 void QVLCMenu::updateSystrayMenu( MainInterface *mi,
677 intf_thread_t *p_intf,
678 bool b_force_visible )
682 /* Get the systray menu and clean it */
683 QMenu *sysMenu = mi->getSysTrayMenu();
686 /* Hide / Show VLC and cone */
687 if( mi->isVisible() || b_force_visible )
689 sysMenu->addAction( QIcon( ":/vlc16.png" ),
690 qtr( "Hide VLC media player in taskbar" ), mi,
691 SLOT( toggleUpdateSystrayMenu() ) );
695 sysMenu->addAction( QIcon( ":/vlc16.png" ),
696 qtr( "Show VLC media player" ), mi,
697 SLOT( toggleUpdateSystrayMenu() ) );
700 sysMenu->addSeparator();
701 PopupMenuControlEntries( sysMenu, p_intf, p_input );
703 sysMenu->addSeparator();
704 addDPStaticEntry( sysMenu, qtr( "&Open Media" ), "",
705 ":/pixmaps/file-wide_16px.png", SLOT( openFileDialog() ), "" );
706 addDPStaticEntry( sysMenu, qtr( "&Quit" ) , "",
707 ":/pixmaps/menus_quit_16px.png", SLOT( quit() ), "" );
710 mi->getSysTray()->setContextMenu( sysMenu );
714 #undef PUSH_SEPARATOR
717 /*************************************************************************
718 * Builders for automenus
719 *************************************************************************/
720 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf,
722 vector< const char *> & varnames,
723 vector<int> & objects,
726 QMenu *menu = current;
734 vlc_object_t *p_object;
735 vlc_bool_t b_section_empty = VLC_FALSE;
738 #define APPEND_EMPTY { QAction *action = menu->addAction( qtr( "Empty" ) ); \
739 action->setEnabled( false ); }
741 for( i = 0; i < ( int )objects.size() ; i++ )
743 if( !varnames[i] || !*varnames[i] )
745 if( b_section_empty )
747 menu->addSeparator();
748 b_section_empty = VLC_TRUE;
752 if( objects[i] == 0 )
754 /// \bug What is this ?
755 // Append( menu, varnames[i], NULL );
756 b_section_empty = VLC_FALSE;
760 p_object = ( vlc_object_t * )vlc_object_get( p_intf, objects[i] );
761 if( p_object == NULL ) continue;
763 b_section_empty = VLC_FALSE;
764 /* Ugly specific stuff */
765 if( strstr( varnames[i], "intf-add" ) )
766 CreateItem( menu, varnames[i], p_object, false );
768 CreateItem( menu, varnames[i], p_object, true );
769 vlc_object_release( p_object );
772 /* Special case for empty menus */
773 if( menu->actions().size() == 0 || b_section_empty )
780 /*****************************************************************************
782 *****************************************************************************/
784 static bool IsMenuEmpty( const char *psz_var,
785 vlc_object_t *p_object,
788 vlc_value_t val, val_list;
789 int i_type, i_result, i;
791 /* Check the type of the object variable */
792 i_type = var_Type( p_object, psz_var );
794 /* Check if we want to display the variable */
795 if( !( i_type & VLC_VAR_HASCHOICE ) ) return false;
797 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
798 if( val.i_int == 0 ) return true;
800 if( ( i_type & VLC_VAR_TYPE ) != VLC_VAR_VARIABLE )
802 /* Very evil hack ! intf-switch can have only one value */
803 if( !strcmp( psz_var, "intf-switch" ) ) return false;
804 if( val.i_int == 1 && b_root ) return true;
808 /* Check children variables in case of VLC_VAR_VARIABLE */
809 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
814 for( i = 0, i_result = true; i < val_list.p_list->i_count; i++ )
816 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
824 /* clean up everything */
825 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
830 void QVLCMenu::CreateItem( QMenu *menu, const char *psz_var,
831 vlc_object_t *p_object, bool b_submenu )
833 vlc_value_t val, text;
836 /* Check the type of the object variable */
837 i_type = var_Type( p_object, psz_var );
839 switch( i_type & VLC_VAR_TYPE )
843 case VLC_VAR_VARIABLE:
845 case VLC_VAR_INTEGER:
849 /* Variable doesn't exist or isn't handled */
853 /* Make sure we want to display the variable */
854 if( IsMenuEmpty( psz_var, p_object ) ) return;
856 /* Get the descriptive name of the variable */
857 var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
859 if( i_type & VLC_VAR_HASCHOICE )
861 /* Append choices menu */
864 QMenu *submenu = new QMenu();
865 submenu->setTitle( qfu( text.psz_string ?
866 text.psz_string : psz_var ) );
867 if( CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0 )
868 menu->addMenu( submenu );
871 CreateChoicesMenu( menu, psz_var, p_object, true );
872 FREENULL( text.psz_string );
876 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
878 switch( i_type & VLC_VAR_TYPE )
881 var_Get( p_object, psz_var, &val );
882 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
883 p_object->i_object_id, val, i_type );
887 var_Get( p_object, psz_var, &val );
888 val.b_bool = !val.b_bool;
889 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
890 p_object->i_object_id, val, i_type, !val.b_bool );
893 FREENULL( text.psz_string );
897 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
898 vlc_object_t *p_object, bool b_root )
900 vlc_value_t val, val_list, text_list;
903 /* Check the type of the object variable */
904 i_type = var_Type( p_object, psz_var );
906 /* Make sure we want to display the variable */
907 if( IsMenuEmpty( psz_var, p_object, b_root ) ) return VLC_EGENERIC;
909 switch( i_type & VLC_VAR_TYPE )
913 case VLC_VAR_VARIABLE:
915 case VLC_VAR_INTEGER:
919 /* Variable doesn't exist or isn't handled */
923 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
924 &val_list, &text_list ) < 0 )
929 #define NORMAL_OR_RADIO i_type & VLC_VAR_ISCOMMAND ? ITEM_NORMAL: ITEM_RADIO
930 #define NOTCOMMAND !( i_type & VLC_VAR_ISCOMMAND )
931 #define CURVAL val_list.p_list->p_values[i]
932 #define CURTEXT text_list.p_list->p_values[i].psz_string
934 for( i = 0; i < val_list.p_list->i_count; i++ )
936 vlc_value_t another_val;
938 QMenu *subsubmenu = new QMenu();
940 switch( i_type & VLC_VAR_TYPE )
942 case VLC_VAR_VARIABLE:
943 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
944 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
945 submenu->addMenu( subsubmenu );
949 var_Get( p_object, psz_var, &val );
950 another_val.psz_string = strdup( CURVAL.psz_string );
951 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
952 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
953 p_object->i_object_id, another_val, i_type,
954 NOTCOMMAND && val.psz_string &&
955 !strcmp( val.psz_string, CURVAL.psz_string ) );
957 if( val.psz_string ) free( val.psz_string );
960 case VLC_VAR_INTEGER:
961 var_Get( p_object, psz_var, &val );
962 if( CURTEXT ) menutext = qfu( CURTEXT );
963 else menutext.sprintf( "%d", CURVAL.i_int );
964 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
965 p_object->i_object_id, CURVAL, i_type,
966 NOTCOMMAND && CURVAL.i_int == val.i_int );
970 var_Get( p_object, psz_var, &val );
971 if( CURTEXT ) menutext = qfu( CURTEXT );
972 else menutext.sprintf( "%.2f", CURVAL.f_float );
973 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
974 p_object->i_object_id, CURVAL, i_type,
975 NOTCOMMAND && CURVAL.f_float == val.f_float );
984 /* clean up everything */
985 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
987 #undef NORMAL_OR_RADIO
994 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
995 QString text, QString help,
996 int i_item_type, int i_object_id,
997 vlc_value_t val, int i_val_type,
1000 QAction *action = new QAction( text, menu );
1001 action->setText( text );
1002 action->setToolTip( help );
1004 if( i_item_type == ITEM_CHECK )
1006 action->setCheckable( true );
1008 else if( i_item_type == ITEM_RADIO )
1010 action->setCheckable( true );
1012 currentGroup = new QActionGroup( menu );
1013 currentGroup->addAction( action );
1018 action->setChecked( true );
1020 MenuItemData *itemData = new MenuItemData( i_object_id, i_val_type,
1022 CONNECT( action, triggered(), THEDP->menusMapper, map() );
1023 THEDP->menusMapper->setMapping( action, itemData );
1024 menu->addAction( action );
1027 void QVLCMenu::DoAction( intf_thread_t *p_intf, QObject *data )
1029 MenuItemData *itemData = qobject_cast<MenuItemData *>( data );
1030 vlc_object_t *p_object = ( vlc_object_t * )vlc_object_get( p_intf,
1031 itemData->i_object_id );
1032 if( p_object == NULL ) return;
1034 var_Set( p_object, itemData->psz_var, itemData->val );
1035 vlc_object_release( p_object );