3 # A GTK based console program
5 # usage: gtkconsole [<callsign>] [<host> <port>]
7 # Copyright (c) 2001-6 Dirk Koopman G1TLH
14 our $VERSION = '$Revision$';
15 $VERSION =~ s|[^\d\.]+||g;
19 # search local then perl directories
21 # root of directory tree for this system
23 $root = $ENV{'DXSPIDER_ROOT'} if $ENV{'DXSPIDER_ROOT'};
35 use vars qw(@modules $font);
37 @modules = (); # is the list of modules that need init calling
38 # on them. It is set up by each 'use'ed module
39 # that has Gtk stuff in it
42 our @month = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
45 our $main; # the main screen
46 our $scr_width; # calculated screen dimensions
48 our ($dx, $cmd, $ann, $wcy, $wwv); # scrolling list windows
49 our $bot; # the cmd entry window
50 our $date; # the current date
52 # read in the user data
53 our $userfn = "$ENV{HOME}/.gtkconsole_data";
54 our $user = read_user_data();
61 # read in gtkconsole file
64 Gtk2::Rc->set_default_files("$root/gtkconsole/gtkconsolerc", "$ENV{HOME}/.gtkconsolerc", ".gtkconsolerc");
65 Gtk2::Rc->reparse_all;
67 # sort out a callsign, host and port, looking in order
69 # 2. any defaults in the user data;
70 # 3. poke about in any spider tree that we can find
74 $call = uc shift @ARGV;
75 $host = shift @ARGV if @ARGV;
76 $port = shift @ARGV if @ARGV;
79 unless ($call && $host) {
80 my $node = $user->{clusters}->{$user->{node}};
82 if ($node->{call} || $user->{call}) {
83 $call = $node->{call} || $user->{call};
84 $host = $node->{passwd};
85 $host = $node->{host};
86 $port = $node->{port};
90 unless ($call && $host) {
91 if (-e "$root/local/DXVars.pm") {
92 require "$root/local/DXVars.pm";
93 $call = $main::myalias;
94 $call = $main::myalias; # for the warning
96 if (-e "$root/local/Listeners.pm") {
97 require "$root/local/Listeners.pm";
98 $host = $main::listen->[0]->[0];
99 $port = $main::listen->[0]->[1];
104 $host = $user->{clusters}->{$user->{node}}->{host};
105 $port = $user->{clusters}->{$user->{node}}->{port};
111 die "You need a callsign ($call), a hostname($host) and a port($port) to proceed" unless $call && $host;
117 gtk_create_main_screen();
119 $main->set_title("gtkconsole $VERSION - DXSpider Console - $call \@ $host:$port");
121 # connect and send stuff
122 my $sock = IO::Socket::INET->new(PeerAddr=>$host, PeerPort=>$port);
123 die "Cannot connect to $/$port ($!)\n" unless $sock;
125 sendmsg($passwd) if $passwd;
127 sendmsg('set/page 500');
128 sendmsg('set/nobeep');
130 my $sock_helper = Gtk2::Helper->add_watch($sock->fileno, 'in', \&tophandler, $sock);
144 $_[0]->set_text(cldatetime(time));
150 my ($self, $data) = @_;
151 my $msg = $self->get_text;
162 my ($fd, $condx, $socket) = @_;
164 my $offset = length $rbuf;
165 my $l = sysread($socket, $rbuf, 1024, $offset);
168 while ($rbuf =~ s/^([^\015\012]*)\015?\012//) {
186 # this is truely evil and I bet there is a better way...
189 if ($line =~ /^'\w{2,4}',/) {
190 $list = eval qq([$line]);
192 $list = ['cmd', $line];
196 my $cmd = shift @$list;
197 my $handle = "handle_$cmd";
198 if (__PACKAGE__->can($handle)) {
199 __PACKAGE__->$handle($list);
201 unshift @$list, $cmd;
202 __PACKAGE__->handle_def($list);
211 my ($t, $ts) = (time, '');
213 $s = ref $ref ? join ', ',@$ref : $ref;
215 if (($cmd->{lasttime}||0) != $t) {
217 $cmd->{lasttime} = $t;
221 $cmd->add_data([$ts, $s]);
228 my ($t, $ts) = (time, '');
230 $s = ref $ref ? join(', ', @$ref) : $ref;
231 if (($cmd->{lasttime}||0) != $t) {
233 $cmd->{lasttime} = $t;
235 $cmd->add_data([$ts, $s]);
242 my ($t, $ts) = (time, '');
244 if (($dx->{lasttime}||0) != $t) {
246 $dx->{lasttime} = $t;
248 $dx->add_data([$ts, @$ref[0,1,15,3,4,16], stim($ref->[2]) ]);
256 my ($t, $ts) = (time, '');
258 $s = ref $ref ? join ', ',@$ref : $ref;
260 if (($ann->{lasttime}||0) != $t) {
262 $ann->{lasttime} = $t;
266 $ann->add_data([$ts, @$ref[3,1,2]]);
274 $s = ref $ref ? join ', ',@$ref : $ref;
278 $wcy->add_data([tim(), @$ref[10,4,5,3,6,2,7,8,9,1] ]);
286 $s = ref $ref ? join ', ',@$ref : $ref;
289 $wwv->add_data([tim(), @$ref[6,2,3,4,5,1] ]);
301 $sock->print("$msg\n");
306 my $t = shift || time;
307 return sprintf "%02d:%02d:%02d", (gmtime($t))[2,1,0];
312 my $t = shift || time;
313 return sprintf "%02d:%02d", (gmtime($t))[2,1];
316 # get a zulu time in cluster format (2300Z)
320 $t = defined $t ? $t : time;
322 my ($sec,$min,$hour) = $dst ? localtime($t): gmtime($t);
323 my $buf = sprintf "%02d%02d%s", $hour, $min, ($dst) ? '' : 'Z';
327 # get a cluster format date (23-Jun-1998)
331 $t = defined $t ? $t : time;
333 my ($sec,$min,$hour,$mday,$mon,$year) = $dst ? localtime($t) : gmtime($t);
335 my $buf = sprintf "%2d-%s-%04d", $mday, $month[$mon], $year;
339 # return a cluster style date time
344 my $date = cldate($t, $dst);
345 my $time = ztime($t, $dst);
346 return "$date $time";
354 my $fh = new IO::File $userfn;
364 print "$userfn missing or unreadable, starting afresh!\n";
368 'GB7DJK' => {host => 'gb7djk.dxcluster.net', port => 7300},
369 'WR3D' => {host => 'wr3d.dxcluster.net', port => 7300},
370 'GB7BAA' => {host => 'gb7baa.dxcluster.net', port => 7300},
383 my $fh = new IO::File ">$userfn";
385 my $dd = new Data::Dumper([ $u ]);
389 $fh->print($dd->Dumpxs);
396 sub def_menu_callback
401 sub gtk_create_main_screen
403 $main = new Gtk2::Window('toplevel');
404 my $scr = $main->get_screen;
405 $scr_width = int ($scr->get_width > 1280 ? 1280 : $scr->get_width) * 0.99;
406 $scr_height = int $scr->get_height * 0.5;
407 $main->set_default_size($scr_width, $scr_height);
408 $main->signal_connect('delete_event', sub { Gtk2->main_quit; });
411 my $vbox = new Gtk2::VBox(0, 1);
416 item_type => '<Branch>',
419 callback => sub { Gtk2->main_quit; },
420 callback_action => 1,
421 accelerator => '<ctrl>Q',
427 item_type => '<Branch>',
430 callback_action => 9,
437 my $menu = Gtk2::SimpleMenu->new(menu_tree => $menutree, default_callback => \&def_menu_callback, user_data => $user);
438 $vbox->pack_start($menu->{widget}, 0, 1, 0);
441 # a paned hbox is packed as the bottom of the vbox
442 my $bhpane = Gtk2::HPaned->new;
443 $vbox->pack_end($bhpane, 1, 1, 0);
445 # now create the lh and rh panes
446 my $lhvpane = Gtk2::VPaned->new;
447 my $rhvpane = Gtk2::VPaned->new;
448 $bhpane->pack1($lhvpane, 1, 0);
449 $bhpane->pack2($rhvpane, 1, 0);
455 $ann = Screen::List->new(fields =>[
459 Announcement => 'ttlesslong',
462 frame => 'Announcements',
463 size => [$scr_width * 0.45, $scr_height * 0.33],
466 $lhvpane->pack1($ann->widget, 1, 0);
469 my $lhvbox = Gtk2::VBox->new(0, 1);
470 $cmd = Screen::List->new(fields => [
472 Information => 'ttlong',
474 size => [$scr_width * 0.45, $scr_height * 0.66],
476 $lhvbox->pack_start($cmd->widget, 1, 1, 0);
479 # callsign and current date and time
480 my $hbox = new Gtk2::HBox;
481 my $calllabel = new Gtk2::Label($call);
482 my $date = new Gtk2::Label(cldatetime(time));
483 $date->{tick} = Glib::Timeout->add(1000, \&updatetime, $date);
484 $hbox->pack_start( $calllabel, 0, 1, 0 );
485 $hbox->pack_end($date, 0, 1, 0);
486 $lhvbox->pack_start($hbox, 0, 1, 0);
487 $lhvbox->pack_start(Gtk2::HSeparator->new, 0, 1, 0);
490 $bot = new Gtk2::Entry;
491 $bot->set_editable(1);
492 $bot->signal_connect('activate', \&bothandler);
493 $bot->can_default(1);
494 $lhvbox->pack_end($bot, 0, 1, 0);
495 $lhvpane->pack2($lhvbox, 1, 0);
503 $dx = Screen::List->new(fields => [
508 'Remarks' => 'ttshort',
513 policy => [qw(never automatic)],
517 size => [$scr_width * 0.45, $scr_height * 0.45],
519 $rhvpane->pack1($dx->widget, 1, 0);
522 my $rhvbox = Gtk2::VBox->new(0, 1);
523 $wwv = Screen::List->new( fields =>[
529 Remarks => 'ttshort',
533 policy => ['never', 'automatic'],
536 $rhvbox->pack_start($wwv->widget, 1, 1, 0);
539 $wcy = Screen::List->new(fields => [
553 policy => ['never', 'automatic'],
557 $rhvbox->pack_start($wcy->widget, 1, 1, 0);
558 $rhvbox->set_size_request($scr_width * 0.45, $scr_height * 0.33);
559 $rhvpane->pack2($rhvbox, 1, 0);