--- deliantra/Deliantra-Client/DC/Util.pm 2006/04/07 16:30:23 1.3 +++ deliantra/Deliantra-Client/DC/Util.pm 2006/04/07 18:27:54 1.8 @@ -1,14 +1,34 @@ package Client::Util; +use strict; +use base 'Exporter'; +use Data::Dumper; +our @EXPORT = qw(find_rcfile); + use Gtk2; +sub find_rcfile($) { + my $path; + + for (@INC) { + $path = "$_/Crossfire/Client/$_[0]"; + return $path if -r $path; + } + + die "FATAL: can't find required file $_[0]\n"; +} + sub read_cfg { my ($file) = @_; open CFG, $file or return; + my $CFG; + local $/; - $::CFG = eval ; + $CFG = eval ; + + $::CFG = $CFG; close CFG; } @@ -34,6 +54,10 @@ my $i = $cfg->{_i}++; $tbl->attach_defaults (my $lbl = Gtk2::Label->new ($klbl), 0, 1, $i, $i + 1); $tbl->attach_defaults (my $ent = Gtk2::Entry->new, 1, 2, $i, $i + 1); + if ($key eq 'password') { + $ent->set_invisible_char ("*"); + $ent->set (visibility => 0) + } $ent->set_text ($value); $ent->signal_connect (changed => sub { my ($ent) = @_; @@ -42,13 +66,17 @@ } sub run_config_dialog { - Gtk2->init; + my (%events) = @_; my $w = Gtk2::Window->new; my @cfg = ( - [qw/Width width/], - [qw/Height height/], + [qw/Width width/], + [qw/Height height/], + [qw/Host host/], + [qw/Port port/], + [qw/Username user/], + [qw/Password password/], ); my $cfg = {}; @@ -60,16 +88,30 @@ } $vb->pack_start (my $hb = Gtk2::HBox->new, 0, 0, 0); - $hb->pack_start (my $cb = Gtk2::Button->new ("close"), 1, 1, 5); - $cb->signal_connect (clicked => sub { $w->destroy }); $hb->pack_start (my $cb = Gtk2::Button->new ("save"), 1, 1, 5); $cb->signal_connect (clicked => sub { for (keys %$cfg) { $::CFG->{$_} = $cfg->{$_} if $_ ne '_i'; } - $w->destroy + write_cfg "$Crossfire::VARDIR/pclientrc"; }); + $hb->pack_start (my $cb = Gtk2::Button->new ("login"), 1, 1, 5); + $cb->signal_connect (clicked => sub { + for (keys %$cfg) { + $::CFG->{$_} = $cfg->{$_} + if $_ ne '_i'; + } + my $cb = $events{login} || sub {}; + $cb->($::CFG->{user}, $::CFG->{password}); + }); + $hb->pack_start (my $cb = Gtk2::Button->new ("logout"), 1, 1, 5); + $cb->signal_connect (clicked => sub { + my $cb = $events{login} || sub {}; + $cb->(); + }); + $hb->pack_start (my $cb = Gtk2::Button->new ("quit"), 1, 1, 5); + $cb->signal_connect (clicked => sub { $w->destroy }); $w->show_all;