1 /*****************************************************************************
2 * main_interface.cpp : Main interface
3 ****************************************************************************
4 * Copyright (C) 2006-2009 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Jean-Baptiste Kempf <jb@videolan.org>
9 * Ilkka Ollakka <ileoo@videolan.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
32 #include "main_interface.hpp"
33 #include "input_manager.hpp"
34 #include "actions_manager.hpp"
36 #include "util/customwidgets.hpp"
37 #include "util/qt_dirs.hpp"
39 #include "components/interface_widgets.hpp"
40 #include "components/controller.hpp"
41 #include "components/playlist/playlist.hpp"
42 #include "dialogs/external.hpp"
45 #include "recents.hpp"
47 #include <QCloseEvent>
59 #include <QPushButton>
63 #include <vlc_keys.h> /* Wheel event */
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 */
75 // need_components_update = false;
78 playlistWidget = NULL;
80 videoIsActive = false;
81 playlistVisible = false;
83 fullscreenControls = NULL;
96 * Configuration and settings
97 * Pre-building of interface
100 setFocusPolicy( Qt::StrongFocus );
101 setAcceptDrops( true );
102 setWindowIcon( QApplication::windowIcon() );
103 setWindowOpacity( config_GetFloat( p_intf, "qt-opacity" ) );
105 /* Set The Video In emebedded Mode or not */
106 videoEmbeddedFlag = config_GetInt( p_intf, "embedded-video" );
108 /* Does the interface resize to video size or the opposite */
109 b_keep_size = !config_GetInt( p_intf, "qt-video-autoresize" );
111 /* Are we in the enhanced always-video mode or not ? */
112 i_visualmode = config_GetInt( p_intf, "qt-display-mode" );
114 /* Set the other interface settings */
115 settings = getSettings();
116 settings->beginGroup( "MainWindow" );
119 * Retrieve saved sizes for main window
120 * mainBasedSize = based window size for normal mode
121 * (no video, no background)
122 * mainVideoSize = window size with video (all modes)
124 mainBasedSize = settings->value( "mainBasedSize", QSize( 350, 120 ) ).toSize();
125 mainVideoSize = settings->value( "mainVideoSize", QSize( 400, 300 ) ).toSize();
127 /* Do we want anoying popups or not */
128 notificationEnabled = (bool)config_GetInt( p_intf, "qt-notification" );
135 /**************************
136 * UI and Widgets design
137 **************************/
138 setVLCWindowsTitle();
139 createMainWidget( settings );
144 QVLCMenu::createMenuBar( this, p_intf );
145 CONNECT( THEMIM->getIM(), voutListChanged( vout_thread_t **, int ),
146 this, destroyPopupMenu() );
149 /* Create a Dock to get the playlist */
150 dockPL = new QDockWidget( qtr( "Playlist" ), this );
151 dockPL->setSizePolicy( QSizePolicy::Preferred,
152 QSizePolicy::Expanding );
153 dockPL->setFeatures( QDockWidget::AllDockWidgetFeatures );
154 dockPL->setAllowedAreas( Qt::LeftDockWidgetArea
155 | Qt::RightDockWidgetArea
156 | Qt::BottomDockWidgetArea );
160 /********************
162 ********************/
163 MainInputManager::getInstance( p_intf );
165 /*********************************
166 * Create the Systray Management *
167 *********************************/
170 /**************************
171 * Various CONNECTs on IM *
172 **************************/
173 /* Connect the input manager to the GUI elements it manages */
176 * Connects on nameChanged()
177 * Those connects are not merged because different options can trigger
180 /* Naming in the controller statusbar */
181 CONNECT( THEMIM->getIM(), nameChanged( QString ),
182 this, setName( QString ) );
183 /* and in the systray */
186 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
187 updateSystrayTooltipName( QString ) );
189 /* and in the title of the controller */
190 if( config_GetInt( p_intf, "qt-name-in-title" ) )
192 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
193 setVLCWindowsTitle( QString ) );
197 * CONNECTS on PLAY_STATUS
199 /* Status on the systray */
202 CONNECT( THEMIM->getIM(), statusChanged( int ),
203 this, updateSystrayTooltipStatus( int ) );
207 /* END CONNECTS ON IM */
209 dialogHandler = new DialogHandler (p_intf);
214 var_AddCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
216 /* Register callback for the intf-popupmenu variable */
217 var_AddCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
220 /* VideoWidget connects to avoid different threads speaking to each other */
221 connect( this, SIGNAL(askReleaseVideo( void )),
222 this, SLOT(releaseVideoSlot( void )), Qt::BlockingQueuedConnection );
226 CONNECT( this, askVideoToResize( unsigned int, unsigned int ),
227 videoWidget, SetSizing( unsigned int, unsigned int ) );
229 connect( this, SIGNAL(askVideoToShow( unsigned int, unsigned int)),
230 videoWidget, SLOT(SetSizing(unsigned int, unsigned int )),
231 Qt::BlockingQueuedConnection );
234 CONNECT( this, askUpdate(), this, doComponentsUpdate() );
235 CONNECT( THEDP, toolBarConfUpdated(), this, recreateToolbars() );
237 /* Size and placement of interface */
238 settings->beginGroup( "MainWindow" );
239 QVLCTools::restoreWidgetPosition( settings, this, QSize(380, 60) );
241 /* resize to previously saved main window size if appicable */
244 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
245 i_visualmode == QT_MINIMAL_MODE )
247 resize( mainVideoSize );
251 resize( mainBasedSize );
255 bool b_visible = settings->value( "playlist-visible", 0 ).toInt();
256 settings->endGroup();
259 if( b_visible ) togglePlaylist();
261 /* Enable the popup menu in the MI */
262 setContextMenuPolicy( Qt::CustomContextMenu );
263 CONNECT( this, customContextMenuRequested( const QPoint& ),
264 this, popupMenu( const QPoint& ) );
266 /* Final sizing and showing */
267 setMinimumWidth( __MAX( controls->sizeHint().width(),
268 menuBar()->sizeHint().width() ) );
269 setVisible( !b_shouldHide );
271 /* And switch to minimal view if needed
272 Must be called after the show() */
273 if( i_visualmode == QT_MINIMAL_MODE )
274 toggleMinimalView( true );
276 /* Update the geometry : It is useful if you switch between
279 resize( sizeHint() );
283 MainInterface::~MainInterface()
285 msg_Dbg( p_intf, "Destroying the main interface" );
287 delete dialogHandler;
289 /* Unsure we hide the videoWidget before destroying it */
290 if( videoIsActive ) videoWidget->hide();
292 /* Save playlist state */
296 QVLCTools::saveWidgetPosition( p_intf, "Playlist", playlistWidget );
298 delete playlistWidget;
301 /* Be sure to kill the actionsManager... FIXME */
302 ActionsManager::killInstance();
304 /* Delete the FSC controller */
305 delete fullscreenControls;
308 settings->beginGroup( "MainWindow" );
309 settings->setValue( "pl-dock-status", (int)i_pl_dock );
310 settings->setValue( "playlist-visible", (int)playlistVisible );
311 settings->setValue( "adv-controls",
312 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
314 settings->setValue( "mainBasedSize", mainBasedSize );
315 settings->setValue( "mainVideoSize", mainVideoSize );
318 settings->setValue( "backgroundSize", bgWidget->size() );
321 QVLCTools::saveWidgetPosition(settings, this);
322 settings->endGroup();
325 /* Unregister callbacks */
326 var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
327 var_DelCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
329 p_intf->p_sys->p_mi = NULL;
332 /*****************************
334 *****************************/
335 void MainInterface::recreateToolbars()
337 settings->beginGroup( "MainWindow" );
340 controls = new ControlsWidget( p_intf, false, this ); /* FIXME */
341 CONNECT( controls, advancedControlsToggled( bool ),
342 this, doComponentsUpdate() );
343 CONNECT( controls, sizeChanged(),
344 this, doComponentsUpdate() );
345 inputC = new InputControlsWidget( p_intf, this );
347 mainLayout->insertWidget( 2, inputC, 0, Qt::AlignBottom );
348 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
349 controls, 0, Qt::AlignBottom );
350 settings->endGroup();
353 void MainInterface::createMainWidget( QSettings *settings )
355 /* Create the main Widget and the mainLayout */
356 QWidget *main = new QWidget;
357 setCentralWidget( main );
358 mainLayout = new QVBoxLayout( main );
360 /* Margins, spacing */
361 main->setContentsMargins( 0, 0, 0, 0 );
362 main->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
363 mainLayout->setSpacing( 0 );
364 mainLayout->setMargin( 0 );
367 /* Disabled for now, they SUCK */
369 visualSelector = new VisualSelector( p_intf );
370 mainLayout->insertWidget( 0, visualSelector );
371 visualSelector->hide();
375 bgWidget = new BackgroundWidget( p_intf );
377 settings->value( "backgroundSize", QSize( 300, 200 ) ).toSize() );
378 bgWidget->updateGeometry();
379 CONNECT( this, askBgWidgetToToggle(), bgWidget, toggle() );
381 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
382 i_visualmode != QT_MINIMAL_MODE )
387 /* And video Outputs */
388 if( videoEmbeddedFlag )
389 videoWidget = new VideoWidget( p_intf );
391 /* Create the CONTROLS Widget */
392 controls = new ControlsWidget( p_intf,
393 settings->value( "adv-controls", false ).toBool(), this );
394 CONNECT( controls, advancedControlsToggled( bool ),
395 this, doComponentsUpdate() );
396 CONNECT( controls, sizeChanged(),
397 this, doComponentsUpdate() );
398 inputC = new InputControlsWidget( p_intf, this );
401 /* Add the controls Widget to the main Widget */
402 mainLayout->insertWidget( 0, bgWidget );
403 if( videoWidget ) mainLayout->insertWidget( 0, videoWidget, 10 );
404 mainLayout->insertWidget( 2, inputC, 0, Qt::AlignBottom );
405 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
406 controls, 0, Qt::AlignBottom );
408 /* Finish the sizing */
409 main->updateGeometry();
411 getSettings()->endGroup();
415 /* Create the FULLSCREEN CONTROLS Widget */
416 if( config_GetInt( p_intf, "qt-fs-controller" ) )
418 fullscreenControls = new FullscreenControllerWidget( p_intf );
422 inline void MainInterface::createStatusBar()
427 /* Widgets Creation*/
428 QStatusBar *statusBarr = statusBar();
430 TimeLabel *timeLabel = new TimeLabel( p_intf );
431 nameLabel = new QLabel( this );
432 nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
433 | Qt::TextSelectableByKeyboard );
434 SpeedLabel *speedLabel = new SpeedLabel( p_intf, "1.00x", this );
436 /* Styling those labels */
437 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
438 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
439 nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
441 /* and adding those */
442 statusBarr->addWidget( nameLabel, 8 );
443 statusBarr->addPermanentWidget( speedLabel, 0 );
444 statusBarr->addPermanentWidget( timeLabel, 0 );
446 /* timeLabel behaviour:
447 - double clicking opens the goto time dialog
448 - right-clicking and clicking just toggle between remaining and
450 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
452 CONNECT( THEMIM->getIM(), encryptionChanged( bool ),
453 this, showCryptedLabel( bool ) );
456 inline void MainInterface::initSystray()
458 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
459 bool b_systrayWanted = config_GetInt( p_intf, "qt-system-tray" );
461 if( config_GetInt( p_intf, "qt-start-minimized") > 0 )
463 if( b_systrayAvailable )
465 b_systrayWanted = true;
469 msg_Err( p_intf, "cannot start minimized without system tray bar" );
472 if( b_systrayAvailable && b_systrayWanted )
476 inline void MainInterface::askForPrivacy()
479 * Ask for the network policy on FIRST STARTUP
481 if( config_GetInt( p_intf, "qt-privacy-ask") )
483 QList<ConfigControl *> controls;
484 if( privacyDialog( &controls ) == QDialog::Accepted )
486 QList<ConfigControl *>::Iterator i;
487 for( i = controls.begin() ; i != controls.end() ; i++ )
489 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
490 c->doApply( p_intf );
493 config_PutInt( p_intf, "qt-privacy-ask" , 0 );
494 /* We have to save here because the user may not launch Prefs */
495 config_SaveConfigFile( p_intf, NULL );
500 int MainInterface::privacyDialog( QList<ConfigControl *> *controls )
502 QDialog *privacy = new QDialog( this );
504 privacy->setWindowTitle( qtr( "Privacy and Network Policies" ) );
506 QGridLayout *gLayout = new QGridLayout( privacy );
508 QGroupBox *blabla = new QGroupBox( qtr( "Privacy and Network Warning" ) );
509 QGridLayout *blablaLayout = new QGridLayout( blabla );
510 QLabel *text = new QLabel( qtr(
511 "<p>The <i>VideoLAN Team</i> doesn't like when an application goes "
512 "online without authorization.</p>\n "
513 "<p><i>VLC media player</i> can retreive limited information from "
514 "the Internet in order to get CD covers or to check "
515 "for available updates.</p>\n"
516 "<p><i>VLC media player</i> <b>DOES NOT</b> send or collect <b>ANY</b> "
517 "information, even anonymously, about your usage.</p>\n"
518 "<p>Therefore please select from the following options, the default being "
519 "almost no access to the web.</p>\n") );
520 text->setWordWrap( true );
521 text->setTextFormat( Qt::RichText );
523 blablaLayout->addWidget( text, 0, 0 ) ;
525 QGroupBox *options = new QGroupBox;
526 QGridLayout *optionsLayout = new QGridLayout( options );
528 gLayout->addWidget( blabla, 0, 0, 1, 3 );
529 gLayout->addWidget( options, 1, 0, 1, 3 );
530 module_config_t *p_config;
531 ConfigControl *control;
534 #define CONFIG_GENERIC( option, type ) \
535 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
538 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
539 p_config, options, false, optionsLayout, line ); \
540 controls->append( control ); \
543 #define CONFIG_GENERIC_NOBOOL( option, type ) \
544 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
547 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
548 p_config, options, optionsLayout, line ); \
549 controls->append( control ); \
552 CONFIG_GENERIC( "album-art", IntegerList ); line++;
554 CONFIG_GENERIC_NOBOOL( "qt-updates-notif", Bool ); line++;
557 QPushButton *ok = new QPushButton( qtr( "OK" ) );
559 gLayout->addWidget( ok, 2, 2 );
561 CONNECT( ok, clicked(), privacy, accept() );
562 return privacy->exec();
566 /**********************************************************************
567 * Handling of sizing of the components
568 **********************************************************************/
570 /* This function is probably wrong, but we don't have many many choices...
571 Since we can't know from the playlist Widget if we are inside a dock or not,
572 because the playlist Widget can be called by THEDP, as a separate windows for
574 Maybe the other solution is to redefine the sizeHint() of the playlist and
575 ask _parent->isFloating()...
576 If you think this would be better, please FIXME it...
579 QSize MainInterface::sizeHint() const
583 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
584 i_visualmode == QT_MINIMAL_MODE )
586 return mainVideoSize;
590 if( VISIBLE( bgWidget) ||
591 ( videoIsActive && videoWidget->isVisible() )
593 return mainVideoSize;
595 return mainBasedSize;
599 int nwidth = controls->sizeHint().width();
600 int nheight = controls->isVisible() ?
601 controls->size().height()
602 + inputC->size().height()
603 + menuBar()->size().height()
604 + statusBar()->size().height()
607 if( VISIBLE( bgWidget ) )
610 nheight += i_bg_height;
612 nheight += bgWidget->size().height();
613 nwidth = __MAX( nwidth, bgWidget->size().width() );
615 else if( videoIsActive && videoWidget->isVisible() )
617 nheight += videoWidget->sizeHint().height();
618 nwidth = __MAX( nwidth, videoWidget->sizeHint().width() );
621 if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget() )
623 nheight += dockPL->size().height();
624 nwidth = __MAX( nwidth, dockPL->size().width() );
625 msg_Warn( p_intf, "3 %i %i", nheight, nwidth );
628 return QSize( nwidth, nheight );
631 /* Video widget cannot do this synchronously as it runs in another thread */
632 /* Well, could it, actually ? Probably dangerous ... */
634 /* This function is called:
635 - toggling of minimal View
636 - through askUpdate() by Vout thread request video and resize video (zoom)
637 - Advanced buttons toggled
639 void MainInterface::doComponentsUpdate()
641 if( isFullScreen() || isMaximized() ) return;
643 msg_Dbg( p_intf, "Updating the geometry" );
644 /* Here we resize to sizeHint() and not adjustsize because we want
645 the videoWidget to be exactly the correctSize */
646 resize( sizeHint() );
653 void MainInterface::debug()
656 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
657 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
658 if( videoWidget && videoWidget->isVisible() )
660 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
661 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
666 void MainInterface::destroyPopupMenu()
668 QVLCMenu::PopupMenu(p_intf, false );
672 void MainInterface::toggleFSC()
674 if( !fullscreenControls ) return;
676 IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
677 QApplication::postEvent( fullscreenControls, eShow );
680 void MainInterface::popupMenu( const QPoint &p )
682 /* Ow, that's ugly: don't show the popup menu if cursor over
683 * the main menu bar or the status bar */
684 if( !childAt( p ) || ( ( childAt( p ) != menuBar() )
685 && ( childAt( p )->parentWidget() != statusBar() ) ) )
686 QVLCMenu::PopupMenu( p_intf, true );
689 /****************************************************************************
691 ****************************************************************************/
693 /* This event is used to deal with the fullscreen and always on top
694 issue conflict (bug in wx) */
695 class SetVideoOnTopQtEvent : public QEvent
698 SetVideoOnTopQtEvent( bool _onTop ) :
699 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
702 bool OnTop() const { return onTop; }
710 * Thou shall not call/resize/hide widgets from on another thread.
711 * This is wrong, and this is THE reason to emit signals on those Video Functions
713 WId MainInterface::requestVideo( vout_thread_t *p_nvout, int *pi_x,
714 int *pi_y, unsigned int *pi_width,
715 unsigned int *pi_height )
717 /* Request the videoWidget */
718 if( !videoWidget ) return 0;
719 WId ret = videoWidget->request( p_nvout,pi_x, pi_y,
720 pi_width, pi_height, b_keep_size );
721 if( ret ) /* The videoWidget is available */
723 /* Did we have a bg ? Hide it! */
724 if( VISIBLE( bgWidget) )
727 emit askBgWidgetToToggle();
730 bgWasVisible = false;
732 /* ask videoWidget to show */
733 emit askVideoToShow( *pi_width, *pi_height );
735 /* Consider the video active now */
736 videoIsActive = true;
743 /* Call from the WindowClose function */
744 void MainInterface::releaseVideo( void )
746 emit askReleaseVideo( );
749 /* Function that is CONNECTED to the previous emit */
750 void MainInterface::releaseVideoSlot( void )
752 videoWidget->release( );
756 /* Reset the bg state */
757 bgWasVisible = false;
761 videoIsActive = false;
763 /* Try to resize, except when you are in Fullscreen mode */
764 if( !isFullScreen() ) doComponentsUpdate();
767 /* Call from WindowControl function */
768 int MainInterface::controlVideo( int i_query, va_list args )
770 int i_ret = VLC_SUCCESS;
775 unsigned int i_width = va_arg( args, unsigned int );
776 unsigned int i_height = va_arg( args, unsigned int );
777 emit askVideoToResize( i_width, i_height );
781 case VOUT_SET_STAY_ON_TOP:
783 int i_arg = va_arg( args, int );
784 QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
788 i_ret = VLC_EGENERIC;
789 msg_Warn( p_intf, "unsupported control query" );
795 /*****************************************************************************
796 * Playlist, Visualisation and Menus handling
797 *****************************************************************************/
799 * Toggle the playlist widget or dialog
801 void MainInterface::togglePlaylist()
804 If no playlist exist, then create one and attach it to the DockPL*/
805 if( !playlistWidget )
807 playlistWidget = new PlaylistWidget( p_intf );
809 i_pl_dock = PL_UNDOCKED;
810 /* i_pl_dock = (pl_dock_e)getSettings()
811 ->value( "pl-dock-status", PL_UNDOCKED ).toInt(); */
813 if( i_pl_dock == PL_UNDOCKED )
815 playlistWidget->setWindowFlags( Qt::Window );
817 /* This will restore the geometry but will not work for position,
818 because of parenting */
819 QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
820 playlistWidget, QSize( 600, 300 ) );
824 mainLayout->insertWidget( 4, playlistWidget );
826 playlistVisible = true;
828 playlistWidget->show();
832 /* toggle the visibility of the playlist */
833 TOGGLEV( playlistWidget );
834 playlistVisible = !playlistVisible;
835 //doComponentsUpdate(); //resize( sizeHint() );
839 /* Function called from the menu to undock the playlist */
840 void MainInterface::undockPlaylist()
842 // dockPL->setFloating( true );
846 void MainInterface::dockPlaylist( pl_dock_e i_pos )
850 void MainInterface::toggleMinimalView( bool b_switch )
852 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
853 i_visualmode != QT_MINIMAL_MODE )
854 { /* NORMAL MODE then */
855 if( !videoWidget || videoWidget->isHidden() )
857 emit askBgWidgetToToggle();
861 /* If video is visible, then toggle the status of bgWidget */
862 bgWasVisible = !bgWasVisible;
866 i_bg_height = bgWidget->height();
868 menuBar()->setVisible( !b_switch );
869 controls->setVisible( !b_switch );
870 statusBar()->setVisible( !b_switch );
871 inputC->setVisible( !b_switch );
873 doComponentsUpdate();
875 emit minimalViewToggled( b_switch );
878 /* toggling advanced controls buttons */
879 void MainInterface::toggleAdvanced()
881 controls->toggleAdvanced();
882 // if( fullscreenControls ) fullscreenControls->toggleAdvanced();
885 /* Get the visibility status of the controls (hidden or not, advanced or not) */
886 int MainInterface::getControlsVisibilityStatus()
888 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
889 + CONTROLS_ADVANCED * controls->b_advancedVisible );
893 void MainInterface::visual()
895 if( !VISIBLE( visualSelector) )
897 visualSelector->show();
898 if( !THEMIM->getIM()->hasVideo() )
900 /* Show the background widget */
902 visualSelectorEnabled = true;
906 /* Stop any currently running visualization */
907 visualSelector->hide();
908 visualSelectorEnabled = false;
910 doComponentsUpdate();
914 /************************************************************************
916 ************************************************************************/
917 void MainInterface::setName( QString name )
919 input_name = name; /* store it for the QSystray use */
920 /* Display it in the status bar, but also as a Tooltip in case it doesn't
922 nameLabel->setText( " " + name + " " );
923 nameLabel->setToolTip( " " + name +" " );
927 * Give the decorations of the Main Window a correct Name.
928 * If nothing is given, set it to VLC...
930 void MainInterface::setVLCWindowsTitle( QString aTitle )
932 if( aTitle.isEmpty() )
934 setWindowTitle( qtr( "VLC media player" ) );
938 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
942 void MainInterface::showCryptedLabel( bool b_show )
944 if( cryptedLabel == NULL )
946 cryptedLabel = new QLabel;
947 // The lock icon is not the right one for DRM protection/scrambled.
948 //cryptedLabel->setPixmap( QPixmap( ":/lock" ) );
949 cryptedLabel->setText( "DRM" );
950 statusBar()->addWidget( cryptedLabel );
953 cryptedLabel->setVisible( b_show );
956 /*****************************************************************************
957 * Systray Icon and Systray Menu
958 *****************************************************************************/
961 * Create a SystemTray icon and a menu that would go with it.
962 * Connects to a click handler on the icon.
964 void MainInterface::createSystray()
967 if( QDate::currentDate().dayOfYear() >= 354 )
968 iconVLC = QIcon( QPixmap( ":/vlc128-christmas.png" ) );
970 iconVLC = QIcon( QPixmap( ":/vlc128.png" ) );
971 sysTray = new QSystemTrayIcon( iconVLC, this );
972 sysTray->setToolTip( qtr( "VLC media player" ));
974 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
975 systrayMenu->setIcon( iconVLC );
977 QVLCMenu::updateSystrayMenu( this, p_intf, true );
980 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
981 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
985 * Updates the Systray Icon's menu and toggle the main interface
987 void MainInterface::toggleUpdateSystrayMenu()
989 /* If hidden, show it */
995 else if( isMinimized() )
1003 /* Visible (possibly under other windows) */
1005 /* check if any visible window is above vlc in the z-order,
1006 * but ignore the ones always on top
1007 * and the ones which can't be activated */
1010 wi.cbSize = sizeof( WINDOWINFO );
1011 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
1012 hwnd && ( !IsWindowVisible( hwnd ) ||
1013 ( GetWindowInfo( hwnd, &wi ) &&
1014 (wi.dwExStyle&WS_EX_NOACTIVATE) ) );
1015 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
1016 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
1017 (wi.dwExStyle&WS_EX_TOPMOST) )
1029 QVLCMenu::updateSystrayMenu( this, p_intf );
1032 void MainInterface::handleSystrayClick(
1033 QSystemTrayIcon::ActivationReason reason )
1037 case QSystemTrayIcon::Trigger:
1038 case QSystemTrayIcon::DoubleClick:
1039 toggleUpdateSystrayMenu();
1041 case QSystemTrayIcon::MiddleClick:
1042 sysTray->showMessage( qtr( "VLC media player" ),
1043 qtr( "Control menu for the player" ),
1044 QSystemTrayIcon::Information, 3000 );
1052 * Updates the name of the systray Icon tooltip.
1053 * Doesn't check if the systray exists, check before you call it.
1055 void MainInterface::updateSystrayTooltipName( QString name )
1057 if( name.isEmpty() )
1059 sysTray->setToolTip( qtr( "VLC media player" ) );
1063 sysTray->setToolTip( name );
1064 if( notificationEnabled && ( isHidden() || isMinimized() ) )
1066 sysTray->showMessage( qtr( "VLC media player" ), name,
1067 QSystemTrayIcon::NoIcon, 3000 );
1071 QVLCMenu::updateSystrayMenu( this, p_intf );
1075 * Updates the status of the systray Icon tooltip.
1076 * Doesn't check if the systray exists, check before you call it.
1078 void MainInterface::updateSystrayTooltipStatus( int i_status )
1085 sysTray->setToolTip( qtr( "VLC media player" ) );
1090 sysTray->setToolTip( input_name );
1095 sysTray->setToolTip( input_name + " - "
1100 QVLCMenu::updateSystrayMenu( this, p_intf );
1103 /************************************************************************
1105 ************************************************************************/
1106 void MainInterface::dropEvent(QDropEvent *event)
1108 dropEventPlay( event, true );
1111 void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
1113 event->setDropAction( Qt::CopyAction );
1114 if( !event->possibleActions() & Qt::CopyAction )
1117 const QMimeData *mimeData = event->mimeData();
1119 /* D&D of a subtitles file, add it on the fly */
1120 if( mimeData->urls().size() == 1 )
1122 if( THEMIM->getIM()->hasInput() )
1124 if( !input_AddSubtitle( THEMIM->getInput(),
1125 qtu( toNativeSeparators(
1126 mimeData->urls()[0].toLocalFile() ) ),
1134 bool first = b_play;
1135 foreach( const QUrl &url, mimeData->urls() )
1137 QString s = toNativeSeparators( url.toLocalFile() );
1139 if( s.length() > 0 ) {
1140 playlist_Add( THEPL, qtu(s), NULL,
1141 PLAYLIST_APPEND | (first ? PLAYLIST_GO: 0),
1142 PLAYLIST_END, true, false );
1144 RecentsMRL::getInstance( p_intf )->addRecent( s );
1149 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1151 event->acceptProposedAction();
1153 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1155 event->acceptProposedAction();
1157 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1162 /************************************************************************
1164 ************************************************************************/
1165 void MainInterface::customEvent( QEvent *event )
1168 if( event->type() == PLDockEvent_Type )
1170 PlaylistDialog::killInstance();
1171 playlistEmbeddedFlag = true;
1173 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1178 if ( event->type() == (int)SetVideoOnTopEvent_Type )
1180 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1181 if( p_event->OnTop() )
1182 setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
1184 setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint);
1185 show(); /* necessary to apply window flags?? */
1189 void MainInterface::keyPressEvent( QKeyEvent *e )
1191 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() == Qt::Key_H )
1192 && !menuBar()->isVisible() )
1194 toggleMinimalView( false );
1198 int i_vlck = qtEventToVLCKey( e );
1201 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1208 void MainInterface::resizeEvent( QResizeEvent * event )
1212 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
1213 i_visualmode == QT_MINIMAL_MODE )
1215 mainVideoSize = size();
1219 if( VISIBLE( bgWidget) ||
1220 ( videoIsActive && videoWidget->isVisible() )
1222 mainVideoSize = size();
1224 mainBasedSize = size();
1229 void MainInterface::wheelEvent( QWheelEvent *e )
1231 int i_vlckey = qtWheelEventToVLCKey( e );
1232 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1236 void MainInterface::closeEvent( QCloseEvent *e )
1243 void MainInterface::toggleFullScreen( void )
1245 if( isFullScreen() )
1248 emit askUpdate(); // Needed if video was launched after the F11
1249 emit fullscreenInterfaceToggled( false );
1254 emit fullscreenInterfaceToggled( true );
1259 /*****************************************************************************
1260 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1261 * We don't show the menu directly here because we don't want the
1262 * caller to block for a too long time.
1263 *****************************************************************************/
1264 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1265 vlc_value_t old_val, vlc_value_t new_val, void *param )
1267 intf_thread_t *p_intf = (intf_thread_t *)param;
1269 if( p_intf->pf_show_dialog )
1271 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1272 new_val.b_bool, NULL );
1278 /*****************************************************************************
1279 * IntfShowCB: callback triggered by the intf-show libvlc variable.
1280 *****************************************************************************/
1281 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1282 vlc_value_t old_val, vlc_value_t new_val, void *param )
1284 intf_thread_t *p_intf = (intf_thread_t *)param;
1285 p_intf->p_sys->p_mi->toggleFSC();