main_interface.cpp 4.85 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 "util/qvlcframe.hpp"
zorglub's avatar
zorglub committed
27
#include "dialogs_provider.hpp"
zorglub's avatar
zorglub committed
28
#include <QCloseEvent>
29
#include <assert.h>
zorglub's avatar
zorglub committed
30
#include <QPushButton>
zorglub's avatar
zorglub committed
31

32
MainInterface::MainInterface( intf_thread_t *_p_intf ) : QMainWindow(), p_intf( _p_intf )
zorglub's avatar
zorglub committed
33
{
34
35
36
37
    /* All UI stuff */
    QVLCFrame::fixStyle( this );
    QWidget *main = new QWidget( this );
    setCentralWidget( main );
zorglub's avatar
zorglub committed
38
    setWindowTitle( _("VLC media player") );
39
    ui.setupUi( centralWidget() );
zorglub's avatar
zorglub committed
40
41
42
43
    slider = new InputSlider( Qt::Horizontal, ui.sliderBox );
    QVBoxLayout *box_layout = new QVBoxLayout();
    box_layout->addWidget( slider );
    ui.sliderBox->setLayout( box_layout );
44
    resize( QSize( 450, 80 ) );
zorglub's avatar
zorglub committed
45
46

    /* Init input manager */
47
    MainInputManager::getInstance( p_intf );
zorglub's avatar
zorglub committed
48

zorglub's avatar
zorglub committed
49
    /* Get timer updates */
zorglub's avatar
zorglub committed
50
51
    connect( DialogsProvider::getInstance(NULL)->fixed_timer,
             SIGNAL( timeout() ), this, SLOT(updateOnTimer() ) );
zorglub's avatar
zorglub committed
52

zorglub's avatar
zorglub committed
53
    /* Connect the input manager to the GUI elements it manages */
54
55
    connect( MainInputManager::getInstance( p_intf )->getIM(),
             SIGNAL(positionUpdated( float, int, int ) ),
zorglub's avatar
zorglub committed
56
57
             slider, SLOT( setPosition( float,int, int ) ) );
    connect( slider, SIGNAL( sliderDragged( float ) ),
58
59
60
61
             MainInputManager::getInstance( p_intf )->getIM(),
             SLOT( sliderUpdate( float ) ) );
    connect( MainInputManager::getInstance( p_intf )->getIM(),
             SIGNAL( positionUpdated( float, int, int ) ),
zorglub's avatar
zorglub committed
62
             this, SLOT( setDisplay( float, int, int ) ) );
63

zorglub's avatar
zorglub committed
64
65
66
67
68
    /* 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
69
70
71

    connect( ui.playlistButton, SLOT(clicked() ), 
             DialogsProvider::getInstance( p_intf ), SLOT( playlistDialog() ) );
zorglub's avatar
zorglub committed
72
73
74
75
76
}

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

zorglub's avatar
zorglub committed
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
123
124
125
126
127
128
129
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
130
131
void MainInterface::updateOnTimer()
{
zorglub's avatar
zorglub committed
132
133
134
135
136
137
138
139
140
141
    if( p_intf->b_die )
    {
        QApplication::quit();
    }
}

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