[gnome-software] Add gs_app_set_origin_hostname() and allow plugins to refine it
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Add gs_app_set_origin_hostname() and allow plugins to refine it
- Date: Fri, 8 Jul 2016 08:29:30 +0000 (UTC)
commit a9ec0028bf3a64f0b32ab0236649eda5b85f593b
Author: Richard Hughes <richard hughsie com>
Date: Thu Jul 7 08:56:47 2016 +0100
Add gs_app_set_origin_hostname() and allow plugins to refine it
src/gs-app.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++
src/gs-app.h | 3 ++
src/gs-cmd.c | 2 +
src/gs-plugin.h | 2 +
src/gs-self-test.c | 4 +++
5 files changed, 71 insertions(+), 0 deletions(-)
---
diff --git a/src/gs-app.c b/src/gs-app.c
index 73c8df9..0c51de1 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -83,6 +83,7 @@ struct _GsApp
gchar **menu_path;
gchar *origin;
gchar *origin_ui;
+ gchar *origin_hostname;
gchar *update_version;
gchar *update_version_ui;
gchar *update_details;
@@ -378,6 +379,8 @@ gs_app_to_string (GsApp *app)
gs_app_kv_lpad (str, "origin", app->origin);
if (app->origin_ui != NULL && app->origin_ui[0] != '\0')
gs_app_kv_lpad (str, "origin-ui", app->origin_ui);
+ if (app->origin_hostname != NULL && app->origin_hostname[0] != '\0')
+ gs_app_kv_lpad (str, "origin-hostname", app->origin_hostname);
if (app->rating != -1)
gs_app_kv_printf (str, "rating", "%i", app->rating);
if (app->review_ratings != NULL) {
@@ -1657,6 +1660,62 @@ gs_app_set_origin_ui (GsApp *app, const gchar *origin_ui)
}
/**
+ * gs_app_get_origin_hostname:
+ * @app: a #GsApp
+ *
+ * Gets the hostname of the origin used to install the application, e.g.
+ * "fedoraproject.org" or "sdk.gnome.org".
+ *
+ * Returns: a string, or %NULL for unset
+ **/
+const gchar *
+gs_app_get_origin_hostname (GsApp *app)
+{
+ g_return_val_if_fail (GS_IS_APP (app), NULL);
+ return app->origin_hostname;
+}
+
+/**
+ * gs_app_set_origin_hostname:
+ * @app: a #GsApp
+ * @origin_hostname: a string, or %NULL
+ *
+ * The origin is the hostname of the source used to install the application
+ * e.g. "fedoraproject.org"
+ *
+ * You can also use a full URL as @origin_hostname and this will be parsed and
+ * the hostname extracted. This process will also remove any unnecessary DNS
+ * prefixes like "download" or "mirrors".
+ **/
+void
+gs_app_set_origin_hostname (GsApp *app, const gchar *origin_hostname)
+{
+ g_autoptr(SoupURI) uri = NULL;
+ guint i;
+ const gchar *prefixes[] = { "download.", "mirrors.", NULL };
+
+ g_return_if_fail (GS_IS_APP (app));
+
+ if (origin_hostname == app->origin_hostname)
+ return;
+ g_free (app->origin_hostname);
+
+ /* use libsoup to convert a URL */
+ uri = soup_uri_new (origin_hostname);
+ if (uri != NULL)
+ origin_hostname = soup_uri_get_host (uri);
+
+ /* remove some common prefixes */
+ for (i = 0; prefixes[i] != NULL; i++) {
+ if (g_str_has_prefix (origin_hostname, prefixes[i]))
+ origin_hostname += strlen (prefixes[i]);
+ }
+
+ /* success */
+ app->origin_hostname = g_strdup (origin_hostname);
+}
+
+/**
* gs_app_add_screenshot:
* @app: a #GsApp
* @screenshot: a #AsScreenshot
@@ -2787,6 +2846,7 @@ gs_app_finalize (GObject *object)
g_strfreev (app->menu_path);
g_free (app->origin);
g_free (app->origin_ui);
+ g_free (app->origin_hostname);
g_ptr_array_unref (app->sources);
g_ptr_array_unref (app->source_ids);
g_free (app->project_group);
diff --git a/src/gs-app.h b/src/gs-app.h
index 0a696a6..e66108e 100644
--- a/src/gs-app.h
+++ b/src/gs-app.h
@@ -170,6 +170,9 @@ void gs_app_set_origin (GsApp *app,
const gchar *gs_app_get_origin_ui (GsApp *app);
void gs_app_set_origin_ui (GsApp *app,
const gchar *origin_ui);
+const gchar *gs_app_get_origin_hostname (GsApp *app);
+void gs_app_set_origin_hostname (GsApp *app,
+ const gchar *origin_hostname);
GPtrArray *gs_app_get_screenshots (GsApp *app);
void gs_app_add_screenshot (GsApp *app,
AsScreenshot *screenshot);
diff --git a/src/gs-cmd.c b/src/gs-cmd.c
index 9872b5e..74a2318 100644
--- a/src/gs-cmd.c
+++ b/src/gs-cmd.c
@@ -140,6 +140,8 @@ gs_cmd_refine_flag_from_string (const gchar *flag, GError **error)
return GS_PLUGIN_REFINE_FLAGS_REQUIRE_ICON;
if (g_strcmp0 (flag, "permissions") == 0)
return GS_PLUGIN_REFINE_FLAGS_REQUIRE_PERMISSIONS;
+ if (g_strcmp0 (flag, "origin-hostname") == 0)
+ return GS_PLUGIN_REFINE_FLAGS_REQUIRE_ORIGIN_HOSTNAME;
g_set_error (error,
GS_PLUGIN_ERROR,
GS_PLUGIN_ERROR_NOT_SUPPORTED,
diff --git a/src/gs-plugin.h b/src/gs-plugin.h
index dd1b1af..6fe1b5f 100644
--- a/src/gs-plugin.h
+++ b/src/gs-plugin.h
@@ -156,6 +156,7 @@ typedef enum {
* @GS_PLUGIN_REFINE_FLAGS_REQUIRE_KEY_COLORS: Require the key colors
* @GS_PLUGIN_REFINE_FLAGS_REQUIRE_ICON: Require the icon to be loaded
* @GS_PLUGIN_REFINE_FLAGS_REQUIRE_PERMISSIONS: Require the needed permissions
+ * @GS_PLUGIN_REFINE_FLAGS_REQUIRE_ORIGIN_HOSTNAME: Require the origin hostname
*
* The refine flags.
**/
@@ -184,6 +185,7 @@ typedef enum {
GS_PLUGIN_REFINE_FLAGS_REQUIRE_KEY_COLORS = 1 << 20,
GS_PLUGIN_REFINE_FLAGS_REQUIRE_ICON = 1 << 21,
GS_PLUGIN_REFINE_FLAGS_REQUIRE_PERMISSIONS = 1 << 22,
+ GS_PLUGIN_REFINE_FLAGS_REQUIRE_ORIGIN_HOSTNAME = 1 << 23,
/*< private >*/
GS_PLUGIN_REFINE_FLAGS_LAST
} GsPluginRefineFlags;
diff --git a/src/gs-self-test.c b/src/gs-self-test.c
index 4e59955..5d72aa6 100644
--- a/src/gs-self-test.c
+++ b/src/gs-self-test.c
@@ -204,6 +204,10 @@ gs_app_func (void)
g_assert_cmpint (gs_app_get_state (app), ==, AS_APP_STATE_REMOVING);
gs_app_set_state_recover (app); // simulate an error
g_assert_cmpint (gs_app_get_state (app), ==, AS_APP_STATE_INSTALLED);
+
+ /* correctly parse URL */
+ gs_app_set_origin_hostname (app, "https://mirrors.fedoraproject.org/metalink");
+ g_assert_cmpstr (gs_app_get_origin_hostname (app), ==, "fedoraproject.org");
}
static guint _status_changed_cnt = 0;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]