version 1.1, 2007/02/01 01:57:09 |
version 1.2, 2007/02/01 04:44:55 |
|
|
|
|
# begin wxGlade: MainFrame::__set_properties |
# begin wxGlade: MainFrame::__set_properties |
|
|
$self->SetTitle("GNU KeyRing"); |
$self->SetTitle("GNU Keyring"); |
$self->{statusbar}->SetStatusWidths(-1); |
$self->{statusbar}->SetStatusWidths(-1); |
|
|
my( @statusbar_fields ) = ( |
my( @statusbar_fields ) = ( |
|
|
} |
} |
|
|
# Get the topic name from the list. |
# Get the topic name from the list. |
$topic = $self->{_keyringnames}->[$topic]; |
my $rec = $self->{_keyringsortedrecs}->[$topic]; |
|
|
# Create the password dialog, if needed. |
# Create the password dialog, if needed. |
my $d_passwd; |
my $d_passwd; |
if ( !$self->{_keyringdecryptor} ) { |
if ( !$self->{_keyringdecryptor} ) { |
$d_passwd = Wx::TextEntryDialog->new |
$d_passwd = Wx::TextEntryDialog->new |
($self, |
($self, |
"Enter password for $topic", |
"Enter password for $self->{_keyringfile}", |
"Enter KeyRing password", |
"Enter Keyring password", |
"", |
"", |
wxOK|wxCANCEL|wxTE_PASSWORD, |
wxOK|wxCANCEL|wxTE_PASSWORD, |
wxDefaultPosition); |
wxDefaultPosition); |
|
|
return; |
return; |
} |
} |
$ret = $d_passwd->GetValue; |
$ret = $d_passwd->GetValue; |
$self->{_keyringdecryptor} = $self->{_keyringdb}->getDecryptor($ret); |
$self->{_keyringdecryptor} = $self->{_keyringdb}->Password($ret); |
# Check for a valid decryptor. |
# Check for a valid decryptor. |
if ( !$self->{_keyringdecryptor} ) { |
if ( !$self->{_keyringdecryptor} ) { |
my $md = Wx::MessageDialog->new |
my $md = Wx::MessageDialog->new |
|
|
} |
} |
|
|
# Get the record. |
# Get the record. |
my $rec = $self->{_keyringdb}->getRecordsByName($topic); |
|
if ( !$rec ) { |
if ( !$rec ) { |
my $md = Wx::MessageDialog->new |
my $md = Wx::MessageDialog->new |
($self, "Topic \"$topic\" not found", |
($self, "Topic \"$topic\" not found", |
|
|
$md->Destroy; |
$md->Destroy; |
next; |
next; |
} |
} |
$rec = $rec->[0]; |
|
# Decrypt it. |
# Decrypt it. |
my ($name,$cat,$acc,$pass,$note,$mod) = |
my ($acct) = $self->{_keyringdb}->Decrypt($rec); |
$self->{_keyringdecryptor}->decrypt($rec); |
|
|
|
# Show values. |
# Show values. |
$self->{text_ctrl_category}->SetValue($cat); |
$self->{text_ctrl_category}->SetValue( |
$self->{text_ctrl_account}->SetValue($acc); |
$self->{_keyringcategories}->[$rec->{category}]); |
|
$self->{text_ctrl_account}->SetValue($acct->{account}); |
if ( $self->{checkbox_pw_veil}->IsChecked ) { |
if ( $self->{checkbox_pw_veil}->IsChecked ) { |
$self->{text_ctrl_passwd}->SetValue("\x{2022}" x 8); |
$self->{text_ctrl_passwd}->SetValue("\x{2022}" x 8); |
} |
} |
else { |
else { |
$self->{text_ctrl_passwd}->SetValue($pass); |
$self->{text_ctrl_passwd}->SetValue($acct->{password}); |
} |
} |
if ( $self->{checkbox_pw_clip}->IsChecked ) { |
if ( $self->{checkbox_pw_clip}->IsChecked ) { |
$self->PutOnClipboard($pass); |
$self->PutOnClipboard($acct->{password}); |
} |
} |
else { |
else { |
$self->PutOnClipboard(undef); |
$self->PutOnClipboard(undef); |
} |
} |
$note =~ s/\n+$//; |
$acct->{notes} =~ s/\n+$//; |
$self->{text_ctrl_note}->SetValue($note); |
$self->{text_ctrl_note}->SetValue($acct->{notes}); |
|
|
if ( $mod ) { |
if ( $acct->{lastchange} ) { |
$self->{text_ctrl_mod}->SetValue |
$self->{text_ctrl_mod}->SetValue |
(sprintf("%d-%02d-%02d", |
(sprintf("%d-%02d-%02d", |
1900 + $mod->[0], |
1900 + $acct->{lastchange}->{year}, |
1 + $mod->[1], |
1 + $acct->{lastchange}->{month}, |
$mod->[2])); |
$acct->{lastchange}->{day})); |
|
|
} |
} |
# Exit. |
# Exit. |
|
|
$self->{button_fetch}->Enable(0); |
$self->{button_fetch}->Enable(0); |
return; |
return; |
} |
} |
$topic = $self->{_keyringnames}->[$topic]; |
my $rec = $self->{_keyringsortedrecs}->[$topic]; |
$self->{text_ctrl_category}->SetValue |
$self->{text_ctrl_category}->SetValue($self->{_keyringcategories}->[ $rec->{category} ]); |
($self->{_keyringdb}->getCategory |
|
($self->{_keyringdb}->getRecordsByName($topic)->[0]->{category})); |
|
|
|
|
|
# end wxGlade |
# end wxGlade |
} |
} |
|
|
|
|
# end wxGlade |
# end wxGlade |
} |
} |
|
|
sub LoadKeyRing { |
sub LoadKeyring { |
my ($self, $file) = @_; |
my ($self, $file) = @_; |
|
|
# Load the database. |
# Load the database. |
eval { |
eval { |
$self->{_keyringdb} = ::loadKeyRing($file); |
$self->{_keyringdb} = ::loadKeyring($file); |
}; |
}; |
if ( $@ ) { |
if ( $@ ) { |
my $msg = $@; |
my $msg = $@; |
|
|
} |
} |
$self->{_keyringfile} = $file; |
$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}); |
undef($self->{_keyringdecryptor}); |
|
|
# It's no use to remember the cat mask, since codes will differ |
# It's no use to remember the cat mask, since codes will differ |
|
|
} |
} |
|
|
# Prepend new choices to the Categories menu. |
# Prepend new choices to the Categories menu. |
$i = 16; |
|
my $did = 0; |
my $did = 0; |
$self->{_catmaskids} = []; |
$self->{_catmaskids} = []; |
foreach ( reverse $self->{_keyringdb}->getCategories ) { |
foreach my $i (reverse 0..$#{ $self->{_keyringsortedcategoryids} }) { |
$i--; |
my $cat_id = $self->{_keyringsortedcategoryids}->[$i]; |
next if !$did && !$_; # strip trailing unused categories |
my $name = $self->{_keyringcategories}->[$cat_id]; |
$_ ||= "<Unknown $i>"; |
next if !$name; |
my $id = ::next_id(); |
$name ||= "<Unknown $i>"; |
my $m = $catmenu->PrependCheckItem($id, $_, $_); |
my $id = ::next_id(); |
|
my $m = $catmenu->PrependCheckItem($id, $name, $name); |
|
|
# Remember for toggle access. |
# Remember for toggle access. |
$self->{_catmaskids}->[$i] = $m; |
$self->{_catmaskids}->[$i] = $m; |
|
|
# Set check status. |
# Set check status. |
$m->Check($self->{_catmask} & (1 << $i)); |
$m->Check($self->{_catmask} & (1 << $i)); |
|
|
# Handler. |
# Handler. |
my $maskno = $i; # lexical copy |
my $maskno = $i; # lexical copy |
Wx::Event::EVT_MENU($self, $id, sub { OnToggleCategory($self, $_[1], $maskno) }); |
Wx::Event::EVT_MENU($self, $id, sub { |
|
OnToggleCategory($self, $_[1], $maskno) }); |
|
|
# Yes. |
# Yes. |
$did++; |
$did++; |
} |
} |
|
|
$self->UpdateCatMask; |
$self->UpdateCatMask; |
$self->{statusbar}->SetStatusText("File: $file, ". |
$self->{statusbar}->SetStatusText("File: $file, ". |
($self->{_keyringdb}->getRecords)." entries.", |
(@{ $self->{_keyringdb}->{records} })." entries.", |
0); |
0); |
} |
} |
|
|
|
|
|
|
my $fd = Wx::FileDialog->new |
my $fd = Wx::FileDialog->new |
($self, |
($self, |
"Choose KeyRing", |
"Choose Keyring", |
"", "", |
"", "", |
"*.pdb", |
"*.pdb", |
0, |
0, |
wxDefaultPosition); |
wxDefaultPosition); |
my $ret = $fd->ShowModal; |
my $ret = $fd->ShowModal; |
if ( $ret == wxID_OK ) { |
if ( $ret == wxID_OK ) { |
$self->LoadKeyRing($fd->GetPath); |
$self->LoadKeyring($fd->GetPath); |
} |
} |
$fd->Destroy; |
$fd->Destroy; |
|
|
|
|
|
|
my $md = Wx::MessageDialog->new |
my $md = Wx::MessageDialog->new |
($self, |
($self, |
"wxKeyRing version $::VERSION\n". |
"wxKeyring version $::VERSION\n". |
::COPYRIGHT() . "\n\n". |
::COPYRIGHT() . "\n\n". |
"Written by Johan Vromans\n". |
"Written by Johan Vromans\n". |
"<jvromans\@squirrel.nl>\n". |
"<jvromans\@squirrel.nl>\n". |
|
|
"Perl version ".sprintf("%vd",$^V)."\n". |
"Perl version ".sprintf("%vd",$^V)."\n". |
"WxPerl version $Wx::VERSION\n". |
"WxPerl version $Wx::VERSION\n". |
"wxWidgets version ".Wx::wxVERSION."\n". |
"wxWidgets version ".Wx::wxVERSION."\n". |
"Palm::KeyRing version $Palm::KeyRing::VERSION\n", |
"Palm::Keyring version $Palm::Keyring::VERSION\n", |
"About wxKeyRing", |
"About wxKeyring", |
wxOK|wxICON_INFORMATION, |
wxOK|wxICON_INFORMATION, |
wxDefaultPosition); |
wxDefaultPosition); |
$md->ShowModal; |
$md->ShowModal; |
|
|
|
|
# Update check status on the category menu. |
# Update check status on the category menu. |
for ( my $i = 0; $i < 16; $i++ ) { |
for ( my $i = 0; $i < 16; $i++ ) { |
my $m = $self->{_catmaskids}->[$i]; |
my $m = $self->{_catmaskids}->[$i]; |
next unless $m; |
next unless $m; |
$m->Check($self->{_catmask} & (1 << $i)); |
$m->Check($self->{_catmask} & (1 << $i)); |
} |
} |
|
|
# Update the list of displayed items. |
# Update the list of displayed items. |
if ( $self->{_catmask} == ~0 ) { |
my %id_by_cat; |
# All. |
foreach (0..$#{ $self->{_keyringsortedcategoryids} }) { |
$self->{_keyringnames} = [sort { lc($a) cmp lc($b) } @{$self->{_keyringdb}->getNames}]; |
$id_by_cat{ $self->{_keyringsortedcategoryids}->[$_]} = $_; |
} |
} |
else { |
$self->{_keyringsortedrecs} = []; |
# Selective. |
foreach my $rec ( sort { lc($a->{name}) cmp lc($b->{name}) } |
$self->{_keyringnames} = []; |
@{ $self->{_keyringdb}->{records} } ) { |
foreach my $k ( sort { lc($a) cmp lc($b) } @{$self->{_keyringdb}->getNames} ) { |
next unless $rec->{name}; |
my $rec = $self->{_keyringdb}->getRecordsByName($k); |
if ($self->{_catmask} != ~0) { |
$rec = $rec->[0]; |
next unless $self->{_catmask} & (1 << |
next unless $self->{_catmask} & (1 << $rec->{category}); |
$id_by_cat{ $rec->{category} }); |
push(@{$self->{_keyringnames}}, $k); |
} |
} |
push @{$self->{_keyringsortedrecs}}, $rec; |
} |
} |
$self->{list_box_topic}->Set($self->{_keyringnames}); |
$self->{list_box_topic}->Set( [ map { $_->{name} } |
|
@{ $self->{_keyringsortedrecs} } ]); |
} |
} |
|
|
sub OnSelectAllCategories { |
sub OnSelectAllCategories { |
|
|
|
|
for ( 0, 1 ) { |
for ( 0, 1 ) { |
# Put it on the Clipboard as well as the Primary Selection. |
# Put it on the Clipboard as well as the Primary Selection. |
wxTheClipboard->UsePrimarySelection($_); |
wxTheClipboard->UsePrimarySelection($_); |
if ( $data ) { |
if ( $data ) { |
my $cb = Wx::TextDataObject->new($data); |
my $cb = Wx::TextDataObject->new($data); |
wxTheClipboard->Open; |
wxTheClipboard->Open; |
|
|
|
|
package main; |
package main; |
|
|
use Palm::KeyRing; |
use Palm::Keyring; |
|
|
use Wx qw(wxID_HIGHEST); |
use Wx qw(wxID_HIGHEST); |
|
|
|
|
++$next_id; |
++$next_id; |
} |
} |
|
|
sub loadKeyRing { |
sub loadKeyring { |
my $file = shift; |
my $file = shift; |
Palm::KeyRing->new($file); |
my $pdb = new Palm::Keyring; |
|
$pdb->Load($file); |
} |
} |
|
|
sub COPYRIGHT() { |
sub COPYRIGHT() { |
|
|
"clip!" => \$clip, |
"clip!" => \$clip, |
"password=s" => \$passwd, |
"password=s" => \$passwd, |
) && @ARGV <= 1 |
) && @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); |
my ($w, $h, $x, $y) = (450, 300, -1, -1); |
if ( $geo =~ /^(?:(\d+)x(\d+))?(?:\+(\d+)\+(\d+))?$/ ) { |
if ( $geo =~ /^(?:(\d+)x(\d+))?(?:\+(\d+)\+(\d+))?$/ ) { |
|
|
$app->SetTopWindow($frame); |
$app->SetTopWindow($frame); |
$frame->Show(1); |
$frame->Show(1); |
|
|
$frame->LoadKeyRing($keyringfile) if $keyringfile; |
$frame->LoadKeyring($keyringfile) if $keyringfile; |
$frame->{statusbar}->SetStatusText(COPYRIGHT, 0); |
$frame->{statusbar}->SetStatusText(COPYRIGHT, 0); |
|
|
# Presets. |
# Presets. |
$frame->{checkbox_pw_clip}->SetValue($clip); |
$frame->{checkbox_pw_clip}->SetValue($clip); |
$frame->{checkbox_pw_veil}->SetValue($veil); |
$frame->{checkbox_pw_veil}->SetValue($veil); |
if ( $passwd ) { |
if ( $passwd ) { |
$frame->{_keyringdecryptor} = $frame->{_keyringdb}->getDecryptor($passwd); |
$frame->{_keyringdecryptor} = $frame->{_keyringdb}->Password($passwd); |
$frame->{list_box_topic}->SetSelection(0); |
$frame->{list_box_topic}->SetSelection(0); |
$frame->OnFetch; |
$frame->OnFetch; |
} |
} |