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 */
65 /* Callback prototypes */
66 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
67 vlc_value_t old_val, vlc_value_t new_val, void *param );
68 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
69 vlc_value_t old_val, vlc_value_t new_val, void *param );
70 static int InteractCallback( vlc_object_t *, const char *, vlc_value_t,
73 MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
75 /* Variables initialisation */
76 // need_components_update = false;
79 playlistWidget = NULL;
81 videoIsActive = false;
82 playlistVisible = false;
84 fullscreenControls = NULL;
93 * Configuration and settings
94 * Pre-building of interface
97 setFocusPolicy( Qt::StrongFocus );
98 setAcceptDrops( true );
99 setWindowIcon( QApplication::windowIcon() );
100 setWindowOpacity( config_GetFloat( p_intf, "qt-opacity" ) );
102 /* Set The Video In emebedded Mode or not */
103 videoEmbeddedFlag = config_GetInt( p_intf, "embedded-video" );
105 /* Does the interface resize to video size or the opposite */
106 b_keep_size = !config_GetInt( p_intf, "qt-video-autoresize" );
108 /* Are we in the enhanced always-video mode or not ? */
109 i_visualmode = config_GetInt( p_intf, "qt-display-mode" );
111 /* Set the other interface settings */
112 settings = getSettings();
113 settings->beginGroup( "MainWindow" );
116 * Retrieve saved sizes for main window
117 * mainBasedSize = based window size for normal mode
118 * (no video, no background)
119 * mainVideoSize = window size with video (all modes)
121 mainBasedSize = settings->value( "mainBasedSize", QSize( 350, 120 ) ).toSize();
122 mainVideoSize = settings->value( "mainVideoSize", QSize( 400, 300 ) ).toSize();
124 /* Do we want anoying popups or not */
125 notificationEnabled = (bool)config_GetInt( p_intf, "qt-notification" );
132 /**************************
133 * UI and Widgets design
134 **************************/
135 setVLCWindowsTitle();
136 handleMainUi( settings );
141 QVLCMenu::createMenuBar( this, p_intf );
144 /* Create a Dock to get the playlist */
145 dockPL = new QDockWidget( qtr( "Playlist" ), this );
146 dockPL->setSizePolicy( QSizePolicy::Preferred,
147 QSizePolicy::Expanding );
148 dockPL->setFeatures( QDockWidget::AllDockWidgetFeatures );
149 dockPL->setAllowedAreas( Qt::LeftDockWidgetArea
150 | Qt::RightDockWidgetArea
151 | Qt::BottomDockWidgetArea );
155 /********************
157 ********************/
158 MainInputManager::getInstance( p_intf );
160 /**************************
161 * Various CONNECTs on IM *
162 **************************/
163 /* Connect the input manager to the GUI elements it manages */
166 * Connects on nameChanged()
167 * Those connects are not merged because different options can trigger
170 /* Naming in the controller statusbar */
171 CONNECT( THEMIM->getIM(), nameChanged( QString ),
172 this, setName( QString ) );
173 /* and in the systray */
176 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
177 updateSystrayTooltipName( QString ) );
179 /* and in the title of the controller */
180 if( config_GetInt( p_intf, "qt-name-in-title" ) )
182 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
183 setVLCWindowsTitle( QString ) );
187 * CONNECTS on PLAY_STATUS
189 /* Status on the systray */
192 CONNECT( THEMIM->getIM(), statusChanged( int ),
193 this, updateSystrayTooltipStatus( int ) );
196 /* END CONNECTS ON IM */
202 var_Create( p_intf, "interaction", VLC_VAR_ADDRESS );
203 var_AddCallback( p_intf, "interaction", InteractCallback, this );
204 interaction_Register( p_intf );
206 var_AddCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
208 /* Register callback for the intf-popupmenu variable */
209 var_AddCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
212 /* VideoWidget connects to avoid different threads speaking to each other */
213 connect( this, SIGNAL(askReleaseVideo( void )),
214 this, SLOT(releaseVideoSlot( void )), Qt::BlockingQueuedConnection );
218 CONNECT( this, askVideoToResize( unsigned int, unsigned int ),
219 videoWidget, SetSizing( unsigned int, unsigned int ) );
221 connect( this, SIGNAL(askVideoToShow( unsigned int, unsigned int)),
222 videoWidget, SLOT(SetSizing(unsigned int, unsigned int )),
223 Qt::BlockingQueuedConnection );
226 CONNECT( this, askUpdate(), this, doComponentsUpdate() );
228 /* Size and placement of interface */
229 settings->beginGroup( "MainWindow" );
230 QVLCTools::restoreWidgetPosition( settings, this, QSize(380, 60) );
232 /* resize to previously saved main window size if appicable */
235 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
236 i_visualmode == QT_MINIMAL_MODE )
238 resize( mainVideoSize );
242 resize( mainBasedSize );
246 bool b_visible = settings->value( "playlist-visible", 0 ).toInt();
247 settings->endGroup();
250 if( b_visible ) togglePlaylist();
252 /* Final sizing and showing */
253 setMinimumWidth( __MAX( controls->sizeHint().width(),
254 menuBar()->sizeHint().width() ) );
257 /* And switch to minimal view if needed
258 Must be called after the show() */
259 if( i_visualmode == QT_MINIMAL_MODE )
260 toggleMinimalView( true );
262 /* Update the geometry : It is useful if you switch between
265 resize( sizeHint() );
267 /*****************************************************
268 * End everything by creating the Systray Management *
269 *****************************************************/
273 MainInterface::~MainInterface()
275 msg_Dbg( p_intf, "Destroying the main interface" );
277 /* Unsure we hide the videoWidget before destroying it */
278 if( videoIsActive ) videoWidget->hide();
280 /* Save playlist state */
284 QVLCTools::saveWidgetPosition( p_intf, "Playlist", playlistWidget );
286 delete playlistWidget;
289 /* Be sure to kill the actionsManager... FIXME */
290 ActionsManager::killInstance();
292 /* Delete the FSC controller */
293 if( fullscreenControls ) delete fullscreenControls;
296 settings->beginGroup( "MainWindow" );
297 settings->setValue( "pl-dock-status", (int)i_pl_dock );
298 settings->setValue( "playlist-visible", (int)playlistVisible );
299 settings->setValue( "adv-controls",
300 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
302 settings->setValue( "mainBasedSize", mainBasedSize );
303 settings->setValue( "mainVideoSize", mainVideoSize );
306 settings->setValue( "backgroundSize", bgWidget->size() );
309 QVLCTools::saveWidgetPosition(settings, this);
310 settings->endGroup();
313 /* Unregister callbacks */
314 var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
315 var_DelCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
317 interaction_Unregister( p_intf );
318 var_DelCallback( p_intf, "interaction", InteractCallback, this );
320 p_intf->p_sys->p_mi = NULL;
323 /*****************************
325 *****************************/
327 inline void MainInterface::createStatusBar()
332 /* Widgets Creation*/
333 QStatusBar *statusBarr = statusBar();
335 TimeLabel *timeLabel = new TimeLabel( p_intf );
336 nameLabel = new QLabel( this );
337 nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
338 | Qt::TextSelectableByKeyboard );
339 SpeedLabel *speedLabel = new SpeedLabel( p_intf, "1.00x", this );
341 /* Styling those labels */
342 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
343 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
344 nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
346 /* and adding those */
347 statusBarr->addWidget( nameLabel, 8 );
348 statusBarr->addPermanentWidget( speedLabel, 0 );
349 statusBarr->addPermanentWidget( timeLabel, 0 );
351 /* timeLabel behaviour:
352 - double clicking opens the goto time dialog
353 - right-clicking and clicking just toggle between remaining and
355 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
357 CONNECT( THEMIM->getIM(), encryptionChanged( bool ) , this, showCryptedLabel( bool ) );
362 void MainInterface::showCryptedLabel( bool )
364 if( cryptedLabel == NULL )
366 cryptedLabel = new QLabel;
367 cryptedLabel->setPixmap( QPixmap( ":/lock" ) );
368 statusBar()->addWidget( cryptedLabel );
371 cryptedLabel->show();
375 inline void MainInterface::initSystray()
377 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
378 bool b_systrayWanted = config_GetInt( p_intf, "qt-system-tray" );
380 if( config_GetInt( p_intf, "qt-start-minimized") > 0 )
382 if( b_systrayAvailable )
384 b_systrayWanted = true;
388 msg_Err( p_intf, "cannot start minimized without system tray bar" );
391 if( b_systrayAvailable && b_systrayWanted )
396 * Give the decorations of the Main Window a correct Name.
397 * If nothing is given, set it to VLC...
399 void MainInterface::setVLCWindowsTitle( QString aTitle )
401 if( aTitle.isEmpty() )
403 setWindowTitle( qtr( "VLC media player" ) );
407 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
411 void MainInterface::handleMainUi( QSettings *settings )
413 /* Create the main Widget and the mainLayout */
414 QWidget *main = new QWidget;
415 setCentralWidget( main );
416 mainLayout = new QVBoxLayout( main );
418 /* Margins, spacing */
419 main->setContentsMargins( 0, 0, 0, 0 );
420 main->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
421 mainLayout->setSpacing( 0 );
422 mainLayout->setMargin( 0 );
424 /* Create the CONTROLS Widget */
425 controls = new ControlsWidget( p_intf,
426 settings->value( "adv-controls", false ).toBool(), this );
427 CONNECT( controls, advancedControlsToggled( bool ),
428 this, doComponentsUpdate() );
429 inputC = new InputControlsWidget( p_intf, this );
432 /* Disabled for now, they SUCK */
434 visualSelector = new VisualSelector( p_intf );
435 mainLayout->insertWidget( 0, visualSelector );
436 visualSelector->hide();
440 bgWidget = new BackgroundWidget( p_intf );
442 settings->value( "backgroundSize", QSize( 300, 200 ) ).toSize() );
443 bgWidget->updateGeometry();
444 CONNECT( this, askBgWidgetToToggle(), bgWidget, toggle() );
446 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
447 i_visualmode != QT_MINIMAL_MODE )
452 /* And video Outputs */
453 if( videoEmbeddedFlag )
454 videoWidget = new VideoWidget( p_intf );
456 /* Add the controls Widget to the main Widget */
457 mainLayout->insertWidget( 0, bgWidget );
458 if( videoWidget ) mainLayout->insertWidget( 0, videoWidget, 10 );
459 mainLayout->insertWidget( 2, inputC, 0, Qt::AlignBottom );
460 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
461 controls, 0, Qt::AlignBottom );
463 /* Finish the sizing */
464 main->updateGeometry();
466 getSettings()->endGroup();
470 /* Create the FULLSCREEN CONTROLS Widget */
471 if( config_GetInt( p_intf, "qt-fs-controller" ) )
473 fullscreenControls = new FullscreenControllerWidget( p_intf );
477 inline void MainInterface::askForPrivacy()
480 * Ask for the network policy on FIRST STARTUP
482 if( config_GetInt( p_intf, "qt-privacy-ask") )
484 QList<ConfigControl *> controls;
485 if( privacyDialog( &controls ) == QDialog::Accepted )
487 QList<ConfigControl *>::Iterator i;
488 for( i = controls.begin() ; i != controls.end() ; i++ )
490 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
491 c->doApply( p_intf );
494 config_PutInt( p_intf, "qt-privacy-ask" , 0 );
495 /* We have to save here because the user may not launch Prefs */
496 config_SaveConfigFile( p_intf, NULL );
501 int MainInterface::privacyDialog( QList<ConfigControl *> *controls )
503 QDialog *privacy = new QDialog( this );
505 privacy->setWindowTitle( qtr( "Privacy and Network Policies" ) );
507 QGridLayout *gLayout = new QGridLayout( privacy );
509 QGroupBox *blabla = new QGroupBox( qtr( "Privacy and Network Warning" ) );
510 QGridLayout *blablaLayout = new QGridLayout( blabla );
511 QLabel *text = new QLabel( qtr(
512 "<p>The <i>VideoLAN Team</i> doesn't like when an application goes "
513 "online without authorization.</p>\n "
514 "<p><i>VLC media player</i> can retreive limited information from "
515 "the Internet in order to get CD covers or to check "
516 "for available updates.</p>\n"
517 "<p><i>VLC media player</i> <b>DOES NOT</b> send or collect <b>ANY</b> "
518 "information, even anonymously, about your usage.</p>\n"
519 "<p>Therefore please select from the following options, the default being "
520 "almost no access to the web.</p>\n") );
521 text->setWordWrap( true );
522 text->setTextFormat( Qt::RichText );
524 blablaLayout->addWidget( text, 0, 0 ) ;
526 QGroupBox *options = new QGroupBox;
527 QGridLayout *optionsLayout = new QGridLayout( options );
529 gLayout->addWidget( blabla, 0, 0, 1, 3 );
530 gLayout->addWidget( options, 1, 0, 1, 3 );
531 module_config_t *p_config;
532 ConfigControl *control;
535 #define CONFIG_GENERIC( option, type ) \
536 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
539 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
540 p_config, options, false, optionsLayout, line ); \
541 controls->append( control ); \
544 #define CONFIG_GENERIC_NOBOOL( option, type ) \
545 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
548 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
549 p_config, options, optionsLayout, line ); \
550 controls->append( control ); \
553 CONFIG_GENERIC( "album-art", IntegerList ); line++;
555 CONFIG_GENERIC_NOBOOL( "qt-updates-notif", Bool ); line++;
556 CONFIG_GENERIC_NOBOOL( "qt-updates-days", Integer ); line++;
559 QPushButton *ok = new QPushButton( qtr( "OK" ) );
561 gLayout->addWidget( ok, 2, 2 );
563 CONNECT( ok, clicked(), privacy, accept() );
564 return privacy->exec();
568 /**********************************************************************
569 * Handling of sizing of the components
570 **********************************************************************/
572 /* This function is probably wrong, but we don't have many many choices...
573 Since we can't know from the playlist Widget if we are inside a dock or not,
574 because the playlist Widget can be called by THEDP, as a separate windows for
576 Maybe the other solution is to redefine the sizeHint() of the playlist and
577 ask _parent->isFloating()...
578 If you think this would be better, please FIXME it...
581 QSize MainInterface::sizeHint() const
585 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
586 i_visualmode == QT_MINIMAL_MODE )
588 return mainVideoSize;
592 if( VISIBLE( bgWidget) ||
593 ( videoIsActive && videoWidget->isVisible() )
595 return mainVideoSize;
597 return mainBasedSize;
601 int nwidth = controls->sizeHint().width();
602 int nheight = controls->isVisible() ?
603 controls->size().height()
604 + inputC->size().height()
605 + menuBar()->size().height()
606 + statusBar()->size().height()
609 if( VISIBLE( bgWidget ) )
611 nheight += bgWidget->size().height();
612 nwidth = bgWidget->size().width();
614 else if( videoIsActive && videoWidget->isVisible() )
616 nheight += videoWidget->sizeHint().height();
617 nwidth = videoWidget->sizeHint().width();
620 if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget() )
622 nheight += dockPL->size().height();
623 nwidth = __MAX( nwidth, dockPL->size().width() );
624 msg_Warn( p_intf, "3 %i %i", nheight, nwidth );
627 return QSize( nwidth, nheight );
630 void MainInterface::toggleFSC()
632 if( !fullscreenControls ) return;
634 IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
635 QApplication::postEvent( fullscreenControls, eShow );
638 void MainInterface::debug()
641 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
642 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
643 if( videoWidget && videoWidget->isVisible() )
645 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
646 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
651 /****************************************************************************
653 ****************************************************************************/
655 /* This event is used to deal with the fullscreen and always on top
656 issue conflict (bug in wx) */
657 class SetVideoOnTopQtEvent : public QEvent
660 SetVideoOnTopQtEvent( bool _onTop ) :
661 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
664 bool OnTop() const { return onTop; }
672 * Thou shall not call/resize/hide widgets from on another thread.
673 * This is wrong, and this is THE reason to emit signals on those Video Functions
675 WId MainInterface::requestVideo( vout_thread_t *p_nvout, int *pi_x,
676 int *pi_y, unsigned int *pi_width,
677 unsigned int *pi_height )
679 /* Request the videoWidget */
680 WId ret = videoWidget->request( p_nvout,pi_x, pi_y,
681 pi_width, pi_height, b_keep_size );
682 if( ret ) /* The videoWidget is available */
684 /* Did we have a bg ? Hide it! */
685 if( VISIBLE( bgWidget) )
688 emit askBgWidgetToToggle();
691 bgWasVisible = false;
693 /* ask videoWidget to show */
694 emit askVideoToShow( *pi_width, *pi_height );
696 /* Consider the video active now */
697 videoIsActive = true;
704 /* Call from the WindowClose function */
705 void MainInterface::releaseVideo( void )
707 emit askReleaseVideo( );
710 /* Function that is CONNECTED to the previous emit */
711 void MainInterface::releaseVideoSlot( void )
713 videoWidget->release( );
717 /* Reset the bg state */
718 bgWasVisible = false;
722 videoIsActive = false;
724 /* Try to resize, except when you are in Fullscreen mode */
725 if( !isFullScreen() ) doComponentsUpdate();
728 /* Call from WindowControl function */
729 int MainInterface::controlVideo( int i_query, va_list args )
731 int i_ret = VLC_SUCCESS;
736 unsigned int i_width = va_arg( args, unsigned int );
737 unsigned int i_height = va_arg( args, unsigned int );
738 emit askVideoToResize( i_width, i_height );
742 case VOUT_SET_STAY_ON_TOP:
744 int i_arg = va_arg( args, int );
745 QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
749 i_ret = VLC_EGENERIC;
750 msg_Warn( p_intf, "unsupported control query" );
756 /*****************************************************************************
757 * Playlist, Visualisation and Menus handling
758 *****************************************************************************/
760 * Toggle the playlist widget or dialog
762 void MainInterface::togglePlaylist()
765 If no playlist exist, then create one and attach it to the DockPL*/
766 if( !playlistWidget )
768 playlistWidget = new PlaylistWidget( p_intf );
770 i_pl_dock = PL_UNDOCKED;
771 /* i_pl_dock = (pl_dock_e)getSettings()
772 ->value( "pl-dock-status", PL_UNDOCKED ).toInt(); */
774 if( i_pl_dock == PL_UNDOCKED )
776 playlistWidget->setWindowFlags( Qt::Window );
778 /* This will restore the geometry but will not work for position,
779 because of parenting */
780 QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
781 playlistWidget, QSize( 600, 300 ) );
785 mainLayout->insertWidget( 4, playlistWidget );
787 playlistVisible = true;
789 playlistWidget->show();
793 /* toggle the visibility of the playlist */
794 TOGGLEV( playlistWidget );
795 playlistVisible = !playlistVisible;
796 //doComponentsUpdate(); //resize( sizeHint() );
800 /* Function called from the menu to undock the playlist */
801 void MainInterface::undockPlaylist()
803 // dockPL->setFloating( true );
807 void MainInterface::dockPlaylist( pl_dock_e i_pos )
811 void MainInterface::toggleMinimalView( bool b_switch )
813 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
814 i_visualmode != QT_MINIMAL_MODE )
815 { /* NORMAL MODE then */
816 if( !videoWidget || videoWidget->isHidden() ) emit askBgWidgetToToggle();
819 /* If video is visible, then toggle the status of bgWidget */
820 bgWasVisible = !bgWasVisible;
824 menuBar()->setVisible( !b_switch );
825 controls->setVisible( !b_switch );
826 statusBar()->setVisible( !b_switch );
827 inputC->setVisible( !b_switch );
828 doComponentsUpdate();
830 emit minimalViewToggled( b_switch );
833 /* Video widget cannot do this synchronously as it runs in another thread */
834 /* Well, could it, actually ? Probably dangerous ... */
836 /* This function is called:
837 - toggling of minimal View
838 - through askUpdate() by Vout thread request video and resize video (zoom)
839 - Advanced buttons toggled
841 void MainInterface::doComponentsUpdate()
843 msg_Dbg( p_intf, "Updating the geometry" );
844 /* Here we resize to sizeHint() and not adjustsize because we want
845 the videoWidget to be exactly the correctSize */
846 resize( sizeHint() );
853 /* toggling advanced controls buttons */
854 void MainInterface::toggleAdvanced()
856 controls->toggleAdvanced();
857 // if( fullscreenControls ) fullscreenControls->toggleAdvanced();
860 /* Get the visibility status of the controls (hidden or not, advanced or not) */
861 int MainInterface::getControlsVisibilityStatus()
863 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
864 + CONTROLS_ADVANCED * controls->b_advancedVisible );
868 void MainInterface::visual()
870 if( !VISIBLE( visualSelector) )
872 visualSelector->show();
873 if( !THEMIM->getIM()->hasVideo() )
875 /* Show the background widget */
877 visualSelectorEnabled = true;
881 /* Stop any currently running visualization */
882 visualSelector->hide();
883 visualSelectorEnabled = false;
885 doComponentsUpdate();
889 /************************************************************************
891 ************************************************************************/
892 void MainInterface::setName( QString name )
894 input_name = name; /* store it for the QSystray use */
895 /* Display it in the status bar, but also as a Tooltip in case it doesn't
897 nameLabel->setText( " " + name + " " );
898 nameLabel->setToolTip( " " + name +" " );
901 /*****************************************************************************
902 * Systray Icon and Systray Menu
903 *****************************************************************************/
906 * Create a SystemTray icon and a menu that would go with it.
907 * Connects to a click handler on the icon.
909 void MainInterface::createSystray()
912 if( QDate::currentDate().dayOfYear() >= 354 )
913 iconVLC = QIcon( QPixmap( ":/vlc128-christmas.png" ) );
915 iconVLC = QIcon( QPixmap( ":/vlc128.png" ) );
916 sysTray = new QSystemTrayIcon( iconVLC, this );
917 sysTray->setToolTip( qtr( "VLC media player" ));
919 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
920 systrayMenu->setIcon( iconVLC );
922 QVLCMenu::updateSystrayMenu( this, p_intf, true );
925 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
926 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
930 * Updates the Systray Icon's menu and toggle the main interface
932 void MainInterface::toggleUpdateSystrayMenu()
934 /* If hidden, show it */
940 else if( isMinimized() )
948 /* Visible (possibly under other windows) */
950 /* check if any visible window is above vlc in the z-order,
951 * but ignore the ones always on top
952 * and the ones which can't be activated */
955 wi.cbSize = sizeof( WINDOWINFO );
956 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
957 hwnd && ( !IsWindowVisible( hwnd ) ||
958 ( GetWindowInfo( hwnd, &wi ) &&
959 (wi.dwExStyle&WS_EX_NOACTIVATE) ) );
960 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
961 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
962 (wi.dwExStyle&WS_EX_TOPMOST) )
974 QVLCMenu::updateSystrayMenu( this, p_intf );
977 void MainInterface::handleSystrayClick(
978 QSystemTrayIcon::ActivationReason reason )
982 case QSystemTrayIcon::Trigger:
983 case QSystemTrayIcon::DoubleClick:
984 toggleUpdateSystrayMenu();
986 case QSystemTrayIcon::MiddleClick:
987 sysTray->showMessage( qtr( "VLC media player" ),
988 qtr( "Control menu for the player" ),
989 QSystemTrayIcon::Information, 3000 );
997 * Updates the name of the systray Icon tooltip.
998 * Doesn't check if the systray exists, check before you call it.
1000 void MainInterface::updateSystrayTooltipName( QString name )
1002 if( name.isEmpty() )
1004 sysTray->setToolTip( qtr( "VLC media player" ) );
1008 sysTray->setToolTip( name );
1009 if( notificationEnabled && ( isHidden() || isMinimized() ) )
1011 sysTray->showMessage( qtr( "VLC media player" ), name,
1012 QSystemTrayIcon::NoIcon, 3000 );
1016 QVLCMenu::updateSystrayMenu( this, p_intf );
1020 * Updates the status of the systray Icon tooltip.
1021 * Doesn't check if the systray exists, check before you call it.
1023 void MainInterface::updateSystrayTooltipStatus( int i_status )
1030 sysTray->setToolTip( qtr( "VLC media player" ) );
1035 sysTray->setToolTip( input_name );
1040 sysTray->setToolTip( input_name + " - "
1047 /************************************************************************
1049 ************************************************************************/
1050 void MainInterface::dropEvent(QDropEvent *event)
1052 dropEventPlay( event, true );
1055 void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
1057 const QMimeData *mimeData = event->mimeData();
1059 /* D&D of a subtitles file, add it on the fly */
1060 if( mimeData->urls().size() == 1 )
1062 if( THEMIM->getIM()->hasInput() )
1064 if( !input_AddSubtitle( THEMIM->getInput(),
1065 qtu( toNativeSeparators(
1066 mimeData->urls()[0].toLocalFile() ) ),
1069 event->acceptProposedAction();
1074 bool first = b_play;
1075 foreach( const QUrl &url, mimeData->urls() )
1077 QString s = toNativeSeparators( url.toLocalFile() );
1079 if( s.length() > 0 ) {
1080 playlist_Add( THEPL, qtu(s), NULL,
1081 PLAYLIST_APPEND | (first ? PLAYLIST_GO: 0),
1082 PLAYLIST_END, true, false );
1084 RecentsMRL::getInstance( p_intf )->addRecent( s );
1087 event->acceptProposedAction();
1089 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1091 event->acceptProposedAction();
1093 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1095 event->acceptProposedAction();
1097 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1102 /************************************************************************
1104 ************************************************************************/
1105 void MainInterface::customEvent( QEvent *event )
1108 if( event->type() == PLDockEvent_Type )
1110 PlaylistDialog::killInstance();
1111 playlistEmbeddedFlag = true;
1113 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1118 if ( event->type() == (int)SetVideoOnTopEvent_Type )
1120 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1121 if( p_event->OnTop() )
1122 setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
1124 setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint);
1125 show(); /* necessary to apply window flags?? */
1129 void MainInterface::keyPressEvent( QKeyEvent *e )
1131 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() == Qt::Key_H )
1132 && menuBar()->isHidden() )
1134 toggleMinimalView( false );
1138 int i_vlck = qtEventToVLCKey( e );
1141 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1148 void MainInterface::resizeEvent( QResizeEvent * event )
1152 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
1153 i_visualmode == QT_MINIMAL_MODE )
1155 mainVideoSize = size();
1159 if( VISIBLE( bgWidget) ||
1160 ( videoIsActive && videoWidget->isVisible() )
1162 mainVideoSize = size();
1164 mainBasedSize = size();
1169 void MainInterface::wheelEvent( QWheelEvent *e )
1171 int i_vlckey = qtWheelEventToVLCKey( e );
1172 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1176 void MainInterface::closeEvent( QCloseEvent *e )
1183 void MainInterface::toggleFullScreen( void )
1185 if( isFullScreen() )
1188 emit askUpdate(); // Needed if video was launched after the F11
1189 emit fullscreenInterfaceToggled( false );
1194 emit fullscreenInterfaceToggled( true );
1199 /*****************************************************************************
1201 *****************************************************************************/
1202 static int InteractCallback( vlc_object_t *p_this,
1203 const char *psz_var, vlc_value_t old_val,
1204 vlc_value_t new_val, void *param )
1206 intf_dialog_args_t *p_arg = new intf_dialog_args_t;
1207 p_arg->p_dialog = (interaction_dialog_t *)(new_val.p_address);
1208 DialogEvent *event = new DialogEvent( INTF_DIALOG_INTERACTION, 0, p_arg );
1209 QApplication::postEvent( THEDP, event );
1213 /*****************************************************************************
1214 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1215 * We don't show the menu directly here because we don't want the
1216 * caller to block for a too long time.
1217 *****************************************************************************/
1218 static int PopupMenuCB( 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;
1223 if( p_intf->pf_show_dialog )
1225 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1226 new_val.b_bool, NULL );
1232 /*****************************************************************************
1233 * IntfShowCB: callback triggered by the intf-show libvlc variable.
1234 *****************************************************************************/
1235 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1236 vlc_value_t old_val, vlc_value_t new_val, void *param )
1238 intf_thread_t *p_intf = (intf_thread_t *)param;
1239 p_intf->p_sys->p_mi->toggleFSC();