void TwitterConfigWidget::authenticateTwitter() { qDebug() << Q_FUNC_INFO; 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->twitterInstructionsBox->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->twitterInstructionsBox->setVisible( false ); QMessageBox::critical( 0, QString("Tweetin' Error"), QString("There was an error validating your authentication") ); } }
void TwitterConfigWidget::startPostGotTomahawkStatus() { m_postGTtype = ui->twitterTweetComboBox->currentText(); if ( m_postGTtype != "Global Tweet" && ( ui->twitterUserTweetLineEdit->text().isEmpty() || ui->twitterUserTweetLineEdit->text() == "@" ) ) { QMessageBox::critical( this, tr("Tweetin' Error"), tr("You must enter a user name for this type of tweet.") ); return; } qDebug() << "Posting Got Tomahawk status"; TomahawkSettings* s = TomahawkSettings::instance(); if ( s->twitterOAuthToken().isEmpty() || s->twitterOAuthTokenSecret().isEmpty() || s->twitterScreenName().isEmpty() ) { QMessageBox::critical( this, tr("Tweetin' Error"), tr("Your saved credentials could not be loaded.\nYou may wish to try re-authenticating.") ); emit twitterAuthed( false ); 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 TwitterConfigWidget::authenticateTwitter() { qDebug() << Q_FUNC_INFO; TomahawkOAuthTwitter *twitAuth = new TomahawkOAuthTwitter( this ); twitAuth->setNetworkAccessManager( TomahawkUtils::nam() ); twitAuth->authorizePin(); 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::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 TwitterConfigWidget::postGotTomahawkStatusAuthVerifyReply( const QTweetUser &user ) { if ( user.id() == 0 ) { QMessageBox::critical( this, tr("Tweetin' Error"), tr("Your saved credentials could not be verified.\nYou may wish to try re-authenticating.") ); emit twitterAuthed( false ); return; } TomahawkSettings* s = TomahawkSettings::instance(); s->setTwitterScreenName( user.screenName() ); TomahawkOAuthTwitter *twitAuth = new TomahawkOAuthTwitter( this ); twitAuth->setNetworkAccessManager( TomahawkUtils::nam() ); twitAuth->setOAuthToken( s->twitterOAuthToken().toLatin1() ); twitAuth->setOAuthTokenSecret( s->twitterOAuthTokenSecret().toLatin1() ); if ( m_postGTtype != "Direct Message" ) { 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(); QString message = QString( "Got Tomahawk? {" ) + Database::instance()->dbid() + QString( "} (" ) + uuid.mid( 1, 8 ) + QString( ")" ) + QString( " http://gettomahawk.com" ); if ( m_postGTtype == "@Mention" ) { QString user = ui->twitterUserTweetLineEdit->text(); if ( user.startsWith( "@" ) ) user.remove( 0, 1 ); message = QString( "@" ) + user + QString( " " ) + message; } statUpdate->post( message ); } else { QTweetDirectMessageNew *statUpdate = new QTweetDirectMessageNew( twitAuth, this ); connect( statUpdate, SIGNAL( parsedDirectMessage(const QTweetDMStatus &)), SLOT( postGotTomahawkDirectMessageReply(const QTweetDMStatus &) ) ); connect( statUpdate, SIGNAL( error(QTweetNetBase::ErrorCode, const QString&) ), SLOT( postGotTomahawkStatusUpdateError(QTweetNetBase::ErrorCode, const QString &) ) ); QString uuid = QUuid::createUuid(); QString message = QString( "Got Tomahawk? {" ) + Database::instance()->dbid() + QString( "} (" ) + uuid.mid( 1, 8 ) + QString( ")" ) + QString( " http://gettomahawk.com" ); QString user = ui->twitterUserTweetLineEdit->text(); if ( user.startsWith( "@" ) ) user.remove( 0, 1 ); statUpdate->post( user, message ); } }
void TwitterConfigWidget::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(); s->setTwitterScreenName( user.screenName() ); 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 &) ) ); connect( statUpdate, SIGNAL( error(QTweetNetBase::ErrorCode, const QString&) ), SLOT( postGotTomahawkStatusUpdateError(QTweetNetBase::ErrorCode, const QString &) ) ); QString uuid = QUuid::createUuid(); statUpdate->post( QString( "Got Tomahawk? {" ) + Database::instance()->dbid() + QString( "} (" ) + uuid.mid( 1, 8 ) + QString( ")" ) ); }