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