1 /*****************************************************************************
2 * main_interface.cpp : Main interface
3 ****************************************************************************
4 * Copyright (C) 2006-2008 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Jean-Baptiste Kempf <jb@videolan.org>
9 * Ilkka Ollakka <ileoo@videolan.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
32 #include "main_interface.hpp"
33 #include "input_manager.hpp"
34 #include "actions_manager.hpp"
36 #include "util/customwidgets.hpp"
37 #include "util/qt_dirs.hpp"
39 #include "components/interface_widgets.hpp"
40 #include "components/controller.hpp"
41 #include "components/playlist/playlist.hpp"
42 #include "dialogs/external.hpp"
45 #include "recents.hpp"
47 #include <QCloseEvent>
59 #include <QPushButton>
63 #include <vlc_keys.h> /* Wheel event */
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 */
75 // need_components_update = false;
78 playlistWidget = NULL;
80 videoIsActive = false;
81 playlistVisible = false;
83 fullscreenControls = NULL;
93 * Configuration and settings
94 * Pre-building of interface
97 setFocusPolicy( Qt::StrongFocus );
98 setAcceptDrops( true );
99 setWindowIcon( QApplication::windowIcon() );
100 setWindowOpacity( config_GetFloat( p_intf, "qt-opacity" ) );
102 /* Set The Video In emebedded Mode or not */
103 videoEmbeddedFlag = config_GetInt( p_intf, "embedded-video" );
105 /* Does the interface resize to video size or the opposite */
106 b_keep_size = !config_GetInt( p_intf, "qt-video-autoresize" );
108 /* Are we in the enhanced always-video mode or not ? */
109 i_visualmode = config_GetInt( p_intf, "qt-display-mode" );
111 /* Set the other interface settings */
112 settings = getSettings();
113 settings->beginGroup( "MainWindow" );
116 * Retrieve saved sizes for main window
117 * mainBasedSize = based window size for normal mode
118 * (no video, no background)
119 * mainVideoSize = window size with video (all modes)
121 mainBasedSize = settings->value( "mainBasedSize", QSize( 350, 120 ) ).toSize();
122 mainVideoSize = settings->value( "mainVideoSize", QSize( 400, 300 ) ).toSize();
124 /* Do we want anoying popups or not */
125 notificationEnabled = (bool)config_GetInt( p_intf, "qt-notification" );
132 /**************************
133 * UI and Widgets design
134 **************************/
135 setVLCWindowsTitle();
136 handleMainUi( settings );
141 QVLCMenu::createMenuBar( this, p_intf );
144 /* Create a Dock to get the playlist */
145 dockPL = new QDockWidget( qtr( "Playlist" ), this );
146 dockPL->setSizePolicy( QSizePolicy::Preferred,
147 QSizePolicy::Expanding );
148 dockPL->setFeatures( QDockWidget::AllDockWidgetFeatures );
149 dockPL->setAllowedAreas( Qt::LeftDockWidgetArea
150 | Qt::RightDockWidgetArea
151 | Qt::BottomDockWidgetArea );
155 /********************
157 ********************/
158 MainInputManager::getInstance( p_intf );
160 /**************************
161 * Various CONNECTs on IM *
162 **************************/
163 /* Connect the input manager to the GUI elements it manages */
166 * Connects on nameChanged()
167 * Those connects are not merged because different options can trigger
170 /* Naming in the controller statusbar */
171 CONNECT( THEMIM->getIM(), nameChanged( QString ),
172 this, setName( QString ) );
173 /* and in the systray */
176 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
177 updateSystrayTooltipName( QString ) );
179 /* and in the title of the controller */
180 if( config_GetInt( p_intf, "qt-name-in-title" ) )
182 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
183 setVLCWindowsTitle( QString ) );
187 * CONNECTS on PLAY_STATUS
189 /* Status on the systray */
192 CONNECT( THEMIM->getIM(), statusChanged( int ),
193 this, updateSystrayTooltipStatus( int ) );
196 /* END CONNECTS ON IM */
198 dialogHandler = new DialogHandler (p_intf);
203 var_AddCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
205 /* Register callback for the intf-popupmenu variable */
206 var_AddCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
209 /* VideoWidget connects to avoid different threads speaking to each other */
210 connect( this, SIGNAL(askReleaseVideo( void )),
211 this, SLOT(releaseVideoSlot( void )), Qt::BlockingQueuedConnection );
215 CONNECT( this, askVideoToResize( unsigned int, unsigned int ),
216 videoWidget, SetSizing( unsigned int, unsigned int ) );
218 connect( this, SIGNAL(askVideoToShow( unsigned int, unsigned int)),
219 videoWidget, SLOT(SetSizing(unsigned int, unsigned int )),
220 Qt::BlockingQueuedConnection );
223 CONNECT( this, askUpdate(), this, doComponentsUpdate() );
225 /* Size and placement of interface */
226 settings->beginGroup( "MainWindow" );
227 QVLCTools::restoreWidgetPosition( settings, this, QSize(380, 60) );
229 /* resize to previously saved main window size if appicable */
232 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
233 i_visualmode == QT_MINIMAL_MODE )
235 resize( mainVideoSize );
239 resize( mainBasedSize );
243 bool b_visible = settings->value( "playlist-visible", 0 ).toInt();
244 settings->endGroup();
247 if( b_visible ) togglePlaylist();
249 /* Enable the popup menu in the MI */
250 setContextMenuPolicy( Qt::CustomContextMenu );
251 CONNECT( this, customContextMenuRequested( const QPoint& ),
252 this, popupMenu( const QPoint& ) );
254 /* Final sizing and showing */
255 setMinimumWidth( __MAX( controls->sizeHint().width(),
256 menuBar()->sizeHint().width() ) );
259 /* And switch to minimal view if needed
260 Must be called after the show() */
261 if( i_visualmode == QT_MINIMAL_MODE )
262 toggleMinimalView( true );
264 /* Update the geometry : It is useful if you switch between
267 resize( sizeHint() );
269 /*****************************************************
270 * End everything by creating the Systray Management *
271 *****************************************************/
275 MainInterface::~MainInterface()
277 msg_Dbg( p_intf, "Destroying the main interface" );
279 delete dialogHandler;
281 /* Unsure we hide the videoWidget before destroying it */
282 if( videoIsActive ) videoWidget->hide();
284 /* Save playlist state */
288 QVLCTools::saveWidgetPosition( p_intf, "Playlist", playlistWidget );
290 delete playlistWidget;
293 /* Be sure to kill the actionsManager... FIXME */
294 ActionsManager::killInstance();
296 /* Delete the FSC controller */
297 delete fullscreenControls;
300 settings->beginGroup( "MainWindow" );
301 settings->setValue( "pl-dock-status", (int)i_pl_dock );
302 settings->setValue( "playlist-visible", (int)playlistVisible );
303 settings->setValue( "adv-controls",
304 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
306 settings->setValue( "mainBasedSize", mainBasedSize );
307 settings->setValue( "mainVideoSize", mainVideoSize );
310 settings->setValue( "backgroundSize", bgWidget->size() );
313 QVLCTools::saveWidgetPosition(settings, this);
314 settings->endGroup();
317 /* Unregister callbacks */
318 var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
319 var_DelCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
321 p_intf->p_sys->p_mi = NULL;
324 /*****************************
326 *****************************/
328 inline void MainInterface::createStatusBar()
333 /* Widgets Creation*/
334 QStatusBar *statusBarr = statusBar();
336 TimeLabel *timeLabel = new TimeLabel( p_intf );
337 nameLabel = new QLabel( this );
338 nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
339 | Qt::TextSelectableByKeyboard );
340 SpeedLabel *speedLabel = new SpeedLabel( p_intf, "1.00x", this );
342 /* Styling those labels */
343 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
344 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
345 nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
347 /* and adding those */
348 statusBarr->addWidget( nameLabel, 8 );
349 statusBarr->addPermanentWidget( speedLabel, 0 );
350 statusBarr->addPermanentWidget( timeLabel, 0 );
352 /* timeLabel behaviour:
353 - double clicking opens the goto time dialog
354 - right-clicking and clicking just toggle between remaining and
356 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
358 CONNECT( THEMIM->getIM(), encryptionChanged( bool ) , this, showCryptedLabel( bool ) );
361 void MainInterface::showCryptedLabel( bool b_show )
363 if( cryptedLabel == NULL )
365 cryptedLabel = new QLabel;
366 // The lock icon is not the right one for DRM protection/scrambled.
367 //cryptedLabel->setPixmap( QPixmap( ":/lock" ) );
368 cryptedLabel->setText( "DRM" );
369 statusBar()->addWidget( cryptedLabel );
372 cryptedLabel->setVisible( b_show );
375 inline void MainInterface::initSystray()
377 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
378 bool b_systrayWanted = config_GetInt( p_intf, "qt-system-tray" );
380 if( config_GetInt( p_intf, "qt-start-minimized") > 0 )
382 if( b_systrayAvailable )
384 b_systrayWanted = true;
388 msg_Err( p_intf, "cannot start minimized without system tray bar" );
391 if( b_systrayAvailable && b_systrayWanted )
396 * Give the decorations of the Main Window a correct Name.
397 * If nothing is given, set it to VLC...
399 void MainInterface::setVLCWindowsTitle( QString aTitle )
401 if( aTitle.isEmpty() )
403 setWindowTitle( qtr( "VLC media player" ) );
407 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
411 void MainInterface::handleMainUi( QSettings *settings )
413 /* Create the main Widget and the mainLayout */
414 QWidget *main = new QWidget;
415 setCentralWidget( main );
416 mainLayout = new QVBoxLayout( main );
418 /* Margins, spacing */
419 main->setContentsMargins( 0, 0, 0, 0 );
420 main->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
421 mainLayout->setSpacing( 0 );
422 mainLayout->setMargin( 0 );
424 /* Create the CONTROLS Widget */
425 controls = new ControlsWidget( p_intf,
426 settings->value( "adv-controls", false ).toBool(), this );
427 CONNECT( controls, advancedControlsToggled( bool ),
428 this, doComponentsUpdate() );
429 CONNECT( controls, sizeChanged(),
430 this, doComponentsUpdate() );
431 inputC = new InputControlsWidget( p_intf, this );
434 /* Disabled for now, they SUCK */
436 visualSelector = new VisualSelector( p_intf );
437 mainLayout->insertWidget( 0, visualSelector );
438 visualSelector->hide();
442 bgWidget = new BackgroundWidget( p_intf );
444 settings->value( "backgroundSize", QSize( 300, 200 ) ).toSize() );
445 bgWidget->updateGeometry();
446 CONNECT( this, askBgWidgetToToggle(), bgWidget, toggle() );
448 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
449 i_visualmode != QT_MINIMAL_MODE )
454 /* And video Outputs */
455 if( videoEmbeddedFlag )
456 videoWidget = new VideoWidget( p_intf );
458 /* Add the controls Widget to the main Widget */
459 mainLayout->insertWidget( 0, bgWidget );
460 if( videoWidget ) mainLayout->insertWidget( 0, videoWidget, 10 );
461 mainLayout->insertWidget( 2, inputC, 0, Qt::AlignBottom );
462 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
463 controls, 0, Qt::AlignBottom );
465 /* Finish the sizing */
466 main->updateGeometry();
468 getSettings()->endGroup();
472 /* Create the FULLSCREEN CONTROLS Widget */
473 if( config_GetInt( p_intf, "qt-fs-controller" ) )
475 fullscreenControls = new FullscreenControllerWidget( p_intf );
479 inline void MainInterface::askForPrivacy()
482 * Ask for the network policy on FIRST STARTUP
484 if( config_GetInt( p_intf, "qt-privacy-ask") )
486 QList<ConfigControl *> controls;
487 if( privacyDialog( &controls ) == QDialog::Accepted )
489 QList<ConfigControl *>::Iterator i;
490 for( i = controls.begin() ; i != controls.end() ; i++ )
492 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
493 c->doApply( p_intf );
496 config_PutInt( p_intf, "qt-privacy-ask" , 0 );
497 /* We have to save here because the user may not launch Prefs */
498 config_SaveConfigFile( p_intf, NULL );
503 int MainInterface::privacyDialog( QList<ConfigControl *> *controls )
505 QDialog *privacy = new QDialog( this );
507 privacy->setWindowTitle( qtr( "Privacy and Network Policies" ) );
509 QGridLayout *gLayout = new QGridLayout( privacy );
511 QGroupBox *blabla = new QGroupBox( qtr( "Privacy and Network Warning" ) );
512 QGridLayout *blablaLayout = new QGridLayout( blabla );
513 QLabel *text = new QLabel( qtr(
514 "<p>The <i>VideoLAN Team</i> doesn't like when an application goes "
515 "online without authorization.</p>\n "
516 "<p><i>VLC media player</i> can retreive limited information from "
517 "the Internet in order to get CD covers or to check "
518 "for available updates.</p>\n"
519 "<p><i>VLC media player</i> <b>DOES NOT</b> send or collect <b>ANY</b> "
520 "information, even anonymously, about your usage.</p>\n"
521 "<p>Therefore please select from the following options, the default being "
522 "almost no access to the web.</p>\n") );
523 text->setWordWrap( true );
524 text->setTextFormat( Qt::RichText );
526 blablaLayout->addWidget( text, 0, 0 ) ;
528 QGroupBox *options = new QGroupBox;
529 QGridLayout *optionsLayout = new QGridLayout( options );
531 gLayout->addWidget( blabla, 0, 0, 1, 3 );
532 gLayout->addWidget( options, 1, 0, 1, 3 );
533 module_config_t *p_config;
534 ConfigControl *control;
537 #define CONFIG_GENERIC( option, type ) \
538 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
541 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
542 p_config, options, false, optionsLayout, line ); \
543 controls->append( control ); \
546 #define CONFIG_GENERIC_NOBOOL( option, type ) \
547 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
550 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
551 p_config, options, optionsLayout, line ); \
552 controls->append( control ); \
555 CONFIG_GENERIC( "album-art", IntegerList ); line++;
557 CONFIG_GENERIC_NOBOOL( "qt-updates-notif", Bool ); line++;
560 QPushButton *ok = new QPushButton( qtr( "OK" ) );
562 gLayout->addWidget( ok, 2, 2 );
564 CONNECT( ok, clicked(), privacy, accept() );
565 return privacy->exec();
569 /**********************************************************************
570 * Handling of sizing of the components
571 **********************************************************************/
573 /* This function is probably wrong, but we don't have many many choices...
574 Since we can't know from the playlist Widget if we are inside a dock or not,
575 because the playlist Widget can be called by THEDP, as a separate windows for
577 Maybe the other solution is to redefine the sizeHint() of the playlist and
578 ask _parent->isFloating()...
579 If you think this would be better, please FIXME it...
582 QSize MainInterface::sizeHint() const
586 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
587 i_visualmode == QT_MINIMAL_MODE )
589 return mainVideoSize;
593 if( VISIBLE( bgWidget) ||
594 ( videoIsActive && videoWidget->isVisible() )
596 return mainVideoSize;
598 return mainBasedSize;
602 int nwidth = controls->sizeHint().width();
603 int nheight = controls->isVisible() ?
604 controls->size().height()
605 + inputC->size().height()
606 + menuBar()->size().height()
607 + statusBar()->size().height()
610 if( VISIBLE( bgWidget ) )
613 nheight += i_bg_height;
615 nheight += bgWidget->size().height();
616 nwidth = __MAX( nwidth, bgWidget->size().width() );
618 else if( videoIsActive && videoWidget->isVisible() )
620 nheight += videoWidget->sizeHint().height();
621 nwidth = __MAX( nwidth, videoWidget->sizeHint().width() );
624 if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget() )
626 nheight += dockPL->size().height();
627 nwidth = __MAX( nwidth, dockPL->size().width() );
628 msg_Warn( p_intf, "3 %i %i", nheight, nwidth );
631 return QSize( nwidth, nheight );
634 void MainInterface::toggleFSC()
636 if( !fullscreenControls ) return;
638 IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
639 QApplication::postEvent( fullscreenControls, eShow );
642 void MainInterface::popupMenu( const QPoint &p )
644 /* Ow, that's ugly: don't show the popup menu if cursor over
645 * the main menu bar or the status bar */
646 if( !childAt( p ) || ( ( childAt( p ) != menuBar() )
647 && ( childAt( p )->parentWidget() != statusBar() ) ) )
648 QVLCMenu::PopupMenu( p_intf, true );
651 void MainInterface::debug()
654 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
655 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
656 if( videoWidget && videoWidget->isVisible() )
658 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
659 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
664 /****************************************************************************
666 ****************************************************************************/
668 /* This event is used to deal with the fullscreen and always on top
669 issue conflict (bug in wx) */
670 class SetVideoOnTopQtEvent : public QEvent
673 SetVideoOnTopQtEvent( bool _onTop ) :
674 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
677 bool OnTop() const { return onTop; }
685 * Thou shall not call/resize/hide widgets from on another thread.
686 * This is wrong, and this is THE reason to emit signals on those Video Functions
688 WId MainInterface::requestVideo( vout_thread_t *p_nvout, int *pi_x,
689 int *pi_y, unsigned int *pi_width,
690 unsigned int *pi_height )
692 /* Request the videoWidget */
693 WId ret = videoWidget->request( p_nvout,pi_x, pi_y,
694 pi_width, pi_height, b_keep_size );
695 if( ret ) /* The videoWidget is available */
697 /* Did we have a bg ? Hide it! */
698 if( VISIBLE( bgWidget) )
701 emit askBgWidgetToToggle();
704 bgWasVisible = false;
706 /* ask videoWidget to show */
707 emit askVideoToShow( *pi_width, *pi_height );
709 /* Consider the video active now */
710 videoIsActive = true;
717 /* Call from the WindowClose function */
718 void MainInterface::releaseVideo( void )
720 emit askReleaseVideo( );
723 /* Function that is CONNECTED to the previous emit */
724 void MainInterface::releaseVideoSlot( void )
726 videoWidget->release( );
730 /* Reset the bg state */
731 bgWasVisible = false;
735 videoIsActive = false;
737 /* Try to resize, except when you are in Fullscreen mode */
738 if( !isFullScreen() ) doComponentsUpdate();
741 /* Call from WindowControl function */
742 int MainInterface::controlVideo( int i_query, va_list args )
744 int i_ret = VLC_SUCCESS;
749 unsigned int i_width = va_arg( args, unsigned int );
750 unsigned int i_height = va_arg( args, unsigned int );
751 emit askVideoToResize( i_width, i_height );
755 case VOUT_SET_STAY_ON_TOP:
757 int i_arg = va_arg( args, int );
758 QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
762 i_ret = VLC_EGENERIC;
763 msg_Warn( p_intf, "unsupported control query" );
769 /*****************************************************************************
770 * Playlist, Visualisation and Menus handling
771 *****************************************************************************/
773 * Toggle the playlist widget or dialog
775 void MainInterface::togglePlaylist()
778 If no playlist exist, then create one and attach it to the DockPL*/
779 if( !playlistWidget )
781 playlistWidget = new PlaylistWidget( p_intf );
783 i_pl_dock = PL_UNDOCKED;
784 /* i_pl_dock = (pl_dock_e)getSettings()
785 ->value( "pl-dock-status", PL_UNDOCKED ).toInt(); */
787 if( i_pl_dock == PL_UNDOCKED )
789 playlistWidget->setWindowFlags( Qt::Window );
791 /* This will restore the geometry but will not work for position,
792 because of parenting */
793 QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
794 playlistWidget, QSize( 600, 300 ) );
798 mainLayout->insertWidget( 4, playlistWidget );
800 playlistVisible = true;
802 playlistWidget->show();
806 /* toggle the visibility of the playlist */
807 TOGGLEV( playlistWidget );
808 playlistVisible = !playlistVisible;
809 //doComponentsUpdate(); //resize( sizeHint() );
813 /* Function called from the menu to undock the playlist */
814 void MainInterface::undockPlaylist()
816 // dockPL->setFloating( true );
820 void MainInterface::dockPlaylist( pl_dock_e i_pos )
824 void MainInterface::toggleMinimalView( bool b_switch )
826 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
827 i_visualmode != QT_MINIMAL_MODE )
828 { /* NORMAL MODE then */
829 if( !videoWidget || videoWidget->isHidden() )
831 emit askBgWidgetToToggle();
835 /* If video is visible, then toggle the status of bgWidget */
836 bgWasVisible = !bgWasVisible;
840 i_bg_height = bgWidget->height();
842 menuBar()->setVisible( !b_switch );
843 controls->setVisible( !b_switch );
844 statusBar()->setVisible( !b_switch );
845 inputC->setVisible( !b_switch );
847 doComponentsUpdate();
849 emit minimalViewToggled( b_switch );
852 /* Video widget cannot do this synchronously as it runs in another thread */
853 /* Well, could it, actually ? Probably dangerous ... */
855 /* This function is called:
856 - toggling of minimal View
857 - through askUpdate() by Vout thread request video and resize video (zoom)
858 - Advanced buttons toggled
860 void MainInterface::doComponentsUpdate()
862 msg_Dbg( p_intf, "Updating the geometry" );
863 /* Here we resize to sizeHint() and not adjustsize because we want
864 the videoWidget to be exactly the correctSize */
865 resize( sizeHint() );
872 /* toggling advanced controls buttons */
873 void MainInterface::toggleAdvanced()
875 controls->toggleAdvanced();
876 // if( fullscreenControls ) fullscreenControls->toggleAdvanced();
879 /* Get the visibility status of the controls (hidden or not, advanced or not) */
880 int MainInterface::getControlsVisibilityStatus()
882 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
883 + CONTROLS_ADVANCED * controls->b_advancedVisible );
887 void MainInterface::visual()
889 if( !VISIBLE( visualSelector) )
891 visualSelector->show();
892 if( !THEMIM->getIM()->hasVideo() )
894 /* Show the background widget */
896 visualSelectorEnabled = true;
900 /* Stop any currently running visualization */
901 visualSelector->hide();
902 visualSelectorEnabled = false;
904 doComponentsUpdate();
908 /************************************************************************
910 ************************************************************************/
911 void MainInterface::setName( QString name )
913 input_name = name; /* store it for the QSystray use */
914 /* Display it in the status bar, but also as a Tooltip in case it doesn't
916 nameLabel->setText( " " + name + " " );
917 nameLabel->setToolTip( " " + name +" " );
920 /*****************************************************************************
921 * Systray Icon and Systray Menu
922 *****************************************************************************/
925 * Create a SystemTray icon and a menu that would go with it.
926 * Connects to a click handler on the icon.
928 void MainInterface::createSystray()
931 if( QDate::currentDate().dayOfYear() >= 354 )
932 iconVLC = QIcon( QPixmap( ":/vlc128-christmas.png" ) );
934 iconVLC = QIcon( QPixmap( ":/vlc128.png" ) );
935 sysTray = new QSystemTrayIcon( iconVLC, this );
936 sysTray->setToolTip( qtr( "VLC media player" ));
938 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
939 systrayMenu->setIcon( iconVLC );
941 QVLCMenu::updateSystrayMenu( this, p_intf, true );
944 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
945 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
949 * Updates the Systray Icon's menu and toggle the main interface
951 void MainInterface::toggleUpdateSystrayMenu()
953 /* If hidden, show it */
959 else if( isMinimized() )
967 /* Visible (possibly under other windows) */
969 /* check if any visible window is above vlc in the z-order,
970 * but ignore the ones always on top
971 * and the ones which can't be activated */
974 wi.cbSize = sizeof( WINDOWINFO );
975 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
976 hwnd && ( !IsWindowVisible( hwnd ) ||
977 ( GetWindowInfo( hwnd, &wi ) &&
978 (wi.dwExStyle&WS_EX_NOACTIVATE) ) );
979 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
980 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
981 (wi.dwExStyle&WS_EX_TOPMOST) )
993 QVLCMenu::updateSystrayMenu( this, p_intf );
996 void MainInterface::handleSystrayClick(
997 QSystemTrayIcon::ActivationReason reason )
1001 case QSystemTrayIcon::Trigger:
1002 case QSystemTrayIcon::DoubleClick:
1003 toggleUpdateSystrayMenu();
1005 case QSystemTrayIcon::MiddleClick:
1006 sysTray->showMessage( qtr( "VLC media player" ),
1007 qtr( "Control menu for the player" ),
1008 QSystemTrayIcon::Information, 3000 );
1016 * Updates the name of the systray Icon tooltip.
1017 * Doesn't check if the systray exists, check before you call it.
1019 void MainInterface::updateSystrayTooltipName( QString name )
1021 if( name.isEmpty() )
1023 sysTray->setToolTip( qtr( "VLC media player" ) );
1027 sysTray->setToolTip( name );
1028 if( notificationEnabled && ( isHidden() || isMinimized() ) )
1030 sysTray->showMessage( qtr( "VLC media player" ), name,
1031 QSystemTrayIcon::NoIcon, 3000 );
1035 QVLCMenu::updateSystrayMenu( this, p_intf );
1039 * Updates the status of the systray Icon tooltip.
1040 * Doesn't check if the systray exists, check before you call it.
1042 void MainInterface::updateSystrayTooltipStatus( int i_status )
1049 sysTray->setToolTip( qtr( "VLC media player" ) );
1054 sysTray->setToolTip( input_name );
1059 sysTray->setToolTip( input_name + " - "
1066 /************************************************************************
1068 ************************************************************************/
1069 void MainInterface::dropEvent(QDropEvent *event)
1071 dropEventPlay( event, true );
1074 void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
1076 const QMimeData *mimeData = event->mimeData();
1078 /* D&D of a subtitles file, add it on the fly */
1079 if( mimeData->urls().size() == 1 )
1081 if( THEMIM->getIM()->hasInput() )
1083 if( !input_AddSubtitle( THEMIM->getInput(),
1084 qtu( toNativeSeparators(
1085 mimeData->urls()[0].toLocalFile() ) ),
1088 event->acceptProposedAction();
1093 bool first = b_play;
1094 foreach( const QUrl &url, mimeData->urls() )
1096 QString s = toNativeSeparators( url.toLocalFile() );
1098 if( s.length() > 0 ) {
1099 playlist_Add( THEPL, qtu(s), NULL,
1100 PLAYLIST_APPEND | (first ? PLAYLIST_GO: 0),
1101 PLAYLIST_END, true, false );
1103 RecentsMRL::getInstance( p_intf )->addRecent( s );
1106 event->acceptProposedAction();
1108 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1110 event->acceptProposedAction();
1112 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1114 event->acceptProposedAction();
1116 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1121 /************************************************************************
1123 ************************************************************************/
1124 void MainInterface::customEvent( QEvent *event )
1127 if( event->type() == PLDockEvent_Type )
1129 PlaylistDialog::killInstance();
1130 playlistEmbeddedFlag = true;
1132 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1137 if ( event->type() == (int)SetVideoOnTopEvent_Type )
1139 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1140 if( p_event->OnTop() )
1141 setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
1143 setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint);
1144 show(); /* necessary to apply window flags?? */
1148 void MainInterface::keyPressEvent( QKeyEvent *e )
1150 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() == Qt::Key_H )
1151 && !menuBar()->isVisible() )
1153 toggleMinimalView( false );
1157 int i_vlck = qtEventToVLCKey( e );
1160 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1167 void MainInterface::resizeEvent( QResizeEvent * event )
1171 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
1172 i_visualmode == QT_MINIMAL_MODE )
1174 mainVideoSize = size();
1178 if( VISIBLE( bgWidget) ||
1179 ( videoIsActive && videoWidget->isVisible() )
1181 mainVideoSize = size();
1183 mainBasedSize = size();
1188 void MainInterface::wheelEvent( QWheelEvent *e )
1190 int i_vlckey = qtWheelEventToVLCKey( e );
1191 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1195 void MainInterface::closeEvent( QCloseEvent *e )
1202 void MainInterface::toggleFullScreen( void )
1204 if( isFullScreen() )
1207 emit askUpdate(); // Needed if video was launched after the F11
1208 emit fullscreenInterfaceToggled( false );
1213 emit fullscreenInterfaceToggled( true );
1218 /*****************************************************************************
1219 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1220 * We don't show the menu directly here because we don't want the
1221 * caller to block for a too long time.
1222 *****************************************************************************/
1223 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1224 vlc_value_t old_val, vlc_value_t new_val, void *param )
1226 intf_thread_t *p_intf = (intf_thread_t *)param;
1228 if( p_intf->pf_show_dialog )
1230 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1231 new_val.b_bool, NULL );
1237 /*****************************************************************************
1238 * IntfShowCB: callback triggered by the intf-show libvlc variable.
1239 *****************************************************************************/
1240 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1241 vlc_value_t old_val, vlc_value_t new_val, void *param )
1243 intf_thread_t *p_intf = (intf_thread_t *)param;
1244 p_intf->p_sys->p_mi->toggleFSC();