main_interface.cpp 7.37 KB
Newer Older
zorglub's avatar
zorglub committed
1 2 3
/*****************************************************************************
 * main_inteface.cpp : Main interface
 ****************************************************************************
4 5
 * Copyright (C) 2006 the VideoLAN team
 * $Id$
zorglub's avatar
zorglub committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *
 * 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. *****************************************************************************/

23
#include "qt4.hpp"
zorglub's avatar
zorglub committed
24
#include "main_interface.hpp"
zorglub's avatar
zorglub committed
25
#include "input_manager.hpp"
26
#include "util/input_slider.hpp"
zorglub's avatar
zorglub committed
27
#include "util/qvlcframe.hpp"
zorglub's avatar
zorglub committed
28
#include "dialogs_provider.hpp"
29
#include "components/video_widget.hpp"
zorglub's avatar
zorglub committed
30
#include <QCloseEvent>
31
#include <assert.h>
zorglub's avatar
zorglub committed
32
#include <QPushButton>
33
#include "menus.hpp"
zorglub's avatar
zorglub committed
34

zorglub's avatar
zorglub committed
35 36 37
static int InteractCallback( vlc_object_t *, const char *, vlc_value_t,
                             vlc_value_t, void *);

zorglub's avatar
zorglub committed
38
MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
zorglub's avatar
zorglub committed
39
{
40 41 42
    /* All UI stuff */
    QWidget *main = new QWidget( this );
    setCentralWidget( main );
zorglub's avatar
zorglub committed
43
    setWindowTitle( QString::fromUtf8( _("VLC media player") ) );
44
    ui.setupUi( centralWidget() );
zorglub's avatar
Icons  
zorglub committed
45

zorglub's avatar
zorglub committed
46 47 48 49
    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
50 51 52 53
    ui.prevButton->setText( "" );
    ui.nextButton->setText( "" );
    ui.playButton->setText( "" ); 
    ui.stopButton->setText( "" ); 
zorglub's avatar
Icons  
zorglub committed
54 55 56 57 58 59 60
    ui.prevButton->setIcon( QIcon( ":/pixmaps/previous.png" ) );
    ui.nextButton->setIcon( QIcon( ":/pixmaps/next.png" ) );
    ui.playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
    ui.stopButton->setIcon( QIcon( ":/pixmaps/stop.png" ) );
    ui.volLowLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
    ui.volHighLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );

61
    QVLCMenu::createMenuBar( menuBar(), p_intf );
zorglub's avatar
zorglub committed
62 63

    resize (500, 131 );
64
//    if( config_GetInt( p_intf, "embedded" ) )
zorglub's avatar
zorglub committed
65

66 67
    {
        videoWidget = new VideoWidget( p_intf );
zorglub's avatar
zorglub committed
68 69 70 71 72 73 74 75 76 77
        if( config_GetInt( p_intf, "qt-always-video" ) )
        {
            QSettings settings( "VideoLAN", "VLC" );
            settings.beginGroup( "MainWindow" );
            videoSize = settings.value( "videoSize", QSize( 200, 200 ) ).
                                                toSize();
        } 
        else
            videoSize = QSize( 1,1 );
        videoWidget->resize( videoSize );
78 79
        ui.vboxLayout->insertWidget( 0, videoWidget );
    }
zorglub's avatar
zorglub committed
80 81
    fprintf( stderr, "Margin : %i\n",ui.vboxLayout->margin() );
    readSettings( "MainWindow" );
zorglub's avatar
zorglub committed
82

zorglub's avatar
zorglub committed
83 84 85 86 87 88 89 90 91
    addSize = QSize( ui.vboxLayout->margin() * 2, 131 );
    
    if( config_GetInt( p_intf, "qt-always-video" ) )
        mainSize = videoSize + addSize;
    else
        mainSize = QSize( 500,131 );
        resize( 500,131 );
    resize( mainSize );
    mainSize = size();
zorglub's avatar
Icons  
zorglub committed
92

zorglub's avatar
zorglub committed
93 94 95 96
    fprintf( stderr, "Size is %ix%i - Video %ix%i\n", mainSize.width(), mainSize.height(), videoSize.width(), videoSize.height() );

    fprintf( stderr, "Additional size around video %ix%i", addSize.width(), addSize.height() );
    setMinimumSize( 500, addSize.height() );
zorglub's avatar
zorglub committed
97 98

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

zorglub's avatar
zorglub committed
101
    /* Get timer updates */
102 103
    connect( THEDP->fixed_timer, SIGNAL( timeout() ),
             this, SLOT(updateOnTimer() ) );
zorglub's avatar
zorglub committed
104

zorglub's avatar
zorglub committed
105
    /* Connect the input manager to the GUI elements it manages */
106
    connect( THEMIM->getIM(),SIGNAL(positionUpdated( float, int, int ) ),
zorglub's avatar
zorglub committed
107
             slider, SLOT( setPosition( float,int, int ) ) );
108
    connect( THEMIM->getIM(), SIGNAL( positionUpdated( float, int, int ) ),
zorglub's avatar
zorglub committed
109
             this, SLOT( setDisplay( float, int, int ) ) );
110 111 112 113
    connect( THEMIM->getIM(), SIGNAL( statusChanged( int ) ),
             this, SLOT( setStatus( int ) ) );
    connect( slider, SIGNAL( sliderDragged( float ) ),
             THEMIM->getIM(),SLOT( sliderUpdate( float ) ) );
114

zorglub's avatar
zorglub committed
115 116 117 118 119
    /* 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
120

121 122
    connect( ui.playlistButton, SLOT(clicked()),
             THEDP, SLOT( playlistDialog() ) );
zorglub's avatar
zorglub committed
123 124 125 126

    var_Create( p_intf, "interaction", VLC_VAR_ADDRESS );
    var_AddCallback( p_intf, "interaction", InteractCallback, this );
    p_intf->b_interaction = VLC_TRUE;
zorglub's avatar
zorglub committed
127 128 129 130
}

MainInterface::~MainInterface()
{
zorglub's avatar
zorglub committed
131 132 133 134 135 136 137 138 139 140
    writeSettings( "MainWindow" );
    if( config_GetInt( p_intf, "qt-always-video" ) )
    {
        QSettings s("VideoLAN", "VLC" );
        s.beginGroup( "MainWindow" );
        s.setValue( "videoSize", videoSize );
        s.endGroup();
    }
    p_intf->b_interaction = VLC_FALSE;
    var_DelCallback( p_intf, "interaction", InteractCallback, this );
zorglub's avatar
zorglub committed
141
}
zorglub's avatar
zorglub committed
142

zorglub's avatar
zorglub committed
143
void MainInterface::resizeEvent( QResizeEvent *e )
144
{
145 146
    videoSize.setHeight( e->size().height() - addSize.height() );
    videoSize.setWidth( e->size().width() - addSize.width() );
zorglub's avatar
zorglub committed
147
    p_intf->p_sys->p_video->updateGeometry() ;
148 149
}

zorglub's avatar
zorglub committed
150 151
void MainInterface::stop()
{
152
    playlist_Stop( THEPL );
zorglub's avatar
zorglub committed
153 154 155
}
void MainInterface::play()
{
156 157 158 159 160 161 162 163
    if( !THEPL->i_size || !THEPL->i_enabled )
    {
        /* The playlist is empty, open a file requester */
        THEDP->openDialog();
        setStatus( 0 );
        return;
    }
    THEMIM->togglePlayPause();
zorglub's avatar
zorglub committed
164 165 166
}
void MainInterface::prev()
{
167
    playlist_Prev( THEPL );
zorglub's avatar
zorglub committed
168 169 170
}
void MainInterface::next()
{
171
    playlist_Next( THEPL );
zorglub's avatar
zorglub committed
172 173 174 175 176 177 178 179 180 181 182 183
}

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 );
}

184 185 186 187 188 189 190 191 192
void MainInterface::setStatus( int status )
{
    fprintf( stderr, "Status is now %i\n", status );
    if( status == 2 ) // Playing
        ui.playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
    else
        ui.playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
}

zorglub's avatar
zorglub committed
193 194
void MainInterface::updateOnTimer()
{
zorglub's avatar
zorglub committed
195 196 197 198 199 200 201 202 203 204
    if( p_intf->b_die )
    {
        QApplication::quit();
    }
}

void MainInterface::closeEvent( QCloseEvent *e )
{
    hide();
    p_intf->b_die = VLC_TRUE;
zorglub's avatar
zorglub committed
205
}
zorglub's avatar
zorglub committed
206 207 208 209 210 211 212 213 214 215

static int InteractCallback( vlc_object_t *p_this,
                             const char *psz_var, vlc_value_t old_val,
                             vlc_value_t new_val, void *param )
{
    intf_dialog_args_t *p_arg = new intf_dialog_args_t;
    p_arg->p_dialog = (interaction_dialog_t *)(new_val.p_address);
    
    MainInterface *p_interface = (MainInterface*)param;
    DialogEvent *event = new DialogEvent( INTF_DIALOG_INTERACTION, 0, p_arg );
216
    QApplication::postEvent( THEDP, static_cast<QEvent*>(event) );
zorglub's avatar
zorglub committed
217 218
    return VLC_SUCCESS;
}