1. It no longer segfaults when sflphoned isn't available.
2. User is provided with GUI error dialog.

There are still many places that suppress DBus errors and just log them without
any GUI indication, this patch is just a beginning to show how things should be.
---
 sflphone-client-gnome/src/actions.c   |   41 ++++++++++------------
 sflphone-client-gnome/src/codeclist.c |   20 ++++++-----
 sflphone-client-gnome/src/dbus/dbus.c |   40 +++++-----------------
 sflphone-client-gnome/src/dbus/dbus.h |    5 ++-
 sflphone-client-gnome/src/main.c      |   59 ++++++++++++++++++++------------
 5 files changed, 79 insertions(+), 86 deletions(-)

diff --git a/sflphone-client-gnome/src/actions.c 
b/sflphone-client-gnome/src/actions.c
index 1291e94..5c7ba8e 100644
--- a/sflphone-client-gnome/src/actions.c
+++ b/sflphone-client-gnome/src/actions.c
@@ -313,38 +313,35 @@ void sflphone_fill_account_list (void)
     sflphone_fill_codec_list ();
 }
 
-gboolean sflphone_init()
+gboolean sflphone_init (GError **error)
 {
+    if (!dbus_connect (error))
+        return FALSE;
 
-    if (!dbus_connect ()) {
-
-        main_window_error_message (_ ("Unable to connect to the SFLphone 
server.\nMake sure the daemon is running."));
+    if (!dbus_register (getpid (), "Gtk+ Client", error))
         return FALSE;
-    } else {
-        dbus_register (getpid(), "Gtk+ Client");
 
-        // Init icons factory
-        init_icon_factory ();
+    // Init icons factory
+    init_icon_factory ();
 
-        current_calls = calltab_init (FALSE, CURRENT_CALLS);
-        contacts = calltab_init (TRUE, CONTACTS);
-        history = calltab_init (TRUE, HISTORY);
+    current_calls = calltab_init (FALSE, CURRENT_CALLS);
+    contacts = calltab_init (TRUE, CONTACTS);
+    history = calltab_init (TRUE, HISTORY);
 
-        account_list_init ();
-        codec_capabilities_load ();
-        conferencelist_init ();
+    account_list_init ();
+    codec_capabilities_load ();
+    conferencelist_init ();
 
-        // Fetch the configured accounts
-        sflphone_fill_account_list ();
+    // Fetch the configured accounts
+    sflphone_fill_account_list ();
 
-        // Fetch the ip2ip profile
-        sflphone_fill_ip2ip_profile();
+    // Fetch the ip2ip profile
+    sflphone_fill_ip2ip_profile();
 
-        // Fetch the conference list
-        // sflphone_fill_conference_list();
+    // Fetch the conference list
+    // sflphone_fill_conference_list();
 
-        return TRUE;
-    }
+    return TRUE;
 }
 
 void sflphone_fill_ip2ip_profile (void)
diff --git a/sflphone-client-gnome/src/codeclist.c 
b/sflphone-client-gnome/src/codeclist.c
index d6fcadb..61d389e 100644
--- a/sflphone-client-gnome/src/codeclist.c
+++ b/sflphone-client-gnome/src/codeclist.c
@@ -82,14 +82,16 @@ void codec_capabilities_load (void)
     // This is a global list inherited by all accounts
     codecs = (gchar**) dbus_codec_list ();
 
-    // Add the codecs in the list
-    for (pl=codecs; *codecs; codecs++) {
-
-        codec_t *c;
-        payload = atoi (*codecs);
-        specs = (gchar **) dbus_codec_details (payload);
-        codec_create_new_with_specs (payload, specs, TRUE, &c);
-        g_queue_push_tail (codecsCapabilities, (gpointer*) c);
+    if (codecs != NULL) {
+        // Add the codecs in the list
+        for (pl=codecs; *codecs; codecs++) {
+
+            codec_t *c;
+            payload = atoi (*codecs);
+            specs = (gchar **) dbus_codec_details (payload);
+            codec_create_new_with_specs (payload, specs, TRUE, &c);
+            g_queue_push_tail (codecsCapabilities, (gpointer*) c);
+        }
     }
 
     // If we didn't load any codecs, problem ...
@@ -98,7 +100,7 @@ void codec_capabilities_load (void)
         // Error message
         ERROR ("No audio codecs found");
         dbus_unregister (getpid());
-        exit (0);
+        exit (1);
     }
 }
 
diff --git a/sflphone-client-gnome/src/dbus/dbus.c 
b/sflphone-client-gnome/src/dbus/dbus.c
index 1583b92..df9f73a 100644
--- a/sflphone-client-gnome/src/dbus/dbus.c
+++ b/sflphone-client-gnome/src/dbus/dbus.c
@@ -511,23 +511,17 @@ error_alert (DBusGProxy *proxy UNUSED, int errCode, void 
* foo  UNUSED)
 }
 
 gboolean
-dbus_connect()
+dbus_connect (GError **error)
 {
-
-    GError *error = NULL;
     connection = NULL;
     instanceProxy = NULL;
 
     g_type_init();
 
-    connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+    connection = dbus_g_bus_get (DBUS_BUS_SESSION, error);
 
-    if (error) {
-        ERROR ("Failed to open connection to bus: %s",
-               error->message);
-        g_error_free (error);
+    if (connection == NULL)
         return FALSE;
-    }
 
     /* Create a proxy object for the "bus driver" (name 
"org.freedesktop.DBus") */
 
@@ -545,11 +539,7 @@ dbus_connect()
     callManagerProxy = dbus_g_proxy_new_for_name (connection,
                        "org.sflphone.SFLphone", 
"/org/sflphone/SFLphone/CallManager",
                        "org.sflphone.SFLphone.CallManager");
-
-    if (callManagerProxy == NULL) {
-        ERROR ("Failed to get proxy to CallManagers");
-        return FALSE;
-    }
+    g_assert (callManagerProxy != NULL);
 
     DEBUG ("DBus connected to CallManager");
     /* STRING STRING STRING Marshaller */
@@ -687,11 +677,7 @@ dbus_connect()
     configurationManagerProxy = dbus_g_proxy_new_for_name (connection,
                                 "org.sflphone.SFLphone", 
"/org/sflphone/SFLphone/ConfigurationManager",
                                 "org.sflphone.SFLphone.ConfigurationManager");
-
-    if (!configurationManagerProxy) {
-        ERROR ("Failed to get proxy to ConfigurationManager");
-        return FALSE;
-    }
+    g_assert (configurationManagerProxy != NULL);
 
     DEBUG ("DBus connected to ConfigurationManager");
     dbus_g_proxy_add_signal (configurationManagerProxy, "accountsChanged",
@@ -1171,18 +1157,10 @@ dbus_start_tone (const int start, const guint type)
     }
 }
 
-void
-dbus_register (int pid, gchar * name)
+gboolean
+dbus_register (int pid, gchar *name, GError **error)
 {
-    GError *error = NULL;
-
-    org_sflphone_SFLphone_Instance_register (instanceProxy, pid, name, &error);
-
-    if (error) {
-        ERROR ("Failed to call register() on instanceProxy: %s",
-               error->message);
-        g_error_free (error);
-    }
+    return org_sflphone_SFLphone_Instance_register (instanceProxy, pid, name, 
error);
 }
 
 void
@@ -1874,7 +1852,7 @@ dbus_get_addressbook_list (void)
 {
 
     GError *error = NULL;
-    gchar** array;
+    gchar** array = NULL;
 
     org_sflphone_SFLphone_ConfigurationManager_get_addressbook_list (
         configurationManagerProxy, &array, &error);
diff --git a/sflphone-client-gnome/src/dbus/dbus.h 
b/sflphone-client-gnome/src/dbus/dbus.h
index 1389918..877842a 100644
--- a/sflphone-client-gnome/src/dbus/dbus.h
+++ b/sflphone-client-gnome/src/dbus/dbus.h
@@ -50,7 +50,7 @@
  * Try to connect to DBus services
  * @return TRUE if connection succeeded, FALSE otherwise
  */
-gboolean dbus_connect ();
+gboolean dbus_connect (GError **error);
 
 /**
  * Unreferences the proxies
@@ -417,8 +417,9 @@ void dbus_start_tone (const int start , const guint type);
  * Manage the instances of clients connected to the server
  * @param pid The pid of the processus client
  * @param name The string description of the client. Here : GTK+ Client
+ * @param error return location for a GError or NULL
  */
-void dbus_register (int pid, gchar * name);
+gboolean dbus_register (int pid, gchar * name, GError **error);
 
 /**
  * Instance - Send unregistration request to dbus services
diff --git a/sflphone-client-gnome/src/main.c b/sflphone-client-gnome/src/main.c
index b3b6b2e..b349302 100644
--- a/sflphone-client-gnome/src/main.c
+++ b/sflphone-client-gnome/src/main.c
@@ -47,6 +47,7 @@
 int
 main (int argc, char *argv[])
 {
+    GError *error = NULL;
     // Handle logging
     int i;
 
@@ -89,42 +90,56 @@ main (int argc, char *argv[])
                         GNOME_PROGRAM_STANDARD_PROPERTIES,
                         NULL) ;
 
-    if (sflphone_init ()) {
+    if (!sflphone_init (&error)) {
+        gchar *markup;
 
-        if (eel_gconf_get_integer (SHOW_STATUSICON))
-            show_status_icon ();
+        ERROR (error->message);
+        markup = g_markup_printf_escaped (
+                     _ ("Unable to initialize.\nMake sure the daemon is 
running.\nError: %s"),
+                     error->message);
 
-        create_main_window ();
+        main_window_error_message (markup);
 
-        if (eel_gconf_get_integer (SHOW_STATUSICON) && eel_gconf_get_integer 
(START_HIDDEN)) {
-            gtk_widget_hide (GTK_WIDGET (get_main_window()));
-            set_minimized (TRUE);
-        }
+        g_free (markup);
+        g_error_free (error);
 
+        goto OUT;
+    }
 
-        status_bar_display_account ();
+    if (eel_gconf_get_integer (SHOW_STATUSICON))
+        show_status_icon ();
 
-        // Load the history
-        sflphone_fill_history ();
+    create_main_window ();
 
-        // Get the active calls and conferences at startup
-        sflphone_fill_call_list ();
-        sflphone_fill_conference_list ();
+    if (eel_gconf_get_integer (SHOW_STATUSICON) && eel_gconf_get_integer 
(START_HIDDEN)) {
+        gtk_widget_hide (GTK_WIDGET (get_main_window()));
+        set_minimized (TRUE);
+    }
 
-        // Update the GUI
-        update_actions ();
 
-        shortcuts_initialize_bindings();
+    status_bar_display_account ();
 
-        /* start the main loop */
-        gtk_main ();
-    }
+    // Load the history
+    sflphone_fill_history ();
 
-    gdk_threads_leave ();
+    // Get the active calls and conferences at startup
+    sflphone_fill_call_list ();
+    sflphone_fill_conference_list ();
+
+    // Update the GUI
+    update_actions ();
+
+    shortcuts_initialize_bindings();
+
+    /* start the main loop */
+    gtk_main ();
 
     shortcuts_destroy_bindings();
 
-    return 0;
+OUT:
+    gdk_threads_leave ();
+
+    return error != NULL;
 }
 
 /** @mainpage SFLphone GTK+ Client Documentation
-- 
1.6.6

_______________________________________________
SFLphone mailing list
[email protected]
http://lists.savoirfairelinux.net/mailman/listinfo/sflphone

Reply via email to