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>
74 /* Callback prototypes */
75 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
76 vlc_value_t old_val, vlc_value_t new_val, void *param );
77 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
78 vlc_value_t old_val, vlc_value_t new_val, void *param );
80 MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
82 /* Variables initialisation */
83 // need_components_update = false;
86 playlistWidget = NULL;
90 fullscreenControls = NULL;
95 b_hideAfterCreation = false;
96 playlistVisible = false; // FIXME remove
101 /* Ask for Privacy */
102 new FirstRun( this, p_intf );
105 * Configuration and settings
106 * Pre-building of interface
109 setFocusPolicy( Qt::StrongFocus );
110 setAcceptDrops( true );
111 setWindowRole( "vlc-main" );
112 setWindowIcon( QApplication::windowIcon() );
113 setWindowOpacity( config_GetFloat( p_intf, "qt-opacity" ) );
115 /* Set The Video In emebedded Mode or not */
116 videoEmbeddedFlag = config_GetInt( p_intf, "embedded-video" );
118 /* Does the interface resize to video size or the opposite */
119 b_keep_size = !config_GetInt( p_intf, "qt-video-autoresize" );
121 /* Are we in the enhanced always-video mode or not ? */
122 i_visualmode = config_GetInt( p_intf, "qt-display-mode" );
124 /* Do we want anoying popups or not */
125 notificationEnabled = (bool)config_GetInt( p_intf, "qt-notification" );
127 /* Set the other interface settings */
128 settings = getSettings();
129 settings->beginGroup( "MainWindow" );
132 * Retrieve saved sizes for main window
133 * mainBasedSize = based window size for normal mode
134 * (no video, no background)
135 * mainVideoSize = window size with video (all modes)
137 mainBasedSize = settings->value( "mainBasedSize", QSize( 350, 120 ) ).toSize();
138 mainVideoSize = settings->value( "mainVideoSize", QSize( 400, 300 ) ).toSize();
146 /**************************
147 * UI and Widgets design
148 **************************/
149 setVLCWindowsTitle();
150 createMainWidget( settings );
155 QVLCMenu::createMenuBar( this, p_intf );
156 CONNECT( THEMIM->getIM(), voutListChanged( vout_thread_t **, int ),
157 this, destroyPopupMenu() );
160 /* Create a Dock to get the playlist */
161 dockPL = new QDockWidget( qtr( "Playlist" ), this );
162 dockPL->setSizePolicy( QSizePolicy::Preferred,
163 QSizePolicy::Expanding );
164 dockPL->setFeatures( QDockWidget::AllDockWidgetFeatures );
165 dockPL->setAllowedAreas( Qt::LeftDockWidgetArea
166 | Qt::RightDockWidgetArea
167 | Qt::BottomDockWidgetArea );
171 /*********************************
172 * Create the Systray Management *
173 *********************************/
176 /********************
178 ********************/
179 MainInputManager::getInstance( p_intf );
182 createTaskBarButtons();
185 /************************************************************
186 * Connect the input manager to the GUI elements it manages *
187 ************************************************************/
189 * Connects on nameChanged()
190 * Those connects are different because options can impeach them to trigger.
192 /* Main Interface statusbar */
193 CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
194 this, setName( const QString& ) );
199 CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
200 this, updateSystrayTooltipName( const QString& ) );
203 /* and title of the Main Interface*/
204 if( config_GetInt( p_intf, "qt-name-in-title" ) )
206 CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
207 this, setVLCWindowsTitle( const QString& ) );
211 * CONNECTS on PLAY_STATUS
213 /* Status on the systray */
217 CONNECT( THEMIM->getIM(), statusChanged( int ),
218 this, updateSystrayTooltipStatus( int ) );
222 /* END CONNECTS ON IM */
227 var_AddCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
229 /* Register callback for the intf-popupmenu variable */
230 var_AddCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
233 /* VideoWidget connects for asynchronous calls */
234 connect( this, SIGNAL(askGetVideo(WId*,int*,int*,unsigned*,unsigned *)),
235 this, SLOT(getVideoSlot(WId*,int*,int*,unsigned*,unsigned*)),
236 Qt::BlockingQueuedConnection );
237 connect( this, SIGNAL(askReleaseVideo( void )),
238 this, SLOT(releaseVideoSlot( void )),
239 Qt::BlockingQueuedConnection );
243 CONNECT( this, askVideoToResize( unsigned int, unsigned int ),
244 videoWidget, SetSizing( unsigned int, unsigned int ) );
245 CONNECT( this, askVideoSetFullScreen( bool ),
246 videoWidget, SetFullScreen( bool ) );
247 CONNECT( videoWidget, keyPressed( QKeyEvent * ),
248 this, handleKeyPress( QKeyEvent * ) );
251 CONNECT( this, askUpdate(), this, doComponentsUpdate() );
252 CONNECT( THEDP, toolBarConfUpdated(), this, recreateToolbars() );
254 /* Enable the popup menu in the MI */
255 setContextMenuPolicy( Qt::CustomContextMenu );
256 CONNECT( this, customContextMenuRequested( const QPoint& ),
257 this, popupMenu( const QPoint& ) );
259 /** END of CONNECTS**/
262 /**** FINAL SIZING and placement of interface */
263 settings->beginGroup( "MainWindow" );
264 QVLCTools::restoreWidgetPosition( settings, this, QSize(380, 60) );
266 /* resize to previously saved main window size if appicable */
269 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
270 i_visualmode == QT_MINIMAL_MODE )
272 resize( mainVideoSize );
276 resize( mainBasedSize );
280 msg_Dbg( p_intf, "%i", stackCentralOldState );
282 if( settings->value( "playlist-visible", 0 ).toInt() )
284 settings->endGroup();
286 /* Final sizing and showing */
287 setVisible( !b_hideAfterCreation );
288 //setMinimumSize( QSize( 0, 0 ) );
289 // setMinimumWidth( __MAX( controls->sizeHint().width(),
290 // menuBar()->sizeHint().width() ) );
293 /* And switch to minimal view if needed
294 Must be called after the show() */
295 if( i_visualmode == QT_MINIMAL_MODE )
296 toggleMinimalView( true );
298 /* Update the geometry : It is useful if you switch between
301 resize( sizeHint() );
305 MainInterface::~MainInterface()
307 msg_Dbg( p_intf, "Destroying the main interface" );
309 /* Unsure we hide the videoWidget before destroying it */
310 if( stackCentralOldState == VIDEO_TAB )
313 /* Save playlist state */
317 QVLCTools::saveWidgetPosition( p_intf, "Playlist", playlistWidget );
319 delete playlistWidget;
324 ImageList_Destroy( himl );
326 p_taskbl->vt->Release(p_taskbl);
330 /* Be sure to kill the actionsManager... FIXME */
331 ActionsManager::killInstance();
333 /* Delete the FSC controller */
334 delete fullscreenControls;
337 settings->beginGroup( "MainWindow" );
338 settings->setValue( "pl-dock-status", (int)i_pl_dock );
339 settings->setValue( "playlist-visible", (int)playlistVisible );
340 settings->setValue( "adv-controls",
341 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
343 settings->setValue( "mainBasedSize", mainBasedSize );
344 settings->setValue( "mainVideoSize", mainVideoSize );
347 settings->setValue( "backgroundSize", bgWidget->size() );
350 QVLCTools::saveWidgetPosition(settings, this);
351 settings->endGroup();
353 /* Unregister callbacks */
354 var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
355 var_DelCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
357 p_intf->p_sys->p_mi = NULL;
360 /*****************************
362 *****************************/
363 void MainInterface::recreateToolbars()
365 msg_Dbg( p_intf, "Recreating the toolbars" );
366 settings->beginGroup( "MainWindow" );
369 controls = new ControlsWidget( p_intf, false, this ); /* FIXME */
370 CONNECT( controls, advancedControlsToggled( bool ),
371 this, doComponentsUpdate() );
372 CONNECT( controls, sizeChanged(),
373 this, doComponentsUpdate() );
374 inputC = new InputControlsWidget( p_intf, this );
376 mainLayout->insertWidget( 2, inputC );
377 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
379 settings->endGroup();
382 void MainInterface::createMainWidget( QSettings *settings )
384 /* Create the main Widget and the mainLayout */
385 QWidget *main = new QWidget;
386 setCentralWidget( main );
387 mainLayout = new QVBoxLayout( main );
389 /* Margins, spacing */
390 main->setContentsMargins( 0, 0, 0, 0 );
391 mainLayout->setSpacing( 0 );
392 mainLayout->setMargin( 0 );
395 stackCentralW = new QStackedWidget( main );
398 bgWidget = new BackgroundWidget( p_intf );
400 settings->value( "backgroundSize", QSize( 300, 200 ) ).toSize() );
401 bgWidget->updateGeometry();
402 stackCentralW->insertWidget( BACKG_TAB, bgWidget );
405 /* And video Outputs */
406 if( videoEmbeddedFlag )
408 videoWidget = new VideoWidget( p_intf );
409 stackCentralW->insertWidget( VIDEO_TAB, videoWidget );
411 mainLayout->insertWidget( 1, stackCentralW, 100 );
414 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
415 i_visualmode != QT_MINIMAL_MODE )
418 stackCentralOldState = HIDDEN_TAB;
422 showTab( BACKG_TAB );
423 stackCentralOldState = BACKG_TAB;
426 /* Create the CONTROLS Widget */
427 controls = new ControlsWidget( p_intf,
428 settings->value( "adv-controls", false ).toBool(), this );
429 CONNECT( controls, advancedControlsToggled( bool ),
430 this, doComponentsUpdate() );
431 CONNECT( controls, sizeChanged(),
432 this, doComponentsUpdate() );
433 inputC = new InputControlsWidget( p_intf, this );
435 //mainLayout->setRowStretch( 1, 10 );
436 mainLayout->insertWidget( 2, inputC );
437 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
441 /* Disabled for now, they SUCK */
443 visualSelector = new VisualSelector( p_intf );
444 mainLayout->insertWidget( 0, visualSelector );
445 visualSelector->hide();
448 /* Finish the sizing */
449 main->updateGeometry();
451 getSettings()->endGroup();
455 /* Create the FULLSCREEN CONTROLS Widget */
456 if( config_GetInt( p_intf, "qt-fs-controller" ) )
458 fullscreenControls = new FullscreenControllerWidget( p_intf, this );
459 CONNECT( fullscreenControls, keyPressed( QKeyEvent * ),
460 this, handleKeyPress( QKeyEvent * ) );
464 inline void MainInterface::initSystray()
467 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
468 bool b_systrayWanted = config_GetInt( p_intf, "qt-system-tray" );
470 if( config_GetInt( p_intf, "qt-start-minimized") > 0 )
472 if( b_systrayAvailable )
474 b_systrayWanted = true;
475 b_hideAfterCreation = true;
478 msg_Err( p_intf, "cannot start minimized without system tray bar" );
481 if( b_systrayAvailable && b_systrayWanted )
486 inline void MainInterface::createStatusBar()
491 /* Widgets Creation*/
492 QStatusBar *statusBarr = statusBar();
494 TimeLabel *timeLabel = new TimeLabel( p_intf );
495 nameLabel = new QLabel( this );
496 nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
497 | Qt::TextSelectableByKeyboard );
498 SpeedLabel *speedLabel = new SpeedLabel( p_intf, "1.00x", this );
500 /* Styling those labels */
501 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
502 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
503 nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
505 /* and adding those */
506 statusBarr->addWidget( nameLabel, 8 );
507 statusBarr->addPermanentWidget( speedLabel, 0 );
508 statusBarr->addPermanentWidget( timeLabel, 0 );
510 /* timeLabel behaviour:
511 - double clicking opens the goto time dialog
512 - right-clicking and clicking just toggle between remaining and
514 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
516 CONNECT( THEMIM->getIM(), encryptionChanged( bool ),
517 this, showCryptedLabel( bool ) );
521 void MainInterface::createTaskBarButtons()
523 /*Here is the code for the taskbar thumb buttons
524 FIXME:We need pretty buttons in 16x16 px that are handled correctly by masks in Qt
525 FIXME:the play button's picture doesn't changed to pause when clicked
527 OSVERSIONINFO winVer;
528 winVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
529 if( GetVersionEx(&winVer) && winVer.dwMajorVersion > 5 )
531 if(himl = ImageList_Create( 15, //cx
534 4,//initial nb of images
535 0//nb of images that can be added
538 QPixmap img = QPixmap(":/toolbar/previous_b");
539 QPixmap img2 = QPixmap(":/toolbar/pause_b");
540 QPixmap img3 = QPixmap(":/toolbar/play_b");
541 QPixmap img4 = QPixmap(":/toolbar/next_b");
542 QBitmap mask = img.createMaskFromColor(Qt::transparent);
543 QBitmap mask2 = img2.createMaskFromColor(Qt::transparent);
544 QBitmap mask3 = img3.createMaskFromColor(Qt::transparent);
545 QBitmap mask4 = img4.createMaskFromColor(Qt::transparent);
547 if(-1 == ImageList_Add(himl, img.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask.toWinHBITMAP()))
548 msg_Err( p_intf, "ImageList_Add failed" );
549 if(-1 == ImageList_Add(himl, img2.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask2.toWinHBITMAP()))
550 msg_Err( p_intf, "ImageList_Add failed" );
551 if(-1 == ImageList_Add(himl, img3.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask3.toWinHBITMAP()))
552 msg_Err( p_intf, "ImageList_Add failed" );
553 if(-1 == ImageList_Add(himl, img4.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask4.toWinHBITMAP()))
554 msg_Err( p_intf, "ImageList_Add failed" );
559 if( S_OK == CoCreateInstance( &clsid_ITaskbarList,
560 NULL, CLSCTX_INPROC_SERVER,
562 (void **)&p_taskbl) )
564 p_taskbl->vt->HrInit(p_taskbl);
566 int msg_value = RegisterWindowMessage("TaskbarButtonCreated");
567 //msg_Info( p_intf, "msg value: %04x", msg_value );
569 // Define an array of two buttons. These buttons provide images through an
570 // image list and also provide tooltips.
571 DWORD dwMask = THB_BITMAP | THB_FLAGS;
573 THUMBBUTTON thbButtons[2];
574 thbButtons[0].dwMask = dwMask;
575 thbButtons[0].iId = 0;
576 thbButtons[0].iBitmap = 0;
577 thbButtons[0].dwFlags = THBF_HIDDEN;
579 thbButtons[1].dwMask = dwMask;
580 thbButtons[1].iId = 1;
581 thbButtons[1].iBitmap = 2;
582 thbButtons[1].dwFlags = THBF_HIDDEN;
584 thbButtons[2].dwMask = dwMask;
585 thbButtons[2].iId = 2;
586 thbButtons[2].iBitmap = 3;
587 thbButtons[2].dwFlags = THBF_HIDDEN;
589 HRESULT hr = p_taskbl->vt->ThumbBarSetImageList(p_taskbl, GetForegroundWindow(), himl );
591 msg_Err( p_intf, "ThumbBarSetImageList failed with error %08x", hr );
592 if(S_OK != p_taskbl->vt->ThumbBarAddButtons(p_taskbl, GetForegroundWindow(), 3, thbButtons))
593 msg_Err( p_intf, "ThumbBarAddButtons failed with error %08x", GetLastError() );
595 CONNECT( THEMIM->getIM(), statusChanged( int ), this, changeThumbbarButtons( int ) );
609 /**********************************************************************
610 * Handling of sizing of the components
611 **********************************************************************/
613 /* This function is probably wrong, but we don't have many many choices...
614 Since we can't know from the playlist Widget if we are inside a dock or not,
615 because the playlist Widget can be called by THEDP, as a separate windows for
617 Maybe the other solution is to redefine the sizeHint() of the playlist and
618 ask _parent->isFloating()...
619 If you think this would be better, please FIXME it...
622 QSize MainInterface::sizeHint() const
627 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
628 i_visualmode == QT_MINIMAL_MODE )
630 return mainVideoSize;
634 if( VISIBLE( bgWidget) ||
635 ( videoIsActive && videoWidget->isVisible() )
637 return mainVideoSize;
639 return mainBasedSize;
644 int nwidth = __MAX( controls->sizeHint().width(),
645 menuBar()->sizeHint().width() );
647 int nheight = controls->isVisible() ?
648 controls->size().height()
649 + inputC->size().height()
650 + menuBar()->size().height()
651 + statusBar()->size().height()
654 if( stackCentralW->isVisible() )
655 nheight += stackCentralW->height();
656 nwidth = __MAX( nwidth, stackCentralW->width() );
658 /* if( VISIBLE( bgWidget ) )
660 msg_Warn( p_intf, "Hello here" );
662 nheight += i_bg_height;
664 nheight += bgWidget->size().height();
665 nwidth = __MAX( nwidth, bgWidget->size().width() );
667 else if( videoIsActive && videoWidget->isVisible() )
669 msg_Warn( p_intf, "Hello there" );
670 nheight += videoWidget->sizeHint().height();
671 nwidth = __MAX( nwidth, videoWidget->sizeHint().width() );
674 if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget() )
676 nheight += dockPL->size().height();
677 nwidth = __MAX( nwidth, dockPL->size().width() );
678 msg_Warn( p_intf, "3 %i %i", nheight, nwidth );
681 return QSize( nwidth, nheight );
685 /* Video widget cannot do this synchronously as it runs in another thread */
686 /* Well, could it, actually ? Probably dangerous ... */
688 /* This function is called:
689 - toggling of minimal View
690 - through askUpdate() by Vout thread request video and resize video (zoom)
691 - Advanced buttons toggled
693 void MainInterface::doComponentsUpdate()
695 if( isFullScreen() || isMaximized() ) return;
697 msg_Warn( p_intf, "Updating the geometry" );
698 /* Here we resize to sizeHint() and not adjustsize because we want
699 the videoWidget to be exactly the correctSize */
704 /* This is WRONG, but I believe there is a Qt bug here */
705 setMinimumSize( 0, 0 );
706 resize( sizeHint() );
708 //adjustSize() ; /* This is not needed, but might help in the future */
711 void MainInterface::debug()
714 msg_Dbg( p_intf, "Stack Size: %i - %i", stackCentralW->size().height(), size().width() );
715 msg_Dbg( p_intf, "Stack Size: %i - %i", stackCentralW->widget( VIDEO_TAB )->size().height(), stackCentralW->widget( VIDEO_TAB )->size().width() );
717 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
718 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
719 //msg_Dbg( p_intf, "maximumsize: %i - %i", maximumSize().height(), maximumSize().width() );
721 msg_Dbg( p_intf, "Stack minimumsize: %i - %i", stackCentralW->minimumSize().height(), stackCentralW->minimumSize().width() );
722 msg_Dbg( p_intf, "Controls minimumsize: %i - %i", controls->minimumSize().height(), controls->minimumSize().width() );
723 msg_Dbg( p_intf, "Central minimumsize: %i - %i", centralWidget()->minimumSize().height(), centralWidget()->minimumSize().width() );
724 msg_Dbg( p_intf, "Menu minimumsize: %i - %i", menuBar()->minimumSize().height(), menuBar()->minimumSize().width() );
725 msg_Dbg( p_intf, "Input minimuSize: %i - %i", inputC->minimumSize().height(), inputC->minimumSize().width() );
726 msg_Dbg( p_intf, "Status minimumsize: %i - %i", statusBar()->minimumSize().height(), statusBar()->minimumSize().width() );
727 msg_Dbg( p_intf, "minimumsize: %i - %i", minimumSize().height(), minimumSize().width() );
729 /*if( videoWidget && videoWidget->isVisible() )
731 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
732 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
737 inline void MainInterface::showTab( int i_tab )
739 msg_Warn( p_intf, "stackCentralOldState %i", stackCentralOldState );
740 stackCentralOldState = stackCentralW->isVisible() ? stackCentralW->currentIndex()
742 msg_Dbg( p_intf, "State chnage %i", stackCentralW->currentIndex() );
744 if( i_visualmode == QT_NORMAL_MODE )
746 stackCentralW->setVisible( i_tab != HIDDEN_TAB );
749 if( i_tab == HIDDEN_TAB ) i_tab == BACKG_TAB;
751 stackCentralW->setCurrentIndex( i_tab );
754 inline void MainInterface::restoreStackOldWidget()
756 msg_Warn( p_intf, "stackCentralOldState %i", stackCentralOldState );
757 int temp = stackCentralW->isVisible() ? stackCentralW->currentIndex()
759 stackCentralW->setCurrentIndex( stackCentralOldState );
760 if( i_visualmode == QT_NORMAL_MODE )
761 stackCentralW->setVisible( stackCentralOldState != HIDDEN_TAB );
763 stackCentralOldState = temp;
764 msg_Dbg( p_intf, "Here %i %i", temp, stackCentralW->currentIndex() );
768 void MainInterface::destroyPopupMenu()
770 QVLCMenu::PopupMenu( p_intf, false );
773 void MainInterface::toggleFSC()
775 if( !fullscreenControls ) return;
777 IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
778 QApplication::postEvent( fullscreenControls, eShow );
781 void MainInterface::popupMenu( const QPoint &p )
783 /* Ow, that's ugly: don't show the popup menu if cursor over
784 * the main menu bar or the status bar */
785 if( !childAt( p ) || ( ( childAt( p ) != menuBar() )
786 && ( childAt( p )->parentWidget() != statusBar() ) ) )
787 QVLCMenu::PopupMenu( p_intf, true );
790 /****************************************************************************
792 ****************************************************************************/
794 /* This event is used to deal with the fullscreen and always on top
795 issue conflict (bug in wx) */
796 class SetVideoOnTopQtEvent : public QEvent
799 SetVideoOnTopQtEvent( bool _onTop ) :
800 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
803 bool OnTop() const { return onTop; }
811 * You must note change the state of this object or other Qt4 UI objects,
812 * from the video output thread - only from the Qt4 UI main loop thread.
813 * All window provider queries must be handled through signals or events.
814 * That's why we have all those emit statements...
816 WId MainInterface::getVideo( int *pi_x, int *pi_y,
817 unsigned int *pi_width, unsigned int *pi_height )
822 /* This is a blocking call signal. Results are returned through pointers.
823 * Beware of deadlocks! */
825 emit askGetVideo( &id, pi_x, pi_y, pi_width, pi_height );
829 void MainInterface::getVideoSlot( WId *p_id, int *pi_x, int *pi_y,
830 unsigned *pi_width, unsigned *pi_height )
832 /* Request the videoWidget */
833 WId ret = videoWidget->request( pi_x, pi_y,
834 pi_width, pi_height, b_keep_size );
836 if( ret ) /* The videoWidget is available */
838 /* ask videoWidget to show */
839 videoWidget->SetSizing( *pi_width, *pi_height );
841 /* Consider the video active now */
844 stackCentralW->resize( *pi_width, *pi_height );
852 /* Asynchronous call from the WindowClose function */
853 void MainInterface::releaseVideo( void )
855 emit askReleaseVideo( );
858 /* Function that is CONNECTED to the previous emit */
859 void MainInterface::releaseVideoSlot( void )
861 videoWidget->release( );
863 restoreStackOldWidget();
865 /* Try to resize, except when you are in Fullscreen mode */
866 // doComponentsUpdate();
869 /* Asynchronous call from WindowControl function */
870 int MainInterface::controlVideo( int i_query, va_list args )
872 /* Debug to check if VOUT_WINDOW_SET_SIZE is called, because this is broken now */
873 msg_Warn( p_intf, "Control Video: %i", i_query );
876 case VOUT_WINDOW_SET_SIZE:
878 unsigned int i_width = va_arg( args, unsigned int );
879 unsigned int i_height = va_arg( args, unsigned int );
880 emit askVideoToResize( i_width, i_height );
884 case VOUT_WINDOW_SET_ON_TOP:
886 int i_arg = va_arg( args, int );
887 QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
890 case VOUT_WINDOW_SET_FULLSCREEN:
892 bool b_fs = va_arg( args, int );
893 emit askVideoSetFullScreen( b_fs );
897 msg_Warn( p_intf, "unsupported control query" );
902 /*****************************************************************************
903 * Playlist, Visualisation and Menus handling
904 *****************************************************************************/
906 * Toggle the playlist widget or dialog
908 void MainInterface::createPlaylist( bool b_show )
910 playlistWidget = new PlaylistWidget( p_intf );
912 i_pl_dock = PL_BOTTOM;
913 /* i_pl_dock = (pl_dock_e)getSettings()
914 ->value( "pl-dock-status", PL_UNDOCKED ).toInt(); */
916 if( i_pl_dock == PL_UNDOCKED )
918 playlistWidget->setWindowFlags( Qt::Window );
920 /* This will restore the geometry but will not work for position,
921 because of parenting */
922 QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
923 playlistWidget, QSize( 600, 300 ) );
927 msg_Warn( p_intf, "Here 12 %i", stackCentralW->currentIndex() );
928 stackCentralW->insertWidget( PLAYL_TAB, playlistWidget );
929 msg_Warn( p_intf, "Here 12 %i", stackCentralW->currentIndex() );
934 playlistVisible = true;
935 stackCentralW->show();
939 void MainInterface::togglePlaylist()
941 msg_Warn( p_intf, "Here toggling %i %i", stackCentralW->currentIndex(), stackCentralOldState );
942 if( !playlistWidget )
944 createPlaylist( true );
946 msg_Warn( p_intf, "Here toggling %i %i", stackCentralW->currentIndex(), stackCentralOldState );
948 if( i_pl_dock != PL_UNDOCKED )
950 /* Playlist not visible */
951 if( stackCentralW->currentIndex() != PLAYL_TAB )
953 msg_Warn( p_intf, "Here 42" );
954 showTab( PLAYL_TAB );
955 stackCentralW->show();
959 restoreStackOldWidget();
961 playlistVisible = ( stackCentralW->currentIndex() == PLAYL_TAB );
962 //doComponentsUpdate(); //resize( sizeHint() );
966 /* Function called from the menu to undock the playlist */
967 void MainInterface::undockPlaylist()
969 // dockPL->setFloating( true );
973 void MainInterface::dockPlaylist( pl_dock_e i_pos )
977 void MainInterface::toggleMinimalView( bool b_switch )
979 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
980 i_visualmode != QT_MINIMAL_MODE )
981 { /* NORMAL MODE then */
982 stackCentralW->show();
983 if( !videoWidget || stackCentralW->currentIndex() != VIDEO_TAB )
989 /* If video is visible, then toggle the status of bgWidget */
990 //bgWasVisible = !bgWasVisible;
991 if( stackCentralOldState == BACKG_TAB )
992 stackCentralOldState = HIDDEN_TAB;
994 stackCentralOldState = BACKG_TAB;
998 i_bg_height = stackCentralW->height();
1000 menuBar()->setVisible( !b_switch );
1001 controls->setVisible( !b_switch );
1002 statusBar()->setVisible( !b_switch );
1003 inputC->setVisible( !b_switch );
1005 doComponentsUpdate();
1007 emit minimalViewToggled( b_switch );
1010 /* toggling advanced controls buttons */
1011 void MainInterface::toggleAdvanced()
1013 controls->toggleAdvanced();
1014 // if( fullscreenControls ) fullscreenControls->toggleAdvanced();
1017 /* Get the visibility status of the controls (hidden or not, advanced or not) */
1018 int MainInterface::getControlsVisibilityStatus()
1020 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
1021 + CONTROLS_ADVANCED * controls->b_advancedVisible );
1025 void MainInterface::visual()
1027 if( !VISIBLE( visualSelector) )
1029 visualSelector->show();
1030 if( !THEMIM->getIM()->hasVideo() )
1032 /* Show the background widget */
1034 visualSelectorEnabled = true;
1038 /* Stop any currently running visualization */
1039 visualSelector->hide();
1040 visualSelectorEnabled = false;
1042 doComponentsUpdate();
1046 /************************************************************************
1048 ************************************************************************/
1049 void MainInterface::setName( const QString& name )
1051 input_name = name; /* store it for the QSystray use */
1052 /* Display it in the status bar, but also as a Tooltip in case it doesn't
1054 nameLabel->setText( " " + name + " " );
1055 nameLabel->setToolTip( " " + name +" " );
1059 * Give the decorations of the Main Window a correct Name.
1060 * If nothing is given, set it to VLC...
1062 void MainInterface::setVLCWindowsTitle( const QString& aTitle )
1064 if( aTitle.isEmpty() )
1066 setWindowTitle( qtr( "VLC media player" ) );
1070 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
1074 void MainInterface::showCryptedLabel( bool b_show )
1076 if( cryptedLabel == NULL )
1078 cryptedLabel = new QLabel;
1079 // The lock icon is not the right one for DRM protection/scrambled.
1080 //cryptedLabel->setPixmap( QPixmap( ":/lock" ) );
1081 cryptedLabel->setText( "DRM" );
1082 statusBar()->addWidget( cryptedLabel );
1085 cryptedLabel->setVisible( b_show );
1088 /*****************************************************************************
1089 * Systray Icon and Systray Menu
1090 *****************************************************************************/
1093 * Create a SystemTray icon and a menu that would go with it.
1094 * Connects to a click handler on the icon.
1096 void MainInterface::createSystray()
1099 if( QDate::currentDate().dayOfYear() >= 354 )
1100 iconVLC = QIcon( ":/logo/vlc128-christmas.png" );
1102 iconVLC = QIcon( ":/logo/vlc128.png" );
1103 sysTray = new QSystemTrayIcon( iconVLC, this );
1104 sysTray->setToolTip( qtr( "VLC media player" ));
1106 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
1107 systrayMenu->setIcon( iconVLC );
1109 QVLCMenu::updateSystrayMenu( this, p_intf, true );
1112 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
1113 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
1117 * Updates the Systray Icon's menu and toggle the main interface
1119 void MainInterface::toggleUpdateSystrayMenu()
1121 /* If hidden, show it */
1127 else if( isMinimized() )
1135 /* Visible (possibly under other windows) */
1137 /* check if any visible window is above vlc in the z-order,
1138 * but ignore the ones always on top
1139 * and the ones which can't be activated */
1142 wi.cbSize = sizeof( WINDOWINFO );
1143 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
1144 hwnd && ( !IsWindowVisible( hwnd ) ||
1145 ( GetWindowInfo( hwnd, &wi ) &&
1146 (wi.dwExStyle&WS_EX_NOACTIVATE) ) );
1147 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
1148 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
1149 (wi.dwExStyle&WS_EX_TOPMOST) )
1161 QVLCMenu::updateSystrayMenu( this, p_intf );
1164 void MainInterface::handleSystrayClick(
1165 QSystemTrayIcon::ActivationReason reason )
1169 case QSystemTrayIcon::Trigger:
1170 case QSystemTrayIcon::DoubleClick:
1171 toggleUpdateSystrayMenu();
1173 case QSystemTrayIcon::MiddleClick:
1174 sysTray->showMessage( qtr( "VLC media player" ),
1175 qtr( "Control menu for the player" ),
1176 QSystemTrayIcon::Information, 3000 );
1184 * Updates the name of the systray Icon tooltip.
1185 * Doesn't check if the systray exists, check before you call it.
1187 void MainInterface::updateSystrayTooltipName( const QString& name )
1189 if( name.isEmpty() )
1191 sysTray->setToolTip( qtr( "VLC media player" ) );
1195 sysTray->setToolTip( name );
1196 if( notificationEnabled && ( isHidden() || isMinimized() ) )
1198 sysTray->showMessage( qtr( "VLC media player" ), name,
1199 QSystemTrayIcon::NoIcon, 3000 );
1203 QVLCMenu::updateSystrayMenu( this, p_intf );
1207 * Updates the status of the systray Icon tooltip.
1208 * Doesn't check if the systray exists, check before you call it.
1210 void MainInterface::updateSystrayTooltipStatus( int i_status )
1217 sysTray->setToolTip( qtr( "VLC media player" ) );
1222 sysTray->setToolTip( input_name );
1227 sysTray->setToolTip( input_name + " - "
1232 QVLCMenu::updateSystrayMenu( this, p_intf );
1236 /************************************************************************
1238 ************************************************************************/
1239 void MainInterface::dropEvent(QDropEvent *event)
1241 dropEventPlay( event, true );
1244 void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
1246 event->setDropAction( Qt::CopyAction );
1247 if( !event->possibleActions() & Qt::CopyAction )
1250 const QMimeData *mimeData = event->mimeData();
1252 /* D&D of a subtitles file, add it on the fly */
1253 if( mimeData->urls().size() == 1 && THEMIM->getIM()->hasInput() )
1255 if( !input_AddSubtitle( THEMIM->getInput(),
1256 qtu( toNativeSeparators( mimeData->urls()[0].toLocalFile() ) ),
1264 bool first = b_play;
1265 foreach( const QUrl &url, mimeData->urls() )
1267 QString s = toNativeSeparators( url.toLocalFile() );
1269 if( s.length() > 0 ) {
1270 char* psz_uri = make_URI( qtu(s) );
1271 playlist_Add( THEPL, psz_uri, NULL,
1272 PLAYLIST_APPEND | (first ? PLAYLIST_GO: PLAYLIST_PREPARSE),
1273 PLAYLIST_END, true, pl_Unlocked );
1276 RecentsMRL::getInstance( p_intf )->addRecent( s );
1281 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1283 event->acceptProposedAction();
1285 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1287 event->acceptProposedAction();
1289 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1294 /************************************************************************
1296 ************************************************************************/
1297 void MainInterface::customEvent( QEvent *event )
1300 if( event->type() == PLDockEvent_Type )
1302 PlaylistDialog::killInstance();
1303 playlistEmbeddedFlag = true;
1305 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1310 if ( event->type() == (int)SetVideoOnTopEvent_Type )
1312 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1313 if( p_event->OnTop() )
1314 setWindowFlags( windowFlags() | Qt::WindowStaysOnTopHint );
1316 setWindowFlags( windowFlags() & ~Qt::WindowStaysOnTopHint );
1317 show(); /* necessary to apply window flags */
1321 void MainInterface::keyPressEvent( QKeyEvent *e )
1323 handleKeyPress( e );
1326 void MainInterface::handleKeyPress( QKeyEvent *e )
1328 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() == Qt::Key_H )
1329 && !menuBar()->isVisible() )
1331 toggleMinimalView( false );
1335 int i_vlck = qtEventToVLCKey( e );
1338 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1345 void MainInterface::resizeEvent( QResizeEvent * event )
1350 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
1351 i_visualmode == QT_MINIMAL_MODE )
1353 mainVideoSize = size();
1357 if( VISIBLE( bgWidget) ||
1358 ( videoIsActive && videoWidget->isVisible() )
1360 mainVideoSize = size();
1362 mainBasedSize = size();
1366 QVLCMW::resizeEvent( event );
1367 msg_Dbg( p_intf, "Resize Event, height: %i", size().height() );
1370 void MainInterface::wheelEvent( QWheelEvent *e )
1372 int i_vlckey = qtWheelEventToVLCKey( e );
1373 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1377 void MainInterface::closeEvent( QCloseEvent *e )
1384 void MainInterface::toggleFullScreen( void )
1386 if( isFullScreen() )
1389 emit askUpdate(); // Needed if video was launched after the F11
1390 emit fullscreenInterfaceToggled( false );
1395 emit fullscreenInterfaceToggled( true );
1400 //moc doesn't know about #ifdef, so we have to build this method for every platform
1401 void MainInterface::changeThumbbarButtons( int i_status)
1404 // Define an array of two buttons. These buttons provide images through an
1405 // image list and also provide tooltips.
1406 DWORD dwMask = THB_BITMAP | THB_FLAGS;
1408 THUMBBUTTON thbButtons[3];
1410 thbButtons[0].dwMask = dwMask;
1411 thbButtons[0].iId = 0;
1412 thbButtons[0].iBitmap = 0;
1415 thbButtons[1].dwMask = dwMask;
1416 thbButtons[1].iId = 1;
1419 thbButtons[2].dwMask = dwMask;
1420 thbButtons[2].iId = 2;
1421 thbButtons[2].iBitmap = 3;
1428 thbButtons[0].dwFlags = THBF_HIDDEN;
1429 thbButtons[1].dwFlags = THBF_HIDDEN;
1430 thbButtons[2].dwFlags = THBF_HIDDEN;
1435 thbButtons[0].dwFlags = THBF_ENABLED;
1436 thbButtons[1].dwFlags = THBF_ENABLED;
1437 thbButtons[2].dwFlags = THBF_ENABLED;
1438 thbButtons[1].iBitmap = 1;
1443 //thbButtons[0].dwFlags = THBF_ENABLED;
1444 //thbButtons[1].dwFlags = THBF_ENABLED;
1445 //thbButtons[2].dwFlags = THBF_ENABLED;
1446 thbButtons[1].iBitmap = 2;
1451 HRESULT hr = p_taskbl->vt->ThumbBarUpdateButtons(p_taskbl, GetForegroundWindow(), 3, thbButtons);
1453 msg_Err( p_intf, "ThumbBarUpdateButtons failed with error %08x", hr );
1459 /*****************************************************************************
1460 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1461 * We don't show the menu directly here because we don't want the
1462 * caller to block for a too long time.
1463 *****************************************************************************/
1464 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1465 vlc_value_t old_val, vlc_value_t new_val, void *param )
1467 intf_thread_t *p_intf = (intf_thread_t *)param;
1469 if( p_intf->pf_show_dialog )
1471 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1472 new_val.b_bool, NULL );
1478 /*****************************************************************************
1479 * IntfShowCB: callback triggered by the intf-show libvlc variable.
1480 *****************************************************************************/
1481 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1482 vlc_value_t old_val, vlc_value_t new_val, void *param )
1484 intf_thread_t *p_intf = (intf_thread_t *)param;
1485 p_intf->p_sys->p_mi->toggleFSC();