eog r4518 - in trunk: . src



Author: csaavedra
Date: Sat Apr  5 16:19:14 2008
New Revision: 4518
URL: http://svn.gnome.org/viewvc/eog?rev=4518&view=rev

Log:
2008-04-05  Claudio Saavedra  <csaavedra gnome org>

	* src/eog-print.c: (eog_print_get_key_file),
	(eog_print_get_page_setup), (eog_print_save_key_file),
	(eog_print_set_page_setup), (eog_print_get_print_settings),
	(eog_print_set_print_settings): New API to save/load print
	settings to/from a GKeyFile.
	* src/eog-print.h: Add headers for public API.
	* src/eog-window.c: (eog_window_page_setup), (eog_window_print),
	(eog_window_init), (eog_window_dispose): Load and save print
	settings to and from a GKeyFile. Fixes bug #517821.



Modified:
   trunk/ChangeLog
   trunk/src/eog-print.c
   trunk/src/eog-print.h
   trunk/src/eog-window.c

Modified: trunk/src/eog-print.c
==============================================================================
--- trunk/src/eog-print.c	(original)
+++ trunk/src/eog-print.c	Sat Apr  5 16:19:14 2008
@@ -23,8 +23,14 @@
 #include <glib/gi18n.h>
 #include "eog-print.h"
 #include "eog-print-image-setup.h"
+#include "eog-util.h"
 #include "eog-debug.h"
 
+#define EOG_PRINT_SETTINGS_FILE "eog-print-settings.ini"
+#define EOG_PAGE_SETUP_GROUP "Page Setup"
+#define EOG_PRINT_SETTINGS_GROUP "Print Settings"
+#define EOG_PAPER_SIZE_GROUP "Paper Size"
+
 typedef struct {
 	EogImage *image;
 	gdouble left_margin;
@@ -193,3 +199,150 @@
 
 	return print;
 }
+
+static GKeyFile *
+eog_print_get_key_file (void)
+{
+	GKeyFile *key_file;
+	GError *error = NULL;
+	gchar *filename;
+	GFile *file;
+	const gchar *dot_dir = eog_util_dot_dir ();
+
+	filename = g_build_filename (dot_dir, EOG_PRINT_SETTINGS_FILE, NULL);
+
+	file = g_file_new_for_path (filename);
+	key_file = g_key_file_new ();
+
+	if (g_file_query_exists (file, NULL)) {
+		g_key_file_load_from_file (key_file, filename,
+					   G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS,
+					   &error);
+		if (error) {
+			g_warning (_("Error loading print settings file: %s"), error->message);
+			g_error_free (error);
+			g_object_unref (file);
+			g_free (filename);
+			g_key_file_free (key_file);
+			return NULL;
+		}
+	}
+
+	g_object_unref (file);
+	g_free (filename);
+
+	return key_file;
+}
+
+GtkPageSetup *
+eog_print_get_page_setup (void)
+{
+	GtkPageSetup *page_setup;
+	GKeyFile *key_file;
+	GError *error = NULL;
+
+	key_file = eog_print_get_key_file ();
+
+	if (key_file && g_key_file_has_group (key_file, EOG_PAGE_SETUP_GROUP)) {
+		page_setup = gtk_page_setup_new_from_key_file (key_file, EOG_PAGE_SETUP_GROUP, &error);
+	} else {
+		page_setup = gtk_page_setup_new ();
+	}
+
+	if (error) {
+		page_setup = gtk_page_setup_new ();
+
+		g_warning (_("Error loading print settings file: %s"), error->message);
+		g_error_free (error);
+	}
+
+	if (key_file)
+		g_key_file_free (key_file);
+	
+	return page_setup;
+}
+
+static void
+eog_print_save_key_file (GKeyFile *key_file)
+{
+	gchar *filename;
+	gchar *data;
+	GError *error = NULL;
+	const gchar *dot_dir = eog_util_dot_dir ();
+
+	filename = g_build_filename (dot_dir, EOG_PRINT_SETTINGS_FILE, NULL);
+
+	data = g_key_file_to_data (key_file, NULL, NULL);
+
+	g_file_set_contents (filename, data, -1, &error);
+
+	if (error) {
+		g_warning (_("Error saving print settings file: %s"), error->message);
+		g_error_free (error);
+	}
+
+	g_free (filename);
+	g_free (data);
+}
+
+void
+eog_print_set_page_setup (GtkPageSetup *page_setup)
+{
+	GKeyFile *key_file;
+
+	key_file = eog_print_get_key_file ();
+
+	if (key_file == NULL) {
+		key_file = g_key_file_new ();
+	}
+
+	gtk_page_setup_to_key_file (page_setup, key_file, EOG_PAGE_SETUP_GROUP);
+	eog_print_save_key_file (key_file);
+
+	g_key_file_free (key_file);
+}
+
+GtkPrintSettings *
+eog_print_get_print_settings (void)
+{
+	GtkPrintSettings *print_settings;
+	GError *error = NULL;
+	GKeyFile *key_file;
+
+	key_file = eog_print_get_key_file ();
+
+	if (key_file && g_key_file_has_group (key_file, EOG_PRINT_SETTINGS_GROUP)) {
+		print_settings = gtk_print_settings_new_from_key_file (key_file, EOG_PRINT_SETTINGS_GROUP, &error);
+	} else {
+		print_settings = gtk_print_settings_new ();
+	}
+
+	if (error) {
+		print_settings = gtk_print_settings_new ();
+
+		g_warning (_("Error loading print settings file: %s"), error->message);
+		g_error_free (error);
+	}
+
+	if (key_file)
+		g_key_file_free (key_file);
+	
+	return print_settings;
+}
+
+void
+eog_print_set_print_settings (GtkPrintSettings *print_settings)
+{
+	GKeyFile *key_file;
+
+	key_file = eog_print_get_key_file ();
+
+	if (key_file == NULL) {
+		key_file = g_key_file_new ();
+	}
+
+	gtk_print_settings_to_key_file (print_settings, key_file, EOG_PRINT_SETTINGS_GROUP);
+	eog_print_save_key_file (key_file);
+
+	g_key_file_free (key_file);
+}

Modified: trunk/src/eog-print.h
==============================================================================
--- trunk/src/eog-print.h	(original)
+++ trunk/src/eog-print.h	Sat Apr  5 16:19:14 2008
@@ -30,6 +30,12 @@
 GtkPrintOperation*    eog_print_operation_new (EogImage *image,
 					       GtkPrintSettings *print_settings,
 					       GtkPageSetup *page_setup);
+
+GtkPageSetup*         eog_print_get_page_setup (void);
+void                  eog_print_set_page_setup (GtkPageSetup *page_setup);
+GtkPrintSettings *    eog_print_get_print_settings (void);
+void                  eog_print_set_print_settings (GtkPrintSettings *print_settings);
+
 G_END_DECLS
 
 #endif /* __EOG_PRINT_H__ */

Modified: trunk/src/eog-window.c
==============================================================================
--- trunk/src/eog-window.c	(original)
+++ trunk/src/eog-window.c	Sat Apr  5 16:19:14 2008
@@ -164,9 +164,6 @@
 
         guint		     recent_menu_id;
 
-	GtkPrintSettings    *print_settings;
-	GtkPageSetup        *print_page_setup;
-
         EogJob              *load_job;
         EogJob              *transform_job;
 	EogJob              *save_job;
@@ -2198,21 +2195,22 @@
 eog_window_page_setup (EogWindow *window)
 {
 	GtkPageSetup *new_page_setup;
+	GtkPageSetup *page_setup;
+	GtkPrintSettings *print_settings;
 
 	eog_debug (DEBUG_PRINTING);
 	
-	if (window->priv->print_settings == NULL) {
-		window->priv->print_settings = gtk_print_settings_new ();
-	}
-	
+	print_settings = eog_print_get_print_settings ();
+	page_setup = eog_print_get_page_setup ();
+
 	new_page_setup = gtk_print_run_page_setup_dialog (GTK_WINDOW (window),
-							  window->priv->print_page_setup, 
-							  window->priv->print_settings);
-	if (window->priv->print_page_setup) {
-		g_object_unref (window->priv->print_page_setup);
-	}
-	
-	window->priv->print_page_setup = new_page_setup;
+							  page_setup,
+							  print_settings);
+	eog_print_set_page_setup (new_page_setup);
+
+	g_object_unref (page_setup);
+	g_object_unref (new_page_setup);
+	g_object_unref (print_settings);
 }
 
 static void
@@ -2222,20 +2220,20 @@
 	GError *error = NULL;
 	GtkPrintOperation *print;
 	GtkPrintOperationResult res;
-	
+	GtkPageSetup *page_setup;
+	GtkPrintSettings *print_settings;
+
 	eog_debug (DEBUG_PRINTING);
 	
-	if (!window->priv->print_settings)
-		window->priv->print_settings = gtk_print_settings_new ();
-	if (!window->priv->print_page_setup)
-		window->priv->print_page_setup = gtk_page_setup_new ();
-	
+	print_settings = eog_print_get_print_settings ();
+	page_setup = eog_print_get_page_setup ();
+
 	/* Make sure the window stays valid while printing */
 	g_object_ref (window);
 
 	print = eog_print_operation_new (window->priv->image,
-					 window->priv->print_settings,
-					 window->priv->print_page_setup);
+					 print_settings,
+					 page_setup);
 
 	res = gtk_print_operation_run (print,
 				       GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
@@ -2253,11 +2251,11 @@
 		gtk_widget_show (dialog);
 		g_error_free (error);
 	} else if (res == GTK_PRINT_OPERATION_RESULT_APPLY) {
-		if (window->priv->print_settings != NULL)
-			g_object_unref (window->priv->print_settings);
-		window->priv->print_settings = g_object_ref (gtk_print_operation_get_print_settings (print));
+		eog_print_set_print_settings (gtk_print_operation_get_print_settings (print));
 	}
 
+	g_object_unref (page_setup);
+	g_object_unref (print_settings);
 	g_object_unref (window);
 }
 
@@ -4065,9 +4063,6 @@
 
 	window->priv->recent_menu_id = 0;
 
-	window->priv->print_page_setup = NULL;
-	window->priv->print_settings = NULL;
-	
 	window->priv->collection_position = 0;
 	window->priv->collection_resizable = FALSE;
 
@@ -4165,16 +4160,6 @@
 		priv->client = NULL;
 	}
 		
-	if (priv->print_settings != NULL) {
-		g_object_unref (priv->print_settings);
-		priv->print_settings = NULL;
-	}
-	
-	if (priv->print_page_setup != NULL) {
-		g_object_unref (priv->print_page_setup);
-		priv->print_page_setup = NULL;
-	}
-
 	if (priv->file_list != NULL) {
 		g_slist_foreach (priv->file_list, (GFunc) g_object_unref, NULL);	
 		g_slist_free (priv->file_list);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]