Moved to separate functions

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2023-06-27 18:09:29 +03:00
parent 9a3931dac6
commit 50dae9d4f3
No known key found for this signature in database
GPG Key ID: 55EF5DA53DB36318

View File

@ -21,10 +21,8 @@
#include <QJsonObject>
namespace ExportToModList {
QString ExportToModList(QList<Mod*> mods, Formats format, OptionalData extraData)
QString toHTML(QList<Mod*> mods, OptionalData extraData)
{
switch (format) {
case HTML: {
QStringList lines;
for (auto mod : mods) {
auto meta = mod->metadata();
@ -48,7 +46,9 @@ QString ExportToModList(QList<Mod*> mods, Formats format, OptionalData extraData
}
return QString("<html><body><ul>\n\t%1\n</ul></body></html>").arg(lines.join("\n\t"));
}
case MARKDOWN: {
QString toMARKDOWN(QList<Mod*> mods, OptionalData extraData)
{
QStringList lines;
for (auto mod : mods) {
auto meta = mod->metadata();
@ -72,7 +72,9 @@ QString ExportToModList(QList<Mod*> mods, Formats format, OptionalData extraData
}
return lines.join("\n");
}
case PLAINTXT: {
QString toPLAINTXT(QList<Mod*> mods, OptionalData extraData)
{
QStringList lines;
for (auto mod : mods) {
auto meta = mod->metadata();
@ -97,7 +99,9 @@ QString ExportToModList(QList<Mod*> mods, Formats format, OptionalData extraData
}
return lines.join("\n");
}
case JSON: {
QString toJSON(QList<Mod*> mods, OptionalData extraData)
{
QJsonArray lines;
for (auto mod : mods) {
auto meta = mod->metadata();
@ -124,7 +128,9 @@ QString ExportToModList(QList<Mod*> mods, Formats format, OptionalData extraData
doc.setArray(lines);
return doc.toJson();
}
case CSV: {
QString toCSV(QList<Mod*> mods, OptionalData extraData)
{
QStringList lines;
for (auto mod : mods) {
QStringList data;
@ -132,24 +138,40 @@ QString ExportToModList(QList<Mod*> mods, Formats format, OptionalData extraData
auto modName = mod->name();
data << modName;
if (extraData & Url) {
auto url = mod->metaurl();
if (!url.isEmpty())
data << url;
}
if (extraData & Url)
data << mod->metaurl();
if (extraData & Version) {
auto ver = mod->version();
if (ver.isEmpty() && meta != nullptr)
ver = meta->version().toString();
if (!ver.isEmpty())
data << ver;
}
if (extraData & Authors && !mod->authors().isEmpty())
data << QString("\"%1\"").arg(mod->authors().join(","));
if (extraData & Authors) {
QString authors;
if (mod->authors().length() == 1)
authors = mod->authors().back();
else if (mod->authors().length() > 1)
authors = QString("\"%1\"").arg(mod->authors().join(","));
data << authors;
}
lines << data.join(",");
}
return lines.join("\n");
}
QString ExportToModList(QList<Mod*> mods, Formats format, OptionalData extraData)
{
switch (format) {
case HTML:
return toHTML(mods, extraData);
case MARKDOWN:
return toMARKDOWN(mods, extraData);
case PLAINTXT:
return toPLAINTXT(mods, extraData);
case JSON:
return toJSON(mods, extraData);
case CSV:
return toCSV(mods, extraData);
default: {
return QString("unknown format:%1").arg(format);
}