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 /* Enable the popup menu in the MI */
260 setContextMenuPolicy( Qt::CustomContextMenu );
261 CONNECT( this, customContextMenuRequested( const QPoint& ),
264 /* Final sizing and showing */
265 setMinimumWidth( __MAX( controls->sizeHint().width(),
266 menuBar()->sizeHint().width() ) );
269 /* And switch to minimal view if needed
270 Must be called after the show() */
271 if( i_visualmode == QT_MINIMAL_MODE )
272 toggleMinimalView( true );
274 /* Update the geometry : It is useful if you switch between
277 resize( sizeHint() );
279 /*****************************************************
280 * End everything by creating the Systray Management *
281 *****************************************************/
285 MainInterface::~MainInterface()
287 msg_Dbg( p_intf, "Destroying the main interface" );
289 /* Unsure we hide the videoWidget before destroying it */
290 if( videoIsActive ) videoWidget->hide();
292 /* Save playlist state */
296 QVLCTools::saveWidgetPosition( p_intf, "Playlist", playlistWidget );
298 delete playlistWidget;
301 /* Be sure to kill the actionsManager... FIXME */
302 ActionsManager::killInstance();
304 /* Delete the FSC controller */
305 if( fullscreenControls ) delete fullscreenControls;
308 settings->beginGroup( "MainWindow" );
309 settings->setValue( "pl-dock-status", (int)i_pl_dock );
310 settings->setValue( "playlist-visible", (int)playlistVisible );
311 settings->setValue( "adv-controls",
312 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
314 settings->setValue( "mainBasedSize", mainBasedSize );
315 settings->setValue( "mainVideoSize", mainVideoSize );
318 settings->setValue( "backgroundSize", bgWidget->size() );
321 QVLCTools::saveWidgetPosition(settings, this);
322 settings->endGroup();
325 /* Unregister callbacks */
326 var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
327 var_DelCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
329 interaction_Unregister( p_intf );
330 var_DelCallback( p_intf, "interaction", InteractCallback, this );
332 dialog_Unregister( p_intf );
333 var_DelCallback( p_intf, "dialog-fatal", DialogCallback, this );
335 p_intf->p_sys->p_mi = NULL;
338 /*****************************
340 *****************************/
342 inline void MainInterface::createStatusBar()
347 /* Widgets Creation*/
348 QStatusBar *statusBarr = statusBar();
350 TimeLabel *timeLabel = new TimeLabel( p_intf );
351 nameLabel = new QLabel( this );
352 nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
353 | Qt::TextSelectableByKeyboard );
354 SpeedLabel *speedLabel = new SpeedLabel( p_intf, "1.00x", this );
356 /* Styling those labels */
357 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
358 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
359 nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
361 /* and adding those */
362 statusBarr->addWidget( nameLabel, 8 );
363 statusBarr->addPermanentWidget( speedLabel, 0 );
364 statusBarr->addPermanentWidget( timeLabel, 0 );
366 /* timeLabel behaviour:
367 - double clicking opens the goto time dialog
368 - right-clicking and clicking just toggle between remaining and
370 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
372 CONNECT( THEMIM->getIM(), encryptionChanged( bool ) , this, showCryptedLabel( bool ) );
377 void MainInterface::showCryptedLabel( bool )
379 if( cryptedLabel == NULL )
381 cryptedLabel = new QLabel;
382 cryptedLabel->setPixmap( QPixmap( ":/lock" ) );
383 statusBar()->addWidget( cryptedLabel );
386 cryptedLabel->show();
390 inline void MainInterface::initSystray()
392 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
393 bool b_systrayWanted = config_GetInt( p_intf, "qt-system-tray" );
395 if( config_GetInt( p_intf, "qt-start-minimized") > 0 )
397 if( b_systrayAvailable )
399 b_systrayWanted = true;
403 msg_Err( p_intf, "cannot start minimized without system tray bar" );
406 if( b_systrayAvailable && b_systrayWanted )
411 * Give the decorations of the Main Window a correct Name.
412 * If nothing is given, set it to VLC...
414 void MainInterface::setVLCWindowsTitle( QString aTitle )
416 if( aTitle.isEmpty() )
418 setWindowTitle( qtr( "VLC media player" ) );
422 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
426 void MainInterface::handleMainUi( QSettings *settings )
428 /* Create the main Widget and the mainLayout */
429 QWidget *main = new QWidget;
430 setCentralWidget( main );
431 mainLayout = new QVBoxLayout( main );
433 /* Margins, spacing */
434 main->setContentsMargins( 0, 0, 0, 0 );
435 main->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
436 mainLayout->setSpacing( 0 );
437 mainLayout->setMargin( 0 );
439 /* Create the CONTROLS Widget */
440 controls = new ControlsWidget( p_intf,
441 settings->value( "adv-controls", false ).toBool(), this );
442 CONNECT( controls, advancedControlsToggled( bool ),
443 this, doComponentsUpdate() );
444 CONNECT( controls, sizeChanged(),
445 this, doComponentsUpdate() );
446 inputC = new InputControlsWidget( p_intf, this );
449 /* Disabled for now, they SUCK */
451 visualSelector = new VisualSelector( p_intf );
452 mainLayout->insertWidget( 0, visualSelector );
453 visualSelector->hide();
457 bgWidget = new BackgroundWidget( p_intf );
459 settings->value( "backgroundSize", QSize( 300, 200 ) ).toSize() );
460 bgWidget->updateGeometry();
461 CONNECT( this, askBgWidgetToToggle(), bgWidget, toggle() );
463 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
464 i_visualmode != QT_MINIMAL_MODE )
469 /* And video Outputs */
470 if( videoEmbeddedFlag )
471 videoWidget = new VideoWidget( p_intf );
473 /* Add the controls Widget to the main Widget */
474 mainLayout->insertWidget( 0, bgWidget );
475 if( videoWidget ) mainLayout->insertWidget( 0, videoWidget, 10 );
476 mainLayout->insertWidget( 2, inputC, 0, Qt::AlignBottom );
477 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
478 controls, 0, Qt::AlignBottom );
480 /* Finish the sizing */
481 main->updateGeometry();
483 getSettings()->endGroup();
487 /* Create the FULLSCREEN CONTROLS Widget */
488 if( config_GetInt( p_intf, "qt-fs-controller" ) )
490 fullscreenControls = new FullscreenControllerWidget( p_intf );
494 inline void MainInterface::askForPrivacy()
497 * Ask for the network policy on FIRST STARTUP
499 if( config_GetInt( p_intf, "qt-privacy-ask") )
501 QList<ConfigControl *> controls;
502 if( privacyDialog( &controls ) == QDialog::Accepted )
504 QList<ConfigControl *>::Iterator i;
505 for( i = controls.begin() ; i != controls.end() ; i++ )
507 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
508 c->doApply( p_intf );
511 config_PutInt( p_intf, "qt-privacy-ask" , 0 );
512 /* We have to save here because the user may not launch Prefs */
513 config_SaveConfigFile( p_intf, NULL );
518 int MainInterface::privacyDialog( QList<ConfigControl *> *controls )
520 QDialog *privacy = new QDialog( this );
522 privacy->setWindowTitle( qtr( "Privacy and Network Policies" ) );
524 QGridLayout *gLayout = new QGridLayout( privacy );
526 QGroupBox *blabla = new QGroupBox( qtr( "Privacy and Network Warning" ) );
527 QGridLayout *blablaLayout = new QGridLayout( blabla );
528 QLabel *text = new QLabel( qtr(
529 "<p>The <i>VideoLAN Team</i> doesn't like when an application goes "
530 "online without authorization.</p>\n "
531 "<p><i>VLC media player</i> can retreive limited information from "
532 "the Internet in order to get CD covers or to check "
533 "for available updates.</p>\n"
534 "<p><i>VLC media player</i> <b>DOES NOT</b> send or collect <b>ANY</b> "
535 "information, even anonymously, about your usage.</p>\n"
536 "<p>Therefore please select from the following options, the default being "
537 "almost no access to the web.</p>\n") );
538 text->setWordWrap( true );
539 text->setTextFormat( Qt::RichText );
541 blablaLayout->addWidget( text, 0, 0 ) ;
543 QGroupBox *options = new QGroupBox;
544 QGridLayout *optionsLayout = new QGridLayout( options );
546 gLayout->addWidget( blabla, 0, 0, 1, 3 );
547 gLayout->addWidget( options, 1, 0, 1, 3 );
548 module_config_t *p_config;
549 ConfigControl *control;
552 #define CONFIG_GENERIC( option, type ) \
553 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
556 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
557 p_config, options, false, optionsLayout, line ); \
558 controls->append( control ); \
561 #define CONFIG_GENERIC_NOBOOL( option, type ) \
562 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
565 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
566 p_config, options, optionsLayout, line ); \
567 controls->append( control ); \
570 CONFIG_GENERIC( "album-art", IntegerList ); line++;
572 CONFIG_GENERIC_NOBOOL( "qt-updates-notif", Bool ); line++;
573 CONFIG_GENERIC_NOBOOL( "qt-updates-days", Integer ); line++;
576 QPushButton *ok = new QPushButton( qtr( "OK" ) );
578 gLayout->addWidget( ok, 2, 2 );
580 CONNECT( ok, clicked(), privacy, accept() );
581 return privacy->exec();
585 /**********************************************************************
586 * Handling of sizing of the components
587 **********************************************************************/
589 /* This function is probably wrong, but we don't have many many choices...
590 Since we can't know from the playlist Widget if we are inside a dock or not,
591 because the playlist Widget can be called by THEDP, as a separate windows for
593 Maybe the other solution is to redefine the sizeHint() of the playlist and
594 ask _parent->isFloating()...
595 If you think this would be better, please FIXME it...
598 QSize MainInterface::sizeHint() const
602 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
603 i_visualmode == QT_MINIMAL_MODE )
605 return mainVideoSize;
609 if( VISIBLE( bgWidget) ||
610 ( videoIsActive && videoWidget->isVisible() )
612 return mainVideoSize;
614 return mainBasedSize;
618 int nwidth = controls->sizeHint().width();
619 int nheight = controls->isVisible() ?
620 controls->size().height()
621 + inputC->size().height()
622 + menuBar()->size().height()
623 + statusBar()->size().height()
626 if( VISIBLE( bgWidget ) )
628 nheight += bgWidget->size().height();
629 nwidth = bgWidget->size().width();
631 else if( videoIsActive && videoWidget->isVisible() )
633 nheight += videoWidget->sizeHint().height();
634 nwidth = videoWidget->sizeHint().width();
637 if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget() )
639 nheight += dockPL->size().height();
640 nwidth = __MAX( nwidth, dockPL->size().width() );
641 msg_Warn( p_intf, "3 %i %i", nheight, nwidth );
644 return QSize( nwidth, nheight );
647 void MainInterface::toggleFSC()
649 if( !fullscreenControls ) return;
651 IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
652 QApplication::postEvent( fullscreenControls, eShow );
655 void MainInterface::popupMenu()
657 QVLCMenu::PopupMenu( p_intf, true );
660 void MainInterface::debug()
663 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
664 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
665 if( videoWidget && videoWidget->isVisible() )
667 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
668 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
673 /****************************************************************************
675 ****************************************************************************/
677 /* This event is used to deal with the fullscreen and always on top
678 issue conflict (bug in wx) */
679 class SetVideoOnTopQtEvent : public QEvent
682 SetVideoOnTopQtEvent( bool _onTop ) :
683 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
686 bool OnTop() const { return onTop; }
694 * Thou shall not call/resize/hide widgets from on another thread.
695 * This is wrong, and this is THE reason to emit signals on those Video Functions
697 WId MainInterface::requestVideo( vout_thread_t *p_nvout, int *pi_x,
698 int *pi_y, unsigned int *pi_width,
699 unsigned int *pi_height )
701 /* Request the videoWidget */
702 WId ret = videoWidget->request( p_nvout,pi_x, pi_y,
703 pi_width, pi_height, b_keep_size );
704 if( ret ) /* The videoWidget is available */
706 /* Did we have a bg ? Hide it! */
707 if( VISIBLE( bgWidget) )
710 emit askBgWidgetToToggle();
713 bgWasVisible = false;
715 /* ask videoWidget to show */
716 emit askVideoToShow( *pi_width, *pi_height );
718 /* Consider the video active now */
719 videoIsActive = true;
726 /* Call from the WindowClose function */
727 void MainInterface::releaseVideo( void )
729 emit askReleaseVideo( );
732 /* Function that is CONNECTED to the previous emit */
733 void MainInterface::releaseVideoSlot( void )
735 videoWidget->release( );
739 /* Reset the bg state */
740 bgWasVisible = false;
744 videoIsActive = false;
746 /* Try to resize, except when you are in Fullscreen mode */
747 if( !isFullScreen() ) doComponentsUpdate();
750 /* Call from WindowControl function */
751 int MainInterface::controlVideo( int i_query, va_list args )
753 int i_ret = VLC_SUCCESS;
758 unsigned int i_width = va_arg( args, unsigned int );
759 unsigned int i_height = va_arg( args, unsigned int );
760 emit askVideoToResize( i_width, i_height );
764 case VOUT_SET_STAY_ON_TOP:
766 int i_arg = va_arg( args, int );
767 QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
771 i_ret = VLC_EGENERIC;
772 msg_Warn( p_intf, "unsupported control query" );
778 /*****************************************************************************
779 * Playlist, Visualisation and Menus handling
780 *****************************************************************************/
782 * Toggle the playlist widget or dialog
784 void MainInterface::togglePlaylist()
787 If no playlist exist, then create one and attach it to the DockPL*/
788 if( !playlistWidget )
790 playlistWidget = new PlaylistWidget( p_intf );
792 i_pl_dock = PL_UNDOCKED;
793 /* i_pl_dock = (pl_dock_e)getSettings()
794 ->value( "pl-dock-status", PL_UNDOCKED ).toInt(); */
796 if( i_pl_dock == PL_UNDOCKED )
798 playlistWidget->setWindowFlags( Qt::Window );
800 /* This will restore the geometry but will not work for position,
801 because of parenting */
802 QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
803 playlistWidget, QSize( 600, 300 ) );
807 mainLayout->insertWidget( 4, playlistWidget );
809 playlistVisible = true;
811 playlistWidget->show();
815 /* toggle the visibility of the playlist */
816 TOGGLEV( playlistWidget );
817 playlistVisible = !playlistVisible;
818 //doComponentsUpdate(); //resize( sizeHint() );
822 /* Function called from the menu to undock the playlist */
823 void MainInterface::undockPlaylist()
825 // dockPL->setFloating( true );
829 void MainInterface::dockPlaylist( pl_dock_e i_pos )
833 void MainInterface::toggleMinimalView( bool b_switch )
835 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
836 i_visualmode != QT_MINIMAL_MODE )
837 { /* NORMAL MODE then */
838 if( !videoWidget || videoWidget->isHidden() ) emit askBgWidgetToToggle();
841 /* If video is visible, then toggle the status of bgWidget */
842 bgWasVisible = !bgWasVisible;
846 menuBar()->setVisible( !b_switch );
847 controls->setVisible( !b_switch );
848 statusBar()->setVisible( !b_switch );
849 inputC->setVisible( !b_switch );
850 doComponentsUpdate();
852 emit minimalViewToggled( b_switch );
855 /* Video widget cannot do this synchronously as it runs in another thread */
856 /* Well, could it, actually ? Probably dangerous ... */
858 /* This function is called:
859 - toggling of minimal View
860 - through askUpdate() by Vout thread request video and resize video (zoom)
861 - Advanced buttons toggled
863 void MainInterface::doComponentsUpdate()
865 msg_Dbg( p_intf, "Updating the geometry" );
866 /* Here we resize to sizeHint() and not adjustsize because we want
867 the videoWidget to be exactly the correctSize */
868 resize( sizeHint() );
875 /* toggling advanced controls buttons */
876 void MainInterface::toggleAdvanced()
878 controls->toggleAdvanced();
879 // if( fullscreenControls ) fullscreenControls->toggleAdvanced();
882 /* Get the visibility status of the controls (hidden or not, advanced or not) */
883 int MainInterface::getControlsVisibilityStatus()
885 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
886 + CONTROLS_ADVANCED * controls->b_advancedVisible );
890 void MainInterface::visual()
892 if( !VISIBLE( visualSelector) )
894 visualSelector->show();
895 if( !THEMIM->getIM()->hasVideo() )
897 /* Show the background widget */
899 visualSelectorEnabled = true;
903 /* Stop any currently running visualization */
904 visualSelector->hide();
905 visualSelectorEnabled = false;
907 doComponentsUpdate();
911 /************************************************************************
913 ************************************************************************/
914 void MainInterface::setName( QString name )
916 input_name = name; /* store it for the QSystray use */
917 /* Display it in the status bar, but also as a Tooltip in case it doesn't
919 nameLabel->setText( " " + name + " " );
920 nameLabel->setToolTip( " " + name +" " );
923 /*****************************************************************************
924 * Systray Icon and Systray Menu
925 *****************************************************************************/
928 * Create a SystemTray icon and a menu that would go with it.
929 * Connects to a click handler on the icon.
931 void MainInterface::createSystray()
934 if( QDate::currentDate().dayOfYear() >= 354 )
935 iconVLC = QIcon( QPixmap( ":/vlc128-christmas.png" ) );
937 iconVLC = QIcon( QPixmap( ":/vlc128.png" ) );
938 sysTray = new QSystemTrayIcon( iconVLC, this );
939 sysTray->setToolTip( qtr( "VLC media player" ));
941 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
942 systrayMenu->setIcon( iconVLC );
944 QVLCMenu::updateSystrayMenu( this, p_intf, true );
947 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
948 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
952 * Updates the Systray Icon's menu and toggle the main interface
954 void MainInterface::toggleUpdateSystrayMenu()
956 /* If hidden, show it */
962 else if( isMinimized() )
970 /* Visible (possibly under other windows) */
972 /* check if any visible window is above vlc in the z-order,
973 * but ignore the ones always on top
974 * and the ones which can't be activated */
977 wi.cbSize = sizeof( WINDOWINFO );
978 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
979 hwnd && ( !IsWindowVisible( hwnd ) ||
980 ( GetWindowInfo( hwnd, &wi ) &&
981 (wi.dwExStyle&WS_EX_NOACTIVATE) ) );
982 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
983 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
984 (wi.dwExStyle&WS_EX_TOPMOST) )
996 QVLCMenu::updateSystrayMenu( this, p_intf );
999 void MainInterface::handleSystrayClick(
1000 QSystemTrayIcon::ActivationReason reason )
1004 case QSystemTrayIcon::Trigger:
1005 case QSystemTrayIcon::DoubleClick:
1006 toggleUpdateSystrayMenu();
1008 case QSystemTrayIcon::MiddleClick:
1009 sysTray->showMessage( qtr( "VLC media player" ),
1010 qtr( "Control menu for the player" ),
1011 QSystemTrayIcon::Information, 3000 );
1019 * Updates the name of the systray Icon tooltip.
1020 * Doesn't check if the systray exists, check before you call it.
1022 void MainInterface::updateSystrayTooltipName( QString name )
1024 if( name.isEmpty() )
1026 sysTray->setToolTip( qtr( "VLC media player" ) );
1030 sysTray->setToolTip( name );
1031 if( notificationEnabled && ( isHidden() || isMinimized() ) )
1033 sysTray->showMessage( qtr( "VLC media player" ), name,
1034 QSystemTrayIcon::NoIcon, 3000 );
1038 QVLCMenu::updateSystrayMenu( this, p_intf );
1042 * Updates the status of the systray Icon tooltip.
1043 * Doesn't check if the systray exists, check before you call it.
1045 void MainInterface::updateSystrayTooltipStatus( int i_status )
1052 sysTray->setToolTip( qtr( "VLC media player" ) );
1057 sysTray->setToolTip( input_name );
1062 sysTray->setToolTip( input_name + " - "
1069 /************************************************************************
1071 ************************************************************************/
1072 void MainInterface::dropEvent(QDropEvent *event)
1074 dropEventPlay( event, true );
1077 void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
1079 const QMimeData *mimeData = event->mimeData();
1081 /* D&D of a subtitles file, add it on the fly */
1082 if( mimeData->urls().size() == 1 )
1084 if( THEMIM->getIM()->hasInput() )
1086 if( !input_AddSubtitle( THEMIM->getInput(),
1087 qtu( toNativeSeparators(
1088 mimeData->urls()[0].toLocalFile() ) ),
1091 event->acceptProposedAction();
1096 bool first = b_play;
1097 foreach( const QUrl &url, mimeData->urls() )
1099 QString s = toNativeSeparators( url.toLocalFile() );
1101 if( s.length() > 0 ) {
1102 playlist_Add( THEPL, qtu(s), NULL,
1103 PLAYLIST_APPEND | (first ? PLAYLIST_GO: 0),
1104 PLAYLIST_END, true, false );
1106 RecentsMRL::getInstance( p_intf )->addRecent( s );
1109 event->acceptProposedAction();
1111 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1113 event->acceptProposedAction();
1115 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1117 event->acceptProposedAction();
1119 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1124 /************************************************************************
1126 ************************************************************************/
1127 void MainInterface::customEvent( QEvent *event )
1130 if( event->type() == PLDockEvent_Type )
1132 PlaylistDialog::killInstance();
1133 playlistEmbeddedFlag = true;
1135 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1140 if ( event->type() == (int)SetVideoOnTopEvent_Type )
1142 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1143 if( p_event->OnTop() )
1144 setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
1146 setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint);
1147 show(); /* necessary to apply window flags?? */
1151 void MainInterface::keyPressEvent( QKeyEvent *e )
1153 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() == Qt::Key_H )
1154 && !menuBar()->isVisible() )
1156 toggleMinimalView( false );
1160 int i_vlck = qtEventToVLCKey( e );
1163 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1170 void MainInterface::resizeEvent( QResizeEvent * event )
1174 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
1175 i_visualmode == QT_MINIMAL_MODE )
1177 mainVideoSize = size();
1181 if( VISIBLE( bgWidget) ||
1182 ( videoIsActive && videoWidget->isVisible() )
1184 mainVideoSize = size();
1186 mainBasedSize = size();
1191 void MainInterface::wheelEvent( QWheelEvent *e )
1193 int i_vlckey = qtWheelEventToVLCKey( e );
1194 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1198 void MainInterface::closeEvent( QCloseEvent *e )
1205 void MainInterface::toggleFullScreen( void )
1207 if( isFullScreen() )
1210 emit askUpdate(); // Needed if video was launched after the F11
1211 emit fullscreenInterfaceToggled( false );
1216 emit fullscreenInterfaceToggled( true );
1221 /*****************************************************************************
1223 *****************************************************************************/
1224 static int InteractCallback( vlc_object_t *p_this,
1225 const char *psz_var, vlc_value_t old_val,
1226 vlc_value_t new_val, void *param )
1228 intf_dialog_args_t *p_arg = new intf_dialog_args_t;
1229 p_arg->p_dialog = (interaction_dialog_t *)(new_val.p_address);
1230 DialogEvent *event = new DialogEvent( INTF_DIALOG_INTERACTION, 0, p_arg );
1231 QApplication::postEvent( THEDP, event );
1235 static int DialogCallback( vlc_object_t *p_this,
1236 const char *type, vlc_value_t previous,
1237 vlc_value_t value, void *data )
1239 MainInterface *self = (MainInterface *)data;
1240 const dialog_fatal_t *dialog = (const dialog_fatal_t *)value.p_address;
1242 if (!strcmp (type, "dialog-fatal"))
1243 printf ("ERROR: %s\n %s\n", dialog->title, dialog->message);
1250 /*****************************************************************************
1251 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1252 * We don't show the menu directly here because we don't want the
1253 * caller to block for a too long time.
1254 *****************************************************************************/
1255 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1256 vlc_value_t old_val, vlc_value_t new_val, void *param )
1258 intf_thread_t *p_intf = (intf_thread_t *)param;
1260 if( p_intf->pf_show_dialog )
1262 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1263 new_val.b_bool, NULL );
1269 /*****************************************************************************
1270 * IntfShowCB: callback triggered by the intf-show libvlc variable.
1271 *****************************************************************************/
1272 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1273 vlc_value_t old_val, vlc_value_t new_val, void *param )
1275 intf_thread_t *p_intf = (intf_thread_t *)param;
1276 p_intf->p_sys->p_mi->toggleFSC();