1 /* gnome-file-property-dialog.c
2 * Copyright (C) 1999 Free Software Foundation
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
25 #include "gnome-file-property-dialog.h"
29 #include <sys/types.h>
31 #include "fileopctx.h"
33 #include "../vfs/vfs.h"
38 static void gnome_file_property_dialog_init (GnomeFilePropertyDialog
*file_property_dialog
);
39 static void gnome_file_property_dialog_class_init (GnomeFilePropertyDialogClass
*klass
);
40 static void gnome_file_property_dialog_finalize (GtkObject
*object
);
42 static GnomeDialogClass
*parent_class
= NULL
;
46 gnome_file_property_dialog_get_type (void)
48 static GtkType file_property_dialog_type
= 0;
50 if (!file_property_dialog_type
)
52 static const GtkTypeInfo file_property_dialog_info
=
54 "GnomeFilePropertyDialog",
55 sizeof (GnomeFilePropertyDialog
),
56 sizeof (GnomeFilePropertyDialogClass
),
57 (GtkClassInitFunc
) gnome_file_property_dialog_class_init
,
58 (GtkObjectInitFunc
) gnome_file_property_dialog_init
,
59 /* reserved_1 */ NULL
,
60 /* reserved_2 */ NULL
,
63 file_property_dialog_type
= gtk_type_unique (gnome_dialog_get_type (), &file_property_dialog_info
);
66 return file_property_dialog_type
;
70 gnome_file_property_dialog_class_init (GnomeFilePropertyDialogClass
*klass
)
72 GtkObjectClass
*object_class
;
74 object_class
= (GtkObjectClass
*) klass
;
76 parent_class
= gtk_type_class (gnome_dialog_get_type ());
77 object_class
->finalize
= gnome_file_property_dialog_finalize
;
83 gnome_file_property_dialog_init (GnomeFilePropertyDialog
*file_property_dialog
)
85 gnome_dialog_close_hides (GNOME_DIALOG (file_property_dialog
), TRUE
);
87 file_property_dialog
->file_name
= NULL
;
88 file_property_dialog
->file_entry
= NULL
;
89 file_property_dialog
->group_name
= NULL
;
90 file_property_dialog
->modifyable
= TRUE
;
91 file_property_dialog
->user_name
= NULL
;
92 file_property_dialog
->prop1_label
= NULL
;
93 file_property_dialog
->prop2_label
= NULL
;
94 file_property_dialog
->prop1_entry
= NULL
;
95 file_property_dialog
->prop2_entry
= NULL
;
96 file_property_dialog
->prop1_cbox
= NULL
;
97 file_property_dialog
->prop2_cbox
= NULL
;
98 file_property_dialog
->fm_open
= NULL
;
99 file_property_dialog
->fm_view
= NULL
;
100 file_property_dialog
->edit
= NULL
;
101 file_property_dialog
->drop_target
= NULL
;
102 file_property_dialog
->im
= NULL
;
106 gnome_file_property_dialog_finalize (GtkObject
*object
)
108 GnomeFilePropertyDialog
*gfpd
;
110 g_return_if_fail (object
!= NULL
);
111 g_return_if_fail (GNOME_IS_FILE_PROPERTY_DIALOG (object
));
113 gfpd
= GNOME_FILE_PROPERTY_DIALOG (object
);
116 g_free (gfpd
->file_name
);
118 g_free (gfpd
->fm_open
);
120 g_free (gfpd
->fm_view
);
123 if (gfpd
->drop_target
)
124 g_free (gfpd
->drop_target
);
125 if (gfpd
->icon_filename
)
126 g_free (gfpd
->icon_filename
);
127 if (gfpd
->desktop_url
)
128 g_free (gfpd
->desktop_url
);
130 g_free (gfpd
->caption
);
133 g_free (gfpd
->mode_name
);
135 (* GTK_OBJECT_CLASS (parent_class
)->finalize
) (object
);
138 /* Create the pane */
141 create_general_properties (GnomeFilePropertyDialog
*fp_dlg
)
149 gchar buf
[MC_MAXPATHLEN
];
150 gchar buf2
[MC_MAXPATHLEN
];
157 vbox
= gtk_vbox_new (FALSE
, GNOME_PAD_SMALL
);
158 gtk_container_set_border_width (GTK_CONTAINER (vbox
), GNOME_PAD
);
160 /* first, we set the icon */
161 direc
= g_strdup (fp_dlg
->file_name
);
162 strrchr (direc
, '/')[0] = '\0';
163 fe
= file_entry_from_file (fp_dlg
->file_name
);
164 fp_dlg
->im
= gicon_get_icon_for_file (direc
, fe
, FALSE
);
165 file_entry_free (fe
);
167 icon
= gnome_pixmap_new_from_imlib (fp_dlg
->im
);
168 gtk_box_pack_start (GTK_BOX (vbox
), icon
, FALSE
, FALSE
, 0);
170 /* we set the file part */
171 gen_string
= g_strconcat (_("Full Name: "), fp_dlg
->file_name
, NULL
);
172 label
= gtk_label_new (gen_string
);
173 gtk_misc_set_alignment (GTK_MISC (label
), 0.0, 0.5);
175 gtk_box_pack_start (GTK_BOX (vbox
), label
, FALSE
, FALSE
, 0);
176 /* if it's a symlink */
177 align
= gtk_alignment_new (0.0, 0.5, 1.0, 1.0);
178 hbox
= gtk_hbox_new (FALSE
, 2);
179 label
= gtk_label_new (_("File Name"));
180 gtk_box_pack_start (GTK_BOX (hbox
), label
, FALSE
, FALSE
, 0);
181 fp_dlg
->file_entry
= gtk_entry_new ();
182 gen_string
= strrchr (fp_dlg
->file_name
, '/');
184 gtk_entry_set_text (GTK_ENTRY (fp_dlg
->file_entry
), gen_string
+ 1);
186 /* I don't think this should happen anymore, but it can't hurt in
187 * case this ever gets used outside gmc */
188 gtk_entry_set_text (GTK_ENTRY (fp_dlg
->file_entry
), fp_dlg
->file_name
);
189 /* We want to prevent editing of the file if
190 * the thing is a BLK, CHAR, or we don't own it */
191 /* FIXME: We can actually edit it if we're in the same grp of the file. */
192 if (fp_dlg
->modifyable
== FALSE
)
193 gtk_widget_set_sensitive (fp_dlg
->file_entry
, FALSE
);
194 gtk_box_pack_start (GTK_BOX (hbox
), fp_dlg
->file_entry
, FALSE
, FALSE
, 0);
195 gtk_container_add (GTK_CONTAINER (align
), hbox
);
196 gtk_box_pack_start (GTK_BOX (vbox
), align
, FALSE
, FALSE
, 0);
197 gtk_box_pack_start (GTK_BOX (vbox
), gtk_hseparator_new (), FALSE
, FALSE
, 8);
199 /* File statistics */
200 /* File type first */
201 if (S_ISREG (fp_dlg
->st
.st_mode
)) {
202 gen_string
= g_strconcat (_("File Type: "), use_magic
?
203 gnome_mime_type_or_default_of_file (fp_dlg
->file_name
, "text/plain") :
204 gnome_mime_type (fp_dlg
->file_name
),
206 label
= gtk_label_new (gen_string
);
208 } else if (S_ISLNK (fp_dlg
->st
.st_mode
)) {
209 label
= gtk_label_new (_("File Type: Symbolic Link"));
210 gtk_misc_set_alignment (GTK_MISC (label
), 0.0, 0.5);
211 gtk_box_pack_start (GTK_BOX (vbox
), label
, FALSE
, FALSE
, 0);
212 n
= mc_readlink (fp_dlg
->file_name
, buf
, MC_MAXPATHLEN
);
214 label
= gtk_label_new (_("Target Name: INVALID LINK"));
217 gen_string
= g_strconcat (_("Target Name: "), buf
, NULL
);
218 label
= gtk_label_new (gen_string
);
221 }else if (S_ISDIR (fp_dlg
->st
.st_mode
))
222 label
= gtk_label_new (_("File Type: Directory"));
223 else if (S_ISCHR (fp_dlg
->st
.st_mode
))
224 label
= gtk_label_new (_("File Type: Character Device"));
225 else if (S_ISBLK (fp_dlg
->st
.st_mode
))
226 label
= gtk_label_new (_("File Type: Block Device"));
227 else if (S_ISSOCK (fp_dlg
->st
.st_mode
))
228 label
= gtk_label_new (_("File Type: Socket"));
229 else if (S_ISFIFO (fp_dlg
->st
.st_mode
))
230 label
= gtk_label_new (_("File Type: FIFO"));
231 gtk_misc_set_alignment (GTK_MISC (label
), 0.0, 0.5);
232 gtk_box_pack_start (GTK_BOX (vbox
), label
, FALSE
, FALSE
, 0);
235 if (S_ISDIR (fp_dlg
->st
.st_mode
)
236 || S_ISREG (fp_dlg
->st
.st_mode
)
237 || S_ISLNK (fp_dlg
->st
.st_mode
)) {
238 if ((gint
)fp_dlg
->st
.st_size
< 1024) {
239 g_snprintf (buf
, MC_MAXPATHLEN
, "%d", (gint
) fp_dlg
->st
.st_size
);
240 gen_string
= g_strconcat (_("File Size: "), buf
, _(" bytes"), NULL
);
241 } else if ((gint
)fp_dlg
->st
.st_size
< 1024 * 1024) {
242 g_snprintf (buf
, MC_MAXPATHLEN
, "%.1f", (gfloat
) fp_dlg
->st
.st_size
/ 1024.0);
243 g_snprintf (buf2
, MC_MAXPATHLEN
, "%d", (gint
) fp_dlg
->st
.st_size
);
244 gen_string
= g_strconcat (_("File Size: "), buf
, _(" KBytes ("),
245 buf2
, _(" bytes)"), NULL
);
247 g_snprintf (buf
, MC_MAXPATHLEN
, "%.1f",
248 (gfloat
) fp_dlg
->st
.st_size
/ (1024.0 * 1024.0));
249 g_snprintf (buf2
, MC_MAXPATHLEN
, "%d", (gint
) fp_dlg
->st
.st_size
);
250 gen_string
= g_strconcat (_("File Size: "), buf
, _(" MBytes ("),
251 buf2
, _(" bytes)"), NULL
);
253 label
= gtk_label_new (gen_string
);
255 gtk_misc_set_alignment (GTK_MISC (label
), 0.0, 0.5);
256 gtk_box_pack_start (GTK_BOX (vbox
), label
, FALSE
, FALSE
, 0);
258 label
= gtk_label_new (_("File Size: N/A"));
259 gtk_misc_set_alignment (GTK_MISC (label
), 0.0, 0.5);
260 gtk_box_pack_start (GTK_BOX (vbox
), label
, FALSE
, FALSE
, 0);
263 gtk_box_pack_start (GTK_BOX (vbox
), gtk_hseparator_new (), FALSE
, FALSE
, 8);
266 table
= gtk_table_new (3, 2, FALSE
);
267 gtk_table_set_row_spacings (GTK_TABLE (table
), 2);
268 gtk_box_pack_start (GTK_BOX (vbox
), table
, FALSE
, FALSE
, 0);
269 label
= gtk_label_new (_("File Created on: "));
270 gtk_misc_set_alignment (GTK_MISC (label
), 0.0, 0.5);
271 gtk_table_attach_defaults (GTK_TABLE (table
), label
, 0, 1, 0, 1);
272 time
= localtime (&(fp_dlg
->st
.st_ctime
));
273 strftime (buf
, MC_MAXPATHLEN
, _("%a, %b %d %Y, %I:%M:%S %p"), time
);
274 label
= gtk_label_new (buf
);
275 gtk_misc_set_alignment (GTK_MISC (label
), 0.0, 0.5);
276 gtk_table_attach_defaults (GTK_TABLE (table
), label
, 1, 2, 0, 1);
278 label
= gtk_label_new (_("Last Modified on: "));
279 gtk_misc_set_alignment (GTK_MISC (label
), 0.0, 0.5);
280 gtk_table_attach_defaults (GTK_TABLE (table
), label
, 0, 1, 1, 2);
281 time
= localtime (&(fp_dlg
->st
.st_mtime
));
282 strftime (buf
, MC_MAXPATHLEN
, _("%a, %b %d %Y, %I:%M:%S %p"), time
);
283 label
= gtk_label_new (buf
);
284 gtk_misc_set_alignment (GTK_MISC (label
), 0.0, 0.5);
285 gtk_table_attach_defaults (GTK_TABLE (table
), label
, 1, 2, 1, 2);
287 label
= gtk_label_new (_("Last Accessed on: "));
288 gtk_misc_set_alignment (GTK_MISC (label
), 0.0, 0.5);
289 gtk_table_attach_defaults (GTK_TABLE (table
), label
, 0, 1, 2, 3);
290 time
= localtime (&(fp_dlg
->st
.st_atime
));
291 strftime (buf
, MC_MAXPATHLEN
, _("%a, %b %d %Y, %I:%M:%S %p"), time
);
292 label
= gtk_label_new (buf
);
293 gtk_misc_set_alignment (GTK_MISC (label
), 0.0, 0.5);
294 gtk_table_attach_defaults (GTK_TABLE (table
), label
, 1, 2, 2, 3);
299 create_url_properties (GnomeFilePropertyDialog
*fp_dlg
)
301 GtkWidget
*table
, *label
;
303 table
= gtk_table_new (0, 0, 0);
305 label
= gtk_label_new (_("URL:"));
306 gtk_table_attach (GTK_TABLE (table
), label
,
307 1, 2, 1, 2, 0, 0, GNOME_PAD
, GNOME_PAD
);
308 fp_dlg
->desktop_entry
= gtk_entry_new ();
309 gtk_table_attach (GTK_TABLE (table
), fp_dlg
->desktop_entry
,
310 2, 3, 1, 2, GTK_FILL
| GTK_EXPAND
, 0, GNOME_PAD
, GNOME_PAD
);
312 label
= gtk_label_new (_("Caption:"));
313 gtk_table_attach (GTK_TABLE (table
), label
,
314 1, 2, 2, 3, 0, 0, GNOME_PAD
, GNOME_PAD
);
315 fp_dlg
->caption_entry
= gtk_entry_new ();
316 gtk_table_attach (GTK_TABLE (table
), fp_dlg
->caption_entry
,
317 2, 3, 2, 3, GTK_FILL
| GTK_EXPAND
, 0, GNOME_PAD
, GNOME_PAD
);
319 gtk_widget_show_all (table
);
325 metadata_toggled (GtkWidget
*cbox
, GnomeFilePropertyDialog
*fp_dlg
)
327 if (fp_dlg
->changing
)
329 if (cbox
== fp_dlg
->open_cbox
) {
330 if (GTK_TOGGLE_BUTTON (cbox
)->active
) {
331 gtk_widget_set_sensitive (fp_dlg
->open_entry
, FALSE
);
332 if (fp_dlg
->mime_fm_open
)
333 gtk_entry_set_text (GTK_ENTRY (fp_dlg
->open_entry
), fp_dlg
->mime_fm_open
);
335 gtk_widget_set_sensitive (fp_dlg
->open_entry
, TRUE
);
336 if (fp_dlg
->fm_open
) {
337 gtk_entry_set_text (GTK_ENTRY (fp_dlg
->open_entry
), fp_dlg
->fm_open
);
340 } else if (cbox
== fp_dlg
->prop1_cbox
) {
341 if (GTK_TOGGLE_BUTTON (cbox
)->active
) {
342 gtk_widget_set_sensitive (fp_dlg
->prop1_entry
, FALSE
);
343 if (fp_dlg
->executable
&& fp_dlg
->mime_drop_target
) {
344 gtk_entry_set_text (GTK_ENTRY (fp_dlg
->prop1_entry
), fp_dlg
->mime_drop_target
);
345 } else if (!fp_dlg
->executable
&& fp_dlg
->mime_fm_view
) {
346 gtk_entry_set_text (GTK_ENTRY (fp_dlg
->prop1_entry
), fp_dlg
->mime_fm_view
);
348 gtk_entry_set_text (GTK_ENTRY (fp_dlg
->prop1_entry
), "");
351 gtk_widget_set_sensitive (fp_dlg
->prop1_entry
, TRUE
);
352 if (fp_dlg
->executable
&& fp_dlg
->drop_target
) {
353 gtk_entry_set_text (GTK_ENTRY (fp_dlg
->prop1_entry
), fp_dlg
->drop_target
);
354 } else if (!fp_dlg
->executable
&& fp_dlg
->fm_view
) {
355 gtk_entry_set_text (GTK_ENTRY (fp_dlg
->prop1_entry
), fp_dlg
->fm_view
);
359 if (GTK_TOGGLE_BUTTON (cbox
)->active
) {
360 gtk_widget_set_sensitive (fp_dlg
->prop2_entry
, FALSE
);
361 if (fp_dlg
->mime_edit
) {
362 gtk_entry_set_text (GTK_ENTRY (fp_dlg
->prop2_entry
), fp_dlg
->mime_edit
);
364 gtk_entry_set_text (GTK_ENTRY (fp_dlg
->prop2_entry
), "");
367 gtk_widget_set_sensitive (fp_dlg
->prop2_entry
, TRUE
);
369 gtk_entry_set_text (GTK_ENTRY (fp_dlg
->prop2_entry
), fp_dlg
->edit
);
376 switch_metadata_box (GnomeFilePropertyDialog
*fp_dlg
)
378 if (NULL
== fp_dlg
->prop1_label
)
380 fp_dlg
->changing
= TRUE
;
382 if (fp_dlg
->desktop_url
){
383 gtk_entry_set_text (GTK_ENTRY (fp_dlg
->desktop_entry
), fp_dlg
->desktop_url
);
385 gtk_entry_set_text (GTK_ENTRY (fp_dlg
->caption_entry
), fp_dlg
->caption
);
388 if (fp_dlg
->executable
) {
389 gtk_label_set_text (GTK_LABEL (fp_dlg
->prop1_label
), _("Drop Action"));
390 gtk_label_set_text (GTK_LABEL (GTK_BIN (fp_dlg
->prop1_cbox
)->child
), _("Use default Drop Action options"));
391 if (fp_dlg
->drop_target
) {
392 gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON (fp_dlg
->prop1_cbox
), FALSE
);
393 gtk_entry_set_text (GTK_ENTRY (fp_dlg
->prop1_entry
), fp_dlg
->drop_target
);
394 gtk_widget_set_sensitive (fp_dlg
->prop1_entry
, TRUE
);
395 } else if (fp_dlg
->mime_drop_target
) {
396 gtk_entry_set_text (GTK_ENTRY (fp_dlg
->prop1_entry
), fp_dlg
->mime_drop_target
);
397 gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON (fp_dlg
->prop1_cbox
), TRUE
);
398 gtk_widget_set_sensitive (fp_dlg
->prop1_entry
, FALSE
);
400 gtk_entry_set_text (GTK_ENTRY (fp_dlg
->prop1_entry
), "");
401 gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON (fp_dlg
->prop1_cbox
), TRUE
);
402 gtk_widget_set_sensitive (fp_dlg
->prop1_entry
, FALSE
);
405 gtk_label_set_text (GTK_LABEL (fp_dlg
->prop1_label
), _("View"));
406 gtk_label_set_text (GTK_LABEL (GTK_BIN (fp_dlg
->prop1_cbox
)->child
), _("Use default View options"));
407 if (fp_dlg
->fm_view
) {
408 gtk_entry_set_text (GTK_ENTRY (fp_dlg
->prop1_entry
), fp_dlg
->fm_view
);
409 gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON (fp_dlg
->prop1_cbox
), FALSE
);
410 gtk_widget_set_sensitive (fp_dlg
->prop1_entry
, TRUE
);
411 } else if (fp_dlg
->mime_fm_view
) {
412 gtk_entry_set_text (GTK_ENTRY (fp_dlg
->prop1_entry
), fp_dlg
->mime_fm_view
);
413 gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON (fp_dlg
->prop1_cbox
), TRUE
);
414 gtk_widget_set_sensitive (fp_dlg
->prop1_entry
, FALSE
);
416 gtk_entry_set_text (GTK_ENTRY (fp_dlg
->prop1_entry
), "");
417 gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON (fp_dlg
->prop1_cbox
), TRUE
);
418 gtk_widget_set_sensitive (fp_dlg
->prop1_entry
, FALSE
);
421 if (fp_dlg
->executable
) {
422 gtk_widget_hide (fp_dlg
->prop2_label
);
423 gtk_widget_hide (fp_dlg
->prop2_entry
);
424 gtk_widget_hide (fp_dlg
->prop2_cbox
);
425 gtk_widget_hide (fp_dlg
->prop2_hline
);
427 gtk_widget_show (fp_dlg
->prop2_label
);
428 gtk_widget_show (fp_dlg
->prop2_entry
);
429 gtk_widget_show (fp_dlg
->prop2_cbox
);
430 gtk_widget_show (fp_dlg
->prop2_hline
);
432 fp_dlg
->changing
= FALSE
;
436 generate_icon_sel (GnomeFilePropertyDialog
*fp_dlg
)
441 retval
= gnome_icon_entry_new ("gmc_file_icon", _("Select an Icon"));
442 icon
= g_strdup (gicon_get_filename_for_icon (fp_dlg
->im
));
446 gnome_icon_entry_set_icon (GNOME_ICON_ENTRY (retval
), icon
);
447 fp_dlg
->icon_filename
= icon
;
452 generate_actions_box (GnomeFilePropertyDialog
*fp_dlg
)
457 /* Here's the Logic: */
458 /* All tops of files (other then folders) should let us edit "open" */
459 /* If we are a file, and an executable, we want to edit our "drop-action" */
460 /* Metadata, as it is meaningful to us. */
461 /* If we are non-executable, we want to edit our "edit" and "view" fields. */
462 /* Sym links want to have the same options as above, but use their Target's */
463 /* Executable/set bit in order to determine which one. */
464 /* Note, symlinks can set their own metadata, independent from their */
467 table
= gtk_table_new (8, 2, FALSE
);
468 gtk_container_set_border_width (GTK_CONTAINER (table
), GNOME_PAD_SMALL
);
470 /* we do open first */
471 fp_dlg
->open_label
= gtk_label_new (_("Open"));
472 gtk_misc_set_alignment (GTK_MISC (fp_dlg
->open_label
), 0.0, 0.5);
473 gtk_misc_set_padding (GTK_MISC (fp_dlg
->open_label
), 2, 0);
474 gtk_table_attach_defaults (GTK_TABLE (table
),
477 fp_dlg
->open_entry
= gtk_entry_new ();
478 gtk_table_attach_defaults (GTK_TABLE (table
),
481 fp_dlg
->open_cbox
= gtk_check_button_new_with_label (_("Use default Open action"));
482 gtk_signal_connect (GTK_OBJECT (fp_dlg
->open_cbox
), "toggled", metadata_toggled
, fp_dlg
);
483 gtk_table_attach_defaults (GTK_TABLE (table
), fp_dlg
->open_cbox
, 0, 2, 1, 2);
486 vbox
= gtk_vbox_new (FALSE
, 0);
487 gtk_box_pack_start (GTK_BOX (vbox
), gtk_hseparator_new (), FALSE
, FALSE
, GNOME_PAD_SMALL
);
488 gtk_table_attach_defaults (GTK_TABLE (table
), vbox
, 0, 2, 2, 3);
490 if (fp_dlg
->executable
)
491 fp_dlg
->prop1_label
= gtk_label_new (_("Drop Action"));
493 fp_dlg
->prop1_label
= gtk_label_new (_("View"));
494 gtk_misc_set_alignment (GTK_MISC (fp_dlg
->prop1_label
), 0.0, 0.5);
495 gtk_misc_set_padding (GTK_MISC (fp_dlg
->prop1_label
), 2, 0);
496 gtk_table_attach_defaults (GTK_TABLE (table
),
499 fp_dlg
->prop1_entry
= gtk_entry_new ();
500 gtk_table_attach_defaults (GTK_TABLE (table
),
503 if (fp_dlg
->executable
)
504 fp_dlg
->prop1_cbox
= gtk_check_button_new_with_label (_("Use default Drop action"));
506 fp_dlg
->prop1_cbox
= gtk_check_button_new_with_label (_("Use default View action"));
507 gtk_signal_connect (GTK_OBJECT (fp_dlg
->prop1_cbox
), "toggled", metadata_toggled
, fp_dlg
);
508 gtk_table_attach_defaults (GTK_TABLE (table
), fp_dlg
->prop1_cbox
, 0, 2, 4, 5);
510 vbox
= gtk_vbox_new (FALSE
, 0);
511 fp_dlg
->prop2_hline
= gtk_hseparator_new ();
512 gtk_box_pack_start (GTK_BOX (vbox
), fp_dlg
->prop2_hline
, FALSE
, FALSE
, GNOME_PAD_SMALL
);
513 gtk_table_attach_defaults (GTK_TABLE (table
), vbox
, 0, 2, 5, 6);
515 fp_dlg
->prop2_label
= gtk_label_new (_("Edit"));
516 gtk_misc_set_alignment (GTK_MISC (fp_dlg
->prop2_label
), 0.0, 0.5);
517 gtk_misc_set_padding (GTK_MISC (fp_dlg
->prop2_label
), 2, 0);
518 gtk_table_attach_defaults (GTK_TABLE (table
),
521 fp_dlg
->prop2_entry
= gtk_entry_new ();
522 gtk_table_attach_defaults (GTK_TABLE (table
),
525 fp_dlg
->prop2_cbox
= gtk_check_button_new_with_label (_("Use default Edit action"));
526 gtk_signal_connect (GTK_OBJECT (fp_dlg
->prop2_cbox
), "toggled", metadata_toggled
, fp_dlg
);
527 gtk_table_attach_defaults (GTK_TABLE (table
), fp_dlg
->prop2_cbox
, 0, 2, 7, 8);
529 /* we set the open field */
530 fp_dlg
->changing
= TRUE
;
531 if (fp_dlg
->fm_open
) {
532 gtk_entry_set_text (GTK_ENTRY (fp_dlg
->open_entry
), fp_dlg
->fm_open
);
533 gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON (fp_dlg
->open_cbox
), FALSE
);
534 gtk_widget_set_sensitive (fp_dlg
->open_entry
, TRUE
);
535 } else if (fp_dlg
->mime_fm_open
) {
536 gtk_entry_set_text (GTK_ENTRY (fp_dlg
->open_entry
), fp_dlg
->mime_fm_open
);
537 gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON (fp_dlg
->open_cbox
), TRUE
);
538 gtk_widget_set_sensitive (fp_dlg
->open_entry
, FALSE
);
540 gtk_entry_set_text (GTK_ENTRY (fp_dlg
->open_entry
), "");
541 gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON (fp_dlg
->open_cbox
), TRUE
);
542 gtk_widget_set_sensitive (fp_dlg
->open_entry
, FALSE
);
545 gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON (fp_dlg
->prop2_cbox
), FALSE
);
546 gtk_entry_set_text (GTK_ENTRY (fp_dlg
->prop2_entry
), fp_dlg
->edit
);
547 gtk_widget_set_sensitive (fp_dlg
->prop2_entry
, TRUE
);
548 } else if (fp_dlg
->mime_edit
) {
549 gtk_entry_set_text (GTK_ENTRY (fp_dlg
->prop2_entry
), fp_dlg
->mime_edit
);
550 gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON (fp_dlg
->prop2_cbox
), TRUE
);
551 gtk_widget_set_sensitive (fp_dlg
->prop2_entry
, FALSE
);
553 gtk_entry_set_text (GTK_ENTRY (fp_dlg
->prop2_entry
), "");
554 gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON (fp_dlg
->prop2_cbox
), TRUE
);
555 gtk_widget_set_sensitive (fp_dlg
->prop2_entry
, FALSE
);
557 fp_dlg
->changing
= FALSE
;
563 create_settings_pane (GnomeFilePropertyDialog
*fp_dlg
)
565 GtkWidget
*vbox
= NULL
;
571 struct stat linkstat
;
574 vbox
= gtk_vbox_new (FALSE
, GNOME_PAD_SMALL
);
575 gtk_container_set_border_width (GTK_CONTAINER (vbox
), GNOME_PAD
);
577 if (fp_dlg
->can_set_icon
) {
579 frame
= gtk_frame_new (_("Icon"));
580 vbox2
= gtk_vbox_new (FALSE
, 0);
581 hbox
= gtk_hbox_new (FALSE
, 0);
582 align
= gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
583 gtk_box_pack_start (GTK_BOX (vbox
), frame
, TRUE
, TRUE
, 0);
584 fp_dlg
->button
= generate_icon_sel (fp_dlg
);
585 gtk_container_add (GTK_CONTAINER (frame
), vbox2
);
586 gtk_container_set_border_width (GTK_CONTAINER (vbox2
), GNOME_PAD_SMALL
);
587 gtk_box_pack_start (GTK_BOX (vbox2
), hbox
, TRUE
, FALSE
, 0);
588 gtk_box_pack_start (GTK_BOX (hbox
), align
, TRUE
, FALSE
, 0);
589 gtk_container_add (GTK_CONTAINER (align
), fp_dlg
->button
);
591 /* Are we a directory or device? If so, we do nothing else. */
592 if (S_ISLNK (fp_dlg
->st
.st_mode
))
593 mc_stat (fp_dlg
->file_name
, &linkstat
);
596 if (!S_ISREG (fp_dlg
->st
.st_mode
)){
597 if (S_ISLNK (fp_dlg
->st
.st_mode
)){
598 if (!S_ISREG (linkstat
.st_mode
))
605 if (!fp_dlg
->can_set_icon
) {
606 gtk_widget_unref (vbox
);
612 /* We must be a file or a link to a file. */
613 frame
= gtk_frame_new (_("File Actions"));
614 gtk_box_pack_start (GTK_BOX (vbox
), frame
, TRUE
, TRUE
, 0);
615 table
= generate_actions_box (fp_dlg
);
616 gtk_container_add (GTK_CONTAINER (frame
), table
);
618 frame
= gtk_frame_new (_("Open action"));
619 fp_dlg
->needs_terminal_check
= gtk_check_button_new_with_label (_("Needs terminal to run"));
620 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fp_dlg
->needs_terminal_check
),
621 fp_dlg
->needs_terminal
);
622 gtk_container_add (GTK_CONTAINER (frame
), fp_dlg
->needs_terminal_check
);
624 gtk_box_pack_start (GTK_BOX (vbox
), frame
, TRUE
, TRUE
, 0);
628 /* Permissions Pane */
631 align_label_new (char *text
, double xalign
, double yalign
)
635 label
= gtk_label_new (text
);
636 gtk_misc_set_alignment (GTK_MISC (label
), xalign
, yalign
);
637 gtk_widget_show (label
);
643 perm_get_umode (GnomeFilePropertyDialog
*fp_dlg
)
647 #define SETBIT(widget, flag) umode |= GTK_TOGGLE_BUTTON (widget)->active ? flag : 0
651 SETBIT (fp_dlg
->suid
, S_ISUID
);
652 SETBIT (fp_dlg
->sgid
, S_ISGID
);
653 SETBIT (fp_dlg
->svtx
, S_ISVTX
);
655 SETBIT (fp_dlg
->rusr
, S_IRUSR
);
656 SETBIT (fp_dlg
->wusr
, S_IWUSR
);
657 SETBIT (fp_dlg
->xusr
, S_IXUSR
);
659 SETBIT (fp_dlg
->rgrp
, S_IRGRP
);
660 SETBIT (fp_dlg
->wgrp
, S_IWGRP
);
661 SETBIT (fp_dlg
->xgrp
, S_IXGRP
);
663 SETBIT (fp_dlg
->roth
, S_IROTH
);
664 SETBIT (fp_dlg
->woth
, S_IWOTH
);
665 SETBIT (fp_dlg
->xoth
, S_IXOTH
);
673 perm_set_mode_label (GtkWidget
*widget
, gpointer data
)
675 GnomeFilePropertyDialog
*fp_dlg
;
679 fp_dlg
= GNOME_FILE_PROPERTY_DIALOG (data
);
680 umode
= perm_get_umode (fp_dlg
);
681 if (!fp_dlg
->executable
&& (umode
& (S_IXUSR
| S_IXGRP
| S_IXOTH
))) {
682 fp_dlg
->executable
= TRUE
;
683 switch_metadata_box (fp_dlg
);
684 } else if (fp_dlg
->executable
&& !(umode
& (S_IXUSR
| S_IXGRP
| S_IXOTH
))) {
685 fp_dlg
->executable
= FALSE
;
686 switch_metadata_box (fp_dlg
);
689 s_mode
[0] = '0' + ((umode
& (S_ISUID
| S_ISGID
| S_ISVTX
)) >> 9);
690 s_mode
[1] = '0' + ((umode
& (S_IRUSR
| S_IWUSR
| S_IXUSR
)) >> 6);
691 s_mode
[2] = '0' + ((umode
& (S_IRGRP
| S_IWGRP
| S_IXGRP
)) >> 3);
692 s_mode
[3] = '0' + ((umode
& (S_IROTH
| S_IWOTH
| S_IXOTH
)) >> 0);
694 gtk_label_set_text (GTK_LABEL (fp_dlg
->mode_label
), s_mode
);
698 perm_check_new (char *text
, int state
, GnomeFilePropertyDialog
*fp_dlg
)
703 check
= gtk_check_button_new_with_label (text
);
705 check
= gtk_check_button_new ();
707 gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (check
), FALSE
);
708 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check
), state
? TRUE
: FALSE
);
710 gtk_signal_connect (GTK_OBJECT (check
), "toggled",
711 (GtkSignalFunc
) perm_set_mode_label
,
714 gtk_widget_show (check
);
718 #define ATTACH(table, widget, left, right, top, bottom) \
719 gtk_table_attach (GTK_TABLE (table), widget, \
720 left, right, top, bottom, \
721 GTK_FILL | GTK_SHRINK, \
722 GTK_FILL | GTK_SHRINK, \
725 #define PERMSET(name, r, w, x, rmask, wmask, xmask, y) do { \
726 r = perm_check_new (NULL, fp_dlg->st.st_mode & rmask, fp_dlg); \
727 w = perm_check_new (NULL, fp_dlg->st.st_mode & wmask, fp_dlg); \
728 x = perm_check_new (NULL, fp_dlg->st.st_mode & xmask, fp_dlg); \
730 ATTACH (table, align_label_new (name, 0.0, 0.5), 0, 1, y, y + 1); \
731 ATTACH (table, r, 1, 2, y, y + 1); \
732 ATTACH (table, w, 2, 3, y, y + 1); \
733 ATTACH (table, x, 3, 4, y, y + 1); \
737 perm_mode_new (GnomeFilePropertyDialog
*fp_dlg
)
745 frame
= gtk_frame_new (_("File Permissions"));
747 vbox
= gtk_vbox_new (FALSE
, GNOME_PAD_SMALL
);
748 gtk_container_set_border_width (GTK_CONTAINER (vbox
), 6);
749 gtk_container_add (GTK_CONTAINER (frame
), vbox
);
750 gtk_widget_show (vbox
);
752 hbox
= gtk_hbox_new (FALSE
, 0);
753 gtk_box_pack_start (GTK_BOX (vbox
), hbox
, FALSE
, FALSE
, 0);
754 gtk_widget_show (hbox
);
756 gtk_box_pack_start (GTK_BOX (hbox
), align_label_new (_("Current mode: "), 0.0, 0.5),
759 fp_dlg
->mode_label
= align_label_new ("0000", 0.0, 0.5);
760 gtk_box_pack_start (GTK_BOX (hbox
), fp_dlg
->mode_label
, FALSE
, FALSE
, 0);
762 table
= gtk_table_new (4, 5, FALSE
);
763 if (!fp_dlg
->modifyable
|| S_ISLNK (fp_dlg
->st
.st_mode
))
764 gtk_widget_set_sensitive (table
, FALSE
);
765 gtk_table_set_col_spacings (GTK_TABLE (table
), 4);
766 gtk_table_set_row_spacings (GTK_TABLE (table
), 6);
767 gtk_box_pack_start (GTK_BOX (vbox
), table
, FALSE
, FALSE
, 0);
768 gtk_widget_show (table
);
772 ATTACH (table
, align_label_new (_("Read"), 0.0, 0.5), 1, 2, 0, 1);
773 ATTACH (table
, align_label_new (_("Write"), 0.0, 0.5), 2, 3, 0, 1);
774 ATTACH (table
, align_label_new (_("Exec"), 0.0, 0.5), 3, 4, 0, 1);
775 ATTACH (table
, align_label_new (_("Special"), 0.0, 0.5), 4, 5, 0, 1);
779 PERMSET (_("User"), fp_dlg
->rusr
, fp_dlg
->wusr
, fp_dlg
->xusr
, S_IRUSR
, S_IWUSR
, S_IXUSR
, 1);
780 PERMSET (_("Group"), fp_dlg
->rgrp
, fp_dlg
->wgrp
, fp_dlg
->xgrp
, S_IRGRP
, S_IWGRP
, S_IXGRP
, 2);
781 PERMSET (_("Other"), fp_dlg
->roth
, fp_dlg
->woth
, fp_dlg
->xoth
, S_IROTH
, S_IWOTH
, S_IXOTH
, 3);
785 fp_dlg
->suid
= perm_check_new (_("Set UID"), fp_dlg
->st
.st_mode
& S_ISUID
, fp_dlg
);
786 fp_dlg
->sgid
= perm_check_new (_("Set GID"), fp_dlg
->st
.st_mode
& S_ISGID
, fp_dlg
);
787 fp_dlg
->svtx
= perm_check_new (_("Sticky"), fp_dlg
->st
.st_mode
& S_ISVTX
, fp_dlg
);
789 ATTACH (table
, fp_dlg
->suid
, 4, 5, 1, 2);
790 ATTACH (table
, fp_dlg
->sgid
, 4, 5, 2, 3);
791 ATTACH (table
, fp_dlg
->svtx
, 4, 5, 3, 4);
793 perm_set_mode_label (NULL
, fp_dlg
);
794 gtk_label_get (GTK_LABEL (fp_dlg
->mode_label
), &mode
);
795 fp_dlg
->mode_name
= g_strdup (mode
);
803 perm_owner_new (GnomeFilePropertyDialog
*fp_dlg
)
806 struct passwd
*passwd
;
808 gentry
= gtk_entry_new ();
810 if (fp_dlg
->euid
!= 0)
811 gtk_widget_set_sensitive (gentry
, FALSE
);
812 passwd
= getpwuid (fp_dlg
->st
.st_uid
);
814 fp_dlg
->user_name
= passwd
->pw_name
;
815 gtk_entry_set_text (GTK_ENTRY (gentry
), passwd
->pw_name
);
819 g_snprintf (buf
, sizeof (buf
), "%d", (int) fp_dlg
->st
.st_uid
);
820 gtk_entry_set_text (GTK_ENTRY (gentry
), buf
);
827 perm_group_new (GnomeFilePropertyDialog
*fp_dlg
)
831 gboolean grp_flag
= FALSE
;
832 gchar
*grpname
= NULL
;
836 /* Are we root? Do we own the file? */
837 /* In this case we can change it. */
838 /* A little bit of this was swiped from kfm. */
840 if ((fp_dlg
->euid
== 0) || (fp_dlg
->st
.st_uid
== fp_dlg
->euid
)) {
841 gentry
= gtk_combo_new ();
842 grp
= getgrgid (fp_dlg
->st
.st_gid
);
845 fp_dlg
->group_name
= g_strdup (grp
->gr_name
);
847 fp_dlg
->group_name
= g_strdup_printf ("%d", (int) grp
->gr_gid
);
850 fp_dlg
->group_name
= g_strdup_printf ("%d", (int) fp_dlg
->st
.st_gid
);
853 /* we change this, b/c we are able to set the egid, if we aren't in the group already */
854 grp
= getgrgid (getegid());
857 grpname
= g_strdup (grp
->gr_name
);
859 grpname
= g_strdup_printf ("%d", (int) grp
->gr_gid
);
861 grpname
= g_strdup_printf ("%d", (int) fp_dlg
->st
.st_gid
);
863 if (fp_dlg
->euid
!= 0)
864 gtk_editable_set_editable (GTK_EDITABLE (GTK_COMBO (gentry
)->entry
), FALSE
);
865 for (setgrent (); (grp
= getgrent ()) != NULL
;) {
866 if (!grp_flag
&& grpname
&& !strcmp (grp
->gr_name
, grpname
)) {
867 list
= g_list_insert_sorted (list
, g_strdup (grp
->gr_name
), (GCompareFunc
)strcmp
);
871 if (fp_dlg
->euid
== 0) {
872 list
= g_list_insert_sorted (list
, g_strdup (grp
->gr_name
), (GCompareFunc
)strcmp
);
874 gchar
**members
= grp
->gr_mem
;
876 while ((member
= *members
) != 0L) {
877 if (!strcmp (member
, fp_dlg
->user_name
)) {
878 list
= g_list_insert_sorted (list
, g_strdup (grp
->gr_name
), (GCompareFunc
)strcmp
);
887 /* we also might want to add the egid to the list. */
889 list
= g_list_insert_sorted (list
, g_strdup (grpname
), (GCompareFunc
)strcmp
);
891 /* Now we have a list. We should make our option menu. */
892 gtk_combo_set_popdown_strings (GTK_COMBO (gentry
), list
);
893 for (templist
= list
; templist
; templist
= templist
->next
) {
894 g_free (templist
->data
);
896 gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (gentry
)->entry
), fp_dlg
->group_name
);
899 /* we're neither so we just put an entry down */
900 gentry
= gtk_entry_new ();
901 gtk_widget_set_sensitive (gentry
, FALSE
);
903 grp
= getgrgid (fp_dlg
->st
.st_gid
);
905 gtk_entry_set_text (GTK_ENTRY (gentry
), grp
->gr_name
);
909 g_snprintf (buf
, sizeof (buf
), _("<Unknown> (%d)"), fp_dlg
->st
.st_gid
);
910 gtk_entry_set_text (GTK_ENTRY (gentry
), buf
);
918 perm_ownership_new (GnomeFilePropertyDialog
*fp_dlg
)
923 frame
= gtk_frame_new (_("File ownership"));
925 table
= gtk_table_new (2, 2, FALSE
);
926 gtk_container_set_border_width (GTK_CONTAINER (table
), 6);
927 gtk_table_set_col_spacings (GTK_TABLE (table
), 6);
928 gtk_table_set_row_spacings (GTK_TABLE (table
), 4);
929 gtk_container_add (GTK_CONTAINER (frame
), table
);
930 gtk_widget_show (table
);
934 gtk_table_attach (GTK_TABLE (table
), align_label_new (_("Owner"), 0.0, 0.5),
936 GTK_FILL
| GTK_SHRINK
, GTK_FILL
| GTK_SHRINK
,
939 fp_dlg
->owner_entry
= perm_owner_new (fp_dlg
);
940 gtk_table_attach (GTK_TABLE (table
), fp_dlg
->owner_entry
,
942 GTK_EXPAND
| GTK_FILL
| GTK_SHRINK
,
943 GTK_FILL
| GTK_SHRINK
,
945 gtk_widget_show (fp_dlg
->owner_entry
);
949 gtk_table_attach (GTK_TABLE (table
), align_label_new (_("Group"), 0.0, 0.5),
951 GTK_FILL
| GTK_SHRINK
, GTK_FILL
| GTK_SHRINK
,
954 fp_dlg
->group_entry
= perm_group_new (fp_dlg
);
955 gtk_table_attach (GTK_TABLE (table
), fp_dlg
->group_entry
,
957 GTK_EXPAND
| GTK_FILL
| GTK_SHRINK
,
958 GTK_FILL
| GTK_SHRINK
,
960 gtk_widget_show (fp_dlg
->group_entry
);
965 create_perm_properties (GnomeFilePropertyDialog
*fp_dlg
)
969 vbox
= gtk_vbox_new (FALSE
, GNOME_PAD_SMALL
);
970 gtk_container_set_border_width (GTK_CONTAINER (vbox
), GNOME_PAD
);
971 gtk_box_pack_start (GTK_BOX (vbox
), perm_mode_new (fp_dlg
), FALSE
, FALSE
, 0);
972 gtk_box_pack_start (GTK_BOX (vbox
), perm_ownership_new (fp_dlg
), TRUE
, TRUE
, 0);
976 /* finally the new dialog */
978 init_metadata (GnomeFilePropertyDialog
*fp_dlg
)
981 char *mime_type
, *str
;
982 gchar link_name
[MC_MAXPATHLEN
];
984 gchar
*file_name
, *desktop_url
;
986 if (gnome_metadata_get (fp_dlg
->file_name
, "fm-open", &size
, &fp_dlg
->fm_open
) != 0)
987 gnome_metadata_get (fp_dlg
->file_name
, "open", &size
, &fp_dlg
->fm_open
);
988 if (gnome_metadata_get (fp_dlg
->file_name
, "fm-view", &size
, &fp_dlg
->fm_view
) != 0)
989 gnome_metadata_get (fp_dlg
->file_name
, "view", &size
, &fp_dlg
->fm_view
);
990 gnome_metadata_get (fp_dlg
->file_name
, "edit", &size
, &fp_dlg
->edit
);
991 gnome_metadata_get (fp_dlg
->file_name
, "drop-action", &size
, &fp_dlg
->drop_target
);
994 * Fetch the needs-terminal setting
996 if (gnome_metadata_get (fp_dlg
->file_name
, "flags", &size
, &str
) == 0){
997 fp_dlg
->needs_terminal
= strstr (str
, "needsterminal") != 0;
1000 fp_dlg
->needs_terminal
= 0;
1003 file_name
= fp_dlg
->file_name
;
1004 if (S_ISLNK (fp_dlg
->st
.st_mode
)) {
1005 n
= mc_readlink (fp_dlg
->file_name
, link_name
, MC_MAXPATHLEN
);
1008 file_name
= link_name
;
1012 if (gnome_metadata_get (fp_dlg
->file_name
, "desktop-url", &size
, &desktop_url
) == 0)
1013 fp_dlg
->desktop_url
= desktop_url
;
1015 fp_dlg
->desktop_url
= NULL
;
1017 if (gnome_metadata_get (fp_dlg
->file_name
, "icon-caption", &size
, &fp_dlg
->caption
))
1018 fp_dlg
->caption
= g_strdup (desktop_url
);
1025 mime_type
= (char *) gnome_mime_type_or_default_of_file (file_name
, NULL
);
1028 mime_type
= (char *) gnome_mime_type_or_default (file_name
, NULL
);
1032 fp_dlg
->mime_fm_open
= gnome_mime_get_value (mime_type
, "fm-open");
1033 if (!fp_dlg
->mime_fm_open
)
1034 fp_dlg
->mime_fm_open
= gnome_mime_get_value (mime_type
, "open");
1035 fp_dlg
->mime_fm_view
= gnome_mime_get_value (mime_type
, "fm-view");
1036 if (!fp_dlg
->mime_fm_view
)
1037 fp_dlg
->mime_fm_view
= gnome_mime_get_value (mime_type
, "view");
1038 fp_dlg
->mime_edit
= gnome_mime_get_value (mime_type
, "edit");
1039 fp_dlg
->mime_drop_target
= gnome_mime_get_value (mime_type
, "drop-action");
1043 gnome_file_property_dialog_new (gchar
*file_name
, gboolean can_set_icon
)
1045 GnomeFilePropertyDialog
*fp_dlg
;
1046 GtkWidget
*notebook
;
1047 GtkWidget
*new_page
;
1048 gchar
*title_string
;
1051 g_return_val_if_fail (file_name
!= NULL
, NULL
);
1052 fp_dlg
= gtk_type_new (gnome_file_property_dialog_get_type ());
1054 /* We set non-gui specific things first */
1055 if (mc_lstat (file_name
, &fp_dlg
->st
) == -1) {
1056 /* Bad things man, bad things */
1057 gtk_object_unref (GTK_OBJECT (fp_dlg
));
1061 mode
= fp_dlg
->st
.st_mode
;
1062 if (S_ISLNK (mode
)){
1065 if (mc_stat (file_name
, &s
) != -1)
1069 if (fp_dlg
->st
.st_mode
& (S_IXUSR
| S_IXGRP
|S_IXOTH
)) {
1070 fp_dlg
->executable
= TRUE
;
1072 fp_dlg
->executable
= FALSE
;
1075 fp_dlg
->file_name
= g_strdup (file_name
);
1076 fp_dlg
->euid
= geteuid ();
1077 fp_dlg
->can_set_icon
= can_set_icon
;
1078 if (S_ISCHR (fp_dlg
->st
.st_mode
) || S_ISBLK (fp_dlg
->st
.st_mode
)
1079 || ((fp_dlg
->euid
!= fp_dlg
->st
.st_uid
) && (fp_dlg
->euid
!= 0)))
1080 fp_dlg
->modifyable
= FALSE
;
1081 init_metadata (fp_dlg
);
1083 /* and now, we set up the gui. */
1084 notebook
= gtk_notebook_new ();
1086 if (fp_dlg
->desktop_url
)
1087 gtk_notebook_append_page (GTK_NOTEBOOK (notebook
),
1088 create_url_properties (fp_dlg
),
1089 gtk_label_new (_("URL")));
1090 gtk_notebook_append_page (GTK_NOTEBOOK (notebook
),
1091 create_general_properties (fp_dlg
),
1092 gtk_label_new (_("Statistics")));
1094 new_page
= create_settings_pane (fp_dlg
);
1096 gtk_notebook_append_page (GTK_NOTEBOOK (notebook
),
1098 gtk_label_new (_("Options")));
1099 gtk_notebook_append_page (GTK_NOTEBOOK (notebook
),
1100 create_perm_properties (fp_dlg
),
1101 gtk_label_new (_("Permissions")));
1102 gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (fp_dlg
)->vbox
),
1103 notebook
, TRUE
, TRUE
, 0);
1104 title_string
= g_strconcat (strrchr (file_name
, '/') + 1, _(" Properties"), NULL
);
1105 gtk_window_set_title (GTK_WINDOW (fp_dlg
), title_string
);
1106 g_free (title_string
);
1108 gnome_dialog_append_button ( GNOME_DIALOG(fp_dlg
),
1109 GNOME_STOCK_BUTTON_OK
);
1110 gnome_dialog_append_button ( GNOME_DIALOG(fp_dlg
),
1111 GNOME_STOCK_BUTTON_CANCEL
);
1112 gtk_widget_show_all (GNOME_DIALOG (fp_dlg
)->vbox
);
1114 /* It's okay to do this now... */
1115 /* and set the rest of the fields */
1116 switch_metadata_box (fp_dlg
);
1118 return GTK_WIDGET (fp_dlg
);
1122 apply_mode_change (GnomeFilePropertyDialog
*fpd
)
1125 gtk_label_get (GTK_LABEL (fpd
->mode_label
), &new_mode
);
1126 if (strcmp (new_mode
, fpd
->mode_name
)) {
1127 mc_chmod (fpd
->file_name
, (mode_t
) strtol(new_mode
, (char **)NULL
, 8));
1134 apply_uid_group_change (GnomeFilePropertyDialog
*fpd
)
1140 gchar
*new_user_name
= NULL
;
1141 gchar
*new_group_name
= NULL
;
1143 uid
= fpd
->st
.st_uid
;
1144 gid
= fpd
->st
.st_gid
;
1146 /* we only check if our euid == 0 */
1147 if (fpd
->euid
== 0) {
1148 new_user_name
= gtk_entry_get_text (GTK_ENTRY (fpd
->owner_entry
));
1150 if (fpd
->user_name
&& new_user_name
&& strcmp (fpd
->user_name
, new_user_name
)) {
1151 /* now we need to get the new uid */
1152 p
= getpwnam (new_user_name
);
1154 uid
= atoi (new_user_name
);
1156 message (1, MSG_ERROR
, _("You entered an invalid username"));
1157 uid
= fpd
->st
.st_uid
;
1163 p
= getpwnam (new_user_name
);
1165 uid
= atoi (new_user_name
);
1167 message (1, MSG_ERROR
, _("You entered an invalid username"));
1168 uid
= fpd
->st
.st_uid
;
1176 /* now we check the group */
1177 /* We are only a combo if we are sensitive, and we only want to check if we are
1179 if (GTK_WIDGET_IS_SENSITIVE (fpd
->group_entry
))
1180 new_group_name
= gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (fpd
->group_entry
)->entry
));
1182 if (fpd
->group_name
&& new_group_name
&& strcmp (fpd
->group_name
, new_group_name
)) {
1183 g
= getgrnam (new_group_name
);
1185 gid
= atoi (new_group_name
);
1187 message (1, MSG_ERROR
, _("You entered an invalid group name"));
1188 gid
= fpd
->st
.st_gid
;
1193 if ((uid
!= fpd
->st
.st_uid
) || (gid
!= fpd
->st
.st_gid
)) {
1194 mc_chown (fpd
->file_name
, uid
, gid
);
1201 apply_name_change (GnomeFilePropertyDialog
*fpd
)
1208 new_name
= gtk_entry_get_text (GTK_ENTRY (fpd
->file_entry
));
1210 message (1, MSG_ERROR
, _("You must rename your file to something"));
1213 /* has it changed? */
1214 if (strcmp (strrchr(fpd
->file_name
, '/') + 1, new_name
)) {
1215 if (strchr (new_name
, '/')) {
1216 message (1, MSG_ERROR
, _("You cannot rename a file to something containing a '/' character"));
1224 /* create the files. */
1225 base_name
= g_strdup (fpd
->file_name
);
1227 p
= strrchr (base_name
, '/');
1232 full_target
= concat_dir_and_file (base_name
, new_name
);
1235 ctx
= file_op_context_new ();
1236 file_op_context_create_ui (ctx
, OP_MOVE
, FALSE
);
1237 s
= move_file_file (ctx
, fpd
->file_name
, full_target
, &count
, &bytes
);
1238 file_op_context_destroy (ctx
);
1240 if (s
== FILE_CONT
){
1241 g_free (fpd
->file_name
);
1242 fpd
->file_name
= full_target
;
1244 g_free (full_target
);
1251 apply_metadata_change (GnomeFilePropertyDialog
*fpd
)
1255 /* If we don't have an open_cbox, that means we have no metadata
1258 if (fpd
->open_cbox
!= NULL
) {
1259 if (!GTK_TOGGLE_BUTTON (fpd
->open_cbox
)->active
) {
1260 text
= gtk_entry_get_text (GTK_ENTRY (fpd
->open_entry
));
1261 if (text
&& text
[0])
1262 gnome_metadata_set (fpd
->file_name
,
1267 gnome_metadata_remove (fpd
->file_name
,
1271 gnome_metadata_remove (fpd
->file_name
,
1274 if (fpd
->executable
) {
1275 if (!GTK_TOGGLE_BUTTON (fpd
->prop1_cbox
)->active
) {
1276 text
= gtk_entry_get_text (GTK_ENTRY (fpd
->prop1_entry
));
1277 if (text
&& text
[0])
1278 gnome_metadata_set (fpd
->file_name
,
1283 gnome_metadata_remove (fpd
->file_name
,
1286 if (fpd
->drop_target
)
1287 gnome_metadata_remove (fpd
->file_name
,
1291 if (!GTK_TOGGLE_BUTTON (fpd
->prop1_cbox
)->active
) {
1292 text
= gtk_entry_get_text (GTK_ENTRY (fpd
->prop1_entry
));
1293 if (text
&& text
[0])
1294 gnome_metadata_set (fpd
->file_name
,
1299 gnome_metadata_remove (fpd
->file_name
,
1303 gnome_metadata_remove (fpd
->file_name
,
1306 if (!GTK_TOGGLE_BUTTON (fpd
->prop2_cbox
)->active
) {
1307 text
= gtk_entry_get_text (GTK_ENTRY (fpd
->prop2_entry
));
1308 if (text
&& text
[0])
1309 gnome_metadata_set (fpd
->file_name
,
1314 gnome_metadata_remove (fpd
->file_name
,
1318 gnome_metadata_remove (fpd
->file_name
,
1324 if (fpd
->desktop_url
){
1325 char *new_desktop_url
= gtk_entry_get_text (GTK_ENTRY (fpd
->desktop_entry
));
1326 char *new_caption
= gtk_entry_get_text (GTK_ENTRY (fpd
->caption_entry
));
1328 gnome_metadata_set (fpd
->file_name
, "desktop-url",
1329 strlen (new_desktop_url
)+1, new_desktop_url
);
1330 gnome_metadata_set (fpd
->file_name
, "icon-caption",
1331 strlen (new_caption
)+1, new_caption
);
1335 * "Needs terminal" check button
1337 * This piece of code is more complex than it should, as the "flags"
1338 * metadata value is actually a list of comma separated flags. So
1339 * we need to edit this list when removing the "needsterminal" flag.
1341 if (fpd
->needs_terminal_check
)
1343 int toggled
= 0 != GTK_TOGGLE_BUTTON (fpd
->needs_terminal_check
)->active
;
1347 if (gnome_metadata_get (fpd
->file_name
, "flags", &size
, &buf
) == 0){
1350 p
= strstr (buf
, "needsterminal");
1353 p
= g_strconcat (buf
, ",needsterminal", NULL
);
1354 gnome_metadata_set (fpd
->file_name
, "flags", strlen (p
)+1, p
);
1362 p1
= g_malloc (p
- buf
+ 1);
1363 strncpy (p1
, buf
, p
- buf
);
1368 p
+= strlen ("needsterminal");
1370 p2
= g_strconcat (p1
, p
, NULL
);
1371 if (strcmp (p2
, ",") == 0)
1372 gnome_metadata_remove (fpd
->file_name
, "flags");
1374 gnome_metadata_set (fpd
->file_name
, "flags",
1383 gnome_metadata_set (fpd
->file_name
, "flags",
1384 sizeof ("needsterminal"), "needsterminal");
1389 if (!fpd
->can_set_icon
)
1391 /* And finally, we set the metadata on the icon filename */
1392 text
= gnome_icon_entry_get_filename (GNOME_ICON_ENTRY (fpd
->button
));
1393 /*gtk_entry_get_text (GTK_ENTRY (gnome_icon_entry_gtk_entry (GNOME_ICON_ENTRY (fpd->button))));*/
1396 if (fpd
->icon_filename
== NULL
|| strcmp (fpd
->icon_filename
, text
) != 0)
1397 gnome_metadata_set (fpd
->file_name
, "icon-filename", strlen (text
) + 1, text
);
1400 /* I suppose we should only do this if we know there's been a change -- I'll try to figure it
1401 * out later if it turns out to be important. */
1405 /* This function will apply what changes it can do. It is meant to be used in conjunction
1406 * with a gnome_dialog_run_and_hide. Please note that doing a gnome_dialog_run
1407 * will (obviously) cause greivious bogoness. */
1410 gnome_file_property_dialog_make_changes (GnomeFilePropertyDialog
*file_property_dialog
)
1414 g_return_val_if_fail (file_property_dialog
!= NULL
, 1);
1415 g_return_val_if_fail (GNOME_IS_FILE_PROPERTY_DIALOG (file_property_dialog
), 1);
1417 retval
+= apply_mode_change (file_property_dialog
);
1418 retval
+= apply_uid_group_change (file_property_dialog
);
1419 retval
+= apply_name_change (file_property_dialog
);
1420 retval
+= apply_metadata_change (file_property_dialog
);