1 | package user; |
1 | package user; |
2 | |
2 | |
3 | use KGS::Constants; |
3 | use List::Util; |
4 | |
4 | |
5 | use base KGS::Listener::User; |
5 | use base KGS::Listener::User; |
6 | use base gtk::widget; |
6 | use base gtk::widget; |
7 | |
7 | |
8 | sub new { |
8 | sub new { |
… | |
… | |
17 | $self->{window}->set_title("KGS User $self->{name}"); |
17 | $self->{window}->set_title("KGS User $self->{name}"); |
18 | gtk::state $self->{window}, "user::window", undef, window_size => [400, 300]; |
18 | gtk::state $self->{window}, "user::window", undef, window_size => [400, 300]; |
19 | |
19 | |
20 | $self->{window}->signal_connect(delete_event => sub { $self->destroy; 1 }); |
20 | $self->{window}->signal_connect(delete_event => sub { $self->destroy; 1 }); |
21 | |
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 | $notebook->append_page (($self->{chat} = new chat), (new_with_mnemonic Gtk2::Label "_Chat")); |
|
|
35 | |
|
|
36 | $self->{page_userinfo} = new Gtk2::Table 3, 5; |
|
|
37 | |
|
|
38 | $notebook->append_page ($self->{page_userinfo}, (new_with_mnemonic Gtk2::Label "_Info")); |
|
|
39 | |
|
|
40 | $self->{page_record} = new Gtk2::VBox; |
|
|
41 | |
|
|
42 | $notebook->append_page ($self->{page_record}, (new_with_mnemonic Gtk2::Label "_Record")); |
|
|
43 | |
|
|
44 | $self->{page_graph} = new Gtk2::Curve; |
|
|
45 | |
|
|
46 | $notebook->append_page ($self->{page_graph}, (new_with_mnemonic Gtk2::Label "_Graph")); |
|
|
47 | |
22 | $self; |
48 | $self; |
|
|
49 | } |
|
|
50 | |
|
|
51 | sub join { |
|
|
52 | my ($self) = @_; |
|
|
53 | |
|
|
54 | $self->{window}->show_all; |
|
|
55 | } |
|
|
56 | |
|
|
57 | sub event_userinfo { |
|
|
58 | my ($self) = @_; |
|
|
59 | |
|
|
60 | my $ui = $self->{page_userinfo}; |
|
|
61 | |
|
|
62 | $ui->attach_defaults ((new Gtk2::Label "Name"), 0, 1, 0, 1); |
|
|
63 | $ui->attach_defaults ((new Gtk2::Label "Email"), 0, 1, 1, 2); |
|
|
64 | $ui->attach_defaults ((new Gtk2::Label "Registered"), 0, 1, 2, 3); |
|
|
65 | $ui->attach_defaults ((new Gtk2::Label "Last Login"), 0, 1, 3, 4); |
|
|
66 | |
|
|
67 | $ui->attach_defaults ((new Gtk2::Label $self->{userinfo}{realname}), 1, 2, 0, 1); |
|
|
68 | $ui->attach_defaults ((new Gtk2::Label $self->{userinfo}{email}), 1, 2, 1, 2); |
|
|
69 | $ui->attach_defaults ((new Gtk2::Label $self->{userinfo}{regdate}), 1, 2, 2, 3); |
|
|
70 | $ui->attach_defaults ((new Gtk2::Label $self->{userinfo}{lastlogin}), 1, 2, 3, 4); |
|
|
71 | |
|
|
72 | if ($self->{userinfo}{user}->has_pic) { |
|
|
73 | $self->{app}->userpic ($self->{name}, sub { |
|
|
74 | if ($_[0]) { |
|
|
75 | $ui->attach_defaults ((gtk::image_from_data $_[0]), 2, 3, 0, 4); |
|
|
76 | $ui->show_all; |
|
|
77 | } |
|
|
78 | }); |
|
|
79 | } |
|
|
80 | |
|
|
81 | $ui->attach_defaults ((new Gtk2::Label $self->{userinfo}{info}), 0, 2, 4, 5); |
|
|
82 | |
|
|
83 | $ui->show_all; |
|
|
84 | } |
|
|
85 | |
|
|
86 | sub event_game_record { |
|
|
87 | my ($self) = @_; |
|
|
88 | } |
|
|
89 | |
|
|
90 | sub event_usergraph { |
|
|
91 | my ($self) = @_; |
|
|
92 | |
|
|
93 | my $graph = $self->{usergraph}; |
|
|
94 | |
|
|
95 | my $curve = $self->{page_graph}; |
|
|
96 | |
|
|
97 | if (@$graph) { |
|
|
98 | $curve->set_range (0, (scalar @graph) - 1, (List::Util::min @$graph) - 1, (List::Util::max @$graph) + 1); |
|
|
99 | $curve->set_vector (@$graph); |
|
|
100 | } |
|
|
101 | } |
|
|
102 | |
|
|
103 | sub event_msg { |
|
|
104 | my ($self) = @_; |
23 | } |
105 | } |
24 | |
106 | |
25 | sub destroy { |
107 | sub destroy { |
26 | my ($self) = @_; |
108 | my ($self) = @_; |
27 | |
109 | |