]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/interface_widgets.cpp
Qt: Access-filter 'record' does not exist 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 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #include <vlc_vout.h>
32
33 #include "dialogs_provider.hpp"
34 #include "components/interface_widgets.hpp"
35 #include "main_interface.hpp"
36 #include "input_manager.hpp"
37 #include "menus.hpp"
38 #include "util/input_slider.hpp"
39 #include "util/customwidgets.hpp"
40
41 #include <QLabel>
42 #include <QSpacerItem>
43 #include <QCursor>
44 #include <QPushButton>
45 #include <QToolButton>
46 #include <QHBoxLayout>
47 #include <QMenu>
48 #include <QPalette>
49 #include <QResizeEvent>
50 #include <QDate>
51
52 #ifdef Q_WS_X11
53 # include <X11/Xlib.h>
54 # include <qx11info_x11.h>
55 #endif
56
57 #include <math.h>
58
59 #define I_PLAY_TOOLTIP N_("Play\nIf the playlist is empty, open a media")
60
61 /**********************************************************************
62  * Video Widget. A simple frame on which video is drawn
63  * This class handles resize issues
64  **********************************************************************/
65
66 VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
67 {
68     /* Init */
69     i_vout = 0;
70     videoSize.rwidth() = -1;
71     videoSize.rheight() = -1;
72
73     hide();
74
75     /* Set the policy to expand in both directions */
76 //    setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
77
78     /* Black background is more coherent for a Video Widget */
79     QPalette plt =  palette();
80     plt.setColor( QPalette::Window, Qt::black );
81     setPalette( plt );
82     setAutoFillBackground(true);
83
84     /* Indicates that the widget wants to draw directly onto the screen.
85        Widgets with this attribute set do not participate in composition
86        management */
87     setAttribute( Qt::WA_PaintOnScreen, true );
88
89     /* The core can ask through a callback to show the video. */
90 #if HAS_QT43
91     connect( this, SIGNAL(askVideoWidgetToShow( unsigned int, unsigned int)),
92              this, SLOT(SetSizing(unsigned int, unsigned int )),
93              Qt::BlockingQueuedConnection );
94 #else
95 #warning This is broken. Fix it with a QEventLoop with a processEvents ()
96     connect( this, SIGNAL(askVideoWidgetToShow( unsigned int, unsigned int)),
97              this, SLOT(SetSizing(unsigned int, unsigned int )) );
98 #endif
99 }
100
101 void VideoWidget::paintEvent(QPaintEvent *ev)
102 {
103     QFrame::paintEvent(ev);
104 #ifdef Q_WS_X11
105     XFlush( QX11Info::display() );
106 #endif
107 }
108
109 /* Kill the vout at Destruction */
110 VideoWidget::~VideoWidget()
111 {
112     vout_thread_t *p_vout = i_vout ?
113         (vout_thread_t *)vlc_object_get( p_intf->p_libvlc, i_vout ) : NULL;
114
115     if( p_vout )
116     {
117         if( vout_Control( p_vout, VOUT_CLOSE ) != VLC_SUCCESS )
118             vout_Control( p_vout, VOUT_REPARENT );
119         vlc_object_release( p_vout );
120     }
121 }
122
123 /**
124  * Request the video to avoid the conflicts
125  **/
126 void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
127                             unsigned int *pi_width, unsigned int *pi_height )
128 {
129     msg_Dbg( p_intf, "Video was requested %i, %i", *pi_x, *pi_y );
130     emit askVideoWidgetToShow( *pi_width, *pi_height );
131     if( i_vout )
132     {
133         msg_Dbg( p_intf, "embedded video already in use" );
134         return NULL;
135     }
136     i_vout = p_nvout->i_object_id;
137 #ifndef NDEBUG
138     msg_Dbg( p_intf, "embedded video ready (handle %p)", winId() );
139 #endif
140     return ( void* )winId();
141 }
142
143 /* Set the Widget to the correct Size */
144 /* Function has to be called by the parent
145    Parent has to care about resizing himself*/
146 void VideoWidget::SetSizing( unsigned int w, unsigned int h )
147 {
148     msg_Dbg( p_intf, "Video is resizing to: %i %i", w, h );
149     videoSize.rwidth() = w;
150     videoSize.rheight() = h;
151     if( isHidden() ) show();
152     updateGeometry(); // Needed for deinterlace
153 }
154
155 void VideoWidget::release( void *p_win )
156 {
157     msg_Dbg( p_intf, "Video is not needed anymore" );
158     i_vout = 0;
159     videoSize.rwidth() = 0;
160     videoSize.rheight() = 0;
161     updateGeometry();
162     hide();
163 }
164
165 QSize VideoWidget::sizeHint() const
166 {
167     return videoSize;
168 }
169
170 /**********************************************************************
171  * Background Widget. Show a simple image background. Currently,
172  * it's album art if present or cone.
173  **********************************************************************/
174 #define ICON_SIZE 128
175 #define MAX_BG_SIZE 400
176 #define MIN_BG_SIZE 128
177
178 BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i )
179                  :QWidget( NULL ), p_intf( _p_i )
180 {
181     /* We should use that one to take the more size it can */
182     setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding);
183
184     /* A dark background */
185     setAutoFillBackground( true );
186     plt = palette();
187     plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
188     plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
189     setPalette( plt );
190
191     /* A cone in the middle */
192     label = new QLabel;
193     label->setMargin( 5 );
194     label->setMaximumHeight( MAX_BG_SIZE );
195     label->setMaximumWidth( MAX_BG_SIZE );
196     label->setMinimumHeight( MIN_BG_SIZE );
197     label->setMinimumWidth( MIN_BG_SIZE );
198     if( QDate::currentDate().dayOfYear() >= 354 )
199         label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
200     else
201         label->setPixmap( QPixmap( ":/vlc128.png" ) );
202
203     QGridLayout *backgroundLayout = new QGridLayout( this );
204     backgroundLayout->addWidget( label, 0, 1 );
205     backgroundLayout->setColumnStretch( 0, 1 );
206     backgroundLayout->setColumnStretch( 2, 1 );
207
208     CONNECT( THEMIM->getIM(), artChanged( input_item_t* ),
209              this, updateArt( input_item_t* ) );
210 }
211
212 BackgroundWidget::~BackgroundWidget()
213 {}
214
215 void BackgroundWidget::resizeEvent( QResizeEvent * event )
216 {
217     if( event->size().height() <= MIN_BG_SIZE )
218         label->hide();
219     else
220         label->show();
221 }
222
223 void BackgroundWidget::updateArt( input_item_t *p_item )
224 {
225     QString url;
226     if( p_item )
227     {
228         char *psz_art = input_item_GetArtURL( p_item );
229         url = psz_art;
230         free( psz_art );
231     }
232
233     if( url.isEmpty() )
234     {
235         if( QDate::currentDate().dayOfYear() >= 354 )
236             label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
237         else
238             label->setPixmap( QPixmap( ":/vlc128.png" ) );
239     }
240     else
241     {
242         url = url.replace( "file://", QString("" ) );
243         /* Taglib seems to define a attachment://, It won't work yet */
244         url = url.replace( "attachment://", QString("" ) );
245         label->setPixmap( QPixmap( url ) );
246     }
247 }
248
249 void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
250 {
251     QVLCMenu::PopupMenu( p_intf, true );
252 }
253
254 #if 0
255 /**********************************************************************
256  * Visualization selector panel
257  **********************************************************************/
258 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
259                                 QFrame( NULL ), p_intf( _p_i )
260 {
261     QHBoxLayout *layout = new QHBoxLayout( this );
262     layout->setMargin( 0 );
263     QPushButton *prevButton = new QPushButton( "Prev" );
264     QPushButton *nextButton = new QPushButton( "Next" );
265     layout->addWidget( prevButton );
266     layout->addWidget( nextButton );
267
268     layout->addStretch( 10 );
269     layout->addWidget( new QLabel( qtr( "Current visualization" ) ) );
270
271     current = new QLabel( qtr( "None" ) );
272     layout->addWidget( current );
273
274     BUTTONACT( prevButton, prev() );
275     BUTTONACT( nextButton, next() );
276
277     setLayout( layout );
278     setMaximumHeight( 35 );
279 }
280
281 VisualSelector::~VisualSelector()
282 {}
283
284 void VisualSelector::prev()
285 {
286     char *psz_new = aout_VisualPrev( p_intf );
287     if( psz_new )
288     {
289         current->setText( qfu( psz_new ) );
290         free( psz_new );
291     }
292 }
293
294 void VisualSelector::next()
295 {
296     char *psz_new = aout_VisualNext( p_intf );
297     if( psz_new )
298     {
299         current->setText( qfu( psz_new ) );
300         free( psz_new );
301     }
302 }
303 #endif
304
305 /**********************************************************************
306  * TEH controls
307  **********************************************************************/
308
309 #define setupSmallButton( aButton ){  \
310     aButton->setMaximumSize( QSize( 26, 26 ) ); \
311     aButton->setMinimumSize( QSize( 26, 26 ) ); \
312     aButton->setIconSize( QSize( 20, 20 ) ); }
313
314 /* init static variables in advanced controls */
315 mtime_t AdvControlsWidget::timeA = 0;
316 mtime_t AdvControlsWidget::timeB = 0;
317
318 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i, bool b_fsCreation = false ) :
319                                            QFrame( NULL ), p_intf( _p_i )
320 {
321     QHBoxLayout *advLayout = new QHBoxLayout( this );
322     advLayout->setMargin( 0 );
323     advLayout->setSpacing( 0 );
324     advLayout->setAlignment( Qt::AlignBottom );
325
326     /* A to B Button */
327     ABButton = new QPushButton;
328     setupSmallButton( ABButton );
329     advLayout->addWidget( ABButton );
330     BUTTON_SET_ACT_I( ABButton, "", atob_nob,
331       qtr( "Loop from point A to point B continuously.\nClick to set point A" ),
332       fromAtoB() );
333     timeA = timeB = 0;
334     i_last_input_id = 0;
335     /* in FS controller we skip this, because we dont want to have it double
336        controlled */
337     if( !b_fsCreation )
338         CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
339                  this, AtoBLoop( float, int, int ) );
340     /* set up synchronization between main controller and fs controller */
341     CONNECT( THEMIM->getIM(), advControlsSetIcon(), this, setIcon() );
342     connect( this, SIGNAL( timeChanged() ),
343         THEMIM->getIM(), SIGNAL( advControlsSetIcon()));
344 #if 0
345     frameButton = new QPushButton( "Fr" );
346     frameButton->setMaximumSize( QSize( 26, 26 ) );
347     frameButton->setIconSize( QSize( 20, 20 ) );
348     advLayout->addWidget( frameButton );
349     BUTTON_SET_ACT( frameButton, "Fr", qtr( "Frame by frame" ), frame() );
350 #endif
351
352     /* Record Button */
353 #if 0
354     recordButton = new QPushButton;
355     setupSmallButton( recordButton );
356     advLayout->addWidget( recordButton );
357     BUTTON_SET_ACT_I( recordButton, "", record,
358             qtr( "Record" ), record() );
359 #endif
360
361     /* Snapshot Button */
362     snapshotButton = new QPushButton;
363     setupSmallButton( snapshotButton );
364     advLayout->addWidget( snapshotButton );
365     BUTTON_SET_ACT_I( snapshotButton, "", snapshot,
366             qtr( "Take a snapshot" ), snapshot() );
367 }
368
369 AdvControlsWidget::~AdvControlsWidget()
370 {}
371
372 void AdvControlsWidget::enableInput( bool enable )
373 {
374     int i_input_id = 0;
375     if( THEMIM->getInput() != NULL )
376     {
377         input_item_t *p_item = input_GetItem( THEMIM->getInput() );
378         i_input_id = p_item->i_id;
379 #if 0
380         recordButton->setVisible( var_GetBool( THEMIM->getInput(), "can-record" ) );
381     }
382     else
383     {
384         recordButton->setVisible( false );
385 #endif
386     }
387
388     ABButton->setEnabled( enable );
389 #if 0
390     recordButton->setEnabled( enable );
391 #endif
392
393     if( enable && ( i_last_input_id != i_input_id ) )
394     {
395         timeA = timeB = 0;
396         i_last_input_id = i_input_id;
397         emit timeChanged();
398     }
399 }
400
401 void AdvControlsWidget::enableVideo( bool enable )
402 {
403     snapshotButton->setEnabled( enable );
404 #if 0
405     frameButton->setEnabled( enable );
406 #endif
407 }
408
409 void AdvControlsWidget::snapshot()
410 {
411     vout_thread_t *p_vout =
412         (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
413     if( p_vout )
414     {
415         vout_Control( p_vout, VOUT_SNAPSHOT );
416         vlc_object_release( p_vout );
417     }
418 }
419
420 /* Function called when the button is clicked() */
421 void AdvControlsWidget::fromAtoB()
422 {
423     if( !timeA )
424     {
425         timeA = var_GetTime( THEMIM->getInput(), "time"  );
426         emit timeChanged();
427         return;
428     }
429     if( !timeB )
430     {
431         timeB = var_GetTime( THEMIM->getInput(), "time"  );
432         var_SetTime( THEMIM->getInput(), "time" , timeA );
433         emit timeChanged();
434         return;
435     }
436     timeA = 0;
437     timeB = 0;
438     emit timeChanged();
439 }
440
441 /* setting/synchro icons after click on main or fs controller */
442 void AdvControlsWidget::setIcon()
443 {
444     if( !timeA && !timeB)
445     {
446         ABButton->setIcon( QIcon( ":/atob_nob" ) );
447         ABButton->setToolTip( qtr( "Loop from point A to point B continuously\nClick to set point A" ) );
448     }
449     else if( timeA && !timeB )
450     {
451         ABButton->setIcon( QIcon( ":/atob_noa" ) );
452         ABButton->setToolTip( qtr( "Click to set point B" ) );
453     }
454     else if( timeA && timeB )
455     {
456         ABButton->setIcon( QIcon( ":/atob" ) );
457         ABButton->setToolTip( qtr( "Stop the A to B loop" ) );
458     }
459 }
460
461 /* Function called regularly when in an AtoB loop */
462 void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
463 {
464     if( timeB )
465     {
466         if( ( i_time >= (int)( timeB/1000000 ) )
467             || ( i_time < (int)( timeA/1000000 ) ) )
468             var_SetTime( THEMIM->getInput(), "time" , timeA );
469     }
470 }
471
472 // TODO: On-the-fly record needs to be reimplemented
473 void AdvControlsWidget::record()
474 {
475     input_thread_t *p_input = THEMIM->getInput();
476     if( p_input )
477     {
478         /* This method won't work fine if the stream can't be cut anywhere */
479         const bool b_recording = var_GetBool( p_input, "record" );
480         var_SetBool( p_input, "record", !b_recording );
481 #if 0
482         else
483         {
484             /* 'record' access-filter is not loaded, we open Save dialog */
485             input_item_t *p_item = input_GetItem( p_input );
486             if( !p_item )
487                 return;
488
489             char *psz = input_item_GetURI( p_item );
490             if( psz )
491                 THEDP->streamingDialog( NULL, psz, true );
492         }
493 #endif
494     }
495 }
496
497 #if 0
498 //FIXME Frame by frame function
499 void AdvControlsWidget::frame(){}
500 #endif
501
502 /*****************************
503  * DA Control Widget !
504  *****************************/
505 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
506                                 MainInterface *_p_mi,
507                                 bool b_advControls,
508                                 bool b_shiny,
509                                 bool b_fsCreation) :
510                                 QFrame( _p_mi ), p_intf( _p_i )
511 {
512     setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
513
514     /** The main Slider **/
515     slider = new InputSlider( Qt::Horizontal, NULL );
516     /* Update the position when the IM has changed */
517     CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
518              slider, setPosition( float, int, int ) );
519     /* And update the IM, when the position has changed */
520     CONNECT( slider, sliderDragged( float ),
521              THEMIM->getIM(), sliderUpdate( float ) );
522
523     /** Slower and faster Buttons **/
524     slowerButton = new QToolButton;
525     slowerButton->setAutoRaise( true );
526     slowerButton->setMaximumSize( QSize( 26, 20 ) );
527
528     BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
529
530     fasterButton = new QToolButton;
531     fasterButton->setAutoRaise( true );
532     fasterButton->setMaximumSize( QSize( 26, 20 ) );
533
534     BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
535
536     /* advanced Controls handling */
537     b_advancedVisible = b_advControls;
538
539     advControls = new AdvControlsWidget( p_intf, b_fsCreation );
540     if( !b_advancedVisible ) advControls->hide();
541
542     /** Disc and Menus handling */
543     discFrame = new QWidget( this );
544
545     QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
546     discLayout->setSpacing( 0 );
547     discLayout->setMargin( 0 );
548
549     prevSectionButton = new QPushButton( discFrame );
550     setupSmallButton( prevSectionButton );
551     discLayout->addWidget( prevSectionButton );
552
553     menuButton = new QPushButton( discFrame );
554     setupSmallButton( menuButton );
555     discLayout->addWidget( menuButton );
556
557     nextSectionButton = new QPushButton( discFrame );
558     setupSmallButton( nextSectionButton );
559     discLayout->addWidget( nextSectionButton );
560
561     BUTTON_SET_IMG( prevSectionButton, "", dvd_prev, "" );
562     BUTTON_SET_IMG( nextSectionButton, "", dvd_next, "" );
563     BUTTON_SET_IMG( menuButton, "", dvd_menu, qtr( "Menu" ) );
564
565     discFrame->hide();
566
567     /* Change the navigation button display when the IM navigation changes */
568     CONNECT( THEMIM->getIM(), navigationChanged( int ),
569              this, setNavigation( int ) );
570     /* Changes the IM navigation when triggered on the nav buttons */
571     CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
572              sectionPrev() );
573     CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
574              sectionNext() );
575     CONNECT( menuButton, clicked(), THEMIM->getIM(),
576              sectionMenu() );
577
578     /**
579      * Telextext QFrame
580      * TODO: Merge with upper menu in a StackLayout
581      **/
582     telexFrame = new QWidget( this );
583     QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
584     telexLayout->setSpacing( 0 );
585     telexLayout->setMargin( 0 );
586
587     telexOn = new QPushButton;
588     setupSmallButton( telexOn );
589     telexLayout->addWidget( telexOn );
590
591     telexTransparent = new QPushButton;
592     setupSmallButton( telexTransparent );
593     telexLayout->addWidget( telexTransparent );
594     b_telexTransparent = false;
595
596     telexPage = new QSpinBox;
597     telexPage->setRange( 0, 999 );
598     telexPage->setValue( 100 );
599     telexPage->setAccelerated( true );
600     telexPage->setWrapping( true );
601     telexPage->setAlignment( Qt::AlignRight );
602     telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
603     telexLayout->addWidget( telexPage );
604
605     telexFrame->hide(); /* default hidden */
606
607     CONNECT( telexPage, valueChanged( int ), THEMIM->getIM(),
608              telexGotoPage( int ) );
609     CONNECT( THEMIM->getIM(), setNewTelexPage( int ),
610               telexPage, setValue( int ) );
611
612     BUTTON_SET_IMG( telexOn, "", tv, qtr( "Teletext on" ) );
613
614     CONNECT( telexOn, clicked(), THEMIM->getIM(),
615              telexToggleButtons() );
616     CONNECT( telexOn, clicked( bool ), THEMIM->getIM(),
617              telexToggle( bool ) );
618     CONNECT( THEMIM->getIM(), toggleTelexButtons(),
619               this, toggleTeletext() );
620     b_telexEnabled = false;
621     telexTransparent->setEnabled( false );
622     telexPage->setEnabled( false );
623
624     BUTTON_SET_IMG( telexTransparent, "", tvtelx, qtr( "Teletext" ) );
625     CONNECT( telexTransparent, clicked( bool ),
626              THEMIM->getIM(), telexSetTransparency() );
627     CONNECT( THEMIM->getIM(), toggleTelexTransparency(),
628               this, toggleTeletextTransparency() );
629     CONNECT( THEMIM->getIM(), teletextEnabled( bool ),
630              this, enableTeletext( bool ) );
631
632     /** Play Buttons **/
633     QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
634     sizePolicy.setHorizontalStretch( 0 );
635     sizePolicy.setVerticalStretch( 0 );
636
637     /* Play */
638     playButton = new QPushButton;
639     playButton->setSizePolicy( sizePolicy );
640     playButton->setMaximumSize( QSize( 36, 36 ) );
641     playButton->setMinimumSize( QSize( 36, 36 ) );
642     playButton->setIconSize( QSize( 30, 30 ) );
643
644
645     /** Prev + Stop + Next Block **/
646     controlButLayout = new QHBoxLayout;
647     controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
648
649     /* Prev */
650     QPushButton *prevButton = new QPushButton;
651     prevButton->setSizePolicy( sizePolicy );
652     setupSmallButton( prevButton );
653
654     controlButLayout->addWidget( prevButton );
655
656     /* Stop */
657     QPushButton *stopButton = new QPushButton;
658     stopButton->setSizePolicy( sizePolicy );
659     setupSmallButton( stopButton );
660
661     controlButLayout->addWidget( stopButton );
662
663     /* next */
664     QPushButton *nextButton = new QPushButton;
665     nextButton->setSizePolicy( sizePolicy );
666     setupSmallButton( nextButton );
667
668     controlButLayout->addWidget( nextButton );
669
670     /* Add this block to the main layout */
671
672     BUTTON_SET_ACT_I( playButton, "", play_b, qtr( I_PLAY_TOOLTIP ), play() );
673     BUTTON_SET_ACT_I( prevButton, "" , previous_b,
674                       qtr( "Previous media in the playlist" ), prev() );
675     BUTTON_SET_ACT_I( nextButton, "", next_b,
676                       qtr( "Next media in the playlist" ), next() );
677     BUTTON_SET_ACT_I( stopButton, "", stop_b, qtr( "Stop playback" ), stop() );
678
679     /*
680      * Other first Line buttons
681      */
682     /* */
683     CONNECT( THEMIM->getIM(), voutChanged(bool), this, enableVideo(bool) );
684
685     /** Fullscreen/Visualisation **/
686     fullscreenButton = new QPushButton;
687     BUTTON_SET_ACT_I( fullscreenButton, "", fullscreen,
688             qtr( "Toggle the video in fullscreen" ), fullscreen() );
689     setupSmallButton( fullscreenButton );
690
691     if( !b_fsCreation )
692     {
693         /** Playlist Button **/
694         playlistButton = new QPushButton;
695         setupSmallButton( playlistButton );
696         BUTTON_SET_IMG( playlistButton, "" , playlist, qtr( "Show playlist" ) );
697         CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
698
699         /** extended Settings **/
700         extSettingsButton = new QPushButton;
701         BUTTON_SET_ACT_I( extSettingsButton, "", extended,
702                 qtr( "Show extended settings" ), extSettings() );
703         setupSmallButton( extSettingsButton );
704     }
705
706     /* Volume */
707     hVolLabel = new VolumeClickHandler( p_intf, this );
708
709     volMuteLabel = new QLabel;
710     volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
711     volMuteLabel->installEventFilter( hVolLabel );
712
713     if( b_shiny )
714     {
715         volumeSlider = new SoundSlider( this,
716             config_GetInt( p_intf, "volume-step" ),
717             config_GetInt( p_intf, "qt-volume-complete" ),
718             config_GetPsz( p_intf, "qt-slider-colours" ) );
719     }
720     else
721     {
722         volumeSlider = new QSlider( this );
723         volumeSlider->setOrientation( Qt::Horizontal );
724     }
725     volumeSlider->setMaximumSize( QSize( 200, 40 ) );
726     volumeSlider->setMinimumSize( QSize( 85, 30 ) );
727     volumeSlider->setFocusPolicy( Qt::NoFocus );
728
729     /* Set the volume from the config */
730     volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
731                               VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
732
733     /* Force the update at build time in order to have a muted icon if needed */
734     updateVolume( volumeSlider->value() );
735
736     /* Volume control connection */
737     CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
738     CONNECT( THEMIM, volumeChanged( void ), this, updateVolume( void ) );
739
740     if( !b_fsCreation )
741     {
742         controlLayout = new QGridLayout( this );
743
744         controlLayout->setSpacing( 0 );
745         controlLayout->setLayoutMargins( 7, 5, 7, 3, 6 );
746
747         controlLayout->addWidget( slider, 0, 1, 1, 18 );
748         controlLayout->addWidget( slowerButton, 0, 0 );
749         controlLayout->addWidget( fasterButton, 0, 19 );
750
751         controlLayout->addWidget( discFrame, 1, 8, 2, 3, Qt::AlignBottom );
752         controlLayout->addWidget( telexFrame, 1, 8, 2, 5, Qt::AlignBottom );
753
754         controlLayout->addWidget( playButton, 2, 0, 2, 2, Qt::AlignBottom );
755         controlLayout->setColumnMinimumWidth( 2, 10 );
756         controlLayout->setColumnStretch( 2, 0 );
757
758         controlLayout->addLayout( controlButLayout, 3, 3, 1, 3, Qt::AlignBottom );
759         /* Column 6 is unused */
760         controlLayout->setColumnStretch( 6, 0 );
761         controlLayout->setColumnStretch( 7, 0 );
762         controlLayout->setColumnMinimumWidth( 7, 10 );
763
764         controlLayout->addWidget( fullscreenButton, 3, 8, Qt::AlignBottom );
765         controlLayout->addWidget( playlistButton, 3, 9, Qt::AlignBottom );
766         controlLayout->addWidget( extSettingsButton, 3, 10, Qt::AlignBottom );
767         controlLayout->setColumnStretch( 11, 0 ); /* telex alignment */
768
769         controlLayout->setColumnStretch( 12, 0 );
770         controlLayout->setColumnMinimumWidth( 12, 10 );
771
772         controlLayout->addWidget( advControls, 3, 13, 1, 3, Qt::AlignBottom );
773
774         controlLayout->setColumnStretch( 16, 10 );
775         controlLayout->setColumnMinimumWidth( 16, 10 );
776
777         controlLayout->addWidget( volMuteLabel, 3, 17, Qt::AlignBottom );
778         controlLayout->addWidget( volumeSlider, 3, 18, 1 , 2, Qt::AlignBottom );
779     }
780
781     updateInput();
782 }
783
784 ControlsWidget::~ControlsWidget()
785 {}
786
787 void ControlsWidget::toggleTeletext()
788 {
789     bool b_enabled = THEMIM->teletextState();
790     if( b_telexEnabled )
791     {
792         telexTransparent->setEnabled( false );
793         telexPage->setEnabled( false );
794         b_telexEnabled = false;
795     }
796     else if( b_enabled )
797     {
798         telexTransparent->setEnabled( true );
799         telexPage->setEnabled( true );
800         b_telexEnabled = true;
801     }
802 }
803
804 void ControlsWidget::enableTeletext( bool b_enable )
805 {
806     telexFrame->setVisible( b_enable );
807     bool b_on = THEMIM->teletextState();
808
809     telexOn->setChecked( b_on );
810     telexTransparent->setEnabled( b_on );
811     telexPage->setEnabled( b_on );
812     b_telexEnabled = b_on;
813 }
814
815 void ControlsWidget::toggleTeletextTransparency()
816 {
817     if( b_telexTransparent )
818     {
819         telexTransparent->setIcon( QIcon( ":/tvtelx" ) );
820         telexTransparent->setToolTip( qtr( "Teletext" ) );
821         b_telexTransparent = false;
822     }
823     else
824     {
825         telexTransparent->setIcon( QIcon( ":/tvtelx-trans" ) );
826         telexTransparent->setToolTip( qtr( "Transparent" ) );
827         b_telexTransparent = true;
828     }
829 }
830
831 void ControlsWidget::stop()
832 {
833     THEMIM->stop();
834 }
835
836 void ControlsWidget::play()
837 {
838     if( THEPL->current.i_size == 0 )
839     {
840         /* The playlist is empty, open a file requester */
841         THEDP->openFileDialog();
842         setStatus( 0 );
843         return;
844     }
845     THEMIM->togglePlayPause();
846 }
847
848 void ControlsWidget::prev()
849 {
850     THEMIM->prev();
851 }
852
853 void ControlsWidget::next()
854 {
855     THEMIM->next();
856 }
857
858 void ControlsWidget::setNavigation( int navigation )
859 {
860 #define HELP_PCH N_( "Previous chapter" )
861 #define HELP_NCH N_( "Next chapter" )
862
863     // 1 = chapter, 2 = title, 0 = no
864     if( navigation == 0 )
865     {
866         discFrame->hide();
867     } else if( navigation == 1 ) {
868         prevSectionButton->setToolTip( qtr( HELP_PCH ) );
869         nextSectionButton->setToolTip( qtr( HELP_NCH ) );
870         menuButton->show();
871         discFrame->show();
872     } else {
873         prevSectionButton->setToolTip( qtr( HELP_PCH ) );
874         nextSectionButton->setToolTip( qtr( HELP_NCH ) );
875         menuButton->hide();
876         discFrame->show();
877     }
878 }
879
880 static bool b_my_volume;
881 void ControlsWidget::updateVolume( int i_sliderVolume )
882 {
883     if( !b_my_volume )
884     {
885         int i_res = i_sliderVolume  * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
886         aout_VolumeSet( p_intf, i_res );
887     }
888     if( i_sliderVolume == 0 )
889     {
890         volMuteLabel->setPixmap( QPixmap(":/volume-muted" ) );
891         volMuteLabel->setToolTip( qtr( "Unmute" ) );
892         return;
893     }
894
895     if( i_sliderVolume < VOLUME_MAX / 3 )
896         volMuteLabel->setPixmap( QPixmap( ":/volume-low" ) );
897     else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
898         volMuteLabel->setPixmap( QPixmap( ":/volume-high" ) );
899     else volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
900     volMuteLabel->setToolTip( qtr( "Mute" ) );
901 }
902
903 void ControlsWidget::updateVolume()
904 {
905     /* Audio part */
906     audio_volume_t i_volume;
907     aout_VolumeGet( p_intf, &i_volume );
908     i_volume = ( i_volume *  VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
909     int i_gauge = volumeSlider->value();
910     b_my_volume = false;
911     if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
912     {
913         b_my_volume = true;
914         volumeSlider->setValue( i_volume );
915         b_my_volume = false;
916     }
917 }
918
919 void ControlsWidget::updateInput()
920 {
921     /* Activate the interface buttons according to the presence of the input */
922     enableInput( THEMIM->getIM()->hasInput() );
923     enableVideo( THEMIM->getIM()->hasVideo() );
924 }
925
926 void ControlsWidget::setStatus( int status )
927 {
928     if( status == PLAYING_S ) /* Playing */
929     {
930         playButton->setIcon( QIcon( ":/pause_b" ) );
931         playButton->setToolTip( qtr( "Pause the playback" ) );
932     }
933     else
934     {
935         playButton->setIcon( QIcon( ":/play_b" ) );
936         playButton->setToolTip( qtr( I_PLAY_TOOLTIP ) );
937     }
938 }
939
940 /**
941  * TODO
942  * This functions toggle the fullscreen mode
943  * If there is no video, it should first activate Visualisations...
944  *  This has also to be fixed in enableVideo()
945  */
946 void ControlsWidget::fullscreen()
947 {
948     vout_thread_t *p_vout =
949         (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
950     if( p_vout)
951     {
952         var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
953         vlc_object_release( p_vout );
954     }
955 }
956
957 void ControlsWidget::extSettings()
958 {
959     THEDP->extendedDialog();
960 }
961
962 void ControlsWidget::slower()
963 {
964     THEMIM->getIM()->slower();
965 }
966
967 void ControlsWidget::faster()
968 {
969     THEMIM->getIM()->faster();
970 }
971
972 void ControlsWidget::enableInput( bool enable )
973 {
974     slowerButton->setEnabled( enable );
975     slider->setEnabled( enable );
976     slider->setSliderPosition ( 0 );
977     fasterButton->setEnabled( enable );
978
979     /* Advanced Buttons too */
980     advControls->enableInput( enable );
981 }
982
983 void ControlsWidget::enableVideo( bool enable )
984 {
985     // TODO Later make the fullscreenButton toggle Visualisation and so on.
986     fullscreenButton->setEnabled( enable );
987
988     /* Advanced Buttons too */
989     advControls->enableVideo( enable );
990 }
991
992 void ControlsWidget::toggleAdvanced()
993 {
994     if( advControls && !b_advancedVisible )
995     {
996         advControls->show();
997         b_advancedVisible = true;
998     }
999     else
1000     {
1001         advControls->hide();
1002         b_advancedVisible = false;
1003     }
1004     emit advancedControlsToggled( b_advancedVisible );
1005 }
1006
1007 /**********************************************************************
1008  * Fullscrenn control widget
1009  **********************************************************************/
1010 FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i,
1011         MainInterface *_p_mi, bool b_advControls, bool b_shiny )
1012         : ControlsWidget( _p_i, _p_mi, b_advControls, b_shiny, true ),
1013           i_mouse_last_x( -1 ), i_mouse_last_y( -1 ), b_mouse_over(false),
1014           b_slow_hide_begin(false), i_slow_hide_timeout(1),
1015           b_fullscreen( false ), i_hide_timeout( 1 ), p_vout(NULL)
1016 {
1017     setWindowFlags( Qt::ToolTip );
1018
1019     setFrameShape( QFrame::StyledPanel );
1020     setFrameStyle( QFrame::Sunken );
1021     setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
1022
1023     QGridLayout *fsLayout = new QGridLayout( this );
1024     fsLayout->setLayoutMargins( 5, 2, 5, 2, 5 );
1025
1026     /* First line */
1027     slider->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum);
1028     slider->setMinimumWidth( 220 );
1029     fsLayout->addWidget( slowerButton, 0, 0 );
1030     fsLayout->addWidget( slider, 0, 1, 1, 9 );
1031     fsLayout->addWidget( fasterButton, 0, 10 );
1032
1033     fsLayout->addWidget( playButton, 1, 0, 1, 2 );
1034     fsLayout->addLayout( controlButLayout, 1, 2 );
1035
1036     fsLayout->addWidget( discFrame, 1, 3 );
1037     fsLayout->addWidget( telexFrame, 1, 4 );
1038     fsLayout->addWidget( fullscreenButton, 1, 5 );
1039     fsLayout->addWidget( advControls, 1, 6, Qt::AlignVCenter );
1040
1041     fsLayout->setColumnStretch( 7, 10 );
1042     fsLayout->addWidget( volMuteLabel, 1, 8 );
1043     fsLayout->addWidget( volumeSlider, 1, 9, 1, 2 );
1044
1045     /* hiding timer */
1046     p_hideTimer = new QTimer( this );
1047     CONNECT( p_hideTimer, timeout(), this, hideFSC() );
1048     p_hideTimer->setSingleShot( true );
1049
1050     /* slow hiding timer */
1051 #if HAVE_TRANSPARENCY
1052     p_slowHideTimer = new QTimer( this );
1053     CONNECT( p_slowHideTimer, timeout(), this, slowHideFSC() );
1054 #endif
1055
1056     adjustSize ();  /* need to get real width and height for moving */
1057
1058     /* center down */
1059     QDesktopWidget * p_desktop = QApplication::desktop();
1060
1061     move( p_desktop->width() / 2 - width() / 2,
1062           p_desktop->height() - height() );
1063
1064 #ifdef WIN32TRICK
1065     setWindowOpacity( 0.0 );
1066     b_fscHidden = true;
1067     adjustSize();
1068     show();
1069 #endif
1070
1071     fullscreenButton->setIcon( QIcon( ":/defullscreen" ) );
1072
1073     vlc_mutex_init_recursive( &lock );
1074 }
1075
1076 FullscreenControllerWidget::~FullscreenControllerWidget()
1077 {
1078     detachVout();
1079     vlc_mutex_destroy( &lock );
1080 }
1081
1082 /**
1083  * Show fullscreen controller
1084  */
1085 void FullscreenControllerWidget::showFSC()
1086 {
1087     adjustSize();
1088 #ifdef WIN32TRICK
1089     // after quiting and going to fs, we need to call show()
1090     if( isHidden() )
1091         show();
1092
1093     if( b_fscHidden )
1094     {
1095         b_fscHidden = false;
1096         setWindowOpacity( 1.0 );
1097     }
1098 #else
1099     show();
1100 #endif
1101
1102 #if HAVE_TRANSPARENCY
1103     setWindowOpacity( DEFAULT_OPACITY );
1104 #endif
1105 }
1106
1107 /**
1108  * Hide fullscreen controller
1109  * FIXME: under windows it have to be done by moving out of screen
1110  *        because hide() doesnt work
1111  */
1112 void FullscreenControllerWidget::hideFSC()
1113 {
1114 #ifdef WIN32TRICK
1115     b_fscHidden = true;
1116     setWindowOpacity( 0.0 );    // simulate hidding
1117 #else
1118     hide();
1119 #endif
1120 }
1121
1122 /**
1123  * Plane to hide fullscreen controller
1124  */
1125 void FullscreenControllerWidget::planHideFSC()
1126 {
1127     vlc_mutex_lock( &lock );
1128     int i_timeout = i_hide_timeout;
1129     vlc_mutex_unlock( &lock );
1130
1131     p_hideTimer->start( i_timeout );
1132
1133 #if HAVE_TRANSPARENCY
1134     b_slow_hide_begin = true;
1135     i_slow_hide_timeout = i_timeout;
1136     p_slowHideTimer->start( i_slow_hide_timeout / 2 );
1137 #endif
1138 }
1139
1140 /**
1141  * Hidding fullscreen controller slowly
1142  * Linux: need composite manager
1143  * Windows: it is blinking, so it can be enabled by define TRASPARENCY
1144  */
1145 void FullscreenControllerWidget::slowHideFSC()
1146 {
1147 #if HAVE_TRANSPARENCY
1148     if( b_slow_hide_begin )
1149     {
1150         b_slow_hide_begin = false;
1151
1152         p_slowHideTimer->stop();
1153         /* the last part of time divided to 100 pieces */
1154         p_slowHideTimer->start( (int)( i_slow_hide_timeout / 2 / ( windowOpacity() * 100 ) ) );
1155
1156     }
1157     else
1158     {
1159 #ifdef WIN32TRICK
1160          if ( windowOpacity() > 0.0 && !b_fscHidden )
1161 #else
1162          if ( windowOpacity() > 0.0 )
1163 #endif
1164          {
1165              /* we should use 0.01 because of 100 pieces ^^^
1166                 but than it cannt be done in time */
1167              setWindowOpacity( windowOpacity() - 0.02 );
1168          }
1169
1170          if ( windowOpacity() <= 0.0 )
1171              p_slowHideTimer->stop();
1172     }
1173 #endif
1174 }
1175
1176 /**
1177  * event handling
1178  * events: show, hide, start timer for hidding
1179  */
1180 void FullscreenControllerWidget::customEvent( QEvent *event )
1181 {
1182     bool b_fs;
1183
1184     switch( event->type() )
1185     {
1186         case FullscreenControlToggle_Type:
1187             vlc_mutex_lock( &lock );
1188             b_fs = b_fullscreen;
1189             vlc_mutex_unlock( &lock );
1190             if( b_fs )
1191 #ifdef WIN32TRICK
1192                 if( b_fscHidden )
1193 #else
1194                 if( isHidden() )
1195 #endif
1196                 {
1197                     p_hideTimer->stop();
1198                     showFSC();
1199                 }
1200                 else
1201                     hideFSC();
1202             break;
1203         case FullscreenControlShow_Type:
1204             vlc_mutex_lock( &lock );
1205             b_fs = b_fullscreen;
1206             vlc_mutex_unlock( &lock );
1207
1208             if( b_fs )  // FIXME I am not sure about that one
1209                 showFSC();
1210             break;
1211         case FullscreenControlHide_Type:
1212             hideFSC();
1213             break;
1214         case FullscreenControlPlanHide_Type:
1215             if( !b_mouse_over ) // Only if the mouse is not over FSC
1216                 planHideFSC();
1217             break;
1218     }
1219 }
1220
1221 /**
1222  * On mouse move
1223  * moving with FSC
1224  */
1225 void FullscreenControllerWidget::mouseMoveEvent( QMouseEvent *event )
1226 {
1227     if ( event->buttons() == Qt::LeftButton )
1228     {
1229         int i_moveX = event->globalX() - i_mouse_last_x;
1230         int i_moveY = event->globalY() - i_mouse_last_y;
1231
1232         move( x() + i_moveX, y() + i_moveY );
1233
1234         i_mouse_last_x = event->globalX();
1235         i_mouse_last_y = event->globalY();
1236     }
1237 }
1238
1239 /**
1240  * On mouse press
1241  * store position of cursor
1242  */
1243 void FullscreenControllerWidget::mousePressEvent( QMouseEvent *event )
1244 {
1245     i_mouse_last_x = event->globalX();
1246     i_mouse_last_y = event->globalY();
1247 }
1248
1249 /**
1250  * On mouse go above FSC
1251  */
1252 void FullscreenControllerWidget::enterEvent( QEvent *event )
1253 {
1254     b_mouse_over = true;
1255
1256     p_hideTimer->stop();
1257 #if HAVE_TRANSPARENCY
1258     p_slowHideTimer->stop();
1259 #endif
1260 }
1261
1262 /**
1263  * On mouse go out from FSC
1264  */
1265 void FullscreenControllerWidget::leaveEvent( QEvent *event )
1266 {
1267     planHideFSC();
1268
1269     b_mouse_over = false;
1270 }
1271
1272 /**
1273  * When you get pressed key, send it to video output
1274  * FIXME: clearing focus by clearFocus() to not getting
1275  * key press events didnt work
1276  */
1277 void FullscreenControllerWidget::keyPressEvent( QKeyEvent *event )
1278 {
1279     int i_vlck = qtEventToVLCKey( event );
1280     if( i_vlck > 0 )
1281     {
1282         var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1283         event->accept();
1284     }
1285     else
1286         event->ignore();
1287 }
1288
1289 /* */
1290 static int FullscreenControllerWidgetFullscreenChanged( vlc_object_t *vlc_object, const char *variable,
1291                                                         vlc_value_t old_val, vlc_value_t new_val,
1292                                                         void *data )
1293 {
1294     vout_thread_t *p_vout = (vout_thread_t *) vlc_object;
1295     FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1296
1297     p_fs->fullscreenChanged( p_vout, new_val.b_bool, var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1298
1299     return VLC_SUCCESS;
1300 }
1301 /* */
1302 static int FullscreenControllerWidgetMouseMoved( vlc_object_t *vlc_object, const char *variable,
1303                                                  vlc_value_t old_val, vlc_value_t new_val,
1304                                                  void *data )
1305 {
1306     FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1307
1308     /* Show event */
1309     IMEvent *eShow = new IMEvent( FullscreenControlShow_Type, 0 );
1310     QApplication::postEvent( p_fs, static_cast<QEvent *>(eShow) );
1311
1312     /* Plan hide event */
1313     IMEvent *eHide = new IMEvent( FullscreenControlPlanHide_Type, 0 );
1314     QApplication::postEvent( p_fs, static_cast<QEvent *>(eHide) );
1315
1316     return VLC_SUCCESS;
1317 }
1318
1319
1320 /**
1321  * It is called when video start
1322  */
1323 void FullscreenControllerWidget::attachVout( vout_thread_t *p_nvout )
1324 {
1325     assert( p_nvout && !p_vout );
1326
1327     p_vout = p_nvout;
1328
1329     vlc_mutex_lock( &lock );
1330     var_AddCallback( p_vout, "fullscreen", FullscreenControllerWidgetFullscreenChanged, this ); /* I miss a add and fire */
1331     fullscreenChanged( p_vout, var_GetBool( p_vout, "fullscreen" ), var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1332     vlc_mutex_unlock( &lock );
1333 }
1334 /**
1335  * It is called after turn off video.
1336  */
1337 void FullscreenControllerWidget::detachVout()
1338 {
1339     if( p_vout )
1340     {
1341         var_DelCallback( p_vout, "fullscreen", FullscreenControllerWidgetFullscreenChanged, this );
1342         vlc_mutex_lock( &lock );
1343         fullscreenChanged( p_vout, false, 0 );
1344         vlc_mutex_unlock( &lock );
1345         p_vout = NULL;
1346     }
1347 }
1348
1349 /**
1350  * Register and unregister callback for mouse moving
1351  */
1352 void FullscreenControllerWidget::fullscreenChanged( vout_thread_t *p_vout, bool b_fs, int i_timeout )
1353 {
1354     vlc_mutex_lock( &lock );
1355     if( b_fs && !b_fullscreen )
1356     {
1357         b_fullscreen = true;
1358         i_hide_timeout = i_timeout;
1359         var_AddCallback( p_vout, "mouse-moved", FullscreenControllerWidgetMouseMoved, this );
1360     }
1361     else if( !b_fs && b_fullscreen )
1362     {
1363         b_fullscreen = false;
1364         i_hide_timeout = i_timeout;
1365         var_DelCallback( p_vout, "mouse-moved", FullscreenControllerWidgetMouseMoved, this );
1366
1367         /* Force fs hidding */
1368         IMEvent *eHide = new IMEvent( FullscreenControlHide_Type, 0 );
1369         QApplication::postEvent( this, static_cast<QEvent *>(eHide) );
1370     }
1371     vlc_mutex_unlock( &lock );
1372 }
1373
1374 /**********************************************************************
1375  * Speed control widget
1376  **********************************************************************/
1377 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
1378                              QFrame( NULL ), p_intf( _p_i )
1379 {
1380     QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
1381     sizePolicy.setHorizontalStretch( 0 );
1382     sizePolicy.setVerticalStretch( 0 );
1383
1384     speedSlider = new QSlider;
1385     speedSlider->setSizePolicy( sizePolicy );
1386     speedSlider->setMaximumSize( QSize( 80, 200 ) );
1387     speedSlider->setOrientation( Qt::Vertical );
1388     speedSlider->setTickPosition( QSlider::TicksRight );
1389
1390     speedSlider->setRange( -24, 24 );
1391     speedSlider->setSingleStep( 1 );
1392     speedSlider->setPageStep( 1 );
1393     speedSlider->setTickInterval( 12 );
1394
1395     CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
1396
1397     QToolButton *normalSpeedButton = new QToolButton( this );
1398     normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
1399     normalSpeedButton->setAutoRaise( true );
1400     normalSpeedButton->setText( "1x" );
1401     normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
1402
1403     CONNECT( normalSpeedButton, clicked(), this, resetRate() );
1404
1405     QVBoxLayout *speedControlLayout = new QVBoxLayout;
1406     speedControlLayout->setLayoutMargins( 4, 4, 4, 4, 4 );
1407     speedControlLayout->setSpacing( 4 );
1408     speedControlLayout->addWidget( speedSlider );
1409     speedControlLayout->addWidget( normalSpeedButton );
1410     setLayout( speedControlLayout );
1411 }
1412
1413 SpeedControlWidget::~SpeedControlWidget()
1414 {}
1415
1416 void SpeedControlWidget::setEnable( bool b_enable )
1417 {
1418     speedSlider->setEnabled( b_enable );
1419 }
1420
1421 void SpeedControlWidget::updateControls( int rate )
1422 {
1423     if( speedSlider->isSliderDown() )
1424     {
1425         //We don't want to change anything if the user is using the slider
1426         return;
1427     }
1428
1429     double value = 12 * log( (double)INPUT_RATE_DEFAULT / rate ) / log( 2 );
1430     int sliderValue = (int) ( ( value > 0 ) ? value + .5 : value - .5 );
1431
1432     if( sliderValue < speedSlider->minimum() )
1433     {
1434         sliderValue = speedSlider->minimum();
1435     }
1436     else if( sliderValue > speedSlider->maximum() )
1437     {
1438         sliderValue = speedSlider->maximum();
1439     }
1440
1441     //Block signals to avoid feedback loop
1442     speedSlider->blockSignals( true );
1443     speedSlider->setValue( sliderValue );
1444     speedSlider->blockSignals( false );
1445 }
1446
1447 void SpeedControlWidget::updateRate( int sliderValue )
1448 {
1449     double speed = pow( 2, (double)sliderValue / 12 );
1450     int rate = INPUT_RATE_DEFAULT / speed;
1451
1452     THEMIM->getIM()->setRate(rate);
1453 }
1454
1455 void SpeedControlWidget::resetRate()
1456 {
1457     THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);
1458 }
1459
1460
1461
1462 static int downloadCoverCallback( vlc_object_t *p_this,
1463                                   char const *psz_var,
1464                                   vlc_value_t oldvar, vlc_value_t newvar,
1465                                   void *data )
1466 {
1467     if( !strcmp( psz_var, "item-change" ) )
1468     {
1469         CoverArtLabel *art = static_cast< CoverArtLabel* >( data );
1470         if( art )
1471             art->requestUpdate();
1472     }
1473     return VLC_SUCCESS;
1474 }
1475
1476 CoverArtLabel::CoverArtLabel( QWidget *parent,
1477                               vlc_object_t *_p_this,
1478                               input_item_t *_p_input )
1479         : QLabel( parent ), p_this( _p_this), p_input( _p_input ), prevArt()
1480 {
1481     setContextMenuPolicy( Qt::ActionsContextMenu );
1482     CONNECT( this, updateRequested(), this, doUpdate() );
1483
1484     playlist_t *p_playlist = pl_Yield( p_this );
1485     var_AddCallback( p_playlist, "item-change",
1486                      downloadCoverCallback, this );
1487     pl_Release( p_this );
1488
1489     setMinimumHeight( 128 );
1490     setMinimumWidth( 128 );
1491     setMaximumHeight( 128 );
1492     setMaximumWidth( 128 );
1493     setScaledContents( true );
1494
1495     doUpdate();
1496 }
1497
1498 void CoverArtLabel::downloadCover()
1499 {
1500     if( p_input )
1501     {
1502         playlist_t *p_playlist = pl_Yield( p_this );
1503         playlist_AskForArtEnqueue( p_playlist, p_input );
1504         pl_Release( p_this );
1505     }
1506 }
1507
1508 void CoverArtLabel::doUpdate()
1509 {
1510     if( !p_input )
1511     {
1512         setPixmap( QPixmap( ":/noart.png" ) );
1513         QList< QAction* > artActions = actions();
1514         if( !artActions.isEmpty() )
1515             foreach( QAction *act, artActions )
1516                 removeAction( act );
1517         prevArt = "";
1518     }
1519     else
1520     {
1521         char *psz_meta = input_item_GetArtURL( p_input );
1522         if( psz_meta && !strncmp( psz_meta, "file://", 7 ) )
1523         {
1524             QString artUrl = qfu( psz_meta ).replace( "file://", "" );
1525             if( artUrl != prevArt )
1526                 setPixmap( QPixmap( artUrl ) );
1527             QList< QAction* > artActions = actions();
1528             if( !artActions.isEmpty() )
1529             {
1530                 foreach( QAction *act, artActions )
1531                     removeAction( act );
1532             }
1533             prevArt = artUrl;
1534         }
1535         else
1536         {
1537             if( prevArt != "" )
1538                 setPixmap( QPixmap( ":/noart.png" ) );
1539             prevArt = "";
1540             QList< QAction* > artActions = actions();
1541             if( artActions.isEmpty() )
1542             {
1543                 QAction *action = new QAction( qtr( "Download cover art" ),
1544                                                this );
1545                 addAction( action );
1546                 CONNECT( action, triggered(),
1547                          this, downloadCover() );
1548             }
1549         }
1550         free( psz_meta );
1551     }
1552 }
1553