1 |
elmex |
1.1 |
package DC::MessageDistributor; |
2 |
|
|
use strict; |
3 |
|
|
no warnings; |
4 |
|
|
|
5 |
|
|
sub new { |
6 |
|
|
my $this = shift; |
7 |
|
|
my $class = ref($this) || $this; |
8 |
|
|
my $self = { @_ }; |
9 |
|
|
bless $self, $class; |
10 |
|
|
|
11 |
|
|
$self->{dockbar}->add_dock ( |
12 |
|
|
$self->{log} = DC::UI::ChatView->new ( |
13 |
|
|
expand => 1, |
14 |
|
|
can_close => 0, |
15 |
|
|
can_undock => 0, |
16 |
|
|
info => { |
17 |
|
|
title => "Log", |
18 |
|
|
tooltip => |
19 |
|
|
"<b>Server Log</b>. This text viewer contains all recent message sent by the server.", |
20 |
|
|
entry_tooltip => |
21 |
|
|
"<b>Command Entry</b>. If you enter something and press return/enter here, " |
22 |
|
|
."the line you entered will be sent to the server as a command.", |
23 |
|
|
reply => '' |
24 |
|
|
} |
25 |
|
|
) |
26 |
|
|
); |
27 |
|
|
|
28 |
|
|
return $self |
29 |
|
|
} |
30 |
|
|
|
31 |
|
|
# called by MAPWIDGET activate console event |
32 |
|
|
sub activate_console { |
33 |
|
|
} |
34 |
|
|
|
35 |
|
|
# adding channel |
36 |
|
|
sub add_channel { |
37 |
|
|
my ($self, $chaninfo) = @_; |
38 |
|
|
|
39 |
|
|
$self->{info}->{$chaninfo->{id}} = $chaninfo; |
40 |
|
|
$self->touch_channel ($chaninfo->{id}); |
41 |
|
|
} |
42 |
|
|
|
43 |
|
|
# set max paragraphs |
44 |
|
|
sub set_max_para { |
45 |
|
|
} |
46 |
|
|
|
47 |
elmex |
1.2 |
# set fontsize for all chatviews |
48 |
elmex |
1.1 |
sub set_fontsize { |
49 |
elmex |
1.2 |
my ($self, $s) = @_; |
50 |
|
|
|
51 |
|
|
for ($self->{log}, values %{$self->{chatview}}) { |
52 |
|
|
$_->set_fontsize ($s); |
53 |
|
|
} |
54 |
elmex |
1.1 |
} |
55 |
|
|
|
56 |
|
|
# push message in |
57 |
|
|
sub message { |
58 |
|
|
my ($self, $para) = @_; |
59 |
|
|
my $id = $para->{type}; |
60 |
|
|
|
61 |
|
|
if (exists $self->{info}->{$id}) { |
62 |
|
|
unless (exists $self->{chatview}->{$id}) { |
63 |
|
|
$self->touch_channel ($id); |
64 |
|
|
} |
65 |
|
|
|
66 |
|
|
my $cv = $self->{chatview}->{$id}; |
67 |
|
|
|
68 |
|
|
unless ($cv) { |
69 |
|
|
warn "message couldn't be delivered to chatview with " |
70 |
|
|
."id '$id', sending it to main log."; |
71 |
|
|
$self->{log}->message ($para); |
72 |
|
|
return; |
73 |
|
|
} |
74 |
|
|
|
75 |
|
|
$cv->message ($para); |
76 |
|
|
|
77 |
|
|
} else { |
78 |
|
|
$self->{log}->message ($para); |
79 |
|
|
} |
80 |
|
|
} |
81 |
|
|
|
82 |
|
|
sub touch_channel { |
83 |
|
|
my ($self, $id) = @_; |
84 |
|
|
|
85 |
|
|
if (exists $self->{chatview}->{$id}) { |
86 |
|
|
$self->update_chat ($id); |
87 |
|
|
} else { |
88 |
|
|
$self->init_chat ($id); |
89 |
|
|
} |
90 |
|
|
} |
91 |
|
|
|
92 |
|
|
sub update_chat { |
93 |
|
|
my ($self, $id) = @_; |
94 |
|
|
$self->{chatview}->{$id}->update_info ($self->{info}->{$id}); |
95 |
|
|
} |
96 |
|
|
|
97 |
|
|
sub init_chat { |
98 |
|
|
my ($self, $id) = @_; |
99 |
|
|
|
100 |
|
|
my $chaninfo = $self->{info}->{$id}; |
101 |
|
|
my $dock = $self->{chatview}->{$id} = |
102 |
|
|
DC::UI::ChatView->new ( |
103 |
|
|
expand => 1, |
104 |
|
|
info => $chaninfo, |
105 |
|
|
); |
106 |
|
|
$dock->connect (close_dock => sub { |
107 |
|
|
delete $self->{chatview}->{$id}; |
108 |
|
|
0 |
109 |
|
|
}); |
110 |
|
|
$self->{dockbar}->add_dock ($dock); |
111 |
|
|
} |
112 |
|
|
|
113 |
|
|
1; |