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