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
99 stackCentralOldState = HIDDEN_TAB;
102 /* Ask for Privacy */
103 new FirstRun( this, p_intf );
106 * Configuration and settings
107 * Pre-building of interface
110 setFocusPolicy( Qt::StrongFocus );
111 setAcceptDrops( true );
112 setWindowRole( "vlc-main" );
113 setWindowIcon( QApplication::windowIcon() );
114 setWindowOpacity( config_GetFloat( p_intf, "qt-opacity" ) );
116 /* Set The Video In emebedded Mode or not */
117 videoEmbeddedFlag = config_GetInt( p_intf, "embedded-video" );
119 /* Does the interface resize to video size or the opposite */
120 b_keep_size = !config_GetInt( p_intf, "qt-video-autoresize" );
122 /* Are we in the enhanced always-video mode or not ? */
123 i_visualmode = config_GetInt( p_intf, "qt-display-mode" );
125 /* Do we want anoying popups or not */
126 notificationEnabled = (bool)config_GetInt( p_intf, "qt-notification" );
128 /* Set the other interface settings */
129 settings = getSettings();
130 settings->beginGroup( "MainWindow" );
133 * Retrieve saved sizes for main window
134 * mainBasedSize = based window size for normal mode
135 * (no video, no background)
136 * mainVideoSize = window size with video (all modes)
138 mainBasedSize = settings->value( "mainBasedSize", QSize( 350, 120 ) ).toSize();
139 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() );
160 /* Create a Dock to get the playlist */
161 dockPL = new QDockWidget( qtr( "Playlist" ), this );
162 dockPL->setSizePolicy( QSizePolicy::Preferred,
163 QSizePolicy::Expanding );
164 dockPL->setFeatures( QDockWidget::AllDockWidgetFeatures );
165 dockPL->setAllowedAreas( Qt::LeftDockWidgetArea
166 | Qt::RightDockWidgetArea
167 | Qt::BottomDockWidgetArea );
171 /*********************************
172 * Create the Systray Management *
173 *********************************/
176 /********************
178 ********************/
179 MainInputManager::getInstance( p_intf );
181 /************************************************************
182 * Connect the input manager to the GUI elements it manages *
183 ************************************************************/
185 * Connects on nameChanged()
186 * Those connects are different because options can impeach them to trigger.
188 /* Main Interface statusbar */
189 CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
190 this, setName( const QString& ) );
195 CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
196 this, updateSystrayTooltipName( const QString& ) );
199 /* and title of the Main Interface*/
200 if( config_GetInt( p_intf, "qt-name-in-title" ) )
202 CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
203 this, setVLCWindowsTitle( const QString& ) );
207 * CONNECTS on PLAY_STATUS
209 /* Status on the systray */
213 CONNECT( THEMIM->getIM(), statusChanged( int ),
214 this, updateSystrayTooltipStatus( int ) );
218 /* END CONNECTS ON IM */
223 var_AddCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
225 /* Register callback for the intf-popupmenu variable */
226 var_AddCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
229 /* VideoWidget connects for asynchronous calls */
230 connect( this, SIGNAL(askGetVideo(WId*,int*,int*,unsigned*,unsigned *)),
231 this, SLOT(getVideoSlot(WId*,int*,int*,unsigned*,unsigned*)),
232 Qt::BlockingQueuedConnection );
233 connect( this, SIGNAL(askReleaseVideo( void )),
234 this, SLOT(releaseVideoSlot( void )),
235 Qt::BlockingQueuedConnection );
239 CONNECT( this, askVideoToResize( unsigned int, unsigned int ),
240 videoWidget, SetSizing( unsigned int, unsigned int ) );
241 CONNECT( this, askVideoSetFullScreen( bool ),
242 videoWidget, SetFullScreen( bool ) );
243 CONNECT( videoWidget, keyPressed( QKeyEvent * ),
244 this, handleKeyPress( QKeyEvent * ) );
247 CONNECT( this, askUpdate(), this, doComponentsUpdate() );
248 CONNECT( THEDP, toolBarConfUpdated(), this, recreateToolbars() );
250 /* Size 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 bool b_pl_visible = settings->value( "playlist-visible", 0 ).toInt();
269 settings->endGroup();
272 if( b_pl_visible ) togglePlaylist();
274 /* Enable the popup menu in the MI */
275 setContextMenuPolicy( Qt::CustomContextMenu );
276 CONNECT( this, customContextMenuRequested( const QPoint& ),
277 this, popupMenu( const QPoint& ) );
281 /* Final sizing and showing */
282 setVisible( !b_hideAfterCreation );
283 //setMinimumSize( QSize( 0, 0 ) );
284 // setMinimumWidth( __MAX( controls->sizeHint().width(),
285 // menuBar()->sizeHint().width() ) );
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 );
293 /* Update the geometry : It is useful if you switch between
296 resize( sizeHint() );
299 createTaskBarButtons();
303 MainInterface::~MainInterface()
305 msg_Dbg( p_intf, "Destroying the main interface" );
307 /* Unsure we hide the videoWidget before destroying it */
308 if( stackCentralOldState == VIDEO_TAB )
311 /* Save playlist state */
315 QVLCTools::saveWidgetPosition( p_intf, "Playlist", playlistWidget );
317 delete playlistWidget;
322 ImageList_Destroy( himl );
324 p_taskbl->vt->Release(p_taskbl);
328 /* Be sure to kill the actionsManager... FIXME */
329 ActionsManager::killInstance();
331 /* Delete the FSC controller */
332 delete fullscreenControls;
335 settings->beginGroup( "MainWindow" );
336 settings->setValue( "pl-dock-status", (int)i_pl_dock );
337 settings->setValue( "playlist-visible", (int)playlistVisible );
338 settings->setValue( "adv-controls",
339 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
341 settings->setValue( "mainBasedSize", mainBasedSize );
342 settings->setValue( "mainVideoSize", mainVideoSize );
345 settings->setValue( "backgroundSize", bgWidget->size() );
348 QVLCTools::saveWidgetPosition(settings, this);
349 settings->endGroup();
351 /* Unregister callbacks */
352 var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
353 var_DelCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
355 p_intf->p_sys->p_mi = NULL;
358 /*****************************
360 *****************************/
361 void MainInterface::recreateToolbars()
363 msg_Dbg( p_intf, "Recreating the toolbars" );
364 settings->beginGroup( "MainWindow" );
367 controls = new ControlsWidget( p_intf, false, this ); /* FIXME */
368 CONNECT( controls, advancedControlsToggled( bool ),
369 this, doComponentsUpdate() );
370 CONNECT( controls, sizeChanged(),
371 this, doComponentsUpdate() );
372 inputC = new InputControlsWidget( p_intf, this );
374 mainLayout->insertWidget( 2, inputC );
375 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
377 settings->endGroup();
380 void MainInterface::createMainWidget( QSettings *settings )
382 /* Create the main Widget and the mainLayout */
383 QWidget *main = new QWidget;
384 setCentralWidget( main );
385 mainLayout = new QVBoxLayout( main );
387 /* Margins, spacing */
388 main->setContentsMargins( 0, 0, 0, 0 );
389 mainLayout->setSpacing( 0 );
390 mainLayout->setMargin( 0 );
393 stackCentralW = new QStackedWidget( main );
396 bgWidget = new BackgroundWidget( p_intf );
398 settings->value( "backgroundSize", QSize( 300, 200 ) ).toSize() );
399 bgWidget->updateGeometry();
400 stackCentralW->insertWidget( BACKG_TAB, bgWidget );
402 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
403 i_visualmode != QT_MINIMAL_MODE )
405 stackCentralW->hide();
408 /* And video Outputs */
409 if( videoEmbeddedFlag )
411 videoWidget = new VideoWidget( p_intf );
412 stackCentralW->insertWidget( VIDEO_TAB, videoWidget );
414 mainLayout->insertWidget( 1, stackCentralW, 100 );
415 /* Create the CONTROLS Widget */
416 controls = new ControlsWidget( p_intf,
417 settings->value( "adv-controls", false ).toBool(), this );
418 CONNECT( controls, advancedControlsToggled( bool ),
419 this, doComponentsUpdate() );
420 CONNECT( controls, sizeChanged(),
421 this, doComponentsUpdate() );
422 inputC = new InputControlsWidget( p_intf, this );
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::createStatusBar()
458 /* Widgets Creation*/
459 QStatusBar *statusBarr = statusBar();
461 TimeLabel *timeLabel = new TimeLabel( p_intf );
462 nameLabel = new QLabel( this );
463 nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
464 | Qt::TextSelectableByKeyboard );
465 SpeedLabel *speedLabel = new SpeedLabel( p_intf, "1.00x", this );
467 /* Styling those labels */
468 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
469 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
470 nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
472 /* and adding those */
473 statusBarr->addWidget( nameLabel, 8 );
474 statusBarr->addPermanentWidget( speedLabel, 0 );
475 statusBarr->addPermanentWidget( timeLabel, 0 );
477 /* timeLabel behaviour:
478 - double clicking opens the goto time dialog
479 - right-clicking and clicking just toggle between remaining and
481 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
483 CONNECT( THEMIM->getIM(), encryptionChanged( bool ),
484 this, showCryptedLabel( bool ) );
488 void MainInterface::createTaskBarButtons()
490 /*Here is the code for the taskbar thumb buttons
491 FIXME:We need pretty buttons in 16x16 px that are handled correctly by masks in Qt
492 FIXME:the play button's picture doesn't changed to pause when clicked
494 OSVERSIONINFO winVer;
495 winVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
496 if( GetVersionEx(&winVer) && winVer.dwMajorVersion > 5 )
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" );
526 if( S_OK == CoCreateInstance( &clsid_ITaskbarList,
527 NULL, CLSCTX_INPROC_SERVER,
529 (void **)&p_taskbl) )
531 p_taskbl->vt->HrInit(p_taskbl);
533 int msg_value = RegisterWindowMessage("TaskbarButtonCreated");
534 //msg_Info( p_intf, "msg value: %04x", msg_value );
536 // Define an array of two buttons. These buttons provide images through an
537 // image list and also provide tooltips.
538 DWORD dwMask = THB_BITMAP | THB_FLAGS;
540 THUMBBUTTON thbButtons[2];
541 thbButtons[0].dwMask = dwMask;
542 thbButtons[0].iId = 0;
543 thbButtons[0].iBitmap = 0;
544 thbButtons[0].dwFlags = THBF_HIDDEN;
546 thbButtons[1].dwMask = dwMask;
547 thbButtons[1].iId = 1;
548 thbButtons[1].iBitmap = 2;
549 thbButtons[1].dwFlags = THBF_HIDDEN;
551 thbButtons[2].dwMask = dwMask;
552 thbButtons[2].iId = 2;
553 thbButtons[2].iBitmap = 3;
554 thbButtons[2].dwFlags = THBF_HIDDEN;
556 HRESULT hr = p_taskbl->vt->ThumbBarSetImageList(p_taskbl, GetForegroundWindow(), himl );
558 msg_Err( p_intf, "ThumbBarSetImageList failed with error %08x", hr );
559 if(S_OK != p_taskbl->vt->ThumbBarAddButtons(p_taskbl, GetForegroundWindow(), 3, thbButtons))
560 msg_Err( p_intf, "ThumbBarAddButtons failed with error %08x", GetLastError() );
562 CONNECT( THEMIM->getIM(), statusChanged( int ), this, changeThumbbarButtons( int ) );
574 inline void MainInterface::initSystray()
577 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
578 bool b_systrayWanted = config_GetInt( p_intf, "qt-system-tray" );
580 if( config_GetInt( p_intf, "qt-start-minimized") > 0 )
582 if( b_systrayAvailable )
584 b_systrayWanted = true;
585 b_hideAfterCreation = true;
588 msg_Err( p_intf, "cannot start minimized without system tray bar" );
591 if( b_systrayAvailable && b_systrayWanted )
597 /**********************************************************************
598 * Handling of sizing of the components
599 **********************************************************************/
601 /* This function is probably wrong, but we don't have many many choices...
602 Since we can't know from the playlist Widget if we are inside a dock or not,
603 because the playlist Widget can be called by THEDP, as a separate windows for
605 Maybe the other solution is to redefine the sizeHint() of the playlist and
606 ask _parent->isFloating()...
607 If you think this would be better, please FIXME it...
610 QSize MainInterface::sizeHint() const
615 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
616 i_visualmode == QT_MINIMAL_MODE )
618 return mainVideoSize;
622 if( VISIBLE( bgWidget) ||
623 ( videoIsActive && videoWidget->isVisible() )
625 return mainVideoSize;
627 return mainBasedSize;
632 int nwidth = __MAX( controls->sizeHint().width(),
633 menuBar()->sizeHint().width() );
635 int nheight = controls->isVisible() ?
636 controls->size().height()
637 + inputC->size().height()
638 + menuBar()->size().height()
639 + statusBar()->size().height()
642 if( stackCentralW->isVisible() )
643 nheight += stackCentralW->height();
644 nwidth = __MAX( nwidth, stackCentralW->width() );
646 /* if( VISIBLE( bgWidget ) )
648 msg_Warn( p_intf, "Hello here" );
650 nheight += i_bg_height;
652 nheight += bgWidget->size().height();
653 nwidth = __MAX( nwidth, bgWidget->size().width() );
655 else if( videoIsActive && videoWidget->isVisible() )
657 msg_Warn( p_intf, "Hello there" );
658 nheight += videoWidget->sizeHint().height();
659 nwidth = __MAX( nwidth, videoWidget->sizeHint().width() );
662 if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget() )
664 nheight += dockPL->size().height();
665 nwidth = __MAX( nwidth, dockPL->size().width() );
666 msg_Warn( p_intf, "3 %i %i", nheight, nwidth );
669 return QSize( nwidth, nheight );
673 /* Video widget cannot do this synchronously as it runs in another thread */
674 /* Well, could it, actually ? Probably dangerous ... */
676 /* This function is called:
677 - toggling of minimal View
678 - through askUpdate() by Vout thread request video and resize video (zoom)
679 - Advanced buttons toggled
681 void MainInterface::doComponentsUpdate()
683 if( isFullScreen() || isMaximized() ) return;
685 msg_Warn( p_intf, "Updating the geometry" );
686 /* Here we resize to sizeHint() and not adjustsize because we want
687 the videoWidget to be exactly the correctSize */
692 /* This is WRONG, but I believe there is a Qt bug here */
693 setMinimumSize( 0, 0 );
694 resize( sizeHint() );
696 //adjustSize() ; /* This is not needed, but might help in the future */
699 void MainInterface::debug()
702 msg_Dbg( p_intf, "Stack Size: %i - %i", stackCentralW->size().height(), size().width() );
703 msg_Dbg( p_intf, "Stack Size: %i - %i", stackCentralW->widget( VIDEO_TAB )->size().height(), stackCentralW->widget( VIDEO_TAB )->size().width() );
705 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
706 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
707 //msg_Dbg( p_intf, "maximumsize: %i - %i", maximumSize().height(), maximumSize().width() );
709 msg_Dbg( p_intf, "Stack minimumsize: %i - %i", stackCentralW->minimumSize().height(), stackCentralW->minimumSize().width() );
710 msg_Dbg( p_intf, "Controls minimumsize: %i - %i", controls->minimumSize().height(), controls->minimumSize().width() );
711 msg_Dbg( p_intf, "Central minimumsize: %i - %i", centralWidget()->minimumSize().height(), centralWidget()->minimumSize().width() );
712 msg_Dbg( p_intf, "Menu minimumsize: %i - %i", menuBar()->minimumSize().height(), menuBar()->minimumSize().width() );
713 msg_Dbg( p_intf, "Input minimuSize: %i - %i", inputC->minimumSize().height(), inputC->minimumSize().width() );
714 msg_Dbg( p_intf, "Status minimumsize: %i - %i", statusBar()->minimumSize().height(), statusBar()->minimumSize().width() );
715 msg_Dbg( p_intf, "minimumsize: %i - %i", minimumSize().height(), minimumSize().width() );
717 /*if( videoWidget && videoWidget->isVisible() )
719 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
720 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
725 void MainInterface::destroyPopupMenu()
727 QVLCMenu::PopupMenu( p_intf, false );
730 void MainInterface::toggleFSC()
732 if( !fullscreenControls ) return;
734 IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
735 QApplication::postEvent( fullscreenControls, eShow );
738 void MainInterface::popupMenu( const QPoint &p )
740 /* Ow, that's ugly: don't show the popup menu if cursor over
741 * the main menu bar or the status bar */
742 if( !childAt( p ) || ( ( childAt( p ) != menuBar() )
743 && ( childAt( p )->parentWidget() != statusBar() ) ) )
744 QVLCMenu::PopupMenu( p_intf, true );
747 /****************************************************************************
749 ****************************************************************************/
751 /* This event is used to deal with the fullscreen and always on top
752 issue conflict (bug in wx) */
753 class SetVideoOnTopQtEvent : public QEvent
756 SetVideoOnTopQtEvent( bool _onTop ) :
757 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
760 bool OnTop() const { return onTop; }
768 * You must note change the state of this object or other Qt4 UI objects,
769 * from the video output thread - only from the Qt4 UI main loop thread.
770 * All window provider queries must be handled through signals or events.
771 * That's why we have all those emit statements...
773 WId MainInterface::getVideo( int *pi_x, int *pi_y,
774 unsigned int *pi_width, unsigned int *pi_height )
779 /* This is a blocking call signal. Results are returned through pointers.
780 * Beware of deadlocks! */
782 emit askGetVideo( &id, pi_x, pi_y, pi_width, pi_height );
786 void MainInterface::getVideoSlot( WId *p_id, int *pi_x, int *pi_y,
787 unsigned *pi_width, unsigned *pi_height )
789 /* Request the videoWidget */
790 WId ret = videoWidget->request( pi_x, pi_y,
791 pi_width, pi_height, b_keep_size );
793 if( ret ) /* The videoWidget is available */
795 /* ask videoWidget to show */
796 videoWidget->SetSizing( *pi_width, *pi_height );
798 /* Consider the video active now */
801 stackCentralW->resize( *pi_width, *pi_height );
807 inline void MainInterface::showTab( int i_tab )
809 stackCentralOldState = stackCentralW->currentIndex();
811 stackCentralW->setCurrentIndex( i_tab );
812 if( stackCentralW->isHidden() ) stackCentralW->show();
815 /* Asynchronous call from the WindowClose function */
816 void MainInterface::releaseVideo( void )
818 emit askReleaseVideo( );
821 /* Function that is CONNECTED to the previous emit */
822 void MainInterface::releaseVideoSlot( void )
824 videoWidget->release( );
826 /* Restore the previous State */
827 if( stackCentralOldState == BACKG_TAB )
833 stackCentralW->hide();
834 stackCentralOldState == -1;
837 /* Try to resize, except when you are in Fullscreen mode */
838 doComponentsUpdate();
841 /* Asynchronous call from WindowControl function */
842 int MainInterface::controlVideo( int i_query, va_list args )
844 /* Debug to check if VOUT_WINDOW_SET_SIZE is called, because this is broken now */
845 msg_Warn( p_intf, "Control Video: %i", i_query );
848 case VOUT_WINDOW_SET_SIZE:
850 unsigned int i_width = va_arg( args, unsigned int );
851 unsigned int i_height = va_arg( args, unsigned int );
852 emit askVideoToResize( i_width, i_height );
856 case VOUT_WINDOW_SET_ON_TOP:
858 int i_arg = va_arg( args, int );
859 QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
862 case VOUT_WINDOW_SET_FULLSCREEN:
864 bool b_fs = va_arg( args, int );
865 emit askVideoSetFullScreen( b_fs );
869 msg_Warn( p_intf, "unsupported control query" );
874 /*****************************************************************************
875 * Playlist, Visualisation and Menus handling
876 *****************************************************************************/
878 * Toggle the playlist widget or dialog
880 void MainInterface::togglePlaylist()
883 If no playlist exist, then create one and attach it to the DockPL*/
884 if( !playlistWidget )
886 playlistWidget = new PlaylistWidget( p_intf );
888 i_pl_dock = PL_BOTTOM;
889 /*i_pl_dock = (pl_dock_e)getSettings()
890 ->value( "pl-dock-status", PL_UNDOCKED ).toInt();*/
892 if( i_pl_dock == PL_UNDOCKED )
894 playlistWidget->setWindowFlags( Qt::Window );
896 /* This will restore the geometry but will not work for position,
897 because of parenting */
898 QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
899 playlistWidget, QSize( 600, 300 ) );
903 stackCentralW->insertWidget(PLAYL_TAB, playlistWidget );
904 stackCentralW->setCurrentWidget( playlistWidget );
905 stackCentralW->show();
907 playlistVisible = true;
909 playlistWidget->show();
913 /* toggle the visibility of the playlist */
914 if( stackCentralW->currentIndex() != PLAYL_TAB )
916 stackCentralW->insertWidget(PLAYL_TAB, playlistWidget );
917 stackCentralW->setCurrentWidget( playlistWidget );
918 stackCentralW->show();
921 stackCentralW->setCurrentIndex( VIDEO_TAB );
922 playlistVisible = !playlistVisible;
923 //doComponentsUpdate(); //resize( sizeHint() );
927 /* Function called from the menu to undock the playlist */
928 void MainInterface::undockPlaylist()
930 // dockPL->setFloating( true );
934 void MainInterface::dockPlaylist( pl_dock_e i_pos )
938 void MainInterface::toggleMinimalView( bool b_switch )
940 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
941 i_visualmode != QT_MINIMAL_MODE )
942 { /* NORMAL MODE then */
943 stackCentralW->show();
944 if( !videoWidget || stackCentralW->currentIndex() != VIDEO_TAB )
950 /* If video is visible, then toggle the status of bgWidget */
951 //bgWasVisible = !bgWasVisible;
952 if( stackCentralOldState == BACKG_TAB )
953 stackCentralOldState = HIDDEN_TAB;
955 stackCentralOldState = BACKG_TAB;
959 i_bg_height = stackCentralW->height();
961 menuBar()->setVisible( !b_switch );
962 controls->setVisible( !b_switch );
963 statusBar()->setVisible( !b_switch );
964 inputC->setVisible( !b_switch );
966 doComponentsUpdate();
968 emit minimalViewToggled( b_switch );
971 /* toggling advanced controls buttons */
972 void MainInterface::toggleAdvanced()
974 controls->toggleAdvanced();
975 // if( fullscreenControls ) fullscreenControls->toggleAdvanced();
978 /* Get the visibility status of the controls (hidden or not, advanced or not) */
979 int MainInterface::getControlsVisibilityStatus()
981 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
982 + CONTROLS_ADVANCED * controls->b_advancedVisible );
986 void MainInterface::visual()
988 if( !VISIBLE( visualSelector) )
990 visualSelector->show();
991 if( !THEMIM->getIM()->hasVideo() )
993 /* Show the background widget */
995 visualSelectorEnabled = true;
999 /* Stop any currently running visualization */
1000 visualSelector->hide();
1001 visualSelectorEnabled = false;
1003 doComponentsUpdate();
1007 /************************************************************************
1009 ************************************************************************/
1010 void MainInterface::setName( const QString& name )
1012 input_name = name; /* store it for the QSystray use */
1013 /* Display it in the status bar, but also as a Tooltip in case it doesn't
1015 nameLabel->setText( " " + name + " " );
1016 nameLabel->setToolTip( " " + name +" " );
1020 * Give the decorations of the Main Window a correct Name.
1021 * If nothing is given, set it to VLC...
1023 void MainInterface::setVLCWindowsTitle( const QString& aTitle )
1025 if( aTitle.isEmpty() )
1027 setWindowTitle( qtr( "VLC media player" ) );
1031 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
1035 void MainInterface::showCryptedLabel( bool b_show )
1037 if( cryptedLabel == NULL )
1039 cryptedLabel = new QLabel;
1040 // The lock icon is not the right one for DRM protection/scrambled.
1041 //cryptedLabel->setPixmap( QPixmap( ":/lock" ) );
1042 cryptedLabel->setText( "DRM" );
1043 statusBar()->addWidget( cryptedLabel );
1046 cryptedLabel->setVisible( b_show );
1049 /*****************************************************************************
1050 * Systray Icon and Systray Menu
1051 *****************************************************************************/
1054 * Create a SystemTray icon and a menu that would go with it.
1055 * Connects to a click handler on the icon.
1057 void MainInterface::createSystray()
1060 if( QDate::currentDate().dayOfYear() >= 354 )
1061 iconVLC = QIcon( ":/logo/vlc128-christmas.png" );
1063 iconVLC = QIcon( ":/logo/vlc128.png" );
1064 sysTray = new QSystemTrayIcon( iconVLC, this );
1065 sysTray->setToolTip( qtr( "VLC media player" ));
1067 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
1068 systrayMenu->setIcon( iconVLC );
1070 QVLCMenu::updateSystrayMenu( this, p_intf, true );
1073 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
1074 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
1078 * Updates the Systray Icon's menu and toggle the main interface
1080 void MainInterface::toggleUpdateSystrayMenu()
1082 /* If hidden, show it */
1088 else if( isMinimized() )
1096 /* Visible (possibly under other windows) */
1098 /* check if any visible window is above vlc in the z-order,
1099 * but ignore the ones always on top
1100 * and the ones which can't be activated */
1103 wi.cbSize = sizeof( WINDOWINFO );
1104 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
1105 hwnd && ( !IsWindowVisible( hwnd ) ||
1106 ( GetWindowInfo( hwnd, &wi ) &&
1107 (wi.dwExStyle&WS_EX_NOACTIVATE) ) );
1108 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
1109 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
1110 (wi.dwExStyle&WS_EX_TOPMOST) )
1122 QVLCMenu::updateSystrayMenu( this, p_intf );
1125 void MainInterface::handleSystrayClick(
1126 QSystemTrayIcon::ActivationReason reason )
1130 case QSystemTrayIcon::Trigger:
1131 case QSystemTrayIcon::DoubleClick:
1132 toggleUpdateSystrayMenu();
1134 case QSystemTrayIcon::MiddleClick:
1135 sysTray->showMessage( qtr( "VLC media player" ),
1136 qtr( "Control menu for the player" ),
1137 QSystemTrayIcon::Information, 3000 );
1145 * Updates the name of the systray Icon tooltip.
1146 * Doesn't check if the systray exists, check before you call it.
1148 void MainInterface::updateSystrayTooltipName( const QString& name )
1150 if( name.isEmpty() )
1152 sysTray->setToolTip( qtr( "VLC media player" ) );
1156 sysTray->setToolTip( name );
1157 if( notificationEnabled && ( isHidden() || isMinimized() ) )
1159 sysTray->showMessage( qtr( "VLC media player" ), name,
1160 QSystemTrayIcon::NoIcon, 3000 );
1164 QVLCMenu::updateSystrayMenu( this, p_intf );
1168 * Updates the status of the systray Icon tooltip.
1169 * Doesn't check if the systray exists, check before you call it.
1171 void MainInterface::updateSystrayTooltipStatus( int i_status )
1178 sysTray->setToolTip( qtr( "VLC media player" ) );
1183 sysTray->setToolTip( input_name );
1188 sysTray->setToolTip( input_name + " - "
1193 QVLCMenu::updateSystrayMenu( this, p_intf );
1197 /************************************************************************
1199 ************************************************************************/
1200 void MainInterface::dropEvent(QDropEvent *event)
1202 dropEventPlay( event, true );
1205 void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
1207 event->setDropAction( Qt::CopyAction );
1208 if( !event->possibleActions() & Qt::CopyAction )
1211 const QMimeData *mimeData = event->mimeData();
1213 /* D&D of a subtitles file, add it on the fly */
1214 if( mimeData->urls().size() == 1 && THEMIM->getIM()->hasInput() )
1216 if( !input_AddSubtitle( THEMIM->getInput(),
1217 qtu( toNativeSeparators( mimeData->urls()[0].toLocalFile() ) ),
1225 bool first = b_play;
1226 foreach( const QUrl &url, mimeData->urls() )
1228 QString s = toNativeSeparators( url.toLocalFile() );
1230 if( s.length() > 0 ) {
1231 char* psz_uri = make_URI( qtu(s) );
1232 playlist_Add( THEPL, psz_uri, NULL,
1233 PLAYLIST_APPEND | (first ? PLAYLIST_GO: PLAYLIST_PREPARSE),
1234 PLAYLIST_END, true, pl_Unlocked );
1237 RecentsMRL::getInstance( p_intf )->addRecent( s );
1242 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1244 event->acceptProposedAction();
1246 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1248 event->acceptProposedAction();
1250 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1255 /************************************************************************
1257 ************************************************************************/
1258 void MainInterface::customEvent( QEvent *event )
1261 if( event->type() == PLDockEvent_Type )
1263 PlaylistDialog::killInstance();
1264 playlistEmbeddedFlag = true;
1266 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1271 if ( event->type() == (int)SetVideoOnTopEvent_Type )
1273 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1274 if( p_event->OnTop() )
1275 setWindowFlags( windowFlags() | Qt::WindowStaysOnTopHint );
1277 setWindowFlags( windowFlags() & ~Qt::WindowStaysOnTopHint );
1278 show(); /* necessary to apply window flags */
1282 void MainInterface::keyPressEvent( QKeyEvent *e )
1284 handleKeyPress( e );
1287 void MainInterface::handleKeyPress( QKeyEvent *e )
1289 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() == Qt::Key_H )
1290 && !menuBar()->isVisible() )
1292 toggleMinimalView( false );
1296 int i_vlck = qtEventToVLCKey( e );
1299 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1306 void MainInterface::resizeEvent( QResizeEvent * event )
1311 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
1312 i_visualmode == QT_MINIMAL_MODE )
1314 mainVideoSize = size();
1318 if( VISIBLE( bgWidget) ||
1319 ( videoIsActive && videoWidget->isVisible() )
1321 mainVideoSize = size();
1323 mainBasedSize = size();
1327 QVLCMW::resizeEvent( event );
1328 msg_Dbg( p_intf, "Resize Event, height: %i", size().height() );
1331 void MainInterface::wheelEvent( QWheelEvent *e )
1333 int i_vlckey = qtWheelEventToVLCKey( e );
1334 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1338 void MainInterface::closeEvent( QCloseEvent *e )
1345 void MainInterface::toggleFullScreen( void )
1347 if( isFullScreen() )
1350 emit askUpdate(); // Needed if video was launched after the F11
1351 emit fullscreenInterfaceToggled( false );
1356 emit fullscreenInterfaceToggled( true );
1361 //moc doesn't know about #ifdef, so we have to build this method for every platform
1362 void MainInterface::changeThumbbarButtons( int i_status)
1365 // Define an array of two buttons. These buttons provide images through an
1366 // image list and also provide tooltips.
1367 DWORD dwMask = THB_BITMAP | THB_FLAGS;
1369 THUMBBUTTON thbButtons[3];
1371 thbButtons[0].dwMask = dwMask;
1372 thbButtons[0].iId = 0;
1373 thbButtons[0].iBitmap = 0;
1376 thbButtons[1].dwMask = dwMask;
1377 thbButtons[1].iId = 1;
1380 thbButtons[2].dwMask = dwMask;
1381 thbButtons[2].iId = 2;
1382 thbButtons[2].iBitmap = 3;
1389 thbButtons[0].dwFlags = THBF_HIDDEN;
1390 thbButtons[1].dwFlags = THBF_HIDDEN;
1391 thbButtons[2].dwFlags = THBF_HIDDEN;
1396 thbButtons[0].dwFlags = THBF_ENABLED;
1397 thbButtons[1].dwFlags = THBF_ENABLED;
1398 thbButtons[2].dwFlags = THBF_ENABLED;
1399 thbButtons[1].iBitmap = 1;
1404 //thbButtons[0].dwFlags = THBF_ENABLED;
1405 //thbButtons[1].dwFlags = THBF_ENABLED;
1406 //thbButtons[2].dwFlags = THBF_ENABLED;
1407 thbButtons[1].iBitmap = 2;
1412 HRESULT hr = p_taskbl->vt->ThumbBarUpdateButtons(p_taskbl, GetForegroundWindow(), 3, thbButtons);
1414 msg_Err( p_intf, "ThumbBarUpdateButtons failed with error %08x", hr );
1420 /*****************************************************************************
1421 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1422 * We don't show the menu directly here because we don't want the
1423 * caller to block for a too long time.
1424 *****************************************************************************/
1425 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1426 vlc_value_t old_val, vlc_value_t new_val, void *param )
1428 intf_thread_t *p_intf = (intf_thread_t *)param;
1430 if( p_intf->pf_show_dialog )
1432 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1433 new_val.b_bool, NULL );
1439 /*****************************************************************************
1440 * IntfShowCB: callback triggered by the intf-show libvlc variable.
1441 *****************************************************************************/
1442 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1443 vlc_value_t old_val, vlc_value_t new_val, void *param )
1445 intf_thread_t *p_intf = (intf_thread_t *)param;
1446 p_intf->p_sys->p_mi->toggleFSC();