phonemgr r309 - in trunk: . libgsm
- From: hadess svn gnome org
- To: svn-commits-list gnome org
- Subject: phonemgr r309 - in trunk: . libgsm
- Date: Wed, 18 Jun 2008 12:23:32 +0000 (UTC)
Author: hadess
Date: Wed Jun 18 12:23:32 2008
New Revision: 309
URL: http://svn.gnome.org/viewvc/phonemgr?rev=309&view=rev
Log:
2008-06-18 Bastien Nocera <hadess hadess net>
* libgsm/phonemgr-listener.c (phonemgr_listener_connect),
(phonemgr_listener_get_phonebook_entry),
(phonemgr_listener_get_data), (phonemgr_listener_list_all_data):
Fix problem with phonebooks entries not being all consecutive
* libgsm/phonemgr-listener.h: Fix a warning
* configure.in: Require evolution-data-server in the backend as
well
* libgsm/glibgsmtest.c (main): Add options to make the debugging
tool more flexible, add delete/add/list/put support
Modified:
trunk/ChangeLog
trunk/configure.in
trunk/libgsm/glibgsmtest.c
trunk/libgsm/phonemgr-listener.c
trunk/libgsm/phonemgr-listener.h
Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in (original)
+++ trunk/configure.in Wed Jun 18 12:23:32 2008
@@ -38,15 +38,13 @@
AC_PATH_PROG(GCONFTOOL, gconftool-2)
AM_GCONF_SOURCE_2
-PKG_CHECK_MODULES(LIBGSM, glib-2.0 gobject-2.0 $GNOKII_REQS gthread-2.0 bluez)
-AC_SUBST(LIBGSM_CFLAGS)
-AC_SUBST(LIBGSM_LIBS)
-
dnl Evolution address book
PKG_CHECK_MODULES(TMP_EVO, libebook-1.2,
evo_pc_file="libebook-1.2",
evo_pc_file="libebook-1.0")
+PKG_CHECK_MODULES(LIBGSM, glib-2.0 gobject-2.0 $GNOKII_REQS gthread-2.0 bluez $evo_pc_file)
+
PKG_CHECK_MODULES(PHONEMGR, gtk+-2.0 >= 2.10 glib-2.0 >= 2.13.0
gstreamer-0.10 gdk-pixbuf-2.0 gconf-2.0
$GNOME_BLUETOOTH_REQS libglade-2.0 $evo_pc_file
Modified: trunk/libgsm/glibgsmtest.c
==============================================================================
--- trunk/libgsm/glibgsmtest.c (original)
+++ trunk/libgsm/glibgsmtest.c Wed Jun 18 12:23:32 2008
@@ -97,9 +97,30 @@
"test message XXX", TRUE);
}
+static gboolean debug = FALSE;
+static gboolean list_all = FALSE;
+static const char *get_uuid = NULL;
+static const char *delete_uuid = NULL;
+static const char *put_card = NULL;
+static gboolean send_test_msg = FALSE;
+static const char *bdaddr = NULL;
+
+static const GOptionEntry entries[] = {
+ { "address", 'a', 0, G_OPTION_ARG_STRING, &bdaddr, "Address of the device to connect to", NULL },
+ { "verbose", 'v', 0, G_OPTION_ARG_NONE, &debug, "Whether to enable verbose output from gnokii", NULL },
+ { "list-all-data", 'l', 0, G_OPTION_ARG_NONE, &list_all, "List all the PIM data", NULL },
+ { "get-data", 'g', 0, G_OPTION_ARG_STRING, &get_uuid, "Retrieve the PIM data with the given UUID", NULL },
+ { "delete-data", 'd', 0, G_OPTION_ARG_STRING, &delete_uuid, "Delete the PIM data with the given UUID", NULL },
+ { "put-data", 'p', 0, G_OPTION_ARG_FILENAME, &put_card, "Upload the given vCard file", NULL },
+ { "send-msg", 's', 0, G_OPTION_ARG_NONE, &send_test_msg, "Send a test message", NULL },
+ { NULL }
+};
+
int
main (int argc, char **argv)
{
+ GOptionGroup *options;
+ GOptionContext *context;
GError *err = NULL;
PhonemgrListener *listener;
@@ -108,10 +129,19 @@
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);
+ context = g_option_context_new ("Manage mobile phone");
+ g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
+
g_thread_init (NULL);
g_type_init ();
+
+ if (g_option_context_parse (context, &argc, &argv, &err) == FALSE) {
+ g_print ("couldn't parse command-line options: %s\n", err->message);
+ g_error_free (err);
+ return 1;
+ }
- listener = phonemgr_listener_new (TRUE);
+ listener = phonemgr_listener_new (debug);
g_signal_connect (G_OBJECT (listener), "message",
G_CALLBACK (message), (gpointer) listener);
@@ -126,20 +156,74 @@
g_signal_connect (G_OBJECT (listener), "network",
G_CALLBACK (network_status), (gpointer) listener);
-// if (phonemgr_listener_connect (listener, "1", &err)) {
- if (phonemgr_listener_connect (listener, "00:12:D2:79:B7:33", &err)) {
-// if (phonemgr_listener_connect (listener, "/dev/rfcomm0", &err)) {
- g_message ("Connected OK");
+ if (bdaddr == NULL) {
+ g_print ("Please pass a device address to connect to\n");
+ return 1;
+ }
- g_timeout_add_seconds (1, (GSourceFunc) send_message, listener);
+ if (phonemgr_listener_connect (listener, bdaddr, &err)) {
+ g_message ("Connected OK");
- loop = g_main_loop_new (NULL, FALSE);
- g_main_loop_run (loop);
+ if (send_test_msg != FALSE) {
+ g_timeout_add_seconds (1, (GSourceFunc) send_message, listener);
+ loop = g_main_loop_new (NULL, FALSE);
+ g_main_loop_run (loop);
+ } else if (list_all != FALSE) {
+ char **array;
+ guint i;
+
+ array = phonemgr_listener_list_all_data (listener, PHONEMGR_LISTENER_DATA_CONTACT);
+ if (array == NULL) {
+ g_message ("BLEEEEEEH");
+ return 1;
+ }
+ for (i = 0; array[i] != NULL; i++) {
+ char *vcard;
+
+ vcard = phonemgr_listener_get_data (listener, PHONEMGR_LISTENER_DATA_CONTACT, array[i]);
+ if (vcard != NULL) {
+ g_print ("UUID: %s\n", array[i]);
+ g_print ("%s\n", vcard);
+ }
+ }
+
+ g_strfreev (array);
+ } else if (get_uuid != NULL) {
+ char *vcard;
+
+ vcard = phonemgr_listener_get_data (listener, PHONEMGR_LISTENER_DATA_CONTACT, get_uuid);
+ if (vcard != NULL) {
+ g_print ("%s\n", vcard);
+ g_free (vcard);
+ } else {
+ g_message ("Failed to get data at location %s", get_uuid);
+ }
+ } else if (put_card != NULL) {
+ char *contents;
+ char *uuid;
+
+ if (g_file_get_contents (put_card, &contents, NULL, &err) == FALSE) {
+ g_message ("Getting the data from '%s' failed: %s", put_card, err->message);
+ g_error_free (err);
+ return 1;
+ }
+
+ uuid = phonemgr_listener_put_data (listener, PHONEMGR_LISTENER_DATA_CONTACT, contents);
+ if (uuid != NULL) {
+ g_print ("Added vCard at location '%s'\n", uuid);
+ g_free (uuid);
+ } else {
+ g_message ("Failed to add data from '%s' to the device", put_card);
+ }
+ } else if (delete_uuid != NULL) {
+ phonemgr_listener_delete_data (listener, PHONEMGR_LISTENER_DATA_CONTACT, delete_uuid);
+ } else {
+ g_message ("Nothing to do!");
+ }
phonemgr_listener_disconnect (listener);
} else {
- g_error ("Couldn't connect to the phone: %s\n",
- err ? err->message : "No reason");
+ g_error ("Couldn't connect to the phone: %s\n", err ? err->message : "No reason");
if (err)
g_error_free (err);
}
Modified: trunk/libgsm/phonemgr-listener.c
==============================================================================
--- trunk/libgsm/phonemgr-listener.c (original)
+++ trunk/libgsm/phonemgr-listener.c Wed Jun 18 12:23:32 2008
@@ -434,7 +434,7 @@
}
gboolean
-phonemgr_listener_connect (PhonemgrListener *l, char *device, GError **error)
+phonemgr_listener_connect (PhonemgrListener *l, const char *device, GError **error)
{
PhonemgrConnectionType type;
int channel;
@@ -1174,66 +1174,6 @@
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,
@@ -1255,6 +1195,28 @@
return TRUE;
}
+static gboolean
+phonemgr_listener_get_phonebook_entry (PhonemgrListener *l,
+ gn_memory_type type,
+ guint index,
+ gn_phonebook_entry *entry)
+{
+ gn_error error;
+
+ memset(entry, 0, sizeof(gn_phonebook_entry));
+ entry->memory_type = type;
+ entry->location = index;
+
+ l->phone_state->data.phonebook_entry = entry;
+ error = phonemgr_listener_gnokii_func (GN_OP_ReadPhonebook, l);
+ if (error == GN_ERR_EMPTYLOCATION) {
+ entry->empty = TRUE;
+ return TRUE;
+ }
+
+ return (error != GN_ERR_NONE);
+}
+
char *
phonemgr_listener_get_data (PhonemgrListener *l,
PhonemgrListenerDataType type,
@@ -1273,13 +1235,12 @@
g_mutex_lock (l->mutex);
- memset(&entry, 0, sizeof(gn_phonebook_entry));
- entry.memory_type = gn_str2memory_type(memory_type);
- entry.location = index;
+ if (phonemgr_listener_get_phonebook_entry (l, gn_str2memory_type (memory_type), index, &entry) == FALSE) {
+ g_mutex_unlock (l->mutex);
+ return NULL;
+ }
- l->phone_state->data.phonebook_entry = &entry;
- error = phonemgr_listener_gnokii_func (GN_OP_ReadPhonebook, l);
- if (error != GN_ERR_NONE || entry.empty != FALSE) {
+ if (entry.empty != FALSE) {
g_mutex_unlock (l->mutex);
return NULL;
}
@@ -1303,6 +1264,81 @@
return NULL;
}
+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, found;
+
+ g_mutex_lock (l->mutex);
+ memset (&memstat, 0, sizeof (memstat));
+ memstat.memory_type = gn_str2memory_type("ME");
+ l->phone_state->data.memory_status = &memstat;
+ error = phonemgr_listener_gnokii_func (GN_OP_GetMemoryStatus, l);
+ if (error != GN_ERR_NONE) {
+ g_message ("GN_OP_GetMemoryStatus on ME failed");
+ g_mutex_unlock (l->mutex);
+ break;
+ }
+ a = g_ptr_array_sized_new (memstat.used);
+ for (i = 1, found = 0; found <= memstat.used; i++) {
+ gn_phonebook_entry entry;
+ if (phonemgr_listener_get_phonebook_entry (l, memstat.memory_type, i, &entry) == FALSE) {
+ g_mutex_unlock (l->mutex);
+ break;
+ } else if (entry.empty == FALSE) {
+ char *uuid;
+ uuid = g_strdup_printf ("GPM-UUID-%s-%s-%d", l->imei, "ME", i);
+ g_ptr_array_add (a, uuid);
+ found++;
+ }
+ }
+
+ memset (&memstat, 0, sizeof (memstat));
+ memstat.memory_type = gn_str2memory_type("SM");
+ l->phone_state->data.memory_status = &memstat;
+ error = phonemgr_listener_gnokii_func (GN_OP_GetMemoryStatus, l);
+ if (error != GN_ERR_NONE) {
+ g_message ("GN_OP_GetMemoryStatus on SM failed");
+ g_ptr_array_add (a, NULL);
+ g_mutex_unlock (l->mutex);
+ return (char **) g_ptr_array_free (a, FALSE);
+ }
+
+ for (i = 1, found = 0; found <= memstat.used; i++) {
+ gn_phonebook_entry entry;
+ if (phonemgr_listener_get_phonebook_entry (l, memstat.memory_type, i, &entry) == FALSE) {
+ g_mutex_unlock (l->mutex);
+ break;
+ } else if (entry.empty == FALSE) {
+ char *uuid;
+ uuid = g_strdup_printf ("GPM-UUID-%s-%s-%d", l->imei, "SM", i);
+ g_ptr_array_add (a, uuid);
+ found++;
+ }
+ }
+ 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;
+}
+
gboolean
phonemgr_listener_delete_data (PhonemgrListener *l,
PhonemgrListenerDataType type,
@@ -1473,7 +1509,7 @@
}
gboolean
-phonemgr_listener_connect (PhonemgrListener *l, char *device, GError **err)
+phonemgr_listener_connect (PhonemgrListener *l, const char *device, GError **err)
{
g_message ("[DUMMY] connecting to %s", device);
phonemgr_listener_emit_status (l, PHONEMGR_LISTENER_CONNECTING);
Modified: trunk/libgsm/phonemgr-listener.h
==============================================================================
--- trunk/libgsm/phonemgr-listener.h (original)
+++ trunk/libgsm/phonemgr-listener.h Wed Jun 18 12:23:32 2008
@@ -83,7 +83,7 @@
GType phonemgr_listener_get_type (void);
PhonemgrListener* phonemgr_listener_new (gboolean debug);
gboolean phonemgr_listener_connect (PhonemgrListener *listener,
- char *device,
+ const char *device,
GError **error);
void phonemgr_listener_disconnect (PhonemgrListener *listener);
void phonemgr_listener_queue_message (PhonemgrListener *listener,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]