/** * Returns the removed item - but only if it's the only one, otherwise * the return result is undefined. */ ContactRosterItem* GroupRosterItem::removeChild(const JID& jid) { std::vector<RosterItem*>::iterator it = children_.begin(); ContactRosterItem* removed = NULL; while (it != children_.end()) { ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(*it); if (contact && contact->getJID() == jid) { displayedChildren_.erase(std::remove(displayedChildren_.begin(), displayedChildren_.end(), contact), displayedChildren_.end()); removed = contact; delete contact; it = children_.erase(it); continue; } GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(*it); if (group) { ContactRosterItem* groupRemoved = group->removeChild(jid); if (groupRemoved) { removed = groupRemoved; } } ++it; } onChildrenChanged(); onDataChanged(); return removed; }
void testUnavailablePresence() { std::vector<std::string> groups; groups.push_back("testGroup1"); JID from("*****@*****.**"); xmppRoster_->addContact(from, "name", groups, RosterItemPayload::Both); Presence::ref lowPresence(new Presence()); lowPresence->setFrom(withResource(from, "bob")); lowPresence->setPriority(2); lowPresence->setShow(StatusShow::Away); lowPresence->setStatus("Not here"); Presence::ref lowPresenceOffline(new Presence()); lowPresenceOffline->setFrom(withResource(from, "bob")); lowPresenceOffline->setStatus("Signing out"); lowPresenceOffline->setType(Presence::Unavailable); Presence::ref highPresence(new Presence()); highPresence->setFrom(withResource(from, "bert")); highPresence->setPriority(10); highPresence->setStatus("So totally here"); Presence::ref highPresenceOffline(new Presence()); highPresenceOffline->setFrom(withResource(from, "bert")); highPresenceOffline->setType(Presence::Unavailable); stanzaChannel_->onPresenceReceived(lowPresence); Presence::ref accountPresence = presenceOracle_->getAccountPresence(from); CPPUNIT_ASSERT_EQUAL(StatusShow::Away, accountPresence->getShow()); stanzaChannel_->onPresenceReceived(highPresence); accountPresence = presenceOracle_->getAccountPresence(from); CPPUNIT_ASSERT_EQUAL(StatusShow::Online, accountPresence->getShow()); stanzaChannel_->onPresenceReceived(highPresenceOffline); // After this, the roster should show the low presence. ContactRosterItem* item = dynamic_cast<ContactRosterItem*>(dynamic_cast<GroupRosterItem*>(CHILDREN[0])->getChildren()[0]); CPPUNIT_ASSERT(item); Presence::ref low = presenceOracle_->getAccountPresence(from); CPPUNIT_ASSERT_EQUAL(Presence::Available, low->getType()); CPPUNIT_ASSERT_EQUAL(lowPresence->getStatus(), low->getStatus()); CPPUNIT_ASSERT_EQUAL(lowPresence->getShow(), item->getStatusShow()); CPPUNIT_ASSERT_EQUAL(lowPresence->getStatus(), item->getStatusText()); stanzaChannel_->onPresenceReceived(lowPresenceOffline); item = dynamic_cast<ContactRosterItem*>(dynamic_cast<GroupRosterItem*>(CHILDREN[0])->getChildren()[0]); CPPUNIT_ASSERT(item); /* A verification that if the test fails, it's the RosterController, not the PresenceOracle. */ low = presenceOracle_->getHighestPriorityPresence(from); CPPUNIT_ASSERT_EQUAL(Presence::Unavailable, low->getType()); CPPUNIT_ASSERT_EQUAL(lowPresenceOffline->getStatus(), low->getStatus()); CPPUNIT_ASSERT_EQUAL(StatusShow::None, item->getStatusShow()); CPPUNIT_ASSERT_EQUAL(lowPresenceOffline->getStatus(), item->getStatusText()); }
void testNotHighestPresence() { std::vector<std::string> groups; groups.push_back("testGroup1"); JID from("*****@*****.**"); xmppRoster_->addContact(from, "name", groups, RosterItemPayload::Both); Presence::ref lowPresence(new Presence()); lowPresence->setFrom(withResource(from, "bob")); lowPresence->setPriority(2); lowPresence->setStatus("Not here"); Presence::ref highPresence(new Presence()); highPresence->setFrom(withResource(from, "bert")); highPresence->setPriority(10); highPresence->setStatus("So totally here"); stanzaChannel_->onPresenceReceived(highPresence); stanzaChannel_->onPresenceReceived(lowPresence); ContactRosterItem* item = dynamic_cast<ContactRosterItem*>(dynamic_cast<GroupRosterItem*>(CHILDREN[0])->getChildren()[0]); CPPUNIT_ASSERT(item); CPPUNIT_ASSERT_EQUAL(highPresence->getStatus(), item->getStatusText()); }
void QtRosterWidget::mouseMoveEvent(QMouseEvent *event) { if (!(event->buttons() & Qt::LeftButton)) { return; } if ((event->pos() - dragStartPosition).manhattanLength()< QApplication::startDragDistance()) { return; } clickedIndex=indexAt(event->pos()); if (!clickedIndex.isValid()) { return; } QDrag *drag = new QDrag(this); QMimeData *mimeData = new QMimeData(); RosterItem* item = static_cast<RosterItem*>(clickedIndex.internalPointer()); ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item); std::string jid=contact->getJID().toString(); QString str=QString::P2QSTRING(jid); mimeData->setText(str); drag->setMimeData(mimeData); drag->exec(Qt::CopyAction | Qt::MoveAction); }