ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/kgsueme/kgsueme/user.pl
Revision: 1.4
Committed: Mon Aug 4 00:30:10 2003 UTC (20 years, 10 months ago) by pcg
Content type: text/plain
Branch: MAIN
Changes since 1.3: +15 -5 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 package user;
2
3 use List::Util;
4
5 use base KGS::Listener::User;
6 use base gtk::widget;
7
8 sub new {
9 my $self = shift;
10 $self = $self->SUPER::new(@_);
11
12 $self->listen($self->{conn});
13
14 $self->send (notify_add => name => $self->{name});
15
16 $self->{window} = new Gtk2::Window 'toplevel';
17 $self->{window}->set_title("KGS User $self->{name}");
18 gtk::state $self->{window}, "user::window", undef, window_size => [400, 300];
19
20 $self->{window}->signal_connect(delete_event => sub { $self->destroy; 1 });
21
22 my $notebook = new Gtk2::Notebook;
23
24 $notebook->signal_connect (switch_page => sub {
25 my ($notebook, undef, $page) = @_;
26
27 $self->userinfo if $page == 1;
28 $self->game_record if $page == 2;
29 $self->usergraph if $page == 3;
30 });
31
32 $self->{window}->add ($notebook);
33
34 $self->{chat} = new chat;
35 $self->{chat}->signal_connect(command => sub {
36 my ($chat, $cmd, $arg) = @_;
37 $self->{app}->do_command ($chat, $cmd, $arg, user => $self);
38 });
39
40 $notebook->append_page ($self->{chat}, (new_with_mnemonic Gtk2::Label "_Chat"));
41
42
43 $self->{page_userinfo} = new Gtk2::Table 3, 5, 0;
44 $notebook->append_page ($self->{page_userinfo}, (new_with_mnemonic Gtk2::Label "_Info"));
45
46
47 $self->{page_record} = new Gtk2::VBox;
48 $notebook->append_page ($self->{page_record}, (new_with_mnemonic Gtk2::Label "_Record"));
49
50
51 $self->{page_graph} = new Gtk2::Curve;
52 $notebook->append_page ($self->{page_graph}, (new_with_mnemonic Gtk2::Label "_Graph"));
53
54
55 $self;
56 }
57
58 sub join {
59 my ($self) = @_;
60
61 $self->{window}->show_all;
62 }
63
64 sub event_userinfo {
65 my ($self) = @_;
66
67 my $ui = $self->{page_userinfo};
68
69 $ui->attach_defaults ((new Gtk2::Label "Name"), 0, 1, 0, 1);
70 $ui->attach_defaults ((new Gtk2::Label "Email"), 0, 1, 1, 2);
71 $ui->attach_defaults ((new Gtk2::Label "Registered"), 0, 1, 2, 3);
72 $ui->attach_defaults ((new Gtk2::Label "Last Login"), 0, 1, 3, 4);
73
74 $ui->attach_defaults ((new Gtk2::Label $self->{userinfo}{realname}), 1, 2, 0, 1);
75 $ui->attach_defaults ((new Gtk2::Label $self->{userinfo}{email}), 1, 2, 1, 2);
76 $ui->attach_defaults ((new Gtk2::Label $self->{userinfo}{regdate}), 1, 2, 2, 3);
77 $ui->attach_defaults ((new Gtk2::Label $self->{userinfo}{lastlogin}), 1, 2, 3, 4);
78
79 if ($self->{userinfo}{user}->has_pic) {
80 $self->{app}->userpic ($self->{name}, sub {
81 if ($_[0]) {
82 $ui->attach_defaults ((gtk::image_from_data $_[0]), 2, 3, 0, 4);
83 $ui->show_all;
84 }
85 });
86 }
87
88 $ui->attach_defaults ((new Gtk2::Label $self->{userinfo}{info}), 0, 2, 4, 5);
89
90 $ui->show_all;
91 }
92
93 sub event_game_record {
94 my ($self) = @_;
95 }
96
97 sub event_usergraph {
98 my ($self) = @_;
99
100 my $graph = $self->{usergraph};
101
102 my $curve = $self->{page_graph};
103
104 if (@$graph) {
105 $curve->set_range (0, (scalar @graph) - 1, (List::Util::min @$graph) - 1, (List::Util::max @$graph) + 1);
106 $curve->set_vector (@$graph);
107 }
108 }
109
110 sub event_msg {
111 my ($self, $name, $message) = @_;
112
113 $self->{chat}->append_text ("\n<user>$name</user>: $message");
114 warn "MSG($name => $message)\n";#d#
115 }
116
117 sub destroy {
118 my ($self) = @_;
119
120 $self->send (notify_del => name => $self->{name});
121
122 $self->SUPER::destroy;
123 }
124
125 1;
126