1 /*****************************************************************************
2 * main_interface.cpp : Main interface
3 ****************************************************************************
4 * Copyright (C) 2006-2010 VideoLAN and AUTHORS
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 Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
27 - playlist minimumSize applies to all stackWidgets
35 #include "main_interface.hpp"
36 #include "input_manager.hpp" // Creation
37 #include "actions_manager.hpp" // killInstance
38 #include "extensions_manager.hpp" // killInstance
40 #include "util/customwidgets.hpp" // qtEventToVLCKey
41 #include "util/qt_dirs.hpp" // toNativeSeparators
43 #include "components/interface_widgets.hpp" // bgWidget, videoWidget
44 #include "components/controller.hpp" // controllers
45 #include "components/playlist/playlist.hpp" // plWidget
46 #include "dialogs/firstrun.hpp" // First Run
48 #include "menus.hpp" // Menu creation
49 #include "recents.hpp" // RecentItems when DnD
51 #include <QCloseEvent>
62 #include <QStackedWidget>
64 #include <vlc_keys.h> /* Wheel event */
65 #include <vlc_vout_display.h> /* vout_thread_t and VOUT_ events */
67 #ifdef WIN32 /* Win7 taskbar */
68 #include <vlc_windows_interfaces.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 */
85 playlistWidget = NULL;
89 fullscreenControls = NULL;
94 b_hideAfterCreation = false; // --qt-start-minimized
95 playlistVisible = false; // FIXME remove
100 /* Ask for Privacy */
101 FirstRun::CheckAndRun( this, p_intf );
104 * Configuration and settings
105 * Pre-building of interface
108 setFocusPolicy( Qt::StrongFocus );
109 setAcceptDrops( true );
110 setWindowRole( "vlc-main" );
111 setWindowIcon( QApplication::windowIcon() );
112 setWindowOpacity( var_InheritFloat( p_intf, "qt-opacity" ) );
114 /* Is video in embedded in the UI or not */
115 b_videoEmbedded = var_InheritBool( p_intf, "embedded-video" );
117 /* Does the interface resize to video size or the opposite */
118 b_keep_size = !var_InheritBool( p_intf, "qt-video-autoresize" );
120 /* Are we in the enhanced always-video mode or not ? */
121 i_visualmode = var_InheritInteger( p_intf, "qt-minimal-view" );
123 /* Do we want anoying popups or not */
124 b_notificationEnabled = var_InheritBool( p_intf, "qt-notification" );
126 /* Set the other interface settings */
127 settings = getSettings();
128 settings->beginGroup( "MainWindow" );
131 b_plDocked = getSettings()->value( "pl-dock-status", true ).toBool();
135 * Retrieve saved sizes for main window
136 * mainBasedSize = based window size for normal mode
137 * (no video, no background)
138 * mainVideoSize = window size with video (all modes)
140 mainBasedSize = settings->value( "mainBasedSize", QSize( 350, 120 ) ).toSize();
141 mainVideoSize = settings->value( "mainVideoSize", QSize( 400, 300 ) ).toSize();
149 /**************************
150 * UI and Widgets design
151 **************************/
152 setVLCWindowsTitle();
153 createMainWidget( settings );
158 QVLCMenu::createMenuBar( this, p_intf );
159 CONNECT( THEMIM->getIM(), voutListChanged( vout_thread_t **, int ),
160 this, destroyPopupMenu() );
162 /*********************************
163 * Create the Systray Management *
164 *********************************/
167 /********************
169 ********************/
170 MainInputManager::getInstance( p_intf );
175 taskbar_wmsg = RegisterWindowMessage("TaskbarButtonCreated");
178 /************************************************************
179 * Connect the input manager to the GUI elements it manages *
180 ************************************************************/
182 * Connects on nameChanged()
183 * Those connects are different because options can impeach them to trigger.
185 /* Main Interface statusbar */
186 CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
187 this, setName( const QString& ) );
192 CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
193 this, updateSystrayTooltipName( const QString& ) );
196 /* and title of the Main Interface*/
197 if( var_InheritBool( p_intf, "qt-name-in-title" ) )
199 CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
200 this, setVLCWindowsTitle( const QString& ) );
204 * CONNECTS on PLAY_STATUS
206 /* Status on the systray */
210 CONNECT( THEMIM->getIM(), statusChanged( int ),
211 this, updateSystrayTooltipStatus( int ) );
215 /* END CONNECTS ON IM */
217 /* VideoWidget connects for asynchronous calls */
218 connect( this, SIGNAL(askGetVideo(WId*,int*,int*,unsigned*,unsigned *)),
219 this, SLOT(getVideoSlot(WId*,int*,int*,unsigned*,unsigned*)),
220 Qt::BlockingQueuedConnection );
221 connect( this, SIGNAL(askReleaseVideo( void )),
222 this, SLOT(releaseVideoSlot( void )),
223 Qt::BlockingQueuedConnection );
227 CONNECT( this, askVideoToResize( unsigned int, unsigned int ),
228 videoWidget, SetSizing( unsigned int, unsigned int ) );
229 CONNECT( this, askVideoSetFullScreen( bool ),
230 videoWidget, SetFullScreen( bool ) );
231 CONNECT( videoWidget, keyPressed( QKeyEvent * ),
232 this, handleKeyPress( QKeyEvent * ) );
235 CONNECT( this, askUpdate(), this, doComponentsUpdate() );
236 CONNECT( THEDP, toolBarConfUpdated(), this, recreateToolbars() );
238 /* Enable the popup menu in the MI */
239 setContextMenuPolicy( Qt::CustomContextMenu );
240 CONNECT( this, customContextMenuRequested( const QPoint& ),
241 this, popupMenu( const QPoint& ) );
243 /** END of CONNECTS**/
249 var_AddCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
251 /* Register callback for the intf-popupmenu variable */
252 var_AddCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
255 /**** FINAL SIZING and placement of interface */
256 settings->beginGroup( "MainWindow" );
257 QVLCTools::restoreWidgetPosition( settings, this, QSize(400, 100) );
259 /* resize to previously saved main window size if appicable */
264 resize( mainVideoSize );
266 resize( mainBasedSize );
270 int i_plVis = settings->value( "playlist-visible", 0 ).toInt();
272 settings->endGroup();
274 if( i_plVis ) togglePlaylist();
276 /* Final sizing and showing */
277 setVisible( !b_hideAfterCreation );
279 setMinimumWidth( __MAX( controls->sizeHint().width(),
280 menuBar()->sizeHint().width() ) + 30 );
282 /* Switch to minimal view if needed, must be called after the show() */
284 toggleMinimalView( true );
287 MainInterface::~MainInterface()
289 /* Unsure we hide the videoWidget before destroying it */
290 if( stackCentralOldWidget == playlistWidget )
293 /* Save playlist state */
297 QVLCTools::saveWidgetPosition( p_intf, "Playlist", playlistWidget );
299 delete playlistWidget;
304 ImageList_Destroy( himl );
306 p_taskbl->vt->Release(p_taskbl);
310 /* Be sure to kill the actionsManager... FIXME */
311 ActionsManager::killInstance();
314 ExtensionsManager::killInstance();
316 /* Delete the FSC controller */
317 delete fullscreenControls;
320 settings->beginGroup( "MainWindow" );
321 settings->setValue( "pl-dock-status", b_plDocked );
322 settings->setValue( "playlist-visible", (int)playlistVisible );
323 settings->setValue( "adv-controls",
324 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
326 settings->setValue( "mainBasedSize", mainBasedSize );
327 settings->setValue( "mainVideoSize", mainVideoSize );
329 settings->setValue( "backgroundSize", bgWidget->size() );
332 QVLCTools::saveWidgetPosition(settings, this);
333 settings->endGroup();
337 /* Unregister callbacks */
338 var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
339 var_DelCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
341 p_intf->p_sys->p_mi = NULL;
344 /*****************************
346 *****************************/
347 void MainInterface::recreateToolbars()
349 // FIXME: do the same for the FSC
350 //msg_Dbg( p_intf, "Recreating the toolbars" );
351 settings->beginGroup( "MainWindow" );
355 controls = new ControlsWidget( p_intf, false, this ); /* FIXME */
356 CONNECT( controls, advancedControlsToggled( bool ),
357 this, doComponentsUpdate() );
358 CONNECT( controls, sizeChanged(),
359 this, doComponentsUpdate() );
361 inputC = new InputControlsWidget( p_intf, this );
363 mainLayout->insertWidget( 2, inputC );
364 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
366 settings->endGroup();
369 void MainInterface::createMainWidget( QSettings *settings )
371 /* Create the main Widget and the mainLayout */
372 QWidget *main = new QWidget;
373 setCentralWidget( main );
374 mainLayout = new QVBoxLayout( main );
375 main->setContentsMargins( 0, 0, 0, 0 );
376 mainLayout->setSpacing( 0 ); mainLayout->setMargin( 0 );
379 stackCentralW = new QStackedWidget( main );
382 bgWidget = new BackgroundWidget( p_intf );
383 stackCentralW->addWidget( bgWidget );
385 /* And video Outputs */
386 if( b_videoEmbedded )
388 videoWidget = new VideoWidget( p_intf );
389 stackCentralW->addWidget( videoWidget );
391 mainLayout->insertWidget( 1, stackCentralW );
393 /* Create the CONTROLS Widget */
394 controls = new ControlsWidget( p_intf,
395 settings->value( "adv-controls", false ).toBool(), this );
396 CONNECT( controls, advancedControlsToggled( bool ),
397 this, doComponentsUpdate() );
398 CONNECT( controls, sizeChanged(),
399 this, doComponentsUpdate() );
400 inputC = new InputControlsWidget( p_intf, this );
402 mainLayout->insertWidget( 2, inputC );
403 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
406 /* Visualisation, disabled for now, they SUCK */
408 visualSelector = new VisualSelector( p_intf );
409 mainLayout->insertWidget( 0, visualSelector );
410 visualSelector->hide();
413 getSettings()->endGroup();
415 if ( depth() > 8 ) /* 8bit depth has too many issues with opacity */
416 /* Create the FULLSCREEN CONTROLS Widget */
417 if( var_InheritBool( p_intf, "qt-fs-controller" ) )
419 fullscreenControls = new FullscreenControllerWidget( p_intf, this );
420 CONNECT( fullscreenControls, keyPressed( QKeyEvent * ),
421 this, handleKeyPress( QKeyEvent * ) );
425 inline void MainInterface::initSystray()
428 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
429 bool b_systrayWanted = var_InheritBool( p_intf, "qt-system-tray" );
431 if( var_InheritBool( p_intf, "qt-start-minimized") )
433 if( b_systrayAvailable )
435 b_systrayWanted = true;
436 b_hideAfterCreation = true;
439 msg_Err( p_intf, "cannot start minimized without system tray bar" );
442 if( b_systrayAvailable && b_systrayWanted )
447 inline void MainInterface::createStatusBar()
452 /* Widgets Creation*/
453 QStatusBar *statusBarr = statusBar();
455 TimeLabel *timeLabel = new TimeLabel( p_intf );
456 nameLabel = new QLabel( this );
457 nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
458 | Qt::TextSelectableByKeyboard );
459 SpeedLabel *speedLabel = new SpeedLabel( p_intf, this );
461 /* Styling those labels */
462 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
463 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
464 nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
466 /* and adding those */
467 statusBarr->addWidget( nameLabel, 8 );
468 statusBarr->addPermanentWidget( speedLabel, 0 );
469 statusBarr->addPermanentWidget( timeLabel, 0 );
471 /* timeLabel behaviour:
472 - double clicking opens the goto time dialog
473 - right-clicking and clicking just toggle between remaining and
475 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
477 CONNECT( THEMIM->getIM(), encryptionChanged( bool ),
478 this, showCryptedLabel( bool ) );
480 CONNECT( THEMIM->getIM(), seekRequested( float ),
481 timeLabel, setDisplayPosition( float ) );
485 void MainInterface::createTaskBarButtons()
487 taskbar_wmsg = WM_NULL;
488 /*Here is the code for the taskbar thumb buttons
489 FIXME:We need pretty buttons in 16x16 px that are handled correctly by masks in Qt
490 FIXME:the play button's picture doesn't changed to pause when clicked
495 if( S_OK == CoCreateInstance( &clsid_ITaskbarList,
496 NULL, CLSCTX_INPROC_SERVER,
498 (void **)&p_taskbl) )
500 p_taskbl->vt->HrInit(p_taskbl);
502 if(himl = ImageList_Create( 15, //cx
505 4,//initial nb of images
506 0//nb of images that can be added
509 QPixmap img = QPixmap(":/toolbar/previous_b");
510 QPixmap img2 = QPixmap(":/toolbar/pause_b");
511 QPixmap img3 = QPixmap(":/toolbar/play_b");
512 QPixmap img4 = QPixmap(":/toolbar/next_b");
513 QBitmap mask = img.createMaskFromColor(Qt::transparent);
514 QBitmap mask2 = img2.createMaskFromColor(Qt::transparent);
515 QBitmap mask3 = img3.createMaskFromColor(Qt::transparent);
516 QBitmap mask4 = img4.createMaskFromColor(Qt::transparent);
518 if(-1 == ImageList_Add(himl, img.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask.toWinHBITMAP()))
519 msg_Err( p_intf, "ImageList_Add failed" );
520 if(-1 == ImageList_Add(himl, img2.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask2.toWinHBITMAP()))
521 msg_Err( p_intf, "ImageList_Add failed" );
522 if(-1 == ImageList_Add(himl, img3.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask3.toWinHBITMAP()))
523 msg_Err( p_intf, "ImageList_Add failed" );
524 if(-1 == ImageList_Add(himl, img4.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask4.toWinHBITMAP()))
525 msg_Err( p_intf, "ImageList_Add failed" );
528 // Define an array of two buttons. These buttons provide images through an
529 // image list and also provide tooltips.
530 DWORD dwMask = THB_BITMAP | THB_FLAGS;
532 THUMBBUTTON thbButtons[3];
533 thbButtons[0].dwMask = dwMask;
534 thbButtons[0].iId = 0;
535 thbButtons[0].iBitmap = 0;
536 thbButtons[0].dwFlags = THBF_HIDDEN;
538 thbButtons[1].dwMask = dwMask;
539 thbButtons[1].iId = 1;
540 thbButtons[1].iBitmap = 2;
541 thbButtons[1].dwFlags = THBF_HIDDEN;
543 thbButtons[2].dwMask = dwMask;
544 thbButtons[2].iId = 2;
545 thbButtons[2].iBitmap = 3;
546 thbButtons[2].dwFlags = THBF_HIDDEN;
548 HRESULT hr = p_taskbl->vt->ThumbBarSetImageList(p_taskbl, winId(), himl );
550 msg_Err( p_intf, "ThumbBarSetImageList failed with error %08x", hr );
553 hr = p_taskbl->vt->ThumbBarAddButtons(p_taskbl, winId(), 3, thbButtons);
555 msg_Err( p_intf, "ThumbBarAddButtons failed with error %08x", hr );
557 CONNECT( THEMIM->getIM(), statusChanged( int ), this, changeThumbbarButtons( int ) );
567 bool MainInterface::winEvent ( MSG * msg, long * result )
569 if (msg->message == taskbar_wmsg)
571 //We received the taskbarbuttoncreated, now we can really create th buttons
572 createTaskBarButtons();
576 switch( msg->message )
579 if (HIWORD(msg->wParam) == THBN_CLICKED)
581 switch(LOWORD(msg->wParam))
587 THEMIM->togglePlayPause();
596 cmd = GET_APPCOMMAND_LPARAM(msg->lParam);
599 case APPCOMMAND_MEDIA_PLAY_PAUSE:
600 THEMIM->togglePlayPause();
602 case APPCOMMAND_MEDIA_PLAY:
605 case APPCOMMAND_MEDIA_PAUSE:
608 case APPCOMMAND_MEDIA_PREVIOUSTRACK:
611 case APPCOMMAND_MEDIA_NEXTTRACK:
614 case APPCOMMAND_MEDIA_STOP:
617 case APPCOMMAND_VOLUME_DOWN:
620 case APPCOMMAND_VOLUME_UP:
623 case APPCOMMAND_VOLUME_MUTE:
624 THEAM->toggleMuteAudio();
627 msg_Dbg( p_intf, "unknown APPCOMMAND = %d", cmd);
636 /**********************************************************************
637 * Handling of sizing of the components
638 **********************************************************************/
640 /* This function is probably wrong, but we don't have many many choices...
641 Since we can't know from the playlist Widget if we are inside a dock or not,
642 because the playlist Widget can be called by THEDP, as a separate windows for
644 Maybe the other solution is to redefine the sizeHint() of the playlist and
645 ask _parent->isFloating()...
646 If you think this would be better, please FIXME it...
650 QSize MainInterface::sizeHint() const
657 return mainVideoSize;
661 if( VISIBLE( bgWidget) ||
662 ( videoIsActive && videoWidget->isVisible() )
664 return mainVideoSize;
666 return mainBasedSize;
671 int nwidth = __MAX( controls->sizeHint().width(),
672 menuBar()->sizeHint().width() );
674 int nheight = controls->isVisible() ?
675 controls->size().height()
676 + inputC->size().height()
677 + menuBar()->size().height()
678 + statusBar()->size().height()
681 /* if( stackCentralW->isVisible() )
683 nheight += stackCentralW->height();
684 nwidth = __MAX( nwidth, stackCentralW->width() );
687 /* if( VISIBLE( bgWidget ) )
689 msg_Warn( p_intf, "Hello here" );
691 nheight += i_bg_height;
693 nheight += bgWidget->size().height();
694 nwidth = __MAX( nwidth, bgWidget->size().width() );
696 else if( videoIsActive && videoWidget->isVisible() )
698 msg_Warn( p_intf, "Hello there" );
699 nheight += videoWidget->sizeHint().height();
700 nwidth = __MAX( nwidth, videoWidget->sizeHint().width() );
703 if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget() )
705 nheight += dockPL->size().height();
706 nwidth = __MAX( nwidth, dockPL->size().width() );
707 msg_Warn( p_intf, "3 %i %i", nheight, nwidth );
710 return QSize( nwidth, nheight );
714 /* Video widget cannot do this synchronously as it runs in another thread */
715 /* Well, could it, actually ? Probably dangerous ... */
717 /* This function is called:
718 - toggling of minimal View
719 - through askUpdate() by Vout thread request video and resize video (zoom)
720 - Advanced buttons toggled
722 void MainInterface::doComponentsUpdate()
724 if( isFullScreen() || isMaximized() ) return;
726 // msg_Warn( p_intf, "Updating the geometry" );
727 /* Here we resize to sizeHint() and not adjustsize because we want
728 the videoWidget to be exactly the correctSize */
733 /* This is WRONG, but I believe there is a Qt bug here */
734 setMinimumSize( 0, 0 );
735 //resize( sizeHint() );
737 //adjustSize() ; /* This is not needed, but might help in the future */
740 void MainInterface::debug()
743 msg_Dbg( p_intf, "Stack Size: %i - %i", stackCentralW->size().height(), size().width() );
745 msg_Dbg( p_intf, "Stack Size: %i - %i",
746 videoWidget->size().height(),
747 videoWidget->size().width() );
749 msg_Dbg( p_intf, "no embedded video" );
751 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
752 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
753 //msg_Dbg( p_intf, "maximumsize: %i - %i", maximumSize().height(), maximumSize().width() );
755 msg_Dbg( p_intf, "Stack size: %i - %i", stackCentralW->size().height(), stackCentralW->size().width() );
756 msg_Dbg( p_intf, "Stack minimumSize(): %i - %i", stackCentralW->minimumHeight(), stackCentralW->minimumWidth() );
757 msg_Dbg( p_intf, "Central minimumsize: %i - %i", centralWidget()->minimumSize().height(), centralWidget()->minimumSize().width() );
758 msg_Dbg( p_intf, "Central size: %i - %i", centralWidget()->size().height(), centralWidget()->size().width() );
759 msg_Dbg( p_intf, "Menu minimumsize: %i - %i", menuBar()->minimumSize().height(), menuBar()->minimumSize().width() );
760 msg_Dbg( p_intf, "Input size: %i - %i", inputC->size().height(), inputC->size().width() );
761 msg_Dbg( p_intf, "Status minimumsize: %i - %i", statusBar()->minimumSize().height(), statusBar()->minimumSize().width() );
762 msg_Dbg( p_intf, "minimumsize: %i - %i", minimumSize().height(), minimumSize().width() );
763 msg_Dbg( p_intf, "bg Size: %i - %i", bgWidget->size().height(), bgWidget->size().width() );
765 /*if( videoWidget && videoWidget->isVisible() )
767 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
768 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
773 inline void MainInterface::showVideo() { showTab( videoWidget ); }
774 inline void MainInterface::showBg() { showTab( bgWidget ); }
776 inline void MainInterface::showTab( QWidget *widget )
779 msg_Warn( p_intf, "Old stackCentralOldWidget %i", stackCentralW->indexOf( stackCentralOldWidget ) );
781 stackCentralOldWidget = stackCentralW->currentWidget();
782 stackCentralW->setCurrentWidget( widget );
785 msg_Warn( p_intf, "State change %i", stackCentralW->currentIndex() );
786 msg_Warn( p_intf, "New stackCentralOldWidget %i", stackCentralW->indexOf( stackCentralOldWidget ) );
790 inline void MainInterface::restoreStackOldWidget()
793 msg_Warn( p_intf, "New stackCentralOldWidget %i", stackCentralW->indexOf( stackCentralOldWidget ) );
795 QWidget *wTemp = stackCentralW->currentWidget();
797 stackCentralW->setCurrentWidget( stackCentralOldWidget );
799 stackCentralOldWidget = wTemp;
801 msg_Warn( p_intf, "Debug %i %i",stackCentralW->indexOf( wTemp ), stackCentralW->indexOf( stackCentralW->currentWidget() ) );
805 void MainInterface::destroyPopupMenu()
807 QVLCMenu::PopupMenu( p_intf, false );
810 void MainInterface::popupMenu( const QPoint &p )
813 * Ow, that's ugly: don't show the popup menu if cursor over
814 * the main menu bar or the status bar */
815 if( !childAt( p ) || ( ( childAt( p ) != menuBar() )
816 && ( childAt( p )->parentWidget() != statusBar() ) ) )
817 QVLCMenu::PopupMenu( p_intf, true );
820 void MainInterface::toggleFSC()
822 if( !fullscreenControls ) return;
824 IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
825 QApplication::postEvent( fullscreenControls, eShow );
828 /****************************************************************************
830 ****************************************************************************/
832 /* This event is used to deal with the fullscreen and always on top
833 issue conflict (bug in wx) */
834 class SetVideoOnTopQtEvent : public QEvent
837 SetVideoOnTopQtEvent( bool _onTop ) :
838 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
841 bool OnTop() const { return onTop; }
849 * You must not change the state of this object or other Qt4 UI objects,
850 * from the video output thread - only from the Qt4 UI main loop thread.
851 * All window provider queries must be handled through signals or events.
852 * That's why we have all those emit statements...
854 WId MainInterface::getVideo( int *pi_x, int *pi_y,
855 unsigned int *pi_width, unsigned int *pi_height )
860 /* This is a blocking call signal. Results are returned through pointers.
861 * Beware of deadlocks! */
863 emit askGetVideo( &id, pi_x, pi_y, pi_width, pi_height );
867 void MainInterface::getVideoSlot( WId *p_id, int *pi_x, int *pi_y,
868 unsigned *pi_width, unsigned *pi_height )
870 /* Request the videoWidget */
871 WId ret = videoWidget->request( pi_x, pi_y,
872 pi_width, pi_height, b_keep_size );
874 if( ret ) /* The videoWidget is available */
876 /* ask videoWidget to show */
877 videoWidget->SetSizing( *pi_width, *pi_height );
879 /* Consider the video active now */
882 stackCentralW->resize( *pi_width, *pi_height );
890 /* Asynchronous call from the WindowClose function */
891 void MainInterface::releaseVideo( void )
893 emit askReleaseVideo( );
896 /* Function that is CONNECTED to the previous emit */
897 void MainInterface::releaseVideoSlot( void )
899 videoWidget->release( );
901 restoreStackOldWidget();
903 /* We don't want to have a blank video to popup */
904 stackCentralOldWidget = bgWidget;
906 /* Try to resize, except when you are in Fullscreen mode */
907 // doComponentsUpdate();
910 /* Asynchronous call from WindowControl function */
911 int MainInterface::controlVideo( int i_query, va_list args )
913 /* Debug to check if VOUT_WINDOW_SET_SIZE is called, because this is broken now */
914 msg_Warn( p_intf, "Control Video: %i", i_query );
917 case VOUT_WINDOW_SET_SIZE:
919 unsigned int i_width = va_arg( args, unsigned int );
920 unsigned int i_height = va_arg( args, unsigned int );
921 emit askVideoToResize( i_width, i_height );
925 case VOUT_WINDOW_SET_STATE:
927 unsigned i_arg = va_arg( args, unsigned );
928 unsigned on_top = i_arg & VOUT_WINDOW_STATE_ABOVE;
929 QApplication::postEvent( this, new SetVideoOnTopQtEvent( on_top ) );
932 case VOUT_WINDOW_SET_FULLSCREEN:
934 bool b_fs = va_arg( args, int );
935 emit askVideoSetFullScreen( b_fs );
939 msg_Warn( p_intf, "unsupported control query" );
944 /*****************************************************************************
945 * Playlist, Visualisation and Menus handling
946 *****************************************************************************/
948 * Toggle the playlist widget or dialog
950 void MainInterface::createPlaylist()
952 playlistWidget = new PlaylistWidget( p_intf, this );
956 playlistWidget->setWindowFlags( Qt::Window );
958 /* This will restore the geometry but will not work for position,
959 because of parenting */
960 QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
961 playlistWidget, QSize( 600, 300 ) );
966 msg_Warn( p_intf, "Here 1 %i", stackCentralW->currentIndex() );
968 stackCentralW->addWidget( playlistWidget );
970 msg_Warn( p_intf, "Here 2 %i", stackCentralW->currentIndex() );
975 void MainInterface::togglePlaylist()
977 if( !playlistWidget )
982 /* Playlist is not visible, show it */
983 if( stackCentralW->currentWidget() != playlistWidget )
985 playlistWidget->forceShow();
986 showTab( playlistWidget );
990 restoreStackOldWidget();
991 stackCentralW->updateGeometry();
992 // HACK: So it doesn't limit the stackWidget minimumSize
993 playlistWidget->forceHide();
995 playlistVisible = ( stackCentralW->currentWidget() == playlistWidget );
999 playlistWidget->setWindowFlags( Qt::Window );
1000 playlistVisible = !playlistVisible;
1001 playlistWidget->setVisible( playlistVisible );
1006 void MainInterface::dockPlaylist( bool p_docked )
1008 if( b_plDocked == p_docked ) return;
1009 b_plDocked = p_docked;
1011 if( !playlistWidget ) return; /* Playlist wasn't created yet */
1014 stackCentralW->removeWidget( playlistWidget );
1015 playlistWidget->setWindowFlags( Qt::Window );
1016 QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
1017 playlistWidget, QSize( 600, 300 ) );
1018 playlistWidget->show();
1019 restoreStackOldWidget();
1023 playlistWidget->setWindowFlags( Qt::Widget ); // Probably a Qt bug here
1024 // It would be logical that QStackWidget::addWidget reset the flags...
1025 stackCentralW->addWidget( playlistWidget );
1026 stackCentralW->setCurrentWidget( playlistWidget );
1030 void MainInterface::toggleMinimalView( bool b_switch )
1032 if( i_visualmode == 0 )
1033 { /* NORMAL MODE then */
1034 if( !videoWidget || stackCentralW->currentWidget() != videoWidget )
1040 /* If video is visible, then toggle the status of bgWidget */
1042 //bgWasVisible = !bgWasVisible;
1043 /* if( stackCentralOldState == BACK G_TAB )
1044 stackCentralOldState = HID DEN_TAB;
1046 stackCentralOldState = BACK G_TAB;
1052 i_bg_height = stackCentralW->height();
1054 menuBar()->setVisible( !b_switch );
1055 controls->setVisible( !b_switch );
1056 statusBar()->setVisible( !b_switch );
1057 inputC->setVisible( !b_switch );
1059 doComponentsUpdate();
1061 emit minimalViewToggled( b_switch );
1064 /* toggling advanced controls buttons */
1065 void MainInterface::toggleAdvanced()
1067 controls->toggleAdvanced();
1068 // if( fullscreenControls ) fullscreenControls->toggleAdvanced();
1071 /* Get the visibility status of the controls (hidden or not, advanced or not) */
1072 int MainInterface::getControlsVisibilityStatus()
1074 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
1075 + CONTROLS_ADVANCED * controls->b_advancedVisible );
1079 void MainInterface::visual()
1081 if( !VISIBLE( visualSelector) )
1083 visualSelector->show();
1084 if( !THEMIM->getIM()->hasVideo() )
1086 /* Show the background widget */
1088 visualSelectorEnabled = true;
1092 /* Stop any currently running visualization */
1093 visualSelector->hide();
1094 visualSelectorEnabled = false;
1096 doComponentsUpdate();
1100 /************************************************************************
1102 ************************************************************************/
1103 void MainInterface::setName( const QString& name )
1105 input_name = name; /* store it for the QSystray use */
1106 /* Display it in the status bar, but also as a Tooltip in case it doesn't
1108 nameLabel->setText( " " + name + " " );
1109 nameLabel->setToolTip( " " + name +" " );
1113 * Give the decorations of the Main Window a correct Name.
1114 * If nothing is given, set it to VLC...
1116 void MainInterface::setVLCWindowsTitle( const QString& aTitle )
1118 if( aTitle.isEmpty() )
1120 setWindowTitle( qtr( "VLC media player" ) );
1124 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
1128 void MainInterface::showCryptedLabel( bool b_show )
1130 if( cryptedLabel == NULL )
1132 cryptedLabel = new QLabel;
1133 // The lock icon is not the right one for DRM protection/scrambled.
1134 //cryptedLabel->setPixmap( QPixmap( ":/lock" ) );
1135 cryptedLabel->setText( "DRM" );
1136 statusBar()->addWidget( cryptedLabel );
1139 cryptedLabel->setVisible( b_show );
1142 void MainInterface::showBuffering( float f_cache )
1144 QString amount = QString("Buffering: %1%").arg( (int)(100*f_cache) );
1145 statusBar()->showMessage( amount, 1000 );
1148 /*****************************************************************************
1149 * Systray Icon and Systray Menu
1150 *****************************************************************************/
1153 * Create a SystemTray icon and a menu that would go with it.
1154 * Connects to a click handler on the icon.
1156 void MainInterface::createSystray()
1159 if( QDate::currentDate().dayOfYear() >= 354 )
1160 iconVLC = QIcon( ":/logo/vlc128-christmas.png" );
1162 iconVLC = QIcon( ":/logo/vlc128.png" );
1163 sysTray = new QSystemTrayIcon( iconVLC, this );
1164 sysTray->setToolTip( qtr( "VLC media player" ));
1166 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
1167 systrayMenu->setIcon( iconVLC );
1169 QVLCMenu::updateSystrayMenu( this, p_intf, true );
1172 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
1173 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
1177 * Updates the Systray Icon's menu and toggle the main interface
1179 void MainInterface::toggleUpdateSystrayMenu()
1181 /* If hidden, show it */
1187 else if( isMinimized() )
1195 /* Visible (possibly under other windows) */
1197 /* check if any visible window is above vlc in the z-order,
1198 * but ignore the ones always on top
1199 * and the ones which can't be activated */
1202 wi.cbSize = sizeof( WINDOWINFO );
1203 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
1204 hwnd && ( !IsWindowVisible( hwnd ) ||
1205 ( GetWindowInfo( hwnd, &wi ) &&
1206 (wi.dwExStyle&WS_EX_NOACTIVATE) ) );
1207 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
1208 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
1209 (wi.dwExStyle&WS_EX_TOPMOST) )
1221 QVLCMenu::updateSystrayMenu( this, p_intf );
1224 void MainInterface::handleSystrayClick(
1225 QSystemTrayIcon::ActivationReason reason )
1229 case QSystemTrayIcon::Trigger:
1230 case QSystemTrayIcon::DoubleClick:
1231 toggleUpdateSystrayMenu();
1233 case QSystemTrayIcon::MiddleClick:
1234 sysTray->showMessage( qtr( "VLC media player" ),
1235 qtr( "Control menu for the player" ),
1236 QSystemTrayIcon::Information, 3000 );
1244 * Updates the name of the systray Icon tooltip.
1245 * Doesn't check if the systray exists, check before you call it.
1247 void MainInterface::updateSystrayTooltipName( const QString& name )
1249 if( name.isEmpty() )
1251 sysTray->setToolTip( qtr( "VLC media player" ) );
1255 sysTray->setToolTip( name );
1256 if( b_notificationEnabled && ( isHidden() || isMinimized() ) )
1258 sysTray->showMessage( qtr( "VLC media player" ), name,
1259 QSystemTrayIcon::NoIcon, 3000 );
1263 QVLCMenu::updateSystrayMenu( this, p_intf );
1267 * Updates the status of the systray Icon tooltip.
1268 * Doesn't check if the systray exists, check before you call it.
1270 void MainInterface::updateSystrayTooltipStatus( int i_status )
1277 sysTray->setToolTip( qtr( "VLC media player" ) );
1282 sysTray->setToolTip( input_name );
1287 sysTray->setToolTip( input_name + " - "
1292 QVLCMenu::updateSystrayMenu( this, p_intf );
1296 /************************************************************************
1298 ************************************************************************/
1299 void MainInterface::dropEvent(QDropEvent *event)
1301 dropEventPlay( event, true );
1304 void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
1306 event->setDropAction( Qt::CopyAction );
1307 if( !event->possibleActions() & Qt::CopyAction )
1310 const QMimeData *mimeData = event->mimeData();
1312 /* D&D of a subtitles file, add it on the fly */
1313 if( mimeData->urls().size() == 1 && THEMIM->getIM()->hasInput() )
1315 if( !input_AddSubtitle( THEMIM->getInput(),
1316 qtu( toNativeSeparators( mimeData->urls()[0].toLocalFile() ) ),
1324 bool first = b_play;
1325 foreach( const QUrl &url, mimeData->urls() )
1327 QString s = toNativeSeparators( url.toLocalFile() );
1329 if( s.length() > 0 ) {
1330 char* psz_uri = make_URI( qtu(s) );
1331 playlist_Add( THEPL, psz_uri, NULL,
1332 PLAYLIST_APPEND | (first ? PLAYLIST_GO: PLAYLIST_PREPARSE),
1333 PLAYLIST_END, true, pl_Unlocked );
1336 RecentsMRL::getInstance( p_intf )->addRecent( s );
1341 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1343 event->acceptProposedAction();
1345 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1347 event->acceptProposedAction();
1349 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1354 /************************************************************************
1356 ************************************************************************/
1357 void MainInterface::customEvent( QEvent *event )
1360 if( event->type() == PLDockEvent_Type )
1362 PlaylistDialog::killInstance();
1363 playlistEmbeddedFlag = true;
1365 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1370 if ( event->type() == (int)SetVideoOnTopEvent_Type )
1372 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1373 if( p_event->OnTop() )
1374 setWindowFlags( windowFlags() | Qt::WindowStaysOnTopHint );
1376 setWindowFlags( windowFlags() & ~Qt::WindowStaysOnTopHint );
1377 show(); /* necessary to apply window flags */
1381 void MainInterface::keyPressEvent( QKeyEvent *e )
1383 handleKeyPress( e );
1386 void MainInterface::handleKeyPress( QKeyEvent *e )
1388 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() == Qt::Key_H )
1389 && !menuBar()->isVisible() )
1391 toggleMinimalView( false );
1395 int i_vlck = qtEventToVLCKey( e );
1398 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1405 void MainInterface::resizeEvent( QResizeEvent * event )
1412 mainVideoSize = size();
1416 if( VISIBLE( bgWidget) ||
1417 ( videoIsActive && videoWidget->isVisible() )
1419 mainVideoSize = size();
1421 mainBasedSize = size();
1425 QVLCMW::resizeEvent( event );
1426 msg_Dbg( p_intf, "Resize Event, height: %i", size().height() );
1430 void MainInterface::wheelEvent( QWheelEvent *e )
1432 int i_vlckey = qtWheelEventToVLCKey( e );
1433 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1437 void MainInterface::closeEvent( QCloseEvent *e )
1444 void MainInterface::toggleFullScreen( void )
1446 if( isFullScreen() )
1449 emit askUpdate(); // Needed if video was launched after the F11
1450 emit fullscreenInterfaceToggled( false );
1455 emit fullscreenInterfaceToggled( true );
1460 //moc doesn't know about #ifdef, so we have to build this method for every platform
1461 void MainInterface::changeThumbbarButtons( int i_status)
1464 // Define an array of three buttons. These buttons provide images through an
1465 // image list and also provide tooltips.
1466 DWORD dwMask = THB_BITMAP | THB_FLAGS;
1468 THUMBBUTTON thbButtons[3];
1470 thbButtons[0].dwMask = dwMask;
1471 thbButtons[0].iId = 0;
1472 thbButtons[0].iBitmap = 0;
1475 thbButtons[1].dwMask = dwMask;
1476 thbButtons[1].iId = 1;
1479 thbButtons[2].dwMask = dwMask;
1480 thbButtons[2].iId = 2;
1481 thbButtons[2].iBitmap = 3;
1487 thbButtons[0].dwFlags = THBF_ENABLED;
1488 thbButtons[1].dwFlags = THBF_ENABLED;
1489 thbButtons[2].dwFlags = THBF_ENABLED;
1490 thbButtons[1].iBitmap = 1;
1495 thbButtons[0].dwFlags = THBF_ENABLED;
1496 thbButtons[1].dwFlags = THBF_ENABLED;
1497 thbButtons[2].dwFlags = THBF_ENABLED;
1498 thbButtons[1].iBitmap = 2;
1504 HRESULT hr = p_taskbl->vt->ThumbBarUpdateButtons(p_taskbl, this->winId(), 3, thbButtons);
1506 msg_Err( p_intf, "ThumbBarUpdateButtons failed with error %08x", hr );
1512 /*****************************************************************************
1513 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1514 * We don't show the menu directly here because we don't want the
1515 * caller to block for a too long time.
1516 *****************************************************************************/
1517 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1518 vlc_value_t old_val, vlc_value_t new_val, void *param )
1520 intf_thread_t *p_intf = (intf_thread_t *)param;
1522 if( p_intf->pf_show_dialog )
1524 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1525 new_val.b_bool, NULL );
1531 /*****************************************************************************
1532 * IntfShowCB: callback triggered by the intf-show libvlc variable.
1533 *****************************************************************************/
1534 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1535 vlc_value_t old_val, vlc_value_t new_val, void *param )
1537 intf_thread_t *p_intf = (intf_thread_t *)param;
1538 p_intf->p_sys->p_mi->toggleFSC();