Subject: | Make ftp connection parameters persistent |
Add options to make ftp connection, user, and password used for ftp connection available to the caller.
Also squelch a warning when the user cancels the dialog without making an ftp connection.
--- RemoteFileSelect.pm.old Wed Aug 28 08:02:06 2002
+++ RemoteFileSelect.pm Thu Mar 31 12:33:21 2005
@@ -18,9 +18,42 @@
my $dialog; # Reference to RemoteFileSelect widget.
my $file; # File selected in the widget.
- $dialog = $mw -> RemoteFileSelect( -directory => '.' );
+ $dialog = $mw -> RemoteFileSelect( ?I<options>? );
$file = $dialog -> Show;
+=head1 WIDGET-SPECIFIC OPTIONS
+
+=over 4
+
+=item Name: B<directory>
+
+=item Switch: B<-directory>
+
+Specifies the initial directory to start in.
+
+=item Name: B<ftpvariable>
+
+=item Switch: B<-ftpvariable>
+
+If the dialog successfully logs into an FTP server,
+set the variable referenced by this option to the ftp connection.
+
+=item Name: B<useridvariable>
+
+=item Switch: B<-useridvariable>
+
+If the dialog successfully logs into an FTP server,
+set the variable referenced by this option to the userid.
+
+=item Name: B<passwordvariable>
+
+=item Switch: B<-passwordvariable>
+
+If the dialog successfully logs into an FTP server,
+set the variable referenced by this option to the password.
+
+=back
+
=head1 DESCRIPTION
A RemoteFileSelect dialog contains two Listboxes that display
@@ -127,7 +160,7 @@
my $hostname = $cw -> cget( -hostname );
if( $hostname ne '' ) {
my $ftp = $cw -> cget( -ftp );
- $ftp -> quit;
+ $ftp -> quit if $ftp;
$cw -> configure( -ftp => undef,
-connected => '' );
}
@@ -177,6 +210,7 @@
if( $ftp -> login( $userid, $password ) ) {
$cw -> configure( -ftp => $ftp,
-connected => '1');
+ $cw->setLoginVariables( $ftp, $userid, $password );
} else {
my $edlg = $cw -> Subwidget( 'errormessage' );
$edlg -> configure( -text => "Error: Could not login to $hostid\." );
@@ -187,6 +221,16 @@
return $ftp;
}
+sub setLoginVariables {
+ my ($cw, $ftp, $userid, $password) = @_;
+ my $ftpvar = $cw->cget('-ftpvariable');
+ $$ftpvar = $ftp if $ftpvar and ref $ftpvar;
+ my $useridvar = $cw->cget('-useridvariable');
+ $$useridvar = $userid if $useridvar and ref $useridvar;
+ my $passwordvar = $cw->cget('-passwordvariable');
+ $$passwordvar = $password if $passwordvar and ref $useridvar;
+}
+
sub Accept {
# Accept the file or directory name if possible.
@@ -454,6 +498,9 @@
-uidlabel => ['PASSIVE', undef, undef, 'User ID:'],
-pwdlabel => ['PASSIVE', undef, undef, 'Password:'],
-connected => ['PASSIVE', undef, undef, '' ],
+ -ftpvariable => ['PASSIVE', undef, undef, '' ],
+ -useridvariable => ['PASSIVE', undef, undef, '' ],
+ -passwordvariable => ['PASSIVE', undef, undef, '' ],
DEFAULT => [ 'file_list' ],
);
$w->Delegates(DEFAULT => 'file_list');