1 /*****************************************************************************
2 * main_inteface.cpp : Main interface
3 ****************************************************************************
4 * Copyright (C) 2000-2005 the VideoLAN team
5 * $Id: wxwidgets.cpp 15731 2006-05-25 14:43:53Z zorglub $
7 * Authors: Clément Stenac <zorglub@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/
23 #include "main_interface.hpp"
24 #include "input_manager.hpp"
25 #include "util/input_slider.hpp"
26 #include "util/qvlcframe.hpp"
27 #include "dialogs_provider.hpp"
28 #include <QCloseEvent>
30 #include <QPushButton>
32 MainInterface::MainInterface( intf_thread_t *_p_intf ) : QMainWindow(), p_intf( _p_intf )
35 QVLCFrame::fixStyle( this );
36 QWidget *main = new QWidget( this );
37 setCentralWidget( main );
38 setWindowTitle( _("VLC media player") );
39 ui.setupUi( centralWidget() );
40 slider = new InputSlider( Qt::Horizontal, ui.sliderBox );
41 QVBoxLayout *box_layout = new QVBoxLayout();
42 box_layout->addWidget( slider );
43 ui.sliderBox->setLayout( box_layout );
44 resize( QSize( 450, 80 ) );
46 /* Init input manager */
47 MainInputManager::getInstance( p_intf );
49 /* Get timer updates */
50 connect( DialogsProvider::getInstance(NULL)->fixed_timer,
51 SIGNAL( timeout() ), this, SLOT(updateOnTimer() ) );
53 /* Connect the input manager to the GUI elements it manages */
54 connect( MainInputManager::getInstance( p_intf )->getIM(),
55 SIGNAL(positionUpdated( float, int, int ) ),
56 slider, SLOT( setPosition( float,int, int ) ) );
57 connect( slider, SIGNAL( sliderDragged( float ) ),
58 MainInputManager::getInstance( p_intf )->getIM(),
59 SLOT( sliderUpdate( float ) ) );
60 connect( MainInputManager::getInstance( p_intf )->getIM(),
61 SIGNAL( positionUpdated( float, int, int ) ),
62 this, SLOT( setDisplay( float, int, int ) ) );
65 connect( ui.playButton, SLOT( clicked() ), this, SLOT( play() ) );
66 connect( ui.stopButton, SLOT( clicked() ), this, SLOT( stop() ) );
67 connect( ui.nextButton, SLOT( clicked() ), this, SLOT( next() ) );
68 connect( ui.prevButton, SLOT( clicked() ), this, SLOT( prev() ) );
70 connect( ui.playlistButton, SLOT(clicked() ),
71 DialogsProvider::getInstance( p_intf ), SLOT( playlistDialog() ) );
74 MainInterface::~MainInterface()
78 void MainInterface::stop()
80 /// \todo store playlist globally
81 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
82 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
83 if( !p_playlist ) return;
84 playlist_Stop( p_playlist );
85 vlc_object_release( p_playlist );
87 void MainInterface::play()
89 /// \todo store playlist globally
90 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
91 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
92 if( !p_playlist ) return;
93 playlist_Play( p_playlist );
94 vlc_object_release( p_playlist );
96 void MainInterface::prev()
98 /// \todo store playlist globally
99 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
100 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
101 if( !p_playlist ) return;
102 playlist_Prev( p_playlist );
103 vlc_object_release( p_playlist );
105 void MainInterface::next()
107 /// \todo store playlist globally
108 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
109 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
110 if( !p_playlist ) return;
111 playlist_Next( p_playlist );
112 vlc_object_release( p_playlist );
120 void MainInterface::setDisplay( float pos, int time, int length )
122 char psz_length[MSTRTIME_MAX_SIZE], psz_time[MSTRTIME_MAX_SIZE];
123 secstotimestr( psz_length, length );
124 secstotimestr( psz_time, time );
126 title.sprintf( "%s/%s", psz_time, psz_length );
127 ui.sliderBox->setTitle( title );
130 void MainInterface::updateOnTimer()
134 QApplication::quit();
138 void MainInterface::closeEvent( QCloseEvent *e )
141 p_intf->b_die = VLC_TRUE;