[baobab/wip/vala: 13/23] BaobabChart: more cleanup
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [baobab/wip/vala: 13/23] BaobabChart: more cleanup
- Date: Fri, 6 Jan 2012 01:42:31 +0000 (UTC)
commit f8b5b3799b1da33019ca93757480999b402206e4
Author: Ryan Lortie <desrt desrt ca>
Date: Thu Jan 5 14:26:59 2012 -0500
BaobabChart: more cleanup
Clean up use of ->priv and fix type macro for consistency.
src/baobab-chart.c | 238 ++++++++++++++++++++---------------------------
src/baobab-chart.h | 12 +-
src/baobab-ringschart.c | 2 +-
src/baobab-treemap.c | 2 +-
4 files changed, 111 insertions(+), 143 deletions(-)
---
diff --git a/src/baobab-chart.c b/src/baobab-chart.c
index a0c46b1..3b5b1f0 100644
--- a/src/baobab-chart.c
+++ b/src/baobab-chart.c
@@ -39,10 +39,6 @@
#include <gtk/gtk.h>
#include "baobab-chart.h"
-#define BAOBAB_CHART_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
- BAOBAB_CHART_TYPE, \
- BaobabChartPrivate))
-
#define SNAPSHOT_DEF_FILENAME_FORMAT "%s-disk-usage"
G_DEFINE_ABSTRACT_TYPE (BaobabChart, baobab_chart, GTK_TYPE_WIDGET);
@@ -243,26 +239,23 @@ baobab_chart_class_init (BaobabChartClass *class)
static void
baobab_chart_init (BaobabChart *chart)
{
- BaobabChartPrivate *priv;
-
- priv = BAOBAB_CHART_GET_PRIVATE (chart);
- chart->priv = priv;
-
- priv->model = NULL;
- priv->max_depth = BAOBAB_CHART_MAX_DEPTH;
- priv->name_column = 0;
- priv->size_column = 0;
- priv->info_column = 0;
- priv->percentage_column = 0;
- priv->valid_column = 0;
- priv->button_pressed = FALSE;
- priv->is_frozen = FALSE;
- priv->memento = NULL;
- priv->root = NULL;
-
- priv->first_item = NULL;
- priv->last_item = NULL;
- priv->highlighted_item = NULL;
+ chart->priv = G_TYPE_INSTANCE_GET_PRIVATE (chart, BAOBAB_TYPE_CHART, BaobabChartPrivate);
+
+ chart->priv->model = NULL;
+ chart->priv->max_depth = BAOBAB_CHART_MAX_DEPTH;
+ chart->priv->name_column = 0;
+ chart->priv->size_column = 0;
+ chart->priv->info_column = 0;
+ chart->priv->percentage_column = 0;
+ chart->priv->valid_column = 0;
+ chart->priv->button_pressed = FALSE;
+ chart->priv->is_frozen = FALSE;
+ chart->priv->memento = NULL;
+ chart->priv->root = NULL;
+
+ chart->priv->first_item = NULL;
+ chart->priv->last_item = NULL;
+ chart->priv->highlighted_item = NULL;
}
static void
@@ -371,7 +364,7 @@ baobab_chart_set_property (GObject *object,
const GValue *value,
GParamSpec *pspec)
{
- BaobabChart *chart = BAOBAB_CHART (object);;
+ BaobabChart *chart = BAOBAB_CHART (object);
switch (prop_id)
{
@@ -396,20 +389,18 @@ baobab_chart_get_property (GObject *object,
GValue *value,
GParamSpec *pspec)
{
- BaobabChartPrivate *priv;
-
- priv = BAOBAB_CHART (object)->priv;
+ BaobabChart *chart = BAOBAB_CHART (object);
switch (prop_id)
{
case PROP_MAX_DEPTH:
- g_value_set_int (value, priv->max_depth);
+ g_value_set_int (value, chart->priv->max_depth);
break;
case PROP_MODEL:
- g_value_set_object (value, priv->model);
+ g_value_set_object (value, chart->priv->model);
break;
case PROP_ROOT:
- g_value_set_object (value, priv->root);
+ g_value_set_object (value, chart->priv->root);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -424,18 +415,15 @@ baobab_chart_add_item (BaobabChart *chart,
gdouble rel_size,
GtkTreeIter iter)
{
- BaobabChartPrivate *priv;
BaobabChartItem *item;
gchar *name;
guint64 size;
- priv = BAOBAB_CHART_GET_PRIVATE (chart);
-
- gtk_tree_model_get (priv->model, &iter,
- priv->name_column, &name, -1);
- gtk_tree_model_get (priv->model, &iter,
- priv->size_column, &size, -1);
+ gtk_tree_model_get (chart->priv->model, &iter,
+ chart->priv->name_column, &name,
+ chart->priv->size_column, &size,
+ -1);
item = g_new (BaobabChartItem, 1);
item->name = name;
@@ -452,22 +440,19 @@ baobab_chart_add_item (BaobabChart *chart,
item->parent = NULL;
item->data = NULL;
- priv->last_item = g_list_prepend (priv->last_item, item);
+ chart->priv->last_item = g_list_prepend (chart->priv->last_item, item);
- return priv->last_item;
+ return chart->priv->last_item;
}
static void
baobab_chart_free_items (BaobabChart *chart)
{
- BaobabChartPrivate *priv;
BaobabChartItem *item;
GList *node;
GList *next;
- priv = BAOBAB_CHART_GET_PRIVATE (chart);
-
- node = priv->first_item;
+ node = chart->priv->first_item;
while (node != NULL)
{
next = node->next;
@@ -486,9 +471,9 @@ baobab_chart_free_items (BaobabChart *chart)
node = next;
}
- priv->first_item = NULL;
- priv->last_item = NULL;
- priv->highlighted_item = NULL;
+ chart->priv->first_item = NULL;
+ chart->priv->last_item = NULL;
+ chart->priv->highlighted_item = NULL;
}
static void
@@ -583,11 +568,9 @@ static void
baobab_chart_draw_chart (BaobabChart *chart,
cairo_t *cr)
{
- BaobabChartPrivate *priv;
BaobabChartClass *class;
GList *node;
- priv = BAOBAB_CHART_GET_PRIVATE (chart);
class = BAOBAB_CHART_GET_CLASS (chart);
/* call pre-draw abstract method */
@@ -596,7 +579,7 @@ baobab_chart_draw_chart (BaobabChart *chart,
cairo_save (cr);
- node = priv->first_item;
+ node = chart->priv->first_item;
while (node != NULL)
{
BaobabChartItem *item;
@@ -607,11 +590,11 @@ baobab_chart_draw_chart (BaobabChart *chart,
if (gdk_cairo_get_clip_rectangle (cr, &clip) &&
(item->visible) &&
(gdk_rectangle_intersect (&clip, &item->rect, NULL)) &&
- (item->depth <= priv->max_depth))
+ (item->depth <= chart->priv->max_depth))
{
gboolean highlighted;
- highlighted = (node == priv->highlighted_item);
+ highlighted = (node == chart->priv->highlighted_item);
class->draw_item (chart, cr, item, highlighted);
}
@@ -630,34 +613,31 @@ static void
baobab_chart_update_draw (BaobabChart* chart,
GtkTreePath *path)
{
- BaobabChartPrivate *priv;
GtkTreePath *root_path = NULL;
gint root_depth, node_depth;
if (!gtk_widget_get_realized ( GTK_WIDGET (chart)))
return;
- priv = BAOBAB_CHART (chart)->priv;
-
- if (priv->root != NULL)
+ if (chart->priv->root != NULL)
{
- root_path = gtk_tree_row_reference_get_path (priv->root);
+ root_path = gtk_tree_row_reference_get_path (chart->priv->root);
if (root_path == NULL)
{
- gtk_tree_row_reference_free (priv->root);
- priv->root = NULL;
+ gtk_tree_row_reference_free (chart->priv->root);
+ chart->priv->root = NULL;
}
}
- if (priv->root == NULL)
+ if (chart->priv->root == NULL)
root_path = gtk_tree_path_new_first ();
root_depth = gtk_tree_path_get_depth (root_path);
node_depth = gtk_tree_path_get_depth (path);
- if (((node_depth-root_depth)<=priv->max_depth)&&
+ if (((node_depth-root_depth)<=chart->priv->max_depth)&&
((gtk_tree_path_is_ancestor (root_path, path))||
(gtk_tree_path_compare (root_path, path) == 0)))
{
@@ -671,55 +651,63 @@ static void
baobab_chart_row_changed (GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
- gpointer data)
+ gpointer user_data)
{
- g_return_if_fail (BAOBAB_IS_CHART (data));
+ BaobabChart *chart = user_data;
+
+ g_return_if_fail (BAOBAB_IS_CHART (chart));
g_return_if_fail (path != NULL || iter != NULL);
- BAOBAB_CHART_GET_PRIVATE (data)->model_changed = TRUE;
+ chart->priv->model_changed = TRUE;
- baobab_chart_update_draw (BAOBAB_CHART (data), path);
+ baobab_chart_update_draw (chart, path);
}
static void
baobab_chart_row_inserted (GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
- gpointer data)
+ gpointer user_data)
{
- g_return_if_fail (BAOBAB_IS_CHART (data));
+ BaobabChart *chart = user_data;
+
+ g_return_if_fail (BAOBAB_IS_CHART (chart));
g_return_if_fail (path != NULL || iter != NULL);
- BAOBAB_CHART_GET_PRIVATE (data)->model_changed = TRUE;
+ chart->priv->model_changed = TRUE;
- baobab_chart_update_draw (BAOBAB_CHART (data), path);
+ baobab_chart_update_draw (chart, path);
}
static void
baobab_chart_row_has_child_toggled (GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
- gpointer data)
+ gpointer user_data)
{
- g_return_if_fail (BAOBAB_IS_CHART (data));
+ BaobabChart *chart = user_data;
+
+ g_return_if_fail (BAOBAB_IS_CHART (chart));
g_return_if_fail (path != NULL || iter != NULL);
- BAOBAB_CHART_GET_PRIVATE (data)->model_changed = TRUE;
+ chart->priv->model_changed = TRUE;
- baobab_chart_update_draw (BAOBAB_CHART (data), path);
+ baobab_chart_update_draw (chart, path);
}
static void
baobab_chart_row_deleted (GtkTreeModel *model,
GtkTreePath *path,
- gpointer data)
+ gpointer user_data)
{
- g_return_if_fail (BAOBAB_IS_CHART (data));
+ BaobabChart *chart = user_data;
+
+ g_return_if_fail (BAOBAB_IS_CHART (chart));
g_return_if_fail (path != NULL);
- BAOBAB_CHART_GET_PRIVATE (data)->model_changed = TRUE;
+ chart->priv->model_changed = TRUE;
- baobab_chart_update_draw (BAOBAB_CHART (data), path);
+ baobab_chart_update_draw (chart, path);
}
@@ -728,14 +716,16 @@ baobab_chart_rows_reordered (GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
gint *new_order,
- gpointer data)
+ gpointer user_data)
{
- g_return_if_fail (BAOBAB_IS_CHART (data));
+ BaobabChart *chart = user_data;
+
+ g_return_if_fail (BAOBAB_IS_CHART (chart));
g_return_if_fail (path != NULL || iter != NULL);
- BAOBAB_CHART_GET_PRIVATE (data)->model_changed = TRUE;
+ chart->priv->model_changed = TRUE;
- baobab_chart_update_draw (BAOBAB_CHART (data), path);
+ baobab_chart_update_draw (chart, path);
}
@@ -744,24 +734,22 @@ baobab_chart_draw (GtkWidget *widget,
cairo_t *cr)
{
BaobabChart *chart = BAOBAB_CHART (widget);
- BaobabChartPrivate *priv;
- priv = BAOBAB_CHART (chart)->priv;
/* the columns are not set we paint nothing */
- if (priv->name_column == priv->percentage_column)
+ if (chart->priv->name_column == chart->priv->percentage_column)
return FALSE;
/* there is no model we can not paint */
- if ((priv->is_frozen) || (priv->model == NULL))
+ if ((chart->priv->is_frozen) || (chart->priv->model == NULL))
{
- if (priv->memento != NULL)
+ if (chart->priv->memento != NULL)
{
gint w, h, aw, ah;
gdouble p, sx, sy;
- w = cairo_image_surface_get_width (priv->memento);
- h = cairo_image_surface_get_height (priv->memento);
+ w = cairo_image_surface_get_width (chart->priv->memento);
+ h = cairo_image_surface_get_height (chart->priv->memento);
aw = gtk_widget_get_allocated_width (widget);
ah = gtk_widget_get_allocated_height (widget);
@@ -778,9 +766,7 @@ baobab_chart_draw (GtkWidget *widget,
cairo_scale (cr, p, p);
}
- cairo_set_source_surface (cr,
- priv->memento,
- 0, 0);
+ cairo_set_source_surface (cr, chart->priv->memento, 0, 0);
cairo_paint (cr);
}
}
@@ -791,18 +777,17 @@ baobab_chart_draw (GtkWidget *widget,
cairo_set_source_rgb (cr, 1, 1, 1);
cairo_fill_preserve (cr);
- if (priv->root != NULL)
- root_path = gtk_tree_row_reference_get_path (priv->root);
+ if (chart->priv->root != NULL)
+ root_path = gtk_tree_row_reference_get_path (chart->priv->root);
if (root_path == NULL)
{
root_path = gtk_tree_path_new_first ();
- priv->root = NULL;
+ chart->priv->root = NULL;
}
/* Check if tree model was modified in any way */
- if ((priv->model_changed) ||
- (priv->first_item == NULL))
+ if ((chart->priv->model_changed) || (chart->priv->first_item == NULL))
{
baobab_chart_get_items (chart, root_path);
}
@@ -811,8 +796,8 @@ baobab_chart_draw (GtkWidget *widget,
GtkTreePath *current_path;
/* Check if root was changed */
- current_path = gtk_tree_model_get_path (priv->model,
- &((BaobabChartItem*) priv->first_item->data)->iter);
+ current_path = gtk_tree_model_get_path (chart->priv->model,
+ &((BaobabChartItem*) chart->priv->first_item->data)->iter);
if (gtk_tree_path_compare (root_path, current_path) != 0)
baobab_chart_get_items (chart, root_path);
@@ -1112,16 +1097,14 @@ baobab_chart_query_tooltip (GtkWidget *widget,
GtkTooltip *tooltip,
gpointer user_data)
{
- BaobabChartPrivate *priv;
+ BaobabChart *chart = BAOBAB_CHART (widget);
BaobabChartItem *item;
char *markup;
- priv = BAOBAB_CHART_GET_PRIVATE (widget);
-
- if (priv->highlighted_item == NULL)
+ if (chart->priv->highlighted_item == NULL)
return FALSE;
- item = (BaobabChartItem *) priv->highlighted_item->data;
+ item = (BaobabChartItem *) chart->priv->highlighted_item->data;
if ( (item->name == NULL) || (item->size == NULL) )
return FALSE;
@@ -1165,7 +1148,7 @@ baobab_chart_get_pixbuf (BaobabChart *chart)
BaobabChart *
baobab_chart_new (void)
{
- return g_object_new (BAOBAB_CHART_TYPE, NULL);
+ return g_object_new (BAOBAB_TYPE_CHART, NULL);
}
/**
@@ -1213,26 +1196,23 @@ baobab_chart_set_model_with_columns (BaobabChart *chart,
guint valid_column,
GtkTreePath *root)
{
- BaobabChartPrivate *priv;
-
g_return_if_fail (BAOBAB_IS_CHART (chart));
g_return_if_fail (GTK_IS_TREE_MODEL (model));
- priv = BAOBAB_CHART (chart)->priv;
baobab_chart_set_model (chart, model);
if (root != NULL)
{
- priv->root = gtk_tree_row_reference_new (model, root);
+ chart->priv->root = gtk_tree_row_reference_new (model, root);
g_object_notify (G_OBJECT (chart), "root");
}
- priv->name_column = name_column;
- priv->size_column = size_column;
- priv->info_column = info_column;
- priv->percentage_column = percentage_column;
- priv->valid_column = valid_column;
+ chart->priv->name_column = name_column;
+ chart->priv->size_column = size_column;
+ chart->priv->info_column = info_column;
+ chart->priv->percentage_column = percentage_column;
+ chart->priv->valid_column = valid_column;
}
/**
@@ -1554,8 +1534,6 @@ baobab_chart_zoom_out (BaobabChart *chart)
void
baobab_chart_move_up_root (BaobabChart *chart)
{
- BaobabChartPrivate *priv;
-
GtkTreeIter parent_iter;
GtkTreePath *path;
GtkTreeIter root_iter;
@@ -1565,29 +1543,27 @@ baobab_chart_move_up_root (BaobabChart *chart)
g_return_if_fail (BAOBAB_IS_CHART (chart));
- priv = BAOBAB_CHART_GET_PRIVATE (chart);
-
- if (priv->root == NULL)
+ if (chart->priv->root == NULL)
return;
- path = gtk_tree_row_reference_get_path (priv->root);
+ path = gtk_tree_row_reference_get_path (chart->priv->root);
if (path != NULL)
- gtk_tree_model_get_iter (priv->model, &root_iter, path);
+ gtk_tree_model_get_iter (chart->priv->model, &root_iter, path);
else
return;
- if (gtk_tree_model_iter_parent (priv->model, &parent_iter, &root_iter))
+ if (gtk_tree_model_iter_parent (chart->priv->model, &parent_iter, &root_iter))
{
- gtk_tree_model_get (priv->model, &parent_iter, priv->valid_column,
+ gtk_tree_model_get (chart->priv->model, &parent_iter, chart->priv->valid_column,
&valid, -1);
if (valid == -1)
return;
- gtk_tree_row_reference_free (priv->root);
- parent_path = gtk_tree_model_get_path (priv->model, &parent_iter);
- priv->root = gtk_tree_row_reference_new (priv->model, parent_path);
+ gtk_tree_row_reference_free (chart->priv->root);
+ parent_path = gtk_tree_model_get_path (chart->priv->model, &parent_iter);
+ chart->priv->root = gtk_tree_row_reference_new (chart->priv->model, parent_path);
gtk_tree_path_free (parent_path);
g_signal_emit (BAOBAB_CHART (chart),
@@ -1722,8 +1698,6 @@ baobab_chart_save_snapshot (BaobabChart *chart)
gboolean
baobab_chart_is_frozen (BaobabChart *chart)
{
- BaobabChartPrivate *priv;
-
g_return_val_if_fail (BAOBAB_IS_CHART (chart), FALSE);
return chart->priv->is_frozen;
@@ -1741,13 +1715,9 @@ baobab_chart_is_frozen (BaobabChart *chart)
BaobabChartItem *
baobab_chart_get_highlighted_item (BaobabChart *chart)
{
- BaobabChartPrivate *priv;
-
g_return_val_if_fail (BAOBAB_IS_CHART (chart), NULL);
- priv = BAOBAB_CHART_GET_PRIVATE (chart);
- return (priv->highlighted_item ?
- (BaobabChartItem *) priv->highlighted_item->data : NULL);
+ return chart->priv->highlighted_item ? (BaobabChartItem *) chart->priv->highlighted_item->data : NULL;
}
/**
@@ -1786,16 +1756,14 @@ baobab_chart_can_zoom_in (BaobabChart *chart)
gboolean
baobab_chart_can_zoom_out (BaobabChart *chart)
{
- BaobabChartPrivate *priv;
BaobabChartClass *class;
g_return_val_if_fail (BAOBAB_IS_CHART (chart), FALSE);
- priv = BAOBAB_CHART (chart)->priv;
class = BAOBAB_CHART_GET_CLASS (chart);
if (class->can_zoom_out != NULL)
return class->can_zoom_out (chart) > 0;
else
- return (priv->max_depth < BAOBAB_CHART_MAX_DEPTH);
+ return (chart->priv->max_depth < BAOBAB_CHART_MAX_DEPTH);
}
diff --git a/src/baobab-chart.h b/src/baobab-chart.h
index 59ffd0a..f5fe632 100644
--- a/src/baobab-chart.h
+++ b/src/baobab-chart.h
@@ -38,15 +38,15 @@
G_BEGIN_DECLS
-#define BAOBAB_CHART_TYPE (baobab_chart_get_type ())
+#define BAOBAB_TYPE_CHART (baobab_chart_get_type ())
#define BAOBAB_CHART(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), \
- BAOBAB_CHART_TYPE, BaobabChart))
+ BAOBAB_TYPE_CHART, BaobabChart))
#define BAOBAB_CHART_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), \
- BAOBAB_CHART_TYPE, BaobabChartClass))
-#define BAOBAB_IS_CHART(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), BAOBAB_CHART_TYPE))
-#define BAOBAB_IS_CHART_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), BAOBAB_CHART_TYPE))
+ BAOBAB_TYPE_CHART, BaobabChartClass))
+#define BAOBAB_IS_CHART(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), BAOBAB_TYPE_CHART))
+#define BAOBAB_IS_CHART_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), BAOBAB_TYPE_CHART))
#define BAOBAB_CHART_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), \
- BAOBAB_CHART_TYPE, BaobabChartClass))
+ BAOBAB_TYPE_CHART, BaobabChartClass))
typedef struct _BaobabChart BaobabChart;
typedef struct _BaobabChartClass BaobabChartClass;
diff --git a/src/baobab-ringschart.c b/src/baobab-ringschart.c
index ab604f5..4e093da 100644
--- a/src/baobab-ringschart.c
+++ b/src/baobab-ringschart.c
@@ -53,7 +53,7 @@
#define SUBFOLDER_TIP_PADDING 3
-G_DEFINE_TYPE (BaobabRingschart, baobab_ringschart, BAOBAB_CHART_TYPE);
+G_DEFINE_TYPE (BaobabRingschart, baobab_ringschart, BAOBAB_TYPE_CHART);
typedef struct _BaobabRingschartItem BaobabRingschartItem;
diff --git a/src/baobab-treemap.c b/src/baobab-treemap.c
index 30fd446..bae122b 100644
--- a/src/baobab-treemap.c
+++ b/src/baobab-treemap.c
@@ -48,7 +48,7 @@
#define ITEM_SHOW_LABEL TRUE
-G_DEFINE_TYPE (BaobabTreemap, baobab_treemap, BAOBAB_CHART_TYPE);
+G_DEFINE_TYPE (BaobabTreemap, baobab_treemap, BAOBAB_TYPE_CHART);
struct _BaobabTreemapPrivate
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]