From 30c4a6ef93dcfb6c53af44640d7bae19ec980ce7 Mon Sep 17 00:00:00 2001 From: thunder2 Date: Mon, 1 Jul 2013 20:35:07 +0000 Subject: [PATCH] Added quick fix to show the plain name and title in the chat lobby. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6470 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- retroshare-gui/src/gui/ChatLobbyWidget.cpp | 7 ++++--- retroshare-gui/src/gui/chat/ChatLobbyDialog.cpp | 15 ++++++++------- retroshare-gui/src/gui/chat/ChatStyle.cpp | 3 ++- retroshare-gui/src/gui/chat/ChatWidget.cpp | 4 ++-- .../src/gui/toaster/ChatLobbyToaster.cpp | 4 ++-- retroshare-gui/src/lang/retroshare_en.ts | 8 ++++---- retroshare-gui/src/util/HandleRichText.cpp | 10 ++++++++++ retroshare-gui/src/util/HandleRichText.h | 5 +++-- 8 files changed, 35 insertions(+), 21 deletions(-) diff --git a/retroshare-gui/src/gui/ChatLobbyWidget.cpp b/retroshare-gui/src/gui/ChatLobbyWidget.cpp index bdfb1300c..86c3445a2 100644 --- a/retroshare-gui/src/gui/ChatLobbyWidget.cpp +++ b/retroshare-gui/src/gui/ChatLobbyWidget.cpp @@ -10,6 +10,7 @@ #include "common/RSTreeWidgetItem.h" #include "notifyqt.h" #include "chat/ChatLobbyDialog.h" +#include "util/HandleRichText.h" #include "retroshare/rsmsgs.h" #include "retroshare/rspeers.h" @@ -458,9 +459,9 @@ void ChatLobbyWidget::showBlankPage(ChatLobbyId id) QString lobby_description_string ; lobby_description_string += "

"+tr("Selected lobby info")+"

" ; - lobby_description_string += ""+tr("Lobby name: ")+"\t" + (*it).lobby_name.c_str() + "
" ; + lobby_description_string += ""+tr("Lobby name: ")+"\t" + RsHtml::plainText(it->lobby_name) + "
" ; lobby_description_string += ""+tr("Lobby Id: ")+"\t" + QString::number((*it).lobby_id,16) + "
" ; - lobby_description_string += ""+tr("Topic: ")+"\t" + (*it).lobby_topic.c_str() + "
" ; + lobby_description_string += ""+tr("Topic: ")+"\t" + RsHtml::plainText(it->lobby_topic) + "
" ; lobby_description_string += ""+tr("Type: ")+"\t" + (( (*it).lobby_privacy_level == RS_CHAT_LOBBY_PRIVACY_LEVEL_PRIVATE)?tr("Private"):tr("Public")) + "
" ; lobby_description_string += ""+tr("Peers: ")+"\t" + QString::number((*it).total_number_of_peers) + "
" ; @@ -645,7 +646,7 @@ void ChatLobbyWidget::readChatLobbyInvites() rsMsgs->getPendingChatLobbyInvites(invites); for(std::list::const_iterator it(invites.begin());it!=invites.end();++it) { - if (QMessageBox::Ok == QMessageBox::question(this, tr("Invitation to chat lobby"), tr("%1 invites you to chat lobby named %2").arg(QString::fromUtf8(rsPeers->getPeerName((*it).peer_id).c_str())).arg(QString::fromUtf8((*it).lobby_name.c_str())), QMessageBox::Ok, QMessageBox::Ignore)) { + if (QMessageBox::Ok == QMessageBox::question(this, tr("Invitation to chat lobby"), tr("%1 invites you to chat lobby named %2").arg(QString::fromUtf8(rsPeers->getPeerName((*it).peer_id).c_str())).arg(RsHtml::plainText(it->lobby_name)), QMessageBox::Ok, QMessageBox::Ignore)) { std::cerr << "Accepting invite to lobby " << (*it).lobby_name << std::endl; rsMsgs->acceptLobbyInvite((*it).lobby_id); diff --git a/retroshare-gui/src/gui/chat/ChatLobbyDialog.cpp b/retroshare-gui/src/gui/chat/ChatLobbyDialog.cpp index 74b27529f..8a3107817 100644 --- a/retroshare-gui/src/gui/chat/ChatLobbyDialog.cpp +++ b/retroshare-gui/src/gui/chat/ChatLobbyDialog.cpp @@ -34,6 +34,7 @@ #include #include "gui/common/RSTreeWidgetItem.h" #include "gui/common/FriendSelectionDialog.h" +#include "util/HandleRichText.h" #include @@ -157,10 +158,10 @@ void ChatLobbyDialog::init(const std::string &peerId, const QString &title) std::string vpid; if (rsMsgs->getVirtualPeerId(lobbyIt->lobby_id, vpid)) { if (vpid == peerId) { - QString msg = tr("Welcome to lobby %1").arg(QString::fromUtf8(lobbyIt->lobby_name.c_str())); + QString msg = tr("Welcome to lobby %1").arg(RsHtml::plainText(lobbyIt->lobby_name)); _lobby_name = QString::fromUtf8(lobbyIt->lobby_name.c_str()) ; if (!lobbyIt->lobby_topic.empty()) { - msg += "\n" + tr("Topic: %1").arg(QString::fromUtf8(lobbyIt->lobby_topic.c_str())); + msg += "\n" + tr("Topic: %1").arg(RsHtml::plainText(lobbyIt->lobby_topic)); } ui.chatWidget->setWelcomeMessage(msg); break; @@ -402,7 +403,7 @@ void ChatLobbyDialog::participantsTreeWidgetDoubleClicked(QTreeWidgetItem *item, if(column == COLUMN_NAME) { - getChatWidget()->pasteText("@"+item->text(COLUMN_NAME)) ; + getChatWidget()->pasteText("@" + RsHtml::plainText(item->text(COLUMN_NAME))) ; return ; } @@ -477,21 +478,21 @@ void ChatLobbyDialog::displayLobbyEvent(int event_type, const QString& nickname, { switch (event_type) { case RS_CHAT_LOBBY_EVENT_PEER_LEFT: - ui.chatWidget->addChatMsg(true, tr("Lobby management"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), tr("%1 has left the lobby.").arg(str), ChatWidget::TYPE_SYSTEM); + ui.chatWidget->addChatMsg(true, tr("Lobby management"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), tr("%1 has left the lobby.").arg(RsHtml::plainText(str)), ChatWidget::TYPE_SYSTEM); emit peerLeft(id()) ; break; case RS_CHAT_LOBBY_EVENT_PEER_JOINED: - ui.chatWidget->addChatMsg(true, tr("Lobby management"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), tr("%1 joined the lobby.").arg(str), ChatWidget::TYPE_SYSTEM); + ui.chatWidget->addChatMsg(true, tr("Lobby management"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), tr("%1 joined the lobby.").arg(RsHtml::plainText(str)), ChatWidget::TYPE_SYSTEM); emit peerJoined(id()) ; break; case RS_CHAT_LOBBY_EVENT_PEER_STATUS: - ui.chatWidget->updateStatusString(nickname + " %1", str); + ui.chatWidget->updateStatusString(RsHtml::plainText(nickname) + " %1", RsHtml::plainText(str)); if (!isParticipantMuted(nickname)) { emit typingEventReceived(id()) ; } break; case RS_CHAT_LOBBY_EVENT_PEER_CHANGE_NICKNAME: - ui.chatWidget->addChatMsg(true, tr("Lobby management"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), tr("%1 changed his name to: %2").arg(nickname, str), ChatWidget::TYPE_SYSTEM); + ui.chatWidget->addChatMsg(true, tr("Lobby management"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), tr("%1 changed his name to: %2").arg(RsHtml::plainText(nickname), RsHtml::plainText(str)), ChatWidget::TYPE_SYSTEM); // TODO if a user was muted and changed his name, update mute list, but only, when the muted peer, dont change his name to a other peer in your chat lobby if (isParticipantMuted(nickname) && !isNicknameInLobby(str)) { diff --git a/retroshare-gui/src/gui/chat/ChatStyle.cpp b/retroshare-gui/src/gui/chat/ChatStyle.cpp index 879e40ac7..7a5b7c2d5 100644 --- a/retroshare-gui/src/gui/chat/ChatStyle.cpp +++ b/retroshare-gui/src/gui/chat/ChatStyle.cpp @@ -106,6 +106,7 @@ #include "gui/settings/rsharesettings.h" #include "gui/notifyqt.h" #include "util/DateTime.h" +#include "util/HandleRichText.h" #include @@ -323,7 +324,7 @@ QString ChatStyle::formatMessage(enumFormatMessage type, const QString &name, co Q_UNUSED(flag); #endif - QString formatMsg = style.replace("%name%", name) + QString formatMsg = style.replace("%name%", RsHtml::plainText(name)) .replace("%date%", DateTime::formatDate(timestamp.date())) .replace("%time%", DateTime::formatTime(timestamp.time())) #ifdef COLORED_NICKNAMES diff --git a/retroshare-gui/src/gui/chat/ChatWidget.cpp b/retroshare-gui/src/gui/chat/ChatWidget.cpp index d7860c04d..972ed6401 100644 --- a/retroshare-gui/src/gui/chat/ChatWidget.cpp +++ b/retroshare-gui/src/gui/chat/ChatWidget.cpp @@ -152,7 +152,7 @@ void ChatWidget::init(const std::string &peerId, const QString &title) this->peerId = peerId; this->title = title; - ui->titleLabel->setText(title); + ui->titleLabel->setText(RsHtml::plainText(title)); std::string ownId = rsPeers->getOwnId(); setName(QString::fromUtf8(rsPeers->getPeerName(ownId).c_str())); @@ -929,7 +929,7 @@ void ChatWidget::updateTitle() return; } - ui->titleLabel->setText(name + "@" + title); + ui->titleLabel->setText(RsHtml::plainText(name) + "@" + RsHtml::plainText(title)); } void ChatWidget::updatePeersCustomStateString(const QString& peer_id, const QString& status_string) diff --git a/retroshare-gui/src/gui/toaster/ChatLobbyToaster.cpp b/retroshare-gui/src/gui/toaster/ChatLobbyToaster.cpp index 0a7ceada8..e536f6b27 100644 --- a/retroshare-gui/src/gui/toaster/ChatLobbyToaster.cpp +++ b/retroshare-gui/src/gui/toaster/ChatLobbyToaster.cpp @@ -40,7 +40,7 @@ ChatLobbyToaster::ChatLobbyToaster(const std::string &peerId, const QString &nam ui.avatarWidget->setFrameType(AvatarWidget::NORMAL_FRAME); ui.avatarWidget->setDefaultAvatar(":images/user/agt_forum64.png"); - QString lobbyName = name; + QString lobbyName = RsHtml::plainText(name); std::list linfos; rsMsgs->getChatLobbyList(linfos); @@ -49,7 +49,7 @@ ChatLobbyToaster::ChatLobbyToaster(const std::string &peerId, const QString &nam if (rsMsgs->isLobbyId(peerId, lobbyId)) { for (std::list::const_iterator it(linfos.begin()); it != linfos.end(); ++it) { if ((*it).lobby_id == lobbyId) { - lobbyName += "@" + QString::fromUtf8((*it).lobby_name.c_str()); + lobbyName += "@" + RsHtml::plainText(it->lobby_name); break; } } diff --git a/retroshare-gui/src/lang/retroshare_en.ts b/retroshare-gui/src/lang/retroshare_en.ts index a7deaff37..2f66200d7 100644 --- a/retroshare-gui/src/lang/retroshare_en.ts +++ b/retroshare-gui/src/lang/retroshare_en.ts @@ -1376,10 +1376,6 @@ Double click lobbies to enter and chat. Invitation to chat lobby - - %1 invites you to chat lobby named %2 - - Remove Auto Subscribe @@ -1388,6 +1384,10 @@ Double click lobbies to enter and chat. Add Auto Subscribe + + %1 invites you to chat lobby named %2 + + ChatMsgItem diff --git a/retroshare-gui/src/util/HandleRichText.cpp b/retroshare-gui/src/util/HandleRichText.cpp index 4ad06616b..c2066d81a 100644 --- a/retroshare-gui/src/util/HandleRichText.cpp +++ b/retroshare-gui/src/util/HandleRichText.cpp @@ -792,3 +792,13 @@ bool RsHtml::makeEmbeddedImage(const QImage &originalImage, QString &embeddedIma } return true; } + +QString RsHtml::plainText(const QString &text) +{ + return Qt::escape(text); +} + +QString RsHtml::plainText(const std::string &text) +{ + return Qt::escape(QString::fromUtf8(text.c_str())); +} diff --git a/retroshare-gui/src/util/HandleRichText.h b/retroshare-gui/src/util/HandleRichText.h index 433353211..d3d69bed5 100644 --- a/retroshare-gui/src/util/HandleRichText.h +++ b/retroshare-gui/src/util/HandleRichText.h @@ -28,8 +28,6 @@ #ifndef HANDLE_RICH_TEXT_H_ #define HANDLE_RICH_TEXT_H_ -#include - /* Flags for RsHtml::formatText */ #define RSHTML_FORMATTEXT_EMBED_SMILEYS 1 #define RSHTML_FORMATTEXT_EMBED_LINKS 2 @@ -71,6 +69,9 @@ public: static bool makeEmbeddedImage(const QString &fileName, QString &embeddedImage, const int maxPixels); static bool makeEmbeddedImage(const QImage &originalImage, QString &embeddedImage, const int maxPixels); + static QString plainText(const QString &text); + static QString plainText(const std::string &text); + protected: void embedHtml(QTextDocument *textDocument, QDomDocument &doc, QDomElement ¤tElement, EmbedInHtml& embedInfos, ulong flag); void replaceAnchorWithImg(QDomDocument& doc, QDomElement &element, QTextDocument *textDocument, const RetroShareLink &link);