本文整理汇总了C++中QXmppMessage::type方法的典型用法代码示例。如果您正苦于以下问题:C++ QXmppMessage::type方法的具体用法?C++ QXmppMessage::type怎么用?C++ QXmppMessage::type使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QXmppMessage
的用法示例。
在下文中一共展示了QXmppMessage::type方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HandleMessage
void RoomHandler::HandleMessage (const QXmppMessage& msg, const QString& nick)
{
const bool existed = Nick2Entry_.contains (nick);
RoomParticipantEntry_ptr entry = GetParticipantEntry (nick, false);
if (msg.type () == QXmppMessage::Chat && !nick.isEmpty ())
{
if (msg.state ())
entry->UpdateChatState (msg.state (), QString ());
if (!msg.body ().isEmpty ())
{
GlooxMessage *message = new GlooxMessage (msg,
Account_->GetClientConnection ().get ());
entry->HandleMessage (message);
}
}
else
{
RoomPublicMessage *message = 0;
if (msg.type () == QXmppMessage::GroupChat &&
!msg.subject ().isEmpty ())
{
Subject_ = msg.subject ();
CLEntry_->HandleSubjectChanged (Subject_);
const QString& string = nick.isEmpty () ?
msg.subject () :
tr ("%1 changed subject to %2")
.arg (nick)
.arg (msg.subject ());
message = new RoomPublicMessage (string,
IMessage::DIn,
CLEntry_,
IMessage::MTEventMessage,
IMessage::MSTOther);
}
else if (!nick.isEmpty ())
{
if (!msg.body ().isEmpty ())
message = new RoomPublicMessage (msg, CLEntry_, entry);
}
else
message = new RoomPublicMessage (msg.body (),
IMessage::DIn,
CLEntry_,
IMessage::MTEventMessage,
IMessage::MSTOther);
if (message)
CLEntry_->HandleMessage (message);
if (!existed)
Nick2Entry_.remove (nick);
}
}
示例2: testMessageReceipt
void tst_QXmppMessage::testMessageReceipt()
{
const QByteArray xml(
"<message id=\"richard2-4.1.247\" to=\"[email protected]/throne\" from=\"[email protected]/westminster\" type=\"normal\">"
"<body>My lord, dispatch; read o'er these articles.</body>"
"<request xmlns=\"urn:xmpp:receipts\"/>"
"</message>");
QXmppMessage message;
parsePacket(message, xml);
QCOMPARE(message.id(), QString("richard2-4.1.247"));
QCOMPARE(message.to(), QString("[email protected]/throne"));
QCOMPARE(message.from(), QString("[email protected]/westminster"));
QVERIFY(message.extendedAddresses().isEmpty());
QCOMPARE(message.type(), QXmppMessage::Normal);
QCOMPARE(message.body(), QString("My lord, dispatch; read o'er these articles."));
QCOMPARE(message.isAttentionRequested(), false);
QCOMPARE(message.isReceiptRequested(), true);
QCOMPARE(message.receiptId(), QString());
serializePacket(message, xml);
const QByteArray receiptXml(
"<message id=\"bi29sg183b4v\" to=\"[email protected]/westminster\" from=\"[email protected]/throne\" type=\"normal\">"
"<received xmlns=\"urn:xmpp:receipts\" id=\"richard2-4.1.247\"/>"
"</message>");
QXmppMessage receipt;
parsePacket(receipt, receiptXml);
QCOMPARE(receipt.id(), QString("bi29sg183b4v"));
QCOMPARE(receipt.to(), QString("[email protected]/westminster"));
QCOMPARE(receipt.from(), QString("[email protected]/throne"));
QVERIFY(receipt.extendedAddresses().isEmpty());
QCOMPARE(receipt.type(), QXmppMessage::Normal);
QCOMPARE(receipt.body(), QString());
QCOMPARE(receipt.isAttentionRequested(), false);
QCOMPARE(receipt.isReceiptRequested(), false);
QCOMPARE(receipt.receiptId(), QString("richard2-4.1.247"));
serializePacket(receipt, receiptXml);
const QByteArray oldXml(
"<message id=\"richard2-4.1.247\" to=\"[email protected]/westminster\" from=\"[email protected]/throne\" type=\"normal\">"
"<received xmlns=\"urn:xmpp:receipts\"/>"
"</message>");
QXmppMessage old;
parsePacket(old, oldXml);
QCOMPARE(old.id(), QString("richard2-4.1.247"));
QCOMPARE(old.to(), QString("[email protected]/westminster"));
QCOMPARE(old.from(), QString("[email protected]/throne"));
QVERIFY(old.extendedAddresses().isEmpty());
QCOMPARE(old.type(), QXmppMessage::Normal);
QCOMPARE(old.body(), QString());
QCOMPARE(old.isAttentionRequested(), false);
QCOMPARE(old.isReceiptRequested(), false);
QCOMPARE(old.receiptId(), QString("richard2-4.1.247"));
}
示例3: messageReceived
void Conversation::messageReceived(const QXmppMessage &msg)
{
if (msg.type() != QXmppMessage::Chat ||
QXmppUtils::jidToBareJid(msg.from()) != m_jid)
return;
// handle chat state
if (msg.state() != m_remoteState) {
m_remoteState = msg.state();
emit remoteStateChanged(m_remoteState);
}
// handle message body
if (msg.body().isEmpty())
return;
HistoryMessage message;
message.body = msg.body();
message.date = msg.stamp();
if (!message.date.isValid())
message.date = m_client->serverTime();
message.jid = m_jid;
message.received = true;
if (m_historyModel)
m_historyModel->addMessage(message);
}
示例4: testBasic
void tst_QXmppMessage::testBasic()
{
QFETCH(QByteArray, xml);
QFETCH(int, type);
QFETCH(QString, body);
QFETCH(QString, subject);
QFETCH(QString, thread);
QXmppMessage message;
parsePacket(message, xml);
QCOMPARE(message.to(), QString("[email protected]/QXmpp"));
QCOMPARE(message.from(), QString("[email protected]/QXmpp"));
QVERIFY(message.extendedAddresses().isEmpty());
QCOMPARE(int(message.type()), type);
QCOMPARE(message.body(), body);
QCOMPARE(message.subject(), subject);
QCOMPARE(message.thread(), thread);
QCOMPARE(message.state(), QXmppMessage::None);
QCOMPARE(message.isAttentionRequested(), false);
QCOMPARE(message.isReceiptRequested(), false);
QCOMPARE(message.hasForwarded(), false);
QCOMPARE(message.receiptId(), QString());
QCOMPARE(message.xhtml(), QString());
serializePacket(message, xml);
}
示例5: 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);
}
示例6: handleReceivedMessage
void JabberChatService::handleReceivedMessage(const QXmppMessage &xmppMessage)
{
if (!m_formattedStringFactory)
return;
m_chatStateService->extractReceivedChatState(xmppMessage);
if (xmppMessage.body().isEmpty())
return;
if (xmppMessage.type() == QXmppMessage::Type::Error) // #1642
return;
auto message = xmppMessage.type() == QXmppMessage::GroupChat
? m_roomChatService->handleReceivedMessage(xmppMessage)
: handleNormalReceivedMessage(xmppMessage);
if (message.isNull())
return;
message.setType(MessageTypeReceived);
message.setSendDate(xmppMessage.stamp().toLocalTime());
message.setReceiveDate(QDateTime::currentDateTime());
auto body = xmppMessage.body();
if (rawMessageTransformerService())
body = QString::fromUtf8(rawMessageTransformerService()->transform(body.toUtf8(), message).rawContent());
auto htmlBody = replacedNewLine(Qt::escape(body), QLatin1String("<br/>"));
auto formattedString = m_formattedStringFactory.data()->fromHtml(htmlBody);
if (!formattedString || formattedString->isEmpty())
return;
message.setContent(std::move(formattedString));
auto id = xmppMessage.from();
auto resourceIndex = id.indexOf('/');
if (resourceIndex >= 0)
id = id.mid(0, resourceIndex);
m_contactMessageTypes.insert(id, xmppMessage.type());
emit messageReceived(message);
}
示例7: HandleMessageReceived
void ChatExtension::HandleMessageReceived(const QXmppMessage &message)
{
if(message.type() == QXmppMessage::GroupChat)
return;
QString sender_jid = jidToBareJid(message.from());
QString msg = message.body();
LogInfo("XMPPModule: Received message. From: " + sender_jid.toStdString()
+ " Body: " + msg.toStdString());
emit MessageReceived(sender_jid, msg);
}
示例8: testMessageAttention
void tst_QXmppMessage::testMessageAttention()
{
const QByteArray xml(
"<message to=\"[email protected]/QXmpp\" from=\"[email protected]/QXmpp\" type=\"normal\">"
"<attention xmlns=\"urn:xmpp:attention:0\"/>"
"</message>");
QXmppMessage message;
parsePacket(message, xml);
QCOMPARE(message.to(), QString("[email protected]/QXmpp"));
QCOMPARE(message.from(), QString("[email protected]/QXmpp"));
QVERIFY(message.extendedAddresses().isEmpty());
QCOMPARE(message.type(), QXmppMessage::Normal);
QCOMPARE(message.body(), QString());
QCOMPARE(message.isAttentionRequested(), true);
QCOMPARE(message.isReceiptRequested(), false);
QCOMPARE(message.receiptId(), QString());
serializePacket(message, xml);
}
示例9: testMessageFull
void TestPackets::testMessageFull()
{
const QByteArray xml(
"<message to=\"[email protected]/QXmpp\" from=\"[email protected]/QXmpp\" type=\"normal\">"
"<subject>test subject</subject>"
"<body>test body & stuff</body>"
"<thread>test thread</thread>"
"<composing xmlns=\"http://jabber.org/protocol/chatstates\"/>"
"</message>");
QXmppMessage message;
parsePacket(message, xml);
QCOMPARE(message.to(), QString("[email protected]/QXmpp"));
QCOMPARE(message.from(), QString("[email protected]/QXmpp"));
QCOMPARE(message.type(), QXmppMessage::Normal);
QCOMPARE(message.body(), QString("test body & stuff"));
QCOMPARE(message.subject(), QString("test subject"));
QCOMPARE(message.thread(), QString("test thread"));
QCOMPARE(message.state(), QXmppMessage::Composing);
serializePacket(message, xml);
}
示例10: slotClientMessageReceived
void CFrmUserList::slotClientMessageReceived(const QXmppMessage &message)
{
LOG_MODEL_DEBUG("Roster", "CFrmUserList::slotClientMessageReceived:type:%d;state:%d;from:%s;to:%s;body:%s",
message.type(),
message.state(), //消息的状态 0:消息内容,其它值表示这个消息的状态
qPrintable(message.from()),
qPrintable(message.to()),
qPrintable(message.body())
);
m_LastUser = message.from();//保存接收到最后消息的用户
QMap<QString, CRoster*>::iterator it;
it = m_Rosters.find(QXmppUtils::jidToBareJid(message.from()));
if(m_Rosters.end() != it)
{
if(QXmppMessage::None == message.state())
{
it.value()->AppendMessage(message.body());
}
//TODO:消息输入状态显示
}
}
示例11: HandleMessageReceived
void MucExtension::HandleMessageReceived(const QXmppMessage &message)
{
QXmppMucRoom *room = qobject_cast<QXmppMucRoom*>(sender());
if(!room)
return;
QString message_type;
// Parse message type into string.
switch(message.type())
{
case QXmppMessage::Error:
message_type = "error";
break;
case QXmppMessage::Normal:
message_type = "normal";
break;
case QXmppMessage::Chat:
message_type = "chat";
break;
case QXmppMessage::GroupChat:
message_type = "groupchat";
break;
case QXmppMessage::Headline:
message_type = "headline";
break;
default:
message_type = "invalid type";
}
LogInfo("XMPPModule: Received message. From: " + message.from().toStdString()
+ " Room: " + room->jid().toStdString()
+ " Body: " + message.body().toStdString()
+ " Type: " + message_type.toStdString());
emit MessageReceived(room->jid(), message.from(), message.body(), message_type);
}
示例12: HandleMessage
void RoomHandler::HandleMessage (const QXmppMessage& msg, const QString& nick)
{
Q_FOREACH (const QXmppElement& elem, msg.extensions ())
{
const QString& xmlns = elem.attribute ("xmlns");
if (xmlns == ns_data)
{
QXmppDataForm *df = new QXmppDataForm ();
df->parse (XooxUtil::XmppElem2DomElem (elem));
if (df->isNull ())
{
qWarning () << Q_FUNC_INFO
<< "unable to parse form from"
<< msg.from ();
delete df;
}
else
emit gotPendingForm (df, msg.from ());
}
else
qWarning () << Q_FUNC_INFO
<< "unhandled <x> element"
<< xmlns;
}
const bool existed = Nick2Entry_.contains (nick);
RoomParticipantEntry_ptr entry = GetParticipantEntry (nick, false);
if (msg.type () == QXmppMessage::Chat && !nick.isEmpty ())
{
if (msg.isAttentionRequested ())
entry->HandleAttentionMessage (msg);
if (msg.state ())
entry->UpdateChatState (msg.state (), QString ());
if (!msg.body ().isEmpty ())
{
GlooxMessage *message = new GlooxMessage (msg,
Account_->GetClientConnection ().get ());
entry->HandleMessage (message);
}
}
else
{
RoomPublicMessage *message = 0;
if (msg.type () == QXmppMessage::GroupChat &&
!msg.subject ().isEmpty ())
{
Subject_ = msg.subject ();
CLEntry_->HandleSubjectChanged (Subject_);
const QString& string = nick.isEmpty () ?
msg.subject () :
tr ("%1 changed subject to %2")
.arg (nick)
.arg (msg.subject ());
message = new RoomPublicMessage (string,
IMessage::DIn,
CLEntry_,
IMessage::MTEventMessage,
IMessage::MSTOther);
}
else if (!nick.isEmpty ())
{
if (!msg.body ().isEmpty ())
message = new RoomPublicMessage (msg, CLEntry_, entry);
}
else if (!msg.body ().isEmpty ())
message = new RoomPublicMessage (msg.body (),
IMessage::DIn,
CLEntry_,
IMessage::MTEventMessage,
IMessage::MSTOther);
if (message)
CLEntry_->HandleMessage (message);
if (!existed)
Nick2Entry_.remove (nick);
}
}