[Tcladdressbook-commits] Source TclAddressBookUtils.c,1.2,1.3
Status: Alpha
Brought to you by:
bdesgraupes
|
From: <bde...@us...> - 2003-12-07 16:43:18
|
Update of /cvsroot/tcladdressbook/Source
In directory sc8-pr-cvs1:/tmp/cvs-serv761/Source
Modified Files:
TclAddressBookUtils.c
Log Message:
Renamed cmds (add-create, properties-property)
Index: TclAddressBookUtils.c
===================================================================
RCS file: /cvsroot/tcladdressbook/Source/TclAddressBookUtils.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- TclAddressBookUtils.c 6 Dec 2003 06:20:24 -0000 1.2
+++ TclAddressBookUtils.c 7 Dec 2003 16:43:15 -0000 1.3
@@ -1,7 +1,7 @@
/*
* File : "TclAddressBookUtils.c"
* Created: 2003-12-05 10:08:03
- * Last modification: 2003-12-06 06:35:27
+ * Last modification: 2003-12-07 16:58:34
* Author: Bernard Desgraupes
* e-mail: <bde...@ea...>
*
@@ -653,8 +653,7 @@
*
* TclAB_ResultListFromCFArray --
*
- * This function is invoked to determine the type (group or person)
- * corresponding to a particular UID.
+ * This function is invoked to bild a Tcl list from a CFArray.
*
* Results:
* None.
@@ -666,7 +665,7 @@
*/
void TclAB_ResultListFromCFArray(Tcl_Interp *interp, Tcl_Obj *resultPtr,
- CFArrayRef allSubGroups, Boolean onlyID,
+ CFArrayRef allElements, Boolean onlyID,
int inRecordType)
{
CFIndex theCount;
@@ -677,12 +676,17 @@
int result, i;
TextEncoding theEncoding = GetApplicationTextEncoding();
- theCount = CFArrayGetCount(allSubGroups);
+ Tcl_ResetResult(interp);
+ if (!allElements) {
+ return;
+ }
+
+ theCount = CFArrayGetCount(allElements);
for (i = 0; i < theCount; i++) {
Tcl_Obj * listPtr;
// Get the record at index i
- theGroup = (ABGroupRef) CFArrayGetValueAtIndex(allSubGroups,i);
+ theGroup = (ABGroupRef) CFArrayGetValueAtIndex(allElements,i);
// Get the unique id for this record
uniqueId = ABRecordCopyUniqueId(theGroup);
CFStringGetCString(uniqueId, theUID, sizeof(theUID), theEncoding);
@@ -776,7 +780,7 @@
/*
*----------------------------------------------------------------------
*
- * TclABCmd_Add --
+ * TclAB_CreateRecord --
*
* This function is invoked to process the [addressbook add group] and
* the [addressbook add person] Tcl commands.
@@ -796,7 +800,7 @@
*/
int
-TclAB_AddRecord(
+TclAB_CreateRecord(
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *CONST objv[], /* Argument values. */
@@ -913,7 +917,7 @@
/*
*----------------------------------------------------------------------
*
- * TclAB_AddProperty --
+ * TclAB_PropertyAdd --
*
* This function is invoked to process the [addressbook add property]
* Tcl command.
@@ -932,24 +936,21 @@
*/
int
-TclAB_AddProperty(
+TclAB_PropertyAdd(
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *CONST objv[], /* Argument values. */
- Tcl_Obj *resultPtr) /* Pointer to store the result. */
+ Tcl_Obj *resultPtr, /* Pointer to store the result. */
+ int inRecordType)
{
ABAddressBookRef ab;
CFStringRef theKey, theValue;
CFMutableDictionaryRef theDict;
- int index, kind, length, result;
+ int index, length, result;
int theInt;
SInt32 theSInt32;
TextEncoding theEncoding = GetApplicationTextEncoding();
- static CONST char *addpropSwitches[] = {
- "-groups", "-persons", (char *) NULL
- };
-
static CONST char *typeSwitches[] = {
"Array", "Data", "Date", "Dictionary", "Integer", "Real", "String",
"MultiArray","MultiData", "MultiDate", "MultiDictionary",
@@ -976,16 +977,12 @@
Tcl_ResetResult(interp);
if (objc != 6) {
- Tcl_WrongNumArgs(interp, 2, objv, "property (-groups|-persons) propName propType");
+ Tcl_WrongNumArgs(interp, 2, objv, "add (-groups|-persons) propName propType");
return TCL_ERROR;
}
Tcl_IncrRefCount(objv[4]);
- if (Tcl_GetIndexFromObj(interp, objv[3], addpropSwitches, "option", 0, &kind) != TCL_OK) {
- return TCL_ERROR;
- }
-
if (Tcl_GetIndexFromObj(interp, objv[5], typeSwitches, "property", 0, &index) != TCL_OK) {
return TCL_ERROR;
}
@@ -1002,9 +999,9 @@
CFDictionaryAddValue(theDict, theKey, theValue);
// Add the property to the Address Book
- if ( !ABAddPropertiesAndTypes(ab, kind ? kABPersonRecordType : kABGroupRecordType, theDict) ) {
+ if ( !ABAddPropertiesAndTypes(ab, inRecordType ? kABPersonRecordType : kABGroupRecordType, theDict) ) {
Tcl_AppendStringsToObj(resultPtr, "Couldn't add new property for ",
- kind ? "Person":"Group" , " records", (char *) NULL);
+ inRecordType ? "Person":"Group" , " records", (char *) NULL);
result = TCL_ERROR;
} else {
result = TCL_OK;
@@ -1021,19 +1018,15 @@
/*
*----------------------------------------------------------------------
*
- * TclAB_RemoveRecord --
+ * TclAB_PropertyNames --
*
- * This procedure is invoked to process the [addressbook remove] Tcl command.
+ * This procedure is invoked to process the [addressbook property] Tcl command.
* See the user documentation for details on what it does.
- * - if -fromgroup is specified, remove recordID from the group: recordID can be
- * either a person (remove it as a member of the group) or a group (remove it as
- * a subgroup of the group)
- * - otherwise, remove recordID from the database.
*
* Syntax:
- * addressbook remove person recordID ?-fromgroup groupID?
- * addressbook remove group recordID ?-fromgroup groupID?
- * addressbook remove record recordID ?-fromgroup groupID?
+ * addressbook property add (-groups|-persons) propName propType
+ * addressbook property remove (-groups|-persons) propName
+ * addressbook property names (-groups|-persons)
*
* Results:
* A standard Tcl result.
@@ -1044,102 +1037,59 @@
*----------------------------------------------------------------------
*/
-
int
-TclAB_RemoveRecord(
+TclAB_PropertyNames(
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *CONST objv[], /* Argument values. */
- Tcl_Obj *resultPtr) /* Pointer to store the result. */
+ Tcl_Obj *resultPtr, /* Pointer to store the result. */
+ int inRecordType)
{
+ CFIndex theCount;
+ CFStringRef theProperty;
+ CFArrayRef theItems;
+ char theName[256];
+ Tcl_Obj * objPtr;
+ int i, result;
ABAddressBookRef ab;
- ABRecordRef theRecord, fromGroup;
- CONST84 char * directUID;
- CONST84 char * fromUID;
- CFStringRef directCFStr;
- int length, kind, result;
- TextEncoding theEncoding = GetApplicationTextEncoding();
- Boolean removingFromGroup = false;
-
- static CONST char *removerecSwitches[] = {
- "-ingroup", (char *) NULL
- };
-
- if (objc != 3 && objc != 5) {
- Tcl_WrongNumArgs(interp, 2, objv, "record recordID ?-fromgroup groupID?");
- return TCL_ERROR;
- }
-
- if (objc == 5) {
- if (Tcl_GetIndexFromObj(interp, objv[3], removerecSwitches, "option", 0, &index) != TCL_OK) {
- return TCL_ERROR;
- } else {
- fromUID = Tcl_GetStringFromObj(objv[4], &length);
- removingFromGroup = true;
- }
- }
-
- result = TCL_OK;
- directUID = Tcl_GetStringFromObj(objv[2], &length);
// Get the address book
- ab = ABGetSharedAddressBook();
-
- directCFStr = CFStringCreateWithCString(NULL, directUID, theEncoding);
- // Find the record corresponding to the UID
- theRecord = ABCopyRecordForUniqueId(ab, directCFStr);
- CFRelease(directCFStr);
- if (!theRecord) {
- Tcl_AppendStringsToObj(resultPtr, "Unrecognized record ID", (char *) NULL);
- return TCL_ERROR;
- }
+ ab = ABGetSharedAddressBook();
+
+ switch (inRecordType) {
+ case rec_group:
+ theItems = ABCopyArrayOfPropertiesForRecordType(ab, kABGroupRecordType);
+ break;
+
+ case rec_person:
+ theItems = ABCopyArrayOfPropertiesForRecordType(ab, kABPersonRecordType);
+ break;
+ }
- if (removingFromGroup) {
- if ( !TclAB_CheckGroup(interp, ab, fromUID, "-fromgroup", &fromGroup) ) {
- result = TCL_ERROR;
- goto DONE;
- }
+ theCount = CFArrayGetCount(theItems);
+ for (i = 0; i < theCount; i++) {
+ // Get the record at index i
+ theProperty = CFArrayGetValueAtIndex(theItems,i);
- // Is recordID a person or a group?
- kind = TclAB_TypeFromRecord(ab, theRecord);
- switch (kind) {
- case rec_person:
- if (!ABGroupRemoveMember(fromGroup, theRecord)) {
- Tcl_AppendStringsToObj(resultPtr, "Couldn't remove member from group", (char *) NULL);
- result = TCL_ERROR;
- }
- break;
-
- case rec_group:
- if (!ABGroupRemoveGroup(fromGroup, theRecord)) {
- Tcl_AppendStringsToObj(resultPtr, "Couldn't remove subgroup from group", (char *) NULL);
- result = TCL_ERROR;
- }
- break;
-
- default:
- Tcl_AppendStringsToObj(resultPtr, "Unknown type for recordID argument", (char *) NULL);
- result = TCL_ERROR;
- break;
- }
- CFRelease(fromGroup);
- } else {
- if (!ABRemoveRecord(ab, theRecord)) {
- Tcl_AppendStringsToObj(resultPtr, "Couldn't remove record from database", (char *) NULL);
- result = TCL_ERROR;
- }
+ if (theProperty && CFStringGetCString(theProperty, theName, sizeof(theName), GetApplicationTextEncoding())) {
+ objPtr = Tcl_NewStringObj(theName, strlen(theName));
+ result = Tcl_ListObjAppendElement(interp, resultPtr, objPtr);
+ if (result != TCL_OK) {
+ Tcl_DecrRefCount(objPtr);
+ break;
+ }
+ }
}
-
-DONE:
- CFRelease(theRecord);
- return result;
+ CFRelease(theItems);
+
+ return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
- * TclAB_RemoveProperty --
+ * TclAB_PropertyRemove --
*
* This function is invoked to process the [addressbook remove property]
* Tcl command.
@@ -1158,38 +1108,31 @@
*/
int
-TclAB_RemoveProperty(
+TclAB_PropertyRemove(
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *CONST objv[], /* Argument values. */
- Tcl_Obj *resultPtr) /* Pointer to store the result. */
+ Tcl_Obj *resultPtr, /* Pointer to store the result. */
+ int inRecordType)
{
ABAddressBookRef ab;
CFStringRef theProp;
CFMutableArrayRef theArray;
- int index, kind, length, result;
+ int index, length, result;
int theInt;
SInt32 theSInt32;
char * propName;
- static CONST char *removepropSwitches[] = {
- "-groups", "-persons", (char *) NULL
- };
-
Tcl_ResetResult(interp);
if (objc != 5) {
- Tcl_WrongNumArgs(interp, 2, objv, "property (-groups|-persons) propName");
+ Tcl_WrongNumArgs(interp, 2, objv, "remove (-groups|-persons) propName");
return TCL_ERROR;
}
Tcl_IncrRefCount(objv[4]);
propName = Tcl_GetStringFromObj(objv[4], &length);
- if (Tcl_GetIndexFromObj(interp, objv[3], removepropSwitches, "option", 0, &kind) != TCL_OK) {
- return TCL_ERROR;
- }
-
// Get the address book
ab = ABGetSharedAddressBook();
@@ -1200,10 +1143,10 @@
CFArrayAppendValue(theArray, theProp);
// Add the property to the Address Book
- result = ABRemoveProperties(ab, kind ? kABPersonRecordType : kABGroupRecordType, theArray);
+ result = ABRemoveProperties(ab, inRecordType ? kABPersonRecordType : kABGroupRecordType, theArray);
if ( !result ) {
Tcl_AppendStringsToObj(resultPtr, "Couldn't remove property '",
- propName, "' for ", kind ? "Person":"Group" , " records", (char *) NULL);
+ propName, "' for ", inRecordType ? "Person":"Group" , " records", (char *) NULL);
result = TCL_ERROR;
} else {
result = TCL_OK;
@@ -1214,5 +1157,6 @@
CFRelease(theArray);
return result;
}
+
|