ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/CV/bin/cv
(Generate patch)

Comparing CV/bin/cv (file contents):
Revision 1.39 by root, Sun May 1 05:53:40 2005 UTC vs.
Revision 1.76 by root, Sat Mar 15 11:02:17 2008 UTC

1#!/opt/bin/perl 1#!/opt/bin/perl
2 2
3use Cwd (); 3use Cwd ();
4use Encode (); 4use Encode ();
5use File::Glob ();
5 6
6use Gtk2 -init; 7use Gtk2 -init;
7use Gtk2::Gdk::Keysyms; 8use Gtk2::Gdk::Keysyms;
8 9
10use Gtk2::CV;
11
9use Gtk2::CV::ImageWindow; 12use Gtk2::CV::ImageWindow;
10use Gtk2::CV::Schnauzer; 13use Gtk2::CV::Schnauzer;
11 14
12use Gtk2::CV; 15BEGIN {
16 require Gtk2::CV::Plugin;
17 require "$ENV{HOME}/.cvrc" if -r "$ENV{HOME}/.cvrc";
18}
19
20use Gtk2::CV::Plugin::NameCluster;
21use Gtk2::CV::Plugin::RCluster;
13 22
14Gtk2::Rc->parse (Gtk2::CV::find_rcfile "gtkrc"); 23Gtk2::Rc->parse (Gtk2::CV::find_rcfile "gtkrc");
15 24
16use File::Spec; 25use File::Spec;
17 26
18my $mainwin; 27my $mainwin;
19my $viewer; 28my $viewer;
29my $viewer_count;
20my $schnauzer; 30my $schnauzer;
21my $info; 31my $info;
22my $help; 32my $help;
23 33
24my $schnauzer_idx = 0; 34my $schnauzer_idx = 0;
27 my $s = new Gtk2::CV::Schnauzer; 37 my $s = new Gtk2::CV::Schnauzer;
28 38
29 $s->signal_connect_after (key_press_event => \&std_keys); 39 $s->signal_connect_after (key_press_event => \&std_keys);
30 $s->signal_connect (activate => sub { 40 $s->signal_connect (activate => sub {
31 my $label = sprintf "%s (%d)", 41 my $label = sprintf "%s (%d)",
32 (File::Spec->splitpath ($_[1]))[2], 42 (Glib::filename_display_name +(File::Spec->splitpath ($_[1]))[2]),
33 -s $_[1]; 43 -s $_[1];
34 $info->set_label ($label); 44 $info->set_label ($label);
35 $viewer->load_image ($_[1]); 45 $viewer->load_image ($_[1]) if $viewer; # TODO: error, or chose ANY viewer
36 }); 46 });
47
48 Gtk2::CV::Plugin->call (new_schnauzer => $s);
49
50 $s
51}
52
53sub new_viewer {
54 my $self = new Gtk2::CV::ImageWindow;
55
56 $viewer_count++;
57
58 $self->set_title ("CV: Image");
59
37 $s->signal_connect (chdir => sub { 60 $self->signal_connect (key_press_event => sub {
38 my ($self, $dir) = @_; 61 $viewer = $_[0];
39 62
40 my $path = Cwd::abs_path $dir; 63 my $key = $_[1]->keyval;
64 my $state = $_[1]->state;
41 65
42 $self->realize; 66 if ($state * "control-mask" && $key == $Gtk2::Gdk::Keysyms{c}) {
43 $self->window->property_change ( 67 my $viewer = new_viewer ();
44 Gtk2::Gdk::Atom->intern ("_X_CWD", 0), 68 $viewer->set_image ($_[0]->{image});
45 Gtk2::Gdk::Atom->intern ("UTF8_STRING", 0), 69 $viewer->show_all;
46 Gtk2::Gdk::CHARS, 'replace', 70 1
47 Encode::encode_utf8 $path, 71 } else {
72 &std_keys
73 or $schnauzer->signal_emit (key_press_event => $_[1])
48 ); 74 }
49 }); 75 });
76 $self->signal_connect (delete_event => sub { $_[0]->destroy; 0 });
77 $self->signal_connect (destroy => sub {
78 $viewer = undef if $viewer == $_[0];
50 79
51 $s; 80 main_quit Gtk2 unless --$viewer_count;
81
82 0
83 });
84
85 $self->signal_connect (button3_press_event => sub {
86 $mainwin->visible
87 ? $mainwin->hide
88 : $mainwin->show_all;
89
90 1
91 });
92
93 Gtk2::CV::Plugin->call (new_imagewindow => $self);
94
95 $self
52} 96}
53 97
54sub std_keys { 98sub std_keys {
55 my $key = $_[1]->keyval; 99 my $key = $_[1]->keyval;
56 my $state = $_[1]->state; 100 my $state = $_[1]->state;
57 101
58 my $ctrl = $state * "control-mask"; 102 my $ctrl = $state * "control-mask";
59 103
60 if ($key == $Gtk2::Gdk::Keysyms{q}) { 104 if ($key == $Gtk2::Gdk::Keysyms{q}) {
61 main_quit Gtk2; 105 $viewer->destroy;
62 } elsif ($ctrl && $key == $Gtk2::Gdk::Keysyms{v}) { 106 } elsif ($ctrl && $key == $Gtk2::Gdk::Keysyms{v}) {
63 my $w = new Gtk2::Window; 107 my $w = new Gtk2::Window;
64 108
109 $w->set_role ("schnauzer");
65 $w->set_title ("CV: Schnauzer"); 110 $w->set_title ("CV: Schnauzer");
66 $w->add (my $s = new_schnauzer); 111 $w->add (my $s = new_schnauzer);
67 $s->set_dir (File::Spec->curdir); 112 $s->set_dir (File::Spec->curdir);
68 $s->set_geometry_hints; 113 $s->set_geometry_hints;
69 $w->show_all; 114 $w->show_all;
70 115
71 } elsif ($ctrl && $key == $Gtk2::Gdk::Keysyms{h}) { 116 } elsif ($ctrl && $key == $Gtk2::Gdk::Keysyms{h}) {
72 unless ($help) { 117 unless ($help) {
73 require Gtk2::PodViewer; 118 require Gtk2::Ex::PodViewer;
74 119
75 $help = new Gtk2::Window; 120 $help = new Gtk2::Window;
121 $help->set_role ("help");
76 $help->set_title ("CV: Help"); 122 $help->set_title ("CV: Help");
77 $help->set_default_size (500, 300); 123 $help->set_default_size (500, 300);
78 $help->signal_connect (delete_event => sub { $help->hide; 1 }); 124 $help->signal_connect (delete_event => sub { $help->hide; 1 });
79 125
80 $help->add (my $sw = new Gtk2::ScrolledWindow); 126 $help->add (my $sw = new Gtk2::ScrolledWindow);
81 $sw->add (my $h = new Gtk2::PodViewer); 127 $sw->add (my $h = new Gtk2::Ex::PodViewer);
82 128
83 #binmode DATA, ":utf8"; 129 #binmode DATA, ":utf8";
84 $h->load_string (do { local $/; <DATA> }); 130 $h->load_string (do { local $/; <DATA> });
85 } 131 }
86 132
87 $help->show_all; 133 $help->show_all;
88 } else { 134 } else {
89 #$mainwin->show_all; 135 return 0;
90 $schnauzer->handle_key ($key, $state);
91 } 136 }
92 137
93 1; 138 1
94} 139}
95 140
96{ 141{
97 $viewer = new Gtk2::CV::ImageWindow; 142 $viewer = new_viewer;
98 143 $::cur_viewer = $viewer;
99 $viewer->set_title ("CV: Image");
100
101 $viewer->signal_connect (key_press_event => \&std_keys);
102 $viewer->signal_connect (delete_event => sub { main_quit Gtk2 });
103
104 $viewer->signal_connect (button3_press_event => sub {
105 $mainwin->visible
106 ? $mainwin->hide
107 : $mainwin->show_all;
108 1;
109 });
110 144
111 $schnauzer = new_schnauzer; 145 $schnauzer = new_schnauzer;
112 146
113 $mainwin = new Gtk2::Window; 147 $mainwin = new Gtk2::Window;
148 $mainwin->set_role ("main");
114 $mainwin->set_title ("CV"); 149 $mainwin->set_title ("CV");
115 $mainwin->add (my $vbox = new Gtk2::VBox); 150 $mainwin->add (my $vbox = new Gtk2::VBox);
116 $mainwin->signal_connect (delete_event => sub { $mainwin->hide; 1; }); 151 $mainwin->signal_connect (delete_event => sub { $mainwin->hide; 1 });
117 152
118 $vbox->add ($schnauzer); 153 $vbox->add ($schnauzer);
119 $vbox->pack_end (my $frame = new Gtk2::Frame, 0, 0, 0); 154 $vbox->pack_end (my $frame = new Gtk2::Frame, 0, 0, 0);
120 $frame->add (my $hbox = new Gtk2::HBox 0, 0); 155 $frame->add (my $hbox = new Gtk2::HBox 0, 0);
121 $hbox->pack_start ((new Gtk2::Label "Info"), 0, 0, 0); 156 $hbox->pack_start ((new Gtk2::Label "Info: "), 0, 0, 0);
122 $hbox->pack_start (($info = new Gtk2::Label), 1, 1, 0); 157 $hbox->pack_end (my $labelwindow = new Gtk2::EventBox, 1, 1, 0);
123 $info->set (wrap => 1); 158 $labelwindow->add ($info = new Gtk2::Label);
159 $labelwindow->signal_connect_after (size_request => sub { $_[1]->width (0); 0 });
160 $info->set (selectable => 1, xalign => 0, justify => "left");
124 161
125 $schnauzer->set_geometry_hints; 162 $schnauzer->set_geometry_hints;
126} 163}
127 164
128if (@ARGV) { 165if (@ARGV) {
129 $schnauzer->set_paths ([map Glib::filename_to_unicode $_, @ARGV]); 166 my $show_first = sub {
130 $schnauzer->show_all; 167 $schnauzer->show_all;
131 $schnauzer->handle_key ($Gtk2::Gdk::Keysyms{space}, []); 168 $schnauzer->handle_key ($Gtk2::Gdk::Keysyms{space}, []);
169 $viewer->show_all;
170 };
171
172 if (@ARGV == 1 && $ARGV[0] eq "-0r") {
173 local $/;
174 $schnauzer->set_paths ([split /\x00/, <STDIN>], 1, $show_first);
175 } elsif (@ARGV == 1 && -d $ARGV[0]) {
176 $schnauzer->set_dir (shift, $show_first);
177 } else {
178 if ($ARGV[0] eq "-g") {
179 shift @ARGV;
180 @ARGV = map +(File::Glob::bsd_glob $_, File::Glob::GLOB_BRACE | File::Glob::GLOB_QUOTE), @ARGV;
181 }
182 $schnauzer->set_paths ([@ARGV], 1, $show_first);
183 }
132} else { 184} else {
133 $schnauzer->set_dir (File::Spec->curdir); 185 $schnauzer->set_dir (File::Spec->curdir, sub {
134 $mainwin->show_all; 186 $mainwin->show_all;
135 $viewer->show_all; 187 $viewer->show_all;
188 });
136} 189}
137
138$viewer->show_all;
139 190
140main Gtk2; 191main Gtk2;
141 192
193Gtk2::CV::flush_aio;
194
142__DATA__ 195__DATA__
143 196
197=encoding utf-8
198
144=head1 NAME 199=head1 NAME
145 200
146cv - a fast gtk+ image viewer modeled after xv 201cv - a fast gtk+ image viewer loosely modeled after XV
147 202
148=head1 SYNOPSIS 203=head1 SYNOPSIS
149 204
150 cv [file...] 205 cv [file...]
151 206
207=head1 FEATURES
208
209CV is supposed to work similar to the venerable XV image viewer, just
210faster. Why faster?
211
212=over 4
213
214=item * optimized directory scanning algorithm
215
216The directory scanning in CV uses some tricks that - on most modern
217filesystems - makes it possible to detect filetypes faster than stat()'ing
218every file. This makes CV suitable for directories with lots of files
219(10000+).
220
221This algorithm is quite unprecise - it doesn't make a difference between
222files, device nodes, symlinks and the like, and filetype detection is done
223using the file extension only.
224
225On the positive side, it is usually many orders of magnitude faster than
226traditional scanning techniques (good for directories with 10000 or
227100000+ files).
228
229=item * queuing for all time-consuming background tasks
230
231All tasks, such as unlinking files or generating thumbnails, that can be
232done in the background will be done so - no waiting required, even when
233changing directories.
234
235=item * use of asynchronous I/O
236
237CV tries to use asynchronous I/O whereever it makes sense, for example
238while scanning directories, waiting for stat data, unlinking files or
239generating thumbnails. This usually decreases scanning times for large
240directories a bit (especially on RAID devices and over NFS) and makes CV
241much more interactive.
242
243=item * fast image loading
244
245The time span between the user issuing a command and displaying the new
246image should be as small as possible. CV uses optimized (especially
247for JPEG) loading functions and sacrifices some quality (e.g no gamma
248correction, although this might change) to achieve this speed.
249
250=item * fast thumbnail creation
251
252Thumbnail creation uses both CPU and Disk-I/O. CV interleaves both, so
253on modern CPUs, thumbnailing is usually limited by I/O speed. Thumbnail
254creation for JPEGs has been specially optimized and can even take
255advantage of multiple CPUs.
256
257=item * minimum optical clutter
258
259CV has no menus or other user interface elements that take up a lot of
260screen space (or are useful for beginning users). The schnauzer windows
261can also be somewhat crowded.
262
263The point of an image viewer is viewing images, not a nice GUI. This is
264similar to XV's behaviour.
265
266=item * efficient (and hard to learn) user interface
267
268CV uses key combinations. A lot. If you are an experienced XV user, you
269will find most of these keys familiar. If not, CV might be hard to use at
270first, but will be an efficient tool later.
271
272=item * multi-window GUI
273
274CV doesn't force you to use a specific layout, instead it relies on your
275window manager, thus enabling you to chose whatever layout that suits you
276most.
277
278=item * i18n'ed filename handling throughout
279
280As long as glib can recognize your filename encoding (either UTF-8 or
281locale-specific, depending on the setting of G_BROKEN_FILENAMES) and you
282have the relevant fonts, CV will display your filenames correctly.
283
284=item * extensible through plug-ins
285
286I have weird plug-ins that access remote databases to find a
287directory. This is not likely to be of any use to other people. Likewise,
288others might have weird requirements I cannot dream of.
289
290=item * filename clustering
291
292Among the standard plug-ins is a filename clustering plug-in, that (in
293case of tens of thousands images in one directory) might be able to
294cluster similar names together.
295
296=back
297
152=head1 DESCRIPTION 298=head1 DESCRIPTION
153 299
154None yet.
155
156=head2 THE IMAGE WINDOW 300=head2 THE IMAGE WINDOW
157 301
158You can use the following keys in the image window: 302You can use the following keys in the image window:
159 303
160 q quit the program 304 q quit the program
161 < half the image size 305 < half the image size
162 > double the image size 306 > double the image size
163 , shrink the image by 10% 307 , shrink the image by 10%
164 . enlarge the image by 10% 308 . enlarge the image by 10%
165 n reset to normal size 309 n reset to normal size
166 m maximize to screensize 310 m maximize to screensize
167 M maxime to screensize, respecting image aspect 311 M maximize to screensize, respecting image aspect
168 ctrl-m toggle maxpect-always mode 312 ctrl-m toggle maxpect-always mode
313 ctrl-sift-m toggle using current image size as max image size
169 u uncrop 314 u uncrop
170 r set scaling mode to 'nearest' (fastest) 315 r set scaling mode to 'nearest' (fastest)
171 s set scaling mode to 'bilinear' (default) 316 s set scaling mode to 'bilinear' (default)
172 S set scaling mode to 'hyper' (slowest) 317 shift-s set scaling mode to 'hyper' (slowest)
173 t rotate clockwise 90° 318 t rotate clockwise 90°
174 T rotate counterclockwise° 319 T rotate counterclockwise°
320 a apply all rotations loslessly to a jpeg file (using exiftran)
175 ctrl-v open a new visual schnauzer window for the current dir 321 ctrl-v open a new visual schnauzer window for the current dir
176 ctrl-s rescan visual schnauzer files for updates/deletes etc. 322 ctrl-c clone the current image window
177 ctrl-e run an editor ($CV_EDITOR or "gimp") on the current image. 323 ctrl-e run an editor ($CV_EDITOR or "gimp") on the current image
324 ctrl-p fire up the print dialog
325 escape cancel a crop action
178 326
179And when playing movies, these additional keys are active: 327And when playing movies, these additional keys are active:
180 328
181 left rewind by 10 seconds 329 left rewind by 10 seconds
182 right forward by 10 seconds 330 right forward by 10 seconds
183 down rewind by 60 seconds 331 down rewind by 60 seconds
184 up forward by 60 seconds 332 up forward by 60 seconds
185 pg_up rewind by 600 seconds 333 pg_up rewind by 600 seconds
186 pg_down forward by 600 seconds 334 pg_down forward by 600 seconds
187 o toggle on-screen display 335 o toggle on-screen display
188 p pause/unpause 336 p pause/unpause
189 escape stop playing 337 escape stop playing
190 9 turn volume down 338 9 turn volume down
191 0 turn volume up 339 0 turn volume up
192 340
193The following keys are redirected to the default visual schnauzer window: 341Any other keys will be sent to the default schnauzer window, which can be
342toggled on and off by right-clicking into the image window.
194 343
195 space next image 344Left-clicking into the image window will let you crop the image (usually
196 backspace last image 345to zoom into large images that CV scales down).
197 346
198=head2 THE VISUAL SCHNAUZER 347=head2 THE VISUAL SCHNAUZER
199 348
349Any image-loading action in a schnauzer window acts on the
350"last-recently-activated" imagewindow, which currently is simply the last
351image window that received a keypress.
352
200You can use the following keys in the schnauzer window: 353You can use the following keys in the schnauzer window:
201 354
355 ctrl-space,
202 space move to and display next image 356 space move to and display next image
357 ctrl-backspace,
203 backspace move to and display previous image 358 backspace move to and display previous image
359 ctrl-return,
204 return display selected picture 360 return display selected picture, or enter directory
205 361
206 cursor keys move selection 362 cursor keys move selection
207 page-up move one page up 363 page-up move one page up
208 page-down move one page down 364 page-down move one page down
209 home move to first file 365 home move to first file
210 end move to last file 366 end move to last file
211 367
368 ctrl-a select all files
369 ctrl-shift-a select all files currently displayed in the schnauzer window
212 ctrl-d delete selected files WITHOUT ASKING AGAIN 370 ctrl-d delete selected files WITHOUT ASKING AGAIN
213 ctrl-g generate icons for the selected files 371 ctrl-g force generation of thumbnais for the selected files
372 ctrl-s rescan current direcory or files updates/deletes etc.
214 ctrl-u update selected (or all) icons if neccessary 373 ctrl-u update selected (or all) icons if neccessary
215 ctrl-a select all files 374 ctrl-- unselected thumbnailed images
375 ctrl-+ keep only thumbnailed images, deselect others
376
377 ^ go to parent directory (caret).
378
379 0-9,
380 a-z find the first filename beginning with this letter
381
382Right-clicking into the schnauzer window displays a pop-up menu with
383additional actions.
384
385=head3 SELECTION
386
387You can select entries in the Schnauzer in a variety of ways:
388
389=over 4
390
391=item Keyboard
392
393Moving the cursor with the keyboard will first deselect all files and then
394select the file you moved to.
395
396=item Clicking
397
398Clicking on an entry will select the one you clicked and deselect all
399others.
400
401=item Shift-Clicking
402
403Shift-clicking will toggle the selection on the entry under the mouse.
404
405=item Dragging
406
407Dragging will select all entries between the one selected when pushing the
408button and the one selected when releasing the button. If you move above
409or below the schnauzer area while drag-selecting, the schnauzer will move
410up/down one row twice per second. In addition, horizontal mouse movement
411acts as a kind of invisible horizontal scrollbar.
412
413=item Hint: double-click works while click-selecting
414
415You can double-click any image while click-selecting to display it
416without stopping the selection process. This will act as if you normally
417double-clicked the image to display it, and will toggle the selection
418twice, resulting in no change.
419
420=back
421
422=head1 FILES
423
424When starting, CV runs the F<.cvrc> file in your F<$HOME> directory as if
425it were a perl script. in that, you will mostly load plug-ins.
426
427Example:
428
429 system "fping -q -t 10 ether"
430 or require "/fs/cv/cvplugin.pl";
431
432This will load a plug-in, but only if the machine I<ether> is reachable
433(supposedly the plug-in is networked in some way :).
216 434
217=head1 ENVIRONMENT 435=head1 ENVIRONMENT
218 436
219=over 4 437=over 4
220 438
221=item CV_EDITOR 439=item CV_EDITOR
222 440
223The program that gets executed when the user presses C<CTRL-e> in the 441The program that gets executed when the user presses C<CTRL-e> in the
224Schnauzer or image window. The default is C<gimp>. 442Schnauzer or image window. The default is C<gimp>.
225 443
444=item CV_AUDIO_PLAYER
445
446Program used to play all sorts of audio (wav, aif, mp3, ogg...), default "play".
447Will be called like C<< $CV_AUDIO_PLAYER -- <path> >>.
448
226=item CV_PRINT_DESTINATION 449=item CV_PRINT_DESTINATION
227 450
228The default (perl-style) destination to use in the print dialog. 451The default (perl-style) destination to use in the print dialog.
229 452
230=item CV_TRASHCAN 453=item CV_TRASHCAN
234 457
235=back 458=back
236 459
237=head1 SECURITY CONSIDERATIONS 460=head1 SECURITY CONSIDERATIONS
238 461
239CV uses Pixbuf to load images. Pixbuf is not considered safe for this 462CV uses Pixbuf to load non-JPEG images. Pixbuf is not considered safe for
240purpose, though (from the gtk-2.2 release notes): 463this purpose, though (from the gtk-2.2 release notes):
241 464
242"While efforts have been made to make gdk-pixbuf robust against invalid 465"While efforts have been made to make gdk-pixbuf robust against invalid
243images, using gdk-pixbuf to load untrusted data is not recommended, due to 466images, using gdk-pixbuf to load untrusted data is not recommended, due to
244the likelyhood that there are additional problems where an invalid image 467the likelyhood that there are additional problems where an invalid image
245could cause gdk-pixbuf to crash or worse." 468could cause gdk-pixbuf to crash or worse."
246 469
247=head1 BUGS/TODO 470=head1 BUGS/TODO
248 471
472 Lots of functionality is missing.
473
249 Pixbuf doesn't honor G_BROKEN_FILENAMES, so accessing files with names 474 Pixbuf doesn't always honor G_BROKEN_FILENAMES, so accessing files with
250 incompatible with utf-8 fails. 475 names incompatible with utf-8 might fail.
251 476
252 rotate on disk 477 rotate on disk
253 print
254 lots of ui issues 478 lots of ui issues
255 save(?) 479 save(?)
256 preferences 480 preferences
257 ctrl-u in schnauzer
258 shift-cursor in schnauzer
259 481
260=head1 AUTHOR 482=head1 AUTHOR
261 483
262Marc Lehmann <cv@plan9.de>. 484Marc Lehmann <cv@plan9.de>.
263 485

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines