r1859: New 'Class' parameter to Filer_OpenDir SOAP method allows setting the
[rox-filer.git] / ROX-Filer / src / filer.c
blob54bb2577ec8612c0377acaa2cd107fad4072b826
1 /*
2 * $Id$
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)
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 /* filer.c - code for handling filer windows */
24 #include "config.h"
26 #include <stdlib.h>
27 #include <stdio.h>
28 #include <string.h>
29 #include <errno.h>
30 #include <ctype.h>
31 #include <netdb.h>
32 #include <sys/param.h>
34 #include <gtk/gtk.h>
35 #include <gdk/gdkx.h>
36 #include <gdk/gdkkeysyms.h>
38 #include "global.h"
40 #include "display.h"
41 #include "main.h"
42 #include "fscache.h"
43 #include "support.h"
44 #include "gui_support.h"
45 #include "filer.h"
46 #include "choices.h"
47 #include "pixmaps.h"
48 #include "menu.h"
49 #include "dnd.h"
50 #include "dir.h"
51 #include "diritem.h"
52 #include "run.h"
53 #include "type.h"
54 #include "options.h"
55 #include "minibuffer.h"
56 #include "icon.h"
57 #include "toolbar.h"
58 #include "bind.h"
59 #include "appinfo.h"
60 #include "mount.h"
61 #include "xml.h"
62 #include "view_iface.h"
63 #include "view_collection.h"
65 static XMLwrapper *groups = NULL;
67 /* This is rather badly named. It's actually the filer window which received
68 * the last key press or Menu click event.
70 FilerWindow *window_with_focus = NULL;
72 GList *all_filer_windows = NULL;
74 static FilerWindow *window_with_primary = NULL;
76 /* Static prototypes */
77 static void attach(FilerWindow *filer_window);
78 static void detach(FilerWindow *filer_window);
79 static void filer_window_destroyed(GtkWidget *widget,
80 FilerWindow *filer_window);
81 static void update_display(Directory *dir,
82 DirAction action,
83 GPtrArray *items,
84 FilerWindow *filer_window);
85 static void set_scanning_display(FilerWindow *filer_window, gboolean scanning);
86 static gboolean may_rescan(FilerWindow *filer_window, gboolean warning);
87 static gboolean minibuffer_show_cb(FilerWindow *filer_window);
88 static FilerWindow *find_filer_window(const char *sym_path, FilerWindow *diff);
89 static void filer_add_widgets(FilerWindow *filer_window, const gchar *wm_class);
90 static void filer_add_signals(FilerWindow *filer_window);
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_short_flag_names;
108 Option o_filer_auto_resize, o_unique_filer_windows;
109 Option o_filer_size_limit;
111 void filer_init(void)
113 const gchar *ohost;
114 const gchar *dpy;
115 gchar *dpyhost, *tmp;
117 option_add_int(&o_filer_size_limit, "filer_size_limit", 75);
118 option_add_int(&o_filer_auto_resize, "filer_auto_resize",
119 RESIZE_ALWAYS);
120 option_add_int(&o_unique_filer_windows, "filer_unique_windows", 0);
122 option_add_int(&o_short_flag_names, "filer_short_flag_names", FALSE);
124 option_add_int(&o_filer_change_size, "filer_change_size", TRUE);
125 option_add_int(&o_filer_change_size_num, "filer_change_size_num", 30);
127 option_add_notify(filer_options_changed);
129 busy_cursor = gdk_cursor_new(GDK_WATCH);
130 crosshair = gdk_cursor_new(GDK_CROSSHAIR);
132 /* Is the display on the local machine, or are we being
133 * run remotely? See filer_set_title().
135 ohost = our_host_name();
136 dpy = gdk_get_display();
137 dpyhost = g_strdup(dpy);
138 tmp = strchr(dpyhost, ':');
139 if (tmp)
140 *tmp = '\0';
142 if (dpyhost[0] && strcmp(ohost, dpyhost) != 0)
144 /* Try the cannonical name for dpyhost (see our_host_name()
145 * in support.c).
147 struct hostent *ent;
149 ent = gethostbyname(dpyhost);
150 if (!ent || strcmp(ohost, ent->h_name) != 0)
151 not_local = TRUE;
154 g_free(dpyhost);
157 static gboolean if_deleted(gpointer item, gpointer removed)
159 int i = ((GPtrArray *) removed)->len;
160 DirItem **r = (DirItem **) ((GPtrArray *) removed)->pdata;
161 char *leafname = ((DirItem *) item)->leafname;
163 while (i--)
165 if (strcmp(leafname, r[i]->leafname) == 0)
166 return TRUE;
169 return FALSE;
172 /* Resize the filer window to w x h pixels, plus border (not clamped).
173 * If triggered by a key event, warp the pointer (for SloppyFocus users).
175 void filer_window_set_size(FilerWindow *filer_window, int w, int h)
177 GdkEvent *event;
178 GtkWidget *window;
180 g_return_if_fail(filer_window != NULL);
182 if (filer_window->scrollbar)
183 w += filer_window->scrollbar->allocation.width;
185 if (o_toolbar.int_value != TOOLBAR_NONE)
186 h += filer_window->toolbar->allocation.height;
187 if (filer_window->message)
188 h += filer_window->message->allocation.height;
190 window = filer_window->window;
192 if (GTK_WIDGET_VISIBLE(window))
194 gint x, y;
195 GtkRequisition *req = &window->requisition;
196 GdkWindow *gdk_window = window->window;
198 w = MAX(req->width, w);
199 h = MAX(req->height, h);
200 gdk_window_get_position(gdk_window, &x, &y);
202 if (x + w > screen_width || y + h > screen_height)
204 if (x + w > screen_width)
205 x = screen_width - w - 4;
206 if (y + h > screen_height)
207 y = screen_height - h - 4;
208 gdk_window_move_resize(gdk_window, x, y, w, h);
210 else
211 gdk_window_resize(gdk_window, w, h);
213 else
214 gtk_window_set_default_size(GTK_WINDOW(window), w, h);
216 event = gtk_get_current_event();
217 if (event && event->type == GDK_KEY_PRESS)
219 GdkWindow *win = filer_window->window->window;
221 XWarpPointer(gdk_x11_drawable_get_xdisplay(win),
222 None,
223 gdk_x11_drawable_get_xid(win),
224 0, 0, 0, 0,
225 w - 4, h - 4);
229 /* Resize the window to fit the items currently in the Directory.
230 * When opening a directory for the first time, the names will be known but not
231 * the types and images. We can still make a good estimate of the size.
233 void filer_window_autosize(FilerWindow *filer_window)
235 view_autosize(filer_window->view);
238 /* Called on a timeout while scanning or when scanning ends
239 * (whichever happens first).
241 static gint open_filer_window(FilerWindow *filer_window)
243 view_style_changed(filer_window->view, 0);
245 if (filer_window->open_timeout)
247 gtk_timeout_remove(filer_window->open_timeout);
248 filer_window->open_timeout = 0;
251 if (!GTK_WIDGET_VISIBLE(filer_window->window))
253 set_style_by_number_of_items(filer_window);
254 filer_window_autosize(filer_window);
255 gtk_widget_show(filer_window->window);
258 return FALSE;
261 static void update_display(Directory *dir,
262 DirAction action,
263 GPtrArray *items,
264 FilerWindow *filer_window)
266 ViewIface *view = (ViewIface *) filer_window->view;
268 switch (action)
270 case DIR_ADD:
271 view_add_items(view, items);
272 /* Open and resize if currently hidden */
273 open_filer_window(filer_window);
274 break;
275 case DIR_REMOVE:
276 view_delete_if(view, if_deleted, items);
277 break;
278 case DIR_START_SCAN:
279 set_scanning_display(filer_window, TRUE);
280 toolbar_update_info(filer_window);
281 break;
282 case DIR_END_SCAN:
283 if (filer_window->window->window)
284 gdk_window_set_cursor(
285 filer_window->window->window,
286 NULL);
287 set_scanning_display(filer_window, FALSE);
288 toolbar_update_info(filer_window);
289 open_filer_window(filer_window);
291 if (filer_window->had_cursor &&
292 !view_cursor_visible(view))
294 view_show_cursor(view);
295 filer_window->had_cursor = FALSE;
297 if (filer_window->auto_select)
298 display_set_autoselect(filer_window,
299 filer_window->auto_select);
300 g_free(filer_window->auto_select);
301 filer_window->auto_select = NULL;
303 filer_create_thumbs(filer_window);
305 if (filer_window->thumb_queue)
306 start_thumb_scanning(filer_window);
307 break;
308 case DIR_UPDATE:
309 view_update_items(view, items);
310 break;
314 static void attach(FilerWindow *filer_window)
316 gdk_window_set_cursor(filer_window->window->window, busy_cursor);
317 view_clear(filer_window->view);
318 filer_window->scanning = TRUE;
319 dir_attach(filer_window->directory, (DirCallback) update_display,
320 filer_window);
321 filer_set_title(filer_window);
324 static void detach(FilerWindow *filer_window)
326 g_return_if_fail(filer_window->directory != NULL);
328 dir_detach(filer_window->directory,
329 (DirCallback) update_display, filer_window);
330 g_object_unref(filer_window->directory);
331 filer_window->directory = NULL;
334 static void filer_window_destroyed(GtkWidget *widget,
335 FilerWindow *filer_window)
337 all_filer_windows = g_list_remove(all_filer_windows, filer_window);
339 g_object_set_data(G_OBJECT(widget), "filer_window", NULL);
341 if (window_with_primary == filer_window)
342 window_with_primary = NULL;
344 if (window_with_focus == filer_window)
346 menu_popdown();
347 window_with_focus = NULL;
350 if (filer_window->directory)
351 detach(filer_window);
353 if (filer_window->open_timeout)
355 gtk_timeout_remove(filer_window->open_timeout);
356 filer_window->open_timeout = 0;
359 if (filer_window->thumb_queue)
361 g_list_foreach(filer_window->thumb_queue, (GFunc) g_free, NULL);
362 g_list_free(filer_window->thumb_queue);
365 tooltip_show(NULL);
367 g_free(filer_window->auto_select);
368 g_free(filer_window->real_path);
369 g_free(filer_window->sym_path);
370 g_free(filer_window);
372 one_less_window();
375 /* Returns TRUE iff the directory still exists. */
376 static gboolean may_rescan(FilerWindow *filer_window, gboolean warning)
378 Directory *dir;
380 g_return_val_if_fail(filer_window != NULL, FALSE);
382 /* We do a fresh lookup (rather than update) because the inode may
383 * have changed.
385 dir = g_fscache_lookup(dir_cache, filer_window->real_path);
386 if (!dir)
388 if (warning)
389 info_message(_("Directory missing/deleted"));
390 gtk_widget_destroy(filer_window->window);
391 return FALSE;
393 if (dir == filer_window->directory)
394 g_object_unref(dir);
395 else
397 detach(filer_window);
398 filer_window->directory = dir;
399 attach(filer_window);
402 return TRUE;
405 /* No items are now selected. This might be because another app claimed
406 * the selection or because the user unselected all the items.
408 void filer_lost_selection(FilerWindow *filer_window, guint time)
410 if (window_with_primary == filer_window)
412 window_with_primary = NULL;
413 gtk_selection_owner_set(NULL, GDK_SELECTION_PRIMARY, time);
417 /* Another app has claimed the primary selection */
418 static void filer_lost_primary(GtkWidget *window,
419 GdkEventSelection *event,
420 gpointer user_data)
422 FilerWindow *filer_window = (FilerWindow *) user_data;
424 if (window_with_primary && window_with_primary == filer_window)
426 window_with_primary = NULL;
427 set_selection_state(filer_window, FALSE);
431 /* Someone wants us to send them the selection */
432 static void selection_get(GtkWidget *widget,
433 GtkSelectionData *selection_data,
434 guint info,
435 guint time,
436 gpointer data)
438 GString *reply, *header;
439 FilerWindow *filer_window = (FilerWindow *) data;
440 ViewIter iter;
441 DirItem *item;
443 reply = g_string_new(NULL);
444 header = g_string_new(NULL);
446 switch (info)
448 case TARGET_STRING:
449 g_string_sprintf(header, " %s",
450 make_path(filer_window->sym_path, "")->str);
451 break;
452 case TARGET_URI_LIST:
453 g_string_sprintf(header, " file://%s%s",
454 our_host_name_for_dnd(),
455 make_path(filer_window->sym_path, "")->str);
456 break;
459 view_get_iter(filer_window->view, &iter, VIEW_ITER_SELECTED);
461 while ((item = iter.next(&iter)))
463 g_string_append(reply, header->str);
464 g_string_append(reply, item->leafname);
467 if (reply->len > 0)
468 gtk_selection_data_set(selection_data, xa_string,
469 8, reply->str + 1, reply->len - 1);
470 else
472 g_warning("Attempt to paste empty selection!");
473 gtk_selection_data_set(selection_data, xa_string, 8, "", 0);
476 g_string_free(reply, TRUE);
477 g_string_free(header, TRUE);
480 /* Selection has been changed -- try to grab the primary selection
481 * if we don't have it. Also called when clicking on an insensitive selection
482 * to regain primary.
483 * Also updates toolbar info.
485 void filer_selection_changed(FilerWindow *filer_window, gint time)
487 toolbar_update_info(filer_window);
489 if (window_with_primary == filer_window)
490 return; /* Already got primary */
492 if (!view_count_selected(filer_window->view))
493 return; /* Nothing selected */
495 if (filer_window->temp_item_selected == FALSE &&
496 gtk_selection_owner_set(GTK_WIDGET(filer_window->window),
497 GDK_SELECTION_PRIMARY,
498 time))
500 window_with_primary = filer_window;
501 set_selection_state(filer_window, TRUE);
503 else
504 set_selection_state(filer_window, FALSE);
507 /* Open the item (or add it to the shell command minibuffer) */
508 void filer_openitem(FilerWindow *filer_window, ViewIter *iter, OpenFlags flags)
510 gboolean shift = (flags & OPEN_SHIFT) != 0;
511 gboolean close_mini = flags & OPEN_FROM_MINI;
512 gboolean close_window = (flags & OPEN_CLOSE_WINDOW) != 0;
513 DirItem *item;
514 guchar *full_path;
515 gboolean wink = TRUE;
516 Directory *old_dir;
518 g_return_if_fail(filer_window != NULL && iter != NULL);
520 item = iter->peek(iter);
522 g_return_if_fail(item != NULL);
524 if (filer_window->mini_type == MINI_SHELL)
526 minibuffer_add(filer_window, item->leafname);
527 return;
530 if (!item->image)
531 dir_update_item(filer_window->directory, item->leafname);
533 if (item->base_type == TYPE_DIRECTORY)
535 /* Never close a filer window when opening a directory
536 * (click on a dir or click on an app with shift).
538 if (shift || !(item->flags & ITEM_FLAG_APPDIR))
539 close_window = FALSE;
542 full_path = make_path(filer_window->sym_path, item->leafname)->str;
543 if (shift && (item->flags & ITEM_FLAG_SYMLINK))
544 wink = FALSE;
546 old_dir = filer_window->directory;
547 if (run_diritem(full_path, item,
548 flags & OPEN_SAME_WINDOW ? filer_window : NULL,
549 filer_window,
550 shift))
552 if (old_dir != filer_window->directory)
553 return;
555 if (close_window)
556 gtk_widget_destroy(filer_window->window);
557 else
559 if (wink)
560 view_wink_item(filer_window->view, iter);
561 if (close_mini)
562 minibuffer_hide(filer_window);
567 static gint pointer_in(GtkWidget *widget,
568 GdkEventCrossing *event,
569 FilerWindow *filer_window)
571 may_rescan(filer_window, TRUE);
572 return FALSE;
575 static gint pointer_out(GtkWidget *widget,
576 GdkEventCrossing *event,
577 FilerWindow *filer_window)
579 tooltip_show(NULL);
580 return FALSE;
583 /* Move the cursor to the next selected item in direction 'dir'
584 * (+1 or -1).
586 static void next_selected(FilerWindow *filer_window, int dir)
588 ViewIter iter, cursor;
589 gboolean have_cursor;
590 ViewIface *view = filer_window->view;
592 g_return_if_fail(dir == 1 || dir == -1);
594 view_get_cursor(view, &cursor);
595 have_cursor = cursor.peek(&cursor) != NULL;
597 view_get_iter(view, &iter,
598 VIEW_ITER_SELECTED |
599 (have_cursor ? VIEW_ITER_FROM_CURSOR : 0) |
600 (dir < 0 ? VIEW_ITER_BACKWARDS : 0));
602 if (have_cursor && view_get_selected(view, &cursor))
603 iter.next(&iter); /* Skip the cursor itself */
605 if (iter.next(&iter))
606 view_cursor_to_iter(view, &iter);
607 else
608 gdk_beep();
610 return;
613 static void return_pressed(FilerWindow *filer_window, GdkEventKey *event)
615 TargetFunc cb = filer_window->target_cb;
616 gpointer data = filer_window->target_data;
617 OpenFlags flags = 0;
618 ViewIter iter;
620 filer_target_mode(filer_window, NULL, NULL, NULL);
622 view_get_cursor(filer_window->view, &iter);
623 if (!iter.peek(&iter))
624 return;
626 if (cb)
628 cb(filer_window, &iter, data);
629 return;
632 if (event->state & GDK_SHIFT_MASK)
633 flags |= OPEN_SHIFT;
634 if (event->state & GDK_MOD1_MASK)
635 flags |= OPEN_CLOSE_WINDOW;
636 else
637 flags |= OPEN_SAME_WINDOW;
639 filer_openitem(filer_window, &iter, flags);
642 /* Makes sure that 'groups' is up-to-date, reloading from file if it has
643 * changed. If no groups were loaded and there is no file then initialised
644 * groups to an empty document.
645 * Return the node for the 'name' group.
647 static xmlNode *group_find(char *name)
649 xmlNode *node;
650 gchar *path;
652 /* Update the groups, if possible */
653 path = choices_find_path_load("Groups.xml", PROJECT);
654 if (path)
656 XMLwrapper *wrapper;
657 wrapper = xml_cache_load(path);
658 if (wrapper)
660 if (groups)
661 g_object_unref(groups);
662 groups = wrapper;
665 g_free(path);
668 if (!groups)
670 groups = xml_new(NULL);
671 groups->doc = xmlNewDoc("1.0");
673 xmlDocSetRootElement(groups->doc,
674 xmlNewDocNode(groups->doc, NULL, "groups", NULL));
675 return NULL;
678 node = xmlDocGetRootElement(groups->doc);
680 for (node = node->xmlChildrenNode; node; node = node->next)
682 guchar *gid;
684 gid = xmlGetProp(node, "name");
686 if (!gid)
687 continue;
689 if (strcmp(name, gid) != 0)
690 continue;
692 g_free(gid);
694 return node;
697 return NULL;
700 static void group_save(FilerWindow *filer_window, char *name)
702 xmlNode *group;
703 guchar *save_path;
704 DirItem *item;
705 ViewIter iter;
707 group = group_find(name);
708 if (group)
710 xmlUnlinkNode(group);
711 xmlFreeNode(group);
713 group = xmlNewChild(xmlDocGetRootElement(groups->doc),
714 NULL, "group", NULL);
715 xmlSetProp(group, "name", name);
717 xmlNewChild(group, NULL, "directory", filer_window->sym_path);
719 view_get_iter(filer_window->view, &iter, VIEW_ITER_SELECTED);
721 while ((item = iter.next(&iter)))
722 xmlNewChild(group, NULL, "item", item->leafname);
724 save_path = choices_find_path_save("Groups.xml", PROJECT, TRUE);
725 if (save_path)
727 save_xml_file(groups->doc, save_path);
728 g_free(save_path);
732 static gboolean group_restore_cb(ViewIter *iter, gpointer data)
734 GHashTable *in_group = (GHashTable *) data;
736 return g_hash_table_lookup(in_group,
737 iter->peek(iter)->leafname) != NULL;
740 static void group_restore(FilerWindow *filer_window, char *name)
742 GHashTable *in_group;
743 char *path;
744 xmlNode *group, *node;
746 group = group_find(name);
748 if (!group)
750 report_error(_("Group %s is not set. Select some files "
751 "and press Ctrl+%s to set the group. Press %s "
752 "on its own to reselect the files later.\n"
753 "Make sure NumLock is on if you use the keypad."),
754 name, name, name);
755 return;
758 node = get_subnode(group, NULL, "directory");
759 g_return_if_fail(node != NULL);
760 path = xmlNodeListGetString(groups->doc, node->xmlChildrenNode, 1);
761 g_return_if_fail(path != NULL);
763 if (strcmp(path, filer_window->sym_path) != 0)
764 filer_change_to(filer_window, path, NULL);
765 g_free(path);
767 in_group = g_hash_table_new(g_str_hash, g_str_equal);
768 for (node = group->xmlChildrenNode; node; node = node->next)
770 gchar *leaf;
771 if (node->type != XML_ELEMENT_NODE)
772 continue;
773 if (strcmp(node->name, "item") != 0)
774 continue;
776 leaf = xmlNodeListGetString(groups->doc,
777 node->xmlChildrenNode, 1);
778 if (!leaf)
779 g_warning("Missing leafname!\n");
780 else
781 g_hash_table_insert(in_group, leaf, filer_window);
784 view_select_if(filer_window->view, &group_restore_cb, in_group);
786 g_hash_table_foreach(in_group, (GHFunc) g_free, NULL);
787 g_hash_table_destroy(in_group);
790 static gboolean popup_menu(GtkWidget *widget, FilerWindow *filer_window)
792 ViewIter iter;
794 view_get_cursor(filer_window->view, &iter);
796 show_filer_menu(filer_window, NULL, &iter);
798 return TRUE;
801 /* Handle keys that can't be bound with the menu */
802 static gint key_press_event(GtkWidget *widget,
803 GdkEventKey *event,
804 FilerWindow *filer_window)
806 GtkWidget *focus = GTK_WINDOW(widget)->focus_widget;
807 guint key = event->keyval;
808 char group[2] = "1";
810 window_with_focus = filer_window;
812 /* Delay setting up the keys until now to speed loading... */
813 if (!filer_keys)
814 ensure_filer_menu(); /* Gets the keys working... */
816 if (!g_slist_find(filer_keys->acceleratables, widget))
817 gtk_window_add_accel_group(GTK_WINDOW(filer_window->window),
818 filer_keys);
820 if (focus && focus != widget &&
821 gtk_widget_get_toplevel(focus) == widget)
822 if (gtk_widget_event(focus, (GdkEvent *) event))
823 return TRUE; /* Handled */
825 switch (key)
827 case GDK_Escape:
828 filer_target_mode(filer_window, NULL, NULL, NULL);
829 return FALSE;
830 case GDK_Return:
831 return_pressed(filer_window, event);
832 break;
833 case GDK_ISO_Left_Tab:
834 next_selected(filer_window, -1);
835 break;
836 case GDK_Tab:
837 next_selected(filer_window, 1);
838 break;
839 case GDK_BackSpace:
840 change_to_parent(filer_window);
841 break;
842 case GDK_backslash:
844 ViewIter iter;
846 tooltip_show(NULL);
848 view_get_cursor(filer_window->view, &iter);
849 show_filer_menu(filer_window,
850 (GdkEvent *) event, &iter);
851 break;
853 default:
854 if (key >= GDK_0 && key <= GDK_9)
855 group[0] = key - GDK_0 + '0';
856 else if (key >= GDK_KP_0 && key <= GDK_KP_9)
857 group[0] = key - GDK_KP_0 + '0';
858 else
859 return FALSE;
862 if (event->state & GDK_CONTROL_MASK)
863 group_save(filer_window, group);
864 else
865 group_restore(filer_window, group);
868 return TRUE;
871 void filer_open_parent(FilerWindow *filer_window)
873 char *dir;
874 const char *current = filer_window->sym_path;
876 if (current[0] == '/' && current[1] == '\0')
877 return; /* Already in the root */
879 dir = g_dirname(current);
880 filer_opendir(dir, filer_window, NULL);
881 g_free(dir);
884 void change_to_parent(FilerWindow *filer_window)
886 char *dir;
887 const char *current = filer_window->sym_path;
889 if (current[0] == '/' && current[1] == '\0')
890 return; /* Already in the root */
892 dir = g_dirname(current);
893 filer_change_to(filer_window, dir, g_basename(current));
894 g_free(dir);
897 /* Removes trailing /s from path (modified in place) */
898 static void tidy_sympath(gchar *path)
900 int l;
902 g_return_if_fail(path != NULL);
904 l = strlen(path);
905 while (l > 1 && path[l - 1] == '/')
907 l--;
908 path[l] = '\0';
912 /* Make filer_window display path. When finished, highlight item 'from', or
913 * the first item if from is NULL. If there is currently no cursor then
914 * simply wink 'from' (if not NULL).
915 * If the cause was a key event and we resize, warp the pointer.
917 void filer_change_to(FilerWindow *filer_window,
918 const char *path, const char *from)
920 char *from_dup;
921 char *sym_path, *real_path;
922 Directory *new_dir;
924 g_return_if_fail(filer_window != NULL);
926 filer_cancel_thumbnails(filer_window);
928 tooltip_show(NULL);
930 sym_path = g_strdup(path);
931 real_path = pathdup(path);
932 new_dir = g_fscache_lookup(dir_cache, real_path);
934 if (!new_dir)
936 delayed_error(_("Directory '%s' is not accessible"),
937 sym_path);
938 g_free(real_path);
939 g_free(sym_path);
940 return;
943 if (o_unique_filer_windows.int_value)
945 FilerWindow *fw;
947 fw = find_filer_window(sym_path, filer_window);
948 if (fw)
949 gtk_widget_destroy(fw->window);
952 from_dup = from && *from ? g_strdup(from) : NULL;
954 detach(filer_window);
955 g_free(filer_window->real_path);
956 g_free(filer_window->sym_path);
957 filer_window->real_path = real_path;
958 filer_window->sym_path = sym_path;
959 tidy_sympath(filer_window->sym_path);
961 filer_window->directory = new_dir;
963 g_free(filer_window->auto_select);
964 filer_window->auto_select = from_dup;
966 filer_window->had_cursor = filer_window->had_cursor ||
967 view_cursor_visible(filer_window->view);
969 filer_set_title(filer_window);
970 if (filer_window->window->window)
971 gdk_window_set_role(filer_window->window->window,
972 filer_window->sym_path);
973 view_cursor_to_iter(filer_window->view, NULL);
975 attach(filer_window);
977 set_style_by_number_of_items(filer_window);
979 if (o_filer_auto_resize.int_value == RESIZE_ALWAYS)
980 filer_window_autosize(filer_window);
982 if (filer_window->mini_type == MINI_PATH)
983 gtk_idle_add((GtkFunction) minibuffer_show_cb,
984 filer_window);
987 /* Returns a list containing the full (sym) pathname of every selected item.
988 * You must g_free() each item in the list.
990 GList *filer_selected_items(FilerWindow *filer_window)
992 GList *retval = NULL;
993 guchar *dir = filer_window->sym_path;
994 ViewIter iter;
995 DirItem *item;
997 view_get_iter(filer_window->view, &iter, VIEW_ITER_SELECTED);
998 while ((item = iter.next(&iter)))
1000 retval = g_list_prepend(retval,
1001 g_strdup(make_path(dir, item->leafname)->str));
1004 return g_list_reverse(retval);
1007 /* Return the single selected item. Error if nothing is selected. */
1008 DirItem *filer_selected_item(FilerWindow *filer_window)
1010 ViewIter iter;
1011 DirItem *item;
1013 view_get_iter(filer_window->view, &iter, VIEW_ITER_SELECTED);
1015 item = iter.next(&iter);
1016 g_return_val_if_fail(item != NULL, NULL);
1017 g_return_val_if_fail(iter.next(&iter) == NULL, NULL);
1019 return item;
1022 /* Creates and shows a new filer window.
1023 * If src_win != NULL then display options can be taken from that source window.
1024 * Returns the new filer window, or NULL on error.
1025 * Note: if unique windows is in use, may return an existing window.
1027 FilerWindow *filer_opendir(const char *path, FilerWindow *src_win, const gchar *wm_class)
1029 FilerWindow *filer_window;
1030 char *real_path;
1031 DisplayStyle dstyle;
1032 DetailsType dtype;
1034 /* Get the real pathname of the directory and copy it */
1035 real_path = pathdup(path);
1037 if (o_unique_filer_windows.int_value)
1039 FilerWindow *same_dir_window;
1041 same_dir_window = find_filer_window(path, NULL);
1043 if (same_dir_window)
1045 gtk_window_present(GTK_WINDOW(same_dir_window->window));
1046 return same_dir_window;
1050 filer_window = g_new(FilerWindow, 1);
1051 filer_window->message = NULL;
1052 filer_window->minibuffer = NULL;
1053 filer_window->minibuffer_label = NULL;
1054 filer_window->minibuffer_area = NULL;
1055 filer_window->temp_show_hidden = FALSE;
1056 filer_window->sym_path = g_strdup(path);
1057 filer_window->real_path = real_path;
1058 filer_window->scanning = FALSE;
1059 filer_window->had_cursor = FALSE;
1060 filer_window->auto_select = NULL;
1061 filer_window->toolbar_text = NULL;
1062 filer_window->target_cb = NULL;
1063 filer_window->mini_type = MINI_NONE;
1064 filer_window->selection_state = GTK_STATE_INSENSITIVE;
1065 filer_window->toolbar = NULL;
1066 filer_window->toplevel_vbox = NULL;
1068 tidy_sympath(filer_window->sym_path);
1070 /* Finds the entry for this directory in the dir cache, creating
1071 * a new one if needed. This does not cause a scan to start,
1072 * so if a new entry is created then it will be empty.
1074 filer_window->directory = g_fscache_lookup(dir_cache, real_path);
1075 if (!filer_window->directory)
1077 delayed_error(_("Directory '%s' not found."), path);
1078 g_free(filer_window->real_path);
1079 g_free(filer_window->sym_path);
1080 g_free(filer_window);
1081 return NULL;
1084 filer_window->temp_item_selected = FALSE;
1085 filer_window->flags = (FilerFlags) 0;
1086 filer_window->details_type = DETAILS_SUMMARY;
1087 filer_window->display_style = UNKNOWN_STYLE;
1088 filer_window->thumb_queue = NULL;
1089 filer_window->max_thumbs = 0;
1091 if (src_win && o_display_inherit_options.int_value)
1093 filer_window->sort_fn = src_win->sort_fn;
1094 dstyle = src_win->display_style;
1095 dtype = src_win->details_type;
1096 filer_window->show_hidden = src_win->show_hidden;
1097 filer_window->show_thumbs = src_win->show_thumbs;
1099 else
1101 int i = o_display_sort_by.int_value;
1102 filer_window->sort_fn = i == 0 ? sort_by_name :
1103 i == 1 ? sort_by_type :
1104 i == 2 ? sort_by_date :
1105 sort_by_size;
1107 dstyle = o_display_size.int_value;
1108 dtype = o_display_details.int_value;
1109 filer_window->show_hidden =
1110 o_display_show_hidden.int_value;
1111 filer_window->show_thumbs =
1112 o_display_show_thumbs.int_value;
1115 /* Add all the user-interface elements & realise */
1116 filer_add_widgets(filer_window, wm_class);
1117 if (src_win)
1118 gtk_window_set_position(GTK_WINDOW(filer_window->window),
1119 GTK_WIN_POS_MOUSE);
1121 /* Connect to all the signal handlers */
1122 filer_add_signals(filer_window);
1124 display_set_layout(filer_window, dstyle, dtype);
1126 /* Open the window after a timeout, or when scanning stops.
1127 * Do this before attaching, because attach() might tell us to
1128 * stop scanning (if a scan isn't needed).
1130 filer_window->open_timeout = gtk_timeout_add(500,
1131 (GtkFunction) open_filer_window,
1132 filer_window);
1134 /* The view is created empty and then attach() is called, which
1135 * links the filer window to the entry in the directory cache we
1136 * looked up / created above.
1138 * The attach() function will immediately callback to the filer window
1139 * to deliver a list of all known entries in the directory (so,
1140 * the number of items will be known after attach() returns).
1142 * If the directory was not in the cache (because it hadn't been
1143 * opened it before) then the types and icons for the entries are
1144 * not know, but the list of names is.
1147 attach(filer_window);
1149 number_of_windows++;
1150 all_filer_windows = g_list_prepend(all_filer_windows, filer_window);
1152 return filer_window;
1155 /* This adds all the widgets to a new filer window. It is in a separate
1156 * function because filer_opendir() was getting too long...
1158 static void filer_add_widgets(FilerWindow *filer_window, const gchar *wm_class)
1160 GtkWidget *hbox, *vbox;
1162 /* Create the top-level window widget */
1163 filer_window->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1164 filer_set_title(filer_window);
1165 if (wm_class)
1166 gtk_window_set_wmclass(GTK_WINDOW(filer_window->window), wm_class, PROJECT);
1168 /* This property is cleared when the window is destroyed.
1169 * You can thus ref filer_window->window and use this to see
1170 * if the window no longer exists.
1172 g_object_set_data(G_OBJECT(filer_window->window),
1173 "filer_window", filer_window);
1175 /* Create this now to make the Adjustment before the View */
1176 filer_window->scrollbar = gtk_vscrollbar_new(NULL);
1178 /* The view is the area that actually displays the files */
1179 filer_window->view = VIEW(view_collection_new(filer_window));
1180 gtk_widget_show(GTK_WIDGET(filer_window->view));
1182 /* Scrollbar on the right, everything else on the left */
1183 hbox = gtk_hbox_new(FALSE, 0);
1184 gtk_container_add(GTK_CONTAINER(filer_window->window), hbox);
1186 vbox = gtk_vbox_new(FALSE, 0);
1187 gtk_box_pack_start_defaults(GTK_BOX(hbox), vbox);
1188 filer_window->toplevel_vbox = GTK_BOX(vbox);
1190 /* If we want a toolbar, create it now */
1191 toolbar_update_toolbar(filer_window);
1193 /* If there's a message that should be displayed in each window (eg
1194 * 'Running as root'), add it here.
1196 if (show_user_message)
1198 filer_window->message = gtk_label_new(show_user_message);
1199 gtk_box_pack_start(GTK_BOX(vbox), filer_window->message,
1200 FALSE, TRUE, 0);
1201 gtk_widget_show(filer_window->message);
1204 /* Now add the area for displaying the files */
1205 gtk_box_pack_start_defaults(GTK_BOX(vbox),
1206 GTK_WIDGET(filer_window->view));
1208 /* And the minibuffer (hidden to start with) */
1209 create_minibuffer(filer_window);
1210 gtk_box_pack_start(GTK_BOX(vbox), filer_window->minibuffer_area,
1211 FALSE, TRUE, 0);
1213 /* And the thumbnail progress bar (also hidden) */
1215 GtkWidget *cancel;
1217 filer_window->thumb_bar = gtk_hbox_new(FALSE, 2);
1218 gtk_box_pack_start(GTK_BOX(vbox), filer_window->thumb_bar,
1219 FALSE, TRUE, 0);
1221 filer_window->thumb_progress = gtk_progress_bar_new();
1223 gtk_box_pack_start(GTK_BOX(filer_window->thumb_bar),
1224 filer_window->thumb_progress, TRUE, TRUE, 0);
1226 cancel = gtk_button_new_with_label(_("Cancel"));
1227 GTK_WIDGET_UNSET_FLAGS(cancel, GTK_CAN_FOCUS);
1228 gtk_box_pack_start(GTK_BOX(filer_window->thumb_bar),
1229 cancel, FALSE, TRUE, 0);
1230 g_signal_connect_swapped(cancel, "clicked",
1231 G_CALLBACK(filer_cancel_thumbnails),
1232 filer_window);
1235 /* Put the scrollbar on the left of everything else... */
1236 gtk_box_pack_start(GTK_BOX(hbox),
1237 filer_window->scrollbar, FALSE, TRUE, 0);
1239 gtk_widget_show(hbox);
1240 gtk_widget_show(vbox);
1241 gtk_widget_show(filer_window->scrollbar);
1243 gtk_widget_realize(filer_window->window);
1245 gdk_window_set_role(filer_window->window->window,
1246 filer_window->sym_path);
1248 filer_window_set_size(filer_window, 4, 4);
1251 static void filer_add_signals(FilerWindow *filer_window)
1253 GtkTargetEntry target_table[] =
1255 {"text/uri-list", 0, TARGET_URI_LIST},
1256 {"STRING", 0, TARGET_STRING},
1257 {"COMPOUND_TEXT", 0, TARGET_STRING},/* XXX: Treats as STRING */
1260 /* Events on the top-level window */
1261 gtk_widget_add_events(filer_window->window, GDK_ENTER_NOTIFY);
1262 g_signal_connect(filer_window->window, "enter-notify-event",
1263 G_CALLBACK(pointer_in), filer_window);
1264 g_signal_connect(filer_window->window, "leave-notify-event",
1265 G_CALLBACK(pointer_out), filer_window);
1266 g_signal_connect(filer_window->window, "destroy",
1267 G_CALLBACK(filer_window_destroyed), filer_window);
1269 g_signal_connect(filer_window->window, "selection_clear_event",
1270 G_CALLBACK(filer_lost_primary), filer_window);
1272 g_signal_connect(filer_window->window, "selection_get",
1273 G_CALLBACK(selection_get), filer_window);
1274 gtk_selection_add_targets(GTK_WIDGET(filer_window->window),
1275 GDK_SELECTION_PRIMARY,
1276 target_table,
1277 sizeof(target_table) / sizeof(*target_table));
1279 g_signal_connect(filer_window->window, "popup-menu",
1280 G_CALLBACK(popup_menu), filer_window);
1281 g_signal_connect(filer_window->window, "key_press_event",
1282 G_CALLBACK(key_press_event), filer_window);
1285 static gint clear_scanning_display(FilerWindow *filer_window)
1287 if (filer_exists(filer_window))
1288 filer_set_title(filer_window);
1289 return FALSE;
1292 static void set_scanning_display(FilerWindow *filer_window, gboolean scanning)
1294 if (scanning == filer_window->scanning)
1295 return;
1296 filer_window->scanning = scanning;
1298 if (scanning)
1299 filer_set_title(filer_window);
1300 else
1301 gtk_timeout_add(300, (GtkFunction) clear_scanning_display,
1302 filer_window);
1305 /* Note that filer_window may not exist after this call */
1306 void filer_update_dir(FilerWindow *filer_window, gboolean warning)
1308 if (may_rescan(filer_window, warning))
1309 dir_update(filer_window->directory, filer_window->sym_path);
1312 void filer_update_all(void)
1314 GList *next = all_filer_windows;
1316 while (next)
1318 FilerWindow *filer_window = (FilerWindow *) next->data;
1320 /* Updating directory may remove it from list -- stop sending
1321 * patches to move this line!
1323 next = next->next;
1325 filer_update_dir(filer_window, TRUE);
1329 /* Refresh the various caches even if we don't think we need to */
1330 void full_refresh(void)
1332 mount_update(TRUE);
1333 reread_mime_files();
1336 /* See whether a filer window with a given path already exists
1337 * and is different from diff.
1339 static FilerWindow *find_filer_window(const char *sym_path, FilerWindow *diff)
1341 GList *next;
1343 for (next = all_filer_windows; next; next = next->next)
1345 FilerWindow *filer_window = (FilerWindow *) next->data;
1347 if (filer_window != diff &&
1348 strcmp(sym_path, filer_window->sym_path) == 0)
1349 return filer_window;
1352 return NULL;
1355 /* This path has been mounted/umounted/deleted some files - update all dirs */
1356 void filer_check_mounted(const char *real_path)
1358 GList *next = all_filer_windows;
1359 gchar *parent;
1360 int len;
1362 len = strlen(real_path);
1364 while (next)
1366 FilerWindow *filer_window = (FilerWindow *) next->data;
1368 next = next->next;
1370 if (strncmp(real_path, filer_window->real_path, len) == 0)
1372 char s = filer_window->real_path[len];
1374 if (s == '/' || s == '\0')
1375 filer_update_dir(filer_window, FALSE);
1379 parent = g_dirname(real_path);
1380 refresh_dirs(parent);
1381 g_free(parent);
1383 icons_may_update(real_path);
1386 /* Close all windows displaying 'path' or subdirectories of 'path' */
1387 void filer_close_recursive(const char *path)
1389 GList *next = all_filer_windows;
1390 gchar *real;
1391 int len;
1393 real = pathdup(path);
1394 len = strlen(real);
1396 while (next)
1398 FilerWindow *filer_window = (FilerWindow *) next->data;
1400 next = next->next;
1402 if (strncmp(real, filer_window->real_path, len) == 0)
1404 char s = filer_window->real_path[len];
1406 if (len == 1 || s == '/' || s == '\0')
1407 gtk_widget_destroy(filer_window->window);
1412 /* Like minibuffer_show(), except that:
1413 * - It returns FALSE (to be used from an idle callback)
1414 * - It checks that the filer window still exists.
1416 static gboolean minibuffer_show_cb(FilerWindow *filer_window)
1418 if (filer_exists(filer_window))
1419 minibuffer_show(filer_window, MINI_PATH);
1420 return FALSE;
1423 /* TRUE iff filer_window points to an existing FilerWindow
1424 * structure.
1426 gboolean filer_exists(FilerWindow *filer_window)
1428 GList *next;
1430 for (next = all_filer_windows; next; next = next->next)
1432 FilerWindow *fw = (FilerWindow *) next->data;
1434 if (fw == filer_window)
1435 return TRUE;
1438 return FALSE;
1441 /* Make sure the window title is up-to-date */
1442 void filer_set_title(FilerWindow *filer_window)
1444 guchar *title = NULL;
1445 guchar *flags = "";
1447 if (filer_window->scanning || filer_window->show_hidden ||
1448 filer_window->show_thumbs)
1450 if (o_short_flag_names.int_value)
1452 flags = g_strconcat(" +",
1453 filer_window->scanning ? _("S") : "",
1454 filer_window->show_hidden ? _("A") : "",
1455 filer_window->show_thumbs ? _("T") : "",
1456 NULL);
1458 else
1460 flags = g_strconcat(" (",
1461 filer_window->scanning ? _("Scanning, ") : "",
1462 filer_window->show_hidden ? _("All, ") : "",
1463 filer_window->show_thumbs ? _("Thumbs, ") : "",
1464 NULL);
1465 flags[strlen(flags) - 2] = ')';
1469 if (not_local)
1470 title = g_strconcat("//", our_host_name(),
1471 filer_window->sym_path, flags, NULL);
1473 if (!title && home_dir_len > 1 &&
1474 strncmp(filer_window->sym_path, home_dir, home_dir_len) == 0)
1476 guchar sep = filer_window->sym_path[home_dir_len];
1478 if (sep == '\0' || sep == '/')
1479 title = g_strconcat("~",
1480 filer_window->sym_path + home_dir_len,
1481 flags,
1482 NULL);
1485 if (!title)
1486 title = g_strconcat(filer_window->sym_path, flags, NULL);
1488 gtk_window_set_title(GTK_WINDOW(filer_window->window), title);
1489 g_free(title);
1491 if (flags[0] != '\0')
1492 g_free(flags);
1495 /* Reconnect to the same directory (used when the Show Hidden option is
1496 * toggled). This has the side-effect of updating the window title.
1498 void filer_detach_rescan(FilerWindow *filer_window)
1500 Directory *dir = filer_window->directory;
1502 g_object_ref(dir);
1503 detach(filer_window);
1504 filer_window->directory = dir;
1505 attach(filer_window);
1508 /* Puts the filer window into target mode. When an item is chosen,
1509 * fn(filer_window, iter, data) is called. 'reason' will be displayed
1510 * on the toolbar while target mode is active.
1512 * Use fn == NULL to cancel target mode.
1514 void filer_target_mode(FilerWindow *filer_window,
1515 TargetFunc fn,
1516 gpointer data,
1517 const char *reason)
1519 TargetFunc old_fn = filer_window->target_cb;
1521 if (fn != old_fn)
1522 gdk_window_set_cursor(
1523 GTK_WIDGET(filer_window->view)->window,
1524 fn ? crosshair : NULL);
1526 filer_window->target_cb = fn;
1527 filer_window->target_data = data;
1529 if (filer_window->toolbar_text == NULL)
1530 return;
1532 if (fn)
1533 gtk_label_set_text(
1534 GTK_LABEL(filer_window->toolbar_text), reason);
1535 else if (o_toolbar_info.int_value)
1537 if (old_fn)
1538 toolbar_update_info(filer_window);
1540 else
1541 gtk_label_set_text(GTK_LABEL(filer_window->toolbar_text), "");
1544 static void set_selection_state(FilerWindow *filer_window, gboolean normal)
1546 GtkStateType old_state = filer_window->selection_state;
1548 filer_window->selection_state = normal
1549 ? GTK_STATE_SELECTED : GTK_STATE_INSENSITIVE;
1551 if (old_state != filer_window->selection_state
1552 && view_count_selected(filer_window->view))
1553 gtk_widget_queue_draw(GTK_WIDGET(filer_window->view));
1556 void filer_cancel_thumbnails(FilerWindow *filer_window)
1558 gtk_widget_hide(filer_window->thumb_bar);
1560 g_list_foreach(filer_window->thumb_queue, (GFunc) g_free, NULL);
1561 g_list_free(filer_window->thumb_queue);
1562 filer_window->thumb_queue = NULL;
1563 filer_window->max_thumbs = 0;
1566 /* Generate the next thumb for this window. The window object is
1567 * unref'd when there is nothing more to do.
1568 * If the window no longer has a filer window, nothing is done.
1570 static gboolean filer_next_thumb_real(GObject *window)
1572 FilerWindow *filer_window;
1573 gchar *path;
1574 int done, total;
1576 filer_window = g_object_get_data(window, "filer_window");
1578 if (!filer_window)
1580 g_object_unref(window);
1581 return FALSE;
1584 if (!filer_window->thumb_queue)
1586 filer_cancel_thumbnails(filer_window);
1587 g_object_unref(window);
1588 return FALSE;
1591 total = filer_window->max_thumbs;
1592 done = total - g_list_length(filer_window->thumb_queue);
1594 path = (gchar *) filer_window->thumb_queue->data;
1596 pixmap_background_thumb(path, (GFunc) filer_next_thumb, window);
1598 filer_window->thumb_queue = g_list_remove(filer_window->thumb_queue,
1599 path);
1600 g_free(path);
1602 gtk_progress_bar_set_fraction(
1603 GTK_PROGRESS_BAR(filer_window->thumb_progress),
1604 done / (float) total);
1606 return FALSE;
1609 /* path is the thumb just loaded, if any.
1610 * window is unref'd (eventually).
1612 static void filer_next_thumb(GObject *window, const gchar *path)
1614 if (path)
1615 dir_force_update_path(path);
1617 gtk_idle_add((GtkFunction) filer_next_thumb_real, window);
1620 static void start_thumb_scanning(FilerWindow *filer_window)
1622 if (GTK_WIDGET_VISIBLE(filer_window->thumb_bar))
1623 return; /* Already scanning */
1625 gtk_widget_show_all(filer_window->thumb_bar);
1627 g_object_ref(G_OBJECT(filer_window->window));
1628 filer_next_thumb(G_OBJECT(filer_window->window), NULL);
1631 /* Set this image to be loaded some time in the future */
1632 void filer_create_thumb(FilerWindow *filer_window, const gchar *path)
1634 filer_window->max_thumbs++;
1636 filer_window->thumb_queue = g_list_append(filer_window->thumb_queue,
1637 g_strdup(path));
1639 if (filer_window->scanning)
1640 return; /* Will start when scan ends */
1642 start_thumb_scanning(filer_window);
1645 /* If thumbnail display is on, look through all the items in this directory
1646 * and start creating or updating the thumbnails as needed.
1648 void filer_create_thumbs(FilerWindow *filer_window)
1650 DirItem *item;
1651 ViewIter iter;
1653 if (!filer_window->show_thumbs)
1654 return;
1656 view_get_iter(filer_window->view, &iter, 0);
1658 while ((item = iter.next(&iter)))
1660 MaskedPixmap *pixmap;
1661 gchar *path;
1662 gboolean found;
1664 if (item->base_type != TYPE_FILE)
1665 continue;
1667 if (strcmp(item->mime_type->media_type, "image") != 0)
1668 continue;
1670 path = make_path(filer_window->real_path, item->leafname)->str;
1672 pixmap = g_fscache_lookup_full(pixmap_cache, path,
1673 FSCACHE_LOOKUP_ONLY_NEW, &found);
1674 if (pixmap)
1675 g_object_unref(pixmap);
1677 /* If we didn't get an image, it could be because:
1679 * - We're loading the image now. found is TRUE,
1680 * and we'll update the item later.
1681 * - We tried to load the image and failed. found
1682 * is TRUE.
1683 * - We haven't tried loading the image. found is
1684 * FALSE, and we start creating the thumb here.
1686 if (!found)
1687 filer_create_thumb(filer_window, path);
1691 static void filer_options_changed(void)
1693 if (o_short_flag_names.has_changed)
1695 GList *next;
1697 for (next = all_filer_windows; next; next = next->next)
1699 FilerWindow *filer_window = (FilerWindow *) next->data;
1701 filer_set_title(filer_window);
1706 /* Change to Large or Small icons depending on the number of items
1707 * in the directory, subject to options.
1709 static void set_style_by_number_of_items(FilerWindow *filer_window)
1711 int n;
1713 g_return_if_fail(filer_window != NULL);
1715 if (!o_filer_change_size.int_value)
1716 return; /* Don't auto-set style */
1718 if (filer_window->display_style != LARGE_ICONS &&
1719 filer_window->display_style != SMALL_ICONS)
1720 return; /* Only change between these two styles */
1722 n = view_count_items(filer_window->view);
1724 if (n >= o_filer_change_size_num.int_value)
1725 display_set_layout(filer_window, SMALL_ICONS,
1726 filer_window->details_type);
1727 else
1728 display_set_layout(filer_window, LARGE_ICONS,
1729 filer_window->details_type);
1732 /* Append interesting information to this GString */
1733 void filer_add_tip_details(FilerWindow *filer_window,
1734 GString *tip, DirItem *item)
1736 guchar *fullpath = NULL;
1738 fullpath = make_path(filer_window->real_path, item->leafname)->str;
1740 if (item->flags & ITEM_FLAG_SYMLINK)
1742 char *target;
1744 target = readlink_dup(fullpath);
1745 if (target)
1747 g_string_append(tip, _("Symbolic link to "));
1748 g_string_append(tip, target);
1749 g_string_append_c(tip, '\n');
1750 g_free(target);
1754 if (item->flags & ITEM_FLAG_APPDIR)
1756 XMLwrapper *info;
1757 xmlNode *node;
1759 info = appinfo_get(fullpath, item);
1760 if (info && ((node = xml_get_section(info, NULL, "Summary"))))
1762 guchar *str;
1763 str = xmlNodeListGetString(node->doc,
1764 node->xmlChildrenNode, 1);
1765 if (str)
1767 g_string_append(tip, str);
1768 g_string_append_c(tip, '\n');
1769 g_free(str);
1772 if (info)
1773 g_object_unref(info);
1776 if (!g_utf8_validate(item->leafname, -1, NULL))
1777 g_string_append(tip,
1778 _("This filename is not valid UTF-8. "
1779 "You should rename it.\n"));