From 76a6ff433280ed7bee6346ab05caa00ceb2aba49 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Tue, 3 Aug 2010 17:47:23 +0200 Subject: main-window: pass the TpConnectionStatusReason to main_window_error_display --- src/empathy-main-window.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/empathy-main-window.c b/src/empathy-main-window.c index f0dac6392..54496414c 100644 --- a/src/empathy-main-window.c +++ b/src/empathy-main-window.c @@ -418,7 +418,7 @@ main_window_error_close_clicked_cb (GtkButton *button, static void main_window_error_display (EmpathyMainWindow *window, TpAccount *account, - const gchar *message) + TpConnectionStatusReason reason) { EmpathyMainWindowPriv *priv = GET_PRIV (window); GtkWidget *info_bar; @@ -432,6 +432,9 @@ main_window_error_display (EmpathyMainWindow *window, GtkWidget *action_table; gchar *str; const gchar *icon_name; + const gchar *message; + + message = empathy_status_reason_get_default_message (reason); str = g_markup_printf_escaped ("%s\n%s", tp_account_get_display_name (account), @@ -571,11 +574,7 @@ main_window_connection_changed_cb (TpAccount *account, if (current == TP_CONNECTION_STATUS_DISCONNECTED && reason != TP_CONNECTION_STATUS_REASON_REQUESTED) { - const gchar *message; - - message = empathy_status_reason_get_default_message (reason); - - main_window_error_display (window, account, message); + main_window_error_display (window, account, reason); } if (current == TP_CONNECTION_STATUS_DISCONNECTED) { -- cgit v1.2.3 From 0b5e1ce2f0aafecaaf855b1f81d52821862f6526 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Thu, 5 Aug 2010 12:38:26 +0200 Subject: add empathy_dbus_error_name_get_default_message Reuse existing errors for now. --- libempathy/empathy-utils.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ libempathy/empathy-utils.h | 1 + 2 files changed, 45 insertions(+) diff --git a/libempathy/empathy-utils.c b/libempathy/empathy-utils.c index 49df14b41..367b6aa9b 100644 --- a/libempathy/empathy-utils.c +++ b/libempathy/empathy-utils.c @@ -321,6 +321,50 @@ empathy_status_reason_get_default_message (TpConnectionStatusReason reason) } } +static GHashTable * +create_errors_to_message_hash (void) +{ + GHashTable *errors; + + errors = g_hash_table_new (g_str_hash, g_str_equal); + g_hash_table_insert (errors, TP_ERROR_STR_NETWORK_ERROR, _("Network error")); + g_hash_table_insert (errors, TP_ERROR_STR_AUTHENTICATION_FAILED, + _("Authentication failed")); + g_hash_table_insert (errors, TP_ERROR_STR_ENCRYPTION_ERROR, + _("Encryption error")); + g_hash_table_insert (errors, TP_ERROR_STR_CERT_NOT_PROVIDED, + _("Certificate not provided")); + g_hash_table_insert (errors, TP_ERROR_STR_CERT_UNTRUSTED, + _("Certificate untrusted")); + g_hash_table_insert (errors, TP_ERROR_STR_CERT_EXPIRED, + _("Certificate expired")); + g_hash_table_insert (errors, TP_ERROR_STR_CERT_NOT_ACTIVATED, + _("Certificate not activated")); + g_hash_table_insert (errors, TP_ERROR_STR_CERT_HOSTNAME_MISMATCH, + _("Certificate hostname mismatch")); + g_hash_table_insert (errors, TP_ERROR_STR_CERT_FINGERPRINT_MISMATCH, + _("Certificate fingerprint mismatch")); + g_hash_table_insert (errors, TP_ERROR_STR_CERT_SELF_SIGNED, + _("Certificate self-signed")); + + return errors; +} + +const gchar * +empathy_dbus_error_name_get_default_message (const gchar *error) +{ + static GHashTable *errors_to_message = NULL; + + if (error == NULL) + return NULL; + + if (G_UNLIKELY (errors_to_message == NULL)) { + errors_to_message = create_errors_to_message_hash (); + } + + return g_hash_table_lookup (errors_to_message, error); +} + gchar * empathy_file_lookup (const gchar *filename, const gchar *subdir) { diff --git a/libempathy/empathy-utils.h b/libempathy/empathy-utils.h index da0edc58c..6ddf58a85 100644 --- a/libempathy/empathy-utils.h +++ b/libempathy/empathy-utils.h @@ -76,6 +76,7 @@ gboolean empathy_check_available_state (void); gint empathy_uint_compare (gconstpointer a, gconstpointer b); const gchar * empathy_status_reason_get_default_message (TpConnectionStatusReason reason); +const gchar * empathy_dbus_error_name_get_default_message (const gchar *error); gchar *empathy_protocol_icon_name (const gchar *protocol); const gchar *empathy_protocol_name_to_display_name (const gchar *proto_name); -- cgit v1.2.3 From 3486c2525088388b5d1fa39b4099f8b80743fd00 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Thu, 5 Aug 2010 12:50:37 +0200 Subject: create_errors_to_message_hash: add support for more errors --- libempathy/empathy-utils.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/libempathy/empathy-utils.c b/libempathy/empathy-utils.c index 367b6aa9b..f2f1d5458 100644 --- a/libempathy/empathy-utils.c +++ b/libempathy/empathy-utils.c @@ -346,6 +346,27 @@ create_errors_to_message_hash (void) _("Certificate fingerprint mismatch")); g_hash_table_insert (errors, TP_ERROR_STR_CERT_SELF_SIGNED, _("Certificate self-signed")); + g_hash_table_insert (errors, TP_ERROR_STR_CANCELLED, + _("Status is set to offline")); + g_hash_table_insert (errors, TP_ERROR_STR_ENCRYPTION_NOT_AVAILABLE, + _("Encryption is not available")); + g_hash_table_insert (errors, TP_ERROR_STR_CERT_INVALID, + _("Certificate is invalid")); + g_hash_table_insert (errors, TP_ERROR_STR_CONNECTION_REFUSED, + _("Connection has been refused")); + g_hash_table_insert (errors, TP_ERROR_STR_CONNECTION_FAILED, + _("Connection can't be established")); + g_hash_table_insert (errors, TP_ERROR_STR_CONNECTION_LOST, + _("Connection has been lost")); + g_hash_table_insert (errors, TP_ERROR_STR_ALREADY_CONNECTED, + _("This resource is already connected to the server")); + g_hash_table_insert (errors, TP_ERROR_STR_CONNECTION_REPLACED, + _("Connection has been replaced by a new connection using the " + "same resource")); + g_hash_table_insert (errors, TP_ERROR_STR_REGISTRATION_EXISTS, + _("The account already exists on the server")); + g_hash_table_insert (errors, TP_ERROR_STR_SERVICE_BUSY, + _("Server is currently too busy to handle the connection")); return errors; } -- cgit v1.2.3 From fde1ddca54a6f94fd4112f9d4e5c49d823ed00a4 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Thu, 5 Aug 2010 13:37:35 +0200 Subject: add empathy_account_get_error_message --- libempathy/empathy-utils.c | 21 ++++++++++++++++++++- libempathy/empathy-utils.h | 4 +++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/libempathy/empathy-utils.c b/libempathy/empathy-utils.c index f2f1d5458..ee6ad5bd4 100644 --- a/libempathy/empathy-utils.c +++ b/libempathy/empathy-utils.c @@ -371,7 +371,7 @@ create_errors_to_message_hash (void) return errors; } -const gchar * +static const gchar * empathy_dbus_error_name_get_default_message (const gchar *error) { static GHashTable *errors_to_message = NULL; @@ -386,6 +386,25 @@ empathy_dbus_error_name_get_default_message (const gchar *error) return g_hash_table_lookup (errors_to_message, error); } +const gchar * +empathy_account_get_error_message (TpAccount *account, + TpConnectionStatusReason reason) +{ + const gchar *dbus_error; + const gchar *message; + const GHashTable *details = NULL; + + dbus_error = tp_account_get_detailed_error (account, &details); + message = empathy_dbus_error_name_get_default_message (dbus_error); + if (message != NULL) + return message; + + DEBUG ("Don't understand error '%s'; fallback to the status reason (%u)", + dbus_error, reason); + + return empathy_status_reason_get_default_message (reason); +} + gchar * empathy_file_lookup (const gchar *filename, const gchar *subdir) { diff --git a/libempathy/empathy-utils.h b/libempathy/empathy-utils.h index 6ddf58a85..340705545 100644 --- a/libempathy/empathy-utils.h +++ b/libempathy/empathy-utils.h @@ -76,7 +76,9 @@ gboolean empathy_check_available_state (void); gint empathy_uint_compare (gconstpointer a, gconstpointer b); const gchar * empathy_status_reason_get_default_message (TpConnectionStatusReason reason); -const gchar * empathy_dbus_error_name_get_default_message (const gchar *error); + +const gchar * empathy_account_get_error_message (TpAccount *account, + TpConnectionStatusReason reason); gchar *empathy_protocol_icon_name (const gchar *protocol); const gchar *empathy_protocol_name_to_display_name (const gchar *proto_name); -- cgit v1.2.3 From 42d87a3d0d9048d6661449a5997d7dadc9a2a3c4 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Thu, 5 Aug 2010 13:37:52 +0200 Subject: main-window: use empathy_account_get_error_message (#523895) --- src/empathy-main-window.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/empathy-main-window.c b/src/empathy-main-window.c index 54496414c..afca30281 100644 --- a/src/empathy-main-window.c +++ b/src/empathy-main-window.c @@ -432,13 +432,10 @@ main_window_error_display (EmpathyMainWindow *window, GtkWidget *action_table; gchar *str; const gchar *icon_name; - const gchar *message; - - message = empathy_status_reason_get_default_message (reason); str = g_markup_printf_escaped ("%s\n%s", tp_account_get_display_name (account), - message); + empathy_account_get_error_message (account, reason)); info_bar = g_hash_table_lookup (priv->errors, account); if (info_bar) { -- cgit v1.2.3 From d3c850f72226ae5b9a6d0cdaf357d81f0fd261d1 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Thu, 5 Aug 2010 13:40:57 +0200 Subject: accounts-dialog: use empathy_account_get_error_message (#523895) --- src/empathy-accounts-dialog.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index 46d629890..a3a771cc4 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -310,7 +310,7 @@ accounts_dialog_update_status_infobar (EmpathyAccountsDialog *dialog, gchar *message; message = g_strdup_printf (_("Offline — %s"), - empathy_status_reason_get_default_message (reason)); + empathy_account_get_error_message (account, reason)); gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar), GTK_MESSAGE_WARNING); @@ -322,7 +322,7 @@ accounts_dialog_update_status_infobar (EmpathyAccountsDialog *dialog, gchar *message; message = g_strdup_printf (_("Disconnected — %s"), - empathy_status_reason_get_default_message (reason)); + empathy_account_get_error_message (account, reason)); gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar), GTK_MESSAGE_ERROR); -- cgit v1.2.3 From b5c916cfcee92d2c20d4ee25889dd56d9abb8721 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Thu, 5 Aug 2010 13:43:02 +0200 Subject: empathy_status_reason_get_default_message can be static now --- libempathy/empathy-utils.c | 2 +- libempathy/empathy-utils.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/libempathy/empathy-utils.c b/libempathy/empathy-utils.c index ee6ad5bd4..939b32897 100644 --- a/libempathy/empathy-utils.c +++ b/libempathy/empathy-utils.c @@ -284,7 +284,7 @@ empathy_presence_from_str (const gchar *str) return TP_CONNECTION_PRESENCE_TYPE_UNSET; } -const gchar * +static const gchar * empathy_status_reason_get_default_message (TpConnectionStatusReason reason) { switch (reason) { diff --git a/libempathy/empathy-utils.h b/libempathy/empathy-utils.h index 340705545..9930e6536 100644 --- a/libempathy/empathy-utils.h +++ b/libempathy/empathy-utils.h @@ -75,7 +75,6 @@ guint empathy_proxy_hash (gconstpointer key); gboolean empathy_check_available_state (void); gint empathy_uint_compare (gconstpointer a, gconstpointer b); -const gchar * empathy_status_reason_get_default_message (TpConnectionStatusReason reason); const gchar * empathy_account_get_error_message (TpAccount *account, TpConnectionStatusReason reason); -- cgit v1.2.3 From b5e7268ebc857928c6672d84b23c1c05f9a45bd5 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Thu, 5 Aug 2010 14:11:04 +0200 Subject: empathy_account_get_error_message: no need to get the details hash table --- libempathy/empathy-utils.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libempathy/empathy-utils.c b/libempathy/empathy-utils.c index 939b32897..b0abaa948 100644 --- a/libempathy/empathy-utils.c +++ b/libempathy/empathy-utils.c @@ -392,9 +392,8 @@ empathy_account_get_error_message (TpAccount *account, { const gchar *dbus_error; const gchar *message; - const GHashTable *details = NULL; - dbus_error = tp_account_get_detailed_error (account, &details); + dbus_error = tp_account_get_detailed_error (account, NULL); message = empathy_dbus_error_name_get_default_message (dbus_error); if (message != NULL) return message; -- cgit v1.2.3 From 1707cb8bb953cb4886a8e3b8ab0eeddf0d6b0567 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Thu, 5 Aug 2010 14:14:34 +0200 Subject: no need to pass the reason to empathy_account_get_error_message --- libempathy/empathy-utils.c | 6 ++++-- libempathy/empathy-utils.h | 3 +-- src/empathy-accounts-dialog.c | 4 ++-- src/empathy-main-window.c | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/libempathy/empathy-utils.c b/libempathy/empathy-utils.c index b0abaa948..b47987f85 100644 --- a/libempathy/empathy-utils.c +++ b/libempathy/empathy-utils.c @@ -387,11 +387,11 @@ empathy_dbus_error_name_get_default_message (const gchar *error) } const gchar * -empathy_account_get_error_message (TpAccount *account, - TpConnectionStatusReason reason) +empathy_account_get_error_message (TpAccount *account) { const gchar *dbus_error; const gchar *message; + TpConnectionStatusReason reason; dbus_error = tp_account_get_detailed_error (account, NULL); message = empathy_dbus_error_name_get_default_message (dbus_error); @@ -401,6 +401,8 @@ empathy_account_get_error_message (TpAccount *account, DEBUG ("Don't understand error '%s'; fallback to the status reason (%u)", dbus_error, reason); + tp_account_get_connection_status (account, &reason); + return empathy_status_reason_get_default_message (reason); } diff --git a/libempathy/empathy-utils.h b/libempathy/empathy-utils.h index 9930e6536..47b9b84ad 100644 --- a/libempathy/empathy-utils.h +++ b/libempathy/empathy-utils.h @@ -76,8 +76,7 @@ gboolean empathy_check_available_state (void); gint empathy_uint_compare (gconstpointer a, gconstpointer b); -const gchar * empathy_account_get_error_message (TpAccount *account, - TpConnectionStatusReason reason); +const gchar * empathy_account_get_error_message (TpAccount *account); gchar *empathy_protocol_icon_name (const gchar *protocol); const gchar *empathy_protocol_name_to_display_name (const gchar *proto_name); diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index a3a771cc4..e7977894c 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -310,7 +310,7 @@ accounts_dialog_update_status_infobar (EmpathyAccountsDialog *dialog, gchar *message; message = g_strdup_printf (_("Offline — %s"), - empathy_account_get_error_message (account, reason)); + empathy_account_get_error_message (account)); gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar), GTK_MESSAGE_WARNING); @@ -322,7 +322,7 @@ accounts_dialog_update_status_infobar (EmpathyAccountsDialog *dialog, gchar *message; message = g_strdup_printf (_("Disconnected — %s"), - empathy_account_get_error_message (account, reason)); + empathy_account_get_error_message (account)); gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar), GTK_MESSAGE_ERROR); diff --git a/src/empathy-main-window.c b/src/empathy-main-window.c index afca30281..c6519be7f 100644 --- a/src/empathy-main-window.c +++ b/src/empathy-main-window.c @@ -435,7 +435,7 @@ main_window_error_display (EmpathyMainWindow *window, str = g_markup_printf_escaped ("%s\n%s", tp_account_get_display_name (account), - empathy_account_get_error_message (account, reason)); + empathy_account_get_error_message (account)); info_bar = g_hash_table_lookup (priv->errors, account); if (info_bar) { -- cgit v1.2.3 From 717184f6d506b0fe6ea316accbb6aeebb3253919 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Thu, 5 Aug 2010 14:17:33 +0200 Subject: no need to pass the reason to main_window_error_display --- src/empathy-main-window.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/empathy-main-window.c b/src/empathy-main-window.c index c6519be7f..826cda487 100644 --- a/src/empathy-main-window.c +++ b/src/empathy-main-window.c @@ -417,8 +417,7 @@ main_window_error_close_clicked_cb (GtkButton *button, static void main_window_error_display (EmpathyMainWindow *window, - TpAccount *account, - TpConnectionStatusReason reason) + TpAccount *account) { EmpathyMainWindowPriv *priv = GET_PRIV (window); GtkWidget *info_bar; @@ -571,7 +570,7 @@ main_window_connection_changed_cb (TpAccount *account, if (current == TP_CONNECTION_STATUS_DISCONNECTED && reason != TP_CONNECTION_STATUS_REASON_REQUESTED) { - main_window_error_display (window, account, reason); + main_window_error_display (window, account); } if (current == TP_CONNECTION_STATUS_DISCONNECTED) { -- cgit v1.2.3