blib/lib/Sybase/Login.pm untested

filter: Statementstmt 0.0% 0 / 282 Branchbran 0.0% 0 / 84 Conditioncond 0.0% 0 / 36 MC/DCmcdc 0.0% 0 / 22 Subroutinesub 0.0% 0 / 20 Podpod 0.0% 0 / 14 totaltotal 0.0% 0 / 458 CC 43 SCAR 52.5
CC
43
Cov
0%
getVerification
506.0
addDatabase
42.0
Database
20.0
CRAP 189.8
1 ##########################################
2 ##########################################
3 ## ##
4 ## Login - a reusable Tk-widget ##
5 ## login screen ##
6 ## ##
7 ## Version 1.4 ##
8 ## ##
9 ## Brent B. Powers (B2Pi) ##
10 ## Merrill Lynch ##
11 ## powers@swaps-comm.ml.com ##
12 ## ##
13 ## ##
14 ##########################################
15 ##########################################
16  
17 =head1 NAME
18  
19 Sybase::Login - A highly configurable Login widget for Sybperl and Perl/Tk
20  
21 =head1 Change History
22  
23 =over 4
24  
25 =item
26  
27 I<1.0> - Initial Implementation
28  
29 I<1.1> - Componentized for perl5.0021bh, handlers fixed
30  
31 I<1.2> - Set up for general distribution, added Version and VERSION.
32 Changed funky menu generation to Optionmenus.
33  
34 I<1.3> - Added presentDBMenu and presentSrvMenu options.
35  
36 I<1.4> - OK, so I had troubles with PAUSE on 1.3
37  
38 I<Todo:> - Subclass Optionmenu to dynamically set up the Server
39 selections on post (or Buttondown?)
40  
41 =back
42  
43 =cut
44  
45 =head1 DESCRIPTION
46  
47 Login is a Widget that presents a dialog box to the user so that
48 the user may enter his or her login name and password, as well as
49 select the appropriate database and server.
50  
51 =head1 USAGE
52  
53 One uses Login by creating a new Login widget, adding at least one
54 Database via the addDatabase method, configuring via the configure
55 method, and then getting a valid login via the getVerification method.
56  
57 =over 4
58  
59 =item
60  
61 =head2 Sample Program
62  
63 =over 8
64  
65 =item
66  
67 #!/usr/local/bin/perl -w
68  
69 use Tk;
70 use Sybase::DBlib;
71 use Sybase::Login;
72 use strict;
73  
74 my($main) = MainWindow->new;
75 my($Login) = $main->Login;
76  
77 $Login->addDatabase('DB', 'SYBSRV1','SYB11');
78 $Login->addDatabase('DBBACK', 'SYBSRV1','SYB11');
79  
80 $Login->configure(-User => $ENV{USER},
81 -ULabel => 'User Name:',
82 -Title => 'Please Login');
83  
84 my($msg) = $main->Message(-text => 'Ready to go')->pack;
85 $main->Button(-text => 'kick me!',
86 -command => sub {
87 my($pwd, $usr, $db, $srv, $mDB);
88 if ($Login->getVerification(-Force => 1)) {
89 $pwd = $Login->cget(-Password);
90 $usr = $Login->cget(-User);
91 $db = $Login->cget(-Database);
92 $srv = $Login->cget(-Server);
93 print "Results good:\n\tUser:\t\t$usr\n";
94 print "\tPassword:\t$pwd\n\tDatabase:\t$db\n";
95 print "\tServer:\t\t$srv\n";
96 print "Verifying Login...\n";
97 $mDB = Sybase::DBlib->dblogin("$usr","$pwd", "$srv");
98 $mDB->dbuse($db);
99 $mDB->dbclose;
100 print "Login worked!!!\n";
101 } else {
102 print "Login cancelled at User request.\n";
103 }
104 })->pack;
105  
106 $main->Button(-text => 'exit',
107 -command => sub {$main->destroy;})->pack;
108  
109 MainLoop;
110  
111 print "And I'm on my way home!\n";
112  
113 exit;
114  
115 =back
116  
117 =item
118  
119 =head2 Operation
120  
121 The user is presented with a dialog box. The focus is on the username
122 entry if no user name has been configured; otherwise, it is on the
123 password entry. If multiple databases have been configured, the user
124 may select the appropriate database from the menu button. If multiple
125 servers have been configured for the selected database, the user may
126 select the appropriate server from the menu button.
127  
128 When the user has finished entering information, she may press the OK
129 button to attempt to login, or the cancel button to abort the process.
130 If the user presses the OK button, and the login succeeds, control
131 returns to the caller. If the login fails, an error dialog box is
132 displayed, and the user may press retry, or may press cancel, in which
133 case control returns to the caller exactly as if the user had pressed
134 cancel at the main login screen.
135  
136 When control returns to the caller, the return value will be 1 if the
137 login was successful, or 0 if not.
138  
139 =head2 Notes
140  
141 A caller may define a message or error handler either before or after
142 calling any of the methods of this object. getCurrentVerification
143 will restore the handlers extant when invoked.
144  
145 =back
146  
147 =head1 Methods
148  
149 =over 4
150  
151 =item
152  
153 =head2 getCurrentVerification
154  
155 I<$Login->>I<getCurrentVerification;>
156  
157 I<(No parameters)>
158  
159 return 1 if the current configuration will result
160 in a valid login, 0 otherwise. No GUI is ever displayed.
161  
162 =head2 getVerification
163  
164 I<$Login->>I<getVerification(-Force => ?);>
165  
166 If the current configuration is NOT valid, activate the login
167 frame. This will return 1 with a valid configuration, or 0 if the user
168 hit cancel. If the -Force parameter is passed as 't', 'y', or 1,
169 the login frame will be activated even if the current configuration
170 is valid.
171  
172 =head2 addDatabase
173  
174 I<$Login->>I<addDatabase(Database, Server List);>
175  
176 adds a database/server set. The first parameter is
177 the name of the database, the second is a list of
178 Associated Servers. See the code above for examples.
179  
180 Note that the first server in the list is the default server for that
181 database. Further note that adding a database a second time simply
182 alters the servers.
183  
184 =head2 clearDatabase
185  
186 I<$Login->>I<clearDatabase([Database[, Database,...]]);>
187  
188 Clears the given Database entries, or all databases if
189 if none are specified.
190  
191 =head2 Version
192  
193 I<$Login->>I<Version>
194  
195 I<(No parameters)>
196  
197 Returns the current version of Login
198  
199 =back
200  
201 =head1 Configuration Items
202  
203 Any of the following configuration items may be set via the configure
204 method, or retrieved via the cget method.
205  
206 =over 4
207  
208 =item
209  
210 =head2 -User
211  
212 =over 4
213  
214 Set or get the username. The default is blank.
215  
216 =back
217  
218 =head2 -Password
219  
220 =over 4
221  
222 Set or get the password. The default is blank.
223  
224 =back
225  
226 =head2 -Title
227  
228 =over 4
229  
230 Set or get the Title of the Login Widget. The default is 'Database Login'
231  
232 =back
233  
234 =head2 -Database
235  
236 =over 4
237  
238 Set or get the default Database. The default is blank. The call will
239 silently fail if the database is not configured via the AddDatabase
240 method. If the configured server is not a valid server for the given
241 database, the server will be set to the default server for the
242 database.
243  
244 =back
245  
246 =head2 -Server
247  
248 =over 4
249  
250 Set or get the default Server. The default is blank. The call will
251 silently fail if the server is not a valid server for the currently
252 configured database.
253  
254 =back
255  
256 =head2 -OKText
257  
258 =over 4
259  
260 Set or get the text for the I<OK> button. The default is OK.
261  
262 =back
263  
264 =head2 -CancelText
265  
266 =over 4
267  
268 Set or get the text for the I<Cancel> button. The default is Cancel.
269  
270  
271 =back
272  
273 =head2 -ULabel
274  
275 =over 4
276  
277 Set or get the label for the User name entry. The default is 'User:'.
278  
279 =back
280  
281 =head2 -PLabel
282  
283 =over 4
284  
285 Set or get the label for the Password entry. The default is 'Password:'.
286  
287 =back
288  
289 =head2 -DLabel
290  
291 =over 4
292  
293 Set or get the label for the Database Menu Button. The default is 'Database:'.
294  
295 =back
296  
297 =head2 -SLabel
298  
299 =over 4
300  
301 Set or get the label for the Server Menu Button. The default is 'Server:'.
302  
303 =back
304  
305 =head2 -Labelfont
306  
307 =over 4
308  
309 Set or get the font used for the labels. The default is
310 '-Adobe-Courier-Bold-R-Normal--*-120-*'.
311  
312 =back
313  
314 =head2 -EDlgTitle
315  
316 =over 4
317  
318 Set or get the Title for the Error Dialog. The default is
319 'Database Login Error!'.
320  
321 =back
322  
323 =head2 -EDlgText
324  
325 =over 4
326  
327 Set or get the text displayed in the Error Dialog. The default is
328 'Unable to login to $db at $srv'. $db will be interpreted as the
329 Database name, $srv will be interpreted as the Server name, $usr
330 will be interpreted as the User name, and $pwd will be interpreted
331 as the password.
332  
333 =back
334  
335 =head2 -EDlgRetry
336  
337 =over 4
338  
339 Set or get the text for the Retry button in the Error Dialog. The
340 default is 'Retry'.
341  
342 =back
343  
344 =head2 -EDlgCancel
345  
346 =over 4
347  
348 Set or get the text for the Cancel button in the Error Dialog. The
349 default is 'Cancel'.
350  
351 =back
352  
353 =head2 -presentDBMenu
354  
355 =over 4
356  
357 If set False, do not display the database menu. The database will be
358 as configured, or default. Default is True.
359  
360 =back
361  
362 =head2 -presentSrvMenu
363  
364 If set False, do not display the server menu. The Server will be as
365 configured, or default for the database. Default is True.
366  
367 =over 4
368  
369 =back
370  
371 =back
372  
373 =head1 Author
374  
375 B<Brent B. Powers, B2Pi>
376  
377 Currently on-site at Merrill Lynch, powers@ml.com
378  
379 This code may be distributed under the same conditions as perl itself.
380  
381 =cut
382 ### Gevalt. That's the end... now the code (350 lines of docs?)
383 #;
384  
385 package Sybase::Login;
386  
387 require 5.002;
388  
389 use Tk;
390 use Tk::Dialog;
391 use Sybase::DBlib;
392 use Carp;
393 use strict;
394  
395 @Sybase::Login::ISA = qw (Tk::Toplevel);
396 Tk::Widget->Construct('Login');
397  
398 $Sybase::VERSION = 1.4;
399  
400 my(@topside) = (-side => 'top');
401 my(@leftside) = (-side => 'left');
402 my(@rightside) = (-side => 'right');
403 my(@xfill) = (-fill => 'x');
404 my(@expand) = (-expand => 1);
405 my(@wanchor) = (-anchor => 'w');
406 my(@eanchor) = (-anchor => 'e');
407 my(@raised) = (-relief => 'raised');
408 my(@sunken) = (-relief => 'sunken');
409 my(@bw2) = (-borderwidth => 2);
410  
411 sub Populate {
412  
413 ## Constructor for Login (password verification) widget. Inherits
414 ## new from base class
415  
416 my($self, @args) = @_;
417  
418 $self->SUPER::Populate(@args);
419  
420 $self->withdraw;
421  
422 ## This is a good chance to initialize some values
423 $self->{Verified} = 0;
424 $self->{DBList} = undef;
425  
426 $self->BuildBox;
427  
428 $self->ConfigSpecs(-User => ['PASSIVE', undef, undef, ''],
429 -Password => ['PASSIVE', undef, undef, ''],
430 -Title => ['PASSIVE', undef, undef, 'Database Login'],
431 -Database => ['METHOD', undef, undef, ''],
432 -Server => ['METHOD', undef, undef, ''],
433 -presentDBMenu =>['PASSIVE', undef, undef, 1],
434 -presentSrvMenu=>['PASSIVE', undef, undef, 1],
435 -OKText => ['PASSIVE', undef, undef, 'OK'],
436 -CancelText => ['PASSIVE', undef, undef, 'Cancel'],
437 -ULabel => ['PASSIVE', undef, undef, 'User:'],
438 -PLabel => ['PASSIVE', undef, undef, 'Password:'],
439 -DLabel => ['PASSIVE', undef, undef, 'Database:'],
440 -SLabel => ['PASSIVE', undef, undef, 'Server:'],
441 -Labelfont => ['PASSIVE', undef, undef,
442 '-Adobe-Courier-Bold-R-Normal--*-120-*'],
443 -EDlgTitle => ['PASSIVE', undef, undef,
444 'Database Login Error!'],
445 -EDlgText => ['PASSIVE', undef, undef,
446 'Unable to login to $db at $srv'],
447 -EDlgRetry => ['PASSIVE', undef, undef,'Retry'],
448 -EDlgCancel => ['PASSIVE', undef, undef,'Cancel'],
449 );
450 }
451  
452 sub Version {return $Sybase::Login::VERSION;}
453  
454 sub addDatabase {
455 my($self,$db,@srvlist) = @_;
456 ### $db is the Database being added,
457 ### @srvlist is the list of servers
458  
459 if (defined($db)) {
460 $db =~ s/^\s+|\s+$//g;
461 } else {
462 $db = '';
463 }
464 if ($db eq '') {
465 carp "Use Login->addDatabase(database, server [, server ...])";
466 return;
467 }
468  
469 ## Kvetch if somebody's trying to add a blank database
470 if (!defined(@srvlist)) {
471 carp "No servers defined for $db";
472 return;
473 }
474  
475 ### The user may either be modifying a current entry,
476 ### implicitly deleting a current entry, or
477 ### creating a new entry
478 $self->{DBList}{$db} = \@srvlist;
479  
480 my($db1,$srv1);
481  
482 ### If the current Database is that just modified, check that the
483 ### current server is still valid. If not, set it to the default.
484 if ($self->{Configure}{-Database} eq $db) {
485 foreach (@srvlist) {
486 if ($self->{Configure}{'-Server'} eq $_) {
487 # Found it, so we're OK
488 return;
489 }
490 }
491 # Didn't find it, so set it to the default
492 $self->{Configure}{'-Server'} = @srvlist[0];
493 }
494 }
495  
496 sub clearDatabase {
497 # Parameters: ([Database[, Database, ...]])
498  
499 my($self) = shift;
500 my($firstdeldb) = @_;
501 if (defined($firstdeldb) and ($firstdeldb ne "")) {
502 ### Parameters given
503 foreach (@_) {
504 delete $self->{DBList}{$_};
505  
506 if ($self->{Configure}{'-Database'} eq $_ ) {
507 $self->{Configure}{'-Database'} = '';
508 $self->{Configure}{'-Server'} = '';
509 }
510 }
511 } else {
512 ### No parameters given, delete all databases
513 undef $self->{DBList};
514 $self->{Configure}{'-Database'} = '';
515 $self->{Configure}{'-Server'} = '';
516 }
517 }
518  
519 sub Server {
520 my($self, $server) = @_;
521  
522 my($db);
523  
524 # Verify that the server is correct before setting
525  
526 ## Note that the database must be configured first,
527 ## and the given server valid for the configured database
528 if (defined($server) &&
529 ($server ne '') &&
530 ($self->{Configure}{-Database} ne '')) {
531  
532 foreach (@{$self->{DBList}{$self->{Configure}{'-Database'}}}) {
533 if ($server eq $_) {
534 ## Found it... save it
535 $self->{Configure}{'-Server'} = $server;
536 last;
537 }
538 }
539 }
540 return $self->{Configure}{'-Server'};
541 }
542  
543 sub Database {
544 # Parameters: (Database)
545 my ($self, $db) = @_;
546  
547 if (defined($db) and ($db ne '')) {
548 ## Only set a database that is configured
549 if (defined($self->{DBList}{$db})) {
550 $self->{Configure}{'-Database'} = $db;
551  
552 ## Now check that the server is still valid
553 foreach (@{$self->{DBList}{$db}}) {
554 if ($self->{Configure}{'-Server'} eq $_) {
555 # It matches, and we're done
556 return $db;
557 }
558 }
559 ## Hmmm, no match, use default
560 $self->{Configure}{'-Server'} = $self->{DBList}{$db}[0];
561 }
562 }
563 return $self->{Configure}{'-Database'};
564 }
565  
566 sub BuildBox {
567  
568 my($self) = shift;
569  
570 ############ Create the User name frame #############
571 my($tFrame) = $self->Frame
572 ->pack(@topside, @xfill);
573  
574 $self->{ULabel} = $tFrame->Label(@wanchor)
575 ->pack(@leftside);
576  
577 $self->{userEntry} =
578 $tFrame->Entry(-textvariable => \$self->{Configure}{-User},
579 @sunken)
580 ->pack(@rightside, @expand, @xfill, @wanchor);
581  
582 ############ Create the Password Frame #############
583 $self->{PFrame} = $tFrame = $self->Frame
584 ->pack(@topside, @xfill);
585  
586 $self->{PLabel} = $tFrame->Label(@wanchor)
587 ->pack(@leftside);
588  
589 $self->{passEntry} =
590 $tFrame->Entry(-textvariable => \$self->{Configure}{-Password},
591 -show => '#',
592 @sunken)
593 ->pack(@rightside, @expand, @xfill, @wanchor);
594  
595 ############ Create the Button Frame #############
596 $tFrame = $self->Frame(@bw2)
597 ->pack(@topside);
598  
599 $self->{OKButton} = $tFrame->Button(-command => sub {
600 $self->TestLogin($self);
601 })
602 ->pack(@leftside, @expand);
603  
604 $self->{OKButton}->bind('<Return>' => [sub {$self->{OKButton}->invoke}]);
605  
606 $self->{CancelButton} = $tFrame->Button(-command => sub {
607 $self->Exit(0);
608 })
609 ->pack(@leftside, @expand);
610  
611 $self->{CancelButton}->bind('<Return>' => sub {
612 $self->{CancelButton}->invoke});
613 $self->bind('<Escape>' => [sub {$self->{CancelButton}->invoke}]);
614  
615 $self->{passEntry}->bind('<Return>'=> sub { $self->{OKButton}->focus; });
616 $self->{passEntry}->bind('<Control-u>' => sub {
617 $self->{Configure}{-Password} = '';
618 });
619 $self->{userEntry}->bind('<Control-u>' => sub {
620 $self->{Configure}{-User} = '';
621 });
622 $self->{userEntry}->bind('<Return>'=> sub {
623 \$self->{passEntry}->focus; } );
624 }
625  
626 sub getCurrentVerification {
627 my($self) = shift;
628  
629 ### The caller wants to find out if the current user, password
630 ### database and server are OK.
631 &TestDatabase($self);
632 }
633  
634 sub CvtBool {
635 my($a) = shift;
636 return 1 if defined($a) && $a =~ m/[ytYT1]/;
637 return 0;
638 }
639  
640 sub getVerification {
641  
642 my($self, $force, $forceval) = @_;
643 if (!defined($self->{DBList}) ||
644 (keys %{$self->{DBList}}) == 0) {
645 carp "No Databases defined";
646 return 0;
647 }
648  
649 if ((defined($force) &&
650 &CvtBool($forceval) &&
651 lc($force) eq '-force') ||
652 !getCurrentVerification($self)) {
653  
654 ## OK, do it
655 $self->{Verified} = -1;
656  
657 $self->{Configure}{-presentDBMenu} =
658 &CvtBool($self->{Configure}{-presentDBMenu});
659  
660 $self->{Configure}{-presentSrvMenu} =
661 &CvtBool($self->{Configure}{-presentSrvMenu});
662  
663 $self->title($self->{Configure}{-Title});
664 my($ParentState) = $self->parent->state;
665  
666 if ($ParentState ne 'withdrawn') {
667 $self->parent->withdraw;
668 }
669  
670 ## Set up the labels for the entries and menus
671 $self->{ULabel}->configure(-text => $self->{Configure}{-ULabel},
672 -font => $self->{Configure}{-Labelfont});
673 $self->{PLabel}->configure(-text => $self->{Configure}{-PLabel},
674 -font => $self->{Configure}{-Labelfont});
675  
676  
677 ############ Create the Database Frame, label, etc #############
678 $self->{dbFrame}->destroy if defined($self->{dbFrame});
679 if ($self->{Configure}{-presentDBMenu}) {
680 $self->{dbFrame} = $self->Frame
681 ->pack(-after => $self->{PFrame}, @xfill);
682 $self->{DLabel} = $self->{dbFrame}->Label(@wanchor)
683 ->pack(@leftside);
684 $self->{DLabel}->
685 configure(-text => $self->{Configure}{-DLabel},
686 -font => $self->{Configure}{-Labelfont});
687 }
688  
689 ############ Create the Server Frame, label, etc #############
690 $self->{srvFrame}->destroy if defined($self->{srvFrame});
691 if ($self->{Configure}{-presentSrvMenu}) {
692 my($f);
693 $f = $self->{srvFrame} = $self->Frame;
694 if ($self->{Configure}{-presentDBMenu}) {
695 $f->pack(-after => $self->{dbFrame}, @xfill)
696 } else {
697 $f->pack(-after => $self->{PFrame}, @xfill)
698 }
699  
700 $self->{SLabel} = $self->{srvFrame}->Label(@wanchor)
701 ->pack(@leftside);
702 $self->{SLabel}->
703 configure(-text => $self->{Configure}{-SLabel},
704 -font => $self->{Configure}{-Labelfont});
705 }
706  
707 $self->update;
708  
709 ## Get the widest label...
710 my($maxWidth) = $self->{ULabel}->reqwidth;
711 my($max) = '-ULabel';
712  
713 if ($self->{PLabel}->reqwidth > $maxWidth) {
714 $max = $self->{PLabel}->reqwidth;
715 $max = '-PLabel';
716 }
717  
718 if ($self->{Configure}{-presentDBMenu} &&
719 $self->{DLabel}->reqwidth > $maxWidth) {
720 $maxWidth = $self->{DLabel}->reqwidth;
721 $max = '-DLabel';
722 }
723  
724 if ($self->{Configure}{-presentSrvMenu} &&
725 $self->{SLabel}->reqwidth > $maxWidth) {
726 $maxWidth = $self->{SLabel}->reqwidth;
727 $max = '-SLabel';
728 }
729 $max = length($self->{Configure}{$max});
730  
731 $self->{ULabel}->configure(-width => $max);
732 $self->{PLabel}->configure(-width => $max);
733 $self->{DLabel}->configure(-width => $max)
734 if $self->{Configure}{-presentDBMenu};
735 $self->{SLabel}->configure(-width => $max)
736 if $self->{Configure}{-presentSrvMenu};
737 $self->update;
738  
739 # Make sure that the Database is set
740 if (!defined($self->{Configure}{'-Database'}) ||
741 ($self->{Configure}{'-Database'} eq '')) {
742 $self->{Configure}{'-Database'} = (keys %{$self->{DBList}})[0];
743 print "Set database to \"",(keys %{$self->{DBList}})[0],"\"\n";
744 }
745  
746 ## Set up the buttons
747 $self->{OKButton}->configure(-text =>
748 $self->{Configure}{-OKText});
749 $self->{CancelButton}->configure(-text =>
750 $self->{Configure}{-CancelText});
751  
752 $self->{databaseMB}->destroy if defined($self->{databaseMB});
753 if ($self->{Configure}{-presentDBMenu}) {
754 $self->{databaseMB} = $self->{dbFrame}->Optionmenu
755 (-textvariable => \$self->{Configure}{'-Database'},
756 -command => sub {
757 &CreateSrvMenu($self);
758 },
759 @raised)
760 ->pack(@rightside, @eanchor, @expand, @xfill);
761  
762 my(@opts);
763 foreach (sort keys(%{$self->{DBList}})) {
764 push(@opts,$_);
765 }
766  
767 $self->{databaseMB}->configure(-options => [@opts]);
768  
769 $self->{databaseMB}->configure(-state => 'disabled') if 1 == @opts;
770 }
771  
772 &CreateSrvMenu($self);
773  
774  
775 # Set the focus to the user if it hasn't been set, or
776 # to the password frame
777 my ($oldFocus) = $self->focusCurrent;
778 if ($self->{Configure}{-User} eq "") {
779 $self->{userEntry}->focusForce;
780 } else {
781 $self->{passEntry}->focusForce;
782 }
783  
784 # Take care of the window position
785 my($x) = int(($self->screenwidth - $self->reqwidth)/2)
786 - $self->parent->vrootx;
787 my($y) = int(($self->screenheight - $self->reqheight)/2)
788 - $self->parent->vrooty;
789  
790 $self->geometry("+$x+$y");
791  
792 $self->deiconify;
793  
794 ## And do a grab
795 $self->grab;
796  
797 ## Wait for verification or cancel
798 $self->tkwait('variable'=>\$self->{Verified});
799  
800 $self->grab('release');
801 $oldFocus->focus if defined($oldFocus);
802  
803 $self->withdraw;
804 if ($ParentState eq 'normal') {
805 $self->parent->deiconify;
806 } elsif ($ParentState eq 'iconic') {
807 $self->parent->iconify;
808 }
809  
810 return $self->{Verified};
811  
812 }
813 return 1;
814 }
815  
816 sub CreateSrvMenu {
817 my($self) = @_;
818  
819 $self->{serverMB}->destroy if (defined($self->{serverMB}));
820  
821 $self->{Configure}{'-Server'} =
822 $self->{DBList}{$self->{Configure}{'-Database'}}[0];
823  
824 return if !$self->{Configure}{-presentSrvMenu};
825  
826 my(@opts);
827 foreach (@{$self->{DBList}{$self->{Configure}{'-Database'}}}) {
828 push(@opts, $_);
829 }
830  
831 $self->{serverMB} = $self->{srvFrame}->
832 Optionmenu(-textvariable => \$self->{Configure}{'-Server'},
833 -options => [@opts],
834 @raised)
835 ->pack(@rightside, @eanchor, @expand, @xfill);
836  
837 $self->{Configure}{'-Server'} =
838 $self->{DBList}{$self->{Configure}{'-Database'}}[0];
839  
840 $self->{serverMB}->configure(-state => 'disabled') if 1 == @opts;
841 }
842  
843 ################################
844 ## Password Screen Subroutines
845 ################################
846  
847 sub TestDatabase {
848 ## Validate the current variables.
849  
850 my($self) = shift;
851  
852 $self->configure(-cursor => 'watch');
853 $self->update;
854  
855 my($rslt,$mh, $eh);
856  
857 my($usr, $pwd, $srv, $db);
858 $usr = $self->{Configure}{-User};
859 $pwd = $self->{Configure}{-Password};
860 $srv = $self->{Configure}{'-Server'};
861 $db = $self->{Configure}{'-Database'};
862  
863 $mh = &dbmsghandle(undef);
864 $eh = &dberrhandle(undef);
865 $rslt = eval {
866 &dbmsghandle(sub {return 1});
867 &dberrhandle(sub {die;});
868  
869 my($MasterDB) = Sybase::DBlib->dblogin("$usr","$pwd", "$srv");
870 $MasterDB->dbuse($db);
871 $MasterDB->dbclose;
872 return 1;
873 };
874  
875 $rslt = $1 if !defined($rslt);
876  
877 if (defined($mh)) {
878 &dbmsghandle($mh);
879 } else {
880 &dbmsghandle(undef);
881 }
882 if (defined($eh)) {
883 &dberrhandle($eh);
884 } else {
885 &dberrhandle(undef);
886 }
887  
888 $self->configure(-cursor => 'top_left_arrow');
889 $self->update;
890 return $rslt;
891 }
892  
893 sub TestLogin {
894  
895 my($self) = @_;
896  
897 ## Validate the current set of login variables.
898 ## If there's a failure, inform the user via a dialog
899 if ($self->getCurrentVerification) {
900 $self->Exit(1);
901 } else {
902 my($db) = $self->{Configure}{'-Database'};
903 my($srv) = $self->{Configure}{'-Server'};
904 my($usr) = $self->{Configure}{-User};
905 my($pwd) = $self->{Configure}{-Password};
906  
907 eval "\$db = \"$self->{Configure}{-EDlgText}\"";
908  
909 if ($self->Dialog(-title => $self->{Configure}{-EDlgTitle},
910 -text => $db,
911 -bitmap => 'error',
912 -default_button => $self->{Configure}{-EDlgRetry},
913 -justify => 'center',
914 -buttons => [$self->{Configure}{-EDlgRetry},
915 $self->{Configure}{-EDlgCancel}])
916 ->Show eq $self->{Configure}{-EDlgCancel}) {
917 $self->Exit(0);
918 }
919 }
920 }
921  
922 sub Exit {
923 my($self, $arg) = @_;
924 ## Trigger the change to the value Verified, enabling an exit
925 ## from the tkwait.
926 $self->{Verified} = $arg;
927 return $self->{Verified};
928 }
929  
930 ### Return 1 to the calling use statement ###
931 1;
932 ### End of file Login.pm ###