My test case/guinea pig program is a snippet to use use.perl.org's SOAP interface to display journals. (More information on that interface is available here and here.)
It's not perfect. There are some layout issues. If you click on a link on the RHS, you don't get anywhere. I couldn't get PerlQt to change to a Waiting cursor while it was retrieving things. But for a few hours of hacking, it's fun and was a good refresher.
#!/pkg/perl-5.8.0/bin/perl -w
use strict;
use warnings;
# -- Configuration --
my $uid = $ARGV[0] || '1414'; # Robrt my $host = 'use.perl.org';
my $uri = "http://$host/Slash/Journal/SOAP";
my $proxy = "http://$host/journal.pl";
# -- End --
package JournalPanes;
use Qt;
use Qt::isa qw(Qt::Widget);
use Qt::slots
onQuit => [],
onRefresh => [],
onSelect => ['int'],
;
use Qt::attributes qw(listbox refresh quit textbox journal label data);
use SOAP::Lite;
sub NEW {
shift->SUPER::NEW(@_);
my $layout = Qt::HBoxLayout( this,"hbox" );
my $leftlayout = Qt::VBoxLayout( $layout,"left" );
my $rightlayout = Qt::VBoxLayout( $layout,"right" );
listbox = Qt::ListBox(this);
$leftlayout->addWidget(listbox);
refresh = Qt::PushButton("Refresh",this);
quit = Qt::PushButton("Quit",this);
$leftlayout->addWidget(refresh);
$leftlayout->addWidget(quit);
my $font = Qt::Font();
$font->setBold(1);
$font->setPointSize(16);
label = Qt::Label(this);
label->setFont($font);
$rightlayout->addWidget(label);
textbox = Qt::TextBrowser(this);
$rightlayout->addWidget(textbox);
this->connect(quit, SIGNAL('clicked()'), SLOT('onQuit()'));
this->connect(refresh, SIGNAL('clicked()'), SLOT('onRefresh()'));
this->connect(listbox, SIGNAL('highlighted(int)'), SLOT('onSelect(int)'));
journal = SOAP::Lite->uri($uri)->proxy($proxy);
this->onRefresh;
}
sub onQuit {
Qt::app->quit();
}
sub onRefresh {
# Qt::app->setOverrideCursor( &Qt::WaitCursor );
listbox->clear();
data = undef;
my $entries = journal->get_entries( $uid )->result; # all entries
my $data = [];
my $i = 0;
for (@$entries) {
$data->[$i++] = [ $_->{subject}, $_->{id} ];
listbox->insertItem($_->{subject});
}
data = $data;
# Qt::Application::restoreOverrideCursor();
}
sub onSelect {
my ($id) = @_;
textbox->clear();
label->setText( data->[$id][0] );
my $jid = data->[$id][1];
my $entry = journal->get_entry( $jid )->result;
my $body = "$entry->{date}<BR>$entry->{url}<BR>$entry->{nickname}<BR><HR>$entry->{body}";}
package main;
use Qt;
use JournalPanes;
my $a = Qt::Application(\@ARGV);
my $j = JournalPanes;
$j->resize(470, 300);
$a->setMainWidget($j);
$j->setCaption("$host Journals");
$j->show;
exit $a->exec;
1;
PerlQt, SOAP, and 104 lines of code 0 Comments More | Login | Reply /