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 //FIXME 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() );
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", getControlsVisibilityStatus() & CONTROLS_ADVANCED );
301 settings->setValue( "pos", pos() );
303 settings->endGroup();
306 /* Unregister callback for the intf-popupmenu variable */
307 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
308 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
309 if( p_playlist != NULL )
311 var_DelCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
312 var_DelCallback( p_playlist, "intf-show", IntfShowCB, p_intf );
313 vlc_object_release( p_playlist );
316 p_intf->b_interaction = VLC_FALSE;
317 var_DelCallback( p_intf, "interaction", InteractCallback, this );
319 p_intf->pf_request_window = NULL;
320 p_intf->pf_release_window = NULL;
321 p_intf->pf_control_window = NULL;
324 /*****************************
326 *****************************/
329 * Give the decorations of the Main Window a correct Name.
330 * If nothing is given, set it to VLC...
332 void MainInterface::setVLCWindowsTitle( QString aTitle )
334 if( aTitle.isEmpty() )
336 setWindowTitle( qtr( "VLC media player" ) );
340 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
344 void MainInterface::handleMainUi( QSettings *settings )
346 /* Create the main Widget and the mainLayout */
347 QWidget *main = new QWidget;
348 setCentralWidget( main );
349 mainLayout = new QVBoxLayout( main );
351 /* Margins, spacing */
352 main->setContentsMargins( 0, 0, 0, 0 );
353 mainLayout->setMargin( 0 );
355 /* Create the CONTROLS Widget */
356 /* bool b_shiny = config_GetInt( p_intf, "qt-blingbling" ); */
357 controls = new ControlsWidget( p_intf, this,
358 settings->value( "adv-controls", false ).toBool(),
359 config_GetInt( p_intf, "qt-blingbling" ) );
361 /* Add the controls Widget to the main Widget */
362 mainLayout->insertWidget( 0, controls );
364 /* Create the Speed Control Widget */
365 speedControl = new SpeedControlWidget( p_intf );
366 speedControlMenu = new QMenu( this );
368 QWidgetAction *widgetAction = new QWidgetAction( speedControl );
369 widgetAction->setDefaultWidget( speedControl );
370 speedControlMenu->addAction( widgetAction );
373 /* Disabled for now, they SUCK */
375 visualSelector = new VisualSelector( p_intf );
376 mainLayout->insertWidget( 0, visualSelector );
377 visualSelector->hide();
380 /* And video Outputs */
381 if( alwaysVideoFlag )
383 bgWidget = new BackgroundWidget( p_intf );
384 bgWidget->widgetSize = settings->value( "backgroundSize",
385 QSize( 300, 200 ) ).toSize();
386 bgWidget->resize( bgWidget->widgetSize );
387 bgWidget->updateGeometry();
388 mainLayout->insertWidget( 0, bgWidget );
389 CONNECT( this, askBgWidgetToToggle(), bgWidget, toggle() );
392 if( videoEmbeddedFlag )
394 videoWidget = new VideoWidget( p_intf );
395 videoWidget->widgetSize = QSize( 1, 1 );
396 //videoWidget->resize( videoWidget->widgetSize );
397 mainLayout->insertWidget( 0, videoWidget );
399 p_intf->pf_request_window = ::DoRequest;
400 p_intf->pf_release_window = ::DoRelease;
401 p_intf->pf_control_window = ::DoControl;
404 /* Finish the sizing */
408 int MainInterface::privacyDialog( QList<ConfigControl *> controls )
410 QDialog *privacy = new QDialog( this );
412 privacy->setWindowTitle( qtr( "Privacy and Network policies" ) );
414 QGridLayout *gLayout = new QGridLayout( privacy );
416 QGroupBox *blabla = new QGroupBox( qtr( "Privacy and Network Warning" ) );
417 QGridLayout *blablaLayout = new QGridLayout( blabla );
418 QLabel *text = new QLabel( qtr(
419 "<p>The <i>VideoLAN Team</i> doesn't like when an application goes "
420 "online without authorisation.</p>\n "
421 "<p><i>VLC media player</i> can request limited information on "
422 "Internet, espically to get CD Covers and songs metadata or to know "
423 "if updates are available.</p>\n"
424 "<p><i>VLC media player</i> <b>DOES NOT</b> send or collect <b>ANY</b> "
425 "information, even anonymously about your "
427 "<p>Therefore please check the following options, the default being "
428 "almost no access on the web.</p>\n") );
429 text->setWordWrap( true );
430 text->setTextFormat( Qt::RichText );
432 blablaLayout->addWidget( text, 0, 0 ) ;
434 QGroupBox *options = new QGroupBox;
435 QGridLayout *optionsLayout = new QGridLayout( options );
437 gLayout->addWidget( blabla, 0, 0, 1, 3 );
438 gLayout->addWidget( options, 1, 0, 1, 3 );
439 module_config_t *p_config;
440 ConfigControl *control;
443 #define CONFIG_GENERIC( option, type ) \
444 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
447 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
448 p_config, options, false, optionsLayout, line ); \
449 controls.append( control ); \
452 #define CONFIG_GENERIC_NOBOOL( option, type ) \
453 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
456 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
457 p_config, options, optionsLayout, line ); \
458 controls.append( control ); \
461 CONFIG_GENERIC( "album-art", IntegerList ); line++;
462 CONFIG_GENERIC_NOBOOL( "fetch-meta", Bool ); line++;
463 CONFIG_GENERIC_NOBOOL( "qt-updates-notif", Bool );
465 QPushButton *ok = new QPushButton( qtr( "Ok" ) );
467 gLayout->addWidget( ok, 2, 2 );
469 CONNECT( ok, clicked(), privacy, accept() );
470 return privacy->exec();
473 //FIXME remove me at the end...
474 void MainInterface::debug()
476 msg_Dbg( p_intf, "size: %i - %i", controls->size().height(), controls->size().width() );
477 msg_Dbg( p_intf, "sizeHint: %i - %i", controls->sizeHint().height(), controls->sizeHint().width() );
480 /**********************************************************************
481 * Handling of sizing of the components
482 **********************************************************************/
484 /* This function is probably wrong, but we don't have many many choices...
485 Since we can't know from the playlist Widget if we are inside a dock or not,
486 because the playlist Widget can be called by THEDP, as a separate windows for
488 Maybe the other solution is to redefine the sizeHint() of the playlist and
489 ask _parent->isFloating()...
490 If you think this would be better, please FIX it...
492 QSize MainInterface::sizeHint() const
494 QSize tempSize = controls->sizeHint() +
495 QSize( 100, menuBar()->size().height() + statusBar()->size().height() );
497 if( VISIBLE( bgWidget ) )
498 tempSize += bgWidget->sizeHint();
499 else if( videoIsActive )
500 tempSize += videoWidget->size();
502 if( !dockPL->isFloating() && dockPL->widget() )
503 tempSize += dockPL->widget()->size();
509 /* FIXME This is dead code and need to be removed AT THE END */
510 void MainInterface::resizeEvent( QResizeEvent *e )
513 videoWidget->widgetSize.setWidth( e->size().width() - addSize.width() );
514 if( videoWidget && videoIsActive && videoWidget->widgetSize.height() > 1 )
516 SET_WH( videoWidget, e->size().width() - addSize.width(),
517 e->size().height() - addSize.height() );
518 videoWidget->updateGeometry();
520 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 //FIXME Remove this function at the end...
800 void MainInterface::updateOnTimer()
802 /* if( intf_ShouldDie( p_intf ) )
804 QApplication::closeAllWindows();
805 QApplication::quit();
808 if( need_components_update )
810 doComponentsUpdate();
811 need_components_update = false;
815 controls->updateOnTimer();
818 /*****************************************************************************
819 * Systray Icon and Systray Menu
820 *****************************************************************************/
823 * Create a SystemTray icon and a menu that would go with it.
824 * Connects to a click handler on the icon.
826 void MainInterface::createSystray()
828 QIcon iconVLC = QIcon( QPixmap( ":/vlc128.png" ) );
829 sysTray = new QSystemTrayIcon( iconVLC, this );
830 sysTray->setToolTip( qtr( "VLC media player" ));
832 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
833 systrayMenu->setIcon( iconVLC );
835 QVLCMenu::updateSystrayMenu( this, p_intf, true );
838 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
839 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
843 * Updates the Systray Icon's menu and toggle the main interface
845 void MainInterface::toggleUpdateSystrayMenu()
847 /* If hidden, show it */
853 else if( isMinimized() )
863 /* check if any visible window is above vlc in the z-order,
864 * but ignore the ones always on top */
867 wi.cbSize = sizeof( WINDOWINFO );
868 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
869 hwnd && !IsWindowVisible( hwnd );
870 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
871 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
872 (wi.dwExStyle&WS_EX_TOPMOST) )
874 if( isActiveWindow() )
884 QVLCMenu::updateSystrayMenu( this, p_intf );
887 void MainInterface::handleSystrayClick(
888 QSystemTrayIcon::ActivationReason reason )
892 case QSystemTrayIcon::Trigger:
893 toggleUpdateSystrayMenu();
895 case QSystemTrayIcon::MiddleClick:
896 sysTray->showMessage( qtr( "VLC media player" ),
897 qtr( "Control menu for the player" ),
898 QSystemTrayIcon::Information, 3000 );
904 * Updates the name of the systray Icon tooltip.
905 * Doesn't check if the systray exists, check before you call it.
907 void MainInterface::updateSystrayTooltipName( QString name )
911 sysTray->setToolTip( qtr( "VLC media player" ) );
915 sysTray->setToolTip( name );
916 if( notificationEnabled && ( isHidden() || isMinimized() ) )
918 sysTray->showMessage( qtr( "VLC media player" ), name,
919 QSystemTrayIcon::NoIcon, 3000 );
925 * Updates the status of the systray Icon tooltip.
926 * Doesn't check if the systray exists, check before you call it.
928 void MainInterface::updateSystrayTooltipStatus( int i_status )
935 sysTray->setToolTip( qtr( "VLC media player" ) );
940 sysTray->setToolTip( input_name );
945 sysTray->setToolTip( input_name + " - "
952 /************************************************************************
954 ************************************************************************/
955 void MainInterface::dropEvent(QDropEvent *event)
957 const QMimeData *mimeData = event->mimeData();
959 /* D&D of a subtitles file, add it on the fly */
960 if( mimeData->urls().size() == 1 )
962 if( THEMIM->getIM()->hasInput() )
964 if( input_AddSubtitles( THEMIM->getInput(),
965 qtu( mimeData->urls()[0].toString() ),
968 event->acceptProposedAction();
974 foreach( QUrl url, mimeData->urls() ) {
975 QString s = url.toString();
976 if( s.length() > 0 ) {
977 playlist_Add( THEPL, qtu(s), NULL,
978 PLAYLIST_APPEND | (first ? PLAYLIST_GO:0),
979 PLAYLIST_END, VLC_TRUE, VLC_FALSE );
983 event->acceptProposedAction();
985 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
987 event->acceptProposedAction();
989 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
991 event->acceptProposedAction();
993 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
998 /************************************************************************
1000 ************************************************************************/
1001 void MainInterface::customEvent( QEvent *event )
1004 if( event->type() == PLDockEvent_Type )
1006 PlaylistDialog::killInstance();
1007 playlistEmbeddedFlag = true;
1009 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1014 if ( event->type() == SetVideoOnTopEvent_Type )
1016 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1017 if( p_event->OnTop() )
1018 setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
1020 setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint);
1021 show(); /* necessary to apply window flags?? */
1025 void MainInterface::keyPressEvent( QKeyEvent *e )
1027 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() & Qt::Key_H )
1028 && menuBar()->isHidden() )
1030 toggleMinimalView();
1034 int i_vlck = qtEventToVLCKey( e );
1037 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1044 void MainInterface::wheelEvent( QWheelEvent *e )
1046 int i_vlckey = qtWheelEventToVLCKey( e );
1047 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1051 void MainInterface::closeEvent( QCloseEvent *e )
1054 vlc_object_kill( p_intf );
1055 QApplication::closeAllWindows();
1056 QApplication::quit();
1059 /*****************************************************************************
1061 *****************************************************************************/
1062 static int InteractCallback( vlc_object_t *p_this,
1063 const char *psz_var, vlc_value_t old_val,
1064 vlc_value_t new_val, void *param )
1066 intf_dialog_args_t *p_arg = new intf_dialog_args_t;
1067 p_arg->p_dialog = (interaction_dialog_t *)(new_val.p_address);
1068 DialogEvent *event = new DialogEvent( INTF_DIALOG_INTERACTION, 0, p_arg );
1069 QApplication::postEvent( THEDP, static_cast<QEvent*>(event) );
1073 /*****************************************************************************
1074 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1075 * We don't show the menu directly here because we don't want the
1076 * caller to block for a too long time.
1077 *****************************************************************************/
1078 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1079 vlc_value_t old_val, vlc_value_t new_val, void *param )
1081 intf_thread_t *p_intf = (intf_thread_t *)param;
1083 if( p_intf->pf_show_dialog )
1085 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1086 new_val.b_bool, 0 );
1092 /*****************************************************************************
1093 * IntfShowCB: callback triggered by the intf-show playlist variable.
1094 *****************************************************************************/
1095 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1096 vlc_value_t old_val, vlc_value_t new_val, void *param )
1098 intf_thread_t *p_intf = (intf_thread_t *)param;
1099 //p_intf->p_sys->b_intf_show = VLC_TRUE;