Ejemplo n.º 1
0
Picture VCardTool::parsePicture(const VCardLine &line)
{
    Picture pic;

    const QStringList params = line.parameterList();
    if(params.findIndex("encoding") != -1)
    {
        QImage img;
        img.loadFromData(line.value().asByteArray());
        pic.setData(img);
    }
    else if(params.findIndex("value") != -1)
    {
        if(line.parameter("value").lower() == "uri")
            pic.setUrl(line.value().asString());
    }

    if(params.findIndex("type") != -1)
        pic.setType(line.parameter("type"));

    return pic;
}
Ejemplo n.º 2
0
Picture VCardFormatImpl::readPictureValue( VCARD::ContentLine *cl, VCARD::EntityType type, const Addressee &addr )
{
  Picture pic;
  bool isInline = false;
  QString picType;
  TextValue *v = (TextValue *)cl->value();

  ParamList params = cl->paramList();
  ParamListIterator it( params );
  for( ; it.current(); ++it ) {
    if ( (*it)->name() == "ENCODING" && (*it)->value() == "b" )
      isInline = true;
    if ( (*it)->name() == "TYPE" && !(*it)->value().isEmpty() )
      picType = QString::fromUtf8( (*it)->value() );
  }

  if ( isInline ) {
    QImage img;
    if ( v->asString() == "<dummy>" ) { // no picture inline stored => picture is in cache
      QString dir;
      if ( type == EntityPhoto )
        dir = "photos";
      if ( type == EntityLogo )
        dir = "logos";

      img.load( locateLocal( "data", "kabc/" + dir + "/" + addr.uid() ) );
    } else {
      QByteArray data;
      KCodecs::base64Decode( v->asString(), data );
      img.loadFromData( data );
    }
    pic.setData( img );
    pic.setType( picType );
  } else {
    pic.setUrl( QString::fromUtf8( v->asString() ) );
  }

  return pic;
}