QTfrontend/ui/widget/chatwidget.cpp
branchqt5transition
changeset 12897 fc47fc4af6bd
parent 11865 047be82b6f67
child 13513 7e188a28f078
equal deleted inserted replaced
12896:8869b5256720 12897:fc47fc4af6bd
    30 #include <QListView>
    30 #include <QListView>
    31 #include <QModelIndexList>
    31 #include <QModelIndexList>
    32 #include <QSortFilterProxyModel>
    32 #include <QSortFilterProxyModel>
    33 #include <QMenu>
    33 #include <QMenu>
    34 #include <QScrollBar>
    34 #include <QScrollBar>
       
    35 #include <QMimeData>
    35 
    36 
    36 #include "DataManager.h"
    37 #include "DataManager.h"
    37 #include "hwconsts.h"
    38 #include "hwconsts.h"
    38 #include "gameuiconfig.h"
    39 #include "gameuiconfig.h"
    39 #include "playerslistmodel.h"
    40 #include "playerslistmodel.h"
   310     if ((link.scheme() == "http") or (link.scheme() == "https"))
   311     if ((link.scheme() == "http") or (link.scheme() == "https"))
   311         QDesktopServices::openUrl(link);
   312         QDesktopServices::openUrl(link);
   312     else if (link.scheme() == "hwnick")
   313     else if (link.scheme() == "hwnick")
   313     {
   314     {
   314         // decode nick
   315         // decode nick
   315         QString nick = QString::fromUtf8(QByteArray::fromBase64(link.encodedQuery()));
   316         QString nick = QString::fromUtf8(QByteArray::fromBase64(link.query(QUrl::FullyDecoded).toLatin1()));
   316         QModelIndexList mil = chatNicks->model()->match(chatNicks->model()->index(0, 0), Qt::DisplayRole, nick);
   317         QModelIndexList mil = chatNicks->model()->match(chatNicks->model()->index(0, 0), Qt::DisplayRole, nick);
   317 
   318 
   318         bool isOffline = (mil.size() < 1);
   319         bool isOffline = (mil.size() < 1);
   319 
   320 
   320         if (isOffline)
   321         if (isOffline)
   372 // it as host would convert it to it's lower case variant
   373 // it as host would convert it to it's lower case variant
   373 QString HWChatWidget::linkedNick(const QString & nickname)
   374 QString HWChatWidget::linkedNick(const QString & nickname)
   374 {
   375 {
   375     if (nickname != m_userNick)
   376     if (nickname != m_userNick)
   376         return QString("<a href=\"hwnick://?%1\" class=\"nick\">%2</a>").arg(
   377         return QString("<a href=\"hwnick://?%1\" class=\"nick\">%2</a>").arg(
   377                    QString(nickname.toUtf8().toBase64())).arg(Qt::escape(nickname));
   378                    QString(nickname.toUtf8().toBase64())).arg(nickname.toHtmlEscaped());
   378 
   379 
   379     // unlinked nick (if own one)
   380     // unlinked nick (if own one)
   380     return QString("<span class=\"nick\">%1</span>").arg(Qt::escape(nickname));
   381     return QString("<span class=\"nick\">%1</span>").arg(nickname.toHtmlEscaped());
   381 }
   382 }
   382 
   383 
   383 const QRegExp HWChatWidget::URLREGEXP = QRegExp("(http(s)?://)?(www\\.)?((([^/:?&#]+\\.)?hedgewars\\.org|code\\.google\\.com|googlecode\\.com|hh\\.unit22\\.org)(/[^ ]*)?)");
   384 const QRegExp HWChatWidget::URLREGEXP = QRegExp("(http(s)?://)?(www\\.)?((([^/:?&#]+\\.)?hedgewars\\.org|code\\.google\\.com|googlecode\\.com|hh\\.unit22\\.org)(/[^ ]*)?)");
   384 
   385 
   385 bool HWChatWidget::containsHighlight(const QString & sender, const QString & message)
   386 bool HWChatWidget::containsHighlight(const QString & sender, const QString & message)
   397     return false;
   398     return false;
   398 }
   399 }
   399 
   400 
   400 QString HWChatWidget::messageToHTML(const QString & message)
   401 QString HWChatWidget::messageToHTML(const QString & message)
   401 {
   402 {
   402     QString formattedStr = Qt::escape(message);
   403     QString formattedStr = message.toHtmlEscaped();
   403     // link some urls
   404     // link some urls
   404     formattedStr = formattedStr.replace(URLREGEXP, "<a href=\"http\\2://\\4\">\\4</a>");
   405     formattedStr = formattedStr.replace(URLREGEXP, "<a href=\"http\\2://\\4\">\\4</a>");
   405     return formattedStr;
   406     return formattedStr;
   406 }
   407 }
   407 
   408 
   604             const QString & version,
   605             const QString & version,
   605             const QString & roomInfo)
   606             const QString & roomInfo)
   606 {
   607 {
   607     addLine("msg_PlayerInfo", QString(" >>> %1 - <span class=\"ipaddress\">%2</span> <span class=\"version\">%3</span> <span class=\"location\">%4</span>")
   608     addLine("msg_PlayerInfo", QString(" >>> %1 - <span class=\"ipaddress\">%2</span> <span class=\"version\">%3</span> <span class=\"location\">%4</span>")
   608         .arg(linkedNick(nick))
   609         .arg(linkedNick(nick))
   609         .arg(Qt::escape(ip == "[]"?"":ip))
   610         .arg(QString(ip == "[]"?"":ip).toHtmlEscaped())
   610         .arg(Qt::escape(version))
   611         .arg(version.toHtmlEscaped())
   611         .arg(Qt::escape(roomInfo))
   612         .arg(roomInfo.toHtmlEscaped())
   612     );
   613     );
   613 }
   614 }
   614 
   615 
   615 void HWChatWidget::onKick()
   616 void HWChatWidget::onKick()
   616 {
   617 {