]> git.sesse.net Git - vlc/blob - modules/gui/qt4/input_manager.hpp
Qt: rename even ID offsets as what they are
[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 "util/uniqueevent.hpp"
37 #include "variables.hpp"
38
39 #include <QObject>
40 #include <QEvent>
41
42 enum {
43     PositionUpdate_Type = QEvent::User + IMEventTypeOffset + 1,
44     ItemChanged_Type,
45     ItemStateChanged_Type,
46     ItemTitleChanged_Type,
47     ItemRateChanged_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     LoopOrRepeatChanged_Type,
63     EPGEvent_Type,
64 /*    SignalChanged_Type, */
65
66     FullscreenControlToggle_Type = QEvent::User + IMEventTypeOffset + 20,
67     FullscreenControlShow_Type,
68     FullscreenControlHide_Type,
69     FullscreenControlPlanHide_Type,
70 };
71
72 enum { NORMAL,    /* loop: 0, repeat: 0 */
73        REPEAT_ONE,/* loop: 0, repeat: 1 */
74        REPEAT_ALL,/* loop: 1, repeat: 0 */
75 };
76
77 class IMEvent : public UniqueEvent
78 {
79     public:
80     IMEvent( int type, input_item_t *p_input = NULL )
81         : UniqueEvent( (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     input_item_t *item() const { return p_item; };
92     virtual bool equals(UniqueEvent *e) const
93     {
94         IMEvent *ev = static_cast<IMEvent *>(e);
95         return ( ev->item() == p_item && ev->type() == type() );
96     }
97 private:
98     input_item_t *p_item;
99 };
100
101 class PLEvent : public QEvent
102 {
103 public:
104     enum PLEventTypes
105     {
106         PLItemAppended_Type = QEvent::User + PLEventTypeOffset + 1,
107         PLItemRemoved_Type,
108         LeafToParent_Type,
109         PLEmpty_Type
110     };
111     PLEvent( PLEventTypes t, int i, int p = 0 )
112         : QEvent( (QEvent::Type)(t) ), i_item(i), i_parent(p) {}
113
114     /* Needed for "playlist-item*" and "leaf-to-parent" callbacks
115      * !! Can be a input_item_t->i_id or a playlist_item_t->i_id */
116     int i_item;
117     // Needed for "playlist-item-append" callback, notably
118     int i_parent;
119 };
120
121 class InputManager : public QObject
122 {
123     Q_OBJECT
124     friend class MainInputManager;
125
126 public:
127     InputManager( QObject *, intf_thread_t * );
128     virtual ~InputManager();
129
130     void delInput();
131     bool hasInput()
132     {
133         return p_input /* We have an input */
134             && !p_input->b_dead /* not dead yet, */
135             && !p_input->b_eof  /* not EOF either, */
136             && vlc_object_alive (p_input); /* and the VLC object is alive */
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
145     QString getName() { return oldName; }
146     static const QString decodeArtURL( input_item_t *p_item );
147     void postUniqueEvent( QObject *, UniqueEvent * );
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     RateLimitedEventPoster *rateLimitedEventPoster;
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 public slots:
187     void setInput( input_thread_t * ); ///< Our controlled input changed
188     void sliderUpdate( float ); ///< User dragged the slider. We get new pos
189     /* SpeedRate Rate Management */
190     void reverse();
191     void slower();
192     void faster();
193     void littlefaster();
194     void littleslower();
195     void normalRate();
196     void setRate( int );
197     /* Jumping */
198     void jumpFwd();
199     void jumpBwd();
200     /* Menus */
201     void sectionNext();
202     void sectionPrev();
203     void sectionMenu();
204     /* Teletext */
205     void telexSetPage( int );          ///< Goto teletext page
206     void telexSetTransparency( bool ); ///< Transparency on teletext background
207     void activateTeletext( bool );     ///< Toggle buttons after click
208     /* A to B Loop */
209     void setAtoB();
210
211 private slots:
212     void AtoBLoop( float, int64_t, int );
213
214 signals:
215     /// Send new position, new time and new length
216     void positionUpdated( float , int64_t, int );
217     void seekRequested( float pos );
218     void rateChanged( float );
219     void nameChanged( const QString& );
220     /// Used to signal whether we should show navigation buttons
221     void titleChanged( bool );
222     void chapterChanged( bool );
223     void inputCanSeek( bool );
224     /// Statistics are updated
225     void statisticsUpdated( input_item_t* );
226     void infoChanged( input_item_t* );
227     void currentMetaChanged( input_item_t* );
228     void metaChanged( input_item_t *);
229     void artChanged( QString ); /* current item art ( same as item == NULL ) */
230     void artChanged( input_item_t * );
231     /// Play/pause status
232     void playingStatusChanged( int );
233     void recordingStateChanged( bool );
234     /// Teletext
235     void teletextPossible( bool );
236     void teletextActivated( bool );
237     void teletextTransparencyActivated( bool );
238     void newTelexPageSet( int );
239     /// Advanced buttons
240     void AtoBchanged( bool, bool );
241     /// Vout
242     void voutChanged( bool );
243     void voutListChanged( vout_thread_t **pp_vout, int i_vout );
244     /// Other
245     void synchroChanged();
246     void bookmarksChanged();
247     void cachingChanged( float );
248     /// Program Event changes
249     void encryptionChanged( bool );
250     void epgChanged();
251 };
252
253 class MainInputManager : public QObject, public Singleton<MainInputManager>
254 {
255     Q_OBJECT
256     friend class Singleton<MainInputManager>;
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 private:
273     MainInputManager( intf_thread_t * );
274     virtual ~MainInputManager();
275
276     void customEvent( QEvent * );
277
278     InputManager            *im;
279     input_thread_t          *p_input;
280     intf_thread_t           *p_intf;
281     QVLCBool random, repeat, loop;
282     QVLCFloat volume;
283     QVLCBool mute;
284
285 public slots:
286     void togglePlayPause();
287     void play();
288     void pause();
289     void toggleRandom();
290     void stop();
291     void next();
292     void prev();
293     void prevOrReset();
294     void activatePlayQuit( bool );
295
296     void loopRepeatLoopStatus();
297 private slots:
298     void notifyRandom( bool );
299     void notifyRepeatLoop( bool );
300     void notifyVolume( float );
301     void notifyMute( bool );
302 signals:
303     void inputChanged( input_thread_t * );
304     void volumeChanged( float );
305     void soundMuteChanged( bool );
306     void playlistItemAppended( int itemId, int parentId );
307     void playlistItemRemoved( int itemId );
308     void playlistNotEmpty( bool );
309     void randomChanged( bool );
310     void repeatLoopChanged( int );
311     void leafBecameParent( int );
312 };
313
314 #endif