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"
35 #include "util/customwidgets.hpp"
36 #include "util/qt_dirs.hpp"
38 #include "components/interface_widgets.hpp"
39 #include "components/controller.hpp"
40 #include "components/playlist/playlist.hpp"
43 #include "recents.hpp"
45 #include <QCloseEvent>
57 #include <QPushButton>
61 #include <vlc_keys.h> /* Wheel event */
64 /* Callback prototypes */
65 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
66 vlc_value_t old_val, vlc_value_t new_val, void *param );
67 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
68 vlc_value_t old_val, vlc_value_t new_val, void *param );
69 static int InteractCallback( vlc_object_t *, const char *, vlc_value_t,
72 MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
74 /* Variables initialisation */
75 // need_components_update = false;
78 playlistWidget = NULL;
80 videoIsActive = false;
81 playlistVisible = false;
83 fullscreenControls = NULL;
89 * Configuration and settings
90 * Pre-building of interface
93 setFocusPolicy( Qt::StrongFocus );
94 setAcceptDrops( true );
95 setWindowIcon( QApplication::windowIcon() );
96 setWindowOpacity( config_GetFloat( p_intf, "qt-opacity" ) );
98 /* Set The Video In emebedded Mode or not */
99 videoEmbeddedFlag = config_GetInt( p_intf, "embedded-video" );
101 /* Are we in the enhanced always-video mode or not ? */
102 i_visualmode = config_GetInt( p_intf, "qt-display-mode" );
104 /* Set the other interface settings */
105 settings = getSettings();
106 settings->beginGroup( "MainWindow" );
108 /* Visualisation, not really used yet */
109 visualSelectorEnabled = settings->value( "visual-selector", false).toBool();
111 /* Do we want anoying popups or not */
112 notificationEnabled = (bool)config_GetInt( p_intf, "qt-notification" );
114 /**************************
115 * UI and Widgets design
116 **************************/
117 setVLCWindowsTitle();
118 handleMainUi( settings );
121 /* Create a Dock to get the playlist */
122 dockPL = new QDockWidget( qtr( "Playlist" ), this );
123 dockPL->setSizePolicy( QSizePolicy::Preferred,
124 QSizePolicy::Expanding );
125 dockPL->setFeatures( QDockWidget::AllDockWidgetFeatures );
126 dockPL->setAllowedAreas( Qt::LeftDockWidgetArea
127 | Qt::RightDockWidgetArea
128 | Qt::BottomDockWidgetArea );
132 /**************************
133 * Menu Bar and Status Bar
134 **************************/
135 QVLCMenu::createMenuBar( this, p_intf, visualSelectorEnabled );
137 /* StatusBar Creation */
140 /********************
142 ********************/
143 MainInputManager::getInstance( p_intf );
145 /**************************
146 * Various CONNECTs on IM *
147 **************************/
148 /* Connect the input manager to the GUI elements it manages */
151 * Connects on nameChanged()
152 * Those connects are not merged because different options can trigger
155 /* Naming in the controller statusbar */
156 CONNECT( THEMIM->getIM(), nameChanged( QString ),
157 this, setName( QString ) );
158 /* and in the systray */
161 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
162 updateSystrayTooltipName( QString ) );
164 /* and in the title of the controller */
165 if( config_GetInt( p_intf, "qt-name-in-title" ) )
167 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
168 setVLCWindowsTitle( QString ) );
172 * CONNECTS on PLAY_STATUS
174 /* Status on the systray */
177 CONNECT( THEMIM->getIM(), statusChanged( int ),
178 this, updateSystrayTooltipStatus( int ) );
181 /* END CONNECTS ON IM */
187 var_Create( p_intf, "interaction", VLC_VAR_ADDRESS );
188 var_AddCallback( p_intf, "interaction", InteractCallback, this );
189 interaction_Register( p_intf );
191 var_AddCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
193 /* Register callback for the intf-popupmenu variable */
194 var_AddCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
197 /* VideoWidget connects to avoid different threads speaking to each other */
198 connect( this, SIGNAL(askReleaseVideo( void )),
199 this, SLOT(releaseVideoSlot( void )), Qt::BlockingQueuedConnection );
202 CONNECT( this, askVideoToResize( unsigned int, unsigned int ),
203 videoWidget, SetSizing( unsigned int, unsigned int ) );
205 CONNECT( this, askUpdate(), this, doComponentsUpdate() );
207 /* Size and placement of interface */
208 settings->beginGroup( "MainWindow" );
209 QVLCTools::restoreWidgetPosition( settings, this, QSize(380, 60) );
211 bool b_visible = settings->value( "playlist-visible", 0 ).toInt();
212 settings->endGroup();
215 if( b_visible ) togglePlaylist();
217 /* Final sizing and showing */
218 setMinimumWidth( __MAX( controls->sizeHint().width(),
219 menuBar()->sizeHint().width() ) );
222 /* And switch to minimal view if needed
223 Must be called after the show() */
224 if( i_visualmode == QT_MINIMAL_MODE )
227 /* Update the geometry : It is useful if you switch between
230 resize( sizeHint() );
232 /*****************************************************
233 * End everything by creating the Systray Management *
234 *****************************************************/
238 MainInterface::~MainInterface()
240 msg_Dbg( p_intf, "Destroying the main interface" );
242 if( videoIsActive ) videoWidget->hide();
247 QVLCTools::saveWidgetPosition( p_intf, "Playlist", playlistWidget );
249 delete playlistWidget;
252 settings->beginGroup( "MainWindow" );
254 settings->setValue( "pl-dock-status", (int)i_pl_dock );
255 settings->setValue( "playlist-visible", (int)playlistVisible );
256 settings->setValue( "adv-controls",
257 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
260 settings->setValue( "backgroundSize", bgWidget->size() );
262 QVLCTools::saveWidgetPosition(settings, this);
263 settings->endGroup();
265 var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
267 /* Unregister callback for the intf-popupmenu variable */
268 var_DelCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
270 interaction_Unregister( p_intf );
271 var_DelCallback( p_intf, "interaction", InteractCallback, this );
273 p_intf->p_sys->p_mi = NULL;
276 /*****************************
278 *****************************/
280 inline void MainInterface::createStatusBar()
285 /* Widgets Creation*/
286 TimeLabel *timeLabel = new TimeLabel( p_intf );
287 nameLabel = new QLabel;
288 nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
289 | Qt::TextSelectableByKeyboard );
290 SpeedLabel *speedLabel = new SpeedLabel( p_intf, "1.00x" );
292 /* Styling those labels */
293 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
294 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
295 nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
297 /* and adding those */
298 statusBar()->addWidget( nameLabel, 8 );
299 statusBar()->addPermanentWidget( speedLabel, 0 );
300 statusBar()->addPermanentWidget( timeLabel, 0 );
302 /* timeLabel behaviour:
303 - double clicking opens the goto time dialog
304 - right-clicking and clicking just toggle between remaining and
306 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
309 inline void MainInterface::initSystray()
311 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
312 bool b_systrayWanted = config_GetInt( p_intf, "qt-system-tray" );
314 if( config_GetInt( p_intf, "qt-start-minimized") > 0 )
316 if( b_systrayAvailable )
318 b_systrayWanted = true;
322 msg_Err( p_intf, "cannot start minimized without system tray bar" );
325 if( b_systrayAvailable && b_systrayWanted )
330 * Give the decorations of the Main Window a correct Name.
331 * If nothing is given, set it to VLC...
333 void MainInterface::setVLCWindowsTitle( QString aTitle )
335 if( aTitle.isEmpty() )
337 setWindowTitle( qtr( "VLC media player" ) );
341 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
345 void MainInterface::handleMainUi( QSettings *settings )
347 /* Create the main Widget and the mainLayout */
348 QWidget *main = new QWidget;
349 setCentralWidget( main );
350 mainLayout = new QVBoxLayout( main );
352 /* Margins, spacing */
353 main->setContentsMargins( 0, 0, 0, 0 );
354 main->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
355 mainLayout->setSpacing( 0 );
356 mainLayout->setMargin( 0 );
358 /* Create the CONTROLS Widget */
359 controls = new ControlsWidget( p_intf,
360 settings->value( "adv-controls", false ).toBool(), this );
361 CONNECT( controls, advancedControlsToggled( bool ),
362 this, doComponentsUpdate() );
363 inputC = new InputControlsWidget( p_intf, this );
366 /* Disabled for now, they SUCK */
368 visualSelector = new VisualSelector( p_intf );
369 mainLayout->insertWidget( 0, visualSelector );
370 visualSelector->hide();
374 bgWidget = new BackgroundWidget( p_intf );
376 settings->value( "backgroundSize", QSize( 300, 200 ) ).toSize() );
377 bgWidget->updateGeometry();
378 CONNECT( this, askBgWidgetToToggle(), bgWidget, toggle() );
380 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
381 i_visualmode != QT_MINIMAL_MODE )
386 /* And video Outputs */
387 if( videoEmbeddedFlag )
388 videoWidget = new VideoWidget( p_intf );
390 /* Add the controls Widget to the main Widget */
391 mainLayout->insertWidget( 0, bgWidget );
392 if( videoWidget ) mainLayout->insertWidget( 0, videoWidget, 10 );
393 mainLayout->insertWidget( 2, inputC, 0, Qt::AlignBottom );
394 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
395 controls, 0, Qt::AlignBottom );
398 /* Finish the sizing */
399 main->updateGeometry();
401 getSettings()->endGroup();
405 /* Create the FULLSCREEN CONTROLS Widget */
406 if( config_GetInt( p_intf, "qt-fs-controller" ) )
408 fullscreenControls = new FullscreenControllerWidget( p_intf );
412 inline void MainInterface::askForPrivacy()
415 * Ask for the network policy on FIRST STARTUP
417 if( config_GetInt( p_intf, "qt-privacy-ask") )
419 QList<ConfigControl *> controls;
420 if( privacyDialog( &controls ) == QDialog::Accepted )
422 QList<ConfigControl *>::Iterator i;
423 for( i = controls.begin() ; i != controls.end() ; i++ )
425 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
426 c->doApply( p_intf );
429 config_PutInt( p_intf, "qt-privacy-ask" , 0 );
430 /* We have to save here because the user may not launch Prefs */
431 config_SaveConfigFile( p_intf, NULL );
436 int MainInterface::privacyDialog( QList<ConfigControl *> *controls )
438 QDialog *privacy = new QDialog();
440 privacy->setWindowTitle( qtr( "Privacy and Network Policies" ) );
442 QGridLayout *gLayout = new QGridLayout( privacy );
444 QGroupBox *blabla = new QGroupBox( qtr( "Privacy and Network Warning" ) );
445 QGridLayout *blablaLayout = new QGridLayout( blabla );
446 QLabel *text = new QLabel( qtr(
447 "<p>The <i>VideoLAN Team</i> doesn't like when an application goes "
448 "online without authorization.</p>\n "
449 "<p><i>VLC media player</i> can retreive limited information from "
450 "the Internet in order to get CD covers or to check "
451 "for available updates.</p>\n"
452 "<p><i>VLC media player</i> <b>DOES NOT</b> send or collect <b>ANY</b> "
453 "information, even anonymously, about your usage.</p>\n"
454 "<p>Therefore please select from the following options, the default being "
455 "almost no access to the web.</p>\n") );
456 text->setWordWrap( true );
457 text->setTextFormat( Qt::RichText );
459 blablaLayout->addWidget( text, 0, 0 ) ;
461 QGroupBox *options = new QGroupBox;
462 QGridLayout *optionsLayout = new QGridLayout( options );
464 gLayout->addWidget( blabla, 0, 0, 1, 3 );
465 gLayout->addWidget( options, 1, 0, 1, 3 );
466 module_config_t *p_config;
467 ConfigControl *control;
470 #define CONFIG_GENERIC( option, type ) \
471 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
474 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
475 p_config, options, false, optionsLayout, line ); \
476 controls->append( control ); \
479 #define CONFIG_GENERIC_NOBOOL( option, type ) \
480 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
483 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
484 p_config, options, optionsLayout, line ); \
485 controls->append( control ); \
488 CONFIG_GENERIC( "album-art", IntegerList ); line++;
490 CONFIG_GENERIC_NOBOOL( "qt-updates-notif", Bool ); line++;
491 CONFIG_GENERIC_NOBOOL( "qt-updates-days", Integer ); line++;
494 QPushButton *ok = new QPushButton( qtr( "OK" ) );
496 gLayout->addWidget( ok, 2, 2 );
498 CONNECT( ok, clicked(), privacy, accept() );
499 return privacy->exec();
503 /**********************************************************************
504 * Handling of sizing of the components
505 **********************************************************************/
507 /* This function is probably wrong, but we don't have many many choices...
508 Since we can't know from the playlist Widget if we are inside a dock or not,
509 because the playlist Widget can be called by THEDP, as a separate windows for
511 Maybe the other solution is to redefine the sizeHint() of the playlist and
512 ask _parent->isFloating()...
513 If you think this would be better, please FIXME it...
516 QSize MainInterface::sizeHint() const
518 int nwidth = controls->sizeHint().width();
519 int nheight = controls->isVisible() ?
520 controls->size().height()
521 + menuBar()->size().height()
522 + statusBar()->size().height()
525 if( VISIBLE( bgWidget ) )
527 nheight += bgWidget->size().height();
528 nwidth = bgWidget->size().width();
530 else if( videoIsActive && videoWidget->isVisible() )
532 nheight += videoWidget->sizeHint().height();
533 nwidth = videoWidget->sizeHint().width();
536 if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget() )
538 nheight += dockPL->size().height();
539 nwidth = __MAX( nwidth, dockPL->size().width() );
540 msg_Warn( p_intf, "3 %i %i", nheight, nwidth );
543 return QSize( nwidth, nheight );
546 void MainInterface::toggleFSC()
548 if( !fullscreenControls ) return;
550 IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
551 QApplication::postEvent( fullscreenControls, static_cast<QEvent *>(eShow) );
554 void MainInterface::debug()
557 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
558 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
559 if( videoWidget && videoWidget->isVisible() )
561 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
562 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
567 /****************************************************************************
569 ****************************************************************************/
571 /* This event is used to deal with the fullscreen and always on top
572 issue conflict (bug in wx) */
573 class SetVideoOnTopQtEvent : public QEvent
576 SetVideoOnTopQtEvent( bool _onTop ) :
577 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
580 bool OnTop() const { return onTop; }
588 * Thou shall not call/resize/hide widgets from on another thread.
589 * This is wrong, and this is TEH reason to emit signals on those Video Functions
591 void *MainInterface::requestVideo( vout_thread_t *p_nvout, int *pi_x,
592 int *pi_y, unsigned int *pi_width,
593 unsigned int *pi_height )
595 /* Request the videoWidget */
596 void *ret = videoWidget->request( p_nvout,pi_x, pi_y, pi_width, pi_height );
597 if( ret ) /* The videoWidget is available */
599 /* Did we have a bg ? Hide it! */
600 if( VISIBLE( bgWidget) )
603 emit askBgWidgetToToggle();
606 bgWasVisible = false;
608 /* Consider the video active now */
609 videoIsActive = true;
616 /* Call from the WindowClose function */
617 void MainInterface::releaseVideo( void )
619 emit askReleaseVideo( );
622 /* Function that is CONNECTED to the previous emit */
623 void MainInterface::releaseVideoSlot( void )
625 videoWidget->release( );
629 /* Reset the bg state */
630 bgWasVisible = false;
634 videoIsActive = false;
636 /* Try to resize, except when you are in Fullscreen mode */
637 if( !isFullScreen() ) doComponentsUpdate();
640 /* Call from WindowControl function */
641 int MainInterface::controlVideo( void *p_window, int i_query, va_list args )
643 VLC_UNUSED( p_window ); //FIXME remove this param
644 int i_ret = VLC_SUCCESS;
649 unsigned int *pi_width = va_arg( args, unsigned int * );
650 unsigned int *pi_height = va_arg( args, unsigned int * );
651 *pi_width = videoWidget->videoSize.width();
652 *pi_height = videoWidget->videoSize.height();
657 unsigned int i_width = va_arg( args, unsigned int );
658 unsigned int i_height = va_arg( args, unsigned int );
659 emit askVideoToResize( i_width, i_height );
663 case VOUT_SET_STAY_ON_TOP:
665 int i_arg = va_arg( args, int );
666 QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
670 i_ret = VLC_EGENERIC;
671 msg_Warn( p_intf, "unsupported control query" );
677 /*****************************************************************************
678 * Playlist, Visualisation and Menus handling
679 *****************************************************************************/
681 * Toggle the playlist widget or dialog
683 void MainInterface::togglePlaylist()
686 If no playlist exist, then create one and attach it to the DockPL*/
687 if( !playlistWidget )
689 playlistWidget = new PlaylistWidget( p_intf );
691 i_pl_dock = PL_UNDOCKED;
692 /* i_pl_dock = (pl_dock_e)getSettings()
693 ->value( "pl-dock-status", PL_UNDOCKED ).toInt(); */
695 if( i_pl_dock == PL_UNDOCKED )
697 playlistWidget->setWindowFlags( Qt::Window );
699 /* This will restore the geometry but will not work for position,
700 because of parenting */
701 QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
702 playlistWidget, QSize( 600, 300 ) );
706 mainLayout->insertWidget( 4, playlistWidget );
708 playlistVisible = true;
710 playlistWidget->show();
714 /* toggle the visibility of the playlist */
715 TOGGLEV( playlistWidget );
716 playlistVisible = !playlistVisible;
717 //doComponentsUpdate(); //resize( sizeHint() );
721 /* Function called from the menu to undock the playlist */
722 void MainInterface::undockPlaylist()
724 // dockPL->setFloating( true );
728 void MainInterface::dockPlaylist( pl_dock_e i_pos )
732 void MainInterface::toggleMinimalView()
734 /* HACK for minimalView, see menus.cpp */
735 if( !menuBar()->isVisible() ) QVLCMenu::minimalViewAction->toggle();
737 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
738 i_visualmode != QT_MINIMAL_MODE )
739 { /* NORMAL MODE then */
740 if( !videoWidget || videoWidget->isHidden() ) emit askBgWidgetToToggle();
743 /* If video is visible, then toggle the status of bgWidget */
744 bgWasVisible = !bgWasVisible;
748 TOGGLEV( menuBar() );
750 TOGGLEV( statusBar() );
752 doComponentsUpdate();
755 /* Video widget cannot do this synchronously as it runs in another thread */
756 /* Well, could it, actually ? Probably dangerous ... */
758 /* This function is called:
759 - toggling of minimal View
760 - through askUpdate() by Vout thread request video and resize video (zoom)
761 - Advanced buttons toggled
763 void MainInterface::doComponentsUpdate()
765 msg_Dbg( p_intf, "Updating the geometry" );
766 /* Here we resize to sizeHint() and not adjustsize because we want
767 the videoWidget to be exactly the correctSize */
768 resize( sizeHint() );
775 /* toggling advanced controls buttons */
776 void MainInterface::toggleAdvanced()
778 controls->toggleAdvanced();
779 // if( fullscreenControls ) fullscreenControls->toggleAdvanced();
782 /* Get the visibility status of the controls (hidden or not, advanced or not) */
783 int MainInterface::getControlsVisibilityStatus()
785 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
786 + CONTROLS_ADVANCED * controls->b_advancedVisible );
790 void MainInterface::visual()
792 if( !VISIBLE( visualSelector) )
794 visualSelector->show();
795 if( !THEMIM->getIM()->hasVideo() )
797 /* Show the background widget */
799 visualSelectorEnabled = true;
803 /* Stop any currently running visualization */
804 visualSelector->hide();
805 visualSelectorEnabled = false;
807 doComponentsUpdate();
811 /************************************************************************
813 ************************************************************************/
814 void MainInterface::setName( QString name )
816 input_name = name; /* store it for the QSystray use */
817 /* Display it in the status bar, but also as a Tooltip in case it doesn't
819 nameLabel->setText( " " + name + " " );
820 nameLabel->setToolTip( " " + name +" " );
823 /*****************************************************************************
824 * Systray Icon and Systray Menu
825 *****************************************************************************/
828 * Create a SystemTray icon and a menu that would go with it.
829 * Connects to a click handler on the icon.
831 void MainInterface::createSystray()
834 if( QDate::currentDate().dayOfYear() >= 354 )
835 iconVLC = QIcon( QPixmap( ":/vlc128-christmas.png" ) );
837 iconVLC = QIcon( QPixmap( ":/vlc128.png" ) );
838 sysTray = new QSystemTrayIcon( iconVLC, this );
839 sysTray->setToolTip( qtr( "VLC media player" ));
841 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
842 systrayMenu->setIcon( iconVLC );
844 QVLCMenu::updateSystrayMenu( this, p_intf, true );
847 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
848 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
852 * Updates the Systray Icon's menu and toggle the main interface
854 void MainInterface::toggleUpdateSystrayMenu()
856 /* If hidden, show it */
862 else if( isMinimized() )
870 /* Visible (possibly under other windows) */
872 /* check if any visible window is above vlc in the z-order,
873 * but ignore the ones always on top
874 * and the ones which can't be activated */
877 wi.cbSize = sizeof( WINDOWINFO );
878 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
879 hwnd && ( !IsWindowVisible( hwnd ) ||
880 ( GetWindowInfo( hwnd, &wi ) &&
881 (wi.dwExStyle&WS_EX_NOACTIVATE) ) );
882 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
883 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
884 (wi.dwExStyle&WS_EX_TOPMOST) )
896 QVLCMenu::updateSystrayMenu( this, p_intf );
899 void MainInterface::handleSystrayClick(
900 QSystemTrayIcon::ActivationReason reason )
904 case QSystemTrayIcon::Trigger:
905 case QSystemTrayIcon::DoubleClick:
906 toggleUpdateSystrayMenu();
908 case QSystemTrayIcon::MiddleClick:
909 case QSystemTrayIcon::Context:
910 sysTray->showMessage( qtr( "VLC media player" ),
911 qtr( "Control menu for the player" ),
912 QSystemTrayIcon::Information, 3000 );
920 * Updates the name of the systray Icon tooltip.
921 * Doesn't check if the systray exists, check before you call it.
923 void MainInterface::updateSystrayTooltipName( QString name )
927 sysTray->setToolTip( qtr( "VLC media player" ) );
931 sysTray->setToolTip( name );
932 if( notificationEnabled && ( isHidden() || isMinimized() ) )
934 sysTray->showMessage( qtr( "VLC media player" ), name,
935 QSystemTrayIcon::NoIcon, 3000 );
939 QVLCMenu::updateSystrayMenu( this, p_intf );
943 * Updates the status of the systray Icon tooltip.
944 * Doesn't check if the systray exists, check before you call it.
946 void MainInterface::updateSystrayTooltipStatus( int i_status )
953 sysTray->setToolTip( qtr( "VLC media player" ) );
958 sysTray->setToolTip( input_name );
963 sysTray->setToolTip( input_name + " - "
970 /************************************************************************
972 ************************************************************************/
973 void MainInterface::dropEvent(QDropEvent *event)
975 dropEventPlay( event, true );
978 void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
980 const QMimeData *mimeData = event->mimeData();
982 /* D&D of a subtitles file, add it on the fly */
983 if( mimeData->urls().size() == 1 )
985 if( THEMIM->getIM()->hasInput() )
987 if( !input_AddSubtitle( THEMIM->getInput(),
988 qtu( toNativeSeparators(
989 mimeData->urls()[0].toLocalFile() ) ),
992 event->acceptProposedAction();
998 foreach( QUrl url, mimeData->urls() )
1000 QString s = toNativeSeparators( url.toLocalFile() );
1002 if( s.length() > 0 ) {
1003 playlist_Add( THEPL, qtu(s), NULL,
1004 PLAYLIST_APPEND | (first ? PLAYLIST_GO: 0),
1005 PLAYLIST_END, true, false );
1007 RecentsMRL::getInstance( p_intf )->addRecent( s );
1010 event->acceptProposedAction();
1012 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1014 event->acceptProposedAction();
1016 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1018 event->acceptProposedAction();
1020 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1025 /************************************************************************
1027 ************************************************************************/
1028 void MainInterface::customEvent( QEvent *event )
1031 if( event->type() == PLDockEvent_Type )
1033 PlaylistDialog::killInstance();
1034 playlistEmbeddedFlag = true;
1036 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1041 if ( event->type() == (int)SetVideoOnTopEvent_Type )
1043 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1044 if( p_event->OnTop() )
1045 setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
1047 setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint);
1048 show(); /* necessary to apply window flags?? */
1052 void MainInterface::keyPressEvent( QKeyEvent *e )
1054 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() == Qt::Key_H )
1055 && menuBar()->isHidden() )
1057 toggleMinimalView();
1061 int i_vlck = qtEventToVLCKey( e );
1064 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1071 void MainInterface::wheelEvent( QWheelEvent *e )
1073 int i_vlckey = qtWheelEventToVLCKey( e );
1074 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1078 void MainInterface::closeEvent( QCloseEvent *e )
1085 void MainInterface::toggleFullScreen( void )
1087 if( isFullScreen() )
1090 emit askUpdate(); // Needed if video was launched after the F11
1096 /*****************************************************************************
1098 *****************************************************************************/
1099 static int InteractCallback( vlc_object_t *p_this,
1100 const char *psz_var, vlc_value_t old_val,
1101 vlc_value_t new_val, void *param )
1103 intf_dialog_args_t *p_arg = new intf_dialog_args_t;
1104 p_arg->p_dialog = (interaction_dialog_t *)(new_val.p_address);
1105 DialogEvent *event = new DialogEvent( INTF_DIALOG_INTERACTION, 0, p_arg );
1106 QApplication::postEvent( THEDP, static_cast<QEvent*>(event) );
1110 /*****************************************************************************
1111 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1112 * We don't show the menu directly here because we don't want the
1113 * caller to block for a too long time.
1114 *****************************************************************************/
1115 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1116 vlc_value_t old_val, vlc_value_t new_val, void *param )
1118 intf_thread_t *p_intf = (intf_thread_t *)param;
1120 if( p_intf->pf_show_dialog )
1122 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1123 new_val.b_bool, 0 );
1129 /*****************************************************************************
1130 * IntfShowCB: callback triggered by the intf-show libvlc variable.
1131 *****************************************************************************/
1132 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1133 vlc_value_t old_val, vlc_value_t new_val, void *param )
1135 intf_thread_t *p_intf = (intf_thread_t *)param;
1136 p_intf->p_sys->p_mi->toggleFSC();