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 /* This is rather badly named. It's actually the filer window which received
70 * the last key press or Menu click event.
72 FilerWindow
*window_with_focus
= NULL
;
74 GList
*all_filer_windows
= NULL
;
76 static FilerWindow
*window_with_primary
= NULL
;
78 /* Static prototypes */
79 static void attach(FilerWindow
*filer_window
);
80 static void detach(FilerWindow
*filer_window
);
81 static void filer_window_destroyed(GtkWidget
*widget
,
82 FilerWindow
*filer_window
);
83 static void update_display(Directory
*dir
,
86 FilerWindow
*filer_window
);
87 static void set_scanning_display(FilerWindow
*filer_window
, gboolean scanning
);
88 static gboolean
may_rescan(FilerWindow
*filer_window
, gboolean warning
);
89 static gboolean
minibuffer_show_cb(FilerWindow
*filer_window
);
90 static FilerWindow
*find_filer_window(const char *sym_path
, FilerWindow
*diff
);
91 static void filer_add_widgets(FilerWindow
*filer_window
);
92 static void filer_add_signals(FilerWindow
*filer_window
);
93 static void filer_size_for(FilerWindow
*filer_window
,
94 int w
, int h
, int n
, gboolean allow_shrink
);
96 static void set_selection_state(FilerWindow
*filer_window
, gboolean normal
);
97 static void filer_next_thumb(GObject
*window
, const gchar
*path
);
98 static void start_thumb_scanning(FilerWindow
*filer_window
);
99 static void filer_options_changed(void);
100 static void set_style_by_number_of_items(FilerWindow
*filer_window
);
102 static GdkCursor
*busy_cursor
= NULL
;
103 static GdkCursor
*crosshair
= NULL
;
105 /* Indicates whether the filer's display is different to the machine it
106 * is actually running on.
108 static gboolean not_local
= FALSE
;
110 static Option o_filer_change_size
, o_filer_change_size_num
;
111 static Option o_filer_size_limit
, o_short_flag_names
;
112 Option o_filer_auto_resize
, o_unique_filer_windows
;
114 void filer_init(void)
118 gchar
*dpyhost
, *tmp
;
120 option_add_int(&o_filer_size_limit
, "filer_size_limit", 75);
121 option_add_int(&o_filer_auto_resize
, "filer_auto_resize",
123 option_add_int(&o_unique_filer_windows
, "filer_unique_windows", 0);
125 option_add_int(&o_short_flag_names
, "filer_short_flag_names", FALSE
);
127 option_add_int(&o_filer_change_size
, "filer_change_size", TRUE
);
128 option_add_int(&o_filer_change_size_num
, "filer_change_size_num", 30);
130 option_add_notify(filer_options_changed
);
132 busy_cursor
= gdk_cursor_new(GDK_WATCH
);
133 crosshair
= gdk_cursor_new(GDK_CROSSHAIR
);
135 /* Is the display on the local machine, or are we being
136 * run remotely? See filer_set_title().
138 ohost
= our_host_name();
139 dpy
= gdk_get_display();
140 dpyhost
= g_strdup(dpy
);
141 tmp
= strchr(dpyhost
, ':');
145 if (dpyhost
[0] && strcmp(ohost
, dpyhost
) != 0)
147 /* Try the cannonical name for dpyhost (see our_host_name()
152 ent
= gethostbyname(dpyhost
);
153 if (!ent
|| strcmp(ohost
, ent
->h_name
) != 0)
160 static gboolean
if_deleted(gpointer item
, gpointer removed
)
162 int i
= ((GPtrArray
*) removed
)->len
;
163 DirItem
**r
= (DirItem
**) ((GPtrArray
*) removed
)->pdata
;
164 char *leafname
= ((DirItem
*) item
)->leafname
;
168 if (strcmp(leafname
, r
[i
]->leafname
) == 0)
175 /* Resize the filer window to w x h pixels, plus border (not clamped) */
176 static void filer_window_set_size(FilerWindow
*filer_window
,
178 gboolean allow_shrink
)
182 g_return_if_fail(filer_window
!= NULL
);
184 if (filer_window
->scrollbar
)
185 w
+= filer_window
->scrollbar
->allocation
.width
;
187 if (o_toolbar
.int_value
!= TOOLBAR_NONE
)
188 h
+= filer_window
->toolbar
->allocation
.height
;
189 if (filer_window
->message
)
190 h
+= filer_window
->message
->allocation
.height
;
192 window
= filer_window
->window
;
194 if (GTK_WIDGET_VISIBLE(window
))
197 GtkRequisition
*req
= &window
->requisition
;
198 GdkWindow
*gdk_window
= window
->window
;
200 w
= MAX(req
->width
, w
);
201 h
= MAX(req
->height
, h
);
202 gdk_window_get_position(gdk_window
, &x
, &y
);
208 gdk_drawable_get_size(gdk_window
, &old_w
, &old_h
);
212 if (w
== old_w
&& h
== old_h
)
216 if (x
+ w
> screen_width
|| y
+ h
> screen_height
)
218 if (x
+ w
> screen_width
)
219 x
= screen_width
- w
- 4;
220 if (y
+ h
> screen_height
)
221 y
= screen_height
- h
- 4;
222 gdk_window_move_resize(gdk_window
, x
, y
, w
, h
);
225 gdk_window_resize(gdk_window
, w
, h
);
228 gtk_window_set_default_size(GTK_WINDOW(window
), w
, h
);
231 /* Resize the window to fit the items currently in the Directory.
232 * This should be used once the Directory has been fully scanned, otherwise
233 * the window will appear too small. When opening a directory for the first
234 * time, the names will be known but not the types and images. We can
235 * still make a good estimate of the size.
237 void filer_window_autosize(FilerWindow
*filer_window
, gboolean allow_shrink
)
239 Collection
*collection
= filer_window
->collection
;
242 n
= collection
->number_of_items
;
245 filer_size_for(filer_window
,
246 collection
->item_width
,
247 collection
->item_height
,
251 /* Choose a good size for this window, assuming n items of size (w, h) */
252 static void filer_size_for(FilerWindow
*filer_window
,
253 int w
, int h
, int n
, gboolean allow_shrink
)
263 size_limit
= o_filer_size_limit
.int_value
;
265 /* Get the extra height required for the toolbar and minibuffer,
268 if (o_toolbar
.int_value
!= TOOLBAR_NONE
)
269 t
= filer_window
->toolbar
->allocation
.height
;
270 if (filer_window
->message
)
271 t
+= filer_window
->message
->allocation
.height
;
272 if (GTK_WIDGET_VISIBLE(filer_window
->minibuffer_area
))
276 gtk_widget_size_request(filer_window
->minibuffer_area
, &req
);
277 space
= req
.height
+ 2;
281 max_x
= (size_limit
* screen_width
) / 100;
282 max_rows
= (size_limit
* screen_height
) / (h
* 100);
284 /* Aim for a size where
285 * x = r(y + t + h), (1)
286 * unless that's too wide.
288 * t = toolbar (and minibuffer) height
289 * r = desired (width / height) ratio
291 * Want to display all items:
294 * => x(x/r - t - h) = nwh (from 1)
295 * => xx - x.rt - hr(1 - nw) = 0
296 * => 2x = rt +/- sqrt(rt.rt + 4hr(nw - 1))
300 * sqrt(rt.rt + ...) > rt
302 * So, the +/- must be +:
304 * => x = (rt + sqrt(rt.rt + 4hr(nw - 1))) / 2
306 * ( + w - 1 to round up)
308 x
= (r
* t
+ sqrt(r
*r
*t
*t
+ 4*h
*r
* (n
*w
- 1))) / 2 + w
- 1;
317 /* Choose rows to display all items given our chosen x.
318 * Don't make the window *too* big!
320 rows
= (n
+ cols
- 1) / cols
;
324 /* Leave some room for extra icons, but only in Small Icons mode
325 * otherwise it takes up too much space.
326 * Also, don't add space if the minibuffer is open.
329 space
= filer_window
->display_style
== SMALL_ICONS
? h
: 2;
331 filer_window_set_size(filer_window
,
333 h
* MAX(rows
, 1) + space
,
337 /* Called on a timeout while scanning or when scanning ends
338 * (whichever happens first).
340 static gint
open_filer_window(FilerWindow
*filer_window
)
342 view_style_changed(filer_window
->view
, 0);
344 if (filer_window
->open_timeout
)
346 gtk_timeout_remove(filer_window
->open_timeout
);
347 filer_window
->open_timeout
= 0;
350 if (!GTK_WIDGET_VISIBLE(filer_window
->window
))
352 set_style_by_number_of_items(filer_window
);
353 filer_window_autosize(filer_window
, TRUE
);
354 gtk_widget_show(filer_window
->window
);
360 static void update_display(Directory
*dir
,
363 FilerWindow
*filer_window
)
365 Collection
*collection
= filer_window
->collection
;
366 ViewIface
*view
= (ViewIface
*) filer_window
->view
;
371 view_add_items(view
, items
);
372 /* Open and resize if currently hidden */
373 open_filer_window(filer_window
);
376 view_delete_if(view
, if_deleted
, items
);
379 set_scanning_display(filer_window
, TRUE
);
380 toolbar_update_info(filer_window
);
383 if (filer_window
->window
->window
)
384 gdk_window_set_cursor(
385 filer_window
->window
->window
,
387 set_scanning_display(filer_window
, FALSE
);
388 toolbar_update_info(filer_window
);
389 open_filer_window(filer_window
);
391 if (filer_window
->had_cursor
&&
392 collection
->cursor_item
== -1)
394 collection_set_cursor_item(collection
, 0);
395 filer_window
->had_cursor
= FALSE
;
397 if (filer_window
->auto_select
)
398 display_set_autoselect(filer_window
,
399 filer_window
->auto_select
);
400 g_free(filer_window
->auto_select
);
401 filer_window
->auto_select
= NULL
;
403 filer_create_thumbs(filer_window
);
405 if (filer_window
->thumb_queue
)
406 start_thumb_scanning(filer_window
);
409 view_update_items(view
, items
);
414 static void attach(FilerWindow
*filer_window
)
416 gdk_window_set_cursor(filer_window
->window
->window
, busy_cursor
);
417 view_clear(filer_window
->view
);
418 filer_window
->scanning
= TRUE
;
419 dir_attach(filer_window
->directory
, (DirCallback
) update_display
,
421 filer_set_title(filer_window
);
424 static void detach(FilerWindow
*filer_window
)
426 g_return_if_fail(filer_window
->directory
!= NULL
);
428 dir_detach(filer_window
->directory
,
429 (DirCallback
) update_display
, filer_window
);
430 g_object_unref(filer_window
->directory
);
431 filer_window
->directory
= NULL
;
434 static void filer_window_destroyed(GtkWidget
*widget
,
435 FilerWindow
*filer_window
)
437 all_filer_windows
= g_list_remove(all_filer_windows
, filer_window
);
439 g_object_set_data(G_OBJECT(widget
), "filer_window", NULL
);
441 if (window_with_primary
== filer_window
)
442 window_with_primary
= NULL
;
444 if (window_with_focus
== filer_window
)
447 window_with_focus
= NULL
;
450 if (filer_window
->directory
)
451 detach(filer_window
);
453 if (filer_window
->open_timeout
)
455 gtk_timeout_remove(filer_window
->open_timeout
);
456 filer_window
->open_timeout
= 0;
459 if (filer_window
->thumb_queue
)
461 g_list_foreach(filer_window
->thumb_queue
, (GFunc
) g_free
, NULL
);
462 g_list_free(filer_window
->thumb_queue
);
467 g_free(filer_window
->auto_select
);
468 g_free(filer_window
->real_path
);
469 g_free(filer_window
->sym_path
);
470 g_free(filer_window
);
475 /* Returns TRUE iff the directory still exists. */
476 static gboolean
may_rescan(FilerWindow
*filer_window
, gboolean warning
)
480 g_return_val_if_fail(filer_window
!= NULL
, FALSE
);
482 /* We do a fresh lookup (rather than update) because the inode may
485 dir
= g_fscache_lookup(dir_cache
, filer_window
->real_path
);
489 info_message(_("Directory missing/deleted"));
490 gtk_widget_destroy(filer_window
->window
);
493 if (dir
== filer_window
->directory
)
497 detach(filer_window
);
498 filer_window
->directory
= dir
;
499 attach(filer_window
);
505 /* No items are now selected. This might be because another app claimed
506 * the selection or because the user unselected all the items.
508 void filer_lost_selection(FilerWindow
*filer_window
, gint time
)
510 if (window_with_primary
== filer_window
)
512 window_with_primary
= NULL
;
513 gtk_selection_owner_set(NULL
, GDK_SELECTION_PRIMARY
, time
);
517 /* Another app has claimed the primary selection */
518 void filer_lost_primary(FilerWindow
*filer_window
)
520 if (window_with_primary
&& window_with_primary
== filer_window
)
522 window_with_primary
= NULL
;
523 set_selection_state(filer_window
, FALSE
);
527 /* Someone wants us to send them the selection */
528 static void selection_get(GtkWidget
*widget
,
529 GtkSelectionData
*selection_data
,
534 GString
*reply
, *header
;
535 FilerWindow
*filer_window
;
539 filer_window
= g_object_get_data(G_OBJECT(widget
), "filer_window");
541 reply
= g_string_new(NULL
);
542 header
= g_string_new(NULL
);
547 g_string_sprintf(header
, " %s",
548 make_path(filer_window
->sym_path
, "")->str
);
550 case TARGET_URI_LIST
:
551 g_string_sprintf(header
, " file://%s%s",
552 our_host_name_for_dnd(),
553 make_path(filer_window
->sym_path
, "")->str
);
557 view_get_iter(filer_window
->view
, &iter
, VIEW_ITER_SELECTED
);
559 while ((item
= iter
.next(&iter
)))
561 g_string_append(reply
, header
->str
);
562 g_string_append(reply
, item
->leafname
);
566 gtk_selection_data_set(selection_data
, xa_string
,
567 8, reply
->str
+ 1, reply
->len
- 1);
570 g_warning("Attempt to paste empty selection!");
571 gtk_selection_data_set(selection_data
, xa_string
, 8, "", 0);
574 g_string_free(reply
, TRUE
);
575 g_string_free(header
, TRUE
);
578 void filer_selection_changed(FilerWindow
*filer_window
, gint time
)
580 /* Selection has been changed -- try to grab the primary selection
581 * if we don't have it.
583 if (window_with_primary
== filer_window
)
584 return; /* Already got it */
586 if (!filer_window
->collection
->number_selected
)
587 return; /* Nothing selected */
589 if (filer_window
->temp_item_selected
== FALSE
&&
590 gtk_selection_owner_set(GTK_WIDGET(filer_window
->collection
),
591 GDK_SELECTION_PRIMARY
,
594 window_with_primary
= filer_window
;
595 set_selection_state(filer_window
, TRUE
);
598 set_selection_state(filer_window
, FALSE
);
601 /* Open the item (or add it to the shell command minibuffer) */
602 void filer_openitem(FilerWindow
*filer_window
, int item_number
, OpenFlags flags
)
604 gboolean shift
= (flags
& OPEN_SHIFT
) != 0;
605 gboolean close_mini
= flags
& OPEN_FROM_MINI
;
606 gboolean close_window
= (flags
& OPEN_CLOSE_WINDOW
) != 0;
607 DirItem
*item
= (DirItem
*)
608 filer_window
->collection
->items
[item_number
].data
;
610 gboolean wink
= TRUE
;
613 if (filer_window
->mini_type
== MINI_SHELL
)
615 minibuffer_add(filer_window
, item
->leafname
);
620 dir_update_item(filer_window
->directory
, item
->leafname
);
622 if (item
->base_type
== TYPE_DIRECTORY
)
624 /* Never close a filer window when opening a directory
625 * (click on a dir or click on an app with shift).
627 if (shift
|| !(item
->flags
& ITEM_FLAG_APPDIR
))
628 close_window
= FALSE
;
631 full_path
= make_path(filer_window
->sym_path
, item
->leafname
)->str
;
632 if (shift
&& (item
->flags
& ITEM_FLAG_SYMLINK
))
635 old_dir
= filer_window
->directory
;
636 if (run_diritem(full_path
, item
,
637 flags
& OPEN_SAME_WINDOW
? filer_window
: NULL
,
641 if (old_dir
!= filer_window
->directory
)
645 gtk_widget_destroy(filer_window
->window
);
649 collection_wink_item(filer_window
->collection
,
652 minibuffer_hide(filer_window
);
657 static gint
pointer_in(GtkWidget
*widget
,
658 GdkEventCrossing
*event
,
659 FilerWindow
*filer_window
)
661 may_rescan(filer_window
, TRUE
);
665 static gint
pointer_out(GtkWidget
*widget
,
666 GdkEventCrossing
*event
,
667 FilerWindow
*filer_window
)
673 /* Move the cursor to the next selected item in direction 'dir'
676 static void next_selected(FilerWindow
*filer_window
, int dir
)
678 Collection
*collection
= filer_window
->collection
;
679 int to_check
= collection
->number_of_items
;
680 int item
= collection
->cursor_item
;
682 g_return_if_fail(dir
== 1 || dir
== -1);
684 if (to_check
> 0 && item
== -1)
686 /* Cursor not currently on */
690 item
= collection
->number_of_items
- 1;
692 if (collection
->items
[item
].selected
)
696 while (--to_check
> 0)
700 if (item
>= collection
->number_of_items
)
703 item
= collection
->number_of_items
- 1;
705 if (collection
->items
[item
].selected
)
712 collection_set_cursor_item(collection
, item
);
715 static void return_pressed(FilerWindow
*filer_window
, GdkEventKey
*event
)
717 Collection
*collection
= filer_window
->collection
;
718 int item
= collection
->cursor_item
;
719 TargetFunc cb
= filer_window
->target_cb
;
720 gpointer data
= filer_window
->target_data
;
721 OpenFlags flags
= OPEN_SAME_WINDOW
;
723 filer_target_mode(filer_window
, NULL
, NULL
, NULL
);
724 if (item
< 0 || item
>= collection
->number_of_items
)
729 cb(filer_window
, item
, data
);
733 if (event
->state
& GDK_SHIFT_MASK
)
736 filer_openitem(filer_window
, item
, flags
);
739 /* Makes sure that 'groups' is up-to-date, reloading from file if it has
740 * changed. If no groups were loaded and there is no file then initialised
741 * groups to an empty document.
742 * Return the node for the 'name' group.
744 static xmlNode
*group_find(char *name
)
749 /* Update the groups, if possible */
750 path
= choices_find_path_load("Groups.xml", PROJECT
);
754 wrapper
= xml_cache_load(path
);
758 g_object_unref(groups
);
767 groups
= xml_new(NULL
);
768 groups
->doc
= xmlNewDoc("1.0");
770 xmlDocSetRootElement(groups
->doc
,
771 xmlNewDocNode(groups
->doc
, NULL
, "groups", NULL
));
775 node
= xmlDocGetRootElement(groups
->doc
);
777 for (node
= node
->xmlChildrenNode
; node
; node
= node
->next
)
781 gid
= xmlGetProp(node
, "name");
786 if (strcmp(name
, gid
) != 0)
797 static void group_save(FilerWindow
*filer_window
, char *name
)
804 group
= group_find(name
);
807 xmlUnlinkNode(group
);
810 group
= xmlNewChild(xmlDocGetRootElement(groups
->doc
),
811 NULL
, "group", NULL
);
812 xmlSetProp(group
, "name", name
);
814 xmlNewChild(group
, NULL
, "directory", filer_window
->sym_path
);
816 view_get_iter(filer_window
->view
, &iter
, VIEW_ITER_SELECTED
);
818 while ((item
= iter
.next(&iter
)))
819 xmlNewChild(group
, NULL
, "item", item
->leafname
);
821 save_path
= choices_find_path_save("Groups.xml", PROJECT
, TRUE
);
824 save_xml_file(groups
->doc
, save_path
);
829 static void group_restore(FilerWindow
*filer_window
, char *name
)
831 GHashTable
*in_group
;
832 Collection
*collection
= filer_window
->collection
;
835 xmlNode
*group
, *node
;
837 group
= group_find(name
);
841 report_error(_("Group %s is not set. Select some files "
842 "and press Ctrl+%s to set the group. Press %s "
843 "on its own to reselect the files later."),
848 node
= get_subnode(group
, NULL
, "directory");
849 g_return_if_fail(node
!= NULL
);
850 path
= xmlNodeListGetString(groups
->doc
, node
->xmlChildrenNode
, 1);
851 g_return_if_fail(path
!= NULL
);
853 if (strcmp(path
, filer_window
->sym_path
) != 0)
854 filer_change_to(filer_window
, path
, NULL
);
857 /* If an item at the start is selected then we could lose the
858 * primary selection after checking that item and then need to
859 * gain it again at the end. Therefore, if anything is selected
860 * then select the last item until the end of the search.
862 n
= collection
->number_of_items
;
863 if (collection
->number_selected
)
864 collection_select_item(collection
, n
- 1);
866 in_group
= g_hash_table_new(g_str_hash
, g_str_equal
);
867 for (node
= group
->xmlChildrenNode
; node
; node
= node
->next
)
870 if (node
->type
!= XML_ELEMENT_NODE
)
872 if (strcmp(node
->name
, "item") != 0)
875 leaf
= xmlNodeListGetString(groups
->doc
,
876 node
->xmlChildrenNode
, 1);
878 g_warning("Missing leafname!\n");
880 g_hash_table_insert(in_group
, leaf
, filer_window
);
883 for (j
= 0; j
< n
; j
++)
885 DirItem
*item
= (DirItem
*) collection
->items
[j
].data
;
887 if (g_hash_table_lookup(in_group
, item
->leafname
))
888 collection_select_item(collection
, j
);
890 collection_unselect_item(collection
, j
);
893 g_hash_table_foreach(in_group
, (GHFunc
) g_free
, NULL
);
894 g_hash_table_destroy(in_group
);
897 /* Handle keys that can't be bound with the menu */
898 static gint
key_press_event(GtkWidget
*widget
,
900 FilerWindow
*filer_window
)
902 GtkWidget
*focus
= GTK_WINDOW(widget
)->focus_widget
;
903 guint key
= event
->keyval
;
906 window_with_focus
= filer_window
;
908 /* Delay setting up the keys until now to speed loading... */
910 ensure_filer_menu(); /* Gets the keys working... */
912 if (!g_slist_find(filer_keys
->acceleratables
, widget
))
913 gtk_window_add_accel_group(GTK_WINDOW(filer_window
->window
),
916 if (focus
&& focus
!= widget
&&
917 gtk_widget_get_toplevel(focus
) == widget
)
918 if (gtk_widget_event(focus
, (GdkEvent
*) event
))
919 return TRUE
; /* Handled */
924 filer_target_mode(filer_window
, NULL
, NULL
, NULL
);
927 return_pressed(filer_window
, event
);
929 case GDK_ISO_Left_Tab
:
930 next_selected(filer_window
, -1);
933 next_selected(filer_window
, 1);
936 change_to_parent(filer_window
);
940 show_filer_menu(filer_window
, (GdkEvent
*) event
,
941 filer_window
->collection
->cursor_item
);
944 if (key
>= GDK_0
&& key
<= GDK_9
)
945 group
[0] = key
- GDK_0
+ '0';
946 else if (key
>= GDK_KP_0
&& key
<= GDK_KP_9
)
947 group
[0] = key
- GDK_KP_0
+ '0';
952 if (event
->state
& GDK_CONTROL_MASK
)
953 group_save(filer_window
, group
);
955 group_restore(filer_window
, group
);
961 void filer_open_parent(FilerWindow
*filer_window
)
964 const char *current
= filer_window
->sym_path
;
966 if (current
[0] == '/' && current
[1] == '\0')
967 return; /* Already in the root */
969 dir
= g_dirname(current
);
970 filer_opendir(dir
, filer_window
);
974 void change_to_parent(FilerWindow
*filer_window
)
977 const char *current
= filer_window
->sym_path
;
979 if (current
[0] == '/' && current
[1] == '\0')
980 return; /* Already in the root */
982 dir
= g_dirname(current
);
983 filer_change_to(filer_window
, dir
, g_basename(current
));
987 /* Removes trailing /s from path (modified in place) */
988 static void tidy_sympath(gchar
*path
)
992 g_return_if_fail(path
!= NULL
);
995 while (l
> 1 && path
[l
- 1] == '/')
1002 /* Make filer_window display path. When finished, highlight item 'from', or
1003 * the first item if from is NULL. If there is currently no cursor then
1004 * simply wink 'from' (if not NULL).
1006 void filer_change_to(FilerWindow
*filer_window
,
1007 const char *path
, const char *from
)
1010 char *sym_path
, *real_path
;
1013 g_return_if_fail(filer_window
!= NULL
);
1015 filer_cancel_thumbnails(filer_window
);
1019 sym_path
= g_strdup(path
);
1020 real_path
= pathdup(path
);
1021 new_dir
= g_fscache_lookup(dir_cache
, real_path
);
1025 delayed_error(_("Directory '%s' is not accessible"),
1032 if (o_unique_filer_windows
.int_value
)
1036 fw
= find_filer_window(sym_path
, filer_window
);
1038 gtk_widget_destroy(fw
->window
);
1041 from_dup
= from
&& *from
? g_strdup(from
) : NULL
;
1043 detach(filer_window
);
1044 g_free(filer_window
->real_path
);
1045 g_free(filer_window
->sym_path
);
1046 filer_window
->real_path
= real_path
;
1047 filer_window
->sym_path
= sym_path
;
1048 tidy_sympath(filer_window
->sym_path
);
1050 filer_window
->directory
= new_dir
;
1052 g_free(filer_window
->auto_select
);
1053 filer_window
->had_cursor
= filer_window
->collection
->cursor_item
!= -1
1054 || filer_window
->had_cursor
;
1055 filer_window
->auto_select
= from_dup
;
1057 filer_set_title(filer_window
);
1058 if (filer_window
->window
->window
)
1059 gdk_window_set_role(filer_window
->window
->window
,
1060 filer_window
->sym_path
);
1061 collection_set_cursor_item(filer_window
->collection
, -1);
1063 attach(filer_window
);
1065 set_style_by_number_of_items(filer_window
);
1067 if (o_filer_auto_resize
.int_value
== RESIZE_ALWAYS
)
1068 filer_window_autosize(filer_window
, TRUE
);
1070 if (filer_window
->mini_type
== MINI_PATH
)
1071 gtk_idle_add((GtkFunction
) minibuffer_show_cb
,
1075 /* Returns a list containing the full (sym) pathname of every selected item.
1076 * You must g_free() each item in the list.
1078 GList
*filer_selected_items(FilerWindow
*filer_window
)
1080 GList
*retval
= NULL
;
1081 guchar
*dir
= filer_window
->sym_path
;
1085 view_get_iter(filer_window
->view
, &iter
, VIEW_ITER_SELECTED
);
1086 while ((item
= iter
.next(&iter
)))
1088 retval
= g_list_prepend(retval
,
1089 g_strdup(make_path(dir
, item
->leafname
)->str
));
1092 return g_list_reverse(retval
);
1095 DirItem
*filer_selected_item(FilerWindow
*filer_window
)
1097 Collection
*collection
= filer_window
->collection
;
1100 item
= collection_selected_item_number(collection
);
1103 return (DirItem
*) collection
->items
[item
].data
;
1107 /* Creates and shows a new filer window.
1108 * If src_win != NULL then display options can be taken from that source window.
1109 * Returns the new filer window, or NULL on error.
1110 * Note: if unique windows is in use, may return an existing window.
1112 FilerWindow
*filer_opendir(const char *path
, FilerWindow
*src_win
)
1114 FilerWindow
*filer_window
;
1116 DisplayStyle dstyle
;
1119 /* Get the real pathname of the directory and copy it */
1120 real_path
= pathdup(path
);
1122 if (o_unique_filer_windows
.int_value
)
1124 FilerWindow
*same_dir_window
;
1126 same_dir_window
= find_filer_window(path
, NULL
);
1128 if (same_dir_window
)
1130 gtk_window_present(GTK_WINDOW(same_dir_window
->window
));
1131 return same_dir_window
;
1135 filer_window
= g_new(FilerWindow
, 1);
1136 filer_window
->message
= NULL
;
1137 filer_window
->minibuffer
= NULL
;
1138 filer_window
->minibuffer_label
= NULL
;
1139 filer_window
->minibuffer_area
= NULL
;
1140 filer_window
->temp_show_hidden
= FALSE
;
1141 filer_window
->sym_path
= g_strdup(path
);
1142 filer_window
->real_path
= real_path
;
1143 filer_window
->scanning
= FALSE
;
1144 filer_window
->had_cursor
= FALSE
;
1145 filer_window
->auto_select
= NULL
;
1146 filer_window
->toolbar_text
= NULL
;
1147 filer_window
->target_cb
= NULL
;
1148 filer_window
->mini_type
= MINI_NONE
;
1149 filer_window
->selection_state
= GTK_STATE_INSENSITIVE
;
1150 filer_window
->toolbar
= NULL
;
1151 filer_window
->toplevel_vbox
= NULL
;
1153 tidy_sympath(filer_window
->sym_path
);
1155 /* Finds the entry for this directory in the dir cache, creating
1156 * a new one if needed. This does not cause a scan to start,
1157 * so if a new entry is created then it will be empty.
1159 filer_window
->directory
= g_fscache_lookup(dir_cache
, real_path
);
1160 if (!filer_window
->directory
)
1162 delayed_error(_("Directory '%s' not found."), path
);
1163 g_free(filer_window
->real_path
);
1164 g_free(filer_window
->sym_path
);
1165 g_free(filer_window
);
1169 filer_window
->temp_item_selected
= FALSE
;
1170 filer_window
->flags
= (FilerFlags
) 0;
1171 filer_window
->details_type
= DETAILS_SUMMARY
;
1172 filer_window
->display_style
= UNKNOWN_STYLE
;
1173 filer_window
->thumb_queue
= NULL
;
1174 filer_window
->max_thumbs
= 0;
1176 if (src_win
&& o_display_inherit_options
.int_value
)
1178 filer_window
->sort_fn
= src_win
->sort_fn
;
1179 dstyle
= src_win
->display_style
;
1180 dtype
= src_win
->details_type
;
1181 filer_window
->show_hidden
= src_win
->show_hidden
;
1182 filer_window
->show_thumbs
= src_win
->show_thumbs
;
1186 int i
= o_display_sort_by
.int_value
;
1187 filer_window
->sort_fn
= i
== 0 ? sort_by_name
:
1188 i
== 1 ? sort_by_type
:
1189 i
== 2 ? sort_by_date
:
1192 dstyle
= o_display_size
.int_value
;
1193 dtype
= o_display_details
.int_value
;
1194 filer_window
->show_hidden
=
1195 o_display_show_hidden
.int_value
;
1196 filer_window
->show_thumbs
=
1197 o_display_show_thumbs
.int_value
;
1200 /* Add all the user-interface elements & realise */
1201 filer_add_widgets(filer_window
);
1203 gtk_window_set_position(GTK_WINDOW(filer_window
->window
),
1206 /* Connect to all the signal handlers */
1207 filer_add_signals(filer_window
);
1209 display_set_layout(filer_window
, dstyle
, dtype
);
1211 /* Open the window after a timeout, or when scanning stops.
1212 * Do this before attaching, because attach() might tell us to
1213 * stop scanning (if a scan isn't needed).
1215 filer_window
->open_timeout
= gtk_timeout_add(500,
1216 (GtkFunction
) open_filer_window
,
1219 /* The collection is created empty and then attach() is called, which
1220 * links the filer window to the entry in the directory cache we
1221 * looked up / created above.
1223 * The attach() function will immediately callback to the filer window
1224 * to deliver a list of all known entries in the directory (so,
1225 * collection->number_of_items may be valid after the call to
1226 * attach() returns).
1228 * If the directory was not in the cache (because it hadn't been
1229 * opened it before) then the types and icons for the entries are
1230 * not know, but the list of names is.
1233 attach(filer_window
);
1235 number_of_windows
++;
1236 all_filer_windows
= g_list_prepend(all_filer_windows
, filer_window
);
1238 return filer_window
;
1241 /* This adds all the widgets to a new filer window. It is in a separate
1242 * function because filer_opendir() was getting too long...
1244 static void filer_add_widgets(FilerWindow
*filer_window
)
1246 GtkWidget
*hbox
, *vbox
, *collection
;
1248 /* Create the top-level window widget */
1249 filer_window
->window
= gtk_window_new(GTK_WINDOW_TOPLEVEL
);
1250 filer_set_title(filer_window
);
1252 /* This property is cleared when the window is destroyed.
1253 * You can thus ref filer_window->window and use this to see
1254 * if the window no longer exists.
1256 g_object_set_data(G_OBJECT(filer_window
->window
),
1257 "filer_window", filer_window
);
1259 /* The view is the area that actually displays the files */
1260 filer_window
->view
= VIEW(view_collection_new(filer_window
));
1261 gtk_widget_show(GTK_WIDGET(filer_window
->view
));
1262 collection
= GTK_WIDGET(filer_window
->collection
); /* XXX */
1263 g_object_set_data(G_OBJECT(collection
), "filer_window", filer_window
);
1265 /* Scrollbar on the right, everything else on the left */
1266 hbox
= gtk_hbox_new(FALSE
, 0);
1267 gtk_container_add(GTK_CONTAINER(filer_window
->window
), hbox
);
1269 vbox
= gtk_vbox_new(FALSE
, 0);
1270 gtk_box_pack_start_defaults(GTK_BOX(hbox
), vbox
);
1271 filer_window
->toplevel_vbox
= GTK_BOX(vbox
);
1273 /* If we want a toolbar, create it now */
1274 toolbar_update_toolbar(filer_window
);
1276 /* If there's a message that should be displayed in each window (eg
1277 * 'Running as root'), add it here.
1279 if (show_user_message
)
1281 filer_window
->message
= gtk_label_new(show_user_message
);
1282 gtk_box_pack_start(GTK_BOX(vbox
), filer_window
->message
,
1284 gtk_widget_show(filer_window
->message
);
1287 /* Now add the area for displaying the files.
1288 * The collection is one huge window that goes in a Viewport.
1290 gtk_box_pack_start_defaults(GTK_BOX(vbox
),
1291 GTK_WIDGET(filer_window
->view
));
1292 filer_window
->scrollbar
=
1293 gtk_vscrollbar_new(filer_window
->collection
->vadj
);
1295 /* And the minibuffer (hidden to start with) */
1296 create_minibuffer(filer_window
);
1297 gtk_box_pack_start(GTK_BOX(vbox
), filer_window
->minibuffer_area
,
1300 /* And the thumbnail progress bar (also hidden) */
1304 filer_window
->thumb_bar
= gtk_hbox_new(FALSE
, 2);
1305 gtk_box_pack_start(GTK_BOX(vbox
), filer_window
->thumb_bar
,
1308 filer_window
->thumb_progress
= gtk_progress_bar_new();
1310 gtk_box_pack_start(GTK_BOX(filer_window
->thumb_bar
),
1311 filer_window
->thumb_progress
, TRUE
, TRUE
, 0);
1313 cancel
= gtk_button_new_with_label(_("Cancel"));
1314 GTK_WIDGET_UNSET_FLAGS(cancel
, GTK_CAN_FOCUS
);
1315 gtk_box_pack_start(GTK_BOX(filer_window
->thumb_bar
),
1316 cancel
, FALSE
, TRUE
, 0);
1317 g_signal_connect_swapped(cancel
, "clicked",
1318 G_CALLBACK(filer_cancel_thumbnails
),
1322 /* Put the scrollbar on the left of everything else... */
1323 gtk_box_pack_start(GTK_BOX(hbox
),
1324 filer_window
->scrollbar
, FALSE
, TRUE
, 0);
1326 gtk_window_set_focus(GTK_WINDOW(filer_window
->window
), collection
);
1328 gtk_widget_show(hbox
);
1329 gtk_widget_show(vbox
);
1330 gtk_widget_show(filer_window
->scrollbar
);
1331 gtk_widget_show(collection
);
1333 gtk_widget_realize(filer_window
->window
);
1335 gdk_window_set_role(filer_window
->window
->window
,
1336 filer_window
->sym_path
);
1338 filer_window_set_size(filer_window
, 4, 4, TRUE
);
1341 static void filer_add_signals(FilerWindow
*filer_window
)
1343 GtkObject
*collection
= GTK_OBJECT(filer_window
->collection
);
1344 GtkTargetEntry target_table
[] =
1346 {"text/uri-list", 0, TARGET_URI_LIST
},
1347 {"STRING", 0, TARGET_STRING
},
1348 {"COMPOUND_TEXT", 0, TARGET_STRING
},/* XXX: Treats as STRING */
1351 /* Events on the top-level window */
1352 gtk_widget_add_events(filer_window
->window
, GDK_ENTER_NOTIFY
);
1353 g_signal_connect(filer_window
->window
, "enter-notify-event",
1354 G_CALLBACK(pointer_in
), filer_window
);
1355 g_signal_connect(filer_window
->window
, "leave-notify-event",
1356 G_CALLBACK(pointer_out
), filer_window
);
1357 g_signal_connect(filer_window
->window
, "destroy",
1358 G_CALLBACK(filer_window_destroyed
), filer_window
);
1360 /* Events on the collection widget */
1361 gtk_widget_set_events(GTK_WIDGET(collection
),
1362 GDK_BUTTON1_MOTION_MASK
| GDK_BUTTON2_MOTION_MASK
|
1363 GDK_BUTTON3_MOTION_MASK
| GDK_POINTER_MOTION_MASK
|
1364 GDK_BUTTON_PRESS_MASK
| GDK_BUTTON_RELEASE_MASK
);
1366 g_signal_connect(collection
, "selection_get",
1367 G_CALLBACK(selection_get
), NULL
);
1368 gtk_selection_add_targets(GTK_WIDGET(collection
), GDK_SELECTION_PRIMARY
,
1370 sizeof(target_table
) / sizeof(*target_table
));
1372 g_signal_connect(filer_window
->window
, "key_press_event",
1373 G_CALLBACK(key_press_event
), filer_window
);
1375 /* Drag and drop events */
1376 g_signal_connect(collection
, "drag_data_get",
1377 GTK_SIGNAL_FUNC(drag_data_get
), NULL
);
1378 drag_set_dest(filer_window
);
1381 static gint
clear_scanning_display(FilerWindow
*filer_window
)
1383 if (filer_exists(filer_window
))
1384 filer_set_title(filer_window
);
1388 static void set_scanning_display(FilerWindow
*filer_window
, gboolean scanning
)
1390 if (scanning
== filer_window
->scanning
)
1392 filer_window
->scanning
= scanning
;
1395 filer_set_title(filer_window
);
1397 gtk_timeout_add(300, (GtkFunction
) clear_scanning_display
,
1401 /* Note that filer_window may not exist after this call */
1402 void filer_update_dir(FilerWindow
*filer_window
, gboolean warning
)
1404 if (may_rescan(filer_window
, warning
))
1405 dir_update(filer_window
->directory
, filer_window
->sym_path
);
1408 void filer_update_all(void)
1410 GList
*next
= all_filer_windows
;
1414 FilerWindow
*filer_window
= (FilerWindow
*) next
->data
;
1416 /* Updating directory may remove it from list -- stop sending
1417 * patches to move this line!
1421 filer_update_dir(filer_window
, TRUE
);
1425 /* Refresh the various caches even if we don't think we need to */
1426 void full_refresh(void)
1431 /* See whether a filer window with a given path already exists
1432 * and is different from diff.
1434 static FilerWindow
*find_filer_window(const char *sym_path
, FilerWindow
*diff
)
1438 for (next
= all_filer_windows
; next
; next
= next
->next
)
1440 FilerWindow
*filer_window
= (FilerWindow
*) next
->data
;
1442 if (filer_window
!= diff
&&
1443 strcmp(sym_path
, filer_window
->sym_path
) == 0)
1444 return filer_window
;
1450 /* This path has been mounted/umounted/deleted some files - update all dirs */
1451 void filer_check_mounted(const char *real_path
)
1453 GList
*next
= all_filer_windows
;
1457 len
= strlen(real_path
);
1461 FilerWindow
*filer_window
= (FilerWindow
*) next
->data
;
1465 if (strncmp(real_path
, filer_window
->real_path
, len
) == 0)
1467 char s
= filer_window
->real_path
[len
];
1469 if (s
== '/' || s
== '\0')
1470 filer_update_dir(filer_window
, FALSE
);
1474 parent
= g_dirname(real_path
);
1475 refresh_dirs(parent
);
1478 icons_may_update(real_path
);
1481 /* Close all windows displaying 'path' or subdirectories of 'path' */
1482 void filer_close_recursive(const char *path
)
1484 GList
*next
= all_filer_windows
;
1488 real
= pathdup(path
);
1493 FilerWindow
*filer_window
= (FilerWindow
*) next
->data
;
1497 if (strncmp(real
, filer_window
->real_path
, len
) == 0)
1499 char s
= filer_window
->real_path
[len
];
1501 if (len
== 1 || s
== '/' || s
== '\0')
1502 gtk_widget_destroy(filer_window
->window
);
1507 /* Like minibuffer_show(), except that:
1508 * - It returns FALSE (to be used from an idle callback)
1509 * - It checks that the filer window still exists.
1511 static gboolean
minibuffer_show_cb(FilerWindow
*filer_window
)
1513 if (filer_exists(filer_window
))
1514 minibuffer_show(filer_window
, MINI_PATH
);
1518 /* TRUE iff filer_window points to an existing FilerWindow
1521 gboolean
filer_exists(FilerWindow
*filer_window
)
1525 for (next
= all_filer_windows
; next
; next
= next
->next
)
1527 FilerWindow
*fw
= (FilerWindow
*) next
->data
;
1529 if (fw
== filer_window
)
1536 /* Make sure the window title is up-to-date */
1537 void filer_set_title(FilerWindow
*filer_window
)
1539 guchar
*title
= NULL
;
1542 if (filer_window
->scanning
|| filer_window
->show_hidden
||
1543 filer_window
->show_thumbs
)
1545 if (o_short_flag_names
.int_value
)
1547 flags
= g_strconcat(" +",
1548 filer_window
->scanning
? _("S") : "",
1549 filer_window
->show_hidden
? _("A") : "",
1550 filer_window
->show_thumbs
? _("T") : "",
1555 flags
= g_strconcat(" (",
1556 filer_window
->scanning
? _("Scanning, ") : "",
1557 filer_window
->show_hidden
? _("All, ") : "",
1558 filer_window
->show_thumbs
? _("Thumbs, ") : "",
1560 flags
[strlen(flags
) - 2] = ')';
1565 title
= g_strconcat("//", our_host_name(),
1566 filer_window
->sym_path
, flags
, NULL
);
1568 if (!title
&& home_dir_len
> 1 &&
1569 strncmp(filer_window
->sym_path
, home_dir
, home_dir_len
) == 0)
1571 guchar sep
= filer_window
->sym_path
[home_dir_len
];
1573 if (sep
== '\0' || sep
== '/')
1574 title
= g_strconcat("~",
1575 filer_window
->sym_path
+ home_dir_len
,
1581 title
= g_strconcat(filer_window
->sym_path
, flags
, NULL
);
1583 gtk_window_set_title(GTK_WINDOW(filer_window
->window
), title
);
1586 if (flags
[0] != '\0')
1590 /* Reconnect to the same directory (used when the Show Hidden option is
1591 * toggled). This has the side-effect of updating the window title.
1593 void filer_detach_rescan(FilerWindow
*filer_window
)
1595 Directory
*dir
= filer_window
->directory
;
1598 detach(filer_window
);
1599 filer_window
->directory
= dir
;
1600 attach(filer_window
);
1603 /* Puts the filer window into target mode. When an item is chosen,
1604 * fn(filer_window, item, data) is called. 'reason' will be displayed
1605 * on the toolbar while target mode is active.
1607 * Use fn == NULL to cancel target mode.
1609 void filer_target_mode(FilerWindow
*filer_window
,
1614 TargetFunc old_fn
= filer_window
->target_cb
;
1617 gdk_window_set_cursor(
1618 GTK_WIDGET(filer_window
->collection
)->window
,
1619 fn
? crosshair
: NULL
);
1621 filer_window
->target_cb
= fn
;
1622 filer_window
->target_data
= data
;
1624 if (filer_window
->toolbar_text
== NULL
)
1629 GTK_LABEL(filer_window
->toolbar_text
), reason
);
1630 else if (o_toolbar_info
.int_value
)
1633 toolbar_update_info(filer_window
);
1636 gtk_label_set_text(GTK_LABEL(filer_window
->toolbar_text
), "");
1639 static void set_selection_state(FilerWindow
*filer_window
, gboolean normal
)
1641 GtkStateType old_state
= filer_window
->selection_state
;
1643 filer_window
->selection_state
= normal
1644 ? GTK_STATE_SELECTED
: GTK_STATE_INSENSITIVE
;
1646 if (old_state
!= filer_window
->selection_state
1647 && filer_window
->collection
->number_selected
)
1648 gtk_widget_queue_draw(GTK_WIDGET(filer_window
->collection
));
1651 void filer_cancel_thumbnails(FilerWindow
*filer_window
)
1653 gtk_widget_hide(filer_window
->thumb_bar
);
1655 g_list_foreach(filer_window
->thumb_queue
, (GFunc
) g_free
, NULL
);
1656 g_list_free(filer_window
->thumb_queue
);
1657 filer_window
->thumb_queue
= NULL
;
1658 filer_window
->max_thumbs
= 0;
1661 /* Generate the next thumb for this window. The collection object is
1662 * unref'd when there is nothing more to do.
1663 * If the collection no longer has a filer window, nothing is done.
1665 static gboolean
filer_next_thumb_real(GObject
*window
)
1667 FilerWindow
*filer_window
;
1671 filer_window
= g_object_get_data(window
, "filer_window");
1675 g_object_unref(window
);
1679 if (!filer_window
->thumb_queue
)
1681 filer_cancel_thumbnails(filer_window
);
1682 g_object_unref(window
);
1686 total
= filer_window
->max_thumbs
;
1687 done
= total
- g_list_length(filer_window
->thumb_queue
);
1689 path
= (gchar
*) filer_window
->thumb_queue
->data
;
1691 pixmap_background_thumb(path
, (GFunc
) filer_next_thumb
, window
);
1693 filer_window
->thumb_queue
= g_list_remove(filer_window
->thumb_queue
,
1697 gtk_progress_bar_set_fraction(
1698 GTK_PROGRESS_BAR(filer_window
->thumb_progress
),
1699 done
/ (float) total
);
1704 /* path is the thumb just loaded, if any.
1705 * collection is unref'd (eventually).
1707 static void filer_next_thumb(GObject
*window
, const gchar
*path
)
1710 dir_force_update_path(path
);
1712 gtk_idle_add((GtkFunction
) filer_next_thumb_real
, window
);
1715 static void start_thumb_scanning(FilerWindow
*filer_window
)
1717 if (GTK_WIDGET_VISIBLE(filer_window
->thumb_bar
))
1718 return; /* Already scanning */
1720 gtk_widget_show_all(filer_window
->thumb_bar
);
1722 g_object_ref(G_OBJECT(filer_window
->window
));
1723 filer_next_thumb(G_OBJECT(filer_window
->window
), NULL
);
1726 /* Set this image to be loaded some time in the future */
1727 void filer_create_thumb(FilerWindow
*filer_window
, const gchar
*path
)
1729 filer_window
->max_thumbs
++;
1731 filer_window
->thumb_queue
= g_list_append(filer_window
->thumb_queue
,
1734 if (filer_window
->scanning
)
1735 return; /* Will start when scan ends */
1737 start_thumb_scanning(filer_window
);
1740 /* If thumbnail display is on, look through all the items in this directory
1741 * and start creating or updating the thumbnails as needed.
1743 void filer_create_thumbs(FilerWindow
*filer_window
)
1748 if (!filer_window
->show_thumbs
)
1751 view_get_iter(filer_window
->view
, &iter
, 0);
1753 while ((item
= iter
.next(&iter
)))
1755 MaskedPixmap
*pixmap
;
1759 if (item
->base_type
!= TYPE_FILE
)
1762 if (strcmp(item
->mime_type
->media_type
, "image") != 0)
1765 path
= make_path(filer_window
->real_path
, item
->leafname
)->str
;
1767 pixmap
= g_fscache_lookup_full(pixmap_cache
, path
,
1768 FSCACHE_LOOKUP_ONLY_NEW
, &found
);
1770 g_object_unref(pixmap
);
1772 /* If we didn't get an image, it could be because:
1774 * - We're loading the image now. found is TRUE,
1775 * and we'll update the item later.
1776 * - We tried to load the image and failed. found
1778 * - We haven't tried loading the image. found is
1779 * FALSE, and we start creating the thumb here.
1782 filer_create_thumb(filer_window
, path
);
1786 static void filer_options_changed(void)
1788 if (o_short_flag_names
.has_changed
)
1792 for (next
= all_filer_windows
; next
; next
= next
->next
)
1794 FilerWindow
*filer_window
= (FilerWindow
*) next
->data
;
1796 filer_set_title(filer_window
);
1801 /* Change to Large or Small icons depending on the number of items
1802 * in the directory, subject to options.
1804 static void set_style_by_number_of_items(FilerWindow
*filer_window
)
1808 g_return_if_fail(filer_window
!= NULL
);
1810 if (!o_filer_change_size
.int_value
)
1811 return; /* Don't auto-set style */
1813 if (filer_window
->display_style
!= LARGE_ICONS
&&
1814 filer_window
->display_style
!= SMALL_ICONS
)
1815 return; /* Only change between these two styles */
1817 n
= filer_window
->collection
->number_of_items
;
1819 if (n
>= o_filer_change_size_num
.int_value
)
1820 display_set_layout(filer_window
, SMALL_ICONS
,
1821 filer_window
->details_type
);
1823 display_set_layout(filer_window
, LARGE_ICONS
,
1824 filer_window
->details_type
);
1827 /* Append interesting information to this GString */
1828 void filer_add_tip_details(FilerWindow
*filer_window
,
1829 GString
*tip
, DirItem
*item
)
1831 guchar
*fullpath
= NULL
;
1833 fullpath
= make_path(filer_window
->real_path
, item
->leafname
)->str
;
1835 if (item
->flags
& ITEM_FLAG_SYMLINK
)
1839 target
= readlink_dup(fullpath
);
1842 g_string_append(tip
, _("Symbolic link to "));
1843 g_string_append(tip
, target
);
1844 g_string_append_c(tip
, '\n');
1849 if (item
->flags
& ITEM_FLAG_APPDIR
)
1854 info
= appinfo_get(fullpath
, item
);
1855 if (info
&& ((node
= xml_get_section(info
, NULL
, "Summary"))))
1858 str
= xmlNodeListGetString(node
->doc
,
1859 node
->xmlChildrenNode
, 1);
1862 g_string_append(tip
, str
);
1863 g_string_append_c(tip
, '\n');
1868 g_object_unref(info
);
1871 if (!g_utf8_validate(item
->leafname
, -1, NULL
))
1872 g_string_append(tip
,
1873 _("This filename is not valid UTF-8. "
1874 "You should rename it.\n"));