]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-account-widget.c
Updated Basque language
[empathy.git] / libempathy-gtk / empathy-account-widget.c
index 0927d109c73714c610728348c75ccef762f5820f..641ef00badbaa0dddf9da4a133786ab8d6faedd1 100644 (file)
@@ -49,7 +49,6 @@
 G_DEFINE_TYPE (EmpathyAccountWidget, empathy_account_widget, G_TYPE_OBJECT)
 
 typedef struct {
-  char *protocol;
   EmpathyAccountSettings *settings;
 
   GtkWidget *table_common_settings;
@@ -62,17 +61,13 @@ typedef struct {
 
   gboolean simple;
 
+  gboolean contains_pending_changes;
+  gboolean original_enabled_checkbox_value;
+
   /* An EmpathyAccountWidget can be used to either create an account or
    * modify it. When we are creating an account, this member is set to TRUE */
   gboolean creating_account;
 
-  /* After having applied changes to a user account, we automatically
-   * disconnect him. Once he's disconnected, he will be reconnected,
-   * depending on the value of this member which should be set to the checked
-   * state of the "Enabled" checkbox. This is done so the new information
-   * entered by the user is validated on the server. */
-  gboolean re_enable_accound;
-
   gboolean dispose_run;
 } EmpathyAccountWidgetPriv;
 
@@ -104,7 +99,10 @@ account_widget_set_control_buttons_sensitivity (EmpathyAccountWidget *self,
   if (!priv->simple)
     {
       gtk_widget_set_sensitive (priv->apply_button, sensitive);
-      gtk_widget_set_sensitive (priv->cancel_button, sensitive);
+      gtk_widget_set_sensitive (
+          priv->cancel_button, sensitive || priv->creating_account);
+
+      priv->contains_pending_changes = sensitive;
     }
 }
 
@@ -117,10 +115,7 @@ account_widget_handle_control_buttons_sensitivity (EmpathyAccountWidget *self)
   is_valid = empathy_account_settings_is_valid (priv->settings);
 
   if (!priv->simple)
-    {
-      gtk_widget_set_sensitive (priv->apply_button, is_valid);
-      gtk_widget_set_sensitive (priv->cancel_button, is_valid);
-    }
+      account_widget_set_control_buttons_sensitivity (self, is_valid);
 
   g_signal_emit (self, signals[HANDLE_APPLY], 0, is_valid);
 }
@@ -158,16 +153,6 @@ account_widget_entry_changed_common (EmpathyAccountWidget *self,
     }
 }
 
-static gboolean
-account_widget_entry_focus_cb (GtkWidget *widget,
-    GdkEventFocus *event,
-    EmpathyAccountWidget *self)
-{
-  account_widget_entry_changed_common (self, GTK_ENTRY (widget), TRUE);
-
-  return FALSE;
-}
-
 static void
 account_widget_entry_changed_cb (GtkEditable *entry,
     EmpathyAccountWidget *self)
@@ -363,9 +348,6 @@ account_widget_setup_widget (EmpathyAccountWidget *self,
           gtk_entry_set_visibility (GTK_ENTRY (widget), FALSE);
         }
 
-      g_signal_connect (widget, "focus-out-event",
-          G_CALLBACK (account_widget_entry_focus_cb),
-          self);
       g_signal_connect (widget, "changed",
           G_CALLBACK (account_widget_entry_changed_cb), self);
     }
@@ -623,32 +605,35 @@ account_widget_applied_cb (GObject *source_object,
 
   account = empathy_account_settings_get_account (priv->settings);
 
-  if (priv->creating_account)
-    {
-      /* By default, when an account is created, we enable it. */
-      empathy_account_set_enabled_async (account, TRUE,
-          account_widget_account_enabled_cb, widget);
-    }
-  else if (account != NULL && priv->enabled_checkbox != NULL)
+  if (account != NULL)
     {
-      gboolean enabled_checked;
-
-      enabled_checked = gtk_toggle_button_get_active (
-          GTK_TOGGLE_BUTTON (priv->enabled_checkbox));
-
-      if (empathy_account_is_enabled (account))
+      if (priv->creating_account)
         {
-          /* We want to disable the account (and possibly re-enable it) to make
-           * sure that the new settings are effective */
-          priv->re_enable_accound = enabled_checked;
-          empathy_account_set_enabled_async (account, FALSE, NULL, NULL);
+          /* By default, when an account is created, we enable it. */
+          empathy_account_set_enabled_async (account, TRUE,
+              account_widget_account_enabled_cb, widget);
         }
-      else
+      else if (priv->enabled_checkbox != NULL)
         {
-          /* The account is already disable so we just enable it according
-           * to the value of the "Enabled" checkbox */
-          empathy_account_set_enabled_async (account, enabled_checked,
-              NULL, NULL);
+          gboolean enabled_checked;
+
+          enabled_checked = gtk_toggle_button_get_active (
+              GTK_TOGGLE_BUTTON (priv->enabled_checkbox));
+
+          if (empathy_account_is_enabled (account) && enabled_checked)
+            {
+              /* After having applied changes to a user account, we
+               * automatically reconnect it. This is done so the new
+               * information entered by the user is validated on the server. */
+              empathy_account_reconnect_async (account, NULL, NULL);
+            }
+          else
+            {
+              /* The account is disabled so we enable it according to the value
+               * of the "Enabled" checkbox */
+              empathy_account_set_enabled_async (account, enabled_checked,
+                  NULL, NULL);
+            }
         }
     }
 
@@ -742,6 +727,24 @@ account_widget_build_salut (EmpathyAccountWidget *self,
   self->ui_details->default_focus = g_strdup ("entry_nickname");
 }
 
+static void
+account_widget_build_irc (EmpathyAccountWidget *self,
+  const char *filename)
+{
+  EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
+  empathy_account_widget_irc_build (self, filename,
+    &priv->table_common_settings);
+}
+
+static void
+account_widget_build_sip (EmpathyAccountWidget *self,
+  const char *filename)
+{
+  EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
+  empathy_account_widget_sip_build (self, filename,
+    &priv->table_common_settings);
+}
+
 static void
 account_widget_build_msn (EmpathyAccountWidget *self,
     const char *filename)
@@ -789,8 +792,14 @@ account_widget_build_jabber (EmpathyAccountWidget *self,
   GtkWidget *checkbutton_ssl;
   GtkWidget *label_id, *label_password;
   GtkWidget *label_id_create, *label_password_create;
+  GtkWidget *label_example_gtalk, *label_example_jabber;
+  gboolean is_gtalk;
 
-  if (priv->simple)
+  is_gtalk = !tp_strdiff (
+      empathy_account_settings_get_icon_name (priv->settings),
+      "im-google-talk");
+
+  if (priv->simple && !is_gtalk)
     {
       self->ui_details->gui = empathy_builder_get_file (filename,
           "vbox_jabber_simple", &self->ui_details->widget,
@@ -815,6 +824,19 @@ account_widget_build_jabber (EmpathyAccountWidget *self,
 
       self->ui_details->default_focus = g_strdup ("entry_id_simple");
     }
+  else if (priv->simple && is_gtalk)
+    {
+      self->ui_details->gui = empathy_builder_get_file (filename,
+          "vbox_gtalk_simple", &self->ui_details->widget,
+          NULL);
+
+      empathy_account_widget_handle_params (self,
+          "entry_id_g_simple", "account",
+          "entry_password_g_simple", "password",
+          NULL);
+
+      self->ui_details->default_focus = g_strdup ("entry_id_g_simple");
+    }
   else
     {
       self->ui_details->gui = empathy_builder_get_file (filename,
@@ -822,6 +844,8 @@ account_widget_build_jabber (EmpathyAccountWidget *self,
           "vbox_jabber_settings", &self->ui_details->widget,
           "spinbutton_port", &spinbutton_port,
           "checkbutton_ssl", &checkbutton_ssl,
+          "label_username_example", &label_example_jabber,
+          "label_username_g_example", &label_example_gtalk,
           NULL);
 
       empathy_account_widget_handle_params (self,
@@ -843,6 +867,12 @@ account_widget_build_jabber (EmpathyAccountWidget *self,
       g_signal_connect (checkbutton_ssl, "toggled",
           G_CALLBACK (account_widget_jabber_ssl_toggled_cb),
           self);
+
+      if (is_gtalk)
+        {
+          gtk_widget_hide (label_example_jabber);
+          gtk_widget_show (label_example_gtalk);
+        }
     }
 }
 
@@ -1023,14 +1053,7 @@ empathy_account_widget_enabled_cb (EmpathyAccount *account,
   EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
   gboolean enabled = empathy_account_is_enabled (account);
 
-  if (!enabled && priv->re_enable_accound)
-    {
-      /* The account has been disabled because we were applying changes.
-       * However, the user wants the account to be enabled so let's re-enable
-       * it */
-      empathy_account_set_enabled_async (account, TRUE, NULL, NULL);
-    }
-  else if (priv->enabled_checkbox != NULL)
+  if (priv->enabled_checkbox != NULL)
     {
       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->enabled_checkbox),
           enabled);
@@ -1038,7 +1061,7 @@ empathy_account_widget_enabled_cb (EmpathyAccount *account,
 }
 
 static void
-account_widget_enabled_toggled_cb (GtkToggleButton *toggle_button,
+account_widget_enabled_released_cb (GtkToggleButton *toggle_button,
     gpointer user_data)
 {
   account_widget_handle_control_buttons_sensitivity (
@@ -1055,9 +1078,6 @@ do_set_property (GObject *object,
 
   switch (prop_id)
     {
-    case PROP_PROTOCOL:
-      priv->protocol = g_value_dup_string (value);
-      break;
     case PROP_SETTINGS:
       priv->settings = g_value_dup_object (value);
       break;
@@ -1083,7 +1103,8 @@ do_get_property (GObject *object,
   switch (prop_id)
     {
     case PROP_PROTOCOL:
-      g_value_set_string (value, priv->protocol);
+      g_value_set_string (value,
+        empathy_account_settings_get_protocol (priv->settings));
       break;
     case PROP_SETTINGS:
       g_value_set_object (value, priv->settings);
@@ -1099,52 +1120,63 @@ do_get_property (GObject *object,
     }
 }
 
+#define WIDGET(cm, proto) \
+  { #cm, #proto, "empathy-account-widget-"#proto".ui", \
+    account_widget_build_##proto }
+
 static void
 do_constructed (GObject *obj)
 {
   EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
   EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
   EmpathyAccount *account;
-  char *uiname, *filename;
-
-  uiname = g_strconcat ("empathy-account-widget-", priv->protocol,
-      ".ui", NULL);
-  filename = empathy_file_lookup (uiname, "libempathy-gtk");
-
-  if (!tp_strdiff (priv->protocol, "local-xmpp"))
-    account_widget_build_salut (self, filename);
-  else if (!tp_strdiff (priv->protocol, "msn"))
-    account_widget_build_msn (self, filename);
-  else if (!tp_strdiff (priv->protocol, "jabber"))
-    account_widget_build_jabber (self, filename);
-  else if (!tp_strdiff (priv->protocol, "icq"))
-    account_widget_build_icq (self, filename);
-  else if (!tp_strdiff (priv->protocol, "aim"))
-    account_widget_build_aim (self, filename);
-  else if (!tp_strdiff (priv->protocol, "yahoo"))
-    account_widget_build_yahoo (self, filename);
-  else if (!tp_strdiff (priv->protocol, "groupwise"))
-    account_widget_build_groupwise (self, filename);
-  else if (!tp_strdiff (priv->protocol, "irc"))
-    empathy_account_widget_irc_build (self, filename,
-        &priv->table_common_settings);
-  else if (!tp_strdiff (priv->protocol, "sip"))
-    empathy_account_widget_sip_build (self, filename,
-        &priv->table_common_settings);
-  else if (!tp_strdiff (priv->protocol, "generic"))
-    account_widget_build_generic (self, filename);
-  else
+  const gchar *protocol, *cm_name;
+  int i = 0;
+  struct {
+    const gchar *cm_name;
+    const gchar *protocol;
+    const char *file;
+    void (*func)(EmpathyAccountWidget *self, const gchar *filename);
+  } widgets [] = {
+    { "salut", "local-xmpp", "empathy-account-widget-local-xmpp.ui",
+        account_widget_build_salut },
+    WIDGET (gabble, jabber),
+    WIDGET (butterfly, msn),
+    WIDGET (haze, icq),
+    WIDGET (haze, aim),
+    WIDGET (haze, yahoo),
+    WIDGET (haze, groupwise),
+    WIDGET (idle, irc),
+    WIDGET (sofiasip, sip),
+  };
+
+  cm_name = empathy_account_settings_get_cm (priv->settings);
+  protocol = empathy_account_settings_get_protocol (priv->settings);
+
+  for (i = 0 ; i < G_N_ELEMENTS (widgets); i++)
     {
-      g_free (filename);
+      if (!tp_strdiff (widgets[i].cm_name, cm_name) &&
+          !tp_strdiff (widgets[i].protocol, protocol))
+        {
+          gchar *filename;
+
+          filename = empathy_file_lookup (widgets[i].file,
+              "libempathy-gtk");
+          widgets[i].func (self, filename);
+          g_free (filename);
+
+          break;
+        }
+    }
 
-      filename = empathy_file_lookup (
+  if (i == G_N_ELEMENTS (widgets))
+    {
+      gchar *filename = empathy_file_lookup (
           "empathy-account-widget-generic.ui", "libempathy-gtk");
       account_widget_build_generic (self, filename);
+      g_free (filename);
     }
 
-  g_free (uiname);
-  g_free (filename);
-
   /* handle default focus */
   if (self->ui_details->default_focus != NULL)
     {
@@ -1204,7 +1236,15 @@ do_constructed (GObject *obj)
           G_CALLBACK (account_widget_apply_clicked_cb),
           self);
       gtk_widget_show_all (hbox);
-      account_widget_set_control_buttons_sensitivity (self, FALSE);
+
+      if (priv->creating_account)
+        /* When creating an account, the user might have nothing to enter.
+         * That means that no control interaction might occur,
+         * so we update the control button sensitivity manually.
+         */
+        account_widget_handle_control_buttons_sensitivity (self);
+      else
+        account_widget_set_control_buttons_sensitivity (self, FALSE);
     }
 
   account = empathy_account_settings_get_account (priv->settings);
@@ -1222,9 +1262,11 @@ do_constructed (GObject *obj)
 
       priv->enabled_checkbox =
           gtk_check_button_new_with_label (_("Enabled"));
+      priv->original_enabled_checkbox_value =
+          empathy_account_is_enabled (account);
       gtk_toggle_button_set_active (
           GTK_TOGGLE_BUTTON (priv->enabled_checkbox),
-          empathy_account_is_enabled (account));
+          priv->original_enabled_checkbox_value);
 
       g_object_get (priv->table_common_settings, "n-rows", &nb_rows,
           "n-columns", &nb_columns, NULL);
@@ -1238,8 +1280,8 @@ do_constructed (GObject *obj)
 
       gtk_widget_show (priv->enabled_checkbox);
 
-      g_signal_connect (G_OBJECT (priv->enabled_checkbox), "toggled",
-          G_CALLBACK (account_widget_enabled_toggled_cb), self);
+      g_signal_connect (G_OBJECT (priv->enabled_checkbox), "released",
+          G_CALLBACK (account_widget_enabled_released_cb), self);
     }
 
   /* hook up to widget destruction to unref ourselves */
@@ -1287,13 +1329,10 @@ static void
 do_finalize (GObject *obj)
 {
   EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
-  EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
 
   g_free (self->ui_details->default_focus);
   g_slice_free (EmpathyAccountWidgetUIDetails, self->ui_details);
 
-  g_free (priv->protocol);
-
   if (G_OBJECT_CLASS (empathy_account_widget_parent_class)->finalize != NULL)
     G_OBJECT_CLASS (empathy_account_widget_parent_class)->finalize (obj);
 }
@@ -1313,7 +1352,7 @@ empathy_account_widget_class_init (EmpathyAccountWidgetClass *klass)
   param_spec = g_param_spec_string ("protocol",
       "protocol", "The protocol of the account",
       NULL,
-      G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
+      G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
   g_object_class_install_property (oclass, PROP_PROTOCOL, param_spec);
 
   param_spec = g_param_spec_object ("settings",
@@ -1375,6 +1414,26 @@ empathy_account_widget_init (EmpathyAccountWidget *self)
 
 /* public methods */
 
+void
+empathy_account_widget_discard_pending_changes
+    (EmpathyAccountWidget *widget)
+{
+  EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
+
+  empathy_account_settings_discard_changes (priv->settings);
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->enabled_checkbox),
+      priv->original_enabled_checkbox_value);
+  priv->contains_pending_changes = FALSE;
+}
+
+gboolean
+empathy_account_widget_contains_pending_changes (EmpathyAccountWidget *widget)
+{
+  EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
+
+  return priv->contains_pending_changes;
+}
+
 void
 empathy_account_widget_handle_params (EmpathyAccountWidget *self,
     const gchar *first_widget,
@@ -1394,17 +1453,15 @@ empathy_account_widget_get_widget (EmpathyAccountWidget *widget)
 }
 
 EmpathyAccountWidget *
-empathy_account_widget_new_for_protocol (const char *protocol,
-    EmpathyAccountSettings *settings,
+empathy_account_widget_new_for_protocol (EmpathyAccountSettings *settings,
     gboolean simple)
 {
   EmpathyAccountWidget *self;
 
   g_return_val_if_fail (EMPATHY_IS_ACCOUNT_SETTINGS (settings), NULL);
-  g_return_val_if_fail (protocol != NULL, NULL);
 
   self = g_object_new
-    (EMPATHY_TYPE_ACCOUNT_WIDGET, "protocol", protocol,
+    (EMPATHY_TYPE_ACCOUNT_WIDGET,
         "settings", settings, "simple", simple,
         "creating-account",
         empathy_account_settings_get_account (settings) == NULL,