ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/kgsueme/kgsueme/room.pl
Revision: 1.32
Committed: Tue Jun 8 17:58:48 2004 UTC (19 years, 11 months ago) by elmex
Content type: text/plain
Branch: MAIN
Changes since 1.31: +13 -11 lines
Log Message:
Added Paned widget between chat and userlist, rearranged the buttons.

File Contents

# Content
1 package room;
2
3 use KGS::Constants;
4
5 use base KGS::Listener::Room;
6
7 use Glib::Object::Subclass
8 Gtk2::Frame;
9
10 sub new {
11 my ($self, %arg) = @_;
12
13 $self = $self->Glib::Object::new;
14 $self->{$_} = delete $arg{$_} for keys %arg;
15
16 $self->signal_connect (destroy => sub {
17 delete $::config->{rooms}{$self->{channel}};
18 delete $self->{app}{room}{$self->{channel}};
19 (remove Glib::Source delete $self->{gameupdate}) if $self->{gameupdate};
20 $self->unlisten;
21 %{$_[0]} = ();
22 });
23
24 $self->listen ($self->{conn}, qw(msg_room:));
25
26 $self->signal_connect (delete_event => sub { $self->part; 1 });
27
28 $self->add (my $vbox = new Gtk2::VBox);
29
30 $vbox->pack_start((my $hbox = new Gtk2::HBox), 0, 1, 0);
31
32 $hbox->pack_start ((my $button = new_with_label Gtk2::Button "Leave"), 0, 1, 0);
33 $button->signal_connect (clicked => sub { $self->part });
34
35 $hbox->pack_start ((my $button = new_with_label Gtk2::Button "New Game"), 0, 1, 0);
36 $button->signal_connect (clicked => sub { $self->new_game });
37
38 $vbox->pack_start ((my $hpane = new Gtk2::HPaned), 1, 1, 0);
39 gtk::state $hpane, "room::hpane", undef, position => 500;
40
41 $hpane->pack1 (($self->{chat} = new chat app => $self->{app}), 1, 0);
42
43 $self->{chat}->signal_connect (command => sub {
44 my ($chat, $cmd, $arg) = @_;
45 $self->{app}->do_command ($chat, $cmd, $arg, userlist => $self->{userlist}, room => $self);
46 });
47
48 $hpane->pack2 ((my $sw = new Gtk2::ScrolledWindow), 1, 0);
49
50 $sw->set_policy ("automatic", "always");
51
52 $sw->add ($self->{userlist} = new userlist);
53
54 $self;
55 }
56
57 sub FINALIZE_INSTANCE { print "FIN room\n" } # never called MEMLEAK #d#TODO#
58
59 sub part {
60 my ($self) = @_;
61
62 $self->hide;
63 $self->SUPER::part;
64 }
65
66 sub inject_msg_room {
67 my ($self, $msg) = @_;
68
69 # secret typoe ;-)
70 $self->{chat}->append_text ("\n<user>" . (util::toxml $msg->{name})
71 . "</user>: " . (util::toxml $msg->{message}));
72 }
73
74 sub event_update_users {
75 my ($self, $add, $update, $remove) = @_;
76
77 $self->{userlist}->update ($add, $update, $remove);
78 }
79
80 sub event_update_games {
81 my ($self, $add, $update, $remove) = @_;
82
83 $self->{app}{gamelist}->update ($self, $add, $update, $remove);
84
85 # try to identify any new games assigned to us. stupid protocol
86 # first updates the game, joins you and THEN tells you that
87 # which of the games you asked for this is.
88
89 for (@$add) {
90 if (($_->{black}{name} eq $self->{conn}{name}
91 || $_->{white}{name} eq $self->{conn}{name}
92 || $_->{owner}{name} eq $self->{conn}{name})
93 && (my $game = shift @{$self->{new_game}})) {
94 $game->inject_upd_game ({ game => $_ });
95 $game->set_channel ($game->{channel});
96 }
97 }
98 }
99
100 sub event_join {
101 my ($self) = @_;
102 $self->SUPER::event_join;
103
104 $::config->{rooms}{$self->{channel}} = { channel => $self->{channel}, name => $self->{name} };
105
106 # mysteriously enough, we have to request game updates manually
107 $self->{gameupdate} ||= add Glib::Timeout INTERVAL_GAMEUPDATES * 1000, sub {
108 $self->req_games;
109 1;
110 };
111
112 $self->show_all;
113 }
114
115 sub event_part {
116 my ($self) = @_;
117
118 $self->SUPER::event_part;
119 $self->destroy;
120 }
121
122 sub event_quit {
123 my ($self) = @_;
124
125 $self->SUPER::event_quit;
126 $self->destroy;
127 }
128
129 sub event_update_roominfo {
130 my ($self) = @_;
131
132 $self->{chat}->append_text("\n<user>" . (util::toxml $self->{owner}) . "</user>\n"
133 . "<description>" . (util::toxml $self->{description}) . "</description>\n");
134 }
135
136 sub new_game {
137 my ($self) = @_;
138
139 my $game = new game conn => $self->{conn}, app => $self->{app}, roomid => $self->{channel};
140 $game->new_game_challenge;
141 $game->show_all;
142
143 push @{$self->{new_game}}, $game;
144 }
145
146 1;
147