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>
59 #define SET_WIDTH(i,j) i->widgetSize.setWidth(j)
60 #define SET_HEIGHT(i,j) i->widgetSize.setHeight(j)
61 #define SET_WH( i,j,k) i->widgetSize.setWidth(j); i->widgetSize.setHeight(k);
63 #define DS(i) i.width(),i.height()
65 /* Callback prototypes */
66 static int PopupMenuCB( 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 IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
69 vlc_value_t old_val, vlc_value_t new_val, void *param );
70 static int InteractCallback( vlc_object_t *, const char *, vlc_value_t,
73 static void *DoRequest( intf_thread_t *p_intf, vout_thread_t *p_vout,
74 int *pi1, int *pi2, unsigned int*pi3,unsigned int*pi4)
76 return p_intf->p_sys->p_mi->requestVideo( p_vout, pi1, pi2, pi3, pi4 );
78 static void DoRelease( intf_thread_t *p_intf, void *p_win )
80 return p_intf->p_sys->p_mi->releaseVideo( p_win );
82 static int DoControl( intf_thread_t *p_intf, void *p_win, int i_q, va_list a )
84 return p_intf->p_sys->p_mi->controlVideo( p_win, i_q, a );
87 MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
89 /* Variables initialisation */
90 // need_components_update = false;
91 bgWidget = NULL; videoWidget = NULL; playlistWidget = NULL;
92 videoIsActive = false;
99 * Configuration and settings
101 settings = new QSettings( "vlc", "vlc-qt-interface" );
102 settings->beginGroup( "MainWindow" );
105 setFocusPolicy( Qt::StrongFocus );
106 setAcceptDrops( true );
107 setWindowIcon( QApplication::windowIcon() );
108 setWindowOpacity( config_GetFloat( p_intf, "qt-opacity" ) );
110 /* Set The Video In emebedded Mode or not */
111 videoEmbeddedFlag = false;
112 if( config_GetInt( p_intf, "embedded-video" ) ) videoEmbeddedFlag = true;
114 /* Are we in the enhanced always-video mode or not ? */
115 alwaysVideoFlag = false;
116 if( videoEmbeddedFlag && config_GetInt( p_intf, "qt-always-video" ) )
117 alwaysVideoFlag = true;
119 /* Set the other interface settings */
120 //TODO: I don't like that code
121 visualSelectorEnabled = settings->value( "visual-selector", false ).toBool();
122 notificationEnabled = config_GetInt( p_intf, "qt-notification" )
125 /**************************
126 * UI and Widgets design
127 **************************/
128 setVLCWindowsTitle();
129 handleMainUi( settings );
131 /* Create a Dock to get the playlist */
132 dockPL = new QDockWidget( qtr( "Playlist" ), this );
133 dockPL->setSizePolicy( QSizePolicy::Preferred,
134 QSizePolicy::Expanding );
135 dockPL->setFeatures( QDockWidget::AllDockWidgetFeatures );
136 dockPL->setAllowedAreas( Qt::LeftDockWidgetArea
137 | Qt::RightDockWidgetArea
138 | Qt::BottomDockWidgetArea );
144 QVLCMenu::createMenuBar( this, p_intf, visualSelectorEnabled );
149 /* Widgets Creation*/
150 b_remainingTime = false;
151 timeLabel = new TimeLabel;
152 nameLabel = new QLabel;
153 nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
154 | Qt::TextSelectableByKeyboard );
155 speedLabel = new QLabel( "1.00x" );
156 speedLabel->setContextMenuPolicy ( Qt::CustomContextMenu );
158 /* Styling those labels */
159 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
160 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
161 nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
163 /* and adding those */
164 statusBar()->addWidget( nameLabel, 8 );
165 statusBar()->addPermanentWidget( speedLabel, 0 );
166 statusBar()->addPermanentWidget( timeLabel, 2 );
168 /* timeLabel behaviour:
169 - double clicking opens the goto time dialog
170 - right-clicking and clicking just toggle between remaining and
172 CONNECT( timeLabel, timeLabelClicked(), this, toggleTimeDisplay() );
173 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
174 CONNECT( timeLabel, timeLabelDoubleClicked(), this, toggleTimeDisplay() );
176 /* Speed Label behaviour:
177 - right click gives the vertical speed slider */
178 CONNECT( speedLabel, customContextMenuRequested( QPoint ),
179 this, showSpeedMenu( QPoint ) );
181 /**********************
182 * Systray Management *
183 **********************/
185 bool b_createSystray = false;
186 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
187 if( config_GetInt( p_intf, "qt-start-minimized") )
189 if( b_systrayAvailable ){
190 b_createSystray = true;
191 hide(); //FIXME BUG HERE
193 else msg_Warn( p_intf, "You can't minize if you haven't a system "
196 if( config_GetInt( p_intf, "qt-system-tray") )
197 b_createSystray = true;
199 if( b_systrayAvailable && b_createSystray )
202 if( config_GetInt( p_intf, "qt-minimal-view" ) )
205 /********************
207 ********************/
208 MainInputManager::getInstance( p_intf );
210 /********************
212 ********************/
213 /* Connect the input manager to the GUI elements it manages */
215 /* It is also connected to the control->slider, see the ControlsWidget */
216 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
217 this, setDisplayPosition( float, int, int ) );
218 /* Change the SpeedRate in the Status */
219 CONNECT( THEMIM->getIM(), rateChanged( int ), this, setRate( int ) );
222 * Connects on nameChanged()
223 * Those connects are not merged because different options can trigger
226 /* Naming in the controller statusbar */
227 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
228 setName( QString ) );
229 /* and in the systray */
232 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
233 updateSystrayTooltipName( QString ) );
235 /* and in the title of the controller */
236 if( config_GetInt( p_intf, "qt-name-in-title" ) )
238 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
239 setVLCWindowsTitle( QString ) );
243 * CONNECTS on PLAY_STATUS
245 /* Status on the main controller */
246 CONNECT( THEMIM->getIM(), statusChanged( int ), this, setStatus( int ) );
247 /* and in the systray */
250 CONNECT( THEMIM->getIM(), statusChanged( int ), this,
251 updateSystrayTooltipStatus( int ) );
256 ON_TIMEOUT( updateOnTimer() );
257 //ON_TIMEOUT( debug() );
262 var_Create( p_intf, "interaction", VLC_VAR_ADDRESS );
263 var_AddCallback( p_intf, "interaction", InteractCallback, this );
264 p_intf->b_interaction = VLC_TRUE;
266 /* Register callback for the intf-popupmenu variable */
267 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
268 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
269 if( p_playlist != NULL )
271 var_AddCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
272 var_AddCallback( p_playlist, "intf-show", IntfShowCB, p_intf );
273 vlc_object_release( p_playlist );
276 /* VideoWidget connect mess to avoid different threads speaking to each other */
277 CONNECT( this, askReleaseVideo( void * ), this, releaseVideoSlot( void * ) );
278 CONNECT( this, askVideoToResize( unsigned int, unsigned int ),
279 videoWidget, SetSizing( unsigned int, unsigned int ) );
280 CONNECT( this, askUpdate(), this, doComponentsUpdate() );
282 CONNECT( dockPL, topLevelChanged( bool ), this, doComponentsUpdate() );
283 CONNECT( controls, advancedControlsToggled( bool ),
284 this, doComponentsUpdate() );
286 move( settings->value( "pos", QPoint( 0, 0 ) ).toPoint() );
288 resize( settings->value( "size", QSize( 350, 60 ) ).toSize() );
291 settings->endGroup();
294 MainInterface::~MainInterface()
296 if( playlistWidget ) playlistWidget->savingSettings( settings );
297 if( ExtendedDialog::exists() )
298 ExtendedDialog::getInstance( p_intf )->savingSettings();
300 settings->beginGroup( "MainWindow" );
301 settings->setValue( "playlist-floats", dockPL->isFloating() );
302 settings->setValue( "adv-controls",
303 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
304 settings->setValue( "pos", pos() );
305 settings->setValue( "size", size() );
307 settings->endGroup();
310 /* Unregister callback for the intf-popupmenu variable */
311 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
312 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
313 if( p_playlist != NULL )
315 var_DelCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
316 var_DelCallback( p_playlist, "intf-show", IntfShowCB, p_intf );
317 vlc_object_release( p_playlist );
320 p_intf->b_interaction = VLC_FALSE;
321 var_DelCallback( p_intf, "interaction", InteractCallback, this );
323 p_intf->pf_request_window = NULL;
324 p_intf->pf_release_window = NULL;
325 p_intf->pf_control_window = NULL;
328 /*****************************
330 *****************************/
333 * Give the decorations of the Main Window a correct Name.
334 * If nothing is given, set it to VLC...
336 void MainInterface::setVLCWindowsTitle( QString aTitle )
338 if( aTitle.isEmpty() )
340 setWindowTitle( qtr( "VLC media player" ) );
344 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
348 void MainInterface::handleMainUi( QSettings *settings )
350 /* Create the main Widget and the mainLayout */
351 QWidget *main = new QWidget;
352 setCentralWidget( main );
353 mainLayout = new QVBoxLayout( main );
355 /* Margins, spacing */
356 main->setContentsMargins( 0, 0, 0, 0 );
357 // main->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
358 mainLayout->setMargin( 0 );
360 /* Create the CONTROLS Widget */
361 /* bool b_shiny = config_GetInt( p_intf, "qt-blingbling" ); */
362 controls = new ControlsWidget( p_intf, this,
363 settings->value( "adv-controls", false ).toBool(),
364 config_GetInt( p_intf, "qt-blingbling" ) );
366 /* Add the controls Widget to the main Widget */
367 mainLayout->insertWidget( 0, controls );
369 /* Create the Speed Control Widget */
370 speedControl = new SpeedControlWidget( p_intf );
371 speedControlMenu = new QMenu( this );
373 QWidgetAction *widgetAction = new QWidgetAction( speedControl );
374 widgetAction->setDefaultWidget( speedControl );
375 speedControlMenu->addAction( widgetAction );
378 /* Disabled for now, they SUCK */
380 visualSelector = new VisualSelector( p_intf );
381 mainLayout->insertWidget( 0, visualSelector );
382 visualSelector->hide();
385 /* And video Outputs */
386 if( alwaysVideoFlag )
388 bgWidget = new BackgroundWidget( p_intf );
389 bgWidget->widgetSize = settings->value( "backgroundSize",
390 QSize( 300, 200 ) ).toSize();
391 bgWidget->resize( bgWidget->widgetSize );
392 bgWidget->updateGeometry();
393 mainLayout->insertWidget( 0, bgWidget );
394 CONNECT( this, askBgWidgetToToggle(), bgWidget, toggle() );
397 if( videoEmbeddedFlag )
399 videoWidget = new VideoWidget( p_intf );
400 //videoWidget->widgetSize = QSize( 16, 16 );
401 //videoWidget->hide();
402 //videoWidget->resize( videoWidget->widgetSize );
403 mainLayout->insertWidget( 0, videoWidget );
405 p_intf->pf_request_window = ::DoRequest;
406 p_intf->pf_release_window = ::DoRelease;
407 p_intf->pf_control_window = ::DoControl;
410 /* Finish the sizing */
414 inline void MainInterface::privacy()
417 * Ask for the network policy on FIRST STARTUP
419 if( config_GetInt( p_intf, "privacy-ask") )
421 QList<ConfigControl *> controls;
422 if( privacyDialog( controls ) == QDialog::Accepted )
424 QList<ConfigControl *>::Iterator i;
425 for( i = controls.begin() ; i != controls.end() ; i++ )
427 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
428 c->doApply( p_intf );
431 config_PutInt( p_intf, "privacy-ask" , 0 );
432 config_SaveConfigFile( p_intf, NULL );
437 int MainInterface::privacyDialog( QList<ConfigControl *> controls )
439 QDialog *privacy = new QDialog( this );
441 privacy->setWindowTitle( qtr( "Privacy and Network policies" ) );
443 QGridLayout *gLayout = new QGridLayout( privacy );
445 QGroupBox *blabla = new QGroupBox( qtr( "Privacy and Network Warning" ) );
446 QGridLayout *blablaLayout = new QGridLayout( blabla );
447 QLabel *text = new QLabel( qtr(
448 "<p>The <i>VideoLAN Team</i> doesn't like when an application goes "
449 "online without authorisation.</p>\n "
450 "<p><i>VLC media player</i> can request limited information on "
451 "Internet, espically to get CD Covers and songs metadata or to know "
452 "if updates are available.</p>\n"
453 "<p><i>VLC media player</i> <b>DOES NOT</b> send or collect <b>ANY</b> "
454 "information, even anonymously about your "
456 "<p>Therefore please check the following options, the default being "
457 "almost no access on the web.</p>\n") );
458 text->setWordWrap( true );
459 text->setTextFormat( Qt::RichText );
461 blablaLayout->addWidget( text, 0, 0 ) ;
463 QGroupBox *options = new QGroupBox;
464 QGridLayout *optionsLayout = new QGridLayout( options );
466 gLayout->addWidget( blabla, 0, 0, 1, 3 );
467 gLayout->addWidget( options, 1, 0, 1, 3 );
468 module_config_t *p_config;
469 ConfigControl *control;
472 #define CONFIG_GENERIC( option, type ) \
473 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
476 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
477 p_config, options, false, optionsLayout, line ); \
478 controls.append( control ); \
481 #define CONFIG_GENERIC_NOBOOL( option, type ) \
482 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
485 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
486 p_config, options, optionsLayout, line ); \
487 controls.append( control ); \
490 CONFIG_GENERIC( "album-art", IntegerList ); line++;
491 CONFIG_GENERIC_NOBOOL( "fetch-meta", Bool ); line++;
492 CONFIG_GENERIC_NOBOOL( "qt-updates-notif", Bool );
494 QPushButton *ok = new QPushButton( qtr( "Ok" ) );
496 gLayout->addWidget( ok, 2, 2 );
498 CONNECT( ok, clicked(), privacy, accept() );
499 return privacy->exec();
502 //FIXME remove me at the end...
503 void MainInterface::debug()
505 msg_Dbg( p_intf, "size: %i - %i", controls->size().height(), controls->size().width() );
506 msg_Dbg( p_intf, "sizeHint: %i - %i", controls->sizeHint().height(), controls->sizeHint().width() );
509 /**********************************************************************
510 * Handling of sizing of the components
511 **********************************************************************/
513 /* This function is probably wrong, but we don't have many many choices...
514 Since we can't know from the playlist Widget if we are inside a dock or not,
515 because the playlist Widget can be called by THEDP, as a separate windows for
517 Maybe the other solution is to redefine the sizeHint() of the playlist and
518 ask _parent->isFloating()...
519 If you think this would be better, please FIXME it...
521 QSize MainInterface::sizeHint() const
523 int nwidth = controls->sizeHint().width();
524 int nheight = controls->sizeHint().height()
525 + menuBar()->size().height()
526 + statusBar()->size().height();
528 msg_Dbg( p_intf, "1 %i %i", nheight, nwidth );
529 if( VISIBLE( bgWidget ) )
531 nheight += bgWidget->size().height();
532 nwidth = bgWidget->size().width();
534 else if( videoIsActive )
536 nheight += videoWidget->size().height();
537 nwidth = videoWidget->size().width();
538 msg_Dbg( p_intf, "2 %i %i", nheight, nwidth );
540 if( !dockPL->isFloating() && dockPL->widget() )
542 nheight += dockPL->size().height();
543 nwidth = MAX( nwidth, dockPL->size().width() );
544 msg_Dbg( p_intf, "3 %i %i", nheight, nwidth );
546 msg_Dbg( p_intf, "4 %i %i", nheight, nwidth );
547 return QSize( nwidth, nheight );
551 /* FIXME This is dead code and need to be removed AT THE END */
552 void MainInterface::resizeEvent( QResizeEvent *e )
555 videoWidget->widgetSize.setWidth( e->size().width() - addSize.width() );
556 if( videoWidget && videoIsActive && videoWidget->widgetSize.height() > 1 )
558 SET_WH( videoWidget, e->size().width() - addSize.width(),
559 e->size().height() - addSize.height() );
560 videoWidget->updateGeometry();
562 if( VISIBLE( playlistWidget ) )
564 // SET_WH( playlistWidget , e->size().width() - addSize.width(),
565 // e->size().height() - addSize.height() );
566 playlistWidget->updateGeometry();
571 /****************************************************************************
572 * Small right-click menu for rate control
573 ****************************************************************************/
574 void MainInterface::showSpeedMenu( QPoint pos )
576 speedControlMenu->exec( QCursor::pos() - pos
577 + QPoint( 0, speedLabel->height() ) );
580 /****************************************************************************
582 ****************************************************************************/
583 class SetVideoOnTopQtEvent : public QEvent
586 SetVideoOnTopQtEvent( bool _onTop ) :
587 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
599 /* function called from ::DoRequest in order to show a nice VideoWidget
601 void *MainInterface::requestVideo( vout_thread_t *p_nvout, int *pi_x,
602 int *pi_y, unsigned int *pi_width,
603 unsigned int *pi_height )
605 bool bgWasVisible = false;
607 /* Request the videoWidget */
608 void *ret = videoWidget->request( p_nvout,pi_x, pi_y, pi_width, pi_height );
609 if( ret ) /* The videoWidget is available */
611 /* Did we have a bg ? Hide it! */
612 if( VISIBLE( bgWidget) )
615 emit askBgWidgetToToggle();
618 /*if( THEMIM->getIM()->hasVideo() || !bgWasVisible )
620 videoWidget->widgetSize = QSize( *pi_width, *pi_height );
622 else /* Background widget available, use its size */
624 /* Ok, our visualizations are bad, so don't do this for the moment
625 * use the requested size anyway */
626 // videoWidget->widgetSize = bgWidget->widgeTSize;
627 /* videoWidget->widgetSize = QSize( *pi_width, *pi_height );
630 videoIsActive = true;
632 emit askVideoToResize( *pi_width, *pi_height );
638 void MainInterface::releaseVideo( void *p_win )
640 emit askReleaseVideo( p_win );
643 void MainInterface::releaseVideoSlot( void *p_win )
645 videoWidget->release( p_win );
648 if( bgWidget )// WORONG
651 videoIsActive = false;
655 int MainInterface::controlVideo( void *p_window, int i_query, va_list args )
657 int i_ret = VLC_EGENERIC;
662 unsigned int *pi_width = va_arg( args, unsigned int * );
663 unsigned int *pi_height = va_arg( args, unsigned int * );
664 *pi_width = videoWidget->widgetSize.width();
665 *pi_height = videoWidget->widgetSize.height();
671 unsigned int i_width = va_arg( args, unsigned int );
672 unsigned int i_height = va_arg( args, unsigned int );
673 emit askVideoToResize( i_width, i_height );
679 case VOUT_SET_STAY_ON_TOP:
681 int i_arg = va_arg( args, int );
682 QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
687 msg_Warn( p_intf, "unsupported control query" );
693 /*****************************************************************************
694 * Playlist, Visualisation and Menus handling
695 *****************************************************************************/
697 * Toggle the playlist widget or dialog
699 void MainInterface::togglePlaylist()
702 If no playlist exist, then create one and attach it to the DockPL*/
703 if( !playlistWidget )
705 playlistWidget = new PlaylistWidget( p_intf, settings );
707 /* Add it to the parent DockWidget */
708 dockPL->setWidget( playlistWidget );
710 /* Add the dock to the main Interface */
711 addDockWidget( Qt::BottomDockWidgetArea, dockPL );
713 /* Make the playlist floating is requested. Default is not. */
715 if( settings->value( "playlist-floats", false ).toBool() );
717 msg_Dbg( p_intf, "we don't want the playlist inside");
718 dockPL->setFloating( true );
724 /* toggle the visibility of the playlist */
726 //resize(sizeHint());
729 doComponentsUpdate();
734 /* Function called from the menu to undock the playlist */
735 void MainInterface::undockPlaylist()
737 dockPL->setFloating( true );
741 void MainInterface::toggleMinimalView()
743 TOGGLEV( menuBar() );
745 TOGGLEV( statusBar() );
749 /* Video widget cannot do this synchronously as it runs in another thread */
750 /* Well, could it, actually ? Probably dangerous ... */
751 void MainInterface::doComponentsUpdate()
753 msg_Dbg( p_intf, "Updating the geometry" );
755 resize( sizeHint() );
758 /* toggling advanced controls buttons */
759 void MainInterface::toggleAdvanced()
761 controls->toggleAdvanced();
764 /* Get the visibility status of the controls (hidden or not, advanced or not) */
765 int MainInterface::getControlsVisibilityStatus()
767 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
768 + CONTROLS_ADVANCED * controls->b_advancedVisible );
772 void MainInterface::visual()
774 if( !VISIBLE( visualSelector) )
776 visualSelector->show();
777 if( !THEMIM->getIM()->hasVideo() )
779 /* Show the background widget */
781 visualSelectorEnabled = true;
785 /* Stop any currently running visualization */
786 visualSelector->hide();
787 visualSelectorEnabled = false;
789 doComponentsUpdate();
793 /************************************************************************
795 ************************************************************************/
796 void MainInterface::setDisplayPosition( float pos, int time, int length )
798 char psz_length[MSTRTIME_MAX_SIZE], psz_time[MSTRTIME_MAX_SIZE];
799 secstotimestr( psz_length, length );
800 secstotimestr( psz_time, ( b_remainingTime && length ) ? length - time
804 title.sprintf( "%s/%s", psz_time,
805 ( !length && time ) ? "--:--" : psz_length );
807 /* Add a minus to remaining time*/
808 if( b_remainingTime && length ) timeLabel->setText( " -"+title+" " );
809 else timeLabel->setText( " "+title+" " );
812 void MainInterface::toggleTimeDisplay()
814 b_remainingTime = !b_remainingTime;
817 void MainInterface::setName( QString name )
819 input_name = name; /* store it for the QSystray use */
820 /* Display it in the status bar, but also as a Tooltip in case it doesn't
822 nameLabel->setText( " " + name + " " );
823 nameLabel->setToolTip( " " + name +" " );
826 void MainInterface::setStatus( int status )
828 /* Forward the status to the controls to toggle Play/Pause */
829 controls->setStatus( status );
830 /* And in the systray for the menu */
832 QVLCMenu::updateSystrayMenu( this, p_intf );
835 void MainInterface::setRate( int rate )
838 str.setNum( ( 1000 / (double)rate ), 'f', 2 );
840 speedLabel->setText( str );
841 speedControl->updateControls( rate );
844 void MainInterface::updateOnTimer()
846 if( intf_ShouldDie( p_intf ) )
848 QApplication::closeAllWindows();
849 QApplication::quit();
852 if( need_components_update )
854 doComponentsUpdate();
855 need_components_update = false;
859 controls->updateOnTimer();
862 /*****************************************************************************
863 * Systray Icon and Systray Menu
864 *****************************************************************************/
867 * Create a SystemTray icon and a menu that would go with it.
868 * Connects to a click handler on the icon.
870 void MainInterface::createSystray()
873 if( QDate::currentDate().dayOfYear() >= 354 )
874 iconVLC = QIcon( QPixmap( ":/vlc128-christmas.png" ) );
876 iconVLC = QIcon( QPixmap( ":/vlc128.png" ) );
877 sysTray = new QSystemTrayIcon( iconVLC, this );
878 sysTray->setToolTip( qtr( "VLC media player" ));
880 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
881 systrayMenu->setIcon( iconVLC );
883 QVLCMenu::updateSystrayMenu( this, p_intf, true );
886 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
887 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
891 * Updates the Systray Icon's menu and toggle the main interface
893 void MainInterface::toggleUpdateSystrayMenu()
895 /* If hidden, show it */
901 else if( isMinimized() )
911 /* check if any visible window is above vlc in the z-order,
912 * but ignore the ones always on top */
915 wi.cbSize = sizeof( WINDOWINFO );
916 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
917 hwnd && !IsWindowVisible( hwnd );
918 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
919 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
920 (wi.dwExStyle&WS_EX_TOPMOST) )
922 if( isActiveWindow() )
932 QVLCMenu::updateSystrayMenu( this, p_intf );
935 void MainInterface::handleSystrayClick(
936 QSystemTrayIcon::ActivationReason reason )
940 case QSystemTrayIcon::Trigger:
941 toggleUpdateSystrayMenu();
943 case QSystemTrayIcon::MiddleClick:
944 sysTray->showMessage( qtr( "VLC media player" ),
945 qtr( "Control menu for the player" ),
946 QSystemTrayIcon::Information, 3000 );
952 * Updates the name of the systray Icon tooltip.
953 * Doesn't check if the systray exists, check before you call it.
955 void MainInterface::updateSystrayTooltipName( QString name )
959 sysTray->setToolTip( qtr( "VLC media player" ) );
963 sysTray->setToolTip( name );
964 if( notificationEnabled && ( isHidden() || isMinimized() ) )
966 sysTray->showMessage( qtr( "VLC media player" ), name,
967 QSystemTrayIcon::NoIcon, 3000 );
973 * Updates the status of the systray Icon tooltip.
974 * Doesn't check if the systray exists, check before you call it.
976 void MainInterface::updateSystrayTooltipStatus( int i_status )
983 sysTray->setToolTip( qtr( "VLC media player" ) );
988 sysTray->setToolTip( input_name );
993 sysTray->setToolTip( input_name + " - "
1000 /************************************************************************
1002 ************************************************************************/
1003 void MainInterface::dropEvent(QDropEvent *event)
1005 const QMimeData *mimeData = event->mimeData();
1007 /* D&D of a subtitles file, add it on the fly */
1008 if( mimeData->urls().size() == 1 )
1010 if( THEMIM->getIM()->hasInput() )
1012 if( input_AddSubtitles( THEMIM->getInput(),
1013 qtu( mimeData->urls()[0].toString() ),
1016 event->acceptProposedAction();
1022 foreach( QUrl url, mimeData->urls() ) {
1023 QString s = url.toString();
1024 if( s.length() > 0 ) {
1025 playlist_Add( THEPL, qtu(s), NULL,
1026 PLAYLIST_APPEND | (first ? PLAYLIST_GO:0),
1027 PLAYLIST_END, VLC_TRUE, VLC_FALSE );
1031 event->acceptProposedAction();
1033 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1035 event->acceptProposedAction();
1037 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1039 event->acceptProposedAction();
1041 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1046 /************************************************************************
1048 ************************************************************************/
1049 void MainInterface::customEvent( QEvent *event )
1052 if( event->type() == PLDockEvent_Type )
1054 PlaylistDialog::killInstance();
1055 playlistEmbeddedFlag = true;
1057 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1062 if ( event->type() == SetVideoOnTopEvent_Type )
1064 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1065 if( p_event->OnTop() )
1066 setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
1068 setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint);
1069 show(); /* necessary to apply window flags?? */
1073 void MainInterface::keyPressEvent( QKeyEvent *e )
1075 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() & Qt::Key_H )
1076 && menuBar()->isHidden() )
1078 toggleMinimalView();
1082 int i_vlck = qtEventToVLCKey( e );
1085 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1092 void MainInterface::wheelEvent( QWheelEvent *e )
1094 int i_vlckey = qtWheelEventToVLCKey( e );
1095 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1099 void MainInterface::closeEvent( QCloseEvent *e )
1102 vlc_object_kill( p_intf );
1103 QApplication::closeAllWindows();
1104 QApplication::quit();
1107 /*****************************************************************************
1109 *****************************************************************************/
1110 static int InteractCallback( vlc_object_t *p_this,
1111 const char *psz_var, vlc_value_t old_val,
1112 vlc_value_t new_val, void *param )
1114 intf_dialog_args_t *p_arg = new intf_dialog_args_t;
1115 p_arg->p_dialog = (interaction_dialog_t *)(new_val.p_address);
1116 DialogEvent *event = new DialogEvent( INTF_DIALOG_INTERACTION, 0, p_arg );
1117 QApplication::postEvent( THEDP, static_cast<QEvent*>(event) );
1121 /*****************************************************************************
1122 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1123 * We don't show the menu directly here because we don't want the
1124 * caller to block for a too long time.
1125 *****************************************************************************/
1126 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1127 vlc_value_t old_val, vlc_value_t new_val, void *param )
1129 intf_thread_t *p_intf = (intf_thread_t *)param;
1131 if( p_intf->pf_show_dialog )
1133 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1134 new_val.b_bool, 0 );
1140 /*****************************************************************************
1141 * IntfShowCB: callback triggered by the intf-show playlist variable.
1142 *****************************************************************************/
1143 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1144 vlc_value_t old_val, vlc_value_t new_val, void *param )
1146 intf_thread_t *p_intf = (intf_thread_t *)param;
1147 //p_intf->p_sys->b_intf_show = VLC_TRUE;