]> git.sesse.net Git - vlc/blob - modules/gui/qt4/menus.hpp
Qt: rebuild correctly the playback menu
[vlc] / modules / gui / qt4 / menus.hpp
1 /*****************************************************************************
2  * menus.hpp : Menus handling
3  ****************************************************************************
4  * Copyright (C) 2006 the VideoLAN team
5  * $Id$
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 "qt4.hpp"
29
30 #include <QObject>
31 #include <QMenu>
32 #include <QVector>
33
34 using namespace std;
35
36 class QMenuBar;
37 class QSystemTrayIcon;
38
39 class MenuItemData : public QObject
40 {
41     Q_OBJECT
42
43 public:
44     MenuItemData( QObject* parent, vlc_object_t *_p_obj, int _i_type,
45                   vlc_value_t _val, const char *_var ) : QObject( parent )
46     {
47         p_obj = _p_obj;
48         if( p_obj )
49             vlc_object_hold( p_obj );
50         i_val_type = _i_type;
51         val = _val;
52         psz_var = strdup( _var );
53     }
54     virtual ~MenuItemData()
55     {
56         free( psz_var );
57         if( ( i_val_type & VLC_VAR_TYPE) == VLC_VAR_STRING )
58             free( val.psz_string );
59         if( p_obj )
60             vlc_object_release( p_obj );
61     }
62
63     vlc_object_t *p_obj;
64     vlc_value_t val;
65     char *psz_var;
66
67 private:
68     int i_val_type;
69 };
70
71 class VLCMenuBar : public QObject
72 {
73     Q_OBJECT
74     friend class MenuFunc;
75
76 public:
77     /* Main bar creation */
78     static void createMenuBar( MainInterface *mi, intf_thread_t * );
79
80     /* Popups Menus */
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 );
85
86     /* Systray */
87     static void updateSystrayMenu( MainInterface *, intf_thread_t  *,
88                                    bool b_force_visible = false);
89
90     /* Actions */
91     static void DoAction( QObject * );
92     enum actionflag {
93         ACTION_NONE = 0x0,
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     };
99     Q_DECLARE_FLAGS(actionflags, actionflag)
100
101 private:
102     /* All main Menus */
103     static QMenu *FileMenu( intf_thread_t *, QWidget *, MainInterface * mi = NULL );
104
105     static QMenu *ToolsMenu( QMenu * );
106     static QMenu *ToolsMenu( QWidget *parent ) { return ToolsMenu( 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 * );
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 *, bool b_subtitle = true );
120     static QMenu *VideoMenu( intf_thread_t *p_intf, QWidget *parent ) {
121         return VideoMenu( p_intf, new QMenu( parent ) );
122     }
123     static QMenu *SubtitleMenu( QMenu *current);
124
125     static QMenu *AudioMenu( intf_thread_t *, QMenu * );
126     static QMenu *AudioMenu( intf_thread_t *p_intf, QWidget *parent ) {
127         return AudioMenu( p_intf, new QMenu( parent ) );
128     }
129
130     static QMenu *HelpMenu( QWidget * );
131
132     /* Popups Menus */
133     static void PopupMenuStaticEntries( QMenu *menu );
134     static void PopupPlayEntries( QMenu *menu, intf_thread_t *p_intf,
135                                          input_thread_t *p_input );
136     static void PopupMenuControlEntries( QMenu *menu, intf_thread_t *p_intf, bool b = true );
137     static void PopupMenuPlaylistControlEntries( QMenu *menu, intf_thread_t *p_intf );
138
139     /* Generic automenu methods */
140     static QMenu * Populate( intf_thread_t *, QMenu *current,
141                              QVector<const char*>&, QVector<vlc_object_t *>& );
142
143     static void CreateAndConnect( QMenu *, const char *, const QString&,
144                                   const QString&, int, vlc_object_t *,
145                                   vlc_value_t, int, bool c = false );
146     static void UpdateItem( intf_thread_t *, QMenu *, const char *,
147                             vlc_object_t *, bool );
148     static int CreateChoicesMenu( QMenu *,const char *, vlc_object_t *, bool );
149     static void EnableStaticEntries( QMenu *, bool );
150
151     /* recentMRL menu */
152     static QMenu *recentsMenu;
153
154 public slots:
155     static void updateRecents( intf_thread_t * );
156 };
157 Q_DECLARE_OPERATORS_FOR_FLAGS(VLCMenuBar::actionflags)
158
159 class MenuFunc : public QObject
160 {
161     Q_OBJECT
162
163 public:
164     MenuFunc( QMenu *_menu, int _id ) : QObject( (QObject *)_menu ),
165                                         menu( _menu ), id( _id ){}
166
167     void doFunc( intf_thread_t *p_intf)
168     {
169         switch( id )
170         {
171             case 1: VLCMenuBar::AudioMenu( p_intf, menu ); break;
172             case 2: VLCMenuBar::VideoMenu( p_intf, menu ); break;
173             case 3: VLCMenuBar::RebuildNavigMenu( p_intf, menu ); break;
174             case 4: VLCMenuBar::ViewMenu( p_intf, menu ); break;
175         }
176     }
177 private:
178     QMenu *menu;
179     int id;
180 };
181
182 #endif