ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/kgsueme/kgsueme/user.pl
Revision: 1.9
Committed: Tue Jun 8 19:42:36 2004 UTC (19 years, 11 months ago) by elmex
Content type: text/plain
Branch: MAIN
Changes since 1.8: +28 -1 lines
Log Message:
Added the Gamerecord list

File Contents

# Content
1 package user;
2
3 use List::Util;
4
5 use base KGS::Listener::User;
6
7 use Glib::Object::Subclass
8 Gtk2::Window;
9
10 use Gtk2::SimpleList;
11
12 sub new {
13 my ($self, %arg) = @_;
14 $self = $self->Glib::Object::new;
15 $self->{$_} = delete $arg{$_} for keys %arg;
16
17 $self->listen ($self->{conn});
18
19 $self->send (notify_add => name => $self->{name})
20 unless (lc $self->{name}) eq (lc $self->{app}{name});
21
22 gtk::state $self, "user::window", undef, window_size => [400, 300];
23
24 $self->event_name;
25
26 $self->signal_connect (destroy => sub { %{$_[0]} = () });
27 $self->signal_connect (delete_event => sub { $self->destroy; 1 });
28
29 my $notebook = new Gtk2::Notebook;
30
31 $notebook->signal_connect (switch_page => sub {
32 my ($notebook, undef, $page) = @_;
33
34 $self->userinfo if $page == 1;
35 $self->game_record if $page == 2;
36 $self->usergraph if $page == 3;
37 });
38
39 $self->add ($notebook);
40
41 $self->{chat} = new chat;
42 $self->{chat}->signal_connect(command => sub {
43 my ($chat, $cmd, $arg) = @_;
44 $self->{app}->do_command ($chat, $cmd, $arg, user => $self);
45 });
46
47 $notebook->append_page ($self->{chat}, (new_with_mnemonic Gtk2::Label "_Chat"));
48
49 $self->{page_userinfo} = new Gtk2::Table 3, 5, 0;
50 $notebook->append_page ($self->{page_userinfo}, (new_with_mnemonic Gtk2::Label "_Info"));
51
52 $self->{page_record} = new Gtk2::ScrolledWindow;
53 $self->{page_record}->set_policy ("automatic", "always");
54 $self->{page_record}->add ($self->{record_list} = Gtk2::SimpleList->new(
55 "Time" => "text",
56 "Black" => "text",
57 "White" => "text",
58 "Size" => "text",
59 "Handicap" => "int",
60 "Komi" => "text",
61 "Score" => "text"
62 ));
63 $notebook->append_page ($self->{page_record}, (new_with_mnemonic Gtk2::Label "_Record"));
64
65 $self->{page_graph} = new Gtk2::Curve;
66 $notebook->append_page ($self->{page_graph}, (new_with_mnemonic Gtk2::Label "_Graph"));
67
68
69 $self;
70 }
71
72 sub join {
73 my ($self) = @_;
74
75 $self->show_all;
76 }
77
78 sub event_name {
79 my ($self) = @_;
80
81 $self->set_title("KGS User $self->{name}");
82 }
83
84 sub event_userinfo {
85 my ($self) = @_;
86
87 my $ui = $self->{page_userinfo};
88
89 $ui->attach_defaults ((new Gtk2::Label "Name"), 0, 1, 0, 1);
90 $ui->attach_defaults ((new Gtk2::Label "Email"), 0, 1, 1, 2);
91 $ui->attach_defaults ((new Gtk2::Label "Registered"), 0, 1, 2, 3);
92 $ui->attach_defaults ((new Gtk2::Label "Last Login"), 0, 1, 3, 4);
93
94 $ui->attach_defaults ((new Gtk2::Label $self->{userinfo}{realname}), 1, 2, 0, 1);
95 $ui->attach_defaults ((new Gtk2::Label $self->{userinfo}{email}), 1, 2, 1, 2);
96 $ui->attach_defaults ((new Gtk2::Label $self->{userinfo}{regdate}), 1, 2, 2, 3);
97 $ui->attach_defaults ((new Gtk2::Label $self->{userinfo}{lastlogin}), 1, 2, 3, 4);
98
99 if ($self->{userinfo}{user}->has_pic) {
100 $self->{app}->userpic ($self->{name}, sub {
101 if ($_[0]) {
102 $ui->attach_defaults ((gtk::image_from_data $_[0]), 2, 3, 0, 4);
103 $ui->show_all;
104 }
105 });
106 }
107
108 $ui->attach_defaults ((new Gtk2::Label $self->{userinfo}{info}), 0, 2, 4, 5);
109
110 $ui->show_all;
111 }
112
113 sub event_game_record {
114 my ($self) = @_;
115
116 for (reverse sort { $a->{timestamp} <=> $b->{timestamp} } @{$self->{game_record}}) {
117 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($_->{timestamp});
118 push @{$self->{record_list}->{data}},
119 [
120 sprintf ("%02d.%02d.%04d %02d:%02d", $mday, $mon + 1, $year + 1900, $hour, $min),
121 $_->{black}->{name},
122 $_->{white}->{name},
123 sprintf ("%dx%d", $_->size, $_->size),
124 sprintf ("%.1d", $_->handicap),
125 $_->komi,
126 $_->score_string
127 ];
128 }
129 }
130
131 sub event_usergraph {
132 my ($self) = @_;
133
134 my $graph = $self->{usergraph};
135
136 my $curve = $self->{page_graph};
137
138 if (@$graph) {
139 $curve->set_range (0, (scalar @graph) - 1, (List::Util::min @$graph) - 1, (List::Util::max @$graph) + 1);
140 $curve->set_vector (@$graph);
141 }
142 }
143
144 sub event_msg {
145 my ($self, $name, $message) = @_;
146
147 $message =~ s/&/&amp;/g;
148 $message =~ s/</&lt;/g;
149
150 $self->{chat}->append_text ("\n<user>$name</user>: $message");
151 }
152
153 sub destroy {
154 my ($self) = @_;
155
156 $self->send (notify_del => name => $self->{name})
157 unless (lc $self->{name}) eq (lc $self->{app}{name});
158
159 $self->SUPER::destroy;
160 }
161
162 1;
163