From ba0736c2a9824f00eeb8bee9d00177f0e3dfc2e7 Mon Sep 17 00:00:00 2001 From: unknown <¹@.(none)> Date: Thu, 11 Aug 2011 18:00:37 +0900 Subject: [PATCH] Before delete before publishing. --- CommandoJikkyouSennyou.pro | 6 +- extrapushbutton.cpp | 40 ++++ extrapushbutton.h | 6 + separatorline.cpp | 18 -- separatorline.h | 26 --- widget.cpp | 489 +++++++++++++++++++++++++++++------------ widget.h | 27 ++- widget.ui | 534 ++++++++++++++++++++++++++++++++------------- 8 files changed, 795 insertions(+), 351 deletions(-) delete mode 100644 separatorline.cpp delete mode 100644 separatorline.h diff --git a/CommandoJikkyouSennyou.pro b/CommandoJikkyouSennyou.pro index 1ba4601..4def948 100644 --- a/CommandoJikkyouSennyou.pro +++ b/CommandoJikkyouSennyou.pro @@ -12,13 +12,11 @@ TEMPLATE = app SOURCES += main.cpp\ widget.cpp \ - extrapushbutton.cpp \ - separatorline.cpp + extrapushbutton.cpp HEADERS += \ widget.h \ - extrapushbutton.h \ - separatorline.h + extrapushbutton.h FORMS += \ widget.ui diff --git a/extrapushbutton.cpp b/extrapushbutton.cpp index bb9e6bb..2bee041 100644 --- a/extrapushbutton.cpp +++ b/extrapushbutton.cpp @@ -1,6 +1,10 @@ #include "extrapushbutton.h" #include +#include +/* + public functions + */ ExtraPushButton::ExtraPushButton(QString shortCutKey, QString string, QWidget *parent) :QPushButton(shortCutKey + ":" + string, parent), _shortCutKey(shortCutKey), @@ -14,6 +18,16 @@ ExtraPushButton::ExtraPushButton(QString shortCutKey, QString string, QWidget *p setMinimumSize(130,23); } +QString ExtraPushButton::getShortCutKey() +{ + return _shortCutKey; +} + +QString ExtraPushButton::getString() +{ + return _string; +} + /* public slots */ @@ -21,3 +35,29 @@ void ExtraPushButton::click() { emit clicked(_string); } + +/* + private functions + */ +void ExtraPushButton::enterEvent(QEvent *e) +{ + switch(e->type()) + { + case QEvent::Enter: + { + if(this->toolTip().size()==0) + { + qDebug("Tool Tip of Button Error"); + return; + } + if(this->isEnabled()==false) + { + return; + } + emit showingToolTip(toolTip()); + break; + } + default: + break; + } +} diff --git a/extrapushbutton.h b/extrapushbutton.h index 3b25f80..e43d73b 100644 --- a/extrapushbutton.h +++ b/extrapushbutton.h @@ -7,15 +7,21 @@ class ExtraPushButton : public QPushButton Q_OBJECT public: ExtraPushButton(QString shortCutKey, QString string, QWidget *parent=0); + QString getShortCutKey(); + QString getString(); public slots: void click(); +protected: + virtual void enterEvent(QEvent *e); + private: QString _shortCutKey, _string; signals: void clicked(QString string); + void showingToolTip(QString toolTipString); }; #endif // EXTRAPUSHBUTTON_H diff --git a/separatorline.cpp b/separatorline.cpp deleted file mode 100644 index 8c7eef8..0000000 --- a/separatorline.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include "separatorline.h" -#include -separatorLine::separatorLine(QWidget *parent) : - QFrame(parent) -{ - setFrameStyle(QFrame::HLine); - setCursor(Qt::SizeVerCursor); -} - -void separatorLine::mousePressEvent(QMouseEvent *e) -{ - emit mousePressed(e->pos()); -} - -void separatorLine::mouseReleaseEvent(QMouseEvent *e) -{ - emit mouseReleased(e->pos()); -} diff --git a/separatorline.h b/separatorline.h deleted file mode 100644 index 64e3b64..0000000 --- a/separatorline.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef SEPARATORLINE_H -#define SEPARATORLINE_H - -#include - -class separatorLine : public QFrame -{ - Q_OBJECT -public: - explicit separatorLine(QWidget *parent = 0); - -protected: - void mousePressEvent(QMouseEvent *e); - void mouseReleaseEvent(QMouseEvent *e); - -private: - -signals: - void mousePressed(QPoint pos); - void mouseReleased(QPoint pos); - -public slots: - -}; - -#endif // SEPARATORLINE_H diff --git a/widget.cpp b/widget.cpp index f5837ef..2614ddf 100644 --- a/widget.cpp +++ b/widget.cpp @@ -8,7 +8,6 @@ #include #include #include "extrapushbutton.h" -#include "separatorline.h" #include #include #include @@ -18,7 +17,8 @@ #include #include #include -#include +#include +#include /* publidc functions */ @@ -33,8 +33,7 @@ Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget){ ui->setupUi(this); QString oauthIniName = qApp->applicationDirPath() - + QDir::separator() - + "QtTC.ini"; + + "/verification.ini"; _oauthSettings = new QSettings(oauthIniName, QSettings::IniFormat); _oauthSettings->setIniCodec("utf-8"); //------------------------- @@ -44,18 +43,22 @@ Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget){ _oauthManager->setNetworkManager(new QNetworkAccessManager); + connect(_oauthManager, SIGNAL(authorizedRequestDone()), + this, SLOT(onAuthorizedRequestDone())); + _oauthRequest->setEnableDebugOutput(true); // デバッグ出力ON // _oauthRequest->setEnableDebugOutput(false); // デバッグ出力OFF //------------------------- - if (_oauthSettings->childKeys().size() == 2) { + if (_oauthSettings->childKeys().size() == 3) { // 既に認証キー取得済みならボタン2を有効にする ui->pushButton_2->setEnabled(true); + + ui->lineEdit->setText(_oauthSettings->value("number").toString()); } QString shortCutKeysIniName = qApp->applicationDirPath() - + QDir::separator() - + "key.txt"; + + "/key.txt"; _shortCutKeysSettings = new QSettings(shortCutKeysIniName, QSettings::IniFormat); _shortCutKeysSettings->setIniCodec("utf-8"); QStringList keyKeys = _shortCutKeysSettings->childKeys(); @@ -70,15 +73,12 @@ Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget){ ui->buttonsGridLayout->addWidget(p,0,i); // Succession of slots can not go well. connect(p, SIGNAL(clicked()), p, SLOT(click())); - //connect(p, SIGNAL(clicked(QString)), this, SLOT(sendTweet(QString))); + connect(p, SIGNAL(clicked(QString)), this, SLOT(sendTweet(QString))); + connect(p, SIGNAL(showingToolTip(QString)), ui->plainTextEdit, SLOT(setPlainText(QString))); } - separatorLine *sl = new separatorLine(this); - ui->timeLienVerticalLayout->addWidget(sl); - QString sizeIniName = qApp->applicationDirPath() - + QDir::separator() - + "size.ini"; + + "/size.ini"; _sizeSettings = new QSettings(sizeIniName, QSettings::IniFormat); if(_sizeSettings->allKeys().count()==2) { @@ -89,7 +89,27 @@ Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget){ resize(200,200); } - QList cList; + // Short Cut Key for Post. + QShortcut *post1 = new QShortcut(ui->lineEdit_2); + QShortcut *post2 = new QShortcut(ui->lineEdit_3); + QShortcut *post3 = new QShortcut(ui->lineEdit_4); + QShortcut *post4 = new QShortcut(ui->lineEdit_5); + QShortcut *post5 = new QShortcut(ui->lineEdit_6); + QList postShortCutList; + postShortCutList << post1 << post2 << post3 << post4 << post5; + for(int i=0;isetShortCutKeyAndContext(postShortCutList.at(i), QKeyStandard(Qt::CTRL + Qt::Key_Return), Qt::WidgetShortcut); + } + + connect(post1, SIGNAL(activated()), ui->pushButton_4, SLOT(click())); + connect(post2, SIGNAL(activated()), ui->pushButton_4, SLOT(click())); + connect(post3, SIGNAL(activated()), ui->pushButton_4, SLOT(click())); + connect(post4, SIGNAL(activated()), ui->pushButton_4, SLOT(click())); + connect(post5, SIGNAL(activated()), ui->pushButton_4, SLOT(click())); + + //initializeOwnPostsWidgets(); + /* QList cList; QFile f1(qApp->applicationDirPath() + "\\" + "v.cer"); f1.open(QIODevice::ReadOnly); @@ -122,8 +142,8 @@ Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget){ sock->setCaCertificates(cList); qDebug() << "[CLIENT]: Attempting Connection..."; //sock->connectToHostEncrypted("userstream.twitter.com/2/user.json", 443); - //sock->connectToHostEncrypted("userstream.twitter.com", 443); - sock->connectToHostEncrypted("api.twitter.com", 443); + sock->connectToHostEncrypted("userstream.twitter.com", 443); + //sock->connectToHostEncrypted("api.twitter.com", 443); if(sock->waitForConnected()) { @@ -150,10 +170,11 @@ Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget){ } qDebug("Writing"); - if(true) + if(false) { - QUrl url("https://api.twitter.com/1/statuses/home_timeline.json"); + //QUrl url("https://api.twitter.com/1/statuses/home_timeline.json"); //QUrl url("https://userstream.twitter.com/2/user.json"); + QUrl url("http://stream.twitter.com/1/filter.json"); _oauthRequest->initRequest(KQOAuthRequest::AuthorizedRequest, url); _oauthRequest->setHttpMethod(KQOAuthRequest::GET); // GET指定 _oauthRequest->setConsumerKey("nXrjGagSLIQxCC4AmJ1J3g"); @@ -170,7 +191,7 @@ Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget){ this, SLOT(onAuthorizedRequestDone())); // _oauthManager->executeRequest(_oauthRequest); } - else + else if(false) { QUrl url("https://api.twitter.com/1/statuses/update.xml"); _oauthRequest->initRequest(KQOAuthRequest::AuthorizedRequest,url); @@ -186,7 +207,47 @@ Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget){ _oauthRequest->setAdditionalParameters(params); // _oauthManager->executeRequest(_oauthRequest); } + else if(false) + { + QUrl url("http://stream.twitter.com/1/statuses/filter.json"); + _oauthRequest->initRequest(KQOAuthRequest::AuthorizedRequest,url); + _oauthRequest->setHttpMethod(KQOAuthRequest::POST); // POST指定 + _oauthRequest->setConsumerKey("nXrjGagSLIQxCC4AmJ1J3g"); + _oauthRequest->setConsumerSecretKey("QkTRr36zT6wAMERWqKUefyshxXIeaGzPKxB5pwMN0tg"); + _oauthRequest->setToken(_oauthSettings->value("oauth_token").toString()); + _oauthRequest->setTokenSecret(_oauthSettings->value("oauth_token_secret").toString()); + KQOAuthParameters params; + params.insert("follow", "2062439"); + _oauthRequest->setAdditionalParameters(params); + + connect(sock, SIGNAL(readyRead()), this, SLOT(readyRead())); + disconnect(_oauthManager, SIGNAL(requestReady(QByteArray))); + connect(_oauthManager, SIGNAL(requestReady(QByteArray)), + this, SLOT(onRequestReadyTimeline(QByteArray))); + connect(_oauthManager, SIGNAL(authorizedRequestDone()), + this, SLOT(onAuthorizedRequestDone())); + // _oauthManager->executeRequest(_oauthRequest); + } + else + { + QUrl url("http://stream.twitter.com/1/sample.json"); + _oauthRequest->initRequest(KQOAuthRequest::AuthorizedRequest, url); + _oauthRequest->setHttpMethod(KQOAuthRequest::GET); // GET指定 + _oauthRequest->setConsumerKey("nXrjGagSLIQxCC4AmJ1J3g"); + _oauthRequest->setConsumerSecretKey("QkTRr36zT6wAMERWqKUefyshxXIeaGzPKxB5pwMN0tg"); + _oauthRequest->setToken(_oauthSettings->value("oauth_token").toString()); + _oauthRequest->setTokenSecret( + _oauthSettings->value("oauth_token_secret").toString()); + + connect(sock, SIGNAL(readyRead()), this, SLOT(readyRead())); + disconnect(_oauthManager, SIGNAL(requestReady(QByteArray))); + connect(_oauthManager, SIGNAL(requestReady(QByteArray)), + this, SLOT(onRequestReadyTimeline(QByteArray))); + connect(_oauthManager, SIGNAL(authorizedRequestDone()), + this, SLOT(onAuthorizedRequestDone())); + // _oauthManager->executeRequest(_oauthRequest); + } QNetworkRequest networkRequest; networkRequest.setUrl( _oauthRequest->requestEndpoint() ); @@ -236,25 +297,26 @@ Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget){ // Submit the request including the params. //QNetworkReply *reply = d->networkManager->get(networkRequest); - QNetworkReply *reply = _oauthManager->networkManager()->get(networkRequest); + //QNetworkReply *reply = _oauthManager->networkManager()->get(networkRequest); //qDebug() << reply->readAll(); //QByteArray array("GET /1/statuses/home_timeline.json"); - QByteArray array("GET /2/user.json"); + //QByteArray array("GET /2/user.json"); + QByteArray array("GET /1/statuses/sample.json"); array.append("\r\nAuthorization: " + authHeader); - // array.append("HTTP/1.1\r\n"); - // .append("Accept: */* \r\n") - // .append("Accept-Language: ja\r\n") - // .append("If-Modified-Since: Mon,04 Dec 2000 00:11:45 GMT; length=35\r\n") - // .append("User-Agent: Mozilla/4.0(compatible; MSIE 5.5; Windows NT 5.0)\r\n") - //array.append("Host: ").append("api.twitter.com").append("\r\n"); - // array.append("Host: ").append("userstream.twitter.com").append("\r\n"); - // .append("Connection: Keep-Alive") - //qDebug() << array; - //sock->write(array); - - connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), - this, SLOT(slotError(QNetworkReply::NetworkError))); + // array.append("HTTP/1.1\r\n"); + // .append("Accept: *\/\* \r\n") + // .append("Accept-Language: ja\r\n") + // .append("If-Modified-Since: Mon,04 Dec 2000 00:11:45 GMT; length=35\r\n") + // .append("User-Agent: Mozilla/4.0(compatible; MSIE 5.5; Windows NT 5.0)\r\n"); + // array.append("Host: ").append("api.twitter.com").append("\r\n"); + // array.append("Host: ").append("userstream.twitter.com").append("\r\n"); + // .append("Connection: Keep-Alive"); + qDebug() << array; + sock->write(array); + +// connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), +// this, SLOT(slotError(QNetworkReply::NetworkError))); } else if (_oauthRequest->httpMethod() == KQOAuthRequest::POST) { @@ -268,7 +330,7 @@ Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget){ if (_oauthRequest->contentType() == "application/x-www-form-urlencoded") { //reply = d->networkManager->post(networkRequest, _oauthRequest->requestBody()); reply = _oauthManager->networkManager()->post(networkRequest, _oauthRequest->requestBody()); - qDebug() << "pp" << _oauthRequest->requestBody(); + qDebug() << "pp" << _oauthRequest->requestBody() << reply->readAll(); } else { //reply = d->networkManager->post(networkRequest, _oauthRequest->rawData()); reply = _oauthManager->networkManager()->post(networkRequest, _oauthRequest->rawData()); @@ -279,12 +341,48 @@ Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget){ this, SLOT(slotError(QNetworkReply::NetworkError))); } - return; - +*/ // sock->disconnectFromHost(); // } } +bool Widget::setShortCutKeyAndContext(QShortcut *sc, QKeySequence s, Qt::ShortcutContext c) +{ + sc->setKey(s); + sc->setContext(c); +} + +bool Widget::initializeOwnPostsWidgets() +{ + QUrl url("https://api.twitter.com/1/statuses/user_timeline.json"); + _oauthRequest->initRequest(KQOAuthRequest::AuthorizedRequest, url); + _oauthRequest->setHttpMethod(KQOAuthRequest::GET); // GET指定 + _oauthRequest->setConsumerKey("nXrjGagSLIQxCC4AmJ1J3g"); + _oauthRequest->setConsumerSecretKey("QkTRr36zT6wAMERWqKUefyshxXIeaGzPKxB5pwMN0tg"); + _oauthRequest->setToken(_oauthSettings->value("oauth_token").toString()); + _oauthRequest->setTokenSecret( + _oauthSettings->value("oauth_token_secret").toString()); + + KQOAuthParameters params; + params.insert("count", "131"); + _oauthRequest->setAdditionalParameters(params); + + + qDebug() << _oauthSettings->value("oauth_token").toString(); + qDebug() << _oauthSettings->value("oauth_token_secret").toString(); + + disconnect(_oauthManager, SIGNAL(requestReady(QByteArray))); + connect(_oauthManager, SIGNAL(requestReady(QByteArray)), + this, SLOT(onRequestReadyOwnPosts(QByteArray))); + + connect(_oauthManager, SIGNAL(authorizedRequestDone()), + this, SLOT(onAuthorizedRequestDone())); + + _oauthManager->executeRequest(_oauthRequest); + + return true; +} + void Widget::slotError(QNetworkReply::NetworkError e) { qDebug() << "1" << e; @@ -297,7 +395,8 @@ void Widget::cState(QAbstractSocket::SocketState s) void Widget::readyRead() { - qDebug() << "3" << sock->readAll(); + qDebug() << "3"; + qDebug() << sock->readAll(); } void Widget::cError(QAbstractSocket::SocketError e) @@ -366,7 +465,8 @@ void Widget::keyPressEvent(QKeyEvent *ke) qDebug() << ke->text() << _keyString << ke->count(); for(int i=0;ibuttonsGridLayout->count();++i) { - if(dynamic_cast(ui->buttonsGridLayout->itemAt(i)->widget())->text().contains(QRegExp("^" + _keyString))==false) + ExtraPushButton *p = dynamic_cast(ui->buttonsGridLayout->itemAt(i)->widget()); + if(p->getShortCutKey().indexOf(_keyString)==-1) { ui->buttonsGridLayout->itemAt(i)->widget()->setEnabled(false); } @@ -382,49 +482,59 @@ void Widget::keyReleaseEvent(QKeyEvent *ke) } if( ( ke->key()==Qt::Key_Control) && (_keyString.size()>0) ) { - for(int i=0;ibuttonsGridLayout->count();++i) - { - if(!dynamic_cast(ui->buttonsGridLayout->itemAt(i)->widget())->text().contains(QRegExp("^" + _keyString))); - { - ui->buttonsGridLayout->itemAt(i)->widget()->setEnabled(true); - } - } qDebug() << "ctrl!" << _keyString; QString tweet; - QList list = _keysHash->keys(); int matchedKeysNumber = 0; + QList list = _keysHash->keys(); for(int i=0;ivalue(list.at(i)); + matchedKeysNumber = -1; + break; + } ++matchedKeysNumber; tweet = _keysHash->value(list.at(i)); } - if(matchedKeysNumber>1) - { - break; - } } - if(matchedKeysNumber!=1) + + if(matchedKeysNumber>1) { tweet.clear(); } _keyString.clear(); - if(tweet.size()==0) - { - qDebug() << "There is not such a short cut key."; - return; - } if(tweet.contains(QRegExp("\\(\\d.*\\)"))) { - qDebug("ho"); + ui->plainTextEdit->setPlainText(tweet); + for(int i=0;ibuttonsGridLayout->count();++i) + { + if(ui->buttonsGridLayout->itemAt(i)->widget()->isEnabled()==true) + { + ui->buttonsGridLayout->itemAt(i)->widget()->setEnabled(false); + } + } ui->lineEdit_2->setFocus(); } else { - //sendTweet(tweet); + for(int i=0;ibuttonsGridLayout->count();++i) + { + if(ui->buttonsGridLayout->itemAt(i)->widget()->isEnabled()==false) + { + ui->buttonsGridLayout->itemAt(i)->widget()->setEnabled(true); + } + } + if(tweet.size()==0) + { + qDebug() << "There is not such a short cut key."; + return; + } + sendTweet(tweet); } - qDebug() << "send " << tweet; tweet.clear(); } } @@ -561,7 +671,7 @@ void Widget::onAccessTokenReceived(QString token, QString tokenSecret) qDebug() << "Access token received: " << token << tokenSecret; _oauthSettings->setValue(tr("oauth_token"), token); - _oauthSettings->setValue(tr("_oauth_token_secret"), tokenSecret); + _oauthSettings->setValue(tr("oauth_token_secret"), tokenSecret); qDebug() << "Access tokens now stored. " "You are ready to send Tweets from user's account!"; @@ -580,6 +690,9 @@ void Widget::onRequestReady(QByteArray response) } void Widget::on_pushButton_clicked() { + ui->lineEdit->setEnabled(true); + ui->pushButton_3->setEnabled(true); + //-------------------------- // kQOAuthのスロットの登録 connect(_oauthManager, SIGNAL(temporaryTokenReceived(QString,QString)), @@ -622,9 +735,10 @@ void Widget::on_pushButton_clicked() { } void Widget::on_pushButton_2_clicked() { - ui->pushButton_2->setEnabled(false); + //ui->pushButton_2->setEnabled(false); + ui->listWidget->clear(); - QUrl url("https://api.twitter.com/1/statuses/home_timeline.xml"); + QUrl url("https://api.twitter.com/1/statuses/home_timeline.json"); _oauthRequest->initRequest(KQOAuthRequest::AuthorizedRequest, url); _oauthRequest->setHttpMethod(KQOAuthRequest::GET); // GET指定 _oauthRequest->setConsumerKey("nXrjGagSLIQxCC4AmJ1J3g"); @@ -636,12 +750,12 @@ void Widget::on_pushButton_2_clicked() { qDebug() << _oauthSettings->value("oauth_token").toString(); qDebug() << _oauthSettings->value("oauth_token_secret").toString(); - disconnect(_oauthManager, SIGNAL(requestReady(QByteArray))); + disconnect(_oauthManager, SIGNAL(requestReady(QByteArray)),0,0); connect(_oauthManager, SIGNAL(requestReady(QByteArray)), this, SLOT(onRequestReadyTimeline(QByteArray))); - connect(_oauthManager, SIGNAL(authorizedRequestDone()), - this, SLOT(onAuthorizedRequestDone())); + // connect(_oauthManager, SIGNAL(authorizedRequestDone()), + // this, SLOT(onAuthorizedRequestDone())); _oauthManager->executeRequest(_oauthRequest); } @@ -649,6 +763,7 @@ void Widget::on_pushButton_2_clicked() { void Widget::onRequestReadyTimeline(QByteArray response) { qDebug() << "requestReady-Timeline"; QDomDocument dom; + // For JSON if(dom.setContent(response)==false) { QJson::Parser parser; @@ -656,157 +771,188 @@ void Widget::onRequestReadyTimeline(QByteArray response) { QVariant top = parser.parse(response, &ok); if(!ok) { - qDebug() << "json error"; + qDebug() << response.size() << response << "json error"; return; } - qDebug() << "top.list.size:" << top.toList().size(); - qDebug() << "top.map.size:" << top.toMap().size(); //QVariantMap result = top.toMap(); QVariantList contentList = top.toList(); foreach ( QVariant content, contentList ){ - //qDebug() << contentList.toMap(); + /* qDebug() << content.toMap()["contributors"] << - "\t" << + "\n" << content.toMap()["coordinates"] << - "-" << + "\n" << content.toMap()["created_at"].toString() << - "\t" << + "\n" << content.toMap()["geo"]<< - "\t" << + "\n" << content.toMap()["id"].toLongLong() << - ":" << + "\n" << content.toMap()["id_str"].toString() << - ":" << + "\n" << content.toMap()["in_reply_to_screen_name"] << - ":" << + "\n" << content.toMap()["in_reply_to_status_id"]<< - ":" << + "\n" << content.toMap()["in_reply_to_status_id"] << - ":" << + "\n" << content.toMap()["in_reply_to_user_id"] << - ":" << + "\n" << content.toMap()["in_reply_to_user_id_str"] << - ":" << + "\n" << content.toMap()["place"] << - ":" << + "\n" << content.toMap()["possibly_sensitive"].toBool() << - ":" << + "\n" << content.toMap()["retweet_count"].toULongLong() << - ":" << + "\n" << content.toMap()["retweeted"].toBool() << - ":" << + "\n" << content.toMap()["text"].toString() << - ":" << + "\n" << content.toMap()["truncated"].toBool() << - ":" << + "\n" << content.toMap()["user"].toMap()["contributors_enabled"].toBool() << - ":" << + "\n" << content.toMap()["user"].toMap()["created_at"].toString() << - ":" << + "\n" << content.toMap()["user"].toMap()["default_profile"].toBool() << - ":" << + "\n" << content.toMap()["user"].toMap()["default_profile_image"].toBool() << - ":" << + "\n" << content.toMap()["user"].toMap()["description"].toString() << - ":" << + "\n" << content.toMap()["user"].toMap()["favourites_count"].toULongLong() << - ":" << + "\n" << content.toMap()["user"].toMap()["followers_count"].toULongLong() << - ":" << + "\n" << content.toMap()["user"].toMap()["following"].toBool() << - ":" << + "\n" << content.toMap()["user"].toMap()["friends_count"].toULongLong() << - ":" << + "\n" << content.toMap()["user"].toMap()["geo_enabled"].toBool() << - ":" << + "\n" << content.toMap()["user"].toMap()["id"].toULongLong() << - ":" << + "\n" << content.toMap()["user"].toMap()["id_str"].toString() << - ":" << + "\n" << content.toMap()["user"].toMap()["is_translator"].toBool() << - ":" << + "\n" << content.toMap()["user"].toMap()["lang"].toString() << - ":" << + "\n" << content.toMap()["user"].toMap()["listed_count"].toULongLong() << - ":" << + "\n" << content.toMap()["user"].toMap()["location"].toString() << - ":" << + "\n" << content.toMap()["user"].toMap()["profile_background_color"].toString() << - ":" << + "\n" << content.toMap()["user"].toMap()["profile_background_image_url"].toString() << - ":" << + "\n" << content.toMap()["user"].toMap()["profile_background_image_url_https"].toString() << - ":" << + "\n" << content.toMap()["user"].toMap()["profile_background_tile"].toBool() << - ":" << + "\n" << content.toMap()["user"].toMap()["profile_image_url_https"].toString() << - ":" << + "\n" << content.toMap()["user"].toMap()["profile_sidebar_border_color"].toString() << - ":" << + "\n" << content.toMap()["user"].toMap()["profile_sidebar_fill_color"].toString() << - ":" << + "\n" << content.toMap()["user"].toMap()["profile_text_color"].toString() << - ":" << + "\n" << content.toMap()["user"].toMap()["profile_use_background_image"].toString() << - ":" << + "\n" << content.toMap()["user"].toMap()["protected"].toBool() << - ":" << + "\n" << content.toMap()["user"].toMap()["screen_name"].toBool() << - ":" << + "\n" << content.toMap()["user"].toMap()["show_all_inline_media"].toString() << - ":" << + "\n" << content.toMap()["user"].toMap()["statuses_count"].toULongLong() << - ":" << + "\n" << content.toMap()["user"].toMap()["time_zone"].toString() << - ":" << + "\n" << content.toMap()["user"].toMap()["url"].toString() << - ":" << + "\n" << content.toMap()["user"].toMap()["utc_offset"].toULongLong() << - ":" << + "\n" << content.toMap()["user"].toMap()["verified"].toBool() << "\n\n"; - +*/ ui->listWidget->addItem(content.toMap()["text"].toString()); } return; } - - // DOM からヘッダ情報を取得する - QDomElement root = dom.documentElement(); - QDomNode node; - node = root.firstChild(); - while ( !node.isNull() ) + // for XML + else { - if ( node.isElement() && (node.nodeName() == "status" ) ) + QDomElement root = dom.documentElement(); + QDomNode node; + node = root.firstChild(); + while ( !node.isNull() ) { - QDomElement header = node.toElement(); - - QDomNode node = header.firstChild(); - while ( !node.isNull() ) + if ( node.isElement() && (node.nodeName() == "status" ) ) { - if ( node.isElement() ) + QDomElement header = node.toElement(); + + QDomNode node = header.firstChild(); + while ( !node.isNull() ) { - // いろいろなヘッダエントリの場合 - if ( node.nodeName() == "text" ) + if ( node.isElement() ) { - QDomText textChild = node.firstChild().toText(); - if ( !textChild.isNull() ) + // いろいろなヘッダエントリの場合 + if ( node.nodeName() == "text" ) { - qDebug() << textChild.nodeValue(); - ui->listWidget->addItem(textChild.nodeValue()); + QDomText textChild = node.firstChild().toText(); + if ( !textChild.isNull() ) + { + ui->listWidget->addItem(textChild.nodeValue()); + } } } + node = node.nextSibling(); } - node = node.nextSibling(); } + node = node.nextSibling(); } - node = node.nextSibling(); } } +void Widget::onRequestReadyOwnPosts(QByteArray response) { + qDebug() << "requestReady-OwnPosts"; + // for JSON + QDomDocument dom; + if(dom.setContent(response)==false) + { + QJson::Parser parser; + bool ok =false; + QVariant top = parser.parse(response, &ok); + if(!ok) + { + qDebug() << response.size() << response << "json error"; + return; + } + qDebug() << "top.list.size:" << top.toList().size(); + qDebug() << "top.map.size:" << top.toMap().size(); + + //QVariantMap result = top.toMap(); + QVariantList contentList = top.toList(); + + for(int i=0;itableWidget_2->setItem(ui->tableWidget_2->rowCount()-i-1, 0, new QTableWidgetItem(content.toMap()["created_at"].toString().mid(8,11))); + if(i<10) + { + ui->tableWidget->setItem(9-i,0, new QTableWidgetItem(content.toMap()["text"].toString())); + } + } + return; + } +} void Widget::sendTweet(QString tweet) { @@ -830,11 +976,24 @@ void Widget::sendTweet(QString tweet) { _oauthRequest->setAdditionalParameters(params); qDebug() << "Attempting send tweet such as " << tweet; - _oauthManager->executeRequest(_oauthRequest); + //_oauthManager->executeRequest(_oauthRequest); + + ui->tableWidget->removeRow(0); + ui->tableWidget->setRowCount(ui->tableWidget->rowCount()+1); + ui->tableWidget->setItem(9,0,new QTableWidgetItem(tweet)); + ui->tableWidget_2->removeRow(0); + ui->tableWidget_2->setRowCount(ui->tableWidget_2->rowCount()+1); + ui->tableWidget_2->setItem(129,0, new QTableWidgetItem( (QDateTime::currentDateTime().toString("dd hh:mm:ss")))); // connect(_oauthManager, SIGNAL(authorizedRequestReady()), // this, SLOT(onAuthorizedRequestReady())); + // LineEdits must cleare content. + ui->lineEdit_2->clear(); + ui->lineEdit_3->clear(); + ui->lineEdit_4->clear(); + ui->lineEdit_5->clear(); + ui->lineEdit_6->clear(); } void Widget::showOAuthError(const int nErrNum) @@ -844,6 +1003,9 @@ void Widget::showOAuthError(const int nErrNum) void Widget::on_pushButton_3_clicked() { + ui->lineEdit->setEnabled(false); + ui->pushButton_3->setEnabled(false); + _oauthSettings->setValue("number", ui->lineEdit->text()); _oauthManager->onVerificationReceived1(ui->lineEdit->text()); } @@ -851,3 +1013,46 @@ void Widget::on_lineEdit_2_editingFinished() { //lineEditの継承クラスにCtrl+Enter押し下し時の処置:(\d)との置換:を記述する } + +void Widget::on_pushButton_4_clicked() +{ + QString tweet = ui->plainTextEdit->toPlainText(); + tweet.replace(QRegExp("\\(\\d+:([^()]+)\\)"), "\\1"); + sendTweet(tweet); +} + +void Widget::on_lineEdit_2_textChanged(const QString &arg1) +{ + replacePlainTextEditContent(1, arg1); +} + +void Widget::on_lineEdit_3_textChanged(const QString &arg1) +{ + replacePlainTextEditContent(1, arg1); +} + +void Widget::on_lineEdit_4_textChanged(const QString &arg1) +{ + replacePlainTextEditContent(1, arg1); +} + +void Widget::on_lineEdit_5_textChanged(const QString &arg1) +{ + replacePlainTextEditContent(1, arg1); +} + +void Widget::on_lineEdit_6_textChanged(const QString &arg1) +{ + replacePlainTextEditContent(1, arg1); +} + +bool Widget::replacePlainTextEditContent(int i, QString str) +{ + if(str.length()>0) + { + QString text = ui->plainTextEdit->toPlainText(); + text.replace(QRegExp("(\\(" + QString::number(i) + ":)[^()]+(\\))"), "\\1" + str + "\\2"); + ui->plainTextEdit->setPlainText(text); + } + return true; +} diff --git a/widget.h b/widget.h index 2821e61..5e4fd6b 100644 --- a/widget.h +++ b/widget.h @@ -14,6 +14,7 @@ #include #include #include +#include class KQOAuthManager; class KQOAuthRequest; //class KQOAuthRequest_XAuth; @@ -28,13 +29,11 @@ class Widget : public QWidget { public: explicit Widget(QWidget *parent = 0); ~Widget(); + bool initializeOwnPostsWidgets(); + bool replacePlainTextEditContent(int i, QString str); + bool setShortCutKeyAndContext(QShortcut *sc, QKeySequence s, Qt::ShortcutContext c); public slots: - void receive(QList e); - void cError(QAbstractSocket::SocketError); - void readyRead(); - void cState(QAbstractSocket::SocketState); - void slotError(QNetworkReply::NetworkError); protected: void keyPressEvent(QKeyEvent *); @@ -49,13 +48,31 @@ private slots: void onAuthorizedRequestDone(); void onRequestReady(QByteArray response); void onRequestReadyTimeline(QByteArray response); + void onRequestReadyOwnPosts(QByteArray); void sendTweet(QString tweet); + void receive(QList e); + void cError(QAbstractSocket::SocketError); + void readyRead(); + void cState(QAbstractSocket::SocketState); + void slotError(QNetworkReply::NetworkError); void on_pushButton_clicked(); void on_pushButton_2_clicked(); void on_pushButton_3_clicked(); void on_lineEdit_2_editingFinished(); + void on_pushButton_4_clicked(); + + void on_lineEdit_2_textChanged(const QString &arg1); + + void on_lineEdit_3_textChanged(const QString &arg1); + + void on_lineEdit_4_textChanged(const QString &arg1); + + void on_lineEdit_5_textChanged(const QString &arg1); + + void on_lineEdit_6_textChanged(const QString &arg1); + private: Ui::Widget *ui; diff --git a/widget.ui b/widget.ui index b3ef00d..fea99a6 100644 --- a/widget.ui +++ b/widget.ui @@ -6,178 +6,400 @@ 0 0 - 402 - 358 + 361 + 484 - Qt::TabFocus + Qt::ClickFocus - + - QLayout::SetMaximumSize + QLayout::SetNoConstraint - - - - - - - 75 - 23 - - - - - 75 - 23 - - - - Qt::ClickFocus - - - OAuth - - - - - - - - 75 - 20 - - - - - 75 - 20 - - - - Qt::ClickFocus - - - - - - - - 75 - 23 - - - - - 75 - 23 - - - - Qt::ClickFocus - - - Verification + + + + Qt::Vertical + + + + + + + + + + 75 + 23 + + + + + 75 + 23 + + + + Qt::ClickFocus + + + OAuth + + + + + + + false + + + + 75 + 20 + + + + + 75 + 20 + + + + Qt::ClickFocus + + + + + + + false + + + + 75 + 23 + + + + + 75 + 23 + + + + Qt::ClickFocus + + + Verification + + + + + + + Latest 130 + + + + + + + Qt::NoFocus + + + 130 + + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 日 時刻 + + + + + 現時刻との差 + + + + + + + + Latest 10 + + + + + + + Qt::NoFocus + + + 10 + + + 1 + + + true + + + + + + + + + + + + + + POST + + + + + + + + + + + + TL + + + + + + + + + + + + + + QLayout::SetMaximumSize - - - - - - Qt::Vertical + + + + Qt::ClickFocus + + + + + + + + + + + + + + + + + + + false + + + + + + + POST +Ctrl+Enter + + + + + + + + + 0 + 0 + + + + ctrl+ + + + + 0 - - - 20 - 174 - + + 0 - - - - - - - - - - TL - - - - - - - - - - - - false - + + + + true + + + + + 0 + 0 + 339 + 69 + + + + + + + + + + + + - - - - false - - - - - - - - - - - 0 - 0 - - - - ctrl+ - - - - - - QLayout::SetDefaultConstraint - - - - - - - - - - false - - - - - - - false - - - - - - - lineEdit_2 - lineEdit_3 - lineEdit_4 - lineEdit_5 - lineEdit_6 pushButton lineEdit - plainTextEdit pushButton_3 pushButton_2 listWidget -- 2.11.0