aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/archive_parser.cpp72
-rw-r--r--src/archive_parser.h1
-rw-r--r--src/list_item.cpp9
-rw-r--r--src/list_item.h3
-rw-r--r--src/mainwindow.cpp9
-rw-r--r--src/mainwindow.h3
-rw-r--r--src/mainwindow.ui14
-rw-r--r--src/templates/status_info.html19
8 files changed, 127 insertions, 3 deletions
diff --git a/src/archive_parser.cpp b/src/archive_parser.cpp
index 603ffa7..d3b9197 100644
--- a/src/archive_parser.cpp
+++ b/src/archive_parser.cpp
@@ -142,3 +142,75 @@ void Archive::update_status_list(ViewStatusTypes allowed_types, QListWidget *par
++i;
}
}
+
+QString* get_html_status_info_template() {
+ static QString* html = new QString();
+
+ if (html->isNull()) {
+ QFile file("src/templates/status_info.html");
+ if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
+ html->append("<i>Error loading status_info template.</i>");
+ return html;
+ }
+
+ html->append(file.readAll());
+ }
+
+ return html;
+}
+
+QString get_html_status_object_as_list(QJsonObject obj, QString element_name) {
+ QString text;
+
+ if (obj.contains(element_name)) {
+ QJsonArray to = obj.value(element_name).toArray();
+
+ for (auto collection : to)
+ text.append(collection.toString() + ", ");
+ }
+
+ if (text.isEmpty())
+ text = "<em>(empty)</em>";
+ else
+ text.chop(2); // remove leftover ", "
+
+ return text;
+}
+
+// status_index is assumed to be a valid index
+QString Archive::get_html_status_info(int status_index) {
+ QString info_text(*get_html_status_info_template());
+ QJsonObject obj = outbox_items->at(status_index).toObject();
+
+ if (obj.contains("type") and obj["type"].isString())
+ info_text.replace("{{type}}", obj["type"].toString());
+
+ if (obj.contains("published") and obj["published"].isString())
+ info_text.replace("{{published}}", obj["published"].toString());
+
+ if (obj.contains("id") and obj["id"].isString())
+ info_text.replace("{{url-id}}", obj["id"].toString());
+
+ info_text.replace("{{to}}", get_html_status_object_as_list(obj, "to"));
+ info_text.replace("{{cc}}", get_html_status_object_as_list(obj, "cc"));
+
+ if (obj["object"].isObject()) {
+ QJsonObject activity = obj["object"].toObject();
+
+ if (activity.contains("summary")) {
+ QString summary_text = activity["summary"].toString();
+ if (summary_text.isEmpty())
+ summary_text = "<em>(empty)</em>";
+ info_text.replace("{{summary}}", summary_text);
+ }
+
+ if (activity.contains("url") and activity["url"].isString())
+ info_text.replace("{{url-status}}", activity["url"].toString());
+
+ if (activity["content"].isString()) {
+ info_text.replace("{{content}}", activity["content"].toString());
+ }
+ }
+
+ return info_text;
+}
diff --git a/src/archive_parser.h b/src/archive_parser.h
index 73adb2c..98fd2b8 100644
--- a/src/archive_parser.h
+++ b/src/archive_parser.h
@@ -30,6 +30,7 @@ public:
InitError init();
void update_status_list(ViewStatusTypes allowed_types, QListWidget *parent);
+ QString get_html_status_info(int status_index);
private:
QString outbox_filename;
ArchiveType archive_type;
diff --git a/src/list_item.cpp b/src/list_item.cpp
index ce7c86e..b84f147 100644
--- a/src/list_item.cpp
+++ b/src/list_item.cpp
@@ -13,8 +13,11 @@ QIcon* choose_icon(StatusType status_type) {
}
ListItem::ListItem(const QString &text, StatusType status_type, QListWidget *parent, int index) :
- QListWidgetItem(*choose_icon(status_type), text, parent, ArchiveListItemType), status_index(index)
+ status_index(index)
{
+ setText(text);
+ setIcon(*choose_icon(status_type));
+ parent->addItem(this);
#ifndef NDEBUG
QString tool_tip;
switch (status_type) {
@@ -28,3 +31,7 @@ ListItem::ListItem(const QString &text, StatusType status_type, QListWidget *par
setToolTip(tool_tip);
#endif
}
+
+int ListItem::get_status_index() {
+ return status_index;
+}
diff --git a/src/list_item.h b/src/list_item.h
index e2b3c3f..ce5b6b2 100644
--- a/src/list_item.h
+++ b/src/list_item.h
@@ -3,13 +3,14 @@
#include <QListWidgetItem>
#include "types.h"
-class ListItem : QListWidgetItem {
+class ListItem : public QListWidgetItem {
public:
enum ItemType {
ArchiveListItemType = QListWidgetItem::UserType
};
ListItem(const QString &text, StatusType status_type, QListWidget *parent = nullptr, int index = 0);
+ int get_status_index();
private:
int status_index;
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 0b77012..f8440c8 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -1,6 +1,7 @@
#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include "src/archive_parser.h"
+#include "src/list_item.h"
#include <QFileDialog>
#include <QMessageBox>
@@ -68,6 +69,14 @@ void MainWindow::on_actionAbout_triggered(bool checked) {
QMessageBox::information(this, "title", "text");
}
+void MainWindow::on_listWidget_itemActivated(QListWidgetItem *item) {
+ ListItem* casted = dynamic_cast<ListItem*>(item);
+ if (casted != nullptr) { // this is always a nullptr, but it should work?? https://cplusplus.com/forum/beginner/78766/
+ QString status_info = data_archive->get_html_status_info(casted->get_status_index());
+ ui->statusInfoText->setHtml(status_info);
+ }
+}
+
void MainWindow::relist_statuses() {
if (data_archive) {
ui->listWidget->clear();
diff --git a/src/mainwindow.h b/src/mainwindow.h
index 881aa2d..ce72397 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -1,6 +1,7 @@
#pragma once
#include <QMainWindow>
+#include <QListWidgetItem>
#include <qobjectdefs.h>
#include "archive_parser.h"
@@ -32,6 +33,8 @@ private slots:
void on_menuView_aboutToHide();
+ void on_listWidget_itemActivated(QListWidgetItem *item);
+
private:
void reset_view_filters();
void relist_statuses();
diff --git a/src/mainwindow.ui b/src/mainwindow.ui
index a89812b..c0ca438 100644
--- a/src/mainwindow.ui
+++ b/src/mainwindow.ui
@@ -19,7 +19,16 @@
<widget class="QListWidget" name="listWidget"/>
</item>
<item>
- <widget class="QTextBrowser" name="statusInfoText">
+ <widget class="QTextEdit" name="statusInfoText">
+ <property name="cursor" stdset="0">
+ <cursorShape>IBeamCursor</cursorShape>
+ </property>
+ <property name="undoRedoEnabled">
+ <bool>false</bool>
+ </property>
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
<property name="html">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
@@ -27,6 +36,9 @@ p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Noto Sans'; font-size:10pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p align=&quot;center&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-style:italic;&quot;&gt;Select Status to display from list.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
+ <property name="textInteractionFlags">
+ <set>Qt::TextBrowserInteraction</set>
+ </property>
</widget>
</item>
</layout>
diff --git a/src/templates/status_info.html b/src/templates/status_info.html
new file mode 100644
index 0000000..a081463
--- /dev/null
+++ b/src/templates/status_info.html
@@ -0,0 +1,19 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
+<html lang="en">
+ <head>
+ <meta charset="utf-8">
+ <title>Status info</title>
+ </head>
+ <body>
+ <h1 id="type">{{type}}</h1>
+ <ul>
+ <li id="publication-date"><b>Published:</b> {{published}}</li>
+ <li id="to"><b>To:</b> {{to}}</li>
+ <li id="cc"><b>CC:</b> {{cc}}</li>
+ <li>URL to <a href="{{url-status}}">Status</a>, <a href="{{url-id}}">JSON-LD Object</a></li>
+ </ul>
+
+ <div><tt id="content-warning"><b>CW:</b> {{summary}}</tt></div>
+ <div id="content">{{content}}</div>
+ </body>
+</html>