342
|
1 /*****************************************************************************/
|
|
2 /* textui.c - Text UI related functions for gFTP */
|
|
3 /* Copyright (C) 1998-2003 Brian Masney <masneyb@gftp.org> */
|
|
4 /* */
|
|
5 /* This program is free software; you can redistribute it and/or modify */
|
|
6 /* it under the terms of the GNU General Public License as published by */
|
|
7 /* the Free Software Foundation; either version 2 of the License, or */
|
|
8 /* (at your option) any later version. */
|
|
9 /* */
|
|
10 /* This program is distributed in the hope that it will be useful, */
|
|
11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
|
12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
|
13 /* GNU General Public License for more details. */
|
|
14 /* */
|
|
15 /* You should have received a copy of the GNU General Public License */
|
|
16 /* along with this program; if not, write to the Free Software */
|
|
17 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA */
|
|
18 /*****************************************************************************/
|
|
19
|
|
20 #include "gftp-text.h"
|
|
21 static const char cvsid[] = "$Id$";
|
|
22
|
|
23 void
|
|
24 gftpui_lookup_file_colors (gftp_file * fle, char **start_color,
|
|
25 char ** end_color)
|
|
26 {
|
|
27 if (*fle->attribs == 'd')
|
|
28 *start_color = GFTPUI_COMMON_COLOR_BLUE;
|
|
29 else if (*fle->attribs == 'l')
|
|
30 *start_color = GFTPUI_COMMON_COLOR_WHITE;
|
|
31 else if (strchr (fle->attribs, 'x') != NULL)
|
|
32 *start_color = GFTPUI_COMMON_COLOR_GREEN;
|
|
33 else
|
|
34 *start_color = GFTPUI_COMMON_COLOR_DEFAULT;
|
|
35
|
|
36 *end_color = GFTPUI_COMMON_COLOR_DEFAULT;
|
|
37 }
|
|
38
|
|
39
|
|
40 void
|
|
41 gftpui_refresh (void *uidata)
|
|
42 {
|
380
|
43 gftp_request * request;
|
|
44
|
|
45 request = uidata; /* Note: uidata is set to the request in gftp_text.c */
|
|
46 gftp_delete_cache_entry (request, NULL, 0);
|
342
|
47 }
|
|
48
|
|
49
|
|
50 void *
|
|
51 gftpui_generic_thread (void * (*func) (void *), void *data)
|
|
52 {
|
367
|
53 return (func (data));
|
342
|
54 }
|
|
55
|
|
56
|
|
57 int
|
|
58 gftpui_check_reconnect (gftpui_callback_data * cdata)
|
|
59 {
|
|
60 return (1);
|
|
61 }
|
|
62
|
356
|
63
|
380
|
64 void
|
356
|
65 gftpui_prompt_username (void *uidata, gftp_request * request)
|
|
66 {
|
380
|
67 char tempstr[256];
|
356
|
68
|
380
|
69 gftp_set_username (request,
|
|
70 gftp_text_ask_question (_("Username [anonymous]:"), 1,
|
|
71 tempstr, sizeof (tempstr)));
|
356
|
72 }
|
|
73
|
|
74
|
|
75
|
380
|
76 void
|
356
|
77 gftpui_prompt_password (void *uidata, gftp_request * request)
|
|
78 {
|
380
|
79 char tempstr[256];
|
356
|
80
|
380
|
81 gftp_set_password (request,
|
|
82 gftp_text_ask_question (_("Password:"), 0,
|
|
83 tempstr, sizeof (tempstr)));
|
356
|
84 }
|
|
85
|
367
|
86
|
|
87 void
|
397
|
88 gftpui_add_file_to_transfer (gftp_transfer * tdata, GList * curfle)
|
367
|
89 {
|
|
90 }
|
|
91
|
|
92
|
|
93 void
|
|
94 gftpui_ask_transfer (gftp_transfer * tdata)
|
|
95 {
|
378
|
96 char buf, question[1024], srcsize[50], destsize[50], *pos, defaction;
|
|
97 int action, newaction;
|
|
98 gftp_file * tempfle;
|
|
99 GList * templist;
|
|
100
|
|
101 action = newaction = -1;
|
|
102
|
|
103 for (templist = tdata->files; templist != NULL; templist = templist->next)
|
|
104 {
|
|
105 tempfle = templist->data;
|
|
106 if (tempfle->startsize == 0 || tempfle->isdir)
|
|
107 continue;
|
|
108
|
|
109 while (action == -1)
|
|
110 {
|
|
111 insert_commas (tempfle->size, srcsize, sizeof (srcsize));
|
|
112 insert_commas (tempfle->startsize, destsize, sizeof (destsize));
|
|
113
|
|
114 if ((pos = strrchr (tempfle->file, '/')) != NULL)
|
|
115 pos++;
|
|
116 else
|
|
117 pos = tempfle->file;
|
|
118
|
|
119 gftp_get_transfer_action (tdata->fromreq, tempfle);
|
|
120 switch (tempfle->transfer_action)
|
|
121 {
|
|
122 case GFTP_TRANS_ACTION_OVERWRITE:
|
|
123 action = GFTP_TRANS_ACTION_OVERWRITE;
|
|
124 defaction = 'o';
|
|
125 break;
|
|
126 case GFTP_TRANS_ACTION_SKIP:
|
|
127 action = GFTP_TRANS_ACTION_SKIP;
|
|
128 defaction = 's';
|
|
129 break;
|
|
130 case GFTP_TRANS_ACTION_RESUME:
|
|
131 action = GFTP_TRANS_ACTION_RESUME;
|
|
132 defaction = 'r';
|
|
133 break;
|
|
134 default:
|
|
135 defaction = ' ';
|
|
136 break;
|
|
137 }
|
|
138
|
|
139 g_snprintf (question, sizeof (question), _("%s already exists. (%s source size, %s destination size):\n(o)verwrite, (r)esume, (s)kip, (O)verwrite All, (R)esume All, (S)kip All: (%c)"), pos, srcsize, destsize, defaction);
|
|
140
|
|
141 gftp_text_ask_question (question, 1, &buf, 1);
|
|
142
|
|
143 switch (buf)
|
|
144 {
|
|
145 case 'o':
|
|
146 action = GFTP_TRANS_ACTION_OVERWRITE;
|
|
147 break;
|
|
148 case 'O':
|
|
149 action = newaction = GFTP_TRANS_ACTION_OVERWRITE;
|
|
150 break;
|
|
151 case 'r':
|
|
152 action = GFTP_TRANS_ACTION_RESUME;
|
|
153 break;
|
|
154 case 'R':
|
|
155 action = newaction = GFTP_TRANS_ACTION_RESUME;
|
|
156 break;
|
|
157 case 's':
|
|
158 action = GFTP_TRANS_ACTION_SKIP;
|
|
159 break;
|
|
160 case 'S':
|
|
161 action = newaction = GFTP_TRANS_ACTION_SKIP;
|
|
162 break;
|
380
|
163 case '\0':
|
|
164 case '\n':
|
|
165 break;
|
|
166 default:
|
|
167 action = -1;
|
|
168 break;
|
378
|
169 }
|
|
170 }
|
|
171
|
|
172 tempfle->transfer_action = action;
|
|
173 action = newaction;
|
|
174 }
|
367
|
175 }
|
|
176
|
377
|
177
|
|
178 static void
|
|
179 _gftpui_text_print_status (gftp_transfer * tdata)
|
|
180 {
|
|
181 static int progress_pos = 0;
|
|
182 char *progress = "|/-\\";
|
|
183 int sw, tot, i;
|
|
184
|
|
185 printf ("\r%c [", progress[progress_pos++]);
|
|
186
|
|
187 if (progress[progress_pos] == '\0')
|
|
188 progress_pos = 0;
|
|
189
|
|
190 sw = gftp_text_get_win_size () - 20;
|
|
191 tot = (float) tdata->curtrans / (float) tdata->tot_file_trans * (float) sw;
|
|
192
|
|
193 if (tot > sw)
|
|
194 tot = sw;
|
|
195
|
|
196 for (i=0; i<tot; i++)
|
|
197 printf ("=");
|
|
198
|
|
199 for (i=0; i<sw-tot; i++)
|
|
200 printf (" ");
|
|
201
|
|
202 printf ("] @ %.2fKB/s", tdata->kbs);
|
|
203
|
|
204 fflush (stdout);
|
|
205 }
|
|
206
|
|
207
|
|
208 void
|
|
209 gftpui_start_current_file_in_transfer (gftp_transfer * tdata)
|
|
210 {
|
|
211 _gftpui_text_print_status (tdata);
|
|
212 }
|
|
213
|
|
214
|
|
215 void
|
|
216 gftpui_update_current_file_in_transfer (gftp_transfer * tdata)
|
|
217 {
|
|
218 _gftpui_text_print_status (tdata);
|
|
219 }
|
|
220
|
|
221
|
|
222 void
|
|
223 gftpui_finish_current_file_in_transfer (gftp_transfer * tdata)
|
|
224 {
|
|
225 _gftpui_text_print_status (tdata);
|
|
226 printf ("\n");
|
|
227 }
|
|
228
|
|
229
|
|
230 void
|
|
231 gftpui_start_transfer (gftp_transfer * tdata)
|
|
232 {
|
|
233 gftpui_common_transfer_files (tdata);
|
|
234 }
|
|
235
|
380
|
236
|
|
237 void
|
|
238 gftpui_disconnect (void *uidata)
|
|
239 {
|
387
|
240 gftp_request * request;
|
|
241
|
|
242 request = uidata; /* Note: uidata is set to the request in gftp_text.c */
|
|
243 gftp_disconnect (request);
|
380
|
244 }
|
|
245
|
460
|
246
|
|
247 int
|
|
248 gftpui_protocol_ask_yes_no (gftp_request * request, char *title, char *question)
|
|
249 {
|
|
250 char buf[10];
|
|
251 int ret;
|
|
252
|
|
253 do
|
|
254 {
|
|
255 gftp_text_ask_question (question, 1, buf, sizeof (buf));
|
|
256 if (strcasecmp (buf, "yes") == 0)
|
|
257 ret = 1;
|
|
258 else if (strcasecmp (buf, "no") == 0)
|
|
259 ret = 0;
|
|
260 else
|
|
261 ret = -1;
|
|
262 }
|
|
263 while (ret == -1);
|
|
264
|
|
265 return (ret);
|
|
266 }
|
|
267
|
484
|
268
|
|
269 char *
|
|
270 gftpui_protocol_ask_user_input (gftp_request * request, char *title,
|
|
271 char *question, int shown)
|
|
272 {
|
|
273 char buf[255];
|
|
274
|
|
275 do
|
|
276 {
|
|
277 gftp_text_ask_question (question, shown, buf, sizeof (buf));
|
|
278 }
|
|
279 while (*buf == '\0');
|
|
280
|
|
281 return (g_strdup (buf));
|
|
282 }
|
|
283
|