annotate bins-edit2-gui @ 11:8b62360dc2a5 default tip

Adding notes, cloning edit-gui
author Peter Gervai <grin@grin.hu>
date Sun, 02 Nov 2008 16:29:52 +0100
parents bins-edit-gui@a84c32f131df
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
1 #!/usr/bin/perl
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
2 # bins-edit-gui -- graphical editor for BINS-format XML tag files
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
3 #
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
4 # Copyright 2002 Mark W. Eichin <eichin@thok.org>
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
5 # The Herd of Kittens
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
6 #
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
7 # -- GPL notice --
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
8 $gpl_text = <<EOF ;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
9 # This program is free software; you can redistribute it and/or modify
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
10 # it under the terms of the GNU General Public License as published by
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
11 # the Free Software Foundation; either version 2 of the License, or
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
12 # (at your option) any later version.
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
13 #
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
14 # This program is distributed in the hope that it will be useful,
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
17 # GNU General Public License for more details.
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
18 #
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
19 # You should have received a copy of the GNU General Public License
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
20 # along with this program; if not, write to the Free Software
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
21 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
22 EOF
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
23 # -- end GPL notice --
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
24
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
25 $version = "0.9";
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
26
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
27 @album_tags = qw(title longdesc shortdesc sampleimage);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
28 @image_tags = qw(title event location people date description);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
29 @known_tags = sort (@album_tags, @image_tags);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
30 {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
31 # perlfaq4 uniquify
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
32 my $prev = undef;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
33 @known_tags = grep($_ ne $prev && ($prev = $_, 1), @known_tags);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
34 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
35 # allbery suggests
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
36 # keys %{{map(($_,1),@array)}}
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
37 # would be like the perlfaq unique-keys example...
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
38
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
39 use Getopt::Long;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
40
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
41 use Gtk;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
42 use Gtk::GladeXML;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
43
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
44 use XML::DOM;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
45 use XML::XQL;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
46 use XML::XQL::DOM;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
47 use XML::Writer;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
48
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
49 use Gtk::Gdk::ImlibImage;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
50 use Gnome;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
51
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
52 use Text::Iconv;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
53
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
54 # for localized text
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
55 # use POSIX qw(setlocale LC_MESSAGES); # apparently only works on Debian,
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
56 # mandrake, redhat, and suse are reported to need the following instead:
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
57 use POSIX 'locale_h';
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
58 use Locale::gettext;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
59
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
60 sub _ {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
61 Locale::gettext::gettext(shift);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
62 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
63
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
64 $debug=0;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
65
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
66 $localePath = "/usr/local/share/locale"; # Base locale path (for I18N)
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
67
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
68 setlocale(LC_MESSAGES, "");
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
69 bindtextdomain("bins-edit-gui", $localePath);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
70 textdomain("bins-edit-gui");
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
71
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
72 sub usage {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
73 my $why = shift;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
74 my $usage =
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
75 "bins-edit-gui: [--debug] [--version] " . _("file [files...]") ."\n".
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
76 " "._("Edit BINS-format tags (captions, titles, etc) for image files.") ."\n".
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
77 "\n".
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
78 " --debug " . _("enable developer-only debugging.") ."\n".
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
79 " --version " . _("display version information.") ."\n";
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
80
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
81 if ($why eq 'error') {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
82 print STDERR $usage;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
83 exit 1;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
84 } elsif ($why eq 'user') {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
85 print STDOUT $usage;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
86 exit 0;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
87 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
88 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
89
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
90 $o_help=0;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
91 $o_version=0;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
92
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
93 $fullversion =
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
94 "bins-edit-gui $version " . _("for BINS") ."\n".
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
95 "Copyright 2002 Mark W. Eichin <eichin\@thok.org>" ."\n".
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
96 _("This is free software distributed under the GPL. There is NO WARRANTY.") ."\n".
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
97
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
98
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
99 GetOptions('debug+' => \$debug,
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
100 'h|help' => \$o_help,
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
101 'v|version' => \$o_version,
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
102 ) or usage('error');
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
103 usage('user') if $o_help;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
104 if ($o_version) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
105 print $fullversion;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
106 exit 0;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
107 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
108
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
109 # take this out when we have a file browser
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
110 usage('error') if scalar(@ARGV) < 1;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
111
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
112 # find a way to do this in Perl; nl_langinfo seems to be coming in 5.8
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
113 my $localEncoding = "";
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
114 my $codeset;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
115 eval {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
116 require I18N::Langinfo;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
117 I18N::Langinfo->import(qw(langinfo CODESET));
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
118 $codeset = langinfo(CODESET());
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
119 };
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
120 # ANSI is unspeakably primitive, keep LATIN1 instead
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
121 # Solaris refers to ISO 646 as "646" but that is not a valid codeset
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
122 if (!$@ && $codeset && $codeset ne "ANSI_X3.4-1968" && $codeset ne "646") {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
123 $localEncoding = $codeset;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
124 print "Forcing encoding to $codeset";
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
125 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
126
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
127 chop($localEncoding);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
128 if (! $localEncoding) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
129 $localEncoding = "LATIN1";
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
130 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
131 $Latin2UTF = Text::Iconv->new($localEncoding, "UTF-8");
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
132 $UTF2Latin = Text::Iconv->new("UTF-8", $localEncoding);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
133
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
134 my_init_rotations();
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
135
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
136 Gtk->set_locale;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
137
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
138 Gnome->init("bins-edit-gui", $version);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
139 Gtk->init;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
140
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
141 $glade = "/usr/local/share/bins/bins-edit-gui.glade";
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
142 if (! -r $glade) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
143 $glade = "bins-edit-gui.glade" ; # developer hack
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
144 print "DEVELOPER HACK\n";
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
145 if (! -r $glade) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
146 die "No bins-edit-gui.glade available";
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
147 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
148 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
149 #$g = new Gtk::GladeXML($glade, 'image_edit_top');
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
150 $g = new Gtk::GladeXML($glade);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
151 die "Gtk::GladeXML($glade) initialization failed; check required packages" unless $g;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
152
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
153 $g->signal_autoconnect_from_package('main'); # main:: so we can grab stuff directly
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
154
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
155 # get the "global" widgets
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
156
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
157 $w = $g->get_widget('image_edit_pixmap'); # GTK-Interface/widget/name
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
158 $w->signal_connect(expose_event => \&on_test_expose_event);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
159 $name_entry = $g->get_widget("field_name_entry");
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
160 $value_entry = $g->get_widget("field_value_entry");
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
161 $ilist = $g->get_widget("image_prop_list");
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
162 $ilist->column_titles_passive; # shouldn't this be in the .glade?
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
163 # work around libglade 0.17 bug (debbugs #147051)
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
164 $ilist->set_column_title(0, _("Property"));
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
165 $ilist->set_column_title(1, _("Value"));
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
166 # end workaround.
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
167 $statusbar = $g->get_widget('statusbar1');
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
168 $aboutbox = $g->get_widget('about_box');
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
169 $aboutbox->close_hides;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
170 $licensebox = $g->get_widget('license_box');
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
171 $licensetext = $g->get_widget('license_text'); # GtkText
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
172 #print ref($licensetext),": ",join("\n\t|",%Gtk::Text::),"\n";
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
173 $gpl_text =~ s/^\# ?//gm;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
174 $licensetext->insert(undef, undef, undef, $gpl_text);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
175
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
176 ## album-panel globals
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
177 $albumedit = $g->get_widget('album_edit_top');
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
178 $albumfile = $g->get_widget('album_edit_filename');
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
179 $albumprop = $g->get_widget('album_prop_list');
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
180 # work around libglade 0.17 bug (debbugs #147051)
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
181 $albumprop->set_column_title(0, _("Property"));
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
182 $albumprop->set_column_title(1, _("Value"));
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
183 # end workaround.
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
184 $albumname = $g->get_widget('album_name_entry');
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
185 $albumname->set_popdown_strings(@album_tags);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
186 $albumvalue = $g->get_widget('album_edit_text');
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
187
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
188 sub on_dismiss_about_clicked {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
189 $licensebox->hide;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
190 status(_("Thank you for sharing."));
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
191 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
192
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
193 sub status {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
194 my $msg = shift;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
195 $statusbar->pop(1);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
196 $statusbar->push(1, $msg);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
197 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
198
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
199 use Image::Info;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
200
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
201 # original orientation for viewing
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
202 sub get_image_orientation($) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
203 my $filename = shift;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
204 # bail directly if we have a tag-loaded value
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
205 return $newimage_tagged_or if (defined $newimage_tagged_or);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
206 # try and find a way to get this from imlib?
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
207 my $info = Image::Info::image_info($filename);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
208 if (exists $info->{'error'}) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
209 my $msg = sprintf(_("Couldn't read EXIF info from %s: %s, ignoring."),
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
210 $filename, $info->{'error'});
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
211
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
212 status($msg);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
213 print $msg if $debug;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
214 return "top_left";
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
215 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
216 $info->{'Orientation'};
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
217 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
218
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
219 # see http://www.ba.wakwak.com/~tsuruzoh/Computer/Digicams/exif-e.html
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
220 # for the meaning of the orientations.
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
221 # see /usr/share/doc/imlib-base/html/index.html
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
222 # for the not-quite-apology for the function supplied.
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
223 # see the qiv sources for an example of how to use it anyway...
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
224
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
225 sub my_real_gdk_rotate($$) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
226 my ($newimage,$orientation) = @_;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
227 my $degrees;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
228
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
229 if ($orientation eq "right_top"){
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
230 $degrees = 90;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
231 $newimage->rotate_image('a 45 degree mirror is *not* a rotate');
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
232 $newimage->flip_image_horizontal ();
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
233 } elsif ($orientation eq "left_bot"){
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
234 $degrees = 270;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
235 $newimage->rotate_image('a 45 degree mirror is *not* a rotate');
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
236 $newimage->flip_image_vertical ();
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
237 } elsif ($orientation eq "right_bot"){
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
238 $degrees = 180;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
239 # test this, maybe simplify...
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
240 $newimage->rotate_image('a 45 degree mirror is *not* a rotate');
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
241 $newimage->flip_image_horizontal ();
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
242 $newimage->rotate_image('a 45 degree mirror is *not* a rotate');
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
243 $newimage->flip_image_horizontal ();
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
244 } elsif ($orientation eq "top_left"){
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
245 # do nothing
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
246 return;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
247 } else {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
248 print STDERR "Warning, Orientation field has an unknown value '$orientation'.\n" if $debug;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
249 # still do nothing
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
250 return 0;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
251 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
252
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
253 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
254
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
255
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
256 sub load_image_tags($);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
257
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
258 sub load_image { # no proto, we're cheating and doing 1arg/2arg (or should that be @?)
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
259 my $test_filename = shift;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
260 my $extra = shift;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
261 my $ilabel = $g->get_widget('image_filename_label');
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
262 $newimage->destroy_image() if defined $newimage;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
263 $newimage = load_image Gtk::Gdk::ImlibImage($test_filename);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
264 if (defined $newimage) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
265 if ($extra ne "keeptags") {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
266 load_image_tags $test_filename;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
267 $newimage_loaded_or = $newimage_or = get_image_orientation($test_filename);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
268 print "$test_filename: got orientation <$newimage_or>\n" if $debug;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
269 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
270 my_real_gdk_rotate($newimage,$newimage_or);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
271 $ilabel->set($test_filename);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
272 status(sprintf(_("Loaded %s."), $test_filename));
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
273 } else {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
274 # no image - just skip. we've already filtered xml files, though.
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
275 $ilabel->set(_("Load failed: ") . $test_filename);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
276 status(sprintf(_("IMLib failed loading %s."), $test_filename));
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
277 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
278 # regardless, rerender
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
279 if (defined $imagesized) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
280 undef $imagesized;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
281 on_test_expose_event(); # cheat, it doesn't use it
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
282 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
283
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
284 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
285 # from bins_edit
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
286
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
287 # my $grove_builder = XML::Grove::Builder->new;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
288 # my $parser = XML::Parser::PerlSAX->new ( Handler => $grove_builder );
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
289 # $document = $parser->parse ( Source => { SystemId => "${test_filename}.xml" } );
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
290
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
291 # now only internal for load...
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
292 sub load_image_tags($) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
293 %old_field = %field; # save for later recall
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
294
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
295 my $test_filename = shift;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
296 $parser = new XML::DOM::Parser;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
297 if (-r "${test_filename}.xml" ) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
298 $doc = $parser->parsefile ("${test_filename}.xml");
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
299 } else {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
300 # literal minimal tree
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
301 $doc = $parser->parse('<?xml version="1.0" encoding="UTF-8"?><image><description></description><bins></bins><exif></exif></image>');
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
302 status(sprintf(_("%s not found, constructing"), "${test_filename}.xml"));
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
303 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
304
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
305
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
306 undef %field;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
307
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
308 for my $i (@image_tags) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
309 $field{$i} = "";
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
310 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
311
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
312 for my $field_node ($doc->xql("image/description/field")) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
313 # <field name="location"></field>
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
314 # <field name="description">Sjenka</field>
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
315 my $fieldname = ($field_node->xql("\@name"))[0]->xql_toString;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
316 my $fieldval = $field_node->xql_toString;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
317 print "N: $fieldname V: $fieldval\n" if $debug;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
318 my $newval;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
319 do {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
320 $newval = $UTF2Latin->convert($fieldval);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
321 charmap_failed("load_image_tags", $fieldval) if (not defined $newval);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
322 } until defined $newval;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
323 $field{$fieldname} = $newval;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
324 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
325
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
326 undef $newimage_tagged_or;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
327 # <image><exif><tag name="Orientation" priority="1">right_top</tag>
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
328 for my $tag_node ($doc->xql("image/exif/tag[\@name = 'Orientation']")) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
329 my $tagname = ($tag_node->xql("\@name"))[0]->xql_toString;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
330 my $tagprio_node = ($tag_node->xql("\@priority"))[0];
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
331 my $tagprio;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
332 $tagprio = $tagprio_node->xql_toString if defined $tagprio_node;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
333 my $tagval = $tag_node->xql_toString;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
334 # but actually, we only care about orientation
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
335 print "N: $tagname V: $tagval P: $tagprio\n" if $debug;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
336 if ($tagprio == 1) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
337 $newimage_tagged_or = $tagval;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
338 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
339 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
340
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
341 # a clist is output only. someday, replace it with a list of
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
342 # editboxes, even if we have to write one all in perl.
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
343
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
344 # in the mean time, we vector out to a pair of combo boxes and let
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
345 # the user edit there, while copying the changes back live.
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
346
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
347 # save last index if any...
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
348 my $oldtag;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
349 my $oldrow = $ilist->focus_row();
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
350 $oldtag = $ilist->get_text($oldrow, 0) if $oldrow > 0;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
351 print "old $oldrow: $oldtag\n" if $debug;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
352 $ilist->clear;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
353 for my $i (sort keys %field) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
354 $ilist->append("\u$i", $field{$i});
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
355 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
356 if ($oldrow > 0) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
357 my $newrow = my_gtk_find_row($ilist, 0, $oldtag);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
358 print "new $newrow\n" if $debug;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
359 if ($newrow > 0) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
360 $ilist->set_focus_row($newrow);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
361 $ilist->grab_focus();
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
362 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
363 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
364
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
365 # help the user enter stuff
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
366 $name_entry->set_popdown_strings(@known_tags);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
367 # tag as unchanged
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
368 $dirty = 0;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
369 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
370
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
371 sub charmap_failed($$) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
372 my $ipop = $g->get_widget('iconv_failed_dialog');
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
373
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
374 my $lbutton = $g->get_widget('iconv_latin1_charmap_button');
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
375 $lbutton->set_active(Gtk->true); # really we mean it
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
376 my $ubutton = $g->get_widget('iconv_user_charmap_button');
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
377 my $uentry = $g->get_widget('iconv_user_charmap_entry');
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
378 # if there's a value there, it is from the previous attempt, and is wrong.
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
379 $uentry->set_text("");
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
380
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
381 $ipop->run_and_close;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
382
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
383 if ($lbutton->get_active) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
384 set_encoding("LATIN1");
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
385 } elsif ($ubutton->get_active) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
386 set_encoding($uentry->get_text);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
387 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
388
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
389 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
390
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
391 sub save_image_tags {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
392 my $test_filename = shift;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
393 if ((not $dirty) && ($newimage_or eq $newimage_loaded_or)) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
394 status(sprintf(_("%s not dirty, not saved"), ${test_filename}));
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
395 return;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
396 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
397
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
398 my $parent = ($doc->xql("image/description"))[0]; # first one
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
399 my $exif = ($doc->xql("image/exif"))[0];
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
400 my %f = %field;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
401
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
402 # write out the tree...
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
403 for my $xmlfield ($doc->xql("image/description/field")) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
404 my $namestr = $xmlfield->getAttribute("name");
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
405 if (defined $f{$namestr}) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
406 # delete this node so we can append it later
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
407 $xmlfield->getParentNode->removeChild($xmlfield);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
408 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
409 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
410 # now append the remaining ones...
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
411 for my $k (keys %f) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
412 next if ($f{$k} eq "");
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
413 my $newfield = new XML::DOM::Element($doc, "field");
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
414 print "creating <$k> with <$f{$k}>\n" if $debug;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
415 $newfield->setAttribute("name", $k); # needs quoting!
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
416 print "k: ", $k, " f: ", $f{$k}, " L2U: ", $Latin2UTF->convert($f{$k}), "\n" if $debug;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
417 my $newval;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
418 do {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
419 $newval = $Latin2UTF->convert($f{$k});
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
420 charmap_failed("save_image_tags", $f{$k}) if (not defined $newval);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
421 } until defined $newval;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
422
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
423 $newfield->addText($newval);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
424 $parent->appendChild($newfield);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
425 print "created $k with $f{$k}\n" if $debug;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
426 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
427
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
428 # and orientation, if set
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
429 if ($newimage_or ne $newimage_loaded_or) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
430 for my $tag_node ($doc->xql("image/exif/tag[\@name = 'Orientation']")) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
431 # delete the node, then construct a new one
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
432 $tag_node->getParentNode->removeChild($tag_node);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
433 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
434 my $newtag = new XML::DOM::Element($doc, "tag");
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
435 $newtag->setAttribute("name", "Orientation");
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
436 $newtag->setAttribute("priority", "1");
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
437 $newtag->addText($Latin2UTF->convert($newimage_or)); # unneeded conversion
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
438 $exif->appendChild($newtag);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
439 print "Set orientation <$newimage_or> (loaded $newimage_loaded_or) in exif tag\n" if $debug;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
440 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
441
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
442 $doc->printToFile("${test_filename}.xml");
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
443 status(sprintf(_("Saved %s."), $test_filename));
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
444 # undirty it
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
445 $dirty = 0;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
446 $newimage_loaded_or = $newimage_or;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
447 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
448
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
449 # if they enter or select a known one, snarf the value
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
450 $name_entry->entry->signal_connect('changed', sub {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
451 my $entry = shift;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
452 my $val = $field{$entry->get_text};
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
453 if (defined $val) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
454 $value_entry->entry->set_text($val);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
455 $value_entry->entry->set_editable(Gtk->true);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
456 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
457 $dirty = 1;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
458 });
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
459
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
460 sub my_album_replace_text($$) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
461 my $aw = shift;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
462 my $text = shift;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
463 $aw->set_point(0);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
464 $aw->forward_delete($albumvalue->get_length());
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
465 $aw->insert(undef, undef, undef, $text);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
466 $aw->set_editable(Gtk->true);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
467 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
468
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
469 # album version
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
470 $albumname->entry->signal_connect('changed', sub {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
471 my $entry = shift;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
472 my $val = $album{$entry->get_text};
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
473 if (defined $val) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
474 my_album_replace_text($albumvalue, $val);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
475 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
476 $album_dirty = 1;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
477 });
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
478
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
479 sub my_gtk_find_row { # returns row
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
480 my ($clist, $col, $value) = @_;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
481 for my $i (0..$clist->rows) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
482 my $cell = $clist->get_text($i, $col);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
483 return $i if ($cell ne "" && lc($cell) eq lc($value));
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
484 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
485 return -1;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
486 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
487
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
488 # if the value changes, update the text
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
489 $value_entry->entry->signal_connect('changed', sub {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
490 my $entry = shift;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
491 my $newval = $entry->get_text;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
492 my $tag = lc($name_entry->entry->get_text);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
493 $field{$tag} = $newval;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
494 $dirty = 1;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
495 my $row = my_gtk_find_row($ilist, 0, $tag);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
496 print "row: $row tag: $tag newval: $newval\n" if $debug;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
497 # oh, no tag yet, add one
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
498 if ($row != -1) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
499 $ilist->set_text($row, 1, $newval);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
500 } else {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
501 # triggers select-row?
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
502 $ilist->append("\u$tag", $newval);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
503 # update the dropdown too
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
504 @known_tags = sort (@known_tags, $tag);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
505 $name_entry->set_popdown_strings(@known_tags);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
506 # force it all back
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
507 $ilist->select_row($ilist->rows()-1, 0);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
508 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
509 });
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
510 # album version
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
511 $albumvalue->signal_connect('changed', sub {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
512 my $entry = shift;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
513 my $newval = $entry->get_chars(0,-1);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
514 my $tag = lc($albumname->entry->get_text);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
515 $album{$tag} = $newval;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
516 $dirty = 1;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
517 my $row = my_gtk_find_row($albumprop, 0, $tag);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
518 print "row: $row tag: $tag newval: $newval\n" if $debug;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
519 # oh, no tag yet, add one
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
520 if ($row != -1) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
521 $albumprop->set_text($row, 1, $newval);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
522 } else {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
523 # triggers select-row?
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
524 $albumprob->append("\u$tag", $newval);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
525 # update the dropdown too
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
526 @known_tags = sort (@known_tags, $tag);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
527 $albumname->set_popdown_strings(@known_tags);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
528 # force it all back
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
529 $albumprob->select_row($ilist->rows()-1, 0);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
530 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
531 });
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
532
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
533 $ilist->signal_connect('select-row', sub {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
534 my ($clist, $row, $col, $event, $udata) = @_;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
535 print "list: $clist row: $row col: $col event: $event udata: $udata\n"
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
536 if $debug;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
537 $name_entry->entry->set_text($clist->get_text($row,0));
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
538 $value_entry->entry->set_text($clist->get_text($row,1));
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
539 print "focus on $value_entry\n" if $debug;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
540 $value_entry->entry->grab_focus();
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
541 });
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
542
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
543 # album version
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
544 $albumprop->signal_connect('select-row', sub {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
545 my ($clist, $row, $col, $event, $udata) = @_;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
546 print "list: $clist row: $row col: $col event: $event udata: $udata\n"
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
547 if $debug;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
548 $albumname->entry->set_text($clist->get_text($row,0));
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
549 my_album_replace_text($albumvalue, $clist->get_text($row,1));
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
550 print "focus on $value_entry\n" if $debug;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
551 $albumvalue->grab_focus();
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
552 });
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
553
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
554
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
555 # filter out .xml files, as we always derive them from the images
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
556 # (also lets us eventually use the images as database keys instead)
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
557 @filenames = grep (!/\.xml$/, @ARGV);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
558
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
559 $current_n = 0;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
560 $current_filename = $filenames[$current_n];
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
561
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
562 load_image $current_filename;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
563
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
564 Gtk->main;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
565
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
566 ## callbacks..
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
567 # new callbacks
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
568 # sgrep -o '%r\n' 'stag("HANDLER") __ etag("HANDLER") ' bins-edit-gui.glade | while read sub; do grep "$sub" bins-edit-gui.pl >/dev/null || echo "$sub"; done
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
569
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
570 sub on_save1_activate {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
571 save_image_tags $current_filename;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
572 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
573
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
574 sub on_about2_activate {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
575 $aboutbox->show;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
576 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
577
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
578 sub on_license1_activate {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
579 $licensebox->show;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
580 my $button = $g->get_widget('dismiss_about');
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
581 $button->grab_focus();
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
582 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
583
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
584 sub on_open2_activate {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
585 status(_("File browser not yet implemented."));
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
586 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
587
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
588 sub on_revert1_activate {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
589 load_image $current_filename;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
590 status(sprintf(_("Reverted from %s."), $current_filename));
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
591 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
592
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
593 sub set_filename_index($) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
594 $current_n = shift;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
595 $current_filename = $filenames[$current_n];
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
596 load_image $current_filename;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
597 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
598
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
599 sub move_filename_index($) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
600 save_image_tags $current_filename;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
601 my $delta = shift;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
602 my $new_n = $current_n + $delta;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
603
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
604 # clamp it
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
605 $new_n = 0 if $new_n < 0;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
606 $new_n = $#filenames if $new_n > $#filenames;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
607 if ($new_n == $current_n) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
608 # we didn't move
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
609 status(_("Out of filenames."));
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
610 } else {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
611 set_filename_index($new_n);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
612 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
613 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
614
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
615 sub on_next_file1_activate {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
616 move_filename_index(+1);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
617 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
618
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
619 sub on_prev_file1_activate {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
620 move_filename_index(-1);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
621 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
622
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
623 sub on_forward_10_activate {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
624 move_filename_index(+10);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
625 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
626 sub on_back_10_activate {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
627 move_filename_index(-10);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
628 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
629 sub on_start_of_list1_activate {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
630 set_filename_index(0);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
631 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
632 sub on_end_of_list1_activate {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
633 set_filename_index($#filenames);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
634 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
635
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
636
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
637 # auto fill from old_field
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
638 sub on_auto_fill1_activate {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
639 for my $k (keys %old_field) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
640 if ($field{$k} eq "" && $old_field{$k} ne "") {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
641 $field{$k} = $old_field{$k};
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
642 $dirty = 1;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
643 # and change it on-screen
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
644 my $row = my_gtk_find_row($ilist, 0, $k);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
645 if ($row != -1) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
646 print "updating row $row with $k ($field{$k})\n" if $debug;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
647 $ilist->set_text($row, 1, $field{$k});
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
648 } # maybe warn, or add field, if not found?
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
649 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
650 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
651 status("Auto-filled fields.");
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
652 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
653
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
654 sub on_exit1_activate {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
655 save_image_tags $current_filename;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
656
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
657 Gtk->main_quit;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
658 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
659
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
660 sub on_test_expose_event {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
661 my($widget) = @_;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
662
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
663 # print "otee, ",defined $imagesized,"\n";
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
664 # if (1 || not defined $imagesized) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
665 my $w = $g->get_widget('image_edit_pixmap'); # GTK-Interface/widget/name
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
666 # x,y,width,height
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
667 my ($alloc_x, $alloc_y, $alloc_w, $alloc_h) = @{$w->allocation};
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
668 my $widget_w = $alloc_w;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
669 my $widget_h = $alloc_h;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
670
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
671 if ($debug) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
672 print join("| ", @{$w->allocation});
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
673 print "| x: $widget_w y: $widget_h ";
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
674 print
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
675 "nw: ", $newimage->rgb_width,
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
676 " nh: ", $newimage->rgb_height, "\n" if defined $newimage;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
677 print
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
678 " x/y: ",$widget_w/$widget_h,
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
679 " nw/x: ", $newimage->rgb_width/$widget_w,
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
680 " nh/y: ", $newimage->rgb_height/$widget_h,
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
681 "\n" if defined $newimage;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
682 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
683 # print "ox: $old_x oy: $old_y ww: $widget_w wh: $widget_h I:$imagesized\n";
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
684 # return if same size
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
685 if ($old_x == $widget_w && $old_y == $widget_h) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
686 # but not if we never dealt before
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
687 return if (defined $imagesized);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
688 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
689 if (defined $newimage) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
690 my ($use_w, $use_h) = ($newimage->rgb_width, $newimage->rgb_height);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
691 my $rat_w = $use_w/$widget_w;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
692 my $rat_h = $use_h/$widget_h;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
693 $rat = ($rat_w > $rat_h) ? $rat_w : $rat_h;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
694
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
695 $use_w = $use_w / $rat;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
696 $use_h = $use_h / $rat;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
697 $newimage->render($use_w, $use_h);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
698 my $my_image = $newimage->copy_image(); # returns Gtk::Gdk::Pixmap
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
699 my $my_mask = $newimage->copy_mask(); # returns Gtk::Gdk::Bitmap
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
700 $w->set($my_image, $my_mask);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
701 $my_image->imlib_free();
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
702 } else {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
703 # come up with more clever "test pattern" later?
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
704 $w->set(undef, undef);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
705 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
706 $old_x = $widget_w;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
707 $old_y = $widget_h;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
708 #undef $imagesized;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
709 $imagesized = 1;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
710 # }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
711 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
712
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
713 # rotations that override, or rather compound, the EXIF values
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
714 # build the rotation-ring first
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
715 sub my_init_rotations {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
716 my @rotation_order = ("right_top", "right_bot", "left_bot", "top_left");
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
717 my $left = $rotation_order[$#rotation_order];
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
718 for my $curr (@rotation_order) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
719 $rotate_right{$left} = $curr;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
720 $rotate_left{$curr} = $left;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
721 $left = $curr;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
722 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
723 # special case none->top_left
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
724 $rotate_right{""} = $rotate_right{"top_left"};
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
725 $rotate_left{""} = $rotate_left{"top_left"};
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
726 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
727
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
728 sub my_image_rotate {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
729 my $delta_or = shift;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
730 print "$test_filename: new user-requested rotation $delta_or to $newimage_or\n" if $debug;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
731
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
732 my_real_gdk_rotate($newimage,$delta_or);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
733 # consider noticing that $newimage_or == $newimage_loaded_or and reverting.
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
734 # regardless, rerender
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
735 if (defined $imagesized) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
736 undef $imagesized;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
737 on_test_expose_event();
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
738 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
739 status(_("Rotated."));
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
740 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
741
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
742 sub on_rotate_right_cw1_activate {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
743 $newimage_or = $rotate_right{$newimage_or};
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
744 my_image_rotate("right_top");
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
745 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
746
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
747 sub on_rotate_left1_activate {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
748 $newimage_or = $rotate_left{$newimage_or};
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
749 my_image_rotate("left_bot");
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
750 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
751
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
752 # don't actually undo the rotations, just reload - but don't lose tags
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
753 sub on_cancel_rotation1_activate {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
754 load_image $current_filename, "keeptags";
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
755 status(_("Image restored."));
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
756 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
757
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
758 ### album stuff ###
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
759 sub load_album_tags($);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
760
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
761 sub on_album1_activate {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
762 $current_album = $current_filename;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
763 # basename
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
764 $current_album =~ s{[^/]*$}{}; # } perl-mode-sucks
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
765 # make a complete name out of it
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
766 $current_album .= "album.xml"; #if (-d "${current_album}");
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
767 $albumfile->set($current_album);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
768 load_album_tags($current_album);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
769 $albumedit->show;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
770 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
771
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
772 sub on_open2_activate {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
773 status(_("File browser not yet implemented."));
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
774 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
775
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
776 sub on_close1_activate {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
777 # save if dirty
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
778 save_album_tags($current_album) if $album_dirty;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
779 $albumedit->hide;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
780 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
781
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
782 sub on_revert2_activate {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
783 load_album_tags $current_album;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
784 status(sprintf(_("Reverted from %s."), $current_album));
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
785 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
786
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
787 sub save_album_tags;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
788
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
789 sub on_save2_activate {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
790 save_album_tags $current_album;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
791 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
792
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
793 # sub on_exit2_activate {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
794 # &on_exit1_activate(@_);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
795 # }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
796
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
797 sub load_album_tags($) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
798 %old_album = %album; # save for later recall
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
799
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
800 my $test_filename = shift;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
801 $parser = new XML::DOM::Parser;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
802 if (-r "${test_filename}" ) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
803 $album_doc = $parser->parsefile ("${test_filename}");
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
804 } else {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
805 # literal minimal tree
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
806 $album_doc = $parser->parse('<?xml version="1.0" encoding="UTF-8"?><album><description></description><bins></bins></album>');
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
807 status(sprintf(_("%s not found, constructing"), "${test_filename}"));
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
808 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
809
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
810
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
811 undef %album;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
812
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
813 for my $i (@album_tags) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
814 $album{$i} = "";
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
815 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
816
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
817 for my $field_node ($album_doc->xql("album/description/field")) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
818 my $fieldname = ($field_node->xql("\@name"))[0]->xql_toString;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
819 my $fieldval = $field_node->xql_toString;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
820 print "N: $fieldname V: $fieldval\n" if $debug;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
821 $album{$fieldname} = $UTF2Latin->convert($fieldval);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
822 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
823
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
824 # a clist is output only. someday, replace it with a list of
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
825 # editboxes, even if we have to write one all in perl.
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
826
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
827 # in the mean time, we vector out to a pair of combo boxes and let
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
828 # the user edit there, while copying the changes back live.
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
829
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
830 # save last index if any...
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
831 my $oldtag;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
832 my $oldrow = $albumprop->focus_row();
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
833 $oldtag = $albumprop->get_text($oldrow, 0) if $oldrow > 0;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
834 print "old $oldrow: $oldtag\n" if $debug;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
835 $albumprop->clear;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
836 for my $i (sort keys %album) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
837 $albumprop->append("\u$i", $album{$i});
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
838 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
839 if ($oldrow > 0) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
840 my $newrow = my_gtk_find_row($albumprop, 0, $oldtag);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
841 print "new $newrow\n" if $debug;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
842 if ($newrow > 0) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
843 $albumprop->set_focus_row($newrow);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
844 $albumprop->grab_focus();
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
845 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
846 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
847
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
848 # help the user enter stuff
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
849 $albumname->set_popdown_strings(@known_tags);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
850 # tag as unchanged
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
851 $dirty = 0;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
852 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
853
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
854 sub save_album_tags {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
855 my $test_filename = shift;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
856 if (not $album_dirty) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
857 status(sprintf(_("%s not dirty, not saved"), ${test_filename}));
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
858 return;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
859 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
860
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
861 my $parent = ($album_doc->xql("album/description"))[0]; # first one
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
862 my %f = %album;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
863
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
864 # write out the tree...
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
865 for my $xmlfield ($album_doc->xql("album/description/field")) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
866 my $namestr = $xmlfield->getAttribute("name");
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
867 if (defined $f{$namestr}) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
868 # delete this node so we can append it later
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
869 $xmlfield->getParentNode->removeChild($xmlfield);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
870 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
871 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
872 # now append the remaining ones...
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
873 for my $k (keys %f) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
874 next if ($f{$k} eq "");
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
875 my $newfield = new XML::DOM::Element($album_doc, "field");
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
876 print "creating <$k> with <$f{$k}>\n" if $debug;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
877 $newfield->setAttribute("name", $k); # needs quoting!
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
878 $newfield->addText($Latin2UTF->convert($f{$k}));
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
879 $parent->appendChild($newfield);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
880 print "created $k with $f{$k}\n" if $debug;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
881 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
882
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
883 $album_doc->printToFile("${test_filename}");
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
884 status(sprintf(_("Saved %s."), $test_filename));
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
885 # undirty it
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
886 $album_dirty = 0;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
887 }