[gnome-builder] egg: add EggProgressButton



commit 696cb23fa309d7818157a77d939eff5f2621d589
Author: Christian Hergert <chergert redhat com>
Date:   Fri Mar 10 18:56:14 2017 -0800

    egg: add EggProgressButton
    
    This is an import and update of GsProgressButton from GNOME Software. We
    can use it as a base for our transfer button so that progresss is shown.

 contrib/egg/Makefile.am           |    2 +
 contrib/egg/egg-progress-button.c |  197 +++++++++++++++++++++++++++++++++++++
 contrib/egg/egg-progress-button.h |   52 ++++++++++
 data/theme/shared.css             |   15 +++
 4 files changed, 266 insertions(+), 0 deletions(-)
---
diff --git a/contrib/egg/Makefile.am b/contrib/egg/Makefile.am
index cb8dcc4..7772555 100644
--- a/contrib/egg/Makefile.am
+++ b/contrib/egg/Makefile.am
@@ -25,6 +25,7 @@ headers_DATA =                        \
        egg-pill-box.h                \
        egg-priority-box.h            \
        egg-private.h                 \
+       egg-progress-button.h         \
        egg-radio-box.h               \
        egg-scrolled-window.h         \
        egg-search-bar.h              \
@@ -59,6 +60,7 @@ libegg_private_la_SOURCES =           \
        egg-menu-manager.c            \
        egg-pill-box.c                \
        egg-priority-box.c            \
+       egg-progress-button.c         \
        egg-radio-box.c               \
        egg-scrolled-window.c         \
        egg-search-bar.c              \
diff --git a/contrib/egg/egg-progress-button.c b/contrib/egg/egg-progress-button.c
new file mode 100644
index 0000000..2146f78
--- /dev/null
+++ b/contrib/egg/egg-progress-button.c
@@ -0,0 +1,197 @@
+/*
+ * Copyright (C) 2013-2014 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#define G_LOG_DOMAIN "egg-progress-button"
+
+#include "egg-progress-button.h"
+
+typedef struct
+{
+  GtkButton       parent_instance;
+  guint           progress;
+  guint           show_progress : 1;
+  GtkCssProvider *css_provider;
+} EggProgressButtonPrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE (EggProgressButton, egg_progress_button, GTK_TYPE_BUTTON)
+
+enum {
+  PROP_0,
+  PROP_PROGRESS,
+  PROP_SHOW_PROGRESS,
+  N_PROPS
+};
+
+static GParamSpec *properties [N_PROPS];
+
+guint
+egg_progress_button_get_progress (EggProgressButton *self)
+{
+  EggProgressButtonPrivate *priv = egg_progress_button_get_instance_private (self);
+
+  g_return_val_if_fail (EGG_IS_PROGRESS_BUTTON (self), 0);
+
+  return priv->progress;
+}
+
+gboolean
+egg_progress_button_get_show_progress (EggProgressButton *self)
+{
+  EggProgressButtonPrivate *priv = egg_progress_button_get_instance_private (self);
+
+  g_return_val_if_fail (EGG_IS_PROGRESS_BUTTON (self), FALSE);
+
+  return priv->show_progress;
+}
+
+void
+egg_progress_button_set_progress (EggProgressButton *button,
+                                  guint              percentage)
+{
+  EggProgressButtonPrivate *priv = egg_progress_button_get_instance_private (button);
+  g_autofree gchar *css = NULL;
+
+  g_return_if_fail (EGG_IS_PROGRESS_BUTTON (button));
+
+  priv->progress = percentage = MIN (percentage, 100);
+
+  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 (priv->css_provider, css, -1, NULL);
+}
+
+void
+egg_progress_button_set_show_progress (EggProgressButton *button,
+                                       gboolean           show_progress)
+{
+  EggProgressButtonPrivate *priv = egg_progress_button_get_instance_private (button);
+  GtkStyleContext *context;
+
+  g_return_if_fail (EGG_IS_PROGRESS_BUTTON (button));
+
+  priv->show_progress = !!show_progress;
+
+  context = gtk_widget_get_style_context (GTK_WIDGET (button));
+
+  if (show_progress)
+    gtk_style_context_add_class (context, "install-progress");
+  else
+    gtk_style_context_remove_class (context, "install-progress");
+}
+
+static void
+egg_progress_button_dispose (GObject *object)
+{
+  EggProgressButton *button = EGG_PROGRESS_BUTTON (object);
+  EggProgressButtonPrivate *priv = egg_progress_button_get_instance_private (button);
+
+  g_clear_object (&priv->css_provider);
+
+  G_OBJECT_CLASS (egg_progress_button_parent_class)->dispose (object);
+}
+
+static void
+egg_progress_button_init (EggProgressButton *button)
+{
+  EggProgressButtonPrivate *priv = egg_progress_button_get_instance_private (button);
+
+  priv->css_provider = gtk_css_provider_new ();
+
+  gtk_style_context_add_provider (gtk_widget_get_style_context (GTK_WIDGET (button)),
+                                  GTK_STYLE_PROVIDER (priv->css_provider),
+                                  GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+}
+
+static void
+egg_progress_button_get_property (GObject    *object,
+                                  guint       prop_id,
+                                  GValue     *value,
+                                  GParamSpec *pspec)
+{
+  EggProgressButton *self = EGG_PROGRESS_BUTTON (object);
+
+  switch (prop_id)
+    {
+    case PROP_PROGRESS:
+      g_value_set_uint (value, egg_progress_button_get_progress (self));
+      break;
+
+    case PROP_SHOW_PROGRESS:
+      g_value_set_boolean (value, egg_progress_button_get_show_progress (self));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+egg_progress_button_set_property (GObject      *object,
+                                  guint         prop_id,
+                                  const GValue *value,
+                                  GParamSpec   *pspec)
+{
+  EggProgressButton *self = EGG_PROGRESS_BUTTON (object);
+
+  switch (prop_id)
+    {
+    case PROP_PROGRESS:
+      egg_progress_button_set_progress (self, g_value_get_uint (value));
+      break;
+
+    case PROP_SHOW_PROGRESS:
+      egg_progress_button_set_show_progress (self, g_value_get_boolean (value));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+egg_progress_button_class_init (EggProgressButtonClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->dispose = egg_progress_button_dispose;
+  object_class->get_property = egg_progress_button_get_property;
+  object_class->set_property = egg_progress_button_set_property;
+
+  properties [PROP_PROGRESS] =
+    g_param_spec_uint ("progress", NULL, NULL, 0, 100, 0,
+                       (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+  properties [PROP_SHOW_PROGRESS] =
+    g_param_spec_boolean ("show-progress", NULL,  NULL, FALSE,
+                         (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_properties (object_class, N_PROPS, properties);
+}
+
+GtkWidget *
+egg_progress_button_new (void)
+{
+  return g_object_new (EGG_TYPE_PROGRESS_BUTTON, NULL);
+}
diff --git a/contrib/egg/egg-progress-button.h b/contrib/egg/egg-progress-button.h
new file mode 100644
index 0000000..0cb0850
--- /dev/null
+++ b/contrib/egg/egg-progress-button.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2013-2014 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef EGG_PROGRESS_BUTTON_H
+#define EGG_PROGRESS_BUTTON_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define EGG_TYPE_PROGRESS_BUTTON (egg_progress_button_get_type ())
+
+G_DECLARE_DERIVABLE_TYPE (EggProgressButton, egg_progress_button, EGG, PROGRESS_BUTTON, GtkButton)
+
+struct _EggProgressButtonClass
+{
+  GtkButtonClass parent_class;
+
+  gpointer _reserved1;
+  gpointer _reserved2;
+  gpointer _reserved3;
+  gpointer _reserved4;
+};
+
+GtkWidget      *egg_progress_button_new               (void);
+guint      egg_progress_button_get_progress      (EggProgressButton *self);
+void       egg_progress_button_set_progress         (EggProgressButton *button,
+                                                  guint              percentage);
+gboolean   egg_progress_button_get_show_progress (EggProgressButton *self);
+void       egg_progress_button_set_show_progress (EggProgressButton *button,
+                                                                                                             
                                                                  gboolean           show_progress);
+
+G_END_DECLS
+
+#endif /* EGG_PROGRESS_BUTTON_H */
diff --git a/data/theme/shared.css b/data/theme/shared.css
index 320d0af..cc948b8 100644
--- a/data/theme/shared.css
+++ b/data/theme/shared.css
@@ -263,3 +263,18 @@ treeview.dim-label {
 button.run-arrow-button {
   min-width: 12px;
 }
+
+
+/* EggProgressButton */
+
+.install-progress {
+  background-image: linear-gradient(to top, @theme_selected_bg_color 2px, alpha(@theme_selected_bg_color, 0) 
2px);
+  background-repeat: no-repeat;
+  background-position: 0 bottom;
+  transition: none;
+}
+
+.install-progress:dir(rtl) {
+  background-position: 100% bottom;
+}
+


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