Author: bdonlan
Date: 2004-05-30 18:06:04 -0400 (Sun, 30 May 2004)
New Revision: 204

Added:
   trunk/haver-gtk/lib/Haver/Client/Gtk/Page/Chat.pm
Modified:
   trunk/haver-gtk/lib/Haver/Client/Gtk/Page/Channel.pm
   trunk/haver-gtk/lib/Haver/Client/Gtk/Page/Query.pm
Log:
Move chat message formatting logic to seperate module.

Modified: trunk/haver-gtk/lib/Haver/Client/Gtk/Page/Channel.pm
===================================================================
--- trunk/haver-gtk/lib/Haver/Client/Gtk/Page/Channel.pm        2004-05-30 
21:59:21 UTC (rev 203)
+++ trunk/haver-gtk/lib/Haver/Client/Gtk/Page/Channel.pm        2004-05-30 
22:06:04 UTC (rev 204)
@@ -26,7 +26,7 @@
 };
 
 use POE;
-use base 'Haver::Client::Gtk::Page::Text';
+use base 'Haver::Client::Gtk::Page::Chat';
 
 our $VERSION = 0.01;
 
@@ -93,7 +93,7 @@
 sub new ($$) {
        my ($class, $name, $present) = @_;
        $present ||= 0; # Make sure it's defined
-       my $page = Haver::Client::Gtk::Page::Text::new($class, "#$name");
+       my $page = $class->SUPER::new("#$name");
                
        my $sw = Gtk::ScrolledWindow->new(undef, undef);
        $sw->set_policy('never', 'automatic');
@@ -237,24 +237,7 @@
 sub _msg {
        my ($self, $kernel, $args, $chan) = @_[OBJECT,KERNEL,ARG0,ARG1];
        if ($chan eq $self->{channel}) {
-               my ($type, $who, $text) = @$args;
-               my $prefix;
-               my @lines = split "\n", $text;
-               if ($type eq q{"}) {
-                       $prefix = "<$who> ";
-               } elsif ($type eq q{:}) {
-                       $prefix = "* $who ";
-               } else {
-                       if (@lines > 1) {
-                               @lines = map { ">$_" } @lines;
-                               $self->print_page("$who sent unknown message 
type $type:", @lines);
-                       } else {
-                               $self->print_page("$who sent unknown message 
type $type: $lines[0]");
-                       }
-                       return;
-               }
-               @lines = map { "$prefix$_" } @lines;
-               $self->print_page(@lines);
+               $self->_display_msg($args);
        }
 }
 

Added: trunk/haver-gtk/lib/Haver/Client/Gtk/Page/Chat.pm
===================================================================
--- trunk/haver-gtk/lib/Haver/Client/Gtk/Page/Chat.pm   2004-05-30 21:59:21 UTC 
(rev 203)
+++ trunk/haver-gtk/lib/Haver/Client/Gtk/Page/Chat.pm   2004-05-30 22:06:04 UTC 
(rev 204)
@@ -0,0 +1,52 @@
+# vim: set ft=perl ts=4 sw=4:
+# Haver::Client::Gtk::Page::Chat - chat-like pages
+# 
+# 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
+
+# In the future, this might handle some input-related functions, but for now
+# it only does [p]msg formatting
+
+package Haver::Client::Gtk::Page::Chat;
+use warnings;
+use strict;
+
+use base 'Haver::Client::Gtk::Page::Text';
+
+sub _display_msg {
+       my ($self, $args) = @_;
+       # This assumes the parent has already checked that we should display it
+       my ($type, $who, $text) = @$args;
+       my $prefix;
+       my @lines = split "\n", $text;
+       if ($type eq q{"}) {
+               $prefix = "<$who> ";
+       } elsif ($type eq q{:}) {
+               $prefix = "* $who ";
+       } else {
+               if (@lines > 1) {
+                       @lines = map { ">$_" } @lines;
+                       $self->print_page("$who sent unknown message type 
$type:", @lines);
+               } else {
+                       $self->print_page("$who sent unknown message type 
$type: $lines[0]");
+               }
+               return;
+       }
+       @lines = map { "$prefix$_" } @lines;
+       $self->print_page(@lines);
+}
+
+1;

Modified: trunk/haver-gtk/lib/Haver/Client/Gtk/Page/Query.pm
===================================================================
--- trunk/haver-gtk/lib/Haver/Client/Gtk/Page/Query.pm  2004-05-30 21:59:21 UTC 
(rev 203)
+++ trunk/haver-gtk/lib/Haver/Client/Gtk/Page/Query.pm  2004-05-30 22:06:04 UTC 
(rev 204)
@@ -26,7 +26,7 @@
 };
 
 use POE;
-use base 'Haver::Client::Gtk::Page::Text';
+use base 'Haver::Client::Gtk::Page::Chat';
 
 our $VERSION = 0.01;
 
@@ -69,7 +69,7 @@
 
 sub new ($$) {
        my ($class, $uid) = @_;
-       my $self = Haver::Client::Gtk::Page::Text::new($class, "=$uid");
+       my $self = $class->SUPER::new("=$uid");
        $self->{UID} = $uid;
        $self->{local} = 0;
        return $self;
@@ -78,12 +78,7 @@
 sub send_msg ($$$) {
        my ($self, $type, $text) = @_;
        $poe_kernel->post('haver', 'pmsg', $type, $self->{UID}, $text);
-       my @lines = split "\n", $text;
-       if($type eq q{"}) {
-               $self->print_page(map { "$main::globals{UID}: $_" } @lines);
-       } elsif($type eq q{:}) {
-               $self->print_page(map { "* $main::globals{UID} $_" } @lines);
-       }
+       $self->_display_msg([$type, $main::globals{UID}, $text]);
 }
 
 sub close {
@@ -94,24 +89,7 @@
        my ($self, $args) = @_;
        my ($type, $who, $text) = @$args;
        return unless $who eq $self->{UID};
-       ### XXX: Copied from ::Channel, consolidate somewhere
-       my $prefix;
-       my @lines = split "\n", $text;
-       if ($type eq q{"}) {
-               $prefix = "<$who> ";
-       } elsif ($type eq q{:}) {
-               $prefix = "* $who ";
-       } else {
-               if (@lines > 1) {
-                       @lines = map { ">$_" } @lines;
-                       $self->print_page("$who sent unknown message type 
$type:", @lines);
-               } else {
-                       $self->print_page("$who sent unknown message type 
$type: $lines[0]");
-               }
-               return;
-       }
-       @lines = map { "$prefix$_" } @lines;
-       $self->print_page(@lines);
+       $self->_display_msg($args);
 }
 
 ### EVENTS


Reply via email to