]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/controller.cpp
[Qt] use screenGeometry instead of screen.
[vlc] / modules / gui / qt4 / components / controller.cpp
1 /*****************************************************************************
2  * Controller.cpp : Controller for the main interface
3  ****************************************************************************
4  * Copyright ( C ) 2006-2008 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 <QToolButton>
45 #include <QToolButton>
46 #include <QHBoxLayout>
47 #include <QMenu>
48 #include <QPalette>
49 #include <QResizeEvent>
50 #include <QDate>
51 #include <QSignalMapper>
52
53 #define I_PLAY_TOOLTIP N_("Play\nIf the playlist is empty, open a media")
54
55 /**********************************************************************
56  * TEH controls
57  **********************************************************************/
58
59 /******
60   * This is an abstract Toolbar/Controller
61   * This has helper to create any toolbar, any buttons and to manage the actions
62   *
63   *****/
64 AbstractController::AbstractController( intf_thread_t * _p_i ) : QFrame( NULL )
65 {
66     p_intf = _p_i;
67
68     /* We need one layout. An controller without layout is stupid with 
69        current architecture */
70     controlLayout = new QGridLayout( this );
71
72     /* Main action provider */
73     toolbarActionsMapper = new QSignalMapper();
74     CONNECT( toolbarActionsMapper, mapped( int ),
75              this, doAction( int ) );
76     CONNECT( THEMIM->getIM(), statusChanged( int ), this, setStatus( int ) );
77 }
78
79 void AbstractController::setStatus( int status )
80 {
81     bool b_hasInput = THEMIM->getIM()->hasInput();
82     /* Activate the interface buttons according to the presence of the input */
83     emit inputExists( b_hasInput );
84
85     emit inputPlaying( status == PLAYING_S );
86
87     emit inputIsRecordable( b_hasInput &&
88                             var_GetBool( THEMIM->getInput(), "can-record" ) );
89 }
90
91 void AbstractController::setupButton( QAbstractButton *aButton )
92 {
93     static QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
94     sizePolicy.setHorizontalStretch( 0 );
95     sizePolicy.setVerticalStretch( 0 );
96
97     aButton->setSizePolicy( sizePolicy );
98     aButton->setFixedSize( QSize( 26, 26 ) );
99     aButton->setIconSize( QSize( 20, 20 ) );
100     aButton->setFocusPolicy( Qt::NoFocus );
101 }
102
103 #define CONNECT_MAP( a ) CONNECT( a, clicked(),  toolbarActionsMapper, map() )
104 #define SET_MAPPING( a, b ) toolbarActionsMapper->setMapping( a , b )
105 #define CONNECT_MAP_SET( a, b ) \
106     CONNECT_MAP( a ); \
107     SET_MAPPING( a, b );
108 #define BUTTON_SET_BAR( button, image, tooltip ) \
109     button->setToolTip( tooltip );          \
110     button->setIcon( QIcon( ":/"#image ) );
111
112 #define ENABLE_ON_VIDEO( a ) \
113     CONNECT( THEMIM->getIM(), voutChanged( bool ), a, setEnabled( bool ) ); \
114     a->setEnabled( THEMIM->getIM()->hasVideo() ); /* TODO: is this necessary? when input is started before the interface? */
115
116 #define ENABLE_ON_INPUT( a ) \
117     CONNECT( this, inputExists( bool ), a, setEnabled( bool ) ); \
118     a->setEnabled( THEMIM->getIM()->hasInput() ); /* TODO: is this necessary? when input is started before the interface? */
119
120 QWidget *AbstractController::createWidget( buttonType_e button, bool b_flat,
121         bool b_big, bool b_shiny )
122 {
123     QWidget *widget = NULL;
124     switch( button )
125     {
126     case PLAY_BUTTON: {
127         PlayButton *playButton = new PlayButton;
128         setupButton( playButton );
129         BUTTON_SET_BAR( playButton, play_b, qtr( I_PLAY_TOOLTIP ) );
130         CONNECT_MAP_SET( playButton, PLAY_ACTION );
131         CONNECT( this, inputPlaying( bool ),
132                  playButton, updateButton( bool ));
133         widget = playButton;
134         }
135         break;
136     case STOP_BUTTON:{
137         QToolButton *stopButton = new QToolButton;
138         setupButton( stopButton );
139         CONNECT_MAP_SET( stopButton, STOP_ACTION );
140         BUTTON_SET_BAR( stopButton, stop_b, qtr( "Stop playback" ) );
141         widget = stopButton;
142         }
143         break;
144     case PREVIOUS_BUTTON:{
145         QToolButton *prevButton = new QToolButton;
146         setupButton( prevButton );
147         CONNECT_MAP_SET( prevButton, PREVIOUS_ACTION );
148         BUTTON_SET_BAR( prevButton, previous_b,
149                   qtr( "Previous media in the playlist" ) );
150         widget = prevButton;
151         }
152         break;
153     case NEXT_BUTTON:
154         {
155         QToolButton *nextButton = new QToolButton;
156         setupButton( nextButton );
157         CONNECT_MAP_SET( nextButton, NEXT_ACTION );
158         BUTTON_SET_BAR( nextButton, next_b,
159                 qtr( "Next media in the playlist" ) );
160         widget = nextButton;
161         }
162         break;
163     case SLOWER_BUTTON:{
164         QToolButton *slowerButton = new QToolButton;
165         setupButton( slowerButton );
166         CONNECT_MAP_SET( slowerButton, SLOWER_ACTION );
167         BUTTON_SET_BAR( slowerButton, slower, qtr( "Slower" ) );
168         ENABLE_ON_INPUT( slowerButton );
169         widget = slowerButton;
170         }
171         break;
172     case FASTER_BUTTON:{
173         QToolButton *fasterButton = new QToolButton;
174         setupButton( fasterButton );
175         CONNECT_MAP_SET( fasterButton, SLOWER_ACTION );
176         BUTTON_SET_BAR( fasterButton, faster, qtr( "Faster" ) );
177         ENABLE_ON_INPUT( fasterButton );
178         widget = fasterButton;
179         }
180         break;
181 #if 0
182     case FRAME_BUTTON: {
183         QToolButton *frameButton = new QToolButton( "Fr" );
184         setupButton( frameButton );
185         BUTTON_SET_BAR( frameButton, "", qtr( "Frame by frame" ) );
186         ENABLE_ON_INPUT( frameButton );
187         widget = frameButton;
188         }
189         break;
190 #endif
191     case FULLSCREEN_BUTTON:{
192         QToolButton *fullscreenButton = new QToolButton;
193         setupButton( fullscreenButton );
194         CONNECT_MAP_SET( fullscreenButton, FULLSCREEN_ACTION );
195         BUTTON_SET_BAR( fullscreenButton, fullscreen,
196                 qtr( "Toggle the video in fullscreen" ) );
197         ENABLE_ON_VIDEO( fullscreenButton );
198         widget = fullscreenButton;
199         }
200         break;
201     case EXTENDED_BUTTON:{
202         QToolButton *extSettingsButton = new QToolButton;
203         setupButton( extSettingsButton );
204         CONNECT_MAP_SET( extSettingsButton, EXTENDED_ACTION );
205         BUTTON_SET_BAR( extSettingsButton, extended,
206                 qtr( "Show extended settings" ) );
207         widget = extSettingsButton;
208         }
209         break;
210     case PLAYLIST_BUTTON:{
211         QToolButton *playlistButton = new QToolButton;
212         setupButton( playlistButton );
213         CONNECT_MAP_SET( playlistButton, PLAYLIST_ACTION );
214         BUTTON_SET_BAR( playlistButton, playlist,
215                 qtr( "Show playlist" ) );
216         widget = playlistButton;
217         }
218         break;
219     case SNAPSHOT_BUTTON:{
220         QToolButton *snapshotButton = new QToolButton;
221         setupButton( snapshotButton );
222         CONNECT_MAP_SET( snapshotButton, SNAPSHOT_ACTION );
223         BUTTON_SET_BAR( snapshotButton, snapshot, qtr( "Take a snapshot" ) );
224         ENABLE_ON_VIDEO( snapshotButton );
225         widget = snapshotButton;
226         }
227         break;
228     case RECORD_BUTTON:{
229         QToolButton *recordButton = new QToolButton;
230         setupButton( recordButton );
231         CONNECT_MAP_SET( recordButton, RECORD_ACTION );
232         BUTTON_SET_BAR( recordButton, record, qtr( "Record" ) );
233         ENABLE_ON_INPUT( recordButton );
234         widget = recordButton;
235         }
236         break;
237     case ATOB_BUTTON: {
238         AtoB_Button *ABButton = new AtoB_Button;
239         setupButton( ABButton );
240         BUTTON_SET_BAR( ABButton, atob_nob, qtr( "Loop from point A to point "
241                     "B continuously.\nClick to set point A" ) );
242         ENABLE_ON_INPUT( ABButton );
243         CONNECT_MAP_SET( ABButton, ATOB_ACTION );
244         CONNECT( THEMIM->getIM(), AtoBchanged( bool, bool),
245                  ABButton, setIcons( bool, bool ) );
246         widget = ABButton;
247         }
248         break;
249     case INPUT_SLIDER: {
250         InputSlider *slider = new InputSlider( Qt::Horizontal, NULL );
251         /* Update the position when the IM has changed */
252         CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
253                 slider, setPosition( float, int, int ) );
254         /* And update the IM, when the position has changed */
255         CONNECT( slider, sliderDragged( float ),
256                 THEMIM->getIM(), sliderUpdate( float ) );
257         widget = slider;
258         }
259         break;
260     case MENU_BUTTONS:
261         widget = discFrame();
262         widget->hide();
263         break;
264     case TELETEXT_BUTTONS:
265         widget = telexFrame();
266         widget->hide();
267         break;
268     case VOLUME:
269         {
270             SoundWidget *snd = new SoundWidget( p_intf, b_shiny );
271             widget = snd;
272         }
273         break;
274     default:
275         msg_Warn( p_intf, "This should not happen" );
276         break;
277     }
278
279     /* Customize Buttons */
280     if( b_flat || b_big )
281     {
282         QToolButton *tmpButton = qobject_cast<QToolButton *>(widget);
283         if( tmpButton )
284         {
285             if( b_flat )
286                 tmpButton->setAutoRaise( b_flat );
287             if( b_big )
288             {
289                 tmpButton->setFixedSize( QSize( 32, 32 ) );
290                 tmpButton->setIconSize( QSize( 26, 26 ) );
291             }
292         }
293     }
294     return widget;
295 }
296
297 QWidget *AbstractController::discFrame()
298 {
299     /** Disc and Menus handling */
300     QWidget *discFrame = new QWidget( this );
301
302     QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
303     discLayout->setSpacing( 0 ); discLayout->setMargin( 0 );
304
305     QToolButton *prevSectionButton = new QToolButton( discFrame );
306     setupButton( prevSectionButton );
307     BUTTON_SET_BAR( prevSectionButton, dvd_prev,
308             qtr("Previous Chapter/Title" ) );
309     discLayout->addWidget( prevSectionButton );
310
311     QToolButton *menuButton = new QToolButton( discFrame );
312     setupButton( menuButton );
313     discLayout->addWidget( menuButton );
314     BUTTON_SET_BAR( menuButton, dvd_menu, qtr( "Menu" ) );
315
316     QToolButton *nextSectionButton = new QToolButton( discFrame );
317     setupButton( nextSectionButton );
318     discLayout->addWidget( nextSectionButton );
319     BUTTON_SET_BAR( nextSectionButton, dvd_next,
320             qtr("Next Chapter/Title" ) );
321
322
323     /* Change the navigation button display when the IM
324        navigation changes */
325     CONNECT( THEMIM->getIM(), titleChanged( bool ),
326             discFrame, setVisible( bool ) );
327     CONNECT( THEMIM->getIM(), chapterChanged( bool ),
328             menuButton, setVisible( bool ) );
329     /* Changes the IM navigation when triggered on the nav buttons */
330     CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
331             sectionPrev() );
332     CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
333             sectionNext() );
334     CONNECT( menuButton, clicked(), THEMIM->getIM(),
335             sectionMenu() );
336
337     return discFrame;
338 }
339
340 QWidget *AbstractController::telexFrame()
341 {
342     /**
343      * Telextext QFrame
344      **/
345     TeletextController *telexFrame = new TeletextController;
346     QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
347     telexLayout->setSpacing( 0 ); telexLayout->setMargin( 0 );
348     CONNECT( THEMIM->getIM(), teletextPossible( bool ),
349              telexFrame, setVisible( bool ) );
350
351     /* On/Off button */
352     QToolButton *telexOn = new QToolButton;
353     telexFrame->telexOn = telexOn;
354     setupButton( telexOn );
355     BUTTON_SET_BAR( telexOn, tv, qtr( "Teletext Activation" ) );
356     telexLayout->addWidget( telexOn );
357
358     /* Teletext Activation and set */
359     CONNECT( telexOn, clicked( bool ),
360              THEMIM->getIM(), activateTeletext( bool ) );
361     CONNECT( THEMIM->getIM(), teletextActivated( bool ),
362              telexFrame, enableTeletextButtons( bool ) );
363
364
365     /* Transparency button */
366     QToolButton *telexTransparent = new QToolButton;
367     telexFrame->telexTransparent = telexTransparent;
368     setupButton( telexTransparent );
369     BUTTON_SET_BAR( telexTransparent, tvtelx,
370             qtr( "Toggle Transparency " ) );
371     telexTransparent->setEnabled( false );
372     telexLayout->addWidget( telexTransparent );
373
374     /* Transparency change and set */
375     CONNECT( telexTransparent, clicked( bool ),
376             THEMIM->getIM(), telexSetTransparency( bool ) );
377     CONNECT( THEMIM->getIM(), teletextTransparencyActivated( bool ),
378             telexFrame, toggleTeletextTransparency( bool ) );
379
380
381     /* Page setting */
382     QSpinBox *telexPage = new QSpinBox;
383     telexFrame->telexPage = telexPage;
384     telexPage->setRange( 0, 999 );
385     telexPage->setValue( 100 );
386     telexPage->setAccelerated( true );
387     telexPage->setWrapping( true );
388     telexPage->setAlignment( Qt::AlignRight );
389     telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
390     telexPage->setEnabled( false );
391     telexLayout->addWidget( telexPage );
392
393     /* Page change and set */
394     CONNECT( telexPage, valueChanged( int ),
395             THEMIM->getIM(), telexSetPage( int ) );
396     CONNECT( THEMIM->getIM(), newTelexPageSet( int ),
397             telexPage, setValue( int ) );
398
399     return telexFrame;
400 }
401 #undef CONNECT_MAP
402 #undef SET_MAPPING
403 #undef BUTTON_SET_BAR
404
405 SoundWidget::SoundWidget( intf_thread_t * _p_intf, bool b_shiny )
406                          : b_my_volume( false )
407 {
408     p_intf = _p_intf;
409     QHBoxLayout *layout = new QHBoxLayout( this );
410     layout->setSpacing( 0 ); layout->setMargin( 0 );
411     hVolLabel = new VolumeClickHandler( p_intf, this );
412
413     volMuteLabel = new QLabel;
414     volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
415     volMuteLabel->installEventFilter( hVolLabel );
416     layout->addWidget( volMuteLabel );
417
418     if( b_shiny )
419     {
420         volumeSlider = new SoundSlider( this,
421             config_GetInt( p_intf, "volume-step" ),
422             config_GetInt( p_intf, "qt-volume-complete" ),
423             config_GetPsz( p_intf, "qt-slider-colours" ) );
424     }
425     else
426     {
427         volumeSlider = new QSlider( this );
428         volumeSlider->setOrientation( Qt::Horizontal );
429     }
430     volumeSlider->setMaximumSize( QSize( 200, 40 ) );
431     volumeSlider->setMinimumSize( QSize( 85, 30 ) );
432     volumeSlider->setFocusPolicy( Qt::NoFocus );
433     layout->addWidget( volumeSlider );
434
435     /* Set the volume from the config */
436     volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
437                               VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
438
439     /* Force the update at build time in order to have a muted icon if needed */
440     updateVolume( volumeSlider->value() );
441
442     /* Volume control connection */
443     CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
444     CONNECT( THEMIM, volumeChanged( void ), this, updateVolume( void ) );
445 }
446
447 void SoundWidget::updateVolume( int i_sliderVolume )
448 {
449     if( !b_my_volume )
450     {
451         int i_res = i_sliderVolume  * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
452         aout_VolumeSet( p_intf, i_res );
453     }
454     if( i_sliderVolume == 0 )
455     {
456         volMuteLabel->setPixmap( QPixmap(":/volume-muted" ) );
457         volMuteLabel->setToolTip( qtr( "Unmute" ) );
458         return;
459     }
460
461     if( i_sliderVolume < VOLUME_MAX / 3 )
462         volMuteLabel->setPixmap( QPixmap( ":/volume-low" ) );
463     else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
464         volMuteLabel->setPixmap( QPixmap( ":/volume-high" ) );
465     else volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
466     volMuteLabel->setToolTip( qtr( "Mute" ) );
467 }
468
469 void SoundWidget::updateVolume()
470 {
471     /* Audio part */
472     audio_volume_t i_volume;
473     aout_VolumeGet( p_intf, &i_volume );
474     i_volume = ( i_volume *  VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
475     int i_gauge = volumeSlider->value();
476     b_my_volume = false;
477     if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
478     {
479         b_my_volume = true;
480         volumeSlider->setValue( i_volume );
481         b_my_volume = false;
482     }
483 }
484
485 void TeletextController::toggleTeletextTransparency( bool b_transparent )
486 {
487     telexTransparent->setIcon( b_transparent ? QIcon( ":/tvtelx" )
488                                              : QIcon( ":/tvtelx-trans" ) );
489 }
490
491 void TeletextController::enableTeletextButtons( bool b_enabled )
492 {
493     telexOn->setChecked( b_enabled );
494     telexTransparent->setEnabled( b_enabled );
495     telexPage->setEnabled( b_enabled );
496 }
497
498 void PlayButton::updateButton( bool b_playing )
499 {
500     setIcon( b_playing ? QIcon( ":/pause_b" ) : QIcon( ":/play_b" ) );
501     setToolTip( b_playing ? qtr( "Pause the playback" )
502                           : qtr( I_PLAY_TOOLTIP ) );
503 }
504
505 void AtoB_Button::setIcons( bool timeA, bool timeB )
506 {
507     if( !timeA && !timeB)
508     {
509         setIcon( QIcon( ":/atob_nob" ) );
510         setToolTip( qtr( "Loop from point A to point B continuously\n"
511                          "Click to set point A" ) );
512     }
513     else if( timeA && !timeB )
514     {
515         setIcon( QIcon( ":/atob_noa" ) );
516         setToolTip( qtr( "Click to set point B" ) );
517     }
518     else if( timeA && timeB )
519     {
520         setIcon( QIcon( ":/atob" ) );
521         setToolTip( qtr( "Stop the A to B loop" ) );
522     }
523 }
524
525
526 //* Actions */
527 void AbstractController::doAction( int id_action )
528 {
529     switch( id_action )
530     {
531         case PLAY_ACTION:
532             play(); break;
533         case PREVIOUS_ACTION:
534             prev(); break;
535         case NEXT_ACTION:
536             next(); break;
537         case STOP_ACTION:
538             stop(); break;
539         case SLOWER_ACTION:
540             slower(); break;
541         case FASTER_ACTION:
542             faster(); break;
543         case FULLSCREEN_ACTION:
544             fullscreen(); break;
545         case EXTENDED_ACTION:
546             extSettings(); break;
547         case PLAYLIST_ACTION:
548             playlist(); break;
549         case SNAPSHOT_ACTION:
550             snapshot(); break;
551         case RECORD_ACTION:
552             record(); break;
553         case ATOB_ACTION:
554             THEMIM->getIM()->setAtoB(); break;
555         default:
556             msg_Dbg( p_intf, "Action: %i", id_action );
557             break;
558     }
559 }
560
561 void AbstractController::stop()
562 {
563     THEMIM->stop();
564 }
565
566 void AbstractController::play()
567 {
568     if( THEPL->current.i_size == 0 )
569     {
570         /* The playlist is empty, open a file requester */
571         THEDP->openFileDialog();
572         return;
573     }
574     THEMIM->togglePlayPause();
575 }
576
577 void AbstractController::prev()
578 {
579     THEMIM->prev();
580 }
581
582 void AbstractController::next()
583 {
584     THEMIM->next();
585 }
586
587 /**
588   * TODO
589  * This functions toggle the fullscreen mode
590  * If there is no video, it should first activate Visualisations...
591  *  This has also to be fixed in enableVideo()
592  */
593 void AbstractController::fullscreen()
594 {
595     vout_thread_t *p_vout =
596       (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
597     if( p_vout)
598     {
599         var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
600         vlc_object_release( p_vout );
601     }
602 }
603
604 void AbstractController::snapshot()
605 {
606     vout_thread_t *p_vout =
607       (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
608     if( p_vout )
609     {
610         vout_Control( p_vout, VOUT_SNAPSHOT );
611         vlc_object_release( p_vout );
612     }
613 }
614
615
616 void AbstractController::extSettings()
617 {
618     THEDP->extendedDialog();
619 }
620
621 void AbstractController::slower()
622 {
623     THEMIM->getIM()->slower();
624 }
625
626 void AbstractController::faster()
627 {
628     THEMIM->getIM()->faster();
629 }
630
631 void AbstractController::playlist()
632 {
633     if( p_intf->p_sys->p_mi ) p_intf->p_sys->p_mi->togglePlaylist();
634 }
635
636 void AbstractController::record()
637 {
638     input_thread_t *p_input = THEMIM->getInput();
639     if( p_input )
640     {
641         /* This method won't work fine if the stream can't be cut anywhere */
642         const bool b_recording = var_GetBool( p_input, "record" );
643         var_SetBool( p_input, "record", !b_recording );
644 #if 0
645         else
646         {
647             /* 'record' access-filter is not loaded, we open Save dialog */
648             input_item_t *p_item = input_GetItem( p_input );
649             if( !p_item )
650                 return;
651
652             char *psz = input_item_GetURI( p_item );
653             if( psz )
654                 THEDP->streamingDialog( NULL, psz, true );
655         }
656 #endif
657     }
658 }
659
660 #if 0
661 //TODO Frame by frame function
662 void AbstractController::frame(){}
663 #endif
664
665
666 /*****************************
667  * DA Control Widget !
668  *****************************/
669 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
670                                 bool b_advControls ) :
671                                 AbstractController( _p_i )
672 {
673     setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
674
675     /* advanced Controls handling */
676     b_advancedVisible = b_advControls;
677
678     advControls = new AdvControlsWidget( p_intf );
679     if( !b_advancedVisible ) advControls->hide();
680
681     controlLayout->setSpacing( 0 );
682     controlLayout->setLayoutMargins( 7, 5, 7, 3, 6 );
683
684     controlLayout->addWidget( createWidget( INPUT_SLIDER ), 0, 1, 1, 18 );
685     controlLayout->addWidget( createWidget( SLOWER_BUTTON, true ), 0, 0 );
686     controlLayout->addWidget( createWidget( FASTER_BUTTON, true ), 0, 19 );
687
688     controlLayout->addWidget( createWidget( MENU_BUTTONS ), 1, 8, 2, 3 );
689     controlLayout->addWidget( createWidget( TELETEXT_BUTTONS ), 1, 8, 2, 5, Qt::AlignBottom );
690
691     controlLayout->addWidget( createWidget( PLAY_BUTTON, false, true ), 2, 0, 2, 2, Qt::AlignBottom );
692     controlLayout->setColumnMinimumWidth( 2, 10 );
693     controlLayout->setColumnStretch( 2, 0 );
694
695     controlLayout->addWidget( createWidget( PREVIOUS_BUTTON ), 3, 3, Qt::AlignBottom );
696     controlLayout->addWidget( createWidget( STOP_BUTTON ), 3, 4, Qt::AlignBottom  );
697     controlLayout->addWidget( createWidget( NEXT_BUTTON ), 3, 5, Qt::AlignBottom  );
698
699     /* Column 6 is unused */
700     controlLayout->setColumnStretch( 6, 0 );
701     controlLayout->setColumnStretch( 7, 0 );
702     controlLayout->setColumnMinimumWidth( 7, 10 );
703
704     controlLayout->addWidget( createWidget( FULLSCREEN_BUTTON ), 3, 8, Qt::AlignBottom );
705     controlLayout->addWidget( createWidget( PLAYLIST_BUTTON ), 3, 9, Qt::AlignBottom );
706     controlLayout->addWidget( createWidget( EXTENDED_BUTTON ), 3, 10, Qt::AlignBottom );
707     controlLayout->setColumnStretch( 11, 0 ); /* telex alignment */
708
709     controlLayout->setColumnStretch( 12, 0 );
710     controlLayout->setColumnMinimumWidth( 12, 10 );
711
712     controlLayout->addWidget( advControls, 3, 13, 1, 3, Qt::AlignBottom );
713
714     controlLayout->setColumnStretch( 16, 10 );
715     controlLayout->setColumnMinimumWidth( 16, 10 );
716
717     controlLayout->addWidget( createWidget( VOLUME, false, false, true ),
718             3, 17, 1, 3, Qt::AlignBottom );
719 }
720
721 ControlsWidget::~ControlsWidget()
722 {}
723
724 void ControlsWidget::toggleAdvanced()
725 {
726     if( advControls && !b_advancedVisible )
727     {
728         advControls->show();
729         b_advancedVisible = true;
730     }
731     else
732     {
733         advControls->hide();
734         b_advancedVisible = false;
735     }
736     emit advancedControlsToggled( b_advancedVisible );
737 }
738
739 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
740                                      AbstractController( _p_i )
741 {
742     controlLayout->setMargin( 0 );
743     controlLayout->setSpacing( 0 );
744
745     controlLayout->addWidget( createWidget( RECORD_BUTTON ), 0, 0 );
746     controlLayout->addWidget( createWidget( SNAPSHOT_BUTTON ), 0, 1 );
747     controlLayout->addWidget( createWidget( ATOB_BUTTON ), 0, 2 );
748 }
749
750 AdvControlsWidget::~AdvControlsWidget()
751 {}
752
753
754 /**********************************************************************
755  * Fullscrenn control widget
756  **********************************************************************/
757 FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i )
758                            : AbstractController( _p_i )
759 {
760     i_mouse_last_x      = -1;
761     i_mouse_last_y      = -1;
762     b_mouse_over        = false;
763     i_mouse_last_move_x = -1;
764     i_mouse_last_move_y = -1;
765 #if HAVE_TRANSPARENCY
766     b_slow_hide_begin   = false;
767     i_slow_hide_timeout = 1;
768 #endif
769     b_fullscreen        = false;
770     i_hide_timeout      = 1;
771     p_vout              = NULL;
772
773     setWindowFlags( Qt::ToolTip );
774     setMinimumWidth( 600 );
775
776     setFrameShape( QFrame::StyledPanel );
777     setFrameStyle( QFrame::Sunken );
778     setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
779
780     controlLayout->setLayoutMargins( 5, 2, 5, 2, 5 );
781
782     /* First line */
783     controlLayout->addWidget( createWidget( SLOWER_BUTTON ), 0, 0 );
784     controlLayout->addWidget( createWidget( INPUT_SLIDER ), 0, 1, 1, 13 );
785     controlLayout->addWidget( createWidget( FASTER_BUTTON ), 0, 14 );
786
787     /* Second line */
788     controlLayout->addWidget( createWidget( PLAY_BUTTON, false, true ), 1, 0, 1, 2 );
789     controlLayout->addWidget( createWidget( PREVIOUS_BUTTON ), 1, 2 );
790     controlLayout->addWidget( createWidget( STOP_BUTTON ), 1, 3 );
791     controlLayout->addWidget( createWidget( NEXT_BUTTON ), 1, 4 );
792
793     controlLayout->addWidget( createWidget( MENU_BUTTONS ), 1, 5 );
794     controlLayout->addWidget( createWidget( TELETEXT_BUTTONS ), 1, 6 );
795     QToolButton *fullscreenButton =
796          qobject_cast<QToolButton *>(createWidget( FULLSCREEN_BUTTON ) );
797     fullscreenButton->setIcon( QIcon( ":/defullscreen" ) );
798     controlLayout->addWidget( fullscreenButton, 1, 7 );
799
800     controlLayout->setColumnStretch( 9, 10 );
801
802     TimeLabel *timeLabel = new TimeLabel( p_intf );
803
804     controlLayout->addWidget( timeLabel, 1, 10 );
805     controlLayout->addWidget( createWidget( VOLUME, false, false, true ),
806             1, 11, 1, 3 );
807
808     /* hiding timer */
809     p_hideTimer = new QTimer( this );
810     CONNECT( p_hideTimer, timeout(), this, hideFSC() );
811     p_hideTimer->setSingleShot( true );
812
813     /* slow hiding timer */
814 #if HAVE_TRANSPARENCY
815     p_slowHideTimer = new QTimer( this );
816     CONNECT( p_slowHideTimer, timeout(), this, slowHideFSC() );
817 #endif
818
819     adjustSize ();  /* need to get real width and height for moving */
820
821     /* center down */
822     QRect desktopRect = QApplication::desktop()->
823         screenGeometry( p_intf->p_sys->p_mi );
824
825     QPoint pos = QPoint( desktopRect.width() / 2 - width() / 2,
826           desktopRect.height() - height() );
827
828     getSettings()->beginGroup( "FullScreen" );
829     move( getSettings()->value( "pos", pos ).toPoint() );
830     getSettings()->endGroup();
831
832 #ifdef WIN32TRICK
833     setWindowOpacity( 0.0 );
834     b_fscHidden = true;
835     adjustSize();
836     show();
837 #endif
838
839     vlc_mutex_init_recursive( &lock );
840 }
841
842 FullscreenControllerWidget::~FullscreenControllerWidget()
843 {
844     getSettings()->beginGroup( "FullScreen" );
845     getSettings()->setValue( "pos", pos() );
846     getSettings()->endGroup();
847     detachVout();
848     vlc_mutex_destroy( &lock );
849 }
850
851 /**
852  * Show fullscreen controller
853  */
854 void FullscreenControllerWidget::showFSC()
855 {
856     adjustSize();
857 #ifdef WIN32TRICK
858     // after quiting and going to fs, we need to call show()
859     if( isHidden() )
860         show();
861
862     if( b_fscHidden )
863     {
864         b_fscHidden = false;
865         setWindowOpacity( 1.0 );
866     }
867 #else
868     show();
869 #endif
870
871 #if HAVE_TRANSPARENCY
872     setWindowOpacity( DEFAULT_OPACITY );
873 #endif
874 }
875
876 /**
877  * Hide fullscreen controller
878  * FIXME: under windows it have to be done by moving out of screen
879  *        because hide() doesnt work
880  */
881 void FullscreenControllerWidget::hideFSC()
882 {
883 #ifdef WIN32TRICK
884     b_fscHidden = true;
885     setWindowOpacity( 0.0 );    // simulate hidding
886 #else
887     hide();
888 #endif
889 }
890
891 /**
892  * Plane to hide fullscreen controller
893  */
894 void FullscreenControllerWidget::planHideFSC()
895 {
896     vlc_mutex_lock( &lock );
897     int i_timeout = i_hide_timeout;
898     vlc_mutex_unlock( &lock );
899
900     p_hideTimer->start( i_timeout );
901
902 #if HAVE_TRANSPARENCY
903     b_slow_hide_begin = true;
904     i_slow_hide_timeout = i_timeout;
905     p_slowHideTimer->start( i_slow_hide_timeout / 2 );
906 #endif
907 }
908
909 /**
910  * Hidding fullscreen controller slowly
911  * Linux: need composite manager
912  * Windows: it is blinking, so it can be enabled by define TRASPARENCY
913  */
914 void FullscreenControllerWidget::slowHideFSC()
915 {
916 #if HAVE_TRANSPARENCY
917     if( b_slow_hide_begin )
918     {
919         b_slow_hide_begin = false;
920
921         p_slowHideTimer->stop();
922         /* the last part of time divided to 100 pieces */
923         p_slowHideTimer->start( (int)( i_slow_hide_timeout / 2 / ( windowOpacity() * 100 ) ) );
924
925     }
926     else
927     {
928 #ifdef WIN32TRICK
929          if ( windowOpacity() > 0.0 && !b_fscHidden )
930 #else
931          if ( windowOpacity() > 0.0 )
932 #endif
933          {
934              /* we should use 0.01 because of 100 pieces ^^^
935                 but than it cannt be done in time */
936              setWindowOpacity( windowOpacity() - 0.02 );
937          }
938
939          if ( windowOpacity() <= 0.0 )
940              p_slowHideTimer->stop();
941     }
942 #endif
943 }
944
945 /**
946  * event handling
947  * events: show, hide, start timer for hidding
948  */
949 void FullscreenControllerWidget::customEvent( QEvent *event )
950 {
951     bool b_fs;
952
953     switch( event->type() )
954     {
955         case FullscreenControlToggle_Type:
956             vlc_mutex_lock( &lock );
957             b_fs = b_fullscreen;
958             vlc_mutex_unlock( &lock );
959             if( b_fs )
960 #ifdef WIN32TRICK
961                 if( b_fscHidden )
962 #else
963                 if( isHidden() )
964 #endif
965                 {
966                     p_hideTimer->stop();
967                     showFSC();
968                 }
969                 else
970                     hideFSC();
971             break;
972         case FullscreenControlShow_Type:
973             vlc_mutex_lock( &lock );
974             b_fs = b_fullscreen;
975             vlc_mutex_unlock( &lock );
976
977 #ifdef WIN32TRICK
978             if( b_fs && b_fscHidden )
979 #else
980             if( b_fs && !isVisible() )
981 #endif
982                 showFSC();
983             break;
984         case FullscreenControlHide_Type:
985             hideFSC();
986             break;
987         case FullscreenControlPlanHide_Type:
988             if( !b_mouse_over ) // Only if the mouse is not over FSC
989                 planHideFSC();
990             break;
991     }
992 }
993
994 /**
995  * On mouse move
996  * moving with FSC
997  */
998 void FullscreenControllerWidget::mouseMoveEvent( QMouseEvent *event )
999 {
1000     if ( event->buttons() == Qt::LeftButton )
1001     {
1002         int i_moveX = event->globalX() - i_mouse_last_x;
1003         int i_moveY = event->globalY() - i_mouse_last_y;
1004
1005         move( x() + i_moveX, y() + i_moveY );
1006
1007         i_mouse_last_x = event->globalX();
1008         i_mouse_last_y = event->globalY();
1009     }
1010 }
1011
1012 /**
1013  * On mouse press
1014  * store position of cursor
1015  */
1016 void FullscreenControllerWidget::mousePressEvent( QMouseEvent *event )
1017 {
1018     i_mouse_last_x = event->globalX();
1019     i_mouse_last_y = event->globalY();
1020 }
1021
1022 /**
1023  * On mouse go above FSC
1024  */
1025 void FullscreenControllerWidget::enterEvent( QEvent *event )
1026 {
1027     b_mouse_over = true;
1028
1029     p_hideTimer->stop();
1030 #if HAVE_TRANSPARENCY
1031     p_slowHideTimer->stop();
1032 #endif
1033 }
1034
1035 /**
1036  * On mouse go out from FSC
1037  */
1038 void FullscreenControllerWidget::leaveEvent( QEvent *event )
1039 {
1040     planHideFSC();
1041
1042     b_mouse_over = false;
1043 }
1044
1045 /**
1046  * When you get pressed key, send it to video output
1047  * FIXME: clearing focus by clearFocus() to not getting
1048  * key press events didnt work
1049  */
1050 void FullscreenControllerWidget::keyPressEvent( QKeyEvent *event )
1051 {
1052     int i_vlck = qtEventToVLCKey( event );
1053     if( i_vlck > 0 )
1054     {
1055         var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1056         event->accept();
1057     }
1058     else
1059         event->ignore();
1060 }
1061
1062 /* */
1063 static int FullscreenControllerWidgetFullscreenChanged( vlc_object_t *vlc_object,
1064                 const char *variable, vlc_value_t old_val,
1065                 vlc_value_t new_val,  void *data )
1066 {
1067     vout_thread_t *p_vout = (vout_thread_t *) vlc_object;
1068     msg_Dbg( p_vout, "Qt4: Fullscreen state changed" );
1069     FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1070
1071     p_fs->fullscreenChanged( p_vout, new_val.b_bool,
1072             var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1073
1074     return VLC_SUCCESS;
1075 }
1076 /* */
1077 static int FullscreenControllerWidgetMouseMoved( vlc_object_t *vlc_object, const char *variable,
1078                                                  vlc_value_t old_val, vlc_value_t new_val,
1079                                                  void *data )
1080 {
1081     FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1082
1083     int i_mousex, i_mousey;
1084     bool b_toShow = false;
1085
1086     /* Get the value from the Vout - Trust the vout more than Qt */
1087     i_mousex = var_GetInteger( p_fs->p_vout, "mouse-x" );
1088     i_mousey = var_GetInteger( p_fs->p_vout, "mouse-y" );
1089
1090     /* First time */
1091     if( p_fs->i_mouse_last_move_x == -1 || p_fs->i_mouse_last_move_y == -1 )
1092     {
1093         p_fs->i_mouse_last_move_x = i_mousex;
1094         p_fs->i_mouse_last_move_y = i_mousey;
1095         b_toShow = true;
1096     }
1097     /* All other times */
1098     else
1099     {
1100         /* Trigger only if move > 3 px dans une direction */
1101         if( abs( p_fs->i_mouse_last_move_x - i_mousex ) > 2 ||
1102             abs( p_fs->i_mouse_last_move_y - i_mousey ) > 2 )
1103         {
1104             b_toShow = true;
1105             p_fs->i_mouse_last_move_x = i_mousex;
1106             p_fs->i_mouse_last_move_y = i_mousey;
1107         }
1108     }
1109
1110     if( b_toShow )
1111     {
1112         /* Show event */
1113         IMEvent *eShow = new IMEvent( FullscreenControlShow_Type, 0 );
1114         QApplication::postEvent( p_fs, static_cast<QEvent *>(eShow) );
1115
1116         /* Plan hide event */
1117         IMEvent *eHide = new IMEvent( FullscreenControlPlanHide_Type, 0 );
1118         QApplication::postEvent( p_fs, static_cast<QEvent *>(eHide) );
1119     }
1120
1121     return VLC_SUCCESS;
1122 }
1123
1124
1125 /**
1126  * It is called when video start
1127  */
1128 void FullscreenControllerWidget::attachVout( vout_thread_t *p_nvout )
1129 {
1130     assert( p_nvout && !p_vout );
1131
1132     p_vout = p_nvout;
1133
1134     msg_Dbg( p_vout, "Qt FS: Attaching Vout" );
1135     vlc_mutex_lock( &lock );
1136
1137     var_AddCallback( p_vout, "fullscreen",
1138             FullscreenControllerWidgetFullscreenChanged, this );
1139             /* I miss a add and fire */
1140     fullscreenChanged( p_vout, var_GetBool( p_vout, "fullscreen" ),
1141                        var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1142     vlc_mutex_unlock( &lock );
1143 }
1144 /**
1145  * It is called after turn off video.
1146  */
1147 void FullscreenControllerWidget::detachVout()
1148 {
1149     if( p_vout )
1150     {
1151         msg_Dbg( p_vout, "Qt FS: Detaching Vout" );
1152         var_DelCallback( p_vout, "fullscreen",
1153                 FullscreenControllerWidgetFullscreenChanged, this );
1154         vlc_mutex_lock( &lock );
1155         fullscreenChanged( p_vout, false, 0 );
1156         vlc_mutex_unlock( &lock );
1157         p_vout = NULL;
1158     }
1159 }
1160
1161 /**
1162  * Register and unregister callback for mouse moving
1163  */
1164 void FullscreenControllerWidget::fullscreenChanged( vout_thread_t *p_vout,
1165         bool b_fs, int i_timeout )
1166 {
1167     msg_Dbg( p_vout, "Qt: Entering Fullscreen" );
1168
1169     vlc_mutex_lock( &lock );
1170     /* Entering fullscreen, register callback */
1171     if( b_fs && !b_fullscreen )
1172     {
1173         b_fullscreen = true;
1174         i_hide_timeout = i_timeout;
1175         var_AddCallback( p_vout, "mouse-moved",
1176                 FullscreenControllerWidgetMouseMoved, this );
1177     }
1178     /* Quitting fullscreen, unregistering callback */
1179     else if( !b_fs && b_fullscreen )
1180     {
1181         b_fullscreen = false;
1182         i_hide_timeout = i_timeout;
1183         var_DelCallback( p_vout, "mouse-moved",
1184                 FullscreenControllerWidgetMouseMoved, this );
1185
1186         /* Force fs hidding */
1187         IMEvent *eHide = new IMEvent( FullscreenControlHide_Type, 0 );
1188         QApplication::postEvent( this, static_cast<QEvent *>(eHide) );
1189     }
1190     vlc_mutex_unlock( &lock );
1191 }
1192