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;
88 videoIsActive = false;
89 playlistVisible = false;
91 fullscreenControls = NULL;
100 /* Ask for privacy */
104 * Configuration and settings
105 * Pre-building of interface
108 setFocusPolicy( Qt::StrongFocus );
109 setAcceptDrops( true );
110 setWindowRole( "vlc-main" );
111 setWindowIcon( QApplication::windowIcon() );
112 setWindowOpacity( config_GetFloat( p_intf, "qt-opacity" ) );
114 /* Set The Video In emebedded Mode or not */
115 videoEmbeddedFlag = config_GetInt( p_intf, "embedded-video" );
117 /* Does the interface resize to video size or the opposite */
118 b_keep_size = !config_GetInt( p_intf, "qt-video-autoresize" );
120 /* Are we in the enhanced always-video mode or not ? */
121 i_visualmode = config_GetInt( p_intf, "qt-display-mode" );
123 /* Do we want anoying popups or not */
124 notificationEnabled = (bool)config_GetInt( p_intf, "qt-notification" );
126 /* Set the other interface settings */
127 settings = getSettings();
128 settings->beginGroup( "MainWindow" );
131 * Retrieve saved sizes for main window
132 * mainBasedSize = based window size for normal mode
133 * (no video, no background)
134 * mainVideoSize = window size with video (all modes)
136 mainBasedSize = settings->value( "mainBasedSize", QSize( 350, 120 ) ).toSize();
137 mainVideoSize = settings->value( "mainVideoSize", QSize( 400, 300 ) ).toSize();
144 /**************************
145 * UI and Widgets design
146 **************************/
147 setVLCWindowsTitle();
148 createMainWidget( settings );
153 QVLCMenu::createMenuBar( this, p_intf );
154 CONNECT( THEMIM->getIM(), voutListChanged( vout_thread_t **, int ),
155 this, destroyPopupMenu() );
158 /* Create a Dock to get the playlist */
159 dockPL = new QDockWidget( qtr( "Playlist" ), this );
160 dockPL->setSizePolicy( QSizePolicy::Preferred,
161 QSizePolicy::Expanding );
162 dockPL->setFeatures( QDockWidget::AllDockWidgetFeatures );
163 dockPL->setAllowedAreas( Qt::LeftDockWidgetArea
164 | Qt::RightDockWidgetArea
165 | Qt::BottomDockWidgetArea );
169 /*********************************
170 * Create the Systray Management *
171 *********************************/
174 /********************
176 ********************/
177 MainInputManager::getInstance( p_intf );
179 /************************************************************
180 * Connect the input manager to the GUI elements it manages *
181 ************************************************************/
183 * Connects on nameChanged()
184 * Those connects are different because options can impeach them to trigger.
186 /* Main Interface statusbar */
187 CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
188 this, setName( const QString& ) );
193 CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
194 this, updateSystrayTooltipName( const QString& ) );
197 /* and title of the Main Interface*/
198 if( config_GetInt( p_intf, "qt-name-in-title" ) )
200 CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
201 this, setVLCWindowsTitle( const QString& ) );
205 * CONNECTS on PLAY_STATUS
207 /* Status on the systray */
211 CONNECT( THEMIM->getIM(), statusChanged( int ),
212 this, updateSystrayTooltipStatus( int ) );
216 /* END CONNECTS ON IM */
221 var_AddCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
223 /* Register callback for the intf-popupmenu variable */
224 var_AddCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
227 /* VideoWidget connects for asynchronous calls */
228 connect( this, SIGNAL(askGetVideo(WId*,int*,int*,unsigned*,unsigned *)),
229 this, SLOT(getVideoSlot(WId*,int*,int*,unsigned*,unsigned*)),
230 Qt::BlockingQueuedConnection );
231 connect( this, SIGNAL(askReleaseVideo( void )),
232 this, SLOT(releaseVideoSlot( void )),
233 Qt::BlockingQueuedConnection );
237 CONNECT( this, askVideoToResize( unsigned int, unsigned int ),
238 videoWidget, SetSizing( unsigned int, unsigned int ) );
239 CONNECT( this, askVideoSetFullScreen( bool ),
240 videoWidget, SetFullScreen( bool ) );
241 CONNECT( videoWidget, keyPressed( QKeyEvent * ),
242 this, handleKeyPress( QKeyEvent * ) );
245 CONNECT( this, askUpdate(), this, doComponentsUpdate() );
246 CONNECT( THEDP, toolBarConfUpdated(), this, recreateToolbars() );
248 /* Size and placement of interface */
249 settings->beginGroup( "MainWindow" );
250 QVLCTools::restoreWidgetPosition( settings, this, QSize(380, 60) );
252 /* resize to previously saved main window size if appicable */
255 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
256 i_visualmode == QT_MINIMAL_MODE )
258 resize( mainVideoSize );
262 resize( mainBasedSize );
266 bool b_pl_visible = settings->value( "playlist-visible", 0 ).toInt();
267 settings->endGroup();
270 if( b_pl_visible ) togglePlaylist();
272 /* Enable the popup menu in the MI */
273 setContextMenuPolicy( Qt::CustomContextMenu );
274 CONNECT( this, customContextMenuRequested( const QPoint& ),
275 this, popupMenu( const QPoint& ) );
277 /* Final sizing and showing */
278 setMinimumWidth( __MAX( controls->sizeHint().width(),
279 menuBar()->sizeHint().width() ) );
280 setVisible( !b_shouldHide );
282 /* And switch to minimal view if needed
283 Must be called after the show() */
284 if( i_visualmode == QT_MINIMAL_MODE )
285 toggleMinimalView( true );
287 /* Update the geometry : It is useful if you switch between
290 resize( sizeHint() );
293 createTaskBarButtons();
297 MainInterface::~MainInterface()
299 msg_Dbg( p_intf, "Destroying the main interface" );
301 /* Unsure we hide the videoWidget before destroying it */
302 if( videoIsActive ) videoWidget->hide();
304 /* Save playlist state */
308 QVLCTools::saveWidgetPosition( p_intf, "Playlist", playlistWidget );
310 delete playlistWidget;
315 ImageList_Destroy( himl );
317 p_taskbl->vt->Release(p_taskbl);
321 /* Be sure to kill the actionsManager... FIXME */
322 ActionsManager::killInstance();
324 /* Delete the FSC controller */
325 delete fullscreenControls;
328 settings->beginGroup( "MainWindow" );
329 settings->setValue( "pl-dock-status", (int)i_pl_dock );
330 settings->setValue( "playlist-visible", (int)playlistVisible );
331 settings->setValue( "adv-controls",
332 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
334 settings->setValue( "mainBasedSize", mainBasedSize );
335 settings->setValue( "mainVideoSize", mainVideoSize );
338 settings->setValue( "backgroundSize", bgWidget->size() );
341 QVLCTools::saveWidgetPosition(settings, this);
342 settings->endGroup();
345 /* Unregister callbacks */
346 var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
347 var_DelCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
349 p_intf->p_sys->p_mi = NULL;
352 /*****************************
354 *****************************/
355 void MainInterface::recreateToolbars()
357 msg_Dbg( p_intf, "Recreating the toolbars" );
358 settings->beginGroup( "MainWindow" );
361 controls = new ControlsWidget( p_intf, false, this ); /* FIXME */
362 CONNECT( controls, advancedControlsToggled( bool ),
363 this, doComponentsUpdate() );
364 CONNECT( controls, sizeChanged(),
365 this, doComponentsUpdate() );
366 inputC = new InputControlsWidget( p_intf, this );
368 mainLayout->addWidget( inputC, 2, 0, 1, -1, Qt::AlignBottom );
369 mainLayout->addWidget( controls, settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
370 0, 1, -1, Qt::AlignBottom );
371 settings->endGroup();
374 void MainInterface::createMainWidget( QSettings *settings )
376 /* Create the main Widget and the mainLayout */
377 QWidget *main = new QWidget;
378 setCentralWidget( main );
379 mainLayout = new QGridLayout( main );
381 /* Margins, spacing */
382 main->setContentsMargins( 0, 0, 0, 0 );
383 main->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
384 mainLayout->setSpacing( 0 );
385 mainLayout->setMargin( 0 );
388 /* Disabled for now, they SUCK */
390 visualSelector = new VisualSelector( p_intf );
391 mainLayout->insertWidget( 0, visualSelector );
392 visualSelector->hide();
396 bgWidget = new BackgroundWidget( p_intf );
398 settings->value( "backgroundSize", QSize( 300, 200 ) ).toSize() );
399 bgWidget->updateGeometry();
401 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
402 i_visualmode != QT_MINIMAL_MODE )
407 /* And video Outputs */
408 if( videoEmbeddedFlag )
409 videoWidget = new VideoWidget( p_intf );
411 /* Create the CONTROLS Widget */
412 controls = new ControlsWidget( p_intf,
413 settings->value( "adv-controls", false ).toBool(), this );
414 CONNECT( controls, advancedControlsToggled( bool ),
415 this, doComponentsUpdate() );
416 CONNECT( controls, sizeChanged(),
417 this, doComponentsUpdate() );
418 inputC = new InputControlsWidget( p_intf, this );
421 /* Add the controls Widget to the main Widget */
423 mainLayout->addWidget( videoWidget, 0, 0, 1, -1 );
424 mainLayout->setRowStretch( 0, 10 );
426 mainLayout->addWidget( bgWidget, 1, 0, 1, -1 );
427 //mainLayout->setRowStretch( 1, 10 );
428 mainLayout->addWidget( inputC, 2, 0, 1, -1, Qt::AlignBottom );
429 mainLayout->addWidget( controls, settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
430 0, 1, -1, Qt::AlignBottom );
432 /* Finish the sizing */
433 main->updateGeometry();
435 getSettings()->endGroup();
439 /* Create the FULLSCREEN CONTROLS Widget */
440 if( config_GetInt( p_intf, "qt-fs-controller" ) )
442 fullscreenControls = new FullscreenControllerWidget( p_intf, this );
443 CONNECT( fullscreenControls, keyPressed( QKeyEvent * ),
444 this, handleKeyPress( QKeyEvent * ) );
448 inline void MainInterface::createStatusBar()
453 /* Widgets Creation*/
454 QStatusBar *statusBarr = statusBar();
456 TimeLabel *timeLabel = new TimeLabel( p_intf );
457 nameLabel = new QLabel( this );
458 nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
459 | Qt::TextSelectableByKeyboard );
460 SpeedLabel *speedLabel = new SpeedLabel( p_intf, "1.00x", this );
462 /* Styling those labels */
463 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
464 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
465 nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
467 /* and adding those */
468 statusBarr->addWidget( nameLabel, 8 );
469 statusBarr->addPermanentWidget( speedLabel, 0 );
470 statusBarr->addPermanentWidget( timeLabel, 0 );
472 /* timeLabel behaviour:
473 - double clicking opens the goto time dialog
474 - right-clicking and clicking just toggle between remaining and
476 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
478 CONNECT( THEMIM->getIM(), encryptionChanged( bool ),
479 this, showCryptedLabel( bool ) );
483 void MainInterface::createTaskBarButtons()
485 /*Here is the code for the taskbar thumb buttons
486 FIXME:We need pretty buttons in 16x16 px that are handled correctly by masks in Qt
487 FIXME:the play button's picture doesn't changed to pause when clicked
489 OSVERSIONINFO winVer;
490 winVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
491 if( GetVersionEx(&winVer) && winVer.dwMajorVersion > 5 )
493 if(himl = ImageList_Create( 15, //cx
496 4,//initial nb of images
497 0//nb of images that can be added
500 QPixmap img = QPixmap(":/toolbar/previous_b");
501 QPixmap img2 = QPixmap(":/toolbar/pause_b");
502 QPixmap img3 = QPixmap(":/toolbar/play_b");
503 QPixmap img4 = QPixmap(":/toolbar/next_b");
504 QBitmap mask = img.createMaskFromColor(Qt::transparent);
505 QBitmap mask2 = img2.createMaskFromColor(Qt::transparent);
506 QBitmap mask3 = img3.createMaskFromColor(Qt::transparent);
507 QBitmap mask4 = img4.createMaskFromColor(Qt::transparent);
509 if(-1 == ImageList_Add(himl, img.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask.toWinHBITMAP()))
510 msg_Err( p_intf, "ImageList_Add failed" );
511 if(-1 == ImageList_Add(himl, img2.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask2.toWinHBITMAP()))
512 msg_Err( p_intf, "ImageList_Add failed" );
513 if(-1 == ImageList_Add(himl, img3.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask3.toWinHBITMAP()))
514 msg_Err( p_intf, "ImageList_Add failed" );
515 if(-1 == ImageList_Add(himl, img4.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask4.toWinHBITMAP()))
516 msg_Err( p_intf, "ImageList_Add failed" );
521 if( S_OK == CoCreateInstance( &clsid_ITaskbarList,
522 NULL, CLSCTX_INPROC_SERVER,
524 (void **)&p_taskbl) )
526 p_taskbl->vt->HrInit(p_taskbl);
528 int msg_value = RegisterWindowMessage("TaskbarButtonCreated");
529 //msg_Info( p_intf, "msg value: %04x", msg_value );
531 // Define an array of two buttons. These buttons provide images through an
532 // image list and also provide tooltips.
533 DWORD dwMask = THB_BITMAP | THB_FLAGS;
535 THUMBBUTTON thbButtons[2];
536 thbButtons[0].dwMask = dwMask;
537 thbButtons[0].iId = 0;
538 thbButtons[0].iBitmap = 0;
539 thbButtons[0].dwFlags = THBF_HIDDEN;
541 thbButtons[1].dwMask = dwMask;
542 thbButtons[1].iId = 1;
543 thbButtons[1].iBitmap = 2;
544 thbButtons[1].dwFlags = THBF_HIDDEN;
546 thbButtons[2].dwMask = dwMask;
547 thbButtons[2].iId = 2;
548 thbButtons[2].iBitmap = 3;
549 thbButtons[2].dwFlags = THBF_HIDDEN;
551 HRESULT hr = p_taskbl->vt->ThumbBarSetImageList(p_taskbl, GetForegroundWindow(), himl );
553 msg_Err( p_intf, "ThumbBarSetImageList failed with error %08x", hr );
554 if(S_OK != p_taskbl->vt->ThumbBarAddButtons(p_taskbl, GetForegroundWindow(), 3, thbButtons))
555 msg_Err( p_intf, "ThumbBarAddButtons failed with error %08x", GetLastError() );
557 CONNECT( THEMIM->getIM(), statusChanged( int ), this, changeThumbbarButtons( int ) );
569 inline void MainInterface::initSystray()
572 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
573 bool b_systrayWanted = config_GetInt( p_intf, "qt-system-tray" );
575 if( config_GetInt( p_intf, "qt-start-minimized") > 0 )
577 if( b_systrayAvailable )
579 b_systrayWanted = true;
583 msg_Err( p_intf, "cannot start minimized without system tray bar" );
586 if( b_systrayAvailable && b_systrayWanted )
591 inline void MainInterface::askForPrivacy()
595 * Ask for the network policy on FIRST STARTUP
597 if( config_GetInt( p_intf, "qt-privacy-ask") )
599 QList<ConfigControl *> controls;
600 if( privacyDialog( &controls ) == QDialog::Accepted )
602 QList<ConfigControl *>::Iterator i;
603 for( i = controls.begin() ; i != controls.end() ; i++ )
605 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
606 c->doApply( p_intf );
609 config_PutInt( p_intf, "qt-privacy-ask" , 0 );
610 /* We have to save here because the user may not launch Prefs */
611 config_SaveConfigFile( p_intf, NULL );
617 int MainInterface::privacyDialog( QList<ConfigControl *> *controls )
619 QDialog *privacy = new QDialog( this );
621 privacy->setWindowTitle( qtr( "Privacy and Network Policies" ) );
622 privacy->setWindowRole( "vlc-privacy" );
624 QGridLayout *gLayout = new QGridLayout( privacy );
626 QGroupBox *blabla = new QGroupBox( qtr( "Privacy and Network Warning" ) );
627 QGridLayout *blablaLayout = new QGridLayout( blabla );
628 QLabel *text = new QLabel( qtr(
629 "<p>The <i>VideoLAN Team</i> doesn't like when an application goes "
630 "online without authorization.</p>\n "
631 "<p><i>VLC media player</i> can retreive limited information from "
632 "the Internet in order to get CD covers or to check "
633 "for available updates.</p>\n"
634 "<p><i>VLC media player</i> <b>DOES NOT</b> send or collect <b>ANY</b> "
635 "information, even anonymously, about your usage.</p>\n"
636 "<p>Therefore please select from the following options, the default being "
637 "almost no access to the web.</p>\n") );
638 text->setWordWrap( true );
639 text->setTextFormat( Qt::RichText );
641 blablaLayout->addWidget( text, 0, 0 ) ;
643 QGroupBox *options = new QGroupBox;
644 QGridLayout *optionsLayout = new QGridLayout( options );
646 gLayout->addWidget( blabla, 0, 0, 1, 3 );
647 gLayout->addWidget( options, 1, 0, 1, 3 );
648 module_config_t *p_config;
649 ConfigControl *control;
652 #define CONFIG_GENERIC( option, type ) \
653 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
656 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
657 p_config, options, false, optionsLayout, line ); \
658 controls->append( control ); \
661 #define CONFIG_GENERIC_NOBOOL( option, type ) \
662 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
665 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
666 p_config, options, optionsLayout, line ); \
667 controls->append( control ); \
670 CONFIG_GENERIC( "album-art", IntegerList ); line++;
672 CONFIG_GENERIC_NOBOOL( "qt-updates-notif", Bool ); line++;
675 QPushButton *ok = new QPushButton( qtr( "OK" ) );
677 gLayout->addWidget( ok, 2, 2 );
679 CONNECT( ok, clicked(), privacy, accept() );
680 return privacy->exec();
684 /**********************************************************************
685 * Handling of sizing of the components
686 **********************************************************************/
688 /* This function is probably wrong, but we don't have many many choices...
689 Since we can't know from the playlist Widget if we are inside a dock or not,
690 because the playlist Widget can be called by THEDP, as a separate windows for
692 Maybe the other solution is to redefine the sizeHint() of the playlist and
693 ask _parent->isFloating()...
694 If you think this would be better, please FIXME it...
697 QSize MainInterface::sizeHint() const
701 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
702 i_visualmode == QT_MINIMAL_MODE )
704 return mainVideoSize;
708 if( VISIBLE( bgWidget) ||
709 ( videoIsActive && videoWidget->isVisible() )
711 return mainVideoSize;
713 return mainBasedSize;
717 int nwidth = controls->sizeHint().width();
718 int nheight = controls->isVisible() ?
719 controls->size().height()
720 + inputC->size().height()
721 + menuBar()->size().height()
722 + statusBar()->size().height()
725 if( VISIBLE( bgWidget ) )
728 nheight += i_bg_height;
730 nheight += bgWidget->size().height();
731 nwidth = __MAX( nwidth, bgWidget->size().width() );
733 else if( videoIsActive && videoWidget->isVisible() )
735 nheight += videoWidget->sizeHint().height();
736 nwidth = __MAX( nwidth, videoWidget->sizeHint().width() );
739 if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget() )
741 nheight += dockPL->size().height();
742 nwidth = __MAX( nwidth, dockPL->size().width() );
743 msg_Warn( p_intf, "3 %i %i", nheight, nwidth );
746 return QSize( nwidth, nheight );
749 /* Video widget cannot do this synchronously as it runs in another thread */
750 /* Well, could it, actually ? Probably dangerous ... */
752 /* This function is called:
753 - toggling of minimal View
754 - through askUpdate() by Vout thread request video and resize video (zoom)
755 - Advanced buttons toggled
757 void MainInterface::doComponentsUpdate()
759 if( isFullScreen() || isMaximized() ) return;
761 msg_Dbg( p_intf, "Updating the geometry" );
762 /* Here we resize to sizeHint() and not adjustsize because we want
763 the videoWidget to be exactly the correctSize */
764 resize( sizeHint() );
771 void MainInterface::debug()
774 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
775 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
776 if( videoWidget && videoWidget->isVisible() )
778 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
779 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
784 void MainInterface::destroyPopupMenu()
786 QVLCMenu::PopupMenu(p_intf, false );
790 void MainInterface::toggleFSC()
792 if( !fullscreenControls ) return;
794 IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
795 QApplication::postEvent( fullscreenControls, eShow );
798 void MainInterface::popupMenu( const QPoint &p )
800 /* Ow, that's ugly: don't show the popup menu if cursor over
801 * the main menu bar or the status bar */
802 if( !childAt( p ) || ( ( childAt( p ) != menuBar() )
803 && ( childAt( p )->parentWidget() != statusBar() ) ) )
804 QVLCMenu::PopupMenu( p_intf, true );
807 /****************************************************************************
809 ****************************************************************************/
811 /* This event is used to deal with the fullscreen and always on top
812 issue conflict (bug in wx) */
813 class SetVideoOnTopQtEvent : public QEvent
816 SetVideoOnTopQtEvent( bool _onTop ) :
817 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
820 bool OnTop() const { return onTop; }
828 * You must note change the state of this object or other Qt4 UI objects,
829 * from the video output thread - only from the Qt4 UI main loop thread.
830 * All window provider queries must be handled through signals or events.
831 * That's why we have all those emit statements...
833 WId MainInterface::getVideo( int *pi_x, int *pi_y,
834 unsigned int *pi_width, unsigned int *pi_height )
839 /* This is a blocking call signal. Results are returned through pointers.
840 * Beware of deadlocks! */
842 emit askGetVideo( &id, pi_x, pi_y, pi_width, pi_height );
846 void MainInterface::getVideoSlot( WId *p_id, int *pi_x, int *pi_y,
847 unsigned *pi_width, unsigned *pi_height )
849 /* Request the videoWidget */
850 WId ret = videoWidget->request( pi_x, pi_y,
851 pi_width, pi_height, b_keep_size );
853 if( ret ) /* The videoWidget is available */
855 /* Did we have a bg ? Hide it! */
856 if( VISIBLE( bgWidget) )
862 bgWasVisible = false;
864 /* ask videoWidget to show */
865 videoWidget->SetSizing( *pi_width, *pi_height );
867 /* Consider the video active now */
868 videoIsActive = true;
874 /* Asynchronous call from the WindowClose function */
875 void MainInterface::releaseVideo( void )
877 emit askReleaseVideo( );
880 /* Function that is CONNECTED to the previous emit */
881 void MainInterface::releaseVideoSlot( void )
883 videoWidget->release( );
887 /* Reset the bg state */
888 bgWasVisible = false;
892 videoIsActive = false;
894 /* Try to resize, except when you are in Fullscreen mode */
895 doComponentsUpdate();
898 /* Asynchronous call from WindowControl function */
899 int MainInterface::controlVideo( int i_query, va_list args )
903 case VOUT_WINDOW_SET_SIZE:
905 unsigned int i_width = va_arg( args, unsigned int );
906 unsigned int i_height = va_arg( args, unsigned int );
907 emit askVideoToResize( i_width, i_height );
911 case VOUT_WINDOW_SET_ON_TOP:
913 int i_arg = va_arg( args, int );
914 QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
917 case VOUT_WINDOW_SET_FULLSCREEN:
919 bool b_fs = va_arg( args, int );
920 emit askVideoSetFullScreen( b_fs );
924 msg_Warn( p_intf, "unsupported control query" );
929 /*****************************************************************************
930 * Playlist, Visualisation and Menus handling
931 *****************************************************************************/
933 * Toggle the playlist widget or dialog
935 void MainInterface::togglePlaylist()
938 If no playlist exist, then create one and attach it to the DockPL*/
939 if( !playlistWidget )
941 playlistWidget = new PlaylistWidget( p_intf );
943 i_pl_dock = PL_UNDOCKED;
944 /* i_pl_dock = (pl_dock_e)getSettings()
945 ->value( "pl-dock-status", PL_UNDOCKED ).toInt(); */
947 if( i_pl_dock == PL_UNDOCKED )
949 playlistWidget->setWindowFlags( Qt::Window );
951 /* This will restore the geometry but will not work for position,
952 because of parenting */
953 QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
954 playlistWidget, QSize( 600, 300 ) );
958 // mainLayout->insertWidget( 4, playlistWidget );
960 playlistVisible = true;
962 playlistWidget->show();
966 /* toggle the visibility of the playlist */
967 TOGGLEV( playlistWidget );
968 playlistVisible = !playlistVisible;
969 //doComponentsUpdate(); //resize( sizeHint() );
973 /* Function called from the menu to undock the playlist */
974 void MainInterface::undockPlaylist()
976 // dockPL->setFloating( true );
980 void MainInterface::dockPlaylist( pl_dock_e i_pos )
984 void MainInterface::toggleMinimalView( bool b_switch )
986 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
987 i_visualmode != QT_MINIMAL_MODE )
988 { /* NORMAL MODE then */
989 if( !videoWidget || videoWidget->isHidden() )
995 /* If video is visible, then toggle the status of bgWidget */
996 bgWasVisible = !bgWasVisible;
1000 i_bg_height = bgWidget->height();
1002 menuBar()->setVisible( !b_switch );
1003 controls->setVisible( !b_switch );
1004 statusBar()->setVisible( !b_switch );
1005 inputC->setVisible( !b_switch );
1007 doComponentsUpdate();
1009 emit minimalViewToggled( b_switch );
1012 /* toggling advanced controls buttons */
1013 void MainInterface::toggleAdvanced()
1015 controls->toggleAdvanced();
1016 // if( fullscreenControls ) fullscreenControls->toggleAdvanced();
1019 /* Get the visibility status of the controls (hidden or not, advanced or not) */
1020 int MainInterface::getControlsVisibilityStatus()
1022 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
1023 + CONTROLS_ADVANCED * controls->b_advancedVisible );
1027 void MainInterface::visual()
1029 if( !VISIBLE( visualSelector) )
1031 visualSelector->show();
1032 if( !THEMIM->getIM()->hasVideo() )
1034 /* Show the background widget */
1036 visualSelectorEnabled = true;
1040 /* Stop any currently running visualization */
1041 visualSelector->hide();
1042 visualSelectorEnabled = false;
1044 doComponentsUpdate();
1048 /************************************************************************
1050 ************************************************************************/
1051 void MainInterface::setName( const QString& name )
1053 input_name = name; /* store it for the QSystray use */
1054 /* Display it in the status bar, but also as a Tooltip in case it doesn't
1056 nameLabel->setText( " " + name + " " );
1057 nameLabel->setToolTip( " " + name +" " );
1061 * Give the decorations of the Main Window a correct Name.
1062 * If nothing is given, set it to VLC...
1064 void MainInterface::setVLCWindowsTitle( const QString& aTitle )
1066 if( aTitle.isEmpty() )
1068 setWindowTitle( qtr( "VLC media player" ) );
1072 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
1076 void MainInterface::showCryptedLabel( bool b_show )
1078 if( cryptedLabel == NULL )
1080 cryptedLabel = new QLabel;
1081 // The lock icon is not the right one for DRM protection/scrambled.
1082 //cryptedLabel->setPixmap( QPixmap( ":/lock" ) );
1083 cryptedLabel->setText( "DRM" );
1084 statusBar()->addWidget( cryptedLabel );
1087 cryptedLabel->setVisible( b_show );
1090 /*****************************************************************************
1091 * Systray Icon and Systray Menu
1092 *****************************************************************************/
1095 * Create a SystemTray icon and a menu that would go with it.
1096 * Connects to a click handler on the icon.
1098 void MainInterface::createSystray()
1101 if( QDate::currentDate().dayOfYear() >= 354 )
1102 iconVLC = QIcon( QPixmap( ":/logo/vlc128-christmas.png" ) );
1104 iconVLC = QIcon( QPixmap( ":/logo/vlc128.png" ) );
1105 sysTray = new QSystemTrayIcon( iconVLC, this );
1106 sysTray->setToolTip( qtr( "VLC media player" ));
1108 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
1109 systrayMenu->setIcon( iconVLC );
1111 QVLCMenu::updateSystrayMenu( this, p_intf, true );
1114 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
1115 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
1119 * Updates the Systray Icon's menu and toggle the main interface
1121 void MainInterface::toggleUpdateSystrayMenu()
1123 /* If hidden, show it */
1129 else if( isMinimized() )
1137 /* Visible (possibly under other windows) */
1139 /* check if any visible window is above vlc in the z-order,
1140 * but ignore the ones always on top
1141 * and the ones which can't be activated */
1144 wi.cbSize = sizeof( WINDOWINFO );
1145 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
1146 hwnd && ( !IsWindowVisible( hwnd ) ||
1147 ( GetWindowInfo( hwnd, &wi ) &&
1148 (wi.dwExStyle&WS_EX_NOACTIVATE) ) );
1149 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
1150 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
1151 (wi.dwExStyle&WS_EX_TOPMOST) )
1163 QVLCMenu::updateSystrayMenu( this, p_intf );
1166 void MainInterface::handleSystrayClick(
1167 QSystemTrayIcon::ActivationReason reason )
1171 case QSystemTrayIcon::Trigger:
1172 case QSystemTrayIcon::DoubleClick:
1173 toggleUpdateSystrayMenu();
1175 case QSystemTrayIcon::MiddleClick:
1176 sysTray->showMessage( qtr( "VLC media player" ),
1177 qtr( "Control menu for the player" ),
1178 QSystemTrayIcon::Information, 3000 );
1186 * Updates the name of the systray Icon tooltip.
1187 * Doesn't check if the systray exists, check before you call it.
1189 void MainInterface::updateSystrayTooltipName( const QString& name )
1191 if( name.isEmpty() )
1193 sysTray->setToolTip( qtr( "VLC media player" ) );
1197 sysTray->setToolTip( name );
1198 if( notificationEnabled && ( isHidden() || isMinimized() ) )
1200 sysTray->showMessage( qtr( "VLC media player" ), name,
1201 QSystemTrayIcon::NoIcon, 3000 );
1205 QVLCMenu::updateSystrayMenu( this, p_intf );
1209 * Updates the status of the systray Icon tooltip.
1210 * Doesn't check if the systray exists, check before you call it.
1212 void MainInterface::updateSystrayTooltipStatus( int i_status )
1219 sysTray->setToolTip( qtr( "VLC media player" ) );
1224 sysTray->setToolTip( input_name );
1229 sysTray->setToolTip( input_name + " - "
1234 QVLCMenu::updateSystrayMenu( this, p_intf );
1238 /************************************************************************
1240 ************************************************************************/
1241 void MainInterface::dropEvent(QDropEvent *event)
1243 dropEventPlay( event, true );
1246 void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
1248 event->setDropAction( Qt::CopyAction );
1249 if( !event->possibleActions() & Qt::CopyAction )
1252 const QMimeData *mimeData = event->mimeData();
1254 /* D&D of a subtitles file, add it on the fly */
1255 if( mimeData->urls().size() == 1 && THEMIM->getIM()->hasInput() )
1257 if( !input_AddSubtitle( THEMIM->getInput(),
1258 qtu( toNativeSeparators( mimeData->urls()[0].toLocalFile() ) ),
1266 bool first = b_play;
1267 foreach( const QUrl &url, mimeData->urls() )
1269 QString s = toNativeSeparators( url.toLocalFile() );
1271 if( s.length() > 0 ) {
1272 char* psz_uri = make_URI( qtu(s) );
1273 playlist_Add( THEPL, psz_uri, NULL,
1274 PLAYLIST_APPEND | (first ? PLAYLIST_GO: PLAYLIST_PREPARSE),
1275 PLAYLIST_END, true, pl_Unlocked );
1278 RecentsMRL::getInstance( p_intf )->addRecent( s );
1283 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1285 event->acceptProposedAction();
1287 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1289 event->acceptProposedAction();
1291 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1296 /************************************************************************
1298 ************************************************************************/
1299 void MainInterface::customEvent( QEvent *event )
1302 if( event->type() == PLDockEvent_Type )
1304 PlaylistDialog::killInstance();
1305 playlistEmbeddedFlag = true;
1307 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1312 if ( event->type() == (int)SetVideoOnTopEvent_Type )
1314 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1315 if( p_event->OnTop() )
1316 setWindowFlags( windowFlags() | Qt::WindowStaysOnTopHint );
1318 setWindowFlags( windowFlags() & ~Qt::WindowStaysOnTopHint );
1319 show(); /* necessary to apply window flags */
1323 void MainInterface::keyPressEvent( QKeyEvent *e )
1325 handleKeyPress( e );
1328 void MainInterface::handleKeyPress( QKeyEvent *e )
1330 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() == Qt::Key_H )
1331 && !menuBar()->isVisible() )
1333 toggleMinimalView( false );
1337 int i_vlck = qtEventToVLCKey( e );
1340 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1347 void MainInterface::resizeEvent( QResizeEvent * event )
1351 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
1352 i_visualmode == QT_MINIMAL_MODE )
1354 mainVideoSize = size();
1358 if( VISIBLE( bgWidget) ||
1359 ( videoIsActive && videoWidget->isVisible() )
1361 mainVideoSize = size();
1363 mainBasedSize = size();
1368 void MainInterface::wheelEvent( QWheelEvent *e )
1370 int i_vlckey = qtWheelEventToVLCKey( e );
1371 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1375 void MainInterface::closeEvent( QCloseEvent *e )
1382 void MainInterface::toggleFullScreen( void )
1384 if( isFullScreen() )
1387 emit askUpdate(); // Needed if video was launched after the F11
1388 emit fullscreenInterfaceToggled( false );
1393 emit fullscreenInterfaceToggled( true );
1398 //moc doesn't know about #ifdef, so we have to build this method for every platform
1399 void MainInterface::changeThumbbarButtons( int i_status)
1402 // Define an array of two buttons. These buttons provide images through an
1403 // image list and also provide tooltips.
1404 DWORD dwMask = THB_BITMAP | THB_FLAGS;
1406 THUMBBUTTON thbButtons[3];
1408 thbButtons[0].dwMask = dwMask;
1409 thbButtons[0].iId = 0;
1410 thbButtons[0].iBitmap = 0;
1413 thbButtons[1].dwMask = dwMask;
1414 thbButtons[1].iId = 1;
1417 thbButtons[2].dwMask = dwMask;
1418 thbButtons[2].iId = 2;
1419 thbButtons[2].iBitmap = 3;
1426 thbButtons[0].dwFlags = THBF_HIDDEN;
1427 thbButtons[1].dwFlags = THBF_HIDDEN;
1428 thbButtons[2].dwFlags = THBF_HIDDEN;
1433 thbButtons[0].dwFlags = THBF_ENABLED;
1434 thbButtons[1].dwFlags = THBF_ENABLED;
1435 thbButtons[2].dwFlags = THBF_ENABLED;
1436 thbButtons[1].iBitmap = 1;
1441 //thbButtons[0].dwFlags = THBF_ENABLED;
1442 //thbButtons[1].dwFlags = THBF_ENABLED;
1443 //thbButtons[2].dwFlags = THBF_ENABLED;
1444 thbButtons[1].iBitmap = 2;
1449 HRESULT hr = p_taskbl->vt->ThumbBarUpdateButtons(p_taskbl, GetForegroundWindow(), 3, thbButtons);
1451 msg_Err( p_intf, "ThumbBarUpdateButtons failed with error %08x", hr );
1457 /*****************************************************************************
1458 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1459 * We don't show the menu directly here because we don't want the
1460 * caller to block for a too long time.
1461 *****************************************************************************/
1462 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1463 vlc_value_t old_val, vlc_value_t new_val, void *param )
1465 intf_thread_t *p_intf = (intf_thread_t *)param;
1467 if( p_intf->pf_show_dialog )
1469 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1470 new_val.b_bool, NULL );
1476 /*****************************************************************************
1477 * IntfShowCB: callback triggered by the intf-show libvlc variable.
1478 *****************************************************************************/
1479 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1480 vlc_value_t old_val, vlc_value_t new_val, void *param )
1482 intf_thread_t *p_intf = (intf_thread_t *)param;
1483 p_intf->p_sys->p_mi->toggleFSC();