From e515ca109faa897e84be8a97a1240c59df612dd4 Mon Sep 17 00:00:00 2001 From: ConfuSomu Date: Wed, 5 Jul 2023 15:14:46 +0200 Subject: 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. --- src/activitypub/apbase.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/activitypub/apbase.cpp (limited to 'src/activitypub/apbase.cpp') diff --git a/src/activitypub/apbase.cpp b/src/activitypub/apbase.cpp new file mode 100644 index 0000000..52c995d --- /dev/null +++ b/src/activitypub/apbase.cpp @@ -0,0 +1,21 @@ +#include "apbase.h" +#include +#include +#include + +const QString APBase::get_html_template(const QString& template_name) { + static QHash* templates = new QHash; + + if (not templates->contains(template_name)) { + QFile file("src/templates/"+ template_name +".html"); + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { + templates->insert(template_name, "Error loading status_info template."); + return templates->value(template_name); + } + + templates->insert(template_name, file.readAll()); + qDebug() << "Loaded HTML template:" << template_name << "Total loaded:" << templates->size(); // print size to make sure that everything is loaded by the same function + } + + return templates->value(template_name); +} -- cgit v1.2.3-54-g00ecf