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 {
|
499
|
27 if (S_ISDIR (fle->st_mode))
|
342
|
28 *start_color = GFTPUI_COMMON_COLOR_BLUE;
|
499
|
29 else if (S_ISLNK (fle->st_mode))
|
342
|
30 *start_color = GFTPUI_COMMON_COLOR_WHITE;
|
499
|
31 else if ((fle->st_mode & S_IXUSR) ||
|
|
32 (fle->st_mode & S_IXGRP) ||
|
|
33 (fle->st_mode & S_IXOTH))
|
342
|
34 *start_color = GFTPUI_COMMON_COLOR_GREEN;
|
|
35 else
|
|
36 *start_color = GFTPUI_COMMON_COLOR_DEFAULT;
|
|
37
|
|
38 *end_color = GFTPUI_COMMON_COLOR_DEFAULT;
|
|
39 }
|
|
40
|
|
41
|
|
42 void
|
521
|
43 gftpui_refresh (void *uidata, int clear_cache_entry)
|
342
|
44 {
|
380
|
45 gftp_request * request;
|
|
46
|
|
47 request = uidata; /* Note: uidata is set to the request in gftp_text.c */
|
514
|
48
|
521
|
49 if (clear_cache_entry)
|
514
|
50 gftp_delete_cache_entry (request, NULL, 0);
|
342
|
51 }
|
|
52
|
|
53
|
|
54 void *
|
|
55 gftpui_generic_thread (void * (*func) (void *), void *data)
|
|
56 {
|
367
|
57 return (func (data));
|
342
|
58 }
|
|
59
|
|
60
|
|
61 int
|
|
62 gftpui_check_reconnect (gftpui_callback_data * cdata)
|
|
63 {
|
|
64 return (1);
|
|
65 }
|
|
66
|
775
|
67 void
|
|
68 gftpui_show_busy (gboolean busy)
|
|
69 {
|
|
70 /* do nothing for text based */
|
|
71 }
|
356
|
72
|
380
|
73 void
|
356
|
74 gftpui_prompt_username (void *uidata, gftp_request * request)
|
|
75 {
|
380
|
76 char tempstr[256];
|
356
|
77
|
380
|
78 gftp_set_username (request,
|
|
79 gftp_text_ask_question (_("Username [anonymous]:"), 1,
|
|
80 tempstr, sizeof (tempstr)));
|
356
|
81 }
|
|
82
|
|
83
|
|
84
|
380
|
85 void
|
356
|
86 gftpui_prompt_password (void *uidata, gftp_request * request)
|
|
87 {
|
380
|
88 char tempstr[256];
|
356
|
89
|
380
|
90 gftp_set_password (request,
|
|
91 gftp_text_ask_question (_("Password:"), 0,
|
|
92 tempstr, sizeof (tempstr)));
|
356
|
93 }
|
|
94
|
367
|
95
|
|
96 void
|
397
|
97 gftpui_add_file_to_transfer (gftp_transfer * tdata, GList * curfle)
|
367
|
98 {
|
|
99 }
|
|
100
|
|
101
|
|
102 void
|
|
103 gftpui_ask_transfer (gftp_transfer * tdata)
|
|
104 {
|
378
|
105 char buf, question[1024], srcsize[50], destsize[50], *pos, defaction;
|
|
106 int action, newaction;
|
|
107 gftp_file * tempfle;
|
|
108 GList * templist;
|
|
109
|
|
110 action = newaction = -1;
|
|
111
|
|
112 for (templist = tdata->files; templist != NULL; templist = templist->next)
|
|
113 {
|
|
114 tempfle = templist->data;
|
499
|
115 if (tempfle->startsize == 0 || S_ISDIR (tempfle->st_mode))
|
378
|
116 continue;
|
|
117
|
|
118 while (action == -1)
|
|
119 {
|
|
120 insert_commas (tempfle->size, srcsize, sizeof (srcsize));
|
|
121 insert_commas (tempfle->startsize, destsize, sizeof (destsize));
|
|
122
|
|
123 if ((pos = strrchr (tempfle->file, '/')) != NULL)
|
|
124 pos++;
|
|
125 else
|
|
126 pos = tempfle->file;
|
|
127
|
|
128 gftp_get_transfer_action (tdata->fromreq, tempfle);
|
|
129 switch (tempfle->transfer_action)
|
|
130 {
|
|
131 case GFTP_TRANS_ACTION_OVERWRITE:
|
|
132 action = GFTP_TRANS_ACTION_OVERWRITE;
|
|
133 defaction = 'o';
|
|
134 break;
|
|
135 case GFTP_TRANS_ACTION_SKIP:
|
|
136 action = GFTP_TRANS_ACTION_SKIP;
|
|
137 defaction = 's';
|
|
138 break;
|
|
139 case GFTP_TRANS_ACTION_RESUME:
|
|
140 action = GFTP_TRANS_ACTION_RESUME;
|
|
141 defaction = 'r';
|
|
142 break;
|
|
143 default:
|
|
144 defaction = ' ';
|
|
145 break;
|
|
146 }
|
|
147
|
|
148 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);
|
|
149
|
|
150 gftp_text_ask_question (question, 1, &buf, 1);
|
|
151
|
|
152 switch (buf)
|
|
153 {
|
|
154 case 'o':
|
|
155 action = GFTP_TRANS_ACTION_OVERWRITE;
|
|
156 break;
|
|
157 case 'O':
|
|
158 action = newaction = GFTP_TRANS_ACTION_OVERWRITE;
|
|
159 break;
|
|
160 case 'r':
|
|
161 action = GFTP_TRANS_ACTION_RESUME;
|
|
162 break;
|
|
163 case 'R':
|
|
164 action = newaction = GFTP_TRANS_ACTION_RESUME;
|
|
165 break;
|
|
166 case 's':
|
|
167 action = GFTP_TRANS_ACTION_SKIP;
|
|
168 break;
|
|
169 case 'S':
|
|
170 action = newaction = GFTP_TRANS_ACTION_SKIP;
|
|
171 break;
|
380
|
172 case '\0':
|
|
173 case '\n':
|
|
174 break;
|
|
175 default:
|
|
176 action = -1;
|
|
177 break;
|
378
|
178 }
|
|
179 }
|
|
180
|
|
181 tempfle->transfer_action = action;
|
|
182 action = newaction;
|
|
183 }
|
367
|
184 }
|
|
185
|
377
|
186
|
|
187 static void
|
|
188 _gftpui_text_print_status (gftp_transfer * tdata)
|
|
189 {
|
|
190 static int progress_pos = 0;
|
|
191 char *progress = "|/-\\";
|
766
|
192 unsigned int sw, tot, i;
|
377
|
193
|
|
194 printf ("\r%c [", progress[progress_pos++]);
|
|
195
|
|
196 if (progress[progress_pos] == '\0')
|
|
197 progress_pos = 0;
|
|
198
|
|
199 sw = gftp_text_get_win_size () - 20;
|
766
|
200 tot = (unsigned int) ((float) tdata->curtrans / (float) tdata->tot_file_trans * (float) sw);
|
377
|
201
|
|
202 if (tot > sw)
|
|
203 tot = sw;
|
|
204
|
766
|
205 for (i = 0; i < tot; i++)
|
377
|
206 printf ("=");
|
|
207
|
766
|
208 for (i = 0; i < sw - tot; i++)
|
377
|
209 printf (" ");
|
|
210
|
|
211 printf ("] @ %.2fKB/s", tdata->kbs);
|
|
212
|
|
213 fflush (stdout);
|
|
214 }
|
|
215
|
|
216
|
|
217 void
|
|
218 gftpui_start_current_file_in_transfer (gftp_transfer * tdata)
|
|
219 {
|
|
220 _gftpui_text_print_status (tdata);
|
|
221 }
|
|
222
|
|
223
|
|
224 void
|
|
225 gftpui_update_current_file_in_transfer (gftp_transfer * tdata)
|
|
226 {
|
|
227 _gftpui_text_print_status (tdata);
|
|
228 }
|
|
229
|
|
230
|
|
231 void
|
|
232 gftpui_finish_current_file_in_transfer (gftp_transfer * tdata)
|
|
233 {
|
|
234 _gftpui_text_print_status (tdata);
|
|
235 printf ("\n");
|
|
236 }
|
|
237
|
|
238
|
|
239 void
|
|
240 gftpui_start_transfer (gftp_transfer * tdata)
|
|
241 {
|
|
242 gftpui_common_transfer_files (tdata);
|
|
243 }
|
|
244
|
380
|
245
|
|
246 void
|
|
247 gftpui_disconnect (void *uidata)
|
|
248 {
|
387
|
249 gftp_request * request;
|
|
250
|
|
251 request = uidata; /* Note: uidata is set to the request in gftp_text.c */
|
|
252 gftp_disconnect (request);
|
380
|
253 }
|
|
254
|
460
|
255
|
|
256 int
|
|
257 gftpui_protocol_ask_yes_no (gftp_request * request, char *title, char *question)
|
|
258 {
|
|
259 char buf[10];
|
|
260 int ret;
|
|
261
|
|
262 do
|
|
263 {
|
|
264 gftp_text_ask_question (question, 1, buf, sizeof (buf));
|
|
265 if (strcasecmp (buf, "yes") == 0)
|
|
266 ret = 1;
|
|
267 else if (strcasecmp (buf, "no") == 0)
|
|
268 ret = 0;
|
|
269 else
|
|
270 ret = -1;
|
|
271 }
|
|
272 while (ret == -1);
|
|
273
|
|
274 return (ret);
|
|
275 }
|
|
276
|
484
|
277
|
|
278 char *
|
|
279 gftpui_protocol_ask_user_input (gftp_request * request, char *title,
|
|
280 char *question, int shown)
|
|
281 {
|
|
282 char buf[255];
|
|
283
|
|
284 do
|
|
285 {
|
|
286 gftp_text_ask_question (question, shown, buf, sizeof (buf));
|
|
287 }
|
|
288 while (*buf == '\0');
|
|
289
|
|
290 return (g_strdup (buf));
|
|
291 }
|
|
292
|