1 /*****************************************************************************
2 * main_interface.cpp : Main interface
3 ****************************************************************************
4 * Copyright (C) 2006-2008 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Jean-Baptiste Kempf <jb@videolan.org>
9 * Ilkka Ollakka <ileoo@videolan.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
32 #include "main_interface.hpp"
33 #include "input_manager.hpp"
35 #include "util/customwidgets.hpp"
36 #include "util/qvlcapp.hpp" /* DialogEvent defintion */
38 #include "components/interface_widgets.hpp"
39 #include "components/controller.hpp"
40 #include "components/playlist/playlist.hpp"
43 #include "recents.hpp"
45 #include <QCloseEvent>
56 #include <QPushButton>
57 #include <QWidgetAction>
61 #include <vlc_keys.h> /* Wheel event */
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(),
142 this, updateRecentsMenu() );
144 /********************
146 ********************/
147 MainInputManager::getInstance( p_intf );
149 /**************************
150 * Various CONNECTs on IM *
151 **************************/
152 /* Connect the input manager to the GUI elements it manages */
154 /* Change the SpeedRate in the Status Bar */
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(), this );
378 CONNECT( controls, advancedControlsToggled( bool ),
379 this, doComponentsUpdate() );
380 InputControlsWidget *inputC = new InputControlsWidget( p_intf, this );
382 /* Add the controls Widget to the main Widget */
383 mainLayout->insertWidget( 0, controls, 0, Qt::AlignBottom );
384 mainLayout->insertWidget( 0, inputC, 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 );
437 inline void MainInterface::askForPrivacy()
440 * Ask for the network policy on FIRST STARTUP
442 if( config_GetInt( p_intf, "qt-privacy-ask") )
444 QList<ConfigControl *> controls;
445 if( privacyDialog( &controls ) == QDialog::Accepted )
447 QList<ConfigControl *>::Iterator i;
448 for( i = controls.begin() ; i != controls.end() ; i++ )
450 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
451 c->doApply( p_intf );
454 config_PutInt( p_intf, "qt-privacy-ask" , 0 );
455 /* We have to save here because the user may not launch Prefs */
456 config_SaveConfigFile( p_intf, NULL );
461 int MainInterface::privacyDialog( QList<ConfigControl *> *controls )
463 QDialog *privacy = new QDialog();
465 privacy->setWindowTitle( qtr( "Privacy and Network Policies" ) );
467 QGridLayout *gLayout = new QGridLayout( privacy );
469 QGroupBox *blabla = new QGroupBox( qtr( "Privacy and Network Warning" ) );
470 QGridLayout *blablaLayout = new QGridLayout( blabla );
471 QLabel *text = new QLabel( qtr(
472 "<p>The <i>VideoLAN Team</i> doesn't like when an application goes "
473 "online without authorization.</p>\n "
474 "<p><i>VLC media player</i> can retreive limited information from "
475 "the Internet in order to get CD covers or to check "
476 "for available updates.</p>\n"
477 "<p><i>VLC media player</i> <b>DOES NOT</b> send or collect <b>ANY</b> "
478 "information, even anonymously, about your usage.</p>\n"
479 "<p>Therefore please select from the following options, the default being "
480 "almost no access to the web.</p>\n") );
481 text->setWordWrap( true );
482 text->setTextFormat( Qt::RichText );
484 blablaLayout->addWidget( text, 0, 0 ) ;
486 QGroupBox *options = new QGroupBox;
487 QGridLayout *optionsLayout = new QGridLayout( options );
489 gLayout->addWidget( blabla, 0, 0, 1, 3 );
490 gLayout->addWidget( options, 1, 0, 1, 3 );
491 module_config_t *p_config;
492 ConfigControl *control;
495 #define CONFIG_GENERIC( option, type ) \
496 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
499 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
500 p_config, options, false, optionsLayout, line ); \
501 controls->append( control ); \
504 #define CONFIG_GENERIC_NOBOOL( option, type ) \
505 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
508 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
509 p_config, options, optionsLayout, line ); \
510 controls->append( control ); \
513 CONFIG_GENERIC( "album-art", IntegerList ); line++;
515 CONFIG_GENERIC_NOBOOL( "qt-updates-notif", Bool ); line++;
516 CONFIG_GENERIC_NOBOOL( "qt-updates-days", Integer ); line++;
519 QPushButton *ok = new QPushButton( qtr( "OK" ) );
521 gLayout->addWidget( ok, 2, 2 );
523 CONNECT( ok, clicked(), privacy, accept() );
524 return privacy->exec();
528 /**********************************************************************
529 * Handling of sizing of the components
530 **********************************************************************/
532 /* This function is probably wrong, but we don't have many many choices...
533 Since we can't know from the playlist Widget if we are inside a dock or not,
534 because the playlist Widget can be called by THEDP, as a separate windows for
536 Maybe the other solution is to redefine the sizeHint() of the playlist and
537 ask _parent->isFloating()...
538 If you think this would be better, please FIXME it...
541 QSize MainInterface::sizeHint() const
543 int nwidth = controls->sizeHint().width();
544 int nheight = controls->isVisible() ?
545 controls->size().height()
546 + menuBar()->size().height()
547 + statusBar()->size().height()
550 if( VISIBLE( bgWidget ) )
552 nheight += bgWidget->size().height();
553 nwidth = bgWidget->size().width();
555 else if( videoIsActive && videoWidget->isVisible() )
557 nheight += videoWidget->sizeHint().height();
558 nwidth = videoWidget->sizeHint().width();
561 if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget() )
563 nheight += dockPL->size().height();
564 nwidth = __MAX( nwidth, dockPL->size().width() );
565 msg_Warn( p_intf, "3 %i %i", nheight, nwidth );
568 return QSize( nwidth, nheight );
571 void MainInterface::toggleFSC()
573 if( !fullscreenControls ) return;
575 IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
576 QApplication::postEvent( fullscreenControls, static_cast<QEvent *>(eShow) );
579 void MainInterface::debug()
582 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
583 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
584 if( videoWidget && videoWidget->isVisible() )
586 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
587 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
592 /****************************************************************************
593 * Small right-click menu for rate control
594 ****************************************************************************/
595 void MainInterface::showSpeedMenu( QPoint pos )
597 speedControlMenu->exec( QCursor::pos() - pos
598 + QPoint( 0, speedLabel->height() ) );
601 /****************************************************************************
603 ****************************************************************************/
605 /* This event is used to deal with the fullscreen and always on top
606 issue conflict (bug in wx) */
607 class SetVideoOnTopQtEvent : public QEvent
610 SetVideoOnTopQtEvent( bool _onTop ) :
611 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
614 bool OnTop() const { return onTop; }
622 * Thou shall not call/resize/hide widgets from on another thread.
623 * This is wrong, and this is TEH reason to emit signals on those Video Functions
625 void *MainInterface::requestVideo( vout_thread_t *p_nvout, int *pi_x,
626 int *pi_y, unsigned int *pi_width,
627 unsigned int *pi_height )
629 /* Request the videoWidget */
630 void *ret = videoWidget->request( p_nvout,pi_x, pi_y, pi_width, pi_height );
631 if( ret ) /* The videoWidget is available */
633 /* Did we have a bg ? Hide it! */
634 if( VISIBLE( bgWidget) )
637 emit askBgWidgetToToggle();
640 bgWasVisible = false;
642 /* Consider the video active now */
643 videoIsActive = true;
647 if( fullscreenControls ) fullscreenControls->attachVout( p_nvout );
652 /* Call from the WindowClose function */
653 void MainInterface::releaseVideo( void )
655 if( fullscreenControls ) fullscreenControls->detachVout();
656 emit askReleaseVideo( );
659 /* Function that is CONNECTED to the previous emit */
660 void MainInterface::releaseVideoSlot( void )
662 videoWidget->release( );
666 /* Reset the bg state */
667 bgWasVisible = false;
671 videoIsActive = false;
673 /* Try to resize, except when you are in Fullscreen mode */
674 if( !isFullScreen() ) doComponentsUpdate();
677 /* Call from WindowControl function */
678 int MainInterface::controlVideo( void *p_window, int i_query, va_list args )
680 int i_ret = VLC_SUCCESS;
685 unsigned int *pi_width = va_arg( args, unsigned int * );
686 unsigned int *pi_height = va_arg( args, unsigned int * );
687 *pi_width = videoWidget->videoSize.width();
688 *pi_height = videoWidget->videoSize.height();
693 unsigned int i_width = va_arg( args, unsigned int );
694 unsigned int i_height = va_arg( args, unsigned int );
695 emit askVideoToResize( i_width, i_height );
699 case VOUT_SET_STAY_ON_TOP:
701 int i_arg = va_arg( args, int );
702 QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
706 i_ret = VLC_EGENERIC;
707 msg_Warn( p_intf, "unsupported control query" );
713 /*****************************************************************************
714 * Playlist, Visualisation and Menus handling
715 *****************************************************************************/
717 * Toggle the playlist widget or dialog
719 void MainInterface::togglePlaylist()
722 If no playlist exist, then create one and attach it to the DockPL*/
723 if( !playlistWidget )
725 playlistWidget = new PlaylistWidget( p_intf );
727 i_pl_dock = PL_UNDOCKED;
728 /* i_pl_dock = (pl_dock_e)getSettings()
729 ->value( "pl-dock-status", PL_UNDOCKED ).toInt(); */
731 if( i_pl_dock == PL_UNDOCKED )
733 playlistWidget->setWindowFlags( Qt::Window );
735 /* This will restore the geometry but will not work for position,
736 because of parenting */
737 QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
738 playlistWidget, QSize( 600, 300 ) );
742 mainLayout->insertWidget( 4, playlistWidget );
744 playlistVisible = true;
746 playlistWidget->show();
750 /* toggle the visibility of the playlist */
751 TOGGLEV( playlistWidget );
752 playlistVisible = !playlistVisible;
753 //doComponentsUpdate(); //resize( sizeHint() );
757 /* Function called from the menu to undock the playlist */
758 void MainInterface::undockPlaylist()
760 // dockPL->setFloating( true );
764 void MainInterface::dockPlaylist( pl_dock_e i_pos )
768 void MainInterface::toggleMinimalView()
770 /* HACK for minimalView, see menus.cpp */
771 if( !menuBar()->isVisible() ) QVLCMenu::minimalViewAction->toggle();
773 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
774 i_visualmode != QT_MINIMAL_MODE )
775 { /* NORMAL MODE then */
776 if( !videoWidget || videoWidget->isHidden() ) emit askBgWidgetToToggle();
779 /* If video is visible, then toggle the status of bgWidget */
780 bgWasVisible = !bgWasVisible;
784 TOGGLEV( menuBar() );
786 TOGGLEV( statusBar() );
787 doComponentsUpdate();
790 /* Video widget cannot do this synchronously as it runs in another thread */
791 /* Well, could it, actually ? Probably dangerous ... */
793 /* This function is called:
794 - toggling of minimal View
795 - through askUpdate() by Vout thread request video and resize video (zoom)
796 - Advanced buttons toggled
798 void MainInterface::doComponentsUpdate()
800 msg_Dbg( p_intf, "Updating the geometry" );
801 /* Here we resize to sizeHint() and not adjustsize because we want
802 the videoWidget to be exactly the correctSize */
803 resize( sizeHint() );
810 /* toggling advanced controls buttons */
811 void MainInterface::toggleAdvanced()
813 controls->toggleAdvanced();
814 // if( fullscreenControls ) fullscreenControls->toggleAdvanced();
817 /* Get the visibility status of the controls (hidden or not, advanced or not) */
818 int MainInterface::getControlsVisibilityStatus()
820 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
821 + CONTROLS_ADVANCED * controls->b_advancedVisible );
825 void MainInterface::visual()
827 if( !VISIBLE( visualSelector) )
829 visualSelector->show();
830 if( !THEMIM->getIM()->hasVideo() )
832 /* Show the background widget */
834 visualSelectorEnabled = true;
838 /* Stop any currently running visualization */
839 visualSelector->hide();
840 visualSelectorEnabled = false;
842 doComponentsUpdate();
846 /************************************************************************
848 ************************************************************************/
849 void MainInterface::setName( QString name )
851 input_name = name; /* store it for the QSystray use */
852 /* Display it in the status bar, but also as a Tooltip in case it doesn't
854 nameLabel->setText( " " + name + " " );
855 nameLabel->setToolTip( " " + name +" " );
858 void MainInterface::setStatus( int status )
860 msg_Dbg( p_intf, "Updating the stream status: %i", status );
862 speedControl->setEnable( THEMIM->getIM()->hasInput() );
864 /* And in the systray for the menu */
866 QVLCMenu::updateSystrayMenu( this, p_intf );
869 void MainInterface::setRate( int rate )
872 str.setNum( ( 1000 / (double)rate ), 'f', 2 );
874 speedLabel->setText( str );
875 speedLabel->setToolTip( str );
876 speedControl->updateControls( rate );
879 /*****************************************************************************
880 * Systray Icon and Systray Menu
881 *****************************************************************************/
884 * Create a SystemTray icon and a menu that would go with it.
885 * Connects to a click handler on the icon.
887 void MainInterface::createSystray()
890 if( QDate::currentDate().dayOfYear() >= 354 )
891 iconVLC = QIcon( QPixmap( ":/vlc128-christmas.png" ) );
893 iconVLC = QIcon( QPixmap( ":/vlc128.png" ) );
894 sysTray = new QSystemTrayIcon( iconVLC, this );
895 sysTray->setToolTip( qtr( "VLC media player" ));
897 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
898 systrayMenu->setIcon( iconVLC );
900 QVLCMenu::updateSystrayMenu( this, p_intf, true );
903 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
904 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
908 * Updates the Systray Icon's menu and toggle the main interface
910 void MainInterface::toggleUpdateSystrayMenu()
912 /* If hidden, show it */
918 else if( isMinimized() )
928 /* check if any visible window is above vlc in the z-order,
929 * but ignore the ones always on top
930 * and the ones which can't be activated */
933 wi.cbSize = sizeof( WINDOWINFO );
934 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
935 hwnd && ( !IsWindowVisible( hwnd ) ||
936 ( GetWindowInfo( hwnd, &wi ) &&
937 (wi.dwExStyle&WS_EX_NOACTIVATE) ) );
938 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
939 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
940 (wi.dwExStyle&WS_EX_TOPMOST) )
942 if( isActiveWindow() )
952 QVLCMenu::updateSystrayMenu( this, p_intf );
955 void MainInterface::handleSystrayClick(
956 QSystemTrayIcon::ActivationReason reason )
960 case QSystemTrayIcon::Trigger:
961 toggleUpdateSystrayMenu();
963 case QSystemTrayIcon::MiddleClick:
964 sysTray->showMessage( qtr( "VLC media player" ),
965 qtr( "Control menu for the player" ),
966 QSystemTrayIcon::Information, 3000 );
972 * Updates the name of the systray Icon tooltip.
973 * Doesn't check if the systray exists, check before you call it.
975 void MainInterface::updateSystrayTooltipName( QString name )
979 sysTray->setToolTip( qtr( "VLC media player" ) );
983 sysTray->setToolTip( name );
984 if( notificationEnabled && ( isHidden() || isMinimized() ) )
986 sysTray->showMessage( qtr( "VLC media player" ), name,
987 QSystemTrayIcon::NoIcon, 3000 );
993 * Updates the status of the systray Icon tooltip.
994 * Doesn't check if the systray exists, check before you call it.
996 void MainInterface::updateSystrayTooltipStatus( int i_status )
1003 sysTray->setToolTip( qtr( "VLC media player" ) );
1008 sysTray->setToolTip( input_name );
1013 sysTray->setToolTip( input_name + " - "
1020 /************************************************************************
1022 ************************************************************************/
1023 void MainInterface::dropEvent(QDropEvent *event)
1025 dropEventPlay( event, true );
1028 void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
1030 const QMimeData *mimeData = event->mimeData();
1032 /* D&D of a subtitles file, add it on the fly */
1033 if( mimeData->urls().size() == 1 )
1035 if( THEMIM->getIM()->hasInput() )
1037 if( !input_AddSubtitle( THEMIM->getInput(),
1038 qtu( toNativeSeparators(
1039 mimeData->urls()[0].toLocalFile() ) ),
1042 event->acceptProposedAction();
1047 bool first = b_play;
1048 foreach( QUrl url, mimeData->urls() )
1050 QString s = toNativeSeparators( url.toLocalFile() );
1052 if( s.length() > 0 ) {
1053 playlist_Add( THEPL, qtu(s), NULL,
1054 PLAYLIST_APPEND | (first ? PLAYLIST_GO: 0),
1055 PLAYLIST_END, true, false );
1057 RecentsMRL::getInstance( p_intf )->addRecent( s );
1060 event->acceptProposedAction();
1062 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1064 event->acceptProposedAction();
1066 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1068 event->acceptProposedAction();
1070 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1075 /************************************************************************
1077 ************************************************************************/
1078 void MainInterface::customEvent( QEvent *event )
1081 if( event->type() == PLDockEvent_Type )
1083 PlaylistDialog::killInstance();
1084 playlistEmbeddedFlag = true;
1086 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1091 if ( event->type() == (int)SetVideoOnTopEvent_Type )
1093 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1094 if( p_event->OnTop() )
1095 setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
1097 setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint);
1098 show(); /* necessary to apply window flags?? */
1102 void MainInterface::keyPressEvent( QKeyEvent *e )
1104 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() == Qt::Key_H )
1105 && menuBar()->isHidden() )
1107 toggleMinimalView();
1111 int i_vlck = qtEventToVLCKey( e );
1114 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1121 void MainInterface::wheelEvent( QWheelEvent *e )
1123 int i_vlckey = qtWheelEventToVLCKey( e );
1124 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1128 void MainInterface::closeEvent( QCloseEvent *e )
1134 void MainInterface::toggleFullScreen( void )
1136 if( isFullScreen() )
1139 emit askUpdate(); // Needed if video was launched after the F11
1145 /*****************************************************************************
1147 *****************************************************************************/
1148 static int InteractCallback( vlc_object_t *p_this,
1149 const char *psz_var, vlc_value_t old_val,
1150 vlc_value_t new_val, void *param )
1152 intf_dialog_args_t *p_arg = new intf_dialog_args_t;
1153 p_arg->p_dialog = (interaction_dialog_t *)(new_val.p_address);
1154 DialogEvent *event = new DialogEvent( INTF_DIALOG_INTERACTION, 0, p_arg );
1155 QApplication::postEvent( THEDP, static_cast<QEvent*>(event) );
1159 /*****************************************************************************
1160 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1161 * We don't show the menu directly here because we don't want the
1162 * caller to block for a too long time.
1163 *****************************************************************************/
1164 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1165 vlc_value_t old_val, vlc_value_t new_val, void *param )
1167 intf_thread_t *p_intf = (intf_thread_t *)param;
1169 if( p_intf->pf_show_dialog )
1171 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1172 new_val.b_bool, 0 );
1178 /*****************************************************************************
1179 * IntfShowCB: callback triggered by the intf-show libvlc variable.
1180 *****************************************************************************/
1181 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1182 vlc_value_t old_val, vlc_value_t new_val, void *param )
1184 intf_thread_t *p_intf = (intf_thread_t *)param;
1185 p_intf->p_sys->p_mi->toggleFSC();
1191 /*****************************************************************************
1192 * updateRecentsMenu: event called by RecentsMRL
1193 *****************************************************************************/
1195 void MainInterface::updateRecentsMenu()
1197 QVLCMenu::updateRecents( p_intf );