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