1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-04-21 00:12:06 +02:00

sipPlugin() calls to most sips would automatically create if it did not already exist. But when shutting down and trying to disconnect a plugin, you don't want it constructing as you're shutting things down...it leads to crashes. Based on some of the code I looked at/touched, this will also fix a few places where sips were being connected when unexpected, like after changing some settings.

This commit is contained in:
Jeff Mitchell 2013-09-28 15:49:40 -04:00
parent 921a8e445f
commit 7aeda82761
13 changed files with 35 additions and 22 deletions

View File

@ -106,10 +106,13 @@ GoogleWrapper::~GoogleWrapper()
SipPlugin*
GoogleWrapper::sipPlugin()
GoogleWrapper::sipPlugin( bool create )
{
if ( m_xmppSipPlugin.isNull() )
{
if ( !create )
return 0;
m_xmppSipPlugin = QPointer< XmppSipPlugin >( new GoogleWrapperSip( const_cast< GoogleWrapper* >( this ) ) );
connect( m_xmppSipPlugin.data(), SIGNAL( stateChanged( Tomahawk::Accounts::Account::ConnectionState ) ), this, SIGNAL( connectionStateChanged( Tomahawk::Accounts::Account::ConnectionState ) ) );

View File

@ -72,7 +72,7 @@ public:
virtual const QString name() const { return QString( "Google" ); }
virtual const QString friendlyName() const { return "Google"; }
virtual SipPlugin* sipPlugin();
virtual SipPlugin* sipPlugin( bool create = true );
private:
QPointer< GoogleWrapperSip > m_sipPlugin;

View File

@ -151,7 +151,7 @@ void
HatchetAccount::deauthenticate()
{
if ( !m_tomahawkSipPlugin.isNull() )
sipPlugin()->disconnectPlugin();
m_tomahawkSipPlugin->disconnectPlugin();
emit deauthenticated();
}
@ -173,10 +173,13 @@ HatchetAccount::connectionState() const
SipPlugin*
HatchetAccount::sipPlugin()
HatchetAccount::sipPlugin( bool create )
{
if ( m_tomahawkSipPlugin.isNull() )
{
if ( !create )
return 0;
tLog() << Q_FUNC_INFO;
m_tomahawkSipPlugin = QPointer< HatchetSipPlugin >( new HatchetSipPlugin( this ) );
connect( m_tomahawkSipPlugin.data(), SIGNAL( authUrlDiscovered( Tomahawk::Accounts::HatchetAccount::Service, QString ) ),

View File

@ -81,7 +81,7 @@ public:
virtual Tomahawk::InfoSystem::InfoPluginPtr infoPlugin() { return Tomahawk::InfoSystem::InfoPluginPtr(); }
SipPlugin* sipPlugin();
SipPlugin* sipPlugin( bool create = true );
AccountConfigWidget* configurationWidget();
QWidget* aclWidget() { return 0; }

View File

@ -77,8 +77,8 @@ XmppAccount::authenticate()
void
XmppAccount::deauthenticate()
{
if ( connectionState() != Account::Disconnected )
sipPlugin()->disconnectPlugin();
if ( connectionState() != Account::Disconnected && !m_xmppSipPlugin.isNull() )
m_xmppSipPlugin->disconnectPlugin();
}
bool
@ -116,10 +116,13 @@ XmppAccount::infoPlugin()
SipPlugin*
XmppAccount::sipPlugin()
XmppAccount::sipPlugin( bool create )
{
if ( m_xmppSipPlugin.isNull() )
{
if ( !create )
return 0;
m_xmppSipPlugin = QPointer< XmppSipPlugin >( new XmppSipPlugin( this ) );
connect( m_xmppSipPlugin.data(), SIGNAL( stateChanged( Tomahawk::Accounts::Account::ConnectionState ) ), this, SIGNAL( connectionStateChanged( Tomahawk::Accounts::Account::ConnectionState ) ) );

View File

@ -73,7 +73,7 @@ public:
Tomahawk::InfoSystem::InfoPluginPtr infoPlugin();
SipPlugin* sipPlugin();
SipPlugin* sipPlugin( bool create = true );
AccountConfigWidget* configurationWidget() { return m_configWidget.data(); }
QWidget* aclWidget() { return 0; }

View File

@ -91,8 +91,8 @@ ZeroconfAccount::authenticate()
void
ZeroconfAccount::deauthenticate()
{
if ( isAuthenticated() )
sipPlugin()->disconnectPlugin();
if ( isAuthenticated() && !m_sipPlugin.isNull() )
m_sipPlugin->disconnectPlugin();
}
@ -110,15 +110,19 @@ ZeroconfAccount::connectionState() const
return Disconnected;
// TODO can we get called before sipPlugin()?
return m_sipPlugin.data()->connectionState();
return m_sipPlugin->connectionState();
}
SipPlugin*
ZeroconfAccount::sipPlugin()
ZeroconfAccount::sipPlugin( bool create )
{
if ( m_sipPlugin.isNull() )
if ( m_sipPlugin.isNull() ) {
if ( !create )
return 0;
m_sipPlugin = QPointer< ZeroconfPlugin >( new ZeroconfPlugin( this ) );
}
return m_sipPlugin.data();
}

View File

@ -69,7 +69,7 @@ public:
ConnectionState connectionState() const;
virtual Tomahawk::InfoSystem::InfoPluginPtr infoPlugin() { return Tomahawk::InfoSystem::InfoPluginPtr(); }
SipPlugin* sipPlugin();
SipPlugin* sipPlugin( bool create = true );
AccountConfigWidget* configurationWidget() { return 0; }
QWidget* aclWidget() { return 0; }

View File

@ -117,7 +117,7 @@ public:
virtual QString errorMessage() const { QMutexLocker locker( &m_mutex ); return m_cachedError; }
virtual Tomahawk::InfoSystem::InfoPluginPtr infoPlugin() = 0;
virtual SipPlugin* sipPlugin() = 0;
virtual SipPlugin* sipPlugin( bool create = true ) = 0;
// Some accounts cannot be enabled if authentication fails. Return true after failing to authenticate
// if this is the case, and the account will not be enabled

View File

@ -208,7 +208,7 @@ AccountManager::disconnectAll()
tDebug( LOGVERBOSE ) << Q_FUNC_INFO;
foreach ( Account* acc, m_enabledAccounts )
{
if ( acc->sipPlugin() )
if ( acc->sipPlugin( false ) )
{
tDebug() << Q_FUNC_INFO << "Disconnecting" << acc->accountFriendlyName();
acc->deauthenticate();
@ -440,7 +440,7 @@ AccountManager::zeroconfAccount() const
{
foreach ( Account* account, accounts() )
{
if ( account->sipPlugin() && account->sipPlugin()->serviceName() == "zeroconf" )
if ( account->sipPlugin( false ) && account->sipPlugin()->serviceName() == "zeroconf" )
return account;
}
@ -521,7 +521,7 @@ AccountManager::onSettingsChanged()
{
foreach ( Account* account, m_accounts )
{
if ( account->types() & Accounts::SipType && account->sipPlugin() )
if ( account->types() & Accounts::SipType && account->sipPlugin( false ) )
account->sipPlugin()->checkSettings();
}
}

View File

@ -92,7 +92,7 @@ public:
virtual QString version() const;
// Not relevant
virtual SipPlugin* sipPlugin() { return 0; }
virtual SipPlugin* sipPlugin( bool ) { return 0; }
virtual Tomahawk::InfoSystem::InfoPluginPtr infoPlugin() { return Tomahawk::InfoSystem::InfoPluginPtr(); }
virtual QWidget* aclWidget() { return 0; }

View File

@ -73,7 +73,7 @@ public:
virtual void deauthenticate();
virtual void authenticate();
virtual SipPlugin* sipPlugin() { return 0; }
virtual SipPlugin* sipPlugin( bool ) { return 0; }
virtual Tomahawk::InfoSystem::InfoPluginPtr infoPlugin();
virtual bool isAuthenticated() const;

View File

@ -100,7 +100,7 @@ public:
virtual QWidget* aclWidget() { return 0; }
virtual Tomahawk::InfoSystem::InfoPluginPtr infoPlugin();
virtual SipPlugin* sipPlugin() { return 0; }
virtual SipPlugin* sipPlugin( bool ) { return 0; }
virtual bool preventEnabling() const { return m_preventEnabling; }
bool hasPlaylist( const QString& plId );