Commit 13fcc89b authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

plug-ins/print/Makefile.am added new files with utility functions.

2008-02-25  Sven Neumann  <sven@gimp.org>

	* plug-ins/print/Makefile.am
	* plug-ins/print/print-utils.[ch]: added new files with utility
	functions.

	* plug-ins/print/print-settings.c: use the new utility
	functions for loading and saving GKeyFile.

	* plug-ins/print/print-page-setup.[ch]
	* plug-ins/print/print.c: also store the page setup in an image
	parasite. Fixes most of what remained to be done for bug 
#513291.


svn path=/trunk/; revision=24960
parent afc10516
2008-02-25 Sven Neumann <sven@gimp.org>
* plug-ins/print/Makefile.am
* plug-ins/print/print-utils.[ch]: added new files with utility
functions.
* plug-ins/print/print-settings.c: use the new utility
functions for loading and saving GKeyFile.
* plug-ins/print/print-page-setup.[ch]
* plug-ins/print/print.c: also store the page setup in an image
parasite. Fixes most of what remained to be done for bug #513291.
2008-02-25 Sven Neumann <sven@gimp.org> 2008-02-25 Sven Neumann <sven@gimp.org>
* plug-ins/print/print-settings.[ch] * plug-ins/print/print-settings.[ch]
......
...@@ -49,4 +49,6 @@ print_SOURCES = \ ...@@ -49,4 +49,6 @@ print_SOURCES = \
print-preview.c \ print-preview.c \
print-preview.h \ print-preview.h \
print-settings.c \ print-settings.c \
print-settings.h print-settings.h \
print-utils.c \
print-utils.h
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <libgimp/gimpui.h> #include <libgimp/gimpui.h>
#include "print-page-setup.h" #include "print-page-setup.h"
#include "print-utils.h"
void void
...@@ -41,49 +42,62 @@ print_page_setup_dialog (GtkPrintOperation *operation) ...@@ -41,49 +42,62 @@ print_page_setup_dialog (GtkPrintOperation *operation)
gtk_print_operation_set_default_page_setup (operation, setup); gtk_print_operation_set_default_page_setup (operation, setup);
} }
gboolean void
print_page_setup_load (GtkPrintOperation *operation, print_page_setup_load (GtkPrintOperation *operation,
gint32 image_ID) gint32 image_ID)
{ {
GtkPageSetup *setup; GKeyFile *key_file;
gchar *filename;
filename = g_build_filename (gimp_directory (), "print-page-setup", NULL); g_return_if_fail (GTK_IS_PRINT_OPERATION (operation));
setup = gtk_page_setup_new_from_file (filename, NULL); key_file = print_utils_key_file_load_from_parasite (image_ID,
"print-page-setup");
g_free (filename); if (! key_file)
key_file = print_utils_key_file_load_from_rcfile ("print-page-setup");
if (setup) if (key_file)
{ {
gtk_print_operation_set_default_page_setup (operation, setup); GtkPageSetup *setup;
g_object_unref (setup); GError *error = NULL;
return TRUE; setup = gtk_page_setup_new_from_key_file (key_file, NULL, &error);
if (setup)
{
gtk_print_operation_set_default_page_setup (operation, setup);
g_object_unref (setup);
}
else
{
g_warning ("unable to read page setup from key file: %s",
error->message);
g_error_free (error);
}
g_key_file_free (key_file);
} }
return FALSE;
} }
void void
print_page_setup_save (GtkPrintOperation *operation) print_page_setup_save (GtkPrintOperation *operation,
gint32 image_ID)
{ {
GtkPageSetup *setup; GtkPageSetup *setup;
gchar *filename; GKeyFile *key_file;
GError *error = NULL;
setup = gtk_print_operation_get_default_page_setup (operation); g_return_if_fail (GTK_IS_PRINT_OPERATION (operation));
key_file = g_key_file_new ();
filename = g_build_filename (gimp_directory (), "print-page-setup", NULL); setup = gtk_print_operation_get_default_page_setup (operation);
gtk_page_setup_to_file (setup, filename, &error); gtk_page_setup_to_key_file (setup, key_file, NULL);
if (error) print_utils_key_file_save_as_parasite (key_file,
{ image_ID, "print-page-setup");
g_message ("Error saving page setup as resource file: %s", print_utils_key_file_save_as_rcfile (key_file,
error->message); "print-page-setup");
g_error_free (error);
}
g_free (filename); g_key_file_free (key_file);
} }
...@@ -17,9 +17,10 @@ ...@@ -17,9 +17,10 @@
*/ */
void print_page_setup_dialog (GtkPrintOperation *operation); void print_page_setup_dialog (GtkPrintOperation *operation);
gboolean print_page_setup_load (GtkPrintOperation *operation, void print_page_setup_load (GtkPrintOperation *operation,
gint32 image_ID); gint32 image_ID);
void print_page_setup_save (GtkPrintOperation *operation); void print_page_setup_save (GtkPrintOperation *operation,
gint32 image_ID);
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "print.h" #include "print.h"
#include "print-settings.h" #include "print-settings.h"
#include "print-utils.h"
#define PRINT_SETTINGS_MAJOR_VERSION 0 #define PRINT_SETTINGS_MAJOR_VERSION 0
...@@ -31,11 +32,6 @@ ...@@ -31,11 +32,6 @@
static GKeyFile * print_settings_key_file_from_settings (PrintData *data); static GKeyFile * print_settings_key_file_from_settings (PrintData *data);
static void print_settings_save_resource_file (GKeyFile *settings_key_file);
static void print_settings_save_as_parasite (GKeyFile *settings_key_file,
gint32 image_ID);
static void print_settings_add_to_key_file (const gchar *key, static void print_settings_add_to_key_file (const gchar *key,
const gchar *value, const gchar *value,
gpointer data); gpointer data);
...@@ -81,7 +77,7 @@ print_settings_save (PrintData *data) ...@@ -81,7 +77,7 @@ print_settings_save (PrintData *data)
{ {
GKeyFile *key_file = print_settings_key_file_from_settings (data); GKeyFile *key_file = print_settings_key_file_from_settings (data);
print_settings_save_resource_file (key_file); print_utils_key_file_save_as_rcfile (key_file, "print-settings");
/* image setup */ /* image setup */
if (gimp_image_is_valid (data->image_id)) if (gimp_image_is_valid (data->image_id))
...@@ -101,7 +97,8 @@ print_settings_save (PrintData *data) ...@@ -101,7 +97,8 @@ print_settings_save (PrintData *data)
g_key_file_set_boolean (key_file, "image-setup", g_key_file_set_boolean (key_file, "image-setup",
"use-full-page", data->use_full_page); "use-full-page", data->use_full_page);
print_settings_save_as_parasite (key_file, data->image_id); print_utils_key_file_save_as_parasite (key_file,
data->image_id, "print-settings");
} }
g_key_file_free (key_file); g_key_file_free (key_file);
...@@ -117,8 +114,6 @@ print_settings_key_file_from_settings (PrintData *data) ...@@ -117,8 +114,6 @@ print_settings_key_file_from_settings (PrintData *data)
GtkPrintSettings *settings; GtkPrintSettings *settings;
GKeyFile *key_file = g_key_file_new (); GKeyFile *key_file = g_key_file_new ();
g_key_file_set_list_separator (key_file, '=');
/* put version information into the file */ /* put version information into the file */
g_key_file_set_integer (key_file, "meta", "major-version", g_key_file_set_integer (key_file, "meta", "major-version",
PRINT_SETTINGS_MAJOR_VERSION); PRINT_SETTINGS_MAJOR_VERSION);
...@@ -135,67 +130,6 @@ print_settings_key_file_from_settings (PrintData *data) ...@@ -135,67 +130,6 @@ print_settings_key_file_from_settings (PrintData *data)
return key_file; return key_file;
} }
/*
* create a resource file from a GKeyFile holding the settings
*/
static void
print_settings_save_resource_file (GKeyFile *settings_key_file)
{
gchar *filename;
gchar *contents;
gsize length;
GError *error = NULL;
contents = g_key_file_to_data (settings_key_file, &length, &error);
if (! contents)
{
g_warning ("Unable to get contents of settings key file: %s",
error->message);
g_error_free (error);
return;
}
filename = g_build_filename (gimp_directory (), "print-settings", NULL);
if (! g_file_set_contents (filename, contents, length, &error))
{
g_warning ("Unable to write print settings to '%s': %s",
gimp_filename_to_utf8 (filename), error->message);
g_error_free (error);
}
g_free (filename);
g_free (contents);
}
/*
* create an image parasite called "print-settings" from a GKeyFile
* holding the print settings
*/
static void
print_settings_save_as_parasite (GKeyFile *settings_key_file,
gint32 image_ID)
{
gchar *contents;
gsize length;
GError *error = NULL;
contents = g_key_file_to_data (settings_key_file, &length, &error);
if (! contents)
{
g_warning ("Unable to get contents of settings key file: %s",
error->message);
g_error_free (error);
return;
}
gimp_image_attach_new_parasite (image_ID, "print-settings",
0, length, contents);
g_free (contents);
}
/* /*
* callback used in gtk_print_settings_foreach loop * callback used in gtk_print_settings_foreach loop
*/ */
...@@ -215,22 +149,9 @@ print_settings_add_to_key_file (const gchar *key, ...@@ -215,22 +149,9 @@ print_settings_add_to_key_file (const gchar *key,
static GKeyFile * static GKeyFile *
print_settings_key_file_from_resource_file (void) print_settings_key_file_from_resource_file (void)
{ {
GKeyFile *key_file = g_key_file_new (); GKeyFile *key_file = print_utils_key_file_load_from_rcfile ("print-settings");
gchar *filename;
g_key_file_set_list_separator (key_file, '=');
filename = g_build_filename (gimp_directory (), "print-settings", NULL);
if (! g_key_file_load_from_file (key_file, filename, G_KEY_FILE_NONE, NULL))
{
g_key_file_free (key_file);
key_file = NULL;
}
g_free (filename);
if (! print_settings_check_version (key_file)) if (key_file && ! print_settings_check_version (key_file))
{ {
g_key_file_free (key_file); g_key_file_free (key_file);
return NULL; return NULL;
...@@ -246,30 +167,12 @@ print_settings_key_file_from_resource_file (void) ...@@ -246,30 +167,12 @@ print_settings_key_file_from_resource_file (void)
static GKeyFile * static GKeyFile *
print_settings_key_file_from_parasite (gint32 image_ID) print_settings_key_file_from_parasite (gint32 image_ID)
{ {
GimpParasite *parasite; GKeyFile *key_file;
GKeyFile *key_file;
parasite = gimp_image_parasite_find (image_ID, "print-settings");
if (! parasite)
return NULL;
key_file = g_key_file_new ();
g_key_file_set_list_separator (key_file, '=');
if (! g_key_file_load_from_data (key_file,
gimp_parasite_data (parasite),
gimp_parasite_data_size (parasite),
G_KEY_FILE_NONE, NULL))
{
g_key_file_free (key_file);
key_file = NULL;;
}
gimp_parasite_free (parasite); key_file = print_utils_key_file_load_from_parasite (image_ID,
"print-settings");
if (! print_settings_check_version (key_file)) if (key_file && ! print_settings_check_version (key_file))
{ {
g_key_file_free (key_file); g_key_file_free (key_file);
return FALSE; return FALSE;
......
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <libgimp/gimp.h>
#include "print-utils.h"
GKeyFile *
print_utils_key_file_load_from_rcfile (const gchar *basename)
{
GKeyFile *key_file;
gchar *filename;
g_return_val_if_fail (basename != NULL, NULL);
filename = g_build_filename (gimp_directory (), "print-settings", NULL);
key_file = g_key_file_new ();
if (! g_key_file_load_from_file (key_file, filename, G_KEY_FILE_NONE, NULL))
{
g_key_file_free (key_file);
key_file = NULL;
}
g_free (filename);
return key_file;
}
GKeyFile *
print_utils_key_file_load_from_parasite (gint32 image_ID,
const gchar *parasite_name)
{
GimpParasite *parasite;
GKeyFile *key_file;
GError *error = NULL;
g_return_val_if_fail (parasite_name != NULL, NULL);
parasite = gimp_image_parasite_find (image_ID, parasite_name);
if (! parasite)
return NULL;
key_file = g_key_file_new ();
if (! g_key_file_load_from_data (key_file,
gimp_parasite_data (parasite),
gimp_parasite_data_size (parasite),
G_KEY_FILE_NONE, &error))
{
g_key_file_free (key_file);
gimp_parasite_free (parasite);
g_warning ("Unable to create key file from image parasite '%s': %s",
parasite_name, error->message);
g_error_free (error);
return NULL;
}
gimp_parasite_free (parasite);
return key_file;
}
void
print_utils_key_file_save_as_rcfile (GKeyFile *key_file,
const gchar *basename)
{
gchar *filename;
gchar *contents;
gsize length;
GError *error = NULL;
g_return_if_fail (basename != NULL);
contents = g_key_file_to_data (key_file, &length, &error);
if (! contents)
{
g_warning ("Unable to get contents of key file for '%s': %s",
basename, error->message);
g_error_free (error);
return;
}
filename = g_build_filename (gimp_directory (), basename, NULL);
if (! g_file_set_contents (filename, contents, length, &error))
{
g_warning ("Unable to write settings to '%s': %s",
gimp_filename_to_utf8 (filename), error->message);
g_error_free (error);
}
g_free (filename);
g_free (contents);
}
void
print_utils_key_file_save_as_parasite (GKeyFile *key_file,
gint32 image_ID,
const gchar *parasite_name)
{
gchar *contents;
gsize length;
GError *error = NULL;
g_return_if_fail (parasite_name != NULL);
contents = g_key_file_to_data (key_file, &length, &error);
if (! contents)
{
g_warning ("Unable to get contents of key file for parasite '%s': %s",
parasite_name, error->message);
g_error_free (error);
return;
}
gimp_image_attach_new_parasite (image_ID, parasite_name, 0, length, contents);
g_free (contents);
}
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
GKeyFile * print_utils_key_file_load_from_rcfile (const gchar *basename);
GKeyFile * print_utils_key_file_load_from_parasite (gint32 image_ID,
const gchar *parasite_name);
void print_utils_key_file_save_as_rcfile (GKeyFile *key_file,
const gchar *basename);
void print_utils_key_file_save_as_parasite (GKeyFile *key_file,
gint32 image_ID,
const gchar *parasite_name);
...@@ -301,7 +301,7 @@ page_setup (gint32 image_ID) ...@@ -301,7 +301,7 @@ page_setup (gint32 image_ID)
print_page_setup_load (operation, image_ID); print_page_setup_load (operation, image_ID);
print_page_setup_dialog (operation); print_page_setup_dialog (operation);
print_page_setup_save (operation); print_page_setup_save (operation, image_ID);
g_object_unref (operation); g_object_unref (operation);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment