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"
44 #include "recents.hpp"
46 #include <QCloseEvent>
58 #include <QPushButton>
62 #include <vlc_keys.h> /* Wheel event */
65 /* Callback prototypes */
66 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
67 vlc_value_t old_val, vlc_value_t new_val, void *param );
68 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
69 vlc_value_t old_val, vlc_value_t new_val, void *param );
70 static int InteractCallback( vlc_object_t *, const char *, vlc_value_t,
73 MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
75 /* Variables initialisation */
76 // need_components_update = false;
79 playlistWidget = NULL;
81 videoIsActive = false;
82 playlistVisible = false;
84 fullscreenControls = NULL;
90 * Configuration and settings
91 * Pre-building of interface
94 setFocusPolicy( Qt::StrongFocus );
95 setAcceptDrops( true );
96 setWindowIcon( QApplication::windowIcon() );
97 setWindowOpacity( config_GetFloat( p_intf, "qt-opacity" ) );
99 /* Set The Video In emebedded Mode or not */
100 videoEmbeddedFlag = config_GetInt( p_intf, "embedded-video" );
102 /* Does the interface resize to video size or the opposite */
103 b_keep_size = !config_GetInt( p_intf, "qt-video-autoresize" );
105 /* Are we in the enhanced always-video mode or not ? */
106 i_visualmode = config_GetInt( p_intf, "qt-display-mode" );
108 /* Set the other interface settings */
109 settings = getSettings();
110 settings->beginGroup( "MainWindow" );
113 * Retrieve saved sizes for main window
114 * mainBasedSize = based window size for normal mode
115 * (no video, no background)
116 * mainVideoSize = window size with video (all modes)
118 mainBasedSize = settings->value( "mainBasedSize", QSize( 350, 120 ) ).toSize();
119 mainVideoSize = settings->value( "mainVideoSize", QSize( 400, 300 ) ).toSize();
121 /* Visualisation, not really used yet */
122 visualSelectorEnabled = settings->value( "visual-selector", false).toBool();
124 /* Do we want anoying popups or not */
125 notificationEnabled = (bool)config_GetInt( p_intf, "qt-notification" );
127 /**************************
128 * UI and Widgets design
129 **************************/
130 setVLCWindowsTitle();
131 handleMainUi( settings );
134 /* Create a Dock to get the playlist */
135 dockPL = new QDockWidget( qtr( "Playlist" ), this );
136 dockPL->setSizePolicy( QSizePolicy::Preferred,
137 QSizePolicy::Expanding );
138 dockPL->setFeatures( QDockWidget::AllDockWidgetFeatures );
139 dockPL->setAllowedAreas( Qt::LeftDockWidgetArea
140 | Qt::RightDockWidgetArea
141 | Qt::BottomDockWidgetArea );
145 /**************************
146 * Menu Bar and Status Bar
147 **************************/
148 QVLCMenu::createMenuBar( this, p_intf, visualSelectorEnabled );
150 /* StatusBar Creation */
151 setStatusBar( createStatusBar() );
153 /********************
155 ********************/
156 MainInputManager::getInstance( p_intf );
158 /**************************
159 * Various CONNECTs on IM *
160 **************************/
161 /* Connect the input manager to the GUI elements it manages */
164 * Connects on nameChanged()
165 * Those connects are not merged because different options can trigger
168 /* Naming in the controller statusbar */
169 CONNECT( THEMIM->getIM(), nameChanged( QString ),
170 this, setName( QString ) );
171 /* and in the systray */
174 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
175 updateSystrayTooltipName( QString ) );
177 /* and in the title of the controller */
178 if( config_GetInt( p_intf, "qt-name-in-title" ) )
180 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
181 setVLCWindowsTitle( QString ) );
185 * CONNECTS on PLAY_STATUS
187 /* Status on the systray */
190 CONNECT( THEMIM->getIM(), statusChanged( int ),
191 this, updateSystrayTooltipStatus( int ) );
194 /* END CONNECTS ON IM */
200 var_Create( p_intf, "interaction", VLC_VAR_ADDRESS );
201 var_AddCallback( p_intf, "interaction", InteractCallback, this );
202 interaction_Register( p_intf );
204 var_AddCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
206 /* Register callback for the intf-popupmenu variable */
207 var_AddCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
210 /* VideoWidget connects to avoid different threads speaking to each other */
211 connect( this, SIGNAL(askReleaseVideo( void )),
212 this, SLOT(releaseVideoSlot( void )), Qt::BlockingQueuedConnection );
215 CONNECT( this, askVideoToResize( unsigned int, unsigned int ),
216 videoWidget, SetSizing( unsigned int, unsigned int ) );
218 CONNECT( this, askUpdate(), this, doComponentsUpdate() );
220 /* Size and placement of interface */
221 settings->beginGroup( "MainWindow" );
222 QVLCTools::restoreWidgetPosition( settings, this, QSize(380, 60) );
224 /* resize to previously saved main window size if appicable */
227 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
228 i_visualmode == QT_MINIMAL_MODE )
230 resize( mainVideoSize );
234 resize( mainBasedSize );
238 bool b_visible = settings->value( "playlist-visible", 0 ).toInt();
239 settings->endGroup();
242 if( b_visible ) togglePlaylist();
244 /* Final sizing and showing */
245 setMinimumWidth( __MAX( controls->sizeHint().width(),
246 menuBar()->sizeHint().width() ) );
249 /* And switch to minimal view if needed
250 Must be called after the show() */
251 if( i_visualmode == QT_MINIMAL_MODE )
254 /* Update the geometry : It is useful if you switch between
257 resize( sizeHint() );
259 /*****************************************************
260 * End everything by creating the Systray Management *
261 *****************************************************/
265 MainInterface::~MainInterface()
267 msg_Dbg( p_intf, "Destroying the main interface" );
269 if( videoIsActive ) videoWidget->hide();
274 QVLCTools::saveWidgetPosition( p_intf, "Playlist", playlistWidget );
276 delete playlistWidget;
279 ActionsManager::killInstance();
281 if( fullscreenControls ) delete fullscreenControls;
283 settings->beginGroup( "MainWindow" );
285 settings->setValue( "pl-dock-status", (int)i_pl_dock );
286 settings->setValue( "playlist-visible", (int)playlistVisible );
287 settings->setValue( "adv-controls",
288 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
290 settings->setValue( "mainBasedSize", mainBasedSize );
291 settings->setValue( "mainVideoSize", mainVideoSize );
294 settings->setValue( "backgroundSize", bgWidget->size() );
296 QVLCTools::saveWidgetPosition(settings, this);
297 settings->endGroup();
299 var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
301 /* Unregister callback for the intf-popupmenu variable */
302 var_DelCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
304 interaction_Unregister( p_intf );
305 var_DelCallback( p_intf, "interaction", InteractCallback, this );
307 p_intf->p_sys->p_mi = NULL;
310 /*****************************
312 *****************************/
314 QStatusBar * MainInterface::createStatusBar()
316 QStatusBar *statusBar = new QStatusBar;
321 /* Widgets Creation*/
322 TimeLabel *timeLabel = new TimeLabel( p_intf );
323 nameLabel = new QLabel( this );
324 nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
325 | Qt::TextSelectableByKeyboard );
326 SpeedLabel *speedLabel = new SpeedLabel( p_intf, "1.00x", this );
328 /* Styling those labels */
329 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
330 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
331 nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
333 /* and adding those */
334 statusBar->addWidget( nameLabel, 8 );
335 statusBar->addPermanentWidget( speedLabel, 0 );
336 statusBar->addPermanentWidget( timeLabel, 0 );
338 /* timeLabel behaviour:
339 - double clicking opens the goto time dialog
340 - right-clicking and clicking just toggle between remaining and
342 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
346 inline void MainInterface::initSystray()
348 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
349 bool b_systrayWanted = config_GetInt( p_intf, "qt-system-tray" );
351 if( config_GetInt( p_intf, "qt-start-minimized") > 0 )
353 if( b_systrayAvailable )
355 b_systrayWanted = true;
359 msg_Err( p_intf, "cannot start minimized without system tray bar" );
362 if( b_systrayAvailable && b_systrayWanted )
367 * Give the decorations of the Main Window a correct Name.
368 * If nothing is given, set it to VLC...
370 void MainInterface::setVLCWindowsTitle( QString aTitle )
372 if( aTitle.isEmpty() )
374 setWindowTitle( qtr( "VLC media player" ) );
378 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
382 void MainInterface::handleMainUi( QSettings *settings )
384 /* Create the main Widget and the mainLayout */
385 QWidget *main = new QWidget;
386 setCentralWidget( main );
387 mainLayout = new QVBoxLayout( main );
389 /* Margins, spacing */
390 main->setContentsMargins( 0, 0, 0, 0 );
391 main->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
392 mainLayout->setSpacing( 0 );
393 mainLayout->setMargin( 0 );
395 /* Create the CONTROLS Widget */
396 controls = new ControlsWidget( p_intf,
397 settings->value( "adv-controls", false ).toBool(), this );
398 CONNECT( controls, advancedControlsToggled( bool ),
399 this, doComponentsUpdate() );
400 inputC = new InputControlsWidget( p_intf, this );
403 /* Disabled for now, they SUCK */
405 visualSelector = new VisualSelector( p_intf );
406 mainLayout->insertWidget( 0, visualSelector );
407 visualSelector->hide();
411 bgWidget = new BackgroundWidget( p_intf );
413 settings->value( "backgroundSize", QSize( 300, 200 ) ).toSize() );
414 bgWidget->updateGeometry();
415 CONNECT( this, askBgWidgetToToggle(), bgWidget, toggle() );
417 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
418 i_visualmode != QT_MINIMAL_MODE )
423 /* And video Outputs */
424 if( videoEmbeddedFlag )
425 videoWidget = new VideoWidget( p_intf );
427 /* Add the controls Widget to the main Widget */
428 mainLayout->insertWidget( 0, bgWidget );
429 if( videoWidget ) mainLayout->insertWidget( 0, videoWidget, 10 );
430 mainLayout->insertWidget( 2, inputC, 0, Qt::AlignBottom );
431 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
432 controls, 0, Qt::AlignBottom );
434 /* Finish the sizing */
435 main->updateGeometry();
437 getSettings()->endGroup();
441 /* Create the FULLSCREEN CONTROLS Widget */
442 if( config_GetInt( p_intf, "qt-fs-controller" ) )
444 fullscreenControls = new FullscreenControllerWidget( p_intf );
448 inline void MainInterface::askForPrivacy()
451 * Ask for the network policy on FIRST STARTUP
453 if( config_GetInt( p_intf, "qt-privacy-ask") )
455 QList<ConfigControl *> controls;
456 if( privacyDialog( &controls ) == QDialog::Accepted )
458 QList<ConfigControl *>::Iterator i;
459 for( i = controls.begin() ; i != controls.end() ; i++ )
461 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
462 c->doApply( p_intf );
465 config_PutInt( p_intf, "qt-privacy-ask" , 0 );
466 /* We have to save here because the user may not launch Prefs */
467 config_SaveConfigFile( p_intf, NULL );
472 int MainInterface::privacyDialog( QList<ConfigControl *> *controls )
474 QDialog *privacy = new QDialog( this );
476 privacy->setWindowTitle( qtr( "Privacy and Network Policies" ) );
478 QGridLayout *gLayout = new QGridLayout( privacy );
480 QGroupBox *blabla = new QGroupBox( qtr( "Privacy and Network Warning" ) );
481 QGridLayout *blablaLayout = new QGridLayout( blabla );
482 QLabel *text = new QLabel( qtr(
483 "<p>The <i>VideoLAN Team</i> doesn't like when an application goes "
484 "online without authorization.</p>\n "
485 "<p><i>VLC media player</i> can retreive limited information from "
486 "the Internet in order to get CD covers or to check "
487 "for available updates.</p>\n"
488 "<p><i>VLC media player</i> <b>DOES NOT</b> send or collect <b>ANY</b> "
489 "information, even anonymously, about your usage.</p>\n"
490 "<p>Therefore please select from the following options, the default being "
491 "almost no access to the web.</p>\n") );
492 text->setWordWrap( true );
493 text->setTextFormat( Qt::RichText );
495 blablaLayout->addWidget( text, 0, 0 ) ;
497 QGroupBox *options = new QGroupBox;
498 QGridLayout *optionsLayout = new QGridLayout( options );
500 gLayout->addWidget( blabla, 0, 0, 1, 3 );
501 gLayout->addWidget( options, 1, 0, 1, 3 );
502 module_config_t *p_config;
503 ConfigControl *control;
506 #define CONFIG_GENERIC( option, type ) \
507 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
510 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
511 p_config, options, false, optionsLayout, line ); \
512 controls->append( control ); \
515 #define CONFIG_GENERIC_NOBOOL( option, type ) \
516 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
519 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
520 p_config, options, optionsLayout, line ); \
521 controls->append( control ); \
524 CONFIG_GENERIC( "album-art", IntegerList ); line++;
526 CONFIG_GENERIC_NOBOOL( "qt-updates-notif", Bool ); line++;
527 CONFIG_GENERIC_NOBOOL( "qt-updates-days", Integer ); line++;
530 QPushButton *ok = new QPushButton( qtr( "OK" ) );
532 gLayout->addWidget( ok, 2, 2 );
534 CONNECT( ok, clicked(), privacy, accept() );
535 return privacy->exec();
539 /**********************************************************************
540 * Handling of sizing of the components
541 **********************************************************************/
543 /* This function is probably wrong, but we don't have many many choices...
544 Since we can't know from the playlist Widget if we are inside a dock or not,
545 because the playlist Widget can be called by THEDP, as a separate windows for
547 Maybe the other solution is to redefine the sizeHint() of the playlist and
548 ask _parent->isFloating()...
549 If you think this would be better, please FIXME it...
552 QSize MainInterface::sizeHint() const
556 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
557 i_visualmode == QT_MINIMAL_MODE )
559 return mainVideoSize;
563 if( VISIBLE( bgWidget) ||
564 ( videoIsActive && videoWidget->isVisible() )
566 return mainVideoSize;
568 return mainBasedSize;
572 int nwidth = controls->sizeHint().width();
573 int nheight = controls->isVisible() ?
574 controls->size().height()
575 + inputC->size().height()
576 + menuBar()->size().height()
577 + statusBar()->size().height()
580 if( VISIBLE( bgWidget ) )
582 nheight += bgWidget->size().height();
583 nwidth = bgWidget->size().width();
585 else if( videoIsActive && videoWidget->isVisible() )
587 nheight += videoWidget->sizeHint().height();
588 nwidth = videoWidget->sizeHint().width();
591 if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget() )
593 nheight += dockPL->size().height();
594 nwidth = __MAX( nwidth, dockPL->size().width() );
595 msg_Warn( p_intf, "3 %i %i", nheight, nwidth );
598 return QSize( nwidth, nheight );
601 void MainInterface::toggleFSC()
603 if( !fullscreenControls ) return;
605 IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
606 QApplication::postEvent( fullscreenControls, eShow );
609 void MainInterface::debug()
612 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
613 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
614 if( videoWidget && videoWidget->isVisible() )
616 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
617 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
622 /****************************************************************************
624 ****************************************************************************/
626 /* This event is used to deal with the fullscreen and always on top
627 issue conflict (bug in wx) */
628 class SetVideoOnTopQtEvent : public QEvent
631 SetVideoOnTopQtEvent( bool _onTop ) :
632 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
635 bool OnTop() const { return onTop; }
643 * Thou shall not call/resize/hide widgets from on another thread.
644 * This is wrong, and this is THE reason to emit signals on those Video Functions
646 WId MainInterface::requestVideo( vout_thread_t *p_nvout, int *pi_x,
647 int *pi_y, unsigned int *pi_width,
648 unsigned int *pi_height )
650 /* Request the videoWidget */
651 WId ret = videoWidget->request( p_nvout,pi_x, pi_y,
652 pi_width, pi_height, b_keep_size );
653 if( ret ) /* The videoWidget is available */
655 /* Did we have a bg ? Hide it! */
656 if( VISIBLE( bgWidget) )
659 emit askBgWidgetToToggle();
662 bgWasVisible = false;
664 /* Consider the video active now */
665 videoIsActive = true;
672 /* Call from the WindowClose function */
673 void MainInterface::releaseVideo( void )
675 emit askReleaseVideo( );
678 /* Function that is CONNECTED to the previous emit */
679 void MainInterface::releaseVideoSlot( void )
681 videoWidget->release( );
685 /* Reset the bg state */
686 bgWasVisible = false;
690 videoIsActive = false;
692 /* Try to resize, except when you are in Fullscreen mode */
693 if( !isFullScreen() ) doComponentsUpdate();
696 /* Call from WindowControl function */
697 int MainInterface::controlVideo( int i_query, va_list args )
699 int i_ret = VLC_SUCCESS;
704 unsigned int *pi_width = va_arg( args, unsigned int * );
705 unsigned int *pi_height = va_arg( args, unsigned int * );
706 *pi_width = videoWidget->videoSize.width();
707 *pi_height = videoWidget->videoSize.height();
712 unsigned int i_width = va_arg( args, unsigned int );
713 unsigned int i_height = va_arg( args, unsigned int );
714 emit askVideoToResize( i_width, i_height );
718 case VOUT_SET_STAY_ON_TOP:
720 int i_arg = va_arg( args, int );
721 QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
725 i_ret = VLC_EGENERIC;
726 msg_Warn( p_intf, "unsupported control query" );
732 /*****************************************************************************
733 * Playlist, Visualisation and Menus handling
734 *****************************************************************************/
736 * Toggle the playlist widget or dialog
738 void MainInterface::togglePlaylist()
741 If no playlist exist, then create one and attach it to the DockPL*/
742 if( !playlistWidget )
744 playlistWidget = new PlaylistWidget( p_intf );
746 i_pl_dock = PL_UNDOCKED;
747 /* i_pl_dock = (pl_dock_e)getSettings()
748 ->value( "pl-dock-status", PL_UNDOCKED ).toInt(); */
750 if( i_pl_dock == PL_UNDOCKED )
752 playlistWidget->setWindowFlags( Qt::Window );
754 /* This will restore the geometry but will not work for position,
755 because of parenting */
756 QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
757 playlistWidget, QSize( 600, 300 ) );
761 mainLayout->insertWidget( 4, playlistWidget );
763 playlistVisible = true;
765 playlistWidget->show();
769 /* toggle the visibility of the playlist */
770 TOGGLEV( playlistWidget );
771 playlistVisible = !playlistVisible;
772 //doComponentsUpdate(); //resize( sizeHint() );
776 /* Function called from the menu to undock the playlist */
777 void MainInterface::undockPlaylist()
779 // dockPL->setFloating( true );
783 void MainInterface::dockPlaylist( pl_dock_e i_pos )
787 void MainInterface::toggleMinimalView()
789 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
790 i_visualmode != QT_MINIMAL_MODE )
791 { /* NORMAL MODE then */
792 if( !videoWidget || videoWidget->isHidden() ) emit askBgWidgetToToggle();
795 /* If video is visible, then toggle the status of bgWidget */
796 bgWasVisible = !bgWasVisible;
800 TOGGLEV( menuBar() );
802 TOGGLEV( statusBar() );
804 doComponentsUpdate();
806 QVLCMenu::minimalViewAction->setChecked( bgWasVisible );
809 /* Video widget cannot do this synchronously as it runs in another thread */
810 /* Well, could it, actually ? Probably dangerous ... */
812 /* This function is called:
813 - toggling of minimal View
814 - through askUpdate() by Vout thread request video and resize video (zoom)
815 - Advanced buttons toggled
817 void MainInterface::doComponentsUpdate()
819 msg_Dbg( p_intf, "Updating the geometry" );
820 /* Here we resize to sizeHint() and not adjustsize because we want
821 the videoWidget to be exactly the correctSize */
822 resize( sizeHint() );
829 /* toggling advanced controls buttons */
830 void MainInterface::toggleAdvanced()
832 controls->toggleAdvanced();
833 // if( fullscreenControls ) fullscreenControls->toggleAdvanced();
836 /* Get the visibility status of the controls (hidden or not, advanced or not) */
837 int MainInterface::getControlsVisibilityStatus()
839 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
840 + CONTROLS_ADVANCED * controls->b_advancedVisible );
844 void MainInterface::visual()
846 if( !VISIBLE( visualSelector) )
848 visualSelector->show();
849 if( !THEMIM->getIM()->hasVideo() )
851 /* Show the background widget */
853 visualSelectorEnabled = true;
857 /* Stop any currently running visualization */
858 visualSelector->hide();
859 visualSelectorEnabled = false;
861 doComponentsUpdate();
865 /************************************************************************
867 ************************************************************************/
868 void MainInterface::setName( QString name )
870 input_name = name; /* store it for the QSystray use */
871 /* Display it in the status bar, but also as a Tooltip in case it doesn't
873 nameLabel->setText( " " + name + " " );
874 nameLabel->setToolTip( " " + name +" " );
877 /*****************************************************************************
878 * Systray Icon and Systray Menu
879 *****************************************************************************/
882 * Create a SystemTray icon and a menu that would go with it.
883 * Connects to a click handler on the icon.
885 void MainInterface::createSystray()
888 if( QDate::currentDate().dayOfYear() >= 354 )
889 iconVLC = QIcon( QPixmap( ":/vlc128-christmas.png" ) );
891 iconVLC = QIcon( QPixmap( ":/vlc128.png" ) );
892 sysTray = new QSystemTrayIcon( iconVLC, this );
893 sysTray->setToolTip( qtr( "VLC media player" ));
895 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
896 systrayMenu->setIcon( iconVLC );
898 QVLCMenu::updateSystrayMenu( this, p_intf, true );
901 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
902 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
906 * Updates the Systray Icon's menu and toggle the main interface
908 void MainInterface::toggleUpdateSystrayMenu()
910 /* If hidden, show it */
916 else if( isMinimized() )
924 /* Visible (possibly under other windows) */
926 /* check if any visible window is above vlc in the z-order,
927 * but ignore the ones always on top
928 * and the ones which can't be activated */
931 wi.cbSize = sizeof( WINDOWINFO );
932 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
933 hwnd && ( !IsWindowVisible( hwnd ) ||
934 ( GetWindowInfo( hwnd, &wi ) &&
935 (wi.dwExStyle&WS_EX_NOACTIVATE) ) );
936 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
937 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
938 (wi.dwExStyle&WS_EX_TOPMOST) )
950 QVLCMenu::updateSystrayMenu( this, p_intf );
953 void MainInterface::handleSystrayClick(
954 QSystemTrayIcon::ActivationReason reason )
958 case QSystemTrayIcon::Trigger:
959 case QSystemTrayIcon::DoubleClick:
960 toggleUpdateSystrayMenu();
962 case QSystemTrayIcon::MiddleClick:
963 case QSystemTrayIcon::Context:
964 sysTray->showMessage( qtr( "VLC media player" ),
965 qtr( "Control menu for the player" ),
966 QSystemTrayIcon::Information, 3000 );
974 * Updates the name of the systray Icon tooltip.
975 * Doesn't check if the systray exists, check before you call it.
977 void MainInterface::updateSystrayTooltipName( QString name )
981 sysTray->setToolTip( qtr( "VLC media player" ) );
985 sysTray->setToolTip( name );
986 if( notificationEnabled && ( isHidden() || isMinimized() ) )
988 sysTray->showMessage( qtr( "VLC media player" ), name,
989 QSystemTrayIcon::NoIcon, 3000 );
993 QVLCMenu::updateSystrayMenu( this, p_intf );
997 * Updates the status of the systray Icon tooltip.
998 * Doesn't check if the systray exists, check before you call it.
1000 void MainInterface::updateSystrayTooltipStatus( int i_status )
1007 sysTray->setToolTip( qtr( "VLC media player" ) );
1012 sysTray->setToolTip( input_name );
1017 sysTray->setToolTip( input_name + " - "
1024 /************************************************************************
1026 ************************************************************************/
1027 void MainInterface::dropEvent(QDropEvent *event)
1029 dropEventPlay( event, true );
1032 void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
1034 const QMimeData *mimeData = event->mimeData();
1036 /* D&D of a subtitles file, add it on the fly */
1037 if( mimeData->urls().size() == 1 )
1039 if( THEMIM->getIM()->hasInput() )
1041 if( !input_AddSubtitle( THEMIM->getInput(),
1042 qtu( toNativeSeparators(
1043 mimeData->urls()[0].toLocalFile() ) ),
1046 event->acceptProposedAction();
1051 bool first = b_play;
1052 foreach( const QUrl &url, mimeData->urls() )
1054 QString s = toNativeSeparators( url.toLocalFile() );
1056 if( s.length() > 0 ) {
1057 playlist_Add( THEPL, qtu(s), NULL,
1058 PLAYLIST_APPEND | (first ? PLAYLIST_GO: 0),
1059 PLAYLIST_END, true, false );
1061 RecentsMRL::getInstance( p_intf )->addRecent( s );
1064 event->acceptProposedAction();
1066 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1068 event->acceptProposedAction();
1070 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1072 event->acceptProposedAction();
1074 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1079 /************************************************************************
1081 ************************************************************************/
1082 void MainInterface::customEvent( QEvent *event )
1085 if( event->type() == PLDockEvent_Type )
1087 PlaylistDialog::killInstance();
1088 playlistEmbeddedFlag = true;
1090 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1095 if ( event->type() == (int)SetVideoOnTopEvent_Type )
1097 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1098 if( p_event->OnTop() )
1099 setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
1101 setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint);
1102 show(); /* necessary to apply window flags?? */
1106 void MainInterface::keyPressEvent( QKeyEvent *e )
1108 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() == Qt::Key_H )
1109 && menuBar()->isHidden() )
1111 toggleMinimalView();
1115 int i_vlck = qtEventToVLCKey( e );
1118 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1125 void MainInterface::resizeEvent( QResizeEvent * event )
1129 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
1130 i_visualmode == QT_MINIMAL_MODE )
1132 mainVideoSize = size();
1136 if( VISIBLE( bgWidget) ||
1137 ( videoIsActive && videoWidget->isVisible() )
1139 mainVideoSize = size();
1141 mainBasedSize = size();
1146 void MainInterface::wheelEvent( QWheelEvent *e )
1148 int i_vlckey = qtWheelEventToVLCKey( e );
1149 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1153 void MainInterface::closeEvent( QCloseEvent *e )
1160 void MainInterface::toggleFullScreen( void )
1162 if( isFullScreen() )
1165 emit askUpdate(); // Needed if video was launched after the F11
1166 QVLCMenu::fullscreenViewAction->setChecked( false );
1171 QVLCMenu::fullscreenViewAction->setChecked( true );
1176 /*****************************************************************************
1178 *****************************************************************************/
1179 static int InteractCallback( vlc_object_t *p_this,
1180 const char *psz_var, vlc_value_t old_val,
1181 vlc_value_t new_val, void *param )
1183 intf_dialog_args_t *p_arg = new intf_dialog_args_t;
1184 p_arg->p_dialog = (interaction_dialog_t *)(new_val.p_address);
1185 DialogEvent *event = new DialogEvent( INTF_DIALOG_INTERACTION, 0, p_arg );
1186 QApplication::postEvent( THEDP, event );
1190 /*****************************************************************************
1191 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1192 * We don't show the menu directly here because we don't want the
1193 * caller to block for a too long time.
1194 *****************************************************************************/
1195 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1196 vlc_value_t old_val, vlc_value_t new_val, void *param )
1198 intf_thread_t *p_intf = (intf_thread_t *)param;
1200 if( p_intf->pf_show_dialog )
1202 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1203 new_val.b_bool, NULL );
1209 /*****************************************************************************
1210 * IntfShowCB: callback triggered by the intf-show libvlc variable.
1211 *****************************************************************************/
1212 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1213 vlc_value_t old_val, vlc_value_t new_val, void *param )
1215 intf_thread_t *p_intf = (intf_thread_t *)param;
1216 p_intf->p_sys->p_mi->toggleFSC();