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 *****************************************************************************/
27 #include "main_interface.hpp"
28 #include "input_manager.hpp"
29 #include "util/qvlcframe.hpp"
30 #include "util/customwidgets.hpp"
31 #include "dialogs_provider.hpp"
32 #include "components/interface_widgets.hpp"
33 #include "components/playlist/playlist.hpp"
34 #include "dialogs/extended.hpp"
35 #include "dialogs/playlist.hpp"
39 #include <QCloseEvent>
40 #include <QPushButton>
44 #include <QSystemTrayIcon>
49 #include <QWidgetAction>
50 #include <QDockWidget>
58 #define SET_WIDTH(i,j) i->widgetSize.setWidth(j)
59 #define SET_HEIGHT(i,j) i->widgetSize.setHeight(j)
60 #define SET_WH( i,j,k) i->widgetSize.setWidth(j); i->widgetSize.setHeight(k);
62 #define DS(i) i.width(),i.height()
64 /* Callback prototypes */
65 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
66 vlc_value_t old_val, vlc_value_t new_val, void *param );
67 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
68 vlc_value_t old_val, vlc_value_t new_val, void *param );
69 static int InteractCallback( vlc_object_t *, const char *, vlc_value_t,
72 static void *DoRequest( intf_thread_t *p_intf, vout_thread_t *p_vout,
73 int *pi1, int *pi2, unsigned int*pi3,unsigned int*pi4)
75 return p_intf->p_sys->p_mi->requestVideo( p_vout, pi1, pi2, pi3, pi4 );
77 static void DoRelease( intf_thread_t *p_intf, void *p_win )
79 return p_intf->p_sys->p_mi->releaseVideo( p_win );
81 static int DoControl( intf_thread_t *p_intf, void *p_win, int i_q, va_list a )
83 return p_intf->p_sys->p_mi->controlVideo( p_win, i_q, a );
86 MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
88 /* Variables initialisation */
89 // need_components_update = false;
90 bgWidget = NULL; videoWidget = NULL; playlistWidget = NULL;
91 videoIsActive = false;
95 * Ask for the network policy on FIRST STARTUP
97 if( config_GetInt( p_intf, "privacy-ask") )
99 QList<ConfigControl *> controls;
100 if( privacyDialog( controls ) == QDialog::Accepted )
102 QList<ConfigControl *>::Iterator i;
103 for( i = controls.begin() ; i != controls.end() ; i++ )
105 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
106 c->doApply( p_intf );
109 config_PutInt( p_intf, "privacy-ask" , 0 );
110 config_SaveConfigFile( p_intf, NULL );
115 * Configuration and settings
117 settings = new QSettings( "vlc", "vlc-qt-interface" );
118 settings->beginGroup( "MainWindow" );
121 setFocusPolicy( Qt::StrongFocus );
122 setAcceptDrops( true );
123 setWindowIcon( QApplication::windowIcon() );
124 setWindowOpacity( config_GetFloat( p_intf, "qt-opacity" ) );
126 /* Set The Video In emebedded Mode or not */
127 videoEmbeddedFlag = false;
128 if( config_GetInt( p_intf, "embedded-video" ) ) videoEmbeddedFlag = true;
130 /* Are we in the enhanced always-video mode or not ? */
131 alwaysVideoFlag = false;
132 if( videoEmbeddedFlag && config_GetInt( p_intf, "qt-always-video" ) )
133 alwaysVideoFlag = true;
135 /* Set the other interface settings */
136 //TODO: I don't like that code
137 visualSelectorEnabled = settings->value( "visual-selector", false ).toBool();
138 notificationEnabled = config_GetInt( p_intf, "qt-notification" )
141 /**************************
142 * UI and Widgets design
143 **************************/
144 setVLCWindowsTitle();
145 handleMainUi( settings );
147 /* Create a Dock to get the playlist */
148 dockPL = new QDockWidget( qtr( "Playlist" ), this );
149 dockPL->setSizePolicy( QSizePolicy::Preferred,
150 QSizePolicy::Expanding );
151 dockPL->setFeatures( QDockWidget::AllDockWidgetFeatures );
152 dockPL->setAllowedAreas( Qt::LeftDockWidgetArea
153 | Qt::RightDockWidgetArea
154 | Qt::BottomDockWidgetArea );
159 QVLCMenu::createMenuBar( this, p_intf, visualSelectorEnabled );
165 /* Widgets Creation*/
166 b_remainingTime = false;
167 timeLabel = new TimeLabel;
168 nameLabel = new QLabel;
169 nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
170 | Qt::TextSelectableByKeyboard );
171 speedLabel = new QLabel( "1.00x" );
172 speedLabel->setContextMenuPolicy ( Qt::CustomContextMenu );
174 /* Styling those labels */
175 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
176 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
177 nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
179 /* and adding those */
180 statusBar()->addWidget( nameLabel, 8 );
181 statusBar()->addPermanentWidget( speedLabel, 0 );
182 statusBar()->addPermanentWidget( timeLabel, 2 );
184 /* timeLabel behaviour:
185 - double clicking opens the goto time dialog
186 - right-clicking and clicking just toggle between remaining and
188 CONNECT( timeLabel, timeLabelClicked(), this, toggleTimeDisplay() );
189 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
190 CONNECT( timeLabel, timeLabelDoubleClicked(), this, toggleTimeDisplay() );
192 /* Speed Label behaviour:
193 - right click gives the vertical speed slider */
194 CONNECT( speedLabel, customContextMenuRequested( QPoint ),
195 this, showSpeedMenu( QPoint ) );
197 /**********************
198 * Systray Management *
199 **********************/
201 bool b_createSystray = false;
202 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
203 if( config_GetInt( p_intf, "qt-start-minimized") )
205 if( b_systrayAvailable ){
206 b_createSystray = true;
207 hide(); //FIXME BUG HERE
209 else msg_Warn( p_intf, "You can't minize if you haven't a system "
212 if( config_GetInt( p_intf, "qt-system-tray") )
213 b_createSystray = true;
215 if( b_systrayAvailable && b_createSystray )
218 if( config_GetInt( p_intf, "qt-minimal-view" ) )
221 /* Init input manager */
222 MainInputManager::getInstance( p_intf );
223 ON_TIMEOUT( updateOnTimer() );
224 //ON_TIMEOUT( debug() ):;
226 /********************
228 ********************/
230 /* Connect the input manager to the GUI elements it manages */
231 /* It is also connected to the control->slider, see the ControlsWidget */
232 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
233 this, setDisplayPosition( float, int, int ) );
235 CONNECT( THEMIM->getIM(), rateChanged( int ), this, setRate( int ) );
238 * Connects on nameChanged()
240 /* Naming in the controller statusbar */
241 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
242 setName( QString ) );
243 /* and in the systray */
246 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
247 updateSystrayTooltipName( QString ) );
249 /* and in the title of the controller */
250 if( config_GetInt( p_intf, "qt-name-in-title" ) )
252 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
253 setVLCWindowsTitle( QString ) );
256 /** 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 ) );
269 var_Create( p_intf, "interaction", VLC_VAR_ADDRESS );
270 var_AddCallback( p_intf, "interaction", InteractCallback, this );
271 p_intf->b_interaction = VLC_TRUE;
273 /* Register callback for the intf-popupmenu variable */
274 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
275 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
276 if( p_playlist != NULL )
278 var_AddCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
279 var_AddCallback( p_playlist, "intf-show", IntfShowCB, p_intf );
280 vlc_object_release( p_playlist );
283 CONNECT( this, askReleaseVideo( void * ), this, releaseVideoSlot( void * ) );
285 CONNECT( dockPL, topLevelChanged( bool ), this, doComponentsUpdate() );
286 CONNECT( controls, advancedControlsToggled( bool ),
287 this, doComponentsUpdate() );
290 settings->endGroup();
293 MainInterface::~MainInterface()
295 if( playlistWidget ) playlistWidget->savingSettings( settings );
296 if( ExtendedDialog::exists() )
297 ExtendedDialog::getInstance( p_intf )->savingSettings();
299 settings->beginGroup( "MainWindow" );
300 settings->setValue( "playlist-floats", dockPL->isFloating() );
301 settings->setValue( "adv-controls",
302 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
303 settings->setValue( "pos", pos() );
305 settings->endGroup();
308 /* Unregister callback for the intf-popupmenu variable */
309 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
310 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
311 if( p_playlist != NULL )
313 var_DelCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
314 var_DelCallback( p_playlist, "intf-show", IntfShowCB, p_intf );
315 vlc_object_release( p_playlist );
318 p_intf->b_interaction = VLC_FALSE;
319 var_DelCallback( p_intf, "interaction", InteractCallback, this );
321 p_intf->pf_request_window = NULL;
322 p_intf->pf_release_window = NULL;
323 p_intf->pf_control_window = NULL;
326 /*****************************
328 *****************************/
331 * Give the decorations of the Main Window a correct Name.
332 * If nothing is given, set it to VLC...
334 void MainInterface::setVLCWindowsTitle( QString aTitle )
336 if( aTitle.isEmpty() )
338 setWindowTitle( qtr( "VLC media player" ) );
342 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
346 void MainInterface::handleMainUi( QSettings *settings )
348 /* Create the main Widget and the mainLayout */
349 QWidget *main = new QWidget;
350 setCentralWidget( main );
351 mainLayout = new QVBoxLayout( main );
353 /* Margins, spacing */
354 main->setContentsMargins( 0, 0, 0, 0 );
355 main->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
356 mainLayout->setMargin( 0 );
358 /* Create the CONTROLS Widget */
359 /* bool b_shiny = config_GetInt( p_intf, "qt-blingbling" ); */
360 controls = new ControlsWidget( p_intf, this,
361 settings->value( "adv-controls", false ).toBool(),
362 config_GetInt( p_intf, "qt-blingbling" ) );
364 /* Add the controls Widget to the main Widget */
365 mainLayout->insertWidget( 0, controls );
367 /* Create the Speed Control Widget */
368 speedControl = new SpeedControlWidget( p_intf );
369 speedControlMenu = new QMenu( this );
371 QWidgetAction *widgetAction = new QWidgetAction( speedControl );
372 widgetAction->setDefaultWidget( speedControl );
373 speedControlMenu->addAction( widgetAction );
376 /* Disabled for now, they SUCK */
378 visualSelector = new VisualSelector( p_intf );
379 mainLayout->insertWidget( 0, visualSelector );
380 visualSelector->hide();
383 /* And video Outputs */
384 if( alwaysVideoFlag )
386 bgWidget = new BackgroundWidget( p_intf );
387 bgWidget->widgetSize = settings->value( "backgroundSize",
388 QSize( 300, 200 ) ).toSize();
389 bgWidget->resize( bgWidget->widgetSize );
390 bgWidget->updateGeometry();
391 mainLayout->insertWidget( 0, bgWidget );
392 CONNECT( this, askBgWidgetToToggle(), bgWidget, toggle() );
395 if( videoEmbeddedFlag )
397 videoWidget = new VideoWidget( p_intf );
398 videoWidget->widgetSize = QSize( 1, 1 );
399 //videoWidget->resize( videoWidget->widgetSize );
400 mainLayout->insertWidget( 0, videoWidget );
402 p_intf->pf_request_window = ::DoRequest;
403 p_intf->pf_release_window = ::DoRelease;
404 p_intf->pf_control_window = ::DoControl;
407 /* Finish the sizing */
411 int MainInterface::privacyDialog( QList<ConfigControl *> controls )
413 QDialog *privacy = new QDialog( this );
415 privacy->setWindowTitle( qtr( "Privacy and Network policies" ) );
417 QGridLayout *gLayout = new QGridLayout( privacy );
419 QGroupBox *blabla = new QGroupBox( qtr( "Privacy and Network Warning" ) );
420 QGridLayout *blablaLayout = new QGridLayout( blabla );
421 QLabel *text = new QLabel( qtr(
422 "<p>The <i>VideoLAN Team</i> doesn't like when an application goes "
423 "online without authorisation.</p>\n "
424 "<p><i>VLC media player</i> can request limited information on "
425 "Internet, espically to get CD Covers and songs metadata or to know "
426 "if updates are available.</p>\n"
427 "<p><i>VLC media player</i> <b>DOES NOT</b> send or collect <b>ANY</b> "
428 "information, even anonymously about your "
430 "<p>Therefore please check the following options, the default being "
431 "almost no access on the web.</p>\n") );
432 text->setWordWrap( true );
433 text->setTextFormat( Qt::RichText );
435 blablaLayout->addWidget( text, 0, 0 ) ;
437 QGroupBox *options = new QGroupBox;
438 QGridLayout *optionsLayout = new QGridLayout( options );
440 gLayout->addWidget( blabla, 0, 0, 1, 3 );
441 gLayout->addWidget( options, 1, 0, 1, 3 );
442 module_config_t *p_config;
443 ConfigControl *control;
446 #define CONFIG_GENERIC( option, type ) \
447 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
450 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
451 p_config, options, false, optionsLayout, line ); \
452 controls.append( control ); \
455 #define CONFIG_GENERIC_NOBOOL( option, type ) \
456 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
459 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
460 p_config, options, optionsLayout, line ); \
461 controls.append( control ); \
464 CONFIG_GENERIC( "album-art", IntegerList ); line++;
465 CONFIG_GENERIC_NOBOOL( "fetch-meta", Bool ); line++;
466 CONFIG_GENERIC_NOBOOL( "qt-updates-notif", Bool );
468 QPushButton *ok = new QPushButton( qtr( "Ok" ) );
470 gLayout->addWidget( ok, 2, 2 );
472 CONNECT( ok, clicked(), privacy, accept() );
473 return privacy->exec();
476 //FIXME remove me at the end...
477 void MainInterface::debug()
479 msg_Dbg( p_intf, "size: %i - %i", controls->size().height(), controls->size().width() );
480 msg_Dbg( p_intf, "sizeHint: %i - %i", controls->sizeHint().height(), controls->sizeHint().width() );
483 /**********************************************************************
484 * Handling of sizing of the components
485 **********************************************************************/
487 /* This function is probably wrong, but we don't have many many choices...
488 Since we can't know from the playlist Widget if we are inside a dock or not,
489 because the playlist Widget can be called by THEDP, as a separate windows for
491 Maybe the other solution is to redefine the sizeHint() of the playlist and
492 ask _parent->isFloating()...
493 If you think this would be better, please FIXME it...
495 QSize MainInterface::sizeHint() const
497 QSize tempSize = controls->sizeHint() +
498 QSize( 100, menuBar()->size().height() + statusBar()->size().height() );
500 if( VISIBLE( bgWidget ) )
501 tempSize += bgWidget->sizeHint();
502 else if( videoIsActive )
503 tempSize += videoWidget->size();
505 if( !dockPL->isFloating() && dockPL->widget() )
506 tempSize += dockPL->widget()->size();
512 /* FIXME This is dead code and need to be removed AT THE END */
513 void MainInterface::resizeEvent( QResizeEvent *e )
516 videoWidget->widgetSize.setWidth( e->size().width() - addSize.width() );
517 if( videoWidget && videoIsActive && videoWidget->widgetSize.height() > 1 )
519 SET_WH( videoWidget, e->size().width() - addSize.width(),
520 e->size().height() - addSize.height() );
521 videoWidget->updateGeometry();
523 if( VISIBLE( playlistWidget ) )
525 // SET_WH( playlistWidget , e->size().width() - addSize.width(),
526 // e->size().height() - addSize.height() );
527 playlistWidget->updateGeometry();
532 /****************************************************************************
533 * Small right-click menu for rate control
534 ****************************************************************************/
535 void MainInterface::showSpeedMenu( QPoint pos )
537 speedControlMenu->exec( QCursor::pos() - pos
538 + QPoint( 0, speedLabel->height() ) );
541 /****************************************************************************
543 ****************************************************************************/
544 class SetVideoOnTopQtEvent : public QEvent
547 SetVideoOnTopQtEvent( bool _onTop ) :
548 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
560 void *MainInterface::requestVideo( vout_thread_t *p_nvout, int *pi_x,
561 int *pi_y, unsigned int *pi_width,
562 unsigned int *pi_height )
564 void *ret = videoWidget->request( p_nvout,pi_x, pi_y, pi_width, pi_height );
567 videoIsActive = true;
568 bool bgWasVisible = false;
570 /* Did we have a bg ? */
571 if( VISIBLE( bgWidget) )
574 emit askBgWidgetToToggle();
577 if( THEMIM->getIM()->hasVideo() || !bgWasVisible )
579 videoWidget->widgetSize = QSize( *pi_width, *pi_height );
581 else /* Background widget available, use its size */
583 /* Ok, our visualizations are bad, so don't do this for the moment
584 * use the requested size anyway */
585 // videoWidget->widgetSize = bgWidget->widgeTSize;
586 videoWidget->widgetSize = QSize( *pi_width, *pi_height );
588 videoWidget->updateGeometry(); // Needed for deinterlace
594 void MainInterface::releaseVideo( void *p_win )
596 emit askReleaseVideo( p_win );
599 void MainInterface::releaseVideoSlot( void *p_win )
601 videoWidget->release( p_win );
607 videoIsActive = false;
611 int MainInterface::controlVideo( void *p_window, int i_query, va_list args )
613 int i_ret = VLC_EGENERIC;
618 unsigned int *pi_width = va_arg( args, unsigned int * );
619 unsigned int *pi_height = va_arg( args, unsigned int * );
620 *pi_width = videoWidget->widgetSize.width();
621 *pi_height = videoWidget->widgetSize.height();
627 unsigned int i_width = va_arg( args, unsigned int );
628 unsigned int i_height = va_arg( args, unsigned int );
629 videoWidget->widgetSize = QSize( i_width, i_height );
630 videoWidget->updateGeometry();
635 case VOUT_SET_STAY_ON_TOP:
637 int i_arg = va_arg( args, int );
638 QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
643 msg_Warn( p_intf, "unsupported control query" );
649 /*****************************************************************************
650 * Playlist, Visualisation and Menus handling
651 *****************************************************************************/
653 * Toggle the playlist widget or dialog
655 void MainInterface::togglePlaylist()
658 If no playlist exist, then create one and attach it to the DockPL*/
659 if( !playlistWidget )
661 msg_Dbg( p_intf, "Creating a new playlist" );
662 playlistWidget = new PlaylistWidget( p_intf, settings );
664 /* Add it to the parent DockWidget */
665 dockPL->setWidget( playlistWidget );
667 /* Add the dock to the main Interface */
668 addDockWidget( Qt::BottomDockWidgetArea, dockPL );
670 /* Make the playlist floating is requested. Default is not. */
671 if( settings->value( "playlist-floats", false ).toBool() );
673 msg_Dbg( p_intf, "we don't want it inside");
674 dockPL->setFloating( true );
679 /* toggle the visibility of the playlist */
681 //resize(sizeHint());
684 doComponentsUpdate();
689 /* Function called from the menu to undock the playlist */
690 void MainInterface::undockPlaylist()
692 dockPL->setFloating( true );
696 void MainInterface::toggleMinimalView()
698 TOGGLEV( menuBar() );
700 TOGGLEV( statusBar() );
704 /* Video widget cannot do this synchronously as it runs in another thread */
705 /* Well, could it, actually ? Probably dangerous ... */
706 void MainInterface::doComponentsUpdate()
711 /* toggling advanced controls buttons */
712 void MainInterface::toggleAdvanced()
714 controls->toggleAdvanced();
717 /* Get the visibility status of the controls (hidden or not, advanced or not) */
718 int MainInterface::getControlsVisibilityStatus()
720 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
721 + CONTROLS_ADVANCED * controls->b_advancedVisible );
725 void MainInterface::visual()
727 if( !VISIBLE( visualSelector) )
729 visualSelector->show();
730 if( !THEMIM->getIM()->hasVideo() )
732 /* Show the background widget */
734 visualSelectorEnabled = true;
738 /* Stop any currently running visualization */
739 visualSelector->hide();
740 visualSelectorEnabled = false;
742 doComponentsUpdate();
746 /************************************************************************
748 ************************************************************************/
749 void MainInterface::setDisplayPosition( float pos, int time, int length )
751 char psz_length[MSTRTIME_MAX_SIZE], psz_time[MSTRTIME_MAX_SIZE];
752 secstotimestr( psz_length, length );
753 secstotimestr( psz_time, ( b_remainingTime && length ) ? length - time
757 title.sprintf( "%s/%s", psz_time,
758 ( !length && time ) ? "--:--" : psz_length );
760 /* Add a minus to remaining time*/
761 if( b_remainingTime && length ) timeLabel->setText( " -"+title+" " );
762 else timeLabel->setText( " "+title+" " );
765 void MainInterface::toggleTimeDisplay()
767 b_remainingTime = !b_remainingTime;
768 //b_remainingTime = ( b_remainingTime ? false : true );
771 void MainInterface::setName( QString name )
773 input_name = name; /* store it for the QSystray use */
774 /* Display it in the status bar, but also as a Tooltip in case it doesn't
776 nameLabel->setText( " " + name + " " );
777 nameLabel->setToolTip( " " + name +" " );
780 void MainInterface::setStatus( int status )
782 /* Forward the status to the controls to toggle Play/Pause */
783 controls->setStatus( status );
784 /* And in the systray for the menu */
786 QVLCMenu::updateSystrayMenu( this, p_intf );
789 void MainInterface::setRate( int rate )
792 str.setNum( ( 1000 / (double)rate ), 'f', 2 );
794 speedLabel->setText( str );
795 speedControl->updateControls( rate );
798 void MainInterface::updateOnTimer()
801 if( intf_ShouldDie( p_intf ) )
803 QApplication::closeAllWindows();
804 QApplication::quit();
806 if( need_components_update )
808 doComponentsUpdate();
809 need_components_update = false;
813 controls->updateOnTimer();
816 /*****************************************************************************
817 * Systray Icon and Systray Menu
818 *****************************************************************************/
821 * Create a SystemTray icon and a menu that would go with it.
822 * Connects to a click handler on the icon.
824 void MainInterface::createSystray()
826 QIcon iconVLC = QIcon( QPixmap( ":/vlc128.png" ) );
827 sysTray = new QSystemTrayIcon( iconVLC, this );
828 sysTray->setToolTip( qtr( "VLC media player" ));
830 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
831 systrayMenu->setIcon( iconVLC );
833 QVLCMenu::updateSystrayMenu( this, p_intf, true );
836 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
837 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
841 * Updates the Systray Icon's menu and toggle the main interface
843 void MainInterface::toggleUpdateSystrayMenu()
845 /* If hidden, show it */
851 else if( isMinimized() )
861 /* check if any visible window is above vlc in the z-order,
862 * but ignore the ones always on top */
865 wi.cbSize = sizeof( WINDOWINFO );
866 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
867 hwnd && !IsWindowVisible( hwnd );
868 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
869 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
870 (wi.dwExStyle&WS_EX_TOPMOST) )
872 if( isActiveWindow() )
882 QVLCMenu::updateSystrayMenu( this, p_intf );
885 void MainInterface::handleSystrayClick(
886 QSystemTrayIcon::ActivationReason reason )
890 case QSystemTrayIcon::Trigger:
891 toggleUpdateSystrayMenu();
893 case QSystemTrayIcon::MiddleClick:
894 sysTray->showMessage( qtr( "VLC media player" ),
895 qtr( "Control menu for the player" ),
896 QSystemTrayIcon::Information, 3000 );
902 * Updates the name of the systray Icon tooltip.
903 * Doesn't check if the systray exists, check before you call it.
905 void MainInterface::updateSystrayTooltipName( QString name )
909 sysTray->setToolTip( qtr( "VLC media player" ) );
913 sysTray->setToolTip( name );
914 if( notificationEnabled && ( isHidden() || isMinimized() ) )
916 sysTray->showMessage( qtr( "VLC media player" ), name,
917 QSystemTrayIcon::NoIcon, 3000 );
923 * Updates the status of the systray Icon tooltip.
924 * Doesn't check if the systray exists, check before you call it.
926 void MainInterface::updateSystrayTooltipStatus( int i_status )
933 sysTray->setToolTip( qtr( "VLC media player" ) );
938 sysTray->setToolTip( input_name );
943 sysTray->setToolTip( input_name + " - "
950 /************************************************************************
952 ************************************************************************/
953 void MainInterface::dropEvent(QDropEvent *event)
955 const QMimeData *mimeData = event->mimeData();
957 /* D&D of a subtitles file, add it on the fly */
958 if( mimeData->urls().size() == 1 )
960 if( THEMIM->getIM()->hasInput() )
962 if( input_AddSubtitles( THEMIM->getInput(),
963 qtu( mimeData->urls()[0].toString() ),
966 event->acceptProposedAction();
972 foreach( QUrl url, mimeData->urls() ) {
973 QString s = url.toString();
974 if( s.length() > 0 ) {
975 playlist_Add( THEPL, qtu(s), NULL,
976 PLAYLIST_APPEND | (first ? PLAYLIST_GO:0),
977 PLAYLIST_END, VLC_TRUE, VLC_FALSE );
981 event->acceptProposedAction();
983 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
985 event->acceptProposedAction();
987 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
989 event->acceptProposedAction();
991 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
996 /************************************************************************
998 ************************************************************************/
999 void MainInterface::customEvent( QEvent *event )
1002 if( event->type() == PLDockEvent_Type )
1004 PlaylistDialog::killInstance();
1005 playlistEmbeddedFlag = true;
1007 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1012 if ( event->type() == SetVideoOnTopEvent_Type )
1014 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1015 if( p_event->OnTop() )
1016 setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
1018 setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint);
1019 show(); /* necessary to apply window flags?? */
1023 void MainInterface::keyPressEvent( QKeyEvent *e )
1025 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() & Qt::Key_H )
1026 && menuBar()->isHidden() )
1028 toggleMinimalView();
1032 int i_vlck = qtEventToVLCKey( e );
1035 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1042 void MainInterface::wheelEvent( QWheelEvent *e )
1044 int i_vlckey = qtWheelEventToVLCKey( e );
1045 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1049 void MainInterface::closeEvent( QCloseEvent *e )
1052 vlc_object_kill( p_intf );
1053 QApplication::closeAllWindows();
1054 QApplication::quit();
1057 /*****************************************************************************
1059 *****************************************************************************/
1060 static int InteractCallback( vlc_object_t *p_this,
1061 const char *psz_var, vlc_value_t old_val,
1062 vlc_value_t new_val, void *param )
1064 intf_dialog_args_t *p_arg = new intf_dialog_args_t;
1065 p_arg->p_dialog = (interaction_dialog_t *)(new_val.p_address);
1066 DialogEvent *event = new DialogEvent( INTF_DIALOG_INTERACTION, 0, p_arg );
1067 QApplication::postEvent( THEDP, static_cast<QEvent*>(event) );
1071 /*****************************************************************************
1072 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1073 * We don't show the menu directly here because we don't want the
1074 * caller to block for a too long time.
1075 *****************************************************************************/
1076 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1077 vlc_value_t old_val, vlc_value_t new_val, void *param )
1079 intf_thread_t *p_intf = (intf_thread_t *)param;
1081 if( p_intf->pf_show_dialog )
1083 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1084 new_val.b_bool, 0 );
1090 /*****************************************************************************
1091 * IntfShowCB: callback triggered by the intf-show playlist variable.
1092 *****************************************************************************/
1093 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1094 vlc_value_t old_val, vlc_value_t new_val, void *param )
1096 intf_thread_t *p_intf = (intf_thread_t *)param;
1097 //p_intf->p_sys->b_intf_show = VLC_TRUE;