[gnome-software/wip/hughsie/appstream-editor] f-editor



commit 8e914c11d0c1953cdad05d507d2a0da88784b08b
Author: Richard Hughes <richard hughsie com>
Date:   Fri May 5 21:18:47 2017 +0100

    f-editor

 src/gs-editor.c |   47 ++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 44 insertions(+), 3 deletions(-)
---
diff --git a/src/gs-editor.c b/src/gs-editor.c
index c7817a4..7c288a1 100644
--- a/src/gs-editor.c
+++ b/src/gs-editor.c
@@ -41,6 +41,27 @@ typedef struct {
        gboolean                 pending_changes;
 } GsEditor;
 
+static gchar *
+gs_editor_css_download_resources (GsEditor *self, const gchar *css, GError **error)
+{
+       g_autoptr(GsPlugin) plugin = NULL;
+       g_autoptr(GString) css2 = NULL;
+       g_autoptr(SoupSession) soup_session = NULL;
+
+       /* replace keywords */
+       css2 = g_string_new (css);
+       as_utils_string_replace (css2, "@datadir@", DATADIR);
+
+       /* make remote URIs local */
+       plugin = gs_plugin_new ();
+       gs_plugin_set_name (plugin, "editor");
+       soup_session = soup_session_new_with_options (SOUP_SESSION_USER_AGENT, gs_user_agent (),
+                                                     SOUP_SESSION_TIMEOUT, 10,
+                                                     NULL);
+       gs_plugin_set_soup_session (plugin, soup_session);
+       return gs_plugin_download_rewrite_resource (plugin, css2->str, NULL, error);
+}
+
 typedef struct {
        GsEditor        *self;
        GError          **error;
@@ -67,13 +88,21 @@ static gboolean
 gs_design_validate_css (GsEditor *self, const gchar *css, GError **error)
 {
        GsDesignErrorHelper helper;
-       g_autoptr(GtkCssProvider) provider = NULL;
+       g_autofree gchar *css_new = NULL;
        g_autoptr(GString) str = NULL;
+       g_autoptr(GtkCssProvider) provider = NULL;
+
+       /* nothing set */
+       if (css == NULL)
+               return TRUE;
 
        /* remove custom class if NULL */
        str = g_string_new (NULL);
        g_string_append (str, ".themed-widget {");
-       g_string_append (str, css);
+       css_new = gs_editor_css_download_resources (self, css, error);
+       if (css_new == NULL)
+               return FALSE;
+       g_string_append (str, css_new);
        g_string_append (str, "}");
 
        /* set up custom provider */
@@ -129,6 +158,8 @@ gs_editor_convert_app (GsEditor *self, AsApp *item)
        AsApp *item_global;
        GsApp *app;
        const gchar *css = NULL;
+       g_autofree gchar *css_new = NULL;
+       g_autoptr(GError) error = NULL;
 
        app = gs_app_new (as_app_get_id (item));
        item_global = as_store_get_app_by_id (self->store_global, as_app_get_id (item));
@@ -162,7 +193,17 @@ gs_editor_convert_app (GsEditor *self, AsApp *item)
        }
        gs_editor_refine_app_pixbuf (app);
        css = as_app_get_metadata_item (item, "GnomeSoftware::FeatureTile-css");
-       gs_app_set_metadata (app, "GnomeSoftware::FeatureTile-css", css);
+       if (css != NULL) {
+               css_new = gs_editor_css_download_resources (self, css, &error);
+               if (css_new == NULL) {
+                       g_warning ("%s", error->message);
+                       gs_app_set_metadata (app, "GnomeSoftware::FeatureTile-css", css);
+               } else {
+                       gs_app_set_metadata (app, "GnomeSoftware::FeatureTile-css", css_new);
+               }
+       } else {
+               gs_app_set_metadata (app, "GnomeSoftware::FeatureTile-css", NULL);
+       }
        return app;
 }
 


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