1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-04-22 17:01:51 +02:00

Send node information in initial Got Tomahawk message

This commit is contained in:
Jeff Mitchell 2011-02-13 12:41:39 -05:00
parent d48a7b11fa
commit b3acdd3795
4 changed files with 81 additions and 18 deletions

@ -21,6 +21,7 @@
#include "tomahawksettings.h"
#include "sip/SipHandler.h"
#include "sip/twitter/tomahawkoauthtwitter.h"
#include <database/database.h>
static QString
md5( const QByteArray& src )
@ -314,6 +315,7 @@ SettingsDialog::authenticateTwitter()
ui->twitterStatusLabel->setText("Status: No saved credentials");
ui->twitterAuthenticateButton->setText( "Authenticate" );
ui->twitterInstructionsBox->setVisible( false );
QMessageBox::critical( 0, QString("Tweetin' Error"), QString("There was an error validating your authentication") );
}
}
@ -352,8 +354,9 @@ SettingsDialog::postGotTomahawkStatusAuthVerifyReply( const QTweetUser &user )
twitAuth->setOAuthTokenSecret( s->twitterOAuthTokenSecret().toLatin1() );
QTweetStatusUpdate *statUpdate = new QTweetStatusUpdate( twitAuth, this );
connect( statUpdate, SIGNAL( postedStatus(const QTweetStatus &) ), SLOT( postGotTomahawkStatusUpdateReply(const QTweetStatus &) ) );
connect( statUpdate, SIGNAL( error(QTweetNetBase::ErrorCode, const QString&) ), SLOT( postGotTomahawkStatusUpdateError(QTweetNetBase::ErrorCode, const QString &) ) );
QString uuid = QUuid::createUuid();
statUpdate->post( QString( "Got Tomahawk? (" ) + uuid.mid( 1, 8 ) + ")" );
statUpdate->post( QString( "Got Tomahawk? {" ) + Database::instance()->dbid() + QString( "} (" ) + uuid.mid( 1, 8 ) + QString( ")" ) );
}
void
@ -364,6 +367,13 @@ SettingsDialog::postGotTomahawkStatusUpdateReply( const QTweetStatus& status )
else
QMessageBox::information( 0, QString("Tweeted!"), QString("Your tweet has been posted!") );
}
void
SettingsDialog::postGotTomahawkStatusUpdateError( QTweetNetBase::ErrorCode code, const QString& errorMsg )
{
qDebug() << Q_FUNC_INFO;
qDebug() << "Error posting Got Tomahawk message, error code is " << code << ", error message is " << errorMsg;
QMessageBox::critical( 0, QString("Tweetin' Error"), QString("There was an error posting your status -- sorry!") );
}
ProxyDialog::ProxyDialog( QWidget *parent )
: QDialog( parent )

@ -5,6 +5,7 @@
#include <qtweetstatus.h>
#include <qtweetuser.h>
#include <qtweetnetbase.h>
class QNetworkReply;
@ -58,7 +59,8 @@ private slots:
void startPostGotTomahawkStatus();
void postGotTomahawkStatusAuthVerifyReply( const QTweetUser &user );
void postGotTomahawkStatusUpdateReply( const QTweetStatus &status );
void postGotTomahawkStatusUpdateError( QTweetNetBase::ErrorCode, const QString &errorMsg );
void addScriptResolver();
void scriptSelectionChanged();
void removeScriptResolver();

@ -473,16 +473,20 @@ When you press the button your web browser will launch and take you to Twitter.c
<item>
<widget class="QLabel" name="twitterInstructionsInfoLabel">
<property name="text">
<string>How it works is simple: just tweet &quot;Got Tomahawk?&quot; and be (very) patient. It can take a bit.
<string>How it works is simple: just press the button below to tweet &quot;Got Tomahawk?&quot; and some necessary information. Then be (very) patient. Twitter is an asynchronous protocol so it can take a bit!
If connections to peers seem to have been lost, just press the button again to re-post a tweet for resynchronization.
</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="twitterTweetGotTomahawkButton">
<property name="text">
<string>Press here if you'd like to have Tomahawk tweet this for you</string>
<string>Press here to have Tomahawk post a tweet</string>
</property>
</widget>
</item>

@ -184,7 +184,7 @@ void
TwitterPlugin::friendsTimelineStatuses( const QList< QTweetStatus > &statuses )
{
qDebug() << Q_FUNC_INFO;
QRegExp regex( QString( "^(@[a-zA-Z0-9]+ )?Got Tomahawk\\?(.*)$" ), Qt::CaseSensitive, QRegExp::RegExp2 );
QRegExp regex( QString( "^(@[a-zA-Z0-9]+ )?(Got Tomahawk\\?) (\\{[a-fA-F0-9\\-]+\\}) (.*)$" ), Qt::CaseSensitive, QRegExp::RegExp2 );
QString myScreenName = TomahawkSettings::instance()->twitterScreenName();
QHash< QString, QTweetStatus > latestHash;
@ -213,13 +213,33 @@ TwitterPlugin::friendsTimelineStatuses( const QList< QTweetStatus > &statuses )
qDebug() << "TwitterPlugin skipping tweet because it's directed @someone that isn't us";
continue;
}
QString node;
for ( int i = 0; i < regex.captureCount(); ++i )
{
if ( regex.cap( i ) == QString( "Got Tomahawk?" ) )
{
QString nodeCap = regex.cap( i + 1 );
nodeCap.chop( 1 );
node = nodeCap.mid( 1 );
}
}
if ( node.isEmpty() )
{
qDebug() << "TwitterPlugin could not parse node out of the tweet";
continue;
}
else
qDebug() << "TwitterPlugin parsed node " << node << " out of the tweet";
QHash< QString, QVariant > peerData;
if( m_cachedPeers.contains( status.user().screenName() ) )
{
peerData = m_cachedPeers[status.user().screenName()].toHash();
//force a re-send of info but no need to re-register
peerData["oprt"] = Servent::instance()->externalPort() + 1;
peerData["resend"] = QVariant::fromValue< bool >( true );
}
peerData["node"] = QVariant::fromValue< QString >( node );
QMetaObject::invokeMethod( this, "registerOffer", Q_ARG( QString, status.user().screenName() ), QGenericArgument( "QHash< QString, QVariant >", (const void*)&peerData ) );
}
}
@ -234,7 +254,7 @@ void
TwitterPlugin::mentionsStatuses( const QList< QTweetStatus > &statuses )
{
qDebug() << Q_FUNC_INFO;
QRegExp regex( QString( "^(@[a-zA-Z0-9]+ )?Got Tomahawk\\?(.*)$" ), Qt::CaseSensitive, QRegExp::RegExp2 );
QRegExp regex( QString( "^(@[a-zA-Z0-9]+ )?(Got Tomahawk\\?) (\\{[a-fA-F0-9\\-]+\\}) (.*)$" ), Qt::CaseSensitive, QRegExp::RegExp2 );
QString myScreenName = TomahawkSettings::instance()->twitterScreenName();
QHash< QString, QTweetStatus > latestHash;
@ -263,13 +283,33 @@ TwitterPlugin::mentionsStatuses( const QList< QTweetStatus > &statuses )
qDebug() << "TwitterPlugin skipping mention because it's directed @someone that isn't us";
continue;
}
QString node;
for ( int i = 0; i < regex.captureCount(); ++i )
{
if ( regex.cap( i ) == QString( "Got Tomahawk?" ) )
{
QString nodeCap = regex.cap( i + 1 );
nodeCap.chop( 1 );
node = nodeCap.mid( 1 );
}
}
if ( node.isEmpty() )
{
qDebug() << "TwitterPlugin could not parse node out of the tweet";
continue;
}
else
qDebug() << "TwitterPlugin parsed node " << node << " out of the tweet";
QHash< QString, QVariant > peerData;
if( m_cachedPeers.contains( status.user().screenName() ) )
{
peerData = m_cachedPeers[status.user().screenName()].toHash();
//force a re-send of info but no need to re-register
peerData["oprt"] = Servent::instance()->externalPort() + 1;
peerData["resend"] = QVariant::fromValue< bool >( true );
}
peerData["node"] = QVariant::fromValue< QString >( node );
QMetaObject::invokeMethod( this, "registerOffer", Q_ARG( QString, status.user().screenName() ), QGenericArgument( "QHash< QString, QVariant >", (const void*)&peerData ) );
}
}
@ -360,7 +400,7 @@ void
TwitterPlugin::registerOffer( const QString &screenName, const QHash< QString, QVariant > &peerData )
{
qDebug() << Q_FUNC_INFO;
QString node = QString( '@' + screenName );
QString friendlyName = QString( '@' + screenName );
bool peersChanged = false;
QHash< QString, QVariant > _peerData( peerData );
@ -373,6 +413,13 @@ TwitterPlugin::registerOffer( const QString &screenName, const QHash< QString, Q
_peerData.remove( "dirty" );
}
if ( _peerData.contains( "resend" ) )
{
needToSend = true;
peersChanged = true;
_peerData.remove( "resend" );
}
if ( !_peerData.contains( "okey" ) )
{
QString okey = QUuid::createUuid().toString().split( '-' ).last();
@ -392,13 +439,13 @@ TwitterPlugin::registerOffer( const QString &screenName, const QHash< QString, Q
)
needToSend = true;
if( needToAddToCache )
if( needToAddToCache && _peerData.contains( "node" ) )
{
qDebug() << "TwitterPlugin registering offer to " << node << " with node " << node << " and offeredkey " << _peerData["okey"].toString();
m_keyCache << Servent::instance()->createConnectionKey( node, node, _peerData["okey"].toString(), false );
qDebug() << "TwitterPlugin registering offer to " << friendlyName << " with node " << _peerData["node"].toString() << " and offeredkey " << _peerData["okey"].toString();
m_keyCache << Servent::instance()->createConnectionKey( friendlyName, _peerData["node"].toString(), _peerData["okey"].toString(), false );
}
if( needToSend )
if( needToSend && _peerData.contains( "node") )
{
_peerData["ohst"] = QVariant::fromValue< QString >( Servent::instance()->externalAddress() );
_peerData["oprt"] = QVariant::fromValue< int >( Servent::instance()->externalPort() );
@ -431,18 +478,18 @@ void
TwitterPlugin::makeConnection( const QString &screenName, const QHash< QString, QVariant > &peerData )
{
qDebug() << Q_FUNC_INFO;
if ( !peerData.contains( "host" ) || !peerData.contains( "port" ) || !peerData.contains( "pkey" ) )
if ( !peerData.contains( "host" ) || !peerData.contains( "port" ) || !peerData.contains( "pkey" ) || !peerData.contains( "node" ) )
{
qDebug() << "TwitterPlugin could not find host and/or port and/or pkey for peer " << screenName;
return;
}
QString node = QString( '@' + screenName );
if ( !Servent::instance()->connectedToSession( node ) )
QString friendlyName = QString( '@' + screenName );
if ( !Servent::instance()->connectedToSession( peerData["node"].toString() ) )
Servent::instance()->connectToPeer( peerData["host"].toString(),
peerData["port"].toString().toInt(),
peerData["pkey"].toString(),
node,
node );
friendlyName,
peerData["node"].toString() );
}
void