[empathy] move code generating the default display name of new account to account-widget



commit 07cb259462d9958e65d2f94aef6e5728e83ccf29
Author: Guillaume Desmottes <guillaume desmottes collabora co uk>
Date:   Thu Nov 12 17:13:21 2009 +0000

    move code generating the default display name of new account to account-widget
    
    This will allow us to:
    - Use this function from other places, like in the assistant.
    - Delegate special cases to the specialized versions of the widget.

 libempathy-gtk/empathy-account-widget.c |   52 ++++++++++++++++++++++++++++++
 libempathy-gtk/empathy-account-widget.h |    3 ++
 src/empathy-accounts-dialog.c           |   53 +-----------------------------
 3 files changed, 57 insertions(+), 51 deletions(-)
---
diff --git a/libempathy-gtk/empathy-account-widget.c b/libempathy-gtk/empathy-account-widget.c
index d773787..77f93e2 100644
--- a/libempathy-gtk/empathy-account-widget.c
+++ b/libempathy-gtk/empathy-account-widget.c
@@ -1594,3 +1594,55 @@ empathy_account_widget_new_for_protocol (EmpathyAccountSettings *settings,
 
   return self;
 }
+
+gchar *
+empathy_account_widget_get_default_display_name (EmpathyAccountWidget *self)
+{
+  EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
+  const gchar *login_id;
+  const gchar *protocol, *p;
+  gchar *default_display_name;
+
+  login_id = empathy_account_settings_get_string (priv->settings, "account");
+  protocol = empathy_account_settings_get_protocol (priv->settings);
+
+  if (login_id != NULL)
+    {
+      if (!tp_strdiff (protocol, "irc"))
+        {
+          const gchar* server;
+          server = empathy_account_settings_get_string (priv->settings,
+              "server");
+
+          /* To translators: The first parameter is the login id and the
+           * second one is the server. The resulting string will be something
+           * like: "MyUserName on chat.freenode.net".
+           * You should reverse the order of these arguments if the
+           * server should come before the login id in your locale.*/
+          default_display_name = g_strdup_printf (_("%1$s on %2$s"),
+              login_id, server);
+        }
+      else
+        {
+          default_display_name = g_strdup (login_id);
+        }
+
+      return default_display_name;
+    }
+
+  if ((p = empathy_protocol_name_to_display_name (protocol)) != NULL)
+    protocol = p;
+
+  if (protocol != NULL)
+    {
+      /* To translators: The parameter is the protocol name. The resulting
+       * string will be something like: "Jabber Account" */
+      default_display_name = g_strdup_printf (_("%s Account"), protocol);
+    }
+  else
+    {
+      default_display_name = g_strdup (_("New account"));
+    }
+
+  return default_display_name;
+}
diff --git a/libempathy-gtk/empathy-account-widget.h b/libempathy-gtk/empathy-account-widget.h
index 75214fa..56ba9d0 100644
--- a/libempathy-gtk/empathy-account-widget.h
+++ b/libempathy-gtk/empathy-account-widget.h
@@ -70,6 +70,9 @@ gboolean empathy_account_widget_contains_pending_changes
 void empathy_account_widget_discard_pending_changes
     (EmpathyAccountWidget *widget);
 
+gchar * empathy_account_widget_get_default_display_name (
+    EmpathyAccountWidget *widget);
+
 G_END_DECLS
 
 #endif /* __EMPATHY_ACCOUNT_WIDGET_H__ */
diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c
index d2161a2..e4e963c 100644
--- a/src/empathy-accounts-dialog.c
+++ b/src/empathy-accounts-dialog.c
@@ -208,56 +208,6 @@ empathy_account_dialog_widget_cancelled_cb (
     g_object_unref (settings);
 }
 
-static gchar *
-get_default_display_name (EmpathyAccountSettings *settings)
-{
-  const gchar *login_id;
-  const gchar *protocol, *p;
-  gchar *default_display_name;
-
-  login_id = empathy_account_settings_get_string (settings, "account");
-  protocol = empathy_account_settings_get_protocol (settings);
-
-  if (login_id != NULL)
-    {
-      if (!tp_strdiff (protocol, "irc"))
-        {
-          const gchar* server;
-          server = empathy_account_settings_get_string (settings, "server");
-
-          /* To translators: The first parameter is the login id and the
-           * second one is the server. The resulting string will be something
-           * like: "MyUserName on chat.freenode.net".
-           * You should reverse the order of these arguments if the
-           * server should come before the login id in your locale.*/
-          default_display_name = g_strdup_printf (_("%1$s on %2$s"),
-              login_id, server);
-        }
-      else
-        {
-          default_display_name = g_strdup (login_id);
-        }
-
-      return default_display_name;
-    }
-
-  if ((p = empathy_protocol_name_to_display_name (protocol)) != NULL)
-    protocol = p;
-
-  if (protocol != NULL)
-    {
-      /* To translators: The parameter is the protocol name. The resulting
-       * string will be something like: "Jabber Account" */
-      default_display_name = g_strdup_printf (_("%s Account"), protocol);
-    }
-  else
-    {
-      default_display_name = g_strdup (_("New account"));
-    }
-
-  return default_display_name;
-}
-
 static void
 empathy_account_dialog_account_created_cb (EmpathyAccountWidget *widget_object,
     EmpathyAccountsDialog *dialog)
@@ -266,7 +216,8 @@ empathy_account_dialog_account_created_cb (EmpathyAccountWidget *widget_object,
   EmpathyAccountSettings *settings =
       accounts_dialog_model_get_selected_settings (dialog);
 
-  display_name = get_default_display_name (settings);
+  display_name = empathy_account_widget_get_default_display_name (
+      widget_object);
 
   empathy_account_settings_set_display_name_async (settings,
       display_name, NULL, NULL);



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