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::MinimumExpanding );
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 mainLayout->setMargin( 0 );
357 /* Create the CONTROLS Widget */
358 /* bool b_shiny = config_GetInt( p_intf, "qt-blingbling" ); */
359 controls = new ControlsWidget( p_intf, this,
360 settings->value( "adv-controls", false ).toBool(),
361 config_GetInt( p_intf, "qt-blingbling" ) );
363 /* Add the controls Widget to the main Widget */
364 mainLayout->insertWidget( 0, controls );
366 /* Create the Speed Control Widget */
367 speedControl = new SpeedControlWidget( p_intf );
368 speedControlMenu = new QMenu( this );
370 QWidgetAction *widgetAction = new QWidgetAction( speedControl );
371 widgetAction->setDefaultWidget( speedControl );
372 speedControlMenu->addAction( widgetAction );
375 /* Disabled for now, they SUCK */
377 visualSelector = new VisualSelector( p_intf );
378 mainLayout->insertWidget( 0, visualSelector );
379 visualSelector->hide();
382 /* And video Outputs */
383 if( alwaysVideoFlag )
385 bgWidget = new BackgroundWidget( p_intf );
386 bgWidget->widgetSize = settings->value( "backgroundSize",
387 QSize( 300, 200 ) ).toSize();
388 bgWidget->resize( bgWidget->widgetSize );
389 bgWidget->updateGeometry();
390 mainLayout->insertWidget( 0, bgWidget );
391 CONNECT( this, askBgWidgetToToggle(), bgWidget, toggle() );
394 if( videoEmbeddedFlag )
396 videoWidget = new VideoWidget( p_intf );
397 videoWidget->widgetSize = QSize( 1, 1 );
398 //videoWidget->resize( videoWidget->widgetSize );
399 mainLayout->insertWidget( 0, videoWidget );
401 p_intf->pf_request_window = ::DoRequest;
402 p_intf->pf_release_window = ::DoRelease;
403 p_intf->pf_control_window = ::DoControl;
406 /* Finish the sizing */
410 int MainInterface::privacyDialog( QList<ConfigControl *> controls )
412 QDialog *privacy = new QDialog( this );
414 privacy->setWindowTitle( qtr( "Privacy and Network policies" ) );
416 QGridLayout *gLayout = new QGridLayout( privacy );
418 QGroupBox *blabla = new QGroupBox( qtr( "Privacy and Network Warning" ) );
419 QGridLayout *blablaLayout = new QGridLayout( blabla );
420 QLabel *text = new QLabel( qtr(
421 "<p>The <i>VideoLAN Team</i> doesn't like when an application goes "
422 "online without authorisation.</p>\n "
423 "<p><i>VLC media player</i> can request limited information on "
424 "Internet, espically to get CD Covers and songs metadata or to know "
425 "if updates are available.</p>\n"
426 "<p><i>VLC media player</i> <b>DOES NOT</b> send or collect <b>ANY</b> "
427 "information, even anonymously about your "
429 "<p>Therefore please check the following options, the default being "
430 "almost no access on the web.</p>\n") );
431 text->setWordWrap( true );
432 text->setTextFormat( Qt::RichText );
434 blablaLayout->addWidget( text, 0, 0 ) ;
436 QGroupBox *options = new QGroupBox;
437 QGridLayout *optionsLayout = new QGridLayout( options );
439 gLayout->addWidget( blabla, 0, 0, 1, 3 );
440 gLayout->addWidget( options, 1, 0, 1, 3 );
441 module_config_t *p_config;
442 ConfigControl *control;
445 #define CONFIG_GENERIC( option, type ) \
446 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
449 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
450 p_config, options, false, optionsLayout, line ); \
451 controls.append( control ); \
454 #define CONFIG_GENERIC_NOBOOL( option, type ) \
455 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
458 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
459 p_config, options, optionsLayout, line ); \
460 controls.append( control ); \
463 CONFIG_GENERIC( "album-art", IntegerList ); line++;
464 CONFIG_GENERIC_NOBOOL( "fetch-meta", Bool ); line++;
465 CONFIG_GENERIC_NOBOOL( "qt-updates-notif", Bool );
467 QPushButton *ok = new QPushButton( qtr( "Ok" ) );
469 gLayout->addWidget( ok, 2, 2 );
471 CONNECT( ok, clicked(), privacy, accept() );
472 return privacy->exec();
475 //FIXME remove me at the end...
476 void MainInterface::debug()
478 msg_Dbg( p_intf, "size: %i - %i", controls->size().height(), controls->size().width() );
479 msg_Dbg( p_intf, "sizeHint: %i - %i", controls->sizeHint().height(), controls->sizeHint().width() );
482 /**********************************************************************
483 * Handling of sizing of the components
484 **********************************************************************/
486 /* This function is probably wrong, but we don't have many many choices...
487 Since we can't know from the playlist Widget if we are inside a dock or not,
488 because the playlist Widget can be called by THEDP, as a separate windows for
490 Maybe the other solution is to redefine the sizeHint() of the playlist and
491 ask _parent->isFloating()...
492 If you think this would be better, please FIXME it...
494 QSize MainInterface::sizeHint() const
496 QSize tempSize = controls->sizeHint() +
497 QSize( 100, menuBar()->size().height() + statusBar()->size().height() );
499 if( VISIBLE( bgWidget ) )
500 tempSize += bgWidget->sizeHint();
501 else if( videoIsActive )
502 tempSize += videoWidget->size();
504 if( !dockPL->isFloating() && dockPL->widget() )
505 tempSize += dockPL->widget()->size();
511 /* FIXME This is dead code and need to be removed AT THE END */
512 void MainInterface::resizeEvent( QResizeEvent *e )
515 videoWidget->widgetSize.setWidth( e->size().width() - addSize.width() );
516 if( videoWidget && videoIsActive && videoWidget->widgetSize.height() > 1 )
518 SET_WH( videoWidget, e->size().width() - addSize.width(),
519 e->size().height() - addSize.height() );
520 videoWidget->updateGeometry();
522 if( VISIBLE( playlistWidget ) )
524 // SET_WH( playlistWidget , e->size().width() - addSize.width(),
525 // e->size().height() - addSize.height() );
526 playlistWidget->updateGeometry();
531 /****************************************************************************
532 * Small right-click menu for rate control
533 ****************************************************************************/
534 void MainInterface::showSpeedMenu( QPoint pos )
536 speedControlMenu->exec( QCursor::pos() - pos
537 + QPoint( 0, speedLabel->height() ) );
540 /****************************************************************************
542 ****************************************************************************/
543 class SetVideoOnTopQtEvent : public QEvent
546 SetVideoOnTopQtEvent( bool _onTop ) :
547 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
559 void *MainInterface::requestVideo( vout_thread_t *p_nvout, int *pi_x,
560 int *pi_y, unsigned int *pi_width,
561 unsigned int *pi_height )
563 void *ret = videoWidget->request( p_nvout,pi_x, pi_y, pi_width, pi_height );
566 videoIsActive = true;
567 bool bgWasVisible = false;
569 /* Did we have a bg ? */
570 if( VISIBLE( bgWidget) )
573 emit askBgWidgetToToggle();
576 if( THEMIM->getIM()->hasVideo() || !bgWasVisible )
578 videoWidget->widgetSize = QSize( *pi_width, *pi_height );
580 else /* Background widget available, use its size */
582 /* Ok, our visualizations are bad, so don't do this for the moment
583 * use the requested size anyway */
584 // videoWidget->widgetSize = bgWidget->widgeTSize;
585 videoWidget->widgetSize = QSize( *pi_width, *pi_height );
587 videoWidget->updateGeometry(); // Needed for deinterlace
593 void MainInterface::releaseVideo( void *p_win )
595 emit askReleaseVideo( p_win );
598 void MainInterface::releaseVideoSlot( void *p_win )
600 videoWidget->release( p_win );
606 videoIsActive = false;
610 int MainInterface::controlVideo( void *p_window, int i_query, va_list args )
612 int i_ret = VLC_EGENERIC;
617 unsigned int *pi_width = va_arg( args, unsigned int * );
618 unsigned int *pi_height = va_arg( args, unsigned int * );
619 *pi_width = videoWidget->widgetSize.width();
620 *pi_height = videoWidget->widgetSize.height();
626 unsigned int i_width = va_arg( args, unsigned int );
627 unsigned int i_height = va_arg( args, unsigned int );
628 videoWidget->widgetSize = QSize( i_width, i_height );
629 videoWidget->updateGeometry();
634 case VOUT_SET_STAY_ON_TOP:
636 int i_arg = va_arg( args, int );
637 QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
642 msg_Warn( p_intf, "unsupported control query" );
648 /*****************************************************************************
649 * Playlist, Visualisation and Menus handling
650 *****************************************************************************/
652 * Toggle the playlist widget or dialog
654 void MainInterface::togglePlaylist()
657 If no playlist exist, then create one and attach it to the DockPL*/
658 if( !playlistWidget )
660 msg_Dbg( p_intf, "Creating a new playlist" );
661 playlistWidget = new PlaylistWidget( p_intf, settings );
663 /* Add it to the parent DockWidget */
664 dockPL->setWidget( playlistWidget );
666 /* Add the dock to the main Interface */
667 addDockWidget( Qt::BottomDockWidgetArea, dockPL );
669 /* Make the playlist floating is requested. Default is not. */
670 if( settings->value( "playlist-floats", false ).toBool() );
672 msg_Dbg( p_intf, "we don't want it inside");
673 dockPL->setFloating( true );
678 /* toggle the visibility of the playlist */
680 //resize(sizeHint());
683 doComponentsUpdate();
688 /* Function called from the menu to undock the playlist */
689 void MainInterface::undockPlaylist()
691 dockPL->setFloating( true );
695 void MainInterface::toggleMinimalView()
697 TOGGLEV( menuBar() );
699 TOGGLEV( statusBar() );
703 /* Video widget cannot do this synchronously as it runs in another thread */
704 /* Well, could it, actually ? Probably dangerous ... */
705 void MainInterface::doComponentsUpdate()
710 /* toggling advanced controls buttons */
711 void MainInterface::toggleAdvanced()
713 controls->toggleAdvanced();
716 /* Get the visibility status of the controls (hidden or not, advanced or not) */
717 int MainInterface::getControlsVisibilityStatus()
719 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
720 + CONTROLS_ADVANCED * controls->b_advancedVisible );
724 void MainInterface::visual()
726 if( !VISIBLE( visualSelector) )
728 visualSelector->show();
729 if( !THEMIM->getIM()->hasVideo() )
731 /* Show the background widget */
733 visualSelectorEnabled = true;
737 /* Stop any currently running visualization */
738 visualSelector->hide();
739 visualSelectorEnabled = false;
741 doComponentsUpdate();
745 /************************************************************************
747 ************************************************************************/
748 void MainInterface::setDisplayPosition( float pos, int time, int length )
750 char psz_length[MSTRTIME_MAX_SIZE], psz_time[MSTRTIME_MAX_SIZE];
751 secstotimestr( psz_length, length );
752 secstotimestr( psz_time, ( b_remainingTime && length ) ? length - time
756 title.sprintf( "%s/%s", psz_time,
757 ( !length && time ) ? "--:--" : psz_length );
759 /* Add a minus to remaining time*/
760 if( b_remainingTime && length ) timeLabel->setText( " -"+title+" " );
761 else timeLabel->setText( " "+title+" " );
764 void MainInterface::toggleTimeDisplay()
766 b_remainingTime = !b_remainingTime;
767 //b_remainingTime = ( b_remainingTime ? false : true );
770 void MainInterface::setName( QString name )
772 input_name = name; /* store it for the QSystray use */
773 /* Display it in the status bar, but also as a Tooltip in case it doesn't
775 nameLabel->setText( " " + name + " " );
776 nameLabel->setToolTip( " " + name +" " );
779 void MainInterface::setStatus( int status )
781 /* Forward the status to the controls to toggle Play/Pause */
782 controls->setStatus( status );
783 /* And in the systray for the menu */
785 QVLCMenu::updateSystrayMenu( this, p_intf );
788 void MainInterface::setRate( int rate )
791 str.setNum( ( 1000 / (double)rate ), 'f', 2 );
793 speedLabel->setText( str );
794 speedControl->updateControls( rate );
797 void MainInterface::updateOnTimer()
800 if( intf_ShouldDie( p_intf ) )
802 QApplication::closeAllWindows();
803 QApplication::quit();
805 if( need_components_update )
807 doComponentsUpdate();
808 need_components_update = false;
812 controls->updateOnTimer();
815 /*****************************************************************************
816 * Systray Icon and Systray Menu
817 *****************************************************************************/
820 * Create a SystemTray icon and a menu that would go with it.
821 * Connects to a click handler on the icon.
823 void MainInterface::createSystray()
825 QIcon iconVLC = QIcon( QPixmap( ":/vlc128.png" ) );
826 sysTray = new QSystemTrayIcon( iconVLC, this );
827 sysTray->setToolTip( qtr( "VLC media player" ));
829 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
830 systrayMenu->setIcon( iconVLC );
832 QVLCMenu::updateSystrayMenu( this, p_intf, true );
835 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
836 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
840 * Updates the Systray Icon's menu and toggle the main interface
842 void MainInterface::toggleUpdateSystrayMenu()
844 /* If hidden, show it */
850 else if( isMinimized() )
860 /* check if any visible window is above vlc in the z-order,
861 * but ignore the ones always on top */
864 wi.cbSize = sizeof( WINDOWINFO );
865 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
866 hwnd && !IsWindowVisible( hwnd );
867 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
868 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
869 (wi.dwExStyle&WS_EX_TOPMOST) )
871 if( isActiveWindow() )
881 QVLCMenu::updateSystrayMenu( this, p_intf );
884 void MainInterface::handleSystrayClick(
885 QSystemTrayIcon::ActivationReason reason )
889 case QSystemTrayIcon::Trigger:
890 toggleUpdateSystrayMenu();
892 case QSystemTrayIcon::MiddleClick:
893 sysTray->showMessage( qtr( "VLC media player" ),
894 qtr( "Control menu for the player" ),
895 QSystemTrayIcon::Information, 3000 );
901 * Updates the name of the systray Icon tooltip.
902 * Doesn't check if the systray exists, check before you call it.
904 void MainInterface::updateSystrayTooltipName( QString name )
908 sysTray->setToolTip( qtr( "VLC media player" ) );
912 sysTray->setToolTip( name );
913 if( notificationEnabled && ( isHidden() || isMinimized() ) )
915 sysTray->showMessage( qtr( "VLC media player" ), name,
916 QSystemTrayIcon::NoIcon, 3000 );
922 * Updates the status of the systray Icon tooltip.
923 * Doesn't check if the systray exists, check before you call it.
925 void MainInterface::updateSystrayTooltipStatus( int i_status )
932 sysTray->setToolTip( qtr( "VLC media player" ) );
937 sysTray->setToolTip( input_name );
942 sysTray->setToolTip( input_name + " - "
949 /************************************************************************
951 ************************************************************************/
952 void MainInterface::dropEvent(QDropEvent *event)
954 const QMimeData *mimeData = event->mimeData();
956 /* D&D of a subtitles file, add it on the fly */
957 if( mimeData->urls().size() == 1 )
959 if( THEMIM->getIM()->hasInput() )
961 if( input_AddSubtitles( THEMIM->getInput(),
962 qtu( mimeData->urls()[0].toString() ),
965 event->acceptProposedAction();
971 foreach( QUrl url, mimeData->urls() ) {
972 QString s = url.toString();
973 if( s.length() > 0 ) {
974 playlist_Add( THEPL, qtu(s), NULL,
975 PLAYLIST_APPEND | (first ? PLAYLIST_GO:0),
976 PLAYLIST_END, VLC_TRUE, VLC_FALSE );
980 event->acceptProposedAction();
982 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
984 event->acceptProposedAction();
986 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
988 event->acceptProposedAction();
990 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
995 /************************************************************************
997 ************************************************************************/
998 void MainInterface::customEvent( QEvent *event )
1001 if( event->type() == PLDockEvent_Type )
1003 PlaylistDialog::killInstance();
1004 playlistEmbeddedFlag = true;
1006 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1011 if ( event->type() == SetVideoOnTopEvent_Type )
1013 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1014 if( p_event->OnTop() )
1015 setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
1017 setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint);
1018 show(); /* necessary to apply window flags?? */
1022 void MainInterface::keyPressEvent( QKeyEvent *e )
1024 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() & Qt::Key_H )
1025 && menuBar()->isHidden() )
1027 toggleMinimalView();
1031 int i_vlck = qtEventToVLCKey( e );
1034 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1041 void MainInterface::wheelEvent( QWheelEvent *e )
1043 int i_vlckey = qtWheelEventToVLCKey( e );
1044 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1048 void MainInterface::closeEvent( QCloseEvent *e )
1051 vlc_object_kill( p_intf );
1052 QApplication::closeAllWindows();
1053 QApplication::quit();
1056 /*****************************************************************************
1058 *****************************************************************************/
1059 static int InteractCallback( vlc_object_t *p_this,
1060 const char *psz_var, vlc_value_t old_val,
1061 vlc_value_t new_val, void *param )
1063 intf_dialog_args_t *p_arg = new intf_dialog_args_t;
1064 p_arg->p_dialog = (interaction_dialog_t *)(new_val.p_address);
1065 DialogEvent *event = new DialogEvent( INTF_DIALOG_INTERACTION, 0, p_arg );
1066 QApplication::postEvent( THEDP, static_cast<QEvent*>(event) );
1070 /*****************************************************************************
1071 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1072 * We don't show the menu directly here because we don't want the
1073 * caller to block for a too long time.
1074 *****************************************************************************/
1075 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1076 vlc_value_t old_val, vlc_value_t new_val, void *param )
1078 intf_thread_t *p_intf = (intf_thread_t *)param;
1080 if( p_intf->pf_show_dialog )
1082 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1083 new_val.b_bool, 0 );
1089 /*****************************************************************************
1090 * IntfShowCB: callback triggered by the intf-show playlist variable.
1091 *****************************************************************************/
1092 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1093 vlc_value_t old_val, vlc_value_t new_val, void *param )
1095 intf_thread_t *p_intf = (intf_thread_t *)param;
1096 //p_intf->p_sys->b_intf_show = VLC_TRUE;