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