Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/aotextarea.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "aotextarea.h"

#include "aoutils.h"

AOTextArea::AOTextArea(QWidget *parent)
: AOTextArea(5000, parent)
{}
Expand Down Expand Up @@ -27,7 +29,7 @@ void AOTextArea::addMessage(QString name, QString message, QString nameColor, QS
message += " ";
}

QString result = message.toHtmlEscaped().replace("\n", "<br>").replace(url_parser_regex, "<a href='\\1'>\\1</a>");
QString result = AOUtils::convert_to_html(message);

if (!messageColor.isEmpty())
{
Expand Down
3 changes: 0 additions & 3 deletions src/aotextarea.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include <QDebug>
#include <QRegularExpression>
#include <QScrollBar>
#include <QTextBrowser>
#include <QTextCursor>
Expand All @@ -17,7 +16,5 @@ class AOTextArea : public QTextBrowser
void addMessage(QString name, QString message, QString nameColor, QString messageColor = QString());

private:
const QRegularExpression url_parser_regex = QRegularExpression("\\b(https?://\\S+\\.\\S+)\\b");

void auto_scroll(QTextCursor old_cursor, int scrollbar_value, bool is_scrolled_down);
};
6 changes: 6 additions & 0 deletions src/aoutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,9 @@ void AOUtils::migrateEffects(QSettings &p_effects_ini)
}
p_effects_ini.sync();
}

QString AOUtils::convert_to_html(const QString &p_text)
{
static const QRegularExpression url_regex(QStringLiteral("\\b(https?://\\S+)"));
return p_text.toHtmlEscaped().replace(url_regex, "<a href=\"\\1\">\\1</a>").replace("\n", "<br>");
}
6 changes: 6 additions & 0 deletions src/aoutils.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <QSettings>
#include <QString>

namespace AOUtils
{
Expand All @@ -9,4 +10,9 @@ namespace AOUtils
* @param QSettings object reference of the old effects.ini
*/
void migrateEffects(QSettings &p_fileName);

/**
* @brief Converts plain text to HTML and turns any URLs into links
*/
QString convert_to_html(const QString &p_text);
}; // namespace AOUtils
9 changes: 3 additions & 6 deletions src/lobby.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "lobby.h"

#include "aoapplication.h"
#include "aoutils.h"
#include "demoserver.h"
#include "gui_utils.h"
#include "networkmanager.h"
Expand Down Expand Up @@ -568,13 +569,11 @@ void Lobby::check_for_updates()
QVersionNumber current_version = QVersionNumber::fromString(ao_app->get_version_string());
QVersionNumber master_version = QVersionNumber::fromString(version);

static QRegularExpression regexp_links("\\b(https?://\\S+\\.\\S+)\\b");

if (current_version < master_version)
{
ui_game_version_lbl->setText(tr("Version: %1 [OUTDATED]").arg(current_version.toString()));
setWindowTitle(tr("[Your client is outdated]"));
const QString download_url = QString("https://github.com/AttorneyOnline/AO2-Client/releases/latest").replace(regexp_links, "<a href='\\1'>\\1</a>");
const QString download_url = AOUtils::convert_to_html(QStringLiteral("https://github.com/AttorneyOnline/AO2-Client/releases/latest"));
const QString message = QString("Your client is outdated!<br>Your Version: %1<br>Current Version: %2<br>Download the latest version at<br>%3").arg(current_version.toString(), master_version.toString(), download_url);
QMessageBox::warning(this, "Your client is outdated!", message);
}
Expand All @@ -590,9 +589,7 @@ void Lobby::set_player_count(int players_online, int max_players)
void Lobby::set_server_description(const QString &server_description)
{
ui_server_description_text->clear();
static QRegularExpression regexp_links("\\b(https?://\\S+\\.\\S+)\\b");
QString result = server_description.toHtmlEscaped().replace("\n", "<br>").replace(regexp_links, "<a href='\\1'>\\1</a>");
ui_server_description_text->insertHtml(result);
ui_server_description_text->insertHtml(AOUtils::convert_to_html(server_description));
}

Lobby::~Lobby()
Expand Down
Loading