1 /*****************************************************************************
2 * main_interface.cpp : Main interface
3 ****************************************************************************
4 * Copyright (C) 2006-2009 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Jean-Baptiste Kempf <jb@videolan.org>
9 * Ilkka Ollakka <ileoo@videolan.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
32 #include "main_interface.hpp"
33 #include "input_manager.hpp"
34 #include "actions_manager.hpp"
36 #include "util/customwidgets.hpp"
37 #include "util/qt_dirs.hpp"
39 #include "components/interface_widgets.hpp"
40 #include "components/controller.hpp"
41 #include "components/playlist/playlist.hpp"
42 #include "dialogs/external.hpp"
43 #include "dialogs/firstrun.hpp"
46 #include "recents.hpp"
48 #include <QCloseEvent>
60 #include <QPushButton>
61 #include <QStackedWidget>
64 #include <vlc_windows_interfaces.h>
70 #include <vlc_keys.h> /* Wheel event */
71 #include <vlc_vout_window.h>
72 #include <vlc_vout_display.h>
75 /* Callback prototypes */
76 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
77 vlc_value_t old_val, vlc_value_t new_val, void *param );
78 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
79 vlc_value_t old_val, vlc_value_t new_val, void *param );
81 MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
83 /* Variables initialisation */
84 // need_components_update = false;
87 playlistWidget = NULL;
91 fullscreenControls = NULL;
96 b_hideAfterCreation = false;
97 playlistVisible = false; // FIXME remove
102 /* Ask for Privacy */
103 FirstRun::CheckAndRun( this, p_intf );
106 * Configuration and settings
107 * Pre-building of interface
110 setFocusPolicy( Qt::StrongFocus );
111 setAcceptDrops( true );
112 setWindowRole( "vlc-main" );
113 setWindowIcon( QApplication::windowIcon() );
114 setWindowOpacity( var_InheritFloat( p_intf, "qt-opacity" ) );
116 /* Set The Video In emebedded Mode or not */
117 videoEmbeddedFlag = var_InheritBool( p_intf, "embedded-video" );
119 /* Does the interface resize to video size or the opposite */
120 b_keep_size = !var_InheritBool( p_intf, "qt-video-autoresize" );
122 /* Are we in the enhanced always-video mode or not ? */
123 i_visualmode = var_InheritInteger( p_intf, "qt-display-mode" );
125 /* Do we want anoying popups or not */
126 notificationEnabled = (bool)var_InheritBool( p_intf, "qt-notification" );
128 /* Set the other interface settings */
129 settings = getSettings();
130 settings->beginGroup( "MainWindow" );
133 * Retrieve saved sizes for main window
134 * mainBasedSize = based window size for normal mode
135 * (no video, no background)
136 * mainVideoSize = window size with video (all modes)
138 mainBasedSize = settings->value( "mainBasedSize", QSize( 350, 120 ) ).toSize();
139 mainVideoSize = settings->value( "mainVideoSize", QSize( 400, 300 ) ).toSize();
147 /**************************
148 * UI and Widgets design
149 **************************/
150 setVLCWindowsTitle();
151 createMainWidget( settings );
156 QVLCMenu::createMenuBar( this, p_intf );
157 CONNECT( THEMIM->getIM(), voutListChanged( vout_thread_t **, int ),
158 this, destroyPopupMenu() );
160 /*********************************
161 * Create the Systray Management *
162 *********************************/
165 /********************
167 ********************/
168 MainInputManager::getInstance( p_intf );
171 taskbar_wmsg = RegisterWindowMessage("TaskbarButtonCreated");
174 /************************************************************
175 * Connect the input manager to the GUI elements it manages *
176 ************************************************************/
178 * Connects on nameChanged()
179 * Those connects are different because options can impeach them to trigger.
181 /* Main Interface statusbar */
182 CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
183 this, setName( const QString& ) );
188 CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
189 this, updateSystrayTooltipName( const QString& ) );
192 /* and title of the Main Interface*/
193 if( var_InheritBool( p_intf, "qt-name-in-title" ) )
195 CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
196 this, setVLCWindowsTitle( const QString& ) );
200 * CONNECTS on PLAY_STATUS
202 /* Status on the systray */
206 CONNECT( THEMIM->getIM(), statusChanged( int ),
207 this, updateSystrayTooltipStatus( int ) );
211 /* END CONNECTS ON IM */
216 var_AddCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
218 /* Register callback for the intf-popupmenu variable */
219 var_AddCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
222 /* VideoWidget connects for asynchronous calls */
223 connect( this, SIGNAL(askGetVideo(WId*,int*,int*,unsigned*,unsigned *)),
224 this, SLOT(getVideoSlot(WId*,int*,int*,unsigned*,unsigned*)),
225 Qt::BlockingQueuedConnection );
226 connect( this, SIGNAL(askReleaseVideo( void )),
227 this, SLOT(releaseVideoSlot( void )),
228 Qt::BlockingQueuedConnection );
232 CONNECT( this, askVideoToResize( unsigned int, unsigned int ),
233 videoWidget, SetSizing( unsigned int, unsigned int ) );
234 CONNECT( this, askVideoSetFullScreen( bool ),
235 videoWidget, SetFullScreen( bool ) );
236 CONNECT( videoWidget, keyPressed( QKeyEvent * ),
237 this, handleKeyPress( QKeyEvent * ) );
240 CONNECT( this, askUpdate(), this, doComponentsUpdate() );
241 CONNECT( THEDP, toolBarConfUpdated(), this, recreateToolbars() );
243 /* Enable the popup menu in the MI */
244 setContextMenuPolicy( Qt::CustomContextMenu );
245 CONNECT( this, customContextMenuRequested( const QPoint& ),
246 this, popupMenu( const QPoint& ) );
248 /** END of CONNECTS**/
251 /**** FINAL SIZING and placement of interface */
252 settings->beginGroup( "MainWindow" );
253 QVLCTools::restoreWidgetPosition( settings, this, QSize(380, 60) );
255 /* resize to previously saved main window size if appicable */
258 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
259 i_visualmode == QT_MINIMAL_MODE )
261 resize( mainVideoSize );
265 resize( mainBasedSize );
269 msg_Dbg( p_intf, "%i", stackCentralOldState );
271 if( settings->value( "playlist-visible", 0 ).toInt() )
273 settings->endGroup();
275 /* Final sizing and showing */
276 setVisible( !b_hideAfterCreation );
277 //setMinimumSize( QSize( 0, 0 ) );
278 // setMinimumWidth( __MAX( controls->sizeHint().width(),
279 // menuBar()->sizeHint().width() ) );
282 /* And switch to minimal view if needed
283 Must be called after the show() */
284 if( i_visualmode == QT_MINIMAL_MODE )
285 toggleMinimalView( true );
287 /* Update the geometry : It is useful if you switch between
290 resize( sizeHint() );
293 MainInterface::~MainInterface()
295 msg_Dbg( p_intf, "Destroying the main interface" );
297 /* Unsure we hide the videoWidget before destroying it */
298 if( stackCentralOldState == VIDEO_TAB )
301 /* Save playlist state */
305 QVLCTools::saveWidgetPosition( p_intf, "Playlist", playlistWidget );
307 delete playlistWidget;
312 ImageList_Destroy( himl );
314 p_taskbl->vt->Release(p_taskbl);
318 /* Be sure to kill the actionsManager... FIXME */
319 ActionsManager::killInstance();
321 /* Delete the FSC controller */
322 delete fullscreenControls;
325 settings->beginGroup( "MainWindow" );
326 settings->setValue( "pl-dock-status", (int)i_pl_dock );
327 settings->setValue( "playlist-visible", (int)playlistVisible );
328 settings->setValue( "adv-controls",
329 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
331 settings->setValue( "mainBasedSize", mainBasedSize );
332 settings->setValue( "mainVideoSize", mainVideoSize );
335 settings->setValue( "backgroundSize", bgWidget->size() );
338 QVLCTools::saveWidgetPosition(settings, this);
339 settings->endGroup();
341 /* Unregister callbacks */
342 var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
343 var_DelCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
345 p_intf->p_sys->p_mi = NULL;
348 /*****************************
350 *****************************/
351 void MainInterface::recreateToolbars()
353 //msg_Dbg( p_intf, "Recreating the toolbars" );
354 settings->beginGroup( "MainWindow" );
358 controls = new ControlsWidget( p_intf, false, this ); /* FIXME */
359 CONNECT( controls, advancedControlsToggled( bool ),
360 this, doComponentsUpdate() );
361 CONNECT( controls, sizeChanged(),
362 this, doComponentsUpdate() );
364 inputC = new InputControlsWidget( p_intf, this );
366 mainLayout->insertWidget( 2, inputC );
367 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
369 settings->endGroup();
372 void MainInterface::createMainWidget( QSettings *settings )
374 /* Create the main Widget and the mainLayout */
375 QWidget *main = new QWidget;
376 setCentralWidget( main );
377 mainLayout = new QVBoxLayout( main );
379 /* Margins, spacing */
380 main->setContentsMargins( 0, 0, 0, 0 );
381 mainLayout->setSpacing( 0 ); mainLayout->setMargin( 0 );
384 stackCentralW = new QStackedWidget( main );
387 bgWidget = new BackgroundWidget( p_intf );
389 settings->value( "backgroundSize", QSize( 300, 200 ) ).toSize() );
390 bgWidget->updateGeometry();
391 stackCentralW->insertWidget( BACKG_TAB, bgWidget );
394 /* And video Outputs */
395 if( videoEmbeddedFlag )
397 videoWidget = new VideoWidget( p_intf );
398 stackCentralW->insertWidget( VIDEO_TAB, videoWidget );
400 mainLayout->insertWidget( 1, stackCentralW, 100 );
403 /* Create the CONTROLS Widget */
404 controls = new ControlsWidget( p_intf,
405 settings->value( "adv-controls", false ).toBool(), this );
406 CONNECT( controls, advancedControlsToggled( bool ),
407 this, doComponentsUpdate() );
408 CONNECT( controls, sizeChanged(),
409 this, doComponentsUpdate() );
410 inputC = new InputControlsWidget( p_intf, this );
412 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
413 i_visualmode != QT_MINIMAL_MODE )
416 stackCentralOldState = HIDDEN_TAB;
420 showTab( BACKG_TAB );
421 stackCentralOldState = BACKG_TAB;
425 //mainLayout->setRowStretch( 1, 10 );
426 mainLayout->insertWidget( 2, inputC );
427 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
431 /* Disabled for now, they SUCK */
433 visualSelector = new VisualSelector( p_intf );
434 mainLayout->insertWidget( 0, visualSelector );
435 visualSelector->hide();
438 /* Finish the sizing */
439 main->updateGeometry();
441 getSettings()->endGroup();
445 /* Create the FULLSCREEN CONTROLS Widget */
446 if( var_InheritBool( p_intf, "qt-fs-controller" ) )
448 fullscreenControls = new FullscreenControllerWidget( p_intf, this );
449 CONNECT( fullscreenControls, keyPressed( QKeyEvent * ),
450 this, handleKeyPress( QKeyEvent * ) );
454 inline void MainInterface::initSystray()
457 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
458 bool b_systrayWanted = var_InheritBool( p_intf, "qt-system-tray" );
460 if( var_InheritBool( p_intf, "qt-start-minimized") )
462 if( b_systrayAvailable )
464 b_systrayWanted = true;
465 b_hideAfterCreation = true;
468 msg_Err( p_intf, "cannot start minimized without system tray bar" );
471 if( b_systrayAvailable && b_systrayWanted )
476 inline void MainInterface::createStatusBar()
481 /* Widgets Creation*/
482 QStatusBar *statusBarr = statusBar();
484 TimeLabel *timeLabel = new TimeLabel( p_intf );
485 nameLabel = new QLabel( this );
486 nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
487 | Qt::TextSelectableByKeyboard );
488 SpeedLabel *speedLabel = new SpeedLabel( p_intf, "1.00x", this );
490 /* Styling those labels */
491 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
492 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
493 nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
495 /* and adding those */
496 statusBarr->addWidget( nameLabel, 8 );
497 statusBarr->addPermanentWidget( speedLabel, 0 );
498 statusBarr->addPermanentWidget( timeLabel, 0 );
500 /* timeLabel behaviour:
501 - double clicking opens the goto time dialog
502 - right-clicking and clicking just toggle between remaining and
504 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
506 CONNECT( THEMIM->getIM(), encryptionChanged( bool ),
507 this, showCryptedLabel( bool ) );
511 void MainInterface::createTaskBarButtons()
513 taskbar_wmsg = WM_NULL;
514 /*Here is the code for the taskbar thumb buttons
515 FIXME:We need pretty buttons in 16x16 px that are handled correctly by masks in Qt
516 FIXME:the play button's picture doesn't changed to pause when clicked
518 OSVERSIONINFO winVer;
519 winVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
520 if( GetVersionEx(&winVer) && winVer.dwMajorVersion > 5 )
522 if(himl = ImageList_Create( 15, //cx
525 4,//initial nb of images
526 0//nb of images that can be added
529 QPixmap img = QPixmap(":/toolbar/previous_b");
530 QPixmap img2 = QPixmap(":/toolbar/pause_b");
531 QPixmap img3 = QPixmap(":/toolbar/play_b");
532 QPixmap img4 = QPixmap(":/toolbar/next_b");
533 QBitmap mask = img.createMaskFromColor(Qt::transparent);
534 QBitmap mask2 = img2.createMaskFromColor(Qt::transparent);
535 QBitmap mask3 = img3.createMaskFromColor(Qt::transparent);
536 QBitmap mask4 = img4.createMaskFromColor(Qt::transparent);
538 if(-1 == ImageList_Add(himl, img.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask.toWinHBITMAP()))
539 msg_Err( p_intf, "ImageList_Add failed" );
540 if(-1 == ImageList_Add(himl, img2.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask2.toWinHBITMAP()))
541 msg_Err( p_intf, "ImageList_Add failed" );
542 if(-1 == ImageList_Add(himl, img3.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask3.toWinHBITMAP()))
543 msg_Err( p_intf, "ImageList_Add failed" );
544 if(-1 == ImageList_Add(himl, img4.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask4.toWinHBITMAP()))
545 msg_Err( p_intf, "ImageList_Add failed" );
550 if( S_OK == CoCreateInstance( &clsid_ITaskbarList,
551 NULL, CLSCTX_INPROC_SERVER,
553 (void **)&p_taskbl) )
555 p_taskbl->vt->HrInit(p_taskbl);
557 // Define an array of two buttons. These buttons provide images through an
558 // image list and also provide tooltips.
559 DWORD dwMask = THB_BITMAP | THB_FLAGS;
561 THUMBBUTTON thbButtons[3];
562 thbButtons[0].dwMask = dwMask;
563 thbButtons[0].iId = 0;
564 thbButtons[0].iBitmap = 0;
565 thbButtons[0].dwFlags = THBF_HIDDEN;
567 thbButtons[1].dwMask = dwMask;
568 thbButtons[1].iId = 1;
569 thbButtons[1].iBitmap = 2;
570 thbButtons[1].dwFlags = THBF_HIDDEN;
572 thbButtons[2].dwMask = dwMask;
573 thbButtons[2].iId = 2;
574 thbButtons[2].iBitmap = 3;
575 thbButtons[2].dwFlags = THBF_HIDDEN;
577 HRESULT hr = p_taskbl->vt->ThumbBarSetImageList(p_taskbl, winId(), himl );
579 msg_Err( p_intf, "ThumbBarSetImageList failed with error %08x", hr );
582 hr = p_taskbl->vt->ThumbBarAddButtons(p_taskbl, winId(), 3, thbButtons);
584 msg_Err( p_intf, "ThumbBarAddButtons failed with error %08x", hr );
586 CONNECT( THEMIM->getIM(), statusChanged( int ), this, changeThumbbarButtons( int ) );
596 bool MainInterface::winEvent ( MSG * msg, long * result )
598 if (msg->message == taskbar_wmsg)
600 //We received the taskbarbuttoncreated, now we can really create th buttons
601 createTaskBarButtons();
605 switch( msg->message )
608 if (HIWORD(msg->wParam) == THBN_CLICKED)
610 switch(LOWORD(msg->wParam))
616 THEMIM->togglePlayPause();
625 cmd = GET_APPCOMMAND_LPARAM(msg->lParam);
628 case APPCOMMAND_MEDIA_PLAY_PAUSE:
629 THEMIM->togglePlayPause();
631 case APPCOMMAND_MEDIA_PLAY:
634 case APPCOMMAND_MEDIA_PAUSE:
637 case APPCOMMAND_MEDIA_PREVIOUSTRACK:
640 case APPCOMMAND_MEDIA_NEXTTRACK:
643 case APPCOMMAND_MEDIA_STOP:
646 case APPCOMMAND_VOLUME_DOWN:
649 case APPCOMMAND_VOLUME_UP:
652 case APPCOMMAND_VOLUME_MUTE:
653 THEAM->toggleMuteAudio();
656 msg_Dbg( p_intf, "unknown APPCOMMAND = %d", cmd);
665 /**********************************************************************
666 * Handling of sizing of the components
667 **********************************************************************/
669 /* This function is probably wrong, but we don't have many many choices...
670 Since we can't know from the playlist Widget if we are inside a dock or not,
671 because the playlist Widget can be called by THEDP, as a separate windows for
673 Maybe the other solution is to redefine the sizeHint() of the playlist and
674 ask _parent->isFloating()...
675 If you think this would be better, please FIXME it...
678 QSize MainInterface::sizeHint() const
683 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
684 i_visualmode == QT_MINIMAL_MODE )
686 return mainVideoSize;
690 if( VISIBLE( bgWidget) ||
691 ( videoIsActive && videoWidget->isVisible() )
693 return mainVideoSize;
695 return mainBasedSize;
700 int nwidth = __MAX( controls->sizeHint().width(),
701 menuBar()->sizeHint().width() );
703 int nheight = controls->isVisible() ?
704 controls->size().height()
705 + inputC->size().height()
706 + menuBar()->size().height()
707 + statusBar()->size().height()
710 if( stackCentralW->isVisible() )
711 nheight += stackCentralW->height();
712 nwidth = __MAX( nwidth, stackCentralW->width() );
714 /* if( VISIBLE( bgWidget ) )
716 msg_Warn( p_intf, "Hello here" );
718 nheight += i_bg_height;
720 nheight += bgWidget->size().height();
721 nwidth = __MAX( nwidth, bgWidget->size().width() );
723 else if( videoIsActive && videoWidget->isVisible() )
725 msg_Warn( p_intf, "Hello there" );
726 nheight += videoWidget->sizeHint().height();
727 nwidth = __MAX( nwidth, videoWidget->sizeHint().width() );
730 if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget() )
732 nheight += dockPL->size().height();
733 nwidth = __MAX( nwidth, dockPL->size().width() );
734 msg_Warn( p_intf, "3 %i %i", nheight, nwidth );
737 return QSize( nwidth, nheight );
741 /* Video widget cannot do this synchronously as it runs in another thread */
742 /* Well, could it, actually ? Probably dangerous ... */
744 /* This function is called:
745 - toggling of minimal View
746 - through askUpdate() by Vout thread request video and resize video (zoom)
747 - Advanced buttons toggled
749 void MainInterface::doComponentsUpdate()
751 if( isFullScreen() || isMaximized() ) return;
753 // msg_Warn( p_intf, "Updating the geometry" );
754 /* Here we resize to sizeHint() and not adjustsize because we want
755 the videoWidget to be exactly the correctSize */
760 /* This is WRONG, but I believe there is a Qt bug here */
761 setMinimumSize( 0, 0 );
762 resize( sizeHint() );
764 //adjustSize() ; /* This is not needed, but might help in the future */
767 void MainInterface::debug()
770 msg_Dbg( p_intf, "Stack Size: %i - %i", stackCentralW->size().height(), size().width() );
771 if( videoEmbeddedFlag )
772 msg_Dbg( p_intf, "Stack Size: %i - %i",
773 stackCentralW->widget( VIDEO_TAB )->size().height(),
774 stackCentralW->widget( VIDEO_TAB )->size().width() );
776 msg_Dbg( p_intf, "no embedded video" );
778 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
779 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
780 //msg_Dbg( p_intf, "maximumsize: %i - %i", maximumSize().height(), maximumSize().width() );
782 msg_Dbg( p_intf, "Stack minimumsize: %i - %i", stackCentralW->minimumSize().height(), stackCentralW->minimumSize().width() );
783 msg_Dbg( p_intf, "Controls minimumsize: %i - %i", controls->minimumSize().height(), controls->minimumSize().width() );
784 msg_Dbg( p_intf, "Central minimumsize: %i - %i", centralWidget()->minimumSize().height(), centralWidget()->minimumSize().width() );
785 msg_Dbg( p_intf, "Menu minimumsize: %i - %i", menuBar()->minimumSize().height(), menuBar()->minimumSize().width() );
786 msg_Dbg( p_intf, "Input minimuSize: %i - %i", inputC->minimumSize().height(), inputC->minimumSize().width() );
787 msg_Dbg( p_intf, "Status minimumsize: %i - %i", statusBar()->minimumSize().height(), statusBar()->minimumSize().width() );
788 msg_Dbg( p_intf, "minimumsize: %i - %i", minimumSize().height(), minimumSize().width() );
790 /*if( videoWidget && videoWidget->isVisible() )
792 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
793 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
798 inline void MainInterface::showTab( int i_tab )
801 msg_Err( p_intf, "showTab %i", i_tab );
802 msg_Warn( p_intf, "Old stackCentralOldState %i", stackCentralOldState );
804 stackCentralOldState = stackCentralW->isVisible() ? stackCentralW->currentIndex()
807 msg_Warn( p_intf, "State change %i %i", stackCentralW->currentIndex(), i_tab );
810 if( i_visualmode == QT_NORMAL_MODE )
812 stackCentralW->setVisible( i_tab != HIDDEN_TAB );
813 doComponentsUpdate(); // resize the player
816 if( i_tab == HIDDEN_TAB ) i_tab == BACKG_TAB;
818 stackCentralW->setCurrentIndex( i_tab );
821 msg_Warn( p_intf, "New stackCentralOldState %i", stackCentralOldState );
825 inline void MainInterface::restoreStackOldWidget()
828 msg_Warn( p_intf, "Old stackCentralOldState %i", stackCentralOldState );
830 int temp = stackCentralW->isVisible() ? stackCentralW->currentIndex()
832 stackCentralW->setCurrentIndex( stackCentralOldState );
833 if( i_visualmode == QT_NORMAL_MODE )
835 stackCentralW->setVisible( stackCentralOldState != HIDDEN_TAB );
836 doComponentsUpdate(); // resize the player
839 stackCentralOldState = temp;
841 msg_Warn( p_intf, "Debug %i %i", temp, stackCentralW->currentIndex() );
845 void MainInterface::destroyPopupMenu()
847 QVLCMenu::PopupMenu( p_intf, false );
850 void MainInterface::toggleFSC()
852 if( !fullscreenControls ) return;
854 IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
855 QApplication::postEvent( fullscreenControls, eShow );
858 void MainInterface::popupMenu( const QPoint &p )
860 /* Ow, that's ugly: don't show the popup menu if cursor over
861 * the main menu bar or the status bar */
862 if( !childAt( p ) || ( ( childAt( p ) != menuBar() )
863 && ( childAt( p )->parentWidget() != statusBar() ) ) )
864 QVLCMenu::PopupMenu( p_intf, true );
867 /****************************************************************************
869 ****************************************************************************/
871 /* This event is used to deal with the fullscreen and always on top
872 issue conflict (bug in wx) */
873 class SetVideoOnTopQtEvent : public QEvent
876 SetVideoOnTopQtEvent( bool _onTop ) :
877 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
880 bool OnTop() const { return onTop; }
888 * You must note change the state of this object or other Qt4 UI objects,
889 * from the video output thread - only from the Qt4 UI main loop thread.
890 * All window provider queries must be handled through signals or events.
891 * That's why we have all those emit statements...
893 WId MainInterface::getVideo( int *pi_x, int *pi_y,
894 unsigned int *pi_width, unsigned int *pi_height )
899 /* This is a blocking call signal. Results are returned through pointers.
900 * Beware of deadlocks! */
902 emit askGetVideo( &id, pi_x, pi_y, pi_width, pi_height );
906 void MainInterface::getVideoSlot( WId *p_id, int *pi_x, int *pi_y,
907 unsigned *pi_width, unsigned *pi_height )
909 /* Request the videoWidget */
910 WId ret = videoWidget->request( pi_x, pi_y,
911 pi_width, pi_height, b_keep_size );
913 if( ret ) /* The videoWidget is available */
915 /* ask videoWidget to show */
916 videoWidget->SetSizing( *pi_width, *pi_height );
918 /* Consider the video active now */
921 stackCentralW->resize( *pi_width, *pi_height );
929 /* Asynchronous call from the WindowClose function */
930 void MainInterface::releaseVideo( void )
932 emit askReleaseVideo( );
935 /* Function that is CONNECTED to the previous emit */
936 void MainInterface::releaseVideoSlot( void )
938 videoWidget->release( );
940 restoreStackOldWidget();
942 /* Try to resize, except when you are in Fullscreen mode */
943 // doComponentsUpdate();
946 /* Asynchronous call from WindowControl function */
947 int MainInterface::controlVideo( int i_query, va_list args )
949 /* Debug to check if VOUT_WINDOW_SET_SIZE is called, because this is broken now */
950 msg_Warn( p_intf, "Control Video: %i", i_query );
953 case VOUT_WINDOW_SET_SIZE:
955 unsigned int i_width = va_arg( args, unsigned int );
956 unsigned int i_height = va_arg( args, unsigned int );
957 emit askVideoToResize( i_width, i_height );
961 case VOUT_WINDOW_SET_STATE:
963 unsigned i_arg = va_arg( args, unsigned );
964 unsigned on_top = i_arg & VOUT_WINDOW_STATE_ABOVE;
965 QApplication::postEvent( this, new SetVideoOnTopQtEvent( on_top ) );
968 case VOUT_WINDOW_SET_FULLSCREEN:
970 bool b_fs = va_arg( args, int );
971 emit askVideoSetFullScreen( b_fs );
975 msg_Warn( p_intf, "unsupported control query" );
980 /*****************************************************************************
981 * Playlist, Visualisation and Menus handling
982 *****************************************************************************/
984 * Toggle the playlist widget or dialog
986 void MainInterface::createPlaylist( bool b_show )
988 playlistWidget = new PlaylistWidget( p_intf, this );
990 i_pl_dock = PL_BOTTOM;
991 /* i_pl_dock = (pl_dock_e)getSettings()
992 ->value( "pl-dock-status", PL_UNDOCKED ).toInt(); */
994 if( i_pl_dock == PL_UNDOCKED )
996 playlistWidget->setWindowFlags( Qt::Window );
998 /* This will restore the geometry but will not work for position,
999 because of parenting */
1000 QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
1001 playlistWidget, QSize( 600, 300 ) );
1006 msg_Warn( p_intf, "Here %i", stackCentralW->currentIndex() );
1008 stackCentralW->insertWidget( PLAYL_TAB, playlistWidget );
1010 msg_Warn( p_intf, "Here %i", stackCentralW->currentIndex() );
1016 playlistVisible = true;
1017 stackCentralW->show();
1021 void MainInterface::togglePlaylist()
1024 msg_Warn( p_intf, "Here toggling %i %i", stackCentralW->currentIndex(), stackCentralOldState );
1026 if( !playlistWidget )
1028 createPlaylist( true );
1031 msg_Warn( p_intf, "Here toggling %i %i", stackCentralW->currentIndex(), stackCentralOldState );
1034 if( i_pl_dock != PL_UNDOCKED )
1036 /* Playlist not visible */
1037 if( stackCentralW->currentIndex() != PLAYL_TAB )
1039 showTab( PLAYL_TAB );
1040 stackCentralW->show();
1044 restoreStackOldWidget();
1046 playlistVisible = ( stackCentralW->currentIndex() == PLAYL_TAB );
1047 //doComponentsUpdate(); //resize( sizeHint() );
1051 /* Function called from the menu to undock the playlist */
1052 void MainInterface::undockPlaylist()
1054 // dockPL->setFloating( true );
1058 void MainInterface::dockPlaylist( pl_dock_e i_pos )
1062 void MainInterface::toggleMinimalView( bool b_switch )
1064 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
1065 i_visualmode != QT_MINIMAL_MODE )
1066 { /* NORMAL MODE then */
1067 stackCentralW->show();
1068 if( !videoWidget || stackCentralW->currentIndex() != VIDEO_TAB )
1074 /* If video is visible, then toggle the status of bgWidget */
1075 //bgWasVisible = !bgWasVisible;
1076 if( stackCentralOldState == BACKG_TAB )
1077 stackCentralOldState = HIDDEN_TAB;
1079 stackCentralOldState = BACKG_TAB;
1083 i_bg_height = stackCentralW->height();
1085 menuBar()->setVisible( !b_switch );
1086 controls->setVisible( !b_switch );
1087 statusBar()->setVisible( !b_switch );
1088 inputC->setVisible( !b_switch );
1090 doComponentsUpdate();
1092 emit minimalViewToggled( b_switch );
1095 /* toggling advanced controls buttons */
1096 void MainInterface::toggleAdvanced()
1098 controls->toggleAdvanced();
1099 // if( fullscreenControls ) fullscreenControls->toggleAdvanced();
1102 /* Get the visibility status of the controls (hidden or not, advanced or not) */
1103 int MainInterface::getControlsVisibilityStatus()
1105 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
1106 + CONTROLS_ADVANCED * controls->b_advancedVisible );
1110 void MainInterface::visual()
1112 if( !VISIBLE( visualSelector) )
1114 visualSelector->show();
1115 if( !THEMIM->getIM()->hasVideo() )
1117 /* Show the background widget */
1119 visualSelectorEnabled = true;
1123 /* Stop any currently running visualization */
1124 visualSelector->hide();
1125 visualSelectorEnabled = false;
1127 doComponentsUpdate();
1131 /************************************************************************
1133 ************************************************************************/
1134 void MainInterface::setName( const QString& name )
1136 input_name = name; /* store it for the QSystray use */
1137 /* Display it in the status bar, but also as a Tooltip in case it doesn't
1139 nameLabel->setText( " " + name + " " );
1140 nameLabel->setToolTip( " " + name +" " );
1144 * Give the decorations of the Main Window a correct Name.
1145 * If nothing is given, set it to VLC...
1147 void MainInterface::setVLCWindowsTitle( const QString& aTitle )
1149 if( aTitle.isEmpty() )
1151 setWindowTitle( qtr( "VLC media player" ) );
1155 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
1159 void MainInterface::showCryptedLabel( bool b_show )
1161 if( cryptedLabel == NULL )
1163 cryptedLabel = new QLabel;
1164 // The lock icon is not the right one for DRM protection/scrambled.
1165 //cryptedLabel->setPixmap( QPixmap( ":/lock" ) );
1166 cryptedLabel->setText( "DRM" );
1167 statusBar()->addWidget( cryptedLabel );
1170 cryptedLabel->setVisible( b_show );
1173 /*****************************************************************************
1174 * Systray Icon and Systray Menu
1175 *****************************************************************************/
1178 * Create a SystemTray icon and a menu that would go with it.
1179 * Connects to a click handler on the icon.
1181 void MainInterface::createSystray()
1184 if( QDate::currentDate().dayOfYear() >= 354 )
1185 iconVLC = QIcon( ":/logo/vlc128-christmas.png" );
1187 iconVLC = QIcon( ":/logo/vlc128.png" );
1188 sysTray = new QSystemTrayIcon( iconVLC, this );
1189 sysTray->setToolTip( qtr( "VLC media player" ));
1191 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
1192 systrayMenu->setIcon( iconVLC );
1194 QVLCMenu::updateSystrayMenu( this, p_intf, true );
1197 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
1198 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
1202 * Updates the Systray Icon's menu and toggle the main interface
1204 void MainInterface::toggleUpdateSystrayMenu()
1206 /* If hidden, show it */
1212 else if( isMinimized() )
1220 /* Visible (possibly under other windows) */
1222 /* check if any visible window is above vlc in the z-order,
1223 * but ignore the ones always on top
1224 * and the ones which can't be activated */
1227 wi.cbSize = sizeof( WINDOWINFO );
1228 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
1229 hwnd && ( !IsWindowVisible( hwnd ) ||
1230 ( GetWindowInfo( hwnd, &wi ) &&
1231 (wi.dwExStyle&WS_EX_NOACTIVATE) ) );
1232 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
1233 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
1234 (wi.dwExStyle&WS_EX_TOPMOST) )
1246 QVLCMenu::updateSystrayMenu( this, p_intf );
1249 void MainInterface::handleSystrayClick(
1250 QSystemTrayIcon::ActivationReason reason )
1254 case QSystemTrayIcon::Trigger:
1255 case QSystemTrayIcon::DoubleClick:
1256 toggleUpdateSystrayMenu();
1258 case QSystemTrayIcon::MiddleClick:
1259 sysTray->showMessage( qtr( "VLC media player" ),
1260 qtr( "Control menu for the player" ),
1261 QSystemTrayIcon::Information, 3000 );
1269 * Updates the name of the systray Icon tooltip.
1270 * Doesn't check if the systray exists, check before you call it.
1272 void MainInterface::updateSystrayTooltipName( const QString& name )
1274 if( name.isEmpty() )
1276 sysTray->setToolTip( qtr( "VLC media player" ) );
1280 sysTray->setToolTip( name );
1281 if( notificationEnabled && ( isHidden() || isMinimized() ) )
1283 sysTray->showMessage( qtr( "VLC media player" ), name,
1284 QSystemTrayIcon::NoIcon, 3000 );
1288 QVLCMenu::updateSystrayMenu( this, p_intf );
1292 * Updates the status of the systray Icon tooltip.
1293 * Doesn't check if the systray exists, check before you call it.
1295 void MainInterface::updateSystrayTooltipStatus( int i_status )
1302 sysTray->setToolTip( qtr( "VLC media player" ) );
1307 sysTray->setToolTip( input_name );
1312 sysTray->setToolTip( input_name + " - "
1317 QVLCMenu::updateSystrayMenu( this, p_intf );
1321 /************************************************************************
1323 ************************************************************************/
1324 void MainInterface::dropEvent(QDropEvent *event)
1326 dropEventPlay( event, true );
1329 void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
1331 event->setDropAction( Qt::CopyAction );
1332 if( !event->possibleActions() & Qt::CopyAction )
1335 const QMimeData *mimeData = event->mimeData();
1337 /* D&D of a subtitles file, add it on the fly */
1338 if( mimeData->urls().size() == 1 && THEMIM->getIM()->hasInput() )
1340 if( !input_AddSubtitle( THEMIM->getInput(),
1341 qtu( toNativeSeparators( mimeData->urls()[0].toLocalFile() ) ),
1349 bool first = b_play;
1350 foreach( const QUrl &url, mimeData->urls() )
1352 QString s = toNativeSeparators( url.toLocalFile() );
1354 if( s.length() > 0 ) {
1355 char* psz_uri = make_URI( qtu(s) );
1356 playlist_Add( THEPL, psz_uri, NULL,
1357 PLAYLIST_APPEND | (first ? PLAYLIST_GO: PLAYLIST_PREPARSE),
1358 PLAYLIST_END, true, pl_Unlocked );
1361 RecentsMRL::getInstance( p_intf )->addRecent( s );
1366 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1368 event->acceptProposedAction();
1370 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1372 event->acceptProposedAction();
1374 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1379 /************************************************************************
1381 ************************************************************************/
1382 void MainInterface::customEvent( QEvent *event )
1385 if( event->type() == PLDockEvent_Type )
1387 PlaylistDialog::killInstance();
1388 playlistEmbeddedFlag = true;
1390 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1395 if ( event->type() == (int)SetVideoOnTopEvent_Type )
1397 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1398 if( p_event->OnTop() )
1399 setWindowFlags( windowFlags() | Qt::WindowStaysOnTopHint );
1401 setWindowFlags( windowFlags() & ~Qt::WindowStaysOnTopHint );
1402 show(); /* necessary to apply window flags */
1406 void MainInterface::keyPressEvent( QKeyEvent *e )
1408 handleKeyPress( e );
1411 void MainInterface::handleKeyPress( QKeyEvent *e )
1413 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() == Qt::Key_H )
1414 && !menuBar()->isVisible() )
1416 toggleMinimalView( false );
1420 int i_vlck = qtEventToVLCKey( e );
1423 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1430 void MainInterface::resizeEvent( QResizeEvent * event )
1435 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
1436 i_visualmode == QT_MINIMAL_MODE )
1438 mainVideoSize = size();
1442 if( VISIBLE( bgWidget) ||
1443 ( videoIsActive && videoWidget->isVisible() )
1445 mainVideoSize = size();
1447 mainBasedSize = size();
1451 QVLCMW::resizeEvent( event );
1452 msg_Dbg( p_intf, "Resize Event, height: %i", size().height() );
1455 void MainInterface::wheelEvent( QWheelEvent *e )
1457 int i_vlckey = qtWheelEventToVLCKey( e );
1458 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1462 void MainInterface::closeEvent( QCloseEvent *e )
1469 void MainInterface::toggleFullScreen( void )
1471 if( isFullScreen() )
1474 emit askUpdate(); // Needed if video was launched after the F11
1475 emit fullscreenInterfaceToggled( false );
1480 emit fullscreenInterfaceToggled( true );
1485 //moc doesn't know about #ifdef, so we have to build this method for every platform
1486 void MainInterface::changeThumbbarButtons( int i_status)
1489 // Define an array of three buttons. These buttons provide images through an
1490 // image list and also provide tooltips.
1491 DWORD dwMask = THB_BITMAP | THB_FLAGS;
1493 THUMBBUTTON thbButtons[3];
1495 thbButtons[0].dwMask = dwMask;
1496 thbButtons[0].iId = 0;
1497 thbButtons[0].iBitmap = 0;
1500 thbButtons[1].dwMask = dwMask;
1501 thbButtons[1].iId = 1;
1504 thbButtons[2].dwMask = dwMask;
1505 thbButtons[2].iId = 2;
1506 thbButtons[2].iBitmap = 3;
1512 thbButtons[0].dwFlags = THBF_ENABLED;
1513 thbButtons[1].dwFlags = THBF_ENABLED;
1514 thbButtons[2].dwFlags = THBF_ENABLED;
1515 thbButtons[1].iBitmap = 1;
1520 thbButtons[0].dwFlags = THBF_ENABLED;
1521 thbButtons[1].dwFlags = THBF_ENABLED;
1522 thbButtons[2].dwFlags = THBF_ENABLED;
1523 thbButtons[1].iBitmap = 2;
1529 HRESULT hr = p_taskbl->vt->ThumbBarUpdateButtons(p_taskbl, this->winId(), 3, thbButtons);
1531 msg_Err( p_intf, "ThumbBarUpdateButtons failed with error %08x", hr );
1537 /*****************************************************************************
1538 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1539 * We don't show the menu directly here because we don't want the
1540 * caller to block for a too long time.
1541 *****************************************************************************/
1542 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1543 vlc_value_t old_val, vlc_value_t new_val, void *param )
1545 intf_thread_t *p_intf = (intf_thread_t *)param;
1547 if( p_intf->pf_show_dialog )
1549 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1550 new_val.b_bool, NULL );
1556 /*****************************************************************************
1557 * IntfShowCB: callback triggered by the intf-show libvlc variable.
1558 *****************************************************************************/
1559 static int IntfShowCB( 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;
1563 p_intf->p_sys->p_mi->toggleFSC();