[gnome-software] Emit a signal when the application buttons are clicked



commit 0152d9a6560a652e0644babd810ce549a1aca064
Author: Richard Hughes <richard hughsie com>
Date:   Wed Jun 27 20:43:11 2012 +0100

    Emit a signal when the application buttons are clicked

 src/gs-app-widget.c |   33 ++++++++++++++++++++++++++++++---
 src/gs-app-widget.h |    1 +
 src/gs-main.c       |   28 ++++++++++++++++++++++++++++
 3 files changed, 59 insertions(+), 3 deletions(-)
---
diff --git a/src/gs-app-widget.c b/src/gs-app-widget.c
index 85eaab1..4da6553 100644
--- a/src/gs-app-widget.c
+++ b/src/gs-app-widget.c
@@ -43,6 +43,13 @@ struct _GsAppWidgetPrivate
 
 G_DEFINE_TYPE (GsAppWidget, gs_app_widget, GTK_TYPE_BOX)
 
+enum {
+	SIGNAL_BUTTON_CLICKED,
+	SIGNAL_LAST
+};
+
+static guint signals [SIGNAL_LAST] = { 0 };
+
 /**
  * gs_app_widget_refresh:
  **/
@@ -211,11 +218,29 @@ gs_app_widget_destroy (GtkWidget *object)
 }
 
 static void
-gs_app_widget_class_init (GsAppWidgetClass *class)
+gs_app_widget_class_init (GsAppWidgetClass *klass)
 {
-	GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+	GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 	widget_class->destroy = gs_app_widget_destroy;
-	g_type_class_add_private (class, sizeof (GsAppWidgetPrivate));
+
+	signals [SIGNAL_BUTTON_CLICKED] =
+		g_signal_new ("button-clicked",
+			      G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
+			      G_STRUCT_OFFSET (GsAppWidgetClass, button_clicked),
+			      NULL, NULL, g_cclosure_marshal_VOID__VOID,
+			      G_TYPE_NONE, 0);
+
+	g_type_class_add_private (klass, sizeof (GsAppWidgetPrivate));
+}
+
+/**
+ * gs_app_widget_button_clicked_cb:
+ **/
+static void
+gs_app_widget_button_clicked_cb (GtkWidget *widget, GsAppWidget *app_widget)
+{
+	g_signal_emit (app_widget, signals[SIGNAL_BUTTON_CLICKED], 0);
 }
 
 /**
@@ -286,6 +311,8 @@ gs_app_widget_init (GsAppWidget *app_widget)
 	gtk_widget_set_margin_right (GTK_WIDGET (priv->widget_button), 9);
 	gtk_widget_set_size_request (priv->widget_button, 100, -1);
 	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);
 	gtk_box_pack_start (GTK_BOX (box),
 			    GTK_WIDGET (priv->widget_button),
diff --git a/src/gs-app-widget.h b/src/gs-app-widget.h
index e9d9335..0803ec6 100644
--- a/src/gs-app-widget.h
+++ b/src/gs-app-widget.h
@@ -48,6 +48,7 @@ struct _GsAppWidget
 struct _GsAppWidgetClass
 {
 	GtkBoxClass		 parent_class;
+	void			(*button_clicked)	(GsAppWidget	*app_widget);
 };
 
 typedef enum {
diff --git a/src/gs-main.c b/src/gs-main.c
index 7aa666b..dd83d8a 100644
--- a/src/gs-main.c
+++ b/src/gs-main.c
@@ -222,6 +222,25 @@ gs_main_is_pkg_installed_target (PkPackage *pkg)
 }
 
 /**
+ * gs_main_app_widget_button_clicked_cb:
+ **/
+static void
+gs_main_app_widget_button_clicked_cb (GsAppWidget *app_widget, GsMainPrivate *priv)
+{
+	const gchar *package_id;
+	GsAppWidgetKind kind;
+
+	kind = gs_app_widget_get_kind (app_widget);
+	package_id = gs_app_widget_get_id (app_widget);
+	if (kind == GS_APP_WIDGET_KIND_UPDATE)
+		g_debug ("update %s", package_id);
+	else if (kind == GS_APP_WIDGET_KIND_INSTALL)
+		g_debug ("install %s", package_id);
+	else if (kind == GS_APP_WIDGET_KIND_REMOVE)
+		g_debug ("remove %s", package_id);
+}
+
+/**
  * gs_main_installed_add_package:
  **/
 static void
@@ -239,6 +258,9 @@ gs_main_installed_add_package (GsMainPrivate *priv, PkPackage *pkg)
 						priv->custom_icon_size);
 
 	widget = gs_app_widget_new ();
+	g_signal_connect (widget, "button-clicked",
+			  G_CALLBACK (gs_main_app_widget_button_clicked_cb),
+			  priv);
 	target_installed = gs_main_is_pkg_installed_target (pkg);
 	if (target_installed) {
 		list_box = priv->list_box_installed;
@@ -349,6 +371,9 @@ gs_main_installed_add_desktop_file (GsMainPrivate *priv,
 
 	/* add to list store */
 	widget = gs_app_widget_new ();
+	g_signal_connect (widget, "button-clicked",
+			  G_CALLBACK (gs_main_app_widget_button_clicked_cb),
+			  priv);
 	target_installed = gs_main_is_pkg_installed_target (pkg);
 	if (target_installed) {
 		list_box = priv->list_box_installed;
@@ -406,6 +431,9 @@ gs_main_installed_add_os_update (GsMainPrivate *priv, PkPackage *pkg)
 	}
 
 	priv->os_update_widget = gs_app_widget_new ();
+	g_signal_connect (priv->os_update_widget, "button-clicked",
+			  G_CALLBACK (gs_main_app_widget_button_clicked_cb),
+			  priv);
 	gs_app_widget_set_kind (GS_APP_WIDGET (priv->os_update_widget),
 				GS_APP_WIDGET_KIND_UPDATE);
 	gs_app_widget_set_id (GS_APP_WIDGET (priv->os_update_widget), "");



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