]> git.sesse.net Git - vlc/blob - modules/gui/qt4/input_manager.hpp
Qt4: remove useless alive check on input
[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 #include "util/singleton.hpp"
36 #include "variables.hpp"
37
38 #include <QObject>
39 #include <QEvent>
40
41 enum { NORMAL,    /* loop: 0, repeat: 0 */
42        REPEAT_ONE,/* loop: 0, repeat: 1 */
43        REPEAT_ALL,/* loop: 1, repeat: 0 */
44 };
45
46 class IMEvent : public QEvent
47 {
48 public:
49     enum event_types {
50         PositionUpdate = QEvent::User + IMEventTypeOffset + 1,
51         ItemChanged,
52         ItemStateChanged,
53         ItemTitleChanged,
54         ItemRateChanged,
55         ItemEsChanged,
56         ItemTeletextChanged,
57         InterfaceVoutUpdate,
58         StatisticsUpdate, /*10*/
59         InterfaceAoutUpdate,
60         MetaChanged,
61         NameChanged,
62         InfoChanged,
63         SynchroChanged,
64         CachingEvent,
65         BookmarksChanged,
66         RecordingEvent,
67         ProgramChanged,
68         RandomChanged,
69         LoopOrRepeatChanged,
70         EPGEvent,
71     /*    SignalChanged, */
72
73         FullscreenControlToggle = QEvent::User + IMEventTypeOffset + 20,
74         FullscreenControlShow,
75         FullscreenControlHide,
76         FullscreenControlPlanHide,
77     };
78
79     IMEvent( event_types type, input_item_t *p_input = NULL )
80         : QEvent( (QEvent::Type)(type) )
81     {
82         if( (p_item = p_input) != NULL )
83             vlc_gc_incref( p_item );
84     }
85
86     virtual ~IMEvent()
87     {
88         if( p_item )
89             vlc_gc_decref( p_item );
90     }
91
92     input_item_t *item() const { return p_item; };
93
94 private:
95     input_item_t *p_item;
96 };
97
98 class PLEvent : public QEvent
99 {
100 public:
101     enum PLEventTypes
102     {
103         PLItemAppended = QEvent::User + PLEventTypeOffset + 1,
104         PLItemRemoved,
105         LeafToParent,
106         PLEmpty
107     };
108
109     PLEvent( PLEventTypes t, int i, int p = 0 )
110         : QEvent( (QEvent::Type)(t) ), i_item(i), i_parent(p) {}
111     int getItemId() const { return i_item; };
112     int getParentId() const { return i_parent; };
113
114 private:
115     /* Needed for "playlist-item*" and "leaf-to-parent" callbacks
116      * !! Can be a input_item_t->i_id or a playlist_item_t->i_id */
117     int i_item;
118     // Needed for "playlist-item-append" callback, notably
119     int i_parent;
120 };
121
122 class InputManager : public QObject
123 {
124     Q_OBJECT
125     friend class MainInputManager;
126
127 public:
128     InputManager( QObject *, intf_thread_t * );
129     virtual ~InputManager();
130
131     void delInput();
132     bool hasInput()
133     {
134         return p_input /* We have an input */
135             && !p_input->b_dead /* not dead yet, */
136             && !p_input->b_eof  /* not EOF either */;
137     }
138
139     int playingStatus();
140     bool hasAudio();
141     bool hasVideo() { return hasInput() && b_video; }
142     bool hasVisualisation();
143     void requestArtUpdate( input_item_t *p_item );
144     void setArt( input_item_t *p_item, QString fileUrl );
145
146     QString getName() { return oldName; }
147     static const QString decodeArtURL( input_item_t *p_item );
148
149 private:
150     intf_thread_t  *p_intf;
151     input_thread_t *p_input;
152     vlc_object_t   *p_input_vbi;
153     input_item_t   *p_item;
154     int             i_old_playing_status;
155     QString         oldName;
156     QString         artUrl;
157     float           f_rate;
158     float           f_cache;
159     bool            b_video;
160     mtime_t         timeA, timeB;
161
162     void customEvent( QEvent * );
163
164     void addCallbacks();
165     void delCallbacks();
166
167     void UpdateRate();
168     void UpdateName();
169     void UpdateStatus();
170     void UpdateNavigation();
171     void UpdatePosition();
172     void UpdateTeletext();
173     void UpdateArt();
174     void UpdateInfo();
175     void UpdateMeta();
176     void UpdateMeta(input_item_t *);
177     void UpdateVout();
178     void UpdateAout();
179     void UpdateStats();
180     void UpdateCaching();
181     void UpdateRecord();
182     void UpdateProgramEvent();
183     void UpdateEPG();
184
185 public slots:
186     void setInput( input_thread_t * ); ///< Our controlled input changed
187     void sliderUpdate( float ); ///< User dragged the slider. We get new pos
188     /* SpeedRate Rate Management */
189     void reverse();
190     void slower();
191     void faster();
192     void littlefaster();
193     void littleslower();
194     void normalRate();
195     void setRate( int );
196     /* Jumping */
197     void jumpFwd();
198     void jumpBwd();
199     /* Menus */
200     void sectionNext();
201     void sectionPrev();
202     void sectionMenu();
203     /* Teletext */
204     void telexSetPage( int );          ///< Goto teletext page
205     void telexSetTransparency( bool ); ///< Transparency on teletext background
206     void activateTeletext( bool );     ///< Toggle buttons after click
207     /* A to B Loop */
208     void setAtoB();
209
210 private slots:
211     void AtoBLoop( float, int64_t, int );
212
213 signals:
214     /// Send new position, new time and new length
215     void positionUpdated( float , int64_t, int );
216     void seekRequested( float pos );
217     void rateChanged( float );
218     void nameChanged( const QString& );
219     /// Used to signal whether we should show navigation buttons
220     void titleChanged( bool );
221     void chapterChanged( bool );
222     void inputCanSeek( bool );
223     /// Statistics are updated
224     void statisticsUpdated( input_item_t* );
225     void infoChanged( input_item_t* );
226     void currentMetaChanged( input_item_t* );
227     void metaChanged( input_item_t *);
228     void artChanged( QString ); /* current item art ( same as item == NULL ) */
229     void artChanged( input_item_t * );
230     /// Play/pause status
231     void playingStatusChanged( int );
232     void recordingStateChanged( bool );
233     /// Teletext
234     void teletextPossible( bool );
235     void teletextActivated( bool );
236     void teletextTransparencyActivated( bool );
237     void newTelexPageSet( int );
238     /// Advanced buttons
239     void AtoBchanged( bool, bool );
240     /// Vout
241     void voutChanged( bool );
242     void voutListChanged( vout_thread_t **pp_vout, int i_vout );
243     /// Other
244     void synchroChanged();
245     void bookmarksChanged();
246     void cachingChanged( float );
247     /// Program Event changes
248     void encryptionChanged( bool );
249     void epgChanged();
250 };
251
252 class MainInputManager : public QObject, public Singleton<MainInputManager>
253 {
254     Q_OBJECT
255     friend class Singleton<MainInputManager>;
256
257 public:
258     input_thread_t *getInput() { return p_input; }
259     InputManager *getIM() { return im; }
260     inline input_item_t *currentInputItem()
261     {
262         return ( p_input ? input_GetItem( p_input ) : NULL );
263     }
264
265     vout_thread_t* getVout();
266     audio_output_t *getAout();
267
268     bool getPlayExitState();
269     bool hasEmptyPlaylist();
270
271     void requestVoutUpdate() { return im->UpdateVout(); }
272
273 private:
274     MainInputManager( intf_thread_t * );
275     virtual ~MainInputManager();
276
277     void customEvent( QEvent * );
278
279     InputManager            *im;
280     input_thread_t          *p_input;
281     intf_thread_t           *p_intf;
282     QVLCBool random, repeat, loop;
283     QVLCFloat volume;
284     QVLCBool mute;
285
286 public slots:
287     void togglePlayPause();
288     void play();
289     void pause();
290     void toggleRandom();
291     void stop();
292     void next();
293     void prev();
294     void prevOrReset();
295     void activatePlayQuit( bool );
296
297     void loopRepeatLoopStatus();
298
299 private slots:
300     void notifyRandom( bool );
301     void notifyRepeatLoop( bool );
302     void notifyVolume( float );
303     void notifyMute( bool );
304
305 signals:
306     void inputChanged( input_thread_t * );
307     void volumeChanged( float );
308     void soundMuteChanged( bool );
309     void playlistItemAppended( int itemId, int parentId );
310     void playlistItemRemoved( int itemId );
311     void playlistNotEmpty( bool );
312     void randomChanged( bool );
313     void repeatLoopChanged( int );
314     void leafBecameParent( int );
315 };
316
317 #endif