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