gui: qt: use float for rate
[vlc.git] / modules / gui / qt / input_manager.hpp
blobeece06e13de24af7ddb9fa9655be2acd2b79b62e
1 /*****************************************************************************
2 * input_manager.hpp : Manage an input and interact with its GUI elements
3 ****************************************************************************
4 * Copyright (C) 2006-2008 the VideoLAN team
6 * Authors: Clément Stenac <zorglub@videolan.org>
7 * Jean-Baptiste <jb@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #ifndef QVLC_INPUT_MANAGER_H_
25 #define QVLC_INPUT_MANAGER_H_
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
31 #include <vlc_input.h>
33 #include "qt.hpp"
34 #include "util/singleton.hpp"
35 #include "adapters/variables.hpp"
37 #include <QObject>
38 #include <QEvent>
39 class QSignalMapper;
41 enum { NORMAL, /* loop: 0, repeat: 0 */
42 REPEAT_ONE,/* loop: 0, repeat: 1 */
43 REPEAT_ALL,/* loop: 1, repeat: 0 */
46 class IMEvent : public QEvent
48 public:
49 enum event_types {
50 PositionUpdate = QEvent::User + IMEventTypeOffset + 1,
51 ItemChanged,
52 ItemStateChanged,
53 ItemTitleChanged,
54 ItemRateChanged,
55 ItemEsChanged,
56 ItemTeletextChanged,
57 InterfaceVoutUpdate,
58 StatisticsUpdate,
59 MetaChanged, /* 10 */
60 InfoChanged,
61 SynchroChanged,
62 CachingEvent,
63 BookmarksChanged,
64 RecordingEvent,
65 ProgramChanged,
66 RandomChanged,
67 LoopOrRepeatChanged,
68 EPGEvent,
69 CapabilitiesChanged, /* 20 */
70 /* SignalChanged, */
72 FullscreenControlToggle = QEvent::User + IMEventTypeOffset + 50,
73 FullscreenControlShow,
74 FullscreenControlHide,
75 FullscreenControlPlanHide,
78 IMEvent( event_types type, input_item_t *p_input = NULL )
79 : QEvent( (QEvent::Type)(type) )
81 if( (p_item = p_input) != NULL )
82 input_item_Hold( p_item );
85 virtual ~IMEvent()
87 if( p_item )
88 input_item_Release( p_item );
91 input_item_t *item() const { return p_item; };
93 private:
94 input_item_t *p_item;
97 class PLEvent : public QEvent
99 public:
100 enum PLEventTypes
102 PLItemAppended = QEvent::User + PLEventTypeOffset + 1,
103 PLItemRemoved,
104 LeafToParent,
105 PLEmpty
108 PLEvent( PLEventTypes t, int i, int p = 0 )
109 : QEvent( (QEvent::Type)(t) ), i_item(i), i_parent(p) {}
110 int getItemId() const { return i_item; };
111 int getParentId() const { return i_parent; };
113 private:
114 /* Needed for "playlist-item*" and "leaf-to-parent" callbacks
115 * !! Can be a input_item_t->i_id or a playlist_item_t->i_id */
116 int i_item;
117 // Needed for "playlist-item-append" callback, notably
118 int i_parent;
121 class MainInputManager;
123 class InputManager : public QObject
125 Q_OBJECT
126 friend class MainInputManager;
128 public:
129 InputManager( MainInputManager *, intf_thread_t * );
130 virtual ~InputManager();
132 void delInput();
133 bool hasInput() const { return p_input != NULL; }
135 int playingStatus() const;
136 bool hasAudio();
137 bool hasVideo() { return hasInput() && b_video; }
138 bool hasVisualisation();
139 void requestArtUpdate( input_item_t *p_item, bool b_forced );
140 void setArt( input_item_t *p_item, QString fileUrl );
142 QString getName() { return oldName; }
143 static const QString decodeArtURL( input_item_t *p_item );
145 private:
146 intf_thread_t *p_intf;
147 MainInputManager* p_mim;
148 input_thread_t *p_input;
149 vlc_object_t *p_input_vbi;
150 input_item_t *p_item;
151 int i_old_playing_status;
152 QString oldName;
153 QString lastURI;
154 QString artUrl;
155 float f_rate;
156 float f_cache;
157 bool b_video;
158 vlc_tick_t timeA, timeB;
160 void customEvent( QEvent * );
162 void addCallbacks();
163 void delCallbacks();
165 void UpdateRate();
166 void UpdateName();
167 void UpdateStatus();
168 void UpdateNavigation();
169 void UpdateCapabilities();
170 void UpdatePosition();
171 void UpdateTeletext();
172 void UpdateArt();
173 void UpdateInfo();
174 void UpdateMeta();
175 void UpdateMeta(input_item_t *);
176 void UpdateVout();
177 void UpdateStats();
178 void UpdateCaching();
179 void UpdateRecord();
180 void UpdateProgramEvent();
181 void UpdateEPG();
183 void setInput( input_thread_t * );
185 public slots:
186 void inputChangedHandler(); ///< Our controlled input changed
187 void sliderUpdate( float ); ///< User dragged the slider. We get new pos
188 /* SpeedRate Rate Management */
189 void reverse();
190 void slower();
191 void faster();
192 void littlefaster();
193 void littleslower();
194 void normalRate();
195 void setRate( float );
196 /* Jumping */
197 void jumpFwd();
198 void jumpBwd();
199 /* Menus */
200 void sectionNext();
201 void sectionPrev();
202 void sectionMenu();
203 /* Program */
204 void changeProgram( int );
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();
212 private slots:
213 void AtoBLoop( float, vlc_tick_t, int );
215 signals:
216 /// Send new position, new time and new length
217 void positionUpdated( float , vlc_tick_t, int );
218 void remainingTimeChanged( bool );
219 void seekRequested( float pos );
220 void rateChanged( float );
221 void nameChanged( const QString& );
222 /// Used to signal whether we should show navigation buttons
223 void titleChanged( bool );
224 void chapterChanged( bool );
225 void inputCanSeek( bool );
226 /// You can resume playback
227 void resumePlayback( vlc_tick_t );
228 /// Statistics are updated
229 void statisticsUpdated( input_item_t* );
230 void infoChanged( input_item_t* );
231 void currentMetaChanged( input_item_t* );
232 void metaChanged( input_item_t *);
233 void artChanged( QString ); /* current item art ( same as item == NULL ) */
234 void artChanged( input_item_t * );
235 /// Play/pause status
236 void playingStatusChanged( int );
237 void recordingStateChanged( bool );
238 /// Teletext
239 void teletextPossible( bool );
240 void teletextActivated( bool );
241 void teletextTransparencyActivated( bool );
242 void newTelexPageSet( int );
243 /// Advanced buttons
244 void AtoBchanged( bool, bool );
245 /// Vout
246 void voutChanged( bool );
247 void voutListChanged( vout_thread_t **pp_vout, int i_vout );
248 /// Other
249 void synchroChanged();
250 void bookmarksChanged();
251 void cachingChanged( float );
252 /// Program Event changes
253 void encryptionChanged( bool );
254 void epgChanged();
257 class MainInputManager : public QObject, public Singleton<MainInputManager>
259 Q_OBJECT
260 friend class Singleton<MainInputManager>;
261 friend class VLCMenuBar;
263 public:
264 input_thread_t *getInput() { return p_input; }
265 InputManager *getIM() { return im; }
266 inline input_item_t *currentInputItem()
268 return ( p_input ? input_GetItem( p_input ) : NULL );
271 vout_thread_t* getVout();
272 QVector<vout_thread_t*> getVouts() const;
273 audio_output_t *getAout();
275 bool getPlayExitState();
276 bool hasEmptyPlaylist();
278 void requestVoutUpdate() { return im->UpdateVout(); }
279 // Probe for initial input. Doing this from the constructor would cause
280 // the getInstance to call itself recursively from the inputChangedHandler
281 void probeCurrentInput();
283 protected:
284 QSignalMapper *menusAudioMapper;
286 private:
287 MainInputManager( intf_thread_t * );
288 virtual ~MainInputManager();
290 void customEvent( QEvent * );
292 InputManager *im;
293 input_thread_t *p_input;
294 intf_thread_t *p_intf;
295 QVLCBool random, repeat, loop;
296 QVLCFloat volume;
297 QVLCBool mute;
299 private:
300 static int ItemChanged( vlc_object_t *, const char *,
301 vlc_value_t, vlc_value_t, void * );
302 static int LeafToParent( vlc_object_t *, const char *,
303 vlc_value_t, vlc_value_t, void * );
304 static int PLItemChanged( vlc_object_t *, const char *,
305 vlc_value_t, vlc_value_t, void * );
306 static int PLItemAppended( vlc_object_t *, const char *,
307 vlc_value_t, vlc_value_t, void * );
308 static int PLItemRemoved( vlc_object_t *, const char *,
309 vlc_value_t, vlc_value_t, void * );
311 public slots:
312 void togglePlayPause();
313 void play();
314 void pause();
315 void toggleRandom();
316 void stop();
317 void next();
318 void prev();
319 void prevOrReset();
320 void activatePlayQuit( bool );
322 void loopRepeatLoopStatus();
323 void changeFullscreen( bool );
325 private slots:
326 void notifyRandom( bool );
327 void notifyRepeatLoop( bool );
328 void notifyVolume( float );
329 void notifyMute( bool );
330 void menusUpdateAudio( const QString& );
332 signals:
333 void inputChanged( bool );
334 void volumeChanged( float );
335 void soundMuteChanged( bool );
336 void playlistItemAppended( int itemId, int parentId );
337 void playlistItemRemoved( int itemId );
338 void playlistNotEmpty( bool );
339 void randomChanged( bool );
340 void repeatLoopChanged( int );
341 void leafBecameParent( int );
344 #endif