| dotReader documentation | Contained in the dotReader distribution. |
dtRdr::GUI::Wx::Dialog::Password - password dialog
Ask the user for a username and password.
A class method ...
my ($u, $p) = dtRdr::GUI::Wx::Dialog::Password->get_credentials(
$parent,
config => $object,
uri => $uri,
realm => $realm,
);
This dialog should work with or without a config object.
$pw->init();
$self->init_dialog($evt);
$self->set_config($config);
What? This didn't get bound?
$self->OnOK;
Eric Wilhelm <ewilhelm at cpan dot org>
http://scratchcomputing.com/
Copyright (C) 2007 Eric L. Wilhelm and OSoft, All Rights Reserved.
Absolutely, positively NO WARRANTY, neither express or implied, is offered with this software. You use this software at your own risk. In case of loss, no person or entity owes you anything whatsoever. You have been warned.
The dotReader(TM) is OSI Certified Open Source Software licensed under the GNU General Public License (GPL) Version 2, June 1991. Non-encrypted and encrypted packages are usable in connection with the dotReader(TM). The ability to create, edit, or otherwise modify content of such encrypted packages is self-contained within the packages, and NOT provided by the dotReader(TM), and is addressed in a separate commercial license.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
| dotReader documentation | Contained in the dotReader distribution. |
package dtRdr::GUI::Wx::Dialog::Password; $VERSION = eval{require version}?version::qv($_):$_ for(0.0.1); use warnings; use strict; use Carp; use base 'dtRdr::GUI::Wx::Dialog::Password0'; use Class::Accessor::Classy; rw 'config'; no Class::Accessor::Classy;
sub get_credentials { my $package = shift; (@_ % 2) or croak "odd number of options in argument list"; my ($parent, %opts) = @_; my %own_opts; foreach my $key (qw(config)) { exists($opts{$key}) or next; $own_opts{$key} = delete($opts{$key}); } my %args; foreach my $key (qw(realm uri)) { $args{$key} = delete($opts{$key}) || ''; } $opts{title} ||= 'Authentication Required'; my $self = $package->new($parent, %opts); my $message = "Password required for '$args{realm}'" . ($args{uri} ? "\n($args{uri})" : ''); # naive word-wrap because ->Wrap doesn't work $message =~ s/(.{40,50}\b)/$1\n/g; $self->label_message->SetLabel($message); #$self->label_message->Wrap; # XXX not there #$self->GetSizer->Layout; #$self->SetSize(Wx::Size->new(400,300)); # uh, why am I repeating myself here? $self->GetSizer->SetSizeHints($self); $self->Layout(); foreach my $key (keys %own_opts) { $self->${\("set_$key")}($own_opts{$key}); } $self->init; $self->ShowModal == Wx::wxID_OK() or return; my ($u, $p) = (map({$self->${\('value_'.$_)}->GetValue} qw(username password))); if(my $config = $self->config) { my $cu = $config->username; my $cp = $config->password; if(not defined($cu) or (defined($cu) and ($u ne $cu))) { $config->set_username($u); } if($self->checkbox_save->IsChecked and not (defined($cp) and ($cp eq $p)) ) { warn "write pasword"; $config->set_password($p);# unless(defined($cp) and ($cp eq $p)); } } return($u, $p) } # end subroutine get_credentials definition ########################################################################
sub init { my $self = shift; # setup the events Wx::Event::EVT_INIT_DIALOG($self, sub {shift->init_dialog(@_)}); #Wx::Event::EVT_SET_FOCUS($self, sub {warn "focus!"}); #Wx::Event::EVT_TEXT_ENTER($self, $self->$_, sub {warn "enter!"; $self->OnOK}) # for(qw(value_username value_password)); Wx::Event::EVT_TEXT_ENTER($self, $self->value_username, sub {$self->value_password->SetFocus}); Wx::Event::EVT_TEXT_ENTER($self, $self->value_password, sub {$self->OnOK}); # XXX yet another difficult thing to get right Wx::Event::EVT_KEY_DOWN($self->checkbox_save, sub { my ($obj, $evt) = @_; my $code = $evt->GetKeyCode; if($code == Wx::WXK_RETURN()) { $self->OnOK } elsif($code == Wx::WXK_ESCAPE()) { $self->Close; } else { $evt->Skip; } }); if(1) { # XXX grr! ShowModal ignores my SetFocus in init_dialog! my $once = 0; Wx::Event::EVT_SET_FOCUS($self->value_username, sub { $once++ and return; if($self->config and defined($self->config->username)) { $self->value_password->SetFocus } } ); # and this as a workaround for the workaround! Wx::Event::EVT_SET_FOCUS($self->value_password, sub { $once++; }); } } # end subroutine init definition ########################################################################
sub init_dialog { my $self = shift; $self->TransferDataToWindow; my $empty = 'value_username'; if(my $config = $self->config) { my @populate = map({[$_, 'value_' . $_]} qw(username password)); foreach my $field (@populate) { my ($from, $to) = @$field; if(defined(my $val = $config->$from())) { $self->$to()->SetValue($val); } } $empty = 'value_password' if(defined($config->username)); } # warn "empty is $empty"; $self->$empty->SetFocus; $self->checkbox_save->Enable(0) unless($self->config); } # end subroutine init_dialog definition ########################################################################
sub set_config { my $self = shift; my ($config) = @_; $self->checkbox_save->Enable(defined($config) ? 1 : 0); $self->SUPER::set_config($config); } # end subroutine set_config definition ######################################################################## #sub Show {warn "show?"; shift->SUPER::Show(@_)}; #sub ShowModal {warn "huh?"; shift->SUPER::ShowModal}; #sub SetFocus {warn "SetFocus"; shift->SUPER::SetFocus(@_)}; #sub OnSetFocus {warn "OnSetFocus"; shift->SUPER::OnSetFocus(@_)};
sub OnOK { my $self = shift; if($self->IsModal) { $self->EndModal(Wx::wxID_OK()); } else { $self->SetReturnCode(Wx::wxID_OK()); $self->Show(0); } } # end subroutine OnOK definition ########################################################################
# vi:ts=2:sw=2:et:sta 1;