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