After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 344515 - serialising/deserialising page setup & print settings
serialising/deserialising page setup & print settings
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Printing
unspecified
Other Linux
: Normal enhancement
: Small API
Assigned To: gtk-bugs
: 345128 (view as bug list)
Depends on:
Blocks: 349102 396475 403717
 
 
Reported: 2006-06-10 21:07 UTC by Christian Persch
Modified: 2007-04-29 06:22 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
document key/value requirements (874 bytes, patch)
2006-06-20 17:00 UTC, Christian Persch
none Details | Review
proposed patch (26.74 KB, patch)
2006-12-04 15:07 UTC, Christian Persch
none Details | Review

Description Christian Persch 2006-06-10 21:07:50 UTC
To store page setup and print settings between program invocations, there should be a way to serialise/deserialise GtkPageSetup and GtkPrintSettings.
Comment 1 Matthias Clasen 2006-06-11 13:28:18 UTC
I believe gtk_print_settings_foreach is meant to be that way.
It will be hard to come up with a less generic one-size-fits-all
serialization solution. Keyfile ? XML ? Binary ? separate file ?
Comment 2 Christian Persch 2006-06-11 13:52:23 UTC
Yes, I was thinking about a keyfile, maybe gtk_{print_settings,page_setup}_{from,to}_key_file.
If we leave this to the programmer to do himself, this will lead to code duplication and everyone will do it subtly differently wrt. corner cases...
Comment 3 Matthias Clasen 2006-06-16 23:05:50 UTC
*** Bug 345128 has been marked as a duplicate of this bug. ***
Comment 4 Christian Persch 2006-06-18 12:51:39 UTC
So I'm working on a patch for this. The question is which API we want: like this:

+GtkPrintSettings *gtk_print_settings_new_from_data           (const gchar          *data,
+                                                             gsize                 length,
+                                                             GError              **error);
+
+GtkPrintSettings *gtk_print_settings_new_from_file           (const gchar          *filename,
+                                                             GError              **error);
+
+GtkPrintSettings *gtk_print_settings_new_from_key_file       (GKeyFile             *key_file,
+                                                             GError              **error);
+
+gchar            *gtk_print_settings_to_data                 (GtkPrintSettings     *settings,
+                                                             gsize                *length);
+
+gboolean          gtk_print_settings_to_key_file             (GtkPrintSettings     *settings,
+                                                             GKeyFile             *key_file,
+                                                             GError              **error);
+

and the same for GtkPageSetup, or something combined that would save a GtkPrintSettings and GtkPageSetup to the same keyfile?

gchar *gtk_print_utils_settings_and_setup_to_data (GtkPrintSettings *,
                                                   GtkPageSetup *,
                                                   GError **);

gboolean gtk_print_utils_settings_and_setup_from_data (const gchar *data,
                                                       gsize length,
                                                       GtkPrintSetting **,
                                                       GtkPageSetup **,
                                                       GError **);

(and maybe from_file and {from,to}_key_file)

?
Comment 5 Christian Persch 2006-06-20 16:40:58 UTC
Btw, IMHO we should also document the encoding to use for a GtkPrintSettings setting, so you can reliably serialise/deserialise them. For use with keyfiles, it would be simplest to simply declare keys to have to be gkeyfile keys, and the data to be utf-8 ?
Comment 6 Matthias Clasen 2006-06-20 16:47:57 UTC
keys should be ascii without whitespace really
values should be utf-8
Comment 7 Christian Persch 2006-06-20 16:50:40 UTC
So that rules out storing the output filename as a filename, since that'll be in filename encoding :)
Comment 8 Christian Persch 2006-06-20 17:00:33 UTC
Created attachment 67726 [details] [review]
document key/value requirements

I think we should exclude = and ; in key names to we can actually use gkeyfile to store them as-is.

Should the functions actually g_return_if_fail-check those requirements (I can make a patch for that too) ?
Comment 9 Matthias Clasen 2006-06-20 17:10:38 UTC
re comment #7: I already admitted that in the other bug...
Comment 10 Carolyn_MacLeod 2006-06-20 17:47:09 UTC
Re comment #4, whether to store GtkPrintSettings and GtkPageSetup separately or together... I have a slight preference for storing them separately. (but only because it feels "logically prettier" to have a one-to-one mapping <g>).

As for whether to store as GKeyFile or gchar *data (or both), I don't think it matters either way, as long as a GKeyFile isn't some huge thing - I am just going to be storing GtkPrintSettings and GtkPageSetup temporarily so that I can recreate the user's dialog choices after the dialog is destroyed. Smaller is better in this case - I don't need to do any lookups on it or anything.

I see that you are talking about wanting to freeze printing api for the endgame. I hope this api will still be considered?
Comment 11 Matthias Clasen 2006-06-20 18:14:15 UTC
Carolyn, even if we decide to not include this in 2.10, it is not very
hard to write those serialization functions yourself. 
Comment 12 Carolyn_MacLeod 2006-06-20 20:37:20 UTC
True, but I'd want to pull the code out as soon as the 'real' api went in.
Comment 13 Carolyn_MacLeod 2006-06-28 22:05:26 UTC
Matthias, I am still hoping that this api will be in 2.10.

The serialize/deserailize code I wrote works, but it feels like a hack - I'd love to pull it out before I ship (and replace it with 4 lines of api code <g>).

It's not too bad for print_settings because of the foreach, and because the set/get methods work with strings. But the page_setup object is a little bit uglier - that and its paper_size object are best serialized/deserialized by you.
I am currently guessing a little bit for paper_size recreation. Here's what I do:
- serialize name, display_name, ppd_name, width, height, is_custom
- deserialize all of that, and then:
    - if is_custom and it has a ppd_name, use gtk_paper_size_new_from_ppd
    - if is_custom and ppd_name is null, use gtk_paper_size_new_custom
    - otherwise (not is_custom), use gtk_paper_size_new

Also note that my code won't see any future changes to page_setup or paper_size, so I would always have to watch out for those.
Comment 14 Carlos Garcia Campos 2006-07-23 09:39:26 UTC
This will be useful for the external previewer too. The preview could serialize the settings and pass them to evince through the command line. I will implement such a command line option in evince, so that it could be called in this way:

evince --preview --print-settings=/tmp/<file>

It would be nice to have it for G2.16 :-P
Comment 15 Wouter Bolsterlee (uws) 2006-11-04 21:35:12 UTC
chpe, any progress on this one? It blocks #349102 and probably others.
Comment 16 Christian Persch 2006-11-04 22:39:12 UTC
uws: I wrote code in epiphany to do that, lib/ephy-print-utils.[ch]. Feel free to copy them into evince.
Comment 17 Carolyn_MacLeod 2006-11-05 21:59:09 UTC
Yes, and I wrote it for eclipse, too, and it's a hack - see comment 13 for details. It feels like code that should be in the base. We're going to have copies of it all over the place, and then someone will add a field to one of the classes and a bunch of people will be broken. It would be better to make it api.
Comment 18 Christian Persch 2006-12-04 15:07:00 UTC
Created attachment 77646 [details] [review]
proposed patch
Comment 19 Wouter Bolsterlee (uws) 2007-03-21 13:58:48 UTC
Any chance of getting this into GTK+?
Comment 20 Matthias Clasen 2007-04-29 06:22:31 UTC
2007-04-29  Matthias Clasen  <mclasen@redhat.com>

        * gtk/gtkprintoperation.h: Add a new error code

        * gtk/gtk.symbols:
        * gtk/gtkpagesetup.[hc]:
        * gtk/gtkpapersize.[hc]:
        * gtk/gtkprintsettings.[hc]: Add functions to serialize
        and deserialize page setups and print settings to files
        and key files.  (#344515, Christian Persch)

        * gtk/gtkpagesetupunixdialog.c: Adapt to the new functions.

        * tests/print-editor.c: Use the new functions to persist
        page setup and print settings.