[gnome-software] trivial: Add gs_utils_get_error_value() for future use



commit 9bdbbecf48e1b8ebe7d3e72107d27a0f23f34a7e
Author: Richard Hughes <richard hughsie com>
Date:   Fri Jun 10 14:25:10 2016 +0100

    trivial: Add gs_utils_get_error_value() for future use

 src/gs-common.c |   22 ++++++++++++++++++++++
 src/gs-common.h |    1 +
 2 files changed, 23 insertions(+), 0 deletions(-)
---
diff --git a/src/gs-common.c b/src/gs-common.c
index 3c2c22d..c6b9422 100644
--- a/src/gs-common.c
+++ b/src/gs-common.c
@@ -913,4 +913,26 @@ gs_search_button_new (GtkSearchBar *search_bar)
        return widget;
 }
 
+/**
+ * gs_utils_get_error_value:
+ * @error: A GError
+ *
+ * Gets the machine-readable value stored in the error message.
+ * The machine readable string is after the first "@", e.g.
+ * message = "Requires authentication with @aaa"
+ *
+ * Returns: a string, or %NULL
+ */
+const gchar *
+gs_utils_get_error_value (const GError *error)
+{
+       gchar *str;
+       if (error == NULL)
+               return NULL;
+       str = g_strstr_len (error->message, -1, "@");
+       if (str == NULL)
+               return NULL;
+       return (const gchar *) str + 1;
+}
+
 /* vim: set noexpandtab: */
diff --git a/src/gs-common.h b/src/gs-common.h
index 770b2d8..1d6aa7d 100644
--- a/src/gs-common.h
+++ b/src/gs-common.h
@@ -63,6 +63,7 @@ void           gs_utils_widget_set_css_simple (GtkWidget      *widget,
                                                 const gchar    *css);
 gboolean        gs_utils_strv_fnmatch          (gchar          **strv,
                                                 const gchar    *str);
+const gchar    *gs_utils_get_error_value       (const GError   *error);
 void            gs_utils_show_error_dialog     (GtkWindow      *parent,
                                                 const gchar    *title,
                                                 const gchar    *msg,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]