3 # A GTK based console program
5 # Copyright (c) 2001 Dirk Koopman G1TLH
10 # search local then perl directories
12 # root of directory tree for this system
14 $root = $ENV{'DXSPIDER_ROOT'} if $ENV{'DXSPIDER_ROOT'};
16 unshift @INC, "$root/perl"; # this IS the right way round!
17 unshift @INC, "$root/gtkconsole";
18 unshift @INC, "$root/local";
25 use vars qw(@modules $font);
27 @modules = (); # is the list of modules that need init calling
28 # on them. It is set up by each 'use'ed module
29 # that has Gtk stuff in it
30 $font = Gtk::Gdk::Font->load("-misc-fixed-medium-r-normal-*-*-130-*-*-c-*-koi8-r");
41 my $call = uc shift @ARGV if @ARGV;
42 $call = uc $main::myalias unless $call;
43 my ($scall, $ssid) = split /-/, $call;
44 $ssid = undef unless $ssid && $ssid =~ /^\d+$/;
46 $ssid = 15 if $ssid > 15;
47 $call = "$scall-$ssid";
50 die "You cannot connect as your cluster callsign ($main::mycall)\n" if $call eq $main::mycall;
53 my $sock = IO::Socket::INET->new(PeerAddr=>$main::clusteraddr, PeerPort=>$main::clusterport);
54 die "Cannot connect to $main::clusteraddr/$main::clusterport ($!)\n" unless $sock;
55 sendmsg('A', 'local');
57 sendmsg('I', 'set/page 500');
58 sendmsg('I', 'set/nobeep');
66 my $main = new Gtk::Window('toplevel');
67 $main->set_default_size(600, 600);
68 $main->set_policy(0, 1, 0);
69 $main->signal_connect('destroy', sub { Gtk->exit(0); });
70 $main->signal_connect('delete_event', sub { Gtk->exit(0); });
71 $main->set_title("gtkconsole - The DXSpider Console - $call");
74 my $vbox = new Gtk::VBox(0, 1);
75 $vbox->border_width(1);
80 {path => '/_File', type => '<Branch>'},
81 {path => '/_File/Quit', callback => sub {Gtk->exit(0)}},
82 {path => '/_Help', type => '<LastBranch>'},
83 {path => '/_Help/About'},
85 my $accel = new Gtk::AccelGroup();
86 my $itemf = new Gtk::ItemFactory('Gtk::MenuBar', '<main>', $accel);
87 $itemf->create_items(@menu);
88 $main->add_accel_group($accel);
89 my $menu = $itemf->get_widget('<main>');
90 $vbox->pack_start($menu, 0, 1, 0);
94 my $top = new Text(1);
95 my $toplist = $top->text;
96 $toplist->set_editable(0);
97 $toplist->sensitive(0);
99 # add the handler for incoming messages from the node
100 my $tophandler = Gtk::Gdk->input_add($sock->fileno, ['read'], \&tophandler, $sock);
101 my $rbuf = ""; # used in handler
103 #$toplist->{signalid} = $toplist->signal_connect(insert_text => \&doinsert, $toplist);
104 #$bot->{signalid} = $bot->signal_connect(insert_text => \&botinsert, $bot);
105 $vbox->pack_start($top, 1, 1, 0);
109 my $bot = new Gtk::Entry;
110 my $style = $toplist->style;
111 $style->font($main::font);
112 $bot->set_style($style);
113 $bot->set_editable(1);
114 $bot->signal_connect('activate', \&bothandler);
115 $bot->can_default(1);
120 my $hbox = new Gtk::HBox;
123 # callsign and current date and time
124 my $calllabel = new Gtk::Label($call);
125 my $date = new Gtk::Label(cldatetime(time));
126 Gtk->timeout_add(1000, \&updatetime);
130 $hbox->pack_start( $calllabel, 0, 1, 0 );
131 $hbox->pack_end($date, 0, 1, 0);
134 $vbox->pack_start($hbox, 0, 1, 0);
136 # nice little separator
137 my $separator = new Gtk::HSeparator();
138 $vbox->pack_start( $separator, 0, 1, 0 );
140 $vbox->pack_start($bot, 0, 1, 0);
153 $date->set_text(cldatetime(time));
158 my ($self, $text) = @_;
160 # we temporarily block this handler to avoid recursion
161 $self->signal_handler_block($self->{signalid});
162 my $pos = $self->insert($self->{font}, $toplist->style->black, $toplist->style->white, $text);
163 $self->signal_handler_unblock($self->{signalid});
165 # we already inserted the text if it was valid: no need
166 # for the self to process this signal emission
167 $self->signal_emit_stop_by_name('insert-text');
173 my ($self, $data) = @_;
174 my $msg = $self->get_text;
183 my ($socket, $fd, $flags) = @_;
184 if ($flags->{read}) {
185 my $offset = length $rbuf;
186 my $l = sysread($socket, $rbuf, 1024, $offset);
190 while ($rbuf =~ s/^([^\015\012]*)\015?\012//) {
192 $msg =~ s/\%([0-9A-F][0-9A-F])/chr(hex($1))/eg;
193 $msg =~ s/[\x00-\x08\x0a-\x19\x1b-\x1f\x80-\x9f]/./g; # immutable CSI sequence + control characters
194 $toplist->freeze unless $freeze++;
199 $toplist->vadj->set_value($toplist->vadj->upper);
200 $toplist->vadj->value_changed;
214 my ($sort, $call, $line) = $msg =~ /^(\w)([^\|]+)\|(.*)$/;
216 $toplist->insert($toplist->{font}, undef, undef, "$line\n");
217 } elsif ($sort eq 'X') {
218 $toplist->insert($toplist->{font}, undef, undef, "$line\n");
219 } elsif ($sort eq 'T') {
220 $toplist->insert($toplist->{font}, undef, undef, "$line\n");
221 } elsif ($sort eq 'Y') {
222 $toplist->insert($toplist->{font}, undef, undef, "$line\n");
223 } elsif ($sort eq 'V') {
224 $toplist->insert($toplist->{font}, undef, undef, "$line\n");
225 } elsif ($sort eq 'N') {
226 $toplist->insert($toplist->{font}, undef, undef, "$line\n");
227 } elsif ($sort eq 'W') {
228 $toplist->insert($toplist->{font}, undef, undef, "$line\n");
229 } elsif ($sort eq 'Z') {
246 my ($let, $msg) = @_;
247 $msg =~ s/([\%\x00-\x1f\x7f-\xff])/sprintf("%%%02X", ord($1))/eg;
248 $sock->print("$let$call|$msg\n");