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>
60 #include <QStackedWidget>
63 #include <vlc_windows_interfaces.h>
69 #include <vlc_keys.h> /* Wheel event */
70 #include <vlc_vout_window.h>
73 /* Callback prototypes */
74 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
75 vlc_value_t old_val, vlc_value_t new_val, void *param );
76 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
77 vlc_value_t old_val, vlc_value_t new_val, void *param );
79 MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
81 /* Variables initialisation */
82 // need_components_update = false;
85 playlistWidget = NULL;
89 videoIsActive = false;
90 playlistVisible = false;
92 fullscreenControls = NULL;
101 /* Ask for privacy */
105 * Configuration and settings
106 * Pre-building of interface
109 setFocusPolicy( Qt::StrongFocus );
110 setAcceptDrops( true );
111 setWindowRole( "vlc-main" );
112 setWindowIcon( QApplication::windowIcon() );
113 setWindowOpacity( config_GetFloat( p_intf, "qt-opacity" ) );
115 /* Set The Video In emebedded Mode or not */
116 videoEmbeddedFlag = config_GetInt( p_intf, "embedded-video" );
118 /* Does the interface resize to video size or the opposite */
119 b_keep_size = !config_GetInt( p_intf, "qt-video-autoresize" );
121 /* Are we in the enhanced always-video mode or not ? */
122 i_visualmode = config_GetInt( p_intf, "qt-display-mode" );
124 /* Do we want anoying popups or not */
125 notificationEnabled = (bool)config_GetInt( p_intf, "qt-notification" );
127 /* Set the other interface settings */
128 settings = getSettings();
129 settings->beginGroup( "MainWindow" );
132 * Retrieve saved sizes for main window
133 * mainBasedSize = based window size for normal mode
134 * (no video, no background)
135 * mainVideoSize = window size with video (all modes)
137 mainBasedSize = settings->value( "mainBasedSize", QSize( 350, 120 ) ).toSize();
138 mainVideoSize = settings->value( "mainVideoSize", QSize( 400, 300 ) ).toSize();
145 /**************************
146 * UI and Widgets design
147 **************************/
148 setVLCWindowsTitle();
149 createMainWidget( settings );
154 QVLCMenu::createMenuBar( this, p_intf );
155 CONNECT( THEMIM->getIM(), voutListChanged( vout_thread_t **, int ),
156 this, destroyPopupMenu() );
159 /* Create a Dock to get the playlist */
160 dockPL = new QDockWidget( qtr( "Playlist" ), this );
161 dockPL->setSizePolicy( QSizePolicy::Preferred,
162 QSizePolicy::Expanding );
163 dockPL->setFeatures( QDockWidget::AllDockWidgetFeatures );
164 dockPL->setAllowedAreas( Qt::LeftDockWidgetArea
165 | Qt::RightDockWidgetArea
166 | Qt::BottomDockWidgetArea );
170 /*********************************
171 * Create the Systray Management *
172 *********************************/
175 /********************
177 ********************/
178 MainInputManager::getInstance( p_intf );
180 /************************************************************
181 * Connect the input manager to the GUI elements it manages *
182 ************************************************************/
184 * Connects on nameChanged()
185 * Those connects are different because options can impeach them to trigger.
187 /* Main Interface statusbar */
188 CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
189 this, setName( const QString& ) );
194 CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
195 this, updateSystrayTooltipName( const QString& ) );
198 /* and title of the Main Interface*/
199 if( config_GetInt( p_intf, "qt-name-in-title" ) )
201 CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
202 this, setVLCWindowsTitle( const QString& ) );
206 * CONNECTS on PLAY_STATUS
208 /* Status on the systray */
212 CONNECT( THEMIM->getIM(), statusChanged( int ),
213 this, updateSystrayTooltipStatus( int ) );
217 /* END CONNECTS ON IM */
222 var_AddCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
224 /* Register callback for the intf-popupmenu variable */
225 var_AddCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
228 /* VideoWidget connects for asynchronous calls */
229 connect( this, SIGNAL(askGetVideo(WId*,int*,int*,unsigned*,unsigned *)),
230 this, SLOT(getVideoSlot(WId*,int*,int*,unsigned*,unsigned*)),
231 Qt::BlockingQueuedConnection );
232 connect( this, SIGNAL(askReleaseVideo( void )),
233 this, SLOT(releaseVideoSlot( void )),
234 Qt::BlockingQueuedConnection );
238 CONNECT( this, askVideoToResize( unsigned int, unsigned int ),
239 videoWidget, SetSizing( unsigned int, unsigned int ) );
240 CONNECT( this, askVideoSetFullScreen( bool ),
241 videoWidget, SetFullScreen( bool ) );
242 CONNECT( videoWidget, keyPressed( QKeyEvent * ),
243 this, handleKeyPress( QKeyEvent * ) );
246 CONNECT( this, askUpdate(), this, doComponentsUpdate() );
247 CONNECT( THEDP, toolBarConfUpdated(), this, recreateToolbars() );
249 /* Size and placement of interface */
250 settings->beginGroup( "MainWindow" );
251 QVLCTools::restoreWidgetPosition( settings, this, QSize(380, 60) );
253 /* resize to previously saved main window size if appicable */
256 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
257 i_visualmode == QT_MINIMAL_MODE )
259 resize( mainVideoSize );
263 resize( mainBasedSize );
267 bool b_pl_visible = settings->value( "playlist-visible", 0 ).toInt();
268 settings->endGroup();
271 if( b_pl_visible ) togglePlaylist();
273 /* Enable the popup menu in the MI */
274 setContextMenuPolicy( Qt::CustomContextMenu );
275 CONNECT( this, customContextMenuRequested( const QPoint& ),
276 this, popupMenu( const QPoint& ) );
280 /* Final sizing and showing */
281 setVisible( !b_shouldHide );
282 //setMinimumSize( QSize( 0, 0 ) );
283 // setMinimumWidth( __MAX( controls->sizeHint().width(),
284 // menuBar()->sizeHint().width() ) );
287 /* And switch to minimal view if needed
288 Must be called after the show() */
289 if( i_visualmode == QT_MINIMAL_MODE )
290 toggleMinimalView( true );
292 /* Update the geometry : It is useful if you switch between
295 resize( sizeHint() );
299 createTaskBarButtons();
303 MainInterface::~MainInterface()
305 msg_Dbg( p_intf, "Destroying the main interface" );
307 /* Unsure we hide the videoWidget before destroying it */
313 /* Save playlist state */
317 QVLCTools::saveWidgetPosition( p_intf, "Playlist", playlistWidget );
319 delete playlistWidget;
324 ImageList_Destroy( himl );
326 p_taskbl->vt->Release(p_taskbl);
330 /* Be sure to kill the actionsManager... FIXME */
331 ActionsManager::killInstance();
333 /* Delete the FSC controller */
334 delete fullscreenControls;
337 settings->beginGroup( "MainWindow" );
338 settings->setValue( "pl-dock-status", (int)i_pl_dock );
339 settings->setValue( "playlist-visible", (int)playlistVisible );
340 settings->setValue( "adv-controls",
341 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
343 settings->setValue( "mainBasedSize", mainBasedSize );
344 settings->setValue( "mainVideoSize", mainVideoSize );
347 settings->setValue( "backgroundSize", bgWidget->size() );
350 QVLCTools::saveWidgetPosition(settings, this);
351 settings->endGroup();
354 /* Unregister callbacks */
355 var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
356 var_DelCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
358 p_intf->p_sys->p_mi = NULL;
361 /*****************************
363 *****************************/
364 void MainInterface::recreateToolbars()
366 msg_Err( p_intf, "Recreating the toolbars" );
367 settings->beginGroup( "MainWindow" );
370 controls = new ControlsWidget( p_intf, false, this ); /* FIXME */
371 CONNECT( controls, advancedControlsToggled( bool ),
372 this, doComponentsUpdate() );
373 CONNECT( controls, sizeChanged(),
374 this, doComponentsUpdate() );
375 inputC = new InputControlsWidget( p_intf, this );
377 mainLayout->insertWidget( 2, inputC );
378 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
380 settings->endGroup();
383 void MainInterface::createMainWidget( QSettings *settings )
385 /* Create the main Widget and the mainLayout */
386 QWidget *main = new QWidget;
387 setCentralWidget( main );
388 mainLayout = new QVBoxLayout( main );
390 /* Margins, spacing */
391 main->setContentsMargins( 0, 0, 0, 0 );
392 // main->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
393 mainLayout->setSpacing( 0 );
394 mainLayout->setMargin( 0 );
397 /* Disabled for now, they SUCK */
399 visualSelector = new VisualSelector( p_intf );
400 mainLayout->insertWidget( 0, visualSelector );
401 visualSelector->hide();
404 stackCentralW = new QStackedWidget( main );
406 bgWidget = new BackgroundWidget( p_intf );
408 settings->value( "backgroundSize", QSize( 300, 200 ) ).toSize() );
409 bgWidget->updateGeometry();
410 stackCentralW->insertWidget( BACKG_TAB, bgWidget );
412 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
413 i_visualmode != QT_MINIMAL_MODE )
415 stackCentralW->hide();
418 /* And video Outputs */
419 if( videoEmbeddedFlag )
421 videoWidget = new VideoWidget( p_intf );
422 stackCentralW->insertWidget( VIDEO_TAB, videoWidget );
424 mainLayout->insertWidget( 1, stackCentralW, 100 );
426 /* Create the CONTROLS Widget */
427 controls = new ControlsWidget( p_intf,
428 settings->value( "adv-controls", false ).toBool(), this );
429 CONNECT( controls, advancedControlsToggled( bool ),
430 this, doComponentsUpdate() );
431 CONNECT( controls, sizeChanged(),
432 this, doComponentsUpdate() );
433 inputC = new InputControlsWidget( p_intf, this );
435 //mainLayout->setRowStretch( 1, 10 );
436 mainLayout->insertWidget( 2, inputC );
437 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
440 /* Finish the sizing */
441 main->updateGeometry();
443 getSettings()->endGroup();
447 /* Create the FULLSCREEN CONTROLS Widget */
448 if( config_GetInt( p_intf, "qt-fs-controller" ) )
450 fullscreenControls = new FullscreenControllerWidget( p_intf, this );
451 CONNECT( fullscreenControls, keyPressed( QKeyEvent * ),
452 this, handleKeyPress( QKeyEvent * ) );
456 inline void MainInterface::createStatusBar()
461 /* Widgets Creation*/
462 QStatusBar *statusBarr = statusBar();
464 TimeLabel *timeLabel = new TimeLabel( p_intf );
465 nameLabel = new QLabel( this );
466 nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
467 | Qt::TextSelectableByKeyboard );
468 SpeedLabel *speedLabel = new SpeedLabel( p_intf, "1.00x", this );
470 /* Styling those labels */
471 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
472 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
473 nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
475 /* and adding those */
476 statusBarr->addWidget( nameLabel, 8 );
477 statusBarr->addPermanentWidget( speedLabel, 0 );
478 statusBarr->addPermanentWidget( timeLabel, 0 );
480 /* timeLabel behaviour:
481 - double clicking opens the goto time dialog
482 - right-clicking and clicking just toggle between remaining and
484 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
486 CONNECT( THEMIM->getIM(), encryptionChanged( bool ),
487 this, showCryptedLabel( bool ) );
491 void MainInterface::createTaskBarButtons()
493 /*Here is the code for the taskbar thumb buttons
494 FIXME:We need pretty buttons in 16x16 px that are handled correctly by masks in Qt
495 FIXME:the play button's picture doesn't changed to pause when clicked
497 OSVERSIONINFO winVer;
498 winVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
499 if( GetVersionEx(&winVer) && winVer.dwMajorVersion > 5 )
501 if(himl = ImageList_Create( 15, //cx
504 4,//initial nb of images
505 0//nb of images that can be added
508 QPixmap img = QPixmap(":/toolbar/previous_b");
509 QPixmap img2 = QPixmap(":/toolbar/pause_b");
510 QPixmap img3 = QPixmap(":/toolbar/play_b");
511 QPixmap img4 = QPixmap(":/toolbar/next_b");
512 QBitmap mask = img.createMaskFromColor(Qt::transparent);
513 QBitmap mask2 = img2.createMaskFromColor(Qt::transparent);
514 QBitmap mask3 = img3.createMaskFromColor(Qt::transparent);
515 QBitmap mask4 = img4.createMaskFromColor(Qt::transparent);
517 if(-1 == ImageList_Add(himl, img.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask.toWinHBITMAP()))
518 msg_Err( p_intf, "ImageList_Add failed" );
519 if(-1 == ImageList_Add(himl, img2.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask2.toWinHBITMAP()))
520 msg_Err( p_intf, "ImageList_Add failed" );
521 if(-1 == ImageList_Add(himl, img3.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask3.toWinHBITMAP()))
522 msg_Err( p_intf, "ImageList_Add failed" );
523 if(-1 == ImageList_Add(himl, img4.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask4.toWinHBITMAP()))
524 msg_Err( p_intf, "ImageList_Add failed" );
529 if( S_OK == CoCreateInstance( &clsid_ITaskbarList,
530 NULL, CLSCTX_INPROC_SERVER,
532 (void **)&p_taskbl) )
534 p_taskbl->vt->HrInit(p_taskbl);
536 int msg_value = RegisterWindowMessage("TaskbarButtonCreated");
537 //msg_Info( p_intf, "msg value: %04x", msg_value );
539 // Define an array of two buttons. These buttons provide images through an
540 // image list and also provide tooltips.
541 DWORD dwMask = THB_BITMAP | THB_FLAGS;
543 THUMBBUTTON thbButtons[2];
544 thbButtons[0].dwMask = dwMask;
545 thbButtons[0].iId = 0;
546 thbButtons[0].iBitmap = 0;
547 thbButtons[0].dwFlags = THBF_HIDDEN;
549 thbButtons[1].dwMask = dwMask;
550 thbButtons[1].iId = 1;
551 thbButtons[1].iBitmap = 2;
552 thbButtons[1].dwFlags = THBF_HIDDEN;
554 thbButtons[2].dwMask = dwMask;
555 thbButtons[2].iId = 2;
556 thbButtons[2].iBitmap = 3;
557 thbButtons[2].dwFlags = THBF_HIDDEN;
559 HRESULT hr = p_taskbl->vt->ThumbBarSetImageList(p_taskbl, GetForegroundWindow(), himl );
561 msg_Err( p_intf, "ThumbBarSetImageList failed with error %08x", hr );
562 if(S_OK != p_taskbl->vt->ThumbBarAddButtons(p_taskbl, GetForegroundWindow(), 3, thbButtons))
563 msg_Err( p_intf, "ThumbBarAddButtons failed with error %08x", GetLastError() );
565 CONNECT( THEMIM->getIM(), statusChanged( int ), this, changeThumbbarButtons( int ) );
577 inline void MainInterface::initSystray()
580 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
581 bool b_systrayWanted = config_GetInt( p_intf, "qt-system-tray" );
583 if( config_GetInt( p_intf, "qt-start-minimized") > 0 )
585 if( b_systrayAvailable )
587 b_systrayWanted = true;
591 msg_Err( p_intf, "cannot start minimized without system tray bar" );
594 if( b_systrayAvailable && b_systrayWanted )
599 inline void MainInterface::askForPrivacy()
603 * Ask for the network policy on FIRST STARTUP
605 if( config_GetInt( p_intf, "qt-privacy-ask") )
607 QList<ConfigControl *> controls;
608 if( privacyDialog( &controls ) == QDialog::Accepted )
610 QList<ConfigControl *>::Iterator i;
611 for( i = controls.begin() ; i != controls.end() ; i++ )
613 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
614 c->doApply( p_intf );
617 config_PutInt( p_intf, "qt-privacy-ask" , 0 );
618 /* We have to save here because the user may not launch Prefs */
619 config_SaveConfigFile( p_intf, NULL );
625 int MainInterface::privacyDialog( QList<ConfigControl *> *controls )
627 QDialog *privacy = new QDialog( this );
629 privacy->setWindowTitle( qtr( "Privacy and Network Policies" ) );
630 privacy->setWindowRole( "vlc-privacy" );
632 QGridLayout *gLayout = new QGridLayout( privacy );
634 QGroupBox *blabla = new QGroupBox( qtr( "Privacy and Network Warning" ) );
635 QGridLayout *blablaLayout = new QGridLayout( blabla );
636 QLabel *text = new QLabel( qtr(
637 "<p>The <i>VideoLAN Team</i> doesn't like when an application goes "
638 "online without authorization.</p>\n "
639 "<p><i>VLC media player</i> can retreive limited information from "
640 "the Internet in order to get CD covers or to check "
641 "for available updates.</p>\n"
642 "<p><i>VLC media player</i> <b>DOES NOT</b> send or collect <b>ANY</b> "
643 "information, even anonymously, about your usage.</p>\n"
644 "<p>Therefore please select from the following options, the default being "
645 "almost no access to the web.</p>\n") );
646 text->setWordWrap( true );
647 text->setTextFormat( Qt::RichText );
649 blablaLayout->addWidget( text, 0, 0 ) ;
651 QGroupBox *options = new QGroupBox;
652 QGridLayout *optionsLayout = new QGridLayout( options );
654 gLayout->addWidget( blabla, 0, 0, 1, 3 );
655 gLayout->addWidget( options, 1, 0, 1, 3 );
656 module_config_t *p_config;
657 ConfigControl *control;
660 #define CONFIG_GENERIC( option, type ) \
661 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
664 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
665 p_config, options, false, optionsLayout, line ); \
666 controls->append( control ); \
669 #define CONFIG_GENERIC_NOBOOL( option, type ) \
670 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
673 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
674 p_config, options, optionsLayout, line ); \
675 controls->append( control ); \
678 CONFIG_GENERIC( "album-art", IntegerList ); line++;
680 CONFIG_GENERIC_NOBOOL( "qt-updates-notif", Bool ); line++;
683 QPushButton *ok = new QPushButton( qtr( "OK" ) );
685 gLayout->addWidget( ok, 2, 2 );
687 CONNECT( ok, clicked(), privacy, accept() );
688 return privacy->exec();
692 /**********************************************************************
693 * Handling of sizing of the components
694 **********************************************************************/
696 /* This function is probably wrong, but we don't have many many choices...
697 Since we can't know from the playlist Widget if we are inside a dock or not,
698 because the playlist Widget can be called by THEDP, as a separate windows for
700 Maybe the other solution is to redefine the sizeHint() of the playlist and
701 ask _parent->isFloating()...
702 If you think this would be better, please FIXME it...
705 QSize MainInterface::sizeHint() const
710 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
711 i_visualmode == QT_MINIMAL_MODE )
713 return mainVideoSize;
717 if( VISIBLE( bgWidget) ||
718 ( videoIsActive && videoWidget->isVisible() )
720 return mainVideoSize;
722 return mainBasedSize;
727 int nwidth = __MAX( controls->sizeHint().width(),
728 menuBar()->sizeHint().width() );
730 int nheight = controls->isVisible() ?
731 controls->size().height()
732 + inputC->size().height()
733 + menuBar()->size().height()
734 + statusBar()->size().height()
737 if( stackCentralW->isVisible() )
738 nheight += stackCentralW->height();
739 nwidth = __MAX( nwidth, stackCentralW->width() );
741 /* if( VISIBLE( bgWidget ) )
743 msg_Warn( p_intf, "Hello here" );
745 nheight += i_bg_height;
747 nheight += bgWidget->size().height();
748 nwidth = __MAX( nwidth, bgWidget->size().width() );
750 else if( videoIsActive && videoWidget->isVisible() )
752 msg_Warn( p_intf, "Hello there" );
753 nheight += videoWidget->sizeHint().height();
754 nwidth = __MAX( nwidth, videoWidget->sizeHint().width() );
757 if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget() )
759 nheight += dockPL->size().height();
760 nwidth = __MAX( nwidth, dockPL->size().width() );
761 msg_Warn( p_intf, "3 %i %i", nheight, nwidth );
764 return QSize( nwidth, nheight );
768 /* Video widget cannot do this synchronously as it runs in another thread */
769 /* Well, could it, actually ? Probably dangerous ... */
771 /* This function is called:
772 - toggling of minimal View
773 - through askUpdate() by Vout thread request video and resize video (zoom)
774 - Advanced buttons toggled
776 void MainInterface::doComponentsUpdate()
778 if( isFullScreen() || isMaximized() ) return;
780 msg_Err( p_intf, "Updating the geometry" );
781 /* Here we resize to sizeHint() and not adjustsize because we want
782 the videoWidget to be exactly the correctSize */
783 //mainLayout->invalidate();
784 // setMinimumSize( 0, 0 );
789 resize( sizeHint() );
793 void MainInterface::debug()
796 if( stackCentralW->isVisible() )
797 msg_Dbg( p_intf, "CentralStack visible" );
799 msg_Dbg( p_intf, "CentralStack inVisible" );
800 //msg_Dbg( p_intf, "Stack Size: %i - %i", stackCentralW->sizeHint().height(), stackCentralW->sizeHint().width() );
801 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
802 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
803 //msg_Dbg( p_intf, "maximumsize: %i - %i", maximumSize().height(), maximumSize().width() );
805 msg_Dbg( p_intf, "Stack minimumsize: %i - %i", stackCentralW->minimumSize().height(), stackCentralW->minimumSize().width() );
806 msg_Dbg( p_intf, "Controls minimumsize: %i - %i", controls->minimumSize().height(), controls->minimumSize().width() );
807 msg_Dbg( p_intf, "Central minimumsize: %i - %i", centralWidget()->minimumSize().height(), centralWidget()->minimumSize().width() );
808 msg_Dbg( p_intf, "Menu minimumsize: %i - %i", menuBar()->minimumSize().height(), menuBar()->minimumSize().width() );
809 msg_Dbg( p_intf, "Input minimuSize: %i - %i", inputC->minimumSize().height(), inputC->minimumSize().width() );
810 msg_Dbg( p_intf, "Status minimumsize: %i - %i", statusBar()->minimumSize().height(), statusBar()->minimumSize().width() );
811 msg_Dbg( p_intf, "minimumsize: %i - %i", minimumSize().height(), minimumSize().width() );
814 /*if( videoWidget && videoWidget->isVisible() )
816 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
817 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
822 void MainInterface::destroyPopupMenu()
824 QVLCMenu::PopupMenu(p_intf, false );
828 void MainInterface::toggleFSC()
830 if( !fullscreenControls ) return;
832 IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
833 QApplication::postEvent( fullscreenControls, eShow );
836 void MainInterface::popupMenu( const QPoint &p )
838 /* Ow, that's ugly: don't show the popup menu if cursor over
839 * the main menu bar or the status bar */
840 if( !childAt( p ) || ( ( childAt( p ) != menuBar() )
841 && ( childAt( p )->parentWidget() != statusBar() ) ) )
842 QVLCMenu::PopupMenu( p_intf, true );
845 /****************************************************************************
847 ****************************************************************************/
849 /* This event is used to deal with the fullscreen and always on top
850 issue conflict (bug in wx) */
851 class SetVideoOnTopQtEvent : public QEvent
854 SetVideoOnTopQtEvent( bool _onTop ) :
855 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
858 bool OnTop() const { return onTop; }
866 * You must note change the state of this object or other Qt4 UI objects,
867 * from the video output thread - only from the Qt4 UI main loop thread.
868 * All window provider queries must be handled through signals or events.
869 * That's why we have all those emit statements...
871 WId MainInterface::getVideo( int *pi_x, int *pi_y,
872 unsigned int *pi_width, unsigned int *pi_height )
877 /* This is a blocking call signal. Results are returned through pointers.
878 * Beware of deadlocks! */
880 emit askGetVideo( &id, pi_x, pi_y, pi_width, pi_height );
884 void MainInterface::getVideoSlot( WId *p_id, int *pi_x, int *pi_y,
885 unsigned *pi_width, unsigned *pi_height )
887 /* Request the videoWidget */
888 WId ret = videoWidget->request( pi_x, pi_y,
889 pi_width, pi_height, b_keep_size );
891 if( ret ) /* The videoWidget is available */
893 /* Did we have a bg ? Hide it! */
894 if( stackCentralW->isVisible() &&
895 stackCentralW->currentIndex() == BACKG_TAB )
901 bgWasVisible = false;
903 /* ask videoWidget to show */
904 videoWidget->SetSizing( *pi_width, *pi_height );
906 /* Consider the video active now */
907 videoIsActive = true;
910 stackCentralW->resize( *pi_width, *pi_height );
916 inline void MainInterface::showTab( int i_tab )
918 stackCentralW->setCurrentIndex( i_tab );
919 if( stackCentralW->isHidden() ) stackCentralW->show();
922 /* Asynchronous call from the WindowClose function */
923 void MainInterface::releaseVideo( void )
925 emit askReleaseVideo( );
928 /* Function that is CONNECTED to the previous emit */
929 void MainInterface::releaseVideoSlot( void )
931 videoWidget->release( );
935 /* Reset the bg state */
936 bgWasVisible = false;
940 stackCentralW->hide();
941 stackCentralW->setMinimumSize(QSize(0, 0));
944 videoIsActive = false;
946 /* Try to resize, except when you are in Fullscreen mode */
947 doComponentsUpdate();
950 /* Asynchronous call from WindowControl function */
951 int MainInterface::controlVideo( int i_query, va_list args )
955 /* Debug to check if VOUT_WINDOW_SET_SIZE is called? */
956 msg_Dbg( p_intf, "Control Video: %i", i_query );
957 case VOUT_WINDOW_SET_SIZE:
959 unsigned int i_width = va_arg( args, unsigned int );
960 unsigned int i_height = va_arg( args, unsigned int );
961 emit askVideoToResize( i_width, i_height );
965 case VOUT_WINDOW_SET_ON_TOP:
967 int i_arg = va_arg( args, int );
968 QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
971 case VOUT_WINDOW_SET_FULLSCREEN:
973 bool b_fs = va_arg( args, int );
974 emit askVideoSetFullScreen( b_fs );
978 msg_Warn( p_intf, "unsupported control query" );
983 /*****************************************************************************
984 * Playlist, Visualisation and Menus handling
985 *****************************************************************************/
987 * Toggle the playlist widget or dialog
989 void MainInterface::togglePlaylist()
992 If no playlist exist, then create one and attach it to the DockPL*/
993 if( !playlistWidget )
995 playlistWidget = new PlaylistWidget( p_intf );
997 i_pl_dock = PL_BOTTOM;
998 /*i_pl_dock = (pl_dock_e)getSettings()
999 ->value( "pl-dock-status", PL_UNDOCKED ).toInt();*/
1001 if( i_pl_dock == PL_UNDOCKED )
1003 playlistWidget->setWindowFlags( Qt::Window );
1005 /* This will restore the geometry but will not work for position,
1006 because of parenting */
1007 QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
1008 playlistWidget, QSize( 600, 300 ) );
1012 stackCentralW->insertWidget(PLAYL_TAB, playlistWidget );
1013 stackCentralW->setCurrentWidget( playlistWidget );
1014 stackCentralW->show();
1016 playlistVisible = true;
1018 playlistWidget->show();
1022 /* toggle the visibility of the playlist */
1023 if( stackCentralW->currentIndex() != PLAYL_TAB )
1025 stackCentralW->insertWidget(PLAYL_TAB, playlistWidget );
1026 stackCentralW->setCurrentWidget( playlistWidget );
1027 stackCentralW->show();
1030 stackCentralW->setCurrentIndex( VIDEO_TAB );
1031 playlistVisible = !playlistVisible;
1032 //doComponentsUpdate(); //resize( sizeHint() );
1036 /* Function called from the menu to undock the playlist */
1037 void MainInterface::undockPlaylist()
1039 // dockPL->setFloating( true );
1043 void MainInterface::dockPlaylist( pl_dock_e i_pos )
1047 void MainInterface::toggleMinimalView( bool b_switch )
1049 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
1050 i_visualmode != QT_MINIMAL_MODE )
1051 { /* NORMAL MODE then */
1052 stackCentralW->show();
1053 if( !videoWidget || stackCentralW->currentIndex() != VIDEO_TAB )
1059 /* If video is visible, then toggle the status of bgWidget */
1060 bgWasVisible = !bgWasVisible;
1064 i_bg_height = stackCentralW->height();
1066 menuBar()->setVisible( !b_switch );
1067 controls->setVisible( !b_switch );
1068 statusBar()->setVisible( !b_switch );
1069 inputC->setVisible( !b_switch );
1071 doComponentsUpdate();
1073 emit minimalViewToggled( b_switch );
1076 /* toggling advanced controls buttons */
1077 void MainInterface::toggleAdvanced()
1079 controls->toggleAdvanced();
1080 // if( fullscreenControls ) fullscreenControls->toggleAdvanced();
1083 /* Get the visibility status of the controls (hidden or not, advanced or not) */
1084 int MainInterface::getControlsVisibilityStatus()
1086 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
1087 + CONTROLS_ADVANCED * controls->b_advancedVisible );
1091 void MainInterface::visual()
1093 if( !VISIBLE( visualSelector) )
1095 visualSelector->show();
1096 if( !THEMIM->getIM()->hasVideo() )
1098 /* Show the background widget */
1100 visualSelectorEnabled = true;
1104 /* Stop any currently running visualization */
1105 visualSelector->hide();
1106 visualSelectorEnabled = false;
1108 doComponentsUpdate();
1112 /************************************************************************
1114 ************************************************************************/
1115 void MainInterface::setName( const QString& name )
1117 input_name = name; /* store it for the QSystray use */
1118 /* Display it in the status bar, but also as a Tooltip in case it doesn't
1120 nameLabel->setText( " " + name + " " );
1121 nameLabel->setToolTip( " " + name +" " );
1125 * Give the decorations of the Main Window a correct Name.
1126 * If nothing is given, set it to VLC...
1128 void MainInterface::setVLCWindowsTitle( const QString& aTitle )
1130 if( aTitle.isEmpty() )
1132 setWindowTitle( qtr( "VLC media player" ) );
1136 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
1140 void MainInterface::showCryptedLabel( bool b_show )
1142 if( cryptedLabel == NULL )
1144 cryptedLabel = new QLabel;
1145 // The lock icon is not the right one for DRM protection/scrambled.
1146 //cryptedLabel->setPixmap( QPixmap( ":/lock" ) );
1147 cryptedLabel->setText( "DRM" );
1148 statusBar()->addWidget( cryptedLabel );
1151 cryptedLabel->setVisible( b_show );
1154 /*****************************************************************************
1155 * Systray Icon and Systray Menu
1156 *****************************************************************************/
1159 * Create a SystemTray icon and a menu that would go with it.
1160 * Connects to a click handler on the icon.
1162 void MainInterface::createSystray()
1165 if( QDate::currentDate().dayOfYear() >= 354 )
1166 iconVLC = QIcon( ":/logo/vlc128-christmas.png" );
1168 iconVLC = QIcon( ":/logo/vlc128.png" );
1169 sysTray = new QSystemTrayIcon( iconVLC, this );
1170 sysTray->setToolTip( qtr( "VLC media player" ));
1172 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
1173 systrayMenu->setIcon( iconVLC );
1175 QVLCMenu::updateSystrayMenu( this, p_intf, true );
1178 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
1179 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
1183 * Updates the Systray Icon's menu and toggle the main interface
1185 void MainInterface::toggleUpdateSystrayMenu()
1187 /* If hidden, show it */
1193 else if( isMinimized() )
1201 /* Visible (possibly under other windows) */
1203 /* check if any visible window is above vlc in the z-order,
1204 * but ignore the ones always on top
1205 * and the ones which can't be activated */
1208 wi.cbSize = sizeof( WINDOWINFO );
1209 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
1210 hwnd && ( !IsWindowVisible( hwnd ) ||
1211 ( GetWindowInfo( hwnd, &wi ) &&
1212 (wi.dwExStyle&WS_EX_NOACTIVATE) ) );
1213 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
1214 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
1215 (wi.dwExStyle&WS_EX_TOPMOST) )
1227 QVLCMenu::updateSystrayMenu( this, p_intf );
1230 void MainInterface::handleSystrayClick(
1231 QSystemTrayIcon::ActivationReason reason )
1235 case QSystemTrayIcon::Trigger:
1236 case QSystemTrayIcon::DoubleClick:
1237 toggleUpdateSystrayMenu();
1239 case QSystemTrayIcon::MiddleClick:
1240 sysTray->showMessage( qtr( "VLC media player" ),
1241 qtr( "Control menu for the player" ),
1242 QSystemTrayIcon::Information, 3000 );
1250 * Updates the name of the systray Icon tooltip.
1251 * Doesn't check if the systray exists, check before you call it.
1253 void MainInterface::updateSystrayTooltipName( const QString& name )
1255 if( name.isEmpty() )
1257 sysTray->setToolTip( qtr( "VLC media player" ) );
1261 sysTray->setToolTip( name );
1262 if( notificationEnabled && ( isHidden() || isMinimized() ) )
1264 sysTray->showMessage( qtr( "VLC media player" ), name,
1265 QSystemTrayIcon::NoIcon, 3000 );
1269 QVLCMenu::updateSystrayMenu( this, p_intf );
1273 * Updates the status of the systray Icon tooltip.
1274 * Doesn't check if the systray exists, check before you call it.
1276 void MainInterface::updateSystrayTooltipStatus( int i_status )
1283 sysTray->setToolTip( qtr( "VLC media player" ) );
1288 sysTray->setToolTip( input_name );
1293 sysTray->setToolTip( input_name + " - "
1298 QVLCMenu::updateSystrayMenu( this, p_intf );
1302 /************************************************************************
1304 ************************************************************************/
1305 void MainInterface::dropEvent(QDropEvent *event)
1307 dropEventPlay( event, true );
1310 void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
1312 event->setDropAction( Qt::CopyAction );
1313 if( !event->possibleActions() & Qt::CopyAction )
1316 const QMimeData *mimeData = event->mimeData();
1318 /* D&D of a subtitles file, add it on the fly */
1319 if( mimeData->urls().size() == 1 && THEMIM->getIM()->hasInput() )
1321 if( !input_AddSubtitle( THEMIM->getInput(),
1322 qtu( toNativeSeparators( mimeData->urls()[0].toLocalFile() ) ),
1330 bool first = b_play;
1331 foreach( const QUrl &url, mimeData->urls() )
1333 QString s = toNativeSeparators( url.toLocalFile() );
1335 if( s.length() > 0 ) {
1336 char* psz_uri = make_URI( qtu(s) );
1337 playlist_Add( THEPL, psz_uri, NULL,
1338 PLAYLIST_APPEND | (first ? PLAYLIST_GO: PLAYLIST_PREPARSE),
1339 PLAYLIST_END, true, pl_Unlocked );
1342 RecentsMRL::getInstance( p_intf )->addRecent( s );
1347 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1349 event->acceptProposedAction();
1351 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1353 event->acceptProposedAction();
1355 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1360 /************************************************************************
1362 ************************************************************************/
1363 void MainInterface::customEvent( QEvent *event )
1366 if( event->type() == PLDockEvent_Type )
1368 PlaylistDialog::killInstance();
1369 playlistEmbeddedFlag = true;
1371 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1376 if ( event->type() == (int)SetVideoOnTopEvent_Type )
1378 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1379 if( p_event->OnTop() )
1380 setWindowFlags( windowFlags() | Qt::WindowStaysOnTopHint );
1382 setWindowFlags( windowFlags() & ~Qt::WindowStaysOnTopHint );
1383 show(); /* necessary to apply window flags */
1387 void MainInterface::keyPressEvent( QKeyEvent *e )
1389 handleKeyPress( e );
1392 void MainInterface::handleKeyPress( QKeyEvent *e )
1394 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() == Qt::Key_H )
1395 && !menuBar()->isVisible() )
1397 toggleMinimalView( false );
1401 int i_vlck = qtEventToVLCKey( e );
1404 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1411 void MainInterface::resizeEvent( QResizeEvent * event )
1416 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
1417 i_visualmode == QT_MINIMAL_MODE )
1419 mainVideoSize = size();
1423 if( VISIBLE( bgWidget) ||
1424 ( videoIsActive && videoWidget->isVisible() )
1426 mainVideoSize = size();
1428 mainBasedSize = size();
1432 QVLCMW::resizeEvent( event );
1433 msg_Warn( p_intf, "%i", size().height() );
1436 void MainInterface::wheelEvent( QWheelEvent *e )
1438 int i_vlckey = qtWheelEventToVLCKey( e );
1439 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1443 void MainInterface::closeEvent( QCloseEvent *e )
1450 void MainInterface::toggleFullScreen( void )
1452 if( isFullScreen() )
1455 emit askUpdate(); // Needed if video was launched after the F11
1456 emit fullscreenInterfaceToggled( false );
1461 emit fullscreenInterfaceToggled( true );
1466 //moc doesn't know about #ifdef, so we have to build this method for every platform
1467 void MainInterface::changeThumbbarButtons( int i_status)
1470 // Define an array of two buttons. These buttons provide images through an
1471 // image list and also provide tooltips.
1472 DWORD dwMask = THB_BITMAP | THB_FLAGS;
1474 THUMBBUTTON thbButtons[3];
1476 thbButtons[0].dwMask = dwMask;
1477 thbButtons[0].iId = 0;
1478 thbButtons[0].iBitmap = 0;
1481 thbButtons[1].dwMask = dwMask;
1482 thbButtons[1].iId = 1;
1485 thbButtons[2].dwMask = dwMask;
1486 thbButtons[2].iId = 2;
1487 thbButtons[2].iBitmap = 3;
1494 thbButtons[0].dwFlags = THBF_HIDDEN;
1495 thbButtons[1].dwFlags = THBF_HIDDEN;
1496 thbButtons[2].dwFlags = THBF_HIDDEN;
1501 thbButtons[0].dwFlags = THBF_ENABLED;
1502 thbButtons[1].dwFlags = THBF_ENABLED;
1503 thbButtons[2].dwFlags = THBF_ENABLED;
1504 thbButtons[1].iBitmap = 1;
1509 //thbButtons[0].dwFlags = THBF_ENABLED;
1510 //thbButtons[1].dwFlags = THBF_ENABLED;
1511 //thbButtons[2].dwFlags = THBF_ENABLED;
1512 thbButtons[1].iBitmap = 2;
1517 HRESULT hr = p_taskbl->vt->ThumbBarUpdateButtons(p_taskbl, GetForegroundWindow(), 3, thbButtons);
1519 msg_Err( p_intf, "ThumbBarUpdateButtons failed with error %08x", hr );
1525 /*****************************************************************************
1526 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1527 * We don't show the menu directly here because we don't want the
1528 * caller to block for a too long time.
1529 *****************************************************************************/
1530 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1531 vlc_value_t old_val, vlc_value_t new_val, void *param )
1533 intf_thread_t *p_intf = (intf_thread_t *)param;
1535 if( p_intf->pf_show_dialog )
1537 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1538 new_val.b_bool, NULL );
1544 /*****************************************************************************
1545 * IntfShowCB: callback triggered by the intf-show libvlc variable.
1546 *****************************************************************************/
1547 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1548 vlc_value_t old_val, vlc_value_t new_val, void *param )
1550 intf_thread_t *p_intf = (intf_thread_t *)param;
1551 p_intf->p_sys->p_mi->toggleFSC();