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