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