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