]> git.sesse.net Git - vlc/blob - modules/gui/qt4/main_interface.cpp
qt4: change QIcon( QPixmap( x ) ) -> QIcon( x )
[vlc] / modules / gui / qt4 / main_interface.cpp
1 /*****************************************************************************
2  * main_interface.cpp : Main interface
3  ****************************************************************************
4  * Copyright (C) 2006-2009 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *          Jean-Baptiste Kempf <jb@videolan.org>
9  *          Ilkka Ollakka <ileoo@videolan.org>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24  *****************************************************************************/
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include "qt4.hpp"
31
32 #include "main_interface.hpp"
33 #include "input_manager.hpp"
34 #include "actions_manager.hpp"
35
36 #include "util/customwidgets.hpp"
37 #include "util/qt_dirs.hpp"
38
39 #include "components/interface_widgets.hpp"
40 #include "components/controller.hpp"
41 #include "components/playlist/playlist.hpp"
42 #include "dialogs/external.hpp"
43
44 #include "menus.hpp"
45 #include "recents.hpp"
46
47 #include <QCloseEvent>
48 #include <QKeyEvent>
49
50 #include <QUrl>
51 #include <QSize>
52 #include <QDate>
53
54 #include <QMenu>
55 #include <QMenuBar>
56 #include <QStatusBar>
57 #include <QLabel>
58 #include <QGroupBox>
59 #include <QPushButton>
60
61 #ifdef WIN32
62  #include <vlc_windows_interfaces.h>
63  #include <QBitmap>
64 #endif
65
66 #include <assert.h>
67
68 #include <vlc_keys.h> /* Wheel event */
69 #include <vlc_vout_window.h>
70 #include <vlc_vout.h>
71
72 /* Callback prototypes */
73 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
74                         vlc_value_t old_val, vlc_value_t new_val, void *param );
75 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
76                        vlc_value_t old_val, vlc_value_t new_val, void *param );
77
78 MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
79 {
80     /* Variables initialisation */
81     // need_components_update = false;
82     bgWidget             = NULL;
83     videoWidget          = NULL;
84     playlistWidget       = NULL;
85 #ifndef HAVE_MAEMO
86     sysTray              = NULL;
87 #endif
88     videoIsActive        = false;
89     playlistVisible      = false;
90     input_name           = "";
91     fullscreenControls   = NULL;
92     cryptedLabel         = NULL;
93     controls             = NULL;
94     inputC               = NULL;
95     b_shouldHide         = false;
96
97     bgWasVisible         = false;
98     i_bg_height          = 0;
99
100     /* Ask for privacy */
101     askForPrivacy();
102
103     /**
104      *  Configuration and settings
105      *  Pre-building of interface
106      **/
107     /* Main settings */
108     setFocusPolicy( Qt::StrongFocus );
109     setAcceptDrops( true );
110     setWindowRole( "vlc-main" );
111     setWindowIcon( QApplication::windowIcon() );
112     setWindowOpacity( config_GetFloat( p_intf, "qt-opacity" ) );
113
114     /* Set The Video In emebedded Mode or not */
115     videoEmbeddedFlag = config_GetInt( p_intf, "embedded-video" );
116
117     /* Does the interface resize to video size or the opposite */
118     b_keep_size = !config_GetInt( p_intf, "qt-video-autoresize" );
119
120     /* Are we in the enhanced always-video mode or not ? */
121     i_visualmode = config_GetInt( p_intf, "qt-display-mode" );
122
123         /* Do we want anoying popups or not */
124     notificationEnabled = (bool)config_GetInt( p_intf, "qt-notification" );
125
126     /* Set the other interface settings */
127     settings = getSettings();
128     settings->beginGroup( "MainWindow" );
129
130     /**
131      * Retrieve saved sizes for main window
132      *   mainBasedSize = based window size for normal mode
133      *                  (no video, no background)
134      *   mainVideoSize = window size with video (all modes)
135      **/
136     mainBasedSize = settings->value( "mainBasedSize", QSize( 350, 120 ) ).toSize();
137     mainVideoSize = settings->value( "mainVideoSize", QSize( 400, 300 ) ).toSize();
138
139     /**************
140      * Status Bar *
141      **************/
142     createStatusBar();
143
144     /**************************
145      *  UI and Widgets design
146      **************************/
147     setVLCWindowsTitle();
148     createMainWidget( settings );
149
150     /************
151      * Menu Bar *
152      ************/
153     QVLCMenu::createMenuBar( this, p_intf );
154     CONNECT( THEMIM->getIM(), voutListChanged( vout_thread_t **, int ),
155              this, destroyPopupMenu() );
156
157 #if 0
158     /* Create a Dock to get the playlist */
159     dockPL = new QDockWidget( qtr( "Playlist" ), this );
160     dockPL->setSizePolicy( QSizePolicy::Preferred,
161                            QSizePolicy::Expanding );
162     dockPL->setFeatures( QDockWidget::AllDockWidgetFeatures );
163     dockPL->setAllowedAreas( Qt::LeftDockWidgetArea
164                            | Qt::RightDockWidgetArea
165                            | Qt::BottomDockWidgetArea );
166     dockPL->hide();
167 #endif
168
169     /*********************************
170      * Create the Systray Management *
171      *********************************/
172     initSystray();
173
174     /********************
175      * Input Manager    *
176      ********************/
177     MainInputManager::getInstance( p_intf );
178
179     /************************************************************
180      * Connect the input manager to the GUI elements it manages *
181      ************************************************************/
182     /**
183      * Connects on nameChanged()
184      * Those connects are different because options can impeach them to trigger.
185      **/
186     /* Main Interface statusbar */
187     CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
188              this, setName( const QString& ) );
189     /* and systray */
190 #ifndef HAVE_MAEMO
191     if( sysTray )
192     {
193         CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
194                  this, updateSystrayTooltipName( const QString& ) );
195     }
196 #endif
197     /* and title of the Main Interface*/
198     if( config_GetInt( p_intf, "qt-name-in-title" ) )
199     {
200         CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
201                  this, setVLCWindowsTitle( const QString& ) );
202     }
203
204     /**
205      * CONNECTS on PLAY_STATUS
206      **/
207     /* Status on the systray */
208 #ifndef HAVE_MAEMO
209     if( sysTray )
210     {
211         CONNECT( THEMIM->getIM(), statusChanged( int ),
212                  this, updateSystrayTooltipStatus( int ) );
213     }
214 #endif
215
216     /* END CONNECTS ON IM */
217
218     /************
219      * Callbacks
220      ************/
221     var_AddCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
222
223     /* Register callback for the intf-popupmenu variable */
224     var_AddCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
225
226
227     /* VideoWidget connects for asynchronous calls */
228     connect( this, SIGNAL(askGetVideo(WId*,int*,int*,unsigned*,unsigned *)),
229              this, SLOT(getVideoSlot(WId*,int*,int*,unsigned*,unsigned*)),
230              Qt::BlockingQueuedConnection );
231     connect( this, SIGNAL(askReleaseVideo( void )),
232              this, SLOT(releaseVideoSlot( void )),
233              Qt::BlockingQueuedConnection );
234
235     if( videoWidget )
236     {
237         CONNECT( this, askVideoToResize( unsigned int, unsigned int ),
238                  videoWidget, SetSizing( unsigned int, unsigned int ) );
239         CONNECT( this, askVideoSetFullScreen( bool ),
240                  videoWidget, SetFullScreen( bool ) );
241         CONNECT( videoWidget, keyPressed( QKeyEvent * ),
242                  this, handleKeyPress( QKeyEvent * ) );
243     }
244
245     CONNECT( this, askUpdate(), this, doComponentsUpdate() );
246     CONNECT( THEDP, toolBarConfUpdated(), this, recreateToolbars() );
247
248     /* Size and placement of interface */
249     settings->beginGroup( "MainWindow" );
250     QVLCTools::restoreWidgetPosition( settings, this, QSize(380, 60) );
251
252     /* resize to previously saved main window size if appicable */
253     if( b_keep_size )
254     {
255        if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
256            i_visualmode == QT_MINIMAL_MODE )
257        {
258            resize( mainVideoSize );
259        }
260        else
261        {
262            resize( mainBasedSize );
263        }
264     }
265
266     bool b_pl_visible = settings->value( "playlist-visible", 0 ).toInt();
267     settings->endGroup();
268
269     /* Playlist */
270     if( b_pl_visible ) togglePlaylist();
271
272     /* Enable the popup menu in the MI */
273     setContextMenuPolicy( Qt::CustomContextMenu );
274     CONNECT( this, customContextMenuRequested( const QPoint& ),
275              this, popupMenu( const QPoint& ) );
276
277     /* Final sizing and showing */
278     setMinimumWidth( __MAX( controls->sizeHint().width(),
279                             menuBar()->sizeHint().width() ) );
280     setVisible( !b_shouldHide );
281
282     /* And switch to minimal view if needed
283        Must be called after the show() */
284     if( i_visualmode == QT_MINIMAL_MODE )
285         toggleMinimalView( true );
286
287     /* Update the geometry : It is useful if you switch between
288        qt-display-modes */
289     updateGeometry();
290     resize( sizeHint() );
291
292 #ifdef WIN32
293     createTaskBarButtons();
294 #endif
295 }
296
297 MainInterface::~MainInterface()
298 {
299     msg_Dbg( p_intf, "Destroying the main interface" );
300
301     /* Unsure we hide the videoWidget before destroying it */
302     if( videoIsActive ) videoWidget->hide();
303
304     /* Save playlist state */
305     if( playlistWidget )
306     {
307         if( !isDocked() )
308             QVLCTools::saveWidgetPosition( p_intf, "Playlist", playlistWidget );
309
310         delete playlistWidget;
311     }
312
313 #ifdef WIN32
314     if( himl )
315         ImageList_Destroy( himl );
316     if(p_taskbl)
317         p_taskbl->vt->Release(p_taskbl);
318     CoUninitialize();
319 #endif
320
321     /* Be sure to kill the actionsManager... FIXME */
322     ActionsManager::killInstance();
323
324     /* Delete the FSC controller */
325     delete fullscreenControls;
326
327     /* Save states */
328     settings->beginGroup( "MainWindow" );
329     settings->setValue( "pl-dock-status", (int)i_pl_dock );
330     settings->setValue( "playlist-visible", (int)playlistVisible );
331     settings->setValue( "adv-controls",
332                         getControlsVisibilityStatus() & CONTROLS_ADVANCED );
333
334     settings->setValue( "mainBasedSize", mainBasedSize );
335     settings->setValue( "mainVideoSize", mainVideoSize );
336
337     if( bgWidget )
338         settings->setValue( "backgroundSize", bgWidget->size() );
339
340     /* Save this size */
341     QVLCTools::saveWidgetPosition(settings, this);
342     settings->endGroup();
343
344
345     /* Unregister callbacks */
346     var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
347     var_DelCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
348
349     p_intf->p_sys->p_mi = NULL;
350 }
351
352 /*****************************
353  *   Main UI handling        *
354  *****************************/
355 void MainInterface::recreateToolbars()
356 {
357     msg_Dbg( p_intf, "Recreating the toolbars" );
358     settings->beginGroup( "MainWindow" );
359     delete controls;
360     delete inputC;
361     controls = new ControlsWidget( p_intf, false, this ); /* FIXME */
362     CONNECT( controls, advancedControlsToggled( bool ),
363              this, doComponentsUpdate() );
364     CONNECT( controls, sizeChanged(),
365              this, doComponentsUpdate() );
366     inputC = new InputControlsWidget( p_intf, this );
367
368     mainLayout->addWidget( inputC, 2, 0, 1, -1, Qt::AlignBottom );
369     mainLayout->addWidget( controls, settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
370                               0, 1, -1, Qt::AlignBottom );
371     settings->endGroup();
372 }
373
374 void MainInterface::createMainWidget( QSettings *settings )
375 {
376     /* Create the main Widget and the mainLayout */
377     QWidget *main = new QWidget;
378     setCentralWidget( main );
379     mainLayout = new QGridLayout( main );
380
381     /* Margins, spacing */
382     main->setContentsMargins( 0, 0, 0, 0 );
383     main->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
384     mainLayout->setSpacing( 0 );
385     mainLayout->setMargin( 0 );
386
387     /* Visualisation */
388     /* Disabled for now, they SUCK */
389     #if 0
390     visualSelector = new VisualSelector( p_intf );
391     mainLayout->insertWidget( 0, visualSelector );
392     visualSelector->hide();
393     #endif
394
395     /* Bg Cone */
396     bgWidget = new BackgroundWidget( p_intf );
397     bgWidget->resize(
398             settings->value( "backgroundSize", QSize( 300, 200 ) ).toSize() );
399     bgWidget->updateGeometry();
400
401     if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
402         i_visualmode != QT_MINIMAL_MODE )
403     {
404         bgWidget->hide();
405     }
406
407     /* And video Outputs */
408     if( videoEmbeddedFlag )
409         videoWidget = new VideoWidget( p_intf );
410
411     /* Create the CONTROLS Widget */
412     controls = new ControlsWidget( p_intf,
413                    settings->value( "adv-controls", false ).toBool(), this );
414     CONNECT( controls, advancedControlsToggled( bool ),
415              this, doComponentsUpdate() );
416     CONNECT( controls, sizeChanged(),
417              this, doComponentsUpdate() );
418     inputC = new InputControlsWidget( p_intf, this );
419
420
421     /* Add the controls Widget to the main Widget */
422     if( videoWidget ){
423         mainLayout->addWidget( videoWidget, 0, 0, 1, -1 );
424         mainLayout->setRowStretch( 0, 10 );
425     }
426     mainLayout->addWidget( bgWidget, 1, 0, 1, -1 );
427     //mainLayout->setRowStretch( 1, 10 );
428     mainLayout->addWidget( inputC, 2, 0, 1, -1, Qt::AlignBottom );
429     mainLayout->addWidget( controls, settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
430                            0, 1, -1, Qt::AlignBottom );
431
432     /* Finish the sizing */
433     main->updateGeometry();
434
435     getSettings()->endGroup();
436 #ifdef WIN32
437     if ( depth() > 8 )
438 #endif
439     /* Create the FULLSCREEN CONTROLS Widget */
440     if( config_GetInt( p_intf, "qt-fs-controller" ) )
441     {
442         fullscreenControls = new FullscreenControllerWidget( p_intf, this );
443         CONNECT( fullscreenControls, keyPressed( QKeyEvent * ),
444                  this, handleKeyPress( QKeyEvent * ) );
445     }
446 }
447
448 inline void MainInterface::createStatusBar()
449 {
450     /****************
451      *  Status Bar  *
452      ****************/
453     /* Widgets Creation*/
454     QStatusBar *statusBarr = statusBar();
455
456     TimeLabel *timeLabel = new TimeLabel( p_intf );
457     nameLabel = new QLabel( this );
458     nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
459                                       | Qt::TextSelectableByKeyboard );
460     SpeedLabel *speedLabel = new SpeedLabel( p_intf, "1.00x", this );
461
462     /* Styling those labels */
463     timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
464     speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
465     nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
466
467     /* and adding those */
468     statusBarr->addWidget( nameLabel, 8 );
469     statusBarr->addPermanentWidget( speedLabel, 0 );
470     statusBarr->addPermanentWidget( timeLabel, 0 );
471
472     /* timeLabel behaviour:
473        - double clicking opens the goto time dialog
474        - right-clicking and clicking just toggle between remaining and
475          elapsed time.*/
476     CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
477
478     CONNECT( THEMIM->getIM(), encryptionChanged( bool ),
479              this, showCryptedLabel( bool ) );
480 }
481
482 #ifdef WIN32
483 void MainInterface::createTaskBarButtons()
484 {
485     /*Here is the code for the taskbar thumb buttons
486     FIXME:We need pretty buttons in 16x16 px that are handled correctly by masks in Qt
487     FIXME:the play button's picture doesn't changed to pause when clicked
488     */
489     OSVERSIONINFO winVer;
490     winVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
491     if( GetVersionEx(&winVer) && winVer.dwMajorVersion > 5 )
492     {
493         if(himl = ImageList_Create( 15, //cx
494                                     18, //cy
495                                     ILC_COLOR,//flags
496                                     4,//initial nb of images
497                                     0//nb of images that can be added
498                                     ))
499         {
500             QPixmap img   = QPixmap(":/toolbar/previous_b");
501             QPixmap img2  = QPixmap(":/toolbar/pause_b");
502             QPixmap img3  = QPixmap(":/toolbar/play_b");
503             QPixmap img4  = QPixmap(":/toolbar/next_b");
504             QBitmap mask  = img.createMaskFromColor(Qt::transparent);
505             QBitmap mask2 = img2.createMaskFromColor(Qt::transparent);
506             QBitmap mask3 = img3.createMaskFromColor(Qt::transparent);
507             QBitmap mask4 = img4.createMaskFromColor(Qt::transparent);
508
509             if(-1 == ImageList_Add(himl, img.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask.toWinHBITMAP()))
510                 msg_Err( p_intf, "ImageList_Add failed" );
511             if(-1 == ImageList_Add(himl, img2.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask2.toWinHBITMAP()))
512                 msg_Err( p_intf, "ImageList_Add failed" );
513             if(-1 == ImageList_Add(himl, img3.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask3.toWinHBITMAP()))
514                 msg_Err( p_intf, "ImageList_Add failed" );
515             if(-1 == ImageList_Add(himl, img4.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask4.toWinHBITMAP()))
516                 msg_Err( p_intf, "ImageList_Add failed" );
517         }
518
519         CoInitialize( 0 );
520
521         if( S_OK == CoCreateInstance( &clsid_ITaskbarList,
522                     NULL, CLSCTX_INPROC_SERVER,
523                     &IID_ITaskbarList3,
524                     (void **)&p_taskbl) )
525         {
526             p_taskbl->vt->HrInit(p_taskbl);
527
528             int msg_value = RegisterWindowMessage("TaskbarButtonCreated");
529             //msg_Info( p_intf, "msg value: %04x", msg_value );
530
531             // Define an array of two buttons. These buttons provide images through an
532             // image list and also provide tooltips.
533             DWORD dwMask = THB_BITMAP | THB_FLAGS;
534
535             THUMBBUTTON thbButtons[2];
536             thbButtons[0].dwMask = dwMask;
537             thbButtons[0].iId = 0;
538             thbButtons[0].iBitmap = 0;
539             thbButtons[0].dwFlags = THBF_HIDDEN;
540
541             thbButtons[1].dwMask = dwMask;
542             thbButtons[1].iId = 1;
543             thbButtons[1].iBitmap = 2;
544             thbButtons[1].dwFlags = THBF_HIDDEN;
545
546             thbButtons[2].dwMask = dwMask;
547             thbButtons[2].iId = 2;
548             thbButtons[2].iBitmap = 3;
549             thbButtons[2].dwFlags = THBF_HIDDEN;
550
551             HRESULT hr = p_taskbl->vt->ThumbBarSetImageList(p_taskbl, GetForegroundWindow(), himl );
552             if(S_OK != hr)
553                 msg_Err( p_intf, "ThumbBarSetImageList failed with error %08x", hr );
554             if(S_OK != p_taskbl->vt->ThumbBarAddButtons(p_taskbl, GetForegroundWindow(), 3, thbButtons))
555                 msg_Err( p_intf, "ThumbBarAddButtons failed with error %08x", GetLastError() );
556
557             CONNECT( THEMIM->getIM(), statusChanged( int ), this, changeThumbbarButtons( int ) );
558         }
559     }
560     else
561     {
562         himl = NULL;
563         p_taskbl = NULL;
564     }
565 }
566 #endif
567
568
569 inline void MainInterface::initSystray()
570 {
571 #ifndef HAVE_MAEMO
572     bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
573     bool b_systrayWanted = config_GetInt( p_intf, "qt-system-tray" );
574
575     if( config_GetInt( p_intf, "qt-start-minimized") > 0 )
576     {
577         if( b_systrayAvailable )
578         {
579             b_systrayWanted = true;
580             b_shouldHide = true;
581         }
582         else
583             msg_Err( p_intf, "cannot start minimized without system tray bar" );
584     }
585
586     if( b_systrayAvailable && b_systrayWanted )
587             createSystray();
588 #endif
589 }
590
591 inline void MainInterface::askForPrivacy()
592 {
593 #ifndef HAVE_MAEMO
594     /**
595      * Ask for the network policy on FIRST STARTUP
596      **/
597     if( config_GetInt( p_intf, "qt-privacy-ask") )
598     {
599         QList<ConfigControl *> controls;
600         if( privacyDialog( &controls ) == QDialog::Accepted )
601         {
602             QList<ConfigControl *>::Iterator i;
603             for(  i = controls.begin() ; i != controls.end() ; i++ )
604             {
605                 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
606                 c->doApply( p_intf );
607             }
608
609             config_PutInt( p_intf,  "qt-privacy-ask" , 0 );
610             /* We have to save here because the user may not launch Prefs */
611             config_SaveConfigFile( p_intf, NULL );
612         }
613     }
614 #endif
615 }
616
617 int MainInterface::privacyDialog( QList<ConfigControl *> *controls )
618 {
619     QDialog *privacy = new QDialog( this );
620
621     privacy->setWindowTitle( qtr( "Privacy and Network Policies" ) );
622     privacy->setWindowRole( "vlc-privacy" );
623
624     QGridLayout *gLayout = new QGridLayout( privacy );
625
626     QGroupBox *blabla = new QGroupBox( qtr( "Privacy and Network Warning" ) );
627     QGridLayout *blablaLayout = new QGridLayout( blabla );
628     QLabel *text = new QLabel( qtr(
629         "<p>The <i>VideoLAN Team</i> doesn't like when an application goes "
630         "online without authorization.</p>\n "
631         "<p><i>VLC media player</i> can retreive limited information from "
632         "the Internet in order to get CD covers or to check "
633         "for available updates.</p>\n"
634         "<p><i>VLC media player</i> <b>DOES NOT</b> send or collect <b>ANY</b> "
635         "information, even anonymously, about your usage.</p>\n"
636         "<p>Therefore please select from the following options, the default being "
637         "almost no access to the web.</p>\n") );
638     text->setWordWrap( true );
639     text->setTextFormat( Qt::RichText );
640
641     blablaLayout->addWidget( text, 0, 0 ) ;
642
643     QGroupBox *options = new QGroupBox;
644     QGridLayout *optionsLayout = new QGridLayout( options );
645
646     gLayout->addWidget( blabla, 0, 0, 1, 3 );
647     gLayout->addWidget( options, 1, 0, 1, 3 );
648     module_config_t *p_config;
649     ConfigControl *control;
650     int line = 0;
651
652 #define CONFIG_GENERIC( option, type )                            \
653     p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
654     if( p_config )                                                \
655     {                                                             \
656         control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
657                 p_config, options, false, optionsLayout, line );  \
658         controls->append( control );                               \
659     }
660
661 #define CONFIG_GENERIC_NOBOOL( option, type )                     \
662     p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
663     if( p_config )                                                \
664     {                                                             \
665         control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
666                 p_config, options, optionsLayout, line );  \
667         controls->append( control );                               \
668     }
669
670     CONFIG_GENERIC( "album-art", IntegerList ); line++;
671 #ifdef UPDATE_CHECK
672     CONFIG_GENERIC_NOBOOL( "qt-updates-notif", Bool ); line++;
673 #endif
674
675     QPushButton *ok = new QPushButton( qtr( "OK" ) );
676
677     gLayout->addWidget( ok, 2, 2 );
678
679     CONNECT( ok, clicked(), privacy, accept() );
680     return privacy->exec();
681 }
682
683
684 /**********************************************************************
685  * Handling of sizing of the components
686  **********************************************************************/
687
688 /* This function is probably wrong, but we don't have many many choices...
689    Since we can't know from the playlist Widget if we are inside a dock or not,
690    because the playlist Widget can be called by THEDP, as a separate windows for
691    the skins.
692    Maybe the other solution is to redefine the sizeHint() of the playlist and
693    ask _parent->isFloating()...
694    If you think this would be better, please FIXME it...
695 */
696
697 QSize MainInterface::sizeHint() const
698 {
699     if( b_keep_size )
700     {
701         if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
702             i_visualmode == QT_MINIMAL_MODE )
703         {
704                 return mainVideoSize;
705         }
706         else
707         {
708             if( VISIBLE( bgWidget) ||
709                 ( videoIsActive && videoWidget->isVisible() )
710               )
711                 return mainVideoSize;
712             else
713                 return mainBasedSize;
714         }
715     }
716
717     int nwidth  = controls->sizeHint().width();
718     int nheight = controls->isVisible() ?
719                   controls->size().height()
720                   + inputC->size().height()
721                   + menuBar()->size().height()
722                   + statusBar()->size().height()
723                   : 0 ;
724
725     if( VISIBLE( bgWidget ) )
726     {
727         if( i_bg_height )
728             nheight += i_bg_height;
729         else
730             nheight += bgWidget->size().height();
731         nwidth  = __MAX( nwidth, bgWidget->size().width() );
732     }
733     else if( videoIsActive && videoWidget->isVisible() )
734     {
735         nheight += videoWidget->sizeHint().height();
736         nwidth  = __MAX( nwidth, videoWidget->sizeHint().width() );
737     }
738 #if 0
739     if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget()  )
740     {
741         nheight += dockPL->size().height();
742         nwidth = __MAX( nwidth, dockPL->size().width() );
743         msg_Warn( p_intf, "3 %i %i", nheight, nwidth );
744     }
745 #endif
746     return QSize( nwidth, nheight );
747 }
748
749 /* Video widget cannot do this synchronously as it runs in another thread */
750 /* Well, could it, actually ? Probably dangerous ... */
751
752 /* This function is called:
753    - toggling of minimal View
754    - through askUpdate() by Vout thread request video and resize video (zoom)
755    - Advanced buttons toggled
756  */
757 void MainInterface::doComponentsUpdate()
758 {
759     if( isFullScreen() || isMaximized() ) return;
760
761     msg_Dbg( p_intf, "Updating the geometry" );
762     /* Here we resize to sizeHint() and not adjustsize because we want
763        the videoWidget to be exactly the correctSize */
764     resize( sizeHint() );
765     //    adjustSize()  ;
766 #ifndef NDEBUG
767     debug();
768 #endif
769 }
770
771 void MainInterface::debug()
772 {
773 #ifndef NDEBUG
774     msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
775     msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
776     if( videoWidget && videoWidget->isVisible() )
777     {
778         msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
779         msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
780     }
781 #endif
782 }
783
784 void MainInterface::destroyPopupMenu()
785 {
786     QVLCMenu::PopupMenu(p_intf, false );
787 }
788
789
790 void MainInterface::toggleFSC()
791 {
792    if( !fullscreenControls ) return;
793
794    IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
795    QApplication::postEvent( fullscreenControls, eShow );
796 }
797
798 void MainInterface::popupMenu( const QPoint &p )
799 {
800     /* Ow, that's ugly: don't show the popup menu if cursor over
801      * the main menu bar or the status bar */
802     if( !childAt( p ) || ( ( childAt( p ) != menuBar() )
803                         && ( childAt( p )->parentWidget() != statusBar() ) ) )
804         QVLCMenu::PopupMenu( p_intf, true );
805 }
806
807 /****************************************************************************
808  * Video Handling
809  ****************************************************************************/
810
811 /* This event is used to deal with the fullscreen and always on top
812    issue conflict (bug in wx) */
813 class SetVideoOnTopQtEvent : public QEvent
814 {
815 public:
816     SetVideoOnTopQtEvent( bool _onTop ) :
817       QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
818     {}
819
820     bool OnTop() const { return onTop; }
821
822 private:
823     bool onTop;
824 };
825
826 /**
827  * NOTE:
828  * You must note change the state of this object or other Qt4 UI objects,
829  * from the video output thread - only from the Qt4 UI main loop thread.
830  * All window provider queries must be handled through signals or events.
831  * That's why we have all those emit statements...
832  */
833 WId MainInterface::getVideo( int *pi_x, int *pi_y,
834                              unsigned int *pi_width, unsigned int *pi_height )
835 {
836     if( !videoWidget )
837         return 0;
838
839     /* This is a blocking call signal. Results are returned through pointers.
840      * Beware of deadlocks! */
841     WId id;
842     emit askGetVideo( &id, pi_x, pi_y, pi_width, pi_height );
843     return id;
844 }
845
846 void MainInterface::getVideoSlot( WId *p_id, int *pi_x, int *pi_y,
847                                   unsigned *pi_width, unsigned *pi_height )
848 {
849     /* Request the videoWidget */
850     WId ret = videoWidget->request( pi_x, pi_y,
851                                     pi_width, pi_height, b_keep_size );
852     *p_id = ret;
853     if( ret ) /* The videoWidget is available */
854     {
855         /* Did we have a bg ? Hide it! */
856         if( VISIBLE( bgWidget) )
857         {
858             bgWasVisible = true;
859             bgWidget->toggle();
860         }
861         else
862             bgWasVisible = false;
863
864         /* ask videoWidget to show */
865         videoWidget->SetSizing( *pi_width, *pi_height );
866
867         /* Consider the video active now */
868         videoIsActive = true;
869
870         emit askUpdate();
871     }
872 }
873
874 /* Asynchronous call from the WindowClose function */
875 void MainInterface::releaseVideo( void )
876 {
877     emit askReleaseVideo( );
878 }
879
880 /* Function that is CONNECTED to the previous emit */
881 void MainInterface::releaseVideoSlot( void )
882 {
883     videoWidget->release( );
884
885     if( bgWasVisible )
886     {
887         /* Reset the bg state */
888         bgWasVisible = false;
889         bgWidget->show();
890     }
891
892     videoIsActive = false;
893
894     /* Try to resize, except when you are in Fullscreen mode */
895     doComponentsUpdate();
896 }
897
898 /* Asynchronous call from WindowControl function */
899 int MainInterface::controlVideo( int i_query, va_list args )
900 {
901     switch( i_query )
902     {
903     case VOUT_WINDOW_SET_SIZE:
904     {
905         unsigned int i_width  = va_arg( args, unsigned int );
906         unsigned int i_height = va_arg( args, unsigned int );
907         emit askVideoToResize( i_width, i_height );
908         emit askUpdate();
909         return VLC_SUCCESS;
910     }
911     case VOUT_WINDOW_SET_ON_TOP:
912     {
913         int i_arg = va_arg( args, int );
914         QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
915         return VLC_SUCCESS;
916     }
917     case VOUT_WINDOW_SET_FULLSCREEN:
918     {
919         bool b_fs = va_arg( args, int );
920         emit askVideoSetFullScreen( b_fs );
921         return VLC_SUCCESS;
922     }
923     default:
924         msg_Warn( p_intf, "unsupported control query" );
925         return VLC_EGENERIC;
926     }
927 }
928
929 /*****************************************************************************
930  * Playlist, Visualisation and Menus handling
931  *****************************************************************************/
932 /**
933  * Toggle the playlist widget or dialog
934  **/
935 void MainInterface::togglePlaylist()
936 {
937     /* CREATION
938     If no playlist exist, then create one and attach it to the DockPL*/
939     if( !playlistWidget )
940     {
941         playlistWidget = new PlaylistWidget( p_intf );
942
943         i_pl_dock = PL_UNDOCKED;
944 /*        i_pl_dock = (pl_dock_e)getSettings()
945                          ->value( "pl-dock-status", PL_UNDOCKED ).toInt(); */
946
947         if( i_pl_dock == PL_UNDOCKED )
948         {
949             playlistWidget->setWindowFlags( Qt::Window );
950
951             /* This will restore the geometry but will not work for position,
952                because of parenting */
953             QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
954                     playlistWidget, QSize( 600, 300 ) );
955         }
956         else
957         {
958          //   mainLayout->insertWidget( 4, playlistWidget );
959         }
960         playlistVisible = true;
961
962         playlistWidget->show();
963     }
964     else
965     {
966     /* toggle the visibility of the playlist */
967       //TOGGLEV( playlistWidget );
968
969       if( playlistWidget->isVisible() && !playlistWidget->isMinimized() )
970       {
971           playlistWidget->hide();
972       }
973       else
974       {
975           playlistWidget->setWindowState(
976               playlistWidget->windowState() & ~Qt::WindowMinimized | Qt::WindowActive);
977           playlistWidget->show();
978       }
979
980       playlistVisible = !playlistVisible;
981       //doComponentsUpdate(); //resize( sizeHint() );
982     }
983 }
984
985 /* Function called from the menu to undock the playlist */
986 void MainInterface::undockPlaylist()
987 {
988 //    dockPL->setFloating( true );
989 //    adjustSize();
990 }
991
992 void MainInterface::dockPlaylist( pl_dock_e i_pos )
993 {
994 }
995
996 void MainInterface::toggleMinimalView( bool b_switch )
997 {
998     if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
999         i_visualmode != QT_MINIMAL_MODE )
1000     { /* NORMAL MODE then */
1001         if( !videoWidget || videoWidget->isHidden() )
1002         {
1003             bgWidget->toggle();
1004         }
1005         else
1006         {
1007             /* If video is visible, then toggle the status of bgWidget */
1008             bgWasVisible = !bgWasVisible;
1009         }
1010     }
1011
1012     i_bg_height = bgWidget->height();
1013
1014     menuBar()->setVisible( !b_switch );
1015     controls->setVisible( !b_switch );
1016     statusBar()->setVisible( !b_switch );
1017     inputC->setVisible( !b_switch );
1018
1019     doComponentsUpdate();
1020
1021     emit minimalViewToggled( b_switch );
1022 }
1023
1024 /* toggling advanced controls buttons */
1025 void MainInterface::toggleAdvanced()
1026 {
1027     controls->toggleAdvanced();
1028 //    if( fullscreenControls ) fullscreenControls->toggleAdvanced();
1029 }
1030
1031 /* Get the visibility status of the controls (hidden or not, advanced or not) */
1032 int MainInterface::getControlsVisibilityStatus()
1033 {
1034     return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
1035                 + CONTROLS_ADVANCED * controls->b_advancedVisible );
1036 }
1037
1038 #if 0
1039 void MainInterface::visual()
1040 {
1041     if( !VISIBLE( visualSelector) )
1042     {
1043         visualSelector->show();
1044         if( !THEMIM->getIM()->hasVideo() )
1045         {
1046             /* Show the background widget */
1047         }
1048         visualSelectorEnabled = true;
1049     }
1050     else
1051     {
1052         /* Stop any currently running visualization */
1053         visualSelector->hide();
1054         visualSelectorEnabled = false;
1055     }
1056     doComponentsUpdate();
1057 }
1058 #endif
1059
1060 /************************************************************************
1061  * Other stuff
1062  ************************************************************************/
1063 void MainInterface::setName( const QString& name )
1064 {
1065     input_name = name; /* store it for the QSystray use */
1066     /* Display it in the status bar, but also as a Tooltip in case it doesn't
1067        fit in the label */
1068     nameLabel->setText( " " + name + " " );
1069     nameLabel->setToolTip( " " + name +" " );
1070 }
1071
1072 /**
1073  * Give the decorations of the Main Window a correct Name.
1074  * If nothing is given, set it to VLC...
1075  **/
1076 void MainInterface::setVLCWindowsTitle( const QString& aTitle )
1077 {
1078     if( aTitle.isEmpty() )
1079     {
1080         setWindowTitle( qtr( "VLC media player" ) );
1081     }
1082     else
1083     {
1084         setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
1085     }
1086 }
1087
1088 void MainInterface::showCryptedLabel( bool b_show )
1089 {
1090     if( cryptedLabel == NULL )
1091     {
1092         cryptedLabel = new QLabel;
1093         // The lock icon is not the right one for DRM protection/scrambled.
1094         //cryptedLabel->setPixmap( QPixmap( ":/lock" ) );
1095         cryptedLabel->setText( "DRM" );
1096         statusBar()->addWidget( cryptedLabel );
1097     }
1098
1099     cryptedLabel->setVisible( b_show );
1100 }
1101
1102 /*****************************************************************************
1103  * Systray Icon and Systray Menu
1104  *****************************************************************************/
1105 #ifndef HAVE_MAEMO
1106 /**
1107  * Create a SystemTray icon and a menu that would go with it.
1108  * Connects to a click handler on the icon.
1109  **/
1110 void MainInterface::createSystray()
1111 {
1112     QIcon iconVLC;
1113     if( QDate::currentDate().dayOfYear() >= 354 )
1114         iconVLC =  QIcon( ":/logo/vlc128-christmas.png" );
1115     else
1116         iconVLC =  QIcon( ":/logo/vlc128.png" );
1117     sysTray = new QSystemTrayIcon( iconVLC, this );
1118     sysTray->setToolTip( qtr( "VLC media player" ));
1119
1120     systrayMenu = new QMenu( qtr( "VLC media player" ), this );
1121     systrayMenu->setIcon( iconVLC );
1122
1123     QVLCMenu::updateSystrayMenu( this, p_intf, true );
1124     sysTray->show();
1125
1126     CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
1127             this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
1128 }
1129
1130 /**
1131  * Updates the Systray Icon's menu and toggle the main interface
1132  */
1133 void MainInterface::toggleUpdateSystrayMenu()
1134 {
1135     /* If hidden, show it */
1136     if( isHidden() )
1137     {
1138         show();
1139         activateWindow();
1140     }
1141     else if( isMinimized() )
1142     {
1143         /* Minimized */
1144         showNormal();
1145         activateWindow();
1146     }
1147     else
1148     {
1149         /* Visible (possibly under other windows) */
1150 #ifdef WIN32
1151         /* check if any visible window is above vlc in the z-order,
1152          * but ignore the ones always on top
1153          * and the ones which can't be activated */
1154         WINDOWINFO wi;
1155         HWND hwnd;
1156         wi.cbSize = sizeof( WINDOWINFO );
1157         for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
1158                 hwnd && ( !IsWindowVisible( hwnd ) ||
1159                     ( GetWindowInfo( hwnd, &wi ) &&
1160                       (wi.dwExStyle&WS_EX_NOACTIVATE) ) );
1161                 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
1162             if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
1163                 (wi.dwExStyle&WS_EX_TOPMOST) )
1164             {
1165                 hide();
1166             }
1167             else
1168             {
1169                 activateWindow();
1170             }
1171 #else
1172         hide();
1173 #endif
1174     }
1175     QVLCMenu::updateSystrayMenu( this, p_intf );
1176 }
1177
1178 void MainInterface::handleSystrayClick(
1179                                     QSystemTrayIcon::ActivationReason reason )
1180 {
1181     switch( reason )
1182     {
1183         case QSystemTrayIcon::Trigger:
1184         case QSystemTrayIcon::DoubleClick:
1185             toggleUpdateSystrayMenu();
1186             break;
1187         case QSystemTrayIcon::MiddleClick:
1188             sysTray->showMessage( qtr( "VLC media player" ),
1189                     qtr( "Control menu for the player" ),
1190                     QSystemTrayIcon::Information, 3000 );
1191             break;
1192         default:
1193             break;
1194     }
1195 }
1196
1197 /**
1198  * Updates the name of the systray Icon tooltip.
1199  * Doesn't check if the systray exists, check before you call it.
1200  **/
1201 void MainInterface::updateSystrayTooltipName( const QString& name )
1202 {
1203     if( name.isEmpty() )
1204     {
1205         sysTray->setToolTip( qtr( "VLC media player" ) );
1206     }
1207     else
1208     {
1209         sysTray->setToolTip( name );
1210         if( notificationEnabled && ( isHidden() || isMinimized() ) )
1211         {
1212             sysTray->showMessage( qtr( "VLC media player" ), name,
1213                     QSystemTrayIcon::NoIcon, 3000 );
1214         }
1215     }
1216
1217     QVLCMenu::updateSystrayMenu( this, p_intf );
1218 }
1219
1220 /**
1221  * Updates the status of the systray Icon tooltip.
1222  * Doesn't check if the systray exists, check before you call it.
1223  **/
1224 void MainInterface::updateSystrayTooltipStatus( int i_status )
1225 {
1226     switch( i_status )
1227     {
1228         case  0:
1229         case  END_S:
1230             {
1231                 sysTray->setToolTip( qtr( "VLC media player" ) );
1232                 break;
1233             }
1234         case PLAYING_S:
1235             {
1236                 sysTray->setToolTip( input_name );
1237                 break;
1238             }
1239         case PAUSE_S:
1240             {
1241                 sysTray->setToolTip( input_name + " - "
1242                         + qtr( "Paused") );
1243                 break;
1244             }
1245     }
1246     QVLCMenu::updateSystrayMenu( this, p_intf );
1247 }
1248 #endif
1249
1250 /************************************************************************
1251  * D&D Events
1252  ************************************************************************/
1253 void MainInterface::dropEvent(QDropEvent *event)
1254 {
1255     dropEventPlay( event, true );
1256 }
1257
1258 void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
1259 {
1260     event->setDropAction( Qt::CopyAction );
1261     if( !event->possibleActions() & Qt::CopyAction )
1262         return;
1263
1264     const QMimeData *mimeData = event->mimeData();
1265
1266     /* D&D of a subtitles file, add it on the fly */
1267     if( mimeData->urls().size() == 1 && THEMIM->getIM()->hasInput() )
1268     {
1269         if( !input_AddSubtitle( THEMIM->getInput(),
1270                  qtu( toNativeSeparators( mimeData->urls()[0].toLocalFile() ) ),
1271                  true ) )
1272         {
1273             event->accept();
1274             return;
1275         }
1276     }
1277
1278     bool first = b_play;
1279     foreach( const QUrl &url, mimeData->urls() )
1280     {
1281         QString s = toNativeSeparators( url.toLocalFile() );
1282
1283         if( s.length() > 0 ) {
1284             char* psz_uri = make_URI( qtu(s) );
1285             playlist_Add( THEPL, psz_uri, NULL,
1286                           PLAYLIST_APPEND | (first ? PLAYLIST_GO: PLAYLIST_PREPARSE),
1287                           PLAYLIST_END, true, pl_Unlocked );
1288             free( psz_uri );
1289             first = false;
1290             RecentsMRL::getInstance( p_intf )->addRecent( s );
1291         }
1292     }
1293     event->accept();
1294 }
1295 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1296 {
1297      event->acceptProposedAction();
1298 }
1299 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1300 {
1301      event->acceptProposedAction();
1302 }
1303 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1304 {
1305      event->accept();
1306 }
1307
1308 /************************************************************************
1309  * Events stuff
1310  ************************************************************************/
1311 void MainInterface::customEvent( QEvent *event )
1312 {
1313 #if 0
1314     if( event->type() == PLDockEvent_Type )
1315     {
1316         PlaylistDialog::killInstance();
1317         playlistEmbeddedFlag = true;
1318         menuBar()->clear();
1319         QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1320         togglePlaylist();
1321     }
1322 #endif
1323     /*else */
1324     if ( event->type() == (int)SetVideoOnTopEvent_Type )
1325     {
1326         SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1327         if( p_event->OnTop() )
1328             setWindowFlags( windowFlags() | Qt::WindowStaysOnTopHint );
1329         else
1330             setWindowFlags( windowFlags() & ~Qt::WindowStaysOnTopHint );
1331         show(); /* necessary to apply window flags */
1332     }
1333 }
1334
1335 void MainInterface::keyPressEvent( QKeyEvent *e )
1336 {
1337     handleKeyPress( e );
1338 }
1339
1340 void MainInterface::handleKeyPress( QKeyEvent *e )
1341 {
1342     if( ( e->modifiers() &  Qt::ControlModifier ) && ( e->key() == Qt::Key_H )
1343           && !menuBar()->isVisible() )
1344     {
1345         toggleMinimalView( false );
1346         e->accept();
1347     }
1348
1349     int i_vlck = qtEventToVLCKey( e );
1350     if( i_vlck > 0 )
1351     {
1352         var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1353         e->accept();
1354     }
1355     else
1356         e->ignore();
1357 }
1358
1359 void MainInterface::resizeEvent( QResizeEvent * event )
1360 {
1361     if( b_keep_size )
1362     {
1363         if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
1364             i_visualmode == QT_MINIMAL_MODE )
1365         {
1366                 mainVideoSize = size();
1367         }
1368         else
1369         {
1370             if( VISIBLE( bgWidget) ||
1371                 ( videoIsActive && videoWidget->isVisible() )
1372               )
1373                 mainVideoSize = size();
1374             else
1375                 mainBasedSize = size();
1376         }
1377     }
1378 }
1379
1380 void MainInterface::wheelEvent( QWheelEvent *e )
1381 {
1382     int i_vlckey = qtWheelEventToVLCKey( e );
1383     var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1384     e->accept();
1385 }
1386
1387 void MainInterface::closeEvent( QCloseEvent *e )
1388 {
1389     e->accept();
1390     hide();
1391     THEDP->quit();
1392 }
1393
1394 void MainInterface::toggleFullScreen( void )
1395 {
1396     if( isFullScreen() )
1397     {
1398         showNormal();
1399         emit askUpdate(); // Needed if video was launched after the F11
1400         emit fullscreenInterfaceToggled( false );
1401     }
1402     else
1403     {
1404         showFullScreen();
1405         emit fullscreenInterfaceToggled( true );
1406     }
1407
1408 }
1409
1410 //moc doesn't know about #ifdef, so we have to build this method for every platform
1411 void MainInterface::changeThumbbarButtons( int i_status)
1412 {
1413 #ifdef WIN32
1414     // Define an array of two buttons. These buttons provide images through an
1415     // image list and also provide tooltips.
1416     DWORD dwMask = THB_BITMAP | THB_FLAGS;
1417
1418     THUMBBUTTON thbButtons[3];
1419     //prev
1420     thbButtons[0].dwMask = dwMask;
1421     thbButtons[0].iId = 0;
1422     thbButtons[0].iBitmap = 0;
1423
1424     //play/pause
1425     thbButtons[1].dwMask = dwMask;
1426     thbButtons[1].iId = 1;
1427
1428     //next
1429     thbButtons[2].dwMask = dwMask;
1430     thbButtons[2].iId = 2;
1431     thbButtons[2].iBitmap = 3;
1432
1433     switch( i_status )
1434     {
1435         case  0:
1436         case  END_S:
1437             {
1438                 thbButtons[0].dwFlags = THBF_HIDDEN;
1439                 thbButtons[1].dwFlags = THBF_HIDDEN;
1440                 thbButtons[2].dwFlags = THBF_HIDDEN;
1441                 break;
1442             }
1443         case PLAYING_S:
1444             {
1445                 thbButtons[0].dwFlags = THBF_ENABLED;
1446                 thbButtons[1].dwFlags = THBF_ENABLED;
1447                 thbButtons[2].dwFlags = THBF_ENABLED;
1448                 thbButtons[1].iBitmap = 1;
1449                 break;
1450             }
1451         case PAUSE_S:
1452             {
1453                 //thbButtons[0].dwFlags = THBF_ENABLED;
1454                 //thbButtons[1].dwFlags = THBF_ENABLED;
1455                 //thbButtons[2].dwFlags = THBF_ENABLED;
1456                 thbButtons[1].iBitmap = 2;
1457                 break;
1458             }
1459     }
1460
1461     HRESULT hr =  p_taskbl->vt->ThumbBarUpdateButtons(p_taskbl, GetForegroundWindow(), 3, thbButtons);
1462     if(S_OK != hr)
1463         msg_Err( p_intf, "ThumbBarUpdateButtons failed with error %08x", hr );
1464 #else
1465     ;
1466 #endif
1467 }
1468
1469 /*****************************************************************************
1470  * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1471  *  We don't show the menu directly here because we don't want the
1472  *  caller to block for a too long time.
1473  *****************************************************************************/
1474 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1475                         vlc_value_t old_val, vlc_value_t new_val, void *param )
1476 {
1477     intf_thread_t *p_intf = (intf_thread_t *)param;
1478
1479     if( p_intf->pf_show_dialog )
1480     {
1481         p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1482                                 new_val.b_bool, NULL );
1483     }
1484
1485     return VLC_SUCCESS;
1486 }
1487
1488 /*****************************************************************************
1489  * IntfShowCB: callback triggered by the intf-show libvlc variable.
1490  *****************************************************************************/
1491 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1492                        vlc_value_t old_val, vlc_value_t new_val, void *param )
1493 {
1494     intf_thread_t *p_intf = (intf_thread_t *)param;
1495     p_intf->p_sys->p_mi->toggleFSC();
1496
1497     /* Show event */
1498      return VLC_SUCCESS;
1499 }
1500