コード例 #1
0
ファイル: UserSearchController.cpp プロジェクト: swift/swift
Contact::ref UserSearchController::convertJIDtoContact(const JID& jid) {
    Contact::ref contact = std::make_shared<Contact>();
    contact->jid = jid;

    // name lookup
    boost::optional<XMPPRosterItem> rosterItem = rosterController_->getItem(jid);
    if (rosterItem && !rosterItem->getName().empty()) {
        contact->name = rosterItem->getName();
    } else {
        VCard::ref vcard = vcardManager_->getVCard(jid);
        if (vcard && !vcard->getFullName().empty()) {
            contact->name = vcard->getFullName();
        } else {
            contact->name = jid.toString();
        }
    }

    // presence lookup
    Presence::ref presence = presenceOracle_->getAccountPresence(jid);
    if (presence) {
        contact->statusType = presence->getShow();
    } else {
        contact->statusType = StatusShow::None;
    }

    // avatar lookup
    contact->avatarPath = avatarManager_->getAvatarPath(jid);
    return contact;
}
コード例 #2
0
        void testGetVCard() {
            std::shared_ptr<VCardFileStorage> testling(createTestling());
            VCard::ref vcard(new VCard());
            vcard->setFullName("Alice In Wonderland");
            testling->setVCard(JID("*****@*****.**"), vcard);

            VCard::ref result = testling->getVCard(JID("*****@*****.**"));
            CPPUNIT_ASSERT_EQUAL(std::string("Alice In Wonderland"), result->getFullName());
        }
コード例 #3
0
std::string VCardStorage::getPhotoHash(const JID& jid) const {
	VCard::ref vCard = getVCard(jid);
	if (vCard && !vCard->getPhoto().isEmpty()) {
		return Hexify::hexify(SHA1::getHash(vCard->getPhoto()));
	}
	else {
		return "";
	}
}
コード例 #4
0
ファイル: VCardManagerTest.cpp プロジェクト: jyhong836/swift
		void testGet_ExistingVCard() {
			boost::shared_ptr<VCardManager> testling = createManager();
			VCard::ref vcard(new VCard());
			vcard->setFullName("Foo Bar");
			vcardStorage->setVCard(JID("[email protected]/baz"), vcard);

			VCard::ref result = testling->getVCardAndRequestWhenNeeded(JID("[email protected]/baz"));

			CPPUNIT_ASSERT_EQUAL(std::string("Foo Bar"), result->getFullName());
			CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(stanzaChannel->sentStanzas.size()));
		}
コード例 #5
0
ファイル: VCardManagerTest.cpp プロジェクト: jyhong836/swift
		void testCreateSetVCardRequest_Error() {
			boost::shared_ptr<VCardManager> testling = createManager();
			VCard::ref vcard = boost::make_shared<VCard>();
			vcard->setFullName("New Name");
			SetVCardRequest::ref request = testling->createSetVCardRequest(vcard);
			request->send();

			stanzaChannel->onIQReceived(IQ::createError(JID("[email protected]/foo"), stanzaChannel->sentStanzas[0]->getID()));

			CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(changes.size()));
		}
コード例 #6
0
void MainController::handleVCardReceived(const JID& jid, VCard::ref vCard) {
	if (!jid.equals(jid_, JID::WithoutResource) || !vCard || vCard->getPhoto().isEmpty()) {
		return;
	}
	std::string hash = Hexify::hexify(SHA1::getHash(vCard->getPhoto()));
	if (hash != vCardPhotoHash_) {
		vCardPhotoHash_ = hash;
		if (client_ && client_->isAvailable()) {
			sendPresence(statusTracker_->getNextPresence());
		}
	}
}
コード例 #7
0
				std::string getPhotoHash(const JID& jid) const {
					if (photoHashes.find(jid) != photoHashes.end()) {
						return photoHashes.find(jid)->second;
					}
					VCard::ref vCard = getVCard(jid);
					if (vCard && !vCard->getPhoto().empty()) {
						return Hexify::hexify(SHA1::getHash(vCard->getPhoto()));
					}
					else {
						return "";
					}
				}
コード例 #8
0
ファイル: VCardManagerTest.cpp プロジェクト: jyhong836/swift
		void testCreateSetVCardRequest() {
			boost::shared_ptr<VCardManager> testling = createManager();
			VCard::ref vcard = boost::make_shared<VCard>();
			vcard->setFullName("New Name");
			SetVCardRequest::ref request = testling->createSetVCardRequest(vcard);
			request->send();

			stanzaChannel->onIQReceived(createSetVCardResult());

			CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(changes.size()));
			CPPUNIT_ASSERT_EQUAL(ownJID.toBare(), changes[0].first);
			CPPUNIT_ASSERT_EQUAL(std::string("New Name"), changes[0].second->getFullName());
		}
コード例 #9
0
void MainController::handleVCardReceived(const JID& jid, VCard::ref vCard) {
	if (!jid.equals(jid_, JID::WithoutResource) || !vCard) {
		return;
	}
	std::string hash;
	if (!vCard->getPhoto().empty()) {
		hash = Hexify::hexify(networkFactories_->getCryptoProvider()->getSHA1Hash(vCard->getPhoto()));
	}
	if (hash != vCardPhotoHash_) {
		vCardPhotoHash_ = hash;
		if (client_ && client_->isAvailable()) {
			sendPresence(statusTracker_->getNextPresence());
		}
	}
}
コード例 #10
0
std::string VCardFileStorage::getAndUpdatePhotoHash(const JID& jid, VCard::ref vCard) const {
	std::string hash;
	if (vCard && !vCard->getPhoto().empty()) {
		hash = Hexify::hexify(crypto->getSHA1Hash(vCard->getPhoto()));
	}
	std::pair<PhotoHashMap::iterator, bool> r = photoHashes.insert(std::make_pair(jid, hash));
	if (r.second) {
		savePhotoHashes();
	}
	else if (r.first->second != hash) {
		r.first->second = hash;
		savePhotoHashes();
	}
	return hash;
}
コード例 #11
0
void VCardUpdateAvatarManager::handleVCardChanged(const JID& from, VCard::ref vCard) {
	if (!vCard) {
		std::cerr << "Warning: " << from << ": null vcard payload" << std::endl;
		return;
	}

	if (vCard->getPhoto().isEmpty()) {
		setAvatarHash(from, "");
	}
	else {
		std::string hash = Hexify::hexify(SHA1::getHash(vCard->getPhoto()));
		if (!avatarStorage_->hasAvatar(hash)) {
			avatarStorage_->addAvatar(hash, vCard->getPhoto());
		}
		setAvatarHash(from, hash);
	}
}
コード例 #12
0
std::string VCardAvatarManager::getAvatarHash(const JID& jid) const {
    JID avatarJID = getAvatarJID(jid);
    std::string hash = vcardManager_->getPhotoHash(avatarJID);
    if (!hash.empty()) {
        if (!avatarStorage_->hasAvatar(hash)) {
            VCard::ref vCard = vcardManager_->getVCard(avatarJID);
            if (vCard) {
                avatarStorage_->addAvatar(hash, vCard->getPhoto());
            }
            else {
                // Can happen if the cache is inconsistent.
                hash = "";
            }
        }
    }
    return hash;
}
コード例 #13
0
std::vector<std::string> ContactEditController::nameSuggestionsFromVCard(VCard::ref vcard) {
	std::vector<std::string> suggestions;
	if (!vcard->getNickname().empty()) {
		suggestions.push_back(vcard->getNickname());
	}
	if (!vcard->getFullName().empty()) {
		suggestions.push_back(vcard->getFullName());
	}
	if (!vcard->getGivenName().empty()) {
		std::string suggestedName;
		suggestedName = vcard->getGivenName();
		boost::algorithm::trim(suggestedName);
		suggestions.push_back(suggestedName);
	}
	return suggestions;
}
コード例 #14
0
ファイル: QtVCardWidget.cpp プロジェクト: swift/swift
void QtVCardWidget::setVCard(VCard::ref vcard) {
    clearFields();
    this->vcard = std::make_shared<VCard>(*vcard);
    ui->photoAndName->setFormattedName(P2QSTRING(vcard->getFullName()));
    ui->photoAndName->setNickname(P2QSTRING(vcard->getNickname()));
    ui->photoAndName->setPrefix(P2QSTRING(vcard->getPrefix()));
    ui->photoAndName->setGivenName(P2QSTRING(vcard->getGivenName()));
    ui->photoAndName->setMiddleName(P2QSTRING(vcard->getMiddleName()));
    ui->photoAndName->setFamilyName(P2QSTRING(vcard->getFamilyName()));
    ui->photoAndName->setSuffix(P2QSTRING(vcard->getSuffix()));
    ui->photoAndName->setAvatar(vcard->getPhoto(), vcard->getPhotoType());

    for (const auto& address : vcard->getEMailAddresses()) {
        if (address.isInternet) {
            QtVCardInternetEMailField* internetEmailField = new QtVCardInternetEMailField(this, ui->cardFields);
            internetEmailField->initialize();
            internetEmailField->setInternetEMailAddress(address);
            appendField(internetEmailField);
        }
    }

    for (const auto& telephone : vcard->getTelephones()) {
        QtVCardTelephoneField* telField = new QtVCardTelephoneField(this, ui->cardFields);
        telField->initialize();
        telField->setTelephone(telephone);
        appendField(telField);
    }

    for (const auto& address : vcard->getAddresses()) {
        QtVCardAddressField* addressField = new QtVCardAddressField(this, ui->cardFields);
        addressField->initialize();
        addressField->setAddress(address);
        appendField(addressField);
    }

    for (const auto& label : vcard->getAddressLabels()) {
        QtVCardAddressLabelField* addressLabelField = new QtVCardAddressLabelField(this, ui->cardFields);
        addressLabelField->initialize();
        addressLabelField->setAddressLabel(label);
        appendField(addressLabelField);
    }

    if (!vcard->getBirthday().is_not_a_date_time()) {
        QtVCardBirthdayField* bdayField = new QtVCardBirthdayField(this, ui->cardFields);
        bdayField->initialize();
        bdayField->setBirthday(vcard->getBirthday());
        appendField(bdayField);
    }

    for (const auto& jid : vcard->getJIDs()) {
        QtVCardJIDField* jidField = new QtVCardJIDField(this, ui->cardFields);
        jidField->initialize();
        jidField->setJID(jid);
        appendField(jidField);
    }

    if (!vcard->getDescription().empty()) {
        QtVCardDescriptionField* descField = new QtVCardDescriptionField(this, ui->cardFields);
        descField->initialize();
        descField->setDescription(vcard->getDescription());
        appendField(descField);
    }

    for (const auto& org : vcard->getOrganizations()) {
        QtVCardOrganizationField* orgField = new QtVCardOrganizationField(this, ui->cardFields);
        orgField->initialize();
        orgField->setOrganization(org);
        appendField(orgField);
    }

    for (const auto& role : vcard->getRoles()) {
        QtVCardRoleField* roleField = new QtVCardRoleField(this, ui->cardFields);
        roleField->initialize();
        roleField->setRole(role);
        appendField(roleField);
    }

    for (const auto& title : vcard->getTitles()) {
        QtVCardTitleField* titleField = new QtVCardTitleField(this, ui->cardFields);
        titleField->initialize();
        titleField->setTitle(title);
        appendField(titleField);
    }

    for (const auto& url : vcard->getURLs()) {
        QtVCardURLField* urlField = new QtVCardURLField(this, ui->cardFields);
        urlField->initialize();
        urlField->setURL(url);
        appendField(urlField);
    }

    relayoutToolButton();
    setEditable(editable);
}