[gnome-software] Add a read-more-clicked signal to GsAppWidget



commit cd83d74cb10b9d04b06b1fc9407b106fddc18206
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Aug 21 23:18:38 2013 -0400

    Add a read-more-clicked signal to GsAppWidget
    
    We want different behaviour for the read more links in the
    installed list and the updates list, so a signal makes sense.
    Move the implementation for the installed list to gs-main.c.
    
    Also, hide the box containing the button and spinner on the
    updates list. This was reserving 200 pixels of empty space
     at the right.

 src/gs-app-widget.c |   88 +++++++-------------------------------------------
 src/gs-main.c       |   80 +++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 92 insertions(+), 76 deletions(-)
---
diff --git a/src/gs-app-widget.c b/src/gs-app-widget.c
index 9b25eca..8099ddd 100644
--- a/src/gs-app-widget.c
+++ b/src/gs-app-widget.c
@@ -51,6 +51,7 @@ G_DEFINE_TYPE (GsAppWidget, gs_app_widget, GTK_TYPE_BOX)
 
 enum {
        SIGNAL_BUTTON_CLICKED,
+       SIGNAL_READ_MORE_CLICKED,
        SIGNAL_LAST
 };
 
@@ -64,6 +65,7 @@ gs_app_widget_refresh (GsAppWidget *app_widget)
 {
        GsAppWidgetPrivate *priv = app_widget->priv;
        GtkStyleContext *context;
+        GtkWidget *box;
 
        if (app_widget->priv->app == NULL)
                return;
@@ -116,6 +118,9 @@ gs_app_widget_refresh (GsAppWidget *app_widget)
                gtk_widget_set_visible (priv->widget_button, FALSE);
                break;
        }
+        box = gtk_widget_get_parent (priv->widget_button);
+        gtk_widget_set_visible (box, gtk_widget_get_visible (priv->widget_spinner) ||
+                                     gtk_widget_get_visible (priv->widget_button));
 }
 
 /**
@@ -253,6 +258,12 @@ gs_app_widget_class_init (GsAppWidgetClass *klass)
                              G_STRUCT_OFFSET (GsAppWidgetClass, button_clicked),
                              NULL, NULL, g_cclosure_marshal_VOID__VOID,
                              G_TYPE_NONE, 0);
+       signals [SIGNAL_READ_MORE_CLICKED] =
+               g_signal_new ("read-more-clicked",
+                             G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
+                             G_STRUCT_OFFSET (GsAppWidgetClass, read_more_clicked),
+                             NULL, NULL, g_cclosure_marshal_VOID__VOID,
+                             G_TYPE_NONE, 0);
 
        g_type_class_add_private (klass, sizeof (GsAppWidgetPrivate));
 }
@@ -373,78 +384,7 @@ read_more_cb (GtkLabel    *widget,
               const gchar *uri,
               GsAppWidget *app_widget)
 {
-        GtkWidget *details, *button, *grid;
-        GtkWidget *image, *label;
-        GsApp *app;
-        PangoAttrList *attr_list;
-        const gchar *tmp;
-
-        app = gs_app_widget_get_app (app_widget);
-
-        details = gtk_dialog_new_with_buttons (_("Details"),
-                                               GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET 
(app_widget))),
-                                               GTK_DIALOG_MODAL,
-                                               _("_Done"), GTK_RESPONSE_CLOSE,
-                                               NULL);
-        gtk_container_set_border_width (GTK_CONTAINER (details), 20);
-
-        button = gtk_dialog_get_widget_for_response (GTK_DIALOG (details), GTK_RESPONSE_CLOSE);
-        gtk_style_context_add_class (gtk_widget_get_style_context (button), "suggested-action");
-        g_signal_connect_swapped (button, "clicked", G_CALLBACK (gtk_widget_destroy), details);
-
-        grid = gtk_grid_new ();
-        gtk_widget_show (grid);
-        gtk_widget_set_halign (grid, GTK_ALIGN_FILL);
-        gtk_grid_set_column_spacing (GTK_GRID (grid), 20);
-        gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (details))), grid);
-
-        image = gtk_image_new ();
-        if (gs_app_get_pixbuf (app)) {
-                gtk_image_set_from_pixbuf (GTK_IMAGE (image), gs_app_get_pixbuf (app));         
gtk_widget_show (image);
-        }
-        gtk_grid_attach (GTK_GRID (grid), image, 0, 0, 1, 3);
-
-        label = gtk_label_new (gs_app_get_name (app));
-        gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
-        gtk_widget_set_hexpand (label, TRUE);
-        gtk_widget_set_margin_bottom (label, 10);
-       attr_list = pango_attr_list_new ();
-       pango_attr_list_insert (attr_list, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
-       pango_attr_list_insert (attr_list, pango_attr_scale_new (1));
-       gtk_label_set_attributes (GTK_LABEL (label), attr_list);
-       pango_attr_list_unref (attr_list);
-        gtk_widget_show (label);
-        gtk_grid_attach (GTK_GRID (grid), label, 1, 0, 1, 1);
-
-        label = gtk_label_new (NULL);
-        gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
-        gtk_widget_set_hexpand (label, TRUE);
-        gtk_widget_set_margin_bottom (label, 20);
-        if (gs_app_get_summary (app)) {
-                gtk_label_set_label (GTK_LABEL (label), gs_app_get_summary (app));
-                gtk_widget_show (label);
-        }
-        gtk_grid_attach (GTK_GRID (grid), label, 1, 1, 1, 1);
-
-        tmp = gs_app_get_description (app);
-        if (!tmp) {
-               tmp = _("The author of this software has not included a long description.");
-        }
-        label = gtk_label_new (tmp);
-        gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
-        gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
-        gtk_widget_show (label);
-        gtk_grid_attach (GTK_GRID (grid), label, 0, 3, 2, 1);
-
-        if (gs_app_get_url (app)) {
-                button = gtk_link_button_new_with_label (gs_app_get_url (app), _("Visit website"));
-                gtk_widget_set_halign (button, GTK_ALIGN_START);
-                gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
-                gtk_widget_show (button);
-                gtk_grid_attach (GTK_GRID (grid), button, 0, 4, 2, 1);
-        }
-
-        gtk_window_present (GTK_WINDOW (details));
+       g_signal_emit (app_widget, signals[SIGNAL_READ_MORE_CLICKED], 0);
 
         return TRUE;
 }
@@ -469,9 +409,7 @@ gs_app_widget_init (GsAppWidget *app_widget)
 
        /* set defaults */
        gtk_box_set_spacing (GTK_BOX (app_widget), 3);
-       gtk_widget_set_margin_left (GTK_WIDGET (app_widget), 9);
-       gtk_widget_set_margin_top (GTK_WIDGET (app_widget), 9);
-       gtk_widget_set_margin_bottom (GTK_WIDGET (app_widget), 9);
+        g_object_set (app_widget, "margin", 9, NULL);
 
        /* pixbuf */
        priv->widget_image = gtk_image_new_from_icon_name ("missing-image",
diff --git a/src/gs-main.c b/src/gs-main.c
index ebbd5a2..80373ed 100644
--- a/src/gs-main.c
+++ b/src/gs-main.c
@@ -479,6 +479,81 @@ gs_main_app_widget_button_clicked_cb (GsAppWidget *app_widget, GsMainPrivate *pr
        }
 }
 
+static void
+gs_main_app_widget_read_more_clicked_cb (GsAppWidget *app_widget, GsMainPrivate *priv)
+{
+        GtkWidget *details, *button, *grid;
+        GtkWidget *image, *label;
+        GsApp *app;
+        PangoAttrList *attr_list;
+        const gchar *tmp;
+
+        app = gs_app_widget_get_app (app_widget);
+
+        details = gtk_dialog_new_with_buttons (_("Details"),
+                                               GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET 
(app_widget))),
+                                               GTK_DIALOG_MODAL,
+                                               _("_Done"), GTK_RESPONSE_CLOSE,
+                                               NULL);
+        gtk_container_set_border_width (GTK_CONTAINER (details), 20);
+        button = gtk_dialog_get_widget_for_response (GTK_DIALOG (details), GTK_RESPONSE_CLOSE);
+        gtk_style_context_add_class (gtk_widget_get_style_context (button), "suggested-action");
+        g_signal_connect_swapped (button, "clicked", G_CALLBACK (gtk_widget_destroy), details);
+
+        grid = gtk_grid_new ();
+        gtk_widget_show (grid);
+        gtk_widget_set_halign (grid, GTK_ALIGN_FILL);
+        gtk_grid_set_column_spacing (GTK_GRID (grid), 20);
+        gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (details))), grid);
+
+        image = gtk_image_new ();
+        if (gs_app_get_pixbuf (app)) {
+                gtk_image_set_from_pixbuf (GTK_IMAGE (image), gs_app_get_pixbuf (app));         
gtk_widget_show (image);
+        }
+        gtk_grid_attach (GTK_GRID (grid), image, 0, 0, 1, 3);
+
+        label = gtk_label_new (gs_app_get_name (app));
+        gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
+        gtk_widget_set_hexpand (label, TRUE);
+        gtk_widget_set_margin_bottom (label, 10);
+        attr_list = pango_attr_list_new ();
+        pango_attr_list_insert (attr_list, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
+        pango_attr_list_insert (attr_list, pango_attr_scale_new (1));
+        gtk_label_set_attributes (GTK_LABEL (label), attr_list);
+        pango_attr_list_unref (attr_list);
+        gtk_widget_show (label);
+        gtk_grid_attach (GTK_GRID (grid), label, 1, 0, 1, 1);
+
+        label = gtk_label_new (NULL);
+        gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
+        gtk_widget_set_hexpand (label, TRUE);
+        gtk_widget_set_margin_bottom (label, 20);
+        if (gs_app_get_summary (app)) {
+                gtk_label_set_label (GTK_LABEL (label), gs_app_get_summary (app));
+                gtk_widget_show (label);
+        }
+        gtk_grid_attach (GTK_GRID (grid), label, 1, 1, 1, 1);
+        tmp = gs_app_get_description (app);
+        if (!tmp) {
+                tmp = _("The author of this software has not included a long description.");
+        }
+        label = gtk_label_new (tmp);
+        gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
+        gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
+        gtk_widget_show (label);
+        gtk_grid_attach (GTK_GRID (grid), label, 0, 3, 2, 1);
+
+        if (gs_app_get_url (app)) {
+                button = gtk_link_button_new_with_label (gs_app_get_url (app), _("Visit website"));
+                gtk_widget_set_halign (button, GTK_ALIGN_START);
+                gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
+                gtk_widget_show (button);
+                gtk_grid_attach (GTK_GRID (grid), button, 0, 4, 2, 1);
+        }
+
+        gtk_window_present (GTK_WINDOW (details));
+}
+
 #if 0
 /**
  * gs_main_installed_add_os_update:
@@ -543,6 +618,10 @@ gs_main_get_installed_cb (GObject *source_object,
                g_signal_connect (widget, "button-clicked",
                                  G_CALLBACK (gs_main_app_widget_button_clicked_cb),
                                  priv);
+               g_signal_connect (widget, "read-more-clicked",
+                                 G_CALLBACK (gs_main_app_widget_read_more_clicked_cb),
+                                 priv);
+
                gs_app_widget_set_kind (GS_APP_WIDGET (widget),
                                        gs_app_get_kind (app) == GS_APP_KIND_SYSTEM ? 
GS_APP_WIDGET_KIND_BLANK : GS_APP_WIDGET_KIND_REMOVE);
                gs_app_widget_set_app (GS_APP_WIDGET (widget), app);
@@ -1202,7 +1281,6 @@ gs_main_get_featured_cb (GObject *source_object,
        GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source_object);
        GtkImage *image;
        GtkWidget *button;
-       GtkWidget *widget;
 
        list = gs_plugin_loader_get_featured_finish (plugin_loader,
                                                     res,


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