January 2002
Beginner
480 pages
13h 15m
English
The hlv script, shown in
Example 9-20, uses Perl
with the Net::Jabber library.
use Tk; use Net::Jabber qw(Client); use strict; use constant SERVER => 'gnu.pipetree.com'; use constant PORT => 5222; use constant USER => 'dj'; use constant PASSWORD => 'secret'; use constant RESOURCE => 'hlv'; use constant BROWSER => '/usr/bin/konqueror'; my @headlines; my @list; my $connection = Net::Jabber::Client->new(); $connection->Connect( hostname => SERVER, port => PORT, ) or die "Cannot connect ($!)\n"; my @result = $connection->AuthSend( username => USER, password => PASSWORD, resource => RESOURCE, ); if ($result[0] ne "ok") { die "Ident/Auth with server failed: $result[0] - $result[1]\n"; } $connection->SetCallBacks( message => \&handle_message ); my $main = MainWindow->new( -title => "Headline Viewer" ); $main->geometry('50x5+10+10'); $main->repeat(5000, \&check_headlines); # Button frame my $buttons = $main->Frame(); $buttons->pack(qw/-side bottom -fill x/); # Headline list my $list = $main->Scrolled(qw/Listbox -scrollbars e -height 40 -setgrid 1/); # Clear button my $button_clear = $buttons->Button( -text => 'Clear', -underline => '0', -command => sub { @list = (); $list->delete(0, 'end') }, ); # Fetch Button my $button_fetch = $buttons->Button( -text => 'Fetch', -underline => '0', -command => sub { system( join(" ", (BROWSER, $list[$list->curselection], "&")) ) }, ); # Exit button my $button_exit = $buttons->Button( -text => ...Read now
Unlock full access