1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-13 09:34:53 +02:00

Wait for both Servent and AccountManager to be ready for initSIP.

This commit is contained in:
Teo Mrnjavac
2013-05-22 17:42:10 +02:00
parent f47d8ddf74
commit 75f99dca4f
4 changed files with 39 additions and 24 deletions

View File

@@ -3,6 +3,7 @@
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
* Copyright 2010-2012, Jeff Mitchell <jeff@tomahawk-player.org>
* Copyright 2013, Teo Mrnjavac <teo@kde.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -249,7 +250,8 @@ TomahawkApp::init()
tDebug() << "Init AccountManager.";
m_accountManager = QPointer< Tomahawk::Accounts::AccountManager >( new Tomahawk::Accounts::AccountManager( this ) );
connect( m_accountManager.data(), SIGNAL( ready() ), SLOT( accountManagerReady() ) );
connect( m_accountManager.data(), SIGNAL( readyForFactories() ), SLOT( initFactoriesForAccountManager() ) );
connect( m_accountManager.data(), SIGNAL( readyForSip() ), SLOT( initSIP() ) );
Echonest::Config::instance()->setNetworkAccessManager( TomahawkUtils::nam() );
#ifndef ENABLE_HEADLESS
@@ -616,13 +618,32 @@ TomahawkApp::initServent()
}
// Called after Servent emits ready()
void
TomahawkApp::initFactoriesForAccountManager()
{
#ifdef LIBLASTFM_FOUND
Tomahawk::Accounts::LastFmAccountFactory* lastfmFactory = new Tomahawk::Accounts::LastFmAccountFactory();
m_accountManager.data()->addAccountFactory( lastfmFactory );
#endif
Tomahawk::Accounts::SpotifyAccountFactory* spotifyFactory = new Tomahawk::Accounts::SpotifyAccountFactory;
m_accountManager.data()->addAccountFactory( spotifyFactory );
m_accountManager.data()->registerAccountFactoryForFilesystem( spotifyFactory );
Tomahawk::Accounts::AccountManager::instance()->loadFromConfig();
}
// This method will be called twice during Tomahawk startup.
// We don't know which is going to be ready first, AccountManager or Servent, but this goes through
// only when both are.
void
TomahawkApp::initSIP()
{
tDebug() << Q_FUNC_INFO;
//FIXME: jabber autoconnect is really more, now that there is sip -- should be renamed and/or split out of jabber-specific settings
if ( !arguments().contains( "--nosip" ) )
if ( !arguments().contains( "--nosip" ) &&
Servent::instance()->isReady() && Accounts::AccountManager::instance()->isReadyForSip() )
{
tDebug( LOGINFO ) << "Connecting SIP classes";
Accounts::AccountManager::instance()->initSIP();
@@ -645,22 +666,6 @@ TomahawkApp::spotifyApiCheckFinished()
}
void
TomahawkApp::accountManagerReady()
{
#ifdef LIBLASTFM_FOUND
Tomahawk::Accounts::LastFmAccountFactory* lastfmFactory = new Tomahawk::Accounts::LastFmAccountFactory();
m_accountManager.data()->addAccountFactory( lastfmFactory );
#endif
Tomahawk::Accounts::SpotifyAccountFactory* spotifyFactory = new Tomahawk::Accounts::SpotifyAccountFactory;
m_accountManager.data()->addAccountFactory( spotifyFactory );
m_accountManager.data()->registerAccountFactoryForFilesystem( spotifyFactory );
Tomahawk::Accounts::AccountManager::instance()->loadFromConfig();
}
void
TomahawkApp::activate()
{

View File

@@ -111,9 +111,9 @@ private slots:
void initServent();
void initSIP();
void initHTTP();
void initFactoriesForAccountManager();
void spotifyApiCheckFinished();
void accountManagerReady();
private:
void registerMetaTypes();

View File

@@ -2,6 +2,7 @@
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
* Copyright 2013, Teo Mrnjavac <teo@kde.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -55,6 +56,7 @@ AccountManager::instance()
AccountManager::AccountManager( QObject *parent )
: QObject( parent )
, m_readyForSip( false )
{
s_instance = this;
@@ -89,7 +91,7 @@ AccountManager::init()
m_accountFactories[ f->factoryId() ] = f;
registerAccountFactoryForFilesystem( f );
emit ready(); //Notifies TomahawkApp to load the remaining AccountFactories, then Accounts from config
emit readyForFactories(); //Notifies TomahawkApp to load the remaining AccountFactories, then Accounts from config
}
@@ -304,6 +306,9 @@ AccountManager::finishLoadingFromConfig()
addAccount( account );
}
}
m_readyForSip = true;
emit readyForSip();
}

View File

@@ -2,6 +2,7 @@
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
* Copyright 2013, Teo Mrnjavac <teo@kde.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -47,7 +48,7 @@ public:
virtual ~AccountManager();
void loadFromConfig();
void initSIP();
void initSIP(); //only call this after isReadyForSip returns true
void enableAccount( Account* account );
void disableAccount( Account* account );
@@ -84,7 +85,9 @@ public:
Account* zeroconfAccount() const;
bool isConnected() { return m_connected; }
bool isConnected() const { return m_connected; }
bool isReadyForSip() const { return m_readyForSip; }
public slots:
void connectAll();
@@ -92,7 +95,8 @@ public slots:
void toggleAccountsConnected();
signals:
void ready();
void readyForFactories(); //this happens first, right before loading accounts from config
void readyForSip(); //then this, so TomahawkApp can call initSIP if Servent is ready
void added( Tomahawk::Accounts::Account* );
void removed( Tomahawk::Accounts::Account* );
@@ -126,6 +130,7 @@ private:
QList< Account* > m_enabledAccounts;
QList< Account* > m_connectedAccounts;
bool m_connected;
bool m_readyForSip;
QHash< AccountType, QList< Account* > > m_accountsByAccountType;
QHash< QString, AccountFactory* > m_accountFactories;