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 *****************************************************************************/
31 #include "main_interface.hpp"
32 #include "input_manager.hpp"
33 #include "util/qvlcframe.hpp"
34 #include "util/customwidgets.hpp"
35 #include "dialogs_provider.hpp"
36 #include "components/interface_widgets.hpp"
37 #include "components/playlist/playlist.hpp"
38 #include "dialogs/extended.hpp"
39 #include "dialogs/playlist.hpp"
43 #include <QCloseEvent>
44 #include <QPushButton>
48 #include <QSystemTrayIcon>
53 #include <QWidgetAction>
54 #include <QDockWidget>
58 #include <QProgressBar>
64 #define SET_WIDTH(i,j) i->widgetSize.setWidth(j)
65 #define SET_HEIGHT(i,j) i->widgetSize.setHeight(j)
66 #define SET_WH( i,j,k) i->widgetSize.setWidth(j); i->widgetSize.setHeight(k);
68 #define DS(i) i.width(),i.height()
70 /* Callback prototypes */
71 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
72 vlc_value_t old_val, vlc_value_t new_val, void *param );
73 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
74 vlc_value_t old_val, vlc_value_t new_val, void *param );
75 static int InteractCallback( vlc_object_t *, const char *, vlc_value_t,
78 static void *DoRequest( intf_thread_t *p_intf, vout_thread_t *p_vout,
79 int *pi1, int *pi2, unsigned int*pi3,unsigned int*pi4)
81 return p_intf->p_sys->p_mi->requestVideo( p_vout, pi1, pi2, pi3, pi4 );
83 static void DoRelease( intf_thread_t *p_intf, void *p_win )
85 return p_intf->p_sys->p_mi->releaseVideo( p_win );
87 static int DoControl( intf_thread_t *p_intf, void *p_win, int i_q, va_list a )
89 return p_intf->p_sys->p_mi->controlVideo( p_win, i_q, a );
92 MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
94 /* Variables initialisation */
95 // need_components_update = false;
96 bgWidget = NULL; videoWidget = NULL; playlistWidget = NULL;
97 videoIsActive = false;
99 playlistVisible = false;
101 /* Ask for privacy */
105 * Configuration and settings
106 * Pre-building of interface
108 settings = new QSettings( "vlc", "vlc-qt-interface" );
109 settings->beginGroup( "MainWindow" );
112 setFocusPolicy( Qt::StrongFocus );
113 setAcceptDrops( true );
114 setWindowIcon( QApplication::windowIcon() );
115 setWindowOpacity( config_GetFloat( p_intf, "qt-opacity" ) );
117 /* Set The Video In emebedded Mode or not */
118 videoEmbeddedFlag = config_GetInt( p_intf, "embedded-video" );
120 /* Are we in the enhanced always-video mode or not ? */
121 i_visualmode = config_GetInt( p_intf, "qt-display-mode" );
123 /* Set the other interface settings */
124 //TODO: I don't like that code
125 visualSelectorEnabled = settings->value( "visual-selector", false ).toBool();
126 notificationEnabled = config_GetInt( p_intf, "qt-notification" )
129 /**************************
130 * UI and Widgets design
131 **************************/
132 setVLCWindowsTitle();
133 handleMainUi( settings );
135 /* Create a Dock to get the playlist */
136 dockPL = new QDockWidget( qtr( "Playlist" ), this );
137 dockPL->setSizePolicy( QSizePolicy::Preferred,
138 QSizePolicy::Expanding );
139 dockPL->setFeatures( QDockWidget::AllDockWidgetFeatures );
140 dockPL->setAllowedAreas( Qt::LeftDockWidgetArea
141 | Qt::RightDockWidgetArea
142 | Qt::BottomDockWidgetArea );
148 QVLCMenu::createMenuBar( this, p_intf, visualSelectorEnabled );
153 /* Widgets Creation*/
154 b_remainingTime = false;
155 timeLabel = new TimeLabel;
156 timeLabel->setText( " --:--/--:-- " );
157 timeLabel->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
158 nameLabel = new QLabel;
159 nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
160 | Qt::TextSelectableByKeyboard );
161 speedLabel = new QLabel( "1.00x" );
162 speedLabel->setContextMenuPolicy ( Qt::CustomContextMenu );
164 /* Styling those labels */
165 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
166 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
167 nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
169 pgBar = new QProgressBar;
172 /* and adding those */
173 statusBar()->addWidget( nameLabel, 8 );
174 statusBar()->addPermanentWidget( speedLabel, 0 );
175 statusBar()->addPermanentWidget( pgBar, 0 );
176 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 /********************
216 ********************/
217 MainInputManager::getInstance( p_intf );
219 /**************************
220 * Various CONNECTs on IM *
221 **************************/
222 /* Connect the input manager to the GUI elements it manages */
224 /* It is also connected to the control->slider, see the ControlsWidget */
225 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
226 this, setDisplayPosition( float, int, int ) );
227 /* Change the SpeedRate in the Status */
228 CONNECT( THEMIM->getIM(), rateChanged( int ), this, setRate( int ) );
231 * Connects on nameChanged()
232 * Those connects are not merged because different options can trigger
235 /* Naming in the controller statusbar */
236 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
237 setName( QString ) );
238 /* and in the systray */
241 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
242 updateSystrayTooltipName( QString ) );
244 /* and in the title of the controller */
245 if( config_GetInt( p_intf, "qt-name-in-title" ) )
247 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
248 setVLCWindowsTitle( QString ) );
252 * CONNECTS on PLAY_STATUS
254 /* Status on the main controller */
255 CONNECT( THEMIM->getIM(), statusChanged( int ), this, setStatus( int ) );
256 /* and in the systray */
259 CONNECT( THEMIM->getIM(), statusChanged( int ), this,
260 updateSystrayTooltipStatus( int ) );
265 ON_TIMEOUT( updateOnTimer() );
266 //ON_TIMEOUT( debug() );
271 var_Create( p_intf, "interaction", VLC_VAR_ADDRESS );
272 var_AddCallback( p_intf, "interaction", InteractCallback, this );
273 p_intf->b_interaction = VLC_TRUE;
275 /* Register callback for the intf-popupmenu variable */
276 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
277 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
278 if( p_playlist != NULL )
280 var_AddCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
281 var_AddCallback( p_playlist, "intf-show", IntfShowCB, p_intf );
282 vlc_object_release( p_playlist );
285 /* VideoWidget connect mess to avoid different threads speaking to each other */
286 CONNECT( this, askReleaseVideo( void * ), this, releaseVideoSlot( void * ) );
287 CONNECT( this, askVideoToResize( unsigned int, unsigned int ),
288 videoWidget, SetSizing( unsigned int, unsigned int ) );
289 CONNECT( this, askUpdate(), this, doComponentsUpdate() );
291 CONNECT( dockPL, topLevelChanged( bool ), this, doComponentsUpdate() );
292 CONNECT( controls, advancedControlsToggled( bool ),
293 this, doComponentsUpdate() );
296 /* Size and placement of interface */
297 move( settings->value( "pos", QPoint( 0, 0 ) ).toPoint() );
299 QSize newSize = settings->value( "size", QSize( 350, 60 ) ).toSize();
300 if( newSize.isValid() )
306 msg_Warn( p_intf, "Invalid size in constructor" );
310 int tgPlay = settings->value( "playlist-visible", 0 ).toInt();
311 settings->endGroup();
320 if( i_visualmode == QT_MINIMAL_MODE )
323 /* Update the geometry TODO: is it useful */
327 MainInterface::~MainInterface()
329 msg_Dbg( p_intf, "Destroying the main interface" );
331 if( playlistWidget ) playlistWidget->savingSettings( settings );
332 if( ExtendedDialog::exists() )
333 ExtendedDialog::getInstance( p_intf )->savingSettings();
335 settings->beginGroup( "MainWindow" );
336 settings->setValue( "playlist-floats", (int)(dockPL->isFloating()) );
337 settings->setValue( "playlist-visible", (int)playlistVisible );
338 settings->setValue( "adv-controls",
339 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
340 settings->setValue( "pos", pos() );
341 settings->setValue( "size", size() );
343 settings->setValue( "backgroundSize", bgWidget->size() );
345 settings->endGroup();
348 /* Unregister callback for the intf-popupmenu variable */
349 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
350 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
351 if( p_playlist != NULL )
353 var_DelCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
354 var_DelCallback( p_playlist, "intf-show", IntfShowCB, p_intf );
355 vlc_object_release( p_playlist );
358 p_intf->b_interaction = VLC_FALSE;
359 var_DelCallback( p_intf, "interaction", InteractCallback, this );
361 p_intf->pf_request_window = NULL;
362 p_intf->pf_release_window = NULL;
363 p_intf->pf_control_window = NULL;
364 p_intf->p_sys->p_mi = NULL;
367 /*****************************
369 *****************************/
372 * Give the decorations of the Main Window a correct Name.
373 * If nothing is given, set it to VLC...
375 void MainInterface::setVLCWindowsTitle( QString aTitle )
377 if( aTitle.isEmpty() )
379 setWindowTitle( qtr( "VLC media player" ) );
383 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
387 void MainInterface::handleMainUi( QSettings *settings )
389 /* Create the main Widget and the mainLayout */
390 QWidget *main = new QWidget;
391 setCentralWidget( main );
392 mainLayout = new QVBoxLayout( main );
394 /* Margins, spacing */
395 main->setContentsMargins( 0, 0, 0, 0 );
396 // main->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
397 mainLayout->setMargin( 0 );
399 /* Create the CONTROLS Widget */
400 /* bool b_shiny = config_GetInt( p_intf, "qt-blingbling" ); */
401 controls = new ControlsWidget( p_intf, this,
402 settings->value( "adv-controls", false ).toBool(),
403 config_GetInt( p_intf, "qt-blingbling" ) );
405 /* Add the controls Widget to the main Widget */
406 mainLayout->insertWidget( 0, controls );
408 /* Create the Speed Control Widget */
409 speedControl = new SpeedControlWidget( p_intf );
410 speedControlMenu = new QMenu( this );
412 QWidgetAction *widgetAction = new QWidgetAction( speedControl );
413 widgetAction->setDefaultWidget( speedControl );
414 speedControlMenu->addAction( widgetAction );
417 /* Disabled for now, they SUCK */
419 visualSelector = new VisualSelector( p_intf );
420 mainLayout->insertWidget( 0, visualSelector );
421 visualSelector->hide();
424 /* And video Outputs */
425 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
426 i_visualmode == QT_MINIMAL_MODE )
428 bgWidget = new BackgroundWidget( p_intf );
430 settings->value( "backgroundSize", QSize( 300, 150 ) ).toSize() );
431 bgWidget->updateGeometry();
432 mainLayout->insertWidget( 0, bgWidget );
433 CONNECT( this, askBgWidgetToToggle(), bgWidget, toggle() );
436 if( videoEmbeddedFlag )
438 videoWidget = new VideoWidget( p_intf );
439 mainLayout->insertWidget( 0, videoWidget );
441 p_intf->pf_request_window = ::DoRequest;
442 p_intf->pf_release_window = ::DoRelease;
443 p_intf->pf_control_window = ::DoControl;
446 /* Finish the sizing */
450 inline void MainInterface::privacy()
453 * Ask for the network policy on FIRST STARTUP
455 if( config_GetInt( p_intf, "qt-privacy-ask") )
457 QList<ConfigControl *> controls;
458 if( privacyDialog( controls ) == QDialog::Accepted )
460 QList<ConfigControl *>::Iterator i;
461 for( i = controls.begin() ; i != controls.end() ; i++ )
463 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
464 c->doApply( p_intf );
467 config_PutInt( p_intf, "qt-privacy-ask" , 0 );
468 config_SaveConfigFile( p_intf, NULL );
473 int MainInterface::privacyDialog( QList<ConfigControl *> controls )
475 QDialog *privacy = new QDialog( this );
477 privacy->setWindowTitle( qtr( "Privacy and Network policies" ) );
479 QGridLayout *gLayout = new QGridLayout( privacy );
481 QGroupBox *blabla = new QGroupBox( qtr( "Privacy and Network Warning" ) );
482 QGridLayout *blablaLayout = new QGridLayout( blabla );
483 QLabel *text = new QLabel( qtr(
484 "<p>The <i>VideoLAN Team</i> doesn't like when an application goes "
485 "online without authorization.</p>\n "
486 "<p><i>VLC media player</i> can request limited information on "
487 "the Internet, especially to get CD covers and songs metadata or to know "
488 "if updates are available.</p>\n"
489 "<p><i>VLC media player</i> <b>DOES NOT</b> send or collect <b>ANY</b> "
490 "information, even anonymously, about your usage.</p>\n"
491 "<p>Therefore please check the following options, the default being "
492 "almost no access on the web.</p>\n") );
493 text->setWordWrap( true );
494 text->setTextFormat( Qt::RichText );
496 blablaLayout->addWidget( text, 0, 0 ) ;
498 QGroupBox *options = new QGroupBox;
499 QGridLayout *optionsLayout = new QGridLayout( options );
501 gLayout->addWidget( blabla, 0, 0, 1, 3 );
502 gLayout->addWidget( options, 1, 0, 1, 3 );
503 module_config_t *p_config;
504 ConfigControl *control;
507 #define CONFIG_GENERIC( option, type ) \
508 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
511 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
512 p_config, options, false, optionsLayout, line ); \
513 controls.append( control ); \
516 #define CONFIG_GENERIC_NOBOOL( option, type ) \
517 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
520 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
521 p_config, options, optionsLayout, line ); \
522 controls.append( control ); \
525 CONFIG_GENERIC( "album-art", IntegerList ); line++;
526 CONFIG_GENERIC_NOBOOL( "fetch-meta", Bool ); line++;
528 CONFIG_GENERIC_NOBOOL( "qt-updates-notif", Bool ); line++;
529 CONFIG_GENERIC_NOBOOL( "qt-updates-days", Integer ); line++;
531 QPushButton *ok = new QPushButton( qtr( "Ok" ) );
533 gLayout->addWidget( ok, 2, 2 );
535 CONNECT( ok, clicked(), privacy, accept() );
536 return privacy->exec();
539 //FIXME remove me at the end...
540 void MainInterface::debug()
542 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
543 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
546 /**********************************************************************
547 * Handling of sizing of the components
548 **********************************************************************/
550 /* This function is probably wrong, but we don't have many many choices...
551 Since we can't know from the playlist Widget if we are inside a dock or not,
552 because the playlist Widget can be called by THEDP, as a separate windows for
554 Maybe the other solution is to redefine the sizeHint() of the playlist and
555 ask _parent->isFloating()...
556 If you think this would be better, please FIXME it...
558 QSize MainInterface::sizeHint() const
560 int nwidth = controls->sizeHint().width();
561 int nheight = controls->isVisible() ?
562 controls->size().height()
563 + menuBar()->size().height()
564 + statusBar()->size().height()
567 msg_Dbg( p_intf, "1 %i %i", nheight, nwidth );
568 if( VISIBLE( bgWidget ) )
570 nheight += bgWidget->size().height();
571 nwidth = bgWidget->size().width();
572 msg_Dbg( p_intf, "1b %i %i", nheight, nwidth );
574 else if( videoIsActive )
576 nheight += videoWidget->size().height();
577 nwidth = videoWidget->size().width();
578 msg_Dbg( p_intf, "2 %i %i", nheight, nwidth );
580 if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget() )
582 nheight += dockPL->size().height();
583 nwidth = __MAX( nwidth, dockPL->size().width() );
584 msg_Dbg( p_intf, "3 %i %i", nheight, nwidth );
586 msg_Dbg( p_intf, "4 %i %i", nheight, nwidth );
587 return QSize( nwidth, nheight );
591 /* FIXME This is dead code and need to be removed AT THE END */
592 void MainInterface::resizeEvent( QResizeEvent *e )
595 videoWidget->widgetSize.setWidth( e->size().width() - addSize.width() );
596 if( videoWidget && videoIsActive && videoWidget->widgetSize.height() > 1 )
598 SET_WH( videoWidget, e->size().width() - addSize.width(),
599 e->size().height() - addSize.height() );
600 videoWidget->updateGeometry();
602 if( VISIBLE( playlistWidget ) )
604 // SET_WH( playlistWidget , e->size().width() - addSize.width(),
605 // e->size().height() - addSize.height() );
606 playlistWidget->updateGeometry();
611 /****************************************************************************
612 * Small right-click menu for rate control
613 ****************************************************************************/
614 void MainInterface::showSpeedMenu( QPoint pos )
616 speedControlMenu->exec( QCursor::pos() - pos
617 + QPoint( 0, speedLabel->height() ) );
620 /****************************************************************************
622 ****************************************************************************/
623 class SetVideoOnTopQtEvent : public QEvent
626 SetVideoOnTopQtEvent( bool _onTop ) :
627 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
639 /* function called from ::DoRequest in order to show a nice VideoWidget
641 void *MainInterface::requestVideo( vout_thread_t *p_nvout, int *pi_x,
642 int *pi_y, unsigned int *pi_width,
643 unsigned int *pi_height )
645 bool bgWasVisible = false;
647 /* Request the videoWidget */
648 void *ret = videoWidget->request( p_nvout,pi_x, pi_y, pi_width, pi_height );
649 if( ret ) /* The videoWidget is available */
651 /* Did we have a bg ? Hide it! */
652 if( VISIBLE( bgWidget) )
655 emit askBgWidgetToToggle();
658 /*if( THEMIM->getIM()->hasVideo() || !bgWasVisible )
660 videoWidget->widgetSize = QSize( *pi_width, *pi_height );
662 else /* Background widget available, use its size */
664 /* Ok, our visualizations are bad, so don't do this for the moment
665 * use the requested size anyway */
666 // videoWidget->widgetSize = bgWidget->widgeTSize;
667 /* videoWidget->widgetSize = QSize( *pi_width, *pi_height );
670 videoIsActive = true;
672 emit askVideoToResize( *pi_width, *pi_height );
678 void MainInterface::releaseVideo( void *p_win )
680 emit askReleaseVideo( p_win );
683 void MainInterface::releaseVideoSlot( void *p_win )
685 videoWidget->release( p_win );
688 if( bgWidget )// WORONG
691 videoIsActive = false;
695 int MainInterface::controlVideo( void *p_window, int i_query, va_list args )
697 int i_ret = VLC_EGENERIC;
702 unsigned int *pi_width = va_arg( args, unsigned int * );
703 unsigned int *pi_height = va_arg( args, unsigned int * );
704 *pi_width = videoWidget->width();
705 *pi_height = videoWidget->height();
711 unsigned int i_width = va_arg( args, unsigned int );
712 unsigned int i_height = va_arg( args, unsigned int );
713 emit askVideoToResize( i_width, i_height );
719 case VOUT_SET_STAY_ON_TOP:
721 int i_arg = va_arg( args, int );
722 QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
727 msg_Warn( p_intf, "unsupported control query" );
733 /*****************************************************************************
734 * Playlist, Visualisation and Menus handling
735 *****************************************************************************/
737 * Toggle the playlist widget or dialog
739 void MainInterface::togglePlaylist()
742 If no playlist exist, then create one and attach it to the DockPL*/
743 if( !playlistWidget )
745 playlistWidget = new PlaylistWidget( p_intf, settings, dockPL );
747 /* Add it to the parent DockWidget */
748 dockPL->setWidget( playlistWidget );
750 /* Add the dock to the main Interface */
751 addDockWidget( Qt::BottomDockWidgetArea, dockPL );
753 /* Make the playlist floating is requested. Default is not. */
754 settings->beginGroup( "MainWindow" );
755 if( settings->value( "playlist-floats", 1 ).toInt() )
757 msg_Dbg( p_intf, "we don't want the playlist inside");
758 dockPL->setFloating( true );
760 settings->endGroup();
761 settings->beginGroup( "playlist" );
762 dockPL->move( settings->value( "pos", QPoint( 0,0 ) ).toPoint() );
763 QSize newSize = settings->value( "size", QSize( 400, 300 ) ).toSize();
764 if( newSize.isValid() )
765 dockPL->resize( newSize );
766 settings->endGroup();
769 playlistVisible = true;
773 /* toggle the visibility of the playlist */
775 resize( sizeHint() );
776 playlistVisible = !playlistVisible;
780 /* Function called from the menu to undock the playlist */
781 void MainInterface::undockPlaylist()
783 dockPL->setFloating( true );
784 resize( sizeHint() );
787 void MainInterface::toggleMinimalView()
789 TOGGLEV( menuBar() );
791 TOGGLEV( statusBar() );
792 doComponentsUpdate();
795 /* Video widget cannot do this synchronously as it runs in another thread */
796 /* Well, could it, actually ? Probably dangerous ... */
797 void MainInterface::doComponentsUpdate()
799 resize( sizeHint() );
800 msg_Dbg( p_intf, "Updating the geometry" );
804 /* toggling advanced controls buttons */
805 void MainInterface::toggleAdvanced()
807 controls->toggleAdvanced();
810 /* Get the visibility status of the controls (hidden or not, advanced or not) */
811 int MainInterface::getControlsVisibilityStatus()
813 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
814 + CONTROLS_ADVANCED * controls->b_advancedVisible );
818 void MainInterface::visual()
820 if( !VISIBLE( visualSelector) )
822 visualSelector->show();
823 if( !THEMIM->getIM()->hasVideo() )
825 /* Show the background widget */
827 visualSelectorEnabled = true;
831 /* Stop any currently running visualization */
832 visualSelector->hide();
833 visualSelectorEnabled = false;
835 doComponentsUpdate();
839 /************************************************************************
841 ************************************************************************/
842 void MainInterface::setDisplayPosition( float pos, int time, int length )
844 char psz_length[MSTRTIME_MAX_SIZE], psz_time[MSTRTIME_MAX_SIZE];
845 secstotimestr( psz_length, length );
846 secstotimestr( psz_time, ( b_remainingTime && length ) ? length - time
850 timestr.sprintf( "%s/%s", psz_time,
851 ( !length && time ) ? "--:--" : psz_length );
853 /* Add a minus to remaining time*/
854 if( b_remainingTime && length ) timeLabel->setText( " -"+timestr+" " );
855 else timeLabel->setText( " "+timestr+" " );
858 void MainInterface::toggleTimeDisplay()
860 b_remainingTime = !b_remainingTime;
863 void MainInterface::setName( QString name )
865 input_name = name; /* store it for the QSystray use */
866 /* Display it in the status bar, but also as a Tooltip in case it doesn't
868 nameLabel->setText( " " + name + " " );
869 nameLabel->setToolTip( " " + name +" " );
872 void MainInterface::setStatus( int status )
874 /* Forward the status to the controls to toggle Play/Pause */
875 controls->setStatus( status );
876 /* And in the systray for the menu */
878 QVLCMenu::updateSystrayMenu( this, p_intf );
881 void MainInterface::setRate( int rate )
884 str.setNum( ( 1000 / (double)rate ), 'f', 2 );
886 speedLabel->setText( str );
887 speedControl->updateControls( rate );
890 void MainInterface::updateOnTimer()
892 if( intf_ShouldDie( p_intf ) )
894 QApplication::closeAllWindows();
895 QApplication::quit();
898 if( need_components_update )
900 doComponentsUpdate();
901 need_components_update = false;
906 /*****************************************************************************
907 * Systray Icon and Systray Menu
908 *****************************************************************************/
911 * Create a SystemTray icon and a menu that would go with it.
912 * Connects to a click handler on the icon.
914 void MainInterface::createSystray()
917 if( QDate::currentDate().dayOfYear() >= 354 )
918 iconVLC = QIcon( QPixmap( ":/vlc128-christmas.png" ) );
920 iconVLC = QIcon( QPixmap( ":/vlc128.png" ) );
921 sysTray = new QSystemTrayIcon( iconVLC, this );
922 sysTray->setToolTip( qtr( "VLC media player" ));
924 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
925 systrayMenu->setIcon( iconVLC );
927 QVLCMenu::updateSystrayMenu( this, p_intf, true );
930 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
931 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
935 * Updates the Systray Icon's menu and toggle the main interface
937 void MainInterface::toggleUpdateSystrayMenu()
939 /* If hidden, show it */
945 else if( isMinimized() )
955 /* check if any visible window is above vlc in the z-order,
956 * but ignore the ones always on top */
959 wi.cbSize = sizeof( WINDOWINFO );
960 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
961 hwnd && !IsWindowVisible( hwnd );
962 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
963 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
964 (wi.dwExStyle&WS_EX_TOPMOST) )
966 if( isActiveWindow() )
976 QVLCMenu::updateSystrayMenu( this, p_intf );
979 void MainInterface::handleSystrayClick(
980 QSystemTrayIcon::ActivationReason reason )
984 case QSystemTrayIcon::Trigger:
985 toggleUpdateSystrayMenu();
987 case QSystemTrayIcon::MiddleClick:
988 sysTray->showMessage( qtr( "VLC media player" ),
989 qtr( "Control menu for the player" ),
990 QSystemTrayIcon::Information, 3000 );
996 * Updates the name of the systray Icon tooltip.
997 * Doesn't check if the systray exists, check before you call it.
999 void MainInterface::updateSystrayTooltipName( QString name )
1001 if( name.isEmpty() )
1003 sysTray->setToolTip( qtr( "VLC media player" ) );
1007 sysTray->setToolTip( name );
1008 if( notificationEnabled && ( isHidden() || isMinimized() ) )
1010 sysTray->showMessage( qtr( "VLC media player" ), name,
1011 QSystemTrayIcon::NoIcon, 3000 );
1017 * Updates the status of the systray Icon tooltip.
1018 * Doesn't check if the systray exists, check before you call it.
1020 void MainInterface::updateSystrayTooltipStatus( int i_status )
1027 sysTray->setToolTip( qtr( "VLC media player" ) );
1032 sysTray->setToolTip( input_name );
1037 sysTray->setToolTip( input_name + " - "
1044 /************************************************************************
1046 ************************************************************************/
1047 void MainInterface::dropEvent(QDropEvent *event)
1049 const QMimeData *mimeData = event->mimeData();
1051 /* D&D of a subtitles file, add it on the fly */
1052 if( mimeData->urls().size() == 1 )
1054 if( THEMIM->getIM()->hasInput() )
1056 if( input_AddSubtitles( THEMIM->getInput(),
1057 qtu( mimeData->urls()[0].toString() ),
1060 event->acceptProposedAction();
1066 foreach( QUrl url, mimeData->urls() ) {
1067 QString s = url.toString();
1068 if( s.length() > 0 ) {
1069 playlist_Add( THEPL, qtu(s), NULL,
1070 PLAYLIST_APPEND | (first ? PLAYLIST_GO:0),
1071 PLAYLIST_END, VLC_TRUE, VLC_FALSE );
1075 event->acceptProposedAction();
1077 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1079 event->acceptProposedAction();
1081 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1083 event->acceptProposedAction();
1085 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1090 /************************************************************************
1092 ************************************************************************/
1093 void MainInterface::customEvent( QEvent *event )
1096 if( event->type() == PLDockEvent_Type )
1098 PlaylistDialog::killInstance();
1099 playlistEmbeddedFlag = true;
1101 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1106 if ( event->type() == SetVideoOnTopEvent_Type )
1108 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1109 if( p_event->OnTop() )
1110 setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
1112 setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint);
1113 show(); /* necessary to apply window flags?? */
1117 void MainInterface::keyPressEvent( QKeyEvent *e )
1119 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() & Qt::Key_H )
1120 && menuBar()->isHidden() )
1122 toggleMinimalView();
1126 int i_vlck = qtEventToVLCKey( e );
1129 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1136 void MainInterface::wheelEvent( QWheelEvent *e )
1138 int i_vlckey = qtWheelEventToVLCKey( e );
1139 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1143 void MainInterface::closeEvent( QCloseEvent *e )
1149 void MainInterface::toggleFullScreen( void )
1151 if( isFullScreen() )
1157 /*****************************************************************************
1159 *****************************************************************************/
1160 static int InteractCallback( vlc_object_t *p_this,
1161 const char *psz_var, vlc_value_t old_val,
1162 vlc_value_t new_val, void *param )
1164 intf_dialog_args_t *p_arg = new intf_dialog_args_t;
1165 p_arg->p_dialog = (interaction_dialog_t *)(new_val.p_address);
1166 DialogEvent *event = new DialogEvent( INTF_DIALOG_INTERACTION, 0, p_arg );
1167 QApplication::postEvent( THEDP, static_cast<QEvent*>(event) );
1171 /*****************************************************************************
1172 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1173 * We don't show the menu directly here because we don't want the
1174 * caller to block for a too long time.
1175 *****************************************************************************/
1176 static int PopupMenuCB( 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, "Menu Requested" ); // DEBUG to track the non disparition of the menu...
1182 if( p_intf->pf_show_dialog )
1184 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1185 new_val.b_bool, 0 );
1191 /*****************************************************************************
1192 * IntfShowCB: callback triggered by the intf-show playlist variable.
1193 *****************************************************************************/
1194 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1195 vlc_value_t old_val, vlc_value_t new_val, void *param )
1197 intf_thread_t *p_intf = (intf_thread_t *)param;
1198 msg_Dbg( p_this, "Intf Show Requested" ); // DEBUG to track the non disparition of the menu...
1199 //p_intf->p_sys->b_intf_show = VLC_TRUE;