diff --git a/src/sip/twitter/twitter.cpp b/src/sip/twitter/twitter.cpp index 3588802b7..3c92b6f8b 100644 --- a/src/sip/twitter/twitter.cpp +++ b/src/sip/twitter/twitter.cpp @@ -61,10 +61,22 @@ TwitterPlugin::TwitterPlugin() m_connectTimer.start(); } +void +TwitterPlugin::configDialogAuthedSignalSlot( bool authed ) +{ + m_isAuthed = authed; + if ( !authed ) + { + TomahawkSettings::instance()->setTwitterScreenName( QString() ); + TomahawkSettings::instance()->setTwitterOAuthToken( QString() ); + TomahawkSettings::instance()->setTwitterOAuthTokenSecret( QString() ); + } +} + bool TwitterPlugin::isValid() { - return m_isAuthed || !m_cachedPeers.isEmpty(); + return m_isAuthed; } const QString @@ -89,11 +101,11 @@ QWidget* TwitterPlugin::configWidget() { m_configWidget = new TwitterConfigWidget( this ); + connect( m_configWidget, SIGNAL( twitterAuthed(bool) ), SLOT( configDialogAuthedSignalSlot(bool) ) ); + return m_configWidget; } - - bool TwitterPlugin::connectPlugin( bool /*startup*/ ) { @@ -282,7 +294,10 @@ TwitterPlugin::friendsTimelineStatuses( const QList< QTweetStatus > &statuses ) qDebug() << "TwitterPlugin parsed node " << node << " out of the tweet"; if ( status.user().screenName() == myScreenName && node == Database::instance()->dbid() ) + { + qDebug() << "My screen name and my dbid found; ignoring"; continue; + } QHash< QString, QVariant > peerData; if( m_cachedPeers.contains( status.user().screenName() ) ) @@ -354,7 +369,10 @@ TwitterPlugin::mentionsStatuses( const QList< QTweetStatus > &statuses ) qDebug() << "TwitterPlugin parsed node " << node << " out of the tweet"; if ( status.user().screenName() == myScreenName && node == Database::instance()->dbid() ) + { + qDebug() << "My screen name and my dbid found; ignoring"; continue; + } QHash< QString, QVariant > peerData; if( m_cachedPeers.contains( status.user().screenName() ) ) diff --git a/src/sip/twitter/twitter.h b/src/sip/twitter/twitter.h index 9c0c0fd8f..3b03440af 100644 --- a/src/sip/twitter/twitter.h +++ b/src/sip/twitter/twitter.h @@ -75,6 +75,7 @@ public slots: } private slots: + void configDialogAuthedSignalSlot( bool authed ); void connectAuthVerifyReply( const QTweetUser &user ); void checkTimerFired(); void connectTimerFired(); diff --git a/src/sip/twitter/twitterconfigwidget.cpp b/src/sip/twitter/twitterconfigwidget.cpp index 70c16a512..dbf484652 100644 --- a/src/sip/twitter/twitterconfigwidget.cpp +++ b/src/sip/twitter/twitterconfigwidget.cpp @@ -37,25 +37,29 @@ TwitterConfigWidget::TwitterConfigWidget(SipPlugin* plugin, QWidget *parent) : ui->setupUi(this); connect(ui->twitterAuthenticateButton, SIGNAL(pressed()), - this, SLOT(authenticateTwitter())); + this, SLOT(authDeauthTwitter())); connect(ui->twitterTweetGotTomahawkButton, SIGNAL(pressed()), this, SLOT(startPostGotTomahawkStatus())); TomahawkSettings* s = TomahawkSettings::instance(); - if ( s->twitterOAuthToken().isEmpty() || s->twitterOAuthTokenSecret().isEmpty() ) + if ( s->twitterOAuthToken().isEmpty() || s->twitterOAuthTokenSecret().isEmpty() || s->twitterScreenName().isEmpty() ) { ui->twitterStatusLabel->setText("Status: No saved credentials"); ui->twitterAuthenticateButton->setText( "Authenticate" ); ui->twitterInstructionsInfoLabel->setVisible( false ); ui->twitterTweetGotTomahawkButton->setVisible( false ); + + emit twitterAuthed( false ); } else { ui->twitterStatusLabel->setText("Status: Credentials saved"); - ui->twitterAuthenticateButton->setText( "Re-authenticate" ); + ui->twitterAuthenticateButton->setText( "De-authenticate" ); ui->twitterInstructionsInfoLabel->setVisible( true ); ui->twitterTweetGotTomahawkButton->setVisible( true ); + + emit twitterAuthed( true ); } } @@ -65,6 +69,15 @@ TwitterConfigWidget::~TwitterConfigWidget() delete ui; } +void +TwitterConfigWidget::authDeauthTwitter() +{ + if ( ui->twitterAuthenticateButton->text() == "Authenticate" ) + authenticateTwitter(); + else + deauthenticateTwitter(); +} + void TwitterConfigWidget::authenticateTwitter() { @@ -72,46 +85,80 @@ TwitterConfigWidget::authenticateTwitter() TomahawkOAuthTwitter *twitAuth = new TomahawkOAuthTwitter( this ); twitAuth->setNetworkAccessManager( TomahawkUtils::nam() ); twitAuth->authorizePin(); - if ( !twitAuth->oauthToken().isEmpty() && !twitAuth->oauthTokenSecret().isEmpty() ) - { - TomahawkSettings* s = TomahawkSettings::instance(); - s->setTwitterOAuthToken( twitAuth->oauthToken() ); - s->setTwitterOAuthTokenSecret( twitAuth->oauthTokenSecret() ); - ui->twitterStatusLabel->setText("Status: Credentials saved"); - ui->twitterAuthenticateButton->setText( "Re-authenticate" ); - - ui->twitterInstructionsInfoLabel->setVisible( true ); - ui->twitterTweetGotTomahawkButton->setVisible( true ); - - TomahawkSettings::instance()->setTwitterCachedFriendsSinceId( 0 ); - TomahawkSettings::instance()->setTwitterCachedMentionsSinceId( 0 ); - m_plugin->connectPlugin( false ); - - } - else - { - TomahawkSettings* s = TomahawkSettings::instance(); - s->setTwitterOAuthToken( QString() ); - s->setTwitterOAuthTokenSecret( QString() ); - ui->twitterStatusLabel->setText("Status: No saved credentials"); - ui->twitterAuthenticateButton->setText( "Authenticate" ); - - ui->twitterInstructionsInfoLabel->setVisible( false ); - ui->twitterTweetGotTomahawkButton->setVisible( false ); - - QMessageBox::critical( 0, QString("Tweetin' Error"), QString("There was an error validating your authentication") ); - } + + TomahawkSettings* s = TomahawkSettings::instance(); + s->setTwitterOAuthToken( twitAuth->oauthToken() ); + s->setTwitterOAuthTokenSecret( twitAuth->oauthTokenSecret() ); + + QTweetAccountVerifyCredentials *credVerifier = new QTweetAccountVerifyCredentials( twitAuth, this ); + connect( credVerifier, SIGNAL( parsedUser( const QTweetUser & ) ), SLOT( authenticateVerifyReply( const QTweetUser & ) ) ); + connect( credVerifier, SIGNAL( error( QTweetNetBase::ErrorCode, QString ) ), SLOT( authenticateVerifyError( QTweetNetBase::ErrorCode, QString ) ) ); + credVerifier->verify(); } +void +TwitterConfigWidget::authenticateVerifyReply( const QTweetUser &user ) +{ + qDebug() << Q_FUNC_INFO; + if ( user.id() == 0 ) + { + QMessageBox::critical( 0, QString("Tweetin' Error"), QString("The credentials could not be verified.\nYou may wish to try re-authenticating.") ); + emit twitterAuthed( false ); + return; + } + + TomahawkSettings* s = TomahawkSettings::instance(); + s->setTwitterScreenName( user.screenName() ); + s->setTwitterCachedFriendsSinceId( 0 ); + s->setTwitterCachedMentionsSinceId( 0 ); + + ui->twitterStatusLabel->setText("Status: Credentials saved"); + ui->twitterAuthenticateButton->setText( "De-authenticate" ); + ui->twitterInstructionsInfoLabel->setVisible( true ); + ui->twitterTweetGotTomahawkButton->setVisible( true ); + + m_plugin->connectPlugin( false ); + + emit twitterAuthed( true ); +} + +void +TwitterConfigWidget::authenticateVerifyError( QTweetNetBase::ErrorCode code, const QString &errorMsg ) +{ + qDebug() << Q_FUNC_INFO; + qDebug() << "Error validating credentials, error code is " << code << ", error message is " << errorMsg; + ui->twitterStatusLabel->setText("Status: Error validating credentials"); + emit twitterAuthed( false ); + return; +} + + +void +TwitterConfigWidget::deauthenticateTwitter() +{ + qDebug() << Q_FUNC_INFO; + TomahawkSettings* s = TomahawkSettings::instance(); + s->setTwitterOAuthToken( QString() ); + s->setTwitterOAuthTokenSecret( QString() ); + s->setTwitterScreenName( QString() ); + + ui->twitterStatusLabel->setText("Status: No saved credentials"); + ui->twitterAuthenticateButton->setText( "Authenticate" ); + ui->twitterInstructionsInfoLabel->setVisible( false ); + ui->twitterTweetGotTomahawkButton->setVisible( false ); + + emit twitterAuthed( false ); +} void TwitterConfigWidget::startPostGotTomahawkStatus() { qDebug() << "Posting Got Tomahawk status"; TomahawkSettings* s = TomahawkSettings::instance(); - if ( s->twitterOAuthToken().isEmpty() || s->twitterOAuthTokenSecret().isEmpty() ) + if ( s->twitterOAuthToken().isEmpty() || s->twitterOAuthTokenSecret().isEmpty() || s->twitterScreenName().isEmpty() ) { QMessageBox::critical( 0, QString("Tweetin' Error"), QString("Your saved credentials could not be loaded.\nYou may wish to try re-authenticating.") ); + emit twitterAuthed( false ); return; } TomahawkOAuthTwitter *twitAuth = new TomahawkOAuthTwitter( this ); @@ -130,6 +177,7 @@ TwitterConfigWidget::postGotTomahawkStatusAuthVerifyReply( const QTweetUser &use 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.") ); + emit twitterAuthed( false ); return; } TomahawkSettings* s = TomahawkSettings::instance(); diff --git a/src/sip/twitter/twitterconfigwidget.h b/src/sip/twitter/twitterconfigwidget.h index 8e1d3ed19..5521c7f7b 100644 --- a/src/sip/twitter/twitterconfigwidget.h +++ b/src/sip/twitter/twitterconfigwidget.h @@ -40,14 +40,22 @@ public: explicit TwitterConfigWidget(SipPlugin* plugin = 0, QWidget *parent = 0); ~TwitterConfigWidget(); +signals: + void twitterAuthed( bool authed ); + private slots: - void authenticateTwitter(); + void authDeauthTwitter(); void startPostGotTomahawkStatus(); + void authenticateVerifyReply( const QTweetUser &user ); + void authenticateVerifyError( QTweetNetBase::ErrorCode code, const QString &errorMsg ); void postGotTomahawkStatusAuthVerifyReply( const QTweetUser &user ); void postGotTomahawkStatusUpdateReply( const QTweetStatus &status ); void postGotTomahawkStatusUpdateError( QTweetNetBase::ErrorCode, const QString &errorMsg ); private: + void authenticateTwitter(); + void deauthenticateTwitter(); + Ui::TwitterConfigWidget *ui; SipPlugin *m_plugin; }; diff --git a/thirdparty/qtweetlib/tomahawk-custom/tomahawkoauthtwitter.cpp b/thirdparty/qtweetlib/tomahawk-custom/tomahawkoauthtwitter.cpp index 580ba6daf..0d4c3e06b 100644 --- a/thirdparty/qtweetlib/tomahawk-custom/tomahawkoauthtwitter.cpp +++ b/thirdparty/qtweetlib/tomahawk-custom/tomahawkoauthtwitter.cpp @@ -1,5 +1,6 @@ #include "tomahawkoauthtwitter.h" #include +#include TomahawkOAuthTwitter::TomahawkOAuthTwitter( QObject* parent ) : OAuthTwitter( parent ) @@ -7,7 +8,8 @@ TomahawkOAuthTwitter::TomahawkOAuthTwitter( QObject* parent ) } -int TomahawkOAuthTwitter::authorizationWidget() +int +TomahawkOAuthTwitter::authorizationWidget() { bool ok; int i = QInputDialog::getInt(0, QString( "Twitter PIN" ), QString( "After authenticating on Twitter's web site,\nenter the displayed PIN number here:" ), 0, 0, 2147483647, 1, &ok); @@ -16,3 +18,11 @@ int TomahawkOAuthTwitter::authorizationWidget() return 0; } + +void +TomahawkOAuthTwitter::error() +{ + qDebug() << Q_FUNC_INFO; + setOAuthToken( QString().toLatin1() ); + setOAuthTokenSecret( QString().toLatin1() ); +} diff --git a/thirdparty/qtweetlib/tomahawk-custom/tomahawkoauthtwitter.h b/thirdparty/qtweetlib/tomahawk-custom/tomahawkoauthtwitter.h index 22690ac3c..8336f4158 100644 --- a/thirdparty/qtweetlib/tomahawk-custom/tomahawkoauthtwitter.h +++ b/thirdparty/qtweetlib/tomahawk-custom/tomahawkoauthtwitter.h @@ -16,6 +16,9 @@ public: protected: virtual int authorizationWidget(); + +private slots: + void error(); }; #endif