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
522 OSVERSIONINFO winVer;
523 winVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
524 if( GetVersionEx(&winVer) && winVer.dwMajorVersion > 5 )
526 if(himl = ImageList_Create( 15, //cx
529 4,//initial nb of images
530 0//nb of images that can be added
533 QPixmap img = QPixmap(":/toolbar/previous_b");
534 QPixmap img2 = QPixmap(":/toolbar/pause_b");
535 QPixmap img3 = QPixmap(":/toolbar/play_b");
536 QPixmap img4 = QPixmap(":/toolbar/next_b");
537 QBitmap mask = img.createMaskFromColor(Qt::transparent);
538 QBitmap mask2 = img2.createMaskFromColor(Qt::transparent);
539 QBitmap mask3 = img3.createMaskFromColor(Qt::transparent);
540 QBitmap mask4 = img4.createMaskFromColor(Qt::transparent);
542 if(-1 == ImageList_Add(himl, img.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask.toWinHBITMAP()))
543 msg_Err( p_intf, "ImageList_Add failed" );
544 if(-1 == ImageList_Add(himl, img2.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask2.toWinHBITMAP()))
545 msg_Err( p_intf, "ImageList_Add failed" );
546 if(-1 == ImageList_Add(himl, img3.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask3.toWinHBITMAP()))
547 msg_Err( p_intf, "ImageList_Add failed" );
548 if(-1 == ImageList_Add(himl, img4.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask4.toWinHBITMAP()))
549 msg_Err( p_intf, "ImageList_Add failed" );
554 if( S_OK == CoCreateInstance( &clsid_ITaskbarList,
555 NULL, CLSCTX_INPROC_SERVER,
557 (void **)&p_taskbl) )
559 p_taskbl->vt->HrInit(p_taskbl);
561 // Define an array of two buttons. These buttons provide images through an
562 // image list and also provide tooltips.
563 DWORD dwMask = THB_BITMAP | THB_FLAGS;
565 THUMBBUTTON thbButtons[3];
566 thbButtons[0].dwMask = dwMask;
567 thbButtons[0].iId = 0;
568 thbButtons[0].iBitmap = 0;
569 thbButtons[0].dwFlags = THBF_HIDDEN;
571 thbButtons[1].dwMask = dwMask;
572 thbButtons[1].iId = 1;
573 thbButtons[1].iBitmap = 2;
574 thbButtons[1].dwFlags = THBF_HIDDEN;
576 thbButtons[2].dwMask = dwMask;
577 thbButtons[2].iId = 2;
578 thbButtons[2].iBitmap = 3;
579 thbButtons[2].dwFlags = THBF_HIDDEN;
581 HRESULT hr = p_taskbl->vt->ThumbBarSetImageList(p_taskbl, winId(), himl );
583 msg_Err( p_intf, "ThumbBarSetImageList failed with error %08x", hr );
586 hr = p_taskbl->vt->ThumbBarAddButtons(p_taskbl, winId(), 3, thbButtons);
588 msg_Err( p_intf, "ThumbBarAddButtons failed with error %08x", hr );
590 CONNECT( THEMIM->getIM(), statusChanged( int ), this, changeThumbbarButtons( int ) );
600 bool MainInterface::winEvent ( MSG * msg, long * result )
602 if (msg->message == taskbar_wmsg)
604 //We received the taskbarbuttoncreated, now we can really create th buttons
605 createTaskBarButtons();
609 switch( msg->message )
612 if (HIWORD(msg->wParam) == THBN_CLICKED)
614 switch(LOWORD(msg->wParam))
620 THEMIM->togglePlayPause();
629 cmd = GET_APPCOMMAND_LPARAM(msg->lParam);
632 case APPCOMMAND_MEDIA_PLAY_PAUSE:
633 THEMIM->togglePlayPause();
635 case APPCOMMAND_MEDIA_PLAY:
638 case APPCOMMAND_MEDIA_PAUSE:
641 case APPCOMMAND_MEDIA_PREVIOUSTRACK:
644 case APPCOMMAND_MEDIA_NEXTTRACK:
647 case APPCOMMAND_MEDIA_STOP:
650 case APPCOMMAND_VOLUME_DOWN:
653 case APPCOMMAND_VOLUME_UP:
656 case APPCOMMAND_VOLUME_MUTE:
657 THEAM->toggleMuteAudio();
660 msg_Dbg( p_intf, "unknown APPCOMMAND = %d", cmd);
669 /**********************************************************************
670 * Handling of sizing of the components
671 **********************************************************************/
673 /* This function is probably wrong, but we don't have many many choices...
674 Since we can't know from the playlist Widget if we are inside a dock or not,
675 because the playlist Widget can be called by THEDP, as a separate windows for
677 Maybe the other solution is to redefine the sizeHint() of the playlist and
678 ask _parent->isFloating()...
679 If you think this would be better, please FIXME it...
682 QSize MainInterface::sizeHint() const
687 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
688 i_visualmode == QT_MINIMAL_MODE )
690 return mainVideoSize;
694 if( VISIBLE( bgWidget) ||
695 ( videoIsActive && videoWidget->isVisible() )
697 return mainVideoSize;
699 return mainBasedSize;
704 int nwidth = __MAX( controls->sizeHint().width(),
705 menuBar()->sizeHint().width() );
707 int nheight = controls->isVisible() ?
708 controls->size().height()
709 + inputC->size().height()
710 + menuBar()->size().height()
711 + statusBar()->size().height()
714 if( stackCentralW->isVisible() )
715 nheight += stackCentralW->height();
716 nwidth = __MAX( nwidth, stackCentralW->width() );
718 /* if( VISIBLE( bgWidget ) )
720 msg_Warn( p_intf, "Hello here" );
722 nheight += i_bg_height;
724 nheight += bgWidget->size().height();
725 nwidth = __MAX( nwidth, bgWidget->size().width() );
727 else if( videoIsActive && videoWidget->isVisible() )
729 msg_Warn( p_intf, "Hello there" );
730 nheight += videoWidget->sizeHint().height();
731 nwidth = __MAX( nwidth, videoWidget->sizeHint().width() );
734 if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget() )
736 nheight += dockPL->size().height();
737 nwidth = __MAX( nwidth, dockPL->size().width() );
738 msg_Warn( p_intf, "3 %i %i", nheight, nwidth );
741 return QSize( nwidth, nheight );
745 /* Video widget cannot do this synchronously as it runs in another thread */
746 /* Well, could it, actually ? Probably dangerous ... */
748 /* This function is called:
749 - toggling of minimal View
750 - through askUpdate() by Vout thread request video and resize video (zoom)
751 - Advanced buttons toggled
753 void MainInterface::doComponentsUpdate()
755 if( isFullScreen() || isMaximized() ) return;
757 // msg_Warn( p_intf, "Updating the geometry" );
758 /* Here we resize to sizeHint() and not adjustsize because we want
759 the videoWidget to be exactly the correctSize */
764 /* This is WRONG, but I believe there is a Qt bug here */
765 setMinimumSize( 0, 0 );
766 resize( sizeHint() );
768 //adjustSize() ; /* This is not needed, but might help in the future */
771 void MainInterface::debug()
774 msg_Dbg( p_intf, "Stack Size: %i - %i", stackCentralW->size().height(), size().width() );
775 if( videoEmbeddedFlag )
776 msg_Dbg( p_intf, "Stack Size: %i - %i",
777 stackCentralW->widget( VIDEO_TAB )->size().height(),
778 stackCentralW->widget( VIDEO_TAB )->size().width() );
780 msg_Dbg( p_intf, "no embedded video" );
782 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
783 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
784 //msg_Dbg( p_intf, "maximumsize: %i - %i", maximumSize().height(), maximumSize().width() );
786 msg_Dbg( p_intf, "Stack minimumsize: %i - %i", stackCentralW->minimumSize().height(), stackCentralW->minimumSize().width() );
787 msg_Dbg( p_intf, "Controls minimumsize: %i - %i", controls->minimumSize().height(), controls->minimumSize().width() );
788 msg_Dbg( p_intf, "Central minimumsize: %i - %i", centralWidget()->minimumSize().height(), centralWidget()->minimumSize().width() );
789 msg_Dbg( p_intf, "Menu minimumsize: %i - %i", menuBar()->minimumSize().height(), menuBar()->minimumSize().width() );
790 msg_Dbg( p_intf, "Input minimuSize: %i - %i", inputC->minimumSize().height(), inputC->minimumSize().width() );
791 msg_Dbg( p_intf, "Status minimumsize: %i - %i", statusBar()->minimumSize().height(), statusBar()->minimumSize().width() );
792 msg_Dbg( p_intf, "minimumsize: %i - %i", minimumSize().height(), minimumSize().width() );
794 /*if( videoWidget && videoWidget->isVisible() )
796 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
797 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
802 inline void MainInterface::showTab( int i_tab )
805 msg_Err( p_intf, "showTab %i", i_tab );
806 msg_Warn( p_intf, "Old stackCentralOldState %i", stackCentralOldState );
808 stackCentralOldState = stackCentralW->isVisible() ? stackCentralW->currentIndex()
811 msg_Warn( p_intf, "State change %i %i", stackCentralW->currentIndex(), i_tab );
814 if( i_visualmode == QT_NORMAL_MODE )
816 stackCentralW->setVisible( i_tab != HIDDEN_TAB );
817 doComponentsUpdate(); // resize the player
820 if( i_tab == HIDDEN_TAB ) i_tab == BACKG_TAB;
822 stackCentralW->setCurrentIndex( i_tab );
825 msg_Warn( p_intf, "New stackCentralOldState %i", stackCentralOldState );
829 inline void MainInterface::restoreStackOldWidget()
832 msg_Warn( p_intf, "Old stackCentralOldState %i", stackCentralOldState );
834 int temp = stackCentralW->isVisible() ? stackCentralW->currentIndex()
836 stackCentralW->setCurrentIndex( stackCentralOldState );
837 if( i_visualmode == QT_NORMAL_MODE )
839 stackCentralW->setVisible( stackCentralOldState != HIDDEN_TAB );
840 doComponentsUpdate(); // resize the player
843 stackCentralOldState = temp;
845 msg_Warn( p_intf, "Debug %i %i", temp, stackCentralW->currentIndex() );
849 void MainInterface::destroyPopupMenu()
851 QVLCMenu::PopupMenu( p_intf, false );
854 void MainInterface::toggleFSC()
856 if( !fullscreenControls ) return;
858 IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
859 QApplication::postEvent( fullscreenControls, eShow );
862 void MainInterface::popupMenu( const QPoint &p )
864 /* Ow, that's ugly: don't show the popup menu if cursor over
865 * the main menu bar or the status bar */
866 if( !childAt( p ) || ( ( childAt( p ) != menuBar() )
867 && ( childAt( p )->parentWidget() != statusBar() ) ) )
868 QVLCMenu::PopupMenu( p_intf, true );
871 /****************************************************************************
873 ****************************************************************************/
875 /* This event is used to deal with the fullscreen and always on top
876 issue conflict (bug in wx) */
877 class SetVideoOnTopQtEvent : public QEvent
880 SetVideoOnTopQtEvent( bool _onTop ) :
881 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
884 bool OnTop() const { return onTop; }
892 * You must note change the state of this object or other Qt4 UI objects,
893 * from the video output thread - only from the Qt4 UI main loop thread.
894 * All window provider queries must be handled through signals or events.
895 * That's why we have all those emit statements...
897 WId MainInterface::getVideo( int *pi_x, int *pi_y,
898 unsigned int *pi_width, unsigned int *pi_height )
903 /* This is a blocking call signal. Results are returned through pointers.
904 * Beware of deadlocks! */
906 emit askGetVideo( &id, pi_x, pi_y, pi_width, pi_height );
910 void MainInterface::getVideoSlot( WId *p_id, int *pi_x, int *pi_y,
911 unsigned *pi_width, unsigned *pi_height )
913 /* Request the videoWidget */
914 WId ret = videoWidget->request( pi_x, pi_y,
915 pi_width, pi_height, b_keep_size );
917 if( ret ) /* The videoWidget is available */
919 /* ask videoWidget to show */
920 videoWidget->SetSizing( *pi_width, *pi_height );
922 /* Consider the video active now */
925 stackCentralW->resize( *pi_width, *pi_height );
933 /* Asynchronous call from the WindowClose function */
934 void MainInterface::releaseVideo( void )
936 emit askReleaseVideo( );
939 /* Function that is CONNECTED to the previous emit */
940 void MainInterface::releaseVideoSlot( void )
942 videoWidget->release( );
944 restoreStackOldWidget();
946 /* Try to resize, except when you are in Fullscreen mode */
947 // doComponentsUpdate();
950 /* Asynchronous call from WindowControl function */
951 int MainInterface::controlVideo( int i_query, va_list args )
953 /* Debug to check if VOUT_WINDOW_SET_SIZE is called, because this is broken now */
954 msg_Warn( p_intf, "Control Video: %i", i_query );
957 case VOUT_WINDOW_SET_SIZE:
959 unsigned int i_width = va_arg( args, unsigned int );
960 unsigned int i_height = va_arg( args, unsigned int );
961 emit askVideoToResize( i_width, i_height );
965 case VOUT_WINDOW_SET_STATE:
967 unsigned i_arg = va_arg( args, unsigned );
968 unsigned on_top = i_arg & VOUT_WINDOW_STATE_ABOVE;
969 QApplication::postEvent( this, new SetVideoOnTopQtEvent( on_top ) );
972 case VOUT_WINDOW_SET_FULLSCREEN:
974 bool b_fs = va_arg( args, int );
975 emit askVideoSetFullScreen( b_fs );
979 msg_Warn( p_intf, "unsupported control query" );
984 /*****************************************************************************
985 * Playlist, Visualisation and Menus handling
986 *****************************************************************************/
988 * Toggle the playlist widget or dialog
990 void MainInterface::createPlaylist( bool b_show )
992 playlistWidget = new PlaylistWidget( p_intf, this );
994 i_pl_dock = PL_BOTTOM;
995 /* i_pl_dock = (pl_dock_e)getSettings()
996 ->value( "pl-dock-status", PL_UNDOCKED ).toInt(); */
998 if( i_pl_dock == PL_UNDOCKED )
1000 playlistWidget->setWindowFlags( Qt::Window );
1002 /* This will restore the geometry but will not work for position,
1003 because of parenting */
1004 QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
1005 playlistWidget, QSize( 600, 300 ) );
1010 msg_Warn( p_intf, "Here %i", stackCentralW->currentIndex() );
1012 stackCentralW->insertWidget( PLAYL_TAB, playlistWidget );
1014 msg_Warn( p_intf, "Here %i", stackCentralW->currentIndex() );
1020 playlistVisible = true;
1021 stackCentralW->show();
1025 void MainInterface::togglePlaylist()
1028 msg_Warn( p_intf, "Here toggling %i %i", stackCentralW->currentIndex(), stackCentralOldState );
1030 if( !playlistWidget )
1032 createPlaylist( true );
1035 msg_Warn( p_intf, "Here toggling %i %i", stackCentralW->currentIndex(), stackCentralOldState );
1038 if( i_pl_dock != PL_UNDOCKED )
1040 /* Playlist not visible */
1041 if( stackCentralW->currentIndex() != PLAYL_TAB )
1043 showTab( PLAYL_TAB );
1044 stackCentralW->show();
1048 restoreStackOldWidget();
1050 playlistVisible = ( stackCentralW->currentIndex() == PLAYL_TAB );
1051 //doComponentsUpdate(); //resize( sizeHint() );
1055 /* Function called from the menu to undock the playlist */
1056 void MainInterface::undockPlaylist()
1058 // dockPL->setFloating( true );
1062 void MainInterface::dockPlaylist( pl_dock_e i_pos )
1066 void MainInterface::toggleMinimalView( bool b_switch )
1068 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
1069 i_visualmode != QT_MINIMAL_MODE )
1070 { /* NORMAL MODE then */
1071 stackCentralW->show();
1072 if( !videoWidget || stackCentralW->currentIndex() != VIDEO_TAB )
1078 /* If video is visible, then toggle the status of bgWidget */
1079 //bgWasVisible = !bgWasVisible;
1080 if( stackCentralOldState == BACKG_TAB )
1081 stackCentralOldState = HIDDEN_TAB;
1083 stackCentralOldState = BACKG_TAB;
1087 i_bg_height = stackCentralW->height();
1089 menuBar()->setVisible( !b_switch );
1090 controls->setVisible( !b_switch );
1091 statusBar()->setVisible( !b_switch );
1092 inputC->setVisible( !b_switch );
1094 doComponentsUpdate();
1096 emit minimalViewToggled( b_switch );
1099 /* toggling advanced controls buttons */
1100 void MainInterface::toggleAdvanced()
1102 controls->toggleAdvanced();
1103 // if( fullscreenControls ) fullscreenControls->toggleAdvanced();
1106 /* Get the visibility status of the controls (hidden or not, advanced or not) */
1107 int MainInterface::getControlsVisibilityStatus()
1109 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
1110 + CONTROLS_ADVANCED * controls->b_advancedVisible );
1114 void MainInterface::visual()
1116 if( !VISIBLE( visualSelector) )
1118 visualSelector->show();
1119 if( !THEMIM->getIM()->hasVideo() )
1121 /* Show the background widget */
1123 visualSelectorEnabled = true;
1127 /* Stop any currently running visualization */
1128 visualSelector->hide();
1129 visualSelectorEnabled = false;
1131 doComponentsUpdate();
1135 /************************************************************************
1137 ************************************************************************/
1138 void MainInterface::setName( const QString& name )
1140 input_name = name; /* store it for the QSystray use */
1141 /* Display it in the status bar, but also as a Tooltip in case it doesn't
1143 nameLabel->setText( " " + name + " " );
1144 nameLabel->setToolTip( " " + name +" " );
1148 * Give the decorations of the Main Window a correct Name.
1149 * If nothing is given, set it to VLC...
1151 void MainInterface::setVLCWindowsTitle( const QString& aTitle )
1153 if( aTitle.isEmpty() )
1155 setWindowTitle( qtr( "VLC media player" ) );
1159 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
1163 void MainInterface::showCryptedLabel( bool b_show )
1165 if( cryptedLabel == NULL )
1167 cryptedLabel = new QLabel;
1168 // The lock icon is not the right one for DRM protection/scrambled.
1169 //cryptedLabel->setPixmap( QPixmap( ":/lock" ) );
1170 cryptedLabel->setText( "DRM" );
1171 statusBar()->addWidget( cryptedLabel );
1174 cryptedLabel->setVisible( b_show );
1177 /*****************************************************************************
1178 * Systray Icon and Systray Menu
1179 *****************************************************************************/
1182 * Create a SystemTray icon and a menu that would go with it.
1183 * Connects to a click handler on the icon.
1185 void MainInterface::createSystray()
1188 if( QDate::currentDate().dayOfYear() >= 354 )
1189 iconVLC = QIcon( ":/logo/vlc128-christmas.png" );
1191 iconVLC = QIcon( ":/logo/vlc128.png" );
1192 sysTray = new QSystemTrayIcon( iconVLC, this );
1193 sysTray->setToolTip( qtr( "VLC media player" ));
1195 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
1196 systrayMenu->setIcon( iconVLC );
1198 QVLCMenu::updateSystrayMenu( this, p_intf, true );
1201 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
1202 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
1206 * Updates the Systray Icon's menu and toggle the main interface
1208 void MainInterface::toggleUpdateSystrayMenu()
1210 /* If hidden, show it */
1216 else if( isMinimized() )
1224 /* Visible (possibly under other windows) */
1226 /* check if any visible window is above vlc in the z-order,
1227 * but ignore the ones always on top
1228 * and the ones which can't be activated */
1231 wi.cbSize = sizeof( WINDOWINFO );
1232 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
1233 hwnd && ( !IsWindowVisible( hwnd ) ||
1234 ( GetWindowInfo( hwnd, &wi ) &&
1235 (wi.dwExStyle&WS_EX_NOACTIVATE) ) );
1236 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
1237 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
1238 (wi.dwExStyle&WS_EX_TOPMOST) )
1250 QVLCMenu::updateSystrayMenu( this, p_intf );
1253 void MainInterface::handleSystrayClick(
1254 QSystemTrayIcon::ActivationReason reason )
1258 case QSystemTrayIcon::Trigger:
1259 case QSystemTrayIcon::DoubleClick:
1260 toggleUpdateSystrayMenu();
1262 case QSystemTrayIcon::MiddleClick:
1263 sysTray->showMessage( qtr( "VLC media player" ),
1264 qtr( "Control menu for the player" ),
1265 QSystemTrayIcon::Information, 3000 );
1273 * Updates the name of the systray Icon tooltip.
1274 * Doesn't check if the systray exists, check before you call it.
1276 void MainInterface::updateSystrayTooltipName( const QString& name )
1278 if( name.isEmpty() )
1280 sysTray->setToolTip( qtr( "VLC media player" ) );
1284 sysTray->setToolTip( name );
1285 if( notificationEnabled && ( isHidden() || isMinimized() ) )
1287 sysTray->showMessage( qtr( "VLC media player" ), name,
1288 QSystemTrayIcon::NoIcon, 3000 );
1292 QVLCMenu::updateSystrayMenu( this, p_intf );
1296 * Updates the status of the systray Icon tooltip.
1297 * Doesn't check if the systray exists, check before you call it.
1299 void MainInterface::updateSystrayTooltipStatus( int i_status )
1306 sysTray->setToolTip( qtr( "VLC media player" ) );
1311 sysTray->setToolTip( input_name );
1316 sysTray->setToolTip( input_name + " - "
1321 QVLCMenu::updateSystrayMenu( this, p_intf );
1325 /************************************************************************
1327 ************************************************************************/
1328 void MainInterface::dropEvent(QDropEvent *event)
1330 dropEventPlay( event, true );
1333 void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
1335 event->setDropAction( Qt::CopyAction );
1336 if( !event->possibleActions() & Qt::CopyAction )
1339 const QMimeData *mimeData = event->mimeData();
1341 /* D&D of a subtitles file, add it on the fly */
1342 if( mimeData->urls().size() == 1 && THEMIM->getIM()->hasInput() )
1344 if( !input_AddSubtitle( THEMIM->getInput(),
1345 qtu( toNativeSeparators( mimeData->urls()[0].toLocalFile() ) ),
1353 bool first = b_play;
1354 foreach( const QUrl &url, mimeData->urls() )
1356 QString s = toNativeSeparators( url.toLocalFile() );
1358 if( s.length() > 0 ) {
1359 char* psz_uri = make_URI( qtu(s) );
1360 playlist_Add( THEPL, psz_uri, NULL,
1361 PLAYLIST_APPEND | (first ? PLAYLIST_GO: PLAYLIST_PREPARSE),
1362 PLAYLIST_END, true, pl_Unlocked );
1365 RecentsMRL::getInstance( p_intf )->addRecent( s );
1370 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1372 event->acceptProposedAction();
1374 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1376 event->acceptProposedAction();
1378 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1383 /************************************************************************
1385 ************************************************************************/
1386 void MainInterface::customEvent( QEvent *event )
1389 if( event->type() == PLDockEvent_Type )
1391 PlaylistDialog::killInstance();
1392 playlistEmbeddedFlag = true;
1394 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1399 if ( event->type() == (int)SetVideoOnTopEvent_Type )
1401 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1402 if( p_event->OnTop() )
1403 setWindowFlags( windowFlags() | Qt::WindowStaysOnTopHint );
1405 setWindowFlags( windowFlags() & ~Qt::WindowStaysOnTopHint );
1406 show(); /* necessary to apply window flags */
1410 void MainInterface::keyPressEvent( QKeyEvent *e )
1412 handleKeyPress( e );
1415 void MainInterface::handleKeyPress( QKeyEvent *e )
1417 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() == Qt::Key_H )
1418 && !menuBar()->isVisible() )
1420 toggleMinimalView( false );
1424 int i_vlck = qtEventToVLCKey( e );
1427 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1434 void MainInterface::resizeEvent( QResizeEvent * event )
1439 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
1440 i_visualmode == QT_MINIMAL_MODE )
1442 mainVideoSize = size();
1446 if( VISIBLE( bgWidget) ||
1447 ( videoIsActive && videoWidget->isVisible() )
1449 mainVideoSize = size();
1451 mainBasedSize = size();
1455 QVLCMW::resizeEvent( event );
1456 msg_Dbg( p_intf, "Resize Event, height: %i", size().height() );
1459 void MainInterface::wheelEvent( QWheelEvent *e )
1461 int i_vlckey = qtWheelEventToVLCKey( e );
1462 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1466 void MainInterface::closeEvent( QCloseEvent *e )
1473 void MainInterface::toggleFullScreen( void )
1475 if( isFullScreen() )
1478 emit askUpdate(); // Needed if video was launched after the F11
1479 emit fullscreenInterfaceToggled( false );
1484 emit fullscreenInterfaceToggled( true );
1489 //moc doesn't know about #ifdef, so we have to build this method for every platform
1490 void MainInterface::changeThumbbarButtons( int i_status)
1493 // Define an array of three buttons. These buttons provide images through an
1494 // image list and also provide tooltips.
1495 DWORD dwMask = THB_BITMAP | THB_FLAGS;
1497 THUMBBUTTON thbButtons[3];
1499 thbButtons[0].dwMask = dwMask;
1500 thbButtons[0].iId = 0;
1501 thbButtons[0].iBitmap = 0;
1504 thbButtons[1].dwMask = dwMask;
1505 thbButtons[1].iId = 1;
1508 thbButtons[2].dwMask = dwMask;
1509 thbButtons[2].iId = 2;
1510 thbButtons[2].iBitmap = 3;
1516 thbButtons[0].dwFlags = THBF_ENABLED;
1517 thbButtons[1].dwFlags = THBF_ENABLED;
1518 thbButtons[2].dwFlags = THBF_ENABLED;
1519 thbButtons[1].iBitmap = 1;
1524 thbButtons[0].dwFlags = THBF_ENABLED;
1525 thbButtons[1].dwFlags = THBF_ENABLED;
1526 thbButtons[2].dwFlags = THBF_ENABLED;
1527 thbButtons[1].iBitmap = 2;
1533 HRESULT hr = p_taskbl->vt->ThumbBarUpdateButtons(p_taskbl, this->winId(), 3, thbButtons);
1535 msg_Err( p_intf, "ThumbBarUpdateButtons failed with error %08x", hr );
1541 /*****************************************************************************
1542 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1543 * We don't show the menu directly here because we don't want the
1544 * caller to block for a too long time.
1545 *****************************************************************************/
1546 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1547 vlc_value_t old_val, vlc_value_t new_val, void *param )
1549 intf_thread_t *p_intf = (intf_thread_t *)param;
1551 if( p_intf->pf_show_dialog )
1553 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1554 new_val.b_bool, NULL );
1560 /*****************************************************************************
1561 * IntfShowCB: callback triggered by the intf-show libvlc variable.
1562 *****************************************************************************/
1563 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1564 vlc_value_t old_val, vlc_value_t new_val, void *param )
1566 intf_thread_t *p_intf = (intf_thread_t *)param;
1567 p_intf->p_sys->p_mi->toggleFSC();