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