]> git.sesse.net Git - vlc/blob - modules/gui/qt4/main_interface.cpp
Icons support
[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 #include <QStatusBar>
34 #include "menus.hpp"
35
36 #define PREF_W 480
37 #define PREF_H 125
38
39 static int InteractCallback( vlc_object_t *, const char *, vlc_value_t,
40                              vlc_value_t, void *);
41
42 MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
43 {
44     /* All UI stuff */
45     QWidget *main = new QWidget( this );
46     setCentralWidget( main );
47     setWindowTitle( QString::fromUtf8( _("VLC media player") ) );
48     ui.setupUi( centralWidget() );
49
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" ) );
62
63     QVLCMenu::createMenuBar( menuBar(), p_intf );
64
65     timeLabel = new QLabel( 0 );
66     nameLabel = new QLabel( 0 );
67     statusBar()->addWidget( nameLabel, 4 );
68     statusBar()->addPermanentWidget( timeLabel, 1 );
69
70     resize ( PREF_W, PREF_H );
71 //    if( config_GetInt( p_intf, "embedded" ) )
72
73     {
74         videoWidget = new VideoWidget( p_intf );
75         if( config_GetInt( p_intf, "qt-always-video" ) )
76         {
77             QSettings settings( "VideoLAN", "VLC" );
78             settings.beginGroup( "MainWindow" );
79             videoSize = settings.value( "videoSize", QSize( 200, 200 ) ).
80                                                 toSize();
81         }
82         else
83             videoSize = QSize( 1,1 );
84         videoWidget->resize( videoSize );
85         ui.vboxLayout->insertWidget( 0, videoWidget );
86     }
87     readSettings( "MainWindow" );
88
89     addSize = QSize( ui.vboxLayout->margin() * 2, PREF_H );
90     if( config_GetInt( p_intf, "qt-always-video" ) )
91         mainSize = videoSize + addSize;
92     else
93         mainSize = QSize( PREF_W, PREF_H );
94     resize( mainSize );
95     mainSize = size();
96
97     setMinimumSize( PREF_W, addSize.height() );
98
99     /* Init input manager */
100     MainInputManager::getInstance( p_intf );
101
102     /* Get timer updates */
103     connect( THEDP->fixed_timer, SIGNAL( timeout() ),
104              this, SLOT(updateOnTimer() ) );
105
106     /* Connect the input manager to the GUI elements it manages */
107     connect( THEMIM->getIM(),SIGNAL(positionUpdated( float, int, int ) ),
108              slider, SLOT( setPosition( float,int, int ) ) );
109     connect( THEMIM->getIM(), SIGNAL( positionUpdated( float, int, int ) ),
110              this, SLOT( setDisplay( float, int, int ) ) );
111     connect( THEMIM->getIM(), SIGNAL( nameChanged( QString ) ),
112              this, SLOT( setName( QString ) ) );
113     connect( THEMIM->getIM(), SIGNAL( statusChanged( int ) ),
114              this, SLOT( setStatus( int ) ) );
115     connect( slider, SIGNAL( sliderDragged( float ) ),
116              THEMIM->getIM(),SLOT( sliderUpdate( float ) ) );
117
118     /* Actions */
119     connect( ui.playButton, SIGNAL( clicked() ), this, SLOT( play() ) );
120     connect( ui.stopButton, SIGNAL( clicked() ), this, SLOT( stop() ) );
121     connect( ui.nextButton, SIGNAL( clicked() ), this, SLOT( next() ) );
122     connect( ui.prevButton, SIGNAL( clicked() ), this, SLOT( prev() ) );
123
124     connect( ui.playlistButton, SIGNAL(clicked()),
125              THEDP, SLOT( playlistDialog() ) );
126
127     var_Create( p_intf, "interaction", VLC_VAR_ADDRESS );
128     var_AddCallback( p_intf, "interaction", InteractCallback, this );
129     p_intf->b_interaction = VLC_TRUE;
130 }
131
132 MainInterface::~MainInterface()
133 {
134     writeSettings( "MainWindow" );
135     if( config_GetInt( p_intf, "qt-always-video" ) )
136     {
137         QSettings s("VideoLAN", "VLC" );
138         s.beginGroup( "MainWindow" );
139         s.setValue( "videoSize", videoSize );
140         s.endGroup();
141     }
142     p_intf->b_interaction = VLC_FALSE;
143     var_DelCallback( p_intf, "interaction", InteractCallback, this );
144 }
145
146 void MainInterface::resizeEvent( QResizeEvent *e )
147 {
148     videoSize.setHeight( e->size().height() - addSize.height() );
149     videoSize.setWidth( e->size().width() - addSize.width() );
150     p_intf->p_sys->p_video->updateGeometry() ;
151 }
152
153 void MainInterface::stop()
154 {
155     playlist_Stop( THEPL );
156 }
157 void MainInterface::play()
158 {
159     if( !THEPL->i_size || !THEPL->i_enabled )
160     {
161         /* The playlist is empty, open a file requester */
162         THEDP->openDialog();
163         setStatus( 0 );
164         return;
165     }
166     THEMIM->togglePlayPause();
167 }
168 void MainInterface::prev()
169 {
170     playlist_Prev( THEPL );
171 }
172 void MainInterface::next()
173 {
174     playlist_Next( THEPL );
175 }
176
177 void MainInterface::setDisplay( float pos, int time, int length )
178 {
179     char psz_length[MSTRTIME_MAX_SIZE], psz_time[MSTRTIME_MAX_SIZE];
180     secstotimestr( psz_length, length );
181     secstotimestr( psz_time, time );
182     QString title;
183     title.sprintf( "%s/%s", psz_time, psz_length );
184     timeLabel->setText( title );
185 }
186
187 void MainInterface::setName( QString name )
188 {
189     nameLabel->setText( name );
190 }
191
192 void MainInterface::setStatus( int status )
193 {
194     if( status == 2 ) // Playing
195         ui.playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
196     else
197         ui.playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
198 }
199
200 void MainInterface::updateOnTimer()
201 {
202     if( p_intf->b_die )
203     {
204         QApplication::quit();
205     }
206 }
207
208 void MainInterface::closeEvent( QCloseEvent *e )
209 {
210     hide();
211     p_intf->b_die = VLC_TRUE;
212 }
213
214 static int InteractCallback( vlc_object_t *p_this,
215                              const char *psz_var, vlc_value_t old_val,
216                              vlc_value_t new_val, void *param )
217 {
218     intf_dialog_args_t *p_arg = new intf_dialog_args_t;
219     p_arg->p_dialog = (interaction_dialog_t *)(new_val.p_address);
220     
221     MainInterface *p_interface = (MainInterface*)param;
222     DialogEvent *event = new DialogEvent( INTF_DIALOG_INTERACTION, 0, p_arg );
223     QApplication::postEvent( THEDP, static_cast<QEvent*>(event) );
224     return VLC_SUCCESS;
225 }