]> git.sesse.net Git - vlc/blob - modules/gui/qt4/input_manager.hpp
98f5c1d86d197dca959615320737eab835b007d0
[vlc] / modules / gui / qt4 / input_manager.hpp
1 /*****************************************************************************
2  * input_manager.hpp : Manage an input and interact with its GUI elements
3  ****************************************************************************
4  * Copyright (C) 2006-2008 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *          Jean-Baptiste <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_INPUT_MANAGER_H_
26 #define QVLC_INPUT_MANAGER_H_
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <vlc_input.h>
33
34 #include "qt4.hpp"
35
36 #include <QObject>
37 #include <QEvent>
38
39
40 enum {
41     PositionUpdate_Type = QEvent::User + IMEventType + 1,
42     ItemChanged_Type,
43     ItemStateChanged_Type,
44     ItemTitleChanged_Type,
45     ItemRateChanged_Type,
46     VolumeChanged_Type,
47     ItemEsChanged_Type,
48     ItemTeletextChanged_Type,
49     InterfaceVoutUpdate_Type,
50     StatisticsUpdate_Type, /*10*/
51     InterfaceAoutUpdate_Type,
52     MetaChanged_Type,
53     NameChanged_Type,
54     InfoChanged_Type,
55     SynchroChanged_Type,
56     CachingEvent_Type,
57     BookmarksChanged_Type,
58     RecordingEvent_Type,
59     ProgramChanged_Type,
60     RandomChanged_Type,
61 /*    SignalChanged_Type, */
62
63     FullscreenControlToggle_Type = QEvent::User + IMEventType + 20,
64     FullscreenControlShow_Type,
65     FullscreenControlHide_Type,
66     FullscreenControlPlanHide_Type,
67 };
68
69 class IMEvent : public QEvent
70 {
71 friend class InputManager;
72     public:
73     IMEvent( int type, input_item_t *p_input = NULL )
74         : QEvent( (QEvent::Type)(type) )
75     {
76         if( (p_item = p_input) != NULL )
77             vlc_gc_incref( p_item );
78     }
79     virtual ~IMEvent()
80     {
81         if( p_item )
82             vlc_gc_decref( p_item );
83     }
84
85 private:
86     input_item_t *p_item;
87 };
88
89 enum PLEventTypes
90 {
91     PLItemAppended_Type = QEvent::User + PLEventType + 1,
92     PLItemRemoved_Type
93 };
94
95 class PLEvent : public QEvent
96 {
97 public:
98     PLEvent( PLEventTypes t, int i, int p )
99         : QEvent( (QEvent::Type)t ), i_item(i), i_parent(p) {}
100     int i_item;
101     int i_parent;
102 };
103
104 class InputManager : public QObject
105 {
106     Q_OBJECT;
107     friend class MainInputManager;
108
109 public:
110     InputManager( QObject *, intf_thread_t * );
111     virtual ~InputManager();
112
113     void delInput();
114     bool hasInput()
115     {
116         return p_input /* We have an input */
117             && !p_input->b_dead /* not dead yet, */
118             && !p_input->b_eof  /* not EOF either, */
119             && vlc_object_alive (p_input); /* and the VLC object is alive */
120     }
121
122     bool hasAudio();
123     bool hasVideo() { return hasInput() && b_video; }
124     void requestArtUpdate();
125
126     QString getName() { return oldName; }
127
128 private:
129     intf_thread_t  *p_intf;
130     input_thread_t *p_input;
131     input_item_t   *p_item;
132     int             i_old_playing_status;
133     QString         oldName;
134     QString         artUrl;
135     int             i_rate;
136     float           f_cache;
137     bool            b_video;
138     mtime_t         timeA, timeB;
139
140     void customEvent( QEvent * );
141
142     void addCallbacks();
143     void delCallbacks();
144
145     void UpdateRate();
146     void UpdateName();
147     void UpdateStatus();
148     void UpdateNavigation();
149     void UpdatePosition();
150     void UpdateTeletext();
151     void UpdateArt();
152     void UpdateInfo();
153     void UpdateMeta();
154     void UpdateMeta(input_item_t *);
155     void UpdateVout();
156     void UpdateAout();
157     void UpdateStats();
158     void UpdateCaching();
159     void UpdateRecord();
160     void UpdateProgramEvent();
161
162 public slots:
163     void setInput( input_thread_t * ); ///< Our controlled input changed
164     void sliderUpdate( float ); ///< User dragged the slider. We get new pos
165     /* SpeedRate Rate Management */
166     void reverse();
167     void slower();
168     void faster();
169     void littlefaster();
170     void littleslower();
171     void normalRate();
172     void setRate( int );
173     /* Jumping */
174     void jumpFwd();
175     void jumpBwd();
176     /* Menus */
177     void sectionNext();
178     void sectionPrev();
179     void sectionMenu();
180     /* Teletext */
181     void telexSetPage( int );          ///< Goto teletext page
182     void telexSetTransparency( bool ); ///< Transparency on teletext background
183     void activateTeletext( bool );     ///< Toggle buttons after click
184     /* A to B Loop */
185     void setAtoB();
186
187 private slots:
188     void togglePlayPause();
189     void AtoBLoop( float, int, int );
190
191 signals:
192     /// Send new position, new time and new length
193     void positionUpdated( float , int, int );
194     void rateChanged( int );
195     void nameChanged( const QString& );
196     /// Used to signal whether we should show navigation buttons
197     void titleChanged( bool );
198     void chapterChanged( bool );
199     /// Statistics are updated
200     void statisticsUpdated( input_item_t* );
201     void infoChanged( input_item_t* );
202     void currentMetaChanged( input_item_t* );
203     void metaChanged( input_item_t *);
204     void artChanged( QString );
205     /// Play/pause status
206     void statusChanged( int );
207     void recordingStateChanged( bool );
208     /// Teletext
209     void teletextPossible( bool );
210     void teletextActivated( bool );
211     void teletextTransparencyActivated( bool );
212     void newTelexPageSet( int );
213     /// Advanced buttons
214     void AtoBchanged( bool, bool );
215     /// Vout
216     void voutChanged( bool );
217     void voutListChanged( vout_thread_t **pp_vout, int i_vout );
218     /// Other
219     void synchroChanged();
220     void bookmarksChanged();
221     void cachingChanged( float );
222     /// Program Event changes
223     void encryptionChanged( bool );
224 };
225
226 class MainInputManager : public QObject
227 {
228     Q_OBJECT;
229 public:
230     static MainInputManager *getInstance( intf_thread_t *_p_intf )
231     {
232         if( !instance )
233             instance = new MainInputManager( _p_intf );
234         return instance;
235     }
236     static void killInstance()
237     {
238         delete instance;
239         instance = NULL;
240     }
241
242     input_thread_t *getInput() { return p_input; }
243     InputManager *getIM() { return im; }
244
245     vout_thread_t* getVout();
246     aout_instance_t *getAout();
247
248 private:
249     MainInputManager( intf_thread_t * );
250     virtual ~MainInputManager();
251
252     static MainInputManager *instance;
253
254     void customEvent( QEvent * );
255
256     InputManager            *im;
257     input_thread_t          *p_input;
258     intf_thread_t           *p_intf;
259
260 public slots:
261     void togglePlayPause();
262     void toggleRandom();
263     void stop();
264     void next();
265     void prev();
266     void activatePlayQuit( bool );
267
268 signals:
269     void inputChanged( input_thread_t * );
270     void volumeChanged();
271     void playlistItemAppended( int itemId, int parentId );
272     void playlistItemRemoved( int itemId );
273     void randomChanged( bool );
274 };
275
276 #endif