1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-05 05:37:29 +02:00

Hopefully fix TWK-13 crash bug.

This commit is contained in:
Jeff Mitchell
2011-03-29 09:58:14 -04:00
parent 6a605789e1
commit 0a0e27c717

View File

@@ -54,12 +54,10 @@ TwitterPlugin::TwitterPlugin()
m_checkTimer.setInterval( 60000 ); m_checkTimer.setInterval( 60000 );
m_checkTimer.setSingleShot( false ); m_checkTimer.setSingleShot( false );
connect( &m_checkTimer, SIGNAL( timeout() ), SLOT( checkTimerFired() ) ); connect( &m_checkTimer, SIGNAL( timeout() ), SLOT( checkTimerFired() ) );
m_checkTimer.start();
m_connectTimer.setInterval( 60000 ); m_connectTimer.setInterval( 60000 );
m_connectTimer.setSingleShot( false ); m_connectTimer.setSingleShot( false );
connect( &m_connectTimer, SIGNAL( timeout() ), SLOT( connectTimerFired() ) ); connect( &m_connectTimer, SIGNAL( timeout() ), SLOT( connectTimerFired() ) );
m_connectTimer.start();
} }
void void
@@ -144,13 +142,15 @@ TwitterPlugin::connectPlugin( bool /*startup*/ )
bool bool
TwitterPlugin::refreshTwitterAuth() TwitterPlugin::refreshTwitterAuth()
{ {
if( !m_twitterAuth.isNull() )
delete m_twitterAuth.data();
m_twitterAuth = QWeakPointer<TomahawkOAuthTwitter>( new TomahawkOAuthTwitter( this ) ); m_twitterAuth = QWeakPointer<TomahawkOAuthTwitter>( new TomahawkOAuthTwitter( this ) );
TomahawkSettings *settings = TomahawkSettings::instance(); if( m_twitterAuth.isNull() )
if ( m_twitterAuth.isNull() )
return false; return false;
TomahawkSettings *settings = TomahawkSettings::instance();
m_twitterAuth.data()->setNetworkAccessManager( TomahawkUtils::nam() ); m_twitterAuth.data()->setNetworkAccessManager( TomahawkUtils::nam() );
m_twitterAuth.data()->setOAuthToken( settings->twitterOAuthToken().toLatin1() ); m_twitterAuth.data()->setOAuthToken( settings->twitterOAuthToken().toLatin1() );
m_twitterAuth.data()->setOAuthTokenSecret( settings->twitterOAuthTokenSecret().toLatin1() ); m_twitterAuth.data()->setOAuthTokenSecret( settings->twitterOAuthTokenSecret().toLatin1() );
@@ -162,14 +162,23 @@ void
TwitterPlugin::disconnectPlugin() TwitterPlugin::disconnectPlugin()
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
m_checkTimer.stop();
m_connectTimer.stop();
if( !m_friendsTimeline.isNull() ) if( !m_friendsTimeline.isNull() )
m_friendsTimeline.data()->deleteLater(); delete m_friendsTimeline.data();
if( !m_mentions.isNull() )
delete m_mentions.data();
if( !m_directMessages.isNull() )
delete m_directMessages.data();
if( !m_directMessageNew.isNull() )
delete m_directMessageNew.data();
if( !m_directMessageDestroy.isNull() )
delete m_directMessageDestroy.data();
if( !m_twitterAuth.isNull() ) if( !m_twitterAuth.isNull() )
m_twitterAuth.data()->deleteLater(); delete m_twitterAuth.data();
m_cachedPeers.empty(); m_cachedPeers.empty();
m_attemptedConnects.empty(); m_attemptedConnects.empty();
delete m_twitterAuth.data();
m_isOnline = false; m_isOnline = false;
} }
@@ -200,6 +209,8 @@ TwitterPlugin::connectAuthVerifyReply( const QTweetUser &user )
connect( m_directMessageNew.data(), SIGNAL( error(QTweetNetBase::ErrorCode, const QString &) ), SLOT( directMessagePostError(QTweetNetBase::ErrorCode, const QString &) ) ); connect( m_directMessageNew.data(), SIGNAL( error(QTweetNetBase::ErrorCode, const QString &) ), SLOT( directMessagePostError(QTweetNetBase::ErrorCode, const QString &) ) );
connect( m_directMessageDestroy.data(), SIGNAL( parsedDirectMessage(const QTweetDMStatus &) ), SLOT( directMessageDestroyed(const QTweetDMStatus &) ) ); connect( m_directMessageDestroy.data(), SIGNAL( parsedDirectMessage(const QTweetDMStatus &) ), SLOT( directMessageDestroyed(const QTweetDMStatus &) ) );
m_isOnline = true; m_isOnline = true;
m_connectTimer.start();
m_checkTimer.start();
QMetaObject::invokeMethod( this, "checkTimerFired", Qt::AutoConnection ); QMetaObject::invokeMethod( this, "checkTimerFired", Qt::AutoConnection );
QTimer::singleShot( 20000, this, SLOT( connectTimerFired() ) ); QTimer::singleShot( 20000, this, SLOT( connectTimerFired() ) );
} }
@@ -223,24 +234,9 @@ TwitterPlugin::connectAuthVerifyReply( const QTweetUser &user )
void void
TwitterPlugin::checkTimerFired() TwitterPlugin::checkTimerFired()
{ {
if ( !isValid() ) if ( !isValid() || m_twitterAuth.isNull() )
return; return;
if ( m_twitterAuth.isNull() )
{
if ( refreshTwitterAuth() )
{
QTweetAccountVerifyCredentials *credVerifier = new QTweetAccountVerifyCredentials( m_twitterAuth.data(), this );
connect( credVerifier, SIGNAL( parsedUser(const QTweetUser &) ), SLOT( connectAuthVerifyReply(const QTweetUser &) ) );
credVerifier->verify();
}
else
{
qDebug() << "TwitterPlugin auth went null somehow and could not refresh";
return;
}
}
if ( m_cachedFriendsSinceId == 0 ) if ( m_cachedFriendsSinceId == 0 )
m_cachedFriendsSinceId = TomahawkSettings::instance()->twitterCachedFriendsSinceId(); m_cachedFriendsSinceId = TomahawkSettings::instance()->twitterCachedFriendsSinceId();
@@ -249,7 +245,6 @@ TwitterPlugin::checkTimerFired()
if ( !m_friendsTimeline.isNull() ) if ( !m_friendsTimeline.isNull() )
m_friendsTimeline.data()->fetch( m_cachedFriendsSinceId, 0, 800 ); m_friendsTimeline.data()->fetch( m_cachedFriendsSinceId, 0, 800 );
if ( m_cachedMentionsSinceId == 0 ) if ( m_cachedMentionsSinceId == 0 )
m_cachedMentionsSinceId = TomahawkSettings::instance()->twitterCachedMentionsSinceId(); m_cachedMentionsSinceId = TomahawkSettings::instance()->twitterCachedMentionsSinceId();
@@ -262,24 +257,9 @@ TwitterPlugin::checkTimerFired()
void void
TwitterPlugin::connectTimerFired() TwitterPlugin::connectTimerFired()
{ {
if ( !isValid() || m_cachedPeers.isEmpty() ) if ( !isValid() || m_cachedPeers.isEmpty() || m_twitterAuth.isNull() )
return; return;
if ( m_twitterAuth.isNull() )
{
if ( refreshTwitterAuth() )
{
QTweetAccountVerifyCredentials *credVerifier = new QTweetAccountVerifyCredentials( m_twitterAuth.data(), this );
connect( credVerifier, SIGNAL( parsedUser(const QTweetUser &) ), SLOT( connectAuthVerifyReply(const QTweetUser &) ) );
credVerifier->verify();
}
else
{
qDebug() << "TwitterPlugin auth went null somehow and could not refresh";
return;
}
}
QString myScreenName = TomahawkSettings::instance()->twitterScreenName(); QString myScreenName = TomahawkSettings::instance()->twitterScreenName();
QList<QString> peerlist = m_cachedPeers.keys(); QList<QString> peerlist = m_cachedPeers.keys();
qStableSort( peerlist.begin(), peerlist.end() ); qStableSort( peerlist.begin(), peerlist.end() );