]> git.sesse.net Git - vlc/blob - modules/gui/qt4/menus.hpp
[Qt] Privatise what can be privatised in menu class
[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 _MENUS_H_
26 #define _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         i_val_type = _i_type;
57         val = _val;
58         psz_var = strdup( _var );
59     }
60     virtual ~MenuItemData()
61     {
62         free( psz_var );
63         if( ( i_val_type & VLC_VAR_TYPE) == VLC_VAR_STRING )
64             free( val.psz_string );
65     }
66
67     vlc_object_t *p_obj;
68     vlc_value_t val;
69     char *psz_var;
70
71 private:
72     int i_val_type;
73 };
74
75 class QVLCMenu : public QObject
76 {
77     Q_OBJECT;
78     friend class MenuFunc;
79
80 public:
81     /* Main bar creation */
82     static void createMenuBar( MainInterface *mi, intf_thread_t *, bool );
83
84     /* Popups Menus */
85     static void PopupMenu( intf_thread_t *, bool );
86     static void AudioPopupMenu( intf_thread_t * );
87     static void VideoPopupMenu( intf_thread_t * );
88     static void MiscPopupMenu( intf_thread_t * );
89
90     /* Systray */
91     static void updateSystrayMenu( MainInterface *,intf_thread_t  *,
92                                    bool b_force_visible = false);
93
94     /* Actions */
95     static void DoAction( intf_thread_t *, QObject * );
96
97     /* HACK for minimalView */
98     static QAction *minimalViewAction;
99
100 private:
101     /* All main Menus */
102     static QMenu *FileMenu( intf_thread_t * );
103     static QMenu *SDMenu( intf_thread_t * );
104     static QMenu *ToolsMenu( intf_thread_t * );
105     static QMenu *ViewMenu( intf_thread_t *, QMenu *, MainInterface *,
106                              bool, bool with = true );
107     static QMenu *NavigMenu( intf_thread_t *, QMenu * );
108     static QMenu *VideoMenu( intf_thread_t *, QMenu * );
109     static QMenu *AudioMenu( intf_thread_t *, QMenu * );
110     static QMenu *InterfacesMenu( intf_thread_t *p_intf, QMenu * );
111     static QMenu *HelpMenu( QMenu * );
112
113     /* Popups Menus */
114     static void PopupMenuStaticEntries( intf_thread_t *p_intf, QMenu *menu );
115     static void PopupMenuControlEntries( QMenu *menu, intf_thread_t *p_intf,
116                                          input_thread_t *p_input );
117     /* Generic automenu methods */
118     static QMenu * Populate( intf_thread_t *, QMenu *current,
119                              vector<const char*>&, vector<vlc_object_t *>&,
120                              bool append = false );
121
122     static void CreateAndConnect( QMenu *, const char *, QString, QString,
123                                   int, vlc_object_t *, vlc_value_t, int, bool c = false );
124     static void UpdateItem( intf_thread_t *, QMenu *, const char *,
125                             vlc_object_t *, bool );
126     static int CreateChoicesMenu( QMenu *,const char *, vlc_object_t *, bool );
127
128     /* recentMRL menu */
129     static QMenu *recentsMenu;
130
131 public slots:
132     static void updateRecents( intf_thread_t * );
133 };
134
135 class MenuFunc : public QObject
136 {
137     Q_OBJECT
138
139 public:
140     MenuFunc( QMenu *_menu, int _id ) { menu = _menu; id = _id; };
141     void doFunc( intf_thread_t *p_intf)
142     {
143         switch( id )
144         {
145             case 1: QVLCMenu::AudioMenu( p_intf, menu ); break;
146             case 2: QVLCMenu::VideoMenu( p_intf, menu ); break;
147             case 3: QVLCMenu::NavigMenu( p_intf, menu ); break;
148             case 4: QVLCMenu::InterfacesMenu( p_intf, menu ); break;
149         }
150     };
151 private:
152     int id;
153     QMenu *menu;
154 };
155
156 #endif