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