Index: /trunk/src/target/OM-2007.2/applications/openmoko-dialer2/ChangeLog
===================================================================
--- /trunk/src/target/OM-2007.2/applications/openmoko-dialer2/ChangeLog	(revision 3455)
+++ /trunk/src/target/OM-2007.2/applications/openmoko-dialer2/ChangeLog	(revision 3456)
@@ -1,2 +1,12 @@
+2007-11-20  Thomas Wood  <thomas@openedhand.com>
+
+	* src/phone-kit/moko-dialer.c: (moko_dialer_get_status),
+	(moko_dialer_dial), (moko_dialer_class_init), (dialer_init_gsmd):
+	* src/phone-kit/moko-dialer.h:
+
+	- Return error messages when d-bus functions fail.
+	- Try to re-connect to gsmd on each d-bus function rather than only on
+	initialisation
+
 2007-11-20  Chris Lord  <chris@openedhand.com>
 
Index: /trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-dialer.c
===================================================================
--- /trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-dialer.c	(revision 3455)
+++ /trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-dialer.c	(revision 3456)
@@ -77,8 +77,10 @@
 static guint dialer_signals[LAST_SIGNAL] = {0, };
 
+static MokoGsmdConnection * dialer_init_gsmd (MokoDialer *dialer);
+
 /* DBus functions */
 
 static gboolean
-moko_dialer_get_status (MokoDialer *dialer, gint *OUT_status, GError *error)
+moko_dialer_get_status (MokoDialer *dialer, gint *OUT_status, GError **error)
 {
   MokoDialerPrivate *priv;
@@ -93,5 +95,5 @@
 
 gboolean
-moko_dialer_dial (MokoDialer *dialer, const gchar *number, GError *error)
+moko_dialer_dial (MokoDialer *dialer, const gchar *number, GError **error)
 {
 
@@ -104,4 +106,14 @@
 
   g_debug ("Received dial request: %s", number);
+
+
+  if (!priv->connection)
+    priv->connection = dialer_init_gsmd (dialer);
+  
+  if (!priv->connection)
+  {
+    *error = g_error_new (PHONE_KIT_DIALER_ERROR, PK_DIALER_ERROR_GSMD, "Could not connect to gsmd");
+    return FALSE;
+  }
 
   /* check current dialer state */
@@ -114,12 +126,8 @@
       "Outgoing Call"
     };
-	/*
-	GtkWidget *dlg;
-    dlg = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
-        "Cannot dial when dialer is busy.\nCurrent status = %s", strings[priv->status]);
-    gtk_dialog_run (GTK_DIALOG (dlg));
-    gtk_widget_destroy (dlg);
-    */
+
     g_warning ("Cannot dial when dialer is busy. Current status = %s\n", strings[priv->status]);
+    
+    *error = g_error_new (PHONE_KIT_DIALER_ERROR, PK_DIALER_ERROR_BUSY, "Dialer busy");
 
     return FALSE;
@@ -141,12 +149,7 @@
       "Roaming network registered"
     };
-      /*
-	GtkWidget *dlg;
-    dlg = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
-        "Not connected to network.\nCurrent status = %s ", strings[priv->registered]);
-    gtk_dialog_run (GTK_DIALOG (dlg));
-    gtk_widget_destroy (dlg);
-	*/
-	g_warning ("Not connected to network.\nCurrent status = %s ", strings[priv->registered]);
+
+    g_warning ("Not connected to network.\nCurrent status = %s ", strings[priv->registered]);
+    *error = g_error_new (PHONE_KIT_DIALER_ERROR, PK_DIALER_ERROR_NOT_CONNECTED, "No Network");
 
     /* no point continuing if we're not connected to a network! */
@@ -177,8 +180,21 @@
 
 static gboolean
-moko_dialer_hang_up (MokoDialer *dialer, const gchar *message, GError *error)
-{
+moko_dialer_hang_up (MokoDialer *dialer, const gchar *message, GError **error)
+{
+  MokoDialerPrivate *priv;
+
+  priv = dialer->priv; 
   g_return_val_if_fail (MOKO_IS_DIALER (dialer), FALSE);
-  
+
+  /* check for gsmd connection */
+  if (!priv->connection)
+    priv->connection = dialer_init_gsmd (dialer);
+  
+  if (!priv->connection)
+  {
+    *error = g_error_new (PHONE_KIT_DIALER_ERROR, PK_DIALER_ERROR_GSMD, "Could not connect to gsmd");
+    return FALSE;
+  }
+
   /* FIXME: Create a dialog and let the user know that another program is
    * requesting the connection be dropped, and why ($message).
@@ -662,43 +678,28 @@
 dialer_display_error (GError *err)
 {
-  /* GtkWidget *dlg; */
-
   if (!err)
     return;
-  /*
-  dlg = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "Dialer: %s", err->message);
-  gtk_dialog_run (GTK_DIALOG (dlg));
-  gtk_widget_destroy (dlg);
-  */
   g_warning (err->message);
 }
 
-static void
-moko_dialer_init (MokoDialer *dialer)
-{
-  MokoDialerPrivate *priv;
+static MokoGsmdConnection *
+dialer_init_gsmd (MokoDialer *dialer)
+{
+  GError *err = NULL;
   MokoGsmdConnection *conn;
-  GError *err = NULL;
-
+  MokoDialerPrivate *priv;
   priv = dialer->priv = MOKO_DIALER_GET_PRIVATE (dialer);
 
-  /* create the dialer_data struct */
-  priv->status = DIALER_STATUS_NORMAL;
-  
-  /* clear incoming clip */
-  priv->incoming_clip = NULL;
-
-  /* Initialise the contacts list */
-  //contact_init_contact_data (&(priv->data->g_contactlist));
-
   /* Init the gsmd connection, and power it up */
-  conn = priv->connection = moko_gsmd_connection_new ();
+  conn = moko_gsmd_connection_new ();
   moko_gsmd_connection_set_antenna_power (conn, TRUE, &err);
 
   dialer_display_error (err);
   if (err && err->code == MOKO_GSMD_ERROR_CONNECT)
-    exit (1); /* no point continuing if we can't connect to gsmd? */
-
- 
+  {
+    g_object_unref (conn);
+    return NULL;
+  }
+
   /* Connect to the gsmd signals */
   g_signal_connect (G_OBJECT (conn), "network-registration", 
@@ -717,5 +718,26 @@
   priv->registered = MOKO_GSMD_CONNECTION_NETREG_SEARCHING;
   moko_gsmd_connection_network_register (conn);
- 
+
+  return conn;
+}
+
+static void
+moko_dialer_init (MokoDialer *dialer)
+{
+  MokoDialerPrivate *priv;
+
+  priv = dialer->priv = MOKO_DIALER_GET_PRIVATE (dialer);
+
+  /* create the dialer_data struct */
+  priv->status = DIALER_STATUS_NORMAL;
+  
+  /* clear incoming clip */
+  priv->incoming_clip = NULL;
+
+  /* Initialise the contacts list */
+  //contact_init_contact_data (&(priv->data->g_contactlist));
+
+  priv->connection = dialer_init_gsmd (dialer);
+
   /* Set up the journal */
   priv->journal = moko_journal_open_default ();
Index: /trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-dialer.h
===================================================================
--- /trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-dialer.h	(revision 3455)
+++ /trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-dialer.h	(revision 3456)
@@ -44,4 +44,12 @@
         MOKO_TYPE_DIALER, MokoDialerClass))
 
+#define PHONE_KIT_DIALER_ERROR g_quark_from_static_string("phone-kit-dialer")
+
+typedef enum {
+  PK_DIALER_ERROR_BUSY,
+  PK_DIALER_ERROR_GSMD,
+  PK_DIALER_ERROR_NOT_CONNECTED
+} PhoneKitDialerError;
+
 typedef struct _MokoDialer MokoDialer;
 typedef struct _MokoDialerClass MokoDialerClass;
@@ -54,5 +62,4 @@
   DIALER_STATUS_DIALING,
   DIALER_STATUS_TALKING
-
 };
 
@@ -98,11 +105,11 @@
 
 gboolean
-moko_dialer_show_dialer (MokoDialer *dialer, GError *error);
+moko_dialer_show_dialer (MokoDialer *dialer, GError **error);
 
 gboolean
-moko_dialer_show_missed_calls (MokoDialer *dialer, GError *error);
+moko_dialer_show_missed_calls (MokoDialer *dialer, GError **error);
 
 gboolean
-moko_dialer_dial (MokoDialer *dialer, const gchar *number, GError *error);
+moko_dialer_dial (MokoDialer *dialer, const gchar *number, GError **error);
 
 void
