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 );
85 static void DoRelease( intf_thread_t *p_intf, void *p_win )
87 return p_intf->p_sys->p_mi->releaseVideo( p_win );
89 static int DoControl( intf_thread_t *p_intf, void *p_win, int i_q, va_list a )
91 return p_intf->p_sys->p_mi->controlVideo( p_win, i_q, a );
94 MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
96 /* Variables initialisation */
97 // need_components_update = false;
100 playlistWidget = NULL;
102 videoIsActive = false;
103 playlistVisible = false;
106 /* Ask for privacy */
110 * Configuration and settings
111 * Pre-building of interface
114 setFocusPolicy( Qt::StrongFocus );
115 setAcceptDrops( true );
116 setWindowIcon( QApplication::windowIcon() );
117 setWindowOpacity( config_GetFloat( p_intf, "qt-opacity" ) );
119 /* Set The Video In emebedded Mode or not */
120 videoEmbeddedFlag = config_GetInt( p_intf, "embedded-video" );
122 /* Are we in the enhanced always-video mode or not ? */
123 i_visualmode = config_GetInt( p_intf, "qt-display-mode" );
125 /* Set the other interface settings */
126 settings = new QSettings( "vlc", "vlc-qt-interface" );
127 settings->beginGroup( "MainWindow" );
129 //TODO: I don't like that code
130 visualSelectorEnabled = settings->value( "visual-selector", false ).toBool();
131 notificationEnabled = (bool)config_GetInt( p_intf, "qt-notification" );
133 /**************************
134 * UI and Widgets design
135 **************************/
136 setVLCWindowsTitle();
137 handleMainUi( settings );
140 /* Create a Dock to get the playlist */
141 dockPL = new QDockWidget( qtr( "Playlist" ), this );
142 dockPL->setSizePolicy( QSizePolicy::Preferred,
143 QSizePolicy::Expanding );
144 dockPL->setFeatures( QDockWidget::AllDockWidgetFeatures );
145 dockPL->setAllowedAreas( Qt::LeftDockWidgetArea
146 | Qt::RightDockWidgetArea
147 | Qt::BottomDockWidgetArea );
154 QVLCMenu::createMenuBar( this, p_intf, visualSelectorEnabled );
156 /* StatusBar Creation */
160 /********************
162 ********************/
163 MainInputManager::getInstance( p_intf );
165 /**************************
166 * Various CONNECTs on IM *
167 **************************/
168 /* Connect the input manager to the GUI elements it manages */
170 /* It is also connected to the control->slider, see the ControlsWidget */
171 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
172 this, setDisplayPosition( float, int, int ) );
173 /* Change the SpeedRate in the Status */
174 CONNECT( THEMIM->getIM(), rateChanged( int ), this, setRate( int ) );
177 * Connects on nameChanged()
178 * Those connects are not merged because different options can trigger
181 /* Naming in the controller statusbar */
182 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
183 setName( QString ) );
184 /* and in the systray */
187 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
188 updateSystrayTooltipName( QString ) );
190 /* and in the title of the controller */
191 if( config_GetInt( p_intf, "qt-name-in-title" ) )
193 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
194 setVLCWindowsTitle( QString ) );
198 * CONNECTS on PLAY_STATUS
200 /* Status on the main controller */
201 CONNECT( THEMIM->getIM(), statusChanged( int ), this, setStatus( int ) );
202 /* and in the systray */
205 CONNECT( THEMIM->getIM(), statusChanged( int ), this,
206 updateSystrayTooltipStatus( int ) );
209 /* END CONNECTS ON IM */
213 /* TODO Remove this function, but so far, there is no choice because there
214 is no intf-should-die variable */
215 ON_TIMEOUT( updateOnTimer() );
216 //ON_TIMEOUT( debug() );
221 var_Create( p_intf, "interaction", VLC_VAR_ADDRESS );
222 var_AddCallback( p_intf, "interaction", InteractCallback, this );
223 p_intf->b_interaction = true;
225 var_AddCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
227 /* Register callback for the intf-popupmenu variable */
228 playlist_t *p_playlist = pl_Yield( p_intf );
229 var_AddCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
230 pl_Release( p_intf );
232 /* VideoWidget connect mess to avoid different threads speaking to each other */
233 CONNECT( this, askReleaseVideo( void * ),
234 this, releaseVideoSlot( void * ) );
235 CONNECT( this, askVideoToResize( unsigned int, unsigned int ),
236 videoWidget, SetSizing( unsigned int, unsigned int ) );
238 CONNECT( this, askUpdate(), this, doComponentsUpdate() );
240 CONNECT( controls, advancedControlsToggled( bool ),
241 this, doComponentsUpdate() );
243 /* Size and placement of interface */
244 QVLCTools::restoreWidgetPosition(settings,this,QSize(350,60));
248 if( settings->value( "playlist-visible", 0 ).toInt() ) togglePlaylist();
249 settings->endGroup();
253 if( i_visualmode == QT_MINIMAL_MODE )
256 /* Update the geometry TODO: is it useful ?*/
259 /*****************************************************
260 * End everything by creating the Systray Management *
261 *****************************************************/
265 MainInterface::~MainInterface()
267 msg_Dbg( p_intf, "Destroying the main interface" );
270 playlistWidget->savingSettings( settings );
272 settings->beginGroup( "MainWindow" );
274 // settings->setValue( "playlist-floats", (int)(dockPL->isFloating()) );
275 settings->setValue( "playlist-visible", (int)playlistVisible );
276 settings->setValue( "adv-controls",
277 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
280 QVLCTools::saveWidgetPosition(settings, this);
283 settings->setValue( "backgroundSize", bgWidget->size() );
285 settings->endGroup();
288 var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
290 /* Unregister callback for the intf-popupmenu variable */
291 playlist_t *p_playlist = pl_Yield( p_intf );
292 var_DelCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
293 pl_Release( p_intf );
295 p_intf->b_interaction = false;
296 var_DelCallback( p_intf, "interaction", InteractCallback, this );
298 p_intf->pf_request_window = NULL;
299 p_intf->pf_release_window = NULL;
300 p_intf->pf_control_window = NULL;
301 p_intf->p_sys->p_mi = NULL;
304 /*****************************
306 *****************************/
308 inline void MainInterface::createStatusBar()
313 /* Widgets Creation*/
314 b_remainingTime = false;
315 timeLabel = new TimeLabel;
316 timeLabel->setText( " --:--/--:-- " );
317 timeLabel->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
318 nameLabel = new QLabel;
319 nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
320 | Qt::TextSelectableByKeyboard );
321 speedLabel = new SpeedLabel( p_intf, "1.00x" );
322 speedLabel->setContextMenuPolicy ( Qt::CustomContextMenu );
324 /* Styling those labels */
325 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
326 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
327 nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
329 pgBar = new QProgressBar;
332 /* and adding those */
333 statusBar()->addWidget( nameLabel, 8 );
334 statusBar()->addPermanentWidget( speedLabel, 0 );
335 statusBar()->addPermanentWidget( pgBar, 0 );
336 statusBar()->addPermanentWidget( timeLabel, 0 );
338 /* timeLabel behaviour:
339 - double clicking opens the goto time dialog
340 - right-clicking and clicking just toggle between remaining and
342 CONNECT( timeLabel, timeLabelClicked(), this, toggleTimeDisplay() );
343 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
344 CONNECT( timeLabel, timeLabelDoubleClicked(), this, toggleTimeDisplay() );
346 /* Speed Label behaviour:
347 - right click gives the vertical speed slider */
348 CONNECT( speedLabel, customContextMenuRequested( QPoint ),
349 this, showSpeedMenu( QPoint ) );
352 inline void MainInterface::initSystray()
354 bool b_createSystray = false;
355 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
356 if( config_GetInt( p_intf, "qt-start-minimized") )
358 if( b_systrayAvailable )
360 b_createSystray = true;
363 else msg_Err( p_intf, "You can't minimize if you haven't a system "
366 if( config_GetInt( p_intf, "qt-system-tray") )
367 b_createSystray = true;
369 if( b_systrayAvailable && b_createSystray )
374 * Give the decorations of the Main Window a correct Name.
375 * If nothing is given, set it to VLC...
377 void MainInterface::setVLCWindowsTitle( QString aTitle )
379 if( aTitle.isEmpty() )
381 setWindowTitle( qtr( "VLC media player" ) );
385 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
389 void MainInterface::handleMainUi( QSettings *settings )
391 /* Create the main Widget and the mainLayout */
392 QWidget *main = new QWidget;
393 setCentralWidget( main );
394 mainLayout = new QVBoxLayout( main );
396 /* Margins, spacing */
397 main->setContentsMargins( 0, 0, 0, 0 );
398 main->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
399 mainLayout->setMargin( 0 );
401 /* Create the CONTROLS Widget */
402 /* bool b_shiny = config_GetInt( p_intf, "qt-blingbling" ); */
403 controls = new ControlsWidget( p_intf, this,
404 settings->value( "adv-controls", false ).toBool(),
405 config_GetInt( p_intf, "qt-blingbling" ) );
407 /* Add the controls Widget to the main Widget */
408 mainLayout->insertWidget( 0, controls, 0, Qt::AlignBottom );
410 /* Create the Speed Control Widget */
411 speedControl = new SpeedControlWidget( p_intf );
412 speedControlMenu = new QMenu( this );
414 QWidgetAction *widgetAction = new QWidgetAction( speedControl );
415 widgetAction->setDefaultWidget( speedControl );
416 speedControlMenu->addAction( widgetAction );
419 /* Disabled for now, they SUCK */
421 visualSelector = new VisualSelector( p_intf );
422 mainLayout->insertWidget( 0, visualSelector );
423 visualSelector->hide();
426 /* And video Outputs */
427 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
428 i_visualmode == QT_MINIMAL_MODE )
430 bgWidget = new BackgroundWidget( p_intf );
432 settings->value( "backgroundSize", QSize( 300, 150 ) ).toSize() );
433 bgWidget->updateGeometry();
434 mainLayout->insertWidget( 0, bgWidget );
435 CONNECT( this, askBgWidgetToToggle(), bgWidget, toggle() );
438 if( videoEmbeddedFlag )
440 videoWidget = new VideoWidget( p_intf );
441 mainLayout->insertWidget( 0, videoWidget );
443 p_intf->pf_request_window = ::DoRequest;
444 p_intf->pf_release_window = ::DoRelease;
445 p_intf->pf_control_window = ::DoControl;
448 /* Finish the sizing */
449 main->updateGeometry();
452 inline void MainInterface::askForPrivacy()
455 * Ask for the network policy on FIRST STARTUP
457 if( config_GetInt( p_intf, "qt-privacy-ask") )
459 QList<ConfigControl *> controls;
460 if( privacyDialog( controls ) == QDialog::Accepted )
462 QList<ConfigControl *>::Iterator i;
463 for( i = controls.begin() ; i != controls.end() ; i++ )
465 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
466 c->doApply( p_intf );
469 config_PutInt( p_intf, "qt-privacy-ask" , 0 );
470 /* We have to save here because the user may not launch Prefs */
471 config_SaveConfigFile( p_intf, NULL );
476 int MainInterface::privacyDialog( QList<ConfigControl *> controls )
478 QDialog *privacy = new QDialog();
480 privacy->setWindowTitle( qtr( "Privacy and Network policies" ) );
482 QGridLayout *gLayout = new QGridLayout( privacy );
484 QGroupBox *blabla = new QGroupBox( qtr( "Privacy and Network Warning" ) );
485 QGridLayout *blablaLayout = new QGridLayout( blabla );
486 QLabel *text = new QLabel( qtr(
487 "<p>The <i>VideoLAN Team</i> doesn't like when an application goes "
488 "online without authorization.</p>\n "
489 "<p><i>VLC media player</i> can request limited information on "
490 "the Internet, especially to get CD covers and songs metadata or to know "
491 "if updates are available.</p>\n"
492 "<p><i>VLC media player</i> <b>DOES NOT</b> send or collect <b>ANY</b> "
493 "information, even anonymously, about your usage.</p>\n"
494 "<p>Therefore please check the following options, the default being "
495 "almost no access on the web.</p>\n") );
496 text->setWordWrap( true );
497 text->setTextFormat( Qt::RichText );
499 blablaLayout->addWidget( text, 0, 0 ) ;
501 QGroupBox *options = new QGroupBox;
502 QGridLayout *optionsLayout = new QGridLayout( options );
504 gLayout->addWidget( blabla, 0, 0, 1, 3 );
505 gLayout->addWidget( options, 1, 0, 1, 3 );
506 module_config_t *p_config;
507 ConfigControl *control;
510 #define CONFIG_GENERIC( option, type ) \
511 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
514 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
515 p_config, options, false, optionsLayout, line ); \
516 controls.append( control ); \
519 #define CONFIG_GENERIC_NOBOOL( option, type ) \
520 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
523 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
524 p_config, options, optionsLayout, line ); \
525 controls.append( control ); \
528 CONFIG_GENERIC( "album-art", IntegerList ); line++;
529 CONFIG_GENERIC_NOBOOL( "fetch-meta", Bool ); line++;
531 CONFIG_GENERIC_NOBOOL( "qt-updates-notif", Bool ); line++;
532 CONFIG_GENERIC_NOBOOL( "qt-updates-days", Integer ); line++;
535 QPushButton *ok = new QPushButton( qtr( "Ok" ) );
537 gLayout->addWidget( ok, 2, 2 );
539 CONNECT( ok, clicked(), privacy, accept() );
540 return privacy->exec();
544 /**********************************************************************
545 * Handling of sizing of the components
546 **********************************************************************/
548 /* This function is probably wrong, but we don't have many many choices...
549 Since we can't know from the playlist Widget if we are inside a dock or not,
550 because the playlist Widget can be called by THEDP, as a separate windows for
552 Maybe the other solution is to redefine the sizeHint() of the playlist and
553 ask _parent->isFloating()...
554 If you think this would be better, please FIXME it...
557 QSize MainInterface::sizeHint() const
559 int nwidth = controls->sizeHint().width();
560 int nheight = controls->isVisible() ?
561 controls->size().height()
562 + menuBar()->size().height()
563 + statusBar()->size().height()
566 msg_Dbg( p_intf, "1 %i %i", nheight, nwidth );
567 if( VISIBLE( bgWidget ) )
569 nheight += bgWidget->size().height();
570 nwidth = bgWidget->size().width();
571 msg_Dbg( p_intf, "1b %i %i", nheight, nwidth );
573 else if( videoIsActive )
575 nheight += videoWidget->size().height();
576 nwidth = videoWidget->size().width();
577 msg_Dbg( p_intf, "2 %i %i", nheight, nwidth );
579 /* if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget() )
581 nheight += dockPL->size().height();
582 nwidth = __MAX( nwidth, dockPL->size().width() );
583 msg_Dbg( p_intf, "3 %i %i", nheight, nwidth );
585 msg_Dbg( p_intf, "4 %i %i", nheight, nwidth );
586 return QSize( nwidth, nheight );
590 /* FIXME This is dead code and need to be removed AT THE END */
591 void MainInterface::resizeEvent( QResizeEvent *e )
594 videoWidget->widgetSize.setWidth( e->size().width() - addSize.width() );
595 if( videoWidget && videoIsActive && videoWidget->widgetSize.height() > 1 )
597 SET_WH( videoWidget, e->size().width() - addSize.width(),
598 e->size().height() - addSize.height() );
599 videoWidget->updateGeometry();
601 if( VISIBLE( playlistWidget ) )
603 // SET_WH( playlistWidget , e->size().width() - addSize.width(),
604 // e->size().height() - addSize.height() );
605 playlistWidget->updateGeometry();
610 void MainInterface::requestLayoutUpdate()
615 //FIXME remove me at the end...
616 void MainInterface::debug()
618 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
619 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
620 if( videoWidget && videoWidget->isVisible() )
623 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
624 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
629 /****************************************************************************
630 * Small right-click menu for rate control
631 ****************************************************************************/
632 void MainInterface::showSpeedMenu( QPoint pos )
634 speedControlMenu->exec( QCursor::pos() - pos
635 + QPoint( 0, speedLabel->height() ) );
638 /****************************************************************************
640 ****************************************************************************/
641 class SetVideoOnTopQtEvent : public QEvent
644 SetVideoOnTopQtEvent( bool _onTop ) :
645 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
660 * Thou shall not call/resize/hide widgets from on another thread.
661 * This is wrong, and this is TEH reason to emit signals on those Video Functions
663 /* function called from ::DoRequest in order to show a nice VideoWidget
665 void *MainInterface::requestVideo( vout_thread_t *p_nvout, int *pi_x,
666 int *pi_y, unsigned int *pi_width,
667 unsigned int *pi_height )
669 bool bgWasVisible = false;
671 /* Request the videoWidget */
672 void *ret = videoWidget->request( p_nvout,pi_x, pi_y, pi_width, pi_height );
673 if( ret ) /* The videoWidget is available */
675 /* Did we have a bg ? Hide it! */
676 if( VISIBLE( bgWidget) )
679 emit askBgWidgetToToggle();
682 /*if( THEMIM->getIM()->hasVideo() || !bgWasVisible )
684 videoWidget->widgetSize = QSize( *pi_width, *pi_height );
686 else /* Background widget available, use its size */
688 /* Ok, our visualizations are bad, so don't do this for the moment
689 * use the requested size anyway */
690 // videoWidget->widgetSize = bgWidget->widgeTSize;
691 /* videoWidget->widgetSize = QSize( *pi_width, *pi_height );
694 videoIsActive = true;
696 emit askVideoToResize( *pi_width, *pi_height );
702 void MainInterface::releaseVideo( void *p_win )
704 emit askReleaseVideo( p_win );
707 void MainInterface::releaseVideoSlot( void *p_win )
709 videoWidget->release( p_win );
712 if( bgWidget )// WORONG
716 videoIsActive = false;
719 int MainInterface::controlVideo( void *p_window, int i_query, va_list args )
721 int i_ret = VLC_SUCCESS;
726 unsigned int *pi_width = va_arg( args, unsigned int * );
727 unsigned int *pi_height = va_arg( args, unsigned int * );
728 *pi_width = videoWidget->videoSize.width();
729 *pi_height = videoWidget->videoSize.height();
734 unsigned int i_width = va_arg( args, unsigned int );
735 unsigned int i_height = va_arg( args, unsigned int );
736 emit askVideoToResize( i_width, i_height );
740 case VOUT_SET_STAY_ON_TOP:
742 int i_arg = va_arg( args, int );
743 QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
747 i_ret = VLC_EGENERIC;
748 msg_Warn( p_intf, "unsupported control query" );
754 /*****************************************************************************
755 * Playlist, Visualisation and Menus handling
756 *****************************************************************************/
758 * Toggle the playlist widget or dialog
760 void MainInterface::togglePlaylist()
762 THEDP->playlistDialog();
765 If no playlist exist, then create one and attach it to the DockPL*/
766 if( !playlistWidget )
768 playlistWidget = new PlaylistWidget( p_intf, settings, dockPL );
770 /* Add it to the parent DockWidget */
771 dockPL->setWidget( playlistWidget );
773 /* Add the dock to the main Interface */
774 addDockWidget( Qt::BottomDockWidgetArea, dockPL );
776 /* Make the playlist floating is requested. Default is not. */
777 settings->beginGroup( "MainWindow" );
778 if( settings->value( "playlist-floats", 1 ).toInt() )
780 msg_Dbg( p_intf, "we don't want the playlist inside");
781 dockPL->setFloating( true );
783 settings->endGroup();
784 settings->beginGroup( "playlist" );
785 dockPL->move( settings->value( "pos", QPoint( 0,0 ) ).toPoint() );
786 QSize newSize = settings->value( "size", QSize( 400, 300 ) ).toSize();
787 if( newSize.isValid() )
788 dockPL->resize( newSize );
789 settings->endGroup();
792 playlistVisible = true;
796 /* toggle the visibility of the playlist */
798 resize( sizeHint() );
799 playlistVisible = !playlistVisible;
804 /* Function called from the menu to undock the playlist */
805 void MainInterface::undockPlaylist()
807 // dockPL->setFloating( true );
811 void MainInterface::toggleMinimalView()
813 TOGGLEV( menuBar() );
815 TOGGLEV( statusBar() );
816 doComponentsUpdate();
819 /* Video widget cannot do this synchronously as it runs in another thread */
820 /* Well, could it, actually ? Probably dangerous ... */
821 void MainInterface::doComponentsUpdate()
823 msg_Dbg( p_intf, "Updating the geometry" );
824 // resize( sizeHint() );
828 /* toggling advanced controls buttons */
829 void MainInterface::toggleAdvanced()
831 controls->toggleAdvanced();
834 /* Get the visibility status of the controls (hidden or not, advanced or not) */
835 int MainInterface::getControlsVisibilityStatus()
837 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
838 + CONTROLS_ADVANCED * controls->b_advancedVisible );
842 void MainInterface::visual()
844 if( !VISIBLE( visualSelector) )
846 visualSelector->show();
847 if( !THEMIM->getIM()->hasVideo() )
849 /* Show the background widget */
851 visualSelectorEnabled = true;
855 /* Stop any currently running visualization */
856 visualSelector->hide();
857 visualSelectorEnabled = false;
859 doComponentsUpdate();
863 /************************************************************************
865 ************************************************************************/
866 void MainInterface::setDisplayPosition( float pos, int time, int length )
868 char psz_length[MSTRTIME_MAX_SIZE], psz_time[MSTRTIME_MAX_SIZE];
869 secstotimestr( psz_length, length );
870 secstotimestr( psz_time, ( b_remainingTime && length ) ? length - time
874 timestr.sprintf( "%s/%s", psz_time,
875 ( !length && time ) ? "--:--" : psz_length );
877 /* Add a minus to remaining time*/
878 if( b_remainingTime && length ) timeLabel->setText( " -"+timestr+" " );
879 else timeLabel->setText( " "+timestr+" " );
882 void MainInterface::toggleTimeDisplay()
884 b_remainingTime = !b_remainingTime;
887 void MainInterface::setName( QString name )
889 input_name = name; /* store it for the QSystray use */
890 /* Display it in the status bar, but also as a Tooltip in case it doesn't
892 nameLabel->setText( " " + name + " " );
893 nameLabel->setToolTip( " " + name +" " );
896 void MainInterface::setStatus( int status )
898 msg_Dbg( p_intf, "I was here, updating your status" );
899 /* Forward the status to the controls to toggle Play/Pause */
900 controls->setStatus( status );
902 controls->updateInput();
903 speedControl->setEnable( THEMIM->getIM()->hasInput() );
905 /* And in the systray for the menu */
907 QVLCMenu::updateSystrayMenu( this, p_intf );
910 void MainInterface::setRate( int rate )
913 str.setNum( ( 1000 / (double)rate ), 'f', 2 );
915 speedLabel->setText( str );
916 speedLabel->setToolTip( str );
917 speedControl->updateControls( rate );
920 void MainInterface::updateOnTimer()
922 /* No event for dying */
923 if( intf_ShouldDie( p_intf ) )
925 QApplication::closeAllWindows();
926 QApplication::quit();
930 /*****************************************************************************
931 * Systray Icon and Systray Menu
932 *****************************************************************************/
935 * Create a SystemTray icon and a menu that would go with it.
936 * Connects to a click handler on the icon.
938 void MainInterface::createSystray()
941 if( QDate::currentDate().dayOfYear() >= 354 )
942 iconVLC = QIcon( QPixmap( ":/vlc128-christmas.png" ) );
944 iconVLC = QIcon( QPixmap( ":/vlc128.png" ) );
945 sysTray = new QSystemTrayIcon( iconVLC, this );
946 sysTray->setToolTip( qtr( "VLC media player" ));
948 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
949 systrayMenu->setIcon( iconVLC );
951 QVLCMenu::updateSystrayMenu( this, p_intf, true );
954 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
955 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
959 * Updates the Systray Icon's menu and toggle the main interface
961 void MainInterface::toggleUpdateSystrayMenu()
963 /* If hidden, show it */
969 else if( isMinimized() )
979 /* check if any visible window is above vlc in the z-order,
980 * but ignore the ones always on top */
983 wi.cbSize = sizeof( WINDOWINFO );
984 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
985 hwnd && !IsWindowVisible( hwnd );
986 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
987 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
988 (wi.dwExStyle&WS_EX_TOPMOST) )
990 if( isActiveWindow() )
1000 QVLCMenu::updateSystrayMenu( this, p_intf );
1003 void MainInterface::handleSystrayClick(
1004 QSystemTrayIcon::ActivationReason reason )
1008 case QSystemTrayIcon::Trigger:
1009 toggleUpdateSystrayMenu();
1011 case QSystemTrayIcon::MiddleClick:
1012 sysTray->showMessage( qtr( "VLC media player" ),
1013 qtr( "Control menu for the player" ),
1014 QSystemTrayIcon::Information, 3000 );
1020 * Updates the name of the systray Icon tooltip.
1021 * Doesn't check if the systray exists, check before you call it.
1023 void MainInterface::updateSystrayTooltipName( QString name )
1025 if( name.isEmpty() )
1027 sysTray->setToolTip( qtr( "VLC media player" ) );
1031 sysTray->setToolTip( name );
1032 if( notificationEnabled && ( isHidden() || isMinimized() ) )
1034 sysTray->showMessage( qtr( "VLC media player" ), name,
1035 QSystemTrayIcon::NoIcon, 3000 );
1041 * Updates the status of the systray Icon tooltip.
1042 * Doesn't check if the systray exists, check before you call it.
1044 void MainInterface::updateSystrayTooltipStatus( int i_status )
1051 sysTray->setToolTip( qtr( "VLC media player" ) );
1056 sysTray->setToolTip( input_name );
1061 sysTray->setToolTip( input_name + " - "
1068 /************************************************************************
1070 ************************************************************************/
1071 void MainInterface::dropEvent(QDropEvent *event)
1073 const QMimeData *mimeData = event->mimeData();
1075 /* D&D of a subtitles file, add it on the fly */
1076 if( mimeData->urls().size() == 1 )
1078 if( THEMIM->getIM()->hasInput() )
1080 if( input_AddSubtitles( THEMIM->getInput(),
1081 qtu( mimeData->urls()[0].toString() ),
1084 event->acceptProposedAction();
1090 foreach( QUrl url, mimeData->urls() )
1092 QString s = url.toLocalFile();
1093 if( s.length() > 0 ) {
1094 playlist_Add( THEPL, qtu(s), NULL,
1095 PLAYLIST_APPEND | (first ? PLAYLIST_GO:0),
1096 PLAYLIST_END, true, false );
1100 event->acceptProposedAction();
1102 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1104 event->acceptProposedAction();
1106 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1108 event->acceptProposedAction();
1110 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1115 /************************************************************************
1117 ************************************************************************/
1118 void MainInterface::customEvent( QEvent *event )
1121 if( event->type() == PLDockEvent_Type )
1123 PlaylistDialog::killInstance();
1124 playlistEmbeddedFlag = true;
1126 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1131 if ( event->type() == SetVideoOnTopEvent_Type )
1133 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1134 if( p_event->OnTop() )
1135 setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
1137 setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint);
1138 show(); /* necessary to apply window flags?? */
1142 void MainInterface::keyPressEvent( QKeyEvent *e )
1144 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() & Qt::Key_H )
1145 && menuBar()->isHidden() )
1147 toggleMinimalView();
1151 int i_vlck = qtEventToVLCKey( e );
1154 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1161 void MainInterface::wheelEvent( QWheelEvent *e )
1163 int i_vlckey = qtWheelEventToVLCKey( e );
1164 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1168 void MainInterface::closeEvent( QCloseEvent *e )
1174 void MainInterface::toggleFullScreen( void )
1176 if( isFullScreen() )
1182 /*****************************************************************************
1184 *****************************************************************************/
1185 static int InteractCallback( vlc_object_t *p_this,
1186 const char *psz_var, vlc_value_t old_val,
1187 vlc_value_t new_val, void *param )
1189 intf_dialog_args_t *p_arg = new intf_dialog_args_t;
1190 p_arg->p_dialog = (interaction_dialog_t *)(new_val.p_address);
1191 DialogEvent *event = new DialogEvent( INTF_DIALOG_INTERACTION, 0, p_arg );
1192 QApplication::postEvent( THEDP, static_cast<QEvent*>(event) );
1196 /*****************************************************************************
1197 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1198 * We don't show the menu directly here because we don't want the
1199 * caller to block for a too long time.
1200 *****************************************************************************/
1201 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1202 vlc_value_t old_val, vlc_value_t new_val, void *param )
1204 intf_thread_t *p_intf = (intf_thread_t *)param;
1206 if( p_intf->pf_show_dialog )
1208 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1209 new_val.b_bool, 0 );
1215 /*****************************************************************************
1216 * IntfShowCB: callback triggered by the intf-show libvlc variable.
1217 *****************************************************************************/
1218 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1219 vlc_value_t old_val, vlc_value_t new_val, void *param )
1221 intf_thread_t *p_intf = (intf_thread_t *)param;
1222 p_intf->p_sys->p_mi->requestLayoutUpdate();