3 # A GTK based console program
5 # usage: gtkconsole [<callsign>] [<host> <port>]
7 # Copyright (c) 2006-2007 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, $chat); # scrolling list windows
49 our $bot; # the cmd entry window
50 our $date; # the current date
53 our $annwin; # the announcement window handle
54 our $dxwin; # the dx spot window handle
55 our $wwvwin; # wwv window handle
56 our $wcywin; # wcy window handle
57 our $chatwin; # chat window handle
59 require "$root/local/DXVars.pm" if -e "$root/local/DXVars.pm";
61 # read in the user data
62 our $userfn = "$ENV{HOME}/.gtkconsole_data";
63 our $user = read_user_data();
66 our $host = 'localhost';
70 # read in gtkconsole file
73 Gtk2::Rc->set_default_files("$root/gtkconsole/gtkconsolerc", "$ENV{HOME}/.gtkconsolerc", ".gtkconsolerc");
74 Gtk2::Rc->reparse_all;
76 # sort out a callsign, host and port, looking in order
78 # 2. any defaults in the user data;
79 # 3. poke about in any spider tree that we can find
83 $call = uc shift @ARGV;
84 $host = shift @ARGV if @ARGV;
85 $port = shift @ARGV if @ARGV;
88 unless ($call && $host) {
89 my $node = $user->{clusters}->{$user->{node}};
91 if ($node->{call} || $user->{call}) {
92 $call = $node->{call} || $user->{call} || $main::myalias;
93 $host = $node->{passwd};
94 $host = $node->{host};
95 $port = $node->{port};
99 unless ($call && $host) {
100 if (-e "$root/local/Listeners.pm") {
101 require "$root/local/Listeners.pm";
102 $host = $main::listen->[0]->[0];
103 $port = $main::listen->[0]->[1];
104 $host ||= '127.0.0.1';
105 $host = "127.0.0.1" if $host eq '0.0.0.0';
111 $host = $user->{clusters}->{$user->{node}}->{host};
112 $port = $user->{clusters}->{$user->{node}}->{port};
118 die "You need a callsign ($call), a hostname($host) and a port($port) to proceed" unless $call && $host;
124 gtk_create_main_screen();
126 $main->set_title("gtkconsole $VERSION - DXSpider Console - $call \@ $host:$port");
128 # connect and send stuff
129 my $sock = IO::Socket::INET->new(PeerAddr=>$host, PeerPort=>$port);
130 die "Cannot connect to $/$port ($!)\n" unless $sock;
132 sendmsg($passwd) if $passwd;
134 sendmsg('set/page 500');
135 sendmsg('set/nobeep');
137 my $sock_helper = Gtk2::Helper->add_watch($sock->fileno, 'in', \&tophandler, $sock);
151 $_[0]->set_text(cldatetime(time));
157 my ($self, $data) = @_;
158 my $msg = $self->get_text;
169 my ($fd, $condx, $socket) = @_;
171 my $offset = defined $rbuf ? length $rbuf : 0;
172 my $l = sysread($socket, $rbuf, 1024, $offset);
175 while ($rbuf =~ s/^([^\015\012]*)\015?\012//) {
193 # this is truely evil and I bet there is a better way...
196 if ($line =~ /^'\w{2,4}',/) {
197 $list = eval qq([$line]);
199 $list = ['cmd', $line];
203 my $cmd = shift @$list;
204 my $handle = "handle_$cmd";
205 if (__PACKAGE__->can($handle)) {
206 __PACKAGE__->$handle($list);
208 unshift @$list, $cmd;
209 __PACKAGE__->handle_def($list);
218 my ($t, $ts) = (time, '');
220 $s = ref $ref ? join ', ',@$ref : $ref;
222 if (($cmd->{lasttime}||0) != $t) {
224 $cmd->{lasttime} = $t;
228 $cmd->add_data([$ts, $s]);
235 my ($t, $ts) = (time, '');
237 $s = ref $ref ? join(', ', @$ref) : $ref;
238 if (($cmd->{lasttime}||0) != $t) {
240 $cmd->{lasttime} = $t;
242 $cmd->add_data([$ts, $s]);
249 my ($t, $ts) = (time, '');
251 if (($dx->{lasttime}||0) != $t) {
253 $dx->{lasttime} = $t;
255 $dx->add_data([$ts, @$ref[0,1,15,3,4,16], stim($ref->[2]) ]);
263 my ($t, $ts) = (time, '');
265 # $s = ref $ref ? (join ', ',@$ref) : $ref;
267 if (($ann->{lasttime}||0) != $t) {
269 $ann->{lasttime} = $t;
273 $ann->add_data([$ts, @$ref[3,1,2]]);
282 # $s = ref $ref ? join ', ',@$ref : $ref;
286 $wcy->add_data([tim(), @$ref[10,4,5,3,6,2,7,8,9,1] ]);
295 # $s = ref $ref ? join ', ',@$ref : $ref;
298 $wwv->add_data([tim(), @$ref[6,2,3,4,5,1] ]);
307 my ($t, $ts) = (time, '');
309 $s = ref $ref ? (join ', ',@$ref) : $ref;
311 if (($ann->{lasttime}||0) != $t) {
313 $ann->{lasttime} = $t;
317 $chat->add_data([$ts, @$ref[3,1,2]]);
330 $sock->print("$msg\n");
335 my $t = shift || time;
336 return sprintf "%02d:%02d:%02d", (gmtime($t))[2,1,0];
341 my $t = shift || time;
342 return sprintf "%02d:%02d", (gmtime($t))[2,1];
345 # get a zulu time in cluster format (2300Z)
349 $t = defined $t ? $t : time;
351 my ($sec,$min,$hour) = $dst ? localtime($t): gmtime($t);
352 my $buf = sprintf "%02d%02d%s", $hour, $min, ($dst) ? '' : 'Z';
356 # get a cluster format date (23-Jun-1998)
360 $t = defined $t ? $t : time;
362 my ($sec,$min,$hour,$mday,$mon,$year) = $dst ? localtime($t) : gmtime($t);
364 my $buf = sprintf "%2d-%s-%04d", $mday, $month[$mon], $year;
368 # return a cluster style date time
373 my $date = cldate($t, $dst);
374 my $time = ztime($t, $dst);
375 return "$date $time";
383 my $fh = new IO::File $userfn;
393 print "$userfn missing or unreadable, starting afresh!\n";
397 'LOCAL' => {host => '127.0.0.1', port => 7300},
398 'GB7DJK' => {host => 'gb7djk.dxcluster.net', port => 7300},
399 'WR3D' => {host => 'wr3d.dxcluster.net', port => 7300},
400 'GB7BAA' => {host => 'gb7baa.dxcluster.net', port => 7300},
403 call => $main::myalias,
414 my $fh = new IO::File ">$userfn";
416 my $dd = new Data::Dumper([ $u ]);
419 $fh->print($dd->Dumpxs);
426 sub def_menu_callback
431 sub gtk_create_main_screen
433 $main = new Gtk2::Window('toplevel');
434 my $scr = $main->get_screen;
435 $scr_width = $scr->get_width;
436 $scr_width = 700 if $scr_width > 700;
437 $scr_height = int ($scr->get_height * 0.66);
438 $main->set_default_size($scr_width, $scr_height);
439 $main->signal_connect('delete_event', sub { Gtk2->main_quit; });
442 my $vbox = new Gtk2::VBox(0, 1);
447 item_type => '<Branch>',
450 callback => sub { Gtk2->main_quit; },
451 callback_action => 1,
452 accelerator => '<ctrl>Q',
458 item_type => '<Branch>',
461 callback_action => 9,
468 my $menu = Gtk2::SimpleMenu->new(menu_tree => $menutree, default_callback => \&def_menu_callback, user_data => $user);
469 $vbox->pack_start($menu->{widget}, 0, 1, 0);
472 # a paned hbox is packed as the bottom of the vbox
473 # my $bhpane = Gtk2::HPaned->new;
474 # $vbox->pack_end($bhpane, 1, 1, 0);
476 # now create the lh and rh panes
477 # my $lhvpane = Gtk2::VPaned->new;
478 # my $rhvpane = Gtk2::VPaned->new;
479 # $bhpane->pack1($lhvpane, 1, 0);
480 # $bhpane->pack2($rhvpane, 1, 0);
484 # my $lhvbox = Gtk2::VBox->new(0, 1);
485 $cmd = Screen::List->new(fields => [
487 Information => 'ttlong',
489 size => [$scr_width, $scr_height * 0.66],
491 $vbox->pack_start($cmd->widget, 1, 1, 0);
494 # callsign and current date and time
495 my $hbox = new Gtk2::HBox;
496 my $calllabel = new Gtk2::Label($call);
497 my $date = new Gtk2::Label(cldatetime(time));
498 $date->{tick} = Glib::Timeout->add(1000, \&updatetime, $date);
499 $hbox->pack_start( $calllabel, 0, 1, 0 );
500 $hbox->pack_end($date, 0, 1, 0);
501 $vbox->pack_start($hbox, 0, 1, 0);
502 $vbox->pack_start(Gtk2::HSeparator->new, 0, 1, 0);
505 $bot = new Gtk2::Entry;
506 $bot->set_editable(1);
507 $bot->signal_connect('activate', \&bothandler);
508 $bot->can_default(1);
509 $vbox->pack_end($bot, 0, 1, 0);
510 # $lhvpane->pack2($lhvbox, 1, 0);
519 $annwin = new Gtk2::Window('toplevel');
520 $ann = Screen::List->new(fields =>[
524 Announcement => 'ttlesslong',
527 frame => 'Announcements',
528 size => [$scr_width * 0.85, $scr_height * 0.25],
530 $annwin->add($ann->widget);
534 $chatwin = new Gtk2::Window('toplevel');
535 $chat = Screen::List->new(fields =>[
539 Chat => 'ttlesslong',
543 size => [$scr_width * 0.85, $scr_height * 0.25],
545 $chatwin->add($chat->widget);
549 $dxwin = new Gtk2::Window('toplevel');
550 $dx = Screen::List->new(fields => [
555 'Remarks' => 'ttshort',
560 policy => [qw(never automatic)],
564 size => [$scr_width * 0.9, $scr_height * 0.25],
566 # $rhvpane->pack1($dx->widget, 1, 0);
567 $dxwin->add($dx->widget);
571 $wwvwin = new Gtk2::Window('toplevel');
572 # my $rhvbox = Gtk2::VBox->new(0, 1);
573 $wwv = Screen::List->new( fields =>[
579 Remarks => 'ttshort',
583 policy => ['never', 'automatic'],
586 $wwvwin->add($wwv->widget);
589 # $rhvbox->pack_start($wwv->widget, 1, 1, 0);
592 $wcywin = new Gtk2::Window('toplevel');
593 $wcy = Screen::List->new(fields => [
607 policy => ['never', 'automatic'],
611 # $rhvbox->pack_start($wcy->widget, 1, 1, 0);
612 # $rhvbox->set_size_request($scr_width * 0.45, $scr_height * 0.33);
613 # $rhvpane->pack2($rhvbox, 1, 0);
614 $wcywin->add($wcy->widget);