2 * ROX-Filer, filer for the ROX desktop project
3 * Copyright (C) 2006, Thomas Leonard and others (see changelog for details).
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation; either version 2 of the License, or (at your option)
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
17 * Place, Suite 330, Boston, MA 02111-1307 USA
20 /* infobox.c - code for showing a file's attributes */
27 #include <sys/param.h>
29 #include <libxml/parser.h>
37 #include "gui_support.h"
42 #include "dnd.h" /* For xa_string */
43 #include "run.h" /* For show_help_files() */
49 typedef struct _FileStatus FileStatus
;
51 /* This is for the 'file(1) says...' thing */
54 int fd
; /* FD to read from, -1 if closed */
55 int input
; /* Input watcher tag if fd valid */
56 GtkLabel
*label
; /* Widget to output to */
57 gchar
*text
; /* String so far */
68 typedef struct _Permissions Permissions
;
77 /* Static prototypes */
78 static void refresh_info(GObject
*window
);
79 static GtkWidget
*make_vbox(const guchar
*path
, GObject
*window
);
80 static GtkWidget
*make_details(const guchar
*path
, DirItem
*item
,
82 static GtkWidget
*make_about(const guchar
*path
, XMLwrapper
*ai
);
83 static GtkWidget
*make_about_desktop(const gchar
*path
);
84 static GtkWidget
*make_file_says(const guchar
*path
);
85 static GtkWidget
*make_permissions(const gchar
*path
, DirItem
*item
);
86 static void add_file_output(FileStatus
*fs
,
87 gint source
, GdkInputCondition condition
);
88 static const gchar
*pretty_type(DirItem
*file
, const guchar
*path
);
89 static void got_response(GObject
*window
, gint response
, gpointer data
);
90 static void file_info_destroyed(GtkWidget
*widget
, FileStatus
*fs
);
92 /****************************************************************
93 * EXTERNAL INTERFACE *
94 ****************************************************************/
96 /* Open each item in a new infobox. Confirms if there are a large
97 * number of items to show.
99 void infobox_show_list(GList
*paths
)
103 n
= g_list_length(paths
);
110 message
= g_strdup_printf(
111 _("Are you sure you want to open %d windows?"), n
);
112 ok
= confirm(message
, GTK_STOCK_YES
, _("Show Info"));
118 g_list_foreach(paths
, (GFunc
) infobox_new
, NULL
);
121 /* Create and display a new info box showing details about this item */
122 void infobox_new(const gchar
*pathname
)
124 GtkWidget
*window
, *details
;
128 g_return_if_fail(pathname
!= NULL
);
130 path
= g_strdup(pathname
); /* Gets attached to window & freed later */
132 window
= gtk_dialog_new_with_buttons(
133 g_utf8_validate(path
, -1, NULL
) ? path
135 NULL
, GTK_DIALOG_NO_SEPARATOR
,
136 GTK_STOCK_CLOSE
, GTK_RESPONSE_CANCEL
,
137 GTK_STOCK_REFRESH
, GTK_RESPONSE_APPLY
,
140 gtk_window_set_position(GTK_WINDOW(window
), GTK_WIN_POS_MOUSE
);
142 owindow
= G_OBJECT(window
);
143 details
= make_vbox(path
, owindow
);
144 gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(window
)->vbox
),
147 g_object_set_data(owindow
, "details", details
);
148 g_object_set_data_full(owindow
, "path", path
, g_free
);
150 g_signal_connect(window
, "response", G_CALLBACK(got_response
), NULL
);
153 gtk_widget_show_all(window
);
156 /****************************************************************
157 * INTERNAL FUNCTIONS *
158 ****************************************************************/
160 static void got_response(GObject
*window
, gint response
, gpointer data
)
162 if (response
== GTK_RESPONSE_APPLY
)
163 refresh_info(window
);
166 gtk_widget_destroy(GTK_WIDGET(window
));
171 static void refresh_info(GObject
*window
)
173 GtkWidget
*details
, *vbox
;
176 path
= g_object_get_data(window
, "path");
177 details
= g_object_get_data(window
, "details");
178 g_return_if_fail(details
!= NULL
);
179 g_return_if_fail(path
!= NULL
);
181 vbox
= details
->parent
;
182 gtk_widget_destroy(details
);
184 details
= make_vbox(path
, window
);
185 g_object_set_data(window
, "details", details
);
186 gtk_box_pack_start_defaults(GTK_BOX(vbox
), details
);
187 gtk_widget_show_all(details
);
190 static void add_frame(GtkBox
*vbox
, GtkWidget
*list
)
194 frame
= gtk_frame_new(NULL
);
195 gtk_frame_set_shadow_type(GTK_FRAME(frame
), GTK_SHADOW_IN
);
196 gtk_container_add(GTK_CONTAINER(frame
), list
);
197 gtk_box_pack_start_defaults(vbox
, frame
);
200 /* Create the VBox widget that contains the details.
201 * Note that 'path' must not be freed until the vbox is destroyed.
203 static GtkWidget
*make_vbox(const guchar
*path
, GObject
*window
)
208 xmlNode
*about
= NULL
;
210 GtkWidget
*hbox
, *name
, *label
;
212 g_return_val_if_fail(path
[0] == '/', NULL
);
214 item
= diritem_new(g_basename(path
));
215 diritem_restat(path
, item
, NULL
);
217 ai
= appinfo_get(path
, item
);
219 about
= xml_get_section(ai
, NULL
, "About");
221 vbox
= GTK_BOX(gtk_vbox_new(FALSE
, 4));
222 gtk_container_set_border_width(GTK_CONTAINER(vbox
), 4);
224 /* Heading, with icon and name */
225 hbox
= gtk_hbox_new(FALSE
, 4);
226 gtk_box_pack_start(vbox
, hbox
, FALSE
, TRUE
, 0);
227 gtk_box_pack_start(GTK_BOX(hbox
),
228 gtk_image_new_from_pixbuf(di_image(item
)->pixbuf
),
231 if (g_utf8_validate(item
->leafname
, -1, NULL
))
232 name
= gtk_label_new(item
->leafname
);
237 u8
= to_utf8(item
->leafname
);
238 name
= gtk_label_new(u8
);
241 gtk_label_set_selectable(GTK_LABEL(name
), TRUE
);
242 gtk_label_set_line_wrap(GTK_LABEL(name
), TRUE
);
243 gtk_box_pack_start(GTK_BOX(hbox
), name
, FALSE
, TRUE
, 4);
245 make_heading(name
, PANGO_SCALE_X_LARGE
);
247 /* List of file attributes */
248 add_frame(vbox
, make_details(path
, item
, window
));
250 help_dir
= g_strconcat(path
, "/Help", NULL
);
252 if (access(help_dir
, F_OK
) == 0)
254 GtkWidget
*button
, *align
;
256 align
= gtk_alignment_new(0.5, 0.5, 0, 0);
258 button
= button_new_mixed(GTK_STOCK_JUMP_TO
,
259 _("Show _Help Files"));
260 gtk_box_pack_start(vbox
, align
, FALSE
, TRUE
, 0);
261 gtk_container_add(GTK_CONTAINER(align
), button
);
262 g_signal_connect_swapped(button
, "clicked",
263 G_CALLBACK(show_help_files
),
268 if (!(item
->flags
& ITEM_FLAG_SYMLINK
))
270 label
= gtk_label_new(NULL
);
271 gtk_label_set_markup(GTK_LABEL(label
),
272 _("<b>Permissions</b>"));
273 gtk_misc_set_alignment(GTK_MISC(label
), 0, 1);
274 gtk_box_pack_start(vbox
, label
, FALSE
, TRUE
, 2);
276 gtk_box_pack_start(vbox
, make_permissions(path
, item
),
281 add_frame(vbox
, make_about(path
, ai
));
282 else if (item
->mime_type
== application_x_desktop
)
284 add_frame(vbox
, make_about_desktop(path
));
286 else if (item
->base_type
== TYPE_FILE
)
288 label
= gtk_label_new(NULL
);
289 gtk_label_set_markup(GTK_LABEL(label
),
290 _("<b>Contents indicate...</b>"));
291 gtk_misc_set_alignment(GTK_MISC(label
), 0, 1);
292 gtk_box_pack_start(vbox
, label
, FALSE
, TRUE
, 2);
294 gtk_box_pack_start_defaults(vbox
, make_file_says(path
));
302 return (GtkWidget
*) vbox
;
305 /* The selection has changed - grab or release the primary selection */
306 static void set_selection(GtkTreeView
*view
, gpointer data
)
308 static GtkClipboard
*primary
= NULL
;
310 GtkTreePath
*path
= NULL
;
314 gtk_tree_view_get_cursor(view
, &path
, NULL
);
319 primary
= gtk_clipboard_get(gdk_atom_intern("PRIMARY", FALSE
));
321 model
= gtk_tree_view_get_model(GTK_TREE_VIEW(view
));
323 gtk_tree_model_get_iter(model
, &iter
, path
);
324 gtk_tree_path_free(path
);
326 gtk_tree_model_get(model
, &iter
, 1, &text
, -1);
328 gtk_clipboard_set_text(primary
, text
, -1);
333 /* Returns a GtkTreePath for the item */
334 static const gchar
*add_row(GtkListStore
*store
, const gchar
*label
,
340 static gchar
*last
= NULL
;
342 if (!g_utf8_validate(data
, -1, NULL
))
345 gtk_list_store_append(store
, &iter
);
346 gtk_list_store_set(store
, &iter
, 0, label
, 1, u8
? u8
: data
, -1);
350 tpath
= gtk_tree_model_get_path(GTK_TREE_MODEL(store
), &iter
);
353 last
= gtk_tree_path_to_string(tpath
);
354 gtk_tree_path_free(tpath
);
359 static void add_row_and_free(GtkListStore
*store
,
360 const gchar
*label
, gchar
*data
)
362 add_row(store
, label
, data
);
366 /* Create an empty list view, ready to place some data in */
367 static void make_list(GtkListStore
**list_store
, GtkWidget
**list_view
,
368 GCallback cell_edited
)
372 GtkCellRenderer
*cell_renderer
;
374 /* Field name, value, editable */
375 store
= gtk_list_store_new(3, G_TYPE_STRING
, G_TYPE_STRING
,
377 view
= GTK_TREE_VIEW(
378 gtk_tree_view_new_with_model(GTK_TREE_MODEL(store
)));
379 g_object_unref(G_OBJECT(store
));
380 gtk_tree_view_set_headers_visible(view
, FALSE
);
382 cell_renderer
= gtk_cell_renderer_text_new();
383 g_object_set(G_OBJECT(cell_renderer
), "xalign", 1.0, NULL
);
384 gtk_tree_view_insert_column_with_attributes(view
,
385 0, NULL
, cell_renderer
, "text", 0, NULL
);
387 cell_renderer
= gtk_cell_renderer_text_new();
388 gtk_tree_view_insert_column_with_attributes(view
,
389 1, NULL
, cell_renderer
, "text", 1, "editable", 2, NULL
);
392 g_signal_connect(G_OBJECT(cell_renderer
), "edited",
393 G_CALLBACK(cell_edited
), store
);
396 g_signal_connect(view
, "cursor_changed",
397 G_CALLBACK(set_selection
), NULL
);
400 *list_view
= (GtkWidget
*) view
;
403 static void set_cell(GtkListStore
*store
, const gchar
*path
,
408 gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(store
),
410 gtk_list_store_set(store
, &iter
, 1, ctext
, -1);
413 static void insert_size(DU
*du
, const char *line
)
418 #ifdef LARGE_FILE_SUPPORT
419 size
= strtoll(line
, NULL
, 10);
421 size
= strtol(line
, NULL
, 10);
423 size
<<= 10; /* Because du reports in K */
424 cell
= (size
>= PRETTY_SIZE_LIMIT
)
425 ? g_strdup_printf("%s (%" SIZE_FMT
" %s)",
428 : g_strdup(format_size(size
));
430 set_cell(du
->store
, du
->path
, cell
);
435 static gboolean
read_du_output(GIOChannel
*source
, GIOCondition cond
, DU
*du
)
441 line
= g_string_new("");
442 stat
= g_io_channel_read_line_string(source
, line
, NULL
, &err
);
445 case G_IO_STATUS_NORMAL
:
446 insert_size(du
, line
->str
);
448 case G_IO_STATUS_EOF
:
449 set_cell(du
->store
, du
->path
,
450 _("Failed to read size"));
452 case G_IO_STATUS_AGAIN
:
453 g_string_free(line
, TRUE
);
455 case G_IO_STATUS_ERROR
:
456 set_cell(du
->store
, du
->path
, err
->message
);
459 g_string_free(line
, TRUE
);
464 static void kill_du_output(GtkWidget
*widget
, DU
*du
)
466 g_source_remove(du
->watch
);
467 g_io_channel_shutdown(du
->chan
, FALSE
, NULL
);
468 g_io_channel_unref(du
->chan
);
469 kill((pid_t
) du
->child
, SIGTERM
);
470 g_object_unref(G_OBJECT(du
->store
));
475 static gboolean
refresh_info_idle(gpointer data
)
477 GObject
*window
= G_OBJECT(data
);
479 refresh_info(window
);
480 g_object_unref(window
);
484 static void cell_edited(GtkCellRendererText
*cell
,
485 const gchar
*path_string
,
486 const gchar
*new_text
,
489 GtkTreeModel
*model
= (GtkTreeModel
*) data
;
493 const char *fullpath
;
496 window
= g_object_get_data(G_OBJECT(model
), "rox_window");
497 g_return_if_fail(window
!= NULL
);
499 fullpath
= g_object_get_data(window
, "path");
500 g_return_if_fail(fullpath
!= NULL
);
502 path
= gtk_tree_path_new_from_string(path_string
);
503 gtk_tree_model_get_iter(model
, &iter
, path
);
504 gtk_tree_path_free(path
);
506 oldlink
= readlink_dup(fullpath
);
508 /* Must use delayed_error(), as this can be called
509 * from a focus-out event (causes a crash).
511 delayed_error(_("'%s' is no longer a symlink"), fullpath
);
514 if (strcmp(oldlink
, new_text
) == 0)
515 return; /* No change */
517 if (unlink(fullpath
)) {
518 delayed_error(_("Failed to unlink '%s':\n%s"),
519 fullpath
, g_strerror(errno
));
522 if (symlink(new_text
, fullpath
)) {
523 delayed_error(_("Failed to create symlink from '%s':\n%s\n"
524 "(note: old link has been deleted)"),
525 fullpath
, g_strerror(errno
));
529 g_object_ref(window
);
530 g_idle_add(refresh_info_idle
, window
);
533 /* Create the TreeView widget with the file's details */
534 static GtkWidget
*make_details(const guchar
*path
, DirItem
*item
,
541 make_list(&store
, &view
, G_CALLBACK(cell_edited
));
542 g_object_set_data(G_OBJECT(store
), "rox_window", window
);
544 /* For a symlink to an error, don't show the error */
545 if (item
->base_type
== TYPE_ERROR
&& item
->lstat_errno
)
547 add_row(store
, _("Error:"), g_strerror(item
->lstat_errno
));
551 tmp
= g_path_get_dirname(path
);
553 if (strcmp(tmp
, tmp2
) != 0)
554 add_row_and_free(store
, _("Real directory:"), tmp2
);
557 add_row_and_free(store
, _("Owner, Group:"),
558 g_strdup_printf("%s, %s",
559 user_name(item
->uid
),
560 group_name(item
->gid
)));
562 if (item
->base_type
!= TYPE_DIRECTORY
)
564 add_row_and_free(store
, _("Size:"),
565 item
->size
>= PRETTY_SIZE_LIMIT
566 ? g_strdup_printf("%s (%" SIZE_FMT
" %s)",
567 format_size(item
->size
),
568 item
->size
, _("bytes"))
569 : g_strdup(format_size(item
->size
)));
575 if(item
->flags
& ITEM_FLAG_MOUNTED
)
576 stt
=mount_get_fs_size(path
);
579 add_row_and_free(store
, _("Size:"), stt
);
584 gchar
*args
[] = {"du", "-sk", "", NULL
};
588 du
->path
= g_strdup(add_row(store
, _("Size:"),
591 args
[2] = (gchar
*) path
;
592 if (g_spawn_async_with_pipes(NULL
, args
, NULL
,
594 NULL
, NULL
, &du
->child
,
598 du
->chan
= g_io_channel_unix_new(out
);
599 /* Select binary encoding so we don't get an
600 * error with non-UTF-8 filenames.
602 g_io_channel_set_encoding(du
->chan
, NULL
, NULL
);
603 du
->watch
= g_io_add_watch(du
->chan
,
604 G_IO_IN
|G_IO_ERR
|G_IO_HUP
,
605 (GIOFunc
) read_du_output
, du
);
606 g_object_ref(G_OBJECT(du
->store
));
607 g_signal_connect(G_OBJECT(view
),
609 G_CALLBACK(kill_du_output
),
614 set_cell(store
, du
->path
, _("Failed to scan"));
621 add_row_and_free(store
, _("Change time:"), pretty_time(&item
->ctime
));
623 add_row_and_free(store
, _("Modify time:"), pretty_time(&item
->mtime
));
625 add_row_and_free(store
, _("Access time:"), pretty_time(&item
->atime
));
627 add_row(store
, _("Type:"), pretty_type(item
, path
));
630 add_row(store
, "", mime_type_comment(item
->mime_type
));
632 if (xattr_supported(NULL
)) {
633 add_row(store
, _("Extended attributes:"),
634 (item
->flags
& ITEM_FLAG_HAS_XATTR
)
636 : xattr_supported(path
) ? _("None")
637 : _("Not supported"));
640 if (item
->flags
& ITEM_FLAG_SYMLINK
)
643 GtkTreeModel
*model
= GTK_TREE_MODEL(store
);
646 target
= readlink_dup(path
);
648 target
= g_strdup(g_strerror(errno
));
649 add_row_and_free(store
, _("Link target:"), target
);
651 /* Make cell editable */
652 gtk_tree_model_iter_nth_child(model
, &iter
,
653 NULL
, gtk_tree_model_iter_n_children(model
, NULL
) - 1);
655 gtk_list_store_set(store
, &iter
, 2, TRUE
, -1);
658 if (item
->base_type
!= TYPE_DIRECTORY
)
660 if (EXECUTABLE_FILE(item
))
661 add_row(store
, _("Run action:"), _("Execute file"));
664 add_row_and_free(store
, _("Run action:"),
665 describe_current_command(item
->mime_type
));
672 /* Create the TreeView widget with the application's details */
673 static GtkWidget
*make_about(const guchar
*path
, XMLwrapper
*ai
)
678 xmlNode
*about
, *about_trans
;
679 GHashTable
*translate
;
681 g_return_val_if_fail(ai
!= NULL
, NULL
);
683 about_trans
= xml_get_section(ai
, NULL
, "About");
685 about
= xmlDocGetRootElement(ai
->doc
)->xmlChildrenNode
;
686 for (; about
; about
= about
->next
)
688 if (about
->type
!= XML_ELEMENT_NODE
)
690 if (about
->ns
== NULL
&& strcmp(about
->name
, "About") == 0)
694 g_return_val_if_fail(about
!= NULL
, NULL
);
696 make_list(&store
, &view
, NULL
);
698 /* Add each field in about to the list, but overriding each element
699 * with about_trans if a translation is supplied.
701 translate
= g_hash_table_new(g_str_hash
, g_str_equal
);
702 if (about_trans
!= about
)
705 for (p
= about_trans
->xmlChildrenNode
; p
; p
= p
->next
)
707 if (p
->type
!= XML_ELEMENT_NODE
)
709 g_hash_table_insert(translate
, (char *) p
->name
, p
);
712 for (prop
= about
->xmlChildrenNode
; prop
; prop
= prop
->next
)
714 if (prop
->type
== XML_ELEMENT_NODE
)
721 trans
= g_hash_table_lookup(translate
, prop
->name
);
725 tmp
= xmlGetProp(trans
, "label");
726 label
= g_strconcat(tmp
? tmp
727 : (char *) trans
->name
,
730 value
= xmlNodeListGetString(trans
->doc
,
731 trans
->xmlChildrenNode
, 1);
733 value
= xmlNodeListGetString(prop
->doc
,
734 prop
->xmlChildrenNode
, 1);
736 value
= g_strdup("-");
737 add_row_and_free(store
, label
, value
);
742 g_hash_table_destroy(translate
);
747 /* Create the TreeView widget with the desktop entry's details */
748 static GtkWidget
*make_about_desktop(const gchar
*path
)
753 gchar
*name
=NULL
, *comment
=NULL
, *exec
=NULL
;
755 make_list(&store
, &view
, NULL
);
757 if(!get_values_from_desktop_file(path
, &error
,
758 "Desktop Entry", "Name", &name
,
759 "Desktop Entry", "Comment", &comment
,
760 "Desktop Entry", "Exec", &exec
,
764 delayed_error("%s", error
->message
);
771 add_row_and_free(store
, _("Name"), name
);
773 add_row_and_free(store
, _("Comment"), comment
);
775 add_row_and_free(store
, _("Execute"), exec
);
780 static GtkWidget
*make_file_says(const guchar
*path
)
782 GtkWidget
*w_file_label
;
783 GtkLabel
*l_file_label
;
785 char *argv
[] = {"file", "-b", NULL
, NULL
};
786 FileStatus
*fs
= NULL
;
789 w_file_label
= gtk_label_new(_("<nothing yet>"));
790 l_file_label
= GTK_LABEL(w_file_label
);
791 gtk_label_set_line_wrap(l_file_label
, TRUE
);
792 gtk_label_set_selectable(l_file_label
, TRUE
);
796 tmp
= g_strdup_printf("pipe(): %s", g_strerror(errno
));
797 gtk_label_set_text(l_file_label
, tmp
);
805 tmp
= g_strdup_printf("pipe(): %s", g_strerror(errno
));
806 gtk_label_set_text(l_file_label
, tmp
);
812 /* We are the child */
814 dup2(file_data
[1], STDOUT_FILENO
);
815 dup2(file_data
[1], STDERR_FILENO
);
817 argv
[2] = (char *) path
;
819 argv
[1] = (char *) g_basename(path
);
820 chdir(g_path_get_dirname(path
));
822 if (execvp(argv
[0], argv
))
823 fprintf(stderr
, "execvp() error: %s\n",
827 /* We are the parent */
829 fs
= g_new(FileStatus
, 1);
830 fs
->label
= l_file_label
;
831 fs
->fd
= file_data
[0];
832 fs
->text
= g_strdup("");
833 fs
->input
= gdk_input_add_full(fs
->fd
, GDK_INPUT_READ
,
834 (GdkInputFunction
) add_file_output
,
836 g_signal_connect(w_file_label
, "destroy",
837 G_CALLBACK(file_info_destroyed
), fs
);
844 /* Got some data from file(1) - stick it in the window. */
845 static void add_file_output(FileStatus
*fs
,
846 gint source
, GdkInputCondition condition
)
852 got
= read(source
, buffer
, sizeof(buffer
) - 1);
856 g_source_remove(fs
->input
);
860 delayed_error(_("file(1) says... %s"),
866 str
= g_strconcat(fs
->text
, buffer
, NULL
);
870 str
= to_utf8(fs
->text
);
872 gtk_label_set_text(fs
->label
, str
);
876 static void file_info_destroyed(GtkWidget
*widget
, FileStatus
*fs
)
880 g_source_remove(fs
->input
);
888 static void permissions_destroyed(GtkWidget
*widget
, Permissions
*perm
)
891 diritem_free(perm
->item
);
896 static void permissions_apply(GtkWidget
*widget
, Permissions
*perm
)
903 for (i
= 0; i
< 9; i
++)
905 GtkToggleButton
*bit
= GTK_TOGGLE_BUTTON(perm
->bits
[i
]);
906 if (gtk_toggle_button_get_active(bit
))
909 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(perm
->bits
[9])))
911 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(perm
->bits
[10])))
913 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(perm
->bits
[11])))
916 if (chmod(perm
->path
, nmode
))
917 report_error(_("Could not change permissions: %s"),
921 static GtkWidget
*make_permissions(const gchar
*path
, DirItem
*item
)
925 GtkWidget
*tick
, *label
;
928 perm
= g_new(Permissions
, 1);
930 perm
->path
= g_strdup(path
);
931 perm
->item
= diritem_new(path
);
933 table
= gtk_table_new(4, 5, TRUE
);
935 label
= gtk_label_new(_("Owner"));
936 gtk_table_attach_defaults(GTK_TABLE(table
), label
, 0, 1, 1, 2);
937 label
= gtk_label_new(_("Group"));
938 gtk_table_attach_defaults(GTK_TABLE(table
), label
, 0, 1, 2, 3);
939 label
= gtk_label_new(_("World"));
940 gtk_table_attach_defaults(GTK_TABLE(table
), label
, 0, 1, 3, 4);
942 label
= gtk_label_new(_("Read"));
943 gtk_table_attach_defaults(GTK_TABLE(table
), label
, 1, 2, 0, 1);
944 label
= gtk_label_new(_("Write"));
945 gtk_table_attach_defaults(GTK_TABLE(table
), label
, 2, 3, 0, 1);
946 label
= gtk_label_new(_("Exec"));
947 gtk_table_attach_defaults(GTK_TABLE(table
), label
, 3, 4, 0, 1);
949 for (i
= 0; i
< 9; i
++)
953 perm
->bits
[i
] = tick
= gtk_check_button_new();
954 gtk_table_attach_defaults(GTK_TABLE(table
), tick
,
956 if (item
->mode
& (1 << i
))
957 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(tick
),
959 g_signal_connect(tick
, "toggled",
960 G_CALLBACK(permissions_apply
), perm
);
963 tick
= gtk_check_button_new_with_label(_("SUID"));
964 gtk_table_attach_defaults(GTK_TABLE(table
), tick
, 4, 5, 1, 2);
965 if (item
->mode
& S_ISUID
)
966 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(tick
), TRUE
);
967 g_signal_connect(tick
, "toggled", G_CALLBACK(permissions_apply
), perm
);
968 perm
->bits
[9] = tick
;
970 tick
= gtk_check_button_new_with_label(_("SGID"));
971 gtk_table_attach_defaults(GTK_TABLE(table
), tick
, 4, 5, 2, 3);
972 if (item
->mode
& S_ISGID
)
973 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(tick
), TRUE
);
974 g_signal_connect(tick
, "toggled", G_CALLBACK(permissions_apply
), perm
);
975 perm
->bits
[10] = tick
;
977 tick
= gtk_check_button_new_with_label(_("Sticky"));
978 gtk_table_attach_defaults(GTK_TABLE(table
), tick
, 4, 5, 3, 4);
979 if (item
->mode
& S_ISVTX
)
980 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(tick
), TRUE
);
981 g_signal_connect(tick
, "toggled", G_CALLBACK(permissions_apply
), perm
);
982 perm
->bits
[11] = tick
;
984 g_signal_connect(table
, "destroy",
985 G_CALLBACK(permissions_destroyed
), perm
);
987 gtk_widget_show_all(table
);
991 /* Don't g_free() the result */
992 static const gchar
*pretty_type(DirItem
*file
, const guchar
*path
)
994 static gchar
*text
= NULL
;
998 if (file
->flags
& ITEM_FLAG_SYMLINK
)
999 return _("Symbolic link");
1001 if (file
->flags
& ITEM_FLAG_APPDIR
)
1002 return _("ROX application");
1004 if (file
->flags
& ITEM_FLAG_MOUNT_POINT
)
1007 const gchar
*mounted
;
1009 mounted
= mount_is_mounted(path
, NULL
, NULL
)
1010 ? _("mounted") : _("unmounted");
1012 mp
= g_hash_table_lookup(fstab_mounts
, path
);
1014 text
= g_strdup_printf(_("Mount point for %s (%s)"),
1017 text
= g_strdup_printf(_("Mount point (%s)"), mounted
);
1021 if (file
->mime_type
)
1023 text
= g_strconcat(file
->mime_type
->media_type
, "/",
1024 file
->mime_type
->subtype
, NULL
);