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