+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
{
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)
/* 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)
g_free (uri);
g_free (file);
+ g_free (directory);
g_signal_handler_unblock (priv->source, priv->source_changed_handler);
emit_changed (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);
GtkPrinter *printer = NULL;
GtkWindow *toplevel = NULL;
GtkWidget *dialog = NULL;
- gchar *filename = NULL;
+ GFile *file = NULL;
gchar *basename = NULL;
gchar *dirname = NULL;
int response;
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 |
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);
}
}
}
GtkPrintBackend *backend;
GtkPrintJobCompleteFunc callback;
GtkPrintJob *job;
- GIOChannel *target_io;
+ GFileOutputStream *target_io_stream;
gpointer user_data;
GDestroyNotify dnotify;
} _PrintStreamData;
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);
{
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)
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);
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)