void MyXmppClient::clearPresence() { qDebug() << "MyXmppClient::clearPresence() called"; for( int j=0; j < cachedRoster->rowCount(); j++ ) { RosterItemModel *itemExists = (RosterItemModel*)cachedRoster->getElementByID(j); if (itemExists != 0) { itemExists->setPresence( this->getPicPresence( QXmppPresence::Unavailable ) ); } itemExists = 0; delete itemExists; } emit rosterChanged(); }
void MyXmppClient::messageReceivedSlot( const QXmppMessage &xmppMsg ) { QString bareJid_from = MyXmppClient::getBareJidByJid( xmppMsg.from() ); QString bareJid_to = MyXmppClient::getBareJidByJid( xmppMsg.to() ); if( xmppMsg.state() == QXmppMessage::Active ) qDebug() << "Msg state is QXmppMessage::Active"; else if( xmppMsg.state() == QXmppMessage::Inactive ) qDebug() << "Msg state is QXmppMessage::Inactive"; else if( xmppMsg.state() == QXmppMessage::Gone ) qDebug() << "Msg state is QXmppMessage::Gone"; else if( xmppMsg.state() == QXmppMessage::Composing ) { if (bareJid_from != "") { m_flTyping = true; emit typingChanged(m_accountId,bareJid_from, true); qDebug() << bareJid_from << " is composing."; } } else if( xmppMsg.state() == QXmppMessage::Paused ) { if (bareJid_from != "") { m_flTyping = false; emit typingChanged(m_accountId,bareJid_from, false); qDebug() << bareJid_from << " paused."; } } else { if( xmppMsg.isAttentionRequested() ) { //qDebug() << "ZZZ: attentionRequest !!! from:" <<xmppMsg.from(); //msgWrapper->attention( bareJid_from, false ); } qDebug() << "MessageWrapper::messageReceived(): xmppMsg.state():" << xmppMsg.state(); } if ( !( xmppMsg.body().isEmpty() || xmppMsg.body().isNull() || bareJid_from == m_myjid ) ) { m_bareJidLastMessage = getBareJidByJid(xmppMsg.from()); m_resourceLastMessage = getResourceByJid(xmppMsg.from()); this->openChat( bareJid_from ); RosterItemModel *item = (RosterItemModel*)cachedRoster->find( bareJid_from ); if( item != 0 ) { int cnt = item->unreadMsg(); item->setUnreadMsg( ++cnt ); } else { RosterItemModel *itemModel = new RosterItemModel( ); itemModel->setPresence( this->getPicPresence( QXmppPresence::Unavailable ) ); itemModel->setContactName( bareJid_from ); itemModel->setJid( bareJid_from ); itemModel->setUnreadMsg( 1 ); itemModel->setStatusText( ""); cachedRoster->append(itemModel); itemModel = 0; delete itemModel; } item = 0; delete item; emit insertMessage(m_accountId,this->getBareJidByJid(xmppMsg.from()),xmppMsg.body(),QDateTime::currentDateTime().toString("dd-MM-yy hh:mm"),0); } }
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 MyXmppClient::initRoster() { qDebug() << "MyXmppClient::initRoster() called"; if (!rosterManager->isRosterReceived()) { qDebug() << "MyXmppClient::initRoster(): roster not available yet"; return; } cachedRoster->cleanList(); QStringList listBareJids = rosterManager->getRosterBareJids(); for( int j=0; j < listBareJids.length(); j++ ) { QString bareJid = listBareJids.at(j); cacheIM->addCacheJid( bareJid ); QXmppRosterIq::Item itemRoster = rosterManager->getRosterEntry( bareJid ); QString name = itemRoster.name(); vCardData vCdata = cacheIM->getVCard( bareJid ); if ( vCdata.isEmpty() && !disableAvatarCaching ) { qDebug() << "MyXmppClient::initRoster():" << bareJid << "has no VCard. Requesting."; vCardManager->requestVCard( bareJid ); } RosterItemModel *itemExists = (RosterItemModel*)cachedRoster->find(bareJid); if (itemExists == 0) { RosterItemModel *itemModel = new RosterItemModel( ); itemModel->setPresence( this->getPicPresence( QXmppPresence::Unavailable ) ); itemModel->setContactName( name ); itemModel->setJid( bareJid ); itemModel->setAvatar(cacheIM->getAvatarCache(bareJid)); cachedRoster->append(itemModel); itemModel = 0; delete itemModel; } else if (itemExists->name() != name) { itemExists->setContactName(name); emit contactRenamed(bareJid,name); } itemExists = 0; delete itemExists; } emit rosterChanged(); }
void MyXmppClient::itemAdded(const QString &bareJid ) { qDebug() << "MyXmppClient::itemAdded(): " << bareJid; QStringList resourcesList = rosterManager->getResources( bareJid ); RosterItemModel *itemExists = (RosterItemModel*)cachedRoster->find(bareJid); if (itemExists == 0) { RosterItemModel *itemModel = new RosterItemModel( ); itemModel->setPresence( this->getPicPresence(QXmppPresence::Unavailable) ); itemModel->setJid( bareJid ); itemModel->setAvatar(cacheIM->getAvatarCache(bareJid)); cachedRoster->append( itemModel ); itemModel = 0; delete itemModel; }; itemExists = 0; delete itemExists; for( int L = 0; L<resourcesList.length(); L++ ) { QString resource = resourcesList.at(L); this->initPresence( bareJid, resource ); } }