1 /*****************************************************************************
2 * main_interface.cpp : Main interface
3 ****************************************************************************
4 * Copyright (C) 2006-2009 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Jean-Baptiste Kempf <jb@videolan.org>
9 * Ilkka Ollakka <ileoo@videolan.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
32 #include "main_interface.hpp"
33 #include "input_manager.hpp"
34 #include "actions_manager.hpp"
36 #include "util/customwidgets.hpp"
37 #include "util/qt_dirs.hpp"
39 #include "components/interface_widgets.hpp"
40 #include "components/controller.hpp"
41 #include "components/playlist/playlist.hpp"
42 #include "dialogs/external.hpp"
45 #include "recents.hpp"
47 #include <QCloseEvent>
59 #include <QPushButton>
62 #include <vlc_windows_interfaces.h>
68 #include <vlc_keys.h> /* Wheel event */
69 #include <vlc_vout_window.h>
72 /* Callback prototypes */
73 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
74 vlc_value_t old_val, vlc_value_t new_val, void *param );
75 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
76 vlc_value_t old_val, vlc_value_t new_val, void *param );
78 MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
80 /* Variables initialisation */
81 // need_components_update = false;
84 playlistWidget = NULL;
86 videoIsActive = false;
87 playlistVisible = false;
89 fullscreenControls = NULL;
102 * Configuration and settings
103 * Pre-building of interface
106 setFocusPolicy( Qt::StrongFocus );
107 setAcceptDrops( true );
108 setWindowRole( "vlc-main" );
109 setWindowIcon( QApplication::windowIcon() );
110 setWindowOpacity( config_GetFloat( p_intf, "qt-opacity" ) );
112 /* Set The Video In emebedded Mode or not */
113 videoEmbeddedFlag = config_GetInt( p_intf, "embedded-video" );
115 /* Does the interface resize to video size or the opposite */
116 b_keep_size = !config_GetInt( p_intf, "qt-video-autoresize" );
118 /* Are we in the enhanced always-video mode or not ? */
119 i_visualmode = config_GetInt( p_intf, "qt-display-mode" );
121 /* Set the other interface settings */
122 settings = getSettings();
123 settings->beginGroup( "MainWindow" );
126 * Retrieve saved sizes for main window
127 * mainBasedSize = based window size for normal mode
128 * (no video, no background)
129 * mainVideoSize = window size with video (all modes)
131 mainBasedSize = settings->value( "mainBasedSize", QSize( 350, 120 ) ).toSize();
132 mainVideoSize = settings->value( "mainVideoSize", QSize( 400, 300 ) ).toSize();
134 /* Do we want anoying popups or not */
135 notificationEnabled = (bool)config_GetInt( p_intf, "qt-notification" );
142 /**************************
143 * UI and Widgets design
144 **************************/
145 setVLCWindowsTitle();
146 createMainWidget( settings );
151 QVLCMenu::createMenuBar( this, p_intf );
152 CONNECT( THEMIM->getIM(), voutListChanged( vout_thread_t **, int ),
153 this, destroyPopupMenu() );
156 /* Create a Dock to get the playlist */
157 dockPL = new QDockWidget( qtr( "Playlist" ), this );
158 dockPL->setSizePolicy( QSizePolicy::Preferred,
159 QSizePolicy::Expanding );
160 dockPL->setFeatures( QDockWidget::AllDockWidgetFeatures );
161 dockPL->setAllowedAreas( Qt::LeftDockWidgetArea
162 | Qt::RightDockWidgetArea
163 | Qt::BottomDockWidgetArea );
167 /********************
169 ********************/
170 MainInputManager::getInstance( p_intf );
172 /*********************************
173 * Create the Systray Management *
174 *********************************/
177 /**************************
178 * Various CONNECTs on IM *
179 **************************/
180 /* Connect the input manager to the GUI elements it manages */
183 * Connects on nameChanged()
184 * Those connects are not merged because different options can trigger
187 /* Naming in the controller statusbar */
188 CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
189 this, setName( const QString& ) );
190 /* and in the systray */
193 CONNECT( THEMIM->getIM(), nameChanged( const QString& ), this,
194 updateSystrayTooltipName( const QString& ) );
196 /* and in the title of the controller */
197 if( config_GetInt( p_intf, "qt-name-in-title" ) )
199 CONNECT( THEMIM->getIM(), nameChanged( const QString& ), this,
200 setVLCWindowsTitle( const QString& ) );
204 * CONNECTS on PLAY_STATUS
206 /* Status on the systray */
209 CONNECT( THEMIM->getIM(), statusChanged( int ),
210 this, updateSystrayTooltipStatus( int ) );
214 /* END CONNECTS ON IM */
219 var_AddCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
221 /* Register callback for the intf-popupmenu variable */
222 var_AddCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
225 /* VideoWidget connects for asynchronous calls */
226 connect( this, SIGNAL(askGetVideo(WId*,int*,int*,unsigned*,unsigned *)),
227 this, SLOT(getVideoSlot(WId*,int*,int*,unsigned*,unsigned*)),
228 Qt::BlockingQueuedConnection );
229 connect( this, SIGNAL(askReleaseVideo( void )),
230 this, SLOT(releaseVideoSlot( void )),
231 Qt::BlockingQueuedConnection );
235 CONNECT( this, askVideoToResize( unsigned int, unsigned int ),
236 videoWidget, SetSizing( unsigned int, unsigned int ) );
237 CONNECT( this, askVideoSetFullScreen( bool ),
238 videoWidget, SetFullScreen( bool ) );
239 CONNECT( videoWidget, keyPressed( QKeyEvent * ),
240 this, handleKeyPress( QKeyEvent * ) );
243 CONNECT( this, askUpdate(), this, doComponentsUpdate() );
244 CONNECT( THEDP, toolBarConfUpdated(), this, recreateToolbars() );
246 /* Size and placement of interface */
247 settings->beginGroup( "MainWindow" );
248 QVLCTools::restoreWidgetPosition( settings, this, QSize(380, 60) );
250 /* resize to previously saved main window size if appicable */
253 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
254 i_visualmode == QT_MINIMAL_MODE )
256 resize( mainVideoSize );
260 resize( mainBasedSize );
264 bool b_visible = settings->value( "playlist-visible", 0 ).toInt();
265 settings->endGroup();
268 if( b_visible ) togglePlaylist();
270 /* Enable the popup menu in the MI */
271 setContextMenuPolicy( Qt::CustomContextMenu );
272 CONNECT( this, customContextMenuRequested( const QPoint& ),
273 this, popupMenu( const QPoint& ) );
275 /* Final sizing and showing */
276 setMinimumWidth( __MAX( controls->sizeHint().width(),
277 menuBar()->sizeHint().width() ) );
278 setVisible( !b_shouldHide );
280 /* And switch to minimal view if needed
281 Must be called after the show() */
282 if( i_visualmode == QT_MINIMAL_MODE )
283 toggleMinimalView( true );
285 /* Update the geometry : It is useful if you switch between
288 resize( sizeHint() );
291 createTaskBarButtons();
295 MainInterface::~MainInterface()
297 msg_Dbg( p_intf, "Destroying the main interface" );
299 /* Unsure we hide the videoWidget before destroying it */
300 if( videoIsActive ) videoWidget->hide();
302 /* Save playlist state */
306 QVLCTools::saveWidgetPosition( p_intf, "Playlist", playlistWidget );
308 delete playlistWidget;
313 ImageList_Destroy( himl );
315 p_taskbl->vt->Release(p_taskbl);
319 /* Be sure to kill the actionsManager... FIXME */
320 ActionsManager::killInstance();
322 /* Delete the FSC controller */
323 delete fullscreenControls;
326 settings->beginGroup( "MainWindow" );
327 settings->setValue( "pl-dock-status", (int)i_pl_dock );
328 settings->setValue( "playlist-visible", (int)playlistVisible );
329 settings->setValue( "adv-controls",
330 getControlsVisibilityStatus() & CONTROLS_ADVANCED );
332 settings->setValue( "mainBasedSize", mainBasedSize );
333 settings->setValue( "mainVideoSize", mainVideoSize );
336 settings->setValue( "backgroundSize", bgWidget->size() );
339 QVLCTools::saveWidgetPosition(settings, this);
340 settings->endGroup();
343 /* Unregister callbacks */
344 var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
345 var_DelCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
347 p_intf->p_sys->p_mi = NULL;
350 /*****************************
352 *****************************/
353 void MainInterface::recreateToolbars()
355 msg_Dbg( p_intf, "Recreating the toolbars" );
356 settings->beginGroup( "MainWindow" );
359 controls = new ControlsWidget( p_intf, false, this ); /* FIXME */
360 CONNECT( controls, advancedControlsToggled( bool ),
361 this, doComponentsUpdate() );
362 CONNECT( controls, sizeChanged(),
363 this, doComponentsUpdate() );
364 inputC = new InputControlsWidget( p_intf, this );
366 mainLayout->addWidget( inputC, 2, 0, 1, -1, Qt::AlignBottom );
367 mainLayout->addWidget( controls, settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
368 0, 1, -1, Qt::AlignBottom );
369 settings->endGroup();
372 void MainInterface::createMainWidget( QSettings *settings )
374 /* Create the main Widget and the mainLayout */
375 QWidget *main = new QWidget;
376 setCentralWidget( main );
377 mainLayout = new QGridLayout( main );
379 /* Margins, spacing */
380 main->setContentsMargins( 0, 0, 0, 0 );
381 main->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
382 mainLayout->setSpacing( 0 );
383 mainLayout->setMargin( 0 );
386 /* Disabled for now, they SUCK */
388 visualSelector = new VisualSelector( p_intf );
389 mainLayout->insertWidget( 0, visualSelector );
390 visualSelector->hide();
394 bgWidget = new BackgroundWidget( p_intf );
396 settings->value( "backgroundSize", QSize( 300, 200 ) ).toSize() );
397 bgWidget->updateGeometry();
399 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
400 i_visualmode != QT_MINIMAL_MODE )
405 /* And video Outputs */
406 if( videoEmbeddedFlag )
407 videoWidget = new VideoWidget( p_intf );
409 /* Create the CONTROLS Widget */
410 controls = new ControlsWidget( p_intf,
411 settings->value( "adv-controls", false ).toBool(), this );
412 CONNECT( controls, advancedControlsToggled( bool ),
413 this, doComponentsUpdate() );
414 CONNECT( controls, sizeChanged(),
415 this, doComponentsUpdate() );
416 inputC = new InputControlsWidget( p_intf, this );
419 /* Add the controls Widget to the main Widget */
421 mainLayout->addWidget( videoWidget, 0, 0, 1, -1 );
422 mainLayout->setRowStretch( 0, 10 );
424 mainLayout->addWidget( bgWidget, 1, 0, 1, -1 );
425 //mainLayout->setRowStretch( 1, 10 );
426 mainLayout->addWidget( inputC, 2, 0, 1, -1, Qt::AlignBottom );
427 mainLayout->addWidget( controls, settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
428 0, 1, -1, Qt::AlignBottom );
430 /* Finish the sizing */
431 main->updateGeometry();
433 getSettings()->endGroup();
437 /* Create the FULLSCREEN CONTROLS Widget */
438 if( config_GetInt( p_intf, "qt-fs-controller" ) )
440 fullscreenControls = new FullscreenControllerWidget( p_intf, this );
441 CONNECT( fullscreenControls, keyPressed( QKeyEvent * ),
442 this, handleKeyPress( QKeyEvent * ) );
446 inline void MainInterface::createStatusBar()
451 /* Widgets Creation*/
452 QStatusBar *statusBarr = statusBar();
454 TimeLabel *timeLabel = new TimeLabel( p_intf );
455 nameLabel = new QLabel( this );
456 nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
457 | Qt::TextSelectableByKeyboard );
458 SpeedLabel *speedLabel = new SpeedLabel( p_intf, "1.00x", this );
460 /* Styling those labels */
461 timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
462 speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
463 nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
465 /* and adding those */
466 statusBarr->addWidget( nameLabel, 8 );
467 statusBarr->addPermanentWidget( speedLabel, 0 );
468 statusBarr->addPermanentWidget( timeLabel, 0 );
470 /* timeLabel behaviour:
471 - double clicking opens the goto time dialog
472 - right-clicking and clicking just toggle between remaining and
474 CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
476 CONNECT( THEMIM->getIM(), encryptionChanged( bool ),
477 this, showCryptedLabel( bool ) );
481 void MainInterface::createTaskBarButtons()
483 /*Here is the code for the taskbar thumb buttons
484 FIXME:We need pretty buttons in 16x16 px that are handled correctly by masks in Qt
485 FIXME:the play button's picture doesn't changed to pause when clicked
487 OSVERSIONINFO winVer;
488 winVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
489 if( GetVersionEx(&winVer) && winVer.dwMajorVersion > 5 && winVer.dwMajorVersion > 0 )
491 if(himl = ImageList_Create( 15, //cx
494 4,//initial nb of images
495 0//nb of images that can be added
498 QPixmap img = QPixmap(":/toolbar/previous_b");
499 QPixmap img2 = QPixmap(":/toolbar/pause_b");
500 QPixmap img3 = QPixmap(":/toolbar/play_b");
501 QPixmap img4 = QPixmap(":/toolbar/next_b");
502 QBitmap mask = img.createMaskFromColor(Qt::transparent);
503 QBitmap mask2 = img2.createMaskFromColor(Qt::transparent);
504 QBitmap mask3 = img3.createMaskFromColor(Qt::transparent);
505 QBitmap mask4 = img4.createMaskFromColor(Qt::transparent);
507 if(-1 == ImageList_Add(himl, img.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask.toWinHBITMAP()))
508 msg_Err( p_intf, "ImageList_Add failed" );
509 if(-1 == ImageList_Add(himl, img2.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask2.toWinHBITMAP()))
510 msg_Err( p_intf, "ImageList_Add failed" );
511 if(-1 == ImageList_Add(himl, img3.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask3.toWinHBITMAP()))
512 msg_Err( p_intf, "ImageList_Add failed" );
513 if(-1 == ImageList_Add(himl, img4.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask4.toWinHBITMAP()))
514 msg_Err( p_intf, "ImageList_Add failed" );
519 if( S_OK == CoCreateInstance( &clsid_ITaskbarList,
520 NULL, CLSCTX_INPROC_SERVER,
522 (void **)&p_taskbl) )
524 p_taskbl->vt->HrInit(p_taskbl);
526 int msg_value = RegisterWindowMessage("TaskbarButtonCreated");
527 //msg_Info( p_intf, "msg value: %04x", msg_value );
529 // Define an array of two buttons. These buttons provide images through an
530 // image list and also provide tooltips.
531 DWORD dwMask = THB_BITMAP | THB_FLAGS;
533 THUMBBUTTON thbButtons[2];
534 thbButtons[0].dwMask = dwMask;
535 thbButtons[0].iId = 0;
536 thbButtons[0].iBitmap = 0;
537 thbButtons[0].dwFlags = THBF_HIDDEN;
539 thbButtons[1].dwMask = dwMask;
540 thbButtons[1].iId = 1;
541 thbButtons[1].iBitmap = 2;
542 thbButtons[1].dwFlags = THBF_HIDDEN;
544 thbButtons[2].dwMask = dwMask;
545 thbButtons[2].iId = 2;
546 thbButtons[2].iBitmap = 3;
547 thbButtons[2].dwFlags = THBF_HIDDEN;
549 HRESULT hr = p_taskbl->vt->ThumbBarSetImageList(p_taskbl, GetForegroundWindow(), himl );
551 msg_Err( p_intf, "ThumbBarSetImageList failed with error %08x", hr );
552 if(S_OK != p_taskbl->vt->ThumbBarAddButtons(p_taskbl, GetForegroundWindow(), 3, thbButtons))
553 msg_Err( p_intf, "ThumbBarAddButtons failed with error %08x", GetLastError() );
555 CONNECT( THEMIM->getIM(), statusChanged( int ), this, changeThumbbarButtons( int ) );
567 inline void MainInterface::initSystray()
569 bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
570 bool b_systrayWanted = config_GetInt( p_intf, "qt-system-tray" );
572 if( config_GetInt( p_intf, "qt-start-minimized") > 0 )
574 if( b_systrayAvailable )
576 b_systrayWanted = true;
580 msg_Err( p_intf, "cannot start minimized without system tray bar" );
583 if( b_systrayAvailable && b_systrayWanted )
587 inline void MainInterface::askForPrivacy()
590 * Ask for the network policy on FIRST STARTUP
592 if( config_GetInt( p_intf, "qt-privacy-ask") )
594 QList<ConfigControl *> controls;
595 if( privacyDialog( &controls ) == QDialog::Accepted )
597 QList<ConfigControl *>::Iterator i;
598 for( i = controls.begin() ; i != controls.end() ; i++ )
600 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
601 c->doApply( p_intf );
604 config_PutInt( p_intf, "qt-privacy-ask" , 0 );
605 /* We have to save here because the user may not launch Prefs */
606 config_SaveConfigFile( p_intf, NULL );
611 int MainInterface::privacyDialog( QList<ConfigControl *> *controls )
613 QDialog *privacy = new QDialog( this );
615 privacy->setWindowTitle( qtr( "Privacy and Network Policies" ) );
616 privacy->setWindowRole( "vlc-privacy" );
618 QGridLayout *gLayout = new QGridLayout( privacy );
620 QGroupBox *blabla = new QGroupBox( qtr( "Privacy and Network Warning" ) );
621 QGridLayout *blablaLayout = new QGridLayout( blabla );
622 QLabel *text = new QLabel( qtr(
623 "<p>The <i>VideoLAN Team</i> doesn't like when an application goes "
624 "online without authorization.</p>\n "
625 "<p><i>VLC media player</i> can retreive limited information from "
626 "the Internet in order to get CD covers or to check "
627 "for available updates.</p>\n"
628 "<p><i>VLC media player</i> <b>DOES NOT</b> send or collect <b>ANY</b> "
629 "information, even anonymously, about your usage.</p>\n"
630 "<p>Therefore please select from the following options, the default being "
631 "almost no access to the web.</p>\n") );
632 text->setWordWrap( true );
633 text->setTextFormat( Qt::RichText );
635 blablaLayout->addWidget( text, 0, 0 ) ;
637 QGroupBox *options = new QGroupBox;
638 QGridLayout *optionsLayout = new QGridLayout( options );
640 gLayout->addWidget( blabla, 0, 0, 1, 3 );
641 gLayout->addWidget( options, 1, 0, 1, 3 );
642 module_config_t *p_config;
643 ConfigControl *control;
646 #define CONFIG_GENERIC( option, type ) \
647 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
650 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
651 p_config, options, false, optionsLayout, line ); \
652 controls->append( control ); \
655 #define CONFIG_GENERIC_NOBOOL( option, type ) \
656 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
659 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
660 p_config, options, optionsLayout, line ); \
661 controls->append( control ); \
664 CONFIG_GENERIC( "album-art", IntegerList ); line++;
666 CONFIG_GENERIC_NOBOOL( "qt-updates-notif", Bool ); line++;
669 QPushButton *ok = new QPushButton( qtr( "OK" ) );
671 gLayout->addWidget( ok, 2, 2 );
673 CONNECT( ok, clicked(), privacy, accept() );
674 return privacy->exec();
678 /**********************************************************************
679 * Handling of sizing of the components
680 **********************************************************************/
682 /* This function is probably wrong, but we don't have many many choices...
683 Since we can't know from the playlist Widget if we are inside a dock or not,
684 because the playlist Widget can be called by THEDP, as a separate windows for
686 Maybe the other solution is to redefine the sizeHint() of the playlist and
687 ask _parent->isFloating()...
688 If you think this would be better, please FIXME it...
691 QSize MainInterface::sizeHint() const
695 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
696 i_visualmode == QT_MINIMAL_MODE )
698 return mainVideoSize;
702 if( VISIBLE( bgWidget) ||
703 ( videoIsActive && videoWidget->isVisible() )
705 return mainVideoSize;
707 return mainBasedSize;
711 int nwidth = controls->sizeHint().width();
712 int nheight = controls->isVisible() ?
713 controls->size().height()
714 + inputC->size().height()
715 + menuBar()->size().height()
716 + statusBar()->size().height()
719 if( VISIBLE( bgWidget ) )
722 nheight += i_bg_height;
724 nheight += bgWidget->size().height();
725 nwidth = __MAX( nwidth, bgWidget->size().width() );
727 else if( videoIsActive && videoWidget->isVisible() )
729 nheight += videoWidget->sizeHint().height();
730 nwidth = __MAX( nwidth, videoWidget->sizeHint().width() );
733 if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget() )
735 nheight += dockPL->size().height();
736 nwidth = __MAX( nwidth, dockPL->size().width() );
737 msg_Warn( p_intf, "3 %i %i", nheight, nwidth );
740 return QSize( nwidth, nheight );
743 /* Video widget cannot do this synchronously as it runs in another thread */
744 /* Well, could it, actually ? Probably dangerous ... */
746 /* This function is called:
747 - toggling of minimal View
748 - through askUpdate() by Vout thread request video and resize video (zoom)
749 - Advanced buttons toggled
751 void MainInterface::doComponentsUpdate()
753 if( isFullScreen() || isMaximized() ) return;
755 msg_Dbg( p_intf, "Updating the geometry" );
756 /* Here we resize to sizeHint() and not adjustsize because we want
757 the videoWidget to be exactly the correctSize */
758 resize( sizeHint() );
765 void MainInterface::debug()
768 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
769 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
770 if( videoWidget && videoWidget->isVisible() )
772 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
773 msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
778 void MainInterface::destroyPopupMenu()
780 QVLCMenu::PopupMenu(p_intf, false );
784 void MainInterface::toggleFSC()
786 if( !fullscreenControls ) return;
788 IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
789 QApplication::postEvent( fullscreenControls, eShow );
792 void MainInterface::popupMenu( const QPoint &p )
794 /* Ow, that's ugly: don't show the popup menu if cursor over
795 * the main menu bar or the status bar */
796 if( !childAt( p ) || ( ( childAt( p ) != menuBar() )
797 && ( childAt( p )->parentWidget() != statusBar() ) ) )
798 QVLCMenu::PopupMenu( p_intf, true );
801 /****************************************************************************
803 ****************************************************************************/
805 /* This event is used to deal with the fullscreen and always on top
806 issue conflict (bug in wx) */
807 class SetVideoOnTopQtEvent : public QEvent
810 SetVideoOnTopQtEvent( bool _onTop ) :
811 QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
814 bool OnTop() const { return onTop; }
822 * You must note change the state of this object or other Qt4 UI objects,
823 * from the video output thread - only from the Qt4 UI main loop thread.
824 * All window provider queries must be handled through signals or events.
825 * That's why we have all those emit statements...
827 WId MainInterface::getVideo( int *pi_x, int *pi_y,
828 unsigned int *pi_width, unsigned int *pi_height )
833 /* This is a blocking call signal. Results are returned through pointers.
834 * Beware of deadlocks! */
836 emit askGetVideo( &id, pi_x, pi_y, pi_width, pi_height );
840 void MainInterface::getVideoSlot( WId *p_id, int *pi_x, int *pi_y,
841 unsigned *pi_width, unsigned *pi_height )
843 /* Request the videoWidget */
844 WId ret = videoWidget->request( pi_x, pi_y,
845 pi_width, pi_height, b_keep_size );
847 if( ret ) /* The videoWidget is available */
849 /* Did we have a bg ? Hide it! */
850 if( VISIBLE( bgWidget) )
856 bgWasVisible = false;
858 /* ask videoWidget to show */
859 videoWidget->SetSizing( *pi_width, *pi_height );
861 /* Consider the video active now */
862 videoIsActive = true;
868 /* Asynchronous call from the WindowClose function */
869 void MainInterface::releaseVideo( void )
871 emit askReleaseVideo( );
874 /* Function that is CONNECTED to the previous emit */
875 void MainInterface::releaseVideoSlot( void )
877 videoWidget->release( );
881 /* Reset the bg state */
882 bgWasVisible = false;
886 videoIsActive = false;
888 /* Try to resize, except when you are in Fullscreen mode */
889 doComponentsUpdate();
892 /* Asynchronous call from WindowControl function */
893 int MainInterface::controlVideo( int i_query, va_list args )
897 case VOUT_WINDOW_SET_SIZE:
899 unsigned int i_width = va_arg( args, unsigned int );
900 unsigned int i_height = va_arg( args, unsigned int );
901 emit askVideoToResize( i_width, i_height );
905 case VOUT_WINDOW_SET_ON_TOP:
907 int i_arg = va_arg( args, int );
908 QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
911 case VOUT_WINDOW_SET_FULLSCREEN:
913 bool b_fs = va_arg( args, int );
914 emit askVideoSetFullScreen( b_fs );
918 msg_Warn( p_intf, "unsupported control query" );
923 /*****************************************************************************
924 * Playlist, Visualisation and Menus handling
925 *****************************************************************************/
927 * Toggle the playlist widget or dialog
929 void MainInterface::togglePlaylist()
932 If no playlist exist, then create one and attach it to the DockPL*/
933 if( !playlistWidget )
935 playlistWidget = new PlaylistWidget( p_intf );
937 i_pl_dock = PL_UNDOCKED;
938 /* i_pl_dock = (pl_dock_e)getSettings()
939 ->value( "pl-dock-status", PL_UNDOCKED ).toInt(); */
941 if( i_pl_dock == PL_UNDOCKED )
943 playlistWidget->setWindowFlags( Qt::Window );
945 /* This will restore the geometry but will not work for position,
946 because of parenting */
947 QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
948 playlistWidget, QSize( 600, 300 ) );
952 // mainLayout->insertWidget( 4, playlistWidget );
954 playlistVisible = true;
956 playlistWidget->show();
960 /* toggle the visibility of the playlist */
961 TOGGLEV( playlistWidget );
962 playlistVisible = !playlistVisible;
963 //doComponentsUpdate(); //resize( sizeHint() );
967 /* Function called from the menu to undock the playlist */
968 void MainInterface::undockPlaylist()
970 // dockPL->setFloating( true );
974 void MainInterface::dockPlaylist( pl_dock_e i_pos )
978 void MainInterface::toggleMinimalView( bool b_switch )
980 if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
981 i_visualmode != QT_MINIMAL_MODE )
982 { /* NORMAL MODE then */
983 if( !videoWidget || videoWidget->isHidden() )
989 /* If video is visible, then toggle the status of bgWidget */
990 bgWasVisible = !bgWasVisible;
994 i_bg_height = bgWidget->height();
996 menuBar()->setVisible( !b_switch );
997 controls->setVisible( !b_switch );
998 statusBar()->setVisible( !b_switch );
999 inputC->setVisible( !b_switch );
1001 doComponentsUpdate();
1003 emit minimalViewToggled( b_switch );
1006 /* toggling advanced controls buttons */
1007 void MainInterface::toggleAdvanced()
1009 controls->toggleAdvanced();
1010 // if( fullscreenControls ) fullscreenControls->toggleAdvanced();
1013 /* Get the visibility status of the controls (hidden or not, advanced or not) */
1014 int MainInterface::getControlsVisibilityStatus()
1016 return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
1017 + CONTROLS_ADVANCED * controls->b_advancedVisible );
1021 void MainInterface::visual()
1023 if( !VISIBLE( visualSelector) )
1025 visualSelector->show();
1026 if( !THEMIM->getIM()->hasVideo() )
1028 /* Show the background widget */
1030 visualSelectorEnabled = true;
1034 /* Stop any currently running visualization */
1035 visualSelector->hide();
1036 visualSelectorEnabled = false;
1038 doComponentsUpdate();
1042 /************************************************************************
1044 ************************************************************************/
1045 void MainInterface::setName( const QString& name )
1047 input_name = name; /* store it for the QSystray use */
1048 /* Display it in the status bar, but also as a Tooltip in case it doesn't
1050 nameLabel->setText( " " + name + " " );
1051 nameLabel->setToolTip( " " + name +" " );
1055 * Give the decorations of the Main Window a correct Name.
1056 * If nothing is given, set it to VLC...
1058 void MainInterface::setVLCWindowsTitle( const QString& aTitle )
1060 if( aTitle.isEmpty() )
1062 setWindowTitle( qtr( "VLC media player" ) );
1066 setWindowTitle( aTitle + " - " + qtr( "VLC media player" ) );
1070 void MainInterface::showCryptedLabel( bool b_show )
1072 if( cryptedLabel == NULL )
1074 cryptedLabel = new QLabel;
1075 // The lock icon is not the right one for DRM protection/scrambled.
1076 //cryptedLabel->setPixmap( QPixmap( ":/lock" ) );
1077 cryptedLabel->setText( "DRM" );
1078 statusBar()->addWidget( cryptedLabel );
1081 cryptedLabel->setVisible( b_show );
1084 /*****************************************************************************
1085 * Systray Icon and Systray Menu
1086 *****************************************************************************/
1089 * Create a SystemTray icon and a menu that would go with it.
1090 * Connects to a click handler on the icon.
1092 void MainInterface::createSystray()
1095 if( QDate::currentDate().dayOfYear() >= 354 )
1096 iconVLC = QIcon( QPixmap( ":/logo/vlc128-christmas.png" ) );
1098 iconVLC = QIcon( QPixmap( ":/logo/vlc128.png" ) );
1099 sysTray = new QSystemTrayIcon( iconVLC, this );
1100 sysTray->setToolTip( qtr( "VLC media player" ));
1102 systrayMenu = new QMenu( qtr( "VLC media player" ), this );
1103 systrayMenu->setIcon( iconVLC );
1105 QVLCMenu::updateSystrayMenu( this, p_intf, true );
1108 CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
1109 this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
1113 * Updates the Systray Icon's menu and toggle the main interface
1115 void MainInterface::toggleUpdateSystrayMenu()
1117 /* If hidden, show it */
1123 else if( isMinimized() )
1131 /* Visible (possibly under other windows) */
1133 /* check if any visible window is above vlc in the z-order,
1134 * but ignore the ones always on top
1135 * and the ones which can't be activated */
1138 wi.cbSize = sizeof( WINDOWINFO );
1139 for( hwnd = GetNextWindow( internalWinId(), GW_HWNDPREV );
1140 hwnd && ( !IsWindowVisible( hwnd ) ||
1141 ( GetWindowInfo( hwnd, &wi ) &&
1142 (wi.dwExStyle&WS_EX_NOACTIVATE) ) );
1143 hwnd = GetNextWindow( hwnd, GW_HWNDPREV ) );
1144 if( !hwnd || !GetWindowInfo( hwnd, &wi ) ||
1145 (wi.dwExStyle&WS_EX_TOPMOST) )
1157 QVLCMenu::updateSystrayMenu( this, p_intf );
1160 void MainInterface::handleSystrayClick(
1161 QSystemTrayIcon::ActivationReason reason )
1165 case QSystemTrayIcon::Trigger:
1166 case QSystemTrayIcon::DoubleClick:
1167 toggleUpdateSystrayMenu();
1169 case QSystemTrayIcon::MiddleClick:
1170 sysTray->showMessage( qtr( "VLC media player" ),
1171 qtr( "Control menu for the player" ),
1172 QSystemTrayIcon::Information, 3000 );
1180 * Updates the name of the systray Icon tooltip.
1181 * Doesn't check if the systray exists, check before you call it.
1183 void MainInterface::updateSystrayTooltipName( const QString& name )
1185 if( name.isEmpty() )
1187 sysTray->setToolTip( qtr( "VLC media player" ) );
1191 sysTray->setToolTip( name );
1192 if( notificationEnabled && ( isHidden() || isMinimized() ) )
1194 sysTray->showMessage( qtr( "VLC media player" ), name,
1195 QSystemTrayIcon::NoIcon, 3000 );
1199 QVLCMenu::updateSystrayMenu( this, p_intf );
1203 * Updates the status of the systray Icon tooltip.
1204 * Doesn't check if the systray exists, check before you call it.
1206 void MainInterface::updateSystrayTooltipStatus( int i_status )
1213 sysTray->setToolTip( qtr( "VLC media player" ) );
1218 sysTray->setToolTip( input_name );
1223 sysTray->setToolTip( input_name + " - "
1228 QVLCMenu::updateSystrayMenu( this, p_intf );
1231 /************************************************************************
1233 ************************************************************************/
1234 void MainInterface::dropEvent(QDropEvent *event)
1236 dropEventPlay( event, true );
1239 void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
1241 event->setDropAction( Qt::CopyAction );
1242 if( !event->possibleActions() & Qt::CopyAction )
1245 const QMimeData *mimeData = event->mimeData();
1247 /* D&D of a subtitles file, add it on the fly */
1248 if( mimeData->urls().size() == 1 )
1250 if( THEMIM->getIM()->hasInput() )
1252 if( !input_AddSubtitle( THEMIM->getInput(),
1253 qtu( toNativeSeparators(
1254 mimeData->urls()[0].toLocalFile() ) ),
1262 bool first = b_play;
1263 foreach( const QUrl &url, mimeData->urls() )
1265 QString s = toNativeSeparators( url.toLocalFile() );
1267 if( s.length() > 0 ) {
1268 char* psz_uri = make_URI( qtu(s) );
1269 playlist_Add( THEPL, psz_uri, NULL,
1270 PLAYLIST_APPEND | (first ? PLAYLIST_GO: PLAYLIST_PREPARSE),
1271 PLAYLIST_END, true, pl_Unlocked );
1274 RecentsMRL::getInstance( p_intf )->addRecent( s );
1279 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
1281 event->acceptProposedAction();
1283 void MainInterface::dragMoveEvent(QDragMoveEvent *event)
1285 event->acceptProposedAction();
1287 void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
1292 /************************************************************************
1294 ************************************************************************/
1295 void MainInterface::customEvent( QEvent *event )
1298 if( event->type() == PLDockEvent_Type )
1300 PlaylistDialog::killInstance();
1301 playlistEmbeddedFlag = true;
1303 QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
1308 if ( event->type() == (int)SetVideoOnTopEvent_Type )
1310 SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
1311 if( p_event->OnTop() )
1312 setWindowFlags( windowFlags() | Qt::WindowStaysOnTopHint );
1314 setWindowFlags( windowFlags() & ~Qt::WindowStaysOnTopHint );
1315 show(); /* necessary to apply window flags */
1319 void MainInterface::keyPressEvent( QKeyEvent *e )
1321 handleKeyPress( e );
1324 void MainInterface::handleKeyPress( QKeyEvent *e )
1326 if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() == Qt::Key_H )
1327 && !menuBar()->isVisible() )
1329 toggleMinimalView( false );
1333 int i_vlck = qtEventToVLCKey( e );
1336 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1343 void MainInterface::resizeEvent( QResizeEvent * event )
1347 if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
1348 i_visualmode == QT_MINIMAL_MODE )
1350 mainVideoSize = size();
1354 if( VISIBLE( bgWidget) ||
1355 ( videoIsActive && videoWidget->isVisible() )
1357 mainVideoSize = size();
1359 mainBasedSize = size();
1364 void MainInterface::wheelEvent( QWheelEvent *e )
1366 int i_vlckey = qtWheelEventToVLCKey( e );
1367 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
1371 void MainInterface::closeEvent( QCloseEvent *e )
1378 void MainInterface::toggleFullScreen( void )
1380 if( isFullScreen() )
1383 emit askUpdate(); // Needed if video was launched after the F11
1384 emit fullscreenInterfaceToggled( false );
1389 emit fullscreenInterfaceToggled( true );
1394 //moc doesn't know about #ifdef, so we have to build this method for every platform
1395 void MainInterface::changeThumbbarButtons( int i_status)
1398 // Define an array of two buttons. These buttons provide images through an
1399 // image list and also provide tooltips.
1400 DWORD dwMask = THB_BITMAP | THB_FLAGS;
1402 THUMBBUTTON thbButtons[3];
1404 thbButtons[0].dwMask = dwMask;
1405 thbButtons[0].iId = 0;
1406 thbButtons[0].iBitmap = 0;
1409 thbButtons[1].dwMask = dwMask;
1410 thbButtons[1].iId = 1;
1413 thbButtons[2].dwMask = dwMask;
1414 thbButtons[2].iId = 2;
1415 thbButtons[2].iBitmap = 3;
1422 thbButtons[0].dwFlags = THBF_HIDDEN;
1423 thbButtons[1].dwFlags = THBF_HIDDEN;
1424 thbButtons[2].dwFlags = THBF_HIDDEN;
1429 thbButtons[0].dwFlags = THBF_ENABLED;
1430 thbButtons[1].dwFlags = THBF_ENABLED;
1431 thbButtons[2].dwFlags = THBF_ENABLED;
1432 thbButtons[1].iBitmap = 1;
1437 //thbButtons[0].dwFlags = THBF_ENABLED;
1438 //thbButtons[1].dwFlags = THBF_ENABLED;
1439 //thbButtons[2].dwFlags = THBF_ENABLED;
1440 thbButtons[1].iBitmap = 2;
1445 HRESULT hr = p_taskbl->vt->ThumbBarUpdateButtons(p_taskbl, GetForegroundWindow(), 3, thbButtons);
1447 msg_Err( p_intf, "ThumbBarUpdateButtons failed with error %08x", hr );
1453 /*****************************************************************************
1454 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1455 * We don't show the menu directly here because we don't want the
1456 * caller to block for a too long time.
1457 *****************************************************************************/
1458 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
1459 vlc_value_t old_val, vlc_value_t new_val, void *param )
1461 intf_thread_t *p_intf = (intf_thread_t *)param;
1463 if( p_intf->pf_show_dialog )
1465 p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
1466 new_val.b_bool, NULL );
1472 /*****************************************************************************
1473 * IntfShowCB: callback triggered by the intf-show libvlc variable.
1474 *****************************************************************************/
1475 static int IntfShowCB( 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;
1479 p_intf->p_sys->p_mi->toggleFSC();