VCardLine VCardTool::createPicture(const QString &identifier, const Picture &pic) { VCardLine line(identifier); if(pic.isIntern()) { if(!pic.data().isNull()) { QByteArray input; QBuffer buffer(input); buffer.open(IO_WriteOnly); QImageIO iio(&buffer, "JPEG"); iio.setImage(pic.data()); iio.setQuality(100); iio.write(); line.setValue(input); line.addParameter("encoding", "b"); line.addParameter("type", "image/jpeg"); } } else if(!pic.url().isEmpty()) { line.setValue(pic.url()); line.addParameter("value", "URI"); } return line; }
void VCardFormatImpl::addPictureValue( VCARD::VCard *vcard, VCARD::EntityType type, const Picture &pic, const Addressee &addr, bool intern ) { ContentLine cl; cl.setName( EntityTypeToParamName( type ) ); if ( pic.isIntern() && pic.data().isNull() ) return; if ( !pic.isIntern() && pic.url().isEmpty() ) return; ParamList params; if ( pic.isIntern() ) { QImage img = pic.data(); if ( intern ) { // only for vCard export we really write the data inline QByteArray data; QDataStream s( data, IO_WriteOnly ); s.setVersion( 4 ); // to produce valid png files s << img; cl.setValue( new TextValue( KCodecs::base64Encode( data ) ) ); } else { // save picture in cache QString dir; if ( type == EntityPhoto ) dir = "photos"; if ( type == EntityLogo ) dir = "logos"; img.save( locateLocal( "data", "kabc/" + dir + "/" + addr.uid() ), pic.type().utf8() ); cl.setValue( new TextValue( "<dummy>" ) ); } params.append( new Param( "ENCODING", "b" ) ); if ( !pic.type().isEmpty() ) params.append( new Param( "TYPE", pic.type().utf8() ) ); } else { cl.setValue( new TextValue( pic.url().utf8() ) ); params.append( new Param( "VALUE", "uri" ) ); } cl.setParamList( params ); vcard->add( cl ); }