void Plugin::hookFormatBodyEnd (IHookProxy_ptr proxy, QObject *chatTab, QString body, QObject *msgObj) { IMessage *msg = qobject_cast<IMessage*> (msgObj); if (msg->GetDirection () != IMessage::DIn || msg->GetMessageType () != IMessage::MTChatMessage) return; ICLEntry *other = qobject_cast<ICLEntry*> (msg->OtherPart ()); if (!other->GetEntryID ().contains ("*****@*****.**")) return; proxy->SetValue ("body", FormatBody (body)); }
void Plugin::hookFormatBodyEnd (IHookProxy_ptr proxy, QObject*, QString body, QObject *msgObj) { IMessage *msg = qobject_cast<IMessage*> (msgObj); if (msg->GetDirection () != IMessage::DIn || msg->GetMessageType () != IMessage::MTChatMessage) return; ICLEntry *other = qobject_cast<ICLEntry*> (msg->OtherPart ()); if (!other) { qWarning () << Q_FUNC_INFO << "NULL other part for message" << msgObj << msg->GetBody (); return; } if (!other->GetEntryID ().contains ("*****@*****.**")) return; proxy->SetValue ("body", FormatBody (body)); }
void ChatTab::AppendMessage (Plugins::IMessage *msg) { Plugins::ICLEntry *other = qobject_cast<Plugins::ICLEntry*> (msg->OtherPart ()); if (!other && msg->OtherPart ()) { qWarning () << Q_FUNC_INFO << "message's other part doesn't implement ICLEntry" << msg->GetObject () << msg->OtherPart (); return; } if (msg->GetDirection () == Plugins::IMessage::DOut && other->GetEntryType () == Plugins::ICLEntry::ETMUC) return; QWebFrame *frame = Ui_.View_->page ()->mainFrame (); bool shouldScrollFurther = (frame->scrollBarMaximum (Qt::Vertical) == frame->scrollBarValue (Qt::Vertical)); QString body = FormatBody (msg->GetBody (), msg); QString string = QString ("%1 ") .arg (FormatDate (msg->GetDateTime (), msg)); string.append (' '); switch (msg->GetDirection ()) { case Plugins::IMessage::DIn: { switch (msg->GetMessageType ()) { case Plugins::IMessage::MTChatMessage: case Plugins::IMessage::MTMUCMessage: { QString entryName = Qt::escape (other->GetEntryName ()); entryName = FormatNickname (entryName, msg); if (body.startsWith ("/me ")) { body = body.mid (3); string.append ("*** "); string.append (entryName); string.append (' '); } else { string.append (entryName); string.append (": "); } break; } case Plugins::IMessage::MTEventMessage: string.append ("! "); break; } break; } case Plugins::IMessage::DOut: string.append (FormatNickname ("R", msg)); string.append (": "); break; } string.append (body); QWebElement elem = frame->findFirstElement ("body"); elem.appendInside (QString ("<div>%1</div").arg (string)); if (shouldScrollFurther) QTimer::singleShot (100, this, SLOT (scrollToEnd ())); }
void Plugin::hookFormatBodyEnd (IHookProxy_ptr proxy, QObject *msgObj) { if (ShouldHandle (msgObj, IMessage::Direction::In, IMessage::Type::ChatMessage)) proxy->SetValue ("body", FormatBody (proxy->GetValue ("body").toString ())); }
// Highlights the current line according to the state requested; // check to see if the node of type "state" is present; // if it is, the node is formatted void XHTMLHighlighter::HighlightLine(const QString &text, int state) { QRegularExpression left_bracket_regex = GetLeftBracketRegEx(state); QRegularExpression right_bracket_regex = GetRightBracketRegEx(state); int main_index = 0; // We loop over the line several times // because we could have several nodes on it while (main_index < text.length()) { int left_bracket_index = -1; int left_bracket_len = 0; int right_bracket_index = -1; int right_bracket_len = 0; if (!left_bracket_regex.pattern().isEmpty()) { QRegularExpressionMatch left_bracket_match = left_bracket_regex.match(text, main_index); if (left_bracket_match.hasMatch()) { left_bracket_index = left_bracket_match.capturedStart(); left_bracket_len = left_bracket_match.capturedLength(); } } if (!right_bracket_regex.pattern().isEmpty()) { QRegularExpressionMatch right_bracket_match = right_bracket_regex.match(text, main_index); if (right_bracket_match.hasMatch()) { right_bracket_index = right_bracket_match.capturedStart(); right_bracket_len = right_bracket_match.capturedLength(); } } // If we are not starting our state and our state is // not already set, we don't format; see the four cases explanation below if (left_bracket_index == -1 && !StateChecked(state)) { return; } // Every node/state has a left "bracket", a right "bracket" and the inside body. // This example uses HTML tags, but the principle is the same for every node/state. // There are four possible cases: // (1) <......> (both brackets on the same line; state starts and stops here) // (2) <....... (only the left bracket; next line continues state) // (3) .......> (only the right bracket; current line ends state) // (4) ........ (no brackets; a line between (2) and (3)) // We also check the state because we don't want to start a new node // if the current node of the same type hasn't finished if (left_bracket_index != -1 && !StateChecked(state)) { main_index = left_bracket_index + left_bracket_len; // (1) if (right_bracket_index != -1) { main_index = right_bracket_index + right_bracket_len; int length = right_bracket_index - left_bracket_index + right_bracket_len; FormatBody(text, state, left_bracket_index, length); // There's no point in setting the state here because the state // starts and ends on this line. } // (2) else { int length = text.length() - left_bracket_index; FormatBody(text, state, left_bracket_index, length); main_index += length; // Set the current state so the next line can continue // with the formatting. SetState(state); } } else { // (3) if (right_bracket_index != -1) { main_index = right_bracket_index + right_bracket_len; int length = right_bracket_index + right_bracket_len; FormatBody(text, state, 0, length); // Clear the current state because our state has just ended. ClearState(state); } // (4) else { int length = text.length(); FormatBody(text, state, 0, length); main_index += length; } } } }