ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/kgsueme/kgsueme/app.pl
(Generate patch)

Comparing kgsueme/kgsueme/app.pl (file contents):
Revision 1.8 by pcg, Thu May 20 22:59:55 2004 UTC vs.
Revision 1.9 by pcg, Thu May 20 23:09:53 2004 UTC

3use KGS::Protocol::Client; 3use KGS::Protocol::Client;
4 4
5use Scalar::Util; 5use Scalar::Util;
6 6
7use base KGS::Listener; 7use base KGS::Listener;
8use base gtk::widget; 8
9use Glib::Object::Subclass
10 Gtk2::Window;
9 11
10my %context_id; 12my %context_id;
13
14our $self;
11 15
12sub status { 16sub status {
13 my ($type, $text) = @_; 17 my ($type, $text) = @_;
14 18
15 $self->{status}->pop($context_id{$type}) if $context_id{$type}; 19 $::self->{status}->pop ($context_id{$type}) if $context_id{$type};
16 $self->{status}->push($context_id{$type} ||= $self->{status}->get_context_id($type), $text) if $text; 20 $::self->{status}->push ($context_id{$type} ||= $::self->{status}->get_context_id ($type), $text) if $text;
17} 21}
18 22
19sub new { 23sub new {
20 my $self = shift; 24 my $self = shift;
21 $self = $self->SUPER::new(@_); 25 $self = $self->Glib::Object::new;
22 26
23 $app::self = $self; # singleton 27 Scalar::Util::weaken ($::self = $self); # singleton...
24 Scalar::Util::weaken $app::self;
25 28
26 $self->{conn} = new KGS::Protocol::Client; 29 $self->{conn} = new KGS::Protocol::Client;
27 30
28 #KGS::Listener::Debug->new->listen($self->{conn}, "any"); #d# debug only :)
29
30 $self->listen($self->{conn}, qw(login userpic idle_warn msg_chat)); 31 $self->listen ($self->{conn}, qw(login userpic idle_warn msg_chat));
31 32
32 $self->{roomlist} = new roomlist conn => $self->{conn}, app => $self; 33 $self->{roomlist} = new roomlist conn => $self->{conn}, app => $self;
33 34
34 $self->{window} = new Gtk2::Window 'toplevel';
35 $self->{window}->set_title('kgsueme'); 35 $self->set_title ('kgsueme');
36 gtk::state $self->{window}, "main::window", undef, window_size => [400, 400]; 36 gtk::state $self, "main::window", undef, window_size => [400, 400];
37 $self->signal_connect (destroy => sub { %{$_[0]} = () });
37 $self->{window}->signal_connect(delete_event => sub { main_quit Gtk2; 1 }); 38 $self->signal_connect (delete_event => sub { main_quit Gtk2; 1 });
38 39
39 $self->{window}->add(my $vbox = new Gtk2::VBox); 40 $self->add (my $vbox = new Gtk2::VBox);
40 41
41 $vbox->pack_start(($buttonbox = new Gtk2::HButtonBox), 0, 1, 0); 42 $vbox->pack_start (($buttonbox = new Gtk2::HButtonBox), 0, 1, 0);
42 $buttonbox->set_spacing(0); 43 $buttonbox->set_spacing (0);
43 44
44 my $button = sub { 45 my $button = sub {
45 $buttonbox->add(my $button = new Gtk2::Button $_[0]); 46 $buttonbox->add (my $button = new Gtk2::Button $_[0]);
46 signal_connect $button clicked => $_[1]; 47 signal_connect $button clicked => $_[1];
47 }; 48 };
48 49
49 $button->("Login", sub { $self->login; }); 50 $button->("Login", sub { $self->login; });
50 $button->("Roomlist", sub { $self->{roomlist}->show; }); 51 $button->("Roomlist", sub { $self->{roomlist}->show; });
51 $button->("Save Config & Layout", \&util::save_config); 52 $button->("Save Config & Layout", \&util::save_config);
52 $button->("Quit", sub { main_quit Gtk2 }); 53 $button->("Quit", sub { main_quit Gtk2 });
53 54
54 $vbox->pack_start((my $hbox = new Gtk2::HBox), 0, 1, 0); 55 $vbox->pack_start ((my $hbox = new Gtk2::HBox), 0, 1, 0);
55 56
56 $hbox->add(new Gtk2::Label "Login"); 57 $hbox->add (new Gtk2::Label "Login");
57 58
58 $hbox->add($self->{login} = new_with_max_length Gtk2::Entry 12); 59 $hbox->add ($self->{login} = new_with_max_length Gtk2::Entry 12);
59 $self->{login}->set_text($::config->{login}); 60 $self->{login}->set_text ($::config->{login});
60 61
61 $hbox->add(new Gtk2::Label "Password"); 62 $hbox->add (new Gtk2::Label "Password");
62 $hbox->add($self->{password} = new Gtk2::Entry); 63 $hbox->add ($self->{password} = new Gtk2::Entry);
63 $self->{password}->set_visibility(0); 64 $self->{password}->set_visibility(0);
64 65
65 $self->{gamelist} = new gamelist conn => $self->{conn}, app => $self; 66 $self->{gamelist} = new gamelist conn => $self->{conn}, app => $self;
66 $vbox->pack_start ($self->{gamelist}->widget, 1, 1, 0); 67 $vbox->pack_start ($self->{gamelist}->widget, 1, 1, 0);
67 68
68 $vbox->pack_start(($self->{status} = new Gtk2::Statusbar), 0, 1, 0); 69 $vbox->pack_start(($self->{status} = new Gtk2::Statusbar), 0, 1, 0);
69 70
70 $self->{window}->show_all; 71 $self->show_all;
71 72
72 $self; 73 $self;
73} 74}
74 75
75sub login { 76sub login {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines