input_manager.hpp 9.71 KB
Newer Older
zorglub's avatar
zorglub committed
1 2 3
/*****************************************************************************
 * input_manager.hpp : Manage an input and interact with its GUI elements
 ****************************************************************************
4
 * Copyright (C) 2006-2008 the VideoLAN team
5
 * $Id$
zorglub's avatar
zorglub committed
6 7
 *
 * Authors: Clément Stenac <zorglub@videolan.org>
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
8
 *          Jean-Baptiste <jb@videolan.org>
zorglub's avatar
zorglub committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

25 26
#ifndef QVLC_INPUT_MANAGER_H_
#define QVLC_INPUT_MANAGER_H_
zorglub's avatar
zorglub committed
27

28 29
#ifdef HAVE_CONFIG_H
# include "config.h"
Christophe Mutricy's avatar
Christophe Mutricy committed
30 31
#endif

zorglub's avatar
zorglub committed
32
#include <vlc_input.h>
zorglub's avatar
zorglub committed
33

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
34
#include "qt.hpp"
35
#include "util/singleton.hpp"
François Cartegnie's avatar
François Cartegnie committed
36
#include "adapters/variables.hpp"
37

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
38
#include <QObject>
39
#include <QEvent>
40
class QSignalMapper;
41

42
enum { NORMAL,    /* loop: 0, repeat: 0 */
43 44
       REPEAT_ONE,/* loop: 0, repeat: 1 */
       REPEAT_ALL,/* loop: 1, repeat: 0 */
45 46
};

47
class IMEvent : public QEvent
48
{
49 50
public:
    enum event_types {
51 52 53 54 55 56 57 58
        PositionUpdate = QEvent::User + IMEventTypeOffset + 1,
        ItemChanged,
        ItemStateChanged,
        ItemTitleChanged,
        ItemRateChanged,
        ItemEsChanged,
        ItemTeletextChanged,
        InterfaceVoutUpdate,
59 60
        StatisticsUpdate,
        InterfaceAoutUpdate, /* 10 */
61 62 63 64 65 66 67 68
        MetaChanged,
        InfoChanged,
        SynchroChanged,
        CachingEvent,
        BookmarksChanged,
        RecordingEvent,
        ProgramChanged,
        RandomChanged,
69
        LoopOrRepeatChanged, /* 20 */
70 71
        EPGEvent,
    /*    SignalChanged, */
72

73
        FullscreenControlToggle = QEvent::User + IMEventTypeOffset + 50,
74 75 76
        FullscreenControlShow,
        FullscreenControlHide,
        FullscreenControlPlanHide,
77
    };
78

79
    IMEvent( event_types type, input_item_t *p_input = NULL )
80
        : QEvent( (QEvent::Type)(type) )
81 82
    {
        if( (p_item = p_input) != NULL )
83
            input_item_Hold( p_item );
84
    }
85

86 87 88
    virtual ~IMEvent()
    {
        if( p_item )
89
            input_item_Release( p_item );
90
    }
91

92
    input_item_t *item() const { return p_item; };
93

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
94
private:
95
    input_item_t *p_item;
96
};
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
97

98 99 100
class PLEvent : public QEvent
{
public:
101 102
    enum PLEventTypes
    {
103 104 105 106
        PLItemAppended = QEvent::User + PLEventTypeOffset + 1,
        PLItemRemoved,
        LeafToParent,
        PLEmpty
107
    };
108

109
    PLEvent( PLEventTypes t, int i, int p = 0 )
110
        : QEvent( (QEvent::Type)(t) ), i_item(i), i_parent(p) {}
111 112
    int getItemId() const { return i_item; };
    int getParentId() const { return i_parent; };
113

114
private:
115 116
    /* Needed for "playlist-item*" and "leaf-to-parent" callbacks
     * !! Can be a input_item_t->i_id or a playlist_item_t->i_id */
117
    int i_item;
118
    // Needed for "playlist-item-append" callback, notably
119 120 121
    int i_parent;
};

122 123
class MainInputManager;

zorglub's avatar
zorglub committed
124 125
class InputManager : public QObject
{
François Cartegnie's avatar
François Cartegnie committed
126
    Q_OBJECT
127 128
    friend class MainInputManager;

zorglub's avatar
zorglub committed
129
public:
130
    InputManager( MainInputManager *, intf_thread_t * );
zorglub's avatar
zorglub committed
131 132
    virtual ~InputManager();

133
    void delInput();
134
    bool hasInput() const { return p_input != NULL; }
135

136
    int playingStatus() const;
137
    bool hasAudio();
138
    bool hasVideo() { return hasInput() && b_video; }
139
    bool hasVisualisation();
140
    void requestArtUpdate( input_item_t *p_item, bool b_forced );
Angelo Haller's avatar
Angelo Haller committed
141
    void setArt( input_item_t *p_item, QString fileUrl );
142

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
143
    QString getName() { return oldName; }
144
    static const QString decodeArtURL( input_item_t *p_item );
145

zorglub's avatar
zorglub committed
146
private:
147
    intf_thread_t  *p_intf;
148
    MainInputManager* p_mim;
149
    input_thread_t *p_input;
150
    vlc_object_t   *p_input_vbi;
151
    input_item_t   *p_item;
152
    int             i_old_playing_status;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
153
    QString         oldName;
154
    QString         lastURI;
155
    QString         artUrl;
156
    float           f_rate;
157
    float           f_cache;
158
    bool            b_video;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
159
    mtime_t         timeA, timeB;
160

161
    void customEvent( QEvent * );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
162

163 164
    void addCallbacks();
    void delCallbacks();
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
165

166
    void UpdateRate();
167
    void UpdateName();
168
    void UpdateStatus();
169
    void UpdateNavigation();
170
    void UpdatePosition();
171
    void UpdateTeletext();
172
    void UpdateArt();
173 174
    void UpdateInfo();
    void UpdateMeta();
175
    void UpdateMeta(input_item_t *);
176
    void UpdateVout();
177
    void UpdateAout();
178
    void UpdateStats();
179
    void UpdateCaching();
180
    void UpdateRecord();
181
    void UpdateProgramEvent();
182
    void UpdateEPG();
183

184 185
    void setInput( input_thread_t * );

zorglub's avatar
zorglub committed
186
public slots:
187
    void inputChangedHandler(); ///< Our controlled input changed
zorglub's avatar
zorglub committed
188
    void sliderUpdate( float ); ///< User dragged the slider. We get new pos
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
189
    /* SpeedRate Rate Management */
190
    void reverse();
zorglub's avatar
zorglub committed
191 192
    void slower();
    void faster();
193 194
    void littlefaster();
    void littleslower();
zorglub's avatar
zorglub committed
195
    void normalRate();
196
    void setRate( int );
197 198 199
    /* Jumping */
    void jumpFwd();
    void jumpBwd();
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
200
    /* Menus */
201 202 203
    void sectionNext();
    void sectionPrev();
    void sectionMenu();
204 205
    /* Program */
    void changeProgram( int );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
206 207 208 209 210 211 212
    /* Teletext */
    void telexSetPage( int );          ///< Goto teletext page
    void telexSetTransparency( bool ); ///< Transparency on teletext background
    void activateTeletext( bool );     ///< Toggle buttons after click
    /* A to B Loop */
    void setAtoB();

213
private slots:
214
    void AtoBLoop( float, int64_t, int );
215

zorglub's avatar
zorglub committed
216 217
signals:
    /// Send new position, new time and new length
218
    void positionUpdated( float , int64_t, int );
219
    void remainingTimeChanged( bool );
220
    void seekRequested( float pos );
221
    void rateChanged( float );
ivoire's avatar
ivoire committed
222
    void nameChanged( const QString& );
223
    /// Used to signal whether we should show navigation buttons
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
224 225
    void titleChanged( bool );
    void chapterChanged( bool );
226
    void inputCanSeek( bool );
227 228
    /// You can resume playback
    void resumePlayback( int64_t );
229 230
    /// Statistics are updated
    void statisticsUpdated( input_item_t* );
231
    void infoChanged( input_item_t* );
232
    void currentMetaChanged( input_item_t* );
233
    void metaChanged( input_item_t *);
234 235
    void artChanged( QString ); /* current item art ( same as item == NULL ) */
    void artChanged( input_item_t * );
236
    /// Play/pause status
237
    void playingStatusChanged( int );
238
    void recordingStateChanged( bool );
239
    /// Teletext
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
240 241 242 243
    void teletextPossible( bool );
    void teletextActivated( bool );
    void teletextTransparencyActivated( bool );
    void newTelexPageSet( int );
244
    /// Advanced buttons
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
245
    void AtoBchanged( bool, bool );
246 247
    /// Vout
    void voutChanged( bool );
248 249
    void voutListChanged( vout_thread_t **pp_vout, int i_vout );
    /// Other
250
    void synchroChanged();
251
    void bookmarksChanged();
252
    void cachingChanged( float );
253
    /// Program Event changes
254
    void encryptionChanged( bool );
255
    void epgChanged();
zorglub's avatar
zorglub committed
256 257
};

258
class MainInputManager : public QObject, public Singleton<MainInputManager>
259
{
François Cartegnie's avatar
François Cartegnie committed
260
    Q_OBJECT
261
    friend class Singleton<MainInputManager>;
262
    friend class VLCMenuBar;
263

264
public:
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
265 266
    input_thread_t *getInput() { return p_input; }
    InputManager *getIM() { return im; }
267 268 269 270
    inline input_item_t *currentInputItem()
    {
        return ( p_input ? input_GetItem( p_input ) : NULL );
    }
271

272
    vout_thread_t* getVout();
273
    audio_output_t *getAout();
274

275
    bool getPlayExitState();
276
    bool hasEmptyPlaylist();
277 278

    void requestVoutUpdate() { return im->UpdateVout(); }
279 280 281
    // Probe for initial input. Doing this from the constructor would cause
    // the getInstance to call itself recursively from the inputChangedHandler
    void probeCurrentInput();
282

283 284 285
protected:
    QSignalMapper *menusAudioMapper;

286
private:
287
    MainInputManager( intf_thread_t * );
288 289
    virtual ~MainInputManager();

290
    void customEvent( QEvent * );
291 292 293

    InputManager            *im;
    input_thread_t          *p_input;
294
    intf_thread_t           *p_intf;
295
    QVLCBool random, repeat, loop;
296
    QVLCFloat volume;
297
    QVLCBool mute;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
298

299 300 301 302 303 304 305 306 307 308 309 310
private:
    static int ItemChanged( vlc_object_t *, const char *,
                            vlc_value_t, vlc_value_t, void * );
    static int LeafToParent( vlc_object_t *, const char *,
                            vlc_value_t, vlc_value_t, void * );
    static int PLItemChanged( vlc_object_t *, const char *,
                            vlc_value_t, vlc_value_t, void * );
    static int PLItemAppended( vlc_object_t *, const char *,
                            vlc_value_t, vlc_value_t, void * );
    static int PLItemRemoved( vlc_object_t *, const char *,
                            vlc_value_t, vlc_value_t, void * );

311 312
public slots:
    void togglePlayPause();
313 314
    void play();
    void pause();
315
    void toggleRandom();
316 317 318
    void stop();
    void next();
    void prev();
319
    void prevOrReset();
320
    void activatePlayQuit( bool );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
321

322
    void loopRepeatLoopStatus();
323
    void changeFullscreen( bool );
324

325 326 327
private slots:
    void notifyRandom( bool );
    void notifyRepeatLoop( bool );
328
    void notifyVolume( float );
329
    void notifyMute( bool );
330
    void menusUpdateAudio( const QString& );
331

332
signals:
333
    void inputChanged( bool );
334 335
    void volumeChanged( float );
    void soundMuteChanged( bool );
336 337
    void playlistItemAppended( int itemId, int parentId );
    void playlistItemRemoved( int itemId );
338
    void playlistNotEmpty( bool );
339
    void randomChanged( bool );
340
    void repeatLoopChanged( int );
341
    void leafBecameParent( int );
342 343
};

zorglub's avatar
zorglub committed
344
#endif