1 /*****************************************************************************
2 * main_interface.cpp : Main interface
3 ****************************************************************************
4 * Copyright (C) 2006-2009 the VideoLAN team
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
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
32 #include "main_interface.hpp"
33 #include "input_manager.hpp"
34 #include "actions_manager.hpp"
36 #include "util/customwidgets.hpp"
37 #include "util/qt_dirs.hpp"
39 #include "components/interface_widgets.hpp"
40 #include "components/controller.hpp"
41 #include "components/playlist/playlist.hpp"
42 #include "dialogs/external.hpp"
43 #include "dialogs/firstrun.hpp"
46 #include "recents.hpp"
48 #include <QCloseEvent>
60 #include <QPushButton>
61 #include <QStackedWidget>
64 #include <vlc_windows_interfaces.h>
70 #include <vlc_keys.h> /* Wheel event */
71 #include <vlc_vout_window.h>
74 /* Callback prototypes */
75 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
76 vlc_value_t old_val, vlc_value_t new_val, void *param );
77 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
78 vlc_value_t old_val, vlc_value_t new_val, void *param );
80 MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
82 /* Variables initialisation */
83 // need_components_update = false;
86 playlistWidget = NULL;
90 fullscreenControls = NULL;
95 b_hideAfterCreation = false;
96 playlistVisible = false; // FIXME remove
101 /* Ask for Privacy */
102 new FirstRun( this, p_intf );
105 * Configuration and settings
106 * Pre-building of interface
109 setFocusPolicy( Qt::StrongFocus );
110 setAcceptDrops( true );
111 setWindowRole( "vlc-main" );
112 setWindowIcon( QApplication::windowIcon() );
113 setWindowOpacity( config_GetFloat( p_intf, "qt-opacity" ) );
115 /* Set The Video In emebedded Mode or not */
116 videoEmbeddedFlag = config_GetInt( p_intf, "embedded-video" );
118 /* Does the interface resize to video size or the opposite */
119 b_keep_size = !config_GetInt( p_intf, "qt-video-autoresize" );
121 /* Are we in the enhanced always-video mode or not ? */
122 i_visualmode = config_GetInt( p_intf, "qt-display-mode" );
124 /* Do we want anoying popups or not */
125 notificationEnabled = (bool)config_GetInt( p_intf, "qt-notification" );
127 /* Set the other interface settings */
128 settings = getSettings();
129 settings->beginGroup( "MainWindow" );
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 );
170 createTaskBarButtons();
173 /************************************************************
174 * Connect the input manager to the GUI elements it manages *
175 ************************************************************/
177 * Connects on nameChanged()
178 * Those connects are different because options can impeach them to trigger.
180 /* Main Interface statusbar */
181 CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
182 this, setName( const QString& ) );
187 CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
188 this, updateSystrayTooltipName( const QString& ) );
191 /* and title of the Main Interface*/
192 if( config_GetInt( p_intf, "qt-name-in-title" ) )
194 CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
195 this, setVLCWindowsTitle( const QString& ) );
199 * CONNECTS on PLAY_STATUS
201 /* Status on the systray */
205 CONNECT( THEMIM->getIM(), statusChanged( int ),
206 this, updateSystrayTooltipStatus( int ) );
210 /* END CONNECTS ON IM */
215 var_AddCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
217 /* Register callback for the intf-popupmenu variable */
218 var_AddCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
221 /* VideoWidget connects for asynchronous calls */
222 connect( this, SIGNAL(askGetVideo(WId*,int*,int*,unsigned*,unsigned *)),
223 this, SLOT(getVideoSlot(WId*,int*,int*,unsigned*,unsigned*)),
224 Qt::BlockingQueuedConnection );
225 connect( this, SIGNAL(askReleaseVideo( void )),
226 this, SLOT(releaseVideoSlot( void )),
227 Qt::BlockingQueuedConnection );
231 CONNECT( this, askVideoToResize( unsigned int, unsigned int ),
232 videoWidget, SetSizing( unsigned int, unsigned int ) );
233 CONNECT( this, askVideoSetFullScreen( bool ),
234 videoWidget, SetFullScreen( bool ) );
235 CONNECT( videoWidget, keyPressed( QKeyEvent * ),
236 this, handleKeyPress( QKeyEvent * ) );
239 CONNECT( this, askUpdate(), this, doComponentsUpdate() );
240 CONNECT( THEDP, toolBarConfUpdated(), this, recreateToolbars() );
242 /* Enable the popup menu in the MI */
243 setContextMenuPolicy( Qt::CustomContextMenu );
244 CONNECT( this, customContextMenuRequested( const QPoint& ),
245 this, popupMenu( const QPoint& ) );
247 /** END of CONNECTS**/
250 /**** FINAL SIZING and placement of interface */
251 settings->beginGroup( "MainWindow" );
252 QVLCTools::restoreWidgetPosition( settings, this, QSize(380, 60) );
254 /* resize to previously saved main window size if appicable */
257 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
258 i_visualmode == QT_MINIMAL_MODE )
260 resize( mainVideoSize );
264 resize( mainBasedSize );
268 msg_Dbg( p_intf, "%i", stackCentralOldState );
270 if( settings->value( "playlist-visible", 0 ).toInt() )
272 settings->endGroup();
274 /* Final sizing and showing */
275 setVisible( !b_hideAfterCreation );
276 //setMinimumSize( QSize( 0, 0 ) );
277 // setMinimumWidth( __MAX( controls->sizeHint().width(),
278 // menuBar()->sizeHint().width() ) );
281 /* And switch to minimal view if needed
282 Must be called after the show() */
283 if( i_visualmode == QT_MINIMAL_MODE )
284 toggleMinimalView( true );
286 /* Update the geometry : It is useful if you switch between
289 resize( sizeHint() );
292 MainInterface::~MainInterface()
294 msg_Dbg( p_intf, "Destroying the main interface" );
296 /* Unsure we hide the videoWidget before destroying it */
297 if( stackCentralOldState == VIDEO_TAB )
300 /* Save playlist state */
304 QVLCTools::saveWidgetPosition( p_intf, "Playlist", playlistWidget );
306 delete playlistWidget;
311 ImageList_Destroy( himl );
313 p_taskbl->vt->Release(p_taskbl);
317 /* Be sure to kill the actionsManager... FIXME */
318 ActionsManager::killInstance();
320 /* Delete the FSC controller */
321 delete fullscreenControls;
324 settings->beginGroup( "MainWindow" );
325 settings->setValue( "pl-dock-status", (int)i_pl_dock );
326 settings->setValue( "playlist-visible", (int)playlistVisible );
327 settings->setValue( "adv-controls",
328 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
330 settings->setValue( "mainBasedSize", mainBasedSize );
331 settings->setValue( "mainVideoSize", mainVideoSize );
334 settings->setValue( "backgroundSize", bgWidget->size() );
337 QVLCTools::saveWidgetPosition(settings, this);
338 settings->endGroup();
340 /* Unregister callbacks */
341 var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
342 var_DelCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
344 p_intf->p_sys->p_mi = NULL;
347 /*****************************
349 *****************************/
350 void MainInterface::recreateToolbars()
352 //msg_Dbg( p_intf, "Recreating the toolbars" );
353 settings->beginGroup( "MainWindow" );
357 controls = new ControlsWidget( p_intf, false, this ); /* FIXME */
358 CONNECT( controls, advancedControlsToggled( bool ),
359 this, doComponentsUpdate() );
360 CONNECT( controls, sizeChanged(),
361 this, doComponentsUpdate() );
363 inputC = new InputControlsWidget( p_intf, this );
365 mainLayout->insertWidget( 2, inputC );
366 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
368 settings->endGroup();
371 void MainInterface::createMainWidget( QSettings *settings )
373 /* Create the main Widget and the mainLayout */
374 QWidget *main = new QWidget;
375 setCentralWidget( main );
376 mainLayout = new QVBoxLayout( main );
378 /* Margins, spacing */
379 main->setContentsMargins( 0, 0, 0, 0 );
380 mainLayout->setSpacing( 0 ); mainLayout->setMargin( 0 );
383 stackCentralW = new QStackedWidget( main );
386 bgWidget = new BackgroundWidget( p_intf );
388 settings->value( "backgroundSize", QSize( 300, 200 ) ).toSize() );
389 bgWidget->updateGeometry();
390 stackCentralW->insertWidget( BACKG_TAB, bgWidget );
393 /* And video Outputs */
394 if( videoEmbeddedFlag )
396 videoWidget = new VideoWidget( p_intf );
397 stackCentralW->insertWidget( VIDEO_TAB, videoWidget );
399 mainLayout->insertWidget( 1, stackCentralW, 100 );
402 /* Create the CONTROLS Widget */
403 controls = new ControlsWidget( p_intf,
404 settings->value( "adv-controls", false ).toBool(), this );
405 CONNECT( controls, advancedControlsToggled( bool ),
406 this, doComponentsUpdate() );
407 CONNECT( controls, sizeChanged(),
408 this, doComponentsUpdate() );
409 inputC = new InputControlsWidget( p_intf, this );
411 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
412 i_visualmode != QT_MINIMAL_MODE )
415 stackCentralOldState = HIDDEN_TAB;
419 showTab( BACKG_TAB );
420 stackCentralOldState = BACKG_TAB;
424 //mainLayout->setRowStretch( 1, 10 );
425 mainLayout->insertWidget( 2, inputC );
426 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
430 /* Disabled for now, they SUCK */
432 visualSelector = new VisualSelector( p_intf );
433 mainLayout->insertWidget( 0, visualSelector );
434 visualSelector->hide();
437 /* Finish the sizing */
438 main->updateGeometry();
440 getSettings()->endGroup();
444 /* Create the FULLSCREEN CONTROLS Widget */
445 if( config_GetInt( p_intf, "qt-fs-controller" ) )
447 fullscreenControls = new FullscreenControllerWidget( p_intf, this );
448 CONNECT( fullscreenControls, keyPressed( QKeyEvent * ),
449 this, handleKeyPress( QKeyEvent * ) );
453 inline void MainInterface::initSystray()
456 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
457 bool b_systrayWanted = config_GetInt( p_intf, "qt-system-tray" );
459 if( config_GetInt( p_intf, "qt-start-minimized") > 0 )
461 if( b_systrayAvailable )
463 b_systrayWanted = true;
464 b_hideAfterCreation = true;
467 msg_Err( p_intf, "cannot start minimized without system tray bar" );
470 if( b_systrayAvailable && b_systrayWanted )
475 inline void MainInterface::createStatusBar()
480 /* Widgets Creation*/
481 QStatusBar *statusBarr = statusBar();
483 TimeLabel *timeLabel = new TimeLabel( p_intf );
484 nameLabel = new QLabel( this );
485 nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
486 | Qt::TextSelectableByKeyboard );
487 SpeedLabel *speedLabel = new SpeedLabel( p_intf, "1.00x", this );
489 /* Styling those labels */
490 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
491 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
492 nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
494 /* and adding those */
495 statusBarr->addWidget( nameLabel, 8 );
496 statusBarr->addPermanentWidget( speedLabel, 0 );
497 statusBarr->addPermanentWidget( timeLabel, 0 );
499 /* timeLabel behaviour:
500 - double clicking opens the goto time dialog
501 - right-clicking and clicking just toggle between remaining and
503 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
505 CONNECT( THEMIM->getIM(), encryptionChanged( bool ),
506 this, showCryptedLabel( bool ) );
510 void MainInterface::createTaskBarButtons()
512 /*Here is the code for the taskbar thumb buttons
513 FIXME:We need pretty buttons in 16x16 px that are handled correctly by masks in Qt
514 FIXME:the play button's picture doesn't changed to pause when clicked
516 OSVERSIONINFO winVer;
517 winVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
518 if( GetVersionEx(&winVer) && winVer.dwMajorVersion > 5 )
520 if(himl = ImageList_Create( 15, //cx
523 4,//initial nb of images
524 0//nb of images that can be added
527 QPixmap img = QPixmap(":/toolbar/previous_b");
528 QPixmap img2 = QPixmap(":/toolbar/pause_b");
529 QPixmap img3 = QPixmap(":/toolbar/play_b");
530 QPixmap img4 = QPixmap(":/toolbar/next_b");
531 QBitmap mask = img.createMaskFromColor(Qt::transparent);
532 QBitmap mask2 = img2.createMaskFromColor(Qt::transparent);
533 QBitmap mask3 = img3.createMaskFromColor(Qt::transparent);
534 QBitmap mask4 = img4.createMaskFromColor(Qt::transparent);
536 if(-1 == ImageList_Add(himl, img.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask.toWinHBITMAP()))
537 msg_Err( p_intf, "ImageList_Add failed" );
538 if(-1 == ImageList_Add(himl, img2.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask2.toWinHBITMAP()))
539 msg_Err( p_intf, "ImageList_Add failed" );
540 if(-1 == ImageList_Add(himl, img3.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask3.toWinHBITMAP()))
541 msg_Err( p_intf, "ImageList_Add failed" );
542 if(-1 == ImageList_Add(himl, img4.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask4.toWinHBITMAP()))
543 msg_Err( p_intf, "ImageList_Add failed" );
548 if( S_OK == CoCreateInstance( &clsid_ITaskbarList,
549 NULL, CLSCTX_INPROC_SERVER,
551 (void **)&p_taskbl) )
553 p_taskbl->vt->HrInit(p_taskbl);
555 int msg_value = RegisterWindowMessage("TaskbarButtonCreated");
556 //msg_Info( p_intf, "msg value: %04x", msg_value );
558 // Define an array of two buttons. These buttons provide images through an
559 // image list and also provide tooltips.
560 DWORD dwMask = THB_BITMAP | THB_FLAGS;
562 THUMBBUTTON thbButtons[2];
563 thbButtons[0].dwMask = dwMask;
564 thbButtons[0].iId = 0;
565 thbButtons[0].iBitmap = 0;
566 thbButtons[0].dwFlags = THBF_HIDDEN;
568 thbButtons[1].dwMask = dwMask;
569 thbButtons[1].iId = 1;
570 thbButtons[1].iBitmap = 2;
571 thbButtons[1].dwFlags = THBF_HIDDEN;
573 thbButtons[2].dwMask = dwMask;
574 thbButtons[2].iId = 2;
575 thbButtons[2].iBitmap = 3;
576 thbButtons[2].dwFlags = THBF_HIDDEN;
578 HRESULT hr = p_taskbl->vt->ThumbBarSetImageList(p_taskbl, GetForegroundWindow(), himl );
580 msg_Err( p_intf, "ThumbBarSetImageList failed with error %08x", hr );
581 if(S_OK != p_taskbl->vt->ThumbBarAddButtons(p_taskbl, GetForegroundWindow(), 3, thbButtons))
582 msg_Err( p_intf, "ThumbBarAddButtons failed with error %08x", GetLastError() );
584 CONNECT( THEMIM->getIM(), statusChanged( int ), this, changeThumbbarButtons( int ) );
598 /**********************************************************************
599 * Handling of sizing of the components
600 **********************************************************************/
602 /* This function is probably wrong, but we don't have many many choices...
603 Since we can't know from the playlist Widget if we are inside a dock or not,
604 because the playlist Widget can be called by THEDP, as a separate windows for
606 Maybe the other solution is to redefine the sizeHint() of the playlist and
607 ask _parent->isFloating()...
608 If you think this would be better, please FIXME it...
611 QSize MainInterface::sizeHint() const
616 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
617 i_visualmode == QT_MINIMAL_MODE )
619 return mainVideoSize;
623 if( VISIBLE( bgWidget) ||
624 ( videoIsActive && videoWidget->isVisible() )
626 return mainVideoSize;
628 return mainBasedSize;
633 int nwidth = __MAX( controls->sizeHint().width(),
634 menuBar()->sizeHint().width() );
636 int nheight = controls->isVisible() ?
637 controls->size().height()
638 + inputC->size().height()
639 + menuBar()->size().height()
640 + statusBar()->size().height()
643 if( stackCentralW->isVisible() )
644 nheight += stackCentralW->height();
645 nwidth = __MAX( nwidth, stackCentralW->width() );
647 /* if( VISIBLE( bgWidget ) )
649 msg_Warn( p_intf, "Hello here" );
651 nheight += i_bg_height;
653 nheight += bgWidget->size().height();
654 nwidth = __MAX( nwidth, bgWidget->size().width() );
656 else if( videoIsActive && videoWidget->isVisible() )
658 msg_Warn( p_intf, "Hello there" );
659 nheight += videoWidget->sizeHint().height();
660 nwidth = __MAX( nwidth, videoWidget->sizeHint().width() );
663 if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget() )
665 nheight += dockPL->size().height();
666 nwidth = __MAX( nwidth, dockPL->size().width() );
667 msg_Warn( p_intf, "3 %i %i", nheight, nwidth );
670 return QSize( nwidth, nheight );
674 /* Video widget cannot do this synchronously as it runs in another thread */
675 /* Well, could it, actually ? Probably dangerous ... */
677 /* This function is called:
678 - toggling of minimal View
679 - through askUpdate() by Vout thread request video and resize video (zoom)
680 - Advanced buttons toggled
682 void MainInterface::doComponentsUpdate()
684 if( isFullScreen() || isMaximized() ) return;
686 // msg_Warn( p_intf, "Updating the geometry" );
687 /* Here we resize to sizeHint() and not adjustsize because we want
688 the videoWidget to be exactly the correctSize */
693 /* This is WRONG, but I believe there is a Qt bug here */
694 setMinimumSize( 0, 0 );
695 resize( sizeHint() );
697 //adjustSize() ; /* This is not needed, but might help in the future */
700 void MainInterface::debug()
703 msg_Dbg( p_intf, "Stack Size: %i - %i", stackCentralW->size().height(), size().width() );
704 msg_Dbg( p_intf, "Stack Size: %i - %i", stackCentralW->widget( VIDEO_TAB )->size().height(), stackCentralW->widget( VIDEO_TAB )->size().width() );
706 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
707 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
708 //msg_Dbg( p_intf, "maximumsize: %i - %i", maximumSize().height(), maximumSize().width() );
710 msg_Dbg( p_intf, "Stack minimumsize: %i - %i", stackCentralW->minimumSize().height(), stackCentralW->minimumSize().width() );
711 msg_Dbg( p_intf, "Controls minimumsize: %i - %i", controls->minimumSize().height(), controls->minimumSize().width() );
712 msg_Dbg( p_intf, "Central minimumsize: %i - %i", centralWidget()->minimumSize().height(), centralWidget()->minimumSize().width() );
713 msg_Dbg( p_intf, "Menu minimumsize: %i - %i", menuBar()->minimumSize().height(), menuBar()->minimumSize().width() );
714 msg_Dbg( p_intf, "Input minimuSize: %i - %i", inputC->minimumSize().height(), inputC->minimumSize().width() );
715 msg_Dbg( p_intf, "Status minimumsize: %i - %i", statusBar()->minimumSize().height(), statusBar()->minimumSize().width() );
716 msg_Dbg( p_intf, "minimumsize: %i - %i", minimumSize().height(), minimumSize().width() );
718 /*if( videoWidget && videoWidget->isVisible() )
720 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
721 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
726 inline void MainInterface::showTab( int i_tab )
728 msg_Err( p_intf, "showTab %i", i_tab );
729 msg_Warn( p_intf, "Old stackCentralOldState %i", stackCentralOldState );
730 stackCentralOldState = stackCentralW->isVisible() ? stackCentralW->currentIndex()
732 msg_Warn( p_intf, "State change %i %i", stackCentralW->currentIndex(), i_tab );
734 if( i_visualmode == QT_NORMAL_MODE )
736 stackCentralW->setVisible( i_tab != HIDDEN_TAB );
737 doComponentsUpdate(); // resize the player
740 if( i_tab == HIDDEN_TAB ) i_tab == BACKG_TAB;
742 stackCentralW->setCurrentIndex( i_tab );
744 msg_Warn( p_intf, "New stackCentralOldState %i", stackCentralOldState );
747 inline void MainInterface::restoreStackOldWidget()
749 msg_Warn( p_intf, "Old stackCentralOldState %i", stackCentralOldState );
750 int temp = stackCentralW->isVisible() ? stackCentralW->currentIndex()
752 stackCentralW->setCurrentIndex( stackCentralOldState );
753 if( i_visualmode == QT_NORMAL_MODE )
755 stackCentralW->setVisible( stackCentralOldState != HIDDEN_TAB );
756 doComponentsUpdate(); // resize the player
759 stackCentralOldState = temp;
760 msg_Warn( p_intf, "Debug %i %i", temp, stackCentralW->currentIndex() );
764 void MainInterface::destroyPopupMenu()
766 QVLCMenu::PopupMenu( p_intf, false );
769 void MainInterface::toggleFSC()
771 if( !fullscreenControls ) return;
773 IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
774 QApplication::postEvent( fullscreenControls, eShow );
777 void MainInterface::popupMenu( const QPoint &p )
779 /* Ow, that's ugly: don't show the popup menu if cursor over
780 * the main menu bar or the status bar */
781 if( !childAt( p ) || ( ( childAt( p ) != menuBar() )
782 && ( childAt( p )->parentWidget() != statusBar() ) ) )
783 QVLCMenu::PopupMenu( p_intf, true );
786 /****************************************************************************
788 ****************************************************************************/
790 /* This event is used to deal with the fullscreen and always on top
791 issue conflict (bug in wx) */
792 class SetVideoOnTopQtEvent : public QEvent
795 SetVideoOnTopQtEvent( bool _onTop ) :
796 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
799 bool OnTop() const { return onTop; }
807 * You must note change the state of this object or other Qt4 UI objects,
808 * from the video output thread - only from the Qt4 UI main loop thread.
809 * All window provider queries must be handled through signals or events.
810 * That's why we have all those emit statements...
812 WId MainInterface::getVideo( int *pi_x, int *pi_y,
813 unsigned int *pi_width, unsigned int *pi_height )
818 /* This is a blocking call signal. Results are returned through pointers.
819 * Beware of deadlocks! */
821 emit askGetVideo( &id, pi_x, pi_y, pi_width, pi_height );
825 void MainInterface::getVideoSlot( WId *p_id, int *pi_x, int *pi_y,
826 unsigned *pi_width, unsigned *pi_height )
828 /* Request the videoWidget */
829 WId ret = videoWidget->request( pi_x, pi_y,
830 pi_width, pi_height, b_keep_size );
832 if( ret ) /* The videoWidget is available */
834 /* ask videoWidget to show */
835 videoWidget->SetSizing( *pi_width, *pi_height );
837 /* Consider the video active now */
840 stackCentralW->resize( *pi_width, *pi_height );
848 /* Asynchronous call from the WindowClose function */
849 void MainInterface::releaseVideo( void )
851 emit askReleaseVideo( );
854 /* Function that is CONNECTED to the previous emit */
855 void MainInterface::releaseVideoSlot( void )
857 videoWidget->release( );
859 restoreStackOldWidget();
861 /* Try to resize, except when you are in Fullscreen mode */
862 // doComponentsUpdate();
865 /* Asynchronous call from WindowControl function */
866 int MainInterface::controlVideo( int i_query, va_list args )
868 /* Debug to check if VOUT_WINDOW_SET_SIZE is called, because this is broken now */
869 msg_Warn( p_intf, "Control Video: %i", i_query );
872 case VOUT_WINDOW_SET_SIZE:
874 unsigned int i_width = va_arg( args, unsigned int );
875 unsigned int i_height = va_arg( args, unsigned int );
876 emit askVideoToResize( i_width, i_height );
880 case VOUT_WINDOW_SET_ON_TOP:
882 int i_arg = va_arg( args, int );
883 QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
886 case VOUT_WINDOW_SET_FULLSCREEN:
888 bool b_fs = va_arg( args, int );
889 emit askVideoSetFullScreen( b_fs );
893 msg_Warn( p_intf, "unsupported control query" );
898 /*****************************************************************************
899 * Playlist, Visualisation and Menus handling
900 *****************************************************************************/
902 * Toggle the playlist widget or dialog
904 void MainInterface::createPlaylist( bool b_show )
906 playlistWidget = new PlaylistWidget( p_intf );
908 i_pl_dock = PL_BOTTOM;
909 /* i_pl_dock = (pl_dock_e)getSettings()
910 ->value( "pl-dock-status", PL_UNDOCKED ).toInt(); */
912 if( i_pl_dock == PL_UNDOCKED )
914 playlistWidget->setWindowFlags( Qt::Window );
916 /* This will restore the geometry but will not work for position,
917 because of parenting */
918 QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
919 playlistWidget, QSize( 600, 300 ) );
923 msg_Warn( p_intf, "Here %i", stackCentralW->currentIndex() );
924 stackCentralW->insertWidget( PLAYL_TAB, playlistWidget );
925 msg_Warn( p_intf, "Here %i", stackCentralW->currentIndex() );
930 playlistVisible = true;
931 stackCentralW->show();
935 void MainInterface::togglePlaylist()
937 msg_Warn( p_intf, "Here toggling %i %i", stackCentralW->currentIndex(), stackCentralOldState );
938 if( !playlistWidget )
940 createPlaylist( true );
942 msg_Warn( p_intf, "Here toggling %i %i", stackCentralW->currentIndex(), stackCentralOldState );
944 if( i_pl_dock != PL_UNDOCKED )
946 /* Playlist not visible */
947 if( stackCentralW->currentIndex() != PLAYL_TAB )
949 msg_Warn( p_intf, "Here 42" );
950 showTab( PLAYL_TAB );
951 stackCentralW->show();
955 restoreStackOldWidget();
957 playlistVisible = ( stackCentralW->currentIndex() == PLAYL_TAB );
958 //doComponentsUpdate(); //resize( sizeHint() );
962 /* Function called from the menu to undock the playlist */
963 void MainInterface::undockPlaylist()
965 // dockPL->setFloating( true );
969 void MainInterface::dockPlaylist( pl_dock_e i_pos )
973 void MainInterface::toggleMinimalView( bool b_switch )
975 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
976 i_visualmode != QT_MINIMAL_MODE )
977 { /* NORMAL MODE then */
978 stackCentralW->show();
979 if( !videoWidget || stackCentralW->currentIndex() != VIDEO_TAB )
985 /* If video is visible, then toggle the status of bgWidget */
986 //bgWasVisible = !bgWasVisible;
987 if( stackCentralOldState == BACKG_TAB )
988 stackCentralOldState = HIDDEN_TAB;
990 stackCentralOldState = BACKG_TAB;
994 i_bg_height = stackCentralW->height();
996 menuBar()->setVisible( !b_switch );
997 controls->setVisible( !b_switch );
998 statusBar()->setVisible( !b_switch );
999 inputC->setVisible( !b_switch );
1001 doComponentsUpdate();
1003 emit minimalViewToggled( b_switch );
1006 /* toggling advanced controls buttons */
1007 void MainInterface::toggleAdvanced()
1009 controls->toggleAdvanced();
1010 // if( fullscreenControls ) fullscreenControls->toggleAdvanced();
1013 /* Get the visibility status of the controls (hidden or not, advanced or not) */
1014 int MainInterface::getControlsVisibilityStatus()
1016 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
1017 + CONTROLS_ADVANCED * controls->b_advancedVisible );
1021 void MainInterface::visual()
1023 if( !VISIBLE( visualSelector) )
1025 visualSelector->show();
1026 if( !THEMIM->getIM()->hasVideo() )
1028 /* Show the background widget */
1030 visualSelectorEnabled = true;
1034 /* Stop any currently running visualization */
1035 visualSelector->hide();
1036 visualSelectorEnabled = false;
1038 doComponentsUpdate();
1042 /************************************************************************
1044 ************************************************************************/
1045 void MainInterface::setName( const QString& name )
1047 input_name = name; /* store it for the QSystray use */
1048 /* Display it in the status bar, but also as a Tooltip in case it doesn't
1050 nameLabel->setText( " " + name + " " );
1051 nameLabel->setToolTip( " " + name +" " );
1055 * Give the decorations of the Main Window a correct Name.
1056 * If nothing is given, set it to VLC...
1058 void MainInterface::setVLCWindowsTitle( const QString& aTitle )
1060 if( aTitle.isEmpty() )
1062 setWindowTitle( qtr( "VLC media player" ) );
1066 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
1070 void MainInterface::showCryptedLabel( bool b_show )
1072 if( cryptedLabel == NULL )
1074 cryptedLabel = new QLabel;
1075 // The lock icon is not the right one for DRM protection/scrambled.
1076 //cryptedLabel->setPixmap( QPixmap( ":/lock" ) );
1077 cryptedLabel->setText( "DRM" );
1078 statusBar()->addWidget( cryptedLabel );
1081 cryptedLabel->setVisible( b_show );
1084 /*****************************************************************************
1085 * Systray Icon and Systray Menu
1086 *****************************************************************************/
1089 * Create a SystemTray icon and a menu that would go with it.
1090 * Connects to a click handler on the icon.
1092 void MainInterface::createSystray()
1095 if( QDate::currentDate().dayOfYear() >= 354 )
1096 iconVLC = QIcon( ":/logo/vlc128-christmas.png" );
1098 iconVLC = QIcon( ":/logo/vlc128.png" );
1099 sysTray = new QSystemTrayIcon( iconVLC, this );
1100 sysTray->setToolTip( qtr( "VLC media player" ));
1102 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
1103 systrayMenu->setIcon( iconVLC );
1105 QVLCMenu::updateSystrayMenu( this, p_intf, true );
1108 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
1109 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
1113 * Updates the Systray Icon's menu and toggle the main interface
1115 void MainInterface::toggleUpdateSystrayMenu()
1117 /* If hidden, show it */
1123 else if( isMinimized() )
1131 /* Visible (possibly under other windows) */
1133 /* check if any visible window is above vlc in the z-order,
1134 * but ignore the ones always on top
1135 * and the ones which can't be activated */
1138 wi.cbSize = sizeof( WINDOWINFO );
1139 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
1140 hwnd && ( !IsWindowVisible( hwnd ) ||
1141 ( GetWindowInfo( hwnd, &wi ) &&
1142 (wi.dwExStyle&WS_EX_NOACTIVATE) ) );
1143 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
1144 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
1145 (wi.dwExStyle&WS_EX_TOPMOST) )
1157 QVLCMenu::updateSystrayMenu( this, p_intf );
1160 void MainInterface::handleSystrayClick(
1161 QSystemTrayIcon::ActivationReason reason )
1165 case QSystemTrayIcon::Trigger:
1166 case QSystemTrayIcon::DoubleClick:
1167 toggleUpdateSystrayMenu();
1169 case QSystemTrayIcon::MiddleClick:
1170 sysTray->showMessage( qtr( "VLC media player" ),
1171 qtr( "Control menu for the player" ),
1172 QSystemTrayIcon::Information, 3000 );
1180 * Updates the name of the systray Icon tooltip.
1181 * Doesn't check if the systray exists, check before you call it.
1183 void MainInterface::updateSystrayTooltipName( const QString& name )
1185 if( name.isEmpty() )
1187 sysTray->setToolTip( qtr( "VLC media player" ) );
1191 sysTray->setToolTip( name );
1192 if( notificationEnabled && ( isHidden() || isMinimized() ) )
1194 sysTray->showMessage( qtr( "VLC media player" ), name,
1195 QSystemTrayIcon::NoIcon, 3000 );
1199 QVLCMenu::updateSystrayMenu( this, p_intf );
1203 * Updates the status of the systray Icon tooltip.
1204 * Doesn't check if the systray exists, check before you call it.
1206 void MainInterface::updateSystrayTooltipStatus( int i_status )
1213 sysTray->setToolTip( qtr( "VLC media player" ) );
1218 sysTray->setToolTip( input_name );
1223 sysTray->setToolTip( input_name + " - "
1228 QVLCMenu::updateSystrayMenu( this, p_intf );
1232 /************************************************************************
1234 ************************************************************************/
1235 void MainInterface::dropEvent(QDropEvent *event)
1237 dropEventPlay( event, true );
1240 void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
1242 event->setDropAction( Qt::CopyAction );
1243 if( !event->possibleActions() & Qt::CopyAction )
1246 const QMimeData *mimeData = event->mimeData();
1248 /* D&D of a subtitles file, add it on the fly */
1249 if( mimeData->urls().size() == 1 && THEMIM->getIM()->hasInput() )
1251 if( !input_AddSubtitle( THEMIM->getInput(),
1252 qtu( toNativeSeparators( mimeData->urls()[0].toLocalFile() ) ),
1260 bool first = b_play;
1261 foreach( const QUrl &url, mimeData->urls() )
1263 QString s = toNativeSeparators( url.toLocalFile() );
1265 if( s.length() > 0 ) {
1266 char* psz_uri = make_URI( qtu(s) );
1267 playlist_Add( THEPL, psz_uri, NULL,
1268 PLAYLIST_APPEND | (first ? PLAYLIST_GO: PLAYLIST_PREPARSE),
1269 PLAYLIST_END, true, pl_Unlocked );
1272 RecentsMRL::getInstance( p_intf )->addRecent( s );
1277 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1279 event->acceptProposedAction();
1281 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1283 event->acceptProposedAction();
1285 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1290 /************************************************************************
1292 ************************************************************************/
1293 void MainInterface::customEvent( QEvent *event )
1296 if( event->type() == PLDockEvent_Type )
1298 PlaylistDialog::killInstance();
1299 playlistEmbeddedFlag = true;
1301 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1306 if ( event->type() == (int)SetVideoOnTopEvent_Type )
1308 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1309 if( p_event->OnTop() )
1310 setWindowFlags( windowFlags() | Qt::WindowStaysOnTopHint );
1312 setWindowFlags( windowFlags() & ~Qt::WindowStaysOnTopHint );
1313 show(); /* necessary to apply window flags */
1317 void MainInterface::keyPressEvent( QKeyEvent *e )
1319 handleKeyPress( e );
1322 void MainInterface::handleKeyPress( QKeyEvent *e )
1324 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() == Qt::Key_H )
1325 && !menuBar()->isVisible() )
1327 toggleMinimalView( false );
1331 int i_vlck = qtEventToVLCKey( e );
1334 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1341 void MainInterface::resizeEvent( QResizeEvent * event )
1346 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
1347 i_visualmode == QT_MINIMAL_MODE )
1349 mainVideoSize = size();
1353 if( VISIBLE( bgWidget) ||
1354 ( videoIsActive && videoWidget->isVisible() )
1356 mainVideoSize = size();
1358 mainBasedSize = size();
1362 QVLCMW::resizeEvent( event );
1363 msg_Dbg( p_intf, "Resize Event, height: %i", size().height() );
1366 void MainInterface::wheelEvent( QWheelEvent *e )
1368 int i_vlckey = qtWheelEventToVLCKey( e );
1369 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1373 void MainInterface::closeEvent( QCloseEvent *e )
1380 void MainInterface::toggleFullScreen( void )
1382 if( isFullScreen() )
1385 emit askUpdate(); // Needed if video was launched after the F11
1386 emit fullscreenInterfaceToggled( false );
1391 emit fullscreenInterfaceToggled( true );
1396 //moc doesn't know about #ifdef, so we have to build this method for every platform
1397 void MainInterface::changeThumbbarButtons( int i_status)
1400 // Define an array of two buttons. These buttons provide images through an
1401 // image list and also provide tooltips.
1402 DWORD dwMask = THB_BITMAP | THB_FLAGS;
1404 THUMBBUTTON thbButtons[3];
1406 thbButtons[0].dwMask = dwMask;
1407 thbButtons[0].iId = 0;
1408 thbButtons[0].iBitmap = 0;
1411 thbButtons[1].dwMask = dwMask;
1412 thbButtons[1].iId = 1;
1415 thbButtons[2].dwMask = dwMask;
1416 thbButtons[2].iId = 2;
1417 thbButtons[2].iBitmap = 3;
1424 thbButtons[0].dwFlags = THBF_HIDDEN;
1425 thbButtons[1].dwFlags = THBF_HIDDEN;
1426 thbButtons[2].dwFlags = THBF_HIDDEN;
1431 thbButtons[0].dwFlags = THBF_ENABLED;
1432 thbButtons[1].dwFlags = THBF_ENABLED;
1433 thbButtons[2].dwFlags = THBF_ENABLED;
1434 thbButtons[1].iBitmap = 1;
1439 //thbButtons[0].dwFlags = THBF_ENABLED;
1440 //thbButtons[1].dwFlags = THBF_ENABLED;
1441 //thbButtons[2].dwFlags = THBF_ENABLED;
1442 thbButtons[1].iBitmap = 2;
1447 HRESULT hr = p_taskbl->vt->ThumbBarUpdateButtons(p_taskbl, GetForegroundWindow(), 3, thbButtons);
1449 msg_Err( p_intf, "ThumbBarUpdateButtons failed with error %08x", hr );
1455 /*****************************************************************************
1456 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1457 * We don't show the menu directly here because we don't want the
1458 * caller to block for a too long time.
1459 *****************************************************************************/
1460 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1461 vlc_value_t old_val, vlc_value_t new_val, void *param )
1463 intf_thread_t *p_intf = (intf_thread_t *)param;
1465 if( p_intf->pf_show_dialog )
1467 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1468 new_val.b_bool, NULL );
1474 /*****************************************************************************
1475 * IntfShowCB: callback triggered by the intf-show libvlc variable.
1476 *****************************************************************************/
1477 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1478 vlc_value_t old_val, vlc_value_t new_val, void *param )
1480 intf_thread_t *p_intf = (intf_thread_t *)param;
1481 p_intf->p_sys->p_mi->toggleFSC();