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 );
275 int i_plVis = settings->value( "playlist-visible", 0 ).toInt();
277 settings->endGroup();
279 if( i_plVis ) togglePlaylist();
281 /* Final sizing and showing */
282 setVisible( !b_hideAfterCreation );
283 //setMinimumSize( QSize( 0, 0 ) );
284 // setMinimumWidth( __MAX( controls->sizeHint().width(),
285 // menuBar()->sizeHint().width() ) );
288 /* And switch to minimal view if needed
289 Must be called after the show() */
290 if( i_visualmode == QT_MINIMAL_MODE )
291 toggleMinimalView( true );
293 /* Update the geometry : It is useful if you switch between
296 resize( sizeHint() );
299 MainInterface::~MainInterface()
301 msg_Dbg( p_intf, "Destroying the main interface" );
303 /* Unsure we hide the videoWidget before destroying it */
304 if( stackCentralOldState == VIDEO_TAB )
307 /* Save playlist state */
311 QVLCTools::saveWidgetPosition( p_intf, "Playlist", playlistWidget );
313 delete playlistWidget;
318 ImageList_Destroy( himl );
320 p_taskbl->vt->Release(p_taskbl);
324 /* Be sure to kill the actionsManager... FIXME */
325 ActionsManager::killInstance();
328 ExtensionsManager::killInstance();
330 /* Delete the FSC controller */
331 delete fullscreenControls;
334 settings->beginGroup( "MainWindow" );
335 settings->setValue( "pl-dock-status", (int)i_pl_dock );
336 settings->setValue( "playlist-visible", (int)playlistVisible );
337 settings->setValue( "adv-controls",
338 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
340 settings->setValue( "mainBasedSize", mainBasedSize );
341 settings->setValue( "mainVideoSize", mainVideoSize );
344 settings->setValue( "backgroundSize", bgWidget->size() );
347 QVLCTools::saveWidgetPosition(settings, this);
348 settings->endGroup();
352 /* Unregister callbacks */
353 var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
354 var_DelCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
356 p_intf->p_sys->p_mi = NULL;
359 /*****************************
361 *****************************/
362 void MainInterface::recreateToolbars()
364 //msg_Dbg( p_intf, "Recreating the toolbars" );
365 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() );
375 inputC = new InputControlsWidget( p_intf, this );
377 mainLayout->insertWidget( 2, inputC );
378 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
380 settings->endGroup();
383 void MainInterface::createMainWidget( QSettings *settings )
385 /* Create the main Widget and the mainLayout */
386 QWidget *main = new QWidget;
387 setCentralWidget( main );
388 mainLayout = new QVBoxLayout( main );
390 /* Margins, spacing */
391 main->setContentsMargins( 0, 0, 0, 0 );
392 mainLayout->setSpacing( 0 ); 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 /* Create the CONTROLS Widget */
415 controls = new ControlsWidget( p_intf,
416 settings->value( "adv-controls", false ).toBool(), this );
417 CONNECT( controls, advancedControlsToggled( bool ),
418 this, doComponentsUpdate() );
419 CONNECT( controls, sizeChanged(),
420 this, doComponentsUpdate() );
421 inputC = new InputControlsWidget( p_intf, this );
423 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
424 i_visualmode != QT_MINIMAL_MODE )
427 stackCentralOldState = HIDDEN_TAB;
431 showTab( BACKG_TAB );
432 stackCentralOldState = BACKG_TAB;
436 //mainLayout->setRowStretch( 1, 10 );
437 mainLayout->insertWidget( 2, inputC );
438 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
442 /* Disabled for now, they SUCK */
444 visualSelector = new VisualSelector( p_intf );
445 mainLayout->insertWidget( 0, visualSelector );
446 visualSelector->hide();
449 /* Finish the sizing */
450 main->updateGeometry();
452 getSettings()->endGroup();
456 /* Create the FULLSCREEN CONTROLS Widget */
457 if( var_InheritBool( p_intf, "qt-fs-controller" ) )
459 fullscreenControls = new FullscreenControllerWidget( p_intf, this );
460 CONNECT( fullscreenControls, keyPressed( QKeyEvent * ),
461 this, handleKeyPress( QKeyEvent * ) );
465 inline void MainInterface::initSystray()
468 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
469 bool b_systrayWanted = var_InheritBool( p_intf, "qt-system-tray" );
471 if( var_InheritBool( p_intf, "qt-start-minimized") )
473 if( b_systrayAvailable )
475 b_systrayWanted = true;
476 b_hideAfterCreation = true;
479 msg_Err( p_intf, "cannot start minimized without system tray bar" );
482 if( b_systrayAvailable && b_systrayWanted )
487 inline void MainInterface::createStatusBar()
492 /* Widgets Creation*/
493 QStatusBar *statusBarr = statusBar();
495 TimeLabel *timeLabel = new TimeLabel( p_intf );
496 nameLabel = new QLabel( this );
497 nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
498 | Qt::TextSelectableByKeyboard );
499 SpeedLabel *speedLabel = new SpeedLabel( p_intf, "1.00x", this );
501 /* Styling those labels */
502 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
503 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
504 nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
506 /* and adding those */
507 statusBarr->addWidget( nameLabel, 8 );
508 statusBarr->addPermanentWidget( speedLabel, 0 );
509 statusBarr->addPermanentWidget( timeLabel, 0 );
511 /* timeLabel behaviour:
512 - double clicking opens the goto time dialog
513 - right-clicking and clicking just toggle between remaining and
515 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
517 CONNECT( THEMIM->getIM(), encryptionChanged( bool ),
518 this, showCryptedLabel( bool ) );
522 void MainInterface::createTaskBarButtons()
524 taskbar_wmsg = WM_NULL;
525 /*Here is the code for the taskbar thumb buttons
526 FIXME:We need pretty buttons in 16x16 px that are handled correctly by masks in Qt
527 FIXME:the play button's picture doesn't changed to pause when clicked
532 if( S_OK == CoCreateInstance( &clsid_ITaskbarList,
533 NULL, CLSCTX_INPROC_SERVER,
535 (void **)&p_taskbl) )
537 p_taskbl->vt->HrInit(p_taskbl);
539 if(himl = ImageList_Create( 15, //cx
542 4,//initial nb of images
543 0//nb of images that can be added
546 QPixmap img = QPixmap(":/toolbar/previous_b");
547 QPixmap img2 = QPixmap(":/toolbar/pause_b");
548 QPixmap img3 = QPixmap(":/toolbar/play_b");
549 QPixmap img4 = QPixmap(":/toolbar/next_b");
550 QBitmap mask = img.createMaskFromColor(Qt::transparent);
551 QBitmap mask2 = img2.createMaskFromColor(Qt::transparent);
552 QBitmap mask3 = img3.createMaskFromColor(Qt::transparent);
553 QBitmap mask4 = img4.createMaskFromColor(Qt::transparent);
555 if(-1 == ImageList_Add(himl, img.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask.toWinHBITMAP()))
556 msg_Err( p_intf, "ImageList_Add failed" );
557 if(-1 == ImageList_Add(himl, img2.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask2.toWinHBITMAP()))
558 msg_Err( p_intf, "ImageList_Add failed" );
559 if(-1 == ImageList_Add(himl, img3.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask3.toWinHBITMAP()))
560 msg_Err( p_intf, "ImageList_Add failed" );
561 if(-1 == ImageList_Add(himl, img4.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask4.toWinHBITMAP()))
562 msg_Err( p_intf, "ImageList_Add failed" );
565 // Define an array of two buttons. These buttons provide images through an
566 // image list and also provide tooltips.
567 DWORD dwMask = THB_BITMAP | THB_FLAGS;
569 THUMBBUTTON thbButtons[3];
570 thbButtons[0].dwMask = dwMask;
571 thbButtons[0].iId = 0;
572 thbButtons[0].iBitmap = 0;
573 thbButtons[0].dwFlags = THBF_HIDDEN;
575 thbButtons[1].dwMask = dwMask;
576 thbButtons[1].iId = 1;
577 thbButtons[1].iBitmap = 2;
578 thbButtons[1].dwFlags = THBF_HIDDEN;
580 thbButtons[2].dwMask = dwMask;
581 thbButtons[2].iId = 2;
582 thbButtons[2].iBitmap = 3;
583 thbButtons[2].dwFlags = THBF_HIDDEN;
585 HRESULT hr = p_taskbl->vt->ThumbBarSetImageList(p_taskbl, winId(), himl );
587 msg_Err( p_intf, "ThumbBarSetImageList failed with error %08x", hr );
590 hr = p_taskbl->vt->ThumbBarAddButtons(p_taskbl, winId(), 3, thbButtons);
592 msg_Err( p_intf, "ThumbBarAddButtons failed with error %08x", hr );
594 CONNECT( THEMIM->getIM(), statusChanged( int ), this, changeThumbbarButtons( int ) );
604 bool MainInterface::winEvent ( MSG * msg, long * result )
606 if (msg->message == taskbar_wmsg)
608 //We received the taskbarbuttoncreated, now we can really create th buttons
609 createTaskBarButtons();
613 switch( msg->message )
616 if (HIWORD(msg->wParam) == THBN_CLICKED)
618 switch(LOWORD(msg->wParam))
624 THEMIM->togglePlayPause();
633 cmd = GET_APPCOMMAND_LPARAM(msg->lParam);
636 case APPCOMMAND_MEDIA_PLAY_PAUSE:
637 THEMIM->togglePlayPause();
639 case APPCOMMAND_MEDIA_PLAY:
642 case APPCOMMAND_MEDIA_PAUSE:
645 case APPCOMMAND_MEDIA_PREVIOUSTRACK:
648 case APPCOMMAND_MEDIA_NEXTTRACK:
651 case APPCOMMAND_MEDIA_STOP:
654 case APPCOMMAND_VOLUME_DOWN:
657 case APPCOMMAND_VOLUME_UP:
660 case APPCOMMAND_VOLUME_MUTE:
661 THEAM->toggleMuteAudio();
664 msg_Dbg( p_intf, "unknown APPCOMMAND = %d", cmd);
673 /**********************************************************************
674 * Handling of sizing of the components
675 **********************************************************************/
677 /* This function is probably wrong, but we don't have many many choices...
678 Since we can't know from the playlist Widget if we are inside a dock or not,
679 because the playlist Widget can be called by THEDP, as a separate windows for
681 Maybe the other solution is to redefine the sizeHint() of the playlist and
682 ask _parent->isFloating()...
683 If you think this would be better, please FIXME it...
686 QSize MainInterface::sizeHint() const
691 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
692 i_visualmode == QT_MINIMAL_MODE )
694 return mainVideoSize;
698 if( VISIBLE( bgWidget) ||
699 ( videoIsActive && videoWidget->isVisible() )
701 return mainVideoSize;
703 return mainBasedSize;
708 int nwidth = __MAX( controls->sizeHint().width(),
709 menuBar()->sizeHint().width() );
711 int nheight = controls->isVisible() ?
712 controls->size().height()
713 + inputC->size().height()
714 + menuBar()->size().height()
715 + statusBar()->size().height()
718 if( stackCentralW->isVisible() )
719 nheight += stackCentralW->height();
720 nwidth = __MAX( nwidth, stackCentralW->width() );
722 /* if( VISIBLE( bgWidget ) )
724 msg_Warn( p_intf, "Hello here" );
726 nheight += i_bg_height;
728 nheight += bgWidget->size().height();
729 nwidth = __MAX( nwidth, bgWidget->size().width() );
731 else if( videoIsActive && videoWidget->isVisible() )
733 msg_Warn( p_intf, "Hello there" );
734 nheight += videoWidget->sizeHint().height();
735 nwidth = __MAX( nwidth, videoWidget->sizeHint().width() );
738 if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget() )
740 nheight += dockPL->size().height();
741 nwidth = __MAX( nwidth, dockPL->size().width() );
742 msg_Warn( p_intf, "3 %i %i", nheight, nwidth );
745 return QSize( nwidth, nheight );
749 /* Video widget cannot do this synchronously as it runs in another thread */
750 /* Well, could it, actually ? Probably dangerous ... */
752 /* This function is called:
753 - toggling of minimal View
754 - through askUpdate() by Vout thread request video and resize video (zoom)
755 - Advanced buttons toggled
757 void MainInterface::doComponentsUpdate()
759 if( isFullScreen() || isMaximized() ) return;
761 // msg_Warn( p_intf, "Updating the geometry" );
762 /* Here we resize to sizeHint() and not adjustsize because we want
763 the videoWidget to be exactly the correctSize */
768 /* This is WRONG, but I believe there is a Qt bug here */
769 setMinimumSize( 0, 0 );
770 resize( sizeHint() );
772 //adjustSize() ; /* This is not needed, but might help in the future */
775 void MainInterface::debug()
778 msg_Dbg( p_intf, "Stack Size: %i - %i", stackCentralW->size().height(), size().width() );
779 if( videoEmbeddedFlag )
780 msg_Dbg( p_intf, "Stack Size: %i - %i",
781 stackCentralW->widget( VIDEO_TAB )->size().height(),
782 stackCentralW->widget( VIDEO_TAB )->size().width() );
784 msg_Dbg( p_intf, "no embedded video" );
786 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
787 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
788 //msg_Dbg( p_intf, "maximumsize: %i - %i", maximumSize().height(), maximumSize().width() );
790 msg_Dbg( p_intf, "Stack minimumsize: %i - %i", stackCentralW->minimumSize().height(), stackCentralW->minimumSize().width() );
791 msg_Dbg( p_intf, "Controls minimumsize: %i - %i", controls->minimumSize().height(), controls->minimumSize().width() );
792 msg_Dbg( p_intf, "Central minimumsize: %i - %i", centralWidget()->minimumSize().height(), centralWidget()->minimumSize().width() );
793 msg_Dbg( p_intf, "Menu minimumsize: %i - %i", menuBar()->minimumSize().height(), menuBar()->minimumSize().width() );
794 msg_Dbg( p_intf, "Input minimuSize: %i - %i", inputC->minimumSize().height(), inputC->minimumSize().width() );
795 msg_Dbg( p_intf, "Status minimumsize: %i - %i", statusBar()->minimumSize().height(), statusBar()->minimumSize().width() );
796 msg_Dbg( p_intf, "minimumsize: %i - %i", minimumSize().height(), minimumSize().width() );
798 /*if( videoWidget && videoWidget->isVisible() )
800 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
801 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
806 inline void MainInterface::showTab( int i_tab )
809 msg_Err( p_intf, "showTab %i", i_tab );
810 msg_Warn( p_intf, "Old stackCentralOldState %i", stackCentralOldState );
812 stackCentralOldState = stackCentralW->isVisible() ? stackCentralW->currentIndex()
815 msg_Warn( p_intf, "State change %i %i", stackCentralW->currentIndex(), i_tab );
818 if( i_visualmode == QT_NORMAL_MODE )
820 stackCentralW->setVisible( i_tab != HIDDEN_TAB );
821 doComponentsUpdate(); // resize the player
824 if( i_tab == HIDDEN_TAB ) i_tab = BACKG_TAB;
826 stackCentralW->setCurrentIndex( i_tab );
829 msg_Warn( p_intf, "New stackCentralOldState %i", stackCentralOldState );
833 inline void MainInterface::restoreStackOldWidget()
836 msg_Warn( p_intf, "Old stackCentralOldState %i", stackCentralOldState );
838 int temp = stackCentralW->isVisible() ? stackCentralW->currentIndex()
840 stackCentralW->setCurrentIndex( stackCentralOldState );
841 if( i_visualmode == QT_NORMAL_MODE )
843 stackCentralW->setVisible( stackCentralOldState != HIDDEN_TAB );
844 doComponentsUpdate(); // resize the player
847 stackCentralOldState = temp;
849 msg_Warn( p_intf, "Debug %i %i", temp, stackCentralW->currentIndex() );
853 void MainInterface::destroyPopupMenu()
855 QVLCMenu::PopupMenu( p_intf, false );
858 void MainInterface::toggleFSC()
860 if( !fullscreenControls ) return;
862 IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
863 QApplication::postEvent( fullscreenControls, eShow );
866 void MainInterface::popupMenu( const QPoint &p )
868 /* Ow, that's ugly: don't show the popup menu if cursor over
869 * the main menu bar or the status bar */
870 if( !childAt( p ) || ( ( childAt( p ) != menuBar() )
871 && ( childAt( p )->parentWidget() != statusBar() ) ) )
872 QVLCMenu::PopupMenu( p_intf, true );
875 /****************************************************************************
877 ****************************************************************************/
879 /* This event is used to deal with the fullscreen and always on top
880 issue conflict (bug in wx) */
881 class SetVideoOnTopQtEvent : public QEvent
884 SetVideoOnTopQtEvent( bool _onTop ) :
885 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
888 bool OnTop() const { return onTop; }
896 * You must note change the state of this object or other Qt4 UI objects,
897 * from the video output thread - only from the Qt4 UI main loop thread.
898 * All window provider queries must be handled through signals or events.
899 * That's why we have all those emit statements...
901 WId MainInterface::getVideo( int *pi_x, int *pi_y,
902 unsigned int *pi_width, unsigned int *pi_height )
907 /* This is a blocking call signal. Results are returned through pointers.
908 * Beware of deadlocks! */
910 emit askGetVideo( &id, pi_x, pi_y, pi_width, pi_height );
914 void MainInterface::getVideoSlot( WId *p_id, int *pi_x, int *pi_y,
915 unsigned *pi_width, unsigned *pi_height )
917 /* Request the videoWidget */
918 WId ret = videoWidget->request( pi_x, pi_y,
919 pi_width, pi_height, b_keep_size );
921 if( ret ) /* The videoWidget is available */
923 /* ask videoWidget to show */
924 videoWidget->SetSizing( *pi_width, *pi_height );
926 /* Consider the video active now */
929 stackCentralW->resize( *pi_width, *pi_height );
937 /* Asynchronous call from the WindowClose function */
938 void MainInterface::releaseVideo( void )
940 emit askReleaseVideo( );
943 /* Function that is CONNECTED to the previous emit */
944 void MainInterface::releaseVideoSlot( void )
946 videoWidget->release( );
948 restoreStackOldWidget();
950 /* Try to resize, except when you are in Fullscreen mode */
951 // doComponentsUpdate();
954 /* Asynchronous call from WindowControl function */
955 int MainInterface::controlVideo( int i_query, va_list args )
957 /* Debug to check if VOUT_WINDOW_SET_SIZE is called, because this is broken now */
958 msg_Warn( p_intf, "Control Video: %i", i_query );
961 case VOUT_WINDOW_SET_SIZE:
963 unsigned int i_width = va_arg( args, unsigned int );
964 unsigned int i_height = va_arg( args, unsigned int );
965 emit askVideoToResize( i_width, i_height );
969 case VOUT_WINDOW_SET_STATE:
971 unsigned i_arg = va_arg( args, unsigned );
972 unsigned on_top = i_arg & VOUT_WINDOW_STATE_ABOVE;
973 QApplication::postEvent( this, new SetVideoOnTopQtEvent( on_top ) );
976 case VOUT_WINDOW_SET_FULLSCREEN:
978 bool b_fs = va_arg( args, int );
979 emit askVideoSetFullScreen( b_fs );
983 msg_Warn( p_intf, "unsupported control query" );
988 /*****************************************************************************
989 * Playlist, Visualisation and Menus handling
990 *****************************************************************************/
992 * Toggle the playlist widget or dialog
994 void MainInterface::createPlaylist( bool b_show )
996 playlistWidget = new PlaylistWidget( p_intf, this );
998 i_pl_dock = PL_BOTTOM;
999 /* i_pl_dock = (pl_dock_e)getSettings()
1000 ->value( "pl-dock-status", PL_UNDOCKED ).toInt(); */
1002 if( i_pl_dock == PL_UNDOCKED )
1004 playlistWidget->setWindowFlags( Qt::Window );
1006 /* This will restore the geometry but will not work for position,
1007 because of parenting */
1008 QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
1009 playlistWidget, QSize( 600, 300 ) );
1014 msg_Warn( p_intf, "Here %i", stackCentralW->currentIndex() );
1016 stackCentralW->insertWidget( PLAYL_TAB, playlistWidget );
1018 msg_Warn( p_intf, "Here %i", stackCentralW->currentIndex() );
1024 playlistVisible = true;
1025 stackCentralW->show();
1029 void MainInterface::togglePlaylist()
1032 msg_Warn( p_intf, "Here toggling %i %i", stackCentralW->currentIndex(), stackCentralOldState );
1034 if( !playlistWidget )
1036 createPlaylist( true );
1039 msg_Warn( p_intf, "Here toggling %i %i", stackCentralW->currentIndex(), stackCentralOldState );
1042 if( i_pl_dock != PL_UNDOCKED )
1044 /* Playlist not visible */
1045 if( stackCentralW->currentIndex() != PLAYL_TAB )
1047 showTab( PLAYL_TAB );
1048 stackCentralW->show();
1052 restoreStackOldWidget();
1054 playlistVisible = ( stackCentralW->currentIndex() == PLAYL_TAB );
1055 //doComponentsUpdate(); //resize( sizeHint() );
1059 /* Function called from the menu to undock the playlist */
1060 void MainInterface::undockPlaylist()
1062 // dockPL->setFloating( true );
1066 void MainInterface::dockPlaylist( pl_dock_e i_pos )
1070 void MainInterface::toggleMinimalView( bool b_switch )
1072 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
1073 i_visualmode != QT_MINIMAL_MODE )
1074 { /* NORMAL MODE then */
1075 stackCentralW->show();
1076 if( !videoWidget || stackCentralW->currentIndex() != VIDEO_TAB )
1082 /* If video is visible, then toggle the status of bgWidget */
1083 //bgWasVisible = !bgWasVisible;
1084 if( stackCentralOldState == BACKG_TAB )
1085 stackCentralOldState = HIDDEN_TAB;
1087 stackCentralOldState = BACKG_TAB;
1091 i_bg_height = stackCentralW->height();
1093 menuBar()->setVisible( !b_switch );
1094 controls->setVisible( !b_switch );
1095 statusBar()->setVisible( !b_switch );
1096 inputC->setVisible( !b_switch );
1098 doComponentsUpdate();
1100 emit minimalViewToggled( b_switch );
1103 /* toggling advanced controls buttons */
1104 void MainInterface::toggleAdvanced()
1106 controls->toggleAdvanced();
1107 // if( fullscreenControls ) fullscreenControls->toggleAdvanced();
1110 /* Get the visibility status of the controls (hidden or not, advanced or not) */
1111 int MainInterface::getControlsVisibilityStatus()
1113 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
1114 + CONTROLS_ADVANCED * controls->b_advancedVisible );
1118 void MainInterface::visual()
1120 if( !VISIBLE( visualSelector) )
1122 visualSelector->show();
1123 if( !THEMIM->getIM()->hasVideo() )
1125 /* Show the background widget */
1127 visualSelectorEnabled = true;
1131 /* Stop any currently running visualization */
1132 visualSelector->hide();
1133 visualSelectorEnabled = false;
1135 doComponentsUpdate();
1139 /************************************************************************
1141 ************************************************************************/
1142 void MainInterface::setName( const QString& name )
1144 input_name = name; /* store it for the QSystray use */
1145 /* Display it in the status bar, but also as a Tooltip in case it doesn't
1147 nameLabel->setText( " " + name + " " );
1148 nameLabel->setToolTip( " " + name +" " );
1152 * Give the decorations of the Main Window a correct Name.
1153 * If nothing is given, set it to VLC...
1155 void MainInterface::setVLCWindowsTitle( const QString& aTitle )
1157 if( aTitle.isEmpty() )
1159 setWindowTitle( qtr( "VLC media player" ) );
1163 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
1167 void MainInterface::showCryptedLabel( bool b_show )
1169 if( cryptedLabel == NULL )
1171 cryptedLabel = new QLabel;
1172 // The lock icon is not the right one for DRM protection/scrambled.
1173 //cryptedLabel->setPixmap( QPixmap( ":/lock" ) );
1174 cryptedLabel->setText( "DRM" );
1175 statusBar()->addWidget( cryptedLabel );
1178 cryptedLabel->setVisible( b_show );
1181 /*****************************************************************************
1182 * Systray Icon and Systray Menu
1183 *****************************************************************************/
1186 * Create a SystemTray icon and a menu that would go with it.
1187 * Connects to a click handler on the icon.
1189 void MainInterface::createSystray()
1192 if( QDate::currentDate().dayOfYear() >= 354 )
1193 iconVLC = QIcon( ":/logo/vlc128-christmas.png" );
1195 iconVLC = QIcon( ":/logo/vlc128.png" );
1196 sysTray = new QSystemTrayIcon( iconVLC, this );
1197 sysTray->setToolTip( qtr( "VLC media player" ));
1199 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
1200 systrayMenu->setIcon( iconVLC );
1202 QVLCMenu::updateSystrayMenu( this, p_intf, true );
1205 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
1206 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
1210 * Updates the Systray Icon's menu and toggle the main interface
1212 void MainInterface::toggleUpdateSystrayMenu()
1214 /* If hidden, show it */
1220 else if( isMinimized() )
1228 /* Visible (possibly under other windows) */
1230 /* check if any visible window is above vlc in the z-order,
1231 * but ignore the ones always on top
1232 * and the ones which can't be activated */
1235 wi.cbSize = sizeof( WINDOWINFO );
1236 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
1237 hwnd && ( !IsWindowVisible( hwnd ) ||
1238 ( GetWindowInfo( hwnd, &wi ) &&
1239 (wi.dwExStyle&WS_EX_NOACTIVATE) ) );
1240 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
1241 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
1242 (wi.dwExStyle&WS_EX_TOPMOST) )
1254 QVLCMenu::updateSystrayMenu( this, p_intf );
1257 void MainInterface::handleSystrayClick(
1258 QSystemTrayIcon::ActivationReason reason )
1262 case QSystemTrayIcon::Trigger:
1263 case QSystemTrayIcon::DoubleClick:
1264 toggleUpdateSystrayMenu();
1266 case QSystemTrayIcon::MiddleClick:
1267 sysTray->showMessage( qtr( "VLC media player" ),
1268 qtr( "Control menu for the player" ),
1269 QSystemTrayIcon::Information, 3000 );
1277 * Updates the name of the systray Icon tooltip.
1278 * Doesn't check if the systray exists, check before you call it.
1280 void MainInterface::updateSystrayTooltipName( const QString& name )
1282 if( name.isEmpty() )
1284 sysTray->setToolTip( qtr( "VLC media player" ) );
1288 sysTray->setToolTip( name );
1289 if( notificationEnabled && ( isHidden() || isMinimized() ) )
1291 sysTray->showMessage( qtr( "VLC media player" ), name,
1292 QSystemTrayIcon::NoIcon, 3000 );
1296 QVLCMenu::updateSystrayMenu( this, p_intf );
1300 * Updates the status of the systray Icon tooltip.
1301 * Doesn't check if the systray exists, check before you call it.
1303 void MainInterface::updateSystrayTooltipStatus( int i_status )
1310 sysTray->setToolTip( qtr( "VLC media player" ) );
1315 sysTray->setToolTip( input_name );
1320 sysTray->setToolTip( input_name + " - "
1325 QVLCMenu::updateSystrayMenu( this, p_intf );
1329 /************************************************************************
1331 ************************************************************************/
1332 void MainInterface::dropEvent(QDropEvent *event)
1334 dropEventPlay( event, true );
1337 void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
1339 event->setDropAction( Qt::CopyAction );
1340 if( !event->possibleActions() & Qt::CopyAction )
1343 const QMimeData *mimeData = event->mimeData();
1345 /* D&D of a subtitles file, add it on the fly */
1346 if( mimeData->urls().size() == 1 && THEMIM->getIM()->hasInput() )
1348 if( !input_AddSubtitle( THEMIM->getInput(),
1349 qtu( toNativeSeparators( mimeData->urls()[0].toLocalFile() ) ),
1357 bool first = b_play;
1358 foreach( const QUrl &url, mimeData->urls() )
1360 QString s = toNativeSeparators( url.toLocalFile() );
1362 if( s.length() > 0 ) {
1363 char* psz_uri = make_URI( qtu(s) );
1364 playlist_Add( THEPL, psz_uri, NULL,
1365 PLAYLIST_APPEND | (first ? PLAYLIST_GO: PLAYLIST_PREPARSE),
1366 PLAYLIST_END, true, pl_Unlocked );
1369 RecentsMRL::getInstance( p_intf )->addRecent( s );
1374 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1376 event->acceptProposedAction();
1378 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1380 event->acceptProposedAction();
1382 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1387 /************************************************************************
1389 ************************************************************************/
1390 void MainInterface::customEvent( QEvent *event )
1393 if( event->type() == PLDockEvent_Type )
1395 PlaylistDialog::killInstance();
1396 playlistEmbeddedFlag = true;
1398 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1403 if ( event->type() == (int)SetVideoOnTopEvent_Type )
1405 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1406 if( p_event->OnTop() )
1407 setWindowFlags( windowFlags() | Qt::WindowStaysOnTopHint );
1409 setWindowFlags( windowFlags() & ~Qt::WindowStaysOnTopHint );
1410 show(); /* necessary to apply window flags */
1414 void MainInterface::keyPressEvent( QKeyEvent *e )
1416 handleKeyPress( e );
1419 void MainInterface::handleKeyPress( QKeyEvent *e )
1421 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() == Qt::Key_H )
1422 && !menuBar()->isVisible() )
1424 toggleMinimalView( false );
1428 int i_vlck = qtEventToVLCKey( e );
1431 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1438 void MainInterface::resizeEvent( QResizeEvent * event )
1443 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
1444 i_visualmode == QT_MINIMAL_MODE )
1446 mainVideoSize = size();
1450 if( VISIBLE( bgWidget) ||
1451 ( videoIsActive && videoWidget->isVisible() )
1453 mainVideoSize = size();
1455 mainBasedSize = size();
1459 QVLCMW::resizeEvent( event );
1460 msg_Dbg( p_intf, "Resize Event, height: %i", size().height() );
1463 void MainInterface::wheelEvent( QWheelEvent *e )
1465 int i_vlckey = qtWheelEventToVLCKey( e );
1466 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1470 void MainInterface::closeEvent( QCloseEvent *e )
1477 void MainInterface::toggleFullScreen( void )
1479 if( isFullScreen() )
1482 emit askUpdate(); // Needed if video was launched after the F11
1483 emit fullscreenInterfaceToggled( false );
1488 emit fullscreenInterfaceToggled( true );
1493 //moc doesn't know about #ifdef, so we have to build this method for every platform
1494 void MainInterface::changeThumbbarButtons( int i_status)
1497 // Define an array of three buttons. These buttons provide images through an
1498 // image list and also provide tooltips.
1499 DWORD dwMask = THB_BITMAP | THB_FLAGS;
1501 THUMBBUTTON thbButtons[3];
1503 thbButtons[0].dwMask = dwMask;
1504 thbButtons[0].iId = 0;
1505 thbButtons[0].iBitmap = 0;
1508 thbButtons[1].dwMask = dwMask;
1509 thbButtons[1].iId = 1;
1512 thbButtons[2].dwMask = dwMask;
1513 thbButtons[2].iId = 2;
1514 thbButtons[2].iBitmap = 3;
1520 thbButtons[0].dwFlags = THBF_ENABLED;
1521 thbButtons[1].dwFlags = THBF_ENABLED;
1522 thbButtons[2].dwFlags = THBF_ENABLED;
1523 thbButtons[1].iBitmap = 1;
1528 thbButtons[0].dwFlags = THBF_ENABLED;
1529 thbButtons[1].dwFlags = THBF_ENABLED;
1530 thbButtons[2].dwFlags = THBF_ENABLED;
1531 thbButtons[1].iBitmap = 2;
1537 HRESULT hr = p_taskbl->vt->ThumbBarUpdateButtons(p_taskbl, this->winId(), 3, thbButtons);
1539 msg_Err( p_intf, "ThumbBarUpdateButtons failed with error %08x", hr );
1545 /*****************************************************************************
1546 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1547 * We don't show the menu directly here because we don't want the
1548 * caller to block for a too long time.
1549 *****************************************************************************/
1550 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1551 vlc_value_t old_val, vlc_value_t new_val, void *param )
1553 intf_thread_t *p_intf = (intf_thread_t *)param;
1555 if( p_intf->pf_show_dialog )
1557 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1558 new_val.b_bool, NULL );
1564 /*****************************************************************************
1565 * IntfShowCB: callback triggered by the intf-show libvlc variable.
1566 *****************************************************************************/
1567 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1568 vlc_value_t old_val, vlc_value_t new_val, void *param )
1570 intf_thread_t *p_intf = (intf_thread_t *)param;
1571 p_intf->p_sys->p_mi->toggleFSC();