[Tcladdressbook-commits] Source TclAddressBookUtils.c,1.14,1.15
Status: Alpha
Brought to you by:
bdesgraupes
|
From: Bernard D. <bde...@us...> - 2004-07-29 13:30:45
|
Update of /cvsroot/tcladdressbook/Source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5266/Source Modified Files: TclAddressBookUtils.c Log Message: Debugging return values Index: TclAddressBookUtils.c =================================================================== RCS file: /cvsroot/tcladdressbook/Source/TclAddressBookUtils.c,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- TclAddressBookUtils.c 29 Jul 2004 09:12:14 -0000 1.14 +++ TclAddressBookUtils.c 29 Jul 2004 13:30:36 -0000 1.15 @@ -1037,7 +1037,7 @@ ABAddressBookRef ab; CFStringRef theKey, theValue; CFMutableDictionaryRef theDict; - int index, length, result; + int index, length, result = TCL_OK; int theInt; char * propName; @@ -1072,9 +1072,7 @@ Tcl_AppendStringsToObj(resultPtr, "Couldn't add property '", propName, "' to ", inRecordType ? "Person":"Group" , " records", (char *) NULL); result = TCL_ERROR; - } else { - result = TCL_OK; - } + } } else { Tcl_AppendStringsToObj(resultPtr, "CFCreate error", (char *) NULL); result = TCL_ERROR; @@ -1191,13 +1189,13 @@ ABAddressBookRef ab; CFStringRef theProp; CFMutableArrayRef theArray; - int length, result; + int length, num, result = TCL_OK; char * propName; Tcl_ResetResult(interp); if (objc != 5) { - Tcl_WrongNumArgs(interp, 2, objv, "remove (-groups|-persons) propName"); + Tcl_WrongNumArgs(interp, 2, objv, "remove (-groups|-persons|recordID) propName"); return TCL_ERROR; } @@ -1209,23 +1207,39 @@ // Get the address book ab = ABGetSharedAddressBook(); - // Create a CFArray and store the property therein - theArray = CFArrayCreateMutable(NULL, 0, NULL); - CFArrayAppendValue(theArray, theProp); - CFRelease(theProp); - - // Remove the property from the Address Book - result = ABRemoveProperties(ab, inRecordType ? kABPersonRecordType : kABGroupRecordType, theArray); - CFRelease(theArray); - if ( !result ) { - Tcl_AppendStringsToObj(resultPtr, "Couldn't remove property '", propName, - "' for ", inRecordType ? "Person":"Group" , " records", (char *) NULL); - result = TCL_ERROR; + if (inRecordType == rec_undefined) { + // The third argument was a record ID + CONST84 char * theUID; + CFStringRef theCFStr; + ABRecordRef theRecord; + + theUID = Tcl_GetStringFromObj(objv[3], &length); + theCFStr = CFStringCreateWithCString(NULL, theUID, NULL); + + // Find the record corresponding to the UID + theRecord = ABCopyRecordForUniqueId(ab, theCFStr); + CFRelease(theCFStr); + if (!ABRecordRemoveValue(theRecord, theProp)) { + Tcl_AppendStringsToObj(resultPtr, "Couldn't remove property '", propName, + "' from the record", (char *) NULL); + result = TCL_ERROR; + } + CFRelease(theRecord); } else { + // The third argument was -groups or -persons. + // Create a CFArray to store the property. + theArray = CFArrayCreateMutable(NULL, 0, NULL); + CFArrayAppendValue(theArray, theProp); + CFRelease(theProp); + + // Remove the property from all the records of this type in the Address Book + num = ABRemoveProperties(ab, inRecordType ? kABPersonRecordType : kABGroupRecordType, theArray); + CFRelease(theArray); + Tcl_SetObjResult(interp, Tcl_NewIntObj(num)); result = TCL_OK; } } else { - Tcl_AppendStringsToObj(resultPtr, "CFStringCreateWithCString error", (char *) NULL); + Tcl_AppendStringsToObj(resultPtr, "Problem getting CFString for property", (char *) NULL); result = TCL_ERROR; } |