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 */
289 settings
->setValue( "playlist-visible", playlistVisible
);
291 settings
->setValue( "adv-controls",
292 getControlsVisibilityStatus() & CONTROLS_ADVANCED
);
294 /* Save the stackCentralW sizes */
295 settings
->setValue( "bgSize", stackWidgetsSizes
[bgWidget
] );
296 settings
->setValue( "playlistSize", stackWidgetsSizes
[playlistWidget
] );
299 QVLCTools::saveWidgetPosition(settings
, this);
301 settings
->endGroup();
303 /* Save undocked playlist size */
304 if( playlistWidget
&& !isPlDocked() )
305 QVLCTools::saveWidgetPosition( p_intf
, "Playlist", playlistWidget
);
307 delete playlistWidget
;
311 /* Unregister callbacks */
312 var_DelCallback( p_intf
->p_libvlc
, "intf-show", IntfShowCB
, p_intf
);
313 var_DelCallback( p_intf
->p_libvlc
, "intf-popupmenu", PopupMenuCB
, p_intf
);
315 p_intf
->p_sys
->p_mi
= NULL
;
318 /*****************************
320 *****************************/
321 void MainInterface::recreateToolbars()
323 bool b_adv
= getControlsVisibilityStatus() & CONTROLS_ADVANCED
;
325 settings
->beginGroup( "MainWindow" );
329 controls
= new ControlsWidget( p_intf
, b_adv
, this );
330 inputC
= new InputControlsWidget( p_intf
, this );
332 if( fullscreenControls
)
334 delete fullscreenControls
;
335 fullscreenControls
= new FullscreenControllerWidget( p_intf
, this );
336 CONNECT( fullscreenControls
, keyPressed( QKeyEvent
* ),
337 this, handleKeyPress( QKeyEvent
* ) );
339 mainLayout
->insertWidget( 2, inputC
);
340 mainLayout
->insertWidget( settings
->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
342 settings
->endGroup();
345 void MainInterface::createMainWidget( QSettings
*settings
)
347 /* Create the main Widget and the mainLayout */
348 QWidget
*main
= new QWidget
;
349 setCentralWidget( main
);
350 mainLayout
= new QVBoxLayout( main
);
351 main
->setContentsMargins( 0, 0, 0, 0 );
352 mainLayout
->setSpacing( 0 ); mainLayout
->setMargin( 0 );
355 stackCentralW
= new QVLCStackedWidget( main
);
358 bgWidget
= new BackgroundWidget( p_intf
);
359 stackCentralW
->addWidget( bgWidget
);
361 /* And video Outputs */
362 if( b_videoEmbedded
)
364 videoWidget
= new VideoWidget( p_intf
);
365 stackCentralW
->addWidget( videoWidget
);
367 mainLayout
->insertWidget( 1, stackCentralW
);
369 settings
->beginGroup( "MainWindow" );
370 stackWidgetsSizes
[bgWidget
] = settings
->value( "bgSize", QSize( 400, 0 ) ).toSize();
371 /* Resize even if no-auto-resize, because we are at creation */
372 resizeStack( stackWidgetsSizes
[bgWidget
].width(), stackWidgetsSizes
[bgWidget
].height() );
374 /* Create the CONTROLS Widget */
375 controls
= new ControlsWidget( p_intf
,
376 settings
->value( "adv-controls", false ).toBool(), this );
377 inputC
= new InputControlsWidget( p_intf
, this );
379 mainLayout
->insertWidget( 2, inputC
);
380 mainLayout
->insertWidget( settings
->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
383 /* Visualisation, disabled for now, they SUCK */
385 visualSelector
= new VisualSelector( p_intf
);
386 mainLayout
->insertWidget( 0, visualSelector
);
387 visualSelector
->hide();
390 settings
->endGroup();
392 /* Enable the popup menu in the MI */
393 main
->setContextMenuPolicy( Qt::CustomContextMenu
);
394 CONNECT( main
, customContextMenuRequested( const QPoint
& ),
395 this, popupMenu( const QPoint
& ) );
397 if ( depth() > 8 ) /* 8bit depth has too many issues with opacity */
398 /* Create the FULLSCREEN CONTROLS Widget */
399 if( var_InheritBool( p_intf
, "qt-fs-controller" ) )
401 fullscreenControls
= new FullscreenControllerWidget( p_intf
, this );
402 CONNECT( fullscreenControls
, keyPressed( QKeyEvent
* ),
403 this, handleKeyPress( QKeyEvent
* ) );
407 inline void MainInterface::initSystray()
410 bool b_systrayAvailable
= QSystemTrayIcon::isSystemTrayAvailable();
411 bool b_systrayWanted
= var_InheritBool( p_intf
, "qt-system-tray" );
413 if( var_InheritBool( p_intf
, "qt-start-minimized") )
415 if( b_systrayAvailable
)
417 b_systrayWanted
= true;
418 b_hideAfterCreation
= true;
421 msg_Err( p_intf
, "cannot start minimized without system tray bar" );
424 if( b_systrayAvailable
&& b_systrayWanted
)
429 inline void MainInterface::createStatusBar()
434 /* Widgets Creation*/
435 QStatusBar
*statusBarr
= statusBar();
437 TimeLabel
*timeLabel
= new TimeLabel( p_intf
);
438 nameLabel
= new QLabel( this );
439 nameLabel
->setTextInteractionFlags( Qt::TextSelectableByMouse
440 | Qt::TextSelectableByKeyboard
);
441 SpeedLabel
*speedLabel
= new SpeedLabel( p_intf
, this );
443 /* Styling those labels */
444 timeLabel
->setFrameStyle( QFrame::Sunken
| QFrame::Panel
);
445 speedLabel
->setFrameStyle( QFrame::Sunken
| QFrame::Panel
);
446 nameLabel
->setFrameStyle( QFrame::Sunken
| QFrame::StyledPanel
);
447 timeLabel
->setStyleSheet(
448 "QLabel:hover { background-color: rgba(255, 255, 255, 50%) }" );
449 speedLabel
->setStyleSheet(
450 "QLabel:hover { background-color: rgba(255, 255, 255, 50%) }" );
452 /* and adding those */
453 statusBarr
->addWidget( nameLabel
, 8 );
454 statusBarr
->addPermanentWidget( speedLabel
, 0 );
455 statusBarr
->addPermanentWidget( timeLabel
, 0 );
457 /* timeLabel behaviour:
458 - double clicking opens the goto time dialog
459 - right-clicking and clicking just toggle between remaining and
461 CONNECT( timeLabel
, timeLabelDoubleClicked(), THEDP
, gotoTimeDialog() );
463 CONNECT( THEMIM
->getIM(), encryptionChanged( bool ),
464 this, showCryptedLabel( bool ) );
466 CONNECT( THEMIM
->getIM(), seekRequested( float ),
467 timeLabel
, setDisplayPosition( float ) );
470 /**********************************************************************
471 * Handling of sizing of the components
472 **********************************************************************/
474 void MainInterface::debug()
477 msg_Dbg( p_intf
, "size: %i - %i", size().height(), size().width() );
478 msg_Dbg( p_intf
, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
479 msg_Dbg( p_intf
, "minimumsize: %i - %i", minimumSize().height(), minimumSize().width() );
481 msg_Dbg( p_intf
, "Stack size: %i - %i", stackCentralW
->size().height(), stackCentralW
->size().width() );
482 msg_Dbg( p_intf
, "Stack sizeHint: %i - %i", stackCentralW
->sizeHint().height(), stackCentralW
->sizeHint().width() );
483 msg_Dbg( p_intf
, "Central size: %i - %i", centralWidget()->size().height(), centralWidget()->size().width() );
487 inline void MainInterface::showVideo() { showTab( videoWidget
); }
488 inline void MainInterface::restoreStackOldWidget()
489 { showTab( stackCentralOldWidget
); }
491 inline void MainInterface::showTab( QWidget
*widget
)
494 msg_Warn( p_intf
, "Old stackCentralOldWidget %i", stackCentralW
->indexOf( stackCentralOldWidget
) );
497 stackCentralOldWidget
= stackCentralW
->currentWidget();
498 stackWidgetsSizes
[stackCentralOldWidget
] = stackCentralW
->size();
500 stackCentralW
->setCurrentWidget( widget
);
502 resizeStack( stackWidgetsSizes
[widget
].width(), stackWidgetsSizes
[widget
].height() );
505 msg_Warn( p_intf
, "State change %i", stackCentralW
->currentIndex() );
506 msg_Warn( p_intf
, "New stackCentralOldWidget %i", stackCentralW
->indexOf( stackCentralOldWidget
) );
510 void MainInterface::destroyPopupMenu()
512 QVLCMenu::PopupMenu( p_intf
, false );
515 void MainInterface::popupMenu( const QPoint
&p
)
517 QVLCMenu::PopupMenu( p_intf
, true );
520 void MainInterface::toggleFSC()
522 if( !fullscreenControls
) return;
524 IMEvent
*eShow
= new IMEvent( FullscreenControlToggle_Type
, 0 );
525 QApplication::postEvent( fullscreenControls
, eShow
);
528 /****************************************************************************
530 ****************************************************************************/
534 * You must not change the state of this object or other Qt4 UI objects,
535 * from the video output thread - only from the Qt4 UI main loop thread.
536 * All window provider queries must be handled through signals or events.
537 * That's why we have all those emit statements...
539 WId
MainInterface::getVideo( int *pi_x
, int *pi_y
,
540 unsigned int *pi_width
, unsigned int *pi_height
)
545 /* This is a blocking call signal. Results are returned through pointers.
546 * Beware of deadlocks! */
548 emit
askGetVideo( &id
, pi_x
, pi_y
, pi_width
, pi_height
);
552 void MainInterface::getVideoSlot( WId
*p_id
, int *pi_x
, int *pi_y
,
553 unsigned *pi_width
, unsigned *pi_height
)
555 /* Request the videoWidget */
556 WId ret
= videoWidget
->request( pi_x
, pi_y
,
557 pi_width
, pi_height
, !b_autoresize
);
559 if( ret
) /* The videoWidget is available */
561 /* Consider the video active now */
564 /* Ask videoWidget to resize correctly, if we are in normal mode */
565 if( !isFullScreen() && !isMaximized() && b_autoresize
)
566 videoWidget
->SetSizing( *pi_width
, *pi_height
);
570 /* Asynchronous call from the WindowClose function */
571 void MainInterface::releaseVideo( void )
573 emit
askReleaseVideo();
576 /* Function that is CONNECTED to the previous emit */
577 void MainInterface::releaseVideoSlot( void )
579 videoWidget
->release();
580 setVideoOnTop( false );
581 setVideoFullScreen( false );
583 if( stackCentralW
->currentWidget() == videoWidget
)
584 restoreStackOldWidget();
586 /* We don't want to have a blank video to popup */
587 stackCentralOldWidget
= bgWidget
;
590 void MainInterface::setVideoSize( unsigned int w
, unsigned int h
)
592 if( !isFullScreen() && !isMaximized() )
593 videoWidget
->SetSizing( w
, h
);
596 void MainInterface::setVideoFullScreen( bool fs
)
598 b_videoFullScreen
= fs
;
601 int numscreen
= var_InheritInteger( p_intf
, "qt-fullscreen-screennumber" );
602 /* if user hasn't defined screennumber, or screennumber that is bigger
603 * than current number of screens, take screennumber where current interface
606 if( numscreen
== -1 || numscreen
> QApplication::desktop()->numScreens() )
607 numscreen
= QApplication::desktop()->screenNumber( p_intf
->p_sys
->p_mi
);
609 QRect screenres
= QApplication::desktop()->screenGeometry( numscreen
);
611 /* To be sure window is on proper-screen in xinerama */
613 if( !screenres
.contains( pos() ) && QApplication::desktop()->screenCount() > 1 )
615 if( !screenres
.contains( pos() ) )
618 msg_Dbg( p_intf
, "Moving video to correct screen");
619 move( QPoint( screenres
.x(), screenres
.y() ) );
621 setMinimalView( true );
622 setInterfaceFullScreen( true );
626 /* TODO do we want to restore screen and position ? (when
627 * qt-fullscreen-screennumber is forced) */
628 setMinimalView( b_minimalView
);
629 setInterfaceFullScreen( b_interfaceFullScreen
);
634 /* Slot to change the video always-on-top flag.
635 * Emit askVideoOnTop() to invoke this from other thread. */
636 void MainInterface::setVideoOnTop( bool on_top
)
638 b_videoOnTop
= on_top
;
640 Qt::WindowFlags oldflags
= windowFlags(), newflags
;
643 newflags
= oldflags
| Qt::WindowStaysOnTopHint
;
645 newflags
= oldflags
& ~Qt::WindowStaysOnTopHint
;
647 if( newflags
!= oldflags
)
649 setWindowFlags( newflags
);
650 show(); /* necessary to apply window flags */
654 /* Asynchronous call from WindowControl function */
655 int MainInterface::controlVideo( int i_query
, va_list args
)
659 case VOUT_WINDOW_SET_SIZE
:
661 unsigned int i_width
= va_arg( args
, unsigned int );
662 unsigned int i_height
= va_arg( args
, unsigned int );
664 emit
askVideoToResize( i_width
, i_height
);
667 case VOUT_WINDOW_SET_STATE
:
669 unsigned i_arg
= va_arg( args
, unsigned );
670 unsigned on_top
= i_arg
& VOUT_WINDOW_STATE_ABOVE
;
672 emit
askVideoOnTop( on_top
!= 0 );
675 case VOUT_WINDOW_SET_FULLSCREEN
:
677 bool b_fs
= va_arg( args
, int );
679 emit
askVideoSetFullScreen( b_fs
);
683 msg_Warn( p_intf
, "unsupported control query" );
688 /*****************************************************************************
689 * Playlist, Visualisation and Menus handling
690 *****************************************************************************/
692 * Toggle the playlist widget or dialog
694 void MainInterface::createPlaylist()
696 playlistWidget
= new PlaylistWidget( p_intf
, this );
700 stackCentralW
->addWidget( playlistWidget
);
701 stackWidgetsSizes
[playlistWidget
] = settings
->value( "playlistSize", QSize( 500, 250 ) ).toSize();
706 playlistWidget
->setParent( NULL
);
708 playlistWidget
->setWindowFlags( Qt::Window
);
710 /* This will restore the geometry but will not work for position,
711 because of parenting */
712 QVLCTools::restoreWidgetPosition( p_intf
, "Playlist",
713 playlistWidget
, QSize( 600, 300 ) );
717 void MainInterface::togglePlaylist()
719 if( !playlistWidget
)
726 /* Playlist is not visible, show it */
727 if( stackCentralW
->currentWidget() != playlistWidget
)
729 showTab( playlistWidget
);
733 restoreStackOldWidget();
735 playlistVisible
= ( stackCentralW
->currentWidget() == playlistWidget
);
740 playlistWidget
->setParent( NULL
);
742 playlistWidget
->setWindowFlags( Qt::Window
);
743 playlistVisible
= !playlistVisible
;
744 playlistWidget
->setVisible( playlistVisible
);
749 void MainInterface::dockPlaylist( bool p_docked
)
751 if( b_plDocked
== p_docked
) return;
752 b_plDocked
= p_docked
;
754 if( !playlistWidget
) return; /* Playlist wasn't created yet */
757 stackCentralW
->removeWidget( playlistWidget
);
759 playlistWidget
->setParent( NULL
);
761 playlistWidget
->setWindowFlags( Qt::Window
);
762 QVLCTools::restoreWidgetPosition( p_intf
, "Playlist",
763 playlistWidget
, QSize( 600, 300 ) );
764 playlistWidget
->show();
765 restoreStackOldWidget();
769 QVLCTools::saveWidgetPosition( p_intf
, "Playlist", playlistWidget
);
770 playlistWidget
->setWindowFlags( Qt::Widget
); // Probably a Qt bug here
771 // It would be logical that QStackWidget::addWidget reset the flags...
772 stackCentralW
->addWidget( playlistWidget
);
773 showTab( playlistWidget
);
775 playlistVisible
= true;
778 void MainInterface::setMinimalView( bool b_minimal
)
780 menuBar()->setVisible( !b_minimal
);
781 controls
->setVisible( !b_minimal
);
782 statusBar()->setVisible( !b_minimal
);
783 inputC
->setVisible( !b_minimal
);
787 If b_minimal is false, then we are normalView
789 void MainInterface::toggleMinimalView( bool b_minimal
)
791 if( !b_minimalView
&& b_autoresize
) /* Normal mode */
793 if( stackCentralW
->currentWidget() == bgWidget
)
795 if( stackCentralW
->height() < 16 )
797 resizeStack( stackCentralW
->width(), 100 );
801 b_minimalView
= b_minimal
;
802 if( !b_videoFullScreen
)
803 setMinimalView( b_minimalView
);
805 emit
minimalViewToggled( b_minimalView
);
808 /* toggling advanced controls buttons */
809 void MainInterface::toggleAdvancedButtons()
811 controls
->toggleAdvanced();
812 // if( fullscreenControls ) fullscreenControls->toggleAdvanced();
815 /* Get the visibility status of the controls (hidden or not, advanced or not) */
816 int MainInterface::getControlsVisibilityStatus()
818 if( !controls
) return 0;
819 return( (controls
->isVisible() ? CONTROLS_VISIBLE
: CONTROLS_HIDDEN
)
820 + CONTROLS_ADVANCED
* controls
->b_advancedVisible
);
824 void MainInterface::visual()
826 if( !VISIBLE( visualSelector
) )
828 visualSelector
->show();
829 if( !THEMIM
->getIM()->hasVideo() )
831 /* Show the background widget */
833 visualSelectorEnabled
= true;
837 /* Stop any currently running visualization */
838 visualSelector
->hide();
839 visualSelectorEnabled
= false;
844 /************************************************************************
846 ************************************************************************/
847 void MainInterface::setName( const QString
& name
)
849 input_name
= name
; /* store it for the QSystray use */
850 /* Display it in the status bar, but also as a Tooltip in case it doesn't
852 nameLabel
->setText( " " + name
+ " " );
853 nameLabel
->setToolTip( " " + name
+" " );
857 * Give the decorations of the Main Window a correct Name.
858 * If nothing is given, set it to VLC...
860 void MainInterface::setVLCWindowsTitle( const QString
& aTitle
)
862 if( aTitle
.isEmpty() )
864 setWindowTitle( qtr( "VLC media player" ) );
868 setWindowTitle( aTitle
+ " - " + qtr( "VLC media player" ) );
872 void MainInterface::showCryptedLabel( bool b_show
)
874 if( cryptedLabel
== NULL
)
876 cryptedLabel
= new QLabel
;
877 // The lock icon is not the right one for DRM protection/scrambled.
878 //cryptedLabel->setPixmap( QPixmap( ":/lock" ) );
879 cryptedLabel
->setText( "DRM" );
880 statusBar()->addWidget( cryptedLabel
);
883 cryptedLabel
->setVisible( b_show
);
886 void MainInterface::showBuffering( float f_cache
)
888 QString amount
= QString("Buffering: %1%").arg( (int)(100*f_cache
) );
889 statusBar()->showMessage( amount
, 1000 );
892 /*****************************************************************************
893 * Systray Icon and Systray Menu
894 *****************************************************************************/
897 * Create a SystemTray icon and a menu that would go with it.
898 * Connects to a click handler on the icon.
900 void MainInterface::createSystray()
903 if( QDate::currentDate().dayOfYear() >= 354 )
904 iconVLC
= QIcon( ":/logo/vlc128-christmas.png" );
906 iconVLC
= QIcon( ":/logo/vlc128.png" );
907 sysTray
= new QSystemTrayIcon( iconVLC
, this );
908 sysTray
->setToolTip( qtr( "VLC media player" ));
910 systrayMenu
= new QMenu( qtr( "VLC media player" ), this );
911 systrayMenu
->setIcon( iconVLC
);
913 QVLCMenu::updateSystrayMenu( this, p_intf
, true );
916 CONNECT( sysTray
, activated( QSystemTrayIcon::ActivationReason
),
917 this, handleSystrayClick( QSystemTrayIcon::ActivationReason
) );
921 * Updates the Systray Icon's menu and toggle the main interface
923 void MainInterface::toggleUpdateSystrayMenu()
925 /* If hidden, show it */
931 else if( isMinimized() )
939 /* Visible (possibly under other windows) */
941 /* check if any visible window is above vlc in the z-order,
942 * but ignore the ones always on top
943 * and the ones which can't be activated */
946 wi
.cbSize
= sizeof( WINDOWINFO
);
947 for( hwnd
= GetNextWindow( internalWinId(), GW_HWNDPREV
);
948 hwnd
&& ( !IsWindowVisible( hwnd
) ||
949 ( GetWindowInfo( hwnd
, &wi
) &&
950 (wi
.dwExStyle
&WS_EX_NOACTIVATE
) ) );
951 hwnd
= GetNextWindow( hwnd
, GW_HWNDPREV
) );
952 if( !hwnd
|| !GetWindowInfo( hwnd
, &wi
) ||
953 (wi
.dwExStyle
&WS_EX_TOPMOST
) )
965 QVLCMenu::updateSystrayMenu( this, p_intf
);
968 void MainInterface::handleSystrayClick(
969 QSystemTrayIcon::ActivationReason reason
)
973 case QSystemTrayIcon::Trigger
:
974 case QSystemTrayIcon::DoubleClick
:
975 toggleUpdateSystrayMenu();
977 case QSystemTrayIcon::MiddleClick
:
978 sysTray
->showMessage( qtr( "VLC media player" ),
979 qtr( "Control menu for the player" ),
980 QSystemTrayIcon::Information
, 3000 );
988 * Updates the name of the systray Icon tooltip.
989 * Doesn't check if the systray exists, check before you call it.
991 void MainInterface::updateSystrayTooltipName( const QString
& name
)
995 sysTray
->setToolTip( qtr( "VLC media player" ) );
999 sysTray
->setToolTip( name
);
1000 if( b_notificationEnabled
&& ( isHidden() || isMinimized() ) )
1002 sysTray
->showMessage( qtr( "VLC media player" ), name
,
1003 QSystemTrayIcon::NoIcon
, 3000 );
1007 QVLCMenu::updateSystrayMenu( this, p_intf
);
1011 * Updates the status of the systray Icon tooltip.
1012 * Doesn't check if the systray exists, check before you call it.
1014 void MainInterface::updateSystrayTooltipStatus( int i_status
)
1019 sysTray
->setToolTip( input_name
);
1022 sysTray
->setToolTip( input_name
+ " - " + qtr( "Paused") );
1025 sysTray
->setToolTip( qtr( "VLC media player" ) );
1028 QVLCMenu::updateSystrayMenu( this, p_intf
);
1032 /************************************************************************
1034 ************************************************************************/
1035 void MainInterface::dropEvent(QDropEvent
*event
)
1037 dropEventPlay( event
, true );
1040 void MainInterface::dropEventPlay( QDropEvent
*event
, bool b_play
)
1042 event
->setDropAction( Qt::CopyAction
);
1043 if( !event
->possibleActions() & Qt::CopyAction
)
1046 const QMimeData
*mimeData
= event
->mimeData();
1048 /* D&D of a subtitles file, add it on the fly */
1049 if( mimeData
->urls().size() == 1 && THEMIM
->getIM()->hasInput() )
1051 if( !input_AddSubtitle( THEMIM
->getInput(),
1052 qtu( toNativeSeparators( mimeData
->urls()[0].toLocalFile() ) ),
1060 bool first
= b_play
;
1061 foreach( const QUrl
&url
, mimeData
->urls() )
1063 QString s
= toNativeSeparators( url
.toLocalFile() );
1065 if( s
.length() > 0 ) {
1066 char* psz_uri
= make_URI( qtu(s
) );
1067 playlist_Add( THEPL
, psz_uri
, NULL
,
1068 PLAYLIST_APPEND
| (first
? PLAYLIST_GO
: PLAYLIST_PREPARSE
),
1069 PLAYLIST_END
, true, pl_Unlocked
);
1072 RecentsMRL::getInstance( p_intf
)->addRecent( s
);
1077 void MainInterface::dragEnterEvent(QDragEnterEvent
*event
)
1079 event
->acceptProposedAction();
1081 void MainInterface::dragMoveEvent(QDragMoveEvent
*event
)
1083 event
->acceptProposedAction();
1085 void MainInterface::dragLeaveEvent(QDragLeaveEvent
*event
)
1090 /************************************************************************
1092 ************************************************************************/
1093 void MainInterface::keyPressEvent( QKeyEvent
*e
)
1095 handleKeyPress( e
);
1098 void MainInterface::handleKeyPress( QKeyEvent
*e
)
1100 if( ( e
->modifiers() & Qt::ControlModifier
) && ( e
->key() == Qt::Key_H
) )
1102 toggleMinimalView( !b_minimalView
);
1106 int i_vlck
= qtEventToVLCKey( e
);
1109 var_SetInteger( p_intf
->p_libvlc
, "key-pressed", i_vlck
);
1116 void MainInterface::wheelEvent( QWheelEvent
*e
)
1118 int i_vlckey
= qtWheelEventToVLCKey( e
);
1119 var_SetInteger( p_intf
->p_libvlc
, "key-pressed", i_vlckey
);
1123 void MainInterface::closeEvent( QCloseEvent
*e
)
1130 void MainInterface::setInterfaceFullScreen( bool fs
)
1133 setWindowState( windowState() | Qt::WindowFullScreen
);
1135 setWindowState( windowState() & ~Qt::WindowFullScreen
);
1137 void MainInterface::toggleInterfaceFullScreen()
1139 b_interfaceFullScreen
= !b_interfaceFullScreen
;
1140 if( !b_videoFullScreen
)
1141 setInterfaceFullScreen( b_interfaceFullScreen
);
1142 emit
fullscreenInterfaceToggled( b_interfaceFullScreen
);
1145 /*****************************************************************************
1146 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
1147 * We don't show the menu directly here because we don't want the
1148 * caller to block for a too long time.
1149 *****************************************************************************/
1150 static int PopupMenuCB( vlc_object_t
*p_this
, const char *psz_variable
,
1151 vlc_value_t old_val
, vlc_value_t new_val
, void *param
)
1153 intf_thread_t
*p_intf
= (intf_thread_t
*)param
;
1155 if( p_intf
->pf_show_dialog
)
1157 p_intf
->pf_show_dialog( p_intf
, INTF_DIALOG_POPUPMENU
,
1158 new_val
.b_bool
, NULL
);
1164 /*****************************************************************************
1165 * IntfShowCB: callback triggered by the intf-show libvlc variable.
1166 *****************************************************************************/
1167 static int IntfShowCB( vlc_object_t
*p_this
, const char *psz_variable
,
1168 vlc_value_t old_val
, vlc_value_t new_val
, void *param
)
1170 intf_thread_t
*p_intf
= (intf_thread_t
*)param
;
1171 p_intf
->p_sys
->p_mi
->toggleFSC();