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