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 ) );
231 CONNECT( this, askVideoSetFullScreen( bool ),
232 videoWidget, SetFullScreen( bool ) );
233 CONNECT( videoWidget, keyPressed( QKeyEvent * ),
234 this, handleKeyPress( QKeyEvent * ) );
237 CONNECT( this, askUpdate(), this, doComponentsUpdate() );
238 CONNECT( THEDP, toolBarConfUpdated(), this, recreateToolbars() );
240 /* Size and placement of interface */
241 settings->beginGroup( "MainWindow" );
242 QVLCTools::restoreWidgetPosition( settings, this, QSize(380, 60) );
244 /* resize to previously saved main window size if appicable */
247 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
248 i_visualmode == QT_MINIMAL_MODE )
250 resize( mainVideoSize );
254 resize( mainBasedSize );
258 bool b_visible = settings->value( "playlist-visible", 0 ).toInt();
259 settings->endGroup();
262 if( b_visible ) togglePlaylist();
264 /* Enable the popup menu in the MI */
265 setContextMenuPolicy( Qt::CustomContextMenu );
266 CONNECT( this, customContextMenuRequested( const QPoint& ),
267 this, popupMenu( const QPoint& ) );
269 /* Final sizing and showing */
270 setMinimumWidth( __MAX( controls->sizeHint().width(),
271 menuBar()->sizeHint().width() ) );
272 setVisible( !b_shouldHide );
274 /* And switch to minimal view if needed
275 Must be called after the show() */
276 if( i_visualmode == QT_MINIMAL_MODE )
277 toggleMinimalView( true );
279 /* Update the geometry : It is useful if you switch between
282 resize( sizeHint() );
286 MainInterface::~MainInterface()
288 msg_Dbg( p_intf, "Destroying the main interface" );
290 /* Unsure we hide the videoWidget before destroying it */
291 if( videoIsActive ) videoWidget->hide();
293 /* Save playlist state */
297 QVLCTools::saveWidgetPosition( p_intf, "Playlist", playlistWidget );
299 delete playlistWidget;
302 /* Be sure to kill the actionsManager... FIXME */
303 ActionsManager::killInstance();
305 /* Delete the FSC controller */
306 delete fullscreenControls;
309 settings->beginGroup( "MainWindow" );
310 settings->setValue( "pl-dock-status", (int)i_pl_dock );
311 settings->setValue( "playlist-visible", (int)playlistVisible );
312 settings->setValue( "adv-controls",
313 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
315 settings->setValue( "mainBasedSize", mainBasedSize );
316 settings->setValue( "mainVideoSize", mainVideoSize );
319 settings->setValue( "backgroundSize", bgWidget->size() );
322 QVLCTools::saveWidgetPosition(settings, this);
323 settings->endGroup();
326 /* Unregister callbacks */
327 var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
328 var_DelCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
330 p_intf->p_sys->p_mi = NULL;
333 /*****************************
335 *****************************/
336 void MainInterface::recreateToolbars()
338 msg_Dbg( p_intf, "Recreating the toolbars" );
339 settings->beginGroup( "MainWindow" );
342 controls = new ControlsWidget( p_intf, false, this ); /* FIXME */
343 CONNECT( controls, advancedControlsToggled( bool ),
344 this, doComponentsUpdate() );
345 CONNECT( controls, sizeChanged(),
346 this, doComponentsUpdate() );
347 inputC = new InputControlsWidget( p_intf, this );
349 mainLayout->addWidget( inputC, 2, 0, 1, -1, Qt::AlignBottom );
350 mainLayout->addWidget( controls, settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
351 0, 1, -1, Qt::AlignBottom );
352 settings->endGroup();
355 void MainInterface::createMainWidget( QSettings *settings )
357 /* Create the main Widget and the mainLayout */
358 QWidget *main = new QWidget;
359 setCentralWidget( main );
360 mainLayout = new QGridLayout( main );
362 /* Margins, spacing */
363 main->setContentsMargins( 0, 0, 0, 0 );
364 main->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
365 mainLayout->setSpacing( 0 );
366 mainLayout->setMargin( 0 );
369 /* Disabled for now, they SUCK */
371 visualSelector = new VisualSelector( p_intf );
372 mainLayout->insertWidget( 0, visualSelector );
373 visualSelector->hide();
377 bgWidget = new BackgroundWidget( p_intf );
379 settings->value( "backgroundSize", QSize( 300, 200 ) ).toSize() );
380 bgWidget->updateGeometry();
382 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
383 i_visualmode != QT_MINIMAL_MODE )
388 /* And video Outputs */
389 if( videoEmbeddedFlag )
390 videoWidget = new VideoWidget( p_intf );
392 /* Create the CONTROLS Widget */
393 controls = new ControlsWidget( p_intf,
394 settings->value( "adv-controls", false ).toBool(), this );
395 CONNECT( controls, advancedControlsToggled( bool ),
396 this, doComponentsUpdate() );
397 CONNECT( controls, sizeChanged(),
398 this, doComponentsUpdate() );
399 inputC = new InputControlsWidget( p_intf, this );
402 /* Add the controls Widget to the main Widget */
404 mainLayout->addWidget( videoWidget, 0, 0, 1, -1 );
405 mainLayout->setRowStretch( 0, 10 );
407 mainLayout->addWidget( bgWidget, 1, 0, 1, -1 );
408 //mainLayout->setRowStretch( 1, 10 );
409 mainLayout->addWidget( inputC, 2, 0, 1, -1, Qt::AlignBottom );
410 mainLayout->addWidget( controls, settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
411 0, 1, -1, Qt::AlignBottom );
413 /* Finish the sizing */
414 main->updateGeometry();
416 getSettings()->endGroup();
420 /* Create the FULLSCREEN CONTROLS Widget */
421 if( config_GetInt( p_intf, "qt-fs-controller" ) )
423 fullscreenControls = new FullscreenControllerWidget( p_intf, this );
424 CONNECT( fullscreenControls, keyPressed( QKeyEvent * ),
425 this, handleKeyPress( QKeyEvent * ) );
429 inline void MainInterface::createStatusBar()
434 /* Widgets Creation*/
435 QStatusBar *statusBarr = statusBar();
437 TimeLabel *timeLabel = new TimeLabel( p_intf );
438 nameLabel = new QLabel( this );
439 nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
440 | Qt::TextSelectableByKeyboard );
441 SpeedLabel *speedLabel = new SpeedLabel( p_intf, "1.00x", this );
443 /* Styling those labels */
444 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
445 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
446 nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
448 /* and adding those */
449 statusBarr->addWidget( nameLabel, 8 );
450 statusBarr->addPermanentWidget( speedLabel, 0 );
451 statusBarr->addPermanentWidget( timeLabel, 0 );
453 /* timeLabel behaviour:
454 - double clicking opens the goto time dialog
455 - right-clicking and clicking just toggle between remaining and
457 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
459 CONNECT( THEMIM->getIM(), encryptionChanged( bool ),
460 this, showCryptedLabel( bool ) );
463 inline void MainInterface::initSystray()
465 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
466 bool b_systrayWanted = config_GetInt( p_intf, "qt-system-tray" );
468 if( config_GetInt( p_intf, "qt-start-minimized") > 0 )
470 if( b_systrayAvailable )
472 b_systrayWanted = true;
476 msg_Err( p_intf, "cannot start minimized without system tray bar" );
479 if( b_systrayAvailable && b_systrayWanted )
483 inline void MainInterface::askForPrivacy()
486 * Ask for the network policy on FIRST STARTUP
488 if( config_GetInt( p_intf, "qt-privacy-ask") )
490 QList<ConfigControl *> controls;
491 if( privacyDialog( &controls ) == QDialog::Accepted )
493 QList<ConfigControl *>::Iterator i;
494 for( i = controls.begin() ; i != controls.end() ; i++ )
496 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
497 c->doApply( p_intf );
500 config_PutInt( p_intf, "qt-privacy-ask" , 0 );
501 /* We have to save here because the user may not launch Prefs */
502 config_SaveConfigFile( p_intf, NULL );
507 int MainInterface::privacyDialog( QList<ConfigControl *> *controls )
509 QDialog *privacy = new QDialog( this );
511 privacy->setWindowTitle( qtr( "Privacy and Network Policies" ) );
513 QGridLayout *gLayout = new QGridLayout( privacy );
515 QGroupBox *blabla = new QGroupBox( qtr( "Privacy and Network Warning" ) );
516 QGridLayout *blablaLayout = new QGridLayout( blabla );
517 QLabel *text = new QLabel( qtr(
518 "<p>The <i>VideoLAN Team</i> doesn't like when an application goes "
519 "online without authorization.</p>\n "
520 "<p><i>VLC media player</i> can retreive limited information from "
521 "the Internet in order to get CD covers or to check "
522 "for available updates.</p>\n"
523 "<p><i>VLC media player</i> <b>DOES NOT</b> send or collect <b>ANY</b> "
524 "information, even anonymously, about your usage.</p>\n"
525 "<p>Therefore please select from the following options, the default being "
526 "almost no access to the web.</p>\n") );
527 text->setWordWrap( true );
528 text->setTextFormat( Qt::RichText );
530 blablaLayout->addWidget( text, 0, 0 ) ;
532 QGroupBox *options = new QGroupBox;
533 QGridLayout *optionsLayout = new QGridLayout( options );
535 gLayout->addWidget( blabla, 0, 0, 1, 3 );
536 gLayout->addWidget( options, 1, 0, 1, 3 );
537 module_config_t *p_config;
538 ConfigControl *control;
541 #define CONFIG_GENERIC( option, type ) \
542 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
545 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
546 p_config, options, false, optionsLayout, line ); \
547 controls->append( control ); \
550 #define CONFIG_GENERIC_NOBOOL( option, type ) \
551 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
554 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
555 p_config, options, optionsLayout, line ); \
556 controls->append( control ); \
559 CONFIG_GENERIC( "album-art", IntegerList ); line++;
561 CONFIG_GENERIC_NOBOOL( "qt-updates-notif", Bool ); line++;
564 QPushButton *ok = new QPushButton( qtr( "OK" ) );
566 gLayout->addWidget( ok, 2, 2 );
568 CONNECT( ok, clicked(), privacy, accept() );
569 return privacy->exec();
573 /**********************************************************************
574 * Handling of sizing of the components
575 **********************************************************************/
577 /* This function is probably wrong, but we don't have many many choices...
578 Since we can't know from the playlist Widget if we are inside a dock or not,
579 because the playlist Widget can be called by THEDP, as a separate windows for
581 Maybe the other solution is to redefine the sizeHint() of the playlist and
582 ask _parent->isFloating()...
583 If you think this would be better, please FIXME it...
586 QSize MainInterface::sizeHint() const
590 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
591 i_visualmode == QT_MINIMAL_MODE )
593 return mainVideoSize;
597 if( VISIBLE( bgWidget) ||
598 ( videoIsActive && videoWidget->isVisible() )
600 return mainVideoSize;
602 return mainBasedSize;
606 int nwidth = controls->sizeHint().width();
607 int nheight = controls->isVisible() ?
608 controls->size().height()
609 + inputC->size().height()
610 + menuBar()->size().height()
611 + statusBar()->size().height()
614 if( VISIBLE( bgWidget ) )
617 nheight += i_bg_height;
619 nheight += bgWidget->size().height();
620 nwidth = __MAX( nwidth, bgWidget->size().width() );
622 else if( videoIsActive && videoWidget->isVisible() )
624 nheight += videoWidget->sizeHint().height();
625 nwidth = __MAX( nwidth, videoWidget->sizeHint().width() );
628 if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget() )
630 nheight += dockPL->size().height();
631 nwidth = __MAX( nwidth, dockPL->size().width() );
632 msg_Warn( p_intf, "3 %i %i", nheight, nwidth );
635 return QSize( nwidth, nheight );
638 /* Video widget cannot do this synchronously as it runs in another thread */
639 /* Well, could it, actually ? Probably dangerous ... */
641 /* This function is called:
642 - toggling of minimal View
643 - through askUpdate() by Vout thread request video and resize video (zoom)
644 - Advanced buttons toggled
646 void MainInterface::doComponentsUpdate()
648 if( isFullScreen() || isMaximized() ) return;
650 msg_Dbg( p_intf, "Updating the geometry" );
651 /* Here we resize to sizeHint() and not adjustsize because we want
652 the videoWidget to be exactly the correctSize */
653 resize( sizeHint() );
660 void MainInterface::debug()
663 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
664 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
665 if( videoWidget && videoWidget->isVisible() )
667 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
668 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
673 void MainInterface::destroyPopupMenu()
675 QVLCMenu::PopupMenu(p_intf, false );
679 void MainInterface::toggleFSC()
681 if( !fullscreenControls ) return;
683 IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
684 QApplication::postEvent( fullscreenControls, eShow );
687 void MainInterface::popupMenu( const QPoint &p )
689 /* Ow, that's ugly: don't show the popup menu if cursor over
690 * the main menu bar or the status bar */
691 if( !childAt( p ) || ( ( childAt( p ) != menuBar() )
692 && ( childAt( p )->parentWidget() != statusBar() ) ) )
693 QVLCMenu::PopupMenu( p_intf, true );
696 /****************************************************************************
698 ****************************************************************************/
700 /* This event is used to deal with the fullscreen and always on top
701 issue conflict (bug in wx) */
702 class SetVideoOnTopQtEvent : public QEvent
705 SetVideoOnTopQtEvent( bool _onTop ) :
706 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
709 bool OnTop() const { return onTop; }
717 * You must note change the state of this object or other Qt4 UI objects,
718 * from the video output thread - only from the Qt4 UI main loop thread.
719 * All window provider queries must be handled through signals or events.
720 * That's why we have all those emit statements...
722 WId MainInterface::getVideo( int *pi_x, int *pi_y,
723 unsigned int *pi_width, unsigned int *pi_height )
728 /* This is a blocking call signal. Results are returned through pointers.
729 * Beware of deadlocks! */
731 emit askGetVideo( &id, pi_x, pi_y, pi_width, pi_height );
735 void MainInterface::getVideoSlot( WId *p_id, int *pi_x, int *pi_y,
736 unsigned *pi_width, unsigned *pi_height )
738 /* Request the videoWidget */
739 WId ret = videoWidget->request( pi_x, pi_y,
740 pi_width, pi_height, b_keep_size );
742 if( ret ) /* The videoWidget is available */
744 /* Did we have a bg ? Hide it! */
745 if( VISIBLE( bgWidget) )
751 bgWasVisible = false;
753 /* ask videoWidget to show */
754 videoWidget->SetSizing( *pi_width, *pi_height );
756 /* Consider the video active now */
757 videoIsActive = true;
763 /* Asynchronous call from the WindowClose function */
764 void MainInterface::releaseVideo( void )
766 emit askReleaseVideo( );
769 /* Function that is CONNECTED to the previous emit */
770 void MainInterface::releaseVideoSlot( void )
772 videoWidget->release( );
776 /* Reset the bg state */
777 bgWasVisible = false;
781 videoIsActive = false;
783 /* Try to resize, except when you are in Fullscreen mode */
784 doComponentsUpdate();
787 /* Asynchronous call from WindowControl function */
788 int MainInterface::controlVideo( int i_query, va_list args )
792 case VOUT_WINDOW_SET_SIZE:
794 unsigned int i_width = va_arg( args, unsigned int );
795 unsigned int i_height = va_arg( args, unsigned int );
796 emit askVideoToResize( i_width, i_height );
800 case VOUT_WINDOW_SET_ON_TOP:
802 int i_arg = va_arg( args, int );
803 QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
806 case VOUT_WINDOW_SET_FULLSCREEN:
808 bool b_fs = va_arg( args, int );
809 emit askVideoSetFullScreen( b_fs );
813 msg_Warn( p_intf, "unsupported control query" );
818 /*****************************************************************************
819 * Playlist, Visualisation and Menus handling
820 *****************************************************************************/
822 * Toggle the playlist widget or dialog
824 void MainInterface::togglePlaylist()
827 If no playlist exist, then create one and attach it to the DockPL*/
828 if( !playlistWidget )
830 playlistWidget = new PlaylistWidget( p_intf );
832 i_pl_dock = PL_UNDOCKED;
833 /* i_pl_dock = (pl_dock_e)getSettings()
834 ->value( "pl-dock-status", PL_UNDOCKED ).toInt(); */
836 if( i_pl_dock == PL_UNDOCKED )
838 playlistWidget->setWindowFlags( Qt::Window );
840 /* This will restore the geometry but will not work for position,
841 because of parenting */
842 QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
843 playlistWidget, QSize( 600, 300 ) );
847 // mainLayout->insertWidget( 4, playlistWidget );
849 playlistVisible = true;
851 playlistWidget->show();
855 /* toggle the visibility of the playlist */
856 TOGGLEV( playlistWidget );
857 playlistVisible = !playlistVisible;
858 //doComponentsUpdate(); //resize( sizeHint() );
862 /* Function called from the menu to undock the playlist */
863 void MainInterface::undockPlaylist()
865 // dockPL->setFloating( true );
869 void MainInterface::dockPlaylist( pl_dock_e i_pos )
873 void MainInterface::toggleMinimalView( bool b_switch )
875 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
876 i_visualmode != QT_MINIMAL_MODE )
877 { /* NORMAL MODE then */
878 if( !videoWidget || videoWidget->isHidden() )
884 /* If video is visible, then toggle the status of bgWidget */
885 bgWasVisible = !bgWasVisible;
889 i_bg_height = bgWidget->height();
891 menuBar()->setVisible( !b_switch );
892 controls->setVisible( !b_switch );
893 statusBar()->setVisible( !b_switch );
894 inputC->setVisible( !b_switch );
896 doComponentsUpdate();
898 emit minimalViewToggled( b_switch );
901 /* toggling advanced controls buttons */
902 void MainInterface::toggleAdvanced()
904 controls->toggleAdvanced();
905 // if( fullscreenControls ) fullscreenControls->toggleAdvanced();
908 /* Get the visibility status of the controls (hidden or not, advanced or not) */
909 int MainInterface::getControlsVisibilityStatus()
911 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
912 + CONTROLS_ADVANCED * controls->b_advancedVisible );
916 void MainInterface::visual()
918 if( !VISIBLE( visualSelector) )
920 visualSelector->show();
921 if( !THEMIM->getIM()->hasVideo() )
923 /* Show the background widget */
925 visualSelectorEnabled = true;
929 /* Stop any currently running visualization */
930 visualSelector->hide();
931 visualSelectorEnabled = false;
933 doComponentsUpdate();
937 /************************************************************************
939 ************************************************************************/
940 void MainInterface::setName( const QString& name )
942 input_name = name; /* store it for the QSystray use */
943 /* Display it in the status bar, but also as a Tooltip in case it doesn't
945 nameLabel->setText( " " + name + " " );
946 nameLabel->setToolTip( " " + name +" " );
950 * Give the decorations of the Main Window a correct Name.
951 * If nothing is given, set it to VLC...
953 void MainInterface::setVLCWindowsTitle( const QString& aTitle )
955 if( aTitle.isEmpty() )
957 setWindowTitle( qtr( "VLC media player" ) );
961 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
965 void MainInterface::showCryptedLabel( bool b_show )
967 if( cryptedLabel == NULL )
969 cryptedLabel = new QLabel;
970 // The lock icon is not the right one for DRM protection/scrambled.
971 //cryptedLabel->setPixmap( QPixmap( ":/lock" ) );
972 cryptedLabel->setText( "DRM" );
973 statusBar()->addWidget( cryptedLabel );
976 cryptedLabel->setVisible( b_show );
979 /*****************************************************************************
980 * Systray Icon and Systray Menu
981 *****************************************************************************/
984 * Create a SystemTray icon and a menu that would go with it.
985 * Connects to a click handler on the icon.
987 void MainInterface::createSystray()
990 if( QDate::currentDate().dayOfYear() >= 354 )
991 iconVLC = QIcon( QPixmap( ":/logo/vlc128-christmas.png" ) );
993 iconVLC = QIcon( QPixmap( ":/logo/vlc128.png" ) );
994 sysTray = new QSystemTrayIcon( iconVLC, this );
995 sysTray->setToolTip( qtr( "VLC media player" ));
997 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
998 systrayMenu->setIcon( iconVLC );
1000 QVLCMenu::updateSystrayMenu( this, p_intf, true );
1003 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
1004 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
1008 * Updates the Systray Icon's menu and toggle the main interface
1010 void MainInterface::toggleUpdateSystrayMenu()
1012 /* If hidden, show it */
1018 else if( isMinimized() )
1026 /* Visible (possibly under other windows) */
1028 /* check if any visible window is above vlc in the z-order,
1029 * but ignore the ones always on top
1030 * and the ones which can't be activated */
1033 wi.cbSize = sizeof( WINDOWINFO );
1034 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
1035 hwnd && ( !IsWindowVisible( hwnd ) ||
1036 ( GetWindowInfo( hwnd, &wi ) &&
1037 (wi.dwExStyle&WS_EX_NOACTIVATE) ) );
1038 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
1039 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
1040 (wi.dwExStyle&WS_EX_TOPMOST) )
1052 QVLCMenu::updateSystrayMenu( this, p_intf );
1055 void MainInterface::handleSystrayClick(
1056 QSystemTrayIcon::ActivationReason reason )
1060 case QSystemTrayIcon::Trigger:
1061 case QSystemTrayIcon::DoubleClick:
1062 toggleUpdateSystrayMenu();
1064 case QSystemTrayIcon::MiddleClick:
1065 sysTray->showMessage( qtr( "VLC media player" ),
1066 qtr( "Control menu for the player" ),
1067 QSystemTrayIcon::Information, 3000 );
1075 * Updates the name of the systray Icon tooltip.
1076 * Doesn't check if the systray exists, check before you call it.
1078 void MainInterface::updateSystrayTooltipName( const QString& name )
1080 if( name.isEmpty() )
1082 sysTray->setToolTip( qtr( "VLC media player" ) );
1086 sysTray->setToolTip( name );
1087 if( notificationEnabled && ( isHidden() || isMinimized() ) )
1089 sysTray->showMessage( qtr( "VLC media player" ), name,
1090 QSystemTrayIcon::NoIcon, 3000 );
1094 QVLCMenu::updateSystrayMenu( this, p_intf );
1098 * Updates the status of the systray Icon tooltip.
1099 * Doesn't check if the systray exists, check before you call it.
1101 void MainInterface::updateSystrayTooltipStatus( int i_status )
1108 sysTray->setToolTip( qtr( "VLC media player" ) );
1113 sysTray->setToolTip( input_name );
1118 sysTray->setToolTip( input_name + " - "
1123 QVLCMenu::updateSystrayMenu( this, p_intf );
1126 /************************************************************************
1128 ************************************************************************/
1129 void MainInterface::dropEvent(QDropEvent *event)
1131 dropEventPlay( event, true );
1134 void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
1136 event->setDropAction( Qt::CopyAction );
1137 if( !event->possibleActions() & Qt::CopyAction )
1140 const QMimeData *mimeData = event->mimeData();
1142 /* D&D of a subtitles file, add it on the fly */
1143 if( mimeData->urls().size() == 1 )
1145 if( THEMIM->getIM()->hasInput() )
1147 if( !input_AddSubtitle( THEMIM->getInput(),
1148 qtu( toNativeSeparators(
1149 mimeData->urls()[0].toLocalFile() ) ),
1157 bool first = b_play;
1158 foreach( const QUrl &url, mimeData->urls() )
1160 QString s = toNativeSeparators( url.toLocalFile() );
1162 if( s.length() > 0 ) {
1163 playlist_Add( THEPL, qtu(s), NULL,
1164 PLAYLIST_APPEND | (first ? PLAYLIST_GO: PLAYLIST_PREPARSE),
1165 PLAYLIST_END, true, pl_Unlocked );
1167 RecentsMRL::getInstance( p_intf )->addRecent( s );
1172 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1174 event->acceptProposedAction();
1176 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1178 event->acceptProposedAction();
1180 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1185 /************************************************************************
1187 ************************************************************************/
1188 void MainInterface::customEvent( QEvent *event )
1191 if( event->type() == PLDockEvent_Type )
1193 PlaylistDialog::killInstance();
1194 playlistEmbeddedFlag = true;
1196 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1201 if ( event->type() == (int)SetVideoOnTopEvent_Type )
1203 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1204 if( p_event->OnTop() )
1205 setWindowFlags( windowFlags() | Qt::WindowStaysOnTopHint );
1207 setWindowFlags( windowFlags() & ~Qt::WindowStaysOnTopHint );
1208 show(); /* necessary to apply window flags */
1212 void MainInterface::keyPressEvent( QKeyEvent *e )
1214 handleKeyPress( e );
1217 void MainInterface::handleKeyPress( QKeyEvent *e )
1219 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() == Qt::Key_H )
1220 && !menuBar()->isVisible() )
1222 toggleMinimalView( false );
1226 int i_vlck = qtEventToVLCKey( e );
1229 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1236 void MainInterface::resizeEvent( QResizeEvent * event )
1240 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
1241 i_visualmode == QT_MINIMAL_MODE )
1243 mainVideoSize = size();
1247 if( VISIBLE( bgWidget) ||
1248 ( videoIsActive && videoWidget->isVisible() )
1250 mainVideoSize = size();
1252 mainBasedSize = size();
1257 void MainInterface::wheelEvent( QWheelEvent *e )
1259 int i_vlckey = qtWheelEventToVLCKey( e );
1260 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1264 void MainInterface::closeEvent( QCloseEvent *e )
1271 void MainInterface::toggleFullScreen( void )
1273 if( isFullScreen() )
1276 emit askUpdate(); // Needed if video was launched after the F11
1277 emit fullscreenInterfaceToggled( false );
1282 emit fullscreenInterfaceToggled( true );
1287 /*****************************************************************************
1288 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1289 * We don't show the menu directly here because we don't want the
1290 * caller to block for a too long time.
1291 *****************************************************************************/
1292 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1293 vlc_value_t old_val, vlc_value_t new_val, void *param )
1295 intf_thread_t *p_intf = (intf_thread_t *)param;
1297 if( p_intf->pf_show_dialog )
1299 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1300 new_val.b_bool, NULL );
1306 /*****************************************************************************
1307 * IntfShowCB: callback triggered by the intf-show libvlc variable.
1308 *****************************************************************************/
1309 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1310 vlc_value_t old_val, vlc_value_t new_val, void *param )
1312 intf_thread_t *p_intf = (intf_thread_t *)param;
1313 p_intf->p_sys->p_mi->toggleFSC();