]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-account-widget.c
Merge commit 'staz/dnd'
[empathy.git] / libempathy-gtk / empathy-account-widget.c
index b12e25683babbccff920334bd372ec89180a64db..733fa383b16fba34bfa31cfbabedd8d4c28f9e39 100644 (file)
@@ -73,6 +73,11 @@ typedef struct {
    * modify it. When we are creating an account, this member is set to TRUE */
   gboolean creating_account;
 
+  /* whether there are any other real accounts. Necessary so we know whether
+   * it's safe to dismiss this widget in some cases (eg, whether the Cancel
+   * button should be sensitive) */
+  gboolean other_accounts_exist;
+
   /* if TRUE, the GTK+ destroy signal has been fired and so the widgets
    * embedded in this account widget can't be used any more
    * workaround because some async callbacks can be called after the
@@ -91,7 +96,8 @@ enum {
   PROP_PROTOCOL = 1,
   PROP_SETTINGS,
   PROP_SIMPLE,
-  PROP_CREATING_ACCOUNT
+  PROP_CREATING_ACCOUNT,
+  PROP_OTHER_ACCOUNTS_EXIST,
 };
 
 enum {
@@ -114,9 +120,14 @@ account_widget_set_control_buttons_sensitivity (EmpathyAccountWidget *self,
 
   if (!priv->simple)
     {
+      /* we hit this case because of the 'other-accounts-exist' property handler
+       * being called during init (before constructed()) */
+      if (priv->apply_button == NULL || priv->cancel_button == NULL)
+        return;
+
       gtk_widget_set_sensitive (priv->apply_button, sensitive);
-      gtk_widget_set_sensitive (
-          priv->cancel_button, sensitive || priv->creating_account);
+      gtk_widget_set_sensitive (priv->cancel_button,
+          (sensitive || priv->creating_account) && priv->other_accounts_exist);
     }
 }
 
@@ -668,9 +679,6 @@ account_widget_account_enabled_cb (GObject *source_object,
   TpAccount *account = TP_ACCOUNT (source_object);
   EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data);
   EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
-  TpConnectionPresenceType presence;
-  gchar *message = NULL;
-  gchar *status = NULL;
 
   tp_account_set_enabled_finish (account, res, &error);
 
@@ -681,28 +689,11 @@ account_widget_account_enabled_cb (GObject *source_object,
     }
   else
     {
-      /* only force presence if presence was offline, unknown or unset */
-      presence = tp_account_get_requested_presence (account, NULL, NULL);
-      switch (presence)
-        {
-        case TP_CONNECTION_PRESENCE_TYPE_OFFLINE:
-        case TP_CONNECTION_PRESENCE_TYPE_UNKNOWN:
-        case TP_CONNECTION_PRESENCE_TYPE_UNSET:
-          presence = tp_account_manager_get_most_available_presence (
-              priv->account_manager, &status, &message);
-          tp_account_request_presence_async (account, presence,
-              status, NULL, NULL, NULL);
-          break;
-        default:
-          /* do nothing if the presence is not offline */
-          break;
-        }
+      empathy_connect_new_account (account, priv->account_manager);
     }
 
   /* unref widget - part of the workaround */
   g_object_unref (widget);
-  g_free (message);
-  g_free (status);
 }
 
 static void
@@ -777,6 +768,7 @@ account_widget_apply_clicked_cb (GtkWidget *button,
     EmpathyAccountWidget *self)
 {
   EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
+  gboolean display_name_overridden;
 
   if (priv->radiobutton_reuse != NULL)
     {
@@ -787,6 +779,23 @@ account_widget_apply_clicked_cb (GtkWidget *button,
       empathy_account_settings_set_boolean (priv->settings, "register", !reuse);
     }
 
+  g_object_get (priv->settings,
+      "display-name-overridden", &display_name_overridden, NULL);
+
+  if (priv->creating_account || !display_name_overridden)
+    {
+      gchar *display_name;
+
+      /* set default display name for new accounts or update if user didn't
+       * manually override it. */
+      display_name = empathy_account_widget_get_default_display_name (self);
+
+      empathy_account_settings_set_display_name_async (priv->settings,
+          display_name, NULL, NULL);
+
+      g_free (display_name);
+    }
+
   /* workaround to keep widget alive during async call */
   g_object_ref (self);
   empathy_account_settings_apply_async (priv->settings,
@@ -1368,6 +1377,18 @@ account_widget_enabled_released_cb (GtkToggleButton *toggle_button,
       account_widget_account_enabled_cb, user_data);
 }
 
+void
+empathy_account_widget_set_other_accounts_exist (EmpathyAccountWidget *self,
+    gboolean others_exist)
+{
+  EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
+
+  priv->other_accounts_exist = others_exist;
+
+  if (priv->creating_account)
+    account_widget_handle_control_buttons_sensitivity (self);
+}
+
 static void
 do_set_property (GObject *object,
     guint prop_id,
@@ -1387,6 +1408,10 @@ do_set_property (GObject *object,
     case PROP_CREATING_ACCOUNT:
       priv->creating_account = g_value_get_boolean (value);
       break;
+    case PROP_OTHER_ACCOUNTS_EXIST:
+      empathy_account_widget_set_other_accounts_exist (
+          EMPATHY_ACCOUNT_WIDGET (object), g_value_get_boolean (value));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -1415,6 +1440,9 @@ do_get_property (GObject *object,
     case PROP_CREATING_ACCOUNT:
       g_value_set_boolean (value, priv->creating_account);
       break;
+    case PROP_OTHER_ACCOUNTS_EXIST:
+      g_value_set_boolean (value, priv->other_accounts_exist);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -1608,6 +1636,7 @@ do_constructed (GObject *obj)
   EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
   TpAccount *account;
   const gchar *protocol, *cm_name;
+  const gchar *display_name, *default_display_name;
   guint i = 0;
   struct {
     const gchar *cm_name;
@@ -1757,6 +1786,16 @@ do_constructed (GObject *obj)
   empathy_builder_unref_and_keep_widget (self->ui_details->gui,
       self->ui_details->widget);
   self->ui_details->gui = NULL;
+
+  display_name = empathy_account_settings_get_display_name (priv->settings);
+  default_display_name = empathy_account_widget_get_default_display_name (self);
+
+  if (tp_strdiff (display_name, default_display_name))
+    {
+      /* The display name of the account is not the one that we'd assign by
+       * default; assume that the user changed it manually */
+      g_object_set (priv->settings, "display-name-overridden", TRUE, NULL);
+    }
 }
 
 static void
@@ -1770,8 +1809,6 @@ do_dispose (GObject *obj)
 
   priv->dispose_run = TRUE;
 
-  empathy_account_settings_is_ready (priv->settings);
-
   if (priv->settings != NULL)
     {
       TpAccount *account;
@@ -1846,6 +1883,14 @@ empathy_account_widget_class_init (EmpathyAccountWidgetClass *klass)
       G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
   g_object_class_install_property (oclass, PROP_CREATING_ACCOUNT, param_spec);
 
+  param_spec = g_param_spec_boolean ("other-accounts-exist",
+      "other-accounts-exist",
+      "TRUE if there are any other accounts (even if this isn't yet saved)",
+      FALSE,
+      G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
+  g_object_class_install_property (oclass, PROP_OTHER_ACCOUNTS_EXIST,
+                  param_spec);
+
   signals[HANDLE_APPLY] =
     g_signal_new ("handle-apply", G_TYPE_FROM_CLASS (klass),
         G_SIGNAL_RUN_LAST, 0, NULL, NULL,
@@ -1857,7 +1902,7 @@ empathy_account_widget_class_init (EmpathyAccountWidgetClass *klass)
   signals[ACCOUNT_CREATED] =
       g_signal_new ("account-created", G_TYPE_FROM_CLASS (klass),
           G_SIGNAL_RUN_LAST, 0, NULL, NULL,
-          g_cclosure_marshal_VOID__POINTER,
+          g_cclosure_marshal_VOID__OBJECT,
           G_TYPE_NONE,
           1, G_TYPE_OBJECT);