return unlink_temp_file;
}
+static const gchar *
+get_print_settings_from_args (GHashTable *args)
+{
+ const gchar *print_settings = NULL;
+ GValue *value = NULL;
+
+ g_assert (args != NULL);
+
+ value = g_hash_table_lookup (args, "print-settings");
+ if (value) {
+ print_settings = g_value_get_string (value);
+ }
+
+ return print_settings;
+}
+
/**
* ev_application_open_window:
* @application: The instance of the application.
EvLinkDest *dest,
EvWindowRunMode mode,
gboolean unlink_temp_file,
+ const gchar *print_settings,
guint timestamp)
{
- EvWindow *new_window;
+ EvWindow *new_window;
g_return_if_fail (uri != NULL);
/* We need to load uri before showing the window, so
we can restore window size without flickering */
- ev_window_open_uri (new_window, uri, dest, mode, unlink_temp_file);
+ ev_window_open_uri (new_window, uri, dest, mode,
+ unlink_temp_file, print_settings);
ev_document_fc_mutex_lock ();
gtk_widget_show (GTK_WIDGET (new_window));
EvLinkDest *dest = NULL;
EvWindowRunMode mode = EV_WINDOW_MODE_NORMAL;
gboolean unlink_temp_file = FALSE;
+ const gchar *print_settings;
GdkScreen *screen = NULL;
if (args) {
mode = get_window_run_mode_from_args (args);
unlink_temp_file = (mode == EV_WINDOW_MODE_PREVIEW &&
get_unlink_temp_file_from_args (args));
+ print_settings = get_print_settings_from_args (args);
}
ev_application_open_uri_at_dest (application, uri, screen,
- dest, mode, unlink_temp_file,
- timestamp);
+ dest, mode, unlink_temp_file,
+ print_settings, timestamp);
if (dest)
g_object_unref (dest);
for (l = uri_list; l != NULL; l = l->next) {
ev_application_open_uri_at_dest (application, (char *)l->data,
- screen, NULL, 0, FALSE,
- timestamp);
+ screen, NULL, 0, FALSE,
+ NULL, timestamp);
}
}
/* Preview mode */
GtkWidget *preview_toolbar;
+ gchar *print_settings_file;
/* Popup view */
GtkWidget *view_popup;
ev_window_set_action_sensitive (ev_window, PAGE_SELECTOR_ACTION, has_pages);
ev_window_set_action_sensitive (ev_window, ZOOM_CONTROL_ACTION, has_pages);
ev_window_set_action_sensitive (ev_window, NAVIGATION_ACTION, FALSE);
+ ev_window_set_action_sensitive (ev_window, "PreviewPrint", has_pages && ok_to_print);
ev_window_update_actions (ev_window);
}
}
}
+static void
+ev_window_clear_print_settings_file (EvWindow *ev_window)
+{
+ if (ev_window->priv->print_settings_file) {
+ g_unlink (ev_window->priv->print_settings_file);
+ g_free (ev_window->priv->print_settings_file);
+ ev_window->priv->print_settings_file = NULL;
+ }
+}
+
static void
ev_window_clear_temp_file (EvWindow *ev_window)
{
const char *uri,
EvLinkDest *dest,
EvWindowRunMode mode,
- gboolean unlink_temp_file)
+ gboolean unlink_temp_file,
+ const gchar *print_settings)
{
GnomeVFSURI *source_uri;
GnomeVFSURI *target_uri;
ev_window_close_dialogs (ev_window);
ev_window_clear_load_job (ev_window);
ev_window_clear_local_uri (ev_window);
+ ev_window_clear_print_settings_file (ev_window);
ev_view_set_loading (EV_VIEW (ev_window->priv->view), TRUE);
ev_window->priv->unlink_temp_file = unlink_temp_file;
+ if (mode == EV_WINDOW_MODE_PREVIEW) {
+ ev_window->priv->print_settings_file = print_settings ?
+ g_strdup (print_settings) : NULL;
+ }
+
if (ev_window->priv->uri)
g_free (ev_window->priv->uri);
ev_window->priv->uri = g_strdup (uri);
dest,
0,
TRUE,
+ NULL,
GDK_CURRENT_TIME);
g_free (symlink_uri);
}
ev_application_open_uri_at_dest (EV_APP, uri,
gtk_window_get_screen (GTK_WINDOW (window)),
- NULL, 0, FALSE,
+ NULL, 0, FALSE, NULL,
GDK_CURRENT_TIME);
}
#else
ev_application_open_uri_at_dest (EV_APP, uri,
gtk_window_get_screen (GTK_WINDOW (ev_window)),
- NULL, 0, FALSE,
+ NULL, 0, FALSE, NULL,
GDK_CURRENT_TIME);
g_free (uri);
static void
ev_window_run_preview (EvWindow *window)
{
+ GtkAction *action;
+
if (!window->priv->preview_toolbar) {
window->priv->preview_toolbar =
gtk_ui_manager_get_widget (window->priv->ui_manager,
update_chrome_flag (window, EV_CHROME_SIDEBAR, FALSE);
update_chrome_flag (window, EV_CHROME_PREVIEW_TOOLBAR, TRUE);
+
+ action = gtk_action_group_get_action (window->priv->action_group,
+ "PreviewPrint");
+#if GTK_CHECK_VERSION (2, 11, 0)
+ gtk_action_set_visible (action, TRUE);
+#else
+ gtk_action_set_visible (action, FALSE);
+#endif
update_chrome_visibility (window);
}
gchar *uri;
uri = g_strdup (ev_window->priv->uri);
- ev_window_open_uri (ev_window, uri, NULL, 0, FALSE);
+ ev_window_open_uri (ev_window, uri, NULL, 0, FALSE, NULL);
g_free (uri);
}
ev_window_run_presentation (window);
}
+#ifdef WITH_GTK_PRINT
+static gboolean
+lookup_printer_from_name (GtkPrinter *printer,
+ EvWindow *window)
+{
+ const gchar *printer_name;
+
+ printer_name = gtk_print_settings_get_printer (window->priv->print_settings);
+
+ if ((printer_name
+ && g_ascii_strcasecmp (printer_name, gtk_printer_get_name (printer)) == 0) ||
+ (!printer_name && gtk_printer_is_default (printer))) {
+ if (window->priv->printer)
+ g_object_unref (window->priv->printer);
+ window->priv->printer = g_object_ref (printer);
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static void
+ev_window_preview_print_finished (GtkPrintJob *print_job,
+ EvWindow *window,
+ GError *error)
+{
+ if (error) {
+ GtkWidget *dialog;
+
+ dialog = gtk_message_dialog_new (GTK_WINDOW (window),
+ GTK_DIALOG_MODAL,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_OK,
+ _("Failed to print document"));
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+ error->message);
+
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+ }
+
+ g_object_unref (print_job);
+ gtk_widget_destroy (GTK_WIDGET (window));
+}
+#endif /* WITH_GTK_PRINT */
+
+static void
+ev_window_cmd_preview_print (GtkAction *action, EvWindow *window)
+{
+#ifdef WITH_GTK_PRINT
+ GtkPrintSettings *print_settings = NULL;
+ GtkPageSetup *page_setup;
+ GtkPrintJob *job;
+ gchar *filename;
+ GError *error = NULL;
+#if GTK_CHECK_VERSION (2, 11, 0)
+ const gchar *print_settings_file = window->priv->print_settings_file;
+
+ if (print_settings_file) {
+ if (g_file_test (print_settings_file, G_FILE_TEST_IS_REGULAR)) {
+ GError *error = NULL;
+
+ print_settings = gtk_print_settings_new_from_file (print_settings_file,
+ &error);
+
+ if (error) {
+ g_warning (error->message);
+ g_error_free (error);
+ print_settings = NULL;
+ }
+ }
+ }
+#endif /* GTK 2.11.0 */
+
+ if (!print_settings)
+ print_settings = gtk_print_settings_new ();
+
+ if (window->priv->print_settings)
+ g_object_unref (window->priv->print_settings);
+ window->priv->print_settings = print_settings;
+
+ gtk_enumerate_printers ((GtkPrinterFunc) lookup_printer_from_name,
+ window, NULL, TRUE);
+ g_assert (GTK_IS_PRINTER (window->priv->printer));
+
+ page_setup = gtk_page_setup_new ();
+
+ job = gtk_print_job_new ("evince-print",
+ window->priv->printer,
+ window->priv->print_settings,
+ page_setup);
+
+ g_object_unref (window->priv->print_settings);
+ window->priv->print_settings = NULL;
+ g_object_unref (window->priv->printer);
+ window->priv->printer = NULL;
+ g_object_unref (page_setup);
+
+ filename = g_filename_from_uri (window->priv->local_uri ?
+ window->priv->local_uri : window->priv->uri,
+ NULL, NULL);
+
+ if (gtk_print_job_set_source_file (job, filename, &error)) {
+ gtk_print_job_send (job,
+ (GtkPrintJobCompleteFunc)ev_window_preview_print_finished,
+ window, NULL);
+ } else {
+ g_warning (error->message);
+ g_error_free (error);
+ }
+
+ g_free (filename);
+
+ gtk_widget_hide (GTK_WIDGET (window));
+#endif /* WITH_GTK_PRINT */
+}
+
static void
ev_window_cmd_escape (GtkAction *action, EvWindow *window)
{
priv->history = NULL;
}
+ if (priv->print_settings_file) {
+ ev_window_clear_print_settings_file (window);
+ priv->print_settings_file = NULL;
+ }
+
if (priv->presentation_timeout_id > 0) {
g_source_remove (priv->presentation_timeout_id);
priv->presentation_timeout_id = 0;
{ "StartPresentation", EV_STOCK_RUN_PRESENTATION, N_("Start Presentation"), NULL,
N_("Start a presentation"),
G_CALLBACK (ev_window_cmd_start_presentation) },
+ { "PreviewPrint", GTK_STOCK_PRINT, N_("Print"), NULL,
+ N_("Print this document"),
+ G_CALLBACK (ev_window_cmd_preview_print) },
/* Accellerators */
{ "Escape", NULL, "", "Escape", "",
ev_link_action_get_dest (action),
0,
FALSE,
+ NULL,
GDK_CURRENT_TIME);
g_free (uri);
static gboolean fullscren_mode = FALSE;
static gboolean presentation_mode = FALSE;
static gboolean unlink_temp_file = FALSE;
+static gchar *print_settings;
static const char **file_arguments = NULL;
static const GOptionEntry goption_options[] =
{ "presentation", 's', 0, G_OPTION_ARG_NONE, &presentation_mode, N_("Run evince in presentation mode"), NULL },
{ "preview", 'w', 0, G_OPTION_ARG_NONE, &preview_mode, N_("Run evince as a previewer"), NULL },
{ "unlink-tempfile", 'u', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &unlink_temp_file, NULL, NULL },
+ { "print-settings", 't', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_FILENAME, &print_settings, NULL, NULL },
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &file_arguments, NULL, N_("[FILE...]") },
{ NULL }
};
g_value_set_string (value, ev_page_label);
g_hash_table_insert (args, g_strdup ("page-label"), value);
+
+ g_free (ev_page_label);
+ ev_page_label = NULL;
}
if (fullscren_mode)
value);
}
+ if (mode == EV_WINDOW_MODE_PREVIEW && print_settings) {
+ value = g_new0 (GValue, 1);
+ g_value_init (value, G_TYPE_STRING);
+ g_value_set_string (value, print_settings);
+
+ g_hash_table_insert (args,
+ g_strdup ("print-settings"),
+ value);
+ g_free (print_settings);
+ print_settings = NULL;
+ }
+
return args;
}