1 /*****************************************************************************
2 * main_interface.cpp : Main interface
3 ****************************************************************************
4 * Copyright (C) 2006-2010 VideoLAN and AUTHORS
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Jean-Baptiste Kempf <jb@videolan.org>
9 * Ilkka Ollakka <ileoo@videolan.org>
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.
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.
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 Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
32 #include "main_interface.hpp"
33 #include "input_manager.hpp" // Creation
34 #include "actions_manager.hpp" // killInstance
35 #include "extensions_manager.hpp" // killInstance
37 #include "util/customwidgets.hpp" // qtEventToVLCKey
38 #include "util/qt_dirs.hpp" // toNativeSeparators
40 #include "components/interface_widgets.hpp" // bgWidget, videoWidget
41 #include "components/controller.hpp" // controllers
42 #include "components/playlist/playlist.hpp" // plWidget
43 #include "dialogs/firstrun.hpp" // First Run
45 #include "menus.hpp" // Menu creation
46 #include "recents.hpp" // RecentItems when DnD
48 #include <QCloseEvent>
59 #include <QStackedWidget>
61 #include <vlc_keys.h> /* Wheel event */
62 #include <vlc_vout_display.h> /* vout_thread_t and VOUT_ events */
64 #ifdef WIN32 /* Win7 taskbar */
65 #include <vlc_windows_interfaces.h>
71 /* Callback prototypes */
72 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
73 vlc_value_t old_val, vlc_value_t new_val, void *param );
74 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
75 vlc_value_t old_val, vlc_value_t new_val, void *param );
77 MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
79 /* Variables initialisation */
82 playlistWidget = NULL;
86 fullscreenControls = NULL;
91 b_hideAfterCreation = false; // --qt-start-minimized
92 playlistVisible = false; // FIXME remove
98 FirstRun::CheckAndRun( this, p_intf );
101 * Configuration and settings
102 * Pre-building of interface
105 setFocusPolicy( Qt::StrongFocus );
106 setAcceptDrops( true );
107 setWindowRole( "vlc-main" );
108 setWindowIcon( QApplication::windowIcon() );
109 setWindowOpacity( var_InheritFloat( p_intf, "qt-opacity" ) );
111 /* Is video in embedded in the UI or not */
112 b_videoEmbedded = var_InheritBool( p_intf, "embedded-video" );
114 /* Does the interface resize to video size or the opposite */
115 b_keep_size = !var_InheritBool( p_intf, "qt-video-autoresize" );
117 /* Are we in the enhanced always-video mode or not ? */
118 i_visualmode = var_InheritInteger( p_intf, "qt-minimal-view" );
120 /* Do we want anoying popups or not */
121 b_notificationEnabled = var_InheritBool( p_intf, "qt-notification" );
123 /* Set the other interface settings */
124 settings = getSettings();
125 settings->beginGroup( "MainWindow" );
128 b_plDocked = getSettings()->value( "pl-dock-status", true ).toBool();
132 * Retrieve saved sizes for main window
133 * mainBasedSize = based window size for normal mode
134 * (no video, no background)
135 * mainVideoSize = window size with video (all modes)
137 mainBasedSize = settings->value( "mainBasedSize", QSize( 350, 120 ) ).toSize();
138 mainVideoSize = settings->value( "mainVideoSize", QSize( 400, 300 ) ).toSize();
146 /**************************
147 * UI and Widgets design
148 **************************/
149 setVLCWindowsTitle();
150 createMainWidget( settings );
155 QVLCMenu::createMenuBar( this, p_intf );
156 CONNECT( THEMIM->getIM(), voutListChanged( vout_thread_t **, int ),
157 this, destroyPopupMenu() );
159 /*********************************
160 * Create the Systray Management *
161 *********************************/
164 /********************
166 ********************/
167 MainInputManager::getInstance( p_intf );
172 taskbar_wmsg = RegisterWindowMessage("TaskbarButtonCreated");
175 /************************************************************
176 * Connect the input manager to the GUI elements it manages *
177 ************************************************************/
179 * Connects on nameChanged()
180 * Those connects are different because options can impeach them to trigger.
182 /* Main Interface statusbar */
183 CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
184 this, setName( const QString& ) );
189 CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
190 this, updateSystrayTooltipName( const QString& ) );
193 /* and title of the Main Interface*/
194 if( var_InheritBool( p_intf, "qt-name-in-title" ) )
196 CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
197 this, setVLCWindowsTitle( const QString& ) );
201 * CONNECTS on PLAY_STATUS
203 /* Status on the systray */
207 CONNECT( THEMIM->getIM(), statusChanged( int ),
208 this, updateSystrayTooltipStatus( int ) );
212 /* END CONNECTS ON IM */
214 /* VideoWidget connects for asynchronous calls */
215 connect( this, SIGNAL(askGetVideo(WId*,int*,int*,unsigned*,unsigned *)),
216 this, SLOT(getVideoSlot(WId*,int*,int*,unsigned*,unsigned*)),
217 Qt::BlockingQueuedConnection );
218 connect( this, SIGNAL(askReleaseVideo( void )),
219 this, SLOT(releaseVideoSlot( void )),
220 Qt::BlockingQueuedConnection );
224 CONNECT( this, askVideoToResize( unsigned int, unsigned int ),
225 videoWidget, SetSizing( unsigned int, unsigned int ) );
226 CONNECT( this, askVideoSetFullScreen( bool ),
227 videoWidget, SetFullScreen( bool ) );
228 CONNECT( videoWidget, keyPressed( QKeyEvent * ),
229 this, handleKeyPress( QKeyEvent * ) );
232 CONNECT( this, askUpdate(), this, doComponentsUpdate() );
233 CONNECT( THEDP, toolBarConfUpdated(), this, recreateToolbars() );
235 /* Enable the popup menu in the MI */
236 setContextMenuPolicy( Qt::CustomContextMenu );
237 CONNECT( this, customContextMenuRequested( const QPoint& ),
238 this, popupMenu( const QPoint& ) );
240 /** END of CONNECTS**/
246 var_AddCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
248 /* Register callback for the intf-popupmenu variable */
249 var_AddCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
251 /**** FINAL SIZING and placement of interface */
252 settings->beginGroup( "MainWindow" );
253 QVLCTools::restoreWidgetPosition( settings, this, QSize(400, 100) );
255 /* resize to previously saved main window size if appicable */
260 resize( mainVideoSize );
262 resize( mainBasedSize );
266 int i_plVis = settings->value( "playlist-visible", 0 ).toInt();
268 settings->endGroup();
270 if( i_plVis ) togglePlaylist();
272 /* Final sizing and showing */
273 setVisible( !b_hideAfterCreation );
275 setMinimumWidth( __MAX( controls->sizeHint().width(),
276 menuBar()->sizeHint().width() ) + 30 );
278 /* Switch to minimal view if needed, must be called after the show() */
280 toggleMinimalView( true );
283 MainInterface::~MainInterface()
285 /* Unsure we hide the videoWidget before destroying it */
286 if( stackCentralOldWidget == playlistWidget )
289 /* Save playlist state */
293 QVLCTools::saveWidgetPosition( p_intf, "Playlist", playlistWidget );
295 delete playlistWidget;
300 ImageList_Destroy( himl );
302 p_taskbl->vt->Release(p_taskbl);
306 /* Be sure to kill the actionsManager... FIXME */
307 ActionsManager::killInstance();
310 ExtensionsManager::killInstance();
312 /* Delete the FSC controller */
313 delete fullscreenControls;
316 settings->beginGroup( "MainWindow" );
317 settings->setValue( "pl-dock-status", b_plDocked );
318 settings->setValue( "playlist-visible", (int)playlistVisible );
319 settings->setValue( "adv-controls",
320 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
322 settings->setValue( "mainBasedSize", mainBasedSize );
323 settings->setValue( "mainVideoSize", mainVideoSize );
325 settings->setValue( "backgroundSize", bgWidget->size() );
328 QVLCTools::saveWidgetPosition(settings, this);
329 settings->endGroup();
333 /* Unregister callbacks */
334 var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
335 var_DelCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
337 p_intf->p_sys->p_mi = NULL;
340 /*****************************
342 *****************************/
343 void MainInterface::recreateToolbars()
345 // FIXME: do the same for the FSC
346 //msg_Dbg( p_intf, "Recreating the toolbars" );
347 settings->beginGroup( "MainWindow" );
351 controls = new ControlsWidget( p_intf, false, this ); /* FIXME */
352 CONNECT( controls, advancedControlsToggled( bool ),
353 this, doComponentsUpdate() );
354 CONNECT( controls, sizeChanged(),
355 this, doComponentsUpdate() );
357 inputC = new InputControlsWidget( p_intf, this );
359 mainLayout->insertWidget( 2, inputC );
360 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
362 settings->endGroup();
365 void MainInterface::createMainWidget( QSettings *settings )
367 /* Create the main Widget and the mainLayout */
368 QWidget *main = new QWidget;
369 setCentralWidget( main );
370 mainLayout = new QVBoxLayout( main );
371 main->setContentsMargins( 0, 0, 0, 0 );
372 mainLayout->setSpacing( 0 ); mainLayout->setMargin( 0 );
375 stackCentralW = new QStackedWidget( main );
378 bgWidget = new BackgroundWidget( p_intf );
379 stackCentralW->addWidget( bgWidget );
381 /* And video Outputs */
382 if( b_videoEmbedded )
384 videoWidget = new VideoWidget( p_intf );
385 stackCentralW->addWidget( videoWidget );
387 mainLayout->insertWidget( 1, stackCentralW );
389 /* Create the CONTROLS Widget */
390 controls = new ControlsWidget( p_intf,
391 settings->value( "adv-controls", false ).toBool(), this );
392 CONNECT( controls, advancedControlsToggled( bool ),
393 this, doComponentsUpdate() );
394 CONNECT( controls, sizeChanged(),
395 this, doComponentsUpdate() );
396 inputC = new InputControlsWidget( p_intf, this );
398 mainLayout->insertWidget( 2, inputC );
399 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
402 /* Visualisation, disabled for now, they SUCK */
404 visualSelector = new VisualSelector( p_intf );
405 mainLayout->insertWidget( 0, visualSelector );
406 visualSelector->hide();
409 getSettings()->endGroup();
411 if ( depth() > 8 ) /* 8bit depth has too many issues with opacity */
412 /* Create the FULLSCREEN CONTROLS Widget */
413 if( var_InheritBool( p_intf, "qt-fs-controller" ) )
415 fullscreenControls = new FullscreenControllerWidget( p_intf, this );
416 CONNECT( fullscreenControls, keyPressed( QKeyEvent * ),
417 this, handleKeyPress( QKeyEvent * ) );
421 inline void MainInterface::initSystray()
424 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
425 bool b_systrayWanted = var_InheritBool( p_intf, "qt-system-tray" );
427 if( var_InheritBool( p_intf, "qt-start-minimized") )
429 if( b_systrayAvailable )
431 b_systrayWanted = true;
432 b_hideAfterCreation = true;
435 msg_Err( p_intf, "cannot start minimized without system tray bar" );
438 if( b_systrayAvailable && b_systrayWanted )
443 inline void MainInterface::createStatusBar()
448 /* Widgets Creation*/
449 QStatusBar *statusBarr = statusBar();
451 TimeLabel *timeLabel = new TimeLabel( p_intf );
452 nameLabel = new QLabel( this );
453 nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
454 | Qt::TextSelectableByKeyboard );
455 SpeedLabel *speedLabel = new SpeedLabel( p_intf, this );
457 /* Styling those labels */
458 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
459 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
460 nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
462 /* and adding those */
463 statusBarr->addWidget( nameLabel, 8 );
464 statusBarr->addPermanentWidget( speedLabel, 0 );
465 statusBarr->addPermanentWidget( timeLabel, 0 );
467 /* timeLabel behaviour:
468 - double clicking opens the goto time dialog
469 - right-clicking and clicking just toggle between remaining and
471 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
473 CONNECT( THEMIM->getIM(), encryptionChanged( bool ),
474 this, showCryptedLabel( bool ) );
476 CONNECT( THEMIM->getIM(), seekRequested( float ),
477 timeLabel, setDisplayPosition( float ) );
481 void MainInterface::createTaskBarButtons()
483 taskbar_wmsg = WM_NULL;
484 /*Here is the code for the taskbar thumb buttons
485 FIXME:We need pretty buttons in 16x16 px that are handled correctly by masks in Qt
486 FIXME:the play button's picture doesn't changed to pause when clicked
491 if( S_OK == CoCreateInstance( &clsid_ITaskbarList,
492 NULL, CLSCTX_INPROC_SERVER,
494 (void **)&p_taskbl) )
496 p_taskbl->vt->HrInit(p_taskbl);
498 if(himl = ImageList_Create( 15, //cx
501 4,//initial nb of images
502 0//nb of images that can be added
505 QPixmap img = QPixmap(":/toolbar/previous_b");
506 QPixmap img2 = QPixmap(":/toolbar/pause_b");
507 QPixmap img3 = QPixmap(":/toolbar/play_b");
508 QPixmap img4 = QPixmap(":/toolbar/next_b");
509 QBitmap mask = img.createMaskFromColor(Qt::transparent);
510 QBitmap mask2 = img2.createMaskFromColor(Qt::transparent);
511 QBitmap mask3 = img3.createMaskFromColor(Qt::transparent);
512 QBitmap mask4 = img4.createMaskFromColor(Qt::transparent);
514 if(-1 == ImageList_Add(himl, img.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask.toWinHBITMAP()))
515 msg_Err( p_intf, "ImageList_Add failed" );
516 if(-1 == ImageList_Add(himl, img2.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask2.toWinHBITMAP()))
517 msg_Err( p_intf, "ImageList_Add failed" );
518 if(-1 == ImageList_Add(himl, img3.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask3.toWinHBITMAP()))
519 msg_Err( p_intf, "ImageList_Add failed" );
520 if(-1 == ImageList_Add(himl, img4.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask4.toWinHBITMAP()))
521 msg_Err( p_intf, "ImageList_Add failed" );
524 // Define an array of two buttons. These buttons provide images through an
525 // image list and also provide tooltips.
526 DWORD dwMask = THB_BITMAP | THB_FLAGS;
528 THUMBBUTTON thbButtons[3];
529 thbButtons[0].dwMask = dwMask;
530 thbButtons[0].iId = 0;
531 thbButtons[0].iBitmap = 0;
532 thbButtons[0].dwFlags = THBF_HIDDEN;
534 thbButtons[1].dwMask = dwMask;
535 thbButtons[1].iId = 1;
536 thbButtons[1].iBitmap = 2;
537 thbButtons[1].dwFlags = THBF_HIDDEN;
539 thbButtons[2].dwMask = dwMask;
540 thbButtons[2].iId = 2;
541 thbButtons[2].iBitmap = 3;
542 thbButtons[2].dwFlags = THBF_HIDDEN;
544 HRESULT hr = p_taskbl->vt->ThumbBarSetImageList(p_taskbl, winId(), himl );
546 msg_Err( p_intf, "ThumbBarSetImageList failed with error %08x", hr );
549 hr = p_taskbl->vt->ThumbBarAddButtons(p_taskbl, winId(), 3, thbButtons);
551 msg_Err( p_intf, "ThumbBarAddButtons failed with error %08x", hr );
553 CONNECT( THEMIM->getIM(), statusChanged( int ), this, changeThumbbarButtons( int ) );
563 bool MainInterface::winEvent ( MSG * msg, long * result )
565 if (msg->message == taskbar_wmsg)
567 //We received the taskbarbuttoncreated, now we can really create th buttons
568 createTaskBarButtons();
572 switch( msg->message )
575 if (HIWORD(msg->wParam) == THBN_CLICKED)
577 switch(LOWORD(msg->wParam))
583 THEMIM->togglePlayPause();
592 cmd = GET_APPCOMMAND_LPARAM(msg->lParam);
595 case APPCOMMAND_MEDIA_PLAY_PAUSE:
596 THEMIM->togglePlayPause();
598 case APPCOMMAND_MEDIA_PLAY:
601 case APPCOMMAND_MEDIA_PAUSE:
604 case APPCOMMAND_MEDIA_PREVIOUSTRACK:
607 case APPCOMMAND_MEDIA_NEXTTRACK:
610 case APPCOMMAND_MEDIA_STOP:
613 case APPCOMMAND_VOLUME_DOWN:
616 case APPCOMMAND_VOLUME_UP:
619 case APPCOMMAND_VOLUME_MUTE:
620 THEAM->toggleMuteAudio();
623 msg_Dbg( p_intf, "unknown APPCOMMAND = %d", cmd);
632 /**********************************************************************
633 * Handling of sizing of the components
634 **********************************************************************/
636 /* This function is probably wrong, but we don't have many many choices...
637 Since we can't know from the playlist Widget if we are inside a dock or not,
638 because the playlist Widget can be called by THEDP, as a separate windows for
640 Maybe the other solution is to redefine the sizeHint() of the playlist and
641 ask _parent->isFloating()...
642 If you think this would be better, please FIXME it...
646 QSize MainInterface::sizeHint() const
653 return mainVideoSize;
657 if( VISIBLE( bgWidget) ||
658 ( videoIsActive && videoWidget->isVisible() )
660 return mainVideoSize;
662 return mainBasedSize;
667 int nwidth = __MAX( controls->sizeHint().width(),
668 menuBar()->sizeHint().width() );
670 int nheight = controls->isVisible() ?
671 controls->size().height()
672 + inputC->size().height()
673 + menuBar()->size().height()
674 + statusBar()->size().height()
677 /* if( stackCentralW->isVisible() )
679 nheight += stackCentralW->height();
680 nwidth = __MAX( nwidth, stackCentralW->width() );
683 /* if( VISIBLE( bgWidget ) )
685 msg_Warn( p_intf, "Hello here" );
687 nheight += i_bg_height;
689 nheight += bgWidget->size().height();
690 nwidth = __MAX( nwidth, bgWidget->size().width() );
692 else if( videoIsActive && videoWidget->isVisible() )
694 msg_Warn( p_intf, "Hello there" );
695 nheight += videoWidget->sizeHint().height();
696 nwidth = __MAX( nwidth, videoWidget->sizeHint().width() );
699 if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget() )
701 nheight += dockPL->size().height();
702 nwidth = __MAX( nwidth, dockPL->size().width() );
703 msg_Warn( p_intf, "3 %i %i", nheight, nwidth );
706 return QSize( nwidth, nheight );
710 /* Video widget cannot do this synchronously as it runs in another thread */
711 /* Well, could it, actually ? Probably dangerous ... */
713 /* This function is called:
714 - toggling of minimal View
715 - through askUpdate() by Vout thread request video and resize video (zoom)
716 - Advanced buttons toggled
718 void MainInterface::doComponentsUpdate()
720 if( isFullScreen() || isMaximized() ) return;
722 // msg_Warn( p_intf, "Updating the geometry" );
723 /* Here we resize to sizeHint() and not adjustsize because we want
724 the videoWidget to be exactly the correctSize */
729 /* This is WRONG, but I believe there is a Qt bug here */
730 setMinimumSize( 0, 0 );
731 //resize( sizeHint() );
733 //adjustSize() ; /* This is not needed, but might help in the future */
736 void MainInterface::debug()
739 msg_Dbg( p_intf, "Stack Size: %i - %i", stackCentralW->size().height(), size().width() );
741 msg_Dbg( p_intf, "Stack Size: %i - %i",
742 videoWidget->size().height(),
743 videoWidget->size().width() );
745 msg_Dbg( p_intf, "no embedded video" );
747 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
748 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
749 //msg_Dbg( p_intf, "maximumsize: %i - %i", maximumSize().height(), maximumSize().width() );
751 msg_Dbg( p_intf, "Stack size: %i - %i", stackCentralW->size().height(), stackCentralW->size().width() );
752 msg_Dbg( p_intf, "Stack minimumSize(): %i - %i", stackCentralW->minimumHeight(), stackCentralW->minimumWidth() );
753 msg_Dbg( p_intf, "Central minimumsize: %i - %i", centralWidget()->minimumSize().height(), centralWidget()->minimumSize().width() );
754 msg_Dbg( p_intf, "Central size: %i - %i", centralWidget()->size().height(), centralWidget()->size().width() );
755 msg_Dbg( p_intf, "Menu minimumsize: %i - %i", menuBar()->minimumSize().height(), menuBar()->minimumSize().width() );
756 msg_Dbg( p_intf, "Input size: %i - %i", inputC->size().height(), inputC->size().width() );
757 msg_Dbg( p_intf, "Status minimumsize: %i - %i", statusBar()->minimumSize().height(), statusBar()->minimumSize().width() );
758 msg_Dbg( p_intf, "minimumsize: %i - %i", minimumSize().height(), minimumSize().width() );
759 msg_Dbg( p_intf, "bg Size: %i - %i", bgWidget->size().height(), bgWidget->size().width() );
761 /*if( videoWidget && videoWidget->isVisible() )
763 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
764 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
769 inline void MainInterface::showVideo() { showTab( videoWidget ); }
770 inline void MainInterface::showBg() { showTab( bgWidget ); }
772 inline void MainInterface::showTab( QWidget *widget )
775 msg_Warn( p_intf, "Old stackCentralOldWidget %i", stackCentralW->indexOf( stackCentralOldWidget ) );
777 stackCentralOldWidget = stackCentralW->currentWidget();
778 stackCentralW->setCurrentWidget( widget );
781 msg_Warn( p_intf, "State change %i", stackCentralW->currentIndex() );
782 msg_Warn( p_intf, "New stackCentralOldWidget %i", stackCentralW->indexOf( stackCentralOldWidget ) );
786 inline void MainInterface::restoreStackOldWidget()
789 msg_Warn( p_intf, "New stackCentralOldWidget %i", stackCentralW->indexOf( stackCentralOldWidget ) );
791 QWidget *wTemp = stackCentralW->currentWidget();
793 stackCentralW->setCurrentWidget( stackCentralOldWidget );
795 stackCentralOldWidget = wTemp;
797 msg_Warn( p_intf, "Debug %i %i",stackCentralW->indexOf( wTemp ), stackCentralW->indexOf( stackCentralW->currentWidget() ) );
801 void MainInterface::destroyPopupMenu()
803 QVLCMenu::PopupMenu( p_intf, false );
806 void MainInterface::popupMenu( const QPoint &p )
809 * Ow, that's ugly: don't show the popup menu if cursor over
810 * the main menu bar or the status bar */
811 if( !childAt( p ) || ( ( childAt( p ) != menuBar() )
812 && ( childAt( p )->parentWidget() != statusBar() ) ) )
813 QVLCMenu::PopupMenu( p_intf, true );
816 void MainInterface::toggleFSC()
818 if( !fullscreenControls ) return;
820 IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
821 QApplication::postEvent( fullscreenControls, eShow );
824 /****************************************************************************
826 ****************************************************************************/
828 /* This event is used to deal with the fullscreen and always on top
829 issue conflict (bug in wx) */
830 class SetVideoOnTopQtEvent : public QEvent
833 SetVideoOnTopQtEvent( bool _onTop ) :
834 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
837 bool OnTop() const { return onTop; }
845 * You must not change the state of this object or other Qt4 UI objects,
846 * from the video output thread - only from the Qt4 UI main loop thread.
847 * All window provider queries must be handled through signals or events.
848 * That's why we have all those emit statements...
850 WId MainInterface::getVideo( int *pi_x, int *pi_y,
851 unsigned int *pi_width, unsigned int *pi_height )
856 /* This is a blocking call signal. Results are returned through pointers.
857 * Beware of deadlocks! */
859 emit askGetVideo( &id, pi_x, pi_y, pi_width, pi_height );
863 void MainInterface::getVideoSlot( WId *p_id, int *pi_x, int *pi_y,
864 unsigned *pi_width, unsigned *pi_height )
866 /* Request the videoWidget */
867 WId ret = videoWidget->request( pi_x, pi_y,
868 pi_width, pi_height, b_keep_size );
870 if( ret ) /* The videoWidget is available */
872 /* ask videoWidget to show */
873 videoWidget->SetSizing( *pi_width, *pi_height );
875 /* Consider the video active now */
878 stackCentralW->resize( *pi_width, *pi_height );
886 /* Asynchronous call from the WindowClose function */
887 void MainInterface::releaseVideo( void )
889 emit askReleaseVideo( );
892 /* Function that is CONNECTED to the previous emit */
893 void MainInterface::releaseVideoSlot( void )
895 videoWidget->release( );
897 restoreStackOldWidget();
899 /* We don't want to have a blank video to popup */
900 stackCentralOldWidget = bgWidget;
902 /* Try to resize, except when you are in Fullscreen mode */
903 // doComponentsUpdate();
906 /* Asynchronous call from WindowControl function */
907 int MainInterface::controlVideo( int i_query, va_list args )
909 /* Debug to check if VOUT_WINDOW_SET_SIZE is called, because this is broken now */
910 msg_Warn( p_intf, "Control Video: %i", i_query );
913 case VOUT_WINDOW_SET_SIZE:
915 unsigned int i_width = va_arg( args, unsigned int );
916 unsigned int i_height = va_arg( args, unsigned int );
917 emit askVideoToResize( i_width, i_height );
921 case VOUT_WINDOW_SET_STATE:
923 unsigned i_arg = va_arg( args, unsigned );
924 unsigned on_top = i_arg & VOUT_WINDOW_STATE_ABOVE;
925 QApplication::postEvent( this, new SetVideoOnTopQtEvent( on_top ) );
928 case VOUT_WINDOW_SET_FULLSCREEN:
930 bool b_fs = va_arg( args, int );
931 emit askVideoSetFullScreen( b_fs );
935 msg_Warn( p_intf, "unsupported control query" );
940 /*****************************************************************************
941 * Playlist, Visualisation and Menus handling
942 *****************************************************************************/
944 * Toggle the playlist widget or dialog
946 void MainInterface::createPlaylist()
948 playlistWidget = new PlaylistWidget( p_intf, this );
952 playlistWidget->setWindowFlags( Qt::Window );
954 /* This will restore the geometry but will not work for position,
955 because of parenting */
956 QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
957 playlistWidget, QSize( 600, 300 ) );
961 stackCentralW->addWidget( playlistWidget );
965 void MainInterface::togglePlaylist()
967 if( !playlistWidget )
972 /* Playlist is not visible, show it */
973 if( stackCentralW->currentWidget() != playlistWidget )
975 playlistWidget->forceShow();
976 showTab( playlistWidget );
980 restoreStackOldWidget();
981 stackCentralW->updateGeometry();
982 // HACK: So it doesn't limit the stackWidget minimumSize
983 playlistWidget->forceHide();
985 playlistVisible = ( stackCentralW->currentWidget() == playlistWidget );
989 playlistWidget->setWindowFlags( Qt::Window );
990 playlistVisible = !playlistVisible;
991 playlistWidget->setVisible( playlistVisible );
996 void MainInterface::dockPlaylist( bool p_docked )
998 if( b_plDocked == p_docked ) return;
999 b_plDocked = p_docked;
1001 if( !playlistWidget ) return; /* Playlist wasn't created yet */
1004 stackCentralW->removeWidget( playlistWidget );
1005 playlistWidget->setWindowFlags( Qt::Window );
1006 QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
1007 playlistWidget, QSize( 600, 300 ) );
1008 playlistWidget->show();
1009 restoreStackOldWidget();
1013 playlistWidget->setWindowFlags( Qt::Widget ); // Probably a Qt bug here
1014 // It would be logical that QStackWidget::addWidget reset the flags...
1015 stackCentralW->addWidget( playlistWidget );
1016 stackCentralW->setCurrentWidget( playlistWidget );
1020 void MainInterface::toggleMinimalView( bool b_switch )
1022 if( i_visualmode == 0 )
1023 { /* NORMAL MODE then */
1024 if( !videoWidget || stackCentralW->currentWidget() != videoWidget )
1030 /* If video is visible, then toggle the status of bgWidget */
1032 //bgWasVisible = !bgWasVisible;
1033 /* if( stackCentralOldState == BACK G_TAB )
1034 stackCentralOldState = HID DEN_TAB;
1036 stackCentralOldState = BACK G_TAB;
1042 i_bg_height = stackCentralW->height();
1044 menuBar()->setVisible( !b_switch );
1045 controls->setVisible( !b_switch );
1046 statusBar()->setVisible( !b_switch );
1047 inputC->setVisible( !b_switch );
1049 doComponentsUpdate();
1051 emit minimalViewToggled( b_switch );
1054 /* toggling advanced controls buttons */
1055 void MainInterface::toggleAdvanced()
1057 controls->toggleAdvanced();
1058 // if( fullscreenControls ) fullscreenControls->toggleAdvanced();
1061 /* Get the visibility status of the controls (hidden or not, advanced or not) */
1062 int MainInterface::getControlsVisibilityStatus()
1064 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
1065 + CONTROLS_ADVANCED * controls->b_advancedVisible );
1069 void MainInterface::visual()
1071 if( !VISIBLE( visualSelector) )
1073 visualSelector->show();
1074 if( !THEMIM->getIM()->hasVideo() )
1076 /* Show the background widget */
1078 visualSelectorEnabled = true;
1082 /* Stop any currently running visualization */
1083 visualSelector->hide();
1084 visualSelectorEnabled = false;
1086 doComponentsUpdate();
1090 /************************************************************************
1092 ************************************************************************/
1093 void MainInterface::setName( const QString& name )
1095 input_name = name; /* store it for the QSystray use */
1096 /* Display it in the status bar, but also as a Tooltip in case it doesn't
1098 nameLabel->setText( " " + name + " " );
1099 nameLabel->setToolTip( " " + name +" " );
1103 * Give the decorations of the Main Window a correct Name.
1104 * If nothing is given, set it to VLC...
1106 void MainInterface::setVLCWindowsTitle( const QString& aTitle )
1108 if( aTitle.isEmpty() )
1110 setWindowTitle( qtr( "VLC media player" ) );
1114 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
1118 void MainInterface::showCryptedLabel( bool b_show )
1120 if( cryptedLabel == NULL )
1122 cryptedLabel = new QLabel;
1123 // The lock icon is not the right one for DRM protection/scrambled.
1124 //cryptedLabel->setPixmap( QPixmap( ":/lock" ) );
1125 cryptedLabel->setText( "DRM" );
1126 statusBar()->addWidget( cryptedLabel );
1129 cryptedLabel->setVisible( b_show );
1132 void MainInterface::showBuffering( float f_cache )
1134 QString amount = QString("Buffering: %1%").arg( (int)(100*f_cache) );
1135 statusBar()->showMessage( amount, 1000 );
1138 /*****************************************************************************
1139 * Systray Icon and Systray Menu
1140 *****************************************************************************/
1143 * Create a SystemTray icon and a menu that would go with it.
1144 * Connects to a click handler on the icon.
1146 void MainInterface::createSystray()
1149 if( QDate::currentDate().dayOfYear() >= 354 )
1150 iconVLC = QIcon( ":/logo/vlc128-christmas.png" );
1152 iconVLC = QIcon( ":/logo/vlc128.png" );
1153 sysTray = new QSystemTrayIcon( iconVLC, this );
1154 sysTray->setToolTip( qtr( "VLC media player" ));
1156 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
1157 systrayMenu->setIcon( iconVLC );
1159 QVLCMenu::updateSystrayMenu( this, p_intf, true );
1162 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
1163 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
1167 * Updates the Systray Icon's menu and toggle the main interface
1169 void MainInterface::toggleUpdateSystrayMenu()
1171 /* If hidden, show it */
1177 else if( isMinimized() )
1185 /* Visible (possibly under other windows) */
1187 /* check if any visible window is above vlc in the z-order,
1188 * but ignore the ones always on top
1189 * and the ones which can't be activated */
1192 wi.cbSize = sizeof( WINDOWINFO );
1193 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
1194 hwnd && ( !IsWindowVisible( hwnd ) ||
1195 ( GetWindowInfo( hwnd, &wi ) &&
1196 (wi.dwExStyle&WS_EX_NOACTIVATE) ) );
1197 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
1198 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
1199 (wi.dwExStyle&WS_EX_TOPMOST) )
1211 QVLCMenu::updateSystrayMenu( this, p_intf );
1214 void MainInterface::handleSystrayClick(
1215 QSystemTrayIcon::ActivationReason reason )
1219 case QSystemTrayIcon::Trigger:
1220 case QSystemTrayIcon::DoubleClick:
1221 toggleUpdateSystrayMenu();
1223 case QSystemTrayIcon::MiddleClick:
1224 sysTray->showMessage( qtr( "VLC media player" ),
1225 qtr( "Control menu for the player" ),
1226 QSystemTrayIcon::Information, 3000 );
1234 * Updates the name of the systray Icon tooltip.
1235 * Doesn't check if the systray exists, check before you call it.
1237 void MainInterface::updateSystrayTooltipName( const QString& name )
1239 if( name.isEmpty() )
1241 sysTray->setToolTip( qtr( "VLC media player" ) );
1245 sysTray->setToolTip( name );
1246 if( b_notificationEnabled && ( isHidden() || isMinimized() ) )
1248 sysTray->showMessage( qtr( "VLC media player" ), name,
1249 QSystemTrayIcon::NoIcon, 3000 );
1253 QVLCMenu::updateSystrayMenu( this, p_intf );
1257 * Updates the status of the systray Icon tooltip.
1258 * Doesn't check if the systray exists, check before you call it.
1260 void MainInterface::updateSystrayTooltipStatus( int i_status )
1267 sysTray->setToolTip( qtr( "VLC media player" ) );
1272 sysTray->setToolTip( input_name );
1277 sysTray->setToolTip( input_name + " - "
1282 QVLCMenu::updateSystrayMenu( this, p_intf );
1286 /************************************************************************
1288 ************************************************************************/
1289 void MainInterface::dropEvent(QDropEvent *event)
1291 dropEventPlay( event, true );
1294 void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
1296 event->setDropAction( Qt::CopyAction );
1297 if( !event->possibleActions() & Qt::CopyAction )
1300 const QMimeData *mimeData = event->mimeData();
1302 /* D&D of a subtitles file, add it on the fly */
1303 if( mimeData->urls().size() == 1 && THEMIM->getIM()->hasInput() )
1305 if( !input_AddSubtitle( THEMIM->getInput(),
1306 qtu( toNativeSeparators( mimeData->urls()[0].toLocalFile() ) ),
1314 bool first = b_play;
1315 foreach( const QUrl &url, mimeData->urls() )
1317 QString s = toNativeSeparators( url.toLocalFile() );
1319 if( s.length() > 0 ) {
1320 char* psz_uri = make_URI( qtu(s) );
1321 playlist_Add( THEPL, psz_uri, NULL,
1322 PLAYLIST_APPEND | (first ? PLAYLIST_GO: PLAYLIST_PREPARSE),
1323 PLAYLIST_END, true, pl_Unlocked );
1326 RecentsMRL::getInstance( p_intf )->addRecent( s );
1331 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1333 event->acceptProposedAction();
1335 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1337 event->acceptProposedAction();
1339 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1344 /************************************************************************
1346 ************************************************************************/
1347 void MainInterface::customEvent( QEvent *event )
1350 if( event->type() == PLDockEvent_Type )
1352 PlaylistDialog::killInstance();
1353 playlistEmbeddedFlag = true;
1355 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1360 if ( event->type() == (int)SetVideoOnTopEvent_Type )
1362 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1363 if( p_event->OnTop() )
1364 setWindowFlags( windowFlags() | Qt::WindowStaysOnTopHint );
1366 setWindowFlags( windowFlags() & ~Qt::WindowStaysOnTopHint );
1367 show(); /* necessary to apply window flags */
1371 void MainInterface::keyPressEvent( QKeyEvent *e )
1373 handleKeyPress( e );
1376 void MainInterface::handleKeyPress( QKeyEvent *e )
1378 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() == Qt::Key_H )
1379 && !menuBar()->isVisible() )
1381 toggleMinimalView( false );
1385 int i_vlck = qtEventToVLCKey( e );
1388 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1395 void MainInterface::resizeEvent( QResizeEvent * event )
1402 mainVideoSize = size();
1406 if( VISIBLE( bgWidget) ||
1407 ( videoIsActive && videoWidget->isVisible() )
1409 mainVideoSize = size();
1411 mainBasedSize = size();
1415 QVLCMW::resizeEvent( event );
1416 msg_Dbg( p_intf, "Resize Event, height: %i", size().height() );
1420 void MainInterface::wheelEvent( QWheelEvent *e )
1422 int i_vlckey = qtWheelEventToVLCKey( e );
1423 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1427 void MainInterface::closeEvent( QCloseEvent *e )
1434 void MainInterface::toggleFullScreen( void )
1436 if( isFullScreen() )
1439 emit askUpdate(); // Needed if video was launched after the F11
1440 emit fullscreenInterfaceToggled( false );
1445 emit fullscreenInterfaceToggled( true );
1450 //moc doesn't know about #ifdef, so we have to build this method for every platform
1451 void MainInterface::changeThumbbarButtons( int i_status)
1454 // Define an array of three buttons. These buttons provide images through an
1455 // image list and also provide tooltips.
1456 DWORD dwMask = THB_BITMAP | THB_FLAGS;
1458 THUMBBUTTON thbButtons[3];
1460 thbButtons[0].dwMask = dwMask;
1461 thbButtons[0].iId = 0;
1462 thbButtons[0].iBitmap = 0;
1465 thbButtons[1].dwMask = dwMask;
1466 thbButtons[1].iId = 1;
1469 thbButtons[2].dwMask = dwMask;
1470 thbButtons[2].iId = 2;
1471 thbButtons[2].iBitmap = 3;
1477 thbButtons[0].dwFlags = THBF_ENABLED;
1478 thbButtons[1].dwFlags = THBF_ENABLED;
1479 thbButtons[2].dwFlags = THBF_ENABLED;
1480 thbButtons[1].iBitmap = 1;
1485 thbButtons[0].dwFlags = THBF_ENABLED;
1486 thbButtons[1].dwFlags = THBF_ENABLED;
1487 thbButtons[2].dwFlags = THBF_ENABLED;
1488 thbButtons[1].iBitmap = 2;
1494 HRESULT hr = p_taskbl->vt->ThumbBarUpdateButtons(p_taskbl, this->winId(), 3, thbButtons);
1496 msg_Err( p_intf, "ThumbBarUpdateButtons failed with error %08x", hr );
1502 /*****************************************************************************
1503 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1504 * We don't show the menu directly here because we don't want the
1505 * caller to block for a too long time.
1506 *****************************************************************************/
1507 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1508 vlc_value_t old_val, vlc_value_t new_val, void *param )
1510 intf_thread_t *p_intf = (intf_thread_t *)param;
1512 if( p_intf->pf_show_dialog )
1514 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1515 new_val.b_bool, NULL );
1521 /*****************************************************************************
1522 * IntfShowCB: callback triggered by the intf-show libvlc variable.
1523 *****************************************************************************/
1524 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1525 vlc_value_t old_val, vlc_value_t new_val, void *param )
1527 intf_thread_t *p_intf = (intf_thread_t *)param;
1528 p_intf->p_sys->p_mi->toggleFSC();