1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-04-21 08:21:54 +02:00

Tomahawk can now send a Got Tomahawk? tweet for you (also PoC of the

authentication verification and status posting bits)
This commit is contained in:
Jeff Mitchell 2011-02-12 01:46:59 -05:00
parent 9a7ecddfda
commit 9a69fb34c3
5 changed files with 106 additions and 2 deletions

View File

@ -302,6 +302,7 @@ include_directories( . ${CMAKE_CURRENT_BINARY_DIR} ..
../../thirdparty/jdns
../../thirdparty/jdns/jdns
../../thirdparty/jdns/jdnsshared
../../thirdparty/qtweetlib/src
playlist
)

View File

@ -19,6 +19,8 @@
#include "tomahawksettings.h"
#include "sip/SipHandler.h"
#include "sip/twitter/tomahawkoauthtwitter.h"
#include <qtweetaccountverifycredentials.h>
#include <qtweetstatusupdate.h>
static QString
@ -67,11 +69,13 @@ SettingsDialog::SettingsDialog( QWidget *parent )
{
ui->twitterStatusLabel->setText("Status: No saved credentials");
ui->twitterAuthenticateButton->setText( "Authenticate" );
ui->twitterInstructionsBox->setVisible( false );
}
else
{
ui->twitterStatusLabel->setText("Status: Credentials saved");
ui->twitterAuthenticateButton->setText( "Re-authenticate" );
ui->twitterInstructionsBox->setVisible( true );
}
// MUSIC SCANNER
@ -298,6 +302,7 @@ SettingsDialog::authenticateTwitter()
s->setTwitterOAuthTokenSecret( twitAuth->oauthTokenSecret() );
ui->twitterStatusLabel->setText("Status: Credentials saved");
ui->twitterAuthenticateButton->setText( "Re-authenticate" );
ui->twitterInstructionsBox->setVisible( true );
}
else
{
@ -306,9 +311,56 @@ SettingsDialog::authenticateTwitter()
s->setTwitterOAuthTokenSecret( QString() );
ui->twitterStatusLabel->setText("Status: No saved credentials");
ui->twitterAuthenticateButton->setText( "Authenticate" );
ui->twitterInstructionsBox->setVisible( false );
}
}
void
SettingsDialog::startPostGotTomahawkStatus()
{
qDebug() << "Posting Got Tomahawk status";
TomahawkSettings* s = TomahawkSettings::instance();
if ( s->twitterOAuthToken().isEmpty() || s->twitterOAuthTokenSecret().isEmpty() )
{
QMessageBox::critical( 0, QString("Tweetin' Error"), QString("Your saved credentials could not be loaded.\nYou may wish to try re-authenticating.") );
return;
}
TomahawkOAuthTwitter *twitAuth = new TomahawkOAuthTwitter( this );
twitAuth->setNetworkAccessManager( TomahawkUtils::nam() );
twitAuth->setOAuthToken( s->twitterOAuthToken().toLatin1() );
twitAuth->setOAuthTokenSecret( s->twitterOAuthTokenSecret().toLatin1() );
QTweetAccountVerifyCredentials *credVerifier = new QTweetAccountVerifyCredentials( twitAuth, this );
connect( credVerifier, SIGNAL( parsedUser(const QTweetUser &) ), SLOT( postGotTomahawkStatusAuthVerifyReply(const QTweetUser &) ) );
credVerifier->verify();
}
void
SettingsDialog::postGotTomahawkStatusAuthVerifyReply( const QTweetUser &user )
{
if ( user.id() == 0 )
{
QMessageBox::critical( 0, QString("Tweetin' Error"), QString("Your saved credentials could not be verified.\nYou may wish to try re-authenticating.") );
return;
}
TomahawkSettings* s = TomahawkSettings::instance();
TomahawkOAuthTwitter *twitAuth = new TomahawkOAuthTwitter( this );
twitAuth->setNetworkAccessManager( TomahawkUtils::nam() );
twitAuth->setOAuthToken( s->twitterOAuthToken().toLatin1() );
twitAuth->setOAuthTokenSecret( s->twitterOAuthTokenSecret().toLatin1() );
QTweetStatusUpdate *statUpdate = new QTweetStatusUpdate( twitAuth, this );
connect( statUpdate, SIGNAL( postedStatus(const QTweetStatus &) ), SLOT( postGotTomahawkStatusUpdateReply(const QTweetStatus &) ) );
statUpdate->post( QString( "Got Tomahawk?" ) );
}
void
SettingsDialog::postGotTomahawkStatusUpdateReply( const QTweetStatus& status )
{
if ( status.id() == 0 )
QMessageBox::critical( 0, QString("Tweetin' Error"), QString("There was an error posting your status -- sorry!") );
else
QMessageBox::information( 0, QString("Tweeted!"), QString("Your tweet has been posted!") );
}
ProxyDialog::ProxyDialog( QWidget *parent )
: QDialog( parent )
, ui( new Ui::ProxyDialog )

View File

@ -3,6 +3,9 @@
#include <QDialog>
#include <qtweetstatus.h>
#include <qtweetuser.h>
class QNetworkReply;
namespace Ui
@ -52,6 +55,9 @@ private slots:
void onLastFmFinished();
void authenticateTwitter();
void startPostGotTomahawkStatus();
void postGotTomahawkStatusAuthVerifyReply( const QTweetUser &user );
void postGotTomahawkStatusUpdateReply( const QTweetStatus &status );
void addScriptResolver();
void scriptSelectionChanged();

View File

@ -29,7 +29,7 @@
</sizepolicy>
</property>
<property name="currentIndex">
<number>0</number>
<number>2</number>
</property>
<widget class="QWidget" name="tabJabber">
<attribute name="title">
@ -462,6 +462,35 @@ When you press the button your web browser will launch and take you to Twitter.c
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="twitterInstructionsBox">
<property name="title">
<string>Instructions</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_12">
<item>
<layout class="QVBoxLayout" name="twitterInstructionsVLayout">
<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>
</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>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="twitterVertSpacer">
<property name="orientation">
@ -769,5 +798,21 @@ When you press the button your web browser will launch and take you to Twitter.c
</hint>
</hints>
</connection>
<connection>
<sender>twitterTweetGotTomahawkButton</sender>
<signal>pressed()</signal>
<receiver>SettingsDialog</receiver>
<slot>startPostGotTomahawkStatus()</slot>
<hints>
<hint type="sourcelabel">
<x>310</x>
<y>313</y>
</hint>
<hint type="destinationlabel">
<x>310</x>
<y>216</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -11,7 +11,7 @@ class SIPDLLEXPORT TomahawkOAuthTwitter : public OAuthTwitter
public:
TomahawkOAuthTwitter( QObject *parent = 0 );
~TomahawkOAuthTwitter() {}
protected: