phonemgr r308 - in trunk: . libgsm
- From: hadess svn gnome org
- To: svn-commits-list gnome org
- Subject: phonemgr r308 - in trunk: . libgsm
- Date: Tue, 17 Jun 2008 09:10:57 +0000 (UTC)
Author: hadess
Date: Tue Jun 17 09:10:57 2008
New Revision: 308
URL: http://svn.gnome.org/viewvc/phonemgr?rev=308&view=rev
Log:
2008-06-17 Bastien Nocera <hadess hadess net>
* configure.in: Require evolution-data-server in the backend as
well, so we can parse vCards
* libgsm/phonemgr-utils.c (vcard_to_phonebook_entry):
* libgsm/phonemgr-utils.h: vCard to phonebook entry parsing
* libgsm/phonemgr-listener.c (phonemgr_listener_get_own_details),
(phonemgr_listener_list_all_data),
(phonemgr_listener_parse_data_uuid), (phonemgr_listener_get_data),
(phonemgr_listener_delete_data), (phonemgr_listener_put_data):
* libgsm/phonemgr-listener.h: Add _list_all_data, _get_data,
_delete_data, and _put_data functions, that should be exported
for Conduit's use (see #456259)
Modified:
trunk/ChangeLog
trunk/libgsm/phonemgr-listener.c
trunk/libgsm/phonemgr-listener.h
trunk/libgsm/phonemgr-utils.c
trunk/libgsm/phonemgr-utils.h
Modified: trunk/libgsm/phonemgr-listener.c
==============================================================================
--- trunk/libgsm/phonemgr-listener.c (original)
+++ trunk/libgsm/phonemgr-listener.c Tue Jun 17 09:10:57 2008
@@ -832,7 +832,7 @@
} else if (error == GN_ERR_INVALIDMEMORYTYPE) {
g_message ("Couldn't get our own phone number (no Own Number phonebook)");
return;
- } else if (error == GN_ERR_NOTREADY) {
+ } else {
return;
}
@@ -1174,6 +1174,251 @@
g_warning ("Can't set date: %s", phonemgr_utils_gn_error_to_string (error, &perr));
}
+char **
+phonemgr_listener_list_all_data (PhonemgrListener *l,
+ PhonemgrListenerDataType type)
+{
+ switch (type) {
+ case PHONEMGR_LISTENER_DATA_CONTACT:
+ {
+ GPtrArray *a;
+ gn_memory_status memstat;
+ gn_error error;
+ guint i;
+
+ g_mutex_lock (l->mutex);
+ memstat.memory_type = gn_str2memory_type("ME");
+ l->phone_state->data.memory_status = &memstat;
+ error = phonemgr_listener_gnokii_func (GN_OP_GetMemoryStatus, l);
+ //FIXME better error?
+ if (error != GN_ERR_NONE) {
+ g_mutex_unlock (l->mutex);
+ break;
+ }
+ a = g_ptr_array_sized_new (memstat.used);
+ //FIXME there might be holes in the addressbook :/
+ for (i = 1; i <= memstat.used; i++) {
+ char *uuid;
+ uuid = g_strdup_printf ("GPM-UUID-%s-%s-%d", l->imei, "ME", i);
+ g_ptr_array_add (a, uuid);
+ }
+
+ memstat.memory_type = gn_str2memory_type("SM");
+ l->phone_state->data.memory_status = &memstat;
+ error = phonemgr_listener_gnokii_func (GN_OP_GetMemoryStatus, l);
+ //FIXME better error?
+ if (error != GN_ERR_NONE) {
+ g_ptr_array_add (a, NULL);
+ g_mutex_unlock (l->mutex);
+ return (char **) g_ptr_array_free (a, FALSE);
+ }
+
+ for (i = 1; i <= memstat.used; i++) {
+ char *uuid;
+ uuid = g_strdup_printf ("GPM-UUID-%s-%s-%d", l->imei, "SM", i);
+ g_ptr_array_add (a, uuid);
+ }
+ g_ptr_array_add (a, NULL);
+ g_mutex_unlock (l->mutex);
+
+ return (char **) g_ptr_array_free (a, FALSE);
+ }
+ case PHONEMGR_LISTENER_DATA_CALENDAR:
+ break;
+ case PHONEMGR_LISTENER_DATA_TODO:
+ break;
+ default:
+ g_assert_not_reached ();
+ }
+
+ return NULL;
+}
+
+static gboolean
+phonemgr_listener_parse_data_uuid (const char *dataid,
+ char **memory_type,
+ int *index)
+{
+ char *s;
+
+ g_return_val_if_fail (dataid != NULL, FALSE);
+
+ if (g_str_has_prefix (dataid, "GPM-UUID-") == FALSE)
+ return FALSE;
+ s = strchr (dataid + strlen ("GPM-UUID-") + 1, '-');
+ if (s == NULL)
+ return FALSE;
+ if (strlen(s) < 5)
+ return FALSE;
+ *memory_type = g_strndup (s + 1, 2);
+ *index = atoi (s + 4);
+ return TRUE;
+}
+
+char *
+phonemgr_listener_get_data (PhonemgrListener *l,
+ PhonemgrListenerDataType type,
+ const char *dataid)
+{
+ switch (type) {
+ case PHONEMGR_LISTENER_DATA_CONTACT:
+ {
+ gn_phonebook_entry entry;
+ char *memory_type, *retval;
+ gn_error error;
+ int index;
+
+ if (phonemgr_listener_parse_data_uuid (dataid, &memory_type, &index) == FALSE)
+ return NULL;
+
+ g_mutex_lock (l->mutex);
+
+ memset(&entry, 0, sizeof(gn_phonebook_entry));
+ entry.memory_type = gn_str2memory_type(memory_type);
+ entry.location = index;
+
+ l->phone_state->data.phonebook_entry = &entry;
+ error = phonemgr_listener_gnokii_func (GN_OP_ReadPhonebook, l);
+ if (error != GN_ERR_NONE || entry.empty != FALSE) {
+ g_mutex_unlock (l->mutex);
+ return NULL;
+ }
+
+ retval = gn_phonebook2vcardstr (&entry);
+ g_free (memory_type);
+
+ g_mutex_unlock (l->mutex);
+
+ return retval;
+ }
+ break;
+ case PHONEMGR_LISTENER_DATA_CALENDAR:
+ break;
+ case PHONEMGR_LISTENER_DATA_TODO:
+ break;
+ default:
+ g_assert_not_reached ();
+ }
+
+ return NULL;
+}
+
+gboolean
+phonemgr_listener_delete_data (PhonemgrListener *l,
+ PhonemgrListenerDataType type,
+ const char *dataid)
+{
+ switch (type) {
+ case PHONEMGR_LISTENER_DATA_CONTACT:
+ {
+ gn_phonebook_entry entry;
+ char *memory_type, *retval;
+ gn_error error;
+ int index;
+
+ if (phonemgr_listener_parse_data_uuid (dataid, &memory_type, &index) == FALSE)
+ return FALSE;
+
+ g_mutex_lock (l->mutex);
+
+ memset(&entry, 0, sizeof(gn_phonebook_entry));
+ entry.memory_type = gn_str2memory_type(memory_type);
+ entry.location = index;
+ entry.empty = TRUE;
+
+ l->phone_state->data.phonebook_entry = &entry;
+ error = phonemgr_listener_gnokii_func (GN_OP_DeletePhonebook, l);
+ g_free (memory_type);
+
+ g_mutex_unlock (l->mutex);
+
+ return (error != GN_ERR_NONE);
+ }
+ break;
+ case PHONEMGR_LISTENER_DATA_CALENDAR:
+ break;
+ case PHONEMGR_LISTENER_DATA_TODO:
+ break;
+ default:
+ g_assert_not_reached ();
+ }
+
+ return FALSE;
+}
+
+char *
+phonemgr_listener_put_data (PhonemgrListener *l,
+ PhonemgrListenerDataType type,
+ const char *data)
+{
+ switch (type) {
+ case PHONEMGR_LISTENER_DATA_CONTACT:
+ {
+ gn_phonebook_entry entry;
+ char *retval;
+ gn_error error;
+ guint i;
+
+ g_mutex_lock (l->mutex);
+
+ memset(&entry, 0, sizeof(gn_phonebook_entry));
+ if (vcard_to_phonebook_entry (data, &entry) == FALSE) {
+ g_message ("Couldn't parse the data...");
+ return NULL;
+ }
+ entry.memory_type = GN_MT_ME;
+
+ /* Find an empty spot */
+ for (i = 1; ; i++) {
+ gn_phonebook_entry aux;
+
+ memcpy(&aux, &entry, sizeof(gn_phonebook_entry));
+ l->phone_state->data.phonebook_entry = &aux;
+ l->phone_state->data.phonebook_entry->location = i;
+ error = phonemgr_listener_gnokii_func (GN_OP_ReadPhonebook, l);
+ if (error != GN_ERR_NONE && error != GN_ERR_EMPTYLOCATION)
+ break;
+ if (aux.empty || error == GN_ERR_EMPTYLOCATION) {
+ entry.location = aux.location;
+ error = GN_ERR_NONE;
+ break;
+ }
+ }
+
+ if (error != GN_ERR_NONE) {
+ g_mutex_unlock (l->mutex);
+ return NULL;
+ }
+
+ //FIXME This should sanitise the phone numbers
+ gn_phonebook_entry_sanitize(&entry);
+
+ l->phone_state->data.phonebook_entry = &entry;
+ error = phonemgr_listener_gnokii_func (GN_OP_WritePhonebook, l);
+
+ if (error != GN_ERR_NONE) {
+ g_mutex_unlock (l->mutex);
+ return NULL;
+ }
+
+ retval = g_strdup_printf ("GPM-UUID-%s-%s-%d", l->imei, "ME", entry.location);
+
+ g_mutex_unlock (l->mutex);
+
+ return retval;
+ }
+ break;
+ case PHONEMGR_LISTENER_DATA_CALENDAR:
+ break;
+ case PHONEMGR_LISTENER_DATA_TODO:
+ break;
+ default:
+ g_assert_not_reached ();
+ }
+
+ return FALSE;
+}
+
gboolean
phonemgr_listener_connected (PhonemgrListener *l)
{
Modified: trunk/libgsm/phonemgr-listener.h
==============================================================================
--- trunk/libgsm/phonemgr-listener.h (original)
+++ trunk/libgsm/phonemgr-listener.h Tue Jun 17 09:10:57 2008
@@ -56,6 +56,12 @@
PHONEMGR_LISTENER_CALL_UNKNOWN
} PhonemgrListenerCallStatus;
+typedef enum {
+ PHONEMGR_LISTENER_DATA_CONTACT,
+ PHONEMGR_LISTENER_DATA_CALENDAR,
+ PHONEMGR_LISTENER_DATA_TODO
+} PhonemgrListenerDataType;
+
#define CALL_NAME_UNKNOWN "Unknown"
#define CALL_NAME_RESTRICTED "Withheld"
@@ -89,6 +95,19 @@
void phonemgr_listener_set_time (PhonemgrListener *l,
time_t time);
+char ** phonemgr_listener_list_all_data
+ (PhonemgrListener *l,
+ PhonemgrListenerDataType type);
+char * phonemgr_listener_get_data (PhonemgrListener *l,
+ PhonemgrListenerDataType type,
+ const char *dataid);
+gboolean phonemgr_listener_delete_data (PhonemgrListener *l,
+ PhonemgrListenerDataType type,
+ const char *dataid);
+char * phonemgr_listener_put_data (PhonemgrListener *l,
+ PhonemgrListenerDataType type,
+ const char *data);
+
gboolean phonemgr_listener_connected (PhonemgrListener *listener);
/* Error types */
Modified: trunk/libgsm/phonemgr-utils.c
==============================================================================
--- trunk/libgsm/phonemgr-utils.c (original)
+++ trunk/libgsm/phonemgr-utils.c Tue Jun 17 09:10:57 2008
@@ -27,6 +27,7 @@
#include <glib.h>
#include <glib/gstdio.h>
#include <glib-object.h>
+#include <libebook/e-contact.h>
#include <gnokii.h>
#include <bluetooth/bluetooth.h>
@@ -727,3 +728,60 @@
return gn_lib_is_connectiontype_supported (conntype);
}
+#define SET_ENTRY(field, string) { \
+ const char *s; \
+ s = e_contact_get_const (contact, field); \
+ if (s) \
+ strncpy (string, s, sizeof (string)); \
+}
+
+#define SET_SUB_ENTRY(field, type) { \
+ if (entry->subentries_count < GN_PHONEBOOK_SUBENTRIES_MAX_NUMBER) { \
+ entry->subentries[entry->subentries_count].entry_type = type; \
+ SET_ENTRY (field, entry->subentries[entry->subentries_count++].data.number); \
+ } \
+}
+
+gboolean
+vcard_to_phonebook_entry (const char *vcard, gn_phonebook_entry *entry)
+{
+ EContact *contact;
+
+ contact = e_contact_new_from_vcard (vcard);
+ SET_ENTRY(E_CONTACT_FULL_NAME, entry->name);
+ if (entry->name == NULL)
+ return FALSE;
+
+ SET_ENTRY (E_CONTACT_PHONE_PRIMARY, entry->number);
+ if (entry->number == NULL)
+ SET_ENTRY(E_CONTACT_PHONE_HOME, entry->number);
+ if (entry->number == NULL)
+ SET_ENTRY(E_CONTACT_PHONE_MOBILE, entry->number);
+ if (entry->number == NULL)
+ return FALSE;
+
+ SET_ENTRY(E_CONTACT_FAMILY_NAME, entry->person.family_name);
+ SET_ENTRY(E_CONTACT_GIVEN_NAME, entry->person.given_name);
+ SET_ENTRY(E_CONTACT_TITLE, entry->person.honorific_prefixes);
+ SET_SUB_ENTRY (E_CONTACT_HOMEPAGE_URL, GN_PHONEBOOK_ENTRY_URL);
+ if (entry->subentries_count == 0)
+ SET_SUB_ENTRY (E_CONTACT_BLOG_URL, GN_PHONEBOOK_ENTRY_URL);
+ SET_SUB_ENTRY (E_CONTACT_EMAIL_1, GN_PHONEBOOK_ENTRY_Email);
+ SET_SUB_ENTRY (E_CONTACT_EMAIL_2, GN_PHONEBOOK_ENTRY_Email);
+ SET_SUB_ENTRY (E_CONTACT_EMAIL_3, GN_PHONEBOOK_ENTRY_Email);
+ SET_SUB_ENTRY (E_CONTACT_EMAIL_4, GN_PHONEBOOK_ENTRY_Email);
+ SET_SUB_ENTRY (E_CONTACT_ADDRESS_LABEL_HOME, GN_PHONEBOOK_ENTRY_Postal);
+ SET_SUB_ENTRY (E_CONTACT_ADDRESS_LABEL_WORK, GN_PHONEBOOK_ENTRY_Postal);
+ SET_SUB_ENTRY (E_CONTACT_ADDRESS_LABEL_OTHER, GN_PHONEBOOK_ENTRY_Postal);
+ SET_SUB_ENTRY (E_CONTACT_NOTE, GN_PHONEBOOK_ENTRY_Note);
+ SET_SUB_ENTRY (E_CONTACT_PHONE_BUSINESS, GN_PHONEBOOK_NUMBER_Work);
+ SET_SUB_ENTRY (E_CONTACT_PHONE_BUSINESS_2, GN_PHONEBOOK_NUMBER_Work);
+ SET_SUB_ENTRY (E_CONTACT_PHONE_HOME, GN_PHONEBOOK_NUMBER_Home);
+ SET_SUB_ENTRY (E_CONTACT_PHONE_HOME_2, GN_PHONEBOOK_NUMBER_Home);
+ SET_SUB_ENTRY (E_CONTACT_PHONE_MOBILE, GN_PHONEBOOK_NUMBER_Mobile);
+ SET_SUB_ENTRY (E_CONTACT_PHONE_BUSINESS_FAX, GN_PHONEBOOK_NUMBER_Fax);
+ SET_SUB_ENTRY (E_CONTACT_PHONE_HOME_FAX, GN_PHONEBOOK_NUMBER_Fax);
+
+ return TRUE;
+}
+
Modified: trunk/libgsm/phonemgr-utils.h
==============================================================================
--- trunk/libgsm/phonemgr-utils.h (original)
+++ trunk/libgsm/phonemgr-utils.h Tue Jun 17 09:10:57 2008
@@ -74,6 +74,7 @@
char *phonemgr_utils_config_append_debug (const char *config);
gboolean phonemgr_utils_connection_is_supported (PhonemgrConnectionType type);
time_t gn_timestamp_to_gtime (gn_timestamp stamp);
+gboolean vcard_to_phonebook_entry (const char *vcard, gn_phonebook_entry *entry);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]