forked from AuroraMiddleware/gtk
GTK PrintToFile settings
To make setting output directory and filename simpler in the PrintToFile dialog two gtkprintsettings have been added GTK_PRINT_SETTINGS_OUTPUT_DIR and GTK_PRINT_SETTINGS_OUTPUT_BASENAME. This will reduce the code needed to implement a better name than "output.pdf" and actually makes more sense than the existing setting GTK_PRINT_SETTINGS_OUTPUT_URI which doesn't work seamlessly with GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT like the new settings do. https://bugzilla.gnome.org/show_bug.cgi?id=657322
This commit is contained in:
parent
f730f519f8
commit
8d1f32aaaf
@ -134,6 +134,8 @@ void gtk_print_settings_set_int (GtkPrintSettings
|
||||
#define GTK_PRINT_SETTINGS_RESOLUTION_X "resolution-x"
|
||||
#define GTK_PRINT_SETTINGS_RESOLUTION_Y "resolution-y"
|
||||
#define GTK_PRINT_SETTINGS_PRINTER_LPI "printer-lpi"
|
||||
#define GTK_PRINT_SETTINGS_OUTPUT_DIR "output-dir"
|
||||
#define GTK_PRINT_SETTINGS_OUTPUT_BASENAME "output-basename"
|
||||
|
||||
/**
|
||||
* GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT:
|
||||
|
@ -213,13 +213,13 @@ output_file_from_settings (GtkPrintSettings *settings,
|
||||
const gchar *default_format)
|
||||
{
|
||||
gchar *uri = NULL;
|
||||
|
||||
|
||||
if (settings)
|
||||
uri = g_strdup (gtk_print_settings_get (settings, GTK_PRINT_SETTINGS_OUTPUT_URI));
|
||||
|
||||
if (uri == NULL)
|
||||
{
|
||||
const gchar *extension;
|
||||
const gchar *extension, *basename, *output_dir;
|
||||
gchar *name, *locale_name, *path;
|
||||
|
||||
if (default_format)
|
||||
@ -243,30 +243,43 @@ output_file_from_settings (GtkPrintSettings *settings,
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* default filename used for print-to-file */
|
||||
name = g_strdup_printf (_("output.%s"), extension);
|
||||
|
||||
basename = gtk_print_settings_get (settings, GTK_PRINT_SETTINGS_OUTPUT_BASENAME);
|
||||
if (basename == NULL)
|
||||
basename = _("output");
|
||||
|
||||
name = g_strconcat (basename, ".", extension, NULL);
|
||||
|
||||
locale_name = g_filename_from_utf8 (name, -1, NULL, NULL, NULL);
|
||||
g_free (name);
|
||||
|
||||
if (locale_name != NULL)
|
||||
{
|
||||
const gchar *document_dir = g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS);
|
||||
|
||||
if (document_dir == NULL)
|
||||
{
|
||||
output_dir = gtk_print_settings_get (settings, GTK_PRINT_SETTINGS_OUTPUT_DIR);
|
||||
if (output_dir == NULL)
|
||||
{
|
||||
gchar *current_dir = g_get_current_dir ();
|
||||
path = g_build_filename (current_dir, locale_name, NULL);
|
||||
g_free (current_dir);
|
||||
}
|
||||
const gchar *document_dir = g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS);
|
||||
|
||||
if (document_dir == NULL)
|
||||
{
|
||||
gchar *current_dir = g_get_current_dir ();
|
||||
path = g_build_filename (current_dir, locale_name, NULL);
|
||||
g_free (current_dir);
|
||||
}
|
||||
else
|
||||
path = g_build_filename (document_dir, locale_name, NULL);
|
||||
|
||||
uri = g_filename_to_uri (path, NULL, NULL);
|
||||
}
|
||||
else
|
||||
path = g_build_filename (document_dir, locale_name, NULL);
|
||||
|
||||
uri = g_filename_to_uri (path, NULL, NULL);
|
||||
{
|
||||
path = g_build_filename (output_dir, locale_name, NULL);
|
||||
uri = g_filename_to_uri (path, NULL, NULL);
|
||||
}
|
||||
|
||||
g_free (path);
|
||||
g_free (locale_name);
|
||||
g_free (path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return uri;
|
||||
|
Loading…
Reference in New Issue
Block a user