=================================================================== RCS file: /cvs/palm/Palm-Keyring/examples/Attic/wxkeyring,v retrieving revision 1.1 retrieving revision 1.3 diff -u -r1.1 -r1.3 --- palm/Palm-Keyring/examples/Attic/wxkeyring 2007/02/01 01:57:09 1.1 +++ palm/Palm-Keyring/examples/Attic/wxkeyring 2007/02/03 00:47:36 1.3 @@ -95,7 +95,7 @@ # begin wxGlade: MainFrame::__set_properties - $self->SetTitle("GNU KeyRing"); + $self->SetTitle("GNU Keyring"); $self->{statusbar}->SetStatusWidths(-1); my( @statusbar_fields ) = ( @@ -168,15 +168,15 @@ } # Get the topic name from the list. - $topic = $self->{_keyringnames}->[$topic]; + my $rec = $self->{_keyringsortedrecs}->[$topic]; # Create the password dialog, if needed. my $d_passwd; if ( !$self->{_keyringdecryptor} ) { $d_passwd = Wx::TextEntryDialog->new ($self, - "Enter password for $topic", - "Enter KeyRing password", + "Enter password for $self->{_keyringfile}", + "Enter Keyring password", "", wxOK|wxCANCEL|wxTE_PASSWORD, wxDefaultPosition); @@ -194,7 +194,7 @@ return; } $ret = $d_passwd->GetValue; - $self->{_keyringdecryptor} = $self->{_keyringdb}->getDecryptor($ret); + $self->{_keyringdecryptor} = $self->{_keyringdb}->Password($ret); # Check for a valid decryptor. if ( !$self->{_keyringdecryptor} ) { my $md = Wx::MessageDialog->new @@ -211,7 +211,6 @@ } # Get the record. - my $rec = $self->{_keyringdb}->getRecordsByName($topic); if ( !$rec ) { my $md = Wx::MessageDialog->new ($self, "Topic \"$topic\" not found", @@ -222,35 +221,34 @@ $md->Destroy; next; } - $rec = $rec->[0]; # Decrypt it. - my ($name,$cat,$acc,$pass,$note,$mod) = - $self->{_keyringdecryptor}->decrypt($rec); + my ($acct) = $self->{_keyringdb}->Decrypt($rec); # Show values. - $self->{text_ctrl_category}->SetValue($cat); - $self->{text_ctrl_account}->SetValue($acc); + $self->{text_ctrl_category}->SetValue( + $self->{_keyringcategories}->[$rec->{category}]); + $self->{text_ctrl_account}->SetValue($acct->{account}); if ( $self->{checkbox_pw_veil}->IsChecked ) { $self->{text_ctrl_passwd}->SetValue("\x{2022}" x 8); } else { - $self->{text_ctrl_passwd}->SetValue($pass); + $self->{text_ctrl_passwd}->SetValue($acct->{password}); } if ( $self->{checkbox_pw_clip}->IsChecked ) { - $self->PutOnClipboard($pass); + $self->PutOnClipboard($acct->{password}); } else { $self->PutOnClipboard(undef); } - $note =~ s/\n+$//; - $self->{text_ctrl_note}->SetValue($note); + $acct->{notes} =~ s/\n+$//; + $self->{text_ctrl_note}->SetValue($acct->{notes}); - if ( $mod ) { + if ( $acct->{lastchange} ) { $self->{text_ctrl_mod}->SetValue (sprintf("%d-%02d-%02d", - 1900 + $mod->[0], - 1 + $mod->[1], - $mod->[2])); + 1900 + $acct->{lastchange}->{year}, + 1 + $acct->{lastchange}->{month}, + $acct->{lastchange}->{day})); } # Exit. @@ -289,12 +287,9 @@ $self->{button_fetch}->Enable(0); return; } - $topic = $self->{_keyringnames}->[$topic]; - $self->{text_ctrl_category}->SetValue - ($self->{_keyringdb}->getCategory - ($self->{_keyringdb}->getRecordsByName($topic)->[0]->{category})); + my $rec = $self->{_keyringsortedrecs}->[$topic]; + $self->{text_ctrl_category}->SetValue($self->{_keyringcategories}->[ $rec->{category} ]); - # end wxGlade } @@ -308,12 +303,12 @@ # end wxGlade } -sub LoadKeyRing { +sub LoadKeyring { my ($self, $file) = @_; # Load the database. eval { - $self->{_keyringdb} = ::loadKeyRing($file); + $self->{_keyringdb} = ::loadKeyring($file); }; if ( $@ ) { my $msg = $@; @@ -329,6 +324,19 @@ } $self->{_keyringfile} = $file; + my @cats; + foreach my $i (0..$#{ $self->{_keyringdb}->{appinfo}->{categories} }) { + push @cats, { + id => $i, + name => $self->{_keyringdb}->{appinfo}->{categories}->[$i]->{name}, + } + } + + $self->{_keyringcategories} = [ map { $_->{name} } @cats ]; + $self->{_keyringsortedcategoryids} = [ + map { $_->{id} } sort { $a->{name} cmp $b->{name} } @cats ]; + + undef($self->{_keyringdecryptor}); # It's no use to remember the cat mask, since codes will differ @@ -346,33 +354,34 @@ } # Prepend new choices to the Categories menu. - $i = 16; my $did = 0; $self->{_catmaskids} = []; - foreach ( reverse $self->{_keyringdb}->getCategories ) { - $i--; - next if !$did && !$_; # strip trailing unused categories - $_ ||= ""; - my $id = ::next_id(); - my $m = $catmenu->PrependCheckItem($id, $_, $_); + foreach my $i (reverse 0..$#{ $self->{_keyringsortedcategoryids} }) { + my $cat_id = $self->{_keyringsortedcategoryids}->[$i]; + my $name = $self->{_keyringcategories}->[$cat_id]; + next if !$name; + $name ||= ""; + my $id = ::next_id(); + my $m = $catmenu->PrependCheckItem($id, $name, $name); - # Remember for toggle access. - $self->{_catmaskids}->[$i] = $m; + # Remember for toggle access. + $self->{_catmaskids}->[$i] = $m; - # Set check status. - $m->Check($self->{_catmask} & (1 << $i)); + # Set check status. + $m->Check($self->{_catmask} & (1 << $i)); - # Handler. - my $maskno = $i; # lexical copy - Wx::Event::EVT_MENU($self, $id, sub { OnToggleCategory($self, $_[1], $maskno) }); + # Handler. + my $maskno = $i; # lexical copy + Wx::Event::EVT_MENU($self, $id, sub { + OnToggleCategory($self, $_[1], $maskno) }); - # Yes. - $did++; + # Yes. + $did++; } $self->UpdateCatMask; $self->{statusbar}->SetStatusText("File: $file, ". - ($self->{_keyringdb}->getRecords)." entries.", + (@{ $self->{_keyringdb}->{records} })." entries.", 0); } @@ -382,14 +391,14 @@ my $fd = Wx::FileDialog->new ($self, - "Choose KeyRing", + "Choose Keyring", "", "", "*.pdb", 0, wxDefaultPosition); my $ret = $fd->ShowModal; if ( $ret == wxID_OK ) { - $self->LoadKeyRing($fd->GetPath); + $self->LoadKeyring($fd->GetPath); } $fd->Destroy; @@ -403,7 +412,7 @@ my $md = Wx::MessageDialog->new ($self, - "wxKeyRing version $::VERSION\n". + "wxKeyring version $::VERSION\n". ::COPYRIGHT() . "\n\n". "Written by Johan Vromans\n". "\n". @@ -412,8 +421,8 @@ "Perl version ".sprintf("%vd",$^V)."\n". "WxPerl version $Wx::VERSION\n". "wxWidgets version ".Wx::wxVERSION."\n". - "Palm::KeyRing version $Palm::KeyRing::VERSION\n", - "About wxKeyRing", + "Palm::Keyring version $Palm::Keyring::VERSION\n", + "About wxKeyring", wxOK|wxICON_INFORMATION, wxDefaultPosition); $md->ShowModal; @@ -427,28 +436,28 @@ # Update check status on the category menu. for ( my $i = 0; $i < 16; $i++ ) { - my $m = $self->{_catmaskids}->[$i]; - next unless $m; - $m->Check($self->{_catmask} & (1 << $i)); + my $m = $self->{_catmaskids}->[$i]; + next unless $m; + $m->Check($self->{_catmask} & (1 << $i)); } # Update the list of displayed items. - if ( $self->{_catmask} == ~0 ) { - # All. - $self->{_keyringnames} = [sort { lc($a) cmp lc($b) } @{$self->{_keyringdb}->getNames}]; + my %id_by_cat; + foreach (0..$#{ $self->{_keyringsortedcategoryids} }) { + $id_by_cat{ $self->{_keyringsortedcategoryids}->[$_]} = $_; } - else { - # Selective. - $self->{_keyringnames} = []; - foreach my $k ( sort { lc($a) cmp lc($b) } @{$self->{_keyringdb}->getNames} ) { - my $rec = $self->{_keyringdb}->getRecordsByName($k); - $rec = $rec->[0]; - next unless $self->{_catmask} & (1 << $rec->{category}); - push(@{$self->{_keyringnames}}, $k); - } + $self->{_keyringsortedrecs} = []; + foreach my $rec ( sort { lc($a->{name}) cmp lc($b->{name}) } + @{ $self->{_keyringdb}->{records} } ) { + next unless $rec->{name}; + if ($self->{_catmask} != ~0) { + next unless $self->{_catmask} & (1 << + $id_by_cat{ $rec->{category} }); + } + push @{$self->{_keyringsortedrecs}}, $rec; } - $self->{list_box_topic}->Set($self->{_keyringnames}); - + $self->{list_box_topic}->Set( [ map { $_->{name} } + @{ $self->{_keyringsortedrecs} } ]); } sub OnSelectAllCategories { @@ -501,7 +510,7 @@ for ( 0, 1 ) { # Put it on the Clipboard as well as the Primary Selection. - wxTheClipboard->UsePrimarySelection($_); + wxTheClipboard->UsePrimarySelection($_); if ( $data ) { my $cb = Wx::TextDataObject->new($data); wxTheClipboard->Open; @@ -546,7 +555,7 @@ package main; -use Palm::KeyRing; +use Palm::Keyring; use Wx qw(wxID_HIGHEST); @@ -556,9 +565,11 @@ ++$next_id; } -sub loadKeyRing { +sub loadKeyring { my $file = shift; - Palm::KeyRing->new($file); + my $pdb = new Palm::Keyring; + $pdb->Load($file); + return $pdb; } sub COPYRIGHT() { @@ -579,7 +590,7 @@ "clip!" => \$clip, "password=s" => \$passwd, ) && @ARGV <= 1 - or die("Usage: $0 [ -geometry WxH+X+Y ] [ KeyRing ]\n"); + or die("Usage: $0 [ -geometry WxH+X+Y ] [ Keyring ]\n"); my ($w, $h, $x, $y) = (450, 300, -1, -1); if ( $geo =~ /^(?:(\d+)x(\d+))?(?:\+(\d+)\+(\d+))?$/ ) { @@ -605,14 +616,14 @@ $app->SetTopWindow($frame); $frame->Show(1); -$frame->LoadKeyRing($keyringfile) if $keyringfile; +$frame->LoadKeyring($keyringfile) if $keyringfile; $frame->{statusbar}->SetStatusText(COPYRIGHT, 0); # Presets. $frame->{checkbox_pw_clip}->SetValue($clip); $frame->{checkbox_pw_veil}->SetValue($veil); if ( $passwd ) { - $frame->{_keyringdecryptor} = $frame->{_keyringdb}->getDecryptor($passwd); + $frame->{_keyringdecryptor} = $frame->{_keyringdb}->Password($passwd); $frame->{list_box_topic}->SetSelection(0); $frame->OnFetch; }