]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/interface_widgets.cpp
Change backgroundwidget and mediainfo-dialog to use THEMIM
[vlc] / modules / gui / qt4 / components / interface_widgets.cpp
1 /*****************************************************************************
2  * interface_widgets.cpp : Custom widgets for the main interface
3  ****************************************************************************
4  * Copyright ( C ) 2006 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Clément Stenac <zorglub@videolan.org>
8  *          Jean-Baptiste Kempf <jb@videolan.org>
9  *          Rafaël Carré <funman@videolanorg>
10  *          Ilkka Ollakka <ileoo@videolan.org>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * ( at your option ) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25  *****************************************************************************/
26
27 #include "dialogs_provider.hpp"
28 #include "components/interface_widgets.hpp"
29 #include "main_interface.hpp"
30 #include "input_manager.hpp"
31 #include "menus.hpp"
32 #include "util/input_slider.hpp"
33 #include "util/customwidgets.hpp"
34 #include <vlc_vout.h>
35
36 #include <QLabel>
37 #include <QSpacerItem>
38 #include <QCursor>
39 #include <QPushButton>
40 #include <QHBoxLayout>
41 #include <QMenu>
42 #include <QPalette>
43 #include <QResizeEvent>
44
45 /**********************************************************************
46  * Video Widget. A simple frame on which video is drawn
47  * This class handles resize issues
48  **********************************************************************/
49 static void *DoRequest( intf_thread_t *, vout_thread_t *, int*,int*,
50                         unsigned int *, unsigned int * );
51 static void DoRelease( intf_thread_t *, void * );
52 static int DoControl( intf_thread_t *, void *, int, va_list );
53
54 VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
55 {
56     vlc_mutex_init( p_intf, &lock );
57     p_vout = NULL;
58
59     CONNECT( this, askResize(), this, SetMinSize() );
60     CONNECT( this, askVideoToShow(), this, show() );
61     setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
62 }
63
64 VideoWidget::~VideoWidget()
65 {
66     vlc_mutex_lock( &lock );
67     if( p_vout )
68     {
69         if( !p_intf->psz_switch_intf )
70         {
71             if( vout_Control( p_vout, VOUT_CLOSE ) != VLC_SUCCESS )
72                 vout_Control( p_vout, VOUT_REPARENT );
73         }
74         else
75         {
76             if( vout_Control( p_vout, VOUT_REPARENT ) != VLC_SUCCESS )
77                 vout_Control( p_vout, VOUT_CLOSE );
78         }
79     }
80     vlc_mutex_unlock( &lock );
81     vlc_mutex_destroy( &lock );
82 }
83
84 QSize VideoWidget::sizeHint() const
85 {
86     return widgetSize;
87 }
88
89 void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
90                            unsigned int *pi_width, unsigned int *pi_height )
91 {
92     emit askVideoToShow();
93     if( p_vout )
94     {
95         msg_Dbg( p_intf, "embedded video already in use" );
96         return NULL;
97     }
98     p_vout = p_nvout;
99     emit askResize();
100     return ( void* )winId();
101 }
102
103 void VideoWidget::SetMinSize()
104 {
105     setMinimumSize( 16, 16 );
106 }
107
108 void VideoWidget::release( void *p_win )
109 {
110     p_vout = NULL;
111 }
112
113
114 /**********************************************************************
115  * Background Widget. Show a simple image background. Currently,
116  * it's a static cone.
117  **********************************************************************/
118 #define ICON_SIZE 128
119 #define MAX_BG_SIZE 400
120 #define MIN_BG_SIZE 64
121
122 BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i ) :
123                                         QFrame( NULL ), p_intf( _p_i )
124 {
125     /* We should use that one to take the more size it can */
126     setSizePolicy( QSizePolicy::Preferred, QSizePolicy::MinimumExpanding );
127
128     /* A dark background */
129     setAutoFillBackground( true );
130     plt =  palette();
131     plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
132     plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
133     setPalette( plt );
134
135     /* A cone in the middle */
136     label = new QLabel;
137     label->setScaledContents( true );
138     label->setMargin( 5 );
139     label->setMaximumHeight( MAX_BG_SIZE );
140     label->setMaximumWidth( MAX_BG_SIZE );
141     label->setMinimumHeight( MIN_BG_SIZE );
142     label->setMinimumWidth( MIN_BG_SIZE );
143     label->setPixmap( QPixmap( ":/vlc128.png" ) );
144
145     QHBoxLayout *backgroundLayout = new QHBoxLayout( this );
146     backgroundLayout->addWidget( label );
147
148     resize( 300, 150 );
149     updateGeometry();
150     CONNECT( THEMIM, inputChanged( input_thread_t *), this, update( input_thread_t * ) );
151 }
152
153 BackgroundWidget::~BackgroundWidget()
154 {
155 }
156
157
158 void BackgroundWidget::update( input_thread_t *p_input )
159 {
160     if( !p_input || p_input->b_dead )
161     {
162         label->setPixmap( QPixmap( ":/vlc128.png" ) );
163         return;
164     }
165
166
167     vlc_object_yield( p_input );
168     char *psz_arturl = input_item_GetArtURL( input_GetItem(p_input) );
169     vlc_object_release( p_input );
170     QString url = qfu( psz_arturl );
171     QString arturl = url.replace( "file://",QString("" ) );
172     if( arturl.isNull() )
173         label->setPixmap( QPixmap( ":/vlc128.png" ) );
174     else
175     {
176         label->setPixmap( QPixmap( arturl ) );
177         msg_Dbg( p_intf, "changing input b_need_update done %s", psz_arturl );
178     }
179     free( psz_arturl );
180 }
181
182 QSize BackgroundWidget::sizeHint() const
183 {
184     return label->size();
185 }
186
187 void BackgroundWidget::resizeEvent( QResizeEvent *e )
188 {
189     if( e->size().height() < MAX_BG_SIZE -1 )
190     {
191         label->setMaximumWidth( e->size().height() );
192         label->setMaximumHeight( e->size().width() );
193     }
194     else
195     {
196         label->setMaximumHeight( MAX_BG_SIZE );
197         label->setMaximumWidth( MAX_BG_SIZE );
198     }
199 }
200
201 void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
202 {
203     QVLCMenu::PopupMenu( p_intf, true );
204 }
205
206 /**********************************************************************
207  * Visualization selector panel
208  **********************************************************************/
209 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
210                                 QFrame( NULL ), p_intf( _p_i )
211 {
212     QHBoxLayout *layout = new QHBoxLayout( this );
213     layout->setMargin( 0 );
214     QPushButton *prevButton = new QPushButton( "Prev" );
215     QPushButton *nextButton = new QPushButton( "Next" );
216     layout->addWidget( prevButton );
217     layout->addWidget( nextButton );
218
219     layout->addItem( new QSpacerItem( 40,20,
220                               QSizePolicy::Expanding, QSizePolicy::Minimum ) );
221     layout->addWidget( new QLabel( qtr( "Current visualization:" ) ) );
222
223     current = new QLabel( qtr( "None" ) );
224     layout->addWidget( current );
225
226     BUTTONACT( prevButton, prev() );
227     BUTTONACT( nextButton, next() );
228
229     setLayout( layout );
230     setMaximumHeight( 35 );
231 }
232
233 VisualSelector::~VisualSelector()
234 {
235 }
236
237 void VisualSelector::prev()
238 {
239     char *psz_new = aout_VisualPrev( p_intf );
240     if( psz_new )
241     {
242         current->setText( qfu( psz_new ) );
243         free( psz_new );
244     }
245 }
246
247 void VisualSelector::next()
248 {
249     char *psz_new = aout_VisualNext( p_intf );
250     if( psz_new )
251     {
252         current->setText( qfu( psz_new ) );
253         free( psz_new );
254     }
255 }
256
257 /**********************************************************************
258  * TEH controls
259  **********************************************************************/
260
261 #define setupSmallButton( aButton ){  \
262     aButton->setMaximumSize( QSize( 26, 26 ) ); \
263     aButton->setMinimumSize( QSize( 26, 26 ) ); \
264     aButton->setIconSize( QSize( 20, 20 ) ); }
265
266 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
267                                            QFrame( NULL ), p_intf( _p_i )
268 {
269     QHBoxLayout *advLayout = new QHBoxLayout( this );
270     advLayout->setMargin( 0 );
271     advLayout->setSpacing( 0 );
272
273     /* A to B Button */
274     ABButton = new QPushButton( "AB" );
275     ABButton->setMaximumSize( QSize( 26, 26 ) );
276     ABButton->setIconSize( QSize( 20, 20 ) );
277     advLayout->addWidget( ABButton );
278     BUTTON_SET_ACT( ABButton, "AB", qtr( "A to B" ), fromAtoB() );
279     timeA = timeB = 0;
280     CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
281              this, AtoBLoop( float, int, int ) );
282
283     frameButton = new QPushButton( "Fr" );
284     frameButton->setMaximumSize( QSize( 26, 26 ) );
285     frameButton->setIconSize( QSize( 20, 20 ) );
286     advLayout->addWidget( frameButton );
287     BUTTON_SET_ACT( frameButton, "Fr", qtr( "Frame by Frame" ), frame() );
288
289     recordButton = new QPushButton( "R" );
290     recordButton->setMaximumSize( QSize( 26, 26 ) );
291     recordButton->setIconSize( QSize( 20, 20 ) );
292     advLayout->addWidget( recordButton );
293     BUTTON_SET_ACT_I( recordButton, "", record_16px.png,
294             qtr( "Record" ), record() );
295
296     /* Snapshot Button */
297     snapshotButton = new QPushButton( "S" );
298     snapshotButton->setMaximumSize( QSize( 26, 26 ) );
299     snapshotButton->setIconSize( QSize( 20, 20 ) );
300     advLayout->addWidget( snapshotButton );
301     BUTTON_SET_ACT( snapshotButton, "S", qtr( "Take a snapshot" ), snapshot() );
302 }
303
304 AdvControlsWidget::~AdvControlsWidget()
305 {}
306
307 void AdvControlsWidget::enableInput( bool enable )
308 {
309     ABButton->setEnabled( enable );
310     recordButton->setEnabled( enable );
311 }
312
313 void AdvControlsWidget::enableVideo( bool enable )
314 {
315     snapshotButton->setEnabled( enable );
316     frameButton->setEnabled( enable );
317 }
318
319 void AdvControlsWidget::snapshot()
320 {
321     vout_thread_t *p_vout =
322         (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
323     if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
324 }
325
326 /* Function called when the button is clicked() */
327 void AdvControlsWidget::fromAtoB()
328 {
329     if( !timeA )
330     {
331         timeA = var_GetTime( THEMIM->getInput(), "time"  );
332         ABButton->setText( "A->..." );
333         return;
334     }
335     if( !timeB )
336     {
337         timeB = var_GetTime( THEMIM->getInput(), "time"  );
338         var_SetTime( THEMIM->getInput(), "time" , timeA );
339         ABButton->setText( "A<=>B" );
340         return;
341     }
342     timeA = 0;
343     timeB = 0;
344     ABButton->setText( "AB" );
345 }
346
347 /* Function called regularly when in an AtoB loop */
348 void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
349 {
350     if( timeB )
351     {
352         if( i_time >= (int)(timeB/1000000) )
353             var_SetTime( THEMIM->getInput(), "time" , timeA );
354     }
355 }
356
357 /* FIXME Record function */
358 void AdvControlsWidget::record(){}
359
360 //FIXME Frame by frame function
361 void AdvControlsWidget::frame(){}
362
363 /*****************************
364  * DA Control Widget !
365  *****************************/
366 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
367                                 MainInterface *_p_mi,
368                                 bool b_advControls,
369                                 bool b_shiny ) :
370                                 QFrame( NULL ), p_intf( _p_i )
371 {
372     controlLayout = new QGridLayout( this );
373     controlLayout->setSpacing( 0 );
374     setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Minimum );
375
376     /** The main Slider **/
377     slider = new InputSlider( Qt::Horizontal, NULL );
378     controlLayout->addWidget( slider, 0, 1, 1, 16 );
379     /* Update the position when the IM has changed */
380     CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
381              slider, setPosition( float, int, int ) );
382     /* And update the IM, when the position has changed */
383     CONNECT( slider, sliderDragged( float ),
384              THEMIM->getIM(), sliderUpdate( float ) );
385
386     /** Slower and faster Buttons **/
387     slowerButton = new QPushButton;
388     slowerButton->setFlat( true );
389     slowerButton->setMaximumSize( QSize( 26, 20 ) );
390
391     BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
392     controlLayout->addWidget( slowerButton, 0, 0 );
393
394     fasterButton = new QPushButton;
395     fasterButton->setFlat( true );
396     fasterButton->setMaximumSize( QSize( 26, 20 ) );
397
398     BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
399     controlLayout->addWidget( fasterButton, 0, 17 );
400
401     /* advanced Controls handling */
402     b_advancedVisible = b_advControls;
403
404     advControls = new AdvControlsWidget( p_intf );
405     controlLayout->addWidget( advControls, 1, 3, 2, 4, Qt::AlignBottom );
406     if( !b_advancedVisible ) advControls->hide();
407
408     /** Disc and Menus handling */
409     discFrame = new QFrame( this );
410
411     QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
412     discLayout->setSpacing( 0 );
413     discLayout->setMargin( 0 );
414
415     prevSectionButton = new QPushButton( discFrame );
416     setupSmallButton( prevSectionButton );
417     discLayout->addWidget( prevSectionButton );
418
419     menuButton = new QPushButton( discFrame );
420     setupSmallButton( menuButton );
421     discLayout->addWidget( menuButton );
422
423     nextSectionButton = new QPushButton( discFrame );
424     setupSmallButton( nextSectionButton );
425     discLayout->addWidget( nextSectionButton );
426
427     controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
428
429     BUTTON_SET_IMG( prevSectionButton, "", previous.png, "" );
430     BUTTON_SET_IMG( nextSectionButton, "", next.png, "" );
431     BUTTON_SET_IMG( menuButton, "", previous.png, "" );
432
433     discFrame->hide();
434
435     /* Change the navigation button display when the IM navigation changes */
436     CONNECT( THEMIM->getIM(), navigationChanged( int ),
437              this, setNavigation( int ) );
438     /* Changes the IM navigation when triggered on the nav buttons */
439     CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
440              sectionPrev() );
441     CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
442              sectionNext() );
443     CONNECT( menuButton, clicked(), THEMIM->getIM(),
444              sectionMenu() );
445
446     /** TODO
447      * Telextext QFrame
448      * Merge with upper menu in a StackLayout
449      **/
450
451     /** Play Buttons **/
452     QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
453     sizePolicy.setHorizontalStretch( 0 );
454     sizePolicy.setVerticalStretch( 0 );
455
456     /* Play */
457     playButton = new QPushButton;
458     playButton->setSizePolicy( sizePolicy );
459     playButton->setMaximumSize( QSize( 38, 38 ) );
460     playButton->setMinimumSize( QSize( 45, 45 ) );
461     playButton->setIconSize( QSize( 30, 30 ) );
462
463     controlLayout->addWidget( playButton, 2, 0, 2, 2 );
464
465     controlLayout->setColumnMinimumWidth( 2, 20 );
466     controlLayout->setColumnStretch( 2, 0 );
467
468     /** Prev + Stop + Next Block **/
469     QHBoxLayout *controlButLayout = new QHBoxLayout;
470     controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
471
472     /* Prev */
473     QPushButton *prevButton = new QPushButton;
474     prevButton->setSizePolicy( sizePolicy );
475     setupSmallButton( prevButton );
476
477     controlButLayout->addWidget( prevButton );
478
479     /* Stop */
480     QPushButton *stopButton = new QPushButton;
481     stopButton->setSizePolicy( sizePolicy );
482     setupSmallButton( stopButton );
483
484     controlButLayout->addWidget( stopButton );
485
486     /* next */
487     QPushButton *nextButton = new QPushButton;
488     nextButton->setSizePolicy( sizePolicy );
489     setupSmallButton( nextButton );
490
491     controlButLayout->addWidget( nextButton );
492
493     /* Add this block to the main layout */
494     controlLayout->addLayout( controlButLayout, 3, 3, 1, 3, Qt::AlignBottom );
495
496     BUTTON_SET_ACT_I( playButton, "", play.png, qtr( "Play" ), play() );
497     BUTTON_SET_ACT_I( prevButton, "" , previous.png,
498                       qtr( "Previous" ), prev() );
499     BUTTON_SET_ACT_I( nextButton, "", next.png, qtr( "Next" ), next() );
500     BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr( "Stop" ), stop() );
501
502     controlLayout->setColumnStretch( 7 , 2 );
503
504     /*
505      * Other first Line buttons
506      */
507     /** Fullscreen/Visualisation **/
508     fullscreenButton = new QPushButton( "F" );
509     BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
510     setupSmallButton( fullscreenButton );
511     controlLayout->addWidget( fullscreenButton, 3, 10, Qt::AlignBottom );
512
513     /** Playlist Button **/
514     playlistButton = new QPushButton;
515     setupSmallButton( playlistButton );
516     controlLayout->addWidget( playlistButton, 3, 11, Qt::AlignBottom );
517     BUTTON_SET_IMG( playlistButton, "" , playlist.png, qtr( "Show playlist" ) );
518     CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
519
520     /** extended Settings **/
521     QPushButton *extSettingsButton = new QPushButton( "F" );
522     BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
523             extSettings() );
524     setupSmallButton( extSettingsButton );
525     controlLayout->addWidget( extSettingsButton, 3, 12, Qt::AlignBottom );
526
527     controlLayout->setColumnStretch( 14, 5 );
528
529     /* Volume */
530     VolumeClickHandler *hVolLabel = new VolumeClickHandler( p_intf, this );
531
532     volMuteLabel = new QLabel;
533     volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
534     volMuteLabel->setToolTip( qtr( "Mute" ) );
535     volMuteLabel->installEventFilter( hVolLabel );
536     controlLayout->addWidget( volMuteLabel, 3, 15, Qt::AlignBottom );
537
538     if( b_shiny )
539     {
540         volumeSlider = new SoundSlider( this,
541             config_GetInt( p_intf, "volume-step" ),
542             config_GetInt( p_intf, "qt-volume-complete" ) );
543     }
544     else
545     {
546         volumeSlider = new QSlider( this );
547         volumeSlider->setOrientation( Qt::Horizontal );
548     }
549     volumeSlider->setMaximumSize( QSize( 200, 40 ) );
550     volumeSlider->setMinimumSize( QSize( 106, 30 ) );
551     volumeSlider->setFocusPolicy( Qt::NoFocus );
552     controlLayout->addWidget( volumeSlider, 2, 16, 2 , 2, Qt::AlignBottom );
553
554     /* Set the volume from the config */
555     volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
556                               VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
557
558     /* Volume control connection */
559     resize( QSize( 400, 60 ) );
560     CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
561     msg_Dbg( p_intf, "controls size: %i - %i", size().width(), size().height() );
562 }
563
564 ControlsWidget::~ControlsWidget()
565 {
566 }
567
568 /*
569 QSize ControlsWidget::sizeHint() const
570 {
571     return QSize( 300, 50 );
572 }
573 */
574
575 void ControlsWidget::stop()
576 {
577     THEMIM->stop();
578 }
579
580 void ControlsWidget::play()
581 {
582     if( THEPL->current.i_size == 0 )
583     {
584         /* The playlist is empty, open a file requester */
585         THEDP->openFileDialog();
586         setStatus( 0 );
587         return;
588     }
589     THEMIM->togglePlayPause();
590 }
591
592 void ControlsWidget::prev()
593 {
594     THEMIM->prev();
595 }
596
597 void ControlsWidget::next()
598 {
599     THEMIM->next();
600 }
601
602 void ControlsWidget::setNavigation( int navigation )
603 {
604 #define HELP_MENU N_( "Menu" )
605 #define HELP_PCH N_( "Previous chapter" )
606 #define HELP_NCH N_( "Next chapter" )
607 #define HELP_PTR N_( "Previous track" )
608 #define HELP_NTR N_( "Next track" )
609
610     // 1 = chapter, 2 = title, 0 = no
611     if( navigation == 0 )
612     {
613         discFrame->hide();
614     } else if( navigation == 1 ) {
615         prevSectionButton->setToolTip( qfu( HELP_PCH ) );
616         nextSectionButton->setToolTip( qfu( HELP_NCH ) );
617         menuButton->show();
618         discFrame->show();
619     } else {
620         prevSectionButton->setToolTip( qfu( HELP_PCH ) );
621         nextSectionButton->setToolTip( qfu( HELP_NCH ) );
622         menuButton->hide();
623         discFrame->show();
624     }
625 }
626
627 static bool b_my_volume;
628 void ControlsWidget::updateVolume( int i_sliderVolume )
629 {
630     if( !b_my_volume )
631     {
632         int i_res = i_sliderVolume  * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
633         aout_VolumeSet( p_intf, i_res );
634     }
635     if( i_sliderVolume == 0 )
636         volMuteLabel->setPixmap( QPixmap(":/pixmaps/volume-muted.png" ) );
637     else if( i_sliderVolume < VOLUME_MAX / 2 )
638         volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
639     else volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
640 }
641
642 void ControlsWidget::updateOnTimer()
643 {
644     /* Audio part */
645     audio_volume_t i_volume;
646     aout_VolumeGet( p_intf, &i_volume );
647     i_volume = ( i_volume *  VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
648     int i_gauge = volumeSlider->value();
649     b_my_volume = false;
650     if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
651     {
652         b_my_volume = true;
653         volumeSlider->setValue( i_volume );
654         b_my_volume = false;
655     }
656
657     /* Activate the interface buttons according to the presence of the input */
658     enableInput( THEMIM->getIM()->hasInput() );
659     //enableVideo( THEMIM->getIM()->hasVideo() );
660     enableVideo( true );
661 }
662
663 void ControlsWidget::setStatus( int status )
664 {
665     if( status == PLAYING_S ) // Playing
666         playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
667     else
668         playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
669 }
670
671 /**
672  * TODO
673  * This functions toggle the fullscreen mode
674  * If there is no video, it should first activate Visualisations...
675  *  This has also to be fixed in enableVideo()
676  */
677 void ControlsWidget::fullscreen()
678 {
679     vout_thread_t *p_vout =
680         (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
681     if( p_vout)
682     {
683         var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
684         vlc_object_release( p_vout );
685     }
686 }
687
688 void ControlsWidget::extSettings()
689 {
690     THEDP->extendedDialog();
691 }
692
693 void ControlsWidget::slower()
694 {
695     THEMIM->getIM()->slower();
696 }
697
698 void ControlsWidget::faster()
699 {
700     THEMIM->getIM()->faster();
701 }
702
703 void ControlsWidget::enableInput( bool enable )
704 {
705     slowerButton->setEnabled( enable );
706     slider->setEnabled( enable );
707     fasterButton->setEnabled( enable );
708
709     /* Advanced Buttons too */
710     advControls->enableInput( enable );
711 }
712
713 void ControlsWidget::enableVideo( bool enable )
714 {
715     // TODO Later make the fullscreenButton toggle Visualisation and so on.
716     fullscreenButton->setEnabled( enable );
717
718     /* Advanced Buttons too */
719     advControls->enableVideo( enable );
720 }
721
722 void ControlsWidget::toggleAdvanced()
723 {
724     if( !VISIBLE( advControls ) )
725     {
726         advControls->show();
727         b_advancedVisible = true;
728     }
729     else
730     {
731         advControls->hide();
732         b_advancedVisible = false;
733     }
734     emit advancedControlsToggled( b_advancedVisible );
735 }
736
737
738 /**********************************************************************
739  * Speed control widget
740  **********************************************************************/
741 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
742                              QFrame( NULL ), p_intf( _p_i )
743 {
744     QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
745     sizePolicy.setHorizontalStretch( 0 );
746     sizePolicy.setVerticalStretch( 0 );
747
748     speedSlider = new QSlider;
749     speedSlider->setSizePolicy( sizePolicy );
750     speedSlider->setMaximumSize( QSize( 80, 200 ) );
751     speedSlider->setOrientation( Qt::Vertical );
752     speedSlider->setTickPosition( QSlider::TicksRight );
753
754     speedSlider->setRange( -100, 100 );
755     speedSlider->setSingleStep( 10 );
756     speedSlider->setPageStep( 20 );
757     speedSlider->setTickInterval( 20 );
758
759     CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
760
761     normalSpeedButton = new QPushButton( "N" );
762     normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
763     normalSpeedButton->setFlat( true );
764     normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
765
766     CONNECT( normalSpeedButton, clicked(), this, resetRate() );
767
768     QVBoxLayout *speedControlLayout = new QVBoxLayout;
769     speedControlLayout->addWidget(speedSlider);
770     speedControlLayout->addWidget(normalSpeedButton);
771     setLayout(speedControlLayout);
772 }
773
774 SpeedControlWidget::~SpeedControlWidget()
775 {}
776
777 #define RATE_SLIDER_MAXIMUM 3.0
778 #define RATE_SLIDER_MINIMUM 0.3
779 #define RATE_SLIDER_LENGTH 100.0
780
781 void SpeedControlWidget::updateControls( int rate )
782 {
783     if( speedSlider->isSliderDown() )
784     {
785         //We don't want to change anything if the user is using the slider
786         return;
787     }
788
789     int sliderValue;
790     double speed = INPUT_RATE_DEFAULT / (double)rate;
791
792     if( rate >= INPUT_RATE_DEFAULT )
793     {
794         if( speed < RATE_SLIDER_MINIMUM )
795         {
796             sliderValue = speedSlider->minimum();
797         }
798         else
799         {
800             sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
801                                         / ( 1.0 - RATE_SLIDER_MAXIMUM ) );
802         }
803     }
804     else
805     {
806         if( speed > RATE_SLIDER_MAXIMUM )
807         {
808             sliderValue = speedSlider->maximum();
809         }
810         else
811         {
812             sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
813                                         / ( RATE_SLIDER_MAXIMUM - 1.0 ) );
814         }
815     }
816
817     //Block signals to avoid feedback loop
818     speedSlider->blockSignals( true );
819     speedSlider->setValue( sliderValue );
820     speedSlider->blockSignals( false );
821 }
822
823 void SpeedControlWidget::updateRate( int sliderValue )
824 {
825     int rate;
826
827     if( sliderValue < 0.0 )
828     {
829         rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
830             ( sliderValue * ( 1.0 - RATE_SLIDER_MINIMUM ) + RATE_SLIDER_LENGTH );
831     }
832     else
833     {
834         rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
835             ( sliderValue * ( RATE_SLIDER_MAXIMUM - 1.0 ) + RATE_SLIDER_LENGTH );
836     }
837
838     THEMIM->getIM()->setRate(rate);
839 }
840
841 void SpeedControlWidget::resetRate()
842 {
843     THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);
844 }