diff options
author | ConfuSomu | 2023-07-05 15:14:46 +0200 |
---|---|---|
committer | ConfuSomu | 2023-07-05 15:14:46 +0200 |
commit | e515ca109faa897e84be8a97a1240c59df612dd4 (patch) | |
tree | 2a5e0593bb4387449a9a60fb2aefcc74779b5c67 /src/activitypub/apattachment.cpp | |
parent | 0dfab2456b2dcd33f1879ac7d5606dd65cdb8e40 (diff) | |
download | ActorViewer-e515ca109faa897e84be8a97a1240c59df612dd4.tar ActorViewer-e515ca109faa897e84be8a97a1240c59df612dd4.tar.gz ActorViewer-e515ca109faa897e84be8a97a1240c59df612dd4.zip |
Implement a small library of ActivityPub objects
These objects allow, and will allow us, to move HTML rendering out of
the archive parser and into separate classes. Each of the derived
classes specialise HTML rendering for their specific requirements.
Furthermore, these ActivityPub objects will be able to be expanded upon
and have support to be written to disk, in a database, for instance.
Separating ActivityPub object retrieving from rendering allows us to
implement other retrieving sources and methods, such as downloading
posts from a configured remote instance.
Diffstat (limited to 'src/activitypub/apattachment.cpp')
-rw-r--r-- | src/activitypub/apattachment.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/activitypub/apattachment.cpp b/src/activitypub/apattachment.cpp new file mode 100644 index 0000000..0589291 --- /dev/null +++ b/src/activitypub/apattachment.cpp @@ -0,0 +1,45 @@ +#include "apattachment.h" +#include <QFileInfo> + +APAttachment::APAttachment() {} + +APAttachment::APAttachment(APAttachmentFields fields) { + path_url = fields.path; + type = fields.media_type; + description = fields.name; +} + +QString APAttachment::get_html_render(HtmlRenderDetails info) { + QString html(get_html_template("apattachment")); + + if (not path_url.isEmpty()) { + html.replace("{{path}}", path_url); + html.replace("{{filename}}", QFileInfo(path_url).fileName()); // FIXME: this is maybe ugly? + } + + if (type.startsWith("image/")) + // dynamically resize image based on the display widget size to avoid horizontal scrolling + html.replace("{{img-width}}", QString::number((float)info.text_zone_width - (float)info.text_zone_width*0.15)); // finally after passing this for so long i finally use it + else + html.replace("{{img-width}}", "0"); + + html.replace("{{alt-text}}", description); + + return html; +} + +QString APAttachmentList::get_html_render(HtmlRenderDetails render_info) { + QString html; + + int i = 1; + for (APAttachment attachment : *this) { + QString item_html(get_html_template("apattachmentlist_item")); + item_html.replace("{{id}}", QString::number(i)); + item_html.replace("{{attachment}}", attachment.get_html_render(render_info)); + + html.append(item_html); + ++i; + } + + return html; +} |