gyrus r356 - in trunk: . src
- From: csaavedra svn gnome org
- To: svn-commits-list gnome org
- Subject: gyrus r356 - in trunk: . src
- Date: Sun, 12 Oct 2008 11:18:19 +0000 (UTC)
Author: csaavedra
Date: Sun Oct 12 11:18:19 2008
New Revision: 356
URL: http://svn.gnome.org/viewvc/gyrus?rev=356&view=rev
Log:
2008-10-12 Claudio Saavedra <csaavedra igalia com>
* configure.in: Replace libgnomeprintui checks with gtkprint checks.
* src/gyrus-report.c: (gyrus_report_show_report),
(gyrus_report_on_button_cancel_clicked),
(gyrus_report_on_button_update_clicked), (begin_print),
(draw_page), (gyrus_report_on_button_print_clicked): Port the report
to printing to GtkPrint.
Remove dependence on obsolete libgnomeprintui.
Modified:
trunk/ChangeLog
trunk/configure.in
trunk/src/gyrus-report.c
Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in (original)
+++ trunk/configure.in Sun Oct 12 11:18:19 2008
@@ -26,7 +26,7 @@
LIBGNOMEUI_REQUIRED=2.6.0
GNET_REQUIRED=2.0.0
GCONF_REQUIRED=2.0.0
-LIBGNOMEPRINTUI_REQUIRED=2.10
+GTK_PRINT_REQUIRED=2.10.0
PKG_CHECK_MODULES(GYRUS,
gtk+-2.0 >= $GTK_REQUIRED
@@ -34,7 +34,7 @@
libgnomeui-2.0 >= $LIBGNOMEUI_REQUIRED
gnet-2.0 >= $GNET_REQUIRED
gconf-2.0 >= $GCONF_REQUIRED
- libgnomeprintui-2.2 >= $LIBGNOMEPRINTUI_REQUIRED)
+ gtk+-unix-print-2.0 >= $GTK_PRINT_REQUIRED)
AC_ARG_ENABLE(gnutls,
AC_HELP_STRING([--enable-gnutls],
Modified: trunk/src/gyrus-report.c
==============================================================================
--- trunk/src/gyrus-report.c (original)
+++ trunk/src/gyrus-report.c Sun Oct 12 11:18:19 2008
@@ -30,21 +30,18 @@
#include "gyrus-admin-mailbox.h"
#include "gyrus-common.h"
#include <string.h>
+#include <math.h>
-#include <libgnomeprint/gnome-print.h>
-#include <libgnomeprint/gnome-print-job.h>
-#include <libgnomeprintui/gnome-print-dialog.h>
-#include <libgnomeprintui/gnome-print-job-preview.h>
-
-#define MAX_USER_PAGE 40 /* maximun user for page */
-#define XINI 25 /* initial value X */
-#define YINI 740 /* initial value Y */
-#define XLIN 550 /* width of line */
+#define HEADER_HEIGHT (10*72/25.4)
+#define HEADER_GAP (3*72/25.4)
+#define TITLE_HEIGHT (8*72/25.4)
+#define TITLE_GAP (3*72/25.4)
typedef struct _GyrusReportData {
GyrusAdmin *admin;
gdouble n_percen;
+ gint num_users;
gchar *mailbox_temp;
GtkWidget *button_print;
@@ -52,14 +49,11 @@
GtkWidget *spin_report;
GtkTreeView *treeview_report;
- GnomePrintContext *gpc;
- GnomeFont *font;
- gint xini;
- gint yini;
- gint xlin;
- gint nlin;
- gint page;
-
+ gfloat font_size;
+ gint lines_per_page;
+ gint num_pages;
+ gint num_lines;
+ gchar *title;
} GyrusReportData;
typedef enum {
@@ -77,10 +71,6 @@
static GtkTreeView * gyrus_report_initialize_tree_view (GtkTreeView *treeview_report);
static void gyrus_report_on_delete_event_window_report (GtkWidget *widget, GdkEvent *event, GyrusReportData *report);
static void gyrus_report_on_button_print_clicked(GtkWidget *widget, GyrusReportData *report);
-static void gyrus_report_create_print (GnomePrintJob *job, gboolean preview, GyrusReportData *report);
-static void gyrus_report_create_data_page (GyrusReportData *report);
-static gboolean gyrus_report_print_quota (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data);
-static void gyrus_report_draw_begin (GyrusReportData *report);
/* read glade file, connect signal and show window */
void
@@ -88,7 +78,6 @@
{
GladeXML *xml;
gchar *file_glade;
- gchar *title;
GtkWidget *button_cancel;
GtkWidget *button_preview;
@@ -115,10 +104,10 @@
gtk_widget_set_sensitive (report->button_print, FALSE);
/* set title */
- title = g_strdup_printf (_("Report: %s"),
- gyrus_admin_get_current_session_name (admin));
- gtk_window_set_title (GTK_WINDOW(report->window_report),title);
-
+ report->title = g_strdup_printf (_("Mailbox space usage report for %s"),
+ gyrus_admin_get_current_session_name (admin));
+ gtk_window_set_title (GTK_WINDOW (report->window_report), report->title);
+
/* initialize treeview_report */
report->treeview_report = gyrus_report_initialize_tree_view (report->treeview_report);
@@ -141,7 +130,6 @@
gtk_widget_show_all (report->window_report);
g_object_unref (xml);
- g_free (title);
g_free (file_glade);
}
@@ -261,6 +249,7 @@
GyrusReportData *report)
{
gtk_widget_destroy (report->window_report);
+ g_free (report->title);
g_free (report);
}
@@ -272,7 +261,6 @@
GtkListStore *store;
GtkTreeViewColumn *column;
GtkTreeView *treeview;
- gint n_users;
gchar *msg;
GyrusAdmin *admin;
GtkTreeModel *model;
@@ -294,15 +282,15 @@
gtk_tree_model_foreach (model, gyrus_report_evaluate_quota, report);
/* get the number of users in the tree */
- n_users = gtk_tree_model_iter_n_children (GTK_TREE_MODEL(store), NULL);
+ report->num_users = gtk_tree_model_iter_n_children (GTK_TREE_MODEL(store), NULL);
column = gtk_tree_view_get_column
(GTK_TREE_VIEW(report->treeview_report), 0);
- msg = g_strdup_printf (_("Users (%d)"), n_users);
+ msg = g_strdup_printf (_("Users (%d)"), report->num_users);
gtk_tree_view_column_set_title (column, msg);
/* enable/disable button print */
- if (n_users > 0){
+ if (report->num_users > 0){
gtk_widget_set_sensitive (report->button_print, TRUE);
}else{
gtk_widget_set_sensitive (report->button_print, FALSE);
@@ -407,190 +395,212 @@
return FALSE;
}
-/* show print dialog */
static void
-gyrus_report_on_button_print_clicked(GtkWidget *widget, GyrusReportData *report)
+begin_print (GtkPrintOperation *operation,
+ GtkPrintContext *context,
+ gpointer user_data)
{
- GnomePrintJob *job;
- GtkWidget *dialog;
- gint response;
-
- /* Create the objects */
- job = gnome_print_job_new (NULL);
- dialog = gnome_print_dialog_new (job, (guchar *)_("Print Report"), 0);
+ GyrusReportData *report;
+ double height;
- /* Run the dialog */
- response = gnome_print_dialog_run (GNOME_PRINT_DIALOG (dialog));
- switch (response) {
- case GNOME_PRINT_DIALOG_RESPONSE_PRINT:
- gyrus_report_create_print (job, FALSE, report);
- gtk_widget_destroy (dialog);
- break;
- case GNOME_PRINT_DIALOG_RESPONSE_PREVIEW:
- gyrus_report_create_print (job, TRUE, report);
- gtk_widget_destroy (dialog);
- break;
- case GNOME_PRINT_DIALOG_RESPONSE_CANCEL:
- gnome_print_job_close (job);
- gtk_widget_destroy (dialog);
- break;
- default:
- return;
- }
+ report = (GyrusReportData *) user_data;
-
- ///gnome_print_job_close (job);
- g_object_unref (G_OBJECT (job));
+ height = gtk_print_context_get_height (context) - HEADER_HEIGHT - HEADER_GAP - TITLE_HEIGHT - TITLE_GAP;
+ report->lines_per_page = floor (height / report->font_size);
+ report->num_pages = (report->num_users - 1) / report->lines_per_page + 1;
+ gtk_print_operation_set_n_pages (operation, report->num_pages);
}
-
-/* create job to print */
static void
-gyrus_report_create_print (GnomePrintJob *job, gboolean preview, GyrusReportData *report)
-{
- report->gpc = gnome_print_job_get_context (job);
+draw_page (GtkPrintOperation *operation,
+ GtkPrintContext *context,
+ gint page_nr,
+ gpointer user_data)
+{
+ cairo_t *cr;
+ PangoLayout *layout;
+ gint text_width, text_height;
+ gdouble width;
+ gint line, i;
+ PangoFontDescription *desc;
+ gchar *page_str;
+ GyrusReportData *report;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
- /* generate report to print */
- gyrus_report_create_data_page (report);
+ report = (GyrusReportData *)user_data;
- gnome_print_job_close (job);
+ cr = gtk_print_context_get_cairo_context (context);
+ width = gtk_print_context_get_width (context);
- if (!preview) {
- ///my_status_bar_print ("Printing ...");
- gnome_print_job_print (job);
- } else {
- ///my_status_bar_print ("Print previewing ...");
- gtk_widget_show (gnome_print_job_preview_new (job, (guchar *)_("Preview")));
- }
+ cairo_rectangle (cr, 0, 0, width, HEADER_HEIGHT);
- g_object_unref (G_OBJECT (report->gpc));
-}
+ cairo_set_source_rgb (cr, 0.8, 0.8, 0.8);
+ cairo_fill_preserve (cr);
-/* print top data */
-static void
-gyrus_report_draw_begin (GyrusReportData *report)
-{
- guchar *page_name;
-
- report->xini = XINI;
- report->yini = YINI;
- report->xlin = XLIN;
-
- /* print page numbre */
- page_name = (guchar *) g_strdup_printf ("%d", report->page);
- gnome_print_beginpage (report->gpc, page_name);
- g_free (page_name);
-
- /* draw line top */
- gnome_print_moveto (report->gpc, report->xini, report->yini);
- gnome_print_lineto (report->gpc, report->xlin, report->yini);
- gnome_print_stroke (report->gpc);
-
- /* titles */
- gnome_print_moveto (report->gpc, report->xini + 10, report->yini - 20);
- gnome_print_show (report->gpc, (guchar *) _("User"));
-
- gnome_print_moveto (report->gpc, report->xini + 120, report->yini - 20);
- gnome_print_show (report->gpc, (guchar *) _("Quota (%)"));
+ cairo_set_source_rgb (cr, 0, 0, 0);
+ cairo_set_line_width (cr, 1);
+ cairo_stroke (cr);
- gnome_print_moveto (report->gpc, report->xini + 240, report->yini - 20);
- gnome_print_show (report->gpc, (guchar *) _("Assigned (KB)"));
+ layout = gtk_print_context_create_pango_layout (context);
- gnome_print_moveto (report->gpc, report->xini + 360, report->yini - 20);
- gnome_print_show (report->gpc, (guchar *) _("Used (KB)"));
-
- /* other line */
- gnome_print_moveto (report->gpc, report->xini, report->yini - 30);
- gnome_print_lineto (report->gpc, report->xlin, report->yini - 30);
- gnome_print_stroke (report->gpc);
+ desc = pango_font_description_from_string ("sans 14");
+ pango_layout_set_font_description (layout, desc);
+ pango_font_description_free (desc);
- report->yini = report->yini - 50;
-}
+ pango_layout_set_text (layout, report->title, -1);
+ pango_layout_get_pixel_size (layout, &text_width, &text_height);
+ if (text_width > width) {
+ pango_layout_set_width (layout, width);
+ pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_START);
+ pango_layout_get_pixel_size (layout, &text_width, &text_height);
+ }
-/* sent to print each user, initialize number of page, number of line. */
-static void
-gyrus_report_create_data_page (GyrusReportData *report)
-{
- GtkTreeModel *model;
- const guchar font[24] = "Sans Regular";
- /* count number of user printed */
- report->nlin = 1;
-
- /* number of pages */
- report->page = 1;
-
- /* define font and size */
- report->font = gnome_font_find_closest (font, 8);
- g_assert (report->font);
-
- gyrus_report_draw_begin (report);
+ cairo_move_to (cr, (width - text_width) / 2, (HEADER_HEIGHT - text_height) / 2);
+ pango_cairo_show_layout (cr, layout);
+
+ /* Translators: this represents the number of pages being printed. */
+ page_str = g_strdup_printf (_("%d/%d"), page_nr + 1, report->num_pages);
+ pango_layout_set_text (layout, page_str, -1);
+ g_free (page_str);
+
+ pango_layout_set_width (layout, -1);
+ pango_layout_get_pixel_size (layout, &text_width, &text_height);
+ cairo_move_to (cr, width - text_width - 4, (HEADER_HEIGHT - text_height) / 2);
+ pango_cairo_show_layout (cr, layout);
+
+ g_object_unref (layout);
+
+ layout = gtk_print_context_create_pango_layout (context);
+
+ desc = pango_font_description_from_string ("sans");
+ pango_font_description_set_size (desc, report->font_size * PANGO_SCALE);
+ pango_layout_set_font_description (layout, desc);
+ pango_font_description_free (desc);
- /* get model of treeview users */
model = gtk_tree_view_get_model (report->treeview_report);
- gtk_tree_model_foreach (model, gyrus_report_print_quota, report);
-
- gnome_print_showpage (report->gpc);
+
+ pango_layout_get_pixel_size (layout, &text_width, &text_height);
+ cairo_move_to (cr, 0, HEADER_HEIGHT + HEADER_GAP + (TITLE_HEIGHT - text_height)/2);
+
+ pango_layout_set_text (layout, _("User"), -1);
+ pango_cairo_show_layout (cr, layout);
+ cairo_rel_move_to (cr, 130, 0);
+
+ pango_layout_set_text (layout, _("Quota (%)"), -1);
+ pango_cairo_show_layout (cr, layout);
+ cairo_rel_move_to (cr, 120, 0);
+
+ pango_layout_set_text (layout, _("Assigned (KB)"), -1);
+ pango_cairo_show_layout (cr, layout);
+ cairo_rel_move_to (cr, 120, 0);
+
+ pango_layout_set_text (layout, _("Used (KB)"), -1);
+ pango_cairo_show_layout (cr, layout);
+
+ g_object_unref (layout);
+
+ cairo_set_source_rgb (cr, 0, 0, 0);
+ cairo_move_to (cr, 0, HEADER_HEIGHT + HEADER_GAP + TITLE_HEIGHT);
+ cairo_rel_line_to (cr, width, 0);
+ cairo_set_line_width (cr, 1);
+ cairo_stroke (cr);
+
+ layout = gtk_print_context_create_pango_layout (context);
+
+ desc = pango_font_description_from_string ("sans");
+ pango_font_description_set_size (desc, report->font_size * PANGO_SCALE);
+ pango_layout_set_font_description (layout, desc);
+ pango_font_description_free (desc);
+
+ pango_layout_get_pixel_size (layout, &text_width, &text_height);
+ cairo_move_to (cr, 0, HEADER_HEIGHT + HEADER_GAP + TITLE_HEIGHT + TITLE_GAP);
+
+ gtk_tree_model_get_iter_first (model, &iter);
+
+ line = page_nr * report->lines_per_page;
+
+ for (i = 0; i < report->lines_per_page && line < report->num_users; i++) {
+ gint quota;
+ gint assigned;
+ gint used;
+ gchar *str;
+ gchar *mailbox;
+
+ gtk_tree_model_get (model, &iter,
+ COLUMN_MAILBOX, &mailbox,
+ COLUMN_PERCENTAGE, "a,
+ COLUMN_QUOTA_LIMIT, &assigned,
+ COLUMN_QUOTA_USED, &used,
+ -1);
+
+ pango_layout_set_text (layout, mailbox, -1);
+ pango_cairo_show_layout (cr, layout);
+ cairo_rel_move_to (cr, 130, 0);
+
+ str = g_strdup_printf ("%d", quota);
+ pango_layout_set_text (layout, str, -1);
+ g_free (str);
+ pango_cairo_show_layout (cr, layout);
+ cairo_rel_move_to (cr, 120, 0);
+
+ str = g_strdup_printf ("%d", assigned);
+ pango_layout_set_text (layout, str, -1);
+ g_free (str);
+ pango_cairo_show_layout (cr, layout);
+ cairo_rel_move_to (cr, 120, 0);
+
+ str = g_strdup_printf ("%d", used);
+ pango_layout_set_text (layout, str, -1);
+ g_free (str);
+ pango_cairo_show_layout (cr, layout);
+
+ cairo_rel_move_to (cr, -370, report->font_size);
+ line++;
+ gtk_tree_model_iter_next (model, &iter);
+ }
+
+ g_object_unref (layout);
}
-/* print quota and other data */
-static gboolean
-gyrus_report_print_quota (GtkTreeModel *model, GtkTreePath *path,
- GtkTreeIter *iter, gpointer data)
+/* show print dialog */
+static void
+gyrus_report_on_button_print_clicked(GtkWidget *widget, GyrusReportData *report)
{
- GyrusReportData *report = data;
- guchar *mailbox;
- gint quota;
- gint assigned;
- gint used;
-
- guchar *str_tmp;
-
- gtk_tree_model_get (model, iter,
- COLUMN_MAILBOX, &mailbox,
- COLUMN_PERCENTAGE, "a,
- COLUMN_QUOTA_LIMIT, &assigned,
- COLUMN_QUOTA_USED, &used,
- -1);
+ GtkPrintOperation *operation;
+ GtkWidget *window;
+ GtkWidget *dialog;
+ GError *error = NULL;
- /* print mailbox */
- gnome_print_moveto (report->gpc, report->xini + 5, report->yini);
- gnome_print_show (report->gpc, mailbox);
- g_free (mailbox);
-
- /* print quota */
- str_tmp = (guchar *) g_strdup_printf ("%d", quota);
- gnome_print_moveto (report->gpc, report->xini + 130, report->yini);
- gnome_print_show (report->gpc, str_tmp);
- g_free (str_tmp);
-
- /* print asigned */
- str_tmp = (guchar *) g_strdup_printf ("%d", assigned);
- gnome_print_moveto (report->gpc, report->xini + 250, report->yini);
- gnome_print_show (report->gpc, str_tmp);
- g_free (str_tmp);
-
- /* print used */
- str_tmp = (guchar *) g_strdup_printf ("%d", used);
- gnome_print_moveto (report->gpc, report->xini + 370, report->yini);
- gnome_print_show (report->gpc, str_tmp);
- g_free (str_tmp);
-
- report->yini = report->yini - 15;
-
- /* evaluate number of line printed */
- if (report->nlin == MAX_USER_PAGE){
- gnome_print_showpage (report->gpc);
- report->nlin = 1;
- report->page = report->page + 1;
+ /* Create the objects */
+ operation = gtk_print_operation_new ();
+ window = gtk_widget_get_toplevel (widget);
+ report->font_size = 12.0;
+
+ g_signal_connect (G_OBJECT (operation), "begin-print",
+ G_CALLBACK (begin_print), report);
+ g_signal_connect (G_OBJECT (operation), "draw-page",
+ G_CALLBACK (draw_page), report);
+ /* g_signal_connect (G_OBJECT (operation), "end-print", */
+ /* G_CALLBACK (end_print), report); */
+
+ gtk_print_operation_set_use_full_page (operation, FALSE);
+ gtk_print_operation_set_unit (operation, GTK_UNIT_POINTS);
+
+ gtk_print_operation_run (operation,
+ GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
+ GTK_WINDOW (window),
+ &error);
+ if (error) {
+ 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);
- /* new page */
- gyrus_report_draw_begin (report);
- }else{
- report->nlin = report->nlin + 1;
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
}
-
- ///g_print ("quota-> %d\n",quota);
-
- return FALSE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]