gedit r6116 - in trunk: . data gedit
- From: pborelli svn gnome org
- To: svn-commits-list gnome org
- Subject: gedit r6116 - in trunk: . data gedit
- Date: Thu, 24 Jan 2008 22:15:20 +0000 (GMT)
Author: pborelli
Date: Thu Jan 24 22:15:19 2008
New Revision: 6116
URL: http://svn.gnome.org/viewvc/gedit?rev=6116&view=rev
Log:
merge the "printing" branch
Added:
trunk/gedit/gedit-print-job.c
- copied unchanged from r6115, /branches/printing/gedit/gedit-print-job.c
trunk/gedit/gedit-print-job.h
- copied unchanged from r6115, /branches/printing/gedit/gedit-print-job.h
trunk/gedit/gedit-print-preview.c
- copied unchanged from r6115, /branches/printing/gedit/gedit-print-preview.c
trunk/gedit/gedit-print-preview.h
- copied unchanged from r6115, /branches/printing/gedit/gedit-print-preview.h
Modified:
trunk/configure.ac
trunk/data/gedit.schemas.in
trunk/gedit/Makefile.am
trunk/gedit/gedit-app.c
trunk/gedit/gedit-app.h
trunk/gedit/gedit-commands-file-print.c
trunk/gedit/gedit-marshal.list
trunk/gedit/gedit-notebook.c
trunk/gedit/gedit-prefs-manager.c
trunk/gedit/gedit-prefs-manager.h
trunk/gedit/gedit-tab.c
trunk/gedit/gedit-tab.h
trunk/gedit/gedit-window.c
Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac (original)
+++ trunk/configure.ac Thu Jan 24 22:15:19 2008
@@ -167,10 +167,9 @@
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}"
Modified: trunk/data/gedit.schemas.in
==============================================================================
--- trunk/data/gedit.schemas.in (original)
+++ trunk/data/gedit.schemas.in Thu Jan 24 22:15:19 2008
@@ -388,22 +388,6 @@
</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>
<owner>gedit</owner>
@@ -418,23 +402,6 @@
</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>
<owner>gedit</owner>
@@ -450,23 +417,6 @@
</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>
<owner>gedit</owner>
Modified: trunk/gedit/Makefile.am
==============================================================================
--- trunk/gedit/Makefile.am (original)
+++ trunk/gedit/Makefile.am Thu Jan 24 22:15:19 2008
@@ -69,15 +69,14 @@
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 @@
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 @@
gedit-window.c \
sexy-icon-entry.c \
gedittextregion.c \
- gtksourceprintjob.c \
$(NOINST_H_FILES) \
$(INST_H_FILES)
@@ -192,11 +190,16 @@
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
Modified: trunk/gedit/gedit-app.c
==============================================================================
--- trunk/gedit/gedit-app.c (original)
+++ trunk/gedit/gedit-app.c Thu Jan 24 22:15:19 2008
@@ -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 @@
{
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 @@
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 @@
if (home != NULL)
{
return g_build_filename (home,
- ".gnome2/accels/"
+ ".gnome2",
+ "accels"
"gedit",
NULL);
}
@@ -131,21 +145,184 @@
}
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;
- /* Load accels */
- accel_file = get_accel_file ();
- if (accel_file != NULL)
- {
- gedit_debug_message (DEBUG_APP, "Loading keybindings from %s\n", accel_file);
- gtk_accel_map_load (accel_file);
- g_free (accel_file);
+ 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;
+
+ filename = get_print_settings_file ();
+
+ gtk_print_settings_to_file (app->priv->print_settings,
+ filename,
+ &error);
+ if (error)
+ {
+ 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 @@
*/
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 @@
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;
+}
+
Modified: trunk/gedit/gedit-app.h
==============================================================================
--- trunk/gedit/gedit-app.h (original)
+++ trunk/gedit/gedit-app.h Thu Jan 24 22:15:19 2008
@@ -129,6 +129,13 @@
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
Modified: trunk/gedit/gedit-commands-file-print.c
==============================================================================
--- trunk/gedit/gedit-commands-file-print.c (original)
+++ trunk/gedit/gedit-commands-file-print.c Thu Jan 24 22:15:19 2008
@@ -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 @@
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);
}
Modified: trunk/gedit/gedit-marshal.list
==============================================================================
--- trunk/gedit/gedit-marshal.list (original)
+++ trunk/gedit/gedit-marshal.list Thu Jan 24 22:15:19 2008
@@ -1,11 +1,12 @@
-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
Modified: trunk/gedit/gedit-notebook.c
==============================================================================
--- trunk/gedit/gedit-notebook.c (original)
+++ trunk/gedit/gedit-notebook.c Thu Jan 24 22:15:19 2008
@@ -1057,6 +1057,8 @@
(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));
}
Modified: trunk/gedit/gedit-prefs-manager.c
==============================================================================
--- trunk/gedit/gedit-prefs-manager.c (original)
+++ trunk/gedit/gedit-prefs-manager.c Thu Jan 24 22:15:19 2008
@@ -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 @@
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 *
-font_name_from_gnome_font_name (const char *gnome_name)
-{
- PangoFontDescription *desc;
- gchar *pango_name;
-
- desc = font_description_from_gnome_font_name (gnome_name);
- pango_name = pango_font_description_to_string (desc);
- pango_font_description_free (desc);
-
- return pango_name;
-}
-
-static gchar *
-get_string_without_default (GConfClient *gconf_client,
- const char *key,
- GError **error)
-{
- GConfValue *value;
- gchar *result = NULL;
-
- value = gconf_client_get_without_default (gconf_client, key, error);
- if (value && value->type == GCONF_VALUE_STRING)
- {
- result = g_strdup (gconf_value_get_string (value));
- gconf_value_free (value);
- }
-
- return result;
-}
-
-static gchar *
-gedit_prefs_manager_get_font (const gchar *pango_key,
- const gchar *gnome_print_key,
- const gchar *def)
-{
- gchar *pango_value;
- gchar *gnome_print_value;
-
- /* if the new pango key isn't writable, we don't want an old value to
- * overwrite it. Otherwise, we first look whether the pango key has
- * been set explicitely. If the pango key hasn't been set, but the
- * gnome-print key has, we use that and convert it into a pango font name.
- */
- if (gedit_prefs_manager_key_is_writable (pango_key))
- {
- pango_value = get_string_without_default (gedit_prefs_manager->gconf_client,
- pango_key,
- NULL);
- if (pango_value)
- return pango_value;
-
- gnome_print_value = get_string_without_default (gedit_prefs_manager->gconf_client,
- gnome_print_key,
- NULL);
-
- if (gnome_print_value) {
- pango_value = font_name_from_gnome_font_name (gnome_print_value);
- g_free (gnome_print_value);
-
- return pango_value;
- }
- }
-
- return gedit_prefs_manager_get_string (pango_key, def);
-}
-
-gchar *
-gedit_prefs_manager_get_print_font_body (void)
-{
- return gedit_prefs_manager_get_font (GPM_PRINT_FONT_BODY_PANGO,
- GPM_PRINT_FONT_BODY,
- GPM_DEFAULT_PRINT_FONT_BODY_PANGO);
-}
-
-void
-gedit_prefs_manager_set_print_font_body (const gchar* v)
-{
- gedit_prefs_manager_set_string (GPM_PRINT_FONT_BODY_PANGO, v);
-}
-
-gboolean
-gedit_prefs_manager_print_font_body_can_set (void)
-{
- return gedit_prefs_manager_key_is_writable (GPM_PRINT_FONT_BODY_PANGO);
-}
+/* Printing fonts */
+DEFINE_STRING_PREF (print_font_body,
+ GPM_PRINT_FONT_BODY,
+ GPM_DEFAULT_PRINT_FONT_BODY)
const gchar *
gedit_prefs_manager_get_default_print_font_body (void)
{
- return GPM_DEFAULT_PRINT_FONT_BODY_PANGO;
-}
-
-gchar *
-gedit_prefs_manager_get_print_font_header (void)
-{
- return gedit_prefs_manager_get_font (GPM_PRINT_FONT_HEADER_PANGO,
- GPM_PRINT_FONT_HEADER,
- GPM_DEFAULT_PRINT_FONT_HEADER_PANGO);
+ return GPM_DEFAULT_PRINT_FONT_BODY;
}
-void
-gedit_prefs_manager_set_print_font_header (const gchar* v)
-{
- gedit_prefs_manager_set_string (GPM_PRINT_FONT_HEADER_PANGO, v);
-}
-
-gboolean
-gedit_prefs_manager_print_font_header_can_set (void)
-{
- return gedit_prefs_manager_key_is_writable (GPM_PRINT_FONT_HEADER_PANGO);
-}
+DEFINE_STRING_PREF (print_font_header,
+ GPM_PRINT_FONT_HEADER,
+ GPM_DEFAULT_PRINT_FONT_HEADER)
const gchar *
gedit_prefs_manager_get_default_print_font_header (void)
{
- return GPM_DEFAULT_PRINT_FONT_HEADER_PANGO;
-}
-
-gchar *
-gedit_prefs_manager_get_print_font_numbers (void)
-{
- return gedit_prefs_manager_get_font (GPM_PRINT_FONT_NUMBERS_PANGO,
- GPM_PRINT_FONT_NUMBERS,
- GPM_DEFAULT_PRINT_FONT_NUMBERS_PANGO);
+ return GPM_DEFAULT_PRINT_FONT_HEADER;
}
-void
-gedit_prefs_manager_set_print_font_numbers (const gchar* v)
-{
- gedit_prefs_manager_set_string (GPM_PRINT_FONT_NUMBERS_PANGO, v);
-}
-
-gboolean
-gedit_prefs_manager_print_font_numbers_can_set (void)
-{
- return gedit_prefs_manager_key_is_writable (GPM_PRINT_FONT_NUMBERS_PANGO);
-}
+DEFINE_STRING_PREF (print_font_numbers,
+ GPM_PRINT_FONT_NUMBERS,
+ GPM_DEFAULT_PRINT_FONT_NUMBERS)
const gchar *
gedit_prefs_manager_get_default_print_font_numbers (void)
{
- return GPM_DEFAULT_PRINT_FONT_NUMBERS_PANGO;
+ return GPM_DEFAULT_PRINT_FONT_NUMBERS;
}
/* Max number of files in "Recent Files" menu.
Modified: trunk/gedit/gedit-prefs-manager.h
==============================================================================
--- trunk/gedit/gedit-prefs-manager.h (original)
+++ trunk/gedit/gedit-prefs-manager.h Thu Jan 24 22:15:19 2008
@@ -115,12 +115,9 @@
#define GPM_PRINT_LINE_NUMBERS GPM_PRINT_PAGE_DIR "/print_line_numbers"
#define GPM_PRINT_FONT_DIR GPM_PREFS_DIR "/print/fonts"
-#define GPM_PRINT_FONT_BODY GPM_PRINT_FONT_DIR "/print_font_body"
-#define GPM_PRINT_FONT_BODY_PANGO GPM_PRINT_FONT_DIR "/print_font_body_pango"
-#define GPM_PRINT_FONT_HEADER GPM_PRINT_FONT_DIR "/print_font_header"
-#define GPM_PRINT_FONT_HEADER_PANGO GPM_PRINT_FONT_DIR "/print_font_header_pango"
-#define GPM_PRINT_FONT_NUMBERS GPM_PRINT_FONT_DIR "/print_font_numbers"
-#define GPM_PRINT_FONT_NUMBERS_PANGO GPM_PRINT_FONT_DIR "/print_font_numbers_pango"
+#define GPM_PRINT_FONT_BODY GPM_PRINT_FONT_DIR "/print_font_body_pango"
+#define GPM_PRINT_FONT_HEADER GPM_PRINT_FONT_DIR "/print_font_header_pango"
+#define GPM_PRINT_FONT_NUMBERS GPM_PRINT_FONT_DIR "/print_font_numbers_pango"
/* Encodings */
#define GPM_ENCODINGS_DIR GPM_PREFS_DIR "/encodings"
@@ -179,9 +176,9 @@
#define GPM_DEFAULT_PRINT_WRAP_MODE "GTK_WRAP_WORD"
#define GPM_DEFAULT_PRINT_LINE_NUMBERS 0 /* No numbers */
-#define GPM_DEFAULT_PRINT_FONT_BODY_PANGO (const gchar*) "Monospace 9"
-#define GPM_DEFAULT_PRINT_FONT_HEADER_PANGO (const gchar*) "Sans 11"
-#define GPM_DEFAULT_PRINT_FONT_NUMBERS_PANGO (const gchar*) "Sans 8"
+#define GPM_DEFAULT_PRINT_FONT_BODY (const gchar*) "Monospace 9"
+#define GPM_DEFAULT_PRINT_FONT_HEADER (const gchar*) "Sans 11"
+#define GPM_DEFAULT_PRINT_FONT_NUMBERS (const gchar*) "Sans 8"
#define GPM_DEFAULT_MAX_RECENTS 5
Modified: trunk/gedit/gedit-tab.c
==============================================================================
--- trunk/gedit/gedit-tab.c (original)
+++ trunk/gedit/gedit-tab.c Thu Jan 24 22:15:19 2008
@@ -42,8 +42,8 @@
#include "gedit-utils.h"
#include "gedit-message-area.h"
#include "gedit-io-error-message-area.h"
-#include "gedit-print.h"
-#include "gedit-print-job-preview.h"
+#include "gedit-print-job.h"
+#include "gedit-print-preview.h"
#include "gedit-progress-message-area.h"
#include "gedit-debug.h"
#include "gedit-prefs-manager-app.h"
@@ -229,15 +229,7 @@
gedit_tab_finalize (GObject *object)
{
GeditTab *tab = GEDIT_TAB (object);
-
- if (tab->priv->print_job != NULL)
- {
- gedit_debug_message (DEBUG_TAB, "Cancelling printing");
-
- gtk_source_print_job_cancel (GTK_SOURCE_PRINT_JOB (tab->priv->print_job));
- g_object_unref (tab->priv->print_job);
- }
-
+
if (tab->priv->timer != NULL)
g_timer_destroy (tab->priv->timer);
@@ -2149,6 +2141,135 @@
gedit_document_save_as (doc, uri, encoding, tab->priv->save_flags);
}
+#define GEDIT_PAGE_SETUP_KEY "gedit-page-setup-key"
+#define GEDIT_PRINT_SETTINGS_KEY "gedit-print-settings-key"
+
+static GtkPageSetup *
+get_page_setup (GeditTab *tab)
+{
+ gpointer data;
+ GeditDocument *doc;
+
+ doc = gedit_tab_get_document (tab);
+
+ data = g_object_get_data (G_OBJECT (doc),
+ GEDIT_PAGE_SETUP_KEY);
+
+ if (data == NULL)
+ {
+ return _gedit_app_get_default_page_setup (gedit_app_get_default());
+ }
+ else
+ {
+ return GTK_PAGE_SETUP (data);
+ }
+}
+
+static GtkPrintSettings *
+get_print_settings (GeditTab *tab)
+{
+ gpointer data;
+ GeditDocument *doc;
+
+ doc = gedit_tab_get_document (tab);
+
+ data = g_object_get_data (G_OBJECT (doc),
+ GEDIT_PRINT_SETTINGS_KEY);
+
+ if (data == NULL)
+ {
+ return _gedit_app_get_default_print_settings (gedit_app_get_default());
+ }
+ else
+ {
+ return GTK_PRINT_SETTINGS (data);
+ }
+}
+
+/* FIXME: show the message area only if the operation will be "long" */
+static void
+printing_cb (GeditPrintJob *job,
+ GeditPrintJobStatus status,
+ GeditTab *tab)
+{
+ g_return_if_fail (GEDIT_IS_PROGRESS_MESSAGE_AREA (tab->priv->message_area));
+
+ gtk_widget_show (tab->priv->message_area);
+
+ gedit_progress_message_area_set_text (GEDIT_PROGRESS_MESSAGE_AREA (tab->priv->message_area),
+ gedit_print_job_get_status_string (job));
+
+ gedit_progress_message_area_set_fraction (GEDIT_PROGRESS_MESSAGE_AREA (tab->priv->message_area),
+ gedit_print_job_get_progress (job));
+}
+
+static void
+done_printing_cb (GeditPrintJob *job,
+ GeditPrintJobResult result,
+ const GError *error,
+ GeditTab *tab)
+{
+ GeditView *view;
+
+ g_return_if_fail (tab->priv->state == GEDIT_TAB_STATE_PRINT_PREVIEWING ||
+ tab->priv->state == GEDIT_TAB_STATE_SHOWING_PRINT_PREVIEW ||
+ tab->priv->state == GEDIT_TAB_STATE_PRINTING);
+
+ if (tab->priv->state == GEDIT_TAB_STATE_SHOWING_PRINT_PREVIEW)
+ {
+ /* print preview has been destroyed... */
+ tab->priv->print_preview = NULL;
+ }
+ else
+ {
+ g_return_if_fail (GEDIT_IS_PROGRESS_MESSAGE_AREA (tab->priv->message_area));
+
+ set_message_area (tab, NULL); /* destroy the message area */
+ }
+
+ // TODO: check status and error
+
+ /* Save the print settings */
+ if (result == GEDIT_PRINT_JOB_RESULT_OK)
+ {
+ GeditDocument *doc;
+ GtkPrintSettings *settings;
+
+ doc = gedit_tab_get_document (tab);
+
+ settings = gedit_print_job_get_print_settings (job);
+
+ /* remember them for this document */
+ g_object_set_data_full (G_OBJECT (doc),
+ GEDIT_PRINT_SETTINGS_KEY,
+ g_object_ref (settings),
+ (GDestroyNotify)g_object_unref);
+
+ /* make them the default */
+ _gedit_app_set_default_print_settings (gedit_app_get_default (),
+ settings);
+ }
+
+#if 0
+ if (tab->priv->print_preview != NULL)
+ {
+ /* If we were printing while showing the print preview,
+ see bug #352658 */
+ gtk_widget_destroy (tab->priv->print_preview);
+ g_return_if_fail (tab->priv->state == GEDIT_TAB_STATE_PRINTING);
+ }
+#endif
+
+ gedit_tab_set_state (tab, GEDIT_TAB_STATE_NORMAL);
+
+ view = gedit_tab_get_view (tab);
+ gtk_widget_grab_focus (GTK_WIDGET (view));
+
+ g_object_unref (tab->priv->print_job);
+ tab->priv->print_job = NULL;
+}
+
+#if 0
static void
print_preview_destroyed (GtkWidget *preview,
GeditTab *tab)
@@ -2174,62 +2295,62 @@
g_return_if_fail (tab->priv->state == GEDIT_TAB_STATE_PRINTING);
}
}
+#endif
static void
-set_print_preview (GeditTab *tab, GtkWidget *print_preview)
+show_preview_cb (GeditPrintJob *job,
+ GeditPrintPreview *preview,
+ GeditTab *tab)
{
- if (tab->priv->print_preview == print_preview)
- return;
-
- if (tab->priv->print_preview != NULL)
- gtk_widget_destroy (tab->priv->print_preview);
+// g_return_if_fail (tab->priv->state == GEDIT_TAB_STATE_PRINT_PREVIEWING);
+ g_return_if_fail (tab->priv->print_preview == NULL);
- tab->priv->print_preview = print_preview;
+ set_message_area (tab, NULL); /* destroy the message area */
+ tab->priv->print_preview = GTK_WIDGET (preview);
gtk_box_pack_end (GTK_BOX (tab),
tab->priv->print_preview,
TRUE,
TRUE,
- 0);
-
+ 0);
+ gtk_widget_show (tab->priv->print_preview);
gtk_widget_grab_focus (tab->priv->print_preview);
+/* when the preview gets destroyed we get "done" signal
g_signal_connect (tab->priv->print_preview,
"destroy",
G_CALLBACK (print_preview_destroyed),
- tab);
+ tab);
+*/
+ gedit_tab_set_state (tab, GEDIT_TAB_STATE_SHOWING_PRINT_PREVIEW);
}
-#define MIN_PAGES 15
+#if 0
static void
-print_page_cb (GtkSourcePrintJob *pjob, GeditTab *tab)
+set_print_preview (GeditTab *tab,
+ GtkWidget *print_preview)
{
- gchar *str;
- gint page_num;
- gint total;
+ if (tab->priv->print_preview == print_preview)
+ return;
+
+ if (tab->priv->print_preview != NULL)
+ gtk_widget_destroy (tab->priv->print_preview);
- g_return_if_fail (GEDIT_IS_PROGRESS_MESSAGE_AREA (tab->priv->message_area));
+ tab->priv->print_preview = print_preview;
- total = gtk_source_print_job_get_page_count (pjob);
-
- if (total < MIN_PAGES)
- return;
+ gtk_box_pack_end (GTK_BOX (tab),
+ tab->priv->print_preview,
+ TRUE,
+ TRUE,
+ 0);
- page_num = gtk_source_print_job_get_page (pjob);
-
- g_return_if_fail (GEDIT_IS_PROGRESS_MESSAGE_AREA (tab->priv->message_area));
-
- gtk_widget_show (tab->priv->message_area);
-
- str = g_strdup_printf (_("Rendering page %d of %d..."), page_num, total);
+ gtk_widget_grab_focus (tab->priv->print_preview);
- gedit_progress_message_area_set_text (GEDIT_PROGRESS_MESSAGE_AREA (tab->priv->message_area),
- str);
- g_free (str);
-
- gedit_progress_message_area_set_fraction (GEDIT_PROGRESS_MESSAGE_AREA (tab->priv->message_area),
- 1.0 * page_num / total);
+ g_signal_connect (tab->priv->print_preview,
+ "destroy",
+ G_CALLBACK (print_preview_destroyed),
+ tab);
}
static void
@@ -2254,73 +2375,26 @@
gedit_tab_set_state (tab, GEDIT_TAB_STATE_SHOWING_PRINT_PREVIEW);
}
-static void
-print_finished_cb (GtkSourcePrintJob *pjob, GeditTab *tab)
-{
- GnomePrintJob *gjob;
- GeditView *view;
-
- g_return_if_fail (GEDIT_IS_PROGRESS_MESSAGE_AREA (tab->priv->message_area));
-
- set_message_area (tab, NULL); /* destroy the message area */
-
- gjob = gtk_source_print_job_get_print_job (pjob);
-
- gnome_print_job_print (gjob);
- g_object_unref (gjob);
-
- gedit_print_job_save_config (GEDIT_PRINT_JOB (pjob));
-
- g_object_unref (pjob);
- if (tab->priv->print_preview != NULL)
- {
- /* If we were printing while showing the print preview,
- see bug #352658 */
- gtk_widget_destroy (tab->priv->print_preview);
- g_return_if_fail (tab->priv->state == GEDIT_TAB_STATE_PRINTING);
- }
-
- gedit_tab_set_state (tab, GEDIT_TAB_STATE_NORMAL);
-
- view = gedit_tab_get_view (tab);
- gtk_widget_grab_focus (GTK_WIDGET (view));
-}
+#endif
static void
print_cancelled (GeditMessageArea *area,
gint response_id,
GeditTab *tab)
{
- GeditView *view;
-
g_return_if_fail (GEDIT_IS_PROGRESS_MESSAGE_AREA (tab->priv->message_area));
-
- gtk_source_print_job_cancel (GTK_SOURCE_PRINT_JOB (tab->priv->print_job));
- g_object_unref (tab->priv->print_job);
-
- set_message_area (tab, NULL); /* destroy the message area */
-
- if (tab->priv->print_preview != NULL)
- {
- /* If we were printing while showing the print preview,
- see bug #352658 */
- gtk_widget_destroy (tab->priv->print_preview);
- g_return_if_fail (tab->priv->state == GEDIT_TAB_STATE_PRINTING);
- }
- gedit_tab_set_state (tab, GEDIT_TAB_STATE_NORMAL);
+ gedit_print_job_cancel (tab->priv->print_job);
- view = gedit_tab_get_view (tab);
- gtk_widget_grab_focus (GTK_WIDGET (view));
+ g_debug ("print_cancelled");
}
static void
-show_printing_message_area (GeditTab *tab,
- gboolean preview)
+show_printing_message_area (GeditTab *tab, gboolean preview)
{
GtkWidget *area;
-
+
if (preview)
area = gedit_progress_message_area_new (GTK_STOCK_PRINT_PREVIEW,
"",
@@ -2329,7 +2403,6 @@
area = gedit_progress_message_area_new (GTK_STOCK_PRINT,
"",
TRUE);
-
g_signal_connect (area,
"response",
@@ -2339,101 +2412,138 @@
set_message_area (tab, area);
}
-void
-_gedit_tab_print (GeditTab *tab,
- gpointer print_job,
- GtkTextIter *start,
- GtkTextIter *end)
+static void
+page_setup_done_cb (GtkPageSetup *setup,
+ GeditTab *tab)
{
- GeditPrintJob *pjob;
- GeditDocument *doc;
+ if (setup != NULL)
+ {
+ GeditDocument *doc;
- pjob = (GeditPrintJob *) print_job;
+ doc = gedit_tab_get_document (tab);
+
+ /* remember it for this document */
+ g_object_set_data_full (G_OBJECT (doc),
+ GEDIT_PAGE_SETUP_KEY,
+ g_object_ref (setup),
+ (GDestroyNotify)g_object_unref);
+
+ /* make it the default */
+ _gedit_app_set_default_page_setup (gedit_app_get_default(),
+ setup);
+ }
+}
+
+void
+_gedit_tab_page_setup (GeditTab *tab)
+{
+ GtkPageSetup *setup;
+ GtkPrintSettings *settings;
g_return_if_fail (GEDIT_IS_TAB (tab));
- g_return_if_fail (GEDIT_IS_PRINT_JOB (pjob));
- g_return_if_fail (start != NULL);
- g_return_if_fail (end != NULL);
-
- doc = GEDIT_DOCUMENT (gtk_source_print_job_get_buffer (GTK_SOURCE_PRINT_JOB (pjob)));
- g_return_if_fail (doc != NULL);
- g_return_if_fail (gedit_tab_get_document (tab) == doc);
- g_return_if_fail (gtk_text_iter_get_buffer (start) == GTK_TEXT_BUFFER (doc));
- g_return_if_fail (gtk_text_iter_get_buffer (end) == GTK_TEXT_BUFFER (doc));
-
- g_return_if_fail (tab->priv->print_job == NULL);
- g_return_if_fail ((tab->priv->state == GEDIT_TAB_STATE_NORMAL) ||
- (tab->priv->state == GEDIT_TAB_STATE_SHOWING_PRINT_PREVIEW));
-
- g_object_ref (pjob);
- tab->priv->print_job = pjob;
- g_object_add_weak_pointer (G_OBJECT (pjob),
- (gpointer *) &tab->priv->print_job);
-
- show_printing_message_area (tab, FALSE);
- g_signal_connect (pjob, "begin_page", (GCallback) print_page_cb, tab);
- g_signal_connect (pjob, "finished", (GCallback) print_finished_cb, tab);
+ setup = get_page_setup (tab);
+ settings = get_print_settings (tab);
- gedit_tab_set_state (tab, GEDIT_TAB_STATE_PRINTING);
-
- if (!gtk_source_print_job_print_range_async (GTK_SOURCE_PRINT_JOB (pjob), start, end))
- {
- /* FIXME: go in error state */
- gtk_text_view_set_editable (GTK_TEXT_VIEW (tab->priv->view),
- !tab->priv->not_editable);
- g_warning ("Async print preview failed");
- g_object_unref (pjob);
- }
+ gtk_print_run_page_setup_dialog_async (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (tab))),
+ setup,
+ settings,
+ (GtkPageSetupDoneFunc) page_setup_done_cb,
+ tab);
+
+ /* CHECK: should we unref setup and settings? */
}
-void
-_gedit_tab_print_preview (GeditTab *tab,
- gpointer print_job,
- GtkTextIter *start,
- GtkTextIter *end)
+static void
+gedit_tab_print_or_print_preview (GeditTab *tab,
+ GtkPrintOperationAction print_action)
{
- GeditPrintJob *pjob;
- GeditDocument *doc;
-
- pjob = (GeditPrintJob *) print_job;
+ GeditView *view;
+ gboolean is_preview;
+ GtkPageSetup *setup;
+ GtkPrintSettings *settings;
+ GtkPrintOperationResult res;
+ GError *error = NULL;
- g_return_if_fail (GEDIT_IS_TAB (tab));
- g_return_if_fail (GEDIT_IS_PRINT_JOB (pjob));
- g_return_if_fail (start != NULL);
- g_return_if_fail (end != NULL);
-
- doc = GEDIT_DOCUMENT (gtk_source_print_job_get_buffer (GTK_SOURCE_PRINT_JOB (pjob)));
- g_return_if_fail (doc != NULL);
- g_return_if_fail (gedit_tab_get_document (tab) == doc);
- g_return_if_fail (gtk_text_iter_get_buffer (start) == GTK_TEXT_BUFFER (doc));
- g_return_if_fail (gtk_text_iter_get_buffer (end) == GTK_TEXT_BUFFER (doc));
-
g_return_if_fail (tab->priv->print_job == NULL);
g_return_if_fail (tab->priv->state == GEDIT_TAB_STATE_NORMAL);
-
- g_object_ref (pjob);
- tab->priv->print_job = pjob;
- g_object_add_weak_pointer (G_OBJECT (pjob),
+
+ view = gedit_tab_get_view (tab);
+
+ is_preview = (print_action == GTK_PRINT_OPERATION_ACTION_PREVIEW);
+
+ tab->priv->print_job = gedit_print_job_new (view);
+ g_object_add_weak_pointer (G_OBJECT (tab->priv->print_job),
(gpointer *) &tab->priv->print_job);
-
- show_printing_message_area (tab, TRUE);
- g_signal_connect (pjob, "begin_page", (GCallback) print_page_cb, tab);
- g_signal_connect (pjob, "finished", (GCallback) preview_finished_cb, tab);
+ show_printing_message_area (tab, is_preview);
- gedit_tab_set_state (tab, GEDIT_TAB_STATE_PRINT_PREVIEWING);
-
- if (!gtk_source_print_job_print_range_async (GTK_SOURCE_PRINT_JOB (pjob), start, end))
+ g_signal_connect (tab->priv->print_job,
+ "printing",
+ G_CALLBACK (printing_cb),
+ tab);
+ g_signal_connect (tab->priv->print_job,
+ "show-preview",
+ G_CALLBACK (show_preview_cb),
+ tab);
+ g_signal_connect (tab->priv->print_job,
+ "done",
+ G_CALLBACK (done_printing_cb),
+ tab);
+
+ if (is_preview)
+ gedit_tab_set_state (tab, GEDIT_TAB_STATE_PRINT_PREVIEWING);
+ else
+ gedit_tab_set_state (tab, GEDIT_TAB_STATE_PRINTING);
+
+ setup = get_page_setup (tab);
+ settings = get_print_settings (tab);
+
+ res = gedit_print_job_print (tab->priv->print_job,
+ print_action,
+ setup,
+ settings,
+ GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (tab))),
+ &error);
+
+ // TODO: manage res in the correct way
+ if (res == GTK_PRINT_OPERATION_RESULT_ERROR)
{
/* FIXME: go in error state */
gedit_tab_set_state (tab, GEDIT_TAB_STATE_NORMAL);
- g_warning ("Async print preview failed");
- g_object_unref (pjob);
+ g_warning ("Async print preview failed (%s)", error->message);
+ g_object_unref (tab->priv->print_job);
+ g_error_free (error);
}
}
void
+_gedit_tab_print (GeditTab *tab)
+{
+ g_return_if_fail (GEDIT_IS_TAB (tab));
+
+ /* FIXME: currently we can have just one printoperation going on
+ * at a given time, so before starting the print we close the preview.
+ * Would be nice to handle it properly though */
+ if (tab->priv->state == GEDIT_TAB_STATE_SHOWING_PRINT_PREVIEW)
+ {
+ gtk_widget_destroy (tab->priv->print_preview);
+ }
+
+ gedit_tab_print_or_print_preview (tab,
+ GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG);
+}
+
+void
+_gedit_tab_print_preview (GeditTab *tab)
+{
+ g_return_if_fail (GEDIT_IS_TAB (tab));
+
+ gedit_tab_print_or_print_preview (tab,
+ GTK_PRINT_OPERATION_ACTION_PREVIEW);
+}
+
+void
_gedit_tab_mark_for_closing (GeditTab *tab)
{
g_return_if_fail (GEDIT_IS_TAB (tab));
Modified: trunk/gedit/gedit-tab.h
==============================================================================
--- trunk/gedit/gedit-tab.h (original)
+++ trunk/gedit/gedit-tab.h Thu Jan 24 22:15:19 2008
@@ -146,16 +146,10 @@
const gchar *uri,
const GeditEncoding *encoding);
-/* print_job is a gpointer instead of GeditPrintJob because gedit-print is
- * is not public so it cannot be included in this header */
-void _gedit_tab_print (GeditTab *tab,
- gpointer print_job,
- GtkTextIter *start,
- GtkTextIter *end);
-void _gedit_tab_print_preview (GeditTab *tab,
- gpointer print_job,
- GtkTextIter *start,
- GtkTextIter *end);
+void _gedit_tab_page_setup (GeditTab *tab);
+void _gedit_tab_print (GeditTab *tab);
+void _gedit_tab_print_preview (GeditTab *tab);
+
void _gedit_tab_mark_for_closing (GeditTab *tab);
gboolean _gedit_tab_can_close (GeditTab *tab);
Modified: trunk/gedit/gedit-window.c
==============================================================================
--- trunk/gedit/gedit-window.c (original)
+++ trunk/gedit/gedit-window.c Thu Jan 24 22:15:19 2008
@@ -680,6 +680,8 @@
(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));
action = gtk_action_group_get_action (window->priv->action_group,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]