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 );
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 */
219 var_AddCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
221 /* Register callback for the intf-popupmenu variable */
222 var_AddCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
225 /* VideoWidget connects for asynchronous calls */
226 connect( this, SIGNAL(askGetVideo(WId*,int*,int*,unsigned*,unsigned *)),
227 this, SLOT(getVideoSlot(WId*,int*,int*,unsigned*,unsigned*)),
228 Qt::BlockingQueuedConnection );
229 connect( this, SIGNAL(askReleaseVideo( void )),
230 this, SLOT(releaseVideoSlot( void )),
231 Qt::BlockingQueuedConnection );
235 CONNECT( this, askVideoToResize( unsigned int, unsigned int ),
236 videoWidget, SetSizing( unsigned int, unsigned int ) );
237 CONNECT( this, askVideoSetFullScreen( bool ),
238 videoWidget, SetFullScreen( bool ) );
239 CONNECT( videoWidget, keyPressed( QKeyEvent * ),
240 this, handleKeyPress( QKeyEvent * ) );
243 CONNECT( this, askUpdate(), this, doComponentsUpdate() );
244 CONNECT( THEDP, toolBarConfUpdated(), this, recreateToolbars() );
246 /* Enable the popup menu in the MI */
247 setContextMenuPolicy( Qt::CustomContextMenu );
248 CONNECT( this, customContextMenuRequested( const QPoint& ),
249 this, popupMenu( const QPoint& ) );
251 /** END of CONNECTS**/
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 );
274 if( settings->value( "playlist-visible", 0 ).toInt() )
276 settings->endGroup();
278 /* Final sizing and showing */
279 setVisible( !b_hideAfterCreation );
280 //setMinimumSize( QSize( 0, 0 ) );
281 // setMinimumWidth( __MAX( controls->sizeHint().width(),
282 // menuBar()->sizeHint().width() ) );
285 /* And switch to minimal view if needed
286 Must be called after the show() */
287 if( i_visualmode == QT_MINIMAL_MODE )
288 toggleMinimalView( true );
290 /* Update the geometry : It is useful if you switch between
293 resize( sizeHint() );
296 MainInterface::~MainInterface()
298 msg_Dbg( p_intf, "Destroying the main interface" );
300 /* Unsure we hide the videoWidget before destroying it */
301 if( stackCentralOldState == VIDEO_TAB )
304 /* Save playlist state */
308 QVLCTools::saveWidgetPosition( p_intf, "Playlist", playlistWidget );
310 delete playlistWidget;
315 ImageList_Destroy( himl );
317 p_taskbl->vt->Release(p_taskbl);
321 /* Be sure to kill the actionsManager... FIXME */
322 ActionsManager::killInstance();
325 ExtensionsManager::killInstance();
327 /* Delete the FSC controller */
328 delete fullscreenControls;
331 settings->beginGroup( "MainWindow" );
332 settings->setValue( "pl-dock-status", (int)i_pl_dock );
333 settings->setValue( "playlist-visible", (int)playlistVisible );
334 settings->setValue( "adv-controls",
335 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
337 settings->setValue( "mainBasedSize", mainBasedSize );
338 settings->setValue( "mainVideoSize", mainVideoSize );
341 settings->setValue( "backgroundSize", bgWidget->size() );
344 QVLCTools::saveWidgetPosition(settings, this);
345 settings->endGroup();
347 /* Unregister callbacks */
348 var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
349 var_DelCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
351 p_intf->p_sys->p_mi = NULL;
354 /*****************************
356 *****************************/
357 void MainInterface::recreateToolbars()
359 //msg_Dbg( p_intf, "Recreating the toolbars" );
360 settings->beginGroup( "MainWindow" );
364 controls = new ControlsWidget( p_intf, false, this ); /* FIXME */
365 CONNECT( controls, advancedControlsToggled( bool ),
366 this, doComponentsUpdate() );
367 CONNECT( controls, sizeChanged(),
368 this, doComponentsUpdate() );
370 inputC = new InputControlsWidget( p_intf, this );
372 mainLayout->insertWidget( 2, inputC );
373 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
375 settings->endGroup();
378 void MainInterface::createMainWidget( QSettings *settings )
380 /* Create the main Widget and the mainLayout */
381 QWidget *main = new QWidget;
382 setCentralWidget( main );
383 mainLayout = new QVBoxLayout( main );
385 /* Margins, spacing */
386 main->setContentsMargins( 0, 0, 0, 0 );
387 mainLayout->setSpacing( 0 ); mainLayout->setMargin( 0 );
390 stackCentralW = new QStackedWidget( main );
393 bgWidget = new BackgroundWidget( p_intf );
395 settings->value( "backgroundSize", QSize( 300, 200 ) ).toSize() );
396 bgWidget->updateGeometry();
397 stackCentralW->insertWidget( BACKG_TAB, bgWidget );
400 /* And video Outputs */
401 if( videoEmbeddedFlag )
403 videoWidget = new VideoWidget( p_intf );
404 stackCentralW->insertWidget( VIDEO_TAB, videoWidget );
406 mainLayout->insertWidget( 1, stackCentralW, 100 );
409 /* Create the CONTROLS Widget */
410 controls = new ControlsWidget( p_intf,
411 settings->value( "adv-controls", false ).toBool(), this );
412 CONNECT( controls, advancedControlsToggled( bool ),
413 this, doComponentsUpdate() );
414 CONNECT( controls, sizeChanged(),
415 this, doComponentsUpdate() );
416 inputC = new InputControlsWidget( p_intf, this );
418 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
419 i_visualmode != QT_MINIMAL_MODE )
422 stackCentralOldState = HIDDEN_TAB;
426 showTab( BACKG_TAB );
427 stackCentralOldState = BACKG_TAB;
431 //mainLayout->setRowStretch( 1, 10 );
432 mainLayout->insertWidget( 2, inputC );
433 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
437 /* Disabled for now, they SUCK */
439 visualSelector = new VisualSelector( p_intf );
440 mainLayout->insertWidget( 0, visualSelector );
441 visualSelector->hide();
444 /* Finish the sizing */
445 main->updateGeometry();
447 getSettings()->endGroup();
451 /* Create the FULLSCREEN CONTROLS Widget */
452 if( var_InheritBool( p_intf, "qt-fs-controller" ) )
454 fullscreenControls = new FullscreenControllerWidget( p_intf, this );
455 CONNECT( fullscreenControls, keyPressed( QKeyEvent * ),
456 this, handleKeyPress( QKeyEvent * ) );
460 inline void MainInterface::initSystray()
463 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
464 bool b_systrayWanted = var_InheritBool( p_intf, "qt-system-tray" );
466 if( var_InheritBool( p_intf, "qt-start-minimized") )
468 if( b_systrayAvailable )
470 b_systrayWanted = true;
471 b_hideAfterCreation = true;
474 msg_Err( p_intf, "cannot start minimized without system tray bar" );
477 if( b_systrayAvailable && b_systrayWanted )
482 inline void MainInterface::createStatusBar()
487 /* Widgets Creation*/
488 QStatusBar *statusBarr = statusBar();
490 TimeLabel *timeLabel = new TimeLabel( p_intf );
491 nameLabel = new QLabel( this );
492 nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
493 | Qt::TextSelectableByKeyboard );
494 SpeedLabel *speedLabel = new SpeedLabel( p_intf, "1.00x", this );
496 /* Styling those labels */
497 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
498 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
499 nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
501 /* and adding those */
502 statusBarr->addWidget( nameLabel, 8 );
503 statusBarr->addPermanentWidget( speedLabel, 0 );
504 statusBarr->addPermanentWidget( timeLabel, 0 );
506 /* timeLabel behaviour:
507 - double clicking opens the goto time dialog
508 - right-clicking and clicking just toggle between remaining and
510 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
512 CONNECT( THEMIM->getIM(), encryptionChanged( bool ),
513 this, showCryptedLabel( bool ) );
517 void MainInterface::createTaskBarButtons()
519 taskbar_wmsg = WM_NULL;
520 /*Here is the code for the taskbar thumb buttons
521 FIXME:We need pretty buttons in 16x16 px that are handled correctly by masks in Qt
522 FIXME:the play button's picture doesn't changed to pause when clicked
527 if( S_OK == CoCreateInstance( &clsid_ITaskbarList,
528 NULL, CLSCTX_INPROC_SERVER,
530 (void **)&p_taskbl) )
532 p_taskbl->vt->HrInit(p_taskbl);
534 if(himl = ImageList_Create( 15, //cx
537 4,//initial nb of images
538 0//nb of images that can be added
541 QPixmap img = QPixmap(":/toolbar/previous_b");
542 QPixmap img2 = QPixmap(":/toolbar/pause_b");
543 QPixmap img3 = QPixmap(":/toolbar/play_b");
544 QPixmap img4 = QPixmap(":/toolbar/next_b");
545 QBitmap mask = img.createMaskFromColor(Qt::transparent);
546 QBitmap mask2 = img2.createMaskFromColor(Qt::transparent);
547 QBitmap mask3 = img3.createMaskFromColor(Qt::transparent);
548 QBitmap mask4 = img4.createMaskFromColor(Qt::transparent);
550 if(-1 == ImageList_Add(himl, img.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask.toWinHBITMAP()))
551 msg_Err( p_intf, "ImageList_Add failed" );
552 if(-1 == ImageList_Add(himl, img2.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask2.toWinHBITMAP()))
553 msg_Err( p_intf, "ImageList_Add failed" );
554 if(-1 == ImageList_Add(himl, img3.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask3.toWinHBITMAP()))
555 msg_Err( p_intf, "ImageList_Add failed" );
556 if(-1 == ImageList_Add(himl, img4.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask4.toWinHBITMAP()))
557 msg_Err( p_intf, "ImageList_Add failed" );
560 // Define an array of two buttons. These buttons provide images through an
561 // image list and also provide tooltips.
562 DWORD dwMask = THB_BITMAP | THB_FLAGS;
564 THUMBBUTTON thbButtons[3];
565 thbButtons[0].dwMask = dwMask;
566 thbButtons[0].iId = 0;
567 thbButtons[0].iBitmap = 0;
568 thbButtons[0].dwFlags = THBF_HIDDEN;
570 thbButtons[1].dwMask = dwMask;
571 thbButtons[1].iId = 1;
572 thbButtons[1].iBitmap = 2;
573 thbButtons[1].dwFlags = THBF_HIDDEN;
575 thbButtons[2].dwMask = dwMask;
576 thbButtons[2].iId = 2;
577 thbButtons[2].iBitmap = 3;
578 thbButtons[2].dwFlags = THBF_HIDDEN;
580 HRESULT hr = p_taskbl->vt->ThumbBarSetImageList(p_taskbl, winId(), himl );
582 msg_Err( p_intf, "ThumbBarSetImageList failed with error %08x", hr );
585 hr = p_taskbl->vt->ThumbBarAddButtons(p_taskbl, winId(), 3, thbButtons);
587 msg_Err( p_intf, "ThumbBarAddButtons failed with error %08x", hr );
589 CONNECT( THEMIM->getIM(), statusChanged( int ), this, changeThumbbarButtons( int ) );
599 bool MainInterface::winEvent ( MSG * msg, long * result )
601 if (msg->message == taskbar_wmsg)
603 //We received the taskbarbuttoncreated, now we can really create th buttons
604 createTaskBarButtons();
608 switch( msg->message )
611 if (HIWORD(msg->wParam) == THBN_CLICKED)
613 switch(LOWORD(msg->wParam))
619 THEMIM->togglePlayPause();
628 cmd = GET_APPCOMMAND_LPARAM(msg->lParam);
631 case APPCOMMAND_MEDIA_PLAY_PAUSE:
632 THEMIM->togglePlayPause();
634 case APPCOMMAND_MEDIA_PLAY:
637 case APPCOMMAND_MEDIA_PAUSE:
640 case APPCOMMAND_MEDIA_PREVIOUSTRACK:
643 case APPCOMMAND_MEDIA_NEXTTRACK:
646 case APPCOMMAND_MEDIA_STOP:
649 case APPCOMMAND_VOLUME_DOWN:
652 case APPCOMMAND_VOLUME_UP:
655 case APPCOMMAND_VOLUME_MUTE:
656 THEAM->toggleMuteAudio();
659 msg_Dbg( p_intf, "unknown APPCOMMAND = %d", cmd);
668 /**********************************************************************
669 * Handling of sizing of the components
670 **********************************************************************/
672 /* This function is probably wrong, but we don't have many many choices...
673 Since we can't know from the playlist Widget if we are inside a dock or not,
674 because the playlist Widget can be called by THEDP, as a separate windows for
676 Maybe the other solution is to redefine the sizeHint() of the playlist and
677 ask _parent->isFloating()...
678 If you think this would be better, please FIXME it...
681 QSize MainInterface::sizeHint() const
686 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
687 i_visualmode == QT_MINIMAL_MODE )
689 return mainVideoSize;
693 if( VISIBLE( bgWidget) ||
694 ( videoIsActive && videoWidget->isVisible() )
696 return mainVideoSize;
698 return mainBasedSize;
703 int nwidth = __MAX( controls->sizeHint().width(),
704 menuBar()->sizeHint().width() );
706 int nheight = controls->isVisible() ?
707 controls->size().height()
708 + inputC->size().height()
709 + menuBar()->size().height()
710 + statusBar()->size().height()
713 if( stackCentralW->isVisible() )
714 nheight += stackCentralW->height();
715 nwidth = __MAX( nwidth, stackCentralW->width() );
717 /* if( VISIBLE( bgWidget ) )
719 msg_Warn( p_intf, "Hello here" );
721 nheight += i_bg_height;
723 nheight += bgWidget->size().height();
724 nwidth = __MAX( nwidth, bgWidget->size().width() );
726 else if( videoIsActive && videoWidget->isVisible() )
728 msg_Warn( p_intf, "Hello there" );
729 nheight += videoWidget->sizeHint().height();
730 nwidth = __MAX( nwidth, videoWidget->sizeHint().width() );
733 if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget() )
735 nheight += dockPL->size().height();
736 nwidth = __MAX( nwidth, dockPL->size().width() );
737 msg_Warn( p_intf, "3 %i %i", nheight, nwidth );
740 return QSize( nwidth, nheight );
744 /* Video widget cannot do this synchronously as it runs in another thread */
745 /* Well, could it, actually ? Probably dangerous ... */
747 /* This function is called:
748 - toggling of minimal View
749 - through askUpdate() by Vout thread request video and resize video (zoom)
750 - Advanced buttons toggled
752 void MainInterface::doComponentsUpdate()
754 if( isFullScreen() || isMaximized() ) return;
756 // msg_Warn( p_intf, "Updating the geometry" );
757 /* Here we resize to sizeHint() and not adjustsize because we want
758 the videoWidget to be exactly the correctSize */
763 /* This is WRONG, but I believe there is a Qt bug here */
764 setMinimumSize( 0, 0 );
765 resize( sizeHint() );
767 //adjustSize() ; /* This is not needed, but might help in the future */
770 void MainInterface::debug()
773 msg_Dbg( p_intf, "Stack Size: %i - %i", stackCentralW->size().height(), size().width() );
774 if( videoEmbeddedFlag )
775 msg_Dbg( p_intf, "Stack Size: %i - %i",
776 stackCentralW->widget( VIDEO_TAB )->size().height(),
777 stackCentralW->widget( VIDEO_TAB )->size().width() );
779 msg_Dbg( p_intf, "no embedded video" );
781 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
782 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
783 //msg_Dbg( p_intf, "maximumsize: %i - %i", maximumSize().height(), maximumSize().width() );
785 msg_Dbg( p_intf, "Stack minimumsize: %i - %i", stackCentralW->minimumSize().height(), stackCentralW->minimumSize().width() );
786 msg_Dbg( p_intf, "Controls minimumsize: %i - %i", controls->minimumSize().height(), controls->minimumSize().width() );
787 msg_Dbg( p_intf, "Central minimumsize: %i - %i", centralWidget()->minimumSize().height(), centralWidget()->minimumSize().width() );
788 msg_Dbg( p_intf, "Menu minimumsize: %i - %i", menuBar()->minimumSize().height(), menuBar()->minimumSize().width() );
789 msg_Dbg( p_intf, "Input minimuSize: %i - %i", inputC->minimumSize().height(), inputC->minimumSize().width() );
790 msg_Dbg( p_intf, "Status minimumsize: %i - %i", statusBar()->minimumSize().height(), statusBar()->minimumSize().width() );
791 msg_Dbg( p_intf, "minimumsize: %i - %i", minimumSize().height(), minimumSize().width() );
793 /*if( videoWidget && videoWidget->isVisible() )
795 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
796 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
801 inline void MainInterface::showTab( int i_tab )
804 msg_Err( p_intf, "showTab %i", i_tab );
805 msg_Warn( p_intf, "Old stackCentralOldState %i", stackCentralOldState );
807 stackCentralOldState = stackCentralW->isVisible() ? stackCentralW->currentIndex()
810 msg_Warn( p_intf, "State change %i %i", stackCentralW->currentIndex(), i_tab );
813 if( i_visualmode == QT_NORMAL_MODE )
815 stackCentralW->setVisible( i_tab != HIDDEN_TAB );
816 doComponentsUpdate(); // resize the player
819 if( i_tab == HIDDEN_TAB ) i_tab == BACKG_TAB;
821 stackCentralW->setCurrentIndex( i_tab );
824 msg_Warn( p_intf, "New stackCentralOldState %i", stackCentralOldState );
828 inline void MainInterface::restoreStackOldWidget()
831 msg_Warn( p_intf, "Old stackCentralOldState %i", stackCentralOldState );
833 int temp = stackCentralW->isVisible() ? stackCentralW->currentIndex()
835 stackCentralW->setCurrentIndex( stackCentralOldState );
836 if( i_visualmode == QT_NORMAL_MODE )
838 stackCentralW->setVisible( stackCentralOldState != HIDDEN_TAB );
839 doComponentsUpdate(); // resize the player
842 stackCentralOldState = temp;
844 msg_Warn( p_intf, "Debug %i %i", temp, stackCentralW->currentIndex() );
848 void MainInterface::destroyPopupMenu()
850 QVLCMenu::PopupMenu( p_intf, false );
853 void MainInterface::toggleFSC()
855 if( !fullscreenControls ) return;
857 IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
858 QApplication::postEvent( fullscreenControls, eShow );
861 void MainInterface::popupMenu( const QPoint &p )
863 /* Ow, that's ugly: don't show the popup menu if cursor over
864 * the main menu bar or the status bar */
865 if( !childAt( p ) || ( ( childAt( p ) != menuBar() )
866 && ( childAt( p )->parentWidget() != statusBar() ) ) )
867 QVLCMenu::PopupMenu( p_intf, true );
870 /****************************************************************************
872 ****************************************************************************/
874 /* This event is used to deal with the fullscreen and always on top
875 issue conflict (bug in wx) */
876 class SetVideoOnTopQtEvent : public QEvent
879 SetVideoOnTopQtEvent( bool _onTop ) :
880 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
883 bool OnTop() const { return onTop; }
891 * You must note change the state of this object or other Qt4 UI objects,
892 * from the video output thread - only from the Qt4 UI main loop thread.
893 * All window provider queries must be handled through signals or events.
894 * That's why we have all those emit statements...
896 WId MainInterface::getVideo( int *pi_x, int *pi_y,
897 unsigned int *pi_width, unsigned int *pi_height )
902 /* This is a blocking call signal. Results are returned through pointers.
903 * Beware of deadlocks! */
905 emit askGetVideo( &id, pi_x, pi_y, pi_width, pi_height );
909 void MainInterface::getVideoSlot( WId *p_id, int *pi_x, int *pi_y,
910 unsigned *pi_width, unsigned *pi_height )
912 /* Request the videoWidget */
913 WId ret = videoWidget->request( pi_x, pi_y,
914 pi_width, pi_height, b_keep_size );
916 if( ret ) /* The videoWidget is available */
918 /* ask videoWidget to show */
919 videoWidget->SetSizing( *pi_width, *pi_height );
921 /* Consider the video active now */
924 stackCentralW->resize( *pi_width, *pi_height );
932 /* Asynchronous call from the WindowClose function */
933 void MainInterface::releaseVideo( void )
935 emit askReleaseVideo( );
938 /* Function that is CONNECTED to the previous emit */
939 void MainInterface::releaseVideoSlot( void )
941 videoWidget->release( );
943 restoreStackOldWidget();
945 /* Try to resize, except when you are in Fullscreen mode */
946 // doComponentsUpdate();
949 /* Asynchronous call from WindowControl function */
950 int MainInterface::controlVideo( int i_query, va_list args )
952 /* Debug to check if VOUT_WINDOW_SET_SIZE is called, because this is broken now */
953 msg_Warn( p_intf, "Control Video: %i", i_query );
956 case VOUT_WINDOW_SET_SIZE:
958 unsigned int i_width = va_arg( args, unsigned int );
959 unsigned int i_height = va_arg( args, unsigned int );
960 emit askVideoToResize( i_width, i_height );
964 case VOUT_WINDOW_SET_STATE:
966 unsigned i_arg = va_arg( args, unsigned );
967 unsigned on_top = i_arg & VOUT_WINDOW_STATE_ABOVE;
968 QApplication::postEvent( this, new SetVideoOnTopQtEvent( on_top ) );
971 case VOUT_WINDOW_SET_FULLSCREEN:
973 bool b_fs = va_arg( args, int );
974 emit askVideoSetFullScreen( b_fs );
978 msg_Warn( p_intf, "unsupported control query" );
983 /*****************************************************************************
984 * Playlist, Visualisation and Menus handling
985 *****************************************************************************/
987 * Toggle the playlist widget or dialog
989 void MainInterface::createPlaylist( bool b_show )
991 playlistWidget = new PlaylistWidget( p_intf, this );
993 i_pl_dock = PL_BOTTOM;
994 /* i_pl_dock = (pl_dock_e)getSettings()
995 ->value( "pl-dock-status", PL_UNDOCKED ).toInt(); */
997 if( i_pl_dock == PL_UNDOCKED )
999 playlistWidget->setWindowFlags( Qt::Window );
1001 /* This will restore the geometry but will not work for position,
1002 because of parenting */
1003 QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
1004 playlistWidget, QSize( 600, 300 ) );
1009 msg_Warn( p_intf, "Here %i", stackCentralW->currentIndex() );
1011 stackCentralW->insertWidget( PLAYL_TAB, playlistWidget );
1013 msg_Warn( p_intf, "Here %i", stackCentralW->currentIndex() );
1019 playlistVisible = true;
1020 stackCentralW->show();
1024 void MainInterface::togglePlaylist()
1027 msg_Warn( p_intf, "Here toggling %i %i", stackCentralW->currentIndex(), stackCentralOldState );
1029 if( !playlistWidget )
1031 createPlaylist( true );
1034 msg_Warn( p_intf, "Here toggling %i %i", stackCentralW->currentIndex(), stackCentralOldState );
1037 if( i_pl_dock != PL_UNDOCKED )
1039 /* Playlist not visible */
1040 if( stackCentralW->currentIndex() != PLAYL_TAB )
1042 showTab( PLAYL_TAB );
1043 stackCentralW->show();
1047 restoreStackOldWidget();
1049 playlistVisible = ( stackCentralW->currentIndex() == PLAYL_TAB );
1050 //doComponentsUpdate(); //resize( sizeHint() );
1054 /* Function called from the menu to undock the playlist */
1055 void MainInterface::undockPlaylist()
1057 // dockPL->setFloating( true );
1061 void MainInterface::dockPlaylist( pl_dock_e i_pos )
1065 void MainInterface::toggleMinimalView( bool b_switch )
1067 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
1068 i_visualmode != QT_MINIMAL_MODE )
1069 { /* NORMAL MODE then */
1070 stackCentralW->show();
1071 if( !videoWidget || stackCentralW->currentIndex() != VIDEO_TAB )
1077 /* If video is visible, then toggle the status of bgWidget */
1078 //bgWasVisible = !bgWasVisible;
1079 if( stackCentralOldState == BACKG_TAB )
1080 stackCentralOldState = HIDDEN_TAB;
1082 stackCentralOldState = BACKG_TAB;
1086 i_bg_height = stackCentralW->height();
1088 menuBar()->setVisible( !b_switch );
1089 controls->setVisible( !b_switch );
1090 statusBar()->setVisible( !b_switch );
1091 inputC->setVisible( !b_switch );
1093 doComponentsUpdate();
1095 emit minimalViewToggled( b_switch );
1098 /* toggling advanced controls buttons */
1099 void MainInterface::toggleAdvanced()
1101 controls->toggleAdvanced();
1102 // if( fullscreenControls ) fullscreenControls->toggleAdvanced();
1105 /* Get the visibility status of the controls (hidden or not, advanced or not) */
1106 int MainInterface::getControlsVisibilityStatus()
1108 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
1109 + CONTROLS_ADVANCED * controls->b_advancedVisible );
1113 void MainInterface::visual()
1115 if( !VISIBLE( visualSelector) )
1117 visualSelector->show();
1118 if( !THEMIM->getIM()->hasVideo() )
1120 /* Show the background widget */
1122 visualSelectorEnabled = true;
1126 /* Stop any currently running visualization */
1127 visualSelector->hide();
1128 visualSelectorEnabled = false;
1130 doComponentsUpdate();
1134 /************************************************************************
1136 ************************************************************************/
1137 void MainInterface::setName( const QString& name )
1139 input_name = name; /* store it for the QSystray use */
1140 /* Display it in the status bar, but also as a Tooltip in case it doesn't
1142 nameLabel->setText( " " + name + " " );
1143 nameLabel->setToolTip( " " + name +" " );
1147 * Give the decorations of the Main Window a correct Name.
1148 * If nothing is given, set it to VLC...
1150 void MainInterface::setVLCWindowsTitle( const QString& aTitle )
1152 if( aTitle.isEmpty() )
1154 setWindowTitle( qtr( "VLC media player" ) );
1158 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
1162 void MainInterface::showCryptedLabel( bool b_show )
1164 if( cryptedLabel == NULL )
1166 cryptedLabel = new QLabel;
1167 // The lock icon is not the right one for DRM protection/scrambled.
1168 //cryptedLabel->setPixmap( QPixmap( ":/lock" ) );
1169 cryptedLabel->setText( "DRM" );
1170 statusBar()->addWidget( cryptedLabel );
1173 cryptedLabel->setVisible( b_show );
1176 /*****************************************************************************
1177 * Systray Icon and Systray Menu
1178 *****************************************************************************/
1181 * Create a SystemTray icon and a menu that would go with it.
1182 * Connects to a click handler on the icon.
1184 void MainInterface::createSystray()
1187 if( QDate::currentDate().dayOfYear() >= 354 )
1188 iconVLC = QIcon( ":/logo/vlc128-christmas.png" );
1190 iconVLC = QIcon( ":/logo/vlc128.png" );
1191 sysTray = new QSystemTrayIcon( iconVLC, this );
1192 sysTray->setToolTip( qtr( "VLC media player" ));
1194 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
1195 systrayMenu->setIcon( iconVLC );
1197 QVLCMenu::updateSystrayMenu( this, p_intf, true );
1200 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
1201 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
1205 * Updates the Systray Icon's menu and toggle the main interface
1207 void MainInterface::toggleUpdateSystrayMenu()
1209 /* If hidden, show it */
1215 else if( isMinimized() )
1223 /* Visible (possibly under other windows) */
1225 /* check if any visible window is above vlc in the z-order,
1226 * but ignore the ones always on top
1227 * and the ones which can't be activated */
1230 wi.cbSize = sizeof( WINDOWINFO );
1231 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
1232 hwnd && ( !IsWindowVisible( hwnd ) ||
1233 ( GetWindowInfo( hwnd, &wi ) &&
1234 (wi.dwExStyle&WS_EX_NOACTIVATE) ) );
1235 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
1236 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
1237 (wi.dwExStyle&WS_EX_TOPMOST) )
1249 QVLCMenu::updateSystrayMenu( this, p_intf );
1252 void MainInterface::handleSystrayClick(
1253 QSystemTrayIcon::ActivationReason reason )
1257 case QSystemTrayIcon::Trigger:
1258 case QSystemTrayIcon::DoubleClick:
1259 toggleUpdateSystrayMenu();
1261 case QSystemTrayIcon::MiddleClick:
1262 sysTray->showMessage( qtr( "VLC media player" ),
1263 qtr( "Control menu for the player" ),
1264 QSystemTrayIcon::Information, 3000 );
1272 * Updates the name of the systray Icon tooltip.
1273 * Doesn't check if the systray exists, check before you call it.
1275 void MainInterface::updateSystrayTooltipName( const QString& name )
1277 if( name.isEmpty() )
1279 sysTray->setToolTip( qtr( "VLC media player" ) );
1283 sysTray->setToolTip( name );
1284 if( notificationEnabled && ( isHidden() || isMinimized() ) )
1286 sysTray->showMessage( qtr( "VLC media player" ), name,
1287 QSystemTrayIcon::NoIcon, 3000 );
1291 QVLCMenu::updateSystrayMenu( this, p_intf );
1295 * Updates the status of the systray Icon tooltip.
1296 * Doesn't check if the systray exists, check before you call it.
1298 void MainInterface::updateSystrayTooltipStatus( int i_status )
1305 sysTray->setToolTip( qtr( "VLC media player" ) );
1310 sysTray->setToolTip( input_name );
1315 sysTray->setToolTip( input_name + " - "
1320 QVLCMenu::updateSystrayMenu( this, p_intf );
1324 /************************************************************************
1326 ************************************************************************/
1327 void MainInterface::dropEvent(QDropEvent *event)
1329 dropEventPlay( event, true );
1332 void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
1334 event->setDropAction( Qt::CopyAction );
1335 if( !event->possibleActions() & Qt::CopyAction )
1338 const QMimeData *mimeData = event->mimeData();
1340 /* D&D of a subtitles file, add it on the fly */
1341 if( mimeData->urls().size() == 1 && THEMIM->getIM()->hasInput() )
1343 if( !input_AddSubtitle( THEMIM->getInput(),
1344 qtu( toNativeSeparators( mimeData->urls()[0].toLocalFile() ) ),
1352 bool first = b_play;
1353 foreach( const QUrl &url, mimeData->urls() )
1355 QString s = toNativeSeparators( url.toLocalFile() );
1357 if( s.length() > 0 ) {
1358 char* psz_uri = make_URI( qtu(s) );
1359 playlist_Add( THEPL, psz_uri, NULL,
1360 PLAYLIST_APPEND | (first ? PLAYLIST_GO: PLAYLIST_PREPARSE),
1361 PLAYLIST_END, true, pl_Unlocked );
1364 RecentsMRL::getInstance( p_intf )->addRecent( s );
1369 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1371 event->acceptProposedAction();
1373 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1375 event->acceptProposedAction();
1377 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1382 /************************************************************************
1384 ************************************************************************/
1385 void MainInterface::customEvent( QEvent *event )
1388 if( event->type() == PLDockEvent_Type )
1390 PlaylistDialog::killInstance();
1391 playlistEmbeddedFlag = true;
1393 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1398 if ( event->type() == (int)SetVideoOnTopEvent_Type )
1400 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1401 if( p_event->OnTop() )
1402 setWindowFlags( windowFlags() | Qt::WindowStaysOnTopHint );
1404 setWindowFlags( windowFlags() & ~Qt::WindowStaysOnTopHint );
1405 show(); /* necessary to apply window flags */
1409 void MainInterface::keyPressEvent( QKeyEvent *e )
1411 handleKeyPress( e );
1414 void MainInterface::handleKeyPress( QKeyEvent *e )
1416 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() == Qt::Key_H )
1417 && !menuBar()->isVisible() )
1419 toggleMinimalView( false );
1423 int i_vlck = qtEventToVLCKey( e );
1426 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1433 void MainInterface::resizeEvent( QResizeEvent * event )
1438 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
1439 i_visualmode == QT_MINIMAL_MODE )
1441 mainVideoSize = size();
1445 if( VISIBLE( bgWidget) ||
1446 ( videoIsActive && videoWidget->isVisible() )
1448 mainVideoSize = size();
1450 mainBasedSize = size();
1454 QVLCMW::resizeEvent( event );
1455 msg_Dbg( p_intf, "Resize Event, height: %i", size().height() );
1458 void MainInterface::wheelEvent( QWheelEvent *e )
1460 int i_vlckey = qtWheelEventToVLCKey( e );
1461 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1465 void MainInterface::closeEvent( QCloseEvent *e )
1472 void MainInterface::toggleFullScreen( void )
1474 if( isFullScreen() )
1477 emit askUpdate(); // Needed if video was launched after the F11
1478 emit fullscreenInterfaceToggled( false );
1483 emit fullscreenInterfaceToggled( true );
1488 //moc doesn't know about #ifdef, so we have to build this method for every platform
1489 void MainInterface::changeThumbbarButtons( int i_status)
1492 // Define an array of three buttons. These buttons provide images through an
1493 // image list and also provide tooltips.
1494 DWORD dwMask = THB_BITMAP | THB_FLAGS;
1496 THUMBBUTTON thbButtons[3];
1498 thbButtons[0].dwMask = dwMask;
1499 thbButtons[0].iId = 0;
1500 thbButtons[0].iBitmap = 0;
1503 thbButtons[1].dwMask = dwMask;
1504 thbButtons[1].iId = 1;
1507 thbButtons[2].dwMask = dwMask;
1508 thbButtons[2].iId = 2;
1509 thbButtons[2].iBitmap = 3;
1515 thbButtons[0].dwFlags = THBF_ENABLED;
1516 thbButtons[1].dwFlags = THBF_ENABLED;
1517 thbButtons[2].dwFlags = THBF_ENABLED;
1518 thbButtons[1].iBitmap = 1;
1523 thbButtons[0].dwFlags = THBF_ENABLED;
1524 thbButtons[1].dwFlags = THBF_ENABLED;
1525 thbButtons[2].dwFlags = THBF_ENABLED;
1526 thbButtons[1].iBitmap = 2;
1532 HRESULT hr = p_taskbl->vt->ThumbBarUpdateButtons(p_taskbl, this->winId(), 3, thbButtons);
1534 msg_Err( p_intf, "ThumbBarUpdateButtons failed with error %08x", hr );
1540 /*****************************************************************************
1541 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1542 * We don't show the menu directly here because we don't want the
1543 * caller to block for a too long time.
1544 *****************************************************************************/
1545 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1546 vlc_value_t old_val, vlc_value_t new_val, void *param )
1548 intf_thread_t *p_intf = (intf_thread_t *)param;
1550 if( p_intf->pf_show_dialog )
1552 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1553 new_val.b_bool, NULL );
1559 /*****************************************************************************
1560 * IntfShowCB: callback triggered by the intf-show libvlc variable.
1561 *****************************************************************************/
1562 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1563 vlc_value_t old_val, vlc_value_t new_val, void *param )
1565 intf_thread_t *p_intf = (intf_thread_t *)param;
1566 p_intf->p_sys->p_mi->toggleFSC();