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