1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-14 01:54:07 +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, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org> * Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
* Copyright 2010-2012, Jeff Mitchell <jeff@tomahawk-player.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 * Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -249,7 +250,8 @@ TomahawkApp::init()
tDebug() << "Init AccountManager."; tDebug() << "Init AccountManager.";
m_accountManager = QPointer< Tomahawk::Accounts::AccountManager >( new Tomahawk::Accounts::AccountManager( this ) ); 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() ); Echonest::Config::instance()->setNetworkAccessManager( TomahawkUtils::nam() );
#ifndef ENABLE_HEADLESS #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 void
TomahawkApp::initSIP() TomahawkApp::initSIP()
{ {
tDebug() << Q_FUNC_INFO; 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 //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"; tDebug( LOGINFO ) << "Connecting SIP classes";
Accounts::AccountManager::instance()->initSIP(); 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 void
TomahawkApp::activate() TomahawkApp::activate()
{ {

View File

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

View File

@@ -2,6 +2,7 @@
* *
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org> * Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.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 * Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -55,6 +56,7 @@ AccountManager::instance()
AccountManager::AccountManager( QObject *parent ) AccountManager::AccountManager( QObject *parent )
: QObject( parent ) : QObject( parent )
, m_readyForSip( false )
{ {
s_instance = this; s_instance = this;
@@ -89,7 +91,7 @@ AccountManager::init()
m_accountFactories[ f->factoryId() ] = f; m_accountFactories[ f->factoryId() ] = f;
registerAccountFactoryForFilesystem( 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 ); 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, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.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 * Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -47,7 +48,7 @@ public:
virtual ~AccountManager(); virtual ~AccountManager();
void loadFromConfig(); void loadFromConfig();
void initSIP(); void initSIP(); //only call this after isReadyForSip returns true
void enableAccount( Account* account ); void enableAccount( Account* account );
void disableAccount( Account* account ); void disableAccount( Account* account );
@@ -84,7 +85,9 @@ public:
Account* zeroconfAccount() const; Account* zeroconfAccount() const;
bool isConnected() { return m_connected; } bool isConnected() const { return m_connected; }
bool isReadyForSip() const { return m_readyForSip; }
public slots: public slots:
void connectAll(); void connectAll();
@@ -92,7 +95,8 @@ public slots:
void toggleAccountsConnected(); void toggleAccountsConnected();
signals: 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 added( Tomahawk::Accounts::Account* );
void removed( Tomahawk::Accounts::Account* ); void removed( Tomahawk::Accounts::Account* );
@@ -126,6 +130,7 @@ private:
QList< Account* > m_enabledAccounts; QList< Account* > m_enabledAccounts;
QList< Account* > m_connectedAccounts; QList< Account* > m_connectedAccounts;
bool m_connected; bool m_connected;
bool m_readyForSip;
QHash< AccountType, QList< Account* > > m_accountsByAccountType; QHash< AccountType, QList< Account* > > m_accountsByAccountType;
QHash< QString, AccountFactory* > m_accountFactories; QHash< QString, AccountFactory* > m_accountFactories;