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