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"
35 #include "extensions_manager.hpp" // killInstance
37 #include "util/customwidgets.hpp"
38 #include "util/qt_dirs.hpp"
40 #include "components/interface_widgets.hpp"
41 #include "components/controller.hpp"
42 #include "components/playlist/playlist.hpp"
43 #include "dialogs/external.hpp"
44 #include "dialogs/firstrun.hpp"
47 #include "recents.hpp"
49 #include <QCloseEvent>
61 #include <QPushButton>
62 #include <QStackedWidget>
65 #include <vlc_windows_interfaces.h>
71 #include <vlc_keys.h> /* Wheel event */
72 #include <vlc_vout_window.h>
73 #include <vlc_vout_display.h>
76 /* Callback prototypes */
77 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
78 vlc_value_t old_val, vlc_value_t new_val, void *param );
79 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
80 vlc_value_t old_val, vlc_value_t new_val, void *param );
82 MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
84 /* Variables initialisation */
85 // need_components_update = false;
88 playlistWidget = NULL;
92 fullscreenControls = NULL;
97 b_hideAfterCreation = false;
98 playlistVisible = false; // FIXME remove
103 /* Ask for Privacy */
104 FirstRun::CheckAndRun( this, p_intf );
107 * Configuration and settings
108 * Pre-building of interface
111 setFocusPolicy( Qt::StrongFocus );
112 setAcceptDrops( true );
113 setWindowRole( "vlc-main" );
114 setWindowIcon( QApplication::windowIcon() );
115 setWindowOpacity( var_InheritFloat( p_intf, "qt-opacity" ) );
117 /* Set The Video In emebedded Mode or not */
118 videoEmbeddedFlag = var_InheritBool( p_intf, "embedded-video" );
120 /* Does the interface resize to video size or the opposite */
121 b_keep_size = !var_InheritBool( p_intf, "qt-video-autoresize" );
123 /* Are we in the enhanced always-video mode or not ? */
124 i_visualmode = var_InheritInteger( p_intf, "qt-display-mode" );
126 /* Do we want anoying popups or not */
127 notificationEnabled = (bool)var_InheritBool( p_intf, "qt-notification" );
129 /* Set the other interface settings */
130 settings = getSettings();
131 settings->beginGroup( "MainWindow" );
134 * Retrieve saved sizes for main window
135 * mainBasedSize = based window size for normal mode
136 * (no video, no background)
137 * mainVideoSize = window size with video (all modes)
139 mainBasedSize = settings->value( "mainBasedSize", QSize( 350, 120 ) ).toSize();
140 mainVideoSize = settings->value( "mainVideoSize", QSize( 400, 300 ) ).toSize();
148 /**************************
149 * UI and Widgets design
150 **************************/
151 setVLCWindowsTitle();
152 createMainWidget( settings );
157 QVLCMenu::createMenuBar( this, p_intf );
158 CONNECT( THEMIM->getIM(), voutListChanged( vout_thread_t **, int ),
159 this, destroyPopupMenu() );
161 /*********************************
162 * Create the Systray Management *
163 *********************************/
166 /********************
168 ********************/
169 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 */
217 var_AddCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
219 /* Register callback for the intf-popupmenu variable */
220 var_AddCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
223 /* VideoWidget connects for asynchronous calls */
224 connect( this, SIGNAL(askGetVideo(WId*,int*,int*,unsigned*,unsigned *)),
225 this, SLOT(getVideoSlot(WId*,int*,int*,unsigned*,unsigned*)),
226 Qt::BlockingQueuedConnection );
227 connect( this, SIGNAL(askReleaseVideo( void )),
228 this, SLOT(releaseVideoSlot( void )),
229 Qt::BlockingQueuedConnection );
233 CONNECT( this, askVideoToResize( unsigned int, unsigned int ),
234 videoWidget, SetSizing( unsigned int, unsigned int ) );
235 CONNECT( this, askVideoSetFullScreen( bool ),
236 videoWidget, SetFullScreen( bool ) );
237 CONNECT( videoWidget, keyPressed( QKeyEvent * ),
238 this, handleKeyPress( QKeyEvent * ) );
241 CONNECT( this, askUpdate(), this, doComponentsUpdate() );
242 CONNECT( THEDP, toolBarConfUpdated(), this, recreateToolbars() );
244 /* Enable the popup menu in the MI */
245 setContextMenuPolicy( Qt::CustomContextMenu );
246 CONNECT( this, customContextMenuRequested( const QPoint& ),
247 this, popupMenu( const QPoint& ) );
249 /** END of CONNECTS**/
252 /**** FINAL SIZING and placement of interface */
253 settings->beginGroup( "MainWindow" );
254 QVLCTools::restoreWidgetPosition( settings, this, QSize(380, 60) );
256 /* resize to previously saved main window size if appicable */
259 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
260 i_visualmode == QT_MINIMAL_MODE )
262 resize( mainVideoSize );
266 resize( mainBasedSize );
270 msg_Dbg( p_intf, "%i", stackCentralOldState );
272 if( settings->value( "playlist-visible", 0 ).toInt() )
274 settings->endGroup();
276 /* Final sizing and showing */
277 setVisible( !b_hideAfterCreation );
278 //setMinimumSize( QSize( 0, 0 ) );
279 // setMinimumWidth( __MAX( controls->sizeHint().width(),
280 // menuBar()->sizeHint().width() ) );
283 /* And switch to minimal view if needed
284 Must be called after the show() */
285 if( i_visualmode == QT_MINIMAL_MODE )
286 toggleMinimalView( true );
288 /* Update the geometry : It is useful if you switch between
291 resize( sizeHint() );
294 MainInterface::~MainInterface()
296 msg_Dbg( p_intf, "Destroying the main interface" );
298 /* Unsure we hide the videoWidget before destroying it */
299 if( stackCentralOldState == VIDEO_TAB )
302 /* Save playlist state */
306 QVLCTools::saveWidgetPosition( p_intf, "Playlist", playlistWidget );
308 delete playlistWidget;
313 ImageList_Destroy( himl );
315 p_taskbl->vt->Release(p_taskbl);
319 /* Be sure to kill the actionsManager... FIXME */
320 ActionsManager::killInstance();
323 ExtensionsManager::killInstance();
325 /* Delete the FSC controller */
326 delete fullscreenControls;
329 settings->beginGroup( "MainWindow" );
330 settings->setValue( "pl-dock-status", (int)i_pl_dock );
331 settings->setValue( "playlist-visible", (int)playlistVisible );
332 settings->setValue( "adv-controls",
333 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
335 settings->setValue( "mainBasedSize", mainBasedSize );
336 settings->setValue( "mainVideoSize", mainVideoSize );
339 settings->setValue( "backgroundSize", bgWidget->size() );
342 QVLCTools::saveWidgetPosition(settings, this);
343 settings->endGroup();
345 /* Unregister callbacks */
346 var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
347 var_DelCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
349 p_intf->p_sys->p_mi = NULL;
352 /*****************************
354 *****************************/
355 void MainInterface::recreateToolbars()
357 //msg_Dbg( p_intf, "Recreating the toolbars" );
358 settings->beginGroup( "MainWindow" );
362 controls = new ControlsWidget( p_intf, false, this ); /* FIXME */
363 CONNECT( controls, advancedControlsToggled( bool ),
364 this, doComponentsUpdate() );
365 CONNECT( controls, sizeChanged(),
366 this, doComponentsUpdate() );
368 inputC = new InputControlsWidget( p_intf, this );
370 mainLayout->insertWidget( 2, inputC );
371 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
373 settings->endGroup();
376 void MainInterface::createMainWidget( QSettings *settings )
378 /* Create the main Widget and the mainLayout */
379 QWidget *main = new QWidget;
380 setCentralWidget( main );
381 mainLayout = new QVBoxLayout( main );
383 /* Margins, spacing */
384 main->setContentsMargins( 0, 0, 0, 0 );
385 mainLayout->setSpacing( 0 ); mainLayout->setMargin( 0 );
388 stackCentralW = new QStackedWidget( main );
391 bgWidget = new BackgroundWidget( p_intf );
393 settings->value( "backgroundSize", QSize( 300, 200 ) ).toSize() );
394 bgWidget->updateGeometry();
395 stackCentralW->insertWidget( BACKG_TAB, bgWidget );
398 /* And video Outputs */
399 if( videoEmbeddedFlag )
401 videoWidget = new VideoWidget( p_intf );
402 stackCentralW->insertWidget( VIDEO_TAB, videoWidget );
404 mainLayout->insertWidget( 1, stackCentralW, 100 );
407 /* Create the CONTROLS Widget */
408 controls = new ControlsWidget( p_intf,
409 settings->value( "adv-controls", false ).toBool(), this );
410 CONNECT( controls, advancedControlsToggled( bool ),
411 this, doComponentsUpdate() );
412 CONNECT( controls, sizeChanged(),
413 this, doComponentsUpdate() );
414 inputC = new InputControlsWidget( p_intf, this );
416 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
417 i_visualmode != QT_MINIMAL_MODE )
420 stackCentralOldState = HIDDEN_TAB;
424 showTab( BACKG_TAB );
425 stackCentralOldState = BACKG_TAB;
429 //mainLayout->setRowStretch( 1, 10 );
430 mainLayout->insertWidget( 2, inputC );
431 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
435 /* Disabled for now, they SUCK */
437 visualSelector = new VisualSelector( p_intf );
438 mainLayout->insertWidget( 0, visualSelector );
439 visualSelector->hide();
442 /* Finish the sizing */
443 main->updateGeometry();
445 getSettings()->endGroup();
449 /* Create the FULLSCREEN CONTROLS Widget */
450 if( var_InheritBool( p_intf, "qt-fs-controller" ) )
452 fullscreenControls = new FullscreenControllerWidget( p_intf, this );
453 CONNECT( fullscreenControls, keyPressed( QKeyEvent * ),
454 this, handleKeyPress( QKeyEvent * ) );
458 inline void MainInterface::initSystray()
461 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
462 bool b_systrayWanted = var_InheritBool( p_intf, "qt-system-tray" );
464 if( var_InheritBool( p_intf, "qt-start-minimized") )
466 if( b_systrayAvailable )
468 b_systrayWanted = true;
469 b_hideAfterCreation = true;
472 msg_Err( p_intf, "cannot start minimized without system tray bar" );
475 if( b_systrayAvailable && b_systrayWanted )
480 inline void MainInterface::createStatusBar()
485 /* Widgets Creation*/
486 QStatusBar *statusBarr = statusBar();
488 TimeLabel *timeLabel = new TimeLabel( p_intf );
489 nameLabel = new QLabel( this );
490 nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
491 | Qt::TextSelectableByKeyboard );
492 SpeedLabel *speedLabel = new SpeedLabel( p_intf, "1.00x", this );
494 /* Styling those labels */
495 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
496 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
497 nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
499 /* and adding those */
500 statusBarr->addWidget( nameLabel, 8 );
501 statusBarr->addPermanentWidget( speedLabel, 0 );
502 statusBarr->addPermanentWidget( timeLabel, 0 );
504 /* timeLabel behaviour:
505 - double clicking opens the goto time dialog
506 - right-clicking and clicking just toggle between remaining and
508 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
510 CONNECT( THEMIM->getIM(), encryptionChanged( bool ),
511 this, showCryptedLabel( bool ) );
515 void MainInterface::createTaskBarButtons()
517 taskbar_wmsg = WM_NULL;
518 /*Here is the code for the taskbar thumb buttons
519 FIXME:We need pretty buttons in 16x16 px that are handled correctly by masks in Qt
520 FIXME:the play button's picture doesn't changed to pause when clicked
525 if( S_OK == CoCreateInstance( &clsid_ITaskbarList,
526 NULL, CLSCTX_INPROC_SERVER,
528 (void **)&p_taskbl) )
530 p_taskbl->vt->HrInit(p_taskbl);
532 if(himl = ImageList_Create( 15, //cx
535 4,//initial nb of images
536 0//nb of images that can be added
539 QPixmap img = QPixmap(":/toolbar/previous_b");
540 QPixmap img2 = QPixmap(":/toolbar/pause_b");
541 QPixmap img3 = QPixmap(":/toolbar/play_b");
542 QPixmap img4 = QPixmap(":/toolbar/next_b");
543 QBitmap mask = img.createMaskFromColor(Qt::transparent);
544 QBitmap mask2 = img2.createMaskFromColor(Qt::transparent);
545 QBitmap mask3 = img3.createMaskFromColor(Qt::transparent);
546 QBitmap mask4 = img4.createMaskFromColor(Qt::transparent);
548 if(-1 == ImageList_Add(himl, img.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask.toWinHBITMAP()))
549 msg_Err( p_intf, "ImageList_Add failed" );
550 if(-1 == ImageList_Add(himl, img2.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask2.toWinHBITMAP()))
551 msg_Err( p_intf, "ImageList_Add failed" );
552 if(-1 == ImageList_Add(himl, img3.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask3.toWinHBITMAP()))
553 msg_Err( p_intf, "ImageList_Add failed" );
554 if(-1 == ImageList_Add(himl, img4.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask4.toWinHBITMAP()))
555 msg_Err( p_intf, "ImageList_Add failed" );
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[3];
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, winId(), himl );
580 msg_Err( p_intf, "ThumbBarSetImageList failed with error %08x", hr );
583 hr = p_taskbl->vt->ThumbBarAddButtons(p_taskbl, winId(), 3, thbButtons);
585 msg_Err( p_intf, "ThumbBarAddButtons failed with error %08x", hr );
587 CONNECT( THEMIM->getIM(), statusChanged( int ), this, changeThumbbarButtons( int ) );
597 bool MainInterface::winEvent ( MSG * msg, long * result )
599 if (msg->message == taskbar_wmsg)
601 //We received the taskbarbuttoncreated, now we can really create th buttons
602 createTaskBarButtons();
606 switch( msg->message )
609 if (HIWORD(msg->wParam) == THBN_CLICKED)
611 switch(LOWORD(msg->wParam))
617 THEMIM->togglePlayPause();
626 cmd = GET_APPCOMMAND_LPARAM(msg->lParam);
629 case APPCOMMAND_MEDIA_PLAY_PAUSE:
630 THEMIM->togglePlayPause();
632 case APPCOMMAND_MEDIA_PLAY:
635 case APPCOMMAND_MEDIA_PAUSE:
638 case APPCOMMAND_MEDIA_PREVIOUSTRACK:
641 case APPCOMMAND_MEDIA_NEXTTRACK:
644 case APPCOMMAND_MEDIA_STOP:
647 case APPCOMMAND_VOLUME_DOWN:
650 case APPCOMMAND_VOLUME_UP:
653 case APPCOMMAND_VOLUME_MUTE:
654 THEAM->toggleMuteAudio();
657 msg_Dbg( p_intf, "unknown APPCOMMAND = %d", cmd);
666 /**********************************************************************
667 * Handling of sizing of the components
668 **********************************************************************/
670 /* This function is probably wrong, but we don't have many many choices...
671 Since we can't know from the playlist Widget if we are inside a dock or not,
672 because the playlist Widget can be called by THEDP, as a separate windows for
674 Maybe the other solution is to redefine the sizeHint() of the playlist and
675 ask _parent->isFloating()...
676 If you think this would be better, please FIXME it...
679 QSize MainInterface::sizeHint() const
684 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
685 i_visualmode == QT_MINIMAL_MODE )
687 return mainVideoSize;
691 if( VISIBLE( bgWidget) ||
692 ( videoIsActive && videoWidget->isVisible() )
694 return mainVideoSize;
696 return mainBasedSize;
701 int nwidth = __MAX( controls->sizeHint().width(),
702 menuBar()->sizeHint().width() );
704 int nheight = controls->isVisible() ?
705 controls->size().height()
706 + inputC->size().height()
707 + menuBar()->size().height()
708 + statusBar()->size().height()
711 if( stackCentralW->isVisible() )
712 nheight += stackCentralW->height();
713 nwidth = __MAX( nwidth, stackCentralW->width() );
715 /* if( VISIBLE( bgWidget ) )
717 msg_Warn( p_intf, "Hello here" );
719 nheight += i_bg_height;
721 nheight += bgWidget->size().height();
722 nwidth = __MAX( nwidth, bgWidget->size().width() );
724 else if( videoIsActive && videoWidget->isVisible() )
726 msg_Warn( p_intf, "Hello there" );
727 nheight += videoWidget->sizeHint().height();
728 nwidth = __MAX( nwidth, videoWidget->sizeHint().width() );
731 if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget() )
733 nheight += dockPL->size().height();
734 nwidth = __MAX( nwidth, dockPL->size().width() );
735 msg_Warn( p_intf, "3 %i %i", nheight, nwidth );
738 return QSize( nwidth, nheight );
742 /* Video widget cannot do this synchronously as it runs in another thread */
743 /* Well, could it, actually ? Probably dangerous ... */
745 /* This function is called:
746 - toggling of minimal View
747 - through askUpdate() by Vout thread request video and resize video (zoom)
748 - Advanced buttons toggled
750 void MainInterface::doComponentsUpdate()
752 if( isFullScreen() || isMaximized() ) return;
754 // msg_Warn( p_intf, "Updating the geometry" );
755 /* Here we resize to sizeHint() and not adjustsize because we want
756 the videoWidget to be exactly the correctSize */
761 /* This is WRONG, but I believe there is a Qt bug here */
762 setMinimumSize( 0, 0 );
763 resize( sizeHint() );
765 //adjustSize() ; /* This is not needed, but might help in the future */
768 void MainInterface::debug()
771 msg_Dbg( p_intf, "Stack Size: %i - %i", stackCentralW->size().height(), size().width() );
772 if( videoEmbeddedFlag )
773 msg_Dbg( p_intf, "Stack Size: %i - %i",
774 stackCentralW->widget( VIDEO_TAB )->size().height(),
775 stackCentralW->widget( VIDEO_TAB )->size().width() );
777 msg_Dbg( p_intf, "no embedded video" );
779 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
780 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
781 //msg_Dbg( p_intf, "maximumsize: %i - %i", maximumSize().height(), maximumSize().width() );
783 msg_Dbg( p_intf, "Stack minimumsize: %i - %i", stackCentralW->minimumSize().height(), stackCentralW->minimumSize().width() );
784 msg_Dbg( p_intf, "Controls minimumsize: %i - %i", controls->minimumSize().height(), controls->minimumSize().width() );
785 msg_Dbg( p_intf, "Central minimumsize: %i - %i", centralWidget()->minimumSize().height(), centralWidget()->minimumSize().width() );
786 msg_Dbg( p_intf, "Menu minimumsize: %i - %i", menuBar()->minimumSize().height(), menuBar()->minimumSize().width() );
787 msg_Dbg( p_intf, "Input minimuSize: %i - %i", inputC->minimumSize().height(), inputC->minimumSize().width() );
788 msg_Dbg( p_intf, "Status minimumsize: %i - %i", statusBar()->minimumSize().height(), statusBar()->minimumSize().width() );
789 msg_Dbg( p_intf, "minimumsize: %i - %i", minimumSize().height(), minimumSize().width() );
791 /*if( videoWidget && videoWidget->isVisible() )
793 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
794 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
799 inline void MainInterface::showTab( int i_tab )
802 msg_Err( p_intf, "showTab %i", i_tab );
803 msg_Warn( p_intf, "Old stackCentralOldState %i", stackCentralOldState );
805 stackCentralOldState = stackCentralW->isVisible() ? stackCentralW->currentIndex()
808 msg_Warn( p_intf, "State change %i %i", stackCentralW->currentIndex(), i_tab );
811 if( i_visualmode == QT_NORMAL_MODE )
813 stackCentralW->setVisible( i_tab != HIDDEN_TAB );
814 doComponentsUpdate(); // resize the player
817 if( i_tab == HIDDEN_TAB ) i_tab == BACKG_TAB;
819 stackCentralW->setCurrentIndex( i_tab );
822 msg_Warn( p_intf, "New stackCentralOldState %i", stackCentralOldState );
826 inline void MainInterface::restoreStackOldWidget()
829 msg_Warn( p_intf, "Old stackCentralOldState %i", stackCentralOldState );
831 int temp = stackCentralW->isVisible() ? stackCentralW->currentIndex()
833 stackCentralW->setCurrentIndex( stackCentralOldState );
834 if( i_visualmode == QT_NORMAL_MODE )
836 stackCentralW->setVisible( stackCentralOldState != HIDDEN_TAB );
837 doComponentsUpdate(); // resize the player
840 stackCentralOldState = temp;
842 msg_Warn( p_intf, "Debug %i %i", temp, stackCentralW->currentIndex() );
846 void MainInterface::destroyPopupMenu()
848 QVLCMenu::PopupMenu( p_intf, false );
851 void MainInterface::toggleFSC()
853 if( !fullscreenControls ) return;
855 IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
856 QApplication::postEvent( fullscreenControls, eShow );
859 void MainInterface::popupMenu( const QPoint &p )
861 /* Ow, that's ugly: don't show the popup menu if cursor over
862 * the main menu bar or the status bar */
863 if( !childAt( p ) || ( ( childAt( p ) != menuBar() )
864 && ( childAt( p )->parentWidget() != statusBar() ) ) )
865 QVLCMenu::PopupMenu( p_intf, true );
868 /****************************************************************************
870 ****************************************************************************/
872 /* This event is used to deal with the fullscreen and always on top
873 issue conflict (bug in wx) */
874 class SetVideoOnTopQtEvent : public QEvent
877 SetVideoOnTopQtEvent( bool _onTop ) :
878 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
881 bool OnTop() const { return onTop; }
889 * You must note change the state of this object or other Qt4 UI objects,
890 * from the video output thread - only from the Qt4 UI main loop thread.
891 * All window provider queries must be handled through signals or events.
892 * That's why we have all those emit statements...
894 WId MainInterface::getVideo( int *pi_x, int *pi_y,
895 unsigned int *pi_width, unsigned int *pi_height )
900 /* This is a blocking call signal. Results are returned through pointers.
901 * Beware of deadlocks! */
903 emit askGetVideo( &id, pi_x, pi_y, pi_width, pi_height );
907 void MainInterface::getVideoSlot( WId *p_id, int *pi_x, int *pi_y,
908 unsigned *pi_width, unsigned *pi_height )
910 /* Request the videoWidget */
911 WId ret = videoWidget->request( pi_x, pi_y,
912 pi_width, pi_height, b_keep_size );
914 if( ret ) /* The videoWidget is available */
916 /* ask videoWidget to show */
917 videoWidget->SetSizing( *pi_width, *pi_height );
919 /* Consider the video active now */
922 stackCentralW->resize( *pi_width, *pi_height );
930 /* Asynchronous call from the WindowClose function */
931 void MainInterface::releaseVideo( void )
933 emit askReleaseVideo( );
936 /* Function that is CONNECTED to the previous emit */
937 void MainInterface::releaseVideoSlot( void )
939 videoWidget->release( );
941 restoreStackOldWidget();
943 /* Try to resize, except when you are in Fullscreen mode */
944 // doComponentsUpdate();
947 /* Asynchronous call from WindowControl function */
948 int MainInterface::controlVideo( int i_query, va_list args )
950 /* Debug to check if VOUT_WINDOW_SET_SIZE is called, because this is broken now */
951 msg_Warn( p_intf, "Control Video: %i", i_query );
954 case VOUT_WINDOW_SET_SIZE:
956 unsigned int i_width = va_arg( args, unsigned int );
957 unsigned int i_height = va_arg( args, unsigned int );
958 emit askVideoToResize( i_width, i_height );
962 case VOUT_WINDOW_SET_STATE:
964 unsigned i_arg = va_arg( args, unsigned );
965 unsigned on_top = i_arg & VOUT_WINDOW_STATE_ABOVE;
966 QApplication::postEvent( this, new SetVideoOnTopQtEvent( on_top ) );
969 case VOUT_WINDOW_SET_FULLSCREEN:
971 bool b_fs = va_arg( args, int );
972 emit askVideoSetFullScreen( b_fs );
976 msg_Warn( p_intf, "unsupported control query" );
981 /*****************************************************************************
982 * Playlist, Visualisation and Menus handling
983 *****************************************************************************/
985 * Toggle the playlist widget or dialog
987 void MainInterface::createPlaylist( bool b_show )
989 playlistWidget = new PlaylistWidget( p_intf, this );
991 i_pl_dock = PL_BOTTOM;
992 /* i_pl_dock = (pl_dock_e)getSettings()
993 ->value( "pl-dock-status", PL_UNDOCKED ).toInt(); */
995 if( i_pl_dock == PL_UNDOCKED )
997 playlistWidget->setWindowFlags( Qt::Window );
999 /* This will restore the geometry but will not work for position,
1000 because of parenting */
1001 QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
1002 playlistWidget, QSize( 600, 300 ) );
1007 msg_Warn( p_intf, "Here %i", stackCentralW->currentIndex() );
1009 stackCentralW->insertWidget( PLAYL_TAB, playlistWidget );
1011 msg_Warn( p_intf, "Here %i", stackCentralW->currentIndex() );
1017 playlistVisible = true;
1018 stackCentralW->show();
1022 void MainInterface::togglePlaylist()
1025 msg_Warn( p_intf, "Here toggling %i %i", stackCentralW->currentIndex(), stackCentralOldState );
1027 if( !playlistWidget )
1029 createPlaylist( true );
1032 msg_Warn( p_intf, "Here toggling %i %i", stackCentralW->currentIndex(), stackCentralOldState );
1035 if( i_pl_dock != PL_UNDOCKED )
1037 /* Playlist not visible */
1038 if( stackCentralW->currentIndex() != PLAYL_TAB )
1040 showTab( PLAYL_TAB );
1041 stackCentralW->show();
1045 restoreStackOldWidget();
1047 playlistVisible = ( stackCentralW->currentIndex() == PLAYL_TAB );
1048 //doComponentsUpdate(); //resize( sizeHint() );
1052 /* Function called from the menu to undock the playlist */
1053 void MainInterface::undockPlaylist()
1055 // dockPL->setFloating( true );
1059 void MainInterface::dockPlaylist( pl_dock_e i_pos )
1063 void MainInterface::toggleMinimalView( bool b_switch )
1065 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
1066 i_visualmode != QT_MINIMAL_MODE )
1067 { /* NORMAL MODE then */
1068 stackCentralW->show();
1069 if( !videoWidget || stackCentralW->currentIndex() != VIDEO_TAB )
1075 /* If video is visible, then toggle the status of bgWidget */
1076 //bgWasVisible = !bgWasVisible;
1077 if( stackCentralOldState == BACKG_TAB )
1078 stackCentralOldState = HIDDEN_TAB;
1080 stackCentralOldState = BACKG_TAB;
1084 i_bg_height = stackCentralW->height();
1086 menuBar()->setVisible( !b_switch );
1087 controls->setVisible( !b_switch );
1088 statusBar()->setVisible( !b_switch );
1089 inputC->setVisible( !b_switch );
1091 doComponentsUpdate();
1093 emit minimalViewToggled( b_switch );
1096 /* toggling advanced controls buttons */
1097 void MainInterface::toggleAdvanced()
1099 controls->toggleAdvanced();
1100 // if( fullscreenControls ) fullscreenControls->toggleAdvanced();
1103 /* Get the visibility status of the controls (hidden or not, advanced or not) */
1104 int MainInterface::getControlsVisibilityStatus()
1106 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
1107 + CONTROLS_ADVANCED * controls->b_advancedVisible );
1111 void MainInterface::visual()
1113 if( !VISIBLE( visualSelector) )
1115 visualSelector->show();
1116 if( !THEMIM->getIM()->hasVideo() )
1118 /* Show the background widget */
1120 visualSelectorEnabled = true;
1124 /* Stop any currently running visualization */
1125 visualSelector->hide();
1126 visualSelectorEnabled = false;
1128 doComponentsUpdate();
1132 /************************************************************************
1134 ************************************************************************/
1135 void MainInterface::setName( const QString& name )
1137 input_name = name; /* store it for the QSystray use */
1138 /* Display it in the status bar, but also as a Tooltip in case it doesn't
1140 nameLabel->setText( " " + name + " " );
1141 nameLabel->setToolTip( " " + name +" " );
1145 * Give the decorations of the Main Window a correct Name.
1146 * If nothing is given, set it to VLC...
1148 void MainInterface::setVLCWindowsTitle( const QString& aTitle )
1150 if( aTitle.isEmpty() )
1152 setWindowTitle( qtr( "VLC media player" ) );
1156 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
1160 void MainInterface::showCryptedLabel( bool b_show )
1162 if( cryptedLabel == NULL )
1164 cryptedLabel = new QLabel;
1165 // The lock icon is not the right one for DRM protection/scrambled.
1166 //cryptedLabel->setPixmap( QPixmap( ":/lock" ) );
1167 cryptedLabel->setText( "DRM" );
1168 statusBar()->addWidget( cryptedLabel );
1171 cryptedLabel->setVisible( b_show );
1174 /*****************************************************************************
1175 * Systray Icon and Systray Menu
1176 *****************************************************************************/
1179 * Create a SystemTray icon and a menu that would go with it.
1180 * Connects to a click handler on the icon.
1182 void MainInterface::createSystray()
1185 if( QDate::currentDate().dayOfYear() >= 354 )
1186 iconVLC = QIcon( ":/logo/vlc128-christmas.png" );
1188 iconVLC = QIcon( ":/logo/vlc128.png" );
1189 sysTray = new QSystemTrayIcon( iconVLC, this );
1190 sysTray->setToolTip( qtr( "VLC media player" ));
1192 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
1193 systrayMenu->setIcon( iconVLC );
1195 QVLCMenu::updateSystrayMenu( this, p_intf, true );
1198 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
1199 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
1203 * Updates the Systray Icon's menu and toggle the main interface
1205 void MainInterface::toggleUpdateSystrayMenu()
1207 /* If hidden, show it */
1213 else if( isMinimized() )
1221 /* Visible (possibly under other windows) */
1223 /* check if any visible window is above vlc in the z-order,
1224 * but ignore the ones always on top
1225 * and the ones which can't be activated */
1228 wi.cbSize = sizeof( WINDOWINFO );
1229 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
1230 hwnd && ( !IsWindowVisible( hwnd ) ||
1231 ( GetWindowInfo( hwnd, &wi ) &&
1232 (wi.dwExStyle&WS_EX_NOACTIVATE) ) );
1233 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
1234 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
1235 (wi.dwExStyle&WS_EX_TOPMOST) )
1247 QVLCMenu::updateSystrayMenu( this, p_intf );
1250 void MainInterface::handleSystrayClick(
1251 QSystemTrayIcon::ActivationReason reason )
1255 case QSystemTrayIcon::Trigger:
1256 case QSystemTrayIcon::DoubleClick:
1257 toggleUpdateSystrayMenu();
1259 case QSystemTrayIcon::MiddleClick:
1260 sysTray->showMessage( qtr( "VLC media player" ),
1261 qtr( "Control menu for the player" ),
1262 QSystemTrayIcon::Information, 3000 );
1270 * Updates the name of the systray Icon tooltip.
1271 * Doesn't check if the systray exists, check before you call it.
1273 void MainInterface::updateSystrayTooltipName( const QString& name )
1275 if( name.isEmpty() )
1277 sysTray->setToolTip( qtr( "VLC media player" ) );
1281 sysTray->setToolTip( name );
1282 if( notificationEnabled && ( isHidden() || isMinimized() ) )
1284 sysTray->showMessage( qtr( "VLC media player" ), name,
1285 QSystemTrayIcon::NoIcon, 3000 );
1289 QVLCMenu::updateSystrayMenu( this, p_intf );
1293 * Updates the status of the systray Icon tooltip.
1294 * Doesn't check if the systray exists, check before you call it.
1296 void MainInterface::updateSystrayTooltipStatus( int i_status )
1303 sysTray->setToolTip( qtr( "VLC media player" ) );
1308 sysTray->setToolTip( input_name );
1313 sysTray->setToolTip( input_name + " - "
1318 QVLCMenu::updateSystrayMenu( this, p_intf );
1322 /************************************************************************
1324 ************************************************************************/
1325 void MainInterface::dropEvent(QDropEvent *event)
1327 dropEventPlay( event, true );
1330 void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
1332 event->setDropAction( Qt::CopyAction );
1333 if( !event->possibleActions() & Qt::CopyAction )
1336 const QMimeData *mimeData = event->mimeData();
1338 /* D&D of a subtitles file, add it on the fly */
1339 if( mimeData->urls().size() == 1 && THEMIM->getIM()->hasInput() )
1341 if( !input_AddSubtitle( THEMIM->getInput(),
1342 qtu( toNativeSeparators( mimeData->urls()[0].toLocalFile() ) ),
1350 bool first = b_play;
1351 foreach( const QUrl &url, mimeData->urls() )
1353 QString s = toNativeSeparators( url.toLocalFile() );
1355 if( s.length() > 0 ) {
1356 char* psz_uri = make_URI( qtu(s) );
1357 playlist_Add( THEPL, psz_uri, NULL,
1358 PLAYLIST_APPEND | (first ? PLAYLIST_GO: PLAYLIST_PREPARSE),
1359 PLAYLIST_END, true, pl_Unlocked );
1362 RecentsMRL::getInstance( p_intf )->addRecent( s );
1367 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1369 event->acceptProposedAction();
1371 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1373 event->acceptProposedAction();
1375 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1380 /************************************************************************
1382 ************************************************************************/
1383 void MainInterface::customEvent( QEvent *event )
1386 if( event->type() == PLDockEvent_Type )
1388 PlaylistDialog::killInstance();
1389 playlistEmbeddedFlag = true;
1391 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1396 if ( event->type() == (int)SetVideoOnTopEvent_Type )
1398 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1399 if( p_event->OnTop() )
1400 setWindowFlags( windowFlags() | Qt::WindowStaysOnTopHint );
1402 setWindowFlags( windowFlags() & ~Qt::WindowStaysOnTopHint );
1403 show(); /* necessary to apply window flags */
1407 void MainInterface::keyPressEvent( QKeyEvent *e )
1409 handleKeyPress( e );
1412 void MainInterface::handleKeyPress( QKeyEvent *e )
1414 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() == Qt::Key_H )
1415 && !menuBar()->isVisible() )
1417 toggleMinimalView( false );
1421 int i_vlck = qtEventToVLCKey( e );
1424 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1431 void MainInterface::resizeEvent( QResizeEvent * event )
1436 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
1437 i_visualmode == QT_MINIMAL_MODE )
1439 mainVideoSize = size();
1443 if( VISIBLE( bgWidget) ||
1444 ( videoIsActive && videoWidget->isVisible() )
1446 mainVideoSize = size();
1448 mainBasedSize = size();
1452 QVLCMW::resizeEvent( event );
1453 msg_Dbg( p_intf, "Resize Event, height: %i", size().height() );
1456 void MainInterface::wheelEvent( QWheelEvent *e )
1458 int i_vlckey = qtWheelEventToVLCKey( e );
1459 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1463 void MainInterface::closeEvent( QCloseEvent *e )
1470 void MainInterface::toggleFullScreen( void )
1472 if( isFullScreen() )
1475 emit askUpdate(); // Needed if video was launched after the F11
1476 emit fullscreenInterfaceToggled( false );
1481 emit fullscreenInterfaceToggled( true );
1486 //moc doesn't know about #ifdef, so we have to build this method for every platform
1487 void MainInterface::changeThumbbarButtons( int i_status)
1490 // Define an array of three buttons. These buttons provide images through an
1491 // image list and also provide tooltips.
1492 DWORD dwMask = THB_BITMAP | THB_FLAGS;
1494 THUMBBUTTON thbButtons[3];
1496 thbButtons[0].dwMask = dwMask;
1497 thbButtons[0].iId = 0;
1498 thbButtons[0].iBitmap = 0;
1501 thbButtons[1].dwMask = dwMask;
1502 thbButtons[1].iId = 1;
1505 thbButtons[2].dwMask = dwMask;
1506 thbButtons[2].iId = 2;
1507 thbButtons[2].iBitmap = 3;
1513 thbButtons[0].dwFlags = THBF_ENABLED;
1514 thbButtons[1].dwFlags = THBF_ENABLED;
1515 thbButtons[2].dwFlags = THBF_ENABLED;
1516 thbButtons[1].iBitmap = 1;
1521 thbButtons[0].dwFlags = THBF_ENABLED;
1522 thbButtons[1].dwFlags = THBF_ENABLED;
1523 thbButtons[2].dwFlags = THBF_ENABLED;
1524 thbButtons[1].iBitmap = 2;
1530 HRESULT hr = p_taskbl->vt->ThumbBarUpdateButtons(p_taskbl, this->winId(), 3, thbButtons);
1532 msg_Err( p_intf, "ThumbBarUpdateButtons failed with error %08x", hr );
1538 /*****************************************************************************
1539 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1540 * We don't show the menu directly here because we don't want the
1541 * caller to block for a too long time.
1542 *****************************************************************************/
1543 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1544 vlc_value_t old_val, vlc_value_t new_val, void *param )
1546 intf_thread_t *p_intf = (intf_thread_t *)param;
1548 if( p_intf->pf_show_dialog )
1550 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1551 new_val.b_bool, NULL );
1557 /*****************************************************************************
1558 * IntfShowCB: callback triggered by the intf-show libvlc variable.
1559 *****************************************************************************/
1560 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1561 vlc_value_t old_val, vlc_value_t new_val, void *param )
1563 intf_thread_t *p_intf = (intf_thread_t *)param;
1564 p_intf->p_sys->p_mi->toggleFSC();