main_interface.cpp 5.3 KB
Newer Older
zorglub's avatar
zorglub committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*****************************************************************************
 * main_inteface.cpp : Main interface
 ****************************************************************************
 * Copyright (C) 2000-2005 the VideoLAN team
 * $Id: wxwidgets.cpp 15731 2006-05-25 14:43:53Z zorglub $
 *
 * Authors: Clément Stenac <zorglub@videolan.org>
 *
 * 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. *****************************************************************************/

#include "main_interface.hpp"
zorglub's avatar
zorglub committed
24
#include "input_manager.hpp"
25
#include "util/input_slider.hpp"
zorglub's avatar
zorglub committed
26
#include "dialogs_provider.hpp"
zorglub's avatar
zorglub committed
27
#include <QCloseEvent>
28
#include <assert.h>
zorglub's avatar
zorglub committed
29
#include <QPushButton>
zorglub's avatar
zorglub committed
30

zorglub's avatar
zorglub committed
31
MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
zorglub's avatar
zorglub committed
32
{
zorglub's avatar
zorglub committed
33
    /* Init UI */
zorglub's avatar
zorglub committed
34
35
36
37
38
39
    setWindowTitle( _("VLC media player") );
    ui.setupUi( this );
    slider = new InputSlider( Qt::Horizontal, ui.sliderBox );
    QVBoxLayout *box_layout = new QVBoxLayout();
    box_layout->addWidget( slider );
    ui.sliderBox->setLayout( box_layout );
zorglub's avatar
zorglub committed
40
41

    /* Init input manager */
zorglub's avatar
zorglub committed
42
43
    p_input = NULL;
    main_input_manager = new InputManager( this, p_intf );
zorglub's avatar
zorglub committed
44

zorglub's avatar
zorglub committed
45
    /* Get timer updates */
zorglub's avatar
zorglub committed
46
47
    connect( DialogsProvider::getInstance(NULL)->fixed_timer,
             SIGNAL( timeout() ), this, SLOT(updateOnTimer() ) );
zorglub's avatar
zorglub committed
48
    /* Tell input manager about the input changes */
zorglub's avatar
zorglub committed
49
50
    connect( this, SIGNAL( inputChanged( input_thread_t * ) ),
             main_input_manager, SLOT( setInput( input_thread_t * ) ) );
zorglub's avatar
zorglub committed
51

zorglub's avatar
zorglub committed
52
    /* Connect the input manager to the GUI elements it manages */
zorglub's avatar
zorglub committed
53
54
55
56
    connect( main_input_manager, SIGNAL(positionUpdated( float, int, int ) ),
             slider, SLOT( setPosition( float,int, int ) ) );
    connect( slider, SIGNAL( sliderDragged( float ) ),
             main_input_manager, SLOT( sliderUpdate( float ) ) );
zorglub's avatar
zorglub committed
57
58
    connect( main_input_manager, SIGNAL( positionUpdated( float, int, int ) ),
             this, SLOT( setDisplay( float, int, int ) ) );
59

zorglub's avatar
zorglub committed
60
61
62
63
64
    /* Actions */
    connect( ui.playButton, SLOT( clicked() ), this, SLOT( play() ) );
    connect( ui.stopButton, SLOT( clicked() ), this, SLOT( stop() ) );
    connect( ui.nextButton, SLOT( clicked() ), this, SLOT( next() ) );
    connect( ui.prevButton, SLOT( clicked() ), this, SLOT( prev() ) );
zorglub's avatar
zorglub committed
65
66
67
68
69
}

MainInterface::~MainInterface()
{
}
zorglub's avatar
zorglub committed
70

zorglub's avatar
zorglub committed
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
void MainInterface::stop()
{
    /// \todo store playlist globally
    playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
                                VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
    if( !p_playlist ) return;
    playlist_Stop( p_playlist );
    vlc_object_release( p_playlist );
}
void MainInterface::play()
{
    /// \todo store playlist globally
    playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
                                VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
    if( !p_playlist ) return;
    playlist_Play( p_playlist );
    vlc_object_release( p_playlist );
}
void MainInterface::prev()
{
    /// \todo store playlist globally
    playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
                                VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
    if( !p_playlist ) return;
    playlist_Prev( p_playlist );
    vlc_object_release( p_playlist );
}
void MainInterface::next()
{
    /// \todo store playlist globally
    playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
                                VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
    if( !p_playlist ) return;
    playlist_Next( p_playlist );
    vlc_object_release( p_playlist );
}






void MainInterface::setDisplay( float pos, int time, int length )
{
    char psz_length[MSTRTIME_MAX_SIZE], psz_time[MSTRTIME_MAX_SIZE];
    secstotimestr( psz_length, length );
    secstotimestr( psz_time, time );
    QString title;
    title.sprintf( "%s/%s", psz_time, psz_length );
    ui.sliderBox->setTitle( title );
}

zorglub's avatar
zorglub committed
123
124
void MainInterface::updateOnTimer()
{
zorglub's avatar
zorglub committed
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
    if( p_intf->b_die )
    {
        QApplication::quit();
    }
    vlc_mutex_lock( &p_intf->change_lock );
    if( p_input && p_input->b_dead )
    {
        vlc_object_release( p_input );
        p_input = NULL;
        emit inputChanged( NULL );
    }

    if( !p_input )
    {
        playlist_t *p_playlist = (playlist_t *) vlc_object_find( p_intf,
                                        VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
        assert( p_playlist );
        PL_LOCK;

        p_input = p_playlist->p_input;
        if( p_input )
        {
            vlc_object_yield( p_input );
            emit inputChanged( p_input );
        }
zorglub's avatar
zorglub committed
150

zorglub's avatar
zorglub committed
151
152
153
154
155
156
157
158
159
160
        PL_UNLOCK;
        vlc_object_release( p_playlist );
    }
    vlc_mutex_unlock( &p_intf->change_lock );
}

void MainInterface::closeEvent( QCloseEvent *e )
{
    hide();
    p_intf->b_die = VLC_TRUE;
zorglub's avatar
zorglub committed
161
}