From 719255e4c9fd1628f769968c3b5efeaf7f0549b5 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Sun, 27 Mar 2011 13:56:49 -0400 Subject: [PATCH] Revamp twitter config widget again -- use a drop down box for message type. Also display name of saved user. --- src/sip/twitter/twitterconfigwidget.cpp | 107 +++++++--------- src/sip/twitter/twitterconfigwidget.h | 6 +- src/sip/twitter/twitterconfigwidget.ui | 161 +++++++----------------- 3 files changed, 95 insertions(+), 179 deletions(-) diff --git a/src/sip/twitter/twitterconfigwidget.cpp b/src/sip/twitter/twitterconfigwidget.cpp index 15e38c56d..85660318a 100644 --- a/src/sip/twitter/twitterconfigwidget.cpp +++ b/src/sip/twitter/twitterconfigwidget.cpp @@ -30,22 +30,24 @@ #include -TwitterConfigWidget::TwitterConfigWidget(SipPlugin* plugin, QWidget *parent) : - QWidget(parent), - ui(new Ui::TwitterConfigWidget), - m_plugin(plugin) +TwitterConfigWidget::TwitterConfigWidget( SipPlugin* plugin, QWidget *parent ) : + QWidget( parent ), + ui( new Ui::TwitterConfigWidget ), + m_plugin( plugin ) { - ui->setupUi(this); + ui->setupUi( this ); - connect(ui->twitterAuthenticateButton, SIGNAL(pressed()), - this, SLOT(authDeauthTwitter())); - connect(ui->twitterTweetGotTomahawkButton, SIGNAL(pressed()), - this, SLOT(startPostGlobalGotTomahawkStatus())); - connect(ui->twitterUserTweetButton, SIGNAL(pressed()), - this, SLOT(startPostUserGotTomahawkStatus())); - connect(ui->twitterDirectTweetButton, SIGNAL(pressed()), - this, SLOT(startPostDirectGotTomahawkStatus())); + connect( ui->twitterAuthenticateButton, SIGNAL( pressed() ), + this, SLOT( authDeauthTwitter() ) ); + connect( ui->twitterTweetGotTomahawkButton, SIGNAL( pressed() ), + this, SLOT( startPostGotTomahawkStatus() ) ); + connect( ui->twitterTweetComboBox, SIGNAL( currentIndexChanged( int ) ), + this, SLOT( tweetComboBoxIndexChanged( int ) ) ); + ui->twitterTweetComboBox->setCurrentIndex( 0 ); + ui->twitterUserTweetLineEdit->setReadOnly( true ); + ui->twitterUserTweetLineEdit->setEnabled( false ); + TomahawkSettings* s = TomahawkSettings::instance(); if ( s->twitterOAuthToken().isEmpty() || s->twitterOAuthTokenSecret().isEmpty() || s->twitterScreenName().isEmpty() ) { @@ -53,29 +55,21 @@ TwitterConfigWidget::TwitterConfigWidget(SipPlugin* plugin, QWidget *parent) : ui->twitterAuthenticateButton->setText( "Authenticate" ); ui->twitterInstructionsInfoLabel->setVisible( false ); ui->twitterGlobalTweetLabel->setVisible( false ); - ui->twitterUserTweetLabel->setVisible( false ); - ui->twitterDirectTweetLabel->setVisible( false ); ui->twitterTweetGotTomahawkButton->setVisible( false ); - ui->twitterUserTweetButton->setVisible( false ); ui->twitterUserTweetLineEdit->setVisible( false ); - ui->twitterDirectTweetButton->setVisible( false ); - ui->twitterDirectTweetLineEdit->setVisible( false ); - + ui->twitterTweetComboBox->setVisible( false ); + emit twitterAuthed( false ); } else { - ui->twitterStatusLabel->setText("Status: Credentials saved"); + ui->twitterStatusLabel->setText("Status: Credentials saved for " + s->twitterScreenName() ); ui->twitterAuthenticateButton->setText( "De-authenticate" ); ui->twitterInstructionsInfoLabel->setVisible( true ); ui->twitterGlobalTweetLabel->setVisible( true ); - ui->twitterUserTweetLabel->setVisible( true ); - ui->twitterDirectTweetLabel->setVisible( true ); ui->twitterTweetGotTomahawkButton->setVisible( true ); - ui->twitterUserTweetButton->setVisible( true ); ui->twitterUserTweetLineEdit->setVisible( true ); - ui->twitterDirectTweetButton->setVisible( true ); - ui->twitterDirectTweetLineEdit->setVisible( true ); + ui->twitterTweetComboBox->setVisible( true ); emit twitterAuthed( true ); } @@ -130,17 +124,13 @@ TwitterConfigWidget::authenticateVerifyReply( const QTweetUser &user ) s->setTwitterCachedFriendsSinceId( 0 ); s->setTwitterCachedMentionsSinceId( 0 ); - ui->twitterStatusLabel->setText("Status: Credentials saved"); + ui->twitterStatusLabel->setText("Status: Credentials saved for " + s->twitterScreenName() ); ui->twitterAuthenticateButton->setText( "De-authenticate" ); ui->twitterInstructionsInfoLabel->setVisible( true ); ui->twitterGlobalTweetLabel->setVisible( true ); - ui->twitterUserTweetLabel->setVisible( true ); - ui->twitterDirectTweetLabel->setVisible( true ); ui->twitterTweetGotTomahawkButton->setVisible( true ); - ui->twitterUserTweetButton->setVisible( true ); ui->twitterUserTweetLineEdit->setVisible( true ); - ui->twitterDirectTweetButton->setVisible( true ); - ui->twitterDirectTweetLineEdit->setVisible( true ); + ui->twitterTweetComboBox->setVisible( true ); m_plugin->connectPlugin( false ); @@ -170,51 +160,44 @@ TwitterConfigWidget::deauthenticateTwitter() ui->twitterAuthenticateButton->setText( "Authenticate" ); ui->twitterInstructionsInfoLabel->setVisible( false ); ui->twitterGlobalTweetLabel->setVisible( false ); - ui->twitterUserTweetLabel->setVisible( false ); - ui->twitterDirectTweetLabel->setVisible( false ); ui->twitterTweetGotTomahawkButton->setVisible( false ); - ui->twitterUserTweetButton->setVisible( false ); ui->twitterUserTweetLineEdit->setVisible( false ); - ui->twitterDirectTweetButton->setVisible( false ); - ui->twitterDirectTweetLineEdit->setVisible( false ); + ui->twitterTweetComboBox->setVisible( false ); emit twitterAuthed( false ); } void -TwitterConfigWidget::startPostGlobalGotTomahawkStatus() +TwitterConfigWidget::tweetComboBoxIndexChanged( int index ) { - m_postGTtype = "global"; - startPostGotTomahawkStatus(); -} - -void -TwitterConfigWidget::startPostUserGotTomahawkStatus() -{ - if ( ui->twitterUserTweetLineEdit->text().isEmpty() || ui->twitterUserTweetLineEdit->text() == "@" ) + if( ui->twitterTweetComboBox->currentText() == "Global Tweet" ) { - QMessageBox::critical( 0, QString("Tweetin' Error"), QString("You cannot leave the user name empty when sending a mention.") ); - return; + ui->twitterUserTweetLineEdit->setReadOnly( true ); + ui->twitterUserTweetLineEdit->setEnabled( false ); } - m_postGTtype = "user"; - startPostGotTomahawkStatus(); -} - -void -TwitterConfigWidget::startPostDirectGotTomahawkStatus() -{ - if ( ui->twitterDirectTweetLineEdit->text().isEmpty() || ui->twitterDirectTweetLineEdit->text() == "@" ) + else { - QMessageBox::critical( 0, QString("Tweetin' Error"), QString("You cannot leave the user name empty when sending a direct message.") ); - return; + ui->twitterUserTweetLineEdit->setReadOnly( false ); + ui->twitterUserTweetLineEdit->setEnabled( true ); } - m_postGTtype = "direct"; - startPostGotTomahawkStatus(); + + if( ui->twitterTweetComboBox->currentText() == "Direct Message" ) + ui->twitterTweetGotTomahawkButton->setText( "Send Message!" ); + else + ui->twitterTweetGotTomahawkButton->setText( "Tweet!" ); } void TwitterConfigWidget::startPostGotTomahawkStatus() { + m_postGTtype = ui->twitterTweetComboBox->currentText(); + + if ( m_postGTtype != "Global Tweet" && ( ui->twitterUserTweetLineEdit->text().isEmpty() || ui->twitterUserTweetLineEdit->text() == "@" ) ) + { + QMessageBox::critical( 0, QString("Tweetin' Error"), QString("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() ) @@ -247,14 +230,14 @@ TwitterConfigWidget::postGotTomahawkStatusAuthVerifyReply( const QTweetUser &use twitAuth->setNetworkAccessManager( TomahawkUtils::nam() ); twitAuth->setOAuthToken( s->twitterOAuthToken().toLatin1() ); twitAuth->setOAuthTokenSecret( s->twitterOAuthTokenSecret().toLatin1() ); - if ( m_postGTtype != "direct" ) + 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 == "user" ) + if ( m_postGTtype == "@Mention" ) { QString user = ui->twitterUserTweetLineEdit->text(); if ( user.startsWith( "@" ) ) @@ -270,7 +253,7 @@ TwitterConfigWidget::postGotTomahawkStatusAuthVerifyReply( const QTweetUser &use 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->twitterDirectTweetLineEdit->text(); + QString user = ui->twitterUserTweetLineEdit->text(); if ( user.startsWith( "@" ) ) user.remove( 0, 1 ); statUpdate->post( user, message ); diff --git a/src/sip/twitter/twitterconfigwidget.h b/src/sip/twitter/twitterconfigwidget.h index 3d18db321..85fabce90 100644 --- a/src/sip/twitter/twitterconfigwidget.h +++ b/src/sip/twitter/twitterconfigwidget.h @@ -38,7 +38,7 @@ class TwitterConfigWidget : public QWidget Q_OBJECT public: - explicit TwitterConfigWidget(SipPlugin* plugin = 0, QWidget *parent = 0); + explicit TwitterConfigWidget( SipPlugin* plugin = 0, QWidget *parent = 0 ); ~TwitterConfigWidget(); signals: @@ -46,9 +46,6 @@ signals: private slots: void authDeauthTwitter(); - void startPostGlobalGotTomahawkStatus(); - void startPostUserGotTomahawkStatus(); - void startPostDirectGotTomahawkStatus(); void startPostGotTomahawkStatus(); void authenticateVerifyReply( const QTweetUser &user ); void authenticateVerifyError( QTweetNetBase::ErrorCode code, const QString &errorMsg ); @@ -56,6 +53,7 @@ private slots: void postGotTomahawkStatusUpdateReply( const QTweetStatus &status ); void postGotTomahawkDirectMessageReply( const QTweetDMStatus &status ); void postGotTomahawkStatusUpdateError( QTweetNetBase::ErrorCode, const QString &errorMsg ); + void tweetComboBoxIndexChanged( int index ); private: void authenticateTwitter(); diff --git a/src/sip/twitter/twitterconfigwidget.ui b/src/sip/twitter/twitterconfigwidget.ui index 52c99105b..1bb728fd0 100644 --- a/src/sip/twitter/twitterconfigwidget.ui +++ b/src/sip/twitter/twitterconfigwidget.ui @@ -101,133 +101,68 @@ If connections to peers seem to have been lost, just press the appropriate butto - Use this button to send a normal, public tweet: + Select the kind of tweet you would like, then press the button to post it: - + + + + 0 + 0 + + - + + Global Tweet + - - - - 0 - 0 - - - - Press here to post a public tweet - - + + @Mention + - + + + Direct Message + + + - - - - - - Use this button to send a public @mention to the user you enter: - - - - - - - - - - - - - 0 - 0 - - - - - 250 - 0 - - - - e.g. @tomahawkplayer - - - - - - - - 0 - 0 - - - - Press here to post a public @mention - - - - - - + + + + 0 + 0 + + + + + 250 + 0 + + + + e.g. @tomahawkplayer + + - - - - - - Use this button to send a private, direct message to the user you enter: - - - - - - - - - - - - - 0 - 0 - - - - - 250 - 0 - - - - e.g. tomahawkplayer - - - - - - - - 0 - 0 - - - - Press here to post a private message - - - - - - + + + + 0 + 0 + + + + Tweet! + +