r3768: Updated years.
[rox-filer.git] / ROX-Filer / src / filer.c
blobe633b8348d7524a71bd1e8d1fc8267f45b05dec8
1 /*
2 * $Id$
4 * ROX-Filer, filer for the ROX desktop project
5 * Copyright (C) 2005, 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>
33 #include <fnmatch.h>
35 #include <gtk/gtk.h>
36 #include <gdk/gdkx.h>
37 #include <gdk/gdkkeysyms.h>
39 #include "global.h"
41 #include "filer.h"
42 #include "display.h"
43 #include "main.h"
44 #include "fscache.h"
45 #include "support.h"
46 #include "gui_support.h"
47 #include "choices.h"
48 #include "pixmaps.h"
49 #include "menu.h"
50 #include "dnd.h"
51 #include "dir.h"
52 #include "diritem.h"
53 #include "run.h"
54 #include "type.h"
55 #include "options.h"
56 #include "minibuffer.h"
57 #include "icon.h"
58 #include "toolbar.h"
59 #include "bind.h"
60 #include "appinfo.h"
61 #include "mount.h"
62 #include "xml.h"
63 #include "view_iface.h"
64 #include "view_collection.h"
65 #include "view_details.h"
66 #include "action.h"
67 #include "bookmarks.h"
69 static XMLwrapper *groups = NULL;
71 /* Item we are about to display a tooltip for */
72 static DirItem *tip_item = NULL;
74 /* The window which the motion event for the tooltip came from. Use this
75 * to get the correct widget for finding the item under the pointer.
77 static GdkWindow *motion_window = NULL;
79 /* This is rather badly named. It's actually the filer window which received
80 * the last key press or Menu click event.
82 FilerWindow *window_with_focus = NULL;
84 GList *all_filer_windows = NULL;
86 static GHashTable *window_with_id = NULL;
88 static FilerWindow *window_with_primary = NULL;
90 static GHashTable *settings_table=NULL;
92 typedef struct {
93 gchar *path;
95 guint flags; /* Which parts are valid, see below */
97 gint x, y;
98 gint width, height;
99 gboolean show_hidden;
100 ViewType view_type;
101 SortType sort_type;
102 GtkSortType sort_order;
103 gboolean show_thumbs;
105 DetailsType details_type;
106 DisplayStyle display_style;
108 FilterType filter_type;
109 char *filter;
110 } Settings;
112 enum settings_flags{
113 SET_POSITION=1, /* x, y */
114 SET_SIZE=2, /* width, height */
115 SET_HIDDEN=4, /* show_hidden */
116 SET_STYLE=8, /* display_style */
117 SET_SORT=16, /* sort_type, sort_order */
118 SET_DETAILS=32, /* view_type, details_type */
119 SET_THUMBS=64, /* show_thumbs */
120 SET_FILTER=128, /* filter_type, filter */
123 /* Static prototypes */
124 static void attach(FilerWindow *filer_window);
125 static void detach(FilerWindow *filer_window);
126 static void filer_window_destroyed(GtkWidget *widget,
127 FilerWindow *filer_window);
128 static void update_display(Directory *dir,
129 DirAction action,
130 GPtrArray *items,
131 FilerWindow *filer_window);
132 static void set_scanning_display(FilerWindow *filer_window, gboolean scanning);
133 static gboolean may_rescan(FilerWindow *filer_window, gboolean warning);
134 static gboolean minibuffer_show_cb(FilerWindow *filer_window);
135 static FilerWindow *find_filer_window(const char *sym_path, FilerWindow *diff);
136 static void filer_add_widgets(FilerWindow *filer_window, const gchar *wm_class);
137 static void filer_add_signals(FilerWindow *filer_window);
139 static void set_selection_state(FilerWindow *filer_window, gboolean normal);
140 static void filer_next_thumb(GObject *window, const gchar *path);
141 static void start_thumb_scanning(FilerWindow *filer_window);
142 static void filer_options_changed(void);
143 static void drag_end(GtkWidget *widget, GdkDragContext *context,
144 FilerWindow *filer_window);
145 static void drag_leave(GtkWidget *widget,
146 GdkDragContext *context,
147 guint32 time,
148 FilerWindow *filer_window);
149 static gboolean drag_motion(GtkWidget *widget,
150 GdkDragContext *context,
151 gint x,
152 gint y,
153 guint time,
154 FilerWindow *filer_window);
156 static void load_settings(void);
157 static void save_settings(void);
158 static void check_settings(FilerWindow *filer_window);
160 static GdkCursor *busy_cursor = NULL;
161 static GdkCursor *crosshair = NULL;
163 /* Indicates whether the filer's display is different to the machine it
164 * is actually running on.
166 static gboolean not_local = FALSE;
168 static Option o_short_flag_names;
169 static Option o_filer_view_type;
170 Option o_filer_auto_resize, o_unique_filer_windows;
171 Option o_filer_size_limit;
173 void filer_init(void)
175 const gchar *ohost;
176 const gchar *dpy;
177 gchar *dpyhost, *tmp;
179 option_add_int(&o_filer_size_limit, "filer_size_limit", 75);
180 option_add_int(&o_filer_auto_resize, "filer_auto_resize",
181 RESIZE_ALWAYS);
182 option_add_int(&o_unique_filer_windows, "filer_unique_windows", 0);
184 option_add_int(&o_short_flag_names, "filer_short_flag_names", FALSE);
186 option_add_int(&o_filer_view_type, "filer_view_type",
187 VIEW_TYPE_COLLECTION);
189 option_add_notify(filer_options_changed);
191 busy_cursor = gdk_cursor_new(GDK_WATCH);
192 crosshair = gdk_cursor_new(GDK_CROSSHAIR);
194 window_with_id = g_hash_table_new_full(g_str_hash, g_str_equal,
195 NULL, NULL);
197 /* Is the display on the local machine, or are we being
198 * run remotely? See filer_set_title().
200 ohost = our_host_name();
201 dpy = gdk_get_display();
202 dpyhost = g_strdup(dpy);
203 tmp = strchr(dpyhost, ':');
204 if (tmp)
205 *tmp = '\0';
207 if (dpyhost[0] && strcmp(ohost, dpyhost) != 0)
209 /* Try the cannonical name for dpyhost (see our_host_name()
210 * in support.c).
212 struct hostent *ent;
214 ent = gethostbyname(dpyhost);
215 if (!ent || strcmp(ohost, ent->h_name) != 0)
216 not_local = TRUE;
219 g_free(dpyhost);
221 load_settings();
224 static gboolean if_deleted(gpointer item, gpointer removed)
226 int i = ((GPtrArray *) removed)->len;
227 DirItem **r = (DirItem **) ((GPtrArray *) removed)->pdata;
228 char *leafname = ((DirItem *) item)->leafname;
230 while (i--)
232 if (strcmp(leafname, r[i]->leafname) == 0)
233 return TRUE;
236 return FALSE;
239 #define DECOR_BORDER 32
241 /* Resize the filer window to w x h pixels, plus border (not clamped).
242 * If triggered by a key event, warp the pointer (for SloppyFocus users).
244 void filer_window_set_size(FilerWindow *filer_window, int w, int h)
246 GdkEvent *event;
247 GtkWidget *window;
249 g_return_if_fail(filer_window != NULL);
251 if (filer_window->scrollbar)
252 w += filer_window->scrollbar->allocation.width;
254 if (o_toolbar.int_value != TOOLBAR_NONE)
255 h += filer_window->toolbar->allocation.height;
256 if (filer_window->message)
257 h += filer_window->message->allocation.height;
259 window = filer_window->window;
261 if (GTK_WIDGET_VISIBLE(window))
263 gint x, y, m;
264 GtkRequisition *req = &window->requisition;
265 GdkWindow *gdk_window = window->window;
267 w = MAX(req->width, w);
268 h = MAX(req->height, h);
269 gdk_window_get_pointer(NULL, &x, &y, NULL);
270 m = gdk_screen_get_monitor_at_point(gdk_screen_get_default(),
271 x, y);
272 gdk_window_get_position(gdk_window, &x, &y);
274 if (x + w + DECOR_BORDER >
275 monitor_geom[m].x + monitor_geom[m].width ||
276 y + h + DECOR_BORDER >
277 monitor_geom[m].y + monitor_geom[m].height)
279 if (x + w + DECOR_BORDER >
280 monitor_geom[m].x + monitor_geom[m].width)
282 x = monitor_geom[m].x + monitor_geom[m].width -
283 w - 4 - DECOR_BORDER;
285 if (y + h + DECOR_BORDER >
286 monitor_geom[m].y + monitor_geom[m].height)
288 y = monitor_geom[m].y + monitor_geom[m].height -
289 h - 4 - DECOR_BORDER;
291 gdk_window_move_resize(gdk_window, x, y, w, h);
293 else
294 gdk_window_resize(gdk_window, w, h);
296 else
297 gtk_window_set_default_size(GTK_WINDOW(window), w, h);
299 event = gtk_get_current_event();
300 if (event && event->type == GDK_KEY_PRESS)
302 int x, y;
303 int nx, ny;
305 GdkWindow *win = filer_window->window->window;
307 gdk_window_get_pointer(filer_window->window->window,
308 &x, &y, NULL);
310 nx = CLAMP(x, 4, w - 4);
311 ny = CLAMP(y, 4, h - 4);
313 if (nx != x || ny != y)
315 XWarpPointer(gdk_x11_drawable_get_xdisplay(win),
316 None,
317 gdk_x11_drawable_get_xid(win),
318 0, 0, 0, 0,
319 nx, ny);
324 /* Called on a timeout while scanning or when scanning ends
325 * (whichever happens first).
327 static gint open_filer_window(FilerWindow *filer_window)
329 Settings *dir_settings = (Settings *) g_hash_table_lookup(settings_table,
330 filer_window->sym_path);
331 gboolean force_resize = !(o_filer_auto_resize.int_value == RESIZE_NEVER && dir_settings && dir_settings->flags & SET_POSITION);
333 view_style_changed(filer_window->view, 0);
335 if (filer_window->open_timeout)
337 g_source_remove(filer_window->open_timeout);
338 filer_window->open_timeout = 0;
341 if (!GTK_WIDGET_VISIBLE(filer_window->window))
343 display_set_actual_size(filer_window, force_resize);
344 gtk_widget_show(filer_window->window);
347 return FALSE;
350 /* Look through all items we want to display, and queue a recheck on any
351 * that require it.
353 static void queue_interesting(FilerWindow *filer_window)
355 DirItem *item;
356 ViewIter iter;
358 view_get_iter(filer_window->view, &iter, 0);
359 while ((item = iter.next(&iter)))
361 if (item->flags & ITEM_FLAG_NEED_RESCAN_QUEUE)
362 dir_queue_recheck(filer_window->directory, item);
366 static void update_display(Directory *dir,
367 DirAction action,
368 GPtrArray *items,
369 FilerWindow *filer_window)
371 ViewIface *view = (ViewIface *) filer_window->view;
373 switch (action)
375 case DIR_ADD:
376 view_add_items(view, items);
377 /* Open and resize if currently hidden */
378 open_filer_window(filer_window);
379 break;
380 case DIR_REMOVE:
381 view_delete_if(view, if_deleted, items);
382 toolbar_update_info(filer_window);
383 break;
384 case DIR_START_SCAN:
385 set_scanning_display(filer_window, TRUE);
386 toolbar_update_info(filer_window);
387 break;
388 case DIR_END_SCAN:
389 if (filer_window->window->window)
390 gdk_window_set_cursor(
391 filer_window->window->window,
392 NULL);
393 set_scanning_display(filer_window, FALSE);
394 toolbar_update_info(filer_window);
395 open_filer_window(filer_window);
397 if (filer_window->had_cursor &&
398 !view_cursor_visible(view))
400 ViewIter start;
401 view_get_iter(view, &start, 0);
402 if (start.next(&start))
403 view_cursor_to_iter(view, &start);
404 view_show_cursor(view);
405 filer_window->had_cursor = FALSE;
407 if (filer_window->auto_select)
408 display_set_autoselect(filer_window,
409 filer_window->auto_select);
410 null_g_free(&filer_window->auto_select);
412 filer_create_thumbs(filer_window);
414 if (filer_window->thumb_queue)
415 start_thumb_scanning(filer_window);
416 break;
417 case DIR_UPDATE:
418 view_update_items(view, items);
419 break;
420 case DIR_ERROR_CHANGED:
421 filer_set_title(filer_window);
422 break;
423 case DIR_QUEUE_INTERESTING:
424 queue_interesting(filer_window);
425 break;
429 static void attach(FilerWindow *filer_window)
431 gdk_window_set_cursor(filer_window->window->window, busy_cursor);
432 view_clear(filer_window->view);
433 filer_window->scanning = TRUE;
434 dir_attach(filer_window->directory, (DirCallback) update_display,
435 filer_window);
436 filer_set_title(filer_window);
437 bookmarks_add_history(filer_window->sym_path);
439 if (filer_window->directory->error)
441 if (spring_in_progress)
442 g_printerr(_("Error scanning '%s':\n%s\n"),
443 filer_window->sym_path,
444 filer_window->directory->error);
445 else
446 delayed_error(_("Error scanning '%s':\n%s"),
447 filer_window->sym_path,
448 filer_window->directory->error);
452 static void detach(FilerWindow *filer_window)
454 g_return_if_fail(filer_window->directory != NULL);
456 dir_detach(filer_window->directory,
457 (DirCallback) update_display, filer_window);
458 g_object_unref(filer_window->directory);
459 filer_window->directory = NULL;
462 /* If 'start' was mounted by ROX-Filer, return it. Otherwise, try the
463 * parents up the tree.
464 * NULL if we're not in a user mount point.
465 * g_free() the result.
467 static char *get_ancestor_user_mount_point(const char *start)
469 char *path;
471 path = strdup(start);
473 while (1)
475 char *slash;
477 if (mount_is_user_mounted(path))
478 return path;
480 if (!path[1])
482 g_free(path);
483 return NULL;
486 slash = strrchr(path + 1, '/');
487 if (!slash)
488 slash = path + 1;
489 *slash = '\0';
493 static void umount_dialog_response(GtkWidget *dialog, int response, char *mount)
495 if (response == GTK_RESPONSE_OK)
497 GList *list;
499 list = g_list_prepend(NULL, mount);
500 action_mount(list, FALSE, TRUE);
501 g_list_free(list);
504 g_free(mount);
506 gtk_widget_destroy(dialog);
508 one_less_window();
511 /* 'filer_window' shows a directory under 'mount'. If no other window also
512 * shows a directory under it, display a non-modal dialog offering to
513 * unmount the directory.
514 * 'mount' is freed by this function, either directly, or after the dialog
515 * closes.
517 static void may_offer_unmount(FilerWindow *filer_window, char *mount)
519 GtkWidget *dialog, *button;
520 GList *next;
521 int len;
523 len = strlen(mount);
525 for (next = all_filer_windows; next; next = next->next)
527 FilerWindow *other = (FilerWindow *) next->data;
529 if (other == filer_window)
530 continue;
532 if (strncmp(filer_window->real_path, other->real_path,
533 len) != 0)
534 continue;
536 g_return_if_fail(
537 filer_window->real_path[len] != '/' ||
538 filer_window->real_path[len] != '\0');
540 if (other->real_path[len] != '/' &&
541 other->real_path[len] != '\0')
542 continue;
544 /* Found another window. Don't offer to unmount. */
545 g_free(mount);
546 return;
549 dialog = gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_QUESTION,
550 GTK_BUTTONS_NONE,
551 _("Do you want to unmount this device?\n\n"
552 "Unmounting a device makes it safe to remove "
553 "the disk."), mount);
555 button = button_new_mixed(ROX_STOCK_MOUNTED, _("No change"));
556 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
557 gtk_dialog_add_action_widget(GTK_DIALOG(dialog), button,
558 GTK_RESPONSE_CANCEL);
559 gtk_widget_show(button);
561 button = button_new_mixed(ROX_STOCK_MOUNT, _("Unmount"));
562 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
563 gtk_dialog_add_action_widget(GTK_DIALOG(dialog), button,
564 GTK_RESPONSE_OK);
565 gtk_widget_show(button);
567 g_signal_connect(G_OBJECT(dialog), "response",
568 G_CALLBACK(umount_dialog_response), mount);
570 gtk_dialog_set_default_response(GTK_DIALOG(dialog),
571 GTK_RESPONSE_OK);
573 number_of_windows++;
574 gtk_widget_show(dialog);
577 /* Returns TRUE to prevent closing the window. May offer to unmount a
578 * device.
580 gboolean filer_window_delete(GtkWidget *window,
581 GdkEvent *unused, /* (may be NULL) */
582 FilerWindow *filer_window)
584 char *mount;
586 mount = get_ancestor_user_mount_point(filer_window->real_path);
588 if (mount)
589 may_offer_unmount(filer_window, mount);
591 return FALSE;
594 static void filer_window_destroyed(GtkWidget *widget, FilerWindow *filer_window)
596 all_filer_windows = g_list_remove(all_filer_windows, filer_window);
598 g_object_set_data(G_OBJECT(widget), "filer_window", NULL);
600 if (window_with_primary == filer_window)
601 window_with_primary = NULL;
603 if (window_with_focus == filer_window)
605 menu_popdown();
606 window_with_focus = NULL;
609 if (filer_window->directory)
610 detach(filer_window);
612 if (filer_window->open_timeout)
614 g_source_remove(filer_window->open_timeout);
615 filer_window->open_timeout = 0;
618 if (filer_window->auto_scroll != -1)
620 g_source_remove(filer_window->auto_scroll);
621 filer_window->auto_scroll = -1;
624 if (filer_window->thumb_queue)
625 destroy_glist(&filer_window->thumb_queue);
627 tooltip_show(NULL);
629 filer_set_id(filer_window, NULL);
631 if(filer_window->filter_string)
632 g_free(filer_window->filter_string);
633 if(filer_window->regexp)
634 g_free(filer_window->regexp);
636 g_free(filer_window->auto_select);
637 g_free(filer_window->real_path);
638 g_free(filer_window->sym_path);
639 g_free(filer_window);
641 one_less_window();
644 /* Returns TRUE iff the directory still exists. */
645 static gboolean may_rescan(FilerWindow *filer_window, gboolean warning)
647 Directory *dir;
649 g_return_val_if_fail(filer_window != NULL, FALSE);
651 /* We do a fresh lookup (rather than update) because the inode may
652 * have changed.
654 dir = g_fscache_lookup(dir_cache, filer_window->real_path);
655 if (!dir)
657 if (warning)
658 info_message(_("Directory missing/deleted"));
659 gtk_widget_destroy(filer_window->window);
660 return FALSE;
662 if (dir == filer_window->directory)
663 g_object_unref(dir);
664 else
666 detach(filer_window);
667 filer_window->directory = dir;
668 attach(filer_window);
671 return TRUE;
674 /* No items are now selected. This might be because another app claimed
675 * the selection or because the user unselected all the items.
677 void filer_lost_selection(FilerWindow *filer_window, guint time)
679 if (window_with_primary == filer_window)
681 window_with_primary = NULL;
682 gtk_selection_owner_set(NULL, GDK_SELECTION_PRIMARY, time);
686 /* Another app has claimed the primary selection */
687 static void filer_lost_primary(GtkWidget *window,
688 GdkEventSelection *event,
689 gpointer user_data)
691 FilerWindow *filer_window = (FilerWindow *) user_data;
693 if (window_with_primary && window_with_primary == filer_window)
695 window_with_primary = NULL;
696 set_selection_state(filer_window, FALSE);
700 /* Someone wants us to send them the selection */
701 static void selection_get(GtkWidget *widget,
702 GtkSelectionData *selection_data,
703 guint info,
704 guint time,
705 gpointer data)
707 GString *reply, *header;
708 FilerWindow *filer_window = (FilerWindow *) data;
709 ViewIter iter;
710 DirItem *item;
712 reply = g_string_new(NULL);
713 header = g_string_new(NULL);
715 switch (info)
717 case TARGET_STRING:
718 g_string_printf(header, " %s",
719 make_path(filer_window->sym_path, ""));
720 break;
721 case TARGET_URI_LIST:
722 g_string_printf(header, " file://%s%s",
723 our_host_name_for_dnd(),
724 make_path(filer_window->sym_path, ""));
725 break;
728 view_get_iter(filer_window->view, &iter, VIEW_ITER_SELECTED);
730 while ((item = iter.next(&iter)))
732 g_string_append(reply, header->str);
733 g_string_append(reply, item->leafname);
736 if (reply->len > 0)
737 gtk_selection_data_set_text(selection_data,
738 reply->str + 1, reply->len - 1);
739 else
741 g_warning("Attempt to paste empty selection!");
742 gtk_selection_data_set_text(selection_data, "", 0);
745 g_string_free(reply, TRUE);
746 g_string_free(header, TRUE);
749 /* Selection has been changed -- try to grab the primary selection
750 * if we don't have it. Also called when clicking on an insensitive selection
751 * to regain primary.
752 * Also updates toolbar info.
754 void filer_selection_changed(FilerWindow *filer_window, gint time)
756 toolbar_update_info(filer_window);
758 if (window_with_primary == filer_window)
759 return; /* Already got primary */
761 if (!view_count_selected(filer_window->view))
762 return; /* Nothing selected */
764 if (filer_window->temp_item_selected == FALSE &&
765 gtk_selection_owner_set(GTK_WIDGET(filer_window->window),
766 GDK_SELECTION_PRIMARY,
767 time))
769 window_with_primary = filer_window;
770 set_selection_state(filer_window, TRUE);
772 else
773 set_selection_state(filer_window, FALSE);
776 /* Open the item (or add it to the shell command minibuffer) */
777 void filer_openitem(FilerWindow *filer_window, ViewIter *iter, OpenFlags flags)
779 gboolean shift = (flags & OPEN_SHIFT) != 0;
780 gboolean close_mini = flags & OPEN_FROM_MINI;
781 gboolean close_window = (flags & OPEN_CLOSE_WINDOW) != 0;
782 DirItem *item;
783 const guchar *full_path;
784 gboolean wink = TRUE;
785 Directory *old_dir;
787 g_return_if_fail(filer_window != NULL && iter != NULL);
789 item = iter->peek(iter);
791 g_return_if_fail(item != NULL);
793 if (filer_window->mini_type == MINI_SHELL)
795 minibuffer_add(filer_window, item->leafname);
796 return;
799 if (item->base_type == TYPE_UNKNOWN)
800 dir_update_item(filer_window->directory, item->leafname);
802 if (item->base_type == TYPE_DIRECTORY)
804 /* Never close a filer window when opening a directory
805 * (click on a dir or click on an app with shift).
807 if (shift || !(item->flags & ITEM_FLAG_APPDIR))
808 close_window = FALSE;
811 full_path = make_path(filer_window->sym_path, item->leafname);
812 if (shift && (item->flags & ITEM_FLAG_SYMLINK))
813 wink = FALSE;
815 old_dir = filer_window->directory;
816 if (run_diritem(full_path, item,
817 flags & OPEN_SAME_WINDOW ? filer_window : NULL,
818 filer_window,
819 shift))
821 if (old_dir != filer_window->directory)
822 return;
824 if (close_window)
825 gtk_widget_destroy(filer_window->window);
826 else
828 if (wink)
829 view_wink_item(filer_window->view, iter);
830 if (close_mini)
831 minibuffer_hide(filer_window);
836 static gint pointer_in(GtkWidget *widget,
837 GdkEventCrossing *event,
838 FilerWindow *filer_window)
840 may_rescan(filer_window, TRUE);
841 return FALSE;
844 static gint pointer_out(GtkWidget *widget,
845 GdkEventCrossing *event,
846 FilerWindow *filer_window)
848 tooltip_show(NULL);
849 return FALSE;
852 /* Move the cursor to the next selected item in direction 'dir'
853 * (+1 or -1).
855 void filer_next_selected(FilerWindow *filer_window, int dir)
857 ViewIter iter, cursor;
858 gboolean have_cursor;
859 ViewIface *view = filer_window->view;
861 g_return_if_fail(dir == 1 || dir == -1);
863 view_get_cursor(view, &cursor);
864 have_cursor = cursor.peek(&cursor) != NULL;
866 view_get_iter(view, &iter,
867 VIEW_ITER_SELECTED |
868 (have_cursor ? VIEW_ITER_FROM_CURSOR : 0) |
869 (dir < 0 ? VIEW_ITER_BACKWARDS : 0));
871 if (have_cursor && view_get_selected(view, &cursor))
872 iter.next(&iter); /* Skip the cursor itself */
874 if (iter.next(&iter))
875 view_cursor_to_iter(view, &iter);
876 else
877 gdk_beep();
879 return;
882 static void return_pressed(FilerWindow *filer_window, GdkEventKey *event)
884 TargetFunc cb = filer_window->target_cb;
885 gpointer data = filer_window->target_data;
886 OpenFlags flags = 0;
887 ViewIter iter;
889 filer_target_mode(filer_window, NULL, NULL, NULL);
891 view_get_cursor(filer_window->view, &iter);
892 if (!iter.peek(&iter))
893 return;
895 if (cb)
897 cb(filer_window, &iter, data);
898 return;
901 if (event->state & GDK_SHIFT_MASK)
902 flags |= OPEN_SHIFT;
903 if (event->state & GDK_MOD1_MASK)
904 flags |= OPEN_CLOSE_WINDOW;
905 else
906 flags |= OPEN_SAME_WINDOW;
908 filer_openitem(filer_window, &iter, flags);
911 /* Makes sure that 'groups' is up-to-date, reloading from file if it has
912 * changed. If no groups were loaded and there is no file then initialised
913 * groups to an empty document.
914 * Return the node for the 'name' group.
916 static xmlNode *group_find(char *name)
918 xmlNode *node;
919 gchar *path;
921 /* Update the groups, if possible */
922 path = choices_find_path_load("Groups.xml", PROJECT);
923 if (path)
925 XMLwrapper *wrapper;
926 wrapper = xml_cache_load(path);
927 if (wrapper)
929 if (groups)
930 g_object_unref(groups);
931 groups = wrapper;
934 g_free(path);
937 if (!groups)
939 groups = xml_new(NULL);
940 groups->doc = xmlNewDoc("1.0");
942 xmlDocSetRootElement(groups->doc,
943 xmlNewDocNode(groups->doc, NULL, "groups", NULL));
944 return NULL;
947 node = xmlDocGetRootElement(groups->doc);
949 for (node = node->xmlChildrenNode; node; node = node->next)
951 guchar *gid;
953 gid = xmlGetProp(node, "name");
955 if (!gid)
956 continue;
958 if (strcmp(name, gid) != 0)
959 continue;
961 g_free(gid);
963 return node;
966 return NULL;
969 static void group_save(FilerWindow *filer_window, char *name)
971 xmlNode *group;
972 guchar *save_path;
973 DirItem *item;
974 ViewIter iter;
976 group = group_find(name);
977 if (group)
979 xmlUnlinkNode(group);
980 xmlFreeNode(group);
982 group = xmlNewChild(xmlDocGetRootElement(groups->doc),
983 NULL, "group", NULL);
984 xmlSetProp(group, "name", name);
986 xmlNewTextChild(group, NULL, "directory", filer_window->sym_path);
988 view_get_iter(filer_window->view, &iter, VIEW_ITER_SELECTED);
990 while ((item = iter.next(&iter)))
991 xmlNewTextChild(group, NULL, "item", item->leafname);
993 save_path = choices_find_path_save("Groups.xml", PROJECT, TRUE);
994 if (save_path)
996 save_xml_file(groups->doc, save_path);
997 g_free(save_path);
1001 static gboolean group_restore_cb(ViewIter *iter, gpointer data)
1003 GHashTable *in_group = (GHashTable *) data;
1005 return g_hash_table_lookup(in_group,
1006 iter->peek(iter)->leafname) != NULL;
1009 static void group_restore(FilerWindow *filer_window, char *name)
1011 GHashTable *in_group;
1012 char *path;
1013 xmlNode *group, *node;
1015 group = group_find(name);
1017 if (!group)
1019 report_error(_("Group %s is not set. Select some files "
1020 "and press Ctrl+%s to set the group. Press %s "
1021 "on its own to reselect the files later.\n"
1022 "Make sure NumLock is on if you use the keypad."),
1023 name, name, name);
1024 return;
1027 node = get_subnode(group, NULL, "directory");
1028 g_return_if_fail(node != NULL);
1029 path = xmlNodeListGetString(groups->doc, node->xmlChildrenNode, 1);
1030 g_return_if_fail(path != NULL);
1032 if (strcmp(path, filer_window->sym_path) != 0)
1033 filer_change_to(filer_window, path, NULL);
1034 g_free(path);
1036 in_group = g_hash_table_new(g_str_hash, g_str_equal);
1037 for (node = group->xmlChildrenNode; node; node = node->next)
1039 gchar *leaf;
1040 if (node->type != XML_ELEMENT_NODE)
1041 continue;
1042 if (strcmp(node->name, "item") != 0)
1043 continue;
1045 leaf = xmlNodeListGetString(groups->doc,
1046 node->xmlChildrenNode, 1);
1047 if (!leaf)
1048 g_warning("Missing leafname!\n");
1049 else
1050 g_hash_table_insert(in_group, leaf, filer_window);
1053 view_select_if(filer_window->view, &group_restore_cb, in_group);
1055 g_hash_table_foreach(in_group, (GHFunc) g_free, NULL);
1056 g_hash_table_destroy(in_group);
1059 static gboolean popup_menu(GtkWidget *widget, FilerWindow *filer_window)
1061 ViewIter iter;
1063 view_get_cursor(filer_window->view, &iter);
1065 show_filer_menu(filer_window, NULL, &iter);
1067 return TRUE;
1070 void filer_window_toggle_cursor_item_selected(FilerWindow *filer_window)
1072 ViewIface *view = filer_window->view;
1073 ViewIter iter;
1075 view_get_iter(view, &iter, VIEW_ITER_FROM_CURSOR);
1076 if (!iter.next(&iter))
1077 return; /* No cursor */
1079 if (view_get_selected(view, &iter))
1080 view_set_selected(view, &iter, FALSE);
1081 else
1082 view_set_selected(view, &iter, TRUE);
1084 if (iter.next(&iter))
1085 view_cursor_to_iter(view, &iter);
1088 gint filer_key_press_event(GtkWidget *widget,
1089 GdkEventKey *event,
1090 FilerWindow *filer_window)
1092 ViewIface *view = filer_window->view;
1093 ViewIter cursor;
1094 GtkWidget *focus = GTK_WINDOW(widget)->focus_widget;
1095 guint key = event->keyval;
1096 char group[2] = "1";
1098 window_with_focus = filer_window;
1100 /* Delay setting up the keys until now to speed loading... */
1101 if (ensure_filer_menu())
1103 /* Gtk updates in an idle-handler, so force a recheck now */
1104 g_signal_emit_by_name(widget, "keys_changed");
1107 if (focus && focus == filer_window->minibuffer)
1108 if (gtk_widget_event(focus, (GdkEvent *) event))
1109 return TRUE; /* Handled */
1111 if (!focus)
1112 gtk_widget_grab_focus(GTK_WIDGET(view));
1114 view_get_cursor(view, &cursor);
1115 if (!cursor.peek(&cursor) && (key == GDK_Up || key == GDK_Down))
1117 ViewIter iter;
1118 view_get_iter(view, &iter, 0);
1119 if (iter.next(&iter))
1120 view_cursor_to_iter(view, &iter);
1121 gtk_widget_grab_focus(GTK_WIDGET(view)); /* Needed? */
1122 return TRUE;
1125 switch (key)
1127 case GDK_Escape:
1128 filer_target_mode(filer_window, NULL, NULL, NULL);
1129 view_cursor_to_iter(filer_window->view, NULL);
1130 view_clear_selection(filer_window->view);
1131 return FALSE;
1132 case GDK_Return:
1133 return_pressed(filer_window, event);
1134 break;
1135 case GDK_ISO_Left_Tab:
1136 filer_next_selected(filer_window, -1);
1137 break;
1138 case GDK_Tab:
1139 filer_next_selected(filer_window, 1);
1140 break;
1141 case GDK_BackSpace:
1142 change_to_parent(filer_window);
1143 break;
1144 case GDK_backslash:
1146 ViewIter iter;
1148 tooltip_show(NULL);
1150 view_get_cursor(filer_window->view, &iter);
1151 show_filer_menu(filer_window,
1152 (GdkEvent *) event, &iter);
1153 break;
1155 case ' ':
1156 filer_window_toggle_cursor_item_selected(filer_window);
1157 break;
1158 default:
1159 if (key >= GDK_0 && key <= GDK_9)
1160 group[0] = key - GDK_0 + '0';
1161 else if (key >= GDK_KP_0 && key <= GDK_KP_9)
1162 group[0] = key - GDK_KP_0 + '0';
1163 else
1165 if (focus && focus != widget &&
1166 gtk_widget_get_toplevel(focus) == widget)
1167 if (gtk_widget_event(focus,
1168 (GdkEvent *) event))
1169 return TRUE; /* Handled */
1170 return FALSE;
1173 if (event->state & GDK_CONTROL_MASK)
1174 group_save(filer_window, group);
1175 else
1176 group_restore(filer_window, group);
1179 return TRUE;
1182 void filer_open_parent(FilerWindow *filer_window)
1184 char *dir;
1185 const char *current = filer_window->sym_path;
1187 if (current[0] == '/' && current[1] == '\0')
1188 return; /* Already in the root */
1190 dir = g_path_get_dirname(current);
1191 filer_opendir(dir, filer_window, NULL);
1192 g_free(dir);
1195 void change_to_parent(FilerWindow *filer_window)
1197 char *dir;
1198 const char *current = filer_window->sym_path;
1200 if (current[0] == '/' && current[1] == '\0')
1201 return; /* Already in the root */
1203 if (mount_is_user_mounted(filer_window->real_path))
1204 may_offer_unmount(filer_window,
1205 g_strdup(filer_window->real_path));
1207 dir = g_path_get_dirname(current);
1208 filer_change_to(filer_window, dir, g_basename(current));
1209 g_free(dir);
1212 /* Removes trailing /s from path (modified in place) */
1213 static void tidy_sympath(gchar *path)
1215 int l;
1217 g_return_if_fail(path != NULL);
1219 l = strlen(path);
1220 while (l > 1 && path[l - 1] == '/')
1222 l--;
1223 path[l] = '\0';
1227 /* Make filer_window display path. When finished, highlight item 'from', or
1228 * the first item if from is NULL. If there is currently no cursor then
1229 * simply wink 'from' (if not NULL).
1230 * If the cause was a key event and we resize, warp the pointer.
1232 void filer_change_to(FilerWindow *filer_window,
1233 const char *path, const char *from)
1235 char *from_dup;
1236 char *sym_path, *real_path;
1237 Directory *new_dir;
1239 g_return_if_fail(filer_window != NULL);
1241 filer_cancel_thumbnails(filer_window);
1243 tooltip_show(NULL);
1245 sym_path = g_strdup(path);
1246 real_path = pathdup(path);
1247 new_dir = g_fscache_lookup(dir_cache, real_path);
1249 if (!new_dir)
1251 delayed_error(_("Directory '%s' is not accessible"),
1252 sym_path);
1253 g_free(real_path);
1254 g_free(sym_path);
1255 return;
1258 if (o_unique_filer_windows.int_value && !spring_in_progress)
1260 FilerWindow *fw;
1262 fw = find_filer_window(sym_path, filer_window);
1263 if (fw)
1264 gtk_widget_destroy(fw->window);
1267 from_dup = from && *from ? g_strdup(from) : NULL;
1269 detach(filer_window);
1270 g_free(filer_window->real_path);
1271 g_free(filer_window->sym_path);
1272 filer_window->real_path = real_path;
1273 filer_window->sym_path = sym_path;
1274 tidy_sympath(filer_window->sym_path);
1276 filer_window->directory = new_dir;
1278 g_free(filer_window->auto_select);
1279 filer_window->auto_select = from_dup;
1281 filer_window->had_cursor = filer_window->had_cursor ||
1282 view_cursor_visible(filer_window->view);
1284 filer_set_title(filer_window);
1285 if (filer_window->window->window)
1286 gdk_window_set_role(filer_window->window->window,
1287 filer_window->sym_path);
1288 view_cursor_to_iter(filer_window->view, NULL);
1290 attach(filer_window);
1292 check_settings(filer_window);
1294 display_set_actual_size(filer_window, FALSE);
1296 if (o_filer_auto_resize.int_value == RESIZE_ALWAYS)
1297 view_autosize(filer_window->view);
1299 if (filer_window->mini_type == MINI_PATH)
1300 g_idle_add((GSourceFunc) minibuffer_show_cb, filer_window);
1303 /* Returns a list containing the full (sym) pathname of every selected item.
1304 * You must g_free() each item in the list.
1306 GList *filer_selected_items(FilerWindow *filer_window)
1308 GList *retval = NULL;
1309 guchar *dir = filer_window->sym_path;
1310 ViewIter iter;
1311 DirItem *item;
1313 view_get_iter(filer_window->view, &iter, VIEW_ITER_SELECTED);
1314 while ((item = iter.next(&iter)))
1316 retval = g_list_prepend(retval,
1317 g_strdup(make_path(dir, item->leafname)));
1320 return g_list_reverse(retval);
1323 /* Return the single selected item. Error if nothing is selected. */
1324 DirItem *filer_selected_item(FilerWindow *filer_window)
1326 ViewIter iter;
1327 DirItem *item;
1329 view_get_iter(filer_window->view, &iter, VIEW_ITER_SELECTED);
1331 item = iter.next(&iter);
1332 g_return_val_if_fail(item != NULL, NULL);
1333 g_return_val_if_fail(iter.next(&iter) == NULL, NULL);
1335 return item;
1338 /* Creates and shows a new filer window.
1339 * If src_win != NULL then display options can be taken from that source window.
1340 * Returns the new filer window, or NULL on error.
1341 * Note: if unique windows is in use, may return an existing window.
1343 FilerWindow *filer_opendir(const char *path, FilerWindow *src_win,
1344 const gchar *wm_class)
1346 FilerWindow *filer_window;
1347 char *real_path;
1348 DisplayStyle dstyle;
1349 DetailsType dtype;
1350 SortType s_type;
1351 GtkSortType s_order;
1352 Settings *dir_settings = NULL;
1353 gboolean force_resize = TRUE;
1355 /* Get the real pathname of the directory and copy it */
1356 real_path = pathdup(path);
1358 if (o_unique_filer_windows.int_value && !spring_in_progress)
1360 FilerWindow *same_dir_window;
1362 same_dir_window = find_filer_window(path, NULL);
1364 if (same_dir_window)
1366 gtk_window_present(GTK_WINDOW(same_dir_window->window));
1367 return same_dir_window;
1371 filer_window = g_new(FilerWindow, 1);
1372 filer_window->message = NULL;
1373 filer_window->minibuffer = NULL;
1374 filer_window->minibuffer_label = NULL;
1375 filer_window->minibuffer_area = NULL;
1376 filer_window->temp_show_hidden = FALSE;
1377 filer_window->sym_path = g_strdup(path);
1378 filer_window->real_path = real_path;
1379 filer_window->scanning = FALSE;
1380 filer_window->had_cursor = FALSE;
1381 filer_window->auto_select = NULL;
1382 filer_window->toolbar_text = NULL;
1383 filer_window->target_cb = NULL;
1384 filer_window->mini_type = MINI_NONE;
1385 filer_window->selection_state = GTK_STATE_INSENSITIVE;
1386 filer_window->toolbar = NULL;
1387 filer_window->toplevel_vbox = NULL;
1388 filer_window->view_hbox = NULL;
1389 filer_window->view = NULL;
1390 filer_window->scrollbar = NULL;
1391 filer_window->auto_scroll = -1;
1392 filer_window->window_id = NULL;
1394 tidy_sympath(filer_window->sym_path);
1396 /* Finds the entry for this directory in the dir cache, creating
1397 * a new one if needed. This does not cause a scan to start,
1398 * so if a new entry is created then it will be empty.
1400 filer_window->directory = g_fscache_lookup(dir_cache, real_path);
1401 if (!filer_window->directory)
1403 delayed_error(_("Directory '%s' not found."), path);
1404 g_free(filer_window->real_path);
1405 g_free(filer_window->sym_path);
1406 g_free(filer_window);
1407 return NULL;
1410 filer_window->temp_item_selected = FALSE;
1411 filer_window->flags = (FilerFlags) 0;
1412 filer_window->details_type = DETAILS_TIMES;
1413 filer_window->display_style = UNKNOWN_STYLE;
1414 filer_window->display_style_wanted = UNKNOWN_STYLE;
1415 filer_window->thumb_queue = NULL;
1416 filer_window->max_thumbs = 0;
1417 filer_window->sort_type = -1;
1419 filer_window->filter = FILER_SHOW_ALL;
1420 filer_window->filter_string = NULL;
1421 filer_window->regexp = NULL;
1423 if (src_win && o_display_inherit_options.int_value)
1425 s_type = src_win->sort_type;
1426 s_order = src_win->sort_order;
1427 dstyle = src_win->display_style_wanted;
1428 dtype = src_win->details_type;
1429 filer_window->show_hidden = src_win->show_hidden;
1430 filer_window->show_thumbs = src_win->show_thumbs;
1431 filer_window->view_type = src_win->view_type;
1433 filer_set_filter(filer_window, src_win->filter,
1434 src_win->filter_string);
1436 else
1438 s_type = o_display_sort_by.int_value;
1439 s_order = GTK_SORT_ASCENDING;
1440 dstyle = o_display_size.int_value;
1441 dtype = o_display_details.int_value;
1442 filer_window->show_hidden = o_display_show_hidden.int_value;
1443 filer_window->show_thumbs = o_display_show_thumbs.int_value;
1444 filer_window->view_type = o_filer_view_type.int_value;
1447 dir_settings = (Settings *) g_hash_table_lookup(settings_table,
1448 filer_window->sym_path);
1449 if (dir_settings)
1451 /* Override the current defaults with the per-directory
1452 * user settings.
1454 if (dir_settings->flags & SET_HIDDEN)
1455 filer_window->show_hidden = dir_settings->show_hidden;
1457 if (dir_settings->flags & SET_STYLE)
1458 dstyle = dir_settings->display_style;
1460 if (dir_settings->flags & SET_DETAILS)
1462 dtype = dir_settings->details_type;
1463 filer_window->view_type = dir_settings->view_type;
1466 if (dir_settings->flags & SET_SORT)
1468 s_type = dir_settings->sort_type;
1469 s_order = dir_settings->sort_order;
1472 if (dir_settings->flags & SET_THUMBS)
1473 filer_window->show_thumbs = dir_settings->show_thumbs;
1475 if (dir_settings->flags & SET_FILTER)
1476 filer_set_filter(filer_window,
1477 dir_settings->filter_type,
1478 dir_settings->filter);
1481 /* Add all the user-interface elements & realise */
1482 filer_add_widgets(filer_window, wm_class);
1483 if (src_win)
1484 gtk_window_set_position(GTK_WINDOW(filer_window->window),
1485 GTK_WIN_POS_MOUSE);
1487 if (dir_settings)
1489 if (dir_settings->flags & SET_POSITION)
1491 gtk_window_move(GTK_WINDOW(filer_window->window),
1492 dir_settings->x, dir_settings->y);
1494 if (dir_settings->flags & SET_SIZE)
1496 filer_window_set_size(filer_window,
1497 dir_settings->width,
1498 dir_settings->height);
1499 force_resize = o_filer_auto_resize.int_value != RESIZE_NEVER;
1503 /* Connect to all the signal handlers */
1504 filer_add_signals(filer_window);
1506 display_set_layout(filer_window, dstyle, dtype, force_resize);
1507 display_set_sort_type(filer_window, s_type, s_order);
1509 /* Open the window after a timeout, or when scanning stops.
1510 * Do this before attaching, because attach() might tell us to
1511 * stop scanning (if a scan isn't needed).
1513 filer_window->open_timeout = g_timeout_add(500,
1514 (GSourceFunc) open_filer_window,
1515 filer_window);
1517 /* The view is created empty and then attach() is called, which
1518 * links the filer window to the entry in the directory cache we
1519 * looked up / created above.
1521 * The attach() function will immediately callback to the filer window
1522 * to deliver a list of all known entries in the directory (so,
1523 * the number of items will be known after attach() returns).
1525 * If the directory was not in the cache (because it hadn't been
1526 * opened it before) then the types and icons for the entries are
1527 * not know, but the list of names is.
1530 attach(filer_window);
1532 number_of_windows++;
1533 all_filer_windows = g_list_prepend(all_filer_windows, filer_window);
1535 return filer_window;
1538 void filer_set_view_type(FilerWindow *filer_window, ViewType type)
1540 GtkWidget *view = NULL;
1541 Directory *dir = NULL;
1542 GHashTable *selected = NULL;
1544 g_return_if_fail(filer_window != NULL);
1546 motion_window = NULL;
1548 if (filer_window->view)
1550 /* Save the current selection */
1551 ViewIter iter;
1552 DirItem *item;
1554 selected = g_hash_table_new(g_str_hash, g_str_equal);
1555 view_get_iter(filer_window->view, &iter, VIEW_ITER_SELECTED);
1556 while ((item = iter.next(&iter)))
1557 g_hash_table_insert(selected, item->leafname, "yes");
1559 /* Destroy the old view */
1560 gtk_widget_destroy(GTK_WIDGET(filer_window->view));
1561 filer_window->view = NULL;
1563 dir = filer_window->directory;
1564 g_object_ref(dir);
1565 detach(filer_window);
1568 switch (type)
1570 case VIEW_TYPE_COLLECTION:
1571 view = view_collection_new(filer_window);
1572 break;
1573 case VIEW_TYPE_DETAILS:
1574 view = view_details_new(filer_window);
1575 break;
1578 g_return_if_fail(view != NULL);
1580 filer_window->view = VIEW(view);
1581 filer_window->view_type = type;
1583 gtk_box_pack_start(filer_window->view_hbox, view, TRUE, TRUE, 0);
1584 gtk_widget_show(view);
1586 /* Drag and drop events */
1587 make_drop_target(view, 0);
1588 g_signal_connect(view, "drag_motion",
1589 G_CALLBACK(drag_motion), filer_window);
1590 g_signal_connect(view, "drag_leave",
1591 G_CALLBACK(drag_leave), filer_window);
1592 g_signal_connect(view, "drag_end",
1593 G_CALLBACK(drag_end), filer_window);
1594 /* Dragging from us... */
1595 g_signal_connect(view, "drag_data_get",
1596 GTK_SIGNAL_FUNC(drag_data_get), NULL);
1598 if (dir)
1600 /* Only when changing type. Otherwise, will attach later. */
1601 filer_window->directory = dir;
1602 attach(filer_window);
1604 if (o_filer_auto_resize.int_value != RESIZE_NEVER)
1605 view_autosize(filer_window->view);
1608 if (selected)
1610 ViewIter iter;
1611 DirItem *item;
1613 view_get_iter(filer_window->view, &iter, 0);
1614 while ((item = iter.next(&iter)))
1616 if (g_hash_table_lookup(selected, item->leafname))
1617 view_set_selected(filer_window->view,
1618 &iter, TRUE);
1620 g_hash_table_destroy(selected);
1624 /* This adds all the widgets to a new filer window. It is in a separate
1625 * function because filer_opendir() was getting too long...
1627 static void filer_add_widgets(FilerWindow *filer_window, const gchar *wm_class)
1629 GtkWidget *hbox, *vbox;
1631 /* Create the top-level window widget */
1632 filer_window->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1633 filer_set_title(filer_window);
1634 gtk_widget_set_name(filer_window->window, "rox-filer");
1636 if (wm_class)
1637 gtk_window_set_wmclass(GTK_WINDOW(filer_window->window),
1638 wm_class, PROJECT);
1640 /* This property is cleared when the window is destroyed.
1641 * You can thus ref filer_window->window and use this to see
1642 * if the window no longer exists.
1644 g_object_set_data(G_OBJECT(filer_window->window),
1645 "filer_window", filer_window);
1647 /* Create this now to make the Adjustment before the View */
1648 filer_window->scrollbar = gtk_vscrollbar_new(NULL);
1650 vbox = gtk_vbox_new(FALSE, 0);
1651 gtk_container_add(GTK_CONTAINER(filer_window->window), vbox);
1653 filer_window->toplevel_vbox = GTK_BOX(vbox);
1655 /* If there's a message that should be displayed in each window (eg
1656 * 'Running as root'), add it here.
1658 if (show_user_message)
1660 filer_window->message = gtk_label_new(show_user_message);
1661 gtk_box_pack_start(GTK_BOX(vbox), filer_window->message,
1662 FALSE, TRUE, 0);
1663 gtk_widget_show(filer_window->message);
1666 hbox = gtk_hbox_new(FALSE, 0);
1667 filer_window->view_hbox = GTK_BOX(hbox);
1668 gtk_box_pack_start_defaults(GTK_BOX(vbox), hbox);
1669 /* Add the main View widget */
1670 filer_set_view_type(filer_window, filer_window->view_type);
1671 /* Put the scrollbar next to the View */
1672 gtk_box_pack_end(GTK_BOX(hbox),
1673 filer_window->scrollbar, FALSE, TRUE, 0);
1674 gtk_widget_show(hbox);
1676 /* If we want a toolbar, create it now */
1677 toolbar_update_toolbar(filer_window);
1679 /* And the minibuffer (hidden to start with) */
1680 create_minibuffer(filer_window);
1681 gtk_box_pack_end(GTK_BOX(vbox), filer_window->minibuffer_area,
1682 FALSE, TRUE, 0);
1684 /* And the thumbnail progress bar (also hidden) */
1686 GtkWidget *cancel;
1688 filer_window->thumb_bar = gtk_hbox_new(FALSE, 2);
1689 gtk_box_pack_end(GTK_BOX(vbox), filer_window->thumb_bar,
1690 FALSE, TRUE, 0);
1692 filer_window->thumb_progress = gtk_progress_bar_new();
1694 gtk_box_pack_start(GTK_BOX(filer_window->thumb_bar),
1695 filer_window->thumb_progress, TRUE, TRUE, 0);
1697 cancel = gtk_button_new_with_label(_("Cancel"));
1698 GTK_WIDGET_UNSET_FLAGS(cancel, GTK_CAN_FOCUS);
1699 gtk_box_pack_start(GTK_BOX(filer_window->thumb_bar),
1700 cancel, FALSE, TRUE, 0);
1701 g_signal_connect_swapped(cancel, "clicked",
1702 G_CALLBACK(filer_cancel_thumbnails),
1703 filer_window);
1706 gtk_widget_show(vbox);
1707 gtk_widget_show(filer_window->scrollbar);
1709 gtk_widget_realize(filer_window->window);
1711 gdk_window_set_role(filer_window->window->window,
1712 filer_window->sym_path);
1714 filer_window_set_size(filer_window, 4, 4);
1717 static void filer_add_signals(FilerWindow *filer_window)
1719 GtkTargetEntry target_table[] =
1721 {"text/uri-list", 0, TARGET_URI_LIST},
1722 {"UTF8_STRING", 0, TARGET_STRING},
1723 {"STRING", 0, TARGET_STRING},
1724 {"COMPOUND_TEXT", 0, TARGET_STRING},/* XXX: Treats as STRING */
1727 /* Events on the top-level window */
1728 gtk_widget_add_events(filer_window->window, GDK_ENTER_NOTIFY);
1729 g_signal_connect(filer_window->window, "enter-notify-event",
1730 G_CALLBACK(pointer_in), filer_window);
1731 g_signal_connect(filer_window->window, "leave-notify-event",
1732 G_CALLBACK(pointer_out), filer_window);
1733 g_signal_connect(filer_window->window, "destroy",
1734 G_CALLBACK(filer_window_destroyed), filer_window);
1735 g_signal_connect(filer_window->window, "delete-event",
1736 G_CALLBACK(filer_window_delete), filer_window);
1738 g_signal_connect(filer_window->window, "selection_clear_event",
1739 G_CALLBACK(filer_lost_primary), filer_window);
1741 g_signal_connect(filer_window->window, "selection_get",
1742 G_CALLBACK(selection_get), filer_window);
1743 gtk_selection_add_targets(GTK_WIDGET(filer_window->window),
1744 GDK_SELECTION_PRIMARY,
1745 target_table,
1746 sizeof(target_table) / sizeof(*target_table));
1748 g_signal_connect(filer_window->window, "popup-menu",
1749 G_CALLBACK(popup_menu), filer_window);
1750 g_signal_connect(filer_window->window, "key_press_event",
1751 G_CALLBACK(filer_key_press_event), filer_window);
1753 gtk_window_add_accel_group(GTK_WINDOW(filer_window->window),
1754 filer_keys);
1757 static gint clear_scanning_display(FilerWindow *filer_window)
1759 if (filer_exists(filer_window))
1760 filer_set_title(filer_window);
1761 return FALSE;
1764 static void set_scanning_display(FilerWindow *filer_window, gboolean scanning)
1766 if (scanning == filer_window->scanning)
1767 return;
1768 filer_window->scanning = scanning;
1770 if (scanning)
1771 filer_set_title(filer_window);
1772 else
1773 g_timeout_add(300, (GSourceFunc) clear_scanning_display,
1774 filer_window);
1777 /* Note that filer_window may not exist after this call.
1778 * Returns TRUE iff the directory still exists.
1780 gboolean filer_update_dir(FilerWindow *filer_window, gboolean warning)
1782 gboolean still_exists;
1784 still_exists = may_rescan(filer_window, warning);
1786 if (still_exists)
1787 dir_update(filer_window->directory, filer_window->sym_path);
1789 return still_exists;
1792 void filer_update_all(void)
1794 GList *next = all_filer_windows;
1796 while (next)
1798 FilerWindow *filer_window = (FilerWindow *) next->data;
1800 /* Updating directory may remove it from list -- stop sending
1801 * patches to move this line!
1803 next = next->next;
1805 /* Don't trigger a refresh if we're already scanning.
1806 * Otherwise, two views of a single directory will trigger
1807 * two scans.
1809 if (filer_window->directory &&
1810 !filer_window->directory->scanning)
1811 filer_update_dir(filer_window, TRUE);
1815 /* Refresh the various caches even if we don't think we need to */
1816 void full_refresh(void)
1818 mount_update(TRUE);
1819 reread_mime_files(); /* Refreshes all windows */
1822 /* See whether a filer window with a given path already exists
1823 * and is different from diff.
1825 static FilerWindow *find_filer_window(const char *sym_path, FilerWindow *diff)
1827 GList *next;
1829 for (next = all_filer_windows; next; next = next->next)
1831 FilerWindow *filer_window = (FilerWindow *) next->data;
1833 if (filer_window != diff &&
1834 strcmp(sym_path, filer_window->sym_path) == 0)
1835 return filer_window;
1838 return NULL;
1841 /* This path has been mounted/umounted/deleted some files - update all dirs */
1842 void filer_check_mounted(const char *real_path)
1844 GList *next = all_filer_windows;
1845 gchar *parent;
1846 int len;
1847 gboolean resize = o_filer_auto_resize.int_value == RESIZE_ALWAYS;
1849 /* DOS disks, etc, often don't change the mtime of the root directory
1850 * on modification, so force a refresh now.
1852 g_fscache_update(dir_cache, real_path);
1854 len = strlen(real_path);
1856 while (next)
1858 FilerWindow *filer_window = (FilerWindow *) next->data;
1860 next = next->next;
1862 if (strncmp(real_path, filer_window->real_path, len) == 0)
1864 char s = filer_window->real_path[len];
1866 if (s == '/' || s == '\0')
1868 if (filer_update_dir(filer_window, FALSE) &&
1869 resize)
1870 view_autosize(filer_window->view);
1875 parent = g_path_get_dirname(real_path);
1876 refresh_dirs(parent);
1877 g_free(parent);
1879 icons_may_update(real_path);
1882 /* Close all windows displaying 'path' or subdirectories of 'path' */
1883 void filer_close_recursive(const char *path)
1885 GList *next = all_filer_windows;
1886 gchar *real;
1887 int len;
1889 real = pathdup(path);
1890 len = strlen(real);
1892 while (next)
1894 FilerWindow *filer_window = (FilerWindow *) next->data;
1896 next = next->next;
1898 if (strncmp(real, filer_window->real_path, len) == 0)
1900 char s = filer_window->real_path[len];
1902 if (len == 1 || s == '/' || s == '\0')
1903 gtk_widget_destroy(filer_window->window);
1908 /* Like minibuffer_show(), except that:
1909 * - It returns FALSE (to be used from an idle callback)
1910 * - It checks that the filer window still exists.
1912 static gboolean minibuffer_show_cb(FilerWindow *filer_window)
1914 if (filer_exists(filer_window))
1915 minibuffer_show(filer_window, MINI_PATH);
1916 return FALSE;
1919 /* TRUE iff filer_window points to an existing FilerWindow
1920 * structure.
1922 gboolean filer_exists(FilerWindow *filer_window)
1924 GList *next;
1926 for (next = all_filer_windows; next; next = next->next)
1928 FilerWindow *fw = (FilerWindow *) next->data;
1930 if (fw == filer_window)
1931 return TRUE;
1934 return FALSE;
1937 FilerWindow *filer_get_by_id(const char *id)
1939 return g_hash_table_lookup(window_with_id, id);
1942 void filer_set_id(FilerWindow *filer_window, const char *id)
1944 g_return_if_fail(filer_window != NULL);
1946 if (filer_window->window_id)
1948 g_hash_table_remove(window_with_id, filer_window->window_id);
1949 g_free(filer_window->window_id);
1950 filer_window->window_id = NULL;
1953 if (id)
1955 filer_window->window_id = g_strdup(id);
1956 g_hash_table_insert(window_with_id,
1957 filer_window->window_id,
1958 filer_window);
1962 /* Make sure the window title is up-to-date */
1963 void filer_set_title(FilerWindow *filer_window)
1965 gchar *title = NULL;
1966 guchar *flags = "";
1967 gchar *hidden = "";
1969 if (filer_window->scanning ||
1970 filer_window->filter != FILER_SHOW_ALL ||
1971 filer_window->show_hidden || filer_window->show_thumbs)
1973 if (o_short_flag_names.int_value)
1976 switch(filer_window->filter) {
1977 case FILER_SHOW_ALL:
1978 hidden=filer_window->show_hidden? "A": "";
1979 break;
1980 case FILER_SHOW_GLOB: hidden="G"; break;
1981 case FILER_SHOW_REGEXP: hidden="R"; break;
1982 default: break;
1985 flags = g_strconcat(" +",
1986 filer_window->scanning ? _("S") : "",
1987 hidden,
1988 filer_window->show_thumbs ? _("T") : "",
1989 NULL);
1991 else
1993 switch(filer_window->filter) {
1994 case FILER_SHOW_ALL:
1995 hidden=g_strdup(filer_window->show_hidden? "All, ": "");
1996 break;
1997 case FILER_SHOW_GLOB:
1998 hidden=g_strdup_printf("Glob (%s), ",
1999 filer_window->filter_string);
2000 break;
2001 case FILER_SHOW_REGEXP:
2002 hidden=g_strdup_printf("Regexp (%s), ",
2003 filer_window->filter_string);
2004 break;
2005 default:
2006 hidden=g_strdup("");
2007 break;
2009 flags = g_strconcat(" (",
2010 filer_window->scanning ? _("Scanning, ") : "",
2011 hidden,
2012 filer_window->show_thumbs ? _("Thumbs, ") : "",
2013 NULL);
2014 flags[strlen(flags) - 2] = ')';
2015 g_free(hidden);
2019 if (not_local)
2020 title = g_strconcat("//", our_host_name(),
2021 filer_window->sym_path, flags, NULL);
2023 if (!title && home_dir_len > 1 &&
2024 strncmp(filer_window->sym_path, home_dir, home_dir_len) == 0)
2026 guchar sep = filer_window->sym_path[home_dir_len];
2028 if (sep == '\0' || sep == '/')
2029 title = g_strconcat("~",
2030 filer_window->sym_path + home_dir_len,
2031 flags,
2032 NULL);
2035 if (!title)
2036 title = g_strconcat(filer_window->sym_path, flags, NULL);
2038 ensure_utf8(&title);
2040 if (filer_window->directory->error)
2042 gchar *old = title;
2043 title = g_strconcat(old, ": ", filer_window->directory->error,
2044 NULL);
2045 g_free(old);
2048 gtk_window_set_title(GTK_WINDOW(filer_window->window), title);
2050 g_free(title);
2052 if (flags[0] != '\0')
2053 g_free(flags);
2056 /* Reconnect to the same directory (used when the Show Hidden option is
2057 * toggled). This has the side-effect of updating the window title.
2059 void filer_detach_rescan(FilerWindow *filer_window)
2061 Directory *dir = filer_window->directory;
2063 g_object_ref(dir);
2064 detach(filer_window);
2065 filer_window->directory = dir;
2066 attach(filer_window);
2069 /* Puts the filer window into target mode. When an item is chosen,
2070 * fn(filer_window, iter, data) is called. 'reason' will be displayed
2071 * on the toolbar while target mode is active.
2073 * Use fn == NULL to cancel target mode.
2075 void filer_target_mode(FilerWindow *filer_window,
2076 TargetFunc fn,
2077 gpointer data,
2078 const char *reason)
2080 TargetFunc old_fn = filer_window->target_cb;
2082 if (fn != old_fn)
2083 gdk_window_set_cursor(
2084 GTK_WIDGET(filer_window->view)->window,
2085 fn ? crosshair : NULL);
2087 filer_window->target_cb = fn;
2088 filer_window->target_data = data;
2090 if (filer_window->toolbar_text == NULL)
2091 return;
2093 if (fn)
2094 gtk_label_set_text(
2095 GTK_LABEL(filer_window->toolbar_text), reason);
2096 else if (o_toolbar_info.int_value)
2098 if (old_fn)
2099 toolbar_update_info(filer_window);
2101 else
2102 gtk_label_set_text(GTK_LABEL(filer_window->toolbar_text), "");
2105 static void set_selection_state(FilerWindow *filer_window, gboolean normal)
2107 GtkStateType old_state = filer_window->selection_state;
2109 filer_window->selection_state = normal
2110 ? GTK_STATE_SELECTED : GTK_STATE_INSENSITIVE;
2112 if (old_state != filer_window->selection_state
2113 && view_count_selected(filer_window->view))
2114 gtk_widget_queue_draw(GTK_WIDGET(filer_window->view));
2117 void filer_cancel_thumbnails(FilerWindow *filer_window)
2119 gtk_widget_hide(filer_window->thumb_bar);
2121 destroy_glist(&filer_window->thumb_queue);
2122 filer_window->max_thumbs = 0;
2125 /* Generate the next thumb for this window. The window object is
2126 * unref'd when there is nothing more to do.
2127 * If the window no longer has a filer window, nothing is done.
2129 static gboolean filer_next_thumb_real(GObject *window)
2131 FilerWindow *filer_window;
2132 gchar *path;
2133 int done, total;
2135 filer_window = g_object_get_data(window, "filer_window");
2137 if (!filer_window)
2139 g_object_unref(window);
2140 return FALSE;
2143 if (!filer_window->thumb_queue)
2145 filer_cancel_thumbnails(filer_window);
2146 g_object_unref(window);
2147 return FALSE;
2150 total = filer_window->max_thumbs;
2151 done = total - g_list_length(filer_window->thumb_queue);
2153 path = (gchar *) filer_window->thumb_queue->data;
2155 pixmap_background_thumb(path, (GFunc) filer_next_thumb, window);
2157 filer_window->thumb_queue = g_list_remove(filer_window->thumb_queue,
2158 path);
2159 g_free(path);
2161 gtk_progress_bar_set_fraction(
2162 GTK_PROGRESS_BAR(filer_window->thumb_progress),
2163 done / (float) total);
2165 return FALSE;
2168 /* path is the thumb just loaded, if any.
2169 * window is unref'd (eventually).
2171 static void filer_next_thumb(GObject *window, const gchar *path)
2173 if (path)
2174 dir_force_update_path(path);
2176 g_idle_add((GSourceFunc) filer_next_thumb_real, window);
2179 static void start_thumb_scanning(FilerWindow *filer_window)
2181 if (GTK_WIDGET_VISIBLE(filer_window->thumb_bar))
2182 return; /* Already scanning */
2184 gtk_widget_show_all(filer_window->thumb_bar);
2186 g_object_ref(G_OBJECT(filer_window->window));
2187 filer_next_thumb(G_OBJECT(filer_window->window), NULL);
2190 /* Set this image to be loaded some time in the future */
2191 void filer_create_thumb(FilerWindow *filer_window, const gchar *path)
2193 filer_window->max_thumbs++;
2195 filer_window->thumb_queue = g_list_append(filer_window->thumb_queue,
2196 g_strdup(path));
2198 if (filer_window->scanning)
2199 return; /* Will start when scan ends */
2201 start_thumb_scanning(filer_window);
2204 /* If thumbnail display is on, look through all the items in this directory
2205 * and start creating or updating the thumbnails as needed.
2207 void filer_create_thumbs(FilerWindow *filer_window)
2209 DirItem *item;
2210 ViewIter iter;
2212 if (!filer_window->show_thumbs)
2213 return;
2215 view_get_iter(filer_window->view, &iter, 0);
2217 while ((item = iter.next(&iter)))
2219 MaskedPixmap *pixmap;
2220 const guchar *path;
2221 gboolean found;
2223 if (item->base_type != TYPE_FILE)
2224 continue;
2226 /*if (strcmp(item->mime_type->media_type, "image") != 0)
2227 continue;*/
2229 path = make_path(filer_window->real_path, item->leafname);
2231 pixmap = g_fscache_lookup_full(pixmap_cache, path,
2232 FSCACHE_LOOKUP_ONLY_NEW, &found);
2233 if (pixmap)
2234 g_object_unref(pixmap);
2236 /* If we didn't get an image, it could be because:
2238 * - We're loading the image now. found is TRUE,
2239 * and we'll update the item later.
2240 * - We tried to load the image and failed. found
2241 * is TRUE.
2242 * - We haven't tried loading the image. found is
2243 * FALSE, and we start creating the thumb here.
2245 if (!found)
2246 filer_create_thumb(filer_window, path);
2250 static void filer_options_changed(void)
2252 if (o_short_flag_names.has_changed)
2254 GList *next;
2256 for (next = all_filer_windows; next; next = next->next)
2258 FilerWindow *filer_window = (FilerWindow *) next->data;
2260 filer_set_title(filer_window);
2265 /* Append interesting information to this GString */
2266 void filer_add_tip_details(FilerWindow *filer_window,
2267 GString *tip, DirItem *item)
2269 const guchar *fullpath = NULL;
2271 fullpath = make_path(filer_window->real_path, item->leafname);
2273 if (item->flags & ITEM_FLAG_SYMLINK)
2275 char *target;
2277 target = readlink_dup(fullpath);
2278 if (target)
2280 ensure_utf8(&target);
2282 g_string_append(tip, _("Symbolic link to "));
2283 g_string_append(tip, target);
2284 g_string_append_c(tip, '\n');
2285 g_free(target);
2289 if (item->flags & ITEM_FLAG_APPDIR)
2291 XMLwrapper *info;
2292 xmlNode *node;
2294 info = appinfo_get(fullpath, item);
2295 if (info && ((node = xml_get_section(info, NULL, "Summary"))))
2297 guchar *str;
2298 str = xmlNodeListGetString(node->doc,
2299 node->xmlChildrenNode, 1);
2300 if (str)
2302 g_string_append(tip, str);
2303 g_string_append_c(tip, '\n');
2304 g_free(str);
2307 if (info)
2308 g_object_unref(info);
2311 if (!g_utf8_validate(item->leafname, -1, NULL))
2312 g_string_append(tip,
2313 _("This filename is not valid UTF-8. "
2314 "You should rename it.\n"));
2317 /* Return the selection as a text/uri-list.
2318 * g_free() the result.
2320 static guchar *filer_create_uri_list(FilerWindow *filer_window)
2322 GString *string;
2323 GString *leader;
2324 ViewIter iter;
2325 DirItem *item;
2326 guchar *retval;
2328 g_return_val_if_fail(filer_window != NULL, NULL);
2330 string = g_string_new(NULL);
2332 leader = g_string_new(filer_window->sym_path);
2333 if (leader->str[leader->len - 1] != '/')
2334 g_string_append_c(leader, '/');
2336 view_get_iter(filer_window->view, &iter, VIEW_ITER_SELECTED);
2337 while ((item = iter.next(&iter)))
2339 EscapedPath *uri;
2340 char *path;
2342 path = g_strconcat(leader->str, item->leafname, NULL);
2343 uri = encode_path_as_uri(path);
2344 g_string_append(string, (char *) uri);
2345 g_string_append(string, "\r\n");
2346 g_free(path);
2347 g_free(uri);
2350 g_string_free(leader, TRUE);
2351 retval = string->str;
2352 g_string_free(string, FALSE);
2354 return retval;
2357 void filer_perform_action(FilerWindow *filer_window, GdkEventButton *event)
2359 BindAction action;
2360 ViewIface *view = filer_window->view;
2361 DirItem *item = NULL;
2362 gboolean press = event->type == GDK_BUTTON_PRESS;
2363 ViewIter iter;
2364 OpenFlags flags = 0;
2366 if (event->button > 3)
2367 return;
2369 view_get_iter_at_point(view, &iter, event->window, event->x, event->y);
2370 item = iter.peek(&iter);
2372 if (item && event->button == 1 &&
2373 view_get_selected(view, &iter) &&
2374 filer_window->selection_state == GTK_STATE_INSENSITIVE)
2376 /* Possibly a really slow DnD operation? */
2377 filer_window->temp_item_selected = FALSE;
2379 filer_selection_changed(filer_window, event->time);
2380 return;
2383 if (filer_window->target_cb)
2385 dnd_motion_ungrab();
2386 if (item && press && event->button == 1)
2387 filer_window->target_cb(filer_window, &iter,
2388 filer_window->target_data);
2390 filer_target_mode(filer_window, NULL, NULL, NULL);
2392 return;
2395 if (!o_single_click.int_value)
2397 /* Make sure both parts of a double-click fall on
2398 * the same file.
2400 static guchar *first_click = NULL;
2401 static guchar *second_click = NULL;
2403 if (event->type == GDK_BUTTON_PRESS)
2405 g_free(first_click);
2406 first_click = second_click;
2408 if (item)
2409 second_click = g_strdup(item->leafname);
2410 else
2411 second_click = NULL;
2414 if (event->type == GDK_2BUTTON_PRESS)
2416 if (first_click && second_click &&
2417 strcmp(first_click, second_click) != 0)
2418 return;
2419 if ((first_click || second_click) &&
2420 !(first_click && second_click))
2421 return;
2425 action = bind_lookup_bev(
2426 item ? BIND_DIRECTORY_ICON : BIND_DIRECTORY,
2427 event);
2429 switch (action)
2431 case ACT_CLEAR_SELECTION:
2432 view_clear_selection(view);
2433 break;
2434 case ACT_TOGGLE_SELECTED:
2435 view_set_selected(view, &iter,
2436 !view_get_selected(view, &iter));
2437 break;
2438 case ACT_SELECT_EXCL:
2439 view_select_only(view, &iter);
2440 break;
2441 case ACT_EDIT_ITEM:
2442 flags |= OPEN_SHIFT;
2443 /* (no break) */
2444 case ACT_OPEN_ITEM:
2445 if (event->button != 1 || event->state & GDK_MOD1_MASK)
2446 flags |= OPEN_CLOSE_WINDOW;
2447 else
2448 flags |= OPEN_SAME_WINDOW;
2449 if (o_new_button_1.int_value)
2450 flags ^= OPEN_SAME_WINDOW;
2451 if (event->type == GDK_2BUTTON_PRESS)
2452 view_set_selected(view, &iter, FALSE);
2453 dnd_motion_ungrab();
2455 filer_openitem(filer_window, &iter, flags);
2456 break;
2457 case ACT_POPUP_MENU:
2458 dnd_motion_ungrab();
2459 tooltip_show(NULL);
2460 show_filer_menu(filer_window,
2461 (GdkEvent *) event, &iter);
2462 break;
2463 case ACT_PRIME_AND_SELECT:
2464 if (item && !view_get_selected(view, &iter))
2465 view_select_only(view, &iter);
2466 dnd_motion_start(MOTION_READY_FOR_DND);
2467 break;
2468 case ACT_PRIME_AND_TOGGLE:
2469 view_set_selected(view, &iter,
2470 !view_get_selected(view, &iter));
2471 dnd_motion_start(MOTION_READY_FOR_DND);
2472 break;
2473 case ACT_PRIME_FOR_DND:
2474 dnd_motion_start(MOTION_READY_FOR_DND);
2475 break;
2476 case ACT_IGNORE:
2477 if (press && event->button < 4)
2479 if (item)
2480 view_wink_item(view, &iter);
2481 dnd_motion_start(MOTION_NONE);
2483 break;
2484 case ACT_LASSO_CLEAR:
2485 view_clear_selection(view);
2486 /* (no break) */
2487 case ACT_LASSO_MODIFY:
2488 view_start_lasso_box(view, event);
2489 break;
2490 case ACT_RESIZE:
2491 view_autosize(filer_window->view);
2492 break;
2493 default:
2494 g_warning("Unsupported action : %d\n", action);
2495 break;
2499 /* It's time to make the tooltip appear. If we're not over the item any
2500 * more, or the item doesn't need a tooltip, do nothing.
2502 static gboolean tooltip_activate(GtkWidget *window)
2504 FilerWindow *filer_window;
2505 ViewIface *view;
2506 ViewIter iter;
2507 gint x, y;
2508 DirItem *item = NULL;
2509 GString *tip = NULL;
2511 g_return_val_if_fail(tip_item != NULL, 0);
2513 filer_window = g_object_get_data(G_OBJECT(window), "filer_window");
2515 if (!motion_window || !filer_window)
2516 return FALSE; /* Window has been destroyed */
2518 view = filer_window->view;
2520 tooltip_show(NULL);
2522 gdk_window_get_pointer(motion_window, &x, &y, NULL);
2523 view_get_iter_at_point(view, &iter, motion_window, x, y);
2525 item = iter.peek(&iter);
2526 if (item != tip_item)
2527 return FALSE; /* Not still under the pointer */
2529 /* OK, the filer window still exists and the pointer is still
2530 * over the same item. Do we need to show a tip?
2533 tip = g_string_new(NULL);
2535 view_extend_tip(filer_window->view, &iter, tip);
2537 filer_add_tip_details(filer_window, tip, tip_item);
2539 if (tip->len > 1)
2541 g_string_truncate(tip, tip->len - 1);
2543 tooltip_show(tip->str);
2546 g_string_free(tip, TRUE);
2548 return FALSE;
2551 /* Motion detected on the View widget */
2552 gint filer_motion_notify(FilerWindow *filer_window, GdkEventMotion *event)
2554 ViewIface *view = filer_window->view;
2555 ViewIter iter;
2556 DirItem *item;
2558 view_get_iter_at_point(view, &iter, event->window, event->x, event->y);
2559 item = iter.peek(&iter);
2561 if (item)
2563 if (item != tip_item)
2565 tooltip_show(NULL);
2567 tip_item = item;
2568 motion_window = event->window;
2569 tooltip_prime((GtkFunction) tooltip_activate,
2570 G_OBJECT(filer_window->window));
2573 else
2575 tooltip_show(NULL);
2576 tip_item = NULL;
2579 if (motion_state != MOTION_READY_FOR_DND)
2580 return FALSE;
2582 if (!dnd_motion_moved(event))
2583 return FALSE;
2585 view_get_iter_at_point(view, &iter,
2586 event->window,
2587 event->x - (event->x_root - drag_start_x),
2588 event->y - (event->y_root - drag_start_y));
2589 item = iter.peek(&iter);
2590 if (!item)
2591 return FALSE;
2593 view_wink_item(view, NULL);
2595 if (!view_get_selected(view, &iter))
2597 if (event->state & GDK_BUTTON1_MASK)
2599 /* Select just this one */
2600 filer_window->temp_item_selected = TRUE;
2601 view_select_only(view, &iter);
2603 else
2605 if (view_count_selected(view) == 0)
2606 filer_window->temp_item_selected = TRUE;
2607 view_set_selected(view, &iter, TRUE);
2611 g_return_val_if_fail(view_count_selected(view) > 0, TRUE);
2613 if (view_count_selected(view) == 1)
2615 if (item->base_type == TYPE_UNKNOWN)
2616 item = dir_update_item(filer_window->directory,
2617 item->leafname);
2619 if (!item)
2621 report_error(_("Item no longer exists!"));
2622 return FALSE;
2625 drag_one_item(GTK_WIDGET(view), event,
2626 make_path(filer_window->sym_path, item->leafname),
2627 item, di_image(item));
2628 #if 0
2629 /* XXX: Use thumbnail */
2630 item, view ? view->image : NULL);
2631 #endif
2633 else
2635 guchar *uris;
2637 uris = filer_create_uri_list(filer_window);
2638 drag_selection(GTK_WIDGET(view), event, uris);
2639 g_free(uris);
2642 return FALSE;
2645 static void drag_end(GtkWidget *widget, GdkDragContext *context,
2646 FilerWindow *filer_window)
2648 filer_set_autoscroll(filer_window, FALSE);
2650 if (filer_window->temp_item_selected)
2652 view_clear_selection(filer_window->view);
2653 filer_window->temp_item_selected = FALSE;
2657 /* Remove highlights */
2658 static void drag_leave(GtkWidget *widget,
2659 GdkDragContext *context,
2660 guint32 time,
2661 FilerWindow *filer_window)
2663 dnd_spring_abort();
2666 /* Called during the drag when the mouse is in a widget registered
2667 * as a drop target. Returns TRUE if we can accept the drop.
2669 static gboolean drag_motion(GtkWidget *widget,
2670 GdkDragContext *context,
2671 gint x,
2672 gint y,
2673 guint time,
2674 FilerWindow *filer_window)
2676 DirItem *item;
2677 ViewIface *view = filer_window->view;
2678 ViewIter iter;
2679 GdkDragAction action = context->suggested_action;
2680 const guchar *new_path = NULL;
2681 const char *type = NULL;
2682 gboolean retval = FALSE;
2683 gboolean same_window;
2685 if ((context->actions & GDK_ACTION_ASK) && o_dnd_left_menu.int_value)
2687 guint state;
2688 gdk_window_get_pointer(NULL, NULL, NULL, &state);
2689 if (state & GDK_BUTTON1_MASK)
2690 action = GDK_ACTION_ASK;
2693 same_window = gtk_drag_get_source_widget(context) == widget;
2695 filer_set_autoscroll(filer_window, TRUE);
2697 if (filer_window->view_type == VIEW_TYPE_DETAILS)
2699 GdkWindow *bin;
2700 int bin_y;
2701 /* Correct for position of bin window */
2702 bin = gtk_tree_view_get_bin_window(GTK_TREE_VIEW(view));
2703 gdk_window_get_position(bin, NULL, &bin_y);
2704 y -= bin_y;
2707 if (o_dnd_drag_to_icons.int_value)
2709 view_get_iter_at_point(view, &iter, widget->window, x, y);
2710 item = iter.peek(&iter);
2712 else
2713 item = NULL;
2715 if (item && same_window && view_get_selected(view, &iter))
2716 type = NULL;
2717 else
2718 type = dnd_motion_item(context, &item);
2720 if (!type)
2721 item = NULL;
2723 /* Don't allow drops to non-writeable directories. BUT, still
2724 * allow drops on non-writeable SUBdirectories so that we can
2725 * do the spring-open thing.
2727 if (item && type == drop_dest_dir &&
2728 !(item->flags & ITEM_FLAG_APPDIR))
2730 dnd_spring_load(context, filer_window);
2732 else
2733 dnd_spring_abort();
2735 if (item)
2736 view_cursor_to_iter(view, &iter);
2737 else
2739 view_cursor_to_iter(view, NULL);
2741 /* Disallow background drops within a single window */
2742 if (type && same_window)
2743 type = NULL;
2746 if (type)
2748 if (item)
2749 new_path = make_path(filer_window->sym_path,
2750 item->leafname);
2751 else
2752 new_path = filer_window->sym_path;
2755 /* Don't ask about dragging to an application! */
2756 if (type == drop_dest_prog && action == GDK_ACTION_ASK)
2757 action = GDK_ACTION_COPY;
2759 g_dataset_set_data(context, "drop_dest_type", (gpointer) type);
2760 if (type)
2762 gdk_drag_status(context, action, time);
2763 g_dataset_set_data_full(context, "drop_dest_path",
2764 g_strdup(new_path), g_free);
2765 retval = TRUE;
2768 return retval;
2771 static gboolean as_timeout(FilerWindow *filer_window)
2773 gboolean retval;
2775 retval = view_auto_scroll_callback(filer_window->view);
2777 if (!retval)
2778 filer_window->auto_scroll = -1;
2780 return retval;
2783 /* When autoscroll is on, a timer keeps track of the pointer position.
2784 * While it's near the top or bottom of the window, the window scrolls.
2786 * If the mouse buttons are released, the pointer leaves the window, or
2787 * a drag-and-drop operation finishes, auto_scroll is turned off.
2789 void filer_set_autoscroll(FilerWindow *filer_window, gboolean auto_scroll)
2791 g_return_if_fail(filer_window != NULL);
2793 if (auto_scroll)
2795 if (filer_window->auto_scroll != -1)
2796 return; /* Already on! */
2798 filer_window->auto_scroll = g_timeout_add(50,
2799 (GSourceFunc) as_timeout,
2800 filer_window);
2802 else
2804 if (filer_window->auto_scroll == -1)
2805 return; /* Already off! */
2807 g_source_remove(filer_window->auto_scroll);
2808 filer_window->auto_scroll = -1;
2812 #define ZERO_MNT "/uri/0install"
2814 static void refresh_done(FilerWindow *filer_window)
2816 if (filer_exists(filer_window))
2817 filer_update_dir(filer_window, TRUE);
2820 void filer_refresh(FilerWindow *filer_window)
2822 if (!strncmp(ZERO_MNT "/", filer_window->real_path, sizeof(ZERO_MNT)))
2824 /* Try to run 0refresh */
2825 gint pid;
2826 gchar *argv[] = {"0refresh", NULL, NULL};
2827 const char *host = filer_window->real_path + sizeof(ZERO_MNT);
2828 const char *slash;
2830 slash = strchr(host, '/');
2831 if (slash)
2832 argv[1] = g_strndup(host, slash - host);
2833 else
2834 argv[1] = g_strdup(host);
2835 pid = rox_spawn(filer_window->real_path, (const char **) argv);
2836 g_free(argv[1]);
2837 if (pid)
2838 on_child_death(pid, (CallbackFn) refresh_done,
2839 filer_window);
2842 full_refresh();
2845 gboolean filer_match_filter(FilerWindow *filer_window, const gchar *filename)
2847 g_return_val_if_fail(filename != NULL, FALSE);
2849 if(filename[0]=='.' &&
2850 (!filer_window->temp_show_hidden && !filer_window->show_hidden))
2851 return FALSE;
2853 switch(filer_window->filter) {
2854 case FILER_SHOW_GLOB:
2855 return fnmatch(filer_window->filter_string,
2856 filename, 0)==0;
2858 case FILER_SHOW_REGEXP: /* Unimplemented */
2860 case FILER_SHOW_ALL:
2861 default:
2862 break;
2864 return TRUE;
2867 /* Provided to hide the implementation */
2868 void filer_set_hidden(FilerWindow *filer_window, gboolean hidden)
2870 filer_window->show_hidden=hidden;
2873 /* Set the filter type. Returns TRUE if the type has changed
2874 * (must call filer_detach_rescan).
2876 gboolean filer_set_filter(FilerWindow *filer_window, FilterType type,
2877 const gchar *filter_string)
2879 /* Is this new filter the same as the old one? */
2880 if (filer_window->filter == type)
2882 switch(filer_window->filter)
2884 case FILER_SHOW_ALL:
2885 return FALSE;
2886 case FILER_SHOW_GLOB:
2887 case FILER_SHOW_REGEXP:
2888 if (strcmp(filer_window->filter_string,
2889 filter_string) == 0)
2890 return FALSE;
2891 break;
2895 /* Clean up old filter */
2896 if (filer_window->filter_string)
2898 g_free(filer_window->filter_string);
2899 filer_window->filter_string = NULL;
2901 /* Also clean up compiled regexp when implemented */
2903 filer_window->filter = type;
2905 switch(type)
2907 case FILER_SHOW_ALL:
2908 /* No extra work */
2909 break;
2911 case FILER_SHOW_GLOB:
2912 filer_window->filter_string = g_strdup(filter_string);
2913 break;
2915 case FILER_SHOW_REGEXP:
2916 filer_window->filter_string = g_strdup(filter_string);
2917 /* Compile the pattern */
2918 break;
2920 default:
2921 /* oops */
2922 filer_window->filter = FILER_SHOW_ALL;
2923 g_warning("Impossible: filter type %d", type);
2924 break;
2927 return TRUE;
2930 /* Setting stuff */
2931 static Settings *settings_new(const char *path)
2933 Settings *set;
2935 set=g_new(Settings, 1);
2936 memset(set, 0, sizeof(Settings));
2937 if(path)
2938 set->path=g_strdup(path);
2940 return set;
2943 static void settings_free(Settings *set)
2945 g_free(set->path);
2946 if(set->filter)
2947 g_free(set->filter);
2948 g_free(set);
2951 static gboolean free_settings(gpointer key, gpointer value, gpointer data)
2953 if(!data || strcmp(data, key)==0)
2954 settings_free(value);
2956 return TRUE;
2959 static void store_settings(Settings *set)
2961 Settings *old;
2963 old=g_hash_table_lookup(settings_table, set->path);
2964 if(old) {
2965 g_hash_table_foreach_remove(settings_table, free_settings,
2966 set->path);
2969 g_hash_table_insert(settings_table, set->path, set);
2972 /* TODO: use symbolic names in the XML file where possible */
2973 static void load_from_node(Settings *set, xmlDocPtr doc, xmlNodePtr node)
2975 xmlChar *str=NULL;
2977 str=xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
2979 if(strcmp(node->name, "X") == 0) {
2980 set->x=atoi(str);
2981 set->flags|=SET_POSITION;
2982 } else if(strcmp(node->name, "Y") == 0) {
2983 set->y=atoi(str);
2984 set->flags|=SET_POSITION;
2985 } else if(strcmp(node->name, "Width") == 0) {
2986 set->width=atoi(str);
2987 set->flags|=SET_SIZE;
2988 } else if(strcmp(node->name, "Height") == 0) {
2989 set->height=atoi(str);
2990 set->flags|=SET_SIZE;
2991 } else if(strcmp(node->name, "ShowHidden") == 0) {
2992 set->show_hidden=atoi(str);
2993 set->flags|=SET_HIDDEN;
2994 } else if(strcmp(node->name, "ViewType") == 0) {
2995 set->view_type=atoi(str);
2996 set->flags|=SET_DETAILS;
2997 } else if(strcmp(node->name, "DetailsType") == 0) {
2998 set->details_type=atoi(str);
2999 set->flags|=SET_DETAILS;
3000 } else if(strcmp(node->name, "SortType") == 0) {
3001 set->sort_type=atoi(str);
3002 set->flags|=SET_SORT;
3003 } else if(strcmp(node->name, "SortOrder") == 0) {
3004 set->sort_order=atoi(str);
3005 set->flags|=SET_SORT;
3006 } else if(strcmp(node->name, "DisplayStyle") == 0) {
3007 set->display_style=atoi(str);
3008 set->flags|=SET_STYLE;
3009 } else if(strcmp(node->name, "ShowThumbs") == 0) {
3010 set->show_thumbs=atoi(str);
3011 set->flags|=SET_THUMBS;
3012 } else if(strcmp(node->name, "FilterType") == 0) {
3013 set->filter_type=atoi(str);
3014 set->flags|=SET_FILTER;
3015 } else if(strcmp(node->name, "Filter") == 0) {
3016 set->filter=g_strdup(str);
3017 set->flags|=SET_FILTER;
3020 if(str)
3021 xmlFree(str);
3024 static void load_settings(void)
3026 gchar *path;
3027 XMLwrapper *settings_doc=NULL;
3029 path=choices_find_path_load("Settings.xml", "ROX-Filer");
3030 if(path) {
3031 settings_doc=xml_new(path);
3032 g_free(path);
3035 if(!settings_table)
3036 settings_table=g_hash_table_new(g_str_hash, g_str_equal);
3038 if(settings_doc) {
3039 xmlNodePtr node, subnode;
3041 node = xmlDocGetRootElement(settings_doc->doc);
3043 for (node = node->xmlChildrenNode; node; node = node->next)
3045 Settings *set;
3046 xmlChar *path;
3048 if (node->type != XML_ELEMENT_NODE)
3049 continue;
3050 if (strcmp(node->name, "FilerWindow") != 0)
3051 continue;
3053 path=xmlGetProp(node, "path");
3054 set=settings_new(path);
3055 xmlFree(path);
3057 for (subnode=node->xmlChildrenNode; subnode;
3058 subnode=subnode->next) {
3060 if (subnode->type != XML_ELEMENT_NODE)
3061 continue;
3062 load_from_node(set, settings_doc->doc,
3063 subnode);
3066 store_settings(set);
3068 g_object_unref(settings_doc);
3072 static void add_nodes(gpointer key, gpointer value, gpointer data)
3074 xmlNodePtr node=(xmlNodePtr) data;
3075 xmlNodePtr sub;
3076 Settings *set=(Settings *) value;
3077 char *tmp;
3079 sub=xmlNewChild(node, NULL, "FilerWindow", NULL);
3081 xmlSetProp(sub, "path", set->path);
3083 if(set->flags & SET_POSITION) {
3084 tmp=g_strdup_printf("%d", set->x);
3085 xmlNewChild(sub, NULL, "X", tmp);
3086 g_free(tmp);
3087 tmp=g_strdup_printf("%d", set->y);
3088 xmlNewChild(sub, NULL, "Y", tmp);
3089 g_free(tmp);
3091 if(set->flags & SET_SIZE) {
3092 tmp=g_strdup_printf("%d", set->width);
3093 xmlNewChild(sub, NULL, "Width", tmp);
3094 g_free(tmp);
3095 tmp=g_strdup_printf("%d", set->height);
3096 xmlNewChild(sub, NULL, "Height", tmp);
3097 g_free(tmp);
3099 if(set->flags & SET_HIDDEN) {
3100 tmp=g_strdup_printf("%d", set->show_hidden);
3101 xmlNewChild(sub, NULL, "ShowHidden", tmp);
3102 g_free(tmp);
3104 if(set->flags & SET_STYLE) {
3105 tmp=g_strdup_printf("%d", set->display_style);
3106 xmlNewChild(sub, NULL, "DisplayStyle", tmp);
3107 g_free(tmp);
3109 if(set->flags & SET_SORT) {
3110 tmp=g_strdup_printf("%d", set->sort_type);
3111 xmlNewChild(sub, NULL, "SortType", tmp);
3112 g_free(tmp);
3113 tmp=g_strdup_printf("%d", set->sort_order);
3114 xmlNewChild(sub, NULL, "SortOrder", tmp);
3115 g_free(tmp);
3117 if(set->flags & SET_DETAILS) {
3118 tmp=g_strdup_printf("%d", set->view_type);
3119 xmlNewChild(sub, NULL, "ViewType", tmp);
3120 g_free(tmp);
3121 tmp=g_strdup_printf("%d", set->details_type);
3122 xmlNewChild(sub, NULL, "DetailsType", tmp);
3123 g_free(tmp);
3125 if(set->flags & SET_STYLE) {
3126 tmp=g_strdup_printf("%d", set->show_thumbs);
3127 xmlNewChild(sub, NULL, "ShowThumbs", tmp);
3128 g_free(tmp);
3130 if(set->flags & SET_FILTER) {
3131 tmp=g_strdup_printf("%d", set->filter_type);
3132 xmlNewChild(sub, NULL, "FilterType", tmp);
3133 g_free(tmp);
3134 if(set->filter && set->filter[0])
3135 xmlNewChild(sub, NULL, "Filter", set->filter);
3139 static void save_settings(void)
3141 gchar *path;
3143 path=choices_find_path_save("Settings.xml", "ROX-Filer", TRUE);
3144 if(path) {
3145 xmlDocPtr doc = xmlNewDoc("1.0");
3146 xmlDocSetRootElement(doc, xmlNewDocNode(doc, NULL,
3147 "Settings", NULL));
3149 g_hash_table_foreach(settings_table, add_nodes,
3150 xmlDocGetRootElement(doc));
3152 save_xml_file(doc, path);
3154 g_free(path);
3155 xmlFreeDoc(doc);
3160 static void check_settings(FilerWindow *filer_window)
3162 Settings *set;
3164 set=(Settings *) g_hash_table_lookup(settings_table,
3165 filer_window->sym_path);
3167 if(set) {
3168 if(set->flags & SET_POSITION)
3169 gtk_window_move(GTK_WINDOW(filer_window->window),
3170 set->x, set->y);
3171 if(set->flags & SET_SIZE)
3172 filer_window_set_size(filer_window, set->width,
3173 set->height);
3174 if(set->flags & SET_HIDDEN)
3175 filer_set_hidden(filer_window, set->show_hidden);
3177 if(set->flags & (SET_STYLE|SET_DETAILS)) {
3178 DisplayStyle style=filer_window->display_style;
3179 DetailsType details=filer_window->details_type;
3181 if(set->flags & SET_STYLE)
3182 style=set->display_style;
3184 if(set->flags & SET_DETAILS) {
3185 details=set->details_type;
3187 filer_set_view_type(filer_window,
3188 set->view_type);
3191 display_set_layout(filer_window, style,
3192 details, FALSE);
3195 if(set->flags & SET_SORT)
3196 display_set_sort_type(filer_window,
3197 set->sort_type,
3198 set->sort_order);
3200 if(set->flags & SET_THUMBS)
3201 display_set_thumbs(filer_window,
3202 set->show_thumbs);
3204 if(set->flags & SET_FILTER)
3205 display_set_filter(filer_window,
3206 set->filter_type,
3207 set->filter);
3212 typedef struct settings_window {
3213 GtkWidget *window;
3215 GtkWidget *pos, *size, *hidden, *style, *sort, *details,
3216 *thumbs, *filter;
3218 Settings *set;
3219 } SettingsWindow;
3222 static void settings_response(GtkWidget *window, gint response,
3223 SettingsWindow *set_win)
3225 if(response==GTK_RESPONSE_OK) {
3226 gint flags=0;
3228 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(set_win->pos)))
3229 flags|=SET_POSITION;
3230 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(set_win->size)))
3231 flags|=SET_SIZE;
3232 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(set_win->hidden)))
3233 flags|=SET_HIDDEN;
3234 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(set_win->style)))
3235 flags|=SET_STYLE;
3236 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(set_win->sort)))
3237 flags|=SET_SORT;
3238 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(set_win->details)))
3239 flags|=SET_DETAILS;
3240 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(set_win->thumbs)))
3241 flags|=SET_THUMBS;
3242 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(set_win->filter)))
3243 flags|=SET_FILTER;
3245 set_win->set->flags=flags;
3246 store_settings(set_win->set);
3247 save_settings();
3250 gtk_widget_destroy(window);
3253 void filer_save_settings(FilerWindow *fwin)
3255 SettingsWindow *set_win;
3256 GtkWidget *vbox;
3257 GtkWidget *path;
3258 gint x, y;
3260 Settings *set=settings_new(fwin->sym_path);
3262 gtk_window_get_position(GTK_WINDOW(fwin->window),&x, &y);
3263 set->flags|=SET_POSITION;
3264 set->x=x;
3265 set->y=y;
3267 gtk_window_get_size(GTK_WINDOW(fwin->window),&x, &y);
3268 set->flags|=SET_SIZE;
3269 set->width=x;
3270 set->height=y;
3272 set->flags|=SET_HIDDEN;
3273 set->show_hidden=fwin->show_hidden;
3275 set->flags|=SET_STYLE;
3276 set->display_style=fwin->display_style;
3278 set->flags|=SET_SORT;
3279 set->sort_type=fwin->sort_type;
3280 set->sort_order=fwin->sort_order;
3282 set->flags|=SET_DETAILS;
3283 set->view_type=fwin->view_type;
3284 set->details_type=fwin->details_type;
3286 set->flags|=SET_THUMBS;
3287 set->show_thumbs=fwin->show_thumbs;
3289 set->flags|=SET_FILTER;
3290 set->filter_type=fwin->filter;
3291 if(fwin->filter_string)
3292 set->filter=g_strdup(fwin->filter_string);
3294 /* Store other parameters
3296 set_win=g_new(SettingsWindow, 1);
3298 set_win->window=gtk_dialog_new();
3299 number_of_windows++;
3301 gtk_dialog_add_button(GTK_DIALOG(set_win->window),
3302 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
3303 gtk_dialog_add_button(GTK_DIALOG(set_win->window),
3304 GTK_STOCK_OK, GTK_RESPONSE_OK);
3306 g_signal_connect(set_win->window, "destroy",
3307 G_CALLBACK(one_less_window), NULL);
3308 g_signal_connect_swapped(set_win->window, "destroy",
3309 G_CALLBACK(g_free), set_win);
3311 gtk_window_set_title(GTK_WINDOW(set_win->window),
3312 _("Select display properties to save"));
3314 vbox=GTK_DIALOG(set_win->window)->vbox;
3316 path=gtk_label_new(set->path);
3317 gtk_box_pack_start(GTK_BOX(vbox), path, FALSE, FALSE, 2);
3319 set_win->pos=gtk_check_button_new_with_label(_("Position"));
3320 gtk_box_pack_start(GTK_BOX(vbox), set_win->pos, FALSE, FALSE, 2);
3321 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(set_win->pos),
3322 set->flags & SET_POSITION);
3324 set_win->size=gtk_check_button_new_with_label(_("Size"));
3325 gtk_box_pack_start(GTK_BOX(vbox), set_win->size, FALSE, FALSE, 2);
3326 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(set_win->size),
3327 set->flags & SET_SIZE);
3329 set_win->hidden=gtk_check_button_new_with_label(_("Show hidden"));
3330 gtk_box_pack_start(GTK_BOX(vbox), set_win->hidden,
3331 FALSE, FALSE, 2);
3332 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(set_win->hidden),
3333 set->flags & SET_HIDDEN);
3335 set_win->style=gtk_check_button_new_with_label(_("Display style"));
3336 gtk_box_pack_start(GTK_BOX(vbox), set_win->style,
3337 FALSE, FALSE, 2);
3338 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(set_win->style),
3339 set->flags & SET_STYLE);
3341 set_win->sort=gtk_check_button_new_with_label(_("Sort type and order"));
3342 gtk_box_pack_start(GTK_BOX(vbox), set_win->sort, FALSE, FALSE, 2);
3343 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(set_win->sort),
3344 set->flags & SET_SORT);
3346 set_win->details=gtk_check_button_new_with_label(_("Details"));
3347 gtk_box_pack_start(GTK_BOX(vbox), set_win->details, FALSE, FALSE, 2);
3348 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(set_win->details),
3349 set->flags & SET_DETAILS);
3351 set_win->thumbs=gtk_check_button_new_with_label(_("Thumbnails"));
3352 gtk_box_pack_start(GTK_BOX(vbox), set_win->thumbs,
3353 FALSE, FALSE, 2);
3354 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(set_win->thumbs),
3355 set->flags & SET_THUMBS);
3357 set_win->filter=gtk_check_button_new_with_label(_("Filter"));
3358 gtk_box_pack_start(GTK_BOX(vbox), set_win->filter,
3359 FALSE, FALSE, 2);
3360 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(set_win->filter),
3361 set->flags & SET_FILTER);
3363 set_win->set=set;
3364 g_signal_connect(set_win->window, "response",
3365 G_CALLBACK(settings_response), set_win);
3367 gtk_widget_show_all(set_win->window);