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, SLOT( slot ) );
82 action->setIcon( QIcon( icon ) );
86 menu->addAction( text, THEMIM, SLOT( slot ) );
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 QMenu *QVLCMenu::PlaylistMenu( intf_thread_t *p_intf, MainInterface *mi )
218 QMenu *menu = new QMenu();
219 menu->addMenu( SDMenu( p_intf ) );
220 menu->addAction( QIcon( ":/pixmaps/playlist_16px.png" ),
221 qtr( "Show Playlist" ), mi, SLOT( togglePlaylist() ) );
222 menu->addSeparator();
224 addDPStaticEntry( menu, qtr( I_PL_LOAD ), "", "", SLOT( openAPlaylist() ),
226 addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", "", SLOT( saveAPlaylist() ),
228 menu->addSeparator();
229 menu->addAction( qtr( "Undock from interface" ), mi,
230 SLOT( undockPlaylist() ), qtr( "Ctrl+U" ) );
236 * This is kept in the same menu for now, but could change if it gets much
239 QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf,
241 bool visual_selector_enabled,
244 QMenu *menu = new QMenu;
247 menu->addAction( QIcon( ":/pixmaps/playlist_16px.png" ),
248 qtr( "Playlist..." ), mi, SLOT( togglePlaylist() ),
251 addDPStaticEntry( menu, qtr( I_MENU_EXT ), "",
252 ":/pixmaps/menus_settings_16px.png", SLOT( extendedDialog() ),
255 menu->addSeparator();
259 QMenu *intfmenu = InterfacesMenu( p_intf, NULL );
260 intfmenu->setTitle( qtr( "Add Interfaces" ) );
261 menu->addMenu( intfmenu );
262 menu->addSeparator();
267 QAction *action=menu->addAction( qtr( "Minimal View..." ), mi,
268 SLOT( toggleMinimalView() ), qtr( "Ctrl+H" ) );
269 //FIXME: remove useless thing. But keep it until the release, pls.
270 action->setCheckable( true );
271 if( mi->getControlsVisibilityStatus() & CONTROLS_VISIBLE )
272 action->setChecked( true );
274 /* Advanced Controls */
275 action = menu->addAction( qtr( "Advanced controls" ), mi,
276 SLOT( toggleAdvanced() ) );
277 action->setCheckable( true );
278 if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
279 action->setChecked( true );
280 #if 0 /* For Visualisations. Not yet working */
281 adv = menu->addAction( qtr( "Visualizations selector" ),
282 mi, SLOT( visual() ) );
283 adv->setCheckable( true );
284 if( visual_selector_enabled ) adv->setChecked( true );
288 menu->addSeparator();
290 addDPStaticEntry( menu, qtr( I_MENU_MSG ), "",
291 ":/pixmaps/menus_messages_16px.png", SLOT( messagesDialog() ),
293 addDPStaticEntry( menu, qtr( I_MENU_INFO ) , "", "",
294 SLOT( mediaInfoDialog() ), "Ctrl+I" );
295 addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) , "",
296 ":/pixmaps/menus_info_16px.png", SLOT( mediaCodecDialog() ), "Ctrl+J" );
298 #if 0 /* Not Implemented yet */
299 addDPStaticEntry( menu, qtr( I_MENU_BOOKMARK ), "","", "bookmarksDialog()", "Ctrl+B" );
301 addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", "", SLOT( vlmDialog() ),
304 menu->addSeparator();
305 addDPStaticEntry( menu, qtr( "Preferences..." ), "",
306 ":/pixmaps/menus_preferences_16px.png", SLOT( prefsDialog() ), "Ctrl+P" );
311 * Interface Sub-Menu, to list extras interface and skins
313 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
316 vector<const char *> varnames;
317 /** \todo add "switch to XXX" */
318 varnames.push_back( "intf-add" );
319 objects.push_back( p_intf->i_object_id );
321 QMenu *menu = Populate( p_intf, current, varnames, objects );
323 if( !p_intf->pf_show_dialog )
325 menu->addSeparator();
326 menu->addAction( qtr( "Switch to skins" ), THEDP, SLOT( switchToSkins() ),
327 QString( "Ctrl+Z" ) );
330 CONNECT( menu, aboutToShow(), THEDP->menusUpdateMapper, map() );
331 THEDP->menusUpdateMapper->setMapping( menu, 4 );
338 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
341 vector<const char *> varnames;
343 vlc_object_t *p_object = ( vlc_object_t * )vlc_object_find( p_intf,
344 VLC_OBJECT_INPUT, FIND_ANYWHERE );
345 if( p_object != NULL )
347 PUSH_VAR( "audio-es" );
348 vlc_object_release( p_object );
351 p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_AOUT,
355 AudioAutoMenuBuilder( p_object, objects, varnames );
356 vlc_object_release( p_object );
358 return Populate( p_intf, current, varnames, objects );
363 * Subtitles are part of Video.
365 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
367 vlc_object_t *p_object;
369 vector<const char *> varnames;
371 p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_INPUT,
373 if( p_object != NULL )
375 PUSH_VAR( "video-es" );
376 PUSH_VAR( "spu-es" );
377 vlc_object_release( p_object );
380 p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_VOUT,
382 if( p_object != NULL )
384 VideoAutoMenuBuilder( p_object, objects, varnames );
385 vlc_object_release( p_object );
387 return Populate( p_intf, current, varnames, objects );
392 * For DVD, MP4, MOV and other chapter based format
394 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *navMenu )
396 vlc_object_t *p_object;
398 vector<const char *> varnames;
401 p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_INPUT,
403 if( p_object != NULL )
405 InputAutoMenuBuilder( p_object, objects, varnames );
406 PUSH_VAR( "prev-title" ); PUSH_VAR ( "next-title" );
407 PUSH_VAR( "prev-chapter" ); PUSH_VAR( "next-chapter" );
408 vlc_object_release( p_object );
410 navMenu = new QMenu();
411 addDPStaticEntry( navMenu, qtr( I_MENU_GOTOTIME ), "","",
412 SLOT( gotoTimeDialog() ), "Ctrl+T" );
413 navMenu->addSeparator();
414 return Populate( p_intf, navMenu, varnames, objects, true );
418 * Service Discovery SubMenu
420 QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf )
422 QMenu *menu = new QMenu();
423 menu->setTitle( qtr( I_PL_SD ) );
424 char **ppsz_longnames;
425 char **ppsz_names = services_discovery_GetServicesNames( p_intf,
427 char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
428 for( ; *ppsz_name; ppsz_name++, ppsz_longname++ )
430 QAction *a = new QAction( qfu( *ppsz_longname ), menu );
431 a->setCheckable( true );
432 if( playlist_IsServicesDiscoveryLoaded( THEPL, *ppsz_name ) )
433 a->setChecked( true );
434 CONNECT( a , triggered(), THEDP->SDMapper, map() );
435 THEDP->SDMapper->setMapping( a, QString( *ppsz_name ) );
436 menu->addAction( a );
438 if( !strcmp( *ppsz_name, "podcast" ) )
440 QAction *b = new QAction( qfu( "Configure podcasts..." ), menu );
441 //b->setEnabled( a->isChecked() );
442 menu->addAction( b );
443 CONNECT( b, triggered(), THEDP, podcastConfigureDialog() );
446 free( *ppsz_longname );
449 free( ppsz_longnames );
455 QMenu *QVLCMenu::HelpMenu()
457 QMenu *menu = new QMenu();
458 addDPStaticEntry( menu, qtr( "Help..." ) , "",
459 ":/pixmaps/menus_help_16px.png", SLOT( helpDialog() ), "F1" );
460 addDPStaticEntry( menu, qtr( "Update" ) , "", "", SLOT( updateDialog() ), "");
461 menu->addSeparator();
462 addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), "", "", SLOT( aboutDialog() ),
468 /*****************************************************************************
469 * Popup menus - Right Click menus *
470 *****************************************************************************/
471 #define POPUP_BOILERPLATE \
472 unsigned int i_last_separator = 0; \
473 vector<int> objects; \
474 vector<const char *> varnames; \
475 input_thread_t *p_input = THEMIM->getInput();
477 #define CREATE_POPUP \
478 Populate( p_intf, menu, varnames, objects ); \
479 p_intf->p_sys->p_popup_menu = menu; \
480 menu->popup( QCursor::pos() ); \
481 p_intf->p_sys->p_popup_menu = NULL; \
482 i_last_separator = 0;
484 #define POPUP_PLAY_ENTRIES( menu )\
488 var_Get( p_input, "state", &val ); \
489 if( val.i_int == PLAYING_S ) \
490 addMIMStaticEntry( p_intf, menu, qtr( "Pause" ), "", \
491 ":/pixmaps/pause_16px.png", SLOT( togglePlayPause() ) ); \
493 addMIMStaticEntry( p_intf, menu, qtr( "Play" ), "", \
494 ":/pixmaps/play_16px.png", SLOT( togglePlayPause() ) ); \
496 else if( THEPL->items.i_size && THEPL->i_enabled ) \
497 addMIMStaticEntry( p_intf, menu, qtr( "Play" ), "", \
498 ":/pixmaps/play_16px.png", SLOT( togglePlayPause() ) ); \
500 addMIMStaticEntry( p_intf, menu, qtr( "Stop" ), "", \
501 ":/pixmaps/stop_16px.png", SLOT( stop() ) ); \
502 addMIMStaticEntry( p_intf, menu, qtr( "Previous" ), "", \
503 ":/pixmaps/previous_16px.png", SLOT( prev() ) ); \
504 addMIMStaticEntry( p_intf, menu, qtr( "Next" ), "", \
505 ":/pixmaps/next_16px.png", SLOT( next() ) );
507 void QVLCMenu::PopupMenuStaticEntries( intf_thread_t *p_intf, QMenu *menu )
509 QMenu *toolsmenu = ToolsMenu( p_intf, NULL, false, true );
510 toolsmenu->setTitle( qtr( "Tools" ) );
511 menu->addMenu( toolsmenu );
513 QMenu *openmenu = new QMenu( qtr( "Open" ) );
514 openmenu->addAction( qtr( "Open &File..." ), THEDP,
515 SLOT( openFileDialog() ) );
516 openmenu->addAction( qtr( "Open &Disc..." ), THEDP,
517 SLOT( openDiscDialog() ) );
518 openmenu->addAction( qtr( "Open &Network..." ), THEDP,
519 SLOT( openNetDialog() ) );
520 openmenu->addAction( qtr( "Open &Capture Device..." ), THEDP,
521 SLOT( openCaptureDialog() ) );
522 menu->addMenu( openmenu );
524 menu->addSeparator();
525 QMenu *helpmenu = HelpMenu();
526 helpmenu->setTitle( qtr( "Help" ) );
527 menu->addMenu( helpmenu );
529 addDPStaticEntry( menu, qtr( "Quit" ), "", "", SLOT( quit() ) , "Ctrl+Q" );
532 /* Video Tracks and Subtitles tracks */
533 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
538 vlc_object_yield( p_input );
539 varnames.push_back( "video-es" );
540 objects.push_back( p_input->i_object_id );
541 varnames.push_back( "spu-es" );
542 objects.push_back( p_input->i_object_id );
543 vlc_object_t *p_vout = ( vlc_object_t * )vlc_object_find( p_input,
544 VLC_OBJECT_VOUT, FIND_CHILD );
547 VideoAutoMenuBuilder( p_vout, objects, varnames );
548 vlc_object_release( p_vout );
550 vlc_object_release( p_input );
552 QMenu *menu = new QMenu();
557 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
562 vlc_object_yield( p_input );
563 varnames.push_back( "audio-es" );
564 objects.push_back( p_input->i_object_id );
565 vlc_object_t *p_aout = ( vlc_object_t * )vlc_object_find( p_input,
566 VLC_OBJECT_AOUT, FIND_ANYWHERE );
569 AudioAutoMenuBuilder( p_aout, objects, varnames );
570 vlc_object_release( p_aout );
572 vlc_object_release( p_input );
574 QMenu *menu = new QMenu();
578 /* Navigation stuff, and general menus ( open ) */
579 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
586 vlc_object_yield( p_input );
587 varnames.push_back( "audio-es" );
588 InputAutoMenuBuilder( VLC_OBJECT( p_input ), objects, varnames );
592 QMenu *menu = new QMenu();
593 Populate( p_intf, menu, varnames, objects );
595 menu->addSeparator();
596 POPUP_PLAY_ENTRIES( menu );
598 menu->addSeparator();
599 PopupMenuStaticEntries( p_intf, menu );
601 p_intf->p_sys->p_popup_menu = menu;
602 menu->popup( QCursor::pos() );
603 p_intf->p_sys->p_popup_menu = NULL;
606 /* Main Menu that sticks everything together */
607 void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
611 // create a popup if there is none
612 if( ! p_intf->p_sys->p_popup_menu )
617 vlc_object_yield( p_input );
618 InputAutoMenuBuilder( VLC_OBJECT( p_input ), objects, varnames );
622 varnames.push_back( "audio-es" );
623 objects.push_back( p_input->i_object_id );
624 vlc_object_t *p_aout = ( vlc_object_t * )
625 vlc_object_find( p_input, VLC_OBJECT_AOUT, FIND_ANYWHERE );
628 AudioAutoMenuBuilder( p_aout, objects, varnames );
629 vlc_object_release( p_aout );
634 varnames.push_back( "video-es" );
635 objects.push_back( p_input->i_object_id );
636 varnames.push_back( "spu-es" );
637 objects.push_back( p_input->i_object_id );
638 vlc_object_t *p_vout = ( vlc_object_t * )
639 vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD );
642 VideoAutoMenuBuilder( p_vout, objects, varnames );
643 vlc_object_release( p_vout );
647 QMenu *menu = new QMenu();
648 Populate( p_intf, menu, varnames, objects );
649 menu->addSeparator();
650 POPUP_PLAY_ENTRIES( menu );
651 menu->addSeparator();
652 PopupMenuStaticEntries( p_intf, menu );
654 p_intf->p_sys->p_popup_menu = menu;
656 p_intf->p_sys->p_popup_menu->popup( QCursor::pos() );
660 // destroy popup if there is one
661 delete p_intf->p_sys->p_popup_menu;
662 p_intf->p_sys->p_popup_menu = NULL;
666 /************************************************************************
668 ************************************************************************/
670 void QVLCMenu::updateSystrayMenu( MainInterface *mi,
671 intf_thread_t *p_intf,
672 bool b_force_visible )
676 /* Get the systray menu and clean it */
677 QMenu *sysMenu = mi->getSysTrayMenu();
680 /* Hide / Show VLC and cone */
681 if( mi->isVisible() || b_force_visible )
683 sysMenu->addAction( QIcon( ":/vlc16.png" ),
684 qtr( "Hide VLC media player in taskbar" ), mi,
685 SLOT( toggleUpdateSystrayMenu() ) );
689 sysMenu->addAction( QIcon( ":/vlc16.png" ),
690 qtr( "Show VLC media player" ), mi,
691 SLOT( toggleUpdateSystrayMenu() ) );
694 sysMenu->addSeparator();
695 POPUP_PLAY_ENTRIES( sysMenu );
697 sysMenu->addSeparator();
698 addDPStaticEntry( sysMenu, qtr( "&Open Media" ), "",
699 ":/pixmaps/file-wide_16px.png", SLOT( openFileDialog() ), "" );
700 addDPStaticEntry( sysMenu, qtr( "&Quit" ) , "",
701 ":/pixmaps/menus_quit_16px.png", SLOT( quit() ), "" );
704 mi->getSysTray()->setContextMenu( sysMenu );
708 #undef PUSH_SEPARATOR
711 /*************************************************************************
712 * Builders for automenus
713 *************************************************************************/
714 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf,
716 vector< const char *> & varnames,
717 vector<int> & objects,
720 QMenu *menu = current;
728 vlc_object_t *p_object;
729 vlc_bool_t b_section_empty = VLC_FALSE;
732 #define APPEND_EMPTY { QAction *action = menu->addAction( qtr( "Empty" ) ); \
733 action->setEnabled( false ); }
735 for( i = 0; i < ( int )objects.size() ; i++ )
737 if( !varnames[i] || !*varnames[i] )
739 if( b_section_empty )
741 menu->addSeparator();
742 b_section_empty = VLC_TRUE;
746 if( objects[i] == 0 )
748 /// \bug What is this ?
749 // Append( menu, varnames[i], NULL );
750 b_section_empty = VLC_FALSE;
754 p_object = ( vlc_object_t * )vlc_object_get( p_intf, objects[i] );
755 if( p_object == NULL ) continue;
757 b_section_empty = VLC_FALSE;
758 /* Ugly specific stuff */
759 if( strstr( varnames[i], "intf-add" ) )
760 CreateItem( menu, varnames[i], p_object, false );
762 CreateItem( menu, varnames[i], p_object, true );
763 vlc_object_release( p_object );
766 /* Special case for empty menus */
767 if( menu->actions().size() == 0 || b_section_empty )
774 /*****************************************************************************
776 *****************************************************************************/
778 static bool IsMenuEmpty( const char *psz_var,
779 vlc_object_t *p_object,
782 vlc_value_t val, val_list;
783 int i_type, i_result, i;
785 /* Check the type of the object variable */
786 i_type = var_Type( p_object, psz_var );
788 /* Check if we want to display the variable */
789 if( !( i_type & VLC_VAR_HASCHOICE ) ) return false;
791 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
792 if( val.i_int == 0 ) return true;
794 if( ( i_type & VLC_VAR_TYPE ) != VLC_VAR_VARIABLE )
796 /* Very evil hack ! intf-switch can have only one value */
797 if( !strcmp( psz_var, "intf-switch" ) ) return false;
798 if( val.i_int == 1 && b_root ) return true;
802 /* Check children variables in case of VLC_VAR_VARIABLE */
803 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
808 for( i = 0, i_result = true; i < val_list.p_list->i_count; i++ )
810 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
818 /* clean up everything */
819 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
824 void QVLCMenu::CreateItem( QMenu *menu, const char *psz_var,
825 vlc_object_t *p_object, bool b_submenu )
827 vlc_value_t val, text;
830 /* Check the type of the object variable */
831 i_type = var_Type( p_object, psz_var );
833 switch( i_type & VLC_VAR_TYPE )
837 case VLC_VAR_VARIABLE:
839 case VLC_VAR_INTEGER:
843 /* Variable doesn't exist or isn't handled */
847 /* Make sure we want to display the variable */
848 if( IsMenuEmpty( psz_var, p_object ) ) return;
850 /* Get the descriptive name of the variable */
851 var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
853 if( i_type & VLC_VAR_HASCHOICE )
855 /* Append choices menu */
858 QMenu *submenu = new QMenu();
859 submenu->setTitle( qfu( text.psz_string ?
860 text.psz_string : psz_var ) );
861 if( CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0 )
862 menu->addMenu( submenu );
865 CreateChoicesMenu( menu, psz_var, p_object, true );
866 FREENULL( text.psz_string );
870 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
872 switch( i_type & VLC_VAR_TYPE )
875 var_Get( p_object, psz_var, &val );
876 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
877 p_object->i_object_id, val, i_type );
881 var_Get( p_object, psz_var, &val );
882 val.b_bool = !val.b_bool;
883 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
884 p_object->i_object_id, val, i_type, !val.b_bool );
887 FREENULL( text.psz_string );
891 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
892 vlc_object_t *p_object, bool b_root )
894 vlc_value_t val, val_list, text_list;
897 /* Check the type of the object variable */
898 i_type = var_Type( p_object, psz_var );
900 /* Make sure we want to display the variable */
901 if( IsMenuEmpty( psz_var, p_object, b_root ) ) return VLC_EGENERIC;
903 switch( i_type & VLC_VAR_TYPE )
907 case VLC_VAR_VARIABLE:
909 case VLC_VAR_INTEGER:
913 /* Variable doesn't exist or isn't handled */
917 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
918 &val_list, &text_list ) < 0 )
923 #define NORMAL_OR_RADIO i_type & VLC_VAR_ISCOMMAND ? ITEM_NORMAL: ITEM_RADIO
924 #define NOTCOMMAND !( i_type & VLC_VAR_ISCOMMAND )
925 #define CURVAL val_list.p_list->p_values[i]
926 #define CURTEXT text_list.p_list->p_values[i].psz_string
928 for( i = 0; i < val_list.p_list->i_count; i++ )
930 vlc_value_t another_val;
932 QMenu *subsubmenu = new QMenu();
934 switch( i_type & VLC_VAR_TYPE )
936 case VLC_VAR_VARIABLE:
937 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
938 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
939 submenu->addMenu( subsubmenu );
943 var_Get( p_object, psz_var, &val );
944 another_val.psz_string = strdup( CURVAL.psz_string );
945 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
946 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
947 p_object->i_object_id, another_val, i_type,
948 NOTCOMMAND && val.psz_string &&
949 !strcmp( val.psz_string, CURVAL.psz_string ) );
951 if( val.psz_string ) free( val.psz_string );
954 case VLC_VAR_INTEGER:
955 var_Get( p_object, psz_var, &val );
956 if( CURTEXT ) menutext = qfu( CURTEXT );
957 else menutext.sprintf( "%d", CURVAL.i_int );
958 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
959 p_object->i_object_id, CURVAL, i_type,
960 NOTCOMMAND && CURVAL.i_int == val.i_int );
964 var_Get( p_object, psz_var, &val );
965 if( CURTEXT ) menutext = qfu( CURTEXT );
966 else menutext.sprintf( "%.2f", CURVAL.f_float );
967 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
968 p_object->i_object_id, CURVAL, i_type,
969 NOTCOMMAND && CURVAL.f_float == val.f_float );
978 /* clean up everything */
979 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
981 #undef NORMAL_OR_RADIO
988 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
989 QString text, QString help,
990 int i_item_type, int i_object_id,
991 vlc_value_t val, int i_val_type,
994 QAction *action = new QAction( text, menu );
995 action->setText( text );
996 action->setToolTip( help );
998 if( i_item_type == ITEM_CHECK )
1000 action->setCheckable( true );
1002 else if( i_item_type == ITEM_RADIO )
1004 action->setCheckable( true );
1006 currentGroup = new QActionGroup( menu );
1007 currentGroup->addAction( action );
1012 action->setChecked( true );
1014 MenuItemData *itemData = new MenuItemData( i_object_id, i_val_type,
1016 CONNECT( action, triggered(), THEDP->menusMapper, map() );
1017 THEDP->menusMapper->setMapping( action, itemData );
1018 menu->addAction( action );
1021 void QVLCMenu::DoAction( intf_thread_t *p_intf, QObject *data )
1023 MenuItemData *itemData = qobject_cast<MenuItemData *>( data );
1024 vlc_object_t *p_object = ( vlc_object_t * )vlc_object_get( p_intf,
1025 itemData->i_object_id );
1026 if( p_object == NULL ) return;
1028 var_Set( p_object, itemData->psz_var, itemData->val );
1029 vlc_object_release( p_object );