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