diff --git a/saori.pro b/saori.pro index 3ebcb58..225a8de 100644 --- a/saori.pro +++ b/saori.pro @@ -32,7 +32,8 @@ saoriapplication.cpp \ saoricache.cpp \ saoriviewentry.cpp \ - saoriconfiguredialog.cpp + saoriconfiguredialog.cpp \ + saoritootwidget.cpp HEADERS += \ saoriwindow.h \ @@ -44,13 +45,15 @@ saoriapplication.h \ saoricache.h \ saoriviewentry.h \ - saoriconfiguredialog.h + saoriconfiguredialog.h \ + saoritootwidget.h FORMS += \ saoriwindow.ui \ saoriview.ui \ saoriaddaccountdialog.ui \ - saoriconfiguredialog.ui + saoriconfiguredialog.ui \ + saoritootwidget.ui TRANSLATIONS += \ saori_ja.ts diff --git a/saori_ja.qm b/saori_ja.qm index beedf00..7e09b7f 100644 --- a/saori_ja.qm +++ b/saori_ja.qm Binary files differ diff --git a/saori_ja.ts b/saori_ja.ts index 461f047..8a543e0 100644 --- a/saori_ja.ts +++ b/saori_ja.ts @@ -50,92 +50,148 @@ - SaoriView + SaoriConfigureDialog - - Form + + Setting - - Pin - ピン + + Application Setting + - - Notify - 通知 + + Maximum number of entries to get: + - - Auto reload - 自動更新 + + Auto reload Interval (minutes): + + + + + SaoriTootWidget + + + Form + - - Newest - 最新 + + Text + テキスト - - Reload - 更新 - - - + Toot トゥート - - <div>%1</div><div>%2</div><div>%3</div><div>email : %4</div><div>%5</div><div>version : %6</div> - + + 500 + - + + clear + クリア + + + + Toot! + トゥート! + + + + %1 says + %1 曰く + + + + SaoriView + + + Form + + + + + Pin + ピン + + + + Notify + 通知 + + + + Auto reload + 自動更新 + + + + Newest + 最新 + + + + Reload + 更新 + + + + Toot + トゥート + + + boosted by: %1 %1 さんがブースト - - + + created at : 投稿日時 : - + following: フォロー: - + followers: フォロワー: - + %1 mentioned your status. %1 さんが言及 - + %1 boosted your status. %1 さんがブースト - + %1 favourited your status. %1 さんがお気に入りに追加 - + %1 followed you. %1 さんにフォローされました - - %1 - + + %1 (@%2) + @@ -162,102 +218,102 @@ 編集(&E) - + &Help ヘルプ(&H) - + Timeline &list タイムラインリスト(&l) - - Auto reload Interval (minutes) - - - - + List リスト - + Account - + Instance - + &Quit - + Show/Hide Timeline &List - + &Open Timeline - + &Add Account - + &Remove Account - + &TabbedView mode - + T&iled - + + &Configure + + + + Accounts アカウント - + home ホーム - + local ローカルタイムライン - + public 連合タイムライン - + notifications 通知 - + instance - + Instances インスタンス diff --git a/saoriaccount.cpp b/saoriaccount.cpp index a9009bd..a0c3084 100644 --- a/saoriaccount.cpp +++ b/saoriaccount.cpp @@ -84,6 +84,7 @@ { QNetworkRequest request; request.setRawHeader("Authorization","Bearer " + accessToken().toLatin1()); + request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); return request; } @@ -123,3 +124,14 @@ }); return; } + +void SaoriAccount::postNewStatus(const QString timeline, const QString data) +{ + QUrl url(instance()->instance().toString() + SAORI_MASTODON_APIPATH_POST); + QNetworkRequest request = createHearder(); + request.setUrl(url); + auto *reply = SaoriApplication::saori()->manager->post(request,data.toUtf8()); + connect(reply,&QNetworkReply::finished,[=](){ + emit posted(timeline,reply->error()); + }); +} diff --git a/saoriaccount.h b/saoriaccount.h index 61faf51..8ac86b0 100644 --- a/saoriaccount.h +++ b/saoriaccount.h @@ -53,6 +53,7 @@ public slots: void getTimelineData(const QString timeline,const QUrlQuery query); + void postNewStatus(const QString timeline,const QString data); protected: void getAccountInfomation(); @@ -68,6 +69,7 @@ void accessTokenChanged(QString); void accountInfomationChanged(); void apiData(const QString timeline,const QByteArray data); + void posted(const QString timeline,int result); public slots: }; diff --git a/saoridef.h b/saoridef.h index 9873a59..2d88f75 100644 --- a/saoridef.h +++ b/saoridef.h @@ -44,6 +44,6 @@ #define SAORI_MASTODON_APIPATH_ACCOUNTS "/api/v1/accounts" #define SAORI_MASTODON_APIPATH_TIMELINE "/api/v1/timelines" #define SAORI_MASTODON_APIPATH_NOTIFICATION "/api/v1/notifications" - +#define SAORI_MASTODON_APIPATH_POST "/api/v1/statuses" #endif // SAORIDEF_H diff --git a/saoritootwidget.cpp b/saoritootwidget.cpp new file mode 100644 index 0000000..cc259ed --- /dev/null +++ b/saoritootwidget.cpp @@ -0,0 +1,75 @@ +/*** + +The MIT License + +Copyright (c) 2018 Teppei Tamra (TAM) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +***/ + +#include "saoritootwidget.h" +#include "ui_saoritootwidget.h" +#include +#include +#include + +SaoriTootWidget::SaoriTootWidget(QWidget *parent) : + QWidget(parent), + ui(new Ui::SaoriTootWidget) +{ + ui->setupUi(this); + connect(ui->textEdit_toot,&QTextEdit::textChanged,this,[=](){ + int c = 500 - ui->textEdit_toot->toPlainText().count(); + if ((c >= 500) || (c < 0)) ui->pushButton_commit->setEnabled(false); + else ui->pushButton_commit->setEnabled(true); + if (c < 0) ui->label_count->setText("" + QString::number(c) + ""); + else if (c < 100) ui->label_count->setText("" + QString::number(c) + ""); + else ui->label_count->setText("" + QString::number(c) + ""); + }); +} + +SaoriTootWidget::~SaoriTootWidget() +{ + delete ui; +} + +void SaoriTootWidget::setAccountLabel(const QString label) +{ + ui->label_account->setText(tr("%1 says").arg(label)); +} + +void SaoriTootWidget::posted(int result) +{ + if (result == QNetworkReply::NoError) { + ui->textEdit_toot->clear(); + } +} + +const QString SaoriTootWidget::createPostData() +{ + // TODO in_reply_to_id、media_ids、sensitive…。 + QString result = "status=" + ui->textEdit_toot->toPlainText().toUtf8().toPercentEncoding(); + return result; +} + +void SaoriTootWidget::on_pushButton_commit_clicked() +{ + emit postNewStatus(createPostData()); +} diff --git a/saoritootwidget.h b/saoritootwidget.h new file mode 100644 index 0000000..d661a93 --- /dev/null +++ b/saoritootwidget.h @@ -0,0 +1,62 @@ +/*** + +The MIT License + +Copyright (c) 2018 Teppei Tamra (TAM) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +***/ + +#ifndef SAORITOOTWIDGET_H +#define SAORITOOTWIDGET_H + +#include +#include + +namespace Ui { +class SaoriTootWidget; +} + +class SaoriTootWidget : public QWidget +{ + Q_OBJECT + +public: + explicit SaoriTootWidget(QWidget *parent = 0); + ~SaoriTootWidget(); + void setAccountLabel(const QString label); + +public slots: + void posted(int result); + +protected: + const QString createPostData(); + +signals: + void postNewStatus(const QString data); + +private slots: + void on_pushButton_commit_clicked(); + +private: + Ui::SaoriTootWidget *ui; +}; + +#endif // SAORITOOTWIDGET_H diff --git a/saoritootwidget.ui b/saoritootwidget.ui new file mode 100644 index 0000000..f8afa5f --- /dev/null +++ b/saoritootwidget.ui @@ -0,0 +1,102 @@ + + + SaoriTootWidget + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + 0 + + + + Text + + + + + + Toot + + + + + + + + 0 + 0 + + + + Qt::DefaultContextMenu + + + + + + + + + + + + + 500 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::NoFocus + + + clear + + + + + + + false + + + Qt::ActionsContextMenu + + + Toot! + + + + + + + + + + diff --git a/saoriview.cpp b/saoriview.cpp index 73a4bd7..e4678e2 100644 --- a/saoriview.cpp +++ b/saoriview.cpp @@ -44,6 +44,8 @@ ui(new Ui::SaoriView) { ui->setupUi(this); + ui->tootWidget->hide(); + m_viewname = view; m_account = account; m_viewList.append(this); @@ -69,6 +71,21 @@ } } }); + ui->tootWidget->setAccountLabel(QString("%1(@%2@%3)").arg( + saoriaccount->accountInfo("display_name").toString(), + saoriaccount->accountInfo("username").toString(), + saoriaccount->instance()->instanceInfo("uri").toString())); + connect(ui->tootWidget,&SaoriTootWidget::postNewStatus,this,[=](const QString data){ + ui->tootWidget->setEnabled(false); + connect(saoriaccount,&SaoriAccount::posted,this,[=](const QString tl,int result){ + if (tl == m_viewname) { + ui->tootWidget->posted(result); + ui->tootWidget->setEnabled(true); + if (result == QNetworkReply::NoError) reload(); + } + }); + saoriaccount->postNewStatus(m_viewname,data); + }); } } diff --git a/saoriview.ui b/saoriview.ui index e8fc732..0ffd198 100644 --- a/saoriview.ui +++ b/saoriview.ui @@ -6,8 +6,8 @@ 0 0 - 327 - 368 + 331 + 465 @@ -42,8 +42,8 @@ 0 0 - 293 - 316 + 297 + 397 @@ -57,6 +57,16 @@ + + + + 0 + 0 + + + + + 0 @@ -153,14 +163,42 @@ :/icons/ionicons/chatbox.svg:/icons/ionicons/chatbox.svg + + true + + + + SaoriTootWidget + QWidget +
saoritootwidget.h
+ 1 +
+
- + + + pushButton_toot + toggled(bool) + tootWidget + setVisible(bool) + + + 306 + 442 + + + 165 + 418 + + + +