main_interface.cpp 5.27 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
Icons  
zorglub committed
40

zorglub's avatar
zorglub committed
41 42 43 44
    slider = new InputSlider( Qt::Horizontal, ui.sliderBox );
    QVBoxLayout *box_layout = new QVBoxLayout();
    box_layout->addWidget( slider );
    ui.sliderBox->setLayout( box_layout );
zorglub's avatar
Icons  
zorglub committed
45 46 47 48 49 50 51
    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" ) );

52
    resize( QSize( 450, 80 ) );
zorglub's avatar
Icons  
zorglub committed
53 54

    //QVLCMenu::createMenuBar();
zorglub's avatar
zorglub committed
55 56

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

zorglub's avatar
zorglub committed
59
    /* Get timer updates */
zorglub's avatar
zorglub committed
60 61
    connect( DialogsProvider::getInstance(NULL)->fixed_timer,
             SIGNAL( timeout() ), this, SLOT(updateOnTimer() ) );
zorglub's avatar
zorglub committed
62

zorglub's avatar
zorglub committed
63
    /* Connect the input manager to the GUI elements it manages */
64 65
    connect( MainInputManager::getInstance( p_intf )->getIM(),
             SIGNAL(positionUpdated( float, int, int ) ),
zorglub's avatar
zorglub committed
66 67
             slider, SLOT( setPosition( float,int, int ) ) );
    connect( slider, SIGNAL( sliderDragged( float ) ),
68 69 70 71
             MainInputManager::getInstance( p_intf )->getIM(),
             SLOT( sliderUpdate( float ) ) );
    connect( MainInputManager::getInstance( p_intf )->getIM(),
             SIGNAL( positionUpdated( float, int, int ) ),
zorglub's avatar
zorglub committed
72
             this, SLOT( setDisplay( float, int, int ) ) );
73

zorglub's avatar
zorglub committed
74 75 76 77 78
    /* 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
79 80 81

    connect( ui.playlistButton, SLOT(clicked() ), 
             DialogsProvider::getInstance( p_intf ), SLOT( playlistDialog() ) );
zorglub's avatar
zorglub committed
82 83 84 85 86
}

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

zorglub's avatar
zorglub committed
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 130 131 132 133 134 135 136 137 138 139
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
140 141
void MainInterface::updateOnTimer()
{
zorglub's avatar
zorglub committed
142 143 144 145 146 147 148 149 150 151
    if( p_intf->b_die )
    {
        QApplication::quit();
    }
}

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