Annotation of palm/Palm-Keyring/test3.pl, Revision 1.3
1.1 andrew 1: #!/usr/bin/perl
1.3 ! andrew 2: # $RedRiver: palmkeyring-tk,v 1.2 2006/02/02 00:59:08 andrew Exp $
1.1 andrew 3: ########################################################################
4: # palmkeyring-tk *** A GUI for 'Keyring for PalmOS' written in perl
5: #
6: # 2006.01.31 #*#*# andrew fresh <andrew@mad-techies.org>
7: ########################################################################
8: use strict;
9: use warnings;
10:
1.2 andrew 11: use Tk 8.0;
12: use Tk::widgets qw/ Dialog BrowseEntry ROText ProgressBar /;
1.1 andrew 13:
1.2 andrew 14: use lib 'lib';
15: use Palm::Keyring;
16:
1.3 ! andrew 17: #my $File = "Keys-Gtkr.PDB";
! 18: my $File = "k:/working/Keys-Gtkr.PDB";
1.2 andrew 19: my $Keyring = _do_open($File);
20:
21: my $NAME = 'Palm Keyring';
22:
23: my $lock_when = 0;
24: my $unlocked = time; # Change this to 0 when I get more stuff filled out
25: my $lock_timeout = 30;
26:
27: my $MW = MainWindow->new();
28: $MW->optionAdd('*BorderWidth' => 1);
29:
30: my $pane = $MW->Panedwindow(
31: Name => 'main',
32: -showhandle => 1,
33: -orient => 'horizontal'
34: )->pack(-fill => 'both', -expand => 1);
35:
36: my $lists_frame = $pane->Frame(Name => 'lists')
37: ->pack(-side=>'top',-anchor=>'nw',-fill=>'x');
38: my $right_frame = $pane->Frame(Name => 'right',-relief=>'sunken')
39: ->pack(-side=>'top',-anchor=>'ne',-fill=>'both',-expand=>1);
40:
41: my $account_frame = $right_frame->Frame(Name => 'account')
42: ->pack(-side=>'top',-anchor=>'nw',-fill=>'both',-expand=>1);
43: my $lock_frame = $right_frame->Frame(Name => 'lock',-relief=>'raised')
44: ->pack(-side=>'bottom',-fill=>'x');
45:
46: $pane->add('.main.lists');
47: $pane->add('.main.right');
48:
49: # Lists
50: my $category_list = $lists_frame->BrowseEntry()->pack(-side=>'top',-fill=>'x');
51: $category_list->insert(-1, 'All');
52: my $accounts_list = $lists_frame->Scrolled('Listbox', -scrollbars => 'e')
53: ->pack(-side=>'top',-fill=>'both',-expand=>1);
54:
55:
56: # Account
57: my %account_entry;
58: foreach my $label (qw/Category Name Account Password/) {
59: $account_entry{$label} = $account_frame->LabEntry(-state=>'readonly',
60: -labelWidth => 10,
61: -labelPack => [-side => 'left', -anchor => 'w'],
62: -label=>$label . ': ', -text => 'my' . $label)
63: ->pack(-side=>'top',-anchor=>'nw',-fill=>'x');
64: }
65:
66: $account_entry{'Details'} = $account_frame->ROText(-wrap => 'word',-height=>5,-width=>30)
67: ->pack(-side=>'top',-anchor=>'nw',-fill=>'both',-expand=>1);
68: $account_entry{'Details'}->insert('1.0',"This is a test\nThis is only a test");
69:
70:
71: # Lock
72: my $lock_button = $lock_frame->Button(-text => 'Lock', -command => \&Lock)
73: ->pack(-side=>'left');
74: my $lock_progress = $lock_frame->ProgressBar(
75: -variable=>\$lock_when,
76: -blocks => $lock_timeout,
77: -from => $lock_timeout,
78: -to => 0,
79: -gap => 0,
80: )->pack(-side=>'right',-fill=>'x',-expand=>1,-padx=>5);
81:
82: $lock_progress->repeat(500,\&Lock_Timeout);
83:
84: my $menubar = build_menubar($MW);
85:
86: _populate_lists($Keyring, $category_list, $accounts_list);
87:
88: my $VERSION = 0.01;
89:
90: MainLoop;
91:
92:
93: sub build_menubar {
94:
95: # Create the menubar and File and Quit menubuttons. Note
96: # that the cascade's menu widget is automatically created.
97:
98: my $menubar = $MW->Menu;
99: $MW->configure(-menu => $menubar);
100: my $file = $menubar->cascade(-label => '~File', -tearoff => 0);
101: my $help = $menubar->cascade(-label => '~Help', -tearoff => 0);
102:
103: # Create the menuitems for each menu. First, the File menu item.
104:
105: $file->command(-label => "Open", -command => \&Open);
106: $file->command(-label => "Close", -command => \&Close);
107: $file->command(-label => "Quit", -command => \&exit);
108:
109: # Finally, the Help menuitems.
110:
111: $help->command(-label => 'Version');
112: $help->separator;
113: $help->command(-label => 'About');
114:
115: my $ver_dialog = $MW->Dialog(-title => $NAME . ' Version',
116: -text => "$NAME\n\nVersion $VERSION",
117: -buttons => ['OK'],
118: -bitmap => 'info');
119: my $about_dialog = $MW->Dialog(-title => 'About ' . $NAME,
120: -text => 'About ' . $NAME . "\n" .
121: '© Copyright 2006 Andrew Fresh <andrew@mad-techies.org>',
122: -buttons => ['OK']);
123: my $menu = $help->cget('-menu');
124: $menu->entryconfigure('Version', -command => [$ver_dialog => 'Show']);
125: $menu->entryconfigure('About', -command => [$about_dialog => 'Show']);
126:
127: $menubar; # return the menubar
128:
129: }
130:
131: sub Lock
132: {
133: $unlocked = time;
134: }
135:
136: sub Lock_Timeout
137: {
138: #return unless $unlocked;
139: my $diff = time - $unlocked;
140: if ($diff > $lock_timeout) {
141: print "Timed out!";
142: Tk::exit();
143: } else {
144: $lock_when = $diff;
145: }
146: }
147:
148: sub Open
149: {
150: }
151:
152: sub Close
153: {
154: }
155:
156: sub _do_open
157: {
158: my $file = shift;
159: my $pdb = Palm::Keyring->new;
160: $pdb->Load($file) || die "Couldn't load '$file'";
161: return $pdb;
162: }
163:
164: sub _do_close
165: {
166: }
167:
168: sub _do_lock
169: {
170: }
171:
172: sub _populate_lists
173: {
174: my $pdb = shift;
175: my $cat = shift;
176: my $acct = shift;
177: foreach my $category (@{ $pdb->{'appinfo'}->{'categories'} }) {
178: next unless $category->{'name'};
179: $cat->insert( $category->{'id'}, $category->{'name'});
180: }
181: foreach my $account (@{ $pdb->{'records'} }) {
182: next unless $account->{'plaintext'}->{'name'};
183: $acct->insert('end', $account->{'plaintext'}->{'name'});
184: }
185:
186: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>