diff --git a/sflphone-client-gnome/src/actions.c b/sflphone-client-gnome/src/actions.c index 1291e941e626e0fce708a8de0a2d3878a9969455..5c7ba8e6a422f71da09e829801fbfbc811390790 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 d6fcadb3c910296f2e32b715a04c9c6598afa6ee..61d389eb663953538a263bc2530f2ce1848d8a0e 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 1583b92eb089f3db4871031f08a1c97817113482..df9f73ad67c058d95a3d76a55c5e6b7ad70c6911 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 1389918066cc51259c79f3defb5bc13e8da2a137..877842ab3347f3e0517e58667c8fe10fd45d3f3c 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 b3b6b2ebb150358b78c2e8184bfd0ec63eb3a978..b34930234b7c30f7fef2684aa565f89e673ca584 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