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 *****************************************************************************/
30 #include "main_interface.hpp"
31 #include "input_manager.hpp"
32 #include "util/qvlcframe.hpp"
33 #include "util/customwidgets.hpp"
34 #include "dialogs_provider.hpp"
35 #include "components/interface_widgets.hpp"
36 #include "components/playlist/playlist.hpp"
37 #include "dialogs/extended.hpp"
38 #include "dialogs/playlist.hpp"
42 #include <QCloseEvent>
43 #include <QPushButton>
47 #include <QSystemTrayIcon>
52 #include <QWidgetAction>
53 #include <QDockWidget>
57 #include <QProgressBar>
63 #define SET_WIDTH(i,j) i->widgetSize.setWidth(j)
64 #define SET_HEIGHT(i,j) i->widgetSize.setHeight(j)
65 #define SET_WH( i,j,k) i->widgetSize.setWidth(j); i->widgetSize.setHeight(k);
67 #define DS(i) i.width(),i.height()
69 /* Callback prototypes */
70 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
71 vlc_value_t old_val, vlc_value_t new_val, void *param );
72 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
73 vlc_value_t old_val, vlc_value_t new_val, void *param );
74 static int InteractCallback( vlc_object_t *, const char *, vlc_value_t,
77 static void *DoRequest( intf_thread_t *p_intf, vout_thread_t *p_vout,
78 int *pi1, int *pi2, unsigned int*pi3,unsigned int*pi4)
80 return p_intf->p_sys->p_mi->requestVideo( p_vout, pi1, pi2, pi3, pi4 );
82 static void DoRelease( intf_thread_t *p_intf, void *p_win )
84 return p_intf->p_sys->p_mi->releaseVideo( p_win );
86 static int DoControl( intf_thread_t *p_intf, void *p_win, int i_q, va_list a )
88 return p_intf->p_sys->p_mi->controlVideo( p_win, i_q, a );
91 MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
93 /* Variables initialisation */
94 // need_components_update = false;
95 bgWidget = NULL; videoWidget = NULL; playlistWidget = NULL;
96 videoIsActive = false;
98 playlistVisible = false;
100 /* Ask for privacy */
104 * Configuration and settings
106 settings = new QSettings( "vlc", "vlc-qt-interface" );
107 settings->beginGroup( "MainWindow" );
110 setFocusPolicy( Qt::StrongFocus );
111 setAcceptDrops( true );
112 setWindowIcon( QApplication::windowIcon() );
113 setWindowOpacity( config_GetFloat( p_intf, "qt-opacity" ) );
115 /* Set The Video In emebedded Mode or not */
116 videoEmbeddedFlag = false;
117 if( config_GetInt( p_intf, "embedded-video" ) ) videoEmbeddedFlag = true;
119 /* Are we in the enhanced always-video mode or not ? */
120 alwaysVideoFlag = false;
121 if( videoEmbeddedFlag && config_GetInt( p_intf, "qt-always-video" ) )
122 alwaysVideoFlag = true;
124 /* Set the other interface settings */
125 //TODO: I don't like that code
126 visualSelectorEnabled = settings->value( "visual-selector", false ).toBool();
127 notificationEnabled = config_GetInt( p_intf, "qt-notification" )
130 /**************************
131 * UI and Widgets design
132 **************************/
133 setVLCWindowsTitle();
134 handleMainUi( settings );
136 /* Create a Dock to get the playlist */
137 dockPL = new QDockWidget( qtr( "Playlist" ), this );
138 dockPL->setSizePolicy( QSizePolicy::Preferred,
139 QSizePolicy::Expanding );
140 dockPL->setFeatures( QDockWidget::AllDockWidgetFeatures );
141 dockPL->setAllowedAreas( Qt::LeftDockWidgetArea
142 | Qt::RightDockWidgetArea
143 | Qt::BottomDockWidgetArea );
149 QVLCMenu::createMenuBar( this, p_intf, visualSelectorEnabled );
154 /* Widgets Creation*/
155 b_remainingTime = false;
156 timeLabel = new TimeLabel;
157 timeLabel->setText( " --:--/--:-- " );
158 timeLabel->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
159 nameLabel = new QLabel;
160 nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
161 | Qt::TextSelectableByKeyboard );
162 speedLabel = new QLabel( "1.00x" );
163 speedLabel->setContextMenuPolicy ( Qt::CustomContextMenu );
165 /* Styling those labels */
166 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
167 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
168 nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
170 pgBar = new QProgressBar;
173 /* and adding those */
174 statusBar()->addWidget( nameLabel, 8 );
175 statusBar()->addPermanentWidget( speedLabel, 0 );
176 statusBar()->addPermanentWidget( pgBar, 0 );
177 statusBar()->addPermanentWidget( timeLabel, 0 );
179 /* timeLabel behaviour:
180 - double clicking opens the goto time dialog
181 - right-clicking and clicking just toggle between remaining and
183 CONNECT( timeLabel, timeLabelClicked(), this, toggleTimeDisplay() );
184 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
185 CONNECT( timeLabel, timeLabelDoubleClicked(), this, toggleTimeDisplay() );
187 /* Speed Label behaviour:
188 - right click gives the vertical speed slider */
189 CONNECT( speedLabel, customContextMenuRequested( QPoint ),
190 this, showSpeedMenu( QPoint ) );
192 /**********************
193 * Systray Management *
194 **********************/
196 bool b_createSystray = false;
197 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
198 if( config_GetInt( p_intf, "qt-start-minimized") )
200 if( b_systrayAvailable )
202 b_createSystray = true;
203 hide(); //FIXME BUG HERE
205 else msg_Warn( p_intf, "You can't minize if you haven't a system "
208 if( config_GetInt( p_intf, "qt-system-tray") )
209 b_createSystray = true;
211 if( b_systrayAvailable && b_createSystray )
214 if( config_GetInt( p_intf, "qt-minimal-view" ) )
217 /********************
219 ********************/
220 MainInputManager::getInstance( p_intf );
222 /********************
224 ********************/
225 /* Connect the input manager to the GUI elements it manages */
227 /* It is also connected to the control->slider, see the ControlsWidget */
228 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
229 this, setDisplayPosition( float, int, int ) );
230 /* Change the SpeedRate in the Status */
231 CONNECT( THEMIM->getIM(), rateChanged( int ), this, setRate( int ) );
234 * Connects on nameChanged()
235 * Those connects are not merged because different options can trigger
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 ) );
255 * 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 ) );
268 ON_TIMEOUT( updateOnTimer() );
269 //ON_TIMEOUT( debug() );
274 var_Create( p_intf, "interaction", VLC_VAR_ADDRESS );
275 var_AddCallback( p_intf, "interaction", InteractCallback, this );
276 p_intf->b_interaction = VLC_TRUE;
278 /* Register callback for the intf-popupmenu variable */
279 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
280 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
281 if( p_playlist != NULL )
283 var_AddCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
284 var_AddCallback( p_playlist, "intf-show", IntfShowCB, p_intf );
285 vlc_object_release( p_playlist );
288 /* VideoWidget connect mess to avoid different threads speaking to each other */
289 CONNECT( this, askReleaseVideo( void * ), this, releaseVideoSlot( void * ) );
290 CONNECT( this, askVideoToResize( unsigned int, unsigned int ),
291 videoWidget, SetSizing( unsigned int, unsigned int ) );
292 CONNECT( this, askUpdate(), this, doComponentsUpdate() );
294 CONNECT( dockPL, topLevelChanged( bool ), this, doComponentsUpdate() );
295 CONNECT( controls, advancedControlsToggled( bool ),
296 this, doComponentsUpdate() );
298 move( settings->value( "pos", QPoint( 0, 0 ) ).toPoint() );
300 QSize newSize = settings->value( "size", QSize( 350, 60 ) ).toSize();
301 if( newSize.isValid() )
307 msg_Warn( p_intf, "Invalid size in constructor" );
310 int tgPlay = settings->value( "playlist-visible", 0 ).toInt();
311 settings->endGroup();
322 MainInterface::~MainInterface()
324 msg_Dbg( p_intf, "Destroying the main interface" );
326 if( playlistWidget ) playlistWidget->savingSettings( settings );
327 if( ExtendedDialog::exists() )
328 ExtendedDialog::getInstance( p_intf )->savingSettings();
330 settings->beginGroup( "MainWindow" );
331 settings->setValue( "playlist-floats", (int)(dockPL->isFloating()) );
332 settings->setValue( "playlist-visible", (int)playlistVisible );
333 settings->setValue( "adv-controls",
334 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
335 settings->setValue( "pos", pos() );
336 settings->setValue( "size", size() );
338 settings->setValue( "backgroundSize", bgWidget->size() );
340 settings->endGroup();
343 /* Unregister callback for the intf-popupmenu variable */
344 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
345 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
346 if( p_playlist != NULL )
348 var_DelCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
349 var_DelCallback( p_playlist, "intf-show", IntfShowCB, p_intf );
350 vlc_object_release( p_playlist );
353 p_intf->b_interaction = VLC_FALSE;
354 var_DelCallback( p_intf, "interaction", InteractCallback, this );
356 p_intf->pf_request_window = NULL;
357 p_intf->pf_release_window = NULL;
358 p_intf->pf_control_window = NULL;
359 p_intf->p_sys->p_mi = NULL;
362 /*****************************
364 *****************************/
367 * Give the decorations of the Main Window a correct Name.
368 * If nothing is given, set it to VLC...
370 void MainInterface::setVLCWindowsTitle( QString aTitle )
372 if( aTitle.isEmpty() )
374 setWindowTitle( qtr( "VLC media player" ) );
378 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
382 void MainInterface::handleMainUi( QSettings *settings )
384 /* Create the main Widget and the mainLayout */
385 QWidget *main = new QWidget;
386 setCentralWidget( main );
387 mainLayout = new QVBoxLayout( main );
389 /* Margins, spacing */
390 main->setContentsMargins( 0, 0, 0, 0 );
391 // main->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
392 mainLayout->setMargin( 0 );
394 /* Create the CONTROLS Widget */
395 /* bool b_shiny = config_GetInt( p_intf, "qt-blingbling" ); */
396 controls = new ControlsWidget( p_intf, this,
397 settings->value( "adv-controls", false ).toBool(),
398 config_GetInt( p_intf, "qt-blingbling" ) );
400 /* Add the controls Widget to the main Widget */
401 mainLayout->insertWidget( 0, controls );
403 /* Create the Speed Control Widget */
404 speedControl = new SpeedControlWidget( p_intf );
405 speedControlMenu = new QMenu( this );
407 QWidgetAction *widgetAction = new QWidgetAction( speedControl );
408 widgetAction->setDefaultWidget( speedControl );
409 speedControlMenu->addAction( widgetAction );
412 /* Disabled for now, they SUCK */
414 visualSelector = new VisualSelector( p_intf );
415 mainLayout->insertWidget( 0, visualSelector );
416 visualSelector->hide();
419 /* And video Outputs */
420 if( alwaysVideoFlag )
422 bgWidget = new BackgroundWidget( p_intf );
424 settings->value( "backgroundSize", QSize( 300, 150 ) ).toSize() );
425 bgWidget->updateGeometry();
426 mainLayout->insertWidget( 0, bgWidget );
427 CONNECT( this, askBgWidgetToToggle(), bgWidget, toggle() );
430 if( videoEmbeddedFlag )
432 videoWidget = new VideoWidget( p_intf );
433 mainLayout->insertWidget( 0, videoWidget );
435 p_intf->pf_request_window = ::DoRequest;
436 p_intf->pf_release_window = ::DoRelease;
437 p_intf->pf_control_window = ::DoControl;
440 /* Finish the sizing */
444 inline void MainInterface::privacy()
447 * Ask for the network policy on FIRST STARTUP
449 if( config_GetInt( p_intf, "qt-privacy-ask") )
451 QList<ConfigControl *> controls;
452 if( privacyDialog( controls ) == QDialog::Accepted )
454 QList<ConfigControl *>::Iterator i;
455 for( i = controls.begin() ; i != controls.end() ; i++ )
457 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
458 c->doApply( p_intf );
461 config_PutInt( p_intf, "qt-privacy-ask" , 0 );
462 config_SaveConfigFile( p_intf, NULL );
467 int MainInterface::privacyDialog( QList<ConfigControl *> controls )
469 QDialog *privacy = new QDialog( this );
471 privacy->setWindowTitle( qtr( "Privacy and Network policies" ) );
473 QGridLayout *gLayout = new QGridLayout( privacy );
475 QGroupBox *blabla = new QGroupBox( qtr( "Privacy and Network Warning" ) );
476 QGridLayout *blablaLayout = new QGridLayout( blabla );
477 QLabel *text = new QLabel( qtr(
478 "<p>The <i>VideoLAN Team</i> doesn't like when an application goes "
479 "online without authorization.</p>\n "
480 "<p><i>VLC media player</i> can request limited information on "
481 "the Internet, especially to get CD covers and songs metadata or to know "
482 "if updates are available.</p>\n"
483 "<p><i>VLC media player</i> <b>DOES NOT</b> send or collect <b>ANY</b> "
484 "information, even anonymously, about your usage.</p>\n"
485 "<p>Therefore please check the following options, the default being "
486 "almost no access on the web.</p>\n") );
487 text->setWordWrap( true );
488 text->setTextFormat( Qt::RichText );
490 blablaLayout->addWidget( text, 0, 0 ) ;
492 QGroupBox *options = new QGroupBox;
493 QGridLayout *optionsLayout = new QGridLayout( options );
495 gLayout->addWidget( blabla, 0, 0, 1, 3 );
496 gLayout->addWidget( options, 1, 0, 1, 3 );
497 module_config_t *p_config;
498 ConfigControl *control;
501 #define CONFIG_GENERIC( option, type ) \
502 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
505 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
506 p_config, options, false, optionsLayout, line ); \
507 controls.append( control ); \
510 #define CONFIG_GENERIC_NOBOOL( option, type ) \
511 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
514 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
515 p_config, options, optionsLayout, line ); \
516 controls.append( control ); \
519 CONFIG_GENERIC( "album-art", IntegerList ); line++;
520 CONFIG_GENERIC_NOBOOL( "fetch-meta", Bool ); line++;
522 CONFIG_GENERIC_NOBOOL( "qt-updates-notif", Bool ); line++;
523 CONFIG_GENERIC_NOBOOL( "qt-updates-days", Integer ); line++;
525 QPushButton *ok = new QPushButton( qtr( "Ok" ) );
527 gLayout->addWidget( ok, 2, 2 );
529 CONNECT( ok, clicked(), privacy, accept() );
530 return privacy->exec();
533 //FIXME remove me at the end...
534 void MainInterface::debug()
536 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
537 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
540 /**********************************************************************
541 * Handling of sizing of the components
542 **********************************************************************/
544 /* This function is probably wrong, but we don't have many many choices...
545 Since we can't know from the playlist Widget if we are inside a dock or not,
546 because the playlist Widget can be called by THEDP, as a separate windows for
548 Maybe the other solution is to redefine the sizeHint() of the playlist and
549 ask _parent->isFloating()...
550 If you think this would be better, please FIXME it...
552 QSize MainInterface::sizeHint() const
554 int nwidth = controls->sizeHint().width();
555 int nheight = controls->isVisible() ?
556 controls->size().height()
557 + menuBar()->size().height()
558 + statusBar()->size().height()
561 msg_Dbg( p_intf, "1 %i %i", nheight, nwidth );
562 if( VISIBLE( bgWidget ) )
564 nheight += bgWidget->size().height();
565 nwidth = bgWidget->size().width();
566 msg_Dbg( p_intf, "1b %i %i", nheight, nwidth );
568 else if( videoIsActive )
570 nheight += videoWidget->size().height();
571 nwidth = videoWidget->size().width();
572 msg_Dbg( p_intf, "2 %i %i", nheight, nwidth );
574 if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget() )
576 nheight += dockPL->size().height();
577 nwidth = __MAX( nwidth, dockPL->size().width() );
578 msg_Dbg( p_intf, "3 %i %i", nheight, nwidth );
580 msg_Dbg( p_intf, "4 %i %i", nheight, nwidth );
581 return QSize( nwidth, nheight );
585 /* FIXME This is dead code and need to be removed AT THE END */
586 void MainInterface::resizeEvent( QResizeEvent *e )
589 videoWidget->widgetSize.setWidth( e->size().width() - addSize.width() );
590 if( videoWidget && videoIsActive && videoWidget->widgetSize.height() > 1 )
592 SET_WH( videoWidget, e->size().width() - addSize.width(),
593 e->size().height() - addSize.height() );
594 videoWidget->updateGeometry();
596 if( VISIBLE( playlistWidget ) )
598 // SET_WH( playlistWidget , e->size().width() - addSize.width(),
599 // e->size().height() - addSize.height() );
600 playlistWidget->updateGeometry();
605 /****************************************************************************
606 * Small right-click menu for rate control
607 ****************************************************************************/
608 void MainInterface::showSpeedMenu( QPoint pos )
610 speedControlMenu->exec( QCursor::pos() - pos
611 + QPoint( 0, speedLabel->height() ) );
614 /****************************************************************************
616 ****************************************************************************/
617 class SetVideoOnTopQtEvent : public QEvent
620 SetVideoOnTopQtEvent( bool _onTop ) :
621 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
633 /* function called from ::DoRequest in order to show a nice VideoWidget
635 void *MainInterface::requestVideo( vout_thread_t *p_nvout, int *pi_x,
636 int *pi_y, unsigned int *pi_width,
637 unsigned int *pi_height )
639 bool bgWasVisible = false;
641 /* Request the videoWidget */
642 void *ret = videoWidget->request( p_nvout,pi_x, pi_y, pi_width, pi_height );
643 if( ret ) /* The videoWidget is available */
645 /* Did we have a bg ? Hide it! */
646 if( VISIBLE( bgWidget) )
649 emit askBgWidgetToToggle();
652 /*if( THEMIM->getIM()->hasVideo() || !bgWasVisible )
654 videoWidget->widgetSize = QSize( *pi_width, *pi_height );
656 else /* Background widget available, use its size */
658 /* Ok, our visualizations are bad, so don't do this for the moment
659 * use the requested size anyway */
660 // videoWidget->widgetSize = bgWidget->widgeTSize;
661 /* videoWidget->widgetSize = QSize( *pi_width, *pi_height );
664 videoIsActive = true;
666 emit askVideoToResize( *pi_width, *pi_height );
672 void MainInterface::releaseVideo( void *p_win )
674 emit askReleaseVideo( p_win );
677 void MainInterface::releaseVideoSlot( void *p_win )
679 videoWidget->release( p_win );
682 if( bgWidget )// WORONG
685 videoIsActive = false;
689 int MainInterface::controlVideo( void *p_window, int i_query, va_list args )
691 int i_ret = VLC_EGENERIC;
696 unsigned int *pi_width = va_arg( args, unsigned int * );
697 unsigned int *pi_height = va_arg( args, unsigned int * );
698 *pi_width = videoWidget->width();
699 *pi_height = videoWidget->height();
705 unsigned int i_width = va_arg( args, unsigned int );
706 unsigned int i_height = va_arg( args, unsigned int );
707 emit askVideoToResize( i_width, i_height );
713 case VOUT_SET_STAY_ON_TOP:
715 int i_arg = va_arg( args, int );
716 QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
721 msg_Warn( p_intf, "unsupported control query" );
727 /*****************************************************************************
728 * Playlist, Visualisation and Menus handling
729 *****************************************************************************/
731 * Toggle the playlist widget or dialog
733 void MainInterface::togglePlaylist()
736 If no playlist exist, then create one and attach it to the DockPL*/
737 if( !playlistWidget )
739 playlistWidget = new PlaylistWidget( p_intf, settings, dockPL );
741 /* Add it to the parent DockWidget */
742 dockPL->setWidget( playlistWidget );
744 /* Add the dock to the main Interface */
745 addDockWidget( Qt::BottomDockWidgetArea, dockPL );
747 /* Make the playlist floating is requested. Default is not. */
748 settings->beginGroup( "MainWindow" );
749 if( settings->value( "playlist-floats", 1 ).toInt() )
751 msg_Dbg( p_intf, "we don't want the playlist inside");
752 dockPL->setFloating( true );
754 settings->endGroup();
755 settings->beginGroup( "playlist" );
756 dockPL->move( settings->value( "pos", QPoint( 0,0 ) ).toPoint() );
757 QSize newSize = settings->value( "size", QSize( 400, 300 ) ).toSize();
758 if( newSize.isValid() )
759 dockPL->resize( newSize );
760 settings->endGroup();
763 playlistVisible = true;
767 /* toggle the visibility of the playlist */
769 resize( sizeHint() );
770 playlistVisible = !playlistVisible;
774 /* Function called from the menu to undock the playlist */
775 void MainInterface::undockPlaylist()
777 dockPL->setFloating( true );
778 resize( sizeHint() );
781 void MainInterface::toggleMinimalView()
783 TOGGLEV( menuBar() );
785 TOGGLEV( statusBar() );
786 doComponentsUpdate();
789 /* Video widget cannot do this synchronously as it runs in another thread */
790 /* Well, could it, actually ? Probably dangerous ... */
791 void MainInterface::doComponentsUpdate()
793 resize( sizeHint() );
794 msg_Dbg( p_intf, "Updating the geometry" );
798 /* toggling advanced controls buttons */
799 void MainInterface::toggleAdvanced()
801 controls->toggleAdvanced();
804 /* Get the visibility status of the controls (hidden or not, advanced or not) */
805 int MainInterface::getControlsVisibilityStatus()
807 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
808 + CONTROLS_ADVANCED * controls->b_advancedVisible );
812 void MainInterface::visual()
814 if( !VISIBLE( visualSelector) )
816 visualSelector->show();
817 if( !THEMIM->getIM()->hasVideo() )
819 /* Show the background widget */
821 visualSelectorEnabled = true;
825 /* Stop any currently running visualization */
826 visualSelector->hide();
827 visualSelectorEnabled = false;
829 doComponentsUpdate();
833 /************************************************************************
835 ************************************************************************/
836 void MainInterface::setDisplayPosition( float pos, int time, int length )
838 char psz_length[MSTRTIME_MAX_SIZE], psz_time[MSTRTIME_MAX_SIZE];
839 secstotimestr( psz_length, length );
840 secstotimestr( psz_time, ( b_remainingTime && length ) ? length - time
844 timestr.sprintf( "%s/%s", psz_time,
845 ( !length && time ) ? "--:--" : psz_length );
847 /* Add a minus to remaining time*/
848 if( b_remainingTime && length ) timeLabel->setText( " -"+timestr+" " );
849 else timeLabel->setText( " "+timestr+" " );
852 void MainInterface::toggleTimeDisplay()
854 b_remainingTime = !b_remainingTime;
857 void MainInterface::setName( QString name )
859 input_name = name; /* store it for the QSystray use */
860 /* Display it in the status bar, but also as a Tooltip in case it doesn't
862 nameLabel->setText( " " + name + " " );
863 nameLabel->setToolTip( " " + name +" " );
866 void MainInterface::setStatus( int status )
868 /* Forward the status to the controls to toggle Play/Pause */
869 controls->setStatus( status );
870 /* And in the systray for the menu */
872 QVLCMenu::updateSystrayMenu( this, p_intf );
875 void MainInterface::setRate( int rate )
878 str.setNum( ( 1000 / (double)rate ), 'f', 2 );
880 speedLabel->setText( str );
881 speedControl->updateControls( rate );
884 void MainInterface::updateOnTimer()
886 if( intf_ShouldDie( p_intf ) )
888 QApplication::closeAllWindows();
889 QApplication::quit();
892 if( need_components_update )
894 doComponentsUpdate();
895 need_components_update = false;
900 /*****************************************************************************
901 * Systray Icon and Systray Menu
902 *****************************************************************************/
905 * Create a SystemTray icon and a menu that would go with it.
906 * Connects to a click handler on the icon.
908 void MainInterface::createSystray()
911 if( QDate::currentDate().dayOfYear() >= 354 )
912 iconVLC = QIcon( QPixmap( ":/vlc128-christmas.png" ) );
914 iconVLC = QIcon( QPixmap( ":/vlc128.png" ) );
915 sysTray = new QSystemTrayIcon( iconVLC, this );
916 sysTray->setToolTip( qtr( "VLC media player" ));
918 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
919 systrayMenu->setIcon( iconVLC );
921 QVLCMenu::updateSystrayMenu( this, p_intf, true );
924 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
925 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
929 * Updates the Systray Icon's menu and toggle the main interface
931 void MainInterface::toggleUpdateSystrayMenu()
933 /* If hidden, show it */
939 else if( isMinimized() )
949 /* check if any visible window is above vlc in the z-order,
950 * but ignore the ones always on top */
953 wi.cbSize = sizeof( WINDOWINFO );
954 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
955 hwnd && !IsWindowVisible( hwnd );
956 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
957 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
958 (wi.dwExStyle&WS_EX_TOPMOST) )
960 if( isActiveWindow() )
970 QVLCMenu::updateSystrayMenu( this, p_intf );
973 void MainInterface::handleSystrayClick(
974 QSystemTrayIcon::ActivationReason reason )
978 case QSystemTrayIcon::Trigger:
979 toggleUpdateSystrayMenu();
981 case QSystemTrayIcon::MiddleClick:
982 sysTray->showMessage( qtr( "VLC media player" ),
983 qtr( "Control menu for the player" ),
984 QSystemTrayIcon::Information, 3000 );
990 * Updates the name of the systray Icon tooltip.
991 * Doesn't check if the systray exists, check before you call it.
993 void MainInterface::updateSystrayTooltipName( QString name )
997 sysTray->setToolTip( qtr( "VLC media player" ) );
1001 sysTray->setToolTip( name );
1002 if( notificationEnabled && ( isHidden() || isMinimized() ) )
1004 sysTray->showMessage( qtr( "VLC media player" ), name,
1005 QSystemTrayIcon::NoIcon, 3000 );
1011 * Updates the status of the systray Icon tooltip.
1012 * Doesn't check if the systray exists, check before you call it.
1014 void MainInterface::updateSystrayTooltipStatus( int i_status )
1021 sysTray->setToolTip( qtr( "VLC media player" ) );
1026 sysTray->setToolTip( input_name );
1031 sysTray->setToolTip( input_name + " - "
1038 /************************************************************************
1040 ************************************************************************/
1041 void MainInterface::dropEvent(QDropEvent *event)
1043 const QMimeData *mimeData = event->mimeData();
1045 /* D&D of a subtitles file, add it on the fly */
1046 if( mimeData->urls().size() == 1 )
1048 if( THEMIM->getIM()->hasInput() )
1050 if( input_AddSubtitles( THEMIM->getInput(),
1051 qtu( mimeData->urls()[0].toString() ),
1054 event->acceptProposedAction();
1060 foreach( QUrl url, mimeData->urls() ) {
1061 QString s = url.toString();
1062 if( s.length() > 0 ) {
1063 playlist_Add( THEPL, qtu(s), NULL,
1064 PLAYLIST_APPEND | (first ? PLAYLIST_GO:0),
1065 PLAYLIST_END, VLC_TRUE, VLC_FALSE );
1069 event->acceptProposedAction();
1071 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1073 event->acceptProposedAction();
1075 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1077 event->acceptProposedAction();
1079 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1084 /************************************************************************
1086 ************************************************************************/
1087 void MainInterface::customEvent( QEvent *event )
1090 if( event->type() == PLDockEvent_Type )
1092 PlaylistDialog::killInstance();
1093 playlistEmbeddedFlag = true;
1095 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1100 if ( event->type() == SetVideoOnTopEvent_Type )
1102 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1103 if( p_event->OnTop() )
1104 setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
1106 setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint);
1107 show(); /* necessary to apply window flags?? */
1111 void MainInterface::keyPressEvent( QKeyEvent *e )
1113 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() & Qt::Key_H )
1114 && menuBar()->isHidden() )
1116 toggleMinimalView();
1120 int i_vlck = qtEventToVLCKey( e );
1123 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1130 void MainInterface::wheelEvent( QWheelEvent *e )
1132 int i_vlckey = qtWheelEventToVLCKey( e );
1133 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1137 void MainInterface::closeEvent( QCloseEvent *e )
1143 void MainInterface::toggleFullScreen( void )
1145 if( isFullScreen() )
1151 /*****************************************************************************
1153 *****************************************************************************/
1154 static int InteractCallback( vlc_object_t *p_this,
1155 const char *psz_var, vlc_value_t old_val,
1156 vlc_value_t new_val, void *param )
1158 intf_dialog_args_t *p_arg = new intf_dialog_args_t;
1159 p_arg->p_dialog = (interaction_dialog_t *)(new_val.p_address);
1160 DialogEvent *event = new DialogEvent( INTF_DIALOG_INTERACTION, 0, p_arg );
1161 QApplication::postEvent( THEDP, static_cast<QEvent*>(event) );
1165 /*****************************************************************************
1166 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1167 * We don't show the menu directly here because we don't want the
1168 * caller to block for a too long time.
1169 *****************************************************************************/
1170 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1171 vlc_value_t old_val, vlc_value_t new_val, void *param )
1173 intf_thread_t *p_intf = (intf_thread_t *)param;
1174 msg_Dbg( p_this, "Menu Requested" ); // DEBUG to track the non disparition of the menu...
1176 if( p_intf->pf_show_dialog )
1178 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1179 new_val.b_bool, 0 );
1185 /*****************************************************************************
1186 * IntfShowCB: callback triggered by the intf-show playlist variable.
1187 *****************************************************************************/
1188 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1189 vlc_value_t old_val, vlc_value_t new_val, void *param )
1191 intf_thread_t *p_intf = (intf_thread_t *)param;
1192 msg_Dbg( p_this, "Intf Show Requested" ); // DEBUG to track the non disparition of the menu...
1193 //p_intf->p_sys->b_intf_show = VLC_TRUE;