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;
95 * Configuration and settings
96 * Pre-building of interface
99 setFocusPolicy( Qt::StrongFocus );
100 setAcceptDrops( true );
101 setWindowIcon( QApplication::windowIcon() );
102 setWindowOpacity( config_GetFloat( p_intf, "qt-opacity" ) );
104 /* Set The Video In emebedded Mode or not */
105 videoEmbeddedFlag = config_GetInt( p_intf, "embedded-video" );
107 /* Does the interface resize to video size or the opposite */
108 b_keep_size = !config_GetInt( p_intf, "qt-video-autoresize" );
110 /* Are we in the enhanced always-video mode or not ? */
111 i_visualmode = config_GetInt( p_intf, "qt-display-mode" );
113 /* Set the other interface settings */
114 settings = getSettings();
115 settings->beginGroup( "MainWindow" );
118 * Retrieve saved sizes for main window
119 * mainBasedSize = based window size for normal mode
120 * (no video, no background)
121 * mainVideoSize = window size with video (all modes)
123 mainBasedSize = settings->value( "mainBasedSize", QSize( 350, 120 ) ).toSize();
124 mainVideoSize = settings->value( "mainVideoSize", QSize( 400, 300 ) ).toSize();
126 /* Do we want anoying popups or not */
127 notificationEnabled = (bool)config_GetInt( p_intf, "qt-notification" );
134 /**************************
135 * UI and Widgets design
136 **************************/
137 setVLCWindowsTitle();
138 createMainWidget( settings );
143 QVLCMenu::createMenuBar( this, p_intf );
146 /* Create a Dock to get the playlist */
147 dockPL = new QDockWidget( qtr( "Playlist" ), this );
148 dockPL->setSizePolicy( QSizePolicy::Preferred,
149 QSizePolicy::Expanding );
150 dockPL->setFeatures( QDockWidget::AllDockWidgetFeatures );
151 dockPL->setAllowedAreas( Qt::LeftDockWidgetArea
152 | Qt::RightDockWidgetArea
153 | Qt::BottomDockWidgetArea );
157 /********************
159 ********************/
160 MainInputManager::getInstance( p_intf );
162 /**************************
163 * Various CONNECTs on IM *
164 **************************/
165 /* Connect the input manager to the GUI elements it manages */
168 * Connects on nameChanged()
169 * Those connects are not merged because different options can trigger
172 /* Naming in the controller statusbar */
173 CONNECT( THEMIM->getIM(), nameChanged( QString ),
174 this, setName( QString ) );
175 /* and in the systray */
178 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
179 updateSystrayTooltipName( QString ) );
181 /* and in the title of the controller */
182 if( config_GetInt( p_intf, "qt-name-in-title" ) )
184 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
185 setVLCWindowsTitle( QString ) );
189 * CONNECTS on PLAY_STATUS
191 /* Status on the systray */
194 CONNECT( THEMIM->getIM(), statusChanged( int ),
195 this, updateSystrayTooltipStatus( int ) );
198 /* END CONNECTS ON IM */
200 dialogHandler = new DialogHandler (p_intf);
205 var_AddCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
207 /* Register callback for the intf-popupmenu variable */
208 var_AddCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
211 /* VideoWidget connects to avoid different threads speaking to each other */
212 connect( this, SIGNAL(askReleaseVideo( void )),
213 this, SLOT(releaseVideoSlot( void )), Qt::BlockingQueuedConnection );
217 CONNECT( this, askVideoToResize( unsigned int, unsigned int ),
218 videoWidget, SetSizing( unsigned int, unsigned int ) );
220 connect( this, SIGNAL(askVideoToShow( unsigned int, unsigned int)),
221 videoWidget, SLOT(SetSizing(unsigned int, unsigned int )),
222 Qt::BlockingQueuedConnection );
225 CONNECT( this, askUpdate(), this, doComponentsUpdate() );
226 CONNECT( THEDP, toolBarConfUpdated(), this, recreateToolbars() );
228 /* Size and placement of interface */
229 settings->beginGroup( "MainWindow" );
230 QVLCTools::restoreWidgetPosition( settings, this, QSize(380, 60) );
232 /* resize to previously saved main window size if appicable */
235 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
236 i_visualmode == QT_MINIMAL_MODE )
238 resize( mainVideoSize );
242 resize( mainBasedSize );
246 bool b_visible = settings->value( "playlist-visible", 0 ).toInt();
247 settings->endGroup();
250 if( b_visible ) togglePlaylist();
252 /* Enable the popup menu in the MI */
253 setContextMenuPolicy( Qt::CustomContextMenu );
254 CONNECT( this, customContextMenuRequested( const QPoint& ),
255 this, popupMenu( const QPoint& ) );
257 /* Final sizing and showing */
258 setMinimumWidth( __MAX( controls->sizeHint().width(),
259 menuBar()->sizeHint().width() ) );
262 /* And switch to minimal view if needed
263 Must be called after the show() */
264 if( i_visualmode == QT_MINIMAL_MODE )
265 toggleMinimalView( true );
267 /* Update the geometry : It is useful if you switch between
270 resize( sizeHint() );
272 /*****************************************************
273 * End everything by creating the Systray Management *
274 *****************************************************/
278 MainInterface::~MainInterface()
280 msg_Dbg( p_intf, "Destroying the main interface" );
282 delete dialogHandler;
284 /* Unsure we hide the videoWidget before destroying it */
285 if( videoIsActive ) videoWidget->hide();
287 /* Save playlist state */
291 QVLCTools::saveWidgetPosition( p_intf, "Playlist", playlistWidget );
293 delete playlistWidget;
296 /* Be sure to kill the actionsManager... FIXME */
297 ActionsManager::killInstance();
299 /* Delete the FSC controller */
300 delete fullscreenControls;
303 settings->beginGroup( "MainWindow" );
304 settings->setValue( "pl-dock-status", (int)i_pl_dock );
305 settings->setValue( "playlist-visible", (int)playlistVisible );
306 settings->setValue( "adv-controls",
307 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
309 settings->setValue( "mainBasedSize", mainBasedSize );
310 settings->setValue( "mainVideoSize", mainVideoSize );
313 settings->setValue( "backgroundSize", bgWidget->size() );
316 QVLCTools::saveWidgetPosition(settings, this);
317 settings->endGroup();
320 /* Unregister callbacks */
321 var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
322 var_DelCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
324 p_intf->p_sys->p_mi = NULL;
327 /*****************************
329 *****************************/
330 void MainInterface::recreateToolbars()
332 settings->beginGroup( "MainWindow" );
335 controls = new ControlsWidget( p_intf, false, this ); /* FIXME */
336 CONNECT( controls, advancedControlsToggled( bool ),
337 this, doComponentsUpdate() );
338 CONNECT( controls, sizeChanged(),
339 this, doComponentsUpdate() );
340 inputC = new InputControlsWidget( p_intf, this );
342 mainLayout->insertWidget( 2, inputC, 0, Qt::AlignBottom );
343 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
344 controls, 0, Qt::AlignBottom );
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 );
355 /* Margins, spacing */
356 main->setContentsMargins( 0, 0, 0, 0 );
357 main->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
358 mainLayout->setSpacing( 0 );
359 mainLayout->setMargin( 0 );
362 /* Disabled for now, they SUCK */
364 visualSelector = new VisualSelector( p_intf );
365 mainLayout->insertWidget( 0, visualSelector );
366 visualSelector->hide();
370 bgWidget = new BackgroundWidget( p_intf );
372 settings->value( "backgroundSize", QSize( 300, 200 ) ).toSize() );
373 bgWidget->updateGeometry();
374 CONNECT( this, askBgWidgetToToggle(), bgWidget, toggle() );
376 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
377 i_visualmode != QT_MINIMAL_MODE )
382 /* And video Outputs */
383 if( videoEmbeddedFlag )
384 videoWidget = new VideoWidget( p_intf );
386 /* Create the CONTROLS Widget */
387 controls = new ControlsWidget( p_intf,
388 settings->value( "adv-controls", false ).toBool(), this );
389 CONNECT( controls, advancedControlsToggled( bool ),
390 this, doComponentsUpdate() );
391 CONNECT( controls, sizeChanged(),
392 this, doComponentsUpdate() );
393 inputC = new InputControlsWidget( p_intf, this );
396 /* Add the controls Widget to the main Widget */
397 mainLayout->insertWidget( 0, bgWidget );
398 if( videoWidget ) mainLayout->insertWidget( 0, videoWidget, 10 );
399 mainLayout->insertWidget( 2, inputC, 0, Qt::AlignBottom );
400 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
401 controls, 0, Qt::AlignBottom );
403 /* Finish the sizing */
404 main->updateGeometry();
406 getSettings()->endGroup();
410 /* Create the FULLSCREEN CONTROLS Widget */
411 if( config_GetInt( p_intf, "qt-fs-controller" ) )
413 fullscreenControls = new FullscreenControllerWidget( p_intf );
417 inline void MainInterface::createStatusBar()
422 /* Widgets Creation*/
423 QStatusBar *statusBarr = statusBar();
425 TimeLabel *timeLabel = new TimeLabel( p_intf );
426 nameLabel = new QLabel( this );
427 nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
428 | Qt::TextSelectableByKeyboard );
429 SpeedLabel *speedLabel = new SpeedLabel( p_intf, "1.00x", this );
431 /* Styling those labels */
432 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
433 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
434 nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
436 /* and adding those */
437 statusBarr->addWidget( nameLabel, 8 );
438 statusBarr->addPermanentWidget( speedLabel, 0 );
439 statusBarr->addPermanentWidget( timeLabel, 0 );
441 /* timeLabel behaviour:
442 - double clicking opens the goto time dialog
443 - right-clicking and clicking just toggle between remaining and
445 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
447 CONNECT( THEMIM->getIM(), encryptionChanged( bool ),
448 this, showCryptedLabel( bool ) );
451 inline void MainInterface::initSystray()
453 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
454 bool b_systrayWanted = config_GetInt( p_intf, "qt-system-tray" );
456 if( config_GetInt( p_intf, "qt-start-minimized") > 0 )
458 if( b_systrayAvailable )
460 b_systrayWanted = true;
464 msg_Err( p_intf, "cannot start minimized without system tray bar" );
467 if( b_systrayAvailable && b_systrayWanted )
471 inline void MainInterface::askForPrivacy()
474 * Ask for the network policy on FIRST STARTUP
476 if( config_GetInt( p_intf, "qt-privacy-ask") )
478 QList<ConfigControl *> controls;
479 if( privacyDialog( &controls ) == QDialog::Accepted )
481 QList<ConfigControl *>::Iterator i;
482 for( i = controls.begin() ; i != controls.end() ; i++ )
484 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
485 c->doApply( p_intf );
488 config_PutInt( p_intf, "qt-privacy-ask" , 0 );
489 /* We have to save here because the user may not launch Prefs */
490 config_SaveConfigFile( p_intf, NULL );
495 int MainInterface::privacyDialog( QList<ConfigControl *> *controls )
497 QDialog *privacy = new QDialog( this );
499 privacy->setWindowTitle( qtr( "Privacy and Network Policies" ) );
501 QGridLayout *gLayout = new QGridLayout( privacy );
503 QGroupBox *blabla = new QGroupBox( qtr( "Privacy and Network Warning" ) );
504 QGridLayout *blablaLayout = new QGridLayout( blabla );
505 QLabel *text = new QLabel( qtr(
506 "<p>The <i>VideoLAN Team</i> doesn't like when an application goes "
507 "online without authorization.</p>\n "
508 "<p><i>VLC media player</i> can retreive limited information from "
509 "the Internet in order to get CD covers or to check "
510 "for available updates.</p>\n"
511 "<p><i>VLC media player</i> <b>DOES NOT</b> send or collect <b>ANY</b> "
512 "information, even anonymously, about your usage.</p>\n"
513 "<p>Therefore please select from the following options, the default being "
514 "almost no access to the web.</p>\n") );
515 text->setWordWrap( true );
516 text->setTextFormat( Qt::RichText );
518 blablaLayout->addWidget( text, 0, 0 ) ;
520 QGroupBox *options = new QGroupBox;
521 QGridLayout *optionsLayout = new QGridLayout( options );
523 gLayout->addWidget( blabla, 0, 0, 1, 3 );
524 gLayout->addWidget( options, 1, 0, 1, 3 );
525 module_config_t *p_config;
526 ConfigControl *control;
529 #define CONFIG_GENERIC( option, type ) \
530 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
533 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
534 p_config, options, false, optionsLayout, line ); \
535 controls->append( control ); \
538 #define CONFIG_GENERIC_NOBOOL( option, type ) \
539 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
542 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
543 p_config, options, optionsLayout, line ); \
544 controls->append( control ); \
547 CONFIG_GENERIC( "album-art", IntegerList ); line++;
549 CONFIG_GENERIC_NOBOOL( "qt-updates-notif", Bool ); line++;
552 QPushButton *ok = new QPushButton( qtr( "OK" ) );
554 gLayout->addWidget( ok, 2, 2 );
556 CONNECT( ok, clicked(), privacy, accept() );
557 return privacy->exec();
561 /**********************************************************************
562 * Handling of sizing of the components
563 **********************************************************************/
565 /* This function is probably wrong, but we don't have many many choices...
566 Since we can't know from the playlist Widget if we are inside a dock or not,
567 because the playlist Widget can be called by THEDP, as a separate windows for
569 Maybe the other solution is to redefine the sizeHint() of the playlist and
570 ask _parent->isFloating()...
571 If you think this would be better, please FIXME it...
574 QSize MainInterface::sizeHint() const
578 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
579 i_visualmode == QT_MINIMAL_MODE )
581 return mainVideoSize;
585 if( VISIBLE( bgWidget) ||
586 ( videoIsActive && videoWidget->isVisible() )
588 return mainVideoSize;
590 return mainBasedSize;
594 int nwidth = controls->sizeHint().width();
595 int nheight = controls->isVisible() ?
596 controls->size().height()
597 + inputC->size().height()
598 + menuBar()->size().height()
599 + statusBar()->size().height()
602 if( VISIBLE( bgWidget ) )
605 nheight += i_bg_height;
607 nheight += bgWidget->size().height();
608 nwidth = __MAX( nwidth, bgWidget->size().width() );
610 else if( videoIsActive && videoWidget->isVisible() )
612 nheight += videoWidget->sizeHint().height();
613 nwidth = __MAX( nwidth, videoWidget->sizeHint().width() );
616 if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget() )
618 nheight += dockPL->size().height();
619 nwidth = __MAX( nwidth, dockPL->size().width() );
620 msg_Warn( p_intf, "3 %i %i", nheight, nwidth );
623 return QSize( nwidth, nheight );
626 /* Video widget cannot do this synchronously as it runs in another thread */
627 /* Well, could it, actually ? Probably dangerous ... */
629 /* This function is called:
630 - toggling of minimal View
631 - through askUpdate() by Vout thread request video and resize video (zoom)
632 - Advanced buttons toggled
634 void MainInterface::doComponentsUpdate()
636 msg_Dbg( p_intf, "Updating the geometry" );
637 /* Here we resize to sizeHint() and not adjustsize because we want
638 the videoWidget to be exactly the correctSize */
639 resize( sizeHint() );
646 void MainInterface::debug()
649 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
650 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
651 if( videoWidget && videoWidget->isVisible() )
653 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
654 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
659 void MainInterface::toggleFSC()
661 if( !fullscreenControls ) return;
663 IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
664 QApplication::postEvent( fullscreenControls, eShow );
667 void MainInterface::popupMenu( const QPoint &p )
669 /* Ow, that's ugly: don't show the popup menu if cursor over
670 * the main menu bar or the status bar */
671 if( !childAt( p ) || ( ( childAt( p ) != menuBar() )
672 && ( childAt( p )->parentWidget() != statusBar() ) ) )
673 QVLCMenu::PopupMenu( p_intf, true );
676 /****************************************************************************
678 ****************************************************************************/
680 /* This event is used to deal with the fullscreen and always on top
681 issue conflict (bug in wx) */
682 class SetVideoOnTopQtEvent : public QEvent
685 SetVideoOnTopQtEvent( bool _onTop ) :
686 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
689 bool OnTop() const { return onTop; }
697 * Thou shall not call/resize/hide widgets from on another thread.
698 * This is wrong, and this is THE reason to emit signals on those Video Functions
700 WId MainInterface::requestVideo( vout_thread_t *p_nvout, int *pi_x,
701 int *pi_y, unsigned int *pi_width,
702 unsigned int *pi_height )
704 /* Request the videoWidget */
705 WId ret = videoWidget->request( p_nvout,pi_x, pi_y,
706 pi_width, pi_height, b_keep_size );
707 if( ret ) /* The videoWidget is available */
709 /* Did we have a bg ? Hide it! */
710 if( VISIBLE( bgWidget) )
713 emit askBgWidgetToToggle();
716 bgWasVisible = false;
718 /* ask videoWidget to show */
719 emit askVideoToShow( *pi_width, *pi_height );
721 /* Consider the video active now */
722 videoIsActive = true;
729 /* Call from the WindowClose function */
730 void MainInterface::releaseVideo( void )
732 emit askReleaseVideo( );
735 /* Function that is CONNECTED to the previous emit */
736 void MainInterface::releaseVideoSlot( void )
738 videoWidget->release( );
742 /* Reset the bg state */
743 bgWasVisible = false;
747 videoIsActive = false;
749 /* Try to resize, except when you are in Fullscreen mode */
750 if( !isFullScreen() ) doComponentsUpdate();
753 /* Call from WindowControl function */
754 int MainInterface::controlVideo( int i_query, va_list args )
756 int i_ret = VLC_SUCCESS;
761 unsigned int i_width = va_arg( args, unsigned int );
762 unsigned int i_height = va_arg( args, unsigned int );
763 emit askVideoToResize( i_width, i_height );
767 case VOUT_SET_STAY_ON_TOP:
769 int i_arg = va_arg( args, int );
770 QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
774 i_ret = VLC_EGENERIC;
775 msg_Warn( p_intf, "unsupported control query" );
781 /*****************************************************************************
782 * Playlist, Visualisation and Menus handling
783 *****************************************************************************/
785 * Toggle the playlist widget or dialog
787 void MainInterface::togglePlaylist()
790 If no playlist exist, then create one and attach it to the DockPL*/
791 if( !playlistWidget )
793 playlistWidget = new PlaylistWidget( p_intf );
795 i_pl_dock = PL_UNDOCKED;
796 /* i_pl_dock = (pl_dock_e)getSettings()
797 ->value( "pl-dock-status", PL_UNDOCKED ).toInt(); */
799 if( i_pl_dock == PL_UNDOCKED )
801 playlistWidget->setWindowFlags( Qt::Window );
803 /* This will restore the geometry but will not work for position,
804 because of parenting */
805 QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
806 playlistWidget, QSize( 600, 300 ) );
810 mainLayout->insertWidget( 4, playlistWidget );
812 playlistVisible = true;
814 playlistWidget->show();
818 /* toggle the visibility of the playlist */
819 TOGGLEV( playlistWidget );
820 playlistVisible = !playlistVisible;
821 //doComponentsUpdate(); //resize( sizeHint() );
825 /* Function called from the menu to undock the playlist */
826 void MainInterface::undockPlaylist()
828 // dockPL->setFloating( true );
832 void MainInterface::dockPlaylist( pl_dock_e i_pos )
836 void MainInterface::toggleMinimalView( bool b_switch )
838 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
839 i_visualmode != QT_MINIMAL_MODE )
840 { /* NORMAL MODE then */
841 if( !videoWidget || videoWidget->isHidden() )
843 emit askBgWidgetToToggle();
847 /* If video is visible, then toggle the status of bgWidget */
848 bgWasVisible = !bgWasVisible;
852 i_bg_height = bgWidget->height();
854 menuBar()->setVisible( !b_switch );
855 controls->setVisible( !b_switch );
856 statusBar()->setVisible( !b_switch );
857 inputC->setVisible( !b_switch );
859 doComponentsUpdate();
861 emit minimalViewToggled( b_switch );
864 /* toggling advanced controls buttons */
865 void MainInterface::toggleAdvanced()
867 controls->toggleAdvanced();
868 // if( fullscreenControls ) fullscreenControls->toggleAdvanced();
871 /* Get the visibility status of the controls (hidden or not, advanced or not) */
872 int MainInterface::getControlsVisibilityStatus()
874 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
875 + CONTROLS_ADVANCED * controls->b_advancedVisible );
879 void MainInterface::visual()
881 if( !VISIBLE( visualSelector) )
883 visualSelector->show();
884 if( !THEMIM->getIM()->hasVideo() )
886 /* Show the background widget */
888 visualSelectorEnabled = true;
892 /* Stop any currently running visualization */
893 visualSelector->hide();
894 visualSelectorEnabled = false;
896 doComponentsUpdate();
900 /************************************************************************
902 ************************************************************************/
903 void MainInterface::setName( QString name )
905 input_name = name; /* store it for the QSystray use */
906 /* Display it in the status bar, but also as a Tooltip in case it doesn't
908 nameLabel->setText( " " + name + " " );
909 nameLabel->setToolTip( " " + name +" " );
913 * Give the decorations of the Main Window a correct Name.
914 * If nothing is given, set it to VLC...
916 void MainInterface::setVLCWindowsTitle( QString aTitle )
918 if( aTitle.isEmpty() )
920 setWindowTitle( qtr( "VLC media player" ) );
924 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
928 void MainInterface::showCryptedLabel( bool b_show )
930 if( cryptedLabel == NULL )
932 cryptedLabel = new QLabel;
933 // The lock icon is not the right one for DRM protection/scrambled.
934 //cryptedLabel->setPixmap( QPixmap( ":/lock" ) );
935 cryptedLabel->setText( "DRM" );
936 statusBar()->addWidget( cryptedLabel );
939 cryptedLabel->setVisible( b_show );
942 /*****************************************************************************
943 * Systray Icon and Systray Menu
944 *****************************************************************************/
947 * Create a SystemTray icon and a menu that would go with it.
948 * Connects to a click handler on the icon.
950 void MainInterface::createSystray()
953 if( QDate::currentDate().dayOfYear() >= 354 )
954 iconVLC = QIcon( QPixmap( ":/vlc128-christmas.png" ) );
956 iconVLC = QIcon( QPixmap( ":/vlc128.png" ) );
957 sysTray = new QSystemTrayIcon( iconVLC, this );
958 sysTray->setToolTip( qtr( "VLC media player" ));
960 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
961 systrayMenu->setIcon( iconVLC );
963 QVLCMenu::updateSystrayMenu( this, p_intf, true );
966 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
967 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
971 * Updates the Systray Icon's menu and toggle the main interface
973 void MainInterface::toggleUpdateSystrayMenu()
975 /* If hidden, show it */
981 else if( isMinimized() )
989 /* Visible (possibly under other windows) */
991 /* check if any visible window is above vlc in the z-order,
992 * but ignore the ones always on top
993 * and the ones which can't be activated */
996 wi.cbSize = sizeof( WINDOWINFO );
997 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
998 hwnd && ( !IsWindowVisible( hwnd ) ||
999 ( GetWindowInfo( hwnd, &wi ) &&
1000 (wi.dwExStyle&WS_EX_NOACTIVATE) ) );
1001 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
1002 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
1003 (wi.dwExStyle&WS_EX_TOPMOST) )
1015 QVLCMenu::updateSystrayMenu( this, p_intf );
1018 void MainInterface::handleSystrayClick(
1019 QSystemTrayIcon::ActivationReason reason )
1023 case QSystemTrayIcon::Trigger:
1024 case QSystemTrayIcon::DoubleClick:
1025 toggleUpdateSystrayMenu();
1027 case QSystemTrayIcon::MiddleClick:
1028 sysTray->showMessage( qtr( "VLC media player" ),
1029 qtr( "Control menu for the player" ),
1030 QSystemTrayIcon::Information, 3000 );
1038 * Updates the name of the systray Icon tooltip.
1039 * Doesn't check if the systray exists, check before you call it.
1041 void MainInterface::updateSystrayTooltipName( QString name )
1043 if( name.isEmpty() )
1045 sysTray->setToolTip( qtr( "VLC media player" ) );
1049 sysTray->setToolTip( name );
1050 if( notificationEnabled && ( isHidden() || isMinimized() ) )
1052 sysTray->showMessage( qtr( "VLC media player" ), name,
1053 QSystemTrayIcon::NoIcon, 3000 );
1057 QVLCMenu::updateSystrayMenu( this, p_intf );
1061 * Updates the status of the systray Icon tooltip.
1062 * Doesn't check if the systray exists, check before you call it.
1064 void MainInterface::updateSystrayTooltipStatus( int i_status )
1071 sysTray->setToolTip( qtr( "VLC media player" ) );
1076 sysTray->setToolTip( input_name );
1081 sysTray->setToolTip( input_name + " - "
1088 /************************************************************************
1090 ************************************************************************/
1091 void MainInterface::dropEvent(QDropEvent *event)
1093 dropEventPlay( event, true );
1096 void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
1098 const QMimeData *mimeData = event->mimeData();
1100 /* D&D of a subtitles file, add it on the fly */
1101 if( mimeData->urls().size() == 1 )
1103 if( THEMIM->getIM()->hasInput() )
1105 if( !input_AddSubtitle( THEMIM->getInput(),
1106 qtu( toNativeSeparators(
1107 mimeData->urls()[0].toLocalFile() ) ),
1110 event->acceptProposedAction();
1115 bool first = b_play;
1116 foreach( const QUrl &url, mimeData->urls() )
1118 QString s = toNativeSeparators( url.toLocalFile() );
1120 if( s.length() > 0 ) {
1121 playlist_Add( THEPL, qtu(s), NULL,
1122 PLAYLIST_APPEND | (first ? PLAYLIST_GO: 0),
1123 PLAYLIST_END, true, false );
1125 RecentsMRL::getInstance( p_intf )->addRecent( s );
1128 event->acceptProposedAction();
1130 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1132 event->acceptProposedAction();
1134 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1136 event->acceptProposedAction();
1138 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1143 /************************************************************************
1145 ************************************************************************/
1146 void MainInterface::customEvent( QEvent *event )
1149 if( event->type() == PLDockEvent_Type )
1151 PlaylistDialog::killInstance();
1152 playlistEmbeddedFlag = true;
1154 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1159 if ( event->type() == (int)SetVideoOnTopEvent_Type )
1161 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1162 if( p_event->OnTop() )
1163 setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
1165 setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint);
1166 show(); /* necessary to apply window flags?? */
1170 void MainInterface::keyPressEvent( QKeyEvent *e )
1172 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() == Qt::Key_H )
1173 && !menuBar()->isVisible() )
1175 toggleMinimalView( false );
1179 int i_vlck = qtEventToVLCKey( e );
1182 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1189 void MainInterface::resizeEvent( QResizeEvent * event )
1193 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
1194 i_visualmode == QT_MINIMAL_MODE )
1196 mainVideoSize = size();
1200 if( VISIBLE( bgWidget) ||
1201 ( videoIsActive && videoWidget->isVisible() )
1203 mainVideoSize = size();
1205 mainBasedSize = size();
1210 void MainInterface::wheelEvent( QWheelEvent *e )
1212 int i_vlckey = qtWheelEventToVLCKey( e );
1213 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1217 void MainInterface::closeEvent( QCloseEvent *e )
1224 void MainInterface::toggleFullScreen( void )
1226 if( isFullScreen() )
1229 emit askUpdate(); // Needed if video was launched after the F11
1230 emit fullscreenInterfaceToggled( false );
1235 emit fullscreenInterfaceToggled( true );
1240 /*****************************************************************************
1241 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1242 * We don't show the menu directly here because we don't want the
1243 * caller to block for a too long time.
1244 *****************************************************************************/
1245 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1246 vlc_value_t old_val, vlc_value_t new_val, void *param )
1248 intf_thread_t *p_intf = (intf_thread_t *)param;
1250 if( p_intf->pf_show_dialog )
1252 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1253 new_val.b_bool, NULL );
1259 /*****************************************************************************
1260 * IntfShowCB: callback triggered by the intf-show libvlc variable.
1261 *****************************************************************************/
1262 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1263 vlc_value_t old_val, vlc_value_t new_val, void *param )
1265 intf_thread_t *p_intf = (intf_thread_t *)param;
1266 p_intf->p_sys->p_mi->toggleFSC();