1 /*****************************************************************************
2 * main_interface.cpp : Main interface
3 ****************************************************************************
4 * Copyright (C) 2006-2007 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>
55 #include <QDockWidget>
65 #define SET_WIDTH(i,j) i->widgetSize.setWidth(j)
66 #define SET_HEIGHT(i,j) i->widgetSize.setHeight(j)
67 #define SET_WH( i,j,k) i->widgetSize.setWidth(j); i->widgetSize.setHeight(k);
69 #define DS(i) i.width(),i.height()
71 /* Callback prototypes */
72 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
73 vlc_value_t old_val, vlc_value_t new_val, void *param );
74 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
75 vlc_value_t old_val, vlc_value_t new_val, void *param );
76 static int InteractCallback( vlc_object_t *, const char *, vlc_value_t,
79 MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
81 /* Variables initialisation */
82 // need_components_update = false;
85 playlistWidget = NULL;
87 videoIsActive = false;
88 playlistVisible = false;
90 fullscreenControls = NULL;
96 * Configuration and settings
97 * Pre-building of interface
100 setFocusPolicy( Qt::StrongFocus );
101 setAcceptDrops( true );
102 setWindowIcon( QApplication::windowIcon() );
103 setWindowOpacity( config_GetFloat( p_intf, "qt-opacity" ) );
105 /* Set The Video In emebedded Mode or not */
106 videoEmbeddedFlag = config_GetInt( p_intf, "embedded-video" );
108 /* Are we in the enhanced always-video mode or not ? */
109 i_visualmode = config_GetInt( p_intf, "qt-display-mode" );
111 /* Set the other interface settings */
112 settings = getSettings();
113 settings->beginGroup( "MainWindow" );
115 //TODO: I don't like that code
116 visualSelectorEnabled = settings->value( "visual-selector", false ).toBool();
117 notificationEnabled = (bool)config_GetInt( p_intf, "qt-notification" );
119 /**************************
120 * UI and Widgets design
121 **************************/
122 setVLCWindowsTitle();
123 handleMainUi( settings );
126 /* Create a Dock to get the playlist */
127 dockPL = new QDockWidget( qtr( "Playlist" ), this );
128 dockPL->setSizePolicy( QSizePolicy::Preferred,
129 QSizePolicy::Expanding );
130 dockPL->setFeatures( QDockWidget::AllDockWidgetFeatures );
131 dockPL->setAllowedAreas( Qt::LeftDockWidgetArea
132 | Qt::RightDockWidgetArea
133 | Qt::BottomDockWidgetArea );
140 QVLCMenu::createMenuBar( this, p_intf, visualSelectorEnabled );
142 /* StatusBar Creation */
146 /********************
148 ********************/
149 MainInputManager::getInstance( p_intf );
151 /**************************
152 * Various CONNECTs on IM *
153 **************************/
154 /* Connect the input manager to the GUI elements it manages */
156 /* It is also connected to the control->slider, see the ControlsWidget */
157 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
158 this, setDisplayPosition( float, int, int ) );
159 /* Change the SpeedRate in the Status */
160 CONNECT( THEMIM->getIM(), rateChanged( int ), this, setRate( int ) );
163 * Connects on nameChanged()
164 * Those connects are not merged because different options can trigger
167 /* Naming in the controller statusbar */
168 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
169 setName( QString ) );
170 /* and in the systray */
173 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
174 updateSystrayTooltipName( QString ) );
176 /* and in the title of the controller */
177 if( config_GetInt( p_intf, "qt-name-in-title" ) )
179 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
180 setVLCWindowsTitle( QString ) );
184 * CONNECTS on PLAY_STATUS
186 /* Status on the main controller */
187 CONNECT( THEMIM->getIM(), statusChanged( int ), this, setStatus( int ) );
188 /* and in the systray */
191 CONNECT( THEMIM->getIM(), statusChanged( int ), this,
192 updateSystrayTooltipStatus( int ) );
195 /* END CONNECTS ON IM */
199 /* TODO Remove this function, but so far, there is no choice because there
200 is no intf-should-die variable */
201 ON_TIMEOUT( updateOnTimer() );
202 //ON_TIMEOUT( debug() );
207 var_Create( p_intf, "interaction", VLC_VAR_ADDRESS );
208 var_AddCallback( p_intf, "interaction", InteractCallback, this );
209 p_intf->b_interaction = true;
211 var_AddCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
213 /* Register callback for the intf-popupmenu variable */
214 var_AddCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
216 /* VideoWidget connect mess to avoid different threads speaking to each other */
217 CONNECT( this, askReleaseVideo( void * ),
218 this, releaseVideoSlot( void * ) );
220 CONNECT( this, askVideoToResize( unsigned int, unsigned int ),
221 videoWidget, SetSizing( unsigned int, unsigned int ) );
223 CONNECT( this, askUpdate(), this, doComponentsUpdate() );
225 /* Size and placement of interface */
226 QVLCTools::restoreWidgetPosition( settings, this, QSize(380, 60) );
230 if( settings->value( "playlist-visible", 0 ).toInt() ) togglePlaylist();
231 settings->endGroup();
235 if( i_visualmode == QT_MINIMAL_MODE )
238 /* Update the geometry TODO: is it useful ?*/
241 /*****************************************************
242 * End everything by creating the Systray Management *
243 *****************************************************/
247 MainInterface::~MainInterface()
249 msg_Dbg( p_intf, "Destroying the main interface" );
252 playlistWidget->savingSettings();
254 settings->beginGroup( "MainWindow" );
256 // settings->setValue( "playlist-floats", (int)(dockPL->isFloating()) );
257 settings->setValue( "playlist-visible", (int)playlistVisible );
258 settings->setValue( "adv-controls",
259 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
262 QVLCTools::saveWidgetPosition(settings, this);
265 settings->setValue( "backgroundSize", bgWidget->size() );
267 settings->endGroup();
269 var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
271 /* Unregister callback for the intf-popupmenu variable */
272 var_DelCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
274 p_intf->b_interaction = false;
275 var_DelCallback( p_intf, "interaction", InteractCallback, this );
277 p_intf->p_sys->p_mi = NULL;
280 /*****************************
282 *****************************/
284 inline void MainInterface::createStatusBar()
289 /* Widgets Creation*/
290 b_remainingTime = false;
291 timeLabel = new TimeLabel;
292 timeLabel->setText( " --:--/--:-- " );
293 timeLabel->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
294 timeLabel->setToolTip( qtr( "Toggle between elapsed and remaining time" ) );
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);
309 /* and adding those */
310 statusBar()->addWidget( nameLabel, 8 );
311 statusBar()->addPermanentWidget( speedLabel, 0 );
312 statusBar()->addPermanentWidget( timeLabel, 0 );
314 /* timeLabel behaviour:
315 - double clicking opens the goto time dialog
316 - right-clicking and clicking just toggle between remaining and
318 CONNECT( timeLabel, timeLabelClicked(), this, toggleTimeDisplay() );
319 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
320 CONNECT( timeLabel, timeLabelDoubleClicked(), this, toggleTimeDisplay() );
322 /* Speed Label behaviour:
323 - right click gives the vertical speed slider */
324 CONNECT( speedLabel, customContextMenuRequested( QPoint ),
325 this, showSpeedMenu( QPoint ) );
328 inline void MainInterface::initSystray()
330 bool b_createSystray = false;
331 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
332 if( config_GetInt( p_intf, "qt-start-minimized") )
334 if( b_systrayAvailable )
336 b_createSystray = true;
339 else msg_Err( p_intf, "You can't minimize if you haven't a system "
342 if( config_GetInt( p_intf, "qt-system-tray") )
343 b_createSystray = true;
345 if( b_systrayAvailable && b_createSystray )
350 * Give the decorations of the Main Window a correct Name.
351 * If nothing is given, set it to VLC...
353 void MainInterface::setVLCWindowsTitle( QString aTitle )
355 if( aTitle.isEmpty() )
357 setWindowTitle( qtr( "VLC media player" ) );
361 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
365 void MainInterface::handleMainUi( QSettings *settings )
367 /* Create the main Widget and the mainLayout */
368 QWidget *main = new QWidget;
369 setCentralWidget( main );
370 mainLayout = new QVBoxLayout( main );
372 /* Margins, spacing */
373 main->setContentsMargins( 0, 0, 0, 0 );
374 main->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
375 mainLayout->setSpacing( 0 );
376 mainLayout->setMargin( 0 );
378 /* Create the CONTROLS Widget */
379 bool b_shiny = config_GetInt( p_intf, "qt-blingbling" );
380 controls = new ControlsWidget( p_intf, this,
381 settings->value( "adv-controls", false ).toBool(),
383 CONNECT( controls, advancedControlsToggled( bool ),
384 this, doComponentsUpdate() );
386 /* Create the FULLSCREEN CONTROLS Widget */
387 if( config_GetInt( p_intf, "qt-fs-controller" ) )
389 fullscreenControls = new FullscreenControllerWidget( p_intf, this,
390 settings->value( "adv-controls", false ).toBool(),
392 CONNECT( fullscreenControls, advancedControlsToggled( bool ),
393 this, doComponentsUpdate() );
396 /* Add the controls Widget to the main Widget */
397 mainLayout->insertWidget( 0, controls, 0, Qt::AlignBottom );
399 /* Create the Speed Control Widget */
400 speedControl = new SpeedControlWidget( p_intf );
401 speedControlMenu = new QMenu( this );
403 QWidgetAction *widgetAction = new QWidgetAction( speedControl );
404 widgetAction->setDefaultWidget( speedControl );
405 speedControlMenu->addAction( widgetAction );
408 /* Disabled for now, they SUCK */
410 visualSelector = new VisualSelector( p_intf );
411 mainLayout->insertWidget( 0, visualSelector );
412 visualSelector->hide();
416 bgWidget = new BackgroundWidget( p_intf );
418 settings->value( "backgroundSize", QSize( 300, 200 ) ).toSize() );
419 bgWidget->updateGeometry();
420 mainLayout->insertWidget( 0, bgWidget );
421 CONNECT( this, askBgWidgetToToggle(), bgWidget, toggle() );
423 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
424 i_visualmode != QT_MINIMAL_MODE )
429 /* And video Outputs */
430 if( videoEmbeddedFlag )
432 videoWidget = new VideoWidget( p_intf );
433 mainLayout->insertWidget( 0, videoWidget, 10 );
436 /* Finish the sizing */
437 main->updateGeometry();
440 inline void MainInterface::askForPrivacy()
443 * Ask for the network policy on FIRST STARTUP
445 if( config_GetInt( p_intf, "qt-privacy-ask") )
447 QList<ConfigControl *> controls;
448 if( privacyDialog( &controls ) == QDialog::Accepted )
450 QList<ConfigControl *>::Iterator i;
451 for( i = controls.begin() ; i != controls.end() ; i++ )
453 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
454 c->doApply( p_intf );
457 config_PutInt( p_intf, "qt-privacy-ask" , 0 );
458 /* We have to save here because the user may not launch Prefs */
459 config_SaveConfigFile( p_intf, NULL );
464 int MainInterface::privacyDialog( QList<ConfigControl *> *controls )
466 QDialog *privacy = new QDialog();
468 privacy->setWindowTitle( qtr( "Privacy and Network Policies" ) );
470 QGridLayout *gLayout = new QGridLayout( privacy );
472 QGroupBox *blabla = new QGroupBox( qtr( "Privacy and Network Warning" ) );
473 QGridLayout *blablaLayout = new QGridLayout( blabla );
474 QLabel *text = new QLabel( qtr(
475 "<p>The <i>VideoLAN Team</i> doesn't like when an application goes "
476 "online without authorization.</p>\n "
477 "<p><i>VLC media player</i> can request limited information on "
478 "the Internet, especially to get CD covers or to know "
479 "if updates are available.</p>\n"
480 "<p><i>VLC media player</i> <b>DOES NOT</b> send or collect <b>ANY</b> "
481 "information, even anonymously, about your usage.</p>\n"
482 "<p>Therefore please check the following options, the default being "
483 "almost no access on the web.</p>\n") );
484 text->setWordWrap( true );
485 text->setTextFormat( Qt::RichText );
487 blablaLayout->addWidget( text, 0, 0 ) ;
489 QGroupBox *options = new QGroupBox;
490 QGridLayout *optionsLayout = new QGridLayout( options );
492 gLayout->addWidget( blabla, 0, 0, 1, 3 );
493 gLayout->addWidget( options, 1, 0, 1, 3 );
494 module_config_t *p_config;
495 ConfigControl *control;
498 #define CONFIG_GENERIC( option, type ) \
499 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
502 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
503 p_config, options, false, optionsLayout, line ); \
504 controls->append( control ); \
507 #define CONFIG_GENERIC_NOBOOL( option, type ) \
508 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
511 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
512 p_config, options, optionsLayout, line ); \
513 controls->append( control ); \
516 CONFIG_GENERIC( "album-art", IntegerList ); line++;
518 CONFIG_GENERIC_NOBOOL( "qt-updates-notif", Bool ); line++;
519 CONFIG_GENERIC_NOBOOL( "qt-updates-days", Integer ); line++;
522 QPushButton *ok = new QPushButton( qtr( "OK" ) );
524 gLayout->addWidget( ok, 2, 2 );
526 CONNECT( ok, clicked(), privacy, accept() );
527 return privacy->exec();
531 /**********************************************************************
532 * Handling of sizing of the components
533 **********************************************************************/
535 /* This function is probably wrong, but we don't have many many choices...
536 Since we can't know from the playlist Widget if we are inside a dock or not,
537 because the playlist Widget can be called by THEDP, as a separate windows for
539 Maybe the other solution is to redefine the sizeHint() of the playlist and
540 ask _parent->isFloating()...
541 If you think this would be better, please FIXME it...
544 QSize MainInterface::sizeHint() const
546 int nwidth = controls->sizeHint().width();
547 int nheight = controls->isVisible() ?
548 controls->size().height()
549 + menuBar()->size().height()
550 + statusBar()->size().height()
553 msg_Dbg( p_intf, "1 %i %i", nheight, nwidth );
554 if( VISIBLE( bgWidget ) )
556 nheight += bgWidget->size().height();
557 nwidth = bgWidget->size().width();
558 msg_Dbg( p_intf, "1b %i %i", nheight, nwidth );
560 else if( videoIsActive )
562 nheight += videoWidget->size().height();
563 nwidth = videoWidget->size().width();
564 msg_Dbg( p_intf, "2 %i %i", nheight, nwidth );
566 /* if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget() )
568 nheight += dockPL->size().height();
569 nwidth = __MAX( nwidth, dockPL->size().width() );
570 msg_Dbg( p_intf, "3 %i %i", nheight, nwidth );
572 msg_Dbg( p_intf, "4 %i %i", nheight, nwidth );
573 return QSize( nwidth, nheight );
577 /* FIXME This is dead code and need to be removed AT THE END */
578 void MainInterface::resizeEvent( QResizeEvent *e )
581 videoWidget->widgetSize.setWidth( e->size().width() - addSize.width() );
582 if( videoWidget && videoIsActive && videoWidget->widgetSize.height() > 1 )
584 SET_WH( videoWidget, e->size().width() - addSize.width(),
585 e->size().height() - addSize.height() );
586 videoWidget->updateGeometry();
588 if( VISIBLE( playlistWidget ) )
590 // SET_WH( playlistWidget , e->size().width() - addSize.width(),
591 // e->size().height() - addSize.height() );
592 playlistWidget->updateGeometry();
597 void MainInterface::toggleFSC()
599 if( !fullscreenControls ) return;
601 IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
602 QApplication::postEvent( fullscreenControls, static_cast<QEvent *>(eShow) );
605 void MainInterface::requestLayoutUpdate()
611 //FIXME remove me at the end...
612 void MainInterface::debug()
614 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
615 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
616 if( videoWidget && videoWidget->isVisible() )
619 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
620 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
625 /****************************************************************************
626 * Small right-click menu for rate control
627 ****************************************************************************/
628 void MainInterface::showSpeedMenu( QPoint pos )
630 speedControlMenu->exec( QCursor::pos() - pos
631 + QPoint( 0, speedLabel->height() ) );
634 /****************************************************************************
636 ****************************************************************************/
637 class SetVideoOnTopQtEvent : public QEvent
640 SetVideoOnTopQtEvent( bool _onTop ) :
641 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
656 * Thou shall not call/resize/hide widgets from on another thread.
657 * This is wrong, and this is TEH reason to emit signals on those Video Functions
659 void *MainInterface::requestVideo( vout_thread_t *p_nvout, int *pi_x,
660 int *pi_y, unsigned int *pi_width,
661 unsigned int *pi_height )
663 bgWasVisible = false;
665 /* Request the videoWidget */
666 void *ret = videoWidget->request( p_nvout,pi_x, pi_y, pi_width, pi_height );
667 if( ret ) /* The videoWidget is available */
669 /* Did we have a bg ? Hide it! */
670 if( VISIBLE( bgWidget) )
673 emit askBgWidgetToToggle();
676 if( THEMIM->getIM()->hasVideo() || !bgWasVisible )
678 videoWidget->widgetSize = QSize( *pi_width, *pi_height );
680 else /* Background widget available, use its size */
682 /* Ok, our visualizations are bad, so don't do this for the moment
683 * use the requested size anyway */
684 // videoWidget->widgetSize = bgWidget->widgeTSize;
685 videoWidget->widgetSize = QSize( *pi_width, *pi_height );
688 videoIsActive = true;
690 // emit askVideoToResize( *pi_width, *pi_height );
693 if( fullscreenControls ) fullscreenControls->attachVout( p_nvout );
698 void MainInterface::releaseVideo( void *p_win )
700 if( fullscreenControls ) fullscreenControls->detachVout();
702 emit askReleaseVideo( p_win );
705 void MainInterface::releaseVideoSlot( void *p_win )
707 videoWidget->release( p_win );
712 bgWasVisible = false;
716 videoIsActive = false;
717 if( !isFullScreen() ) adjustSize();
720 int MainInterface::controlVideo( void *p_window, int i_query, va_list args )
722 int i_ret = VLC_SUCCESS;
727 unsigned int *pi_width = va_arg( args, unsigned int * );
728 unsigned int *pi_height = va_arg( args, unsigned int * );
729 *pi_width = videoWidget->videoSize.width();
730 *pi_height = videoWidget->videoSize.height();
735 unsigned int i_width = va_arg( args, unsigned int );
736 unsigned int i_height = va_arg( args, unsigned int );
737 emit askVideoToResize( i_width, i_height );
741 case VOUT_SET_STAY_ON_TOP:
743 int i_arg = va_arg( args, int );
744 QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
748 i_ret = VLC_EGENERIC;
749 msg_Warn( p_intf, "unsupported control query" );
755 /*****************************************************************************
756 * Playlist, Visualisation and Menus handling
757 *****************************************************************************/
759 * Toggle the playlist widget or dialog
761 void MainInterface::togglePlaylist()
763 THEDP->playlistDialog();
766 If no playlist exist, then create one and attach it to the DockPL*/
767 if( !playlistWidget )
769 playlistWidget = new PlaylistWidget( p_intf, settings, dockPL );
771 /* Add it to the parent DockWidget */
772 dockPL->setWidget( playlistWidget );
774 /* Add the dock to the main Interface */
775 addDockWidget( Qt::BottomDockWidgetArea, dockPL );
777 /* Make the playlist floating is requested. Default is not. */
778 settings->beginGroup( "MainWindow" );
779 if( settings->value( "playlist-floats", 1 ).toInt() )
781 msg_Dbg( p_intf, "we don't want the playlist inside");
782 dockPL->setFloating( true );
784 settings->endGroup();
785 settings->beginGroup( "playlist" );
786 dockPL->move( settings->value( "pos", QPoint( 0,0 ) ).toPoint() );
787 QSize newSize = settings->value( "size", QSize( 400, 300 ) ).toSize();
788 if( newSize.isValid() )
789 dockPL->resize( newSize );
790 settings->endGroup();
793 playlistVisible = true;
797 /* toggle the visibility of the playlist */
799 resize( sizeHint() );
800 playlistVisible = !playlistVisible;
805 /* Function called from the menu to undock the playlist */
806 void MainInterface::undockPlaylist()
808 // dockPL->setFloating( true );
812 void MainInterface::toggleMinimalView()
814 /* HACK for minimalView, see menus.cpp */
815 if( !menuBar()->isVisible() ) QVLCMenu::minimalViewAction->toggle();
817 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
818 i_visualmode != QT_MINIMAL_MODE )
819 { /* NORMAL MODE then */
820 if( videoWidget->isHidden() ) emit askBgWidgetToToggle();
823 /* If video is visible, then toggle the status of bgWidget */
824 bgWasVisible = !bgWasVisible;
828 TOGGLEV( menuBar() );
830 TOGGLEV( statusBar() );
831 doComponentsUpdate();
834 /* Video widget cannot do this synchronously as it runs in another thread */
835 /* Well, could it, actually ? Probably dangerous ... */
836 void MainInterface::doComponentsUpdate()
838 msg_Dbg( p_intf, "Updating the geometry" );
839 // resize( sizeHint() );
843 /* toggling advanced controls buttons */
844 void MainInterface::toggleAdvanced()
846 controls->toggleAdvanced();
847 if( fullscreenControls ) fullscreenControls->toggleAdvanced();
850 /* Get the visibility status of the controls (hidden or not, advanced or not) */
851 int MainInterface::getControlsVisibilityStatus()
853 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
854 + CONTROLS_ADVANCED * controls->b_advancedVisible );
858 void MainInterface::visual()
860 if( !VISIBLE( visualSelector) )
862 visualSelector->show();
863 if( !THEMIM->getIM()->hasVideo() )
865 /* Show the background widget */
867 visualSelectorEnabled = true;
871 /* Stop any currently running visualization */
872 visualSelector->hide();
873 visualSelectorEnabled = false;
875 doComponentsUpdate();
879 /************************************************************************
881 ************************************************************************/
882 void MainInterface::setDisplayPosition( float pos, int time, int length )
884 char psz_length[MSTRTIME_MAX_SIZE], psz_time[MSTRTIME_MAX_SIZE];
885 secstotimestr( psz_length, length );
886 secstotimestr( psz_time, ( b_remainingTime && length ) ? length - time
890 timestr.sprintf( "%s/%s", psz_time,
891 ( !length && time ) ? "--:--" : psz_length );
893 /* Add a minus to remaining time*/
894 if( b_remainingTime && length ) timeLabel->setText( " -"+timestr+" " );
895 else timeLabel->setText( " "+timestr+" " );
898 void MainInterface::toggleTimeDisplay()
900 b_remainingTime = !b_remainingTime;
903 void MainInterface::setName( QString name )
905 input_name = name; /* store it for the QSystray use */
906 /* Display it in the status bar, but also as a Tooltip in case it doesn't
908 nameLabel->setText( " " + name + " " );
909 nameLabel->setToolTip( " " + name +" " );
912 void MainInterface::setStatus( int status )
914 msg_Dbg( p_intf, "Updating the stream status: %i", status );
916 /* Forward the status to the controls to toggle Play/Pause */
917 controls->setStatus( status );
918 controls->updateInput();
920 if( fullscreenControls )
922 fullscreenControls->setStatus( status );
923 fullscreenControls->updateInput();
926 speedControl->setEnable( THEMIM->getIM()->hasInput() );
928 /* And in the systray for the menu */
930 QVLCMenu::updateSystrayMenu( this, p_intf );
933 void MainInterface::setRate( int rate )
936 str.setNum( ( 1000 / (double)rate ), 'f', 2 );
938 speedLabel->setText( str );
939 speedLabel->setToolTip( str );
940 speedControl->updateControls( rate );
943 void MainInterface::updateOnTimer()
945 /* No event for dying */
946 if( intf_ShouldDie( p_intf ) )
948 QApplication::closeAllWindows();
949 QApplication::quit();
953 /*****************************************************************************
954 * Systray Icon and Systray Menu
955 *****************************************************************************/
958 * Create a SystemTray icon and a menu that would go with it.
959 * Connects to a click handler on the icon.
961 void MainInterface::createSystray()
964 if( QDate::currentDate().dayOfYear() >= 354 )
965 iconVLC = QIcon( QPixmap( ":/vlc128-christmas.png" ) );
967 iconVLC = QIcon( QPixmap( ":/vlc128.png" ) );
968 sysTray = new QSystemTrayIcon( iconVLC, this );
969 sysTray->setToolTip( qtr( "VLC media player" ));
971 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
972 systrayMenu->setIcon( iconVLC );
974 QVLCMenu::updateSystrayMenu( this, p_intf, true );
977 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
978 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
982 * Updates the Systray Icon's menu and toggle the main interface
984 void MainInterface::toggleUpdateSystrayMenu()
986 /* If hidden, show it */
992 else if( isMinimized() )
1002 /* check if any visible window is above vlc in the z-order,
1003 * but ignore the ones always on top */
1006 wi.cbSize = sizeof( WINDOWINFO );
1007 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
1008 hwnd && !IsWindowVisible( hwnd );
1009 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
1010 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
1011 (wi.dwExStyle&WS_EX_TOPMOST) )
1013 if( isActiveWindow() )
1023 QVLCMenu::updateSystrayMenu( this, p_intf );
1026 void MainInterface::handleSystrayClick(
1027 QSystemTrayIcon::ActivationReason reason )
1031 case QSystemTrayIcon::Trigger:
1032 toggleUpdateSystrayMenu();
1034 case QSystemTrayIcon::MiddleClick:
1035 sysTray->showMessage( qtr( "VLC media player" ),
1036 qtr( "Control menu for the player" ),
1037 QSystemTrayIcon::Information, 3000 );
1043 * Updates the name of the systray Icon tooltip.
1044 * Doesn't check if the systray exists, check before you call it.
1046 void MainInterface::updateSystrayTooltipName( QString name )
1048 if( name.isEmpty() )
1050 sysTray->setToolTip( qtr( "VLC media player" ) );
1054 sysTray->setToolTip( name );
1055 if( notificationEnabled && ( isHidden() || isMinimized() ) )
1057 sysTray->showMessage( qtr( "VLC media player" ), name,
1058 QSystemTrayIcon::NoIcon, 3000 );
1064 * Updates the status of the systray Icon tooltip.
1065 * Doesn't check if the systray exists, check before you call it.
1067 void MainInterface::updateSystrayTooltipStatus( int i_status )
1074 sysTray->setToolTip( qtr( "VLC media player" ) );
1079 sysTray->setToolTip( input_name );
1084 sysTray->setToolTip( input_name + " - "
1091 /************************************************************************
1093 ************************************************************************/
1094 void MainInterface::dropEvent(QDropEvent *event)
1096 const QMimeData *mimeData = event->mimeData();
1098 /* D&D of a subtitles file, add it on the fly */
1099 if( mimeData->urls().size() == 1 )
1101 if( THEMIM->getIM()->hasInput() )
1103 if( input_AddSubtitles( THEMIM->getInput(),
1104 qtu( mimeData->urls()[0].toString() ),
1107 event->acceptProposedAction();
1113 foreach( QUrl url, mimeData->urls() )
1115 QString s = url.toLocalFile();
1116 if( s.length() > 0 ) {
1117 playlist_Add( THEPL, qtu(s), NULL,
1118 PLAYLIST_APPEND | (first ? PLAYLIST_GO:0),
1119 PLAYLIST_END, true, false );
1123 event->acceptProposedAction();
1125 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1127 event->acceptProposedAction();
1129 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1131 event->acceptProposedAction();
1133 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1138 /************************************************************************
1140 ************************************************************************/
1141 void MainInterface::customEvent( QEvent *event )
1144 if( event->type() == PLDockEvent_Type )
1146 PlaylistDialog::killInstance();
1147 playlistEmbeddedFlag = true;
1149 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1154 if ( event->type() == SetVideoOnTopEvent_Type )
1156 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1157 if( p_event->OnTop() )
1158 setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
1160 setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint);
1161 show(); /* necessary to apply window flags?? */
1165 void MainInterface::keyPressEvent( QKeyEvent *e )
1167 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() & Qt::Key_H )
1168 && menuBar()->isHidden() )
1170 toggleMinimalView();
1174 int i_vlck = qtEventToVLCKey( e );
1177 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1184 void MainInterface::wheelEvent( QWheelEvent *e )
1186 int i_vlckey = qtWheelEventToVLCKey( e );
1187 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1191 void MainInterface::closeEvent( QCloseEvent *e )
1197 void MainInterface::toggleFullScreen( void )
1199 if( isFullScreen() )
1205 /*****************************************************************************
1207 *****************************************************************************/
1208 static int InteractCallback( vlc_object_t *p_this,
1209 const char *psz_var, vlc_value_t old_val,
1210 vlc_value_t new_val, void *param )
1212 intf_dialog_args_t *p_arg = new intf_dialog_args_t;
1213 p_arg->p_dialog = (interaction_dialog_t *)(new_val.p_address);
1214 DialogEvent *event = new DialogEvent( INTF_DIALOG_INTERACTION, 0, p_arg );
1215 QApplication::postEvent( THEDP, static_cast<QEvent*>(event) );
1219 /*****************************************************************************
1220 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1221 * We don't show the menu directly here because we don't want the
1222 * caller to block for a too long time.
1223 *****************************************************************************/
1224 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1225 vlc_value_t old_val, vlc_value_t new_val, void *param )
1227 intf_thread_t *p_intf = (intf_thread_t *)param;
1229 if( p_intf->pf_show_dialog )
1231 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1232 new_val.b_bool, 0 );
1238 /*****************************************************************************
1239 * IntfShowCB: callback triggered by the intf-show libvlc variable.
1240 *****************************************************************************/
1241 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1242 vlc_value_t old_val, vlc_value_t new_val, void *param )
1244 intf_thread_t *p_intf = (intf_thread_t *)param;
1245 p_intf->p_sys->p_mi->toggleFSC();