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/playlist/playlist.hpp"
38 #include "dialogs/extended.hpp"
39 #include "dialogs/playlist.hpp"
43 #include <QCloseEvent>
44 #include <QPushButton>
48 #include <QSystemTrayIcon>
53 #include <QWidgetAction>
62 /* Callback prototypes */
63 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
64 vlc_value_t old_val, vlc_value_t new_val, void *param );
65 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
66 vlc_value_t old_val, vlc_value_t new_val, void *param );
67 static int InteractCallback( vlc_object_t *, const char *, vlc_value_t,
70 MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
72 /* Variables initialisation */
73 // need_components_update = false;
76 playlistWidget = NULL;
78 videoIsActive = false;
79 playlistVisible = false;
81 fullscreenControls = NULL;
87 * Configuration and settings
88 * Pre-building of interface
91 setFocusPolicy( Qt::StrongFocus );
92 setAcceptDrops( true );
93 setWindowIcon( QApplication::windowIcon() );
94 setWindowOpacity( config_GetFloat( p_intf, "qt-opacity" ) );
96 /* Set The Video In emebedded Mode or not */
97 videoEmbeddedFlag = config_GetInt( p_intf, "embedded-video" );
99 /* Are we in the enhanced always-video mode or not ? */
100 i_visualmode = config_GetInt( p_intf, "qt-display-mode" );
102 /* Set the other interface settings */
103 settings = getSettings();
104 settings->beginGroup( "MainWindow" );
106 /* Visualisation, not really used yet */
107 visualSelectorEnabled = settings->value( "visual-selector", false).toBool();
109 /* Do we want anoying popups or not */
110 notificationEnabled = (bool)config_GetInt( p_intf, "qt-notification" );
112 /**************************
113 * UI and Widgets design
114 **************************/
115 setVLCWindowsTitle();
116 handleMainUi( settings );
119 /* Create a Dock to get the playlist */
120 dockPL = new QDockWidget( qtr( "Playlist" ), this );
121 dockPL->setSizePolicy( QSizePolicy::Preferred,
122 QSizePolicy::Expanding );
123 dockPL->setFeatures( QDockWidget::AllDockWidgetFeatures );
124 dockPL->setAllowedAreas( Qt::LeftDockWidgetArea
125 | Qt::RightDockWidgetArea
126 | Qt::BottomDockWidgetArea );
130 /**************************
131 * Menu Bar and Status Bar
132 **************************/
133 QVLCMenu::createMenuBar( this, p_intf, visualSelectorEnabled );
134 /* StatusBar Creation */
138 /********************
140 ********************/
141 MainInputManager::getInstance( p_intf );
143 /**************************
144 * Various CONNECTs on IM *
145 **************************/
146 /* Connect the input manager to the GUI elements it manages */
148 /* It is also connected to the control->slider, see the ControlsWidget */
149 /* Change the SpeedRate in the Status */
150 CONNECT( THEMIM->getIM(), rateChanged( int ), this, setRate( int ) );
153 * Connects on nameChanged()
154 * Those connects are not merged because different options can trigger
157 /* Naming in the controller statusbar */
158 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
159 setName( QString ) );
160 /* and in the systray */
163 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
164 updateSystrayTooltipName( QString ) );
166 /* and in the title of the controller */
167 if( config_GetInt( p_intf, "qt-name-in-title" ) )
169 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
170 setVLCWindowsTitle( QString ) );
174 * CONNECTS on PLAY_STATUS
176 /* Status on the main controller */
177 CONNECT( THEMIM->getIM(), statusChanged( int ), this, setStatus( int ) );
178 /* and in the systray */
181 CONNECT( THEMIM->getIM(), statusChanged( int ), this,
182 updateSystrayTooltipStatus( int ) );
185 /* END CONNECTS ON IM */
189 /* TODO Remove this function, but so far, there is no choice because there
190 is no intf-should-die variable #1365 */
191 ON_TIMEOUT( updateOnTimer() );
196 var_Create( p_intf, "interaction", VLC_VAR_ADDRESS );
197 var_AddCallback( p_intf, "interaction", InteractCallback, this );
198 p_intf->b_interaction = true;
200 var_AddCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
202 /* Register callback for the intf-popupmenu variable */
203 var_AddCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
206 /* VideoWidget connects to avoid different threads speaking to each other */
207 CONNECT( this, askReleaseVideo( void * ),
208 this, releaseVideoSlot( void * ) );
210 CONNECT( this, askVideoToResize( unsigned int, unsigned int ),
211 videoWidget, SetSizing( unsigned int, unsigned int ) );
213 CONNECT( this, askUpdate(), this, doComponentsUpdate() );
215 /* Size and placement of interface */
216 settings->beginGroup( "MainWindow" );
217 QVLCTools::restoreWidgetPosition( settings, this, QSize(380, 60) );
219 bool b_visible = settings->value( "playlist-visible", 0 ).toInt();
220 settings->endGroup();
223 if( b_visible ) togglePlaylist();
225 /* Final sizing and showing */
226 setMinimumWidth( __MAX( controls->sizeHint().width(),
227 menuBar()->sizeHint().width() ) );
230 /* And switch to minimal view if needed
231 Must be called after the show() */
232 if( i_visualmode == QT_MINIMAL_MODE )
235 /* Update the geometry : It is useful if you switch between
238 resize( sizeHint() );
240 /*****************************************************
241 * End everything by creating the Systray Management *
242 *****************************************************/
246 MainInterface::~MainInterface()
248 msg_Dbg( p_intf, "Destroying the main interface" );
250 if( videoIsActive ) videoWidget->hide();
255 QVLCTools::saveWidgetPosition( p_intf, "Playlist", playlistWidget );
257 delete playlistWidget;
260 settings->beginGroup( "MainWindow" );
262 settings->setValue( "pl-dock-status", (int)i_pl_dock );
263 settings->setValue( "playlist-visible", (int)playlistVisible );
264 settings->setValue( "adv-controls",
265 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
268 settings->setValue( "backgroundSize", bgWidget->size() );
270 QVLCTools::saveWidgetPosition(settings, this);
271 settings->endGroup();
273 var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
275 /* Unregister callback for the intf-popupmenu variable */
276 var_DelCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
278 p_intf->b_interaction = false;
279 var_DelCallback( p_intf, "interaction", InteractCallback, this );
281 p_intf->p_sys->p_mi = NULL;
284 /*****************************
286 *****************************/
288 inline void MainInterface::createStatusBar()
293 /* Widgets Creation*/
294 timeLabel = new TimeLabel( p_intf );
295 nameLabel = new QLabel;
296 nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
297 | Qt::TextSelectableByKeyboard );
298 speedLabel = new SpeedLabel( p_intf, "1.00x" );
299 speedLabel->setToolTip(
300 qtr( "Current playback speed.\nRight click to adjust" ) );
301 speedLabel->setContextMenuPolicy ( Qt::CustomContextMenu );
303 /* Styling those labels */
304 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
305 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
306 nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
308 /* and adding those */
309 statusBar()->addWidget( nameLabel, 8 );
310 statusBar()->addPermanentWidget( speedLabel, 0 );
311 statusBar()->addPermanentWidget( timeLabel, 0 );
313 /* timeLabel behaviour:
314 - double clicking opens the goto time dialog
315 - right-clicking and clicking just toggle between remaining and
317 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
319 /* Speed Label behaviour:
320 - right click gives the vertical speed slider */
321 CONNECT( speedLabel, customContextMenuRequested( QPoint ),
322 this, showSpeedMenu( QPoint ) );
325 inline void MainInterface::initSystray()
327 bool b_createSystray = false;
328 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
329 if( config_GetInt( p_intf, "qt-start-minimized") )
331 if( b_systrayAvailable )
333 b_createSystray = true;
336 else msg_Err( p_intf, "You can't minimize if you haven't a system "
339 if( config_GetInt( p_intf, "qt-system-tray") )
340 b_createSystray = true;
342 if( b_systrayAvailable && b_createSystray )
347 * Give the decorations of the Main Window a correct Name.
348 * If nothing is given, set it to VLC...
350 void MainInterface::setVLCWindowsTitle( QString aTitle )
352 if( aTitle.isEmpty() )
354 setWindowTitle( qtr( "VLC media player" ) );
358 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
362 void MainInterface::handleMainUi( QSettings *settings )
364 /* Create the main Widget and the mainLayout */
365 QWidget *main = new QWidget;
366 setCentralWidget( main );
367 mainLayout = new QVBoxLayout( main );
369 /* Margins, spacing */
370 main->setContentsMargins( 0, 0, 0, 0 );
371 main->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
372 mainLayout->setSpacing( 0 );
373 mainLayout->setMargin( 0 );
375 /* Create the CONTROLS Widget */
376 bool b_shiny = config_GetInt( p_intf, "qt-blingbling" );
377 controls = new ControlsWidget( p_intf, this,
378 settings->value( "adv-controls", false ).toBool(),
380 CONNECT( controls, advancedControlsToggled( bool ),
381 this, doComponentsUpdate() );
383 /* Add the controls Widget to the main Widget */
384 mainLayout->insertWidget( 0, controls, 0, Qt::AlignBottom );
386 /* Create the Speed Control Widget */
387 speedControl = new SpeedControlWidget( p_intf );
388 speedControlMenu = new QMenu( this );
390 QWidgetAction *widgetAction = new QWidgetAction( speedControl );
391 widgetAction->setDefaultWidget( speedControl );
392 speedControlMenu->addAction( widgetAction );
395 /* Disabled for now, they SUCK */
397 visualSelector = new VisualSelector( p_intf );
398 mainLayout->insertWidget( 0, visualSelector );
399 visualSelector->hide();
403 bgWidget = new BackgroundWidget( p_intf );
405 settings->value( "backgroundSize", QSize( 300, 200 ) ).toSize() );
406 bgWidget->updateGeometry();
407 mainLayout->insertWidget( 0, bgWidget );
408 CONNECT( this, askBgWidgetToToggle(), bgWidget, toggle() );
410 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
411 i_visualmode != QT_MINIMAL_MODE )
416 /* And video Outputs */
417 if( videoEmbeddedFlag )
419 videoWidget = new VideoWidget( p_intf );
420 mainLayout->insertWidget( 0, videoWidget, 10 );
423 /* Finish the sizing */
424 main->updateGeometry();
426 getSettings()->endGroup();
430 /* Create the FULLSCREEN CONTROLS Widget */
431 if( config_GetInt( p_intf, "qt-fs-controller" ) )
433 fullscreenControls = new FullscreenControllerWidget( p_intf, this,
434 settings->value( "adv-controls", false ).toBool(),
436 CONNECT( fullscreenControls, advancedControlsToggled( bool ),
437 this, doComponentsUpdate() );
441 inline void MainInterface::askForPrivacy()
444 * Ask for the network policy on FIRST STARTUP
446 if( config_GetInt( p_intf, "qt-privacy-ask") )
448 QList<ConfigControl *> controls;
449 if( privacyDialog( &controls ) == QDialog::Accepted )
451 QList<ConfigControl *>::Iterator i;
452 for( i = controls.begin() ; i != controls.end() ; i++ )
454 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
455 c->doApply( p_intf );
458 config_PutInt( p_intf, "qt-privacy-ask" , 0 );
459 /* We have to save here because the user may not launch Prefs */
460 config_SaveConfigFile( p_intf, NULL );
465 int MainInterface::privacyDialog( QList<ConfigControl *> *controls )
467 QDialog *privacy = new QDialog();
469 privacy->setWindowTitle( qtr( "Privacy and Network Policies" ) );
471 QGridLayout *gLayout = new QGridLayout( privacy );
473 QGroupBox *blabla = new QGroupBox( qtr( "Privacy and Network Warning" ) );
474 QGridLayout *blablaLayout = new QGridLayout( blabla );
475 QLabel *text = new QLabel( qtr(
476 "<p>The <i>VideoLAN Team</i> doesn't like when an application goes "
477 "online without authorization.</p>\n "
478 "<p><i>VLC media player</i> can retreive limited information from "
479 "the Internet in order to get CD covers or to check "
480 "for available updates.</p>\n"
481 "<p><i>VLC media player</i> <b>DOES NOT</b> send or collect <b>ANY</b> "
482 "information, even anonymously, about your usage.</p>\n"
483 "<p>Therefore please select from the following options, the default being "
484 "almost no access to the web.</p>\n") );
485 text->setWordWrap( true );
486 text->setTextFormat( Qt::RichText );
488 blablaLayout->addWidget( text, 0, 0 ) ;
490 QGroupBox *options = new QGroupBox;
491 QGridLayout *optionsLayout = new QGridLayout( options );
493 gLayout->addWidget( blabla, 0, 0, 1, 3 );
494 gLayout->addWidget( options, 1, 0, 1, 3 );
495 module_config_t *p_config;
496 ConfigControl *control;
499 #define CONFIG_GENERIC( option, type ) \
500 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
503 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
504 p_config, options, false, optionsLayout, line ); \
505 controls->append( control ); \
508 #define CONFIG_GENERIC_NOBOOL( option, type ) \
509 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
512 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
513 p_config, options, optionsLayout, line ); \
514 controls->append( control ); \
517 CONFIG_GENERIC( "album-art", IntegerList ); line++;
519 CONFIG_GENERIC_NOBOOL( "qt-updates-notif", Bool ); line++;
520 CONFIG_GENERIC_NOBOOL( "qt-updates-days", Integer ); line++;
523 QPushButton *ok = new QPushButton( qtr( "OK" ) );
525 gLayout->addWidget( ok, 2, 2 );
527 CONNECT( ok, clicked(), privacy, accept() );
528 return privacy->exec();
532 /**********************************************************************
533 * Handling of sizing of the components
534 **********************************************************************/
536 /* This function is probably wrong, but we don't have many many choices...
537 Since we can't know from the playlist Widget if we are inside a dock or not,
538 because the playlist Widget can be called by THEDP, as a separate windows for
540 Maybe the other solution is to redefine the sizeHint() of the playlist and
541 ask _parent->isFloating()...
542 If you think this would be better, please FIXME it...
545 QSize MainInterface::sizeHint() const
547 int nwidth = controls->sizeHint().width();
548 int nheight = controls->isVisible() ?
549 controls->size().height()
550 + menuBar()->size().height()
551 + statusBar()->size().height()
554 if( VISIBLE( bgWidget ) )
556 nheight += bgWidget->size().height();
557 nwidth = bgWidget->size().width();
559 else if( videoIsActive && videoWidget->isVisible() )
561 nheight += videoWidget->sizeHint().height();
562 nwidth = videoWidget->sizeHint().width();
565 if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget() )
567 nheight += dockPL->size().height();
568 nwidth = __MAX( nwidth, dockPL->size().width() );
569 msg_Warn( p_intf, "3 %i %i", nheight, nwidth );
572 return QSize( nwidth, nheight );
575 void MainInterface::toggleFSC()
577 if( !fullscreenControls ) return;
579 IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
580 QApplication::postEvent( fullscreenControls, static_cast<QEvent *>(eShow) );
583 void MainInterface::debug()
586 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
587 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
588 if( videoWidget && videoWidget->isVisible() )
590 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
591 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
596 /****************************************************************************
597 * Small right-click menu for rate control
598 ****************************************************************************/
599 void MainInterface::showSpeedMenu( QPoint pos )
601 speedControlMenu->exec( QCursor::pos() - pos
602 + QPoint( 0, speedLabel->height() ) );
605 /****************************************************************************
607 ****************************************************************************/
609 /* This event is used to deal with the fullscreen and always on top
610 issue conflict (bug in wx) */
611 class SetVideoOnTopQtEvent : public QEvent
614 SetVideoOnTopQtEvent( bool _onTop ) :
615 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
618 bool OnTop() const { return onTop; }
626 * Thou shall not call/resize/hide widgets from on another thread.
627 * This is wrong, and this is TEH reason to emit signals on those Video Functions
629 void *MainInterface::requestVideo( vout_thread_t *p_nvout, int *pi_x,
630 int *pi_y, unsigned int *pi_width,
631 unsigned int *pi_height )
633 /* Request the videoWidget */
634 void *ret = videoWidget->request( p_nvout,pi_x, pi_y, pi_width, pi_height );
635 if( ret ) /* The videoWidget is available */
637 /* Did we have a bg ? Hide it! */
638 if( VISIBLE( bgWidget) )
641 emit askBgWidgetToToggle();
644 bgWasVisible = false;
646 /* Consider the video active now */
647 videoIsActive = true;
651 if( fullscreenControls ) fullscreenControls->attachVout( p_nvout );
656 /* Call from the WindowClose function */
657 void MainInterface::releaseVideo( void *p_win )
659 if( fullscreenControls ) fullscreenControls->detachVout();
661 emit askReleaseVideo( p_win );
664 /* Function that is CONNECTED to the previous emit */
665 void MainInterface::releaseVideoSlot( void *p_win )
667 videoWidget->release( p_win );
671 /* Reset the bg state */
672 bgWasVisible = false;
676 videoIsActive = false;
678 /* Try to resize, except when you are in Fullscreen mode */
679 if( !isFullScreen() ) doComponentsUpdate();
682 /* Call from WindowControl function */
683 int MainInterface::controlVideo( void *p_window, int i_query, va_list args )
685 int i_ret = VLC_SUCCESS;
690 unsigned int *pi_width = va_arg( args, unsigned int * );
691 unsigned int *pi_height = va_arg( args, unsigned int * );
692 *pi_width = videoWidget->videoSize.width();
693 *pi_height = videoWidget->videoSize.height();
698 unsigned int i_width = va_arg( args, unsigned int );
699 unsigned int i_height = va_arg( args, unsigned int );
700 emit askVideoToResize( i_width, i_height );
704 case VOUT_SET_STAY_ON_TOP:
706 int i_arg = va_arg( args, int );
707 QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
711 i_ret = VLC_EGENERIC;
712 msg_Warn( p_intf, "unsupported control query" );
718 /*****************************************************************************
719 * Playlist, Visualisation and Menus handling
720 *****************************************************************************/
722 * Toggle the playlist widget or dialog
724 void MainInterface::togglePlaylist()
727 If no playlist exist, then create one and attach it to the DockPL*/
728 if( !playlistWidget )
730 playlistWidget = new PlaylistWidget( p_intf );
732 i_pl_dock = PL_UNDOCKED;
733 /* i_pl_dock = (pl_dock_e)getSettings()
734 ->value( "pl-dock-status", PL_UNDOCKED ).toInt(); */
736 if( i_pl_dock == PL_UNDOCKED )
738 playlistWidget->setWindowFlags( Qt::Window );
740 /* This will restore the geometry but will not work for position,
741 because of parenting */
742 QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
743 playlistWidget, QSize( 600, 300 ) );
747 mainLayout->insertWidget( 4, playlistWidget );
749 playlistVisible = true;
751 playlistWidget->show();
755 /* toggle the visibility of the playlist */
756 TOGGLEV( playlistWidget );
757 playlistVisible = !playlistVisible;
758 //doComponentsUpdate(); //resize( sizeHint() );
762 /* Function called from the menu to undock the playlist */
763 void MainInterface::undockPlaylist()
765 // dockPL->setFloating( true );
769 void MainInterface::dockPlaylist( pl_dock_e i_pos )
773 void MainInterface::toggleMinimalView()
775 /* HACK for minimalView, see menus.cpp */
776 if( !menuBar()->isVisible() ) QVLCMenu::minimalViewAction->toggle();
778 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
779 i_visualmode != QT_MINIMAL_MODE )
780 { /* NORMAL MODE then */
781 if( videoWidget->isHidden() ) emit askBgWidgetToToggle();
784 /* If video is visible, then toggle the status of bgWidget */
785 bgWasVisible = !bgWasVisible;
789 TOGGLEV( menuBar() );
791 TOGGLEV( statusBar() );
792 doComponentsUpdate();
795 /* Video widget cannot do this synchronously as it runs in another thread */
796 /* Well, could it, actually ? Probably dangerous ... */
798 /* This function is called:
799 - toggling of minimal View
800 - through askUpdate() by Vout thread request video and resize video (zoom)
801 - Advanced buttons toggled
803 void MainInterface::doComponentsUpdate()
805 msg_Dbg( p_intf, "Updating the geometry" );
806 /* Here we resize to sizeHint() and not adjustsize because we want
807 the videoWidget to be exactly the correctSize */
808 resize( sizeHint() );
815 /* toggling advanced controls buttons */
816 void MainInterface::toggleAdvanced()
818 controls->toggleAdvanced();
819 if( fullscreenControls ) fullscreenControls->toggleAdvanced();
822 /* Get the visibility status of the controls (hidden or not, advanced or not) */
823 int MainInterface::getControlsVisibilityStatus()
825 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
826 + CONTROLS_ADVANCED * controls->b_advancedVisible );
830 void MainInterface::visual()
832 if( !VISIBLE( visualSelector) )
834 visualSelector->show();
835 if( !THEMIM->getIM()->hasVideo() )
837 /* Show the background widget */
839 visualSelectorEnabled = true;
843 /* Stop any currently running visualization */
844 visualSelector->hide();
845 visualSelectorEnabled = false;
847 doComponentsUpdate();
851 /************************************************************************
853 ************************************************************************/
854 void MainInterface::setName( QString name )
856 input_name = name; /* store it for the QSystray use */
857 /* Display it in the status bar, but also as a Tooltip in case it doesn't
859 nameLabel->setText( " " + name + " " );
860 nameLabel->setToolTip( " " + name +" " );
863 void MainInterface::setStatus( int status )
865 msg_Dbg( p_intf, "Updating the stream status: %i", status );
867 /* Forward the status to the controls to toggle Play/Pause */
868 controls->setStatus( status );
869 controls->updateInput();
871 if( fullscreenControls )
873 fullscreenControls->setStatus( status );
874 fullscreenControls->updateInput();
877 speedControl->setEnable( THEMIM->getIM()->hasInput() );
879 /* And in the systray for the menu */
881 QVLCMenu::updateSystrayMenu( this, p_intf );
884 void MainInterface::setRate( int rate )
887 str.setNum( ( 1000 / (double)rate ), 'f', 2 );
889 speedLabel->setText( str );
890 speedLabel->setToolTip( str );
891 speedControl->updateControls( rate );
894 void MainInterface::updateOnTimer()
896 /* No event for dying */
897 if( !vlc_object_alive( p_intf ) )
899 QApplication::closeAllWindows();
900 QApplication::quit();
904 /*****************************************************************************
905 * Systray Icon and Systray Menu
906 *****************************************************************************/
909 * Create a SystemTray icon and a menu that would go with it.
910 * Connects to a click handler on the icon.
912 void MainInterface::createSystray()
915 if( QDate::currentDate().dayOfYear() >= 354 )
916 iconVLC = QIcon( QPixmap( ":/vlc128-christmas.png" ) );
918 iconVLC = QIcon( QPixmap( ":/vlc128.png" ) );
919 sysTray = new QSystemTrayIcon( iconVLC, this );
920 sysTray->setToolTip( qtr( "VLC media player" ));
922 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
923 systrayMenu->setIcon( iconVLC );
925 QVLCMenu::updateSystrayMenu( this, p_intf, true );
928 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
929 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
933 * Updates the Systray Icon's menu and toggle the main interface
935 void MainInterface::toggleUpdateSystrayMenu()
937 /* If hidden, show it */
943 else if( isMinimized() )
953 /* check if any visible window is above vlc in the z-order,
954 * but ignore the ones always on top */
957 wi.cbSize = sizeof( WINDOWINFO );
958 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
959 hwnd && !IsWindowVisible( hwnd );
960 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
961 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
962 (wi.dwExStyle&WS_EX_TOPMOST) )
964 if( isActiveWindow() )
974 QVLCMenu::updateSystrayMenu( this, p_intf );
977 void MainInterface::handleSystrayClick(
978 QSystemTrayIcon::ActivationReason reason )
982 case QSystemTrayIcon::Trigger:
983 toggleUpdateSystrayMenu();
985 case QSystemTrayIcon::MiddleClick:
986 sysTray->showMessage( qtr( "VLC media player" ),
987 qtr( "Control menu for the player" ),
988 QSystemTrayIcon::Information, 3000 );
994 * Updates the name of the systray Icon tooltip.
995 * Doesn't check if the systray exists, check before you call it.
997 void MainInterface::updateSystrayTooltipName( QString name )
1001 sysTray->setToolTip( qtr( "VLC media player" ) );
1005 sysTray->setToolTip( name );
1006 if( notificationEnabled && ( isHidden() || isMinimized() ) )
1008 sysTray->showMessage( qtr( "VLC media player" ), name,
1009 QSystemTrayIcon::NoIcon, 3000 );
1015 * Updates the status of the systray Icon tooltip.
1016 * Doesn't check if the systray exists, check before you call it.
1018 void MainInterface::updateSystrayTooltipStatus( int i_status )
1025 sysTray->setToolTip( qtr( "VLC media player" ) );
1030 sysTray->setToolTip( input_name );
1035 sysTray->setToolTip( input_name + " - "
1042 /************************************************************************
1044 ************************************************************************/
1045 void MainInterface::dropEvent(QDropEvent *event)
1047 dropEventPlay( event, true );
1050 void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
1052 const QMimeData *mimeData = event->mimeData();
1054 /* D&D of a subtitles file, add it on the fly */
1055 if( mimeData->urls().size() == 1 )
1057 if( THEMIM->getIM()->hasInput() )
1059 if( input_AddSubtitles( THEMIM->getInput(),
1060 qtu( toNativeSeparators(
1061 mimeData->urls()[0].toLocalFile() ) ),
1064 event->acceptProposedAction();
1069 bool first = b_play;
1070 foreach( QUrl url, mimeData->urls() )
1072 QString s = toNativeSeparators( url.toLocalFile() );
1074 if( s.length() > 0 ) {
1075 playlist_Add( THEPL, qtu(s), NULL,
1076 PLAYLIST_APPEND | (first ? PLAYLIST_GO: 0),
1077 PLAYLIST_END, true, false );
1081 event->acceptProposedAction();
1083 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1085 event->acceptProposedAction();
1087 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1089 event->acceptProposedAction();
1091 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1096 /************************************************************************
1098 ************************************************************************/
1099 void MainInterface::customEvent( QEvent *event )
1102 if( event->type() == PLDockEvent_Type )
1104 PlaylistDialog::killInstance();
1105 playlistEmbeddedFlag = true;
1107 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1112 if ( event->type() == SetVideoOnTopEvent_Type )
1114 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1115 if( p_event->OnTop() )
1116 setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
1118 setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint);
1119 show(); /* necessary to apply window flags?? */
1123 void MainInterface::keyPressEvent( QKeyEvent *e )
1125 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() == Qt::Key_H )
1126 && menuBar()->isHidden() )
1128 toggleMinimalView();
1132 int i_vlck = qtEventToVLCKey( e );
1135 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1142 void MainInterface::wheelEvent( QWheelEvent *e )
1144 int i_vlckey = qtWheelEventToVLCKey( e );
1145 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1149 void MainInterface::closeEvent( QCloseEvent *e )
1155 void MainInterface::toggleFullScreen( void )
1157 if( isFullScreen() )
1160 emit askUpdate(); // Needed if video was launched after the F11
1166 /*****************************************************************************
1168 *****************************************************************************/
1169 static int InteractCallback( vlc_object_t *p_this,
1170 const char *psz_var, vlc_value_t old_val,
1171 vlc_value_t new_val, void *param )
1173 intf_dialog_args_t *p_arg = new intf_dialog_args_t;
1174 p_arg->p_dialog = (interaction_dialog_t *)(new_val.p_address);
1175 DialogEvent *event = new DialogEvent( INTF_DIALOG_INTERACTION, 0, p_arg );
1176 QApplication::postEvent( THEDP, static_cast<QEvent*>(event) );
1180 /*****************************************************************************
1181 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1182 * We don't show the menu directly here because we don't want the
1183 * caller to block for a too long time.
1184 *****************************************************************************/
1185 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1186 vlc_value_t old_val, vlc_value_t new_val, void *param )
1188 intf_thread_t *p_intf = (intf_thread_t *)param;
1190 if( p_intf->pf_show_dialog )
1192 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1193 new_val.b_bool, 0 );
1199 /*****************************************************************************
1200 * IntfShowCB: callback triggered by the intf-show libvlc variable.
1201 *****************************************************************************/
1202 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1203 vlc_value_t old_val, vlc_value_t new_val, void *param )
1205 intf_thread_t *p_intf = (intf_thread_t *)param;
1206 p_intf->p_sys->p_mi->toggleFSC();