[gnome-software] popular tile: Derive directly from GtkButton



commit da7aac6b7dfc9eb265da77c04310504b7b025a83
Author: Kalev Lember <kalevlember gmail com>
Date:   Sun Aug 3 12:32:17 2014 +0200

    popular tile: Derive directly from GtkButton
    
    This simplifies code and makes it easier to style the buttons with CSS.

 src/gs-popular-tile.c |   35 +------------
 src/gs-popular-tile.h |    6 +--
 src/popular-tile.ui   |  139 +++++++++++++++++++++---------------------------
 3 files changed, 65 insertions(+), 115 deletions(-)
---
diff --git a/src/gs-popular-tile.c b/src/gs-popular-tile.c
index ddccee0..bb5c5e4 100644
--- a/src/gs-popular-tile.c
+++ b/src/gs-popular-tile.c
@@ -29,21 +29,13 @@
 struct _GsPopularTilePrivate
 {
        GsApp           *app;
-       GtkWidget       *button;
        GtkWidget       *label;
        GtkWidget       *image;
        GtkWidget       *eventbox;
        GtkWidget       *waiting;
 };
 
-G_DEFINE_TYPE_WITH_PRIVATE (GsPopularTile, gs_popular_tile, GTK_TYPE_BIN)
-
-enum {
-       SIGNAL_CLICKED,
-       SIGNAL_LAST
-};
-
-static guint signals [SIGNAL_LAST] = { 0 };
+G_DEFINE_TYPE_WITH_PRIVATE (GsPopularTile, gs_popular_tile, GTK_TYPE_BUTTON)
 
 GsApp *
 gs_popular_tile_get_app (GsPopularTile *tile)
@@ -66,7 +58,7 @@ app_state_changed (GsApp *app, GParamSpec *pspec, GsPopularTile *tile)
        gchar *name;
 
        priv = gs_popular_tile_get_instance_private (tile);
-       accessible = gtk_widget_get_accessible (priv->button);
+       accessible = gtk_widget_get_accessible (GTK_WIDGET (tile));
 
        label = gtk_bin_get_child (GTK_BIN (priv->eventbox));
        switch (gs_app_get_state (app)) {
@@ -147,44 +139,21 @@ gs_popular_tile_destroy (GtkWidget *widget)
 }
 
 static void
-button_clicked (GsPopularTile *tile)
-{
-       GsPopularTilePrivate *priv;
-       priv = gs_popular_tile_get_instance_private (tile);
-       if (priv->app)
-               g_signal_emit (tile, signals[SIGNAL_CLICKED], 0);
-}
-
-static void
 gs_popular_tile_init (GsPopularTile *tile)
 {
-       GsPopularTilePrivate *priv;
-
        gtk_widget_set_has_window (GTK_WIDGET (tile), FALSE);
        gtk_widget_init_template (GTK_WIDGET (tile));
-       priv = gs_popular_tile_get_instance_private (tile);
-       g_signal_connect_swapped (priv->button, "clicked",
-                                 G_CALLBACK (button_clicked), tile);
 }
 
 static void
 gs_popular_tile_class_init (GsPopularTileClass *klass)
 {
-       GObjectClass *object_class = G_OBJECT_CLASS (klass);
        GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
        widget_class->destroy = gs_popular_tile_destroy;
 
-       signals [SIGNAL_CLICKED] =
-               g_signal_new ("clicked",
-                             G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
-                             G_STRUCT_OFFSET (GsPopularTileClass, clicked),
-                             NULL, NULL, g_cclosure_marshal_VOID__VOID,
-                             G_TYPE_NONE, 0);
-
        gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/Software/popular-tile.ui");
 
-       gtk_widget_class_bind_template_child_private (widget_class, GsPopularTile, button);
        gtk_widget_class_bind_template_child_private (widget_class, GsPopularTile, label);
        gtk_widget_class_bind_template_child_private (widget_class, GsPopularTile, image);
        gtk_widget_class_bind_template_child_private (widget_class, GsPopularTile, eventbox);
diff --git a/src/gs-popular-tile.h b/src/gs-popular-tile.h
index 2be5a7e..a451590 100644
--- a/src/gs-popular-tile.h
+++ b/src/gs-popular-tile.h
@@ -41,15 +41,13 @@ typedef struct _GsPopularTilePrivate                GsPopularTilePrivate;
 
 struct _GsPopularTile
 {
-       GtkBin             parent;
+       GtkButton                parent;
        GsPopularTilePrivate    *priv;
 };
 
 struct _GsPopularTileClass
 {
-       GtkBinClass      parent_class;
-
-       void                    (*clicked)      (GsPopularTile  *tile);
+       GtkButtonClass           parent_class;
 };
 
 GType           gs_popular_tile_get_type               (void);
diff --git a/src/popular-tile.ui b/src/popular-tile.ui
index acbefff..3bfdb6d 100644
--- a/src/popular-tile.ui
+++ b/src/popular-tile.ui
@@ -1,101 +1,84 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <!-- interface-requires gtk+ 3.10 -->
-  <template class="GsPopularTile" parent="GtkBin">
+  <template class="GsPopularTile" parent="GtkButton">
     <property name="visible">True</property>
+    <style>
+      <class name="view"/>
+      <class name="tile"/>
+    </style>
     <child>
-      <object class="GtkAspectFrame" id="frame">
+      <object class="GtkOverlay" id="overlay">
         <property name="visible">True</property>
-        <property name="valign">start</property>
-        <property name="shadow_type">none</property>
-        <property name="height_request">180</property>
-        <property name="obey_child">False</property>
-        <property name="ratio">1.0</property>
-        <child>
-          <object class="GtkButton" id="button">
+        <property name="halign">fill</property>
+        <property name="valign">fill</property>
+        <child type="overlay">
+          <object class="GtkImage" id="waiting">
             <property name="visible">True</property>
-            <property name="halign">fill</property>
-            <property name="valign">fill</property>
+            <property name="halign">center</property>
+            <property name="valign">center</property>
+            <property name="pixel-size">16</property>
+            <property name="icon-name">content-loading-symbolic</property>
+            <style>
+              <class name="dim-label"/>
+            </style>
+          </object>
+        </child>
+        <child type="overlay">
+          <object class="GtkEventBox" id="eventbox">
+            <property name="no_show_all">True</property>
+            <property name="visible_window">True</property>
+            <property name="halign">end</property>
+            <property name="valign">end</property>
+            <property name="margin-bottom">35</property>
             <style>
-              <class name="view"/>
-              <class name="tile"/>
+              <class name="installed-overlay-box"/>
             </style>
             <child>
-              <object class="GtkOverlay" id="overlay">
+              <object class="GtkLabel" id="installed-label">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">Installed</property>
+                <property name="margin-start">16</property>
+                <property name="margin-end">16</property>
+                <property name="margin-top">4</property>
+                <property name="margin-bottom">4</property>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkEventBox" id="eboxbox">
+            <property name="visible">True</property>
+            <child>
+              <object class="GtkBox" id="box">
                 <property name="visible">True</property>
+                <property name="orientation">vertical</property>
                 <property name="halign">fill</property>
                 <property name="valign">fill</property>
-                <child type="overlay">
-                  <object class="GtkImage" id="waiting">
+                <property name="margin">12</property>
+                <child>
+                  <object class="GtkImage" id="image">
                     <property name="visible">True</property>
-                    <property name="halign">center</property>
                     <property name="valign">center</property>
-                    <property name="pixel-size">16</property>
-                    <property name="icon-name">content-loading-symbolic</property>
-                    <style>
-                      <class name="dim-label"/>
-                    </style>
-                  </object>
-                </child>
-                <child type="overlay">
-                  <object class="GtkEventBox" id="eventbox">
-                    <property name="no_show_all">True</property>
-                    <property name="visible_window">True</property>
-                    <property name="halign">end</property>
-                    <property name="valign">end</property>
-                    <property name="margin-bottom">35</property>
-                    <style>
-                      <class name="installed-overlay-box"/>
-                    </style>
-                    <child>
-                      <object class="GtkLabel" id="installed-label">
-                        <property name="visible">True</property>
-                        <property name="label" translatable="yes">Installed</property>
-                        <property name="margin-start">16</property>
-                        <property name="margin-end">16</property>
-                        <property name="margin-top">4</property>
-                        <property name="margin-bottom">4</property>
-                      </object>
-                    </child>
                   </object>
+                  <packing>
+                    <property name="expand">True</property>
+                    <property name="fill">True</property>
+                  </packing>
                 </child>
                 <child>
-                  <object class="GtkEventBox" id="eboxbox">
+                  <object class="GtkLabel" id="label">
                     <property name="visible">True</property>
-                    <child>
-                      <object class="GtkBox" id="box">
-                        <property name="visible">True</property>
-                        <property name="orientation">vertical</property>
-                        <property name="halign">fill</property>
-                        <property name="valign">fill</property>
-                        <property name="margin">12</property>
-                        <child>
-                          <object class="GtkImage" id="image">
-                            <property name="visible">True</property>
-                            <property name="valign">center</property>
-                          </object>
-                          <packing>
-                            <property name="expand">True</property>
-                            <property name="fill">True</property>
-                          </packing>
-                        </child>
-                        <child>
-                          <object class="GtkLabel" id="label">
-                            <property name="visible">True</property>
-                            <property name="valign">end</property>
-                            <property name="margin">6</property>
-                            <property name="ellipsize">end</property>
-                            <property name="width_chars">10</property>
-                            <property name="max_width_chars">15</property>
-                          </object>
-                          <packing>
-                            <property name="expand">False</property>
-                            <property name="fill">True</property>
-                          </packing>
-                        </child>
-                      </object>
-                    </child>
+                    <property name="valign">end</property>
+                    <property name="margin">6</property>
+                    <property name="ellipsize">end</property>
+                    <property name="width_chars">10</property>
+                    <property name="max_width_chars">15</property>
                   </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">True</property>
+                  </packing>
                 </child>
               </object>
             </child>


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