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>
54 #include <QProgressBar>
60 #define SET_WIDTH(i,j) i->widgetSize.setWidth(j)
61 #define SET_HEIGHT(i,j) i->widgetSize.setHeight(j)
62 #define SET_WH( i,j,k) i->widgetSize.setWidth(j); i->widgetSize.setHeight(k);
64 #define DS(i) i.width(),i.height()
66 /* Callback prototypes */
67 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
68 vlc_value_t old_val, vlc_value_t new_val, void *param );
69 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
70 vlc_value_t old_val, vlc_value_t new_val, void *param );
71 static int InteractCallback( vlc_object_t *, const char *, vlc_value_t,
74 static void *DoRequest( intf_thread_t *p_intf, vout_thread_t *p_vout,
75 int *pi1, int *pi2, unsigned int*pi3,unsigned int*pi4)
77 return p_intf->p_sys->p_mi->requestVideo( p_vout, pi1, pi2, pi3, pi4 );
79 static void DoRelease( intf_thread_t *p_intf, void *p_win )
81 return p_intf->p_sys->p_mi->releaseVideo( p_win );
83 static int DoControl( intf_thread_t *p_intf, void *p_win, int i_q, va_list a )
85 return p_intf->p_sys->p_mi->controlVideo( p_win, i_q, a );
88 MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
90 /* Variables initialisation */
91 // need_components_update = false;
92 bgWidget = NULL; videoWidget = NULL; playlistWidget = NULL;
93 videoIsActive = false;
95 playlistVisible = false;
101 * Configuration and settings
103 settings = new QSettings( "vlc", "vlc-qt-interface" );
104 settings->beginGroup( "MainWindow" );
107 setFocusPolicy( Qt::StrongFocus );
108 setAcceptDrops( true );
109 setWindowIcon( QApplication::windowIcon() );
110 setWindowOpacity( config_GetFloat( p_intf, "qt-opacity" ) );
112 /* Set The Video In emebedded Mode or not */
113 videoEmbeddedFlag = false;
114 if( config_GetInt( p_intf, "embedded-video" ) ) videoEmbeddedFlag = true;
116 /* Are we in the enhanced always-video mode or not ? */
117 alwaysVideoFlag = false;
118 if( videoEmbeddedFlag && config_GetInt( p_intf, "qt-always-video" ) )
119 alwaysVideoFlag = true;
121 /* Set the other interface settings */
122 //TODO: I don't like that code
123 visualSelectorEnabled = settings->value( "visual-selector", false ).toBool();
124 notificationEnabled = config_GetInt( p_intf, "qt-notification" )
127 /**************************
128 * UI and Widgets design
129 **************************/
130 setVLCWindowsTitle();
131 handleMainUi( settings );
133 /* Create a Dock to get the playlist */
134 dockPL = new QDockWidget( qtr( "Playlist" ), this );
135 dockPL->setSizePolicy( QSizePolicy::Preferred,
136 QSizePolicy::Expanding );
137 dockPL->setFeatures( QDockWidget::AllDockWidgetFeatures );
138 dockPL->setAllowedAreas( Qt::LeftDockWidgetArea
139 | Qt::RightDockWidgetArea
140 | Qt::BottomDockWidgetArea );
146 QVLCMenu::createMenuBar( this, p_intf, visualSelectorEnabled );
151 /* Widgets Creation*/
152 b_remainingTime = false;
153 timeLabel = new TimeLabel;
154 timeLabel->setText( " --:--/--:-- " );
155 timeLabel->setAlignment( Qt::AlignRight );
156 nameLabel = new QLabel;
157 nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
158 | Qt::TextSelectableByKeyboard );
159 speedLabel = new QLabel( "1.00x" );
160 speedLabel->setContextMenuPolicy ( Qt::CustomContextMenu );
162 /* Styling those labels */
163 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
164 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
165 nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
167 pgBar = new QProgressBar;
170 /* and adding those */
171 statusBar()->addWidget( nameLabel, 8 );
172 statusBar()->addPermanentWidget( speedLabel, 0 );
173 statusBar()->addPermanentWidget( pgBar, 0 );
174 statusBar()->addPermanentWidget( timeLabel, 0 );
176 /* timeLabel behaviour:
177 - double clicking opens the goto time dialog
178 - right-clicking and clicking just toggle between remaining and
180 CONNECT( timeLabel, timeLabelClicked(), this, toggleTimeDisplay() );
181 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
182 CONNECT( timeLabel, timeLabelDoubleClicked(), this, toggleTimeDisplay() );
184 /* Speed Label behaviour:
185 - right click gives the vertical speed slider */
186 CONNECT( speedLabel, customContextMenuRequested( QPoint ),
187 this, showSpeedMenu( QPoint ) );
189 /**********************
190 * Systray Management *
191 **********************/
193 bool b_createSystray = false;
194 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
195 if( config_GetInt( p_intf, "qt-start-minimized") )
197 if( b_systrayAvailable ){
198 b_createSystray = true;
199 hide(); //FIXME BUG HERE
201 else msg_Warn( p_intf, "You can't minize if you haven't a system "
204 if( config_GetInt( p_intf, "qt-system-tray") )
205 b_createSystray = true;
207 if( b_systrayAvailable && b_createSystray )
210 if( config_GetInt( p_intf, "qt-minimal-view" ) )
213 /********************
215 ********************/
216 MainInputManager::getInstance( p_intf );
218 /********************
220 ********************/
221 /* Connect the input manager to the GUI elements it manages */
223 /* It is also connected to the control->slider, see the ControlsWidget */
224 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
225 this, setDisplayPosition( float, int, int ) );
226 /* Change the SpeedRate in the Status */
227 CONNECT( THEMIM->getIM(), rateChanged( int ), this, setRate( int ) );
230 * Connects on nameChanged()
231 * Those connects are not merged because different options can trigger
234 /* Naming in the controller statusbar */
235 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
236 setName( QString ) );
237 /* and in the systray */
240 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
241 updateSystrayTooltipName( QString ) );
243 /* and in the title of the controller */
244 if( config_GetInt( p_intf, "qt-name-in-title" ) )
246 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
247 setVLCWindowsTitle( QString ) );
251 * CONNECTS on PLAY_STATUS
253 /* Status on the main controller */
254 CONNECT( THEMIM->getIM(), statusChanged( int ), this, setStatus( int ) );
255 /* and in the systray */
258 CONNECT( THEMIM->getIM(), statusChanged( int ), this,
259 updateSystrayTooltipStatus( int ) );
264 ON_TIMEOUT( updateOnTimer() );
265 //ON_TIMEOUT( debug() );
270 var_Create( p_intf, "interaction", VLC_VAR_ADDRESS );
271 var_AddCallback( p_intf, "interaction", InteractCallback, this );
272 p_intf->b_interaction = VLC_TRUE;
274 /* Register callback for the intf-popupmenu variable */
275 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
276 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
277 if( p_playlist != NULL )
279 var_AddCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
280 var_AddCallback( p_playlist, "intf-show", IntfShowCB, p_intf );
281 vlc_object_release( p_playlist );
284 /* VideoWidget connect mess to avoid different threads speaking to each other */
285 CONNECT( this, askReleaseVideo( void * ), this, releaseVideoSlot( void * ) );
286 CONNECT( this, askVideoToResize( unsigned int, unsigned int ),
287 videoWidget, SetSizing( unsigned int, unsigned int ) );
288 CONNECT( this, askUpdate(), this, doComponentsUpdate() );
290 CONNECT( dockPL, topLevelChanged( bool ), this, doComponentsUpdate() );
291 CONNECT( controls, advancedControlsToggled( bool ),
292 this, doComponentsUpdate() );
294 move( settings->value( "pos", QPoint( 0, 0 ) ).toPoint() );
296 QSize newSize = settings->value( "size", QSize( 350, 60 ) ).toSize();
297 if( newSize.isValid() )
303 msg_Warn( p_intf, "Invalid size in constructor" );
306 int tgPlay = settings->value( "playlist-visible", 0 ).toInt();
307 settings->endGroup();
318 MainInterface::~MainInterface()
320 if( playlistWidget ) playlistWidget->savingSettings( settings );
321 if( ExtendedDialog::exists() )
322 ExtendedDialog::getInstance( p_intf )->savingSettings();
324 settings->beginGroup( "MainWindow" );
325 settings->setValue( "playlist-floats", (int)(dockPL->isFloating()) );
326 settings->setValue( "playlist-visible", (int)playlistVisible );
327 settings->setValue( "adv-controls",
328 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
329 settings->setValue( "pos", pos() );
330 settings->setValue( "size", size() );
332 settings->setValue( "backgroundSize", bgWidget->size() );
334 settings->endGroup();
337 /* Unregister callback for the intf-popupmenu variable */
338 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
339 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
340 if( p_playlist != NULL )
342 var_DelCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
343 var_DelCallback( p_playlist, "intf-show", IntfShowCB, p_intf );
344 vlc_object_release( p_playlist );
347 p_intf->b_interaction = VLC_FALSE;
348 var_DelCallback( p_intf, "interaction", InteractCallback, this );
350 p_intf->pf_request_window = NULL;
351 p_intf->pf_release_window = NULL;
352 p_intf->pf_control_window = NULL;
355 /*****************************
357 *****************************/
360 * Give the decorations of the Main Window a correct Name.
361 * If nothing is given, set it to VLC...
363 void MainInterface::setVLCWindowsTitle( QString aTitle )
365 if( aTitle.isEmpty() )
367 setWindowTitle( qtr( "VLC media player" ) );
371 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
375 void MainInterface::handleMainUi( QSettings *settings )
377 /* Create the main Widget and the mainLayout */
378 QWidget *main = new QWidget;
379 setCentralWidget( main );
380 mainLayout = new QVBoxLayout( main );
382 /* Margins, spacing */
383 main->setContentsMargins( 0, 0, 0, 0 );
384 // main->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
385 mainLayout->setMargin( 0 );
387 /* Create the CONTROLS Widget */
388 /* bool b_shiny = config_GetInt( p_intf, "qt-blingbling" ); */
389 controls = new ControlsWidget( p_intf, this,
390 settings->value( "adv-controls", false ).toBool(),
391 config_GetInt( p_intf, "qt-blingbling" ) );
393 /* Add the controls Widget to the main Widget */
394 mainLayout->insertWidget( 0, controls );
396 /* Create the Speed Control Widget */
397 speedControl = new SpeedControlWidget( p_intf );
398 speedControlMenu = new QMenu( this );
400 QWidgetAction *widgetAction = new QWidgetAction( speedControl );
401 widgetAction->setDefaultWidget( speedControl );
402 speedControlMenu->addAction( widgetAction );
405 /* Disabled for now, they SUCK */
407 visualSelector = new VisualSelector( p_intf );
408 mainLayout->insertWidget( 0, visualSelector );
409 visualSelector->hide();
412 /* And video Outputs */
413 if( alwaysVideoFlag )
415 bgWidget = new BackgroundWidget( p_intf );
417 settings->value( "backgroundSize", QSize( 300, 150 ) ).toSize() );
418 bgWidget->updateGeometry();
419 mainLayout->insertWidget( 0, bgWidget );
420 CONNECT( this, askBgWidgetToToggle(), bgWidget, toggle() );
423 if( videoEmbeddedFlag )
425 videoWidget = new VideoWidget( p_intf );
426 mainLayout->insertWidget( 0, videoWidget );
428 p_intf->pf_request_window = ::DoRequest;
429 p_intf->pf_release_window = ::DoRelease;
430 p_intf->pf_control_window = ::DoControl;
433 /* Finish the sizing */
437 inline void MainInterface::privacy()
440 * Ask for the network policy on FIRST STARTUP
442 if( config_GetInt( p_intf, "privacy-ask") )
444 QList<ConfigControl *> controls;
445 if( privacyDialog( controls ) == QDialog::Accepted )
447 QList<ConfigControl *>::Iterator i;
448 for( i = controls.begin() ; i != controls.end() ; i++ )
450 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
451 c->doApply( p_intf );
454 config_PutInt( p_intf, "privacy-ask" , 0 );
455 config_SaveConfigFile( p_intf, NULL );
460 int MainInterface::privacyDialog( QList<ConfigControl *> controls )
462 QDialog *privacy = new QDialog( this );
464 privacy->setWindowTitle( qtr( "Privacy and Network policies" ) );
466 QGridLayout *gLayout = new QGridLayout( privacy );
468 QGroupBox *blabla = new QGroupBox( qtr( "Privacy and Network Warning" ) );
469 QGridLayout *blablaLayout = new QGridLayout( blabla );
470 QLabel *text = new QLabel( qtr(
471 "<p>The <i>VideoLAN Team</i> doesn't like when an application goes "
472 "online without authorization.</p>\n "
473 "<p><i>VLC media player</i> can request limited information on "
474 "Internet, espically to get CD Covers and songs metadata or to know "
475 "if updates are available.</p>\n"
476 "<p><i>VLC media player</i> <b>DOES NOT</b> send or collect <b>ANY</b> "
477 "information, even anonymously about your "
479 "<p>Therefore please check the following options, the default being "
480 "almost no access on the web.</p>\n") );
481 text->setWordWrap( true );
482 text->setTextFormat( Qt::RichText );
484 blablaLayout->addWidget( text, 0, 0 ) ;
486 QGroupBox *options = new QGroupBox;
487 QGridLayout *optionsLayout = new QGridLayout( options );
489 gLayout->addWidget( blabla, 0, 0, 1, 3 );
490 gLayout->addWidget( options, 1, 0, 1, 3 );
491 module_config_t *p_config;
492 ConfigControl *control;
495 #define CONFIG_GENERIC( option, type ) \
496 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
499 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
500 p_config, options, false, optionsLayout, line ); \
501 controls.append( control ); \
504 #define CONFIG_GENERIC_NOBOOL( option, type ) \
505 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
508 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
509 p_config, options, optionsLayout, line ); \
510 controls.append( control ); \
513 CONFIG_GENERIC( "album-art", IntegerList ); line++;
514 CONFIG_GENERIC_NOBOOL( "fetch-meta", Bool ); line++;
515 CONFIG_GENERIC_NOBOOL( "qt-updates-notif", Bool );
517 QPushButton *ok = new QPushButton( qtr( "Ok" ) );
519 gLayout->addWidget( ok, 2, 2 );
521 CONNECT( ok, clicked(), privacy, accept() );
522 return privacy->exec();
525 //FIXME remove me at the end...
526 void MainInterface::debug()
528 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
529 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
532 /**********************************************************************
533 * Handling of sizing of the components
534 **********************************************************************/
536 /* This function is probably wrong, but we don't have many many choices...
537 Since we can't know from the playlist Widget if we are inside a dock or not,
538 because the playlist Widget can be called by THEDP, as a separate windows for
540 Maybe the other solution is to redefine the sizeHint() of the playlist and
541 ask _parent->isFloating()...
542 If you think this would be better, please FIXME it...
544 QSize MainInterface::sizeHint() const
546 int nwidth = controls->sizeHint().width();
547 int nheight = controls->isVisible() ?
548 controls->size().height()
549 + menuBar()->size().height()
550 + statusBar()->size().height()
553 msg_Dbg( p_intf, "1 %i %i", nheight, nwidth );
554 if( VISIBLE( bgWidget ) )
556 nheight += bgWidget->size().height();
557 nwidth = bgWidget->size().width();
558 msg_Dbg( p_intf, "1b %i %i", nheight, nwidth );
560 else if( videoIsActive )
562 nheight += videoWidget->size().height();
563 nwidth = videoWidget->size().width();
564 msg_Dbg( p_intf, "2 %i %i", nheight, nwidth );
566 if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget() )
568 nheight += dockPL->size().height();
569 nwidth = __MAX( nwidth, dockPL->size().width() );
570 msg_Dbg( p_intf, "3 %i %i", nheight, nwidth );
572 msg_Dbg( p_intf, "4 %i %i", nheight, nwidth );
573 return QSize( nwidth, nheight );
577 /* FIXME This is dead code and need to be removed AT THE END */
578 void MainInterface::resizeEvent( QResizeEvent *e )
581 videoWidget->widgetSize.setWidth( e->size().width() - addSize.width() );
582 if( videoWidget && videoIsActive && videoWidget->widgetSize.height() > 1 )
584 SET_WH( videoWidget, e->size().width() - addSize.width(),
585 e->size().height() - addSize.height() );
586 videoWidget->updateGeometry();
588 if( VISIBLE( playlistWidget ) )
590 // SET_WH( playlistWidget , e->size().width() - addSize.width(),
591 // e->size().height() - addSize.height() );
592 playlistWidget->updateGeometry();
597 /****************************************************************************
598 * Small right-click menu for rate control
599 ****************************************************************************/
600 void MainInterface::showSpeedMenu( QPoint pos )
602 speedControlMenu->exec( QCursor::pos() - pos
603 + QPoint( 0, speedLabel->height() ) );
606 /****************************************************************************
608 ****************************************************************************/
609 class SetVideoOnTopQtEvent : public QEvent
612 SetVideoOnTopQtEvent( bool _onTop ) :
613 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
625 /* function called from ::DoRequest in order to show a nice VideoWidget
627 void *MainInterface::requestVideo( vout_thread_t *p_nvout, int *pi_x,
628 int *pi_y, unsigned int *pi_width,
629 unsigned int *pi_height )
631 bool bgWasVisible = false;
633 /* Request the videoWidget */
634 void *ret = videoWidget->request( p_nvout,pi_x, pi_y, pi_width, pi_height );
635 if( ret ) /* The videoWidget is available */
637 /* Did we have a bg ? Hide it! */
638 if( VISIBLE( bgWidget) )
641 emit askBgWidgetToToggle();
644 /*if( THEMIM->getIM()->hasVideo() || !bgWasVisible )
646 videoWidget->widgetSize = QSize( *pi_width, *pi_height );
648 else /* Background widget available, use its size */
650 /* Ok, our visualizations are bad, so don't do this for the moment
651 * use the requested size anyway */
652 // videoWidget->widgetSize = bgWidget->widgeTSize;
653 /* videoWidget->widgetSize = QSize( *pi_width, *pi_height );
656 videoIsActive = true;
658 emit askVideoToResize( *pi_width, *pi_height );
664 void MainInterface::releaseVideo( void *p_win )
666 emit askReleaseVideo( p_win );
669 void MainInterface::releaseVideoSlot( void *p_win )
671 videoWidget->release( p_win );
674 if( bgWidget )// WORONG
677 videoIsActive = false;
681 int MainInterface::controlVideo( void *p_window, int i_query, va_list args )
683 int i_ret = VLC_EGENERIC;
688 unsigned int *pi_width = va_arg( args, unsigned int * );
689 unsigned int *pi_height = va_arg( args, unsigned int * );
690 *pi_width = videoWidget->width();
691 *pi_height = videoWidget->height();
697 unsigned int i_width = va_arg( args, unsigned int );
698 unsigned int i_height = va_arg( args, unsigned int );
699 emit askVideoToResize( i_width, i_height );
705 case VOUT_SET_STAY_ON_TOP:
707 int i_arg = va_arg( args, int );
708 QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
713 msg_Warn( p_intf, "unsupported control query" );
719 /*****************************************************************************
720 * Playlist, Visualisation and Menus handling
721 *****************************************************************************/
723 * Toggle the playlist widget or dialog
725 void MainInterface::togglePlaylist()
728 If no playlist exist, then create one and attach it to the DockPL*/
729 if( !playlistWidget )
731 playlistWidget = new PlaylistWidget( p_intf, settings, dockPL );
733 /* Add it to the parent DockWidget */
734 dockPL->setWidget( playlistWidget );
736 /* Add the dock to the main Interface */
737 addDockWidget( Qt::BottomDockWidgetArea, dockPL );
739 /* Make the playlist floating is requested. Default is not. */
740 settings->beginGroup( "MainWindow" );
741 if( settings->value( "playlist-floats", 1 ).toInt() )
743 msg_Dbg( p_intf, "we don't want the playlist inside");
744 dockPL->setFloating( true );
746 settings->endGroup();
747 settings->beginGroup( "playlist" );
748 dockPL->move( settings->value( "pos", QPoint( 0,0 ) ).toPoint() );
749 QSize newSize = settings->value( "size", QSize( 400, 300 ) ).toSize();
750 if( newSize.isValid() )
751 dockPL->resize( newSize );
752 settings->endGroup();
755 playlistVisible = true;
759 /* toggle the visibility of the playlist */
761 resize( sizeHint() );
762 playlistVisible = !playlistVisible;
766 /* Function called from the menu to undock the playlist */
767 void MainInterface::undockPlaylist()
769 dockPL->setFloating( true );
770 resize( sizeHint() );
773 void MainInterface::toggleMinimalView()
775 TOGGLEV( menuBar() );
777 TOGGLEV( statusBar() );
778 doComponentsUpdate();
781 /* Video widget cannot do this synchronously as it runs in another thread */
782 /* Well, could it, actually ? Probably dangerous ... */
783 void MainInterface::doComponentsUpdate()
785 resize( sizeHint() );
786 msg_Dbg( p_intf, "Updating the geometry" );
790 /* toggling advanced controls buttons */
791 void MainInterface::toggleAdvanced()
793 controls->toggleAdvanced();
796 /* Get the visibility status of the controls (hidden or not, advanced or not) */
797 int MainInterface::getControlsVisibilityStatus()
799 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
800 + CONTROLS_ADVANCED * controls->b_advancedVisible );
804 void MainInterface::visual()
806 if( !VISIBLE( visualSelector) )
808 visualSelector->show();
809 if( !THEMIM->getIM()->hasVideo() )
811 /* Show the background widget */
813 visualSelectorEnabled = true;
817 /* Stop any currently running visualization */
818 visualSelector->hide();
819 visualSelectorEnabled = false;
821 doComponentsUpdate();
825 /************************************************************************
827 ************************************************************************/
828 void MainInterface::setDisplayPosition( float pos, int time, int length )
830 char psz_length[MSTRTIME_MAX_SIZE], psz_time[MSTRTIME_MAX_SIZE];
831 secstotimestr( psz_length, length );
832 secstotimestr( psz_time, ( b_remainingTime && length ) ? length - time
836 timestr.sprintf( "%s/%s", psz_time,
837 ( !length && time ) ? "--:--" : psz_length );
839 /* Add a minus to remaining time*/
840 if( b_remainingTime && length ) timeLabel->setText( " -"+timestr+" " );
841 else timeLabel->setText( " "+timestr+" " );
844 void MainInterface::toggleTimeDisplay()
846 b_remainingTime = !b_remainingTime;
849 void MainInterface::setName( QString name )
851 input_name = name; /* store it for the QSystray use */
852 /* Display it in the status bar, but also as a Tooltip in case it doesn't
854 nameLabel->setText( " " + name + " " );
855 nameLabel->setToolTip( " " + name +" " );
858 void MainInterface::setStatus( int status )
860 /* Forward the status to the controls to toggle Play/Pause */
861 controls->setStatus( status );
862 /* And in the systray for the menu */
864 QVLCMenu::updateSystrayMenu( this, p_intf );
867 void MainInterface::setRate( int rate )
870 str.setNum( ( 1000 / (double)rate ), 'f', 2 );
872 speedLabel->setText( str );
873 speedControl->updateControls( rate );
876 void MainInterface::updateOnTimer()
878 if( intf_ShouldDie( p_intf ) )
880 QApplication::closeAllWindows();
881 QApplication::quit();
884 if( need_components_update )
886 doComponentsUpdate();
887 need_components_update = false;
891 controls->updateOnTimer();
894 /*****************************************************************************
895 * Systray Icon and Systray Menu
896 *****************************************************************************/
899 * Create a SystemTray icon and a menu that would go with it.
900 * Connects to a click handler on the icon.
902 void MainInterface::createSystray()
905 if( QDate::currentDate().dayOfYear() >= 354 )
906 iconVLC = QIcon( QPixmap( ":/vlc128-christmas.png" ) );
908 iconVLC = QIcon( QPixmap( ":/vlc128.png" ) );
909 sysTray = new QSystemTrayIcon( iconVLC, this );
910 sysTray->setToolTip( qtr( "VLC media player" ));
912 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
913 systrayMenu->setIcon( iconVLC );
915 QVLCMenu::updateSystrayMenu( this, p_intf, true );
918 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
919 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
923 * Updates the Systray Icon's menu and toggle the main interface
925 void MainInterface::toggleUpdateSystrayMenu()
927 /* If hidden, show it */
933 else if( isMinimized() )
943 /* check if any visible window is above vlc in the z-order,
944 * but ignore the ones always on top */
947 wi.cbSize = sizeof( WINDOWINFO );
948 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
949 hwnd && !IsWindowVisible( hwnd );
950 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
951 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
952 (wi.dwExStyle&WS_EX_TOPMOST) )
954 if( isActiveWindow() )
964 QVLCMenu::updateSystrayMenu( this, p_intf );
967 void MainInterface::handleSystrayClick(
968 QSystemTrayIcon::ActivationReason reason )
972 case QSystemTrayIcon::Trigger:
973 toggleUpdateSystrayMenu();
975 case QSystemTrayIcon::MiddleClick:
976 sysTray->showMessage( qtr( "VLC media player" ),
977 qtr( "Control menu for the player" ),
978 QSystemTrayIcon::Information, 3000 );
984 * Updates the name of the systray Icon tooltip.
985 * Doesn't check if the systray exists, check before you call it.
987 void MainInterface::updateSystrayTooltipName( QString name )
991 sysTray->setToolTip( qtr( "VLC media player" ) );
995 sysTray->setToolTip( name );
996 if( notificationEnabled && ( isHidden() || isMinimized() ) )
998 sysTray->showMessage( qtr( "VLC media player" ), name,
999 QSystemTrayIcon::NoIcon, 3000 );
1005 * Updates the status of the systray Icon tooltip.
1006 * Doesn't check if the systray exists, check before you call it.
1008 void MainInterface::updateSystrayTooltipStatus( int i_status )
1015 sysTray->setToolTip( qtr( "VLC media player" ) );
1020 sysTray->setToolTip( input_name );
1025 sysTray->setToolTip( input_name + " - "
1032 /************************************************************************
1034 ************************************************************************/
1035 void MainInterface::dropEvent(QDropEvent *event)
1037 const QMimeData *mimeData = event->mimeData();
1039 /* D&D of a subtitles file, add it on the fly */
1040 if( mimeData->urls().size() == 1 )
1042 if( THEMIM->getIM()->hasInput() )
1044 if( input_AddSubtitles( THEMIM->getInput(),
1045 qtu( mimeData->urls()[0].toString() ),
1048 event->acceptProposedAction();
1054 foreach( QUrl url, mimeData->urls() ) {
1055 QString s = url.toString();
1056 if( s.length() > 0 ) {
1057 playlist_Add( THEPL, qtu(s), NULL,
1058 PLAYLIST_APPEND | (first ? PLAYLIST_GO:0),
1059 PLAYLIST_END, VLC_TRUE, VLC_FALSE );
1063 event->acceptProposedAction();
1065 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1067 event->acceptProposedAction();
1069 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1071 event->acceptProposedAction();
1073 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1078 /************************************************************************
1080 ************************************************************************/
1081 void MainInterface::customEvent( QEvent *event )
1084 if( event->type() == PLDockEvent_Type )
1086 PlaylistDialog::killInstance();
1087 playlistEmbeddedFlag = true;
1089 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1094 if ( event->type() == SetVideoOnTopEvent_Type )
1096 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1097 if( p_event->OnTop() )
1098 setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
1100 setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint);
1101 show(); /* necessary to apply window flags?? */
1105 void MainInterface::keyPressEvent( QKeyEvent *e )
1107 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() & Qt::Key_H )
1108 && menuBar()->isHidden() )
1110 toggleMinimalView();
1114 int i_vlck = qtEventToVLCKey( e );
1117 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1124 void MainInterface::wheelEvent( QWheelEvent *e )
1126 int i_vlckey = qtWheelEventToVLCKey( e );
1127 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1131 void MainInterface::closeEvent( QCloseEvent *e )
1134 vlc_object_kill( p_intf );
1135 QApplication::closeAllWindows();
1136 QApplication::quit();
1139 /*****************************************************************************
1141 *****************************************************************************/
1142 static int InteractCallback( vlc_object_t *p_this,
1143 const char *psz_var, vlc_value_t old_val,
1144 vlc_value_t new_val, void *param )
1146 intf_dialog_args_t *p_arg = new intf_dialog_args_t;
1147 p_arg->p_dialog = (interaction_dialog_t *)(new_val.p_address);
1148 DialogEvent *event = new DialogEvent( INTF_DIALOG_INTERACTION, 0, p_arg );
1149 QApplication::postEvent( THEDP, static_cast<QEvent*>(event) );
1153 /*****************************************************************************
1154 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1155 * We don't show the menu directly here because we don't want the
1156 * caller to block for a too long time.
1157 *****************************************************************************/
1158 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1159 vlc_value_t old_val, vlc_value_t new_val, void *param )
1161 intf_thread_t *p_intf = (intf_thread_t *)param;
1162 msg_Dbg( p_this, "Menu Requested" ); // DEBUG to track the non disparition of the menu...
1164 if( p_intf->pf_show_dialog )
1166 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1167 new_val.b_bool, 0 );
1173 /*****************************************************************************
1174 * IntfShowCB: callback triggered by the intf-show playlist variable.
1175 *****************************************************************************/
1176 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1177 vlc_value_t old_val, vlc_value_t new_val, void *param )
1179 intf_thread_t *p_intf = (intf_thread_t *)param;
1180 msg_Dbg( p_this, "Intf Show Requested" ); // DEBUG to track the non disparition of the menu...
1181 //p_intf->p_sys->b_intf_show = VLC_TRUE;