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