ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/kgsueme/kgsueme/user.pl
Revision: 1.6
Committed: Sat Aug 16 00:03:19 2003 UTC (20 years, 9 months ago) by pcg
Content type: text/plain
Branch: MAIN
CVS Tags: stable
Changes since 1.5: +0 -1 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     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 pcg 1.5 $self->send (notify_add => name => $self->{name})
15     unless (lc $self->{name}) eq (lc $self->{app}{name});
16 pcg 1.1
17     $self->{window} = new Gtk2::Window 'toplevel';
18 pcg 1.5 $self->event_name;
19 pcg 1.1 gtk::state $self->{window}, "user::window", undef, window_size => [400, 300];
20    
21     $self->{window}->signal_connect(delete_event => sub { $self->destroy; 1 });
22    
23 pcg 1.2 my $notebook = new Gtk2::Notebook;
24    
25     $notebook->signal_connect (switch_page => sub {
26     my ($notebook, undef, $page) = @_;
27    
28     $self->userinfo if $page == 1;
29     $self->game_record if $page == 2;
30     $self->usergraph if $page == 3;
31     });
32    
33     $self->{window}->add ($notebook);
34    
35 pcg 1.4 $self->{chat} = new chat;
36     $self->{chat}->signal_connect(command => sub {
37     my ($chat, $cmd, $arg) = @_;
38     $self->{app}->do_command ($chat, $cmd, $arg, user => $self);
39     });
40    
41     $notebook->append_page ($self->{chat}, (new_with_mnemonic Gtk2::Label "_Chat"));
42    
43 pcg 1.2
44 pcg 1.3 $self->{page_userinfo} = new Gtk2::Table 3, 5, 0;
45 pcg 1.2 $notebook->append_page ($self->{page_userinfo}, (new_with_mnemonic Gtk2::Label "_Info"));
46    
47 pcg 1.4
48 pcg 1.2 $self->{page_record} = new Gtk2::VBox;
49 pcg 1.4 $notebook->append_page ($self->{page_record}, (new_with_mnemonic Gtk2::Label "_Record"));
50 pcg 1.2
51    
52     $self->{page_graph} = new Gtk2::Curve;
53 pcg 1.4 $notebook->append_page ($self->{page_graph}, (new_with_mnemonic Gtk2::Label "_Graph"));
54 pcg 1.2
55    
56 pcg 1.1 $self;
57 pcg 1.2 }
58    
59     sub join {
60     my ($self) = @_;
61    
62     $self->{window}->show_all;
63     }
64    
65 pcg 1.5 sub event_name {
66     my ($self) = @_;
67    
68     $self->{window}->set_title("KGS User $self->{name}");
69     }
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     $self->{chat}->append_text ("\n<user>$name</user>: $message");
121 pcg 1.1 }
122    
123     sub destroy {
124     my ($self) = @_;
125    
126 pcg 1.5 $self->send (notify_del => name => $self->{name})
127     unless (lc $self->{name}) eq (lc $self->{app}{name});
128 pcg 1.1
129     $self->SUPER::destroy;
130     }
131    
132     1;
133