[BACK]Return to test3.pl CVS log [TXT][DIR] Up to [local] / palm / Palm-Keyring

Diff for /palm/Palm-Keyring/test3.pl between version 1.2 and 1.5

version 1.2, 2006/02/02 00:59:08 version 1.5, 2006/12/06 20:58:18
Line 1 
Line 1 
 #!/usr/bin/perl  #!/usr/bin/perl
 # $RedRiver: palmkeyring-tk,v 1.1 2006/01/31 23:03:39 andrew Exp $  # $RedRiver: palmkeyring-tk,v 1.4 2006/06/13 00:03:39 andrew Exp $
 ########################################################################  ########################################################################
 # palmkeyring-tk *** A GUI for 'Keyring for PalmOS' written in perl  # palmkeyring-tk *** A GUI for 'Keyring for PalmOS' written in perl
 #  #
 # 2006.01.31 #*#*# andrew fresh <andrew@mad-techies.org>  # 2006.01.31 #*#*# andrew fresh <andrew@mad-techies.org>
 ########################################################################  ########################################################################
 use strict;  use strict;
 use warnings;  use warnings;
   
 use Tk 8.0;  use Tk 8.0;
 use Tk::widgets qw/ Dialog BrowseEntry ROText ProgressBar /;  use Tk::widgets qw/ Dialog BrowseEntry ROText ProgressBar /;
   
 use lib 'lib';  use lib 'lib';
 use Palm::Keyring;  use Palm::Keyring;
   
 my $File    = "Keys-Gtkr.PDB";  my $NAME    = 'Palm Keyring';
 my $Keyring = _do_open($File);  my $VERSION = 0.01;
   
 my $NAME    = 'Palm Keyring';  my $File    = shift || "Keys-Gtkr.PDB";
   my $Keyring = Open($File);
 my $lock_when     = 0;  
 my $unlocked     = time; # Change this to 0 when I get more stuff filled out  
 my $lock_timeout = 30;  my $lock_when     = 0;
   my $unlocked     = time; # Change this to 0 when I get more stuff filled out
 my $MW = MainWindow->new();  my $lock_timeout = 30;
 $MW->optionAdd('*BorderWidth' => 1);  
   build_window();
 my $pane = $MW->Panedwindow(  MainLoop;
   Name => 'main',  
   -showhandle => 1,  
   -orient => 'horizontal'  
 )->pack(-fill => 'both', -expand => 1);  
   sub build_window
 my $lists_frame = $pane->Frame(Name => 'lists')  {
   ->pack(-side=>'top',-anchor=>'nw',-fill=>'x');  
 my $right_frame = $pane->Frame(Name => 'right',-relief=>'sunken')          my $MW = MainWindow->new();
   ->pack(-side=>'top',-anchor=>'ne',-fill=>'both',-expand=>1);          $MW->optionAdd('*BorderWidth' => 1);
   
 my $account_frame = $right_frame->Frame(Name => 'account')          my $pane = $MW->Panedwindow(
   ->pack(-side=>'top',-anchor=>'nw',-fill=>'both',-expand=>1);                  Name => 'main',
 my $lock_frame    = $right_frame->Frame(Name => 'lock',-relief=>'raised')                  -showhandle => 1,
   ->pack(-side=>'bottom',-fill=>'x');                  -orient => 'horizontal'
           )->pack(-fill => 'both', -expand => 1);
 $pane->add('.main.lists');  
 $pane->add('.main.right');          my $lists_frame = $pane->Frame(Name => 'lists')
                   ->pack(-side=>'top',-anchor=>'nw',-fill=>'x');
 # Lists          my $right_frame = $pane->Frame(Name => 'right',-relief=>'sunken')
 my $category_list = $lists_frame->BrowseEntry()->pack(-side=>'top',-fill=>'x');                  ->pack(-side=>'top',-anchor=>'ne',-fill=>'both',-expand=>1);
 $category_list->insert(-1, 'All');  
 my $accounts_list = $lists_frame->Scrolled('Listbox', -scrollbars => 'e')          my $account_frame = $right_frame->Frame(Name => 'account')
   ->pack(-side=>'top',-fill=>'both',-expand=>1);                  ->pack(-side=>'top',-anchor=>'nw',-fill=>'both',-expand=>1);
           my $lock_frame    = $right_frame->Frame(Name => 'lock',-relief=>'raised')
                   ->pack(-side=>'bottom',-fill=>'x');
 # Account  
 my %account_entry;          $pane->add('.main.lists');
 foreach my $label (qw/Category Name Account Password/) {          $pane->add('.main.right');
   $account_entry{$label} = $account_frame->LabEntry(-state=>'readonly',  
   -labelWidth => 10,  # Lists
   -labelPack => [-side => 'left', -anchor => 'w'],          my $category_list = $lists_frame->BrowseEntry()
   -label=>$label . ': ', -text => 'my' . $label)                  ->pack(-side=>'top',-fill=>'x');
   ->pack(-side=>'top',-anchor=>'nw',-fill=>'x');          $category_list->insert(-1, 'All');
 }          my $accounts_list = $lists_frame->Scrolled('Listbox', -scrollbars => 'e')
                   ->pack(-side=>'top',-fill=>'both',-expand=>1);
 $account_entry{'Details'} = $account_frame->ROText(-wrap => 'word',-height=>5,-width=>30)  
   ->pack(-side=>'top',-anchor=>'nw',-fill=>'both',-expand=>1);  
 $account_entry{'Details'}->insert('1.0',"This is a test\nThis is only a test");  # Account
           my %account_entry;
           foreach my $label (qw/Category Name Account Password/) {
 # Lock                  $account_entry{$label} = $account_frame->LabEntry(-state=>'readonly',
 my $lock_button = $lock_frame->Button(-text => 'Lock', -command => \&Lock)                          -labelWidth => 10,
   ->pack(-side=>'left');                          -labelPack => [-side => 'left', -anchor => 'w'],
 my $lock_progress = $lock_frame->ProgressBar(                          -label=>$label . ': ', -text => 'my' . $label)
   -variable=>\$lock_when,                                  ->pack(-side=>'top',-anchor=>'nw',-fill=>'x');
   -blocks => $lock_timeout,          }
   -from   => $lock_timeout,  
   -to     => 0,          $account_entry{'Details'} = $account_frame->ROText(-wrap => 'word',-height=>5,-width=>30)
   -gap    => 0,          ->pack(-side=>'top',-anchor=>'nw',-fill=>'both',-expand=>1);
 )->pack(-side=>'right',-fill=>'x',-expand=>1,-padx=>5);          $account_entry{'Details'}->insert('1.0',"This is a test\nThis is only a test");
   
 $lock_progress->repeat(500,\&Lock_Timeout);  
   # Lock
 my $menubar = build_menubar($MW);          my $lock_button = $lock_frame->Button(-text => 'Lock', -command => \&Lock)
                   ->pack(-side=>'left');
 _populate_lists($Keyring, $category_list, $accounts_list);          my $lock_progress = $lock_frame->ProgressBar(
                   -variable=>\$lock_when,
 my $VERSION = 0.01;                  -blocks => $lock_timeout,
                   -from   => $lock_timeout,
 MainLoop;                  -to     => 0,
                   -gap    => 0,
           )->pack(-side=>'right',-fill=>'x',-expand=>1,-padx=>5);
 sub build_menubar {  
           $lock_progress->repeat(500,\&Lock_Timeout);
   # Create the menubar and File and Quit menubuttons.  Note  
   # that the cascade's menu widget is automatically created.          my $menubar = build_menubar($MW);
   
   my $menubar = $MW->Menu;          _populate_lists($Keyring, $category_list, $accounts_list);
   $MW->configure(-menu => $menubar);  
   my $file = $menubar->cascade(-label => '~File', -tearoff => 0);          return $MW;
   my $help = $menubar->cascade(-label => '~Help', -tearoff => 0);  }
   
   # Create the menuitems for each menu.  First, the File menu item.  
   sub build_menubar {
   $file->command(-label => "Open",  -command => \&Open);  
   $file->command(-label => "Close", -command => \&Close);          my $MW = shift;
   $file->command(-label => "Quit",  -command => \&exit);  
           # Create the menubar and File and Quit menubuttons.  Note
   # Finally, the Help menuitems.          # that the cascade's menu widget is automatically created.
   
   $help->command(-label => 'Version');          my $menubar = $MW->Menu;
   $help->separator;          $MW->configure(-menu => $menubar);
   $help->command(-label => 'About');          my $file = $menubar->cascade(-label => '~File', -tearoff => 0);
           my $help = $menubar->cascade(-label => '~Help', -tearoff => 0);
   my $ver_dialog =   $MW->Dialog(-title   => $NAME . ' Version',  
     -text    => "$NAME\n\nVersion $VERSION",          # Create the menuitems for each menu.  First, the File menu item.
     -buttons => ['OK'],  
     -bitmap  => 'info');          $file->command(-label => "Open",  -command => \&Open);
   my $about_dialog = $MW->Dialog(-title   => 'About ' . $NAME,          $file->command(-label => "Close", -command => \&Close);
     -text    => 'About ' . $NAME . "\n" .          $file->command(-label => "Quit",  -command => \&exit);
                 '© Copyright 2006 Andrew Fresh <andrew@mad-techies.org>',  
     -buttons => ['OK']);          # Finally, the Help menuitems.
   my $menu = $help->cget('-menu');  
   $menu->entryconfigure('Version', -command => [$ver_dialog   => 'Show']);          $help->command(-label => 'Version');
   $menu->entryconfigure('About',   -command => [$about_dialog => 'Show']);          $help->separator;
           $help->command(-label => 'About');
   $menubar;                        # return the menubar  
           my $ver_dialog =   $MW->Dialog(-title   => $NAME . ' Version',
 }                  -text    => "$NAME\n\nVersion $VERSION",
                   -buttons => ['OK'],
 sub Lock                  -bitmap  => 'info');
 {          my $about_dialog = $MW->Dialog(-title   => 'About ' . $NAME,
   $unlocked = time;                  -text    => 'About ' . $NAME . "\n" .
 }                  '© Copyright 2006 Andrew Fresh <andrew@mad-techies.org>',
                   -buttons => ['OK']);
 sub Lock_Timeout          my $menu = $help->cget('-menu');
 {          $menu->entryconfigure('Version', -command => [$ver_dialog   => 'Show']);
   #return unless $unlocked;          $menu->entryconfigure('About',   -command => [$about_dialog => 'Show']);
   my $diff = time - $unlocked;  
   if ($diff > $lock_timeout) {          $menubar;                        # return the menubar
     print "Timed out!";  
     Tk::exit();  }
   } else {  
     $lock_when = $diff;  sub Lock
   }  {
 }          $unlocked = time;
   }
 sub Open  
 {  sub Lock_Timeout
 }  {
           #return unless $unlocked;
 sub Close          my $diff = time - $unlocked;
 {          if ($diff > $lock_timeout) {
 }                  print "Timed out!";
                   Tk::exit();
 sub _do_open                  Lock();
 {          } else {
   my $file = shift;                  $lock_when = $diff;
   my $pdb  = Palm::Keyring->new;          }
   $pdb->Load($file) || die "Couldn't load '$file'";  }
   return $pdb;  
 }  sub Open
   {
 sub _do_close          my $file = shift;
 {          my $pdb  = Palm::Keyring->new;
 }          $pdb->Load($file) || die "Couldn't load '$file'";
           return $pdb;
 sub _do_lock  }
 {  
 }  sub Close
   {
 sub _populate_lists  }
 {  
   my $pdb  = shift;  sub _populate_lists
   my $cat  = shift;  {
   my $acct = shift;          my $pdb  = shift;
   foreach my $category (@{ $pdb->{'appinfo'}->{'categories'} }) {          my $cat  = shift;
     next unless $category->{'name'};          my $acct = shift;
     $cat->insert( $category->{'id'}, $category->{'name'});          foreach my $category (@{ $pdb->{'appinfo'}->{'categories'} }) {
   }                  next unless $category->{'name'};
   foreach my $account (@{ $pdb->{'records'} }) {                  $cat->insert( $category->{'id'}, $category->{'name'});
     next unless $account->{'plaintext'}->{'name'};          }
     $acct->insert('end', $account->{'plaintext'}->{'name'});          foreach my $account (@{ $pdb->{'records'} }) {
   }                  next unless $account->{'plaintext'}->{'name'};
                       $acct->insert('end', $account->{'plaintext'}->{'name'});
 }          }
   
   }

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.5

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