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