int main(int argc,char **argv) { KAboutData aboutData("testkabc",I18N_NOOP("TestKabc"),"0.1"); KCmdLineArgs::init(argc, argv, &aboutData); KApplication app( false, false ); AddressBook *ab = StdAddressBook::self(); #define READ #ifdef READ AddressBook::Iterator it; for ( it = ab->begin(); it != ab->end(); ++it ) { QString vcard; VCardConverter converter; converter.addresseeToVCard( *it, vcard ); kdDebug() << "card=" << vcard << endl; } #else Addressee addr; addr.setGivenName("Tobias"); addr.setFamilyName("Koenig"); Picture pic; QImage img; img.load("/home/tobias/test.png"); /* pic.setData(img); pic.setType(QImage::imageFormat("/home/tobias/test.png")); */ pic.setUrl("http://www.mypict.de"); addr.setLogo( pic ); ab->insertAddressee( addr ); StdAddressBook::save(); #endif return 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; }
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; }