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
|
|
88 gftpui_add_file_to_transfer (gftp_transfer * tdata, GList * curfle,
|
377
|
89 char *filepos )
|
367
|
90 {
|
|
91 }
|
|
92
|
|
93
|
|
94 void
|
|
95 gftpui_ask_transfer (gftp_transfer * tdata)
|
|
96 {
|
378
|
97 char buf, question[1024], srcsize[50], destsize[50], *pos, defaction;
|
|
98 int action, newaction;
|
|
99 gftp_file * tempfle;
|
|
100 GList * templist;
|
|
101
|
|
102 action = newaction = -1;
|
|
103
|
|
104 for (templist = tdata->files; templist != NULL; templist = templist->next)
|
|
105 {
|
|
106 tempfle = templist->data;
|
|
107 if (tempfle->startsize == 0 || tempfle->isdir)
|
|
108 continue;
|
|
109
|
|
110 while (action == -1)
|
|
111 {
|
|
112 insert_commas (tempfle->size, srcsize, sizeof (srcsize));
|
|
113 insert_commas (tempfle->startsize, destsize, sizeof (destsize));
|
|
114
|
|
115 if ((pos = strrchr (tempfle->file, '/')) != NULL)
|
|
116 pos++;
|
|
117 else
|
|
118 pos = tempfle->file;
|
|
119
|
|
120 gftp_get_transfer_action (tdata->fromreq, tempfle);
|
|
121 switch (tempfle->transfer_action)
|
|
122 {
|
|
123 case GFTP_TRANS_ACTION_OVERWRITE:
|
|
124 action = GFTP_TRANS_ACTION_OVERWRITE;
|
|
125 defaction = 'o';
|
|
126 break;
|
|
127 case GFTP_TRANS_ACTION_SKIP:
|
|
128 action = GFTP_TRANS_ACTION_SKIP;
|
|
129 defaction = 's';
|
|
130 break;
|
|
131 case GFTP_TRANS_ACTION_RESUME:
|
|
132 action = GFTP_TRANS_ACTION_RESUME;
|
|
133 defaction = 'r';
|
|
134 break;
|
|
135 default:
|
|
136 defaction = ' ';
|
|
137 break;
|
|
138 }
|
|
139
|
|
140 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);
|
|
141
|
|
142 gftp_text_ask_question (question, 1, &buf, 1);
|
|
143
|
|
144 switch (buf)
|
|
145 {
|
|
146 case 'o':
|
|
147 action = GFTP_TRANS_ACTION_OVERWRITE;
|
|
148 break;
|
|
149 case 'O':
|
|
150 action = newaction = GFTP_TRANS_ACTION_OVERWRITE;
|
|
151 break;
|
|
152 case 'r':
|
|
153 action = GFTP_TRANS_ACTION_RESUME;
|
|
154 break;
|
|
155 case 'R':
|
|
156 action = newaction = GFTP_TRANS_ACTION_RESUME;
|
|
157 break;
|
|
158 case 's':
|
|
159 action = GFTP_TRANS_ACTION_SKIP;
|
|
160 break;
|
|
161 case 'S':
|
|
162 action = newaction = GFTP_TRANS_ACTION_SKIP;
|
|
163 break;
|
380
|
164 case '\0':
|
|
165 case '\n':
|
|
166 break;
|
|
167 default:
|
|
168 action = -1;
|
|
169 break;
|
378
|
170 }
|
|
171 }
|
|
172
|
|
173 tempfle->transfer_action = action;
|
|
174 action = newaction;
|
|
175 }
|
367
|
176 }
|
|
177
|
377
|
178
|
|
179 static void
|
|
180 _gftpui_text_print_status (gftp_transfer * tdata)
|
|
181 {
|
|
182 static int progress_pos = 0;
|
|
183 char *progress = "|/-\\";
|
|
184 int sw, tot, i;
|
|
185
|
|
186 printf ("\r%c [", progress[progress_pos++]);
|
|
187
|
|
188 if (progress[progress_pos] == '\0')
|
|
189 progress_pos = 0;
|
|
190
|
|
191 sw = gftp_text_get_win_size () - 20;
|
|
192 tot = (float) tdata->curtrans / (float) tdata->tot_file_trans * (float) sw;
|
|
193
|
|
194 if (tot > sw)
|
|
195 tot = sw;
|
|
196
|
|
197 for (i=0; i<tot; i++)
|
|
198 printf ("=");
|
|
199
|
|
200 for (i=0; i<sw-tot; i++)
|
|
201 printf (" ");
|
|
202
|
|
203 printf ("] @ %.2fKB/s", tdata->kbs);
|
|
204
|
|
205 fflush (stdout);
|
|
206 }
|
|
207
|
|
208
|
|
209 void
|
|
210 gftpui_start_current_file_in_transfer (gftp_transfer * tdata)
|
|
211 {
|
|
212 _gftpui_text_print_status (tdata);
|
|
213 }
|
|
214
|
|
215
|
|
216 void
|
|
217 gftpui_update_current_file_in_transfer (gftp_transfer * tdata)
|
|
218 {
|
|
219 _gftpui_text_print_status (tdata);
|
|
220 }
|
|
221
|
|
222
|
|
223 void
|
|
224 gftpui_finish_current_file_in_transfer (gftp_transfer * tdata)
|
|
225 {
|
|
226 _gftpui_text_print_status (tdata);
|
|
227 printf ("\n");
|
|
228 }
|
|
229
|
|
230
|
|
231 void
|
|
232 gftpui_start_transfer (gftp_transfer * tdata)
|
|
233 {
|
|
234 gftpui_common_transfer_files (tdata);
|
|
235 }
|
|
236
|
380
|
237
|
|
238 void
|
|
239 gftpui_disconnect (void *uidata)
|
|
240 {
|
|
241 }
|
|
242
|