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