本文整理汇总了C++中QXmppMessage类的典型用法代码示例。如果您正苦于以下问题:C++ QXmppMessage类的具体用法?C++ QXmppMessage怎么用?C++ QXmppMessage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QXmppMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handleStanza
bool QXmppCarbonManager::handleStanza(const QDomElement &element)
{
if(element.tagName() != "message")
return false;
bool sent = true;
QDomElement carbon = element.firstChildElement("sent");
if(carbon.isNull()) {
carbon = element.firstChildElement("received");
sent = false;
}
if(carbon.isNull() || carbon.namespaceURI() != ns_carbons)
return false; // Neither sent nor received -> no carbon message
QDomElement forwarded = carbon.firstChildElement("forwarded");
if(forwarded.isNull())
return false;
QDomElement messageelement = forwarded.firstChildElement("message");
if(messageelement.isNull())
return false;
QXmppMessage message;
message.parse(messageelement);
if(sent)
emit messageSent(message);
else
emit messageReceived(message);
return true;
}
示例2: typeField
void RoomHandler::requestVoice ()
{
QList<QXmppDataForm::Field> fields;
QXmppDataForm::Field typeField (QXmppDataForm::Field::HiddenField);
typeField.setKey ("FORM_TYPE");
typeField.setValue ("http://jabber.org/protocol/muc#request");
fields << typeField;
QXmppDataForm::Field reqField (QXmppDataForm::Field::TextSingleField);
reqField.setLabel ("Requested role");
reqField.setKey ("muc#role");
reqField.setValue ("participant");
fields << reqField;
QXmppDataForm form;
form.setType (QXmppDataForm::Submit);
form.setFields (fields);
QXmppMessage msg ("", Room_->jid ());
msg.setType (QXmppMessage::Normal);
msg.setExtensions (XooxUtil::Form2XmppElem (form));
Account_->GetClientConnection ()->GetClient ()->sendPacket (msg);
}
示例3: xml
void tst_QXmppMessage::testProcessingHints()
{
const QByteArray xml("<message "
"to=\"[email protected]/laptop\" "
"from=\"[email protected]/laptop\" "
"type=\"chat\">"
"<body>V unir avtug'f pybnx gb uvqr zr sebz gurve fvtug</body>"
"<no-copy xmlns=\"urn:xmpp:hints\"/>"
"<no-store xmlns=\"urn:xmpp:hints\"/>"
"<allow-permanent-storage xmlns=\"urn:xmpp:hints\"/>"
"</message>");
QXmppMessage message;
parsePacket(message, xml);
QCOMPARE(message.hasHint(QXmppMessage::NoCopies), true);
QCOMPARE(message.hasHint(QXmppMessage::NoStorage), true);
QCOMPARE(message.hasHint(QXmppMessage::AllowPermantStorage), true);
QXmppMessage message2;
message2.setType(QXmppMessage::Chat);
message2.setFrom(QString("[email protected]/laptop"));
message2.setTo(QString("[email protected]/laptop"));
message2.setBody(QString("V unir avtug'f pybnx gb uvqr zr sebz gurve fvtug"));
message2.addHint(QXmppMessage::NoCopies);
message2.addHint(QXmppMessage::NoStorage);
message2.addHint(QXmppMessage::AllowPermantStorage);
serializePacket(message2, xml);
}
示例4: slotMessageReceived
void CFrmGroupChat::slotMessageReceived(const QXmppMessage &message)
{
LOG_MODEL_DEBUG("Group chat", "CFrmGroupChat::slotMessageReceived:type:%d;state:%d;from:%s;to:%s;body:%s",
message.type(),
message.state(), //消息的状态 0:消息内容,其它值表示这个消息的状态
qPrintable(message.from()),
qPrintable(message.to()),
qPrintable(message.body())
);
if(QXmppUtils::jidToBareJid(message.from()) != QXmppUtils::jidToBareJid(m_pRoom->jid()))
{
LOG_MODEL_DEBUG("Group chat", "the room is %s, from %s received",
m_pRoom->jid().toStdString().c_str(),
message.from().toStdString().c_str());
return;
}
if(message.body().isEmpty())
return;
QString nick;
nick = QXmppUtils::jidToResource(message.from());
if(nick.isEmpty())
nick = tr("System");
AppendMessageToList(message.body(), nick);
}
示例5: sendMessage
bool Conversation::sendMessage(const QString &body)
{
if (body.isEmpty() || m_jid.isEmpty() || !m_client || !m_client->isConnected())
return false;
// send message
QXmppMessage message;
message.setTo(m_jid);
message.setBody(body);
message.setState(QXmppMessage::Active);
if (!m_client->sendPacket(message))
return false;
// update state
if (m_localState != QXmppMessage::Active) {
m_localState = QXmppMessage::Active;
emit localStateChanged(m_localState);
}
// add message to history
if (m_historyModel) {
HistoryMessage message;
message.body = body;
message.date = m_client->serverTime();
message.jid = m_client->configuration().jidBare();
message.received = false;
m_historyModel->addMessage(message);
}
return true;
}
示例6: Forwarded2Message
QXmppMessage Forwarded2Message (const QXmppElement& wrapper)
{
const auto& forwardedElem = wrapper.tagName () == "forwarded" ?
wrapper :
wrapper.firstChildElement ("forwarded");
if (forwardedElem.isNull ())
return {};
const auto& messageElem = forwardedElem.firstChildElement ("message");
if (messageElem.isNull ())
return {};
QXmppMessage original;
#if QXMPP_VERSION >= 0x000800
original.parse (messageElem.sourceDomElement ());
#else
#warning "You won't have good forwarded messages, Message Archive Management and Message Carbons will look like crap."
original.parse (XmppElem2DomElem (messageElem));
#endif
auto delayElem = forwardedElem.firstChildElement ("delay");
if (!delayElem.isNull ())
{
const auto& sourceDT = QXmppUtils::datetimeFromString (delayElem.attribute ("stamp"));
original.setStamp (sourceDT.toLocalTime ());
}
return original;
}
示例7: saveMessage
static void saveMessage(const QXmppMessage &message, const QDateTime &now, bool received)
{
const QString localJid = QXmppUtils::jidToBareJid(received ? message.to() : message.from());
const QString remoteJid = QXmppUtils::jidToBareJid(received ? message.from() : message.to());
// get or create collection
int chatId;
QDjangoQuerySet<ArchiveMessage> qs;
qs = qs.filter(QDjangoWhere("chat__jid", QDjangoWhere::Equals, localJid));
qs = qs.filter(QDjangoWhere("chat__with", QDjangoWhere::Equals, remoteJid));
qs = qs.orderBy(QStringList() << "-date").limit(0, 1);
ArchiveMessage tmp;
if (qs.size() > 0 && qs.at(0, &tmp) && tmp.date().secsTo(now) < 3600) {
chatId = tmp.property("chat_id").toInt();
} else {
ArchiveChat chat;
chat.setJid(localJid);
chat.setWith(remoteJid);
chat.setStart(now);
chat.save();
chatId = chat.pk().toInt();
}
// save outgoing message
ArchiveMessage msg;
msg.setProperty("chat_id", chatId);
msg.setBody(message.body());
msg.setDate(now);
msg.setReceived(received);
msg.save();
}
示例8: qDebug
void Client::messageReceived(const QXmppMessage &message)
{
qDebug() << message.body();
QString from = message.from();
QString msg = message.body();
m_client->sendPacket(QXmppMessage("", from, "Your message: " + msg));
}
示例9: eventFilter
bool ChatWindow::eventFilter(QObject* sender, QEvent* event) {
if (sender == ui->messagePlainTextEdit) {
if (event->type() != QEvent::KeyPress) {
return false;
}
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
if ((keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Enter) &&
(keyEvent->modifiers() & Qt::ShiftModifier) == 0) {
QString messageText = ui->messagePlainTextEdit->document()->toPlainText().trimmed();
if (!messageText.isEmpty()) {
#ifdef HAVE_QXMPP
const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom();
QXmppMessage message;
message.setTo(publicChatRoom->jid());
message.setType(QXmppMessage::GroupChat);
message.setBody(messageText);
XmppClient::getInstance().getXMPPClient().sendPacket(message);
#endif // HAVE_QXMPP
QTextCursor cursor = ui->messagePlainTextEdit->textCursor();
cursor.select(QTextCursor::Document);
cursor.removeSelectedText();
}
return true;
}
} else if (event->type() == QEvent::MouseButtonRelease) {
QVariant userVar = sender->property("user");
if (userVar.isValid()) {
AddressManager::getInstance().goToUser(userVar.toString());
return true;
}
}
return QWidget::eventFilter(sender, event);
}
示例10: extractReceivedChatState
void JabberChatStateService::extractReceivedChatState(const QXmppMessage &message)
{
auto jid = Jid::parse(message.from());
auto contact = ContactManager::instance()->byId(account(), jid.bare(), ActionCreateAndAdd);
contact.addProperty("jabber:received-chat-state", static_cast<int>(message.state()), CustomProperties::NonStorable);
emit peerStateChanged(contact, xmppStateToState(message.state()));
}
示例11: HandleAttentionMessage
void EntryBase::HandleAttentionMessage (const QXmppMessage& msg)
{
QString jid;
QString resource;
ClientConnection::Split (msg.from (), &jid, &resource);
emit attentionDrawn (msg.body (), resource);
}
示例12: withSentChatState
QXmppMessage JabberChatStateService::withSentChatState(QXmppMessage message)
{
auto jid = Jid::parse(message.to());
auto contact = ContactManager::instance()->byId(account(), jid.bare(), ActionCreateAndAdd);
message.setState(QXmppMessage::State::Active);
contact.addProperty("jabber:sent-chat-state", static_cast<int>(QXmppMessage::State::Active), CustomProperties::NonStorable);
return message;
}
示例13: messageReceived
void QxmppPeer::messageReceived(const QXmppMessage& message)
{
QString from = message.from();
QString msg = message.body();
//sendPacket( QXmppMessage("", from, "Your message: " + msg) );
if ( !m_messageHandler.empty() )
m_messageHandler( from.toStdString(), msg.toStdString() );
}
示例14: QFETCH
void tst_QXmppMessage::testDelay()
{
QFETCH(QByteArray, xml);
QFETCH(QDateTime, stamp);
QXmppMessage message;
parsePacket(message, xml);
QCOMPARE(message.stamp(), stamp);
serializePacket(message, xml);
}
示例15: replaceXml
void tst_QXmppMessage::testReplaceWithEmptyMessage()
{
const QByteArray replaceXml(
"<message to='[email protected]/balcony' id='good1'>"
"<body/>"
"<replace id='bad1' xmlns='urn:xmpp:message-correct:0'/>"
"</message>");
QXmppMessage replaceMessage;
parsePacket(replaceMessage, replaceXml);
QCOMPARE(replaceMessage.isReplace(), true);
QCOMPARE(replaceMessage.replaceId(), QString("bad1"));
QCOMPARE(replaceMessage.body(), QString(""));
const QByteArray replaceSerialisation(
"<message id=\"good1\" to=\"[email protected]/balcony\" type=\"chat\">"
"<body/>"
"<replace id=\"bad1\" xmlns=\"urn:xmpp:message-correct:0\"/>"
"</message>");
QXmppMessage serialisationMessage;
serialisationMessage.setTo("[email protected]/balcony");
serialisationMessage.setId("good1");
serialisationMessage.setBody("");
serialisationMessage.setReplace("bad1");
serializePacket(serialisationMessage, replaceSerialisation);
}