1
|
1 /*****************************************************************************/
|
|
2 /* chmod_dialog.c - the chmod dialog box */
|
|
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
|
|
23 static GtkWidget *suid, *sgid, *sticky, *ur, *uw, *ux, *gr, *gw, *gx, *or, *ow,
|
|
24 *ox;
|
|
25 static int mode;
|
|
26
|
48
|
27
|
|
28 static void *
|
|
29 do_chmod_thread (void * data)
|
|
30 {
|
129
|
31 int success, num, sj, network_timeout;
|
48
|
32 GList * filelist, * templist;
|
|
33 gftp_window_data * wdata;
|
|
34 gftp_file * tempfle;
|
|
35
|
|
36 wdata = data;
|
|
37
|
129
|
38 gftp_lookup_request_option (wdata->request, "network_timeout",
|
|
39 &network_timeout);
|
|
40
|
48
|
41 if (wdata->request->use_threads)
|
|
42 {
|
|
43 sj = sigsetjmp (jmp_environment, 1);
|
|
44 use_jmp_environment = 1;
|
|
45 }
|
|
46 else
|
|
47 sj = 0;
|
|
48
|
|
49 success = 0;
|
|
50 if (sj == 0)
|
|
51 {
|
|
52 filelist = wdata->files;
|
|
53 templist = GTK_CLIST (wdata->listbox)->selection;
|
|
54 num = 0;
|
|
55 while (templist != NULL)
|
|
56 {
|
|
57 templist = get_next_selection (templist, &filelist, &num);
|
|
58 tempfle = filelist->data;
|
129
|
59 if (network_timeout > 0)
|
|
60 alarm (network_timeout);
|
48
|
61 if (gftp_chmod (wdata->request, tempfle->file, mode) == 0)
|
|
62 success = 1;
|
|
63 if (!GFTP_IS_CONNECTED (wdata->request))
|
|
64 break;
|
|
65 }
|
|
66 alarm (0);
|
|
67 }
|
|
68 else
|
|
69 {
|
|
70 gftp_disconnect (wdata->request);
|
|
71 wdata->request->logging_function (gftp_logging_error,
|
186
|
72 wdata->request,
|
48
|
73 _("Operation canceled\n"));
|
|
74 }
|
|
75
|
|
76 if (wdata->request->use_threads)
|
|
77 use_jmp_environment = 0;
|
|
78
|
|
79 wdata->request->stopable = 0;
|
|
80 return ((void *) success);
|
|
81 }
|
|
82
|
|
83
|
|
84 static void
|
|
85 dochmod (GtkWidget * widget, gftp_window_data * wdata)
|
|
86 {
|
|
87 int cur;
|
|
88
|
|
89 mode = 0;
|
|
90 if (GTK_TOGGLE_BUTTON (suid)->active)
|
|
91 mode += 4;
|
|
92 if (GTK_TOGGLE_BUTTON (sgid)->active)
|
|
93 mode += 2;
|
|
94 if (GTK_TOGGLE_BUTTON (sticky)->active)
|
|
95 mode += 1;
|
|
96
|
|
97 cur = 0;
|
|
98 if (GTK_TOGGLE_BUTTON (ur)->active)
|
|
99 cur += 4;
|
|
100 if (GTK_TOGGLE_BUTTON (uw)->active)
|
|
101 cur += 2;
|
|
102 if (GTK_TOGGLE_BUTTON (ux)->active)
|
|
103 cur += 1;
|
|
104 mode = mode * 10 + cur;
|
|
105
|
|
106 cur = 0;
|
|
107 if (GTK_TOGGLE_BUTTON (gr)->active)
|
|
108 cur += 4;
|
|
109 if (GTK_TOGGLE_BUTTON (gw)->active)
|
|
110 cur += 2;
|
|
111 if (GTK_TOGGLE_BUTTON (gx)->active)
|
|
112 cur += 1;
|
|
113 mode = mode * 10 + cur;
|
|
114
|
|
115 cur = 0;
|
|
116 if (GTK_TOGGLE_BUTTON (or)->active)
|
|
117 cur += 4;
|
|
118 if (GTK_TOGGLE_BUTTON (ow)->active)
|
|
119 cur += 2;
|
|
120 if (GTK_TOGGLE_BUTTON (ox)->active)
|
|
121 cur += 1;
|
|
122 mode = mode * 10 + cur;
|
|
123
|
|
124 if (check_reconnect (wdata) < 0)
|
|
125 return;
|
|
126
|
|
127 if ((int) generic_thread (do_chmod_thread, wdata))
|
|
128 refresh (wdata);
|
|
129 }
|
|
130
|
|
131
|
45
|
132 #if GTK_MAJOR_VERSION > 1
|
19
|
133 static void
|
|
134 chmod_action (GtkWidget * widget, gint response, gpointer wdata)
|
|
135 {
|
|
136 switch (response)
|
|
137 {
|
|
138 case GTK_RESPONSE_OK:
|
|
139 dochmod (widget, wdata);
|
|
140 /* no break */
|
|
141 default:
|
|
142 gtk_widget_destroy (widget);
|
|
143 }
|
|
144 }
|
|
145 #endif
|
|
146
|
|
147
|
1
|
148 void
|
|
149 chmod_dialog (gpointer data)
|
|
150 {
|
|
151 GtkWidget *tempwid, *dialog, *hbox, *vbox;
|
|
152 GList * templist, * filelist;
|
|
153 gftp_window_data * wdata;
|
|
154 gftp_file * tempfle;
|
|
155 int num;
|
|
156
|
|
157 wdata = data;
|
65
|
158 if (!check_status (_("Chmod"), wdata, wdata->request->use_threads, 0, 1,
|
1
|
159 wdata->request->chmod != NULL))
|
|
160 return;
|
|
161
|
45
|
162 #if GTK_MAJOR_VERSION == 1
|
1
|
163 dialog = gtk_dialog_new ();
|
|
164 gtk_window_set_title (GTK_WINDOW (dialog), _("Chmod"));
|
|
165 gtk_container_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->action_area),
|
|
166 5);
|
|
167 gtk_box_set_homogeneous (GTK_BOX (GTK_DIALOG (dialog)->action_area), TRUE);
|
19
|
168 #else
|
|
169 dialog = gtk_dialog_new_with_buttons (_("Chmod"), NULL, 0,
|
|
170 GTK_STOCK_OK,
|
|
171 GTK_RESPONSE_OK,
|
|
172 GTK_STOCK_CANCEL,
|
|
173 GTK_RESPONSE_CANCEL,
|
|
174 NULL);
|
|
175 #endif
|
|
176 gtk_window_set_wmclass (GTK_WINDOW(dialog), "Chmod", "gFTP");
|
1
|
177 gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE);
|
19
|
178 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 5);
|
|
179 gtk_container_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), 10);
|
|
180 gtk_widget_realize (dialog);
|
|
181
|
|
182 if (gftp_icon != NULL)
|
|
183 {
|
|
184 gdk_window_set_icon (dialog->window, NULL, gftp_icon->pixmap,
|
|
185 gftp_icon->bitmap);
|
168
|
186 gdk_window_set_icon_name (dialog->window, gftp_version);
|
19
|
187 }
|
1
|
188
|
|
189 tempwid = gtk_label_new (_("You can now adjust the attributes of your file(s)\nNote: Not all ftp servers support the chmod feature"));
|
|
190 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), tempwid, FALSE,
|
|
191 FALSE, 0);
|
|
192 gtk_widget_show (tempwid);
|
|
193
|
|
194 hbox = gtk_hbox_new (TRUE, 5);
|
|
195 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), hbox, FALSE, FALSE,
|
|
196 0);
|
|
197 gtk_widget_show (hbox);
|
|
198
|
|
199 tempwid = gtk_frame_new (_("Special"));
|
|
200 gtk_box_pack_start (GTK_BOX (hbox), tempwid, FALSE, FALSE, 0);
|
|
201 gtk_widget_show (tempwid);
|
|
202
|
|
203 vbox = gtk_vbox_new (TRUE, 5);
|
|
204 gtk_container_add (GTK_CONTAINER (tempwid), vbox);
|
|
205 gtk_widget_show (vbox);
|
|
206
|
|
207 suid = gtk_check_button_new_with_label (_("SUID"));
|
|
208 gtk_box_pack_start (GTK_BOX (vbox), suid, FALSE, FALSE, 0);
|
|
209 gtk_widget_show (suid);
|
|
210
|
|
211 sgid = gtk_check_button_new_with_label (_("SGID"));
|
|
212 gtk_box_pack_start (GTK_BOX (vbox), sgid, FALSE, FALSE, 0);
|
|
213 gtk_widget_show (sgid);
|
|
214
|
|
215 sticky = gtk_check_button_new_with_label (_("Sticky"));
|
|
216 gtk_box_pack_start (GTK_BOX (vbox), sticky, FALSE, FALSE, 0);
|
|
217 gtk_widget_show (sticky);
|
|
218
|
|
219 tempwid = gtk_frame_new (_("User"));
|
|
220 gtk_box_pack_start (GTK_BOX (hbox), tempwid, FALSE, FALSE, 0);
|
|
221 gtk_widget_show (tempwid);
|
|
222
|
|
223 vbox = gtk_vbox_new (TRUE, 5);
|
|
224 gtk_container_add (GTK_CONTAINER (tempwid), vbox);
|
|
225 gtk_widget_show (vbox);
|
|
226
|
|
227 ur = gtk_check_button_new_with_label (_("Read"));
|
|
228 gtk_box_pack_start (GTK_BOX (vbox), ur, FALSE, FALSE, 0);
|
|
229 gtk_widget_show (ur);
|
|
230
|
|
231 uw = gtk_check_button_new_with_label (_("Write"));
|
|
232 gtk_box_pack_start (GTK_BOX (vbox), uw, FALSE, FALSE, 0);
|
|
233 gtk_widget_show (uw);
|
|
234
|
|
235 ux = gtk_check_button_new_with_label (_("Execute"));
|
|
236 gtk_box_pack_start (GTK_BOX (vbox), ux, FALSE, FALSE, 0);
|
|
237 gtk_widget_show (ux);
|
|
238
|
|
239 tempwid = gtk_frame_new (_("Group"));
|
|
240 gtk_box_pack_start (GTK_BOX (hbox), tempwid, FALSE, FALSE, 0);
|
|
241 gtk_widget_show (tempwid);
|
|
242
|
|
243 vbox = gtk_vbox_new (TRUE, 5);
|
|
244 gtk_container_add (GTK_CONTAINER (tempwid), vbox);
|
|
245 gtk_widget_show (vbox);
|
|
246
|
|
247 gr = gtk_check_button_new_with_label (_("Read"));
|
|
248 gtk_box_pack_start (GTK_BOX (vbox), gr, FALSE, FALSE, 0);
|
|
249 gtk_widget_show (gr);
|
|
250
|
|
251 gw = gtk_check_button_new_with_label (_("Write"));
|
|
252 gtk_box_pack_start (GTK_BOX (vbox), gw, FALSE, FALSE, 0);
|
|
253 gtk_widget_show (gw);
|
|
254
|
|
255 gx = gtk_check_button_new_with_label (_("Execute"));
|
|
256 gtk_box_pack_start (GTK_BOX (vbox), gx, FALSE, FALSE, 0);
|
|
257 gtk_widget_show (gx);
|
|
258
|
|
259 tempwid = gtk_frame_new (_("Other"));
|
|
260 gtk_box_pack_start (GTK_BOX (hbox), tempwid, FALSE, FALSE, 0);
|
|
261 gtk_widget_show (tempwid);
|
|
262
|
|
263 vbox = gtk_vbox_new (TRUE, 5);
|
|
264 gtk_container_add (GTK_CONTAINER (tempwid), vbox);
|
|
265 gtk_widget_show (vbox);
|
|
266
|
|
267 or = gtk_check_button_new_with_label (_("Read"));
|
|
268 gtk_box_pack_start (GTK_BOX (vbox), or, FALSE, FALSE, 0);
|
|
269 gtk_widget_show (or);
|
|
270
|
|
271 ow = gtk_check_button_new_with_label (_("Write"));
|
|
272 gtk_box_pack_start (GTK_BOX (vbox), ow, FALSE, FALSE, 0);
|
|
273 gtk_widget_show (ow);
|
|
274
|
|
275 ox = gtk_check_button_new_with_label (_("Execute"));
|
|
276 gtk_box_pack_start (GTK_BOX (vbox), ox, FALSE, FALSE, 0);
|
|
277 gtk_widget_show (ox);
|
|
278
|
45
|
279 #if GTK_MAJOR_VERSION == 1
|
19
|
280 tempwid = gtk_button_new_with_label (_("OK"));
|
1
|
281 GTK_WIDGET_SET_FLAGS (tempwid, GTK_CAN_DEFAULT);
|
|
282 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), tempwid,
|
|
283 TRUE, TRUE, 0);
|
|
284 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked",
|
|
285 GTK_SIGNAL_FUNC (dochmod), (gpointer) wdata);
|
|
286 gtk_signal_connect_object (GTK_OBJECT (tempwid), "clicked",
|
|
287 GTK_SIGNAL_FUNC (gtk_widget_destroy),
|
|
288 GTK_OBJECT (dialog));
|
|
289 gtk_widget_grab_default (tempwid);
|
|
290 gtk_widget_show (tempwid);
|
|
291
|
|
292 tempwid = gtk_button_new_with_label (_(" Cancel "));
|
|
293 GTK_WIDGET_SET_FLAGS (tempwid, GTK_CAN_DEFAULT);
|
|
294 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), tempwid,
|
|
295 TRUE, TRUE, 0);
|
|
296 gtk_signal_connect_object (GTK_OBJECT (tempwid), "clicked",
|
|
297 GTK_SIGNAL_FUNC (gtk_widget_destroy),
|
|
298 GTK_OBJECT (dialog));
|
|
299 gtk_widget_show (tempwid);
|
19
|
300 #else
|
|
301 g_signal_connect (GTK_OBJECT (dialog), "response",
|
|
302 G_CALLBACK (chmod_action), wdata);
|
|
303 #endif
|
1
|
304
|
|
305 if (IS_ONE_SELECTED (wdata))
|
|
306 {
|
|
307 filelist = wdata->files;
|
|
308 templist = GTK_CLIST (wdata->listbox)->selection;
|
|
309 num = 0;
|
|
310 templist = get_next_selection (templist, &filelist, &num);
|
|
311 tempfle = filelist->data;
|
|
312 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (suid),
|
|
313 tolower (tempfle->attribs[3]) == 's');
|
|
314 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (sgid),
|
|
315 tolower (tempfle->attribs[6]) == 's');
|
|
316 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (sticky),
|
|
317 tolower (tempfle->attribs[9]) == 't');
|
|
318 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ur),
|
|
319 tempfle->attribs[1] == 'r');
|
|
320 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (uw),
|
|
321 tempfle->attribs[2] == 'w');
|
|
322 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ux),
|
|
323 tempfle->attribs[3] == 'x' ||
|
|
324 tempfle->attribs[3] == 's');
|
|
325 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gr),
|
|
326 tempfle->attribs[4] == 'r');
|
|
327 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gw),
|
|
328 tempfle->attribs[5] == 'w');
|
|
329 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gx),
|
|
330 tempfle->attribs[6] == 'x' ||
|
|
331 tempfle->attribs[6] == 's');
|
|
332 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (or),
|
|
333 tempfle->attribs[7] == 'r');
|
|
334 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ow),
|
|
335 tempfle->attribs[8] == 'w');
|
|
336 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ox),
|
|
337 tempfle->attribs[9] == 'x' ||
|
|
338 tempfle->attribs[9] == 't');
|
|
339 }
|
|
340 gtk_widget_show (dialog);
|
|
341 }
|
|
342
|