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;
98 playlistWidget = NULL;
100 videoIsActive = false;
101 playlistVisible = false;
104 /* Ask for privacy */
108 * Configuration and settings
109 * Pre-building of interface
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 settings = new QSettings( "vlc", "vlc-qt-interface" );
125 settings->beginGroup( "MainWindow" );
127 //TODO: I don't like that code
128 visualSelectorEnabled = settings->value( "visual-selector", false ).toBool();
129 notificationEnabled = (bool)config_GetInt( p_intf, "qt-notification" );
131 /**************************
132 * UI and Widgets design
133 **************************/
134 setVLCWindowsTitle();
135 handleMainUi( settings );
138 /* Create a Dock to get the playlist */
139 /* dockPL = new QDockWidget( qtr( "Playlist" ), this );
140 dockPL->setSizePolicy( QSizePolicy::Preferred,
141 QSizePolicy::Expanding );
142 dockPL->setFeatures( QDockWidget::AllDockWidgetFeatures );
143 dockPL->setAllowedAreas( Qt::LeftDockWidgetArea
144 | Qt::RightDockWidgetArea
145 | Qt::BottomDockWidgetArea );
152 QVLCMenu::createMenuBar( this, p_intf, visualSelectorEnabled );
154 /* StatusBar Creation */
158 /********************
160 ********************/
161 MainInputManager::getInstance( p_intf );
163 /**************************
164 * Various CONNECTs on IM *
165 **************************/
166 /* Connect the input manager to the GUI elements it manages */
168 /* It is also connected to the control->slider, see the ControlsWidget */
169 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
170 this, setDisplayPosition( float, int, int ) );
171 /* Change the SpeedRate in the Status */
172 CONNECT( THEMIM->getIM(), rateChanged( int ), this, setRate( int ) );
175 * Connects on nameChanged()
176 * Those connects are not merged because different options can trigger
179 /* Naming in the controller statusbar */
180 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
181 setName( QString ) );
182 /* and in the systray */
185 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
186 updateSystrayTooltipName( QString ) );
188 /* and in the title of the controller */
189 if( config_GetInt( p_intf, "qt-name-in-title" ) )
191 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
192 setVLCWindowsTitle( QString ) );
196 * CONNECTS on PLAY_STATUS
198 /* Status on the main controller */
199 CONNECT( THEMIM->getIM(), statusChanged( int ), this, setStatus( int ) );
200 /* and in the systray */
203 CONNECT( THEMIM->getIM(), statusChanged( int ), this,
204 updateSystrayTooltipStatus( int ) );
207 /* END CONNECTS ON IM */
211 /* TODO Remove this function, but so far, there is no choice because there
212 is no intf-should-die variable */
213 ON_TIMEOUT( updateOnTimer() );
214 //ON_TIMEOUT( debug() );
219 var_Create( p_intf, "interaction", VLC_VAR_ADDRESS );
220 var_AddCallback( p_intf, "interaction", InteractCallback, this );
221 p_intf->b_interaction = VLC_TRUE;
223 /* Register callback for the intf-popupmenu variable */
224 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
225 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
226 if( p_playlist != NULL )
228 var_AddCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
229 var_AddCallback( p_playlist, "intf-show", IntfShowCB, p_intf );
230 vlc_object_release( p_playlist );
233 /* VideoWidget connect mess to avoid different threads speaking to each other */
234 CONNECT( this, askReleaseVideo( void * ),
235 this, releaseVideoSlot( void * ) );
236 CONNECT( this, askVideoToResize( unsigned int, unsigned int ),
237 videoWidget, SetSizing( unsigned int, unsigned int ) );
239 CONNECT( this, askUpdate(), this, doComponentsUpdate() );
241 CONNECT( controls, advancedControlsToggled( bool ),
242 this, doComponentsUpdate() );
244 /* Size and placement of interface */
245 move( settings->value( "pos", QPoint( 0, 0 ) ).toPoint() );
247 QSize newSize = settings->value( "size", QSize( 350, 60 ) ).toSize();
248 if( newSize.isValid() )
251 msg_Warn( p_intf, "Invalid size in constructor" );
254 if( settings->value( "playlist-visible", 0 ).toInt() ) togglePlaylist();
255 settings->endGroup();
259 if( i_visualmode == QT_MINIMAL_MODE )
262 /* Update the geometry TODO: is it useful ?*/
265 /*****************************************************
266 * End everything by creating the Systray Management *
267 *****************************************************/
271 MainInterface::~MainInterface()
273 msg_Dbg( p_intf, "Destroying the main interface" );
275 if( playlistWidget ) playlistWidget->savingSettings( settings );
276 if( ExtendedDialog::exists() )
277 ExtendedDialog::getInstance( p_intf )->savingSettings();
279 settings->beginGroup( "MainWindow" );
280 // settings->setValue( "playlist-floats", (int)(dockPL->isFloating()) );
281 settings->setValue( "playlist-visible", (int)playlistVisible );
282 settings->setValue( "adv-controls",
283 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
284 settings->setValue( "pos", pos() );
285 settings->setValue( "size", size() );
287 settings->setValue( "backgroundSize", bgWidget->size() );
289 settings->endGroup();
292 /* Unregister callback for the intf-popupmenu variable */
293 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
294 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
295 if( p_playlist != NULL )
297 var_DelCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
298 var_DelCallback( p_playlist, "intf-show", IntfShowCB, p_intf );
299 vlc_object_release( p_playlist );
302 p_intf->b_interaction = VLC_FALSE;
303 var_DelCallback( p_intf, "interaction", InteractCallback, this );
305 p_intf->pf_request_window = NULL;
306 p_intf->pf_release_window = NULL;
307 p_intf->pf_control_window = NULL;
308 p_intf->p_sys->p_mi = NULL;
311 /*****************************
313 *****************************/
315 inline void MainInterface::createStatusBar()
320 /* Widgets Creation*/
321 b_remainingTime = false;
322 timeLabel = new TimeLabel;
323 timeLabel->setText( " --:--/--:-- " );
324 timeLabel->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
325 nameLabel = new QLabel;
326 nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
327 | Qt::TextSelectableByKeyboard );
328 speedLabel = new QLabel( "1.00x" );
329 speedLabel->setContextMenuPolicy ( Qt::CustomContextMenu );
331 /* Styling those labels */
332 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
333 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
334 nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
336 pgBar = new QProgressBar;
339 /* and adding those */
340 statusBar()->addWidget( nameLabel, 8 );
341 statusBar()->addPermanentWidget( speedLabel, 0 );
342 statusBar()->addPermanentWidget( pgBar, 0 );
343 statusBar()->addPermanentWidget( timeLabel, 0 );
345 /* timeLabel behaviour:
346 - double clicking opens the goto time dialog
347 - right-clicking and clicking just toggle between remaining and
349 CONNECT( timeLabel, timeLabelClicked(), this, toggleTimeDisplay() );
350 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
351 CONNECT( timeLabel, timeLabelDoubleClicked(), this, toggleTimeDisplay() );
353 /* Speed Label behaviour:
354 - right click gives the vertical speed slider */
355 CONNECT( speedLabel, customContextMenuRequested( QPoint ),
356 this, showSpeedMenu( QPoint ) );
359 inline void MainInterface::initSystray()
361 bool b_createSystray = false;
362 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
363 if( config_GetInt( p_intf, "qt-start-minimized") )
365 if( b_systrayAvailable )
367 b_createSystray = true;
370 else msg_Err( p_intf, "You can't minimize if you haven't a system "
373 if( config_GetInt( p_intf, "qt-system-tray") )
374 b_createSystray = true;
376 if( b_systrayAvailable && b_createSystray )
381 * Give the decorations of the Main Window a correct Name.
382 * If nothing is given, set it to VLC...
384 void MainInterface::setVLCWindowsTitle( QString aTitle )
386 if( aTitle.isEmpty() )
388 setWindowTitle( qtr( "VLC media player" ) );
392 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
396 void MainInterface::handleMainUi( QSettings *settings )
398 /* Create the main Widget and the mainLayout */
399 QWidget *main = new QWidget;
400 setCentralWidget( main );
401 mainLayout = new QVBoxLayout( main );
403 /* Margins, spacing */
404 main->setContentsMargins( 0, 0, 0, 0 );
405 main->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
406 mainLayout->setMargin( 0 );
408 /* Create the CONTROLS Widget */
409 /* bool b_shiny = config_GetInt( p_intf, "qt-blingbling" ); */
410 controls = new ControlsWidget( p_intf, this,
411 settings->value( "adv-controls", false ).toBool(),
412 config_GetInt( p_intf, "qt-blingbling" ) );
414 /* Add the controls Widget to the main Widget */
415 mainLayout->insertWidget( 0, controls );
417 /* Create the Speed Control Widget */
418 speedControl = new SpeedControlWidget( p_intf );
419 speedControlMenu = new QMenu( this );
421 QWidgetAction *widgetAction = new QWidgetAction( speedControl );
422 widgetAction->setDefaultWidget( speedControl );
423 speedControlMenu->addAction( widgetAction );
426 /* Disabled for now, they SUCK */
428 visualSelector = new VisualSelector( p_intf );
429 mainLayout->insertWidget( 0, visualSelector );
430 visualSelector->hide();
433 /* And video Outputs */
434 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
435 i_visualmode == QT_MINIMAL_MODE )
437 bgWidget = new BackgroundWidget( p_intf );
439 settings->value( "backgroundSize", QSize( 300, 150 ) ).toSize() );
440 bgWidget->updateGeometry();
441 mainLayout->insertWidget( 0, bgWidget );
442 CONNECT( this, askBgWidgetToToggle(), bgWidget, toggle() );
445 if( videoEmbeddedFlag )
447 videoWidget = new VideoWidget( p_intf );
448 mainLayout->insertWidget( 0, videoWidget );
450 p_intf->pf_request_window = ::DoRequest;
451 p_intf->pf_release_window = ::DoRelease;
452 p_intf->pf_control_window = ::DoControl;
455 /* Finish the sizing */
456 main->updateGeometry();
459 inline void MainInterface::askForPrivacy()
462 * Ask for the network policy on FIRST STARTUP
464 if( config_GetInt( p_intf, "qt-privacy-ask") )
466 QList<ConfigControl *> controls;
467 if( privacyDialog( controls ) == QDialog::Accepted )
469 QList<ConfigControl *>::Iterator i;
470 for( i = controls.begin() ; i != controls.end() ; i++ )
472 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
473 c->doApply( p_intf );
476 config_PutInt( p_intf, "qt-privacy-ask" , 0 );
477 /* We have to save here because the user may not launch Prefs */
478 config_SaveConfigFile( p_intf, NULL );
483 int MainInterface::privacyDialog( QList<ConfigControl *> controls )
485 QDialog *privacy = new QDialog( this );
487 privacy->setWindowTitle( qtr( "Privacy and Network policies" ) );
489 QGridLayout *gLayout = new QGridLayout( privacy );
491 QGroupBox *blabla = new QGroupBox( qtr( "Privacy and Network Warning" ) );
492 QGridLayout *blablaLayout = new QGridLayout( blabla );
493 QLabel *text = new QLabel( qtr(
494 "<p>The <i>VideoLAN Team</i> doesn't like when an application goes "
495 "online without authorization.</p>\n "
496 "<p><i>VLC media player</i> can request limited information on "
497 "the Internet, especially to get CD covers and songs metadata or to know "
498 "if updates are available.</p>\n"
499 "<p><i>VLC media player</i> <b>DOES NOT</b> send or collect <b>ANY</b> "
500 "information, even anonymously, about your usage.</p>\n"
501 "<p>Therefore please check the following options, the default being "
502 "almost no access on the web.</p>\n") );
503 text->setWordWrap( true );
504 text->setTextFormat( Qt::RichText );
506 blablaLayout->addWidget( text, 0, 0 ) ;
508 QGroupBox *options = new QGroupBox;
509 QGridLayout *optionsLayout = new QGridLayout( options );
511 gLayout->addWidget( blabla, 0, 0, 1, 3 );
512 gLayout->addWidget( options, 1, 0, 1, 3 );
513 module_config_t *p_config;
514 ConfigControl *control;
517 #define CONFIG_GENERIC( option, type ) \
518 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
521 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
522 p_config, options, false, optionsLayout, line ); \
523 controls.append( control ); \
526 #define CONFIG_GENERIC_NOBOOL( option, type ) \
527 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
530 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
531 p_config, options, optionsLayout, line ); \
532 controls.append( control ); \
535 CONFIG_GENERIC( "album-art", IntegerList ); line++;
536 CONFIG_GENERIC_NOBOOL( "fetch-meta", Bool ); line++;
538 CONFIG_GENERIC_NOBOOL( "qt-updates-notif", Bool ); line++;
539 CONFIG_GENERIC_NOBOOL( "qt-updates-days", Integer ); line++;
541 QPushButton *ok = new QPushButton( qtr( "Ok" ) );
543 gLayout->addWidget( ok, 2, 2 );
545 CONNECT( ok, clicked(), privacy, accept() );
546 return privacy->exec();
550 /**********************************************************************
551 * Handling of sizing of the components
552 **********************************************************************/
554 /* This function is probably wrong, but we don't have many many choices...
555 Since we can't know from the playlist Widget if we are inside a dock or not,
556 because the playlist Widget can be called by THEDP, as a separate windows for
558 Maybe the other solution is to redefine the sizeHint() of the playlist and
559 ask _parent->isFloating()...
560 If you think this would be better, please FIXME it...
563 QSize MainInterface::sizeHint() const
565 int nwidth = controls->sizeHint().width();
566 int nheight = controls->isVisible() ?
567 controls->size().height()
568 + menuBar()->size().height()
569 + statusBar()->size().height()
572 msg_Dbg( p_intf, "1 %i %i", nheight, nwidth );
573 if( VISIBLE( bgWidget ) )
575 nheight += bgWidget->size().height();
576 nwidth = bgWidget->size().width();
577 msg_Dbg( p_intf, "1b %i %i", nheight, nwidth );
579 else if( videoIsActive )
581 nheight += videoWidget->size().height();
582 nwidth = videoWidget->size().width();
583 msg_Dbg( p_intf, "2 %i %i", nheight, nwidth );
585 /* if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget() )
587 nheight += dockPL->size().height();
588 nwidth = __MAX( nwidth, dockPL->size().width() );
589 msg_Dbg( p_intf, "3 %i %i", nheight, nwidth );
591 msg_Dbg( p_intf, "4 %i %i", nheight, nwidth );
592 return QSize( nwidth, nheight );
596 /* FIXME This is dead code and need to be removed AT THE END */
597 void MainInterface::resizeEvent( QResizeEvent *e )
600 videoWidget->widgetSize.setWidth( e->size().width() - addSize.width() );
601 if( videoWidget && videoIsActive && videoWidget->widgetSize.height() > 1 )
603 SET_WH( videoWidget, e->size().width() - addSize.width(),
604 e->size().height() - addSize.height() );
605 videoWidget->updateGeometry();
607 if( VISIBLE( playlistWidget ) )
609 // SET_WH( playlistWidget , e->size().width() - addSize.width(),
610 // e->size().height() - addSize.height() );
611 playlistWidget->updateGeometry();
616 void MainInterface::requestLayoutUpdate()
621 //FIXME remove me at the end...
622 void MainInterface::debug()
624 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
625 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
626 if( videoWidget->isVisible() )
629 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
630 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
635 /****************************************************************************
636 * Small right-click menu for rate control
637 ****************************************************************************/
638 void MainInterface::showSpeedMenu( QPoint pos )
640 speedControlMenu->exec( QCursor::pos() - pos
641 + QPoint( 0, speedLabel->height() ) );
644 /****************************************************************************
646 ****************************************************************************/
647 class SetVideoOnTopQtEvent : public QEvent
650 SetVideoOnTopQtEvent( bool _onTop ) :
651 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
666 * Thou shall not call/resize/hide widgets from on another thread.
667 * This is wrong, and this is TEH reason to emit signals on those Video Functions
669 /* function called from ::DoRequest in order to show a nice VideoWidget
671 void *MainInterface::requestVideo( vout_thread_t *p_nvout, int *pi_x,
672 int *pi_y, unsigned int *pi_width,
673 unsigned int *pi_height )
675 bool bgWasVisible = false;
677 /* Request the videoWidget */
678 void *ret = videoWidget->request( p_nvout,pi_x, pi_y, pi_width, pi_height );
679 if( ret ) /* The videoWidget is available */
681 /* Did we have a bg ? Hide it! */
682 if( VISIBLE( bgWidget) )
685 emit askBgWidgetToToggle();
688 /*if( THEMIM->getIM()->hasVideo() || !bgWasVisible )
690 videoWidget->widgetSize = QSize( *pi_width, *pi_height );
692 else /* Background widget available, use its size */
694 /* Ok, our visualizations are bad, so don't do this for the moment
695 * use the requested size anyway */
696 // videoWidget->widgetSize = bgWidget->widgeTSize;
697 /* videoWidget->widgetSize = QSize( *pi_width, *pi_height );
700 videoIsActive = true;
702 emit askVideoToResize( *pi_width, *pi_height );
708 void MainInterface::releaseVideo( void *p_win )
710 emit askReleaseVideo( p_win );
713 void MainInterface::releaseVideoSlot( void *p_win )
715 videoWidget->release( p_win );
718 if( bgWidget )// WORONG
722 videoIsActive = false;
725 int MainInterface::controlVideo( void *p_window, int i_query, va_list args )
727 int i_ret = VLC_SUCCESS;
732 unsigned int *pi_width = va_arg( args, unsigned int * );
733 unsigned int *pi_height = va_arg( args, unsigned int * );
734 *pi_width = videoWidget->videoSize.width();
735 *pi_height = videoWidget->videoSize.height();
740 unsigned int i_width = va_arg( args, unsigned int );
741 unsigned int i_height = va_arg( args, unsigned int );
742 emit askVideoToResize( i_width, i_height );
746 case VOUT_SET_STAY_ON_TOP:
748 int i_arg = va_arg( args, int );
749 QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
753 i_ret = VLC_EGENERIC;
754 msg_Warn( p_intf, "unsupported control query" );
760 /*****************************************************************************
761 * Playlist, Visualisation and Menus handling
762 *****************************************************************************/
764 * Toggle the playlist widget or dialog
766 void MainInterface::togglePlaylist()
768 THEDP->playlistDialog();
771 If no playlist exist, then create one and attach it to the DockPL*/
772 if( !playlistWidget )
774 playlistWidget = new PlaylistWidget( p_intf, settings, dockPL );
776 /* Add it to the parent DockWidget */
777 dockPL->setWidget( playlistWidget );
779 /* Add the dock to the main Interface */
780 addDockWidget( Qt::BottomDockWidgetArea, dockPL );
782 /* Make the playlist floating is requested. Default is not. */
783 settings->beginGroup( "MainWindow" );
784 if( settings->value( "playlist-floats", 1 ).toInt() )
786 msg_Dbg( p_intf, "we don't want the playlist inside");
787 dockPL->setFloating( true );
789 settings->endGroup();
790 settings->beginGroup( "playlist" );
791 dockPL->move( settings->value( "pos", QPoint( 0,0 ) ).toPoint() );
792 QSize newSize = settings->value( "size", QSize( 400, 300 ) ).toSize();
793 if( newSize.isValid() )
794 dockPL->resize( newSize );
795 settings->endGroup();
798 playlistVisible = true;
802 /* toggle the visibility of the playlist */
804 resize( sizeHint() );
805 playlistVisible = !playlistVisible;
810 /* Function called from the menu to undock the playlist */
811 void MainInterface::undockPlaylist()
813 // dockPL->setFloating( true );
817 void MainInterface::toggleMinimalView()
819 TOGGLEV( menuBar() );
821 TOGGLEV( statusBar() );
822 doComponentsUpdate();
825 /* Video widget cannot do this synchronously as it runs in another thread */
826 /* Well, could it, actually ? Probably dangerous ... */
827 void MainInterface::doComponentsUpdate()
829 msg_Dbg( p_intf, "Updating the geometry" );
830 // resize( sizeHint() );
834 /* toggling advanced controls buttons */
835 void MainInterface::toggleAdvanced()
837 controls->toggleAdvanced();
840 /* Get the visibility status of the controls (hidden or not, advanced or not) */
841 int MainInterface::getControlsVisibilityStatus()
843 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
844 + CONTROLS_ADVANCED * controls->b_advancedVisible );
848 void MainInterface::visual()
850 if( !VISIBLE( visualSelector) )
852 visualSelector->show();
853 if( !THEMIM->getIM()->hasVideo() )
855 /* Show the background widget */
857 visualSelectorEnabled = true;
861 /* Stop any currently running visualization */
862 visualSelector->hide();
863 visualSelectorEnabled = false;
865 doComponentsUpdate();
869 /************************************************************************
871 ************************************************************************/
872 void MainInterface::setDisplayPosition( float pos, int time, int length )
874 char psz_length[MSTRTIME_MAX_SIZE], psz_time[MSTRTIME_MAX_SIZE];
875 secstotimestr( psz_length, length );
876 secstotimestr( psz_time, ( b_remainingTime && length ) ? length - time
880 timestr.sprintf( "%s/%s", psz_time,
881 ( !length && time ) ? "--:--" : psz_length );
883 /* Add a minus to remaining time*/
884 if( b_remainingTime && length ) timeLabel->setText( " -"+timestr+" " );
885 else timeLabel->setText( " "+timestr+" " );
888 void MainInterface::toggleTimeDisplay()
890 b_remainingTime = !b_remainingTime;
893 void MainInterface::setName( QString name )
895 input_name = name; /* store it for the QSystray use */
896 /* Display it in the status bar, but also as a Tooltip in case it doesn't
898 nameLabel->setText( " " + name + " " );
899 nameLabel->setToolTip( " " + name +" " );
902 void MainInterface::setStatus( int status )
904 /* Forward the status to the controls to toggle Play/Pause */
905 controls->setStatus( status );
906 /* And in the systray for the menu */
908 QVLCMenu::updateSystrayMenu( this, p_intf );
911 void MainInterface::setRate( int rate )
914 str.setNum( ( 1000 / (double)rate ), 'f', 2 );
916 speedLabel->setText( str );
917 speedControl->updateControls( rate );
920 void MainInterface::updateOnTimer()
922 /* No event for dying */
923 if( intf_ShouldDie( p_intf ) )
925 QApplication::closeAllWindows();
926 QApplication::quit();
930 /*****************************************************************************
931 * Systray Icon and Systray Menu
932 *****************************************************************************/
935 * Create a SystemTray icon and a menu that would go with it.
936 * Connects to a click handler on the icon.
938 void MainInterface::createSystray()
941 if( QDate::currentDate().dayOfYear() >= 354 )
942 iconVLC = QIcon( QPixmap( ":/vlc128-christmas.png" ) );
944 iconVLC = QIcon( QPixmap( ":/vlc128.png" ) );
945 sysTray = new QSystemTrayIcon( iconVLC, this );
946 sysTray->setToolTip( qtr( "VLC media player" ));
948 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
949 systrayMenu->setIcon( iconVLC );
951 QVLCMenu::updateSystrayMenu( this, p_intf, true );
954 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
955 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
959 * Updates the Systray Icon's menu and toggle the main interface
961 void MainInterface::toggleUpdateSystrayMenu()
963 /* If hidden, show it */
969 else if( isMinimized() )
979 /* check if any visible window is above vlc in the z-order,
980 * but ignore the ones always on top */
983 wi.cbSize = sizeof( WINDOWINFO );
984 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
985 hwnd && !IsWindowVisible( hwnd );
986 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
987 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
988 (wi.dwExStyle&WS_EX_TOPMOST) )
990 if( isActiveWindow() )
1000 QVLCMenu::updateSystrayMenu( this, p_intf );
1003 void MainInterface::handleSystrayClick(
1004 QSystemTrayIcon::ActivationReason reason )
1008 case QSystemTrayIcon::Trigger:
1009 toggleUpdateSystrayMenu();
1011 case QSystemTrayIcon::MiddleClick:
1012 sysTray->showMessage( qtr( "VLC media player" ),
1013 qtr( "Control menu for the player" ),
1014 QSystemTrayIcon::Information, 3000 );
1020 * Updates the name of the systray Icon tooltip.
1021 * Doesn't check if the systray exists, check before you call it.
1023 void MainInterface::updateSystrayTooltipName( QString name )
1025 if( name.isEmpty() )
1027 sysTray->setToolTip( qtr( "VLC media player" ) );
1031 sysTray->setToolTip( name );
1032 if( notificationEnabled && ( isHidden() || isMinimized() ) )
1034 sysTray->showMessage( qtr( "VLC media player" ), name,
1035 QSystemTrayIcon::NoIcon, 3000 );
1041 * Updates the status of the systray Icon tooltip.
1042 * Doesn't check if the systray exists, check before you call it.
1044 void MainInterface::updateSystrayTooltipStatus( int i_status )
1051 sysTray->setToolTip( qtr( "VLC media player" ) );
1056 sysTray->setToolTip( input_name );
1061 sysTray->setToolTip( input_name + " - "
1068 /************************************************************************
1070 ************************************************************************/
1071 void MainInterface::dropEvent(QDropEvent *event)
1073 const QMimeData *mimeData = event->mimeData();
1075 /* D&D of a subtitles file, add it on the fly */
1076 if( mimeData->urls().size() == 1 )
1078 if( THEMIM->getIM()->hasInput() )
1080 if( input_AddSubtitles( THEMIM->getInput(),
1081 qtu( mimeData->urls()[0].toString() ),
1084 event->acceptProposedAction();
1090 foreach( QUrl url, mimeData->urls() ) {
1091 QString s = url.toString();
1092 if( s.length() > 0 ) {
1093 playlist_Add( THEPL, qtu(s), NULL,
1094 PLAYLIST_APPEND | (first ? PLAYLIST_GO:0),
1095 PLAYLIST_END, VLC_TRUE, VLC_FALSE );
1099 event->acceptProposedAction();
1101 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1103 event->acceptProposedAction();
1105 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1107 event->acceptProposedAction();
1109 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1114 /************************************************************************
1116 ************************************************************************/
1117 void MainInterface::customEvent( QEvent *event )
1120 if( event->type() == PLDockEvent_Type )
1122 PlaylistDialog::killInstance();
1123 playlistEmbeddedFlag = true;
1125 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1130 if ( event->type() == SetVideoOnTopEvent_Type )
1132 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1133 if( p_event->OnTop() )
1134 setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
1136 setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint);
1137 show(); /* necessary to apply window flags?? */
1141 void MainInterface::keyPressEvent( QKeyEvent *e )
1143 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() & Qt::Key_H )
1144 && menuBar()->isHidden() )
1146 toggleMinimalView();
1150 int i_vlck = qtEventToVLCKey( e );
1153 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1160 void MainInterface::wheelEvent( QWheelEvent *e )
1162 int i_vlckey = qtWheelEventToVLCKey( e );
1163 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1167 void MainInterface::closeEvent( QCloseEvent *e )
1173 void MainInterface::toggleFullScreen( void )
1175 if( isFullScreen() )
1181 /*****************************************************************************
1183 *****************************************************************************/
1184 static int InteractCallback( vlc_object_t *p_this,
1185 const char *psz_var, vlc_value_t old_val,
1186 vlc_value_t new_val, void *param )
1188 intf_dialog_args_t *p_arg = new intf_dialog_args_t;
1189 p_arg->p_dialog = (interaction_dialog_t *)(new_val.p_address);
1190 DialogEvent *event = new DialogEvent( INTF_DIALOG_INTERACTION, 0, p_arg );
1191 QApplication::postEvent( THEDP, static_cast<QEvent*>(event) );
1195 /*****************************************************************************
1196 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1197 * We don't show the menu directly here because we don't want the
1198 * caller to block for a too long time.
1199 *****************************************************************************/
1200 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1201 vlc_value_t old_val, vlc_value_t new_val, void *param )
1203 intf_thread_t *p_intf = (intf_thread_t *)param;
1204 msg_Dbg( p_this, "Menu Requested" ); // DEBUG to track the non disparition of the menu...
1206 if( p_intf->pf_show_dialog )
1208 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1209 new_val.b_bool, 0 );
1215 /*****************************************************************************
1216 * IntfShowCB: callback triggered by the intf-show playlist variable.
1217 *****************************************************************************/
1218 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1219 vlc_value_t old_val, vlc_value_t new_val, void *param )
1221 intf_thread_t *p_intf = (intf_thread_t *)param;
1222 msg_Dbg( p_this, "Intf Show Requested" ); // DEBUG to track the non disparition of the menu...
1223 p_intf->p_sys->p_mi->requestLayoutUpdate();