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