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