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