]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/interface_widgets.cpp
keep to the style of the file.
[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->setValue( 100 );
481     telexPage->setAlignment( Qt::AlignRight );
482     telexLayout->addWidget( telexPage );
483
484     controlLayout->addWidget( telexFrame, 1, 10, 2, 3, Qt::AlignBottom );
485 //    telexFrame->hide();
486
487     CONNECT( telexPage, valueChanged( int ), THEMIM->getIM(),
488              telexGotoPage( int ) );
489     CONNECT( telexOn, clicked( bool ), THEMIM->getIM(),
490              telexToggle( bool ) );
491     CONNECT( telexTransparent, clicked( bool ),
492              THEMIM->getIM(), telexSetTransparency( bool ) );
493     CONNECT( THEMIM->getIM(), teletextEnabled( bool ),
494              telexFrame, setVisible( bool ) );
495
496     /** Play Buttons **/
497     QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
498     sizePolicy.setHorizontalStretch( 0 );
499     sizePolicy.setVerticalStretch( 0 );
500
501     /* Play */
502     playButton = new QPushButton;
503     playButton->setSizePolicy( sizePolicy );
504     playButton->setMaximumSize( QSize( 36, 36 ) );
505     playButton->setMinimumSize( QSize( 36, 36 ) );
506     playButton->setIconSize( QSize( 30, 30 ) );
507
508     controlLayout->addWidget( playButton, 2, 0, 2, 2 );
509
510     controlLayout->setColumnMinimumWidth( 2, 20 );
511     controlLayout->setColumnStretch( 2, 0 );
512
513     /** Prev + Stop + Next Block **/
514     QHBoxLayout *controlButLayout = new QHBoxLayout;
515     controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
516
517     /* Prev */
518     QPushButton *prevButton = new QPushButton;
519     prevButton->setSizePolicy( sizePolicy );
520     setupSmallButton( prevButton );
521
522     controlButLayout->addWidget( prevButton );
523
524     /* Stop */
525     QPushButton *stopButton = new QPushButton;
526     stopButton->setSizePolicy( sizePolicy );
527     setupSmallButton( stopButton );
528
529     controlButLayout->addWidget( stopButton );
530
531     /* next */
532     QPushButton *nextButton = new QPushButton;
533     nextButton->setSizePolicy( sizePolicy );
534     setupSmallButton( nextButton );
535
536     controlButLayout->addWidget( nextButton );
537
538     /* Add this block to the main layout */
539     controlLayout->addLayout( controlButLayout, 3, 3, 1, 3, Qt::AlignBottom );
540
541     BUTTON_SET_ACT_I( playButton, "", play.png, qtr( "Play" ), play() );
542     BUTTON_SET_ACT_I( prevButton, "" , previous.png,
543                       qtr( "Previous" ), prev() );
544     BUTTON_SET_ACT_I( nextButton, "", next.png, qtr( "Next" ), next() );
545     BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr( "Stop" ), stop() );
546
547     controlLayout->setColumnMinimumWidth( 7, 20 );
548     controlLayout->setColumnStretch( 7, 0 );
549     controlLayout->setColumnStretch( 8, 0 );
550     controlLayout->setColumnStretch( 9, 0 );
551
552     /*
553      * Other first Line buttons
554      */
555     /** Fullscreen/Visualisation **/
556     fullscreenButton = new QPushButton( "F" );
557     BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
558     setupSmallButton( fullscreenButton );
559     controlLayout->addWidget( fullscreenButton, 3, 10, Qt::AlignBottom );
560
561     /** Playlist Button **/
562     playlistButton = new QPushButton;
563     setupSmallButton( playlistButton );
564     controlLayout->addWidget( playlistButton, 3, 11, Qt::AlignBottom );
565     BUTTON_SET_IMG( playlistButton, "" , playlist.png, qtr( "Show playlist" ) );
566     CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
567
568     /** extended Settings **/
569     QPushButton *extSettingsButton = new QPushButton( "F" );
570     BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
571             extSettings() );
572     setupSmallButton( extSettingsButton );
573     controlLayout->addWidget( extSettingsButton, 3, 12, Qt::AlignBottom );
574
575     controlLayout->setColumnStretch( 13, 0 );
576     controlLayout->setColumnMinimumWidth( 13, 24 );
577     controlLayout->setColumnStretch( 14, 5 );
578
579     /* Volume */
580     VolumeClickHandler *hVolLabel = new VolumeClickHandler( p_intf, this );
581
582     volMuteLabel = new QLabel;
583     volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
584     volMuteLabel->setToolTip( qtr( "Mute" ) );
585     volMuteLabel->installEventFilter( hVolLabel );
586     controlLayout->addWidget( volMuteLabel, 3, 15, Qt::AlignBottom );
587
588     if( b_shiny )
589     {
590         volumeSlider = new SoundSlider( this,
591             config_GetInt( p_intf, "volume-step" ),
592             config_GetInt( p_intf, "qt-volume-complete" ) );
593     }
594     else
595     {
596         volumeSlider = new QSlider( this );
597         volumeSlider->setOrientation( Qt::Horizontal );
598     }
599     volumeSlider->setMaximumSize( QSize( 200, 40 ) );
600     volumeSlider->setMinimumSize( QSize( 106, 30 ) );
601     volumeSlider->setFocusPolicy( Qt::NoFocus );
602     controlLayout->addWidget( volumeSlider, 2, 16, 2 , 2, Qt::AlignBottom );
603
604     /* Set the volume from the config */
605     volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
606                               VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
607
608     /* Volume control connection */
609     //resize( QSize( 300, 60 ) );
610     CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
611     msg_Dbg( p_intf, "controls size: %i - %i", size().width(), size().height() );
612 }
613
614 ControlsWidget::~ControlsWidget()
615 {}
616
617 /*
618 QSize ControlsWidget::sizeHint() const
619 {
620     return QSize( 300, 50 );
621 }
622 */
623
624 void ControlsWidget::stop()
625 {
626     THEMIM->stop();
627 }
628
629 void ControlsWidget::play()
630 {
631     if( THEPL->current.i_size == 0 )
632     {
633         /* The playlist is empty, open a file requester */
634         THEDP->openFileDialog();
635         setStatus( 0 );
636         return;
637     }
638     THEMIM->togglePlayPause();
639 }
640
641 void ControlsWidget::prev()
642 {
643     THEMIM->prev();
644 }
645
646 void ControlsWidget::next()
647 {
648     THEMIM->next();
649 }
650
651 void ControlsWidget::setNavigation( int navigation )
652 {
653 #define HELP_MENU N_( "Menu" )
654 #define HELP_PCH N_( "Previous chapter" )
655 #define HELP_NCH N_( "Next chapter" )
656 #define HELP_PTR N_( "Previous track" )
657 #define HELP_NTR N_( "Next track" )
658
659     // 1 = chapter, 2 = title, 0 = no
660     if( navigation == 0 )
661     {
662         discFrame->hide();
663     } else if( navigation == 1 ) {
664         prevSectionButton->setToolTip( qfu( HELP_PCH ) );
665         nextSectionButton->setToolTip( qfu( HELP_NCH ) );
666         menuButton->show();
667         discFrame->show();
668     } else {
669         prevSectionButton->setToolTip( qfu( HELP_PCH ) );
670         nextSectionButton->setToolTip( qfu( HELP_NCH ) );
671         menuButton->hide();
672         discFrame->show();
673     }
674 }
675
676 static bool b_my_volume;
677 void ControlsWidget::updateVolume( int i_sliderVolume )
678 {
679     if( !b_my_volume )
680     {
681         int i_res = i_sliderVolume  * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
682         aout_VolumeSet( p_intf, i_res );
683     }
684     if( i_sliderVolume == 0 )
685         volMuteLabel->setPixmap( QPixmap(":/pixmaps/volume-muted.png" ) );
686     else if( i_sliderVolume < VOLUME_MAX / 2 )
687         volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
688     else volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
689 }
690
691 void ControlsWidget::updateOnTimer()
692 {
693     /* Audio part */
694     audio_volume_t i_volume;
695     aout_VolumeGet( p_intf, &i_volume );
696     i_volume = ( i_volume *  VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
697     int i_gauge = volumeSlider->value();
698     b_my_volume = false;
699     if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
700     {
701         b_my_volume = true;
702         volumeSlider->setValue( i_volume );
703         b_my_volume = false;
704     }
705
706     /* Activate the interface buttons according to the presence of the input */
707     enableInput( THEMIM->getIM()->hasInput() );
708     //enableVideo( THEMIM->getIM()->hasVideo() );
709     enableVideo( true );
710 }
711
712 void ControlsWidget::setStatus( int status )
713 {
714     if( status == PLAYING_S ) // Playing
715         playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
716     else
717         playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
718 }
719
720 /**
721  * TODO
722  * This functions toggle the fullscreen mode
723  * If there is no video, it should first activate Visualisations...
724  *  This has also to be fixed in enableVideo()
725  */
726 void ControlsWidget::fullscreen()
727 {
728     vout_thread_t *p_vout =
729         (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
730     if( p_vout)
731     {
732         var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
733         vlc_object_release( p_vout );
734     }
735 }
736
737 void ControlsWidget::extSettings()
738 {
739     THEDP->extendedDialog();
740 }
741
742 void ControlsWidget::slower()
743 {
744     THEMIM->getIM()->slower();
745 }
746
747 void ControlsWidget::faster()
748 {
749     THEMIM->getIM()->faster();
750 }
751
752 void ControlsWidget::enableInput( bool enable )
753 {
754     slowerButton->setEnabled( enable );
755     slider->setEnabled( enable );
756     fasterButton->setEnabled( enable );
757
758     /* Advanced Buttons too */
759     advControls->enableInput( enable );
760 }
761
762 void ControlsWidget::enableVideo( bool enable )
763 {
764     // TODO Later make the fullscreenButton toggle Visualisation and so on.
765     fullscreenButton->setEnabled( enable );
766
767     /* Advanced Buttons too */
768     advControls->enableVideo( enable );
769 }
770
771 void ControlsWidget::toggleAdvanced()
772 {
773     if( !VISIBLE( advControls ) )
774     {
775         advControls->show();
776         b_advancedVisible = true;
777     }
778     else
779     {
780         advControls->hide();
781         b_advancedVisible = false;
782     }
783     emit advancedControlsToggled( b_advancedVisible );
784 }
785
786
787 /**********************************************************************
788  * Speed control widget
789  **********************************************************************/
790 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
791                              QFrame( NULL ), p_intf( _p_i )
792 {
793     QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
794     sizePolicy.setHorizontalStretch( 0 );
795     sizePolicy.setVerticalStretch( 0 );
796
797     speedSlider = new QSlider;
798     speedSlider->setSizePolicy( sizePolicy );
799     speedSlider->setMaximumSize( QSize( 80, 200 ) );
800     speedSlider->setOrientation( Qt::Vertical );
801     speedSlider->setTickPosition( QSlider::TicksRight );
802
803     speedSlider->setRange( -100, 100 );
804     speedSlider->setSingleStep( 10 );
805     speedSlider->setPageStep( 20 );
806     speedSlider->setTickInterval( 20 );
807
808     CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
809
810     normalSpeedButton = new QPushButton( "N" );
811     normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
812     normalSpeedButton->setFlat( true );
813     normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
814
815     CONNECT( normalSpeedButton, clicked(), this, resetRate() );
816
817     QVBoxLayout *speedControlLayout = new QVBoxLayout;
818     speedControlLayout->addWidget(speedSlider);
819     speedControlLayout->addWidget(normalSpeedButton);
820     setLayout(speedControlLayout);
821 }
822
823 SpeedControlWidget::~SpeedControlWidget()
824 {}
825
826 #define RATE_SLIDER_MAXIMUM 3.0
827 #define RATE_SLIDER_MINIMUM 0.3
828 #define RATE_SLIDER_LENGTH 100.0
829
830 void SpeedControlWidget::updateControls( int rate )
831 {
832     if( speedSlider->isSliderDown() )
833     {
834         //We don't want to change anything if the user is using the slider
835         return;
836     }
837
838     int sliderValue;
839     double speed = INPUT_RATE_DEFAULT / (double)rate;
840
841     if( rate >= INPUT_RATE_DEFAULT )
842     {
843         if( speed < RATE_SLIDER_MINIMUM )
844         {
845             sliderValue = speedSlider->minimum();
846         }
847         else
848         {
849             sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
850                                         / ( 1.0 - RATE_SLIDER_MAXIMUM ) );
851         }
852     }
853     else
854     {
855         if( speed > RATE_SLIDER_MAXIMUM )
856         {
857             sliderValue = speedSlider->maximum();
858         }
859         else
860         {
861             sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
862                                         / ( RATE_SLIDER_MAXIMUM - 1.0 ) );
863         }
864     }
865
866     //Block signals to avoid feedback loop
867     speedSlider->blockSignals( true );
868     speedSlider->setValue( sliderValue );
869     speedSlider->blockSignals( false );
870 }
871
872 void SpeedControlWidget::updateRate( int sliderValue )
873 {
874     int rate;
875
876     if( sliderValue < 0.0 )
877     {
878         rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
879             ( sliderValue * ( 1.0 - RATE_SLIDER_MINIMUM ) + RATE_SLIDER_LENGTH );
880     }
881     else
882     {
883         rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
884             ( sliderValue * ( RATE_SLIDER_MAXIMUM - 1.0 ) + RATE_SLIDER_LENGTH );
885     }
886
887     THEMIM->getIM()->setRate(rate);
888 }
889
890 void SpeedControlWidget::resetRate()
891 {
892     THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);
893 }