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() );
41 slider = new InputSlider( Qt::Horizontal, ui.sliderBox );
42 QVBoxLayout *box_layout = new QVBoxLayout();
43 box_layout->addWidget( slider );
44 ui.sliderBox->setLayout( box_layout );
45 ui.prevButton->setIcon( QIcon( ":/pixmaps/previous.png" ) );
46 ui.nextButton->setIcon( QIcon( ":/pixmaps/next.png" ) );
47 ui.playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
48 ui.stopButton->setIcon( QIcon( ":/pixmaps/stop.png" ) );
49 ui.volLowLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
50 ui.volHighLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
52 resize( QSize( 450, 80 ) );
54 //QVLCMenu::createMenuBar();
56 /* Init input manager */
57 MainInputManager::getInstance( p_intf );
59 /* Get timer updates */
60 connect( DialogsProvider::getInstance(NULL)->fixed_timer,
61 SIGNAL( timeout() ), this, SLOT(updateOnTimer() ) );
63 /* Connect the input manager to the GUI elements it manages */
64 connect( MainInputManager::getInstance( p_intf )->getIM(),
65 SIGNAL(positionUpdated( float, int, int ) ),
66 slider, SLOT( setPosition( float,int, int ) ) );
67 connect( slider, SIGNAL( sliderDragged( float ) ),
68 MainInputManager::getInstance( p_intf )->getIM(),
69 SLOT( sliderUpdate( float ) ) );
70 connect( MainInputManager::getInstance( p_intf )->getIM(),
71 SIGNAL( positionUpdated( float, int, int ) ),
72 this, SLOT( setDisplay( float, int, int ) ) );
75 connect( ui.playButton, SLOT( clicked() ), this, SLOT( play() ) );
76 connect( ui.stopButton, SLOT( clicked() ), this, SLOT( stop() ) );
77 connect( ui.nextButton, SLOT( clicked() ), this, SLOT( next() ) );
78 connect( ui.prevButton, SLOT( clicked() ), this, SLOT( prev() ) );
80 connect( ui.playlistButton, SLOT(clicked() ),
81 DialogsProvider::getInstance( p_intf ), SLOT( playlistDialog() ) );
84 MainInterface::~MainInterface()
88 void MainInterface::stop()
90 /// \todo store playlist globally
91 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
92 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
93 if( !p_playlist ) return;
94 playlist_Stop( p_playlist );
95 vlc_object_release( p_playlist );
97 void MainInterface::play()
99 /// \todo store playlist globally
100 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
101 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
102 if( !p_playlist ) return;
103 playlist_Play( p_playlist );
104 vlc_object_release( p_playlist );
106 void MainInterface::prev()
108 /// \todo store playlist globally
109 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
110 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
111 if( !p_playlist ) return;
112 playlist_Prev( p_playlist );
113 vlc_object_release( p_playlist );
115 void MainInterface::next()
117 /// \todo store playlist globally
118 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
119 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
120 if( !p_playlist ) return;
121 playlist_Next( p_playlist );
122 vlc_object_release( p_playlist );
130 void MainInterface::setDisplay( float pos, int time, int length )
132 char psz_length[MSTRTIME_MAX_SIZE], psz_time[MSTRTIME_MAX_SIZE];
133 secstotimestr( psz_length, length );
134 secstotimestr( psz_time, time );
136 title.sprintf( "%s/%s", psz_time, psz_length );
137 ui.sliderBox->setTitle( title );
140 void MainInterface::updateOnTimer()
144 QApplication::quit();
148 void MainInterface::closeEvent( QCloseEvent *e )
151 p_intf->b_die = VLC_TRUE;