]> git.0d.be Git - empathy.git/blobdiff - src/empathy-account-assistant.c
Update Simplified Chinese help translation.
[empathy.git] / src / empathy-account-assistant.c
index 565da707b63df36b38b1b4fff75d16a9a9c99f43..1b39000cdb4ba3a58b846eff7dd4ea92fabf0719 100644 (file)
@@ -20,7 +20,8 @@
 
 /* empathy-account-assistant.c */
 
-#include <glib/gi18n.h>
+#include <config.h>
+#include <glib/gi18n-lib.h>
 #include <telepathy-glib/util.h>
 #include <gdk/gdkkeysyms.h>
 
@@ -35,7 +36,6 @@
 #include <libempathy-gtk/empathy-account-widget.h>
 #include <libempathy-gtk/empathy-protocol-chooser.h>
 #include <libempathy-gtk/empathy-ui-utils.h>
-#include <libempathy-gtk/empathy-conf.h>
 
 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
 #include <libempathy/empathy-debug.h>
@@ -57,12 +57,12 @@ typedef enum {
   RESPONSE_CREATE_STOP = 2
 } CreateEnterPageResponse;
 
-enum {
+typedef enum {
   PAGE_INTRO = 0,
   PAGE_IMPORT = 1,
   PAGE_ENTER_CREATE = 2,
   PAGE_SALUT = 3,
-};
+} PageID;
 
 enum {
   PROP_PARENT = 1,
@@ -75,6 +75,7 @@ typedef struct {
   gboolean enter_create_forward;
   TpAccountManager *account_mgr;
   EmpathyConnectionManagers *connection_mgrs;
+  PageID current_page_id;
 
   /* enter or create page */
   GtkWidget *enter_or_create_page;
@@ -89,6 +90,7 @@ typedef struct {
 
   /* import page */
   EmpathyImportWidget *iw;
+  GtkWidget *import_page;
 
   /* salut page */
   GtkWidget *salut_page;
@@ -111,7 +113,7 @@ static void account_assistant_finish_enter_or_create_page (
 static void do_constructed (GObject *object);
 
 static GtkWidget *
-build_error_page (const gchar *primary_message,
+build_error_vbox (const gchar *primary_message,
     const gchar *secondary_message)
 {
   GtkWidget *main_vbox, *w, *hbox;
@@ -146,6 +148,7 @@ build_error_page (const gchar *primary_message,
   gtk_label_set_use_markup (GTK_LABEL (w), TRUE);
   gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0);
   gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
+  gtk_label_set_line_wrap (GTK_LABEL (w), TRUE);
   gtk_widget_show (w);
 
   return main_vbox;
@@ -156,7 +159,8 @@ account_assistant_build_error_page (EmpathyAccountAssistant *self,
     GError *error, gint page_num)
 {
   GtkWidget *main_vbox, *w;
-  const char *primary_message, *secondary_message;
+  const char *primary_message;
+  gchar *secondary_message, *markup;
   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
 
   if (page_num == PAGE_IMPORT)
@@ -170,11 +174,11 @@ account_assistant_build_error_page (EmpathyAccountAssistant *self,
   else
     primary_message = _("There was an error.");
 
-  secondary_message = g_markup_printf_escaped
-    (_("The error message was: <span style=\"italic\">%s</span>"),
-        error->message);
+  markup = g_markup_printf_escaped ("<span style=\"italic\">%s</span>",
+      error->message);
+  secondary_message = g_strdup_printf (_("The error message was: %s"), markup);
 
-  main_vbox = build_error_page (primary_message, secondary_message);
+  main_vbox = build_error_vbox (primary_message, secondary_message);
 
   w = gtk_label_new (_("You can either go back and try to enter your "
           "accounts' details again or quit this assistant and add accounts "
@@ -184,6 +188,8 @@ account_assistant_build_error_page (EmpathyAccountAssistant *self,
   gtk_label_set_line_wrap (GTK_LABEL (w), TRUE);
   gtk_widget_show (w);
 
+  g_free (markup);
+  g_free (secondary_message);
   return main_vbox;
 }
 
@@ -226,6 +232,22 @@ account_assistant_present_error_page (EmpathyAccountAssistant *self,
   gtk_assistant_set_current_page (GTK_ASSISTANT (self), num);
 }
 
+static void
+update_create_page_buttons (EmpathyAccountAssistant *self)
+{
+  EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
+  GtkAssistantPageType type;
+
+  if (priv->display_salut_page ||
+      priv->create_enter_resp == RESPONSE_CREATE_AGAIN)
+    type = GTK_ASSISTANT_PAGE_CONTENT;
+  else
+    type = GTK_ASSISTANT_PAGE_CONFIRM;
+
+  gtk_assistant_set_page_type (GTK_ASSISTANT (self), priv->enter_or_create_page,
+      type);
+}
+
 static void
 account_assistant_reset_enter_create_page (EmpathyAccountAssistant *self)
 {
@@ -235,9 +257,8 @@ account_assistant_reset_enter_create_page (EmpathyAccountAssistant *self)
 
   page = account_assistant_build_enter_or_create_page (self);
   idx = gtk_assistant_append_page (GTK_ASSISTANT (self), page);
-  gtk_assistant_set_page_type (GTK_ASSISTANT (self), page,
-      GTK_ASSISTANT_PAGE_INTRO);
   priv->enter_or_create_page = page;
+  update_create_page_buttons (self);
 
   gtk_assistant_set_current_page (GTK_ASSISTANT (self), idx);
 
@@ -256,6 +277,8 @@ account_assistant_account_enabled_cb (GObject *source,
   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
   const gchar *protocol;
   TpAccount *account = TP_ACCOUNT (source);
+  gint current_idx;
+  gboolean salut_created = FALSE;
 
   tp_account_set_enabled_finish (account, result, &error);
 
@@ -268,13 +291,17 @@ account_assistant_account_enabled_cb (GObject *source,
   protocol = tp_account_get_protocol (account);
   if (!tp_strdiff (protocol, "local-xmpp"))
     {
-      DEBUG ("Salut account has been created; update gconf key");
-
-      empathy_conf_set_bool (empathy_conf_get (),
-          EMPATHY_PREFS_SALUT_ACCOUNT_CREATED,
-          TRUE);
+      salut_created = TRUE;
     }
 
+  empathy_connect_new_account (account, priv->account_mgr);
+
+  current_idx = gtk_assistant_get_current_page (GTK_ASSISTANT (self));
+  if (current_idx == PAGE_SALUT && !salut_created)
+    /* We are on the Salut page and aren't creating the salut account so don't
+     * terminate the assistant. */
+    return;
+
   if (priv->create_enter_resp == RESPONSE_CREATE_STOP)
     g_signal_emit_by_name (self, "close");
   else
@@ -291,21 +318,8 @@ account_assistant_apply_account_cb (GObject *source,
   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
   EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (source);
   TpAccount *account;
-  gchar *display_name;
 
-  empathy_account_settings_apply_finish (settings, result, &error);
-
-  if (empathy_account_settings_get_display_name (settings) == NULL)
-    {
-      /* set default display name */
-      display_name = empathy_account_widget_get_default_display_name (
-          priv->current_widget_object);
-
-      empathy_account_settings_set_display_name_async (settings,
-          display_name, NULL, NULL);
-
-      g_free (display_name);
-    }
+  empathy_account_settings_apply_finish (settings, result, NULL, &error);
 
   priv->is_creating = FALSE;
 
@@ -325,7 +339,8 @@ account_assistant_apply_account_cb (GObject *source,
 
 static void
 account_assistant_apply_account_and_finish (EmpathyAccountAssistant *self,
-    EmpathyAccountSettings *settings)
+    EmpathyAccountSettings *settings,
+    gboolean set_display_name)
 {
   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
 
@@ -334,6 +349,19 @@ account_assistant_apply_account_and_finish (EmpathyAccountAssistant *self,
 
   priv->is_creating = TRUE;
 
+  if (set_display_name)
+    {
+      gchar *display_name;
+
+      display_name = empathy_account_widget_get_default_display_name (
+        priv->current_widget_object);
+
+      empathy_account_settings_set_display_name_async (settings,
+        display_name, NULL, NULL);
+
+      g_free (display_name);
+    }
+
   empathy_account_settings_apply_async (settings,
       account_assistant_apply_account_cb, self);
 }
@@ -353,36 +381,19 @@ static void
 account_assistant_protocol_changed_cb (GtkComboBox *chooser,
     EmpathyAccountAssistant *self)
 {
-  TpConnectionManager *cm;
-  TpConnectionManagerProtocol *proto;
   EmpathyAccountSettings *settings;
   EmpathyAccountAssistantPriv *priv;
-  char *str;
   GtkWidget *account_widget;
   EmpathyAccountWidget *widget_object = NULL;
-  gboolean is_gtalk;
 
   priv = GET_PRIV (self);
 
-  cm = empathy_protocol_chooser_dup_selected (
-      EMPATHY_PROTOCOL_CHOOSER (chooser), &proto, &is_gtalk);
+  settings = empathy_protocol_chooser_create_account_settings (
+      EMPATHY_PROTOCOL_CHOOSER (chooser));
 
-  if (cm == NULL || proto == NULL)
-    /* we are not ready yet */
+  if (settings == NULL)
     return;
 
-  /* Create account */
-  /* To translator: %s is the protocol name */
-  str = g_strdup_printf (_("New %s account"),
-      empathy_protocol_name_to_display_name (
-          is_gtalk ? "gtalk" : proto->name));
-
-  settings = empathy_account_settings_new (cm->name, proto->name, str);
-
-  if (is_gtalk)
-    empathy_account_settings_set_icon_name_async (settings, "im-google-talk",
-      NULL, NULL);
-
   if (priv->first_resp == RESPONSE_CREATE_ACCOUNT)
     empathy_account_settings_set_boolean (settings, "register", TRUE);
 
@@ -407,22 +418,25 @@ account_assistant_protocol_changed_cb (GtkComboBox *chooser,
   g_signal_connect (priv->current_widget_object, "handle-apply",
       G_CALLBACK (account_assistant_handle_apply_cb), self);
 
+  if (empathy_account_settings_is_valid (settings))
+    {
+      gtk_assistant_set_page_complete (GTK_ASSISTANT (self),
+          priv->enter_or_create_page, TRUE);
+    }
+
   gtk_box_pack_start (GTK_BOX (priv->enter_or_create_page), account_widget,
       FALSE, FALSE, 0);
   gtk_widget_show (account_widget);
-
-  g_free (str);
 }
 
 static gboolean
 account_assistant_chooser_enter_details_filter_func (
     TpConnectionManager *cm,
     TpConnectionManagerProtocol *protocol,
-    gboolean is_gtalk,
+    const gchar *service,
     gpointer user_data)
 {
-  if (!tp_strdiff (protocol->name, "local-xmpp") ||
-      !tp_strdiff (protocol->name, "irc"))
+  if (!tp_strdiff (protocol->name, "local-xmpp"))
     return FALSE;
 
   return TRUE;
@@ -432,10 +446,10 @@ static gboolean
 account_assistant_chooser_create_account_filter_func (
     TpConnectionManager *cm,
     TpConnectionManagerProtocol *protocol,
-    gboolean is_gtalk,
+    const gchar *service,
     gpointer user_data)
 {
-  if (is_gtalk)
+  if (service != NULL)
     return FALSE;
 
   return tp_connection_manager_protocol_can_register (protocol);
@@ -512,7 +526,16 @@ account_assistant_page_forward_func (gint current_page,
     }
   else if (current_page == PAGE_IMPORT)
     {
-      retval = PAGE_SALUT;
+      if (priv->display_salut_page)
+        retval = PAGE_SALUT;
+      else
+        /* Don't go forward */
+        retval = -1;
+    }
+  else if (current_page == PAGE_SALUT)
+    {
+      /* Don't go forward */
+      retval = -1;
     }
   else if (current_page >= PAGE_ENTER_CREATE)
     {
@@ -521,10 +544,15 @@ account_assistant_page_forward_func (gint current_page,
           priv->enter_create_forward = TRUE;
           retval = current_page;
         }
-      else
+      else if (priv->display_salut_page)
         {
           retval = PAGE_SALUT;
         }
+      else
+        {
+          /* Don't go forward */
+          retval = -1;
+        }
     }
 
   return retval;
@@ -627,8 +655,8 @@ account_assistant_build_introduction_page (EmpathyAccountAssistant *self)
           GINT_TO_POINTER (RESPONSE_IMPORT));
       gtk_widget_show (radio);
 
-      w = gtk_combo_box_new_text ();
-      gtk_combo_box_append_text (GTK_COMBO_BOX (w), "Pidgin");
+      w = gtk_combo_box_text_new ();
+      gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (w), "Pidgin");
       gtk_box_pack_start (GTK_BOX (hbox_1), w, TRUE, TRUE, 0);
       gtk_combo_box_set_active (GTK_COMBO_BOX (w), 0);
       gtk_widget_show (w);
@@ -700,9 +728,9 @@ account_assistant_build_import_page (EmpathyAccountAssistant *self)
   gtk_widget_show (w);
   gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 6);
 
-  w = gtk_alignment_new (0, 0, 0, 0);
+  w = gtk_alignment_new (0, 0, 1, 1);
   gtk_alignment_set_padding (GTK_ALIGNMENT (w), 0, 0, 12, 0);
-  gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0);
+  gtk_box_pack_start (GTK_BOX (main_vbox), w, TRUE, TRUE, 0);
   gtk_widget_show (w);
 
   /* NOTE: this is hardcoded as we support pidgin only */
@@ -729,6 +757,8 @@ account_assistant_radio_create_again_clicked_cb (GtkButton *button,
           "response"));
 
   priv->create_enter_resp = response;
+
+  update_create_page_buttons (self);
 }
 
 static GtkWidget *
@@ -741,9 +771,12 @@ account_assistant_build_enter_or_create_page (EmpathyAccountAssistant *self)
   gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
   gtk_widget_show (main_vbox);
 
+  hbox = gtk_hbox_new (FALSE, 6);
+  gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);
+  gtk_widget_show (hbox);
+
   w = gtk_label_new (NULL);
-  gtk_misc_set_alignment (GTK_MISC (w), 0, 0);
-  gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0);
+  gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
   gtk_widget_show (w);
   priv->first_label = w;
 
@@ -753,7 +786,7 @@ account_assistant_build_enter_or_create_page (EmpathyAccountAssistant *self)
   gtk_widget_show (w);
 
   chooser = empathy_protocol_chooser_new ();
-  gtk_container_add (GTK_CONTAINER (w), chooser);
+  gtk_box_pack_start (GTK_BOX (hbox), chooser, FALSE, FALSE, 0);
   gtk_widget_show (chooser);
   priv->chooser = chooser;
 
@@ -822,12 +855,27 @@ impl_signal_apply (GtkAssistant *assistant)
 
   current_page = gtk_assistant_get_current_page (assistant);
 
-  if (current_page == PAGE_ENTER_CREATE)
-    account_assistant_apply_account_and_finish (self, priv->settings);
+  if (current_page == PAGE_SALUT)
+    {
+      if (priv->create_salut_account)
+        /* create_salut_account_settings() already set the display name of the
+         * account so there is no need to set it again. */
+        account_assistant_apply_account_and_finish (self, priv->salut_settings,
+            FALSE);
+      return;
+    }
+  else if (current_page >= PAGE_ENTER_CREATE &&
+      priv->settings != NULL &&
+      empathy_account_settings_is_valid (priv->settings))
+    {
+      account_assistant_apply_account_and_finish (self, priv->settings, TRUE);
+      g_object_unref (priv->settings);
+      priv->settings = NULL;
+    }
   else if (current_page == PAGE_IMPORT)
-    empathy_import_widget_add_selected_accounts (priv->iw);
-  else if (current_page == PAGE_SALUT && priv->create_salut_account)
-    account_assistant_apply_account_and_finish (self, priv->salut_settings);
+    {
+      empathy_import_widget_add_selected_accounts (priv->iw);
+    }
 }
 
 static void
@@ -844,11 +892,16 @@ impl_signal_prepare (GtkAssistant *assistant,
   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
   gint current_idx;
 
+  /* check from which page we are coming from */
+  if (priv->current_page_id == PAGE_IMPORT)
+    empathy_import_widget_add_selected_accounts (priv->iw);
+
   current_idx = gtk_assistant_get_current_page (assistant);
+  priv->current_page_id = current_idx;
 
-  if (current_idx == PAGE_ENTER_CREATE)
+  if (current_idx >= PAGE_ENTER_CREATE)
     {
-      if (!priv->enter_create_forward)
+      if (!priv->enter_create_forward && current_idx != PAGE_SALUT)
         {
           account_assistant_finish_enter_or_create_page (self,
               priv->first_resp == RESPONSE_ENTER_ACCOUNT ?
@@ -857,7 +910,15 @@ impl_signal_prepare (GtkAssistant *assistant,
       else
         {
           priv->enter_create_forward = FALSE;
-          account_assistant_apply_account_and_finish (self, priv->settings);
+        }
+
+      if (priv->settings != NULL &&
+          empathy_account_settings_is_valid (priv->settings))
+        {
+          account_assistant_apply_account_and_finish (self, priv->settings,
+              TRUE);
+          g_object_unref (priv->settings);
+          priv->settings = NULL;
         }
     }
 }
@@ -1009,6 +1070,7 @@ account_assistant_build_salut_page (EmpathyAccountAssistant *self)
   EmpathyAccountSettings *settings;
   GtkWidget *account_widget;
   EmpathyAccountWidget *widget_object;
+  gchar *markup;
 
   main_vbox = gtk_vbox_new (FALSE, 12);
   gtk_widget_show (main_vbox);
@@ -1018,13 +1080,17 @@ account_assistant_build_salut_page (EmpathyAccountAssistant *self)
   gtk_box_pack_start (GTK_BOX (main_vbox), hbox_1, TRUE, TRUE, 0);
   gtk_widget_show (hbox_1);
 
-  w = gtk_label_new (
+  w = gtk_label_new (NULL);
+  markup = g_strdup_printf ("%s (<span style=\"italic\">%s</span>).",
       _("Empathy can automatically discover and chat with the people "
         "connected on the same network as you. "
         "If you want to use this feature, please check that the "
         "details below are correct. "
         "You can easily change these details later or disable this feature "
-        "by using the 'Accounts' dialog."));
+        "by using the 'Accounts' dialog"),
+      _("Edit->Accounts"));
+  gtk_label_set_markup (GTK_LABEL (w), markup);
+  g_free (markup);
   gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
   gtk_label_set_line_wrap (GTK_LABEL (w), TRUE);
   gtk_box_pack_start (GTK_BOX (hbox_1), w, FALSE, FALSE, 0);
@@ -1037,8 +1103,8 @@ account_assistant_build_salut_page (EmpathyAccountAssistant *self)
 
   g_object_unref (pix);
 
-  w = gtk_check_button_new_with_label (
-      _("I don't want to enable this feature for now"));
+  w = gtk_check_button_new_with_mnemonic (
+      _("I do _not want to enable this feature for now"));
   gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0);
   g_signal_connect (w, "toggled",
       G_CALLBACK (create_salut_check_box_toggled_cb), self);
@@ -1070,12 +1136,19 @@ account_assistant_build_salut_page (EmpathyAccountAssistant *self)
 static GtkWidget *
 account_assistant_build_salut_error_page (EmpathyAccountAssistant *self)
 {
-  return build_error_page (
-      _("telepathy-salut not installed"),
-      _("Empathy won't be able to see the people connected on the same "
-        "network as you because telepathy-salut is not installed.\n"
-        "If you want to enable this feature, you should install "
-        "telepathy-salut and activate it in the Accounts dialog"));
+  GtkWidget *vbox;
+  gchar *markup;
+
+  markup = g_strdup_printf ("%s (<span style=\"italic\">%s</span>).",
+      _("You won't be able to chat with people connected to your local "
+        "network, as telepathy-salut is not installed. If you want to enable "
+        "this feature, please install the telepathy-salut package and create "
+        "a People Nearby account from the Accounts dialog"),
+        _("Edit->Accounts"));
+
+  vbox = build_error_vbox (_("telepathy-salut not installed"), markup);
+  g_free (markup);
+  return vbox;
 }
 
 static void
@@ -1101,6 +1174,11 @@ account_mgr_prepare_cb (GObject *source_object,
       priv->display_salut_page = FALSE;
 
       update_intro_page_buttons (self);
+
+      gtk_assistant_set_page_type (GTK_ASSISTANT (self), priv->import_page,
+          GTK_ASSISTANT_PAGE_CONFIRM);
+
+      update_create_page_buttons (self);
     }
 }
 
@@ -1113,6 +1191,9 @@ empathy_account_assistant_init (EmpathyAccountAssistant *self)
       EmpathyAccountAssistantPriv);
   self->priv = priv;
 
+  gtk_window_set_title (GTK_WINDOW (self),
+      _("Messaging and VoIP Accounts Assistant"));
+
   priv->account_mgr = tp_account_manager_dup ();
 }
 
@@ -1156,12 +1237,13 @@ do_constructed (GObject *object)
   gtk_assistant_set_page_title (assistant, page,
       _("Import your existing accounts"));
   gtk_assistant_set_page_complete (assistant, page, TRUE);
-  gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_INTRO);
+  gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_CONTENT);
+  priv->import_page = page;
 
   /* third page (enter account details) */
   page = account_assistant_build_enter_or_create_page (self);
   gtk_assistant_append_page (assistant, page);
-  gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_INTRO);
+  gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_CONTENT);
   priv->enter_or_create_page = page;
 
   /* fourth page (salut details) */
@@ -1175,6 +1257,12 @@ do_constructed (GObject *object)
       gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_CONFIRM);
 
       priv->create_salut_account = TRUE;
+
+      if (empathy_account_settings_is_valid (priv->salut_settings))
+        {
+          gtk_assistant_set_page_complete (GTK_ASSISTANT (self),
+              page, TRUE);
+        }
     }
   else
     {
@@ -1203,7 +1291,7 @@ empathy_account_assistant_show (GtkWindow *window,
 
   if (dialog == NULL)
     {
-      dialog =  g_object_new (EMPATHY_TYPE_ACCOUNT_ASSISTANT,
+      dialog = g_object_new (EMPATHY_TYPE_ACCOUNT_ASSISTANT,
           "parent-window", window,
           "connection-managers", connection_mgrs,
           NULL);