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