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 *****************************************************************************/
30 #include "main_interface.hpp"
31 #include "input_manager.hpp"
32 #include "util/qvlcframe.hpp"
33 #include "util/customwidgets.hpp"
34 #include "dialogs_provider.hpp"
35 #include "components/interface_widgets.hpp"
36 #include "components/playlist/playlist.hpp"
37 #include "dialogs/extended.hpp"
38 #include "dialogs/playlist.hpp"
42 #include <QCloseEvent>
43 #include <QPushButton>
47 #include <QSystemTrayIcon>
52 #include <QWidgetAction>
53 #include <QDockWidget>
57 #include <QProgressBar>
63 #define SET_WIDTH(i,j) i->widgetSize.setWidth(j)
64 #define SET_HEIGHT(i,j) i->widgetSize.setHeight(j)
65 #define SET_WH( i,j,k) i->widgetSize.setWidth(j); i->widgetSize.setHeight(k);
67 #define DS(i) i.width(),i.height()
69 /* Callback prototypes */
70 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
71 vlc_value_t old_val, vlc_value_t new_val, void *param );
72 static int IntfShowCB( 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 InteractCallback( vlc_object_t *, const char *, vlc_value_t,
77 static void *DoRequest( intf_thread_t *p_intf, vout_thread_t *p_vout,
78 int *pi1, int *pi2, unsigned int*pi3,unsigned int*pi4)
80 return p_intf->p_sys->p_mi->requestVideo( p_vout, pi1, pi2, pi3, pi4 );
82 static void DoRelease( intf_thread_t *p_intf, void *p_win )
84 return p_intf->p_sys->p_mi->releaseVideo( p_win );
86 static int DoControl( intf_thread_t *p_intf, void *p_win, int i_q, va_list a )
88 return p_intf->p_sys->p_mi->controlVideo( p_win, i_q, a );
91 MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
93 /* Variables initialisation */
94 // need_components_update = false;
95 bgWidget = NULL; videoWidget = NULL; playlistWidget = NULL;
96 videoIsActive = false;
98 playlistVisible = false;
100 /* Ask for privacy */
104 * Configuration and settings
106 settings = new QSettings( "vlc", "vlc-qt-interface" );
107 settings->beginGroup( "MainWindow" );
110 setFocusPolicy( Qt::StrongFocus );
111 setAcceptDrops( true );
112 setWindowIcon( QApplication::windowIcon() );
113 setWindowOpacity( config_GetFloat( p_intf, "qt-opacity" ) );
115 /* Set The Video In emebedded Mode or not */
116 videoEmbeddedFlag = false;
117 if( config_GetInt( p_intf, "embedded-video" ) ) videoEmbeddedFlag = true;
119 /* Are we in the enhanced always-video mode or not ? */
120 alwaysVideoFlag = false;
121 if( videoEmbeddedFlag && config_GetInt( p_intf, "qt-always-video" ) )
122 alwaysVideoFlag = true;
124 /* Set the other interface settings */
125 //TODO: I don't like that code
126 visualSelectorEnabled = settings->value( "visual-selector", false ).toBool();
127 notificationEnabled = config_GetInt( p_intf, "qt-notification" )
130 /**************************
131 * UI and Widgets design
132 **************************/
133 setVLCWindowsTitle();
134 handleMainUi( settings );
136 /* Create a Dock to get the playlist */
137 dockPL = new QDockWidget( qtr( "Playlist" ), this );
138 dockPL->setSizePolicy( QSizePolicy::Preferred,
139 QSizePolicy::Expanding );
140 dockPL->setFeatures( QDockWidget::AllDockWidgetFeatures );
141 dockPL->setAllowedAreas( Qt::LeftDockWidgetArea
142 | Qt::RightDockWidgetArea
143 | Qt::BottomDockWidgetArea );
149 QVLCMenu::createMenuBar( this, p_intf, visualSelectorEnabled );
154 /* Widgets Creation*/
155 b_remainingTime = false;
156 timeLabel = new TimeLabel;
157 timeLabel->setText( " --:--/--:-- " );
158 timeLabel->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
159 nameLabel = new QLabel;
160 nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
161 | Qt::TextSelectableByKeyboard );
162 speedLabel = new QLabel( "1.00x" );
163 speedLabel->setContextMenuPolicy ( Qt::CustomContextMenu );
165 /* Styling those labels */
166 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
167 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
168 nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
170 pgBar = new QProgressBar;
173 /* and adding those */
174 statusBar()->addWidget( nameLabel, 8 );
175 statusBar()->addPermanentWidget( speedLabel, 0 );
176 statusBar()->addPermanentWidget( pgBar, 0 );
177 statusBar()->addPermanentWidget( timeLabel, 0 );
179 /* timeLabel behaviour:
180 - double clicking opens the goto time dialog
181 - right-clicking and clicking just toggle between remaining and
183 CONNECT( timeLabel, timeLabelClicked(), this, toggleTimeDisplay() );
184 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
185 CONNECT( timeLabel, timeLabelDoubleClicked(), this, toggleTimeDisplay() );
187 /* Speed Label behaviour:
188 - right click gives the vertical speed slider */
189 CONNECT( speedLabel, customContextMenuRequested( QPoint ),
190 this, showSpeedMenu( QPoint ) );
192 /**********************
193 * Systray Management *
194 **********************/
196 bool b_createSystray = false;
197 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
198 if( config_GetInt( p_intf, "qt-start-minimized") )
200 if( b_systrayAvailable )
202 b_createSystray = true;
203 hide(); //FIXME BUG HERE
205 else msg_Warn( p_intf, "You can't minize if you haven't a system "
208 if( config_GetInt( p_intf, "qt-system-tray") )
209 b_createSystray = true;
211 if( b_systrayAvailable && b_createSystray )
214 if( config_GetInt( p_intf, "qt-minimal-view" ) )
217 /********************
219 ********************/
220 MainInputManager::getInstance( p_intf );
222 /********************
224 ********************/
225 /* Connect the input manager to the GUI elements it manages */
227 /* It is also connected to the control->slider, see the ControlsWidget */
228 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
229 this, setDisplayPosition( float, int, int ) );
230 /* Change the SpeedRate in the Status */
231 CONNECT( THEMIM->getIM(), rateChanged( int ), this, setRate( int ) );
234 * Connects on nameChanged()
235 * Those connects are not merged because different options can trigger
238 /* Naming in the controller statusbar */
239 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
240 setName( QString ) );
241 /* and in the systray */
244 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
245 updateSystrayTooltipName( QString ) );
247 /* and in the title of the controller */
248 if( config_GetInt( p_intf, "qt-name-in-title" ) )
250 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
251 setVLCWindowsTitle( QString ) );
255 * CONNECTS on PLAY_STATUS
257 /* Status on the main controller */
258 CONNECT( THEMIM->getIM(), statusChanged( int ), this, setStatus( int ) );
259 /* and in the systray */
262 CONNECT( THEMIM->getIM(), statusChanged( int ), this,
263 updateSystrayTooltipStatus( int ) );
268 ON_TIMEOUT( updateOnTimer() );
269 //ON_TIMEOUT( debug() );
274 var_Create( p_intf, "interaction", VLC_VAR_ADDRESS );
275 var_AddCallback( p_intf, "interaction", InteractCallback, this );
276 p_intf->b_interaction = VLC_TRUE;
278 /* Register callback for the intf-popupmenu variable */
279 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
280 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
281 if( p_playlist != NULL )
283 var_AddCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
284 var_AddCallback( p_playlist, "intf-show", IntfShowCB, p_intf );
285 vlc_object_release( p_playlist );
288 /* VideoWidget connect mess to avoid different threads speaking to each other */
289 CONNECT( this, askReleaseVideo( void * ), this, releaseVideoSlot( void * ) );
290 CONNECT( this, askVideoToResize( unsigned int, unsigned int ),
291 videoWidget, SetSizing( unsigned int, unsigned int ) );
292 CONNECT( this, askUpdate(), this, doComponentsUpdate() );
294 CONNECT( dockPL, topLevelChanged( bool ), this, doComponentsUpdate() );
295 CONNECT( controls, advancedControlsToggled( bool ),
296 this, doComponentsUpdate() );
298 move( settings->value( "pos", QPoint( 0, 0 ) ).toPoint() );
300 QSize newSize = settings->value( "size", QSize( 350, 60 ) ).toSize();
301 if( newSize.isValid() )
307 msg_Warn( p_intf, "Invalid size in constructor" );
310 int tgPlay = settings->value( "playlist-visible", 0 ).toInt();
311 settings->endGroup();
322 MainInterface::~MainInterface()
324 msg_Dbg( p_intf, "Destroying the main interface" );
326 if( playlistWidget ) playlistWidget->savingSettings( settings );
327 if( ExtendedDialog::exists() )
328 ExtendedDialog::getInstance( p_intf )->savingSettings();
330 settings->beginGroup( "MainWindow" );
331 settings->setValue( "playlist-floats", (int)(dockPL->isFloating()) );
332 settings->setValue( "playlist-visible", (int)playlistVisible );
333 settings->setValue( "adv-controls",
334 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
335 settings->setValue( "pos", pos() );
336 settings->setValue( "size", size() );
338 settings->setValue( "backgroundSize", bgWidget->size() );
340 settings->endGroup();
343 /* Unregister callback for the intf-popupmenu variable */
344 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
345 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
346 if( p_playlist != NULL )
348 var_DelCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
349 var_DelCallback( p_playlist, "intf-show", IntfShowCB, p_intf );
350 vlc_object_release( p_playlist );
353 p_intf->b_interaction = VLC_FALSE;
354 var_DelCallback( p_intf, "interaction", InteractCallback, this );
356 p_intf->pf_request_window = NULL;
357 p_intf->pf_release_window = NULL;
358 p_intf->pf_control_window = NULL;
359 p_intf->p_sys->p_mi = NULL;
362 /*****************************
364 *****************************/
367 * Give the decorations of the Main Window a correct Name.
368 * If nothing is given, set it to VLC...
370 void MainInterface::setVLCWindowsTitle( QString aTitle )
372 if( aTitle.isEmpty() )
374 setWindowTitle( qtr( "VLC media player" ) );
378 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
382 void MainInterface::handleMainUi( QSettings *settings )
384 /* Create the main Widget and the mainLayout */
385 QWidget *main = new QWidget;
386 setCentralWidget( main );
387 mainLayout = new QVBoxLayout( main );
389 /* Margins, spacing */
390 main->setContentsMargins( 0, 0, 0, 0 );
391 // main->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
392 mainLayout->setMargin( 0 );
394 /* Create the CONTROLS Widget */
395 /* bool b_shiny = config_GetInt( p_intf, "qt-blingbling" ); */
396 controls = new ControlsWidget( p_intf, this,
397 settings->value( "adv-controls", false ).toBool(),
398 config_GetInt( p_intf, "qt-blingbling" ) );
400 /* Add the controls Widget to the main Widget */
401 mainLayout->insertWidget( 0, controls );
403 /* Create the Speed Control Widget */
404 speedControl = new SpeedControlWidget( p_intf );
405 speedControlMenu = new QMenu( this );
407 QWidgetAction *widgetAction = new QWidgetAction( speedControl );
408 widgetAction->setDefaultWidget( speedControl );
409 speedControlMenu->addAction( widgetAction );
412 /* Disabled for now, they SUCK */
414 visualSelector = new VisualSelector( p_intf );
415 mainLayout->insertWidget( 0, visualSelector );
416 visualSelector->hide();
419 /* And video Outputs */
420 if( alwaysVideoFlag )
422 bgWidget = new BackgroundWidget( p_intf );
424 settings->value( "backgroundSize", QSize( 300, 150 ) ).toSize() );
425 bgWidget->updateGeometry();
426 mainLayout->insertWidget( 0, bgWidget );
427 CONNECT( this, askBgWidgetToToggle(), bgWidget, toggle() );
430 if( videoEmbeddedFlag )
432 videoWidget = new VideoWidget( p_intf );
433 mainLayout->insertWidget( 0, videoWidget );
435 p_intf->pf_request_window = ::DoRequest;
436 p_intf->pf_release_window = ::DoRelease;
437 p_intf->pf_control_window = ::DoControl;
440 /* Finish the sizing */
444 inline void MainInterface::privacy()
447 * Ask for the network policy on FIRST STARTUP
449 if( config_GetInt( p_intf, "qt-privacy-ask") )
451 QList<ConfigControl *> controls;
452 if( privacyDialog( controls ) == QDialog::Accepted )
454 QList<ConfigControl *>::Iterator i;
455 for( i = controls.begin() ; i != controls.end() ; i++ )
457 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
458 c->doApply( p_intf );
461 config_PutInt( p_intf, "qt-privacy-ask" , 0 );
462 config_SaveConfigFile( p_intf, NULL );
467 int MainInterface::privacyDialog( QList<ConfigControl *> controls )
469 QDialog *privacy = new QDialog( this );
471 privacy->setWindowTitle( qtr( "Privacy and Network policies" ) );
473 QGridLayout *gLayout = new QGridLayout( privacy );
475 QGroupBox *blabla = new QGroupBox( qtr( "Privacy and Network Warning" ) );
476 QGridLayout *blablaLayout = new QGridLayout( blabla );
477 QLabel *text = new QLabel( qtr(
478 "<p>The <i>VideoLAN Team</i> doesn't like when an application goes "
479 "online without authorization.</p>\n "
480 "<p><i>VLC media player</i> can request limited information on "
481 "the Internet, especially to get CD covers and songs metadata or to know "
482 "if updates are available.</p>\n"
483 "<p><i>VLC media player</i> <b>DOES NOT</b> send or collect <b>ANY</b> "
484 "information, even anonymously, about your usage.</p>\n"
485 "<p>Therefore please check the following options, the default being "
486 "almost no access on the web.</p>\n") );
487 text->setWordWrap( true );
488 text->setTextFormat( Qt::RichText );
490 blablaLayout->addWidget( text, 0, 0 ) ;
492 QGroupBox *options = new QGroupBox;
493 QGridLayout *optionsLayout = new QGridLayout( options );
495 gLayout->addWidget( blabla, 0, 0, 1, 3 );
496 gLayout->addWidget( options, 1, 0, 1, 3 );
497 module_config_t *p_config;
498 ConfigControl *control;
501 #define CONFIG_GENERIC( option, type ) \
502 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
505 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
506 p_config, options, false, optionsLayout, line ); \
507 controls.append( control ); \
510 #define CONFIG_GENERIC_NOBOOL( 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, optionsLayout, line ); \
516 controls.append( control ); \
519 CONFIG_GENERIC( "album-art", IntegerList ); line++;
520 CONFIG_GENERIC_NOBOOL( "fetch-meta", Bool ); line++;
522 CONFIG_GENERIC_NOBOOL( "qt-updates-notif", Bool );
524 QPushButton *ok = new QPushButton( qtr( "Ok" ) );
526 gLayout->addWidget( ok, 2, 2 );
528 CONNECT( ok, clicked(), privacy, accept() );
529 return privacy->exec();
532 //FIXME remove me at the end...
533 void MainInterface::debug()
535 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
536 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
539 /**********************************************************************
540 * Handling of sizing of the components
541 **********************************************************************/
543 /* This function is probably wrong, but we don't have many many choices...
544 Since we can't know from the playlist Widget if we are inside a dock or not,
545 because the playlist Widget can be called by THEDP, as a separate windows for
547 Maybe the other solution is to redefine the sizeHint() of the playlist and
548 ask _parent->isFloating()...
549 If you think this would be better, please FIXME it...
551 QSize MainInterface::sizeHint() const
553 int nwidth = controls->sizeHint().width();
554 int nheight = controls->isVisible() ?
555 controls->size().height()
556 + menuBar()->size().height()
557 + statusBar()->size().height()
560 msg_Dbg( p_intf, "1 %i %i", nheight, nwidth );
561 if( VISIBLE( bgWidget ) )
563 nheight += bgWidget->size().height();
564 nwidth = bgWidget->size().width();
565 msg_Dbg( p_intf, "1b %i %i", nheight, nwidth );
567 else if( videoIsActive )
569 nheight += videoWidget->size().height();
570 nwidth = videoWidget->size().width();
571 msg_Dbg( p_intf, "2 %i %i", nheight, nwidth );
573 if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget() )
575 nheight += dockPL->size().height();
576 nwidth = __MAX( nwidth, dockPL->size().width() );
577 msg_Dbg( p_intf, "3 %i %i", nheight, nwidth );
579 msg_Dbg( p_intf, "4 %i %i", nheight, nwidth );
580 return QSize( nwidth, nheight );
584 /* FIXME This is dead code and need to be removed AT THE END */
585 void MainInterface::resizeEvent( QResizeEvent *e )
588 videoWidget->widgetSize.setWidth( e->size().width() - addSize.width() );
589 if( videoWidget && videoIsActive && videoWidget->widgetSize.height() > 1 )
591 SET_WH( videoWidget, e->size().width() - addSize.width(),
592 e->size().height() - addSize.height() );
593 videoWidget->updateGeometry();
595 if( VISIBLE( playlistWidget ) )
597 // SET_WH( playlistWidget , e->size().width() - addSize.width(),
598 // e->size().height() - addSize.height() );
599 playlistWidget->updateGeometry();
604 /****************************************************************************
605 * Small right-click menu for rate control
606 ****************************************************************************/
607 void MainInterface::showSpeedMenu( QPoint pos )
609 speedControlMenu->exec( QCursor::pos() - pos
610 + QPoint( 0, speedLabel->height() ) );
613 /****************************************************************************
615 ****************************************************************************/
616 class SetVideoOnTopQtEvent : public QEvent
619 SetVideoOnTopQtEvent( bool _onTop ) :
620 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
632 /* function called from ::DoRequest in order to show a nice VideoWidget
634 void *MainInterface::requestVideo( vout_thread_t *p_nvout, int *pi_x,
635 int *pi_y, unsigned int *pi_width,
636 unsigned int *pi_height )
638 bool bgWasVisible = false;
640 /* Request the videoWidget */
641 void *ret = videoWidget->request( p_nvout,pi_x, pi_y, pi_width, pi_height );
642 if( ret ) /* The videoWidget is available */
644 /* Did we have a bg ? Hide it! */
645 if( VISIBLE( bgWidget) )
648 emit askBgWidgetToToggle();
651 /*if( THEMIM->getIM()->hasVideo() || !bgWasVisible )
653 videoWidget->widgetSize = QSize( *pi_width, *pi_height );
655 else /* Background widget available, use its size */
657 /* Ok, our visualizations are bad, so don't do this for the moment
658 * use the requested size anyway */
659 // videoWidget->widgetSize = bgWidget->widgeTSize;
660 /* videoWidget->widgetSize = QSize( *pi_width, *pi_height );
663 videoIsActive = true;
665 emit askVideoToResize( *pi_width, *pi_height );
671 void MainInterface::releaseVideo( void *p_win )
673 emit askReleaseVideo( p_win );
676 void MainInterface::releaseVideoSlot( void *p_win )
678 videoWidget->release( p_win );
681 if( bgWidget )// WORONG
684 videoIsActive = false;
688 int MainInterface::controlVideo( void *p_window, int i_query, va_list args )
690 int i_ret = VLC_EGENERIC;
695 unsigned int *pi_width = va_arg( args, unsigned int * );
696 unsigned int *pi_height = va_arg( args, unsigned int * );
697 *pi_width = videoWidget->width();
698 *pi_height = videoWidget->height();
704 unsigned int i_width = va_arg( args, unsigned int );
705 unsigned int i_height = va_arg( args, unsigned int );
706 emit askVideoToResize( i_width, i_height );
712 case VOUT_SET_STAY_ON_TOP:
714 int i_arg = va_arg( args, int );
715 QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
720 msg_Warn( p_intf, "unsupported control query" );
726 /*****************************************************************************
727 * Playlist, Visualisation and Menus handling
728 *****************************************************************************/
730 * Toggle the playlist widget or dialog
732 void MainInterface::togglePlaylist()
735 If no playlist exist, then create one and attach it to the DockPL*/
736 if( !playlistWidget )
738 playlistWidget = new PlaylistWidget( p_intf, settings, dockPL );
740 /* Add it to the parent DockWidget */
741 dockPL->setWidget( playlistWidget );
743 /* Add the dock to the main Interface */
744 addDockWidget( Qt::BottomDockWidgetArea, dockPL );
746 /* Make the playlist floating is requested. Default is not. */
747 settings->beginGroup( "MainWindow" );
748 if( settings->value( "playlist-floats", 1 ).toInt() )
750 msg_Dbg( p_intf, "we don't want the playlist inside");
751 dockPL->setFloating( true );
753 settings->endGroup();
754 settings->beginGroup( "playlist" );
755 dockPL->move( settings->value( "pos", QPoint( 0,0 ) ).toPoint() );
756 QSize newSize = settings->value( "size", QSize( 400, 300 ) ).toSize();
757 if( newSize.isValid() )
758 dockPL->resize( newSize );
759 settings->endGroup();
762 playlistVisible = true;
766 /* toggle the visibility of the playlist */
768 resize( sizeHint() );
769 playlistVisible = !playlistVisible;
773 /* Function called from the menu to undock the playlist */
774 void MainInterface::undockPlaylist()
776 dockPL->setFloating( true );
777 resize( sizeHint() );
780 void MainInterface::toggleMinimalView()
782 TOGGLEV( menuBar() );
784 TOGGLEV( statusBar() );
785 doComponentsUpdate();
788 /* Video widget cannot do this synchronously as it runs in another thread */
789 /* Well, could it, actually ? Probably dangerous ... */
790 void MainInterface::doComponentsUpdate()
792 resize( sizeHint() );
793 msg_Dbg( p_intf, "Updating the geometry" );
797 /* toggling advanced controls buttons */
798 void MainInterface::toggleAdvanced()
800 controls->toggleAdvanced();
803 /* Get the visibility status of the controls (hidden or not, advanced or not) */
804 int MainInterface::getControlsVisibilityStatus()
806 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
807 + CONTROLS_ADVANCED * controls->b_advancedVisible );
811 void MainInterface::visual()
813 if( !VISIBLE( visualSelector) )
815 visualSelector->show();
816 if( !THEMIM->getIM()->hasVideo() )
818 /* Show the background widget */
820 visualSelectorEnabled = true;
824 /* Stop any currently running visualization */
825 visualSelector->hide();
826 visualSelectorEnabled = false;
828 doComponentsUpdate();
832 /************************************************************************
834 ************************************************************************/
835 void MainInterface::setDisplayPosition( float pos, int time, int length )
837 char psz_length[MSTRTIME_MAX_SIZE], psz_time[MSTRTIME_MAX_SIZE];
838 secstotimestr( psz_length, length );
839 secstotimestr( psz_time, ( b_remainingTime && length ) ? length - time
843 timestr.sprintf( "%s/%s", psz_time,
844 ( !length && time ) ? "--:--" : psz_length );
846 /* Add a minus to remaining time*/
847 if( b_remainingTime && length ) timeLabel->setText( " -"+timestr+" " );
848 else timeLabel->setText( " "+timestr+" " );
851 void MainInterface::toggleTimeDisplay()
853 b_remainingTime = !b_remainingTime;
856 void MainInterface::setName( QString name )
858 input_name = name; /* store it for the QSystray use */
859 /* Display it in the status bar, but also as a Tooltip in case it doesn't
861 nameLabel->setText( " " + name + " " );
862 nameLabel->setToolTip( " " + name +" " );
865 void MainInterface::setStatus( int status )
867 /* Forward the status to the controls to toggle Play/Pause */
868 controls->setStatus( status );
869 /* And in the systray for the menu */
871 QVLCMenu::updateSystrayMenu( this, p_intf );
874 void MainInterface::setRate( int rate )
877 str.setNum( ( 1000 / (double)rate ), 'f', 2 );
879 speedLabel->setText( str );
880 speedControl->updateControls( rate );
883 void MainInterface::updateOnTimer()
885 if( intf_ShouldDie( p_intf ) )
887 QApplication::closeAllWindows();
888 QApplication::quit();
891 if( need_components_update )
893 doComponentsUpdate();
894 need_components_update = false;
899 /*****************************************************************************
900 * Systray Icon and Systray Menu
901 *****************************************************************************/
904 * Create a SystemTray icon and a menu that would go with it.
905 * Connects to a click handler on the icon.
907 void MainInterface::createSystray()
910 if( QDate::currentDate().dayOfYear() >= 354 )
911 iconVLC = QIcon( QPixmap( ":/vlc128-christmas.png" ) );
913 iconVLC = QIcon( QPixmap( ":/vlc128.png" ) );
914 sysTray = new QSystemTrayIcon( iconVLC, this );
915 sysTray->setToolTip( qtr( "VLC media player" ));
917 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
918 systrayMenu->setIcon( iconVLC );
920 QVLCMenu::updateSystrayMenu( this, p_intf, true );
923 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
924 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
928 * Updates the Systray Icon's menu and toggle the main interface
930 void MainInterface::toggleUpdateSystrayMenu()
932 /* If hidden, show it */
938 else if( isMinimized() )
948 /* check if any visible window is above vlc in the z-order,
949 * but ignore the ones always on top */
952 wi.cbSize = sizeof( WINDOWINFO );
953 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
954 hwnd && !IsWindowVisible( hwnd );
955 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
956 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
957 (wi.dwExStyle&WS_EX_TOPMOST) )
959 if( isActiveWindow() )
969 QVLCMenu::updateSystrayMenu( this, p_intf );
972 void MainInterface::handleSystrayClick(
973 QSystemTrayIcon::ActivationReason reason )
977 case QSystemTrayIcon::Trigger:
978 toggleUpdateSystrayMenu();
980 case QSystemTrayIcon::MiddleClick:
981 sysTray->showMessage( qtr( "VLC media player" ),
982 qtr( "Control menu for the player" ),
983 QSystemTrayIcon::Information, 3000 );
989 * Updates the name of the systray Icon tooltip.
990 * Doesn't check if the systray exists, check before you call it.
992 void MainInterface::updateSystrayTooltipName( QString name )
996 sysTray->setToolTip( qtr( "VLC media player" ) );
1000 sysTray->setToolTip( name );
1001 if( notificationEnabled && ( isHidden() || isMinimized() ) )
1003 sysTray->showMessage( qtr( "VLC media player" ), name,
1004 QSystemTrayIcon::NoIcon, 3000 );
1010 * Updates the status of the systray Icon tooltip.
1011 * Doesn't check if the systray exists, check before you call it.
1013 void MainInterface::updateSystrayTooltipStatus( int i_status )
1020 sysTray->setToolTip( qtr( "VLC media player" ) );
1025 sysTray->setToolTip( input_name );
1030 sysTray->setToolTip( input_name + " - "
1037 /************************************************************************
1039 ************************************************************************/
1040 void MainInterface::dropEvent(QDropEvent *event)
1042 const QMimeData *mimeData = event->mimeData();
1044 /* D&D of a subtitles file, add it on the fly */
1045 if( mimeData->urls().size() == 1 )
1047 if( THEMIM->getIM()->hasInput() )
1049 if( input_AddSubtitles( THEMIM->getInput(),
1050 qtu( mimeData->urls()[0].toString() ),
1053 event->acceptProposedAction();
1059 foreach( QUrl url, mimeData->urls() ) {
1060 QString s = url.toString();
1061 if( s.length() > 0 ) {
1062 playlist_Add( THEPL, qtu(s), NULL,
1063 PLAYLIST_APPEND | (first ? PLAYLIST_GO:0),
1064 PLAYLIST_END, VLC_TRUE, VLC_FALSE );
1068 event->acceptProposedAction();
1070 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1072 event->acceptProposedAction();
1074 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1076 event->acceptProposedAction();
1078 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1083 /************************************************************************
1085 ************************************************************************/
1086 void MainInterface::customEvent( QEvent *event )
1089 if( event->type() == PLDockEvent_Type )
1091 PlaylistDialog::killInstance();
1092 playlistEmbeddedFlag = true;
1094 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1099 if ( event->type() == SetVideoOnTopEvent_Type )
1101 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1102 if( p_event->OnTop() )
1103 setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
1105 setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint);
1106 show(); /* necessary to apply window flags?? */
1110 void MainInterface::keyPressEvent( QKeyEvent *e )
1112 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() & Qt::Key_H )
1113 && menuBar()->isHidden() )
1115 toggleMinimalView();
1119 int i_vlck = qtEventToVLCKey( e );
1122 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1129 void MainInterface::wheelEvent( QWheelEvent *e )
1131 int i_vlckey = qtWheelEventToVLCKey( e );
1132 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1136 void MainInterface::closeEvent( QCloseEvent *e )
1142 void MainInterface::toggleFullScreen( void )
1144 if( isFullScreen() )
1150 /*****************************************************************************
1152 *****************************************************************************/
1153 static int InteractCallback( vlc_object_t *p_this,
1154 const char *psz_var, vlc_value_t old_val,
1155 vlc_value_t new_val, void *param )
1157 intf_dialog_args_t *p_arg = new intf_dialog_args_t;
1158 p_arg->p_dialog = (interaction_dialog_t *)(new_val.p_address);
1159 DialogEvent *event = new DialogEvent( INTF_DIALOG_INTERACTION, 0, p_arg );
1160 QApplication::postEvent( THEDP, static_cast<QEvent*>(event) );
1164 /*****************************************************************************
1165 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1166 * We don't show the menu directly here because we don't want the
1167 * caller to block for a too long time.
1168 *****************************************************************************/
1169 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1170 vlc_value_t old_val, vlc_value_t new_val, void *param )
1172 intf_thread_t *p_intf = (intf_thread_t *)param;
1173 msg_Dbg( p_this, "Menu Requested" ); // DEBUG to track the non disparition of the menu...
1175 if( p_intf->pf_show_dialog )
1177 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1178 new_val.b_bool, 0 );
1184 /*****************************************************************************
1185 * IntfShowCB: callback triggered by the intf-show playlist variable.
1186 *****************************************************************************/
1187 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1188 vlc_value_t old_val, vlc_value_t new_val, void *param )
1190 intf_thread_t *p_intf = (intf_thread_t *)param;
1191 msg_Dbg( p_this, "Intf Show Requested" ); // DEBUG to track the non disparition of the menu...
1192 //p_intf->p_sys->b_intf_show = VLC_TRUE;