Small tweaks to make things better.

This commit is contained in:
Petr Mrázek 2014-02-06 09:32:44 +01:00
parent b4b6091372
commit f8df07c327
6 changed files with 49 additions and 22 deletions

View File

@ -84,7 +84,7 @@ void ConsoleWindow::iconActivated(QSystemTrayIcon::ActivationReason reason)
} }
} }
void ConsoleWindow::writeColor(QString text, const char *color) void ConsoleWindow::writeColor(QString text, const char *color, const char * background)
{ {
// append a paragraph // append a paragraph
QString newtext; QString newtext;
@ -92,6 +92,8 @@ void ConsoleWindow::writeColor(QString text, const char *color)
{ {
if (color) if (color)
newtext += QString("color:") + color + ";"; newtext += QString("color:") + color + ";";
if (background)
newtext += QString("background-color:") + background + ";";
newtext += "font-family: monospace;"; newtext += "font-family: monospace;";
} }
newtext += "\">"; newtext += "\">";
@ -127,26 +129,26 @@ void ConsoleWindow::write(QString data, MessageLevel::Enum mode)
QListIterator<QString> iter(paragraphs); QListIterator<QString> iter(paragraphs);
if (mode == MessageLevel::MultiMC) if (mode == MessageLevel::MultiMC)
while (iter.hasNext()) while (iter.hasNext())
writeColor(iter.next(), "blue"); writeColor(iter.next(), "blue", 0);
else if (mode == MessageLevel::Error) else if (mode == MessageLevel::Error)
while (iter.hasNext()) while (iter.hasNext())
writeColor(iter.next(), "red"); writeColor(iter.next(), "red", 0);
else if (mode == MessageLevel::Warning) else if (mode == MessageLevel::Warning)
while (iter.hasNext()) while (iter.hasNext())
writeColor(iter.next(), "orange"); writeColor(iter.next(), "orange", 0);
else if (mode == MessageLevel::Fatal) else if (mode == MessageLevel::Fatal)
while (iter.hasNext()) while (iter.hasNext())
writeColor(iter.next(), "pink"); writeColor(iter.next(), "red", "black");
else if (mode == MessageLevel::Debug) else if (mode == MessageLevel::Debug)
while (iter.hasNext()) while (iter.hasNext())
writeColor(iter.next(), "green"); writeColor(iter.next(), "green", 0);
else if (mode == MessageLevel::PrePost) else if (mode == MessageLevel::PrePost)
while (iter.hasNext()) while (iter.hasNext())
writeColor(iter.next(), "grey"); writeColor(iter.next(), "grey", 0);
// TODO: implement other MessageLevels // TODO: implement other MessageLevels
else else
while (iter.hasNext()) while (iter.hasNext())
writeColor(iter.next()); writeColor(iter.next(), 0, 0);
if(isVisible()) if(isVisible())
{ {
if (m_scroll_active) if (m_scroll_active)

View File

@ -47,7 +47,7 @@ private:
* this will only insert a single paragraph. * this will only insert a single paragraph.
* \n are ignored. a real \n is always appended. * \n are ignored. a real \n is always appended.
*/ */
void writeColor(QString data, const char *color = nullptr); void writeColor(QString text, const char *color, const char *background);
signals: signals:
void isClosing(); void isClosing();

View File

@ -113,6 +113,8 @@ MessageLevel::Enum MinecraftProcess::guessLevel(const QString &line, MessageLeve
level = MessageLevel::Fatal; level = MessageLevel::Fatal;
if (line.contains("[DEBUG]")) if (line.contains("[DEBUG]"))
level = MessageLevel::Debug; level = MessageLevel::Debug;
if(line.contains("overwriting existing"))
level = MessageLevel::Fatal;
return level; return level;
} }

View File

@ -164,6 +164,16 @@ void Mod::ReadMCModInfo(QByteArray contents)
m_name = firstObj.value("name").toString(); m_name = firstObj.value("name").toString();
m_version = firstObj.value("version").toString(); m_version = firstObj.value("version").toString();
m_homeurl = firstObj.value("url").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(); m_description = firstObj.value("description").toString();
QJsonArray authors = firstObj.value("authors").toArray(); QJsonArray authors = firstObj.value("authors").toArray();
if (authors.size() == 0) if (authors.size() == 0)
@ -178,7 +188,8 @@ void Mod::ReadMCModInfo(QByteArray contents)
} }
m_credits = firstObj.value("credits").toString(); m_credits = firstObj.value("credits").toString();
return; return;
}; }
;
QJsonParseError jsonError; QJsonParseError jsonError;
QJsonDocument jsonDoc = QJsonDocument::fromJson(contents, &jsonError); QJsonDocument jsonDoc = QJsonDocument::fromJson(contents, &jsonError);
// this is the very old format that had just the array // this is the very old format that had just the array
@ -227,17 +238,17 @@ void Mod::ReadLiteModInfo(QByteArray contents)
QJsonParseError jsonError; QJsonParseError jsonError;
QJsonDocument jsonDoc = QJsonDocument::fromJson(contents, &jsonError); QJsonDocument jsonDoc = QJsonDocument::fromJson(contents, &jsonError);
auto object = jsonDoc.object(); auto object = jsonDoc.object();
if(object.contains("name")) if (object.contains("name"))
{ {
m_mod_id = m_name = object.value("name").toString(); 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 else
{ {
m_version=object.value("revision").toString(""); m_version = object.value("revision").toString("");
} }
m_mcversion = object.value("mcversion").toString(); m_mcversion = object.value("mcversion").toString();
m_authors = object.value("author").toString(); m_authors = object.value("author").toString();

View File

@ -62,6 +62,19 @@ void ModList::stopWatching()
} }
} }
void ModList::internalSort(QList<Mod> &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() bool ModList::update()
{ {
if (!isValid()) if (!isValid())
@ -98,7 +111,7 @@ bool ModList::update()
isEnabled = idxEnabled >= 0; isEnabled = idxEnabled >= 0;
} }
int idx = isEnabled ? idxEnabled : idxDisabled; int idx = isEnabled ? idxEnabled : idxDisabled;
QFileInfo & info = isEnabled ? infoEnabled : infoDisabled; QFileInfo &info = isEnabled ? infoEnabled : infoDisabled;
// if the file from the index file exists // if the file from the index file exists
if (idx != -1) if (idx != -1)
{ {
@ -122,8 +135,7 @@ bool ModList::update()
{ {
newMods.append(Mod(entry)); newMods.append(Mod(entry));
} }
std::sort(newMods.begin(), newMods.end(), [](const Mod & left, const Mod & right) internalSort(newMods);
{ return left.name().localeAwareCompare(right.name()) <= 0; });
orderedMods.append(newMods); orderedMods.append(newMods);
orderOrStateChanged = true; orderOrStateChanged = true;
} }
@ -236,8 +248,8 @@ bool ModList::installMod(const QFileInfo &filename, int index)
int idx = mods.indexOf(m); int idx = mods.indexOf(m);
if (idx != -1) if (idx != -1)
{ {
int idx2 = mods.indexOf(m,idx+1); int idx2 = mods.indexOf(m, idx + 1);
if(idx2 != -1) if (idx2 != -1)
return false; return false;
if (mods[idx].replace(m)) if (mods[idx].replace(m))
{ {
@ -416,7 +428,7 @@ QVariant ModList::data(const QModelIndex &index, int role) const
switch (index.column()) switch (index.column())
{ {
case ActiveColumn: case ActiveColumn:
return mods[row].enabled() ? Qt::Checked: Qt::Unchecked; return mods[row].enabled() ? Qt::Checked : Qt::Unchecked;
default: default:
return QVariant(); return QVariant();
} }
@ -567,8 +579,7 @@ bool ModList::dropMimeData(const QMimeData *data, Qt::DropAction action, int row
if (m_list_file.isEmpty()) if (m_list_file.isEmpty())
{ {
beginResetModel(); beginResetModel();
std::sort(mods.begin(), mods.end(), [](const Mod & left, const Mod & right) internalSort(mods);
{ return left.name().localeAwareCompare(right.name()) <= 0; });
endResetModel(); endResetModel();
} }
} }

View File

@ -127,6 +127,7 @@ public:
} }
private: private:
void internalSort(QList<Mod> & what);
struct OrderItem struct OrderItem
{ {
QString id; QString id;