planner r937 - in trunk: . data/ui libplanner src
- From: mvdpot svn gnome org
- To: svn-commits-list gnome org
- Subject: planner r937 - in trunk: . data/ui libplanner src
- Date: Wed, 5 Nov 2008 19:54:02 +0000 (UTC)
Author: mvdpot
Date: Wed Nov 5 19:54:02 2008
New Revision: 937
URL: http://svn.gnome.org/viewvc/planner?rev=937&view=rev
Log:
2008-11-05 Maurice van der Pot <griffon26 kfk4ever com>
* libplanner/mrp-parser.c: Removed unused function.
* libplanner/mrp-task-manager.c: Commented out unused functions.
* configure.in:
* data/ui/main-window.ui:
* src/planner-gantt-print.c:
* src/planner-gantt-print.h:
* src/planner-gantt-view.c (gantt_view_print):
* src/planner-print-dialog.c:
* src/planner-print-dialog.h:
* src/planner-print-job.c:
* src/planner-print-job.h:
* src/planner-resource-view.c (resource_view_print),
(resource_view_cost_data_func):
* src/planner-table-print-sheet.c:
* src/planner-table-print-sheet.h:
* src/planner-task-view.c (task_view_print),
(task_view_print_cleanup):
* src/planner-usage-view.c (usage_view_print):
* src/planner-view.c (planner_view_print):
* src/planner-view.h:
* src/planner-window.c: Rewrote printing to use the GTK printing API. Thanks
to Francisco Moraes for an initial patch. Also fixed a few memory leaks.
Modified:
trunk/ChangeLog
trunk/configure.in
trunk/data/ui/main-window.ui
trunk/libplanner/mrp-parser.c
trunk/libplanner/mrp-task-manager.c
trunk/src/planner-gantt-print.c
trunk/src/planner-gantt-print.h
trunk/src/planner-gantt-view.c
trunk/src/planner-print-dialog.c
trunk/src/planner-print-dialog.h
trunk/src/planner-print-job.c
trunk/src/planner-print-job.h
trunk/src/planner-resource-view.c
trunk/src/planner-table-print-sheet.c
trunk/src/planner-table-print-sheet.h
trunk/src/planner-task-view.c
trunk/src/planner-usage-view.c
trunk/src/planner-view.c
trunk/src/planner-view.h
trunk/src/planner-window.c
Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in (original)
+++ trunk/configure.in Wed Nov 5 19:54:02 2008
@@ -70,7 +70,6 @@
LIBGNOMECANVAS_REQUIRED=2.10.0
LIBGNOMEUI_REQUIRED=2.10.0
LIBGLADE_REQUIRED=2.3.0
-LIBGNOMEPRINTUI_REQUIRED=2.10.0
GNOME_VFS_REQUIRED=2.10.0
GCONF_REQUIRED=2.10.0
LIBXML_REQUIRED=2.6.27
@@ -118,7 +117,6 @@
libgnomecanvas-2.0 >= $LIBGNOMECANVAS_REQUIRED
libgnomeui-2.0 >= $LIBGNOMEUI_REQUIRED
libglade-2.0 >= $LIBGLADE_REQUIRED
- libgnomeprintui-2.2 >= $LIBGNOMEPRINTUI_REQUIRED
gnome-vfs-2.0 >= $GNOME_VFS_REQUIRED
gconf-2.0 >= $GCONF_REQUIRED
])
Modified: trunk/data/ui/main-window.ui
==============================================================================
--- trunk/data/ui/main-window.ui (original)
+++ trunk/data/ui/main-window.ui Wed Nov 5 19:54:02 2008
@@ -13,6 +13,7 @@
<placeholder name="Export placeholder"/>
</menu>
<separator/>
+ <menuitem action="FilePageSetup"/>
<menuitem action="FilePrint"/>
<menuitem action="FilePrintPreview"/>
<separator/>
Modified: trunk/libplanner/mrp-parser.c
==============================================================================
--- trunk/libplanner/mrp-parser.c (original)
+++ trunk/libplanner/mrp-parser.c Wed Nov 5 19:54:02 2008
@@ -96,8 +96,6 @@
static void mpp_xml_set_task_sched (xmlNodePtr node,
const gchar *prop,
MrpTaskSched sched);
-static xmlNodePtr mpp_xml_search_child (xmlNodePtr node,
- const gchar *name);
static gchar *mpp_property_to_string (MrpObject *object,
MrpProperty *property);
@@ -1179,31 +1177,6 @@
* XML helpers.
*/
-
-/* Search a child by name, if needed go down the tree to find it.
- */
-static xmlNodePtr
-mpp_xml_search_child (xmlNodePtr node, const gchar *name)
-{
- xmlNodePtr ret;
- xmlNodePtr child;
-
- child = node->children;
- while (child != NULL) {
- if (!strcmp (child->name, name))
- return child;
- child = child->next;
- }
- child = node->children;
- while (child != NULL) {
- ret = mpp_xml_search_child (child, name);
- if (ret != NULL)
- return ret;
- child = child->next;
- }
- return NULL;
-}
-
static void
mpp_xml_set_date (xmlNodePtr node, const gchar *prop, mrptime time)
{
Modified: trunk/libplanner/mrp-task-manager.c
==============================================================================
--- trunk/libplanner/mrp-task-manager.c (original)
+++ trunk/libplanner/mrp-task-manager.c Wed Nov 5 19:54:02 2008
@@ -679,6 +679,8 @@
/* ------------------------------------------------------------------------ */
+/* Functions have not been used since revision 417 */
+#if 0
/* Get the ancestor of task_a, that has the same parent as an ancestor or
* task_b.
@@ -771,6 +773,7 @@
*output = g_list_prepend (*output, task);
}
}
+#endif
static void
dump_task_node (MrpTask *task)
Modified: trunk/src/planner-gantt-print.c
==============================================================================
--- trunk/src/planner-gantt-print.c (original)
+++ trunk/src/planner-gantt-print.c Wed Nov 5 19:54:02 2008
@@ -28,7 +28,6 @@
#include <libplanner/mrp-task.h>
#include <libplanner/mrp-resource.h>
#include <glib/gi18n.h>
-#include <libgnomeprint/gnome-print.h>
#include "planner-print-job.h"
#include "planner-format.h"
#include "planner-gantt-model.h"
@@ -92,8 +91,8 @@
GHashTable *task_start_coords;
GHashTable *task_finish_coords;
- GnomeFont *font;
- GnomeFont *font_bold;
+ PangoFontDescription *font;
+ PangoFontDescription *font_bold;
GList *tasks;
@@ -115,6 +114,8 @@
mrptime start;
mrptime finish;
+ mrptime second_column_start;
+
Page *pages;
};
@@ -173,14 +174,14 @@
{
gdouble x, y;
- gnome_print_setlinewidth (data->job->pc, 0);
+ cairo_set_line_width (data->job->cr, THIN_LINE_WIDTH);
planner_print_job_set_font_bold (data->job);
- y = data->header_height + data->row_height / 4;
+ y = data->header_height;
planner_print_job_moveto (data->job, data->tree_x1, y);
planner_print_job_lineto (data->job, data->tree_x2, y);
- gnome_print_stroke (data->job->pc);
+ cairo_stroke (data->job->cr);
x = data->name_x1 + data->job->x_pad;
y = data->row_height;
@@ -188,16 +189,16 @@
planner_print_job_show_clipped (data->job,
x, y,
_("Name"),
- data->name_x1, 0,
- data->name_x2 - data->job->x_pad / 2, y + data->row_height);
+ data->name_x1 + data->job->x_pad, y - data->row_height,
+ data->name_x2 - data->job->x_pad, y + data->row_height);
x = data->work_x1 + data->job->x_pad;
planner_print_job_show_clipped (data->job,
x, y,
_("Work"),
- data->work_x1, 0,
- data->work_x2 - data->job->x_pad / 2, y + data->row_height);
+ data->work_x1 + data->job->x_pad, 0,
+ data->work_x2 - data->job->x_pad, y + data->row_height);
planner_print_job_set_font_regular (data->job);
}
@@ -225,7 +226,7 @@
to = g_list_nth (tasks, last);
i = 1;
- gnome_print_setlinewidth (data->job->pc, 0);
+ cairo_set_line_width (data->job->cr, THIN_LINE_WIDTH);
while (l && l != to) {
ptask = l->data;
@@ -249,10 +250,10 @@
}
planner_print_job_show_clipped (data->job,
- x, y,
+ x, y - data->row_height / 4,
str,
- data->name_x1, 0,
- data->name_x2 - data->job->x_pad / 2, y + data->row_height);
+ data->name_x1 + data->job->x_pad, y - data->row_height,
+ data->name_x2 - data->job->x_pad, y);
g_free (str);
@@ -260,23 +261,21 @@
str = planner_format_duration (data->project, work);
planner_print_job_show_clipped (data->job,
- x, y,
+ x, y - data->row_height / 4,
str,
- data->work_x1, 0,
- data->work_x2 - data->job->x_pad / 2, y + data->row_height);
+ data->work_x1 + data->job->x_pad, y - data->row_height,
+ data->work_x2 - data->job->x_pad, y);
g_free (str);
- y += data->row_height / 4;
-
planner_print_job_moveto (data->job, 0, y);
planner_print_job_lineto (data->job, data->tree_x2, y);
- gnome_print_stroke (data->job->pc);
+ cairo_stroke (data->job->cr);
i++;
l = l->next;
}
- gnome_print_setlinewidth (data->job->pc, 1);
+ cairo_set_line_width (data->job->cr, 1);
}
static void
@@ -293,26 +292,28 @@
gchar *str;
y1 = 0;
- y2 = data->header_height / 2 + data->row_height / 4;
- y3 = data->header_height + data->row_height / 4;
-
- gnome_print_setlinewidth (data->job->pc, 0);
+ y2 = data->header_height / 2;
+ y3 = data->header_height;
+
+ cairo_set_line_width (data->job->cr, THIN_LINE_WIDTH);
planner_print_job_moveto (data->job, x1, y2);
planner_print_job_lineto (data->job, x2, y2);
- gnome_print_stroke (data->job->pc);
+ cairo_stroke (data->job->cr);
planner_print_job_moveto (data->job, x1, y3);
planner_print_job_lineto (data->job, x2, y3);
- gnome_print_stroke (data->job->pc);
+ cairo_stroke (data->job->cr);
/* Major scale. */
x = x1;
- y = data->row_height;
-
+ y = y2 - data->row_height / 4;
+
+ planner_print_job_set_font_regular (data->job);
+
t = mrp_time_align_prev (start, data->major_unit);
- width = (mrp_time_align_next (t, data->major_unit) - t) / data->f - data->job->x_pad / 2;
-
+ width = (mrp_time_align_next (t, data->major_unit) - t) / data->f;
+
while (t <= finish) {
x = x1 + (t - start) / data->f;
@@ -320,7 +321,7 @@
if (x > x1) {
planner_print_job_moveto (data->job, x, y1);
planner_print_job_lineto (data->job, x, y2);
- gnome_print_stroke (data->job->pc);
+ cairo_stroke (data->job->cr);
}
str = planner_scale_format_time (t, data->major_unit, data->major_format);
@@ -339,10 +340,10 @@
/* Minor scale. */
x = x1;
- y = 2 * data->row_height;
+ y = y3 - data->row_height / 4;
t = mrp_time_align_prev (start, data->minor_unit);
- width = (mrp_time_align_next (t, data->minor_unit) - t) / data->f - data->job->x_pad / 2;
+ width = (mrp_time_align_next (t, data->minor_unit) - t) / data->f;
while (t <= finish) {
x = x1 + (t - start) / data->f;
@@ -351,7 +352,7 @@
if (x > x1) {
planner_print_job_moveto (data->job, x, y2);
planner_print_job_lineto (data->job, x, y3);
- gnome_print_stroke (data->job->pc);
+ cairo_stroke (data->job->cr);
}
str = planner_scale_format_time (t, data->minor_unit, data->minor_format);
@@ -458,25 +459,28 @@
static void
gantt_print_task (PlannerGanttPrintData *data, Element *element)
{
- gnome_print_newpath (data->job->pc);
+ cairo_new_path (data->job->cr);
planner_print_job_moveto (data->job, element->x1, element->y1);
planner_print_job_lineto (data->job, element->x2, element->y1);
planner_print_job_lineto (data->job, element->x2, element->y2);
planner_print_job_lineto (data->job, element->x1, element->y2);
- gnome_print_closepath (data->job->pc);
+ cairo_close_path (data->job->cr);
- gnome_print_gsave (data->job->pc);
+ cairo_save (data->job->cr);
if (data->show_critical && element->is_critical) {
- gnome_print_setrgbcolor (data->job->pc, 205/255.0, 92/255.0, 92/255.0);
+ cairo_set_source_rgb (data->job->cr, 205/255.0, 92/255.0, 92/255.0);
} else {
- gnome_print_setrgbcolor (data->job->pc, 235/255.0, 235/255.0, 235/255.0);
+ cairo_set_source_rgb (data->job->cr, 235/255.0, 235/255.0, 235/255.0);
}
- gnome_print_fill (data->job->pc);
- gnome_print_grestore (data->job->pc);
+ cairo_fill_preserve (data->job->cr);
+ cairo_set_line_width (data->job->cr, THIN_LINE_WIDTH);
+ cairo_set_source_rgb (data->job->cr, 0, 0, 0);
+ cairo_stroke (data->job->cr);
+
+ cairo_restore (data->job->cr);
- gnome_print_stroke (data->job->pc);
/* Percent complete. */
if (element->x_complete > 0) {
@@ -484,19 +488,19 @@
pad = (element->y2 - element->y1) * 0.25;
- gnome_print_gsave (data->job->pc);
+ cairo_save (data->job->cr);
- gnome_print_newpath (data->job->pc);
+ cairo_new_path (data->job->cr);
planner_print_job_moveto (data->job, element->x1, element->y1 + pad);
planner_print_job_lineto (data->job, element->x_complete, element->y1 + pad);
planner_print_job_lineto (data->job, element->x_complete, element->y2 - pad);
planner_print_job_lineto (data->job, element->x1, element->y2 - pad);
- gnome_print_closepath (data->job->pc);
+ cairo_close_path (data->job->cr);
- gnome_print_setrgbcolor (data->job->pc, 135/255.0, 135/255.0, 135/255.0);
- gnome_print_fill (data->job->pc);
+ cairo_set_source_rgb (data->job->cr, 135/255.0, 135/255.0, 135/255.0);
+ cairo_fill (data->job->cr);
- gnome_print_grestore (data->job->pc);
+ cairo_restore (data->job->cr);
}
}
@@ -545,19 +549,18 @@
if (units != 100) {
name_unit = g_strdup_printf ("%s [%i]", name, units);
+ g_free (name);
} else {
- name_unit = g_strdup_printf ("%s", name);
+ name_unit = name;
}
if (!text) { /* First resource */
- text = g_strdup_printf ("%s", name_unit);
- g_free (name_unit);
+ text = name_unit;
continue;
}
tmp_str = g_strdup_printf ("%s, %s", text, name_unit);
-
- g_free (name);
+
g_free (text);
g_free (name_unit);
@@ -565,8 +568,7 @@
}
if (text && width) {
- w = gnome_font_get_width_utf8 (
- planner_print_job_get_font (data->job), text);
+ w = planner_print_job_get_extents(data->job, text);
}
if (width) {
@@ -583,20 +585,329 @@
}
void
-planner_gantt_print_do (PlannerGanttPrintData *data)
+planner_gantt_print_do (PlannerGanttPrintData *data, gint page_nr)
{
- GList *relations;
GList *l;
gdouble x1, x2;
+ mrptime t1, t2;
+ Element *element;
+ gint row, col, first_task;
+ Page *page;
+
+ /* Fourth pass, generate pages. */
+ col = page_nr % data->cols_of_pages;
+ row = page_nr / data->cols_of_pages;
+
+ x2 = data->job->width;
+
+ planner_print_job_begin_next_page (data->job);
+
+ if (row == 0) {
+ first_task = 0;
+ } else {
+ first_task = data->tasks_per_page_with_header +
+ data->tasks_per_page_without_header * (row - 1);
+ }
+
+ if (col == 0) {
+ x1 = data->tree_x2;
+ t1 = data->start;
+ t2 = data->second_column_start;
+
+ cairo_set_line_width (data->job->cr, THIN_LINE_WIDTH);
+
+ planner_print_job_moveto (data->job,
+ data->tree_x2,
+ 0);
+ planner_print_job_lineto (data->job,
+ data->tree_x2,
+ data->job->height);
+ cairo_stroke (data->job->cr);
+
+ planner_print_job_moveto (data->job,
+ data->name_x2,
+ 0);
+ planner_print_job_lineto (data->job,
+ data->name_x2,
+ data->job->height);
+ cairo_stroke (data->job->cr);
+
+ print_table_tasks (data,
+ row == 0,
+ data->tasks,
+ first_task);
+ } else {
+ x1 = 0;
+ t1 = data->second_column_start + (col - 1) * data->job->width * data->f;
+ t2 = t1 + data->job->width * data->f;
+ }
+
+ page = GET_PAGE (data, row, col);
+ for (l = page->background_elements; l; l = l->next) {
+ gdouble dashes[] = { 4, 4 };
+
+ element = l->data;
+
+ switch (element->type) {
+ case TIMELINE:
+ cairo_new_path (data->job->cr);
+ cairo_set_source_rgb (data->job->cr, 150/255.0, 150/255.0, 249/255.0);
+
+ cairo_set_dash (data->job->cr, dashes, 2, 0);
+
+ cairo_set_line_width (data->job->cr, 1);
+ planner_print_job_moveto (data->job, element->x1, element->y1);
+ planner_print_job_lineto (data->job, element->x1, element->y2);
+ cairo_stroke (data->job->cr);
+
+ cairo_set_dash (data->job->cr, NULL, 0, 0);
+
+ break;
+ case SHADE:
+ cairo_new_path (data->job->cr);
+ planner_print_job_moveto (data->job, element->x1, element->y1);
+ planner_print_job_lineto (data->job, element->x2, element->y1);
+ planner_print_job_lineto (data->job, element->x2, element->y2);
+ planner_print_job_lineto (data->job, element->x1, element->y2);
+ cairo_close_path (data->job->cr);
+
+ cairo_set_source_rgb (data->job->cr, 249/255.0, 249/255.0, 249/255.0);
+ cairo_fill (data->job->cr);
+
+ cairo_set_line_width (data->job->cr, THIN_LINE_WIDTH);
+ cairo_set_source_rgb (data->job->cr, 150/255.0, 150/255.0, 150/255.0);
+ planner_print_job_moveto (data->job, element->x1, element->y1);
+ planner_print_job_lineto (data->job, element->x1, element->y2);
+ cairo_stroke (data->job->cr);
+ break;
+ default:
+ break;
+ }
+ }
+
+ cairo_set_source_rgb (data->job->cr, 0, 0, 0);
+
+ if (row == 0) {
+ print_time_header (data, x1, x2, t1, t2);
+ if (col == 0) {
+ print_table_header (data);
+ }
+ }
+
+ for (l = page->elements; l; l = l->next) {
+ element = l->data;
+
+ cairo_set_source_rgb (data->job->cr, 0, 0, 0);
+
+ switch (element->type) {
+ case TASK_LEFT:
+ case TASK_RIGHT:
+ case TASK_WHOLE:
+ case TASK_MIDDLE:
+ gantt_print_task (data, element);
+ break;
+ case SUMMARY_LEFT:
+ planner_print_job_moveto (data->job,
+ element->x1,
+ element->y1 + data->summary_thick);
+ planner_print_job_lineto (data->job,
+ element->x1,
+ element->y1 + data->summary_thick + data->summary_height);
+ planner_print_job_lineto (data->job,
+ element->x1 + data->summary_slope,
+ element->y1 + data->summary_thick);
+ cairo_close_path (data->job->cr);
+ cairo_fill (data->job->cr);
+
+ planner_print_job_moveto (data->job,
+ element->x2,
+ element->y1 + 2 * data->summary_thick);
+ planner_print_job_lineto (data->job,
+ element->x1,
+ element->y1 + 2 * data->summary_thick);
+ planner_print_job_lineto (data->job,
+ element->x1,
+ element->y1 + data->summary_thick);
+ planner_print_job_lineto (data->job,
+ element->x2,
+ element->y1 + data->summary_thick);
+ cairo_close_path (data->job->cr);
+ cairo_fill (data->job->cr);
+ break;
+ case SUMMARY_RIGHT:
+ planner_print_job_moveto (data->job,
+ element->x2,
+ element->y1 + data->summary_thick);
+ planner_print_job_lineto (data->job,
+ element->x2,
+ element->y1 + data->summary_thick + data->summary_height);
+ planner_print_job_lineto (data->job,
+ element->x2 - data->summary_slope,
+ element->y1 + data->summary_thick);
+ cairo_close_path (data->job->cr);
+ cairo_fill (data->job->cr);
+
+ planner_print_job_moveto (data->job,
+ element->x2,
+ element->y1 + 2 * data->summary_thick);
+ planner_print_job_lineto (data->job,
+ element->x1,
+ element->y1 + 2 * data->summary_thick);
+ planner_print_job_lineto (data->job,
+ element->x1,
+ element->y1 + data->summary_thick);
+ planner_print_job_lineto (data->job,
+ element->x2,
+ element->y1 + data->summary_thick);
+ cairo_close_path (data->job->cr);
+ cairo_fill (data->job->cr);
+ break;
+ case SUMMARY_WHOLE:
+ planner_print_job_moveto (data->job,
+ element->x1,
+ element->y1 + data->summary_thick);
+ planner_print_job_lineto (data->job,
+ element->x1,
+ element->y1 + data->summary_thick + data->summary_height);
+ planner_print_job_lineto (data->job,
+ element->x1 + data->summary_slope,
+ element->y1 + data->summary_thick);
+ cairo_close_path (data->job->cr);
+ cairo_fill (data->job->cr);
+
+ planner_print_job_moveto (data->job,
+ element->x2,
+ element->y1 + data->summary_thick);
+ planner_print_job_lineto (data->job,
+ element->x2,
+ element->y1 + data->summary_thick + data->summary_height);
+ planner_print_job_lineto (data->job,
+ element->x2 - data->summary_slope,
+ element->y1 + data->summary_thick);
+ cairo_close_path (data->job->cr);
+ cairo_fill (data->job->cr);
+
+ planner_print_job_moveto (data->job,
+ element->x2,
+ element->y1 + 2 * data->summary_thick);
+ planner_print_job_lineto (data->job,
+ element->x1,
+ element->y1 + 2 * data->summary_thick);
+ planner_print_job_lineto (data->job,
+ element->x1,
+ element->y1 + data->summary_thick);
+ planner_print_job_lineto (data->job,
+ element->x2,
+ element->y1 + data->summary_thick);
+ cairo_close_path (data->job->cr);
+ cairo_fill (data->job->cr);
+ break;
+ case SUMMARY_MIDDLE:
+ planner_print_job_moveto (data->job,
+ element->x2,
+ element->y1 + 2 * data->summary_thick);
+ planner_print_job_lineto (data->job,
+ element->x1,
+ element->y1 + 2 * data->summary_thick);
+ planner_print_job_lineto (data->job,
+ element->x1,
+ element->y1 + data->summary_thick);
+ planner_print_job_lineto (data->job,
+ element->x2,
+ element->y1 + data->summary_thick);
+ cairo_close_path (data->job->cr);
+ cairo_fill (data->job->cr);
+ break;
+ case RELATION_ARROW_DOWN:
+ planner_print_job_moveto (data->job,
+ element->x1,
+ element->y1);
+ planner_print_job_lineto (data->job,
+ element->x1 - data->arrow_width,
+ element->y1 - data->arrow_height);
+ planner_print_job_lineto (data->job,
+ element->x1 + data->arrow_width,
+ element->y1 - data->arrow_height);
+ cairo_close_path (data->job->cr);
+ cairo_fill (data->job->cr);
+ break;
+ case RELATION_ARROW_UP:
+ planner_print_job_moveto (data->job,
+ element->x1,
+ element->y1);
+ planner_print_job_lineto (data->job,
+ element->x1 - data->arrow_width,
+ element->y1 + data->arrow_height);
+ planner_print_job_lineto (data->job,
+ element->x1 + data->arrow_width,
+ element->y1 + data->arrow_height);
+ cairo_close_path (data->job->cr);
+ cairo_fill (data->job->cr);
+ break;
+ case RELATION_HORIZ:
+ planner_print_job_moveto (data->job, element->x1, element->y1);
+ planner_print_job_lineto (data->job, element->x2, element->y1);
+ cairo_stroke (data->job->cr);
+ break;
+ case RELATION_VERT:
+ planner_print_job_moveto (data->job, element->x1, element->y1);
+ planner_print_job_lineto (data->job, element->x1, element->y2);
+ cairo_stroke (data->job->cr);
+ break;
+ case MILESTONE:
+ planner_print_job_moveto (data->job,
+ element->x1,
+ element->y1);
+ planner_print_job_lineto (data->job,
+ element->x1 + data->milestone_size,
+ element->y1 + data->milestone_size);
+ planner_print_job_lineto (data->job,
+ element->x1,
+ element->y1 + 2 * data->milestone_size);
+ planner_print_job_lineto (data->job,
+ element->x1 - data->milestone_size,
+ element->y1 + data->milestone_size);
+ cairo_close_path (data->job->cr);
+ cairo_fill (data->job->cr);
+ break;
+ case RESOURCES:
+ planner_print_job_show_clipped (data->job,
+ element->x1,
+ element->y1,
+ element->resources,
+ 0, 0,
+ data->job->width,
+ data->job->height);
+ break;
+ default:
+ break;
+ }
+ }
+
+ planner_print_job_finish_page (data->job, TRUE);
+}
+
+PlannerGanttPrintData *
+planner_gantt_print_data_new (PlannerView *view,
+ PlannerPrintJob *job,
+ GtkTreeView *tree_view,
+ gint level,
+ gboolean show_critical)
+{
+ PlannerGanttPrintData *data;
+ GList *tasks = NULL, *l;
+ gint num_tasks;
+ gdouble max_name_width = 0.0;
+ gdouble ext;
+ GList *relations;
+ gdouble x1;
gdouble y1, y2;
- gint num_tasks;
mrptime t1, t2, t0;
mrptime current_time;
mrptime start, finish;
mrptime complete;
gboolean is_summary;
gboolean is_critical;
- gboolean boundary_overlap = FALSE;
MrpTaskType type;
PrintTask *ptask;
TaskCoord *task_coord;
@@ -610,7 +921,122 @@
MrpCalendar *calendar;
MrpDay *day;
GList *ivals;
- MrpInterval *ival;
+
+ data = g_new0 (PlannerGanttPrintData, 1);
+
+ data->view = view;
+ data->job = job;
+ data->project = planner_window_get_project (view->main_window);
+
+ data->tree_view = tree_view;
+
+ data->show_critical = show_critical;
+ data->level = level;
+
+ /* Note: This looks hackish, but it's more or less the same equation
+ * used for the zoom level in the gantt chart, which actually is
+ * calculated to have a "good feel" :).
+ */
+ data->f = 1.8 / pow (2, level - 19);
+
+ data->major_unit = planner_scale_conf[level].major_unit;
+ data->major_format = planner_scale_conf[level].major_format;
+
+ data->minor_unit = planner_scale_conf[level].minor_unit;
+ data->minor_format = planner_scale_conf[level].minor_format;
+
+ data->task_start_coords = g_hash_table_new_full (NULL, NULL, NULL, g_free);
+ data->task_finish_coords = g_hash_table_new_full (NULL, NULL, NULL, g_free);
+
+ /* Start and finish of the project. */
+ data->start = mrp_project_get_project_start (data->project);
+
+ tasks = gantt_print_get_visible_tasks (data);
+ data->tasks = tasks;
+ num_tasks = g_list_length (tasks);
+
+ data->finish = data->start;
+
+ /* Go through the tasks and get the end time by checking the right-most
+ * resource label we will print.
+ */
+ for (l = tasks; l; l = l->next) {
+ PrintTask *ptask = l->data;
+ MrpTask *task = ptask->task;
+ gchar *name;
+ mrptime finish;
+ gdouble width;
+ gdouble name_width;
+
+ g_object_get (task,
+ "name", &name,
+ "finish", &finish,
+ NULL);
+
+ ext = planner_print_job_get_extents(data->job, name);
+ name_width = ext + ptask->depth * INDENT_FACTOR * data->job->x_pad;
+
+ if (max_name_width < name_width) {
+ max_name_width = name_width;
+ }
+
+ gantt_print_get_allocated_resources_string (data, task, NULL, &width);
+
+ data->finish = MAX (data->finish, finish);/* + width * data->f);*/
+
+ g_free (name);
+ }
+
+ /* TODO: figure out why the width of WW and WORKWO is significant */
+ data->name_x1 = 0;
+ ext = planner_print_job_get_extents (data->job, "WW");
+ data->name_x2 = data->name_x1 + max_name_width + ext;
+
+ data->work_x1 = data->name_x2;
+ ext = planner_print_job_get_extents (data->job, "WORKWO");
+ data->work_x2 = data->work_x1 + ext;
+
+ data->tree_x1 = 0;
+ data->tree_x2 = data->work_x2;
+
+ data->second_column_start = data->start + (data->job->width - (data->tree_x2 - data->tree_x1)) * data->f;
+
+ data->row_height = 2 * planner_print_job_get_font_height (job);
+
+ data->header_height = 2 * data->row_height + data->row_height / 4;
+
+ /* Calculate drawing "constants". */
+ data->summary_height = 0.24 * data->row_height;
+ data->summary_thick = 0.07 * data->row_height;
+ data->summary_slope = 0.22 * data->row_height;
+ data->milestone_size = 0.25 * data->row_height;
+ data->arrow_height = 0.24 * data->row_height;
+ data->arrow_width = 0.11 * data->row_height;
+
+ if (num_tasks > 0) {
+ data->tasks_per_page_without_header = data->job->height / data->row_height;
+ data->tasks_per_page_with_header = (data->job->height - data->header_height) /
+ data->row_height;
+
+ data->cols_of_pages = ceil (((data->finish - data->start) /
+ data->f + data->tree_x2 - data->tree_x1) /
+ data->job->width);
+
+ data->rows_of_pages = ceil ((num_tasks * data->row_height + data->header_height) /
+ (data->job->height - data->row_height));
+
+ if (data->tasks_per_page_without_header * (data->rows_of_pages - 2) +
+ data->tasks_per_page_with_header >= num_tasks) {
+ data->rows_of_pages--;
+ }
+
+ data->cols_of_pages = MAX (1, data->cols_of_pages);
+ data->rows_of_pages = MAX (1, data->rows_of_pages);
+
+ data->pages = g_new0 (Page, data->cols_of_pages * data->rows_of_pages);
+
+
+ }
calendar = mrp_project_get_calendar (data->project);
@@ -659,12 +1085,13 @@
}
d(g_print ("%s: ", name));
+ g_free (name);
col = 0;
t1 = data->start;
- y1 = y0 + data->row_height * (i + 1.5 * 0.25);
- y2 = y1 + 0.75 * data->row_height;
+ y1 = y0 + data->row_height * (i + 0.25);
+ y2 = y1 + 0.5 * data->row_height;
/* Loop through the columns that this task covers. */
@@ -672,7 +1099,7 @@
if (col == 0) {
/* Left-most column has the task tree. */
x0 = data->tree_x2;
- t2 = t1 + (data->job->width - (data->tree_x2 - data->tree_x1)) * data->f;
+ t2 = data->second_column_start;
} else {
x0 = 0;
t2 = t1 + data->job->width * data->f;
@@ -839,7 +1266,7 @@
element->type = RESOURCES;
element->x1 = task_coord->x + data->job->x_pad;
- element->y1 = y0 + data->row_height * (i + 1);
+ element->y1 = y0 + data->row_height * (i + 0.75);
element->resources = str;
@@ -891,10 +1318,10 @@
*/
if ((pre_coord->row == suc_coord->row && pre_coord->y < suc_coord->y) ||
(pre_coord->row < suc_coord->row)) {
- element->y1 = suc_coord->y + 0.75 * data->row_height * 0.5;
+ element->y1 = suc_coord->y + data->row_height * 0.25;
element->type = RELATION_ARROW_DOWN;
} else {
- element->y1 = suc_coord->y + 0.75 * data->row_height * 1.5;
+ element->y1 = suc_coord->y + data->row_height * 0.75;
element->type = RELATION_ARROW_UP;
}
@@ -991,89 +1418,65 @@
t2 = t0 + (data->job->width - x0) * data->f;
/* Loop through the days between t0 and t2. */
- t1 = t0;
+ t1 = mrp_time_align_day(t0);
while (t1 <= t2) {
+ gboolean done = FALSE;
+
day = mrp_calendar_get_day (calendar, t1, TRUE);
ivals = mrp_calendar_day_get_intervals (calendar, day, TRUE);
-
+
ival_prev = t1;
- /* Loop through the intervals for this day. */
- for (l = ivals; l; l = l->next) {
- ival = l->data;
-
- mrp_interval_get_absolute (ival,
- mrp_time_align_day (t1),
- &ival_start,
- &ival_end);
-
- if (planner_scale_conf[data->level].nonworking_limit <= ival_start - ival_prev ||
- (boundary_overlap && ival_start >= t1)) {
-
- boundary_overlap = FALSE;
-
- /* Check for corner case of
- * non-working interval
- * overlapping page boundary.
- */
-
- if (ival_start > t2) {
- boundary_overlap = TRUE;
- }
+ /* Loop through the non-work intervals for this day */
+ while (!done)
+ {
+ /* The number of non-work intervals is one for each work interval and one
+ * more for the remaining period after the last work interval */
+ if (ivals != NULL) {
+ mrp_interval_get_absolute (ivals->data,
+ t1,
+ &ival_start,
+ &ival_end);
+
+ ivals = ivals->next;
+ } else {
+ ival_start = t1 + 60*60*24;
+ done = TRUE;
+ }
+
+ /* Only consider non-work intervals that are large enough and
+ * lie (partially) within [t0...t2] */
+ if (ival_prev < t2 && ival_start > t0 &&
+ planner_scale_conf[data->level].nonworking_limit <= ival_start - ival_prev) {
+
+ /* Only draw the part within [t0...t2] */
element = g_new0 (Element, 1);
element->type = SHADE;
- element->y1 = y0 + data->row_height / 4;
+ element->y1 = y0;
element->y2 = data->job->height;
- element->x1 = x0 + (ival_prev - t0) / data->f;
- element->x2 = x0 + (ival_start - t0) / data->f;
+ element->x1 = x0 + (MAX(t0, ival_prev) - t0) / data->f;
+ element->x2 = x0 + (MIN(t2, ival_start) - t0) / data->f;
page = GET_PAGE (data, row, col);
page->background_elements = g_list_prepend (page->background_elements, element);
- }
-
- ival_prev = ival_end;
- }
-
- t1 += 60*60*24;
- t1 = mrp_time_align_day (t1);
-
- /* Draw the remaining interval if there is one. */
- if ((ival_prev < t1 && planner_scale_conf[data->level].nonworking_limit <= t1 - ival_prev) ||
- boundary_overlap) {
-
- boundary_overlap = FALSE;
-
- /* Check for corner case of non-working
- * interval overlapping page
- * boundary.
- */
- if (t1 > t2) {
- boundary_overlap = TRUE;
}
- element = g_new0 (Element, 1);
- element->type = SHADE;
- element->y1 = y0 + data->row_height / 4;
- element->y2 = data->job->height;
-
- element->x1 = x0 + (ival_prev - t0) / data->f;
- element->x2 = x0 + (t1 - t0) / data->f;
-
- page = GET_PAGE (data, row, col);
- page->background_elements = g_list_prepend (page->background_elements, element);
+ ival_prev = ival_end;
}
+ /* Set t1 to the start of the next day */
+ t1 = ival_start;
}
/* Print the current time. */
if (current_time >= t0 && current_time <= t2) {
element = g_new0 (Element, 1);
element->type = TIMELINE;
- element->y1 = data->header_height + data->row_height / 4;
+ element->y1 = data->header_height;
element->y2 = data->job->height;
element->x1 = x0 + (current_time - t0) / data->f;
element->x2 = element->x1;
@@ -1085,421 +1488,6 @@
}
}
- /* Fourth pass, generate pages. */
- x2 = data->job->width;
- i = 0;
- for (row = 0; row < data->rows_of_pages; row++) {
- t1 = data->start;
-
- for (col = 0; col < data->cols_of_pages; col++) {
- planner_print_job_begin_next_page (data->job);
-
- if (col == 0) {
- x1 = data->tree_x2;
- t2 = t1 + (data->job->width - (data->tree_x2 - data->tree_x1)) * data->f;
-
- planner_print_job_moveto (data->job,
- data->tree_x2,
- 0);
- planner_print_job_lineto (data->job,
- data->tree_x2,
- data->job->height);
- gnome_print_stroke (data->job->pc);
-
- planner_print_job_moveto (data->job,
- data->name_x2,
- 0);
- planner_print_job_lineto (data->job,
- data->name_x2,
- data->job->height);
- gnome_print_stroke (data->job->pc);
-
- print_table_tasks (data,
- row == 0,
- data->tasks,
- i);
- } else {
- x1 = 0;
- t2 = t1 + data->job->width * data->f;
- }
-
- page = GET_PAGE (data, row, col);
- for (l = page->background_elements; l; l = l->next) {
- gdouble dashes[] = { 4, 4 };
-
- element = l->data;
-
- switch (element->type) {
- case TIMELINE:
- gnome_print_newpath (data->job->pc);
- gnome_print_setrgbcolor (data->job->pc, 150/255.0, 150/255.0, 249/255.0);
- gnome_print_setlinewidth (data->job->pc, 1);
-
- gnome_print_setdash (data->job->pc, 2, dashes, 0);
-
- gnome_print_setlinewidth (data->job->pc, 1);
- planner_print_job_moveto (data->job, element->x1, element->y1);
- planner_print_job_lineto (data->job,element->x1, element->y2);
- gnome_print_stroke (data->job->pc);
-
- gnome_print_setdash (data->job->pc, 0, NULL, 0);
-
- break;
- case SHADE:
- gnome_print_newpath (data->job->pc);
- planner_print_job_moveto (data->job, element->x1, element->y1);
- planner_print_job_lineto (data->job, element->x2, element->y1);
- planner_print_job_lineto (data->job, element->x2, element->y2);
- planner_print_job_lineto (data->job, element->x1, element->y2);
- gnome_print_closepath (data->job->pc);
-
- gnome_print_setrgbcolor (data->job->pc, 249/255.0, 249/255.0, 249/255.0);
- gnome_print_fill (data->job->pc);
-
- gnome_print_setlinewidth (data->job->pc, 0);
- gnome_print_setrgbcolor (data->job->pc, 150/255.0, 150/255.0, 150/255.0);
- planner_print_job_moveto (data->job, element->x1, element->y1);
- planner_print_job_lineto (data->job, element->x1, element->y2);
- gnome_print_stroke (data->job->pc);
- break;
- default:
- break;
- }
- }
-
- gnome_print_setrgbcolor (data->job->pc, 0, 0, 0);
-
- if (row == 0) {
- print_time_header (data, x1, x2, t1, t2);
- if (col == 0) {
- print_table_header (data);
- }
- }
-
- for (l = page->elements; l; l = l->next) {
- element = l->data;
-
- gnome_print_setrgbcolor (data->job->pc, 0, 0, 0);
-
- switch (element->type) {
- case TASK_LEFT:
- case TASK_RIGHT:
- case TASK_WHOLE:
- case TASK_MIDDLE:
- gantt_print_task (data, element);
- break;
- case SUMMARY_LEFT:
- planner_print_job_moveto (data->job,
- element->x1,
- element->y1 + data->summary_thick);
- planner_print_job_lineto (data->job,
- element->x1,
- element->y1 + data->summary_thick + data->summary_height);
- planner_print_job_lineto (data->job,
- element->x1 + data->summary_slope,
- element->y1 + data->summary_thick);
- gnome_print_closepath (data->job->pc);
- gnome_print_fill (data->job->pc);
-
- planner_print_job_moveto (data->job,
- element->x2,
- element->y1 + 2 * data->summary_thick);
- planner_print_job_lineto (data->job,
- element->x1,
- element->y1 + 2 * data->summary_thick);
- planner_print_job_lineto (data->job,
- element->x1,
- element->y1 + data->summary_thick);
- planner_print_job_lineto (data->job,
- element->x2,
- element->y1 + data->summary_thick);
- gnome_print_closepath (data->job->pc);
- gnome_print_fill (data->job->pc);
- break;
- case SUMMARY_RIGHT:
- planner_print_job_moveto (data->job,
- element->x2,
- element->y1 + data->summary_thick);
- planner_print_job_lineto (data->job,
- element->x2,
- element->y1 + data->summary_thick + data->summary_height);
- planner_print_job_lineto (data->job,
- element->x2 - data->summary_slope,
- element->y1 + data->summary_thick);
- gnome_print_closepath (data->job->pc);
- gnome_print_fill (data->job->pc);
-
- planner_print_job_moveto (data->job,
- element->x2,
- element->y1 + 2 * data->summary_thick);
- planner_print_job_lineto (data->job,
- element->x1,
- element->y1 + 2 * data->summary_thick);
- planner_print_job_lineto (data->job,
- element->x1,
- element->y1 + data->summary_thick);
- planner_print_job_lineto (data->job,
- element->x2,
- element->y1 + data->summary_thick);
- gnome_print_closepath (data->job->pc);
- gnome_print_fill (data->job->pc);
- break;
- case SUMMARY_WHOLE:
- planner_print_job_moveto (data->job,
- element->x1,
- element->y1 + data->summary_thick);
- planner_print_job_lineto (data->job,
- element->x1,
- element->y1 + data->summary_thick + data->summary_height);
- planner_print_job_lineto (data->job,
- element->x1 + data->summary_slope,
- element->y1 + data->summary_thick);
- gnome_print_closepath (data->job->pc);
- gnome_print_fill (data->job->pc);
-
- planner_print_job_moveto (data->job,
- element->x2,
- element->y1 + data->summary_thick);
- planner_print_job_lineto (data->job,
- element->x2,
- element->y1 + data->summary_thick + data->summary_height);
- planner_print_job_lineto (data->job,
- element->x2 - data->summary_slope,
- element->y1 + data->summary_thick);
- gnome_print_closepath (data->job->pc);
- gnome_print_fill (data->job->pc);
-
- planner_print_job_moveto (data->job,
- element->x2,
- element->y1 + 2 * data->summary_thick);
- planner_print_job_lineto (data->job,
- element->x1,
- element->y1 + 2 * data->summary_thick);
- planner_print_job_lineto (data->job,
- element->x1,
- element->y1 + data->summary_thick);
- planner_print_job_lineto (data->job,
- element->x2,
- element->y1 + data->summary_thick);
- gnome_print_closepath (data->job->pc);
- gnome_print_fill (data->job->pc);
- break;
- case SUMMARY_MIDDLE:
- planner_print_job_moveto (data->job,
- element->x2,
- element->y1 + 2 * data->summary_thick);
- planner_print_job_lineto (data->job,
- element->x1,
- element->y1 + 2 * data->summary_thick);
- planner_print_job_lineto (data->job,
- element->x1,
- element->y1 + data->summary_thick);
- planner_print_job_lineto (data->job,
- element->x2,
- element->y1 + data->summary_thick);
- gnome_print_closepath (data->job->pc);
- gnome_print_fill (data->job->pc);
- break;
- case RELATION_ARROW_DOWN:
- planner_print_job_moveto (data->job,
- element->x1,
- element->y1);
- planner_print_job_lineto (data->job,
- element->x1 - data->arrow_width,
- element->y1 - data->arrow_height);
- planner_print_job_lineto (data->job,
- element->x1 + data->arrow_width,
- element->y1 - data->arrow_height);
- gnome_print_closepath (data->job->pc);
- gnome_print_fill (data->job->pc);
- break;
- case RELATION_ARROW_UP:
- planner_print_job_moveto (data->job,
- element->x1,
- element->y1);
- planner_print_job_lineto (data->job,
- element->x1 - data->arrow_width,
- element->y1 + data->arrow_height);
- planner_print_job_lineto (data->job,
- element->x1 + data->arrow_width,
- element->y1 + data->arrow_height);
- gnome_print_closepath (data->job->pc);
- gnome_print_fill (data->job->pc);
- break;
- case RELATION_HORIZ:
- planner_print_job_moveto (data->job, element->x1, element->y1);
- planner_print_job_lineto (data->job, element->x2, element->y1);
- gnome_print_stroke (data->job->pc);
- break;
- case RELATION_VERT:
- planner_print_job_moveto (data->job, element->x1, element->y1);
- planner_print_job_lineto (data->job, element->x1, element->y2);
- gnome_print_stroke (data->job->pc);
- break;
- case MILESTONE:
- planner_print_job_moveto (data->job,
- element->x1,
- element->y1);
- planner_print_job_lineto (data->job,
- element->x1 + data->milestone_size,
- element->y1 + data->milestone_size);
- planner_print_job_lineto (data->job,
- element->x1,
- element->y1 + 2 * data->milestone_size);
- planner_print_job_lineto (data->job,
- element->x1 - data->milestone_size,
- element->y1 + data->milestone_size);
- gnome_print_closepath (data->job->pc);
- gnome_print_fill (data->job->pc);
- break;
- case RESOURCES:
- planner_print_job_show_clipped (data->job,
- element->x1,
- element->y1,
- element->resources,
- 0, 0,
- data->job->width,
- data->job->height);
- break;
- default:
- break;
- }
- }
-
- planner_print_job_finish_page (data->job, TRUE);
- t1 = t2;
- }
-
- if (row == 0) {
- i += data->tasks_per_page_with_header;
- } else {
- i += data->tasks_per_page_without_header;
- }
- }
-}
-
-PlannerGanttPrintData *
-planner_gantt_print_data_new (PlannerView *view,
- PlannerPrintJob *job,
- GtkTreeView *tree_view,
- gint level,
- gboolean show_critical)
-{
- PlannerGanttPrintData *data;
- GnomeFont *font;
- GList *tasks = NULL, *l;
- gint num_tasks;
- gdouble max_name_width = 0.0;
-
- data = g_new0 (PlannerGanttPrintData, 1);
-
- data->view = view;
- data->job = job;
- data->project = planner_window_get_project (view->main_window);
-
- data->tree_view = tree_view;
-
- data->show_critical = show_critical;
- data->level = level;
-
- /* Note: This looks hackish, but it's the same equation used for the
- * zoom level in the gantt chart, which actually is calculated to have a
- * "good feel" :). We scale it with the paper size here though...
- */
- data->f = 1000 / pow (2, level - 19) / data->job->width;
-
- data->major_unit = planner_scale_conf[level].major_unit;
- data->major_format = planner_scale_conf[level].major_format;
-
- data->minor_unit = planner_scale_conf[level].minor_unit;
- data->minor_format = planner_scale_conf[level].minor_format;
-
- font = planner_print_job_get_font (job);
-
- data->task_start_coords = g_hash_table_new_full (NULL, NULL, NULL, g_free);
- data->task_finish_coords = g_hash_table_new_full (NULL, NULL, NULL, g_free);
-
- /* Start and finish of the project. */
- data->start = mrp_project_get_project_start (data->project);
-
- tasks = gantt_print_get_visible_tasks (data);
- data->tasks = tasks;
- num_tasks = g_list_length (tasks);
-
- data->finish = data->start;
-
- /* Go through the tasks and get the end time by checking the right-most
- * resource label we will print.
- */
- for (l = tasks; l; l = l->next) {
- PrintTask *ptask = l->data;
- MrpTask *task = ptask->task;
- gchar *name;
- mrptime finish;
- gdouble width;
- gdouble name_width;
-
- g_object_get (task,
- "name", &name,
- "finish", &finish,
- NULL);
-
- name_width = gnome_font_get_width_utf8 (font, name) +
- ptask->depth * INDENT_FACTOR * data->job->x_pad;
-
- if (max_name_width < name_width) {
- max_name_width = name_width;
- }
-
- gantt_print_get_allocated_resources_string (data, task, NULL, &width);
-
- data->finish = MAX (data->finish, finish);/* + width * data->f);*/
- }
-
- data->name_x1 = 0;
- data->name_x2 = data->name_x1 + max_name_width + gnome_font_get_width_utf8 (font, "WW");
-
- data->work_x1 = data->name_x2;
- data->work_x2 = data->work_x1 + gnome_font_get_width_utf8 (font, "WORKWO");
-
- data->tree_x1 = 0;
- data->tree_x2 = data->work_x2;
-
- data->row_height = 2 * planner_print_job_get_font_height (job);
-
- data->header_height = 2 * data->row_height;
-
- /* Calculate drawing "constants". */
- data->summary_height = 0.36 * data->row_height;
- data->summary_thick = 0.12 * data->row_height;
- data->summary_slope = 0.28 * data->row_height;
- data->milestone_size = 0.40 * data->row_height;
- data->arrow_height = 0.24 * data->row_height;
- data->arrow_width = 0.16 * data->row_height;
-
- if (num_tasks > 0) {
- data->tasks_per_page_without_header = data->job->height / data->row_height;
- data->tasks_per_page_with_header = (data->job->height - data->header_height) /
- data->row_height;
-
- data->cols_of_pages = ceil (((data->finish - data->start) /
- data->f + data->tree_x2 - data->tree_x1) /
- data->job->width);
-
- data->rows_of_pages = ceil ((num_tasks * data->row_height + data->header_height) /
- (data->job->height - data->row_height));
-
- if (data->tasks_per_page_without_header * (data->rows_of_pages - 2) +
- data->tasks_per_page_with_header >= num_tasks) {
- data->rows_of_pages--;
- }
-
- data->cols_of_pages = MAX (1, data->cols_of_pages);
- data->rows_of_pages = MAX (1, data->rows_of_pages);
-
- data->pages = g_new0 (Page, data->cols_of_pages * data->rows_of_pages);
- }
-
return data;
}
Modified: trunk/src/planner-gantt-print.h
==============================================================================
--- trunk/src/planner-gantt-print.h (original)
+++ trunk/src/planner-gantt-print.h Wed Nov 5 19:54:02 2008
@@ -20,8 +20,8 @@
* Boston, MA 02111-1307, USA.
*/
-#ifndef __PLANNER_GANTT_PRINT_JOB_H__
-#define __PLANNER_GANTT_PRINT_JOB_H__
+#ifndef __PLANNER_GANTT_PRINT_H__
+#define __PLANNER_GANTT_PRINT_H__
#include <gtk/gtktreeview.h>
#include "planner-print-job.h"
@@ -30,7 +30,8 @@
typedef struct _PlannerGanttPrintData PlannerGanttPrintData;
-void planner_gantt_print_do (PlannerGanttPrintData *data);
+void planner_gantt_print_do (PlannerGanttPrintData *data,
+ gint page_nr);
gint planner_gantt_print_get_n_pages (PlannerGanttPrintData *data);
@@ -43,5 +44,5 @@
void planner_gantt_print_data_free (PlannerGanttPrintData *data);
-#endif /* __PLANNER_GANTT_PRINT_JOB_H__ */
+#endif /* __PLANNER_GANTT_PRINT_H__ */
Modified: trunk/src/planner-gantt-view.c
==============================================================================
--- trunk/src/planner-gantt-view.c (original)
+++ trunk/src/planner-gantt-view.c Wed Nov 5 19:54:02 2008
@@ -125,7 +125,8 @@
static GtkWidget *gantt_view_get_widget (PlannerView *view);
static void gantt_view_print_init (PlannerView *view,
PlannerPrintJob *job);
-static void gantt_view_print (PlannerView *view);
+static void gantt_view_print (PlannerView *view,
+ gint page_nr);
static gint gantt_view_print_get_n_pages (PlannerView *view);
static void gantt_view_print_cleanup (PlannerView *view);
@@ -404,14 +405,14 @@
}
static void
-gantt_view_print (PlannerView *view)
+gantt_view_print (PlannerView *view, gint page_nr)
{
PlannerGanttViewPriv *priv;
priv = PLANNER_GANTT_VIEW (view)->priv;
- planner_gantt_print_do (priv->print_data);
+ planner_gantt_print_do (priv->print_data, page_nr);
}
static gint
Modified: trunk/src/planner-print-dialog.c
==============================================================================
--- trunk/src/planner-print-dialog.c (original)
+++ trunk/src/planner-print-dialog.c Wed Nov 5 19:54:02 2008
@@ -31,22 +31,12 @@
#include <glib/gi18n.h>
#include <glib/gstdio.h>
#include <gtk/gtk.h>
-#include <libgnomeprint/gnome-print.h>
-#include <libgnomeprint/gnome-print-job.h>
-#include <libgnomeprintui/gnome-print-job-preview.h>
-#include <libgnomeprintui/gnome-print-paper-selector.h>
-#include <libgnomeprintui/gnome-print-dialog.h>
#include "planner-view.h"
#include "planner-conf.h"
#include "planner-print-dialog.h"
#define PLANNER_PRINT_CONFIG_FILE "planner-print-config"
-static GtkWidget * print_dialog_create_page (PlannerWindow *window,
- GtkWidget *dialog,
- GList *views);
-static GtkNotebook * print_dialog_get_notebook (GtkWidget *dialog);
-
static gboolean
ensure_dir (void)
@@ -91,48 +81,60 @@
NULL);
}
-/*
- * Load printer configuration from a file.
- * Return a GnomePrintConfig object containing the configuration.
- */
-GnomePrintConfig *
-planner_print_dialog_load_config (void)
+
+GtkPageSetup *
+planner_print_dialog_load_page_setup (void)
{
+ gboolean success;
gchar *filename;
- gboolean res;
- gchar *contents;
- GnomePrintConfig *config;
+ GKeyFile *key_file;
+ GtkPageSetup *page_setup = NULL;
filename = get_config_filename ();
- res = g_file_get_contents (filename, &contents, NULL, NULL);
- g_free (filename);
+ if(filename) {
+ key_file = g_key_file_new();
- if (res) {
- config = gnome_print_config_from_string (contents, 0);
- g_free (contents);
- } else {
- config = gnome_print_config_default ();
+ success = g_key_file_load_from_file (key_file,
+ filename,
+ G_KEY_FILE_KEEP_COMMENTS|G_KEY_FILE_KEEP_TRANSLATIONS,
+ NULL);
+ g_free (filename);
+
+ if (success) {
+ page_setup = gtk_page_setup_new_from_key_file (key_file, NULL, NULL);
+ }
+
+ if (page_setup == NULL) {
+ page_setup = gtk_page_setup_new ();
+ }
+
+ g_key_file_free (key_file);
}
- return config;
+ return page_setup;
}
-/*
- * Save printer configuration into a file in the .gnome2 user directory
- */
void
-planner_print_dialog_save_config (GnomePrintConfig *config)
+planner_print_dialog_save_page_setup (GtkPageSetup *page_setup)
{
- gint fd;
- gchar *str;
- gint bytes, bytes_written;
- gchar *filename;
-
- g_return_if_fail (config != NULL);
-
+ gint fd;
+ gchar *str;
+ gint bytes, bytes_written;
+ gchar *filename;
+ GKeyFile *key_file;
+
+ g_return_if_fail (page_setup != NULL);
+
filename = get_config_filename ();
if (filename) {
- str = gnome_print_config_to_string (config, 0);
+ key_file = g_key_file_new ();
+ g_key_file_load_from_file (key_file,
+ filename,
+ G_KEY_FILE_KEEP_COMMENTS|G_KEY_FILE_KEEP_TRANSLATIONS,
+ NULL);
+ gtk_page_setup_to_key_file (page_setup, key_file, NULL);
+ str = g_key_file_to_data (key_file, NULL, NULL);
+ g_key_file_free (key_file);
fd = open (filename, O_WRONLY | O_CREAT | O_TRUNC, 0600);
g_free (filename);
@@ -153,53 +155,80 @@
}
}
-GtkWidget *
-planner_print_views_dialog_new (PlannerWindow *window,
- GList *views)
+GtkPrintSettings *
+planner_print_dialog_load_print_settings (void)
{
- GtkWidget *dialog;
- GtkWidget *page;
+ gboolean success;
+ gchar *filename;
+ GKeyFile *key_file;
+ GtkPrintSettings *settings = NULL;
+
+ filename = get_config_filename ();
+ if(filename) {
+ key_file = g_key_file_new();
- dialog = gtk_dialog_new_with_buttons ("Select Views",
- GTK_WINDOW (window),
- GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_STOCK_OK,
- GTK_RESPONSE_OK,
- GTK_STOCK_CANCEL,
- GTK_RESPONSE_CANCEL,
- NULL);
- page = print_dialog_create_page (window, dialog, views);
+ success = g_key_file_load_from_file (key_file,
+ filename,
+ G_KEY_FILE_KEEP_COMMENTS|G_KEY_FILE_KEEP_TRANSLATIONS,
+ NULL);
+ g_free (filename);
- gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), page);
+ if (success) {
+ settings = gtk_print_settings_new_from_key_file (key_file, NULL, NULL);
+ }
- gtk_widget_show_all (dialog);
+ if (settings == NULL) {
+ settings = gtk_print_settings_new ();
+ }
- return dialog;
-}
-GtkWidget *
-planner_print_dialog_new (PlannerWindow *window,
- GnomePrintJob *job,
- GList *views)
-{
- GtkWidget *dialog;
- GtkWidget *page;
+ g_key_file_free (key_file);
+ }
- dialog = gnome_print_dialog_new (job, _("Print Project"), 0);
+ return settings;
+}
- page = print_dialog_create_page (window, dialog, views);
- gtk_widget_show (page);
+void
+planner_print_dialog_save_print_settings (GtkPrintSettings *settings)
+{
+ gint fd;
+ gchar *str;
+ gint bytes, bytes_written;
+ gchar *filename;
+ GKeyFile *key_file;
- gtk_notebook_prepend_page (print_dialog_get_notebook (dialog),
- page,
- gtk_label_new (_("Select views")));
- gtk_notebook_set_current_page (print_dialog_get_notebook (dialog), 0);
+ g_return_if_fail (settings != NULL);
- g_object_set_data (G_OBJECT (dialog), "window", window);
+ filename = get_config_filename ();
+ if (filename) {
+ key_file = g_key_file_new ();
+ g_key_file_load_from_file (key_file,
+ filename,
+ G_KEY_FILE_KEEP_COMMENTS|G_KEY_FILE_KEEP_TRANSLATIONS,
+ NULL);
+ gtk_print_settings_to_key_file (settings, key_file, NULL);
+ str = g_key_file_to_data (key_file, NULL, NULL);
+ g_key_file_free (key_file);
+
+ fd = open (filename, O_WRONLY | O_CREAT | O_TRUNC, 0600);
+ g_free (filename);
+
+ if (fd >= 0) {
+ bytes = strlen (str);
+
+ again:
+ bytes_written = write (fd, str, bytes);
+ if (bytes_written < 0 && errno == EINTR) {
+ goto again;
+ }
- return dialog;
-}
+ close (fd);
+ }
+
+ g_free (str);
+ }
+}
-static GtkWidget *
+GtkWidget *
print_dialog_create_page (PlannerWindow *window,
GtkWidget *dialog,
GList *views)
@@ -211,7 +240,7 @@
GList *buttons = NULL;
gchar *str;
gboolean state;
-
+
outer_vbox = gtk_vbox_new (FALSE, 4);
gtk_container_set_border_width (GTK_CONTAINER (outer_vbox), 8);
@@ -256,8 +285,7 @@
buttons = g_list_prepend (buttons, w);
}
- buttons = g_list_reverse (buttons);
- g_object_set_data (G_OBJECT (dialog), "buttons", buttons);
+ g_object_set_data (G_OBJECT (outer_vbox), "buttons", buttons);
gtk_widget_show_all (outer_vbox);
@@ -265,7 +293,7 @@
}
GList *
-planner_print_dialog_get_print_selection (GtkDialog *dialog,
+planner_print_dialog_get_print_selection (GtkWidget *widget,
gboolean *summary)
{
GtkToggleButton *button;
@@ -273,19 +301,16 @@
GList *views = NULL;
PlannerView *view;
gchar *str;
- PlannerWindow *window;
- g_return_val_if_fail (GTK_IS_DIALOG (dialog), NULL);
+ g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
/* button = g_object_get_data (G_OBJECT (dialog), "summary-button");
if (summary) {
*summary = gtk_toggle_button_get_active (button);
}
*/
-
- window = g_object_get_data (G_OBJECT (dialog), "window");
- buttons = g_object_get_data (G_OBJECT (dialog), "buttons");
+ buttons = g_object_get_data (G_OBJECT (widget), "buttons");
for (l = buttons; l; l = l->next) {
button = l->data;
@@ -306,35 +331,3 @@
return views;
}
-/*
- * Eek! Hack alert! Hopefully we'll get custom pages in libgnomeprintui soon.
- */
-static GtkNotebook *
-print_dialog_get_notebook (GtkWidget *container)
-{
- GList *children, *l;
- GtkNotebook *notebook;
-
- children = gtk_container_get_children (GTK_CONTAINER (container));
-
- for (l = children; l; l = l->next) {
- if (GTK_IS_NOTEBOOK (l->data)) {
- notebook = l->data;
-
- g_list_free (children);
-
- return notebook;
- }
- else if (GTK_IS_CONTAINER (l->data)) {
- notebook = print_dialog_get_notebook (l->data);
- if (notebook) {
- return notebook;
- }
- }
- }
-
- g_list_free (children);
-
- return NULL;
-}
-
Modified: trunk/src/planner-print-dialog.h
==============================================================================
--- trunk/src/planner-print-dialog.h (original)
+++ trunk/src/planner-print-dialog.h Wed Nov 5 19:54:02 2008
@@ -25,14 +25,17 @@
#include "planner-window.h"
GtkWidget * planner_print_dialog_new (PlannerWindow *window,
- GnomePrintJob *job,
+ GtkPrintOperation *job,
GList *views);
-GtkWidget * planner_print_views_dialog_new (PlannerWindow *window,
- GList *views);
-GList * planner_print_dialog_get_print_selection (GtkDialog *dialog,
+GtkWidget * print_dialog_create_page (PlannerWindow *window,
+ GtkWidget *dialog,
+ GList *views);
+GList * planner_print_dialog_get_print_selection (GtkWidget *widget,
gboolean *summary);
-void planner_print_dialog_save_config (GnomePrintConfig *config);
-GnomePrintConfig *planner_print_dialog_load_config (void);
+void planner_print_dialog_save_page_setup (GtkPageSetup *page_setup);
+GtkPageSetup *planner_print_dialog_load_page_setup (void);
+void planner_print_dialog_save_print_settings (GtkPrintSettings *settings);
+GtkPrintSettings *planner_print_dialog_load_print_settings (void);
#endif /* __PLANNER_PRINT_DIALOG_H__ */
Modified: trunk/src/planner-print-job.c
==============================================================================
--- trunk/src/planner-print-job.c (original)
+++ trunk/src/planner-print-job.c Wed Nov 5 19:54:02 2008
@@ -24,13 +24,11 @@
#include <string.h>
#include <glib-object.h>
#include <glib/gi18n.h>
-#include <libgnomeprint/gnome-print-config.h>
-#include <libgnomeprint/gnome-print-job.h>
-#include <libgnomeprint/gnome-print-pango.h>
-#include <libart_lgpl/libart.h>
#include "planner-print-job.h"
+#include "planner-print-dialog.h"
+#include "planner-view.h"
-#define MARGIN 30
+#define MARGIN 0
struct _PlannerPrintJobPriv {
gchar *header;
@@ -42,18 +40,18 @@
gdouble header_height;
gdouble footer_height;
- GnomeFont *font;
+ PangoFontDescription *font;
gdouble font_height;
- GnomeFont *bold_font;
+ PangoFontDescription *bold_font;
/* The font in use, one of the above. */
- GnomeFont *current_font;
+ PangoFontDescription *current_font;
gint active_page;
gint total_pages;
- gboolean upside_down;
+ GList *views;
};
static void print_job_class_init (PlannerPrintJobClass *klass);
@@ -118,10 +116,9 @@
PlannerPrintJob *job = PLANNER_PRINT_JOB (object);
PlannerPrintJobPriv *priv = job->priv;
- g_object_unref (job->pj);
- gnome_print_context_close (job->pc);
- g_object_unref (job->pc);
- g_object_unref (priv->font);
+ g_object_unref (job->operation);
+ pango_font_description_free (priv->font);
+ pango_font_description_free (priv->bold_font);
g_free (job->priv);
@@ -142,7 +139,7 @@
}
if (y) {
- *y = job->height - *y + MARGIN;
+ *y += MARGIN;
}
}
@@ -162,59 +159,169 @@
2 * MARGIN);
}
-PlannerPrintJob *
-planner_print_job_new (GnomePrintJob *gpj)
+static GObject *
+print_job_create_custom_widget(GtkPrintOperation *operation,
+ gpointer user_data)
{
- PlannerPrintJob *job;
+ PlannerPrintJob *job;
PlannerPrintJobPriv *priv;
- GnomePrintConfig *config;
- gchar *orientation;
-
- job = g_object_new (PLANNER_TYPE_PRINT_JOB, NULL);
+
+ job = (PlannerPrintJob *)user_data;
+ priv = job->priv;
+
+ gtk_print_operation_set_custom_tab_label(operation, _("Select views"));
+
+ return G_OBJECT(print_dialog_create_page (NULL, NULL, priv->views));
+}
+
+static void
+print_job_custom_widget_apply(GtkPrintOperation *operation,
+ GtkWidget *widget,
+ gpointer user_data)
+{
+ gboolean summary;
+ PlannerPrintJob *job;
+ PlannerPrintJobPriv *priv;
+
+ job = (PlannerPrintJob *)user_data;
+ priv = job->priv;
+
+ priv->views = planner_print_dialog_get_print_selection(widget, &summary);
+}
+
+static void
+print_job_begin_print(GtkPrintOperation *operation,
+ GtkPrintContext *context,
+ gpointer user_data)
+{
+ PlannerPrintJob *job;
+ PlannerPrintJobPriv *priv;
+ GList *l;
+ PlannerView *view;
+ int n_pages = 0;
+
+ job = (PlannerPrintJob *)user_data;
+ priv = job->priv;
+
+ job->cr = gtk_print_context_get_cairo_context (context);
+ job->pc = context;
+
+ priv->paper_height = gtk_print_context_get_height (context);
+ priv->paper_width = gtk_print_context_get_width (context);
+
+ print_job_update_size (job);
+ planner_print_job_set_font_regular (job);
+ job->x_pad = planner_print_job_get_extents (job, "#") / 2;
+
+ for (l = priv->views; l; l = l->next) {
+ view = l->data;
+ planner_view_print_init (view, job);
+
+ n_pages += planner_view_print_get_n_pages (view);
+ }
+ gtk_print_operation_set_n_pages (operation, (n_pages > 0) ? n_pages : 1);
+}
+
+static void
+print_job_draw_page (GtkPrintOperation *operation,
+ GtkPrintContext *context,
+ gint page_nr,
+ gpointer user_data)
+{
+ PlannerPrintJob *job;
+ PlannerPrintJobPriv *priv;
+ PlannerView *v;
+ GList *l;
+ gboolean page_found = FALSE;
+ gint pages_in_view;
+
+ job = (PlannerPrintJob *)user_data;
priv = job->priv;
- job->pj = gpj;
- job->pc = gnome_print_job_get_context (job->pj);
+ l = priv->views;
- config = gnome_print_job_get_config (job->pj);
+ /* Abort if there is nothing to print.
+ *
+ * A better solution would be to set the number of pages to print to 0
+ * in print_job_begin_print, but 0 is not a valid value for
+ * gtk_print_operation_set_n_pages.
+ */
+ if(!l) {
+ return;
+ }
- /* Useful for testing, so we leave it here. */
-#if 0
- if (!gnome_print_config_set (config, "Settings.Transport.Backend", "file")) {
- g_warning ("Could not set the backend to file.");
+ while (!page_found) {
+ v = PLANNER_VIEW (l->data);
+
+ pages_in_view = planner_view_print_get_n_pages (v);
+
+ if (page_nr < pages_in_view) {
+ planner_view_print (v, page_nr);
+ page_found = TRUE;
+ } else {
+ page_nr -= pages_in_view;
+ l = l->next;
+
+ g_assert (l != NULL);
+ }
}
-#endif
+}
- gnome_print_job_get_page_size_from_config (config,
- &priv->paper_width,
- &priv->paper_height);
-
- orientation= gnome_print_config_get (config,
- GNOME_PRINT_KEY_PAGE_ORIENTATION);
+static void
+print_job_end_print (GtkPrintOperation *operation,
+ GtkPrintContext *context,
+ gpointer user_data)
+{
+ PlannerPrintJob *job;
+ PlannerPrintJobPriv *priv;
+ GList *l;
+
+ job = (PlannerPrintJob *)user_data;
+ priv = job->priv;
- if (strcmp (orientation, "R270") == 0 || strcmp (orientation, "R180") == 0) {
- priv->upside_down = TRUE;
+ for (l = priv->views; l; l = l->next) {
+ planner_view_print_cleanup (PLANNER_VIEW(l->data));
}
+}
+
+
+PlannerPrintJob *
+planner_print_job_new (GtkPrintOperation *gpo, GList *views)
+{
+ PlannerPrintJob *job;
+ PlannerPrintJobPriv *priv;
+
+ job = g_object_new (PLANNER_TYPE_PRINT_JOB, NULL);
- g_free (orientation);
-
+ priv = job->priv;
+
+ job->operation = g_object_ref (gpo);
+ gtk_print_operation_set_unit (gpo, GTK_UNIT_POINTS);
+
priv->header = NULL;
priv->footer = NULL;
- priv->font = gnome_font_find_closest ("Sans Regular", 6.0);
- priv->font_height = (gnome_font_get_ascender (priv->font) +
- gnome_font_get_descender (priv->font));
+ priv->font = pango_font_description_from_string ("Sans Regular 6");
+ priv->font_height = pango_font_description_get_size (priv->font) / PANGO_SCALE;
- priv->bold_font = gnome_font_find_closest ("Sans Bold", 6.0);
+ priv->bold_font = pango_font_description_from_string ("Sans Bold 6");
priv->header_height = 0;
priv->footer_height = 0;
+ priv->views = views;
- print_job_update_size (job);
+ g_signal_connect (G_OBJECT (gpo), "create-custom-widget",
+ G_CALLBACK (print_job_create_custom_widget), job);
+ g_signal_connect (G_OBJECT (gpo), "custom-widget-apply",
+ G_CALLBACK (print_job_custom_widget_apply), job);
+ g_signal_connect (G_OBJECT (gpo), "begin-print",
+ G_CALLBACK (print_job_begin_print), job);
+ g_signal_connect (G_OBJECT (gpo), "draw-page",
+ G_CALLBACK (print_job_draw_page), job);
+ g_signal_connect (G_OBJECT (gpo), "end-print",
+ G_CALLBACK (print_job_end_print), job);
- job->x_pad = gnome_font_get_width_utf8 (priv->font, "#") / 2;
-
return job;
}
@@ -277,7 +384,7 @@
print_job_transform (job, &x, &y);
- gnome_print_moveto (job->pc, x, y);
+ cairo_move_to (job->cr, x, y);
}
void
@@ -287,7 +394,7 @@
print_job_transform (job, &x, &y);
- gnome_print_lineto (job->pc, x, y);
+ cairo_line_to (job->cr, x, y);
}
void
@@ -299,23 +406,19 @@
g_return_if_fail (job != NULL);
g_return_if_fail (str != NULL);
- PangoLayout *layout = gnome_print_pango_create_layout (job->pc);
+ PangoLayout *layout = gtk_print_context_create_pango_layout (job->pc);
PlannerPrintJobPriv *priv;
priv = job->priv;
- pango_layout_set_text (layout, str, strlen(str));
+ pango_layout_set_font_description (layout, priv->current_font);
+ pango_layout_set_text (layout, str, -1);
- PangoFontDescription *fd = gnome_font_get_pango_description (priv->current_font, 72);
- pango_layout_set_font_description (layout, fd);
-
pango_layout_context_changed (layout);
- planner_print_job_moveto (job, x, y-gnome_font_get_ascender (priv->current_font)-gnome_font_get_descender (priv->current_font));
-
- gnome_print_pango_layout (job->pc, layout);
+ planner_print_job_moveto (job, x, y - priv->font_height);
- pango_font_description_free (fd);
+ pango_cairo_show_layout (job->cr, layout);
g_object_unref (layout);
}
@@ -331,6 +434,7 @@
gdouble y2)
{
PlannerPrintJobPriv *priv;
+ gint height;
priv = job->priv;
@@ -343,46 +447,45 @@
if (x < x1 || x > x2) {
return;
}
-
- gnome_print_gsave (job->pc);
- gnome_print_setlinewidth (job->pc, 0);
+ cairo_save (job->cr);
+
+ cairo_set_line_width (job->cr, 1);
- gnome_print_newpath (job->pc);
+ cairo_new_path (job->cr);
planner_print_job_moveto (job, x1, y1);
planner_print_job_lineto (job, x1, y2);
planner_print_job_lineto (job, x2, y2);
planner_print_job_lineto (job, x2, y1);
- gnome_print_closepath (job->pc);
- gnome_print_clip (job->pc);
+ cairo_close_path (job->cr);
- PangoLayout *layout = gnome_print_pango_create_layout (job->pc);
+ cairo_clip (job->cr);
+
+ PangoLayout *layout = gtk_print_context_create_pango_layout (job->pc);
pango_layout_set_text (layout, str, strlen(str));
pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_END);
pango_layout_set_width (layout, (x2 - x1) * PANGO_SCALE);
- PangoFontDescription *fd = gnome_font_get_pango_description (priv->current_font, 72);
- pango_layout_set_font_description (layout, fd);
+ pango_layout_set_font_description (layout, priv->current_font);
pango_layout_context_changed (layout);
-
- planner_print_job_moveto (job, x, y-gnome_font_get_ascender (priv->current_font)-gnome_font_get_descender (priv->current_font));
-
- gnome_print_pango_layout (job->pc, layout);
-
- pango_font_description_free (fd);
- g_object_unref (layout);
+ pango_layout_get_pixel_size (layout, NULL, &height);
+
+ planner_print_job_moveto (job, x, y - priv->font_height);
- gnome_print_grestore (job->pc);
+ pango_cairo_show_layout (job->cr, layout);
+
+ g_object_unref (layout);
+
+ cairo_restore (job->cr);
}
gboolean
planner_print_job_begin_next_page (PlannerPrintJob *job)
{
PlannerPrintJobPriv *priv;
- gchar *job_name;
g_return_val_if_fail (PLANNER_IS_PRINT_JOB (job), FALSE);
@@ -394,45 +497,28 @@
priv->active_page++;
- job_name = g_strdup_printf ("%d", priv->active_page);
- gnome_print_beginpage (job->pc, job_name);
- g_free (job_name);
-
- if (priv->upside_down) {
- gdouble affine[6];
-
- art_affine_rotate (affine, 180.0);
- gnome_print_concat (job->pc, affine);
-
- art_affine_translate (affine,
- -job->width - 2 * MARGIN,
- -job->height - 2 * MARGIN);
- gnome_print_concat (job->pc, affine);
- }
-
/* Draw header and footer, FIXME: implement. */
-
- gnome_print_newpath (job->pc);
+/*
+ cairo_new_path (job->cr);
planner_print_job_set_font_regular (job);
- gnome_print_setlinewidth (job->pc, 0);
-
+ cairo_set_line_width (job->cr, THIN_LINE_WIDTH);
+
planner_print_job_moveto (job, 0, 0);
planner_print_job_lineto (job, job->width, 0);
planner_print_job_lineto (job, job->width, job->height);
planner_print_job_lineto (job, 0, job->height);
- gnome_print_closepath (job->pc);
+ cairo_close_path (job->cr);
#if 0
- gnome_print_gsave (job->pc);
- gnome_print_setlinewidth (job->pc, 3);
- gnome_print_stroke (job->pc);
- gnome_print_grestore (job->pc);
+ cairo_save (job->cr);
+ cairo_set_line_width (job->cr, 3);
+ cairo_stroke (job->cr);
+ cairo_restore (job->cr);
#endif
-
- gnome_print_clip (job->pc);
-
+ cairo_clip (job->cr);
+ */
return TRUE;
}
@@ -442,20 +528,22 @@
g_return_if_fail (PLANNER_IS_PRINT_JOB (job));
if (draw_border) {
- gnome_print_setlinewidth (job->pc, 0);
+ cairo_new_path (job->cr);
+
+ cairo_set_line_width (job->cr, THIN_LINE_WIDTH);
planner_print_job_moveto (job, 0, 0);
planner_print_job_lineto (job, job->width, 0);
planner_print_job_lineto (job, job->width, job->height);
planner_print_job_lineto (job, 0, job->height);
- gnome_print_closepath (job->pc);
- gnome_print_stroke (job->pc);
+ planner_print_job_lineto (job, 0, 0);
+ cairo_close_path (job->cr);
+
+ cairo_stroke (job->cr);
}
-
- gnome_print_showpage (job->pc);
}
-GnomeFont *
+PangoFontDescription *
planner_print_job_get_font (PlannerPrintJob *job)
{
g_return_val_if_fail (PLANNER_IS_PRINT_JOB (job), NULL);
@@ -481,7 +569,6 @@
priv = job->priv;
priv->current_font = priv->font;
- gnome_print_setfont (job->pc, priv->font);
}
void
@@ -494,7 +581,6 @@
priv = job->priv;
priv->current_font = priv->bold_font;
- gnome_print_setfont (job->pc, priv->bold_font);
}
void
@@ -509,5 +595,27 @@
/* FIXME: use italic. */
priv->current_font = priv->bold_font;
- gnome_print_setfont (job->pc, priv->bold_font);
}
+
+gdouble
+planner_print_job_get_extents (PlannerPrintJob *job, char *text)
+{
+ PangoLayout *layout = gtk_print_context_create_pango_layout (job->pc);
+ PlannerPrintJobPriv *priv;
+ PangoRectangle ink;
+
+ priv = job->priv;
+
+ pango_layout_set_font_description (layout, priv->current_font);
+ pango_layout_set_text (layout, text, -1);
+
+ pango_cairo_update_layout (gtk_print_context_get_cairo_context(job->pc), layout);
+ pango_layout_context_changed (layout);
+
+ pango_layout_get_extents (layout, &ink, NULL);
+
+ g_object_unref (layout);
+
+ return ((gdouble)ink.width / PANGO_SCALE);
+}
+
Modified: trunk/src/planner-print-job.h
==============================================================================
--- trunk/src/planner-print-job.h (original)
+++ trunk/src/planner-print-job.h Wed Nov 5 19:54:02 2008
@@ -23,8 +23,7 @@
#ifndef __PLANNER_PRINT_JOB_H__
#define __PLANNER_PRINT_JOB_H__
-#include <libgnomeprint/gnome-print.h>
-#include <libgnomeprint/gnome-print-job.h>
+#include <gtk/gtk.h>
#define PLANNER_TYPE_PRINT_JOB (planner_print_job_get_type ())
#define PLANNER_PRINT_JOB(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PLANNER_TYPE_PRINT_JOB, PlannerPrintJob))
@@ -33,14 +32,19 @@
#define PLANNER_IS_PRINT_JOB_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PLANNER_TYPE_PRINT_JOB))
#define PLANNER_PRINT_JOB_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PLANNER_TYPE_PRINT_JOB, PlannerPrintJobClass))
+/* See http://lists.freedesktop.org/archives/cairo/2006-January/005979.html */
+#define THIN_LINE_WIDTH (72.0 / 300.0)
+
typedef struct _PlannerPrintJob PlannerPrintJob;
typedef struct _PlannerPrintJobClass PlannerPrintJobClass;
typedef struct _PlannerPrintJobPriv PlannerPrintJobPriv;
struct _PlannerPrintJob {
GObject parent;
- GnomePrintContext *pc;
- GnomePrintJob *pj;
+ GtkPrintOperation *operation;
+ GtkPrintContext *pc;
+ cairo_t *cr;
+ PangoLayout *layout;
/* Printable area */
gdouble width;
@@ -57,14 +61,15 @@
};
GType planner_print_job_get_type (void) G_GNUC_CONST;
-PlannerPrintJob * planner_print_job_new (GnomePrintJob *gpj);
+PlannerPrintJob * planner_print_job_new (GtkPrintOperation *gpo,
+ GList *views);
void planner_print_job_set_header (PlannerPrintJob *job,
const gchar *header);
void planner_print_job_set_footer (PlannerPrintJob *job,
const gchar *footer);
void planner_print_job_set_total_pages (PlannerPrintJob *job,
gint total_pages);
-GnomeFont * planner_print_job_get_font (PlannerPrintJob *job);
+PangoFontDescription * planner_print_job_get_font (PlannerPrintJob *job);
gdouble planner_print_job_get_font_height (PlannerPrintJob *job);
/* These functions use 0,0 as the top left of printable area. Use these
@@ -96,7 +101,8 @@
void planner_print_job_set_font_regular (PlannerPrintJob *job);
void planner_print_job_set_font_bold (PlannerPrintJob *job);
void planner_print_job_set_font_italic (PlannerPrintJob *job);
-
+gdouble planner_print_job_get_extents (PlannerPrintJob *job,
+ char *text);
Modified: trunk/src/planner-resource-view.c
==============================================================================
--- trunk/src/planner-resource-view.c (original)
+++ trunk/src/planner-resource-view.c Wed Nov 5 19:54:02 2008
@@ -205,7 +205,8 @@
static GtkWidget *resource_view_get_widget (PlannerView *view);
static void resource_view_print_init (PlannerView *view,
PlannerPrintJob *job);
-static void resource_view_print (PlannerView *view);
+static void resource_view_print (PlannerView *view,
+ gint page_nr);
static gint resource_view_print_get_n_pages (PlannerView *view);
static void resource_view_print_cleanup (PlannerView *view);
static void resource_view_resource_notify_cb (MrpResource *resource,
@@ -560,10 +561,10 @@
}
static void
-resource_view_print (PlannerView *view)
+resource_view_print (PlannerView *view, gint page_nr)
{
- planner_table_print_sheet_output (PLANNER_RESOURCE_VIEW (view)->priv->print_sheet);
+ planner_table_print_sheet_output (PLANNER_RESOURCE_VIEW (view)->priv->print_sheet, page_nr);
}
static gint
@@ -2282,6 +2283,7 @@
cost_text = planner_format_float (cost, 2, FALSE);
g_object_set (cell, "text", cost_text, NULL);
+ g_free (cost_text);
}
static void
Modified: trunk/src/planner-table-print-sheet.c
==============================================================================
--- trunk/src/planner-table-print-sheet.c (original)
+++ trunk/src/planner-table-print-sheet.c Wed Nov 5 19:54:02 2008
@@ -26,13 +26,12 @@
#include <gtk/gtk.h>
#include <libplanner/planner.h>
#include <glib/gi18n.h>
-#include <libgnomeprint/gnome-print.h>
#include "planner-print-job.h"
#include "planner-table-print-sheet.h"
#define d(x)
-#define TEXT_IN_CELL_MULTI 0.67
+#define TEXT_IN_CELL_MULTI 0.75
#define INDENT_FACTOR 4
#define PRINT_ROW(o) ((PrintRow *) o)
@@ -75,7 +74,7 @@
GSList *pages;
/* Used during creation */
- GnomeFont *font;
+ PangoFontDescription *font;
GSList *columns;
GSList *rows;
gdouble row_height;
@@ -146,7 +145,7 @@
GtkCellRenderer *cell;
PangoWeight weight;
gint depth = 0;
-
+
if (row->header) {
table_print_sheet_print_header_cell (sheet, column, row, x, y);
return;
@@ -170,6 +169,8 @@
"text", &str,
"weight", &weight,
NULL);
+ g_object_ref_sink (cell);
+ g_object_unref (cell);
if (!str) {
return;
@@ -198,6 +199,8 @@
planner_print_job_begin_next_page (sheet->job);
+ cairo_set_line_width (sheet->job->cr, THIN_LINE_WIDTH);
+
for (r = page->rows; r; r = r->next) {
for (c = page->columns; c; c = c->next) {
table_print_sheet_print_cell (sheet,
@@ -210,14 +213,14 @@
planner_print_job_lineto (sheet->job,
x,
y + PRINT_ROW (r->data)->height);
- gnome_print_stroke (sheet->job->pc);
+ cairo_stroke (sheet->job->cr);
}
y += PRINT_ROW (r->data)->height;
planner_print_job_moveto (sheet->job, 0, y);
planner_print_job_lineto (sheet->job, x, y);
- gnome_print_stroke (sheet->job->pc);
+ cairo_stroke (sheet->job->cr);
x = 0;
}
@@ -231,13 +234,16 @@
gboolean expander_column)
{
PrintColumn *column;
+ gdouble ext;
column = g_new0 (PrintColumn, 1);
column->tree_column = tree_column;
column->expander_column = expander_column;
column->name = g_strdup (gtk_tree_view_column_get_title (tree_column));
- column->width = gnome_font_get_width_utf8 (sheet->font, column->name) + 3 * sheet->x_pad;
+ planner_print_job_set_font_bold (sheet->job);
+ ext = planner_print_job_get_extents (sheet->job, column->name);
+ column->width = ext + 3 * sheet->x_pad;
column->data_func = g_object_get_data (G_OBJECT (tree_column),
"data-func");
@@ -260,6 +266,7 @@
gint depth;
GtkTreeIter parent_iter;
GtkTreePath *parent_path = NULL;
+ gdouble ext;
d(g_print ("%s\n", gtk_tree_path_to_string (path)));
@@ -280,7 +287,7 @@
sheet->rows = g_slist_prepend (sheet->rows, row);
cell = gtk_cell_renderer_text_new ();
-
+
/* Loop through the columns to update widths */
for (l = sheet->columns; l; l = l->next) {
PrintColumn *column = PRINT_COL (l->data);
@@ -300,14 +307,19 @@
extra += depth * INDENT_FACTOR * sheet->x_pad;
}
-
+ ext = 0;
+ if(str) {
+ ext = planner_print_job_get_extents (sheet->job, str);
+ }
column->width = MAX (column->width,
- (str ? gnome_font_get_width_utf8 (sheet->font, str) : 0)
+ ext
+ extra);
/* d(g_print ("New width: %f\n", column->width)); */
-
g_free (str);
}
+
+ g_object_ref_sink (cell);
+ g_object_unref (cell);
}
if (parent_path) {
gtk_tree_path_free (parent_path);
@@ -357,7 +369,7 @@
d(g_print ("sheet_create_pages (in loop): Adding a page\n"));
sheet->pages = g_slist_prepend (sheet->pages, page);
}
-
+
page->width += column->width;
page->columns = g_slist_append (page->columns, column);
p = l;
@@ -528,13 +540,12 @@
}
void
-planner_table_print_sheet_output (PlannerTablePrintSheet *sheet)
+planner_table_print_sheet_output (PlannerTablePrintSheet *sheet,
+ gint page_nr)
{
- GSList *p;
-
- for (p = sheet->pages; p; p = p->next) {
- table_print_sheet_print_page (sheet, PRINT_PAGE (p->data));
- }
+ PrintPage *page = PRINT_PAGE(g_slist_nth_data (sheet->pages, page_nr));
+ g_assert(page != NULL);
+ table_print_sheet_print_page(sheet, page);
}
gint
@@ -550,13 +561,10 @@
{
GSList *l;
- /* This won't work since several pages will have pointers to the */
- /* same columns/rows */
-
for (l = sheet->pages; l; l = l->next) {
PrintPage *page = PRINT_PAGE (l->data);
- /* The sheet holds the a list with all the structs and */
+ /* The sheet holds a list with all the structs and */
/* is responsible for freeing those */
g_slist_free (page->columns);
g_slist_free (page->rows);
Modified: trunk/src/planner-table-print-sheet.h
==============================================================================
--- trunk/src/planner-table-print-sheet.h (original)
+++ trunk/src/planner-table-print-sheet.h Wed Nov 5 19:54:02 2008
@@ -29,11 +29,12 @@
typedef struct _PlannerTablePrintSheet PlannerTablePrintSheet;
-void planner_table_print_sheet_output (PlannerTablePrintSheet *sheet);
-gint planner_table_print_sheet_get_n_pages (PlannerTablePrintSheet *sheet);
+void planner_table_print_sheet_output (PlannerTablePrintSheet *sheet,
+ gint page_nr);
+gint planner_table_print_sheet_get_n_pages (PlannerTablePrintSheet *sheet);
PlannerTablePrintSheet *planner_table_print_sheet_new (PlannerView *view,
- PlannerPrintJob *job,
- GtkTreeView *tree);
-void planner_table_print_sheet_free (PlannerTablePrintSheet *sheet);
+ PlannerPrintJob *job,
+ GtkTreeView *tree);
+void planner_table_print_sheet_free (PlannerTablePrintSheet *sheet);
#endif /* __PLANNER_TABLE_PRINT_SHEET_H__ */
Modified: trunk/src/planner-task-view.c
==============================================================================
--- trunk/src/planner-task-view.c (original)
+++ trunk/src/planner-task-view.c Wed Nov 5 19:54:02 2008
@@ -59,7 +59,8 @@
static GtkWidget *task_view_get_widget (PlannerView *view);
static void task_view_print_init (PlannerView *view,
PlannerPrintJob *job);
-static void task_view_print (PlannerView *view);
+static void task_view_print (PlannerView *view,
+ gint page_nr);
static gint task_view_print_get_n_pages (PlannerView *view);
static void task_view_print_cleanup (PlannerView *view);
static void task_view_tree_view_columns_changed_cb (GtkTreeView *tree_view,
@@ -662,14 +663,14 @@
}
static void
-task_view_print (PlannerView *view)
-
+task_view_print (PlannerView *view,
+ gint page_nr)
{
PlannerTaskViewPriv *priv;
priv = PLANNER_TASK_VIEW (view)->priv;
- planner_table_print_sheet_output (priv->print_sheet);
+ planner_table_print_sheet_output (priv->print_sheet, page_nr);
}
static gint
@@ -684,7 +685,6 @@
static void
task_view_print_cleanup (PlannerView *view)
-
{
PlannerTaskViewPriv *priv;
Modified: trunk/src/planner-usage-view.c
==============================================================================
--- trunk/src/planner-usage-view.c (original)
+++ trunk/src/planner-usage-view.c Wed Nov 5 19:54:02 2008
@@ -94,7 +94,8 @@
static GtkWidget * usage_view_get_widget (PlannerView *view);
static void usage_view_print_init (PlannerView *view,
PlannerPrintJob *job);
-static void usage_view_print (PlannerView *view);
+static void usage_view_print (PlannerView *view,
+ gint page_nr);
static gint usage_view_print_get_n_pages (PlannerView *view);
static void usage_view_print_cleanup (PlannerView *view);
static void usage_view_save_columns (PlannerUsageView *view);
@@ -277,7 +278,7 @@
}
static void
-usage_view_print (PlannerView *view)
+usage_view_print (PlannerView *view, gint page_nr)
{
/*planner_usage_print_do (PLANNER_USAGE_VIEW (view)->priv->print_data);*/
}
Modified: trunk/src/planner-view.c
==============================================================================
--- trunk/src/planner-view.c (original)
+++ trunk/src/planner-view.c Wed Nov 5 19:54:02 2008
@@ -157,12 +157,12 @@
}
void
-planner_view_print (PlannerView *view)
+planner_view_print (PlannerView *view, gint page_nr)
{
g_return_if_fail (PLANNER_IS_VIEW (view));
if (PLANNER_VIEW_GET_CLASS (view)->print) {
- PLANNER_VIEW_GET_CLASS (view)->print (view);
+ PLANNER_VIEW_GET_CLASS (view)->print (view, page_nr);
}
}
Modified: trunk/src/planner-view.h
==============================================================================
--- trunk/src/planner-view.h (original)
+++ trunk/src/planner-view.h Wed Nov 5 19:54:02 2008
@@ -50,7 +50,7 @@
const gchar *(*get_icon) (PlannerView *view);
const gchar *(*get_name) (PlannerView *view);
GtkWidget *(*get_widget) (PlannerView *view);
- void (*setup) (PlannerView *view,
+ void (*setup) (PlannerView *view,
PlannerWindow *window);
void (*activate) (PlannerView *view);
void (*deactivate) (PlannerView *view);
@@ -58,7 +58,8 @@
void (*print_init) (PlannerView *view,
PlannerPrintJob *job);
gint (*print_get_n_pages) (PlannerView *view);
- void (*print) (PlannerView *view);
+ void (*print) (PlannerView *view,
+ gint page_nr);
void (*print_cleanup) (PlannerView *view);
};
@@ -80,7 +81,8 @@
void planner_view_print_init (PlannerView *view,
PlannerPrintJob *job);
gint planner_view_print_get_n_pages (PlannerView *view);
-void planner_view_print (PlannerView *view);
+void planner_view_print (PlannerView *view,
+ gint page_nr);
void planner_view_print_cleanup (PlannerView *view);
void planner_view_column_load_helper (PlannerView *view,
GtkTreeView *tree);
Modified: trunk/src/planner-window.c
==============================================================================
--- trunk/src/planner-window.c (original)
+++ trunk/src/planner-window.c Wed Nov 5 19:54:02 2008
@@ -29,8 +29,6 @@
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gtk/gtk.h>
#include <glade/glade.h>
-#include <libgnomeprintui/gnome-print-dialog.h>
-#include <libgnomeprintui/gnome-print-job-preview.h>
#include <libplanner/mrp-error.h>
#include <libplanner/mrp-project.h>
#include <libplanner/mrp-paths.h>
@@ -129,9 +127,9 @@
gpointer data);
static void window_save_cb (GtkAction *action,
gpointer data);
-static void window_print_cb (GtkAction *action,
+static void window_page_setup_cb (GtkAction *action,
gpointer data);
-static void window_print_preview_cb (GtkAction *action,
+static void window_print_cb (GtkAction *action,
gpointer data);
static void window_close_cb (GtkAction *action,
gpointer data);
@@ -248,12 +246,15 @@
{ "FileSaveAs",
GTK_STOCK_SAVE_AS, N_("Save _As..."), "<Shift><Control>s", N_("Save the current project with a different name"),
G_CALLBACK (window_save_as_cb) },
+ { "FilePageSetup",
+ NULL, N_("Page Set_up..."), NULL, N_("Setup the page settings for your current printer"),
+ G_CALLBACK (window_page_setup_cb) },
{ "FilePrint",
GTK_STOCK_PRINT, N_("_Print..."), "<Control>p", N_("Print the current project"),
G_CALLBACK (window_print_cb) },
{ "FilePrintPreview",
GTK_STOCK_PRINT_PREVIEW, N_("Print Pre_view"), "<Shift><Control>p", N_("Print preview of the current project"),
- G_CALLBACK (window_print_preview_cb) },
+ G_CALLBACK (window_print_cb) },
{ "FileClose",
GTK_STOCK_CLOSE, N_("_Close"), "<Control>w", N_("Close the current file"),
G_CALLBACK (window_close_cb) },
@@ -913,234 +914,93 @@
window_do_save (window, FALSE);
}
-static GList *
-window_get_print_selection (PlannerWindow *window)
-{
- PlannerWindowPriv *priv;
- GList *views = NULL, *l;
- PlannerView *view;
- gchar *str;
-
- priv = window->priv;
-
- for (l = priv->views; l; l = l->next) {
- view = l->data;
-
- str = g_strdup_printf ("/views/%s/print_enabled",
- planner_view_get_name (view));
- if (planner_conf_get_bool (str, NULL)) {
- views = g_list_append (views, view);
- }
-
- g_free (str);
- }
-
- return views;
-}
-
static void
-window_print_preview_cb (GtkAction *action,
- gpointer data)
+window_page_setup_cb (GtkAction *action,
+ gpointer data)
{
PlannerWindow *window;
PlannerWindowPriv *priv;
- GnomePrintConfig *config;
- GnomePrintJob *gpj;
- GtkWidget *dialog;
- GtkWidget *preview;
- GList *views, *l;
- PlannerView *view;
- PlannerPrintJob *job;
- gboolean summary;
- gint n_pages, n_views;
- gint response;
-
+ GtkPageSetup *old_page_setup, *new_page_setup;
+ GtkPrintSettings *settings;
+
window = PLANNER_WINDOW (data);
priv = window->priv;
- /* Load printer settings */
- config = planner_print_dialog_load_config ();
- gpj = gnome_print_job_new (config);
- gnome_print_config_unref (config);
-
- job = planner_print_job_new (gpj);
-
- views = window_get_print_selection (window);
-
- /* Check to be sure there are some views selected */
- n_views = g_list_length (views);
- if (n_views == 0) {
- dialog = planner_print_views_dialog_new (window, priv->views);
-
- while (n_views == 0) {
-
- response = gtk_dialog_run (GTK_DIALOG (dialog));
-
- if (response == GTK_RESPONSE_CANCEL) {
- gtk_widget_destroy (dialog);
- g_object_unref (gpj);
- return;
- }
- else if (response == GTK_RESPONSE_DELETE_EVENT) {
- gtk_widget_destroy (dialog);
- g_object_unref (gpj);
- return;
- }
-
- /* Save printer settings. */
- planner_print_dialog_save_config (config);
-
- views = planner_print_dialog_get_print_selection (GTK_DIALOG (dialog), &summary);
- n_views = g_list_length (views);
- }
- gtk_widget_destroy (dialog);
- }
-
- n_pages = 0;
- for (l = views; l; l = l->next) {
- view = l->data;
-
- planner_view_print_init (view, job);
-
- n_pages += planner_view_print_get_n_pages (view);
- }
-
- planner_print_job_set_total_pages (job, n_pages);
-
- for (l = views; l; l = l->next) {
- view = l->data;
-
- planner_view_print (view);
+ settings = planner_print_dialog_load_print_settings ();
+ old_page_setup = planner_print_dialog_load_page_setup ();
- planner_view_print_cleanup (view);
- }
+ new_page_setup = gtk_print_run_page_setup_dialog (GTK_WINDOW (window), old_page_setup, settings);
- gnome_print_job_close (job->pj);
-
- preview = gnome_print_job_preview_new (job->pj, "Planner");
- gtk_widget_show (preview);
+ g_object_unref (old_page_setup);
- g_list_free (views);
+ planner_print_dialog_save_page_setup (new_page_setup);
+ planner_print_dialog_save_print_settings (settings);
- g_object_unref (job);
+ g_object_unref (new_page_setup);
+ g_object_unref (settings);
}
static void
window_print_cb (GtkAction *action,
gpointer data)
{
- PlannerWindow *window;
- PlannerWindowPriv *priv;
- GnomePrintJob *gpj;
- GnomePrintConfig *config;
- GtkWidget *dialog, *message;
- gint response;
- gboolean summary;
- GList *views, *l;
- PlannerView *view;
- PlannerPrintJob *job;
- gint n_pages, n_views;
-
+ PlannerWindow *window;
+ PlannerWindowPriv *priv;
+ GtkPrintOperation *print;
+ GtkPrintSettings *settings;
+ GtkPageSetup *page_setup;
+ PlannerPrintJob *job;
+ GError *error = NULL;
+ GtkPrintOperationResult res;
+ GtkPrintOperationAction print_action;
+
window = PLANNER_WINDOW (data);
priv = window->priv;
/* Load printer settings */
- config = planner_print_dialog_load_config ();
- gpj = gnome_print_job_new (config);
- gnome_print_config_unref (config);
-
- dialog = planner_print_dialog_new (data, gpj, priv->views);
+ print = gtk_print_operation_new ();
- /* n_views is the number of views selected. */
- n_views = 0;
- while (n_views == 0) {
+ settings = planner_print_dialog_load_print_settings ();
+ gtk_print_operation_set_print_settings (print, settings);
+ g_object_unref (settings);
+ settings = NULL;
+
+ page_setup = planner_print_dialog_load_page_setup ();
+ gtk_print_operation_set_default_page_setup (print, page_setup);
+ g_object_unref (page_setup);
+ page_setup = NULL;
- response = gtk_dialog_run (GTK_DIALOG (dialog));
+ job = planner_print_job_new (print, priv->views);
- if (response == GTK_RESPONSE_CANCEL) {
- gtk_widget_destroy (dialog);
- g_object_unref (gpj);
- return;
- }
- else if (response == GTK_RESPONSE_DELETE_EVENT) {
- g_object_unref (gpj);
- return;
- }
-
- /* Save printer settings. */
- planner_print_dialog_save_config (config);
-
- views = planner_print_dialog_get_print_selection (GTK_DIALOG (dialog), &summary);
- n_views = g_list_length (views);
-
- if (n_views == 0) {
+ if (!strcmp (gtk_action_get_name (action), "FilePrint")) {
+ print_action = GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG;
+ } else {
+ print_action = GTK_PRINT_OPERATION_ACTION_PREVIEW;
+ }
- message = gtk_message_dialog_new (GTK_WINDOW (dialog),
- GTK_DIALOG_MODAL |
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_INFO,
- GTK_BUTTONS_OK,
- "%s", "Please choose one or more views to print.");
-
- gtk_dialog_run (GTK_DIALOG (message));
- gtk_widget_destroy (message);
+ res = gtk_print_operation_run (print, print_action, GTK_WINDOW (window), &error);
- }
- }
-
- if (summary) {
- /*g_print ("Print summary\n");*/
- }
-
- job = planner_print_job_new (gpj);
-
- n_pages = 0;
- for (l = views; l; l = l->next) {
- view = l->data;
- planner_view_print_init (view, job);
+ if (res == GTK_PRINT_OPERATION_RESULT_ERROR) {
+ GtkWidget *dialog;
- n_pages += planner_view_print_get_n_pages (view);
- }
-
- planner_print_job_set_total_pages (job, n_pages);
-
- for (l = views; l; l = l->next) {
- view = l->data;
+ dialog = gtk_message_dialog_new (GTK_WINDOW (window),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CLOSE,
+ "%s", error->message);
+ g_error_free (error);
- planner_view_print (view);
- planner_view_print_cleanup (view);
- }
-
- gtk_widget_destroy (dialog);
-
- gnome_print_job_close (job->pj);
-
- if (response == GNOME_PRINT_DIALOG_RESPONSE_PREVIEW) {
- GtkWidget *preview;
+ g_signal_connect (dialog, "response",
+ G_CALLBACK (gtk_widget_destroy), NULL);
- preview = gnome_print_job_preview_new (job->pj, "Planner");
- gtk_widget_show (preview);
+ gtk_widget_show (dialog);
}
- else if (response == GNOME_PRINT_DIALOG_RESPONSE_PRINT) {
- gchar *tmp;
-
- /* This seems to be needed for now to stop older versions of
- * gnome-print from outputting locale dependent floats. Remove
- * this later.
- */
- tmp = g_strdup (setlocale (LC_NUMERIC, NULL));
- setlocale (LC_NUMERIC, "C");
-
- gnome_print_job_print (job->pj);
-
- setlocale (LC_NUMERIC, tmp);
- g_free (tmp);
+ else if (res == GTK_PRINT_OPERATION_RESULT_APPLY) {
+ settings = gtk_print_operation_get_print_settings (print);
+ planner_print_dialog_save_print_settings (settings);
}
-
- g_list_free (views);
-
+ g_object_unref (print);
g_object_unref (job);
- g_object_unref (config);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]