diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-11-22 10:23:47 +0100 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-11-22 10:23:47 +0100 |
commit | 240fb8427a89d0aa78da07c8d147a0d57df5bb67 (patch) | |
tree | aa4d46020f89e3d5dfc0b5fb24bc7190acbfe60c /lib/about/aboutplugin.cpp | |
parent | Add link to GPL to About dialog (diff) | |
download | smolbote-240fb8427a89d0aa78da07c8d147a0d57df5bb67.tar.xz |
Add AboutPlugin dialog
Diffstat (limited to 'lib/about/aboutplugin.cpp')
-rw-r--r-- | lib/about/aboutplugin.cpp | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/lib/about/aboutplugin.cpp b/lib/about/aboutplugin.cpp new file mode 100644 index 0000000..7df75fa --- /dev/null +++ b/lib/about/aboutplugin.cpp @@ -0,0 +1,87 @@ +/* + * 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://neueland.iserlohn-fortress.net/gitea/aqua/smolbote + * + * SPDX-License-Identifier: GPL-3.0 + */ + +#include "aboutplugin.h" +#include "ui_aboutplugin.h" +#include <QJsonArray> +#include <QPluginLoader> + +QTreeWidgetItem *createItem(const QString &key, const QJsonValue &json, QTreeWidgetItem *parent) +{ + auto *item = new QTreeWidgetItem(parent, { key, QLatin1Literal("---") }); + + switch(json.type()) { + case QJsonValue::Bool: + item->setText(1, json.toBool() ? QLatin1Literal("true") : QLatin1Literal("false")); + break; + + case QJsonValue::Double: + item->setText(1, QString::number(json.toDouble())); + break; + + case QJsonValue::String: + item->setText(1, json.toString()); + break; + + case QJsonValue::Array: + item->setText(1, QString()); + for(const QJsonValue &v : json.toArray()) { + createItem(QString(), v, item); + } + break; + + case QJsonValue::Object: + item->setText(1, QString()); + for(const QString &k : json.toObject().keys()) { + createItem(k, json.toObject()[k], item); + } + break; + + case QJsonValue::Null: + item->setText(1, QLatin1Literal("null")); + break; + + case QJsonValue::Undefined: + item->setText(1, QLatin1Literal("undefined")); + break; + } + + return item; +} + +AboutPluginDialog::AboutPluginDialog(const QPluginLoader *loader, QWidget *parent) + : QDialog(parent) + , ui(new Ui::AboutPluginDialog) +{ + setAttribute(Qt::WA_DeleteOnClose, true); + ui->setupUi(this); + + auto metaData = loader->metaData()["MetaData"].toObject(); + + this->setWindowTitle(metaData["name"].toString()); + + ui->path->setText(loader->fileName()); + ui->loaded->setChecked(loader->isLoaded()); + + ui->name->setText(metaData[QLatin1Literal("name")].toString()); + ui->author->setText(metaData[QLatin1Literal("author")].toString()); + ui->license->setText(metaData[QLatin1Literal("license")].toString()); + ui->shortcut->setText(metaData[QLatin1Literal("shortcut")].toString()); + + for(const QString &key : loader->metaData().keys()) { + auto *i = createItem(key, loader->metaData()[key], nullptr); + + if(i != nullptr) + ui->details_treeWidget->insertTopLevelItem(0, i); + } +} + +AboutPluginDialog::~AboutPluginDialog() +{ + delete ui; +} |