]> git.sesse.net Git - vlc/blob - modules/gui/qt4/input_manager.hpp
9c6678f5aaaa67fe4814e0039429bf6403256049
[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  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 #ifndef _INPUT_MANAGER_H_
25 #define _INPUT_MANAGER_H_
26
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #include <vlc_common.h>
32 #include <vlc_input.h>
33
34 #include "qt4.hpp"
35
36 #include <QObject>
37 #include <QEvent>
38
39 static int const PositionUpdate_Type   = QEvent::User + IMEventType + 1;
40 static int const ItemChanged_Type      = QEvent::User + IMEventType + 2;
41 static int const ItemStateChanged_Type = QEvent::User + IMEventType + 3;
42 static int const ItemTitleChanged_Type = QEvent::User + IMEventType + 4;
43 static int const ItemRateChanged_Type  = QEvent::User + IMEventType + 5;
44 static int const VolumeChanged_Type    = QEvent::User + IMEventType + 6;
45
46 class IMEvent : public QEvent
47 {
48 public:
49     IMEvent( int type, int id ) : QEvent( (QEvent::Type)(type) )
50     { i_id = id ; } ;
51     virtual ~IMEvent() {};
52
53     int i_id;
54 };
55
56 class InputManager : public QObject
57 {
58     Q_OBJECT;
59 public:
60     InputManager( QObject *, intf_thread_t * );
61     virtual ~InputManager();
62
63     void delInput();
64     bool hasInput() { return p_input && !p_input->b_dead && !p_input->b_die; }
65     bool hasAudio() { return b_has_audio; }
66     bool hasVideo() { return b_has_video; }
67     bool b_has_audio, b_has_video, b_had_audio, b_had_video, b_has_subs;
68
69 private:
70     intf_thread_t  *p_intf;
71     input_thread_t *p_input;
72     int             i_input_id;
73     int             i_old_playing_status;
74     QString         old_name;
75     QString         artUrl;
76     int             i_rate;
77
78     void customEvent( QEvent * );
79     void addCallbacks();
80     void delCallbacks();
81     void UpdateRate();
82     void UpdateMeta();
83     void UpdateStatus();
84     void UpdateNavigation();
85     void UpdatePosition();
86     void UpdateTracks();
87     void UpdateArt();
88
89 public slots:
90     void setInput( input_thread_t * ); ///< Our controlled input changed
91     void sliderUpdate( float ); ///< User dragged the slider. We get new pos
92     void togglePlayPause();
93     void slower();
94     void faster();
95     void normalRate();
96     void setRate( int );
97     void sectionNext();
98     void sectionPrev();
99     void sectionMenu();
100 #ifdef ZVBI_COMPILED
101     void telexGotoPage( int );
102     void telexToggle( bool );
103     void telexSetTransparency( bool );
104 #endif
105
106 signals:
107     /// Send new position, new time and new length
108     void positionUpdated( float , int, int );
109     void rateChanged( int );
110     void nameChanged( QString );
111     /// Used to signal whether we should show navigation buttons
112     void navigationChanged( int );
113     /// Play/pause status
114     void statusChanged( int );
115     void artChanged( QString );
116 #ifdef ZVBI_COMPILED
117     void teletextEnabled( bool );
118 #endif
119 };
120
121 class MainInputManager : public QObject
122 {
123     Q_OBJECT;
124 public:
125     static MainInputManager *getInstance( intf_thread_t *_p_intf )
126     {
127         if( !instance )
128             instance = new MainInputManager( _p_intf );
129         return instance;
130     }
131     static void killInstance()
132     {
133         if( instance ) delete instance;
134     }
135     virtual ~MainInputManager();
136
137     input_thread_t *getInput() { return p_input; };
138     InputManager *getIM() { return im; };
139
140 private:
141     MainInputManager( intf_thread_t * );
142     void customEvent( QEvent * );
143
144     InputManager            *im;
145     input_thread_t          *p_input;
146
147     intf_thread_t           *p_intf;
148     static MainInputManager *instance;
149 public slots:
150     void togglePlayPause();
151     void stop();
152     void next();
153     void prev();
154 signals:
155     void inputChanged( input_thread_t * );
156     void volumeChanged();
157 };
158
159 #endif