1 /*****************************************************************************
2 * main_interface.cpp : Main interface
3 ****************************************************************************
4 * Copyright (C) 2006-2008 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 *****************************************************************************/
32 #include "main_interface.hpp"
33 #include "input_manager.hpp"
34 #include "actions_manager.hpp"
36 #include "util/customwidgets.hpp"
37 #include "util/qt_dirs.hpp"
39 #include "components/interface_widgets.hpp"
40 #include "components/controller.hpp"
41 #include "components/playlist/playlist.hpp"
44 #include "recents.hpp"
46 #include <QCloseEvent>
58 #include <QPushButton>
62 #include <vlc_keys.h> /* Wheel event */
64 #include <vlc_dialog.h>
66 /* Callback prototypes */
67 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
68 vlc_value_t old_val, vlc_value_t new_val, void *param );
69 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
70 vlc_value_t old_val, vlc_value_t new_val, void *param );
71 static int InteractCallback( vlc_object_t *, const char *, vlc_value_t,
73 static int DialogCallback( vlc_object_t *, const char *,
74 vlc_value_t, vlc_value_t, void *);
76 MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
78 /* Variables initialisation */
79 // need_components_update = false;
82 playlistWidget = NULL;
84 videoIsActive = false;
85 playlistVisible = false;
87 fullscreenControls = NULL;
96 * Configuration and settings
97 * Pre-building of interface
100 setFocusPolicy( Qt::StrongFocus );
101 setAcceptDrops( true );
102 setWindowIcon( QApplication::windowIcon() );
103 setWindowOpacity( config_GetFloat( p_intf, "qt-opacity" ) );
105 /* Set The Video In emebedded Mode or not */
106 videoEmbeddedFlag = config_GetInt( p_intf, "embedded-video" );
108 /* Does the interface resize to video size or the opposite */
109 b_keep_size = !config_GetInt( p_intf, "qt-video-autoresize" );
111 /* Are we in the enhanced always-video mode or not ? */
112 i_visualmode = config_GetInt( p_intf, "qt-display-mode" );
114 /* Set the other interface settings */
115 settings = getSettings();
116 settings->beginGroup( "MainWindow" );
119 * Retrieve saved sizes for main window
120 * mainBasedSize = based window size for normal mode
121 * (no video, no background)
122 * mainVideoSize = window size with video (all modes)
124 mainBasedSize = settings->value( "mainBasedSize", QSize( 350, 120 ) ).toSize();
125 mainVideoSize = settings->value( "mainVideoSize", QSize( 400, 300 ) ).toSize();
127 /* Do we want anoying popups or not */
128 notificationEnabled = (bool)config_GetInt( p_intf, "qt-notification" );
135 /**************************
136 * UI and Widgets design
137 **************************/
138 setVLCWindowsTitle();
139 handleMainUi( settings );
144 QVLCMenu::createMenuBar( this, p_intf );
147 /* Create a Dock to get the playlist */
148 dockPL = new QDockWidget( qtr( "Playlist" ), this );
149 dockPL->setSizePolicy( QSizePolicy::Preferred,
150 QSizePolicy::Expanding );
151 dockPL->setFeatures( QDockWidget::AllDockWidgetFeatures );
152 dockPL->setAllowedAreas( Qt::LeftDockWidgetArea
153 | Qt::RightDockWidgetArea
154 | Qt::BottomDockWidgetArea );
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 */
169 * Connects on nameChanged()
170 * Those connects are not merged because different options can trigger
173 /* Naming in the controller statusbar */
174 CONNECT( THEMIM->getIM(), nameChanged( QString ),
175 this, setName( QString ) );
176 /* and in the systray */
179 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
180 updateSystrayTooltipName( QString ) );
182 /* and in the title of the controller */
183 if( config_GetInt( p_intf, "qt-name-in-title" ) )
185 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
186 setVLCWindowsTitle( QString ) );
190 * CONNECTS on PLAY_STATUS
192 /* Status on the systray */
195 CONNECT( THEMIM->getIM(), statusChanged( int ),
196 this, updateSystrayTooltipStatus( int ) );
199 /* END CONNECTS ON IM */
205 var_Create( p_intf, "interaction", VLC_VAR_ADDRESS );
206 var_AddCallback( p_intf, "interaction", InteractCallback, this );
207 interaction_Register( p_intf );
209 var_Create( p_intf, "dialog-fatal", VLC_VAR_ADDRESS );
210 var_AddCallback( p_intf, "dialog-fatal", DialogCallback, this );
211 dialog_Register( p_intf );
213 var_AddCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
215 /* Register callback for the intf-popupmenu variable */
216 var_AddCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
219 /* VideoWidget connects to avoid different threads speaking to each other */
220 connect( this, SIGNAL(askReleaseVideo( void )),
221 this, SLOT(releaseVideoSlot( void )), Qt::BlockingQueuedConnection );
225 CONNECT( this, askVideoToResize( unsigned int, unsigned int ),
226 videoWidget, SetSizing( unsigned int, unsigned int ) );
228 connect( this, SIGNAL(askVideoToShow( unsigned int, unsigned int)),
229 videoWidget, SLOT(SetSizing(unsigned int, unsigned int )),
230 Qt::BlockingQueuedConnection );
233 CONNECT( this, askUpdate(), this, doComponentsUpdate() );
235 /* Size and placement of interface */
236 settings->beginGroup( "MainWindow" );
237 QVLCTools::restoreWidgetPosition( settings, this, QSize(380, 60) );
239 /* resize to previously saved main window size if appicable */
242 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
243 i_visualmode == QT_MINIMAL_MODE )
245 resize( mainVideoSize );
249 resize( mainBasedSize );
253 bool b_visible = settings->value( "playlist-visible", 0 ).toInt();
254 settings->endGroup();
257 if( b_visible ) togglePlaylist();
259 /* Final sizing and showing */
260 setMinimumWidth( __MAX( controls->sizeHint().width(),
261 menuBar()->sizeHint().width() ) );
264 /* And switch to minimal view if needed
265 Must be called after the show() */
266 if( i_visualmode == QT_MINIMAL_MODE )
267 toggleMinimalView( true );
269 /* Update the geometry : It is useful if you switch between
272 resize( sizeHint() );
274 /*****************************************************
275 * End everything by creating the Systray Management *
276 *****************************************************/
280 MainInterface::~MainInterface()
282 msg_Dbg( p_intf, "Destroying the main interface" );
284 /* Unsure we hide the videoWidget before destroying it */
285 if( videoIsActive ) videoWidget->hide();
287 /* Save playlist state */
291 QVLCTools::saveWidgetPosition( p_intf, "Playlist", playlistWidget );
293 delete playlistWidget;
296 /* Be sure to kill the actionsManager... FIXME */
297 ActionsManager::killInstance();
299 /* Delete the FSC controller */
300 if( fullscreenControls ) delete fullscreenControls;
303 settings->beginGroup( "MainWindow" );
304 settings->setValue( "pl-dock-status", (int)i_pl_dock );
305 settings->setValue( "playlist-visible", (int)playlistVisible );
306 settings->setValue( "adv-controls",
307 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
309 settings->setValue( "mainBasedSize", mainBasedSize );
310 settings->setValue( "mainVideoSize", mainVideoSize );
313 settings->setValue( "backgroundSize", bgWidget->size() );
316 QVLCTools::saveWidgetPosition(settings, this);
317 settings->endGroup();
320 /* Unregister callbacks */
321 var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
322 var_DelCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
324 interaction_Unregister( p_intf );
325 var_DelCallback( p_intf, "interaction", InteractCallback, this );
327 dialog_Unregister( p_intf );
328 var_DelCallback( p_intf, "dialog-fatal", DialogCallback, this );
330 p_intf->p_sys->p_mi = NULL;
333 /*****************************
335 *****************************/
337 inline void MainInterface::createStatusBar()
342 /* Widgets Creation*/
343 QStatusBar *statusBarr = statusBar();
345 TimeLabel *timeLabel = new TimeLabel( p_intf );
346 nameLabel = new QLabel( this );
347 nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
348 | Qt::TextSelectableByKeyboard );
349 SpeedLabel *speedLabel = new SpeedLabel( p_intf, "1.00x", this );
351 /* Styling those labels */
352 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
353 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
354 nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
356 /* and adding those */
357 statusBarr->addWidget( nameLabel, 8 );
358 statusBarr->addPermanentWidget( speedLabel, 0 );
359 statusBarr->addPermanentWidget( timeLabel, 0 );
361 /* timeLabel behaviour:
362 - double clicking opens the goto time dialog
363 - right-clicking and clicking just toggle between remaining and
365 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
367 CONNECT( THEMIM->getIM(), encryptionChanged( bool ) , this, showCryptedLabel( bool ) );
372 void MainInterface::showCryptedLabel( bool )
374 if( cryptedLabel == NULL )
376 cryptedLabel = new QLabel;
377 cryptedLabel->setPixmap( QPixmap( ":/lock" ) );
378 statusBar()->addWidget( cryptedLabel );
381 cryptedLabel->show();
385 inline void MainInterface::initSystray()
387 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
388 bool b_systrayWanted = config_GetInt( p_intf, "qt-system-tray" );
390 if( config_GetInt( p_intf, "qt-start-minimized") > 0 )
392 if( b_systrayAvailable )
394 b_systrayWanted = true;
398 msg_Err( p_intf, "cannot start minimized without system tray bar" );
401 if( b_systrayAvailable && b_systrayWanted )
406 * Give the decorations of the Main Window a correct Name.
407 * If nothing is given, set it to VLC...
409 void MainInterface::setVLCWindowsTitle( QString aTitle )
411 if( aTitle.isEmpty() )
413 setWindowTitle( qtr( "VLC media player" ) );
417 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
421 void MainInterface::handleMainUi( QSettings *settings )
423 /* Create the main Widget and the mainLayout */
424 QWidget *main = new QWidget;
425 setCentralWidget( main );
426 mainLayout = new QVBoxLayout( main );
428 /* Margins, spacing */
429 main->setContentsMargins( 0, 0, 0, 0 );
430 main->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
431 mainLayout->setSpacing( 0 );
432 mainLayout->setMargin( 0 );
434 /* Create the CONTROLS Widget */
435 controls = new ControlsWidget( p_intf,
436 settings->value( "adv-controls", false ).toBool(), this );
437 CONNECT( controls, advancedControlsToggled( bool ),
438 this, doComponentsUpdate() );
439 CONNECT( controls, sizeChanged(),
440 this, doComponentsUpdate() );
441 inputC = new InputControlsWidget( p_intf, this );
444 /* Disabled for now, they SUCK */
446 visualSelector = new VisualSelector( p_intf );
447 mainLayout->insertWidget( 0, visualSelector );
448 visualSelector->hide();
452 bgWidget = new BackgroundWidget( p_intf );
454 settings->value( "backgroundSize", QSize( 300, 200 ) ).toSize() );
455 bgWidget->updateGeometry();
456 CONNECT( this, askBgWidgetToToggle(), bgWidget, toggle() );
458 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
459 i_visualmode != QT_MINIMAL_MODE )
464 /* And video Outputs */
465 if( videoEmbeddedFlag )
466 videoWidget = new VideoWidget( p_intf );
468 /* Add the controls Widget to the main Widget */
469 mainLayout->insertWidget( 0, bgWidget );
470 if( videoWidget ) mainLayout->insertWidget( 0, videoWidget, 10 );
471 mainLayout->insertWidget( 2, inputC, 0, Qt::AlignBottom );
472 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
473 controls, 0, Qt::AlignBottom );
475 /* Finish the sizing */
476 main->updateGeometry();
478 getSettings()->endGroup();
482 /* Create the FULLSCREEN CONTROLS Widget */
483 if( config_GetInt( p_intf, "qt-fs-controller" ) )
485 fullscreenControls = new FullscreenControllerWidget( p_intf );
489 inline void MainInterface::askForPrivacy()
492 * Ask for the network policy on FIRST STARTUP
494 if( config_GetInt( p_intf, "qt-privacy-ask") )
496 QList<ConfigControl *> controls;
497 if( privacyDialog( &controls ) == QDialog::Accepted )
499 QList<ConfigControl *>::Iterator i;
500 for( i = controls.begin() ; i != controls.end() ; i++ )
502 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
503 c->doApply( p_intf );
506 config_PutInt( p_intf, "qt-privacy-ask" , 0 );
507 /* We have to save here because the user may not launch Prefs */
508 config_SaveConfigFile( p_intf, NULL );
513 int MainInterface::privacyDialog( QList<ConfigControl *> *controls )
515 QDialog *privacy = new QDialog( this );
517 privacy->setWindowTitle( qtr( "Privacy and Network Policies" ) );
519 QGridLayout *gLayout = new QGridLayout( privacy );
521 QGroupBox *blabla = new QGroupBox( qtr( "Privacy and Network Warning" ) );
522 QGridLayout *blablaLayout = new QGridLayout( blabla );
523 QLabel *text = new QLabel( qtr(
524 "<p>The <i>VideoLAN Team</i> doesn't like when an application goes "
525 "online without authorization.</p>\n "
526 "<p><i>VLC media player</i> can retreive limited information from "
527 "the Internet in order to get CD covers or to check "
528 "for available updates.</p>\n"
529 "<p><i>VLC media player</i> <b>DOES NOT</b> send or collect <b>ANY</b> "
530 "information, even anonymously, about your usage.</p>\n"
531 "<p>Therefore please select from the following options, the default being "
532 "almost no access to the web.</p>\n") );
533 text->setWordWrap( true );
534 text->setTextFormat( Qt::RichText );
536 blablaLayout->addWidget( text, 0, 0 ) ;
538 QGroupBox *options = new QGroupBox;
539 QGridLayout *optionsLayout = new QGridLayout( options );
541 gLayout->addWidget( blabla, 0, 0, 1, 3 );
542 gLayout->addWidget( options, 1, 0, 1, 3 );
543 module_config_t *p_config;
544 ConfigControl *control;
547 #define CONFIG_GENERIC( option, type ) \
548 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
551 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
552 p_config, options, false, optionsLayout, line ); \
553 controls->append( control ); \
556 #define CONFIG_GENERIC_NOBOOL( option, type ) \
557 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
560 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
561 p_config, options, optionsLayout, line ); \
562 controls->append( control ); \
565 CONFIG_GENERIC( "album-art", IntegerList ); line++;
567 CONFIG_GENERIC_NOBOOL( "qt-updates-notif", Bool ); line++;
568 CONFIG_GENERIC_NOBOOL( "qt-updates-days", Integer ); line++;
571 QPushButton *ok = new QPushButton( qtr( "OK" ) );
573 gLayout->addWidget( ok, 2, 2 );
575 CONNECT( ok, clicked(), privacy, accept() );
576 return privacy->exec();
580 /**********************************************************************
581 * Handling of sizing of the components
582 **********************************************************************/
584 /* This function is probably wrong, but we don't have many many choices...
585 Since we can't know from the playlist Widget if we are inside a dock or not,
586 because the playlist Widget can be called by THEDP, as a separate windows for
588 Maybe the other solution is to redefine the sizeHint() of the playlist and
589 ask _parent->isFloating()...
590 If you think this would be better, please FIXME it...
593 QSize MainInterface::sizeHint() const
597 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
598 i_visualmode == QT_MINIMAL_MODE )
600 return mainVideoSize;
604 if( VISIBLE( bgWidget) ||
605 ( videoIsActive && videoWidget->isVisible() )
607 return mainVideoSize;
609 return mainBasedSize;
613 int nwidth = controls->sizeHint().width();
614 int nheight = controls->isVisible() ?
615 controls->size().height()
616 + inputC->size().height()
617 + menuBar()->size().height()
618 + statusBar()->size().height()
621 if( VISIBLE( bgWidget ) )
623 nheight += bgWidget->size().height();
624 nwidth = bgWidget->size().width();
626 else if( videoIsActive && videoWidget->isVisible() )
628 nheight += videoWidget->sizeHint().height();
629 nwidth = videoWidget->sizeHint().width();
632 if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget() )
634 nheight += dockPL->size().height();
635 nwidth = __MAX( nwidth, dockPL->size().width() );
636 msg_Warn( p_intf, "3 %i %i", nheight, nwidth );
639 return QSize( nwidth, nheight );
642 void MainInterface::toggleFSC()
644 if( !fullscreenControls ) return;
646 IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
647 QApplication::postEvent( fullscreenControls, eShow );
650 void MainInterface::debug()
653 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
654 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
655 if( videoWidget && videoWidget->isVisible() )
657 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
658 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
663 /****************************************************************************
665 ****************************************************************************/
667 /* This event is used to deal with the fullscreen and always on top
668 issue conflict (bug in wx) */
669 class SetVideoOnTopQtEvent : public QEvent
672 SetVideoOnTopQtEvent( bool _onTop ) :
673 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
676 bool OnTop() const { return onTop; }
684 * Thou shall not call/resize/hide widgets from on another thread.
685 * This is wrong, and this is THE reason to emit signals on those Video Functions
687 WId MainInterface::requestVideo( vout_thread_t *p_nvout, int *pi_x,
688 int *pi_y, unsigned int *pi_width,
689 unsigned int *pi_height )
691 /* Request the videoWidget */
692 WId ret = videoWidget->request( p_nvout,pi_x, pi_y,
693 pi_width, pi_height, b_keep_size );
694 if( ret ) /* The videoWidget is available */
696 /* Did we have a bg ? Hide it! */
697 if( VISIBLE( bgWidget) )
700 emit askBgWidgetToToggle();
703 bgWasVisible = false;
705 /* ask videoWidget to show */
706 emit askVideoToShow( *pi_width, *pi_height );
708 /* Consider the video active now */
709 videoIsActive = true;
716 /* Call from the WindowClose function */
717 void MainInterface::releaseVideo( void )
719 emit askReleaseVideo( );
722 /* Function that is CONNECTED to the previous emit */
723 void MainInterface::releaseVideoSlot( void )
725 videoWidget->release( );
729 /* Reset the bg state */
730 bgWasVisible = false;
734 videoIsActive = false;
736 /* Try to resize, except when you are in Fullscreen mode */
737 if( !isFullScreen() ) doComponentsUpdate();
740 /* Call from WindowControl function */
741 int MainInterface::controlVideo( int i_query, va_list args )
743 int i_ret = VLC_SUCCESS;
748 unsigned int i_width = va_arg( args, unsigned int );
749 unsigned int i_height = va_arg( args, unsigned int );
750 emit askVideoToResize( i_width, i_height );
754 case VOUT_SET_STAY_ON_TOP:
756 int i_arg = va_arg( args, int );
757 QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
761 i_ret = VLC_EGENERIC;
762 msg_Warn( p_intf, "unsupported control query" );
768 /*****************************************************************************
769 * Playlist, Visualisation and Menus handling
770 *****************************************************************************/
772 * Toggle the playlist widget or dialog
774 void MainInterface::togglePlaylist()
777 If no playlist exist, then create one and attach it to the DockPL*/
778 if( !playlistWidget )
780 playlistWidget = new PlaylistWidget( p_intf );
782 i_pl_dock = PL_UNDOCKED;
783 /* i_pl_dock = (pl_dock_e)getSettings()
784 ->value( "pl-dock-status", PL_UNDOCKED ).toInt(); */
786 if( i_pl_dock == PL_UNDOCKED )
788 playlistWidget->setWindowFlags( Qt::Window );
790 /* This will restore the geometry but will not work for position,
791 because of parenting */
792 QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
793 playlistWidget, QSize( 600, 300 ) );
797 mainLayout->insertWidget( 4, playlistWidget );
799 playlistVisible = true;
801 playlistWidget->show();
805 /* toggle the visibility of the playlist */
806 TOGGLEV( playlistWidget );
807 playlistVisible = !playlistVisible;
808 //doComponentsUpdate(); //resize( sizeHint() );
812 /* Function called from the menu to undock the playlist */
813 void MainInterface::undockPlaylist()
815 // dockPL->setFloating( true );
819 void MainInterface::dockPlaylist( pl_dock_e i_pos )
823 void MainInterface::toggleMinimalView( bool b_switch )
825 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
826 i_visualmode != QT_MINIMAL_MODE )
827 { /* NORMAL MODE then */
828 if( !videoWidget || videoWidget->isHidden() ) emit askBgWidgetToToggle();
831 /* If video is visible, then toggle the status of bgWidget */
832 bgWasVisible = !bgWasVisible;
836 menuBar()->setVisible( !b_switch );
837 controls->setVisible( !b_switch );
838 statusBar()->setVisible( !b_switch );
839 inputC->setVisible( !b_switch );
840 doComponentsUpdate();
842 emit minimalViewToggled( b_switch );
845 /* Video widget cannot do this synchronously as it runs in another thread */
846 /* Well, could it, actually ? Probably dangerous ... */
848 /* This function is called:
849 - toggling of minimal View
850 - through askUpdate() by Vout thread request video and resize video (zoom)
851 - Advanced buttons toggled
853 void MainInterface::doComponentsUpdate()
855 msg_Dbg( p_intf, "Updating the geometry" );
856 /* Here we resize to sizeHint() and not adjustsize because we want
857 the videoWidget to be exactly the correctSize */
858 resize( sizeHint() );
865 /* toggling advanced controls buttons */
866 void MainInterface::toggleAdvanced()
868 controls->toggleAdvanced();
869 // if( fullscreenControls ) fullscreenControls->toggleAdvanced();
872 /* Get the visibility status of the controls (hidden or not, advanced or not) */
873 int MainInterface::getControlsVisibilityStatus()
875 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
876 + CONTROLS_ADVANCED * controls->b_advancedVisible );
880 void MainInterface::visual()
882 if( !VISIBLE( visualSelector) )
884 visualSelector->show();
885 if( !THEMIM->getIM()->hasVideo() )
887 /* Show the background widget */
889 visualSelectorEnabled = true;
893 /* Stop any currently running visualization */
894 visualSelector->hide();
895 visualSelectorEnabled = false;
897 doComponentsUpdate();
901 /************************************************************************
903 ************************************************************************/
904 void MainInterface::setName( QString name )
906 input_name = name; /* store it for the QSystray use */
907 /* Display it in the status bar, but also as a Tooltip in case it doesn't
909 nameLabel->setText( " " + name + " " );
910 nameLabel->setToolTip( " " + name +" " );
913 /*****************************************************************************
914 * Systray Icon and Systray Menu
915 *****************************************************************************/
918 * Create a SystemTray icon and a menu that would go with it.
919 * Connects to a click handler on the icon.
921 void MainInterface::createSystray()
924 if( QDate::currentDate().dayOfYear() >= 354 )
925 iconVLC = QIcon( QPixmap( ":/vlc128-christmas.png" ) );
927 iconVLC = QIcon( QPixmap( ":/vlc128.png" ) );
928 sysTray = new QSystemTrayIcon( iconVLC, this );
929 sysTray->setToolTip( qtr( "VLC media player" ));
931 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
932 systrayMenu->setIcon( iconVLC );
934 QVLCMenu::updateSystrayMenu( this, p_intf, true );
937 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
938 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
942 * Updates the Systray Icon's menu and toggle the main interface
944 void MainInterface::toggleUpdateSystrayMenu()
946 /* If hidden, show it */
952 else if( isMinimized() )
960 /* Visible (possibly under other windows) */
962 /* check if any visible window is above vlc in the z-order,
963 * but ignore the ones always on top
964 * and the ones which can't be activated */
967 wi.cbSize = sizeof( WINDOWINFO );
968 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
969 hwnd && ( !IsWindowVisible( hwnd ) ||
970 ( GetWindowInfo( hwnd, &wi ) &&
971 (wi.dwExStyle&WS_EX_NOACTIVATE) ) );
972 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
973 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
974 (wi.dwExStyle&WS_EX_TOPMOST) )
986 QVLCMenu::updateSystrayMenu( this, p_intf );
989 void MainInterface::handleSystrayClick(
990 QSystemTrayIcon::ActivationReason reason )
994 case QSystemTrayIcon::Trigger:
995 case QSystemTrayIcon::DoubleClick:
996 toggleUpdateSystrayMenu();
998 case QSystemTrayIcon::MiddleClick:
999 sysTray->showMessage( qtr( "VLC media player" ),
1000 qtr( "Control menu for the player" ),
1001 QSystemTrayIcon::Information, 3000 );
1009 * Updates the name of the systray Icon tooltip.
1010 * Doesn't check if the systray exists, check before you call it.
1012 void MainInterface::updateSystrayTooltipName( QString name )
1014 if( name.isEmpty() )
1016 sysTray->setToolTip( qtr( "VLC media player" ) );
1020 sysTray->setToolTip( name );
1021 if( notificationEnabled && ( isHidden() || isMinimized() ) )
1023 sysTray->showMessage( qtr( "VLC media player" ), name,
1024 QSystemTrayIcon::NoIcon, 3000 );
1028 QVLCMenu::updateSystrayMenu( this, p_intf );
1032 * Updates the status of the systray Icon tooltip.
1033 * Doesn't check if the systray exists, check before you call it.
1035 void MainInterface::updateSystrayTooltipStatus( int i_status )
1042 sysTray->setToolTip( qtr( "VLC media player" ) );
1047 sysTray->setToolTip( input_name );
1052 sysTray->setToolTip( input_name + " - "
1059 /************************************************************************
1061 ************************************************************************/
1062 void MainInterface::dropEvent(QDropEvent *event)
1064 dropEventPlay( event, true );
1067 void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
1069 const QMimeData *mimeData = event->mimeData();
1071 /* D&D of a subtitles file, add it on the fly */
1072 if( mimeData->urls().size() == 1 )
1074 if( THEMIM->getIM()->hasInput() )
1076 if( !input_AddSubtitle( THEMIM->getInput(),
1077 qtu( toNativeSeparators(
1078 mimeData->urls()[0].toLocalFile() ) ),
1081 event->acceptProposedAction();
1086 bool first = b_play;
1087 foreach( const QUrl &url, mimeData->urls() )
1089 QString s = toNativeSeparators( url.toLocalFile() );
1091 if( s.length() > 0 ) {
1092 playlist_Add( THEPL, qtu(s), NULL,
1093 PLAYLIST_APPEND | (first ? PLAYLIST_GO: 0),
1094 PLAYLIST_END, true, false );
1096 RecentsMRL::getInstance( p_intf )->addRecent( s );
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() == (int)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()->isVisible() )
1146 toggleMinimalView( false );
1150 int i_vlck = qtEventToVLCKey( e );
1153 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1160 void MainInterface::resizeEvent( QResizeEvent * event )
1164 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
1165 i_visualmode == QT_MINIMAL_MODE )
1167 mainVideoSize = size();
1171 if( VISIBLE( bgWidget) ||
1172 ( videoIsActive && videoWidget->isVisible() )
1174 mainVideoSize = size();
1176 mainBasedSize = size();
1181 void MainInterface::wheelEvent( QWheelEvent *e )
1183 int i_vlckey = qtWheelEventToVLCKey( e );
1184 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1188 void MainInterface::closeEvent( QCloseEvent *e )
1195 void MainInterface::toggleFullScreen( void )
1197 if( isFullScreen() )
1200 emit askUpdate(); // Needed if video was launched after the F11
1201 emit fullscreenInterfaceToggled( false );
1206 emit fullscreenInterfaceToggled( true );
1211 /*****************************************************************************
1213 *****************************************************************************/
1214 static int InteractCallback( vlc_object_t *p_this,
1215 const char *psz_var, vlc_value_t old_val,
1216 vlc_value_t new_val, void *param )
1218 intf_dialog_args_t *p_arg = new intf_dialog_args_t;
1219 p_arg->p_dialog = (interaction_dialog_t *)(new_val.p_address);
1220 DialogEvent *event = new DialogEvent( INTF_DIALOG_INTERACTION, 0, p_arg );
1221 QApplication::postEvent( THEDP, event );
1225 static int DialogCallback( vlc_object_t *p_this,
1226 const char *type, vlc_value_t previous,
1227 vlc_value_t value, void *data )
1229 MainInterface *self = (MainInterface *)data;
1230 const dialog_fatal_t *dialog = (const dialog_fatal_t *)value.p_address;
1232 if (!strcmp (type, "dialog-fatal"))
1233 printf ("ERROR: %s\n %s\n", dialog->title, dialog->message);
1240 /*****************************************************************************
1241 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1242 * We don't show the menu directly here because we don't want the
1243 * caller to block for a too long time.
1244 *****************************************************************************/
1245 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1246 vlc_value_t old_val, vlc_value_t new_val, void *param )
1248 intf_thread_t *p_intf = (intf_thread_t *)param;
1250 if( p_intf->pf_show_dialog )
1252 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1253 new_val.b_bool, NULL );
1259 /*****************************************************************************
1260 * IntfShowCB: callback triggered by the intf-show libvlc variable.
1261 *****************************************************************************/
1262 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1263 vlc_value_t old_val, vlc_value_t new_val, void *param )
1265 intf_thread_t *p_intf = (intf_thread_t *)param;
1266 p_intf->p_sys->p_mi->toggleFSC();