r3082: Bugfix: If no pinboard or panel icons were present, the menu could not be
[rox-filer.git] / ROX-Filer / src / infobox.c
blobdd2c1b0cfafe8c8366788ede56eb0a9e5d6a31d5
1 /*
2 * $Id$
4 * ROX-Filer, filer for the ROX desktop project
5 * Copyright (C) 2003, the ROX-Filer team.
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2 of the License, or (at your option)
10 * any later version.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19 * Place, Suite 330, Boston, MA 02111-1307 USA
22 /* infobox.c - code for showing a file's attributes */
24 #include "config.h"
26 #include <errno.h>
27 #include <stdio.h>
28 #include <string.h>
29 #include <sys/param.h>
30 #include <libxml/parser.h>
32 #include <gtk/gtk.h>
34 #include "global.h"
36 #include "support.h"
37 #include "main.h"
38 #include "gui_support.h"
39 #include "diritem.h"
40 #include "type.h"
41 #include "infobox.h"
42 #include "appinfo.h"
43 #include "dnd.h" /* For xa_string */
44 #include "run.h" /* For show_help_files() */
45 #include "xml.h"
46 #include "mount.h"
47 #include "pixmaps.h"
49 typedef struct _FileStatus FileStatus;
51 /* This is for the 'file(1) says...' thing */
52 struct _FileStatus
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 */
60 typedef struct du {
61 gchar *path;
62 GtkListStore *store;
63 guint watch;
64 GIOChannel *chan;
65 } DU;
67 typedef struct _Permissions Permissions;
69 struct _Permissions
71 gchar *path;
72 DirItem *item;
73 GtkWidget *bits[12];
76 /* Static prototypes */
77 static void refresh_info(GObject *window);
78 static GtkWidget *make_vbox(const guchar *path);
79 static GtkWidget *make_details(const guchar *path, DirItem *item);
80 static GtkWidget *make_about(const guchar *path, XMLwrapper *ai);
81 static GtkWidget *make_file_says(const guchar *path);
82 static GtkWidget *make_permissions(const gchar *path, DirItem *item);
83 static void add_file_output(FileStatus *fs,
84 gint source, GdkInputCondition condition);
85 static const gchar *pretty_type(DirItem *file, const guchar *path);
86 static void got_response(GObject *window, gint response, gpointer data);
87 static void file_info_destroyed(GtkWidget *widget, FileStatus *fs);
89 /****************************************************************
90 * EXTERNAL INTERFACE *
91 ****************************************************************/
93 /* Open each item in a new infobox. Confirms if there are a large
94 * number of items to show.
96 void infobox_show_list(GList *paths)
98 int n;
100 n = g_list_length(paths);
102 if (n >= 10)
104 gchar *message;
105 gboolean ok;
107 message = g_strdup_printf(
108 _("Are you sure you want to open %d windows?"), n);
109 ok = confirm(message, GTK_STOCK_YES, _("Show Info"));
110 g_free(message);
111 if (!ok)
112 return;
115 g_list_foreach(paths, (GFunc) infobox_new, NULL);
118 /* Create and display a new info box showing details about this item */
119 void infobox_new(const gchar *pathname)
121 GtkWidget *window, *details;
122 gchar *path;
123 GObject *owindow;
125 g_return_if_fail(pathname != NULL);
127 path = g_strdup(pathname); /* Gets attached to window & freed later */
129 window = gtk_dialog_new_with_buttons(
130 g_utf8_validate(path, -1, NULL) ? path
131 : _("(bad utf-8)"),
132 NULL, GTK_DIALOG_NO_SEPARATOR,
133 GTK_STOCK_CANCEL, GTK_RESPONSE_DELETE_EVENT,
134 GTK_STOCK_REFRESH, GTK_RESPONSE_APPLY,
135 NULL);
137 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_MOUSE);
139 details = make_vbox(path);
140 gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(window)->vbox),
141 details);
143 owindow = G_OBJECT(window);
144 g_object_set_data(owindow, "details", details);
145 g_object_set_data_full(owindow, "path", path, g_free);
147 g_signal_connect(window, "response", G_CALLBACK(got_response), NULL);
149 number_of_windows++;
150 gtk_widget_show_all(window);
153 /****************************************************************
154 * INTERNAL FUNCTIONS *
155 ****************************************************************/
157 static void got_response(GObject *window, gint response, gpointer data)
159 if (response == GTK_RESPONSE_APPLY)
160 refresh_info(window);
161 else
163 gtk_widget_destroy(GTK_WIDGET(window));
164 one_less_window();
168 static void refresh_info(GObject *window)
170 GtkWidget *details, *vbox;
171 guchar *path;
173 path = g_object_get_data(window, "path");
174 details = g_object_get_data(window, "details");
175 g_return_if_fail(details != NULL);
176 g_return_if_fail(path != NULL);
178 vbox = details->parent;
179 gtk_widget_destroy(details);
181 details = make_vbox(path);
182 g_object_set_data(window, "details", details);
183 gtk_box_pack_start_defaults(GTK_BOX(vbox), details);
184 gtk_widget_show_all(details);
187 static void add_frame(GtkBox *vbox, GtkWidget *list)
189 GtkWidget *frame;
191 frame = gtk_frame_new(NULL);
192 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN);
193 gtk_container_add(GTK_CONTAINER(frame), list);
194 gtk_box_pack_start_defaults(vbox, frame);
197 /* Create the VBox widget that contains the details.
198 * Note that 'path' must not be freed until the vbox is destroyed.
200 static GtkWidget *make_vbox(const guchar *path)
202 DirItem *item;
203 GtkBox *vbox;
204 XMLwrapper *ai;
205 xmlNode *about = NULL;
206 gchar *help_dir;
207 GtkWidget *hbox, *name, *label;
209 g_return_val_if_fail(path[0] == '/', NULL);
211 item = diritem_new(g_basename(path));
212 diritem_restat(path, item, NULL);
214 ai = appinfo_get(path, item);
215 if (ai)
216 about = xml_get_section(ai, NULL, "About");
218 vbox = GTK_BOX(gtk_vbox_new(FALSE, 4));
219 gtk_container_set_border_width(GTK_CONTAINER(vbox), 4);
221 /* Heading, with icon and name */
222 hbox = gtk_hbox_new(FALSE, 4);
223 gtk_box_pack_start(vbox, hbox, FALSE, TRUE, 0);
224 gtk_box_pack_start(GTK_BOX(hbox),
225 gtk_image_new_from_pixbuf(item->image->pixbuf),
226 FALSE, FALSE, 4);
228 if (g_utf8_validate(item->leafname, -1, NULL))
229 name = gtk_label_new(item->leafname);
230 else
232 guchar *u8;
234 u8 = to_utf8(item->leafname);
235 name = gtk_label_new(u8);
236 g_free(u8);
238 gtk_label_set_selectable(GTK_LABEL(name), TRUE);
239 gtk_box_pack_start(GTK_BOX(hbox), name, FALSE, TRUE, 4);
241 /* Make the name bolder and larger */
243 PangoAttribute *attr;
244 PangoAttrList *list;
246 list = pango_attr_list_new();
248 attr = pango_attr_weight_new(PANGO_WEIGHT_BOLD);
249 attr->start_index = 0;
250 attr->end_index = -1;
251 pango_attr_list_insert(list, attr);
253 attr = pango_attr_scale_new(PANGO_SCALE_X_LARGE);
254 attr->start_index = 0;
255 attr->end_index = -1;
256 pango_attr_list_insert(list, attr);
258 gtk_label_set_attributes(GTK_LABEL(name), list);
261 /* List of file attributes */
262 add_frame(vbox, make_details(path, item));
264 help_dir = g_strconcat(path, "/Help", NULL);
266 if (access(help_dir, F_OK) == 0)
268 GtkWidget *button, *align;
270 align = gtk_alignment_new(0.5, 0.5, 0, 0);
272 button = button_new_mixed(GTK_STOCK_JUMP_TO,
273 _("Show _Help Files"));
274 gtk_box_pack_start(vbox, align, FALSE, TRUE, 0);
275 gtk_container_add(GTK_CONTAINER(align), button);
276 g_signal_connect_swapped(button, "clicked",
277 G_CALLBACK(show_help_files),
278 (gpointer) path);
280 g_free(help_dir);
282 label = gtk_label_new(NULL);
283 gtk_label_set_markup(GTK_LABEL(label), _("<b>Permissions</b>"));
284 gtk_misc_set_alignment(GTK_MISC(label), 0, 1);
285 gtk_box_pack_start(vbox, label, FALSE, TRUE, 2);
287 gtk_box_pack_start(vbox, make_permissions(path, item),
288 FALSE, TRUE, 0);
290 if (about)
291 add_frame(vbox, make_about(path, ai));
292 else if (item->base_type == TYPE_FILE)
294 label = gtk_label_new(NULL);
295 gtk_label_set_markup(GTK_LABEL(label),
296 _("<b>Contents indicate...</b>"));
297 gtk_misc_set_alignment(GTK_MISC(label), 0, 1);
298 gtk_box_pack_start(vbox, label, FALSE, TRUE, 2);
300 gtk_box_pack_start_defaults(vbox, make_file_says(path));
303 if (ai)
304 g_object_unref(ai);
306 diritem_free(item);
308 return (GtkWidget *) vbox;
311 /* The selection has changed - grab or release the primary selection */
312 static void set_selection(GtkTreeView *view, gpointer data)
314 static GtkClipboard *primary = NULL;
315 GtkTreeModel *model;
316 GtkTreePath *path = NULL;
317 GtkTreeIter iter;
318 gchar *text;
320 gtk_tree_view_get_cursor(view, &path, NULL);
321 if (!path)
322 return;
324 if (!primary)
325 primary = gtk_clipboard_get(gdk_atom_intern("PRIMARY", FALSE));
327 model = gtk_tree_view_get_model(GTK_TREE_VIEW(view));
329 gtk_tree_model_get_iter(model, &iter, path);
330 gtk_tree_path_free(path);
332 gtk_tree_model_get(model, &iter, 1, &text, -1);
334 gtk_clipboard_set_text(primary, text, -1);
336 g_free(text);
339 static gchar *add_row(GtkListStore *store, const gchar *label,
340 const gchar *data)
342 GtkTreeIter iter;
343 gchar *u8 = NULL;
344 GtkTreePath *tpath;
345 gchar *last=NULL;
347 if (!g_utf8_validate(data, -1, NULL))
348 u8 = to_utf8(data);
350 gtk_list_store_append(store, &iter);
351 gtk_list_store_set(store, &iter, 0, label, 1, u8 ? u8 : data, -1);
353 g_free(u8);
355 tpath=gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter);
356 if(last)
357 g_free(last);
358 last=gtk_tree_path_to_string(tpath);
359 gtk_tree_path_free(tpath);
361 return last;
364 static void add_row_and_free(GtkListStore *store,
365 const gchar *label, gchar *data)
367 add_row(store, label, data);
368 g_free(data);
371 /* Create an empty list view, ready to place some data in */
372 static void make_list(GtkListStore **list_store, GtkWidget **list_view)
374 GtkListStore *store;
375 GtkTreeView *view;
376 GtkCellRenderer *cell_renderer;
378 store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING);
379 view = GTK_TREE_VIEW(
380 gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)));
381 g_object_unref(G_OBJECT(store));
382 gtk_tree_view_set_headers_visible(view, FALSE);
384 cell_renderer = gtk_cell_renderer_text_new();
385 g_object_set(G_OBJECT(cell_renderer), "xalign", 1.0, NULL);
386 gtk_tree_view_insert_column_with_attributes(view,
387 0, NULL, cell_renderer, "text", 0, NULL);
389 cell_renderer = gtk_cell_renderer_text_new();
390 gtk_tree_view_insert_column_with_attributes(view,
391 1, NULL, cell_renderer, "text", 1, NULL);
393 g_signal_connect(view, "cursor_changed",
394 G_CALLBACK(set_selection), NULL);
396 *list_store = store;
397 *list_view = (GtkWidget *) view;
400 static void set_cell(GtkListStore *store, const gchar *path,
401 const gchar *ctext)
403 GtkTreeIter iter;
405 gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(store),
406 &iter, path);
407 gtk_list_store_set(store, &iter, 1, ctext, -1);
410 static void insert_size(DU *du, const char *line)
412 off_t size;
413 gchar *cell;
415 #ifdef LARGE_FILE_SUPPORT
416 size=strtoll(line, NULL, 10);
417 #else
418 size=strtol(line, NULL, 10);
419 #endif
420 size<<=10; /* Because du reports in K */
421 cell=(size >= PRETTY_SIZE_LIMIT)?
422 g_strdup_printf("%s (%" SIZE_FMT " %s)",
423 format_size(size),
424 size, _("bytes"))
425 : g_strdup(format_size(size));
427 set_cell(du->store, du->path, cell);
429 g_free(cell);
432 static gboolean read_du_output(GIOChannel *source, GIOCondition cond,
433 DU *du)
435 GString *line;
436 GIOStatus stat;
437 GError *err=NULL;
439 line=g_string_new("");
440 stat=g_io_channel_read_line_string(source, line, NULL, &err);
441 switch(stat) {
442 case G_IO_STATUS_NORMAL:
443 insert_size(du, line->str);
444 break;
445 case G_IO_STATUS_EOF:
446 break;
447 case G_IO_STATUS_AGAIN:
448 g_string_free(line, TRUE);
449 return TRUE;
450 case G_IO_STATUS_ERROR:
451 set_cell(du->store, du->path, err->message);
452 break;
454 g_string_free(line, TRUE);
456 return FALSE;
459 static void kill_du_output(GtkWidget *widget, DU *du)
461 g_io_channel_unref(du->chan);
462 g_free(du->path);
463 g_free(du);
466 /* Create the TreeView widget with the file's details */
467 static GtkWidget *make_details(const guchar *path, DirItem *item)
469 GtkListStore *store;
470 GtkWidget *view;
471 gchar *tmp, *tmp2;
473 make_list(&store, &view);
475 if (item->base_type == TYPE_ERROR)
477 add_row(store, _("Error:"), g_strerror(item->lstat_errno));
478 return view;
481 tmp = g_path_get_dirname(path);
482 tmp2 = pathdup(tmp);
483 if (strcmp(tmp, tmp2) != 0)
484 add_row_and_free(store, _("Real directory:"), tmp2);
485 g_free(tmp);
487 add_row_and_free(store, _("Owner, Group:"),
488 g_strdup_printf("%s, %s",
489 user_name(item->uid),
490 group_name(item->gid)));
492 if (item->base_type != TYPE_DIRECTORY) {
493 add_row_and_free(store, _("Size:"),
494 item->size >= PRETTY_SIZE_LIMIT
495 ? g_strdup_printf("%s (%" SIZE_FMT " %s)",
496 format_size(item->size),
497 item->size, _("bytes"))
498 : g_strdup(format_size(item->size)));
499 } else {
500 DU *du=g_new(DU, 1);
501 int out;
502 gchar *args[]={"du", "-sk", "", NULL};
504 du->store=store;
505 du->path=g_strdup(add_row(store, _("Size:"), _("Scanning")));
507 args[2]=(gchar *) path;
508 if(g_spawn_async_with_pipes(NULL, args, NULL,
509 G_SPAWN_SEARCH_PATH,
510 NULL, NULL, NULL,
511 NULL, &out, NULL,
512 NULL)) {
513 du->chan=g_io_channel_unix_new(out);
514 du->watch=g_io_add_watch(du->chan, G_IO_IN,
515 (GIOFunc) read_du_output, du);
516 g_signal_connect(G_OBJECT(view), "destroy",
517 G_CALLBACK(kill_du_output), du);
518 } else {
519 set_cell(store, du->path, _("Failed to scan"));
520 g_free(du->path);
521 g_free(du);
525 add_row_and_free(store, _("Change time:"), pretty_time(&item->ctime));
527 add_row_and_free(store, _("Modify time:"), pretty_time(&item->mtime));
529 add_row_and_free(store, _("Access time:"), pretty_time(&item->atime));
531 add_row(store, _("Type:"), pretty_type(item, path));
533 if (item->mime_type)
534 add_row(store, "", mime_type_comment(item->mime_type));
536 if (item->base_type != TYPE_DIRECTORY)
537 add_row_and_free(store, _("Run action:"),
538 describe_current_command(item->mime_type));
540 return view;
543 /* Create the TreeView widget with the application's details */
544 static GtkWidget *make_about(const guchar *path, XMLwrapper *ai)
546 GtkListStore *store;
547 GtkWidget *view;
548 xmlNode *prop;
549 xmlNode *about, *about_trans;
550 GHashTable *translate;
552 g_return_val_if_fail(ai != NULL, NULL);
554 about_trans = xml_get_section(ai, NULL, "About");
556 about = xmlDocGetRootElement(ai->doc)->xmlChildrenNode;
557 for (; about; about = about->next)
559 if (about->type != XML_ELEMENT_NODE)
560 continue;
561 if (about->ns == NULL && strcmp(about->name, "About") == 0)
562 break;
565 g_return_val_if_fail(about != NULL, NULL);
567 make_list(&store, &view);
569 /* Add each field in about to the list, but overriding each element
570 * with about_trans if a translation is supplied.
572 translate = g_hash_table_new(g_str_hash, g_str_equal);
573 if (about_trans != about)
575 xmlNode *p;
576 for (p = about_trans->xmlChildrenNode; p; p = p->next)
578 if (p->type != XML_ELEMENT_NODE)
579 continue;
580 g_hash_table_insert(translate, (char *) p->name, p);
583 for (prop = about->xmlChildrenNode; prop; prop = prop->next)
585 if (prop->type == XML_ELEMENT_NODE)
587 char *label = NULL;
588 char *value = NULL;
589 char *tmp = NULL;
590 xmlNode *trans;
592 trans = g_hash_table_lookup(translate, prop->name);
593 if (!trans)
594 trans = prop;
596 tmp = xmlGetProp(trans, "label");
597 label = g_strconcat(tmp ? tmp
598 : (char *) trans->name,
599 ":", NULL);
600 g_free(tmp);
601 value = xmlNodeListGetString(trans->doc,
602 trans->xmlChildrenNode, 1);
603 if (!value)
604 value = xmlNodeListGetString(prop->doc,
605 prop->xmlChildrenNode, 1);
606 if (!value)
607 value = g_strdup("-");
608 add_row_and_free(store, label, value);
609 g_free(label);
613 g_hash_table_destroy(translate);
615 return view;
618 static GtkWidget *make_file_says(const guchar *path)
620 GtkWidget *w_file_label;
621 GtkLabel *l_file_label;
622 int file_data[2];
623 char *argv[] = {"file", "-b", NULL, NULL};
624 FileStatus *fs = NULL;
625 guchar *tmp;
627 w_file_label = gtk_label_new(_("<nothing yet>"));
628 l_file_label = GTK_LABEL(w_file_label);
629 gtk_label_set_line_wrap(l_file_label, TRUE);
631 if (pipe(file_data))
633 tmp = g_strdup_printf("pipe(): %s", g_strerror(errno));
634 gtk_label_set_text(l_file_label, tmp);
635 g_free(tmp);
636 return w_file_label;
639 switch (fork())
641 case -1:
642 tmp = g_strdup_printf("pipe(): %s", g_strerror(errno));
643 gtk_label_set_text(l_file_label, tmp);
644 g_free(tmp);
645 close(file_data[0]);
646 close(file_data[1]);
647 break;
648 case 0:
649 /* We are the child */
650 close(file_data[0]);
651 dup2(file_data[1], STDOUT_FILENO);
652 dup2(file_data[1], STDERR_FILENO);
653 #ifdef FILE_B_FLAG
654 argv[2] = (char *) path;
655 #else
656 argv[1] = (char *) g_basename(path);
657 chdir(g_path_get_dirname(path));
658 #endif
659 if (execvp(argv[0], argv))
660 fprintf(stderr, "execvp() error: %s\n",
661 g_strerror(errno));
662 _exit(0);
663 default:
664 /* We are the parent */
665 close(file_data[1]);
666 fs = g_new(FileStatus, 1);
667 fs->label = l_file_label;
668 fs->fd = file_data[0];
669 fs->text = g_strdup("");
670 fs->input = gtk_input_add_full(fs->fd, GDK_INPUT_READ,
671 (GdkInputFunction) add_file_output,
672 NULL, fs, NULL);
673 g_signal_connect(w_file_label, "destroy",
674 G_CALLBACK(file_info_destroyed), fs);
675 break;
678 return w_file_label;
681 /* Got some data from file(1) - stick it in the window. */
682 static void add_file_output(FileStatus *fs,
683 gint source, GdkInputCondition condition)
685 char buffer[20];
686 char *str;
687 int got;
689 got = read(source, buffer, sizeof(buffer) - 1);
690 if (got <= 0)
692 int err = errno;
693 gtk_input_remove(fs->input);
694 close(source);
695 fs->fd = -1;
696 if (got < 0)
697 delayed_error(_("file(1) says... %s"),
698 g_strerror(err));
699 return;
701 buffer[got] = '\0';
703 str = g_strconcat(fs->text, buffer, NULL);
704 g_free(fs->text);
705 fs->text = str;
707 str = to_utf8(fs->text);
708 g_strstrip(str);
709 gtk_label_set_text(fs->label, str);
710 g_free(str);
713 static void file_info_destroyed(GtkWidget *widget, FileStatus *fs)
715 if (fs->fd != -1)
717 gtk_input_remove(fs->input);
718 close(fs->fd);
721 g_free(fs->text);
722 g_free(fs);
725 static void permissions_destroyed(GtkWidget *widget, Permissions *perm)
727 g_free(perm->path);
728 g_free(perm->item);
730 g_free(perm);
733 static void permissions_apply(GtkWidget *widget, Permissions *perm)
735 mode_t nmode;
736 int i;
738 nmode=0;
740 for(i=0; i<9; i++) {
741 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(perm->bits[i])))
742 nmode|=(1<<i);
744 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(perm->bits[9])))
745 nmode|=S_ISUID;
746 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(perm->bits[10])))
747 nmode|=S_ISGID;
748 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(perm->bits[11])))
749 nmode|=S_ISVTX;
751 if(chmod(perm->path, nmode)) {
752 report_error(_("Could not change permissions: %s"),
753 strerror(errno));
757 static GtkWidget *make_permissions(const gchar *path, DirItem *item)
759 Permissions *perm;
760 GtkWidget *table;
761 GtkWidget *tick, *label;
762 int i, x, y;
764 perm=g_new(Permissions, 1);
766 perm->path=g_strdup(path);
767 perm->item=diritem_new(path);
769 table=gtk_table_new(4, 5, TRUE);
771 label=gtk_label_new(_("Owner"));
772 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 1, 2);
773 label=gtk_label_new(_("Group"));
774 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 2, 3);
775 label=gtk_label_new(_("World"));
776 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 3, 4);
778 label=gtk_label_new(_("Read"));
779 gtk_table_attach_defaults(GTK_TABLE(table), label, 1, 2, 0, 1);
780 label=gtk_label_new(_("Write"));
781 gtk_table_attach_defaults(GTK_TABLE(table), label, 2, 3, 0, 1);
782 label=gtk_label_new(_("Exec"));
783 gtk_table_attach_defaults(GTK_TABLE(table), label, 3, 4, 0, 1);
785 for(i=0; i<9; i++) {
786 x=1+2-i%3;
787 y=1+2-i/3;
788 perm->bits[i]=tick=gtk_check_button_new();
789 gtk_table_attach_defaults(GTK_TABLE(table), tick,
790 x, x+1, y, y+1);
791 if(item->mode & (1<<i))
792 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(tick),
793 TRUE);
794 g_signal_connect(tick, "toggled",
795 G_CALLBACK(permissions_apply ), perm);
798 tick=gtk_check_button_new_with_label(_("SUID"));
799 gtk_table_attach_defaults(GTK_TABLE(table), tick, 4, 5, 1, 2);
800 if(item->mode & S_ISUID)
801 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(tick), TRUE);
802 g_signal_connect(tick, "toggled",
803 G_CALLBACK(permissions_apply ), perm);
804 perm->bits[9]=tick;
806 tick=gtk_check_button_new_with_label(_("SGID"));
807 gtk_table_attach_defaults(GTK_TABLE(table), tick, 4, 5, 2, 3);
808 if(item->mode & S_ISGID)
809 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(tick), TRUE);
810 g_signal_connect(tick, "toggled",
811 G_CALLBACK(permissions_apply ), perm);
812 perm->bits[10]=tick;
814 tick=gtk_check_button_new_with_label(_("Sticky"));
815 gtk_table_attach_defaults(GTK_TABLE(table), tick, 4, 5, 3, 4);
816 if(item->mode & S_ISVTX)
817 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(tick), TRUE);
818 g_signal_connect(tick, "toggled",
819 G_CALLBACK(permissions_apply ), perm);
820 perm->bits[11]=tick;
822 g_signal_connect(table, "destroy",
823 G_CALLBACK(permissions_destroyed), perm);
825 gtk_widget_show_all(table);
826 return table;
829 /* Don't g_free() the result */
830 static const gchar *pretty_type(DirItem *file, const guchar *path)
832 static gchar *text = NULL;
834 null_g_free(&text);
836 if (file->flags & ITEM_FLAG_SYMLINK)
838 char *target;
840 target = readlink_dup(path);
841 if (target)
843 ensure_utf8(&target);
845 text = g_strdup_printf(_("Symbolic link to %s"),
846 target);
847 g_free(target);
848 return text;
851 return _("Symbolic link");
854 if (file->flags & ITEM_FLAG_APPDIR)
855 return _("ROX application");
857 if (file->flags & ITEM_FLAG_MOUNT_POINT)
859 MountPoint *mp;
860 const gchar *mounted;
862 mounted = mount_is_mounted(path, NULL, NULL)
863 ? _("mounted") : _("unmounted");
865 mp = g_hash_table_lookup(fstab_mounts, path);
866 if (mp)
867 text = g_strdup_printf(_("Mount point for %s (%s)"),
868 mp->name, mounted);
869 else
870 text = g_strdup_printf(_("Mount point (%s)"), mounted);
871 return text;
874 if (file->mime_type)
876 text = g_strconcat(file->mime_type->media_type, "/",
877 file->mime_type->subtype, NULL);
878 return text;
881 return "-";