[BACK]Return to wxkeyring CVS log [TXT][DIR] Up to [local] / palm / Palm-Keyring / examples

Annotation of palm/Palm-Keyring/examples/wxkeyring, Revision 1.1

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:
        !            98:        $self->SetTitle("GNU KeyRing");
        !            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.
        !           171:        $topic = $self->{_keyringnames}->[$topic];
        !           172:
        !           173:        # Create the password dialog, if needed.
        !           174:        my $d_passwd;
        !           175:        if ( !$self->{_keyringdecryptor} ) {
        !           176:            $d_passwd = Wx::TextEntryDialog->new
        !           177:              ($self,
        !           178:               "Enter password for $topic",
        !           179:               "Enter KeyRing password",
        !           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;
        !           197:                $self->{_keyringdecryptor} = $self->{_keyringdb}->getDecryptor($ret);
        !           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:            my $rec = $self->{_keyringdb}->getRecordsByName($topic);
        !           215:            if ( !$rec ) {
        !           216:                my $md = Wx::MessageDialog->new
        !           217:                  ($self, "Topic \"$topic\" not found",
        !           218:                   "Database error",
        !           219:                   wxOK|wxICON_ERROR,
        !           220:                   wxDefaultPosition);
        !           221:                $md->ShowModal;
        !           222:                $md->Destroy;
        !           223:                next;
        !           224:            }
        !           225:            $rec = $rec->[0];
        !           226:            # Decrypt it.
        !           227:            my ($name,$cat,$acc,$pass,$note,$mod) =
        !           228:              $self->{_keyringdecryptor}->decrypt($rec);
        !           229:
        !           230:            # Show values.
        !           231:            $self->{text_ctrl_category}->SetValue($cat);
        !           232:            $self->{text_ctrl_account}->SetValue($acc);
        !           233:            if ( $self->{checkbox_pw_veil}->IsChecked ) {
        !           234:                $self->{text_ctrl_passwd}->SetValue("\x{2022}" x 8);
        !           235:            }
        !           236:            else {
        !           237:                $self->{text_ctrl_passwd}->SetValue($pass);
        !           238:            }
        !           239:            if ( $self->{checkbox_pw_clip}->IsChecked ) {
        !           240:                $self->PutOnClipboard($pass);
        !           241:            }
        !           242:            else {
        !           243:                $self->PutOnClipboard(undef);
        !           244:            }
        !           245:            $note =~ s/\n+$//;
        !           246:            $self->{text_ctrl_note}->SetValue($note);
        !           247:
        !           248:            if ( $mod ) {
        !           249:                $self->{text_ctrl_mod}->SetValue
        !           250:                  (sprintf("%d-%02d-%02d",
        !           251:                           1900 + $mod->[0],
        !           252:                           1 + $mod->[1],
        !           253:                           $mod->[2]));
        !           254:
        !           255:            }
        !           256:            # Exit.
        !           257:            last;
        !           258:        }
        !           259: # end wxGlade
        !           260: }
        !           261:
        !           262:
        !           263:
        !           264: sub OnQuit {
        !           265:        my ($self, $event) = @_;
        !           266: # wxGlade: MainFrame::OnQuit <event_handler>
        !           267:
        !           268:        $self->Destroy;
        !           269:
        !           270: # end wxGlade
        !           271: }
        !           272:
        !           273:
        !           274: sub OnTopicSelect {
        !           275:        my ($self, $event) = @_;
        !           276: # wxGlade: MainFrame::OnTopicSelect <event_handler>
        !           277:
        !           278:        # We can fetch now.
        !           279:        $self->{button_fetch}->Enable(1);
        !           280:
        !           281:        # Clear values.
        !           282:        foreach ( qw(category account passwd note mod) ) {
        !           283:            $self->{"text_ctrl_$_"}->SetValue("");
        !           284:        }
        !           285:
        !           286:        # Display the current topic category.
        !           287:        my $topic = ($self->{list_box_topic}->GetSelections)[0];
        !           288:        unless ( defined($topic) ) {
        !           289:            $self->{button_fetch}->Enable(0);
        !           290:            return;
        !           291:        }
        !           292:        $topic = $self->{_keyringnames}->[$topic];
        !           293:        $self->{text_ctrl_category}->SetValue
        !           294:          ($self->{_keyringdb}->getCategory
        !           295:           ($self->{_keyringdb}->getRecordsByName($topic)->[0]->{category}));
        !           296:
        !           297:
        !           298: # end wxGlade
        !           299: }
        !           300:
        !           301:
        !           302: sub OnTopicActivate {
        !           303:        my ($self, $event) = @_;
        !           304: # wxGlade: MainFrame::OnTopicActivate <event_handler>
        !           305:
        !           306:        $self->OnFetch($event);
        !           307:
        !           308: # end wxGlade
        !           309: }
        !           310:
        !           311: sub LoadKeyRing {
        !           312:     my ($self, $file) = @_;
        !           313:
        !           314:     # Load the database.
        !           315:     eval {
        !           316:        $self->{_keyringdb} = ::loadKeyRing($file);
        !           317:     };
        !           318:     if ( $@ ) {
        !           319:        my $msg = $@;
        !           320:        $msg =~ s/\n.*//;
        !           321:        my $md = Wx::MessageDialog->new
        !           322:          ($self, $msg,
        !           323:           "Database error",
        !           324:           wxOK|wxICON_ERROR,
        !           325:           wxDefaultPosition);
        !           326:        $md->ShowModal;
        !           327:        $md->Destroy;
        !           328:        return;
        !           329:     }
        !           330:     $self->{_keyringfile} = $file;
        !           331:
        !           332:     undef($self->{_keyringdecryptor});
        !           333:
        !           334:     # It's no use to remember the cat mask, since codes will differ
        !           335:     # from file to file.
        !           336:     $self->{_catmask} = ~0;
        !           337:
        !           338:     # From the Categories menu, remove all but the last 3 (separator + ena/dis all).
        !           339:     my $catmenux = $self->{menubar}->FindMenu("Categories");
        !           340:     my Wx::Menu $catmenu = $self->{menubar}->GetMenu($catmenux);
        !           341:     my $count = $catmenu->GetMenuItemCount;
        !           342:     my $i;
        !           343:     for ( $i = 0; $i < $count-3; $i++ ) {
        !           344:        #### MEMORY LEAK ####
        !           345:        $catmenu->Remove($catmenu->FindItemByPosition(0));
        !           346:     }
        !           347:
        !           348:     # Prepend new choices to the Categories menu.
        !           349:     $i = 16;
        !           350:     my $did = 0;
        !           351:     $self->{_catmaskids} = [];
        !           352:     foreach ( reverse $self->{_keyringdb}->getCategories ) {
        !           353:        $i--;
        !           354:        next if !$did && !$_;   # strip trailing unused categories
        !           355:        $_ ||= "<Unknown $i>";
        !           356:        my $id = ::next_id();
        !           357:        my $m = $catmenu->PrependCheckItem($id, $_, $_);
        !           358:
        !           359:        # Remember for toggle access.
        !           360:        $self->{_catmaskids}->[$i] = $m;
        !           361:
        !           362:        # Set check status.
        !           363:        $m->Check($self->{_catmask} & (1 << $i));
        !           364:
        !           365:        # Handler.
        !           366:        my $maskno = $i;        # lexical copy
        !           367:        Wx::Event::EVT_MENU($self, $id, sub { OnToggleCategory($self, $_[1], $maskno) });
        !           368:
        !           369:        # Yes.
        !           370:        $did++;
        !           371:     }
        !           372:
        !           373:     $self->UpdateCatMask;
        !           374:     $self->{statusbar}->SetStatusText("File: $file, ".
        !           375:                                      ($self->{_keyringdb}->getRecords)." entries.",
        !           376:                                      0);
        !           377: }
        !           378:
        !           379: sub OnOpen {
        !           380:        my ($self, $event) = @_;
        !           381: # wxGlade: MainFrame::OnOpen <event_handler>
        !           382:
        !           383:        my $fd = Wx::FileDialog->new
        !           384:          ($self,
        !           385:           "Choose KeyRing",
        !           386:           "", "",
        !           387:           "*.pdb",
        !           388:           0,
        !           389:           wxDefaultPosition);
        !           390:        my $ret = $fd->ShowModal;
        !           391:        if ( $ret == wxID_OK ) {
        !           392:            $self->LoadKeyRing($fd->GetPath);
        !           393:        }
        !           394:        $fd->Destroy;
        !           395:
        !           396: # end wxGlade
        !           397: }
        !           398:
        !           399:
        !           400: sub OnAbout {
        !           401:        my ($self, $event) = @_;
        !           402: # wxGlade: MainFrame::OnAbout <event_handler>
        !           403:
        !           404:        my $md = Wx::MessageDialog->new
        !           405:          ($self,
        !           406:           "wxKeyRing version $::VERSION\n".
        !           407:           ::COPYRIGHT() . "\n\n".
        !           408:           "Written by Johan Vromans\n".
        !           409:           "<jvromans\@squirrel.nl>\n".
        !           410:           "http://www.squirrel.nl\n\n".
        !           411:           "GUI design with wxGlade, http://www.wxglade.org\n\n".
        !           412:           "Perl version ".sprintf("%vd",$^V)."\n".
        !           413:           "WxPerl version $Wx::VERSION\n".
        !           414:           "wxWidgets version ".Wx::wxVERSION."\n".
        !           415:           "Palm::KeyRing version $Palm::KeyRing::VERSION\n",
        !           416:           "About wxKeyRing",
        !           417:           wxOK|wxICON_INFORMATION,
        !           418:           wxDefaultPosition);
        !           419:        $md->ShowModal;
        !           420:        $md->Destroy;
        !           421:
        !           422: # end wxGlade
        !           423: }
        !           424:
        !           425: sub UpdateCatMask {
        !           426:     my ($self) = @_;
        !           427:
        !           428:     # Update check status on the category menu.
        !           429:     for ( my $i = 0; $i < 16; $i++ ) {
        !           430:        my $m = $self->{_catmaskids}->[$i];
        !           431:        next unless $m;
        !           432:        $m->Check($self->{_catmask} & (1 << $i));
        !           433:     }
        !           434:
        !           435:     # Update the list of displayed items.
        !           436:     if ( $self->{_catmask} == ~0 ) {
        !           437:        # All.
        !           438:        $self->{_keyringnames} = [sort { lc($a) cmp lc($b) } @{$self->{_keyringdb}->getNames}];
        !           439:     }
        !           440:     else {
        !           441:        # Selective.
        !           442:        $self->{_keyringnames} = [];
        !           443:        foreach my $k ( sort { lc($a) cmp lc($b) } @{$self->{_keyringdb}->getNames} ) {
        !           444:            my $rec = $self->{_keyringdb}->getRecordsByName($k);
        !           445:            $rec = $rec->[0];
        !           446:            next unless $self->{_catmask} & (1 << $rec->{category});
        !           447:            push(@{$self->{_keyringnames}}, $k);
        !           448:        }
        !           449:     }
        !           450:     $self->{list_box_topic}->Set($self->{_keyringnames});
        !           451:
        !           452: }
        !           453:
        !           454: sub OnSelectAllCategories {
        !           455:        my ($self, $event) = @_;
        !           456: # wxGlade: MainFrame::OnSelectAllCategories <event_handler>
        !           457:
        !           458:        $self->{_catmask} = ~0;
        !           459:        $self->UpdateCatMask;
        !           460:
        !           461: # end wxGlade
        !           462: }
        !           463:
        !           464: sub OnToggleCategory {
        !           465:        my ($self, $event, $cat) = @_;
        !           466: # wxGlade: MainFrame::OnToggleCategory <event_handler>
        !           467:
        !           468:        $self->{_catmask} ^= (1 << $cat);
        !           469:        $self->UpdateCatMask;
        !           470:
        !           471: # end wxGlade
        !           472: }
        !           473:
        !           474:
        !           475: sub OnDeselectAllCategories {
        !           476:        my ($self, $event) = @_;
        !           477: # wxGlade: MainFrame::OnDeselectAllCategories <event_handler>
        !           478:
        !           479:        $self->{_catmask} = 0;
        !           480:        $self->UpdateCatMask;
        !           481:
        !           482: # end wxGlade
        !           483: }
        !           484:
        !           485:
        !           486: sub OnPwVeil {
        !           487:        my ($self, $event) = @_;
        !           488: # wxGlade: MainFrame::OnPwVeil <event_handler>
        !           489:
        !           490:        if ( $self->{checkbox_pw_veil}->IsChecked ) {
        !           491:            $self->{text_ctrl_passwd}->SetValue("\x{2022}" x 8);
        !           492:        }
        !           493:        else {
        !           494:            $self->OnFetch($event);
        !           495:        }
        !           496: # end wxGlade
        !           497: }
        !           498:
        !           499: sub PutOnClipboard {
        !           500:     my ($self, $data) = @_;
        !           501:
        !           502:     for ( 0, 1 ) {
        !           503:        # Put it on the Clipboard as well as the Primary Selection.
        !           504:        wxTheClipboard->UsePrimarySelection($_);
        !           505:        if ( $data ) {
        !           506:            my $cb = Wx::TextDataObject->new($data);
        !           507:            wxTheClipboard->Open;
        !           508:            wxTheClipboard->SetData($cb);
        !           509:            wxTheClipboard->Close;
        !           510:            $self->{statusbar}->SetStatusText
        !           511:              ("Password stored on Clipboard", 0);
        !           512:            $self->{_pwstored}++;
        !           513:        }
        !           514:        elsif ( $self->{_pwstored} ) {
        !           515:            wxTheClipboard->Open;
        !           516:            wxTheClipboard->Clear;
        !           517:            wxTheClipboard->Close;
        !           518:            $self->{statusbar}->SetStatusText
        !           519:              ("Clipboard cleared", 0);
        !           520:            $self->{_pwstored} = 0 if $_;
        !           521:        }
        !           522:     }
        !           523: }
        !           524:
        !           525: sub OnPwClip {
        !           526:        my ($self, $event) = @_;
        !           527: # wxGlade: MainFrame::OnPwClip <event_handler>
        !           528:
        !           529:        if ( $self->{checkbox_pw_clip}->IsChecked ) {
        !           530:            if ( $self->{checkbox_pw_veil}->IsChecked ) {
        !           531:                $self->OnFetch($event);
        !           532:            }
        !           533:            else {
        !           534:                $self->PutOnClipboard($self->{text_ctrl_passwd}->GetValue);
        !           535:            }
        !           536:        }
        !           537:        else {
        !           538:            $self->PutOnClipboard(undef);
        !           539:        }
        !           540: # end wxGlade
        !           541: }
        !           542:
        !           543: # end of class MainFrame
        !           544:
        !           545: 1;
        !           546:
        !           547: package main;
        !           548:
        !           549: use Palm::KeyRing;
        !           550:
        !           551: use Wx qw(wxID_HIGHEST);
        !           552:
        !           553: my $next_id;
        !           554: sub next_id {
        !           555:     $next_id ||= wxID_HIGHEST;
        !           556:     ++$next_id;
        !           557: }
        !           558:
        !           559: sub loadKeyRing {
        !           560:     my $file = shift;
        !           561:     Palm::KeyRing->new($file);
        !           562: }
        !           563:
        !           564: sub COPYRIGHT() {
        !           565:     "Copyright 2007 Squirrel Consultancy";
        !           566: }
        !           567:
        !           568: use Getopt::Long;
        !           569:
        !           570: my $keyringfile;
        !           571: my $geo = "450x300";
        !           572: my $veil = 1;
        !           573: my $clip = 0;
        !           574: my $passwd;
        !           575:
        !           576: # Note: Using --password is dangerous, and meant for testing only!
        !           577: GetOptions("geometry=s"         => \$geo,
        !           578:           "veil!"       => \$veil,
        !           579:           "clip!"       => \$clip,
        !           580:           "password=s"  => \$passwd,
        !           581:          ) && @ARGV <= 1
        !           582:   or die("Usage: $0 [ -geometry WxH+X+Y ] [ KeyRing ]\n");
        !           583:
        !           584: my ($w, $h, $x, $y) = (450, 300, -1, -1);
        !           585: if ( $geo =~ /^(?:(\d+)x(\d+))?(?:\+(\d+)\+(\d+))?$/ ) {
        !           586:     $w = $1 if defined $1;
        !           587:     $h = $2 if defined $2;
        !           588:     $x = $3 if defined $3;
        !           589:     $y = $4 if defined $4;
        !           590: }
        !           591: else {
        !           592:     die("Invalid geometry: $geo\n");
        !           593: }
        !           594:
        !           595: $keyringfile = shift if @ARGV;
        !           596:
        !           597: no warnings 'redefine';
        !           598: local *Wx::App::OnInit = sub{1};
        !           599: use warnings 'redefine';
        !           600:
        !           601: my $app = Wx::App->new();
        !           602: Wx::InitAllImageHandlers();
        !           603:
        !           604: my $frame = MainFrame->new(undef,undef,undef,[$x,$y],[$w,$h]);
        !           605: $app->SetTopWindow($frame);
        !           606: $frame->Show(1);
        !           607:
        !           608: $frame->LoadKeyRing($keyringfile) if $keyringfile;
        !           609: $frame->{statusbar}->SetStatusText(COPYRIGHT, 0);
        !           610:
        !           611: # Presets.
        !           612: $frame->{checkbox_pw_clip}->SetValue($clip);
        !           613: $frame->{checkbox_pw_veil}->SetValue($veil);
        !           614: if ( $passwd ) {
        !           615:     $frame->{_keyringdecryptor} = $frame->{_keyringdb}->getDecryptor($passwd);
        !           616:     $frame->{list_box_topic}->SetSelection(0);
        !           617:     $frame->OnFetch;
        !           618: }
        !           619:
        !           620: # And go...
        !           621: $app->MainLoop();

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>