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