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