mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-26 21:51:08 +00:00
Convert input to filename encoding and construct an URI from that. Add
2006-06-20 Christian Persch <chpe@cvs.gnome.org> * gtk/gtkprinteroptionwidget.c: (filesave_changed_cb), (alternative_set), (construct_widgets): Convert input to filename encoding and construct an URI from that. * gtk/gtkprintsettings.h: Add OUTPUT_FILE_FORMAT and OUTPUT_URI keys. * modules/printbackends/pdf/gtkprintbackendpdf.c: Use those defines. Step 1 from bug #339592.
This commit is contained in:
parent
2406a5b256
commit
0bce4d271a
@ -411,31 +411,41 @@ filesave_changed_cb (GtkWidget *w,
|
||||
GtkPrinterOptionWidget *widget)
|
||||
{
|
||||
GtkPrinterOptionWidgetPrivate *priv = widget->priv;
|
||||
char *value;
|
||||
char *directory;
|
||||
const char *file;
|
||||
gchar *uri, *directory, *path;
|
||||
const gchar *file;
|
||||
|
||||
/* TODO: how do we support nonlocal file systems? */
|
||||
directory = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (priv->combo));
|
||||
file = g_filename_from_utf8 (gtk_entry_get_text (GTK_ENTRY (priv->entry)),
|
||||
-1, NULL, NULL, NULL);
|
||||
if (file == NULL)
|
||||
return;
|
||||
|
||||
/* combine the value of the chooser with the value of the entry */
|
||||
g_signal_handler_block (priv->source, priv->source_changed_handler);
|
||||
|
||||
/* TODO: how do we support nonlocal file systems? */
|
||||
directory = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (priv->combo));
|
||||
file = gtk_entry_get_text (GTK_ENTRY (priv->entry));
|
||||
|
||||
if (g_path_is_absolute (file))
|
||||
value = g_strdup (file);
|
||||
#ifdef G_OS_UNIX
|
||||
else if (file[0] == '~' && file[1] == '/')
|
||||
value = g_build_filename (g_get_home_dir (), file + 2, NULL);
|
||||
#endif
|
||||
uri = g_filename_to_uri (file, NULL, NULL);
|
||||
else
|
||||
value = g_build_filename (directory, file, NULL);
|
||||
{
|
||||
#ifdef G_OS_UNIX
|
||||
if (file[0] == '~' && file[1] == '/')
|
||||
{
|
||||
directory = g_strdup (g_get_home_dir ());
|
||||
file += 2;
|
||||
}
|
||||
#endif
|
||||
|
||||
path = g_build_filename (directory, file, NULL);
|
||||
uri = g_filename_to_uri (path, NULL, NULL);
|
||||
g_free (path);
|
||||
}
|
||||
|
||||
if (value)
|
||||
gtk_printer_option_set (priv->source, value);
|
||||
if (uri)
|
||||
gtk_printer_option_set (priv->source, uri);
|
||||
|
||||
g_free (directory);
|
||||
g_free (value);
|
||||
g_free (uri);
|
||||
|
||||
g_signal_handler_unblock (priv->source, priv->source_changed_handler);
|
||||
emit_changed (widget);
|
||||
@ -505,7 +515,7 @@ alternative_set (GtkWidget *box,
|
||||
{
|
||||
gtk_container_foreach (GTK_CONTAINER (box),
|
||||
(GtkCallback) select_maybe,
|
||||
value);
|
||||
(gpointer) value);
|
||||
}
|
||||
|
||||
static GSList *
|
||||
@ -619,8 +629,8 @@ construct_widgets (GtkPrinterOptionWidget *widget)
|
||||
|
||||
/* TODO: make this a gtkfilechooserentry once we move to GTK */
|
||||
priv->entry = gtk_entry_new ();
|
||||
priv->combo = gtk_file_chooser_button_new (_("Print to PDF"),
|
||||
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
|
||||
priv->combo = gtk_file_chooser_button_new (source->display_text,
|
||||
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
|
||||
|
||||
label = gtk_label_new_with_mnemonic (_("_Name:"));
|
||||
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
|
||||
|
@ -110,6 +110,9 @@ void gtk_print_settings_set_int (GtkPrintSettings
|
||||
#define GTK_PRINT_SETTINGS_NUMBER_UP "number-up"
|
||||
#define GTK_PRINT_SETTINGS_OUTPUT_BIN "output-bin"
|
||||
|
||||
#define GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT "output-file-format"
|
||||
#define GTK_PRINT_SETTINGS_OUTPUT_URI "output-uri"
|
||||
|
||||
#define GTK_PRINT_SETTINGS_WIN32_DRIVER_VERSION "win32-driver-version"
|
||||
#define GTK_PRINT_SETTINGS_WIN32_DRIVER_EXTRA "win32-driver-extra"
|
||||
|
||||
|
@ -305,25 +305,32 @@ gtk_print_backend_pdf_print_stream (GtkPrintBackend *print_backend,
|
||||
_PrintStreamData *ps;
|
||||
GtkPrintSettings *settings;
|
||||
GIOChannel *save_channel;
|
||||
const char *filename;
|
||||
const gchar *uri;
|
||||
gchar *filename = NULL; /* quit gcc */
|
||||
|
||||
printer = gtk_print_job_get_printer (job);
|
||||
settings = gtk_print_job_get_settings (job);
|
||||
|
||||
error = NULL;
|
||||
|
||||
filename = gtk_print_settings_get (settings, "pdf-filename");
|
||||
uri = gtk_print_settings_get (settings, GTK_PRINT_SETTINGS_OUTPUT_URI);
|
||||
if (uri)
|
||||
filename = g_filename_from_uri (uri, NULL, NULL);
|
||||
/* FIXME: shouldn't we error out if we get an URI we cannot handle,
|
||||
* rather than to print to some random file somewhere?
|
||||
*/
|
||||
if (filename == NULL)
|
||||
filename = "output.pdf";
|
||||
filename = g_strdup_printf ("output.pdf");
|
||||
|
||||
ps = g_new0 (_PrintStreamData, 1);
|
||||
ps->callback = callback;
|
||||
ps->user_data = user_data;
|
||||
ps->dnotify = dnotify;
|
||||
ps->job = g_object_ref (job);
|
||||
ps->backend = print_backend;
|
||||
|
||||
ps->target_fd = creat (filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
|
||||
ps->backend = print_backend;
|
||||
g_free (filename);
|
||||
|
||||
if (ps->target_fd == -1)
|
||||
{
|
||||
@ -376,7 +383,7 @@ pdf_printer_get_options (GtkPrinter *printer,
|
||||
{
|
||||
GtkPrinterOptionSet *set;
|
||||
GtkPrinterOption *option;
|
||||
const char *filename;
|
||||
const char *uri;
|
||||
char *n_up[] = {"1" };
|
||||
|
||||
set = gtk_printer_option_set_new ();
|
||||
@ -394,8 +401,8 @@ pdf_printer_get_options (GtkPrinter *printer,
|
||||
gtk_printer_option_set_add (set, option);
|
||||
|
||||
if (settings != NULL &&
|
||||
(filename = gtk_print_settings_get (settings, "pdf-filename"))!= NULL)
|
||||
gtk_printer_option_set (option, filename);
|
||||
(uri = gtk_print_settings_get (settings, GTK_PRINT_SETTINGS_OUTPUT_URI))!= NULL)
|
||||
gtk_printer_option_set (option, uri);
|
||||
|
||||
return set;
|
||||
}
|
||||
@ -408,7 +415,7 @@ pdf_printer_get_settings_from_options (GtkPrinter *printer,
|
||||
GtkPrinterOption *option;
|
||||
|
||||
option = gtk_printer_option_set_lookup (options, "gtk-main-page-custom-input");
|
||||
gtk_print_settings_set (settings, "pdf-filename", option->value);
|
||||
gtk_print_settings_set (settings, GTK_PRINT_SETTINGS_OUTPUT_URI, option->value);
|
||||
}
|
||||
|
||||
static void
|
||||
|
Loading…
Reference in New Issue
Block a user