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