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