本文整理汇总了C++中QXmppMessage::setTo方法的典型用法代码示例。如果您正苦于以下问题:C++ QXmppMessage::setTo方法的具体用法?C++ QXmppMessage::setTo怎么用?C++ QXmppMessage::setTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QXmppMessage
的用法示例。
在下文中一共展示了QXmppMessage::setTo方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sendMyMessage
bool MyXmppClient::sendMyMessage(QString bareJid, QString resource, QString msgBody) //Q_INVOKABLE
{
if (msgBody == "" || m_stateConnect != Connected) return false; // if message is empty or user not connected - BREAK
QXmppMessage xmppMsg;
QString jid_from = bareJid;
if( resource == "" ) jid_from += "/resource"; else jid_from += "/" + resource;
xmppMsg.setTo( jid_from );
QString jid_to = m_myjid + "/" + xmppClient->configuration().resource();
xmppMsg.setFrom( jid_to );
xmppMsg.setBody( msgBody );
xmppMsg.setState( QXmppMessage::Active );
xmppClient->sendPacket( xmppMsg );
this->messageReceivedSlot( xmppMsg );
emit insertMessage(m_accountId,this->getBareJidByJid(xmppMsg.to()),msgBody,QDateTime::currentDateTime().toString("dd-MM-yy hh:mm"),1);
return true;
}
示例2: testReplaceWithEmptyMessage
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);
}
示例3: 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;
}
示例4: 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);
}
示例5: handleStanza
bool QXmppMessageReceiptManager::handleStanza(const QDomElement &stanza)
{
if (stanza.tagName() != "message")
return false;
QXmppMessage message;
message.parse(stanza);
// Handle receipts and cancel any further processing.
if (!message.receiptId().isEmpty()) {
Q_EMIT messageDelivered(message.from(), message.receiptId());
return true;
}
// If requested, send a receipt.
if (message.isReceiptRequested()
&& !message.from().isEmpty()
&& !message.id().isEmpty()) {
QXmppMessage receipt;
receipt.setTo(message.from());
receipt.setReceiptId(message.id());
client()->sendPacket(receipt);
}
// Continue processing.
return false;
}
示例6: handleStanza
bool XmppServerArchive::handleStanza(const QDomElement &element)
{
const QString domain = server()->domain();
const QString from = element.attribute("from");
const QString to = element.attribute("to");
if (element.tagName() == "message" &&
to != domain &&
(QXmppUtils::jidToDomain(from) == domain || QXmppUtils::jidToDomain(to) == domain) &&
element.attribute("type") != "error" &&
element.attribute("type") != "groupchat" &&
element.attribute("type") != "headline" &&
!element.firstChildElement("body").text().isEmpty())
{
const QDateTime now = QDateTime::currentDateTime().toUTC();
QXmppMessage message;
message.parse(element);
if (QXmppUtils::jidToDomain(from) == domain)
saveMessage(message, now, false);
if (QXmppUtils::jidToDomain(to) == domain) {
saveMessage(message, now, true);
// offline messages
bool found = false;
XmppServerPresence *presenceExtension = XmppServerPresence::instance(server());
Q_ASSERT(presenceExtension);
foreach (const QXmppPresence &presence, presenceExtension->availablePresences(QXmppUtils::jidToBareJid(to))) {
if (QXmppUtils::jidToResource(to).isEmpty() || presence.from() == to) {
found = true;
break;
}
}
if (!found) {
message.setStamp(now);
message.setState(QXmppMessage::None);
message.setTo(QXmppUtils::jidToBareJid(to));
QBuffer buffer;
buffer.open(QIODevice::WriteOnly);
QXmlStreamWriter writer(&buffer);
message.toXml(&writer);
OfflineMessage offline;
offline.setData(QString::fromUtf8(buffer.data()));
offline.setJid(QXmppUtils::jidToBareJid(to));
offline.setStamp(now);
offline.save();
return true;
}
}
return false;
} else if (element.tagName() == "presence" &&
示例7: DrawAttention
void EntryBase::DrawAttention (const QString& text, const QString& variant)
{
const QString& to = variant.isEmpty () ?
GetJID () :
GetJID () + '/' + variant;
QXmppMessage msg;
msg.setBody (text);
msg.setTo (to);
msg.setType (QXmppMessage::Headline);
msg.setAttentionRequested (true);
Account_->GetClientConnection ()->GetClient ()->sendPacket (msg);
}
示例8: sendReceipt
void QXmppDeliveryReceiptsManager::sendReceipt(const QString &jid, const QString &id)
{
QXmppMessage msg;
msg.setTo(jid);
QXmppElement elem;
elem.setTagName("received");
elem.setAttribute("xmlns", ns_message_receipts);
elem.setAttribute("id", id);
msg.setExtensions(QXmppElementList(elem));
client()->sendPacket(msg);
}
示例9: setLocalState
void Conversation::setLocalState(int state)
{
if (state != m_localState) {
m_localState = static_cast<QXmppMessage::State>(state);
// notify state change
if (m_client) {
QXmppMessage message;
message.setTo(m_jid);
message.setState(m_localState);
m_client->sendPacket(message);
}
emit localStateChanged(m_localState);
}
}
示例10: typingStop
/* it sends information about typing : typing is stoped */
void MyXmppClient::typingStop(QString bareJid, QString resource) {
qDebug() << bareJid << " " << "stop typing...";
QXmppMessage xmppMsg;
QString jid_to = bareJid;
if( resource == "" ) jid_to += "/resource"; else jid_to += "/" + resource;
xmppMsg.setTo( jid_to );
QString jid_from = m_myjid + "/" + xmppClient->configuration().resource();
xmppMsg.setFrom( jid_from );
xmppMsg.setReceiptRequested( false );
QDateTime currTime = QDateTime::currentDateTime();
xmppMsg.setStamp( currTime );
xmppMsg.setState( QXmppMessage::Paused );
xmppClient->sendPacket( xmppMsg );
}
示例11: attentionSend
void MyXmppClient::attentionSend( QString bareJid, QString resource ) {
qDebug() << "MyXmppClient::attentionSend(" << bareJid << ";" << resource << ")";
QXmppMessage xmppMsg;
QString jid_to = bareJid;
if( resource == "" ) {
jid_to += "/resource";
} else {
jid_to += "/" + resource;
}
xmppMsg.setTo( jid_to );
QString jid_from = m_myjid + "/" + xmppClient->configuration().resource();
xmppMsg.setFrom( jid_from );
xmppMsg.setReceiptRequested( false );
xmppMsg.setState( QXmppMessage::None );
xmppMsg.setType( QXmppMessage::Headline );
xmppMsg.setAttentionRequested( true );
xmppClient->sendPacket( xmppMsg );
}
示例12: testChatMarkers
//.........这里部分代码省略.........
QCOMPARE(acknowledgedMessage.marker(), QXmppMessage::Acknowledged);
QCOMPARE(acknowledgedMessage.id(), QString("message-2"));
QCOMPARE(acknowledgedMessage.markedId(), QString("message-1"));
QCOMPARE(acknowledgedMessage.thread(), QString());
QCOMPARE(acknowledgedMessage.markedThread(), QString("sleeping"));
const QByteArray emptyThreadXml(
"<message "
"from='[email protected]/throne' "
"id='message-2' "
"to='[email protected]/westminster'>"
"<received xmlns='urn:xmpp:chat-markers:0' "
"id='message-1'/>"
"</message>");
QXmppMessage emptyThreadMessage;
parsePacket(emptyThreadMessage, emptyThreadXml);
QCOMPARE(emptyThreadMessage.isMarkable(), false);
QCOMPARE(emptyThreadMessage.marker(), QXmppMessage::Received);
QCOMPARE(emptyThreadMessage.id(), QString("message-2"));
QCOMPARE(emptyThreadMessage.markedId(), QString("message-1"));
QCOMPARE(emptyThreadMessage.thread(), QString());
QCOMPARE(emptyThreadMessage.markedThread(), QString());
const QByteArray notMarkableSerialisation(
"<message "
"id=\"message-3\" "
"to=\"[email protected]/westminster\" "
"from=\"[email protected]/throne\" "
"type=\"chat\"/>");
QXmppMessage serialisationMessage;
serialisationMessage.setFrom("[email protected]/throne");
serialisationMessage.setTo("[email protected]/westminster");
serialisationMessage.setId("message-3");
serialisationMessage.setMarkable(false);
serializePacket(serialisationMessage, notMarkableSerialisation);
const QByteArray markableSerialisation(
"<message "
"id=\"message-3\" "
"to=\"[email protected]/westminster\" "
"from=\"[email protected]/throne\" "
"type=\"chat\">"
"<markable xmlns=\"urn:xmpp:chat-markers:0\"/>"
"</message>");
serialisationMessage.setMarkable(true);
serializePacket(serialisationMessage, markableSerialisation);
const QByteArray receivedSerialisation(
"<message "
"id=\"message-3\" "
"to=\"[email protected]/westminster\" "
"from=\"[email protected]/throne\" "
"type=\"chat\">"
"<received xmlns=\"urn:xmpp:chat-markers:0\" "
"id=\"message-2\"/>"
"</message>");
serialisationMessage.setMarkable(false);
serialisationMessage.setMarker(QXmppMessage::Received, "message-2");
serializePacket(serialisationMessage, receivedSerialisation);
const QByteArray receivedThreadSerialisation(
"<message "
示例13: executeCommand
bool XMPPChatMarkerCommand::executeCommand(QStringList * const arguments)
{
bool ret = false;
if (arguments->length() not_eq 2)
{
this->client->write(tr("ERROR: xmppChatMarker <resource> <marker>") + "\r\n");
}
else
{
const QString resource = arguments->first();
QXmppClient * const client =
XMPPResourceStore::instance()->getFromStore(resource);
arguments->removeFirst();
if (client)
{
QSharedPointer<QXmppStanza> lastStanza
= XMPPResourceStore::instance()->getLastMessageReceived(
client);
if (lastStanza)
{
const QSharedPointer<QXmppMessage> lastMsg
= lastStanza.dynamicCast<QXmppMessage>();
if (lastMsg and lastMsg->isMarkable())
{
bool markerOk = true;
QXmppMessage::Marker msgMarker;
const QString marker = arguments->first();
arguments->removeFirst();
if (marker == "received")
{
msgMarker = QXmppMessage::Received;
}
else if (marker == "displayed")
{
msgMarker = QXmppMessage::Displayed;
}
else if (marker == "acknowledged")
{
msgMarker = QXmppMessage::Acknowledged;
}
else
{
markerOk = false;
}
if (markerOk)
{
QXmppMessage markerMessage;
markerMessage.setId(QUuid::createUuid().toString());
markerMessage.setThread("");
markerMessage.setMarkable(false);
markerMessage.setTo(lastMsg->from());
markerMessage.setMarker(msgMarker, lastMsg->id());
markerMessage.addHint(QXmppMessage::AllowPermantStorage);
if (XMPPDebugCommand::isDebugEnabled())
{
XMPPPrintCommand::printMessage(
true,
&markerMessage);
}
ret = client->sendPacket(markerMessage);
if (not ret)
{
this->client->write(tr("ERROR: Failed to send packet") + "\r\n");
}
else
{
XMPPResourceStore::instance()->setLastMessageSent(
client,
markerMessage);
}
}
else
{
this->client->write(tr("ERROR: Invalid marker") + "\r\n");
}
}
else
{
this->client->write(tr("ERROR: The last message isn't Markable") + "\r\n");
}
}
else
{
this->client->write(tr("ERROR: Can't find the last message received to mark")
+ "\r\n");
}
}
else
{
this->client->write(tr("ERROR: Unknown resource") + "\r\n");
}
}
return ret;
}