[empathy] Add empathy_service_name_to_display_name()



commit fc4059e17da2a94a3864f396b5de12d93865090d
Author: Guillaume Desmottes <guillaume desmottes collabora co uk>
Date:   Fri Sep 17 15:35:07 2010 +0200

    Add empathy_service_name_to_display_name()
    
    Also makes empathy_protocol_name_to_display_name() fallbacks to the protocol
    name so caller doesn't have to.

 libempathy-gtk/empathy-protocol-chooser.c |    8 ++----
 libempathy/empathy-utils.c                |   32 ++++++++++++++++++++++++++--
 libempathy/empathy-utils.h                |    1 +
 src/empathy-account-assistant.c           |   14 +++++-------
 src/empathy-accounts-dialog.c             |   16 ++++----------
 5 files changed, 44 insertions(+), 27 deletions(-)
---
diff --git a/libempathy-gtk/empathy-protocol-chooser.c b/libempathy-gtk/empathy-protocol-chooser.c
index 2017b33..0ac2680 100644
--- a/libempathy-gtk/empathy-protocol-chooser.c
+++ b/libempathy-gtk/empathy-protocol-chooser.c
@@ -225,10 +225,8 @@ protocol_choosers_add_cm (EmpathyProtocolChooser *chooser,
           g_strdup (proto->name), g_strdup (cm->name));
 
       icon_name = empathy_protocol_icon_name (proto->name);
-      display_name = empathy_protocol_name_to_display_name (proto->name);
 
-      if (display_name == NULL)
-        display_name = proto->name;
+      display_name = empathy_protocol_name_to_display_name (proto->name);
 
       gtk_list_store_insert_with_values (priv->store,
           NULL, 0,
@@ -241,7 +239,7 @@ protocol_choosers_add_cm (EmpathyProtocolChooser *chooser,
       if (!tp_strdiff (proto->name, "jabber") &&
           !tp_strdiff (cm->name, "gabble"))
         {
-          display_name = empathy_protocol_name_to_display_name ("gtalk");
+          display_name = empathy_service_name_to_display_name ("google-talk");
           gtk_list_store_insert_with_values (priv->store,
              NULL, 0,
              COL_ICON, "im-google-talk",
@@ -251,7 +249,7 @@ protocol_choosers_add_cm (EmpathyProtocolChooser *chooser,
              COL_SERVICE, "google-talk",
              -1);
 
-          display_name = empathy_protocol_name_to_display_name ("facebook");
+          display_name = empathy_service_name_to_display_name ("facebook");
           gtk_list_store_insert_with_values (priv->store,
              NULL, 0,
              COL_ICON, "im-facebook",
diff --git a/libempathy/empathy-utils.c b/libempathy/empathy-utils.c
index 85953f8..e2e1f8a 100644
--- a/libempathy/empathy-utils.c
+++ b/libempathy/empathy-utils.c
@@ -539,7 +539,6 @@ empathy_protocol_name_to_display_name (const gchar *proto_name)
     gboolean translated;
   } names[] = {
     { "jabber", "Jabber", FALSE },
-    { "gtalk", "Google Talk", FALSE },
     { "msn", "MSN", FALSE, },
     { "local-xmpp", N_("People Nearby"), TRUE },
     { "irc", "IRC", FALSE },
@@ -547,7 +546,6 @@ empathy_protocol_name_to_display_name (const gchar *proto_name)
     { "aim", "AIM", FALSE },
     { "yahoo", "Yahoo!", FALSE },
     { "yahoojp", N_("Yahoo! Japan"), TRUE },
-    { "facebook", N_("Facebook Chat"), TRUE },
     { "groupwise", "GroupWise", FALSE },
     { "sip", "SIP", FALSE },
     { NULL, NULL }
@@ -564,7 +562,35 @@ empathy_protocol_name_to_display_name (const gchar *proto_name)
         }
     }
 
-  return NULL;
+  return proto_name;
+}
+
+const char *
+empathy_service_name_to_display_name (const gchar *service_name)
+{
+  int i;
+  static struct {
+    const gchar *service;
+    const gchar *display;
+    gboolean translated;
+  } names[] = {
+    { "google-talk", "Google Talk", FALSE },
+    { "facebook", N_("Facebook Chat"), TRUE },
+    { NULL, NULL }
+  };
+
+  for (i = 0; names[i].service != NULL; i++)
+    {
+      if (!tp_strdiff (service_name, names[i].service))
+        {
+          if (names[i].translated)
+            return _(names[i].display);
+          else
+            return names[i].display;
+        }
+    }
+
+  return service_name;
 }
 
 /* Note: this function depends on the account manager having its core feature
diff --git a/libempathy/empathy-utils.h b/libempathy/empathy-utils.h
index 6a67321..0f8adc3 100644
--- a/libempathy/empathy-utils.h
+++ b/libempathy/empathy-utils.h
@@ -83,6 +83,7 @@ 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);
+const gchar *empathy_service_name_to_display_name (const gchar *proto_name);
 
 #define EMPATHY_ARRAY_TYPE_OBJECT (empathy_type_dbus_ao ())
 GType empathy_type_dbus_ao (void);
diff --git a/src/empathy-account-assistant.c b/src/empathy-account-assistant.c
index 2a350e9..046e237 100644
--- a/src/empathy-account-assistant.c
+++ b/src/empathy-account-assistant.c
@@ -389,8 +389,8 @@ account_assistant_protocol_changed_cb (GtkComboBox *chooser,
   GtkWidget *account_widget;
   EmpathyAccountWidget *widget_object = NULL;
   gboolean is_gtalk = FALSE, is_facebook = FALSE;
-  const gchar *name;
   gchar *service;
+  const gchar *display_name;
 
   priv = GET_PRIV (self);
 
@@ -405,21 +405,19 @@ account_assistant_protocol_changed_cb (GtkComboBox *chooser,
   if (!tp_strdiff (service, "google-talk"))
     {
       is_gtalk = TRUE;
-      name = "gtalk";
     }
   else if (!tp_strdiff (service, "facebook"))
     {
       is_facebook = TRUE;
-      name ="facebook";
     }
+
+  if (service != NULL)
+    display_name = empathy_service_name_to_display_name (service);
   else
-    {
-      name = proto->name;
-    }
+    display_name = empathy_protocol_name_to_display_name (proto->name);
 
   /* To translator: %s is the protocol name */
-  str = g_strdup_printf (_("New %s account"),
-      empathy_protocol_name_to_display_name (name));
+  str = g_strdup_printf (_("New %s account"), display_name);
 
   settings = empathy_account_settings_new (cm->name, proto->name, str);
 
diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c
index a8339a5..fd68213 100644
--- a/src/empathy-accounts-dialog.c
+++ b/src/empathy-accounts-dialog.c
@@ -585,7 +585,7 @@ accounts_dialog_setup_ui_to_add_account (EmpathyAccountsDialog *dialog)
   EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
   EmpathyAccountSettings *settings;
   gchar *str;
-  const gchar *name, *display_name;
+  const gchar *display_name;
   TpConnectionManager *cm;
   TpConnectionManagerProtocol *proto;
   gboolean is_gtalk = FALSE, is_facebook = FALSE;
@@ -599,22 +599,16 @@ accounts_dialog_setup_ui_to_add_account (EmpathyAccountsDialog *dialog)
   if (!tp_strdiff (service, "google-talk"))
     {
       is_gtalk = TRUE;
-      name = "gtalk";
     }
   else if (!tp_strdiff (service, "facebook"))
     {
       is_facebook = TRUE;
-      name ="facebook";
-    }
-  else
-    {
-      name = proto->name;
     }
 
-  /* TODO: pass the service name to empathy_protocol_name_to_display_name */
-  display_name = empathy_protocol_name_to_display_name (name);
-  if (display_name == NULL)
-    display_name = proto->name;
+  if (service != NULL)
+    display_name = empathy_service_name_to_display_name (service);
+  else
+    display_name = empathy_protocol_name_to_display_name (proto->name);
 
   /* Create account */
   /* To translator: %s is the name of the protocol, such as "Google Talk" or



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]