From 75f99dca4f16947bfe92bee136790d50a0a962ac Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Wed, 22 May 2013 17:42:10 +0200 Subject: [PATCH] Wait for both Servent and AccountManager to be ready for initSIP. --- src/TomahawkApp.cpp | 43 ++++++++++++--------- src/TomahawkApp.h | 2 +- src/libtomahawk/accounts/AccountManager.cpp | 7 +++- src/libtomahawk/accounts/AccountManager.h | 11 ++++-- 4 files changed, 39 insertions(+), 24 deletions(-) diff --git a/src/TomahawkApp.cpp b/src/TomahawkApp.cpp index b623924e3..9da96882c 100644 --- a/src/TomahawkApp.cpp +++ b/src/TomahawkApp.cpp @@ -3,6 +3,7 @@ * Copyright 2010-2011, Christian Muehlhaeuser * Copyright 2010-2011, Leo Franchi * Copyright 2010-2012, Jeff Mitchell + * Copyright 2013, Teo Mrnjavac * * 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() { diff --git a/src/TomahawkApp.h b/src/TomahawkApp.h index ed2e3f632..761e63fdb 100644 --- a/src/TomahawkApp.h +++ b/src/TomahawkApp.h @@ -111,9 +111,9 @@ private slots: void initServent(); void initSIP(); void initHTTP(); + void initFactoriesForAccountManager(); void spotifyApiCheckFinished(); - void accountManagerReady(); private: void registerMetaTypes(); diff --git a/src/libtomahawk/accounts/AccountManager.cpp b/src/libtomahawk/accounts/AccountManager.cpp index a267ec411..8a855fa19 100644 --- a/src/libtomahawk/accounts/AccountManager.cpp +++ b/src/libtomahawk/accounts/AccountManager.cpp @@ -2,6 +2,7 @@ * * Copyright 2010-2011, Christian Muehlhaeuser * Copyright 2010-2011, Leo Franchi + * Copyright 2013, Teo Mrnjavac * * 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(); } diff --git a/src/libtomahawk/accounts/AccountManager.h b/src/libtomahawk/accounts/AccountManager.h index 7b3076dfb..598591f06 100644 --- a/src/libtomahawk/accounts/AccountManager.h +++ b/src/libtomahawk/accounts/AccountManager.h @@ -2,6 +2,7 @@ * * Copyright 2010-2011, Christian Muehlhaeuser * Copyright 2010-2011, Leo Franchi + * Copyright 2013, Teo Mrnjavac * * 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;