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 *****************************************************************************/
32 #include "main_interface.hpp"
33 #include "input_manager.hpp" // Creation
34 #include "actions_manager.hpp" // killInstance
35 #include "extensions_manager.hpp" // killInstance
37 #include "util/customwidgets.hpp" // qtEventToVLCKey
38 #include "util/qt_dirs.hpp" // toNativeSeparators
40 #include "components/interface_widgets.hpp" // bgWidget, videoWidget
41 #include "components/controller.hpp" // controllers
42 #include "components/playlist/playlist.hpp" // plWidget
43 #include "dialogs/firstrun.hpp" // First Run
45 #include "menus.hpp" // Menu creation
46 #include "recents.hpp" // RecentItems when DnD
48 #include <QCloseEvent>
59 #include <QStackedWidget>
61 #include <vlc_keys.h> /* Wheel event */
62 #include <vlc_vout_display.h> /* vout_thread_t and VOUT_ events */
66 /* Callback prototypes */
67 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
68 vlc_value_t old_val, vlc_value_t new_val, void *param );
69 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
70 vlc_value_t old_val, vlc_value_t new_val, void *param );
72 MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
74 /* Variables initialisation */
77 playlistWidget = NULL;
81 fullscreenControls = NULL;
86 b_hideAfterCreation = false; // --qt-start-minimized
87 playlistVisible = false; // FIXME remove
93 FirstRun::CheckAndRun( this, p_intf );
96 * Configuration and settings
97 * Pre-building of interface
100 setFocusPolicy( Qt::StrongFocus );
101 setAcceptDrops( true );
102 setWindowRole( "vlc-main" );
103 setWindowIcon( QApplication::windowIcon() );
104 setWindowOpacity( var_InheritFloat( p_intf, "qt-opacity" ) );
106 /* Is video in embedded in the UI or not */
107 b_videoEmbedded = var_InheritBool( p_intf, "embedded-video" );
109 /* Does the interface resize to video size or the opposite */
110 b_keep_size = !var_InheritBool( p_intf, "qt-video-autoresize" );
112 /* Are we in the enhanced always-video mode or not ? */
113 i_visualmode = var_InheritInteger( p_intf, "qt-minimal-view" );
115 /* Do we want anoying popups or not */
116 b_notificationEnabled = var_InheritBool( p_intf, "qt-notification" );
118 /* Set the other interface settings */
119 settings = getSettings();
120 settings->beginGroup( "MainWindow" );
123 b_plDocked = getSettings()->value( "pl-dock-status", true ).toBool();
127 * Retrieve saved sizes for main window
128 * mainBasedSize = based window size for normal mode
129 * (no video, no background)
130 * mainVideoSize = window size with video (all modes)
132 mainBasedSize = settings->value( "mainBasedSize", QSize( 350, 120 ) ).toSize();
133 mainVideoSize = settings->value( "mainVideoSize", QSize( 400, 300 ) ).toSize();
141 /**************************
142 * UI and Widgets design
143 **************************/
144 setVLCWindowsTitle();
145 createMainWidget( settings );
150 QVLCMenu::createMenuBar( this, p_intf );
151 CONNECT( THEMIM->getIM(), voutListChanged( vout_thread_t **, int ),
152 this, destroyPopupMenu() );
154 /*********************************
155 * Create the Systray Management *
156 *********************************/
159 /********************
161 ********************/
162 MainInputManager::getInstance( p_intf );
167 taskbar_wmsg = RegisterWindowMessage("TaskbarButtonCreated");
170 /************************************************************
171 * Connect the input manager to the GUI elements it manages *
172 ************************************************************/
174 * Connects on nameChanged()
175 * Those connects are different because options can impeach them to trigger.
177 /* Main Interface statusbar */
178 CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
179 this, setName( const QString& ) );
184 CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
185 this, updateSystrayTooltipName( const QString& ) );
188 /* and title of the Main Interface*/
189 if( var_InheritBool( p_intf, "qt-name-in-title" ) )
191 CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
192 this, setVLCWindowsTitle( const QString& ) );
196 * CONNECTS on PLAY_STATUS
198 /* Status on the systray */
202 CONNECT( THEMIM->getIM(), statusChanged( int ),
203 this, updateSystrayTooltipStatus( int ) );
207 /* END CONNECTS ON IM */
209 /* VideoWidget connects for asynchronous calls */
210 connect( this, SIGNAL(askGetVideo(WId*,int*,int*,unsigned*,unsigned *)),
211 this, SLOT(getVideoSlot(WId*,int*,int*,unsigned*,unsigned*)),
212 Qt::BlockingQueuedConnection );
213 connect( this, SIGNAL(askReleaseVideo( void )),
214 this, SLOT(releaseVideoSlot( void )),
215 Qt::BlockingQueuedConnection );
219 CONNECT( this, askVideoToResize( unsigned int, unsigned int ),
220 videoWidget, SetSizing( unsigned int, unsigned int ) );
221 CONNECT( this, askVideoSetFullScreen( bool ),
222 videoWidget, SetFullScreen( bool ) );
223 CONNECT( videoWidget, keyPressed( QKeyEvent * ),
224 this, handleKeyPress( QKeyEvent * ) );
227 CONNECT( this, askUpdate(), this, doComponentsUpdate() );
228 CONNECT( THEDP, toolBarConfUpdated(), this, recreateToolbars() );
230 /* Enable the popup menu in the MI */
231 setContextMenuPolicy( Qt::CustomContextMenu );
232 CONNECT( this, customContextMenuRequested( const QPoint& ),
233 this, popupMenu( const QPoint& ) );
235 /** END of CONNECTS**/
241 var_AddCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
243 /* Register callback for the intf-popupmenu variable */
244 var_AddCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
246 /**** FINAL SIZING and placement of interface */
247 settings->beginGroup( "MainWindow" );
248 QVLCTools::restoreWidgetPosition( settings, this, QSize(400, 100) );
250 /* resize to previously saved main window size if appicable */
255 resize( mainVideoSize );
257 resize( mainBasedSize );
261 int i_plVis = settings->value( "playlist-visible", 0 ).toInt();
263 settings->endGroup();
265 if( i_plVis ) togglePlaylist();
267 /* Final sizing and showing */
268 setVisible( !b_hideAfterCreation );
270 setMinimumWidth( __MAX( controls->sizeHint().width(),
271 menuBar()->sizeHint().width() ) + 30 );
273 /* Switch to minimal view if needed, must be called after the show() */
275 toggleMinimalView( true );
278 MainInterface::~MainInterface()
280 /* Unsure we hide the videoWidget before destroying it */
281 if( stackCentralOldWidget == playlistWidget )
284 /* Save playlist state */
288 QVLCTools::saveWidgetPosition( p_intf, "Playlist", playlistWidget );
290 delete playlistWidget;
295 ImageList_Destroy( himl );
297 p_taskbl->vt->Release(p_taskbl);
301 /* Be sure to kill the actionsManager... FIXME */
302 ActionsManager::killInstance();
305 ExtensionsManager::killInstance();
307 /* Delete the FSC controller */
308 delete fullscreenControls;
311 settings->beginGroup( "MainWindow" );
312 settings->setValue( "pl-dock-status", b_plDocked );
313 settings->setValue( "playlist-visible", (int)playlistVisible );
314 settings->setValue( "adv-controls",
315 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
317 settings->setValue( "mainBasedSize", mainBasedSize );
318 settings->setValue( "mainVideoSize", mainVideoSize );
320 settings->setValue( "backgroundSize", bgWidget->size() );
323 QVLCTools::saveWidgetPosition(settings, this);
324 settings->endGroup();
328 /* Unregister callbacks */
329 var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
330 var_DelCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
332 p_intf->p_sys->p_mi = NULL;
335 /*****************************
337 *****************************/
338 void MainInterface::recreateToolbars()
340 // FIXME: do the same for the FSC
341 //msg_Dbg( p_intf, "Recreating the toolbars" );
342 settings->beginGroup( "MainWindow" );
346 controls = new ControlsWidget( p_intf, false, this ); /* FIXME */
347 CONNECT( controls, advancedControlsToggled( bool ),
348 this, doComponentsUpdate() );
349 CONNECT( controls, sizeChanged(),
350 this, doComponentsUpdate() );
352 inputC = new InputControlsWidget( p_intf, this );
354 mainLayout->insertWidget( 2, inputC );
355 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
357 settings->endGroup();
360 void MainInterface::createMainWidget( QSettings *settings )
362 /* Create the main Widget and the mainLayout */
363 QWidget *main = new QWidget;
364 setCentralWidget( main );
365 mainLayout = new QVBoxLayout( main );
366 main->setContentsMargins( 0, 0, 0, 0 );
367 mainLayout->setSpacing( 0 ); mainLayout->setMargin( 0 );
370 stackCentralW = new QStackedWidget( main );
373 bgWidget = new BackgroundWidget( p_intf );
374 stackCentralW->addWidget( bgWidget );
376 /* And video Outputs */
377 if( b_videoEmbedded )
379 videoWidget = new VideoWidget( p_intf );
380 stackCentralW->addWidget( videoWidget );
382 mainLayout->insertWidget( 1, stackCentralW );
384 /* Create the CONTROLS Widget */
385 controls = new ControlsWidget( p_intf,
386 settings->value( "adv-controls", false ).toBool(), this );
387 CONNECT( controls, advancedControlsToggled( bool ),
388 this, doComponentsUpdate() );
389 CONNECT( controls, sizeChanged(),
390 this, doComponentsUpdate() );
391 inputC = new InputControlsWidget( p_intf, this );
393 mainLayout->insertWidget( 2, inputC );
394 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
397 /* Visualisation, disabled for now, they SUCK */
399 visualSelector = new VisualSelector( p_intf );
400 mainLayout->insertWidget( 0, visualSelector );
401 visualSelector->hide();
404 getSettings()->endGroup();
406 if ( depth() > 8 ) /* 8bit depth has too many issues with opacity */
407 /* Create the FULLSCREEN CONTROLS Widget */
408 if( var_InheritBool( p_intf, "qt-fs-controller" ) )
410 fullscreenControls = new FullscreenControllerWidget( p_intf, this );
411 CONNECT( fullscreenControls, keyPressed( QKeyEvent * ),
412 this, handleKeyPress( QKeyEvent * ) );
416 inline void MainInterface::initSystray()
419 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
420 bool b_systrayWanted = var_InheritBool( p_intf, "qt-system-tray" );
422 if( var_InheritBool( p_intf, "qt-start-minimized") )
424 if( b_systrayAvailable )
426 b_systrayWanted = true;
427 b_hideAfterCreation = true;
430 msg_Err( p_intf, "cannot start minimized without system tray bar" );
433 if( b_systrayAvailable && b_systrayWanted )
438 inline void MainInterface::createStatusBar()
443 /* Widgets Creation*/
444 QStatusBar *statusBarr = statusBar();
446 TimeLabel *timeLabel = new TimeLabel( p_intf );
447 nameLabel = new QLabel( this );
448 nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
449 | Qt::TextSelectableByKeyboard );
450 SpeedLabel *speedLabel = new SpeedLabel( p_intf, this );
452 /* Styling those labels */
453 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
454 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
455 nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
457 /* and adding those */
458 statusBarr->addWidget( nameLabel, 8 );
459 statusBarr->addPermanentWidget( speedLabel, 0 );
460 statusBarr->addPermanentWidget( timeLabel, 0 );
462 /* timeLabel behaviour:
463 - double clicking opens the goto time dialog
464 - right-clicking and clicking just toggle between remaining and
466 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
468 CONNECT( THEMIM->getIM(), encryptionChanged( bool ),
469 this, showCryptedLabel( bool ) );
471 CONNECT( THEMIM->getIM(), seekRequested( float ),
472 timeLabel, setDisplayPosition( float ) );
475 /**********************************************************************
476 * Handling of sizing of the components
477 **********************************************************************/
479 /* This function is probably wrong, but we don't have many many choices...
480 Since we can't know from the playlist Widget if we are inside a dock or not,
481 because the playlist Widget can be called by THEDP, as a separate windows for
483 Maybe the other solution is to redefine the sizeHint() of the playlist and
484 ask _parent->isFloating()...
485 If you think this would be better, please FIXME it...
489 QSize MainInterface::sizeHint() const
496 return mainVideoSize;
500 if( VISIBLE( bgWidget) ||
501 ( videoIsActive && videoWidget->isVisible() )
503 return mainVideoSize;
505 return mainBasedSize;
510 int nwidth = __MAX( controls->sizeHint().width(),
511 menuBar()->sizeHint().width() );
513 int nheight = controls->isVisible() ?
514 controls->size().height()
515 + inputC->size().height()
516 + menuBar()->size().height()
517 + statusBar()->size().height()
520 /* if( stackCentralW->isVisible() )
522 nheight += stackCentralW->height();
523 nwidth = __MAX( nwidth, stackCentralW->width() );
526 /* if( VISIBLE( bgWidget ) )
528 msg_Warn( p_intf, "Hello here" );
530 nheight += i_bg_height;
532 nheight += bgWidget->size().height();
533 nwidth = __MAX( nwidth, bgWidget->size().width() );
535 else if( videoIsActive && videoWidget->isVisible() )
537 msg_Warn( p_intf, "Hello there" );
538 nheight += videoWidget->sizeHint().height();
539 nwidth = __MAX( nwidth, videoWidget->sizeHint().width() );
542 if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget() )
544 nheight += dockPL->size().height();
545 nwidth = __MAX( nwidth, dockPL->size().width() );
546 msg_Warn( p_intf, "3 %i %i", nheight, nwidth );
549 return QSize( nwidth, nheight );
553 /* Video widget cannot do this synchronously as it runs in another thread */
554 /* Well, could it, actually ? Probably dangerous ... */
556 /* This function is called:
557 - toggling of minimal View
558 - through askUpdate() by Vout thread request video and resize video (zoom)
559 - Advanced buttons toggled
561 void MainInterface::doComponentsUpdate()
563 if( isFullScreen() || isMaximized() ) return;
565 // msg_Warn( p_intf, "Updating the geometry" );
566 /* Here we resize to sizeHint() and not adjustsize because we want
567 the videoWidget to be exactly the correctSize */
572 /* This is WRONG, but I believe there is a Qt bug here */
573 setMinimumSize( 0, 0 );
574 //resize( sizeHint() );
576 //adjustSize() ; /* This is not needed, but might help in the future */
579 void MainInterface::debug()
582 msg_Dbg( p_intf, "Stack Size: %i - %i", stackCentralW->size().height(), size().width() );
584 msg_Dbg( p_intf, "Stack Size: %i - %i",
585 videoWidget->size().height(),
586 videoWidget->size().width() );
588 msg_Dbg( p_intf, "no embedded video" );
590 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
591 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
592 //msg_Dbg( p_intf, "maximumsize: %i - %i", maximumSize().height(), maximumSize().width() );
594 msg_Dbg( p_intf, "Stack size: %i - %i", stackCentralW->size().height(), stackCentralW->size().width() );
595 msg_Dbg( p_intf, "Stack minimumSize(): %i - %i", stackCentralW->minimumHeight(), stackCentralW->minimumWidth() );
596 msg_Dbg( p_intf, "Central minimumsize: %i - %i", centralWidget()->minimumSize().height(), centralWidget()->minimumSize().width() );
597 msg_Dbg( p_intf, "Central size: %i - %i", centralWidget()->size().height(), centralWidget()->size().width() );
598 msg_Dbg( p_intf, "Menu minimumsize: %i - %i", menuBar()->minimumSize().height(), menuBar()->minimumSize().width() );
599 msg_Dbg( p_intf, "Input size: %i - %i", inputC->size().height(), inputC->size().width() );
600 msg_Dbg( p_intf, "Status minimumsize: %i - %i", statusBar()->minimumSize().height(), statusBar()->minimumSize().width() );
601 msg_Dbg( p_intf, "minimumsize: %i - %i", minimumSize().height(), minimumSize().width() );
602 msg_Dbg( p_intf, "bg Size: %i - %i", bgWidget->size().height(), bgWidget->size().width() );
604 /*if( videoWidget && videoWidget->isVisible() )
606 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
607 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
612 inline void MainInterface::showVideo() { showTab( videoWidget ); }
613 inline void MainInterface::showBg() { showTab( bgWidget ); }
615 inline void MainInterface::showTab( QWidget *widget )
618 msg_Warn( p_intf, "Old stackCentralOldWidget %i", stackCentralW->indexOf( stackCentralOldWidget ) );
620 stackCentralOldWidget = stackCentralW->currentWidget();
621 stackCentralW->setCurrentWidget( widget );
624 msg_Warn( p_intf, "State change %i", stackCentralW->currentIndex() );
625 msg_Warn( p_intf, "New stackCentralOldWidget %i", stackCentralW->indexOf( stackCentralOldWidget ) );
629 inline void MainInterface::restoreStackOldWidget()
632 msg_Warn( p_intf, "New stackCentralOldWidget %i", stackCentralW->indexOf( stackCentralOldWidget ) );
634 QWidget *wTemp = stackCentralW->currentWidget();
636 stackCentralW->setCurrentWidget( stackCentralOldWidget );
638 stackCentralOldWidget = wTemp;
640 msg_Warn( p_intf, "Debug %i %i",stackCentralW->indexOf( wTemp ), stackCentralW->indexOf( stackCentralW->currentWidget() ) );
644 void MainInterface::destroyPopupMenu()
646 QVLCMenu::PopupMenu( p_intf, false );
649 void MainInterface::popupMenu( const QPoint &p )
652 * Ow, that's ugly: don't show the popup menu if cursor over
653 * the main menu bar or the status bar */
654 if( !childAt( p ) || ( ( childAt( p ) != menuBar() )
655 && ( childAt( p )->parentWidget() != statusBar() ) ) )
656 QVLCMenu::PopupMenu( p_intf, true );
659 void MainInterface::toggleFSC()
661 if( !fullscreenControls ) return;
663 IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
664 QApplication::postEvent( fullscreenControls, eShow );
667 /****************************************************************************
669 ****************************************************************************/
671 /* This event is used to deal with the fullscreen and always on top
672 issue conflict (bug in wx) */
673 class SetVideoOnTopQtEvent : public QEvent
676 SetVideoOnTopQtEvent( bool _onTop ) :
677 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
680 bool OnTop() const { return onTop; }
688 * You must not change the state of this object or other Qt4 UI objects,
689 * from the video output thread - only from the Qt4 UI main loop thread.
690 * All window provider queries must be handled through signals or events.
691 * That's why we have all those emit statements...
693 WId MainInterface::getVideo( int *pi_x, int *pi_y,
694 unsigned int *pi_width, unsigned int *pi_height )
699 /* This is a blocking call signal. Results are returned through pointers.
700 * Beware of deadlocks! */
702 emit askGetVideo( &id, pi_x, pi_y, pi_width, pi_height );
706 void MainInterface::getVideoSlot( WId *p_id, int *pi_x, int *pi_y,
707 unsigned *pi_width, unsigned *pi_height )
709 /* Request the videoWidget */
710 WId ret = videoWidget->request( pi_x, pi_y,
711 pi_width, pi_height, b_keep_size );
713 if( ret ) /* The videoWidget is available */
715 /* ask videoWidget to show */
716 videoWidget->SetSizing( *pi_width, *pi_height );
718 /* Consider the video active now */
721 stackCentralW->resize( *pi_width, *pi_height );
729 /* Asynchronous call from the WindowClose function */
730 void MainInterface::releaseVideo( void )
732 emit askReleaseVideo( );
735 /* Function that is CONNECTED to the previous emit */
736 void MainInterface::releaseVideoSlot( void )
738 videoWidget->release( );
740 restoreStackOldWidget();
742 /* We don't want to have a blank video to popup */
743 stackCentralOldWidget = bgWidget;
745 /* Try to resize, except when you are in Fullscreen mode */
746 // doComponentsUpdate();
749 /* Asynchronous call from WindowControl function */
750 int MainInterface::controlVideo( int i_query, va_list args )
752 /* Debug to check if VOUT_WINDOW_SET_SIZE is called, because this is broken now */
753 msg_Warn( p_intf, "Control Video: %i", i_query );
756 case VOUT_WINDOW_SET_SIZE:
758 unsigned int i_width = va_arg( args, unsigned int );
759 unsigned int i_height = va_arg( args, unsigned int );
760 emit askVideoToResize( i_width, i_height );
764 case VOUT_WINDOW_SET_STATE:
766 unsigned i_arg = va_arg( args, unsigned );
767 unsigned on_top = i_arg & VOUT_WINDOW_STATE_ABOVE;
768 QApplication::postEvent( this, new SetVideoOnTopQtEvent( on_top ) );
771 case VOUT_WINDOW_SET_FULLSCREEN:
773 bool b_fs = va_arg( args, int );
774 emit askVideoSetFullScreen( b_fs );
778 msg_Warn( p_intf, "unsupported control query" );
783 /*****************************************************************************
784 * Playlist, Visualisation and Menus handling
785 *****************************************************************************/
787 * Toggle the playlist widget or dialog
789 void MainInterface::createPlaylist()
791 playlistWidget = new PlaylistWidget( p_intf, this );
795 playlistWidget->setWindowFlags( Qt::Window );
797 /* This will restore the geometry but will not work for position,
798 because of parenting */
799 QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
800 playlistWidget, QSize( 600, 300 ) );
804 stackCentralW->addWidget( playlistWidget );
808 void MainInterface::togglePlaylist()
810 if( !playlistWidget )
815 /* Playlist is not visible, show it */
816 if( stackCentralW->currentWidget() != playlistWidget )
818 playlistWidget->forceShow();
819 showTab( playlistWidget );
823 restoreStackOldWidget();
824 stackCentralW->updateGeometry();
825 // HACK: So it doesn't limit the stackWidget minimumSize
826 playlistWidget->forceHide();
828 playlistVisible = ( stackCentralW->currentWidget() == playlistWidget );
832 playlistWidget->setWindowFlags( Qt::Window );
833 playlistVisible = !playlistVisible;
834 playlistWidget->setVisible( playlistVisible );
839 void MainInterface::dockPlaylist( bool p_docked )
841 if( b_plDocked == p_docked ) return;
842 b_plDocked = p_docked;
844 if( !playlistWidget ) return; /* Playlist wasn't created yet */
847 stackCentralW->removeWidget( playlistWidget );
848 playlistWidget->setWindowFlags( Qt::Window );
849 QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
850 playlistWidget, QSize( 600, 300 ) );
851 playlistWidget->show();
852 restoreStackOldWidget();
856 playlistWidget->setWindowFlags( Qt::Widget ); // Probably a Qt bug here
857 // It would be logical that QStackWidget::addWidget reset the flags...
858 stackCentralW->addWidget( playlistWidget );
859 stackCentralW->setCurrentWidget( playlistWidget );
863 void MainInterface::toggleMinimalView( bool b_switch )
865 if( i_visualmode == 0 )
866 { /* NORMAL MODE then */
867 if( !videoWidget || stackCentralW->currentWidget() != videoWidget )
873 /* If video is visible, then toggle the status of bgWidget */
875 //bgWasVisible = !bgWasVisible;
876 /* if( stackCentralOldState == BACK G_TAB )
877 stackCentralOldState = HID DEN_TAB;
879 stackCentralOldState = BACK G_TAB;
885 i_bg_height = stackCentralW->height();
887 menuBar()->setVisible( !b_switch );
888 controls->setVisible( !b_switch );
889 statusBar()->setVisible( !b_switch );
890 inputC->setVisible( !b_switch );
892 doComponentsUpdate();
894 emit minimalViewToggled( b_switch );
897 /* toggling advanced controls buttons */
898 void MainInterface::toggleAdvanced()
900 controls->toggleAdvanced();
901 // if( fullscreenControls ) fullscreenControls->toggleAdvanced();
904 /* Get the visibility status of the controls (hidden or not, advanced or not) */
905 int MainInterface::getControlsVisibilityStatus()
907 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
908 + CONTROLS_ADVANCED * controls->b_advancedVisible );
912 void MainInterface::visual()
914 if( !VISIBLE( visualSelector) )
916 visualSelector->show();
917 if( !THEMIM->getIM()->hasVideo() )
919 /* Show the background widget */
921 visualSelectorEnabled = true;
925 /* Stop any currently running visualization */
926 visualSelector->hide();
927 visualSelectorEnabled = false;
929 doComponentsUpdate();
933 /************************************************************************
935 ************************************************************************/
936 void MainInterface::setName( const QString& name )
938 input_name = name; /* store it for the QSystray use */
939 /* Display it in the status bar, but also as a Tooltip in case it doesn't
941 nameLabel->setText( " " + name + " " );
942 nameLabel->setToolTip( " " + name +" " );
946 * Give the decorations of the Main Window a correct Name.
947 * If nothing is given, set it to VLC...
949 void MainInterface::setVLCWindowsTitle( const QString& aTitle )
951 if( aTitle.isEmpty() )
953 setWindowTitle( qtr( "VLC media player" ) );
957 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
961 void MainInterface::showCryptedLabel( bool b_show )
963 if( cryptedLabel == NULL )
965 cryptedLabel = new QLabel;
966 // The lock icon is not the right one for DRM protection/scrambled.
967 //cryptedLabel->setPixmap( QPixmap( ":/lock" ) );
968 cryptedLabel->setText( "DRM" );
969 statusBar()->addWidget( cryptedLabel );
972 cryptedLabel->setVisible( b_show );
975 void MainInterface::showBuffering( float f_cache )
977 QString amount = QString("Buffering: %1%").arg( (int)(100*f_cache) );
978 statusBar()->showMessage( amount, 1000 );
981 /*****************************************************************************
982 * Systray Icon and Systray Menu
983 *****************************************************************************/
986 * Create a SystemTray icon and a menu that would go with it.
987 * Connects to a click handler on the icon.
989 void MainInterface::createSystray()
992 if( QDate::currentDate().dayOfYear() >= 354 )
993 iconVLC = QIcon( ":/logo/vlc128-christmas.png" );
995 iconVLC = QIcon( ":/logo/vlc128.png" );
996 sysTray = new QSystemTrayIcon( iconVLC, this );
997 sysTray->setToolTip( qtr( "VLC media player" ));
999 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
1000 systrayMenu->setIcon( iconVLC );
1002 QVLCMenu::updateSystrayMenu( this, p_intf, true );
1005 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
1006 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
1010 * Updates the Systray Icon's menu and toggle the main interface
1012 void MainInterface::toggleUpdateSystrayMenu()
1014 /* If hidden, show it */
1020 else if( isMinimized() )
1028 /* Visible (possibly under other windows) */
1030 /* check if any visible window is above vlc in the z-order,
1031 * but ignore the ones always on top
1032 * and the ones which can't be activated */
1035 wi.cbSize = sizeof( WINDOWINFO );
1036 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
1037 hwnd && ( !IsWindowVisible( hwnd ) ||
1038 ( GetWindowInfo( hwnd, &wi ) &&
1039 (wi.dwExStyle&WS_EX_NOACTIVATE) ) );
1040 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
1041 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
1042 (wi.dwExStyle&WS_EX_TOPMOST) )
1054 QVLCMenu::updateSystrayMenu( this, p_intf );
1057 void MainInterface::handleSystrayClick(
1058 QSystemTrayIcon::ActivationReason reason )
1062 case QSystemTrayIcon::Trigger:
1063 case QSystemTrayIcon::DoubleClick:
1064 toggleUpdateSystrayMenu();
1066 case QSystemTrayIcon::MiddleClick:
1067 sysTray->showMessage( qtr( "VLC media player" ),
1068 qtr( "Control menu for the player" ),
1069 QSystemTrayIcon::Information, 3000 );
1077 * Updates the name of the systray Icon tooltip.
1078 * Doesn't check if the systray exists, check before you call it.
1080 void MainInterface::updateSystrayTooltipName( const QString& name )
1082 if( name.isEmpty() )
1084 sysTray->setToolTip( qtr( "VLC media player" ) );
1088 sysTray->setToolTip( name );
1089 if( b_notificationEnabled && ( isHidden() || isMinimized() ) )
1091 sysTray->showMessage( qtr( "VLC media player" ), name,
1092 QSystemTrayIcon::NoIcon, 3000 );
1096 QVLCMenu::updateSystrayMenu( this, p_intf );
1100 * Updates the status of the systray Icon tooltip.
1101 * Doesn't check if the systray exists, check before you call it.
1103 void MainInterface::updateSystrayTooltipStatus( int i_status )
1110 sysTray->setToolTip( qtr( "VLC media player" ) );
1115 sysTray->setToolTip( input_name );
1120 sysTray->setToolTip( input_name + " - "
1125 QVLCMenu::updateSystrayMenu( this, p_intf );
1129 /************************************************************************
1131 ************************************************************************/
1132 void MainInterface::dropEvent(QDropEvent *event)
1134 dropEventPlay( event, true );
1137 void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
1139 event->setDropAction( Qt::CopyAction );
1140 if( !event->possibleActions() & Qt::CopyAction )
1143 const QMimeData *mimeData = event->mimeData();
1145 /* D&D of a subtitles file, add it on the fly */
1146 if( mimeData->urls().size() == 1 && THEMIM->getIM()->hasInput() )
1148 if( !input_AddSubtitle( THEMIM->getInput(),
1149 qtu( toNativeSeparators( mimeData->urls()[0].toLocalFile() ) ),
1157 bool first = b_play;
1158 foreach( const QUrl &url, mimeData->urls() )
1160 QString s = toNativeSeparators( url.toLocalFile() );
1162 if( s.length() > 0 ) {
1163 char* psz_uri = make_URI( qtu(s) );
1164 playlist_Add( THEPL, psz_uri, NULL,
1165 PLAYLIST_APPEND | (first ? PLAYLIST_GO: PLAYLIST_PREPARSE),
1166 PLAYLIST_END, true, pl_Unlocked );
1169 RecentsMRL::getInstance( p_intf )->addRecent( s );
1174 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1176 event->acceptProposedAction();
1178 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1180 event->acceptProposedAction();
1182 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1187 /************************************************************************
1189 ************************************************************************/
1190 void MainInterface::customEvent( QEvent *event )
1193 if( event->type() == PLDockEvent_Type )
1195 PlaylistDialog::killInstance();
1196 playlistEmbeddedFlag = true;
1198 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1203 if ( event->type() == (int)SetVideoOnTopEvent_Type )
1205 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1206 if( p_event->OnTop() )
1207 setWindowFlags( windowFlags() | Qt::WindowStaysOnTopHint );
1209 setWindowFlags( windowFlags() & ~Qt::WindowStaysOnTopHint );
1210 show(); /* necessary to apply window flags */
1214 void MainInterface::keyPressEvent( QKeyEvent *e )
1216 handleKeyPress( e );
1219 void MainInterface::handleKeyPress( QKeyEvent *e )
1221 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() == Qt::Key_H )
1222 && !menuBar()->isVisible() )
1224 toggleMinimalView( false );
1228 int i_vlck = qtEventToVLCKey( e );
1231 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1238 void MainInterface::resizeEvent( QResizeEvent * event )
1245 mainVideoSize = size();
1249 if( VISIBLE( bgWidget) ||
1250 ( videoIsActive && videoWidget->isVisible() )
1252 mainVideoSize = size();
1254 mainBasedSize = size();
1258 QVLCMW::resizeEvent( event );
1259 msg_Dbg( p_intf, "Resize Event, height: %i", size().height() );
1263 void MainInterface::wheelEvent( QWheelEvent *e )
1265 int i_vlckey = qtWheelEventToVLCKey( e );
1266 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1270 void MainInterface::closeEvent( QCloseEvent *e )
1277 void MainInterface::toggleFullScreen( void )
1279 if( isFullScreen() )
1282 emit askUpdate(); // Needed if video was launched after the F11
1283 emit fullscreenInterfaceToggled( false );
1288 emit fullscreenInterfaceToggled( true );
1293 /*****************************************************************************
1294 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1295 * We don't show the menu directly here because we don't want the
1296 * caller to block for a too long time.
1297 *****************************************************************************/
1298 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1299 vlc_value_t old_val, vlc_value_t new_val, void *param )
1301 intf_thread_t *p_intf = (intf_thread_t *)param;
1303 if( p_intf->pf_show_dialog )
1305 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1306 new_val.b_bool, NULL );
1312 /*****************************************************************************
1313 * IntfShowCB: callback triggered by the intf-show libvlc variable.
1314 *****************************************************************************/
1315 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1316 vlc_value_t old_val, vlc_value_t new_val, void *param )
1318 intf_thread_t *p_intf = (intf_thread_t *)param;
1319 p_intf->p_sys->p_mi->toggleFSC();