[Tcladdressbook-commits] Source TclAddressBook.c,1.11,1.12
Status: Alpha
Brought to you by:
bdesgraupes
|
From: <bde...@us...> - 2003-12-07 16:43:00
|
Update of /cvsroot/tcladdressbook/Source
In directory sc8-pr-cvs1:/tmp/cvs-serv687/Source
Modified Files:
TclAddressBook.c
Log Message:
Renamed cmds (add-create, properties-property)
Index: TclAddressBook.c
===================================================================
RCS file: /cvsroot/tcladdressbook/Source/TclAddressBook.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- TclAddressBook.c 7 Dec 2003 16:04:06 -0000 1.11
+++ TclAddressBook.c 7 Dec 2003 16:42:57 -0000 1.12
@@ -1,7 +1,7 @@
/*
* File : "TclAddressBook.c"
* Created: 2003-11-26 12:54:15
- * Last modification: 2003-12-07 02:00:17
+ * Last modification: 2003-12-07 16:51:26
* Author: Bernard Desgraupes
* e-mail: <bde...@ea...>
*
@@ -26,17 +26,17 @@
*/
static int TclABCmd_AddressBook(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]);
-static int TclABCmd_Add(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], Tcl_Obj *resultPtr);
static int TclABCmd_Changed(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], Tcl_Obj *resultPtr);
static int TclABCmd_Count(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], Tcl_Obj *resultPtr);
-static int TclABCmd_GetMe(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], Tcl_Obj *resultPtr);
+static int TclABCmd_Create(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], Tcl_Obj *resultPtr);
static int TclABCmd_Export(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], Tcl_Obj *resultPtr);
+static int TclABCmd_GetMe(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], Tcl_Obj *resultPtr);
static int TclABCmd_Groups(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], Tcl_Obj *resultPtr);
static int TclABCmd_Image(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], Tcl_Obj *resultPtr);
static int TclABCmd_Import(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], Tcl_Obj *resultPtr);
static int TclABCmd_Parents(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], Tcl_Obj *resultPtr);
static int TclABCmd_Persons(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], Tcl_Obj *resultPtr);
-static int TclABCmd_Properties(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], Tcl_Obj *resultPtr);
+static int TclABCmd_Property(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], Tcl_Obj *resultPtr);
static int TclABCmd_Record(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], Tcl_Obj *resultPtr);
static int TclABCmd_Remove(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], Tcl_Obj *resultPtr);
static int TclABCmd_Save(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], Tcl_Obj *resultPtr);
@@ -121,14 +121,14 @@
int index, result;
static CONST char *switches[] = {
- "add", "changed", "count", "export", "getme", "groups",
+ "changed", "count", "create", "export", "getme", "groups",
"image", "import", "parents", "persons", "properties",
"record", "remove", "save", "search", "type", "value", (char *) NULL
};
enum {
- TCLAB_ADD, TCLAB_CHANGED, TCLAB_COUNT, TCLAB_EXPORT, TCLAB_GETME, TCLAB_GROUPS,
- TCLAB_IMAGE, TCLAB_IMPORT, TCLAB_PARENTS, TCLAB_PERSONS, TCLAB_PROPERTIES,
+ TCLAB_CHANGED, TCLAB_COUNT, TCLAB_CREATE, TCLAB_EXPORT, TCLAB_GETME, TCLAB_GROUPS,
+ TCLAB_IMAGE, TCLAB_IMPORT, TCLAB_PARENTS, TCLAB_PERSONS, TCLAB_PROPERTY,
TCLAB_RECORD, TCLAB_REMOVE, TCLAB_SAVE, TCLAB_SEARCH, TCLAB_TYPE, TCLAB_VALUE
};
@@ -145,8 +145,8 @@
}
switch (index) {
- case TCLAB_ADD:
- result = TclABCmd_Add(clientData, interp, objc, objv, resultPtr);
+ case TCLAB_CREATE:
+ result = TclABCmd_Create(clientData, interp, objc, objv, resultPtr);
break;
case TCLAB_CHANGED:
@@ -185,8 +185,8 @@
result = TclABCmd_Persons(clientData, interp, objc, objv, resultPtr);
break;
- case TCLAB_PROPERTIES:
- result = TclABCmd_Properties(clientData, interp, objc, objv, resultPtr);
+ case TCLAB_PROPERTY:
+ result = TclABCmd_Property(clientData, interp, objc, objv, resultPtr);
break;
case TCLAB_RECORD:
@@ -224,16 +224,15 @@
/*
*----------------------------------------------------------------------
*
- * TclABCmd_Add --
+ * TclABCmd_Create --
*
- * This procedure is invoked to process the [addressbook add] Tcl command.
+ * This procedure is invoked to process the [addressbook create] Tcl command.
* See the user documentation for details on what it does. It can be used
* either to add a new group or person record to the database, or to add
* a new property.
*
* Syntax:
- * addressbook add (group | person) name ?-ingroup groupID?
- * addressbook add property (-groups|-persons) propName propType
+ * addressbook create (group | person) name ?-ingroup groupID?
*
* Results:
* A standard Tcl result.
@@ -245,7 +244,7 @@
*/
int
-TclABCmd_Add(
+TclABCmd_Create(
ClientData /* clientData */, /* Not used. */
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
@@ -254,32 +253,29 @@
{
int index, result;
- static CONST char *addSubcmds[] = {
- "group", "person", "property", (char *) NULL
+ static CONST char *createSubcmds[] = {
+ "group", "person", (char *) NULL
};
enum {
- TCLAB_ADD_GROUP, TCLAB_ADD_PERSON, TCLAB_ADD_PROPERTY
+ TCLAB_ADD_GROUP, TCLAB_ADD_PERSON
};
if (objc < 4 || objc > 6) {
- Tcl_WrongNumArgs(interp, 2, objv, "(group|person|property) args");
+ Tcl_WrongNumArgs(interp, 2, objv, "(group|person) args");
return TCL_ERROR;
}
- if (Tcl_GetIndexFromObj(interp, objv[2], addSubcmds, "subcommand", 0, &index) != TCL_OK) {
+ if (Tcl_GetIndexFromObj(interp, objv[2], createSubcmds, "subcommand", 0, &index) != TCL_OK) {
return TCL_ERROR;
}
switch (index) {
case TCLAB_ADD_GROUP:
- result = TclAB_AddRecord(interp, objc, objv, resultPtr, rec_group);
+ result = TclAB_CreateRecord(interp, objc, objv, resultPtr, rec_group);
case TCLAB_ADD_PERSON:
- result = TclAB_AddRecord(interp, objc, objv, resultPtr, rec_person);
-
- case TCLAB_ADD_PROPERTY:
- result = TclAB_AddProperty(interp, objc, objv, resultPtr);
+ result = TclAB_CreateRecord(interp, objc, objv, resultPtr, rec_person);
}
return result;
}
@@ -911,13 +907,15 @@
/*
*----------------------------------------------------------------------
*
- * TclABCmd_Properties --
+ * TclABCmd_Property --
*
- * This procedure is invoked to process the [addressbook properties] Tcl command.
+ * This procedure is invoked to process the [addressbook property] Tcl command.
* See the user documentation for details on what it does.
*
* Syntax:
- * addressbook properties (-groups|-persons)
+ * addressbook property add (-groups|-persons) propName propType
+ * addressbook property remove (-groups|-persons) propName
+ * addressbook property names (-groups|-persons)
*
* Results:
* A standard Tcl result.
@@ -929,70 +927,57 @@
*/
int
-TclABCmd_Properties(
+TclABCmd_Property(
ClientData /* clientData */, /* Not used. */
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *CONST objv[], /* Argument values. */
Tcl_Obj *resultPtr) /* Pointer to store the result. */
{
- CFIndex theCount;
- CFStringRef theProperty;
- CFArrayRef theItems;
- char theName[256];
- Tcl_Obj * objPtr;
- int result, index, i;
- ABAddressBookRef ab;
+ int result, index, kind;
- static CONST char *propertiesSwitches[] = {
- "-groups", "-persons", (char *) NULL
+ static CONST char *propSubcmdSwitches[] = {
+ "add", "names", "remove", (char *) NULL
};
enum {
- TCLAB_PROPERTIES_GROUPS, TCLAB_PROPERTIES_PERSONS
+ TCLAB_PROPERTY_ADD, TCLAB_PROPERTY_NAMES, TCLAB_PROPERTY_REMOVE
};
+ static CONST char *propertySwitches[] = {
+ "-groups", "-persons", (char *) NULL
+ };
- if (objc != 3) {
- Tcl_WrongNumArgs(interp, 2, objv, "(-groups|-persons)");
+ if (objc < 4 || objc > 6) {
+ Tcl_WrongNumArgs(interp, 2, objv, "(add|names|remove) (-groups|-persons) args");
return TCL_ERROR;
}
- // Get the address book
- ab = ABGetSharedAddressBook();
+ if (Tcl_GetIndexFromObj(interp, objv[3], propSubcmdSwitches,
+ "subcommand", 0, &index) != TCL_OK) {
+ return TCL_ERROR;
+ }
- if (Tcl_GetIndexFromObj(interp, objv[2], propertiesSwitches,
- "option", 0, &index) != TCL_OK) {
+ if (Tcl_GetIndexFromObj(interp, objv[2], propertySwitches,
+ "option", 0, &kind) != TCL_OK) {
return TCL_ERROR;
}
switch (index) {
- case TCLAB_PROPERTIES_GROUPS:
- theItems = ABCopyArrayOfPropertiesForRecordType(ab, kABGroupRecordType);
+ case TCLAB_PROPERTY_ADD:
+ result = TclAB_PropertyAdd(interp, objc, objv, resultPtr, kind);
break;
- case TCLAB_PROPERTIES_PERSONS:
- theItems = ABCopyArrayOfPropertiesForRecordType(ab, kABPersonRecordType);
+ case TCLAB_PROPERTY_NAMES:
+ result = TclAB_PropertyNames(interp, objc, objv, resultPtr, kind);
break;
- }
-
- theCount = CFArrayGetCount(theItems);
- for (i = 0; i < theCount; i++) {
- // Get the record at index i
- theProperty = CFArrayGetValueAtIndex(theItems,i);
- 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;
- }
- }
+ case TCLAB_PROPERTY_REMOVE:
+ result = TclAB_PropertyRemove(interp, objc, objv, resultPtr, kind);
+ break;
}
- CFRelease(theItems);
- return TCL_OK;
+ return result;
}
@@ -1072,18 +1057,15 @@
*
* TclABCmd_Remove --
*
- * This procedure is invoked to process the [addressbook remove record] and
- * the the [addressbook remove property] Tcl commands.
+ * This procedure is invoked to process the [addressbook remove] 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.
- * - [remove property] removes a property for the specified type of record
*
* Syntax:
- * addressbook remove record recordID ?-fromgroup groupID?
- * addressbook remove property (-groups|-persons) propName
+ * addressbook remove recordID ?-fromgroup groupID?
*
* Results:
* A standard Tcl result.
@@ -1094,7 +1076,6 @@
*----------------------------------------------------------------------
*/
-
int
TclABCmd_Remove(
ClientData /* clientData */, /* Not used. */
@@ -1103,32 +1084,87 @@
Tcl_Obj *CONST objv[], /* Argument values. */
Tcl_Obj *resultPtr) /* Pointer to store the result. */
{
- int index, result;
-
- static CONST char *removeSubcmds[] = {
- "record", "property", (char *) NULL
- };
+
+ ABAddressBookRef ab;
+ ABRecordRef theRecord, fromGroup;
+ CONST84 char * directUID;
+ CONST84 char * fromUID;
+ CFStringRef directCFStr;
+ int length, kind, result;
+ TextEncoding theEncoding = GetApplicationTextEncoding();
+ Boolean removingFromGroup = false;
- enum {
- TCLAB_REMOVE_RECORD, TCLAB_REMOVE_PROPERTY
+ static CONST char *rmRecSwitches[] = {
+ "-fromgroup", (char *) NULL
};
- if (objc < 4 || objc > 6) {
- Tcl_WrongNumArgs(interp, 2, objv, "(record|property) args");
+ if (objc != 3 && objc != 5) {
+ Tcl_WrongNumArgs(interp, 2, objv, "record recordID ?-fromgroup groupID?");
return TCL_ERROR;
}
-
- if (Tcl_GetIndexFromObj(interp, objv[2], removeSubcmds, "subcommand", 0, &index) != TCL_OK) {
+
+ if (objc == 5) {
+ if (Tcl_GetIndexFromObj(interp, objv[3], rmRecSwitches, "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;
}
- switch (index) {
- case TCLAB_REMOVE_RECORD:
- result = TclAB_RemoveRecord(interp, objc, objv, resultPtr);
+ if (removingFromGroup) {
+ if ( !TclAB_CheckGroup(interp, ab, fromUID, "-fromgroup", &fromGroup) ) {
+ result = TCL_ERROR;
+ goto DONE;
+ }
- case TCLAB_REMOVE_PROPERTY:
- result = TclAB_RemoveProperty(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;
+ }
}
+
+DONE:
+ CFRelease(theRecord);
return result;
}
|