コード例 #1
0
ファイル: core.cpp プロジェクト: Pik-9/qTox
QString Core::getPeerName(const ToxId& id) const
{
    QString name;
    CUserId cid(id.toString());

    uint32_t friendId = tox_friend_by_public_key(tox, (uint8_t*)cid.data(), nullptr);
    if (friendId == std::numeric_limits<uint32_t>::max())
    {
        qWarning() << "getPeerName: No such peer";
        return name;
    }

    const size_t nameSize = tox_friend_get_name_size(tox, friendId, nullptr);
    if (nameSize == SIZE_MAX)
        return name;

    uint8_t* cname = new uint8_t[nameSize<TOX_MAX_NAME_LENGTH ? TOX_MAX_NAME_LENGTH : nameSize];
    if (!tox_friend_get_name(tox, friendId, cname, nullptr))
    {
        qWarning() << "getPeerName: Can't get name of friend "+QString().setNum(friendId);
        delete[] cname;
        return name;
    }

    name = CString::toString(cname, nameSize);
    delete[] cname;
    return name;
}
コード例 #2
0
ファイル: core.cpp プロジェクト: rohilsurana/qTox
QString Core::getPeerName(const ToxID& id) const
{
    QString name;
    CUserId cid(id.toString());

    uint32_t friendId = tox_friend_by_public_key(tox, (uint8_t*)cid.data(), nullptr);
    if (friendId == std::numeric_limits<uint32_t>::max())
    {
        qWarning() << "Core::getPeerName: No such peer "+id.toString();
        return name;
    }

    const size_t nameSize = tox_friend_get_name_size(tox, friendId, nullptr);
    if (nameSize == SIZE_MAX)
    {
        //qDebug() << "Core::getPeerName: Can't get name of friend "+QString().setNum(friendId)+" ("+id.toString()+")";
        return name;
    }

    uint8_t* cname = new uint8_t[nameSize<TOX_MAX_NAME_LENGTH ? TOX_MAX_NAME_LENGTH : nameSize];
    if (tox_friend_get_name(tox, friendId, cname, nullptr) == false)
    {
        qWarning() << "Core::getPeerName: Can't get name of friend "+QString().setNum(friendId)+" ("+id.toString()+")";
        delete[] cname;
        return name;
    }

    name = name.fromLocal8Bit((char*)cname, nameSize);
    delete[] cname;
    return name;
}
コード例 #3
0
ファイル: core.cpp プロジェクト: mpxc/qTox
/**
 * @brief Checks if we have a friend by public key
 */
bool Core::hasFriendWithPublicKey(const ToxPk& publicKey) const
{
    if (publicKey.isEmpty()) {
        return false;
    }

    // TODO: error handling
    uint32_t friendId = tox_friend_by_public_key(tox, publicKey.getBytes(), nullptr);
    return friendId != std::numeric_limits<uint32_t>::max();
}