From 9a69fb34c324aa97c17d9dbbe9bb2682f812e87c Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Sat, 12 Feb 2011 01:46:59 -0500 Subject: [PATCH] Tomahawk can now send a Got Tomahawk? tweet for you (also PoC of the authentication verification and status posting bits) --- src/libtomahawk/CMakeLists.txt | 1 + src/settingsdialog.cpp | 52 ++++++++++++++++++++++++++ src/settingsdialog.h | 6 +++ src/settingsdialog.ui | 47 ++++++++++++++++++++++- src/sip/twitter/tomahawkoauthtwitter.h | 2 +- 5 files changed, 106 insertions(+), 2 deletions(-) diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index b741fd1c4..d98199beb 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -302,6 +302,7 @@ include_directories( . ${CMAKE_CURRENT_BINARY_DIR} .. ../../thirdparty/jdns ../../thirdparty/jdns/jdns ../../thirdparty/jdns/jdnsshared + ../../thirdparty/qtweetlib/src playlist ) diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp index a6c3225ff..22ca85469 100644 --- a/src/settingsdialog.cpp +++ b/src/settingsdialog.cpp @@ -19,6 +19,8 @@ #include "tomahawksettings.h" #include "sip/SipHandler.h" #include "sip/twitter/tomahawkoauthtwitter.h" +#include +#include 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 ) diff --git a/src/settingsdialog.h b/src/settingsdialog.h index dc82f03be..1912ce730 100644 --- a/src/settingsdialog.h +++ b/src/settingsdialog.h @@ -3,6 +3,9 @@ #include +#include +#include + 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(); diff --git a/src/settingsdialog.ui b/src/settingsdialog.ui index 4009156eb..30701062e 100644 --- a/src/settingsdialog.ui +++ b/src/settingsdialog.ui @@ -29,7 +29,7 @@ - 0 + 2 @@ -462,6 +462,35 @@ When you press the button your web browser will launch and take you to Twitter.c + + + + Instructions + + + + + + + + How it works is simple: just tweet "Got Tomahawk?" and be (very) patient. It can take a bit. + + + + + + + + + Press here if you'd like to have Tomahawk tweet this for you + + + + + + + + @@ -769,5 +798,21 @@ When you press the button your web browser will launch and take you to Twitter.c + + twitterTweetGotTomahawkButton + pressed() + SettingsDialog + startPostGotTomahawkStatus() + + + 310 + 313 + + + 310 + 216 + + + diff --git a/src/sip/twitter/tomahawkoauthtwitter.h b/src/sip/twitter/tomahawkoauthtwitter.h index bef823c36..5d56b889a 100644 --- a/src/sip/twitter/tomahawkoauthtwitter.h +++ b/src/sip/twitter/tomahawkoauthtwitter.h @@ -11,7 +11,7 @@ class SIPDLLEXPORT TomahawkOAuthTwitter : public OAuthTwitter public: TomahawkOAuthTwitter( QObject *parent = 0 ); - + ~TomahawkOAuthTwitter() {} protected: