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