Ejemplo n.º 1
0
	void ServerHistoryWidget::handleFetched (const QModelIndex& index,
			const QByteArray& startId, const SrvHistMessages_t& messages)
	{
		if (index.row () != ContactsFilter_->mapToSource (Ui_.ContactsView_->currentIndex ()).row ())
			return;

		if (FirstMsgCount_ == -1)
			FirstMsgCount_ = messages.size ();

		CurrentID_ = startId;

		Ui_.MessagesView_->clear ();

		const auto& bgColor = palette ().color (QPalette::Base);
		const auto& colors = Core::Instance ().GenerateColors ("hash", bgColor);

		QString preNick = XmlSettingsManager::Instance ().property ("PreNickText").toString ();
		QString postNick = XmlSettingsManager::Instance ().property ("PostNickText").toString ();
		preNick.replace ('<', "&lt;");
		postNick.replace ('<', "&lt;");

		for (const auto& message : messages)
		{
			const auto& color = Core::Instance ().GetNickColor (message.Nick_, colors);

			auto msgText = message.RichBody_;
			if (msgText.isEmpty ())
			{
				msgText = Qt::escape (message.Body_);
				ProxyObject {}.FormatLinks (msgText);
				msgText.replace ('\n', "<br/>");
			}

			QString html = "[" + message.TS_.toString () + "] " + preNick;
			html += "<font color='" + color + "'>" + message.Nick_ + "</font> ";
			html += postNick + ' ' + msgText;

			html.prepend (QString ("<font color='#") +
					(message.Dir_ == IMessage::DIn ? "0000dd" : "dd0000") +
					"'>");
			html += "</font>";

			Ui_.MessagesView_->append (html);
		}

		MaxID_ = messages.value (0).ID_;
	}