mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-22 07:41:20 -04:00
- Moved HandleRichText from the folder "chat" to "util" and redesigned the source
- Extended RsHtml::formatText to replace the RetroShare links with an image and enabled this for the certificate links in the system messages (friend recommendation and user request) - Added new ObjectPainter for painting a button on a pixmap git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5160 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
5a3863d216
commit
dc2d6c975e
27 changed files with 470 additions and 215 deletions
|
@ -39,6 +39,7 @@
|
|||
#include "RetroShareLink.h"
|
||||
#include "channels/ShareKey.h"
|
||||
#include "notifyqt.h"
|
||||
#include "util/HandleRichText.h"
|
||||
|
||||
#include <retroshare/rspeers.h>
|
||||
#include <retroshare/rsforums.h>
|
||||
|
@ -1165,7 +1166,7 @@ void ForumsDialog::insertPost()
|
|||
}
|
||||
}
|
||||
|
||||
QString extraTxt = RsHtml::formatText(messageFromInfo(msg), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS);
|
||||
QString extraTxt = RsHtml().formatText(ui.postText->document(), messageFromInfo(msg), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS);
|
||||
|
||||
ui.postText->setHtml(extraTxt);
|
||||
ui.threadTitle->setText(titleFromInfo(msg));
|
||||
|
|
|
@ -28,6 +28,9 @@
|
|||
#include <QFontDialog>
|
||||
#include <QMenu>
|
||||
#include <QScrollBar>
|
||||
#include <QTextStream>
|
||||
#include <QTextCodec>
|
||||
#include <QTimer>
|
||||
|
||||
#include "retroshare/rsinit.h"
|
||||
#include "retroshare/rsnotify.h"
|
||||
|
@ -55,6 +58,7 @@
|
|||
#include "RetroShareLink.h"
|
||||
#include "settings/rsharesettings.h"
|
||||
#include "util/misc.h"
|
||||
#include "util/HandleRichText.h"
|
||||
#include "chat/CreateLobbyDialog.h"
|
||||
#include "FriendRecommendDialog.h"
|
||||
|
||||
|
@ -373,11 +377,11 @@ void FriendsDialog::publicChatChanged(int type)
|
|||
|
||||
void FriendsDialog::addChatMsg(bool incoming, bool history, const QString &name, const QDateTime &sendTime, const QDateTime &recvTime, const QString &message)
|
||||
{
|
||||
unsigned int formatFlag = CHAT_FORMATMSG_EMBED_LINKS | CHAT_FORMATMSG_OPTIMIZE;
|
||||
unsigned int formatTextFlag = RSHTML_FORMATTEXT_EMBED_LINKS | RSHTML_FORMATTEXT_OPTIMIZE;
|
||||
|
||||
// embed smileys ?
|
||||
if (Settings->valueFromGroup("Chat", "Emoteicons_GroupChat", true).toBool()) {
|
||||
formatFlag |= CHAT_FORMATMSG_EMBED_SMILEYS;
|
||||
formatTextFlag |= RSHTML_FORMATTEXT_EMBED_SMILEYS;
|
||||
}
|
||||
|
||||
ChatStyle::enumFormatMessage type;
|
||||
|
@ -394,10 +398,9 @@ void FriendsDialog::addChatMsg(bool incoming, bool history, const QString &name,
|
|||
type = ChatStyle::FORMATMSG_OUTGOING;
|
||||
}
|
||||
}
|
||||
// Remove <p>'s from older RetroShare versions before 31.01.2012 (can be removed later)
|
||||
QString optimizedMessage = message;
|
||||
RsHtml::optimizeHtml(optimizedMessage);
|
||||
QString formatMsg = style.formatMessage(type, name, incoming ? recvTime : sendTime, optimizedMessage, formatFlag);
|
||||
|
||||
QString formattedMessage = RsHtml().formatText(ui.msgText->document(), message, formatTextFlag);
|
||||
QString formatMsg = style.formatMessage(type, name, incoming ? recvTime : sendTime, formattedMessage);
|
||||
|
||||
ui.msgText->append(formatMsg);
|
||||
}
|
||||
|
|
|
@ -757,7 +757,7 @@ bool RetroShareLink::checkHash(const QString& hash)
|
|||
return true ;
|
||||
}
|
||||
|
||||
static void processList(QStringList &list, const QString &textSingular, const QString &textPlural, QString &result)
|
||||
static void processList(const QStringList &list, const QString &textSingular, const QString &textPlural, QString &result)
|
||||
{
|
||||
if (list.size() == 0) {
|
||||
return;
|
||||
|
@ -768,7 +768,7 @@ static void processList(QStringList &list, const QString &textSingular, const QS
|
|||
result += "" + textPlural + ":";
|
||||
}
|
||||
result += "<p style='margin-left: 5px; margin-top: 0px'>";
|
||||
QStringList::iterator it;
|
||||
QStringList::const_iterator it;
|
||||
for (it = list.begin(); it != list.end(); ++it) {
|
||||
if (it != list.begin()) {
|
||||
result += ", ";
|
||||
|
@ -778,9 +778,9 @@ static void processList(QStringList &list, const QString &textSingular, const QS
|
|||
result += "</p>";
|
||||
}
|
||||
|
||||
/*static*/ int RetroShareLink::process(QList<RetroShareLink> &linksIn, uint flag /* = RSLINK_PROCESS_NOTIFY_ALL*/)
|
||||
/*static*/ int RetroShareLink::process(const QList<RetroShareLink> &linksIn, uint flag /* = RSLINK_PROCESS_NOTIFY_ALL*/)
|
||||
{
|
||||
QList<RetroShareLink>::iterator linkIt;
|
||||
QList<RetroShareLink>::const_iterator linkIt;
|
||||
|
||||
/* filter dublicate links */
|
||||
QList<RetroShareLink> links;
|
||||
|
@ -798,7 +798,7 @@ static void processList(QStringList &list, const QString &textSingular, const QS
|
|||
QStringList personAdd;
|
||||
|
||||
for (linkIt = links.begin(); linkIt != links.end(); linkIt++) {
|
||||
RetroShareLink &link = *linkIt;
|
||||
const RetroShareLink &link = *linkIt;
|
||||
|
||||
if (link.valid() == false) {
|
||||
continue;
|
||||
|
@ -897,7 +897,7 @@ static void processList(QStringList &list, const QString &textSingular, const QS
|
|||
// not needed: forumFound, channelFound, messageStarted
|
||||
|
||||
for (linkIt = links.begin(); linkIt != links.end(); linkIt++) {
|
||||
RetroShareLink &link = *linkIt;
|
||||
const RetroShareLink &link = *linkIt;
|
||||
|
||||
if (link.valid() == false) {
|
||||
std::cerr << " RetroShareLink::process invalid request" << std::endl;
|
||||
|
@ -1257,11 +1257,11 @@ static void processList(QStringList &list, const QString &textSingular, const QS
|
|||
return 0;
|
||||
}
|
||||
|
||||
/*static*/ int RetroShareLink::process(QStringList &urls, RetroShareLink::enumType type /* = RetroShareLink::TYPE_UNKNOWN*/, uint flag /* = RSLINK_PROCESS_NOTIFY_ALL*/)
|
||||
/*static*/ int RetroShareLink::process(const QStringList &urls, RetroShareLink::enumType type /* = RetroShareLink::TYPE_UNKNOWN*/, uint flag /* = RSLINK_PROCESS_NOTIFY_ALL*/)
|
||||
{
|
||||
QList<RetroShareLink> links;
|
||||
|
||||
for (QStringList::iterator it = urls.begin(); it != urls.end(); it++) {
|
||||
for (QStringList::const_iterator it = urls.begin(); it != urls.end(); it++) {
|
||||
RetroShareLink link(*it);
|
||||
if (link.valid() && (type == RetroShareLink::TYPE_UNKNOWN || link.type() == type)) {
|
||||
links.append(link);
|
||||
|
|
|
@ -101,8 +101,8 @@ class RetroShareLink
|
|||
|
||||
bool operator==(const RetroShareLink& l) const { return _type == l._type && _hash == l._hash ; }
|
||||
|
||||
static int process(QStringList &urls, RetroShareLink::enumType type = RetroShareLink::TYPE_UNKNOWN, uint flag = RSLINK_PROCESS_NOTIFY_ALL);
|
||||
static int process(QList<RetroShareLink> &links, uint flag = RSLINK_PROCESS_NOTIFY_ALL);
|
||||
static int process(const QStringList &urls, RetroShareLink::enumType type = RetroShareLink::TYPE_UNKNOWN, uint flag = RSLINK_PROCESS_NOTIFY_ALL);
|
||||
static int process(const QList<RetroShareLink> &links, uint flag = RSLINK_PROCESS_NOTIFY_ALL);
|
||||
|
||||
private:
|
||||
void fromString(const QString &url);
|
||||
|
|
|
@ -101,11 +101,11 @@
|
|||
|
||||
#include <QApplication>
|
||||
#include <QColor>
|
||||
#include <QXmlStreamReader>
|
||||
|
||||
#include "ChatStyle.h"
|
||||
#include "gui/settings/rsharesettings.h"
|
||||
#include "gui/notifyqt.h"
|
||||
#include "gui/common/Emoticons.h"
|
||||
|
||||
#include <retroshare/rsinit.h>
|
||||
|
||||
|
@ -301,19 +301,6 @@ QString ChatStyle::formatMessage(enumFormatMessage type, const QString &name, co
|
|||
m_style[type] = style;
|
||||
}
|
||||
|
||||
unsigned int formatFlag = 0;
|
||||
if (flag & CHAT_FORMATMSG_EMBED_SMILEYS) {
|
||||
formatFlag |= RSHTML_FORMATTEXT_EMBED_SMILEYS;
|
||||
}
|
||||
if (flag & CHAT_FORMATMSG_EMBED_LINKS) {
|
||||
formatFlag |= RSHTML_FORMATTEXT_EMBED_LINKS;
|
||||
}
|
||||
if (flag & CHAT_FORMATMSG_OPTIMIZE) {
|
||||
formatFlag |= RSHTML_FORMATTEXT_OPTIMIZE;
|
||||
}
|
||||
|
||||
QString msg = RsHtml::formatText(message, formatFlag);
|
||||
|
||||
QColor color;
|
||||
#ifdef COLORED_NICKNAMES
|
||||
if (flag & CHAT_FORMATMSG_SYSTEM) {
|
||||
|
@ -332,12 +319,14 @@ QString ChatStyle::formatMessage(enumFormatMessage type, const QString &name, co
|
|||
|
||||
color.setHsv(hash, 255, 150);
|
||||
}
|
||||
#else
|
||||
Q_UNUSED(flag);
|
||||
#endif
|
||||
|
||||
QString formatMsg = style.replace("%name%", name)
|
||||
.replace("%date%", timestamp.date().toString("dd.MM.yyyy"))
|
||||
.replace("%time%", timestamp.time().toString("hh:mm:ss"))
|
||||
.replace("%message%", msg)
|
||||
.replace("%message%", message)
|
||||
.replace("%color%", color.name());
|
||||
|
||||
return formatMsg;
|
||||
|
|
|
@ -30,14 +30,7 @@
|
|||
#include <QDir>
|
||||
|
||||
/* Flags for ChatStyle::formatMessage */
|
||||
#define CHAT_FORMATMSG_EMBED_SMILEYS 1
|
||||
#define CHAT_FORMATMSG_EMBED_LINKS 2
|
||||
#define CHAT_FORMATMSG_SYSTEM 4
|
||||
#define CHAT_FORMATMSG_OPTIMIZE 8
|
||||
|
||||
/* Flags for ChatStyle::formatText */
|
||||
#define CHAT_FORMATTEXT_EMBED_SMILEYS 1
|
||||
#define CHAT_FORMATTEXT_EMBED_LINKS 2
|
||||
#define CHAT_FORMATMSG_SYSTEM 1
|
||||
|
||||
#define FORMATMSG_COUNT 6
|
||||
|
||||
|
@ -89,7 +82,7 @@ public:
|
|||
bool setStylePath(const QString &stylePath, const QString &styleVariant);
|
||||
bool setStyleFromSettings(enumStyleType styleType);
|
||||
|
||||
QString formatMessage(enumFormatMessage type, const QString &name, const QDateTime ×tamp, const QString &message, unsigned int flag);
|
||||
QString formatMessage(enumFormatMessage type, const QString &name, const QDateTime ×tamp, const QString &message, unsigned int flag = 0);
|
||||
|
||||
static bool getAvailableStyles(enumStyleType styleType, QList<ChatStyleInfo> &styles);
|
||||
static bool getAvailableVariants(const QString &stylePath, QStringList &variants);
|
||||
|
|
|
@ -27,6 +27,9 @@
|
|||
#include <QColorDialog>
|
||||
#include <QFontDialog>
|
||||
#include <QMessageBox>
|
||||
#include <QTextStream>
|
||||
#include <QTextCodec>
|
||||
#include <QTimer>
|
||||
|
||||
#include "ChatWidget.h"
|
||||
#include "ui_ChatWidget.h"
|
||||
|
@ -35,11 +38,11 @@
|
|||
#include "gui/settings/rsharesettings.h"
|
||||
#include "gui/settings/RsharePeerSettings.h"
|
||||
#include "gui/im_history/ImHistoryBrowser.h"
|
||||
#include "HandleRichText.h"
|
||||
#include "gui/common/StatusDefs.h"
|
||||
#include "gui/common/FilesDefs.h"
|
||||
#include "gui/common/Emoticons.h"
|
||||
#include "util/misc.h"
|
||||
#include "util/HandleRichText.h"
|
||||
|
||||
#include <retroshare/rsstatus.h>
|
||||
#include <retroshare/rspeers.h>
|
||||
|
@ -305,11 +308,12 @@ void ChatWidget::addChatMsg(bool incoming, const QString &name, const QDateTime
|
|||
std::cout << "ChatWidget::addChatMsg message : " << message.toStdString() << std::endl;
|
||||
#endif
|
||||
|
||||
unsigned int formatFlag = CHAT_FORMATMSG_EMBED_LINKS | CHAT_FORMATMSG_OPTIMIZE;
|
||||
unsigned int formatTextFlag = RSHTML_FORMATTEXT_EMBED_LINKS | RSHTML_FORMATTEXT_OPTIMIZE;
|
||||
unsigned int formatFlag = 0;
|
||||
|
||||
// embed smileys ?
|
||||
if (Settings->valueFromGroup(QString("Chat"), QString::fromUtf8("Emoteicons_PrivatChat"), true).toBool()) {
|
||||
formatFlag |= CHAT_FORMATMSG_EMBED_SMILEYS;
|
||||
formatTextFlag |= RSHTML_FORMATTEXT_EMBED_SMILEYS;
|
||||
}
|
||||
|
||||
ChatStyle::enumFormatMessage type;
|
||||
|
@ -327,7 +331,8 @@ void ChatWidget::addChatMsg(bool incoming, const QString &name, const QDateTime
|
|||
formatFlag |= CHAT_FORMATMSG_SYSTEM;
|
||||
}
|
||||
|
||||
QString formatMsg = chatStyle.formatMessage(type, name, incoming ? sendTime : recvTime, message, formatFlag);
|
||||
QString formattedMessage = RsHtml().formatText(ui->textBrowser->document(), message, formatTextFlag);
|
||||
QString formatMsg = chatStyle.formatMessage(type, name, incoming ? sendTime : recvTime, formattedMessage, formatFlag);
|
||||
|
||||
ui->textBrowser->append(formatMsg);
|
||||
|
||||
|
@ -732,7 +737,7 @@ void ChatWidget::updatePeersCustomStateString(const QString& peer_id, const QStr
|
|||
ui->statusmessagelabel->hide();
|
||||
} else {
|
||||
ui->statusmessagelabel->show();
|
||||
status_text = RsHtml::formatText(status_string, RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS);
|
||||
status_text = RsHtml().formatText(NULL, status_string, RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS);
|
||||
ui->statusmessagelabel->setText(status_text);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,452 +0,0 @@
|
|||
/****************************************************************
|
||||
* This file is distributed under the following license:
|
||||
*
|
||||
* Copyright (c) 2010, Thomas Kister
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
#include <QTextBrowser>
|
||||
#include "HandleRichText.h"
|
||||
#include "gui/RetroShareLink.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace RsHtml {
|
||||
|
||||
EmbedInHtmlImg defEmbedImg;
|
||||
|
||||
void EmbedInHtmlImg::InitFromAwkwardHash(const QHash< QString, QString >& hash)
|
||||
{
|
||||
QString newRE;
|
||||
for(QHash<QString,QString>::const_iterator it = hash.begin(); it != hash.end(); ++it)
|
||||
foreach(QString smile, it.key().split("|")) {
|
||||
if (smile.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
smileys.insert(smile, it.value());
|
||||
newRE += "(" + QRegExp::escape(smile) + ")|";
|
||||
}
|
||||
newRE.chop(1); // remove last |
|
||||
myRE.setPattern(newRE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a DOM tree and replaces text by HTML tags.
|
||||
* The tree is traversed depth-first, but only through children of Element type
|
||||
* nodes. Any other kind of node is terminal.
|
||||
*
|
||||
* If the node is of type Text, its data is checked against the user-provided
|
||||
* regular expression. If there is a match, the text is cut in three parts: the
|
||||
* preceding part that will be inserted before, the part to be replaced, and the
|
||||
* following part which will be itself checked against the regular expression.
|
||||
*
|
||||
* The part to be replaced is sent to a user-provided functor that will create
|
||||
* the necessary embedding and return a new Element node to be inserted.
|
||||
*
|
||||
* @param[in] doc The whole DOM tree, necessary to create new nodes
|
||||
* @param[in,out] currentElement The current node (which is of type Element)
|
||||
* @param[in] embedInfos The regular expression and the type of embedding to use
|
||||
*/
|
||||
static void embedHtml(QDomDocument& doc, QDomElement& currentElement, EmbedInHtml& embedInfos)
|
||||
{
|
||||
if(embedInfos.myRE.pattern().length() == 0) // we'll get stuck with an empty regexp
|
||||
return;
|
||||
|
||||
QDomNodeList children = currentElement.childNodes();
|
||||
for(uint index = 0; index < children.length(); index++) {
|
||||
QDomNode node = children.item(index);
|
||||
if(node.isElement()) {
|
||||
// child is an element, we skip it if it's an <a> tag
|
||||
QDomElement element = node.toElement();
|
||||
if(element.tagName().toLower() == "head") {
|
||||
// skip it
|
||||
} else if (element.tagName().toLower() == "a") {
|
||||
// skip it, but add title if not available
|
||||
if (element.attribute("title").isEmpty()) {
|
||||
RetroShareLink link(element.attribute("href"));
|
||||
QString title = link.title();
|
||||
if (!title.isEmpty()) {
|
||||
element.setAttribute("title", title);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
embedHtml(doc, element, embedInfos);
|
||||
}
|
||||
}
|
||||
else if(node.isText()) {
|
||||
// child is a text, we parse it
|
||||
QString tempText = node.toText().data();
|
||||
if(embedInfos.myRE.indexIn(tempText) == -1)
|
||||
continue;
|
||||
|
||||
// there is at least one link inside, we start replacing
|
||||
int currentPos = 0;
|
||||
int nextPos = 0;
|
||||
while((nextPos = embedInfos.myRE.indexIn(tempText, currentPos)) != -1) {
|
||||
// if nextPos == 0 it means the text begins by a link
|
||||
if(nextPos > 0) {
|
||||
QDomText textPart = doc.createTextNode(tempText.mid(currentPos, nextPos - currentPos));
|
||||
currentElement.insertBefore(textPart, node);
|
||||
index++;
|
||||
}
|
||||
|
||||
// inserted tag
|
||||
QDomElement insertedTag;
|
||||
switch(embedInfos.myType) {
|
||||
case Ahref:
|
||||
{
|
||||
insertedTag = doc.createElement("a");
|
||||
insertedTag.setAttribute("href", embedInfos.myRE.cap(0));
|
||||
|
||||
RetroShareLink link(embedInfos.myRE.cap(0));
|
||||
QString title = link.title();
|
||||
if (!title.isEmpty()) {
|
||||
insertedTag.setAttribute("title", title);
|
||||
}
|
||||
|
||||
insertedTag.appendChild(doc.createTextNode(embedInfos.myRE.cap(0)));
|
||||
}
|
||||
break;
|
||||
case Img:
|
||||
{
|
||||
insertedTag = doc.createElement("img");
|
||||
const EmbedInHtmlImg& embedImg = static_cast<const EmbedInHtmlImg&>(embedInfos);
|
||||
insertedTag.setAttribute("src", embedImg.smileys[embedInfos.myRE.cap(0)]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
currentElement.insertBefore(insertedTag, node);
|
||||
|
||||
currentPos = nextPos + embedInfos.myRE.matchedLength();
|
||||
index++;
|
||||
}
|
||||
|
||||
// text after the last link, only if there's one, don't touch the index
|
||||
// otherwise decrement the index because we're going to remove node
|
||||
if(currentPos < tempText.length()) {
|
||||
QDomText textPart = doc.createTextNode(tempText.mid(currentPos));
|
||||
currentElement.insertBefore(textPart, node);
|
||||
}
|
||||
else
|
||||
index--;
|
||||
|
||||
currentElement.removeChild(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QString formatText(const QString &text, unsigned int flag)
|
||||
{
|
||||
if (flag == 0 || text.isEmpty()) {
|
||||
// nothing to do
|
||||
return text;
|
||||
}
|
||||
|
||||
QDomDocument doc;
|
||||
if (doc.setContent(text) == false) {
|
||||
// convert text with QTextBrowser
|
||||
QTextBrowser textBrowser;
|
||||
textBrowser.setText(text);
|
||||
doc.setContent(textBrowser.toHtml());
|
||||
}
|
||||
|
||||
QDomElement body = doc.documentElement();
|
||||
if (flag & RSHTML_FORMATTEXT_EMBED_SMILEYS) {
|
||||
embedHtml(doc, body, defEmbedImg);
|
||||
}
|
||||
if (flag & RSHTML_FORMATTEXT_EMBED_LINKS) {
|
||||
EmbedInHtmlAhref defEmbedAhref;
|
||||
embedHtml(doc, body, defEmbedAhref);
|
||||
}
|
||||
|
||||
QString formattedText = doc.toString(-1); // -1 removes any annoying carriage return misinterpreted by QTextEdit
|
||||
|
||||
unsigned int optimizeFlag = 0;
|
||||
if (flag & RSHTML_FORMATTEXT_REMOVE_FONT) {
|
||||
optimizeFlag |= RSHTML_OPTIMIZEHTML_REMOVE_FONT;
|
||||
}
|
||||
if (flag & RSHTML_FORMATTEXT_REMOVE_COLOR) {
|
||||
optimizeFlag |= RSHTML_OPTIMIZEHTML_REMOVE_COLOR;
|
||||
}
|
||||
if (optimizeFlag || (flag & RSHTML_FORMATTEXT_OPTIMIZE)) {
|
||||
optimizeHtml(formattedText, optimizeFlag);
|
||||
}
|
||||
|
||||
return formattedText;
|
||||
}
|
||||
|
||||
static void findElements(QDomDocument& doc, QDomElement& currentElement, const QString& nodeName, const QString& nodeAttribute, QStringList &elements)
|
||||
{
|
||||
if(nodeName.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QDomNodeList children = currentElement.childNodes();
|
||||
for (uint index = 0; index < children.length(); index++) {
|
||||
QDomNode node = children.item(index);
|
||||
if (node.isElement()) {
|
||||
QDomElement element = node.toElement();
|
||||
if (QString::compare(element.tagName(), nodeName, Qt::CaseInsensitive) == 0) {
|
||||
if (nodeAttribute.isEmpty()) {
|
||||
// use text
|
||||
elements.append(element.text());
|
||||
} else {
|
||||
QString attribute = element.attribute(nodeAttribute);
|
||||
if (attribute.isEmpty() == false) {
|
||||
elements.append(attribute);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
findElements(doc, element, nodeName, nodeAttribute, elements);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool findAnchors(const QString &text, QStringList& urls)
|
||||
{
|
||||
QDomDocument doc;
|
||||
if (doc.setContent(text) == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QDomElement body = doc.documentElement();
|
||||
findElements(doc, body, "a", "href", urls);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void removeElement(QDomElement& parentElement, QDomElement& element)
|
||||
{
|
||||
QDomNodeList children = element.childNodes();
|
||||
while (children.length() > 0) {
|
||||
QDomNode childElement = element.removeChild(children.item(children.length() - 1));
|
||||
parentElement.insertAfter(childElement, element);
|
||||
}
|
||||
parentElement.removeChild(element);
|
||||
}
|
||||
|
||||
static void optimizeHtml(QDomDocument& doc, QDomElement& currentElement, unsigned int flag)
|
||||
{
|
||||
if (currentElement.tagName().toLower() == "html") {
|
||||
// change <html> to <span>
|
||||
currentElement.setTagName("span");
|
||||
}
|
||||
|
||||
QDomNode styleNode;
|
||||
bool addBR = false;
|
||||
|
||||
QDomNodeList children = currentElement.childNodes();
|
||||
for (uint index = 0; index < children.length(); ) {
|
||||
QDomNode node = children.item(index);
|
||||
|
||||
// compress style attribute
|
||||
styleNode = node.attributes().namedItem("style");
|
||||
if (styleNode.isAttr()) {
|
||||
QDomAttr styleAttr = styleNode.toAttr();
|
||||
QString style = styleAttr.value().simplified();
|
||||
style.replace("margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px;", "margin:0px 0px 0px 0px;");
|
||||
style.replace("; ", ";");
|
||||
|
||||
if (flag & (RSHTML_OPTIMIZEHTML_REMOVE_FONT | RSHTML_OPTIMIZEHTML_REMOVE_COLOR)) {
|
||||
QStringList styles = style.split(';');
|
||||
style.clear();
|
||||
foreach (QString pair, styles) {
|
||||
if (!pair.trimmed().isEmpty()) {
|
||||
QStringList keyvalue = pair.split(':');
|
||||
if (keyvalue.length() == 2) {
|
||||
QString key = keyvalue.at(0).trimmed();
|
||||
|
||||
if (flag & RSHTML_OPTIMIZEHTML_REMOVE_FONT) {
|
||||
if (key == "font-family" ||
|
||||
key == "font-size" ||
|
||||
key == "font-weight" ||
|
||||
key == "font-style") {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (flag & RSHTML_OPTIMIZEHTML_REMOVE_COLOR) {
|
||||
if (key == "color") {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
style += key + ":" + keyvalue.at(1).trimmed() + ";";
|
||||
} else {
|
||||
style += pair + ";";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (style.isEmpty()) {
|
||||
node.attributes().removeNamedItem("style");
|
||||
styleNode.clear();
|
||||
} else {
|
||||
styleAttr.setValue(style);
|
||||
}
|
||||
}
|
||||
|
||||
if (node.isElement()) {
|
||||
QDomElement element = node.toElement();
|
||||
|
||||
// not <p>
|
||||
if (addBR && element.tagName().toLower() != "p") {
|
||||
// add <br> after a removed <p> but not before a <p>
|
||||
QDomElement elementBr = doc.createElement("br");
|
||||
currentElement.insertBefore(elementBr, element);
|
||||
addBR = false;
|
||||
++index;
|
||||
}
|
||||
|
||||
// <body>
|
||||
if (element.tagName().toLower() == "body") {
|
||||
if (element.attributes().length() == 0) {
|
||||
// remove <body> without attributes
|
||||
removeElement(currentElement, element);
|
||||
// no ++index;
|
||||
continue;
|
||||
}
|
||||
// change <body> to <span>
|
||||
element.setTagName("span");
|
||||
}
|
||||
|
||||
// <head>
|
||||
if (element.tagName().toLower() == "head") {
|
||||
// remove <head>
|
||||
currentElement.removeChild(node);
|
||||
// no ++index;
|
||||
continue;
|
||||
}
|
||||
|
||||
// iterate children
|
||||
optimizeHtml(doc, element, flag);
|
||||
|
||||
// <p>
|
||||
if (element.tagName().toLower() == "p") {
|
||||
// <p style="...">
|
||||
if (element.attributes().size() == 1 && styleNode.isAttr()) {
|
||||
QString style = styleNode.toAttr().value().simplified();
|
||||
if (style == "margin:0px 0px 0px 0px;-qt-block-indent:0;text-indent:0px;" ||
|
||||
style.startsWith("-qt-paragraph-type:empty;margin:0px 0px 0px 0px;-qt-block-indent:0;text-indent:0px;")) {
|
||||
|
||||
if (addBR) {
|
||||
// add <br> after a removed <p> before a removed <p>
|
||||
QDomElement elementBr = doc.createElement("br");
|
||||
currentElement.insertBefore(elementBr, element);
|
||||
++index;
|
||||
}
|
||||
// remove Qt standard <p> or empty <p>
|
||||
index += element.childNodes().length();
|
||||
removeElement(currentElement, element);
|
||||
addBR = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
// check for blockquote (not ready)
|
||||
// style="margin-top:12px;margin-bottom:12px;margin-left:40px;margin-right:40px;-qt-block-indent:0;text-indent:0px;"
|
||||
// int count = 0; // should be 6
|
||||
// QStringList styles = style.split(';');
|
||||
// foreach (QString pair, styles) {
|
||||
// if (!pair.trimmed().isEmpty()) {
|
||||
// QStringList keyvalue = pair.split(':');
|
||||
// if (keyvalue.length() == 2) {
|
||||
// QString key = keyvalue.at(0).trimmed();
|
||||
// QString value = keyvalue.at(1).trimmed();
|
||||
|
||||
// if ((key == "margin-top" || key == "margin-bottom") && value == "12px") {
|
||||
// ++count;
|
||||
// continue;
|
||||
// }
|
||||
// if (key == "margin-left" || key == "margin-right") {
|
||||
// ++count;
|
||||
// continue;
|
||||
// }
|
||||
// if (key == "-qt-block-indent" && value == "0") {
|
||||
// ++count;
|
||||
// continue;
|
||||
// }
|
||||
// if (key == "text-indent" && value == "0px") {
|
||||
// ++count;
|
||||
// continue;
|
||||
// }
|
||||
// count = 0;
|
||||
// break;
|
||||
// } else {
|
||||
// count = 0;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if (count == 6) {
|
||||
// // change to "blockquote"
|
||||
// element.setTagName("blockquote");
|
||||
// element.attributes().removeNamedItem("style");
|
||||
// element.setAttribute("type", "cite");
|
||||
// }
|
||||
}
|
||||
addBR = false;
|
||||
}
|
||||
}
|
||||
++index;
|
||||
}
|
||||
}
|
||||
|
||||
void optimizeHtml(QTextEdit *textEdit, QString &text, unsigned int flag)
|
||||
{
|
||||
if (textEdit->toHtml() == QTextDocument(textEdit->toPlainText()).toHtml()) {
|
||||
text = textEdit->toPlainText();
|
||||
std::cerr << "Optimized text to " << text.length() << " bytes , instead of " << textEdit->toHtml().length() << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
text = textEdit->toHtml();
|
||||
|
||||
optimizeHtml(text, flag);
|
||||
}
|
||||
|
||||
void optimizeHtml(QString &text, unsigned int flag)
|
||||
{
|
||||
int originalLength = text.length();
|
||||
|
||||
// remove doctype
|
||||
text.remove(QRegExp("<!DOCTYPE[^>]*>"));
|
||||
|
||||
QDomDocument doc;
|
||||
if (doc.setContent(text) == false) {
|
||||
return;
|
||||
}
|
||||
|
||||
QDomElement body = doc.documentElement();
|
||||
optimizeHtml(doc, body, flag);
|
||||
text = doc.toString(-1);
|
||||
|
||||
std::cerr << "Optimized text to " << text.length() << " bytes , instead of " << originalLength << std::endl;
|
||||
}
|
||||
|
||||
QString toHtml(QString text, bool realHtml)
|
||||
{
|
||||
// replace "\n" from the optimized html with "<br>"
|
||||
text.replace("\n", "<br>");
|
||||
if (!realHtml) {
|
||||
return text;
|
||||
}
|
||||
|
||||
QTextDocument doc;
|
||||
doc.setHtml(text);
|
||||
return doc.toHtml();
|
||||
}
|
||||
|
||||
} // namespace RsHtml
|
|
@ -1,131 +0,0 @@
|
|||
/****************************************************************
|
||||
* This file is distributed under the following license:
|
||||
*
|
||||
* Copyright (c) 2010, Thomas Kister
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
/**
|
||||
* This file provides helper functions and functors for translating data from/to
|
||||
* rich text format and HTML. Its main goal is to facilitate decoding of chat
|
||||
* messages, particularly embedding special information into HTML tags.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef HANDLE_RICH_TEXT_H_
|
||||
#define HANDLE_RICH_TEXT_H_
|
||||
|
||||
|
||||
#include <QRegExp>
|
||||
#include <QtXml>
|
||||
|
||||
/* Flags for RsHtml::formatText */
|
||||
#define RSHTML_FORMATTEXT_EMBED_SMILEYS 1
|
||||
#define RSHTML_FORMATTEXT_EMBED_LINKS 2
|
||||
#define RSHTML_FORMATTEXT_REMOVE_FONT 4
|
||||
#define RSHTML_FORMATTEXT_REMOVE_COLOR 8
|
||||
#define RSHTML_FORMATTEXT_CLEANSTYLE (RSHTML_FORMATTEXT_REMOVE_FONT | RSHTML_FORMATTEXT_REMOVE_COLOR)
|
||||
#define RSHTML_FORMATTEXT_OPTIMIZE 16
|
||||
|
||||
/* Flags for RsHtml::formatText */
|
||||
#define RSHTML_OPTIMIZEHTML_REMOVE_FONT 2
|
||||
#define RSHTML_OPTIMIZEHTML_REMOVE_COLOR 1
|
||||
|
||||
class QTextEdit;
|
||||
|
||||
namespace RsHtml {
|
||||
|
||||
|
||||
/**
|
||||
* The type of embedding we'd like to do
|
||||
*/
|
||||
enum EmbeddedType
|
||||
{
|
||||
Ahref, ///< into <a></a>
|
||||
Img, ///< into <img/>
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Base class for storing information about a given kind of embedding.
|
||||
*
|
||||
* Its only constructor is protected so it is impossible to instantiate it, and
|
||||
* at the same time derived classes have to provide a type.
|
||||
*/
|
||||
class EmbedInHtml
|
||||
{
|
||||
protected:
|
||||
EmbedInHtml(EmbeddedType newType) :
|
||||
myType(newType)
|
||||
{}
|
||||
|
||||
public:
|
||||
const EmbeddedType myType;
|
||||
QRegExp myRE;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* This class is used to store information for embedding links into <a></a> tags.
|
||||
*/
|
||||
class EmbedInHtmlAhref : public EmbedInHtml
|
||||
{
|
||||
public:
|
||||
EmbedInHtmlAhref() :
|
||||
EmbedInHtml(Ahref)
|
||||
{
|
||||
myRE.setPattern("(\\bretroshare://[^\\s]*)|(\\bhttps?://[^\\s]*)|(\\bfile://[^\\s]*)|(\\bwww\\.[^\\s]*)");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This class is used to store information for embedding smileys into <img/> tags.
|
||||
*
|
||||
* By default the QRegExp the variables are empty, which means it must be
|
||||
* filled at runtime, typically when the smileys set is loaded. It can be
|
||||
* either done by hand or by using one of the helper methods available.
|
||||
*
|
||||
* Note: The QHash uses only *one* smiley per key (unlike soon-to-be-upgraded
|
||||
* code out there).
|
||||
*/
|
||||
class EmbedInHtmlImg : public EmbedInHtml
|
||||
{
|
||||
public:
|
||||
EmbedInHtmlImg() :
|
||||
EmbedInHtml(Img)
|
||||
{}
|
||||
|
||||
void InitFromAwkwardHash(const QHash<QString,QString>& hash);
|
||||
|
||||
QHash<QString,QString> smileys;
|
||||
};
|
||||
|
||||
extern EmbedInHtmlImg defEmbedImg;
|
||||
|
||||
QString formatText(const QString &text, unsigned int flag);
|
||||
bool findAnchors(const QString &text, QStringList& urls);
|
||||
|
||||
void optimizeHtml(QTextEdit *textEdit, QString &text, unsigned int flag = 0);
|
||||
void optimizeHtml(QString &text, unsigned int flag = 0);
|
||||
QString toHtml(QString text, bool realHtml = true);
|
||||
|
||||
} // namespace RsHtml
|
||||
|
||||
|
||||
#endif // HANDLE_RICH_TEXT_H_
|
|
@ -31,6 +31,7 @@
|
|||
#include <iostream>
|
||||
|
||||
#include "Emoticons.h"
|
||||
#include "util/HandleRichText.h"
|
||||
|
||||
static QHash<QString, QString> Smileys;
|
||||
|
||||
|
@ -118,7 +119,7 @@ void Emoticons::load()
|
|||
}
|
||||
|
||||
// init <img> embedder
|
||||
RsHtml::defEmbedImg.InitFromAwkwardHash(Smileys);
|
||||
RsHtml::initEmoticons(Smileys);
|
||||
}
|
||||
|
||||
void Emoticons::showSmileyWidget(QWidget *parent, QWidget *button, const char *slotAddMethod, bool above)
|
||||
|
@ -198,13 +199,13 @@ void Emoticons::showSmileyWidget(QWidget *parent, QWidget *button, const char *s
|
|||
smWidget->show();
|
||||
}
|
||||
|
||||
void Emoticons::formatText(QString &text)
|
||||
{
|
||||
QHashIterator<QString, QString> i(Smileys);
|
||||
while(i.hasNext()) {
|
||||
i.next();
|
||||
foreach (QString code, i.key().split("|")) {
|
||||
text.replace(code, "<img src=\"" + i.value() + "\">");
|
||||
}
|
||||
}
|
||||
}
|
||||
//void Emoticons::formatText(QString &text)
|
||||
//{
|
||||
// QHashIterator<QString, QString> i(Smileys);
|
||||
// while(i.hasNext()) {
|
||||
// i.next();
|
||||
// foreach (QString code, i.key().split("|")) {
|
||||
// text.replace(code, "<img src=\"" + i.value() + "\">");
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
|
|
@ -19,12 +19,9 @@
|
|||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
|
||||
#ifndef _EMOTICONS_H
|
||||
#define _EMOTICONS_H
|
||||
|
||||
#include "gui/chat/HandleRichText.h"
|
||||
|
||||
class QWidget;
|
||||
class QString;
|
||||
|
||||
|
@ -35,7 +32,7 @@ public:
|
|||
|
||||
static void showSmileyWidget(QWidget *parent, QWidget *button, const char *slotAddMethod, bool above);
|
||||
|
||||
static void formatText(QString &text);
|
||||
// static void formatText(QString &text);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#include "gui/notifyqt.h"
|
||||
#include "util/misc.h"
|
||||
#include "gui/RetroShareLink.h"
|
||||
#include "gui/chat/HandleRichText.h"
|
||||
#include "util/HandleRichText.h"
|
||||
|
||||
#include <retroshare/rschannels.h>
|
||||
|
||||
|
@ -123,7 +123,7 @@ void ChanMsgItem::updateItemStatic()
|
|||
{
|
||||
/* subject */
|
||||
titleLabel->setText(QString::fromStdWString(cmi.subject));
|
||||
subjectLabel->setText(RsHtml::formatText(QString::fromStdWString(cmi.msg), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS));
|
||||
subjectLabel->setText(RsHtml().formatText(NULL, QString::fromStdWString(cmi.msg), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS));
|
||||
|
||||
/* disable buttons: deletion facility not enabled with cache services yet */
|
||||
clearButton->setEnabled(false);
|
||||
|
@ -160,7 +160,7 @@ void ChanMsgItem::updateItemStatic()
|
|||
}
|
||||
}
|
||||
|
||||
msgLabel->setText(RsHtml::formatText(QString::fromStdWString(cmi.msg), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS));
|
||||
msgLabel->setText(RsHtml().formatText(NULL, QString::fromStdWString(cmi.msg), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS));
|
||||
msgWidget->setVisible(!cmi.msg.empty());
|
||||
|
||||
QDateTime qtime;
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#include "FeedHolder.h"
|
||||
#include "retroshare-gui/RsAutoUpdatePage.h"
|
||||
#include "gui/msgs/MessageComposer.h"
|
||||
#include "gui/chat/HandleRichText.h"
|
||||
#include "util/HandleRichText.h"
|
||||
#include "gui/common/AvatarDefs.h"
|
||||
#include "gui/settings/rsharesettings.h"
|
||||
|
||||
|
@ -155,7 +155,7 @@ void ChatMsgItem::insertChat(const std::string &message)
|
|||
formatFlag |= RSHTML_FORMATTEXT_EMBED_SMILEYS;
|
||||
}
|
||||
|
||||
formatMsg = RsHtml::formatText(formatMsg, formatFlag);
|
||||
formatMsg = RsHtml().formatText(NULL, formatMsg, formatFlag);
|
||||
|
||||
chatTextlabel->setText(formatMsg);
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
#include <retroshare/rspeers.h>
|
||||
|
||||
#include "gui/forums/CreateForumMsg.h"
|
||||
#include "gui/chat/HandleRichText.h"
|
||||
#include "util/HandleRichText.h"
|
||||
#include "gui/common/AvatarDefs.h"
|
||||
#include "gui/notifyqt.h"
|
||||
#include "gui/ForumsDialog.h"
|
||||
|
@ -155,7 +155,7 @@ void ForumMsgItem::updateItemStatic()
|
|||
}
|
||||
|
||||
prevSubLabel->setText(link.toHtml());
|
||||
prevMsgLabel->setText(RsHtml::formatText(ForumsDialog::messageFromInfo(msg), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS));
|
||||
prevMsgLabel->setText(RsHtml().formatText(NULL, ForumsDialog::messageFromInfo(msg), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS));
|
||||
|
||||
QDateTime qtime;
|
||||
qtime.setTime_t(msg.ts);
|
||||
|
@ -180,7 +180,7 @@ void ForumMsgItem::updateItemStatic()
|
|||
}
|
||||
|
||||
nextSubLabel->setText(link.toHtml());
|
||||
nextMsgLabel->setText(RsHtml::formatText(ForumsDialog::messageFromInfo(msg), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS));
|
||||
nextMsgLabel->setText(RsHtml().formatText(NULL, ForumsDialog::messageFromInfo(msg), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS));
|
||||
|
||||
QDateTime qtime;
|
||||
qtime.setTime_t(msg.ts);
|
||||
|
@ -197,7 +197,7 @@ void ForumMsgItem::updateItemStatic()
|
|||
RetroShareLink linkParent;
|
||||
linkParent.createForum(msgParent.forumId, msgParent.msgId);
|
||||
prevSubLabel->setText(linkParent.toHtml());
|
||||
prevMsgLabel->setText(RsHtml::formatText(ForumsDialog::messageFromInfo(msgParent), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS));
|
||||
prevMsgLabel->setText(RsHtml().formatText(NULL, ForumsDialog::messageFromInfo(msgParent), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS));
|
||||
|
||||
if (rsPeers->getPeerName(msgParent.srcId) !="")
|
||||
{
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#include "FeedHolder.h"
|
||||
#include "SubFileItem.h"
|
||||
#include "gui/msgs/MessageComposer.h"
|
||||
#include "gui/chat/HandleRichText.h"
|
||||
#include "util/HandleRichText.h"
|
||||
#include "gui/common/AvatarDefs.h"
|
||||
#include "gui/notifyqt.h"
|
||||
|
||||
|
@ -131,7 +131,7 @@ void MsgItem::updateItemStatic()
|
|||
titleLabel->setText(title);
|
||||
subjectLabel->setText(QString::fromStdWString(mi.title));
|
||||
|
||||
msgLabel->setText(RsHtml::formatText(QString::fromStdWString(mi.msg), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS));
|
||||
msgLabel->setText(RsHtml().formatText(NULL, QString::fromStdWString(mi.msg), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS));
|
||||
|
||||
std::list<FileInfo>::iterator it;
|
||||
for(it = mi.files.begin(); it != mi.files.end(); it++)
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include "ImHistoryBrowser.h"
|
||||
#include "IMHistoryItemDelegate.h"
|
||||
#include "IMHistoryItemPainter.h"
|
||||
#include "util/HandleRichText.h"
|
||||
|
||||
#include "rshare.h"
|
||||
#include <retroshare/rshistory.h>
|
||||
|
@ -254,10 +255,10 @@ void ImHistoryBrowser::historyChanged(uint msgId, int type)
|
|||
|
||||
void ImHistoryBrowser::fillItem(QListWidgetItem *itemWidget, HistoryMsg& msg)
|
||||
{
|
||||
unsigned int formatFlag = CHAT_FORMATMSG_EMBED_LINKS;
|
||||
unsigned int formatTextFlag = RSHTML_FORMATTEXT_EMBED_LINKS;
|
||||
|
||||
if (embedSmileys) {
|
||||
formatFlag |= CHAT_FORMATMSG_EMBED_SMILEYS;
|
||||
formatTextFlag |= RSHTML_FORMATTEXT_EMBED_SMILEYS;
|
||||
}
|
||||
|
||||
ChatStyle::enumFormatMessage type;
|
||||
|
@ -267,8 +268,8 @@ void ImHistoryBrowser::fillItem(QListWidgetItem *itemWidget, HistoryMsg& msg)
|
|||
type = ChatStyle::FORMATMSG_OUTGOING;
|
||||
}
|
||||
|
||||
QString messageText = QString::fromUtf8(msg.message.c_str());
|
||||
QString formatMsg = style.formatMessage(type, QString::fromUtf8(msg.peerName.c_str()), QDateTime::fromTime_t(msg.sendTime), messageText, formatFlag);
|
||||
QString messageText = RsHtml().formatText(NULL, QString::fromUtf8(msg.message.c_str()), formatTextFlag);
|
||||
QString formatMsg = style.formatMessage(type, QString::fromUtf8(msg.peerName.c_str()), QDateTime::fromTime_t(msg.sendTime), messageText);
|
||||
|
||||
itemWidget->setData(Qt::DisplayRole, qVariantFromValue(IMHistoryItemPainter(formatMsg)));
|
||||
itemWidget->setData(ROLE_MSGID, msg.msgId);
|
||||
|
|
|
@ -31,6 +31,8 @@
|
|||
#include <QTimer>
|
||||
#include <QCompleter>
|
||||
#include <QItemDelegate>
|
||||
#include <QDateTime>
|
||||
#include <QFileInfo>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
|
@ -55,7 +57,7 @@
|
|||
#include "TagsMenu.h"
|
||||
#include "gui/common/TagDefs.h"
|
||||
#include "gui/connect/ConfCertDialog.h"
|
||||
#include "gui/chat/HandleRichText.h"
|
||||
#include "util/HandleRichText.h"
|
||||
|
||||
#define IMAGE_GROUP16 ":/images/user/group16.png"
|
||||
#define IMAGE_FRIENDINFO ":/images/peerdetails_16x16.png"
|
||||
|
|
|
@ -25,6 +25,9 @@
|
|||
#include <QMessageBox>
|
||||
#include <QPrinter>
|
||||
#include <QPrintDialog>
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
#include <QTextCodec>
|
||||
|
||||
#include "gui/notifyqt.h"
|
||||
#include "gui/RetroShareLink.h"
|
||||
|
@ -37,6 +40,7 @@
|
|||
#include "MessageWindow.h"
|
||||
#include "util/misc.h"
|
||||
#include "util/printpreview.h"
|
||||
#include "util/HandleRichText.h"
|
||||
|
||||
#include <retroshare/rspeers.h>
|
||||
#include <retroshare/rsfiles.h>
|
||||
|
@ -51,6 +55,35 @@
|
|||
#define COLUMN_FILE_HASH 2
|
||||
#define COLUMN_FILE_COUNT 3
|
||||
|
||||
class RsHtmlMsg : public RsHtml
|
||||
{
|
||||
public:
|
||||
RsHtmlMsg(uint msgFlags) : RsHtml()
|
||||
{
|
||||
this->msgFlags = msgFlags;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void anchorTextForImg(QDomDocument &doc, QDomElement &element, const RetroShareLink &link, QString &text)
|
||||
{
|
||||
if (link.type() == RetroShareLink::TYPE_CERTIFICATE) {
|
||||
if (msgFlags & RS_MSG_USER_REQUEST) {
|
||||
text = QApplication::translate("MessageWidget", "Confirm %1 as friend").arg(link.name());
|
||||
return;
|
||||
}
|
||||
if (msgFlags & RS_MSG_FRIEND_RECOMMENDATION) {
|
||||
text = QApplication::translate("MessageWidget", "Add %1 as friend").arg(link.name());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
RsHtml::anchorTextForImg(doc, element, link, text);
|
||||
}
|
||||
|
||||
protected:
|
||||
uint msgFlags;
|
||||
};
|
||||
|
||||
MessageWidget *MessageWidget::openMsg(const std::string &msgId, bool window)
|
||||
{
|
||||
if (msgId.empty()) {
|
||||
|
@ -523,7 +556,7 @@ void MessageWidget::fill(const std::string &msgId)
|
|||
|
||||
ui.subjectText->setText(QString::fromStdWString(msgInfo.title));
|
||||
|
||||
text = RsHtml::formatText(QString::fromStdWString(msgInfo.msg), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS);
|
||||
text = RsHtmlMsg(msgInfo.msgflags).formatText(ui.msgText->document(), QString::fromStdWString(msgInfo.msg), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS | RSHTML_FORMATTEXT_REPLACE_LINKS);
|
||||
ui.msgText->setHtml(text);
|
||||
|
||||
ui.filesText->setText(QString("(%1 %2)").arg(msgInfo.count).arg(msgInfo.count == 1 ? tr("File") : tr("Files")));
|
||||
|
|
|
@ -206,12 +206,12 @@ void ChatPage::setPreviewMessages(QString &stylePath, QString styleVariant, QTex
|
|||
QString nameOutgoing = tr("Outgoing");
|
||||
QDateTime timestmp = QDateTime::fromTime_t(time(NULL));
|
||||
|
||||
textBrowser->append(style.formatMessage(ChatStyle::FORMATMSG_HINCOMING, nameIncoming, timestmp, tr("Incoming message in history"), CHAT_FORMATTEXT_EMBED_SMILEYS | CHAT_FORMATMSG_OPTIMIZE));
|
||||
textBrowser->append(style.formatMessage(ChatStyle::FORMATMSG_HOUTGOING, nameOutgoing, timestmp, tr("Outgoing message in history"), CHAT_FORMATTEXT_EMBED_SMILEYS | CHAT_FORMATMSG_OPTIMIZE));
|
||||
textBrowser->append(style.formatMessage(ChatStyle::FORMATMSG_INCOMING, nameIncoming, timestmp, tr("Incoming message"), CHAT_FORMATTEXT_EMBED_SMILEYS | CHAT_FORMATMSG_OPTIMIZE));
|
||||
textBrowser->append(style.formatMessage(ChatStyle::FORMATMSG_OUTGOING, nameOutgoing, timestmp, tr("Outgoing message"), CHAT_FORMATTEXT_EMBED_SMILEYS | CHAT_FORMATMSG_OPTIMIZE));
|
||||
textBrowser->append(style.formatMessage(ChatStyle::FORMATMSG_OOUTGOING, nameOutgoing, timestmp, tr("Outgoing offline message"), CHAT_FORMATTEXT_EMBED_SMILEYS | CHAT_FORMATMSG_OPTIMIZE));
|
||||
textBrowser->append(style.formatMessage(ChatStyle::FORMATMSG_SYSTEM, tr("System"), timestmp, tr("System message"), CHAT_FORMATTEXT_EMBED_SMILEYS | CHAT_FORMATMSG_OPTIMIZE));
|
||||
textBrowser->append(style.formatMessage(ChatStyle::FORMATMSG_HINCOMING, nameIncoming, timestmp, tr("Incoming message in history")));
|
||||
textBrowser->append(style.formatMessage(ChatStyle::FORMATMSG_HOUTGOING, nameOutgoing, timestmp, tr("Outgoing message in history")));
|
||||
textBrowser->append(style.formatMessage(ChatStyle::FORMATMSG_INCOMING, nameIncoming, timestmp, tr("Incoming message")));
|
||||
textBrowser->append(style.formatMessage(ChatStyle::FORMATMSG_OUTGOING, nameOutgoing, timestmp, tr("Outgoing message")));
|
||||
textBrowser->append(style.formatMessage(ChatStyle::FORMATMSG_OOUTGOING, nameOutgoing, timestmp, tr("Outgoing offline message")));
|
||||
textBrowser->append(style.formatMessage(ChatStyle::FORMATMSG_SYSTEM, tr("System"), timestmp, tr("System message")));
|
||||
}
|
||||
|
||||
void ChatPage::fillPreview(QListWidget *listWidget, QComboBox *comboBox, QTextBrowser *textBrowser)
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
#include "ChatLobbyToaster.h"
|
||||
#include "gui/chat/ChatDialog.h"
|
||||
#include "gui/chat/HandleRichText.h"
|
||||
#include "util/HandleRichText.h"
|
||||
|
||||
#include <retroshare/rsmsgs.h>
|
||||
|
||||
|
@ -36,7 +36,7 @@ ChatLobbyToaster::ChatLobbyToaster(const std::string &peerId, const QString &nam
|
|||
connect(ui.closeButton, SIGNAL(clicked()), SLOT(hide()));
|
||||
|
||||
/* set informations */
|
||||
ui.messageLabel->setText(RsHtml::formatText(message, RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS | RSHTML_FORMATTEXT_CLEANSTYLE));
|
||||
ui.messageLabel->setText(RsHtml().formatText(NULL, message, RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS | RSHTML_FORMATTEXT_CLEANSTYLE));
|
||||
ui.avatarWidget->setFrameType(AvatarWidget::NORMAL_FRAME);
|
||||
ui.avatarWidget->setDefaultAvatar(":images/user/agt_forum64.png");
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
#include "ChatToaster.h"
|
||||
#include "gui/chat/ChatDialog.h"
|
||||
#include "gui/chat/HandleRichText.h"
|
||||
#include "util/HandleRichText.h"
|
||||
|
||||
#include <retroshare/rspeers.h>
|
||||
|
||||
|
@ -36,7 +36,7 @@ ChatToaster::ChatToaster(const std::string &peerId, const QString &message) : QW
|
|||
connect(ui.closeButton, SIGNAL(clicked()), SLOT(hide()));
|
||||
|
||||
/* set informations */
|
||||
ui.messageLabel->setText(RsHtml::formatText(message, RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS | RSHTML_FORMATTEXT_CLEANSTYLE));
|
||||
ui.messageLabel->setText(RsHtml().formatText(NULL, message, RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS | RSHTML_FORMATTEXT_CLEANSTYLE));
|
||||
ui.nameLabel->setText(QString::fromUtf8(rsPeers->getPeerName(peerId).c_str()));
|
||||
ui.avatarWidget->setFrameType(AvatarWidget::STATUS_FRAME);
|
||||
ui.avatarWidget->setId(peerId, false);
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
#include "GroupChatToaster.h"
|
||||
#include "gui/FriendsDialog.h"
|
||||
#include "gui/chat/HandleRichText.h"
|
||||
#include "util/HandleRichText.h"
|
||||
|
||||
#include <retroshare/rspeers.h>
|
||||
|
||||
|
@ -34,7 +34,7 @@ GroupChatToaster::GroupChatToaster(const std::string &peerId, const QString &mes
|
|||
connect(ui.closeButton, SIGNAL(clicked()), SLOT(hide()));
|
||||
|
||||
/* set informations */
|
||||
ui.messageLabel->setText(RsHtml::formatText(message, RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS | RSHTML_FORMATTEXT_CLEANSTYLE));
|
||||
ui.messageLabel->setText(RsHtml().formatText(NULL, message, RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS | RSHTML_FORMATTEXT_CLEANSTYLE));
|
||||
ui.nameLabel->setText(QString::fromUtf8(rsPeers->getPeerName(peerId).c_str()));
|
||||
ui.avatarWidget->setFrameType(AvatarWidget::STATUS_FRAME);
|
||||
ui.avatarWidget->setDefaultAvatar(":/images/user/personal64.png");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue