1 /*****************************************************************************
2 * main_interface.cpp : Main interface
3 ****************************************************************************
4 * Copyright (C) 2006-2010 VideoLAN and AUTHORS
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 Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
32 #include "main_interface.hpp"
33 #include "input_manager.hpp" // Creation
34 #include "actions_manager.hpp" // killInstance
35 #include "extensions_manager.hpp" // killInstance
37 #include "util/customwidgets.hpp" // qtEventToVLCKey, QVLCStackedWidget
38 #include "util/qt_dirs.hpp" // toNativeSeparators
40 #include "components/interface_widgets.hpp" // bgWidget, videoWidget
41 #include "components/controller.hpp" // controllers
42 #include "components/playlist/playlist.hpp" // plWidget
43 #include "dialogs/firstrun.hpp" // First Run
45 #include "menus.hpp" // Menu creation
46 #include "recents.hpp" // RecentItems when DnD
48 #include <QCloseEvent>
59 #include <QStackedWidget>
61 #include <vlc_keys.h> /* Wheel event */
62 #include <vlc_vout_display.h> /* vout_thread_t and VOUT_ events */
66 /* Callback prototypes */
67 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
68 vlc_value_t old_val, vlc_value_t new_val, void *param );
69 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
70 vlc_value_t old_val, vlc_value_t new_val, void *param );
72 MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
74 /* Variables initialisation */
77 playlistWidget = NULL;
78 stackCentralOldWidget= NULL;
82 fullscreenControls = NULL;
87 b_hideAfterCreation = false; // --qt-start-minimized
88 playlistVisible = false;
93 FirstRun::CheckAndRun( this, p_intf );
96 * Configuration and settings
97 * Pre-building of interface
100 setFocusPolicy( Qt::StrongFocus );
101 setAcceptDrops( true );
102 setWindowRole( "vlc-main" );
103 setWindowIcon( QApplication::windowIcon() );
104 setWindowOpacity( var_InheritFloat( p_intf, "qt-opacity" ) );
106 /* Is video in embedded in the UI or not */
107 b_videoEmbedded = var_InheritBool( p_intf, "embedded-video" );
109 /* Does the interface resize to video size or the opposite */
110 b_keep_size = !var_InheritBool( p_intf, "qt-video-autoresize" );
112 /* Are we in the enhanced always-video mode or not ? */
113 i_visualmode = var_InheritInteger( p_intf, "qt-minimal-view" );
115 /* Do we want anoying popups or not */
116 b_notificationEnabled = var_InheritBool( p_intf, "qt-notification" );
118 /* Set the other interface settings */
119 settings = getSettings();
120 settings->beginGroup( "MainWindow" );
123 b_plDocked = getSettings()->value( "pl-dock-status", true ).toBool();
127 * Retrieve saved sizes for main window
128 * mainBasedSize = based window size for normal mode
129 * (no video, no background)
130 * mainVideoSize = window size with video (all modes)
132 mainBasedSize = settings->value( "mainBasedSize", QSize( 350, 120 ) ).toSize();
133 mainVideoSize = settings->value( "mainVideoSize", QSize( 400, 300 ) ).toSize();
134 settings->endGroup( );
141 /**************************
142 * UI and Widgets design
143 **************************/
144 setVLCWindowsTitle();
145 createMainWidget( settings );
150 QVLCMenu::createMenuBar( this, p_intf );
151 CONNECT( THEMIM->getIM(), voutListChanged( vout_thread_t **, int ),
152 this, destroyPopupMenu() );
154 /*********************************
155 * Create the Systray Management *
156 *********************************/
159 /********************
161 ********************/
162 MainInputManager::getInstance( p_intf );
167 taskbar_wmsg = RegisterWindowMessage("TaskbarButtonCreated");
170 /************************************************************
171 * Connect the input manager to the GUI elements it manages *
172 ************************************************************/
174 * Connects on nameChanged()
175 * Those connects are different because options can impeach them to trigger.
177 /* Main Interface statusbar */
178 CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
179 this, setName( const QString& ) );
184 CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
185 this, updateSystrayTooltipName( const QString& ) );
188 /* and title of the Main Interface*/
189 if( var_InheritBool( p_intf, "qt-name-in-title" ) )
191 CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
192 this, setVLCWindowsTitle( const QString& ) );
196 * CONNECTS on PLAY_STATUS
198 /* Status on the systray */
202 CONNECT( THEMIM->getIM(), statusChanged( int ),
203 this, updateSystrayTooltipStatus( int ) );
207 /* END CONNECTS ON IM */
209 /* VideoWidget connects for asynchronous calls */
210 connect( this, SIGNAL(askGetVideo(WId*,int*,int*,unsigned*,unsigned *)),
211 this, SLOT(getVideoSlot(WId*,int*,int*,unsigned*,unsigned*)),
212 Qt::BlockingQueuedConnection );
213 connect( this, SIGNAL(askReleaseVideo( void )),
214 this, SLOT(releaseVideoSlot( void )),
215 Qt::BlockingQueuedConnection );
219 CONNECT( this, askVideoToResize( unsigned int, unsigned int ),
220 videoWidget, SetSizing( unsigned int, unsigned int ) );
221 CONNECT( videoWidget, sizeChanged( int, int ),
222 this, resizeStack( int, int ) );
223 CONNECT( this, askVideoSetFullScreen( bool ),
224 videoWidget, SetFullScreen( bool ) );
225 CONNECT( videoWidget, keyPressed( QKeyEvent * ),
226 this, handleKeyPress( QKeyEvent * ) );
229 CONNECT( THEDP, toolBarConfUpdated(), this, recreateToolbars() );
231 /** END of CONNECTS**/
237 var_AddCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
239 /* Register callback for the intf-popupmenu variable */
240 var_AddCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
242 /**** FINAL SIZING and placement of interface */
243 settings->beginGroup( "MainWindow" );
244 QVLCTools::restoreWidgetPosition( settings, this, QSize(400, 100) );
246 /* resize to previously saved main window size if appicable */
251 resize( mainVideoSize );
253 resize( mainBasedSize );
257 int i_plVis = settings->value( "playlist-visible", false ).toBool();
258 settings->endGroup();
260 if( i_plVis ) togglePlaylist();
262 /* Final sizing and showing */
263 setVisible( !b_hideAfterCreation );
265 setMinimumWidth( __MAX( controls->sizeHint().width(),
266 menuBar()->sizeHint().width() ) + 30 );
268 /* Switch to minimal view if needed, must be called after the show() */
270 toggleMinimalView( true );
273 MainInterface::~MainInterface()
275 /* Unsure we hide the videoWidget before destroying it */
276 if( stackCentralOldWidget == videoWidget )
281 ImageList_Destroy( himl );
283 p_taskbl->vt->Release(p_taskbl);
287 /* Be sure to kill the actionsManager... Only used in the MI and control */
288 ActionsManager::killInstance();
291 ExtensionsManager::killInstance();
293 /* Delete the FSC controller */
294 delete fullscreenControls;
297 settings->beginGroup( "MainWindow" );
299 settings->setValue( "pl-dock-status", b_plDocked );
300 /* Save playlist state */
303 settings->setValue( "playlist-visible",
306 playlistWidget->isVisible() /* FIXME */ );
309 settings->setValue( "adv-controls",
310 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
312 settings->setValue( "mainBasedSize", mainBasedSize );
313 settings->setValue( "mainVideoSize", mainVideoSize );
315 settings->setValue( "backgroundSize", bgWidget->size() );
318 QVLCTools::saveWidgetPosition(settings, this);
320 settings->endGroup();
322 /* Save undocked playlist size */
323 if( playlistWidget && !isPlDocked() )
324 QVLCTools::saveWidgetPosition( p_intf, "Playlist", playlistWidget );
326 delete playlistWidget;
330 /* Unregister callbacks */
331 var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
332 var_DelCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
334 p_intf->p_sys->p_mi = NULL;
337 /*****************************
339 *****************************/
340 void MainInterface::recreateToolbars()
342 bool b_adv = getControlsVisibilityStatus() & CONTROLS_ADVANCED;
344 settings->beginGroup( "MainWindow" );
348 controls = new ControlsWidget( p_intf, b_adv, this );
349 inputC = new InputControlsWidget( p_intf, this );
351 if( fullscreenControls )
353 delete fullscreenControls;
354 fullscreenControls = new FullscreenControllerWidget( p_intf, this );
355 CONNECT( fullscreenControls, keyPressed( QKeyEvent * ),
356 this, handleKeyPress( QKeyEvent * ) );
358 mainLayout->insertWidget( 2, inputC );
359 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
361 settings->endGroup();
364 void MainInterface::createMainWidget( QSettings *settings )
366 /* Create the main Widget and the mainLayout */
367 QWidget *main = new QWidget;
368 setCentralWidget( main );
369 mainLayout = new QVBoxLayout( main );
370 main->setContentsMargins( 0, 0, 0, 0 );
371 mainLayout->setSpacing( 0 ); mainLayout->setMargin( 0 );
374 stackCentralW = new QVLCStackedWidget( main );
377 bgWidget = new BackgroundWidget( p_intf );
378 stackCentralW->addWidget( bgWidget );
380 /* And video Outputs */
381 if( b_videoEmbedded )
383 videoWidget = new VideoWidget( p_intf );
384 stackCentralW->addWidget( videoWidget );
386 mainLayout->insertWidget( 1, stackCentralW );
388 settings->beginGroup( "MainWindow" );
390 /* Create the CONTROLS Widget */
391 controls = new ControlsWidget( p_intf,
392 settings->value( "adv-controls", false ).toBool(), this );
393 inputC = new InputControlsWidget( p_intf, this );
395 mainLayout->insertWidget( 2, inputC );
396 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
399 /* Visualisation, disabled for now, they SUCK */
401 visualSelector = new VisualSelector( p_intf );
402 mainLayout->insertWidget( 0, visualSelector );
403 visualSelector->hide();
406 settings->endGroup();
408 /* Enable the popup menu in the MI */
409 main->setContextMenuPolicy( Qt::CustomContextMenu );
410 CONNECT( main, customContextMenuRequested( const QPoint& ),
411 this, popupMenu( const QPoint& ) );
413 if ( depth() > 8 ) /* 8bit depth has too many issues with opacity */
414 /* Create the FULLSCREEN CONTROLS Widget */
415 if( var_InheritBool( p_intf, "qt-fs-controller" ) )
417 fullscreenControls = new FullscreenControllerWidget( p_intf, this );
418 CONNECT( fullscreenControls, keyPressed( QKeyEvent * ),
419 this, handleKeyPress( QKeyEvent * ) );
423 inline void MainInterface::initSystray()
426 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
427 bool b_systrayWanted = var_InheritBool( p_intf, "qt-system-tray" );
429 if( var_InheritBool( p_intf, "qt-start-minimized") )
431 if( b_systrayAvailable )
433 b_systrayWanted = true;
434 b_hideAfterCreation = true;
437 msg_Err( p_intf, "cannot start minimized without system tray bar" );
440 if( b_systrayAvailable && b_systrayWanted )
445 inline void MainInterface::createStatusBar()
450 /* Widgets Creation*/
451 QStatusBar *statusBarr = statusBar();
453 TimeLabel *timeLabel = new TimeLabel( p_intf );
454 nameLabel = new QLabel( this );
455 nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
456 | Qt::TextSelectableByKeyboard );
457 SpeedLabel *speedLabel = new SpeedLabel( p_intf, this );
459 /* Styling those labels */
460 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
461 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
462 nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
463 timeLabel->setStyleSheet(
464 "QLabel:hover { background-color: rgba(255, 255, 255, 50%) }" );
465 speedLabel->setStyleSheet(
466 "QLabel:hover { background-color: rgba(255, 255, 255, 50%) }" );
468 /* and adding those */
469 statusBarr->addWidget( nameLabel, 8 );
470 statusBarr->addPermanentWidget( speedLabel, 0 );
471 statusBarr->addPermanentWidget( timeLabel, 0 );
473 /* timeLabel behaviour:
474 - double clicking opens the goto time dialog
475 - right-clicking and clicking just toggle between remaining and
477 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
479 CONNECT( THEMIM->getIM(), encryptionChanged( bool ),
480 this, showCryptedLabel( bool ) );
482 CONNECT( THEMIM->getIM(), seekRequested( float ),
483 timeLabel, setDisplayPosition( float ) );
486 /**********************************************************************
487 * Handling of sizing of the components
488 **********************************************************************/
490 void MainInterface::debug()
493 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
494 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
495 msg_Dbg( p_intf, "minimumsize: %i - %i", minimumSize().height(), minimumSize().width() );
497 msg_Dbg( p_intf, "Stack size: %i - %i", stackCentralW->size().height(), stackCentralW->size().width() );
498 msg_Dbg( p_intf, "Stack sizeHint: %i - %i", stackCentralW->sizeHint().height(), stackCentralW->sizeHint().width() );
499 msg_Dbg( p_intf, "Central size: %i - %i", centralWidget()->size().height(), centralWidget()->size().width() );
503 inline void MainInterface::showVideo() { showTab( videoWidget ); }
504 inline void MainInterface::showBg() { showTab( bgWidget ); }
506 inline void MainInterface::showTab( QWidget *widget )
509 msg_Warn( p_intf, "Old stackCentralOldWidget %i", stackCentralW->indexOf( stackCentralOldWidget ) );
511 stackCentralOldWidget = stackCentralW->currentWidget();
512 stackCentralW->setCurrentWidget( widget );
515 msg_Warn( p_intf, "State change %i", stackCentralW->currentIndex() );
516 msg_Warn( p_intf, "New stackCentralOldWidget %i", stackCentralW->indexOf( stackCentralOldWidget ) );
520 inline void MainInterface::restoreStackOldWidget()
523 msg_Warn( p_intf, "New stackCentralOldWidget %i", stackCentralW->indexOf( stackCentralOldWidget ) );
525 QWidget *wTemp = stackCentralW->currentWidget();
527 stackCentralW->setCurrentWidget( stackCentralOldWidget );
529 stackCentralOldWidget = wTemp;
531 msg_Warn( p_intf, "Debug %i %i",stackCentralW->indexOf( wTemp ), stackCentralW->indexOf( stackCentralW->currentWidget() ) );
535 void MainInterface::destroyPopupMenu()
537 QVLCMenu::PopupMenu( p_intf, false );
540 void MainInterface::popupMenu( const QPoint &p )
542 QVLCMenu::PopupMenu( p_intf, true );
545 void MainInterface::toggleFSC()
547 if( !fullscreenControls ) return;
549 IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
550 QApplication::postEvent( fullscreenControls, eShow );
553 /****************************************************************************
555 ****************************************************************************/
557 /* This event is used to deal with the fullscreen and always on top
558 issue conflict (bug in wx) */
559 class SetVideoOnTopQtEvent : public QEvent
562 SetVideoOnTopQtEvent( bool _onTop ) :
563 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
566 bool OnTop() const { return onTop; }
574 * You must not change the state of this object or other Qt4 UI objects,
575 * from the video output thread - only from the Qt4 UI main loop thread.
576 * All window provider queries must be handled through signals or events.
577 * That's why we have all those emit statements...
579 WId MainInterface::getVideo( int *pi_x, int *pi_y,
580 unsigned int *pi_width, unsigned int *pi_height )
585 /* This is a blocking call signal. Results are returned through pointers.
586 * Beware of deadlocks! */
588 emit askGetVideo( &id, pi_x, pi_y, pi_width, pi_height );
592 void MainInterface::getVideoSlot( WId *p_id, int *pi_x, int *pi_y,
593 unsigned *pi_width, unsigned *pi_height )
595 /* Request the videoWidget */
596 WId ret = videoWidget->request( pi_x, pi_y,
597 pi_width, pi_height, b_keep_size );
599 if( ret ) /* The videoWidget is available */
601 /* Ask videoWidget to resize correctly, if we are in normal mode */
602 if( !isFullScreen() && !isMaximized() )
603 videoWidget->SetSizing( *pi_width, *pi_height );
605 /* Consider the video active now */
610 /* Asynchronous call from the WindowClose function */
611 void MainInterface::releaseVideo( void )
613 emit askReleaseVideo();
616 /* Function that is CONNECTED to the previous emit */
617 void MainInterface::releaseVideoSlot( void )
619 videoWidget->release();
621 if( stackCentralW->currentWidget() == videoWidget )
622 restoreStackOldWidget();
624 /* We don't want to have a blank video to popup */
625 stackCentralOldWidget = bgWidget;
628 /* Asynchronous call from WindowControl function */
629 int MainInterface::controlVideo( int i_query, va_list args )
633 case VOUT_WINDOW_SET_SIZE:
635 unsigned int i_width = va_arg( args, unsigned int );
636 unsigned int i_height = va_arg( args, unsigned int );
637 if( isFullScreen() || isMaximized() )
639 emit askVideoToResize( i_width, i_height );
642 case VOUT_WINDOW_SET_STATE:
644 unsigned i_arg = va_arg( args, unsigned );
645 unsigned on_top = i_arg & VOUT_WINDOW_STATE_ABOVE;
646 QApplication::postEvent( this, new SetVideoOnTopQtEvent( on_top ) );
649 case VOUT_WINDOW_SET_FULLSCREEN:
651 bool b_fs = va_arg( args, int );
652 emit askVideoSetFullScreen( b_fs );
656 msg_Warn( p_intf, "unsupported control query" );
661 /*****************************************************************************
662 * Playlist, Visualisation and Menus handling
663 *****************************************************************************/
665 * Toggle the playlist widget or dialog
667 void MainInterface::createPlaylist()
669 playlistWidget = new PlaylistWidget( p_intf, this );
673 playlistWidget->setWindowFlags( Qt::Window );
675 /* This will restore the geometry but will not work for position,
676 because of parenting */
677 QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
678 playlistWidget, QSize( 600, 300 ) );
682 stackCentralW->addWidget( playlistWidget );
686 void MainInterface::togglePlaylist()
688 if( !playlistWidget )
693 /* Playlist is not visible, show it */
694 if( stackCentralW->currentWidget() != playlistWidget )
696 showTab( playlistWidget );
700 restoreStackOldWidget();
702 playlistVisible = ( stackCentralW->currentWidget() == playlistWidget );
706 playlistWidget->setWindowFlags( Qt::Window );
707 playlistVisible = !playlistVisible;
708 playlistWidget->setVisible( playlistVisible );
713 void MainInterface::dockPlaylist( bool p_docked )
715 if( b_plDocked == p_docked ) return;
716 b_plDocked = p_docked;
718 if( !playlistWidget ) return; /* Playlist wasn't created yet */
721 stackCentralW->removeWidget( playlistWidget );
722 playlistWidget->setWindowFlags( Qt::Window );
723 QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
724 playlistWidget, QSize( 600, 300 ) );
725 playlistWidget->show();
726 restoreStackOldWidget();
730 QVLCTools::saveWidgetPosition( p_intf, "Playlist", playlistWidget );
731 playlistWidget->setWindowFlags( Qt::Widget ); // Probably a Qt bug here
732 // It would be logical that QStackWidget::addWidget reset the flags...
733 stackCentralW->addWidget( playlistWidget );
734 showTab( playlistWidget );
736 playlistVisible = true;
740 If b_switch is false, then we are normalView
742 void MainInterface::toggleMinimalView( bool b_switch )
744 if( i_visualmode == 0 )
746 if( stackCentralW->currentWidget() == bgWidget )
748 if( stackCentralW->height() < 16 )
750 resizeStack( stackCentralW->width(), 100 );
755 menuBar()->setVisible( !b_switch );
756 controls->setVisible( !b_switch );
757 statusBar()->setVisible( !b_switch );
758 inputC->setVisible( !b_switch );
760 emit minimalViewToggled( b_switch );
763 /* toggling advanced controls buttons */
764 void MainInterface::toggleAdvancedButtons()
766 controls->toggleAdvanced();
767 // if( fullscreenControls ) fullscreenControls->toggleAdvanced();
770 /* Get the visibility status of the controls (hidden or not, advanced or not) */
771 int MainInterface::getControlsVisibilityStatus()
773 if( !controls ) return 0;
774 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
775 + CONTROLS_ADVANCED * controls->b_advancedVisible );
779 void MainInterface::visual()
781 if( !VISIBLE( visualSelector) )
783 visualSelector->show();
784 if( !THEMIM->getIM()->hasVideo() )
786 /* Show the background widget */
788 visualSelectorEnabled = true;
792 /* Stop any currently running visualization */
793 visualSelector->hide();
794 visualSelectorEnabled = false;
799 /************************************************************************
801 ************************************************************************/
802 void MainInterface::setName( const QString& name )
804 input_name = name; /* store it for the QSystray use */
805 /* Display it in the status bar, but also as a Tooltip in case it doesn't
807 nameLabel->setText( " " + name + " " );
808 nameLabel->setToolTip( " " + name +" " );
812 * Give the decorations of the Main Window a correct Name.
813 * If nothing is given, set it to VLC...
815 void MainInterface::setVLCWindowsTitle( const QString& aTitle )
817 if( aTitle.isEmpty() )
819 setWindowTitle( qtr( "VLC media player" ) );
823 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
827 void MainInterface::showCryptedLabel( bool b_show )
829 if( cryptedLabel == NULL )
831 cryptedLabel = new QLabel;
832 // The lock icon is not the right one for DRM protection/scrambled.
833 //cryptedLabel->setPixmap( QPixmap( ":/lock" ) );
834 cryptedLabel->setText( "DRM" );
835 statusBar()->addWidget( cryptedLabel );
838 cryptedLabel->setVisible( b_show );
841 void MainInterface::showBuffering( float f_cache )
843 QString amount = QString("Buffering: %1%").arg( (int)(100*f_cache) );
844 statusBar()->showMessage( amount, 1000 );
847 /*****************************************************************************
848 * Systray Icon and Systray Menu
849 *****************************************************************************/
852 * Create a SystemTray icon and a menu that would go with it.
853 * Connects to a click handler on the icon.
855 void MainInterface::createSystray()
858 if( QDate::currentDate().dayOfYear() >= 354 )
859 iconVLC = QIcon( ":/logo/vlc128-christmas.png" );
861 iconVLC = QIcon( ":/logo/vlc128.png" );
862 sysTray = new QSystemTrayIcon( iconVLC, this );
863 sysTray->setToolTip( qtr( "VLC media player" ));
865 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
866 systrayMenu->setIcon( iconVLC );
868 QVLCMenu::updateSystrayMenu( this, p_intf, true );
871 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
872 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
876 * Updates the Systray Icon's menu and toggle the main interface
878 void MainInterface::toggleUpdateSystrayMenu()
880 /* If hidden, show it */
886 else if( isMinimized() )
894 /* Visible (possibly under other windows) */
896 /* check if any visible window is above vlc in the z-order,
897 * but ignore the ones always on top
898 * and the ones which can't be activated */
901 wi.cbSize = sizeof( WINDOWINFO );
902 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
903 hwnd && ( !IsWindowVisible( hwnd ) ||
904 ( GetWindowInfo( hwnd, &wi ) &&
905 (wi.dwExStyle&WS_EX_NOACTIVATE) ) );
906 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
907 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
908 (wi.dwExStyle&WS_EX_TOPMOST) )
920 QVLCMenu::updateSystrayMenu( this, p_intf );
923 void MainInterface::handleSystrayClick(
924 QSystemTrayIcon::ActivationReason reason )
928 case QSystemTrayIcon::Trigger:
929 case QSystemTrayIcon::DoubleClick:
930 toggleUpdateSystrayMenu();
932 case QSystemTrayIcon::MiddleClick:
933 sysTray->showMessage( qtr( "VLC media player" ),
934 qtr( "Control menu for the player" ),
935 QSystemTrayIcon::Information, 3000 );
943 * Updates the name of the systray Icon tooltip.
944 * Doesn't check if the systray exists, check before you call it.
946 void MainInterface::updateSystrayTooltipName( const QString& name )
950 sysTray->setToolTip( qtr( "VLC media player" ) );
954 sysTray->setToolTip( name );
955 if( b_notificationEnabled && ( isHidden() || isMinimized() ) )
957 sysTray->showMessage( qtr( "VLC media player" ), name,
958 QSystemTrayIcon::NoIcon, 3000 );
962 QVLCMenu::updateSystrayMenu( this, p_intf );
966 * Updates the status of the systray Icon tooltip.
967 * Doesn't check if the systray exists, check before you call it.
969 void MainInterface::updateSystrayTooltipStatus( int i_status )
974 sysTray->setToolTip( input_name );
977 sysTray->setToolTip( input_name + " - " + qtr( "Paused") );
980 sysTray->setToolTip( qtr( "VLC media player" ) );
983 QVLCMenu::updateSystrayMenu( this, p_intf );
987 /************************************************************************
989 ************************************************************************/
990 void MainInterface::dropEvent(QDropEvent *event)
992 dropEventPlay( event, true );
995 void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
997 event->setDropAction( Qt::CopyAction );
998 if( !event->possibleActions() & Qt::CopyAction )
1001 const QMimeData *mimeData = event->mimeData();
1003 /* D&D of a subtitles file, add it on the fly */
1004 if( mimeData->urls().size() == 1 && THEMIM->getIM()->hasInput() )
1006 if( !input_AddSubtitle( THEMIM->getInput(),
1007 qtu( toNativeSeparators( mimeData->urls()[0].toLocalFile() ) ),
1015 bool first = b_play;
1016 foreach( const QUrl &url, mimeData->urls() )
1018 QString s = toNativeSeparators( url.toLocalFile() );
1020 if( s.length() > 0 ) {
1021 char* psz_uri = make_URI( qtu(s) );
1022 playlist_Add( THEPL, psz_uri, NULL,
1023 PLAYLIST_APPEND | (first ? PLAYLIST_GO: PLAYLIST_PREPARSE),
1024 PLAYLIST_END, true, pl_Unlocked );
1027 RecentsMRL::getInstance( p_intf )->addRecent( s );
1032 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1034 event->acceptProposedAction();
1036 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1038 event->acceptProposedAction();
1040 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1045 /************************************************************************
1047 ************************************************************************/
1048 void MainInterface::customEvent( QEvent *event )
1050 if ( event->type() == (int)SetVideoOnTopEvent_Type )
1052 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1053 if( p_event->OnTop() )
1054 setWindowFlags( windowFlags() | Qt::WindowStaysOnTopHint );
1056 setWindowFlags( windowFlags() & ~Qt::WindowStaysOnTopHint );
1057 show(); /* necessary to apply window flags */
1061 void MainInterface::keyPressEvent( QKeyEvent *e )
1063 handleKeyPress( e );
1066 void MainInterface::handleKeyPress( QKeyEvent *e )
1068 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() == Qt::Key_H )
1069 && !menuBar()->isVisible() )
1071 toggleMinimalView( false );
1075 int i_vlck = qtEventToVLCKey( e );
1078 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1085 void MainInterface::wheelEvent( QWheelEvent *e )
1087 int i_vlckey = qtWheelEventToVLCKey( e );
1088 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1092 void MainInterface::closeEvent( QCloseEvent *e )
1099 void MainInterface::toggleFullScreen()
1101 if( isFullScreen() )
1104 emit fullscreenInterfaceToggled( false );
1109 emit fullscreenInterfaceToggled( true );
1113 /*****************************************************************************
1114 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1115 * We don't show the menu directly here because we don't want the
1116 * caller to block for a too long time.
1117 *****************************************************************************/
1118 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1119 vlc_value_t old_val, vlc_value_t new_val, void *param )
1121 intf_thread_t *p_intf = (intf_thread_t *)param;
1123 if( p_intf->pf_show_dialog )
1125 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1126 new_val.b_bool, NULL );
1132 /*****************************************************************************
1133 * IntfShowCB: callback triggered by the intf-show libvlc variable.
1134 *****************************************************************************/
1135 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1136 vlc_value_t old_val, vlc_value_t new_val, void *param )
1138 intf_thread_t *p_intf = (intf_thread_t *)param;
1139 p_intf->p_sys->p_mi->toggleFSC();