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_autoresize = 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();
125 settings->endGroup( );
132 /**************************
133 * UI and Widgets design
134 **************************/
135 setVLCWindowsTitle();
140 QVLCMenu::createMenuBar( this, p_intf );
141 CONNECT( THEMIM->getIM(), voutListChanged( vout_thread_t **, int ),
142 this, destroyPopupMenu() );
144 createMainWidget( settings );
145 /*********************************
146 * Create the Systray Management *
147 *********************************/
150 /********************
152 ********************/
153 MainInputManager::getInstance( p_intf );
158 taskbar_wmsg = RegisterWindowMessage("TaskbarButtonCreated");
161 /************************************************************
162 * Connect the input manager to the GUI elements it manages *
163 ************************************************************/
165 * Connects on nameChanged()
166 * Those connects are different because options can impeach them to trigger.
168 /* Main Interface statusbar */
169 CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
170 this, setName( const QString& ) );
175 CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
176 this, updateSystrayTooltipName( const QString& ) );
179 /* and title of the Main Interface*/
180 if( var_InheritBool( p_intf, "qt-name-in-title" ) )
182 CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
183 this, setVLCWindowsTitle( const QString& ) );
187 * CONNECTS on PLAY_STATUS
189 /* Status on the systray */
193 CONNECT( THEMIM->getIM(), statusChanged( int ),
194 this, updateSystrayTooltipStatus( int ) );
198 /* END CONNECTS ON IM */
200 /* VideoWidget connects for asynchronous calls */
201 connect( this, SIGNAL(askGetVideo(WId*,int*,int*,unsigned*,unsigned *)),
202 this, SLOT(getVideoSlot(WId*,int*,int*,unsigned*,unsigned*)),
203 Qt::BlockingQueuedConnection );
204 connect( this, SIGNAL(askReleaseVideo( void )),
205 this, SLOT(releaseVideoSlot( void )),
206 Qt::BlockingQueuedConnection );
207 CONNECT( this, askVideoOnTop(bool), this, setVideoOnTop(bool));
213 CONNECT( this, askVideoToResize( unsigned int, unsigned int ),
214 videoWidget, SetSizing( unsigned int, unsigned int ) );
215 CONNECT( videoWidget, sizeChanged( int, int ),
216 this, resizeStack( int, int ) );
218 CONNECT( this, askVideoSetFullScreen( bool ),
219 videoWidget, SetFullScreen( bool ) );
220 CONNECT( videoWidget, keyPressed( QKeyEvent * ),
221 this, handleKeyPress( QKeyEvent * ) );
224 CONNECT( THEDP, toolBarConfUpdated(), this, recreateToolbars() );
226 /** END of CONNECTS**/
232 var_AddCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
234 /* Register callback for the intf-popupmenu variable */
235 var_AddCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
238 int i_plVis = settings->value( "MainWindow/playlist-visible", false ).toBool();
240 if( i_plVis ) togglePlaylist();
242 /**** FINAL SIZING and placement of interface */
243 settings->beginGroup( "MainWindow" );
244 QVLCTools::restoreWidgetPosition( settings, this, QSize(400, 100) );
245 settings->endGroup();
247 /* Final sizing and showing */
248 setVisible( !b_hideAfterCreation );
250 setMinimumWidth( __MAX( controls->sizeHint().width(),
251 menuBar()->sizeHint().width() ) + 30 );
253 /* Switch to minimal view if needed, must be called after the show() */
255 toggleMinimalView( true );
258 MainInterface::~MainInterface()
260 /* Unsure we hide the videoWidget before destroying it */
261 if( stackCentralOldWidget == videoWidget )
266 ImageList_Destroy( himl );
268 p_taskbl->vt->Release(p_taskbl);
272 /* Be sure to kill the actionsManager... Only used in the MI and control */
273 ActionsManager::killInstance();
276 ExtensionsManager::killInstance();
278 /* Delete the FSC controller */
279 delete fullscreenControls;
282 settings->beginGroup( "MainWindow" );
284 settings->setValue( "pl-dock-status", b_plDocked );
285 /* Save playlist state */
288 settings->setValue( "playlist-visible",
291 playlistWidget->isVisible() /* FIXME */ );
294 settings->setValue( "adv-controls",
295 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
297 /* Save the stackCentralW sizes */
298 settings->setValue( "bgSize", stackWidgetsSizes[bgWidget] );
299 settings->setValue( "playlistSize", stackWidgetsSizes[playlistWidget] );
302 QVLCTools::saveWidgetPosition(settings, this);
304 settings->endGroup();
306 /* Save undocked playlist size */
307 if( playlistWidget && !isPlDocked() )
308 QVLCTools::saveWidgetPosition( p_intf, "Playlist", playlistWidget );
310 delete playlistWidget;
314 /* Unregister callbacks */
315 var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
316 var_DelCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
318 p_intf->p_sys->p_mi = NULL;
321 /*****************************
323 *****************************/
324 void MainInterface::recreateToolbars()
326 bool b_adv = getControlsVisibilityStatus() & CONTROLS_ADVANCED;
328 settings->beginGroup( "MainWindow" );
332 controls = new ControlsWidget( p_intf, b_adv, this );
333 inputC = new InputControlsWidget( p_intf, this );
335 if( fullscreenControls )
337 delete fullscreenControls;
338 fullscreenControls = new FullscreenControllerWidget( p_intf, this );
339 CONNECT( fullscreenControls, keyPressed( QKeyEvent * ),
340 this, handleKeyPress( QKeyEvent * ) );
342 mainLayout->insertWidget( 2, inputC );
343 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
345 settings->endGroup();
348 void MainInterface::createMainWidget( QSettings *settings )
350 /* Create the main Widget and the mainLayout */
351 QWidget *main = new QWidget;
352 setCentralWidget( main );
353 mainLayout = new QVBoxLayout( main );
354 main->setContentsMargins( 0, 0, 0, 0 );
355 mainLayout->setSpacing( 0 ); mainLayout->setMargin( 0 );
358 stackCentralW = new QVLCStackedWidget( main );
361 bgWidget = new BackgroundWidget( p_intf );
362 stackCentralW->addWidget( bgWidget );
364 /* And video Outputs */
365 if( b_videoEmbedded )
367 videoWidget = new VideoWidget( p_intf );
368 stackCentralW->addWidget( videoWidget );
370 mainLayout->insertWidget( 1, stackCentralW );
372 settings->beginGroup( "MainWindow" );
373 stackWidgetsSizes[bgWidget] = settings->value( "bgSize", QSize( 400, 0 ) ).toSize();
374 /* Resize even if no-auto-resize, because we are at creation */
375 resizeStack( stackWidgetsSizes[bgWidget].width(), stackWidgetsSizes[bgWidget].height() );
377 /* Create the CONTROLS Widget */
378 controls = new ControlsWidget( p_intf,
379 settings->value( "adv-controls", false ).toBool(), this );
380 inputC = new InputControlsWidget( p_intf, this );
382 mainLayout->insertWidget( 2, inputC );
383 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
386 /* Visualisation, disabled for now, they SUCK */
388 visualSelector = new VisualSelector( p_intf );
389 mainLayout->insertWidget( 0, visualSelector );
390 visualSelector->hide();
393 settings->endGroup();
395 /* Enable the popup menu in the MI */
396 main->setContextMenuPolicy( Qt::CustomContextMenu );
397 CONNECT( main, customContextMenuRequested( const QPoint& ),
398 this, popupMenu( const QPoint& ) );
400 if ( depth() > 8 ) /* 8bit depth has too many issues with opacity */
401 /* Create the FULLSCREEN CONTROLS Widget */
402 if( var_InheritBool( p_intf, "qt-fs-controller" ) )
404 fullscreenControls = new FullscreenControllerWidget( p_intf, this );
405 CONNECT( fullscreenControls, keyPressed( QKeyEvent * ),
406 this, handleKeyPress( QKeyEvent * ) );
410 inline void MainInterface::initSystray()
413 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
414 bool b_systrayWanted = var_InheritBool( p_intf, "qt-system-tray" );
416 if( var_InheritBool( p_intf, "qt-start-minimized") )
418 if( b_systrayAvailable )
420 b_systrayWanted = true;
421 b_hideAfterCreation = true;
424 msg_Err( p_intf, "cannot start minimized without system tray bar" );
427 if( b_systrayAvailable && b_systrayWanted )
432 inline void MainInterface::createStatusBar()
437 /* Widgets Creation*/
438 QStatusBar *statusBarr = statusBar();
440 TimeLabel *timeLabel = new TimeLabel( p_intf );
441 nameLabel = new QLabel( this );
442 nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
443 | Qt::TextSelectableByKeyboard );
444 SpeedLabel *speedLabel = new SpeedLabel( p_intf, this );
446 /* Styling those labels */
447 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
448 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
449 nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
450 timeLabel->setStyleSheet(
451 "QLabel:hover { background-color: rgba(255, 255, 255, 50%) }" );
452 speedLabel->setStyleSheet(
453 "QLabel:hover { background-color: rgba(255, 255, 255, 50%) }" );
455 /* and adding those */
456 statusBarr->addWidget( nameLabel, 8 );
457 statusBarr->addPermanentWidget( speedLabel, 0 );
458 statusBarr->addPermanentWidget( timeLabel, 0 );
460 /* timeLabel behaviour:
461 - double clicking opens the goto time dialog
462 - right-clicking and clicking just toggle between remaining and
464 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
466 CONNECT( THEMIM->getIM(), encryptionChanged( bool ),
467 this, showCryptedLabel( bool ) );
469 CONNECT( THEMIM->getIM(), seekRequested( float ),
470 timeLabel, setDisplayPosition( float ) );
473 /**********************************************************************
474 * Handling of sizing of the components
475 **********************************************************************/
477 void MainInterface::debug()
480 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
481 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
482 msg_Dbg( p_intf, "minimumsize: %i - %i", minimumSize().height(), minimumSize().width() );
484 msg_Dbg( p_intf, "Stack size: %i - %i", stackCentralW->size().height(), stackCentralW->size().width() );
485 msg_Dbg( p_intf, "Stack sizeHint: %i - %i", stackCentralW->sizeHint().height(), stackCentralW->sizeHint().width() );
486 msg_Dbg( p_intf, "Central size: %i - %i", centralWidget()->size().height(), centralWidget()->size().width() );
490 inline void MainInterface::showVideo() { showTab( videoWidget ); }
491 inline void MainInterface::restoreStackOldWidget()
492 { showTab( stackCentralOldWidget ); }
494 inline void MainInterface::showTab( QWidget *widget )
497 msg_Warn( p_intf, "Old stackCentralOldWidget %i", stackCentralW->indexOf( stackCentralOldWidget ) );
500 stackCentralOldWidget = stackCentralW->currentWidget();
501 stackWidgetsSizes[stackCentralOldWidget] = stackCentralW->size();
503 stackCentralW->setCurrentWidget( widget );
505 resizeStack( stackWidgetsSizes[widget].width(), stackWidgetsSizes[widget].height() );
508 msg_Warn( p_intf, "State change %i", stackCentralW->currentIndex() );
509 msg_Warn( p_intf, "New stackCentralOldWidget %i", stackCentralW->indexOf( stackCentralOldWidget ) );
513 void MainInterface::destroyPopupMenu()
515 QVLCMenu::PopupMenu( p_intf, false );
518 void MainInterface::popupMenu( const QPoint &p )
520 QVLCMenu::PopupMenu( p_intf, true );
523 void MainInterface::toggleFSC()
525 if( !fullscreenControls ) return;
527 IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
528 QApplication::postEvent( fullscreenControls, eShow );
531 /****************************************************************************
533 ****************************************************************************/
537 * You must not change the state of this object or other Qt4 UI objects,
538 * from the video output thread - only from the Qt4 UI main loop thread.
539 * All window provider queries must be handled through signals or events.
540 * That's why we have all those emit statements...
542 WId MainInterface::getVideo( int *pi_x, int *pi_y,
543 unsigned int *pi_width, unsigned int *pi_height )
548 /* This is a blocking call signal. Results are returned through pointers.
549 * Beware of deadlocks! */
551 emit askGetVideo( &id, pi_x, pi_y, pi_width, pi_height );
555 void MainInterface::getVideoSlot( WId *p_id, int *pi_x, int *pi_y,
556 unsigned *pi_width, unsigned *pi_height )
558 /* Request the videoWidget */
559 WId ret = videoWidget->request( pi_x, pi_y,
560 pi_width, pi_height, !b_autoresize );
562 if( ret ) /* The videoWidget is available */
564 /* Consider the video active now */
567 /* Ask videoWidget to resize correctly, if we are in normal mode */
568 if( !isFullScreen() && !isMaximized() && b_autoresize )
569 videoWidget->SetSizing( *pi_width, *pi_height );
573 /* Asynchronous call from the WindowClose function */
574 void MainInterface::releaseVideo( void )
576 emit askReleaseVideo();
579 /* Function that is CONNECTED to the previous emit */
580 void MainInterface::releaseVideoSlot( void )
582 videoWidget->release();
583 setVideoOnTop( false );
585 if( stackCentralW->currentWidget() == videoWidget )
586 restoreStackOldWidget();
588 /* We don't want to have a blank video to popup */
589 stackCentralOldWidget = bgWidget;
592 /* Slot to change the video always-on-top flag.
593 * Emit askVideoOnTop() to invoke this from other thread. */
594 void MainInterface::setVideoOnTop( bool on_top )
596 Qt::WindowFlags oldflags = windowFlags(), newflags;
599 newflags = oldflags | Qt::WindowStaysOnTopHint;
601 newflags = oldflags & ~Qt::WindowStaysOnTopHint;
603 if( newflags != oldflags )
605 setWindowFlags( newflags );
606 show(); /* necessary to apply window flags */
610 /* Asynchronous call from WindowControl function */
611 int MainInterface::controlVideo( int i_query, va_list args )
615 case VOUT_WINDOW_SET_SIZE:
617 unsigned int i_width = va_arg( args, unsigned int );
618 unsigned int i_height = va_arg( args, unsigned int );
619 if( isFullScreen() || isMaximized() )
621 emit askVideoToResize( i_width, i_height );
624 case VOUT_WINDOW_SET_STATE:
626 unsigned i_arg = va_arg( args, unsigned );
627 unsigned on_top = i_arg & VOUT_WINDOW_STATE_ABOVE;
629 emit askVideoOnTop( on_top != 0 );
632 case VOUT_WINDOW_SET_FULLSCREEN:
634 bool b_fs = va_arg( args, int );
635 emit askVideoSetFullScreen( b_fs );
639 msg_Warn( p_intf, "unsupported control query" );
644 /*****************************************************************************
645 * Playlist, Visualisation and Menus handling
646 *****************************************************************************/
648 * Toggle the playlist widget or dialog
650 void MainInterface::createPlaylist()
652 playlistWidget = new PlaylistWidget( p_intf, this );
656 stackCentralW->addWidget( playlistWidget );
657 stackWidgetsSizes[playlistWidget] = settings->value( "playlistSize", QSize( 500, 250 ) ).toSize();
662 playlistWidget->setParent( NULL );
664 playlistWidget->setWindowFlags( Qt::Window );
666 /* This will restore the geometry but will not work for position,
667 because of parenting */
668 QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
669 playlistWidget, QSize( 600, 300 ) );
673 void MainInterface::togglePlaylist()
675 if( !playlistWidget )
682 /* Playlist is not visible, show it */
683 if( stackCentralW->currentWidget() != playlistWidget )
685 showTab( playlistWidget );
689 restoreStackOldWidget();
691 playlistVisible = ( stackCentralW->currentWidget() == playlistWidget );
696 playlistWidget->setParent( NULL );
698 playlistWidget->setWindowFlags( Qt::Window );
699 playlistVisible = !playlistVisible;
700 playlistWidget->setVisible( playlistVisible );
705 void MainInterface::dockPlaylist( bool p_docked )
707 if( b_plDocked == p_docked ) return;
708 b_plDocked = p_docked;
710 if( !playlistWidget ) return; /* Playlist wasn't created yet */
713 stackCentralW->removeWidget( playlistWidget );
715 playlistWidget->setParent( NULL );
717 playlistWidget->setWindowFlags( Qt::Window );
718 QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
719 playlistWidget, QSize( 600, 300 ) );
720 playlistWidget->show();
721 restoreStackOldWidget();
725 QVLCTools::saveWidgetPosition( p_intf, "Playlist", playlistWidget );
726 playlistWidget->setWindowFlags( Qt::Widget ); // Probably a Qt bug here
727 // It would be logical that QStackWidget::addWidget reset the flags...
728 stackCentralW->addWidget( playlistWidget );
729 showTab( playlistWidget );
731 playlistVisible = true;
735 If b_switch is false, then we are normalView
737 void MainInterface::toggleMinimalView( bool b_switch )
739 if( i_visualmode == 0 && b_autoresize ) /* Normal mode */
741 if( stackCentralW->currentWidget() == bgWidget )
743 if( stackCentralW->height() < 16 )
745 resizeStack( stackCentralW->width(), 100 );
750 menuBar()->setVisible( !b_switch );
751 controls->setVisible( !b_switch );
752 statusBar()->setVisible( !b_switch );
753 inputC->setVisible( !b_switch );
755 emit minimalViewToggled( b_switch );
758 /* toggling advanced controls buttons */
759 void MainInterface::toggleAdvancedButtons()
761 controls->toggleAdvanced();
762 // if( fullscreenControls ) fullscreenControls->toggleAdvanced();
765 /* Get the visibility status of the controls (hidden or not, advanced or not) */
766 int MainInterface::getControlsVisibilityStatus()
768 if( !controls ) return 0;
769 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
770 + CONTROLS_ADVANCED * controls->b_advancedVisible );
774 void MainInterface::visual()
776 if( !VISIBLE( visualSelector) )
778 visualSelector->show();
779 if( !THEMIM->getIM()->hasVideo() )
781 /* Show the background widget */
783 visualSelectorEnabled = true;
787 /* Stop any currently running visualization */
788 visualSelector->hide();
789 visualSelectorEnabled = false;
794 /************************************************************************
796 ************************************************************************/
797 void MainInterface::setName( const QString& name )
799 input_name = name; /* store it for the QSystray use */
800 /* Display it in the status bar, but also as a Tooltip in case it doesn't
802 nameLabel->setText( " " + name + " " );
803 nameLabel->setToolTip( " " + name +" " );
807 * Give the decorations of the Main Window a correct Name.
808 * If nothing is given, set it to VLC...
810 void MainInterface::setVLCWindowsTitle( const QString& aTitle )
812 if( aTitle.isEmpty() )
814 setWindowTitle( qtr( "VLC media player" ) );
818 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
822 void MainInterface::showCryptedLabel( bool b_show )
824 if( cryptedLabel == NULL )
826 cryptedLabel = new QLabel;
827 // The lock icon is not the right one for DRM protection/scrambled.
828 //cryptedLabel->setPixmap( QPixmap( ":/lock" ) );
829 cryptedLabel->setText( "DRM" );
830 statusBar()->addWidget( cryptedLabel );
833 cryptedLabel->setVisible( b_show );
836 void MainInterface::showBuffering( float f_cache )
838 QString amount = QString("Buffering: %1%").arg( (int)(100*f_cache) );
839 statusBar()->showMessage( amount, 1000 );
842 /*****************************************************************************
843 * Systray Icon and Systray Menu
844 *****************************************************************************/
847 * Create a SystemTray icon and a menu that would go with it.
848 * Connects to a click handler on the icon.
850 void MainInterface::createSystray()
853 if( QDate::currentDate().dayOfYear() >= 354 )
854 iconVLC = QIcon( ":/logo/vlc128-christmas.png" );
856 iconVLC = QIcon( ":/logo/vlc128.png" );
857 sysTray = new QSystemTrayIcon( iconVLC, this );
858 sysTray->setToolTip( qtr( "VLC media player" ));
860 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
861 systrayMenu->setIcon( iconVLC );
863 QVLCMenu::updateSystrayMenu( this, p_intf, true );
866 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
867 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
871 * Updates the Systray Icon's menu and toggle the main interface
873 void MainInterface::toggleUpdateSystrayMenu()
875 /* If hidden, show it */
881 else if( isMinimized() )
889 /* Visible (possibly under other windows) */
891 /* check if any visible window is above vlc in the z-order,
892 * but ignore the ones always on top
893 * and the ones which can't be activated */
896 wi.cbSize = sizeof( WINDOWINFO );
897 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
898 hwnd && ( !IsWindowVisible( hwnd ) ||
899 ( GetWindowInfo( hwnd, &wi ) &&
900 (wi.dwExStyle&WS_EX_NOACTIVATE) ) );
901 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
902 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
903 (wi.dwExStyle&WS_EX_TOPMOST) )
915 QVLCMenu::updateSystrayMenu( this, p_intf );
918 void MainInterface::handleSystrayClick(
919 QSystemTrayIcon::ActivationReason reason )
923 case QSystemTrayIcon::Trigger:
924 case QSystemTrayIcon::DoubleClick:
925 toggleUpdateSystrayMenu();
927 case QSystemTrayIcon::MiddleClick:
928 sysTray->showMessage( qtr( "VLC media player" ),
929 qtr( "Control menu for the player" ),
930 QSystemTrayIcon::Information, 3000 );
938 * Updates the name of the systray Icon tooltip.
939 * Doesn't check if the systray exists, check before you call it.
941 void MainInterface::updateSystrayTooltipName( const QString& name )
945 sysTray->setToolTip( qtr( "VLC media player" ) );
949 sysTray->setToolTip( name );
950 if( b_notificationEnabled && ( isHidden() || isMinimized() ) )
952 sysTray->showMessage( qtr( "VLC media player" ), name,
953 QSystemTrayIcon::NoIcon, 3000 );
957 QVLCMenu::updateSystrayMenu( this, p_intf );
961 * Updates the status of the systray Icon tooltip.
962 * Doesn't check if the systray exists, check before you call it.
964 void MainInterface::updateSystrayTooltipStatus( int i_status )
969 sysTray->setToolTip( input_name );
972 sysTray->setToolTip( input_name + " - " + qtr( "Paused") );
975 sysTray->setToolTip( qtr( "VLC media player" ) );
978 QVLCMenu::updateSystrayMenu( this, p_intf );
982 /************************************************************************
984 ************************************************************************/
985 void MainInterface::dropEvent(QDropEvent *event)
987 dropEventPlay( event, true );
990 void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
992 event->setDropAction( Qt::CopyAction );
993 if( !event->possibleActions() & Qt::CopyAction )
996 const QMimeData *mimeData = event->mimeData();
998 /* D&D of a subtitles file, add it on the fly */
999 if( mimeData->urls().size() == 1 && THEMIM->getIM()->hasInput() )
1001 if( !input_AddSubtitle( THEMIM->getInput(),
1002 qtu( toNativeSeparators( mimeData->urls()[0].toLocalFile() ) ),
1010 bool first = b_play;
1011 foreach( const QUrl &url, mimeData->urls() )
1013 QString s = toNativeSeparators( url.toLocalFile() );
1015 if( s.length() > 0 ) {
1016 char* psz_uri = make_URI( qtu(s) );
1017 playlist_Add( THEPL, psz_uri, NULL,
1018 PLAYLIST_APPEND | (first ? PLAYLIST_GO: PLAYLIST_PREPARSE),
1019 PLAYLIST_END, true, pl_Unlocked );
1022 RecentsMRL::getInstance( p_intf )->addRecent( s );
1027 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1029 event->acceptProposedAction();
1031 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1033 event->acceptProposedAction();
1035 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1040 /************************************************************************
1042 ************************************************************************/
1043 void MainInterface::keyPressEvent( QKeyEvent *e )
1045 handleKeyPress( e );
1048 void MainInterface::handleKeyPress( QKeyEvent *e )
1050 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() == Qt::Key_H )
1051 && !menuBar()->isVisible() )
1053 toggleMinimalView( false );
1057 int i_vlck = qtEventToVLCKey( e );
1060 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1067 void MainInterface::wheelEvent( QWheelEvent *e )
1069 int i_vlckey = qtWheelEventToVLCKey( e );
1070 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1074 void MainInterface::closeEvent( QCloseEvent *e )
1081 void MainInterface::toggleFullScreen()
1083 if( isFullScreen() )
1086 emit fullscreenInterfaceToggled( false );
1091 emit fullscreenInterfaceToggled( true );
1095 /*****************************************************************************
1096 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1097 * We don't show the menu directly here because we don't want the
1098 * caller to block for a too long time.
1099 *****************************************************************************/
1100 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1101 vlc_value_t old_val, vlc_value_t new_val, void *param )
1103 intf_thread_t *p_intf = (intf_thread_t *)param;
1105 if( p_intf->pf_show_dialog )
1107 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1108 new_val.b_bool, NULL );
1114 /*****************************************************************************
1115 * IntfShowCB: callback triggered by the intf-show libvlc variable.
1116 *****************************************************************************/
1117 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1118 vlc_value_t old_val, vlc_value_t new_val, void *param )
1120 intf_thread_t *p_intf = (intf_thread_t *)param;
1121 p_intf->p_sys->p_mi->toggleFSC();