1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-14 18:14:50 +02:00

Save and load cached twitter peers (no syncing actually done yet)

This commit is contained in:
Jeff Mitchell
2011-02-12 14:25:34 -05:00
parent 1744f3659e
commit 782a38ec5a
5 changed files with 56 additions and 13 deletions

View File

@@ -482,6 +482,20 @@ TomahawkSettings::setTwitterCachedMentionsSinceId( qint64 cachedId )
setValue( "twitter/cachedmentionssinceid", cachedId ); setValue( "twitter/cachedmentionssinceid", cachedId );
} }
QHash<QString, QVariant>
TomahawkSettings::twitterCachedPeers() const
{
QMutexLocker locker( m_safety );
return value( "twitter/cachedpeers", QHash<QString, QVariant>() ).toHash();
}
void
TomahawkSettings::setTwitterCachedPeers( const QHash<QString, QVariant> &cachedPeers )
{
QMutexLocker locker( m_safety );
setValue( "twitter/cachedpeers", cachedPeers );
}
bool bool
TomahawkSettings::scrobblingEnabled() const TomahawkSettings::scrobblingEnabled() const
{ {

View File

@@ -109,6 +109,9 @@ public:
qint64 twitterCachedMentionsSinceId() const; qint64 twitterCachedMentionsSinceId() const;
void setTwitterCachedMentionsSinceId( qint64 sinceid ); void setTwitterCachedMentionsSinceId( qint64 sinceid );
QHash<QString, QVariant> twitterCachedPeers() const;
void setTwitterCachedPeers( const QHash<QString, QVariant> &cachedPeers );
/// XMPP Component Settings /// XMPP Component Settings
QString xmppBotServer() const; QString xmppBotServer() const;
void setXmppBotServer( const QString &server ); void setXmppBotServer( const QString &server );

View File

@@ -21,6 +21,7 @@ SipHandler::SipHandler( QObject* parent )
SipHandler::~SipHandler() SipHandler::~SipHandler()
{ {
disconnectPlugins();
} }

View File

@@ -14,11 +14,13 @@
TwitterPlugin::TwitterPlugin() TwitterPlugin::TwitterPlugin()
: SipPlugin() : SipPlugin()
, m_isValid( false ) , m_isAuthed( false )
, m_checkTimer( this ) , m_checkTimer( this )
, m_cachedFriendsSinceId( 0 ) , m_cachedFriendsSinceId( 0 )
, m_cachedMentionsSinceId( 0 ) , m_cachedMentionsSinceId( 0 )
, m_cachedPeers()
{ {
qDebug() << Q_FUNC_INFO;
m_checkTimer.setInterval( 60000 ); m_checkTimer.setInterval( 60000 );
m_checkTimer.setSingleShot( false ); m_checkTimer.setSingleShot( false );
QObject::connect( &m_checkTimer, SIGNAL( timeout() ), SLOT( checkTimerFired() ) ); QObject::connect( &m_checkTimer, SIGNAL( timeout() ), SLOT( checkTimerFired() ) );
@@ -28,7 +30,7 @@ TwitterPlugin::TwitterPlugin()
bool bool
TwitterPlugin::isValid() TwitterPlugin::isValid()
{ {
return m_isValid; return m_isAuthed || !m_cachedPeers.isEmpty();
} }
const QString const QString
@@ -41,14 +43,22 @@ TwitterPlugin::name()
bool bool
TwitterPlugin::connectPlugin( bool /*startup*/ ) TwitterPlugin::connectPlugin( bool /*startup*/ )
{ {
qDebug() << "TwitterPlugin connectPlugin called"; qDebug() << Q_FUNC_INFO;
TomahawkSettings *settings = TomahawkSettings::instance(); TomahawkSettings *settings = TomahawkSettings::instance();
m_cachedPeers = settings->twitterCachedPeers();
QList<QString> peerlist = m_cachedPeers.keys();
qStableSort( peerlist.begin(), peerlist.end() );
foreach( QString key, peerlist )
{
qDebug() << "TwitterPlugin found cached peer with host " << m_cachedPeers[key].toHash()["host"].toString() << " and port " << m_cachedPeers[key].toHash()["port"].toString();
}
if ( settings->twitterOAuthToken().isEmpty() || settings->twitterOAuthTokenSecret().isEmpty() ) if ( settings->twitterOAuthToken().isEmpty() || settings->twitterOAuthTokenSecret().isEmpty() )
{ {
qDebug() << "Empty Twitter credentials; not connecting"; qDebug() << "TwitterPlugin has empty Twitter credentials; not connecting";
return false; return m_cachedPeers.isEmpty();
} }
delete m_twitterAuth.data(); delete m_twitterAuth.data();
@@ -71,10 +81,14 @@ TwitterPlugin::connectPlugin( bool /*startup*/ )
void void
TwitterPlugin::disconnectPlugin() TwitterPlugin::disconnectPlugin()
{ {
qDebug() << Q_FUNC_INFO;
if( !m_friendsTimeline.isNull() ) if( !m_friendsTimeline.isNull() )
m_friendsTimeline.data()->deleteLater(); m_friendsTimeline.data()->deleteLater();
if( !m_twitterAuth.isNull() ) if( !m_twitterAuth.isNull() )
m_twitterAuth.data()->deleteLater(); m_twitterAuth.data()->deleteLater();
TomahawkSettings::instance()->setTwitterCachedPeers( m_cachedPeers );
m_cachedPeers.empty();
} }
void void
@@ -82,13 +96,13 @@ TwitterPlugin::connectAuthVerifyReply( const QTweetUser &user )
{ {
if ( user.id() == 0 ) if ( user.id() == 0 )
{ {
qDebug() << "Could not authenticate to Twitter"; qDebug() << "TwitterPlugin could not authenticate to Twitter";
m_isValid = false; m_isAuthed = false;
} }
else else
{ {
qDebug() << "TwitterPlugin successfully authenticated to Twitter as user " << user.screenName(); qDebug() << "TwitterPlugin successfully authenticated to Twitter as user " << user.screenName();
m_isValid = true; m_isAuthed = true;
if ( !m_twitterAuth.isNull() ) if ( !m_twitterAuth.isNull() )
{ {
m_friendsTimeline = QWeakPointer<QTweetFriendsTimeline>( new QTweetFriendsTimeline( m_twitterAuth.data(), this ) ); m_friendsTimeline = QWeakPointer<QTweetFriendsTimeline>( new QTweetFriendsTimeline( m_twitterAuth.data(), this ) );
@@ -99,8 +113,8 @@ TwitterPlugin::connectAuthVerifyReply( const QTweetUser &user )
} }
else else
{ {
qDebug() << "Twitter auth pointer was null!"; qDebug() << "TwitterPlugin auth pointer was null!";
m_isValid = false; m_isAuthed = false;
} }
} }
} }
@@ -112,11 +126,13 @@ TwitterPlugin::checkTimerFired()
{ {
if ( m_cachedFriendsSinceId == 0 ) if ( m_cachedFriendsSinceId == 0 )
m_cachedFriendsSinceId = TomahawkSettings::instance()->twitterCachedFriendsSinceId(); m_cachedFriendsSinceId = TomahawkSettings::instance()->twitterCachedFriendsSinceId();
qDebug() << "TwitterPlugin using friend timeline id of " << m_cachedFriendsSinceId;
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();
qDebug() << "TwitterPlugin using mentions timeline id of " << m_cachedMentionsSinceId;
if ( !m_mentions.isNull() ) if ( !m_mentions.isNull() )
m_mentions.data()->fetch( m_cachedMentionsSinceId, 0, 800 ); m_mentions.data()->fetch( m_cachedMentionsSinceId, 0, 800 );
} }
@@ -125,7 +141,7 @@ TwitterPlugin::checkTimerFired()
void void
TwitterPlugin::friendsTimelineStatuses( const QList< QTweetStatus >& statuses ) TwitterPlugin::friendsTimelineStatuses( const QList< QTweetStatus >& statuses )
{ {
qDebug() << "TwitterPlugin checking friends"; qDebug() << Q_FUNC_INFO;
QRegExp regex( QString( "^(@[a-zA-Z0-9]+ )?Got Tomahawk\\?(.*)$" ) ); QRegExp regex( QString( "^(@[a-zA-Z0-9]+ )?Got Tomahawk\\?(.*)$" ) );
foreach( QTweetStatus status, statuses ) foreach( QTweetStatus status, statuses )
{ {
@@ -135,6 +151,10 @@ TwitterPlugin::friendsTimelineStatuses( const QList< QTweetStatus >& statuses )
if ( regex.exactMatch( statusText ) ) if ( regex.exactMatch( statusText ) )
{ {
qDebug() << "TwitterPlugin found an exact tweet from friend " << status.user().screenName(); qDebug() << "TwitterPlugin found an exact tweet from friend " << status.user().screenName();
QHash<QString, QVariant> peerData;
peerData["host"] = QVariant::fromValue<QString>( "somehost" );
peerData["port"] = QVariant::fromValue<QString>( "port" );
m_cachedPeers[status.user().screenName()] = QVariant::fromValue< QHash< QString, QVariant > >( peerData );
} }
} }
@@ -144,7 +164,7 @@ TwitterPlugin::friendsTimelineStatuses( const QList< QTweetStatus >& statuses )
void void
TwitterPlugin::mentionsStatuses( const QList< QTweetStatus >& statuses ) TwitterPlugin::mentionsStatuses( const QList< QTweetStatus >& statuses )
{ {
qDebug() << "TwitterPlugin checking mentions"; qDebug() << Q_FUNC_INFO;
QRegExp regex( QString( "^(@[a-zA-Z0-9]+ )?Got Tomahawk\\?(.*)$" ) ); QRegExp regex( QString( "^(@[a-zA-Z0-9]+ )?Got Tomahawk\\?(.*)$" ) );
foreach( QTweetStatus status, statuses ) foreach( QTweetStatus status, statuses )
{ {
@@ -154,6 +174,10 @@ TwitterPlugin::mentionsStatuses( const QList< QTweetStatus >& statuses )
if ( regex.exactMatch( statusText ) ) if ( regex.exactMatch( statusText ) )
{ {
qDebug() << "TwitterPlugin found an exact matching mention from user " << status.user().screenName(); qDebug() << "TwitterPlugin found an exact matching mention from user " << status.user().screenName();
QHash<QString, QVariant> peerData;
peerData["host"] = QVariant::fromValue<QString>( "somehost" );
peerData["port"] = QVariant::fromValue<QString>( "port" );
m_cachedPeers[status.user().screenName()] = QVariant::fromValue< QHash< QString, QVariant > >( peerData );
} }
} }

View File

@@ -56,10 +56,11 @@ private:
QWeakPointer<TomahawkOAuthTwitter> m_twitterAuth; QWeakPointer<TomahawkOAuthTwitter> m_twitterAuth;
QWeakPointer<QTweetFriendsTimeline> m_friendsTimeline; QWeakPointer<QTweetFriendsTimeline> m_friendsTimeline;
QWeakPointer<QTweetMentions> m_mentions; QWeakPointer<QTweetMentions> m_mentions;
bool m_isValid; bool m_isAuthed;
QTimer m_checkTimer; QTimer m_checkTimer;
qint64 m_cachedFriendsSinceId; qint64 m_cachedFriendsSinceId;
qint64 m_cachedMentionsSinceId; qint64 m_cachedMentionsSinceId;
QHash<QString, QVariant> m_cachedPeers;
}; };
#endif #endif