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 );
178 /* timeLabel behaviour:
179 - double clicking opens the goto time dialog
180 - right-clicking and clicking just toggle between remaining and
182 CONNECT( timeLabel, timeLabelClicked(), this, toggleTimeDisplay() );
183 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
184 CONNECT( timeLabel, timeLabelDoubleClicked(), this, toggleTimeDisplay() );
186 /* Speed Label behaviour:
187 - right click gives the vertical speed slider */
188 CONNECT( speedLabel, customContextMenuRequested( QPoint ),
189 this, showSpeedMenu( QPoint ) );
191 /**********************
192 * Systray Management *
193 **********************/
195 bool b_createSystray = false;
196 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
197 if( config_GetInt( p_intf, "qt-start-minimized") )
199 if( b_systrayAvailable )
201 b_createSystray = true;
202 hide(); //FIXME BUG HERE
204 else msg_Warn( p_intf, "You can't minize if you haven't a system "
207 if( config_GetInt( p_intf, "qt-system-tray") )
208 b_createSystray = true;
210 if( b_systrayAvailable && b_createSystray )
213 /********************
215 ********************/
216 MainInputManager::getInstance( p_intf );
218 /**************************
219 * Various CONNECTs on IM *
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() );
295 /* Size and placement of interface */
296 move( settings->value( "pos", QPoint( 0, 0 ) ).toPoint() );
298 QSize newSize = settings->value( "size", QSize( 350, 60 ) ).toSize();
299 if( newSize.isValid() )
305 msg_Warn( p_intf, "Invalid size in constructor" );
309 int tgPlay = settings->value( "playlist-visible", 0 ).toInt();
310 settings->endGroup();
319 if( i_visualmode == QT_MINIMAL_MODE )
322 /* Update the geometry TODO: is it useful */
326 MainInterface::~MainInterface()
328 msg_Dbg( p_intf, "Destroying the main interface" );
330 if( playlistWidget ) playlistWidget->savingSettings( settings );
331 if( ExtendedDialog::exists() )
332 ExtendedDialog::getInstance( p_intf )->savingSettings();
334 settings->beginGroup( "MainWindow" );
335 settings->setValue( "playlist-floats", (int)(dockPL->isFloating()) );
336 settings->setValue( "playlist-visible", (int)playlistVisible );
337 settings->setValue( "adv-controls",
338 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
339 settings->setValue( "pos", pos() );
340 settings->setValue( "size", size() );
342 settings->setValue( "backgroundSize", bgWidget->size() );
344 settings->endGroup();
347 /* Unregister callback for the intf-popupmenu variable */
348 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
349 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
350 if( p_playlist != NULL )
352 var_DelCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
353 var_DelCallback( p_playlist, "intf-show", IntfShowCB, p_intf );
354 vlc_object_release( p_playlist );
357 p_intf->b_interaction = VLC_FALSE;
358 var_DelCallback( p_intf, "interaction", InteractCallback, this );
360 p_intf->pf_request_window = NULL;
361 p_intf->pf_release_window = NULL;
362 p_intf->pf_control_window = NULL;
363 p_intf->p_sys->p_mi = NULL;
366 /*****************************
368 *****************************/
371 * Give the decorations of the Main Window a correct Name.
372 * If nothing is given, set it to VLC...
374 void MainInterface::setVLCWindowsTitle( QString aTitle )
376 if( aTitle.isEmpty() )
378 setWindowTitle( qtr( "VLC media player" ) );
382 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
386 void MainInterface::handleMainUi( QSettings *settings )
388 /* Create the main Widget and the mainLayout */
389 QWidget *main = new QWidget;
390 setCentralWidget( main );
391 mainLayout = new QVBoxLayout( main );
393 /* Margins, spacing */
394 main->setContentsMargins( 0, 0, 0, 0 );
395 // main->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
396 mainLayout->setMargin( 0 );
398 /* Create the CONTROLS Widget */
399 /* bool b_shiny = config_GetInt( p_intf, "qt-blingbling" ); */
400 controls = new ControlsWidget( p_intf, this,
401 settings->value( "adv-controls", false ).toBool(),
402 config_GetInt( p_intf, "qt-blingbling" ) );
404 /* Add the controls Widget to the main Widget */
405 mainLayout->insertWidget( 0, controls );
407 /* Create the Speed Control Widget */
408 speedControl = new SpeedControlWidget( p_intf );
409 speedControlMenu = new QMenu( this );
411 QWidgetAction *widgetAction = new QWidgetAction( speedControl );
412 widgetAction->setDefaultWidget( speedControl );
413 speedControlMenu->addAction( widgetAction );
416 /* Disabled for now, they SUCK */
418 visualSelector = new VisualSelector( p_intf );
419 mainLayout->insertWidget( 0, visualSelector );
420 visualSelector->hide();
423 /* And video Outputs */
424 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
425 i_visualmode == QT_MINIMAL_MODE )
427 bgWidget = new BackgroundWidget( p_intf );
429 settings->value( "backgroundSize", QSize( 300, 150 ) ).toSize() );
430 bgWidget->updateGeometry();
431 mainLayout->insertWidget( 0, bgWidget );
432 CONNECT( this, askBgWidgetToToggle(), bgWidget, toggle() );
435 if( videoEmbeddedFlag )
437 videoWidget = new VideoWidget( p_intf );
438 mainLayout->insertWidget( 0, videoWidget );
440 p_intf->pf_request_window = ::DoRequest;
441 p_intf->pf_release_window = ::DoRelease;
442 p_intf->pf_control_window = ::DoControl;
445 /* Finish the sizing */
449 inline void MainInterface::privacy()
452 * Ask for the network policy on FIRST STARTUP
454 if( config_GetInt( p_intf, "qt-privacy-ask") )
456 QList<ConfigControl *> controls;
457 if( privacyDialog( controls ) == QDialog::Accepted )
459 QList<ConfigControl *>::Iterator i;
460 for( i = controls.begin() ; i != controls.end() ; i++ )
462 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
463 c->doApply( p_intf );
466 config_PutInt( p_intf, "qt-privacy-ask" , 0 );
467 config_SaveConfigFile( p_intf, NULL );
472 int MainInterface::privacyDialog( QList<ConfigControl *> controls )
474 QDialog *privacy = new QDialog( this );
476 privacy->setWindowTitle( qtr( "Privacy and Network policies" ) );
478 QGridLayout *gLayout = new QGridLayout( privacy );
480 QGroupBox *blabla = new QGroupBox( qtr( "Privacy and Network Warning" ) );
481 QGridLayout *blablaLayout = new QGridLayout( blabla );
482 QLabel *text = new QLabel( qtr(
483 "<p>The <i>VideoLAN Team</i> doesn't like when an application goes "
484 "online without authorization.</p>\n "
485 "<p><i>VLC media player</i> can request limited information on "
486 "the Internet, especially to get CD covers and songs metadata or to know "
487 "if updates are available.</p>\n"
488 "<p><i>VLC media player</i> <b>DOES NOT</b> send or collect <b>ANY</b> "
489 "information, even anonymously, about your usage.</p>\n"
490 "<p>Therefore please check the following options, the default being "
491 "almost no access on the web.</p>\n") );
492 text->setWordWrap( true );
493 text->setTextFormat( Qt::RichText );
495 blablaLayout->addWidget( text, 0, 0 ) ;
497 QGroupBox *options = new QGroupBox;
498 QGridLayout *optionsLayout = new QGridLayout( options );
500 gLayout->addWidget( blabla, 0, 0, 1, 3 );
501 gLayout->addWidget( options, 1, 0, 1, 3 );
502 module_config_t *p_config;
503 ConfigControl *control;
506 #define CONFIG_GENERIC( option, type ) \
507 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
510 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
511 p_config, options, false, optionsLayout, line ); \
512 controls.append( control ); \
515 #define CONFIG_GENERIC_NOBOOL( option, type ) \
516 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
519 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
520 p_config, options, optionsLayout, line ); \
521 controls.append( control ); \
524 CONFIG_GENERIC( "album-art", IntegerList ); line++;
525 CONFIG_GENERIC_NOBOOL( "fetch-meta", Bool ); line++;
527 CONFIG_GENERIC_NOBOOL( "qt-updates-notif", Bool ); line++;
528 CONFIG_GENERIC_NOBOOL( "qt-updates-days", Integer ); line++;
530 QPushButton *ok = new QPushButton( qtr( "Ok" ) );
532 gLayout->addWidget( ok, 2, 2 );
534 CONNECT( ok, clicked(), privacy, accept() );
535 return privacy->exec();
538 //FIXME remove me at the end...
539 void MainInterface::debug()
541 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
542 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
545 /**********************************************************************
546 * Handling of sizing of the components
547 **********************************************************************/
549 /* This function is probably wrong, but we don't have many many choices...
550 Since we can't know from the playlist Widget if we are inside a dock or not,
551 because the playlist Widget can be called by THEDP, as a separate windows for
553 Maybe the other solution is to redefine the sizeHint() of the playlist and
554 ask _parent->isFloating()...
555 If you think this would be better, please FIXME it...
557 QSize MainInterface::sizeHint() const
559 int nwidth = controls->sizeHint().width();
560 int nheight = controls->isVisible() ?
561 controls->size().height()
562 + menuBar()->size().height()
563 + statusBar()->size().height()
566 msg_Dbg( p_intf, "1 %i %i", nheight, nwidth );
567 if( VISIBLE( bgWidget ) )
569 nheight += bgWidget->size().height();
570 nwidth = bgWidget->size().width();
571 msg_Dbg( p_intf, "1b %i %i", nheight, nwidth );
573 else if( videoIsActive )
575 nheight += videoWidget->size().height();
576 nwidth = videoWidget->size().width();
577 msg_Dbg( p_intf, "2 %i %i", nheight, nwidth );
579 if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget() )
581 nheight += dockPL->size().height();
582 nwidth = __MAX( nwidth, dockPL->size().width() );
583 msg_Dbg( p_intf, "3 %i %i", nheight, nwidth );
585 msg_Dbg( p_intf, "4 %i %i", nheight, nwidth );
586 return QSize( nwidth, nheight );
590 /* FIXME This is dead code and need to be removed AT THE END */
591 void MainInterface::resizeEvent( QResizeEvent *e )
594 videoWidget->widgetSize.setWidth( e->size().width() - addSize.width() );
595 if( videoWidget && videoIsActive && videoWidget->widgetSize.height() > 1 )
597 SET_WH( videoWidget, e->size().width() - addSize.width(),
598 e->size().height() - addSize.height() );
599 videoWidget->updateGeometry();
601 if( VISIBLE( playlistWidget ) )
603 // SET_WH( playlistWidget , e->size().width() - addSize.width(),
604 // e->size().height() - addSize.height() );
605 playlistWidget->updateGeometry();
610 /****************************************************************************
611 * Small right-click menu for rate control
612 ****************************************************************************/
613 void MainInterface::showSpeedMenu( QPoint pos )
615 speedControlMenu->exec( QCursor::pos() - pos
616 + QPoint( 0, speedLabel->height() ) );
619 /****************************************************************************
621 ****************************************************************************/
622 class SetVideoOnTopQtEvent : public QEvent
625 SetVideoOnTopQtEvent( bool _onTop ) :
626 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
638 /* function called from ::DoRequest in order to show a nice VideoWidget
640 void *MainInterface::requestVideo( vout_thread_t *p_nvout, int *pi_x,
641 int *pi_y, unsigned int *pi_width,
642 unsigned int *pi_height )
644 bool bgWasVisible = false;
646 /* Request the videoWidget */
647 void *ret = videoWidget->request( p_nvout,pi_x, pi_y, pi_width, pi_height );
648 if( ret ) /* The videoWidget is available */
650 /* Did we have a bg ? Hide it! */
651 if( VISIBLE( bgWidget) )
654 emit askBgWidgetToToggle();
657 /*if( THEMIM->getIM()->hasVideo() || !bgWasVisible )
659 videoWidget->widgetSize = QSize( *pi_width, *pi_height );
661 else /* Background widget available, use its size */
663 /* Ok, our visualizations are bad, so don't do this for the moment
664 * use the requested size anyway */
665 // videoWidget->widgetSize = bgWidget->widgeTSize;
666 /* videoWidget->widgetSize = QSize( *pi_width, *pi_height );
669 videoIsActive = true;
671 emit askVideoToResize( *pi_width, *pi_height );
677 void MainInterface::releaseVideo( void *p_win )
679 emit askReleaseVideo( p_win );
682 void MainInterface::releaseVideoSlot( void *p_win )
684 videoWidget->release( p_win );
687 if( bgWidget )// WORONG
690 videoIsActive = false;
694 int MainInterface::controlVideo( void *p_window, int i_query, va_list args )
696 int i_ret = VLC_EGENERIC;
701 unsigned int *pi_width = va_arg( args, unsigned int * );
702 unsigned int *pi_height = va_arg( args, unsigned int * );
703 *pi_width = videoWidget->width();
704 *pi_height = videoWidget->height();
710 unsigned int i_width = va_arg( args, unsigned int );
711 unsigned int i_height = va_arg( args, unsigned int );
712 emit askVideoToResize( i_width, i_height );
718 case VOUT_SET_STAY_ON_TOP:
720 int i_arg = va_arg( args, int );
721 QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
726 msg_Warn( p_intf, "unsupported control query" );
732 /*****************************************************************************
733 * Playlist, Visualisation and Menus handling
734 *****************************************************************************/
736 * Toggle the playlist widget or dialog
738 void MainInterface::togglePlaylist()
741 If no playlist exist, then create one and attach it to the DockPL*/
742 if( !playlistWidget )
744 playlistWidget = new PlaylistWidget( p_intf, settings, dockPL );
746 /* Add it to the parent DockWidget */
747 dockPL->setWidget( playlistWidget );
749 /* Add the dock to the main Interface */
750 addDockWidget( Qt::BottomDockWidgetArea, dockPL );
752 /* Make the playlist floating is requested. Default is not. */
753 settings->beginGroup( "MainWindow" );
754 if( settings->value( "playlist-floats", 1 ).toInt() )
756 msg_Dbg( p_intf, "we don't want the playlist inside");
757 dockPL->setFloating( true );
759 settings->endGroup();
760 settings->beginGroup( "playlist" );
761 dockPL->move( settings->value( "pos", QPoint( 0,0 ) ).toPoint() );
762 QSize newSize = settings->value( "size", QSize( 400, 300 ) ).toSize();
763 if( newSize.isValid() )
764 dockPL->resize( newSize );
765 settings->endGroup();
768 playlistVisible = true;
772 /* toggle the visibility of the playlist */
774 resize( sizeHint() );
775 playlistVisible = !playlistVisible;
779 /* Function called from the menu to undock the playlist */
780 void MainInterface::undockPlaylist()
782 dockPL->setFloating( true );
783 resize( sizeHint() );
786 void MainInterface::toggleMinimalView()
788 TOGGLEV( menuBar() );
790 TOGGLEV( statusBar() );
791 doComponentsUpdate();
794 /* Video widget cannot do this synchronously as it runs in another thread */
795 /* Well, could it, actually ? Probably dangerous ... */
796 void MainInterface::doComponentsUpdate()
798 resize( sizeHint() );
799 msg_Dbg( p_intf, "Updating the geometry" );
803 /* toggling advanced controls buttons */
804 void MainInterface::toggleAdvanced()
806 controls->toggleAdvanced();
809 /* Get the visibility status of the controls (hidden or not, advanced or not) */
810 int MainInterface::getControlsVisibilityStatus()
812 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
813 + CONTROLS_ADVANCED * controls->b_advancedVisible );
817 void MainInterface::visual()
819 if( !VISIBLE( visualSelector) )
821 visualSelector->show();
822 if( !THEMIM->getIM()->hasVideo() )
824 /* Show the background widget */
826 visualSelectorEnabled = true;
830 /* Stop any currently running visualization */
831 visualSelector->hide();
832 visualSelectorEnabled = false;
834 doComponentsUpdate();
838 /************************************************************************
840 ************************************************************************/
841 void MainInterface::setDisplayPosition( float pos, int time, int length )
843 char psz_length[MSTRTIME_MAX_SIZE], psz_time[MSTRTIME_MAX_SIZE];
844 secstotimestr( psz_length, length );
845 secstotimestr( psz_time, ( b_remainingTime && length ) ? length - time
849 timestr.sprintf( "%s/%s", psz_time,
850 ( !length && time ) ? "--:--" : psz_length );
852 /* Add a minus to remaining time*/
853 if( b_remainingTime && length ) timeLabel->setText( " -"+timestr+" " );
854 else timeLabel->setText( " "+timestr+" " );
857 void MainInterface::toggleTimeDisplay()
859 b_remainingTime = !b_remainingTime;
862 void MainInterface::setName( QString name )
864 input_name = name; /* store it for the QSystray use */
865 /* Display it in the status bar, but also as a Tooltip in case it doesn't
867 nameLabel->setText( " " + name + " " );
868 nameLabel->setToolTip( " " + name +" " );
871 void MainInterface::setStatus( int status )
873 /* Forward the status to the controls to toggle Play/Pause */
874 controls->setStatus( status );
875 /* And in the systray for the menu */
877 QVLCMenu::updateSystrayMenu( this, p_intf );
880 void MainInterface::setRate( int rate )
883 str.setNum( ( 1000 / (double)rate ), 'f', 2 );
885 speedLabel->setText( str );
886 speedControl->updateControls( rate );
889 void MainInterface::updateOnTimer()
891 if( intf_ShouldDie( p_intf ) )
893 QApplication::closeAllWindows();
894 QApplication::quit();
897 if( need_components_update )
899 doComponentsUpdate();
900 need_components_update = false;
905 /*****************************************************************************
906 * Systray Icon and Systray Menu
907 *****************************************************************************/
910 * Create a SystemTray icon and a menu that would go with it.
911 * Connects to a click handler on the icon.
913 void MainInterface::createSystray()
916 if( QDate::currentDate().dayOfYear() >= 354 )
917 iconVLC = QIcon( QPixmap( ":/vlc128-christmas.png" ) );
919 iconVLC = QIcon( QPixmap( ":/vlc128.png" ) );
920 sysTray = new QSystemTrayIcon( iconVLC, this );
921 sysTray->setToolTip( qtr( "VLC media player" ));
923 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
924 systrayMenu->setIcon( iconVLC );
926 QVLCMenu::updateSystrayMenu( this, p_intf, true );
929 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
930 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
934 * Updates the Systray Icon's menu and toggle the main interface
936 void MainInterface::toggleUpdateSystrayMenu()
938 /* If hidden, show it */
944 else if( isMinimized() )
954 /* check if any visible window is above vlc in the z-order,
955 * but ignore the ones always on top */
958 wi.cbSize = sizeof( WINDOWINFO );
959 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
960 hwnd && !IsWindowVisible( hwnd );
961 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
962 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
963 (wi.dwExStyle&WS_EX_TOPMOST) )
965 if( isActiveWindow() )
975 QVLCMenu::updateSystrayMenu( this, p_intf );
978 void MainInterface::handleSystrayClick(
979 QSystemTrayIcon::ActivationReason reason )
983 case QSystemTrayIcon::Trigger:
984 toggleUpdateSystrayMenu();
986 case QSystemTrayIcon::MiddleClick:
987 sysTray->showMessage( qtr( "VLC media player" ),
988 qtr( "Control menu for the player" ),
989 QSystemTrayIcon::Information, 3000 );
995 * Updates the name of the systray Icon tooltip.
996 * Doesn't check if the systray exists, check before you call it.
998 void MainInterface::updateSystrayTooltipName( QString name )
1000 if( name.isEmpty() )
1002 sysTray->setToolTip( qtr( "VLC media player" ) );
1006 sysTray->setToolTip( name );
1007 if( notificationEnabled && ( isHidden() || isMinimized() ) )
1009 sysTray->showMessage( qtr( "VLC media player" ), name,
1010 QSystemTrayIcon::NoIcon, 3000 );
1016 * Updates the status of the systray Icon tooltip.
1017 * Doesn't check if the systray exists, check before you call it.
1019 void MainInterface::updateSystrayTooltipStatus( int i_status )
1026 sysTray->setToolTip( qtr( "VLC media player" ) );
1031 sysTray->setToolTip( input_name );
1036 sysTray->setToolTip( input_name + " - "
1043 /************************************************************************
1045 ************************************************************************/
1046 void MainInterface::dropEvent(QDropEvent *event)
1048 const QMimeData *mimeData = event->mimeData();
1050 /* D&D of a subtitles file, add it on the fly */
1051 if( mimeData->urls().size() == 1 )
1053 if( THEMIM->getIM()->hasInput() )
1055 if( input_AddSubtitles( THEMIM->getInput(),
1056 qtu( mimeData->urls()[0].toString() ),
1059 event->acceptProposedAction();
1065 foreach( QUrl url, mimeData->urls() ) {
1066 QString s = url.toString();
1067 if( s.length() > 0 ) {
1068 playlist_Add( THEPL, qtu(s), NULL,
1069 PLAYLIST_APPEND | (first ? PLAYLIST_GO:0),
1070 PLAYLIST_END, VLC_TRUE, VLC_FALSE );
1074 event->acceptProposedAction();
1076 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1078 event->acceptProposedAction();
1080 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1082 event->acceptProposedAction();
1084 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1089 /************************************************************************
1091 ************************************************************************/
1092 void MainInterface::customEvent( QEvent *event )
1095 if( event->type() == PLDockEvent_Type )
1097 PlaylistDialog::killInstance();
1098 playlistEmbeddedFlag = true;
1100 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1105 if ( event->type() == SetVideoOnTopEvent_Type )
1107 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1108 if( p_event->OnTop() )
1109 setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
1111 setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint);
1112 show(); /* necessary to apply window flags?? */
1116 void MainInterface::keyPressEvent( QKeyEvent *e )
1118 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() & Qt::Key_H )
1119 && menuBar()->isHidden() )
1121 toggleMinimalView();
1125 int i_vlck = qtEventToVLCKey( e );
1128 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1135 void MainInterface::wheelEvent( QWheelEvent *e )
1137 int i_vlckey = qtWheelEventToVLCKey( e );
1138 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1142 void MainInterface::closeEvent( QCloseEvent *e )
1148 void MainInterface::toggleFullScreen( void )
1150 if( isFullScreen() )
1156 /*****************************************************************************
1158 *****************************************************************************/
1159 static int InteractCallback( vlc_object_t *p_this,
1160 const char *psz_var, vlc_value_t old_val,
1161 vlc_value_t new_val, void *param )
1163 intf_dialog_args_t *p_arg = new intf_dialog_args_t;
1164 p_arg->p_dialog = (interaction_dialog_t *)(new_val.p_address);
1165 DialogEvent *event = new DialogEvent( INTF_DIALOG_INTERACTION, 0, p_arg );
1166 QApplication::postEvent( THEDP, static_cast<QEvent*>(event) );
1170 /*****************************************************************************
1171 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1172 * We don't show the menu directly here because we don't want the
1173 * caller to block for a too long time.
1174 *****************************************************************************/
1175 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1176 vlc_value_t old_val, vlc_value_t new_val, void *param )
1178 intf_thread_t *p_intf = (intf_thread_t *)param;
1179 msg_Dbg( p_this, "Menu Requested" ); // DEBUG to track the non disparition of the menu...
1181 if( p_intf->pf_show_dialog )
1183 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1184 new_val.b_bool, 0 );
1190 /*****************************************************************************
1191 * IntfShowCB: callback triggered by the intf-show playlist variable.
1192 *****************************************************************************/
1193 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1194 vlc_value_t old_val, vlc_value_t new_val, void *param )
1196 intf_thread_t *p_intf = (intf_thread_t *)param;
1197 msg_Dbg( p_this, "Intf Show Requested" ); // DEBUG to track the non disparition of the menu...
1198 //p_intf->p_sys->b_intf_show = VLC_TRUE;