Commit 061f2528 authored by Christian Persch's avatar Christian Persch Committed by Christian Persch
Browse files

Use a priv variable when accessing priv multiple times in the same

2006-05-02  Christian Persch  <chpe@cvs.gnome.org>

	* gtk/gtkpagesetupunixdialog.c:
	* gtk/gtkprintcontext.c:
	* gtk/gtkprinter.c:
	* gtk/gtkprinteroptionwidget.c:
	* gtk/gtkprintjob.c:
	* gtk/gtkprintoperation-unix.c:
	* gtk/gtkprintoperation.c:
	* gtk/gtkprintunixdialog.c: Use a priv variable when accessing priv
	  multiple times in the same function. Bug #340288.
parent 5d6f77b4
2006-05-02 Christian Persch <chpe@cvs.gnome.org>
* gtk/gtkpagesetupunixdialog.c:
* gtk/gtkprintcontext.c:
* gtk/gtkprinter.c:
* gtk/gtkprinteroptionwidget.c:
* gtk/gtkprintjob.c:
* gtk/gtkprintoperation-unix.c:
* gtk/gtkprintoperation.c:
* gtk/gtkprintunixdialog.c: Use a priv variable when accessing priv
multiple times in the same function. Bug #340288.
2006-05-02 Michael Natterer <mitch@imendio.com>
* gtk/gtklabel.c (gtk_label_set_line_wrap): added note about the
......
2006-05-02 Christian Persch <chpe@cvs.gnome.org>
* gtk/gtkpagesetupunixdialog.c:
* gtk/gtkprintcontext.c:
* gtk/gtkprinter.c:
* gtk/gtkprinteroptionwidget.c:
* gtk/gtkprintjob.c:
* gtk/gtkprintoperation-unix.c:
* gtk/gtkprintoperation.c:
* gtk/gtkprintunixdialog.c: Use a priv variable when accessing priv
multiple times in the same function. Bug #340288.
2006-05-02 Michael Natterer <mitch@imendio.com>
* gtk/gtklabel.c (gtk_label_set_line_wrap): added note about the
......
This diff is collapsed.
......@@ -83,14 +83,15 @@ gtk_print_context_class_init (GtkPrintContextClass *class)
GtkPrintContext *
_gtk_print_context_new (GtkPrintOperation *op)
{
GtkPrintOperationPrivate *priv = op->priv;
GtkPrintContext *context;
context = g_object_new (GTK_TYPE_PRINT_CONTEXT, NULL);
context->op = op;
context->cr = cairo_create (op->priv->surface);
context->cr = cairo_create (priv->surface);
switch (op->priv->unit)
switch (priv->unit)
{
default:
case GTK_UNIT_PIXEL:
......@@ -99,16 +100,16 @@ _gtk_print_context_new (GtkPrintOperation *op)
context->pixels_per_unit_y = 1.0;
break;
case GTK_UNIT_POINTS:
context->pixels_per_unit_x = op->priv->dpi_x / POINTS_PER_INCH;
context->pixels_per_unit_y = op->priv->dpi_y / POINTS_PER_INCH;
context->pixels_per_unit_x = priv->dpi_x / POINTS_PER_INCH;
context->pixels_per_unit_y = priv->dpi_y / POINTS_PER_INCH;
break;
case GTK_UNIT_INCH:
context->pixels_per_unit_x = op->priv->dpi_x;
context->pixels_per_unit_y = op->priv->dpi_y;
context->pixels_per_unit_x = priv->dpi_x;
context->pixels_per_unit_y = priv->dpi_y;
break;
case GTK_UNIT_MM:
context->pixels_per_unit_x = op->priv->dpi_x / MM_PER_INCH;
context->pixels_per_unit_y = op->priv->dpi_y / MM_PER_INCH;
context->pixels_per_unit_x = priv->dpi_x / MM_PER_INCH;
context->pixels_per_unit_y = priv->dpi_y / MM_PER_INCH;
break;
}
cairo_scale (context->cr,
......@@ -118,7 +119,7 @@ _gtk_print_context_new (GtkPrintOperation *op)
context->fontmap = pango_cairo_font_map_new ();
/* We use the unit-scaled resolution, as we still want fonts given in points to work */
pango_cairo_font_map_set_resolution (PANGO_CAIRO_FONT_MAP (context->fontmap),
op->priv->dpi_y / context->pixels_per_unit_y);
priv->dpi_y / context->pixels_per_unit_y);
return context;
}
......@@ -126,6 +127,7 @@ _gtk_print_context_new (GtkPrintOperation *op)
void
_gtk_print_context_rotate_according_to_orientation (GtkPrintContext *context)
{
GtkPrintOperationPrivate *priv = context->op->priv;
cairo_t *cr = context->cr;
cairo_matrix_t matrix;
GtkPaperSize *paper_size;
......@@ -134,9 +136,9 @@ _gtk_print_context_rotate_according_to_orientation (GtkPrintContext *context)
paper_size = gtk_page_setup_get_paper_size (context->page_setup);
width = gtk_paper_size_get_width (paper_size, GTK_UNIT_INCH);
width = width * context->op->priv->dpi_x / context->pixels_per_unit_x;
width = width * priv->dpi_x / context->pixels_per_unit_x;
height = gtk_paper_size_get_height (paper_size, GTK_UNIT_INCH);
height = height * context->op->priv->dpi_y / context->pixels_per_unit_y;
height = height * priv->dpi_y / context->pixels_per_unit_y;
switch (gtk_page_setup_get_orientation (context->page_setup))
{
......@@ -173,18 +175,21 @@ _gtk_print_context_rotate_according_to_orientation (GtkPrintContext *context)
void
_gtk_print_context_translate_into_margin (GtkPrintContext *context)
{
GtkPrintOperationPrivate *priv;
gdouble left, top;
g_return_if_fail (GTK_IS_PRINT_CONTEXT (context));
priv = context->op->priv;
/* We do it this way to also handle GTK_UNIT_PIXELS */
left = gtk_page_setup_get_left_margin (context->page_setup, GTK_UNIT_INCH);
top = gtk_page_setup_get_top_margin (context->page_setup, GTK_UNIT_INCH);
cairo_translate (context->cr,
left * context->op->priv->dpi_x / context->pixels_per_unit_x,
top * context->op->priv->dpi_y / context->pixels_per_unit_y);
left * priv->dpi_x / context->pixels_per_unit_x,
top * priv->dpi_y / context->pixels_per_unit_y);
}
void
......@@ -254,17 +259,20 @@ gtk_print_context_get_page_setup (GtkPrintContext *context)
gdouble
gtk_print_context_get_width (GtkPrintContext *context)
{
GtkPrintOperationPrivate *priv;
gdouble width;
g_return_val_if_fail (GTK_IS_PRINT_CONTEXT (context), 0);
if (context->op->priv->use_full_page)
priv = context->op->priv;
if (priv->use_full_page)
width = gtk_page_setup_get_paper_width (context->page_setup, GTK_UNIT_INCH);
else
width = gtk_page_setup_get_page_width (context->page_setup, GTK_UNIT_INCH);
/* Really dpi_x? What about landscape? what does dpi_x mean in that case? */
return width * context->op->priv->dpi_x / context->pixels_per_unit_x;
return width * priv->dpi_x / context->pixels_per_unit_x;
}
/**
......@@ -280,17 +288,20 @@ gtk_print_context_get_width (GtkPrintContext *context)
gdouble
gtk_print_context_get_height (GtkPrintContext *context)
{
GtkPrintOperationPrivate *priv;
gdouble height;
g_return_val_if_fail (GTK_IS_PRINT_CONTEXT (context), 0);
if (context->op->priv->use_full_page)
priv = context->op->priv;
if (priv->use_full_page)
height = gtk_page_setup_get_paper_height (context->page_setup, GTK_UNIT_INCH);
else
height = gtk_page_setup_get_page_height (context->page_setup, GTK_UNIT_INCH);
/* Really dpi_x? What about landscape? what does dpi_x mean in that case? */
return height * context->op->priv->dpi_y / context->pixels_per_unit_y;
return height * priv->dpi_y / context->pixels_per_unit_y;
}
/**
......
......@@ -186,36 +186,36 @@ gtk_printer_class_init (GtkPrinterClass *class)
static void
gtk_printer_init (GtkPrinter *printer)
{
printer->priv = GTK_PRINTER_GET_PRIVATE (printer);
GtkPrinterPrivate *priv;
printer->priv->name = NULL;
printer->priv->location = NULL;
printer->priv->description = NULL;
printer->priv->icon_name = NULL;
priv = printer->priv = GTK_PRINTER_GET_PRIVATE (printer);
printer->priv->is_active = TRUE;
printer->priv->is_new = TRUE;
printer->priv->has_details = FALSE;
priv->name = NULL;
priv->location = NULL;
priv->description = NULL;
priv->icon_name = NULL;
printer->priv->state_message = NULL;
printer->priv->job_count = 0;
priv->is_active = TRUE;
priv->is_new = TRUE;
priv->has_details = FALSE;
priv->state_message = NULL;
priv->job_count = 0;
}
static void
gtk_printer_finalize (GObject *object)
{
g_return_if_fail (object != NULL);
GtkPrinter *printer = GTK_PRINTER (object);
GtkPrinterPrivate *priv = printer->priv;
g_free (printer->priv->name);
g_free (printer->priv->location);
g_free (printer->priv->description);
g_free (printer->priv->state_message);
g_free (printer->priv->icon_name);
g_free (priv->name);
g_free (priv->location);
g_free (priv->description);
g_free (priv->state_message);
g_free (priv->icon_name);
if (G_OBJECT_CLASS (gtk_printer_parent_class)->finalize)
G_OBJECT_CLASS (gtk_printer_parent_class)->finalize (object);
G_OBJECT_CLASS (gtk_printer_parent_class)->finalize (object);
}
static void
......@@ -225,19 +225,20 @@ gtk_printer_set_property (GObject *object,
GParamSpec *pspec)
{
GtkPrinter *printer = GTK_PRINTER (object);
GtkPrinterPrivate *priv = printer->priv;
switch (prop_id)
{
case PROP_NAME:
printer->priv->name = g_value_dup_string (value);
priv->name = g_value_dup_string (value);
break;
case PROP_BACKEND:
printer->priv->backend = GTK_PRINT_BACKEND (g_value_get_object (value));
priv->backend = GTK_PRINT_BACKEND (g_value_get_object (value));
break;
case PROP_IS_VIRTUAL:
printer->priv->is_virtual = g_value_get_boolean (value);
priv->is_virtual = g_value_get_boolean (value);
break;
default:
......@@ -253,38 +254,39 @@ gtk_printer_get_property (GObject *object,
GParamSpec *pspec)
{
GtkPrinter *printer = GTK_PRINTER (object);
GtkPrinterPrivate *priv = printer->priv;
switch (prop_id)
{
case PROP_NAME:
if (printer->priv->name)
g_value_set_string (value, printer->priv->name);
if (priv->name)
g_value_set_string (value, priv->name);
else
g_value_set_string (value, "");
break;
case PROP_BACKEND:
g_value_set_object (value, printer->priv->backend);
g_value_set_object (value, priv->backend);
break;
case PROP_STATE_MESSAGE:
if (printer->priv->state_message)
g_value_set_string (value, printer->priv->state_message);
if (priv->state_message)
g_value_set_string (value, priv->state_message);
else
g_value_set_string (value, "");
break;
case PROP_LOCATION:
if (printer->priv->location)
g_value_set_string (value, printer->priv->location);
if (priv->location)
g_value_set_string (value, priv->location);
else
g_value_set_string (value, "");
break;
case PROP_ICON_NAME:
if (printer->priv->icon_name)
g_value_set_string (value, printer->priv->icon_name);
if (priv->icon_name)
g_value_set_string (value, priv->icon_name);
else
g_value_set_string (value, "");
break;
case PROP_JOB_COUNT:
g_value_set_int (value, printer->priv->job_count);
g_value_set_int (value, priv->job_count);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
......@@ -388,13 +390,17 @@ gboolean
gtk_printer_set_description (GtkPrinter *printer,
const gchar *description)
{
GtkPrinterPrivate *priv;
g_return_val_if_fail (GTK_IS_PRINTER (printer), FALSE);
if (safe_strcmp (printer->priv->description, description) == 0)
priv = printer->priv;
if (safe_strcmp (priv->description, description) == 0)
return FALSE;
g_free (printer->priv->description);
printer->priv->description = g_strdup (description);
g_free (priv->description);
priv->description = g_strdup (description);
return TRUE;
}
......@@ -422,13 +428,17 @@ gboolean
gtk_printer_set_state_message (GtkPrinter *printer,
const gchar *message)
{
GtkPrinterPrivate *priv;
g_return_val_if_fail (GTK_IS_PRINTER (printer), FALSE);
if (safe_strcmp (printer->priv->state_message, message) == 0)
priv = printer->priv;
if (safe_strcmp (priv->state_message, message) == 0)
return FALSE;
g_free (printer->priv->state_message);
printer->priv->state_message = g_strdup (message);
g_free (priv->state_message);
priv->state_message = g_strdup (message);
g_object_notify (G_OBJECT (printer), "state-message");
return TRUE;
......@@ -456,13 +466,17 @@ gboolean
gtk_printer_set_location (GtkPrinter *printer,
const gchar *location)
{
GtkPrinterPrivate *priv;
g_return_val_if_fail (GTK_IS_PRINTER (printer), FALSE);
if (safe_strcmp (printer->priv->location, location) == 0)
priv = printer->priv;
if (safe_strcmp (priv->location, location) == 0)
return FALSE;
g_free (printer->priv->location);
printer->priv->location = g_strdup (location);
g_free (priv->location);
priv->location = g_strdup (location);
g_object_notify (G_OBJECT (printer), "location");
return TRUE;
......@@ -490,10 +504,14 @@ void
gtk_printer_set_icon_name (GtkPrinter *printer,
const gchar *icon)
{
GtkPrinterPrivate *priv;
g_return_if_fail (GTK_IS_PRINTER (printer));
g_free (printer->priv->icon_name);
printer->priv->icon_name = g_strdup (icon);
priv = printer->priv;
g_free (priv->icon_name);
priv->icon_name = g_strdup (icon);
g_object_notify (G_OBJECT (printer), "icon-name");
}
......@@ -519,12 +537,16 @@ gboolean
gtk_printer_set_job_count (GtkPrinter *printer,
gint count)
{
GtkPrinterPrivate *priv;
g_return_val_if_fail (GTK_IS_PRINTER (printer), FALSE);
if (printer->priv->job_count == count)
priv = printer->priv;
if (priv->job_count == count)
return FALSE;
printer->priv->job_count = count;
priv->job_count = count;
g_object_notify (G_OBJECT (printer), "job-count");
......
......@@ -134,18 +134,16 @@ gtk_printer_option_widget_init (GtkPrinterOptionWidget *widget)
static void
gtk_printer_option_widget_finalize (GObject *object)
{
GtkPrinterOptionWidget *widget;
GtkPrinterOptionWidget *widget = GTK_PRINTER_OPTION_WIDGET (object);
GtkPrinterOptionWidgetPrivate *priv = widget->priv;
widget = GTK_PRINTER_OPTION_WIDGET (object);
if (widget->priv->source)
if (priv->source)
{
g_object_unref (widget->priv->source);
widget->priv->source = NULL;
g_object_unref (priv->source);
priv->source = NULL;
}
if (G_OBJECT_CLASS (gtk_printer_option_widget_parent_class)->finalize)
G_OBJECT_CLASS (gtk_printer_option_widget_parent_class)->finalize (object);
G_OBJECT_CLASS (gtk_printer_option_widget_parent_class)->finalize (object);
}
static void
......@@ -175,14 +173,13 @@ gtk_printer_option_widget_get_property (GObject *object,
GValue *value,
GParamSpec *pspec)
{
GtkPrinterOptionWidget *widget;
widget = GTK_PRINTER_OPTION_WIDGET (object);
GtkPrinterOptionWidget *widget = GTK_PRINTER_OPTION_WIDGET (object);
GtkPrinterOptionWidgetPrivate *priv = widget->priv;
switch (prop_id)
{
case PROP_SOURCE:
g_value_set_object (value, widget->priv->source);
g_value_set_object (value, priv->source);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
......@@ -231,20 +228,22 @@ void
gtk_printer_option_widget_set_source (GtkPrinterOptionWidget *widget,
GtkPrinterOption *source)
{
GtkPrinterOptionWidgetPrivate *priv = widget->priv;
if (source)
g_object_ref (source);
if (widget->priv->source)
if (priv->source)
{
g_signal_handler_disconnect (widget->priv->source,
widget->priv->source_changed_handler);
g_object_unref (widget->priv->source);
g_signal_handler_disconnect (priv->source,
priv->source_changed_handler);
g_object_unref (priv->source);
}
widget->priv->source = source;
priv->source = source;
if (source)
widget->priv->source_changed_handler =
priv->source_changed_handler =
g_signal_connect (source, "changed", G_CALLBACK (source_changed_cb), widget);
construct_widgets (widget);
......@@ -351,42 +350,44 @@ combo_box_get (GtkWidget *combo)
static void
deconstruct_widgets (GtkPrinterOptionWidget *widget)
{
if (widget->priv->check)
GtkPrinterOptionWidgetPrivate *priv = widget->priv;
if (priv->check)
{
gtk_widget_destroy (widget->priv->check);
widget->priv->check = NULL;
gtk_widget_destroy (priv->check);
priv->check = NULL;
}
if (widget->priv->combo)
if (priv->combo)
{
gtk_widget_destroy (widget->priv->combo);
widget->priv->combo = NULL;
gtk_widget_destroy (priv->combo);
priv->combo = NULL;
}
if (widget->priv->entry)
if (priv->entry)
{
gtk_widget_destroy (widget->priv->entry);
widget->priv->entry = NULL;
gtk_widget_destroy (priv->entry);
priv->entry = NULL;
}
/* make sure entry and combo are destroyed first */
/* as we use the two of them to create the filechooser */
if (widget->priv->filechooser)
if (priv->filechooser)
{
gtk_widget_destroy (widget->priv->filechooser);
widget->priv->filechooser = NULL;
gtk_widget_destroy (priv->filechooser);
priv->filechooser = NULL;
}
if (widget->priv->image)
if (priv->image)
{
gtk_widget_destroy (widget->priv->image);
widget->priv->image = NULL;
gtk_widget_destroy (priv->image);
priv->image = NULL;
}
if (widget->priv->label)
if (priv->label)
{
gtk_widget_destroy (widget->priv->label);
widget->priv->label = NULL;
gtk_widget_destroy (priv->label);
priv->label = NULL;
}
}
......@@ -394,10 +395,12 @@ static void
check_toggled_cb (GtkToggleButton *toggle_button,
GtkPrinterOptionWidget *widget)
{
g_signal_handler_block (widget->priv->source, widget->priv->source_changed_handler);
gtk_printer_option_set_boolean (widget->priv->source,
GtkPrinterOptionWidgetPrivate *priv = widget->priv;
g_signal_handler_block (priv->source, priv->source_changed_handler);
gtk_printer_option_set_boolean (priv->source,
gtk_toggle_button_get_active (toggle_button));
g_signal_handler_unblock (widget->priv->source, widget->priv->source_changed_handler);
g_signal_handler_unblock (priv->source, priv->source_changed_handler);
emit_changed (widget);
}
......@@ -405,26 +408,27 @@ static void
filesave_changed_cb (GtkWidget *w,
GtkPrinterOptionWidget *widget)
{
GtkPrinterOptionWidgetPrivate *priv = widget->priv;
char *value;
char *directory;
const char *file;
/* combine the value of the chooser with the value of the entry */
g_signal_handler_block (widget->priv->source, widget->priv->source_changed_handler);
g_signal_handler_block (priv->source, priv->source_changed_handler);
/* TODO: how do we support nonlocal file systems? */
directory = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (widget->priv->combo));
file = gtk_entry_get_text (GTK_ENTRY (widget->priv->entry));
directory = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (priv->combo));
file = gtk_entry_get_text (GTK_ENTRY (priv->entry));
value = g_build_filename (directory, file, NULL);
if (value)
gtk_printer_option_set (widget->priv->source, value);
gtk_printer_option_set (priv->source, value);
g_free (directory);
g_free (value);
g_signal_handler_unblock (widget->priv->source, widget->priv->source_changed_handler);
g_signal_handler_unblock (priv->source, priv->source_changed_handler);
emit_changed (widget);
}
......@@ -432,14 +436,15 @@ static void
combo_changed_cb (GtkWidget *combo,
GtkPrinterOptionWidget *widget)
{
GtkPrinterOptionWidgetPrivate *priv = widget->priv;
char *value;
g_signal_handler_block (widget->priv->source, widget->priv->source_changed_handler);
g_signal_handler_block (priv->source, priv->source_changed_handler);
value = combo_box_get (combo);
if (value)
gtk_printer_option_set (widget->priv->source, value);
gtk_printer_option_set (priv->source, value);
g_free (value);
g_signal_handler_unblock (widget->priv->source, widget->priv->source_changed_handler);
g_signal_handler_unblock (priv->source, priv->source_changed_handler);
emit_changed (widget);
}
......@@ -447,13 +452,14 @@ static void
entry_changed_cb (GtkWidget *entry,
GtkPrinterOptionWidget *widget)
{
GtkPrinterOptionWidgetPrivate *priv = widget->priv;
const char *value;
g_signal_handler_block (widget->priv->source, widget->priv->source_changed_handler);
g_signal_handler_block (priv->source, priv->source_changed_handler);
value = gtk_entry_get_text (GTK_ENTRY (entry));
if (value)
gtk_printer_option_set (widget->priv->source, value);
g_signal_handler_unblock (widget->priv->source, widget->priv->source_changed_handler);
gtk_printer_option_set (priv->source, value);
g_signal_handler_unblock (priv->source, priv->source_changed_handler);
emit_changed (widget);
}
......@@ -461,56 +467,57 @@ entry_changed_cb (GtkWidget *entry,
static void