From 56675c410b694ef3a9c19288a12e80976dfdc2be Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 8 Mar 2012 13:32:40 +0000 Subject: [PATCH 7/7] tp_account_dup_detailed_error_vardict: add Bug: https://bugs.freedesktop.org/show_bug.cgi?id=30422 --- docs/reference/telepathy-glib-sections.txt | 1 + telepathy-glib/account.c | 39 ++++++++++++++++++++++++++++ telepathy-glib/account.h | 2 + tests/dbus/account.c | 18 +++++++++++++ 4 files changed, 60 insertions(+), 0 deletions(-) diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt index cc7afea..5223caf 100644 --- a/docs/reference/telepathy-glib-sections.txt +++ b/docs/reference/telepathy-glib-sections.txt @@ -5085,6 +5085,7 @@ tp_account_set_connect_automatically_finish tp_account_get_has_been_online tp_account_get_connection_status tp_account_get_detailed_error +tp_account_dup_detailed_error_vardict tp_account_get_changing_presence tp_account_get_current_presence tp_account_get_requested_presence diff --git a/telepathy-glib/account.c b/telepathy-glib/account.c index 6a3b7b8..d9c1836 100644 --- a/telepathy-glib/account.c +++ b/telepathy-glib/account.c @@ -3780,6 +3780,45 @@ tp_account_get_detailed_error (TpAccount *self, } /** + * tp_account_dup_detailed_error_vardict: + * @self: an account + * @details: (out) (allow-none) (transfer full): + * optionally used to return a variant of type %G_VARIANT_TYPE_VARDICT, + * which must be unreffed by the caller with g_variant_unref() + * + * If the account's connection is not connected, return the D-Bus error name + * with which it last disconnected or failed to connect (in particular, this + * is %TP_ERROR_STR_CANCELLED if it was disconnected by a user request). + * This is the same as #TpAccount:connection-error. + * + * If @details is not %NULL, it will be used to return additional details about + * the error (the same as #TpAccount:connection-error-details). + * + * Otherwise, return %NULL, without altering @details. + * + * The returned string and @details may become invalid when the main loop is + * re-entered or the account is destroyed. + * + * Returns: (transfer full) (allow-none): a D-Bus error name, or %NULL. + * + * Since: 0.UNRELEASED + */ +gchar * +tp_account_dup_detailed_error_vardict (TpAccount *self, + GVariant **details) +{ + g_return_val_if_fail (TP_IS_ACCOUNT (self), NULL); + + if (self->priv->connection_status == TP_CONNECTION_STATUS_CONNECTED) + return NULL; + + if (details != NULL) + *details = _tp_asv_to_vardict (self->priv->error_details); + + return g_strdup (self->priv->error); +} + +/** * tp_account_get_storage_provider: * @self: a #TpAccount * diff --git a/telepathy-glib/account.h b/telepathy-glib/account.h index 79878cd..6658e06 100644 --- a/telepathy-glib/account.h +++ b/telepathy-glib/account.h @@ -190,6 +190,8 @@ TpConnectionStatus tp_account_get_connection_status (TpAccount *account, const gchar *tp_account_get_detailed_error (TpAccount *self, const GHashTable **details); +gchar *tp_account_dup_detailed_error_vardict (TpAccount *self, + GVariant **details); TpConnectionPresenceType tp_account_get_current_presence (TpAccount *account, gchar **status, gchar **status_message); diff --git a/tests/dbus/account.c b/tests/dbus/account.c index 11e4dd4..8d1aba4 100644 --- a/tests/dbus/account.c +++ b/tests/dbus/account.c @@ -695,6 +695,10 @@ test_connection (Test *test, GHashTable *change = tp_asv_new (NULL, NULL); TpConnection *conn; const GHashTable *details; + GVariant *details_v; + gboolean found; + gchar *s; + guint32 u; test->account = tp_account_new (test->dbus, ACCOUNT_PATH, NULL); g_assert (test->account != NULL); @@ -837,6 +841,20 @@ test_connection (Test *test, g_assert_cmpuint (tp_asv_get_uint32 (details, "bits-of-entropy", NULL), ==, 15); + s = tp_account_dup_detailed_error_vardict (test->account, &details_v); + g_assert_cmpstr (s, ==, "org.debian.packages.OpenSSL.NotRandomEnough"); + g_free (s); + g_assert_cmpuint (g_variant_n_children (details_v), >=, 2); + g_assert_cmpstr (g_variant_get_type_string (details_v), ==, "a{sv}"); + found = g_variant_lookup (details_v, "debug-message", "s", &s); + g_assert (found); + g_assert_cmpstr (s, ==, "shiiiiii-"); + g_free (s); + found = g_variant_lookup (details_v, "bits-of-entropy", "u", &u); + g_assert (found); + g_assert_cmpint (u, ==, 15); + g_variant_unref (details_v); + /* staple on a Connection (this is intended for use in e.g. observers, * if they're told about a Connection that the Account hasn't told them * about yet) */ -- 1.7.9.1