Ejemplo n.º 1
0
QByteArray vCard::toByteArray(vCardVersion version) const
{
    QStringList lines;

    lines.append(VC_BEGIN_TOKEN);

    switch (version)
    {
    case VC_VER_2_1:
        lines.append(vCardProperty(VC_VERSION, "2.1").toByteArray());
        break;

    case VC_VER_3_0:
        lines.append(vCardProperty(VC_VERSION, "3.0").toByteArray());
        break;

    default:
        return QByteArray();
    }

    for (const vCardProperty& property : this->properties())
        lines.append(property.toByteArray(version));

    lines.append(VC_END_TOKEN);

    return lines.join(QString(VC_END_LINE_TOKEN)).toUtf8();
}
Ejemplo n.º 2
0
vCardProperty vCardProperty::createKHID(const QString& khID, const vCardParamList& params)
{
    QStringList values;
    values.append(khID);

    return vCardProperty(VC_KHID, values, params);
}
Ejemplo n.º 3
0
vCardProperty vCardProperty::createdFormattedName(const QString& name)
{
    QStringList values;
    values.append(name);

    return vCardProperty(VC_FORMATTED_NAME, values);
}
Ejemplo n.º 4
0
vCardProperty vCardProperty::createNotes(const QString& notes)
{
    QStringList values;
    values.append(notes);

    return vCardProperty(VC_NOTE, values);
}
Ejemplo n.º 5
0
QList<vCardProperty> vCardProperty::fromByteArray(const QByteArray& data)
{
    QList<vCardProperty> properties;

    QStringList lines = QString::fromUtf8(data).split(VC_END_LINE_TOKEN);
    for (const QString& line : lines)
    {
        if (line == VC_BEGIN_TOKEN || line == VC_END_TOKEN)
            break;

        QStringList tokens = line.split(VC_ASSIGNMENT_TOKEN);
        if (tokens.count() >= 2)
        {
            QStringList property_tokens = tokens.at(0).split(VC_SEPARATOR_TOKEN);
            QString name = property_tokens.takeAt(0);

            if (name != VC_VERSION)
            {
                vCardParamList params = vCardParam::fromByteArray(property_tokens.join(QString(VC_SEPARATOR_TOKEN)).toUtf8());

                properties.append(vCardProperty(name, tokens.at(1), params));
            }
        }
    }

    return properties;
}
Ejemplo n.º 6
0
vCardProperty vCard::property(const QString& name, const vCardParamList& params, bool strict) const
{
    int count = m_properties.count();
    for (int i = 0; i < count; i++)
    {
        vCardProperty current = m_properties.at(i);
        if (current.name() == name)
        {
            vCardParamList current_params = current.params();

            if (strict)
            {
                if (params != current_params)
                    continue;
            }

            else
            {
                for (const vCardParam& param : params)
                    if (!current_params.contains(param))
                        continue;
            }

            return current;
        }
    }

    return vCardProperty();
}
Ejemplo n.º 7
0
vCardProperty vCardProperty::createPublicKey(const QString& publicKey, const vCardParamList& params)
{
    QStringList values;
    values.append(publicKey);

    return vCardProperty(VC_KH_PUBLIC_KEY, values, params);
}
Ejemplo n.º 8
0
vCardProperty vCardProperty::createAvatar(const std::vector<char>& iconData)
{
  QByteArray byteArray(iconData.data(), iconData.size());
  QString iconBase64 = QString::fromLatin1(byteArray.toBase64().data());
  QString propertuName = VC_PHOTO + QString(";PNG")/*icon format*/ + ";ENCODING=BASE64";
  return vCardProperty(propertuName, iconBase64);
}
Ejemplo n.º 9
0
vCardProperty vCardProperty::createGeographicPosition(qreal latitude, qreal longitude, const vCardParamList& params)
{
    QStringList values;
    values.insert(vCardProperty::Latitude, QString("%1").arg(latitude));
    values.insert(vCardProperty::Longitude, QString("%1").arg(longitude));

    return vCardProperty(VC_GEOGRAPHIC_POSITION, values, params);
}
Ejemplo n.º 10
0
vCardProperty vCardProperty::createOrganization(const QString& name, const QStringList& levels, const vCardParamList& params)
{
    QStringList values;
    values.append(name);
    values.append(levels);

    return vCardProperty(VC_ORGANIZATION, values, params);
}
Ejemplo n.º 11
0
vCardProperty vCardProperty::createName(const QString& firstname, const QString& lastname, const QString& additional, const QString& prefix, const QString& suffix, const vCardParamList& params)
{
    QStringList values;
    values.insert(vCardProperty::Lastname, lastname);
    values.insert(vCardProperty::Firstname, firstname);
    values.insert(vCardProperty::Additional, additional);
    values.insert(vCardProperty::Prefix, prefix);
    values.insert(vCardProperty::Suffix, suffix);

    return vCardProperty(VC_NAME, values, params);
}
Ejemplo n.º 12
0
vCardProperty vCardProperty::createAddress(const QString& street, const QString& locality, const QString& region, const QString& postal_code, const QString& country, const QString& post_office_box, const QString& ext_address, const vCardParamList& params)
{
    QStringList values;
    values.insert(vCardProperty::PostOfficeBox, post_office_box);
    values.insert(vCardProperty::ExtendedAddress, ext_address);
    values.insert(vCardProperty::Street, street);
    values.insert(vCardProperty::Locality, locality);
    values.insert(vCardProperty::Region, region);
    values.insert(vCardProperty::PostalCode, postal_code);
    values.insert(vCardProperty::Country, country);

    return vCardProperty(VC_ADDRESS, values, params);
}
Ejemplo n.º 13
0
vCardProperty vCardProperty::createNotes(const QString& notes)
{
  /** \warning Multiline notes don't work properly on Windows 7
      "Windows system contact" application doesn't split multilines text.      
      It looks like it is a problem on the "Windows system contact" side
   */  
  QString notesTmp = notes;
  // "\n" is new line in the vCard standard.
  notesTmp.replace("\n", "\\n");
  QStringList values;
  values.append(notesTmp);

  return vCardProperty(VC_NOTE, values);
}
Ejemplo n.º 14
0
QList<vCardProperty> vCardProperty::fromByteArray(const QByteArray& data)
{
    QList<vCardProperty> properties;

    QStringList lines = QString::fromUtf8(data).split(VC_END_LINE_TOKEN);
    foreach (QString line, lines)
    {
        if (line == VC_BEGIN_TOKEN || line == VC_END_TOKEN)
            break;

        //URLs have tokens, only split on the first ':' or properly handle escaped assignments '\:'
        QStringList tokens = line.split(VC_ASSIGNMENT_TOKEN);
        if (tokens.count() >= 2)
        {
            QStringList property_tokens = tokens.at(0).split(VC_SEPARATOR_TOKEN);
            QString name = property_tokens.takeAt(0);

            if (name != VC_VERSION)
            {
                vCardParamList params = vCardParam::fromByteArray(property_tokens.join(QString(VC_SEPARATOR_TOKEN)).toUtf8());

                QString token;
                for(int i=1; i<tokens.count(); i++){
                    token.append( tokens.at(i) );

                    if(i+1 < tokens.count()){
                        token.append(VC_ASSIGNMENT_TOKEN);
                    }
                }

                token.replace("\\:", ":");

                properties.append(vCardProperty(name, token, params));
            }
        }
    }

    return properties;
}
Ejemplo n.º 15
0
QList<vCardProperty> vCardProperty::fromByteArray(const QByteArray& data)
{
    QList<vCardProperty> properties;

    QStringList lines = QString::fromUtf8(data).split(VC_END_LINE_TOKEN);
    foreach (QString line, lines)
    {
        if (line == VC_BEGIN_TOKEN || line == VC_END_TOKEN)
            break;

        QStringList tokens = line.split(VC_ASSIGNMENT_TOKEN);
        if (tokens.count() >= 2)
        {
            QStringList property_tokens = tokens.at(0).split(VC_SEPARATOR_TOKEN);
            QString name = property_tokens.takeAt(0);

            // scheme of URLs uses ':' it's not VC_ASSIGNMENT_TOKEN
            if (tokens.count() >= 3 && name == VC_URL && VC_ASSIGNMENT_TOKEN == ':')
            {
                if (tokens.at(tokens.size() - 2).contains(QRegExp("ftp|http|https|data"))) {
                    tokens[tokens.size() - 2] = tokens.at(tokens.size() - 2) + ":" + tokens.at(tokens.size() - 1);
                    tokens.takeLast();
                }
            }

            if (name != VC_VERSION)
            {
                vCardParamList params = vCardParam::fromByteArray(property_tokens.join(QString(VC_SEPARATOR_TOKEN)).toUtf8());

                properties.append(vCardProperty(name, tokens.at(1), params));
            }
        }
    }

    return properties;
}
Ejemplo n.º 16
0
vCardProperty vCardProperty::createBirthday(const QDateTime& birthday, const vCardParamList& params)
{
    return vCardProperty(VC_BIRTHDAY, birthday.toString("yyyy-MM-ddThh:mm:ssZ"), params);
}
Ejemplo n.º 17
0
vCardProperty vCardProperty::createTelephone(const QString& telephoneNumber, const vCardParamList& params)
{
    return vCardProperty(VC_TELEPHONE, telephoneNumber, params);
}