[gnome-software] trivial: Add gs_plugin_error_to_string()
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] trivial: Add gs_plugin_error_to_string()
- Date: Wed, 7 Sep 2016 12:35:43 +0000 (UTC)
commit 712d09c8658bd6bea4e5970d0987a83a8e48f94c
Author: Richard Hughes <richard hughsie com>
Date: Wed Sep 7 11:10:06 2016 +0100
trivial: Add gs_plugin_error_to_string()
src/gs-plugin-private.h | 2 +-
src/gs-plugin.c | 36 ++++++++++++++++++++++++++++++++++++
src/gs-self-test.c | 9 +++++++++
3 files changed, 46 insertions(+), 1 deletions(-)
---
diff --git a/src/gs-plugin-private.h b/src/gs-plugin-private.h
index c9cf71a..9c90107 100644
--- a/src/gs-plugin-private.h
+++ b/src/gs-plugin-private.h
@@ -34,7 +34,7 @@ G_BEGIN_DECLS
GsPlugin *gs_plugin_new (void);
GsPlugin *gs_plugin_create (const gchar *filename,
GError **error);
-
+const gchar *gs_plugin_error_to_string (GsPluginError error);
void gs_plugin_action_start (GsPlugin *plugin,
gboolean exclusive);
void gs_plugin_action_stop (GsPlugin *plugin);
diff --git a/src/gs-plugin.c b/src/gs-plugin.c
index 5d37fd8..04e75db 100644
--- a/src/gs-plugin.c
+++ b/src/gs-plugin.c
@@ -1268,6 +1268,42 @@ gs_plugin_cache_invalidate (GsPlugin *plugin)
g_hash_table_remove_all (priv->cache);
}
+/**
+ * gs_plugin_error_to_string:
+ * @error: a #GsPluginError, e.g. %GS_PLUGIN_ERROR_NO_NETWORK
+ *
+ * Converts the enumerated error to a string.
+ *
+ * Returns: a string, or %NULL for invalid
+ **/
+const gchar *
+gs_plugin_error_to_string (GsPluginError error)
+{
+ if (error == GS_PLUGIN_ERROR_FAILED)
+ return "failed";
+ if (error == GS_PLUGIN_ERROR_NOT_SUPPORTED)
+ return "not-supported";
+ if (error == GS_PLUGIN_ERROR_CANCELLED)
+ return "cancelled";
+ if (error == GS_PLUGIN_ERROR_NO_NETWORK)
+ return "no-network";
+ if (error == GS_PLUGIN_ERROR_NO_SECURITY)
+ return "no-security";
+ if (error == GS_PLUGIN_ERROR_NO_SPACE)
+ return "no-space";
+ if (error == GS_PLUGIN_ERROR_AUTH_REQUIRED)
+ return "auth-required";
+ if (error == GS_PLUGIN_ERROR_AUTH_INVALID)
+ return "auth-invalid";
+ if (error == GS_PLUGIN_ERROR_PIN_REQUIRED)
+ return "pin-required";
+ if (error == GS_PLUGIN_ERROR_ACCOUNT_SUSPENDED)
+ return "account-suspended";
+ if (error == GS_PLUGIN_ERROR_ACCOUNT_DEACTIVATED)
+ return "account-deactivated";
+ return NULL;
+}
+
static void
gs_plugin_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
{
diff --git a/src/gs-self-test.c b/src/gs-self-test.c
index 2159948..4223739 100644
--- a/src/gs-self-test.c
+++ b/src/gs-self-test.c
@@ -89,6 +89,14 @@ gs_os_release_func (void)
}
static void
+gs_plugin_error_func (void)
+{
+ guint i;
+ for (i = 0; i < GS_PLUGIN_ERROR_LAST; i++)
+ g_assert (gs_plugin_error_to_string (i) != NULL);
+}
+
+static void
gs_plugin_global_cache_func (void)
{
const gchar *unique_id;
@@ -1341,6 +1349,7 @@ main (int argc, char **argv)
g_test_add_func ("/gnome-software/app", gs_app_func);
g_test_add_func ("/gnome-software/app{unique-id}", gs_app_unique_id_func);
g_test_add_func ("/gnome-software/plugin", gs_plugin_func);
+ g_test_add_func ("/gnome-software/plugin{error}", gs_plugin_error_func);
g_test_add_func ("/gnome-software/plugin{global-cache}", gs_plugin_global_cache_func);
g_test_add_func ("/gnome-software/auth{secret}", gs_auth_secret_func);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]