diff --git a/src/aotextarea.cpp b/src/aotextarea.cpp
index 08885da80..f5486c009 100644
--- a/src/aotextarea.cpp
+++ b/src/aotextarea.cpp
@@ -1,5 +1,7 @@
#include "aotextarea.h"
+#include "aoutils.h"
+
AOTextArea::AOTextArea(QWidget *parent)
: AOTextArea(5000, parent)
{}
@@ -27,7 +29,7 @@ void AOTextArea::addMessage(QString name, QString message, QString nameColor, QS
message += " ";
}
- QString result = message.toHtmlEscaped().replace("\n", "
").replace(url_parser_regex, "\\1");
+ QString result = AOUtils::convert_to_html(message);
if (!messageColor.isEmpty())
{
diff --git a/src/aotextarea.h b/src/aotextarea.h
index b24ab2db0..dda7651cf 100644
--- a/src/aotextarea.h
+++ b/src/aotextarea.h
@@ -1,7 +1,6 @@
#pragma once
#include
-#include
#include
#include
#include
@@ -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);
};
diff --git a/src/aoutils.cpp b/src/aoutils.cpp
index f384b81b4..5d5d70dcc 100644
--- a/src/aoutils.cpp
+++ b/src/aoutils.cpp
@@ -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, "\\1").replace("\n", "
");
+}
diff --git a/src/aoutils.h b/src/aoutils.h
index 1fe03fd57..20ea4332d 100644
--- a/src/aoutils.h
+++ b/src/aoutils.h
@@ -1,6 +1,7 @@
#pragma once
#include
+#include
namespace AOUtils
{
@@ -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
diff --git a/src/lobby.cpp b/src/lobby.cpp
index c39979f07..c019135d6 100644
--- a/src/lobby.cpp
+++ b/src/lobby.cpp
@@ -1,6 +1,7 @@
#include "lobby.h"
#include "aoapplication.h"
+#include "aoutils.h"
#include "demoserver.h"
#include "gui_utils.h"
#include "networkmanager.h"
@@ -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, "\\1");
+ 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!
Your Version: %1
Current Version: %2
Download the latest version at
%3").arg(current_version.toString(), master_version.toString(), download_url);
QMessageBox::warning(this, "Your client is outdated!", message);
}
@@ -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", "
").replace(regexp_links, "\\1");
- ui_server_description_text->insertHtml(result);
+ ui_server_description_text->insertHtml(AOUtils::convert_to_html(server_description));
}
Lobby::~Lobby()