Commit 1d7c1e13 authored by Marek Kašík's avatar Marek Kašík Committed by Marek Kašík

Bug 344522 – support non-local destination files (GtkPrint):

2008-09-30  Marek Kasik  <mkasik@redhat.com>

	Bug 344522 – support non-local destination files (GtkPrint):

	* gtk/gtkprintunixdialog.c
	* gtk/gtkprinteroptionwidget.c: Process URI instead of filename.
	* modules/printbackends/file/gtkprintbackendfile.c: Add ability
	to save files on non-local filesystems.

svn path=/trunk/; revision=21552
parent 6a3a9c95
2008-09-30 Marek Kasik <mkasik@redhat.com>
Bug 344522 – support non-local destination files (GtkPrint):
* gtk/gtkprintunixdialog.c
* gtk/gtkprinteroptionwidget.c: Process URI instead of filename.
* modules/printbackends/file/gtkprintbackendfile.c: Add ability
to save files on non-local filesystems.
2008-09-30 Michael Natterer <mitch@imendio.com>
* gtk/gtk.symbols: forgot the G_GNUC_CONST of
......
......@@ -454,8 +454,8 @@ filesave_changed_cb (GtkWidget *button,
{
GtkPrinterOptionWidgetPrivate *priv = widget->priv;
gchar *uri, *file;
gchar *directory;
/* TODO: how do we support nonlocal file systems? */
file = g_filename_from_utf8 (gtk_entry_get_text (GTK_ENTRY (priv->entry)),
-1, NULL, NULL, NULL);
if (file == NULL)
......@@ -464,31 +464,38 @@ filesave_changed_cb (GtkWidget *button,
/* combine the value of the chooser with the value of the entry */
g_signal_handler_block (priv->source, priv->source_changed_handler);
if (g_path_is_absolute (file))
uri = g_filename_to_uri (file, NULL, NULL);
else
directory = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (priv->combo));
if ((g_uri_parse_scheme (file) == NULL) && (directory != NULL))
{
gchar *path;
if (g_path_is_absolute (file))
uri = g_filename_to_uri (file, NULL, NULL);
else
{
gchar *path;
#ifdef G_OS_UNIX
if (file[0] == '~' && file[1] == '/')
{
path = g_build_filename (g_get_home_dir (), file + 2, NULL);
}
else
if (file[0] == '~' && file[1] == '/')
{
path = g_build_filename (g_get_home_dir (), file + 2, NULL);
}
else
#endif
{
gchar *directory;
{
path = g_build_filename (directory, file, NULL);
}
directory = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (priv->combo));
path = g_build_filename (directory, file, NULL);
uri = g_filename_to_uri (path, NULL, NULL);
g_free (directory);
g_free (path);
}
uri = g_filename_to_uri (path, NULL, NULL);
g_free (path);
}
else
{
if (g_uri_parse_scheme (file) != NULL)
uri = g_strdup (file);
else
uri = g_build_path ("/", gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (priv->combo)), file, NULL);
}
if (uri)
......@@ -496,6 +503,7 @@ filesave_changed_cb (GtkWidget *button,
g_free (uri);
g_free (file);
g_free (directory);
g_signal_handler_unblock (priv->source, priv->source_changed_handler);
emit_changed (widget);
......@@ -783,6 +791,8 @@ construct_widgets (GtkPrinterOptionWidget *widget)
priv->combo = gtk_file_chooser_button_new (source->display_text,
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
g_object_set (priv->combo, "local-only", FALSE, NULL);
label = gtk_label_new_with_mnemonic (_("_Name:"));
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_label_set_mnemonic_widget (GTK_LABEL (label), priv->entry);
......
......@@ -333,7 +333,7 @@ error_dialogs (GtkPrintUnixDialog *print_dialog,
GtkPrinter *printer = NULL;
GtkWindow *toplevel = NULL;
GtkWidget *dialog = NULL;
gchar *filename = NULL;
GFile *file = NULL;
gchar *basename = NULL;
gchar *dirname = NULL;
int response;
......@@ -352,15 +352,15 @@ error_dialogs (GtkPrintUnixDialog *print_dialog,
if (option != NULL &&
option->type == GTK_PRINTER_OPTION_TYPE_FILESAVE)
{
filename = g_filename_from_uri (option->value, NULL, NULL);
file = g_file_new_for_uri (option->value);
if (filename != NULL &&
g_file_test (filename, G_FILE_TEST_EXISTS))
if (file != NULL &&
g_file_query_exists (file, NULL))
{
toplevel = get_toplevel (GTK_WIDGET (print_dialog));
basename = g_path_get_basename (filename);
dirname = g_path_get_dirname (filename);
basename = g_file_get_basename (file);
dirname = g_file_get_parse_name (g_file_get_parent (file));
dialog = gtk_message_dialog_new (toplevel,
GTK_DIALOG_MODAL |
......@@ -396,17 +396,18 @@ error_dialogs (GtkPrintUnixDialog *print_dialog,
gtk_widget_destroy (dialog);
g_free (dirname);
g_free (basename);
if (response != GTK_RESPONSE_ACCEPT)
{
g_signal_stop_emission_by_name (print_dialog, "response");
g_object_unref (file);
return TRUE;
}
g_free (dirname);
g_free (basename);
}
g_free (filename);
g_object_unref (file);
}
}
}
......
......@@ -316,7 +316,7 @@ typedef struct {
GtkPrintBackend *backend;
GtkPrintJobCompleteFunc callback;
GtkPrintJob *job;
GIOChannel *target_io;
GFileOutputStream *target_io_stream;
gpointer user_data;
GDestroyNotify dnotify;
} _PrintStreamData;
......@@ -330,8 +330,8 @@ file_print_cb (GtkPrintBackendFile *print_backend,
GDK_THREADS_ENTER ();
if (ps->target_io != NULL)
g_io_channel_unref (ps->target_io);
if (ps->target_io_stream != NULL)
g_output_stream_close (G_OUTPUT_STREAM (ps->target_io_stream), NULL, NULL);
if (ps->callback)
ps->callback (ps->job, ps->user_data, error);
......@@ -374,11 +374,12 @@ file_write (GIOChannel *source,
{
gsize bytes_written;
g_io_channel_write_chars (ps->target_io,
buf,
bytes_read,
&bytes_written,
&error);
g_output_stream_write_all (G_OUTPUT_STREAM (ps->target_io_stream),
buf,
bytes_read,
&bytes_written,
NULL,
&error);
}
if (error != NULL || read_status == G_IO_STATUS_EOF)
......@@ -414,7 +415,8 @@ gtk_print_backend_file_print_stream (GtkPrintBackend *print_backend,
GtkPrinter *printer;
_PrintStreamData *ps;
GtkPrintSettings *settings;
gchar *uri, *filename;
gchar *uri;
GFile *file = NULL;
printer = gtk_print_job_get_printer (job);
settings = gtk_print_job_get_settings (job);
......@@ -428,18 +430,15 @@ gtk_print_backend_file_print_stream (GtkPrintBackend *print_backend,
internal_error = NULL;
uri = output_file_from_settings (settings, NULL);
filename = g_filename_from_uri (uri, NULL, &internal_error);
g_free (uri);
if (filename == NULL)
if (uri == NULL)
goto error;
ps->target_io = g_io_channel_new_file (filename, "w", &internal_error);
file = g_file_new_for_uri (uri);
ps->target_io_stream = g_file_replace (file, NULL, FALSE, G_FILE_CREATE_NONE, NULL, &internal_error);
g_free (filename);
if (internal_error == NULL)
g_io_channel_set_encoding (ps->target_io, NULL, &internal_error);
g_object_unref (file);
g_free (uri);
error:
if (internal_error != NULL)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment