Author: bdonlan
Date: 2004-05-30 12:19:28 -0400 (Sun, 30 May 2004)
New Revision: 195

Modified:
   trunk/haver-gtk/lib/Haver/Client/Gtk/Page/Channel.pm
Log:
Added parsing for some WARN events to the Channel pages.


Modified: trunk/haver-gtk/lib/Haver/Client/Gtk/Page/Channel.pm
===================================================================
--- trunk/haver-gtk/lib/Haver/Client/Gtk/Page/Channel.pm        2004-05-30 
16:18:01 UTC (rev 194)
+++ trunk/haver-gtk/lib/Haver/Client/Gtk/Page/Channel.pm        2004-05-30 
16:19:28 UTC (rev 195)
@@ -30,6 +30,45 @@
 
 our $VERSION = 0.01;
 
+my %warnings = (
+       # Warnings captured by this page. Key is haver server warning, value is 
subref to call
+       # or undef to simply display
+       CID_INVALID => sub {
+               my $self = shift;
+               $self->print_page("The channel ID '$self->{channel}' is 
invalid.");
+               $self->{joining} = -1;
+       },
+       CID_NOT_FOUND => sub {
+               my $self = shift;
+               $self->print_page("Channel '$self->{channel}' does not exist.");
+               $self->{joining} = 0;
+       },
+       ALREADY_JOINED => sub {
+               my $self = shift;
+               $self->print_page("Client bug: Tried to join $self->{channel} 
when already there.");
+               $self->{joining} = 0;
+               $self->{present} = 1;
+               $poe_kernel->post('haver', 'users', $self->{channel}); # Just 
in case
+       },
+       NOT_JOINED_PART => sub {
+               my $self = shift;
+               $self->print_page("Client bug: Tried to part $self->{channel} 
when not there.");
+               $self->{present} = 0;
+       },
+#      ACCESS => undef, # XXX: check command?
+#      PERM => undef,
+);
+
+my %warnpos = (
+       # The position in the args of a given warning of the CID
+       # The protocol should probably use IN for this
+       CID_INVALID => 0,
+       CID_NOT_FOUND => 0,
+       ALREADY_JOINED => 0,
+       NOT_JOINED_PART => 0,
+       # XXX: Can't do access or PERM with current architecture, at least not 
easily
+);
+
 ### METHODS
 
 sub new ($$) {
@@ -63,6 +102,7 @@
                        haver_users                     _users
                        haver_msg                       _msg
                        haver_disconnected      _discon
+                       haver_warn                      _warn
                        _start                          _start
                        destroy                         _destroy
                }}, # $page => {qw{
@@ -251,4 +291,20 @@
        $kernel->post('haver', 'unregister', 'all');
 }
 
+sub _warn {
+       my ($self, $kernel, $args, $chan) = @_[OBJECT,KERNEL,ARG0,ARG1];
+       my ($err, $eshort, $elong, @earg) = @$args;
+       print "_warn $err @earg\n";
+       my $warnpos = $warnpos{$err};
+       return unless defined $warnpos;
+       print "warnpos $warnpos; $earg[$warnpos] v $self->{channel}\n";
+       #return unless ($chan eq $self->{channel}) && exists $warnings{$err};
+       return unless exists $warnpos{$err} && $earg[$warnpos{$err}] eq 
$self->{channel};
+       if($warnings{$err}) {
+               $warnings{$err}($self, @earg);
+       } else {
+               $self->print_page("Warning from server ($err): $elong");
+       }
+}
+
 1;


Reply via email to