1 /*****************************************************************************
2 * main_inteface.cpp : Main interface
3 ****************************************************************************
4 * Copyright (C) 2006 the VideoLAN team
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. *****************************************************************************/
24 #include "main_interface.hpp"
25 #include "input_manager.hpp"
26 #include "util/input_slider.hpp"
27 #include "util/qvlcframe.hpp"
28 #include "dialogs_provider.hpp"
29 #include "components/video_widget.hpp"
30 #include <QCloseEvent>
32 #include <QPushButton>
35 static int InteractCallback( vlc_object_t *, const char *, vlc_value_t,
38 MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
41 QWidget *main = new QWidget( this );
42 setCentralWidget( main );
43 setWindowTitle( QString::fromUtf8( _("VLC media player") ) );
44 ui.setupUi( centralWidget() );
46 slider = new InputSlider( Qt::Horizontal, ui.sliderBox );
47 QVBoxLayout *box_layout = new QVBoxLayout();
48 box_layout->addWidget( slider );
49 ui.sliderBox->setLayout( box_layout );
50 ui.prevButton->setText( "" );
51 ui.nextButton->setText( "" );
52 ui.playButton->setText( "" );
53 ui.stopButton->setText( "" );
54 ui.prevButton->setIcon( QIcon( ":/pixmaps/previous.png" ) );
55 ui.nextButton->setIcon( QIcon( ":/pixmaps/next.png" ) );
56 ui.playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
57 ui.stopButton->setIcon( QIcon( ":/pixmaps/stop.png" ) );
58 ui.volLowLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
59 ui.volHighLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
61 QVLCMenu::createMenuBar( menuBar(), p_intf );
64 // if( config_GetInt( p_intf, "embedded" ) )
67 videoWidget = new VideoWidget( p_intf );
68 if( config_GetInt( p_intf, "qt-always-video" ) )
70 QSettings settings( "VideoLAN", "VLC" );
71 settings.beginGroup( "MainWindow" );
72 videoSize = settings.value( "videoSize", QSize( 200, 200 ) ).
76 videoSize = QSize( 1,1 );
77 videoWidget->resize( videoSize );
78 ui.vboxLayout->insertWidget( 0, videoWidget );
80 fprintf( stderr, "Margin : %i\n",ui.vboxLayout->margin() );
81 readSettings( "MainWindow" );
83 addSize = QSize( ui.vboxLayout->margin() * 2, 131 );
85 if( config_GetInt( p_intf, "qt-always-video" ) )
86 mainSize = videoSize + addSize;
88 mainSize = QSize( 500,131 );
93 fprintf( stderr, "Size is %ix%i - Video %ix%i\n", mainSize.width(), mainSize.height(), videoSize.width(), videoSize.height() );
95 fprintf( stderr, "Additional size around video %ix%i", addSize.width(), addSize.height() );
96 setMinimumSize( 500, addSize.height() );
98 /* Init input manager */
99 MainInputManager::getInstance( p_intf );
101 /* Get timer updates */
102 connect( THEDP->fixed_timer, SIGNAL( timeout() ),
103 this, SLOT(updateOnTimer() ) );
105 /* Connect the input manager to the GUI elements it manages */
106 connect( THEMIM->getIM(),SIGNAL(positionUpdated( float, int, int ) ),
107 slider, SLOT( setPosition( float,int, int ) ) );
108 connect( THEMIM->getIM(), SIGNAL( positionUpdated( float, int, int ) ),
109 this, SLOT( setDisplay( float, int, int ) ) );
110 connect( THEMIM->getIM(), SIGNAL( statusChanged( int ) ),
111 this, SLOT( setStatus( int ) ) );
112 connect( slider, SIGNAL( sliderDragged( float ) ),
113 THEMIM->getIM(),SLOT( sliderUpdate( float ) ) );
116 connect( ui.playButton, SLOT( clicked() ), this, SLOT( play() ) );
117 connect( ui.stopButton, SLOT( clicked() ), this, SLOT( stop() ) );
118 connect( ui.nextButton, SLOT( clicked() ), this, SLOT( next() ) );
119 connect( ui.prevButton, SLOT( clicked() ), this, SLOT( prev() ) );
121 connect( ui.playlistButton, SLOT(clicked()),
122 THEDP, SLOT( playlistDialog() ) );
124 var_Create( p_intf, "interaction", VLC_VAR_ADDRESS );
125 var_AddCallback( p_intf, "interaction", InteractCallback, this );
126 p_intf->b_interaction = VLC_TRUE;
129 MainInterface::~MainInterface()
131 writeSettings( "MainWindow" );
132 if( config_GetInt( p_intf, "qt-always-video" ) )
134 QSettings s("VideoLAN", "VLC" );
135 s.beginGroup( "MainWindow" );
136 s.setValue( "videoSize", videoSize );
139 p_intf->b_interaction = VLC_FALSE;
140 var_DelCallback( p_intf, "interaction", InteractCallback, this );
143 void MainInterface::resizeEvent( QResizeEvent *e )
145 videoSize.setHeight( e->size().height() - addSize.height() );
146 videoSize.setWidth( e->size().width() - addSize.width() );
147 p_intf->p_sys->p_video->updateGeometry() ;
150 void MainInterface::stop()
152 playlist_Stop( THEPL );
154 void MainInterface::play()
156 if( !THEPL->i_size || !THEPL->i_enabled )
158 /* The playlist is empty, open a file requester */
163 THEMIM->togglePlayPause();
165 void MainInterface::prev()
167 playlist_Prev( THEPL );
169 void MainInterface::next()
171 playlist_Next( THEPL );
174 void MainInterface::setDisplay( float pos, int time, int length )
176 char psz_length[MSTRTIME_MAX_SIZE], psz_time[MSTRTIME_MAX_SIZE];
177 secstotimestr( psz_length, length );
178 secstotimestr( psz_time, time );
180 title.sprintf( "%s/%s", psz_time, psz_length );
181 ui.sliderBox->setTitle( title );
184 void MainInterface::setStatus( int status )
186 fprintf( stderr, "Status is now %i\n", status );
187 if( status == 2 ) // Playing
188 ui.playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
190 ui.playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
193 void MainInterface::updateOnTimer()
197 QApplication::quit();
201 void MainInterface::closeEvent( QCloseEvent *e )
204 p_intf->b_die = VLC_TRUE;
207 static int InteractCallback( vlc_object_t *p_this,
208 const char *psz_var, vlc_value_t old_val,
209 vlc_value_t new_val, void *param )
211 intf_dialog_args_t *p_arg = new intf_dialog_args_t;
212 p_arg->p_dialog = (interaction_dialog_t *)(new_val.p_address);
214 MainInterface *p_interface = (MainInterface*)param;
215 DialogEvent *event = new DialogEvent( INTF_DIALOG_INTERACTION, 0, p_arg );
216 QApplication::postEvent( THEDP, static_cast<QEvent*>(event) );