Commit 722f98d8 authored by Maurice van der Pot's avatar Maurice van der Pot Committed by Maurice van der Pot

Removed unused function. Commented out unused functions.

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.


svn path=/trunk/; revision=937
parent 75debef0
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.
2008-09-01 Maurice van der Pot <griffon26@kfk4ever.com>
* src/planner-usage-row.c (usage_row_draw_resource_ival),
......
......@@ -70,7 +70,6 @@ GTK_REQUIRED=2.6.0
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 @@ PKG_CHECK_MODULES(PLANNER,
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
])
......
......@@ -13,6 +13,7 @@
<placeholder name="Export placeholder"/>
</menu>
<separator/>
<menuitem action="FilePageSetup"/>
<menuitem action="FilePrint"/>
<menuitem action="FilePrintPreview"/>
<separator/>
......
......@@ -96,8 +96,6 @@ static void mpp_xml_set_task_type (xmlNodePtr node,
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 @@ mrp_parser_from_xml (MrpStorageMrproject *module,
* 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)
{
......
......@@ -679,6 +679,8 @@ mrp_task_manager_dump_task_list (MrpTaskManager *manager)
/* ------------------------------------------------------------------------ */
/* 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 @@ task_manager_traverse_dependency_graph (MrpTaskManager *manager,
*output = g_list_prepend (*output, task);
}
}
#endif
static void
dump_task_node (MrpTask *task)
......
This diff is collapsed.
......@@ -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 @@ PlannerGanttPrintData * planner_gantt_print_data_new (PlannerView
void planner_gantt_print_data_free (PlannerGanttPrintData *data);
#endif /* __PLANNER_GANTT_PRINT_JOB_H__ */
#endif /* __PLANNER_GANTT_PRINT_H__ */
......@@ -125,7 +125,8 @@ static const gchar *gantt_view_get_name (PlannerView *vi
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 @@ gantt_view_print_init (PlannerView *view,
}
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
......
......@@ -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 @@ get_config_filename (void)
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 @@ planner_print_dialog_save_config (GnomePrintConfig *config)
}
}
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);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), page);
gtk_widget_show_all (dialog);
return dialog;
}
GtkWidget *
planner_print_dialog_new (PlannerWindow *window,
GnomePrintJob *job,
GList *views)
{
GtkWidget *dialog;
GtkWidget *page;
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) {
settings = gtk_print_settings_new_from_key_file (key_file, NULL, NULL);
}
if (settings == NULL) {
settings = gtk_print_settings_new ();
}
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 @@ print_dialog_create_page (PlannerWindow *window,
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 @@ print_dialog_create_page (PlannerWindow *window,
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 @@ print_dialog_create_page (PlannerWindow *window,
}
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 @@ planner_print_dialog_get_print_selection (GtkDialog *dialog,
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 @@ planner_print_dialog_get_print_selection (GtkDialog *dialog,
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;
}
......@@ -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__ */
......
......@@ -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 @@ struct _PlannerPrintJobPriv {
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 @@ print_job_finalize (GObject *object)
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 @@ print_job_transform (PlannerPrintJob *job, gdouble *x, gdouble *y)
}
if (y) {
*y = job->height - *y + MARGIN;
*y += MARGIN;
}
}
......@@ -162,59 +159,169 @@ print_job_update_size (PlannerPrintJob *job)
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) +