/* * Copyright (c) 2013 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include #include #include #include #include #include #include namespace Swift { QtPlainChatView::QtPlainChatView(QWidget* parent) : QtChatView(parent) { QVBoxLayout* mainLayout = new QVBoxLayout(this); mainLayout->setSpacing(0); mainLayout->setContentsMargins(0,0,0,0); log_ = new QTextEdit(this); log_->setReadOnly(true); mainLayout->addWidget(log_); } QtPlainChatView::~QtPlainChatView() { } QString chatMessageToString(const ChatWindow::ChatMessage& message) { QString result; foreach (boost::shared_ptr part, message.getParts()) { boost::shared_ptr textPart; boost::shared_ptr uriPart; boost::shared_ptr emoticonPart; boost::shared_ptr highlightPart; if ((textPart = boost::dynamic_pointer_cast(part))) { QString text = QtUtilities::htmlEscape(P2QSTRING(textPart->text)); text.replace("\n","
"); result += text; continue; } if ((uriPart = boost::dynamic_pointer_cast(part))) { QString uri = QtUtilities::htmlEscape(P2QSTRING(uriPart->target)); result += "" + uri + ""; continue; } if ((emoticonPart = boost::dynamic_pointer_cast(part))) { result += P2QSTRING(emoticonPart->alternativeText); continue; } if ((highlightPart = boost::dynamic_pointer_cast(part))) { //FIXME: Maybe do something here. Anything, really. continue; } } return result; } std::string QtPlainChatView::addMessage(const ChatWindow::ChatMessage& message, const std::string& senderName, bool senderIsSelf, boost::shared_ptr label, const std::string& /*avatarPath*/, const boost::posix_time::ptime& time, const HighlightAction& /*highlight*/) { QString text = "

"; if (label) { text += P2QSTRING(label->getLabel()) + "
"; } QString name = senderIsSelf ? "you" : P2QSTRING(senderName); text += QString(tr("At %1 %2 said:")).arg(ChatSnippet::timeToEscapedString(B2QDATE(time))).arg(name) + "
"; text += chatMessageToString(message); text += "

"; log_->append(text); return ""; }; std::string QtPlainChatView::addAction(const ChatWindow::ChatMessage& message, const std::string& senderName, bool senderIsSelf, boost::shared_ptr label, const std::string& /*avatarPath*/, const boost::posix_time::ptime& time, const HighlightAction& /*highlight*/) { QString text = "

"; if (label) { text += P2QSTRING(label->getLabel()) + "
"; } QString name = senderIsSelf ? "you" : P2QSTRING(senderName); text += QString(tr("At %1 %2 ")).arg(ChatSnippet::timeToEscapedString(B2QDATE(time))).arg(name); text += chatMessageToString(message); text += "

"; log_->append(text); return ""; }; }