[Tcladdressbook-commits] Source TclAddressBook.c,1.38,1.39
Status: Alpha
Brought to you by:
bdesgraupes
|
From: Bernard D. <bde...@us...> - 2004-08-08 20:32:09
|
Update of /cvsroot/tcladdressbook/Source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14408/Source Modified Files: TclAddressBook.c Log Message: Image now copied when importing a VCard Index: TclAddressBook.c =================================================================== RCS file: /cvsroot/tcladdressbook/Source/TclAddressBook.c,v retrieving revision 1.38 retrieving revision 1.39 diff -u -d -r1.38 -r1.39 --- TclAddressBook.c 3 Aug 2004 17:47:33 -0000 1.38 +++ TclAddressBook.c 8 Aug 2004 20:31:58 -0000 1.39 @@ -1,7 +1,7 @@ /* * File : "TclAddressBook.c" * Created: 2003-11-26 12:54:15 - * Last modification: 2004-08-03 11:45:18 + * Last modification: 2004-08-08 22:27:19 * Author: Bernard Desgraupes * e-mail: <bde...@ea...> * @@ -661,7 +661,8 @@ ABRecordRef theRecord; CFStringRef uidRef; CFDataRef vCard; - int kind, length, result, success; + CONST84 char * theUID; + int kind, length; Tcl_Obj * objPtr; if (objc != 3) { @@ -669,34 +670,26 @@ return TCL_ERROR; } - uidRef = CFStringCreateWithCString(NULL, Tcl_GetStringFromObj(objv[2], &length), NULL); // Get the address book ab = ABGetSharedAddressBook(); - // Find the record corresponding to the UID - success = TclAB_RecordFromUID(ab, uidRef, resultPtr, &theRecord); - CFRelease(uidRef); - if (!success) {return TCL_ERROR;} - // Is it a person or a group? - kind = TclAB_TypeFromRecord(ab, theRecord); - if (kind != rec_person) { - Tcl_AppendStringsToObj(resultPtr, "Not a person record", (char *) NULL); - CFRelease(theRecord); + // Check if second argument is a person and get the corresponding record + theUID = Tcl_GetStringFromObj(objv[2], &length); + if ( !TclAB_CheckItem(interp, ab, theUID, "second", &theRecord, rec_person) ) { return TCL_ERROR; } vCard = ABPersonCopyVCardRepresentation(theRecord); + CFRelease(theRecord); if (vCard) { objPtr = Tcl_NewByteArrayObj( CFDataGetBytePtr(vCard), CFDataGetLength(vCard) ); Tcl_SetObjResult(interp, objPtr); + CFRelease(vCard); } else { Tcl_AppendStringsToObj(resultPtr, "Couldn't get vCard representation", (char *) NULL); - CFRelease(theRecord); return TCL_ERROR; } - CFRelease(vCard); - CFRelease(theRecord); return TCL_OK; } @@ -1028,7 +1021,7 @@ importedRecord = ABPersonCreateWithVCardRepresentation(vCard); CFRelease(vCard); // Adding the imported record directly to the database causes a - // crash. So we create a new record and copy the improted property/value + // crash. So we create a new record and copy the imported property/value // pairs to the new record. newRecord = ABPersonCreate(); if (!importedRecord || !newRecord) { @@ -1058,8 +1051,15 @@ } CFRelease(allProps); - // TODO: also copy the image if any - + // Also copy the image if there is one + { + CFDataRef imageRef = ABPersonCopyImageData(importedRecord); + if (imageRef) { + ABPersonSetImageData(newRecord, imageRef); + CFRelease(imageRef); + } + } + // Add the new record to the Address Book. Don't save here: leave // this to the Tcl level. if ( ABAddRecord(ab, newRecord) ) { |