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