ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/kgsueme/kgsueme/user.pl
Revision: 1.8
Committed: Thu May 20 23:17:25 2004 UTC (20 years ago) by pcg
Content type: text/plain
Branch: MAIN
Changes since 1.7: +14 -14 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 pcg 1.1 package user;
2    
3 pcg 1.2 use List::Util;
4 pcg 1.1
5     use base KGS::Listener::User;
6 pcg 1.8
7     use Glib::Object::Subclass
8     Gtk2::Window;
9 pcg 1.1
10     sub new {
11 pcg 1.8 my ($self, %arg) = @_;
12     $self = $self->Glib::Object::new;
13     $self->{$_} = delete $arg{$_} for keys %arg;
14 pcg 1.1
15 pcg 1.8 $self->listen ($self->{conn});
16 pcg 1.1
17 pcg 1.5 $self->send (notify_add => name => $self->{name})
18     unless (lc $self->{name}) eq (lc $self->{app}{name});
19 pcg 1.1
20 pcg 1.8 gtk::state $self, "user::window", undef, window_size => [400, 300];
21    
22 pcg 1.5 $self->event_name;
23 pcg 1.1
24 pcg 1.8 $self->signal_connect (destroy => sub { %{$_[0]} = () });
25     $self->signal_connect (delete_event => sub { $self->destroy; 1 });
26 pcg 1.1
27 pcg 1.2 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 pcg 1.8 $self->add ($notebook);
38 pcg 1.2
39 pcg 1.4 $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 pcg 1.3 $self->{page_userinfo} = new Gtk2::Table 3, 5, 0;
48 pcg 1.2 $notebook->append_page ($self->{page_userinfo}, (new_with_mnemonic Gtk2::Label "_Info"));
49    
50     $self->{page_record} = new Gtk2::VBox;
51 pcg 1.4 $notebook->append_page ($self->{page_record}, (new_with_mnemonic Gtk2::Label "_Record"));
52 pcg 1.2
53     $self->{page_graph} = new Gtk2::Curve;
54 pcg 1.4 $notebook->append_page ($self->{page_graph}, (new_with_mnemonic Gtk2::Label "_Graph"));
55 pcg 1.2
56 pcg 1.1 $self;
57 pcg 1.2 }
58    
59     sub join {
60     my ($self) = @_;
61    
62 pcg 1.8 $self->show_all;
63 pcg 1.2 }
64    
65 pcg 1.5 sub event_name {
66     my ($self) = @_;
67    
68 pcg 1.8 $self->set_title("KGS User $self->{name}");
69 pcg 1.5 }
70    
71 pcg 1.2 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 pcg 1.4 my ($self, $name, $message) = @_;
119    
120 pcg 1.7 $message =~ s/&/&/g;
121     $message =~ s/</&lt;/g;
122    
123 pcg 1.4 $self->{chat}->append_text ("\n<user>$name</user>: $message");
124 pcg 1.1 }
125    
126     sub destroy {
127     my ($self) = @_;
128    
129 pcg 1.5 $self->send (notify_del => name => $self->{name})
130     unless (lc $self->{name}) eq (lc $self->{app}{name});
131 pcg 1.1
132     $self->SUPER::destroy;
133     }
134    
135     1;
136