diff --git a/saoriaddaccountdialog.cpp b/saoriaddaccountdialog.cpp index 61ea2af..7038d9f 100644 --- a/saoriaddaccountdialog.cpp +++ b/saoriaddaccountdialog.cpp @@ -88,7 +88,7 @@ QEventLoop event; QUrlQuery params; QNetworkRequest request; - QString instance = m_instance->instanceInfo("uri"); + QString instance = m_instance->instanceInfo("uri").toString(); request.setRawHeader("Authorization","Bearer " + token.toLatin1()); request.setUrl(QUrl(m_instance->instance().url() + SAORI_MASTODON_APIPATH_ACCOUNTS + "/verify_credentials")); @@ -115,7 +115,7 @@ if (SaoriApplication::findInstance(QUrl(ui->instanceUrl_comboBox->currentText())) == nullptr) { auto instance = new Saoridon(QUrl(ui->instanceUrl_comboBox->currentText()),this); connect(instance,&Saoridon::instanceInfomationChanged,this,[=](){ - if (!instance->instanceInfo("uri").isEmpty()) { + if (!instance->instanceInfo("uri").toString().isEmpty()) { instance->clientRedistration(); if (!instance->clientSecret().isEmpty()) { instance->setParent(SaoriApplication::saori()); diff --git a/saoridon.cpp b/saoridon.cpp index 99e356b..dd99481 100644 --- a/saoridon.cpp +++ b/saoridon.cpp @@ -30,7 +30,8 @@ #include #include #include -#include + +#include #include #include #include @@ -149,12 +150,7 @@ auto *reply = SaoriApplication::saori()->manager->get(request); connect(reply,&QNetworkReply::finished,[=](){ if (reply->error() == QNetworkReply::NoError) { - QJsonObject json = QJsonDocument::fromJson(reply->readAll()).object(); - QMap info; - for (auto it = json.begin();it != json.end();it ++) { - info[it.key()] = it.value().toString(); - } - m_instanceInfo = info; + m_instanceInfo = QJsonDocument::fromJson(reply->readAll()).object(); emit instanceInfomationChanged(); } reply->deleteLater(); @@ -168,7 +164,7 @@ return; } -const QString Saoridon::instanceInfo(const QString key) +const QJsonValue Saoridon::instanceInfo(const QString key) { return m_instanceInfo[key]; } diff --git a/saoridon.h b/saoridon.h index 7a5a746..428da85 100644 --- a/saoridon.h +++ b/saoridon.h @@ -30,6 +30,7 @@ #include #include #include +#include class Saoridon : public QObject { @@ -49,7 +50,7 @@ bool clientRedistration(); const QUrl getAuthorizedUrl(); const QString getAccessToken(const QString code); - const QString instanceInfo(const QString key); + const QJsonValue instanceInfo(const QString key); const QUrl timelineUrl(const QString timeline); static const QUrl addQuery(const QUrl url,const QString key,const QString value); static const QUrl addQuery(const QUrl url,const QUrlQuery query); @@ -61,7 +62,7 @@ QUrl m_instance; QString m_clientId; QString m_clientSecret; - QMap m_instanceInfo; + QJsonObject m_instanceInfo; QMap m_timelineMap; signals: diff --git a/saoriview.cpp b/saoriview.cpp index 3e981fc..bfe1d0e 100644 --- a/saoriview.cpp +++ b/saoriview.cpp @@ -49,6 +49,13 @@ m_viewList.append(this); m_maxid = 0; + if (m_viewname == "instance") { + m_entries.append(new SaoriViewEntry(0,ui->scrollAreaWidgetContents)); + m_entries.at(0)->setContent(instanceInfoParser(account)); + ui->scrollAreaWidgetContents->layout()->addWidget(m_entries.at(0)); + return; + } + auto saoriaccount = SaoriApplication::saori()->findAccount(m_account); if (saoriaccount) { connect(saoriaccount,&SaoriAccount::apiData,this,&SaoriView::recived); @@ -93,6 +100,26 @@ saoriaccount->getTimelineData(m_viewname,query); } +const QString SaoriView::instanceInfoParser(const QString instance) +{ + auto i = SaoriApplication::findInstance(QUrl(instance)); + if (!i) return QString(); + QString result; + result = (tr("
%1
" + "
%2
" + "
%3
" + "
email : %4
" + "
%5
" + "
version : %6
" + ).arg(i->instanceInfo("title").toString(), + i->instanceInfo("uri").toString(), + i->instanceInfo("description").toString(), + i->instanceInfo("email").toString(), + accountParser(i->instanceInfo("contact_account").toObject()), + i->instanceInfo("version").toString())); + return result; +} + const QString SaoriView::statusParser(const QJsonObject json) { QString result; diff --git a/saoriview.h b/saoriview.h index f14cc7d..3af74ce 100644 --- a/saoriview.h +++ b/saoriview.h @@ -56,6 +56,7 @@ protected: void reload(); + const QString instanceInfoParser(const QString instance); const QString statusParser(const QJsonObject json); const QString accountParser(const QJsonObject json); const QString mediaParser(const QJsonObject json); diff --git a/saoriwindow.cpp b/saoriwindow.cpp index 2f572ee..ab9c2a4 100644 --- a/saoriwindow.cpp +++ b/saoriwindow.cpp @@ -51,7 +51,7 @@ // trick for translation. QStringList trtl; QString tlText,icon; - trtl << "home" << "local" << "public" << "notifications"; + trtl << "home" << "local" << "public" << "notifications" << "instance"; switch (trtl.indexOf(timeline)) { case 0: tlText = tr("home"); @@ -69,6 +69,10 @@ tlText = tr("notifications"); icon = ":/icons/ionicons/alert.svg"; break; + case 4: + tlText = tr("instance"); + icon = ""; + break; default: tlText = timeline; break; @@ -147,7 +151,7 @@ for (int i = 0;i < SaoriApplication::getInstanceList()->count();i ++) { auto *item = new QTreeWidgetItem(instanceItem,QStringList() << SaoriApplication::getInstanceList()->at(i)->instance().toString()); instanceItem->addChild(item); - item->addChild(new QTreeWidgetItem(item,QStringList() << tr("Infomation"))); + //item->addChild(new QTreeWidgetItem(item,QStringList() << tr("Infomation"))); } } @@ -156,6 +160,11 @@ auto account = SaoriApplication::findAccount(item->text(1)); if (account) { openView(QStringList() << item->text(1) << item->text(2)); + return; + } + auto instance = SaoriApplication::findInstance(QUrl(item->text(0))); + if (instance) { + openView(QStringList() << instance->instance().toString() << "instance"); } }