]> git.sesse.net Git - vlc/blob - modules/gui/qt4/main_interface.cpp
qt4/*: buildsytem fix + cosmetic+ copyright dates + svn Id
[vlc] / modules / gui / qt4 / main_interface.cpp
1 /*****************************************************************************
2  * main_inteface.cpp : Main interface
3  ****************************************************************************
4  * Copyright (C) 2006 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *
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.
13  *
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.
18  *
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. *****************************************************************************/
22
23 #include "qt4.hpp"
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>
31 #include <assert.h>
32 #include <QPushButton>
33
34 static int InteractCallback( vlc_object_t *, const char *, vlc_value_t,
35                              vlc_value_t, void *);
36
37 MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
38 {
39     /* All UI stuff */
40     QWidget *main = new QWidget( this );
41     setCentralWidget( main );
42     setWindowTitle( QString::fromUtf8( _("VLC media player") ) );
43     ui.setupUi( centralWidget() );
44
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" ) );
59
60     //QVLCMenu::createMenuBar();
61
62     resize (500, 131 );
63     fprintf( stderr, "Before creating the video widget, size is %ix%i\n", size().width(), size().height() );
64 //    if( config_GetInt( p_intf, "embedded" ) )
65
66     {
67         videoWidget = new VideoWidget( p_intf );
68         if( config_GetInt( p_intf, "qt-always-video" ) )
69         {
70             QSettings settings( "VideoLAN", "VLC" );
71             settings.beginGroup( "MainWindow" );
72             videoSize = settings.value( "videoSize", QSize( 200, 200 ) ).
73                                                 toSize();
74         } 
75         else
76             videoSize = QSize( 1,1 );
77         videoWidget->resize( videoSize );
78         ui.vboxLayout->insertWidget( 0, videoWidget );
79     }
80     fprintf( stderr, "Margin : %i\n",ui.vboxLayout->margin() );
81     readSettings( "MainWindow" );
82
83     addSize = QSize( ui.vboxLayout->margin() * 2, 131 );
84     
85     if( config_GetInt( p_intf, "qt-always-video" ) )
86         mainSize = videoSize + addSize;
87     else
88         mainSize = QSize( 500,131 );
89         resize( 500,131 );
90     resize( mainSize );
91     mainSize = size();
92
93     fprintf( stderr, "Size is %ix%i - Video %ix%i\n", mainSize.width(), mainSize.height(), videoSize.width(), videoSize.height() );
94
95     fprintf( stderr, "Additional size around video %ix%i", addSize.width(), addSize.height() );
96     setMinimumSize( 500, addSize.height() );
97
98     /* Init input manager */
99     MainInputManager::getInstance( p_intf );
100
101     /* Get timer updates */
102     connect( DialogsProvider::getInstance(NULL)->fixed_timer,
103              SIGNAL( timeout() ), this, SLOT(updateOnTimer() ) );
104
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 ) ) );
115
116     /* Actions */
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() ) );
121
122     connect( ui.playlistButton, SLOT(clicked() ), 
123              DialogsProvider::getInstance( p_intf ), SLOT( playlistDialog() ) );
124
125     var_Create( p_intf, "interaction", VLC_VAR_ADDRESS );
126     var_AddCallback( p_intf, "interaction", InteractCallback, this );
127     p_intf->b_interaction = VLC_TRUE;
128 }
129
130 MainInterface::~MainInterface()
131 {
132     writeSettings( "MainWindow" );
133     if( config_GetInt( p_intf, "qt-always-video" ) )
134     {
135         QSettings s("VideoLAN", "VLC" );
136         s.beginGroup( "MainWindow" );
137         s.setValue( "videoSize", videoSize );
138         s.endGroup();
139     }
140     p_intf->b_interaction = VLC_FALSE;
141     var_DelCallback( p_intf, "interaction", InteractCallback, this );
142 }
143
144 void MainInterface::resizeEvent( QResizeEvent *e )
145 {
146     fprintf( stderr, "Resized to %ix%i\n", e->size().width(), e->size().height() );
147
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() );
153      
154         videoSize.setHeight( e->size().height() - addSize.height() );
155         videoSize.setWidth( e->size().width() - addSize.width() );
156     p_intf->p_sys->p_video->updateGeometry() ;
157 }
158
159 void MainInterface::stop()
160 {
161     playlist_Stop( THEPL );
162 }
163 void MainInterface::play()
164 {
165     playlist_Play( THEPL );
166 }
167 void MainInterface::prev()
168 {
169     playlist_Prev( THEPL );
170 }
171 void MainInterface::next()
172 {
173     playlist_Next( THEPL );
174 }
175
176 void MainInterface::setDisplay( float pos, int time, int length )
177 {
178     char psz_length[MSTRTIME_MAX_SIZE], psz_time[MSTRTIME_MAX_SIZE];
179     secstotimestr( psz_length, length );
180     secstotimestr( psz_time, time );
181     QString title;
182     title.sprintf( "%s/%s", psz_time, psz_length );
183     ui.sliderBox->setTitle( title );
184 }
185
186 void MainInterface::updateOnTimer()
187 {
188     if( p_intf->b_die )
189     {
190         QApplication::quit();
191     }
192 }
193
194 void MainInterface::closeEvent( QCloseEvent *e )
195 {
196     hide();
197     p_intf->b_die = VLC_TRUE;
198 }
199
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 )
203 {
204     intf_dialog_args_t *p_arg = new intf_dialog_args_t;
205     p_arg->p_dialog = (interaction_dialog_t *)(new_val.p_address);
206     
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) );
211     return VLC_SUCCESS;
212 }