ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/CV/bin/cv
Revision: 1.83
Committed: Mon Feb 20 01:58:56 2012 UTC (14 years, 7 months ago) by root
Branch: MAIN
Changes since 1.82: +1 -1 lines
Log Message:
*** empty log message ***

File Contents

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