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