Added filename to the modlist export
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
parent
6804e2ba59
commit
bedb4da869
@ -16,6 +16,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "ExportToModList.h"
|
||||
#include <qcontainerfwd.h>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
@ -42,17 +43,28 @@ QString toHTML(QList<Mod*> mods, OptionalData extraData)
|
||||
}
|
||||
if (extraData & Authors && !mod->authors().isEmpty())
|
||||
line += " by " + mod->authors().join(", ").toHtmlEscaped();
|
||||
if (extraData & FileName)
|
||||
line += QString(" (%1)").arg(mod->fileinfo().fileName().toHtmlEscaped());
|
||||
|
||||
lines.append(QString("<li>%1</li>").arg(line));
|
||||
}
|
||||
return QString("<html><body><ul>\n\t%1\n</ul></body></html>").arg(lines.join("\n\t"));
|
||||
}
|
||||
|
||||
QString toMarkdownEscaped(QString src)
|
||||
{
|
||||
for (auto ch : "\\`*_{}[]<>()#+-.!|")
|
||||
src.replace(ch, QString("\\%1").arg(ch));
|
||||
return src;
|
||||
}
|
||||
|
||||
QString toMarkdown(QList<Mod*> mods, OptionalData extraData)
|
||||
{
|
||||
QStringList lines;
|
||||
|
||||
for (auto mod : mods) {
|
||||
auto meta = mod->metadata();
|
||||
auto modName = mod->name();
|
||||
auto modName = toMarkdownEscaped(mod->name());
|
||||
if (extraData & Url) {
|
||||
auto url = mod->metaurl();
|
||||
if (!url.isEmpty())
|
||||
@ -60,14 +72,16 @@ QString toMarkdown(QList<Mod*> mods, OptionalData extraData)
|
||||
}
|
||||
auto line = modName;
|
||||
if (extraData & Version) {
|
||||
auto ver = mod->version();
|
||||
auto ver = toMarkdownEscaped(mod->version());
|
||||
if (ver.isEmpty() && meta != nullptr)
|
||||
ver = meta->version().toString();
|
||||
ver = toMarkdownEscaped(meta->version().toString());
|
||||
if (!ver.isEmpty())
|
||||
line += QString(" [%1]").arg(ver);
|
||||
}
|
||||
if (extraData & Authors && !mod->authors().isEmpty())
|
||||
line += " by " + mod->authors().join(", ");
|
||||
line += " by " + toMarkdownEscaped(mod->authors().join(", "));
|
||||
if (extraData & FileName)
|
||||
line += QString(" (%1)").arg(toMarkdownEscaped(mod->fileinfo().fileName()));
|
||||
lines << "- " + line;
|
||||
}
|
||||
return lines.join("\n");
|
||||
@ -95,6 +109,8 @@ QString toPlainTXT(QList<Mod*> mods, OptionalData extraData)
|
||||
}
|
||||
if (extraData & Authors && !mod->authors().isEmpty())
|
||||
line += " by " + mod->authors().join(", ");
|
||||
if (extraData & FileName)
|
||||
line += QString(" (%1)").arg(mod->fileinfo().fileName());
|
||||
lines << line;
|
||||
}
|
||||
return lines.join("\n");
|
||||
@ -122,6 +138,8 @@ QString toJSON(QList<Mod*> mods, OptionalData extraData)
|
||||
}
|
||||
if (extraData & Authors && !mod->authors().isEmpty())
|
||||
line["authors"] = QJsonArray::fromStringList(mod->authors());
|
||||
if (extraData & FileName)
|
||||
line["filename"] = mod->fileinfo().fileName();
|
||||
lines << line;
|
||||
}
|
||||
QJsonDocument doc;
|
||||
@ -154,6 +172,8 @@ QString toCSV(QList<Mod*> mods, OptionalData extraData)
|
||||
authors = QString("\"%1\"").arg(mod->authors().join(","));
|
||||
data << authors;
|
||||
}
|
||||
if (extraData & FileName)
|
||||
data << mod->fileinfo().fileName();
|
||||
lines << data.join(",");
|
||||
}
|
||||
return lines.join("\n");
|
||||
@ -189,11 +209,13 @@ QString exportToModList(QList<Mod*> mods, QString lineTemplate)
|
||||
if (ver.isEmpty() && meta != nullptr)
|
||||
ver = meta->version().toString();
|
||||
auto authors = mod->authors().join(", ");
|
||||
auto filename = mod->fileinfo().fileName();
|
||||
lines << QString(lineTemplate)
|
||||
.replace("{name}", modName)
|
||||
.replace("{url}", url)
|
||||
.replace("{version}", ver)
|
||||
.replace("{authors}", authors);
|
||||
.replace("{authors}", authors)
|
||||
.replace("{filename}", filename);
|
||||
}
|
||||
return lines.join("\n");
|
||||
}
|
||||
|
@ -23,11 +23,7 @@
|
||||
namespace ExportToModList {
|
||||
|
||||
enum Formats { HTML, MARKDOWN, PLAINTXT, JSON, CSV, CUSTOM };
|
||||
enum OptionalData {
|
||||
Authors = 1 << 0,
|
||||
Url = 1 << 1,
|
||||
Version = 1 << 2,
|
||||
};
|
||||
enum OptionalData { Authors = 1 << 0, Url = 1 << 1, Version = 1 << 2, FileName = 1 << 3 };
|
||||
QString exportToModList(QList<Mod*> mods, Formats format, OptionalData extraData);
|
||||
QString exportToModList(QList<Mod*> mods, QString lineTemplate);
|
||||
} // namespace ExportToModList
|
||||
|
@ -49,14 +49,15 @@ ExportToModListDialog::ExportToModListDialog(QString name, QList<Mod*> mods, QWi
|
||||
connect(ui->authorsCheckBox, &QCheckBox::stateChanged, this, &ExportToModListDialog::trigger);
|
||||
connect(ui->versionCheckBox, &QCheckBox::stateChanged, this, &ExportToModListDialog::trigger);
|
||||
connect(ui->urlCheckBox, &QCheckBox::stateChanged, this, &ExportToModListDialog::trigger);
|
||||
connect(ui->filenameCheckBox, &QCheckBox::stateChanged, this, &ExportToModListDialog::trigger);
|
||||
connect(ui->authorsButton, &QPushButton::clicked, this, [this](bool) { addExtra(ExportToModList::Authors); });
|
||||
connect(ui->versionButton, &QPushButton::clicked, this, [this](bool) { addExtra(ExportToModList::Version); });
|
||||
connect(ui->urlButton, &QPushButton::clicked, this, [this](bool) { addExtra(ExportToModList::Url); });
|
||||
connect(ui->filenameButton, &QPushButton::clicked, this, [this](bool) { addExtra(ExportToModList::FileName); });
|
||||
connect(ui->templateText, &QTextEdit::textChanged, this, [this] {
|
||||
if (ui->templateText->toPlainText() != exampleLines[m_format])
|
||||
ui->formatComboBox->setCurrentIndex(5);
|
||||
else
|
||||
triggerImp();
|
||||
triggerImp();
|
||||
});
|
||||
connect(ui->copyButton, &QPushButton::clicked, this, [this](bool) {
|
||||
this->ui->finalText->selectAll();
|
||||
@ -127,6 +128,8 @@ void ExportToModListDialog::triggerImp()
|
||||
opt |= ExportToModList::Version;
|
||||
if (ui->urlCheckBox->isChecked())
|
||||
opt |= ExportToModList::Url;
|
||||
if (ui->filenameCheckBox->isChecked())
|
||||
opt |= ExportToModList::FileName;
|
||||
auto txt = ExportToModList::exportToModList(m_mods, m_format, static_cast<ExportToModList::OptionalData>(opt));
|
||||
ui->finalText->setPlainText(txt);
|
||||
switch (m_format) {
|
||||
@ -199,6 +202,9 @@ void ExportToModListDialog::addExtra(ExportToModList::OptionalData option)
|
||||
case ExportToModList::Version:
|
||||
ui->templateText->insertPlainText("{version}");
|
||||
break;
|
||||
case ExportToModList::FileName:
|
||||
ui->templateText->insertPlainText("{filename}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
void ExportToModListDialog::enableCustom(bool enabled)
|
||||
@ -211,4 +217,7 @@ void ExportToModListDialog::enableCustom(bool enabled)
|
||||
|
||||
ui->urlCheckBox->setHidden(enabled);
|
||||
ui->urlButton->setHidden(!enabled);
|
||||
|
||||
ui->filenameCheckBox->setHidden(enabled);
|
||||
ui->filenameButton->setHidden(!enabled);
|
||||
}
|
||||
|
@ -117,6 +117,13 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="filenameCheckBox">
|
||||
<property name="text">
|
||||
<string>Filename</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="versionButton">
|
||||
<property name="text">
|
||||
@ -138,6 +145,13 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="filenameButton">
|
||||
<property name="text">
|
||||
<string>Filename</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
Loading…
Reference in New Issue
Block a user