Author: bdonlan
Date: 2004-05-30 21:56:06 -0400 (Sun, 30 May 2004)
New Revision: 207
Added:
trunk/haver-gtk/lib/Haver/Client/Gtk/Page/Server.pm
Modified:
trunk/haver-gtk/bin/haver-gtk.pl
Log:
Move server status states to ...::Page::Server.pm. Use $status instead of
->get_page(0)
Modified: trunk/haver-gtk/bin/haver-gtk.pl
===================================================================
--- trunk/haver-gtk/bin/haver-gtk.pl 2004-05-31 01:26:00 UTC (rev 206)
+++ trunk/haver-gtk/bin/haver-gtk.pl 2004-05-31 01:56:06 UTC (rev 207)
@@ -45,6 +45,7 @@
use Haver::Client::Gtk::Page::Text;
use Haver::Client::Gtk::Page::Query;
use Haver::Client::Gtk::Page::Rawlog;
+use Haver::Client::Gtk::Page::Server;
# XXX: Implement config files
use Data::Dumper;
use Carp;
@@ -63,6 +64,7 @@
}
my $pages;
+my $status;
sub get_query_page ($) {
my $page = $pages->get_page("=$_[0]");
@@ -132,12 +134,9 @@
connect_win
do_connect
quit
- haver_connected
haver_connect_fail
haver_disconnected
- haver_login_request
haver_login
- haver_login_fail
haver_joined
haver_pmsg
cmd_join
@@ -209,7 +208,7 @@
$gui{main_window}->show;
- $pages->add_page(new Haver::Client::Gtk::Page::Text("Server"));
+ $status = $pages->add_page(new
Haver::Client::Gtk::Page::Server("Server"));
$pages->add_page(new Haver::Client::Gtk::Page::Rawlog("!rawlog"));
$pages->set_page(0);
@@ -341,7 +340,7 @@
UID => $info->{UID},
Password => $info->{Password},
);
- $pages->get_page(0)->print_page("Connecting to $info->{Address}...");
+ $status->print_page("Connecting to $info->{Address}...");
$gui{connect_win}{window}->destroy;
delete $gui{connect_win};
%globals = %$info;
@@ -357,31 +356,14 @@
undef $pages;
}
-
-sub haver_connected {
- $pages->get_page(0)->print_page("Connected, logging in.");
-}
-
sub haver_connect_fail {
my $kernel = $_[KERNEL];
- my ($args, $scope) = @_[ARG0,ARG1];
- my ($enum, $estr) = @$args;
-
- $pages->get_page(0)->print_page("Connection error: $estr");
$kernel->yield('connect_win');
}
-sub haver_login_fail {
- my ($kernel, $args) = @_[KERNEL,ARG0];
- my $elong = $args->[2];
-
- $pages->get_page(0)->print_page("Login failure: $elong");
- $kernel->post('haver', 'disconnect');
-}
-
sub haver_disconnected {
my ($kernel, $heap) = @_[KERNEL,HEAP];
- $pages->get_page(0)->print_page("Disconnected");
+ $status->print_page("Disconnected");
for($pages->get_pages()) {
next unless ($_->get_name() =~ /^\#/);
$pages->del_page($_);
@@ -390,14 +372,7 @@
$kernel->yield('connect_win');
}
-sub haver_login_request {
- my $kernel = $_[KERNEL];
- $pages->get_page(0)->print_page("Login failed.");
- $kernel->post('haver', 'disconnect');
-}
-
sub haver_login {
- $pages->get_page(0)->print_page("Logged in.");
$_[HEAP]->{ready} = 1;
}
@@ -448,7 +423,7 @@
# XXX: ->can
$chan = $pages->get_current_page()->{string};
unless($chan =~ s/^\#//) {
- $pages->get_page(0)->print_page("That command can only
be used in a channel window.");
+ $status->print_page("That command can only be used in a
channel window.");
return;
}
}
@@ -464,11 +439,11 @@
# XXX: ->can
$chan = $pages->get_current_page()->{string};
unless($chan =~ s/^\#//) {
- $pages->get_page(0)->print_page("This is not a
channel tab");
+ $status->print_page("This is not a channel
tab");
return;
}
} else {
- $pages->get_page(0)->print_page("Syntax: /part
[channel]");
+ $status->print_page("Syntax: /part [channel]");
}
}
if(!defined $heap->{clist}->{$chan}) {
@@ -481,7 +456,7 @@
sub cmd_msg {
my ($kernel, $heap, $args) = @_[KERNEL,HEAP,ARG1];
# unless($args =~ /^\s*(\S+)\s*(.+)$/) {
-# $pages->get_page(0)->print_page "Syntax: /msg UID text";
+# $status->print_page "Syntax: /msg UID text";
# return;
# }
get_query_page($args->[0])->send_msg(q{"}, $args->[1]);
@@ -490,7 +465,7 @@
sub cmd_act {
my ($kernel, $heap, $args) = @_[KERNEL,HEAP,ARG1];
unless($args =~ /^\s*(\S+)\s*(.+)$/) {
- $pages->get_page(0)->print_page("Syntax: /msg UID text");
+ $status->print_page("Syntax: /msg UID text");
return;
}
get_query_page($1)->send_msg(q{:}, $2);
@@ -513,7 +488,7 @@
unless($args->[0] =~ /^\s*$/) {
$page = $pages->get_page($args->[0]);
if(!$page) {
- $pages->get_page(0)->print_page("No such page
$args->[0]");
+ $status->print_page("No such page $args->[0]");
return;
}
}
@@ -522,7 +497,7 @@
$pages->del_page($page);
}
} else {
- $pages->get_page(0)->print_page("Can't close that kind of page,
sorry :(");
+ $status->print_page("Can't close that kind of page, sorry :(");
}
}
Added: trunk/haver-gtk/lib/Haver/Client/Gtk/Page/Server.pm
===================================================================
--- trunk/haver-gtk/lib/Haver/Client/Gtk/Page/Server.pm 2004-05-31 01:26:00 UTC
(rev 206)
+++ trunk/haver-gtk/lib/Haver/Client/Gtk/Page/Server.pm 2004-05-31 01:56:06 UTC
(rev 207)
@@ -0,0 +1,103 @@
+# vim: set ft=perl ts=4 sw=4:
+# Haver::Client::Gtk::Page::Server - server warning/error notification, etc
+#
+# Copyright (C) 2004 Bryan Donlan, Dylan William Hardison.
+#
+# This module is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This module is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this module; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+package Haver::Client::Gtk::Page::Server;
+use warnings;
+use strict;
+
+use POE;
+use base 'Haver::Client::Gtk::Page::Text';
+
+our $package = __PACKAGE__;
+our $VERSION = 0.01;
+
+### METHODS
+
+sub _object_states {
+ my ($self, $ehash) = @_;
+ $ehash = {
+ qw{
+ haver_connected _connected
+ haver_connect_fail _connfail
+ haver_login _login
+ haver_login_fail _lfail
+ haver_login_request _lreq
+ },
+ %$ehash,
+ };
+ return $self->SUPER::_object_states($ehash);
+}
+
+### STATES
+
+my %warn_exclude = (
+ CID_INVALID => 1,
+ CID_NOT_FOUND => 1,
+ ALREADY_JOINED => 1,
+ NOT_JOINED_PART => 1,
+ UID_INVALID => 1,
+ UID_NOT_FOUND => 1,
+);
+
+sub _warndie {
+ # We need to capture all warn/die, since we exclude instead of include
+ # XXX: some way to route all uncaptured events, rather than excluding
+ # XXX: event types
+ my ($self, $kernel, $state, $args) = @_[OBJECT,KERNEL,STATE,ARG0];
+ my ($eid, $eshort, $elong, @earg) = @$args;
+ return if ($warn_exclude{$eid});
+
+ if ($state eq 'haver_warn') {
+ $state = 'Warning';
+ } else {
+ $state = 'Error';
+ }
+
+ $self->print_page("$state from server: $elong");
+}
+
+sub _connected {
+ $_[OBJECT]->print_page("Connected to server, logging in...");
+}
+
+sub _connfail {
+ my $kernel = $_[KERNEL];
+ my ($args, $scope) = @_[ARG0,ARG1];
+ my ($enum, $estr) = @$args;
+
+ $_[OBJECT]->print_page("Connection error: $estr");
+}
+
+sub _login {
+ $_[OBJECT]->print_page("Logged in.");
+}
+
+sub _lfail {
+ my ($self, $kernel, $args) = @_[OBJECT,KERNEL,ARG0];
+ my $elong = $args->[2];
+
+ $self->print_page("Login failure: $elong");
+ $kernel->post('haver', 'disconnect');
+}
+
+sub _lreq {
+ my ($self, $kernel) = @_[OBJECT,KERNEL];
+ $self->print_page("Login failed.");
+ $kernel->post('haver', 'disconnect');
+}