1 /*****************************************************************************
2 * main_interface.cpp : Main interface
3 ****************************************************************************
4 * Copyright (C) 2006-2010 VideoLAN and AUTHORS
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 Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
32 #include "main_interface.hpp"
33 #include "input_manager.hpp" // Creation
34 #include "actions_manager.hpp" // killInstance
35 #include "extensions_manager.hpp" // killInstance
37 #include "util/customwidgets.hpp" // qtEventToVLCKey, QVLCStackedWidget
38 #include "util/qt_dirs.hpp" // toNativeSeparators
40 #include "components/interface_widgets.hpp" // bgWidget, videoWidget
41 #include "components/controller.hpp" // controllers
42 #include "components/playlist/playlist.hpp" // plWidget
43 #include "dialogs/firstrun.hpp" // First Run
45 #include "menus.hpp" // Menu creation
46 #include "recents.hpp" // RecentItems when DnD
48 #include <QCloseEvent>
59 #include <QStackedWidget>
61 #include <vlc_keys.h> /* Wheel event */
62 #include <vlc_vout_display.h> /* vout_thread_t and VOUT_ events */
66 /* Callback prototypes */
67 static int PopupMenuCB( vlc_object_t
*p_this
, const char *psz_variable
,
68 vlc_value_t old_val
, vlc_value_t new_val
, void *param
);
69 static int IntfShowCB( vlc_object_t
*p_this
, const char *psz_variable
,
70 vlc_value_t old_val
, vlc_value_t new_val
, void *param
);
72 MainInterface::MainInterface( intf_thread_t
*_p_intf
) : QVLCMW( _p_intf
)
74 /* Variables initialisation */
77 playlistWidget
= NULL
;
78 stackCentralOldWidget
= NULL
;
82 fullscreenControls
= NULL
;
87 b_hideAfterCreation
= false; // --qt-start-minimized
88 playlistVisible
= false;
93 FirstRun::CheckAndRun( this, p_intf
);
96 * Configuration and settings
97 * Pre-building of interface
100 setFocusPolicy( Qt::StrongFocus
);
101 setAcceptDrops( true );
102 setWindowRole( "vlc-main" );
103 setWindowIcon( QApplication::windowIcon() );
104 setWindowOpacity( var_InheritFloat( p_intf
, "qt-opacity" ) );
106 /* Is video in embedded in the UI or not */
107 b_videoEmbedded
= var_InheritBool( p_intf
, "embedded-video" );
109 /* Does the interface resize to video size or the opposite */
110 b_autoresize
= var_InheritBool( p_intf
, "qt-video-autoresize" );
112 /* Are we in the enhanced always-video mode or not ? */
113 b_minimalView
= var_InheritBool( p_intf
, "qt-minimal-view" );
115 /* Do we want anoying popups or not */
116 b_notificationEnabled
= var_InheritBool( p_intf
, "qt-notification" );
118 /* Set the other interface settings */
119 settings
= getSettings();
120 settings
->beginGroup( "MainWindow" );
123 b_plDocked
= getSettings()->value( "pl-dock-status", true ).toBool();
125 settings
->endGroup( );
132 /**************************
133 * UI and Widgets design
134 **************************/
135 setVLCWindowsTitle();
140 QVLCMenu::createMenuBar( this, p_intf
);
141 CONNECT( THEMIM
->getIM(), voutListChanged( vout_thread_t
**, int ),
142 this, destroyPopupMenu() );
144 createMainWidget( settings
);
145 /*********************************
146 * Create the Systray Management *
147 *********************************/
150 /********************
152 ********************/
153 MainInputManager::getInstance( p_intf
);
158 taskbar_wmsg
= RegisterWindowMessage("TaskbarButtonCreated");
161 /************************************************************
162 * Connect the input manager to the GUI elements it manages *
163 ************************************************************/
165 * Connects on nameChanged()
166 * Those connects are different because options can impeach them to trigger.
168 /* Main Interface statusbar */
169 CONNECT( THEMIM
->getIM(), nameChanged( const QString
& ),
170 this, setName( const QString
& ) );
175 CONNECT( THEMIM
->getIM(), nameChanged( const QString
& ),
176 this, updateSystrayTooltipName( const QString
& ) );
179 /* and title of the Main Interface*/
180 if( var_InheritBool( p_intf
, "qt-name-in-title" ) )
182 CONNECT( THEMIM
->getIM(), nameChanged( const QString
& ),
183 this, setVLCWindowsTitle( const QString
& ) );
187 * CONNECTS on PLAY_STATUS
189 /* Status on the systray */
193 CONNECT( THEMIM
->getIM(), statusChanged( int ),
194 this, updateSystrayTooltipStatus( int ) );
198 /* END CONNECTS ON IM */
200 /* VideoWidget connects for asynchronous calls */
201 b_videoFullScreen
= false;
202 b_videoOnTop
= false;
203 connect( this, SIGNAL(askGetVideo(WId
*,int*,int*,unsigned*,unsigned *)),
204 this, SLOT(getVideoSlot(WId
*,int*,int*,unsigned*,unsigned*)),
205 Qt::BlockingQueuedConnection
);
206 connect( this, SIGNAL(askReleaseVideo( void )),
207 this, SLOT(releaseVideoSlot( void )),
208 Qt::BlockingQueuedConnection
);
209 CONNECT( this, askVideoOnTop(bool), this, setVideoOnTop(bool));
215 CONNECT( this, askVideoToResize( unsigned int, unsigned int ),
216 this, setVideoSize( unsigned int, unsigned int ) );
217 CONNECT( videoWidget
, sizeChanged( int, int ),
218 this, resizeStack( int, int ) );
220 CONNECT( this, askVideoSetFullScreen( bool ),
221 this, setVideoFullScreen( bool ) );
224 CONNECT( THEDP
, toolBarConfUpdated(), this, recreateToolbars() );
226 /** END of CONNECTS**/
232 var_AddCallback( p_intf
->p_libvlc
, "intf-show", IntfShowCB
, p_intf
);
234 /* Register callback for the intf-popupmenu variable */
235 var_AddCallback( p_intf
->p_libvlc
, "intf-popupmenu", PopupMenuCB
, p_intf
);
238 int i_plVis
= settings
->value( "MainWindow/playlist-visible", false ).toBool();
240 if( i_plVis
) togglePlaylist();
242 /**** FINAL SIZING and placement of interface */
243 settings
->beginGroup( "MainWindow" );
244 QVLCTools::restoreWidgetPosition( settings
, this, QSize(400, 100) );
245 settings
->endGroup();
247 b_interfaceFullScreen
= isFullScreen();
249 /* Final sizing and showing */
250 setVisible( !b_hideAfterCreation
);
252 setMinimumWidth( __MAX( controls
->sizeHint().width(),
253 menuBar()->sizeHint().width() ) + 30 );
255 /* Switch to minimal view if needed, must be called after the show() */
257 toggleMinimalView( true );
260 MainInterface::~MainInterface()
262 /* Unsure we hide the videoWidget before destroying it */
263 if( stackCentralOldWidget
== videoWidget
)
268 ImageList_Destroy( himl
);
270 p_taskbl
->vt
->Release(p_taskbl
);
274 /* Be sure to kill the actionsManager... Only used in the MI and control */
275 ActionsManager::killInstance();
278 ExtensionsManager::killInstance();
280 /* Delete the FSC controller */
281 delete fullscreenControls
;
284 settings
->beginGroup( "MainWindow" );
286 settings
->setValue( "pl-dock-status", b_plDocked
);
287 /* Save playlist state */
290 settings
->setValue( "playlist-visible",
293 playlistWidget
->isVisible() /* FIXME */ );
296 settings
->setValue( "adv-controls",
297 getControlsVisibilityStatus() & CONTROLS_ADVANCED
);
299 /* Save the stackCentralW sizes */
300 settings
->setValue( "bgSize", stackWidgetsSizes
[bgWidget
] );
301 settings
->setValue( "playlistSize", stackWidgetsSizes
[playlistWidget
] );
304 QVLCTools::saveWidgetPosition(settings
, this);
306 settings
->endGroup();
308 /* Save undocked playlist size */
309 if( playlistWidget
&& !isPlDocked() )
310 QVLCTools::saveWidgetPosition( p_intf
, "Playlist", playlistWidget
);
312 delete playlistWidget
;
316 /* Unregister callbacks */
317 var_DelCallback( p_intf
->p_libvlc
, "intf-show", IntfShowCB
, p_intf
);
318 var_DelCallback( p_intf
->p_libvlc
, "intf-popupmenu", PopupMenuCB
, p_intf
);
320 p_intf
->p_sys
->p_mi
= NULL
;
323 /*****************************
325 *****************************/
326 void MainInterface::recreateToolbars()
328 bool b_adv
= getControlsVisibilityStatus() & CONTROLS_ADVANCED
;
330 settings
->beginGroup( "MainWindow" );
334 controls
= new ControlsWidget( p_intf
, b_adv
, this );
335 inputC
= new InputControlsWidget( p_intf
, this );
337 if( fullscreenControls
)
339 delete fullscreenControls
;
340 fullscreenControls
= new FullscreenControllerWidget( p_intf
, this );
341 CONNECT( fullscreenControls
, keyPressed( QKeyEvent
* ),
342 this, handleKeyPress( QKeyEvent
* ) );
344 mainLayout
->insertWidget( 2, inputC
);
345 mainLayout
->insertWidget( settings
->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
347 settings
->endGroup();
350 void MainInterface::createMainWidget( QSettings
*settings
)
352 /* Create the main Widget and the mainLayout */
353 QWidget
*main
= new QWidget
;
354 setCentralWidget( main
);
355 mainLayout
= new QVBoxLayout( main
);
356 main
->setContentsMargins( 0, 0, 0, 0 );
357 mainLayout
->setSpacing( 0 ); mainLayout
->setMargin( 0 );
360 stackCentralW
= new QVLCStackedWidget( main
);
363 bgWidget
= new BackgroundWidget( p_intf
);
364 stackCentralW
->addWidget( bgWidget
);
366 /* And video Outputs */
367 if( b_videoEmbedded
)
369 videoWidget
= new VideoWidget( p_intf
);
370 stackCentralW
->addWidget( videoWidget
);
372 mainLayout
->insertWidget( 1, stackCentralW
);
374 settings
->beginGroup( "MainWindow" );
375 stackWidgetsSizes
[bgWidget
] = settings
->value( "bgSize", QSize( 400, 0 ) ).toSize();
376 /* Resize even if no-auto-resize, because we are at creation */
377 resizeStack( stackWidgetsSizes
[bgWidget
].width(), stackWidgetsSizes
[bgWidget
].height() );
379 /* Create the CONTROLS Widget */
380 controls
= new ControlsWidget( p_intf
,
381 settings
->value( "adv-controls", false ).toBool(), this );
382 inputC
= new InputControlsWidget( p_intf
, this );
384 mainLayout
->insertWidget( 2, inputC
);
385 mainLayout
->insertWidget( settings
->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
388 /* Visualisation, disabled for now, they SUCK */
390 visualSelector
= new VisualSelector( p_intf
);
391 mainLayout
->insertWidget( 0, visualSelector
);
392 visualSelector
->hide();
395 settings
->endGroup();
397 /* Enable the popup menu in the MI */
398 main
->setContextMenuPolicy( Qt::CustomContextMenu
);
399 CONNECT( main
, customContextMenuRequested( const QPoint
& ),
400 this, popupMenu( const QPoint
& ) );
402 if ( depth() > 8 ) /* 8bit depth has too many issues with opacity */
403 /* Create the FULLSCREEN CONTROLS Widget */
404 if( var_InheritBool( p_intf
, "qt-fs-controller" ) )
406 fullscreenControls
= new FullscreenControllerWidget( p_intf
, this );
407 CONNECT( fullscreenControls
, keyPressed( QKeyEvent
* ),
408 this, handleKeyPress( QKeyEvent
* ) );
412 inline void MainInterface::initSystray()
415 bool b_systrayAvailable
= QSystemTrayIcon::isSystemTrayAvailable();
416 bool b_systrayWanted
= var_InheritBool( p_intf
, "qt-system-tray" );
418 if( var_InheritBool( p_intf
, "qt-start-minimized") )
420 if( b_systrayAvailable
)
422 b_systrayWanted
= true;
423 b_hideAfterCreation
= true;
426 msg_Err( p_intf
, "cannot start minimized without system tray bar" );
429 if( b_systrayAvailable
&& b_systrayWanted
)
434 inline void MainInterface::createStatusBar()
439 /* Widgets Creation*/
440 QStatusBar
*statusBarr
= statusBar();
442 TimeLabel
*timeLabel
= new TimeLabel( p_intf
);
443 nameLabel
= new QLabel( this );
444 nameLabel
->setTextInteractionFlags( Qt::TextSelectableByMouse
445 | Qt::TextSelectableByKeyboard
);
446 SpeedLabel
*speedLabel
= new SpeedLabel( p_intf
, this );
448 /* Styling those labels */
449 timeLabel
->setFrameStyle( QFrame::Sunken
| QFrame::Panel
);
450 speedLabel
->setFrameStyle( QFrame::Sunken
| QFrame::Panel
);
451 nameLabel
->setFrameStyle( QFrame::Sunken
| QFrame::StyledPanel
);
452 timeLabel
->setStyleSheet(
453 "QLabel:hover { background-color: rgba(255, 255, 255, 50%) }" );
454 speedLabel
->setStyleSheet(
455 "QLabel:hover { background-color: rgba(255, 255, 255, 50%) }" );
457 /* and adding those */
458 statusBarr
->addWidget( nameLabel
, 8 );
459 statusBarr
->addPermanentWidget( speedLabel
, 0 );
460 statusBarr
->addPermanentWidget( timeLabel
, 0 );
462 /* timeLabel behaviour:
463 - double clicking opens the goto time dialog
464 - right-clicking and clicking just toggle between remaining and
466 CONNECT( timeLabel
, timeLabelDoubleClicked(), THEDP
, gotoTimeDialog() );
468 CONNECT( THEMIM
->getIM(), encryptionChanged( bool ),
469 this, showCryptedLabel( bool ) );
471 CONNECT( THEMIM
->getIM(), seekRequested( float ),
472 timeLabel
, setDisplayPosition( float ) );
475 /**********************************************************************
476 * Handling of sizing of the components
477 **********************************************************************/
479 void MainInterface::debug()
482 msg_Dbg( p_intf
, "size: %i - %i", size().height(), size().width() );
483 msg_Dbg( p_intf
, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
484 msg_Dbg( p_intf
, "minimumsize: %i - %i", minimumSize().height(), minimumSize().width() );
486 msg_Dbg( p_intf
, "Stack size: %i - %i", stackCentralW
->size().height(), stackCentralW
->size().width() );
487 msg_Dbg( p_intf
, "Stack sizeHint: %i - %i", stackCentralW
->sizeHint().height(), stackCentralW
->sizeHint().width() );
488 msg_Dbg( p_intf
, "Central size: %i - %i", centralWidget()->size().height(), centralWidget()->size().width() );
492 inline void MainInterface::showVideo() { showTab( videoWidget
); }
493 inline void MainInterface::restoreStackOldWidget()
494 { showTab( stackCentralOldWidget
); }
496 inline void MainInterface::showTab( QWidget
*widget
)
499 msg_Warn( p_intf
, "Old stackCentralOldWidget %i", stackCentralW
->indexOf( stackCentralOldWidget
) );
502 stackCentralOldWidget
= stackCentralW
->currentWidget();
503 stackWidgetsSizes
[stackCentralOldWidget
] = stackCentralW
->size();
505 stackCentralW
->setCurrentWidget( widget
);
507 resizeStack( stackWidgetsSizes
[widget
].width(), stackWidgetsSizes
[widget
].height() );
510 msg_Warn( p_intf
, "State change %i", stackCentralW
->currentIndex() );
511 msg_Warn( p_intf
, "New stackCentralOldWidget %i", stackCentralW
->indexOf( stackCentralOldWidget
) );
515 void MainInterface::destroyPopupMenu()
517 QVLCMenu::PopupMenu( p_intf
, false );
520 void MainInterface::popupMenu( const QPoint
&p
)
522 QVLCMenu::PopupMenu( p_intf
, true );
525 void MainInterface::toggleFSC()
527 if( !fullscreenControls
) return;
529 IMEvent
*eShow
= new IMEvent( FullscreenControlToggle_Type
, 0 );
530 QApplication::postEvent( fullscreenControls
, eShow
);
533 /****************************************************************************
535 ****************************************************************************/
539 * You must not change the state of this object or other Qt4 UI objects,
540 * from the video output thread - only from the Qt4 UI main loop thread.
541 * All window provider queries must be handled through signals or events.
542 * That's why we have all those emit statements...
544 WId
MainInterface::getVideo( int *pi_x
, int *pi_y
,
545 unsigned int *pi_width
, unsigned int *pi_height
)
550 /* This is a blocking call signal. Results are returned through pointers.
551 * Beware of deadlocks! */
553 emit
askGetVideo( &id
, pi_x
, pi_y
, pi_width
, pi_height
);
557 void MainInterface::getVideoSlot( WId
*p_id
, int *pi_x
, int *pi_y
,
558 unsigned *pi_width
, unsigned *pi_height
)
560 /* Request the videoWidget */
561 WId ret
= videoWidget
->request( pi_x
, pi_y
,
562 pi_width
, pi_height
, !b_autoresize
);
564 if( ret
) /* The videoWidget is available */
566 /* Consider the video active now */
569 /* Ask videoWidget to resize correctly, if we are in normal mode */
570 if( !isFullScreen() && !isMaximized() && b_autoresize
)
571 videoWidget
->SetSizing( *pi_width
, *pi_height
);
575 /* Asynchronous call from the WindowClose function */
576 void MainInterface::releaseVideo( void )
578 emit
askReleaseVideo();
581 /* Function that is CONNECTED to the previous emit */
582 void MainInterface::releaseVideoSlot( void )
584 videoWidget
->release();
585 setVideoOnTop( false );
586 setVideoFullScreen( false );
588 if( stackCentralW
->currentWidget() == videoWidget
)
589 restoreStackOldWidget();
591 /* We don't want to have a blank video to popup */
592 stackCentralOldWidget
= bgWidget
;
595 void MainInterface::setVideoSize( unsigned int w
, unsigned int h
)
597 if( !isFullScreen() && !isMaximized() )
598 videoWidget
->SetSizing( w
, h
);
601 void MainInterface::setVideoFullScreen( bool fs
)
603 b_videoFullScreen
= fs
;
606 int numscreen
= var_InheritInteger( p_intf
, "qt-fullscreen-screennumber" );
607 /* if user hasn't defined screennumber, or screennumber that is bigger
608 * than current number of screens, take screennumber where current interface
611 if( numscreen
== -1 || numscreen
> QApplication::desktop()->numScreens() )
612 numscreen
= QApplication::desktop()->screenNumber( p_intf
->p_sys
->p_mi
);
614 QRect screenres
= QApplication::desktop()->screenGeometry( numscreen
);
616 /* To be sure window is on proper-screen in xinerama */
618 if( !screenres
.contains( pos() ) && QApplication::desktop()->screenCount() > 1 )
620 if( !screenres
.contains( pos() ) )
623 msg_Dbg( p_intf
, "Moving video to correct screen");
624 move( QPoint( screenres
.x(), screenres
.y() ) );
626 setMinimalView( true );
627 setInterfaceFullScreen( true );
631 /* TODO do we want to restore screen and position ? (when
632 * qt-fullscreen-screennumber is forced) */
633 setMinimalView( b_minimalView
);
634 setInterfaceFullScreen( b_interfaceFullScreen
);
639 /* Slot to change the video always-on-top flag.
640 * Emit askVideoOnTop() to invoke this from other thread. */
641 void MainInterface::setVideoOnTop( bool on_top
)
643 b_videoOnTop
= on_top
;
645 Qt::WindowFlags oldflags
= windowFlags(), newflags
;
648 newflags
= oldflags
| Qt::WindowStaysOnTopHint
;
650 newflags
= oldflags
& ~Qt::WindowStaysOnTopHint
;
652 if( newflags
!= oldflags
)
654 setWindowFlags( newflags
);
655 show(); /* necessary to apply window flags */
659 /* Asynchronous call from WindowControl function */
660 int MainInterface::controlVideo( int i_query
, va_list args
)
664 case VOUT_WINDOW_SET_SIZE
:
666 unsigned int i_width
= va_arg( args
, unsigned int );
667 unsigned int i_height
= va_arg( args
, unsigned int );
669 emit
askVideoToResize( i_width
, i_height
);
672 case VOUT_WINDOW_SET_STATE
:
674 unsigned i_arg
= va_arg( args
, unsigned );
675 unsigned on_top
= i_arg
& VOUT_WINDOW_STATE_ABOVE
;
677 emit
askVideoOnTop( on_top
!= 0 );
680 case VOUT_WINDOW_SET_FULLSCREEN
:
682 bool b_fs
= va_arg( args
, int );
684 emit
askVideoSetFullScreen( b_fs
);
688 msg_Warn( p_intf
, "unsupported control query" );
693 /*****************************************************************************
694 * Playlist, Visualisation and Menus handling
695 *****************************************************************************/
697 * Toggle the playlist widget or dialog
699 void MainInterface::createPlaylist()
701 playlistWidget
= new PlaylistWidget( p_intf
, this );
705 stackCentralW
->addWidget( playlistWidget
);
706 stackWidgetsSizes
[playlistWidget
] = settings
->value( "playlistSize", QSize( 500, 250 ) ).toSize();
711 playlistWidget
->setParent( NULL
);
713 playlistWidget
->setWindowFlags( Qt::Window
);
715 /* This will restore the geometry but will not work for position,
716 because of parenting */
717 QVLCTools::restoreWidgetPosition( p_intf
, "Playlist",
718 playlistWidget
, QSize( 600, 300 ) );
722 void MainInterface::togglePlaylist()
724 if( !playlistWidget
)
731 /* Playlist is not visible, show it */
732 if( stackCentralW
->currentWidget() != playlistWidget
)
734 showTab( playlistWidget
);
738 restoreStackOldWidget();
740 playlistVisible
= ( stackCentralW
->currentWidget() == playlistWidget
);
745 playlistWidget
->setParent( NULL
);
747 playlistWidget
->setWindowFlags( Qt::Window
);
748 playlistVisible
= !playlistVisible
;
749 playlistWidget
->setVisible( playlistVisible
);
754 void MainInterface::dockPlaylist( bool p_docked
)
756 if( b_plDocked
== p_docked
) return;
757 b_plDocked
= p_docked
;
759 if( !playlistWidget
) return; /* Playlist wasn't created yet */
762 stackCentralW
->removeWidget( playlistWidget
);
764 playlistWidget
->setParent( NULL
);
766 playlistWidget
->setWindowFlags( Qt::Window
);
767 QVLCTools::restoreWidgetPosition( p_intf
, "Playlist",
768 playlistWidget
, QSize( 600, 300 ) );
769 playlistWidget
->show();
770 restoreStackOldWidget();
774 QVLCTools::saveWidgetPosition( p_intf
, "Playlist", playlistWidget
);
775 playlistWidget
->setWindowFlags( Qt::Widget
); // Probably a Qt bug here
776 // It would be logical that QStackWidget::addWidget reset the flags...
777 stackCentralW
->addWidget( playlistWidget
);
778 showTab( playlistWidget
);
780 playlistVisible
= true;
783 void MainInterface::setMinimalView( bool b_minimal
)
785 menuBar()->setVisible( !b_minimal
);
786 controls
->setVisible( !b_minimal
);
787 statusBar()->setVisible( !b_minimal
);
788 inputC
->setVisible( !b_minimal
);
792 If b_minimal is false, then we are normalView
794 void MainInterface::toggleMinimalView( bool b_minimal
)
796 if( !b_minimalView
&& b_autoresize
) /* Normal mode */
798 if( stackCentralW
->currentWidget() == bgWidget
)
800 if( stackCentralW
->height() < 16 )
802 resizeStack( stackCentralW
->width(), 100 );
806 b_minimalView
= b_minimal
;
807 if( !b_videoFullScreen
)
808 setMinimalView( b_minimalView
);
810 emit
minimalViewToggled( b_minimalView
);
813 /* toggling advanced controls buttons */
814 void MainInterface::toggleAdvancedButtons()
816 controls
->toggleAdvanced();
817 // if( fullscreenControls ) fullscreenControls->toggleAdvanced();
820 /* Get the visibility status of the controls (hidden or not, advanced or not) */
821 int MainInterface::getControlsVisibilityStatus()
823 if( !controls
) return 0;
824 return( (controls
->isVisible() ? CONTROLS_VISIBLE
: CONTROLS_HIDDEN
)
825 + CONTROLS_ADVANCED
* controls
->b_advancedVisible
);
829 void MainInterface::visual()
831 if( !VISIBLE( visualSelector
) )
833 visualSelector
->show();
834 if( !THEMIM
->getIM()->hasVideo() )
836 /* Show the background widget */
838 visualSelectorEnabled
= true;
842 /* Stop any currently running visualization */
843 visualSelector
->hide();
844 visualSelectorEnabled
= false;
849 /************************************************************************
851 ************************************************************************/
852 void MainInterface::setName( const QString
& name
)
854 input_name
= name
; /* store it for the QSystray use */
855 /* Display it in the status bar, but also as a Tooltip in case it doesn't
857 nameLabel
->setText( " " + name
+ " " );
858 nameLabel
->setToolTip( " " + name
+" " );
862 * Give the decorations of the Main Window a correct Name.
863 * If nothing is given, set it to VLC...
865 void MainInterface::setVLCWindowsTitle( const QString
& aTitle
)
867 if( aTitle
.isEmpty() )
869 setWindowTitle( qtr( "VLC media player" ) );
873 setWindowTitle( aTitle
+ " - " + qtr( "VLC media player" ) );
877 void MainInterface::showCryptedLabel( bool b_show
)
879 if( cryptedLabel
== NULL
)
881 cryptedLabel
= new QLabel
;
882 // The lock icon is not the right one for DRM protection/scrambled.
883 //cryptedLabel->setPixmap( QPixmap( ":/lock" ) );
884 cryptedLabel
->setText( "DRM" );
885 statusBar()->addWidget( cryptedLabel
);
888 cryptedLabel
->setVisible( b_show
);
891 void MainInterface::showBuffering( float f_cache
)
893 QString amount
= QString("Buffering: %1%").arg( (int)(100*f_cache
) );
894 statusBar()->showMessage( amount
, 1000 );
897 /*****************************************************************************
898 * Systray Icon and Systray Menu
899 *****************************************************************************/
902 * Create a SystemTray icon and a menu that would go with it.
903 * Connects to a click handler on the icon.
905 void MainInterface::createSystray()
908 if( QDate::currentDate().dayOfYear() >= 354 )
909 iconVLC
= QIcon( ":/logo/vlc128-christmas.png" );
911 iconVLC
= QIcon( ":/logo/vlc128.png" );
912 sysTray
= new QSystemTrayIcon( iconVLC
, this );
913 sysTray
->setToolTip( qtr( "VLC media player" ));
915 systrayMenu
= new QMenu( qtr( "VLC media player" ), this );
916 systrayMenu
->setIcon( iconVLC
);
918 QVLCMenu::updateSystrayMenu( this, p_intf
, true );
921 CONNECT( sysTray
, activated( QSystemTrayIcon::ActivationReason
),
922 this, handleSystrayClick( QSystemTrayIcon::ActivationReason
) );
926 * Updates the Systray Icon's menu and toggle the main interface
928 void MainInterface::toggleUpdateSystrayMenu()
930 /* If hidden, show it */
936 else if( isMinimized() )
944 /* Visible (possibly under other windows) */
946 /* check if any visible window is above vlc in the z-order,
947 * but ignore the ones always on top
948 * and the ones which can't be activated */
951 wi
.cbSize
= sizeof( WINDOWINFO
);
952 for( hwnd
= GetNextWindow( internalWinId(), GW_HWNDPREV
);
953 hwnd
&& ( !IsWindowVisible( hwnd
) ||
954 ( GetWindowInfo( hwnd
, &wi
) &&
955 (wi
.dwExStyle
&WS_EX_NOACTIVATE
) ) );
956 hwnd
= GetNextWindow( hwnd
, GW_HWNDPREV
) );
957 if( !hwnd
|| !GetWindowInfo( hwnd
, &wi
) ||
958 (wi
.dwExStyle
&WS_EX_TOPMOST
) )
970 QVLCMenu::updateSystrayMenu( this, p_intf
);
973 void MainInterface::handleSystrayClick(
974 QSystemTrayIcon::ActivationReason reason
)
978 case QSystemTrayIcon::Trigger
:
979 case QSystemTrayIcon::DoubleClick
:
980 toggleUpdateSystrayMenu();
982 case QSystemTrayIcon::MiddleClick
:
983 sysTray
->showMessage( qtr( "VLC media player" ),
984 qtr( "Control menu for the player" ),
985 QSystemTrayIcon::Information
, 3000 );
993 * Updates the name of the systray Icon tooltip.
994 * Doesn't check if the systray exists, check before you call it.
996 void MainInterface::updateSystrayTooltipName( const QString
& name
)
1000 sysTray
->setToolTip( qtr( "VLC media player" ) );
1004 sysTray
->setToolTip( name
);
1005 if( b_notificationEnabled
&& ( isHidden() || isMinimized() ) )
1007 sysTray
->showMessage( qtr( "VLC media player" ), name
,
1008 QSystemTrayIcon::NoIcon
, 3000 );
1012 QVLCMenu::updateSystrayMenu( this, p_intf
);
1016 * Updates the status of the systray Icon tooltip.
1017 * Doesn't check if the systray exists, check before you call it.
1019 void MainInterface::updateSystrayTooltipStatus( int i_status
)
1024 sysTray
->setToolTip( input_name
);
1027 sysTray
->setToolTip( input_name
+ " - " + qtr( "Paused") );
1030 sysTray
->setToolTip( qtr( "VLC media player" ) );
1033 QVLCMenu::updateSystrayMenu( this, p_intf
);
1037 /************************************************************************
1039 ************************************************************************/
1040 void MainInterface::dropEvent(QDropEvent
*event
)
1042 dropEventPlay( event
, true );
1045 void MainInterface::dropEventPlay( QDropEvent
*event
, bool b_play
)
1047 event
->setDropAction( Qt::CopyAction
);
1048 if( !event
->possibleActions() & Qt::CopyAction
)
1051 const QMimeData
*mimeData
= event
->mimeData();
1053 /* D&D of a subtitles file, add it on the fly */
1054 if( mimeData
->urls().size() == 1 && THEMIM
->getIM()->hasInput() )
1056 if( !input_AddSubtitle( THEMIM
->getInput(),
1057 qtu( toNativeSeparators( mimeData
->urls()[0].toLocalFile() ) ),
1065 bool first
= b_play
;
1066 foreach( const QUrl
&url
, mimeData
->urls() )
1068 QString s
= toNativeSeparators( url
.toLocalFile() );
1070 if( s
.length() > 0 ) {
1071 char* psz_uri
= make_URI( qtu(s
) );
1072 playlist_Add( THEPL
, psz_uri
, NULL
,
1073 PLAYLIST_APPEND
| (first
? PLAYLIST_GO
: PLAYLIST_PREPARSE
),
1074 PLAYLIST_END
, true, pl_Unlocked
);
1077 RecentsMRL::getInstance( p_intf
)->addRecent( s
);
1082 void MainInterface::dragEnterEvent(QDragEnterEvent
*event
)
1084 event
->acceptProposedAction();
1086 void MainInterface::dragMoveEvent(QDragMoveEvent
*event
)
1088 event
->acceptProposedAction();
1090 void MainInterface::dragLeaveEvent(QDragLeaveEvent
*event
)
1095 /************************************************************************
1097 ************************************************************************/
1098 void MainInterface::keyPressEvent( QKeyEvent
*e
)
1100 handleKeyPress( e
);
1103 void MainInterface::handleKeyPress( QKeyEvent
*e
)
1105 if( ( e
->modifiers() & Qt::ControlModifier
) && ( e
->key() == Qt::Key_H
) )
1107 toggleMinimalView( !b_minimalView
);
1111 int i_vlck
= qtEventToVLCKey( e
);
1114 var_SetInteger( p_intf
->p_libvlc
, "key-pressed", i_vlck
);
1121 void MainInterface::wheelEvent( QWheelEvent
*e
)
1123 int i_vlckey
= qtWheelEventToVLCKey( e
);
1124 var_SetInteger( p_intf
->p_libvlc
, "key-pressed", i_vlckey
);
1128 void MainInterface::closeEvent( QCloseEvent
*e
)
1135 void MainInterface::setInterfaceFullScreen( bool fs
)
1138 setWindowState( windowState() | Qt::WindowFullScreen
);
1140 setWindowState( windowState() & ~Qt::WindowFullScreen
);
1142 void MainInterface::toggleInterfaceFullScreen()
1144 b_interfaceFullScreen
= !b_interfaceFullScreen
;
1145 if( !b_videoFullScreen
)
1146 setInterfaceFullScreen( b_interfaceFullScreen
);
1147 emit
fullscreenInterfaceToggled( b_interfaceFullScreen
);
1150 /*****************************************************************************
1151 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1152 * We don't show the menu directly here because we don't want the
1153 * caller to block for a too long time.
1154 *****************************************************************************/
1155 static int PopupMenuCB( vlc_object_t
*p_this
, const char *psz_variable
,
1156 vlc_value_t old_val
, vlc_value_t new_val
, void *param
)
1158 intf_thread_t
*p_intf
= (intf_thread_t
*)param
;
1160 if( p_intf
->pf_show_dialog
)
1162 p_intf
->pf_show_dialog( p_intf
, INTF_DIALOG_POPUPMENU
,
1163 new_val
.b_bool
, NULL
);
1169 /*****************************************************************************
1170 * IntfShowCB: callback triggered by the intf-show libvlc variable.
1171 *****************************************************************************/
1172 static int IntfShowCB( vlc_object_t
*p_this
, const char *psz_variable
,
1173 vlc_value_t old_val
, vlc_value_t new_val
, void *param
)
1175 intf_thread_t
*p_intf
= (intf_thread_t
*)param
;
1176 p_intf
->p_sys
->p_mi
->toggleFSC();