29
29
* For more details of Google Contacts' GData API, see the <ulink type="http" url="http://code.google.com/apis/contacts/docs/2.0/reference.html">
30
30
* online documentation</ulink>.
33
* <title>Querying for Groups</title>
35
* GDataContactsService *service;
38
* GError *error = NULL;
40
* /<!-- -->* Create a service *<!-- -->/
41
* service = create_contacts_service ();
43
* /<!-- -->* Query for groups *<!-- -->/
44
* feed = gdata_contacts_service_query_groups (service, NULL, NULL, NULL, NULL, &error);
46
* g_object_unref (service);
48
* if (error != NULL) {
49
* g_error ("Error querying for groups: %s", error->message);
50
* g_error_free (error);
54
* /<!-- -->* Iterate through the returned groups and do something with them *<!-- -->/
55
* for (i = gdata_feed_get_entries (feed); i != NULL; i = i->next) {
56
* const gchar *system_group_id, *group_name;
57
* gboolean is_system_group;
58
* GDataContactsGroup *group = GDATA_CONTACTS_GROUP (i->data);
60
* /<!-- -->* Determine whether the group's a system group. If so, you should use the system group ID to provide your application's own
61
* * translations of the group name, as it's not translated. *<!-- -->/
62
* system_group_id = gdata_contacts_group_get_system_group_id (group);
63
* is_system_group = (system_group_id != NULL) ? TRUE : FALSE;
64
* group_name = (is_system_group == TRUE) ? get_group_name_for_system_group_id (system_group_id)
65
* : gdata_entry_get_title (GDATA_ENTRY (group));
67
* /<!-- -->* Do something with the group here, such as insert it into a UI. Note that system groups are not allowed to be deleted,
68
* * so you may want to make certain parts of your UI insensitive accordingly if the group is a system group. *<!-- -->/
71
* g_object_unref (feed);
75
* The Contacts service can be manipulated using batch operations, too. See the
76
* <ulink type="http" url="http://code.google.com/apis/contacts/docs/3.0/developers_guide_protocol.html#Batch">online documentation on batch
77
* operations</ulink> for more information.
80
* <title>Performing a Batch Operation on Contacts</title>
82
* GDataContactsService *service;
83
* GDataBatchOperation *operation;
85
* GDataLink *batch_link;
87
* GError *error = NULL;
89
* /<!-- -->* Create a service *<!-- -->/
90
* service = create_contacts_service ();
92
* /<!-- -->* Create the batch operation; this requires that we have done a query first so that we can get the batch link *<!-- -->/
93
* feed = do_some_query (service);
94
* batch_link = gdata_feed_look_up_link (feed, GDATA_LINK_BATCH);
95
* operation = gdata_batchable_create_operation (GDATA_BATCHABLE (service), gdata_link_get_uri (batch_link));
96
* g_object_unref (feed);
98
* gdata_batch_operation_add_query (operation, contact_entry_id_to_query, GDATA_TYPE_CONTACTS_CONTACT,
99
* (GDataBatchOperationCallback) batch_query_cb, user_data);
100
* gdata_batch_operation_add_insertion (operation, new_entry, (GDataBatchOperationCallback) batch_insertion_cb, user_data);
101
* gdata_batch_operation_add_update (operation, old_entry, (GDataBatchOperationCallback) batch_update_cb, user_data);
102
* gdata_batch_operation_add_deletion (operation, entry_to_delete, (GDataBatchOperationCallback) batch_deletion_cb, user_data);
104
* /<!-- -->* Run the batch operation and handle the results in the various callbacks *<!-- -->/
105
* gdata_test_batch_operation_run (operation, NULL, &error);
107
* g_object_unref (operation);
108
* g_object_unref (service);
110
* if (error != NULL) {
111
* g_error ("Error running batch operation: %s", error->message);
112
* g_error_free (error);
117
* batch_query_cb (guint operation_id, GDataBatchOperationType operation_type, GDataEntry *entry, GError *error, gpointer user_data)
119
* /<!-- -->* operation_type == GDATA_BATCH_OPERATION_QUERY *<!-- -->/
120
* /<!-- -->* Reference and do something with the returned entry. *<!-- -->/
124
* batch_insertion_cb (guint operation_id, GDataBatchOperationType operation_type, GDataEntry *entry, GError *error, gpointer user_data)
126
* /<!-- -->* operation_type == GDATA_BATCH_OPERATION_INSERTION *<!-- -->/
127
* /<!-- -->* Reference and do something with the returned entry. *<!-- -->/
131
* batch_update_cb (guint operation_id, GDataBatchOperationType operation_type, GDataEntry *entry, GError *error, gpointer user_data)
133
* /<!-- -->* operation_type == GDATA_BATCH_OPERATION_UPDATE *<!-- -->/
134
* /<!-- -->* Reference and do something with the returned entry. *<!-- -->/
138
* batch_deletion_cb (guint operation_id, GDataBatchOperationType operation_type, GDataEntry *entry, GError *error, gpointer user_data)
140
* /<!-- -->* operation_type == GDATA_BATCH_OPERATION_DELETION, entry == NULL *<!-- -->/