4 * ROX-Filer, filer for the ROX desktop project
5 * Copyright (C) 2002, 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)
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
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 /* filer.c - code for handling filer windows */
33 #include <sys/param.h>
37 #include <gdk/gdkkeysyms.h>
41 #include "collection.h"
46 #include "gui_support.h"
57 #include "minibuffer.h"
64 #include "view_iface.h"
65 #include "view_collection.h"
67 static XMLwrapper
*groups
= NULL
;
69 FilerWindow
*window_with_focus
= NULL
;
70 GList
*all_filer_windows
= NULL
;
72 static FilerWindow
*window_with_primary
= NULL
;
74 /* Static prototypes */
75 static void attach(FilerWindow
*filer_window
);
76 static void detach(FilerWindow
*filer_window
);
77 static void filer_window_destroyed(GtkWidget
*widget
,
78 FilerWindow
*filer_window
);
79 static void update_display(Directory
*dir
,
82 FilerWindow
*filer_window
);
83 static void set_scanning_display(FilerWindow
*filer_window
, gboolean scanning
);
84 static gboolean
may_rescan(FilerWindow
*filer_window
, gboolean warning
);
85 static gboolean
minibuffer_show_cb(FilerWindow
*filer_window
);
86 static FilerWindow
*find_filer_window(const char *sym_path
, FilerWindow
*diff
);
87 static void filer_add_widgets(FilerWindow
*filer_window
);
88 static void filer_add_signals(FilerWindow
*filer_window
);
89 static void filer_size_for(FilerWindow
*filer_window
,
90 int w
, int h
, int n
, gboolean allow_shrink
);
92 static void set_selection_state(FilerWindow
*filer_window
, gboolean normal
);
93 static void filer_next_thumb(GObject
*window
, const gchar
*path
);
94 static void start_thumb_scanning(FilerWindow
*filer_window
);
95 static void filer_options_changed(void);
96 static void set_style_by_number_of_items(FilerWindow
*filer_window
);
98 static GdkCursor
*busy_cursor
= NULL
;
99 static GdkCursor
*crosshair
= NULL
;
101 /* Indicates whether the filer's display is different to the machine it
102 * is actually running on.
104 static gboolean not_local
= FALSE
;
106 static Option o_filer_change_size
, o_filer_change_size_num
;
107 static Option o_filer_size_limit
, o_short_flag_names
;
108 Option o_filer_auto_resize
, o_unique_filer_windows
;
110 void filer_init(void)
114 gchar
*dpyhost
, *tmp
;
116 option_add_int(&o_filer_size_limit
, "filer_size_limit", 75);
117 option_add_int(&o_filer_auto_resize
, "filer_auto_resize",
119 option_add_int(&o_unique_filer_windows
, "filer_unique_windows", 0);
121 option_add_int(&o_short_flag_names
, "filer_short_flag_names", FALSE
);
123 option_add_int(&o_filer_change_size
, "filer_change_size", TRUE
);
124 option_add_int(&o_filer_change_size_num
, "filer_change_size_num", 30);
126 option_add_notify(filer_options_changed
);
128 busy_cursor
= gdk_cursor_new(GDK_WATCH
);
129 crosshair
= gdk_cursor_new(GDK_CROSSHAIR
);
131 /* Is the display on the local machine, or are we being
132 * run remotely? See filer_set_title().
134 ohost
= our_host_name();
135 dpy
= gdk_get_display();
136 dpyhost
= g_strdup(dpy
);
137 tmp
= strchr(dpyhost
, ':');
141 if (dpyhost
[0] && strcmp(ohost
, dpyhost
) != 0)
143 /* Try the cannonical name for dpyhost (see our_host_name()
148 ent
= gethostbyname(dpyhost
);
149 if (!ent
|| strcmp(ohost
, ent
->h_name
) != 0)
156 static gboolean
if_deleted(gpointer item
, gpointer removed
)
158 int i
= ((GPtrArray
*) removed
)->len
;
159 DirItem
**r
= (DirItem
**) ((GPtrArray
*) removed
)->pdata
;
160 char *leafname
= ((DirItem
*) item
)->leafname
;
164 if (strcmp(leafname
, r
[i
]->leafname
) == 0)
171 /* Resize the filer window to w x h pixels, plus border (not clamped) */
172 static void filer_window_set_size(FilerWindow
*filer_window
,
174 gboolean allow_shrink
)
178 g_return_if_fail(filer_window
!= NULL
);
180 if (filer_window
->scrollbar
)
181 w
+= filer_window
->scrollbar
->allocation
.width
;
183 if (o_toolbar
.int_value
!= TOOLBAR_NONE
)
184 h
+= filer_window
->toolbar
->allocation
.height
;
185 if (filer_window
->message
)
186 h
+= filer_window
->message
->allocation
.height
;
188 window
= filer_window
->window
;
190 if (GTK_WIDGET_VISIBLE(window
))
193 GtkRequisition
*req
= &window
->requisition
;
194 GdkWindow
*gdk_window
= window
->window
;
196 w
= MAX(req
->width
, w
);
197 h
= MAX(req
->height
, h
);
198 gdk_window_get_position(gdk_window
, &x
, &y
);
204 gdk_drawable_get_size(gdk_window
, &old_w
, &old_h
);
208 if (w
== old_w
&& h
== old_h
)
212 if (x
+ w
> screen_width
|| y
+ h
> screen_height
)
214 if (x
+ w
> screen_width
)
215 x
= screen_width
- w
- 4;
216 if (y
+ h
> screen_height
)
217 y
= screen_height
- h
- 4;
218 gdk_window_move_resize(gdk_window
, x
, y
, w
, h
);
221 gdk_window_resize(gdk_window
, w
, h
);
224 gtk_window_set_default_size(GTK_WINDOW(window
), w
, h
);
227 /* Resize the window to fit the items currently in the Directory.
228 * This should be used once the Directory has been fully scanned, otherwise
229 * the window will appear too small. When opening a directory for the first
230 * time, the names will be known but not the types and images. We can
231 * still make a good estimate of the size.
233 void filer_window_autosize(FilerWindow
*filer_window
, gboolean allow_shrink
)
235 Collection
*collection
= filer_window
->collection
;
238 n
= collection
->number_of_items
;
241 filer_size_for(filer_window
,
242 collection
->item_width
,
243 collection
->item_height
,
247 /* Choose a good size for this window, assuming n items of size (w, h) */
248 static void filer_size_for(FilerWindow
*filer_window
,
249 int w
, int h
, int n
, gboolean allow_shrink
)
259 size_limit
= o_filer_size_limit
.int_value
;
261 /* Get the extra height required for the toolbar and minibuffer,
264 if (o_toolbar
.int_value
!= TOOLBAR_NONE
)
265 t
= filer_window
->toolbar
->allocation
.height
;
266 if (filer_window
->message
)
267 t
+= filer_window
->message
->allocation
.height
;
268 if (GTK_WIDGET_VISIBLE(filer_window
->minibuffer_area
))
272 gtk_widget_size_request(filer_window
->minibuffer_area
, &req
);
273 space
= req
.height
+ 2;
277 max_x
= (size_limit
* screen_width
) / 100;
278 max_rows
= (size_limit
* screen_height
) / (h
* 100);
280 /* Aim for a size where
281 * x = r(y + t + h), (1)
282 * unless that's too wide.
284 * t = toolbar (and minibuffer) height
285 * r = desired (width / height) ratio
287 * Want to display all items:
290 * => x(x/r - t - h) = nwh (from 1)
291 * => xx - x.rt - hr(1 - nw) = 0
292 * => 2x = rt +/- sqrt(rt.rt + 4hr(nw - 1))
296 * sqrt(rt.rt + ...) > rt
298 * So, the +/- must be +:
300 * => x = (rt + sqrt(rt.rt + 4hr(nw - 1))) / 2
302 * ( + w - 1 to round up)
304 x
= (r
* t
+ sqrt(r
*r
*t
*t
+ 4*h
*r
* (n
*w
- 1))) / 2 + w
- 1;
313 /* Choose rows to display all items given our chosen x.
314 * Don't make the window *too* big!
316 rows
= (n
+ cols
- 1) / cols
;
320 /* Leave some room for extra icons, but only in Small Icons mode
321 * otherwise it takes up too much space.
322 * Also, don't add space if the minibuffer is open.
325 space
= filer_window
->display_style
== SMALL_ICONS
? h
: 2;
327 filer_window_set_size(filer_window
,
329 h
* MAX(rows
, 1) + space
,
333 /* Called on a timeout while scanning or when scanning ends
334 * (whichever happens first).
336 static gint
open_filer_window(FilerWindow
*filer_window
)
338 view_style_changed(filer_window
->view
, 0);
340 if (filer_window
->open_timeout
)
342 gtk_timeout_remove(filer_window
->open_timeout
);
343 filer_window
->open_timeout
= 0;
346 if (!GTK_WIDGET_VISIBLE(filer_window
->window
))
348 set_style_by_number_of_items(filer_window
);
349 filer_window_autosize(filer_window
, TRUE
);
350 gtk_widget_show(filer_window
->window
);
356 static void update_display(Directory
*dir
,
359 FilerWindow
*filer_window
)
361 Collection
*collection
= filer_window
->collection
;
362 ViewIface
*view
= (ViewIface
*) filer_window
->view
;
367 view_add_items(view
, items
);
368 /* Open and resize if currently hidden */
369 open_filer_window(filer_window
);
372 view_delete_if(view
, if_deleted
, items
);
375 set_scanning_display(filer_window
, TRUE
);
376 toolbar_update_info(filer_window
);
379 if (filer_window
->window
->window
)
380 gdk_window_set_cursor(
381 filer_window
->window
->window
,
383 set_scanning_display(filer_window
, FALSE
);
384 toolbar_update_info(filer_window
);
385 open_filer_window(filer_window
);
387 if (filer_window
->had_cursor
&&
388 collection
->cursor_item
== -1)
390 collection_set_cursor_item(collection
, 0);
391 filer_window
->had_cursor
= FALSE
;
393 if (filer_window
->auto_select
)
394 display_set_autoselect(filer_window
,
395 filer_window
->auto_select
);
396 g_free(filer_window
->auto_select
);
397 filer_window
->auto_select
= NULL
;
399 filer_create_thumbs(filer_window
);
401 if (filer_window
->thumb_queue
)
402 start_thumb_scanning(filer_window
);
405 view_update_items(view
, items
);
410 static void attach(FilerWindow
*filer_window
)
412 gdk_window_set_cursor(filer_window
->window
->window
, busy_cursor
);
413 view_clear(filer_window
->view
);
414 filer_window
->scanning
= TRUE
;
415 dir_attach(filer_window
->directory
, (DirCallback
) update_display
,
417 filer_set_title(filer_window
);
420 static void detach(FilerWindow
*filer_window
)
422 g_return_if_fail(filer_window
->directory
!= NULL
);
424 dir_detach(filer_window
->directory
,
425 (DirCallback
) update_display
, filer_window
);
426 g_object_unref(filer_window
->directory
);
427 filer_window
->directory
= NULL
;
430 static void filer_window_destroyed(GtkWidget
*widget
,
431 FilerWindow
*filer_window
)
433 all_filer_windows
= g_list_remove(all_filer_windows
, filer_window
);
435 g_object_set_data(G_OBJECT(widget
), "filer_window", NULL
);
437 if (window_with_primary
== filer_window
)
438 window_with_primary
= NULL
;
440 if (window_with_focus
== filer_window
)
443 window_with_focus
= NULL
;
446 if (filer_window
->directory
)
447 detach(filer_window
);
449 if (filer_window
->open_timeout
)
451 gtk_timeout_remove(filer_window
->open_timeout
);
452 filer_window
->open_timeout
= 0;
455 if (filer_window
->thumb_queue
)
457 g_list_foreach(filer_window
->thumb_queue
, (GFunc
) g_free
, NULL
);
458 g_list_free(filer_window
->thumb_queue
);
463 g_free(filer_window
->auto_select
);
464 g_free(filer_window
->real_path
);
465 g_free(filer_window
->sym_path
);
466 g_free(filer_window
);
471 /* Returns TRUE iff the directory still exists. */
472 static gboolean
may_rescan(FilerWindow
*filer_window
, gboolean warning
)
476 g_return_val_if_fail(filer_window
!= NULL
, FALSE
);
478 /* We do a fresh lookup (rather than update) because the inode may
481 dir
= g_fscache_lookup(dir_cache
, filer_window
->real_path
);
485 info_message(_("Directory missing/deleted"));
486 gtk_widget_destroy(filer_window
->window
);
489 if (dir
== filer_window
->directory
)
493 detach(filer_window
);
494 filer_window
->directory
= dir
;
495 attach(filer_window
);
501 /* No items are now selected. This might be because another app claimed
502 * the selection or because the user unselected all the items.
504 void filer_lost_selection(FilerWindow
*filer_window
, gint time
)
506 if (window_with_primary
== filer_window
)
508 window_with_primary
= NULL
;
509 gtk_selection_owner_set(NULL
, GDK_SELECTION_PRIMARY
, time
);
513 /* Another app has claimed the primary selection */
514 void filer_lost_primary(FilerWindow
*filer_window
)
516 if (window_with_primary
&& window_with_primary
== filer_window
)
518 window_with_primary
= NULL
;
519 set_selection_state(filer_window
, FALSE
);
523 /* Someone wants us to send them the selection */
524 static void selection_get(GtkWidget
*widget
,
525 GtkSelectionData
*selection_data
,
530 GString
*reply
, *header
;
531 FilerWindow
*filer_window
;
535 filer_window
= g_object_get_data(G_OBJECT(widget
), "filer_window");
537 reply
= g_string_new(NULL
);
538 header
= g_string_new(NULL
);
543 g_string_sprintf(header
, " %s",
544 make_path(filer_window
->sym_path
, "")->str
);
546 case TARGET_URI_LIST
:
547 g_string_sprintf(header
, " file://%s%s",
548 our_host_name_for_dnd(),
549 make_path(filer_window
->sym_path
, "")->str
);
553 view_get_iter(filer_window
->view
, &iter
, VIEW_ITER_SELECTED
);
555 while ((item
= iter
.next(&iter
)))
557 g_string_append(reply
, header
->str
);
558 g_string_append(reply
, item
->leafname
);
562 gtk_selection_data_set(selection_data
, xa_string
,
563 8, reply
->str
+ 1, reply
->len
- 1);
566 g_warning("Attempt to paste empty selection!");
567 gtk_selection_data_set(selection_data
, xa_string
, 8, "", 0);
570 g_string_free(reply
, TRUE
);
571 g_string_free(header
, TRUE
);
574 void filer_selection_changed(FilerWindow
*filer_window
, gint time
)
576 /* Selection has been changed -- try to grab the primary selection
577 * if we don't have it.
579 if (window_with_primary
== filer_window
)
580 return; /* Already got it */
582 if (!filer_window
->collection
->number_selected
)
583 return; /* Nothing selected */
585 if (filer_window
->temp_item_selected
== FALSE
&&
586 gtk_selection_owner_set(GTK_WIDGET(filer_window
->collection
),
587 GDK_SELECTION_PRIMARY
,
590 window_with_primary
= filer_window
;
591 set_selection_state(filer_window
, TRUE
);
594 set_selection_state(filer_window
, FALSE
);
597 /* Open the item (or add it to the shell command minibuffer) */
598 void filer_openitem(FilerWindow
*filer_window
, int item_number
, OpenFlags flags
)
600 gboolean shift
= (flags
& OPEN_SHIFT
) != 0;
601 gboolean close_mini
= flags
& OPEN_FROM_MINI
;
602 gboolean close_window
= (flags
& OPEN_CLOSE_WINDOW
) != 0;
603 DirItem
*item
= (DirItem
*)
604 filer_window
->collection
->items
[item_number
].data
;
606 gboolean wink
= TRUE
;
609 if (filer_window
->mini_type
== MINI_SHELL
)
611 minibuffer_add(filer_window
, item
->leafname
);
616 dir_update_item(filer_window
->directory
, item
->leafname
);
618 if (item
->base_type
== TYPE_DIRECTORY
)
620 /* Never close a filer window when opening a directory
621 * (click on a dir or click on an app with shift).
623 if (shift
|| !(item
->flags
& ITEM_FLAG_APPDIR
))
624 close_window
= FALSE
;
627 full_path
= make_path(filer_window
->sym_path
, item
->leafname
)->str
;
628 if (shift
&& (item
->flags
& ITEM_FLAG_SYMLINK
))
631 old_dir
= filer_window
->directory
;
632 if (run_diritem(full_path
, item
,
633 flags
& OPEN_SAME_WINDOW
? filer_window
: NULL
,
637 if (old_dir
!= filer_window
->directory
)
641 gtk_widget_destroy(filer_window
->window
);
645 collection_wink_item(filer_window
->collection
,
648 minibuffer_hide(filer_window
);
653 static gint
pointer_in(GtkWidget
*widget
,
654 GdkEventCrossing
*event
,
655 FilerWindow
*filer_window
)
657 may_rescan(filer_window
, TRUE
);
661 static gint
pointer_out(GtkWidget
*widget
,
662 GdkEventCrossing
*event
,
663 FilerWindow
*filer_window
)
669 /* Move the cursor to the next selected item in direction 'dir'
672 static void next_selected(FilerWindow
*filer_window
, int dir
)
674 Collection
*collection
= filer_window
->collection
;
675 int to_check
= collection
->number_of_items
;
676 int item
= collection
->cursor_item
;
678 g_return_if_fail(dir
== 1 || dir
== -1);
680 if (to_check
> 0 && item
== -1)
682 /* Cursor not currently on */
686 item
= collection
->number_of_items
- 1;
688 if (collection
->items
[item
].selected
)
692 while (--to_check
> 0)
696 if (item
>= collection
->number_of_items
)
699 item
= collection
->number_of_items
- 1;
701 if (collection
->items
[item
].selected
)
708 collection_set_cursor_item(collection
, item
);
711 static void return_pressed(FilerWindow
*filer_window
, GdkEventKey
*event
)
713 Collection
*collection
= filer_window
->collection
;
714 int item
= collection
->cursor_item
;
715 TargetFunc cb
= filer_window
->target_cb
;
716 gpointer data
= filer_window
->target_data
;
717 OpenFlags flags
= OPEN_SAME_WINDOW
;
719 filer_target_mode(filer_window
, NULL
, NULL
, NULL
);
720 if (item
< 0 || item
>= collection
->number_of_items
)
725 cb(filer_window
, item
, data
);
729 if (event
->state
& GDK_SHIFT_MASK
)
732 filer_openitem(filer_window
, item
, flags
);
735 /* Makes sure that 'groups' is up-to-date, reloading from file if it has
736 * changed. If no groups were loaded and there is no file then initialised
737 * groups to an empty document.
738 * Return the node for the 'name' group.
740 static xmlNode
*group_find(char *name
)
745 /* Update the groups, if possible */
746 path
= choices_find_path_load("Groups.xml", PROJECT
);
750 wrapper
= xml_cache_load(path
);
754 g_object_unref(groups
);
763 groups
= xml_new(NULL
);
764 groups
->doc
= xmlNewDoc("1.0");
766 xmlDocSetRootElement(groups
->doc
,
767 xmlNewDocNode(groups
->doc
, NULL
, "groups", NULL
));
771 node
= xmlDocGetRootElement(groups
->doc
);
773 for (node
= node
->xmlChildrenNode
; node
; node
= node
->next
)
777 gid
= xmlGetProp(node
, "name");
782 if (strcmp(name
, gid
) != 0)
793 static void group_save(FilerWindow
*filer_window
, char *name
)
800 group
= group_find(name
);
803 xmlUnlinkNode(group
);
806 group
= xmlNewChild(xmlDocGetRootElement(groups
->doc
),
807 NULL
, "group", NULL
);
808 xmlSetProp(group
, "name", name
);
810 xmlNewChild(group
, NULL
, "directory", filer_window
->sym_path
);
812 view_get_iter(filer_window
->view
, &iter
, VIEW_ITER_SELECTED
);
814 while ((item
= iter
.next(&iter
)))
815 xmlNewChild(group
, NULL
, "item", item
->leafname
);
817 save_path
= choices_find_path_save("Groups.xml", PROJECT
, TRUE
);
820 save_xml_file(groups
->doc
, save_path
);
825 static void group_restore(FilerWindow
*filer_window
, char *name
)
827 GHashTable
*in_group
;
828 Collection
*collection
= filer_window
->collection
;
831 xmlNode
*group
, *node
;
833 group
= group_find(name
);
837 report_error(_("Group %s is not set. Select some files "
838 "and press Ctrl+%s to set the group. Press %s "
839 "on its own to reselect the files later."),
844 node
= get_subnode(group
, NULL
, "directory");
845 g_return_if_fail(node
!= NULL
);
846 path
= xmlNodeListGetString(groups
->doc
, node
->xmlChildrenNode
, 1);
847 g_return_if_fail(path
!= NULL
);
849 if (strcmp(path
, filer_window
->sym_path
) != 0)
850 filer_change_to(filer_window
, path
, NULL
);
853 /* If an item at the start is selected then we could lose the
854 * primary selection after checking that item and then need to
855 * gain it again at the end. Therefore, if anything is selected
856 * then select the last item until the end of the search.
858 n
= collection
->number_of_items
;
859 if (collection
->number_selected
)
860 collection_select_item(collection
, n
- 1);
862 in_group
= g_hash_table_new(g_str_hash
, g_str_equal
);
863 for (node
= group
->xmlChildrenNode
; node
; node
= node
->next
)
866 if (node
->type
!= XML_ELEMENT_NODE
)
868 if (strcmp(node
->name
, "item") != 0)
871 leaf
= xmlNodeListGetString(groups
->doc
,
872 node
->xmlChildrenNode
, 1);
874 g_warning("Missing leafname!\n");
876 g_hash_table_insert(in_group
, leaf
, filer_window
);
879 for (j
= 0; j
< n
; j
++)
881 DirItem
*item
= (DirItem
*) collection
->items
[j
].data
;
883 if (g_hash_table_lookup(in_group
, item
->leafname
))
884 collection_select_item(collection
, j
);
886 collection_unselect_item(collection
, j
);
889 g_hash_table_foreach(in_group
, (GHFunc
) g_free
, NULL
);
890 g_hash_table_destroy(in_group
);
893 /* Handle keys that can't be bound with the menu */
894 static gint
key_press_event(GtkWidget
*widget
,
896 FilerWindow
*filer_window
)
898 GtkWidget
*focus
= GTK_WINDOW(widget
)->focus_widget
;
899 guint key
= event
->keyval
;
902 window_with_focus
= filer_window
;
904 /* Delay setting up the keys until now to speed loading... */
906 ensure_filer_menu(); /* Gets the keys working... */
908 if (!g_slist_find(filer_keys
->acceleratables
, widget
))
909 gtk_window_add_accel_group(GTK_WINDOW(filer_window
->window
),
912 if (focus
&& focus
!= widget
&&
913 gtk_widget_get_toplevel(focus
) == widget
)
914 if (gtk_widget_event(focus
, (GdkEvent
*) event
))
915 return TRUE
; /* Handled */
920 filer_target_mode(filer_window
, NULL
, NULL
, NULL
);
923 return_pressed(filer_window
, event
);
925 case GDK_ISO_Left_Tab
:
926 next_selected(filer_window
, -1);
929 next_selected(filer_window
, 1);
932 change_to_parent(filer_window
);
936 show_filer_menu(filer_window
, (GdkEvent
*) event
,
937 filer_window
->collection
->cursor_item
);
940 if (key
>= GDK_0
&& key
<= GDK_9
)
941 group
[0] = key
- GDK_0
+ '0';
942 else if (key
>= GDK_KP_0
&& key
<= GDK_KP_9
)
943 group
[0] = key
- GDK_KP_0
+ '0';
948 if (event
->state
& GDK_CONTROL_MASK
)
949 group_save(filer_window
, group
);
951 group_restore(filer_window
, group
);
957 void filer_open_parent(FilerWindow
*filer_window
)
960 const char *current
= filer_window
->sym_path
;
962 if (current
[0] == '/' && current
[1] == '\0')
963 return; /* Already in the root */
965 dir
= g_dirname(current
);
966 filer_opendir(dir
, filer_window
);
970 void change_to_parent(FilerWindow
*filer_window
)
973 const char *current
= filer_window
->sym_path
;
975 if (current
[0] == '/' && current
[1] == '\0')
976 return; /* Already in the root */
978 dir
= g_dirname(current
);
979 filer_change_to(filer_window
, dir
, g_basename(current
));
983 /* Removes trailing /s from path (modified in place) */
984 static void tidy_sympath(gchar
*path
)
988 g_return_if_fail(path
!= NULL
);
991 while (l
> 1 && path
[l
- 1] == '/')
998 /* Make filer_window display path. When finished, highlight item 'from', or
999 * the first item if from is NULL. If there is currently no cursor then
1000 * simply wink 'from' (if not NULL).
1002 void filer_change_to(FilerWindow
*filer_window
,
1003 const char *path
, const char *from
)
1006 char *sym_path
, *real_path
;
1009 g_return_if_fail(filer_window
!= NULL
);
1011 filer_cancel_thumbnails(filer_window
);
1015 sym_path
= g_strdup(path
);
1016 real_path
= pathdup(path
);
1017 new_dir
= g_fscache_lookup(dir_cache
, real_path
);
1021 delayed_error(_("Directory '%s' is not accessible"),
1028 if (o_unique_filer_windows
.int_value
)
1032 fw
= find_filer_window(sym_path
, filer_window
);
1034 gtk_widget_destroy(fw
->window
);
1037 from_dup
= from
&& *from
? g_strdup(from
) : NULL
;
1039 detach(filer_window
);
1040 g_free(filer_window
->real_path
);
1041 g_free(filer_window
->sym_path
);
1042 filer_window
->real_path
= real_path
;
1043 filer_window
->sym_path
= sym_path
;
1044 tidy_sympath(filer_window
->sym_path
);
1046 filer_window
->directory
= new_dir
;
1048 g_free(filer_window
->auto_select
);
1049 filer_window
->had_cursor
= filer_window
->collection
->cursor_item
!= -1
1050 || filer_window
->had_cursor
;
1051 filer_window
->auto_select
= from_dup
;
1053 filer_set_title(filer_window
);
1054 if (filer_window
->window
->window
)
1055 gdk_window_set_role(filer_window
->window
->window
,
1056 filer_window
->sym_path
);
1057 collection_set_cursor_item(filer_window
->collection
, -1);
1059 attach(filer_window
);
1061 set_style_by_number_of_items(filer_window
);
1063 if (o_filer_auto_resize
.int_value
== RESIZE_ALWAYS
)
1064 filer_window_autosize(filer_window
, TRUE
);
1066 if (filer_window
->mini_type
== MINI_PATH
)
1067 gtk_idle_add((GtkFunction
) minibuffer_show_cb
,
1071 /* Returns a list containing the full (sym) pathname of every selected item.
1072 * You must g_free() each item in the list.
1074 GList
*filer_selected_items(FilerWindow
*filer_window
)
1076 GList
*retval
= NULL
;
1077 guchar
*dir
= filer_window
->sym_path
;
1081 view_get_iter(filer_window
->view
, &iter
, VIEW_ITER_SELECTED
);
1082 while ((item
= iter
.next(&iter
)))
1084 retval
= g_list_prepend(retval
,
1085 g_strdup(make_path(dir
, item
->leafname
)->str
));
1088 return g_list_reverse(retval
);
1091 DirItem
*filer_selected_item(FilerWindow
*filer_window
)
1093 Collection
*collection
= filer_window
->collection
;
1096 item
= collection_selected_item_number(collection
);
1099 return (DirItem
*) collection
->items
[item
].data
;
1103 /* Creates and shows a new filer window.
1104 * If src_win != NULL then display options can be taken from that source window.
1105 * Returns the new filer window, or NULL on error.
1106 * Note: if unique windows is in use, may return an existing window.
1108 FilerWindow
*filer_opendir(const char *path
, FilerWindow
*src_win
)
1110 FilerWindow
*filer_window
;
1112 DisplayStyle dstyle
;
1115 /* Get the real pathname of the directory and copy it */
1116 real_path
= pathdup(path
);
1118 if (o_unique_filer_windows
.int_value
)
1120 FilerWindow
*same_dir_window
;
1122 same_dir_window
= find_filer_window(path
, NULL
);
1124 if (same_dir_window
)
1126 gtk_window_present(GTK_WINDOW(same_dir_window
->window
));
1127 return same_dir_window
;
1131 filer_window
= g_new(FilerWindow
, 1);
1132 filer_window
->message
= NULL
;
1133 filer_window
->minibuffer
= NULL
;
1134 filer_window
->minibuffer_label
= NULL
;
1135 filer_window
->minibuffer_area
= NULL
;
1136 filer_window
->temp_show_hidden
= FALSE
;
1137 filer_window
->sym_path
= g_strdup(path
);
1138 filer_window
->real_path
= real_path
;
1139 filer_window
->scanning
= FALSE
;
1140 filer_window
->had_cursor
= FALSE
;
1141 filer_window
->auto_select
= NULL
;
1142 filer_window
->toolbar_text
= NULL
;
1143 filer_window
->target_cb
= NULL
;
1144 filer_window
->mini_type
= MINI_NONE
;
1145 filer_window
->selection_state
= GTK_STATE_INSENSITIVE
;
1146 filer_window
->toolbar
= NULL
;
1147 filer_window
->toplevel_vbox
= NULL
;
1149 tidy_sympath(filer_window
->sym_path
);
1151 /* Finds the entry for this directory in the dir cache, creating
1152 * a new one if needed. This does not cause a scan to start,
1153 * so if a new entry is created then it will be empty.
1155 filer_window
->directory
= g_fscache_lookup(dir_cache
, real_path
);
1156 if (!filer_window
->directory
)
1158 delayed_error(_("Directory '%s' not found."), path
);
1159 g_free(filer_window
->real_path
);
1160 g_free(filer_window
->sym_path
);
1161 g_free(filer_window
);
1165 filer_window
->temp_item_selected
= FALSE
;
1166 filer_window
->flags
= (FilerFlags
) 0;
1167 filer_window
->details_type
= DETAILS_SUMMARY
;
1168 filer_window
->display_style
= UNKNOWN_STYLE
;
1169 filer_window
->thumb_queue
= NULL
;
1170 filer_window
->max_thumbs
= 0;
1172 if (src_win
&& o_display_inherit_options
.int_value
)
1174 filer_window
->sort_fn
= src_win
->sort_fn
;
1175 dstyle
= src_win
->display_style
;
1176 dtype
= src_win
->details_type
;
1177 filer_window
->show_hidden
= src_win
->show_hidden
;
1178 filer_window
->show_thumbs
= src_win
->show_thumbs
;
1182 int i
= o_display_sort_by
.int_value
;
1183 filer_window
->sort_fn
= i
== 0 ? sort_by_name
:
1184 i
== 1 ? sort_by_type
:
1185 i
== 2 ? sort_by_date
:
1188 dstyle
= o_display_size
.int_value
;
1189 dtype
= o_display_details
.int_value
;
1190 filer_window
->show_hidden
=
1191 o_display_show_hidden
.int_value
;
1192 filer_window
->show_thumbs
=
1193 o_display_show_thumbs
.int_value
;
1196 /* Add all the user-interface elements & realise */
1197 filer_add_widgets(filer_window
);
1199 gtk_window_set_position(GTK_WINDOW(filer_window
->window
),
1202 /* Connect to all the signal handlers */
1203 filer_add_signals(filer_window
);
1205 display_set_layout(filer_window
, dstyle
, dtype
);
1207 /* Open the window after a timeout, or when scanning stops.
1208 * Do this before attaching, because attach() might tell us to
1209 * stop scanning (if a scan isn't needed).
1211 filer_window
->open_timeout
= gtk_timeout_add(500,
1212 (GtkFunction
) open_filer_window
,
1215 /* The collection is created empty and then attach() is called, which
1216 * links the filer window to the entry in the directory cache we
1217 * looked up / created above.
1219 * The attach() function will immediately callback to the filer window
1220 * to deliver a list of all known entries in the directory (so,
1221 * collection->number_of_items may be valid after the call to
1222 * attach() returns).
1224 * If the directory was not in the cache (because it hadn't been
1225 * opened it before) then the types and icons for the entries are
1226 * not know, but the list of names is.
1229 attach(filer_window
);
1231 number_of_windows
++;
1232 all_filer_windows
= g_list_prepend(all_filer_windows
, filer_window
);
1234 return filer_window
;
1237 /* This adds all the widgets to a new filer window. It is in a separate
1238 * function because filer_opendir() was getting too long...
1240 static void filer_add_widgets(FilerWindow
*filer_window
)
1242 GtkWidget
*hbox
, *vbox
, *collection
;
1244 /* Create the top-level window widget */
1245 filer_window
->window
= gtk_window_new(GTK_WINDOW_TOPLEVEL
);
1246 filer_set_title(filer_window
);
1248 /* This property is cleared when the window is destroyed.
1249 * You can thus ref filer_window->window and use this to see
1250 * if the window no longer exists.
1252 g_object_set_data(G_OBJECT(filer_window
->window
),
1253 "filer_window", filer_window
);
1255 /* The view is the area that actually displays the files */
1256 filer_window
->view
= VIEW(view_collection_new(filer_window
));
1257 gtk_widget_show(GTK_WIDGET(filer_window
->view
));
1258 collection
= GTK_WIDGET(filer_window
->collection
); /* XXX */
1259 g_object_set_data(G_OBJECT(collection
), "filer_window", filer_window
);
1261 /* Scrollbar on the right, everything else on the left */
1262 hbox
= gtk_hbox_new(FALSE
, 0);
1263 gtk_container_add(GTK_CONTAINER(filer_window
->window
), hbox
);
1265 vbox
= gtk_vbox_new(FALSE
, 0);
1266 gtk_box_pack_start_defaults(GTK_BOX(hbox
), vbox
);
1267 filer_window
->toplevel_vbox
= GTK_BOX(vbox
);
1269 /* If we want a toolbar, create it now */
1270 toolbar_update_toolbar(filer_window
);
1272 /* If there's a message that should be displayed in each window (eg
1273 * 'Running as root'), add it here.
1275 if (show_user_message
)
1277 filer_window
->message
= gtk_label_new(show_user_message
);
1278 gtk_box_pack_start(GTK_BOX(vbox
), filer_window
->message
,
1280 gtk_widget_show(filer_window
->message
);
1283 /* Now add the area for displaying the files.
1284 * The collection is one huge window that goes in a Viewport.
1286 gtk_box_pack_start_defaults(GTK_BOX(vbox
),
1287 GTK_WIDGET(filer_window
->view
));
1288 filer_window
->scrollbar
=
1289 gtk_vscrollbar_new(filer_window
->collection
->vadj
);
1291 /* And the minibuffer (hidden to start with) */
1292 create_minibuffer(filer_window
);
1293 gtk_box_pack_start(GTK_BOX(vbox
), filer_window
->minibuffer_area
,
1296 /* And the thumbnail progress bar (also hidden) */
1300 filer_window
->thumb_bar
= gtk_hbox_new(FALSE
, 2);
1301 gtk_box_pack_start(GTK_BOX(vbox
), filer_window
->thumb_bar
,
1304 filer_window
->thumb_progress
= gtk_progress_bar_new();
1306 gtk_box_pack_start(GTK_BOX(filer_window
->thumb_bar
),
1307 filer_window
->thumb_progress
, TRUE
, TRUE
, 0);
1309 cancel
= gtk_button_new_with_label(_("Cancel"));
1310 GTK_WIDGET_UNSET_FLAGS(cancel
, GTK_CAN_FOCUS
);
1311 gtk_box_pack_start(GTK_BOX(filer_window
->thumb_bar
),
1312 cancel
, FALSE
, TRUE
, 0);
1313 g_signal_connect_swapped(cancel
, "clicked",
1314 G_CALLBACK(filer_cancel_thumbnails
),
1318 /* Put the scrollbar on the left of everything else... */
1319 gtk_box_pack_start(GTK_BOX(hbox
),
1320 filer_window
->scrollbar
, FALSE
, TRUE
, 0);
1322 gtk_window_set_focus(GTK_WINDOW(filer_window
->window
), collection
);
1324 gtk_widget_show(hbox
);
1325 gtk_widget_show(vbox
);
1326 gtk_widget_show(filer_window
->scrollbar
);
1327 gtk_widget_show(collection
);
1329 gtk_widget_realize(filer_window
->window
);
1331 gdk_window_set_role(filer_window
->window
->window
,
1332 filer_window
->sym_path
);
1334 filer_window_set_size(filer_window
, 4, 4, TRUE
);
1337 static void filer_add_signals(FilerWindow
*filer_window
)
1339 GtkObject
*collection
= GTK_OBJECT(filer_window
->collection
);
1340 GtkTargetEntry target_table
[] =
1342 {"text/uri-list", 0, TARGET_URI_LIST
},
1343 {"STRING", 0, TARGET_STRING
},
1344 {"COMPOUND_TEXT", 0, TARGET_STRING
},/* XXX: Treats as STRING */
1347 /* Events on the top-level window */
1348 gtk_widget_add_events(filer_window
->window
, GDK_ENTER_NOTIFY
);
1349 g_signal_connect(filer_window
->window
, "enter-notify-event",
1350 G_CALLBACK(pointer_in
), filer_window
);
1351 g_signal_connect(filer_window
->window
, "leave-notify-event",
1352 G_CALLBACK(pointer_out
), filer_window
);
1353 g_signal_connect(filer_window
->window
, "destroy",
1354 G_CALLBACK(filer_window_destroyed
), filer_window
);
1356 /* Events on the collection widget */
1357 gtk_widget_set_events(GTK_WIDGET(collection
),
1358 GDK_BUTTON1_MOTION_MASK
| GDK_BUTTON2_MOTION_MASK
|
1359 GDK_BUTTON3_MOTION_MASK
| GDK_POINTER_MOTION_MASK
|
1360 GDK_BUTTON_PRESS_MASK
| GDK_BUTTON_RELEASE_MASK
);
1362 g_signal_connect(collection
, "selection_get",
1363 G_CALLBACK(selection_get
), NULL
);
1364 gtk_selection_add_targets(GTK_WIDGET(collection
), GDK_SELECTION_PRIMARY
,
1366 sizeof(target_table
) / sizeof(*target_table
));
1368 g_signal_connect(filer_window
->window
, "key_press_event",
1369 G_CALLBACK(key_press_event
), filer_window
);
1371 /* Drag and drop events */
1372 g_signal_connect(collection
, "drag_data_get",
1373 GTK_SIGNAL_FUNC(drag_data_get
), NULL
);
1374 drag_set_dest(filer_window
);
1377 static gint
clear_scanning_display(FilerWindow
*filer_window
)
1379 if (filer_exists(filer_window
))
1380 filer_set_title(filer_window
);
1384 static void set_scanning_display(FilerWindow
*filer_window
, gboolean scanning
)
1386 if (scanning
== filer_window
->scanning
)
1388 filer_window
->scanning
= scanning
;
1391 filer_set_title(filer_window
);
1393 gtk_timeout_add(300, (GtkFunction
) clear_scanning_display
,
1397 /* Note that filer_window may not exist after this call */
1398 void filer_update_dir(FilerWindow
*filer_window
, gboolean warning
)
1400 if (may_rescan(filer_window
, warning
))
1401 dir_update(filer_window
->directory
, filer_window
->sym_path
);
1404 void filer_update_all(void)
1406 GList
*next
= all_filer_windows
;
1410 FilerWindow
*filer_window
= (FilerWindow
*) next
->data
;
1412 /* Updating directory may remove it from list -- stop sending
1413 * patches to move this line!
1417 filer_update_dir(filer_window
, TRUE
);
1421 /* Refresh the various caches even if we don't think we need to */
1422 void full_refresh(void)
1427 /* See whether a filer window with a given path already exists
1428 * and is different from diff.
1430 static FilerWindow
*find_filer_window(const char *sym_path
, FilerWindow
*diff
)
1434 for (next
= all_filer_windows
; next
; next
= next
->next
)
1436 FilerWindow
*filer_window
= (FilerWindow
*) next
->data
;
1438 if (filer_window
!= diff
&&
1439 strcmp(sym_path
, filer_window
->sym_path
) == 0)
1440 return filer_window
;
1446 /* This path has been mounted/umounted/deleted some files - update all dirs */
1447 void filer_check_mounted(const char *real_path
)
1449 GList
*next
= all_filer_windows
;
1453 len
= strlen(real_path
);
1457 FilerWindow
*filer_window
= (FilerWindow
*) next
->data
;
1461 if (strncmp(real_path
, filer_window
->real_path
, len
) == 0)
1463 char s
= filer_window
->real_path
[len
];
1465 if (s
== '/' || s
== '\0')
1466 filer_update_dir(filer_window
, FALSE
);
1470 parent
= g_dirname(real_path
);
1471 refresh_dirs(parent
);
1474 icons_may_update(real_path
);
1477 /* Close all windows displaying 'path' or subdirectories of 'path' */
1478 void filer_close_recursive(const char *path
)
1480 GList
*next
= all_filer_windows
;
1484 real
= pathdup(path
);
1489 FilerWindow
*filer_window
= (FilerWindow
*) next
->data
;
1493 if (strncmp(real
, filer_window
->real_path
, len
) == 0)
1495 char s
= filer_window
->real_path
[len
];
1497 if (len
== 1 || s
== '/' || s
== '\0')
1498 gtk_widget_destroy(filer_window
->window
);
1503 /* Like minibuffer_show(), except that:
1504 * - It returns FALSE (to be used from an idle callback)
1505 * - It checks that the filer window still exists.
1507 static gboolean
minibuffer_show_cb(FilerWindow
*filer_window
)
1509 if (filer_exists(filer_window
))
1510 minibuffer_show(filer_window
, MINI_PATH
);
1514 /* TRUE iff filer_window points to an existing FilerWindow
1517 gboolean
filer_exists(FilerWindow
*filer_window
)
1521 for (next
= all_filer_windows
; next
; next
= next
->next
)
1523 FilerWindow
*fw
= (FilerWindow
*) next
->data
;
1525 if (fw
== filer_window
)
1532 /* Make sure the window title is up-to-date */
1533 void filer_set_title(FilerWindow
*filer_window
)
1535 guchar
*title
= NULL
;
1538 if (filer_window
->scanning
|| filer_window
->show_hidden
||
1539 filer_window
->show_thumbs
)
1541 if (o_short_flag_names
.int_value
)
1543 flags
= g_strconcat(" +",
1544 filer_window
->scanning
? _("S") : "",
1545 filer_window
->show_hidden
? _("A") : "",
1546 filer_window
->show_thumbs
? _("T") : "",
1551 flags
= g_strconcat(" (",
1552 filer_window
->scanning
? _("Scanning, ") : "",
1553 filer_window
->show_hidden
? _("All, ") : "",
1554 filer_window
->show_thumbs
? _("Thumbs, ") : "",
1556 flags
[strlen(flags
) - 2] = ')';
1561 title
= g_strconcat("//", our_host_name(),
1562 filer_window
->sym_path
, flags
, NULL
);
1564 if (!title
&& home_dir_len
> 1 &&
1565 strncmp(filer_window
->sym_path
, home_dir
, home_dir_len
) == 0)
1567 guchar sep
= filer_window
->sym_path
[home_dir_len
];
1569 if (sep
== '\0' || sep
== '/')
1570 title
= g_strconcat("~",
1571 filer_window
->sym_path
+ home_dir_len
,
1577 title
= g_strconcat(filer_window
->sym_path
, flags
, NULL
);
1579 gtk_window_set_title(GTK_WINDOW(filer_window
->window
), title
);
1582 if (flags
[0] != '\0')
1586 /* Reconnect to the same directory (used when the Show Hidden option is
1587 * toggled). This has the side-effect of updating the window title.
1589 void filer_detach_rescan(FilerWindow
*filer_window
)
1591 Directory
*dir
= filer_window
->directory
;
1594 detach(filer_window
);
1595 filer_window
->directory
= dir
;
1596 attach(filer_window
);
1599 /* Puts the filer window into target mode. When an item is chosen,
1600 * fn(filer_window, item, data) is called. 'reason' will be displayed
1601 * on the toolbar while target mode is active.
1603 * Use fn == NULL to cancel target mode.
1605 void filer_target_mode(FilerWindow
*filer_window
,
1610 TargetFunc old_fn
= filer_window
->target_cb
;
1613 gdk_window_set_cursor(
1614 GTK_WIDGET(filer_window
->collection
)->window
,
1615 fn
? crosshair
: NULL
);
1617 filer_window
->target_cb
= fn
;
1618 filer_window
->target_data
= data
;
1620 if (filer_window
->toolbar_text
== NULL
)
1625 GTK_LABEL(filer_window
->toolbar_text
), reason
);
1626 else if (o_toolbar_info
.int_value
)
1629 toolbar_update_info(filer_window
);
1632 gtk_label_set_text(GTK_LABEL(filer_window
->toolbar_text
), "");
1635 static void set_selection_state(FilerWindow
*filer_window
, gboolean normal
)
1637 GtkStateType old_state
= filer_window
->selection_state
;
1639 filer_window
->selection_state
= normal
1640 ? GTK_STATE_SELECTED
: GTK_STATE_INSENSITIVE
;
1642 if (old_state
!= filer_window
->selection_state
1643 && filer_window
->collection
->number_selected
)
1644 gtk_widget_queue_draw(GTK_WIDGET(filer_window
->collection
));
1647 void filer_cancel_thumbnails(FilerWindow
*filer_window
)
1649 gtk_widget_hide(filer_window
->thumb_bar
);
1651 g_list_foreach(filer_window
->thumb_queue
, (GFunc
) g_free
, NULL
);
1652 g_list_free(filer_window
->thumb_queue
);
1653 filer_window
->thumb_queue
= NULL
;
1654 filer_window
->max_thumbs
= 0;
1657 /* Generate the next thumb for this window. The collection object is
1658 * unref'd when there is nothing more to do.
1659 * If the collection no longer has a filer window, nothing is done.
1661 static gboolean
filer_next_thumb_real(GObject
*window
)
1663 FilerWindow
*filer_window
;
1667 filer_window
= g_object_get_data(window
, "filer_window");
1671 g_object_unref(window
);
1675 if (!filer_window
->thumb_queue
)
1677 filer_cancel_thumbnails(filer_window
);
1678 g_object_unref(window
);
1682 total
= filer_window
->max_thumbs
;
1683 done
= total
- g_list_length(filer_window
->thumb_queue
);
1685 path
= (gchar
*) filer_window
->thumb_queue
->data
;
1687 pixmap_background_thumb(path
, (GFunc
) filer_next_thumb
, window
);
1689 filer_window
->thumb_queue
= g_list_remove(filer_window
->thumb_queue
,
1693 gtk_progress_bar_set_fraction(
1694 GTK_PROGRESS_BAR(filer_window
->thumb_progress
),
1695 done
/ (float) total
);
1700 /* path is the thumb just loaded, if any.
1701 * collection is unref'd (eventually).
1703 static void filer_next_thumb(GObject
*window
, const gchar
*path
)
1706 dir_force_update_path(path
);
1708 gtk_idle_add((GtkFunction
) filer_next_thumb_real
, window
);
1711 static void start_thumb_scanning(FilerWindow
*filer_window
)
1713 if (GTK_WIDGET_VISIBLE(filer_window
->thumb_bar
))
1714 return; /* Already scanning */
1716 gtk_widget_show_all(filer_window
->thumb_bar
);
1718 g_object_ref(G_OBJECT(filer_window
->window
));
1719 filer_next_thumb(G_OBJECT(filer_window
->window
), NULL
);
1722 /* Set this image to be loaded some time in the future */
1723 void filer_create_thumb(FilerWindow
*filer_window
, const gchar
*path
)
1725 filer_window
->max_thumbs
++;
1727 filer_window
->thumb_queue
= g_list_append(filer_window
->thumb_queue
,
1730 if (filer_window
->scanning
)
1731 return; /* Will start when scan ends */
1733 start_thumb_scanning(filer_window
);
1736 /* If thumbnail display is on, look through all the items in this directory
1737 * and start creating or updating the thumbnails as needed.
1739 void filer_create_thumbs(FilerWindow
*filer_window
)
1744 if (!filer_window
->show_thumbs
)
1747 view_get_iter(filer_window
->view
, &iter
, 0);
1749 while ((item
= iter
.next(&iter
)))
1751 MaskedPixmap
*pixmap
;
1755 if (item
->base_type
!= TYPE_FILE
)
1758 if (strcmp(item
->mime_type
->media_type
, "image") != 0)
1761 path
= make_path(filer_window
->real_path
, item
->leafname
)->str
;
1763 pixmap
= g_fscache_lookup_full(pixmap_cache
, path
,
1764 FSCACHE_LOOKUP_ONLY_NEW
, &found
);
1766 g_object_unref(pixmap
);
1768 /* If we didn't get an image, it could be because:
1770 * - We're loading the image now. found is TRUE,
1771 * and we'll update the item later.
1772 * - We tried to load the image and failed. found
1774 * - We haven't tried loading the image. found is
1775 * FALSE, and we start creating the thumb here.
1778 filer_create_thumb(filer_window
, path
);
1782 static void filer_options_changed(void)
1784 if (o_short_flag_names
.has_changed
)
1788 for (next
= all_filer_windows
; next
; next
= next
->next
)
1790 FilerWindow
*filer_window
= (FilerWindow
*) next
->data
;
1792 filer_set_title(filer_window
);
1797 /* Change to Large or Small icons depending on the number of items
1798 * in the directory, subject to options.
1800 static void set_style_by_number_of_items(FilerWindow
*filer_window
)
1804 g_return_if_fail(filer_window
!= NULL
);
1806 if (!o_filer_change_size
.int_value
)
1807 return; /* Don't auto-set style */
1809 if (filer_window
->display_style
!= LARGE_ICONS
&&
1810 filer_window
->display_style
!= SMALL_ICONS
)
1811 return; /* Only change between these two styles */
1813 n
= filer_window
->collection
->number_of_items
;
1815 if (n
>= o_filer_change_size_num
.int_value
)
1816 display_set_layout(filer_window
, SMALL_ICONS
,
1817 filer_window
->details_type
);
1819 display_set_layout(filer_window
, LARGE_ICONS
,
1820 filer_window
->details_type
);
1823 /* Append interesting information to this GString */
1824 void filer_add_tip_details(FilerWindow
*filer_window
,
1825 GString
*tip
, DirItem
*item
)
1827 guchar
*fullpath
= NULL
;
1829 fullpath
= make_path(filer_window
->real_path
, item
->leafname
)->str
;
1831 if (item
->flags
& ITEM_FLAG_SYMLINK
)
1835 target
= readlink_dup(fullpath
);
1838 g_string_append(tip
, _("Symbolic link to "));
1839 g_string_append(tip
, target
);
1840 g_string_append_c(tip
, '\n');
1845 if (item
->flags
& ITEM_FLAG_APPDIR
)
1850 info
= appinfo_get(fullpath
, item
);
1851 if (info
&& ((node
= xml_get_section(info
, NULL
, "Summary"))))
1854 str
= xmlNodeListGetString(node
->doc
,
1855 node
->xmlChildrenNode
, 1);
1858 g_string_append(tip
, str
);
1859 g_string_append_c(tip
, '\n');
1864 g_object_unref(info
);
1867 if (!g_utf8_validate(item
->leafname
, -1, NULL
))
1868 g_string_append(tip
,
1869 _("This filename is not valid UTF-8. "
1870 "You should rename it.\n"));