Moved the chat history into the libretroshare.

Now the history is saved encrypted. Please delete all files with "chat*.xml" in your profile folder.
Added new config p3HistoryMgr and interface p3History.
Added new option to limit the count of the saved history items.
Added new simple html optimizer "RsHtml::optimizeHtml" to reduce the size of the html strings.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4623 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2011-09-29 09:20:09 +00:00
parent c6a68fe05e
commit 29c090fb44
45 changed files with 1721 additions and 1406 deletions

View file

@ -23,6 +23,8 @@
#include "HandleRichText.h"
#include "gui/RetroShareLink.h"
#include <iostream>
namespace RsHtml {
EmbedInHtmlImg defEmbedImg;
@ -215,4 +217,56 @@ bool findAnchors(const QString &text, QStringList& urls)
return true;
}
static void optimizeHtml(QDomDocument& doc, QDomElement& currentElement)
{
QDomNodeList children = currentElement.childNodes();
for (uint index = 0; index < children.length(); ) {
QDomNode node = children.item(index);
if (node.isElement()) {
QDomElement element = node.toElement();
if (element.tagName().toLower() == "head") {
// remove head
currentElement.removeChild(node);
continue;
}
QDomNode style = element.attributes().namedItem("style");
if (style.isAttr()) {
QDomAttr attr = style.toAttr();
// compress style attribute
QString value = attr.value().simplified();
value.replace("margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px;", "margin:0px 0px 0px 0px;");
value.replace("; ", ";");
attr.setValue(value);
}
optimizeHtml(doc, element);
}
++index;
}
}
void optimizeHtml(QTextEdit *textEdit, QString &text)
{
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();
// remove doctype
text.remove(QRegExp("<!DOCTYPE[^>]*>"));
QDomDocument doc;
if (doc.setContent(text) == false) {
return;
}
QDomElement body = doc.documentElement();
optimizeHtml(doc, body);
text = doc.toString(-1);
std::cerr << "Optimized text to " << text.length() << " bytes , instead of " << textEdit->toHtml().length() << std::endl;
}
} // namespace RsHtml