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 "dialogs/extended.hpp"
33 #include "dialogs/playlist.hpp"
37 #include <QCloseEvent>
38 #include <QPushButton>
42 #include <QSystemTrayIcon>
47 #include <QWidgetAction>
48 #include <QDockWidget>
56 #define SET_WIDTH(i,j) i->widgetSize.setWidth(j)
57 #define SET_HEIGHT(i,j) i->widgetSize.setHeight(j)
58 #define SET_WH( i,j,k) i->widgetSize.setWidth(j); i->widgetSize.setHeight(k);
60 #define DS(i) i.width(),i.height()
62 /* Callback prototypes */
63 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
64 vlc_value_t old_val, vlc_value_t new_val, void *param );
65 static int IntfShowCB( 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 InteractCallback( vlc_object_t *, const char *, vlc_value_t,
70 static void *DoRequest( intf_thread_t *p_intf, vout_thread_t *p_vout,
71 int *pi1, int *pi2, unsigned int*pi3,unsigned int*pi4)
73 return p_intf->p_sys->p_mi->requestVideo( p_vout, pi1, pi2, pi3, pi4 );
75 static void DoRelease( intf_thread_t *p_intf, void *p_win )
77 return p_intf->p_sys->p_mi->releaseVideo( p_win );
79 static int DoControl( intf_thread_t *p_intf, void *p_win, int i_q, va_list a )
81 return p_intf->p_sys->p_mi->controlVideo( p_win, i_q, a );
84 MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
86 /* Variables initialisation */
87 // need_components_update = false;
88 bgWidget = NULL; videoWidget = NULL; playlistWidget = NULL;
89 videoIsActive = false;
93 * Ask for the network policy on FIRST STARTUP
95 if( config_GetInt( p_intf, "privacy-ask") )
97 QList<ConfigControl *> controls;
98 if( privacyDialog( controls ) == QDialog::Accepted )
100 QList<ConfigControl *>::Iterator i;
101 for( i = controls.begin() ; i != controls.end() ; i++ )
103 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
104 c->doApply( p_intf );
107 config_PutInt( p_intf, "privacy-ask" , 0 );
108 config_SaveConfigFile( p_intf, NULL );
113 * Configuration and settings
115 settings = new QSettings( "vlc", "vlc-qt-interface" );
116 settings->beginGroup( "MainWindow" );
119 setFocusPolicy( Qt::StrongFocus );
120 setAcceptDrops( true );
121 setWindowIcon( QApplication::windowIcon() );
122 setWindowOpacity( config_GetFloat( p_intf, "qt-opacity" ) );
124 /* Set The Video In emebedded Mode or not */
125 videoEmbeddedFlag = false;
126 if( config_GetInt( p_intf, "embedded-video" ) ) videoEmbeddedFlag = true;
128 /* Are we in the enhanced always-video mode or not ? */
129 alwaysVideoFlag = false;
130 if( videoEmbeddedFlag && config_GetInt( p_intf, "qt-always-video" ) )
131 alwaysVideoFlag = true;
133 /* Set the other interface settings */
134 //FIXME I don't like that code
135 visualSelectorEnabled = settings->value( "visual-selector", false ).toBool();
136 notificationEnabled = config_GetInt( p_intf, "qt-notification" )
139 /**************************
140 * UI and Widgets design
141 **************************/
142 setVLCWindowsTitle();
143 handleMainUi( settings );
145 /* Create a Dock to get the playlist */
146 dockPL = new QDockWidget( qtr("Playlist"), this );
147 dockPL->setSizePolicy( QSizePolicy::Preferred,
148 QSizePolicy::MinimumExpanding );
149 dockPL->setFeatures( QDockWidget::AllDockWidgetFeatures );
150 dockPL->setAllowedAreas( Qt::LeftDockWidgetArea
151 | Qt::RightDockWidgetArea
152 | Qt::BottomDockWidgetArea );
157 QVLCMenu::createMenuBar( this, p_intf, visualSelectorEnabled );
163 /* Widgets Creation*/
164 b_remainingTime = false;
165 timeLabel = new TimeLabel;
166 nameLabel = new QLabel;
167 nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
168 | Qt::TextSelectableByKeyboard );
169 speedLabel = new QLabel( "1.00x" );
170 speedLabel->setContextMenuPolicy ( Qt::CustomContextMenu );
172 /* Styling those labels */
173 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
174 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
175 nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
177 /* and adding those */
178 statusBar()->addWidget( nameLabel, 8 );
179 statusBar()->addPermanentWidget( speedLabel, 0 );
180 statusBar()->addPermanentWidget( timeLabel, 2 );
182 /* timeLabel behaviour:
183 - double clicking opens the goto time dialog
184 - right-clicking and clicking just toggle between remaining and
186 CONNECT( timeLabel, timeLabelClicked(), this, toggleTimeDisplay() );
187 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
188 CONNECT( timeLabel, timeLabelDoubleClicked(), this, toggleTimeDisplay() );
190 /* Speed Label behaviour:
191 - right click gives the vertical speed slider */
192 CONNECT( speedLabel, customContextMenuRequested( QPoint ),
193 this, showSpeedMenu( QPoint ) );
195 /**********************
196 * Systray Management *
197 **********************/
199 bool b_createSystray = false;
200 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
201 if( config_GetInt( p_intf, "qt-start-minimized") )
203 if( b_systrayAvailable ){
204 b_createSystray = true;
205 hide(); //FIXME BUG HERE
207 else msg_Warn( p_intf, "You can't minize if you haven't a system "
210 if( config_GetInt( p_intf, "qt-system-tray") )
211 b_createSystray = true;
213 if( b_systrayAvailable && b_createSystray )
216 if( config_GetInt( p_intf, "qt-minimal-view" ) )
219 /* Init input manager */
220 MainInputManager::getInstance( p_intf );
221 ON_TIMEOUT( updateOnTimer() );
222 //ON_TIMEOUT( debug() ):;
224 /********************
226 ********************/
228 /* Connect the input manager to the GUI elements it manages */
229 /* It is also connected to the control->slider, see the ControlsWidget */
230 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
231 this, setDisplayPosition( float, int, int ) );
233 CONNECT( THEMIM->getIM(), rateChanged( int ), this, setRate( int ) );
236 * Connects on nameChanged()
238 /* Naming in the controller statusbar */
239 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
240 setName( QString ) );
241 /* and in the systray */
244 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
245 updateSystrayTooltipName( QString ) );
247 /* and in the title of the controller */
248 if( config_GetInt( p_intf, "qt-name-in-title" ) )
250 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
251 setVLCWindowsTitle( QString ) );
254 /** CONNECTS on PLAY_STATUS **/
255 /* Status on the main controller */
256 CONNECT( THEMIM->getIM(), statusChanged( int ), this, setStatus( int ) );
257 /* and in the systray */
260 CONNECT( THEMIM->getIM(), statusChanged( int ), this,
261 updateSystrayTooltipStatus( int ) );
267 var_Create( p_intf, "interaction", VLC_VAR_ADDRESS );
268 var_AddCallback( p_intf, "interaction", InteractCallback, this );
269 p_intf->b_interaction = VLC_TRUE;
271 /* Register callback for the intf-popupmenu variable */
272 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
273 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
274 if( p_playlist != NULL )
276 var_AddCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
277 var_AddCallback( p_playlist, "intf-show", IntfShowCB, p_intf );
278 vlc_object_release( p_playlist );
281 CONNECT( this, askReleaseVideo( void * ), this, releaseVideoSlot( void * ) );
283 CONNECT( dockPL, topLevelChanged( bool ), this, doComponentsUpdate() );
288 settings->endGroup();
291 MainInterface::~MainInterface()
293 if( playlistWidget ) playlistWidget->savingSettings( settings );
294 if( ExtendedDialog::exists() )
295 ExtendedDialog::getInstance( p_intf )->savingSettings();
297 settings->beginGroup( "MainWindow" );
298 settings->setValue( "playlist-floats", dockPL->isFloating() );
299 settings->setValue( "adv-controls", getControlsVisibilityStatus() & CONTROLS_ADVANCED );
300 settings->setValue( "pos", pos() );
302 settings->endGroup();
305 /* Unregister callback for the intf-popupmenu variable */
306 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
307 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
308 if( p_playlist != NULL )
310 var_DelCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
311 var_DelCallback( p_playlist, "intf-show", IntfShowCB, p_intf );
312 vlc_object_release( p_playlist );
315 p_intf->b_interaction = VLC_FALSE;
316 var_DelCallback( p_intf, "interaction", InteractCallback, this );
318 p_intf->pf_request_window = NULL;
319 p_intf->pf_release_window = NULL;
320 p_intf->pf_control_window = NULL;
323 /*****************************
325 *****************************/
328 * Give the decorations of the Main Window a correct Name.
329 * If nothing is given, set it to VLC...
331 void MainInterface::setVLCWindowsTitle( QString aTitle )
333 if( aTitle.isEmpty() )
335 setWindowTitle( qtr( "VLC media player" ) );
339 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
343 void MainInterface::handleMainUi( QSettings *settings )
345 /* Create the main Widget and the mainLayout */
346 QWidget *main = new QWidget;
347 setCentralWidget( main );
348 mainLayout = new QVBoxLayout( main );
350 /* Margins, spacing */
351 main->setContentsMargins( 0, 0, 0, 0 );
352 mainLayout->setMargin( 0 );
354 /* Create the CONTROLS Widget */
355 /* bool b_shiny = config_GetInt( p_intf, "qt-blingbling" ); */
356 controls = new ControlsWidget( p_intf, this,
357 settings->value( "adv-controls", false ).toBool(),
358 config_GetInt( p_intf, "qt-blingbling" ) );
360 /* Add the controls Widget to the main Widget */
361 mainLayout->insertWidget( 0, controls );
363 /* Create the Speed Control Widget */
364 speedControl = new SpeedControlWidget( p_intf );
365 speedControlMenu = new QMenu( this );
367 QWidgetAction *widgetAction = new QWidgetAction( speedControl );
368 widgetAction->setDefaultWidget( speedControl );
369 speedControlMenu->addAction( widgetAction );
372 /* Disabled for now, they SUCK */
374 visualSelector = new VisualSelector( p_intf );
375 mainLayout->insertWidget( 0, visualSelector );
376 visualSelector->hide();
379 /* And video Outputs */
380 if( alwaysVideoFlag )
382 bgWidget = new BackgroundWidget( p_intf );
383 bgWidget->widgetSize = settings->value( "backgroundSize",
384 QSize( 300, 200 ) ).toSize();
385 bgWidget->resize( bgWidget->widgetSize );
386 bgWidget->updateGeometry();
387 mainLayout->insertWidget( 0, bgWidget );
388 CONNECT( this, askBgWidgetToToggle(), bgWidget, toggle() );
391 if( videoEmbeddedFlag )
393 videoWidget = new VideoWidget( p_intf );
394 videoWidget->widgetSize = QSize( 1, 1 );
395 //videoWidget->resize( videoWidget->widgetSize );
396 mainLayout->insertWidget( 0, videoWidget );
398 p_intf->pf_request_window = ::DoRequest;
399 p_intf->pf_release_window = ::DoRelease;
400 p_intf->pf_control_window = ::DoControl;
403 /* Finish the sizing */
407 int MainInterface::privacyDialog( QList<ConfigControl *> controls )
409 QDialog *privacy = new QDialog( this );
411 privacy->setWindowTitle( qtr( "Privacy and Network policies" ) );
413 QGridLayout *gLayout = new QGridLayout( privacy );
415 QGroupBox *blabla = new QGroupBox( qtr( "Privacy and Network Warning" ) );
416 QGridLayout *blablaLayout = new QGridLayout( blabla );
417 QLabel *text = new QLabel( qtr(
418 "<p>The <i>VideoLAN Team</i> doesn't like when an application goes "
419 "online without authorisation.</p>\n "
420 "<p><i>VLC media player</i> can request limited information on "
421 "Internet, espically to get CD Covers and songs metadata or to know "
422 "if updates are available.</p>\n"
423 "<p><i>VLC media player</i> <b>DOES NOT</b> send or collect <b>ANY</b> "
424 "information, even anonymously about your "
426 "<p>Therefore please check the following options, the default being "
427 "almost no access on the web.</p>\n") );
428 text->setWordWrap( true );
429 text->setTextFormat( Qt::RichText );
431 blablaLayout->addWidget( text, 0, 0 ) ;
433 QGroupBox *options = new QGroupBox;
434 QGridLayout *optionsLayout = new QGridLayout( options );
436 gLayout->addWidget( blabla, 0, 0, 1, 3 );
437 gLayout->addWidget( options, 1, 0, 1, 3 );
438 module_config_t *p_config;
439 ConfigControl *control;
442 #define CONFIG_GENERIC( option, type ) \
443 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
446 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
447 p_config, options, false, optionsLayout, line ); \
448 controls.append( control ); \
451 #define CONFIG_GENERIC_NOBOOL( option, type ) \
452 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
455 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
456 p_config, options, optionsLayout, line ); \
457 controls.append( control ); \
460 CONFIG_GENERIC( "album-art", IntegerList ); line++;
461 CONFIG_GENERIC_NOBOOL( "fetch-meta", Bool ); line++;
462 CONFIG_GENERIC_NOBOOL( "qt-updates-notif", Bool );
464 QPushButton *ok = new QPushButton( qtr( "Ok" ) );
466 gLayout->addWidget( ok, 2, 2 );
468 CONNECT( ok, clicked(), privacy, accept() );
469 return privacy->exec();
472 //FIXME remove me at the end...
473 void MainInterface::debug()
475 msg_Dbg( p_intf, "size: %i - %i", controls->size().height(), controls->size().width() );
476 msg_Dbg( p_intf, "sizeHint: %i - %i", controls->sizeHint().height(), controls->sizeHint().width() );
479 /**********************************************************************
480 * Handling of sizing of the components
481 **********************************************************************/
483 /* This function is probably wrong, but we don't have many many choices...
484 Since we can't know from the playlist Widget if we are inside a dock or not,
485 because the playlist Widget can be called by THEDP, as a separate windows for
487 Maybe the other solution is to redefine the sizeHint() of the playlist and
488 ask _parent->isFloating()...
489 If you think this would be better, please FIX it...
491 QSize MainInterface::sizeHint() const
493 QSize tempSize = controls->sizeHint() +
494 QSize( 100, menuBar()->size().height() + statusBar()->size().height() );
496 if( VISIBLE( bgWidget ) )
497 tempSize += bgWidget->sizeHint();
498 else if( videoIsActive )
499 tempSize += videoWidget->size();
501 if( !dockPL->isFloating() && dockPL->widget() )
502 tempSize += dockPL->widget()->size();
508 /* FIXME This is dead code and need to be removed AT THE END */
509 void MainInterface::resizeEvent( QResizeEvent *e )
512 videoWidget->widgetSize.setWidth( e->size().width() - addSize.width() );
513 if( videoWidget && videoIsActive && videoWidget->widgetSize.height() > 1 )
515 SET_WH( videoWidget, e->size().width() - addSize.width(),
516 e->size().height() - addSize.height() );
517 videoWidget->updateGeometry();
519 if( VISIBLE( playlistWidget ) )
522 // SET_WH( playlistWidget , e->size().width() - addSize.width(),
523 // e->size().height() - addSize.height() );
524 playlistWidget->updateGeometry();
529 /****************************************************************************
530 * Small right-click menu for rate control
531 ****************************************************************************/
532 void MainInterface::showSpeedMenu( QPoint pos )
534 speedControlMenu->exec( QCursor::pos() - pos
535 + QPoint( 0, speedLabel->height() ) );
538 /****************************************************************************
540 ****************************************************************************/
541 class SetVideoOnTopQtEvent : public QEvent
544 SetVideoOnTopQtEvent( bool _onTop ) :
545 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
557 void *MainInterface::requestVideo( vout_thread_t *p_nvout, int *pi_x,
558 int *pi_y, unsigned int *pi_width,
559 unsigned int *pi_height )
561 void *ret = videoWidget->request( p_nvout,pi_x, pi_y, pi_width, pi_height );
564 videoIsActive = true;
565 bool bgWasVisible = false;
567 /* Did we have a bg ? */
568 if( VISIBLE( bgWidget) )
571 emit askBgWidgetToToggle();
574 if( THEMIM->getIM()->hasVideo() || !bgWasVisible )
576 videoWidget->widgetSize = QSize( *pi_width, *pi_height );
578 else /* Background widget available, use its size */
580 /* Ok, our visualizations are bad, so don't do this for the moment
581 * use the requested size anyway */
582 // videoWidget->widgetSize = bgWidget->widgeTSize;
583 videoWidget->widgetSize = QSize( *pi_width, *pi_height );
585 videoWidget->updateGeometry(); // Needed for deinterlace
591 void MainInterface::releaseVideo( void *p_win )
593 emit askReleaseVideo( p_win );
596 void MainInterface::releaseVideoSlot( void *p_win )
598 videoWidget->release( p_win );
604 videoIsActive = false;
608 int MainInterface::controlVideo( void *p_window, int i_query, va_list args )
610 int i_ret = VLC_EGENERIC;
615 unsigned int *pi_width = va_arg( args, unsigned int * );
616 unsigned int *pi_height = va_arg( args, unsigned int * );
617 *pi_width = videoWidget->widgetSize.width();
618 *pi_height = videoWidget->widgetSize.height();
624 unsigned int i_width = va_arg( args, unsigned int );
625 unsigned int i_height = va_arg( args, unsigned int );
626 videoWidget->widgetSize = QSize( i_width, i_height );
627 videoWidget->updateGeometry();
632 case VOUT_SET_STAY_ON_TOP:
634 int i_arg = va_arg( args, int );
635 QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
640 msg_Warn( p_intf, "unsupported control query" );
646 /*****************************************************************************
647 * Playlist, Visualisation and Menus handling
648 *****************************************************************************/
650 * Toggle the playlist widget or dialog
652 void MainInterface::togglePlaylist()
655 If no playlist exist, then create one and attach it to the DockPL*/
656 if( !playlistWidget )
658 msg_Dbg( p_intf, "Creating a new playlist" );
659 playlistWidget = new PlaylistWidget( p_intf, settings );
661 CONNECT( playlistWidget, artSet( QString ),
662 bgWidget, setArt(QString) );
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 //FIXME Remove this function at the end...
799 void MainInterface::updateOnTimer()
801 /* if( intf_ShouldDie( p_intf ) )
803 QApplication::closeAllWindows();
804 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;