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>
60 #include <QProgressBar>
66 #define SET_WIDTH(i,j) i->widgetSize.setWidth(j)
67 #define SET_HEIGHT(i,j) i->widgetSize.setHeight(j)
68 #define SET_WH( i,j,k) i->widgetSize.setWidth(j); i->widgetSize.setHeight(k);
70 #define DS(i) i.width(),i.height()
72 /* Callback prototypes */
73 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
74 vlc_value_t old_val, vlc_value_t new_val, void *param );
75 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
76 vlc_value_t old_val, vlc_value_t new_val, void *param );
77 static int InteractCallback( vlc_object_t *, const char *, vlc_value_t,
80 static void *DoRequest( intf_thread_t *p_intf, vout_thread_t *p_vout,
81 int *pi1, int *pi2, unsigned int*pi3,unsigned int*pi4)
83 return p_intf->p_sys->p_mi->requestVideo( p_vout, pi1, pi2, pi3, pi4 );
86 static void *DoNotEmbeddedRequest( intf_thread_t *p_intf, vout_thread_t *p_vout,
87 int *pi1, int *pi2, unsigned int*pi3,unsigned int*pi4)
89 p_intf->p_sys->p_mi->requestNotEmbeddedVideo( p_vout );
93 static void DoRelease( intf_thread_t *p_intf, void *p_win )
95 return p_intf->p_sys->p_mi->releaseVideo( p_win );
98 static int DoControl( intf_thread_t *p_intf, void *p_win, int i_q, va_list a )
100 return p_intf->p_sys->p_mi->controlVideo( p_win, i_q, a );
103 MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
105 /* Variables initialisation */
106 // need_components_update = false;
109 playlistWidget = NULL;
111 videoIsActive = false;
112 playlistVisible = false;
115 /* Ask for privacy */
119 * Configuration and settings
120 * Pre-building of interface
123 setFocusPolicy( Qt::StrongFocus );
124 setAcceptDrops( true );
125 setWindowIcon( QApplication::windowIcon() );
126 setWindowOpacity( config_GetFloat( p_intf, "qt-opacity" ) );
128 /* Set The Video In emebedded Mode or not */
129 videoEmbeddedFlag = config_GetInt( p_intf, "embedded-video" );
131 /* Are we in the enhanced always-video mode or not ? */
132 i_visualmode = config_GetInt( p_intf, "qt-display-mode" );
134 /* Set the other interface settings */
135 settings = new QSettings( "vlc", "vlc-qt-interface" );
136 settings->beginGroup( "MainWindow" );
138 //TODO: I don't like that code
139 visualSelectorEnabled = settings->value( "visual-selector", false ).toBool();
140 notificationEnabled = (bool)config_GetInt( p_intf, "qt-notification" );
142 /**************************
143 * UI and Widgets design
144 **************************/
145 setVLCWindowsTitle();
146 handleMainUi( settings );
149 /* Create a Dock to get the playlist */
150 dockPL = new QDockWidget( qtr( "Playlist" ), this );
151 dockPL->setSizePolicy( QSizePolicy::Preferred,
152 QSizePolicy::Expanding );
153 dockPL->setFeatures( QDockWidget::AllDockWidgetFeatures );
154 dockPL->setAllowedAreas( Qt::LeftDockWidgetArea
155 | Qt::RightDockWidgetArea
156 | Qt::BottomDockWidgetArea );
163 QVLCMenu::createMenuBar( this, p_intf, visualSelectorEnabled );
165 /* StatusBar Creation */
169 /********************
171 ********************/
172 MainInputManager::getInstance( p_intf );
174 /**************************
175 * Various CONNECTs on IM *
176 **************************/
177 /* Connect the input manager to the GUI elements it manages */
179 /* It is also connected to the control->slider, see the ControlsWidget */
180 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
181 this, setDisplayPosition( float, int, int ) );
182 /* Change the SpeedRate in the Status */
183 CONNECT( THEMIM->getIM(), rateChanged( int ), this, setRate( int ) );
186 * Connects on nameChanged()
187 * Those connects are not merged because different options can trigger
190 /* Naming in the controller statusbar */
191 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
192 setName( QString ) );
193 /* and in the systray */
196 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
197 updateSystrayTooltipName( QString ) );
199 /* and in the title of the controller */
200 if( config_GetInt( p_intf, "qt-name-in-title" ) )
202 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
203 setVLCWindowsTitle( QString ) );
207 * CONNECTS on PLAY_STATUS
209 /* Status on the main controller */
210 CONNECT( THEMIM->getIM(), statusChanged( int ), this, setStatus( int ) );
211 /* and in the systray */
214 CONNECT( THEMIM->getIM(), statusChanged( int ), this,
215 updateSystrayTooltipStatus( int ) );
218 /* END CONNECTS ON IM */
222 /* TODO Remove this function, but so far, there is no choice because there
223 is no intf-should-die variable */
224 ON_TIMEOUT( updateOnTimer() );
225 //ON_TIMEOUT( debug() );
230 var_Create( p_intf, "interaction", VLC_VAR_ADDRESS );
231 var_AddCallback( p_intf, "interaction", InteractCallback, this );
232 p_intf->b_interaction = true;
234 var_AddCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
236 /* Register callback for the intf-popupmenu variable */
237 playlist_t *p_playlist = pl_Yield( p_intf );
238 var_AddCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
239 pl_Release( p_intf );
241 /* VideoWidget connect mess to avoid different threads speaking to each other */
242 CONNECT( this, askReleaseVideo( void * ),
243 this, releaseVideoSlot( void * ) );
244 CONNECT( this, askVideoToResize( unsigned int, unsigned int ),
245 videoWidget, SetSizing( unsigned int, unsigned int ) );
247 CONNECT( this, askUpdate(), this, doComponentsUpdate() );
249 CONNECT( controls, advancedControlsToggled( bool ),
250 this, doComponentsUpdate() );
252 CONNECT( fullscreenControls, advancedControlsToggled( bool ),
253 this, doComponentsUpdate() );
255 CONNECT( THEMIM->getIM(), inputUnset(),
256 fullscreenControls, unregFullscreenCallback() );
259 /* Size and placement of interface */
260 QVLCTools::restoreWidgetPosition(settings,this,QSize(350,60));
264 if( settings->value( "playlist-visible", 0 ).toInt() ) togglePlaylist();
265 settings->endGroup();
269 if( i_visualmode == QT_MINIMAL_MODE )
272 /* Update the geometry TODO: is it useful ?*/
275 /*****************************************************
276 * End everything by creating the Systray Management *
277 *****************************************************/
281 MainInterface::~MainInterface()
283 msg_Dbg( p_intf, "Destroying the main interface" );
286 playlistWidget->savingSettings( settings );
288 settings->beginGroup( "MainWindow" );
290 // settings->setValue( "playlist-floats", (int)(dockPL->isFloating()) );
291 settings->setValue( "playlist-visible", (int)playlistVisible );
292 settings->setValue( "adv-controls",
293 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
296 QVLCTools::saveWidgetPosition(settings, this);
299 settings->setValue( "backgroundSize", bgWidget->size() );
301 settings->endGroup();
304 var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
306 /* Unregister callback for the intf-popupmenu variable */
307 playlist_t *p_playlist = pl_Yield( p_intf );
308 var_DelCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
309 pl_Release( p_intf );
311 p_intf->b_interaction = false;
312 var_DelCallback( p_intf, "interaction", InteractCallback, this );
314 p_intf->pf_request_window = NULL;
315 p_intf->pf_release_window = NULL;
316 p_intf->pf_control_window = NULL;
317 p_intf->p_sys->p_mi = NULL;
320 /*****************************
322 *****************************/
324 inline void MainInterface::createStatusBar()
329 /* Widgets Creation*/
330 b_remainingTime = false;
331 timeLabel = new TimeLabel;
332 timeLabel->setText( " --:--/--:-- " );
333 timeLabel->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
334 nameLabel = new QLabel;
335 nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
336 | Qt::TextSelectableByKeyboard );
337 speedLabel = new SpeedLabel( p_intf, "1.00x" );
338 speedLabel->setContextMenuPolicy ( Qt::CustomContextMenu );
340 /* Styling those labels */
341 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
342 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
343 nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
345 pgBar = new QProgressBar;
348 /* and adding those */
349 statusBar()->addWidget( nameLabel, 8 );
350 statusBar()->addPermanentWidget( speedLabel, 0 );
351 statusBar()->addPermanentWidget( pgBar, 0 );
352 statusBar()->addPermanentWidget( timeLabel, 0 );
354 /* timeLabel behaviour:
355 - double clicking opens the goto time dialog
356 - right-clicking and clicking just toggle between remaining and
358 CONNECT( timeLabel, timeLabelClicked(), this, toggleTimeDisplay() );
359 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
360 CONNECT( timeLabel, timeLabelDoubleClicked(), this, toggleTimeDisplay() );
362 /* Speed Label behaviour:
363 - right click gives the vertical speed slider */
364 CONNECT( speedLabel, customContextMenuRequested( QPoint ),
365 this, showSpeedMenu( QPoint ) );
368 inline void MainInterface::initSystray()
370 bool b_createSystray = false;
371 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
372 if( config_GetInt( p_intf, "qt-start-minimized") )
374 if( b_systrayAvailable )
376 b_createSystray = true;
379 else msg_Err( p_intf, "You can't minimize if you haven't a system "
382 if( config_GetInt( p_intf, "qt-system-tray") )
383 b_createSystray = true;
385 if( b_systrayAvailable && b_createSystray )
390 * Give the decorations of the Main Window a correct Name.
391 * If nothing is given, set it to VLC...
393 void MainInterface::setVLCWindowsTitle( QString aTitle )
395 if( aTitle.isEmpty() )
397 setWindowTitle( qtr( "VLC media player" ) );
401 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
405 void MainInterface::handleMainUi( QSettings *settings )
407 /* Create the main Widget and the mainLayout */
408 QWidget *main = new QWidget;
409 setCentralWidget( main );
410 mainLayout = new QVBoxLayout( main );
412 /* Margins, spacing */
413 main->setContentsMargins( 0, 0, 0, 0 );
414 main->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
415 mainLayout->setMargin( 0 );
417 /* Create the CONTROLS Widget */
418 /* bool b_shiny = config_GetInt( p_intf, "qt-blingbling" ); */
419 controls = new ControlsWidget( p_intf, this,
420 settings->value( "adv-controls", false ).toBool(),
421 config_GetInt( p_intf, "qt-blingbling" ) );
423 /* Create the FULLSCREEN CONTROLS Widget */
424 /* bool b_shiny = config_GetInt( p_intf, "qt-blingbling" ); */
425 fullscreenControls = new FullscreenControllerWidget( p_intf, this,
426 settings->value( "adv-controls", false ).toBool(),
427 config_GetInt( p_intf, "qt-blingbling" ) );
429 /* Add the controls Widget to the main Widget */
430 mainLayout->insertWidget( 0, controls, 0, Qt::AlignBottom );
432 /* Create the Speed Control Widget */
433 speedControl = new SpeedControlWidget( p_intf );
434 speedControlMenu = new QMenu( this );
436 QWidgetAction *widgetAction = new QWidgetAction( speedControl );
437 widgetAction->setDefaultWidget( speedControl );
438 speedControlMenu->addAction( widgetAction );
441 /* Disabled for now, they SUCK */
443 visualSelector = new VisualSelector( p_intf );
444 mainLayout->insertWidget( 0, visualSelector );
445 visualSelector->hide();
448 /* And video Outputs */
449 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
450 i_visualmode == QT_MINIMAL_MODE )
452 bgWidget = new BackgroundWidget( p_intf );
454 settings->value( "backgroundSize", QSize( 300, 150 ) ).toSize() );
455 bgWidget->updateGeometry();
456 mainLayout->insertWidget( 0, bgWidget );
457 CONNECT( this, askBgWidgetToToggle(), bgWidget, toggle() );
460 if( videoEmbeddedFlag )
462 videoWidget = new VideoWidget( p_intf );
463 mainLayout->insertWidget( 0, videoWidget );
465 p_intf->pf_request_window = ::DoRequest;
466 p_intf->pf_release_window = ::DoRelease;
467 p_intf->pf_control_window = ::DoControl;
471 p_intf->pf_request_window = ::DoNotEmbeddedRequest;
474 /* Finish the sizing */
475 main->updateGeometry();
478 inline void MainInterface::askForPrivacy()
481 * Ask for the network policy on FIRST STARTUP
483 if( config_GetInt( p_intf, "qt-privacy-ask") )
485 QList<ConfigControl *> controls;
486 if( privacyDialog( controls ) == QDialog::Accepted )
488 QList<ConfigControl *>::Iterator i;
489 for( i = controls.begin() ; i != controls.end() ; i++ )
491 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
492 c->doApply( p_intf );
495 config_PutInt( p_intf, "qt-privacy-ask" , 0 );
496 /* We have to save here because the user may not launch Prefs */
497 config_SaveConfigFile( p_intf, NULL );
502 int MainInterface::privacyDialog( QList<ConfigControl *> controls )
504 QDialog *privacy = new QDialog();
506 privacy->setWindowTitle( qtr( "Privacy and Network policies" ) );
508 QGridLayout *gLayout = new QGridLayout( privacy );
510 QGroupBox *blabla = new QGroupBox( qtr( "Privacy and Network Warning" ) );
511 QGridLayout *blablaLayout = new QGridLayout( blabla );
512 QLabel *text = new QLabel( qtr(
513 "<p>The <i>VideoLAN Team</i> doesn't like when an application goes "
514 "online without authorization.</p>\n "
515 "<p><i>VLC media player</i> can request limited information on "
516 "the Internet, especially to get CD covers and songs metadata or to know "
517 "if updates are available.</p>\n"
518 "<p><i>VLC media player</i> <b>DOES NOT</b> send or collect <b>ANY</b> "
519 "information, even anonymously, about your usage.</p>\n"
520 "<p>Therefore please check the following options, the default being "
521 "almost no access on the web.</p>\n") );
522 text->setWordWrap( true );
523 text->setTextFormat( Qt::RichText );
525 blablaLayout->addWidget( text, 0, 0 ) ;
527 QGroupBox *options = new QGroupBox;
528 QGridLayout *optionsLayout = new QGridLayout( options );
530 gLayout->addWidget( blabla, 0, 0, 1, 3 );
531 gLayout->addWidget( options, 1, 0, 1, 3 );
532 module_config_t *p_config;
533 ConfigControl *control;
536 #define CONFIG_GENERIC( option, type ) \
537 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
540 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
541 p_config, options, false, optionsLayout, line ); \
542 controls.append( control ); \
545 #define CONFIG_GENERIC_NOBOOL( option, type ) \
546 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
549 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
550 p_config, options, optionsLayout, line ); \
551 controls.append( control ); \
554 CONFIG_GENERIC( "album-art", IntegerList ); line++;
555 CONFIG_GENERIC_NOBOOL( "fetch-meta", Bool ); line++;
557 CONFIG_GENERIC_NOBOOL( "qt-updates-notif", Bool ); line++;
558 CONFIG_GENERIC_NOBOOL( "qt-updates-days", Integer ); line++;
561 QPushButton *ok = new QPushButton( qtr( "Ok" ) );
563 gLayout->addWidget( ok, 2, 2 );
565 CONNECT( ok, clicked(), privacy, accept() );
566 return privacy->exec();
570 /**********************************************************************
571 * Handling of sizing of the components
572 **********************************************************************/
574 /* This function is probably wrong, but we don't have many many choices...
575 Since we can't know from the playlist Widget if we are inside a dock or not,
576 because the playlist Widget can be called by THEDP, as a separate windows for
578 Maybe the other solution is to redefine the sizeHint() of the playlist and
579 ask _parent->isFloating()...
580 If you think this would be better, please FIXME it...
583 QSize MainInterface::sizeHint() const
585 int nwidth = controls->sizeHint().width();
586 int nheight = controls->isVisible() ?
587 controls->size().height()
588 + menuBar()->size().height()
589 + statusBar()->size().height()
592 msg_Dbg( p_intf, "1 %i %i", nheight, nwidth );
593 if( VISIBLE( bgWidget ) )
595 nheight += bgWidget->size().height();
596 nwidth = bgWidget->size().width();
597 msg_Dbg( p_intf, "1b %i %i", nheight, nwidth );
599 else if( videoIsActive )
601 nheight += videoWidget->size().height();
602 nwidth = videoWidget->size().width();
603 msg_Dbg( p_intf, "2 %i %i", nheight, nwidth );
605 /* if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget() )
607 nheight += dockPL->size().height();
608 nwidth = __MAX( nwidth, dockPL->size().width() );
609 msg_Dbg( p_intf, "3 %i %i", nheight, nwidth );
611 msg_Dbg( p_intf, "4 %i %i", nheight, nwidth );
612 return QSize( nwidth, nheight );
616 /* FIXME This is dead code and need to be removed AT THE END */
617 void MainInterface::resizeEvent( QResizeEvent *e )
620 videoWidget->widgetSize.setWidth( e->size().width() - addSize.width() );
621 if( videoWidget && videoIsActive && videoWidget->widgetSize.height() > 1 )
623 SET_WH( videoWidget, e->size().width() - addSize.width(),
624 e->size().height() - addSize.height() );
625 videoWidget->updateGeometry();
627 if( VISIBLE( playlistWidget ) )
629 // SET_WH( playlistWidget , e->size().width() - addSize.width(),
630 // e->size().height() - addSize.height() );
631 playlistWidget->updateGeometry();
636 void MainInterface::requestLayoutUpdate()
641 //FIXME remove me at the end...
642 void MainInterface::debug()
644 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
645 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
646 if( videoWidget && videoWidget->isVisible() )
649 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
650 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
655 /****************************************************************************
656 * Small right-click menu for rate control
657 ****************************************************************************/
658 void MainInterface::showSpeedMenu( QPoint pos )
660 speedControlMenu->exec( QCursor::pos() - pos
661 + QPoint( 0, speedLabel->height() ) );
664 /****************************************************************************
666 ****************************************************************************/
667 class SetVideoOnTopQtEvent : public QEvent
670 SetVideoOnTopQtEvent( bool _onTop ) :
671 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
686 * Thou shall not call/resize/hide widgets from on another thread.
687 * This is wrong, and this is TEH reason to emit signals on those Video Functions
689 /* function called from ::DoRequest in order to show a nice VideoWidget
691 void *MainInterface::requestVideo( vout_thread_t *p_nvout, int *pi_x,
692 int *pi_y, unsigned int *pi_width,
693 unsigned int *pi_height )
695 bool bgWasVisible = false;
697 /* Request the videoWidget */
698 void *ret = videoWidget->request( p_nvout,pi_x, pi_y, pi_width, pi_height );
699 if( ret ) /* The videoWidget is available */
701 /* Did we have a bg ? Hide it! */
702 if( VISIBLE( bgWidget) )
705 emit askBgWidgetToToggle();
708 /*if( THEMIM->getIM()->hasVideo() || !bgWasVisible )
710 videoWidget->widgetSize = QSize( *pi_width, *pi_height );
712 else /* Background widget available, use its size */
714 /* Ok, our visualizations are bad, so don't do this for the moment
715 * use the requested size anyway */
716 // videoWidget->widgetSize = bgWidget->widgeTSize;
717 /* videoWidget->widgetSize = QSize( *pi_width, *pi_height );
720 videoIsActive = true;
722 emit askVideoToResize( *pi_width, *pi_height );
725 fullscreenControls->regFullscreenCallback( p_nvout );
730 /* function called from ::DoRequest in order to show a nice VideoWidget
732 void MainInterface::requestNotEmbeddedVideo( vout_thread_t *p_nvout )
734 fullscreenControls->regFullscreenCallback( p_nvout );
737 void MainInterface::releaseVideo( void *p_win )
739 emit askReleaseVideo( p_win );
742 void MainInterface::releaseVideoSlot( void *p_win )
744 videoWidget->release( p_win );
747 if( bgWidget )// WORONG
751 videoIsActive = false;
754 int MainInterface::controlVideo( void *p_window, int i_query, va_list args )
756 int i_ret = VLC_SUCCESS;
761 unsigned int *pi_width = va_arg( args, unsigned int * );
762 unsigned int *pi_height = va_arg( args, unsigned int * );
763 *pi_width = videoWidget->videoSize.width();
764 *pi_height = videoWidget->videoSize.height();
769 unsigned int i_width = va_arg( args, unsigned int );
770 unsigned int i_height = va_arg( args, unsigned int );
771 emit askVideoToResize( i_width, i_height );
775 case VOUT_SET_STAY_ON_TOP:
777 int i_arg = va_arg( args, int );
778 QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
782 i_ret = VLC_EGENERIC;
783 msg_Warn( p_intf, "unsupported control query" );
789 /*****************************************************************************
790 * Playlist, Visualisation and Menus handling
791 *****************************************************************************/
793 * Toggle the playlist widget or dialog
795 void MainInterface::togglePlaylist()
797 THEDP->playlistDialog();
800 If no playlist exist, then create one and attach it to the DockPL*/
801 if( !playlistWidget )
803 playlistWidget = new PlaylistWidget( p_intf, settings, dockPL );
805 /* Add it to the parent DockWidget */
806 dockPL->setWidget( playlistWidget );
808 /* Add the dock to the main Interface */
809 addDockWidget( Qt::BottomDockWidgetArea, dockPL );
811 /* Make the playlist floating is requested. Default is not. */
812 settings->beginGroup( "MainWindow" );
813 if( settings->value( "playlist-floats", 1 ).toInt() )
815 msg_Dbg( p_intf, "we don't want the playlist inside");
816 dockPL->setFloating( true );
818 settings->endGroup();
819 settings->beginGroup( "playlist" );
820 dockPL->move( settings->value( "pos", QPoint( 0,0 ) ).toPoint() );
821 QSize newSize = settings->value( "size", QSize( 400, 300 ) ).toSize();
822 if( newSize.isValid() )
823 dockPL->resize( newSize );
824 settings->endGroup();
827 playlistVisible = true;
831 /* toggle the visibility of the playlist */
833 resize( sizeHint() );
834 playlistVisible = !playlistVisible;
839 /* Function called from the menu to undock the playlist */
840 void MainInterface::undockPlaylist()
842 // dockPL->setFloating( true );
846 void MainInterface::toggleMinimalView()
848 TOGGLEV( menuBar() );
850 TOGGLEV( statusBar() );
851 doComponentsUpdate();
854 /* Video widget cannot do this synchronously as it runs in another thread */
855 /* Well, could it, actually ? Probably dangerous ... */
856 void MainInterface::doComponentsUpdate()
858 msg_Dbg( p_intf, "Updating the geometry" );
859 // resize( sizeHint() );
863 /* toggling advanced controls buttons */
864 void MainInterface::toggleAdvanced()
866 controls->toggleAdvanced();
869 /* Get the visibility status of the controls (hidden or not, advanced or not) */
870 int MainInterface::getControlsVisibilityStatus()
872 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
873 + CONTROLS_ADVANCED * controls->b_advancedVisible );
877 void MainInterface::visual()
879 if( !VISIBLE( visualSelector) )
881 visualSelector->show();
882 if( !THEMIM->getIM()->hasVideo() )
884 /* Show the background widget */
886 visualSelectorEnabled = true;
890 /* Stop any currently running visualization */
891 visualSelector->hide();
892 visualSelectorEnabled = false;
894 doComponentsUpdate();
898 /************************************************************************
900 ************************************************************************/
901 void MainInterface::setDisplayPosition( float pos, int time, int length )
903 char psz_length[MSTRTIME_MAX_SIZE], psz_time[MSTRTIME_MAX_SIZE];
904 secstotimestr( psz_length, length );
905 secstotimestr( psz_time, ( b_remainingTime && length ) ? length - time
909 timestr.sprintf( "%s/%s", psz_time,
910 ( !length && time ) ? "--:--" : psz_length );
912 /* Add a minus to remaining time*/
913 if( b_remainingTime && length ) timeLabel->setText( " -"+timestr+" " );
914 else timeLabel->setText( " "+timestr+" " );
917 void MainInterface::toggleTimeDisplay()
919 b_remainingTime = !b_remainingTime;
922 void MainInterface::setName( QString name )
924 input_name = name; /* store it for the QSystray use */
925 /* Display it in the status bar, but also as a Tooltip in case it doesn't
927 nameLabel->setText( " " + name + " " );
928 nameLabel->setToolTip( " " + name +" " );
931 void MainInterface::setStatus( int status )
933 msg_Dbg( p_intf, "I was here, updating your status" );
934 /* Forward the status to the controls to toggle Play/Pause */
935 controls->setStatus( status );
936 fullscreenControls->setStatus( status );
938 controls->updateInput();
939 fullscreenControls->updateInput();
940 speedControl->setEnable( THEMIM->getIM()->hasInput() );
942 /* And in the systray for the menu */
944 QVLCMenu::updateSystrayMenu( this, p_intf );
947 void MainInterface::setRate( int rate )
950 str.setNum( ( 1000 / (double)rate ), 'f', 2 );
952 speedLabel->setText( str );
953 speedLabel->setToolTip( str );
954 speedControl->updateControls( rate );
957 void MainInterface::updateOnTimer()
959 /* No event for dying */
960 if( intf_ShouldDie( p_intf ) )
962 QApplication::closeAllWindows();
963 QApplication::quit();
967 /*****************************************************************************
968 * Systray Icon and Systray Menu
969 *****************************************************************************/
972 * Create a SystemTray icon and a menu that would go with it.
973 * Connects to a click handler on the icon.
975 void MainInterface::createSystray()
978 if( QDate::currentDate().dayOfYear() >= 354 )
979 iconVLC = QIcon( QPixmap( ":/vlc128-christmas.png" ) );
981 iconVLC = QIcon( QPixmap( ":/vlc128.png" ) );
982 sysTray = new QSystemTrayIcon( iconVLC, this );
983 sysTray->setToolTip( qtr( "VLC media player" ));
985 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
986 systrayMenu->setIcon( iconVLC );
988 QVLCMenu::updateSystrayMenu( this, p_intf, true );
991 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
992 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
996 * Updates the Systray Icon's menu and toggle the main interface
998 void MainInterface::toggleUpdateSystrayMenu()
1000 /* If hidden, show it */
1006 else if( isMinimized() )
1016 /* check if any visible window is above vlc in the z-order,
1017 * but ignore the ones always on top */
1020 wi.cbSize = sizeof( WINDOWINFO );
1021 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
1022 hwnd && !IsWindowVisible( hwnd );
1023 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
1024 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
1025 (wi.dwExStyle&WS_EX_TOPMOST) )
1027 if( isActiveWindow() )
1037 QVLCMenu::updateSystrayMenu( this, p_intf );
1040 void MainInterface::handleSystrayClick(
1041 QSystemTrayIcon::ActivationReason reason )
1045 case QSystemTrayIcon::Trigger:
1046 toggleUpdateSystrayMenu();
1048 case QSystemTrayIcon::MiddleClick:
1049 sysTray->showMessage( qtr( "VLC media player" ),
1050 qtr( "Control menu for the player" ),
1051 QSystemTrayIcon::Information, 3000 );
1057 * Updates the name of the systray Icon tooltip.
1058 * Doesn't check if the systray exists, check before you call it.
1060 void MainInterface::updateSystrayTooltipName( QString name )
1062 if( name.isEmpty() )
1064 sysTray->setToolTip( qtr( "VLC media player" ) );
1068 sysTray->setToolTip( name );
1069 if( notificationEnabled && ( isHidden() || isMinimized() ) )
1071 sysTray->showMessage( qtr( "VLC media player" ), name,
1072 QSystemTrayIcon::NoIcon, 3000 );
1078 * Updates the status of the systray Icon tooltip.
1079 * Doesn't check if the systray exists, check before you call it.
1081 void MainInterface::updateSystrayTooltipStatus( int i_status )
1088 sysTray->setToolTip( qtr( "VLC media player" ) );
1093 sysTray->setToolTip( input_name );
1098 sysTray->setToolTip( input_name + " - "
1105 /************************************************************************
1107 ************************************************************************/
1108 void MainInterface::dropEvent(QDropEvent *event)
1110 const QMimeData *mimeData = event->mimeData();
1112 /* D&D of a subtitles file, add it on the fly */
1113 if( mimeData->urls().size() == 1 )
1115 if( THEMIM->getIM()->hasInput() )
1117 if( input_AddSubtitles( THEMIM->getInput(),
1118 qtu( mimeData->urls()[0].toString() ),
1121 event->acceptProposedAction();
1127 foreach( QUrl url, mimeData->urls() )
1129 QString s = url.toLocalFile();
1130 if( s.length() > 0 ) {
1131 playlist_Add( THEPL, qtu(s), NULL,
1132 PLAYLIST_APPEND | (first ? PLAYLIST_GO:0),
1133 PLAYLIST_END, true, false );
1137 event->acceptProposedAction();
1139 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1141 event->acceptProposedAction();
1143 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1145 event->acceptProposedAction();
1147 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1152 /************************************************************************
1154 ************************************************************************/
1155 void MainInterface::customEvent( QEvent *event )
1158 if( event->type() == PLDockEvent_Type )
1160 PlaylistDialog::killInstance();
1161 playlistEmbeddedFlag = true;
1163 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1168 if ( event->type() == SetVideoOnTopEvent_Type )
1170 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1171 if( p_event->OnTop() )
1172 setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
1174 setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint);
1175 show(); /* necessary to apply window flags?? */
1179 void MainInterface::keyPressEvent( QKeyEvent *e )
1181 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() & Qt::Key_H )
1182 && menuBar()->isHidden() )
1184 toggleMinimalView();
1188 int i_vlck = qtEventToVLCKey( e );
1191 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1198 void MainInterface::wheelEvent( QWheelEvent *e )
1200 int i_vlckey = qtWheelEventToVLCKey( e );
1201 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1205 void MainInterface::closeEvent( QCloseEvent *e )
1211 void MainInterface::toggleFullScreen( void )
1213 if( isFullScreen() )
1219 /*****************************************************************************
1221 *****************************************************************************/
1222 static int InteractCallback( vlc_object_t *p_this,
1223 const char *psz_var, vlc_value_t old_val,
1224 vlc_value_t new_val, void *param )
1226 intf_dialog_args_t *p_arg = new intf_dialog_args_t;
1227 p_arg->p_dialog = (interaction_dialog_t *)(new_val.p_address);
1228 DialogEvent *event = new DialogEvent( INTF_DIALOG_INTERACTION, 0, p_arg );
1229 QApplication::postEvent( THEDP, static_cast<QEvent*>(event) );
1233 /*****************************************************************************
1234 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1235 * We don't show the menu directly here because we don't want the
1236 * caller to block for a too long time.
1237 *****************************************************************************/
1238 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1239 vlc_value_t old_val, vlc_value_t new_val, void *param )
1241 intf_thread_t *p_intf = (intf_thread_t *)param;
1243 if( p_intf->pf_show_dialog )
1245 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1246 new_val.b_bool, 0 );
1252 /*****************************************************************************
1253 * IntfShowCB: callback triggered by the intf-show libvlc variable.
1254 *****************************************************************************/
1255 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1256 vlc_value_t old_val, vlc_value_t new_val, void *param )
1258 intf_thread_t *p_intf = (intf_thread_t *)param;
1259 p_intf->p_sys->p_mi->requestLayoutUpdate();