From 73e52ce4bfd79f1d18cc077364473a31bf22d823 Mon Sep 17 00:00:00 2001 From: Jesper Thomschutz Date: Mon, 2 Apr 2007 23:06:05 +0200 Subject: [PATCH] Added some general usability fixes. --- twittersocket.cpp | 19 ++++++++++++------- twittersocket.h | 2 +- w_connect.cpp | 11 +++++++---- w_timeline.cpp | 27 ++++++++++++++++++--------- w_timeline.h | 7 ++++--- 5 files changed, 42 insertions(+), 24 deletions(-) diff --git a/twittersocket.cpp b/twittersocket.cpp index 84e7dff..547cc1f 100644 --- a/twittersocket.cpp +++ b/twittersocket.cpp @@ -19,6 +19,7 @@ void TwitterSocket::update(QString message) { QHttpRequestHeader header("POST", "/statuses/update.xml"); header.setValue("Host", "twitter.com"); + // Twitterrific manages to get its name on the page using the source // tag, but it doesn't seem to work for us :/ const QString msg("source=Squawker&status="+message); @@ -27,15 +28,19 @@ void TwitterSocket::update(QString message) void TwitterSocket::timeline() { - qDebug() << "You called timeline, it does nothing atm."; + get(QLatin1String("/statuses/friends_timeline.xml")); } void TwitterSocket::done( bool error) { - // Hack to work around bug in Qt4.2 basic auth. Fixed in 4.3 - // (It doesn't report an error when incorrect credentials are supplied) - if (readAll() == "Could't authenticate you") - emit result(true, QLatin1String("Authentication denied")); - else - emit result(error, errorString()); + QString results = readAll(); + + // Hack to work around bug in Qt4.2 basic auth. Fixed in 4.3 + // (It doesn't report an error when incorrect credentials are supplied) + if ( results == "Could't authenticate you") + emit result(true, QLatin1String("Authentication denied"), NULL ); + else + emit result(error, errorString(), results); + + delete this; } diff --git a/twittersocket.h b/twittersocket.h index e3af803..a37d6cd 100644 --- a/twittersocket.h +++ b/twittersocket.h @@ -15,7 +15,7 @@ public: void update(QString message); signals: - void result( bool error, QString errorString); + void result( bool error, QString errorString, QString contents); private: QHttp *http; diff --git a/w_connect.cpp b/w_connect.cpp index d1274b2..0a044a1 100644 --- a/w_connect.cpp +++ b/w_connect.cpp @@ -15,10 +15,12 @@ w_Connect::w_Connect(QWidget *parent) void w_Connect::connect() { pb_connect->setEnabled(false); + le_password->setEnabled(false); + le_user->setEnabled(false); pb_connect->setText(QLatin1String("Connecting")); twittersocket = new TwitterSocket(le_user->text(), le_password->text()); - QObject::connect( twittersocket, SIGNAL( result( bool, QString) ), this, SLOT( status( bool, QString) ) ); + QObject::connect( twittersocket, SIGNAL( result( bool, QString, QString) ), this, SLOT( status( bool, QString) ) ); twittersocket->accountValid(); } @@ -26,9 +28,8 @@ void w_Connect::status( bool error, QString errorString ) { if (error == false) { - w_timeline = new w_Timeline(twittersocket, this->parentWidget()); + w_timeline = new w_Timeline(le_user->text(), le_password->text(), this->parentWidget()); w_timeline->show(); - this->destroy(); delete this; } else @@ -39,7 +40,9 @@ void w_Connect::status( bool error, QString errorString ) pb_connect->setText(QLatin1String("Connect")); pb_connect->setEnabled(true); - + le_password->setEnabled(true); + le_user->setEnabled(true); + le_password->clear(); qDebug() << "error:" << error << " and " << errorString; diff --git a/w_timeline.cpp b/w_timeline.cpp index 4708123..290af6a 100644 --- a/w_timeline.cpp +++ b/w_timeline.cpp @@ -2,43 +2,52 @@ #include "w_timeline.h" -w_Timeline::w_Timeline(TwitterSocket *socket, QWidget *parent) +w_Timeline::w_Timeline(QString usr, QString pass, QWidget *parent) { setupUi(this); le_message->setFocus(); - - twitterSocket = socket; + + user = usr; + password = pass; // Send message button (Squawk!) QObject::connect(pb_update, SIGNAL(clicked()), this, SLOT(sendUpdate())); //Result of the button press - QObject::connect( twitterSocket, SIGNAL( result(bool,QString) ), this, SLOT( updateResult(bool, QString) ) ); +// QObject::connect( twitterSocket, SIGNAL( result(bool,QString) ), this, SLOT( updateResult(bool, QString) ) ); //Refresh the timeline ever so often... timer = new QTimer(this); QObject::connect(timer, SIGNAL(timeout()), this, SLOT(refresh())); - timer->start(9000); + //30 seconds + timer->start(30000); } void w_Timeline::sendUpdate() { pb_update->setEnabled(false); - twitterSocket->update(le_message->text()); + le_message->setEnabled(false); + + TwitterSocket *tmp = new TwitterSocket(user,password); + QObject::connect( tmp, SIGNAL( result(bool,QString,QString) ), this, SLOT( updateResult(bool, QString) ) ); + tmp->update(le_message->text()); } void w_Timeline::updateResult(bool error, QString errorstring) { + le_message->setEnabled(true); pb_update->setEnabled(true); le_message->clear(); - qDebug() << "Update done:" << error; } void w_Timeline::refresh() { - qDebug() << "Refreshing..."; + TwitterSocket *tmp = new TwitterSocket(user,password); + QObject::connect( tmp, SIGNAL( result(bool,QString,QString) ), this, SLOT( refreshResult(bool, QString, QString) ) ); + tmp->timeline(); } -void w_Timeline::refreshResult(bool error, QString errorstring) +void w_Timeline::refreshResult(bool error, QString errorstring, QString contents) { qDebug() << "Refresh result:" << error; + qDebug() << "Contents:" << contents; } diff --git a/w_timeline.h b/w_timeline.h index 6d96297..e24939a 100644 --- a/w_timeline.h +++ b/w_timeline.h @@ -9,16 +9,17 @@ class w_Timeline : public QWidget, private Ui::w_timeline Q_OBJECT public: - w_Timeline(TwitterSocket *socket, QWidget *parent = 0); + w_Timeline(QString user, QString password, QWidget *parent = 0); private slots: void sendUpdate(); void refresh(); - void refreshResult(bool error, QString errorstring); + void refreshResult(bool error, QString errorstring, QString contents); void updateResult(bool error, QString errorstring); private: - TwitterSocket *twitterSocket; + QString user; + QString password; QTimer *timer; }; -- 2.11.4.GIT