]> git.sesse.net Git - vlc/blob - modules/gui/qt4/input_manager.hpp
Qt: adapt menus to new Audio Device list
[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 "adapters/variables.hpp"
37
38 #include <QObject>
39 #include <QEvent>
40 class QSignalMapper;
41
42 enum { NORMAL,    /* loop: 0, repeat: 0 */
43        REPEAT_ONE,/* loop: 0, repeat: 1 */
44        REPEAT_ALL,/* loop: 1, repeat: 0 */
45 };
46
47 class IMEvent : public QEvent
48 {
49 public:
50     enum event_types {
51         PositionUpdate = QEvent::User + IMEventTypeOffset + 1,
52         ItemChanged,
53         ItemStateChanged,
54         ItemTitleChanged,
55         ItemRateChanged,
56         ItemEsChanged,
57         ItemTeletextChanged,
58         InterfaceVoutUpdate,
59         StatisticsUpdate, /*10*/
60         InterfaceAoutUpdate,
61         MetaChanged,
62         NameChanged,
63         InfoChanged,
64         SynchroChanged,
65         CachingEvent,
66         BookmarksChanged,
67         RecordingEvent,
68         ProgramChanged,
69         RandomChanged,
70         LoopOrRepeatChanged,
71         EPGEvent,
72     /*    SignalChanged, */
73
74         FullscreenControlToggle = QEvent::User + IMEventTypeOffset + 20,
75         FullscreenControlShow,
76         FullscreenControlHide,
77         FullscreenControlPlanHide,
78     };
79
80     IMEvent( event_types type, input_item_t *p_input = NULL )
81         : QEvent( (QEvent::Type)(type) )
82     {
83         if( (p_item = p_input) != NULL )
84             vlc_gc_incref( p_item );
85     }
86
87     virtual ~IMEvent()
88     {
89         if( p_item )
90             vlc_gc_decref( p_item );
91     }
92
93     input_item_t *item() const { return p_item; };
94
95 private:
96     input_item_t *p_item;
97 };
98
99 class PLEvent : public QEvent
100 {
101 public:
102     enum PLEventTypes
103     {
104         PLItemAppended = QEvent::User + PLEventTypeOffset + 1,
105         PLItemRemoved,
106         LeafToParent,
107         PLEmpty
108     };
109
110     PLEvent( PLEventTypes t, int i, int p = 0 )
111         : QEvent( (QEvent::Type)(t) ), i_item(i), i_parent(p) {}
112     int getItemId() const { return i_item; };
113     int getParentId() const { return i_parent; };
114
115 private:
116     /* Needed for "playlist-item*" and "leaf-to-parent" callbacks
117      * !! Can be a input_item_t->i_id or a playlist_item_t->i_id */
118     int i_item;
119     // Needed for "playlist-item-append" callback, notably
120     int i_parent;
121 };
122
123 class InputManager : public QObject
124 {
125     Q_OBJECT
126     friend class MainInputManager;
127
128 public:
129     InputManager( QObject *, intf_thread_t * );
130     virtual ~InputManager();
131
132     void delInput();
133     bool hasInput()
134     {
135         return p_input /* We have an input */
136             && !p_input->b_dead /* not dead yet, */
137             && !p_input->b_eof  /* not EOF either */;
138     }
139
140     int playingStatus();
141     bool hasAudio();
142     bool hasVideo() { return hasInput() && b_video; }
143     bool hasVisualisation();
144     void requestArtUpdate( input_item_t *p_item );
145     void setArt( input_item_t *p_item, QString fileUrl );
146
147     QString getName() { return oldName; }
148     static const QString decodeArtURL( input_item_t *p_item );
149
150 private:
151     intf_thread_t  *p_intf;
152     input_thread_t *p_input;
153     vlc_object_t   *p_input_vbi;
154     input_item_t   *p_item;
155     int             i_old_playing_status;
156     QString         oldName;
157     QString         artUrl;
158     float           f_rate;
159     float           f_cache;
160     bool            b_video;
161     mtime_t         timeA, timeB;
162
163     void customEvent( QEvent * );
164
165     void addCallbacks();
166     void delCallbacks();
167
168     void UpdateRate();
169     void UpdateName();
170     void UpdateStatus();
171     void UpdateNavigation();
172     void UpdatePosition();
173     void UpdateTeletext();
174     void UpdateArt();
175     void UpdateInfo();
176     void UpdateMeta();
177     void UpdateMeta(input_item_t *);
178     void UpdateVout();
179     void UpdateAout();
180     void UpdateStats();
181     void UpdateCaching();
182     void UpdateRecord();
183     void UpdateProgramEvent();
184     void UpdateEPG();
185
186 public slots:
187     void setInput( input_thread_t * ); ///< Our controlled input changed
188     void sliderUpdate( float ); ///< User dragged the slider. We get new pos
189     /* SpeedRate Rate Management */
190     void reverse();
191     void slower();
192     void faster();
193     void littlefaster();
194     void littleslower();
195     void normalRate();
196     void setRate( int );
197     /* Jumping */
198     void jumpFwd();
199     void jumpBwd();
200     /* Menus */
201     void sectionNext();
202     void sectionPrev();
203     void sectionMenu();
204     /* Teletext */
205     void telexSetPage( int );          ///< Goto teletext page
206     void telexSetTransparency( bool ); ///< Transparency on teletext background
207     void activateTeletext( bool );     ///< Toggle buttons after click
208     /* A to B Loop */
209     void setAtoB();
210
211 private slots:
212     void AtoBLoop( float, int64_t, int );
213
214 signals:
215     /// Send new position, new time and new length
216     void positionUpdated( float , int64_t, int );
217     void seekRequested( float pos );
218     void rateChanged( float );
219     void nameChanged( const QString& );
220     /// Used to signal whether we should show navigation buttons
221     void titleChanged( bool );
222     void chapterChanged( bool );
223     void inputCanSeek( bool );
224     /// Statistics are updated
225     void statisticsUpdated( input_item_t* );
226     void infoChanged( input_item_t* );
227     void currentMetaChanged( input_item_t* );
228     void metaChanged( input_item_t *);
229     void artChanged( QString ); /* current item art ( same as item == NULL ) */
230     void artChanged( input_item_t * );
231     /// Play/pause status
232     void playingStatusChanged( int );
233     void recordingStateChanged( bool );
234     /// Teletext
235     void teletextPossible( bool );
236     void teletextActivated( bool );
237     void teletextTransparencyActivated( bool );
238     void newTelexPageSet( int );
239     /// Advanced buttons
240     void AtoBchanged( bool, bool );
241     /// Vout
242     void voutChanged( bool );
243     void voutListChanged( vout_thread_t **pp_vout, int i_vout );
244     /// Other
245     void synchroChanged();
246     void bookmarksChanged();
247     void cachingChanged( float );
248     /// Program Event changes
249     void encryptionChanged( bool );
250     void epgChanged();
251 };
252
253 class MainInputManager : public QObject, public Singleton<MainInputManager>
254 {
255     Q_OBJECT
256     friend class Singleton<MainInputManager>;
257     friend class VLCMenuBar;
258
259 public:
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     audio_output_t *getAout();
269
270     bool getPlayExitState();
271     bool hasEmptyPlaylist();
272
273     void requestVoutUpdate() { return im->UpdateVout(); }
274
275 protected:
276     QSignalMapper *menusAudioMapper;
277
278 private:
279     MainInputManager( intf_thread_t * );
280     virtual ~MainInputManager();
281
282     void customEvent( QEvent * );
283
284     InputManager            *im;
285     input_thread_t          *p_input;
286     intf_thread_t           *p_intf;
287     QVLCBool random, repeat, loop;
288     QVLCFloat volume;
289     QVLCBool mute;
290
291 public slots:
292     void togglePlayPause();
293     void play();
294     void pause();
295     void toggleRandom();
296     void stop();
297     void next();
298     void prev();
299     void prevOrReset();
300     void activatePlayQuit( bool );
301
302     void loopRepeatLoopStatus();
303
304 private slots:
305     void notifyRandom( bool );
306     void notifyRepeatLoop( bool );
307     void notifyVolume( float );
308     void notifyMute( bool );
309     void menusUpdateAudio( const QString& );
310
311 signals:
312     void inputChanged( input_thread_t * );
313     void volumeChanged( float );
314     void soundMuteChanged( bool );
315     void playlistItemAppended( int itemId, int parentId );
316     void playlistItemRemoved( int itemId );
317     void playlistNotEmpty( bool );
318     void randomChanged( bool );
319     void repeatLoopChanged( int );
320     void leafBecameParent( int );
321 };
322
323 #endif