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 = 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 );
174 taskbar_wmsg = RegisterWindowMessage("TaskbarButtonCreated");
177 /************************************************************
178 * Connect the input manager to the GUI elements it manages *
179 ************************************************************/
181 * Connects on nameChanged()
182 * Those connects are different because options can impeach them to trigger.
184 /* Main Interface statusbar */
185 CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
186 this, setName( const QString& ) );
191 CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
192 this, updateSystrayTooltipName( const QString& ) );
195 /* and title of the Main Interface*/
196 if( var_InheritBool( p_intf, "qt-name-in-title" ) )
198 CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
199 this, setVLCWindowsTitle( const QString& ) );
203 * CONNECTS on PLAY_STATUS
205 /* Status on the systray */
209 CONNECT( THEMIM->getIM(), statusChanged( int ),
210 this, updateSystrayTooltipStatus( int ) );
214 /* END CONNECTS ON IM */
216 /* VideoWidget connects for asynchronous calls */
217 connect( this, SIGNAL(askGetVideo(WId*,int*,int*,unsigned*,unsigned *)),
218 this, SLOT(getVideoSlot(WId*,int*,int*,unsigned*,unsigned*)),
219 Qt::BlockingQueuedConnection );
220 connect( this, SIGNAL(askReleaseVideo( void )),
221 this, SLOT(releaseVideoSlot( void )),
222 Qt::BlockingQueuedConnection );
226 CONNECT( this, askVideoToResize( unsigned int, unsigned int ),
227 videoWidget, SetSizing( unsigned int, unsigned int ) );
228 CONNECT( this, askVideoSetFullScreen( bool ),
229 videoWidget, SetFullScreen( bool ) );
230 CONNECT( videoWidget, keyPressed( QKeyEvent * ),
231 this, handleKeyPress( QKeyEvent * ) );
234 CONNECT( this, askUpdate(), this, doComponentsUpdate() );
235 CONNECT( THEDP, toolBarConfUpdated(), this, recreateToolbars() );
237 /* Enable the popup menu in the MI */
238 setContextMenuPolicy( Qt::CustomContextMenu );
239 CONNECT( this, customContextMenuRequested( const QPoint& ),
240 this, popupMenu( const QPoint& ) );
242 /** END of CONNECTS**/
248 var_AddCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
250 /* Register callback for the intf-popupmenu variable */
251 var_AddCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
254 /**** FINAL SIZING and placement of interface */
255 settings->beginGroup( "MainWindow" );
256 QVLCTools::restoreWidgetPosition( settings, this, QSize(380, 60) );
258 /* resize to previously saved main window size if appicable */
261 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
262 i_visualmode == QT_MINIMAL_MODE )
264 resize( mainVideoSize );
268 resize( mainBasedSize );
272 msg_Dbg( p_intf, "%i", stackCentralOldState );
275 int i_plVis = settings->value( "playlist-visible", 0 ).toInt();
277 settings->endGroup();
279 if( i_plVis ) togglePlaylist();
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 MainInterface::~MainInterface()
301 /* Unsure we hide the videoWidget before destroying it */
302 if( stackCentralOldState == VIDEO_TAB )
305 /* Save playlist state */
309 QVLCTools::saveWidgetPosition( p_intf, "Playlist", playlistWidget );
311 delete playlistWidget;
316 ImageList_Destroy( himl );
318 p_taskbl->vt->Release(p_taskbl);
322 /* Be sure to kill the actionsManager... FIXME */
323 ActionsManager::killInstance();
326 ExtensionsManager::killInstance();
328 /* Delete the FSC controller */
329 delete fullscreenControls;
332 settings->beginGroup( "MainWindow" );
333 settings->setValue( "pl-dock-status", (int)i_pl_dock );
334 settings->setValue( "playlist-visible", (int)playlistVisible );
335 settings->setValue( "adv-controls",
336 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
338 settings->setValue( "mainBasedSize", mainBasedSize );
339 settings->setValue( "mainVideoSize", mainVideoSize );
342 settings->setValue( "backgroundSize", bgWidget->size() );
345 QVLCTools::saveWidgetPosition(settings, this);
346 settings->endGroup();
350 /* Unregister callbacks */
351 var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
352 var_DelCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
354 p_intf->p_sys->p_mi = NULL;
357 /*****************************
359 *****************************/
360 void MainInterface::recreateToolbars()
362 //msg_Dbg( p_intf, "Recreating the toolbars" );
363 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() );
373 inputC = new InputControlsWidget( p_intf, this );
375 mainLayout->insertWidget( 2, inputC );
376 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
378 settings->endGroup();
381 void MainInterface::createMainWidget( QSettings *settings )
383 /* Create the main Widget and the mainLayout */
384 QWidget *main = new QWidget;
385 setCentralWidget( main );
386 mainLayout = new QVBoxLayout( main );
388 /* Margins, spacing */
389 main->setContentsMargins( 0, 0, 0, 0 );
390 mainLayout->setSpacing( 0 ); 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 );
403 /* And video Outputs */
404 if( videoEmbeddedFlag )
406 videoWidget = new VideoWidget( p_intf );
407 stackCentralW->insertWidget( VIDEO_TAB, videoWidget );
409 mainLayout->insertWidget( 1, stackCentralW, 100 );
412 /* Create the CONTROLS Widget */
413 controls = new ControlsWidget( p_intf,
414 settings->value( "adv-controls", false ).toBool(), this );
415 CONNECT( controls, advancedControlsToggled( bool ),
416 this, doComponentsUpdate() );
417 CONNECT( controls, sizeChanged(),
418 this, doComponentsUpdate() );
419 inputC = new InputControlsWidget( p_intf, this );
421 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
422 i_visualmode != QT_MINIMAL_MODE )
425 stackCentralOldState = HIDDEN_TAB;
429 showTab( BACKG_TAB );
430 stackCentralOldState = BACKG_TAB;
434 //mainLayout->setRowStretch( 1, 10 );
435 mainLayout->insertWidget( 2, inputC );
436 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
440 /* Disabled for now, they SUCK */
442 visualSelector = new VisualSelector( p_intf );
443 mainLayout->insertWidget( 0, visualSelector );
444 visualSelector->hide();
447 /* Finish the sizing */
448 main->updateGeometry();
450 getSettings()->endGroup();
454 /* Create the FULLSCREEN CONTROLS Widget */
455 if( var_InheritBool( p_intf, "qt-fs-controller" ) )
457 fullscreenControls = new FullscreenControllerWidget( p_intf, this );
458 CONNECT( fullscreenControls, keyPressed( QKeyEvent * ),
459 this, handleKeyPress( QKeyEvent * ) );
463 inline void MainInterface::initSystray()
466 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
467 bool b_systrayWanted = var_InheritBool( p_intf, "qt-system-tray" );
469 if( var_InheritBool( p_intf, "qt-start-minimized") )
471 if( b_systrayAvailable )
473 b_systrayWanted = true;
474 b_hideAfterCreation = true;
477 msg_Err( p_intf, "cannot start minimized without system tray bar" );
480 if( b_systrayAvailable && b_systrayWanted )
485 inline void MainInterface::createStatusBar()
490 /* Widgets Creation*/
491 QStatusBar *statusBarr = statusBar();
493 TimeLabel *timeLabel = new TimeLabel( p_intf );
494 nameLabel = new QLabel( this );
495 nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
496 | Qt::TextSelectableByKeyboard );
497 SpeedLabel *speedLabel = new SpeedLabel( p_intf, "1.00x", this );
499 /* Styling those labels */
500 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
501 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
502 nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
504 /* and adding those */
505 statusBarr->addWidget( nameLabel, 8 );
506 statusBarr->addPermanentWidget( speedLabel, 0 );
507 statusBarr->addPermanentWidget( timeLabel, 0 );
509 /* timeLabel behaviour:
510 - double clicking opens the goto time dialog
511 - right-clicking and clicking just toggle between remaining and
513 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
515 CONNECT( THEMIM->getIM(), encryptionChanged( bool ),
516 this, showCryptedLabel( bool ) );
518 connect( THEMIM->getIM(), SIGNAL(seekRequested(float)),
519 timeLabel, SLOT(setDisplayPosition(float)) );
523 void MainInterface::createTaskBarButtons()
525 taskbar_wmsg = WM_NULL;
526 /*Here is the code for the taskbar thumb buttons
527 FIXME:We need pretty buttons in 16x16 px that are handled correctly by masks in Qt
528 FIXME:the play button's picture doesn't changed to pause when clicked
533 if( S_OK == CoCreateInstance( &clsid_ITaskbarList,
534 NULL, CLSCTX_INPROC_SERVER,
536 (void **)&p_taskbl) )
538 p_taskbl->vt->HrInit(p_taskbl);
540 if(himl = ImageList_Create( 15, //cx
543 4,//initial nb of images
544 0//nb of images that can be added
547 QPixmap img = QPixmap(":/toolbar/previous_b");
548 QPixmap img2 = QPixmap(":/toolbar/pause_b");
549 QPixmap img3 = QPixmap(":/toolbar/play_b");
550 QPixmap img4 = QPixmap(":/toolbar/next_b");
551 QBitmap mask = img.createMaskFromColor(Qt::transparent);
552 QBitmap mask2 = img2.createMaskFromColor(Qt::transparent);
553 QBitmap mask3 = img3.createMaskFromColor(Qt::transparent);
554 QBitmap mask4 = img4.createMaskFromColor(Qt::transparent);
556 if(-1 == ImageList_Add(himl, img.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask.toWinHBITMAP()))
557 msg_Err( p_intf, "ImageList_Add failed" );
558 if(-1 == ImageList_Add(himl, img2.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask2.toWinHBITMAP()))
559 msg_Err( p_intf, "ImageList_Add failed" );
560 if(-1 == ImageList_Add(himl, img3.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask3.toWinHBITMAP()))
561 msg_Err( p_intf, "ImageList_Add failed" );
562 if(-1 == ImageList_Add(himl, img4.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask4.toWinHBITMAP()))
563 msg_Err( p_intf, "ImageList_Add failed" );
566 // Define an array of two buttons. These buttons provide images through an
567 // image list and also provide tooltips.
568 DWORD dwMask = THB_BITMAP | THB_FLAGS;
570 THUMBBUTTON thbButtons[3];
571 thbButtons[0].dwMask = dwMask;
572 thbButtons[0].iId = 0;
573 thbButtons[0].iBitmap = 0;
574 thbButtons[0].dwFlags = THBF_HIDDEN;
576 thbButtons[1].dwMask = dwMask;
577 thbButtons[1].iId = 1;
578 thbButtons[1].iBitmap = 2;
579 thbButtons[1].dwFlags = THBF_HIDDEN;
581 thbButtons[2].dwMask = dwMask;
582 thbButtons[2].iId = 2;
583 thbButtons[2].iBitmap = 3;
584 thbButtons[2].dwFlags = THBF_HIDDEN;
586 HRESULT hr = p_taskbl->vt->ThumbBarSetImageList(p_taskbl, winId(), himl );
588 msg_Err( p_intf, "ThumbBarSetImageList failed with error %08x", hr );
591 hr = p_taskbl->vt->ThumbBarAddButtons(p_taskbl, winId(), 3, thbButtons);
593 msg_Err( p_intf, "ThumbBarAddButtons failed with error %08x", hr );
595 CONNECT( THEMIM->getIM(), statusChanged( int ), this, changeThumbbarButtons( int ) );
605 bool MainInterface::winEvent ( MSG * msg, long * result )
607 if (msg->message == taskbar_wmsg)
609 //We received the taskbarbuttoncreated, now we can really create th buttons
610 createTaskBarButtons();
614 switch( msg->message )
617 if (HIWORD(msg->wParam) == THBN_CLICKED)
619 switch(LOWORD(msg->wParam))
625 THEMIM->togglePlayPause();
634 cmd = GET_APPCOMMAND_LPARAM(msg->lParam);
637 case APPCOMMAND_MEDIA_PLAY_PAUSE:
638 THEMIM->togglePlayPause();
640 case APPCOMMAND_MEDIA_PLAY:
643 case APPCOMMAND_MEDIA_PAUSE:
646 case APPCOMMAND_MEDIA_PREVIOUSTRACK:
649 case APPCOMMAND_MEDIA_NEXTTRACK:
652 case APPCOMMAND_MEDIA_STOP:
655 case APPCOMMAND_VOLUME_DOWN:
658 case APPCOMMAND_VOLUME_UP:
661 case APPCOMMAND_VOLUME_MUTE:
662 THEAM->toggleMuteAudio();
665 msg_Dbg( p_intf, "unknown APPCOMMAND = %d", cmd);
674 /**********************************************************************
675 * Handling of sizing of the components
676 **********************************************************************/
678 /* This function is probably wrong, but we don't have many many choices...
679 Since we can't know from the playlist Widget if we are inside a dock or not,
680 because the playlist Widget can be called by THEDP, as a separate windows for
682 Maybe the other solution is to redefine the sizeHint() of the playlist and
683 ask _parent->isFloating()...
684 If you think this would be better, please FIXME it...
687 QSize MainInterface::sizeHint() const
692 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
693 i_visualmode == QT_MINIMAL_MODE )
695 return mainVideoSize;
699 if( VISIBLE( bgWidget) ||
700 ( videoIsActive && videoWidget->isVisible() )
702 return mainVideoSize;
704 return mainBasedSize;
709 int nwidth = __MAX( controls->sizeHint().width(),
710 menuBar()->sizeHint().width() );
712 int nheight = controls->isVisible() ?
713 controls->size().height()
714 + inputC->size().height()
715 + menuBar()->size().height()
716 + statusBar()->size().height()
719 if( stackCentralW->isVisible() )
721 nheight += stackCentralW->height();
722 nwidth = __MAX( nwidth, stackCentralW->width() );
725 /* if( VISIBLE( bgWidget ) )
727 msg_Warn( p_intf, "Hello here" );
729 nheight += i_bg_height;
731 nheight += bgWidget->size().height();
732 nwidth = __MAX( nwidth, bgWidget->size().width() );
734 else if( videoIsActive && videoWidget->isVisible() )
736 msg_Warn( p_intf, "Hello there" );
737 nheight += videoWidget->sizeHint().height();
738 nwidth = __MAX( nwidth, videoWidget->sizeHint().width() );
741 if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget() )
743 nheight += dockPL->size().height();
744 nwidth = __MAX( nwidth, dockPL->size().width() );
745 msg_Warn( p_intf, "3 %i %i", nheight, nwidth );
748 return QSize( nwidth, nheight );
752 /* Video widget cannot do this synchronously as it runs in another thread */
753 /* Well, could it, actually ? Probably dangerous ... */
755 /* This function is called:
756 - toggling of minimal View
757 - through askUpdate() by Vout thread request video and resize video (zoom)
758 - Advanced buttons toggled
760 void MainInterface::doComponentsUpdate()
762 if( isFullScreen() || isMaximized() ) return;
764 // msg_Warn( p_intf, "Updating the geometry" );
765 /* Here we resize to sizeHint() and not adjustsize because we want
766 the videoWidget to be exactly the correctSize */
771 /* This is WRONG, but I believe there is a Qt bug here */
772 setMinimumSize( 0, 0 );
773 resize( sizeHint() );
775 //adjustSize() ; /* This is not needed, but might help in the future */
778 void MainInterface::debug()
781 msg_Dbg( p_intf, "Stack Size: %i - %i", stackCentralW->size().height(), size().width() );
782 if( videoEmbeddedFlag )
783 msg_Dbg( p_intf, "Stack Size: %i - %i",
784 stackCentralW->widget( VIDEO_TAB )->size().height(),
785 stackCentralW->widget( VIDEO_TAB )->size().width() );
787 msg_Dbg( p_intf, "no embedded video" );
789 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
790 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
791 //msg_Dbg( p_intf, "maximumsize: %i - %i", maximumSize().height(), maximumSize().width() );
793 msg_Dbg( p_intf, "Stack minimumsize: %i - %i", stackCentralW->minimumSize().height(), stackCentralW->minimumSize().width() );
794 msg_Dbg( p_intf, "Controls minimumsize: %i - %i", controls->minimumSize().height(), controls->minimumSize().width() );
795 msg_Dbg( p_intf, "Central minimumsize: %i - %i", centralWidget()->minimumSize().height(), centralWidget()->minimumSize().width() );
796 msg_Dbg( p_intf, "Menu minimumsize: %i - %i", menuBar()->minimumSize().height(), menuBar()->minimumSize().width() );
797 msg_Dbg( p_intf, "Input minimuSize: %i - %i", inputC->minimumSize().height(), inputC->minimumSize().width() );
798 msg_Dbg( p_intf, "Status minimumsize: %i - %i", statusBar()->minimumSize().height(), statusBar()->minimumSize().width() );
799 msg_Dbg( p_intf, "minimumsize: %i - %i", minimumSize().height(), minimumSize().width() );
801 /*if( videoWidget && videoWidget->isVisible() )
803 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
804 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
809 inline void MainInterface::showTab( int i_tab )
812 msg_Err( p_intf, "showTab %i", i_tab );
813 msg_Warn( p_intf, "Old stackCentralOldState %i", stackCentralOldState );
815 stackCentralOldState = stackCentralW->isVisible() ? stackCentralW->currentIndex()
818 msg_Warn( p_intf, "State change %i %i", stackCentralW->currentIndex(), i_tab );
821 if( i_visualmode == QT_NORMAL_MODE )
823 stackCentralW->setVisible( i_tab != HIDDEN_TAB );
824 doComponentsUpdate(); // resize the player
827 if( i_tab == HIDDEN_TAB ) i_tab = BACKG_TAB;
829 stackCentralW->setCurrentIndex( i_tab );
832 msg_Warn( p_intf, "New stackCentralOldState %i", stackCentralOldState );
836 inline void MainInterface::restoreStackOldWidget()
839 msg_Warn( p_intf, "Old stackCentralOldState %i", stackCentralOldState );
841 int temp = stackCentralW->isVisible() ? stackCentralW->currentIndex()
843 stackCentralW->setCurrentIndex( stackCentralOldState );
844 if( i_visualmode == QT_NORMAL_MODE )
846 stackCentralW->setVisible( stackCentralOldState != HIDDEN_TAB );
847 doComponentsUpdate(); // resize the player
850 stackCentralOldState = temp;
852 msg_Warn( p_intf, "Debug %i %i", temp, stackCentralW->currentIndex() );
856 void MainInterface::destroyPopupMenu()
858 QVLCMenu::PopupMenu( p_intf, false );
861 void MainInterface::toggleFSC()
863 if( !fullscreenControls ) return;
865 IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
866 QApplication::postEvent( fullscreenControls, eShow );
869 void MainInterface::popupMenu( const QPoint &p )
871 /* Ow, that's ugly: don't show the popup menu if cursor over
872 * the main menu bar or the status bar */
873 if( !childAt( p ) || ( ( childAt( p ) != menuBar() )
874 && ( childAt( p )->parentWidget() != statusBar() ) ) )
875 QVLCMenu::PopupMenu( p_intf, true );
878 /****************************************************************************
880 ****************************************************************************/
882 /* This event is used to deal with the fullscreen and always on top
883 issue conflict (bug in wx) */
884 class SetVideoOnTopQtEvent : public QEvent
887 SetVideoOnTopQtEvent( bool _onTop ) :
888 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
891 bool OnTop() const { return onTop; }
899 * You must note change the state of this object or other Qt4 UI objects,
900 * from the video output thread - only from the Qt4 UI main loop thread.
901 * All window provider queries must be handled through signals or events.
902 * That's why we have all those emit statements...
904 WId MainInterface::getVideo( int *pi_x, int *pi_y,
905 unsigned int *pi_width, unsigned int *pi_height )
910 /* This is a blocking call signal. Results are returned through pointers.
911 * Beware of deadlocks! */
913 emit askGetVideo( &id, pi_x, pi_y, pi_width, pi_height );
917 void MainInterface::getVideoSlot( WId *p_id, int *pi_x, int *pi_y,
918 unsigned *pi_width, unsigned *pi_height )
920 /* Request the videoWidget */
921 WId ret = videoWidget->request( pi_x, pi_y,
922 pi_width, pi_height, b_keep_size );
924 if( ret ) /* The videoWidget is available */
926 /* ask videoWidget to show */
927 videoWidget->SetSizing( *pi_width, *pi_height );
929 /* Consider the video active now */
932 stackCentralW->resize( *pi_width, *pi_height );
940 /* Asynchronous call from the WindowClose function */
941 void MainInterface::releaseVideo( void )
943 emit askReleaseVideo( );
946 /* Function that is CONNECTED to the previous emit */
947 void MainInterface::releaseVideoSlot( void )
949 videoWidget->release( );
951 restoreStackOldWidget();
953 /* Try to resize, except when you are in Fullscreen mode */
954 // doComponentsUpdate();
957 /* Asynchronous call from WindowControl function */
958 int MainInterface::controlVideo( int i_query, va_list args )
960 /* Debug to check if VOUT_WINDOW_SET_SIZE is called, because this is broken now */
961 msg_Warn( p_intf, "Control Video: %i", i_query );
964 case VOUT_WINDOW_SET_SIZE:
966 unsigned int i_width = va_arg( args, unsigned int );
967 unsigned int i_height = va_arg( args, unsigned int );
968 emit askVideoToResize( i_width, i_height );
972 case VOUT_WINDOW_SET_STATE:
974 unsigned i_arg = va_arg( args, unsigned );
975 unsigned on_top = i_arg & VOUT_WINDOW_STATE_ABOVE;
976 QApplication::postEvent( this, new SetVideoOnTopQtEvent( on_top ) );
979 case VOUT_WINDOW_SET_FULLSCREEN:
981 bool b_fs = va_arg( args, int );
982 emit askVideoSetFullScreen( b_fs );
986 msg_Warn( p_intf, "unsupported control query" );
991 /*****************************************************************************
992 * Playlist, Visualisation and Menus handling
993 *****************************************************************************/
995 * Toggle the playlist widget or dialog
997 void MainInterface::createPlaylist( bool b_show )
999 playlistWidget = new PlaylistWidget( p_intf, this );
1001 i_pl_dock = PL_BOTTOM;
1002 /* i_pl_dock = (pl_dock_e)getSettings()
1003 ->value( "pl-dock-status", PL_UNDOCKED ).toInt(); */
1005 if( i_pl_dock == PL_UNDOCKED )
1007 playlistWidget->setWindowFlags( Qt::Window );
1009 /* This will restore the geometry but will not work for position,
1010 because of parenting */
1011 QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
1012 playlistWidget, QSize( 600, 300 ) );
1017 msg_Warn( p_intf, "Here %i", stackCentralW->currentIndex() );
1019 stackCentralW->insertWidget( PLAYL_TAB, playlistWidget );
1021 msg_Warn( p_intf, "Here %i", stackCentralW->currentIndex() );
1027 playlistVisible = true;
1028 stackCentralW->show();
1032 void MainInterface::togglePlaylist()
1035 msg_Warn( p_intf, "Here toggling %i %i", stackCentralW->currentIndex(), stackCentralOldState );
1037 if( !playlistWidget )
1039 createPlaylist( true );
1042 msg_Warn( p_intf, "Here toggling %i %i", stackCentralW->currentIndex(), stackCentralOldState );
1045 if( i_pl_dock != PL_UNDOCKED )
1047 /* Playlist not visible */
1048 if( stackCentralW->currentIndex() != PLAYL_TAB )
1050 showTab( PLAYL_TAB );
1051 stackCentralW->show();
1055 restoreStackOldWidget();
1057 playlistVisible = ( stackCentralW->currentIndex() == PLAYL_TAB );
1058 //doComponentsUpdate(); //resize( sizeHint() );
1062 /* Function called from the menu to undock the playlist */
1063 void MainInterface::undockPlaylist()
1065 // dockPL->setFloating( true );
1069 void MainInterface::dockPlaylist( pl_dock_e i_pos )
1073 void MainInterface::toggleMinimalView( bool b_switch )
1075 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
1076 i_visualmode != QT_MINIMAL_MODE )
1077 { /* NORMAL MODE then */
1078 stackCentralW->show();
1079 if( !videoWidget || stackCentralW->currentIndex() != VIDEO_TAB )
1085 /* If video is visible, then toggle the status of bgWidget */
1086 //bgWasVisible = !bgWasVisible;
1087 if( stackCentralOldState == BACKG_TAB )
1088 stackCentralOldState = HIDDEN_TAB;
1090 stackCentralOldState = BACKG_TAB;
1094 i_bg_height = stackCentralW->height();
1096 menuBar()->setVisible( !b_switch );
1097 controls->setVisible( !b_switch );
1098 statusBar()->setVisible( !b_switch );
1099 inputC->setVisible( !b_switch );
1101 doComponentsUpdate();
1103 emit minimalViewToggled( b_switch );
1106 /* toggling advanced controls buttons */
1107 void MainInterface::toggleAdvanced()
1109 controls->toggleAdvanced();
1110 // if( fullscreenControls ) fullscreenControls->toggleAdvanced();
1113 /* Get the visibility status of the controls (hidden or not, advanced or not) */
1114 int MainInterface::getControlsVisibilityStatus()
1116 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
1117 + CONTROLS_ADVANCED * controls->b_advancedVisible );
1121 void MainInterface::visual()
1123 if( !VISIBLE( visualSelector) )
1125 visualSelector->show();
1126 if( !THEMIM->getIM()->hasVideo() )
1128 /* Show the background widget */
1130 visualSelectorEnabled = true;
1134 /* Stop any currently running visualization */
1135 visualSelector->hide();
1136 visualSelectorEnabled = false;
1138 doComponentsUpdate();
1142 /************************************************************************
1144 ************************************************************************/
1145 void MainInterface::setName( const QString& name )
1147 input_name = name; /* store it for the QSystray use */
1148 /* Display it in the status bar, but also as a Tooltip in case it doesn't
1150 nameLabel->setText( " " + name + " " );
1151 nameLabel->setToolTip( " " + name +" " );
1155 * Give the decorations of the Main Window a correct Name.
1156 * If nothing is given, set it to VLC...
1158 void MainInterface::setVLCWindowsTitle( const QString& aTitle )
1160 if( aTitle.isEmpty() )
1162 setWindowTitle( qtr( "VLC media player" ) );
1166 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
1170 void MainInterface::showCryptedLabel( bool b_show )
1172 if( cryptedLabel == NULL )
1174 cryptedLabel = new QLabel;
1175 // The lock icon is not the right one for DRM protection/scrambled.
1176 //cryptedLabel->setPixmap( QPixmap( ":/lock" ) );
1177 cryptedLabel->setText( "DRM" );
1178 statusBar()->addWidget( cryptedLabel );
1181 cryptedLabel->setVisible( b_show );
1184 void MainInterface::showBuffering( float f_cache )
1186 QString amount = QString("Buffering: %1%").arg( (int)(100*f_cache) );
1187 statusBar()->showMessage( amount, 1000 );
1190 /*****************************************************************************
1191 * Systray Icon and Systray Menu
1192 *****************************************************************************/
1195 * Create a SystemTray icon and a menu that would go with it.
1196 * Connects to a click handler on the icon.
1198 void MainInterface::createSystray()
1201 if( QDate::currentDate().dayOfYear() >= 354 )
1202 iconVLC = QIcon( ":/logo/vlc128-christmas.png" );
1204 iconVLC = QIcon( ":/logo/vlc128.png" );
1205 sysTray = new QSystemTrayIcon( iconVLC, this );
1206 sysTray->setToolTip( qtr( "VLC media player" ));
1208 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
1209 systrayMenu->setIcon( iconVLC );
1211 QVLCMenu::updateSystrayMenu( this, p_intf, true );
1214 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
1215 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
1219 * Updates the Systray Icon's menu and toggle the main interface
1221 void MainInterface::toggleUpdateSystrayMenu()
1223 /* If hidden, show it */
1229 else if( isMinimized() )
1237 /* Visible (possibly under other windows) */
1239 /* check if any visible window is above vlc in the z-order,
1240 * but ignore the ones always on top
1241 * and the ones which can't be activated */
1244 wi.cbSize = sizeof( WINDOWINFO );
1245 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
1246 hwnd && ( !IsWindowVisible( hwnd ) ||
1247 ( GetWindowInfo( hwnd, &wi ) &&
1248 (wi.dwExStyle&WS_EX_NOACTIVATE) ) );
1249 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
1250 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
1251 (wi.dwExStyle&WS_EX_TOPMOST) )
1263 QVLCMenu::updateSystrayMenu( this, p_intf );
1266 void MainInterface::handleSystrayClick(
1267 QSystemTrayIcon::ActivationReason reason )
1271 case QSystemTrayIcon::Trigger:
1272 case QSystemTrayIcon::DoubleClick:
1273 toggleUpdateSystrayMenu();
1275 case QSystemTrayIcon::MiddleClick:
1276 sysTray->showMessage( qtr( "VLC media player" ),
1277 qtr( "Control menu for the player" ),
1278 QSystemTrayIcon::Information, 3000 );
1286 * Updates the name of the systray Icon tooltip.
1287 * Doesn't check if the systray exists, check before you call it.
1289 void MainInterface::updateSystrayTooltipName( const QString& name )
1291 if( name.isEmpty() )
1293 sysTray->setToolTip( qtr( "VLC media player" ) );
1297 sysTray->setToolTip( name );
1298 if( notificationEnabled && ( isHidden() || isMinimized() ) )
1300 sysTray->showMessage( qtr( "VLC media player" ), name,
1301 QSystemTrayIcon::NoIcon, 3000 );
1305 QVLCMenu::updateSystrayMenu( this, p_intf );
1309 * Updates the status of the systray Icon tooltip.
1310 * Doesn't check if the systray exists, check before you call it.
1312 void MainInterface::updateSystrayTooltipStatus( int i_status )
1319 sysTray->setToolTip( qtr( "VLC media player" ) );
1324 sysTray->setToolTip( input_name );
1329 sysTray->setToolTip( input_name + " - "
1334 QVLCMenu::updateSystrayMenu( this, p_intf );
1338 /************************************************************************
1340 ************************************************************************/
1341 void MainInterface::dropEvent(QDropEvent *event)
1343 dropEventPlay( event, true );
1346 void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
1348 event->setDropAction( Qt::CopyAction );
1349 if( !event->possibleActions() & Qt::CopyAction )
1352 const QMimeData *mimeData = event->mimeData();
1354 /* D&D of a subtitles file, add it on the fly */
1355 if( mimeData->urls().size() == 1 && THEMIM->getIM()->hasInput() )
1357 if( !input_AddSubtitle( THEMIM->getInput(),
1358 qtu( toNativeSeparators( mimeData->urls()[0].toLocalFile() ) ),
1366 bool first = b_play;
1367 foreach( const QUrl &url, mimeData->urls() )
1369 QString s = toNativeSeparators( url.toLocalFile() );
1371 if( s.length() > 0 ) {
1372 char* psz_uri = make_URI( qtu(s) );
1373 playlist_Add( THEPL, psz_uri, NULL,
1374 PLAYLIST_APPEND | (first ? PLAYLIST_GO: PLAYLIST_PREPARSE),
1375 PLAYLIST_END, true, pl_Unlocked );
1378 RecentsMRL::getInstance( p_intf )->addRecent( s );
1383 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1385 event->acceptProposedAction();
1387 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1389 event->acceptProposedAction();
1391 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1396 /************************************************************************
1398 ************************************************************************/
1399 void MainInterface::customEvent( QEvent *event )
1402 if( event->type() == PLDockEvent_Type )
1404 PlaylistDialog::killInstance();
1405 playlistEmbeddedFlag = true;
1407 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1412 if ( event->type() == (int)SetVideoOnTopEvent_Type )
1414 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1415 if( p_event->OnTop() )
1416 setWindowFlags( windowFlags() | Qt::WindowStaysOnTopHint );
1418 setWindowFlags( windowFlags() & ~Qt::WindowStaysOnTopHint );
1419 show(); /* necessary to apply window flags */
1423 void MainInterface::keyPressEvent( QKeyEvent *e )
1425 handleKeyPress( e );
1428 void MainInterface::handleKeyPress( QKeyEvent *e )
1430 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() == Qt::Key_H )
1431 && !menuBar()->isVisible() )
1433 toggleMinimalView( false );
1437 int i_vlck = qtEventToVLCKey( e );
1440 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1447 void MainInterface::resizeEvent( QResizeEvent * event )
1452 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
1453 i_visualmode == QT_MINIMAL_MODE )
1455 mainVideoSize = size();
1459 if( VISIBLE( bgWidget) ||
1460 ( videoIsActive && videoWidget->isVisible() )
1462 mainVideoSize = size();
1464 mainBasedSize = size();
1468 QVLCMW::resizeEvent( event );
1469 msg_Dbg( p_intf, "Resize Event, height: %i", size().height() );
1472 void MainInterface::wheelEvent( QWheelEvent *e )
1474 int i_vlckey = qtWheelEventToVLCKey( e );
1475 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1479 void MainInterface::closeEvent( QCloseEvent *e )
1486 void MainInterface::toggleFullScreen( void )
1488 if( isFullScreen() )
1491 emit askUpdate(); // Needed if video was launched after the F11
1492 emit fullscreenInterfaceToggled( false );
1497 emit fullscreenInterfaceToggled( true );
1502 //moc doesn't know about #ifdef, so we have to build this method for every platform
1503 void MainInterface::changeThumbbarButtons( int i_status)
1506 // Define an array of three buttons. These buttons provide images through an
1507 // image list and also provide tooltips.
1508 DWORD dwMask = THB_BITMAP | THB_FLAGS;
1510 THUMBBUTTON thbButtons[3];
1512 thbButtons[0].dwMask = dwMask;
1513 thbButtons[0].iId = 0;
1514 thbButtons[0].iBitmap = 0;
1517 thbButtons[1].dwMask = dwMask;
1518 thbButtons[1].iId = 1;
1521 thbButtons[2].dwMask = dwMask;
1522 thbButtons[2].iId = 2;
1523 thbButtons[2].iBitmap = 3;
1529 thbButtons[0].dwFlags = THBF_ENABLED;
1530 thbButtons[1].dwFlags = THBF_ENABLED;
1531 thbButtons[2].dwFlags = THBF_ENABLED;
1532 thbButtons[1].iBitmap = 1;
1537 thbButtons[0].dwFlags = THBF_ENABLED;
1538 thbButtons[1].dwFlags = THBF_ENABLED;
1539 thbButtons[2].dwFlags = THBF_ENABLED;
1540 thbButtons[1].iBitmap = 2;
1546 HRESULT hr = p_taskbl->vt->ThumbBarUpdateButtons(p_taskbl, this->winId(), 3, thbButtons);
1548 msg_Err( p_intf, "ThumbBarUpdateButtons failed with error %08x", hr );
1554 /*****************************************************************************
1555 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1556 * We don't show the menu directly here because we don't want the
1557 * caller to block for a too long time.
1558 *****************************************************************************/
1559 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1560 vlc_value_t old_val, vlc_value_t new_val, void *param )
1562 intf_thread_t *p_intf = (intf_thread_t *)param;
1564 if( p_intf->pf_show_dialog )
1566 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1567 new_val.b_bool, NULL );
1573 /*****************************************************************************
1574 * IntfShowCB: callback triggered by the intf-show libvlc variable.
1575 *****************************************************************************/
1576 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1577 vlc_value_t old_val, vlc_value_t new_val, void *param )
1579 intf_thread_t *p_intf = (intf_thread_t *)param;
1580 p_intf->p_sys->p_mi->toggleFSC();