]> git.sesse.net Git - vlc/blob - modules/gui/qt4/input_manager.hpp
Qt: namespaces are now sufficient for designating event names
[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 { 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 UniqueEvent
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     IMEvent( event_types type, input_item_t *p_input = NULL )
80         : UniqueEvent( (QEvent::Type)(type) )
81     {
82         if( (p_item = p_input) != NULL )
83             vlc_gc_incref( p_item );
84     }
85     virtual ~IMEvent()
86     {
87         if( p_item )
88             vlc_gc_decref( p_item );
89     }
90     input_item_t *item() const { return p_item; };
91     virtual bool equals(UniqueEvent *e) const
92     {
93         IMEvent *ev = static_cast<IMEvent *>(e);
94         return ( ev->item() == p_item && ev->type() == type() );
95     }
96 private:
97     input_item_t *p_item;
98 };
99
100 class PLEvent : public QEvent
101 {
102 public:
103     enum PLEventTypes
104     {
105         PLItemAppended = QEvent::User + PLEventTypeOffset + 1,
106         PLItemRemoved,
107         LeafToParent,
108         PLEmpty
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 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             && vlc_object_alive (p_input); /* and the VLC object is alive */
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 );
145
146     QString getName() { return oldName; }
147     static const QString decodeArtURL( input_item_t *p_item );
148     void postUniqueEvent( QObject *, UniqueEvent * );
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     RateLimitedEventPoster *rateLimitedEventPoster;
165
166     void addCallbacks();
167     void delCallbacks();
168
169     void UpdateRate();
170     void UpdateName();
171     void UpdateStatus();
172     void UpdateNavigation();
173     void UpdatePosition();
174     void UpdateTeletext();
175     void UpdateArt();
176     void UpdateInfo();
177     void UpdateMeta();
178     void UpdateMeta(input_item_t *);
179     void UpdateVout();
180     void UpdateAout();
181     void UpdateStats();
182     void UpdateCaching();
183     void UpdateRecord();
184     void UpdateProgramEvent();
185     void UpdateEPG();
186
187 public slots:
188     void setInput( input_thread_t * ); ///< Our controlled input changed
189     void sliderUpdate( float ); ///< User dragged the slider. We get new pos
190     /* SpeedRate Rate Management */
191     void reverse();
192     void slower();
193     void faster();
194     void littlefaster();
195     void littleslower();
196     void normalRate();
197     void setRate( int );
198     /* Jumping */
199     void jumpFwd();
200     void jumpBwd();
201     /* Menus */
202     void sectionNext();
203     void sectionPrev();
204     void sectionMenu();
205     /* Teletext */
206     void telexSetPage( int );          ///< Goto teletext page
207     void telexSetTransparency( bool ); ///< Transparency on teletext background
208     void activateTeletext( bool );     ///< Toggle buttons after click
209     /* A to B Loop */
210     void setAtoB();
211
212 private slots:
213     void AtoBLoop( float, int64_t, int );
214
215 signals:
216     /// Send new position, new time and new length
217     void positionUpdated( float , int64_t, int );
218     void seekRequested( float pos );
219     void rateChanged( float );
220     void nameChanged( const QString& );
221     /// Used to signal whether we should show navigation buttons
222     void titleChanged( bool );
223     void chapterChanged( bool );
224     void inputCanSeek( bool );
225     /// Statistics are updated
226     void statisticsUpdated( input_item_t* );
227     void infoChanged( input_item_t* );
228     void currentMetaChanged( input_item_t* );
229     void metaChanged( input_item_t *);
230     void artChanged( QString ); /* current item art ( same as item == NULL ) */
231     void artChanged( input_item_t * );
232     /// Play/pause status
233     void playingStatusChanged( int );
234     void recordingStateChanged( bool );
235     /// Teletext
236     void teletextPossible( bool );
237     void teletextActivated( bool );
238     void teletextTransparencyActivated( bool );
239     void newTelexPageSet( int );
240     /// Advanced buttons
241     void AtoBchanged( bool, bool );
242     /// Vout
243     void voutChanged( bool );
244     void voutListChanged( vout_thread_t **pp_vout, int i_vout );
245     /// Other
246     void synchroChanged();
247     void bookmarksChanged();
248     void cachingChanged( float );
249     /// Program Event changes
250     void encryptionChanged( bool );
251     void epgChanged();
252 };
253
254 class MainInputManager : public QObject, public Singleton<MainInputManager>
255 {
256     Q_OBJECT
257     friend class Singleton<MainInputManager>;
258 public:
259     input_thread_t *getInput() { return p_input; }
260     InputManager *getIM() { return im; }
261     inline input_item_t *currentInputItem()
262     {
263         return ( p_input ? input_GetItem( p_input ) : NULL );
264     }
265
266     vout_thread_t* getVout();
267     audio_output_t *getAout();
268
269     bool getPlayExitState();
270     bool hasEmptyPlaylist();
271
272     void requestVoutUpdate() { return im->UpdateVout(); }
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 private slots:
299     void notifyRandom( bool );
300     void notifyRepeatLoop( bool );
301     void notifyVolume( float );
302     void notifyMute( bool );
303 signals:
304     void inputChanged( input_thread_t * );
305     void volumeChanged( float );
306     void soundMuteChanged( bool );
307     void playlistItemAppended( int itemId, int parentId );
308     void playlistItemRemoved( int itemId );
309     void playlistNotEmpty( bool );
310     void randomChanged( bool );
311     void repeatLoopChanged( int );
312     void leafBecameParent( int );
313 };
314
315 #endif