Annotation of palm/Palm-Keyring/examples/wxkeyring, Revision 1.2
1.1 andrew 1: #!/usr/bin/perl -w --
2: # generated by wxGlade 0.4.1cvs on Fri Jan 26 18:24:52 2007
3: # To get wxPerl visit http://wxPerl.sourceforge.net/
4:
5: $VERSION = 0.92;
6:
7: use Wx 0.15 qw[:allclasses];
8: use strict;
9:
10: package MainFrame;
11:
12: use Wx qw[:everything];
13: use base qw(Wx::Frame);
14: use strict;
15:
16: our $cb;
17:
18: sub new {
19: my( $self, $parent, $id, $title, $pos, $size, $style, $name ) = @_;
20: $parent = undef unless defined $parent;
21: $id = -1 unless defined $id;
22: $title = "" unless defined $title;
23: $pos = wxDefaultPosition unless defined $pos;
24: $size = wxDefaultSize unless defined $size;
25: $name = "" unless defined $name;
26:
27: # begin wxGlade: MainFrame::new
28:
29: $style = wxDEFAULT_FRAME_STYLE
30: unless defined $style;
31:
32: $self = $self->SUPER::new( $parent, $id, $title, $pos, $size, $style, $name );
33: $self->{sizer_account_staticbox} = Wx::StaticBox->new($self, -1, "Account" );
34: $self->{sizer_passwd_staticbox} = Wx::StaticBox->new($self, -1, "Password" );
35: $self->{sizer_note_staticbox} = Wx::StaticBox->new($self, -1, "Note" );
36: $self->{sizer_mod_staticbox} = Wx::StaticBox->new($self, -1, "Last update" );
37: $self->{sizer_category_staticbox} = Wx::StaticBox->new($self, -1, "Category" );
38:
39:
40: # Menu Bar
41:
42: $self->{menubar} = Wx::MenuBar->new();
43: $self->SetMenuBar($self->{menubar});
44: my $wxglade_tmp_menu;
45: $wxglade_tmp_menu = Wx::Menu->new();
46: $wxglade_tmp_menu->Append(wxID_OPEN, "&Open...\tCtrl-O", "Select a file");
47: $wxglade_tmp_menu->AppendSeparator();
48: $wxglade_tmp_menu->Append(wxID_EXIT, "&Quit\tCtrl-Q", "Exit program");
49: $self->{menubar}->Append($wxglade_tmp_menu, "&File");
50: $wxglade_tmp_menu = Wx::Menu->new();
51: $wxglade_tmp_menu->AppendSeparator();
52: $wxglade_tmp_menu->Append(6001, "Select all", "Display all categories");
53: $wxglade_tmp_menu->Append(6002, "Deselect all", "Deselect all");
54: $self->{menubar}->Append($wxglade_tmp_menu, "&Categories");
55: $wxglade_tmp_menu = Wx::Menu->new();
56: $wxglade_tmp_menu->Append(wxID_ABOUT, "&About...", "About...");
57: $self->{menubar}->Append($wxglade_tmp_menu, "&Help");
58:
59: # Menu Bar end
60:
61: $self->{statusbar} = $self->CreateStatusBar(1, wxST_SIZEGRIP);
62: $self->{list_box_topic} = Wx::ListBox->new($self, -1, wxDefaultPosition, wxDefaultSize, [], wxLB_SINGLE|wxLB_ALWAYS_SB);
63: $self->{button_fetch} = Wx::Button->new($self, -1, "Fetch");
64: $self->{text_ctrl_category} = Wx::TextCtrl->new($self, -1, "", wxDefaultPosition, wxDefaultSize, wxTE_READONLY);
65: $self->{text_ctrl_account} = Wx::TextCtrl->new($self, -1, "", wxDefaultPosition, wxDefaultSize, wxTE_READONLY);
66: $self->{text_ctrl_passwd} = Wx::TextCtrl->new($self, -1, "", wxDefaultPosition, wxDefaultSize, wxTE_READONLY);
67: $self->{checkbox_pw_veil} = Wx::CheckBox->new($self, -1, "Veil", wxDefaultPosition, wxDefaultSize, );
68: $self->{checkbox_pw_clip} = Wx::CheckBox->new($self, -1, "Clip", wxDefaultPosition, wxDefaultSize, );
69: $self->{text_ctrl_note} = Wx::TextCtrl->new($self, -1, "", wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY);
70: $self->{text_ctrl_mod} = Wx::TextCtrl->new($self, -1, "", wxDefaultPosition, wxDefaultSize, wxTE_READONLY);
71:
72: $self->__set_properties();
73: $self->__do_layout();
74:
75: Wx::Event::EVT_MENU($self, wxID_OPEN, \&OnOpen);
76: Wx::Event::EVT_MENU($self, wxID_EXIT, \&OnQuit);
77: Wx::Event::EVT_MENU($self, 6001, \&OnSelectAllCategories);
78: Wx::Event::EVT_MENU($self, 6002, \&OnDeselectAllCategories);
79: Wx::Event::EVT_MENU($self, wxID_ABOUT, \&OnAbout);
80: Wx::Event::EVT_LISTBOX_DCLICK($self, $self->{list_box_topic}->GetId, \&OnTopicActivate);
81: Wx::Event::EVT_LISTBOX($self, $self->{list_box_topic}->GetId, \&OnTopicSelect);
82: Wx::Event::EVT_BUTTON($self, $self->{button_fetch}->GetId, \&OnFetch);
83: Wx::Event::EVT_CHECKBOX($self, $self->{checkbox_pw_veil}->GetId, \&OnPwVeil);
84: Wx::Event::EVT_CHECKBOX($self, $self->{checkbox_pw_clip}->GetId, \&OnPwClip);
85:
86: # end wxGlade
87: $self->SetSize($size);
88: return $self;
89:
90: }
91:
92:
93: sub __set_properties {
94: my $self = shift;
95:
96: # begin wxGlade: MainFrame::__set_properties
97:
1.2 ! andrew 98: $self->SetTitle("GNU Keyring");
1.1 andrew 99: $self->{statusbar}->SetStatusWidths(-1);
100:
101: my( @statusbar_fields ) = (
102: ""
103: );
104:
105: if( @statusbar_fields ) {
106: $self->{statusbar}->SetStatusText($statusbar_fields[$_], $_)
107: for 0 .. $#statusbar_fields ;
108: }
109: $self->{list_box_topic}->SetSelection(0);
110: $self->{button_fetch}->Enable(0);
111: $self->{checkbox_pw_veil}->SetValue(1);
112:
113: # end wxGlade
114:
115:
116: }
117:
118: sub __do_layout {
119: my $self = shift;
120:
121: # begin wxGlade: MainFrame::__do_layout
122:
123: $self->{outer_sizer} = Wx::BoxSizer->new(wxHORIZONTAL);
124: $self->{info_sizer} = Wx::BoxSizer->new(wxVERTICAL);
125: $self->{sizer_mod}= Wx::StaticBoxSizer->new($self->{sizer_mod_staticbox}, wxHORIZONTAL);
126: $self->{sizer_note}= Wx::StaticBoxSizer->new($self->{sizer_note_staticbox}, wxHORIZONTAL);
127: $self->{sizer_passwd}= Wx::StaticBoxSizer->new($self->{sizer_passwd_staticbox}, wxVERTICAL);
128: $self->{sizer_pwprefs} = Wx::BoxSizer->new(wxHORIZONTAL);
129: $self->{sizer_account}= Wx::StaticBoxSizer->new($self->{sizer_account_staticbox}, wxHORIZONTAL);
130: $self->{sizer_category}= Wx::StaticBoxSizer->new($self->{sizer_category_staticbox}, wxHORIZONTAL);
131: $self->{sizer_list_box} = Wx::BoxSizer->new(wxVERTICAL);
132: $self->{sizer_list_box}->Add($self->{list_box_topic}, 1, wxEXPAND|wxFIXED_MINSIZE, 0);
133: $self->{sizer_list_box}->Add(1, 3, 0, wxADJUST_MINSIZE, 0);
134: $self->{sizer_list_box}->Add($self->{button_fetch}, 0, wxEXPAND|wxADJUST_MINSIZE, 0);
135: $self->{outer_sizer}->Add($self->{sizer_list_box}, 1, wxLEFT|wxTOP|wxBOTTOM|wxEXPAND, 5);
136: $self->{sizer_category}->Add($self->{text_ctrl_category}, 1, wxEXPAND|wxADJUST_MINSIZE, 0);
137: $self->{info_sizer}->Add($self->{sizer_category}, 0, wxEXPAND, 0);
138: $self->{sizer_account}->Add($self->{text_ctrl_account}, 1, wxADJUST_MINSIZE, 0);
139: $self->{info_sizer}->Add($self->{sizer_account}, 0, wxEXPAND, 0);
140: $self->{sizer_passwd}->Add($self->{text_ctrl_passwd}, 1, wxEXPAND|wxADJUST_MINSIZE, 0);
141: $self->{sizer_pwprefs}->Add($self->{checkbox_pw_veil}, 1, wxADJUST_MINSIZE, 0);
142: $self->{sizer_pwprefs}->Add($self->{checkbox_pw_clip}, 1, wxADJUST_MINSIZE, 0);
143: $self->{sizer_passwd}->Add($self->{sizer_pwprefs}, 0, wxEXPAND, 0);
144: $self->{info_sizer}->Add($self->{sizer_passwd}, 0, wxEXPAND, 0);
145: $self->{sizer_note}->Add($self->{text_ctrl_note}, 1, wxEXPAND|wxADJUST_MINSIZE, 0);
146: $self->{info_sizer}->Add($self->{sizer_note}, 1, wxEXPAND, 0);
147: $self->{sizer_mod}->Add($self->{text_ctrl_mod}, 1, wxADJUST_MINSIZE, 0);
148: $self->{info_sizer}->Add($self->{sizer_mod}, 0, wxEXPAND, 0);
149: $self->{outer_sizer}->Add($self->{info_sizer}, 1, wxALL|wxEXPAND, 5);
150: $self->SetAutoLayout(1);
151: $self->SetSizer($self->{outer_sizer});
152: $self->{outer_sizer}->Fit($self);
153: $self->{outer_sizer}->SetSizeHints($self);
154: $self->Layout();
155:
156: # end wxGlade
157: }
158:
159: sub OnFetch {
160: my ($self, $event) = @_;
161: # wxGlade: MainFrame::OnFetch <event_handler>
162:
163: # Get the desired topic. Note it can be undefined.
164: my $topic = ($self->{list_box_topic}->GetSelections)[0];
165: unless ( defined($topic) ) {
166: $self->{button_fetch}->Enable(0);
167: return;
168: }
169:
170: # Get the topic name from the list.
1.2 ! andrew 171: my $rec = $self->{_keyringsortedrecs}->[$topic];
1.1 andrew 172:
173: # Create the password dialog, if needed.
174: my $d_passwd;
175: if ( !$self->{_keyringdecryptor} ) {
176: $d_passwd = Wx::TextEntryDialog->new
177: ($self,
1.2 ! andrew 178: "Enter password for $self->{_keyringfile}",
! 179: "Enter Keyring password",
1.1 andrew 180: "",
181: wxOK|wxCANCEL|wxTE_PASSWORD,
182: wxDefaultPosition);
183: }
184:
185: # Forever...
186: while ( 1 ) {
187:
188: # If there's no decryptor, start the password dialog.
189: if ( !$self->{_keyringdecryptor} ) {
190: my $ret = $d_passwd->ShowModal;
191: if ( $ret != wxID_OK ) {
192: # Cancelled.
193: $d_passwd->Destroy;
194: return;
195: }
196: $ret = $d_passwd->GetValue;
1.2 ! andrew 197: $self->{_keyringdecryptor} = $self->{_keyringdb}->Password($ret);
1.1 andrew 198: # Check for a valid decryptor.
199: if ( !$self->{_keyringdecryptor} ) {
200: my $md = Wx::MessageDialog->new
201: ($self, "Incorrect password",
202: "Password error",
203: wxOK|wxICON_ERROR,
204: wxDefaultPosition);
205: $md->ShowModal;
206: $md->Destroy;
207: next;
208: }
209: # It's valid, get rid of the dialog.
210: $d_passwd->Destroy;
211: }
212:
213: # Get the record.
214: if ( !$rec ) {
215: my $md = Wx::MessageDialog->new
216: ($self, "Topic \"$topic\" not found",
217: "Database error",
218: wxOK|wxICON_ERROR,
219: wxDefaultPosition);
220: $md->ShowModal;
221: $md->Destroy;
222: next;
223: }
224: # Decrypt it.
1.2 ! andrew 225: my ($acct) = $self->{_keyringdb}->Decrypt($rec);
1.1 andrew 226:
227: # Show values.
1.2 ! andrew 228: $self->{text_ctrl_category}->SetValue(
! 229: $self->{_keyringcategories}->[$rec->{category}]);
! 230: $self->{text_ctrl_account}->SetValue($acct->{account});
1.1 andrew 231: if ( $self->{checkbox_pw_veil}->IsChecked ) {
232: $self->{text_ctrl_passwd}->SetValue("\x{2022}" x 8);
233: }
234: else {
1.2 ! andrew 235: $self->{text_ctrl_passwd}->SetValue($acct->{password});
1.1 andrew 236: }
237: if ( $self->{checkbox_pw_clip}->IsChecked ) {
1.2 ! andrew 238: $self->PutOnClipboard($acct->{password});
1.1 andrew 239: }
240: else {
241: $self->PutOnClipboard(undef);
242: }
1.2 ! andrew 243: $acct->{notes} =~ s/\n+$//;
! 244: $self->{text_ctrl_note}->SetValue($acct->{notes});
1.1 andrew 245:
1.2 ! andrew 246: if ( $acct->{lastchange} ) {
1.1 andrew 247: $self->{text_ctrl_mod}->SetValue
248: (sprintf("%d-%02d-%02d",
1.2 ! andrew 249: 1900 + $acct->{lastchange}->{year},
! 250: 1 + $acct->{lastchange}->{month},
! 251: $acct->{lastchange}->{day}));
1.1 andrew 252:
253: }
254: # Exit.
255: last;
256: }
257: # end wxGlade
258: }
259:
260:
261:
262: sub OnQuit {
263: my ($self, $event) = @_;
264: # wxGlade: MainFrame::OnQuit <event_handler>
265:
266: $self->Destroy;
267:
268: # end wxGlade
269: }
270:
271:
272: sub OnTopicSelect {
273: my ($self, $event) = @_;
274: # wxGlade: MainFrame::OnTopicSelect <event_handler>
275:
276: # We can fetch now.
277: $self->{button_fetch}->Enable(1);
278:
279: # Clear values.
280: foreach ( qw(category account passwd note mod) ) {
281: $self->{"text_ctrl_$_"}->SetValue("");
282: }
283:
284: # Display the current topic category.
285: my $topic = ($self->{list_box_topic}->GetSelections)[0];
286: unless ( defined($topic) ) {
287: $self->{button_fetch}->Enable(0);
288: return;
289: }
1.2 ! andrew 290: my $rec = $self->{_keyringsortedrecs}->[$topic];
! 291: $self->{text_ctrl_category}->SetValue($self->{_keyringcategories}->[ $rec->{category} ]);
1.1 andrew 292:
293: # end wxGlade
294: }
295:
296:
297: sub OnTopicActivate {
298: my ($self, $event) = @_;
299: # wxGlade: MainFrame::OnTopicActivate <event_handler>
300:
301: $self->OnFetch($event);
302:
303: # end wxGlade
304: }
305:
1.2 ! andrew 306: sub LoadKeyring {
1.1 andrew 307: my ($self, $file) = @_;
308:
309: # Load the database.
310: eval {
1.2 ! andrew 311: $self->{_keyringdb} = ::loadKeyring($file);
1.1 andrew 312: };
313: if ( $@ ) {
314: my $msg = $@;
315: $msg =~ s/\n.*//;
316: my $md = Wx::MessageDialog->new
317: ($self, $msg,
318: "Database error",
319: wxOK|wxICON_ERROR,
320: wxDefaultPosition);
321: $md->ShowModal;
322: $md->Destroy;
323: return;
324: }
325: $self->{_keyringfile} = $file;
326:
1.2 ! andrew 327: my @cats;
! 328: foreach my $i (0..$#{ $self->{_keyringdb}->{appinfo}->{categories} }) {
! 329: push @cats, {
! 330: id => $i,
! 331: name => $self->{_keyringdb}->{appinfo}->{categories}->[$i]->{name},
! 332: }
! 333: }
! 334:
! 335: $self->{_keyringcategories} = [ map { $_->{name} } @cats ];
! 336: $self->{_keyringsortedcategoryids} = [
! 337: map { $_->{id} } sort { $a->{name} cmp $b->{name} } @cats ];
! 338:
! 339:
1.1 andrew 340: undef($self->{_keyringdecryptor});
341:
342: # It's no use to remember the cat mask, since codes will differ
343: # from file to file.
344: $self->{_catmask} = ~0;
345:
346: # From the Categories menu, remove all but the last 3 (separator + ena/dis all).
347: my $catmenux = $self->{menubar}->FindMenu("Categories");
348: my Wx::Menu $catmenu = $self->{menubar}->GetMenu($catmenux);
349: my $count = $catmenu->GetMenuItemCount;
350: my $i;
351: for ( $i = 0; $i < $count-3; $i++ ) {
352: #### MEMORY LEAK ####
353: $catmenu->Remove($catmenu->FindItemByPosition(0));
354: }
355:
356: # Prepend new choices to the Categories menu.
357: my $did = 0;
358: $self->{_catmaskids} = [];
1.2 ! andrew 359: foreach my $i (reverse 0..$#{ $self->{_keyringsortedcategoryids} }) {
! 360: my $cat_id = $self->{_keyringsortedcategoryids}->[$i];
! 361: my $name = $self->{_keyringcategories}->[$cat_id];
! 362: next if !$name;
! 363: $name ||= "<Unknown $i>";
! 364: my $id = ::next_id();
! 365: my $m = $catmenu->PrependCheckItem($id, $name, $name);
! 366:
! 367: # Remember for toggle access.
! 368: $self->{_catmaskids}->[$i] = $m;
! 369:
! 370: # Set check status.
! 371: $m->Check($self->{_catmask} & (1 << $i));
! 372:
! 373: # Handler.
! 374: my $maskno = $i; # lexical copy
! 375: Wx::Event::EVT_MENU($self, $id, sub {
! 376: OnToggleCategory($self, $_[1], $maskno) });
1.1 andrew 377:
1.2 ! andrew 378: # Yes.
! 379: $did++;
1.1 andrew 380: }
381:
382: $self->UpdateCatMask;
383: $self->{statusbar}->SetStatusText("File: $file, ".
1.2 ! andrew 384: (@{ $self->{_keyringdb}->{records} })." entries.",
1.1 andrew 385: 0);
386: }
387:
388: sub OnOpen {
389: my ($self, $event) = @_;
390: # wxGlade: MainFrame::OnOpen <event_handler>
391:
392: my $fd = Wx::FileDialog->new
393: ($self,
1.2 ! andrew 394: "Choose Keyring",
1.1 andrew 395: "", "",
396: "*.pdb",
397: 0,
398: wxDefaultPosition);
399: my $ret = $fd->ShowModal;
400: if ( $ret == wxID_OK ) {
1.2 ! andrew 401: $self->LoadKeyring($fd->GetPath);
1.1 andrew 402: }
403: $fd->Destroy;
404:
405: # end wxGlade
406: }
407:
408:
409: sub OnAbout {
410: my ($self, $event) = @_;
411: # wxGlade: MainFrame::OnAbout <event_handler>
412:
413: my $md = Wx::MessageDialog->new
414: ($self,
1.2 ! andrew 415: "wxKeyring version $::VERSION\n".
1.1 andrew 416: ::COPYRIGHT() . "\n\n".
417: "Written by Johan Vromans\n".
418: "<jvromans\@squirrel.nl>\n".
419: "http://www.squirrel.nl\n\n".
420: "GUI design with wxGlade, http://www.wxglade.org\n\n".
421: "Perl version ".sprintf("%vd",$^V)."\n".
422: "WxPerl version $Wx::VERSION\n".
423: "wxWidgets version ".Wx::wxVERSION."\n".
1.2 ! andrew 424: "Palm::Keyring version $Palm::Keyring::VERSION\n",
! 425: "About wxKeyring",
1.1 andrew 426: wxOK|wxICON_INFORMATION,
427: wxDefaultPosition);
428: $md->ShowModal;
429: $md->Destroy;
430:
431: # end wxGlade
432: }
433:
434: sub UpdateCatMask {
435: my ($self) = @_;
436:
437: # Update check status on the category menu.
438: for ( my $i = 0; $i < 16; $i++ ) {
1.2 ! andrew 439: my $m = $self->{_catmaskids}->[$i];
! 440: next unless $m;
! 441: $m->Check($self->{_catmask} & (1 << $i));
1.1 andrew 442: }
443:
444: # Update the list of displayed items.
1.2 ! andrew 445: my %id_by_cat;
! 446: foreach (0..$#{ $self->{_keyringsortedcategoryids} }) {
! 447: $id_by_cat{ $self->{_keyringsortedcategoryids}->[$_]} = $_;
1.1 andrew 448: }
1.2 ! andrew 449: $self->{_keyringsortedrecs} = [];
! 450: foreach my $rec ( sort { lc($a->{name}) cmp lc($b->{name}) }
! 451: @{ $self->{_keyringdb}->{records} } ) {
! 452: next unless $rec->{name};
! 453: if ($self->{_catmask} != ~0) {
! 454: next unless $self->{_catmask} & (1 <<
! 455: $id_by_cat{ $rec->{category} });
! 456: }
! 457: push @{$self->{_keyringsortedrecs}}, $rec;
1.1 andrew 458: }
1.2 ! andrew 459: $self->{list_box_topic}->Set( [ map { $_->{name} }
! 460: @{ $self->{_keyringsortedrecs} } ]);
1.1 andrew 461: }
462:
463: sub OnSelectAllCategories {
464: my ($self, $event) = @_;
465: # wxGlade: MainFrame::OnSelectAllCategories <event_handler>
466:
467: $self->{_catmask} = ~0;
468: $self->UpdateCatMask;
469:
470: # end wxGlade
471: }
472:
473: sub OnToggleCategory {
474: my ($self, $event, $cat) = @_;
475: # wxGlade: MainFrame::OnToggleCategory <event_handler>
476:
477: $self->{_catmask} ^= (1 << $cat);
478: $self->UpdateCatMask;
479:
480: # end wxGlade
481: }
482:
483:
484: sub OnDeselectAllCategories {
485: my ($self, $event) = @_;
486: # wxGlade: MainFrame::OnDeselectAllCategories <event_handler>
487:
488: $self->{_catmask} = 0;
489: $self->UpdateCatMask;
490:
491: # end wxGlade
492: }
493:
494:
495: sub OnPwVeil {
496: my ($self, $event) = @_;
497: # wxGlade: MainFrame::OnPwVeil <event_handler>
498:
499: if ( $self->{checkbox_pw_veil}->IsChecked ) {
500: $self->{text_ctrl_passwd}->SetValue("\x{2022}" x 8);
501: }
502: else {
503: $self->OnFetch($event);
504: }
505: # end wxGlade
506: }
507:
508: sub PutOnClipboard {
509: my ($self, $data) = @_;
510:
511: for ( 0, 1 ) {
512: # Put it on the Clipboard as well as the Primary Selection.
1.2 ! andrew 513: wxTheClipboard->UsePrimarySelection($_);
1.1 andrew 514: if ( $data ) {
515: my $cb = Wx::TextDataObject->new($data);
516: wxTheClipboard->Open;
517: wxTheClipboard->SetData($cb);
518: wxTheClipboard->Close;
519: $self->{statusbar}->SetStatusText
520: ("Password stored on Clipboard", 0);
521: $self->{_pwstored}++;
522: }
523: elsif ( $self->{_pwstored} ) {
524: wxTheClipboard->Open;
525: wxTheClipboard->Clear;
526: wxTheClipboard->Close;
527: $self->{statusbar}->SetStatusText
528: ("Clipboard cleared", 0);
529: $self->{_pwstored} = 0 if $_;
530: }
531: }
532: }
533:
534: sub OnPwClip {
535: my ($self, $event) = @_;
536: # wxGlade: MainFrame::OnPwClip <event_handler>
537:
538: if ( $self->{checkbox_pw_clip}->IsChecked ) {
539: if ( $self->{checkbox_pw_veil}->IsChecked ) {
540: $self->OnFetch($event);
541: }
542: else {
543: $self->PutOnClipboard($self->{text_ctrl_passwd}->GetValue);
544: }
545: }
546: else {
547: $self->PutOnClipboard(undef);
548: }
549: # end wxGlade
550: }
551:
552: # end of class MainFrame
553:
554: 1;
555:
556: package main;
557:
1.2 ! andrew 558: use Palm::Keyring;
1.1 andrew 559:
560: use Wx qw(wxID_HIGHEST);
561:
562: my $next_id;
563: sub next_id {
564: $next_id ||= wxID_HIGHEST;
565: ++$next_id;
566: }
567:
1.2 ! andrew 568: sub loadKeyring {
1.1 andrew 569: my $file = shift;
1.2 ! andrew 570: my $pdb = new Palm::Keyring;
! 571: $pdb->Load($file);
1.1 andrew 572: }
573:
574: sub COPYRIGHT() {
575: "Copyright 2007 Squirrel Consultancy";
576: }
577:
578: use Getopt::Long;
579:
580: my $keyringfile;
581: my $geo = "450x300";
582: my $veil = 1;
583: my $clip = 0;
584: my $passwd;
585:
586: # Note: Using --password is dangerous, and meant for testing only!
587: GetOptions("geometry=s" => \$geo,
588: "veil!" => \$veil,
589: "clip!" => \$clip,
590: "password=s" => \$passwd,
591: ) && @ARGV <= 1
1.2 ! andrew 592: or die("Usage: $0 [ -geometry WxH+X+Y ] [ Keyring ]\n");
1.1 andrew 593:
594: my ($w, $h, $x, $y) = (450, 300, -1, -1);
595: if ( $geo =~ /^(?:(\d+)x(\d+))?(?:\+(\d+)\+(\d+))?$/ ) {
596: $w = $1 if defined $1;
597: $h = $2 if defined $2;
598: $x = $3 if defined $3;
599: $y = $4 if defined $4;
600: }
601: else {
602: die("Invalid geometry: $geo\n");
603: }
604:
605: $keyringfile = shift if @ARGV;
606:
607: no warnings 'redefine';
608: local *Wx::App::OnInit = sub{1};
609: use warnings 'redefine';
610:
611: my $app = Wx::App->new();
612: Wx::InitAllImageHandlers();
613:
614: my $frame = MainFrame->new(undef,undef,undef,[$x,$y],[$w,$h]);
615: $app->SetTopWindow($frame);
616: $frame->Show(1);
617:
1.2 ! andrew 618: $frame->LoadKeyring($keyringfile) if $keyringfile;
1.1 andrew 619: $frame->{statusbar}->SetStatusText(COPYRIGHT, 0);
620:
621: # Presets.
622: $frame->{checkbox_pw_clip}->SetValue($clip);
623: $frame->{checkbox_pw_veil}->SetValue($veil);
624: if ( $passwd ) {
1.2 ! andrew 625: $frame->{_keyringdecryptor} = $frame->{_keyringdb}->Password($passwd);
1.1 andrew 626: $frame->{list_box_topic}->SetSelection(0);
627: $frame->OnFetch;
628: }
629:
630: # And go...
631: $app->MainLoop();
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>