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