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;
|
499
|
25 static mode_t mode;
|
1
|
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;
|
525
|
40 templist = gftp_gtk_get_list_selection (wdata);
|
441
|
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;
|
48
|
62
|
|
63 mode = 0;
|
|
64 if (GTK_TOGGLE_BUTTON (suid)->active)
|
499
|
65 mode |= S_ISUID;
|
48
|
66 if (GTK_TOGGLE_BUTTON (sgid)->active)
|
499
|
67 mode |= S_ISGID;
|
48
|
68 if (GTK_TOGGLE_BUTTON (sticky)->active)
|
499
|
69 mode |= S_ISVTX;
|
48
|
70
|
|
71 if (GTK_TOGGLE_BUTTON (ur)->active)
|
499
|
72 mode |= S_IRUSR;
|
48
|
73 if (GTK_TOGGLE_BUTTON (uw)->active)
|
499
|
74 mode |= S_IWUSR;
|
48
|
75 if (GTK_TOGGLE_BUTTON (ux)->active)
|
499
|
76 mode |= S_IXUSR;
|
48
|
77
|
|
78 if (GTK_TOGGLE_BUTTON (gr)->active)
|
499
|
79 mode |= S_IRGRP;
|
48
|
80 if (GTK_TOGGLE_BUTTON (gw)->active)
|
499
|
81 mode |= S_IWGRP;
|
48
|
82 if (GTK_TOGGLE_BUTTON (gx)->active)
|
648
|
83 mode |= S_IXGRP;
|
48
|
84
|
|
85 if (GTK_TOGGLE_BUTTON (or)->active)
|
499
|
86 mode |= S_IROTH;
|
48
|
87 if (GTK_TOGGLE_BUTTON (ow)->active)
|
499
|
88 mode |= S_IWOTH;
|
48
|
89 if (GTK_TOGGLE_BUTTON (ox)->active)
|
499
|
90 mode |= S_IXOTH;
|
48
|
91
|
|
92 if (check_reconnect (wdata) < 0)
|
|
93 return;
|
|
94
|
441
|
95 cdata = g_malloc0 (sizeof (*cdata));
|
|
96 cdata->request = wdata->request;
|
|
97 cdata->uidata = wdata;
|
|
98 cdata->run_function = do_chmod_thread;
|
|
99
|
517
|
100 gftpui_common_run_callback_function (cdata);
|
441
|
101
|
|
102 g_free (cdata);
|
48
|
103 }
|
|
104
|
|
105
|
45
|
106 #if GTK_MAJOR_VERSION > 1
|
19
|
107 static void
|
|
108 chmod_action (GtkWidget * widget, gint response, gpointer wdata)
|
|
109 {
|
|
110 switch (response)
|
|
111 {
|
|
112 case GTK_RESPONSE_OK:
|
|
113 dochmod (widget, wdata);
|
|
114 /* no break */
|
|
115 default:
|
|
116 gtk_widget_destroy (widget);
|
|
117 }
|
|
118 }
|
|
119 #endif
|
|
120
|
|
121
|
1
|
122 void
|
|
123 chmod_dialog (gpointer data)
|
|
124 {
|
|
125 GtkWidget *tempwid, *dialog, *hbox, *vbox;
|
|
126 GList * templist, * filelist;
|
|
127 gftp_window_data * wdata;
|
|
128 gftp_file * tempfle;
|
|
129 int num;
|
|
130
|
|
131 wdata = data;
|
341
|
132 if (!check_status (_("Chmod"), wdata, gftpui_common_use_threads (wdata->request), 0, 1, wdata->request->chmod != NULL))
|
1
|
133 return;
|
|
134
|
45
|
135 #if GTK_MAJOR_VERSION == 1
|
1
|
136 dialog = gtk_dialog_new ();
|
|
137 gtk_window_set_title (GTK_WINDOW (dialog), _("Chmod"));
|
|
138 gtk_container_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->action_area),
|
|
139 5);
|
|
140 gtk_box_set_homogeneous (GTK_BOX (GTK_DIALOG (dialog)->action_area), TRUE);
|
19
|
141 #else
|
|
142 dialog = gtk_dialog_new_with_buttons (_("Chmod"), NULL, 0,
|
|
143 GTK_STOCK_OK,
|
|
144 GTK_RESPONSE_OK,
|
|
145 GTK_STOCK_CANCEL,
|
|
146 GTK_RESPONSE_CANCEL,
|
|
147 NULL);
|
|
148 #endif
|
|
149 gtk_window_set_wmclass (GTK_WINDOW(dialog), "Chmod", "gFTP");
|
1
|
150 gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE);
|
19
|
151 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 5);
|
|
152 gtk_container_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), 10);
|
|
153 gtk_widget_realize (dialog);
|
|
154
|
|
155 if (gftp_icon != NULL)
|
|
156 {
|
|
157 gdk_window_set_icon (dialog->window, NULL, gftp_icon->pixmap,
|
|
158 gftp_icon->bitmap);
|
168
|
159 gdk_window_set_icon_name (dialog->window, gftp_version);
|
19
|
160 }
|
1
|
161
|
|
162 tempwid = gtk_label_new (_("You can now adjust the attributes of your file(s)\nNote: Not all ftp servers support the chmod feature"));
|
|
163 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), tempwid, FALSE,
|
|
164 FALSE, 0);
|
|
165 gtk_widget_show (tempwid);
|
|
166
|
|
167 hbox = gtk_hbox_new (TRUE, 5);
|
|
168 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), hbox, FALSE, FALSE,
|
|
169 0);
|
|
170 gtk_widget_show (hbox);
|
|
171
|
|
172 tempwid = gtk_frame_new (_("Special"));
|
|
173 gtk_box_pack_start (GTK_BOX (hbox), tempwid, FALSE, FALSE, 0);
|
|
174 gtk_widget_show (tempwid);
|
|
175
|
|
176 vbox = gtk_vbox_new (TRUE, 5);
|
|
177 gtk_container_add (GTK_CONTAINER (tempwid), vbox);
|
|
178 gtk_widget_show (vbox);
|
|
179
|
|
180 suid = gtk_check_button_new_with_label (_("SUID"));
|
|
181 gtk_box_pack_start (GTK_BOX (vbox), suid, FALSE, FALSE, 0);
|
|
182 gtk_widget_show (suid);
|
|
183
|
|
184 sgid = gtk_check_button_new_with_label (_("SGID"));
|
|
185 gtk_box_pack_start (GTK_BOX (vbox), sgid, FALSE, FALSE, 0);
|
|
186 gtk_widget_show (sgid);
|
|
187
|
|
188 sticky = gtk_check_button_new_with_label (_("Sticky"));
|
|
189 gtk_box_pack_start (GTK_BOX (vbox), sticky, FALSE, FALSE, 0);
|
|
190 gtk_widget_show (sticky);
|
|
191
|
|
192 tempwid = gtk_frame_new (_("User"));
|
|
193 gtk_box_pack_start (GTK_BOX (hbox), tempwid, FALSE, FALSE, 0);
|
|
194 gtk_widget_show (tempwid);
|
|
195
|
|
196 vbox = gtk_vbox_new (TRUE, 5);
|
|
197 gtk_container_add (GTK_CONTAINER (tempwid), vbox);
|
|
198 gtk_widget_show (vbox);
|
|
199
|
|
200 ur = gtk_check_button_new_with_label (_("Read"));
|
|
201 gtk_box_pack_start (GTK_BOX (vbox), ur, FALSE, FALSE, 0);
|
|
202 gtk_widget_show (ur);
|
|
203
|
|
204 uw = gtk_check_button_new_with_label (_("Write"));
|
|
205 gtk_box_pack_start (GTK_BOX (vbox), uw, FALSE, FALSE, 0);
|
|
206 gtk_widget_show (uw);
|
|
207
|
|
208 ux = gtk_check_button_new_with_label (_("Execute"));
|
|
209 gtk_box_pack_start (GTK_BOX (vbox), ux, FALSE, FALSE, 0);
|
|
210 gtk_widget_show (ux);
|
|
211
|
|
212 tempwid = gtk_frame_new (_("Group"));
|
|
213 gtk_box_pack_start (GTK_BOX (hbox), tempwid, FALSE, FALSE, 0);
|
|
214 gtk_widget_show (tempwid);
|
|
215
|
|
216 vbox = gtk_vbox_new (TRUE, 5);
|
|
217 gtk_container_add (GTK_CONTAINER (tempwid), vbox);
|
|
218 gtk_widget_show (vbox);
|
|
219
|
|
220 gr = gtk_check_button_new_with_label (_("Read"));
|
|
221 gtk_box_pack_start (GTK_BOX (vbox), gr, FALSE, FALSE, 0);
|
|
222 gtk_widget_show (gr);
|
|
223
|
|
224 gw = gtk_check_button_new_with_label (_("Write"));
|
|
225 gtk_box_pack_start (GTK_BOX (vbox), gw, FALSE, FALSE, 0);
|
|
226 gtk_widget_show (gw);
|
|
227
|
|
228 gx = gtk_check_button_new_with_label (_("Execute"));
|
|
229 gtk_box_pack_start (GTK_BOX (vbox), gx, FALSE, FALSE, 0);
|
|
230 gtk_widget_show (gx);
|
|
231
|
|
232 tempwid = gtk_frame_new (_("Other"));
|
|
233 gtk_box_pack_start (GTK_BOX (hbox), tempwid, FALSE, FALSE, 0);
|
|
234 gtk_widget_show (tempwid);
|
|
235
|
|
236 vbox = gtk_vbox_new (TRUE, 5);
|
|
237 gtk_container_add (GTK_CONTAINER (tempwid), vbox);
|
|
238 gtk_widget_show (vbox);
|
|
239
|
|
240 or = gtk_check_button_new_with_label (_("Read"));
|
|
241 gtk_box_pack_start (GTK_BOX (vbox), or, FALSE, FALSE, 0);
|
|
242 gtk_widget_show (or);
|
|
243
|
|
244 ow = gtk_check_button_new_with_label (_("Write"));
|
|
245 gtk_box_pack_start (GTK_BOX (vbox), ow, FALSE, FALSE, 0);
|
|
246 gtk_widget_show (ow);
|
|
247
|
|
248 ox = gtk_check_button_new_with_label (_("Execute"));
|
|
249 gtk_box_pack_start (GTK_BOX (vbox), ox, FALSE, FALSE, 0);
|
|
250 gtk_widget_show (ox);
|
|
251
|
45
|
252 #if GTK_MAJOR_VERSION == 1
|
19
|
253 tempwid = gtk_button_new_with_label (_("OK"));
|
1
|
254 GTK_WIDGET_SET_FLAGS (tempwid, GTK_CAN_DEFAULT);
|
|
255 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), tempwid,
|
|
256 TRUE, TRUE, 0);
|
|
257 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked",
|
|
258 GTK_SIGNAL_FUNC (dochmod), (gpointer) wdata);
|
|
259 gtk_signal_connect_object (GTK_OBJECT (tempwid), "clicked",
|
|
260 GTK_SIGNAL_FUNC (gtk_widget_destroy),
|
|
261 GTK_OBJECT (dialog));
|
|
262 gtk_widget_grab_default (tempwid);
|
|
263 gtk_widget_show (tempwid);
|
|
264
|
|
265 tempwid = gtk_button_new_with_label (_(" Cancel "));
|
|
266 GTK_WIDGET_SET_FLAGS (tempwid, GTK_CAN_DEFAULT);
|
|
267 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), tempwid,
|
|
268 TRUE, TRUE, 0);
|
|
269 gtk_signal_connect_object (GTK_OBJECT (tempwid), "clicked",
|
|
270 GTK_SIGNAL_FUNC (gtk_widget_destroy),
|
|
271 GTK_OBJECT (dialog));
|
|
272 gtk_widget_show (tempwid);
|
19
|
273 #else
|
|
274 g_signal_connect (GTK_OBJECT (dialog), "response",
|
|
275 G_CALLBACK (chmod_action), wdata);
|
|
276 #endif
|
1
|
277
|
|
278 if (IS_ONE_SELECTED (wdata))
|
|
279 {
|
|
280 filelist = wdata->files;
|
525
|
281 templist = gftp_gtk_get_list_selection (wdata);
|
1
|
282 num = 0;
|
|
283 templist = get_next_selection (templist, &filelist, &num);
|
|
284 tempfle = filelist->data;
|
499
|
285
|
1
|
286 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (suid),
|
499
|
287 tempfle->st_mode & S_ISUID);
|
1
|
288 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ur),
|
499
|
289 tempfle->st_mode & S_IRUSR);
|
1
|
290 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (uw),
|
499
|
291 tempfle->st_mode & S_IWUSR);
|
1
|
292 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ux),
|
499
|
293 tempfle->st_mode & S_IXUSR);
|
|
294
|
|
295 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (sgid),
|
|
296 tempfle->st_mode & S_ISGID);
|
1
|
297 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gr),
|
499
|
298 tempfle->st_mode & S_IRGRP);
|
1
|
299 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gw),
|
499
|
300 tempfle->st_mode & S_IWGRP);
|
1
|
301 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gx),
|
499
|
302 tempfle->st_mode & S_IXGRP);
|
|
303
|
|
304 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (sticky),
|
|
305 tempfle->st_mode & S_ISVTX);
|
1
|
306 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (or),
|
499
|
307 tempfle->st_mode & S_IROTH);
|
1
|
308 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ow),
|
499
|
309 tempfle->st_mode & S_IWOTH);
|
1
|
310 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ox),
|
499
|
311 tempfle->st_mode & S_IXOTH);
|
1
|
312 }
|
|
313 gtk_widget_show (dialog);
|
|
314 }
|
|
315
|