Commit fada667b authored by Jean-Baptiste Kempf's avatar Jean-Baptiste Kempf

Qt4: Systray Menu segfaults. Don't register the connects if you don't have a systray.

parent 8820f0c6
...@@ -95,7 +95,7 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf ) ...@@ -95,7 +95,7 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
need_components_update = false; need_components_update = false;
bgWidget = NULL; videoWidget = NULL; playlistWidget = NULL; bgWidget = NULL; videoWidget = NULL; playlistWidget = NULL;
embeddedPlaylistWasActive = videoIsActive = false; embeddedPlaylistWasActive = videoIsActive = false;
input_name = ""; input_name = "";
videoEmbeddedFlag = false; videoEmbeddedFlag = false;
...@@ -122,6 +122,18 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf ) ...@@ -122,6 +122,18 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
setFocusPolicy( Qt::StrongFocus ); setFocusPolicy( Qt::StrongFocus );
setAcceptDrops(true); setAcceptDrops(true);
/* Systray */
systray = NULL;
if( QSystemTrayIcon::isSystemTrayAvailable() &&
( config_GetInt( p_intf, "qt-start-mininimized") == 1) )
{
hide();
createSystrayMenu();
}
if( QSystemTrayIcon::isSystemTrayAvailable() &&
( config_GetInt( p_intf, "qt-system-tray") == 1) )
createSystrayMenu();
/* Init input manager */ /* Init input manager */
MainInputManager::getInstance( p_intf ); MainInputManager::getInstance( p_intf );
ON_TIMEOUT( updateOnTimer() ); ON_TIMEOUT( updateOnTimer() );
...@@ -138,10 +150,10 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf ) ...@@ -138,10 +150,10 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
/* Naming in the controller */ /* Naming in the controller */
CONNECT( THEMIM->getIM(), nameChanged( QString ), this, CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
setName( QString ) ); setName( QString ) );
if( config_GetInt( p_intf, "qt-system-tray" ) ) if( config_GetInt( p_intf, "qt-system-tray" ) && systray )
{ {
CONNECT( THEMIM->getIM(), nameChanged( QString ), this, CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
updateSystrayTooltipName(QString)); updateSystrayTooltipName( QString ) );
} }
if( config_GetInt( p_intf, "qt-name-in-title" ) ) if( config_GetInt( p_intf, "qt-name-in-title" ) )
{ {
...@@ -153,10 +165,10 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf ) ...@@ -153,10 +165,10 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
CONNECT( THEMIM->getIM(), statusChanged( int ), this, setStatus( int ) ); CONNECT( THEMIM->getIM(), statusChanged( int ), this, setStatus( int ) );
CONNECT( THEMIM->getIM(), navigationChanged( int ), CONNECT( THEMIM->getIM(), navigationChanged( int ),
this, setNavigation(int) ); this, setNavigation(int) );
if( config_GetInt( p_intf, "qt-system-tray" ) ) if( config_GetInt( p_intf, "qt-system-tray" ) && systray )
{ {
CONNECT( THEMIM->getIM(), statusChanged( int ), this, CONNECT( THEMIM->getIM(), statusChanged( int ), this,
updateSystrayTooltipStatus(int)); updateSystrayTooltipStatus( int ) );
} }
CONNECT( slider, sliderDragged( float ), CONNECT( slider, sliderDragged( float ),
THEMIM->getIM(), sliderUpdate( float ) ); THEMIM->getIM(), sliderUpdate( float ) );
...@@ -182,15 +194,6 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf ) ...@@ -182,15 +194,6 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
var_AddCallback( p_playlist, "intf-show", IntfShowCB, p_intf ); var_AddCallback( p_playlist, "intf-show", IntfShowCB, p_intf );
vlc_object_release( p_playlist ); vlc_object_release( p_playlist );
} }
if( QSystemTrayIcon::isSystemTrayAvailable() &&
( config_GetInt( p_intf, "qt-start-mininimized") == 1))
{
hide();
createSystrayMenu();
}
if( QSystemTrayIcon::isSystemTrayAvailable() &&
( config_GetInt( p_intf, "qt-system-tray") == 1))
createSystrayMenu();
} }
...@@ -292,7 +295,7 @@ void MainInterface::handleMainUi( QSettings *settings ) ...@@ -292,7 +295,7 @@ void MainInterface::handleMainUi( QSettings *settings )
{ {
videoWidget = new VideoWidget( p_intf ); videoWidget = new VideoWidget( p_intf );
videoWidget->widgetSize = QSize( 1, 1 ); videoWidget->widgetSize = QSize( 1, 1 );
videoWidget->resize( videoWidget->widgetSize ); //videoWidget->resize( videoWidget->widgetSize );
ui.vboxLayout->insertWidget( 0, videoWidget ); ui.vboxLayout->insertWidget( 0, videoWidget );
p_intf->pf_request_window = ::DoRequest; p_intf->pf_request_window = ::DoRequest;
...@@ -302,19 +305,30 @@ void MainInterface::handleMainUi( QSettings *settings ) ...@@ -302,19 +305,30 @@ void MainInterface::handleMainUi( QSettings *settings )
setMinimumSize( PREF_W, addSize.height() ); setMinimumSize( PREF_W, addSize.height() );
} }
void MainInterface::createSystrayMenu() /**
* Create a SystemTray icon and a menu that would go with it.
* Connects to a click handler on the icon.
**/
void MainInterface::createSystray()
{ {
QIcon iconVLC = QIcon( QPixmap( ":/vlc128.png" ) ); QIcon iconVLC = QIcon( QPixmap( ":/vlc128.png" ) );
sysTray = new QSystemTrayIcon( iconVLC, this ); sysTray = new QSystemTrayIcon( iconVLC, this );
sysTray->setToolTip( qtr( "VLC media player" ));
systrayMenu = new QMenu( qtr( "VLC media player" ), this ); systrayMenu = new QMenu( qtr( "VLC media player" ), this );
systrayMenu->setIcon( iconVLC ); systrayMenu->setIcon( iconVLC );
sysTray->setToolTip( qtr( "VLC media player" ));
QVLCMenu::updateSystrayMenu( this, p_intf, true ); QVLCMenu::updateSystrayMenu( this, p_intf, true );
sysTray->show(); sysTray->show();
CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ), CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) ); this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
} }
/**
* Update the menu of the Systray Icon.
* May be unneedded, since it just calls QVLCMenu::update
**/
void MainInterface::updateSystrayMenu( int status ) void MainInterface::updateSystrayMenu( int status )
{ {
QVLCMenu::updateSystrayMenu( this, p_intf ) ; QVLCMenu::updateSystrayMenu( this, p_intf ) ;
...@@ -341,7 +355,10 @@ void MainInterface::handleSystrayClick( QSystemTrayIcon::ActivationReason reason ...@@ -341,7 +355,10 @@ void MainInterface::handleSystrayClick( QSystemTrayIcon::ActivationReason reason
} }
} }
/**
* Updates the name of the systray Icon tooltip.
* Doesn't check if the systray exists, check before you call it.
**/
void MainInterface::updateSystrayTooltipName( QString name ) void MainInterface::updateSystrayTooltipName( QString name )
{ {
if( name.isEmpty() ) if( name.isEmpty() )
...@@ -354,29 +371,34 @@ void MainInterface::updateSystrayTooltipName( QString name ) ...@@ -354,29 +371,34 @@ void MainInterface::updateSystrayTooltipName( QString name )
} }
} }
/**
* Updates the status of the systray Icon tooltip.
* Doesn't check if the systray exists, check before you call it.
**/
void MainInterface::updateSystrayTooltipStatus( int i_status ) void MainInterface::updateSystrayTooltipStatus( int i_status )
{ {
switch( i_status ) switch( i_status )
{ {
case 0: case 0:
{ {
sysTray->setToolTip( qtr( "VLC media player" ) ); sysTray->setToolTip( qtr( "VLC media player" ) );
break; break;
} }
case PLAYING_S: case PLAYING_S:
{ {
sysTray->setToolTip( input_name ); sysTray->setToolTip( input_name );
//+ " - " + qtr( "Playing" ) ); //+ " - " + qtr( "Playing" ) );
break; break;
} }
case PAUSE_S: case PAUSE_S:
{ {
sysTray->setToolTip( input_name + " - " sysTray->setToolTip( input_name + " - "
+ qtr( "Paused") ); + qtr( "Paused") );
break; break;
} }
} }
} }
/********************************************************************** /**********************************************************************
* Handling of the components * Handling of the components
**********************************************************************/ **********************************************************************/
...@@ -793,7 +815,8 @@ void MainInterface::setStatus( int status ) ...@@ -793,7 +815,8 @@ void MainInterface::setStatus( int status )
ui.playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) ); ui.playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
else else
ui.playButton->setIcon( QIcon( ":/pixmaps/play.png" ) ); ui.playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
updateSystrayMenu( status ); if( systrayMenu )
updateSystrayMenu( status );
} }
#define HELP_MENU N_("Menu") #define HELP_MENU N_("Menu")
......
...@@ -241,6 +241,8 @@ QMenu *QVLCMenu::PlaylistMenu( MainInterface *mi, intf_thread_t *p_intf ) ...@@ -241,6 +241,8 @@ QMenu *QVLCMenu::PlaylistMenu( MainInterface *mi, intf_thread_t *p_intf )
{ {
QMenu *menu = new QMenu(); QMenu *menu = new QMenu();
menu->addMenu( SDMenu( p_intf ) ); menu->addMenu( SDMenu( p_intf ) );
menu->addAction ( QIcon(":/pixmaps/vlc_playlist_16px.png"),
qtr( "Playlist"), mi, SLOT( playlist() ) );
menu->addSeparator(); menu->addSeparator();
DP_SADD( menu, qtr( I_PL_LOAD ), "", "", openPlaylist(), "Ctrl+L" ); DP_SADD( menu, qtr( I_PL_LOAD ), "", "", openPlaylist(), "Ctrl+L" );
...@@ -287,8 +289,8 @@ QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf, MainInterface *mi, ...@@ -287,8 +289,8 @@ QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf, MainInterface *mi,
adv->setCheckable( true ); adv->setCheckable( true );
if( adv_controls_enabled ) adv->setChecked( true ); if( adv_controls_enabled ) adv->setChecked( true );
DP_SADD( menu, qtr( "Hide Menus..." ), "","",hideMenus(), "Ctrl+H" ); DP_SADD( menu, qtr( "Hide Menus..." ), "","",hideMenus(), "Ctrl+H" );
menu->addSeparator(); menu->addSeparator();
#if 0 /* For Visualisations. Not yet working */ #if 0 /* For Visualisations. Not yet working */
adv = menu->addAction( qtr("Visualizations selector" ), adv = menu->addAction( qtr("Visualizations selector" ),
...@@ -296,8 +298,8 @@ QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf, MainInterface *mi, ...@@ -296,8 +298,8 @@ QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf, MainInterface *mi,
adv->setCheckable( true ); adv->setCheckable( true );
if( visual_selector_enabled ) adv->setChecked( true ); if( visual_selector_enabled ) adv->setChecked( true );
#endif #endif
menu->addAction ( QIcon(":/pixmaps/vlc_playlist_16px.png"), menu->addAction ( QIcon(":/pixmaps/vlc_playlist_16px.png"),
qtr( "Playlist"), mi, SLOT( playlist() ) ); qtr( "Playlist"), mi, SLOT( playlist() ) );
} }
DP_SADD( menu, qtr( I_MENU_EXT ), "", ":/pixmaps/vlc_settings_16px.png", DP_SADD( menu, qtr( I_MENU_EXT ), "", ":/pixmaps/vlc_settings_16px.png",
extendedDialog() , "Ctrl+E" ); extendedDialog() , "Ctrl+E" );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment