[gnome-software] Add some status widgets to the GsAppWidget for future use



commit e262b5e3f031c392401af88848fcb8bfd992a03b
Author: Richard Hughes <richard hughsie com>
Date:   Wed Jun 27 22:08:22 2012 +0100

    Add some status widgets to the GsAppWidget for future use

 src/gs-app-widget.c |   81 +++++++++++++++++++++++++++++++++++++++++++++++++--
 src/gs-app-widget.h |    4 ++
 src/gs-main.c       |    4 +-
 3 files changed, 84 insertions(+), 5 deletions(-)
---
diff --git a/src/gs-app-widget.c b/src/gs-app-widget.c
index 4da6553..03cd184 100644
--- a/src/gs-app-widget.c
+++ b/src/gs-app-widget.c
@@ -31,14 +31,17 @@ struct _GsAppWidgetPrivate
 	gchar		*id;
 	gchar		*name;
 	gchar		*description;
+	gchar		*status;
 	gchar		*version;
 	GdkPixbuf	*pixbuf;
 	GsAppWidgetKind	 kind;
 	GtkWidget	*widget_name;
 	GtkWidget	*widget_description;
+	GtkWidget	*widget_status;
 	GtkWidget	*widget_version;
 	GtkWidget	*widget_image;
 	GtkWidget	*widget_button;
+	GtkWidget	*widget_spinner;
 };
 
 G_DEFINE_TYPE (GsAppWidget, gs_app_widget, GTK_TYPE_BOX)
@@ -60,8 +63,14 @@ gs_app_widget_refresh (GsAppWidget *app_widget)
 
 	gtk_label_set_label (GTK_LABEL (priv->widget_name), priv->name);
 	gtk_label_set_label (GTK_LABEL (priv->widget_description), priv->description);
+	gtk_label_set_label (GTK_LABEL (priv->widget_status), priv->status);
 	gtk_label_set_label (GTK_LABEL (priv->widget_version), priv->version);
 	gtk_image_set_from_pixbuf (GTK_IMAGE (priv->widget_image), priv->pixbuf);
+	gtk_widget_set_visible (priv->widget_name, TRUE);
+	gtk_widget_set_visible (priv->widget_description, TRUE);
+	gtk_widget_set_visible (priv->widget_status, priv->status != NULL);
+	gtk_widget_set_visible (priv->widget_version, TRUE);
+	gtk_widget_set_visible (priv->widget_image, TRUE);
 
 	if (app_widget->priv->kind == GS_APP_WIDGET_KIND_INSTALL) {
 		gtk_button_set_label (GTK_BUTTON (priv->widget_button),
@@ -69,10 +78,21 @@ gs_app_widget_refresh (GsAppWidget *app_widget)
 	} else if (app_widget->priv->kind == GS_APP_WIDGET_KIND_REMOVE) {
 		gtk_button_set_label (GTK_BUTTON (priv->widget_button),
 				      _("Remove"));
-	} else {
+	} else if (app_widget->priv->kind == GS_APP_WIDGET_KIND_UPDATE) {
 		gtk_button_set_label (GTK_BUTTON (priv->widget_button),
 				      _("Update"));
-	} 
+	}
+
+	/* show / hide widgets */
+	if (app_widget->priv->kind == GS_APP_WIDGET_KIND_BUSY) {
+		gtk_widget_set_visible (priv->widget_button, FALSE);
+		gtk_widget_set_visible (priv->widget_spinner, TRUE);
+		gtk_spinner_start (GTK_SPINNER (priv->widget_spinner));
+	} else {
+		gtk_widget_set_visible (priv->widget_button, TRUE);
+		gtk_widget_set_visible (priv->widget_spinner, FALSE);
+		gtk_spinner_stop (GTK_SPINNER (priv->widget_spinner));
+	}
 }
 
 /**
@@ -115,6 +135,16 @@ gs_app_widget_get_description (GsAppWidget *app_widget)
 }
 
 /**
+ * gs_app_widget_get_status:
+ **/
+const gchar *
+gs_app_widget_get_status (GsAppWidget *app_widget)
+{
+	g_return_val_if_fail (GS_IS_APP_WIDGET (app_widget), NULL);
+	return app_widget->priv->status;
+}
+
+/**
  * gs_app_widget_get_kind:
  **/
 GsAppWidgetKind
@@ -176,6 +206,19 @@ gs_app_widget_set_description (GsAppWidget *app_widget, const gchar *description
 }
 
 /**
+ * gs_app_widget_set_status:
+ **/
+void
+gs_app_widget_set_status (GsAppWidget *app_widget, const gchar *status)
+{
+	g_return_if_fail (GS_IS_APP_WIDGET (app_widget));
+	g_return_if_fail (status != NULL);
+	g_free (app_widget->priv->status);
+	app_widget->priv->status = g_strdup (status);
+	gs_app_widget_refresh (app_widget);
+}
+
+/**
  * gs_app_widget_set_pixbuf:
  **/
 void
@@ -213,6 +256,14 @@ gs_app_widget_destroy (GtkWidget *object)
 
 	g_free (priv->id);
 	priv->id = NULL;
+	g_free (priv->name);
+	priv->name = NULL;
+	g_free (priv->description);
+	priv->description = NULL;
+	g_free (priv->status);
+	priv->status = NULL;
+	if (priv->pixbuf != NULL)
+		g_clear_object (&priv->pixbuf);
 
 	GTK_WIDGET_CLASS (gs_app_widget_parent_class)->destroy (object);
 }
@@ -250,6 +301,7 @@ static void
 gs_app_widget_init (GsAppWidget *app_widget)
 {
 	GsAppWidgetPrivate *priv;
+	GtkStyleContext *context;
 	GtkWidget *box;
 	PangoAttrList *attr_list;
 
@@ -275,6 +327,7 @@ gs_app_widget_init (GsAppWidget *app_widget)
 
 	/* name > version */
 	box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
+	gtk_widget_set_visible (box, TRUE);
 	priv->widget_name = gtk_label_new ("name");
 	gtk_label_set_ellipsize (GTK_LABEL (priv->widget_name),
 				 PANGO_ELLIPSIZE_NONE);
@@ -313,10 +366,32 @@ gs_app_widget_init (GsAppWidget *app_widget)
 	gtk_widget_set_vexpand (priv->widget_button, FALSE);
 	g_signal_connect (priv->widget_button, "clicked",
 			  G_CALLBACK (gs_app_widget_button_clicked_cb), app_widget);
-	box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
+
+	/* spinner */
+	priv->widget_spinner = gtk_spinner_new ();
+	gtk_widget_set_margin_right (GTK_WIDGET (priv->widget_spinner), 18);
+	gtk_widget_set_size_request (priv->widget_spinner, 48, 48);
+
+	/* status */
+	priv->widget_status = gtk_label_new ("status");
+	context = gtk_widget_get_style_context (priv->widget_status);
+	gtk_style_context_add_class (context, "dim-label");
+	gtk_label_set_ellipsize (GTK_LABEL (priv->widget_status),
+				 PANGO_ELLIPSIZE_NONE);
+	gtk_label_set_line_wrap (GTK_LABEL (priv->widget_status), TRUE);
+	gtk_label_set_max_width_chars (GTK_LABEL (priv->widget_status), 20);
+	gtk_widget_set_margin_right (GTK_WIDGET (priv->widget_status), 9);
+	box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
+	gtk_widget_set_visible (box, TRUE);
 	gtk_box_pack_start (GTK_BOX (box),
 			    GTK_WIDGET (priv->widget_button),
 			    FALSE, FALSE, 0);
+	gtk_box_pack_start (GTK_BOX (box),
+			    GTK_WIDGET (priv->widget_spinner),
+			    FALSE, FALSE, 0);
+	gtk_box_pack_start (GTK_BOX (box),
+			    GTK_WIDGET (priv->widget_status),
+			    FALSE, FALSE, 0);
 	gtk_box_pack_start (GTK_BOX (app_widget),
 			    GTK_WIDGET (box),
 			    FALSE, FALSE, 0);
diff --git a/src/gs-app-widget.h b/src/gs-app-widget.h
index 0803ec6..9207c23 100644
--- a/src/gs-app-widget.h
+++ b/src/gs-app-widget.h
@@ -55,6 +55,7 @@ typedef enum {
 	GS_APP_WIDGET_KIND_INSTALL,
 	GS_APP_WIDGET_KIND_UPDATE,
 	GS_APP_WIDGET_KIND_REMOVE,
+	GS_APP_WIDGET_KIND_BUSY,
 	GS_APP_WIDGET_KIND_LAST
 } GsAppWidgetKind;
 
@@ -72,6 +73,9 @@ void		 gs_app_widget_set_version		(GsAppWidget	*app_widget,
 const gchar	*gs_app_widget_get_description		(GsAppWidget	*app_widget);
 void		 gs_app_widget_set_description		(GsAppWidget	*app_widget,
 							 const gchar	*description);
+const gchar	*gs_app_widget_get_status		(GsAppWidget	*app_widget);
+void		 gs_app_widget_set_status		(GsAppWidget	*app_widget,
+							 const gchar	*status);
 void		 gs_app_widget_set_pixbuf		(GsAppWidget	*app_widget,
 							 GdkPixbuf	*pixbuf);
 GsAppWidgetKind	 gs_app_widget_get_kind			(GsAppWidget	*app_widget);
diff --git a/src/gs-main.c b/src/gs-main.c
index b4da65d..df146d3 100644
--- a/src/gs-main.c
+++ b/src/gs-main.c
@@ -278,7 +278,7 @@ gs_main_installed_add_package (GsMainPrivate *priv, PkPackage *pkg)
 	gs_app_widget_set_pixbuf (GS_APP_WIDGET (widget), pixbuf);
 	gs_app_widget_set_version (GS_APP_WIDGET (widget), tmp);
 	gtk_container_add (GTK_CONTAINER (list_box), widget);
-	gtk_widget_show_all (widget);
+	gtk_widget_show (widget);
 	if (pixbuf != NULL)
 		g_object_unref (pixbuf);
 	g_free (tmp);
@@ -391,7 +391,7 @@ gs_main_installed_add_desktop_file (GsMainPrivate *priv,
 	gs_app_widget_set_pixbuf (GS_APP_WIDGET (widget), pixbuf);
 	gs_app_widget_set_version (GS_APP_WIDGET (widget), version_tmp);
 	gtk_container_add (GTK_CONTAINER (list_box), widget);
-	gtk_widget_show_all (widget);
+	gtk_widget_show (widget);
 out:
 	if (pixbuf != NULL)
 		g_object_unref (pixbuf);



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