[gnome-software] popular tile: Port to G_DECLARE_FINAL_TYPE macro
- From: Kalev Lember <klember src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] popular tile: Port to G_DECLARE_FINAL_TYPE macro
- Date: Mon, 7 Sep 2015 17:37:27 +0000 (UTC)
commit 5767e6c2a2b7928706bf740ca0995ddf5e787c66
Author: Kalev Lember <klember redhat com>
Date: Mon Sep 7 16:32:48 2015 +0200
popular tile: Port to G_DECLARE_FINAL_TYPE macro
src/gs-popular-tile.c | 82 ++++++++++++++++++++----------------------------
src/gs-popular-tile.h | 23 +------------
2 files changed, 36 insertions(+), 69 deletions(-)
---
diff --git a/src/gs-popular-tile.c b/src/gs-popular-tile.c
index 0bddf95..1565788 100644
--- a/src/gs-popular-tile.c
+++ b/src/gs-popular-tile.c
@@ -29,8 +29,10 @@
#include "gs-star-widget.h"
#include "gs-utils.h"
-struct _GsPopularTilePrivate
+struct _GsPopularTile
{
+ GtkButton parent_instance;
+
GsApp *app;
GtkWidget *label;
GtkWidget *image;
@@ -39,17 +41,14 @@ struct _GsPopularTilePrivate
GtkWidget *stars;
};
-G_DEFINE_TYPE_WITH_PRIVATE (GsPopularTile, gs_popular_tile, GTK_TYPE_BUTTON)
+G_DEFINE_TYPE (GsPopularTile, gs_popular_tile, GTK_TYPE_BUTTON)
GsApp *
gs_popular_tile_get_app (GsPopularTile *tile)
{
- GsPopularTilePrivate *priv;
-
g_return_val_if_fail (GS_IS_POPULAR_TILE (tile), NULL);
- priv = gs_popular_tile_get_instance_private (tile);
- return priv->app;
+ return tile->app;
}
static gboolean
@@ -57,23 +56,21 @@ app_state_changed_idle (gpointer user_data)
{
GsPopularTile *tile = GS_POPULAR_TILE (user_data);
AtkObject *accessible;
- GsPopularTilePrivate *priv;
GtkWidget *label;
gboolean installed;
_cleanup_free_ gchar *name = NULL;
- priv = gs_popular_tile_get_instance_private (tile);
accessible = gtk_widget_get_accessible (GTK_WIDGET (tile));
- label = gtk_bin_get_child (GTK_BIN (priv->eventbox));
- switch (gs_app_get_state (priv->app)) {
+ label = gtk_bin_get_child (GTK_BIN (tile->eventbox));
+ switch (gs_app_get_state (tile->app)) {
case AS_APP_STATE_INSTALLED:
case AS_APP_STATE_INSTALLING:
case AS_APP_STATE_REMOVING:
case AS_APP_STATE_UPDATABLE:
installed = TRUE;
name = g_strdup_printf ("%s (%s)",
- gs_app_get_name (priv->app),
+ gs_app_get_name (tile->app),
_("Installed"));
/* TRANSLATORS: this is the small blue label on the tile
* that tells the user the application is installed */
@@ -82,15 +79,15 @@ app_state_changed_idle (gpointer user_data)
case AS_APP_STATE_AVAILABLE:
default:
installed = FALSE;
- name = g_strdup (gs_app_get_name (priv->app));
+ name = g_strdup (gs_app_get_name (tile->app));
break;
}
- gtk_widget_set_visible (priv->eventbox, installed);
+ gtk_widget_set_visible (tile->eventbox, installed);
if (GTK_IS_ACCESSIBLE (accessible)) {
atk_object_set_name (accessible, name);
- atk_object_set_description (accessible, gs_app_get_summary (priv->app));
+ atk_object_set_description (accessible, gs_app_get_summary (tile->app));
}
g_object_unref (tile);
@@ -106,53 +103,46 @@ app_state_changed (GsApp *app, GParamSpec *pspec, GsPopularTile *tile)
void
gs_popular_tile_set_app (GsPopularTile *tile, GsApp *app)
{
- GsPopularTilePrivate *priv;
-
g_return_if_fail (GS_IS_POPULAR_TILE (tile));
g_return_if_fail (GS_IS_APP (app) || app == NULL);
- priv = gs_popular_tile_get_instance_private (tile);
-
- if (priv->app)
- g_signal_handlers_disconnect_by_func (priv->app, app_state_changed, tile);
+ if (tile->app)
+ g_signal_handlers_disconnect_by_func (tile->app, app_state_changed, tile);
- g_clear_object (&priv->app);
+ g_clear_object (&tile->app);
if (!app)
return;
- priv->app = g_object_ref (app);
+ tile->app = g_object_ref (app);
- if (gs_app_get_rating_kind (priv->app) == GS_APP_RATING_KIND_USER) {
- gs_star_widget_set_rating (GS_STAR_WIDGET (priv->stars),
+ if (gs_app_get_rating_kind (tile->app) == GS_APP_RATING_KIND_USER) {
+ gs_star_widget_set_rating (GS_STAR_WIDGET (tile->stars),
GS_APP_RATING_KIND_USER,
- gs_app_get_rating (priv->app));
+ gs_app_get_rating (tile->app));
} else {
- gs_star_widget_set_rating (GS_STAR_WIDGET (priv->stars),
+ gs_star_widget_set_rating (GS_STAR_WIDGET (tile->stars),
GS_APP_RATING_KIND_KUDOS,
- gs_app_get_kudos_percentage (priv->app));
+ gs_app_get_kudos_percentage (tile->app));
}
- gtk_stack_set_visible_child_name (GTK_STACK (priv->stack), "content");
+ gtk_stack_set_visible_child_name (GTK_STACK (tile->stack), "content");
- g_signal_connect (priv->app, "notify::state",
+ g_signal_connect (tile->app, "notify::state",
G_CALLBACK (app_state_changed), tile);
- app_state_changed (priv->app, NULL, tile);
+ app_state_changed (tile->app, NULL, tile);
- gs_image_set_from_pixbuf (GTK_IMAGE (priv->image), gs_app_get_pixbuf (priv->app));
+ gs_image_set_from_pixbuf (GTK_IMAGE (tile->image), gs_app_get_pixbuf (tile->app));
- gtk_label_set_label (GTK_LABEL (priv->label), gs_app_get_name (app));
+ gtk_label_set_label (GTK_LABEL (tile->label), gs_app_get_name (app));
}
static void
gs_popular_tile_destroy (GtkWidget *widget)
{
GsPopularTile *tile = GS_POPULAR_TILE (widget);
- GsPopularTilePrivate *priv;
- priv = gs_popular_tile_get_instance_private (tile);
+ if (tile->app)
+ g_signal_handlers_disconnect_by_func (tile->app, app_state_changed, tile);
- if (priv->app)
- g_signal_handlers_disconnect_by_func (priv->app, app_state_changed, tile);
-
- g_clear_object (&priv->app);
+ g_clear_object (&tile->app);
GTK_WIDGET_CLASS (gs_popular_tile_parent_class)->destroy (widget);
}
@@ -160,13 +150,9 @@ gs_popular_tile_destroy (GtkWidget *widget)
static void
gs_popular_tile_init (GsPopularTile *tile)
{
- GsPopularTilePrivate *priv;
-
- priv = gs_popular_tile_get_instance_private (tile);
-
gtk_widget_set_has_window (GTK_WIDGET (tile), FALSE);
gtk_widget_init_template (GTK_WIDGET (tile));
- gs_star_widget_set_icon_size (GS_STAR_WIDGET (priv->stars), 12);
+ gs_star_widget_set_icon_size (GS_STAR_WIDGET (tile->stars), 12);
}
static void
@@ -178,11 +164,11 @@ gs_popular_tile_class_init (GsPopularTileClass *klass)
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, label);
- gtk_widget_class_bind_template_child_private (widget_class, GsPopularTile, image);
- gtk_widget_class_bind_template_child_private (widget_class, GsPopularTile, eventbox);
- gtk_widget_class_bind_template_child_private (widget_class, GsPopularTile, stack);
- gtk_widget_class_bind_template_child_private (widget_class, GsPopularTile, stars);
+ gtk_widget_class_bind_template_child (widget_class, GsPopularTile, label);
+ gtk_widget_class_bind_template_child (widget_class, GsPopularTile, image);
+ gtk_widget_class_bind_template_child (widget_class, GsPopularTile, eventbox);
+ gtk_widget_class_bind_template_child (widget_class, GsPopularTile, stack);
+ gtk_widget_class_bind_template_child (widget_class, GsPopularTile, stars);
}
GtkWidget *
diff --git a/src/gs-popular-tile.h b/src/gs-popular-tile.h
index a451590..564acfe 100644
--- a/src/gs-popular-tile.h
+++ b/src/gs-popular-tile.h
@@ -26,31 +26,12 @@
#include "gs-app.h"
-#define GS_TYPE_POPULAR_TILE (gs_popular_tile_get_type())
-#define GS_POPULAR_TILE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GS_TYPE_POPULAR_TILE,
GsPopularTile))
-#define GS_POPULAR_TILE_CLASS(cls) (G_TYPE_CHECK_CLASS_CAST((cls), GS_TYPE_POPULAR_TILE,
GsPopularTileClass))
-#define GS_IS_POPULAR_TILE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GS_TYPE_POPULAR_TILE))
-#define GS_IS_POPULAR_TILE_CLASS(cls) (G_TYPE_CHECK_CLASS_TYPE((cls), GS_TYPE_POPULAR_TILE))
-#define GS_POPULAR_TILE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GS_TYPE_POPULAR_TILE,
GsPopularTileClass))
-
G_BEGIN_DECLS
-typedef struct _GsPopularTile GsPopularTile;
-typedef struct _GsPopularTileClass GsPopularTileClass;
-typedef struct _GsPopularTilePrivate GsPopularTilePrivate;
-
-struct _GsPopularTile
-{
- GtkButton parent;
- GsPopularTilePrivate *priv;
-};
+#define GS_TYPE_POPULAR_TILE (gs_popular_tile_get_type ())
-struct _GsPopularTileClass
-{
- GtkButtonClass parent_class;
-};
+G_DECLARE_FINAL_TYPE (GsPopularTile, gs_popular_tile, GS, POPULAR_TILE, GtkButton)
-GType gs_popular_tile_get_type (void);
GtkWidget *gs_popular_tile_new (GsApp *app);
GsApp *gs_popular_tile_get_app (GsPopularTile *tile);
void gs_popular_tile_set_app (GsPopularTile *tile,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]