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 ) );
374 MainInterface::~MainInterface()
376 msg_Dbg( p_intf, "Destroying the main interface" );
378 /* Unsure we hide the videoWidget before destroying it */
379 if( videoIsActive ) videoWidget->hide();
381 /* Save playlist state */
385 QVLCTools::saveWidgetPosition( p_intf, "Playlist", playlistWidget );
387 delete playlistWidget;
392 ImageList_Destroy( himl );
394 p_taskbl->vt->Release(p_taskbl);
398 /* Be sure to kill the actionsManager... FIXME */
399 ActionsManager::killInstance();
401 /* Delete the FSC controller */
402 delete fullscreenControls;
405 settings->beginGroup( "MainWindow" );
406 settings->setValue( "pl-dock-status", (int)i_pl_dock );
407 settings->setValue( "playlist-visible", (int)playlistVisible );
408 settings->setValue( "adv-controls",
409 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
411 settings->setValue( "mainBasedSize", mainBasedSize );
412 settings->setValue( "mainVideoSize", mainVideoSize );
415 settings->setValue( "backgroundSize", bgWidget->size() );
418 QVLCTools::saveWidgetPosition(settings, this);
419 settings->endGroup();
422 /* Unregister callbacks */
423 var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
424 var_DelCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
426 p_intf->p_sys->p_mi = NULL;
429 /*****************************
431 *****************************/
432 void MainInterface::recreateToolbars()
434 msg_Dbg( p_intf, "Recreating the toolbars" );
435 settings->beginGroup( "MainWindow" );
438 controls = new ControlsWidget( p_intf, false, this ); /* FIXME */
439 CONNECT( controls, advancedControlsToggled( bool ),
440 this, doComponentsUpdate() );
441 CONNECT( controls, sizeChanged(),
442 this, doComponentsUpdate() );
443 inputC = new InputControlsWidget( p_intf, this );
445 mainLayout->addWidget( inputC, 2, 0, 1, -1, Qt::AlignBottom );
446 mainLayout->addWidget( controls, settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
447 0, 1, -1, Qt::AlignBottom );
448 settings->endGroup();
451 void MainInterface::createMainWidget( QSettings *settings )
453 /* Create the main Widget and the mainLayout */
454 QWidget *main = new QWidget;
455 setCentralWidget( main );
456 mainLayout = new QGridLayout( main );
458 /* Margins, spacing */
459 main->setContentsMargins( 0, 0, 0, 0 );
460 main->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
461 mainLayout->setSpacing( 0 );
462 mainLayout->setMargin( 0 );
465 /* Disabled for now, they SUCK */
467 visualSelector = new VisualSelector( p_intf );
468 mainLayout->insertWidget( 0, visualSelector );
469 visualSelector->hide();
473 bgWidget = new BackgroundWidget( p_intf );
475 settings->value( "backgroundSize", QSize( 300, 200 ) ).toSize() );
476 bgWidget->updateGeometry();
478 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
479 i_visualmode != QT_MINIMAL_MODE )
484 /* And video Outputs */
485 if( videoEmbeddedFlag )
486 videoWidget = new VideoWidget( p_intf );
488 /* Create the CONTROLS Widget */
489 controls = new ControlsWidget( p_intf,
490 settings->value( "adv-controls", false ).toBool(), this );
491 CONNECT( controls, advancedControlsToggled( bool ),
492 this, doComponentsUpdate() );
493 CONNECT( controls, sizeChanged(),
494 this, doComponentsUpdate() );
495 inputC = new InputControlsWidget( p_intf, this );
498 /* Add the controls Widget to the main Widget */
500 mainLayout->addWidget( videoWidget, 0, 0, 1, -1 );
501 mainLayout->setRowStretch( 0, 10 );
503 mainLayout->addWidget( bgWidget, 1, 0, 1, -1 );
504 //mainLayout->setRowStretch( 1, 10 );
505 mainLayout->addWidget( inputC, 2, 0, 1, -1, Qt::AlignBottom );
506 mainLayout->addWidget( controls, settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
507 0, 1, -1, Qt::AlignBottom );
509 /* Finish the sizing */
510 main->updateGeometry();
512 getSettings()->endGroup();
516 /* Create the FULLSCREEN CONTROLS Widget */
517 if( config_GetInt( p_intf, "qt-fs-controller" ) )
519 fullscreenControls = new FullscreenControllerWidget( p_intf, this );
520 CONNECT( fullscreenControls, keyPressed( QKeyEvent * ),
521 this, handleKeyPress( QKeyEvent * ) );
525 inline void MainInterface::createStatusBar()
530 /* Widgets Creation*/
531 QStatusBar *statusBarr = statusBar();
533 TimeLabel *timeLabel = new TimeLabel( p_intf );
534 nameLabel = new QLabel( this );
535 nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
536 | Qt::TextSelectableByKeyboard );
537 SpeedLabel *speedLabel = new SpeedLabel( p_intf, "1.00x", this );
539 /* Styling those labels */
540 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
541 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
542 nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
544 /* and adding those */
545 statusBarr->addWidget( nameLabel, 8 );
546 statusBarr->addPermanentWidget( speedLabel, 0 );
547 statusBarr->addPermanentWidget( timeLabel, 0 );
549 /* timeLabel behaviour:
550 - double clicking opens the goto time dialog
551 - right-clicking and clicking just toggle between remaining and
553 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
555 CONNECT( THEMIM->getIM(), encryptionChanged( bool ),
556 this, showCryptedLabel( bool ) );
559 inline void MainInterface::initSystray()
561 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
562 bool b_systrayWanted = config_GetInt( p_intf, "qt-system-tray" );
564 if( config_GetInt( p_intf, "qt-start-minimized") > 0 )
566 if( b_systrayAvailable )
568 b_systrayWanted = true;
572 msg_Err( p_intf, "cannot start minimized without system tray bar" );
575 if( b_systrayAvailable && b_systrayWanted )
579 inline void MainInterface::askForPrivacy()
582 * Ask for the network policy on FIRST STARTUP
584 if( config_GetInt( p_intf, "qt-privacy-ask") )
586 QList<ConfigControl *> controls;
587 if( privacyDialog( &controls ) == QDialog::Accepted )
589 QList<ConfigControl *>::Iterator i;
590 for( i = controls.begin() ; i != controls.end() ; i++ )
592 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
593 c->doApply( p_intf );
596 config_PutInt( p_intf, "qt-privacy-ask" , 0 );
597 /* We have to save here because the user may not launch Prefs */
598 config_SaveConfigFile( p_intf, NULL );
603 int MainInterface::privacyDialog( QList<ConfigControl *> *controls )
605 QDialog *privacy = new QDialog( this );
607 privacy->setWindowTitle( qtr( "Privacy and Network Policies" ) );
609 QGridLayout *gLayout = new QGridLayout( privacy );
611 QGroupBox *blabla = new QGroupBox( qtr( "Privacy and Network Warning" ) );
612 QGridLayout *blablaLayout = new QGridLayout( blabla );
613 QLabel *text = new QLabel( qtr(
614 "<p>The <i>VideoLAN Team</i> doesn't like when an application goes "
615 "online without authorization.</p>\n "
616 "<p><i>VLC media player</i> can retreive limited information from "
617 "the Internet in order to get CD covers or to check "
618 "for available updates.</p>\n"
619 "<p><i>VLC media player</i> <b>DOES NOT</b> send or collect <b>ANY</b> "
620 "information, even anonymously, about your usage.</p>\n"
621 "<p>Therefore please select from the following options, the default being "
622 "almost no access to the web.</p>\n") );
623 text->setWordWrap( true );
624 text->setTextFormat( Qt::RichText );
626 blablaLayout->addWidget( text, 0, 0 ) ;
628 QGroupBox *options = new QGroupBox;
629 QGridLayout *optionsLayout = new QGridLayout( options );
631 gLayout->addWidget( blabla, 0, 0, 1, 3 );
632 gLayout->addWidget( options, 1, 0, 1, 3 );
633 module_config_t *p_config;
634 ConfigControl *control;
637 #define CONFIG_GENERIC( option, type ) \
638 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
641 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
642 p_config, options, false, optionsLayout, line ); \
643 controls->append( control ); \
646 #define CONFIG_GENERIC_NOBOOL( option, type ) \
647 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
650 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
651 p_config, options, optionsLayout, line ); \
652 controls->append( control ); \
655 CONFIG_GENERIC( "album-art", IntegerList ); line++;
657 CONFIG_GENERIC_NOBOOL( "qt-updates-notif", Bool ); line++;
660 QPushButton *ok = new QPushButton( qtr( "OK" ) );
662 gLayout->addWidget( ok, 2, 2 );
664 CONNECT( ok, clicked(), privacy, accept() );
665 return privacy->exec();
669 /**********************************************************************
670 * Handling of sizing of the components
671 **********************************************************************/
673 /* This function is probably wrong, but we don't have many many choices...
674 Since we can't know from the playlist Widget if we are inside a dock or not,
675 because the playlist Widget can be called by THEDP, as a separate windows for
677 Maybe the other solution is to redefine the sizeHint() of the playlist and
678 ask _parent->isFloating()...
679 If you think this would be better, please FIXME it...
682 QSize MainInterface::sizeHint() const
686 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
687 i_visualmode == QT_MINIMAL_MODE )
689 return mainVideoSize;
693 if( VISIBLE( bgWidget) ||
694 ( videoIsActive && videoWidget->isVisible() )
696 return mainVideoSize;
698 return mainBasedSize;
702 int nwidth = controls->sizeHint().width();
703 int nheight = controls->isVisible() ?
704 controls->size().height()
705 + inputC->size().height()
706 + menuBar()->size().height()
707 + statusBar()->size().height()
710 if( VISIBLE( bgWidget ) )
713 nheight += i_bg_height;
715 nheight += bgWidget->size().height();
716 nwidth = __MAX( nwidth, bgWidget->size().width() );
718 else if( videoIsActive && videoWidget->isVisible() )
720 nheight += videoWidget->sizeHint().height();
721 nwidth = __MAX( nwidth, videoWidget->sizeHint().width() );
724 if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget() )
726 nheight += dockPL->size().height();
727 nwidth = __MAX( nwidth, dockPL->size().width() );
728 msg_Warn( p_intf, "3 %i %i", nheight, nwidth );
731 return QSize( nwidth, nheight );
734 /* Video widget cannot do this synchronously as it runs in another thread */
735 /* Well, could it, actually ? Probably dangerous ... */
737 /* This function is called:
738 - toggling of minimal View
739 - through askUpdate() by Vout thread request video and resize video (zoom)
740 - Advanced buttons toggled
742 void MainInterface::doComponentsUpdate()
744 if( isFullScreen() || isMaximized() ) return;
746 msg_Dbg( p_intf, "Updating the geometry" );
747 /* Here we resize to sizeHint() and not adjustsize because we want
748 the videoWidget to be exactly the correctSize */
749 resize( sizeHint() );
756 void MainInterface::debug()
759 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
760 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
761 if( videoWidget && videoWidget->isVisible() )
763 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
764 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
769 void MainInterface::destroyPopupMenu()
771 QVLCMenu::PopupMenu(p_intf, false );
775 void MainInterface::toggleFSC()
777 if( !fullscreenControls ) return;
779 IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
780 QApplication::postEvent( fullscreenControls, eShow );
783 void MainInterface::popupMenu( const QPoint &p )
785 /* Ow, that's ugly: don't show the popup menu if cursor over
786 * the main menu bar or the status bar */
787 if( !childAt( p ) || ( ( childAt( p ) != menuBar() )
788 && ( childAt( p )->parentWidget() != statusBar() ) ) )
789 QVLCMenu::PopupMenu( p_intf, true );
792 /****************************************************************************
794 ****************************************************************************/
796 /* This event is used to deal with the fullscreen and always on top
797 issue conflict (bug in wx) */
798 class SetVideoOnTopQtEvent : public QEvent
801 SetVideoOnTopQtEvent( bool _onTop ) :
802 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
805 bool OnTop() const { return onTop; }
813 * You must note change the state of this object or other Qt4 UI objects,
814 * from the video output thread - only from the Qt4 UI main loop thread.
815 * All window provider queries must be handled through signals or events.
816 * That's why we have all those emit statements...
818 WId MainInterface::getVideo( int *pi_x, int *pi_y,
819 unsigned int *pi_width, unsigned int *pi_height )
824 /* This is a blocking call signal. Results are returned through pointers.
825 * Beware of deadlocks! */
827 emit askGetVideo( &id, pi_x, pi_y, pi_width, pi_height );
831 void MainInterface::getVideoSlot( WId *p_id, int *pi_x, int *pi_y,
832 unsigned *pi_width, unsigned *pi_height )
834 /* Request the videoWidget */
835 WId ret = videoWidget->request( pi_x, pi_y,
836 pi_width, pi_height, b_keep_size );
838 if( ret ) /* The videoWidget is available */
840 /* Did we have a bg ? Hide it! */
841 if( VISIBLE( bgWidget) )
847 bgWasVisible = false;
849 /* ask videoWidget to show */
850 videoWidget->SetSizing( *pi_width, *pi_height );
852 /* Consider the video active now */
853 videoIsActive = true;
859 /* Asynchronous call from the WindowClose function */
860 void MainInterface::releaseVideo( void )
862 emit askReleaseVideo( );
865 /* Function that is CONNECTED to the previous emit */
866 void MainInterface::releaseVideoSlot( void )
868 videoWidget->release( );
872 /* Reset the bg state */
873 bgWasVisible = false;
877 videoIsActive = false;
879 /* Try to resize, except when you are in Fullscreen mode */
880 doComponentsUpdate();
883 /* Asynchronous call from WindowControl function */
884 int MainInterface::controlVideo( int i_query, va_list args )
888 case VOUT_WINDOW_SET_SIZE:
890 unsigned int i_width = va_arg( args, unsigned int );
891 unsigned int i_height = va_arg( args, unsigned int );
892 emit askVideoToResize( i_width, i_height );
896 case VOUT_WINDOW_SET_ON_TOP:
898 int i_arg = va_arg( args, int );
899 QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
902 case VOUT_WINDOW_SET_FULLSCREEN:
904 bool b_fs = va_arg( args, int );
905 emit askVideoSetFullScreen( b_fs );
909 msg_Warn( p_intf, "unsupported control query" );
914 /*****************************************************************************
915 * Playlist, Visualisation and Menus handling
916 *****************************************************************************/
918 * Toggle the playlist widget or dialog
920 void MainInterface::togglePlaylist()
923 If no playlist exist, then create one and attach it to the DockPL*/
924 if( !playlistWidget )
926 playlistWidget = new PlaylistWidget( p_intf );
928 i_pl_dock = PL_UNDOCKED;
929 /* i_pl_dock = (pl_dock_e)getSettings()
930 ->value( "pl-dock-status", PL_UNDOCKED ).toInt(); */
932 if( i_pl_dock == PL_UNDOCKED )
934 playlistWidget->setWindowFlags( Qt::Window );
936 /* This will restore the geometry but will not work for position,
937 because of parenting */
938 QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
939 playlistWidget, QSize( 600, 300 ) );
943 // mainLayout->insertWidget( 4, playlistWidget );
945 playlistVisible = true;
947 playlistWidget->show();
951 /* toggle the visibility of the playlist */
952 TOGGLEV( playlistWidget );
953 playlistVisible = !playlistVisible;
954 //doComponentsUpdate(); //resize( sizeHint() );
958 /* Function called from the menu to undock the playlist */
959 void MainInterface::undockPlaylist()
961 // dockPL->setFloating( true );
965 void MainInterface::dockPlaylist( pl_dock_e i_pos )
969 void MainInterface::toggleMinimalView( bool b_switch )
971 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
972 i_visualmode != QT_MINIMAL_MODE )
973 { /* NORMAL MODE then */
974 if( !videoWidget || videoWidget->isHidden() )
980 /* If video is visible, then toggle the status of bgWidget */
981 bgWasVisible = !bgWasVisible;
985 i_bg_height = bgWidget->height();
987 menuBar()->setVisible( !b_switch );
988 controls->setVisible( !b_switch );
989 statusBar()->setVisible( !b_switch );
990 inputC->setVisible( !b_switch );
992 doComponentsUpdate();
994 emit minimalViewToggled( b_switch );
997 /* toggling advanced controls buttons */
998 void MainInterface::toggleAdvanced()
1000 controls->toggleAdvanced();
1001 // if( fullscreenControls ) fullscreenControls->toggleAdvanced();
1004 /* Get the visibility status of the controls (hidden or not, advanced or not) */
1005 int MainInterface::getControlsVisibilityStatus()
1007 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
1008 + CONTROLS_ADVANCED * controls->b_advancedVisible );
1012 void MainInterface::visual()
1014 if( !VISIBLE( visualSelector) )
1016 visualSelector->show();
1017 if( !THEMIM->getIM()->hasVideo() )
1019 /* Show the background widget */
1021 visualSelectorEnabled = true;
1025 /* Stop any currently running visualization */
1026 visualSelector->hide();
1027 visualSelectorEnabled = false;
1029 doComponentsUpdate();
1033 /************************************************************************
1035 ************************************************************************/
1036 void MainInterface::setName( const QString& name )
1038 input_name = name; /* store it for the QSystray use */
1039 /* Display it in the status bar, but also as a Tooltip in case it doesn't
1041 nameLabel->setText( " " + name + " " );
1042 nameLabel->setToolTip( " " + name +" " );
1046 * Give the decorations of the Main Window a correct Name.
1047 * If nothing is given, set it to VLC...
1049 void MainInterface::setVLCWindowsTitle( const QString& aTitle )
1051 if( aTitle.isEmpty() )
1053 setWindowTitle( qtr( "VLC media player" ) );
1057 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
1061 void MainInterface::showCryptedLabel( bool b_show )
1063 if( cryptedLabel == NULL )
1065 cryptedLabel = new QLabel;
1066 // The lock icon is not the right one for DRM protection/scrambled.
1067 //cryptedLabel->setPixmap( QPixmap( ":/lock" ) );
1068 cryptedLabel->setText( "DRM" );
1069 statusBar()->addWidget( cryptedLabel );
1072 cryptedLabel->setVisible( b_show );
1075 /*****************************************************************************
1076 * Systray Icon and Systray Menu
1077 *****************************************************************************/
1080 * Create a SystemTray icon and a menu that would go with it.
1081 * Connects to a click handler on the icon.
1083 void MainInterface::createSystray()
1086 if( QDate::currentDate().dayOfYear() >= 354 )
1087 iconVLC = QIcon( QPixmap( ":/logo/vlc128-christmas.png" ) );
1089 iconVLC = QIcon( QPixmap( ":/logo/vlc128.png" ) );
1090 sysTray = new QSystemTrayIcon( iconVLC, this );
1091 sysTray->setToolTip( qtr( "VLC media player" ));
1093 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
1094 systrayMenu->setIcon( iconVLC );
1096 QVLCMenu::updateSystrayMenu( this, p_intf, true );
1099 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
1100 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
1104 * Updates the Systray Icon's menu and toggle the main interface
1106 void MainInterface::toggleUpdateSystrayMenu()
1108 /* If hidden, show it */
1114 else if( isMinimized() )
1122 /* Visible (possibly under other windows) */
1124 /* check if any visible window is above vlc in the z-order,
1125 * but ignore the ones always on top
1126 * and the ones which can't be activated */
1129 wi.cbSize = sizeof( WINDOWINFO );
1130 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
1131 hwnd && ( !IsWindowVisible( hwnd ) ||
1132 ( GetWindowInfo( hwnd, &wi ) &&
1133 (wi.dwExStyle&WS_EX_NOACTIVATE) ) );
1134 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
1135 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
1136 (wi.dwExStyle&WS_EX_TOPMOST) )
1148 QVLCMenu::updateSystrayMenu( this, p_intf );
1151 void MainInterface::handleSystrayClick(
1152 QSystemTrayIcon::ActivationReason reason )
1156 case QSystemTrayIcon::Trigger:
1157 case QSystemTrayIcon::DoubleClick:
1158 toggleUpdateSystrayMenu();
1160 case QSystemTrayIcon::MiddleClick:
1161 sysTray->showMessage( qtr( "VLC media player" ),
1162 qtr( "Control menu for the player" ),
1163 QSystemTrayIcon::Information, 3000 );
1171 * Updates the name of the systray Icon tooltip.
1172 * Doesn't check if the systray exists, check before you call it.
1174 void MainInterface::updateSystrayTooltipName( const QString& name )
1176 if( name.isEmpty() )
1178 sysTray->setToolTip( qtr( "VLC media player" ) );
1182 sysTray->setToolTip( name );
1183 if( notificationEnabled && ( isHidden() || isMinimized() ) )
1185 sysTray->showMessage( qtr( "VLC media player" ), name,
1186 QSystemTrayIcon::NoIcon, 3000 );
1190 QVLCMenu::updateSystrayMenu( this, p_intf );
1194 * Updates the status of the systray Icon tooltip.
1195 * Doesn't check if the systray exists, check before you call it.
1197 void MainInterface::updateSystrayTooltipStatus( int i_status )
1204 sysTray->setToolTip( qtr( "VLC media player" ) );
1209 sysTray->setToolTip( input_name );
1214 sysTray->setToolTip( input_name + " - "
1219 QVLCMenu::updateSystrayMenu( this, p_intf );
1222 /************************************************************************
1224 ************************************************************************/
1225 void MainInterface::dropEvent(QDropEvent *event)
1227 dropEventPlay( event, true );
1230 void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
1232 event->setDropAction( Qt::CopyAction );
1233 if( !event->possibleActions() & Qt::CopyAction )
1236 const QMimeData *mimeData = event->mimeData();
1238 /* D&D of a subtitles file, add it on the fly */
1239 if( mimeData->urls().size() == 1 )
1241 if( THEMIM->getIM()->hasInput() )
1243 if( !input_AddSubtitle( THEMIM->getInput(),
1244 qtu( toNativeSeparators(
1245 mimeData->urls()[0].toLocalFile() ) ),
1253 bool first = b_play;
1254 foreach( const QUrl &url, mimeData->urls() )
1256 QString s = toNativeSeparators( url.toLocalFile() );
1258 if( s.length() > 0 ) {
1259 playlist_Add( THEPL, qtu(s), NULL,
1260 PLAYLIST_APPEND | (first ? PLAYLIST_GO: PLAYLIST_PREPARSE),
1261 PLAYLIST_END, true, pl_Unlocked );
1263 RecentsMRL::getInstance( p_intf )->addRecent( s );
1268 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1270 event->acceptProposedAction();
1272 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1274 event->acceptProposedAction();
1276 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1281 /************************************************************************
1283 ************************************************************************/
1284 void MainInterface::customEvent( QEvent *event )
1287 if( event->type() == PLDockEvent_Type )
1289 PlaylistDialog::killInstance();
1290 playlistEmbeddedFlag = true;
1292 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1297 if ( event->type() == (int)SetVideoOnTopEvent_Type )
1299 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1300 if( p_event->OnTop() )
1301 setWindowFlags( windowFlags() | Qt::WindowStaysOnTopHint );
1303 setWindowFlags( windowFlags() & ~Qt::WindowStaysOnTopHint );
1304 show(); /* necessary to apply window flags */
1308 void MainInterface::keyPressEvent( QKeyEvent *e )
1310 handleKeyPress( e );
1313 void MainInterface::handleKeyPress( QKeyEvent *e )
1315 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() == Qt::Key_H )
1316 && !menuBar()->isVisible() )
1318 toggleMinimalView( false );
1322 int i_vlck = qtEventToVLCKey( e );
1325 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1332 void MainInterface::resizeEvent( QResizeEvent * event )
1336 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
1337 i_visualmode == QT_MINIMAL_MODE )
1339 mainVideoSize = size();
1343 if( VISIBLE( bgWidget) ||
1344 ( videoIsActive && videoWidget->isVisible() )
1346 mainVideoSize = size();
1348 mainBasedSize = size();
1353 void MainInterface::wheelEvent( QWheelEvent *e )
1355 int i_vlckey = qtWheelEventToVLCKey( e );
1356 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1360 void MainInterface::closeEvent( QCloseEvent *e )
1367 void MainInterface::toggleFullScreen( void )
1369 if( isFullScreen() )
1372 emit askUpdate(); // Needed if video was launched after the F11
1373 emit fullscreenInterfaceToggled( false );
1378 emit fullscreenInterfaceToggled( true );
1383 //moc doesn't know about #ifdef, so we have to build this method for every platform
1384 void MainInterface::changeThumbbarButtons( int i_status)
1387 // Define an array of two buttons. These buttons provide images through an
1388 // image list and also provide tooltips.
1389 DWORD dwMask = THB_BITMAP | THB_FLAGS;
1391 THUMBBUTTON thbButtons[3];
1393 thbButtons[0].dwMask = dwMask;
1394 thbButtons[0].iId = 0;
1395 thbButtons[0].iBitmap = 0;
1398 thbButtons[1].dwMask = dwMask;
1399 thbButtons[1].iId = 1;
1402 thbButtons[2].dwMask = dwMask;
1403 thbButtons[2].iId = 2;
1404 thbButtons[2].iBitmap = 3;
1411 thbButtons[0].dwFlags = THBF_HIDDEN;
1412 thbButtons[1].dwFlags = THBF_HIDDEN;
1413 thbButtons[2].dwFlags = THBF_HIDDEN;
1418 thbButtons[0].dwFlags = THBF_ENABLED;
1419 thbButtons[1].dwFlags = THBF_ENABLED;
1420 thbButtons[2].dwFlags = THBF_ENABLED;
1421 thbButtons[1].iBitmap = 1;
1426 //thbButtons[0].dwFlags = THBF_ENABLED;
1427 //thbButtons[1].dwFlags = THBF_ENABLED;
1428 //thbButtons[2].dwFlags = THBF_ENABLED;
1429 thbButtons[1].iBitmap = 2;
1434 HRESULT hr = p_taskbl->vt->ThumbBarUpdateButtons(p_taskbl, GetForegroundWindow(), 3, thbButtons);
1436 msg_Err( p_intf, "ThumbBarUpdateButtons failed with error %08x", hr );
1442 /*****************************************************************************
1443 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1444 * We don't show the menu directly here because we don't want the
1445 * caller to block for a too long time.
1446 *****************************************************************************/
1447 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1448 vlc_value_t old_val, vlc_value_t new_val, void *param )
1450 intf_thread_t *p_intf = (intf_thread_t *)param;
1452 if( p_intf->pf_show_dialog )
1454 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1455 new_val.b_bool, NULL );
1461 /*****************************************************************************
1462 * IntfShowCB: callback triggered by the intf-show libvlc variable.
1463 *****************************************************************************/
1464 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1465 vlc_value_t old_val, vlc_value_t new_val, void *param )
1467 intf_thread_t *p_intf = (intf_thread_t *)param;
1468 p_intf->p_sys->p_mi->toggleFSC();