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>
39 static int InteractCallback( vlc_object_t *, const char *, vlc_value_t,
42 MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
45 QWidget *main = new QWidget( this );
46 setCentralWidget( main );
47 setWindowTitle( QString::fromUtf8( _("VLC media player") ) );
48 ui.setupUi( centralWidget() );
50 slider = new InputSlider( Qt::Horizontal, NULL );
51 ui.hboxLayout->insertWidget( 0, slider );
52 ui.prevButton->setText( "" );
53 ui.nextButton->setText( "" );
54 ui.playButton->setText( "" );
55 ui.stopButton->setText( "" );
56 ui.prevButton->setIcon( QIcon( ":/pixmaps/previous.png" ) );
57 ui.nextButton->setIcon( QIcon( ":/pixmaps/next.png" ) );
58 ui.playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
59 ui.stopButton->setIcon( QIcon( ":/pixmaps/stop.png" ) );
60 ui.volLowLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
61 ui.volHighLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
63 QVLCMenu::createMenuBar( menuBar(), p_intf );
65 timeLabel = new QLabel( 0 );
66 nameLabel = new QLabel( 0 );
67 statusBar()->addWidget( nameLabel, 4 );
68 statusBar()->addPermanentWidget( timeLabel, 1 );
70 resize ( PREF_W, PREF_H );
71 // if( config_GetInt( p_intf, "embedded" ) )
74 videoWidget = new VideoWidget( p_intf );
75 if( config_GetInt( p_intf, "qt-always-video" ) )
77 QSettings settings( "VideoLAN", "VLC" );
78 settings.beginGroup( "MainWindow" );
79 videoSize = settings.value( "videoSize", QSize( 200, 200 ) ).
83 videoSize = QSize( 1,1 );
84 videoWidget->resize( videoSize );
85 ui.vboxLayout->insertWidget( 0, videoWidget );
87 fprintf( stderr, "Margin : %i\n",ui.vboxLayout->margin() );
88 readSettings( "MainWindow" );
90 addSize = QSize( ui.vboxLayout->margin() * 2, PREF_H );
92 if( config_GetInt( p_intf, "qt-always-video" ) )
93 mainSize = videoSize + addSize;
95 mainSize = QSize( PREF_W, PREF_H );
100 fprintf( stderr, "Size is %ix%i - Video %ix%i\n", mainSize.width(), mainSize.height(), videoSize.width(), videoSize.height() );
102 fprintf( stderr, "Additional size around video %ix%i", addSize.width(), addSize.height() );
103 setMinimumSize( PREF_W, addSize.height() );
105 /* Init input manager */
106 MainInputManager::getInstance( p_intf );
108 /* Get timer updates */
109 connect( THEDP->fixed_timer, SIGNAL( timeout() ),
110 this, SLOT(updateOnTimer() ) );
112 /* Connect the input manager to the GUI elements it manages */
113 connect( THEMIM->getIM(),SIGNAL(positionUpdated( float, int, int ) ),
114 slider, SLOT( setPosition( float,int, int ) ) );
115 connect( THEMIM->getIM(), SIGNAL( positionUpdated( float, int, int ) ),
116 this, SLOT( setDisplay( float, int, int ) ) );
117 connect( THEMIM->getIM(), SIGNAL( nameChanged( QString ) ),
118 this, SLOT( setName( QString ) ) );
119 connect( THEMIM->getIM(), SIGNAL( statusChanged( int ) ),
120 this, SLOT( setStatus( int ) ) );
121 connect( slider, SIGNAL( sliderDragged( float ) ),
122 THEMIM->getIM(),SLOT( sliderUpdate( float ) ) );
125 connect( ui.playButton, SIGNAL( clicked() ), this, SLOT( play() ) );
126 connect( ui.stopButton, SIGNAL( clicked() ), this, SLOT( stop() ) );
127 connect( ui.nextButton, SIGNAL( clicked() ), this, SLOT( next() ) );
128 connect( ui.prevButton, SIGNAL( clicked() ), this, SLOT( prev() ) );
130 connect( ui.playlistButton, SIGNAL(clicked()),
131 THEDP, SLOT( playlistDialog() ) );
133 var_Create( p_intf, "interaction", VLC_VAR_ADDRESS );
134 var_AddCallback( p_intf, "interaction", InteractCallback, this );
135 p_intf->b_interaction = VLC_TRUE;
138 MainInterface::~MainInterface()
140 writeSettings( "MainWindow" );
141 if( config_GetInt( p_intf, "qt-always-video" ) )
143 QSettings s("VideoLAN", "VLC" );
144 s.beginGroup( "MainWindow" );
145 s.setValue( "videoSize", videoSize );
148 p_intf->b_interaction = VLC_FALSE;
149 var_DelCallback( p_intf, "interaction", InteractCallback, this );
152 void MainInterface::resizeEvent( QResizeEvent *e )
154 videoSize.setHeight( e->size().height() - addSize.height() );
155 videoSize.setWidth( e->size().width() - addSize.width() );
156 p_intf->p_sys->p_video->updateGeometry() ;
159 void MainInterface::stop()
161 playlist_Stop( THEPL );
163 void MainInterface::play()
165 if( !THEPL->i_size || !THEPL->i_enabled )
167 /* The playlist is empty, open a file requester */
172 THEMIM->togglePlayPause();
174 void MainInterface::prev()
176 playlist_Prev( THEPL );
178 void MainInterface::next()
180 playlist_Next( THEPL );
183 void MainInterface::setDisplay( float pos, int time, int length )
185 char psz_length[MSTRTIME_MAX_SIZE], psz_time[MSTRTIME_MAX_SIZE];
186 secstotimestr( psz_length, length );
187 secstotimestr( psz_time, time );
189 title.sprintf( "%s/%s", psz_time, psz_length );
190 timeLabel->setText( title );
193 void MainInterface::setName( QString name )
195 nameLabel->setText( name );
198 void MainInterface::setStatus( int status )
200 fprintf( stderr, "Status is now %i\n", status );
201 if( status == 2 ) // Playing
202 ui.playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
204 ui.playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
207 void MainInterface::updateOnTimer()
211 QApplication::quit();
215 void MainInterface::closeEvent( QCloseEvent *e )
218 p_intf->b_die = VLC_TRUE;
221 static int InteractCallback( vlc_object_t *p_this,
222 const char *psz_var, vlc_value_t old_val,
223 vlc_value_t new_val, void *param )
225 intf_dialog_args_t *p_arg = new intf_dialog_args_t;
226 p_arg->p_dialog = (interaction_dialog_t *)(new_val.p_address);
228 MainInterface *p_interface = (MainInterface*)param;
229 DialogEvent *event = new DialogEvent( INTF_DIALOG_INTERACTION, 0, p_arg );
230 QApplication::postEvent( THEDP, static_cast<QEvent*>(event) );