1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11 
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
15  */
16 package net.sf.jftp.gui.tasks;
17 
18 import net.sf.jftp.JFtp;
19 import net.sf.jftp.config.Settings;
20 import net.sf.jftp.gui.base.UIUtils;
21 import net.sf.jftp.gui.framework.*;
22 import net.sf.jftp.net.*;
23 import net.sf.jftp.net.wrappers.StartConnection;
24 
25 import java.awt.*;
26 import java.awt.event.*;
27 
28 import java.io.*;
29 
30 import java.lang.Integer;
31 
32 import java.util.*;
33 
34 import javax.swing.*;
35 
36 
37 //***
38 public class BookmarkItem extends JMenuItem
39 {
40     private String host = "localhost";
41     private String user = "anonymous";
42     private String pass = "j-ftp@sourceforge.net";
43     private String protocol = "FTP";
44     private int port = 21;
45     private String dirOrDom = "/";
46     private boolean useLocal = false;
47 
BookmarkItem(String host)48     public BookmarkItem(String host)
49     {
50         super(host);
51         this.host = host;
52     }
53 
setProtocol(String proto)54     public void setProtocol(String proto)
55     {
56         protocol = proto;
57         setLabel(proto + ": " + getLabel());
58     }
59 
setDirectory(String dir)60     public void setDirectory(String dir)
61     {
62         dirOrDom = dir;
63     }
64 
setPort(int p)65     public void setPort(int p)
66     {
67         port = p;
68     }
69 
setLocal(boolean local)70     public void setLocal(boolean local)
71     {
72         useLocal = local;
73     }
74 
setUserdata(String u, String p)75     public void setUserdata(String u, String p)
76     {
77         user = u;
78         pass = p;
79     }
80 
connect()81     public void connect()
82     {
83         if(protocol.equals("FTP"))
84         {
85             if(pass.equals(Settings.hiddenPassword))
86             {
87                 pass = UIUtils.getPasswordFromUser(JFtp.statusP.jftp);
88             }
89 
90             int i = StartConnection.startFtpCon(host, user, pass, port,
91                                                 dirOrDom, useLocal);
92 
93             if(i < 0)
94             {
95                 pass = Settings.hiddenPassword;
96             }
97 
98             /*
99             FtpConnection con = StartConnection.con;
100 
101             if(con != null)
102             {
103                     con.chdir(dirOrDom);
104             }
105             */
106         }
107         else
108         {
109             if(pass.equals(Settings.hiddenPassword))
110             {
111                 pass = UIUtils.getPasswordFromUser(JFtp.statusP.jftp);
112             }
113 
114             boolean ok = StartConnection.startCon(protocol, host, user, pass,
115                                                   port, dirOrDom, useLocal);
116 
117             if(!ok)
118             {
119                 pass = Settings.hiddenPassword;
120             }
121         }
122     }
123 }
124