[gnome-software/wip/mcrha/unknown-progress-handling] gs-progress-button: Implement unknown progress handling



commit 948d9d595c7fa1e6f0e43172cefbf1ab0468ba3f
Author: Milan Crha <mcrha redhat com>
Date:   Wed Dec 9 18:26:56 2020 +0100

    gs-progress-button: Implement unknown progress handling
    
    This implements unknown progress handling for the progress button
    by a similar way as the GtkProgressBar does, which is by a "ping pong"
    of the bar from the left to the right and back, until the progress
    is known.
    
    It also avoids unnecessary memory allocations in the gs_progress_button_set_progress().

 src/gs-progress-button.c | 23 +++++++++++++----------
 src/gtk-style-hc.css     |  6 ++++++
 src/gtk-style.css        |  6 ++++++
 3 files changed, 25 insertions(+), 10 deletions(-)
---
diff --git a/src/gs-progress-button.c b/src/gs-progress-button.c
index ee6a855c..8c8ddeca 100644
--- a/src/gs-progress-button.c
+++ b/src/gs-progress-button.c
@@ -24,20 +24,23 @@ G_DEFINE_TYPE (GsProgressButton, gs_progress_button, GTK_TYPE_BUTTON)
 void
 gs_progress_button_set_progress (GsProgressButton *button, guint percentage)
 {
-       g_autofree gchar *css = NULL;
+       g_autofree gchar *tmp = NULL;
+       const gchar *css;
 
        if (percentage == GS_APP_PROGRESS_UNKNOWN) {
-               g_warning ("FIXME: Unknown progress handling is not yet implemented for GsProgressButton");
-               percentage = 0;
+               css = ".install-progress {\n"
+                     "  background-size: 25%;\n"
+                     "  animation: install-progress-unknown-move infinite linear 2s;\n"
+                     "}\n";
+       } else if (percentage == 0) {
+               css = ".install-progress { background-size: 0; }";
+       } else if (percentage == 100) {
+               css = ".install-progress { background-size: 100%; }";
+       } else {
+               tmp = g_strdup_printf (".install-progress { background-size: %u%%; }", percentage);
+               css = tmp;
        }
 
-       if (percentage == 0)
-               css = g_strdup (".install-progress { background-size: 0; }");
-       else if (percentage == 100)
-               css = g_strdup (".install-progress { background-size: 100%; }");
-       else
-               css = g_strdup_printf (".install-progress { background-size: %u%%; }", percentage);
-
        gtk_css_provider_load_from_data (button->css_provider, css, -1, NULL);
 }
 
diff --git a/src/gtk-style-hc.css b/src/gtk-style-hc.css
index 62ecc053..c5696b80 100644
--- a/src/gtk-style-hc.css
+++ b/src/gtk-style-hc.css
@@ -112,6 +112,12 @@
 .application-details-description {
 }
 
+@keyframes install-progress-unknown-move {
+       0% { background-position: 0%; }
+       50% { background-position: 100%; }
+       100% { background-position: 0%; }
+}
+
 .install-progress {
        background-image: linear-gradient(to top, @theme_selected_bg_color 2px, 
alpha(@theme_selected_bg_color, 0) 2px);
        background-repeat: no-repeat;
diff --git a/src/gtk-style.css b/src/gtk-style.css
index 73132401..666b4e2b 100644
--- a/src/gtk-style.css
+++ b/src/gtk-style.css
@@ -290,6 +290,12 @@
 .application-details-description {
 }
 
+@keyframes install-progress-unknown-move {
+       0% { background-position: 0%; }
+       50% { background-position: 100%; }
+       100% { background-position: 0%; }
+}
+
 .install-progress {
        background-image: linear-gradient(to top, @theme_selected_bg_color 2px, 
alpha(@theme_selected_bg_color, 0) 2px);
        background-repeat: no-repeat;


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