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& ) );
278 /* Final sizing and showing */
279 setMinimumWidth( __MAX( controls->sizeHint().width(),
280 menuBar()->sizeHint().width() ) );
281 setVisible( !b_shouldHide );
283 /* And switch to minimal view if needed
284 Must be called after the show() */
285 if( i_visualmode == QT_MINIMAL_MODE )
286 toggleMinimalView( true );
288 /* Update the geometry : It is useful if you switch between
291 resize( sizeHint() );
294 createTaskBarButtons();
298 MainInterface::~MainInterface()
300 msg_Dbg( p_intf, "Destroying the main interface" );
302 /* Unsure we hide the videoWidget before destroying it */
303 if( videoIsActive ) videoWidget->hide();
305 /* Save playlist state */
309 QVLCTools::saveWidgetPosition( p_intf, "Playlist", playlistWidget );
311 delete playlistWidget;
316 ImageList_Destroy( himl );
318 p_taskbl->vt->Release(p_taskbl);
322 /* Be sure to kill the actionsManager... FIXME */
323 ActionsManager::killInstance();
325 /* Delete the FSC controller */
326 delete fullscreenControls;
329 settings->beginGroup( "MainWindow" );
330 settings->setValue( "pl-dock-status", (int)i_pl_dock );
331 settings->setValue( "playlist-visible", (int)playlistVisible );
332 settings->setValue( "adv-controls",
333 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
335 settings->setValue( "mainBasedSize", mainBasedSize );
336 settings->setValue( "mainVideoSize", mainVideoSize );
339 settings->setValue( "backgroundSize", bgWidget->size() );
342 QVLCTools::saveWidgetPosition(settings, this);
343 settings->endGroup();
346 /* Unregister callbacks */
347 var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
348 var_DelCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
350 p_intf->p_sys->p_mi = NULL;
353 /*****************************
355 *****************************/
356 void MainInterface::recreateToolbars()
358 msg_Dbg( p_intf, "Recreating the toolbars" );
359 settings->beginGroup( "MainWindow" );
362 controls = new ControlsWidget( p_intf, false, this ); /* FIXME */
363 CONNECT( controls, advancedControlsToggled( bool ),
364 this, doComponentsUpdate() );
365 CONNECT( controls, sizeChanged(),
366 this, doComponentsUpdate() );
367 inputC = new InputControlsWidget( p_intf, this );
369 mainLayout->insertWidget( 2, inputC );
370 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
372 settings->endGroup();
375 void MainInterface::createMainWidget( QSettings *settings )
377 /* Create the main Widget and the mainLayout */
378 QWidget *main = new QWidget;
379 setCentralWidget( main );
380 mainLayout = new QVBoxLayout( main );
382 /* Margins, spacing */
383 main->setContentsMargins( 0, 0, 0, 0 );
384 main->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
385 mainLayout->setSpacing( 0 );
386 mainLayout->setMargin( 0 );
389 /* Disabled for now, they SUCK */
391 visualSelector = new VisualSelector( p_intf );
392 mainLayout->insertWidget( 0, visualSelector );
393 visualSelector->hide();
396 QStackedWidget *stackCentralW = new QStackedWidget( main );
398 bgWidget = new BackgroundWidget( p_intf );
400 settings->value( "backgroundSize", QSize( 300, 200 ) ).toSize() );
401 bgWidget->updateGeometry();
403 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
404 i_visualmode != QT_MINIMAL_MODE )
408 stackCentralW->addWidget( bgWidget );
410 /* And video Outputs */
411 if( videoEmbeddedFlag )
413 videoWidget = new VideoWidget( p_intf );
414 stackCentralW->addWidget( videoWidget );
417 /* Create the CONTROLS Widget */
418 controls = new ControlsWidget( p_intf,
419 settings->value( "adv-controls", false ).toBool(), this );
420 CONNECT( controls, advancedControlsToggled( bool ),
421 this, doComponentsUpdate() );
422 CONNECT( controls, sizeChanged(),
423 this, doComponentsUpdate() );
424 inputC = new InputControlsWidget( p_intf, this );
426 mainLayout->insertWidget( 1, stackCentralW, 10 );
428 //mainLayout->setRowStretch( 1, 10 );
429 mainLayout->insertWidget( 2, inputC );
430 mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
433 /* Finish the sizing */
434 main->updateGeometry();
436 getSettings()->endGroup();
440 /* Create the FULLSCREEN CONTROLS Widget */
441 if( config_GetInt( p_intf, "qt-fs-controller" ) )
443 fullscreenControls = new FullscreenControllerWidget( p_intf, this );
444 CONNECT( fullscreenControls, keyPressed( QKeyEvent * ),
445 this, handleKeyPress( QKeyEvent * ) );
449 inline void MainInterface::createStatusBar()
454 /* Widgets Creation*/
455 QStatusBar *statusBarr = statusBar();
457 TimeLabel *timeLabel = new TimeLabel( p_intf );
458 nameLabel = new QLabel( this );
459 nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
460 | Qt::TextSelectableByKeyboard );
461 SpeedLabel *speedLabel = new SpeedLabel( p_intf, "1.00x", this );
463 /* Styling those labels */
464 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
465 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
466 nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
468 /* and adding those */
469 statusBarr->addWidget( nameLabel, 8 );
470 statusBarr->addPermanentWidget( speedLabel, 0 );
471 statusBarr->addPermanentWidget( timeLabel, 0 );
473 /* timeLabel behaviour:
474 - double clicking opens the goto time dialog
475 - right-clicking and clicking just toggle between remaining and
477 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
479 CONNECT( THEMIM->getIM(), encryptionChanged( bool ),
480 this, showCryptedLabel( bool ) );
484 void MainInterface::createTaskBarButtons()
486 /*Here is the code for the taskbar thumb buttons
487 FIXME:We need pretty buttons in 16x16 px that are handled correctly by masks in Qt
488 FIXME:the play button's picture doesn't changed to pause when clicked
490 OSVERSIONINFO winVer;
491 winVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
492 if( GetVersionEx(&winVer) && winVer.dwMajorVersion > 5 )
494 if(himl = ImageList_Create( 15, //cx
497 4,//initial nb of images
498 0//nb of images that can be added
501 QPixmap img = QPixmap(":/toolbar/previous_b");
502 QPixmap img2 = QPixmap(":/toolbar/pause_b");
503 QPixmap img3 = QPixmap(":/toolbar/play_b");
504 QPixmap img4 = QPixmap(":/toolbar/next_b");
505 QBitmap mask = img.createMaskFromColor(Qt::transparent);
506 QBitmap mask2 = img2.createMaskFromColor(Qt::transparent);
507 QBitmap mask3 = img3.createMaskFromColor(Qt::transparent);
508 QBitmap mask4 = img4.createMaskFromColor(Qt::transparent);
510 if(-1 == ImageList_Add(himl, img.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask.toWinHBITMAP()))
511 msg_Err( p_intf, "ImageList_Add failed" );
512 if(-1 == ImageList_Add(himl, img2.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask2.toWinHBITMAP()))
513 msg_Err( p_intf, "ImageList_Add failed" );
514 if(-1 == ImageList_Add(himl, img3.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask3.toWinHBITMAP()))
515 msg_Err( p_intf, "ImageList_Add failed" );
516 if(-1 == ImageList_Add(himl, img4.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask4.toWinHBITMAP()))
517 msg_Err( p_intf, "ImageList_Add failed" );
522 if( S_OK == CoCreateInstance( &clsid_ITaskbarList,
523 NULL, CLSCTX_INPROC_SERVER,
525 (void **)&p_taskbl) )
527 p_taskbl->vt->HrInit(p_taskbl);
529 int msg_value = RegisterWindowMessage("TaskbarButtonCreated");
530 //msg_Info( p_intf, "msg value: %04x", msg_value );
532 // Define an array of two buttons. These buttons provide images through an
533 // image list and also provide tooltips.
534 DWORD dwMask = THB_BITMAP | THB_FLAGS;
536 THUMBBUTTON thbButtons[2];
537 thbButtons[0].dwMask = dwMask;
538 thbButtons[0].iId = 0;
539 thbButtons[0].iBitmap = 0;
540 thbButtons[0].dwFlags = THBF_HIDDEN;
542 thbButtons[1].dwMask = dwMask;
543 thbButtons[1].iId = 1;
544 thbButtons[1].iBitmap = 2;
545 thbButtons[1].dwFlags = THBF_HIDDEN;
547 thbButtons[2].dwMask = dwMask;
548 thbButtons[2].iId = 2;
549 thbButtons[2].iBitmap = 3;
550 thbButtons[2].dwFlags = THBF_HIDDEN;
552 HRESULT hr = p_taskbl->vt->ThumbBarSetImageList(p_taskbl, GetForegroundWindow(), himl );
554 msg_Err( p_intf, "ThumbBarSetImageList failed with error %08x", hr );
555 if(S_OK != p_taskbl->vt->ThumbBarAddButtons(p_taskbl, GetForegroundWindow(), 3, thbButtons))
556 msg_Err( p_intf, "ThumbBarAddButtons failed with error %08x", GetLastError() );
558 CONNECT( THEMIM->getIM(), statusChanged( int ), this, changeThumbbarButtons( int ) );
570 inline void MainInterface::initSystray()
573 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
574 bool b_systrayWanted = config_GetInt( p_intf, "qt-system-tray" );
576 if( config_GetInt( p_intf, "qt-start-minimized") > 0 )
578 if( b_systrayAvailable )
580 b_systrayWanted = true;
584 msg_Err( p_intf, "cannot start minimized without system tray bar" );
587 if( b_systrayAvailable && b_systrayWanted )
592 inline void MainInterface::askForPrivacy()
596 * Ask for the network policy on FIRST STARTUP
598 if( config_GetInt( p_intf, "qt-privacy-ask") )
600 QList<ConfigControl *> controls;
601 if( privacyDialog( &controls ) == QDialog::Accepted )
603 QList<ConfigControl *>::Iterator i;
604 for( i = controls.begin() ; i != controls.end() ; i++ )
606 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
607 c->doApply( p_intf );
610 config_PutInt( p_intf, "qt-privacy-ask" , 0 );
611 /* We have to save here because the user may not launch Prefs */
612 config_SaveConfigFile( p_intf, NULL );
618 int MainInterface::privacyDialog( QList<ConfigControl *> *controls )
620 QDialog *privacy = new QDialog( this );
622 privacy->setWindowTitle( qtr( "Privacy and Network Policies" ) );
623 privacy->setWindowRole( "vlc-privacy" );
625 QGridLayout *gLayout = new QGridLayout( privacy );
627 QGroupBox *blabla = new QGroupBox( qtr( "Privacy and Network Warning" ) );
628 QGridLayout *blablaLayout = new QGridLayout( blabla );
629 QLabel *text = new QLabel( qtr(
630 "<p>The <i>VideoLAN Team</i> doesn't like when an application goes "
631 "online without authorization.</p>\n "
632 "<p><i>VLC media player</i> can retreive limited information from "
633 "the Internet in order to get CD covers or to check "
634 "for available updates.</p>\n"
635 "<p><i>VLC media player</i> <b>DOES NOT</b> send or collect <b>ANY</b> "
636 "information, even anonymously, about your usage.</p>\n"
637 "<p>Therefore please select from the following options, the default being "
638 "almost no access to the web.</p>\n") );
639 text->setWordWrap( true );
640 text->setTextFormat( Qt::RichText );
642 blablaLayout->addWidget( text, 0, 0 ) ;
644 QGroupBox *options = new QGroupBox;
645 QGridLayout *optionsLayout = new QGridLayout( options );
647 gLayout->addWidget( blabla, 0, 0, 1, 3 );
648 gLayout->addWidget( options, 1, 0, 1, 3 );
649 module_config_t *p_config;
650 ConfigControl *control;
653 #define CONFIG_GENERIC( option, type ) \
654 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
657 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
658 p_config, options, false, optionsLayout, line ); \
659 controls->append( control ); \
662 #define CONFIG_GENERIC_NOBOOL( option, type ) \
663 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
666 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
667 p_config, options, optionsLayout, line ); \
668 controls->append( control ); \
671 CONFIG_GENERIC( "album-art", IntegerList ); line++;
673 CONFIG_GENERIC_NOBOOL( "qt-updates-notif", Bool ); line++;
676 QPushButton *ok = new QPushButton( qtr( "OK" ) );
678 gLayout->addWidget( ok, 2, 2 );
680 CONNECT( ok, clicked(), privacy, accept() );
681 return privacy->exec();
685 /**********************************************************************
686 * Handling of sizing of the components
687 **********************************************************************/
689 /* This function is probably wrong, but we don't have many many choices...
690 Since we can't know from the playlist Widget if we are inside a dock or not,
691 because the playlist Widget can be called by THEDP, as a separate windows for
693 Maybe the other solution is to redefine the sizeHint() of the playlist and
694 ask _parent->isFloating()...
695 If you think this would be better, please FIXME it...
698 QSize MainInterface::sizeHint() const
702 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
703 i_visualmode == QT_MINIMAL_MODE )
705 return mainVideoSize;
709 if( VISIBLE( bgWidget) ||
710 ( videoIsActive && videoWidget->isVisible() )
712 return mainVideoSize;
714 return mainBasedSize;
718 int nwidth = controls->sizeHint().width();
719 int nheight = controls->isVisible() ?
720 controls->size().height()
721 + inputC->size().height()
722 + menuBar()->size().height()
723 + statusBar()->size().height()
726 if( VISIBLE( bgWidget ) )
729 nheight += i_bg_height;
731 nheight += bgWidget->size().height();
732 nwidth = __MAX( nwidth, bgWidget->size().width() );
734 else if( videoIsActive && videoWidget->isVisible() )
736 nheight += videoWidget->sizeHint().height();
737 nwidth = __MAX( nwidth, videoWidget->sizeHint().width() );
740 if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget() )
742 nheight += dockPL->size().height();
743 nwidth = __MAX( nwidth, dockPL->size().width() );
744 msg_Warn( p_intf, "3 %i %i", nheight, nwidth );
747 return QSize( nwidth, nheight );
750 /* Video widget cannot do this synchronously as it runs in another thread */
751 /* Well, could it, actually ? Probably dangerous ... */
753 /* This function is called:
754 - toggling of minimal View
755 - through askUpdate() by Vout thread request video and resize video (zoom)
756 - Advanced buttons toggled
758 void MainInterface::doComponentsUpdate()
760 if( isFullScreen() || isMaximized() ) return;
762 msg_Dbg( p_intf, "Updating the geometry" );
763 /* Here we resize to sizeHint() and not adjustsize because we want
764 the videoWidget to be exactly the correctSize */
765 resize( sizeHint() );
772 void MainInterface::debug()
775 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
776 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
777 if( videoWidget && videoWidget->isVisible() )
779 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
780 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
785 void MainInterface::destroyPopupMenu()
787 QVLCMenu::PopupMenu(p_intf, false );
791 void MainInterface::toggleFSC()
793 if( !fullscreenControls ) return;
795 IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
796 QApplication::postEvent( fullscreenControls, eShow );
799 void MainInterface::popupMenu( const QPoint &p )
801 /* Ow, that's ugly: don't show the popup menu if cursor over
802 * the main menu bar or the status bar */
803 if( !childAt( p ) || ( ( childAt( p ) != menuBar() )
804 && ( childAt( p )->parentWidget() != statusBar() ) ) )
805 QVLCMenu::PopupMenu( p_intf, true );
808 /****************************************************************************
810 ****************************************************************************/
812 /* This event is used to deal with the fullscreen and always on top
813 issue conflict (bug in wx) */
814 class SetVideoOnTopQtEvent : public QEvent
817 SetVideoOnTopQtEvent( bool _onTop ) :
818 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
821 bool OnTop() const { return onTop; }
829 * You must note change the state of this object or other Qt4 UI objects,
830 * from the video output thread - only from the Qt4 UI main loop thread.
831 * All window provider queries must be handled through signals or events.
832 * That's why we have all those emit statements...
834 WId MainInterface::getVideo( int *pi_x, int *pi_y,
835 unsigned int *pi_width, unsigned int *pi_height )
840 /* This is a blocking call signal. Results are returned through pointers.
841 * Beware of deadlocks! */
843 emit askGetVideo( &id, pi_x, pi_y, pi_width, pi_height );
847 void MainInterface::getVideoSlot( WId *p_id, int *pi_x, int *pi_y,
848 unsigned *pi_width, unsigned *pi_height )
850 /* Request the videoWidget */
851 WId ret = videoWidget->request( pi_x, pi_y,
852 pi_width, pi_height, b_keep_size );
854 if( ret ) /* The videoWidget is available */
856 /* Did we have a bg ? Hide it! */
857 if( VISIBLE( bgWidget) )
863 bgWasVisible = false;
865 /* ask videoWidget to show */
866 videoWidget->SetSizing( *pi_width, *pi_height );
868 /* Consider the video active now */
869 videoIsActive = true;
875 /* Asynchronous call from the WindowClose function */
876 void MainInterface::releaseVideo( void )
878 emit askReleaseVideo( );
881 /* Function that is CONNECTED to the previous emit */
882 void MainInterface::releaseVideoSlot( void )
884 videoWidget->release( );
888 /* Reset the bg state */
889 bgWasVisible = false;
893 videoIsActive = false;
895 /* Try to resize, except when you are in Fullscreen mode */
896 doComponentsUpdate();
899 /* Asynchronous call from WindowControl function */
900 int MainInterface::controlVideo( int i_query, va_list args )
904 case VOUT_WINDOW_SET_SIZE:
906 unsigned int i_width = va_arg( args, unsigned int );
907 unsigned int i_height = va_arg( args, unsigned int );
908 emit askVideoToResize( i_width, i_height );
912 case VOUT_WINDOW_SET_ON_TOP:
914 int i_arg = va_arg( args, int );
915 QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
918 case VOUT_WINDOW_SET_FULLSCREEN:
920 bool b_fs = va_arg( args, int );
921 emit askVideoSetFullScreen( b_fs );
925 msg_Warn( p_intf, "unsupported control query" );
930 /*****************************************************************************
931 * Playlist, Visualisation and Menus handling
932 *****************************************************************************/
934 * Toggle the playlist widget or dialog
936 void MainInterface::togglePlaylist()
939 If no playlist exist, then create one and attach it to the DockPL*/
940 if( !playlistWidget )
942 playlistWidget = new PlaylistWidget( p_intf );
944 i_pl_dock = PL_UNDOCKED;
945 /* i_pl_dock = (pl_dock_e)getSettings()
946 ->value( "pl-dock-status", PL_UNDOCKED ).toInt(); */
948 if( i_pl_dock == PL_UNDOCKED )
950 playlistWidget->setWindowFlags( Qt::Window );
952 /* This will restore the geometry but will not work for position,
953 because of parenting */
954 QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
955 playlistWidget, QSize( 600, 300 ) );
959 // mainLayout->insertWidget( 4, playlistWidget );
961 playlistVisible = true;
963 playlistWidget->show();
967 /* toggle the visibility of the playlist */
968 //TOGGLEV( playlistWidget );
970 if( playlistWidget->isVisible() && !playlistWidget->isMinimized() )
972 playlistWidget->hide();
976 playlistWidget->setWindowState(
977 playlistWidget->windowState() & ~Qt::WindowMinimized | Qt::WindowActive);
978 playlistWidget->show();
981 playlistVisible = !playlistVisible;
982 //doComponentsUpdate(); //resize( sizeHint() );
986 /* Function called from the menu to undock the playlist */
987 void MainInterface::undockPlaylist()
989 // dockPL->setFloating( true );
993 void MainInterface::dockPlaylist( pl_dock_e i_pos )
997 void MainInterface::toggleMinimalView( bool b_switch )
999 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
1000 i_visualmode != QT_MINIMAL_MODE )
1001 { /* NORMAL MODE then */
1002 if( !videoWidget || videoWidget->isHidden() )
1008 /* If video is visible, then toggle the status of bgWidget */
1009 bgWasVisible = !bgWasVisible;
1013 i_bg_height = bgWidget->height();
1015 menuBar()->setVisible( !b_switch );
1016 controls->setVisible( !b_switch );
1017 statusBar()->setVisible( !b_switch );
1018 inputC->setVisible( !b_switch );
1020 doComponentsUpdate();
1022 emit minimalViewToggled( b_switch );
1025 /* toggling advanced controls buttons */
1026 void MainInterface::toggleAdvanced()
1028 controls->toggleAdvanced();
1029 // if( fullscreenControls ) fullscreenControls->toggleAdvanced();
1032 /* Get the visibility status of the controls (hidden or not, advanced or not) */
1033 int MainInterface::getControlsVisibilityStatus()
1035 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
1036 + CONTROLS_ADVANCED * controls->b_advancedVisible );
1040 void MainInterface::visual()
1042 if( !VISIBLE( visualSelector) )
1044 visualSelector->show();
1045 if( !THEMIM->getIM()->hasVideo() )
1047 /* Show the background widget */
1049 visualSelectorEnabled = true;
1053 /* Stop any currently running visualization */
1054 visualSelector->hide();
1055 visualSelectorEnabled = false;
1057 doComponentsUpdate();
1061 /************************************************************************
1063 ************************************************************************/
1064 void MainInterface::setName( const QString& name )
1066 input_name = name; /* store it for the QSystray use */
1067 /* Display it in the status bar, but also as a Tooltip in case it doesn't
1069 nameLabel->setText( " " + name + " " );
1070 nameLabel->setToolTip( " " + name +" " );
1074 * Give the decorations of the Main Window a correct Name.
1075 * If nothing is given, set it to VLC...
1077 void MainInterface::setVLCWindowsTitle( const QString& aTitle )
1079 if( aTitle.isEmpty() )
1081 setWindowTitle( qtr( "VLC media player" ) );
1085 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
1089 void MainInterface::showCryptedLabel( bool b_show )
1091 if( cryptedLabel == NULL )
1093 cryptedLabel = new QLabel;
1094 // The lock icon is not the right one for DRM protection/scrambled.
1095 //cryptedLabel->setPixmap( QPixmap( ":/lock" ) );
1096 cryptedLabel->setText( "DRM" );
1097 statusBar()->addWidget( cryptedLabel );
1100 cryptedLabel->setVisible( b_show );
1103 /*****************************************************************************
1104 * Systray Icon and Systray Menu
1105 *****************************************************************************/
1108 * Create a SystemTray icon and a menu that would go with it.
1109 * Connects to a click handler on the icon.
1111 void MainInterface::createSystray()
1114 if( QDate::currentDate().dayOfYear() >= 354 )
1115 iconVLC = QIcon( ":/logo/vlc128-christmas.png" );
1117 iconVLC = QIcon( ":/logo/vlc128.png" );
1118 sysTray = new QSystemTrayIcon( iconVLC, this );
1119 sysTray->setToolTip( qtr( "VLC media player" ));
1121 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
1122 systrayMenu->setIcon( iconVLC );
1124 QVLCMenu::updateSystrayMenu( this, p_intf, true );
1127 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
1128 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
1132 * Updates the Systray Icon's menu and toggle the main interface
1134 void MainInterface::toggleUpdateSystrayMenu()
1136 /* If hidden, show it */
1142 else if( isMinimized() )
1150 /* Visible (possibly under other windows) */
1152 /* check if any visible window is above vlc in the z-order,
1153 * but ignore the ones always on top
1154 * and the ones which can't be activated */
1157 wi.cbSize = sizeof( WINDOWINFO );
1158 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
1159 hwnd && ( !IsWindowVisible( hwnd ) ||
1160 ( GetWindowInfo( hwnd, &wi ) &&
1161 (wi.dwExStyle&WS_EX_NOACTIVATE) ) );
1162 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
1163 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
1164 (wi.dwExStyle&WS_EX_TOPMOST) )
1176 QVLCMenu::updateSystrayMenu( this, p_intf );
1179 void MainInterface::handleSystrayClick(
1180 QSystemTrayIcon::ActivationReason reason )
1184 case QSystemTrayIcon::Trigger:
1185 case QSystemTrayIcon::DoubleClick:
1186 toggleUpdateSystrayMenu();
1188 case QSystemTrayIcon::MiddleClick:
1189 sysTray->showMessage( qtr( "VLC media player" ),
1190 qtr( "Control menu for the player" ),
1191 QSystemTrayIcon::Information, 3000 );
1199 * Updates the name of the systray Icon tooltip.
1200 * Doesn't check if the systray exists, check before you call it.
1202 void MainInterface::updateSystrayTooltipName( const QString& name )
1204 if( name.isEmpty() )
1206 sysTray->setToolTip( qtr( "VLC media player" ) );
1210 sysTray->setToolTip( name );
1211 if( notificationEnabled && ( isHidden() || isMinimized() ) )
1213 sysTray->showMessage( qtr( "VLC media player" ), name,
1214 QSystemTrayIcon::NoIcon, 3000 );
1218 QVLCMenu::updateSystrayMenu( this, p_intf );
1222 * Updates the status of the systray Icon tooltip.
1223 * Doesn't check if the systray exists, check before you call it.
1225 void MainInterface::updateSystrayTooltipStatus( int i_status )
1232 sysTray->setToolTip( qtr( "VLC media player" ) );
1237 sysTray->setToolTip( input_name );
1242 sysTray->setToolTip( input_name + " - "
1247 QVLCMenu::updateSystrayMenu( this, p_intf );
1251 /************************************************************************
1253 ************************************************************************/
1254 void MainInterface::dropEvent(QDropEvent *event)
1256 dropEventPlay( event, true );
1259 void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
1261 event->setDropAction( Qt::CopyAction );
1262 if( !event->possibleActions() & Qt::CopyAction )
1265 const QMimeData *mimeData = event->mimeData();
1267 /* D&D of a subtitles file, add it on the fly */
1268 if( mimeData->urls().size() == 1 && THEMIM->getIM()->hasInput() )
1270 if( !input_AddSubtitle( THEMIM->getInput(),
1271 qtu( toNativeSeparators( mimeData->urls()[0].toLocalFile() ) ),
1279 bool first = b_play;
1280 foreach( const QUrl &url, mimeData->urls() )
1282 QString s = toNativeSeparators( url.toLocalFile() );
1284 if( s.length() > 0 ) {
1285 char* psz_uri = make_URI( qtu(s) );
1286 playlist_Add( THEPL, psz_uri, NULL,
1287 PLAYLIST_APPEND | (first ? PLAYLIST_GO: PLAYLIST_PREPARSE),
1288 PLAYLIST_END, true, pl_Unlocked );
1291 RecentsMRL::getInstance( p_intf )->addRecent( s );
1296 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1298 event->acceptProposedAction();
1300 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1302 event->acceptProposedAction();
1304 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1309 /************************************************************************
1311 ************************************************************************/
1312 void MainInterface::customEvent( QEvent *event )
1315 if( event->type() == PLDockEvent_Type )
1317 PlaylistDialog::killInstance();
1318 playlistEmbeddedFlag = true;
1320 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1325 if ( event->type() == (int)SetVideoOnTopEvent_Type )
1327 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1328 if( p_event->OnTop() )
1329 setWindowFlags( windowFlags() | Qt::WindowStaysOnTopHint );
1331 setWindowFlags( windowFlags() & ~Qt::WindowStaysOnTopHint );
1332 show(); /* necessary to apply window flags */
1336 void MainInterface::keyPressEvent( QKeyEvent *e )
1338 handleKeyPress( e );
1341 void MainInterface::handleKeyPress( QKeyEvent *e )
1343 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() == Qt::Key_H )
1344 && !menuBar()->isVisible() )
1346 toggleMinimalView( false );
1350 int i_vlck = qtEventToVLCKey( e );
1353 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1360 void MainInterface::resizeEvent( QResizeEvent * event )
1364 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
1365 i_visualmode == QT_MINIMAL_MODE )
1367 mainVideoSize = size();
1371 if( VISIBLE( bgWidget) ||
1372 ( videoIsActive && videoWidget->isVisible() )
1374 mainVideoSize = size();
1376 mainBasedSize = size();
1381 void MainInterface::wheelEvent( QWheelEvent *e )
1383 int i_vlckey = qtWheelEventToVLCKey( e );
1384 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1388 void MainInterface::closeEvent( QCloseEvent *e )
1395 void MainInterface::toggleFullScreen( void )
1397 if( isFullScreen() )
1400 emit askUpdate(); // Needed if video was launched after the F11
1401 emit fullscreenInterfaceToggled( false );
1406 emit fullscreenInterfaceToggled( true );
1411 //moc doesn't know about #ifdef, so we have to build this method for every platform
1412 void MainInterface::changeThumbbarButtons( int i_status)
1415 // Define an array of two buttons. These buttons provide images through an
1416 // image list and also provide tooltips.
1417 DWORD dwMask = THB_BITMAP | THB_FLAGS;
1419 THUMBBUTTON thbButtons[3];
1421 thbButtons[0].dwMask = dwMask;
1422 thbButtons[0].iId = 0;
1423 thbButtons[0].iBitmap = 0;
1426 thbButtons[1].dwMask = dwMask;
1427 thbButtons[1].iId = 1;
1430 thbButtons[2].dwMask = dwMask;
1431 thbButtons[2].iId = 2;
1432 thbButtons[2].iBitmap = 3;
1439 thbButtons[0].dwFlags = THBF_HIDDEN;
1440 thbButtons[1].dwFlags = THBF_HIDDEN;
1441 thbButtons[2].dwFlags = THBF_HIDDEN;
1446 thbButtons[0].dwFlags = THBF_ENABLED;
1447 thbButtons[1].dwFlags = THBF_ENABLED;
1448 thbButtons[2].dwFlags = THBF_ENABLED;
1449 thbButtons[1].iBitmap = 1;
1454 //thbButtons[0].dwFlags = THBF_ENABLED;
1455 //thbButtons[1].dwFlags = THBF_ENABLED;
1456 //thbButtons[2].dwFlags = THBF_ENABLED;
1457 thbButtons[1].iBitmap = 2;
1462 HRESULT hr = p_taskbl->vt->ThumbBarUpdateButtons(p_taskbl, GetForegroundWindow(), 3, thbButtons);
1464 msg_Err( p_intf, "ThumbBarUpdateButtons failed with error %08x", hr );
1470 /*****************************************************************************
1471 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1472 * We don't show the menu directly here because we don't want the
1473 * caller to block for a too long time.
1474 *****************************************************************************/
1475 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1476 vlc_value_t old_val, vlc_value_t new_val, void *param )
1478 intf_thread_t *p_intf = (intf_thread_t *)param;
1480 if( p_intf->pf_show_dialog )
1482 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1483 new_val.b_bool, NULL );
1489 /*****************************************************************************
1490 * IntfShowCB: callback triggered by the intf-show libvlc variable.
1491 *****************************************************************************/
1492 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
1493 vlc_value_t old_val, vlc_value_t new_val, void *param )
1495 intf_thread_t *p_intf = (intf_thread_t *)param;
1496 p_intf->p_sys->p_mi->toggleFSC();