automatically convert hedgewars.org urls to actual links (in order to make support in the lobby/rooms easier
authorsheepluva
Tue, 01 Feb 2011 08:15:01 +0100
changeset 4899 8163c9aaad0c
parent 4898 7a94005874c9
child 4900 8ad0e23e6d63
automatically convert hedgewars.org urls to actual links (in order to make support in the lobby/rooms easier
QTfrontend/chatwidget.cpp
QTfrontend/chatwidget.h
--- a/QTfrontend/chatwidget.cpp	Tue Feb 01 07:52:50 2011 +0100
+++ b/QTfrontend/chatwidget.cpp	Tue Feb 01 08:15:01 2011 +0100
@@ -325,6 +325,8 @@
     onChatString("", str);
 }
 
+const QRegExp HWChatWidget::URLREGEXP = QRegExp("(http://)?(www\\.)?(hedgewars\\.org(/[^ ]*)?)");
+
 void HWChatWidget::onChatString(const QString& nick, const QString& str)
 {
     bool isFriend = false;
@@ -341,6 +343,8 @@
         chatStrings.removeFirst();
 
     QString formattedStr = Qt::escape(str.mid(1));
+    // make hedgewars.org urls actual links
+    formattedStr = formattedStr.replace(URLREGEXP, "<a href=\"http://\\3\">\\3</a>");
 
     // "link" nick, but before that encode it in base64 to make sure it can't intefere with html/url syntax
     // the nick is put as querystring as putting it as host would convert it to it's lower case variant
--- a/QTfrontend/chatwidget.h	Tue Feb 01 07:52:50 2011 +0100
+++ b/QTfrontend/chatwidget.h	Tue Feb 01 08:15:01 2011 +0100
@@ -23,6 +23,7 @@
 #include <QListWidget>
 #include <QString>
 #include <QGridLayout>
+#include <QRegExp>
 
 #include "SDLs.h"
 
@@ -66,6 +67,7 @@
   void saveList(QStringList & list, const QString & file);
   void updateNickItem(QListWidgetItem *item);
   void updateNickItems();
+  static const QRegExp URLREGEXP;
 
  public slots:
   void onChatString(const QString& str);