Commit a24d16e3 authored by Paolo Borelli's avatar Paolo Borelli

merge the "printing" branch

svn path=/trunk/; revision=6116
parent bac8610f
......@@ -167,10 +167,9 @@ dnl ================================================================
PKG_CHECK_MODULES(GEDIT, [
glib-2.0 >= 2.14.0
gtk+-2.0 >= 2.12.0
gtksourceview-2.0 >= 2.0.0
gtksourceview-2.0 >= 2.1.0
libgnomeui-2.0 >= 2.16.0
libglade-2.0 >= 2.5.1
libgnomeprintui-2.2 >= 2.12.1
gnome-vfs-2.0 >= 2.16.0
])
GEDIT_LIBS="${GEDIT_LIBS}"
......
......@@ -387,22 +387,6 @@
</locale>
</schema>
<schema>
<key>/schemas/apps/gedit-2/preferences/print/fonts/print_font_body</key>
<applyto>/apps/gedit-2/preferences/print/fonts/print_font_body</applyto>
<owner>gedit</owner>
<type>string</type>
<locale name="C">
<default><!-- Translators: This is the Body font for printing.
This is a gnome-print font name and is replaced by
print_font_body_pango.-->Monospace Regular 9</default>
<short>Body Font for Printing</short>
<long>Specifies the font to use for a document's body when
printing documents. This is a gnome-print font name and replaced by
print_font_body_pango.</long>
</locale>
</schema>
<schema>
<key>/schemas/apps/gedit-2/preferences/print/fonts/print_font_body_pango</key>
<applyto>/apps/gedit-2/preferences/print/fonts/print_font_body_pango</applyto>
......@@ -417,23 +401,6 @@
</locale>
</schema>
<schema>
<key>/schemas/apps/gedit-2/preferences/print/fonts/print_font_header</key>
<applyto>/apps/gedit-2/preferences/print/fonts/print_font_header</applyto>
<owner>gedit</owner>
<type>string</type>
<locale name="C">
<default><!-- Translators: This is the Header font for printing.
This is a gnome-print font name and replaced by
print_font_header_pango.-->Sans Regular 11</default>
<short>Header Font for Printing</short>
<long>Specifies the font to use for page headers when printing
a document. This will only take effect if the "Print Header"
option is turned on. This is a gnome-print font name and replaced by
print_font_header_pango.</long>
</locale>
</schema>
<schema>
<key>/schemas/apps/gedit-2/preferences/print/fonts/print_font_header_pango</key>
<applyto>/apps/gedit-2/preferences/print/fonts/print_font_header_pango</applyto>
......@@ -449,23 +416,6 @@
</locale>
</schema>
<schema>
<key>/schemas/apps/gedit-2/preferences/print/fonts/print_font_numbers</key>
<applyto>/apps/gedit-2/preferences/print/fonts/print_font_numbers</applyto>
<owner>gedit</owner>
<type>string</type>
<locale name="C">
<default><!-- Translators: This is the Line Number font for printing.
This is a gnome-print font name and replaced by
print_font_numbers_pango.-->Sans Regular 8</default>
<short>Line Number Font for Printing</short>
<long>Specifies the font to use for line numbers when
printing. This will only take effect if the "Print Line
Numbers" option is non-zero. This is a gnome-print font name
and replaced by print_font_numbers_pango.</long>
</locale>
</schema>
<schema>
<key>/schemas/apps/gedit-2/preferences/print/fonts/print_font_numbers_pango</key>
<applyto>/apps/gedit-2/preferences/print/fonts/print_font_numbers_pango</applyto>
......
......@@ -69,15 +69,14 @@ NOINST_H_FILES = \
gedit-local-document-saver.h \
gedit-gnomevfs-document-saver.h \
gedit-history-entry.h \
gedit-print.h \
gedit-print-job-preview.h \
gedit-print-job.h \
gedit-print-preview.h \
gedit-io-error-message-area.h \
gedit-spinner.h \
gedit-prefs-manager-private.h \
sexy-icon-entry.h \
gedittextregion.h \
gedit-session.h \
gtksourceprintjob.h
gedit-session.h
if ENABLE_PYTHON
NOINST_H_FILES += \
......@@ -153,8 +152,8 @@ libgedit_la_SOURCES = \
gedit-prefs-manager-app.c \
gedit-prefs-manager.c \
gedit-prefs-manager-private.h \
gedit-print.c \
gedit-print-job-preview.c \
gedit-print-job.c \
gedit-print-preview.c \
gedit-progress-message-area.c \
gedit-session.c \
gedit-spinner.c \
......@@ -166,7 +165,6 @@ libgedit_la_SOURCES = \
gedit-window.c \
sexy-icon-entry.c \
gedittextregion.c \
gtksourceprintjob.c \
$(NOINST_H_FILES) \
$(INST_H_FILES)
......@@ -192,11 +190,16 @@ gedit-marshal.c: gedit-marshal.list $(GLIB_GENMARSHAL)
echo "#include \"gedit-marshal.h\"" > $@ && \
$(GLIB_GENMARSHAL) $< --body --prefix=gedit_marshal >> $@
ui_DATA = gedit-ui.xml
uidir = $(datadir)/gedit-2/ui/
ui_DATA = gedit-ui.xml
gladedir = $(datadir)/gedit-2/glade/
glade_DATA = \
gedit-print-preferences.glade
EXTRA_DIST = \
$(ui_DATA) \
$(glade_DATA) \
gedit-enum-types.h.template \
gedit-enum-types.c.template \
gedit-marshal.list
......
......@@ -44,6 +44,10 @@
#include "gedit-utils.h"
#include "gedit-enum-types.h"
#define GEDIT_PAGE_SETUP_FILE "gedit-page-setup"
#define GEDIT_PRINT_SETTINGS_FILE "gedit-print-settings"
#define GEDIT_APP_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), GEDIT_TYPE_APP, GeditAppPrivate))
/* Properties */
......@@ -57,7 +61,11 @@ struct _GeditAppPrivate
{
GList *windows;
GeditWindow *active_window;
GeditLockdownMask lockdown;
GtkPageSetup *page_setup;
GtkPrintSettings *print_settings;
};
G_DEFINE_TYPE(GeditApp, gedit_app, G_TYPE_OBJECT)
......@@ -69,6 +77,11 @@ gedit_app_finalize (GObject *object)
g_list_free (app->priv->windows);
if (app->priv->page_setup)
g_object_unref (app->priv->page_setup);
if (app->priv->print_settings)
g_object_unref (app->priv->print_settings);
G_OBJECT_CLASS (gedit_app_parent_class)->finalize (object);
}
......@@ -122,7 +135,8 @@ get_accel_file (void)
if (home != NULL)
{
return g_build_filename (home,
".gnome2/accels/"
".gnome2",
"accels"
"gedit",
NULL);
}
......@@ -131,21 +145,184 @@ get_accel_file (void)
}
static void
gedit_app_init (GeditApp *app)
load_accels (void)
{
gchar *accel_file;
gchar *filename;
app->priv = GEDIT_APP_GET_PRIVATE (app);
filename = get_accel_file ();
if (filename != NULL)
{
gedit_debug_message (DEBUG_APP, "Loading keybindings from %s\n", filename);
gtk_accel_map_load (filename);
g_free (filename);
}
}
static void
save_accels (void)
{
gchar *filename;
filename = get_accel_file ();
if (filename != NULL)
{
gedit_debug_message (DEBUG_APP, "Saving keybindings in %s\n", filename);
gtk_accel_map_save (filename);
g_free (filename);
}
}
static gchar *
get_page_setup_file (void)
{
const gchar *home;
home = g_get_home_dir ();
if (home != NULL)
{
return g_build_filename (home,
".gnome2",
"gedit",
GEDIT_PAGE_SETUP_FILE,
NULL);
}
return NULL;
}
static void
load_page_setup (GeditApp *app)
{
gchar *filename;
GError *error = NULL;
g_return_if_fail (app->priv->page_setup == NULL);
filename = get_page_setup_file ();
app->priv->page_setup = gtk_page_setup_new_from_file (filename,
&error);
if (error)
{
/* Ignore file not found error */
if (error->domain != G_FILE_ERROR ||
error->code != G_FILE_ERROR_NOENT)
{
g_warning (error->message);
}
g_error_free (error);
}
g_free (filename);
/* fall back to default settings */
if (app->priv->page_setup == NULL)
app->priv->page_setup = gtk_page_setup_new ();
}
static void
save_page_setup (GeditApp *app)
{
gchar *filename;
GError *error = NULL;
if (app->priv->page_setup == NULL)
return;
filename = get_page_setup_file ();
gtk_page_setup_to_file (app->priv->page_setup,
filename,
&error);
if (error)
{
g_warning (error->message);
g_error_free (error);
}
g_free (filename);
}
static gchar *
get_print_settings_file (void)
{
const gchar *home;
home = g_get_home_dir ();
if (home != NULL)
{
return g_build_filename (home,
".gnome2",
"gedit",
GEDIT_PRINT_SETTINGS_FILE,
NULL);
}
return NULL;
}
static void
load_print_settings (GeditApp *app)
{
gchar *filename;
GError *error = NULL;
g_return_if_fail (app->priv->print_settings == NULL);
filename = get_print_settings_file ();
app->priv->print_settings = gtk_print_settings_new_from_file (filename,
&error);
if (error)
{
/* Ignore file not found error */
if (error->domain != G_FILE_ERROR ||
error->code != G_FILE_ERROR_NOENT)
{
g_warning (error->message);
}
g_error_free (error);
}
g_free (filename);
/* fall back to default settings */
if (app->priv->print_settings == NULL)
app->priv->print_settings = gtk_print_settings_new ();
}
static void
save_print_settings (GeditApp *app)
{
gchar *filename;
GError *error = NULL;
if (app->priv->print_settings == NULL)
return;
/* Load accels */
accel_file = get_accel_file ();
if (accel_file != NULL)
filename = get_print_settings_file ();
gtk_print_settings_to_file (app->priv->print_settings,
filename,
&error);
if (error)
{
gedit_debug_message (DEBUG_APP, "Loading keybindings from %s\n", accel_file);
gtk_accel_map_load (accel_file);
g_free (accel_file);
g_warning (error->message);
g_error_free (error);
}
g_free (filename);
}
static void
gedit_app_init (GeditApp *app)
{
app->priv = GEDIT_APP_GET_PRIVATE (app);
load_accels ();
/* initial lockdown state */
app->priv->lockdown = gedit_prefs_manager_get_lockdown ();
}
......@@ -243,15 +420,12 @@ window_destroy (GeditWindow *window,
*/
if (app->priv->windows == NULL)
{
gchar *accel_file;
accel_file = get_accel_file ();
/* Last window is gone... save some settings and exit */
if (accel_file != NULL)
{
gedit_debug_message (DEBUG_APP, "Saveing keybindings in %s\n", accel_file);
gtk_accel_map_save (accel_file);
g_free (accel_file);
}
save_accels ();
save_page_setup (app);
save_print_settings (app);
g_object_unref (app);
}
......@@ -649,3 +823,54 @@ _gedit_app_set_lockdown_bit (GeditApp *app,
app_lockdown_changed (app);
}
/* Returns a copy */
GtkPageSetup *
_gedit_app_get_default_page_setup (GeditApp *app)
{
g_return_val_if_fail (GEDIT_IS_APP (app), NULL);
if (app->priv->page_setup == NULL)
load_page_setup (app);
return gtk_page_setup_copy (app->priv->page_setup);
}
void
_gedit_app_set_default_page_setup (GeditApp *app,
GtkPageSetup *page_setup)
{
g_return_if_fail (GEDIT_IS_APP (app));
g_return_if_fail (GTK_IS_PAGE_SETUP (page_setup));
if (app->priv->page_setup != NULL)
g_object_unref (app->priv->page_setup);
app->priv->page_setup = page_setup;
}
/* Returns a copy */
GtkPrintSettings *
_gedit_app_get_default_print_settings (GeditApp *app)
{
g_return_val_if_fail (GEDIT_IS_APP (app), NULL);
if (app->priv->print_settings == NULL)
load_print_settings (app);
return gtk_print_settings_copy (app->priv->print_settings);
}
void
_gedit_app_set_default_print_settings (GeditApp *app,
GtkPrintSettings *settings)
{
g_return_if_fail (GEDIT_IS_APP (app));
g_return_if_fail (GTK_IS_PRINT_SETTINGS (settings));
if (app->priv->print_settings != NULL)
g_object_unref (app->priv->print_settings);
app->priv->print_settings = settings;
}
......@@ -129,6 +129,13 @@ void _gedit_app_set_lockdown_bit (GeditApp *app,
void _gedit_window_set_lockdown (GeditWindow *window,
GeditLockdownMask lockdown);
/* global print config */
GtkPageSetup *_gedit_app_get_default_page_setup (GeditApp *app);
void _gedit_app_set_default_page_setup (GeditApp *app,
GtkPageSetup *page_setup);
GtkPrintSettings *_gedit_app_get_default_print_settings (GeditApp *app);
void _gedit_app_set_default_print_settings (GeditApp *app,
GtkPrintSettings *settings);
G_END_DECLS
......
......@@ -39,29 +39,14 @@
#include "gedit-commands.h"
#include "gedit-window.h"
#include "gedit-tab.h"
#include "gedit-debug.h"
#include "gedit-print.h"
#include "dialogs/gedit-page-setup-dialog.h"
void
_gedit_cmd_file_page_setup (GtkAction *action,
GeditWindow *window)
GeditWindow *window)
{
gedit_debug (DEBUG_COMMANDS);
gedit_show_page_setup_dialog (GTK_WINDOW (window));
}
void
_gedit_cmd_file_print_preview (GtkAction *action,
GeditWindow *window)
{
GeditDocument *doc;
GeditTab *tab;
GeditPrintJob *pjob;
GtkTextIter start;
GtkTextIter end;
GeditTab *tab;
gedit_debug (DEBUG_COMMANDS);
......@@ -69,142 +54,36 @@ _gedit_cmd_file_print_preview (GtkAction *action,
if (tab == NULL)
return;
doc = gedit_tab_get_document (tab);
pjob = gedit_print_job_new (doc);
gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (doc) , &start, &end);
_gedit_tab_print_preview (tab, pjob, &start, &end);
g_object_unref (pjob);
_gedit_tab_page_setup (tab);
}
static void
print_dialog_response_cb (GtkWidget *dialog,
gint response,
GeditPrintJob *pjob)
void
_gedit_cmd_file_print_preview (GtkAction *action,
GeditWindow *window)
{
GtkTextIter start;
GtkTextIter end;
gint line_start;
gint line_end;
GnomePrintRangeType range_type;
GtkTextBuffer *buffer;
GeditTab *tab;
GeditTab *tab;
gedit_debug (DEBUG_COMMANDS);
range_type = gnome_print_dialog_get_range (GNOME_PRINT_DIALOG (dialog));
buffer = GTK_TEXT_BUFFER (
gtk_source_print_job_get_buffer (GTK_SOURCE_PRINT_JOB (pjob)));
gtk_text_buffer_get_bounds (buffer, &start, &end);
tab = gedit_tab_get_from_document (GEDIT_DOCUMENT (buffer));
switch (range_type)
{
case GNOME_PRINT_RANGE_ALL:
break;
case GNOME_PRINT_RANGE_SELECTION:
gtk_text_buffer_get_selection_bounds (buffer,
&start,
&end);
break;
case GNOME_PRINT_RANGE_RANGE:
gnome_print_dialog_get_range_page (GNOME_PRINT_DIALOG (dialog),
&line_start,
&line_end);
/* The print dialog should ensure to set the
* sensitivity of the spin buttons so that
* the start and end lines are in ascending
* order, but it doesn't.
* We reorder them if needed */
if (line_start > line_end)
{
gint tmp;
gedit_debug_message (DEBUG_PRINT,
"line start: %d, line end: %d. Swapping.",
line_start,
line_end);
tmp = line_start;
line_start = line_end;
line_end = tmp;
}
gtk_text_iter_set_line (&start, line_start - 1);
gtk_text_iter_set_line (&end, line_end - 1);
gtk_text_iter_forward_to_line_end (&end);
break;
default:
g_return_if_reached ();
}
switch (response)
{
case GNOME_PRINT_DIALOG_RESPONSE_PRINT:
gedit_debug_message (DEBUG_PRINT,
"Print button pressed.");
_gedit_tab_print (tab, pjob, &start, &end);
break;
case GNOME_PRINT_DIALOG_RESPONSE_PREVIEW:
gedit_debug_message (DEBUG_PRINT,
"Preview button pressed.");
_gedit_tab_print_preview (tab, pjob, &start, &end);
break;
}
tab = gedit_window_get_active_tab (window);
if (tab == NULL)
return;
g_object_unref (pjob);
gtk_widget_destroy (dialog);
_gedit_tab_print_preview (tab);
}
void
_gedit_cmd_file_print (GtkAction *action,
GeditWindow *window)
GeditWindow *window)
{
GeditDocument *doc;
GeditPrintJob *pjob;
GtkWidget *print_dialog;
GtkWindowGroup *wg;
GeditTab *tab;
gedit_debug (DEBUG_COMMANDS);
doc = gedit_window_get_active_document (window);
if (doc == NULL)
tab = gedit_window_get_active_tab (window);
if (tab == NULL)
return;
pjob = gedit_print_job_new (doc);
print_dialog = gedit_print_dialog_new (pjob);
wg = gedit_window_get_group (window);
gtk_window_group_add_window (wg,
GTK_WINDOW (print_dialog));
gtk_window_set_transient_for (GTK_WINDOW (print_dialog),
GTK_WINDOW (window));
gtk_window_set_modal (GTK_WINDOW (print_dialog), TRUE);
g_signal_connect (print_dialog,
"response",
G_CALLBACK (print_dialog_response_cb),
pjob);
gtk_widget_show (print_dialog);
_gedit_tab_print (tab);
}
BOOLEAN:OBJECT
BOOLEAN:NONE
VOID:VOID
BOOLEAN:OBJECT
VOID:BOOLEAN
VOID:OBJECT
VOID:POINTER
VOID:UINT64,UINT64
VOID:BOOLEAN,POINTER
VOID:BOXED,BOXED
VOID:OBJECT
VOID:POINTER
VOID:STRING,BOXED,FLAGS
VOID:STRING,BOXED,INT,BOOLEAN
VOID:UINT,POINTER
VOID:UINT64,UINT64
VOID:VOID
......@@ -1057,6 +1057,8 @@ set_close_buttons_sensitivity (GeditTab *tab,
(state != GEDIT_TAB_STATE_CLOSING) &&
(state != GEDIT_TAB_STATE_SAVING) &&
(state != GEDIT_TAB_STATE_SHOWING_PRINT_PREVIEW) &&
(state != GEDIT_TAB_STATE_PRINTING) &&
(state != GEDIT_TAB_STATE_PRINT_PREVIEWING) &&
(state != GEDIT_TAB_STATE_SAVING_ERROR));
}
......
......@@ -35,7 +35,6 @@
#include <glib/gi18n.h>
#include <gconf/gconf-value.h>
#include <libgnomeprint/gnome-font.h>
#include "gedit-prefs-manager.h"
#include "gedit-prefs-manager-private.h"
......@@ -603,213 +602,36 @@ gedit_prefs_manager_print_wrap_mode_can_set (void)
DEFINE_INT_PREF (print_line_numbers,
GPM_PRINT_LINE_NUMBERS,
GPM_DEFAULT_PRINT_LINE_NUMBERS)
/* The printing font entries are done in custom code because we
* need to implement transitioning between old gnome-print font
* names and new Pango fontnames
*/
/*
* The following routines are duplicated in gtksourceview/gtksourceview/gtksourceprintjob.c
*/
/* Do this ourselves since gnome_font_find_closest() doesn't call
* gnome_font_face_find_closest() (probably a gnome-print bug)
*/
static void
face_and_size_from_full_name (const gchar *name,
GnomeFontFace **face,
gdouble *size)
{
char *copy;
char *str_size;
copy = g_strdup (name);
str_size = strrchr (copy, ' ');
if (str_size) {
*str_size = 0;
str_size ++;
*size = atof (str_size);
} else {
*size = 12;
}
*face = gnome_font_face_find_closest ((guchar *)copy);
g_free (copy);
}
static PangoFontDescription *
font_description_from_gnome_font_name (const char *font_name)
{
GnomeFontFace *face;
PangoFontDescription *desc;
PangoStyle style;
PangoWeight weight;
const gchar *family_name;
gdouble size;
face_and_size_from_full_name (font_name, &face, &size);
/* Pango and GnomePrint have basically the same numeric weight values */
weight = (PangoWeight) gnome_font_face_get_weight_code (face);
style = gnome_font_face_is_italic (face) ? PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL;
family_name = (const gchar *) gnome_font_face_get_family_name (face);
desc = pango_font_description_new ();
pango_font_description_set_family (desc, family_name);
pango_font_description_set_weight (desc, weight);
pango_font_description_set_style (desc, style);
pango_font_description_set_size (desc, size * PANGO_SCALE);
g_object_unref (face);
return desc;
}
static char *