]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/interface_widgets.cpp
correctly displays album art in playlist, fix by ILEoo
[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 }
585
586 ControlsWidget::~ControlsWidget()
587 {}
588
589 void ControlsWidget::stop()
590 {
591     THEMIM->stop();
592 }
593
594 void ControlsWidget::play()
595 {
596     if( THEPL->current.i_size == 0 )
597     {
598         /* The playlist is empty, open a file requester */
599         THEDP->openFileDialog();
600         setStatus( 0 );
601         return;
602     }
603     THEMIM->togglePlayPause();
604 }
605
606 void ControlsWidget::prev()
607 {
608     THEMIM->prev();
609 }
610
611 void ControlsWidget::next()
612 {
613     THEMIM->next();
614 }
615
616 void ControlsWidget::setNavigation( int navigation )
617 {
618 #define HELP_MENU N_( "Menu" )
619 #define HELP_PCH N_( "Previous chapter" )
620 #define HELP_NCH N_( "Next chapter" )
621 #define HELP_PTR N_( "Previous track" )
622 #define HELP_NTR N_( "Next track" )
623
624     // 1 = chapter, 2 = title, 0 = no
625     if( navigation == 0 )
626     {
627         discFrame->hide();
628     } else if( navigation == 1 ) {
629         prevSectionButton->setToolTip( qfu( HELP_PCH ) );
630         nextSectionButton->setToolTip( qfu( HELP_NCH ) );
631         menuButton->show();
632         discFrame->show();
633     } else {
634         prevSectionButton->setToolTip( qfu( HELP_PCH ) );
635         nextSectionButton->setToolTip( qfu( HELP_NCH ) );
636         menuButton->hide();
637         discFrame->show();
638     }
639 }
640
641 static bool b_my_volume;
642 void ControlsWidget::updateVolume( int i_sliderVolume )
643 {
644     if( !b_my_volume )
645     {
646         int i_res = i_sliderVolume  * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
647         aout_VolumeSet( p_intf, i_res );
648     }
649     if( i_sliderVolume == 0 )
650         volMuteLabel->setPixmap( QPixmap(":/pixmaps/volume-muted.png" ) );
651     else if( i_sliderVolume < VOLUME_MAX / 3 )
652         volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
653     else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
654         volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
655     else volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-medium.png" ) );
656 }
657
658 void ControlsWidget::updateOnTimer()
659 {
660     /* Audio part */
661     audio_volume_t i_volume;
662     aout_VolumeGet( p_intf, &i_volume );
663     i_volume = ( i_volume *  VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
664     int i_gauge = volumeSlider->value();
665     b_my_volume = false;
666     if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
667     {
668         b_my_volume = true;
669         volumeSlider->setValue( i_volume );
670         b_my_volume = false;
671     }
672
673     /* Activate the interface buttons according to the presence of the input */
674     enableInput( THEMIM->getIM()->hasInput() );
675     //enableVideo( THEMIM->getIM()->hasVideo() );
676     enableVideo( true );
677 }
678
679 void ControlsWidget::setStatus( int status )
680 {
681     if( status == PLAYING_S ) // Playing
682         playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
683     else
684         playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
685 }
686
687 /**
688  * TODO
689  * This functions toggle the fullscreen mode
690  * If there is no video, it should first activate Visualisations...
691  *  This has also to be fixed in enableVideo()
692  */
693 void ControlsWidget::fullscreen()
694 {
695     vout_thread_t *p_vout =
696         (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
697     if( p_vout)
698     {
699         var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
700         vlc_object_release( p_vout );
701     }
702 }
703
704 void ControlsWidget::extSettings()
705 {
706     THEDP->extendedDialog();
707 }
708
709 void ControlsWidget::slower()
710 {
711     THEMIM->getIM()->slower();
712 }
713
714 void ControlsWidget::faster()
715 {
716     THEMIM->getIM()->faster();
717 }
718
719 void ControlsWidget::enableInput( bool enable )
720 {
721     slowerButton->setEnabled( enable );
722     slider->setEnabled( enable );
723     fasterButton->setEnabled( enable );
724
725     /* Advanced Buttons too */
726     advControls->enableInput( enable );
727 }
728
729 void ControlsWidget::enableVideo( bool enable )
730 {
731     // TODO Later make the fullscreenButton toggle Visualisation and so on.
732     fullscreenButton->setEnabled( enable );
733
734     /* Advanced Buttons too */
735     advControls->enableVideo( enable );
736 }
737
738 void ControlsWidget::toggleAdvanced()
739 {
740     if( !VISIBLE( advControls ) )
741     {
742         advControls->show();
743         b_advancedVisible = true;
744     }
745     else
746     {
747         advControls->hide();
748         b_advancedVisible = false;
749     }
750     emit advancedControlsToggled( b_advancedVisible );
751 }
752
753
754 /**********************************************************************
755  * Speed control widget
756  **********************************************************************/
757 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
758                              QFrame( NULL ), p_intf( _p_i )
759 {
760     QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
761     sizePolicy.setHorizontalStretch( 0 );
762     sizePolicy.setVerticalStretch( 0 );
763
764     speedSlider = new QSlider;
765     speedSlider->setSizePolicy( sizePolicy );
766     speedSlider->setMaximumSize( QSize( 80, 200 ) );
767     speedSlider->setOrientation( Qt::Vertical );
768     speedSlider->setTickPosition( QSlider::TicksRight );
769
770     speedSlider->setRange( -100, 100 );
771     speedSlider->setSingleStep( 10 );
772     speedSlider->setPageStep( 20 );
773     speedSlider->setTickInterval( 20 );
774
775     CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
776
777     QToolButton *normalSpeedButton = new QToolButton( this );
778     normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
779     normalSpeedButton->setAutoRaise( true );
780     normalSpeedButton->setText( "N" );
781     normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
782
783     CONNECT( normalSpeedButton, clicked(), this, resetRate() );
784
785     QVBoxLayout *speedControlLayout = new QVBoxLayout;
786     speedControlLayout->addWidget( speedSlider );
787     speedControlLayout->addWidget( normalSpeedButton );
788     setLayout( speedControlLayout );
789 }
790
791 SpeedControlWidget::~SpeedControlWidget()
792 {}
793
794 #define RATE_SLIDER_MAXIMUM 3.0
795 #define RATE_SLIDER_MINIMUM 0.3
796 #define RATE_SLIDER_LENGTH 100.0
797
798 void SpeedControlWidget::updateControls( int rate )
799 {
800     if( speedSlider->isSliderDown() )
801     {
802         //We don't want to change anything if the user is using the slider
803         return;
804     }
805
806     int sliderValue;
807     double speed = INPUT_RATE_DEFAULT / (double)rate;
808
809     if( rate >= INPUT_RATE_DEFAULT )
810     {
811         if( speed < RATE_SLIDER_MINIMUM )
812         {
813             sliderValue = speedSlider->minimum();
814         }
815         else
816         {
817             sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
818                                         / ( 1.0 - RATE_SLIDER_MAXIMUM ) );
819         }
820     }
821     else
822     {
823         if( speed > RATE_SLIDER_MAXIMUM )
824         {
825             sliderValue = speedSlider->maximum();
826         }
827         else
828         {
829             sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
830                                         / ( RATE_SLIDER_MAXIMUM - 1.0 ) );
831         }
832     }
833
834     //Block signals to avoid feedback loop
835     speedSlider->blockSignals( true );
836     speedSlider->setValue( sliderValue );
837     speedSlider->blockSignals( false );
838 }
839
840 void SpeedControlWidget::updateRate( int sliderValue )
841 {
842     int rate;
843
844     if( sliderValue < 0.0 )
845     {
846         rate = (int)(INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
847             ( sliderValue * ( 1.0 - RATE_SLIDER_MINIMUM ) + RATE_SLIDER_LENGTH ));
848     }
849     else
850     {
851         rate = (int)(INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
852             ( sliderValue * ( RATE_SLIDER_MAXIMUM - 1.0 ) + RATE_SLIDER_LENGTH ));
853     }
854
855     THEMIM->getIM()->setRate(rate);
856 }
857
858 void SpeedControlWidget::resetRate()
859 {
860     THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);
861 }