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>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
26 #include "main_interface.hpp"
27 #include "input_manager.hpp"
28 #include "util/qvlcframe.hpp"
29 #include "util/customwidgets.hpp"
30 #include "dialogs_provider.hpp"
31 #include "components/interface_widgets.hpp"
32 #include "components/playlist/playlist.hpp"
33 #include "dialogs/extended.hpp"
34 #include "dialogs/playlist.hpp"
38 #include <QCloseEvent>
39 #include <QPushButton>
43 #include <QSystemTrayIcon>
48 #include <QWidgetAction>
49 #include <QDockWidget>
57 #define SET_WIDTH(i,j) i->widgetSize.setWidth(j)
58 #define SET_HEIGHT(i,j) i->widgetSize.setHeight(j)
59 #define SET_WH( i,j,k) i->widgetSize.setWidth(j); i->widgetSize.setHeight(k);
61 #define DS(i) i.width(),i.height()
63 /* Callback prototypes */
64 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
65 vlc_value_t old_val, vlc_value_t new_val, void *param );
66 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
67 vlc_value_t old_val, vlc_value_t new_val, void *param );
68 static int InteractCallback( vlc_object_t *, const char *, vlc_value_t,
71 static void *DoRequest( intf_thread_t *p_intf, vout_thread_t *p_vout,
72 int *pi1, int *pi2, unsigned int*pi3,unsigned int*pi4)
74 return p_intf->p_sys->p_mi->requestVideo( p_vout, pi1, pi2, pi3, pi4 );
76 static void DoRelease( intf_thread_t *p_intf, void *p_win )
78 return p_intf->p_sys->p_mi->releaseVideo( p_win );
80 static int DoControl( intf_thread_t *p_intf, void *p_win, int i_q, va_list a )
82 return p_intf->p_sys->p_mi->controlVideo( p_win, i_q, a );
85 MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
87 /* Variables initialisation */
88 // need_components_update = false;
89 bgWidget = NULL; videoWidget = NULL; playlistWidget = NULL;
90 videoIsActive = false;
94 * Ask for the network policy on FIRST STARTUP
96 if( config_GetInt( p_intf, "privacy-ask") )
98 QList<ConfigControl *> controls;
99 if( privacyDialog( controls ) == QDialog::Accepted )
101 QList<ConfigControl *>::Iterator i;
102 for( i = controls.begin() ; i != controls.end() ; i++ )
104 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
105 c->doApply( p_intf );
108 config_PutInt( p_intf, "privacy-ask" , 0 );
109 config_SaveConfigFile( p_intf, NULL );
114 * Configuration and settings
116 settings = new QSettings( "vlc", "vlc-qt-interface" );
117 settings->beginGroup( "MainWindow" );
120 setFocusPolicy( Qt::StrongFocus );
121 setAcceptDrops( true );
122 setWindowIcon( QApplication::windowIcon() );
123 setWindowOpacity( config_GetFloat( p_intf, "qt-opacity" ) );
125 /* Set The Video In emebedded Mode or not */
126 videoEmbeddedFlag = false;
127 if( config_GetInt( p_intf, "embedded-video" ) ) videoEmbeddedFlag = true;
129 /* Are we in the enhanced always-video mode or not ? */
130 alwaysVideoFlag = false;
131 if( videoEmbeddedFlag && config_GetInt( p_intf, "qt-always-video" ) )
132 alwaysVideoFlag = true;
134 /* Set the other interface settings */
135 //TODO: I don't like that code
136 visualSelectorEnabled = settings->value( "visual-selector", false ).toBool();
137 notificationEnabled = config_GetInt( p_intf, "qt-notification" )
140 /**************************
141 * UI and Widgets design
142 **************************/
143 setVLCWindowsTitle();
144 handleMainUi( settings );
146 /* Create a Dock to get the playlist */
147 dockPL = new QDockWidget( qtr( "Playlist" ), this );
148 dockPL->setSizePolicy( QSizePolicy::Preferred,
149 QSizePolicy::MinimumExpanding );
150 dockPL->setFeatures( QDockWidget::AllDockWidgetFeatures );
151 dockPL->setAllowedAreas( Qt::LeftDockWidgetArea
152 | Qt::RightDockWidgetArea
153 | Qt::BottomDockWidgetArea );
158 QVLCMenu::createMenuBar( this, p_intf, visualSelectorEnabled );
164 /* Widgets Creation*/
165 b_remainingTime = false;
166 timeLabel = new TimeLabel;
167 nameLabel = new QLabel;
168 nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
169 | Qt::TextSelectableByKeyboard );
170 speedLabel = new QLabel( "1.00x" );
171 speedLabel->setContextMenuPolicy ( Qt::CustomContextMenu );
173 /* Styling those labels */
174 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
175 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
176 nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
178 /* and adding those */
179 statusBar()->addWidget( nameLabel, 8 );
180 statusBar()->addPermanentWidget( speedLabel, 0 );
181 statusBar()->addPermanentWidget( timeLabel, 2 );
183 /* timeLabel behaviour:
184 - double clicking opens the goto time dialog
185 - right-clicking and clicking just toggle between remaining and
187 CONNECT( timeLabel, timeLabelClicked(), this, toggleTimeDisplay() );
188 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
189 CONNECT( timeLabel, timeLabelDoubleClicked(), this, toggleTimeDisplay() );
191 /* Speed Label behaviour:
192 - right click gives the vertical speed slider */
193 CONNECT( speedLabel, customContextMenuRequested( QPoint ),
194 this, showSpeedMenu( QPoint ) );
196 /**********************
197 * Systray Management *
198 **********************/
200 bool b_createSystray = false;
201 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
202 if( config_GetInt( p_intf, "qt-start-minimized") )
204 if( b_systrayAvailable ){
205 b_createSystray = true;
206 hide(); //FIXME BUG HERE
208 else msg_Warn( p_intf, "You can't minize if you haven't a system "
211 if( config_GetInt( p_intf, "qt-system-tray") )
212 b_createSystray = true;
214 if( b_systrayAvailable && b_createSystray )
217 if( config_GetInt( p_intf, "qt-minimal-view" ) )
220 /* Init input manager */
221 MainInputManager::getInstance( p_intf );
222 ON_TIMEOUT( updateOnTimer() );
223 //ON_TIMEOUT( debug() ):;
225 /********************
227 ********************/
229 /* Connect the input manager to the GUI elements it manages */
230 /* It is also connected to the control->slider, see the ControlsWidget */
231 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
232 this, setDisplayPosition( float, int, int ) );
234 CONNECT( THEMIM->getIM(), rateChanged( int ), this, setRate( int ) );
237 * Connects on nameChanged()
239 /* Naming in the controller statusbar */
240 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
241 setName( QString ) );
242 /* and in the systray */
245 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
246 updateSystrayTooltipName( QString ) );
248 /* and in the title of the controller */
249 if( config_GetInt( p_intf, "qt-name-in-title" ) )
251 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
252 setVLCWindowsTitle( QString ) );
255 /** CONNECTS on PLAY_STATUS **/
256 /* Status on the main controller */
257 CONNECT( THEMIM->getIM(), statusChanged( int ), this, setStatus( int ) );
258 /* and in the systray */
261 CONNECT( THEMIM->getIM(), statusChanged( int ), this,
262 updateSystrayTooltipStatus( int ) );
268 var_Create( p_intf, "interaction", VLC_VAR_ADDRESS );
269 var_AddCallback( p_intf, "interaction", InteractCallback, this );
270 p_intf->b_interaction = VLC_TRUE;
272 /* Register callback for the intf-popupmenu variable */
273 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
274 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
275 if( p_playlist != NULL )
277 var_AddCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
278 var_AddCallback( p_playlist, "intf-show", IntfShowCB, p_intf );
279 vlc_object_release( p_playlist );
282 CONNECT( this, askReleaseVideo( void * ), this, releaseVideoSlot( void * ) );
284 CONNECT( dockPL, topLevelChanged( bool ), this, doComponentsUpdate() );
285 CONNECT( controls, advancedControlsToggled( bool ),
286 this, doComponentsUpdate() );
289 settings->endGroup();
292 MainInterface::~MainInterface()
294 if( playlistWidget ) playlistWidget->savingSettings( settings );
295 if( ExtendedDialog::exists() )
296 ExtendedDialog::getInstance( p_intf )->savingSettings();
298 settings->beginGroup( "MainWindow" );
299 settings->setValue( "playlist-floats", dockPL->isFloating() );
300 settings->setValue( "adv-controls",
301 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
302 settings->setValue( "pos", pos() );
304 settings->endGroup();
307 /* Unregister callback for the intf-popupmenu variable */
308 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
309 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
310 if( p_playlist != NULL )
312 var_DelCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
313 var_DelCallback( p_playlist, "intf-show", IntfShowCB, p_intf );
314 vlc_object_release( p_playlist );
317 p_intf->b_interaction = VLC_FALSE;
318 var_DelCallback( p_intf, "interaction", InteractCallback, this );
320 p_intf->pf_request_window = NULL;
321 p_intf->pf_release_window = NULL;
322 p_intf->pf_control_window = NULL;
325 /*****************************
327 *****************************/
330 * Give the decorations of the Main Window a correct Name.
331 * If nothing is given, set it to VLC...
333 void MainInterface::setVLCWindowsTitle( QString aTitle )
335 if( aTitle.isEmpty() )
337 setWindowTitle( qtr( "VLC media player" ) );
341 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
345 void MainInterface::handleMainUi( QSettings *settings )
347 /* Create the main Widget and the mainLayout */
348 QWidget *main = new QWidget;
349 setCentralWidget( main );
350 mainLayout = new QVBoxLayout( main );
352 /* Margins, spacing */
353 main->setContentsMargins( 0, 0, 0, 0 );
354 mainLayout->setMargin( 0 );
356 /* Create the CONTROLS Widget */
357 /* bool b_shiny = config_GetInt( p_intf, "qt-blingbling" ); */
358 controls = new ControlsWidget( p_intf, this,
359 settings->value( "adv-controls", false ).toBool(),
360 config_GetInt( p_intf, "qt-blingbling" ) );
362 /* Add the controls Widget to the main Widget */
363 mainLayout->insertWidget( 0, controls );
365 /* Create the Speed Control Widget */
366 speedControl = new SpeedControlWidget( p_intf );
367 speedControlMenu = new QMenu( this );
369 QWidgetAction *widgetAction = new QWidgetAction( speedControl );
370 widgetAction->setDefaultWidget( speedControl );
371 speedControlMenu->addAction( widgetAction );
374 /* Disabled for now, they SUCK */
376 visualSelector = new VisualSelector( p_intf );
377 mainLayout->insertWidget( 0, visualSelector );
378 visualSelector->hide();
381 /* And video Outputs */
382 if( alwaysVideoFlag )
384 bgWidget = new BackgroundWidget( p_intf );
385 bgWidget->widgetSize = settings->value( "backgroundSize",
386 QSize( 300, 200 ) ).toSize();
387 bgWidget->resize( bgWidget->widgetSize );
388 bgWidget->updateGeometry();
389 mainLayout->insertWidget( 0, bgWidget );
390 CONNECT( this, askBgWidgetToToggle(), bgWidget, toggle() );
393 if( videoEmbeddedFlag )
395 videoWidget = new VideoWidget( p_intf );
396 videoWidget->widgetSize = QSize( 1, 1 );
397 //videoWidget->resize( videoWidget->widgetSize );
398 mainLayout->insertWidget( 0, videoWidget );
400 p_intf->pf_request_window = ::DoRequest;
401 p_intf->pf_release_window = ::DoRelease;
402 p_intf->pf_control_window = ::DoControl;
405 /* Finish the sizing */
409 int MainInterface::privacyDialog( QList<ConfigControl *> controls )
411 QDialog *privacy = new QDialog( this );
413 privacy->setWindowTitle( qtr( "Privacy and Network policies" ) );
415 QGridLayout *gLayout = new QGridLayout( privacy );
417 QGroupBox *blabla = new QGroupBox( qtr( "Privacy and Network Warning" ) );
418 QGridLayout *blablaLayout = new QGridLayout( blabla );
419 QLabel *text = new QLabel( qtr(
420 "<p>The <i>VideoLAN Team</i> doesn't like when an application goes "
421 "online without authorisation.</p>\n "
422 "<p><i>VLC media player</i> can request limited information on "
423 "Internet, espically to get CD Covers and songs metadata or to know "
424 "if updates are available.</p>\n"
425 "<p><i>VLC media player</i> <b>DOES NOT</b> send or collect <b>ANY</b> "
426 "information, even anonymously about your "
428 "<p>Therefore please check the following options, the default being "
429 "almost no access on the web.</p>\n") );
430 text->setWordWrap( true );
431 text->setTextFormat( Qt::RichText );
433 blablaLayout->addWidget( text, 0, 0 ) ;
435 QGroupBox *options = new QGroupBox;
436 QGridLayout *optionsLayout = new QGridLayout( options );
438 gLayout->addWidget( blabla, 0, 0, 1, 3 );
439 gLayout->addWidget( options, 1, 0, 1, 3 );
440 module_config_t *p_config;
441 ConfigControl *control;
444 #define CONFIG_GENERIC( option, type ) \
445 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
448 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
449 p_config, options, false, optionsLayout, line ); \
450 controls.append( control ); \
453 #define CONFIG_GENERIC_NOBOOL( option, type ) \
454 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
457 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
458 p_config, options, optionsLayout, line ); \
459 controls.append( control ); \
462 CONFIG_GENERIC( "album-art", IntegerList ); line++;
463 CONFIG_GENERIC_NOBOOL( "fetch-meta", Bool ); line++;
464 CONFIG_GENERIC_NOBOOL( "qt-updates-notif", Bool );
466 QPushButton *ok = new QPushButton( qtr( "Ok" ) );
468 gLayout->addWidget( ok, 2, 2 );
470 CONNECT( ok, clicked(), privacy, accept() );
471 return privacy->exec();
474 //FIXME remove me at the end...
475 void MainInterface::debug()
477 msg_Dbg( p_intf, "size: %i - %i", controls->size().height(), controls->size().width() );
478 msg_Dbg( p_intf, "sizeHint: %i - %i", controls->sizeHint().height(), controls->sizeHint().width() );
481 /**********************************************************************
482 * Handling of sizing of the components
483 **********************************************************************/
485 /* This function is probably wrong, but we don't have many many choices...
486 Since we can't know from the playlist Widget if we are inside a dock or not,
487 because the playlist Widget can be called by THEDP, as a separate windows for
489 Maybe the other solution is to redefine the sizeHint() of the playlist and
490 ask _parent->isFloating()...
491 If you think this would be better, please FIXME it...
493 QSize MainInterface::sizeHint() const
495 QSize tempSize = controls->sizeHint() +
496 QSize( 100, menuBar()->size().height() + statusBar()->size().height() );
498 if( VISIBLE( bgWidget ) )
499 tempSize += bgWidget->sizeHint();
500 else if( videoIsActive )
501 tempSize += videoWidget->size();
503 if( !dockPL->isFloating() && dockPL->widget() )
504 tempSize += dockPL->widget()->size();
510 /* FIXME This is dead code and need to be removed AT THE END */
511 void MainInterface::resizeEvent( QResizeEvent *e )
514 videoWidget->widgetSize.setWidth( e->size().width() - addSize.width() );
515 if( videoWidget && videoIsActive && videoWidget->widgetSize.height() > 1 )
517 SET_WH( videoWidget, e->size().width() - addSize.width(),
518 e->size().height() - addSize.height() );
519 videoWidget->updateGeometry();
521 if( VISIBLE( playlistWidget ) )
523 // SET_WH( playlistWidget , e->size().width() - addSize.width(),
524 // e->size().height() - addSize.height() );
525 playlistWidget->updateGeometry();
530 /****************************************************************************
531 * Small right-click menu for rate control
532 ****************************************************************************/
533 void MainInterface::showSpeedMenu( QPoint pos )
535 speedControlMenu->exec( QCursor::pos() - pos
536 + QPoint( 0, speedLabel->height() ) );
539 /****************************************************************************
541 ****************************************************************************/
542 class SetVideoOnTopQtEvent : public QEvent
545 SetVideoOnTopQtEvent( bool _onTop ) :
546 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
558 void *MainInterface::requestVideo( vout_thread_t *p_nvout, int *pi_x,
559 int *pi_y, unsigned int *pi_width,
560 unsigned int *pi_height )
562 void *ret = videoWidget->request( p_nvout,pi_x, pi_y, pi_width, pi_height );
565 videoIsActive = true;
566 bool bgWasVisible = false;
568 /* Did we have a bg ? */
569 if( VISIBLE( bgWidget) )
572 emit askBgWidgetToToggle();
575 if( THEMIM->getIM()->hasVideo() || !bgWasVisible )
577 videoWidget->widgetSize = QSize( *pi_width, *pi_height );
579 else /* Background widget available, use its size */
581 /* Ok, our visualizations are bad, so don't do this for the moment
582 * use the requested size anyway */
583 // videoWidget->widgetSize = bgWidget->widgeTSize;
584 videoWidget->widgetSize = QSize( *pi_width, *pi_height );
586 videoWidget->updateGeometry(); // Needed for deinterlace
592 void MainInterface::releaseVideo( void *p_win )
594 emit askReleaseVideo( p_win );
597 void MainInterface::releaseVideoSlot( void *p_win )
599 videoWidget->release( p_win );
605 videoIsActive = false;
609 int MainInterface::controlVideo( void *p_window, int i_query, va_list args )
611 int i_ret = VLC_EGENERIC;
616 unsigned int *pi_width = va_arg( args, unsigned int * );
617 unsigned int *pi_height = va_arg( args, unsigned int * );
618 *pi_width = videoWidget->widgetSize.width();
619 *pi_height = videoWidget->widgetSize.height();
625 unsigned int i_width = va_arg( args, unsigned int );
626 unsigned int i_height = va_arg( args, unsigned int );
627 videoWidget->widgetSize = QSize( i_width, i_height );
628 videoWidget->updateGeometry();
633 case VOUT_SET_STAY_ON_TOP:
635 int i_arg = va_arg( args, int );
636 QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
641 msg_Warn( p_intf, "unsupported control query" );
647 /*****************************************************************************
648 * Playlist, Visualisation and Menus handling
649 *****************************************************************************/
651 * Toggle the playlist widget or dialog
653 void MainInterface::togglePlaylist()
656 If no playlist exist, then create one and attach it to the DockPL*/
657 if( !playlistWidget )
659 msg_Dbg( p_intf, "Creating a new playlist" );
660 playlistWidget = new PlaylistWidget( p_intf, settings );
662 CONNECT( playlistWidget, artSet( QString ),
663 bgWidget, setArt(QString) );
665 /* Add it to the parent DockWidget */
666 dockPL->setWidget( playlistWidget );
668 /* Add the dock to the main Interface */
669 addDockWidget( Qt::BottomDockWidgetArea, dockPL );
671 /* Make the playlist floating is requested. Default is not. */
672 if( settings->value( "playlist-floats", false ).toBool() );
674 msg_Dbg( p_intf, "we don't want it inside");
675 dockPL->setFloating( true );
680 /* toggle the visibility of the playlist */
682 //resize(sizeHint());
685 doComponentsUpdate();
690 /* Function called from the menu to undock the playlist */
691 void MainInterface::undockPlaylist()
693 dockPL->setFloating( true );
697 void MainInterface::toggleMinimalView()
699 TOGGLEV( menuBar() );
701 TOGGLEV( statusBar() );
705 /* Video widget cannot do this synchronously as it runs in another thread */
706 /* Well, could it, actually ? Probably dangerous ... */
707 void MainInterface::doComponentsUpdate()
712 /* toggling advanced controls buttons */
713 void MainInterface::toggleAdvanced()
715 controls->toggleAdvanced();
718 /* Get the visibility status of the controls (hidden or not, advanced or not) */
719 int MainInterface::getControlsVisibilityStatus()
721 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
722 + CONTROLS_ADVANCED * controls->b_advancedVisible );
726 void MainInterface::visual()
728 if( !VISIBLE( visualSelector) )
730 visualSelector->show();
731 if( !THEMIM->getIM()->hasVideo() )
733 /* Show the background widget */
735 visualSelectorEnabled = true;
739 /* Stop any currently running visualization */
740 visualSelector->hide();
741 visualSelectorEnabled = false;
743 doComponentsUpdate();
747 /************************************************************************
749 ************************************************************************/
750 void MainInterface::setDisplayPosition( float pos, int time, int length )
752 char psz_length[MSTRTIME_MAX_SIZE], psz_time[MSTRTIME_MAX_SIZE];
753 secstotimestr( psz_length, length );
754 secstotimestr( psz_time, ( b_remainingTime && length ) ? length - time
758 title.sprintf( "%s/%s", psz_time,
759 ( !length && time ) ? "--:--" : psz_length );
761 /* Add a minus to remaining time*/
762 if( b_remainingTime && length ) timeLabel->setText( " -"+title+" " );
763 else timeLabel->setText( " "+title+" " );
766 void MainInterface::toggleTimeDisplay()
768 b_remainingTime = !b_remainingTime;
769 //b_remainingTime = ( b_remainingTime ? false : true );
772 void MainInterface::setName( QString name )
774 input_name = name; /* store it for the QSystray use */
775 /* Display it in the status bar, but also as a Tooltip in case it doesn't
777 nameLabel->setText( " " + name + " " );
778 nameLabel->setToolTip( " " + name +" " );
781 void MainInterface::setStatus( int status )
783 /* Forward the status to the controls to toggle Play/Pause */
784 controls->setStatus( status );
785 /* And in the systray for the menu */
787 QVLCMenu::updateSystrayMenu( this, p_intf );
790 void MainInterface::setRate( int rate )
793 str.setNum( ( 1000 / (double)rate ), 'f', 2 );
795 speedLabel->setText( str );
796 speedControl->updateControls( rate );
799 void MainInterface::updateOnTimer()
802 if( intf_ShouldDie( p_intf ) )
804 QApplication::closeAllWindows();
805 QApplication::quit();
807 if( need_components_update )
809 doComponentsUpdate();
810 need_components_update = false;
814 controls->updateOnTimer();
817 /*****************************************************************************
818 * Systray Icon and Systray Menu
819 *****************************************************************************/
822 * Create a SystemTray icon and a menu that would go with it.
823 * Connects to a click handler on the icon.
825 void MainInterface::createSystray()
827 QIcon iconVLC = QIcon( QPixmap( ":/vlc128.png" ) );
828 sysTray = new QSystemTrayIcon( iconVLC, this );
829 sysTray->setToolTip( qtr( "VLC media player" ));
831 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
832 systrayMenu->setIcon( iconVLC );
834 QVLCMenu::updateSystrayMenu( this, p_intf, true );
837 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
838 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
842 * Updates the Systray Icon's menu and toggle the main interface
844 void MainInterface::toggleUpdateSystrayMenu()
846 /* If hidden, show it */
852 else if( isMinimized() )
862 /* check if any visible window is above vlc in the z-order,
863 * but ignore the ones always on top */
866 wi.cbSize = sizeof( WINDOWINFO );
867 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
868 hwnd && !IsWindowVisible( hwnd );
869 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
870 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
871 (wi.dwExStyle&WS_EX_TOPMOST) )
873 if( isActiveWindow() )
883 QVLCMenu::updateSystrayMenu( this, p_intf );
886 void MainInterface::handleSystrayClick(
887 QSystemTrayIcon::ActivationReason reason )
891 case QSystemTrayIcon::Trigger:
892 toggleUpdateSystrayMenu();
894 case QSystemTrayIcon::MiddleClick:
895 sysTray->showMessage( qtr( "VLC media player" ),
896 qtr( "Control menu for the player" ),
897 QSystemTrayIcon::Information, 3000 );
903 * Updates the name of the systray Icon tooltip.
904 * Doesn't check if the systray exists, check before you call it.
906 void MainInterface::updateSystrayTooltipName( QString name )
910 sysTray->setToolTip( qtr( "VLC media player" ) );
914 sysTray->setToolTip( name );
915 if( notificationEnabled && ( isHidden() || isMinimized() ) )
917 sysTray->showMessage( qtr( "VLC media player" ), name,
918 QSystemTrayIcon::NoIcon, 3000 );
924 * Updates the status of the systray Icon tooltip.
925 * Doesn't check if the systray exists, check before you call it.
927 void MainInterface::updateSystrayTooltipStatus( int i_status )
934 sysTray->setToolTip( qtr( "VLC media player" ) );
939 sysTray->setToolTip( input_name );
944 sysTray->setToolTip( input_name + " - "
951 /************************************************************************
953 ************************************************************************/
954 void MainInterface::dropEvent(QDropEvent *event)
956 const QMimeData *mimeData = event->mimeData();
958 /* D&D of a subtitles file, add it on the fly */
959 if( mimeData->urls().size() == 1 )
961 if( THEMIM->getIM()->hasInput() )
963 if( input_AddSubtitles( THEMIM->getInput(),
964 qtu( mimeData->urls()[0].toString() ),
967 event->acceptProposedAction();
973 foreach( QUrl url, mimeData->urls() ) {
974 QString s = url.toString();
975 if( s.length() > 0 ) {
976 playlist_Add( THEPL, qtu(s), NULL,
977 PLAYLIST_APPEND | (first ? PLAYLIST_GO:0),
978 PLAYLIST_END, VLC_TRUE, VLC_FALSE );
982 event->acceptProposedAction();
984 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
986 event->acceptProposedAction();
988 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
990 event->acceptProposedAction();
992 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
997 /************************************************************************
999 ************************************************************************/
1000 void MainInterface::customEvent( QEvent *event )
1003 if( event->type() == PLDockEvent_Type )
1005 PlaylistDialog::killInstance();
1006 playlistEmbeddedFlag = true;
1008 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1013 if ( event->type() == SetVideoOnTopEvent_Type )
1015 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1016 if( p_event->OnTop() )
1017 setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
1019 setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint);
1020 show(); /* necessary to apply window flags?? */
1024 void MainInterface::keyPressEvent( QKeyEvent *e )
1026 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() & Qt::Key_H )
1027 && menuBar()->isHidden() )
1029 toggleMinimalView();
1033 int i_vlck = qtEventToVLCKey( e );
1036 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1043 void MainInterface::wheelEvent( QWheelEvent *e )
1045 int i_vlckey = qtWheelEventToVLCKey( e );
1046 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1050 void MainInterface::closeEvent( QCloseEvent *e )
1053 vlc_object_kill( p_intf );
1054 QApplication::closeAllWindows();
1055 QApplication::quit();
1058 /*****************************************************************************
1060 *****************************************************************************/
1061 static int InteractCallback( vlc_object_t *p_this,
1062 const char *psz_var, vlc_value_t old_val,
1063 vlc_value_t new_val, void *param )
1065 intf_dialog_args_t *p_arg = new intf_dialog_args_t;
1066 p_arg->p_dialog = (interaction_dialog_t *)(new_val.p_address);
1067 DialogEvent *event = new DialogEvent( INTF_DIALOG_INTERACTION, 0, p_arg );
1068 QApplication::postEvent( THEDP, static_cast<QEvent*>(event) );
1072 /*****************************************************************************
1073 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1074 * We don't show the menu directly here because we don't want the
1075 * caller to block for a too long time.
1076 *****************************************************************************/
1077 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1078 vlc_value_t old_val, vlc_value_t new_val, void *param )
1080 intf_thread_t *p_intf = (intf_thread_t *)param;
1082 if( p_intf->pf_show_dialog )
1084 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1085 new_val.b_bool, 0 );
1091 /*****************************************************************************
1092 * IntfShowCB: callback triggered by the intf-show playlist variable.
1093 *****************************************************************************/
1094 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1095 vlc_value_t old_val, vlc_value_t new_val, void *param )
1097 intf_thread_t *p_intf = (intf_thread_t *)param;
1098 //p_intf->p_sys->b_intf_show = VLC_TRUE;