Esempio n. 1
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 "";
	}
}
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());
		}
	}
}
				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 "";
					}
				}
Esempio n. 4
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());
		}
	}
}
Esempio n. 5
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;
}
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);
	}
}
Esempio n. 7
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;
}
Esempio n. 8
0
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);
}