]> git.sesse.net Git - vlc/blob - modules/gui/qt4/input_manager.hpp
03a7f358eb825c5df4b9882800f432f05ae2421e
[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     LoopChanged_Type,
62     RepeatChanged_Type,
63 /*    SignalChanged_Type, */
64
65     FullscreenControlToggle_Type = QEvent::User + IMEventType + 20,
66     FullscreenControlShow_Type,
67     FullscreenControlHide_Type,
68     FullscreenControlPlanHide_Type,
69 };
70
71 enum { NORMAL,    /* loop: 0, repeat: 0 */
72        REPEAT_ONE,/* loop: 1, repeat: 0 */
73        REPEAT_ALL,/* loop: 0, repeat: 1 */
74 };
75
76 class IMEvent : public QEvent
77 {
78 friend class InputManager;
79     public:
80     IMEvent( int type, input_item_t *p_input = NULL )
81         : QEvent( (QEvent::Type)(type) )
82     {
83         if( (p_item = p_input) != NULL )
84             vlc_gc_incref( p_item );
85     }
86     virtual ~IMEvent()
87     {
88         if( p_item )
89             vlc_gc_decref( p_item );
90     }
91
92 private:
93     input_item_t *p_item;
94 };
95
96 enum PLEventTypes
97 {
98     PLItemAppended_Type = QEvent::User + PLEventType + 1,
99     PLItemRemoved_Type
100 };
101
102 class PLEvent : public QEvent
103 {
104 public:
105     PLEvent( PLEventTypes t, int i, int p )
106         : QEvent( (QEvent::Type)t ), i_item(i), i_parent(p) {}
107     int i_item;
108     int i_parent;
109 };
110
111 class InputManager : public QObject
112 {
113     Q_OBJECT;
114     friend class MainInputManager;
115
116 public:
117     InputManager( QObject *, intf_thread_t * );
118     virtual ~InputManager();
119
120     void delInput();
121     bool hasInput()
122     {
123         return p_input /* We have an input */
124             && !p_input->b_dead /* not dead yet, */
125             && !p_input->b_eof  /* not EOF either, */
126             && vlc_object_alive (p_input); /* and the VLC object is alive */
127     }
128
129     bool hasAudio();
130     bool hasVideo() { return hasInput() && b_video; }
131     void requestArtUpdate();
132
133     QString getName() { return oldName; }
134
135 private:
136     intf_thread_t  *p_intf;
137     input_thread_t *p_input;
138     input_item_t   *p_item;
139     int             i_old_playing_status;
140     QString         oldName;
141     QString         artUrl;
142     int             i_rate;
143     float           f_cache;
144     bool            b_video;
145     mtime_t         timeA, timeB;
146
147     void customEvent( QEvent * );
148
149     void addCallbacks();
150     void delCallbacks();
151
152     void UpdateRate();
153     void UpdateName();
154     void UpdateStatus();
155     void UpdateNavigation();
156     void UpdatePosition();
157     void UpdateTeletext();
158     void UpdateArt();
159     void UpdateInfo();
160     void UpdateMeta();
161     void UpdateMeta(input_item_t *);
162     void UpdateVout();
163     void UpdateAout();
164     void UpdateStats();
165     void UpdateCaching();
166     void UpdateRecord();
167     void UpdateProgramEvent();
168
169 public slots:
170     void setInput( input_thread_t * ); ///< Our controlled input changed
171     void sliderUpdate( float ); ///< User dragged the slider. We get new pos
172     /* SpeedRate Rate Management */
173     void reverse();
174     void slower();
175     void faster();
176     void littlefaster();
177     void littleslower();
178     void normalRate();
179     void setRate( int );
180     /* Jumping */
181     void jumpFwd();
182     void jumpBwd();
183     /* Menus */
184     void sectionNext();
185     void sectionPrev();
186     void sectionMenu();
187     /* Teletext */
188     void telexSetPage( int );          ///< Goto teletext page
189     void telexSetTransparency( bool ); ///< Transparency on teletext background
190     void activateTeletext( bool );     ///< Toggle buttons after click
191     /* A to B Loop */
192     void setAtoB();
193
194 private slots:
195     void togglePlayPause();
196     void AtoBLoop( float, int, int );
197
198 signals:
199     /// Send new position, new time and new length
200     void positionUpdated( float , int, int );
201     void rateChanged( int );
202     void nameChanged( const QString& );
203     /// Used to signal whether we should show navigation buttons
204     void titleChanged( bool );
205     void chapterChanged( bool );
206     /// Statistics are updated
207     void statisticsUpdated( input_item_t* );
208     void infoChanged( input_item_t* );
209     void currentMetaChanged( input_item_t* );
210     void metaChanged( input_item_t *);
211     void artChanged( QString );
212     /// Play/pause status
213     void statusChanged( int );
214     void recordingStateChanged( bool );
215     /// Teletext
216     void teletextPossible( bool );
217     void teletextActivated( bool );
218     void teletextTransparencyActivated( bool );
219     void newTelexPageSet( int );
220     /// Advanced buttons
221     void AtoBchanged( bool, bool );
222     /// Vout
223     void voutChanged( bool );
224     void voutListChanged( vout_thread_t **pp_vout, int i_vout );
225     /// Other
226     void synchroChanged();
227     void bookmarksChanged();
228     void cachingChanged( float );
229     /// Program Event changes
230     void encryptionChanged( bool );
231 };
232
233 class MainInputManager : public QObject
234 {
235     Q_OBJECT;
236 public:
237     static MainInputManager *getInstance( intf_thread_t *_p_intf )
238     {
239         if( !instance )
240             instance = new MainInputManager( _p_intf );
241         return instance;
242     }
243     static void killInstance()
244     {
245         delete instance;
246         instance = NULL;
247     }
248
249     input_thread_t *getInput() { return p_input; }
250     InputManager *getIM() { return im; }
251
252     vout_thread_t* getVout();
253     aout_instance_t *getAout();
254
255 private:
256     MainInputManager( intf_thread_t * );
257     virtual ~MainInputManager();
258
259     static MainInputManager *instance;
260
261     void customEvent( QEvent * );
262
263     InputManager            *im;
264     input_thread_t          *p_input;
265     intf_thread_t           *p_intf;
266
267     void notifyRepeatLoop();
268 public slots:
269     void togglePlayPause();
270     void toggleRandom();
271     void stop();
272     void next();
273     void prev();
274     void activatePlayQuit( bool );
275
276     void loopRepeatLoopStatus();
277
278 signals:
279     void inputChanged( input_thread_t * );
280     void volumeChanged();
281     void playlistItemAppended( int itemId, int parentId );
282     void playlistItemRemoved( int itemId );
283     void randomChanged( bool );
284     void repeatLoopChanged( int );
285 };
286
287 #endif