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