1 /*****************************************************************************
2  * menus.hpp : Menus handling
3  ****************************************************************************
4  * Copyright (C) 2006 the VideoLAN team
5  * $Id: 99ea6579868f4323da9eacea8f5d46d268e778fc $
6  *
7  * Authors: Clément Stenac <zorglub@videolan.org>
8  *          Jean-Baptiste Kempf <jb@videolan.org>
9  *
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.
14  *
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.
19  *
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  *****************************************************************************/
24 
25 #ifndef QVLC_MENUS_H_
26 #define QVLC_MENUS_H_
27 
28 #include "qt.hpp"
29 
30 #include <QObject>
31 #include <QMenu>
32 #include <QVector>
33 
34 class MenuItemData : public QObject
35 {
36     Q_OBJECT
37 
38 public:
MenuItemData(QObject * parent,vlc_object_t * _p_obj,int _i_type,vlc_value_t _val,const char * _var)39     MenuItemData( QObject* parent, vlc_object_t *_p_obj, int _i_type,
40                   vlc_value_t _val, const char *_var ) : QObject( parent )
41     {
42         p_obj = _p_obj;
43         if( p_obj )
44             vlc_object_hold( p_obj );
45         i_val_type = _i_type;
46         val = _val;
47         psz_var = strdup( _var );
48     }
~MenuItemData()49     virtual ~MenuItemData()
50     {
51         free( psz_var );
52         if( ( i_val_type & VLC_VAR_TYPE) == VLC_VAR_STRING )
53             free( val.psz_string );
54         if( p_obj )
55             vlc_object_release( p_obj );
56     }
57 
58     vlc_object_t *p_obj;
59     vlc_value_t val;
60     char *psz_var;
61 
62 private:
63     int i_val_type;
64 };
65 
66 class VLCMenuBar : public QObject
67 {
68     Q_OBJECT
69     friend class MenuFunc;
70 
71 public:
72     /* Main bar creation */
73     static void createMenuBar( MainInterface *mi, intf_thread_t * );
74 
75     /* Popups Menus */
76     static QMenu* PopupMenu( intf_thread_t *, bool );
77     static QMenu* AudioPopupMenu( intf_thread_t *, bool );
78     static QMenu* VideoPopupMenu( intf_thread_t *, bool );
79     static QMenu* MiscPopupMenu( intf_thread_t *, bool );
80 
81     /* Systray */
82     static void updateSystrayMenu( MainInterface *, intf_thread_t  *,
83                                    bool b_force_visible = false);
84 
85     /* Actions */
86     static void DoAction( QObject * );
87     enum actionflag {
88         ACTION_NONE = 0x0,
89         ACTION_ALWAYS_ENABLED = 0x1,
90         ACTION_MANAGED = 0x2, /* managed using EnableStatic(bool)? */
91         ACTION_NO_CLEANUP = 0x4,
92         ACTION_STATIC = 0x6, /* legacy shortcut */
93         ACTION_DELETE_ON_REBUILD = 0x8
94     };
95     Q_DECLARE_FLAGS(actionflags, actionflag)
96 
97     static QMenu *rendererMenu;
98     static QActionGroup *rendererGroup;
99 
100 private:
101     /* All main Menus */
102     static QMenu *FileMenu( intf_thread_t *, QWidget *, MainInterface * mi = NULL );
103 
104     static QMenu *ToolsMenu( intf_thread_t *, QMenu * );
ToolsMenu(intf_thread_t * p_intf,QWidget * parent)105     static QMenu *ToolsMenu( intf_thread_t * p_intf, QWidget *parent )
106         { return ToolsMenu( p_intf, new QMenu( parent ) ); }
107 
108     static QMenu *ViewMenu( intf_thread_t *, QMenu *, MainInterface * mi = NULL );
109 
110     static QMenu *InterfacesMenu( intf_thread_t *p_intf, QMenu * );
111     static void ExtensionsMenu( intf_thread_t *p_intf, QMenu * );
112 
113     static QMenu *NavigMenu( intf_thread_t *, QMenu * );
NavigMenu(intf_thread_t * p_intf,QWidget * parent)114     static QMenu *NavigMenu( intf_thread_t *p_intf, QWidget *parent ) {
115         return NavigMenu( p_intf, new QMenu( parent ) );
116     }
117     static QMenu *RebuildNavigMenu( intf_thread_t *, QMenu *, bool b_keep = false );
118 
119     static QMenu *VideoMenu( intf_thread_t *, QMenu * );
VideoMenu(intf_thread_t * p_intf,QWidget * parent)120     static QMenu *VideoMenu( intf_thread_t *p_intf, QWidget *parent ) {
121         return VideoMenu( p_intf, new QMenu( parent ) );
122     }
123     static QMenu *SubtitleMenu( intf_thread_t *, QMenu *current, bool b_popup = false );
SubtitleMenu(intf_thread_t * p_intf,QWidget * parent)124     static QMenu *SubtitleMenu( intf_thread_t *p_intf, QWidget *parent) {
125         return SubtitleMenu( p_intf, new QMenu( parent ) );
126     }
127 
128     static QMenu *AudioMenu( intf_thread_t *, QMenu * );
AudioMenu(intf_thread_t * p_intf,QWidget * parent)129     static QMenu *AudioMenu( intf_thread_t *p_intf, QWidget *parent ) {
130         return AudioMenu( p_intf, new QMenu( parent ) );
131     }
132 
133     static QMenu *HelpMenu( QWidget * );
134     static QMenu *RendererMenu(intf_thread_t *p_intf , QMenu *menu = NULL );
135 
136     /* Popups Menus */
137     static void PopupMenuStaticEntries( QMenu *menu );
138     static void PopupMenuPlaylistEntries( QMenu *menu, intf_thread_t *p_intf,
139                                           input_thread_t *p_input );
140     static void PopupMenuPlaylistControlEntries( QMenu *menu, intf_thread_t *p_intf );
141     static void PopupMenuControlEntries( QMenu *menu, intf_thread_t *p_intf, bool b = true );
142 
143     /* Generic automenu methods */
144     static QMenu * Populate( intf_thread_t *, QMenu *current,
145                              QVector<const char*>&, QVector<vlc_object_t *>& );
146 
147     static void CreateAndConnect( QMenu *, const char *, const QString&,
148                                   const QString&, int, vlc_object_t *,
149                                   vlc_value_t, int, bool c = false );
150     static void UpdateItem( intf_thread_t *, QMenu *, const char *,
151                             vlc_object_t *, bool );
152     static int CreateChoicesMenu( QMenu *,const char *, vlc_object_t * );
153     static void EnableStaticEntries( QMenu *, bool );
154 
155     /* recentMRL menu */
156     static QMenu *recentsMenu, *audioDeviceMenu;
157 
158     static void updateAudioDevice( intf_thread_t *, audio_output_t *, QMenu* );
159 
160 public slots:
161     static void updateRecents( intf_thread_t * );
162 };
163 Q_DECLARE_OPERATORS_FOR_FLAGS(VLCMenuBar::actionflags)
164 
165 class MenuFunc : public QObject
166 {
167     Q_OBJECT
168 
169 public:
MenuFunc(QMenu * _menu,int _id)170     MenuFunc( QMenu *_menu, int _id ) : QObject( (QObject *)_menu ),
171                                         menu( _menu ), id( _id ){}
172 
doFunc(intf_thread_t * p_intf)173     void doFunc( intf_thread_t *p_intf)
174     {
175         switch( id )
176         {
177             case 1: VLCMenuBar::AudioMenu( p_intf, menu ); break;
178             case 2: VLCMenuBar::VideoMenu( p_intf, menu ); break;
179             case 3: VLCMenuBar::RebuildNavigMenu( p_intf, menu ); break;
180             case 4: VLCMenuBar::ViewMenu( p_intf, menu ); break;
181             case 5: VLCMenuBar::SubtitleMenu( p_intf, menu ); break;
182         }
183     }
184 private:
185     QMenu *menu;
186     int id;
187 };
188 
189 #endif
190