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

Comparing CV/bin/cv (file contents):
Revision 1.11 by root, Wed Nov 5 01:29:47 2003 UTC vs.
Revision 1.23 by root, Wed Nov 12 00:59:02 2003 UTC

1#!/opt/bin/perl 1#!/opt/bin/perl
2
3use Gtk2 -init;
4use Gtk2::Gdk::Keysyms;
5
6use Gtk2::CV::ImageWindow;
7use Gtk2::CV::Schnauzer;
8
9use Gtk2::CV;
10
11Gtk2::Rc->parse (Gtk2::CV::find_rcfile "gtkrc");
12
13use File::Spec;
14
15my $mainwin;
16my $viewer;
17my $schnauzer;
18my $info;
19my $help;
20
21sub new_schnauzer {
22 my $s = new Gtk2::CV::Schnauzer;
23
24 $s->signal_connect_after (key_press_event => \&std_keys);
25 $s->signal_connect (activate => sub {
26 my $label = sprintf "%s (%d)",
27 (File::Spec->splitpath ($_[1]))[2],
28 -s $_[1];
29 $info->set_label ($label);
30 $viewer->load_image ($_[1]);
31 });
32
33 $s;
34}
35
36sub std_keys {
37 my $key = $_[1]->keyval;
38 my $state = $_[1]->state;
39
40 my $ctrl = $state * "control-mask";
41
42 if ($key == $Gtk2::Gdk::Keysyms{q}) {
43 main_quit Gtk2;
44 } elsif ($ctrl && $key == $Gtk2::Gdk::Keysyms{v}) {
45 my $w = new Gtk2::Window;
46 $w->add (my $s = new_schnauzer);
47 $s->set_dir (File::Spec->curdir);
48 $w->show_all;
49 } elsif ($ctrl && $key == $Gtk2::Gdk::Keysyms{h}) {
50 unless ($help) {
51 require Gtk2::PodViewer;
52
53 $help = new Gtk2::Window;
54 $help->set_title ("CV Help");
55 $help->set_default_size (500, 300);
56 $help->signal_connect (delete_event => sub { $help->hide; 1 });
57
58 $help->add (my $sw = new Gtk2::ScrolledWindow);
59 $sw->add (my $h = new Gtk2::PodViewer);
60
61 #binmode DATA, ":utf8";
62 $h->load_string (do { local $/; <DATA> });
63 }
64
65 $help->show_all;
66 } else {
67 #$mainwin->show_all;
68 $schnauzer->handle_key ($key, $state);
69 }
70
71 1;
72}
73
74{
75 $viewer = new Gtk2::CV::ImageWindow;
76
77 $viewer->set_title ("CV: Image");
78
79 $viewer->signal_connect (key_press_event => \&std_keys);
80 $viewer->signal_connect (delete_event => sub { main_quit Gtk2 });
81
82 $viewer->signal_connect (button3_press_event => sub {
83 $mainwin->visible
84 ? $mainwin->hide
85 : $mainwin->show_all;
86 1;
87 });
88
89 $schnauzer = new_schnauzer;
90
91 $mainwin = new Gtk2::Window;
92 $mainwin->set_title ("CV");
93 $mainwin->add (my $vbox = new Gtk2::VBox);
94 $mainwin->signal_connect (delete_event => sub { $mainwin->hide; 1; });
95
96 $vbox->add ($schnauzer);
97 $vbox->pack_end (my $frame = new Gtk2::Frame, 0, 0, 0);
98 $frame->add (my $hbox = new Gtk2::HBox 0, 0);
99 $hbox->pack_start ((new Gtk2::Label "Info"), 0, 0, 0);
100 $hbox->pack_start (($info = new Gtk2::Label), 1, 1, 0);
101}
102
103if (@ARGV) {
104 $schnauzer->set_paths (\@ARGV);
105 $schnauzer->handle_key ($Gtk2::Gdk::Keysyms{space}, []);
106} else {
107 $schnauzer->set_dir (File::Spec->curdir);
108 $mainwin->show_all;
109}
110
111$viewer->show_all;
112
113main Gtk2;
114
115__DATA__
2 116
3=head1 NAME 117=head1 NAME
4 118
5cv - a fast gtk+ image viewer modeled after xv 119cv - a fast gtk+ image viewer modeled after xv
6 120
52 end move to last file 166 end move to last file
53 167
54 ctrl-g generate icons for the selected files 168 ctrl-g generate icons for the selected files
55 ctrl-d delete selected files WITHOUT ASKING AGAIN 169 ctrl-d delete selected files WITHOUT ASKING AGAIN
56 170
171=head1 SECURITY CONSIDERATIONS
172
173CV uses Pixbuf to load images. Pixbuf is not considered safe for this
174purpose, though (from the gtk-2.2 release notes):
175
176"While efforts have been made to make gdk-pixbuf robust against invalid
177images, using gdk-pixbuf to load untrusted data is not recommended, due to
178the likelyhood that there are additional problems where an invalid image
179could cause gdk-pixbuf to crash or worse."
180
57=head1 BUGS/TODO 181=head1 BUGS/TODO
182
183 Pixbuf doesn't honor G_BROKEN_FILENAMES, so accessing files with names
184 incompatible with utf-8 fails.
58 185
59 rotate on disk 186 rotate on disk
60 print 187 print
61 lots of ui issues 188 lots of ui issues
62 save(?) 189 save(?)
63 preferences 190 preferences
191 ctrl-u in schnauzer
192 shift-cursor in schnauzer
64 193
65=head1 AUTHOR 194=head1 AUTHOR
66 195
67Marc Lehmann <cv@plan9.de>. 196Marc Lehmann <cv@plan9.de>.
68 197
69=cut 198=cut
70 199
71use Gtk2 -init;
72use Gtk2::Gdk::Keysyms;
73
74use Gtk2::CV::ImageWindow;
75use Gtk2::CV::Schnauzer;
76
77my $viewer;
78my $schnauzer;
79
80sub new_schnauzer {
81 my $w = new Gtk2::Window;
82 $w->add (my $s = new Gtk2::CV::Schnauzer);
83
84 $s->signal_connect (activate => sub { $viewer->load_image ($_[1]) });
85 $s->signal_connect_after (key_press_event => \&std_keys);
86
87 $s->set_dir (".");
88 $w->show_all;
89
90 $s;
91}
92
93sub std_keys {
94 my $key = $_[1]->keyval;
95 my $state = $_[1]->state;
96
97 my $ctrl = grep $_ eq "control-mask", @$state;
98
99 if ($key == $Gtk2::Gdk::Keysyms{q}) {
100 main_quit Gtk2;
101 } elsif ($ctrl && $key == $Gtk2::Gdk::Keysyms{v}) {
102 new_schnauzer;
103 } else {
104 $schnauzer->handle_key ($key, $state);
105 }
106
107 1;
108}
109
110$viewer = new Gtk2::CV::ImageWindow;
111$viewer->signal_connect (key_press_event => \&std_keys);
112$viewer->signal_connect (delete_event => sub { main_quit Gtk2 });
113
114$schnauzer = new_schnauzer;
115
116if (@ARGV) {
117 $viewer->load_image ($ARGV[0]);
118
119 if (@ARGV > 1) {
120 $schnauzer->set_paths (\@ARGV);
121 }
122}
123
124$viewer->show_all;
125
126main Gtk2;
127
128

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines