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