mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -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
@ -263,6 +263,8 @@ HEADERS += rshare.h \
|
|||||||
util/printpreview.h \
|
util/printpreview.h \
|
||||||
util/log.h \
|
util/log.h \
|
||||||
util/misc.h \
|
util/misc.h \
|
||||||
|
util/HandleRichText.h \
|
||||||
|
util/ObjectPainter.h \
|
||||||
gui/bwgraph/bwgraph.h \
|
gui/bwgraph/bwgraph.h \
|
||||||
gui/profile/ProfileWidget.h \
|
gui/profile/ProfileWidget.h \
|
||||||
gui/profile/StatusMessage.h \
|
gui/profile/StatusMessage.h \
|
||||||
@ -274,7 +276,6 @@ HEADERS += rshare.h \
|
|||||||
gui/ChatLobbyWidget.h \
|
gui/ChatLobbyWidget.h \
|
||||||
gui/chat/ChatLobbyDialog.h \
|
gui/chat/ChatLobbyDialog.h \
|
||||||
gui/chat/CreateLobbyDialog.h \
|
gui/chat/CreateLobbyDialog.h \
|
||||||
gui/chat/HandleRichText.h \
|
|
||||||
gui/chat/ChatStyle.h \
|
gui/chat/ChatStyle.h \
|
||||||
gui/channels/CreateChannel.h \
|
gui/channels/CreateChannel.h \
|
||||||
gui/channels/ChannelDetails.h \
|
gui/channels/ChannelDetails.h \
|
||||||
@ -545,6 +546,8 @@ SOURCES += main.cpp \
|
|||||||
util/printpreview.cpp \
|
util/printpreview.cpp \
|
||||||
util/log.cpp \
|
util/log.cpp \
|
||||||
util/misc.cpp \
|
util/misc.cpp \
|
||||||
|
util/HandleRichText.cpp \
|
||||||
|
util/ObjectPainter.cpp \
|
||||||
gui/bwgraph/bwgraph.cpp \
|
gui/bwgraph/bwgraph.cpp \
|
||||||
gui/profile/ProfileWidget.cpp \
|
gui/profile/ProfileWidget.cpp \
|
||||||
gui/profile/StatusMessage.cpp \
|
gui/profile/StatusMessage.cpp \
|
||||||
@ -561,7 +564,6 @@ SOURCES += main.cpp \
|
|||||||
gui/ChatLobbyWidget.cpp \
|
gui/ChatLobbyWidget.cpp \
|
||||||
gui/chat/ChatLobbyDialog.cpp \
|
gui/chat/ChatLobbyDialog.cpp \
|
||||||
gui/chat/CreateLobbyDialog.cpp \
|
gui/chat/CreateLobbyDialog.cpp \
|
||||||
gui/chat/HandleRichText.cpp \
|
|
||||||
gui/chat/ChatStyle.cpp \
|
gui/chat/ChatStyle.cpp \
|
||||||
gui/connect/ConfCertDialog.cpp \
|
gui/connect/ConfCertDialog.cpp \
|
||||||
gui/connect/FriendRequest.cpp \
|
gui/connect/FriendRequest.cpp \
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
#include "RetroShareLink.h"
|
#include "RetroShareLink.h"
|
||||||
#include "channels/ShareKey.h"
|
#include "channels/ShareKey.h"
|
||||||
#include "notifyqt.h"
|
#include "notifyqt.h"
|
||||||
|
#include "util/HandleRichText.h"
|
||||||
|
|
||||||
#include <retroshare/rspeers.h>
|
#include <retroshare/rspeers.h>
|
||||||
#include <retroshare/rsforums.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.postText->setHtml(extraTxt);
|
||||||
ui.threadTitle->setText(titleFromInfo(msg));
|
ui.threadTitle->setText(titleFromInfo(msg));
|
||||||
|
@ -28,6 +28,9 @@
|
|||||||
#include <QFontDialog>
|
#include <QFontDialog>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
|
#include <QTextStream>
|
||||||
|
#include <QTextCodec>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
#include "retroshare/rsinit.h"
|
#include "retroshare/rsinit.h"
|
||||||
#include "retroshare/rsnotify.h"
|
#include "retroshare/rsnotify.h"
|
||||||
@ -55,6 +58,7 @@
|
|||||||
#include "RetroShareLink.h"
|
#include "RetroShareLink.h"
|
||||||
#include "settings/rsharesettings.h"
|
#include "settings/rsharesettings.h"
|
||||||
#include "util/misc.h"
|
#include "util/misc.h"
|
||||||
|
#include "util/HandleRichText.h"
|
||||||
#include "chat/CreateLobbyDialog.h"
|
#include "chat/CreateLobbyDialog.h"
|
||||||
#include "FriendRecommendDialog.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)
|
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 ?
|
// embed smileys ?
|
||||||
if (Settings->valueFromGroup("Chat", "Emoteicons_GroupChat", true).toBool()) {
|
if (Settings->valueFromGroup("Chat", "Emoteicons_GroupChat", true).toBool()) {
|
||||||
formatFlag |= CHAT_FORMATMSG_EMBED_SMILEYS;
|
formatTextFlag |= RSHTML_FORMATTEXT_EMBED_SMILEYS;
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatStyle::enumFormatMessage type;
|
ChatStyle::enumFormatMessage type;
|
||||||
@ -394,10 +398,9 @@ void FriendsDialog::addChatMsg(bool incoming, bool history, const QString &name,
|
|||||||
type = ChatStyle::FORMATMSG_OUTGOING;
|
type = ChatStyle::FORMATMSG_OUTGOING;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Remove <p>'s from older RetroShare versions before 31.01.2012 (can be removed later)
|
|
||||||
QString optimizedMessage = message;
|
QString formattedMessage = RsHtml().formatText(ui.msgText->document(), message, formatTextFlag);
|
||||||
RsHtml::optimizeHtml(optimizedMessage);
|
QString formatMsg = style.formatMessage(type, name, incoming ? recvTime : sendTime, formattedMessage);
|
||||||
QString formatMsg = style.formatMessage(type, name, incoming ? recvTime : sendTime, optimizedMessage, formatFlag);
|
|
||||||
|
|
||||||
ui.msgText->append(formatMsg);
|
ui.msgText->append(formatMsg);
|
||||||
}
|
}
|
||||||
|
@ -757,7 +757,7 @@ bool RetroShareLink::checkHash(const QString& hash)
|
|||||||
return true ;
|
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) {
|
if (list.size() == 0) {
|
||||||
return;
|
return;
|
||||||
@ -768,7 +768,7 @@ static void processList(QStringList &list, const QString &textSingular, const QS
|
|||||||
result += "" + textPlural + ":";
|
result += "" + textPlural + ":";
|
||||||
}
|
}
|
||||||
result += "<p style='margin-left: 5px; margin-top: 0px'>";
|
result += "<p style='margin-left: 5px; margin-top: 0px'>";
|
||||||
QStringList::iterator it;
|
QStringList::const_iterator it;
|
||||||
for (it = list.begin(); it != list.end(); ++it) {
|
for (it = list.begin(); it != list.end(); ++it) {
|
||||||
if (it != list.begin()) {
|
if (it != list.begin()) {
|
||||||
result += ", ";
|
result += ", ";
|
||||||
@ -778,9 +778,9 @@ static void processList(QStringList &list, const QString &textSingular, const QS
|
|||||||
result += "</p>";
|
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 */
|
/* filter dublicate links */
|
||||||
QList<RetroShareLink> links;
|
QList<RetroShareLink> links;
|
||||||
@ -798,7 +798,7 @@ static void processList(QStringList &list, const QString &textSingular, const QS
|
|||||||
QStringList personAdd;
|
QStringList personAdd;
|
||||||
|
|
||||||
for (linkIt = links.begin(); linkIt != links.end(); linkIt++) {
|
for (linkIt = links.begin(); linkIt != links.end(); linkIt++) {
|
||||||
RetroShareLink &link = *linkIt;
|
const RetroShareLink &link = *linkIt;
|
||||||
|
|
||||||
if (link.valid() == false) {
|
if (link.valid() == false) {
|
||||||
continue;
|
continue;
|
||||||
@ -897,7 +897,7 @@ static void processList(QStringList &list, const QString &textSingular, const QS
|
|||||||
// not needed: forumFound, channelFound, messageStarted
|
// not needed: forumFound, channelFound, messageStarted
|
||||||
|
|
||||||
for (linkIt = links.begin(); linkIt != links.end(); linkIt++) {
|
for (linkIt = links.begin(); linkIt != links.end(); linkIt++) {
|
||||||
RetroShareLink &link = *linkIt;
|
const RetroShareLink &link = *linkIt;
|
||||||
|
|
||||||
if (link.valid() == false) {
|
if (link.valid() == false) {
|
||||||
std::cerr << " RetroShareLink::process invalid request" << std::endl;
|
std::cerr << " RetroShareLink::process invalid request" << std::endl;
|
||||||
@ -1257,11 +1257,11 @@ static void processList(QStringList &list, const QString &textSingular, const QS
|
|||||||
return 0;
|
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;
|
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);
|
RetroShareLink link(*it);
|
||||||
if (link.valid() && (type == RetroShareLink::TYPE_UNKNOWN || link.type() == type)) {
|
if (link.valid() && (type == RetroShareLink::TYPE_UNKNOWN || link.type() == type)) {
|
||||||
links.append(link);
|
links.append(link);
|
||||||
|
@ -101,8 +101,8 @@ class RetroShareLink
|
|||||||
|
|
||||||
bool operator==(const RetroShareLink& l) const { return _type == l._type && _hash == l._hash ; }
|
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(const 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 QList<RetroShareLink> &links, uint flag = RSLINK_PROCESS_NOTIFY_ALL);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void fromString(const QString &url);
|
void fromString(const QString &url);
|
||||||
|
@ -101,11 +101,11 @@
|
|||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
|
#include <QXmlStreamReader>
|
||||||
|
|
||||||
#include "ChatStyle.h"
|
#include "ChatStyle.h"
|
||||||
#include "gui/settings/rsharesettings.h"
|
#include "gui/settings/rsharesettings.h"
|
||||||
#include "gui/notifyqt.h"
|
#include "gui/notifyqt.h"
|
||||||
#include "gui/common/Emoticons.h"
|
|
||||||
|
|
||||||
#include <retroshare/rsinit.h>
|
#include <retroshare/rsinit.h>
|
||||||
|
|
||||||
@ -301,19 +301,6 @@ QString ChatStyle::formatMessage(enumFormatMessage type, const QString &name, co
|
|||||||
m_style[type] = style;
|
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;
|
QColor color;
|
||||||
#ifdef COLORED_NICKNAMES
|
#ifdef COLORED_NICKNAMES
|
||||||
if (flag & CHAT_FORMATMSG_SYSTEM) {
|
if (flag & CHAT_FORMATMSG_SYSTEM) {
|
||||||
@ -332,12 +319,14 @@ QString ChatStyle::formatMessage(enumFormatMessage type, const QString &name, co
|
|||||||
|
|
||||||
color.setHsv(hash, 255, 150);
|
color.setHsv(hash, 255, 150);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
Q_UNUSED(flag);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QString formatMsg = style.replace("%name%", name)
|
QString formatMsg = style.replace("%name%", name)
|
||||||
.replace("%date%", timestamp.date().toString("dd.MM.yyyy"))
|
.replace("%date%", timestamp.date().toString("dd.MM.yyyy"))
|
||||||
.replace("%time%", timestamp.time().toString("hh:mm:ss"))
|
.replace("%time%", timestamp.time().toString("hh:mm:ss"))
|
||||||
.replace("%message%", msg)
|
.replace("%message%", message)
|
||||||
.replace("%color%", color.name());
|
.replace("%color%", color.name());
|
||||||
|
|
||||||
return formatMsg;
|
return formatMsg;
|
||||||
|
@ -30,14 +30,7 @@
|
|||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
|
||||||
/* Flags for ChatStyle::formatMessage */
|
/* Flags for ChatStyle::formatMessage */
|
||||||
#define CHAT_FORMATMSG_EMBED_SMILEYS 1
|
#define CHAT_FORMATMSG_SYSTEM 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 FORMATMSG_COUNT 6
|
#define FORMATMSG_COUNT 6
|
||||||
|
|
||||||
@ -89,7 +82,7 @@ public:
|
|||||||
bool setStylePath(const QString &stylePath, const QString &styleVariant);
|
bool setStylePath(const QString &stylePath, const QString &styleVariant);
|
||||||
bool setStyleFromSettings(enumStyleType styleType);
|
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 getAvailableStyles(enumStyleType styleType, QList<ChatStyleInfo> &styles);
|
||||||
static bool getAvailableVariants(const QString &stylePath, QStringList &variants);
|
static bool getAvailableVariants(const QString &stylePath, QStringList &variants);
|
||||||
|
@ -27,6 +27,9 @@
|
|||||||
#include <QColorDialog>
|
#include <QColorDialog>
|
||||||
#include <QFontDialog>
|
#include <QFontDialog>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <QTextStream>
|
||||||
|
#include <QTextCodec>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
#include "ChatWidget.h"
|
#include "ChatWidget.h"
|
||||||
#include "ui_ChatWidget.h"
|
#include "ui_ChatWidget.h"
|
||||||
@ -35,11 +38,11 @@
|
|||||||
#include "gui/settings/rsharesettings.h"
|
#include "gui/settings/rsharesettings.h"
|
||||||
#include "gui/settings/RsharePeerSettings.h"
|
#include "gui/settings/RsharePeerSettings.h"
|
||||||
#include "gui/im_history/ImHistoryBrowser.h"
|
#include "gui/im_history/ImHistoryBrowser.h"
|
||||||
#include "HandleRichText.h"
|
|
||||||
#include "gui/common/StatusDefs.h"
|
#include "gui/common/StatusDefs.h"
|
||||||
#include "gui/common/FilesDefs.h"
|
#include "gui/common/FilesDefs.h"
|
||||||
#include "gui/common/Emoticons.h"
|
#include "gui/common/Emoticons.h"
|
||||||
#include "util/misc.h"
|
#include "util/misc.h"
|
||||||
|
#include "util/HandleRichText.h"
|
||||||
|
|
||||||
#include <retroshare/rsstatus.h>
|
#include <retroshare/rsstatus.h>
|
||||||
#include <retroshare/rspeers.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;
|
std::cout << "ChatWidget::addChatMsg message : " << message.toStdString() << std::endl;
|
||||||
#endif
|
#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 ?
|
// embed smileys ?
|
||||||
if (Settings->valueFromGroup(QString("Chat"), QString::fromUtf8("Emoteicons_PrivatChat"), true).toBool()) {
|
if (Settings->valueFromGroup(QString("Chat"), QString::fromUtf8("Emoteicons_PrivatChat"), true).toBool()) {
|
||||||
formatFlag |= CHAT_FORMATMSG_EMBED_SMILEYS;
|
formatTextFlag |= RSHTML_FORMATTEXT_EMBED_SMILEYS;
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatStyle::enumFormatMessage type;
|
ChatStyle::enumFormatMessage type;
|
||||||
@ -327,7 +331,8 @@ void ChatWidget::addChatMsg(bool incoming, const QString &name, const QDateTime
|
|||||||
formatFlag |= CHAT_FORMATMSG_SYSTEM;
|
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);
|
ui->textBrowser->append(formatMsg);
|
||||||
|
|
||||||
@ -732,7 +737,7 @@ void ChatWidget::updatePeersCustomStateString(const QString& peer_id, const QStr
|
|||||||
ui->statusmessagelabel->hide();
|
ui->statusmessagelabel->hide();
|
||||||
} else {
|
} else {
|
||||||
ui->statusmessagelabel->show();
|
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);
|
ui->statusmessagelabel->setText(status_text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "Emoticons.h"
|
#include "Emoticons.h"
|
||||||
|
#include "util/HandleRichText.h"
|
||||||
|
|
||||||
static QHash<QString, QString> Smileys;
|
static QHash<QString, QString> Smileys;
|
||||||
|
|
||||||
@ -118,7 +119,7 @@ void Emoticons::load()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// init <img> embedder
|
// init <img> embedder
|
||||||
RsHtml::defEmbedImg.InitFromAwkwardHash(Smileys);
|
RsHtml::initEmoticons(Smileys);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Emoticons::showSmileyWidget(QWidget *parent, QWidget *button, const char *slotAddMethod, bool above)
|
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();
|
smWidget->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Emoticons::formatText(QString &text)
|
//void Emoticons::formatText(QString &text)
|
||||||
{
|
//{
|
||||||
QHashIterator<QString, QString> i(Smileys);
|
// QHashIterator<QString, QString> i(Smileys);
|
||||||
while(i.hasNext()) {
|
// while(i.hasNext()) {
|
||||||
i.next();
|
// i.next();
|
||||||
foreach (QString code, i.key().split("|")) {
|
// foreach (QString code, i.key().split("|")) {
|
||||||
text.replace(code, "<img src=\"" + i.value() + "\">");
|
// text.replace(code, "<img src=\"" + i.value() + "\">");
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
@ -19,12 +19,9 @@
|
|||||||
* Boston, MA 02110-1301, USA.
|
* Boston, MA 02110-1301, USA.
|
||||||
****************************************************************/
|
****************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#ifndef _EMOTICONS_H
|
#ifndef _EMOTICONS_H
|
||||||
#define _EMOTICONS_H
|
#define _EMOTICONS_H
|
||||||
|
|
||||||
#include "gui/chat/HandleRichText.h"
|
|
||||||
|
|
||||||
class QWidget;
|
class QWidget;
|
||||||
class QString;
|
class QString;
|
||||||
|
|
||||||
@ -35,7 +32,7 @@ public:
|
|||||||
|
|
||||||
static void showSmileyWidget(QWidget *parent, QWidget *button, const char *slotAddMethod, bool above);
|
static void showSmileyWidget(QWidget *parent, QWidget *button, const char *slotAddMethod, bool above);
|
||||||
|
|
||||||
static void formatText(QString &text);
|
// static void formatText(QString &text);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
#include "gui/notifyqt.h"
|
#include "gui/notifyqt.h"
|
||||||
#include "util/misc.h"
|
#include "util/misc.h"
|
||||||
#include "gui/RetroShareLink.h"
|
#include "gui/RetroShareLink.h"
|
||||||
#include "gui/chat/HandleRichText.h"
|
#include "util/HandleRichText.h"
|
||||||
|
|
||||||
#include <retroshare/rschannels.h>
|
#include <retroshare/rschannels.h>
|
||||||
|
|
||||||
@ -123,7 +123,7 @@ void ChanMsgItem::updateItemStatic()
|
|||||||
{
|
{
|
||||||
/* subject */
|
/* subject */
|
||||||
titleLabel->setText(QString::fromStdWString(cmi.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 */
|
/* disable buttons: deletion facility not enabled with cache services yet */
|
||||||
clearButton->setEnabled(false);
|
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());
|
msgWidget->setVisible(!cmi.msg.empty());
|
||||||
|
|
||||||
QDateTime qtime;
|
QDateTime qtime;
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
#include "FeedHolder.h"
|
#include "FeedHolder.h"
|
||||||
#include "retroshare-gui/RsAutoUpdatePage.h"
|
#include "retroshare-gui/RsAutoUpdatePage.h"
|
||||||
#include "gui/msgs/MessageComposer.h"
|
#include "gui/msgs/MessageComposer.h"
|
||||||
#include "gui/chat/HandleRichText.h"
|
#include "util/HandleRichText.h"
|
||||||
#include "gui/common/AvatarDefs.h"
|
#include "gui/common/AvatarDefs.h"
|
||||||
#include "gui/settings/rsharesettings.h"
|
#include "gui/settings/rsharesettings.h"
|
||||||
|
|
||||||
@ -155,7 +155,7 @@ void ChatMsgItem::insertChat(const std::string &message)
|
|||||||
formatFlag |= RSHTML_FORMATTEXT_EMBED_SMILEYS;
|
formatFlag |= RSHTML_FORMATTEXT_EMBED_SMILEYS;
|
||||||
}
|
}
|
||||||
|
|
||||||
formatMsg = RsHtml::formatText(formatMsg, formatFlag);
|
formatMsg = RsHtml().formatText(NULL, formatMsg, formatFlag);
|
||||||
|
|
||||||
chatTextlabel->setText(formatMsg);
|
chatTextlabel->setText(formatMsg);
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
#include <retroshare/rspeers.h>
|
#include <retroshare/rspeers.h>
|
||||||
|
|
||||||
#include "gui/forums/CreateForumMsg.h"
|
#include "gui/forums/CreateForumMsg.h"
|
||||||
#include "gui/chat/HandleRichText.h"
|
#include "util/HandleRichText.h"
|
||||||
#include "gui/common/AvatarDefs.h"
|
#include "gui/common/AvatarDefs.h"
|
||||||
#include "gui/notifyqt.h"
|
#include "gui/notifyqt.h"
|
||||||
#include "gui/ForumsDialog.h"
|
#include "gui/ForumsDialog.h"
|
||||||
@ -155,7 +155,7 @@ void ForumMsgItem::updateItemStatic()
|
|||||||
}
|
}
|
||||||
|
|
||||||
prevSubLabel->setText(link.toHtml());
|
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;
|
QDateTime qtime;
|
||||||
qtime.setTime_t(msg.ts);
|
qtime.setTime_t(msg.ts);
|
||||||
@ -180,7 +180,7 @@ void ForumMsgItem::updateItemStatic()
|
|||||||
}
|
}
|
||||||
|
|
||||||
nextSubLabel->setText(link.toHtml());
|
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;
|
QDateTime qtime;
|
||||||
qtime.setTime_t(msg.ts);
|
qtime.setTime_t(msg.ts);
|
||||||
@ -197,7 +197,7 @@ void ForumMsgItem::updateItemStatic()
|
|||||||
RetroShareLink linkParent;
|
RetroShareLink linkParent;
|
||||||
linkParent.createForum(msgParent.forumId, msgParent.msgId);
|
linkParent.createForum(msgParent.forumId, msgParent.msgId);
|
||||||
prevSubLabel->setText(linkParent.toHtml());
|
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) !="")
|
if (rsPeers->getPeerName(msgParent.srcId) !="")
|
||||||
{
|
{
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
#include "FeedHolder.h"
|
#include "FeedHolder.h"
|
||||||
#include "SubFileItem.h"
|
#include "SubFileItem.h"
|
||||||
#include "gui/msgs/MessageComposer.h"
|
#include "gui/msgs/MessageComposer.h"
|
||||||
#include "gui/chat/HandleRichText.h"
|
#include "util/HandleRichText.h"
|
||||||
#include "gui/common/AvatarDefs.h"
|
#include "gui/common/AvatarDefs.h"
|
||||||
#include "gui/notifyqt.h"
|
#include "gui/notifyqt.h"
|
||||||
|
|
||||||
@ -131,7 +131,7 @@ void MsgItem::updateItemStatic()
|
|||||||
titleLabel->setText(title);
|
titleLabel->setText(title);
|
||||||
subjectLabel->setText(QString::fromStdWString(mi.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;
|
std::list<FileInfo>::iterator it;
|
||||||
for(it = mi.files.begin(); it != mi.files.end(); it++)
|
for(it = mi.files.begin(); it != mi.files.end(); it++)
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#include "ImHistoryBrowser.h"
|
#include "ImHistoryBrowser.h"
|
||||||
#include "IMHistoryItemDelegate.h"
|
#include "IMHistoryItemDelegate.h"
|
||||||
#include "IMHistoryItemPainter.h"
|
#include "IMHistoryItemPainter.h"
|
||||||
|
#include "util/HandleRichText.h"
|
||||||
|
|
||||||
#include "rshare.h"
|
#include "rshare.h"
|
||||||
#include <retroshare/rshistory.h>
|
#include <retroshare/rshistory.h>
|
||||||
@ -254,10 +255,10 @@ void ImHistoryBrowser::historyChanged(uint msgId, int type)
|
|||||||
|
|
||||||
void ImHistoryBrowser::fillItem(QListWidgetItem *itemWidget, HistoryMsg& msg)
|
void ImHistoryBrowser::fillItem(QListWidgetItem *itemWidget, HistoryMsg& msg)
|
||||||
{
|
{
|
||||||
unsigned int formatFlag = CHAT_FORMATMSG_EMBED_LINKS;
|
unsigned int formatTextFlag = RSHTML_FORMATTEXT_EMBED_LINKS;
|
||||||
|
|
||||||
if (embedSmileys) {
|
if (embedSmileys) {
|
||||||
formatFlag |= CHAT_FORMATMSG_EMBED_SMILEYS;
|
formatTextFlag |= RSHTML_FORMATTEXT_EMBED_SMILEYS;
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatStyle::enumFormatMessage type;
|
ChatStyle::enumFormatMessage type;
|
||||||
@ -267,8 +268,8 @@ void ImHistoryBrowser::fillItem(QListWidgetItem *itemWidget, HistoryMsg& msg)
|
|||||||
type = ChatStyle::FORMATMSG_OUTGOING;
|
type = ChatStyle::FORMATMSG_OUTGOING;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString messageText = QString::fromUtf8(msg.message.c_str());
|
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, formatFlag);
|
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(Qt::DisplayRole, qVariantFromValue(IMHistoryItemPainter(formatMsg)));
|
||||||
itemWidget->setData(ROLE_MSGID, msg.msgId);
|
itemWidget->setData(ROLE_MSGID, msg.msgId);
|
||||||
|
@ -31,6 +31,8 @@
|
|||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QCompleter>
|
#include <QCompleter>
|
||||||
#include <QItemDelegate>
|
#include <QItemDelegate>
|
||||||
|
#include <QDateTime>
|
||||||
|
#include <QFileInfo>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
@ -55,7 +57,7 @@
|
|||||||
#include "TagsMenu.h"
|
#include "TagsMenu.h"
|
||||||
#include "gui/common/TagDefs.h"
|
#include "gui/common/TagDefs.h"
|
||||||
#include "gui/connect/ConfCertDialog.h"
|
#include "gui/connect/ConfCertDialog.h"
|
||||||
#include "gui/chat/HandleRichText.h"
|
#include "util/HandleRichText.h"
|
||||||
|
|
||||||
#define IMAGE_GROUP16 ":/images/user/group16.png"
|
#define IMAGE_GROUP16 ":/images/user/group16.png"
|
||||||
#define IMAGE_FRIENDINFO ":/images/peerdetails_16x16.png"
|
#define IMAGE_FRIENDINFO ":/images/peerdetails_16x16.png"
|
||||||
|
@ -25,6 +25,9 @@
|
|||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QPrinter>
|
#include <QPrinter>
|
||||||
#include <QPrintDialog>
|
#include <QPrintDialog>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QTextStream>
|
||||||
|
#include <QTextCodec>
|
||||||
|
|
||||||
#include "gui/notifyqt.h"
|
#include "gui/notifyqt.h"
|
||||||
#include "gui/RetroShareLink.h"
|
#include "gui/RetroShareLink.h"
|
||||||
@ -37,6 +40,7 @@
|
|||||||
#include "MessageWindow.h"
|
#include "MessageWindow.h"
|
||||||
#include "util/misc.h"
|
#include "util/misc.h"
|
||||||
#include "util/printpreview.h"
|
#include "util/printpreview.h"
|
||||||
|
#include "util/HandleRichText.h"
|
||||||
|
|
||||||
#include <retroshare/rspeers.h>
|
#include <retroshare/rspeers.h>
|
||||||
#include <retroshare/rsfiles.h>
|
#include <retroshare/rsfiles.h>
|
||||||
@ -51,6 +55,35 @@
|
|||||||
#define COLUMN_FILE_HASH 2
|
#define COLUMN_FILE_HASH 2
|
||||||
#define COLUMN_FILE_COUNT 3
|
#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)
|
MessageWidget *MessageWidget::openMsg(const std::string &msgId, bool window)
|
||||||
{
|
{
|
||||||
if (msgId.empty()) {
|
if (msgId.empty()) {
|
||||||
@ -523,7 +556,7 @@ void MessageWidget::fill(const std::string &msgId)
|
|||||||
|
|
||||||
ui.subjectText->setText(QString::fromStdWString(msgInfo.title));
|
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.msgText->setHtml(text);
|
||||||
|
|
||||||
ui.filesText->setText(QString("(%1 %2)").arg(msgInfo.count).arg(msgInfo.count == 1 ? tr("File") : tr("Files")));
|
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");
|
QString nameOutgoing = tr("Outgoing");
|
||||||
QDateTime timestmp = QDateTime::fromTime_t(time(NULL));
|
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_HINCOMING, nameIncoming, timestmp, tr("Incoming message in history")));
|
||||||
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_HOUTGOING, nameOutgoing, timestmp, tr("Outgoing message in history")));
|
||||||
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_INCOMING, nameIncoming, timestmp, tr("Incoming message")));
|
||||||
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_OUTGOING, nameOutgoing, timestmp, tr("Outgoing message")));
|
||||||
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_OOUTGOING, nameOutgoing, timestmp, tr("Outgoing offline message")));
|
||||||
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_SYSTEM, tr("System"), timestmp, tr("System message")));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatPage::fillPreview(QListWidget *listWidget, QComboBox *comboBox, QTextBrowser *textBrowser)
|
void ChatPage::fillPreview(QListWidget *listWidget, QComboBox *comboBox, QTextBrowser *textBrowser)
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
#include "ChatLobbyToaster.h"
|
#include "ChatLobbyToaster.h"
|
||||||
#include "gui/chat/ChatDialog.h"
|
#include "gui/chat/ChatDialog.h"
|
||||||
#include "gui/chat/HandleRichText.h"
|
#include "util/HandleRichText.h"
|
||||||
|
|
||||||
#include <retroshare/rsmsgs.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()));
|
connect(ui.closeButton, SIGNAL(clicked()), SLOT(hide()));
|
||||||
|
|
||||||
/* set informations */
|
/* 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->setFrameType(AvatarWidget::NORMAL_FRAME);
|
||||||
ui.avatarWidget->setDefaultAvatar(":images/user/agt_forum64.png");
|
ui.avatarWidget->setDefaultAvatar(":images/user/agt_forum64.png");
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
#include "ChatToaster.h"
|
#include "ChatToaster.h"
|
||||||
#include "gui/chat/ChatDialog.h"
|
#include "gui/chat/ChatDialog.h"
|
||||||
#include "gui/chat/HandleRichText.h"
|
#include "util/HandleRichText.h"
|
||||||
|
|
||||||
#include <retroshare/rspeers.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()));
|
connect(ui.closeButton, SIGNAL(clicked()), SLOT(hide()));
|
||||||
|
|
||||||
/* set informations */
|
/* 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.nameLabel->setText(QString::fromUtf8(rsPeers->getPeerName(peerId).c_str()));
|
||||||
ui.avatarWidget->setFrameType(AvatarWidget::STATUS_FRAME);
|
ui.avatarWidget->setFrameType(AvatarWidget::STATUS_FRAME);
|
||||||
ui.avatarWidget->setId(peerId, false);
|
ui.avatarWidget->setId(peerId, false);
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
#include "GroupChatToaster.h"
|
#include "GroupChatToaster.h"
|
||||||
#include "gui/FriendsDialog.h"
|
#include "gui/FriendsDialog.h"
|
||||||
#include "gui/chat/HandleRichText.h"
|
#include "util/HandleRichText.h"
|
||||||
|
|
||||||
#include <retroshare/rspeers.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()));
|
connect(ui.closeButton, SIGNAL(clicked()), SLOT(hide()));
|
||||||
|
|
||||||
/* set informations */
|
/* 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.nameLabel->setText(QString::fromUtf8(rsPeers->getPeerName(peerId).c_str()));
|
||||||
ui.avatarWidget->setFrameType(AvatarWidget::STATUS_FRAME);
|
ui.avatarWidget->setFrameType(AvatarWidget::STATUS_FRAME);
|
||||||
ui.avatarWidget->setDefaultAvatar(":/images/user/personal64.png");
|
ui.avatarWidget->setDefaultAvatar(":/images/user/personal64.png");
|
||||||
|
Binary file not shown.
@ -1502,7 +1502,7 @@ p, li { white-space: pre-wrap; }
|
|||||||
<context>
|
<context>
|
||||||
<name>ChatStyle</name>
|
<name>ChatStyle</name>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../gui/chat/ChatStyle.cpp" line="+454"/>
|
<location filename="../gui/chat/ChatStyle.cpp" line="+443"/>
|
||||||
<source>Standard style for group chat</source>
|
<source>Standard style for group chat</source>
|
||||||
<translation>Standard Stil für den Gruppenchat</translation>
|
<translation>Standard Stil für den Gruppenchat</translation>
|
||||||
</message>
|
</message>
|
||||||
@ -1646,7 +1646,7 @@ p, li { white-space: pre-wrap; }
|
|||||||
<translation>Schriftart auf den Standard setzen</translation>
|
<translation>Schriftart auf den Standard setzen</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../gui/chat/ChatWidget.cpp" line="+380"/>
|
<location filename="../gui/chat/ChatWidget.cpp" line="+385"/>
|
||||||
<source>Paste RetroShare Link</source>
|
<source>Paste RetroShare Link</source>
|
||||||
<translation>RetroShare Link einfügen</translation>
|
<translation>RetroShare Link einfügen</translation>
|
||||||
</message>
|
</message>
|
||||||
@ -4606,7 +4606,7 @@ p, li { white-space: pre-wrap; }
|
|||||||
<translation>Du kannst einem anonymen Autor nicht antworten</translation>
|
<translation>Du kannst einem anonymen Autor nicht antworten</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location line="-1373"/>
|
<location line="-1372"/>
|
||||||
<source>Your Forums</source>
|
<source>Your Forums</source>
|
||||||
<translation>Deine Foren</translation>
|
<translation>Deine Foren</translation>
|
||||||
</message>
|
</message>
|
||||||
@ -4771,7 +4771,7 @@ p, li { white-space: pre-wrap; }
|
|||||||
<translation>Druckvorschau</translation>
|
<translation>Druckvorschau</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../gui/ForumsDialog.cpp" line="+148"/>
|
<location filename="../gui/ForumsDialog.cpp" line="+147"/>
|
||||||
<location line="+1127"/>
|
<location line="+1127"/>
|
||||||
<source>Start New Thread</source>
|
<source>Start New Thread</source>
|
||||||
<translation>Erstelle neues Thema</translation>
|
<translation>Erstelle neues Thema</translation>
|
||||||
@ -5602,7 +5602,7 @@ p, li { white-space: pre-wrap; }
|
|||||||
<translation>Löscht den gespeicherten und angezeigten Chat Verlauf</translation>
|
<translation>Löscht den gespeicherten und angezeigten Chat Verlauf</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../gui/FriendsDialog.cpp" line="+99"/>
|
<location filename="../gui/FriendsDialog.cpp" line="+103"/>
|
||||||
<source>Chat lobbies</source>
|
<source>Chat lobbies</source>
|
||||||
<translation>Chat Lobbies</translation>
|
<translation>Chat Lobbies</translation>
|
||||||
</message>
|
</message>
|
||||||
@ -5740,7 +5740,7 @@ p, li { white-space: pre-wrap; }
|
|||||||
<translation>tippt...</translation>
|
<translation>tippt...</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location line="+118"/>
|
<location line="+117"/>
|
||||||
<location line="+2"/>
|
<location line="+2"/>
|
||||||
<source>New group chat</source>
|
<source>New group chat</source>
|
||||||
<translation>Neuer Gruppenchat</translation>
|
<translation>Neuer Gruppenchat</translation>
|
||||||
@ -7222,7 +7222,7 @@ p, li { white-space: pre-wrap; }
|
|||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location line="+61"/>
|
<location line="+61"/>
|
||||||
<location filename="../gui/im_history/ImHistoryBrowser.cpp" line="+364"/>
|
<location filename="../gui/im_history/ImHistoryBrowser.cpp" line="+365"/>
|
||||||
<source>Copy</source>
|
<source>Copy</source>
|
||||||
<translation>Kopieren</translation>
|
<translation>Kopieren</translation>
|
||||||
</message>
|
</message>
|
||||||
@ -7673,7 +7673,7 @@ Bitte gib etwas Speicher frei und drücke OK.</translation>
|
|||||||
<name>MessageComposer</name>
|
<name>MessageComposer</name>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../gui/msgs/MessageComposer.ui" line="+17"/>
|
<location filename="../gui/msgs/MessageComposer.ui" line="+17"/>
|
||||||
<location filename="../gui/msgs/MessageComposer.cpp" line="+744"/>
|
<location filename="../gui/msgs/MessageComposer.cpp" line="+746"/>
|
||||||
<source>Compose</source>
|
<source>Compose</source>
|
||||||
<translation>Verfassen</translation>
|
<translation>Verfassen</translation>
|
||||||
</message>
|
</message>
|
||||||
@ -8390,7 +8390,17 @@ p, li { white-space: pre-wrap; }
|
|||||||
<translation>Druckvorschau</translation>
|
<translation>Druckvorschau</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../gui/msgs/MessageWidget.cpp" line="+225"/>
|
<location filename="../gui/msgs/MessageWidget.cpp" line="+71"/>
|
||||||
|
<source>Confirm %1 as friend</source>
|
||||||
|
<translation>%1 als Freund bestätigen</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location line="+4"/>
|
||||||
|
<source>Add %1 as friend</source>
|
||||||
|
<translation>%1 als Freund hinzufügen</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location line="+183"/>
|
||||||
<source>No subject</source>
|
<source>No subject</source>
|
||||||
<translation>Kein Betreff</translation>
|
<translation>Kein Betreff</translation>
|
||||||
</message>
|
</message>
|
||||||
@ -10184,7 +10194,7 @@ p, li { white-space: pre-wrap; }
|
|||||||
<translation type="obsolete">Formular</translation>
|
<translation type="obsolete">Formular</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../gui/settings/PluginItem.ui" line="+241"/>
|
<location filename="../gui/settings/PluginItem.ui" line="+235"/>
|
||||||
<source>Status: </source>
|
<source>Status: </source>
|
||||||
<translation>Status:</translation>
|
<translation>Status:</translation>
|
||||||
</message>
|
</message>
|
||||||
@ -10194,7 +10204,7 @@ p, li { white-space: pre-wrap; }
|
|||||||
<translation>Datei Prüfsumme:</translation>
|
<translation>Datei Prüfsumme:</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location line="-84"/>
|
<location line="-78"/>
|
||||||
<source><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
|
<source><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
|
||||||
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
|
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
|
||||||
p, li { white-space: pre-wrap; }
|
p, li { white-space: pre-wrap; }
|
||||||
@ -10207,7 +10217,7 @@ p, li { white-space: pre-wrap; }
|
|||||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><a href="more"><span style=" text-decoration: underline; color:#0000ff;">mehr...</span></a></p></body></html></translation>
|
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><a href="more"><span style=" text-decoration: underline; color:#0000ff;">mehr...</span></a></p></body></html></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location line="+61"/>
|
<location line="+55"/>
|
||||||
<source>File name: </source>
|
<source>File name: </source>
|
||||||
<translation>Dateiname:</translation>
|
<translation>Dateiname:</translation>
|
||||||
</message>
|
</message>
|
||||||
|
@ -20,16 +20,77 @@
|
|||||||
****************************************************************/
|
****************************************************************/
|
||||||
|
|
||||||
#include <QTextBrowser>
|
#include <QTextBrowser>
|
||||||
|
#include <QtXml>
|
||||||
|
|
||||||
#include "HandleRichText.h"
|
#include "HandleRichText.h"
|
||||||
#include "gui/RetroShareLink.h"
|
#include "gui/RetroShareLink.h"
|
||||||
|
#include "util/ObjectPainter.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
namespace RsHtml {
|
/**
|
||||||
|
* The type of embedding we'd like to do
|
||||||
|
*/
|
||||||
|
enum EmbeddedType
|
||||||
|
{
|
||||||
|
Ahref, ///< into <a></a>
|
||||||
|
Img ///< into <img/>
|
||||||
|
};
|
||||||
|
|
||||||
EmbedInHtmlImg defEmbedImg;
|
/**
|
||||||
|
* 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) {}
|
||||||
|
|
||||||
void EmbedInHtmlImg::InitFromAwkwardHash(const QHash< QString, QString >& hash)
|
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) {}
|
||||||
|
|
||||||
|
QHash<QString,QString> smileys;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* global instance for embedding emoticons */
|
||||||
|
static EmbedInHtmlImg defEmbedImg;
|
||||||
|
|
||||||
|
RsHtml::RsHtml()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void RsHtml::initEmoticons(const QHash< QString, QString >& hash)
|
||||||
{
|
{
|
||||||
QString newRE;
|
QString newRE;
|
||||||
for(QHash<QString,QString>::const_iterator it = hash.begin(); it != hash.end(); ++it)
|
for(QHash<QString,QString>::const_iterator it = hash.begin(); it != hash.end(); ++it)
|
||||||
@ -37,11 +98,103 @@ void EmbedInHtmlImg::InitFromAwkwardHash(const QHash< QString, QString >& hash)
|
|||||||
if (smile.isEmpty()) {
|
if (smile.isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
smileys.insert(smile, it.value());
|
defEmbedImg.smileys.insert(smile, it.value());
|
||||||
newRE += "(" + QRegExp::escape(smile) + ")|";
|
newRE += "(" + QRegExp::escape(smile) + ")|";
|
||||||
}
|
}
|
||||||
newRE.chop(1); // remove last |
|
newRE.chop(1); // remove last |
|
||||||
myRE.setPattern(newRE);
|
defEmbedImg.myRE.setPattern(newRE);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RsHtml::canReplaceAnchor(QDomDocument &/*doc*/, QDomElement &/*element*/, const RetroShareLink &link)
|
||||||
|
{
|
||||||
|
switch (link.type()) {
|
||||||
|
case RetroShareLink::TYPE_UNKNOWN:
|
||||||
|
case RetroShareLink::TYPE_FILE:
|
||||||
|
case RetroShareLink::TYPE_PERSON:
|
||||||
|
case RetroShareLink::TYPE_FORUM:
|
||||||
|
case RetroShareLink::TYPE_CHANNEL:
|
||||||
|
case RetroShareLink::TYPE_SEARCH:
|
||||||
|
case RetroShareLink::TYPE_MESSAGE:
|
||||||
|
// not yet implemented
|
||||||
|
break;
|
||||||
|
|
||||||
|
case RetroShareLink::TYPE_CERTIFICATE:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RsHtml::anchorTextForImg(QDomDocument &/*doc*/, QDomElement &/*element*/, const RetroShareLink &link, QString &text)
|
||||||
|
{
|
||||||
|
text = link.niceName();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RsHtml::anchorStylesheetForImg(QDomDocument &/*doc*/, QDomElement &/*element*/, const RetroShareLink &link, QString &styleSheet)
|
||||||
|
{
|
||||||
|
switch (link.type()) {
|
||||||
|
case RetroShareLink::TYPE_UNKNOWN:
|
||||||
|
case RetroShareLink::TYPE_FILE:
|
||||||
|
case RetroShareLink::TYPE_PERSON:
|
||||||
|
case RetroShareLink::TYPE_FORUM:
|
||||||
|
case RetroShareLink::TYPE_CHANNEL:
|
||||||
|
case RetroShareLink::TYPE_SEARCH:
|
||||||
|
case RetroShareLink::TYPE_MESSAGE:
|
||||||
|
// not yet implemented
|
||||||
|
break;
|
||||||
|
|
||||||
|
case RetroShareLink::TYPE_CERTIFICATE:
|
||||||
|
styleSheet = "";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void RsHtml::replaceAnchorWithImg(QDomDocument &doc, QDomElement &element, QTextDocument *textDocument, const RetroShareLink &link)
|
||||||
|
{
|
||||||
|
if (!textDocument) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!link.valid()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (element.childNodes().length() != 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!canReplaceAnchor(doc, element, link)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString imgText;
|
||||||
|
anchorTextForImg(doc, element, link, imgText);
|
||||||
|
|
||||||
|
QString styleSheet;
|
||||||
|
anchorStylesheetForImg(doc, element, link, styleSheet);
|
||||||
|
|
||||||
|
QDomNode childNode = element.firstChild();
|
||||||
|
|
||||||
|
|
||||||
|
/* build resource name */
|
||||||
|
QString resourceName = QString("%1_%2.png").arg(link.type()).arg(imgText);
|
||||||
|
|
||||||
|
if (!textDocument->resource(QTextDocument::ImageResource, QUrl(resourceName)).isValid()) {
|
||||||
|
/* draw a button on a pixmap */
|
||||||
|
QPixmap pixmap;
|
||||||
|
ObjectPainter::drawButton(imgText, styleSheet, pixmap);
|
||||||
|
|
||||||
|
/* add the image to the resource cache of the text document */
|
||||||
|
textDocument->addResource(QTextDocument::ImageResource, QUrl(resourceName), QVariant(pixmap));
|
||||||
|
}
|
||||||
|
|
||||||
|
element.removeChild(childNode);
|
||||||
|
|
||||||
|
/* replace text of the anchor with <img> */
|
||||||
|
QDomElement img = doc.createElement("img");
|
||||||
|
img.setAttribute("src", resourceName);
|
||||||
|
|
||||||
|
element.appendChild(img);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -61,7 +214,7 @@ void EmbedInHtmlImg::InitFromAwkwardHash(const QHash< QString, QString >& hash)
|
|||||||
* @param[in,out] currentElement The current node (which is of type Element)
|
* @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
|
* @param[in] embedInfos The regular expression and the type of embedding to use
|
||||||
*/
|
*/
|
||||||
static void embedHtml(QDomDocument& doc, QDomElement& currentElement, EmbedInHtml& embedInfos)
|
void RsHtml::embedHtml(QTextDocument *textDocument, QDomDocument& doc, QDomElement& currentElement, EmbedInHtml& embedInfos, ulong flag)
|
||||||
{
|
{
|
||||||
if(embedInfos.myRE.pattern().length() == 0) // we'll get stuck with an empty regexp
|
if(embedInfos.myRE.pattern().length() == 0) // we'll get stuck with an empty regexp
|
||||||
return;
|
return;
|
||||||
@ -75,16 +228,31 @@ static void embedHtml(QDomDocument& doc, QDomElement& currentElement, EmbedInHtm
|
|||||||
if(element.tagName().toLower() == "head") {
|
if(element.tagName().toLower() == "head") {
|
||||||
// skip it
|
// skip it
|
||||||
} else if (element.tagName().toLower() == "a") {
|
} else if (element.tagName().toLower() == "a") {
|
||||||
// skip it, but add title if not available
|
// skip it
|
||||||
|
if (embedInfos.myType == Ahref) {
|
||||||
|
// but add title if not available
|
||||||
if (element.attribute("title").isEmpty()) {
|
if (element.attribute("title").isEmpty()) {
|
||||||
RetroShareLink link(element.attribute("href"));
|
RetroShareLink link(element.attribute("href"));
|
||||||
|
if (link.valid()) {
|
||||||
QString title = link.title();
|
QString title = link.title();
|
||||||
if (!title.isEmpty()) {
|
if (!title.isEmpty()) {
|
||||||
element.setAttribute("title", title);
|
element.setAttribute("title", title);
|
||||||
}
|
}
|
||||||
|
if (textDocument && (flag & RSHTML_FORMATTEXT_REPLACE_LINKS)) {
|
||||||
|
replaceAnchorWithImg(doc, element, textDocument, link);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
embedHtml(doc, element, embedInfos);
|
if (textDocument && (flag & RSHTML_FORMATTEXT_REPLACE_LINKS)) {
|
||||||
|
RetroShareLink link(element.attribute("href"));
|
||||||
|
if (link.valid()) {
|
||||||
|
replaceAnchorWithImg(doc, element, textDocument, link);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
embedHtml(textDocument, doc, element, embedInfos, flag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(node.isText()) {
|
else if(node.isText()) {
|
||||||
@ -109,16 +277,22 @@ static void embedHtml(QDomDocument& doc, QDomElement& currentElement, EmbedInHtm
|
|||||||
switch(embedInfos.myType) {
|
switch(embedInfos.myType) {
|
||||||
case Ahref:
|
case Ahref:
|
||||||
{
|
{
|
||||||
|
RetroShareLink link(embedInfos.myRE.cap(0));
|
||||||
|
if (link.valid()) {
|
||||||
insertedTag = doc.createElement("a");
|
insertedTag = doc.createElement("a");
|
||||||
insertedTag.setAttribute("href", embedInfos.myRE.cap(0));
|
insertedTag.setAttribute("href", embedInfos.myRE.cap(0));
|
||||||
|
|
||||||
RetroShareLink link(embedInfos.myRE.cap(0));
|
|
||||||
QString title = link.title();
|
QString title = link.title();
|
||||||
if (!title.isEmpty()) {
|
if (!title.isEmpty()) {
|
||||||
insertedTag.setAttribute("title", title);
|
insertedTag.setAttribute("title", title);
|
||||||
}
|
}
|
||||||
|
|
||||||
insertedTag.appendChild(doc.createTextNode(embedInfos.myRE.cap(0)));
|
insertedTag.appendChild(doc.createTextNode(embedInfos.myRE.cap(0)));
|
||||||
|
|
||||||
|
if (textDocument && (flag & RSHTML_FORMATTEXT_REPLACE_LINKS)) {
|
||||||
|
replaceAnchorWithImg(doc, insertedTag, textDocument, link);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Img:
|
case Img:
|
||||||
@ -129,10 +303,13 @@ static void embedHtml(QDomDocument& doc, QDomElement& currentElement, EmbedInHtm
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!insertedTag.isNull()) {
|
||||||
currentElement.insertBefore(insertedTag, node);
|
currentElement.insertBefore(insertedTag, node);
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
|
||||||
currentPos = nextPos + embedInfos.myRE.matchedLength();
|
currentPos = nextPos + embedInfos.myRE.matchedLength();
|
||||||
index++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// text after the last link, only if there's one, don't touch the index
|
// text after the last link, only if there's one, don't touch the index
|
||||||
@ -149,7 +326,7 @@ static void embedHtml(QDomDocument& doc, QDomElement& currentElement, EmbedInHtm
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString formatText(const QString &text, unsigned int flag)
|
QString RsHtml::formatText(QTextDocument *textDocument, const QString &text, ulong flag)
|
||||||
{
|
{
|
||||||
if (flag == 0 || text.isEmpty()) {
|
if (flag == 0 || text.isEmpty()) {
|
||||||
// nothing to do
|
// nothing to do
|
||||||
@ -166,11 +343,11 @@ QString formatText(const QString &text, unsigned int flag)
|
|||||||
|
|
||||||
QDomElement body = doc.documentElement();
|
QDomElement body = doc.documentElement();
|
||||||
if (flag & RSHTML_FORMATTEXT_EMBED_SMILEYS) {
|
if (flag & RSHTML_FORMATTEXT_EMBED_SMILEYS) {
|
||||||
embedHtml(doc, body, defEmbedImg);
|
embedHtml(textDocument, doc, body, defEmbedImg, flag);
|
||||||
}
|
}
|
||||||
if (flag & RSHTML_FORMATTEXT_EMBED_LINKS) {
|
if (flag & RSHTML_FORMATTEXT_EMBED_LINKS) {
|
||||||
EmbedInHtmlAhref defEmbedAhref;
|
EmbedInHtmlAhref defEmbedAhref;
|
||||||
embedHtml(doc, body, defEmbedAhref);
|
embedHtml(textDocument, doc, body, defEmbedAhref, flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString formattedText = doc.toString(-1); // -1 removes any annoying carriage return misinterpreted by QTextEdit
|
QString formattedText = doc.toString(-1); // -1 removes any annoying carriage return misinterpreted by QTextEdit
|
||||||
@ -217,11 +394,14 @@ static void findElements(QDomDocument& doc, QDomElement& currentElement, const Q
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool findAnchors(const QString &text, QStringList& urls)
|
bool RsHtml::findAnchors(const QString &text, QStringList& urls)
|
||||||
{
|
{
|
||||||
QDomDocument doc;
|
QDomDocument doc;
|
||||||
if (doc.setContent(text) == false) {
|
if (doc.setContent(text) == false) {
|
||||||
return false;
|
// convert text with QTextBrowser
|
||||||
|
QTextBrowser textBrowser;
|
||||||
|
textBrowser.setText(text);
|
||||||
|
doc.setContent(textBrowser.toHtml());
|
||||||
}
|
}
|
||||||
|
|
||||||
QDomElement body = doc.documentElement();
|
QDomElement body = doc.documentElement();
|
||||||
@ -404,7 +584,7 @@ static void optimizeHtml(QDomDocument& doc, QDomElement& currentElement, unsigne
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void optimizeHtml(QTextEdit *textEdit, QString &text, unsigned int flag)
|
void RsHtml::optimizeHtml(QTextEdit *textEdit, QString &text, unsigned int flag)
|
||||||
{
|
{
|
||||||
if (textEdit->toHtml() == QTextDocument(textEdit->toPlainText()).toHtml()) {
|
if (textEdit->toHtml() == QTextDocument(textEdit->toPlainText()).toHtml()) {
|
||||||
text = textEdit->toPlainText();
|
text = textEdit->toPlainText();
|
||||||
@ -417,7 +597,7 @@ void optimizeHtml(QTextEdit *textEdit, QString &text, unsigned int flag)
|
|||||||
optimizeHtml(text, flag);
|
optimizeHtml(text, flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
void optimizeHtml(QString &text, unsigned int flag)
|
void RsHtml::optimizeHtml(QString &text, unsigned int flag)
|
||||||
{
|
{
|
||||||
int originalLength = text.length();
|
int originalLength = text.length();
|
||||||
|
|
||||||
@ -430,13 +610,13 @@ void optimizeHtml(QString &text, unsigned int flag)
|
|||||||
}
|
}
|
||||||
|
|
||||||
QDomElement body = doc.documentElement();
|
QDomElement body = doc.documentElement();
|
||||||
optimizeHtml(doc, body, flag);
|
::optimizeHtml(doc, body, flag);
|
||||||
text = doc.toString(-1);
|
text = doc.toString(-1);
|
||||||
|
|
||||||
std::cerr << "Optimized text to " << text.length() << " bytes , instead of " << originalLength << std::endl;
|
std::cerr << "Optimized text to " << text.length() << " bytes , instead of " << originalLength << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString toHtml(QString text, bool realHtml)
|
QString RsHtml::toHtml(QString text, bool realHtml)
|
||||||
{
|
{
|
||||||
// replace "\n" from the optimized html with "<br>"
|
// replace "\n" from the optimized html with "<br>"
|
||||||
text.replace("\n", "<br>");
|
text.replace("\n", "<br>");
|
||||||
@ -448,5 +628,3 @@ QString toHtml(QString text, bool realHtml)
|
|||||||
doc.setHtml(text);
|
doc.setHtml(text);
|
||||||
return doc.toHtml();
|
return doc.toHtml();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace RsHtml
|
|
@ -25,13 +25,10 @@
|
|||||||
* messages, particularly embedding special information into HTML tags.
|
* messages, particularly embedding special information into HTML tags.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef HANDLE_RICH_TEXT_H_
|
#ifndef HANDLE_RICH_TEXT_H_
|
||||||
#define HANDLE_RICH_TEXT_H_
|
#define HANDLE_RICH_TEXT_H_
|
||||||
|
|
||||||
|
|
||||||
#include <QRegExp>
|
#include <QRegExp>
|
||||||
#include <QtXml>
|
|
||||||
|
|
||||||
/* Flags for RsHtml::formatText */
|
/* Flags for RsHtml::formatText */
|
||||||
#define RSHTML_FORMATTEXT_EMBED_SMILEYS 1
|
#define RSHTML_FORMATTEXT_EMBED_SMILEYS 1
|
||||||
@ -40,92 +37,40 @@
|
|||||||
#define RSHTML_FORMATTEXT_REMOVE_COLOR 8
|
#define RSHTML_FORMATTEXT_REMOVE_COLOR 8
|
||||||
#define RSHTML_FORMATTEXT_CLEANSTYLE (RSHTML_FORMATTEXT_REMOVE_FONT | RSHTML_FORMATTEXT_REMOVE_COLOR)
|
#define RSHTML_FORMATTEXT_CLEANSTYLE (RSHTML_FORMATTEXT_REMOVE_FONT | RSHTML_FORMATTEXT_REMOVE_COLOR)
|
||||||
#define RSHTML_FORMATTEXT_OPTIMIZE 16
|
#define RSHTML_FORMATTEXT_OPTIMIZE 16
|
||||||
|
#define RSHTML_FORMATTEXT_REPLACE_LINKS 32
|
||||||
|
|
||||||
/* Flags for RsHtml::formatText */
|
/* Flags for RsHtml::formatText */
|
||||||
#define RSHTML_OPTIMIZEHTML_REMOVE_FONT 2
|
#define RSHTML_OPTIMIZEHTML_REMOVE_FONT 2
|
||||||
#define RSHTML_OPTIMIZEHTML_REMOVE_COLOR 1
|
#define RSHTML_OPTIMIZEHTML_REMOVE_COLOR 1
|
||||||
|
|
||||||
class QTextEdit;
|
class QTextEdit;
|
||||||
|
class QTextDocument;
|
||||||
|
class QDomDocument;
|
||||||
|
class QDomElement;
|
||||||
|
class EmbedInHtml;
|
||||||
|
class RetroShareLink;
|
||||||
|
|
||||||
namespace RsHtml {
|
class RsHtml
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type of embedding we'd like to do
|
|
||||||
*/
|
|
||||||
enum EmbeddedType
|
|
||||||
{
|
{
|
||||||
Ahref, ///< into <a></a>
|
public:
|
||||||
Img, ///< into <img/>
|
RsHtml();
|
||||||
};
|
|
||||||
|
|
||||||
|
static void initEmoticons(const QHash< QString, QString >& hash);
|
||||||
|
|
||||||
|
QString formatText(QTextDocument *textDocument, const QString &text, ulong flag);
|
||||||
|
static bool findAnchors(const QString &text, QStringList& urls);
|
||||||
|
|
||||||
|
static void optimizeHtml(QTextEdit *textEdit, QString &text, unsigned int flag = 0);
|
||||||
|
static void optimizeHtml(QString &text, unsigned int flag = 0);
|
||||||
|
static QString toHtml(QString text, bool realHtml = true);
|
||||||
|
|
||||||
/**
|
|
||||||
* 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:
|
protected:
|
||||||
EmbedInHtml(EmbeddedType newType) :
|
void embedHtml(QTextDocument *textDocument, QDomDocument &doc, QDomElement ¤tElement, EmbedInHtml& embedInfos, ulong flag);
|
||||||
myType(newType)
|
void replaceAnchorWithImg(QDomDocument& doc, QDomElement &element, QTextDocument *textDocument, const RetroShareLink &link);
|
||||||
{}
|
|
||||||
|
|
||||||
public:
|
virtual bool canReplaceAnchor(QDomDocument &doc, QDomElement &element, const RetroShareLink &link);
|
||||||
const EmbeddedType myType;
|
virtual void anchorTextForImg(QDomDocument &doc, QDomElement &element, const RetroShareLink &link, QString &text);
|
||||||
QRegExp myRE;
|
virtual void anchorStylesheetForImg(QDomDocument &doc, QDomElement &element, const RetroShareLink &link, QString &styleSheet);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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_
|
#endif // HANDLE_RICH_TEXT_H_
|
62
retroshare-gui/src/util/ObjectPainter.cpp
Normal file
62
retroshare-gui/src/util/ObjectPainter.cpp
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
/****************************************************************
|
||||||
|
* RetroShare is distributed under the following license:
|
||||||
|
*
|
||||||
|
* Copyright (C) 2012, RetroShare Team
|
||||||
|
*
|
||||||
|
* 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 <QPushButton>
|
||||||
|
#include <QStyleOption>
|
||||||
|
#include <QStylePainter>
|
||||||
|
|
||||||
|
#include "ObjectPainter.h"
|
||||||
|
|
||||||
|
namespace ObjectPainter
|
||||||
|
{
|
||||||
|
|
||||||
|
class DrawButton : public QPushButton
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DrawButton(const QString &text) : QPushButton(text) {}
|
||||||
|
|
||||||
|
void drawOnPixmap(QPixmap &pixmap)
|
||||||
|
{
|
||||||
|
// get a transparent pixmap
|
||||||
|
pixmap = QPixmap(size());
|
||||||
|
pixmap.fill(Qt::transparent);
|
||||||
|
|
||||||
|
// init options
|
||||||
|
QStyleOptionButton option;
|
||||||
|
initStyleOption(&option);
|
||||||
|
|
||||||
|
// draw the button onto the pixmap
|
||||||
|
QStylePainter painter(&pixmap, this);
|
||||||
|
painter.drawControl(QStyle::CE_PushButton, option);
|
||||||
|
painter.end();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void drawButton(const QString &text, const QString &styleSheet, QPixmap &pixmap)
|
||||||
|
{
|
||||||
|
DrawButton button(text);
|
||||||
|
button.setStyleSheet(styleSheet);
|
||||||
|
QSize size = button.sizeHint();
|
||||||
|
button.setGeometry(0, 0, size.width(), size.height());
|
||||||
|
button.drawOnPixmap(pixmap);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
33
retroshare-gui/src/util/ObjectPainter.h
Normal file
33
retroshare-gui/src/util/ObjectPainter.h
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
/****************************************************************
|
||||||
|
* RetroShare is distributed under the following license:
|
||||||
|
*
|
||||||
|
* Copyright (C) 2012, RetroShare Team
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
****************************************************************/
|
||||||
|
|
||||||
|
#ifndef OBJECTPAINTER_H
|
||||||
|
#define OBJECTPAINTER_H
|
||||||
|
|
||||||
|
class QString;
|
||||||
|
class QPixmap;
|
||||||
|
|
||||||
|
namespace ObjectPainter
|
||||||
|
{
|
||||||
|
void drawButton(const QString &text, const QString &styleSheet, QPixmap &pixmap);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //MOUSEEVENTFILTER_H
|
Loading…
Reference in New Issue
Block a user