1 /*****************************************************************************
2 * menus.hpp : Menus handling
3 ****************************************************************************
4 * Copyright (C) 2006 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 *****************************************************************************/
37 class QSystemTrayIcon;
39 class MenuItemData : public QObject
44 MenuItemData( QObject* parent, vlc_object_t *_p_obj, int _i_type,
45 vlc_value_t _val, const char *_var ) : QObject( parent )
49 vlc_object_hold( p_obj );
52 psz_var = strdup( _var );
54 virtual ~MenuItemData()
57 if( ( i_val_type & VLC_VAR_TYPE) == VLC_VAR_STRING )
58 free( val.psz_string );
60 vlc_object_release( p_obj );
71 class VLCMenuBar : public QObject
74 friend class MenuFunc;
77 /* Main bar creation */
78 static void createMenuBar( MainInterface *mi, intf_thread_t * );
81 static void PopupMenu( intf_thread_t *, bool );
82 static void AudioPopupMenu( intf_thread_t *, bool );
83 static void VideoPopupMenu( intf_thread_t *, bool );
84 static void MiscPopupMenu( intf_thread_t *, bool );
87 static void updateSystrayMenu( MainInterface *, intf_thread_t *,
88 bool b_force_visible = false);
91 static void DoAction( QObject * );
94 ACTION_ALWAYS_ENABLED = 0x1,
95 ACTION_MANAGED = 0x2, /* managed using EnableStatic(bool)? */
96 ACTION_NO_CLEANUP = 0x4,
97 ACTION_STATIC = 0x6, /* legacy shortcut */
98 ACTION_DELETE_ON_REBUILD = 0x8
100 Q_DECLARE_FLAGS(actionflags, actionflag)
104 static QMenu *FileMenu( intf_thread_t *, QWidget *, MainInterface * mi = NULL );
106 static QMenu *ToolsMenu( intf_thread_t *, QMenu * );
107 static QMenu *ToolsMenu( intf_thread_t * p_intf, QWidget *parent )
108 { return ToolsMenu( p_intf, new QMenu( parent ) ); }
110 static QMenu *ViewMenu( intf_thread_t *, QMenu *, MainInterface * mi = NULL );
112 static QMenu *InterfacesMenu( intf_thread_t *p_intf, QMenu * );
113 static void ExtensionsMenu( intf_thread_t *p_intf, QMenu * );
115 static QMenu *NavigMenu( intf_thread_t *, QMenu * );
116 static QMenu *NavigMenu( intf_thread_t *p_intf, QWidget *parent ) {
117 return NavigMenu( p_intf, new QMenu( parent ) );
119 static QMenu *RebuildNavigMenu( intf_thread_t *, QMenu *, bool b_keep = false );
121 static QMenu *VideoMenu( intf_thread_t *, QMenu *, bool b_subtitle = false );
122 static QMenu *VideoMenu( intf_thread_t *p_intf, QWidget *parent ) {
123 return VideoMenu( p_intf, new QMenu( parent ) );
125 static QMenu *SubtitleMenu( intf_thread_t *, QMenu *current);
126 static QMenu *SubtitleMenu( intf_thread_t *p_intf, QWidget *parent) {
127 return SubtitleMenu( p_intf, new QMenu( parent ) );
130 static QMenu *AudioMenu( intf_thread_t *, QMenu * );
131 static QMenu *AudioMenu( intf_thread_t *p_intf, QWidget *parent ) {
132 return AudioMenu( p_intf, new QMenu( parent ) );
135 static QMenu *HelpMenu( QWidget * );
138 static void PopupMenuStaticEntries( QMenu *menu );
139 static void PopupMenuPlaylistEntries( QMenu *menu, intf_thread_t *p_intf,
140 input_thread_t *p_input );
141 static void PopupMenuPlaylistControlEntries( QMenu *menu, intf_thread_t *p_intf );
142 static void PopupMenuControlEntries( QMenu *menu, intf_thread_t *p_intf, bool b = true );
144 /* Generic automenu methods */
145 static QMenu * Populate( intf_thread_t *, QMenu *current,
146 QVector<const char*>&, QVector<vlc_object_t *>& );
148 static void CreateAndConnect( QMenu *, const char *, const QString&,
149 const QString&, int, vlc_object_t *,
150 vlc_value_t, int, bool c = false );
151 static void UpdateItem( intf_thread_t *, QMenu *, const char *,
152 vlc_object_t *, bool );
153 static int CreateChoicesMenu( QMenu *,const char *, vlc_object_t *, bool );
154 static void EnableStaticEntries( QMenu *, bool );
157 static QMenu *recentsMenu, *audioDeviceMenu;
159 static void updateAudioDevice( intf_thread_t *, audio_output_t *, QMenu* );
162 static void updateRecents( intf_thread_t * );
164 Q_DECLARE_OPERATORS_FOR_FLAGS(VLCMenuBar::actionflags)
166 class MenuFunc : public QObject
171 MenuFunc( QMenu *_menu, int _id ) : QObject( (QObject *)_menu ),
172 menu( _menu ), id( _id ){}
174 void doFunc( intf_thread_t *p_intf)
178 case 1: VLCMenuBar::AudioMenu( p_intf, menu ); break;
179 case 2: VLCMenuBar::VideoMenu( p_intf, menu ); break;
180 case 3: VLCMenuBar::RebuildNavigMenu( p_intf, menu ); break;
181 case 4: VLCMenuBar::ViewMenu( p_intf, menu ); break;
182 case 5: VLCMenuBar::SubtitleMenu( p_intf, menu ); break;