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