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 */
64 #include <vlc_vout_window.h>
67 /* Callback prototypes */
68 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
69 vlc_value_t old_val, vlc_value_t new_val, void *param );
70 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
71 vlc_value_t old_val, vlc_value_t new_val, void *param );
73 MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
75 /* Variables initialisation */
76 // need_components_update = false;
79 playlistWidget = NULL;
81 videoIsActive = false;
82 playlistVisible = false;
84 fullscreenControls = NULL;
97 * Configuration and settings
98 * Pre-building of interface
101 setFocusPolicy( Qt::StrongFocus );
102 setAcceptDrops( true );
103 setWindowIcon( QApplication::windowIcon() );
104 setWindowOpacity( config_GetFloat( p_intf, "qt-opacity" ) );
106 /* Set The Video In emebedded Mode or not */
107 videoEmbeddedFlag = config_GetInt( p_intf, "embedded-video" );
109 /* Does the interface resize to video size or the opposite */
110 b_keep_size = !config_GetInt( p_intf, "qt-video-autoresize" );
112 /* Are we in the enhanced always-video mode or not ? */
113 i_visualmode = config_GetInt( p_intf, "qt-display-mode" );
115 /* Set the other interface settings */
116 settings = getSettings();
117 settings->beginGroup( "MainWindow" );
120 * Retrieve saved sizes for main window
121 * mainBasedSize = based window size for normal mode
122 * (no video, no background)
123 * mainVideoSize = window size with video (all modes)
125 mainBasedSize = settings->value( "mainBasedSize", QSize( 350, 120 ) ).toSize();
126 mainVideoSize = settings->value( "mainVideoSize", QSize( 400, 300 ) ).toSize();
128 /* Do we want anoying popups or not */
129 notificationEnabled = (bool)config_GetInt( p_intf, "qt-notification" );
136 /**************************
137 * UI and Widgets design
138 **************************/
139 setVLCWindowsTitle();
140 createMainWidget( settings );
145 QVLCMenu::createMenuBar( this, p_intf );
146 CONNECT( THEMIM->getIM(), voutListChanged( vout_thread_t **, int ),
147 this, destroyPopupMenu() );
150 /* Create a Dock to get the playlist */
151 dockPL = new QDockWidget( qtr( "Playlist" ), this );
152 dockPL->setSizePolicy( QSizePolicy::Preferred,
153 QSizePolicy::Expanding );
154 dockPL->setFeatures( QDockWidget::AllDockWidgetFeatures );
155 dockPL->setAllowedAreas( Qt::LeftDockWidgetArea
156 | Qt::RightDockWidgetArea
157 | Qt::BottomDockWidgetArea );
161 /********************
163 ********************/
164 MainInputManager::getInstance( p_intf );
166 /*********************************
167 * Create the Systray Management *
168 *********************************/
171 /**************************
172 * Various CONNECTs on IM *
173 **************************/
174 /* Connect the input manager to the GUI elements it manages */
177 * Connects on nameChanged()
178 * Those connects are not merged because different options can trigger
181 /* Naming in the controller statusbar */
182 CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
183 this, setName( const QString& ) );
184 /* and in the systray */
187 CONNECT( THEMIM->getIM(), nameChanged( const QString& ), this,
188 updateSystrayTooltipName( const QString& ) );
190 /* and in the title of the controller */
191 if( config_GetInt( p_intf, "qt-name-in-title" ) )
193 CONNECT( THEMIM->getIM(), nameChanged( const QString& ), this,
194 setVLCWindowsTitle( const QString& ) );
198 * CONNECTS on PLAY_STATUS
200 /* Status on the systray */
203 CONNECT( THEMIM->getIM(), statusChanged( int ),
204 this, updateSystrayTooltipStatus( int ) );
208 /* END CONNECTS ON IM */
213 var_AddCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
215 /* Register callback for the intf-popupmenu variable */
216 var_AddCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
219 /* VideoWidget connects for asynchronous calls */
220 connect( this, SIGNAL(askGetVideo(WId*,int*,int*,unsigned*,unsigned *)),
221 this, SLOT(getVideoSlot(WId*,int*,int*,unsigned*,unsigned*)),
222 Qt::BlockingQueuedConnection );
223 connect( this, SIGNAL(askReleaseVideo( void )),
224 this, SLOT(releaseVideoSlot( void )),
225 Qt::BlockingQueuedConnection );
229 CONNECT( this, askVideoToResize( unsigned int, unsigned int ),
230 videoWidget, SetSizing( unsigned int, unsigned int ) );
233 CONNECT( this, askUpdate(), this, doComponentsUpdate() );
234 CONNECT( THEDP, toolBarConfUpdated(), this, recreateToolbars() );
236 /* Size and placement of interface */
237 settings->beginGroup( "MainWindow" );
238 QVLCTools::restoreWidgetPosition( settings, this, QSize(380, 60) );
240 /* resize to previously saved main window size if appicable */
243 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
244 i_visualmode == QT_MINIMAL_MODE )
246 resize( mainVideoSize );
250 resize( mainBasedSize );
254 bool b_visible = settings->value( "playlist-visible", 0 ).toInt();
255 settings->endGroup();
258 if( b_visible ) togglePlaylist();
260 /* Enable the popup menu in the MI */
261 setContextMenuPolicy( Qt::CustomContextMenu );
262 CONNECT( this, customContextMenuRequested( const QPoint& ),
263 this, popupMenu( const QPoint& ) );
265 /* Final sizing and showing */
266 setMinimumWidth( __MAX( controls->sizeHint().width(),
267 menuBar()->sizeHint().width() ) );
268 setVisible( !b_shouldHide );
270 /* And switch to minimal view if needed
271 Must be called after the show() */
272 if( i_visualmode == QT_MINIMAL_MODE )
273 toggleMinimalView( true );
275 /* Update the geometry : It is useful if you switch between
278 resize( sizeHint() );
282 MainInterface::~MainInterface()
284 msg_Dbg( p_intf, "Destroying the main interface" );
286 /* Unsure we hide the videoWidget before destroying it */
287 if( videoIsActive ) videoWidget->hide();
289 /* Save playlist state */
293 QVLCTools::saveWidgetPosition( p_intf, "Playlist", playlistWidget );
295 delete playlistWidget;
298 /* Be sure to kill the actionsManager... FIXME */
299 ActionsManager::killInstance();
301 /* Delete the FSC controller */
302 delete fullscreenControls;
305 settings->beginGroup( "MainWindow" );
306 settings->setValue( "pl-dock-status", (int)i_pl_dock );
307 settings->setValue( "playlist-visible", (int)playlistVisible );
308 settings->setValue( "adv-controls",
309 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
311 settings->setValue( "mainBasedSize", mainBasedSize );
312 settings->setValue( "mainVideoSize", mainVideoSize );
315 settings->setValue( "backgroundSize", bgWidget->size() );
318 QVLCTools::saveWidgetPosition(settings, this);
319 settings->endGroup();
322 /* Unregister callbacks */
323 var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
324 var_DelCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
326 p_intf->p_sys->p_mi = NULL;
329 /*****************************
331 *****************************/
332 void MainInterface::recreateToolbars()
334 settings->beginGroup( "MainWindow" );
337 controls = new ControlsWidget( p_intf, false, this ); /* FIXME */
338 CONNECT( controls, advancedControlsToggled( bool ),
339 this, doComponentsUpdate() );
340 CONNECT( controls, sizeChanged(),
341 this, doComponentsUpdate() );
342 inputC = new InputControlsWidget( p_intf, this );
344 mainLayout->insertWidget( 2, inputC, 0, Qt::AlignBottom );
345 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
346 controls, 0, Qt::AlignBottom );
347 settings->endGroup();
350 void MainInterface::createMainWidget( QSettings *settings )
352 /* Create the main Widget and the mainLayout */
353 QWidget *main = new QWidget;
354 setCentralWidget( main );
355 mainLayout = new QVBoxLayout( main );
357 /* Margins, spacing */
358 main->setContentsMargins( 0, 0, 0, 0 );
359 main->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
360 mainLayout->setSpacing( 0 );
361 mainLayout->setMargin( 0 );
364 /* Disabled for now, they SUCK */
366 visualSelector = new VisualSelector( p_intf );
367 mainLayout->insertWidget( 0, visualSelector );
368 visualSelector->hide();
372 bgWidget = new BackgroundWidget( p_intf );
374 settings->value( "backgroundSize", QSize( 300, 200 ) ).toSize() );
375 bgWidget->updateGeometry();
377 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
378 i_visualmode != QT_MINIMAL_MODE )
383 /* And video Outputs */
384 if( videoEmbeddedFlag )
385 videoWidget = new VideoWidget( p_intf );
387 /* Create the CONTROLS Widget */
388 controls = new ControlsWidget( p_intf,
389 settings->value( "adv-controls", false ).toBool(), this );
390 CONNECT( controls, advancedControlsToggled( bool ),
391 this, doComponentsUpdate() );
392 CONNECT( controls, sizeChanged(),
393 this, doComponentsUpdate() );
394 inputC = new InputControlsWidget( p_intf, this );
397 /* Add the controls Widget to the main Widget */
398 mainLayout->insertWidget( 0, bgWidget );
399 if( videoWidget ) mainLayout->insertWidget( 0, videoWidget, 10 );
400 mainLayout->insertWidget( 2, inputC, 0, Qt::AlignBottom );
401 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
402 controls, 0, Qt::AlignBottom );
404 /* Finish the sizing */
405 main->updateGeometry();
407 getSettings()->endGroup();
411 /* Create the FULLSCREEN CONTROLS Widget */
412 if( config_GetInt( p_intf, "qt-fs-controller" ) )
414 fullscreenControls = new FullscreenControllerWidget( p_intf, this );
418 inline void MainInterface::createStatusBar()
423 /* Widgets Creation*/
424 QStatusBar *statusBarr = statusBar();
426 TimeLabel *timeLabel = new TimeLabel( p_intf );
427 nameLabel = new QLabel( this );
428 nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
429 | Qt::TextSelectableByKeyboard );
430 SpeedLabel *speedLabel = new SpeedLabel( p_intf, "1.00x", this );
432 /* Styling those labels */
433 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
434 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
435 nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
437 /* and adding those */
438 statusBarr->addWidget( nameLabel, 8 );
439 statusBarr->addPermanentWidget( speedLabel, 0 );
440 statusBarr->addPermanentWidget( timeLabel, 0 );
442 /* timeLabel behaviour:
443 - double clicking opens the goto time dialog
444 - right-clicking and clicking just toggle between remaining and
446 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
448 CONNECT( THEMIM->getIM(), encryptionChanged( bool ),
449 this, showCryptedLabel( bool ) );
452 inline void MainInterface::initSystray()
454 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
455 bool b_systrayWanted = config_GetInt( p_intf, "qt-system-tray" );
457 if( config_GetInt( p_intf, "qt-start-minimized") > 0 )
459 if( b_systrayAvailable )
461 b_systrayWanted = true;
465 msg_Err( p_intf, "cannot start minimized without system tray bar" );
468 if( b_systrayAvailable && b_systrayWanted )
472 inline void MainInterface::askForPrivacy()
475 * Ask for the network policy on FIRST STARTUP
477 if( config_GetInt( p_intf, "qt-privacy-ask") )
479 QList<ConfigControl *> controls;
480 if( privacyDialog( &controls ) == QDialog::Accepted )
482 QList<ConfigControl *>::Iterator i;
483 for( i = controls.begin() ; i != controls.end() ; i++ )
485 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
486 c->doApply( p_intf );
489 config_PutInt( p_intf, "qt-privacy-ask" , 0 );
490 /* We have to save here because the user may not launch Prefs */
491 config_SaveConfigFile( p_intf, NULL );
496 int MainInterface::privacyDialog( QList<ConfigControl *> *controls )
498 QDialog *privacy = new QDialog( this );
500 privacy->setWindowTitle( qtr( "Privacy and Network Policies" ) );
502 QGridLayout *gLayout = new QGridLayout( privacy );
504 QGroupBox *blabla = new QGroupBox( qtr( "Privacy and Network Warning" ) );
505 QGridLayout *blablaLayout = new QGridLayout( blabla );
506 QLabel *text = new QLabel( qtr(
507 "<p>The <i>VideoLAN Team</i> doesn't like when an application goes "
508 "online without authorization.</p>\n "
509 "<p><i>VLC media player</i> can retreive limited information from "
510 "the Internet in order to get CD covers or to check "
511 "for available updates.</p>\n"
512 "<p><i>VLC media player</i> <b>DOES NOT</b> send or collect <b>ANY</b> "
513 "information, even anonymously, about your usage.</p>\n"
514 "<p>Therefore please select from the following options, the default being "
515 "almost no access to the web.</p>\n") );
516 text->setWordWrap( true );
517 text->setTextFormat( Qt::RichText );
519 blablaLayout->addWidget( text, 0, 0 ) ;
521 QGroupBox *options = new QGroupBox;
522 QGridLayout *optionsLayout = new QGridLayout( options );
524 gLayout->addWidget( blabla, 0, 0, 1, 3 );
525 gLayout->addWidget( options, 1, 0, 1, 3 );
526 module_config_t *p_config;
527 ConfigControl *control;
530 #define CONFIG_GENERIC( option, type ) \
531 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
534 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
535 p_config, options, false, optionsLayout, line ); \
536 controls->append( control ); \
539 #define CONFIG_GENERIC_NOBOOL( option, type ) \
540 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
543 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
544 p_config, options, optionsLayout, line ); \
545 controls->append( control ); \
548 CONFIG_GENERIC( "album-art", IntegerList ); line++;
550 CONFIG_GENERIC_NOBOOL( "qt-updates-notif", Bool ); line++;
553 QPushButton *ok = new QPushButton( qtr( "OK" ) );
555 gLayout->addWidget( ok, 2, 2 );
557 CONNECT( ok, clicked(), privacy, accept() );
558 return privacy->exec();
562 /**********************************************************************
563 * Handling of sizing of the components
564 **********************************************************************/
566 /* This function is probably wrong, but we don't have many many choices...
567 Since we can't know from the playlist Widget if we are inside a dock or not,
568 because the playlist Widget can be called by THEDP, as a separate windows for
570 Maybe the other solution is to redefine the sizeHint() of the playlist and
571 ask _parent->isFloating()...
572 If you think this would be better, please FIXME it...
575 QSize MainInterface::sizeHint() const
579 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
580 i_visualmode == QT_MINIMAL_MODE )
582 return mainVideoSize;
586 if( VISIBLE( bgWidget) ||
587 ( videoIsActive && videoWidget->isVisible() )
589 return mainVideoSize;
591 return mainBasedSize;
595 int nwidth = controls->sizeHint().width();
596 int nheight = controls->isVisible() ?
597 controls->size().height()
598 + inputC->size().height()
599 + menuBar()->size().height()
600 + statusBar()->size().height()
603 if( VISIBLE( bgWidget ) )
606 nheight += i_bg_height;
608 nheight += bgWidget->size().height();
609 nwidth = __MAX( nwidth, bgWidget->size().width() );
611 else if( videoIsActive && videoWidget->isVisible() )
613 nheight += videoWidget->sizeHint().height();
614 nwidth = __MAX( nwidth, videoWidget->sizeHint().width() );
617 if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget() )
619 nheight += dockPL->size().height();
620 nwidth = __MAX( nwidth, dockPL->size().width() );
621 msg_Warn( p_intf, "3 %i %i", nheight, nwidth );
624 return QSize( nwidth, nheight );
627 /* Video widget cannot do this synchronously as it runs in another thread */
628 /* Well, could it, actually ? Probably dangerous ... */
630 /* This function is called:
631 - toggling of minimal View
632 - through askUpdate() by Vout thread request video and resize video (zoom)
633 - Advanced buttons toggled
635 void MainInterface::doComponentsUpdate()
637 if( isFullScreen() || isMaximized() ) return;
639 msg_Dbg( p_intf, "Updating the geometry" );
640 /* Here we resize to sizeHint() and not adjustsize because we want
641 the videoWidget to be exactly the correctSize */
642 resize( sizeHint() );
649 void MainInterface::debug()
652 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
653 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
654 if( videoWidget && videoWidget->isVisible() )
656 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
657 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
662 void MainInterface::destroyPopupMenu()
664 QVLCMenu::PopupMenu(p_intf, false );
668 void MainInterface::toggleFSC()
670 if( !fullscreenControls ) return;
672 IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
673 QApplication::postEvent( fullscreenControls, eShow );
676 void MainInterface::popupMenu( const QPoint &p )
678 /* Ow, that's ugly: don't show the popup menu if cursor over
679 * the main menu bar or the status bar */
680 if( !childAt( p ) || ( ( childAt( p ) != menuBar() )
681 && ( childAt( p )->parentWidget() != statusBar() ) ) )
682 QVLCMenu::PopupMenu( p_intf, true );
685 /****************************************************************************
687 ****************************************************************************/
689 /* This event is used to deal with the fullscreen and always on top
690 issue conflict (bug in wx) */
691 class SetVideoOnTopQtEvent : public QEvent
694 SetVideoOnTopQtEvent( bool _onTop ) :
695 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
698 bool OnTop() const { return onTop; }
706 * You must note change the state of this object or other Qt4 UI objects,
707 * from the video output thread - only from the Qt4 UI main loop thread.
708 * All window provider queries must be handled through signals or events.
709 * That's why we have all those emit statements...
711 WId MainInterface::getVideo( int *pi_x, int *pi_y,
712 unsigned int *pi_width, unsigned int *pi_height )
717 /* This is a blocking call signal. Results are returned through pointers.
718 * Beware of deadlocks! */
720 emit askGetVideo( &id, pi_x, pi_y, pi_width, pi_height );
724 void MainInterface::getVideoSlot( WId *p_id, int *pi_x, int *pi_y,
725 unsigned *pi_width, unsigned *pi_height )
727 /* Request the videoWidget */
728 WId ret = videoWidget->request( pi_x, pi_y,
729 pi_width, pi_height, b_keep_size );
731 if( ret ) /* The videoWidget is available */
733 /* Did we have a bg ? Hide it! */
734 if( VISIBLE( bgWidget) )
740 bgWasVisible = false;
742 /* ask videoWidget to show */
743 videoWidget->SetSizing( *pi_width, *pi_height );
745 /* Consider the video active now */
746 videoIsActive = true;
752 /* Asynchronous call from the WindowClose function */
753 void MainInterface::releaseVideo( void )
755 emit askReleaseVideo( );
758 /* Function that is CONNECTED to the previous emit */
759 void MainInterface::releaseVideoSlot( void )
761 videoWidget->release( );
765 /* Reset the bg state */
766 bgWasVisible = false;
770 videoIsActive = false;
772 /* Try to resize, except when you are in Fullscreen mode */
773 doComponentsUpdate();
776 /* Asynchronous call from WindowControl function */
777 int MainInterface::controlVideo( int i_query, va_list args )
781 case VOUT_WINDOW_SET_SIZE:
783 unsigned int i_width = va_arg( args, unsigned int );
784 unsigned int i_height = va_arg( args, unsigned int );
785 emit askVideoToResize( i_width, i_height );
789 case VOUT_WINDOW_SET_ON_TOP:
791 int i_arg = va_arg( args, int );
792 QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
796 msg_Warn( p_intf, "unsupported control query" );
801 /*****************************************************************************
802 * Playlist, Visualisation and Menus handling
803 *****************************************************************************/
805 * Toggle the playlist widget or dialog
807 void MainInterface::togglePlaylist()
810 If no playlist exist, then create one and attach it to the DockPL*/
811 if( !playlistWidget )
813 playlistWidget = new PlaylistWidget( p_intf );
815 i_pl_dock = PL_UNDOCKED;
816 /* i_pl_dock = (pl_dock_e)getSettings()
817 ->value( "pl-dock-status", PL_UNDOCKED ).toInt(); */
819 if( i_pl_dock == PL_UNDOCKED )
821 playlistWidget->setWindowFlags( Qt::Window );
823 /* This will restore the geometry but will not work for position,
824 because of parenting */
825 QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
826 playlistWidget, QSize( 600, 300 ) );
830 mainLayout->insertWidget( 4, playlistWidget );
832 playlistVisible = true;
834 playlistWidget->show();
838 /* toggle the visibility of the playlist */
839 TOGGLEV( playlistWidget );
840 playlistVisible = !playlistVisible;
841 //doComponentsUpdate(); //resize( sizeHint() );
845 /* Function called from the menu to undock the playlist */
846 void MainInterface::undockPlaylist()
848 // dockPL->setFloating( true );
852 void MainInterface::dockPlaylist( pl_dock_e i_pos )
856 void MainInterface::toggleMinimalView( bool b_switch )
858 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
859 i_visualmode != QT_MINIMAL_MODE )
860 { /* NORMAL MODE then */
861 if( !videoWidget || videoWidget->isHidden() )
867 /* If video is visible, then toggle the status of bgWidget */
868 bgWasVisible = !bgWasVisible;
872 i_bg_height = bgWidget->height();
874 menuBar()->setVisible( !b_switch );
875 controls->setVisible( !b_switch );
876 statusBar()->setVisible( !b_switch );
877 inputC->setVisible( !b_switch );
879 doComponentsUpdate();
881 emit minimalViewToggled( b_switch );
884 /* toggling advanced controls buttons */
885 void MainInterface::toggleAdvanced()
887 controls->toggleAdvanced();
888 // if( fullscreenControls ) fullscreenControls->toggleAdvanced();
891 /* Get the visibility status of the controls (hidden or not, advanced or not) */
892 int MainInterface::getControlsVisibilityStatus()
894 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
895 + CONTROLS_ADVANCED * controls->b_advancedVisible );
899 void MainInterface::visual()
901 if( !VISIBLE( visualSelector) )
903 visualSelector->show();
904 if( !THEMIM->getIM()->hasVideo() )
906 /* Show the background widget */
908 visualSelectorEnabled = true;
912 /* Stop any currently running visualization */
913 visualSelector->hide();
914 visualSelectorEnabled = false;
916 doComponentsUpdate();
920 /************************************************************************
922 ************************************************************************/
923 void MainInterface::setName( const QString& name )
925 input_name = name; /* store it for the QSystray use */
926 /* Display it in the status bar, but also as a Tooltip in case it doesn't
928 nameLabel->setText( " " + name + " " );
929 nameLabel->setToolTip( " " + name +" " );
933 * Give the decorations of the Main Window a correct Name.
934 * If nothing is given, set it to VLC...
936 void MainInterface::setVLCWindowsTitle( const QString& aTitle )
938 if( aTitle.isEmpty() )
940 setWindowTitle( qtr( "VLC media player" ) );
944 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
948 void MainInterface::showCryptedLabel( bool b_show )
950 if( cryptedLabel == NULL )
952 cryptedLabel = new QLabel;
953 // The lock icon is not the right one for DRM protection/scrambled.
954 //cryptedLabel->setPixmap( QPixmap( ":/lock" ) );
955 cryptedLabel->setText( "DRM" );
956 statusBar()->addWidget( cryptedLabel );
959 cryptedLabel->setVisible( b_show );
962 /*****************************************************************************
963 * Systray Icon and Systray Menu
964 *****************************************************************************/
967 * Create a SystemTray icon and a menu that would go with it.
968 * Connects to a click handler on the icon.
970 void MainInterface::createSystray()
973 if( QDate::currentDate().dayOfYear() >= 354 )
974 iconVLC = QIcon( QPixmap( ":/logo/vlc128-christmas.png" ) );
976 iconVLC = QIcon( QPixmap( ":/logo/vlc128.png" ) );
977 sysTray = new QSystemTrayIcon( iconVLC, this );
978 sysTray->setToolTip( qtr( "VLC media player" ));
980 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
981 systrayMenu->setIcon( iconVLC );
983 QVLCMenu::updateSystrayMenu( this, p_intf, true );
986 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
987 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
991 * Updates the Systray Icon's menu and toggle the main interface
993 void MainInterface::toggleUpdateSystrayMenu()
995 /* If hidden, show it */
1001 else if( isMinimized() )
1009 /* Visible (possibly under other windows) */
1011 /* check if any visible window is above vlc in the z-order,
1012 * but ignore the ones always on top
1013 * and the ones which can't be activated */
1016 wi.cbSize = sizeof( WINDOWINFO );
1017 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
1018 hwnd && ( !IsWindowVisible( hwnd ) ||
1019 ( GetWindowInfo( hwnd, &wi ) &&
1020 (wi.dwExStyle&WS_EX_NOACTIVATE) ) );
1021 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
1022 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
1023 (wi.dwExStyle&WS_EX_TOPMOST) )
1035 QVLCMenu::updateSystrayMenu( this, p_intf );
1038 void MainInterface::handleSystrayClick(
1039 QSystemTrayIcon::ActivationReason reason )
1043 case QSystemTrayIcon::Trigger:
1044 case QSystemTrayIcon::DoubleClick:
1045 toggleUpdateSystrayMenu();
1047 case QSystemTrayIcon::MiddleClick:
1048 sysTray->showMessage( qtr( "VLC media player" ),
1049 qtr( "Control menu for the player" ),
1050 QSystemTrayIcon::Information, 3000 );
1058 * Updates the name of the systray Icon tooltip.
1059 * Doesn't check if the systray exists, check before you call it.
1061 void MainInterface::updateSystrayTooltipName( const QString& name )
1063 if( name.isEmpty() )
1065 sysTray->setToolTip( qtr( "VLC media player" ) );
1069 sysTray->setToolTip( name );
1070 if( notificationEnabled && ( isHidden() || isMinimized() ) )
1072 sysTray->showMessage( qtr( "VLC media player" ), name,
1073 QSystemTrayIcon::NoIcon, 3000 );
1077 QVLCMenu::updateSystrayMenu( this, p_intf );
1081 * Updates the status of the systray Icon tooltip.
1082 * Doesn't check if the systray exists, check before you call it.
1084 void MainInterface::updateSystrayTooltipStatus( int i_status )
1091 sysTray->setToolTip( qtr( "VLC media player" ) );
1096 sysTray->setToolTip( input_name );
1101 sysTray->setToolTip( input_name + " - "
1106 QVLCMenu::updateSystrayMenu( this, p_intf );
1109 /************************************************************************
1111 ************************************************************************/
1112 void MainInterface::dropEvent(QDropEvent *event)
1114 dropEventPlay( event, true );
1117 void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
1119 event->setDropAction( Qt::CopyAction );
1120 if( !event->possibleActions() & Qt::CopyAction )
1123 const QMimeData *mimeData = event->mimeData();
1125 /* D&D of a subtitles file, add it on the fly */
1126 if( mimeData->urls().size() == 1 )
1128 if( THEMIM->getIM()->hasInput() )
1130 if( !input_AddSubtitle( THEMIM->getInput(),
1131 qtu( toNativeSeparators(
1132 mimeData->urls()[0].toLocalFile() ) ),
1140 bool first = b_play;
1141 foreach( const QUrl &url, mimeData->urls() )
1143 QString s = toNativeSeparators( url.toLocalFile() );
1145 if( s.length() > 0 ) {
1146 playlist_Add( THEPL, qtu(s), NULL,
1147 PLAYLIST_APPEND | (first ? PLAYLIST_GO: PLAYLIST_PREPARSE),
1148 PLAYLIST_END, true, pl_Unlocked );
1150 RecentsMRL::getInstance( p_intf )->addRecent( s );
1155 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1157 event->acceptProposedAction();
1159 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1161 event->acceptProposedAction();
1163 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1168 /************************************************************************
1170 ************************************************************************/
1171 void MainInterface::customEvent( QEvent *event )
1174 if( event->type() == PLDockEvent_Type )
1176 PlaylistDialog::killInstance();
1177 playlistEmbeddedFlag = true;
1179 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1184 if ( event->type() == (int)SetVideoOnTopEvent_Type )
1186 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1187 if( p_event->OnTop() )
1188 setWindowFlags( windowFlags() | Qt::WindowStaysOnTopHint );
1190 setWindowFlags( windowFlags() & ~Qt::WindowStaysOnTopHint );
1191 show(); /* necessary to apply window flags */
1195 void MainInterface::keyPressEvent( QKeyEvent *e )
1197 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() == Qt::Key_H )
1198 && !menuBar()->isVisible() )
1200 toggleMinimalView( false );
1204 int i_vlck = qtEventToVLCKey( e );
1207 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1214 void MainInterface::resizeEvent( QResizeEvent * event )
1218 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
1219 i_visualmode == QT_MINIMAL_MODE )
1221 mainVideoSize = size();
1225 if( VISIBLE( bgWidget) ||
1226 ( videoIsActive && videoWidget->isVisible() )
1228 mainVideoSize = size();
1230 mainBasedSize = size();
1235 void MainInterface::wheelEvent( QWheelEvent *e )
1237 int i_vlckey = qtWheelEventToVLCKey( e );
1238 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1242 void MainInterface::closeEvent( QCloseEvent *e )
1249 void MainInterface::toggleFullScreen( void )
1251 if( isFullScreen() )
1254 emit askUpdate(); // Needed if video was launched after the F11
1255 emit fullscreenInterfaceToggled( false );
1260 emit fullscreenInterfaceToggled( true );
1265 /*****************************************************************************
1266 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1267 * We don't show the menu directly here because we don't want the
1268 * caller to block for a too long time.
1269 *****************************************************************************/
1270 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1271 vlc_value_t old_val, vlc_value_t new_val, void *param )
1273 intf_thread_t *p_intf = (intf_thread_t *)param;
1275 if( p_intf->pf_show_dialog )
1277 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1278 new_val.b_bool, NULL );
1284 /*****************************************************************************
1285 * IntfShowCB: callback triggered by the intf-show libvlc variable.
1286 *****************************************************************************/
1287 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1288 vlc_value_t old_val, vlc_value_t new_val, void *param )
1290 intf_thread_t *p_intf = (intf_thread_t *)param;
1291 p_intf->p_sys->p_mi->toggleFSC();