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 /* Visualisation, not really used yet */
125 visualSelectorEnabled = settings->value( "visual-selector", false).toBool();
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, visualSelectorEnabled );
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_AddCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
211 /* Register callback for the intf-popupmenu variable */
212 var_AddCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
215 /* VideoWidget connects to avoid different threads speaking to each other */
216 connect( this, SIGNAL(askReleaseVideo( void )),
217 this, SLOT(releaseVideoSlot( void )), Qt::BlockingQueuedConnection );
221 CONNECT( this, askVideoToResize( unsigned int, unsigned int ),
222 videoWidget, SetSizing( unsigned int, unsigned int ) );
224 connect( this, SIGNAL(askVideoToShow( unsigned int, unsigned int)),
225 videoWidget, SLOT(SetSizing(unsigned int, unsigned int )),
226 Qt::BlockingQueuedConnection );
229 CONNECT( this, askUpdate(), this, doComponentsUpdate() );
231 /* Size and placement of interface */
232 settings->beginGroup( "MainWindow" );
233 QVLCTools::restoreWidgetPosition( settings, this, QSize(380, 60) );
235 /* resize to previously saved main window size if appicable */
238 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
239 i_visualmode == QT_MINIMAL_MODE )
241 resize( mainVideoSize );
245 resize( mainBasedSize );
249 bool b_visible = settings->value( "playlist-visible", 0 ).toInt();
250 settings->endGroup();
253 if( b_visible ) togglePlaylist();
255 /* Final sizing and showing */
256 setMinimumWidth( __MAX( controls->sizeHint().width(),
257 menuBar()->sizeHint().width() ) );
260 /* And switch to minimal view if needed
261 Must be called after the show() */
262 if( i_visualmode == QT_MINIMAL_MODE )
265 /* Update the geometry : It is useful if you switch between
268 resize( sizeHint() );
270 /*****************************************************
271 * End everything by creating the Systray Management *
272 *****************************************************/
276 MainInterface::~MainInterface()
278 msg_Dbg( p_intf, "Destroying the main interface" );
280 if( videoIsActive ) videoWidget->hide();
285 QVLCTools::saveWidgetPosition( p_intf, "Playlist", playlistWidget );
287 delete playlistWidget;
290 ActionsManager::killInstance();
292 if( fullscreenControls ) delete fullscreenControls;
294 settings->beginGroup( "MainWindow" );
296 settings->setValue( "pl-dock-status", (int)i_pl_dock );
297 settings->setValue( "playlist-visible", (int)playlistVisible );
298 settings->setValue( "adv-controls",
299 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
301 settings->setValue( "mainBasedSize", mainBasedSize );
302 settings->setValue( "mainVideoSize", mainVideoSize );
305 settings->setValue( "backgroundSize", bgWidget->size() );
307 QVLCTools::saveWidgetPosition(settings, this);
308 settings->endGroup();
310 var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
312 /* Unregister callback for the intf-popupmenu variable */
313 var_DelCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
315 interaction_Unregister( p_intf );
316 var_DelCallback( p_intf, "interaction", InteractCallback, this );
318 p_intf->p_sys->p_mi = NULL;
321 /*****************************
323 *****************************/
325 inline void MainInterface::createStatusBar()
330 /* Widgets Creation*/
331 QStatusBar *statusBarr = statusBar();
333 TimeLabel *timeLabel = new TimeLabel( p_intf );
334 nameLabel = new QLabel( this );
335 nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
336 | Qt::TextSelectableByKeyboard );
337 SpeedLabel *speedLabel = new SpeedLabel( p_intf, "1.00x", this );
339 /* Styling those labels */
340 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
341 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
342 nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
344 /* and adding those */
345 statusBarr->addWidget( nameLabel, 8 );
346 statusBarr->addPermanentWidget( speedLabel, 0 );
347 statusBarr->addPermanentWidget( timeLabel, 0 );
349 /* timeLabel behaviour:
350 - double clicking opens the goto time dialog
351 - right-clicking and clicking just toggle between remaining and
353 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
355 CONNECT( THEMIM->getIM(), encryptionChanged( bool ) , this, showCryptedLabel( bool ) );
360 void MainInterface::showCryptedLabel( bool )
362 if( cryptedLabel == NULL )
364 cryptedLabel = new QLabel;
365 cryptedLabel->setPixmap( QPixmap( ":/eject" ) );
366 statusBar()->addWidget( cryptedLabel );
369 cryptedLabel->show();
373 inline void MainInterface::initSystray()
375 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
376 bool b_systrayWanted = config_GetInt( p_intf, "qt-system-tray" );
378 if( config_GetInt( p_intf, "qt-start-minimized") > 0 )
380 if( b_systrayAvailable )
382 b_systrayWanted = true;
386 msg_Err( p_intf, "cannot start minimized without system tray bar" );
389 if( b_systrayAvailable && b_systrayWanted )
394 * Give the decorations of the Main Window a correct Name.
395 * If nothing is given, set it to VLC...
397 void MainInterface::setVLCWindowsTitle( QString aTitle )
399 if( aTitle.isEmpty() )
401 setWindowTitle( qtr( "VLC media player" ) );
405 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
409 void MainInterface::handleMainUi( QSettings *settings )
411 /* Create the main Widget and the mainLayout */
412 QWidget *main = new QWidget;
413 setCentralWidget( main );
414 mainLayout = new QVBoxLayout( main );
416 /* Margins, spacing */
417 main->setContentsMargins( 0, 0, 0, 0 );
418 main->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
419 mainLayout->setSpacing( 0 );
420 mainLayout->setMargin( 0 );
422 /* Create the CONTROLS Widget */
423 controls = new ControlsWidget( p_intf,
424 settings->value( "adv-controls", false ).toBool(), this );
425 CONNECT( controls, advancedControlsToggled( bool ),
426 this, doComponentsUpdate() );
427 inputC = new InputControlsWidget( p_intf, this );
430 /* Disabled for now, they SUCK */
432 visualSelector = new VisualSelector( p_intf );
433 mainLayout->insertWidget( 0, visualSelector );
434 visualSelector->hide();
438 bgWidget = new BackgroundWidget( p_intf );
440 settings->value( "backgroundSize", QSize( 300, 200 ) ).toSize() );
441 bgWidget->updateGeometry();
442 CONNECT( this, askBgWidgetToToggle(), bgWidget, toggle() );
444 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
445 i_visualmode != QT_MINIMAL_MODE )
450 /* And video Outputs */
451 if( videoEmbeddedFlag )
452 videoWidget = new VideoWidget( p_intf );
454 /* Add the controls Widget to the main Widget */
455 mainLayout->insertWidget( 0, bgWidget );
456 if( videoWidget ) mainLayout->insertWidget( 0, videoWidget, 10 );
457 mainLayout->insertWidget( 2, inputC, 0, Qt::AlignBottom );
458 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
459 controls, 0, Qt::AlignBottom );
461 /* Finish the sizing */
462 main->updateGeometry();
464 getSettings()->endGroup();
468 /* Create the FULLSCREEN CONTROLS Widget */
469 if( config_GetInt( p_intf, "qt-fs-controller" ) )
471 fullscreenControls = new FullscreenControllerWidget( p_intf );
475 inline void MainInterface::askForPrivacy()
478 * Ask for the network policy on FIRST STARTUP
480 if( config_GetInt( p_intf, "qt-privacy-ask") )
482 QList<ConfigControl *> controls;
483 if( privacyDialog( &controls ) == QDialog::Accepted )
485 QList<ConfigControl *>::Iterator i;
486 for( i = controls.begin() ; i != controls.end() ; i++ )
488 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
489 c->doApply( p_intf );
492 config_PutInt( p_intf, "qt-privacy-ask" , 0 );
493 /* We have to save here because the user may not launch Prefs */
494 config_SaveConfigFile( p_intf, NULL );
499 int MainInterface::privacyDialog( QList<ConfigControl *> *controls )
501 QDialog *privacy = new QDialog( this );
503 privacy->setWindowTitle( qtr( "Privacy and Network Policies" ) );
505 QGridLayout *gLayout = new QGridLayout( privacy );
507 QGroupBox *blabla = new QGroupBox( qtr( "Privacy and Network Warning" ) );
508 QGridLayout *blablaLayout = new QGridLayout( blabla );
509 QLabel *text = new QLabel( qtr(
510 "<p>The <i>VideoLAN Team</i> doesn't like when an application goes "
511 "online without authorization.</p>\n "
512 "<p><i>VLC media player</i> can retreive limited information from "
513 "the Internet in order to get CD covers or to check "
514 "for available updates.</p>\n"
515 "<p><i>VLC media player</i> <b>DOES NOT</b> send or collect <b>ANY</b> "
516 "information, even anonymously, about your usage.</p>\n"
517 "<p>Therefore please select from the following options, the default being "
518 "almost no access to the web.</p>\n") );
519 text->setWordWrap( true );
520 text->setTextFormat( Qt::RichText );
522 blablaLayout->addWidget( text, 0, 0 ) ;
524 QGroupBox *options = new QGroupBox;
525 QGridLayout *optionsLayout = new QGridLayout( options );
527 gLayout->addWidget( blabla, 0, 0, 1, 3 );
528 gLayout->addWidget( options, 1, 0, 1, 3 );
529 module_config_t *p_config;
530 ConfigControl *control;
533 #define CONFIG_GENERIC( option, type ) \
534 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
537 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
538 p_config, options, false, optionsLayout, line ); \
539 controls->append( control ); \
542 #define CONFIG_GENERIC_NOBOOL( option, type ) \
543 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
546 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
547 p_config, options, optionsLayout, line ); \
548 controls->append( control ); \
551 CONFIG_GENERIC( "album-art", IntegerList ); line++;
553 CONFIG_GENERIC_NOBOOL( "qt-updates-notif", Bool ); line++;
554 CONFIG_GENERIC_NOBOOL( "qt-updates-days", Integer ); line++;
557 QPushButton *ok = new QPushButton( qtr( "OK" ) );
559 gLayout->addWidget( ok, 2, 2 );
561 CONNECT( ok, clicked(), privacy, accept() );
562 return privacy->exec();
566 /**********************************************************************
567 * Handling of sizing of the components
568 **********************************************************************/
570 /* This function is probably wrong, but we don't have many many choices...
571 Since we can't know from the playlist Widget if we are inside a dock or not,
572 because the playlist Widget can be called by THEDP, as a separate windows for
574 Maybe the other solution is to redefine the sizeHint() of the playlist and
575 ask _parent->isFloating()...
576 If you think this would be better, please FIXME it...
579 QSize MainInterface::sizeHint() const
583 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
584 i_visualmode == QT_MINIMAL_MODE )
586 return mainVideoSize;
590 if( VISIBLE( bgWidget) ||
591 ( videoIsActive && videoWidget->isVisible() )
593 return mainVideoSize;
595 return mainBasedSize;
599 int nwidth = controls->sizeHint().width();
600 int nheight = controls->isVisible() ?
601 controls->size().height()
602 + inputC->size().height()
603 + menuBar()->size().height()
604 + statusBar()->size().height()
607 if( VISIBLE( bgWidget ) )
609 nheight += bgWidget->size().height();
610 nwidth = bgWidget->size().width();
612 else if( videoIsActive && videoWidget->isVisible() )
614 nheight += videoWidget->sizeHint().height();
615 nwidth = videoWidget->sizeHint().width();
618 if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget() )
620 nheight += dockPL->size().height();
621 nwidth = __MAX( nwidth, dockPL->size().width() );
622 msg_Warn( p_intf, "3 %i %i", nheight, nwidth );
625 return QSize( nwidth, nheight );
628 void MainInterface::toggleFSC()
630 if( !fullscreenControls ) return;
632 IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
633 QApplication::postEvent( fullscreenControls, eShow );
636 void MainInterface::debug()
639 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
640 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
641 if( videoWidget && videoWidget->isVisible() )
643 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
644 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
649 /****************************************************************************
651 ****************************************************************************/
653 /* This event is used to deal with the fullscreen and always on top
654 issue conflict (bug in wx) */
655 class SetVideoOnTopQtEvent : public QEvent
658 SetVideoOnTopQtEvent( bool _onTop ) :
659 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
662 bool OnTop() const { return onTop; }
670 * Thou shall not call/resize/hide widgets from on another thread.
671 * This is wrong, and this is THE reason to emit signals on those Video Functions
673 WId MainInterface::requestVideo( vout_thread_t *p_nvout, int *pi_x,
674 int *pi_y, unsigned int *pi_width,
675 unsigned int *pi_height )
677 /* Request the videoWidget */
678 WId ret = videoWidget->request( p_nvout,pi_x, pi_y,
679 pi_width, pi_height, b_keep_size );
680 if( ret ) /* The videoWidget is available */
682 /* Did we have a bg ? Hide it! */
683 if( VISIBLE( bgWidget) )
686 emit askBgWidgetToToggle();
689 bgWasVisible = false;
691 /* ask videoWidget to show */
692 emit askVideoToShow( *pi_width, *pi_height );
694 /* Consider the video active now */
695 videoIsActive = true;
702 /* Call from the WindowClose function */
703 void MainInterface::releaseVideo( void )
705 emit askReleaseVideo( );
708 /* Function that is CONNECTED to the previous emit */
709 void MainInterface::releaseVideoSlot( void )
711 videoWidget->release( );
715 /* Reset the bg state */
716 bgWasVisible = false;
720 videoIsActive = false;
722 /* Try to resize, except when you are in Fullscreen mode */
723 if( !isFullScreen() ) doComponentsUpdate();
726 /* Call from WindowControl function */
727 int MainInterface::controlVideo( int i_query, va_list args )
729 int i_ret = VLC_SUCCESS;
734 unsigned int i_width = va_arg( args, unsigned int );
735 unsigned int i_height = va_arg( args, unsigned int );
736 emit askVideoToResize( i_width, i_height );
740 case VOUT_SET_STAY_ON_TOP:
742 int i_arg = va_arg( args, int );
743 QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
747 i_ret = VLC_EGENERIC;
748 msg_Warn( p_intf, "unsupported control query" );
754 /*****************************************************************************
755 * Playlist, Visualisation and Menus handling
756 *****************************************************************************/
758 * Toggle the playlist widget or dialog
760 void MainInterface::togglePlaylist()
763 If no playlist exist, then create one and attach it to the DockPL*/
764 if( !playlistWidget )
766 playlistWidget = new PlaylistWidget( p_intf );
768 i_pl_dock = PL_UNDOCKED;
769 /* i_pl_dock = (pl_dock_e)getSettings()
770 ->value( "pl-dock-status", PL_UNDOCKED ).toInt(); */
772 if( i_pl_dock == PL_UNDOCKED )
774 playlistWidget->setWindowFlags( Qt::Window );
776 /* This will restore the geometry but will not work for position,
777 because of parenting */
778 QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
779 playlistWidget, QSize( 600, 300 ) );
783 mainLayout->insertWidget( 4, playlistWidget );
785 playlistVisible = true;
787 playlistWidget->show();
791 /* toggle the visibility of the playlist */
792 TOGGLEV( playlistWidget );
793 playlistVisible = !playlistVisible;
794 //doComponentsUpdate(); //resize( sizeHint() );
798 /* Function called from the menu to undock the playlist */
799 void MainInterface::undockPlaylist()
801 // dockPL->setFloating( true );
805 void MainInterface::dockPlaylist( pl_dock_e i_pos )
809 void MainInterface::toggleMinimalView()
811 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
812 i_visualmode != QT_MINIMAL_MODE )
813 { /* NORMAL MODE then */
814 if( !videoWidget || videoWidget->isHidden() ) emit askBgWidgetToToggle();
817 /* If video is visible, then toggle the status of bgWidget */
818 bgWasVisible = !bgWasVisible;
822 TOGGLEV( menuBar() );
824 TOGGLEV( statusBar() );
826 doComponentsUpdate();
828 QVLCMenu::minimalViewAction->setChecked( bgWasVisible );
831 /* Video widget cannot do this synchronously as it runs in another thread */
832 /* Well, could it, actually ? Probably dangerous ... */
834 /* This function is called:
835 - toggling of minimal View
836 - through askUpdate() by Vout thread request video and resize video (zoom)
837 - Advanced buttons toggled
839 void MainInterface::doComponentsUpdate()
841 msg_Dbg( p_intf, "Updating the geometry" );
842 /* Here we resize to sizeHint() and not adjustsize because we want
843 the videoWidget to be exactly the correctSize */
844 resize( sizeHint() );
851 /* toggling advanced controls buttons */
852 void MainInterface::toggleAdvanced()
854 controls->toggleAdvanced();
855 // if( fullscreenControls ) fullscreenControls->toggleAdvanced();
858 /* Get the visibility status of the controls (hidden or not, advanced or not) */
859 int MainInterface::getControlsVisibilityStatus()
861 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
862 + CONTROLS_ADVANCED * controls->b_advancedVisible );
866 void MainInterface::visual()
868 if( !VISIBLE( visualSelector) )
870 visualSelector->show();
871 if( !THEMIM->getIM()->hasVideo() )
873 /* Show the background widget */
875 visualSelectorEnabled = true;
879 /* Stop any currently running visualization */
880 visualSelector->hide();
881 visualSelectorEnabled = false;
883 doComponentsUpdate();
887 /************************************************************************
889 ************************************************************************/
890 void MainInterface::setName( QString name )
892 input_name = name; /* store it for the QSystray use */
893 /* Display it in the status bar, but also as a Tooltip in case it doesn't
895 nameLabel->setText( " " + name + " " );
896 nameLabel->setToolTip( " " + name +" " );
899 /*****************************************************************************
900 * Systray Icon and Systray Menu
901 *****************************************************************************/
904 * Create a SystemTray icon and a menu that would go with it.
905 * Connects to a click handler on the icon.
907 void MainInterface::createSystray()
910 if( QDate::currentDate().dayOfYear() >= 354 )
911 iconVLC = QIcon( QPixmap( ":/vlc128-christmas.png" ) );
913 iconVLC = QIcon( QPixmap( ":/vlc128.png" ) );
914 sysTray = new QSystemTrayIcon( iconVLC, this );
915 sysTray->setToolTip( qtr( "VLC media player" ));
917 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
918 systrayMenu->setIcon( iconVLC );
920 QVLCMenu::updateSystrayMenu( this, p_intf, true );
923 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
924 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
928 * Updates the Systray Icon's menu and toggle the main interface
930 void MainInterface::toggleUpdateSystrayMenu()
932 /* If hidden, show it */
938 else if( isMinimized() )
946 /* Visible (possibly under other windows) */
948 /* check if any visible window is above vlc in the z-order,
949 * but ignore the ones always on top
950 * and the ones which can't be activated */
953 wi.cbSize = sizeof( WINDOWINFO );
954 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
955 hwnd && ( !IsWindowVisible( hwnd ) ||
956 ( GetWindowInfo( hwnd, &wi ) &&
957 (wi.dwExStyle&WS_EX_NOACTIVATE) ) );
958 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
959 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
960 (wi.dwExStyle&WS_EX_TOPMOST) )
972 QVLCMenu::updateSystrayMenu( this, p_intf );
975 void MainInterface::handleSystrayClick(
976 QSystemTrayIcon::ActivationReason reason )
980 case QSystemTrayIcon::Trigger:
981 case QSystemTrayIcon::DoubleClick:
982 toggleUpdateSystrayMenu();
984 case QSystemTrayIcon::MiddleClick:
985 case QSystemTrayIcon::Context:
986 sysTray->showMessage( qtr( "VLC media player" ),
987 qtr( "Control menu for the player" ),
988 QSystemTrayIcon::Information, 3000 );
996 * Updates the name of the systray Icon tooltip.
997 * Doesn't check if the systray exists, check before you call it.
999 void MainInterface::updateSystrayTooltipName( QString name )
1001 if( name.isEmpty() )
1003 sysTray->setToolTip( qtr( "VLC media player" ) );
1007 sysTray->setToolTip( name );
1008 if( notificationEnabled && ( isHidden() || isMinimized() ) )
1010 sysTray->showMessage( qtr( "VLC media player" ), name,
1011 QSystemTrayIcon::NoIcon, 3000 );
1015 QVLCMenu::updateSystrayMenu( this, p_intf );
1019 * Updates the status of the systray Icon tooltip.
1020 * Doesn't check if the systray exists, check before you call it.
1022 void MainInterface::updateSystrayTooltipStatus( int i_status )
1029 sysTray->setToolTip( qtr( "VLC media player" ) );
1034 sysTray->setToolTip( input_name );
1039 sysTray->setToolTip( input_name + " - "
1046 /************************************************************************
1048 ************************************************************************/
1049 void MainInterface::dropEvent(QDropEvent *event)
1051 dropEventPlay( event, true );
1054 void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
1056 const QMimeData *mimeData = event->mimeData();
1058 /* D&D of a subtitles file, add it on the fly */
1059 if( mimeData->urls().size() == 1 )
1061 if( THEMIM->getIM()->hasInput() )
1063 if( !input_AddSubtitle( THEMIM->getInput(),
1064 qtu( toNativeSeparators(
1065 mimeData->urls()[0].toLocalFile() ) ),
1068 event->acceptProposedAction();
1073 bool first = b_play;
1074 foreach( const QUrl &url, mimeData->urls() )
1076 QString s = toNativeSeparators( url.toLocalFile() );
1078 if( s.length() > 0 ) {
1079 playlist_Add( THEPL, qtu(s), NULL,
1080 PLAYLIST_APPEND | (first ? PLAYLIST_GO: 0),
1081 PLAYLIST_END, true, false );
1083 RecentsMRL::getInstance( p_intf )->addRecent( s );
1086 event->acceptProposedAction();
1088 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1090 event->acceptProposedAction();
1092 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1094 event->acceptProposedAction();
1096 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1101 /************************************************************************
1103 ************************************************************************/
1104 void MainInterface::customEvent( QEvent *event )
1107 if( event->type() == PLDockEvent_Type )
1109 PlaylistDialog::killInstance();
1110 playlistEmbeddedFlag = true;
1112 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1117 if ( event->type() == (int)SetVideoOnTopEvent_Type )
1119 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1120 if( p_event->OnTop() )
1121 setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
1123 setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint);
1124 show(); /* necessary to apply window flags?? */
1128 void MainInterface::keyPressEvent( QKeyEvent *e )
1130 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() == Qt::Key_H )
1131 && menuBar()->isHidden() )
1133 toggleMinimalView();
1137 int i_vlck = qtEventToVLCKey( e );
1140 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1147 void MainInterface::resizeEvent( QResizeEvent * event )
1151 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
1152 i_visualmode == QT_MINIMAL_MODE )
1154 mainVideoSize = size();
1158 if( VISIBLE( bgWidget) ||
1159 ( videoIsActive && videoWidget->isVisible() )
1161 mainVideoSize = size();
1163 mainBasedSize = size();
1168 void MainInterface::wheelEvent( QWheelEvent *e )
1170 int i_vlckey = qtWheelEventToVLCKey( e );
1171 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1175 void MainInterface::closeEvent( QCloseEvent *e )
1182 void MainInterface::toggleFullScreen( void )
1184 if( isFullScreen() )
1187 emit askUpdate(); // Needed if video was launched after the F11
1188 QVLCMenu::fullscreenViewAction->setChecked( false );
1193 QVLCMenu::fullscreenViewAction->setChecked( true );
1198 /*****************************************************************************
1200 *****************************************************************************/
1201 static int InteractCallback( vlc_object_t *p_this,
1202 const char *psz_var, vlc_value_t old_val,
1203 vlc_value_t new_val, void *param )
1205 intf_dialog_args_t *p_arg = new intf_dialog_args_t;
1206 p_arg->p_dialog = (interaction_dialog_t *)(new_val.p_address);
1207 DialogEvent *event = new DialogEvent( INTF_DIALOG_INTERACTION, 0, p_arg );
1208 QApplication::postEvent( THEDP, event );
1212 /*****************************************************************************
1213 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1214 * We don't show the menu directly here because we don't want the
1215 * caller to block for a too long time.
1216 *****************************************************************************/
1217 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1218 vlc_value_t old_val, vlc_value_t new_val, void *param )
1220 intf_thread_t *p_intf = (intf_thread_t *)param;
1222 if( p_intf->pf_show_dialog )
1224 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1225 new_val.b_bool, NULL );
1231 /*****************************************************************************
1232 * IntfShowCB: callback triggered by the intf-show libvlc variable.
1233 *****************************************************************************/
1234 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1235 vlc_value_t old_val, vlc_value_t new_val, void *param )
1237 intf_thread_t *p_intf = (intf_thread_t *)param;
1238 p_intf->p_sys->p_mi->toggleFSC();