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 *****************************************************************************/
31 #include "main_interface.hpp"
32 #include "input_manager.hpp"
33 #include "util/qvlcframe.hpp"
34 #include "util/customwidgets.hpp"
35 #include "dialogs_provider.hpp"
36 #include "components/interface_widgets.hpp"
37 #include "components/controller.hpp"
38 #include "components/playlist/playlist.hpp"
39 #include "dialogs/extended.hpp"
40 #include "dialogs/playlist.hpp"
44 #include <QCloseEvent>
45 #include <QPushButton>
49 #include <QSystemTrayIcon>
54 #include <QWidgetAction>
63 /* Callback prototypes */
64 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
65 vlc_value_t old_val, vlc_value_t new_val, void *param );
66 static int IntfShowCB( 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 InteractCallback( vlc_object_t *, const char *, vlc_value_t,
71 MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
73 /* Variables initialisation */
74 // need_components_update = false;
77 playlistWidget = NULL;
79 videoIsActive = false;
80 playlistVisible = false;
82 fullscreenControls = NULL;
88 * Configuration and settings
89 * Pre-building of interface
92 setFocusPolicy( Qt::StrongFocus );
93 setAcceptDrops( true );
94 setWindowIcon( QApplication::windowIcon() );
95 setWindowOpacity( config_GetFloat( p_intf, "qt-opacity" ) );
97 /* Set The Video In emebedded Mode or not */
98 videoEmbeddedFlag = config_GetInt( p_intf, "embedded-video" );
100 /* Are we in the enhanced always-video mode or not ? */
101 i_visualmode = config_GetInt( p_intf, "qt-display-mode" );
103 /* Set the other interface settings */
104 settings = getSettings();
105 settings->beginGroup( "MainWindow" );
107 /* Visualisation, not really used yet */
108 visualSelectorEnabled = settings->value( "visual-selector", false).toBool();
110 /* Do we want anoying popups or not */
111 notificationEnabled = (bool)config_GetInt( p_intf, "qt-notification" );
113 /**************************
114 * UI and Widgets design
115 **************************/
116 setVLCWindowsTitle();
117 handleMainUi( settings );
120 /* Create a Dock to get the playlist */
121 dockPL = new QDockWidget( qtr( "Playlist" ), this );
122 dockPL->setSizePolicy( QSizePolicy::Preferred,
123 QSizePolicy::Expanding );
124 dockPL->setFeatures( QDockWidget::AllDockWidgetFeatures );
125 dockPL->setAllowedAreas( Qt::LeftDockWidgetArea
126 | Qt::RightDockWidgetArea
127 | Qt::BottomDockWidgetArea );
131 /**************************
132 * Menu Bar and Status Bar
133 **************************/
134 QVLCMenu::createMenuBar( this, p_intf, visualSelectorEnabled );
135 /* StatusBar Creation */
139 /********************
141 ********************/
142 MainInputManager::getInstance( p_intf );
144 /**************************
145 * Various CONNECTs on IM *
146 **************************/
147 /* Connect the input manager to the GUI elements it manages */
149 /* It is also connected to the control->slider, see the ControlsWidget */
150 /* Change the SpeedRate in the Status */
151 CONNECT( THEMIM->getIM(), rateChanged( int ), this, setRate( int ) );
154 * Connects on nameChanged()
155 * Those connects are not merged because different options can trigger
158 /* Naming in the controller statusbar */
159 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
160 setName( QString ) );
161 /* and in the systray */
164 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
165 updateSystrayTooltipName( QString ) );
167 /* and in the title of the controller */
168 if( config_GetInt( p_intf, "qt-name-in-title" ) )
170 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
171 setVLCWindowsTitle( QString ) );
175 * CONNECTS on PLAY_STATUS
177 /* Status on the main controller */
178 CONNECT( THEMIM->getIM(), statusChanged( int ), this, setStatus( int ) );
179 /* and in the systray */
182 CONNECT( THEMIM->getIM(), statusChanged( int ), this,
183 updateSystrayTooltipStatus( int ) );
186 /* END CONNECTS ON IM */
192 var_Create( p_intf, "interaction", VLC_VAR_ADDRESS );
193 var_AddCallback( p_intf, "interaction", InteractCallback, this );
194 p_intf->b_interaction = true;
196 var_AddCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
198 /* Register callback for the intf-popupmenu variable */
199 var_AddCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
202 /* VideoWidget connects to avoid different threads speaking to each other */
203 CONNECT( this, askReleaseVideo( void * ),
204 this, releaseVideoSlot( void * ) );
206 CONNECT( this, askVideoToResize( unsigned int, unsigned int ),
207 videoWidget, SetSizing( unsigned int, unsigned int ) );
209 CONNECT( this, askUpdate(), this, doComponentsUpdate() );
211 /* Size and placement of interface */
212 settings->beginGroup( "MainWindow" );
213 QVLCTools::restoreWidgetPosition( settings, this, QSize(380, 60) );
215 bool b_visible = settings->value( "playlist-visible", 0 ).toInt();
216 settings->endGroup();
219 if( b_visible ) togglePlaylist();
221 /* Final sizing and showing */
222 setMinimumWidth( __MAX( controls->sizeHint().width(),
223 menuBar()->sizeHint().width() ) );
226 /* And switch to minimal view if needed
227 Must be called after the show() */
228 if( i_visualmode == QT_MINIMAL_MODE )
231 /* Update the geometry : It is useful if you switch between
234 resize( sizeHint() );
236 /*****************************************************
237 * End everything by creating the Systray Management *
238 *****************************************************/
242 MainInterface::~MainInterface()
244 msg_Dbg( p_intf, "Destroying the main interface" );
246 if( videoIsActive ) videoWidget->hide();
251 QVLCTools::saveWidgetPosition( p_intf, "Playlist", playlistWidget );
253 delete playlistWidget;
256 settings->beginGroup( "MainWindow" );
258 settings->setValue( "pl-dock-status", (int)i_pl_dock );
259 settings->setValue( "playlist-visible", (int)playlistVisible );
260 settings->setValue( "adv-controls",
261 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
264 settings->setValue( "backgroundSize", bgWidget->size() );
266 QVLCTools::saveWidgetPosition(settings, this);
267 settings->endGroup();
269 var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
271 /* Unregister callback for the intf-popupmenu variable */
272 var_DelCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
274 p_intf->b_interaction = false;
275 var_DelCallback( p_intf, "interaction", InteractCallback, this );
277 p_intf->p_sys->p_mi = NULL;
280 /*****************************
282 *****************************/
284 inline void MainInterface::createStatusBar()
289 /* Widgets Creation*/
290 timeLabel = new TimeLabel( p_intf );
291 nameLabel = new QLabel;
292 nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
293 | Qt::TextSelectableByKeyboard );
294 speedLabel = new SpeedLabel( p_intf, "1.00x" );
295 speedLabel->setToolTip(
296 qtr( "Current playback speed.\nRight click to adjust" ) );
297 speedLabel->setContextMenuPolicy ( Qt::CustomContextMenu );
299 /* Styling those labels */
300 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
301 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
302 nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
304 /* and adding those */
305 statusBar()->addWidget( nameLabel, 8 );
306 statusBar()->addPermanentWidget( speedLabel, 0 );
307 statusBar()->addPermanentWidget( timeLabel, 0 );
309 /* timeLabel behaviour:
310 - double clicking opens the goto time dialog
311 - right-clicking and clicking just toggle between remaining and
313 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
315 /* Speed Label behaviour:
316 - right click gives the vertical speed slider */
317 CONNECT( speedLabel, customContextMenuRequested( QPoint ),
318 this, showSpeedMenu( QPoint ) );
321 inline void MainInterface::initSystray()
323 bool b_createSystray = false;
324 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
325 if( config_GetInt( p_intf, "qt-start-minimized") )
327 if( b_systrayAvailable )
329 b_createSystray = true;
332 else msg_Err( p_intf, "You can't minimize if you haven't a system "
335 if( config_GetInt( p_intf, "qt-system-tray") )
336 b_createSystray = true;
338 if( b_systrayAvailable && b_createSystray )
343 * Give the decorations of the Main Window a correct Name.
344 * If nothing is given, set it to VLC...
346 void MainInterface::setVLCWindowsTitle( QString aTitle )
348 if( aTitle.isEmpty() )
350 setWindowTitle( qtr( "VLC media player" ) );
354 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
358 void MainInterface::handleMainUi( QSettings *settings )
360 /* Create the main Widget and the mainLayout */
361 QWidget *main = new QWidget;
362 setCentralWidget( main );
363 mainLayout = new QVBoxLayout( main );
365 /* Margins, spacing */
366 main->setContentsMargins( 0, 0, 0, 0 );
367 main->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
368 mainLayout->setSpacing( 0 );
369 mainLayout->setMargin( 0 );
371 /* Create the CONTROLS Widget */
372 controls = new ControlsWidget( p_intf,
373 settings->value( "adv-controls", false ).toBool() );
374 CONNECT( controls, advancedControlsToggled( bool ),
375 this, doComponentsUpdate() );
377 /* Add the controls Widget to the main Widget */
378 mainLayout->insertWidget( 0, controls, 0, Qt::AlignBottom );
380 /* Create the Speed Control Widget */
381 speedControl = new SpeedControlWidget( p_intf );
382 speedControlMenu = new QMenu( this );
384 QWidgetAction *widgetAction = new QWidgetAction( speedControl );
385 widgetAction->setDefaultWidget( speedControl );
386 speedControlMenu->addAction( widgetAction );
389 /* Disabled for now, they SUCK */
391 visualSelector = new VisualSelector( p_intf );
392 mainLayout->insertWidget( 0, visualSelector );
393 visualSelector->hide();
397 bgWidget = new BackgroundWidget( p_intf );
399 settings->value( "backgroundSize", QSize( 300, 200 ) ).toSize() );
400 bgWidget->updateGeometry();
401 mainLayout->insertWidget( 0, bgWidget );
402 CONNECT( this, askBgWidgetToToggle(), bgWidget, toggle() );
404 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
405 i_visualmode != QT_MINIMAL_MODE )
410 /* And video Outputs */
411 if( videoEmbeddedFlag )
413 videoWidget = new VideoWidget( p_intf );
414 mainLayout->insertWidget( 0, videoWidget, 10 );
417 /* Finish the sizing */
418 main->updateGeometry();
420 getSettings()->endGroup();
424 /* Create the FULLSCREEN CONTROLS Widget */
425 if( config_GetInt( p_intf, "qt-fs-controller" ) )
427 fullscreenControls = new FullscreenControllerWidget( p_intf );
431 inline void MainInterface::askForPrivacy()
434 * Ask for the network policy on FIRST STARTUP
436 if( config_GetInt( p_intf, "qt-privacy-ask") )
438 QList<ConfigControl *> controls;
439 if( privacyDialog( &controls ) == QDialog::Accepted )
441 QList<ConfigControl *>::Iterator i;
442 for( i = controls.begin() ; i != controls.end() ; i++ )
444 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
445 c->doApply( p_intf );
448 config_PutInt( p_intf, "qt-privacy-ask" , 0 );
449 /* We have to save here because the user may not launch Prefs */
450 config_SaveConfigFile( p_intf, NULL );
455 int MainInterface::privacyDialog( QList<ConfigControl *> *controls )
457 QDialog *privacy = new QDialog();
459 privacy->setWindowTitle( qtr( "Privacy and Network Policies" ) );
461 QGridLayout *gLayout = new QGridLayout( privacy );
463 QGroupBox *blabla = new QGroupBox( qtr( "Privacy and Network Warning" ) );
464 QGridLayout *blablaLayout = new QGridLayout( blabla );
465 QLabel *text = new QLabel( qtr(
466 "<p>The <i>VideoLAN Team</i> doesn't like when an application goes "
467 "online without authorization.</p>\n "
468 "<p><i>VLC media player</i> can retreive limited information from "
469 "the Internet in order to get CD covers or to check "
470 "for available updates.</p>\n"
471 "<p><i>VLC media player</i> <b>DOES NOT</b> send or collect <b>ANY</b> "
472 "information, even anonymously, about your usage.</p>\n"
473 "<p>Therefore please select from the following options, the default being "
474 "almost no access to the web.</p>\n") );
475 text->setWordWrap( true );
476 text->setTextFormat( Qt::RichText );
478 blablaLayout->addWidget( text, 0, 0 ) ;
480 QGroupBox *options = new QGroupBox;
481 QGridLayout *optionsLayout = new QGridLayout( options );
483 gLayout->addWidget( blabla, 0, 0, 1, 3 );
484 gLayout->addWidget( options, 1, 0, 1, 3 );
485 module_config_t *p_config;
486 ConfigControl *control;
489 #define CONFIG_GENERIC( option, type ) \
490 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
493 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
494 p_config, options, false, optionsLayout, line ); \
495 controls->append( control ); \
498 #define CONFIG_GENERIC_NOBOOL( option, type ) \
499 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
502 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
503 p_config, options, optionsLayout, line ); \
504 controls->append( control ); \
507 CONFIG_GENERIC( "album-art", IntegerList ); line++;
509 CONFIG_GENERIC_NOBOOL( "qt-updates-notif", Bool ); line++;
510 CONFIG_GENERIC_NOBOOL( "qt-updates-days", Integer ); line++;
513 QPushButton *ok = new QPushButton( qtr( "OK" ) );
515 gLayout->addWidget( ok, 2, 2 );
517 CONNECT( ok, clicked(), privacy, accept() );
518 return privacy->exec();
522 /**********************************************************************
523 * Handling of sizing of the components
524 **********************************************************************/
526 /* This function is probably wrong, but we don't have many many choices...
527 Since we can't know from the playlist Widget if we are inside a dock or not,
528 because the playlist Widget can be called by THEDP, as a separate windows for
530 Maybe the other solution is to redefine the sizeHint() of the playlist and
531 ask _parent->isFloating()...
532 If you think this would be better, please FIXME it...
535 QSize MainInterface::sizeHint() const
537 int nwidth = controls->sizeHint().width();
538 int nheight = controls->isVisible() ?
539 controls->size().height()
540 + menuBar()->size().height()
541 + statusBar()->size().height()
544 if( VISIBLE( bgWidget ) )
546 nheight += bgWidget->size().height();
547 nwidth = bgWidget->size().width();
549 else if( videoIsActive && videoWidget->isVisible() )
551 nheight += videoWidget->sizeHint().height();
552 nwidth = videoWidget->sizeHint().width();
555 if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget() )
557 nheight += dockPL->size().height();
558 nwidth = __MAX( nwidth, dockPL->size().width() );
559 msg_Warn( p_intf, "3 %i %i", nheight, nwidth );
562 return QSize( nwidth, nheight );
565 void MainInterface::toggleFSC()
567 if( !fullscreenControls ) return;
569 IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
570 QApplication::postEvent( fullscreenControls, static_cast<QEvent *>(eShow) );
573 void MainInterface::debug()
576 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
577 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
578 if( videoWidget && videoWidget->isVisible() )
580 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
581 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
586 /****************************************************************************
587 * Small right-click menu for rate control
588 ****************************************************************************/
589 void MainInterface::showSpeedMenu( QPoint pos )
591 speedControlMenu->exec( QCursor::pos() - pos
592 + QPoint( 0, speedLabel->height() ) );
595 /****************************************************************************
597 ****************************************************************************/
599 /* This event is used to deal with the fullscreen and always on top
600 issue conflict (bug in wx) */
601 class SetVideoOnTopQtEvent : public QEvent
604 SetVideoOnTopQtEvent( bool _onTop ) :
605 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
608 bool OnTop() const { return onTop; }
616 * Thou shall not call/resize/hide widgets from on another thread.
617 * This is wrong, and this is TEH reason to emit signals on those Video Functions
619 void *MainInterface::requestVideo( vout_thread_t *p_nvout, int *pi_x,
620 int *pi_y, unsigned int *pi_width,
621 unsigned int *pi_height )
623 /* Request the videoWidget */
624 void *ret = videoWidget->request( p_nvout,pi_x, pi_y, pi_width, pi_height );
625 if( ret ) /* The videoWidget is available */
627 /* Did we have a bg ? Hide it! */
628 if( VISIBLE( bgWidget) )
631 emit askBgWidgetToToggle();
634 bgWasVisible = false;
636 /* Consider the video active now */
637 videoIsActive = true;
641 if( fullscreenControls ) fullscreenControls->attachVout( p_nvout );
646 /* Call from the WindowClose function */
647 void MainInterface::releaseVideo( void *p_win )
649 if( fullscreenControls ) fullscreenControls->detachVout();
651 emit askReleaseVideo( p_win );
654 /* Function that is CONNECTED to the previous emit */
655 void MainInterface::releaseVideoSlot( void *p_win )
657 videoWidget->release( p_win );
661 /* Reset the bg state */
662 bgWasVisible = false;
666 videoIsActive = false;
668 /* Try to resize, except when you are in Fullscreen mode */
669 if( !isFullScreen() ) doComponentsUpdate();
672 /* Call from WindowControl function */
673 int MainInterface::controlVideo( void *p_window, int i_query, va_list args )
675 int i_ret = VLC_SUCCESS;
680 unsigned int *pi_width = va_arg( args, unsigned int * );
681 unsigned int *pi_height = va_arg( args, unsigned int * );
682 *pi_width = videoWidget->videoSize.width();
683 *pi_height = videoWidget->videoSize.height();
688 unsigned int i_width = va_arg( args, unsigned int );
689 unsigned int i_height = va_arg( args, unsigned int );
690 emit askVideoToResize( i_width, i_height );
694 case VOUT_SET_STAY_ON_TOP:
696 int i_arg = va_arg( args, int );
697 QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
701 i_ret = VLC_EGENERIC;
702 msg_Warn( p_intf, "unsupported control query" );
708 /*****************************************************************************
709 * Playlist, Visualisation and Menus handling
710 *****************************************************************************/
712 * Toggle the playlist widget or dialog
714 void MainInterface::togglePlaylist()
717 If no playlist exist, then create one and attach it to the DockPL*/
718 if( !playlistWidget )
720 playlistWidget = new PlaylistWidget( p_intf );
722 i_pl_dock = PL_UNDOCKED;
723 /* i_pl_dock = (pl_dock_e)getSettings()
724 ->value( "pl-dock-status", PL_UNDOCKED ).toInt(); */
726 if( i_pl_dock == PL_UNDOCKED )
728 playlistWidget->setWindowFlags( Qt::Window );
730 /* This will restore the geometry but will not work for position,
731 because of parenting */
732 QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
733 playlistWidget, QSize( 600, 300 ) );
737 mainLayout->insertWidget( 4, playlistWidget );
739 playlistVisible = true;
741 playlistWidget->show();
745 /* toggle the visibility of the playlist */
746 TOGGLEV( playlistWidget );
747 playlistVisible = !playlistVisible;
748 //doComponentsUpdate(); //resize( sizeHint() );
752 /* Function called from the menu to undock the playlist */
753 void MainInterface::undockPlaylist()
755 // dockPL->setFloating( true );
759 void MainInterface::dockPlaylist( pl_dock_e i_pos )
763 void MainInterface::toggleMinimalView()
765 /* HACK for minimalView, see menus.cpp */
766 if( !menuBar()->isVisible() ) QVLCMenu::minimalViewAction->toggle();
768 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
769 i_visualmode != QT_MINIMAL_MODE )
770 { /* NORMAL MODE then */
771 if( videoWidget->isHidden() ) emit askBgWidgetToToggle();
774 /* If video is visible, then toggle the status of bgWidget */
775 bgWasVisible = !bgWasVisible;
779 TOGGLEV( menuBar() );
781 TOGGLEV( statusBar() );
782 doComponentsUpdate();
785 /* Video widget cannot do this synchronously as it runs in another thread */
786 /* Well, could it, actually ? Probably dangerous ... */
788 /* This function is called:
789 - toggling of minimal View
790 - through askUpdate() by Vout thread request video and resize video (zoom)
791 - Advanced buttons toggled
793 void MainInterface::doComponentsUpdate()
795 msg_Dbg( p_intf, "Updating the geometry" );
796 /* Here we resize to sizeHint() and not adjustsize because we want
797 the videoWidget to be exactly the correctSize */
798 resize( sizeHint() );
805 /* toggling advanced controls buttons */
806 void MainInterface::toggleAdvanced()
808 controls->toggleAdvanced();
809 // if( fullscreenControls ) fullscreenControls->toggleAdvanced();
812 /* Get the visibility status of the controls (hidden or not, advanced or not) */
813 int MainInterface::getControlsVisibilityStatus()
815 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
816 + CONTROLS_ADVANCED * controls->b_advancedVisible );
820 void MainInterface::visual()
822 if( !VISIBLE( visualSelector) )
824 visualSelector->show();
825 if( !THEMIM->getIM()->hasVideo() )
827 /* Show the background widget */
829 visualSelectorEnabled = true;
833 /* Stop any currently running visualization */
834 visualSelector->hide();
835 visualSelectorEnabled = false;
837 doComponentsUpdate();
841 /************************************************************************
843 ************************************************************************/
844 void MainInterface::setName( QString name )
846 input_name = name; /* store it for the QSystray use */
847 /* Display it in the status bar, but also as a Tooltip in case it doesn't
849 nameLabel->setText( " " + name + " " );
850 nameLabel->setToolTip( " " + name +" " );
853 void MainInterface::setStatus( int status )
855 msg_Dbg( p_intf, "Updating the stream status: %i", status );
857 speedControl->setEnable( THEMIM->getIM()->hasInput() );
859 /* And in the systray for the menu */
861 QVLCMenu::updateSystrayMenu( this, p_intf );
864 void MainInterface::setRate( int rate )
867 str.setNum( ( 1000 / (double)rate ), 'f', 2 );
869 speedLabel->setText( str );
870 speedLabel->setToolTip( str );
871 speedControl->updateControls( rate );
874 /*****************************************************************************
875 * Systray Icon and Systray Menu
876 *****************************************************************************/
879 * Create a SystemTray icon and a menu that would go with it.
880 * Connects to a click handler on the icon.
882 void MainInterface::createSystray()
885 if( QDate::currentDate().dayOfYear() >= 354 )
886 iconVLC = QIcon( QPixmap( ":/vlc128-christmas.png" ) );
888 iconVLC = QIcon( QPixmap( ":/vlc128.png" ) );
889 sysTray = new QSystemTrayIcon( iconVLC, this );
890 sysTray->setToolTip( qtr( "VLC media player" ));
892 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
893 systrayMenu->setIcon( iconVLC );
895 QVLCMenu::updateSystrayMenu( this, p_intf, true );
898 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
899 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
903 * Updates the Systray Icon's menu and toggle the main interface
905 void MainInterface::toggleUpdateSystrayMenu()
907 /* If hidden, show it */
913 else if( isMinimized() )
923 /* check if any visible window is above vlc in the z-order,
924 * but ignore the ones always on top */
927 wi.cbSize = sizeof( WINDOWINFO );
928 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
929 hwnd && !IsWindowVisible( hwnd );
930 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
931 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
932 (wi.dwExStyle&WS_EX_TOPMOST) )
934 if( isActiveWindow() )
944 QVLCMenu::updateSystrayMenu( this, p_intf );
947 void MainInterface::handleSystrayClick(
948 QSystemTrayIcon::ActivationReason reason )
952 case QSystemTrayIcon::Trigger:
953 toggleUpdateSystrayMenu();
955 case QSystemTrayIcon::MiddleClick:
956 sysTray->showMessage( qtr( "VLC media player" ),
957 qtr( "Control menu for the player" ),
958 QSystemTrayIcon::Information, 3000 );
964 * Updates the name of the systray Icon tooltip.
965 * Doesn't check if the systray exists, check before you call it.
967 void MainInterface::updateSystrayTooltipName( QString name )
971 sysTray->setToolTip( qtr( "VLC media player" ) );
975 sysTray->setToolTip( name );
976 if( notificationEnabled && ( isHidden() || isMinimized() ) )
978 sysTray->showMessage( qtr( "VLC media player" ), name,
979 QSystemTrayIcon::NoIcon, 3000 );
985 * Updates the status of the systray Icon tooltip.
986 * Doesn't check if the systray exists, check before you call it.
988 void MainInterface::updateSystrayTooltipStatus( int i_status )
995 sysTray->setToolTip( qtr( "VLC media player" ) );
1000 sysTray->setToolTip( input_name );
1005 sysTray->setToolTip( input_name + " - "
1012 /************************************************************************
1014 ************************************************************************/
1015 void MainInterface::dropEvent(QDropEvent *event)
1017 dropEventPlay( event, true );
1020 void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
1022 const QMimeData *mimeData = event->mimeData();
1024 /* D&D of a subtitles file, add it on the fly */
1025 if( mimeData->urls().size() == 1 )
1027 if( THEMIM->getIM()->hasInput() )
1029 if( input_AddSubtitles( THEMIM->getInput(),
1030 qtu( toNativeSeparators(
1031 mimeData->urls()[0].toLocalFile() ) ),
1034 event->acceptProposedAction();
1039 bool first = b_play;
1040 foreach( QUrl url, mimeData->urls() )
1042 QString s = toNativeSeparators( url.toLocalFile() );
1044 if( s.length() > 0 ) {
1045 playlist_Add( THEPL, qtu(s), NULL,
1046 PLAYLIST_APPEND | (first ? PLAYLIST_GO: 0),
1047 PLAYLIST_END, true, false );
1051 event->acceptProposedAction();
1053 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1055 event->acceptProposedAction();
1057 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1059 event->acceptProposedAction();
1061 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1066 /************************************************************************
1068 ************************************************************************/
1069 void MainInterface::customEvent( QEvent *event )
1072 if( event->type() == PLDockEvent_Type )
1074 PlaylistDialog::killInstance();
1075 playlistEmbeddedFlag = true;
1077 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1082 if ( event->type() == SetVideoOnTopEvent_Type )
1084 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1085 if( p_event->OnTop() )
1086 setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
1088 setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint);
1089 show(); /* necessary to apply window flags?? */
1093 void MainInterface::keyPressEvent( QKeyEvent *e )
1095 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() == Qt::Key_H )
1096 && menuBar()->isHidden() )
1098 toggleMinimalView();
1102 int i_vlck = qtEventToVLCKey( e );
1105 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1112 void MainInterface::wheelEvent( QWheelEvent *e )
1114 int i_vlckey = qtWheelEventToVLCKey( e );
1115 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1119 void MainInterface::closeEvent( QCloseEvent *e )
1125 void MainInterface::toggleFullScreen( void )
1127 if( isFullScreen() )
1130 emit askUpdate(); // Needed if video was launched after the F11
1136 /*****************************************************************************
1138 *****************************************************************************/
1139 static int InteractCallback( vlc_object_t *p_this,
1140 const char *psz_var, vlc_value_t old_val,
1141 vlc_value_t new_val, void *param )
1143 intf_dialog_args_t *p_arg = new intf_dialog_args_t;
1144 p_arg->p_dialog = (interaction_dialog_t *)(new_val.p_address);
1145 DialogEvent *event = new DialogEvent( INTF_DIALOG_INTERACTION, 0, p_arg );
1146 QApplication::postEvent( THEDP, static_cast<QEvent*>(event) );
1150 /*****************************************************************************
1151 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1152 * We don't show the menu directly here because we don't want the
1153 * caller to block for a too long time.
1154 *****************************************************************************/
1155 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1156 vlc_value_t old_val, vlc_value_t new_val, void *param )
1158 intf_thread_t *p_intf = (intf_thread_t *)param;
1160 if( p_intf->pf_show_dialog )
1162 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1163 new_val.b_bool, 0 );
1169 /*****************************************************************************
1170 * IntfShowCB: callback triggered by the intf-show libvlc variable.
1171 *****************************************************************************/
1172 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1173 vlc_value_t old_val, vlc_value_t new_val, void *param )
1175 intf_thread_t *p_intf = (intf_thread_t *)param;
1176 p_intf->p_sys->p_mi->toggleFSC();