package appwin; use base KGS::Listener; my %context_id; sub status { my ($type, $text) = @_; $self->{status}->pop($context_id{$type}) if $context_id{$type}; $self->{status}->push($context_id{$type} ||= $self->{status}->get_context_id($type), $text) if $text; } sub new { my $self = shift; $self = $self->SUPER::new(@_); $appwin::self = $self; # singleton $self->{conn} = new KGS::Protocol; KGS::Listener::Debug->new->listen($self->{conn}, "any"); #d# debug only :) $self->listen($self->{conn}, "login"); $self->{roomlist} = new roomlist conn => $self->{conn}; $self->{window} = new Gtk2::Window 'toplevel'; $self->{window}->set_title('kgsueme'); gtk::state $self->{window}, "main::window", undef, window_size => [400, 100]; $self->{window}->signal_connect(delete_event => sub { main_quit Gtk2; 1 }); $self->{window}->add(my $vbox = new Gtk2::VBox); $vbox->pack_start(($buttonbox = new Gtk2::HButtonBox), 0, 1, 0); $buttonbox->set_spacing(0); my $button = sub { $buttonbox->add(my $button = new Gtk2::Button $_[0]); signal_connect $button clicked => $_[1]; }; $button->("Login", sub { $self->login; }); $button->("Roomlist", sub { $self->{roomlist}->show; }); $button->("Save Config & Layout", \&util::save_configstate); $button->("Quit", sub { main_quit Gtk2 }); $vbox->pack_start((my $hbox = new Gtk2::HBox), 0, 1, 0); $hbox->add(new Gtk2::Label "Login"); $hbox->add($self->{login} = new_with_max_length Gtk2::Entry 12); $self->{login}->set_text($::config->{login}); if ($::HACK) { $self->{login}->signal_connect(activate => sub { $self->{conn}{name} = $self->{login}->get_text; }); } $hbox->add(new Gtk2::Label "Password"); $hbox->add($self->{password} = new Gtk2::Entry); $self->{password}->set_visibility(0); $vbox->pack_start(($self->{status} = new Gtk2::Statusbar), 0, 1, 0); $self->{window}->show_all; $self; } sub login { my ($self) = @_; $self->{conn}->disconnect; # initialize new socket and connection my $sock = new IO::Socket::INET PeerHost => "kgs.kiseido.com", PeerPort => "2379" or die; $sock->blocking(1); $self->{conn}->handshake($sock); $sock->blocking(0); my $input; $input = add_watch Glib::IO fileno $sock, [G_IO_IN, G_IO_ERR, G_IO_HUP], sub { # this is dorked my $buf; if (0 >= sysread $sock, $buf, 16384 and !$!{EINTR} and !$!{EAGAIN}) { remove Glib::Source $input; $self->event_disconnect; } $self->{conn}->feed_data($buf); 1; }, G_PRIORITY_HIGH; # now login $self->{conn}->login("kgsueme $VERSION $^O", $self->{login}->get_text, $self->{password}->get_text); } sub inject_login { my ($self, $msg) = @_; appwin::status("login", "logged in as '$self->{conn}{name}' with status '$msg->{result}'"); $::config->{login} = $self->{conn}{name}; if ($msg->{success}) { for (keys %{$::config->{rooms}}) { $self->{roomlist}->join_room($_); } sound::play 3, "connect"; } elsif ($msg->{result} eq "user unknown") { sound::play 2, "user_unknown"; } else { sound::play 2, "warning"; } } sub event_disconnect { } 1;