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