[next] telepathy-glib: future-account: give display name on creation

Jonny Lamb jonny at kemper.freedesktop.org
Fri May 11 02:41:39 PDT 2012


Module: telepathy-glib
Branch: next
Commit: 2618d12fe15e83c7dc427c46b1b4394c742e5c5a
URL:    http://cgit.freedesktop.org/telepathy/telepathy-glib/commit/?id=2618d12fe15e83c7dc427c46b1b4394c742e5c5a

Author: Jonny Lamb <jonny.lamb at collabora.co.uk>
Date:   Wed May  9 09:24:05 2012 +0100

future-account: give display name on creation

I decided to leave set_display_name() but decided against setter
functions for protocol and CM name.

Signed-off-by: Jonny Lamb <jonny.lamb at collabora.co.uk>

---

 telepathy-glib/future-account.c |   31 ++++++++++++++++---------------
 telepathy-glib/future-account.h |    6 ++++--
 tests/dbus/future-account.c     |   16 ++++++----------
 3 files changed, 26 insertions(+), 27 deletions(-)

diff --git a/telepathy-glib/future-account.c b/telepathy-glib/future-account.c
index 448908b..98415f4 100644
--- a/telepathy-glib/future-account.c
+++ b/telepathy-glib/future-account.c
@@ -52,10 +52,9 @@
  *   TpAccountManager *am = tp_account_manager_dup ();
  *   TpFutureAccount *future;
  *
- *   future = tp_future_account_new (am, "gabble", "jabber");
- *   tp_future_account_set_display_name (future, "Work Jabber account");
+ *   future = tp_future_account_new (am, "gabble", "jabber", "Work Jabber account");
  *
- *   tp_future_account_set_parameter (future, "account", "walter.white at example.com");
+ *   tp_future_account_set_parameter (future, "account", "walter.white at lospollos.lit");
  *
  *   // ...
  *
@@ -168,6 +167,7 @@ tp_future_account_constructed (GObject *object)
   g_assert (priv->account_manager != NULL);
   g_assert (priv->cm_name != NULL);
   g_assert (priv->proto_name != NULL);
+  g_assert (priv->display_name != NULL);
 
   priv->parameters = g_hash_table_new_full (g_str_hash, g_str_equal,
       g_free, (GDestroyNotify) tp_g_value_slice_free);
@@ -320,6 +320,10 @@ tp_future_account_set_property (GObject *object,
       g_assert (priv->proto_name == NULL);
       priv->proto_name = g_value_dup_string (value);
       break;
+    case PROP_DISPLAY_NAME:
+      g_assert (priv->display_name == NULL);
+      priv->display_name = g_value_dup_string (value);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -429,7 +433,7 @@ tp_future_account_class_init (TpFutureAccountClass *klass)
           "DisplayName",
           "The account's display name",
           NULL,
-          G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
+          G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
 
   /**
    * TpFutureAccount:parameters:
@@ -678,6 +682,7 @@ tp_future_account_class_init (TpFutureAccountClass *klass)
  * @account_manager: the #TpAccountManager to create the account on
  * @manager: the name of the connection manager
  * @protocol: the name of the protocol on @manager
+ * @display_name: the user-visible name of this account
  *
  * Convenience function to create a new future account object which
  * will assist in the creation of a new account on @account_manager,
@@ -691,7 +696,8 @@ tp_future_account_class_init (TpFutureAccountClass *klass)
 TpFutureAccount *
 tp_future_account_new (TpAccountManager *account_manager,
     const gchar *manager,
-    const gchar *protocol)
+    const gchar *protocol,
+    const gchar *display_name)
 {
   g_return_val_if_fail (TP_IS_ACCOUNT_MANAGER (account_manager), NULL);
   g_return_val_if_fail (manager != NULL, NULL);
@@ -701,6 +707,7 @@ tp_future_account_new (TpAccountManager *account_manager,
       "account-manager", account_manager,
       "connection-manager", manager,
       "protocol", protocol,
+      "display-name", display_name,
       NULL);
 }
 
@@ -708,6 +715,7 @@ tp_future_account_new (TpAccountManager *account_manager,
  * tp_future_account_new_from_protocol:
  * @account_manager: the #TpAccountManager to create the account on
  * @protocol: a #TpProtocol
+ * @display_name: the user-visible name of this account
  *
  * Convenience function to create a new #TpFutureAccount object using
  * a #TpProtocol instance, instead of specifying connection manager
@@ -721,7 +729,8 @@ tp_future_account_new (TpAccountManager *account_manager,
  */
 TpFutureAccount *
 tp_future_account_new_from_protocol (TpAccountManager *account_manager,
-    TpProtocol *protocol)
+    TpProtocol *protocol,
+    const gchar *display_name)
 {
   g_return_val_if_fail (TP_IS_ACCOUNT_MANAGER (account_manager), NULL);
   g_return_val_if_fail (TP_IS_PROTOCOL (protocol), NULL);
@@ -730,6 +739,7 @@ tp_future_account_new_from_protocol (TpAccountManager *account_manager,
       "account-manager", account_manager,
       "connection-manager", tp_protocol_get_cm_name (protocol),
       "protocol", tp_protocol_get_name (protocol),
+      "display-name", display_name,
       NULL);
 }
 
@@ -1225,15 +1235,6 @@ tp_future_account_create_account_async (TpFutureAccount *self,
       return;
     }
 
-  if (priv->display_name == NULL)
-    {
-      g_simple_async_report_error_in_idle (G_OBJECT (self),
-          callback, user_data,
-          TP_ERROR, TP_ERROR_INVALID_ARGUMENT,
-          "The future account needs a display name to create the account");
-      return;
-    }
-
   if (priv->created)
     WARNING ("trying to create an account which has already been created");
 
diff --git a/telepathy-glib/future-account.h b/telepathy-glib/future-account.h
index ecbf53d..b1ee42f 100644
--- a/telepathy-glib/future-account.h
+++ b/telepathy-glib/future-account.h
@@ -65,12 +65,14 @@ _TP_AVAILABLE_IN_0_20
 TpFutureAccount * tp_future_account_new (
     TpAccountManager *account_manager,
     const gchar *manager,
-    const gchar *protocol) G_GNUC_WARN_UNUSED_RESULT;
+    const gchar *protocol,
+    const gchar *display_name) G_GNUC_WARN_UNUSED_RESULT;
 
 _TP_AVAILABLE_IN_0_20
 TpFutureAccount * tp_future_account_new_from_protocol (
     TpAccountManager *account_manager,
-    TpProtocol *protocol) G_GNUC_WARN_UNUSED_RESULT;
+    TpProtocol *protocol,
+    const gchar *display_name) G_GNUC_WARN_UNUSED_RESULT;
 
 _TP_AVAILABLE_IN_0_20
 void tp_future_account_set_display_name (TpFutureAccount *self,
diff --git a/tests/dbus/future-account.c b/tests/dbus/future-account.c
index b1b50f5..354c002 100644
--- a/tests/dbus/future-account.c
+++ b/tests/dbus/future-account.c
@@ -90,7 +90,7 @@ test_new (Test *test,
     gconstpointer data G_GNUC_UNUSED)
 {
   test->account = tp_future_account_new (test->account_manager,
-      "gabble", "jabber");
+      "gabble", "jabber", "Gustavo Fring");
   g_assert (TP_IS_FUTURE_ACCOUNT (test->account));
 }
 
@@ -102,9 +102,7 @@ test_gobject_properties (Test *test,
   gchar *manager, *protocol, *display_name;
 
   test->account = tp_future_account_new (test->account_manager,
-      "gabble", "jabber");
-
-  tp_future_account_set_display_name (test->account, "Charles Dickens");
+      "gabble", "jabber", "Charles Dickens");
 
   g_object_get (test->account,
       "account-manager", &am,
@@ -136,7 +134,7 @@ test_parameters (Test *test,
   guint u;
 
   test->account = tp_future_account_new (test->account_manager,
-      "gabble", "jabber");
+      "gabble", "jabber", "Mike Ehrmantraut");
 
   v_str = g_variant_new_string ("banana");
   tp_future_account_set_parameter (test->account, "cheese", v_str);
@@ -205,7 +203,7 @@ test_properties (Test *test,
   GVariant *v;
 
   test->account = tp_future_account_new (test->account_manager,
-      "gabble", "jabber");
+      "gabble", "jabber", "Walter Jr.");
 
   g_object_get (test->account,
       "properties", &props,
@@ -369,7 +367,7 @@ test_create_succeed (Test *test,
   GArray *avatar;
 
   test->account = tp_future_account_new (test->account_manager,
-      "gabble", "jabber");
+      "gabble", "jabber", "Hank Schrader");
 
   tp_future_account_set_display_name (test->account, "Walter White");
   tp_future_account_set_icon_name (test->account, "gasmask");
@@ -474,9 +472,7 @@ test_create_fail (Test *test,
   TpAccount *account;
 
   test->account = tp_future_account_new (test->account_manager,
-      "gabble", "jabber");
-
-  tp_future_account_set_display_name (test->account, "Walter White");
+      "gabble", "jabber", "Walter White");
 
   /* this will make CreateAccount fail */
   tp_future_account_set_parameter_string (test->account,



More information about the telepathy-commits mailing list