Status JabberPresenceService::presenceToStatus(const QXmppPresence &presence) { auto status = Status{}; if (presence.type() == QXmppPresence::Available) { switch (presence.availableStatusType()) { case QXmppPresence::AvailableStatusType::Online: status.setType(StatusType::Online); break; case QXmppPresence::AvailableStatusType::Away: status.setType(StatusType::Away); break; case QXmppPresence::AvailableStatusType::XA: status.setType(StatusType::NotAvailable); break; case QXmppPresence::AvailableStatusType::DND: status.setType(StatusType::DoNotDisturb); break; case QXmppPresence::AvailableStatusType::Chat: status.setType(StatusType::FreeForChat); break; case QXmppPresence::AvailableStatusType::Invisible: status.setType(StatusType::DoNotDisturb); break; } } else if (presence.type() == QXmppPresence::Unavailable) status.setType(StatusType::Offline); status.setDescription(presence.statusText()); return status; }
void QXmppRosterManager::presenceReceived(const QXmppPresence& presence) { QString jid = presence.from(); QString bareJid = jidToBareJid(jid); QString resource = jidToResource(jid); if (bareJid.isEmpty()) return; switch(presence.type()) { case QXmppPresence::Available: m_presences[bareJid][resource] = presence; emit presenceChanged(bareJid, resource); break; case QXmppPresence::Unavailable: m_presences[bareJid].remove(resource); emit presenceChanged(bareJid, resource); break; case QXmppPresence::Subscribe: if (m_stream->configuration().autoAcceptSubscriptions()) { QXmppPresence presence; presence.setTo(jid); presence.setType(QXmppPresence::Subscribed); m_stream->sendPacket(presence); } break; default: break; } }
void QXmppRosterManager::_q_presenceReceived(const QXmppPresence& presence) { const QString jid = presence.from(); const QString bareJid = QXmppUtils::jidToBareJid(jid); const QString resource = QXmppUtils::jidToResource(jid); if (bareJid.isEmpty()) return; switch(presence.type()) { case QXmppPresence::Available: d->presences[bareJid][resource] = presence; emit presenceChanged(bareJid, resource); break; case QXmppPresence::Unavailable: d->presences[bareJid].remove(resource); emit presenceChanged(bareJid, resource); break; case QXmppPresence::Subscribe: if (client()->configuration().autoAcceptSubscriptions()) { // accept subscription request acceptSubscription(bareJid); // ask for reciprocal subscription subscribe(bareJid); } else { emit subscriptionReceived(bareJid); } break; default: break; } }
void xmppClient::slotPresenceReceived(const QXmppPresence &presence) { const QLatin1String recipient("*****@*****.**"); // if we are the recipient, or if the presence is not from the recipient, // do nothing if (jidToBareJid(configuration().jid()) == recipient || jidToBareJid(presence.from()) != recipient || presence.type() != QXmppPresence::Available) return; // send the file and connect to the job's signals QXmppTransferJob *job = transferManager->sendFile(presence.from(), "xmppClient.cpp"); bool check = connect( job, SIGNAL(error(QXmppTransferJob::Error)), this, SLOT(slotError(QXmppTransferJob::Error)) ); Q_ASSERT(check); check = connect( job, SIGNAL(finished()), this, SLOT(slotFinished()) ); Q_ASSERT(check); check = connect( job, SIGNAL(progress(qint64,qint64)), this, SLOT(slotProgress(qint64,qint64)) ); Q_ASSERT(check); }
EntryStatus PresenceToStatus (const QXmppPresence& pres) { EntryStatus st (static_cast<State> (pres.availableStatusType () + 1), pres.statusText ()); if (pres.type () == QXmppPresence::Unavailable) st.State_ = SOffline; return st; }
QString presenceToStatusText(const QXmppPresence& presence) { QString statusText = presence.statusText(); if(statusText.isEmpty()) { if(presence.type() == QXmppPresence::Available) { switch(presence.availableStatusType()) { case QXmppPresence::Invisible: statusText = "Offline"; break; case QXmppPresence::Online: case QXmppPresence::Chat: statusText = "Available"; break; case QXmppPresence::Away: case QXmppPresence::XA: statusText = "Idle"; break; case QXmppPresence::DND: statusText = "Busy"; break; } } else statusText = "Offline"; } return statusText; }
void EntryBase::CheckVCardUpdate (const QXmppPresence& pres) { auto conn = Account_->GetClientConnection (); if (!conn->GetInfoReqPolicyManager ()->IsRequestAllowed (InfoRequest::VCard, this)) return; auto fetchVCard = [this, conn] () -> void { QPointer<EntryBase> ptr (this); conn->FetchVCard (GetJID (), [ptr] (const QXmppVCardIq& iq) { if (ptr) ptr->SetVCard (iq); }); }; const auto& vcardUpdate = pres.vCardUpdateType (); if (vcardUpdate == QXmppPresence::VCardUpdateNoPhoto) { if (!Avatar_.isNull ()) { Avatar_ = QImage (); emit avatarChanged (GetAvatar ()); } } else if (vcardUpdate == QXmppPresence::VCardUpdateValidPhoto) { if (pres.photoHash () != VCardPhotoHash_) fetchVCard (); } else if (pres.type () == QXmppPresence::Available && !HasBlindlyRequestedVCard_) { fetchVCard (); HasBlindlyRequestedVCard_ = true; } }
void QFileTrans::slotPresenceReceived(const QXmppPresence &presence) { bool check; Q_UNUSED(check); // if we don't have a recipient, or if the presence is not from the recipient, // do nothing if (m_recipient.isEmpty() || QXmppUtils::jidToBareJid(presence.from()) != m_recipient || presence.type() != QXmppPresence::Available) return; // send the file and connect to the job's signals QXmppTransferJob *job = transferManager->sendFile(presence.from(), ":/example_3_transferHandling.cpp", "example source code"); check = connect(job, SIGNAL(error(QXmppTransferJob::Error)), this, SLOT(slotError(QXmppTransferJob::Error))); Q_ASSERT(check); check = connect(job, SIGNAL(finished()), this, SLOT(slotFinished())); Q_ASSERT(check); check = connect(job, SIGNAL(progress(qint64,qint64)), this, SLOT(slotProgress(qint64,qint64))); Q_ASSERT(check); }
void rosterItem::setPresence(const QXmppPresence &presence) { // determine status text QString statusText = presence.statusText(); if (statusText.isEmpty()) { if(presence.type() == QXmppPresence::Available) statusText = "Available"; else if(presence.type() == QXmppPresence::Unavailable) statusText = "Offline"; } // store data setData(statusText, rosterItem::StatusText); setData(static_cast<int>(presence.type()), PresenceType); setData(static_cast<int>(presence.availableStatusType()), StatusType); // update icon QString icon; if (presence.type() == QXmppPresence::Available) { switch (presence.availableStatusType()) { case QXmppPresence::Online: case QXmppPresence::Chat: icon = "green"; break; case QXmppPresence::Away: case QXmppPresence::XA: icon = "orange"; break; case QXmppPresence::DND: icon = "red"; break; case QXmppPresence::Invisible: icon = "gray"; break; } } else { icon = "gray"; } if (!icon.isEmpty()) setIcon(QIcon(":/icons/resource/"+icon+".png")); }
void RoomHandler::HandlePresence (const QXmppPresence& pres, const QString& nick) { if (pres.type () == QXmppPresence::Unavailable && PendingNickChanges_.remove (nick)) return; const bool existed = Nick2Entry_.contains (nick); RoomParticipantEntry_ptr entry = GetParticipantEntry (nick); if (pres.type () == QXmppPresence::Unavailable) { MakeLeaveMessage (pres, nick); Account_->handleEntryRemoved (entry.get ()); Nick2Entry_.remove (nick); return; } entry->SetClientInfo ("", pres); const QXmppPresence::Status& xmppSt = pres.status (); EntryStatus status (static_cast<State> (xmppSt.type ()), xmppSt.statusText ()); const bool statusChanged = (status != entry->GetStatus (QString ())); if (statusChanged) entry->SetStatus (status, QString ()); if (!PendingNickChanges_.remove (nick)) { if (!existed) { Account_->GetClientConnection ()-> FetchVCard (RoomJID_ + "/" + nick); MakeJoinMessage (pres, nick); entry->SetAffiliation (MUCManager_->getAffiliation (RoomJID_, nick)); entry->SetRole (MUCManager_->getRole (RoomJID_, nick)); } else if (statusChanged) MakeStatusChangedMessage (pres, nick); } }
void xmppClient::slotPresenceReceived(const QXmppPresence &presence) { // if we don't have a recipient, or if the presence is not from the recipient, // do nothing if (m_recipient.isEmpty() || QXmppUtils::jidToBareJid(presence.from()) != m_recipient || presence.type() != QXmppPresence::Available) return; // start the call and connect to the its signals m_recipientFullJid = presence.from(); startCall(); }
void rpcClient::slotPresenceReceived(const QXmppPresence &presence) { const QLatin1String recipient("*****@*****.**"); // if we are the recipient, or if the presence is not from the recipient, // do nothing if (QXmppUtils::jidToBareJid(configuration().jid()) == recipient || QXmppUtils::jidToBareJid(presence.from()) != recipient || presence.type() != QXmppPresence::Available) return; // invoke the remote method in 1 second m_remoteJid = presence.from(); QTimer::singleShot(1000, this, SLOT(slotInvokeRemoteMethod())); }
QString MyXmppClient::getPicPresence( const QXmppPresence &presence ) const { QString picPresenceName; QXmppPresence::Type status = presence.type(); if( status != QXmppPresence::Available ) picPresenceName = "qrc:/presence/offline"; else { QXmppPresence::AvailableStatusType availableStatus = presence.availableStatusType(); if( availableStatus == QXmppPresence::Online ) picPresenceName = "qrc:/presence/online"; else if ( availableStatus == QXmppPresence::Chat ) picPresenceName = "qrc:/presence/chatty"; else if ( availableStatus == QXmppPresence::Away ) picPresenceName = "qrc:/presence/away"; else if ( availableStatus == QXmppPresence::XA ) picPresenceName = "qrc:/presence/xa"; else if ( availableStatus == QXmppPresence::DND ) picPresenceName = "qrc:/presence/busy"; } return picPresenceName; }
void MyXmppClient::initPresence(const QString& bareJid, const QString& resource) { int indxItem = -1; RosterItemModel *item = (RosterItemModel*)cachedRoster->find( bareJid, indxItem ); if( item == 0 ) { return; } QXmppPresence xmppPresence = rosterManager->getPresence( bareJid, resource ); QXmppPresence::Type statusJid = xmppPresence.type(); QStringList _listResources = this->getResourcesByJid( bareJid ); if( (_listResources.count() > 0) && (!_listResources.contains(resource)) ) { qDebug() << bareJid << "/" << resource << " ****************[" <<_listResources<<"]" ; if( statusJid == QXmppPresence::Unavailable ) { return; } } item->setResource( resource ); QString picStatus = this->getPicPresence( xmppPresence ); item->setPresence( picStatus ); QString txtStatus = this->getTextStatus( xmppPresence.statusText(), xmppPresence ); item->setStatusText( txtStatus ); RosterItemModel *itemExists = (RosterItemModel*)cachedRoster->find( bareJid, indxItem ); if( itemExists != 0 ) { itemExists->copy( item ); QString picStatusPrev = itemExists->presence(); if( picStatusPrev != picStatus ) { //emit presenceJidChanged( bareJid, txtStatus, picStatus ); emit rosterChanged(); } } item = 0; itemExists = 0; delete item; delete itemExists; emit contactStatusChanged(m_accountId,bareJid); }
void Xmpp_client::presenceReceived(const QXmppPresence& presence) { qDebug() << "Xmpp_client::presenceReceived !!!"; QString from = presence.from(); QString message; switch(presence.type()) { case QXmppPresence::Subscribe: { QXmppPresence subscribed; subscribed.setTo(from); subscribed.setType(QXmppPresence::Subscribed); this->sendPacket(subscribed); // reciprocal subscription QXmppPresence subscribe; subscribe.setTo(from); subscribe.setType(QXmppPresence::Subscribe); this->sendPacket(subscribe); return; } break; case QXmppPresence::Subscribed: message = "<B>%1</B> accepted your request"; break; case QXmppPresence::Unsubscribe: message = "<B>%1</B> unsubscribe"; break; case QXmppPresence::Unsubscribed: message = "<B>%1</B> unsubscribed"; break; default: return; break; } if(message.isEmpty()) return; }
void MyXmppClient::presenceReceived( const QXmppPresence & presence ) { QString bareJid = getBareJidByJid(presence.from()); QString resource = getResourceByJid(presence.from()); QString myResource = xmppClient->configuration().resource(); if ((presence.from().indexOf( m_myjid ) >= 0 && resource == myResource) || (bareJid == "" && resource == "")) { if (presence.type() == QXmppPresence::Unavailable) m_status = Offline; else { switch (presence.availableStatusType()) { case QXmppPresence::Online: m_status = Online; break; case QXmppPresence::Chat: m_status = Chat; break; case QXmppPresence::Away: m_status = Away; break; case QXmppPresence::XA: m_status = XA; break; case QXmppPresence::DND: m_status = DND; break; } } emit statusChanged(m_accountId); } }
void xmppClient::slotPresenceReceived(const QXmppPresence &presence) { const QLatin1String recipient("*****@*****.**"); // if we are the recipient, or if the presence is not from the recipient, // do nothing if (jidToBareJid(configuration().jid()) == recipient || jidToBareJid(presence.from()) != recipient || presence.type() != QXmppPresence::Available) return; // start the call and connect to the its signals QXmppCall *call = callManager->call(presence.from()); bool check = connect(call, SIGNAL(connected()), this, SLOT(slotConnected())); Q_ASSERT(check); check = connect(call, SIGNAL(finished()), this, SLOT(slotFinished())); Q_ASSERT(check); }
void QXmppClient::setClientPresence(const QXmppPresence& presence) { d->clientPresence = presence; d->addProperCapability(d->clientPresence); if (presence.type() == QXmppPresence::Unavailable) { // cancel reconnection d->reconnectionTimer->stop(); // NOTE: we can't call disconnect() because it alters // the client presence if (d->stream->isConnected()) sendPacket(d->clientPresence); d->stream->disconnectFromHost(); } else if (d->stream->isConnected()) sendPacket(d->clientPresence); else connectToServer(d->stream->configuration(), presence); }
void QXmppClient::setClientPresence(const QXmppPresence& presence) { if (presence.type() == QXmppPresence::Unavailable) { d->clientPresence = presence; // NOTE: we can't call disconnect() because it alters // the client presence if (d->stream->isConnected()) { sendPacket(d->clientPresence); d->stream->disconnectFromHost(); } } else if (!d->stream->isConnected()) connectToServer(d->stream->configuration(), presence); else { d->clientPresence = presence; d->clientPresence.setExtensions(d->stream->presenceExtensions()); sendPacket(d->clientPresence); } }
void EntryBase::SetClientInfo (const QString& variant, const QXmppPresence& pres) { if (pres.type () == QXmppPresence::Available) SetClientInfo (variant, pres.capabilityNode (), pres.capabilityVer ()); }