… | |
… | |
4 | use Gtk2::Gdk::Keysyms; |
4 | use Gtk2::Gdk::Keysyms; |
5 | |
5 | |
6 | use Gtk2::CV::ImageWindow; |
6 | use Gtk2::CV::ImageWindow; |
7 | use Gtk2::CV::Schnauzer; |
7 | use Gtk2::CV::Schnauzer; |
8 | |
8 | |
9 | $VERSION = 0.1; |
9 | use Gtk2::CV; |
10 | |
10 | |
|
|
11 | Gtk2::Rc->parse (Gtk2::CV::find_rcfile "gtkrc"); |
|
|
12 | |
|
|
13 | use File::Spec; |
|
|
14 | |
|
|
15 | my $mainwin; |
11 | my $viewer; |
16 | my $viewer; |
|
|
17 | my $schnauzer; |
|
|
18 | my $info; |
|
|
19 | my $help; |
12 | |
20 | |
13 | package cluster; |
21 | my $schnauzer_idx = 0; |
14 | |
|
|
15 | use Glib::Object::Subclass Gtk2::Window; |
|
|
16 | |
|
|
17 | use Gtk2::SimpleList; |
|
|
18 | |
|
|
19 | sub INIT_INSTANCE { |
|
|
20 | my ($self) = @_; |
|
|
21 | |
|
|
22 | $self->set_default_size (600, 400); |
|
|
23 | |
|
|
24 | my $vbox = new Gtk2::VBox; |
|
|
25 | $self->add ($vbox); |
|
|
26 | |
|
|
27 | my $box = new Gtk2::HBox; |
|
|
28 | $vbox->add ($box); |
|
|
29 | $box->add (my $sw = new Gtk2::ScrolledWindow); |
|
|
30 | $sw->add ( |
|
|
31 | $self->{list} = new Gtk2::SimpleList |
|
|
32 | "#" => "int", |
|
|
33 | "Name" => "text", |
|
|
34 | ); |
|
|
35 | |
|
|
36 | $box->add ($self->{schnauzer} = new Gtk2::CV::Schnauzer); |
|
|
37 | |
|
|
38 | $self->{list}->get_column(0)->set_sort_column_id(0); |
|
|
39 | $self->{list}->get_column(1)->set_sort_column_id(1); |
|
|
40 | |
|
|
41 | $self->{list}->signal_connect (cursor_changed => sub { |
|
|
42 | my $row = scalar +($_[0]->get_selection->get_selected_rows)[0]->get_indices; |
|
|
43 | |
|
|
44 | my $k = $_[0]{data}[$row][1]; |
|
|
45 | $k = $self->{cluster}{$k}; |
|
|
46 | |
|
|
47 | $self->{schnauzer}->set_files ( |
|
|
48 | [sort map "$self->{path}/$_", @{$k->[1]}], |
|
|
49 | ); |
|
|
50 | |
|
|
51 | 1; |
|
|
52 | |
|
|
53 | }); |
|
|
54 | } |
|
|
55 | |
|
|
56 | sub analyse { |
|
|
57 | my ($self, $path) = @_; |
|
|
58 | |
|
|
59 | opendir my $dir, $path |
|
|
60 | or die "$path: $!"; |
|
|
61 | |
|
|
62 | $self->{path} = $path; |
|
|
63 | |
|
|
64 | my @files = map { |
|
|
65 | my $str = $_; |
|
|
66 | $str =~ s/[\-_ ]+/ /g; |
|
|
67 | $str =~ s/\.[^\.]+//g; |
|
|
68 | [$str, $_] |
|
|
69 | } |
|
|
70 | grep !/\.(sfv|crc|par|par2)$/, readdir $dir; |
|
|
71 | |
|
|
72 | my %cluster; |
|
|
73 | |
|
|
74 | my @regexps = ( |
|
|
75 | [qr<\d+$>, qr<^(.+?)\ *(\d+)$>], |
|
|
76 | [qr<\ \d+$>, qr<^(.+?)(\d+)\ +(\d+)$>], |
|
|
77 | ); |
|
|
78 | |
|
|
79 | for my $info (@regexps) { |
|
|
80 | my $re = $info->[0]; |
|
|
81 | for (@files) { |
|
|
82 | if ($_->[0] =~ $re && $_->[0] =~ $info->[1]) { |
|
|
83 | push @{ ($cluster{$1} ||= [ $info, []])->[1] }, $_->[1]; |
|
|
84 | } |
|
|
85 | } |
|
|
86 | } |
|
|
87 | |
|
|
88 | $self->{cluster} = \%cluster; |
|
|
89 | |
|
|
90 | while (my ($k, $v) = each %cluster) { |
|
|
91 | my $n = scalar @{$v->[1]}; |
|
|
92 | push @{$self->{list}{data}}, [$n, $k] if $n > 2; |
|
|
93 | } |
|
|
94 | } |
|
|
95 | |
|
|
96 | package main; |
|
|
97 | |
22 | |
98 | sub new_schnauzer { |
23 | sub new_schnauzer { |
99 | my $w = new Gtk2::Window; |
|
|
100 | $w->add (my $s = new Gtk2::CV::Schnauzer); |
24 | my $s = new Gtk2::CV::Schnauzer; |
101 | |
25 | |
|
|
26 | $s->signal_connect_after (key_press_event => \&std_keys); |
102 | $s->signal_connect (activate => sub { |
27 | $s->signal_connect (activate => sub { |
|
|
28 | my $label = sprintf "%s (%d)", |
|
|
29 | (File::Spec->splitpath ($_[1]))[2], |
|
|
30 | -s $_[1]; |
|
|
31 | $info->set_label ($label); |
103 | $viewer->load_image ($_[1]); |
32 | $viewer->load_image ($_[1]); |
104 | }); |
33 | }); |
105 | $s->set_dir ("/root/pix"); |
34 | |
|
|
35 | $s; |
|
|
36 | } |
|
|
37 | |
|
|
38 | sub std_keys { |
|
|
39 | my $key = $_[1]->keyval; |
|
|
40 | my $state = $_[1]->state; |
|
|
41 | |
|
|
42 | my $ctrl = $state * "control-mask"; |
|
|
43 | |
|
|
44 | if ($key == $Gtk2::Gdk::Keysyms{q}) { |
|
|
45 | main_quit Gtk2; |
|
|
46 | } elsif ($ctrl && $key == $Gtk2::Gdk::Keysyms{v}) { |
|
|
47 | my $w = new Gtk2::Window; |
|
|
48 | |
|
|
49 | $w->set_title ("CV: Schnauzer"); |
|
|
50 | $w->add (my $s = new_schnauzer); |
|
|
51 | $s->set_dir (File::Spec->curdir); |
|
|
52 | $s->set_geometry_hints; |
106 | $w->show_all; |
53 | $w->show_all; |
107 | |
54 | |
108 | $w; |
55 | } elsif ($ctrl && $key == $Gtk2::Gdk::Keysyms{h}) { |
109 | } |
56 | unless ($help) { |
|
|
57 | require Gtk2::PodViewer; |
110 | |
58 | |
|
|
59 | $help = new Gtk2::Window; |
|
|
60 | $help->set_title ("CV: Help"); |
|
|
61 | $help->set_default_size (500, 300); |
|
|
62 | $help->signal_connect (delete_event => sub { $help->hide; 1 }); |
|
|
63 | |
|
|
64 | $help->add (my $sw = new Gtk2::ScrolledWindow); |
|
|
65 | $sw->add (my $h = new Gtk2::PodViewer); |
|
|
66 | |
|
|
67 | #binmode DATA, ":utf8"; |
|
|
68 | $h->load_string (do { local $/; <DATA> }); |
|
|
69 | } |
|
|
70 | |
|
|
71 | $help->show_all; |
|
|
72 | } else { |
|
|
73 | #$mainwin->show_all; |
|
|
74 | $schnauzer->handle_key ($key, $state); |
|
|
75 | } |
|
|
76 | |
|
|
77 | 1; |
|
|
78 | } |
|
|
79 | |
|
|
80 | { |
111 | $viewer = new Gtk2::CV::ImageWindow; |
81 | $viewer = new Gtk2::CV::ImageWindow; |
|
|
82 | |
|
|
83 | $viewer->set_title ("CV: Image"); |
|
|
84 | |
|
|
85 | $viewer->signal_connect (key_press_event => \&std_keys); |
|
|
86 | $viewer->signal_connect (delete_event => sub { main_quit Gtk2 }); |
|
|
87 | |
|
|
88 | $viewer->signal_connect (button3_press_event => sub { |
|
|
89 | $mainwin->visible |
|
|
90 | ? $mainwin->hide |
|
|
91 | : $mainwin->show_all; |
|
|
92 | 1; |
|
|
93 | }); |
|
|
94 | |
|
|
95 | $schnauzer = new_schnauzer; |
|
|
96 | |
|
|
97 | $mainwin = new Gtk2::Window; |
|
|
98 | $mainwin->set_title ("CV"); |
|
|
99 | $mainwin->add (my $vbox = new Gtk2::VBox); |
|
|
100 | $mainwin->signal_connect (delete_event => sub { $mainwin->hide; 1; }); |
|
|
101 | |
|
|
102 | $vbox->add ($schnauzer); |
|
|
103 | $vbox->pack_end (my $frame = new Gtk2::Frame, 0, 0, 0); |
|
|
104 | $frame->add (my $hbox = new Gtk2::HBox 0, 0); |
|
|
105 | $hbox->pack_start ((new Gtk2::Label "Info"), 0, 0, 0); |
|
|
106 | $hbox->pack_start (($info = new Gtk2::Label), 1, 1, 0); |
|
|
107 | |
|
|
108 | $schnauzer->set_geometry_hints; |
|
|
109 | } |
|
|
110 | |
|
|
111 | if (@ARGV) { |
|
|
112 | $_ = Glib::filename_to_unicode $_ for @ARGV; |
|
|
113 | $schnauzer->set_paths (\@ARGV); |
|
|
114 | $schnauzer->show_all; |
|
|
115 | $schnauzer->handle_key ($Gtk2::Gdk::Keysyms{space}, []); |
|
|
116 | } else { |
|
|
117 | $schnauzer->set_dir (File::Spec->curdir); |
|
|
118 | $mainwin->show_all; |
|
|
119 | } |
112 | |
120 | |
113 | $viewer->show_all; |
121 | $viewer->show_all; |
114 | |
122 | |
115 | my $cluster = new cluster; |
|
|
116 | |
|
|
117 | new_schnauzer; |
|
|
118 | |
|
|
119 | #$cluster->analyse ("/fs/samsung/store-anime-done"); |
|
|
120 | #$cluster->show_all; |
|
|
121 | |
|
|
122 | #$viewer->set (path => "/fs/samsung/store-anime-done/yuumi_kazuaki_-_love_to_hajieki_to_sayonara_to_-_150.jpg"); |
|
|
123 | #$viewer->set (path => "/root/pix/kvvz.jpg"); |
|
|
124 | |
|
|
125 | main Gtk2; |
123 | main Gtk2; |
126 | |
124 | |
|
|
125 | __DATA__ |
127 | |
126 | |
|
|
127 | =head1 NAME |
|
|
128 | |
|
|
129 | cv - a fast gtk+ image viewer modeled after xv |
|
|
130 | |
|
|
131 | =head1 SYNOPSIS |
|
|
132 | |
|
|
133 | cv [file...] |
|
|
134 | |
|
|
135 | =head1 DESCRIPTION |
|
|
136 | |
|
|
137 | None yet. |
|
|
138 | |
|
|
139 | =head2 THE IMAGE WINDOW |
|
|
140 | |
|
|
141 | You can use the following keys in the image window: |
|
|
142 | |
|
|
143 | q quit the program |
|
|
144 | < half the image size |
|
|
145 | > double the image size |
|
|
146 | , shrink the image by 10% |
|
|
147 | . enlarge the image by 10% |
|
|
148 | n reset to normal size |
|
|
149 | m maximize to screensize |
|
|
150 | M maxime to screensize, respecting image aspect |
|
|
151 | ctrl-m toggle maxpect-always mode |
|
|
152 | u uncrop |
|
|
153 | r set scaling mode to 'nearest' (fastest) |
|
|
154 | s set scaling mode to 'bilinear' (default) |
|
|
155 | S set scaling mode to 'hyper' (slowest) |
|
|
156 | t rotate clockwise 90° |
|
|
157 | T rotate counterclockwise° |
|
|
158 | ctrl-v open a new visual schnauzer window for the current dir |
|
|
159 | ctrl-s rescan visual schnauzer files for updates/deletes etc. |
|
|
160 | ctrl-e run an editor ($CV_EDITOR or "gimp") on the current image. |
|
|
161 | |
|
|
162 | The following keys are redirected to the default visual schnauzer window: |
|
|
163 | |
|
|
164 | space next image |
|
|
165 | backspace last image |
|
|
166 | |
|
|
167 | =head2 THE VISUAL SCHNAUZER |
|
|
168 | |
|
|
169 | You can use the following keys in the schnauzer window: |
|
|
170 | |
|
|
171 | space move to and display next image |
|
|
172 | backspace move to and display previous image |
|
|
173 | return display selected picture |
|
|
174 | |
|
|
175 | cursor keys move selection |
|
|
176 | page-up move one page up |
|
|
177 | page-down move one page down |
|
|
178 | home move to first file |
|
|
179 | end move to last file |
|
|
180 | |
|
|
181 | ctrl-d delete selected files WITHOUT ASKING AGAIN |
|
|
182 | ctrl-g generate icons for the selected files |
|
|
183 | ctrl-u update selected (or all) icons if neccessary |
|
|
184 | |
|
|
185 | =head1 ENVIRONMENT |
|
|
186 | |
|
|
187 | =over 4 |
|
|
188 | |
|
|
189 | =item CV_PRINT_DESTINATION |
|
|
190 | |
|
|
191 | The default (perl-style) destination to use in the print dialog. |
|
|
192 | |
|
|
193 | =back |
|
|
194 | |
|
|
195 | =head1 SECURITY CONSIDERATIONS |
|
|
196 | |
|
|
197 | CV uses Pixbuf to load images. Pixbuf is not considered safe for this |
|
|
198 | purpose, though (from the gtk-2.2 release notes): |
|
|
199 | |
|
|
200 | "While efforts have been made to make gdk-pixbuf robust against invalid |
|
|
201 | images, using gdk-pixbuf to load untrusted data is not recommended, due to |
|
|
202 | the likelyhood that there are additional problems where an invalid image |
|
|
203 | could cause gdk-pixbuf to crash or worse." |
|
|
204 | |
|
|
205 | =head1 BUGS/TODO |
|
|
206 | |
|
|
207 | Pixbuf doesn't honor G_BROKEN_FILENAMES, so accessing files with names |
|
|
208 | incompatible with utf-8 fails. |
|
|
209 | |
|
|
210 | rotate on disk |
|
|
211 | print |
|
|
212 | lots of ui issues |
|
|
213 | save(?) |
|
|
214 | preferences |
|
|
215 | ctrl-u in schnauzer |
|
|
216 | shift-cursor in schnauzer |
|
|
217 | |
|
|
218 | =head1 AUTHOR |
|
|
219 | |
|
|
220 | Marc Lehmann <cv@plan9.de>. |
|
|
221 | |
|
|
222 | =cut |
|
|
223 | |