… | |
… | |
11 | use IO::Socket::INET; |
11 | use IO::Socket::INET; |
12 | |
12 | |
13 | use Errno; |
13 | use Errno; |
14 | |
14 | |
15 | init Gtk; |
15 | init Gtk; |
|
|
16 | |
|
|
17 | our $config; |
16 | |
18 | |
17 | { |
19 | { |
18 | use Storable (); |
20 | use Storable (); |
19 | use Scalar::Util (); |
21 | use Scalar::Util (); |
20 | |
22 | |
21 | my $staterc = "$ENV{HOME}/.kgsueme"; |
23 | my $staterc = "$ENV{HOME}/.kgsueme"; |
22 | |
24 | |
23 | my $state = -r $staterc ? Storable::retrieve($staterc) : {}; |
25 | my $state = -r $staterc ? Storable::retrieve($staterc) : {}; |
24 | my @widgets; |
26 | my @widgets; |
|
|
27 | |
|
|
28 | $config = $state->{config} ||= {}; |
25 | |
29 | |
26 | # grr... more gtk+ brokenness |
30 | # grr... more gtk+ brokenness |
27 | my %get = ( |
31 | my %get = ( |
28 | hpane_position => sub { ($_[0]->children)[0]->allocation->[2] }, |
32 | hpane_position => sub { ($_[0]->children)[0]->allocation->[2] }, |
29 | vpane_position => sub { ($_[0]->children)[0]->allocation->[3] }, |
33 | vpane_position => sub { ($_[0]->children)[0]->allocation->[3] }, |
… | |
… | |
127 | my $self = shift; |
131 | my $self = shift; |
128 | $self = $self->SUPER::new(@_); |
132 | $self = $self->SUPER::new(@_); |
129 | |
133 | |
130 | $self->{conn} = new KGS::Protocol; |
134 | $self->{conn} = new KGS::Protocol; |
131 | |
135 | |
132 | $self->login; |
|
|
133 | |
|
|
134 | KGS::Listener::Debug->new->listen($self->{conn}); #d# debug only :) |
136 | KGS::Listener::Debug->new->listen($self->{conn}); #d# debug only :) |
135 | |
137 | |
136 | $self->listen($self->{conn}); |
138 | $self->listen($self->{conn}); |
137 | |
139 | |
138 | $self->{window} = new Gtk::Window 'toplevel'; |
140 | $self->{window} = new Gtk::Window 'toplevel'; |
… | |
… | |
142 | |
144 | |
143 | $self->{window}->add(my $vbox = new Gtk::VBox); |
145 | $self->{window}->add(my $vbox = new Gtk::VBox); |
144 | |
146 | |
145 | $vbox->pack_start(($self->{buttonbox} = new Gtk::HButtonBox), 0, 1, 0); |
147 | $vbox->pack_start(($self->{buttonbox} = new Gtk::HButtonBox), 0, 1, 0); |
146 | |
148 | |
147 | $self->{buttonbox}->add(my $button = new Gtk::Button "Save Layout"); |
149 | my $button = sub { |
148 | signal_connect $button clicked => sub { ::save_state }; |
|
|
149 | |
|
|
150 | $self->{buttonbox}->add(my $button = new Gtk::Button "Roomlist"); |
150 | $self->{buttonbox}->add(my $button = new Gtk::Button $_[0]); |
151 | signal_connect $button clicked => sub { |
151 | signal_connect $button clicked => $_[1]; |
|
|
152 | }; |
|
|
153 | |
|
|
154 | $button->("Login", sub { |
|
|
155 | $self->login; |
|
|
156 | }); |
|
|
157 | $button->("Roomlist", sub { |
152 | $self->{roomlist} ||= new roomlist conn => $self->{conn}; |
158 | $self->{roomlist} ||= new roomlist conn => $self->{conn}; |
153 | $self->{roomlist}->show; |
159 | $self->{roomlist}->show; |
154 | }; |
160 | }); |
|
|
161 | $button->("Save Config & Layout", sub { ::save_state }); |
155 | |
162 | |
156 | $vbox->pack_start((my $hbox = new Gtk::HBox), 0, 1, 0); |
163 | $vbox->pack_start((my $hbox = new Gtk::HBox), 0, 1, 0); |
157 | |
164 | |
158 | $hbox->add(new Gtk::Label "Login"); |
165 | $hbox->add(new Gtk::Label "Login"); |
159 | |
166 | |
160 | $hbox->add($self->{login} = new_with_max_length Gtk::Entry 12); |
167 | $hbox->add($self->{login} = new_with_max_length Gtk::Entry 12); |
161 | $self->{login}->signal_connect(activate => sub { |
168 | $self->{login}->set_text($::config->{login}); |
162 | $self->{conn}{name} = $self->{login}->get_text; |
|
|
163 | }); |
|
|
164 | |
169 | |
165 | $hbox->add(new Gtk::Label "Password"); |
170 | $hbox->add(new Gtk::Label "Password"); |
166 | $hbox->add(my $pass = new Gtk::Entry); |
171 | $hbox->add($self->{password} = new Gtk::Entry); |
167 | $pass->set_visibility(0); |
172 | $self->{password}->set_visibility(0); |
168 | |
173 | |
169 | $vbox->pack_start(($self->{status} = new Gtk::Statusbar), 0, 1, 0); |
174 | $vbox->pack_start(($self->{status} = new Gtk::Statusbar), 0, 1, 0); |
170 | |
175 | |
171 | $self->{window}->show_all; |
176 | $self->{window}->show_all; |
172 | |
177 | |
173 | $self; |
178 | $self; |
174 | } |
179 | } |
175 | |
180 | |
176 | sub login { |
181 | sub login { |
177 | my ($self) = @_; |
182 | my ($self) = @_; |
|
|
183 | |
|
|
184 | $self->{conn}->disconnect; |
178 | |
185 | |
179 | # initialize new socket and connection |
186 | # initialize new socket and connection |
180 | my $sock = new IO::Socket::INET PeerHost => "kgs.kiseido.com", PeerPort => "2379" |
187 | my $sock = new IO::Socket::INET PeerHost => "kgs.kiseido.com", PeerPort => "2379" |
181 | or die; |
188 | or die; |
182 | |
189 | |
… | |
… | |
194 | } |
201 | } |
195 | $self->{conn}->feed_data($buf); |
202 | $self->{conn}->feed_data($buf); |
196 | }; |
203 | }; |
197 | |
204 | |
198 | # now login |
205 | # now login |
199 | $self->{conn}->login("dork", ""); |
206 | $self->{conn}->login($self->{login}->get_text, $self->{password}->get_text); |
200 | } |
207 | } |
201 | |
208 | |
202 | sub inject_login { |
209 | sub inject_login { |
203 | my ($self, $msg) = @_; |
210 | my ($self, $msg) = @_; |
204 | |
211 | |
205 | ::status("login", "logged in as '$self->{conn}{name}' with status '$msg->{result}'"); |
212 | ::status("login", "logged in as '$self->{conn}{name}' with status '$msg->{result}'"); |
206 | #$self->{login}->set_text($self->{conn}{name}); |
213 | $::config->{login} = $self->{conn}{name}; |
207 | |
214 | |
208 | $self->{window}->show_all; |
215 | $self->{window}->show_all; |
209 | } |
216 | } |
210 | |
217 | |
211 | sub event_disconnect { } |
218 | sub event_disconnect { } |