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. *****************************************************************************/
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>
34 static int InteractCallback( vlc_object_t *, const char *, vlc_value_t,
37 MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
40 QWidget *main = new QWidget( this );
41 setCentralWidget( main );
42 setWindowTitle( QString::fromUtf8( _("VLC media player") ) );
43 ui.setupUi( centralWidget() );
45 slider = new InputSlider( Qt::Horizontal, ui.sliderBox );
46 QVBoxLayout *box_layout = new QVBoxLayout();
47 box_layout->addWidget( slider );
48 ui.sliderBox->setLayout( box_layout );
49 ui.prevButton->setText( "" );
50 ui.nextButton->setText( "" );
51 ui.playButton->setText( "" );
52 ui.stopButton->setText( "" );
53 ui.prevButton->setIcon( QIcon( ":/pixmaps/previous.png" ) );
54 ui.nextButton->setIcon( QIcon( ":/pixmaps/next.png" ) );
55 ui.playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
56 ui.stopButton->setIcon( QIcon( ":/pixmaps/stop.png" ) );
57 ui.volLowLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
58 ui.volHighLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
60 //QVLCMenu::createMenuBar();
63 fprintf( stderr, "Before creating the video widget, size is %ix%i\n", size().width(), size().height() );
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( DialogsProvider::getInstance(NULL)->fixed_timer,
103 SIGNAL( timeout() ), this, SLOT(updateOnTimer() ) );
105 /* Connect the input manager to the GUI elements it manages */
106 connect( MainInputManager::getInstance( p_intf )->getIM(),
107 SIGNAL(positionUpdated( float, int, int ) ),
108 slider, SLOT( setPosition( float,int, int ) ) );
109 connect( slider, SIGNAL( sliderDragged( float ) ),
110 MainInputManager::getInstance( p_intf )->getIM(),
111 SLOT( sliderUpdate( float ) ) );
112 connect( MainInputManager::getInstance( p_intf )->getIM(),
113 SIGNAL( positionUpdated( float, int, int ) ),
114 this, SLOT( setDisplay( float, int, int ) ) );
117 connect( ui.playButton, SLOT( clicked() ), this, SLOT( play() ) );
118 connect( ui.stopButton, SLOT( clicked() ), this, SLOT( stop() ) );
119 connect( ui.nextButton, SLOT( clicked() ), this, SLOT( next() ) );
120 connect( ui.prevButton, SLOT( clicked() ), this, SLOT( prev() ) );
122 connect( ui.playlistButton, SLOT(clicked() ),
123 DialogsProvider::getInstance( p_intf ), SLOT( playlistDialog() ) );
125 var_Create( p_intf, "interaction", VLC_VAR_ADDRESS );
126 var_AddCallback( p_intf, "interaction", InteractCallback, this );
127 p_intf->b_interaction = VLC_TRUE;
130 MainInterface::~MainInterface()
132 writeSettings( "MainWindow" );
133 if( config_GetInt( p_intf, "qt-always-video" ) )
135 QSettings s("VideoLAN", "VLC" );
136 s.beginGroup( "MainWindow" );
137 s.setValue( "videoSize", videoSize );
140 p_intf->b_interaction = VLC_FALSE;
141 var_DelCallback( p_intf, "interaction", InteractCallback, this );
144 void MainInterface::resizeEvent( QResizeEvent *e )
146 fprintf( stderr, "Resized to %ix%i\n", e->size().width(), e->size().height() );
148 fprintf( stderr, "MI constraints %ix%i -> %ix%i\n",
149 p_intf->p_sys->p_mi->minimumSize().width(),
150 p_intf->p_sys->p_mi->minimumSize().height(),
151 p_intf->p_sys->p_mi->maximumSize().width(),
152 p_intf->p_sys->p_mi->maximumSize().height() );
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 playlist_Play( THEPL );
167 void MainInterface::prev()
169 playlist_Prev( THEPL );
171 void MainInterface::next()
173 playlist_Next( THEPL );
176 void MainInterface::setDisplay( float pos, int time, int length )
178 char psz_length[MSTRTIME_MAX_SIZE], psz_time[MSTRTIME_MAX_SIZE];
179 secstotimestr( psz_length, length );
180 secstotimestr( psz_time, time );
182 title.sprintf( "%s/%s", psz_time, psz_length );
183 ui.sliderBox->setTitle( title );
186 void MainInterface::updateOnTimer()
190 QApplication::quit();
194 void MainInterface::closeEvent( QCloseEvent *e )
197 p_intf->b_die = VLC_TRUE;
200 static int InteractCallback( vlc_object_t *p_this,
201 const char *psz_var, vlc_value_t old_val,
202 vlc_value_t new_val, void *param )
204 intf_dialog_args_t *p_arg = new intf_dialog_args_t;
205 p_arg->p_dialog = (interaction_dialog_t *)(new_val.p_address);
207 MainInterface *p_interface = (MainInterface*)param;
208 DialogEvent *event = new DialogEvent( INTF_DIALOG_INTERACTION, 0, p_arg );
209 QApplication::postEvent( DialogsProvider::getInstance( NULL ),
210 static_cast<QEvent*>(event) );