1
|
1 /*****************************************************************************/
|
|
2 /* delete_dialog.c - the delete dialog */
|
|
3 /* Copyright (C) 1998-2002 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-gtk.h"
|
|
21
|
|
22 static void askdel ( gftp_transfer * transfer );
|
19
|
23 static void yesCB ( gftp_transfer * transfer,
|
|
24 gftp_dialog_data * ddata );
|
1
|
25 static void * do_delete_thread ( void *data );
|
|
26 static void delete_purge_cache ( gpointer key,
|
|
27 gpointer value,
|
|
28 gpointer user_data );
|
|
29 static RETSIGTYPE sig_delquit ( int signo );
|
|
30
|
|
31 static sigjmp_buf delenvir;
|
|
32
|
|
33 void
|
|
34 delete_dialog (gpointer data)
|
|
35 {
|
|
36 gftp_file * tempfle, * newfle;
|
|
37 GList * templist, * filelist;
|
|
38 gftp_transfer * transfer;
|
|
39 gftp_window_data * wdata;
|
|
40 long numfiles, numdirs;
|
|
41 int num, timeout_num;
|
|
42 void *ret;
|
|
43
|
|
44 wdata = data;
|
|
45 if (!check_status (_("Delete"), wdata, wdata->request->use_threads, 0, 1, 1))
|
|
46 return;
|
|
47
|
|
48 transfer = g_malloc0 (sizeof (*transfer));
|
|
49 transfer->fromreq = copy_request (wdata->request);
|
|
50 transfer->fromwdata = wdata;
|
|
51 transfer->transfer_direction = GFTP_DIRECTION_DOWNLOAD;
|
|
52
|
|
53 num = 0;
|
|
54 templist = GTK_CLIST (wdata->listbox)->selection;
|
|
55 filelist = wdata->files;
|
|
56 while (templist != NULL)
|
|
57 {
|
|
58 templist = get_next_selection (templist, &filelist, &num);
|
|
59 tempfle = filelist->data;
|
|
60 if (strcmp (tempfle->file, "..") == 0 ||
|
|
61 strcmp (tempfle->file, ".") == 0)
|
|
62 continue;
|
|
63 newfle = copy_fdata (tempfle);
|
|
64 transfer->files = g_list_append (transfer->files, newfle);
|
|
65 }
|
|
66
|
|
67 if (transfer->files == NULL)
|
|
68 {
|
|
69 free_tdata (transfer);
|
|
70 return;
|
|
71 }
|
|
72
|
|
73 swap_socks (transfer->fromreq, wdata->request);
|
|
74
|
|
75 if (transfer->fromreq->use_threads)
|
|
76 {
|
|
77 wdata->request->stopable = 1;
|
|
78 transfer->fromreq->stopable = 1;
|
|
79 gtk_widget_set_sensitive (stop_btn, 1);
|
|
80 pthread_create (&wdata->tid, NULL, do_getdir_thread, transfer);
|
|
81
|
|
82 timeout_num = gtk_timeout_add (100, progress_timeout, transfer);
|
|
83 while (transfer->fromreq->stopable)
|
|
84 g_main_iteration (TRUE);
|
|
85
|
|
86 gtk_widget_set_sensitive (stop_btn, 0);
|
|
87 gtk_timeout_remove (timeout_num);
|
|
88 numfiles = transfer->numfiles;
|
|
89 numdirs = transfer->numdirs;
|
|
90 transfer->numfiles = transfer->numdirs = -1;
|
|
91 update_directory_download_progress (transfer);
|
|
92 transfer->numfiles = numfiles;
|
|
93 transfer->numdirs = numdirs;
|
|
94
|
|
95 pthread_join (wdata->tid, &ret);
|
|
96 wdata->request->stopable = 0;
|
|
97 }
|
|
98 else
|
|
99 ret = do_getdir_thread (transfer);
|
|
100
|
|
101 if (!GFTP_IS_CONNECTED (transfer->fromreq))
|
|
102 {
|
|
103 disconnect (wdata);
|
|
104 return;
|
|
105 }
|
|
106
|
|
107 swap_socks (wdata->request, transfer->fromreq);
|
|
108
|
|
109 askdel (transfer);
|
|
110 }
|
|
111
|
|
112
|
|
113 static void
|
|
114 askdel (gftp_transfer * transfer)
|
|
115 {
|
|
116 char *tempstr;
|
|
117
|
|
118 tempstr = g_strdup_printf (_("Are you sure you want to delete these %ld files and %ld directories"), transfer->numfiles, transfer->numdirs);
|
|
119
|
19
|
120 MakeYesNoDialog (_("Delete Files/Directories"), tempstr,
|
|
121 yesCB, transfer, NULL, NULL);
|
1
|
122 g_free (tempstr);
|
|
123 }
|
|
124
|
|
125
|
|
126 static void
|
19
|
127 yesCB (gftp_transfer * transfer, gftp_dialog_data * ddata)
|
1
|
128 {
|
|
129 gftp_window_data * wdata;
|
|
130 void * ret;
|
|
131
|
|
132 g_return_if_fail (transfer != NULL);
|
|
133 g_return_if_fail (transfer->files != NULL);
|
|
134
|
|
135 wdata = transfer->fromwdata;
|
|
136 if (check_reconnect (wdata) < 0)
|
|
137 return;
|
|
138
|
|
139 gtk_clist_freeze (GTK_CLIST (wdata->listbox));
|
|
140 swap_socks (transfer->fromreq, wdata->request);
|
|
141 if (wdata->request->use_threads)
|
|
142 {
|
|
143 wdata->request->stopable = 1;
|
|
144 transfer->fromreq->stopable = 1;
|
|
145 gtk_widget_set_sensitive (stop_btn, 1);
|
|
146 pthread_create (&wdata->tid, NULL, do_delete_thread, transfer);
|
|
147
|
|
148 while (transfer->fromreq->stopable)
|
|
149 g_main_iteration (TRUE);
|
|
150
|
|
151 gtk_widget_set_sensitive (stop_btn, 0);
|
|
152 pthread_join (wdata->tid, &ret);
|
|
153 wdata->request->stopable = 0;
|
|
154 }
|
|
155 else
|
|
156 ret = do_delete_thread (transfer);
|
|
157 swap_socks (wdata->request, transfer->fromreq);
|
|
158 free_tdata (transfer);
|
|
159
|
|
160 if (!GFTP_IS_CONNECTED (wdata->request))
|
|
161 disconnect (wdata);
|
|
162 else
|
|
163 refresh (wdata);
|
|
164
|
|
165 gtk_clist_thaw (GTK_CLIST (wdata->listbox));
|
|
166 }
|
|
167
|
|
168
|
|
169 static void *
|
|
170 do_delete_thread (void *data)
|
|
171 {
|
|
172 gftp_transfer * transfer;
|
|
173 char *pos, *tempstr;
|
|
174 gftp_file * tempfle;
|
|
175 GHashTable * rmhash;
|
|
176 GList * templist;
|
|
177 int success, sj;
|
|
178
|
|
179 transfer = data;
|
|
180 transfer->fromreq->user_data = (void *) 0x01;
|
|
181
|
|
182 if (transfer->fromreq->use_threads)
|
|
183 {
|
|
184 sj = sigsetjmp (delenvir, 1);
|
|
185 signal (SIGINT, sig_delquit);
|
|
186 signal (SIGALRM, sig_delquit);
|
|
187 }
|
|
188 else
|
|
189 sj = 0;
|
|
190
|
|
191 if (sj == 0)
|
|
192 {
|
|
193 for (templist = transfer->files; templist->next != NULL;
|
|
194 templist = templist->next);
|
|
195
|
|
196 rmhash = g_hash_table_new (string_hash_function, string_hash_compare);
|
|
197 while (1)
|
|
198 {
|
|
199 tempfle = templist->data;
|
|
200 if (tempfle->isdir)
|
|
201 success = gftp_remove_directory (transfer->fromreq, tempfle->file);
|
|
202 else
|
|
203 success = gftp_remove_file (transfer->fromreq, tempfle->file);
|
|
204
|
|
205 if (success == 0 && (pos = strrchr (tempfle->file, '/')))
|
|
206 {
|
|
207 *pos = '\0';
|
|
208 if (g_hash_table_lookup (rmhash, tempfle->file) == NULL)
|
|
209 {
|
|
210 tempstr = g_strconcat (tempfle->file, NULL);
|
|
211 g_hash_table_insert (rmhash, tempstr, NULL);
|
|
212 }
|
|
213 *pos = '/';
|
|
214 }
|
|
215
|
|
216 if (templist == transfer->files ||
|
|
217 !GFTP_IS_CONNECTED (transfer->fromreq))
|
|
218 break;
|
|
219 templist = templist->prev;
|
|
220 }
|
|
221
|
|
222 g_hash_table_foreach (rmhash, delete_purge_cache, transfer->fromreq);
|
|
223 g_hash_table_destroy (rmhash);
|
|
224 }
|
|
225 else
|
|
226 {
|
|
227 gftp_disconnect (transfer->fromreq);
|
|
228 transfer->fromreq->logging_function (gftp_logging_error,
|
|
229 transfer->fromreq->user_data,
|
|
230 _("Operation canceled\n"));
|
|
231 }
|
|
232
|
|
233 transfer->fromreq->user_data = NULL;
|
|
234 transfer->fromreq->stopable = 0;
|
|
235
|
|
236 if (transfer->fromreq->use_threads)
|
|
237 {
|
|
238 signal (SIGINT, SIG_DFL);
|
|
239 signal (SIGALRM, SIG_IGN);
|
|
240 }
|
|
241
|
|
242 return (NULL);
|
|
243 }
|
|
244
|
|
245
|
|
246 static void
|
|
247 delete_purge_cache (gpointer key, gpointer value, gpointer user_data)
|
|
248 {
|
|
249 gftp_request * request;
|
|
250 char *olddir;
|
|
251
|
|
252 request = user_data;
|
|
253 olddir = request->directory;
|
|
254 request->directory = key;
|
|
255 gftp_delete_cache_entry (request);
|
|
256 request->directory = olddir;
|
|
257 g_free (key);
|
|
258 }
|
|
259
|
|
260
|
|
261 static RETSIGTYPE
|
|
262 sig_delquit (int signo)
|
|
263 {
|
|
264 signal (signo, sig_delquit);
|
|
265 siglongjmp (delenvir, signo == SIGINT ? 1 : 2);
|
|
266 }
|
|
267
|