[libgd/wip/rishi/main-box: 3/7] main-icon-view: Drop the priv pointer
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgd/wip/rishi/main-box: 3/7] main-icon-view: Drop the priv pointer
- Date: Fri, 25 Nov 2016 15:56:05 +0000 (UTC)
commit bea8d6dca95bda36bf375a60cf10f79969a7ac1d
Author: Debarshi Ray <debarshir gnome org>
Date: Wed Nov 23 15:18:46 2016 +0100
main-icon-view: Drop the priv pointer
The current GObject recommendation is to use the generated
get_instance_private function instead of a separate priv pointer in the
instance struct. The saves one pointer per class in the heirarchy
multiplied by the number of instances of the type, and the function is
fast enough because it only does pointer arithmetic.
https://bugzilla.gnome.org/show_bug.cgi?id=774709
libgd/gd-main-icon-view.c | 40 +++++++++++++++++++++++++---------------
libgd/gd-main-icon-view.h | 2 --
2 files changed, 25 insertions(+), 17 deletions(-)
---
diff --git a/libgd/gd-main-icon-view.c b/libgd/gd-main-icon-view.c
index 744f05d..bff4d15 100644
--- a/libgd/gd-main-icon-view.c
+++ b/libgd/gd-main-icon-view.c
@@ -61,34 +61,37 @@ get_source_row (GdkDragContext *context)
static void
set_attributes_from_model (GdMainIconView *self)
{
+ GdMainIconViewPrivate *priv;
GtkTreeModel *model = gtk_icon_view_get_model (GTK_ICON_VIEW (self));
GtkCellLayout *layout = GTK_CELL_LAYOUT (self);
GType icon_gtype;
+ priv = gd_main_icon_view_get_instance_private (self);
+
if (!model)
return;
- gtk_cell_layout_clear_attributes (layout, self->priv->pixbuf_cell);
- gtk_cell_layout_clear_attributes (layout, self->priv->text_cell);
+ gtk_cell_layout_clear_attributes (layout, priv->pixbuf_cell);
+ gtk_cell_layout_clear_attributes (layout, priv->text_cell);
- gtk_cell_layout_add_attribute (layout, self->priv->pixbuf_cell,
+ gtk_cell_layout_add_attribute (layout, priv->pixbuf_cell,
"active", GD_MAIN_COLUMN_SELECTED);
- gtk_cell_layout_add_attribute (layout, self->priv->pixbuf_cell,
+ gtk_cell_layout_add_attribute (layout, priv->pixbuf_cell,
"pulse", GD_MAIN_COLUMN_PULSE);
icon_gtype = gtk_tree_model_get_column_type (model, GD_MAIN_COLUMN_ICON);
if (icon_gtype == GDK_TYPE_PIXBUF)
- gtk_cell_layout_add_attribute (layout, self->priv->pixbuf_cell,
+ gtk_cell_layout_add_attribute (layout, priv->pixbuf_cell,
"pixbuf", GD_MAIN_COLUMN_ICON);
else if (icon_gtype == CAIRO_GOBJECT_TYPE_SURFACE)
- gtk_cell_layout_add_attribute (layout, self->priv->pixbuf_cell,
+ gtk_cell_layout_add_attribute (layout, priv->pixbuf_cell,
"surface", GD_MAIN_COLUMN_ICON);
else
g_assert_not_reached ();
- gtk_cell_layout_add_attribute (layout, self->priv->text_cell,
+ gtk_cell_layout_add_attribute (layout, priv->text_cell,
"text", GD_MAIN_COLUMN_PRIMARY_TEXT);
- gtk_cell_layout_add_attribute (layout, self->priv->text_cell,
+ gtk_cell_layout_add_attribute (layout, priv->text_cell,
"line-two", GD_MAIN_COLUMN_SECONDARY_TEXT);
}
@@ -100,12 +103,15 @@ gd_main_icon_view_drag_data_get (GtkWidget *widget,
guint time)
{
GdMainIconView *self = GD_MAIN_ICON_VIEW (widget);
+ GdMainIconViewPrivate *priv;
GtkTreeModel *model = gtk_icon_view_get_model (GTK_ICON_VIEW (self));
+ priv = gd_main_icon_view_get_instance_private (self);
+
if (info != 0)
return;
- _gd_main_view_generic_dnd_common (model, self->priv->selection_mode,
+ _gd_main_view_generic_dnd_common (model, priv->selection_mode,
get_source_row (drag_context), data);
GTK_WIDGET_CLASS (gd_main_icon_view_parent_class)->drag_data_get (widget, drag_context,
@@ -116,11 +122,14 @@ static void
gd_main_icon_view_constructed (GObject *obj)
{
GdMainIconView *self = GD_MAIN_ICON_VIEW (obj);
+ GdMainIconViewPrivate *priv;
GtkCellRenderer *cell;
const GtkTargetEntry targets[] = {
{ (char *) "text/uri-list", GTK_TARGET_OTHER_APP, 0 }
};
+ priv = gd_main_icon_view_get_instance_private (self);
+
G_OBJECT_CLASS (gd_main_icon_view_parent_class)->constructed (obj);
gtk_widget_set_hexpand (GTK_WIDGET (self), TRUE);
@@ -132,14 +141,14 @@ gd_main_icon_view_constructed (GObject *obj)
"margin", VIEW_MARGIN,
NULL);
- self->priv->pixbuf_cell = cell = gd_toggle_pixbuf_renderer_new ();
+ priv->pixbuf_cell = cell = gd_toggle_pixbuf_renderer_new ();
g_object_set (cell,
"xalign", 0.5,
"yalign", 0.5,
NULL);
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (self), cell, FALSE);
- self->priv->text_cell = cell = gd_two_lines_renderer_new ();
+ priv->text_cell = cell = gd_two_lines_renderer_new ();
g_object_set (cell,
"xalign", 0.5,
"alignment", PANGO_ALIGN_CENTER,
@@ -358,8 +367,6 @@ gd_main_icon_view_class_init (GdMainIconViewClass *klass)
static void
gd_main_icon_view_init (GdMainIconView *self)
{
- self->priv = gd_main_icon_view_get_instance_private (self);
-
g_signal_connect (self, "notify::model",
G_CALLBACK (set_attributes_from_model), NULL);
}
@@ -377,10 +384,13 @@ gd_main_icon_view_set_selection_mode (GdMainViewGeneric *mv,
gboolean selection_mode)
{
GdMainIconView *self = GD_MAIN_ICON_VIEW (mv);
+ GdMainIconViewPrivate *priv;
+
+ priv = gd_main_icon_view_get_instance_private (self);
- self->priv->selection_mode = selection_mode;
+ priv->selection_mode = selection_mode;
- g_object_set (self->priv->pixbuf_cell,
+ g_object_set (priv->pixbuf_cell,
"toggle-visible", selection_mode,
NULL);
gtk_widget_queue_draw (GTK_WIDGET (self));
diff --git a/libgd/gd-main-icon-view.h b/libgd/gd-main-icon-view.h
index 7370b2a..c2d1c22 100644
--- a/libgd/gd-main-icon-view.h
+++ b/libgd/gd-main-icon-view.h
@@ -56,8 +56,6 @@ typedef struct _GdMainIconViewPrivate GdMainIconViewPrivate;
struct _GdMainIconView
{
GtkIconView parent;
-
- GdMainIconViewPrivate *priv;
};
struct _GdMainIconViewClass
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]