]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/interface_widgets.cpp
Qt: Add a parent to the CoverArtLabel We should add parents to all QWidgets created...
[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     recordButton = new QPushButton;
354     setupSmallButton( recordButton );
355     advLayout->addWidget( recordButton );
356     BUTTON_SET_ACT_I( recordButton, "", record,
357             qtr( "Record" ), record() );
358
359     /* Snapshot Button */
360     snapshotButton = new QPushButton;
361     setupSmallButton( snapshotButton );
362     advLayout->addWidget( snapshotButton );
363     BUTTON_SET_ACT_I( snapshotButton, "", snapshot,
364             qtr( "Take a snapshot" ), snapshot() );
365 }
366
367 AdvControlsWidget::~AdvControlsWidget()
368 {}
369
370 void AdvControlsWidget::enableInput( bool enable )
371 {
372     int i_input_id = 0;
373     if( THEMIM->getInput() != NULL )
374     {
375         input_item_t *p_item = input_GetItem( THEMIM->getInput() );
376         i_input_id = p_item->i_id;
377
378         recordButton->setVisible( var_GetBool( THEMIM->getInput(), "can-record" ) );
379     }
380     else
381     {
382         recordButton->setVisible( false );
383     }
384
385     ABButton->setEnabled( enable );
386     recordButton->setEnabled( enable );
387
388     if( enable && ( i_last_input_id != i_input_id ) )
389     {
390         timeA = timeB = 0;
391         i_last_input_id = i_input_id;
392         emit timeChanged();
393     }
394 }
395
396 void AdvControlsWidget::enableVideo( bool enable )
397 {
398     snapshotButton->setEnabled( enable );
399 #if 0
400     frameButton->setEnabled( enable );
401 #endif
402 }
403
404 void AdvControlsWidget::snapshot()
405 {
406     vout_thread_t *p_vout =
407         (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
408     if( p_vout )
409     {
410         vout_Control( p_vout, VOUT_SNAPSHOT );
411         vlc_object_release( p_vout );
412     }
413 }
414
415 /* Function called when the button is clicked() */
416 void AdvControlsWidget::fromAtoB()
417 {
418     if( !timeA )
419     {
420         timeA = var_GetTime( THEMIM->getInput(), "time"  );
421         emit timeChanged();
422         return;
423     }
424     if( !timeB )
425     {
426         timeB = var_GetTime( THEMIM->getInput(), "time"  );
427         var_SetTime( THEMIM->getInput(), "time" , timeA );
428         emit timeChanged();
429         return;
430     }
431     timeA = 0;
432     timeB = 0;
433     emit timeChanged();
434 }
435
436 /* setting/synchro icons after click on main or fs controller */
437 void AdvControlsWidget::setIcon()
438 {
439     if( !timeA && !timeB)
440     {
441         ABButton->setIcon( QIcon( ":/atob_nob" ) );
442         ABButton->setToolTip( qtr( "Loop from point A to point B continuously\nClick to set point A" ) );
443     }
444     else if( timeA && !timeB )
445     {
446         ABButton->setIcon( QIcon( ":/atob_noa" ) );
447         ABButton->setToolTip( qtr( "Click to set point B" ) );
448     }
449     else if( timeA && timeB )
450     {
451         ABButton->setIcon( QIcon( ":/atob" ) );
452         ABButton->setToolTip( qtr( "Stop the A to B loop" ) );
453     }
454 }
455
456 /* Function called regularly when in an AtoB loop */
457 void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
458 {
459     if( timeB )
460     {
461         if( ( i_time >= (int)( timeB/1000000 ) )
462             || ( i_time < (int)( timeA/1000000 ) ) )
463             var_SetTime( THEMIM->getInput(), "time" , timeA );
464     }
465 }
466
467 void AdvControlsWidget::record()
468 {
469     input_thread_t *p_input = THEMIM->getInput();
470     if( p_input )
471     {
472         /* This method won't work fine if the stream can't be cut anywhere */
473         const bool b_recording = var_GetBool( p_input, "record" );
474         var_SetBool( p_input, "record", !b_recording );
475 #if 0
476         else
477         {
478             /* 'record' access-filter is not loaded, we open Save dialog */
479             input_item_t *p_item = input_GetItem( p_input );
480             if( !p_item )
481                 return;
482
483             char *psz = input_item_GetURI( p_item );
484             if( psz )
485                 THEDP->streamingDialog( NULL, psz, true );
486         }
487 #endif
488     }
489 }
490
491 #if 0
492 //FIXME Frame by frame function
493 void AdvControlsWidget::frame(){}
494 #endif
495
496 /*****************************
497  * DA Control Widget !
498  *****************************/
499 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
500                                 MainInterface *_p_mi,
501                                 bool b_advControls,
502                                 bool b_shiny,
503                                 bool b_fsCreation) :
504                                 QFrame( _p_mi ), p_intf( _p_i )
505 {
506     setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
507
508     /** The main Slider **/
509     slider = new InputSlider( Qt::Horizontal, NULL );
510     /* Update the position when the IM has changed */
511     CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
512              slider, setPosition( float, int, int ) );
513     /* And update the IM, when the position has changed */
514     CONNECT( slider, sliderDragged( float ),
515              THEMIM->getIM(), sliderUpdate( float ) );
516
517     /** Slower and faster Buttons **/
518     slowerButton = new QToolButton;
519     slowerButton->setAutoRaise( true );
520     slowerButton->setMaximumSize( QSize( 26, 20 ) );
521
522     BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
523
524     fasterButton = new QToolButton;
525     fasterButton->setAutoRaise( true );
526     fasterButton->setMaximumSize( QSize( 26, 20 ) );
527
528     BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
529
530     /* advanced Controls handling */
531     b_advancedVisible = b_advControls;
532
533     advControls = new AdvControlsWidget( p_intf, b_fsCreation );
534     if( !b_advancedVisible ) advControls->hide();
535
536     /** Disc and Menus handling */
537     discFrame = new QWidget( this );
538
539     QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
540     discLayout->setSpacing( 0 );
541     discLayout->setMargin( 0 );
542
543     prevSectionButton = new QPushButton( discFrame );
544     setupSmallButton( prevSectionButton );
545     discLayout->addWidget( prevSectionButton );
546
547     menuButton = new QPushButton( discFrame );
548     setupSmallButton( menuButton );
549     discLayout->addWidget( menuButton );
550
551     nextSectionButton = new QPushButton( discFrame );
552     setupSmallButton( nextSectionButton );
553     discLayout->addWidget( nextSectionButton );
554
555     BUTTON_SET_IMG( prevSectionButton, "", dvd_prev, "" );
556     BUTTON_SET_IMG( nextSectionButton, "", dvd_next, "" );
557     BUTTON_SET_IMG( menuButton, "", dvd_menu, qtr( "Menu" ) );
558
559     discFrame->hide();
560
561     /* Change the navigation button display when the IM navigation changes */
562     CONNECT( THEMIM->getIM(), navigationChanged( int ),
563              this, setNavigation( int ) );
564     /* Changes the IM navigation when triggered on the nav buttons */
565     CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
566              sectionPrev() );
567     CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
568              sectionNext() );
569     CONNECT( menuButton, clicked(), THEMIM->getIM(),
570              sectionMenu() );
571
572     /**
573      * Telextext QFrame
574      * TODO: Merge with upper menu in a StackLayout
575      **/
576     telexFrame = new QWidget( this );
577     QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
578     telexLayout->setSpacing( 0 );
579     telexLayout->setMargin( 0 );
580
581     telexOn = new QPushButton;
582     setupSmallButton( telexOn );
583     telexLayout->addWidget( telexOn );
584
585     telexTransparent = new QPushButton;
586     setupSmallButton( telexTransparent );
587     telexLayout->addWidget( telexTransparent );
588     b_telexTransparent = false;
589
590     telexPage = new QSpinBox;
591     telexPage->setRange( 0, 999 );
592     telexPage->setValue( 100 );
593     telexPage->setAccelerated( true );
594     telexPage->setWrapping( true );
595     telexPage->setAlignment( Qt::AlignRight );
596     telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
597     telexLayout->addWidget( telexPage );
598
599     telexFrame->hide(); /* default hidden */
600
601     CONNECT( telexPage, valueChanged( int ), THEMIM->getIM(),
602              telexGotoPage( int ) );
603     CONNECT( THEMIM->getIM(), setNewTelexPage( int ),
604               telexPage, setValue( int ) );
605
606     BUTTON_SET_IMG( telexOn, "", tv, qtr( "Teletext on" ) );
607
608     CONNECT( telexOn, clicked(), THEMIM->getIM(),
609              telexToggleButtons() );
610     CONNECT( telexOn, clicked( bool ), THEMIM->getIM(),
611              telexToggle( bool ) );
612     CONNECT( THEMIM->getIM(), toggleTelexButtons(),
613               this, toggleTeletext() );
614     b_telexEnabled = false;
615     telexTransparent->setEnabled( false );
616     telexPage->setEnabled( false );
617
618     BUTTON_SET_IMG( telexTransparent, "", tvtelx, qtr( "Teletext" ) );
619     CONNECT( telexTransparent, clicked( bool ),
620              THEMIM->getIM(), telexSetTransparency() );
621     CONNECT( THEMIM->getIM(), toggleTelexTransparency(),
622               this, toggleTeletextTransparency() );
623     CONNECT( THEMIM->getIM(), teletextEnabled( bool ),
624              this, enableTeletext( bool ) );
625
626     /** Play Buttons **/
627     QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
628     sizePolicy.setHorizontalStretch( 0 );
629     sizePolicy.setVerticalStretch( 0 );
630
631     /* Play */
632     playButton = new QPushButton;
633     playButton->setSizePolicy( sizePolicy );
634     playButton->setMaximumSize( QSize( 36, 36 ) );
635     playButton->setMinimumSize( QSize( 36, 36 ) );
636     playButton->setIconSize( QSize( 30, 30 ) );
637
638
639     /** Prev + Stop + Next Block **/
640     controlButLayout = new QHBoxLayout;
641     controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
642
643     /* Prev */
644     QPushButton *prevButton = new QPushButton;
645     prevButton->setSizePolicy( sizePolicy );
646     setupSmallButton( prevButton );
647
648     controlButLayout->addWidget( prevButton );
649
650     /* Stop */
651     QPushButton *stopButton = new QPushButton;
652     stopButton->setSizePolicy( sizePolicy );
653     setupSmallButton( stopButton );
654
655     controlButLayout->addWidget( stopButton );
656
657     /* next */
658     QPushButton *nextButton = new QPushButton;
659     nextButton->setSizePolicy( sizePolicy );
660     setupSmallButton( nextButton );
661
662     controlButLayout->addWidget( nextButton );
663
664     /* Add this block to the main layout */
665
666     BUTTON_SET_ACT_I( playButton, "", play_b, qtr( I_PLAY_TOOLTIP ), play() );
667     BUTTON_SET_ACT_I( prevButton, "" , previous_b,
668                       qtr( "Previous media in the playlist" ), prev() );
669     BUTTON_SET_ACT_I( nextButton, "", next_b,
670                       qtr( "Next media in the playlist" ), next() );
671     BUTTON_SET_ACT_I( stopButton, "", stop_b, qtr( "Stop playback" ), stop() );
672
673     /*
674      * Other first Line buttons
675      */
676     /* */
677     CONNECT( THEMIM->getIM(), voutChanged(bool), this, enableVideo(bool) );
678
679     /** Fullscreen/Visualisation **/
680     fullscreenButton = new QPushButton;
681     BUTTON_SET_ACT_I( fullscreenButton, "", fullscreen,
682             qtr( "Toggle the video in fullscreen" ), fullscreen() );
683     setupSmallButton( fullscreenButton );
684
685     if( !b_fsCreation )
686     {
687         /** Playlist Button **/
688         playlistButton = new QPushButton;
689         setupSmallButton( playlistButton );
690         BUTTON_SET_IMG( playlistButton, "" , playlist, qtr( "Show playlist" ) );
691         CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
692
693         /** extended Settings **/
694         extSettingsButton = new QPushButton;
695         BUTTON_SET_ACT_I( extSettingsButton, "", extended,
696                 qtr( "Show extended settings" ), extSettings() );
697         setupSmallButton( extSettingsButton );
698     }
699
700     /* Volume */
701     hVolLabel = new VolumeClickHandler( p_intf, this );
702
703     volMuteLabel = new QLabel;
704     volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
705     volMuteLabel->installEventFilter( hVolLabel );
706
707     if( b_shiny )
708     {
709         volumeSlider = new SoundSlider( this,
710             config_GetInt( p_intf, "volume-step" ),
711             config_GetInt( p_intf, "qt-volume-complete" ),
712             config_GetPsz( p_intf, "qt-slider-colours" ) );
713     }
714     else
715     {
716         volumeSlider = new QSlider( this );
717         volumeSlider->setOrientation( Qt::Horizontal );
718     }
719     volumeSlider->setMaximumSize( QSize( 200, 40 ) );
720     volumeSlider->setMinimumSize( QSize( 85, 30 ) );
721     volumeSlider->setFocusPolicy( Qt::NoFocus );
722
723     /* Set the volume from the config */
724     volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
725                               VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
726
727     /* Force the update at build time in order to have a muted icon if needed */
728     updateVolume( volumeSlider->value() );
729
730     /* Volume control connection */
731     CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
732     CONNECT( THEMIM, volumeChanged( void ), this, updateVolume( void ) );
733
734     if( !b_fsCreation )
735     {
736         controlLayout = new QGridLayout( this );
737
738         controlLayout->setSpacing( 0 );
739         controlLayout->setLayoutMargins( 7, 5, 7, 3, 6 );
740
741         controlLayout->addWidget( slider, 0, 1, 1, 18 );
742         controlLayout->addWidget( slowerButton, 0, 0 );
743         controlLayout->addWidget( fasterButton, 0, 19 );
744
745         controlLayout->addWidget( discFrame, 1, 8, 2, 3, Qt::AlignBottom );
746         controlLayout->addWidget( telexFrame, 1, 8, 2, 5, Qt::AlignBottom );
747
748         controlLayout->addWidget( playButton, 2, 0, 2, 2, Qt::AlignBottom );
749         controlLayout->setColumnMinimumWidth( 2, 10 );
750         controlLayout->setColumnStretch( 2, 0 );
751
752         controlLayout->addLayout( controlButLayout, 3, 3, 1, 3, Qt::AlignBottom );
753         /* Column 6 is unused */
754         controlLayout->setColumnStretch( 6, 0 );
755         controlLayout->setColumnStretch( 7, 0 );
756         controlLayout->setColumnMinimumWidth( 7, 10 );
757
758         controlLayout->addWidget( fullscreenButton, 3, 8, Qt::AlignBottom );
759         controlLayout->addWidget( playlistButton, 3, 9, Qt::AlignBottom );
760         controlLayout->addWidget( extSettingsButton, 3, 10, Qt::AlignBottom );
761         controlLayout->setColumnStretch( 11, 0 ); /* telex alignment */
762
763         controlLayout->setColumnStretch( 12, 0 );
764         controlLayout->setColumnMinimumWidth( 12, 10 );
765
766         controlLayout->addWidget( advControls, 3, 13, 1, 3, Qt::AlignBottom );
767
768         controlLayout->setColumnStretch( 16, 10 );
769         controlLayout->setColumnMinimumWidth( 16, 10 );
770
771         controlLayout->addWidget( volMuteLabel, 3, 17, Qt::AlignBottom );
772         controlLayout->addWidget( volumeSlider, 3, 18, 1 , 2, Qt::AlignBottom );
773     }
774
775     updateInput();
776 }
777
778 ControlsWidget::~ControlsWidget()
779 {}
780
781 void ControlsWidget::toggleTeletext()
782 {
783     bool b_enabled = THEMIM->teletextState();
784     if( b_telexEnabled )
785     {
786         telexTransparent->setEnabled( false );
787         telexPage->setEnabled( false );
788         b_telexEnabled = false;
789     }
790     else if( b_enabled )
791     {
792         telexTransparent->setEnabled( true );
793         telexPage->setEnabled( true );
794         b_telexEnabled = true;
795     }
796 }
797
798 void ControlsWidget::enableTeletext( bool b_enable )
799 {
800     telexFrame->setVisible( b_enable );
801     bool b_on = THEMIM->teletextState();
802
803     telexOn->setChecked( b_on );
804     telexTransparent->setEnabled( b_on );
805     telexPage->setEnabled( b_on );
806     b_telexEnabled = b_on;
807 }
808
809 void ControlsWidget::toggleTeletextTransparency()
810 {
811     if( b_telexTransparent )
812     {
813         telexTransparent->setIcon( QIcon( ":/tvtelx" ) );
814         telexTransparent->setToolTip( qtr( "Teletext" ) );
815         b_telexTransparent = false;
816     }
817     else
818     {
819         telexTransparent->setIcon( QIcon( ":/tvtelx-trans" ) );
820         telexTransparent->setToolTip( qtr( "Transparent" ) );
821         b_telexTransparent = true;
822     }
823 }
824
825 void ControlsWidget::stop()
826 {
827     THEMIM->stop();
828 }
829
830 void ControlsWidget::play()
831 {
832     if( THEPL->current.i_size == 0 )
833     {
834         /* The playlist is empty, open a file requester */
835         THEDP->openFileDialog();
836         setStatus( 0 );
837         return;
838     }
839     THEMIM->togglePlayPause();
840 }
841
842 void ControlsWidget::prev()
843 {
844     THEMIM->prev();
845 }
846
847 void ControlsWidget::next()
848 {
849     THEMIM->next();
850 }
851
852 void ControlsWidget::setNavigation( int navigation )
853 {
854 #define HELP_PCH N_( "Previous chapter" )
855 #define HELP_NCH N_( "Next chapter" )
856
857     // 1 = chapter, 2 = title, 0 = no
858     if( navigation == 0 )
859     {
860         discFrame->hide();
861     } else if( navigation == 1 ) {
862         prevSectionButton->setToolTip( qtr( HELP_PCH ) );
863         nextSectionButton->setToolTip( qtr( HELP_NCH ) );
864         menuButton->show();
865         discFrame->show();
866     } else {
867         prevSectionButton->setToolTip( qtr( HELP_PCH ) );
868         nextSectionButton->setToolTip( qtr( HELP_NCH ) );
869         menuButton->hide();
870         discFrame->show();
871     }
872 }
873
874 static bool b_my_volume;
875 void ControlsWidget::updateVolume( int i_sliderVolume )
876 {
877     if( !b_my_volume )
878     {
879         int i_res = i_sliderVolume  * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
880         aout_VolumeSet( p_intf, i_res );
881     }
882     if( i_sliderVolume == 0 )
883     {
884         volMuteLabel->setPixmap( QPixmap(":/volume-muted" ) );
885         volMuteLabel->setToolTip( qtr( "Unmute" ) );
886         return;
887     }
888
889     if( i_sliderVolume < VOLUME_MAX / 3 )
890         volMuteLabel->setPixmap( QPixmap( ":/volume-low" ) );
891     else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
892         volMuteLabel->setPixmap( QPixmap( ":/volume-high" ) );
893     else volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
894     volMuteLabel->setToolTip( qtr( "Mute" ) );
895 }
896
897 void ControlsWidget::updateVolume()
898 {
899     /* Audio part */
900     audio_volume_t i_volume;
901     aout_VolumeGet( p_intf, &i_volume );
902     i_volume = ( i_volume *  VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
903     int i_gauge = volumeSlider->value();
904     b_my_volume = false;
905     if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
906     {
907         b_my_volume = true;
908         volumeSlider->setValue( i_volume );
909         b_my_volume = false;
910     }
911 }
912
913 void ControlsWidget::updateInput()
914 {
915     /* Activate the interface buttons according to the presence of the input */
916     enableInput( THEMIM->getIM()->hasInput() );
917     enableVideo( THEMIM->getIM()->hasVideo() );
918 }
919
920 void ControlsWidget::setStatus( int status )
921 {
922     if( status == PLAYING_S ) /* Playing */
923     {
924         playButton->setIcon( QIcon( ":/pause_b" ) );
925         playButton->setToolTip( qtr( "Pause the playback" ) );
926     }
927     else
928     {
929         playButton->setIcon( QIcon( ":/play_b" ) );
930         playButton->setToolTip( qtr( I_PLAY_TOOLTIP ) );
931     }
932 }
933
934 /**
935  * TODO
936  * This functions toggle the fullscreen mode
937  * If there is no video, it should first activate Visualisations...
938  *  This has also to be fixed in enableVideo()
939  */
940 void ControlsWidget::fullscreen()
941 {
942     vout_thread_t *p_vout =
943         (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
944     if( p_vout)
945     {
946         var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
947         vlc_object_release( p_vout );
948     }
949 }
950
951 void ControlsWidget::extSettings()
952 {
953     THEDP->extendedDialog();
954 }
955
956 void ControlsWidget::slower()
957 {
958     THEMIM->getIM()->slower();
959 }
960
961 void ControlsWidget::faster()
962 {
963     THEMIM->getIM()->faster();
964 }
965
966 void ControlsWidget::enableInput( bool enable )
967 {
968     slowerButton->setEnabled( enable );
969     slider->setEnabled( enable );
970     slider->setSliderPosition ( 0 );
971     fasterButton->setEnabled( enable );
972
973     /* Advanced Buttons too */
974     advControls->enableInput( enable );
975 }
976
977 void ControlsWidget::enableVideo( bool enable )
978 {
979     // TODO Later make the fullscreenButton toggle Visualisation and so on.
980     fullscreenButton->setEnabled( enable );
981
982     /* Advanced Buttons too */
983     advControls->enableVideo( enable );
984 }
985
986 void ControlsWidget::toggleAdvanced()
987 {
988     if( advControls && !b_advancedVisible )
989     {
990         advControls->show();
991         b_advancedVisible = true;
992     }
993     else
994     {
995         advControls->hide();
996         b_advancedVisible = false;
997     }
998     emit advancedControlsToggled( b_advancedVisible );
999 }
1000
1001 /**********************************************************************
1002  * Fullscrenn control widget
1003  **********************************************************************/
1004 FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i,
1005         MainInterface *_p_mi, bool b_advControls, bool b_shiny )
1006         : ControlsWidget( _p_i, _p_mi, b_advControls, b_shiny, true ),
1007           i_mouse_last_x( -1 ), i_mouse_last_y( -1 ), b_mouse_over(false),
1008           b_slow_hide_begin(false), i_slow_hide_timeout(1),
1009           b_fullscreen( false ), i_hide_timeout( 1 ), p_vout(NULL)
1010 {
1011     setWindowFlags( Qt::ToolTip );
1012
1013     setFrameShape( QFrame::StyledPanel );
1014     setFrameStyle( QFrame::Sunken );
1015     setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
1016
1017     QGridLayout *fsLayout = new QGridLayout( this );
1018     fsLayout->setLayoutMargins( 5, 2, 5, 2, 5 );
1019
1020     /* First line */
1021     slider->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum);
1022     slider->setMinimumWidth( 220 );
1023     fsLayout->addWidget( slowerButton, 0, 0 );
1024     fsLayout->addWidget( slider, 0, 1, 1, 9 );
1025     fsLayout->addWidget( fasterButton, 0, 10 );
1026
1027     fsLayout->addWidget( playButton, 1, 0, 1, 2 );
1028     fsLayout->addLayout( controlButLayout, 1, 2 );
1029
1030     fsLayout->addWidget( discFrame, 1, 3 );
1031     fsLayout->addWidget( telexFrame, 1, 4 );
1032     fsLayout->addWidget( fullscreenButton, 1, 5 );
1033     fsLayout->addWidget( advControls, 1, 6, Qt::AlignVCenter );
1034
1035     fsLayout->setColumnStretch( 7, 10 );
1036     fsLayout->addWidget( volMuteLabel, 1, 8 );
1037     fsLayout->addWidget( volumeSlider, 1, 9, 1, 2 );
1038
1039     /* hiding timer */
1040     p_hideTimer = new QTimer( this );
1041     CONNECT( p_hideTimer, timeout(), this, hideFSC() );
1042     p_hideTimer->setSingleShot( true );
1043
1044     /* slow hiding timer */
1045 #if HAVE_TRANSPARENCY
1046     p_slowHideTimer = new QTimer( this );
1047     CONNECT( p_slowHideTimer, timeout(), this, slowHideFSC() );
1048 #endif
1049
1050     adjustSize ();  /* need to get real width and height for moving */
1051
1052     /* center down */
1053     QDesktopWidget * p_desktop = QApplication::desktop();
1054
1055     move( p_desktop->width() / 2 - width() / 2,
1056           p_desktop->height() - height() );
1057
1058 #ifdef WIN32TRICK
1059     setWindowOpacity( 0.0 );
1060     b_fscHidden = true;
1061     adjustSize();
1062     show();
1063 #endif
1064
1065     fullscreenButton->setIcon( QIcon( ":/defullscreen" ) );
1066
1067     vlc_mutex_init_recursive( &lock );
1068 }
1069
1070 FullscreenControllerWidget::~FullscreenControllerWidget()
1071 {
1072     detachVout();
1073     vlc_mutex_destroy( &lock );
1074 }
1075
1076 /**
1077  * Show fullscreen controller
1078  */
1079 void FullscreenControllerWidget::showFSC()
1080 {
1081     adjustSize();
1082 #ifdef WIN32TRICK
1083     // after quiting and going to fs, we need to call show()
1084     if( isHidden() )
1085         show();
1086
1087     if( b_fscHidden )
1088     {
1089         b_fscHidden = false;
1090         setWindowOpacity( 1.0 );
1091     }
1092 #else
1093     show();
1094 #endif
1095
1096 #if HAVE_TRANSPARENCY
1097     setWindowOpacity( DEFAULT_OPACITY );
1098 #endif
1099 }
1100
1101 /**
1102  * Hide fullscreen controller
1103  * FIXME: under windows it have to be done by moving out of screen
1104  *        because hide() doesnt work
1105  */
1106 void FullscreenControllerWidget::hideFSC()
1107 {
1108 #ifdef WIN32TRICK
1109     b_fscHidden = true;
1110     setWindowOpacity( 0.0 );    // simulate hidding
1111 #else
1112     hide();
1113 #endif
1114 }
1115
1116 /**
1117  * Plane to hide fullscreen controller
1118  */
1119 void FullscreenControllerWidget::planHideFSC()
1120 {
1121     vlc_mutex_lock( &lock );
1122     int i_timeout = i_hide_timeout;
1123     vlc_mutex_unlock( &lock );
1124
1125     p_hideTimer->start( i_timeout );
1126
1127 #if HAVE_TRANSPARENCY
1128     b_slow_hide_begin = true;
1129     i_slow_hide_timeout = i_timeout;
1130     p_slowHideTimer->start( i_slow_hide_timeout / 2 );
1131 #endif
1132 }
1133
1134 /**
1135  * Hidding fullscreen controller slowly
1136  * Linux: need composite manager
1137  * Windows: it is blinking, so it can be enabled by define TRASPARENCY
1138  */
1139 void FullscreenControllerWidget::slowHideFSC()
1140 {
1141 #if HAVE_TRANSPARENCY
1142     if( b_slow_hide_begin )
1143     {
1144         b_slow_hide_begin = false;
1145
1146         p_slowHideTimer->stop();
1147         /* the last part of time divided to 100 pieces */
1148         p_slowHideTimer->start( (int)( i_slow_hide_timeout / 2 / ( windowOpacity() * 100 ) ) );
1149
1150     }
1151     else
1152     {
1153 #ifdef WIN32TRICK
1154          if ( windowOpacity() > 0.0 && !b_fscHidden )
1155 #else
1156          if ( windowOpacity() > 0.0 )
1157 #endif
1158          {
1159              /* we should use 0.01 because of 100 pieces ^^^
1160                 but than it cannt be done in time */
1161              setWindowOpacity( windowOpacity() - 0.02 );
1162          }
1163
1164          if ( windowOpacity() <= 0.0 )
1165              p_slowHideTimer->stop();
1166     }
1167 #endif
1168 }
1169
1170 /**
1171  * event handling
1172  * events: show, hide, start timer for hidding
1173  */
1174 void FullscreenControllerWidget::customEvent( QEvent *event )
1175 {
1176     bool b_fs;
1177
1178     switch( event->type() )
1179     {
1180         case FullscreenControlToggle_Type:
1181             vlc_mutex_lock( &lock );
1182             b_fs = b_fullscreen;
1183             vlc_mutex_unlock( &lock );
1184             if( b_fs )
1185 #ifdef WIN32TRICK
1186                 if( b_fscHidden )
1187 #else
1188                 if( isHidden() )
1189 #endif
1190                 {
1191                     p_hideTimer->stop();
1192                     showFSC();
1193                 }
1194                 else
1195                     hideFSC();
1196             break;
1197         case FullscreenControlShow_Type:
1198             vlc_mutex_lock( &lock );
1199             b_fs = b_fullscreen;
1200             vlc_mutex_unlock( &lock );
1201
1202             if( b_fs )  // FIXME I am not sure about that one
1203                 showFSC();
1204             break;
1205         case FullscreenControlHide_Type:
1206             hideFSC();
1207             break;
1208         case FullscreenControlPlanHide_Type:
1209             if( !b_mouse_over ) // Only if the mouse is not over FSC
1210                 planHideFSC();
1211             break;
1212     }
1213 }
1214
1215 /**
1216  * On mouse move
1217  * moving with FSC
1218  */
1219 void FullscreenControllerWidget::mouseMoveEvent( QMouseEvent *event )
1220 {
1221     if ( event->buttons() == Qt::LeftButton )
1222     {
1223         int i_moveX = event->globalX() - i_mouse_last_x;
1224         int i_moveY = event->globalY() - i_mouse_last_y;
1225
1226         move( x() + i_moveX, y() + i_moveY );
1227
1228         i_mouse_last_x = event->globalX();
1229         i_mouse_last_y = event->globalY();
1230     }
1231 }
1232
1233 /**
1234  * On mouse press
1235  * store position of cursor
1236  */
1237 void FullscreenControllerWidget::mousePressEvent( QMouseEvent *event )
1238 {
1239     i_mouse_last_x = event->globalX();
1240     i_mouse_last_y = event->globalY();
1241 }
1242
1243 /**
1244  * On mouse go above FSC
1245  */
1246 void FullscreenControllerWidget::enterEvent( QEvent *event )
1247 {
1248     b_mouse_over = true;
1249
1250     p_hideTimer->stop();
1251 #if HAVE_TRANSPARENCY
1252     p_slowHideTimer->stop();
1253 #endif
1254 }
1255
1256 /**
1257  * On mouse go out from FSC
1258  */
1259 void FullscreenControllerWidget::leaveEvent( QEvent *event )
1260 {
1261     planHideFSC();
1262
1263     b_mouse_over = false;
1264 }
1265
1266 /**
1267  * When you get pressed key, send it to video output
1268  * FIXME: clearing focus by clearFocus() to not getting
1269  * key press events didnt work
1270  */
1271 void FullscreenControllerWidget::keyPressEvent( QKeyEvent *event )
1272 {
1273     int i_vlck = qtEventToVLCKey( event );
1274     if( i_vlck > 0 )
1275     {
1276         var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1277         event->accept();
1278     }
1279     else
1280         event->ignore();
1281 }
1282
1283 /* */
1284 static int FullscreenControllerWidgetFullscreenChanged( vlc_object_t *vlc_object, const char *variable,
1285                                                         vlc_value_t old_val, vlc_value_t new_val,
1286                                                         void *data )
1287 {
1288     vout_thread_t *p_vout = (vout_thread_t *) vlc_object;
1289     FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1290
1291     p_fs->fullscreenChanged( p_vout, new_val.b_bool, var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1292
1293     return VLC_SUCCESS;
1294 }
1295 /* */
1296 static int FullscreenControllerWidgetMouseMoved( vlc_object_t *vlc_object, const char *variable,
1297                                                  vlc_value_t old_val, vlc_value_t new_val,
1298                                                  void *data )
1299 {
1300     FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1301
1302     /* Show event */
1303     IMEvent *eShow = new IMEvent( FullscreenControlShow_Type, 0 );
1304     QApplication::postEvent( p_fs, static_cast<QEvent *>(eShow) );
1305
1306     /* Plan hide event */
1307     IMEvent *eHide = new IMEvent( FullscreenControlPlanHide_Type, 0 );
1308     QApplication::postEvent( p_fs, static_cast<QEvent *>(eHide) );
1309
1310     return VLC_SUCCESS;
1311 }
1312
1313
1314 /**
1315  * It is called when video start
1316  */
1317 void FullscreenControllerWidget::attachVout( vout_thread_t *p_nvout )
1318 {
1319     assert( p_nvout && !p_vout );
1320
1321     p_vout = p_nvout;
1322
1323     vlc_mutex_lock( &lock );
1324     var_AddCallback( p_vout, "fullscreen", FullscreenControllerWidgetFullscreenChanged, this ); /* I miss a add and fire */
1325     fullscreenChanged( p_vout, var_GetBool( p_vout, "fullscreen" ), var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1326     vlc_mutex_unlock( &lock );
1327 }
1328 /**
1329  * It is called after turn off video.
1330  */
1331 void FullscreenControllerWidget::detachVout()
1332 {
1333     if( p_vout )
1334     {
1335         var_DelCallback( p_vout, "fullscreen", FullscreenControllerWidgetFullscreenChanged, this );
1336         vlc_mutex_lock( &lock );
1337         fullscreenChanged( p_vout, false, 0 );
1338         vlc_mutex_unlock( &lock );
1339         p_vout = NULL;
1340     }
1341 }
1342
1343 /**
1344  * Register and unregister callback for mouse moving
1345  */
1346 void FullscreenControllerWidget::fullscreenChanged( vout_thread_t *p_vout, bool b_fs, int i_timeout )
1347 {
1348     vlc_mutex_lock( &lock );
1349     if( b_fs && !b_fullscreen )
1350     {
1351         b_fullscreen = true;
1352         i_hide_timeout = i_timeout;
1353         var_AddCallback( p_vout, "mouse-moved", FullscreenControllerWidgetMouseMoved, this );
1354     }
1355     else if( !b_fs && b_fullscreen )
1356     {
1357         b_fullscreen = false;
1358         i_hide_timeout = i_timeout;
1359         var_DelCallback( p_vout, "mouse-moved", FullscreenControllerWidgetMouseMoved, this );
1360
1361         /* Force fs hidding */
1362         IMEvent *eHide = new IMEvent( FullscreenControlHide_Type, 0 );
1363         QApplication::postEvent( this, static_cast<QEvent *>(eHide) );
1364     }
1365     vlc_mutex_unlock( &lock );
1366 }
1367
1368 /**********************************************************************
1369  * Speed control widget
1370  **********************************************************************/
1371 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
1372                              QFrame( NULL ), p_intf( _p_i )
1373 {
1374     QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
1375     sizePolicy.setHorizontalStretch( 0 );
1376     sizePolicy.setVerticalStretch( 0 );
1377
1378     speedSlider = new QSlider;
1379     speedSlider->setSizePolicy( sizePolicy );
1380     speedSlider->setMaximumSize( QSize( 80, 200 ) );
1381     speedSlider->setOrientation( Qt::Vertical );
1382     speedSlider->setTickPosition( QSlider::TicksRight );
1383
1384     speedSlider->setRange( -24, 24 );
1385     speedSlider->setSingleStep( 1 );
1386     speedSlider->setPageStep( 1 );
1387     speedSlider->setTickInterval( 12 );
1388
1389     CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
1390
1391     QToolButton *normalSpeedButton = new QToolButton( this );
1392     normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
1393     normalSpeedButton->setAutoRaise( true );
1394     normalSpeedButton->setText( "1x" );
1395     normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
1396
1397     CONNECT( normalSpeedButton, clicked(), this, resetRate() );
1398
1399     QVBoxLayout *speedControlLayout = new QVBoxLayout;
1400     speedControlLayout->setLayoutMargins( 4, 4, 4, 4, 4 );
1401     speedControlLayout->setSpacing( 4 );
1402     speedControlLayout->addWidget( speedSlider );
1403     speedControlLayout->addWidget( normalSpeedButton );
1404     setLayout( speedControlLayout );
1405 }
1406
1407 SpeedControlWidget::~SpeedControlWidget()
1408 {}
1409
1410 void SpeedControlWidget::setEnable( bool b_enable )
1411 {
1412     speedSlider->setEnabled( b_enable );
1413 }
1414
1415 void SpeedControlWidget::updateControls( int rate )
1416 {
1417     if( speedSlider->isSliderDown() )
1418     {
1419         //We don't want to change anything if the user is using the slider
1420         return;
1421     }
1422
1423     double value = 12 * log( (double)INPUT_RATE_DEFAULT / rate ) / log( 2 );
1424     int sliderValue = (int) ( ( value > 0 ) ? value + .5 : value - .5 );
1425
1426     if( sliderValue < speedSlider->minimum() )
1427     {
1428         sliderValue = speedSlider->minimum();
1429     }
1430     else if( sliderValue > speedSlider->maximum() )
1431     {
1432         sliderValue = speedSlider->maximum();
1433     }
1434
1435     //Block signals to avoid feedback loop
1436     speedSlider->blockSignals( true );
1437     speedSlider->setValue( sliderValue );
1438     speedSlider->blockSignals( false );
1439 }
1440
1441 void SpeedControlWidget::updateRate( int sliderValue )
1442 {
1443     double speed = pow( 2, (double)sliderValue / 12 );
1444     int rate = INPUT_RATE_DEFAULT / speed;
1445
1446     THEMIM->getIM()->setRate(rate);
1447 }
1448
1449 void SpeedControlWidget::resetRate()
1450 {
1451     THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);
1452 }
1453
1454
1455
1456 static int downloadCoverCallback( vlc_object_t *p_this,
1457                                   char const *psz_var,
1458                                   vlc_value_t oldvar, vlc_value_t newvar,
1459                                   void *data )
1460 {
1461     if( !strcmp( psz_var, "item-change" ) )
1462     {
1463         CoverArtLabel *art = static_cast< CoverArtLabel* >( data );
1464         if( art )
1465             art->requestUpdate();
1466     }
1467     return VLC_SUCCESS;
1468 }
1469
1470 CoverArtLabel::CoverArtLabel( QWidget *parent,
1471                               vlc_object_t *_p_this,
1472                               input_item_t *_p_input )
1473         : QLabel( parent ), p_this( _p_this), p_input( _p_input ), prevArt()
1474 {
1475     setContextMenuPolicy( Qt::ActionsContextMenu );
1476     CONNECT( this, updateRequested(), this, doUpdate() );
1477
1478     playlist_t *p_playlist = pl_Yield( p_this );
1479     var_AddCallback( p_playlist, "item-change",
1480                      downloadCoverCallback, this );
1481     pl_Release( p_this );
1482
1483     setMinimumHeight( 128 );
1484     setMinimumWidth( 128 );
1485     setMaximumHeight( 128 );
1486     setMaximumWidth( 128 );
1487     setScaledContents( true );
1488
1489     doUpdate();
1490 }
1491
1492 void CoverArtLabel::downloadCover()
1493 {
1494     if( p_input )
1495     {
1496         playlist_t *p_playlist = pl_Yield( p_this );
1497         playlist_AskForArtEnqueue( p_playlist, p_input );
1498         pl_Release( p_this );
1499     }
1500 }
1501
1502 void CoverArtLabel::doUpdate()
1503 {
1504     if( !p_input )
1505     {
1506         setPixmap( QPixmap( ":/noart.png" ) );
1507         QList< QAction* > artActions = actions();
1508         if( !artActions.isEmpty() )
1509             foreach( QAction *act, artActions )
1510                 removeAction( act );
1511         prevArt = "";
1512     }
1513     else
1514     {
1515         char *psz_meta = input_item_GetArtURL( p_input );
1516         if( psz_meta && !strncmp( psz_meta, "file://", 7 ) )
1517         {
1518             QString artUrl = qfu( psz_meta ).replace( "file://", "" );
1519             if( artUrl != prevArt )
1520                 setPixmap( QPixmap( artUrl ) );
1521             QList< QAction* > artActions = actions();
1522             if( !artActions.isEmpty() )
1523             {
1524                 foreach( QAction *act, artActions )
1525                     removeAction( act );
1526             }
1527             prevArt = artUrl;
1528         }
1529         else
1530         {
1531             if( prevArt != "" )
1532                 setPixmap( QPixmap( ":/noart.png" ) );
1533             prevArt = "";
1534             QList< QAction* > artActions = actions();
1535             if( artActions.isEmpty() )
1536             {
1537                 QAction *action = new QAction( qtr( "Download cover art" ),
1538                                                this );
1539                 addAction( action );
1540                 CONNECT( action, triggered(),
1541                          this, downloadCover() );
1542             }
1543         }
1544         free( psz_meta );
1545     }
1546 }
1547