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