Re: Glib::IO
- From: "max augsburg gmx de" <max augsburg gmx de>
- To: Jeremy Volkening <jdv base2bio com>
- Cc: Torsten Schoenfeld <kaffeetisch gmx de>, gtk-perl-list gnome org
- Subject: Re: Glib::IO
- Date: Wed, 01 Jun 2016 00:03:38 +0200
Dear Torsten, dear Jeremy, dear Gtk2 list,
I would love to help to work on improving the implementation of the Gio
API in Perl as far as I can with my little skills.
From my point of view, it would need unit tests and, if applicable,
overrides that cover the most relevant areas of the gio API.
Can you foresee which for you are the most relevant areas? Probably this
is very difficult to answer and considering the large numbers of classes
it is hard to say where to begin... For me alone in the foreground are
the classes that are important for creating Gtk3 UIs...
One important "problem" with such a connection to Gtk3 that I noticed
(and perhaps a good starting point) is, that that GIO reads and writes
files in raw bytes format. We have to convert these data so that Perl
can understand them better and more user-friendly. I think this "issue"
concerns more methods and functions (mainly such of GFile etc.pp.) that
we have to identify.
But let me show this on the example of Glib::File::load_contents and
Glib::File::replace_readwrite: I have tried to solve this with a little
override which I wanted to discuss with you. You can find the patches at
the end of the mail.
Without these overrides you get for example from the function
load_contents the pure bytes in an array reference which is from my
point of view not very helpful and user-friendly. I think also that the
Python bindings use a similar override but I don't know...
Disadvantages which I see with the overrides are:
Mainly that you can save and read only documents with the encoding of
utf-8.
We can prevent this on two ways:
1) We let out the command "my $content_utf8 = decode('utf-8',
$content);" resp. "my $content_utf8 = encode('utf-8', $content);"
But: then the user must each time run these commands by himself! A
really good pod Documentation would be important.
2) We can implement an additional argument, with that the user can
specify the desired encoding
But: For example to the method replace_readwrite you already have to
give six arguments at the moment!
3) We can renounce the whole overrides.
This is for me an option and gives the Perl programmer the most freedom,
but then we really need to explain reading and writing files with the
Gio liby in detail in a good POD documentation
What do you think about this proposed override?
Best wishes,
Max
PS.:
I am writing a Gtk3 Tutorial (or better translating the Python tutorial)
and this was the sole problem I noticed so far ;-)
Especcially GMenu and SimpleAction worked like a charme...
ANNEX: Output of the command diff -u
--- ./IO.pm 2016-05-31 23:44:34.102820349 +0200
+++ ./IO-patched.pm 2016-05-31 23:44:51.302821314 +0200
@@ -23,6 +23,7 @@
use strict;
use warnings;
use Glib::Object::Introspection;
+use Encode;
=head2 Wrapped libraries
@@ -47,7 +48,39 @@
=cut
+sub Glib::IO::File::load_contents {
+ my ($gfile, $gcancellable) = @_;
+ my ($success, $raw_content, $etags) =
Glib::Object::Introspection->invoke (
+ 'Gio','File','load_contents',$gfile,$gcancellable
+ );
+ # the problem is, that GIO reads and writes files in raw bytes
format,
+ # which means everything is passed on without any encoding/decoding.
+ # We have to convert these data so that Perl can understand them.
+ # First we convert the bytes (= pure digits) to a bytestring without
encoding
+ my $content = pack "C*", @{$raw_content};
+ # Then we decode this bytestrng in the utf8 encoding format
+ my $content_utf8 = decode('utf-8', $content);
+ return ($success,$content_utf8,$etags);
+}
+
+sub Glib::IO::File::replace_contents {
+ my ($gfile, $content, $etag, $make_backup, $flags, $gerror) = @_;
+ # the problem is, that GIO reads and writes files in raw bytes format,
+ # which means everything is passed on without any encoding/decoding.
+ # Therefore we have to convert the perlish content into an array ref
containing
+ # the raw bytes
+ # First we have to reconvert the textstring with the utf8 encoding
format to
+ # to a bytestring
+ my $content_utf8 = encode('utf-8', $content);
+ # Then we convert the bytestring in bytes and give a array reference
to the function
+ my @contents = unpack "C*", $content_utf8;
+ return Glib::Object::Introspection->invoke (
+ 'Gio','File','replace_contents', $gfile, \ contents, $etag,
$make_backup, $flags, $gerror
+ );
+}
+
1;
+
__END__
=head1 SEE ALSO
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]