From f8df07c3272c0e02f31f46fda8a429292c7a446a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Thu, 6 Feb 2014 09:32:44 +0100 Subject: Small tweaks to make things better. --- logic/MinecraftProcess.cpp | 2 ++ logic/Mod.cpp | 21 ++++++++++++++++----- logic/ModList.cpp | 27 +++++++++++++++++++-------- logic/ModList.h | 1 + 4 files changed, 38 insertions(+), 13 deletions(-) (limited to 'logic') diff --git a/logic/MinecraftProcess.cpp b/logic/MinecraftProcess.cpp index 9c0a7074..70a9d55f 100644 --- a/logic/MinecraftProcess.cpp +++ b/logic/MinecraftProcess.cpp @@ -113,6 +113,8 @@ MessageLevel::Enum MinecraftProcess::guessLevel(const QString &line, MessageLeve level = MessageLevel::Fatal; if (line.contains("[DEBUG]")) level = MessageLevel::Debug; + if(line.contains("overwriting existing")) + level = MessageLevel::Fatal; return level; } diff --git a/logic/Mod.cpp b/logic/Mod.cpp index 6732446d..22ac36c8 100644 --- a/logic/Mod.cpp +++ b/logic/Mod.cpp @@ -164,6 +164,16 @@ void Mod::ReadMCModInfo(QByteArray contents) m_name = firstObj.value("name").toString(); m_version = firstObj.value("version").toString(); m_homeurl = firstObj.value("url").toString(); + m_homeurl = m_homeurl.trimmed(); + if(!m_homeurl.isEmpty()) + { + // fix up url. + if (!m_homeurl.startsWith("http://") && !m_homeurl.startsWith("https://") && + !m_homeurl.startsWith("ftp://")) + { + m_homeurl.prepend("http://"); + } + } m_description = firstObj.value("description").toString(); QJsonArray authors = firstObj.value("authors").toArray(); if (authors.size() == 0) @@ -178,7 +188,8 @@ void Mod::ReadMCModInfo(QByteArray contents) } m_credits = firstObj.value("credits").toString(); return; - }; + } + ; QJsonParseError jsonError; QJsonDocument jsonDoc = QJsonDocument::fromJson(contents, &jsonError); // this is the very old format that had just the array @@ -227,17 +238,17 @@ void Mod::ReadLiteModInfo(QByteArray contents) QJsonParseError jsonError; QJsonDocument jsonDoc = QJsonDocument::fromJson(contents, &jsonError); auto object = jsonDoc.object(); - if(object.contains("name")) + if (object.contains("name")) { m_mod_id = m_name = object.value("name").toString(); } - if(object.contains("version")) + if (object.contains("version")) { - m_version=object.value("version").toString(""); + m_version = object.value("version").toString(""); } else { - m_version=object.value("revision").toString(""); + m_version = object.value("revision").toString(""); } m_mcversion = object.value("mcversion").toString(); m_authors = object.value("author").toString(); diff --git a/logic/ModList.cpp b/logic/ModList.cpp index 499623bf..79b56986 100644 --- a/logic/ModList.cpp +++ b/logic/ModList.cpp @@ -62,6 +62,19 @@ void ModList::stopWatching() } } +void ModList::internalSort(QList &what) +{ + auto predicate = [](const Mod & left, const Mod & right) + { + if (left.name() == right.name()) + { + return left.mmc_id().localeAwareCompare(right.mmc_id()) <= 0; + } + return left.name().localeAwareCompare(right.name()) <= 0; + }; + std::sort(what.begin(), what.end(), predicate); +} + bool ModList::update() { if (!isValid()) @@ -98,7 +111,7 @@ bool ModList::update() isEnabled = idxEnabled >= 0; } int idx = isEnabled ? idxEnabled : idxDisabled; - QFileInfo & info = isEnabled ? infoEnabled : infoDisabled; + QFileInfo &info = isEnabled ? infoEnabled : infoDisabled; // if the file from the index file exists if (idx != -1) { @@ -122,8 +135,7 @@ bool ModList::update() { newMods.append(Mod(entry)); } - std::sort(newMods.begin(), newMods.end(), [](const Mod & left, const Mod & right) - { return left.name().localeAwareCompare(right.name()) <= 0; }); + internalSort(newMods); orderedMods.append(newMods); orderOrStateChanged = true; } @@ -236,8 +248,8 @@ bool ModList::installMod(const QFileInfo &filename, int index) int idx = mods.indexOf(m); if (idx != -1) { - int idx2 = mods.indexOf(m,idx+1); - if(idx2 != -1) + int idx2 = mods.indexOf(m, idx + 1); + if (idx2 != -1) return false; if (mods[idx].replace(m)) { @@ -416,7 +428,7 @@ QVariant ModList::data(const QModelIndex &index, int role) const switch (index.column()) { case ActiveColumn: - return mods[row].enabled() ? Qt::Checked: Qt::Unchecked; + return mods[row].enabled() ? Qt::Checked : Qt::Unchecked; default: return QVariant(); } @@ -567,8 +579,7 @@ bool ModList::dropMimeData(const QMimeData *data, Qt::DropAction action, int row if (m_list_file.isEmpty()) { beginResetModel(); - std::sort(mods.begin(), mods.end(), [](const Mod & left, const Mod & right) - { return left.name().localeAwareCompare(right.name()) <= 0; }); + internalSort(mods); endResetModel(); } } diff --git a/logic/ModList.h b/logic/ModList.h index 0d6507fb..95f52061 100644 --- a/logic/ModList.h +++ b/logic/ModList.h @@ -127,6 +127,7 @@ public: } private: + void internalSort(QList & what); struct OrderItem { QString id; -- cgit v1.2.3