Update of /cvsroot/tcladdressbook/Source
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18328/Source
Modified Files:
TclAddressBook.c
Log Message:
Subcommands to [identifier] command
Index: TclAddressBook.c
===================================================================
RCS file: /cvsroot/tcladdressbook/Source/TclAddressBook.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- TclAddressBook.c 29 Jul 2004 20:14:04 -0000 1.28
+++ TclAddressBook.c 30 Jul 2004 11:14:34 -0000 1.29
@@ -1,7 +1,7 @@
/*
* File : "TclAddressBook.c"
* Created: 2003-11-26 12:54:15
- * Last modification: 2004-07-29 11:06:58
+ * Last modification: 2004-07-30 11:36:35
* Author: Bernard Desgraupes
* e-mail: <bde...@ea...>
*
@@ -787,14 +787,11 @@
* See the user documentation for details on what it does.
*
* Syntax:
- * addressbook identifier personID groupID property ?label?
+ * addressbook identifier count personID propName
+ * addressbook identifier get personID propName index
+ * addressbook identifier primary personID propName
+ * addressbook identifier set groupID personID propName ?identifier?
*
- * If the ?label? argument is specified, the command tries to set the
- * distribution identifier of the property to that value, otherwise it returns
- * the current value of the distribution identifier. It concerns
- * multi-value list properties and applies to a particular person belonging to
- * a particular group. If ?label? is empty, the primary default value is
- * reset.
*
* Results:
* A standard Tcl result.
@@ -813,104 +810,45 @@
Tcl_Obj *CONST objv[], /* Argument values. */
Tcl_Obj *resultPtr) /* Pointer to store the result. */
{
- ABAddressBookRef ab;
- CONST84 char * theProperty, * thePersonUID, * theGroupUID, * theNewVal;
- CFStringRef propertyRef, valueRef;
- ABRecordRef personRecord, groupRecord;
- ABPropertyType thePropType;
- int length, result;
- Boolean setIt = false;
-
- if (objc != 5 && objc != 6) {
- Tcl_WrongNumArgs(interp, 2, objv, "recordID groupID property ?label?");
- return TCL_ERROR;
- }
-
- Tcl_ResetResult(interp);
-
- thePersonUID = Tcl_GetStringFromObj(objv[2], &length);
- theGroupUID = Tcl_GetStringFromObj(objv[3], &length);
-
- // Get the address book
- ab = ABGetSharedAddressBook();
+ int result = TCL_ERROR, index, kind;
- // Check if second argument is a person and get the corresponding record
- if ( !TclAB_CheckItem(interp, ab, thePersonUID, "second", &personRecord, rec_person) ) {
- return TCL_ERROR;
- }
+ static CONST char *identSubcmdSwitches[] = {
+ "count", "get", "primary", "set", (char *) NULL
+ };
- // Check if third argument is a group and get the corresponding record
- if ( !TclAB_CheckItem(interp, ab, theGroupUID, "third", &groupRecord, rec_group) ) {
- CFRelease(personRecord);
+ enum {
+ TCLAB_IDENTIFIER_COUNT, TCLAB_IDENTIFIER_GET,
+ TCLAB_IDENTIFIER_PRIMARY, TCLAB_IDENTIFIER_SET
+ };
+
+ if (objc < 5) {
+ Tcl_WrongNumArgs(interp, 2, objv, "(count|get|set) ?args?");
return TCL_ERROR;
}
- Tcl_IncrRefCount(objv[4]);
- theProperty = Tcl_GetStringFromObj(objv[4], &length);
-
- // Make CFString object for property
- propertyRef = CFStringCreateWithCString(NULL, theProperty, kCFStringEncodingUTF8);
- if (!propertyRef) {
- Tcl_AppendStringsToObj(resultPtr, "Problem getting CFString for property", (char *) NULL);
- result = TCL_ERROR;
- goto DONE;
+ if (Tcl_GetIndexFromObj(interp, objv[2], identSubcmdSwitches,
+ "subcommand", 0, &index) != TCL_OK) {
+ return TCL_ERROR;
}
-
- // Find the property type (string, date, multivalue...)
- thePropType = ABTypeOfProperty(ab, kABPersonRecordType, propertyRef);
- if (thePropType == kABErrorInProperty) {
- Tcl_AppendStringsToObj(resultPtr, "Unknown property '", theProperty,
- "' for Person records", (char *) NULL);
- CFRelease(propertyRef);
- result = TCL_ERROR;
- goto DONE;
- }
- if (objc == 6) {
- theNewVal = Tcl_GetStringFromObj(objv[5], &length);
- if (length == 0) {
- valueRef = NULL;
- } else {
- valueRef = CFStringCreateWithCString(NULL, theNewVal, kCFStringEncodingUTF8);
- }
- setIt = true;
- }
-
- if (setIt) {
-// ABGroupSetDistributionIdentifier(groupRecord, personRecord, propertyRef, valueRef)
-// ABGroupSetDistributionIdentifier(groupRecord, personRecord, kABAddressProperty, kABAddressHomeLabel)
- if (!ABGroupSetDistributionIdentifier(groupRecord, personRecord, propertyRef, valueRef)) {
- Tcl_AppendStringsToObj(resultPtr, "Couldn't set distribution identifier for '",
- theProperty, "' property", (char *) NULL);
- CFRelease(propertyRef);
- if (valueRef != NULL) CFRelease(valueRef);
- result = TCL_ERROR;
- goto DONE;
- }
- } else {
- char theString[256];
- Tcl_DString ds;
+ switch (index) {
+ case TCLAB_IDENTIFIER_COUNT:
+ result = TclAB_IdentifierCount(interp, objc, objv, resultPtr);
+ break;
- valueRef = ABGroupCopyDistributionIdentifier(groupRecord, personRecord, propertyRef);
- if (!valueRef) {
- Tcl_AppendStringsToObj(resultPtr, "Couldn't get distribution identifier of '",
- theProperty, "' property for this record", (char *) NULL);
- CFRelease(propertyRef);
- result = TCL_ERROR;
- goto DONE;
- }
- CFStringGetCString(valueRef, theString, sizeof(theString), NULL);
- Tcl_ExternalToUtfDString(gMacRomanEnc, theString, strlen(theString), &ds);
- Tcl_DStringResult(interp, &ds);
- Tcl_DStringFree(&ds);
- CFRelease(valueRef);
+ case TCLAB_IDENTIFIER_GET:
+ result = TclAB_IdentifierGet(interp, objc, objv, resultPtr);
+ break;
+
+ case TCLAB_IDENTIFIER_PRIMARY:
+ result = TclAB_IdentifierPrimary(interp, objc, objv, resultPtr);
+ break;
+
+ case TCLAB_IDENTIFIER_SET:
+ result = TclAB_IdentifierSet(interp, objc, objv, resultPtr);
+ break;
}
- CFRelease(propertyRef);
-DONE:
- Tcl_DecrRefCount(objv[4]);
- CFRelease(groupRecord);
- CFRelease(personRecord);
return result;
}
|