1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-10 08:04:25 +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

View File

@@ -21,6 +21,7 @@
#include "tomahawksettings.h" #include "tomahawksettings.h"
#include "sip/SipHandler.h" #include "sip/SipHandler.h"
#include "sip/twitter/tomahawkoauthtwitter.h" #include "sip/twitter/tomahawkoauthtwitter.h"
#include <database/database.h>
static QString static QString
md5( const QByteArray& src ) md5( const QByteArray& src )
@@ -314,6 +315,7 @@ SettingsDialog::authenticateTwitter()
ui->twitterStatusLabel->setText("Status: No saved credentials"); ui->twitterStatusLabel->setText("Status: No saved credentials");
ui->twitterAuthenticateButton->setText( "Authenticate" ); ui->twitterAuthenticateButton->setText( "Authenticate" );
ui->twitterInstructionsBox->setVisible( false ); 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() ); twitAuth->setOAuthTokenSecret( s->twitterOAuthTokenSecret().toLatin1() );
QTweetStatusUpdate *statUpdate = new QTweetStatusUpdate( twitAuth, this ); QTweetStatusUpdate *statUpdate = new QTweetStatusUpdate( twitAuth, this );
connect( statUpdate, SIGNAL( postedStatus(const QTweetStatus &) ), SLOT( postGotTomahawkStatusUpdateReply(const QTweetStatus &) ) ); 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(); 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 void
@@ -364,6 +367,13 @@ SettingsDialog::postGotTomahawkStatusUpdateReply( const QTweetStatus& status )
else else
QMessageBox::information( 0, QString("Tweeted!"), QString("Your tweet has been posted!") ); 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 ) ProxyDialog::ProxyDialog( QWidget *parent )
: QDialog( parent ) : QDialog( parent )

View File

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

View File

@@ -473,16 +473,20 @@ When you press the button your web browser will launch and take you to Twitter.c
<item> <item>
<widget class="QLabel" name="twitterInstructionsInfoLabel"> <widget class="QLabel" name="twitterInstructionsInfoLabel">
<property name="text"> <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> </string>
</property> </property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="twitterTweetGotTomahawkButton"> <widget class="QPushButton" name="twitterTweetGotTomahawkButton">
<property name="text"> <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> </property>
</widget> </widget>
</item> </item>

View File

@@ -184,7 +184,7 @@ void
TwitterPlugin::friendsTimelineStatuses( const QList< QTweetStatus > &statuses ) TwitterPlugin::friendsTimelineStatuses( const QList< QTweetStatus > &statuses )
{ {
qDebug() << Q_FUNC_INFO; 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(); QString myScreenName = TomahawkSettings::instance()->twitterScreenName();
QHash< QString, QTweetStatus > latestHash; 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"; qDebug() << "TwitterPlugin skipping tweet because it's directed @someone that isn't us";
continue; 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; QHash< QString, QVariant > peerData;
if( m_cachedPeers.contains( status.user().screenName() ) ) if( m_cachedPeers.contains( status.user().screenName() ) )
{ {
peerData = m_cachedPeers[status.user().screenName()].toHash(); peerData = m_cachedPeers[status.user().screenName()].toHash();
//force a re-send of info but no need to re-register //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 ) ); 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 ) TwitterPlugin::mentionsStatuses( const QList< QTweetStatus > &statuses )
{ {
qDebug() << Q_FUNC_INFO; 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(); QString myScreenName = TomahawkSettings::instance()->twitterScreenName();
QHash< QString, QTweetStatus > latestHash; 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"; qDebug() << "TwitterPlugin skipping mention because it's directed @someone that isn't us";
continue; 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; QHash< QString, QVariant > peerData;
if( m_cachedPeers.contains( status.user().screenName() ) ) if( m_cachedPeers.contains( status.user().screenName() ) )
{ {
peerData = m_cachedPeers[status.user().screenName()].toHash(); peerData = m_cachedPeers[status.user().screenName()].toHash();
//force a re-send of info but no need to re-register //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 ) ); 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 ) TwitterPlugin::registerOffer( const QString &screenName, const QHash< QString, QVariant > &peerData )
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
QString node = QString( '@' + screenName ); QString friendlyName = QString( '@' + screenName );
bool peersChanged = false; bool peersChanged = false;
QHash< QString, QVariant > _peerData( peerData ); QHash< QString, QVariant > _peerData( peerData );
@@ -373,6 +413,13 @@ TwitterPlugin::registerOffer( const QString &screenName, const QHash< QString, Q
_peerData.remove( "dirty" ); _peerData.remove( "dirty" );
} }
if ( _peerData.contains( "resend" ) )
{
needToSend = true;
peersChanged = true;
_peerData.remove( "resend" );
}
if ( !_peerData.contains( "okey" ) ) if ( !_peerData.contains( "okey" ) )
{ {
QString okey = QUuid::createUuid().toString().split( '-' ).last(); QString okey = QUuid::createUuid().toString().split( '-' ).last();
@@ -392,13 +439,13 @@ TwitterPlugin::registerOffer( const QString &screenName, const QHash< QString, Q
) )
needToSend = true; needToSend = true;
if( needToAddToCache ) if( needToAddToCache && _peerData.contains( "node" ) )
{ {
qDebug() << "TwitterPlugin registering offer to " << node << " with node " << node << " and offeredkey " << _peerData["okey"].toString(); qDebug() << "TwitterPlugin registering offer to " << friendlyName << " with node " << _peerData["node"].toString() << " and offeredkey " << _peerData["okey"].toString();
m_keyCache << Servent::instance()->createConnectionKey( node, node, _peerData["okey"].toString(), false ); 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["ohst"] = QVariant::fromValue< QString >( Servent::instance()->externalAddress() );
_peerData["oprt"] = QVariant::fromValue< int >( Servent::instance()->externalPort() ); _peerData["oprt"] = QVariant::fromValue< int >( Servent::instance()->externalPort() );
@@ -431,18 +478,18 @@ void
TwitterPlugin::makeConnection( const QString &screenName, const QHash< QString, QVariant > &peerData ) TwitterPlugin::makeConnection( const QString &screenName, const QHash< QString, QVariant > &peerData )
{ {
qDebug() << Q_FUNC_INFO; 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; qDebug() << "TwitterPlugin could not find host and/or port and/or pkey for peer " << screenName;
return; return;
} }
QString node = QString( '@' + screenName ); QString friendlyName = QString( '@' + screenName );
if ( !Servent::instance()->connectedToSession( node ) ) if ( !Servent::instance()->connectedToSession( peerData["node"].toString() ) )
Servent::instance()->connectToPeer( peerData["host"].toString(), Servent::instance()->connectToPeer( peerData["host"].toString(),
peerData["port"].toString().toInt(), peerData["port"].toString().toInt(),
peerData["pkey"].toString(), peerData["pkey"].toString(),
node, friendlyName,
node ); peerData["node"].toString() );
} }
void void