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>
62 #include <vlc_windows_interfaces.h>
68 #include <vlc_keys.h> /* Wheel event */
69 #include <vlc_vout_window.h>
72 /* Callback prototypes */
73 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
74 vlc_value_t old_val, vlc_value_t new_val, void *param );
75 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
76 vlc_value_t old_val, vlc_value_t new_val, void *param );
78 MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
80 /* Variables initialisation */
81 // need_components_update = false;
84 playlistWidget = NULL;
86 videoIsActive = false;
87 playlistVisible = false;
89 fullscreenControls = NULL;
102 * Configuration and settings
103 * Pre-building of interface
106 setFocusPolicy( Qt::StrongFocus );
107 setAcceptDrops( true );
108 setWindowIcon( QApplication::windowIcon() );
109 setWindowOpacity( config_GetFloat( p_intf, "qt-opacity" ) );
111 /* Set The Video In emebedded Mode or not */
112 videoEmbeddedFlag = config_GetInt( p_intf, "embedded-video" );
114 /* Does the interface resize to video size or the opposite */
115 b_keep_size = !config_GetInt( p_intf, "qt-video-autoresize" );
117 /* Are we in the enhanced always-video mode or not ? */
118 i_visualmode = config_GetInt( p_intf, "qt-display-mode" );
120 /* Set the other interface settings */
121 settings = getSettings();
122 settings->beginGroup( "MainWindow" );
125 * Retrieve saved sizes for main window
126 * mainBasedSize = based window size for normal mode
127 * (no video, no background)
128 * mainVideoSize = window size with video (all modes)
130 mainBasedSize = settings->value( "mainBasedSize", QSize( 350, 120 ) ).toSize();
131 mainVideoSize = settings->value( "mainVideoSize", QSize( 400, 300 ) ).toSize();
133 /* Do we want anoying popups or not */
134 notificationEnabled = (bool)config_GetInt( p_intf, "qt-notification" );
141 /**************************
142 * UI and Widgets design
143 **************************/
144 setVLCWindowsTitle();
145 createMainWidget( settings );
150 QVLCMenu::createMenuBar( this, p_intf );
151 CONNECT( THEMIM->getIM(), voutListChanged( vout_thread_t **, int ),
152 this, destroyPopupMenu() );
155 /* Create a Dock to get the playlist */
156 dockPL = new QDockWidget( qtr( "Playlist" ), this );
157 dockPL->setSizePolicy( QSizePolicy::Preferred,
158 QSizePolicy::Expanding );
159 dockPL->setFeatures( QDockWidget::AllDockWidgetFeatures );
160 dockPL->setAllowedAreas( Qt::LeftDockWidgetArea
161 | Qt::RightDockWidgetArea
162 | Qt::BottomDockWidgetArea );
166 /********************
168 ********************/
169 MainInputManager::getInstance( p_intf );
171 /*********************************
172 * Create the Systray Management *
173 *********************************/
176 /**************************
177 * Various CONNECTs on IM *
178 **************************/
179 /* Connect the input manager to the GUI elements it manages */
182 * Connects on nameChanged()
183 * Those connects are not merged because different options can trigger
186 /* Naming in the controller statusbar */
187 CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
188 this, setName( const QString& ) );
189 /* and in the systray */
192 CONNECT( THEMIM->getIM(), nameChanged( const QString& ), this,
193 updateSystrayTooltipName( const QString& ) );
195 /* and in the title of the controller */
196 if( config_GetInt( p_intf, "qt-name-in-title" ) )
198 CONNECT( THEMIM->getIM(), nameChanged( const QString& ), this,
199 setVLCWindowsTitle( const QString& ) );
203 * CONNECTS on PLAY_STATUS
205 /* Status on the systray */
208 CONNECT( THEMIM->getIM(), statusChanged( int ),
209 this, updateSystrayTooltipStatus( int ) );
213 /* END CONNECTS ON IM */
218 var_AddCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
220 /* Register callback for the intf-popupmenu variable */
221 var_AddCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
224 /* VideoWidget connects for asynchronous calls */
225 connect( this, SIGNAL(askGetVideo(WId*,int*,int*,unsigned*,unsigned *)),
226 this, SLOT(getVideoSlot(WId*,int*,int*,unsigned*,unsigned*)),
227 Qt::BlockingQueuedConnection );
228 connect( this, SIGNAL(askReleaseVideo( void )),
229 this, SLOT(releaseVideoSlot( void )),
230 Qt::BlockingQueuedConnection );
234 CONNECT( this, askVideoToResize( unsigned int, unsigned int ),
235 videoWidget, SetSizing( unsigned int, unsigned int ) );
236 CONNECT( this, askVideoSetFullScreen( bool ),
237 videoWidget, SetFullScreen( bool ) );
238 CONNECT( videoWidget, keyPressed( QKeyEvent * ),
239 this, handleKeyPress( QKeyEvent * ) );
242 CONNECT( this, askUpdate(), this, doComponentsUpdate() );
243 CONNECT( THEDP, toolBarConfUpdated(), this, recreateToolbars() );
245 /* Size and placement of interface */
246 settings->beginGroup( "MainWindow" );
247 QVLCTools::restoreWidgetPosition( settings, this, QSize(380, 60) );
249 /* resize to previously saved main window size if appicable */
252 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
253 i_visualmode == QT_MINIMAL_MODE )
255 resize( mainVideoSize );
259 resize( mainBasedSize );
263 bool b_visible = settings->value( "playlist-visible", 0 ).toInt();
264 settings->endGroup();
267 if( b_visible ) togglePlaylist();
269 /* Enable the popup menu in the MI */
270 setContextMenuPolicy( Qt::CustomContextMenu );
271 CONNECT( this, customContextMenuRequested( const QPoint& ),
272 this, popupMenu( const QPoint& ) );
274 /* Final sizing and showing */
275 setMinimumWidth( __MAX( controls->sizeHint().width(),
276 menuBar()->sizeHint().width() ) );
277 setVisible( !b_shouldHide );
279 /* And switch to minimal view if needed
280 Must be called after the show() */
281 if( i_visualmode == QT_MINIMAL_MODE )
282 toggleMinimalView( true );
284 /* Update the geometry : It is useful if you switch between
287 resize( sizeHint() );
290 /*Here is the code for the taskbar thumb buttons
291 FIXME:We need pretty buttons in 16x16 px that are handled correctly by masks in Qt
292 FIXME:the play button's picture doesn't changed to pause when clicked
294 OSVERSIONINFO winVer;
295 winVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
296 if( GetVersionEx(&winVer) && winVer.dwMajorVersion > 5 && winVer.dwMajorVersion > 0 )
298 if(himl = ImageList_Create( 15, //cx
301 4,//initial nb of images
302 0//nb of images that can be added
305 QPixmap img = QPixmap(":/toolbar/previous_b");
306 QPixmap img2 = QPixmap(":/toolbar/pause_b");
307 QPixmap img3 = QPixmap(":/toolbar/play_b");
308 QPixmap img4 = QPixmap(":/toolbar/next_b");
309 QBitmap mask = img.createMaskFromColor(Qt::transparent);
310 QBitmap mask2 = img2.createMaskFromColor(Qt::transparent);
311 QBitmap mask3 = img3.createMaskFromColor(Qt::transparent);
312 QBitmap mask4 = img4.createMaskFromColor(Qt::transparent);
314 if(-1 == ImageList_Add(himl, img.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask.toWinHBITMAP()))
315 msg_Err( p_intf, "ImageList_Add failed" );
316 if(-1 == ImageList_Add(himl, img2.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask2.toWinHBITMAP()))
317 msg_Err( p_intf, "ImageList_Add failed" );
318 if(-1 == ImageList_Add(himl, img3.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask3.toWinHBITMAP()))
319 msg_Err( p_intf, "ImageList_Add failed" );
320 if(-1 == ImageList_Add(himl, img4.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask4.toWinHBITMAP()))
321 msg_Err( p_intf, "ImageList_Add failed" );
326 if( S_OK == CoCreateInstance( &clsid_ITaskbarList,
327 NULL, CLSCTX_INPROC_SERVER,
329 (void **)&p_taskbl) )
331 p_taskbl->vt->HrInit(p_taskbl);
333 int msg_value = RegisterWindowMessage("TaskbarButtonCreated");
334 //msg_Info( p_intf, "msg value: %04x", msg_value );
336 // Define an array of two buttons. These buttons provide images through an
337 // image list and also provide tooltips.
338 DWORD dwMask = THB_BITMAP | THB_FLAGS;
340 THUMBBUTTON thbButtons[2];
341 thbButtons[0].dwMask = dwMask;
342 thbButtons[0].iId = 0;
343 thbButtons[0].iBitmap = 0;
344 thbButtons[0].dwFlags = THBF_HIDDEN;
346 thbButtons[1].dwMask = dwMask;
347 thbButtons[1].iId = 1;
348 thbButtons[1].iBitmap = 2;
349 thbButtons[1].dwFlags = THBF_HIDDEN;
351 thbButtons[2].dwMask = dwMask;
352 thbButtons[2].iId = 2;
353 thbButtons[2].iBitmap = 3;
354 thbButtons[2].dwFlags = THBF_HIDDEN;
356 HRESULT hr = p_taskbl->vt->ThumbBarSetImageList(p_taskbl, GetForegroundWindow(), himl );
358 msg_Err( p_intf, "ThumbBarSetImageList failed with error %08x", hr );
359 if(S_OK != p_taskbl->vt->ThumbBarAddButtons(p_taskbl, GetForegroundWindow(), 3, thbButtons))
360 msg_Err( p_intf, "ThumbBarAddButtons failed with error %08x", GetLastError() );
363 CONNECT( THEMIM->getIM(), statusChanged( int ), this, changeThumbbarButtons( int ) );
369 MainInterface::~MainInterface()
371 msg_Dbg( p_intf, "Destroying the main interface" );
373 /* Unsure we hide the videoWidget before destroying it */
374 if( videoIsActive ) videoWidget->hide();
376 /* Save playlist state */
380 QVLCTools::saveWidgetPosition( p_intf, "Playlist", playlistWidget );
382 delete playlistWidget;
386 ImageList_Destroy( himl );
388 p_taskbl->vt->Release(p_taskbl);
392 /* Be sure to kill the actionsManager... FIXME */
393 ActionsManager::killInstance();
395 /* Delete the FSC controller */
396 delete fullscreenControls;
399 settings->beginGroup( "MainWindow" );
400 settings->setValue( "pl-dock-status", (int)i_pl_dock );
401 settings->setValue( "playlist-visible", (int)playlistVisible );
402 settings->setValue( "adv-controls",
403 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
405 settings->setValue( "mainBasedSize", mainBasedSize );
406 settings->setValue( "mainVideoSize", mainVideoSize );
409 settings->setValue( "backgroundSize", bgWidget->size() );
412 QVLCTools::saveWidgetPosition(settings, this);
413 settings->endGroup();
416 /* Unregister callbacks */
417 var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
418 var_DelCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
420 p_intf->p_sys->p_mi = NULL;
423 /*****************************
425 *****************************/
426 void MainInterface::recreateToolbars()
428 msg_Dbg( p_intf, "Recreating the toolbars" );
429 settings->beginGroup( "MainWindow" );
432 controls = new ControlsWidget( p_intf, false, this ); /* FIXME */
433 CONNECT( controls, advancedControlsToggled( bool ),
434 this, doComponentsUpdate() );
435 CONNECT( controls, sizeChanged(),
436 this, doComponentsUpdate() );
437 inputC = new InputControlsWidget( p_intf, this );
439 mainLayout->addWidget( inputC, 2, 0, 1, -1, Qt::AlignBottom );
440 mainLayout->addWidget( controls, settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
441 0, 1, -1, Qt::AlignBottom );
442 settings->endGroup();
445 void MainInterface::createMainWidget( QSettings *settings )
447 /* Create the main Widget and the mainLayout */
448 QWidget *main = new QWidget;
449 setCentralWidget( main );
450 mainLayout = new QGridLayout( main );
452 /* Margins, spacing */
453 main->setContentsMargins( 0, 0, 0, 0 );
454 main->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
455 mainLayout->setSpacing( 0 );
456 mainLayout->setMargin( 0 );
459 /* Disabled for now, they SUCK */
461 visualSelector = new VisualSelector( p_intf );
462 mainLayout->insertWidget( 0, visualSelector );
463 visualSelector->hide();
467 bgWidget = new BackgroundWidget( p_intf );
469 settings->value( "backgroundSize", QSize( 300, 200 ) ).toSize() );
470 bgWidget->updateGeometry();
472 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
473 i_visualmode != QT_MINIMAL_MODE )
478 /* And video Outputs */
479 if( videoEmbeddedFlag )
480 videoWidget = new VideoWidget( p_intf );
482 /* Create the CONTROLS Widget */
483 controls = new ControlsWidget( p_intf,
484 settings->value( "adv-controls", false ).toBool(), this );
485 CONNECT( controls, advancedControlsToggled( bool ),
486 this, doComponentsUpdate() );
487 CONNECT( controls, sizeChanged(),
488 this, doComponentsUpdate() );
489 inputC = new InputControlsWidget( p_intf, this );
492 /* Add the controls Widget to the main Widget */
494 mainLayout->addWidget( videoWidget, 0, 0, 1, -1 );
495 mainLayout->setRowStretch( 0, 10 );
497 mainLayout->addWidget( bgWidget, 1, 0, 1, -1 );
498 //mainLayout->setRowStretch( 1, 10 );
499 mainLayout->addWidget( inputC, 2, 0, 1, -1, Qt::AlignBottom );
500 mainLayout->addWidget( controls, settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
501 0, 1, -1, Qt::AlignBottom );
503 /* Finish the sizing */
504 main->updateGeometry();
506 getSettings()->endGroup();
510 /* Create the FULLSCREEN CONTROLS Widget */
511 if( config_GetInt( p_intf, "qt-fs-controller" ) )
513 fullscreenControls = new FullscreenControllerWidget( p_intf, this );
514 CONNECT( fullscreenControls, keyPressed( QKeyEvent * ),
515 this, handleKeyPress( QKeyEvent * ) );
519 inline void MainInterface::createStatusBar()
524 /* Widgets Creation*/
525 QStatusBar *statusBarr = statusBar();
527 TimeLabel *timeLabel = new TimeLabel( p_intf );
528 nameLabel = new QLabel( this );
529 nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
530 | Qt::TextSelectableByKeyboard );
531 SpeedLabel *speedLabel = new SpeedLabel( p_intf, "1.00x", this );
533 /* Styling those labels */
534 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
535 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
536 nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
538 /* and adding those */
539 statusBarr->addWidget( nameLabel, 8 );
540 statusBarr->addPermanentWidget( speedLabel, 0 );
541 statusBarr->addPermanentWidget( timeLabel, 0 );
543 /* timeLabel behaviour:
544 - double clicking opens the goto time dialog
545 - right-clicking and clicking just toggle between remaining and
547 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
549 CONNECT( THEMIM->getIM(), encryptionChanged( bool ),
550 this, showCryptedLabel( bool ) );
553 inline void MainInterface::initSystray()
555 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
556 bool b_systrayWanted = config_GetInt( p_intf, "qt-system-tray" );
558 if( config_GetInt( p_intf, "qt-start-minimized") > 0 )
560 if( b_systrayAvailable )
562 b_systrayWanted = true;
566 msg_Err( p_intf, "cannot start minimized without system tray bar" );
569 if( b_systrayAvailable && b_systrayWanted )
573 inline void MainInterface::askForPrivacy()
576 * Ask for the network policy on FIRST STARTUP
578 if( config_GetInt( p_intf, "qt-privacy-ask") )
580 QList<ConfigControl *> controls;
581 if( privacyDialog( &controls ) == QDialog::Accepted )
583 QList<ConfigControl *>::Iterator i;
584 for( i = controls.begin() ; i != controls.end() ; i++ )
586 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
587 c->doApply( p_intf );
590 config_PutInt( p_intf, "qt-privacy-ask" , 0 );
591 /* We have to save here because the user may not launch Prefs */
592 config_SaveConfigFile( p_intf, NULL );
597 int MainInterface::privacyDialog( QList<ConfigControl *> *controls )
599 QDialog *privacy = new QDialog( this );
601 privacy->setWindowTitle( qtr( "Privacy and Network Policies" ) );
603 QGridLayout *gLayout = new QGridLayout( privacy );
605 QGroupBox *blabla = new QGroupBox( qtr( "Privacy and Network Warning" ) );
606 QGridLayout *blablaLayout = new QGridLayout( blabla );
607 QLabel *text = new QLabel( qtr(
608 "<p>The <i>VideoLAN Team</i> doesn't like when an application goes "
609 "online without authorization.</p>\n "
610 "<p><i>VLC media player</i> can retreive limited information from "
611 "the Internet in order to get CD covers or to check "
612 "for available updates.</p>\n"
613 "<p><i>VLC media player</i> <b>DOES NOT</b> send or collect <b>ANY</b> "
614 "information, even anonymously, about your usage.</p>\n"
615 "<p>Therefore please select from the following options, the default being "
616 "almost no access to the web.</p>\n") );
617 text->setWordWrap( true );
618 text->setTextFormat( Qt::RichText );
620 blablaLayout->addWidget( text, 0, 0 ) ;
622 QGroupBox *options = new QGroupBox;
623 QGridLayout *optionsLayout = new QGridLayout( options );
625 gLayout->addWidget( blabla, 0, 0, 1, 3 );
626 gLayout->addWidget( options, 1, 0, 1, 3 );
627 module_config_t *p_config;
628 ConfigControl *control;
631 #define CONFIG_GENERIC( option, type ) \
632 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
635 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
636 p_config, options, false, optionsLayout, line ); \
637 controls->append( control ); \
640 #define CONFIG_GENERIC_NOBOOL( option, type ) \
641 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
644 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
645 p_config, options, optionsLayout, line ); \
646 controls->append( control ); \
649 CONFIG_GENERIC( "album-art", IntegerList ); line++;
651 CONFIG_GENERIC_NOBOOL( "qt-updates-notif", Bool ); line++;
654 QPushButton *ok = new QPushButton( qtr( "OK" ) );
656 gLayout->addWidget( ok, 2, 2 );
658 CONNECT( ok, clicked(), privacy, accept() );
659 return privacy->exec();
663 /**********************************************************************
664 * Handling of sizing of the components
665 **********************************************************************/
667 /* This function is probably wrong, but we don't have many many choices...
668 Since we can't know from the playlist Widget if we are inside a dock or not,
669 because the playlist Widget can be called by THEDP, as a separate windows for
671 Maybe the other solution is to redefine the sizeHint() of the playlist and
672 ask _parent->isFloating()...
673 If you think this would be better, please FIXME it...
676 QSize MainInterface::sizeHint() const
680 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
681 i_visualmode == QT_MINIMAL_MODE )
683 return mainVideoSize;
687 if( VISIBLE( bgWidget) ||
688 ( videoIsActive && videoWidget->isVisible() )
690 return mainVideoSize;
692 return mainBasedSize;
696 int nwidth = controls->sizeHint().width();
697 int nheight = controls->isVisible() ?
698 controls->size().height()
699 + inputC->size().height()
700 + menuBar()->size().height()
701 + statusBar()->size().height()
704 if( VISIBLE( bgWidget ) )
707 nheight += i_bg_height;
709 nheight += bgWidget->size().height();
710 nwidth = __MAX( nwidth, bgWidget->size().width() );
712 else if( videoIsActive && videoWidget->isVisible() )
714 nheight += videoWidget->sizeHint().height();
715 nwidth = __MAX( nwidth, videoWidget->sizeHint().width() );
718 if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget() )
720 nheight += dockPL->size().height();
721 nwidth = __MAX( nwidth, dockPL->size().width() );
722 msg_Warn( p_intf, "3 %i %i", nheight, nwidth );
725 return QSize( nwidth, nheight );
728 /* Video widget cannot do this synchronously as it runs in another thread */
729 /* Well, could it, actually ? Probably dangerous ... */
731 /* This function is called:
732 - toggling of minimal View
733 - through askUpdate() by Vout thread request video and resize video (zoom)
734 - Advanced buttons toggled
736 void MainInterface::doComponentsUpdate()
738 if( isFullScreen() || isMaximized() ) return;
740 msg_Dbg( p_intf, "Updating the geometry" );
741 /* Here we resize to sizeHint() and not adjustsize because we want
742 the videoWidget to be exactly the correctSize */
743 resize( sizeHint() );
750 void MainInterface::debug()
753 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
754 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
755 if( videoWidget && videoWidget->isVisible() )
757 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
758 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
763 void MainInterface::destroyPopupMenu()
765 QVLCMenu::PopupMenu(p_intf, false );
769 void MainInterface::toggleFSC()
771 if( !fullscreenControls ) return;
773 IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
774 QApplication::postEvent( fullscreenControls, eShow );
777 void MainInterface::popupMenu( const QPoint &p )
779 /* Ow, that's ugly: don't show the popup menu if cursor over
780 * the main menu bar or the status bar */
781 if( !childAt( p ) || ( ( childAt( p ) != menuBar() )
782 && ( childAt( p )->parentWidget() != statusBar() ) ) )
783 QVLCMenu::PopupMenu( p_intf, true );
786 /****************************************************************************
788 ****************************************************************************/
790 /* This event is used to deal with the fullscreen and always on top
791 issue conflict (bug in wx) */
792 class SetVideoOnTopQtEvent : public QEvent
795 SetVideoOnTopQtEvent( bool _onTop ) :
796 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
799 bool OnTop() const { return onTop; }
807 * You must note change the state of this object or other Qt4 UI objects,
808 * from the video output thread - only from the Qt4 UI main loop thread.
809 * All window provider queries must be handled through signals or events.
810 * That's why we have all those emit statements...
812 WId MainInterface::getVideo( int *pi_x, int *pi_y,
813 unsigned int *pi_width, unsigned int *pi_height )
818 /* This is a blocking call signal. Results are returned through pointers.
819 * Beware of deadlocks! */
821 emit askGetVideo( &id, pi_x, pi_y, pi_width, pi_height );
825 void MainInterface::getVideoSlot( WId *p_id, int *pi_x, int *pi_y,
826 unsigned *pi_width, unsigned *pi_height )
828 /* Request the videoWidget */
829 WId ret = videoWidget->request( pi_x, pi_y,
830 pi_width, pi_height, b_keep_size );
832 if( ret ) /* The videoWidget is available */
834 /* Did we have a bg ? Hide it! */
835 if( VISIBLE( bgWidget) )
841 bgWasVisible = false;
843 /* ask videoWidget to show */
844 videoWidget->SetSizing( *pi_width, *pi_height );
846 /* Consider the video active now */
847 videoIsActive = true;
853 /* Asynchronous call from the WindowClose function */
854 void MainInterface::releaseVideo( void )
856 emit askReleaseVideo( );
859 /* Function that is CONNECTED to the previous emit */
860 void MainInterface::releaseVideoSlot( void )
862 videoWidget->release( );
866 /* Reset the bg state */
867 bgWasVisible = false;
871 videoIsActive = false;
873 /* Try to resize, except when you are in Fullscreen mode */
874 doComponentsUpdate();
877 /* Asynchronous call from WindowControl function */
878 int MainInterface::controlVideo( int i_query, va_list args )
882 case VOUT_WINDOW_SET_SIZE:
884 unsigned int i_width = va_arg( args, unsigned int );
885 unsigned int i_height = va_arg( args, unsigned int );
886 emit askVideoToResize( i_width, i_height );
890 case VOUT_WINDOW_SET_ON_TOP:
892 int i_arg = va_arg( args, int );
893 QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
896 case VOUT_WINDOW_SET_FULLSCREEN:
898 bool b_fs = va_arg( args, int );
899 emit askVideoSetFullScreen( b_fs );
903 msg_Warn( p_intf, "unsupported control query" );
908 /*****************************************************************************
909 * Playlist, Visualisation and Menus handling
910 *****************************************************************************/
912 * Toggle the playlist widget or dialog
914 void MainInterface::togglePlaylist()
917 If no playlist exist, then create one and attach it to the DockPL*/
918 if( !playlistWidget )
920 playlistWidget = new PlaylistWidget( p_intf );
922 i_pl_dock = PL_UNDOCKED;
923 /* i_pl_dock = (pl_dock_e)getSettings()
924 ->value( "pl-dock-status", PL_UNDOCKED ).toInt(); */
926 if( i_pl_dock == PL_UNDOCKED )
928 playlistWidget->setWindowFlags( Qt::Window );
930 /* This will restore the geometry but will not work for position,
931 because of parenting */
932 QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
933 playlistWidget, QSize( 600, 300 ) );
937 // mainLayout->insertWidget( 4, playlistWidget );
939 playlistVisible = true;
941 playlistWidget->show();
945 /* toggle the visibility of the playlist */
946 TOGGLEV( playlistWidget );
947 playlistVisible = !playlistVisible;
948 //doComponentsUpdate(); //resize( sizeHint() );
952 /* Function called from the menu to undock the playlist */
953 void MainInterface::undockPlaylist()
955 // dockPL->setFloating( true );
959 void MainInterface::dockPlaylist( pl_dock_e i_pos )
963 void MainInterface::toggleMinimalView( bool b_switch )
965 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
966 i_visualmode != QT_MINIMAL_MODE )
967 { /* NORMAL MODE then */
968 if( !videoWidget || videoWidget->isHidden() )
974 /* If video is visible, then toggle the status of bgWidget */
975 bgWasVisible = !bgWasVisible;
979 i_bg_height = bgWidget->height();
981 menuBar()->setVisible( !b_switch );
982 controls->setVisible( !b_switch );
983 statusBar()->setVisible( !b_switch );
984 inputC->setVisible( !b_switch );
986 doComponentsUpdate();
988 emit minimalViewToggled( b_switch );
991 /* toggling advanced controls buttons */
992 void MainInterface::toggleAdvanced()
994 controls->toggleAdvanced();
995 // if( fullscreenControls ) fullscreenControls->toggleAdvanced();
998 /* Get the visibility status of the controls (hidden or not, advanced or not) */
999 int MainInterface::getControlsVisibilityStatus()
1001 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
1002 + CONTROLS_ADVANCED * controls->b_advancedVisible );
1006 void MainInterface::visual()
1008 if( !VISIBLE( visualSelector) )
1010 visualSelector->show();
1011 if( !THEMIM->getIM()->hasVideo() )
1013 /* Show the background widget */
1015 visualSelectorEnabled = true;
1019 /* Stop any currently running visualization */
1020 visualSelector->hide();
1021 visualSelectorEnabled = false;
1023 doComponentsUpdate();
1027 /************************************************************************
1029 ************************************************************************/
1030 void MainInterface::setName( const QString& name )
1032 input_name = name; /* store it for the QSystray use */
1033 /* Display it in the status bar, but also as a Tooltip in case it doesn't
1035 nameLabel->setText( " " + name + " " );
1036 nameLabel->setToolTip( " " + name +" " );
1040 * Give the decorations of the Main Window a correct Name.
1041 * If nothing is given, set it to VLC...
1043 void MainInterface::setVLCWindowsTitle( const QString& aTitle )
1045 if( aTitle.isEmpty() )
1047 setWindowTitle( qtr( "VLC media player" ) );
1051 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
1055 void MainInterface::showCryptedLabel( bool b_show )
1057 if( cryptedLabel == NULL )
1059 cryptedLabel = new QLabel;
1060 // The lock icon is not the right one for DRM protection/scrambled.
1061 //cryptedLabel->setPixmap( QPixmap( ":/lock" ) );
1062 cryptedLabel->setText( "DRM" );
1063 statusBar()->addWidget( cryptedLabel );
1066 cryptedLabel->setVisible( b_show );
1069 /*****************************************************************************
1070 * Systray Icon and Systray Menu
1071 *****************************************************************************/
1074 * Create a SystemTray icon and a menu that would go with it.
1075 * Connects to a click handler on the icon.
1077 void MainInterface::createSystray()
1080 if( QDate::currentDate().dayOfYear() >= 354 )
1081 iconVLC = QIcon( QPixmap( ":/logo/vlc128-christmas.png" ) );
1083 iconVLC = QIcon( QPixmap( ":/logo/vlc128.png" ) );
1084 sysTray = new QSystemTrayIcon( iconVLC, this );
1085 sysTray->setToolTip( qtr( "VLC media player" ));
1087 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
1088 systrayMenu->setIcon( iconVLC );
1090 QVLCMenu::updateSystrayMenu( this, p_intf, true );
1093 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
1094 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
1098 * Updates the Systray Icon's menu and toggle the main interface
1100 void MainInterface::toggleUpdateSystrayMenu()
1102 /* If hidden, show it */
1108 else if( isMinimized() )
1116 /* Visible (possibly under other windows) */
1118 /* check if any visible window is above vlc in the z-order,
1119 * but ignore the ones always on top
1120 * and the ones which can't be activated */
1123 wi.cbSize = sizeof( WINDOWINFO );
1124 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
1125 hwnd && ( !IsWindowVisible( hwnd ) ||
1126 ( GetWindowInfo( hwnd, &wi ) &&
1127 (wi.dwExStyle&WS_EX_NOACTIVATE) ) );
1128 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
1129 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
1130 (wi.dwExStyle&WS_EX_TOPMOST) )
1142 QVLCMenu::updateSystrayMenu( this, p_intf );
1145 void MainInterface::handleSystrayClick(
1146 QSystemTrayIcon::ActivationReason reason )
1150 case QSystemTrayIcon::Trigger:
1151 case QSystemTrayIcon::DoubleClick:
1152 toggleUpdateSystrayMenu();
1154 case QSystemTrayIcon::MiddleClick:
1155 sysTray->showMessage( qtr( "VLC media player" ),
1156 qtr( "Control menu for the player" ),
1157 QSystemTrayIcon::Information, 3000 );
1165 * Updates the name of the systray Icon tooltip.
1166 * Doesn't check if the systray exists, check before you call it.
1168 void MainInterface::updateSystrayTooltipName( const QString& name )
1170 if( name.isEmpty() )
1172 sysTray->setToolTip( qtr( "VLC media player" ) );
1176 sysTray->setToolTip( name );
1177 if( notificationEnabled && ( isHidden() || isMinimized() ) )
1179 sysTray->showMessage( qtr( "VLC media player" ), name,
1180 QSystemTrayIcon::NoIcon, 3000 );
1184 QVLCMenu::updateSystrayMenu( this, p_intf );
1188 * Updates the status of the systray Icon tooltip.
1189 * Doesn't check if the systray exists, check before you call it.
1191 void MainInterface::updateSystrayTooltipStatus( int i_status )
1198 sysTray->setToolTip( qtr( "VLC media player" ) );
1203 sysTray->setToolTip( input_name );
1208 sysTray->setToolTip( input_name + " - "
1213 QVLCMenu::updateSystrayMenu( this, p_intf );
1216 /************************************************************************
1218 ************************************************************************/
1219 void MainInterface::dropEvent(QDropEvent *event)
1221 dropEventPlay( event, true );
1224 void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
1226 event->setDropAction( Qt::CopyAction );
1227 if( !event->possibleActions() & Qt::CopyAction )
1230 const QMimeData *mimeData = event->mimeData();
1232 /* D&D of a subtitles file, add it on the fly */
1233 if( mimeData->urls().size() == 1 )
1235 if( THEMIM->getIM()->hasInput() )
1237 if( !input_AddSubtitle( THEMIM->getInput(),
1238 qtu( toNativeSeparators(
1239 mimeData->urls()[0].toLocalFile() ) ),
1247 bool first = b_play;
1248 foreach( const QUrl &url, mimeData->urls() )
1250 QString s = toNativeSeparators( url.toLocalFile() );
1252 if( s.length() > 0 ) {
1253 playlist_Add( THEPL, qtu(s), NULL,
1254 PLAYLIST_APPEND | (first ? PLAYLIST_GO: PLAYLIST_PREPARSE),
1255 PLAYLIST_END, true, pl_Unlocked );
1257 RecentsMRL::getInstance( p_intf )->addRecent( s );
1262 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1264 event->acceptProposedAction();
1266 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1268 event->acceptProposedAction();
1270 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1275 /************************************************************************
1277 ************************************************************************/
1278 void MainInterface::customEvent( QEvent *event )
1281 if( event->type() == PLDockEvent_Type )
1283 PlaylistDialog::killInstance();
1284 playlistEmbeddedFlag = true;
1286 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1291 if ( event->type() == (int)SetVideoOnTopEvent_Type )
1293 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1294 if( p_event->OnTop() )
1295 setWindowFlags( windowFlags() | Qt::WindowStaysOnTopHint );
1297 setWindowFlags( windowFlags() & ~Qt::WindowStaysOnTopHint );
1298 show(); /* necessary to apply window flags */
1302 void MainInterface::keyPressEvent( QKeyEvent *e )
1304 handleKeyPress( e );
1307 void MainInterface::handleKeyPress( QKeyEvent *e )
1309 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() == Qt::Key_H )
1310 && !menuBar()->isVisible() )
1312 toggleMinimalView( false );
1316 int i_vlck = qtEventToVLCKey( e );
1319 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1326 void MainInterface::resizeEvent( QResizeEvent * event )
1330 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
1331 i_visualmode == QT_MINIMAL_MODE )
1333 mainVideoSize = size();
1337 if( VISIBLE( bgWidget) ||
1338 ( videoIsActive && videoWidget->isVisible() )
1340 mainVideoSize = size();
1342 mainBasedSize = size();
1347 void MainInterface::wheelEvent( QWheelEvent *e )
1349 int i_vlckey = qtWheelEventToVLCKey( e );
1350 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1354 void MainInterface::closeEvent( QCloseEvent *e )
1361 void MainInterface::toggleFullScreen( void )
1363 if( isFullScreen() )
1366 emit askUpdate(); // Needed if video was launched after the F11
1367 emit fullscreenInterfaceToggled( false );
1372 emit fullscreenInterfaceToggled( true );
1377 //moc doesn't know about #ifdef, so we have to build this method for every platform
1378 void MainInterface::changeThumbbarButtons( int i_status)
1381 // Define an array of two buttons. These buttons provide images through an
1382 // image list and also provide tooltips.
1383 DWORD dwMask = THB_BITMAP | THB_FLAGS;
1385 THUMBBUTTON thbButtons[3];
1387 thbButtons[0].dwMask = dwMask;
1388 thbButtons[0].iId = 0;
1389 thbButtons[0].iBitmap = 0;
1392 thbButtons[1].dwMask = dwMask;
1393 thbButtons[1].iId = 1;
1396 thbButtons[2].dwMask = dwMask;
1397 thbButtons[2].iId = 2;
1398 thbButtons[2].iBitmap = 3;
1405 thbButtons[0].dwFlags = THBF_HIDDEN;
1406 thbButtons[1].dwFlags = THBF_HIDDEN;
1407 thbButtons[2].dwFlags = THBF_HIDDEN;
1412 thbButtons[0].dwFlags = THBF_ENABLED;
1413 thbButtons[1].dwFlags = THBF_ENABLED;
1414 thbButtons[2].dwFlags = THBF_ENABLED;
1415 thbButtons[1].iBitmap = 1;
1420 //thbButtons[0].dwFlags = THBF_ENABLED;
1421 //thbButtons[1].dwFlags = THBF_ENABLED;
1422 //thbButtons[2].dwFlags = THBF_ENABLED;
1423 thbButtons[1].iBitmap = 2;
1428 HRESULT hr = p_taskbl->vt->ThumbBarUpdateButtons(p_taskbl, GetForegroundWindow(), 3, thbButtons);
1430 msg_Err( p_intf, "ThumbBarUpdateButtons failed with error %08x", hr );
1436 /*****************************************************************************
1437 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1438 * We don't show the menu directly here because we don't want the
1439 * caller to block for a too long time.
1440 *****************************************************************************/
1441 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1442 vlc_value_t old_val, vlc_value_t new_val, void *param )
1444 intf_thread_t *p_intf = (intf_thread_t *)param;
1446 if( p_intf->pf_show_dialog )
1448 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1449 new_val.b_bool, NULL );
1455 /*****************************************************************************
1456 * IntfShowCB: callback triggered by the intf-show libvlc variable.
1457 *****************************************************************************/
1458 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1459 vlc_value_t old_val, vlc_value_t new_val, void *param )
1461 intf_thread_t *p_intf = (intf_thread_t *)param;
1462 p_intf->p_sys->p_mi->toggleFSC();