[gnome-software/1225-do-not-allow-distro-upgrades-if-release-art-is-missing: 18/18] gs-plugin-fedora-pkgdb-collections: Get upgrade banner background from the server




commit c23aaff4ce8b96e00e73124416ce60f56aa01d6a
Author: Milan Crha <mcrha redhat com>
Date:   Tue Jul 27 10:22:54 2021 +0200

    gs-plugin-fedora-pkgdb-collections: Get upgrade banner background from the server
    
    Add an option to define from where the upgrade banner background can
    be downloaded and use it in the CSS. Use the semi-hard-coded paths
    only as a fallback.
    
    Closes https://gitlab.gnome.org/GNOME/gnome-software/-/issues/1225

 data/org.gnome.software.gschema.xml                |  5 ++++
 .../gs-plugin-fedora-pkgdb-collections.c           | 29 ++++++++++++++++++++++
 2 files changed, 34 insertions(+)
---
diff --git a/data/org.gnome.software.gschema.xml b/data/org.gnome.software.gschema.xml
index 90aed03c6..1f1d2406e 100644
--- a/data/org.gnome.software.gschema.xml
+++ b/data/org.gnome.software.gschema.xml
@@ -144,6 +144,11 @@
       <summary>Priority order of packaging formats to prefer, with more important formats listed first. An 
empty array means the default order. Omitted formats are assumed to be listed last.</summary>
     </key>
     <child name="auth" schema="org.gnome.software.auth"/>
+    <key name="upgrade-background-uri" type="s">
+      <default>''</default>
+      <summary>The URI that references the background for an upgrade banner.</summary>
+      <description>The URI can contain up to three '%u', which will be replaced by the upgrade 
version.</description>
+    </key>
   </schema>
   <schema id="org.gnome.software.auth" gettext-domain="gnome-software">
     <key name="account-id" type="s">
diff --git a/plugins/fedora-pkgdb-collections/gs-plugin-fedora-pkgdb-collections.c 
b/plugins/fedora-pkgdb-collections/gs-plugin-fedora-pkgdb-collections.c
index 209f1d43d..857de1d76 100644
--- a/plugins/fedora-pkgdb-collections/gs-plugin-fedora-pkgdb-collections.c
+++ b/plugins/fedora-pkgdb-collections/gs-plugin-fedora-pkgdb-collections.c
@@ -221,8 +221,37 @@ gs_plugin_refresh (GsPlugin *plugin,
 static gchar *
 _get_upgrade_css_background (guint version)
 {
+       g_autoptr(GSettings) settings = NULL;
        g_autofree gchar *filename1 = NULL;
        g_autofree gchar *filename2 = NULL;
+       g_autofree gchar *uri = NULL;
+
+       settings = g_settings_new ("org.gnome.software");
+       uri = g_settings_get_string (settings, "upgrade-background-uri");
+       if (uri != NULL && *uri != '\0') {
+               const gchar *ptr;
+               guint percents_u = 0;
+               for (ptr = uri; *ptr != '\0'; ptr++) {
+                       if (*ptr == '%') {
+                               if (ptr[1] == 'u')
+                                       percents_u++;
+                               else if (ptr[1] == '%')
+                                       ptr++;
+                               else
+                                       break;
+                       }
+               }
+
+               if (*ptr != '\0' || percents_u > 3) {
+                       g_warning ("Incorrect upgrade-background-uri (%s), it can contain only up to three 
'%%u' sequences", uri);
+               } else {
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
+                       filename1 = g_strdup_printf (uri, version, version, version);
+#pragma GCC diagnostic pop
+                       return g_strdup_printf ("url('%s')", filename1);
+               }
+       }
 
        filename1 = g_strdup_printf ("/usr/share/backgrounds/f%u/default/standard/f%u.png", version, version);
        if (g_file_test (filename1, G_FILE_TEST_EXISTS))


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