[gnome-software] app tile: Port to G_DECLARE_FINAL_TYPE macro
- From: Kalev Lember <klember src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] app tile: Port to G_DECLARE_FINAL_TYPE macro
- Date: Mon, 7 Sep 2015 17:37:17 +0000 (UTC)
commit 54a7e533599ffb310f7dd13696ea5496b7baddcd
Author: Kalev Lember <klember redhat com>
Date: Mon Sep 7 16:24:05 2015 +0200
app tile: Port to G_DECLARE_FINAL_TYPE macro
src/gs-app-tile.c | 94 +++++++++++++++++++++++------------------------------
src/gs-app-tile.h | 23 +------------
2 files changed, 43 insertions(+), 74 deletions(-)
---
diff --git a/src/gs-app-tile.c b/src/gs-app-tile.c
index 4898f26..9f72ff9 100644
--- a/src/gs-app-tile.c
+++ b/src/gs-app-tile.c
@@ -29,8 +29,10 @@
#include "gs-star-widget.h"
#include "gs-utils.h"
-struct _GsAppTilePrivate
+struct _GsAppTile
{
+ GtkButton parent_instance;
+
GsApp *app;
GtkWidget *image;
GtkWidget *name;
@@ -40,17 +42,14 @@ struct _GsAppTilePrivate
GtkWidget *stars;
};
-G_DEFINE_TYPE_WITH_PRIVATE (GsAppTile, gs_app_tile, GTK_TYPE_BUTTON)
+G_DEFINE_TYPE (GsAppTile, gs_app_tile, GTK_TYPE_BUTTON)
GsApp *
gs_app_tile_get_app (GsAppTile *tile)
{
- GsAppTilePrivate *priv;
-
g_return_val_if_fail (GS_IS_APP_TILE (tile), NULL);
- priv = gs_app_tile_get_instance_private (tile);
- return priv->app;
+ return tile->app;
}
static gboolean
@@ -58,21 +57,19 @@ app_state_changed_idle (gpointer user_data)
{
GsAppTile *tile = GS_APP_TILE (user_data);
AtkObject *accessible;
- GsAppTilePrivate *priv;
GtkWidget *label;
gboolean installed;
_cleanup_free_ gchar *name = NULL;
- priv = gs_app_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_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 */
@@ -81,7 +78,7 @@ app_state_changed_idle (gpointer user_data)
case AS_APP_STATE_INSTALLING:
installed = TRUE;
name = g_strdup_printf ("%s (%s)",
- gs_app_get_name (priv->app),
+ gs_app_get_name (tile->app),
_("Installing"));
/* TRANSLATORS: this is the small blue label on the tile
* that tells the user the application is being installed */
@@ -90,7 +87,7 @@ app_state_changed_idle (gpointer user_data)
case AS_APP_STATE_REMOVING:
installed = TRUE;
name = g_strdup_printf ("%s (%s)",
- gs_app_get_name (priv->app),
+ gs_app_get_name (tile->app),
_("Removing"));
/* TRANSLATORS: this is the small blue label on the tile
* that tells the user the application is being removed */
@@ -100,15 +97,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);
@@ -124,58 +121,52 @@ app_state_changed (GsApp *app, GParamSpec *pspec, GsAppTile *tile)
void
gs_app_tile_set_app (GsAppTile *tile, GsApp *app)
{
- GsAppTilePrivate *priv;
const gchar *summary;
g_return_if_fail (GS_IS_APP_TILE (tile));
g_return_if_fail (GS_IS_APP (app) || app == NULL);
- priv = gs_app_tile_get_instance_private (tile);
-
- gtk_image_clear (GTK_IMAGE (priv->image));
- gtk_image_set_pixel_size (GTK_IMAGE (priv->image), 64);
+ gtk_image_clear (GTK_IMAGE (tile->image));
+ gtk_image_set_pixel_size (GTK_IMAGE (tile->image), 64);
- 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);
- if (gs_app_get_rating_kind (priv->app) == GS_APP_RATING_KIND_USER) {
- gs_star_widget_set_rating (GS_STAR_WIDGET (priv->stars),
+ tile->app = g_object_ref (app);
+ 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 (app));
- gtk_label_set_label (GTK_LABEL (priv->name), gs_app_get_name (app));
+ gs_image_set_from_pixbuf (GTK_IMAGE (tile->image), gs_app_get_pixbuf (app));
+ gtk_label_set_label (GTK_LABEL (tile->name), gs_app_get_name (app));
summary = gs_app_get_summary (app);
- gtk_label_set_label (GTK_LABEL (priv->summary), summary);
- gtk_widget_set_visible (priv->summary, summary && summary[0]);
+ gtk_label_set_label (GTK_LABEL (tile->summary), summary);
+ gtk_widget_set_visible (tile->summary, summary && summary[0]);
}
static void
gs_app_tile_destroy (GtkWidget *widget)
{
GsAppTile *tile = GS_APP_TILE (widget);
- GsAppTilePrivate *priv;
- priv = gs_app_tile_get_instance_private (tile);
-
- if (priv->app)
- g_signal_handlers_disconnect_by_func (priv->app, app_state_changed, tile);
- g_clear_object (&priv->app);
+ if (tile->app)
+ g_signal_handlers_disconnect_by_func (tile->app, app_state_changed, tile);
+ g_clear_object (&tile->app);
GTK_WIDGET_CLASS (gs_app_tile_parent_class)->destroy (widget);
}
@@ -183,12 +174,9 @@ gs_app_tile_destroy (GtkWidget *widget)
static void
gs_app_tile_init (GsAppTile *tile)
{
- GsAppTilePrivate *priv;
-
gtk_widget_set_has_window (GTK_WIDGET (tile), FALSE);
gtk_widget_init_template (GTK_WIDGET (tile));
- priv = gs_app_tile_get_instance_private (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
@@ -200,12 +188,12 @@ gs_app_tile_class_init (GsAppTileClass *klass)
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/Software/app-tile.ui");
- gtk_widget_class_bind_template_child_private (widget_class, GsAppTile, image);
- gtk_widget_class_bind_template_child_private (widget_class, GsAppTile, name);
- gtk_widget_class_bind_template_child_private (widget_class, GsAppTile, summary);
- gtk_widget_class_bind_template_child_private (widget_class, GsAppTile, eventbox);
- gtk_widget_class_bind_template_child_private (widget_class, GsAppTile, stack);
- gtk_widget_class_bind_template_child_private (widget_class, GsAppTile, stars);
+ gtk_widget_class_bind_template_child (widget_class, GsAppTile, image);
+ gtk_widget_class_bind_template_child (widget_class, GsAppTile, name);
+ gtk_widget_class_bind_template_child (widget_class, GsAppTile, summary);
+ gtk_widget_class_bind_template_child (widget_class, GsAppTile, eventbox);
+ gtk_widget_class_bind_template_child (widget_class, GsAppTile, stack);
+ gtk_widget_class_bind_template_child (widget_class, GsAppTile, stars);
}
GtkWidget *
diff --git a/src/gs-app-tile.h b/src/gs-app-tile.h
index 92df174..e089275 100644
--- a/src/gs-app-tile.h
+++ b/src/gs-app-tile.h
@@ -26,31 +26,12 @@
#include "gs-app.h"
-#define GS_TYPE_APP_TILE (gs_app_tile_get_type())
-#define GS_APP_TILE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GS_TYPE_APP_TILE, GsAppTile))
-#define GS_APP_TILE_CLASS(cls) (G_TYPE_CHECK_CLASS_CAST((cls), GS_TYPE_APP_TILE, GsAppTileClass))
-#define GS_IS_APP_TILE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GS_TYPE_APP_TILE))
-#define GS_IS_APP_TILE_CLASS(cls) (G_TYPE_CHECK_CLASS_TYPE((cls), GS_TYPE_APP_TILE))
-#define GS_APP_TILE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GS_TYPE_APP_TILE, GsAppTileClass))
-
G_BEGIN_DECLS
-typedef struct _GsAppTile GsAppTile;
-typedef struct _GsAppTileClass GsAppTileClass;
-typedef struct _GsAppTilePrivate GsAppTilePrivate;
-
-struct _GsAppTile
-{
- GtkButton parent;
- GsAppTilePrivate *priv;
-};
+#define GS_TYPE_APP_TILE (gs_app_tile_get_type ())
-struct _GsAppTileClass
-{
- GtkButtonClass parent_class;
-};
+G_DECLARE_FINAL_TYPE (GsAppTile, gs_app_tile, GS, APP_TILE, GtkButton)
-GType gs_app_tile_get_type (void);
GtkWidget *gs_app_tile_new (GsApp *app);
GsApp *gs_app_tile_get_app (GsAppTile *tile);
void gs_app_tile_set_app (GsAppTile *tile,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]