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();
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" );
298 settings->setValue( "pl-dock-status", b_plDocked );
299 /* Save playlist state */
304 QVLCTools::saveWidgetPosition( p_intf, "Playlist", playlistWidget );
305 settings->setValue( "playlist-visible", playlistVisible );
309 settings->setValue( "playlist-visible", playlistWidget->isVisible() ); // FIXME
312 delete playlistWidget;
315 settings->setValue( "adv-controls",
316 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
318 settings->setValue( "mainBasedSize", mainBasedSize );
319 settings->setValue( "mainVideoSize", mainVideoSize );
321 settings->setValue( "backgroundSize", bgWidget->size() );
324 QVLCTools::saveWidgetPosition(settings, this);
325 settings->endGroup();
329 /* Unregister callbacks */
330 var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
331 var_DelCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
333 p_intf->p_sys->p_mi = NULL;
336 /*****************************
338 *****************************/
339 void MainInterface::recreateToolbars()
341 // FIXME: do the same for the FSC
342 settings->beginGroup( "MainWindow" );
346 controls = new ControlsWidget( p_intf, false, this ); /* FIXME */
347 inputC = new InputControlsWidget( p_intf, this );
349 mainLayout->insertWidget( 2, inputC );
350 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
352 settings->endGroup();
355 void MainInterface::createMainWidget( QSettings *settings )
357 /* Create the main Widget and the mainLayout */
358 QWidget *main = new QWidget;
359 setCentralWidget( main );
360 mainLayout = new QVBoxLayout( main );
361 main->setContentsMargins( 0, 0, 0, 0 );
362 mainLayout->setSpacing( 0 ); mainLayout->setMargin( 0 );
365 stackCentralW = new QVLCStackedWidget( main );
368 bgWidget = new BackgroundWidget( p_intf );
369 stackCentralW->addWidget( bgWidget );
371 /* And video Outputs */
372 if( b_videoEmbedded )
374 videoWidget = new VideoWidget( p_intf );
375 stackCentralW->addWidget( videoWidget );
377 mainLayout->insertWidget( 1, stackCentralW );
379 /* Create the CONTROLS Widget */
380 controls = new ControlsWidget( p_intf,
381 settings->value( "adv-controls", false ).toBool(), this );
382 inputC = new InputControlsWidget( p_intf, this );
384 mainLayout->insertWidget( 2, inputC );
385 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
388 /* Visualisation, disabled for now, they SUCK */
390 visualSelector = new VisualSelector( p_intf );
391 mainLayout->insertWidget( 0, visualSelector );
392 visualSelector->hide();
395 getSettings()->endGroup();
397 /* Enable the popup menu in the MI */
398 main->setContextMenuPolicy( Qt::CustomContextMenu );
399 CONNECT( main, customContextMenuRequested( const QPoint& ),
400 this, popupMenu( const QPoint& ) );
402 if ( depth() > 8 ) /* 8bit depth has too many issues with opacity */
403 /* Create the FULLSCREEN CONTROLS Widget */
404 if( var_InheritBool( p_intf, "qt-fs-controller" ) )
406 fullscreenControls = new FullscreenControllerWidget( p_intf, this );
407 CONNECT( fullscreenControls, keyPressed( QKeyEvent * ),
408 this, handleKeyPress( QKeyEvent * ) );
412 inline void MainInterface::initSystray()
415 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
416 bool b_systrayWanted = var_InheritBool( p_intf, "qt-system-tray" );
418 if( var_InheritBool( p_intf, "qt-start-minimized") )
420 if( b_systrayAvailable )
422 b_systrayWanted = true;
423 b_hideAfterCreation = true;
426 msg_Err( p_intf, "cannot start minimized without system tray bar" );
429 if( b_systrayAvailable && b_systrayWanted )
434 inline void MainInterface::createStatusBar()
439 /* Widgets Creation*/
440 QStatusBar *statusBarr = statusBar();
442 TimeLabel *timeLabel = new TimeLabel( p_intf );
443 nameLabel = new QLabel( this );
444 nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
445 | Qt::TextSelectableByKeyboard );
446 SpeedLabel *speedLabel = new SpeedLabel( p_intf, this );
448 /* Styling those labels */
449 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
450 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
451 nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
452 timeLabel->setStyleSheet(
453 "QLabel:hover { background-color: rgba(255, 255, 255, 50%) }" );
454 speedLabel->setStyleSheet(
455 "QLabel:hover { background-color: rgba(255, 255, 255, 50%) }" );
457 /* and adding those */
458 statusBarr->addWidget( nameLabel, 8 );
459 statusBarr->addPermanentWidget( speedLabel, 0 );
460 statusBarr->addPermanentWidget( timeLabel, 0 );
462 /* timeLabel behaviour:
463 - double clicking opens the goto time dialog
464 - right-clicking and clicking just toggle between remaining and
466 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
468 CONNECT( THEMIM->getIM(), encryptionChanged( bool ),
469 this, showCryptedLabel( bool ) );
471 CONNECT( THEMIM->getIM(), seekRequested( float ),
472 timeLabel, setDisplayPosition( float ) );
475 /**********************************************************************
476 * Handling of sizing of the components
477 **********************************************************************/
479 void MainInterface::debug()
482 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
483 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
484 msg_Dbg( p_intf, "minimumsize: %i - %i", minimumSize().height(), minimumSize().width() );
486 msg_Dbg( p_intf, "Stack size: %i - %i", stackCentralW->size().height(), stackCentralW->size().width() );
487 msg_Dbg( p_intf, "Stack sizeHint: %i - %i", stackCentralW->sizeHint().height(), stackCentralW->sizeHint().width() );
488 msg_Dbg( p_intf, "Central size: %i - %i", centralWidget()->size().height(), centralWidget()->size().width() );
492 inline void MainInterface::showVideo() { showTab( videoWidget ); }
493 inline void MainInterface::showBg() { showTab( bgWidget ); }
495 inline void MainInterface::showTab( QWidget *widget )
498 msg_Warn( p_intf, "Old stackCentralOldWidget %i", stackCentralW->indexOf( stackCentralOldWidget ) );
500 stackCentralOldWidget = stackCentralW->currentWidget();
501 stackCentralW->setCurrentWidget( widget );
504 msg_Warn( p_intf, "State change %i", stackCentralW->currentIndex() );
505 msg_Warn( p_intf, "New stackCentralOldWidget %i", stackCentralW->indexOf( stackCentralOldWidget ) );
509 inline void MainInterface::restoreStackOldWidget()
512 msg_Warn( p_intf, "New stackCentralOldWidget %i", stackCentralW->indexOf( stackCentralOldWidget ) );
514 QWidget *wTemp = stackCentralW->currentWidget();
516 stackCentralW->setCurrentWidget( stackCentralOldWidget );
518 stackCentralOldWidget = wTemp;
520 msg_Warn( p_intf, "Debug %i %i",stackCentralW->indexOf( wTemp ), stackCentralW->indexOf( stackCentralW->currentWidget() ) );
524 void MainInterface::destroyPopupMenu()
526 QVLCMenu::PopupMenu( p_intf, false );
529 void MainInterface::popupMenu( const QPoint &p )
531 QVLCMenu::PopupMenu( p_intf, true );
534 void MainInterface::toggleFSC()
536 if( !fullscreenControls ) return;
538 IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
539 QApplication::postEvent( fullscreenControls, eShow );
542 /****************************************************************************
544 ****************************************************************************/
546 /* This event is used to deal with the fullscreen and always on top
547 issue conflict (bug in wx) */
548 class SetVideoOnTopQtEvent : public QEvent
551 SetVideoOnTopQtEvent( bool _onTop ) :
552 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
555 bool OnTop() const { return onTop; }
563 * You must not change the state of this object or other Qt4 UI objects,
564 * from the video output thread - only from the Qt4 UI main loop thread.
565 * All window provider queries must be handled through signals or events.
566 * That's why we have all those emit statements...
568 WId MainInterface::getVideo( int *pi_x, int *pi_y,
569 unsigned int *pi_width, unsigned int *pi_height )
574 /* This is a blocking call signal. Results are returned through pointers.
575 * Beware of deadlocks! */
577 emit askGetVideo( &id, pi_x, pi_y, pi_width, pi_height );
581 void MainInterface::getVideoSlot( WId *p_id, int *pi_x, int *pi_y,
582 unsigned *pi_width, unsigned *pi_height )
584 /* Request the videoWidget */
585 WId ret = videoWidget->request( pi_x, pi_y,
586 pi_width, pi_height, b_keep_size );
588 if( ret ) /* The videoWidget is available */
590 /* ask videoWidget to show */
591 videoWidget->SetSizing( *pi_width, *pi_height );
593 /* Consider the video active now */
598 /* Asynchronous call from the WindowClose function */
599 void MainInterface::releaseVideo( void )
601 emit askReleaseVideo();
604 /* Function that is CONNECTED to the previous emit */
605 void MainInterface::releaseVideoSlot( void )
607 videoWidget->release();
609 restoreStackOldWidget();
611 /* We don't want to have a blank video to popup */
612 stackCentralOldWidget = bgWidget;
615 /* Asynchronous call from WindowControl function */
616 int MainInterface::controlVideo( int i_query, va_list args )
620 case VOUT_WINDOW_SET_SIZE:
622 unsigned int i_width = va_arg( args, unsigned int );
623 unsigned int i_height = va_arg( args, unsigned int );
624 emit askVideoToResize( i_width, i_height );
627 case VOUT_WINDOW_SET_STATE:
629 unsigned i_arg = va_arg( args, unsigned );
630 unsigned on_top = i_arg & VOUT_WINDOW_STATE_ABOVE;
631 QApplication::postEvent( this, new SetVideoOnTopQtEvent( on_top ) );
634 case VOUT_WINDOW_SET_FULLSCREEN:
636 bool b_fs = va_arg( args, int );
637 emit askVideoSetFullScreen( b_fs );
641 msg_Warn( p_intf, "unsupported control query" );
646 /*****************************************************************************
647 * Playlist, Visualisation and Menus handling
648 *****************************************************************************/
650 * Toggle the playlist widget or dialog
652 void MainInterface::createPlaylist()
654 playlistWidget = new PlaylistWidget( p_intf, this );
658 playlistWidget->setWindowFlags( Qt::Window );
660 /* This will restore the geometry but will not work for position,
661 because of parenting */
662 QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
663 playlistWidget, QSize( 600, 300 ) );
667 stackCentralW->addWidget( playlistWidget );
671 void MainInterface::togglePlaylist()
673 if( !playlistWidget )
678 /* Playlist is not visible, show it */
679 if( stackCentralW->currentWidget() != playlistWidget )
681 showTab( playlistWidget );
685 restoreStackOldWidget();
687 playlistVisible = ( stackCentralW->currentWidget() == playlistWidget );
691 playlistWidget->setWindowFlags( Qt::Window );
692 playlistVisible = !playlistVisible;
693 playlistWidget->setVisible( playlistVisible );
698 void MainInterface::dockPlaylist( bool p_docked )
700 if( b_plDocked == p_docked ) return;
701 b_plDocked = p_docked;
703 if( !playlistWidget ) return; /* Playlist wasn't created yet */
706 stackCentralW->removeWidget( playlistWidget );
707 playlistWidget->setWindowFlags( Qt::Window );
708 QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
709 playlistWidget, QSize( 600, 300 ) );
710 playlistWidget->show();
711 restoreStackOldWidget();
715 playlistWidget->setWindowFlags( Qt::Widget ); // Probably a Qt bug here
716 // It would be logical that QStackWidget::addWidget reset the flags...
717 stackCentralW->addWidget( playlistWidget );
718 stackCentralW->setCurrentWidget( playlistWidget );
723 If b_switch is false, then we are normalView
725 void MainInterface::toggleMinimalView( bool b_switch )
727 if( i_visualmode == 0 )
728 { /* NORMAL MODE then */
729 if( !videoWidget || stackCentralW->currentWidget() != videoWidget )
735 /* If video is visible, then toggle the status of bgWidget */
737 //bgWasVisible = !bgWasVisible;
738 /* if( stackCentralOldState == BACK G_TAB )
739 stackCentralOldState = HID DEN_TAB;
741 stackCentralOldState = BACK G_TAB;
747 menuBar()->setVisible( !b_switch );
748 controls->setVisible( !b_switch );
749 statusBar()->setVisible( !b_switch );
750 inputC->setVisible( !b_switch );
752 emit minimalViewToggled( b_switch );
755 /* toggling advanced controls buttons */
756 void MainInterface::toggleAdvancedButtons()
758 controls->toggleAdvanced();
759 // if( fullscreenControls ) fullscreenControls->toggleAdvanced();
762 /* Get the visibility status of the controls (hidden or not, advanced or not) */
763 int MainInterface::getControlsVisibilityStatus()
765 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
766 + CONTROLS_ADVANCED * controls->b_advancedVisible );
770 void MainInterface::visual()
772 if( !VISIBLE( visualSelector) )
774 visualSelector->show();
775 if( !THEMIM->getIM()->hasVideo() )
777 /* Show the background widget */
779 visualSelectorEnabled = true;
783 /* Stop any currently running visualization */
784 visualSelector->hide();
785 visualSelectorEnabled = false;
790 /************************************************************************
792 ************************************************************************/
793 void MainInterface::setName( const QString& name )
795 input_name = name; /* store it for the QSystray use */
796 /* Display it in the status bar, but also as a Tooltip in case it doesn't
798 nameLabel->setText( " " + name + " " );
799 nameLabel->setToolTip( " " + name +" " );
803 * Give the decorations of the Main Window a correct Name.
804 * If nothing is given, set it to VLC...
806 void MainInterface::setVLCWindowsTitle( const QString& aTitle )
808 if( aTitle.isEmpty() )
810 setWindowTitle( qtr( "VLC media player" ) );
814 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
818 void MainInterface::showCryptedLabel( bool b_show )
820 if( cryptedLabel == NULL )
822 cryptedLabel = new QLabel;
823 // The lock icon is not the right one for DRM protection/scrambled.
824 //cryptedLabel->setPixmap( QPixmap( ":/lock" ) );
825 cryptedLabel->setText( "DRM" );
826 statusBar()->addWidget( cryptedLabel );
829 cryptedLabel->setVisible( b_show );
832 void MainInterface::showBuffering( float f_cache )
834 QString amount = QString("Buffering: %1%").arg( (int)(100*f_cache) );
835 statusBar()->showMessage( amount, 1000 );
838 /*****************************************************************************
839 * Systray Icon and Systray Menu
840 *****************************************************************************/
843 * Create a SystemTray icon and a menu that would go with it.
844 * Connects to a click handler on the icon.
846 void MainInterface::createSystray()
849 if( QDate::currentDate().dayOfYear() >= 354 )
850 iconVLC = QIcon( ":/logo/vlc128-christmas.png" );
852 iconVLC = QIcon( ":/logo/vlc128.png" );
853 sysTray = new QSystemTrayIcon( iconVLC, this );
854 sysTray->setToolTip( qtr( "VLC media player" ));
856 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
857 systrayMenu->setIcon( iconVLC );
859 QVLCMenu::updateSystrayMenu( this, p_intf, true );
862 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
863 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
867 * Updates the Systray Icon's menu and toggle the main interface
869 void MainInterface::toggleUpdateSystrayMenu()
871 /* If hidden, show it */
877 else if( isMinimized() )
885 /* Visible (possibly under other windows) */
887 /* check if any visible window is above vlc in the z-order,
888 * but ignore the ones always on top
889 * and the ones which can't be activated */
892 wi.cbSize = sizeof( WINDOWINFO );
893 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
894 hwnd && ( !IsWindowVisible( hwnd ) ||
895 ( GetWindowInfo( hwnd, &wi ) &&
896 (wi.dwExStyle&WS_EX_NOACTIVATE) ) );
897 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
898 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
899 (wi.dwExStyle&WS_EX_TOPMOST) )
911 QVLCMenu::updateSystrayMenu( this, p_intf );
914 void MainInterface::handleSystrayClick(
915 QSystemTrayIcon::ActivationReason reason )
919 case QSystemTrayIcon::Trigger:
920 case QSystemTrayIcon::DoubleClick:
921 toggleUpdateSystrayMenu();
923 case QSystemTrayIcon::MiddleClick:
924 sysTray->showMessage( qtr( "VLC media player" ),
925 qtr( "Control menu for the player" ),
926 QSystemTrayIcon::Information, 3000 );
934 * Updates the name of the systray Icon tooltip.
935 * Doesn't check if the systray exists, check before you call it.
937 void MainInterface::updateSystrayTooltipName( const QString& name )
941 sysTray->setToolTip( qtr( "VLC media player" ) );
945 sysTray->setToolTip( name );
946 if( b_notificationEnabled && ( isHidden() || isMinimized() ) )
948 sysTray->showMessage( qtr( "VLC media player" ), name,
949 QSystemTrayIcon::NoIcon, 3000 );
953 QVLCMenu::updateSystrayMenu( this, p_intf );
957 * Updates the status of the systray Icon tooltip.
958 * Doesn't check if the systray exists, check before you call it.
960 void MainInterface::updateSystrayTooltipStatus( int i_status )
967 sysTray->setToolTip( qtr( "VLC media player" ) );
972 sysTray->setToolTip( input_name );
977 sysTray->setToolTip( input_name + " - "
982 QVLCMenu::updateSystrayMenu( this, p_intf );
986 /************************************************************************
988 ************************************************************************/
989 void MainInterface::dropEvent(QDropEvent *event)
991 dropEventPlay( event, true );
994 void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
996 event->setDropAction( Qt::CopyAction );
997 if( !event->possibleActions() & Qt::CopyAction )
1000 const QMimeData *mimeData = event->mimeData();
1002 /* D&D of a subtitles file, add it on the fly */
1003 if( mimeData->urls().size() == 1 && THEMIM->getIM()->hasInput() )
1005 if( !input_AddSubtitle( THEMIM->getInput(),
1006 qtu( toNativeSeparators( mimeData->urls()[0].toLocalFile() ) ),
1014 bool first = b_play;
1015 foreach( const QUrl &url, mimeData->urls() )
1017 QString s = toNativeSeparators( url.toLocalFile() );
1019 if( s.length() > 0 ) {
1020 char* psz_uri = make_URI( qtu(s) );
1021 playlist_Add( THEPL, psz_uri, NULL,
1022 PLAYLIST_APPEND | (first ? PLAYLIST_GO: PLAYLIST_PREPARSE),
1023 PLAYLIST_END, true, pl_Unlocked );
1026 RecentsMRL::getInstance( p_intf )->addRecent( s );
1031 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1033 event->acceptProposedAction();
1035 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1037 event->acceptProposedAction();
1039 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1044 /************************************************************************
1046 ************************************************************************/
1047 void MainInterface::customEvent( QEvent *event )
1050 if( event->type() == PLDockEvent_Type )
1052 PlaylistDialog::killInstance();
1053 playlistEmbeddedFlag = true;
1055 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1060 if ( event->type() == (int)SetVideoOnTopEvent_Type )
1062 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1063 if( p_event->OnTop() )
1064 setWindowFlags( windowFlags() | Qt::WindowStaysOnTopHint );
1066 setWindowFlags( windowFlags() & ~Qt::WindowStaysOnTopHint );
1067 show(); /* necessary to apply window flags */
1071 void MainInterface::keyPressEvent( QKeyEvent *e )
1073 handleKeyPress( e );
1076 void MainInterface::handleKeyPress( QKeyEvent *e )
1078 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() == Qt::Key_H )
1079 && !menuBar()->isVisible() )
1081 toggleMinimalView( false );
1085 int i_vlck = qtEventToVLCKey( e );
1088 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1095 void MainInterface::resizeEvent( QResizeEvent * event )
1102 mainVideoSize = size();
1106 if( VISIBLE( bgWidget) ||
1107 ( videoIsActive && videoWidget->isVisible() )
1109 mainVideoSize = size();
1111 mainBasedSize = size();
1115 QVLCMW::resizeEvent( event );
1116 msg_Dbg( p_intf, "Resize Event, height: %i", size().height() );
1120 void MainInterface::wheelEvent( QWheelEvent *e )
1122 int i_vlckey = qtWheelEventToVLCKey( e );
1123 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1127 void MainInterface::closeEvent( QCloseEvent *e )
1134 void MainInterface::toggleFullScreen()
1136 if( isFullScreen() )
1139 emit fullscreenInterfaceToggled( false );
1144 emit fullscreenInterfaceToggled( true );
1148 /*****************************************************************************
1149 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1150 * We don't show the menu directly here because we don't want the
1151 * caller to block for a too long time.
1152 *****************************************************************************/
1153 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1154 vlc_value_t old_val, vlc_value_t new_val, void *param )
1156 intf_thread_t *p_intf = (intf_thread_t *)param;
1158 if( p_intf->pf_show_dialog )
1160 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1161 new_val.b_bool, NULL );
1167 /*****************************************************************************
1168 * IntfShowCB: callback triggered by the intf-show libvlc variable.
1169 *****************************************************************************/
1170 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1171 vlc_value_t old_val, vlc_value_t new_val, void *param )
1173 intf_thread_t *p_intf = (intf_thread_t *)param;
1174 p_intf->p_sys->p_mi->toggleFSC();