1 /*****************************************************************************
2 * main_interface.cpp : Main interface
3 ****************************************************************************
4 * Copyright (C) 2006-2008 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;
90 * Configuration and settings
91 * Pre-building of interface
94 setFocusPolicy( Qt::StrongFocus );
95 setAcceptDrops( true );
96 setWindowIcon( QApplication::windowIcon() );
97 setWindowOpacity( config_GetFloat( p_intf, "qt-opacity" ) );
99 /* Set The Video In emebedded Mode or not */
100 videoEmbeddedFlag = config_GetInt( p_intf, "embedded-video" );
102 /* Does the interface resize to video size or the opposite */
103 b_keep_size = !config_GetInt( p_intf, "qt-video-autoresize" );
105 /* Are we in the enhanced always-video mode or not ? */
106 i_visualmode = config_GetInt( p_intf, "qt-display-mode" );
108 /* Set the other interface settings */
109 settings = getSettings();
110 settings->beginGroup( "MainWindow" );
113 * Retrieve saved sizes for main window
114 * mainBasedSize = based window size for normal mode
115 * (no video, no background)
116 * mainVideoSize = window size with video (all modes)
118 mainBasedSize = settings->value( "mainBasedSize", QSize( 350, 120 ) ).toSize();
119 mainVideoSize = settings->value( "mainVideoSize", QSize( 400, 300 ) ).toSize();
121 /* Do we want anoying popups or not */
122 notificationEnabled = (bool)config_GetInt( p_intf, "qt-notification" );
129 /**************************
130 * UI and Widgets design
131 **************************/
132 setVLCWindowsTitle();
133 handleMainUi( settings );
138 QVLCMenu::createMenuBar( this, p_intf );
141 /* Create a Dock to get the playlist */
142 dockPL = new QDockWidget( qtr( "Playlist" ), this );
143 dockPL->setSizePolicy( QSizePolicy::Preferred,
144 QSizePolicy::Expanding );
145 dockPL->setFeatures( QDockWidget::AllDockWidgetFeatures );
146 dockPL->setAllowedAreas( Qt::LeftDockWidgetArea
147 | Qt::RightDockWidgetArea
148 | Qt::BottomDockWidgetArea );
152 /********************
154 ********************/
155 MainInputManager::getInstance( p_intf );
157 /**************************
158 * Various CONNECTs on IM *
159 **************************/
160 /* Connect the input manager to the GUI elements it manages */
163 * Connects on nameChanged()
164 * Those connects are not merged because different options can trigger
167 /* Naming in the controller statusbar */
168 CONNECT( THEMIM->getIM(), nameChanged( QString ),
169 this, setName( QString ) );
170 /* and in the systray */
173 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
174 updateSystrayTooltipName( QString ) );
176 /* and in the title of the controller */
177 if( config_GetInt( p_intf, "qt-name-in-title" ) )
179 CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
180 setVLCWindowsTitle( QString ) );
184 * CONNECTS on PLAY_STATUS
186 /* Status on the systray */
189 CONNECT( THEMIM->getIM(), statusChanged( int ),
190 this, updateSystrayTooltipStatus( int ) );
193 /* END CONNECTS ON IM */
195 dialogHandler = new DialogHandler (p_intf);
200 var_AddCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
202 /* Register callback for the intf-popupmenu variable */
203 var_AddCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
206 /* VideoWidget connects to avoid different threads speaking to each other */
207 connect( this, SIGNAL(askReleaseVideo( void )),
208 this, SLOT(releaseVideoSlot( void )), Qt::BlockingQueuedConnection );
212 CONNECT( this, askVideoToResize( unsigned int, unsigned int ),
213 videoWidget, SetSizing( unsigned int, unsigned int ) );
215 connect( this, SIGNAL(askVideoToShow( unsigned int, unsigned int)),
216 videoWidget, SLOT(SetSizing(unsigned int, unsigned int )),
217 Qt::BlockingQueuedConnection );
220 CONNECT( this, askUpdate(), this, doComponentsUpdate() );
222 /* Size and placement of interface */
223 settings->beginGroup( "MainWindow" );
224 QVLCTools::restoreWidgetPosition( settings, this, QSize(380, 60) );
226 /* resize to previously saved main window size if appicable */
229 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
230 i_visualmode == QT_MINIMAL_MODE )
232 resize( mainVideoSize );
236 resize( mainBasedSize );
240 bool b_visible = settings->value( "playlist-visible", 0 ).toInt();
241 settings->endGroup();
244 if( b_visible ) togglePlaylist();
246 /* Enable the popup menu in the MI */
247 setContextMenuPolicy( Qt::CustomContextMenu );
248 CONNECT( this, customContextMenuRequested( const QPoint& ),
249 this, popupMenu( const QPoint& ) );
251 /* Final sizing and showing */
252 setMinimumWidth( __MAX( controls->sizeHint().width(),
253 menuBar()->sizeHint().width() ) );
256 /* And switch to minimal view if needed
257 Must be called after the show() */
258 if( i_visualmode == QT_MINIMAL_MODE )
259 toggleMinimalView( true );
261 /* Update the geometry : It is useful if you switch between
264 resize( sizeHint() );
266 /*****************************************************
267 * End everything by creating the Systray Management *
268 *****************************************************/
272 MainInterface::~MainInterface()
274 msg_Dbg( p_intf, "Destroying the main interface" );
276 delete dialogHandler;
278 /* Unsure we hide the videoWidget before destroying it */
279 if( videoIsActive ) videoWidget->hide();
281 /* Save playlist state */
285 QVLCTools::saveWidgetPosition( p_intf, "Playlist", playlistWidget );
287 delete playlistWidget;
290 /* Be sure to kill the actionsManager... FIXME */
291 ActionsManager::killInstance();
293 /* Delete the FSC controller */
294 delete fullscreenControls;
297 settings->beginGroup( "MainWindow" );
298 settings->setValue( "pl-dock-status", (int)i_pl_dock );
299 settings->setValue( "playlist-visible", (int)playlistVisible );
300 settings->setValue( "adv-controls",
301 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
303 settings->setValue( "mainBasedSize", mainBasedSize );
304 settings->setValue( "mainVideoSize", mainVideoSize );
307 settings->setValue( "backgroundSize", bgWidget->size() );
310 QVLCTools::saveWidgetPosition(settings, this);
311 settings->endGroup();
314 /* Unregister callbacks */
315 var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
316 var_DelCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
318 p_intf->p_sys->p_mi = NULL;
321 /*****************************
323 *****************************/
325 inline void MainInterface::createStatusBar()
330 /* Widgets Creation*/
331 QStatusBar *statusBarr = statusBar();
333 TimeLabel *timeLabel = new TimeLabel( p_intf );
334 nameLabel = new QLabel( this );
335 nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
336 | Qt::TextSelectableByKeyboard );
337 SpeedLabel *speedLabel = new SpeedLabel( p_intf, "1.00x", this );
339 /* Styling those labels */
340 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
341 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
342 nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
344 /* and adding those */
345 statusBarr->addWidget( nameLabel, 8 );
346 statusBarr->addPermanentWidget( speedLabel, 0 );
347 statusBarr->addPermanentWidget( timeLabel, 0 );
349 /* timeLabel behaviour:
350 - double clicking opens the goto time dialog
351 - right-clicking and clicking just toggle between remaining and
353 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
355 CONNECT( THEMIM->getIM(), encryptionChanged( bool ) , this, showCryptedLabel( bool ) );
358 void MainInterface::showCryptedLabel( bool b_show )
360 if( cryptedLabel == NULL )
362 cryptedLabel = new QLabel;
363 // The lock icon is not the right one for DRM protection/scrambled.
364 //cryptedLabel->setPixmap( QPixmap( ":/lock" ) );
365 cryptedLabel->setText( "DRM" );
366 statusBar()->addWidget( cryptedLabel );
369 cryptedLabel->setVisible( b_show );
372 inline void MainInterface::initSystray()
374 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
375 bool b_systrayWanted = config_GetInt( p_intf, "qt-system-tray" );
377 if( config_GetInt( p_intf, "qt-start-minimized") > 0 )
379 if( b_systrayAvailable )
381 b_systrayWanted = true;
385 msg_Err( p_intf, "cannot start minimized without system tray bar" );
388 if( b_systrayAvailable && b_systrayWanted )
393 * Give the decorations of the Main Window a correct Name.
394 * If nothing is given, set it to VLC...
396 void MainInterface::setVLCWindowsTitle( QString aTitle )
398 if( aTitle.isEmpty() )
400 setWindowTitle( qtr( "VLC media player" ) );
404 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
408 void MainInterface::handleMainUi( QSettings *settings )
410 /* Create the main Widget and the mainLayout */
411 QWidget *main = new QWidget;
412 setCentralWidget( main );
413 mainLayout = new QVBoxLayout( main );
415 /* Margins, spacing */
416 main->setContentsMargins( 0, 0, 0, 0 );
417 main->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
418 mainLayout->setSpacing( 0 );
419 mainLayout->setMargin( 0 );
421 /* Create the CONTROLS Widget */
422 controls = new ControlsWidget( p_intf,
423 settings->value( "adv-controls", false ).toBool(), this );
424 CONNECT( controls, advancedControlsToggled( bool ),
425 this, doComponentsUpdate() );
426 CONNECT( controls, sizeChanged(),
427 this, doComponentsUpdate() );
428 inputC = new InputControlsWidget( p_intf, this );
431 /* Disabled for now, they SUCK */
433 visualSelector = new VisualSelector( p_intf );
434 mainLayout->insertWidget( 0, visualSelector );
435 visualSelector->hide();
439 bgWidget = new BackgroundWidget( p_intf );
441 settings->value( "backgroundSize", QSize( 300, 200 ) ).toSize() );
442 bgWidget->updateGeometry();
443 CONNECT( this, askBgWidgetToToggle(), bgWidget, toggle() );
445 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
446 i_visualmode != QT_MINIMAL_MODE )
451 /* And video Outputs */
452 if( videoEmbeddedFlag )
453 videoWidget = new VideoWidget( p_intf );
455 /* Add the controls Widget to the main Widget */
456 mainLayout->insertWidget( 0, bgWidget );
457 if( videoWidget ) mainLayout->insertWidget( 0, videoWidget, 10 );
458 mainLayout->insertWidget( 2, inputC, 0, Qt::AlignBottom );
459 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
460 controls, 0, Qt::AlignBottom );
462 /* Finish the sizing */
463 main->updateGeometry();
465 getSettings()->endGroup();
469 /* Create the FULLSCREEN CONTROLS Widget */
470 if( config_GetInt( p_intf, "qt-fs-controller" ) )
472 fullscreenControls = new FullscreenControllerWidget( p_intf );
476 inline void MainInterface::askForPrivacy()
479 * Ask for the network policy on FIRST STARTUP
481 if( config_GetInt( p_intf, "qt-privacy-ask") )
483 QList<ConfigControl *> controls;
484 if( privacyDialog( &controls ) == QDialog::Accepted )
486 QList<ConfigControl *>::Iterator i;
487 for( i = controls.begin() ; i != controls.end() ; i++ )
489 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
490 c->doApply( p_intf );
493 config_PutInt( p_intf, "qt-privacy-ask" , 0 );
494 /* We have to save here because the user may not launch Prefs */
495 config_SaveConfigFile( p_intf, NULL );
500 int MainInterface::privacyDialog( QList<ConfigControl *> *controls )
502 QDialog *privacy = new QDialog( this );
504 privacy->setWindowTitle( qtr( "Privacy and Network Policies" ) );
506 QGridLayout *gLayout = new QGridLayout( privacy );
508 QGroupBox *blabla = new QGroupBox( qtr( "Privacy and Network Warning" ) );
509 QGridLayout *blablaLayout = new QGridLayout( blabla );
510 QLabel *text = new QLabel( qtr(
511 "<p>The <i>VideoLAN Team</i> doesn't like when an application goes "
512 "online without authorization.</p>\n "
513 "<p><i>VLC media player</i> can retreive limited information from "
514 "the Internet in order to get CD covers or to check "
515 "for available updates.</p>\n"
516 "<p><i>VLC media player</i> <b>DOES NOT</b> send or collect <b>ANY</b> "
517 "information, even anonymously, about your usage.</p>\n"
518 "<p>Therefore please select from the following options, the default being "
519 "almost no access to the web.</p>\n") );
520 text->setWordWrap( true );
521 text->setTextFormat( Qt::RichText );
523 blablaLayout->addWidget( text, 0, 0 ) ;
525 QGroupBox *options = new QGroupBox;
526 QGridLayout *optionsLayout = new QGridLayout( options );
528 gLayout->addWidget( blabla, 0, 0, 1, 3 );
529 gLayout->addWidget( options, 1, 0, 1, 3 );
530 module_config_t *p_config;
531 ConfigControl *control;
534 #define CONFIG_GENERIC( option, type ) \
535 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
538 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
539 p_config, options, false, optionsLayout, line ); \
540 controls->append( control ); \
543 #define CONFIG_GENERIC_NOBOOL( option, type ) \
544 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
547 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
548 p_config, options, optionsLayout, line ); \
549 controls->append( control ); \
552 CONFIG_GENERIC( "album-art", IntegerList ); line++;
554 CONFIG_GENERIC_NOBOOL( "qt-updates-notif", Bool ); line++;
557 QPushButton *ok = new QPushButton( qtr( "OK" ) );
559 gLayout->addWidget( ok, 2, 2 );
561 CONNECT( ok, clicked(), privacy, accept() );
562 return privacy->exec();
566 /**********************************************************************
567 * Handling of sizing of the components
568 **********************************************************************/
570 /* This function is probably wrong, but we don't have many many choices...
571 Since we can't know from the playlist Widget if we are inside a dock or not,
572 because the playlist Widget can be called by THEDP, as a separate windows for
574 Maybe the other solution is to redefine the sizeHint() of the playlist and
575 ask _parent->isFloating()...
576 If you think this would be better, please FIXME it...
579 QSize MainInterface::sizeHint() const
583 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
584 i_visualmode == QT_MINIMAL_MODE )
586 return mainVideoSize;
590 if( VISIBLE( bgWidget) ||
591 ( videoIsActive && videoWidget->isVisible() )
593 return mainVideoSize;
595 return mainBasedSize;
599 int nwidth = controls->sizeHint().width();
600 int nheight = controls->isVisible() ?
601 controls->size().height()
602 + inputC->size().height()
603 + menuBar()->size().height()
604 + statusBar()->size().height()
607 if( VISIBLE( bgWidget ) )
609 nheight += bgWidget->size().height();
610 nwidth = bgWidget->size().width();
612 else if( videoIsActive && videoWidget->isVisible() )
614 nheight += videoWidget->sizeHint().height();
615 nwidth = videoWidget->sizeHint().width();
618 if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget() )
620 nheight += dockPL->size().height();
621 nwidth = __MAX( nwidth, dockPL->size().width() );
622 msg_Warn( p_intf, "3 %i %i", nheight, nwidth );
625 return QSize( nwidth, nheight );
628 void MainInterface::toggleFSC()
630 if( !fullscreenControls ) return;
632 IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
633 QApplication::postEvent( fullscreenControls, eShow );
636 void MainInterface::popupMenu( const QPoint &p )
638 /* Ow, that's ugly: don't show the popup menu if cursor over
639 * the main menu bar or the status bar */
640 if( !childAt( p ) || ( ( childAt( p ) != menuBar() )
641 && ( childAt( p )->parentWidget() != statusBar() ) ) )
642 QVLCMenu::PopupMenu( p_intf, true );
645 void MainInterface::debug()
648 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
649 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
650 if( videoWidget && videoWidget->isVisible() )
652 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
653 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
658 /****************************************************************************
660 ****************************************************************************/
662 /* This event is used to deal with the fullscreen and always on top
663 issue conflict (bug in wx) */
664 class SetVideoOnTopQtEvent : public QEvent
667 SetVideoOnTopQtEvent( bool _onTop ) :
668 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
671 bool OnTop() const { return onTop; }
679 * Thou shall not call/resize/hide widgets from on another thread.
680 * This is wrong, and this is THE reason to emit signals on those Video Functions
682 WId MainInterface::requestVideo( vout_thread_t *p_nvout, int *pi_x,
683 int *pi_y, unsigned int *pi_width,
684 unsigned int *pi_height )
686 /* Request the videoWidget */
687 WId ret = videoWidget->request( p_nvout,pi_x, pi_y,
688 pi_width, pi_height, b_keep_size );
689 if( ret ) /* The videoWidget is available */
691 /* Did we have a bg ? Hide it! */
692 if( VISIBLE( bgWidget) )
695 emit askBgWidgetToToggle();
698 bgWasVisible = false;
700 /* ask videoWidget to show */
701 emit askVideoToShow( *pi_width, *pi_height );
703 /* Consider the video active now */
704 videoIsActive = true;
711 /* Call from the WindowClose function */
712 void MainInterface::releaseVideo( void )
714 emit askReleaseVideo( );
717 /* Function that is CONNECTED to the previous emit */
718 void MainInterface::releaseVideoSlot( void )
720 videoWidget->release( );
724 /* Reset the bg state */
725 bgWasVisible = false;
729 videoIsActive = false;
731 /* Try to resize, except when you are in Fullscreen mode */
732 if( !isFullScreen() ) doComponentsUpdate();
735 /* Call from WindowControl function */
736 int MainInterface::controlVideo( int i_query, va_list args )
738 int i_ret = VLC_SUCCESS;
743 unsigned int i_width = va_arg( args, unsigned int );
744 unsigned int i_height = va_arg( args, unsigned int );
745 emit askVideoToResize( i_width, i_height );
749 case VOUT_SET_STAY_ON_TOP:
751 int i_arg = va_arg( args, int );
752 QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
756 i_ret = VLC_EGENERIC;
757 msg_Warn( p_intf, "unsupported control query" );
763 /*****************************************************************************
764 * Playlist, Visualisation and Menus handling
765 *****************************************************************************/
767 * Toggle the playlist widget or dialog
769 void MainInterface::togglePlaylist()
772 If no playlist exist, then create one and attach it to the DockPL*/
773 if( !playlistWidget )
775 playlistWidget = new PlaylistWidget( p_intf );
777 i_pl_dock = PL_UNDOCKED;
778 /* i_pl_dock = (pl_dock_e)getSettings()
779 ->value( "pl-dock-status", PL_UNDOCKED ).toInt(); */
781 if( i_pl_dock == PL_UNDOCKED )
783 playlistWidget->setWindowFlags( Qt::Window );
785 /* This will restore the geometry but will not work for position,
786 because of parenting */
787 QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
788 playlistWidget, QSize( 600, 300 ) );
792 mainLayout->insertWidget( 4, playlistWidget );
794 playlistVisible = true;
796 playlistWidget->show();
800 /* toggle the visibility of the playlist */
801 TOGGLEV( playlistWidget );
802 playlistVisible = !playlistVisible;
803 //doComponentsUpdate(); //resize( sizeHint() );
807 /* Function called from the menu to undock the playlist */
808 void MainInterface::undockPlaylist()
810 // dockPL->setFloating( true );
814 void MainInterface::dockPlaylist( pl_dock_e i_pos )
818 void MainInterface::toggleMinimalView( bool b_switch )
820 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
821 i_visualmode != QT_MINIMAL_MODE )
822 { /* NORMAL MODE then */
823 if( !videoWidget || videoWidget->isHidden() ) emit askBgWidgetToToggle();
826 /* If video is visible, then toggle the status of bgWidget */
827 bgWasVisible = !bgWasVisible;
831 menuBar()->setVisible( !b_switch );
832 controls->setVisible( !b_switch );
833 statusBar()->setVisible( !b_switch );
834 inputC->setVisible( !b_switch );
835 doComponentsUpdate();
837 emit minimalViewToggled( b_switch );
840 /* Video widget cannot do this synchronously as it runs in another thread */
841 /* Well, could it, actually ? Probably dangerous ... */
843 /* This function is called:
844 - toggling of minimal View
845 - through askUpdate() by Vout thread request video and resize video (zoom)
846 - Advanced buttons toggled
848 void MainInterface::doComponentsUpdate()
850 msg_Dbg( p_intf, "Updating the geometry" );
851 /* Here we resize to sizeHint() and not adjustsize because we want
852 the videoWidget to be exactly the correctSize */
853 resize( sizeHint() );
860 /* toggling advanced controls buttons */
861 void MainInterface::toggleAdvanced()
863 controls->toggleAdvanced();
864 // if( fullscreenControls ) fullscreenControls->toggleAdvanced();
867 /* Get the visibility status of the controls (hidden or not, advanced or not) */
868 int MainInterface::getControlsVisibilityStatus()
870 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
871 + CONTROLS_ADVANCED * controls->b_advancedVisible );
875 void MainInterface::visual()
877 if( !VISIBLE( visualSelector) )
879 visualSelector->show();
880 if( !THEMIM->getIM()->hasVideo() )
882 /* Show the background widget */
884 visualSelectorEnabled = true;
888 /* Stop any currently running visualization */
889 visualSelector->hide();
890 visualSelectorEnabled = false;
892 doComponentsUpdate();
896 /************************************************************************
898 ************************************************************************/
899 void MainInterface::setName( QString name )
901 input_name = name; /* store it for the QSystray use */
902 /* Display it in the status bar, but also as a Tooltip in case it doesn't
904 nameLabel->setText( " " + name + " " );
905 nameLabel->setToolTip( " " + name +" " );
908 /*****************************************************************************
909 * Systray Icon and Systray Menu
910 *****************************************************************************/
913 * Create a SystemTray icon and a menu that would go with it.
914 * Connects to a click handler on the icon.
916 void MainInterface::createSystray()
919 if( QDate::currentDate().dayOfYear() >= 354 )
920 iconVLC = QIcon( QPixmap( ":/vlc128-christmas.png" ) );
922 iconVLC = QIcon( QPixmap( ":/vlc128.png" ) );
923 sysTray = new QSystemTrayIcon( iconVLC, this );
924 sysTray->setToolTip( qtr( "VLC media player" ));
926 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
927 systrayMenu->setIcon( iconVLC );
929 QVLCMenu::updateSystrayMenu( this, p_intf, true );
932 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
933 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
937 * Updates the Systray Icon's menu and toggle the main interface
939 void MainInterface::toggleUpdateSystrayMenu()
941 /* If hidden, show it */
947 else if( isMinimized() )
955 /* Visible (possibly under other windows) */
957 /* check if any visible window is above vlc in the z-order,
958 * but ignore the ones always on top
959 * and the ones which can't be activated */
962 wi.cbSize = sizeof( WINDOWINFO );
963 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
964 hwnd && ( !IsWindowVisible( hwnd ) ||
965 ( GetWindowInfo( hwnd, &wi ) &&
966 (wi.dwExStyle&WS_EX_NOACTIVATE) ) );
967 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
968 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
969 (wi.dwExStyle&WS_EX_TOPMOST) )
981 QVLCMenu::updateSystrayMenu( this, p_intf );
984 void MainInterface::handleSystrayClick(
985 QSystemTrayIcon::ActivationReason reason )
989 case QSystemTrayIcon::Trigger:
990 case QSystemTrayIcon::DoubleClick:
991 toggleUpdateSystrayMenu();
993 case QSystemTrayIcon::MiddleClick:
994 sysTray->showMessage( qtr( "VLC media player" ),
995 qtr( "Control menu for the player" ),
996 QSystemTrayIcon::Information, 3000 );
1004 * Updates the name of the systray Icon tooltip.
1005 * Doesn't check if the systray exists, check before you call it.
1007 void MainInterface::updateSystrayTooltipName( QString name )
1009 if( name.isEmpty() )
1011 sysTray->setToolTip( qtr( "VLC media player" ) );
1015 sysTray->setToolTip( name );
1016 if( notificationEnabled && ( isHidden() || isMinimized() ) )
1018 sysTray->showMessage( qtr( "VLC media player" ), name,
1019 QSystemTrayIcon::NoIcon, 3000 );
1023 QVLCMenu::updateSystrayMenu( this, p_intf );
1027 * Updates the status of the systray Icon tooltip.
1028 * Doesn't check if the systray exists, check before you call it.
1030 void MainInterface::updateSystrayTooltipStatus( int i_status )
1037 sysTray->setToolTip( qtr( "VLC media player" ) );
1042 sysTray->setToolTip( input_name );
1047 sysTray->setToolTip( input_name + " - "
1054 /************************************************************************
1056 ************************************************************************/
1057 void MainInterface::dropEvent(QDropEvent *event)
1059 dropEventPlay( event, true );
1062 void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
1064 const QMimeData *mimeData = event->mimeData();
1066 /* D&D of a subtitles file, add it on the fly */
1067 if( mimeData->urls().size() == 1 )
1069 if( THEMIM->getIM()->hasInput() )
1071 if( !input_AddSubtitle( THEMIM->getInput(),
1072 qtu( toNativeSeparators(
1073 mimeData->urls()[0].toLocalFile() ) ),
1076 event->acceptProposedAction();
1081 bool first = b_play;
1082 foreach( const QUrl &url, mimeData->urls() )
1084 QString s = toNativeSeparators( url.toLocalFile() );
1086 if( s.length() > 0 ) {
1087 playlist_Add( THEPL, qtu(s), NULL,
1088 PLAYLIST_APPEND | (first ? PLAYLIST_GO: 0),
1089 PLAYLIST_END, true, false );
1091 RecentsMRL::getInstance( p_intf )->addRecent( s );
1094 event->acceptProposedAction();
1096 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1098 event->acceptProposedAction();
1100 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1102 event->acceptProposedAction();
1104 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1109 /************************************************************************
1111 ************************************************************************/
1112 void MainInterface::customEvent( QEvent *event )
1115 if( event->type() == PLDockEvent_Type )
1117 PlaylistDialog::killInstance();
1118 playlistEmbeddedFlag = true;
1120 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1125 if ( event->type() == (int)SetVideoOnTopEvent_Type )
1127 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1128 if( p_event->OnTop() )
1129 setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
1131 setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint);
1132 show(); /* necessary to apply window flags?? */
1136 void MainInterface::keyPressEvent( QKeyEvent *e )
1138 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() == Qt::Key_H )
1139 && !menuBar()->isVisible() )
1141 toggleMinimalView( false );
1145 int i_vlck = qtEventToVLCKey( e );
1148 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1155 void MainInterface::resizeEvent( QResizeEvent * event )
1159 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
1160 i_visualmode == QT_MINIMAL_MODE )
1162 mainVideoSize = size();
1166 if( VISIBLE( bgWidget) ||
1167 ( videoIsActive && videoWidget->isVisible() )
1169 mainVideoSize = size();
1171 mainBasedSize = size();
1176 void MainInterface::wheelEvent( QWheelEvent *e )
1178 int i_vlckey = qtWheelEventToVLCKey( e );
1179 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1183 void MainInterface::closeEvent( QCloseEvent *e )
1190 void MainInterface::toggleFullScreen( void )
1192 if( isFullScreen() )
1195 emit askUpdate(); // Needed if video was launched after the F11
1196 emit fullscreenInterfaceToggled( false );
1201 emit fullscreenInterfaceToggled( true );
1206 /*****************************************************************************
1207 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1208 * We don't show the menu directly here because we don't want the
1209 * caller to block for a too long time.
1210 *****************************************************************************/
1211 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1212 vlc_value_t old_val, vlc_value_t new_val, void *param )
1214 intf_thread_t *p_intf = (intf_thread_t *)param;
1216 if( p_intf->pf_show_dialog )
1218 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1219 new_val.b_bool, NULL );
1225 /*****************************************************************************
1226 * IntfShowCB: callback triggered by the intf-show libvlc variable.
1227 *****************************************************************************/
1228 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1229 vlc_value_t old_val, vlc_value_t new_val, void *param )
1231 intf_thread_t *p_intf = (intf_thread_t *)param;
1232 p_intf->p_sys->p_mi->toggleFSC();