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 fullscreenControls = NULL;
94 b_hideAfterCreation = false;
95 playlistVisible = false; // FIXME remove
98 stackCentralOldState = HIDDEN_TAB;
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_hideAfterCreation );
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() );
298 createTaskBarButtons();
302 MainInterface::~MainInterface()
304 msg_Dbg( p_intf, "Destroying the main interface" );
306 /* Unsure we hide the videoWidget before destroying it */
307 if( stackCentralOldState == VIDEO_TAB )
310 /* Save playlist state */
314 QVLCTools::saveWidgetPosition( p_intf, "Playlist", playlistWidget );
316 delete playlistWidget;
321 ImageList_Destroy( himl );
323 p_taskbl->vt->Release(p_taskbl);
327 /* Be sure to kill the actionsManager... FIXME */
328 ActionsManager::killInstance();
330 /* Delete the FSC controller */
331 delete fullscreenControls;
334 settings->beginGroup( "MainWindow" );
335 settings->setValue( "pl-dock-status", (int)i_pl_dock );
336 settings->setValue( "playlist-visible", (int)playlistVisible );
337 settings->setValue( "adv-controls",
338 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
340 settings->setValue( "mainBasedSize", mainBasedSize );
341 settings->setValue( "mainVideoSize", mainVideoSize );
344 settings->setValue( "backgroundSize", bgWidget->size() );
347 QVLCTools::saveWidgetPosition(settings, this);
348 settings->endGroup();
350 /* Unregister callbacks */
351 var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
352 var_DelCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
354 p_intf->p_sys->p_mi = NULL;
357 /*****************************
359 *****************************/
360 void MainInterface::recreateToolbars()
362 msg_Dbg( p_intf, "Recreating the toolbars" );
363 settings->beginGroup( "MainWindow" );
366 controls = new ControlsWidget( p_intf, false, this ); /* FIXME */
367 CONNECT( controls, advancedControlsToggled( bool ),
368 this, doComponentsUpdate() );
369 CONNECT( controls, sizeChanged(),
370 this, doComponentsUpdate() );
371 inputC = new InputControlsWidget( p_intf, this );
373 mainLayout->insertWidget( 2, inputC );
374 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
376 settings->endGroup();
379 void MainInterface::createMainWidget( QSettings *settings )
381 /* Create the main Widget and the mainLayout */
382 QWidget *main = new QWidget;
383 setCentralWidget( main );
384 mainLayout = new QVBoxLayout( main );
386 /* Margins, spacing */
387 main->setContentsMargins( 0, 0, 0, 0 );
388 mainLayout->setSpacing( 0 );
389 mainLayout->setMargin( 0 );
392 stackCentralW = new QStackedWidget( main );
395 bgWidget = new BackgroundWidget( p_intf );
397 settings->value( "backgroundSize", QSize( 300, 200 ) ).toSize() );
398 bgWidget->updateGeometry();
399 stackCentralW->insertWidget( BACKG_TAB, bgWidget );
401 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
402 i_visualmode != QT_MINIMAL_MODE )
404 stackCentralW->hide();
407 /* And video Outputs */
408 if( videoEmbeddedFlag )
410 videoWidget = new VideoWidget( p_intf );
411 stackCentralW->insertWidget( VIDEO_TAB, videoWidget );
413 mainLayout->insertWidget( 1, stackCentralW, 100 );
414 /* Create the CONTROLS Widget */
415 controls = new ControlsWidget( p_intf,
416 settings->value( "adv-controls", false ).toBool(), this );
417 CONNECT( controls, advancedControlsToggled( bool ),
418 this, doComponentsUpdate() );
419 CONNECT( controls, sizeChanged(),
420 this, doComponentsUpdate() );
421 inputC = new InputControlsWidget( p_intf, this );
423 //mainLayout->setRowStretch( 1, 10 );
424 mainLayout->insertWidget( 2, inputC );
425 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
429 /* Disabled for now, they SUCK */
431 visualSelector = new VisualSelector( p_intf );
432 mainLayout->insertWidget( 0, visualSelector );
433 visualSelector->hide();
436 /* Finish the sizing */
437 main->updateGeometry();
439 getSettings()->endGroup();
443 /* Create the FULLSCREEN CONTROLS Widget */
444 if( config_GetInt( p_intf, "qt-fs-controller" ) )
446 fullscreenControls = new FullscreenControllerWidget( p_intf, this );
447 CONNECT( fullscreenControls, keyPressed( QKeyEvent * ),
448 this, handleKeyPress( QKeyEvent * ) );
452 inline void MainInterface::createStatusBar()
457 /* Widgets Creation*/
458 QStatusBar *statusBarr = statusBar();
460 TimeLabel *timeLabel = new TimeLabel( p_intf );
461 nameLabel = new QLabel( this );
462 nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
463 | Qt::TextSelectableByKeyboard );
464 SpeedLabel *speedLabel = new SpeedLabel( p_intf, "1.00x", this );
466 /* Styling those labels */
467 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
468 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
469 nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
471 /* and adding those */
472 statusBarr->addWidget( nameLabel, 8 );
473 statusBarr->addPermanentWidget( speedLabel, 0 );
474 statusBarr->addPermanentWidget( timeLabel, 0 );
476 /* timeLabel behaviour:
477 - double clicking opens the goto time dialog
478 - right-clicking and clicking just toggle between remaining and
480 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
482 CONNECT( THEMIM->getIM(), encryptionChanged( bool ),
483 this, showCryptedLabel( bool ) );
487 void MainInterface::createTaskBarButtons()
489 /*Here is the code for the taskbar thumb buttons
490 FIXME:We need pretty buttons in 16x16 px that are handled correctly by masks in Qt
491 FIXME:the play button's picture doesn't changed to pause when clicked
493 OSVERSIONINFO winVer;
494 winVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
495 if( GetVersionEx(&winVer) && winVer.dwMajorVersion > 5 )
497 if(himl = ImageList_Create( 15, //cx
500 4,//initial nb of images
501 0//nb of images that can be added
504 QPixmap img = QPixmap(":/toolbar/previous_b");
505 QPixmap img2 = QPixmap(":/toolbar/pause_b");
506 QPixmap img3 = QPixmap(":/toolbar/play_b");
507 QPixmap img4 = QPixmap(":/toolbar/next_b");
508 QBitmap mask = img.createMaskFromColor(Qt::transparent);
509 QBitmap mask2 = img2.createMaskFromColor(Qt::transparent);
510 QBitmap mask3 = img3.createMaskFromColor(Qt::transparent);
511 QBitmap mask4 = img4.createMaskFromColor(Qt::transparent);
513 if(-1 == ImageList_Add(himl, img.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask.toWinHBITMAP()))
514 msg_Err( p_intf, "ImageList_Add failed" );
515 if(-1 == ImageList_Add(himl, img2.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask2.toWinHBITMAP()))
516 msg_Err( p_intf, "ImageList_Add failed" );
517 if(-1 == ImageList_Add(himl, img3.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask3.toWinHBITMAP()))
518 msg_Err( p_intf, "ImageList_Add failed" );
519 if(-1 == ImageList_Add(himl, img4.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask4.toWinHBITMAP()))
520 msg_Err( p_intf, "ImageList_Add failed" );
525 if( S_OK == CoCreateInstance( &clsid_ITaskbarList,
526 NULL, CLSCTX_INPROC_SERVER,
528 (void **)&p_taskbl) )
530 p_taskbl->vt->HrInit(p_taskbl);
532 int msg_value = RegisterWindowMessage("TaskbarButtonCreated");
533 //msg_Info( p_intf, "msg value: %04x", msg_value );
535 // Define an array of two buttons. These buttons provide images through an
536 // image list and also provide tooltips.
537 DWORD dwMask = THB_BITMAP | THB_FLAGS;
539 THUMBBUTTON thbButtons[2];
540 thbButtons[0].dwMask = dwMask;
541 thbButtons[0].iId = 0;
542 thbButtons[0].iBitmap = 0;
543 thbButtons[0].dwFlags = THBF_HIDDEN;
545 thbButtons[1].dwMask = dwMask;
546 thbButtons[1].iId = 1;
547 thbButtons[1].iBitmap = 2;
548 thbButtons[1].dwFlags = THBF_HIDDEN;
550 thbButtons[2].dwMask = dwMask;
551 thbButtons[2].iId = 2;
552 thbButtons[2].iBitmap = 3;
553 thbButtons[2].dwFlags = THBF_HIDDEN;
555 HRESULT hr = p_taskbl->vt->ThumbBarSetImageList(p_taskbl, GetForegroundWindow(), himl );
557 msg_Err( p_intf, "ThumbBarSetImageList failed with error %08x", hr );
558 if(S_OK != p_taskbl->vt->ThumbBarAddButtons(p_taskbl, GetForegroundWindow(), 3, thbButtons))
559 msg_Err( p_intf, "ThumbBarAddButtons failed with error %08x", GetLastError() );
561 CONNECT( THEMIM->getIM(), statusChanged( int ), this, changeThumbbarButtons( int ) );
573 inline void MainInterface::initSystray()
576 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
577 bool b_systrayWanted = config_GetInt( p_intf, "qt-system-tray" );
579 if( config_GetInt( p_intf, "qt-start-minimized") > 0 )
581 if( b_systrayAvailable )
583 b_systrayWanted = true;
584 b_hideAfterCreation = true;
587 msg_Err( p_intf, "cannot start minimized without system tray bar" );
590 if( b_systrayAvailable && b_systrayWanted )
595 inline void MainInterface::askForPrivacy()
599 * Ask for the network policy on FIRST STARTUP
601 if( config_GetInt( p_intf, "qt-privacy-ask") )
603 QList<ConfigControl *> controls;
604 if( privacyDialog( &controls ) == QDialog::Accepted )
606 QList<ConfigControl *>::Iterator i;
607 for( i = controls.begin() ; i != controls.end() ; i++ )
609 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
610 c->doApply( p_intf );
613 config_PutInt( p_intf, "qt-privacy-ask" , 0 );
614 /* We have to save here because the user may not launch Prefs */
615 config_SaveConfigFile( p_intf, NULL );
621 int MainInterface::privacyDialog( QList<ConfigControl *> *controls )
623 QDialog *privacy = new QDialog( this );
625 privacy->setWindowTitle( qtr( "Privacy and Network Policies" ) );
626 privacy->setWindowRole( "vlc-privacy" );
628 QGridLayout *gLayout = new QGridLayout( privacy );
630 QGroupBox *blabla = new QGroupBox( qtr( "Privacy and Network Warning" ) );
631 QGridLayout *blablaLayout = new QGridLayout( blabla );
632 QLabel *text = new QLabel( qtr(
633 "<p>The <i>VideoLAN Team</i> doesn't like when an application goes "
634 "online without authorization.</p>\n "
635 "<p><i>VLC media player</i> can retreive limited information from "
636 "the Internet in order to get CD covers or to check "
637 "for available updates.</p>\n"
638 "<p><i>VLC media player</i> <b>DOES NOT</b> send or collect <b>ANY</b> "
639 "information, even anonymously, about your usage.</p>\n"
640 "<p>Therefore please select from the following options, the default being "
641 "almost no access to the web.</p>\n") );
642 text->setWordWrap( true );
643 text->setTextFormat( Qt::RichText );
645 blablaLayout->addWidget( text, 0, 0 ) ;
647 QGroupBox *options = new QGroupBox;
648 QGridLayout *optionsLayout = new QGridLayout( options );
650 gLayout->addWidget( blabla, 0, 0, 1, 3 );
651 gLayout->addWidget( options, 1, 0, 1, 3 );
652 module_config_t *p_config;
653 ConfigControl *control;
656 #define CONFIG_GENERIC( option, type ) \
657 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
660 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
661 p_config, options, false, optionsLayout, line ); \
662 controls->append( control ); \
665 #define CONFIG_GENERIC_NOBOOL( option, type ) \
666 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
669 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
670 p_config, options, optionsLayout, line ); \
671 controls->append( control ); \
674 CONFIG_GENERIC( "album-art", IntegerList ); line++;
676 CONFIG_GENERIC_NOBOOL( "qt-updates-notif", Bool ); line++;
679 QPushButton *ok = new QPushButton( qtr( "OK" ) );
681 gLayout->addWidget( ok, 2, 2 );
683 CONNECT( ok, clicked(), privacy, accept() );
684 return privacy->exec();
688 /**********************************************************************
689 * Handling of sizing of the components
690 **********************************************************************/
692 /* This function is probably wrong, but we don't have many many choices...
693 Since we can't know from the playlist Widget if we are inside a dock or not,
694 because the playlist Widget can be called by THEDP, as a separate windows for
696 Maybe the other solution is to redefine the sizeHint() of the playlist and
697 ask _parent->isFloating()...
698 If you think this would be better, please FIXME it...
701 QSize MainInterface::sizeHint() const
706 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
707 i_visualmode == QT_MINIMAL_MODE )
709 return mainVideoSize;
713 if( VISIBLE( bgWidget) ||
714 ( videoIsActive && videoWidget->isVisible() )
716 return mainVideoSize;
718 return mainBasedSize;
723 int nwidth = __MAX( controls->sizeHint().width(),
724 menuBar()->sizeHint().width() );
726 int nheight = controls->isVisible() ?
727 controls->size().height()
728 + inputC->size().height()
729 + menuBar()->size().height()
730 + statusBar()->size().height()
733 if( stackCentralW->isVisible() )
734 nheight += stackCentralW->height();
735 nwidth = __MAX( nwidth, stackCentralW->width() );
737 /* if( VISIBLE( bgWidget ) )
739 msg_Warn( p_intf, "Hello here" );
741 nheight += i_bg_height;
743 nheight += bgWidget->size().height();
744 nwidth = __MAX( nwidth, bgWidget->size().width() );
746 else if( videoIsActive && videoWidget->isVisible() )
748 msg_Warn( p_intf, "Hello there" );
749 nheight += videoWidget->sizeHint().height();
750 nwidth = __MAX( nwidth, videoWidget->sizeHint().width() );
753 if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget() )
755 nheight += dockPL->size().height();
756 nwidth = __MAX( nwidth, dockPL->size().width() );
757 msg_Warn( p_intf, "3 %i %i", nheight, nwidth );
760 return QSize( nwidth, nheight );
764 /* Video widget cannot do this synchronously as it runs in another thread */
765 /* Well, could it, actually ? Probably dangerous ... */
767 /* This function is called:
768 - toggling of minimal View
769 - through askUpdate() by Vout thread request video and resize video (zoom)
770 - Advanced buttons toggled
772 void MainInterface::doComponentsUpdate()
774 if( isFullScreen() || isMaximized() ) return;
776 msg_Warn( p_intf, "Updating the geometry" );
777 /* Here we resize to sizeHint() and not adjustsize because we want
778 the videoWidget to be exactly the correctSize */
783 /* This is WRONG, but I believe there is a Qt bug here */
784 setMinimumSize( 0, 0 );
785 resize( sizeHint() );
787 //adjustSize() ; /* This is not needed, but might help in the future */
790 void MainInterface::debug()
793 msg_Dbg( p_intf, "Stack Size: %i - %i", stackCentralW->size().height(), size().width() );
794 msg_Dbg( p_intf, "Stack Size: %i - %i", stackCentralW->widget( VIDEO_TAB )->size().height(), stackCentralW->widget( VIDEO_TAB )->size().width() );
796 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
797 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
798 //msg_Dbg( p_intf, "maximumsize: %i - %i", maximumSize().height(), maximumSize().width() );
800 msg_Dbg( p_intf, "Stack minimumsize: %i - %i", stackCentralW->minimumSize().height(), stackCentralW->minimumSize().width() );
801 msg_Dbg( p_intf, "Controls minimumsize: %i - %i", controls->minimumSize().height(), controls->minimumSize().width() );
802 msg_Dbg( p_intf, "Central minimumsize: %i - %i", centralWidget()->minimumSize().height(), centralWidget()->minimumSize().width() );
803 msg_Dbg( p_intf, "Menu minimumsize: %i - %i", menuBar()->minimumSize().height(), menuBar()->minimumSize().width() );
804 msg_Dbg( p_intf, "Input minimuSize: %i - %i", inputC->minimumSize().height(), inputC->minimumSize().width() );
805 msg_Dbg( p_intf, "Status minimumsize: %i - %i", statusBar()->minimumSize().height(), statusBar()->minimumSize().width() );
806 msg_Dbg( p_intf, "minimumsize: %i - %i", minimumSize().height(), minimumSize().width() );
808 /*if( videoWidget && videoWidget->isVisible() )
810 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
811 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
816 void MainInterface::destroyPopupMenu()
818 QVLCMenu::PopupMenu( p_intf, false );
821 void MainInterface::toggleFSC()
823 if( !fullscreenControls ) return;
825 IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
826 QApplication::postEvent( fullscreenControls, eShow );
829 void MainInterface::popupMenu( const QPoint &p )
831 /* Ow, that's ugly: don't show the popup menu if cursor over
832 * the main menu bar or the status bar */
833 if( !childAt( p ) || ( ( childAt( p ) != menuBar() )
834 && ( childAt( p )->parentWidget() != statusBar() ) ) )
835 QVLCMenu::PopupMenu( p_intf, true );
838 /****************************************************************************
840 ****************************************************************************/
842 /* This event is used to deal with the fullscreen and always on top
843 issue conflict (bug in wx) */
844 class SetVideoOnTopQtEvent : public QEvent
847 SetVideoOnTopQtEvent( bool _onTop ) :
848 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
851 bool OnTop() const { return onTop; }
859 * You must note change the state of this object or other Qt4 UI objects,
860 * from the video output thread - only from the Qt4 UI main loop thread.
861 * All window provider queries must be handled through signals or events.
862 * That's why we have all those emit statements...
864 WId MainInterface::getVideo( int *pi_x, int *pi_y,
865 unsigned int *pi_width, unsigned int *pi_height )
870 /* This is a blocking call signal. Results are returned through pointers.
871 * Beware of deadlocks! */
873 emit askGetVideo( &id, pi_x, pi_y, pi_width, pi_height );
877 void MainInterface::getVideoSlot( WId *p_id, int *pi_x, int *pi_y,
878 unsigned *pi_width, unsigned *pi_height )
880 /* Request the videoWidget */
881 WId ret = videoWidget->request( pi_x, pi_y,
882 pi_width, pi_height, b_keep_size );
884 if( ret ) /* The videoWidget is available */
886 /* ask videoWidget to show */
887 videoWidget->SetSizing( *pi_width, *pi_height );
889 /* Consider the video active now */
892 stackCentralW->resize( *pi_width, *pi_height );
898 inline void MainInterface::showTab( int i_tab )
900 stackCentralOldState = stackCentralW->currentIndex();
902 stackCentralW->setCurrentIndex( i_tab );
903 if( stackCentralW->isHidden() ) stackCentralW->show();
906 /* Asynchronous call from the WindowClose function */
907 void MainInterface::releaseVideo( void )
909 emit askReleaseVideo( );
912 /* Function that is CONNECTED to the previous emit */
913 void MainInterface::releaseVideoSlot( void )
915 videoWidget->release( );
917 /* Restore the previous State */
918 if( stackCentralOldState == BACKG_TAB )
924 stackCentralW->hide();
925 stackCentralOldState == -1;
928 /* Try to resize, except when you are in Fullscreen mode */
929 doComponentsUpdate();
932 /* Asynchronous call from WindowControl function */
933 int MainInterface::controlVideo( int i_query, va_list args )
935 /* Debug to check if VOUT_WINDOW_SET_SIZE is called, because this is broken now */
936 msg_Warn( p_intf, "Control Video: %i", i_query );
939 case VOUT_WINDOW_SET_SIZE:
941 unsigned int i_width = va_arg( args, unsigned int );
942 unsigned int i_height = va_arg( args, unsigned int );
943 emit askVideoToResize( i_width, i_height );
947 case VOUT_WINDOW_SET_ON_TOP:
949 int i_arg = va_arg( args, int );
950 QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
953 case VOUT_WINDOW_SET_FULLSCREEN:
955 bool b_fs = va_arg( args, int );
956 emit askVideoSetFullScreen( b_fs );
960 msg_Warn( p_intf, "unsupported control query" );
965 /*****************************************************************************
966 * Playlist, Visualisation and Menus handling
967 *****************************************************************************/
969 * Toggle the playlist widget or dialog
971 void MainInterface::togglePlaylist()
974 If no playlist exist, then create one and attach it to the DockPL*/
975 if( !playlistWidget )
977 playlistWidget = new PlaylistWidget( p_intf );
979 i_pl_dock = PL_BOTTOM;
980 /*i_pl_dock = (pl_dock_e)getSettings()
981 ->value( "pl-dock-status", PL_UNDOCKED ).toInt();*/
983 if( i_pl_dock == PL_UNDOCKED )
985 playlistWidget->setWindowFlags( Qt::Window );
987 /* This will restore the geometry but will not work for position,
988 because of parenting */
989 QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
990 playlistWidget, QSize( 600, 300 ) );
994 stackCentralW->insertWidget(PLAYL_TAB, playlistWidget );
995 stackCentralW->setCurrentWidget( playlistWidget );
996 stackCentralW->show();
998 playlistVisible = true;
1000 playlistWidget->show();
1004 /* toggle the visibility of the playlist */
1005 if( stackCentralW->currentIndex() != PLAYL_TAB )
1007 stackCentralW->insertWidget(PLAYL_TAB, playlistWidget );
1008 stackCentralW->setCurrentWidget( playlistWidget );
1009 stackCentralW->show();
1012 stackCentralW->setCurrentIndex( VIDEO_TAB );
1013 playlistVisible = !playlistVisible;
1014 //doComponentsUpdate(); //resize( sizeHint() );
1018 /* Function called from the menu to undock the playlist */
1019 void MainInterface::undockPlaylist()
1021 // dockPL->setFloating( true );
1025 void MainInterface::dockPlaylist( pl_dock_e i_pos )
1029 void MainInterface::toggleMinimalView( bool b_switch )
1031 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
1032 i_visualmode != QT_MINIMAL_MODE )
1033 { /* NORMAL MODE then */
1034 stackCentralW->show();
1035 if( !videoWidget || stackCentralW->currentIndex() != VIDEO_TAB )
1041 /* If video is visible, then toggle the status of bgWidget */
1042 //bgWasVisible = !bgWasVisible;
1043 if( stackCentralOldState == BACKG_TAB )
1044 stackCentralOldState = HIDDEN_TAB;
1046 stackCentralOldState = BACKG_TAB;
1050 i_bg_height = stackCentralW->height();
1052 menuBar()->setVisible( !b_switch );
1053 controls->setVisible( !b_switch );
1054 statusBar()->setVisible( !b_switch );
1055 inputC->setVisible( !b_switch );
1057 doComponentsUpdate();
1059 emit minimalViewToggled( b_switch );
1062 /* toggling advanced controls buttons */
1063 void MainInterface::toggleAdvanced()
1065 controls->toggleAdvanced();
1066 // if( fullscreenControls ) fullscreenControls->toggleAdvanced();
1069 /* Get the visibility status of the controls (hidden or not, advanced or not) */
1070 int MainInterface::getControlsVisibilityStatus()
1072 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
1073 + CONTROLS_ADVANCED * controls->b_advancedVisible );
1077 void MainInterface::visual()
1079 if( !VISIBLE( visualSelector) )
1081 visualSelector->show();
1082 if( !THEMIM->getIM()->hasVideo() )
1084 /* Show the background widget */
1086 visualSelectorEnabled = true;
1090 /* Stop any currently running visualization */
1091 visualSelector->hide();
1092 visualSelectorEnabled = false;
1094 doComponentsUpdate();
1098 /************************************************************************
1100 ************************************************************************/
1101 void MainInterface::setName( const QString& name )
1103 input_name = name; /* store it for the QSystray use */
1104 /* Display it in the status bar, but also as a Tooltip in case it doesn't
1106 nameLabel->setText( " " + name + " " );
1107 nameLabel->setToolTip( " " + name +" " );
1111 * Give the decorations of the Main Window a correct Name.
1112 * If nothing is given, set it to VLC...
1114 void MainInterface::setVLCWindowsTitle( const QString& aTitle )
1116 if( aTitle.isEmpty() )
1118 setWindowTitle( qtr( "VLC media player" ) );
1122 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
1126 void MainInterface::showCryptedLabel( bool b_show )
1128 if( cryptedLabel == NULL )
1130 cryptedLabel = new QLabel;
1131 // The lock icon is not the right one for DRM protection/scrambled.
1132 //cryptedLabel->setPixmap( QPixmap( ":/lock" ) );
1133 cryptedLabel->setText( "DRM" );
1134 statusBar()->addWidget( cryptedLabel );
1137 cryptedLabel->setVisible( b_show );
1140 /*****************************************************************************
1141 * Systray Icon and Systray Menu
1142 *****************************************************************************/
1145 * Create a SystemTray icon and a menu that would go with it.
1146 * Connects to a click handler on the icon.
1148 void MainInterface::createSystray()
1151 if( QDate::currentDate().dayOfYear() >= 354 )
1152 iconVLC = QIcon( ":/logo/vlc128-christmas.png" );
1154 iconVLC = QIcon( ":/logo/vlc128.png" );
1155 sysTray = new QSystemTrayIcon( iconVLC, this );
1156 sysTray->setToolTip( qtr( "VLC media player" ));
1158 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
1159 systrayMenu->setIcon( iconVLC );
1161 QVLCMenu::updateSystrayMenu( this, p_intf, true );
1164 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
1165 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
1169 * Updates the Systray Icon's menu and toggle the main interface
1171 void MainInterface::toggleUpdateSystrayMenu()
1173 /* If hidden, show it */
1179 else if( isMinimized() )
1187 /* Visible (possibly under other windows) */
1189 /* check if any visible window is above vlc in the z-order,
1190 * but ignore the ones always on top
1191 * and the ones which can't be activated */
1194 wi.cbSize = sizeof( WINDOWINFO );
1195 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
1196 hwnd && ( !IsWindowVisible( hwnd ) ||
1197 ( GetWindowInfo( hwnd, &wi ) &&
1198 (wi.dwExStyle&WS_EX_NOACTIVATE) ) );
1199 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
1200 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
1201 (wi.dwExStyle&WS_EX_TOPMOST) )
1213 QVLCMenu::updateSystrayMenu( this, p_intf );
1216 void MainInterface::handleSystrayClick(
1217 QSystemTrayIcon::ActivationReason reason )
1221 case QSystemTrayIcon::Trigger:
1222 case QSystemTrayIcon::DoubleClick:
1223 toggleUpdateSystrayMenu();
1225 case QSystemTrayIcon::MiddleClick:
1226 sysTray->showMessage( qtr( "VLC media player" ),
1227 qtr( "Control menu for the player" ),
1228 QSystemTrayIcon::Information, 3000 );
1236 * Updates the name of the systray Icon tooltip.
1237 * Doesn't check if the systray exists, check before you call it.
1239 void MainInterface::updateSystrayTooltipName( const QString& name )
1241 if( name.isEmpty() )
1243 sysTray->setToolTip( qtr( "VLC media player" ) );
1247 sysTray->setToolTip( name );
1248 if( notificationEnabled && ( isHidden() || isMinimized() ) )
1250 sysTray->showMessage( qtr( "VLC media player" ), name,
1251 QSystemTrayIcon::NoIcon, 3000 );
1255 QVLCMenu::updateSystrayMenu( this, p_intf );
1259 * Updates the status of the systray Icon tooltip.
1260 * Doesn't check if the systray exists, check before you call it.
1262 void MainInterface::updateSystrayTooltipStatus( int i_status )
1269 sysTray->setToolTip( qtr( "VLC media player" ) );
1274 sysTray->setToolTip( input_name );
1279 sysTray->setToolTip( input_name + " - "
1284 QVLCMenu::updateSystrayMenu( this, p_intf );
1288 /************************************************************************
1290 ************************************************************************/
1291 void MainInterface::dropEvent(QDropEvent *event)
1293 dropEventPlay( event, true );
1296 void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
1298 event->setDropAction( Qt::CopyAction );
1299 if( !event->possibleActions() & Qt::CopyAction )
1302 const QMimeData *mimeData = event->mimeData();
1304 /* D&D of a subtitles file, add it on the fly */
1305 if( mimeData->urls().size() == 1 && THEMIM->getIM()->hasInput() )
1307 if( !input_AddSubtitle( THEMIM->getInput(),
1308 qtu( toNativeSeparators( mimeData->urls()[0].toLocalFile() ) ),
1316 bool first = b_play;
1317 foreach( const QUrl &url, mimeData->urls() )
1319 QString s = toNativeSeparators( url.toLocalFile() );
1321 if( s.length() > 0 ) {
1322 char* psz_uri = make_URI( qtu(s) );
1323 playlist_Add( THEPL, psz_uri, NULL,
1324 PLAYLIST_APPEND | (first ? PLAYLIST_GO: PLAYLIST_PREPARSE),
1325 PLAYLIST_END, true, pl_Unlocked );
1328 RecentsMRL::getInstance( p_intf )->addRecent( s );
1333 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1335 event->acceptProposedAction();
1337 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1339 event->acceptProposedAction();
1341 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1346 /************************************************************************
1348 ************************************************************************/
1349 void MainInterface::customEvent( QEvent *event )
1352 if( event->type() == PLDockEvent_Type )
1354 PlaylistDialog::killInstance();
1355 playlistEmbeddedFlag = true;
1357 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1362 if ( event->type() == (int)SetVideoOnTopEvent_Type )
1364 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1365 if( p_event->OnTop() )
1366 setWindowFlags( windowFlags() | Qt::WindowStaysOnTopHint );
1368 setWindowFlags( windowFlags() & ~Qt::WindowStaysOnTopHint );
1369 show(); /* necessary to apply window flags */
1373 void MainInterface::keyPressEvent( QKeyEvent *e )
1375 handleKeyPress( e );
1378 void MainInterface::handleKeyPress( QKeyEvent *e )
1380 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() == Qt::Key_H )
1381 && !menuBar()->isVisible() )
1383 toggleMinimalView( false );
1387 int i_vlck = qtEventToVLCKey( e );
1390 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1397 void MainInterface::resizeEvent( QResizeEvent * event )
1402 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
1403 i_visualmode == QT_MINIMAL_MODE )
1405 mainVideoSize = size();
1409 if( VISIBLE( bgWidget) ||
1410 ( videoIsActive && videoWidget->isVisible() )
1412 mainVideoSize = size();
1414 mainBasedSize = size();
1418 QVLCMW::resizeEvent( event );
1419 msg_Dbg( p_intf, "Resize Event, height: %i", size().height() );
1422 void MainInterface::wheelEvent( QWheelEvent *e )
1424 int i_vlckey = qtWheelEventToVLCKey( e );
1425 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1429 void MainInterface::closeEvent( QCloseEvent *e )
1436 void MainInterface::toggleFullScreen( void )
1438 if( isFullScreen() )
1441 emit askUpdate(); // Needed if video was launched after the F11
1442 emit fullscreenInterfaceToggled( false );
1447 emit fullscreenInterfaceToggled( true );
1452 //moc doesn't know about #ifdef, so we have to build this method for every platform
1453 void MainInterface::changeThumbbarButtons( int i_status)
1456 // Define an array of two buttons. These buttons provide images through an
1457 // image list and also provide tooltips.
1458 DWORD dwMask = THB_BITMAP | THB_FLAGS;
1460 THUMBBUTTON thbButtons[3];
1462 thbButtons[0].dwMask = dwMask;
1463 thbButtons[0].iId = 0;
1464 thbButtons[0].iBitmap = 0;
1467 thbButtons[1].dwMask = dwMask;
1468 thbButtons[1].iId = 1;
1471 thbButtons[2].dwMask = dwMask;
1472 thbButtons[2].iId = 2;
1473 thbButtons[2].iBitmap = 3;
1480 thbButtons[0].dwFlags = THBF_HIDDEN;
1481 thbButtons[1].dwFlags = THBF_HIDDEN;
1482 thbButtons[2].dwFlags = THBF_HIDDEN;
1487 thbButtons[0].dwFlags = THBF_ENABLED;
1488 thbButtons[1].dwFlags = THBF_ENABLED;
1489 thbButtons[2].dwFlags = THBF_ENABLED;
1490 thbButtons[1].iBitmap = 1;
1495 //thbButtons[0].dwFlags = THBF_ENABLED;
1496 //thbButtons[1].dwFlags = THBF_ENABLED;
1497 //thbButtons[2].dwFlags = THBF_ENABLED;
1498 thbButtons[1].iBitmap = 2;
1503 HRESULT hr = p_taskbl->vt->ThumbBarUpdateButtons(p_taskbl, GetForegroundWindow(), 3, thbButtons);
1505 msg_Err( p_intf, "ThumbBarUpdateButtons failed with error %08x", hr );
1511 /*****************************************************************************
1512 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1513 * We don't show the menu directly here because we don't want the
1514 * caller to block for a too long time.
1515 *****************************************************************************/
1516 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1517 vlc_value_t old_val, vlc_value_t new_val, void *param )
1519 intf_thread_t *p_intf = (intf_thread_t *)param;
1521 if( p_intf->pf_show_dialog )
1523 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1524 new_val.b_bool, NULL );
1530 /*****************************************************************************
1531 * IntfShowCB: callback triggered by the intf-show libvlc variable.
1532 *****************************************************************************/
1533 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1534 vlc_value_t old_val, vlc_value_t new_val, void *param )
1536 intf_thread_t *p_intf = (intf_thread_t *)param;
1537 p_intf->p_sys->p_mi->toggleFSC();