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