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

A fix for the introduced crash in liblastfm, ready for more lfranchi debugging

This commit is contained in:
Jeff Mitchell
2011-05-03 16:58:10 -04:00
parent dd4d268c11
commit 97ca55fd53
9 changed files with 21 additions and 9 deletions

View File

@@ -169,6 +169,7 @@ InfoSystemWorker::newNam()
{
qDebug() << Q_FUNC_INFO << " begin";
Q_ASSERT( TomahawkUtils::nam() != 0 );
QNetworkAccessManager *oldNam = TomahawkUtils::nam();
if ( oldNam && oldNam->thread() == thread() )
{

View File

@@ -337,6 +337,7 @@ AlbumModel::onCoverArtDownloaded()
// Follow HTTP redirect
QNetworkRequest req( redir );
req.setAttribute( QNetworkRequest::User, reply->request().attribute( QNetworkRequest::User ) );
Q_ASSERT( TomahawkUtils::nam() != 0 );
QNetworkReply* reply = TomahawkUtils::nam()->get( req );
connect( reply, SIGNAL( finished() ), SLOT( onCoverArtDownloaded() ) );
}

View File

@@ -340,13 +340,16 @@ createDragPixmap( int itemCount )
}
QNetworkAccessManager* s_nam = 0;
QNetworkProxy* s_proxy = 0;
QWeakPointer< QNetworkAccessManager > s_nam;
QNetworkProxy* s_proxy;
QNetworkAccessManager*
nam()
{
return s_nam;
if ( s_nam.isNull() )
return 0;
return s_nam.data();
}
@@ -360,7 +363,7 @@ proxy()
void
setNam( QNetworkAccessManager* nam )
{
s_nam = nam;
s_nam = QWeakPointer< QNetworkAccessManager >( nam );
}

View File

@@ -40,6 +40,7 @@ void
XSPFLoader::load( const QUrl& url )
{
QNetworkRequest request( url );
Q_ASSERT( TomahawkUtils::nam() != 0 );
QNetworkReply* reply = TomahawkUtils::nam()->get( request );
// isn't there a race condition here? something could happen before we connect()

View File

@@ -324,6 +324,7 @@ ProxyDialog::saveSettings()
// Now, set QNAM
QNetworkProxy proxy( static_cast<QNetworkProxy::ProxyType>(s->proxyType()), s->proxyHost(), s->proxyPort(), s->proxyUsername(), s->proxyPassword() );
Q_ASSERT( TomahawkUtils::nam() != 0 );
QNetworkAccessManager* nam = TomahawkUtils::nam();
nam->setProxy( proxy );
QNetworkProxy* globalProxy = TomahawkUtils::proxy();

View File

@@ -146,6 +146,7 @@ TwitterPlugin::refreshTwitterAuth()
if( !m_twitterAuth.isNull() )
delete m_twitterAuth.data();
Q_ASSERT( TomahawkUtils::nam() != 0 );
qDebug() << Q_FUNC_INFO << " with nam " << TomahawkUtils::nam();
m_twitterAuth = QWeakPointer<TomahawkOAuthTwitter>( new TomahawkOAuthTwitter( TomahawkUtils::nam(), this ) );

View File

@@ -198,7 +198,6 @@ TomahawkApp::init()
qDebug() << "Proxy type =" << QString::number( static_cast<int>(TomahawkUtils::proxy()->type()) );
qDebug() << "Proxy host =" << TomahawkUtils::proxy()->hostName();
TomahawkUtils::nam()->setProxy( *TomahawkUtils::proxy() );
lastfm::nam()->setProxy( *TomahawkUtils::proxy() );
}
else
TomahawkUtils::setProxy( new QNetworkProxy( QNetworkProxy::NoProxy ) );

View File

@@ -162,6 +162,7 @@ TomahawkWindow::TomahawkWindow( QWidget* parent )
updaterUrl.setUrl( "http://download.tomahawk-player.org/sparklewin" );
qtsparkle::Updater* updater = new qtsparkle::Updater( updaterUrl, this );
Q_ASSERT( TomahawkUtils::nam() != 0 );
updater->SetNetworkAccessManager( TomahawkUtils::nam() );
updater->SetVersion( TOMAHAWK_VERSION );

View File

@@ -30,7 +30,7 @@
#include <QUrl>
static QMap< QThread*, QNetworkAccessManager* > threadNamHash;
static QMap< QThread*, bool > ourNamHash;
static QSet< QThread* > ourNamSet;
static QMutex namAccessMutex;
QString
@@ -205,10 +205,11 @@ lastfm::nam()
qDebug() << Q_FUNC_INFO << " does not yet have a NAM, creating a new one";
NetworkAccessManager* newNam = new NetworkAccessManager();
threadNamHash[thread] = newNam;
ourNamHash[thread] = true;
ourNamSet.insert( thread );
qDebug() << Q_FUNC_INFO << " returning " << threadNamHash[thread];
return newNam;
}
Q_ASSERT( threadNamHash[thread] );
qDebug() << Q_FUNC_INFO << " found a nam, is " << threadNamHash[thread];
return threadNamHash[thread];
}
@@ -223,11 +224,14 @@ lastfm::setNetworkAccessManager( QNetworkAccessManager* nam )
QMutexLocker l( &namAccessMutex );
QThread* thread = QThread::currentThread();
QNetworkAccessManager* oldNam = 0;
if ( threadNamHash.contains( thread ) && ourNamHash.contains( thread ) && ourNamHash[thread] )
if ( threadNamHash.contains( thread ) && ourNamSet.contains( thread ) )
oldNam = threadNamHash[thread];
if ( oldNam == nam )
return;
threadNamHash[thread] = nam;
ourNamHash[thread] = false;
ourNamSet.remove( thread );
if ( oldNam )
delete oldNam;