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 )
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 if( videoIsActive ) videoWidget->hide();
282 QVLCTools::saveWidgetPosition( p_intf, "Playlist", playlistWidget );
284 delete playlistWidget;
287 ActionsManager::killInstance();
289 if( fullscreenControls ) delete fullscreenControls;
291 settings->beginGroup( "MainWindow" );
293 settings->setValue( "pl-dock-status", (int)i_pl_dock );
294 settings->setValue( "playlist-visible", (int)playlistVisible );
295 settings->setValue( "adv-controls",
296 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
298 settings->setValue( "mainBasedSize", mainBasedSize );
299 settings->setValue( "mainVideoSize", mainVideoSize );
302 settings->setValue( "backgroundSize", bgWidget->size() );
304 QVLCTools::saveWidgetPosition(settings, this);
305 settings->endGroup();
307 var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
309 /* Unregister callback for the intf-popupmenu variable */
310 var_DelCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
312 interaction_Unregister( p_intf );
313 var_DelCallback( p_intf, "interaction", InteractCallback, this );
315 p_intf->p_sys->p_mi = NULL;
318 /*****************************
320 *****************************/
322 inline void MainInterface::createStatusBar()
327 /* Widgets Creation*/
328 QStatusBar *statusBarr = statusBar();
330 TimeLabel *timeLabel = new TimeLabel( p_intf );
331 nameLabel = new QLabel( this );
332 nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
333 | Qt::TextSelectableByKeyboard );
334 SpeedLabel *speedLabel = new SpeedLabel( p_intf, "1.00x", this );
336 /* Styling those labels */
337 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
338 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
339 nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
341 /* and adding those */
342 statusBarr->addWidget( nameLabel, 8 );
343 statusBarr->addPermanentWidget( speedLabel, 0 );
344 statusBarr->addPermanentWidget( timeLabel, 0 );
346 /* timeLabel behaviour:
347 - double clicking opens the goto time dialog
348 - right-clicking and clicking just toggle between remaining and
350 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
352 CONNECT( THEMIM->getIM(), encryptionChanged( bool ) , this, showCryptedLabel( bool ) );
357 void MainInterface::showCryptedLabel( bool )
359 if( cryptedLabel == NULL )
361 cryptedLabel = new QLabel;
362 cryptedLabel->setPixmap( QPixmap( ":/eject" ) );
363 statusBar()->addWidget( cryptedLabel );
366 cryptedLabel->show();
370 inline void MainInterface::initSystray()
372 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
373 bool b_systrayWanted = config_GetInt( p_intf, "qt-system-tray" );
375 if( config_GetInt( p_intf, "qt-start-minimized") > 0 )
377 if( b_systrayAvailable )
379 b_systrayWanted = true;
383 msg_Err( p_intf, "cannot start minimized without system tray bar" );
386 if( b_systrayAvailable && b_systrayWanted )
391 * Give the decorations of the Main Window a correct Name.
392 * If nothing is given, set it to VLC...
394 void MainInterface::setVLCWindowsTitle( QString aTitle )
396 if( aTitle.isEmpty() )
398 setWindowTitle( qtr( "VLC media player" ) );
402 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
406 void MainInterface::handleMainUi( QSettings *settings )
408 /* Create the main Widget and the mainLayout */
409 QWidget *main = new QWidget;
410 setCentralWidget( main );
411 mainLayout = new QVBoxLayout( main );
413 /* Margins, spacing */
414 main->setContentsMargins( 0, 0, 0, 0 );
415 main->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
416 mainLayout->setSpacing( 0 );
417 mainLayout->setMargin( 0 );
419 /* Create the CONTROLS Widget */
420 controls = new ControlsWidget( p_intf,
421 settings->value( "adv-controls", false ).toBool(), this );
422 CONNECT( controls, advancedControlsToggled( bool ),
423 this, doComponentsUpdate() );
424 inputC = new InputControlsWidget( p_intf, this );
427 /* Disabled for now, they SUCK */
429 visualSelector = new VisualSelector( p_intf );
430 mainLayout->insertWidget( 0, visualSelector );
431 visualSelector->hide();
435 bgWidget = new BackgroundWidget( p_intf );
437 settings->value( "backgroundSize", QSize( 300, 200 ) ).toSize() );
438 bgWidget->updateGeometry();
439 CONNECT( this, askBgWidgetToToggle(), bgWidget, toggle() );
441 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
442 i_visualmode != QT_MINIMAL_MODE )
447 /* And video Outputs */
448 if( videoEmbeddedFlag )
449 videoWidget = new VideoWidget( p_intf );
451 /* Add the controls Widget to the main Widget */
452 mainLayout->insertWidget( 0, bgWidget );
453 if( videoWidget ) mainLayout->insertWidget( 0, videoWidget, 10 );
454 mainLayout->insertWidget( 2, inputC, 0, Qt::AlignBottom );
455 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
456 controls, 0, Qt::AlignBottom );
458 /* Finish the sizing */
459 main->updateGeometry();
461 getSettings()->endGroup();
465 /* Create the FULLSCREEN CONTROLS Widget */
466 if( config_GetInt( p_intf, "qt-fs-controller" ) )
468 fullscreenControls = new FullscreenControllerWidget( p_intf );
472 inline void MainInterface::askForPrivacy()
475 * Ask for the network policy on FIRST STARTUP
477 if( config_GetInt( p_intf, "qt-privacy-ask") )
479 QList<ConfigControl *> controls;
480 if( privacyDialog( &controls ) == QDialog::Accepted )
482 QList<ConfigControl *>::Iterator i;
483 for( i = controls.begin() ; i != controls.end() ; i++ )
485 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
486 c->doApply( p_intf );
489 config_PutInt( p_intf, "qt-privacy-ask" , 0 );
490 /* We have to save here because the user may not launch Prefs */
491 config_SaveConfigFile( p_intf, NULL );
496 int MainInterface::privacyDialog( QList<ConfigControl *> *controls )
498 QDialog *privacy = new QDialog( this );
500 privacy->setWindowTitle( qtr( "Privacy and Network Policies" ) );
502 QGridLayout *gLayout = new QGridLayout( privacy );
504 QGroupBox *blabla = new QGroupBox( qtr( "Privacy and Network Warning" ) );
505 QGridLayout *blablaLayout = new QGridLayout( blabla );
506 QLabel *text = new QLabel( qtr(
507 "<p>The <i>VideoLAN Team</i> doesn't like when an application goes "
508 "online without authorization.</p>\n "
509 "<p><i>VLC media player</i> can retreive limited information from "
510 "the Internet in order to get CD covers or to check "
511 "for available updates.</p>\n"
512 "<p><i>VLC media player</i> <b>DOES NOT</b> send or collect <b>ANY</b> "
513 "information, even anonymously, about your usage.</p>\n"
514 "<p>Therefore please select from the following options, the default being "
515 "almost no access to the web.</p>\n") );
516 text->setWordWrap( true );
517 text->setTextFormat( Qt::RichText );
519 blablaLayout->addWidget( text, 0, 0 ) ;
521 QGroupBox *options = new QGroupBox;
522 QGridLayout *optionsLayout = new QGridLayout( options );
524 gLayout->addWidget( blabla, 0, 0, 1, 3 );
525 gLayout->addWidget( options, 1, 0, 1, 3 );
526 module_config_t *p_config;
527 ConfigControl *control;
530 #define CONFIG_GENERIC( option, type ) \
531 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
534 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
535 p_config, options, false, optionsLayout, line ); \
536 controls->append( control ); \
539 #define CONFIG_GENERIC_NOBOOL( option, type ) \
540 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
543 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
544 p_config, options, optionsLayout, line ); \
545 controls->append( control ); \
548 CONFIG_GENERIC( "album-art", IntegerList ); line++;
550 CONFIG_GENERIC_NOBOOL( "qt-updates-notif", Bool ); line++;
551 CONFIG_GENERIC_NOBOOL( "qt-updates-days", Integer ); line++;
554 QPushButton *ok = new QPushButton( qtr( "OK" ) );
556 gLayout->addWidget( ok, 2, 2 );
558 CONNECT( ok, clicked(), privacy, accept() );
559 return privacy->exec();
563 /**********************************************************************
564 * Handling of sizing of the components
565 **********************************************************************/
567 /* This function is probably wrong, but we don't have many many choices...
568 Since we can't know from the playlist Widget if we are inside a dock or not,
569 because the playlist Widget can be called by THEDP, as a separate windows for
571 Maybe the other solution is to redefine the sizeHint() of the playlist and
572 ask _parent->isFloating()...
573 If you think this would be better, please FIXME it...
576 QSize MainInterface::sizeHint() const
580 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
581 i_visualmode == QT_MINIMAL_MODE )
583 return mainVideoSize;
587 if( VISIBLE( bgWidget) ||
588 ( videoIsActive && videoWidget->isVisible() )
590 return mainVideoSize;
592 return mainBasedSize;
596 int nwidth = controls->sizeHint().width();
597 int nheight = controls->isVisible() ?
598 controls->size().height()
599 + inputC->size().height()
600 + menuBar()->size().height()
601 + statusBar()->size().height()
604 if( VISIBLE( bgWidget ) )
606 nheight += bgWidget->size().height();
607 nwidth = bgWidget->size().width();
609 else if( videoIsActive && videoWidget->isVisible() )
611 nheight += videoWidget->sizeHint().height();
612 nwidth = videoWidget->sizeHint().width();
615 if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget() )
617 nheight += dockPL->size().height();
618 nwidth = __MAX( nwidth, dockPL->size().width() );
619 msg_Warn( p_intf, "3 %i %i", nheight, nwidth );
622 return QSize( nwidth, nheight );
625 void MainInterface::toggleFSC()
627 if( !fullscreenControls ) return;
629 IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
630 QApplication::postEvent( fullscreenControls, eShow );
633 void MainInterface::debug()
636 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
637 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
638 if( videoWidget && videoWidget->isVisible() )
640 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
641 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
646 /****************************************************************************
648 ****************************************************************************/
650 /* This event is used to deal with the fullscreen and always on top
651 issue conflict (bug in wx) */
652 class SetVideoOnTopQtEvent : public QEvent
655 SetVideoOnTopQtEvent( bool _onTop ) :
656 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
659 bool OnTop() const { return onTop; }
667 * Thou shall not call/resize/hide widgets from on another thread.
668 * This is wrong, and this is THE reason to emit signals on those Video Functions
670 WId MainInterface::requestVideo( vout_thread_t *p_nvout, int *pi_x,
671 int *pi_y, unsigned int *pi_width,
672 unsigned int *pi_height )
674 /* Request the videoWidget */
675 WId ret = videoWidget->request( p_nvout,pi_x, pi_y,
676 pi_width, pi_height, b_keep_size );
677 if( ret ) /* The videoWidget is available */
679 /* Did we have a bg ? Hide it! */
680 if( VISIBLE( bgWidget) )
683 emit askBgWidgetToToggle();
686 bgWasVisible = false;
688 /* ask videoWidget to show */
689 emit askVideoToShow( *pi_width, *pi_height );
691 /* Consider the video active now */
692 videoIsActive = true;
699 /* Call from the WindowClose function */
700 void MainInterface::releaseVideo( void )
702 emit askReleaseVideo( );
705 /* Function that is CONNECTED to the previous emit */
706 void MainInterface::releaseVideoSlot( void )
708 videoWidget->release( );
712 /* Reset the bg state */
713 bgWasVisible = false;
717 videoIsActive = false;
719 /* Try to resize, except when you are in Fullscreen mode */
720 if( !isFullScreen() ) doComponentsUpdate();
723 /* Call from WindowControl function */
724 int MainInterface::controlVideo( int i_query, va_list args )
726 int i_ret = VLC_SUCCESS;
731 unsigned int i_width = va_arg( args, unsigned int );
732 unsigned int i_height = va_arg( args, unsigned int );
733 emit askVideoToResize( i_width, i_height );
737 case VOUT_SET_STAY_ON_TOP:
739 int i_arg = va_arg( args, int );
740 QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
744 i_ret = VLC_EGENERIC;
745 msg_Warn( p_intf, "unsupported control query" );
751 /*****************************************************************************
752 * Playlist, Visualisation and Menus handling
753 *****************************************************************************/
755 * Toggle the playlist widget or dialog
757 void MainInterface::togglePlaylist()
760 If no playlist exist, then create one and attach it to the DockPL*/
761 if( !playlistWidget )
763 playlistWidget = new PlaylistWidget( p_intf );
765 i_pl_dock = PL_UNDOCKED;
766 /* i_pl_dock = (pl_dock_e)getSettings()
767 ->value( "pl-dock-status", PL_UNDOCKED ).toInt(); */
769 if( i_pl_dock == PL_UNDOCKED )
771 playlistWidget->setWindowFlags( Qt::Window );
773 /* This will restore the geometry but will not work for position,
774 because of parenting */
775 QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
776 playlistWidget, QSize( 600, 300 ) );
780 mainLayout->insertWidget( 4, playlistWidget );
782 playlistVisible = true;
784 playlistWidget->show();
788 /* toggle the visibility of the playlist */
789 TOGGLEV( playlistWidget );
790 playlistVisible = !playlistVisible;
791 //doComponentsUpdate(); //resize( sizeHint() );
795 /* Function called from the menu to undock the playlist */
796 void MainInterface::undockPlaylist()
798 // dockPL->setFloating( true );
802 void MainInterface::dockPlaylist( pl_dock_e i_pos )
806 void MainInterface::toggleMinimalView()
808 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
809 i_visualmode != QT_MINIMAL_MODE )
810 { /* NORMAL MODE then */
811 if( !videoWidget || videoWidget->isHidden() ) emit askBgWidgetToToggle();
814 /* If video is visible, then toggle the status of bgWidget */
815 bgWasVisible = !bgWasVisible;
819 TOGGLEV( menuBar() );
821 TOGGLEV( statusBar() );
823 doComponentsUpdate();
825 QVLCMenu::minimalViewAction->setChecked( bgWasVisible );
828 /* Video widget cannot do this synchronously as it runs in another thread */
829 /* Well, could it, actually ? Probably dangerous ... */
831 /* This function is called:
832 - toggling of minimal View
833 - through askUpdate() by Vout thread request video and resize video (zoom)
834 - Advanced buttons toggled
836 void MainInterface::doComponentsUpdate()
838 msg_Dbg( p_intf, "Updating the geometry" );
839 /* Here we resize to sizeHint() and not adjustsize because we want
840 the videoWidget to be exactly the correctSize */
841 resize( sizeHint() );
848 /* toggling advanced controls buttons */
849 void MainInterface::toggleAdvanced()
851 controls->toggleAdvanced();
852 // if( fullscreenControls ) fullscreenControls->toggleAdvanced();
855 /* Get the visibility status of the controls (hidden or not, advanced or not) */
856 int MainInterface::getControlsVisibilityStatus()
858 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
859 + CONTROLS_ADVANCED * controls->b_advancedVisible );
863 void MainInterface::visual()
865 if( !VISIBLE( visualSelector) )
867 visualSelector->show();
868 if( !THEMIM->getIM()->hasVideo() )
870 /* Show the background widget */
872 visualSelectorEnabled = true;
876 /* Stop any currently running visualization */
877 visualSelector->hide();
878 visualSelectorEnabled = false;
880 doComponentsUpdate();
884 /************************************************************************
886 ************************************************************************/
887 void MainInterface::setName( QString name )
889 input_name = name; /* store it for the QSystray use */
890 /* Display it in the status bar, but also as a Tooltip in case it doesn't
892 nameLabel->setText( " " + name + " " );
893 nameLabel->setToolTip( " " + name +" " );
896 /*****************************************************************************
897 * Systray Icon and Systray Menu
898 *****************************************************************************/
901 * Create a SystemTray icon and a menu that would go with it.
902 * Connects to a click handler on the icon.
904 void MainInterface::createSystray()
907 if( QDate::currentDate().dayOfYear() >= 354 )
908 iconVLC = QIcon( QPixmap( ":/vlc128-christmas.png" ) );
910 iconVLC = QIcon( QPixmap( ":/vlc128.png" ) );
911 sysTray = new QSystemTrayIcon( iconVLC, this );
912 sysTray->setToolTip( qtr( "VLC media player" ));
914 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
915 systrayMenu->setIcon( iconVLC );
917 QVLCMenu::updateSystrayMenu( this, p_intf, true );
920 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
921 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
925 * Updates the Systray Icon's menu and toggle the main interface
927 void MainInterface::toggleUpdateSystrayMenu()
929 /* If hidden, show it */
935 else if( isMinimized() )
943 /* Visible (possibly under other windows) */
945 /* check if any visible window is above vlc in the z-order,
946 * but ignore the ones always on top
947 * and the ones which can't be activated */
950 wi.cbSize = sizeof( WINDOWINFO );
951 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
952 hwnd && ( !IsWindowVisible( hwnd ) ||
953 ( GetWindowInfo( hwnd, &wi ) &&
954 (wi.dwExStyle&WS_EX_NOACTIVATE) ) );
955 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
956 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
957 (wi.dwExStyle&WS_EX_TOPMOST) )
969 QVLCMenu::updateSystrayMenu( this, p_intf );
972 void MainInterface::handleSystrayClick(
973 QSystemTrayIcon::ActivationReason reason )
977 case QSystemTrayIcon::Trigger:
978 case QSystemTrayIcon::DoubleClick:
979 toggleUpdateSystrayMenu();
981 case QSystemTrayIcon::MiddleClick:
982 sysTray->showMessage( qtr( "VLC media player" ),
983 qtr( "Control menu for the player" ),
984 QSystemTrayIcon::Information, 3000 );
992 * Updates the name of the systray Icon tooltip.
993 * Doesn't check if the systray exists, check before you call it.
995 void MainInterface::updateSystrayTooltipName( QString name )
999 sysTray->setToolTip( qtr( "VLC media player" ) );
1003 sysTray->setToolTip( name );
1004 if( notificationEnabled && ( isHidden() || isMinimized() ) )
1006 sysTray->showMessage( qtr( "VLC media player" ), name,
1007 QSystemTrayIcon::NoIcon, 3000 );
1011 QVLCMenu::updateSystrayMenu( this, p_intf );
1015 * Updates the status of the systray Icon tooltip.
1016 * Doesn't check if the systray exists, check before you call it.
1018 void MainInterface::updateSystrayTooltipStatus( int i_status )
1025 sysTray->setToolTip( qtr( "VLC media player" ) );
1030 sysTray->setToolTip( input_name );
1035 sysTray->setToolTip( input_name + " - "
1042 /************************************************************************
1044 ************************************************************************/
1045 void MainInterface::dropEvent(QDropEvent *event)
1047 dropEventPlay( event, true );
1050 void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
1052 const QMimeData *mimeData = event->mimeData();
1054 /* D&D of a subtitles file, add it on the fly */
1055 if( mimeData->urls().size() == 1 )
1057 if( THEMIM->getIM()->hasInput() )
1059 if( !input_AddSubtitle( THEMIM->getInput(),
1060 qtu( toNativeSeparators(
1061 mimeData->urls()[0].toLocalFile() ) ),
1064 event->acceptProposedAction();
1069 bool first = b_play;
1070 foreach( const QUrl &url, mimeData->urls() )
1072 QString s = toNativeSeparators( url.toLocalFile() );
1074 if( s.length() > 0 ) {
1075 playlist_Add( THEPL, qtu(s), NULL,
1076 PLAYLIST_APPEND | (first ? PLAYLIST_GO: 0),
1077 PLAYLIST_END, true, false );
1079 RecentsMRL::getInstance( p_intf )->addRecent( s );
1082 event->acceptProposedAction();
1084 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1086 event->acceptProposedAction();
1088 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1090 event->acceptProposedAction();
1092 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1097 /************************************************************************
1099 ************************************************************************/
1100 void MainInterface::customEvent( QEvent *event )
1103 if( event->type() == PLDockEvent_Type )
1105 PlaylistDialog::killInstance();
1106 playlistEmbeddedFlag = true;
1108 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1113 if ( event->type() == (int)SetVideoOnTopEvent_Type )
1115 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1116 if( p_event->OnTop() )
1117 setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
1119 setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint);
1120 show(); /* necessary to apply window flags?? */
1124 void MainInterface::keyPressEvent( QKeyEvent *e )
1126 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() == Qt::Key_H )
1127 && menuBar()->isHidden() )
1129 toggleMinimalView();
1133 int i_vlck = qtEventToVLCKey( e );
1136 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1143 void MainInterface::resizeEvent( QResizeEvent * event )
1147 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
1148 i_visualmode == QT_MINIMAL_MODE )
1150 mainVideoSize = size();
1154 if( VISIBLE( bgWidget) ||
1155 ( videoIsActive && videoWidget->isVisible() )
1157 mainVideoSize = size();
1159 mainBasedSize = size();
1164 void MainInterface::wheelEvent( QWheelEvent *e )
1166 int i_vlckey = qtWheelEventToVLCKey( e );
1167 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1171 void MainInterface::closeEvent( QCloseEvent *e )
1178 void MainInterface::toggleFullScreen( void )
1180 if( isFullScreen() )
1183 emit askUpdate(); // Needed if video was launched after the F11
1184 QVLCMenu::fullscreenViewAction->setChecked( false );
1189 QVLCMenu::fullscreenViewAction->setChecked( true );
1194 /*****************************************************************************
1196 *****************************************************************************/
1197 static int InteractCallback( vlc_object_t *p_this,
1198 const char *psz_var, vlc_value_t old_val,
1199 vlc_value_t new_val, void *param )
1201 intf_dialog_args_t *p_arg = new intf_dialog_args_t;
1202 p_arg->p_dialog = (interaction_dialog_t *)(new_val.p_address);
1203 DialogEvent *event = new DialogEvent( INTF_DIALOG_INTERACTION, 0, p_arg );
1204 QApplication::postEvent( THEDP, event );
1208 /*****************************************************************************
1209 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1210 * We don't show the menu directly here because we don't want the
1211 * caller to block for a too long time.
1212 *****************************************************************************/
1213 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1214 vlc_value_t old_val, vlc_value_t new_val, void *param )
1216 intf_thread_t *p_intf = (intf_thread_t *)param;
1218 if( p_intf->pf_show_dialog )
1220 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1221 new_val.b_bool, NULL );
1227 /*****************************************************************************
1228 * IntfShowCB: callback triggered by the intf-show libvlc variable.
1229 *****************************************************************************/
1230 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1231 vlc_value_t old_val, vlc_value_t new_val, void *param )
1233 intf_thread_t *p_intf = (intf_thread_t *)param;
1234 p_intf->p_sys->p_mi->toggleFSC();