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 playlistVisible = false;
91 fullscreenControls = NULL;
97 stackCentralOldState = HIDDEN_TAB;
100 /* Ask for privacy */
104 * Configuration and settings
105 * Pre-building of interface
108 setFocusPolicy( Qt::StrongFocus );
109 setAcceptDrops( true );
110 setWindowRole( "vlc-main" );
111 setWindowIcon( QApplication::windowIcon() );
112 setWindowOpacity( config_GetFloat( p_intf, "qt-opacity" ) );
114 /* Set The Video In emebedded Mode or not */
115 videoEmbeddedFlag = config_GetInt( p_intf, "embedded-video" );
117 /* Does the interface resize to video size or the opposite */
118 b_keep_size = !config_GetInt( p_intf, "qt-video-autoresize" );
120 /* Are we in the enhanced always-video mode or not ? */
121 i_visualmode = config_GetInt( p_intf, "qt-display-mode" );
123 /* Do we want anoying popups or not */
124 notificationEnabled = (bool)config_GetInt( p_intf, "qt-notification" );
126 /* Set the other interface settings */
127 settings = getSettings();
128 settings->beginGroup( "MainWindow" );
131 * Retrieve saved sizes for main window
132 * mainBasedSize = based window size for normal mode
133 * (no video, no background)
134 * mainVideoSize = window size with video (all modes)
136 mainBasedSize = settings->value( "mainBasedSize", QSize( 350, 120 ) ).toSize();
137 mainVideoSize = settings->value( "mainVideoSize", QSize( 400, 300 ) ).toSize();
144 /**************************
145 * UI and Widgets design
146 **************************/
147 setVLCWindowsTitle();
148 createMainWidget( settings );
153 QVLCMenu::createMenuBar( this, p_intf );
154 CONNECT( THEMIM->getIM(), voutListChanged( vout_thread_t **, int ),
155 this, destroyPopupMenu() );
158 /* Create a Dock to get the playlist */
159 dockPL = new QDockWidget( qtr( "Playlist" ), this );
160 dockPL->setSizePolicy( QSizePolicy::Preferred,
161 QSizePolicy::Expanding );
162 dockPL->setFeatures( QDockWidget::AllDockWidgetFeatures );
163 dockPL->setAllowedAreas( Qt::LeftDockWidgetArea
164 | Qt::RightDockWidgetArea
165 | Qt::BottomDockWidgetArea );
169 /*********************************
170 * Create the Systray Management *
171 *********************************/
174 /********************
176 ********************/
177 MainInputManager::getInstance( p_intf );
179 /************************************************************
180 * Connect the input manager to the GUI elements it manages *
181 ************************************************************/
183 * Connects on nameChanged()
184 * Those connects are different because options can impeach them to trigger.
186 /* Main Interface statusbar */
187 CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
188 this, setName( const QString& ) );
193 CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
194 this, updateSystrayTooltipName( const QString& ) );
197 /* and title of the Main Interface*/
198 if( config_GetInt( p_intf, "qt-name-in-title" ) )
200 CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
201 this, setVLCWindowsTitle( const QString& ) );
205 * CONNECTS on PLAY_STATUS
207 /* Status on the systray */
211 CONNECT( THEMIM->getIM(), statusChanged( int ),
212 this, updateSystrayTooltipStatus( int ) );
216 /* END CONNECTS ON IM */
221 var_AddCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
223 /* Register callback for the intf-popupmenu variable */
224 var_AddCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
227 /* VideoWidget connects for asynchronous calls */
228 connect( this, SIGNAL(askGetVideo(WId*,int*,int*,unsigned*,unsigned *)),
229 this, SLOT(getVideoSlot(WId*,int*,int*,unsigned*,unsigned*)),
230 Qt::BlockingQueuedConnection );
231 connect( this, SIGNAL(askReleaseVideo( void )),
232 this, SLOT(releaseVideoSlot( void )),
233 Qt::BlockingQueuedConnection );
237 CONNECT( this, askVideoToResize( unsigned int, unsigned int ),
238 videoWidget, SetSizing( unsigned int, unsigned int ) );
239 CONNECT( this, askVideoSetFullScreen( bool ),
240 videoWidget, SetFullScreen( bool ) );
241 CONNECT( videoWidget, keyPressed( QKeyEvent * ),
242 this, handleKeyPress( QKeyEvent * ) );
245 CONNECT( this, askUpdate(), this, doComponentsUpdate() );
246 CONNECT( THEDP, toolBarConfUpdated(), this, recreateToolbars() );
248 /* Size and placement of interface */
249 settings->beginGroup( "MainWindow" );
250 QVLCTools::restoreWidgetPosition( settings, this, QSize(380, 60) );
252 /* resize to previously saved main window size if appicable */
255 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
256 i_visualmode == QT_MINIMAL_MODE )
258 resize( mainVideoSize );
262 resize( mainBasedSize );
266 bool b_pl_visible = settings->value( "playlist-visible", 0 ).toInt();
267 settings->endGroup();
270 if( b_pl_visible ) togglePlaylist();
272 /* Enable the popup menu in the MI */
273 setContextMenuPolicy( Qt::CustomContextMenu );
274 CONNECT( this, customContextMenuRequested( const QPoint& ),
275 this, popupMenu( const QPoint& ) );
279 /* Final sizing and showing */
280 setVisible( !b_shouldHide );
281 //setMinimumSize( QSize( 0, 0 ) );
282 // setMinimumWidth( __MAX( controls->sizeHint().width(),
283 // menuBar()->sizeHint().width() ) );
286 /* And switch to minimal view if needed
287 Must be called after the show() */
288 if( i_visualmode == QT_MINIMAL_MODE )
289 toggleMinimalView( true );
291 /* Update the geometry : It is useful if you switch between
294 resize( sizeHint() );
297 createTaskBarButtons();
301 MainInterface::~MainInterface()
303 msg_Dbg( p_intf, "Destroying the main interface" );
305 /* Unsure we hide the videoWidget before destroying it */
306 if( stackCentralOldState == VIDEO_TAB )
311 /* Save playlist state */
315 QVLCTools::saveWidgetPosition( p_intf, "Playlist", playlistWidget );
317 delete playlistWidget;
322 ImageList_Destroy( himl );
324 p_taskbl->vt->Release(p_taskbl);
328 /* Be sure to kill the actionsManager... FIXME */
329 ActionsManager::killInstance();
331 /* Delete the FSC controller */
332 delete fullscreenControls;
335 settings->beginGroup( "MainWindow" );
336 settings->setValue( "pl-dock-status", (int)i_pl_dock );
337 settings->setValue( "playlist-visible", (int)playlistVisible );
338 settings->setValue( "adv-controls",
339 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
341 settings->setValue( "mainBasedSize", mainBasedSize );
342 settings->setValue( "mainVideoSize", mainVideoSize );
345 settings->setValue( "backgroundSize", bgWidget->size() );
348 QVLCTools::saveWidgetPosition(settings, this);
349 settings->endGroup();
352 /* Unregister callbacks */
353 var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
354 var_DelCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
356 p_intf->p_sys->p_mi = NULL;
359 /*****************************
361 *****************************/
362 void MainInterface::recreateToolbars()
364 msg_Err( p_intf, "Recreating the toolbars" );
365 settings->beginGroup( "MainWindow" );
368 controls = new ControlsWidget( p_intf, false, this ); /* FIXME */
369 CONNECT( controls, advancedControlsToggled( bool ),
370 this, doComponentsUpdate() );
371 CONNECT( controls, sizeChanged(),
372 this, doComponentsUpdate() );
373 inputC = new InputControlsWidget( p_intf, this );
375 mainLayout->insertWidget( 2, inputC );
376 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
378 settings->endGroup();
381 void MainInterface::createMainWidget( QSettings *settings )
383 /* Create the main Widget and the mainLayout */
384 QWidget *main = new QWidget;
385 setCentralWidget( main );
386 mainLayout = new QVBoxLayout( main );
388 /* Margins, spacing */
389 main->setContentsMargins( 0, 0, 0, 0 );
390 mainLayout->setSpacing( 0 );
391 mainLayout->setMargin( 0 );
394 stackCentralW = new QStackedWidget( main );
397 bgWidget = new BackgroundWidget( p_intf );
399 settings->value( "backgroundSize", QSize( 300, 200 ) ).toSize() );
400 bgWidget->updateGeometry();
401 stackCentralW->insertWidget( BACKG_TAB, bgWidget );
403 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
404 i_visualmode != QT_MINIMAL_MODE )
406 stackCentralW->hide();
409 /* And video Outputs */
410 if( videoEmbeddedFlag )
412 videoWidget = new VideoWidget( p_intf );
413 stackCentralW->insertWidget( VIDEO_TAB, videoWidget );
415 mainLayout->insertWidget( 1, stackCentralW, 100 );
416 /* Create the CONTROLS Widget */
417 controls = new ControlsWidget( p_intf,
418 settings->value( "adv-controls", false ).toBool(), this );
419 CONNECT( controls, advancedControlsToggled( bool ),
420 this, doComponentsUpdate() );
421 CONNECT( controls, sizeChanged(),
422 this, doComponentsUpdate() );
423 inputC = new InputControlsWidget( p_intf, this );
425 //mainLayout->setRowStretch( 1, 10 );
426 mainLayout->insertWidget( 2, inputC );
427 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
431 /* Disabled for now, they SUCK */
433 visualSelector = new VisualSelector( p_intf );
434 mainLayout->insertWidget( 0, visualSelector );
435 visualSelector->hide();
438 /* Finish the sizing */
439 main->updateGeometry();
441 getSettings()->endGroup();
445 /* Create the FULLSCREEN CONTROLS Widget */
446 if( config_GetInt( p_intf, "qt-fs-controller" ) )
448 fullscreenControls = new FullscreenControllerWidget( p_intf, this );
449 CONNECT( fullscreenControls, keyPressed( QKeyEvent * ),
450 this, handleKeyPress( QKeyEvent * ) );
454 inline void MainInterface::createStatusBar()
459 /* Widgets Creation*/
460 QStatusBar *statusBarr = statusBar();
462 TimeLabel *timeLabel = new TimeLabel( p_intf );
463 nameLabel = new QLabel( this );
464 nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
465 | Qt::TextSelectableByKeyboard );
466 SpeedLabel *speedLabel = new SpeedLabel( p_intf, "1.00x", this );
468 /* Styling those labels */
469 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
470 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
471 nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
473 /* and adding those */
474 statusBarr->addWidget( nameLabel, 8 );
475 statusBarr->addPermanentWidget( speedLabel, 0 );
476 statusBarr->addPermanentWidget( timeLabel, 0 );
478 /* timeLabel behaviour:
479 - double clicking opens the goto time dialog
480 - right-clicking and clicking just toggle between remaining and
482 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
484 CONNECT( THEMIM->getIM(), encryptionChanged( bool ),
485 this, showCryptedLabel( bool ) );
489 void MainInterface::createTaskBarButtons()
491 /*Here is the code for the taskbar thumb buttons
492 FIXME:We need pretty buttons in 16x16 px that are handled correctly by masks in Qt
493 FIXME:the play button's picture doesn't changed to pause when clicked
495 OSVERSIONINFO winVer;
496 winVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
497 if( GetVersionEx(&winVer) && winVer.dwMajorVersion > 5 )
499 if(himl = ImageList_Create( 15, //cx
502 4,//initial nb of images
503 0//nb of images that can be added
506 QPixmap img = QPixmap(":/toolbar/previous_b");
507 QPixmap img2 = QPixmap(":/toolbar/pause_b");
508 QPixmap img3 = QPixmap(":/toolbar/play_b");
509 QPixmap img4 = QPixmap(":/toolbar/next_b");
510 QBitmap mask = img.createMaskFromColor(Qt::transparent);
511 QBitmap mask2 = img2.createMaskFromColor(Qt::transparent);
512 QBitmap mask3 = img3.createMaskFromColor(Qt::transparent);
513 QBitmap mask4 = img4.createMaskFromColor(Qt::transparent);
515 if(-1 == ImageList_Add(himl, img.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask.toWinHBITMAP()))
516 msg_Err( p_intf, "ImageList_Add failed" );
517 if(-1 == ImageList_Add(himl, img2.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask2.toWinHBITMAP()))
518 msg_Err( p_intf, "ImageList_Add failed" );
519 if(-1 == ImageList_Add(himl, img3.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask3.toWinHBITMAP()))
520 msg_Err( p_intf, "ImageList_Add failed" );
521 if(-1 == ImageList_Add(himl, img4.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask4.toWinHBITMAP()))
522 msg_Err( p_intf, "ImageList_Add failed" );
527 if( S_OK == CoCreateInstance( &clsid_ITaskbarList,
528 NULL, CLSCTX_INPROC_SERVER,
530 (void **)&p_taskbl) )
532 p_taskbl->vt->HrInit(p_taskbl);
534 int msg_value = RegisterWindowMessage("TaskbarButtonCreated");
535 //msg_Info( p_intf, "msg value: %04x", msg_value );
537 // Define an array of two buttons. These buttons provide images through an
538 // image list and also provide tooltips.
539 DWORD dwMask = THB_BITMAP | THB_FLAGS;
541 THUMBBUTTON thbButtons[2];
542 thbButtons[0].dwMask = dwMask;
543 thbButtons[0].iId = 0;
544 thbButtons[0].iBitmap = 0;
545 thbButtons[0].dwFlags = THBF_HIDDEN;
547 thbButtons[1].dwMask = dwMask;
548 thbButtons[1].iId = 1;
549 thbButtons[1].iBitmap = 2;
550 thbButtons[1].dwFlags = THBF_HIDDEN;
552 thbButtons[2].dwMask = dwMask;
553 thbButtons[2].iId = 2;
554 thbButtons[2].iBitmap = 3;
555 thbButtons[2].dwFlags = THBF_HIDDEN;
557 HRESULT hr = p_taskbl->vt->ThumbBarSetImageList(p_taskbl, GetForegroundWindow(), himl );
559 msg_Err( p_intf, "ThumbBarSetImageList failed with error %08x", hr );
560 if(S_OK != p_taskbl->vt->ThumbBarAddButtons(p_taskbl, GetForegroundWindow(), 3, thbButtons))
561 msg_Err( p_intf, "ThumbBarAddButtons failed with error %08x", GetLastError() );
563 CONNECT( THEMIM->getIM(), statusChanged( int ), this, changeThumbbarButtons( int ) );
575 inline void MainInterface::initSystray()
578 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
579 bool b_systrayWanted = config_GetInt( p_intf, "qt-system-tray" );
581 if( config_GetInt( p_intf, "qt-start-minimized") > 0 )
583 if( b_systrayAvailable )
585 b_systrayWanted = true;
589 msg_Err( p_intf, "cannot start minimized without system tray bar" );
592 if( b_systrayAvailable && b_systrayWanted )
597 inline void MainInterface::askForPrivacy()
601 * Ask for the network policy on FIRST STARTUP
603 if( config_GetInt( p_intf, "qt-privacy-ask") )
605 QList<ConfigControl *> controls;
606 if( privacyDialog( &controls ) == QDialog::Accepted )
608 QList<ConfigControl *>::Iterator i;
609 for( i = controls.begin() ; i != controls.end() ; i++ )
611 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
612 c->doApply( p_intf );
615 config_PutInt( p_intf, "qt-privacy-ask" , 0 );
616 /* We have to save here because the user may not launch Prefs */
617 config_SaveConfigFile( p_intf, NULL );
623 int MainInterface::privacyDialog( QList<ConfigControl *> *controls )
625 QDialog *privacy = new QDialog( this );
627 privacy->setWindowTitle( qtr( "Privacy and Network Policies" ) );
628 privacy->setWindowRole( "vlc-privacy" );
630 QGridLayout *gLayout = new QGridLayout( privacy );
632 QGroupBox *blabla = new QGroupBox( qtr( "Privacy and Network Warning" ) );
633 QGridLayout *blablaLayout = new QGridLayout( blabla );
634 QLabel *text = new QLabel( qtr(
635 "<p>The <i>VideoLAN Team</i> doesn't like when an application goes "
636 "online without authorization.</p>\n "
637 "<p><i>VLC media player</i> can retreive limited information from "
638 "the Internet in order to get CD covers or to check "
639 "for available updates.</p>\n"
640 "<p><i>VLC media player</i> <b>DOES NOT</b> send or collect <b>ANY</b> "
641 "information, even anonymously, about your usage.</p>\n"
642 "<p>Therefore please select from the following options, the default being "
643 "almost no access to the web.</p>\n") );
644 text->setWordWrap( true );
645 text->setTextFormat( Qt::RichText );
647 blablaLayout->addWidget( text, 0, 0 ) ;
649 QGroupBox *options = new QGroupBox;
650 QGridLayout *optionsLayout = new QGridLayout( options );
652 gLayout->addWidget( blabla, 0, 0, 1, 3 );
653 gLayout->addWidget( options, 1, 0, 1, 3 );
654 module_config_t *p_config;
655 ConfigControl *control;
658 #define CONFIG_GENERIC( option, type ) \
659 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
662 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
663 p_config, options, false, optionsLayout, line ); \
664 controls->append( control ); \
667 #define CONFIG_GENERIC_NOBOOL( option, type ) \
668 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
671 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
672 p_config, options, optionsLayout, line ); \
673 controls->append( control ); \
676 CONFIG_GENERIC( "album-art", IntegerList ); line++;
678 CONFIG_GENERIC_NOBOOL( "qt-updates-notif", Bool ); line++;
681 QPushButton *ok = new QPushButton( qtr( "OK" ) );
683 gLayout->addWidget( ok, 2, 2 );
685 CONNECT( ok, clicked(), privacy, accept() );
686 return privacy->exec();
690 /**********************************************************************
691 * Handling of sizing of the components
692 **********************************************************************/
694 /* This function is probably wrong, but we don't have many many choices...
695 Since we can't know from the playlist Widget if we are inside a dock or not,
696 because the playlist Widget can be called by THEDP, as a separate windows for
698 Maybe the other solution is to redefine the sizeHint() of the playlist and
699 ask _parent->isFloating()...
700 If you think this would be better, please FIXME it...
703 QSize MainInterface::sizeHint() const
708 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
709 i_visualmode == QT_MINIMAL_MODE )
711 return mainVideoSize;
715 if( VISIBLE( bgWidget) ||
716 ( videoIsActive && videoWidget->isVisible() )
718 return mainVideoSize;
720 return mainBasedSize;
725 int nwidth = __MAX( controls->sizeHint().width(),
726 menuBar()->sizeHint().width() );
728 int nheight = controls->isVisible() ?
729 controls->size().height()
730 + inputC->size().height()
731 + menuBar()->size().height()
732 + statusBar()->size().height()
735 if( stackCentralW->isVisible() )
736 nheight += stackCentralW->height();
737 nwidth = __MAX( nwidth, stackCentralW->width() );
739 /* if( VISIBLE( bgWidget ) )
741 msg_Warn( p_intf, "Hello here" );
743 nheight += i_bg_height;
745 nheight += bgWidget->size().height();
746 nwidth = __MAX( nwidth, bgWidget->size().width() );
748 else if( videoIsActive && videoWidget->isVisible() )
750 msg_Warn( p_intf, "Hello there" );
751 nheight += videoWidget->sizeHint().height();
752 nwidth = __MAX( nwidth, videoWidget->sizeHint().width() );
755 if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget() )
757 nheight += dockPL->size().height();
758 nwidth = __MAX( nwidth, dockPL->size().width() );
759 msg_Warn( p_intf, "3 %i %i", nheight, nwidth );
762 return QSize( nwidth, nheight );
766 /* Video widget cannot do this synchronously as it runs in another thread */
767 /* Well, could it, actually ? Probably dangerous ... */
769 /* This function is called:
770 - toggling of minimal View
771 - through askUpdate() by Vout thread request video and resize video (zoom)
772 - Advanced buttons toggled
774 void MainInterface::doComponentsUpdate()
776 if( isFullScreen() || isMaximized() ) return;
778 msg_Err( p_intf, "Updating the geometry" );
779 /* Here we resize to sizeHint() and not adjustsize because we want
780 the videoWidget to be exactly the correctSize */
786 setMinimumSize( 0, 0 );
787 resize( sizeHint() );
792 void MainInterface::debug()
795 if( stackCentralW->isVisible() )
796 msg_Dbg( p_intf, "CentralStack visible" );
798 msg_Dbg( p_intf, "CentralStack inVisible" );
799 //msg_Dbg( p_intf, "Stack Size: %i - %i", stackCentralW->sizeHint().height(), stackCentralW->sizeHint().width() );
800 msg_Dbg( p_intf, "Stack Size: %i - %i", stackCentralW->size().height(), size().width() );
801 msg_Dbg( p_intf, "Stack Size: %i - %i", stackCentralW->widget( VIDEO_TAB )->size().height(), stackCentralW->widget( VIDEO_TAB )->size().width() );
803 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
804 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
805 //msg_Dbg( p_intf, "maximumsize: %i - %i", maximumSize().height(), maximumSize().width() );
807 msg_Dbg( p_intf, "Stack minimumsize: %i - %i", stackCentralW->minimumSize().height(), stackCentralW->minimumSize().width() );
808 msg_Dbg( p_intf, "Controls minimumsize: %i - %i", controls->minimumSize().height(), controls->minimumSize().width() );
809 msg_Dbg( p_intf, "Central minimumsize: %i - %i", centralWidget()->minimumSize().height(), centralWidget()->minimumSize().width() );
810 msg_Dbg( p_intf, "Menu minimumsize: %i - %i", menuBar()->minimumSize().height(), menuBar()->minimumSize().width() );
811 msg_Dbg( p_intf, "Input minimuSize: %i - %i", inputC->minimumSize().height(), inputC->minimumSize().width() );
812 msg_Dbg( p_intf, "Status minimumsize: %i - %i", statusBar()->minimumSize().height(), statusBar()->minimumSize().width() );
813 msg_Dbg( p_intf, "minimumsize: %i - %i", minimumSize().height(), minimumSize().width() );
816 /*if( videoWidget && videoWidget->isVisible() )
818 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
819 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
824 void MainInterface::destroyPopupMenu()
826 QVLCMenu::PopupMenu(p_intf, false );
830 void MainInterface::toggleFSC()
832 if( !fullscreenControls ) return;
834 IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
835 QApplication::postEvent( fullscreenControls, eShow );
838 void MainInterface::popupMenu( const QPoint &p )
840 /* Ow, that's ugly: don't show the popup menu if cursor over
841 * the main menu bar or the status bar */
842 if( !childAt( p ) || ( ( childAt( p ) != menuBar() )
843 && ( childAt( p )->parentWidget() != statusBar() ) ) )
844 QVLCMenu::PopupMenu( p_intf, true );
847 /****************************************************************************
849 ****************************************************************************/
851 /* This event is used to deal with the fullscreen and always on top
852 issue conflict (bug in wx) */
853 class SetVideoOnTopQtEvent : public QEvent
856 SetVideoOnTopQtEvent( bool _onTop ) :
857 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
860 bool OnTop() const { return onTop; }
868 * You must note change the state of this object or other Qt4 UI objects,
869 * from the video output thread - only from the Qt4 UI main loop thread.
870 * All window provider queries must be handled through signals or events.
871 * That's why we have all those emit statements...
873 WId MainInterface::getVideo( int *pi_x, int *pi_y,
874 unsigned int *pi_width, unsigned int *pi_height )
879 /* This is a blocking call signal. Results are returned through pointers.
880 * Beware of deadlocks! */
882 emit askGetVideo( &id, pi_x, pi_y, pi_width, pi_height );
886 void MainInterface::getVideoSlot( WId *p_id, int *pi_x, int *pi_y,
887 unsigned *pi_width, unsigned *pi_height )
889 /* Request the videoWidget */
890 WId ret = videoWidget->request( pi_x, pi_y,
891 pi_width, pi_height, b_keep_size );
893 if( ret ) /* The videoWidget is available */
895 /* ask videoWidget to show */
896 videoWidget->SetSizing( *pi_width, *pi_height );
898 /* Consider the video active now */
901 stackCentralW->resize( *pi_width, *pi_height );
907 inline void MainInterface::showTab( int i_tab )
909 stackCentralOldState = stackCentralW->currentIndex();
911 stackCentralW->setCurrentIndex( i_tab );
912 if( stackCentralW->isHidden() ) stackCentralW->show();
915 /* Asynchronous call from the WindowClose function */
916 void MainInterface::releaseVideo( void )
918 emit askReleaseVideo( );
921 /* Function that is CONNECTED to the previous emit */
922 void MainInterface::releaseVideoSlot( void )
924 videoWidget->release( );
926 /* Restore the previous State */
927 if( stackCentralOldState == BACKG_TAB )
933 stackCentralW->hide();
934 stackCentralOldState == -1;
937 /* Try to resize, except when you are in Fullscreen mode */
938 doComponentsUpdate();
941 /* Asynchronous call from WindowControl function */
942 int MainInterface::controlVideo( int i_query, va_list args )
946 /* Debug to check if VOUT_WINDOW_SET_SIZE is called? */
947 msg_Dbg( p_intf, "Control Video: %i", i_query );
948 case VOUT_WINDOW_SET_SIZE:
950 unsigned int i_width = va_arg( args, unsigned int );
951 unsigned int i_height = va_arg( args, unsigned int );
952 emit askVideoToResize( i_width, i_height );
956 case VOUT_WINDOW_SET_ON_TOP:
958 int i_arg = va_arg( args, int );
959 QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
962 case VOUT_WINDOW_SET_FULLSCREEN:
964 bool b_fs = va_arg( args, int );
965 emit askVideoSetFullScreen( b_fs );
969 msg_Warn( p_intf, "unsupported control query" );
974 /*****************************************************************************
975 * Playlist, Visualisation and Menus handling
976 *****************************************************************************/
978 * Toggle the playlist widget or dialog
980 void MainInterface::togglePlaylist()
983 If no playlist exist, then create one and attach it to the DockPL*/
984 if( !playlistWidget )
986 playlistWidget = new PlaylistWidget( p_intf );
988 i_pl_dock = PL_BOTTOM;
989 /*i_pl_dock = (pl_dock_e)getSettings()
990 ->value( "pl-dock-status", PL_UNDOCKED ).toInt();*/
992 if( i_pl_dock == PL_UNDOCKED )
994 playlistWidget->setWindowFlags( Qt::Window );
996 /* This will restore the geometry but will not work for position,
997 because of parenting */
998 QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
999 playlistWidget, QSize( 600, 300 ) );
1003 stackCentralW->insertWidget(PLAYL_TAB, playlistWidget );
1004 stackCentralW->setCurrentWidget( playlistWidget );
1005 stackCentralW->show();
1007 playlistVisible = true;
1009 playlistWidget->show();
1013 /* toggle the visibility of the playlist */
1014 if( stackCentralW->currentIndex() != PLAYL_TAB )
1016 stackCentralW->insertWidget(PLAYL_TAB, playlistWidget );
1017 stackCentralW->setCurrentWidget( playlistWidget );
1018 stackCentralW->show();
1021 stackCentralW->setCurrentIndex( VIDEO_TAB );
1022 playlistVisible = !playlistVisible;
1023 //doComponentsUpdate(); //resize( sizeHint() );
1027 /* Function called from the menu to undock the playlist */
1028 void MainInterface::undockPlaylist()
1030 // dockPL->setFloating( true );
1034 void MainInterface::dockPlaylist( pl_dock_e i_pos )
1038 void MainInterface::toggleMinimalView( bool b_switch )
1040 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
1041 i_visualmode != QT_MINIMAL_MODE )
1042 { /* NORMAL MODE then */
1043 stackCentralW->show();
1044 if( !videoWidget || stackCentralW->currentIndex() != VIDEO_TAB )
1050 /* If video is visible, then toggle the status of bgWidget */ //bgWasVisible = !bgWasVisible;
1051 if( stackCentralOldState == BACKG_TAB )
1052 stackCentralOldState = HIDDEN_TAB;
1054 stackCentralOldState = BACKG_TAB;
1058 i_bg_height = stackCentralW->height();
1060 menuBar()->setVisible( !b_switch );
1061 controls->setVisible( !b_switch );
1062 statusBar()->setVisible( !b_switch );
1063 inputC->setVisible( !b_switch );
1065 doComponentsUpdate();
1067 emit minimalViewToggled( b_switch );
1070 /* toggling advanced controls buttons */
1071 void MainInterface::toggleAdvanced()
1073 controls->toggleAdvanced();
1074 // if( fullscreenControls ) fullscreenControls->toggleAdvanced();
1077 /* Get the visibility status of the controls (hidden or not, advanced or not) */
1078 int MainInterface::getControlsVisibilityStatus()
1080 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
1081 + CONTROLS_ADVANCED * controls->b_advancedVisible );
1085 void MainInterface::visual()
1087 if( !VISIBLE( visualSelector) )
1089 visualSelector->show();
1090 if( !THEMIM->getIM()->hasVideo() )
1092 /* Show the background widget */
1094 visualSelectorEnabled = true;
1098 /* Stop any currently running visualization */
1099 visualSelector->hide();
1100 visualSelectorEnabled = false;
1102 doComponentsUpdate();
1106 /************************************************************************
1108 ************************************************************************/
1109 void MainInterface::setName( const QString& name )
1111 input_name = name; /* store it for the QSystray use */
1112 /* Display it in the status bar, but also as a Tooltip in case it doesn't
1114 nameLabel->setText( " " + name + " " );
1115 nameLabel->setToolTip( " " + name +" " );
1119 * Give the decorations of the Main Window a correct Name.
1120 * If nothing is given, set it to VLC...
1122 void MainInterface::setVLCWindowsTitle( const QString& aTitle )
1124 if( aTitle.isEmpty() )
1126 setWindowTitle( qtr( "VLC media player" ) );
1130 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
1134 void MainInterface::showCryptedLabel( bool b_show )
1136 if( cryptedLabel == NULL )
1138 cryptedLabel = new QLabel;
1139 // The lock icon is not the right one for DRM protection/scrambled.
1140 //cryptedLabel->setPixmap( QPixmap( ":/lock" ) );
1141 cryptedLabel->setText( "DRM" );
1142 statusBar()->addWidget( cryptedLabel );
1145 cryptedLabel->setVisible( b_show );
1148 /*****************************************************************************
1149 * Systray Icon and Systray Menu
1150 *****************************************************************************/
1153 * Create a SystemTray icon and a menu that would go with it.
1154 * Connects to a click handler on the icon.
1156 void MainInterface::createSystray()
1159 if( QDate::currentDate().dayOfYear() >= 354 )
1160 iconVLC = QIcon( ":/logo/vlc128-christmas.png" );
1162 iconVLC = QIcon( ":/logo/vlc128.png" );
1163 sysTray = new QSystemTrayIcon( iconVLC, this );
1164 sysTray->setToolTip( qtr( "VLC media player" ));
1166 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
1167 systrayMenu->setIcon( iconVLC );
1169 QVLCMenu::updateSystrayMenu( this, p_intf, true );
1172 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
1173 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
1177 * Updates the Systray Icon's menu and toggle the main interface
1179 void MainInterface::toggleUpdateSystrayMenu()
1181 /* If hidden, show it */
1187 else if( isMinimized() )
1195 /* Visible (possibly under other windows) */
1197 /* check if any visible window is above vlc in the z-order,
1198 * but ignore the ones always on top
1199 * and the ones which can't be activated */
1202 wi.cbSize = sizeof( WINDOWINFO );
1203 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
1204 hwnd && ( !IsWindowVisible( hwnd ) ||
1205 ( GetWindowInfo( hwnd, &wi ) &&
1206 (wi.dwExStyle&WS_EX_NOACTIVATE) ) );
1207 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
1208 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
1209 (wi.dwExStyle&WS_EX_TOPMOST) )
1221 QVLCMenu::updateSystrayMenu( this, p_intf );
1224 void MainInterface::handleSystrayClick(
1225 QSystemTrayIcon::ActivationReason reason )
1229 case QSystemTrayIcon::Trigger:
1230 case QSystemTrayIcon::DoubleClick:
1231 toggleUpdateSystrayMenu();
1233 case QSystemTrayIcon::MiddleClick:
1234 sysTray->showMessage( qtr( "VLC media player" ),
1235 qtr( "Control menu for the player" ),
1236 QSystemTrayIcon::Information, 3000 );
1244 * Updates the name of the systray Icon tooltip.
1245 * Doesn't check if the systray exists, check before you call it.
1247 void MainInterface::updateSystrayTooltipName( const QString& name )
1249 if( name.isEmpty() )
1251 sysTray->setToolTip( qtr( "VLC media player" ) );
1255 sysTray->setToolTip( name );
1256 if( notificationEnabled && ( isHidden() || isMinimized() ) )
1258 sysTray->showMessage( qtr( "VLC media player" ), name,
1259 QSystemTrayIcon::NoIcon, 3000 );
1263 QVLCMenu::updateSystrayMenu( this, p_intf );
1267 * Updates the status of the systray Icon tooltip.
1268 * Doesn't check if the systray exists, check before you call it.
1270 void MainInterface::updateSystrayTooltipStatus( int i_status )
1277 sysTray->setToolTip( qtr( "VLC media player" ) );
1282 sysTray->setToolTip( input_name );
1287 sysTray->setToolTip( input_name + " - "
1292 QVLCMenu::updateSystrayMenu( this, p_intf );
1296 /************************************************************************
1298 ************************************************************************/
1299 void MainInterface::dropEvent(QDropEvent *event)
1301 dropEventPlay( event, true );
1304 void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
1306 event->setDropAction( Qt::CopyAction );
1307 if( !event->possibleActions() & Qt::CopyAction )
1310 const QMimeData *mimeData = event->mimeData();
1312 /* D&D of a subtitles file, add it on the fly */
1313 if( mimeData->urls().size() == 1 && THEMIM->getIM()->hasInput() )
1315 if( !input_AddSubtitle( THEMIM->getInput(),
1316 qtu( toNativeSeparators( mimeData->urls()[0].toLocalFile() ) ),
1324 bool first = b_play;
1325 foreach( const QUrl &url, mimeData->urls() )
1327 QString s = toNativeSeparators( url.toLocalFile() );
1329 if( s.length() > 0 ) {
1330 char* psz_uri = make_URI( qtu(s) );
1331 playlist_Add( THEPL, psz_uri, NULL,
1332 PLAYLIST_APPEND | (first ? PLAYLIST_GO: PLAYLIST_PREPARSE),
1333 PLAYLIST_END, true, pl_Unlocked );
1336 RecentsMRL::getInstance( p_intf )->addRecent( s );
1341 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1343 event->acceptProposedAction();
1345 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1347 event->acceptProposedAction();
1349 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1354 /************************************************************************
1356 ************************************************************************/
1357 void MainInterface::customEvent( QEvent *event )
1360 if( event->type() == PLDockEvent_Type )
1362 PlaylistDialog::killInstance();
1363 playlistEmbeddedFlag = true;
1365 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1370 if ( event->type() == (int)SetVideoOnTopEvent_Type )
1372 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1373 if( p_event->OnTop() )
1374 setWindowFlags( windowFlags() | Qt::WindowStaysOnTopHint );
1376 setWindowFlags( windowFlags() & ~Qt::WindowStaysOnTopHint );
1377 show(); /* necessary to apply window flags */
1381 void MainInterface::keyPressEvent( QKeyEvent *e )
1383 handleKeyPress( e );
1386 void MainInterface::handleKeyPress( QKeyEvent *e )
1388 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() == Qt::Key_H )
1389 && !menuBar()->isVisible() )
1391 toggleMinimalView( false );
1395 int i_vlck = qtEventToVLCKey( e );
1398 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1405 void MainInterface::resizeEvent( QResizeEvent * event )
1410 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
1411 i_visualmode == QT_MINIMAL_MODE )
1413 mainVideoSize = size();
1417 if( VISIBLE( bgWidget) ||
1418 ( videoIsActive && videoWidget->isVisible() )
1420 mainVideoSize = size();
1422 mainBasedSize = size();
1426 QVLCMW::resizeEvent( event );
1427 msg_Warn( p_intf, "%i", size().height() );
1430 void MainInterface::wheelEvent( QWheelEvent *e )
1432 int i_vlckey = qtWheelEventToVLCKey( e );
1433 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1437 void MainInterface::closeEvent( QCloseEvent *e )
1444 void MainInterface::toggleFullScreen( void )
1446 if( isFullScreen() )
1449 emit askUpdate(); // Needed if video was launched after the F11
1450 emit fullscreenInterfaceToggled( false );
1455 emit fullscreenInterfaceToggled( true );
1460 //moc doesn't know about #ifdef, so we have to build this method for every platform
1461 void MainInterface::changeThumbbarButtons( int i_status)
1464 // Define an array of two buttons. These buttons provide images through an
1465 // image list and also provide tooltips.
1466 DWORD dwMask = THB_BITMAP | THB_FLAGS;
1468 THUMBBUTTON thbButtons[3];
1470 thbButtons[0].dwMask = dwMask;
1471 thbButtons[0].iId = 0;
1472 thbButtons[0].iBitmap = 0;
1475 thbButtons[1].dwMask = dwMask;
1476 thbButtons[1].iId = 1;
1479 thbButtons[2].dwMask = dwMask;
1480 thbButtons[2].iId = 2;
1481 thbButtons[2].iBitmap = 3;
1488 thbButtons[0].dwFlags = THBF_HIDDEN;
1489 thbButtons[1].dwFlags = THBF_HIDDEN;
1490 thbButtons[2].dwFlags = THBF_HIDDEN;
1495 thbButtons[0].dwFlags = THBF_ENABLED;
1496 thbButtons[1].dwFlags = THBF_ENABLED;
1497 thbButtons[2].dwFlags = THBF_ENABLED;
1498 thbButtons[1].iBitmap = 1;
1503 //thbButtons[0].dwFlags = THBF_ENABLED;
1504 //thbButtons[1].dwFlags = THBF_ENABLED;
1505 //thbButtons[2].dwFlags = THBF_ENABLED;
1506 thbButtons[1].iBitmap = 2;
1511 HRESULT hr = p_taskbl->vt->ThumbBarUpdateButtons(p_taskbl, GetForegroundWindow(), 3, thbButtons);
1513 msg_Err( p_intf, "ThumbBarUpdateButtons failed with error %08x", hr );
1519 /*****************************************************************************
1520 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1521 * We don't show the menu directly here because we don't want the
1522 * caller to block for a too long time.
1523 *****************************************************************************/
1524 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1525 vlc_value_t old_val, vlc_value_t new_val, void *param )
1527 intf_thread_t *p_intf = (intf_thread_t *)param;
1529 if( p_intf->pf_show_dialog )
1531 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1532 new_val.b_bool, NULL );
1538 /*****************************************************************************
1539 * IntfShowCB: callback triggered by the intf-show libvlc variable.
1540 *****************************************************************************/
1541 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1542 vlc_value_t old_val, vlc_value_t new_val, void *param )
1544 intf_thread_t *p_intf = (intf_thread_t *)param;
1545 p_intf->p_sys->p_mi->toggleFSC();