[Tcladdressbook-commits] Source TclAddressBook.c,1.8,1.9
Status: Alpha
Brought to you by:
bdesgraupes
|
From: <bde...@us...> - 2003-12-06 06:19:46
|
Update of /cvsroot/tcladdressbook/Source
In directory sc8-pr-cvs1:/tmp/cvs-serv17339/Source
Modified Files:
TclAddressBook.c
Log Message:
[remove property]
Index: TclAddressBook.c
===================================================================
RCS file: /cvsroot/tcladdressbook/Source/TclAddressBook.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- TclAddressBook.c 5 Dec 2003 20:21:30 -0000 1.8
+++ TclAddressBook.c 6 Dec 2003 06:19:43 -0000 1.9
@@ -1,7 +1,7 @@
/*
* File : "TclAddressBook.c"
* Created: 2003-11-26 12:54:15
- * Last modification: 2003-12-05 10:26:56
+ * Last modification: 2003-12-06 06:36:29
* Author: Bernard Desgraupes
* e-mail: <bde...@ea...>
*
@@ -18,7 +18,7 @@
*/
-// TclAddressBookUtils.h included in precompiled header
+/* TclAddressBookUtils.h included in precompiled header */
// #include "TclAddressBookUtils.h"
/*
@@ -775,15 +775,18 @@
*
* TclABCmd_Remove --
*
- * This procedure is invoked to process the [addressbook remove] Tcl command.
+ * This procedure is invoked to process the [addressbook remove record] and
+ * the the [addressbook remove property] Tcl commands.
* 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. What if recordID is a group ?
+ * - otherwise, remove recordID from the database.
+ * - [remove property] removes a property for the specified type of record
*
* Syntax:
- * addressbook remove recordID ?-fromgroup groupID?
+ * addressbook remove record recordID ?-fromgroup groupID?
+ * addressbook remove property (-groups|-persons) propName
*
* Results:
* A standard Tcl result.
@@ -803,90 +806,32 @@
Tcl_Obj *CONST objv[], /* Argument values. */
Tcl_Obj *resultPtr) /* Pointer to store the result. */
{
- ABAddressBookRef ab;
- ABRecordRef theRecord, fromGroup;
- CONST84 char * directUID;
- CONST84 char * fromUID;
- CFStringRef directCFStr;
- int length, kind, result;
- TextEncoding theEncoding = GetApplicationTextEncoding();
- Boolean removingFromGroup = false;
+ int index, result;
- static CONST char *removeSwitches[] = {
- "-fromgroup", (char *) NULL
+ static CONST char *removeSubcmds[] = {
+ "record", "property", (char *) NULL
};
enum {
- TCLAB_REMOVE_FROMGROUP
+ TCLAB_REMOVE_RECORD, TCLAB_REMOVE_PROPERTY
};
- if (objc != 3 && objc != 5) {
- Tcl_WrongNumArgs(interp, 2, objv, "recordID ?-fromgroup groupID?");
+ if (objc < 4 || objc > 6) {
+ Tcl_WrongNumArgs(interp, 2, objv, "(record|property) args");
return TCL_ERROR;
}
-
- if (objc == 5) {
- if (Tcl_GetIndexFromObj(interp, objv[3], removeSwitches, "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);
+
+ if (Tcl_GetIndexFromObj(interp, objv[2], removeSubcmds, "subcommand", 0, &index) != TCL_OK) {
return TCL_ERROR;
}
- if (removingFromGroup) {
- if ( !TclAB_CheckGroup(interp, ab, fromUID, "-fromgroup", &fromGroup) ) {
- result = TCL_ERROR;
- goto DONE;
- }
+ switch (index) {
+ case TCLAB_REMOVE_RECORD:
+ result = TclAB_RemoveRecord(interp, objc, objv, resultPtr);
- // 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;
- }
+ case TCLAB_REMOVE_PROPERTY:
+ result = TclAB_RemoveProperty(interp, objc, objv, resultPtr);
}
-
-DONE:
- CFRelease(theRecord);
return result;
}
|