1
|
1 /*****************************************************************************/
|
|
2 /* delete_dialog.c - the delete dialog */
|
885
|
3 /* Copyright (C) 1998-2007 Brian Masney <masneyb@gftp.org> */
|
1
|
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
|
525
|
24 _gftp_gtk_free_del_data (gftp_transfer * transfer, gftp_dialog_data * ddata)
|
|
25 {
|
|
26 free_tdata (transfer);
|
|
27 }
|
|
28
|
|
29
|
|
30 static void
|
48
|
31 yesCB (gftp_transfer * transfer, gftp_dialog_data * ddata)
|
|
32 {
|
507
|
33 gftpui_callback_data * cdata;
|
48
|
34 gftp_window_data * wdata;
|
|
35
|
|
36 g_return_if_fail (transfer != NULL);
|
|
37 g_return_if_fail (transfer->files != NULL);
|
|
38
|
|
39 wdata = transfer->fromwdata;
|
|
40
|
507
|
41 cdata = g_malloc0 (sizeof (*cdata));
|
|
42 cdata->request = wdata->request;
|
|
43 cdata->files = transfer->files;
|
|
44 cdata->uidata = wdata;
|
|
45 cdata->run_function = gftpui_common_run_delete;
|
48
|
46
|
507
|
47 gftpui_common_run_callback_function (cdata);
|
|
48
|
|
49 g_free (cdata);
|
525
|
50 _gftp_gtk_free_del_data (transfer, ddata);
|
48
|
51 }
|
|
52
|
|
53
|
|
54 static void
|
|
55 askdel (gftp_transfer * transfer)
|
|
56 {
|
|
57 char *tempstr;
|
|
58
|
507
|
59 if (transfer->numfiles > 0 && transfer->numdirs > 0)
|
|
60 {
|
|
61 tempstr = g_strdup_printf (_("Are you sure you want to delete these %ld files and %ld directories"), transfer->numfiles, transfer->numdirs);
|
|
62 }
|
|
63 else if (transfer->numfiles > 0)
|
|
64 {
|
|
65 tempstr = g_strdup_printf (_("Are you sure you want to delete these %ld files"), transfer->numfiles, transfer->numdirs);
|
|
66 }
|
|
67 else if (transfer->numdirs > 0)
|
|
68 {
|
827
|
69 tempstr = g_strdup_printf (_("Are you sure you want to delete these %ld directories"), transfer->numdirs);
|
507
|
70 }
|
|
71 else
|
|
72 return;
|
48
|
73
|
|
74 MakeYesNoDialog (_("Delete Files/Directories"), tempstr,
|
525
|
75 yesCB, transfer, _gftp_gtk_free_del_data, transfer);
|
48
|
76 g_free (tempstr);
|
|
77 }
|
|
78
|
1
|
79
|
|
80 void
|
|
81 delete_dialog (gpointer data)
|
|
82 {
|
|
83 gftp_file * tempfle, * newfle;
|
|
84 GList * templist, * filelist;
|
|
85 gftp_transfer * transfer;
|
|
86 gftp_window_data * wdata;
|
506
|
87 int num, ret;
|
1
|
88
|
|
89 wdata = data;
|
511
|
90 if (!check_status (_("Delete"), wdata,
|
|
91 gftpui_common_use_threads (wdata->request), 0, 1, 1))
|
1
|
92 return;
|
|
93
|
|
94 transfer = g_malloc0 (sizeof (*transfer));
|
368
|
95 transfer->fromreq = gftp_copy_request (wdata->request);
|
1
|
96 transfer->fromwdata = wdata;
|
|
97
|
|
98 num = 0;
|
525
|
99 templist = gftp_gtk_get_list_selection (wdata);
|
1
|
100 filelist = wdata->files;
|
|
101 while (templist != NULL)
|
|
102 {
|
|
103 templist = get_next_selection (templist, &filelist, &num);
|
|
104 tempfle = filelist->data;
|
|
105 if (strcmp (tempfle->file, "..") == 0 ||
|
|
106 strcmp (tempfle->file, ".") == 0)
|
|
107 continue;
|
|
108 newfle = copy_fdata (tempfle);
|
|
109 transfer->files = g_list_append (transfer->files, newfle);
|
|
110 }
|
|
111
|
|
112 if (transfer->files == NULL)
|
|
113 {
|
|
114 free_tdata (transfer);
|
|
115 return;
|
|
116 }
|
|
117
|
63
|
118 gftp_swap_socks (transfer->fromreq, wdata->request);
|
1
|
119
|
767
|
120 ret = gftp_gtk_get_subdirs (transfer);
|
1
|
121
|
525
|
122 gftp_swap_socks (wdata->request, transfer->fromreq);
|
|
123
|
|
124 if (!GFTP_IS_CONNECTED (wdata->request))
|
1
|
125 {
|
380
|
126 gftpui_disconnect (wdata);
|
1
|
127 return;
|
|
128 }
|
|
129
|
506
|
130 if (!ret)
|
|
131 return;
|
|
132
|
1
|
133 askdel (transfer);
|
|
134 }
|
|
135
|
|
136
|