aboutsummaryrefslogtreecommitdiff
path: root/staging/smolblok/smolblok.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'staging/smolblok/smolblok.cpp')
-rw-r--r--staging/smolblok/smolblok.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/staging/smolblok/smolblok.cpp b/staging/smolblok/smolblok.cpp
new file mode 100644
index 0000000..6095082
--- /dev/null
+++ b/staging/smolblok/smolblok.cpp
@@ -0,0 +1,58 @@
+/*
+ * This file is part of smolbote. It's copyrighted by the contributors recorded
+ * in the version control history of the file, available from its original
+ * location: https://library.iserlohn-fortress.net/aqua/smolbote.git
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#include "smolblok.hpp"
+#include <QFile>
+#include <QSettings>
+
+bool smolblok::registerFormatPlugin(const QString &format, const QString &filename)
+{
+ if(format.isEmpty() || filename.isEmpty()) {
+ return false;
+ }
+
+ auto *plugin = new QPluginLoader(filename);
+ if(!plugin->load()) {
+ delete plugin;
+ return false;
+ }
+
+ auto *instance = qobject_cast<FilterPlugin *>(plugin->instance());
+ if(instance == nullptr) {
+ delete plugin;
+ return false;
+ }
+
+ m_formats[format] = PluginInfo{ plugin, instance };
+ return false;
+}
+
+bool smolblok::addSubscriptions(const QString &filename)
+{
+ if(filename.isEmpty()) {
+ return false;
+ }
+
+ QSettings listconf(filename, QSettings::IniFormat);
+
+ for(auto &group : listconf.childGroups()) {
+ listconf.beginGroup(group);
+ const auto *loader = m_formats.value(listconf.value("Format").toString()).instance;
+ if(loader != nullptr) {
+ QFile f(listconf.value("File").toString());
+ if(!f.exists() && !loader->update(&f, listconf.value("Href").toUrl())) {
+ continue;
+ }
+
+ m_subscriptions.addFilterList(loader->load(&f));
+ }
+ listconf.endGroup();
+ }
+ return false;
+}
+