]> Pileus Git - ~andy/gtk/commitdiff
GTK PrintToFile settings
authorTimothy Arceri <t_arceri@yahoo.com.au>
Tue, 6 Mar 2012 10:15:01 +0000 (21:15 +1100)
committerMarek Kasik <mkasik@redhat.com>
Mon, 14 May 2012 12:26:53 +0000 (14:26 +0200)
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

gtk/gtkprintsettings.h
modules/printbackends/file/gtkprintbackendfile.c

index dd4dd6d13ae39e4280a76cfda1b228631a4cf57e..3323a7bc01feda0575b4b486dba6fd49fb210818 100644 (file)
@@ -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:
index 32ce8c5b109f2e43b196cdcba42e274d37adb277..3041d706065782d0d85bd2a3d6ffa7366066a923 100644 (file)
@@ -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;