2017-07-13 10:26:03 +02:00
|
|
|
/*
|
|
|
|
* cmodlistview_moc.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
2013-08-22 17:22:49 +03:00
|
|
|
#include "StdInc.h"
|
2013-08-24 23:11:51 +03:00
|
|
|
#include "cmodlistview_moc.h"
|
|
|
|
#include "ui_cmodlistview_moc.h"
|
2014-03-29 15:46:41 +03:00
|
|
|
#include "imageviewer_moc.h"
|
2019-07-30 09:28:42 +02:00
|
|
|
#include "../mainwindow_moc.h"
|
2013-08-22 17:22:49 +03:00
|
|
|
|
|
|
|
#include <QJsonArray>
|
|
|
|
#include <QCryptographicHash>
|
2022-05-28 15:32:20 +02:00
|
|
|
#include <QRegularExpression>
|
2013-08-22 17:22:49 +03:00
|
|
|
|
2024-11-12 22:00:21 +02:00
|
|
|
#include "modstatemodel.h"
|
|
|
|
#include "modstateitemmodel_moc.h"
|
|
|
|
#include "modstatecontroller.h"
|
2013-08-24 23:11:51 +03:00
|
|
|
#include "cdownloadmanager_moc.h"
|
2024-08-30 21:17:18 +02:00
|
|
|
#include "chroniclesextractor.h"
|
2024-04-21 01:32:31 +02:00
|
|
|
#include "../settingsView/csettingsview_moc.h"
|
2024-10-07 07:47:00 +02:00
|
|
|
#include "../vcmiqt/launcherdirs.h"
|
|
|
|
#include "../vcmiqt/jsonutils.h"
|
2024-04-21 16:56:39 +02:00
|
|
|
#include "../helper.h"
|
2013-08-22 17:22:49 +03:00
|
|
|
|
2024-04-21 01:32:31 +02:00
|
|
|
#include "../../lib/VCMIDirs.h"
|
2013-09-02 20:26:52 +03:00
|
|
|
#include "../../lib/CConfigHandler.h"
|
2024-07-20 14:55:17 +02:00
|
|
|
#include "../../lib/texts/Languages.h"
|
2023-09-01 02:12:41 +02:00
|
|
|
#include "../../lib/modding/CModVersion.h"
|
2024-08-31 00:44:20 +02:00
|
|
|
#include "../../lib/filesystem/Filesystem.h"
|
2024-11-20 22:44:24 +02:00
|
|
|
#include "../../lib/texts/CGeneralTextHandler.h"
|
2013-08-22 17:22:49 +03:00
|
|
|
|
2024-08-31 23:44:36 +02:00
|
|
|
#include <future>
|
|
|
|
|
2013-08-22 17:22:49 +03:00
|
|
|
void CModListView::setupModModel()
|
|
|
|
{
|
2024-11-13 19:25:59 +02:00
|
|
|
static const QString repositoryCachePath = CLauncherDirs::downloadsPath() + "/repositoryCache.json";
|
|
|
|
const auto &cachedRepositoryData = JsonUtils::jsonFromFile(repositoryCachePath);
|
|
|
|
|
2024-11-12 22:00:21 +02:00
|
|
|
modStateModel = std::make_shared<ModStateModel>();
|
2024-11-13 19:25:59 +02:00
|
|
|
if (!cachedRepositoryData.isNull())
|
|
|
|
modStateModel->appendRepositories(cachedRepositoryData);
|
|
|
|
|
|
|
|
modModel = new ModStateItemModel(modStateModel, this);
|
2024-11-12 22:00:21 +02:00
|
|
|
manager = std::make_unique<ModStateController>(modStateModel);
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
|
2022-12-25 13:19:16 +02:00
|
|
|
void CModListView::changeEvent(QEvent *event)
|
|
|
|
{
|
2022-12-29 16:37:38 +02:00
|
|
|
if(event->type() == QEvent::LanguageChange)
|
2022-12-25 13:19:16 +02:00
|
|
|
{
|
|
|
|
ui->retranslateUi(this);
|
|
|
|
modModel->reloadRepositories();
|
|
|
|
}
|
2022-12-28 17:58:39 +02:00
|
|
|
QWidget::changeEvent(event);
|
2022-12-25 13:19:16 +02:00
|
|
|
}
|
|
|
|
|
2013-08-22 17:22:49 +03:00
|
|
|
void CModListView::setupFilterModel()
|
|
|
|
{
|
2018-04-28 10:56:01 +02:00
|
|
|
filterModel = new CModFilterModel(modModel, this);
|
2013-08-22 17:22:49 +03:00
|
|
|
|
|
|
|
filterModel->setFilterKeyColumn(-1); // filter across all columns
|
|
|
|
filterModel->setSortCaseSensitivity(Qt::CaseInsensitive); // to make it more user-friendly
|
2014-03-20 20:06:25 +03:00
|
|
|
filterModel->setDynamicSortFilter(true);
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CModListView::setupModsView()
|
|
|
|
{
|
|
|
|
ui->allModsView->setModel(filterModel);
|
|
|
|
// input data is not sorted - sort it before display
|
|
|
|
ui->allModsView->sortByColumn(ModFields::TYPE, Qt::AscendingOrder);
|
|
|
|
|
2014-03-20 20:06:25 +03:00
|
|
|
ui->allModsView->header()->setSectionResizeMode(ModFields::STATUS_ENABLED, QHeaderView::Fixed);
|
2018-04-13 07:34:58 +02:00
|
|
|
ui->allModsView->header()->setSectionResizeMode(ModFields::STATUS_UPDATE, QHeaderView::Fixed);
|
2014-03-20 20:06:25 +03:00
|
|
|
|
2019-07-30 09:28:42 +02:00
|
|
|
QSettings s(Ui::teamName, Ui::appName);
|
|
|
|
auto state = s.value("AllModsView/State").toByteArray();
|
2019-07-30 11:00:44 +02:00
|
|
|
if(!state.isNull()) //read last saved settings
|
2019-07-30 09:28:42 +02:00
|
|
|
{
|
|
|
|
ui->allModsView->header()->restoreState(state);
|
|
|
|
}
|
|
|
|
else //default //TODO: default high-DPI scaling
|
|
|
|
{
|
2024-06-08 18:00:45 +02:00
|
|
|
ui->allModsView->setColumnWidth(ModFields::NAME, 220);
|
2019-07-30 09:28:42 +02:00
|
|
|
ui->allModsView->setColumnWidth(ModFields::TYPE, 75);
|
|
|
|
}
|
2023-03-27 19:11:41 +02:00
|
|
|
|
|
|
|
ui->allModsView->resizeColumnToContents(ModFields::STATUS_ENABLED);
|
|
|
|
ui->allModsView->resizeColumnToContents(ModFields::STATUS_UPDATE);
|
2019-07-30 09:28:42 +02:00
|
|
|
|
2014-03-20 20:06:25 +03:00
|
|
|
ui->allModsView->setUniformRowHeights(true);
|
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
connect(ui->allModsView->selectionModel(), SIGNAL(currentRowChanged(const QModelIndex&,const QModelIndex&)),
|
|
|
|
this, SLOT(modSelected(const QModelIndex&,const QModelIndex&)));
|
2013-08-22 17:22:49 +03:00
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
connect(filterModel, SIGNAL(modelReset()),
|
|
|
|
this, SLOT(modelReset()));
|
2013-08-24 23:11:51 +03:00
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
connect(modModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
|
|
|
|
this, SLOT(dataChanged(QModelIndex,QModelIndex)));
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
CModListView::CModListView(QWidget * parent)
|
2023-03-12 18:33:29 +02:00
|
|
|
: QWidget(parent)
|
|
|
|
, ui(new Ui::CModListView)
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
2024-03-02 23:24:00 +02:00
|
|
|
ui->uninstallButton->setIcon(QIcon{":/icons/mod-delete.png"});
|
|
|
|
ui->enableButton->setIcon(QIcon{":/icons/mod-enabled.png"});
|
|
|
|
ui->disableButton->setIcon(QIcon{":/icons/mod-disabled.png"});
|
|
|
|
ui->updateButton->setIcon(QIcon{":/icons/mod-update.png"});
|
|
|
|
ui->installButton->setIcon(QIcon{":/icons/mod-download.png"});
|
|
|
|
|
2024-07-16 16:13:58 +02:00
|
|
|
ui->splitter->setStyleSheet("QSplitter::handle {background: palette('window');}");
|
|
|
|
|
2024-12-04 13:16:31 +02:00
|
|
|
disableModInfo();
|
2013-08-22 17:22:49 +03:00
|
|
|
setupModModel();
|
|
|
|
setupFilterModel();
|
|
|
|
setupModsView();
|
|
|
|
|
|
|
|
ui->progressWidget->setVisible(false);
|
|
|
|
dlManager = nullptr;
|
2023-03-11 00:57:55 +02:00
|
|
|
|
2024-12-04 13:17:07 +02:00
|
|
|
modModel->reloadRepositories();
|
2018-04-13 07:34:58 +02:00
|
|
|
if(settings["launcher"]["autoCheckRepositories"].Bool())
|
2014-11-03 17:47:37 +02:00
|
|
|
loadRepositories();
|
2024-05-01 20:05:01 +02:00
|
|
|
|
|
|
|
#ifdef VCMI_MOBILE
|
2022-11-22 01:36:27 +02:00
|
|
|
for(auto * scrollWidget : {
|
|
|
|
(QAbstractItemView*)ui->allModsView,
|
|
|
|
(QAbstractItemView*)ui->screenshotsList})
|
|
|
|
{
|
2024-05-01 20:05:01 +02:00
|
|
|
Helper::enableScrollBySwiping(scrollWidget);
|
|
|
|
|
2022-11-22 01:36:27 +02:00
|
|
|
scrollWidget->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
|
|
|
|
scrollWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
}
|
|
|
|
#endif
|
2013-08-24 23:11:51 +03:00
|
|
|
}
|
2013-08-22 17:22:49 +03:00
|
|
|
|
2024-12-04 17:19:02 +02:00
|
|
|
void CModListView::reload()
|
|
|
|
{
|
|
|
|
modStateModel->reloadLocalState();
|
|
|
|
modModel->reloadRepositories();
|
|
|
|
}
|
|
|
|
|
2013-08-24 23:11:51 +03:00
|
|
|
void CModListView::loadRepositories()
|
|
|
|
{
|
2023-06-29 14:41:12 +02:00
|
|
|
QStringList repositories;
|
|
|
|
|
|
|
|
if (settings["launcher"]["defaultRepositoryEnabled"].Bool())
|
|
|
|
repositories.push_back(QString::fromStdString(settings["launcher"]["defaultRepositoryURL"].String()));
|
|
|
|
|
|
|
|
if (settings["launcher"]["extraRepositoryEnabled"].Bool())
|
|
|
|
repositories.push_back(QString::fromStdString(settings["launcher"]["extraRepositoryURL"].String()));
|
|
|
|
|
2024-11-13 22:27:51 +02:00
|
|
|
for(const auto & entry : repositories)
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
2023-06-29 14:41:12 +02:00
|
|
|
if (entry.isEmpty())
|
|
|
|
continue;
|
2013-08-22 17:22:49 +03:00
|
|
|
|
|
|
|
// URL must be encoded to something else to get rid of symbols illegal in file names
|
2023-06-29 14:41:12 +02:00
|
|
|
auto hashed = QCryptographicHash::hash(entry.toUtf8(), QCryptographicHash::Md5);
|
2013-08-22 17:22:49 +03:00
|
|
|
auto hashedStr = QString::fromUtf8(hashed.toHex());
|
|
|
|
|
2024-05-01 12:46:39 +02:00
|
|
|
downloadFile(hashedStr + ".json", entry, tr("mods repository index"));
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CModListView::~CModListView()
|
|
|
|
{
|
2019-07-30 09:28:42 +02:00
|
|
|
QSettings s(Ui::teamName, Ui::appName);
|
|
|
|
s.setValue("AllModsView/State", ui->allModsView->header()->saveState());
|
|
|
|
|
2013-08-22 17:22:49 +03:00
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
static QString replaceIfNotEmpty(QVariant value, QString pattern)
|
|
|
|
{
|
2018-04-13 07:34:58 +02:00
|
|
|
if(value.canConvert<QString>())
|
2024-11-14 18:55:15 +02:00
|
|
|
{
|
|
|
|
if (value.toString().isEmpty())
|
|
|
|
return "";
|
|
|
|
else
|
|
|
|
return pattern.arg(value.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
if(value.canConvert<QStringList>())
|
|
|
|
{
|
|
|
|
if (value.toStringList().isEmpty())
|
|
|
|
return "";
|
|
|
|
else
|
|
|
|
return pattern.arg(value.toStringList().join(", "));
|
|
|
|
}
|
2013-08-22 17:22:49 +03:00
|
|
|
|
|
|
|
// all valid types of data should have been filtered by code above
|
|
|
|
assert(!value.isValid());
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
static QString replaceIfNotEmpty(QStringList value, QString pattern)
|
|
|
|
{
|
2018-04-13 07:34:58 +02:00
|
|
|
if(!value.empty())
|
2013-08-22 17:22:49 +03:00
|
|
|
return pattern.arg(value.join(", "));
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2024-11-13 22:27:51 +02:00
|
|
|
QString CModListView::genChangelogText(const ModState & mod)
|
2014-03-23 15:08:01 +03:00
|
|
|
{
|
|
|
|
QString headerTemplate = "<p><span style=\" font-weight:600;\">%1: </span></p>";
|
|
|
|
QString entryBegin = "<p align=\"justify\"><ul>";
|
|
|
|
QString entryEnd = "</ul></p>";
|
|
|
|
QString entryLine = "<li>%1</li>";
|
|
|
|
//QString versionSeparator = "<hr/>";
|
|
|
|
|
|
|
|
QString result;
|
|
|
|
|
2024-11-12 22:00:21 +02:00
|
|
|
QMap<QString, QStringList> changelog = mod.getChangelog();
|
2014-03-23 15:08:01 +03:00
|
|
|
QList<QString> versions = changelog.keys();
|
|
|
|
|
|
|
|
std::sort(versions.begin(), versions.end(), [](QString lesser, QString greater)
|
|
|
|
{
|
2023-09-01 02:12:41 +02:00
|
|
|
return CModVersion::fromString(lesser.toStdString()) < CModVersion::fromString(greater.toStdString());
|
2014-03-23 15:08:01 +03:00
|
|
|
});
|
2023-05-27 22:12:03 +02:00
|
|
|
std::reverse(versions.begin(), versions.end());
|
2014-03-23 15:08:01 +03:00
|
|
|
|
2024-11-13 22:27:51 +02:00
|
|
|
for(const auto & version : versions)
|
2014-03-23 15:08:01 +03:00
|
|
|
{
|
|
|
|
result += headerTemplate.arg(version);
|
|
|
|
result += entryBegin;
|
2024-11-13 22:27:51 +02:00
|
|
|
for(const auto & line : changelog.value(version))
|
2014-03-23 15:08:01 +03:00
|
|
|
result += entryLine.arg(line);
|
|
|
|
result += entryEnd;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-11-14 20:43:41 +02:00
|
|
|
QStringList CModListView::getModNames(QString queryingModID, QStringList input)
|
2023-03-26 23:32:24 +02:00
|
|
|
{
|
|
|
|
QStringList result;
|
|
|
|
|
2024-11-14 20:43:41 +02:00
|
|
|
auto queryingMod = modStateModel->getMod(queryingModID);
|
|
|
|
|
2023-03-27 00:10:44 +02:00
|
|
|
for(const auto & modID : input)
|
2023-03-26 23:32:24 +02:00
|
|
|
{
|
2024-11-18 19:37:45 +02:00
|
|
|
if (modStateModel->isModExists(modID) && modStateModel->getMod(modID).isHidden())
|
2024-11-13 19:25:59 +02:00
|
|
|
continue;
|
|
|
|
|
2024-11-18 19:37:45 +02:00
|
|
|
QString parentModID = modStateModel->getTopParent(modID);
|
|
|
|
QString displayName;
|
2023-03-26 23:32:24 +02:00
|
|
|
|
2024-11-18 19:37:45 +02:00
|
|
|
if (modStateModel->isSubmod(modID) && queryingMod.getParentID() != parentModID )
|
|
|
|
{
|
|
|
|
// show in form "parent mod (submod)"
|
2024-11-14 20:43:41 +02:00
|
|
|
|
2024-11-18 19:37:45 +02:00
|
|
|
QString parentDisplayName = parentModID;
|
|
|
|
QString submodDisplayName = modID;
|
2024-11-14 18:55:15 +02:00
|
|
|
|
2024-11-18 19:37:45 +02:00
|
|
|
if (modStateModel->isModExists(parentModID))
|
|
|
|
parentDisplayName = modStateModel->getMod(parentModID).getName();
|
2024-10-17 16:19:59 +02:00
|
|
|
|
2024-11-18 19:37:45 +02:00
|
|
|
if (modStateModel->isModExists(modID))
|
|
|
|
submodDisplayName = modStateModel->getMod(modID).getName();
|
|
|
|
|
|
|
|
displayName = QString("%1 (%2)").arg(submodDisplayName, parentDisplayName);
|
|
|
|
}
|
|
|
|
else
|
2024-10-17 16:19:59 +02:00
|
|
|
{
|
2024-11-18 19:37:45 +02:00
|
|
|
// show simply as mod name
|
|
|
|
displayName = modID;
|
|
|
|
if (modStateModel->isModExists(modID))
|
|
|
|
displayName = modStateModel->getMod(modID).getName();
|
2024-10-17 16:19:59 +02:00
|
|
|
}
|
|
|
|
result += displayName;
|
2023-03-26 23:32:24 +02:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-11-13 22:27:51 +02:00
|
|
|
QString CModListView::genModInfoText(const ModState & mod)
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
|
|
|
QString prefix = "<p><span style=\" font-weight:600;\">%1: </span>"; // shared prefix
|
2022-09-29 16:21:29 +02:00
|
|
|
QString redPrefix = "<p><span style=\" font-weight:600; color:red\">%1: </span>"; // shared prefix
|
2013-08-22 17:22:49 +03:00
|
|
|
QString lineTemplate = prefix + "%2</p>";
|
2018-04-13 07:34:58 +02:00
|
|
|
QString urlTemplate = prefix + "<a href=\"%2\">%3</a></p>";
|
2013-08-22 17:22:49 +03:00
|
|
|
QString textTemplate = prefix + "</p><p align=\"justify\">%2</p>";
|
2014-03-20 20:06:25 +03:00
|
|
|
QString listTemplate = "<p align=\"justify\">%1: %2</p>";
|
|
|
|
QString noteTemplate = "<p align=\"justify\">%1</p>";
|
2022-12-25 13:19:16 +02:00
|
|
|
QString incompatibleString = redPrefix + tr("Mod is incompatible") + "</p>";
|
2022-09-29 16:21:29 +02:00
|
|
|
QString supportedVersions = redPrefix + "%2 %3 %4</p>";
|
2013-08-22 17:22:49 +03:00
|
|
|
|
|
|
|
QString result;
|
|
|
|
|
2024-11-12 22:00:21 +02:00
|
|
|
result += replaceIfNotEmpty(mod.getName(), lineTemplate.arg(tr("Mod name")));
|
2024-11-14 20:01:49 +02:00
|
|
|
if (mod.isUpdateAvailable())
|
|
|
|
{
|
|
|
|
result += replaceIfNotEmpty(mod.getInstalledVersion(), lineTemplate.arg(tr("Installed version")));
|
|
|
|
result += replaceIfNotEmpty(mod.getRepositoryVersion(), lineTemplate.arg(tr("Latest version")));
|
|
|
|
}
|
|
|
|
else
|
2024-11-15 18:43:28 +02:00
|
|
|
{
|
|
|
|
if (mod.isInstalled())
|
|
|
|
result += replaceIfNotEmpty(mod.getInstalledVersion(), lineTemplate.arg(tr("Installed version")));
|
|
|
|
else
|
|
|
|
result += replaceIfNotEmpty(mod.getRepositoryVersion(), lineTemplate.arg(tr("Latest version")));
|
|
|
|
}
|
2024-11-12 22:00:21 +02:00
|
|
|
|
2024-11-14 20:22:02 +02:00
|
|
|
if (mod.isInstalled())
|
|
|
|
result += replaceIfNotEmpty(modStateModel->getInstalledModSizeFormatted(mod.getID()), lineTemplate.arg(tr("Size")));
|
2014-03-23 15:08:01 +03:00
|
|
|
|
2024-11-12 22:00:21 +02:00
|
|
|
if((!mod.isInstalled() || mod.isUpdateAvailable()) && !mod.getDownloadSizeFormatted().isEmpty())
|
|
|
|
result += replaceIfNotEmpty(mod.getDownloadSizeFormatted(), lineTemplate.arg(tr("Download size")));
|
2023-09-01 16:43:26 +02:00
|
|
|
|
2024-11-12 22:00:21 +02:00
|
|
|
result += replaceIfNotEmpty(mod.getAuthors(), lineTemplate.arg(tr("Authors")));
|
2014-03-23 15:08:01 +03:00
|
|
|
|
2024-11-13 19:25:59 +02:00
|
|
|
if(!mod.getLicenseName().isEmpty())
|
2024-11-12 22:00:21 +02:00
|
|
|
result += urlTemplate.arg(tr("License")).arg(mod.getLicenseUrl()).arg(mod.getLicenseName());
|
2014-03-23 15:08:01 +03:00
|
|
|
|
2024-11-13 19:25:59 +02:00
|
|
|
if(!mod.getContact().isEmpty())
|
2024-11-12 22:00:21 +02:00
|
|
|
result += urlTemplate.arg(tr("Contact")).arg(mod.getContact()).arg(mod.getContact());
|
2014-03-23 15:08:01 +03:00
|
|
|
|
2022-09-29 16:21:29 +02:00
|
|
|
//compatibility info
|
2023-03-26 23:26:58 +02:00
|
|
|
if(!mod.isCompatible())
|
2022-09-29 16:21:29 +02:00
|
|
|
{
|
2024-11-12 22:00:21 +02:00
|
|
|
auto compatibilityInfo = mod.getCompatibleVersionRange();
|
|
|
|
auto minStr = compatibilityInfo.first;
|
|
|
|
auto maxStr = compatibilityInfo.second;
|
2022-09-29 16:21:29 +02:00
|
|
|
|
|
|
|
result += incompatibleString.arg(tr("Compatibility"));
|
|
|
|
if(minStr == maxStr)
|
|
|
|
result += supportedVersions.arg(tr("Required VCMI version"), minStr, "", "");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(minStr.isEmpty() || maxStr.isEmpty())
|
|
|
|
{
|
|
|
|
if(minStr.isEmpty())
|
2024-05-01 11:43:20 +02:00
|
|
|
result += supportedVersions.arg(tr("Supported VCMI version"), maxStr, ", ", tr("please upgrade mod"));
|
2022-09-29 16:21:29 +02:00
|
|
|
else
|
2024-05-01 12:46:39 +02:00
|
|
|
result += supportedVersions.arg(tr("Required VCMI version"), minStr, " ", tr("or newer"));
|
2022-09-29 16:21:29 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
result += supportedVersions.arg(tr("Supported VCMI versions"), minStr, " - ", maxStr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-12 22:00:21 +02:00
|
|
|
QVariant baseLanguageVariant = mod.getBaseLanguage();
|
2023-03-26 23:26:58 +02:00
|
|
|
QString baseLanguageID = baseLanguageVariant.isValid() ? baseLanguageVariant.toString() : "english";
|
|
|
|
|
2024-11-12 22:00:21 +02:00
|
|
|
QStringList supportedLanguages = mod.getSupportedLanguages();
|
2023-03-26 23:26:58 +02:00
|
|
|
|
2024-11-12 22:00:21 +02:00
|
|
|
if(supportedLanguages.size() > 1)
|
2023-03-26 23:26:58 +02:00
|
|
|
{
|
2024-11-12 22:00:21 +02:00
|
|
|
QStringList supportedLanguagesTranslated;
|
2023-03-26 23:26:58 +02:00
|
|
|
|
2024-11-12 22:00:21 +02:00
|
|
|
for (const auto & languageID : supportedLanguages)
|
|
|
|
supportedLanguagesTranslated += QApplication::translate("Language", Languages::getLanguageOptions(languageID.toStdString()).nameEnglish.c_str());
|
2023-03-26 23:26:58 +02:00
|
|
|
|
2024-11-12 22:00:21 +02:00
|
|
|
result += replaceIfNotEmpty(supportedLanguagesTranslated, lineTemplate.arg(tr("Languages")));
|
2023-03-26 23:26:58 +02:00
|
|
|
}
|
|
|
|
|
2024-11-15 15:25:36 +02:00
|
|
|
QStringList conflicts = mod.getConflicts();
|
|
|
|
for (const auto & otherMod : modStateModel->getAllMods())
|
|
|
|
{
|
|
|
|
QStringList otherConflicts = modStateModel->getMod(otherMod).getConflicts();
|
|
|
|
|
|
|
|
if (otherConflicts.contains(mod.getID()) && !conflicts.contains(otherMod))
|
|
|
|
conflicts.push_back(otherMod);
|
|
|
|
}
|
|
|
|
|
2024-11-14 20:43:41 +02:00
|
|
|
result += replaceIfNotEmpty(getModNames(mod.getID(), mod.getDependencies()), lineTemplate.arg(tr("Required mods")));
|
2024-11-15 15:25:36 +02:00
|
|
|
result += replaceIfNotEmpty(getModNames(mod.getID(), conflicts), lineTemplate.arg(tr("Conflicting mods")));
|
2024-11-12 22:00:21 +02:00
|
|
|
result += replaceIfNotEmpty(mod.getDescription(), textTemplate.arg(tr("Description")));
|
2013-08-22 17:22:49 +03:00
|
|
|
|
|
|
|
result += "<p></p>"; // to get some empty space
|
|
|
|
|
2024-11-20 22:44:24 +02:00
|
|
|
QString translationMismatch = tr("This mod cannot be enabled because it translates into a different language.");
|
2024-11-20 17:24:52 +02:00
|
|
|
QString notInstalledDeps = tr("This mod can not be enabled because the following dependencies are not present");
|
|
|
|
QString unavailableDeps = tr("This mod can not be installed because the following dependencies are not present");
|
2023-03-30 22:23:14 +02:00
|
|
|
QString thisIsSubmod = tr("This is a submod and it cannot be installed or uninstalled separately from its parent mod");
|
2013-08-22 17:22:49 +03:00
|
|
|
|
|
|
|
QString notes;
|
|
|
|
|
2024-11-20 17:24:52 +02:00
|
|
|
QStringList notInstalledDependencies = this->getModsToInstall(mod.getID());
|
|
|
|
QStringList unavailableDependencies = this->findUnavailableMods(notInstalledDependencies);
|
|
|
|
|
|
|
|
if (mod.isInstalled())
|
|
|
|
notes += replaceIfNotEmpty(getModNames(mod.getID(), notInstalledDependencies), listTemplate.arg(notInstalledDeps));
|
|
|
|
else
|
|
|
|
notes += replaceIfNotEmpty(getModNames(mod.getID(), unavailableDependencies), listTemplate.arg(unavailableDeps));
|
2014-03-20 20:06:25 +03:00
|
|
|
|
2023-10-21 22:55:20 +02:00
|
|
|
if(mod.isSubmod())
|
2014-03-20 20:06:25 +03:00
|
|
|
notes += noteTemplate.arg(thisIsSubmod);
|
2013-08-22 17:22:49 +03:00
|
|
|
|
2024-11-20 22:44:24 +02:00
|
|
|
if (mod.isTranslation() && CGeneralTextHandler::getPreferredLanguage() != mod.getBaseLanguage().toStdString())
|
|
|
|
notes += noteTemplate.arg(translationMismatch);
|
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
if(notes.size())
|
2014-03-20 20:06:25 +03:00
|
|
|
result += textTemplate.arg(tr("Notes")).arg(notes);
|
2013-08-22 17:22:49 +03:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CModListView::disableModInfo()
|
|
|
|
{
|
2014-08-04 14:03:57 +03:00
|
|
|
ui->disableButton->setVisible(false);
|
|
|
|
ui->enableButton->setVisible(false);
|
|
|
|
ui->installButton->setVisible(false);
|
|
|
|
ui->uninstallButton->setVisible(false);
|
|
|
|
ui->updateButton->setVisible(false);
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
|
2014-03-20 20:06:25 +03:00
|
|
|
void CModListView::dataChanged(const QModelIndex & topleft, const QModelIndex & bottomRight)
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
2014-03-20 20:06:25 +03:00
|
|
|
selectMod(ui->allModsView->currentIndex());
|
|
|
|
}
|
|
|
|
|
|
|
|
void CModListView::selectMod(const QModelIndex & index)
|
|
|
|
{
|
2024-11-14 20:01:49 +02:00
|
|
|
ui->tabWidget->setCurrentIndex(0);
|
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
if(!index.isValid())
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
|
|
|
disableModInfo();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-03-02 23:24:00 +02:00
|
|
|
const auto modName = index.data(ModRoles::ModNameRole).toString();
|
2024-11-12 22:00:21 +02:00
|
|
|
auto mod = modStateModel->getMod(modName);
|
2013-08-22 17:22:49 +03:00
|
|
|
|
2024-11-14 20:01:49 +02:00
|
|
|
ui->tabWidget->setTabEnabled(1, !mod.getChangelog().isEmpty());
|
|
|
|
ui->tabWidget->setTabEnabled(2, !mod.getScreenshots().isEmpty());
|
|
|
|
|
2014-03-23 15:08:01 +03:00
|
|
|
ui->modInfoBrowser->setHtml(genModInfoText(mod));
|
|
|
|
ui->changelogBrowser->setHtml(genChangelogText(mod));
|
2013-08-22 17:22:49 +03:00
|
|
|
|
2024-05-01 20:05:01 +02:00
|
|
|
Helper::enableScrollBySwiping(ui->modInfoBrowser);
|
|
|
|
Helper::enableScrollBySwiping(ui->changelogBrowser);
|
|
|
|
|
2024-12-10 15:38:13 +02:00
|
|
|
QStringList notInstalledDependencies = getModsToInstall(modName);
|
|
|
|
QStringList unavailableDependencies = findUnavailableMods(notInstalledDependencies);
|
2024-11-20 22:44:24 +02:00
|
|
|
bool translationMismatch = mod.isTranslation() && CGeneralTextHandler::getPreferredLanguage() != mod.getBaseLanguage().toStdString();
|
2024-12-10 15:38:13 +02:00
|
|
|
bool modIsBeingDownloaded = enqueuedModDownloads.contains(mod.getID());
|
2013-08-22 17:22:49 +03:00
|
|
|
|
2024-11-20 00:15:05 +02:00
|
|
|
ui->disableButton->setVisible(modStateModel->isModInstalled(mod.getID()) && modStateModel->isModEnabled(mod.getID()));
|
|
|
|
ui->enableButton->setVisible(modStateModel->isModInstalled(mod.getID()) && !modStateModel->isModEnabled(mod.getID()));
|
2023-10-21 22:55:20 +02:00
|
|
|
ui->installButton->setVisible(mod.isAvailable() && !mod.isSubmod());
|
|
|
|
ui->uninstallButton->setVisible(mod.isInstalled() && !mod.isSubmod());
|
2024-11-12 22:00:21 +02:00
|
|
|
ui->updateButton->setVisible(mod.isUpdateAvailable());
|
2013-08-22 17:22:49 +03:00
|
|
|
|
|
|
|
// Block buttons if action is not allowed at this time
|
2024-11-14 22:56:19 +02:00
|
|
|
ui->disableButton->setEnabled(true);
|
2024-11-20 22:44:24 +02:00
|
|
|
ui->enableButton->setEnabled(notInstalledDependencies.empty() && !translationMismatch);
|
2024-12-10 15:38:13 +02:00
|
|
|
ui->installButton->setEnabled(unavailableDependencies.empty() && !modIsBeingDownloaded);
|
2024-11-15 13:54:43 +02:00
|
|
|
ui->uninstallButton->setEnabled(true);
|
2024-12-10 15:38:13 +02:00
|
|
|
ui->updateButton->setEnabled(unavailableDependencies.empty() && !modIsBeingDownloaded);
|
2014-03-23 15:08:01 +03:00
|
|
|
|
|
|
|
loadScreenshots();
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
void CModListView::modSelected(const QModelIndex & current, const QModelIndex &)
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
2014-03-20 20:06:25 +03:00
|
|
|
selectMod(current);
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
void CModListView::on_allModsView_activated(const QModelIndex & index)
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
2014-03-20 20:06:25 +03:00
|
|
|
selectMod(index);
|
2023-01-26 01:01:41 +02:00
|
|
|
loadScreenshots();
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
void CModListView::on_lineEdit_textChanged(const QString & arg1)
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
2022-05-28 15:32:20 +02:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
|
|
|
auto baseStr = QRegularExpression::wildcardToRegularExpression(arg1, QRegularExpression::UnanchoredWildcardConversion);
|
|
|
|
#else
|
|
|
|
auto baseStr = QRegularExpression::wildcardToRegularExpression(arg1);
|
|
|
|
//Hack due to lack QRegularExpression::UnanchoredWildcardConversion in Qt5
|
|
|
|
baseStr.chop(3);
|
|
|
|
baseStr.remove(0,5);
|
|
|
|
#endif
|
|
|
|
QRegularExpression regExp{baseStr, QRegularExpression::CaseInsensitiveOption};
|
|
|
|
filterModel->setFilterRegularExpression(regExp);
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CModListView::on_comboBox_currentIndexChanged(int index)
|
|
|
|
{
|
2024-11-12 22:00:21 +02:00
|
|
|
auto enumIndex = static_cast<ModFilterMask>(index);
|
|
|
|
filterModel->setTypeFilter(enumIndex);
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
|
2024-11-20 17:24:52 +02:00
|
|
|
QStringList CModListView::findUnavailableMods(QStringList candidates)
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
2024-11-20 17:24:52 +02:00
|
|
|
QStringList invalidMods;
|
2024-11-18 19:37:45 +02:00
|
|
|
|
2024-11-20 17:24:52 +02:00
|
|
|
for(QString modName : candidates)
|
|
|
|
{
|
|
|
|
if(!modStateModel->isModExists(modName))
|
|
|
|
invalidMods.push_back(modName);
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
2024-11-20 17:24:52 +02:00
|
|
|
return invalidMods;
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CModListView::on_enableButton_clicked()
|
|
|
|
{
|
2014-03-20 20:06:25 +03:00
|
|
|
QString modName = ui->allModsView->currentIndex().data(ModRoles::ModNameRole).toString();
|
2022-12-26 02:34:10 +02:00
|
|
|
enableModByName(modName);
|
|
|
|
checkManagerErrors();
|
|
|
|
}
|
2013-08-22 17:22:49 +03:00
|
|
|
|
2022-12-26 02:34:10 +02:00
|
|
|
void CModListView::enableModByName(QString modName)
|
|
|
|
{
|
2024-11-20 00:15:05 +02:00
|
|
|
manager->enableMods({modName});
|
2024-11-21 22:22:10 +02:00
|
|
|
modModel->modChanged(modName);
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CModListView::on_disableButton_clicked()
|
|
|
|
{
|
2014-03-20 20:06:25 +03:00
|
|
|
QString modName = ui->allModsView->currentIndex().data(ModRoles::ModNameRole).toString();
|
2022-12-26 02:34:10 +02:00
|
|
|
disableModByName(modName);
|
|
|
|
checkManagerErrors();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CModListView::disableModByName(QString modName)
|
|
|
|
{
|
2024-11-14 22:56:19 +02:00
|
|
|
manager->disableMod(modName);
|
2024-11-21 22:22:10 +02:00
|
|
|
modModel->modChanged(modName);
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
|
2024-11-18 19:37:45 +02:00
|
|
|
QStringList CModListView::getModsToInstall(QString mod)
|
|
|
|
{
|
|
|
|
QStringList result;
|
|
|
|
QStringList candidates;
|
|
|
|
QStringList processed;
|
|
|
|
|
|
|
|
candidates.push_back(mod);
|
|
|
|
while (!candidates.empty())
|
|
|
|
{
|
|
|
|
QString potentialToInstall = candidates.back();
|
|
|
|
candidates.pop_back();
|
|
|
|
processed.push_back(potentialToInstall);
|
|
|
|
|
2024-11-20 17:24:52 +02:00
|
|
|
if (modStateModel->isSubmod(potentialToInstall))
|
|
|
|
{
|
|
|
|
QString topParent = modStateModel->getTopParent(potentialToInstall);
|
|
|
|
if (modStateModel->isModInstalled(topParent))
|
|
|
|
{
|
|
|
|
if (modStateModel->isModUpdateAvailable(topParent))
|
|
|
|
potentialToInstall = modStateModel->getTopParent(potentialToInstall);
|
|
|
|
// else - potentially broken mod that depends on non-existing submod
|
|
|
|
}
|
|
|
|
else
|
|
|
|
potentialToInstall = modStateModel->getTopParent(potentialToInstall);
|
|
|
|
}
|
|
|
|
|
2024-12-10 15:37:36 +02:00
|
|
|
if (modStateModel->isModExists(potentialToInstall) && !modStateModel->isModInstalled(potentialToInstall))
|
|
|
|
result.push_back(potentialToInstall);
|
2024-11-18 19:37:45 +02:00
|
|
|
|
2024-11-20 17:24:52 +02:00
|
|
|
if (modStateModel->isModExists(potentialToInstall))
|
2024-11-18 19:37:45 +02:00
|
|
|
{
|
2024-11-20 17:24:52 +02:00
|
|
|
QStringList dependencies = modStateModel->getMod(potentialToInstall).getDependencies();
|
|
|
|
for (const auto & dependency : dependencies)
|
|
|
|
{
|
|
|
|
if (!processed.contains(dependency) && !candidates.contains(dependency))
|
|
|
|
candidates.push_back(dependency);
|
|
|
|
}
|
2024-11-18 19:37:45 +02:00
|
|
|
}
|
|
|
|
}
|
2024-11-26 15:31:32 +02:00
|
|
|
result.removeDuplicates();
|
2024-11-18 19:37:45 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-08-22 17:22:49 +03:00
|
|
|
void CModListView::on_updateButton_clicked()
|
|
|
|
{
|
2014-03-20 20:06:25 +03:00
|
|
|
QString modName = ui->allModsView->currentIndex().data(ModRoles::ModNameRole).toString();
|
2024-12-05 00:53:07 +02:00
|
|
|
doUpdateMod(modName);
|
2024-12-10 15:38:13 +02:00
|
|
|
|
|
|
|
ui->updateButton->setEnabled(false);
|
2024-12-05 00:53:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CModListView::doUpdateMod(const QString & modName)
|
|
|
|
{
|
2024-12-04 13:15:39 +02:00
|
|
|
auto targetMod = modStateModel->getMod(modName);
|
|
|
|
|
|
|
|
if(targetMod.isUpdateAvailable())
|
2024-12-10 15:38:13 +02:00
|
|
|
downloadMod(targetMod);
|
2013-08-22 17:22:49 +03:00
|
|
|
|
2024-11-18 19:37:45 +02:00
|
|
|
for(const auto & name : getModsToInstall(modName))
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
2024-11-12 22:00:21 +02:00
|
|
|
auto mod = modStateModel->getMod(name);
|
2013-08-22 17:22:49 +03:00
|
|
|
// update required mod, install missing (can be new dependency)
|
2024-11-12 22:00:21 +02:00
|
|
|
if(mod.isUpdateAvailable() || !mod.isInstalled())
|
2024-12-10 15:38:13 +02:00
|
|
|
downloadMod(mod);
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CModListView::on_uninstallButton_clicked()
|
|
|
|
{
|
2014-03-20 20:06:25 +03:00
|
|
|
QString modName = ui->allModsView->currentIndex().data(ModRoles::ModNameRole).toString();
|
2013-08-22 17:22:49 +03:00
|
|
|
|
2024-11-12 22:00:21 +02:00
|
|
|
if(modStateModel->isModExists(modName) && modStateModel->getMod(modName).isInstalled())
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
2024-11-14 20:43:41 +02:00
|
|
|
if(modStateModel->isModEnabled(modName))
|
2013-11-14 16:21:09 +03:00
|
|
|
manager->disableMod(modName);
|
2013-08-22 17:22:49 +03:00
|
|
|
manager->uninstallMod(modName);
|
2024-11-15 13:54:43 +02:00
|
|
|
modModel->reloadRepositories();
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
2022-12-26 02:34:10 +02:00
|
|
|
|
2013-09-06 00:25:03 +03:00
|
|
|
checkManagerErrors();
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CModListView::on_installButton_clicked()
|
|
|
|
{
|
2014-03-20 20:06:25 +03:00
|
|
|
QString modName = ui->allModsView->currentIndex().data(ModRoles::ModNameRole).toString();
|
2013-08-22 17:22:49 +03:00
|
|
|
|
2024-12-10 15:59:29 +02:00
|
|
|
doInstallMod(modName);
|
2024-12-10 15:38:13 +02:00
|
|
|
|
|
|
|
ui->installButton->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CModListView::downloadMod(const ModState & mod)
|
|
|
|
{
|
|
|
|
if (enqueuedModDownloads.contains(mod.getID()))
|
|
|
|
return;
|
|
|
|
|
|
|
|
enqueuedModDownloads.push_back(mod.getID());
|
|
|
|
downloadFile(mod.getID() + ".zip", mod.getDownloadUrl(), mod.getName(), mod.getDownloadSizeBytes());
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
|
2024-11-21 22:22:10 +02:00
|
|
|
void CModListView::downloadFile(QString file, QUrl url, QString description, qint64 sizeBytes)
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
2018-04-13 07:34:58 +02:00
|
|
|
if(!dlManager)
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
|
|
|
dlManager = new CDownloadManager();
|
|
|
|
ui->progressWidget->setVisible(true);
|
|
|
|
connect(dlManager, SIGNAL(downloadProgress(qint64,qint64)),
|
2018-04-13 07:34:58 +02:00
|
|
|
this, SLOT(downloadProgress(qint64,qint64)));
|
2013-08-22 17:22:49 +03:00
|
|
|
|
|
|
|
connect(dlManager, SIGNAL(finished(QStringList,QStringList,QStringList)),
|
2018-04-13 07:34:58 +02:00
|
|
|
this, SLOT(downloadFinished(QStringList,QStringList,QStringList)));
|
2024-07-08 15:10:44 +02:00
|
|
|
|
2023-09-19 23:38:00 +02:00
|
|
|
connect(manager.get(), SIGNAL(extractionProgress(qint64,qint64)),
|
2023-12-18 00:34:00 +02:00
|
|
|
this, SLOT(extractionProgress(qint64,qint64)));
|
2013-08-22 17:22:49 +03:00
|
|
|
|
2024-11-12 22:00:21 +02:00
|
|
|
connect(modModel, &ModStateItemModel::dataChanged, filterModel, &QAbstractItemModel::dataChanged);
|
2013-08-22 17:22:49 +03:00
|
|
|
|
2024-07-08 15:10:44 +02:00
|
|
|
const auto progressBarFormat = tr("Downloading %1. %p% (%v MB out of %m MB) finished").arg(description);
|
2013-08-22 17:22:49 +03:00
|
|
|
ui->progressBar->setFormat(progressBarFormat);
|
|
|
|
}
|
|
|
|
|
2024-11-21 22:22:10 +02:00
|
|
|
dlManager->downloadFile(url, file, sizeBytes);
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CModListView::downloadProgress(qint64 current, qint64 max)
|
|
|
|
{
|
2023-09-01 22:18:23 +02:00
|
|
|
// display progress, in megabytes
|
2023-09-19 23:38:00 +02:00
|
|
|
ui->progressBar->setVisible(true);
|
2023-09-01 22:18:23 +02:00
|
|
|
ui->progressBar->setMaximum(max / (1024 * 1024));
|
|
|
|
ui->progressBar->setValue(current / (1024 * 1024));
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
|
2023-12-18 00:34:00 +02:00
|
|
|
void CModListView::extractionProgress(qint64 current, qint64 max)
|
|
|
|
{
|
|
|
|
// display progress, in extracted files
|
|
|
|
ui->progressBar->setVisible(true);
|
|
|
|
ui->progressBar->setMaximum(max);
|
|
|
|
ui->progressBar->setValue(current);
|
|
|
|
}
|
|
|
|
|
2013-08-22 17:22:49 +03:00
|
|
|
void CModListView::downloadFinished(QStringList savedFiles, QStringList failedFiles, QStringList errors)
|
|
|
|
{
|
2023-09-01 22:18:23 +02:00
|
|
|
QString title = tr("Download failed");
|
|
|
|
QString firstLine = tr("Unable to download all files.\n\nEncountered errors:\n\n");
|
|
|
|
QString lastLine = tr("\n\nInstall successfully downloaded?");
|
2022-09-29 15:38:03 +02:00
|
|
|
bool doInstallFiles = false;
|
2013-08-22 17:22:49 +03:00
|
|
|
|
|
|
|
// if all files were d/loaded there should be no errors. And on failure there must be an error
|
|
|
|
assert(failedFiles.empty() == errors.empty());
|
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
if(savedFiles.empty())
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
|
|
|
// no successfully downloaded mods
|
2018-04-13 07:34:58 +02:00
|
|
|
QMessageBox::warning(this, title, firstLine + errors.join("\n"), QMessageBox::Ok, QMessageBox::Ok);
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
2018-04-13 07:34:58 +02:00
|
|
|
else if(!failedFiles.empty())
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
|
|
|
// some mods were not downloaded
|
|
|
|
int result = QMessageBox::warning (this, title, firstLine + errors.join("\n") + lastLine,
|
|
|
|
QMessageBox::Yes | QMessageBox::No, QMessageBox::No );
|
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
if(result == QMessageBox::Yes)
|
2022-09-29 15:38:03 +02:00
|
|
|
doInstallFiles = true;
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// everything OK
|
2022-09-29 15:38:03 +02:00
|
|
|
doInstallFiles = true;
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
|
2024-12-10 15:38:13 +02:00
|
|
|
enqueuedModDownloads.clear();
|
2013-08-22 17:22:49 +03:00
|
|
|
dlManager->deleteLater();
|
|
|
|
dlManager = nullptr;
|
2023-09-19 23:38:00 +02:00
|
|
|
|
|
|
|
ui->progressBar->setMaximum(0);
|
|
|
|
ui->progressBar->setValue(0);
|
2022-09-29 15:38:03 +02:00
|
|
|
|
|
|
|
if(doInstallFiles)
|
|
|
|
installFiles(savedFiles);
|
2022-12-26 02:34:10 +02:00
|
|
|
|
2023-09-19 23:38:00 +02:00
|
|
|
hideProgressBar();
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CModListView::hideProgressBar()
|
|
|
|
{
|
2018-04-13 07:34:58 +02:00
|
|
|
if(dlManager == nullptr) // it was not recreated meanwhile
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
|
|
|
ui->progressWidget->setVisible(false);
|
|
|
|
ui->progressBar->setMaximum(0);
|
|
|
|
ui->progressBar->setValue(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CModListView::installFiles(QStringList files)
|
|
|
|
{
|
|
|
|
QStringList mods;
|
2023-12-25 19:53:02 +02:00
|
|
|
QStringList maps;
|
2014-03-23 15:08:01 +03:00
|
|
|
QStringList images;
|
2024-08-30 21:17:18 +02:00
|
|
|
QStringList exe;
|
2024-11-13 19:25:59 +02:00
|
|
|
JsonNode repository;
|
2013-08-22 17:22:49 +03:00
|
|
|
|
|
|
|
// TODO: some better way to separate zip's with mods and downloaded repository files
|
2018-04-13 07:34:58 +02:00
|
|
|
for(QString filename : files)
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
2023-12-25 23:41:15 +02:00
|
|
|
if(filename.endsWith(".zip", Qt::CaseInsensitive))
|
2013-08-22 17:22:49 +03:00
|
|
|
mods.push_back(filename);
|
2023-12-25 23:41:15 +02:00
|
|
|
else if(filename.endsWith(".h3m", Qt::CaseInsensitive) || filename.endsWith(".h3c", Qt::CaseInsensitive) || filename.endsWith(".vmap", Qt::CaseInsensitive) || filename.endsWith(".vcmp", Qt::CaseInsensitive))
|
2023-12-25 19:53:02 +02:00
|
|
|
maps.push_back(filename);
|
2024-08-30 21:17:18 +02:00
|
|
|
if(filename.endsWith(".exe", Qt::CaseInsensitive))
|
|
|
|
exe.push_back(filename);
|
2023-12-25 23:41:15 +02:00
|
|
|
else if(filename.endsWith(".json", Qt::CaseInsensitive))
|
2022-09-29 15:38:03 +02:00
|
|
|
{
|
|
|
|
//download and merge additional files
|
2024-11-13 19:25:59 +02:00
|
|
|
const auto &repoData = JsonUtils::jsonFromFile(filename);
|
|
|
|
if(repoData["name"].isNull())
|
2022-09-29 15:38:03 +02:00
|
|
|
{
|
2024-11-13 19:25:59 +02:00
|
|
|
// This is main repository index. Download all referenced mods
|
|
|
|
for(const auto & [modName, modJson] : repoData.Struct())
|
2022-09-29 15:38:03 +02:00
|
|
|
{
|
2024-11-13 19:25:59 +02:00
|
|
|
auto modNameLower = boost::algorithm::to_lower_copy(modName);
|
|
|
|
auto modJsonUrl = modJson["mod"];
|
|
|
|
if(!modJsonUrl.isNull())
|
|
|
|
downloadFile(QString::fromStdString(modName + ".json"), QString::fromStdString(modJsonUrl.String()), tr("mods repository index"));
|
|
|
|
|
2024-11-14 17:41:22 +02:00
|
|
|
repository[modNameLower] = modJson;
|
2022-09-29 15:38:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-11-13 19:25:59 +02:00
|
|
|
// This is json of a single mod. Extract name of mod and add it to repo
|
|
|
|
auto modName = QFileInfo(filename).baseName().toStdString();
|
|
|
|
auto modNameLower = boost::algorithm::to_lower_copy(modName);
|
|
|
|
repository[modNameLower] = repoData;
|
2022-09-29 15:38:03 +02:00
|
|
|
}
|
|
|
|
}
|
2023-12-25 23:41:15 +02:00
|
|
|
else if(filename.endsWith(".png", Qt::CaseInsensitive))
|
2014-03-23 15:08:01 +03:00
|
|
|
images.push_back(filename);
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
2023-09-05 12:33:26 +02:00
|
|
|
|
2024-11-13 19:25:59 +02:00
|
|
|
if (!repository.isNull())
|
|
|
|
{
|
|
|
|
manager->appendRepositories(repository);
|
|
|
|
modModel->reloadRepositories();
|
|
|
|
|
|
|
|
static const QString repositoryCachePath = CLauncherDirs::downloadsPath() + "/repositoryCache.json";
|
|
|
|
JsonUtils::jsonToFile(repositoryCachePath, modStateModel->getRepositoryData());
|
|
|
|
}
|
2023-09-05 12:33:26 +02:00
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
if(!mods.empty())
|
2024-11-24 19:15:17 +02:00
|
|
|
{
|
2013-08-22 17:22:49 +03:00
|
|
|
installMods(mods);
|
2024-11-24 19:15:17 +02:00
|
|
|
modStateModel->reloadLocalState();
|
|
|
|
modModel->reloadRepositories();
|
|
|
|
}
|
2014-03-23 15:08:01 +03:00
|
|
|
|
2023-12-25 19:53:02 +02:00
|
|
|
if(!maps.empty())
|
|
|
|
installMaps(maps);
|
|
|
|
|
2024-08-30 21:17:18 +02:00
|
|
|
if(!exe.empty())
|
2024-08-30 22:20:33 +02:00
|
|
|
{
|
2024-12-11 16:31:37 +02:00
|
|
|
ui->progressBar->setFormat(tr("Installing Heroes Chronicles"));
|
2024-12-10 23:28:11 +02:00
|
|
|
ui->progressWidget->setVisible(true);
|
|
|
|
ui->pushButton->setEnabled(false);
|
2024-08-31 00:44:20 +02:00
|
|
|
|
2024-08-31 18:46:45 +02:00
|
|
|
float prog = 0.0;
|
|
|
|
|
|
|
|
auto futureExtract = std::async(std::launch::async, [this, exe, &prog]()
|
|
|
|
{
|
2024-08-31 22:05:36 +02:00
|
|
|
ChroniclesExtractor ce(this, [&prog](float progress) { prog = progress; });
|
2024-08-31 18:46:45 +02:00
|
|
|
ce.installChronicles(exe);
|
2024-12-11 21:45:36 +02:00
|
|
|
enableModByName("chronicles");
|
2024-08-31 18:46:45 +02:00
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
while(futureExtract.wait_for(std::chrono::milliseconds(10)) != std::future_status::ready)
|
|
|
|
{
|
2024-09-01 02:16:03 +02:00
|
|
|
emit extractionProgress(static_cast<int>(prog * 1000.f), 1000);
|
2024-08-31 18:46:45 +02:00
|
|
|
qApp->processEvents();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(futureExtract.get())
|
|
|
|
{
|
2024-12-10 23:28:11 +02:00
|
|
|
hideProgressBar();
|
|
|
|
ui->pushButton->setEnabled(true);
|
|
|
|
ui->progressWidget->setVisible(false);
|
2024-08-31 18:46:45 +02:00
|
|
|
//update
|
2024-11-18 16:40:15 +02:00
|
|
|
modStateModel->reloadLocalState();
|
|
|
|
modModel->reloadRepositories();
|
2024-08-31 18:46:45 +02:00
|
|
|
}
|
2024-08-30 22:20:33 +02:00
|
|
|
}
|
2024-08-30 21:17:18 +02:00
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
if(!images.empty())
|
2014-03-23 15:08:01 +03:00
|
|
|
loadScreenshots();
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CModListView::installMods(QStringList archives)
|
|
|
|
{
|
|
|
|
QStringList modNames;
|
2024-11-15 18:17:31 +02:00
|
|
|
QStringList modsToEnable;
|
2013-08-22 17:22:49 +03:00
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
for(QString archive : archives)
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
|
|
|
// get basename out of full file name
|
|
|
|
// remove path remove extension
|
|
|
|
QString modName = archive.section('/', -1, -1).section('.', 0, 0);
|
|
|
|
|
|
|
|
modNames.push_back(modName);
|
|
|
|
}
|
|
|
|
|
|
|
|
// uninstall old version of mod, if installed
|
2024-11-15 15:25:36 +02:00
|
|
|
for(QString mod : modNames)
|
2013-09-06 00:25:03 +03:00
|
|
|
{
|
2024-11-12 22:00:21 +02:00
|
|
|
if(modStateModel->getMod(mod).isInstalled())
|
2024-11-15 18:17:31 +02:00
|
|
|
{
|
2024-11-20 00:15:05 +02:00
|
|
|
if (modStateModel->isModEnabled(mod))
|
|
|
|
modsToEnable.push_back(mod);
|
|
|
|
|
2013-09-06 00:25:03 +03:00
|
|
|
manager->uninstallMod(mod);
|
2024-11-15 18:17:31 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// installation of previously not present mod -> enable it
|
2024-11-20 00:15:05 +02:00
|
|
|
modsToEnable.push_back(mod);
|
2024-11-15 18:17:31 +02:00
|
|
|
}
|
2013-09-06 00:25:03 +03:00
|
|
|
}
|
2013-08-22 17:22:49 +03:00
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
for(int i = 0; i < modNames.size(); i++)
|
2023-09-19 23:38:00 +02:00
|
|
|
{
|
|
|
|
ui->progressBar->setFormat(tr("Installing mod %1").arg(modNames[i]));
|
2013-08-22 17:22:49 +03:00
|
|
|
manager->installMod(modNames[i], archives[i]);
|
2023-09-19 23:38:00 +02:00
|
|
|
}
|
2013-08-22 17:22:49 +03:00
|
|
|
|
2024-12-04 13:16:05 +02:00
|
|
|
if (!modsToEnable.empty())
|
|
|
|
manager->enableMods(modsToEnable);
|
2013-08-22 17:22:49 +03:00
|
|
|
|
2023-09-11 17:10:07 +02:00
|
|
|
checkManagerErrors();
|
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
for(QString archive : archives)
|
2013-08-22 17:22:49 +03:00
|
|
|
QFile::remove(archive);
|
|
|
|
}
|
|
|
|
|
2023-12-25 23:41:15 +02:00
|
|
|
void CModListView::installMaps(QStringList maps)
|
2023-12-25 19:53:02 +02:00
|
|
|
{
|
2024-02-06 00:33:47 +02:00
|
|
|
const auto destDir = CLauncherDirs::mapsPath() + QChar{'/'};
|
2023-12-25 19:53:02 +02:00
|
|
|
|
2023-12-25 23:41:15 +02:00
|
|
|
for(QString map : maps)
|
2023-12-25 19:53:02 +02:00
|
|
|
{
|
2023-12-25 23:41:15 +02:00
|
|
|
QFile(map).rename(destDir + map.section('/', -1, -1));
|
2023-12-25 19:53:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-03 17:47:37 +02:00
|
|
|
void CModListView::on_refreshButton_clicked()
|
|
|
|
{
|
|
|
|
loadRepositories();
|
|
|
|
}
|
|
|
|
|
2013-08-22 17:22:49 +03:00
|
|
|
void CModListView::on_pushButton_clicked()
|
|
|
|
{
|
|
|
|
delete dlManager;
|
|
|
|
dlManager = nullptr;
|
|
|
|
hideProgressBar();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CModListView::modelReset()
|
|
|
|
{
|
2023-01-26 01:01:41 +02:00
|
|
|
selectMod(filterModel->rowCount() > 0 ? filterModel->index(0, 0) : QModelIndex());
|
2013-08-24 23:11:51 +03:00
|
|
|
}
|
2013-09-06 00:25:03 +03:00
|
|
|
|
|
|
|
void CModListView::checkManagerErrors()
|
|
|
|
{
|
|
|
|
QString errors = manager->getErrors().join('\n');
|
2018-04-13 07:34:58 +02:00
|
|
|
if(errors.size() != 0)
|
2013-09-06 00:25:03 +03:00
|
|
|
{
|
2023-09-01 22:18:23 +02:00
|
|
|
QString title = tr("Operation failed");
|
|
|
|
QString description = tr("Encountered errors:\n") + errors;
|
2018-04-13 07:34:58 +02:00
|
|
|
QMessageBox::warning(this, title, description, QMessageBox::Ok, QMessageBox::Ok);
|
2013-09-06 00:25:03 +03:00
|
|
|
}
|
|
|
|
}
|
2014-03-23 15:08:01 +03:00
|
|
|
|
|
|
|
void CModListView::on_tabWidget_currentChanged(int index)
|
|
|
|
{
|
|
|
|
loadScreenshots();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CModListView::loadScreenshots()
|
|
|
|
{
|
2023-01-26 01:01:41 +02:00
|
|
|
if(ui->tabWidget->currentIndex() == 2)
|
2014-03-23 15:08:01 +03:00
|
|
|
{
|
2024-07-19 12:38:42 +02:00
|
|
|
if(!ui->allModsView->currentIndex().isValid())
|
2024-07-18 22:28:47 +02:00
|
|
|
{
|
|
|
|
// select the first mod, so we can access its data
|
|
|
|
ui->allModsView->setCurrentIndex(filterModel->index(0, 0));
|
|
|
|
}
|
|
|
|
|
2014-03-23 15:08:01 +03:00
|
|
|
ui->screenshotsList->clear();
|
|
|
|
QString modName = ui->allModsView->currentIndex().data(ModRoles::ModNameRole).toString();
|
2024-11-12 22:00:21 +02:00
|
|
|
assert(modStateModel->isModExists(modName)); //should be filtered out by check above
|
2014-03-23 15:08:01 +03:00
|
|
|
|
2024-11-12 22:00:21 +02:00
|
|
|
for(QString url : modStateModel->getMod(modName).getScreenshots())
|
2014-03-23 15:08:01 +03:00
|
|
|
{
|
|
|
|
// URL must be encoded to something else to get rid of symbols illegal in file names
|
2024-02-06 00:33:47 +02:00
|
|
|
const auto hashed = QCryptographicHash::hash(url.toUtf8(), QCryptographicHash::Md5);
|
|
|
|
const auto fileName = QString{QLatin1String{"%1.png"}}.arg(QLatin1String{hashed.toHex()});
|
2014-03-23 15:08:01 +03:00
|
|
|
|
2024-02-06 00:33:47 +02:00
|
|
|
const auto fullPath = QString{QLatin1String{"%1/%2"}}.arg(CLauncherDirs::downloadsPath(), fileName);
|
2014-03-23 15:08:01 +03:00
|
|
|
QPixmap pixmap(fullPath);
|
2018-04-13 07:34:58 +02:00
|
|
|
if(pixmap.isNull())
|
2014-03-23 15:08:01 +03:00
|
|
|
{
|
|
|
|
// image file not exists or corrupted - try to redownload
|
2024-05-01 11:43:20 +02:00
|
|
|
downloadFile(fileName, url, tr("screenshots"));
|
2014-03-23 15:08:01 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// managed to load cached image
|
|
|
|
QIcon icon(pixmap);
|
2024-01-16 23:40:48 +02:00
|
|
|
auto * item = new QListWidgetItem(icon, QString(tr("Screenshot %1")).arg(ui->screenshotsList->count() + 1));
|
2014-03-23 15:08:01 +03:00
|
|
|
ui->screenshotsList->addItem(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
void CModListView::on_screenshotsList_clicked(const QModelIndex & index)
|
2014-03-23 15:08:01 +03:00
|
|
|
{
|
2018-04-13 07:34:58 +02:00
|
|
|
if(index.isValid())
|
2014-03-23 15:08:01 +03:00
|
|
|
{
|
|
|
|
QIcon icon = ui->screenshotsList->item(index.row())->icon();
|
|
|
|
auto pixmap = icon.pixmap(icon.availableSizes()[0]);
|
|
|
|
ImageViewer::showPixmap(pixmap, this);
|
|
|
|
}
|
|
|
|
}
|
2014-08-04 14:03:57 +03:00
|
|
|
|
2023-03-11 00:57:55 +02:00
|
|
|
void CModListView::doInstallMod(const QString & modName)
|
|
|
|
{
|
2024-12-10 15:59:29 +02:00
|
|
|
for(const auto & name : getModsToInstall(modName))
|
2023-03-11 00:57:55 +02:00
|
|
|
{
|
2024-11-12 22:00:21 +02:00
|
|
|
auto mod = modStateModel->getMod(name);
|
2024-12-10 15:59:29 +02:00
|
|
|
if(mod.isAvailable())
|
2024-12-10 15:38:13 +02:00
|
|
|
downloadMod(mod);
|
2024-12-10 15:59:29 +02:00
|
|
|
else if(!modStateModel->isModEnabled(name))
|
|
|
|
enableModByName(name);
|
2023-03-11 00:57:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-26 19:11:59 +02:00
|
|
|
bool CModListView::isModAvailable(const QString & modName)
|
2023-03-11 00:57:55 +02:00
|
|
|
{
|
2024-11-12 22:00:21 +02:00
|
|
|
return !modStateModel->isModInstalled(modName);
|
2023-03-11 00:57:55 +02:00
|
|
|
}
|
|
|
|
|
2023-03-14 13:37:22 +02:00
|
|
|
bool CModListView::isModEnabled(const QString & modName)
|
|
|
|
{
|
2024-11-14 20:43:41 +02:00
|
|
|
return modStateModel->isModEnabled(modName);
|
2023-03-14 13:37:22 +02:00
|
|
|
}
|
|
|
|
|
2024-09-14 21:34:39 +02:00
|
|
|
bool CModListView::isModInstalled(const QString & modName)
|
|
|
|
{
|
2024-11-12 22:00:21 +02:00
|
|
|
auto mod = modStateModel->getMod(modName);
|
2024-09-14 21:34:39 +02:00
|
|
|
return mod.isInstalled();
|
|
|
|
}
|
|
|
|
|
2024-12-04 22:56:34 +02:00
|
|
|
QStringList CModListView::getInstalledChronicles()
|
|
|
|
{
|
|
|
|
QStringList result;
|
|
|
|
|
|
|
|
for(const auto & modName : modStateModel->getAllMods())
|
|
|
|
{
|
|
|
|
auto mod = modStateModel->getMod(modName);
|
|
|
|
if (!mod.isInstalled())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (mod.getTopParentID() != "chronicles")
|
|
|
|
continue;
|
|
|
|
|
|
|
|
result += modName;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-05 00:53:07 +02:00
|
|
|
QStringList CModListView::getUpdateableMods()
|
|
|
|
{
|
|
|
|
QStringList result;
|
|
|
|
|
|
|
|
for(const auto & modName : modStateModel->getAllMods())
|
|
|
|
{
|
|
|
|
auto mod = modStateModel->getMod(modName);
|
|
|
|
if (mod.isUpdateAvailable())
|
|
|
|
result.push_back(modName);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-03-11 00:57:55 +02:00
|
|
|
QString CModListView::getTranslationModName(const QString & language)
|
|
|
|
{
|
2024-11-12 22:00:21 +02:00
|
|
|
for(const auto & modName : modStateModel->getAllMods())
|
2023-03-11 00:57:55 +02:00
|
|
|
{
|
2024-11-12 22:00:21 +02:00
|
|
|
auto mod = modStateModel->getMod(modName);
|
2023-03-11 00:57:55 +02:00
|
|
|
|
2023-03-14 15:59:33 +02:00
|
|
|
if (!mod.isTranslation())
|
2023-03-11 00:57:55 +02:00
|
|
|
continue;
|
|
|
|
|
2024-11-12 22:00:21 +02:00
|
|
|
if (mod.getBaseLanguage() != language)
|
2023-03-11 00:57:55 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
return modName;
|
|
|
|
}
|
|
|
|
|
|
|
|
return QString();
|
|
|
|
}
|
2023-09-01 01:29:50 +02:00
|
|
|
|
|
|
|
void CModListView::on_allModsView_doubleClicked(const QModelIndex &index)
|
|
|
|
{
|
|
|
|
if(!index.isValid())
|
|
|
|
return;
|
2023-09-01 15:40:52 +02:00
|
|
|
|
|
|
|
auto modName = index.data(ModRoles::ModNameRole).toString();
|
2024-11-12 22:00:21 +02:00
|
|
|
auto mod = modStateModel->getMod(modName);
|
2023-09-01 15:40:52 +02:00
|
|
|
|
2024-11-20 17:24:52 +02:00
|
|
|
QStringList notInstalledDependencies = this->getModsToInstall(mod.getID());
|
|
|
|
QStringList unavailableDependencies = this->findUnavailableMods(notInstalledDependencies);
|
|
|
|
|
|
|
|
if(unavailableDependencies.empty() && mod.isAvailable() && !mod.isSubmod())
|
2023-09-01 01:29:50 +02:00
|
|
|
{
|
|
|
|
on_installButton_clicked();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-11-20 17:24:52 +02:00
|
|
|
if(unavailableDependencies.empty() && mod.isUpdateAvailable() && index.column() == ModFields::STATUS_UPDATE)
|
2023-09-01 01:29:50 +02:00
|
|
|
{
|
|
|
|
on_updateButton_clicked();
|
2023-09-01 15:40:52 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(index.column() == ModFields::NAME)
|
|
|
|
{
|
|
|
|
if(ui->allModsView->isExpanded(index))
|
|
|
|
ui->allModsView->collapse(index);
|
|
|
|
else
|
|
|
|
ui->allModsView->expand(index);
|
|
|
|
|
|
|
|
return;
|
2023-09-01 01:29:50 +02:00
|
|
|
}
|
|
|
|
|
2024-11-20 17:24:52 +02:00
|
|
|
if(notInstalledDependencies.empty() && !modStateModel->isModEnabled(modName))
|
2023-09-01 01:29:50 +02:00
|
|
|
{
|
|
|
|
on_enableButton_clicked();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-11-18 19:37:45 +02:00
|
|
|
if(modStateModel->isModEnabled(modName))
|
2023-09-01 01:29:50 +02:00
|
|
|
{
|
|
|
|
on_disableButton_clicked();
|
2023-09-01 15:40:52 +02:00
|
|
|
return;
|
2023-09-01 01:29:50 +02:00
|
|
|
}
|
|
|
|
}
|
2024-12-08 22:56:19 +02:00
|
|
|
|
|
|
|
void CModListView::createNewPreset(const QString & presetName)
|
|
|
|
{
|
|
|
|
modStateModel->createNewPreset(presetName);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CModListView::deletePreset(const QString & presetName)
|
|
|
|
{
|
|
|
|
modStateModel->deletePreset(presetName);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CModListView::activatePreset(const QString & presetName)
|
|
|
|
{
|
|
|
|
modStateModel->activatePreset(presetName);
|
|
|
|
modStateModel->reloadLocalState();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CModListView::renamePreset(const QString & oldPresetName, const QString & newPresetName)
|
|
|
|
{
|
|
|
|
modStateModel->renamePreset(oldPresetName, newPresetName);
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList CModListView::getAllPresets() const
|
|
|
|
{
|
|
|
|
return modStateModel->getAllPresets();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString CModListView::getActivePreset() const
|
|
|
|
{
|
|
|
|
return modStateModel->getActivePreset();
|
|
|
|
}
|