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"
42 #include "recents.hpp"
45 #include <QCloseEvent>
46 #include <QPushButton>
50 #include <QSystemTrayIcon>
55 #include <QWidgetAction>
64 /* Callback prototypes */
65 static int PopupMenuCB( 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 IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
68 vlc_value_t old_val, vlc_value_t new_val, void *param );
69 static int InteractCallback( vlc_object_t *, const char *, vlc_value_t,
72 MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
74 /* Variables initialisation */
75 // need_components_update = false;
78 playlistWidget = NULL;
80 videoIsActive = false;
81 playlistVisible = false;
83 fullscreenControls = NULL;
89 * Configuration and settings
90 * Pre-building of interface
93 setFocusPolicy( Qt::StrongFocus );
94 setAcceptDrops( true );
95 setWindowIcon( QApplication::windowIcon() );
96 setWindowOpacity( config_GetFloat( p_intf, "qt-opacity" ) );
98 /* Set The Video In emebedded Mode or not */
99 videoEmbeddedFlag = config_GetInt( p_intf, "embedded-video" );
101 /* Are we in the enhanced always-video mode or not ? */
102 i_visualmode = config_GetInt( p_intf, "qt-display-mode" );
104 /* Set the other interface settings */
105 settings = getSettings();
106 settings->beginGroup( "MainWindow" );
108 /* Visualisation, not really used yet */
109 visualSelectorEnabled = settings->value( "visual-selector", false).toBool();
111 /* Do we want anoying popups or not */
112 notificationEnabled = (bool)config_GetInt( p_intf, "qt-notification" );
114 /**************************
115 * UI and Widgets design
116 **************************/
117 setVLCWindowsTitle();
118 handleMainUi( settings );
121 /* Create a Dock to get the playlist */
122 dockPL = new QDockWidget( qtr( "Playlist" ), this );
123 dockPL->setSizePolicy( QSizePolicy::Preferred,
124 QSizePolicy::Expanding );
125 dockPL->setFeatures( QDockWidget::AllDockWidgetFeatures );
126 dockPL->setAllowedAreas( Qt::LeftDockWidgetArea
127 | Qt::RightDockWidgetArea
128 | Qt::BottomDockWidgetArea );
132 /**************************
133 * Menu Bar and Status Bar
134 **************************/
135 QVLCMenu::createMenuBar( this, p_intf, visualSelectorEnabled );
137 /* StatusBar Creation */
140 /* Recents menu updates */
141 CONNECT( RecentsMRL::getInstance( p_intf ), updated(), this, updateRecentsMenu() );
143 /********************
145 ********************/
146 MainInputManager::getInstance( p_intf );
148 /**************************
149 * Various CONNECTs on IM *
150 **************************/
151 /* Connect the input manager to the GUI elements it manages */
153 /* It is also connected to the control->slider, see the ControlsWidget */
154 /* Change the SpeedRate in the Status */
155 CONNECT( THEMIM->getIM(), rateChanged( int ), this, setRate( int ) );
158 * Connects on nameChanged()
159 * Those connects are not merged because different options can trigger
162 /* Naming in the controller statusbar */
163 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
164 setName( QString ) );
165 /* and in the systray */
168 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
169 updateSystrayTooltipName( QString ) );
171 /* and in the title of the controller */
172 if( config_GetInt( p_intf, "qt-name-in-title" ) )
174 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
175 setVLCWindowsTitle( QString ) );
179 * CONNECTS on PLAY_STATUS
181 /* Status on the main controller */
182 CONNECT( THEMIM->getIM(), statusChanged( int ), this, setStatus( int ) );
183 /* and in the systray */
186 CONNECT( THEMIM->getIM(), statusChanged( int ), this,
187 updateSystrayTooltipStatus( int ) );
190 /* END CONNECTS ON IM */
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 controls = new ControlsWidget( p_intf,
377 settings->value( "adv-controls", false ).toBool() );
378 CONNECT( controls, advancedControlsToggled( bool ),
379 this, doComponentsUpdate() );
381 /* Add the controls Widget to the main Widget */
382 mainLayout->insertWidget( 0, controls, 0, Qt::AlignBottom );
384 /* Create the Speed Control Widget */
385 speedControl = new SpeedControlWidget( p_intf );
386 speedControlMenu = new QMenu( this );
388 QWidgetAction *widgetAction = new QWidgetAction( speedControl );
389 widgetAction->setDefaultWidget( speedControl );
390 speedControlMenu->addAction( widgetAction );
393 /* Disabled for now, they SUCK */
395 visualSelector = new VisualSelector( p_intf );
396 mainLayout->insertWidget( 0, visualSelector );
397 visualSelector->hide();
401 bgWidget = new BackgroundWidget( p_intf );
403 settings->value( "backgroundSize", QSize( 300, 200 ) ).toSize() );
404 bgWidget->updateGeometry();
405 mainLayout->insertWidget( 0, bgWidget );
406 CONNECT( this, askBgWidgetToToggle(), bgWidget, toggle() );
408 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
409 i_visualmode != QT_MINIMAL_MODE )
414 /* And video Outputs */
415 if( videoEmbeddedFlag )
417 videoWidget = new VideoWidget( p_intf );
418 mainLayout->insertWidget( 0, videoWidget, 10 );
421 /* Finish the sizing */
422 main->updateGeometry();
424 getSettings()->endGroup();
428 /* Create the FULLSCREEN CONTROLS Widget */
429 if( config_GetInt( p_intf, "qt-fs-controller" ) )
431 fullscreenControls = new FullscreenControllerWidget( p_intf );
435 inline void MainInterface::askForPrivacy()
438 * Ask for the network policy on FIRST STARTUP
440 if( config_GetInt( p_intf, "qt-privacy-ask") )
442 QList<ConfigControl *> controls;
443 if( privacyDialog( &controls ) == QDialog::Accepted )
445 QList<ConfigControl *>::Iterator i;
446 for( i = controls.begin() ; i != controls.end() ; i++ )
448 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
449 c->doApply( p_intf );
452 config_PutInt( p_intf, "qt-privacy-ask" , 0 );
453 /* We have to save here because the user may not launch Prefs */
454 config_SaveConfigFile( p_intf, NULL );
459 int MainInterface::privacyDialog( QList<ConfigControl *> *controls )
461 QDialog *privacy = new QDialog();
463 privacy->setWindowTitle( qtr( "Privacy and Network Policies" ) );
465 QGridLayout *gLayout = new QGridLayout( privacy );
467 QGroupBox *blabla = new QGroupBox( qtr( "Privacy and Network Warning" ) );
468 QGridLayout *blablaLayout = new QGridLayout( blabla );
469 QLabel *text = new QLabel( qtr(
470 "<p>The <i>VideoLAN Team</i> doesn't like when an application goes "
471 "online without authorization.</p>\n "
472 "<p><i>VLC media player</i> can retreive limited information from "
473 "the Internet in order to get CD covers or to check "
474 "for available updates.</p>\n"
475 "<p><i>VLC media player</i> <b>DOES NOT</b> send or collect <b>ANY</b> "
476 "information, even anonymously, about your usage.</p>\n"
477 "<p>Therefore please select from the following options, the default being "
478 "almost no access to the web.</p>\n") );
479 text->setWordWrap( true );
480 text->setTextFormat( Qt::RichText );
482 blablaLayout->addWidget( text, 0, 0 ) ;
484 QGroupBox *options = new QGroupBox;
485 QGridLayout *optionsLayout = new QGridLayout( options );
487 gLayout->addWidget( blabla, 0, 0, 1, 3 );
488 gLayout->addWidget( options, 1, 0, 1, 3 );
489 module_config_t *p_config;
490 ConfigControl *control;
493 #define CONFIG_GENERIC( option, type ) \
494 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
497 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
498 p_config, options, false, optionsLayout, line ); \
499 controls->append( control ); \
502 #define CONFIG_GENERIC_NOBOOL( option, type ) \
503 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
506 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
507 p_config, options, optionsLayout, line ); \
508 controls->append( control ); \
511 CONFIG_GENERIC( "album-art", IntegerList ); line++;
513 CONFIG_GENERIC_NOBOOL( "qt-updates-notif", Bool ); line++;
514 CONFIG_GENERIC_NOBOOL( "qt-updates-days", Integer ); line++;
517 QPushButton *ok = new QPushButton( qtr( "OK" ) );
519 gLayout->addWidget( ok, 2, 2 );
521 CONNECT( ok, clicked(), privacy, accept() );
522 return privacy->exec();
526 /**********************************************************************
527 * Handling of sizing of the components
528 **********************************************************************/
530 /* This function is probably wrong, but we don't have many many choices...
531 Since we can't know from the playlist Widget if we are inside a dock or not,
532 because the playlist Widget can be called by THEDP, as a separate windows for
534 Maybe the other solution is to redefine the sizeHint() of the playlist and
535 ask _parent->isFloating()...
536 If you think this would be better, please FIXME it...
539 QSize MainInterface::sizeHint() const
541 int nwidth = controls->sizeHint().width();
542 int nheight = controls->isVisible() ?
543 controls->size().height()
544 + menuBar()->size().height()
545 + statusBar()->size().height()
548 if( VISIBLE( bgWidget ) )
550 nheight += bgWidget->size().height();
551 nwidth = bgWidget->size().width();
553 else if( videoIsActive && videoWidget->isVisible() )
555 nheight += videoWidget->sizeHint().height();
556 nwidth = videoWidget->sizeHint().width();
559 if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget() )
561 nheight += dockPL->size().height();
562 nwidth = __MAX( nwidth, dockPL->size().width() );
563 msg_Warn( p_intf, "3 %i %i", nheight, nwidth );
566 return QSize( nwidth, nheight );
569 void MainInterface::toggleFSC()
571 if( !fullscreenControls ) return;
573 IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
574 QApplication::postEvent( fullscreenControls, static_cast<QEvent *>(eShow) );
577 void MainInterface::debug()
580 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
581 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
582 if( videoWidget && videoWidget->isVisible() )
584 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
585 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
590 /****************************************************************************
591 * Small right-click menu for rate control
592 ****************************************************************************/
593 void MainInterface::showSpeedMenu( QPoint pos )
595 speedControlMenu->exec( QCursor::pos() - pos
596 + QPoint( 0, speedLabel->height() ) );
599 /****************************************************************************
601 ****************************************************************************/
603 /* This event is used to deal with the fullscreen and always on top
604 issue conflict (bug in wx) */
605 class SetVideoOnTopQtEvent : public QEvent
608 SetVideoOnTopQtEvent( bool _onTop ) :
609 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
612 bool OnTop() const { return onTop; }
620 * Thou shall not call/resize/hide widgets from on another thread.
621 * This is wrong, and this is TEH reason to emit signals on those Video Functions
623 void *MainInterface::requestVideo( vout_thread_t *p_nvout, int *pi_x,
624 int *pi_y, unsigned int *pi_width,
625 unsigned int *pi_height )
627 /* Request the videoWidget */
628 void *ret = videoWidget->request( p_nvout,pi_x, pi_y, pi_width, pi_height );
629 if( ret ) /* The videoWidget is available */
631 /* Did we have a bg ? Hide it! */
632 if( VISIBLE( bgWidget) )
635 emit askBgWidgetToToggle();
638 bgWasVisible = false;
640 /* Consider the video active now */
641 videoIsActive = true;
645 if( fullscreenControls ) fullscreenControls->attachVout( p_nvout );
650 /* Call from the WindowClose function */
651 void MainInterface::releaseVideo( void *p_win )
653 if( fullscreenControls ) fullscreenControls->detachVout();
655 emit askReleaseVideo( p_win );
658 /* Function that is CONNECTED to the previous emit */
659 void MainInterface::releaseVideoSlot( void *p_win )
661 videoWidget->release( p_win );
665 /* Reset the bg state */
666 bgWasVisible = false;
670 videoIsActive = false;
672 /* Try to resize, except when you are in Fullscreen mode */
673 if( !isFullScreen() ) doComponentsUpdate();
676 /* Call from WindowControl function */
677 int MainInterface::controlVideo( void *p_window, int i_query, va_list args )
679 int i_ret = VLC_SUCCESS;
684 unsigned int *pi_width = va_arg( args, unsigned int * );
685 unsigned int *pi_height = va_arg( args, unsigned int * );
686 *pi_width = videoWidget->videoSize.width();
687 *pi_height = videoWidget->videoSize.height();
692 unsigned int i_width = va_arg( args, unsigned int );
693 unsigned int i_height = va_arg( args, unsigned int );
694 emit askVideoToResize( i_width, i_height );
698 case VOUT_SET_STAY_ON_TOP:
700 int i_arg = va_arg( args, int );
701 QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
705 i_ret = VLC_EGENERIC;
706 msg_Warn( p_intf, "unsupported control query" );
712 /*****************************************************************************
713 * Playlist, Visualisation and Menus handling
714 *****************************************************************************/
716 * Toggle the playlist widget or dialog
718 void MainInterface::togglePlaylist()
721 If no playlist exist, then create one and attach it to the DockPL*/
722 if( !playlistWidget )
724 playlistWidget = new PlaylistWidget( p_intf );
726 i_pl_dock = PL_UNDOCKED;
727 /* i_pl_dock = (pl_dock_e)getSettings()
728 ->value( "pl-dock-status", PL_UNDOCKED ).toInt(); */
730 if( i_pl_dock == PL_UNDOCKED )
732 playlistWidget->setWindowFlags( Qt::Window );
734 /* This will restore the geometry but will not work for position,
735 because of parenting */
736 QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
737 playlistWidget, QSize( 600, 300 ) );
741 mainLayout->insertWidget( 4, playlistWidget );
743 playlistVisible = true;
745 playlistWidget->show();
749 /* toggle the visibility of the playlist */
750 TOGGLEV( playlistWidget );
751 playlistVisible = !playlistVisible;
752 //doComponentsUpdate(); //resize( sizeHint() );
756 /* Function called from the menu to undock the playlist */
757 void MainInterface::undockPlaylist()
759 // dockPL->setFloating( true );
763 void MainInterface::dockPlaylist( pl_dock_e i_pos )
767 void MainInterface::toggleMinimalView()
769 /* HACK for minimalView, see menus.cpp */
770 if( !menuBar()->isVisible() ) QVLCMenu::minimalViewAction->toggle();
772 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
773 i_visualmode != QT_MINIMAL_MODE )
774 { /* NORMAL MODE then */
775 if( videoWidget->isHidden() ) emit askBgWidgetToToggle();
778 /* If video is visible, then toggle the status of bgWidget */
779 bgWasVisible = !bgWasVisible;
783 TOGGLEV( menuBar() );
785 TOGGLEV( statusBar() );
786 doComponentsUpdate();
789 /* Video widget cannot do this synchronously as it runs in another thread */
790 /* Well, could it, actually ? Probably dangerous ... */
792 /* This function is called:
793 - toggling of minimal View
794 - through askUpdate() by Vout thread request video and resize video (zoom)
795 - Advanced buttons toggled
797 void MainInterface::doComponentsUpdate()
799 msg_Dbg( p_intf, "Updating the geometry" );
800 /* Here we resize to sizeHint() and not adjustsize because we want
801 the videoWidget to be exactly the correctSize */
802 resize( sizeHint() );
809 /* toggling advanced controls buttons */
810 void MainInterface::toggleAdvanced()
812 controls->toggleAdvanced();
813 // if( fullscreenControls ) fullscreenControls->toggleAdvanced();
816 /* Get the visibility status of the controls (hidden or not, advanced or not) */
817 int MainInterface::getControlsVisibilityStatus()
819 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
820 + CONTROLS_ADVANCED * controls->b_advancedVisible );
824 void MainInterface::visual()
826 if( !VISIBLE( visualSelector) )
828 visualSelector->show();
829 if( !THEMIM->getIM()->hasVideo() )
831 /* Show the background widget */
833 visualSelectorEnabled = true;
837 /* Stop any currently running visualization */
838 visualSelector->hide();
839 visualSelectorEnabled = false;
841 doComponentsUpdate();
845 /************************************************************************
847 ************************************************************************/
848 void MainInterface::setName( QString name )
850 input_name = name; /* store it for the QSystray use */
851 /* Display it in the status bar, but also as a Tooltip in case it doesn't
853 nameLabel->setText( " " + name + " " );
854 nameLabel->setToolTip( " " + name +" " );
857 void MainInterface::setStatus( int status )
859 msg_Dbg( p_intf, "Updating the stream status: %i", status );
861 speedControl->setEnable( THEMIM->getIM()->hasInput() );
863 /* And in the systray for the menu */
865 QVLCMenu::updateSystrayMenu( this, p_intf );
868 void MainInterface::setRate( int rate )
871 str.setNum( ( 1000 / (double)rate ), 'f', 2 );
873 speedLabel->setText( str );
874 speedLabel->setToolTip( str );
875 speedControl->updateControls( rate );
878 /*****************************************************************************
879 * Systray Icon and Systray Menu
880 *****************************************************************************/
883 * Create a SystemTray icon and a menu that would go with it.
884 * Connects to a click handler on the icon.
886 void MainInterface::createSystray()
889 if( QDate::currentDate().dayOfYear() >= 354 )
890 iconVLC = QIcon( QPixmap( ":/vlc128-christmas.png" ) );
892 iconVLC = QIcon( QPixmap( ":/vlc128.png" ) );
893 sysTray = new QSystemTrayIcon( iconVLC, this );
894 sysTray->setToolTip( qtr( "VLC media player" ));
896 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
897 systrayMenu->setIcon( iconVLC );
899 QVLCMenu::updateSystrayMenu( this, p_intf, true );
902 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
903 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
907 * Updates the Systray Icon's menu and toggle the main interface
909 void MainInterface::toggleUpdateSystrayMenu()
911 /* If hidden, show it */
917 else if( isMinimized() )
927 /* check if any visible window is above vlc in the z-order,
928 * but ignore the ones always on top */
931 wi.cbSize = sizeof( WINDOWINFO );
932 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
933 hwnd && !IsWindowVisible( hwnd );
934 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
935 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
936 (wi.dwExStyle&WS_EX_TOPMOST) )
938 if( isActiveWindow() )
948 QVLCMenu::updateSystrayMenu( this, p_intf );
951 void MainInterface::handleSystrayClick(
952 QSystemTrayIcon::ActivationReason reason )
956 case QSystemTrayIcon::Trigger:
957 toggleUpdateSystrayMenu();
959 case QSystemTrayIcon::MiddleClick:
960 sysTray->showMessage( qtr( "VLC media player" ),
961 qtr( "Control menu for the player" ),
962 QSystemTrayIcon::Information, 3000 );
968 * Updates the name of the systray Icon tooltip.
969 * Doesn't check if the systray exists, check before you call it.
971 void MainInterface::updateSystrayTooltipName( QString name )
975 sysTray->setToolTip( qtr( "VLC media player" ) );
979 sysTray->setToolTip( name );
980 if( notificationEnabled && ( isHidden() || isMinimized() ) )
982 sysTray->showMessage( qtr( "VLC media player" ), name,
983 QSystemTrayIcon::NoIcon, 3000 );
989 * Updates the status of the systray Icon tooltip.
990 * Doesn't check if the systray exists, check before you call it.
992 void MainInterface::updateSystrayTooltipStatus( int i_status )
999 sysTray->setToolTip( qtr( "VLC media player" ) );
1004 sysTray->setToolTip( input_name );
1009 sysTray->setToolTip( input_name + " - "
1016 /************************************************************************
1018 ************************************************************************/
1019 void MainInterface::dropEvent(QDropEvent *event)
1021 dropEventPlay( event, true );
1024 void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
1026 const QMimeData *mimeData = event->mimeData();
1028 /* D&D of a subtitles file, add it on the fly */
1029 if( mimeData->urls().size() == 1 )
1031 if( THEMIM->getIM()->hasInput() )
1033 if( input_AddSubtitles( THEMIM->getInput(),
1034 qtu( toNativeSeparators(
1035 mimeData->urls()[0].toLocalFile() ) ),
1038 event->acceptProposedAction();
1043 bool first = b_play;
1044 foreach( QUrl url, mimeData->urls() )
1046 QString s = toNativeSeparators( url.toLocalFile() );
1048 if( s.length() > 0 ) {
1049 playlist_Add( THEPL, qtu(s), NULL,
1050 PLAYLIST_APPEND | (first ? PLAYLIST_GO: 0),
1051 PLAYLIST_END, true, false );
1053 RecentsMRL::getInstance( p_intf )->addRecent( s );
1056 event->acceptProposedAction();
1058 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1060 event->acceptProposedAction();
1062 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1064 event->acceptProposedAction();
1066 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1071 /************************************************************************
1073 ************************************************************************/
1074 void MainInterface::customEvent( QEvent *event )
1077 if( event->type() == PLDockEvent_Type )
1079 PlaylistDialog::killInstance();
1080 playlistEmbeddedFlag = true;
1082 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1087 if ( event->type() == SetVideoOnTopEvent_Type )
1089 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1090 if( p_event->OnTop() )
1091 setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
1093 setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint);
1094 show(); /* necessary to apply window flags?? */
1098 void MainInterface::keyPressEvent( QKeyEvent *e )
1100 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() == Qt::Key_H )
1101 && menuBar()->isHidden() )
1103 toggleMinimalView();
1107 int i_vlck = qtEventToVLCKey( e );
1110 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1117 void MainInterface::wheelEvent( QWheelEvent *e )
1119 int i_vlckey = qtWheelEventToVLCKey( e );
1120 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1124 void MainInterface::closeEvent( QCloseEvent *e )
1130 void MainInterface::toggleFullScreen( void )
1132 if( isFullScreen() )
1135 emit askUpdate(); // Needed if video was launched after the F11
1141 /*****************************************************************************
1143 *****************************************************************************/
1144 static int InteractCallback( vlc_object_t *p_this,
1145 const char *psz_var, vlc_value_t old_val,
1146 vlc_value_t new_val, void *param )
1148 intf_dialog_args_t *p_arg = new intf_dialog_args_t;
1149 p_arg->p_dialog = (interaction_dialog_t *)(new_val.p_address);
1150 DialogEvent *event = new DialogEvent( INTF_DIALOG_INTERACTION, 0, p_arg );
1151 QApplication::postEvent( THEDP, static_cast<QEvent*>(event) );
1155 /*****************************************************************************
1156 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1157 * We don't show the menu directly here because we don't want the
1158 * caller to block for a too long time.
1159 *****************************************************************************/
1160 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1161 vlc_value_t old_val, vlc_value_t new_val, void *param )
1163 intf_thread_t *p_intf = (intf_thread_t *)param;
1165 if( p_intf->pf_show_dialog )
1167 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1168 new_val.b_bool, 0 );
1174 /*****************************************************************************
1175 * IntfShowCB: callback triggered by the intf-show libvlc variable.
1176 *****************************************************************************/
1177 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1178 vlc_value_t old_val, vlc_value_t new_val, void *param )
1180 intf_thread_t *p_intf = (intf_thread_t *)param;
1181 p_intf->p_sys->p_mi->toggleFSC();
1187 /*****************************************************************************
1188 * updateRecentsMenu: event called by RecentsMRL
1189 *****************************************************************************/
1191 void MainInterface::updateRecentsMenu()
1193 QVLCMenu::updateRecents( p_intf );