r4009: Copied xdgmime library into the filer, so we don't need gnomevfs just
[rox-filer/translations.git] / ROX-Filer / src / filer.c
blobe316e1f41d285cfb9cbe0de659281a4aa0c69690
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_xdg_path_load("Groups.xml", PROJECT, SITE);
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_xdg_path_save("Groups.xml", PROJECT, SITE,
994 TRUE);
995 if (save_path)
997 save_xml_file(groups->doc, save_path);
998 g_free(save_path);
1002 static gboolean group_restore_cb(ViewIter *iter, gpointer data)
1004 GHashTable *in_group = (GHashTable *) data;
1006 return g_hash_table_lookup(in_group,
1007 iter->peek(iter)->leafname) != NULL;
1010 static void group_restore(FilerWindow *filer_window, char *name)
1012 GHashTable *in_group;
1013 char *path;
1014 xmlNode *group, *node;
1016 group = group_find(name);
1018 if (!group)
1020 report_error(_("Group %s is not set. Select some files "
1021 "and press Ctrl+%s to set the group. Press %s "
1022 "on its own to reselect the files later.\n"
1023 "Make sure NumLock is on if you use the keypad."),
1024 name, name, name);
1025 return;
1028 node = get_subnode(group, NULL, "directory");
1029 g_return_if_fail(node != NULL);
1030 path = xmlNodeListGetString(groups->doc, node->xmlChildrenNode, 1);
1031 g_return_if_fail(path != NULL);
1033 if (strcmp(path, filer_window->sym_path) != 0)
1034 filer_change_to(filer_window, path, NULL);
1035 g_free(path);
1037 in_group = g_hash_table_new(g_str_hash, g_str_equal);
1038 for (node = group->xmlChildrenNode; node; node = node->next)
1040 gchar *leaf;
1041 if (node->type != XML_ELEMENT_NODE)
1042 continue;
1043 if (strcmp(node->name, "item") != 0)
1044 continue;
1046 leaf = xmlNodeListGetString(groups->doc,
1047 node->xmlChildrenNode, 1);
1048 if (!leaf)
1049 g_warning("Missing leafname!\n");
1050 else
1051 g_hash_table_insert(in_group, leaf, filer_window);
1054 view_select_if(filer_window->view, &group_restore_cb, in_group);
1056 g_hash_table_foreach(in_group, (GHFunc) g_free, NULL);
1057 g_hash_table_destroy(in_group);
1060 static gboolean popup_menu(GtkWidget *widget, FilerWindow *filer_window)
1062 ViewIter iter;
1064 view_get_cursor(filer_window->view, &iter);
1066 show_filer_menu(filer_window, NULL, &iter);
1068 return TRUE;
1071 void filer_window_toggle_cursor_item_selected(FilerWindow *filer_window)
1073 ViewIface *view = filer_window->view;
1074 ViewIter iter;
1076 view_get_iter(view, &iter, VIEW_ITER_FROM_CURSOR);
1077 if (!iter.next(&iter))
1078 return; /* No cursor */
1080 if (view_get_selected(view, &iter))
1081 view_set_selected(view, &iter, FALSE);
1082 else
1083 view_set_selected(view, &iter, TRUE);
1085 if (iter.next(&iter))
1086 view_cursor_to_iter(view, &iter);
1089 gint filer_key_press_event(GtkWidget *widget,
1090 GdkEventKey *event,
1091 FilerWindow *filer_window)
1093 ViewIface *view = filer_window->view;
1094 ViewIter cursor;
1095 GtkWidget *focus = GTK_WINDOW(widget)->focus_widget;
1096 guint key = event->keyval;
1097 char group[2] = "1";
1099 window_with_focus = filer_window;
1101 /* Delay setting up the keys until now to speed loading... */
1102 if (ensure_filer_menu())
1104 /* Gtk updates in an idle-handler, so force a recheck now */
1105 g_signal_emit_by_name(widget, "keys_changed");
1108 if (focus && focus == filer_window->minibuffer)
1109 if (gtk_widget_event(focus, (GdkEvent *) event))
1110 return TRUE; /* Handled */
1112 if (!focus)
1113 gtk_widget_grab_focus(GTK_WIDGET(view));
1115 view_get_cursor(view, &cursor);
1116 if (!cursor.peek(&cursor) && (key == GDK_Up || key == GDK_Down))
1118 ViewIter iter;
1119 view_get_iter(view, &iter, 0);
1120 if (iter.next(&iter))
1121 view_cursor_to_iter(view, &iter);
1122 gtk_widget_grab_focus(GTK_WIDGET(view)); /* Needed? */
1123 return TRUE;
1126 switch (key)
1128 case GDK_Escape:
1129 filer_target_mode(filer_window, NULL, NULL, NULL);
1130 view_cursor_to_iter(filer_window->view, NULL);
1131 view_clear_selection(filer_window->view);
1132 return FALSE;
1133 case GDK_Return:
1134 return_pressed(filer_window, event);
1135 break;
1136 case GDK_ISO_Left_Tab:
1137 filer_next_selected(filer_window, -1);
1138 break;
1139 case GDK_Tab:
1140 filer_next_selected(filer_window, 1);
1141 break;
1142 case GDK_BackSpace:
1143 change_to_parent(filer_window);
1144 break;
1145 case GDK_backslash:
1147 ViewIter iter;
1149 tooltip_show(NULL);
1151 view_get_cursor(filer_window->view, &iter);
1152 show_filer_menu(filer_window,
1153 (GdkEvent *) event, &iter);
1154 break;
1156 case ' ':
1157 filer_window_toggle_cursor_item_selected(filer_window);
1158 break;
1159 default:
1160 if (key >= GDK_0 && key <= GDK_9)
1161 group[0] = key - GDK_0 + '0';
1162 else if (key >= GDK_KP_0 && key <= GDK_KP_9)
1163 group[0] = key - GDK_KP_0 + '0';
1164 else
1166 if (focus && focus != widget &&
1167 gtk_widget_get_toplevel(focus) == widget)
1168 if (gtk_widget_event(focus,
1169 (GdkEvent *) event))
1170 return TRUE; /* Handled */
1171 return FALSE;
1174 if (event->state & GDK_CONTROL_MASK)
1175 group_save(filer_window, group);
1176 else
1177 group_restore(filer_window, group);
1180 return TRUE;
1183 void filer_open_parent(FilerWindow *filer_window)
1185 char *dir;
1186 const char *current = filer_window->sym_path;
1188 if (current[0] == '/' && current[1] == '\0')
1189 return; /* Already in the root */
1191 dir = g_path_get_dirname(current);
1192 filer_opendir(dir, filer_window, NULL);
1193 g_free(dir);
1196 void change_to_parent(FilerWindow *filer_window)
1198 char *dir;
1199 const char *current = filer_window->sym_path;
1201 if (current[0] == '/' && current[1] == '\0')
1202 return; /* Already in the root */
1204 if (mount_is_user_mounted(filer_window->real_path))
1205 may_offer_unmount(filer_window,
1206 g_strdup(filer_window->real_path));
1208 dir = g_path_get_dirname(current);
1209 filer_change_to(filer_window, dir, g_basename(current));
1210 g_free(dir);
1213 /* Removes trailing /s from path (modified in place) */
1214 static void tidy_sympath(gchar *path)
1216 int l;
1218 g_return_if_fail(path != NULL);
1220 l = strlen(path);
1221 while (l > 1 && path[l - 1] == '/')
1223 l--;
1224 path[l] = '\0';
1228 /* Make filer_window display path. When finished, highlight item 'from', or
1229 * the first item if from is NULL. If there is currently no cursor then
1230 * simply wink 'from' (if not NULL).
1231 * If the cause was a key event and we resize, warp the pointer.
1233 void filer_change_to(FilerWindow *filer_window,
1234 const char *path, const char *from)
1236 char *from_dup;
1237 char *sym_path, *real_path;
1238 Directory *new_dir;
1240 g_return_if_fail(filer_window != NULL);
1242 filer_cancel_thumbnails(filer_window);
1244 tooltip_show(NULL);
1246 sym_path = g_strdup(path);
1247 real_path = pathdup(path);
1248 new_dir = g_fscache_lookup(dir_cache, real_path);
1250 if (!new_dir)
1252 delayed_error(_("Directory '%s' is not accessible"),
1253 sym_path);
1254 g_free(real_path);
1255 g_free(sym_path);
1256 return;
1259 if (o_unique_filer_windows.int_value && !spring_in_progress)
1261 FilerWindow *fw;
1263 fw = find_filer_window(sym_path, filer_window);
1264 if (fw)
1265 gtk_widget_destroy(fw->window);
1268 from_dup = from && *from ? g_strdup(from) : NULL;
1270 detach(filer_window);
1271 g_free(filer_window->real_path);
1272 g_free(filer_window->sym_path);
1273 filer_window->real_path = real_path;
1274 filer_window->sym_path = sym_path;
1275 tidy_sympath(filer_window->sym_path);
1277 filer_window->directory = new_dir;
1279 g_free(filer_window->auto_select);
1280 filer_window->auto_select = from_dup;
1282 filer_window->had_cursor = filer_window->had_cursor ||
1283 view_cursor_visible(filer_window->view);
1285 filer_set_title(filer_window);
1286 if (filer_window->window->window)
1287 gdk_window_set_role(filer_window->window->window,
1288 filer_window->sym_path);
1289 view_cursor_to_iter(filer_window->view, NULL);
1291 attach(filer_window);
1293 check_settings(filer_window);
1295 display_set_actual_size(filer_window, FALSE);
1297 if (o_filer_auto_resize.int_value == RESIZE_ALWAYS)
1298 view_autosize(filer_window->view);
1300 if (filer_window->mini_type == MINI_PATH)
1301 g_idle_add((GSourceFunc) minibuffer_show_cb, filer_window);
1304 /* Returns a list containing the full (sym) pathname of every selected item.
1305 * You must g_free() each item in the list.
1307 GList *filer_selected_items(FilerWindow *filer_window)
1309 GList *retval = NULL;
1310 guchar *dir = filer_window->sym_path;
1311 ViewIter iter;
1312 DirItem *item;
1314 view_get_iter(filer_window->view, &iter, VIEW_ITER_SELECTED);
1315 while ((item = iter.next(&iter)))
1317 retval = g_list_prepend(retval,
1318 g_strdup(make_path(dir, item->leafname)));
1321 return g_list_reverse(retval);
1324 /* Return the single selected item. Error if nothing is selected. */
1325 DirItem *filer_selected_item(FilerWindow *filer_window)
1327 ViewIter iter;
1328 DirItem *item;
1330 view_get_iter(filer_window->view, &iter, VIEW_ITER_SELECTED);
1332 item = iter.next(&iter);
1333 g_return_val_if_fail(item != NULL, NULL);
1334 g_return_val_if_fail(iter.next(&iter) == NULL, NULL);
1336 return item;
1339 /* Creates and shows a new filer window.
1340 * If src_win != NULL then display options can be taken from that source window.
1341 * Returns the new filer window, or NULL on error.
1342 * Note: if unique windows is in use, may return an existing window.
1344 FilerWindow *filer_opendir(const char *path, FilerWindow *src_win,
1345 const gchar *wm_class)
1347 FilerWindow *filer_window;
1348 char *real_path;
1349 DisplayStyle dstyle;
1350 DetailsType dtype;
1351 SortType s_type;
1352 GtkSortType s_order;
1353 Settings *dir_settings = NULL;
1354 gboolean force_resize = TRUE;
1356 /* Get the real pathname of the directory and copy it */
1357 real_path = pathdup(path);
1359 if (o_unique_filer_windows.int_value && !spring_in_progress)
1361 FilerWindow *same_dir_window;
1363 same_dir_window = find_filer_window(path, NULL);
1365 if (same_dir_window)
1367 gtk_window_present(GTK_WINDOW(same_dir_window->window));
1368 return same_dir_window;
1372 filer_window = g_new(FilerWindow, 1);
1373 filer_window->message = NULL;
1374 filer_window->minibuffer = NULL;
1375 filer_window->minibuffer_label = NULL;
1376 filer_window->minibuffer_area = NULL;
1377 filer_window->temp_show_hidden = FALSE;
1378 filer_window->sym_path = g_strdup(path);
1379 filer_window->real_path = real_path;
1380 filer_window->scanning = FALSE;
1381 filer_window->had_cursor = FALSE;
1382 filer_window->auto_select = NULL;
1383 filer_window->toolbar_text = NULL;
1384 filer_window->target_cb = NULL;
1385 filer_window->mini_type = MINI_NONE;
1386 filer_window->selection_state = GTK_STATE_INSENSITIVE;
1387 filer_window->toolbar = NULL;
1388 filer_window->toplevel_vbox = NULL;
1389 filer_window->view_hbox = NULL;
1390 filer_window->view = NULL;
1391 filer_window->scrollbar = NULL;
1392 filer_window->auto_scroll = -1;
1393 filer_window->window_id = NULL;
1395 tidy_sympath(filer_window->sym_path);
1397 /* Finds the entry for this directory in the dir cache, creating
1398 * a new one if needed. This does not cause a scan to start,
1399 * so if a new entry is created then it will be empty.
1401 filer_window->directory = g_fscache_lookup(dir_cache, real_path);
1402 if (!filer_window->directory)
1404 delayed_error(_("Directory '%s' not found."), path);
1405 g_free(filer_window->real_path);
1406 g_free(filer_window->sym_path);
1407 g_free(filer_window);
1408 return NULL;
1411 filer_window->temp_item_selected = FALSE;
1412 filer_window->flags = (FilerFlags) 0;
1413 filer_window->details_type = DETAILS_TIMES;
1414 filer_window->display_style = UNKNOWN_STYLE;
1415 filer_window->display_style_wanted = UNKNOWN_STYLE;
1416 filer_window->thumb_queue = NULL;
1417 filer_window->max_thumbs = 0;
1418 filer_window->sort_type = -1;
1420 filer_window->filter = FILER_SHOW_ALL;
1421 filer_window->filter_string = NULL;
1422 filer_window->regexp = NULL;
1424 if (src_win && o_display_inherit_options.int_value)
1426 s_type = src_win->sort_type;
1427 s_order = src_win->sort_order;
1428 dstyle = src_win->display_style_wanted;
1429 dtype = src_win->details_type;
1430 filer_window->show_hidden = src_win->show_hidden;
1431 filer_window->show_thumbs = src_win->show_thumbs;
1432 filer_window->view_type = src_win->view_type;
1434 filer_set_filter(filer_window, src_win->filter,
1435 src_win->filter_string);
1437 else
1439 s_type = o_display_sort_by.int_value;
1440 s_order = GTK_SORT_ASCENDING;
1441 dstyle = o_display_size.int_value;
1442 dtype = o_display_details.int_value;
1443 filer_window->show_hidden = o_display_show_hidden.int_value;
1444 filer_window->show_thumbs = o_display_show_thumbs.int_value;
1445 filer_window->view_type = o_filer_view_type.int_value;
1448 dir_settings = (Settings *) g_hash_table_lookup(settings_table,
1449 filer_window->sym_path);
1450 if (dir_settings)
1452 /* Override the current defaults with the per-directory
1453 * user settings.
1455 if (dir_settings->flags & SET_HIDDEN)
1456 filer_window->show_hidden = dir_settings->show_hidden;
1458 if (dir_settings->flags & SET_STYLE)
1459 dstyle = dir_settings->display_style;
1461 if (dir_settings->flags & SET_DETAILS)
1463 dtype = dir_settings->details_type;
1464 filer_window->view_type = dir_settings->view_type;
1467 if (dir_settings->flags & SET_SORT)
1469 s_type = dir_settings->sort_type;
1470 s_order = dir_settings->sort_order;
1473 if (dir_settings->flags & SET_THUMBS)
1474 filer_window->show_thumbs = dir_settings->show_thumbs;
1476 if (dir_settings->flags & SET_FILTER)
1477 filer_set_filter(filer_window,
1478 dir_settings->filter_type,
1479 dir_settings->filter);
1482 /* Add all the user-interface elements & realise */
1483 filer_add_widgets(filer_window, wm_class);
1484 if (src_win)
1485 gtk_window_set_position(GTK_WINDOW(filer_window->window),
1486 GTK_WIN_POS_MOUSE);
1488 if (dir_settings)
1490 if (dir_settings->flags & SET_POSITION)
1492 gtk_window_move(GTK_WINDOW(filer_window->window),
1493 dir_settings->x, dir_settings->y);
1495 if (dir_settings->flags & SET_SIZE)
1497 filer_window_set_size(filer_window,
1498 dir_settings->width,
1499 dir_settings->height);
1500 force_resize = o_filer_auto_resize.int_value != RESIZE_NEVER;
1504 /* Connect to all the signal handlers */
1505 filer_add_signals(filer_window);
1507 display_set_layout(filer_window, dstyle, dtype, force_resize);
1508 display_set_sort_type(filer_window, s_type, s_order);
1510 /* Open the window after a timeout, or when scanning stops.
1511 * Do this before attaching, because attach() might tell us to
1512 * stop scanning (if a scan isn't needed).
1514 filer_window->open_timeout = g_timeout_add(500,
1515 (GSourceFunc) open_filer_window,
1516 filer_window);
1518 /* The view is created empty and then attach() is called, which
1519 * links the filer window to the entry in the directory cache we
1520 * looked up / created above.
1522 * The attach() function will immediately callback to the filer window
1523 * to deliver a list of all known entries in the directory (so,
1524 * the number of items will be known after attach() returns).
1526 * If the directory was not in the cache (because it hadn't been
1527 * opened it before) then the types and icons for the entries are
1528 * not know, but the list of names is.
1531 attach(filer_window);
1533 number_of_windows++;
1534 all_filer_windows = g_list_prepend(all_filer_windows, filer_window);
1536 return filer_window;
1539 void filer_set_view_type(FilerWindow *filer_window, ViewType type)
1541 GtkWidget *view = NULL;
1542 Directory *dir = NULL;
1543 GHashTable *selected = NULL;
1545 g_return_if_fail(filer_window != NULL);
1547 motion_window = NULL;
1549 if (filer_window->view)
1551 /* Save the current selection */
1552 ViewIter iter;
1553 DirItem *item;
1555 selected = g_hash_table_new(g_str_hash, g_str_equal);
1556 view_get_iter(filer_window->view, &iter, VIEW_ITER_SELECTED);
1557 while ((item = iter.next(&iter)))
1558 g_hash_table_insert(selected, item->leafname, "yes");
1560 /* Destroy the old view */
1561 gtk_widget_destroy(GTK_WIDGET(filer_window->view));
1562 filer_window->view = NULL;
1564 dir = filer_window->directory;
1565 g_object_ref(dir);
1566 detach(filer_window);
1569 switch (type)
1571 case VIEW_TYPE_COLLECTION:
1572 view = view_collection_new(filer_window);
1573 break;
1574 case VIEW_TYPE_DETAILS:
1575 view = view_details_new(filer_window);
1576 break;
1579 g_return_if_fail(view != NULL);
1581 filer_window->view = VIEW(view);
1582 filer_window->view_type = type;
1584 gtk_box_pack_start(filer_window->view_hbox, view, TRUE, TRUE, 0);
1585 gtk_widget_show(view);
1587 /* Drag and drop events */
1588 make_drop_target(view, 0);
1589 g_signal_connect(view, "drag_motion",
1590 G_CALLBACK(drag_motion), filer_window);
1591 g_signal_connect(view, "drag_leave",
1592 G_CALLBACK(drag_leave), filer_window);
1593 g_signal_connect(view, "drag_end",
1594 G_CALLBACK(drag_end), filer_window);
1595 /* Dragging from us... */
1596 g_signal_connect(view, "drag_data_get",
1597 GTK_SIGNAL_FUNC(drag_data_get), NULL);
1599 if (dir)
1601 /* Only when changing type. Otherwise, will attach later. */
1602 filer_window->directory = dir;
1603 attach(filer_window);
1605 if (o_filer_auto_resize.int_value != RESIZE_NEVER)
1606 view_autosize(filer_window->view);
1609 if (selected)
1611 ViewIter iter;
1612 DirItem *item;
1614 view_get_iter(filer_window->view, &iter, 0);
1615 while ((item = iter.next(&iter)))
1617 if (g_hash_table_lookup(selected, item->leafname))
1618 view_set_selected(filer_window->view,
1619 &iter, TRUE);
1621 g_hash_table_destroy(selected);
1625 /* This adds all the widgets to a new filer window. It is in a separate
1626 * function because filer_opendir() was getting too long...
1628 static void filer_add_widgets(FilerWindow *filer_window, const gchar *wm_class)
1630 GtkWidget *hbox, *vbox;
1632 /* Create the top-level window widget */
1633 filer_window->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1634 filer_set_title(filer_window);
1635 gtk_widget_set_name(filer_window->window, "rox-filer");
1637 if (wm_class)
1638 gtk_window_set_wmclass(GTK_WINDOW(filer_window->window),
1639 wm_class, PROJECT);
1641 /* This property is cleared when the window is destroyed.
1642 * You can thus ref filer_window->window and use this to see
1643 * if the window no longer exists.
1645 g_object_set_data(G_OBJECT(filer_window->window),
1646 "filer_window", filer_window);
1648 /* Create this now to make the Adjustment before the View */
1649 filer_window->scrollbar = gtk_vscrollbar_new(NULL);
1651 vbox = gtk_vbox_new(FALSE, 0);
1652 gtk_container_add(GTK_CONTAINER(filer_window->window), vbox);
1654 filer_window->toplevel_vbox = GTK_BOX(vbox);
1656 /* If there's a message that should be displayed in each window (eg
1657 * 'Running as root'), add it here.
1659 if (show_user_message)
1661 filer_window->message = gtk_label_new(show_user_message);
1662 gtk_box_pack_start(GTK_BOX(vbox), filer_window->message,
1663 FALSE, TRUE, 0);
1664 gtk_widget_show(filer_window->message);
1667 hbox = gtk_hbox_new(FALSE, 0);
1668 filer_window->view_hbox = GTK_BOX(hbox);
1669 gtk_box_pack_start_defaults(GTK_BOX(vbox), hbox);
1670 /* Add the main View widget */
1671 filer_set_view_type(filer_window, filer_window->view_type);
1672 /* Put the scrollbar next to the View */
1673 gtk_box_pack_end(GTK_BOX(hbox),
1674 filer_window->scrollbar, FALSE, TRUE, 0);
1675 gtk_widget_show(hbox);
1677 /* If we want a toolbar, create it now */
1678 toolbar_update_toolbar(filer_window);
1680 /* And the minibuffer (hidden to start with) */
1681 create_minibuffer(filer_window);
1682 gtk_box_pack_end(GTK_BOX(vbox), filer_window->minibuffer_area,
1683 FALSE, TRUE, 0);
1685 /* And the thumbnail progress bar (also hidden) */
1687 GtkWidget *cancel;
1689 filer_window->thumb_bar = gtk_hbox_new(FALSE, 2);
1690 gtk_box_pack_end(GTK_BOX(vbox), filer_window->thumb_bar,
1691 FALSE, TRUE, 0);
1693 filer_window->thumb_progress = gtk_progress_bar_new();
1695 gtk_box_pack_start(GTK_BOX(filer_window->thumb_bar),
1696 filer_window->thumb_progress, TRUE, TRUE, 0);
1698 cancel = gtk_button_new_with_label(_("Cancel"));
1699 GTK_WIDGET_UNSET_FLAGS(cancel, GTK_CAN_FOCUS);
1700 gtk_box_pack_start(GTK_BOX(filer_window->thumb_bar),
1701 cancel, FALSE, TRUE, 0);
1702 g_signal_connect_swapped(cancel, "clicked",
1703 G_CALLBACK(filer_cancel_thumbnails),
1704 filer_window);
1707 gtk_widget_show(vbox);
1708 gtk_widget_show(filer_window->scrollbar);
1710 gtk_widget_realize(filer_window->window);
1712 gdk_window_set_role(filer_window->window->window,
1713 filer_window->sym_path);
1715 filer_window_set_size(filer_window, 4, 4);
1718 static void filer_add_signals(FilerWindow *filer_window)
1720 GtkTargetEntry target_table[] =
1722 {"text/uri-list", 0, TARGET_URI_LIST},
1723 {"UTF8_STRING", 0, TARGET_STRING},
1724 {"STRING", 0, TARGET_STRING},
1725 {"COMPOUND_TEXT", 0, TARGET_STRING},/* XXX: Treats as STRING */
1728 /* Events on the top-level window */
1729 gtk_widget_add_events(filer_window->window, GDK_ENTER_NOTIFY);
1730 g_signal_connect(filer_window->window, "enter-notify-event",
1731 G_CALLBACK(pointer_in), filer_window);
1732 g_signal_connect(filer_window->window, "leave-notify-event",
1733 G_CALLBACK(pointer_out), filer_window);
1734 g_signal_connect(filer_window->window, "destroy",
1735 G_CALLBACK(filer_window_destroyed), filer_window);
1736 g_signal_connect(filer_window->window, "delete-event",
1737 G_CALLBACK(filer_window_delete), filer_window);
1739 g_signal_connect(filer_window->window, "selection_clear_event",
1740 G_CALLBACK(filer_lost_primary), filer_window);
1742 g_signal_connect(filer_window->window, "selection_get",
1743 G_CALLBACK(selection_get), filer_window);
1744 gtk_selection_add_targets(GTK_WIDGET(filer_window->window),
1745 GDK_SELECTION_PRIMARY,
1746 target_table,
1747 sizeof(target_table) / sizeof(*target_table));
1749 g_signal_connect(filer_window->window, "popup-menu",
1750 G_CALLBACK(popup_menu), filer_window);
1751 g_signal_connect(filer_window->window, "key_press_event",
1752 G_CALLBACK(filer_key_press_event), filer_window);
1754 gtk_window_add_accel_group(GTK_WINDOW(filer_window->window),
1755 filer_keys);
1758 static gint clear_scanning_display(FilerWindow *filer_window)
1760 if (filer_exists(filer_window))
1761 filer_set_title(filer_window);
1762 return FALSE;
1765 static void set_scanning_display(FilerWindow *filer_window, gboolean scanning)
1767 if (scanning == filer_window->scanning)
1768 return;
1769 filer_window->scanning = scanning;
1771 if (scanning)
1772 filer_set_title(filer_window);
1773 else
1774 g_timeout_add(300, (GSourceFunc) clear_scanning_display,
1775 filer_window);
1778 /* Note that filer_window may not exist after this call.
1779 * Returns TRUE iff the directory still exists.
1781 gboolean filer_update_dir(FilerWindow *filer_window, gboolean warning)
1783 gboolean still_exists;
1785 still_exists = may_rescan(filer_window, warning);
1787 if (still_exists)
1788 dir_update(filer_window->directory, filer_window->sym_path);
1790 return still_exists;
1793 void filer_update_all(void)
1795 GList *next = all_filer_windows;
1797 while (next)
1799 FilerWindow *filer_window = (FilerWindow *) next->data;
1801 /* Updating directory may remove it from list -- stop sending
1802 * patches to move this line!
1804 next = next->next;
1806 /* Don't trigger a refresh if we're already scanning.
1807 * Otherwise, two views of a single directory will trigger
1808 * two scans.
1810 if (filer_window->directory &&
1811 !filer_window->directory->scanning)
1812 filer_update_dir(filer_window, TRUE);
1816 /* Refresh the various caches even if we don't think we need to */
1817 void full_refresh(void)
1819 mount_update(TRUE);
1820 reread_mime_files(); /* Refreshes all windows */
1823 /* See whether a filer window with a given path already exists
1824 * and is different from diff.
1826 static FilerWindow *find_filer_window(const char *sym_path, FilerWindow *diff)
1828 GList *next;
1830 for (next = all_filer_windows; next; next = next->next)
1832 FilerWindow *filer_window = (FilerWindow *) next->data;
1834 if (filer_window != diff &&
1835 strcmp(sym_path, filer_window->sym_path) == 0)
1836 return filer_window;
1839 return NULL;
1842 /* This path has been mounted/umounted/deleted some files - update all dirs */
1843 void filer_check_mounted(const char *real_path)
1845 GList *next = all_filer_windows;
1846 gchar *parent;
1847 int len;
1848 gboolean resize = o_filer_auto_resize.int_value == RESIZE_ALWAYS;
1850 /* DOS disks, etc, often don't change the mtime of the root directory
1851 * on modification, so force a refresh now.
1853 g_fscache_update(dir_cache, real_path);
1855 len = strlen(real_path);
1857 while (next)
1859 FilerWindow *filer_window = (FilerWindow *) next->data;
1861 next = next->next;
1863 if (strncmp(real_path, filer_window->real_path, len) == 0)
1865 char s = filer_window->real_path[len];
1867 if (s == '/' || s == '\0')
1869 if (filer_update_dir(filer_window, FALSE) &&
1870 resize)
1871 view_autosize(filer_window->view);
1876 parent = g_path_get_dirname(real_path);
1877 refresh_dirs(parent);
1878 g_free(parent);
1880 icons_may_update(real_path);
1883 /* Close all windows displaying 'path' or subdirectories of 'path' */
1884 void filer_close_recursive(const char *path)
1886 GList *next = all_filer_windows;
1887 gchar *real;
1888 int len;
1890 real = pathdup(path);
1891 len = strlen(real);
1893 while (next)
1895 FilerWindow *filer_window = (FilerWindow *) next->data;
1897 next = next->next;
1899 if (strncmp(real, filer_window->real_path, len) == 0)
1901 char s = filer_window->real_path[len];
1903 if (len == 1 || s == '/' || s == '\0')
1904 gtk_widget_destroy(filer_window->window);
1909 /* Like minibuffer_show(), except that:
1910 * - It returns FALSE (to be used from an idle callback)
1911 * - It checks that the filer window still exists.
1913 static gboolean minibuffer_show_cb(FilerWindow *filer_window)
1915 if (filer_exists(filer_window))
1916 minibuffer_show(filer_window, MINI_PATH);
1917 return FALSE;
1920 /* TRUE iff filer_window points to an existing FilerWindow
1921 * structure.
1923 gboolean filer_exists(FilerWindow *filer_window)
1925 GList *next;
1927 for (next = all_filer_windows; next; next = next->next)
1929 FilerWindow *fw = (FilerWindow *) next->data;
1931 if (fw == filer_window)
1932 return TRUE;
1935 return FALSE;
1938 FilerWindow *filer_get_by_id(const char *id)
1940 return g_hash_table_lookup(window_with_id, id);
1943 void filer_set_id(FilerWindow *filer_window, const char *id)
1945 g_return_if_fail(filer_window != NULL);
1947 if (filer_window->window_id)
1949 g_hash_table_remove(window_with_id, filer_window->window_id);
1950 g_free(filer_window->window_id);
1951 filer_window->window_id = NULL;
1954 if (id)
1956 filer_window->window_id = g_strdup(id);
1957 g_hash_table_insert(window_with_id,
1958 filer_window->window_id,
1959 filer_window);
1963 /* Make sure the window title is up-to-date */
1964 void filer_set_title(FilerWindow *filer_window)
1966 gchar *title = NULL;
1967 guchar *flags = "";
1968 gchar *hidden = "";
1970 if (filer_window->scanning ||
1971 filer_window->filter != FILER_SHOW_ALL ||
1972 filer_window->show_hidden || filer_window->show_thumbs)
1974 if (o_short_flag_names.int_value)
1977 switch(filer_window->filter) {
1978 case FILER_SHOW_ALL:
1979 hidden=filer_window->show_hidden? "A": "";
1980 break;
1981 case FILER_SHOW_GLOB: hidden="G"; break;
1982 case FILER_SHOW_REGEXP: hidden="R"; break;
1983 default: break;
1986 flags = g_strconcat(" +",
1987 filer_window->scanning ? _("S") : "",
1988 hidden,
1989 filer_window->show_thumbs ? _("T") : "",
1990 NULL);
1992 else
1994 switch(filer_window->filter) {
1995 case FILER_SHOW_ALL:
1996 hidden=g_strdup(filer_window->show_hidden? "All, ": "");
1997 break;
1998 case FILER_SHOW_GLOB:
1999 hidden=g_strdup_printf("Glob (%s), ",
2000 filer_window->filter_string);
2001 break;
2002 case FILER_SHOW_REGEXP:
2003 hidden=g_strdup_printf("Regexp (%s), ",
2004 filer_window->filter_string);
2005 break;
2006 default:
2007 hidden=g_strdup("");
2008 break;
2010 flags = g_strconcat(" (",
2011 filer_window->scanning ? _("Scanning, ") : "",
2012 hidden,
2013 filer_window->show_thumbs ? _("Thumbs, ") : "",
2014 NULL);
2015 flags[strlen(flags) - 2] = ')';
2016 g_free(hidden);
2020 if (not_local)
2021 title = g_strconcat("//", our_host_name(),
2022 filer_window->sym_path, flags, NULL);
2024 if (!title && home_dir_len > 1 &&
2025 strncmp(filer_window->sym_path, home_dir, home_dir_len) == 0)
2027 guchar sep = filer_window->sym_path[home_dir_len];
2029 if (sep == '\0' || sep == '/')
2030 title = g_strconcat("~",
2031 filer_window->sym_path + home_dir_len,
2032 flags,
2033 NULL);
2036 if (!title)
2037 title = g_strconcat(filer_window->sym_path, flags, NULL);
2039 ensure_utf8(&title);
2041 if (filer_window->directory->error)
2043 gchar *old = title;
2044 title = g_strconcat(old, ": ", filer_window->directory->error,
2045 NULL);
2046 g_free(old);
2049 gtk_window_set_title(GTK_WINDOW(filer_window->window), title);
2051 g_free(title);
2053 if (flags[0] != '\0')
2054 g_free(flags);
2057 /* Reconnect to the same directory (used when the Show Hidden option is
2058 * toggled). This has the side-effect of updating the window title.
2060 void filer_detach_rescan(FilerWindow *filer_window)
2062 Directory *dir = filer_window->directory;
2064 g_object_ref(dir);
2065 detach(filer_window);
2066 filer_window->directory = dir;
2067 attach(filer_window);
2070 /* Puts the filer window into target mode. When an item is chosen,
2071 * fn(filer_window, iter, data) is called. 'reason' will be displayed
2072 * on the toolbar while target mode is active.
2074 * Use fn == NULL to cancel target mode.
2076 void filer_target_mode(FilerWindow *filer_window,
2077 TargetFunc fn,
2078 gpointer data,
2079 const char *reason)
2081 TargetFunc old_fn = filer_window->target_cb;
2083 if (fn != old_fn)
2084 gdk_window_set_cursor(
2085 GTK_WIDGET(filer_window->view)->window,
2086 fn ? crosshair : NULL);
2088 filer_window->target_cb = fn;
2089 filer_window->target_data = data;
2091 if (filer_window->toolbar_text == NULL)
2092 return;
2094 if (fn)
2095 gtk_label_set_text(
2096 GTK_LABEL(filer_window->toolbar_text), reason);
2097 else if (o_toolbar_info.int_value)
2099 if (old_fn)
2100 toolbar_update_info(filer_window);
2102 else
2103 gtk_label_set_text(GTK_LABEL(filer_window->toolbar_text), "");
2106 static void set_selection_state(FilerWindow *filer_window, gboolean normal)
2108 GtkStateType old_state = filer_window->selection_state;
2110 filer_window->selection_state = normal
2111 ? GTK_STATE_SELECTED : GTK_STATE_INSENSITIVE;
2113 if (old_state != filer_window->selection_state
2114 && view_count_selected(filer_window->view))
2115 gtk_widget_queue_draw(GTK_WIDGET(filer_window->view));
2118 void filer_cancel_thumbnails(FilerWindow *filer_window)
2120 gtk_widget_hide(filer_window->thumb_bar);
2122 destroy_glist(&filer_window->thumb_queue);
2123 filer_window->max_thumbs = 0;
2126 /* Generate the next thumb for this window. The window object is
2127 * unref'd when there is nothing more to do.
2128 * If the window no longer has a filer window, nothing is done.
2130 static gboolean filer_next_thumb_real(GObject *window)
2132 FilerWindow *filer_window;
2133 gchar *path;
2134 int done, total;
2136 filer_window = g_object_get_data(window, "filer_window");
2138 if (!filer_window)
2140 g_object_unref(window);
2141 return FALSE;
2144 if (!filer_window->thumb_queue)
2146 filer_cancel_thumbnails(filer_window);
2147 g_object_unref(window);
2148 return FALSE;
2151 total = filer_window->max_thumbs;
2152 done = total - g_list_length(filer_window->thumb_queue);
2154 path = (gchar *) filer_window->thumb_queue->data;
2156 pixmap_background_thumb(path, (GFunc) filer_next_thumb, window);
2158 filer_window->thumb_queue = g_list_remove(filer_window->thumb_queue,
2159 path);
2160 g_free(path);
2162 gtk_progress_bar_set_fraction(
2163 GTK_PROGRESS_BAR(filer_window->thumb_progress),
2164 done / (float) total);
2166 return FALSE;
2169 /* path is the thumb just loaded, if any.
2170 * window is unref'd (eventually).
2172 static void filer_next_thumb(GObject *window, const gchar *path)
2174 if (path)
2175 dir_force_update_path(path);
2177 g_idle_add((GSourceFunc) filer_next_thumb_real, window);
2180 static void start_thumb_scanning(FilerWindow *filer_window)
2182 if (GTK_WIDGET_VISIBLE(filer_window->thumb_bar))
2183 return; /* Already scanning */
2185 gtk_widget_show_all(filer_window->thumb_bar);
2187 g_object_ref(G_OBJECT(filer_window->window));
2188 filer_next_thumb(G_OBJECT(filer_window->window), NULL);
2191 /* Set this image to be loaded some time in the future */
2192 void filer_create_thumb(FilerWindow *filer_window, const gchar *path)
2194 if (g_list_find_custom(filer_window->thumb_queue, path,
2195 (GCompareFunc) strcmp))
2196 return;
2198 if (!filer_window->thumb_queue)
2199 filer_window->max_thumbs=0;
2200 filer_window->max_thumbs++;
2202 filer_window->thumb_queue = g_list_append(filer_window->thumb_queue,
2203 g_strdup(path));
2205 if (filer_window->scanning)
2206 return; /* Will start when scan ends */
2208 start_thumb_scanning(filer_window);
2211 /* If thumbnail display is on, look through all the items in this directory
2212 * and start creating or updating the thumbnails as needed.
2214 void filer_create_thumbs(FilerWindow *filer_window)
2216 DirItem *item;
2217 ViewIter iter;
2219 if (!filer_window->show_thumbs)
2220 return;
2222 view_get_iter(filer_window->view, &iter, 0);
2224 while ((item = iter.next(&iter)))
2226 MaskedPixmap *pixmap;
2227 const guchar *path;
2228 gboolean found;
2230 if (item->base_type != TYPE_FILE)
2231 continue;
2233 /*if (strcmp(item->mime_type->media_type, "image") != 0)
2234 continue;*/
2236 path = make_path(filer_window->real_path, item->leafname);
2238 pixmap = g_fscache_lookup_full(pixmap_cache, path,
2239 FSCACHE_LOOKUP_ONLY_NEW, &found);
2240 if (pixmap)
2241 g_object_unref(pixmap);
2243 /* If we didn't get an image, it could be because:
2245 * - We're loading the image now. found is TRUE,
2246 * and we'll update the item later.
2247 * - We tried to load the image and failed. found
2248 * is TRUE.
2249 * - We haven't tried loading the image. found is
2250 * FALSE, and we start creating the thumb here.
2252 if (!found)
2253 filer_create_thumb(filer_window, path);
2257 static void filer_options_changed(void)
2259 if (o_short_flag_names.has_changed)
2261 GList *next;
2263 for (next = all_filer_windows; next; next = next->next)
2265 FilerWindow *filer_window = (FilerWindow *) next->data;
2267 filer_set_title(filer_window);
2272 /* Append interesting information to this GString */
2273 void filer_add_tip_details(FilerWindow *filer_window,
2274 GString *tip, DirItem *item)
2276 const guchar *fullpath = NULL;
2278 fullpath = make_path(filer_window->real_path, item->leafname);
2280 if (item->flags & ITEM_FLAG_SYMLINK)
2282 char *target;
2284 target = readlink_dup(fullpath);
2285 if (target)
2287 ensure_utf8(&target);
2289 g_string_append(tip, _("Symbolic link to "));
2290 g_string_append(tip, target);
2291 g_string_append_c(tip, '\n');
2292 g_free(target);
2296 if (item->flags & ITEM_FLAG_APPDIR)
2298 XMLwrapper *info;
2299 xmlNode *node;
2301 info = appinfo_get(fullpath, item);
2302 if (info && ((node = xml_get_section(info, NULL, "Summary"))))
2304 guchar *str;
2305 str = xmlNodeListGetString(node->doc,
2306 node->xmlChildrenNode, 1);
2307 if (str)
2309 g_string_append(tip, str);
2310 g_string_append_c(tip, '\n');
2311 g_free(str);
2314 if (info)
2315 g_object_unref(info);
2318 if (!g_utf8_validate(item->leafname, -1, NULL))
2319 g_string_append(tip,
2320 _("This filename is not valid UTF-8. "
2321 "You should rename it.\n"));
2324 /* Return the selection as a text/uri-list.
2325 * g_free() the result.
2327 static guchar *filer_create_uri_list(FilerWindow *filer_window)
2329 GString *string;
2330 GString *leader;
2331 ViewIter iter;
2332 DirItem *item;
2333 guchar *retval;
2335 g_return_val_if_fail(filer_window != NULL, NULL);
2337 string = g_string_new(NULL);
2339 leader = g_string_new(filer_window->sym_path);
2340 if (leader->str[leader->len - 1] != '/')
2341 g_string_append_c(leader, '/');
2343 view_get_iter(filer_window->view, &iter, VIEW_ITER_SELECTED);
2344 while ((item = iter.next(&iter)))
2346 EscapedPath *uri;
2347 char *path;
2349 path = g_strconcat(leader->str, item->leafname, NULL);
2350 uri = encode_path_as_uri(path);
2351 g_string_append(string, (char *) uri);
2352 g_string_append(string, "\r\n");
2353 g_free(path);
2354 g_free(uri);
2357 g_string_free(leader, TRUE);
2358 retval = string->str;
2359 g_string_free(string, FALSE);
2361 return retval;
2364 void filer_perform_action(FilerWindow *filer_window, GdkEventButton *event)
2366 BindAction action;
2367 ViewIface *view = filer_window->view;
2368 DirItem *item = NULL;
2369 gboolean press = event->type == GDK_BUTTON_PRESS;
2370 ViewIter iter;
2371 OpenFlags flags = 0;
2373 if (event->button > 3)
2374 return;
2376 view_get_iter_at_point(view, &iter, event->window, event->x, event->y);
2377 item = iter.peek(&iter);
2379 if (item && event->button == 1 &&
2380 view_get_selected(view, &iter) &&
2381 filer_window->selection_state == GTK_STATE_INSENSITIVE)
2383 /* Possibly a really slow DnD operation? */
2384 filer_window->temp_item_selected = FALSE;
2386 filer_selection_changed(filer_window, event->time);
2387 return;
2390 if (filer_window->target_cb)
2392 dnd_motion_ungrab();
2393 if (item && press && event->button == 1)
2394 filer_window->target_cb(filer_window, &iter,
2395 filer_window->target_data);
2397 filer_target_mode(filer_window, NULL, NULL, NULL);
2399 return;
2402 if (!o_single_click.int_value)
2404 /* Make sure both parts of a double-click fall on
2405 * the same file.
2407 static guchar *first_click = NULL;
2408 static guchar *second_click = NULL;
2410 if (event->type == GDK_BUTTON_PRESS)
2412 g_free(first_click);
2413 first_click = second_click;
2415 if (item)
2416 second_click = g_strdup(item->leafname);
2417 else
2418 second_click = NULL;
2421 if (event->type == GDK_2BUTTON_PRESS)
2423 if (first_click && second_click &&
2424 strcmp(first_click, second_click) != 0)
2425 return;
2426 if ((first_click || second_click) &&
2427 !(first_click && second_click))
2428 return;
2432 action = bind_lookup_bev(
2433 item ? BIND_DIRECTORY_ICON : BIND_DIRECTORY,
2434 event);
2436 switch (action)
2438 case ACT_CLEAR_SELECTION:
2439 view_clear_selection(view);
2440 break;
2441 case ACT_TOGGLE_SELECTED:
2442 view_set_selected(view, &iter,
2443 !view_get_selected(view, &iter));
2444 break;
2445 case ACT_SELECT_EXCL:
2446 view_select_only(view, &iter);
2447 break;
2448 case ACT_EDIT_ITEM:
2449 flags |= OPEN_SHIFT;
2450 /* (no break) */
2451 case ACT_OPEN_ITEM:
2452 if (event->button != 1 || event->state & GDK_MOD1_MASK)
2453 flags |= OPEN_CLOSE_WINDOW;
2454 else
2455 flags |= OPEN_SAME_WINDOW;
2456 if (o_new_button_1.int_value)
2457 flags ^= OPEN_SAME_WINDOW;
2458 if (event->type == GDK_2BUTTON_PRESS)
2459 view_set_selected(view, &iter, FALSE);
2460 dnd_motion_ungrab();
2462 filer_openitem(filer_window, &iter, flags);
2463 break;
2464 case ACT_POPUP_MENU:
2465 dnd_motion_ungrab();
2466 tooltip_show(NULL);
2467 show_filer_menu(filer_window,
2468 (GdkEvent *) event, &iter);
2469 break;
2470 case ACT_PRIME_AND_SELECT:
2471 if (item && !view_get_selected(view, &iter))
2472 view_select_only(view, &iter);
2473 dnd_motion_start(MOTION_READY_FOR_DND);
2474 break;
2475 case ACT_PRIME_AND_TOGGLE:
2476 view_set_selected(view, &iter,
2477 !view_get_selected(view, &iter));
2478 dnd_motion_start(MOTION_READY_FOR_DND);
2479 break;
2480 case ACT_PRIME_FOR_DND:
2481 dnd_motion_start(MOTION_READY_FOR_DND);
2482 break;
2483 case ACT_IGNORE:
2484 if (press && event->button < 4)
2486 if (item)
2487 view_wink_item(view, &iter);
2488 dnd_motion_start(MOTION_NONE);
2490 break;
2491 case ACT_LASSO_CLEAR:
2492 view_clear_selection(view);
2493 /* (no break) */
2494 case ACT_LASSO_MODIFY:
2495 view_start_lasso_box(view, event);
2496 break;
2497 case ACT_RESIZE:
2498 view_autosize(filer_window->view);
2499 break;
2500 default:
2501 g_warning("Unsupported action : %d\n", action);
2502 break;
2506 /* It's time to make the tooltip appear. If we're not over the item any
2507 * more, or the item doesn't need a tooltip, do nothing.
2509 static gboolean tooltip_activate(GtkWidget *window)
2511 FilerWindow *filer_window;
2512 ViewIface *view;
2513 ViewIter iter;
2514 gint x, y;
2515 DirItem *item = NULL;
2516 GString *tip = NULL;
2518 g_return_val_if_fail(tip_item != NULL, 0);
2520 filer_window = g_object_get_data(G_OBJECT(window), "filer_window");
2522 if (!motion_window || !filer_window)
2523 return FALSE; /* Window has been destroyed */
2525 view = filer_window->view;
2527 tooltip_show(NULL);
2529 gdk_window_get_pointer(motion_window, &x, &y, NULL);
2530 view_get_iter_at_point(view, &iter, motion_window, x, y);
2532 item = iter.peek(&iter);
2533 if (item != tip_item)
2534 return FALSE; /* Not still under the pointer */
2536 /* OK, the filer window still exists and the pointer is still
2537 * over the same item. Do we need to show a tip?
2540 tip = g_string_new(NULL);
2542 view_extend_tip(filer_window->view, &iter, tip);
2544 filer_add_tip_details(filer_window, tip, tip_item);
2546 if (tip->len > 1)
2548 g_string_truncate(tip, tip->len - 1);
2550 tooltip_show(tip->str);
2553 g_string_free(tip, TRUE);
2555 return FALSE;
2558 /* Motion detected on the View widget */
2559 gint filer_motion_notify(FilerWindow *filer_window, GdkEventMotion *event)
2561 ViewIface *view = filer_window->view;
2562 ViewIter iter;
2563 DirItem *item;
2565 view_get_iter_at_point(view, &iter, event->window, event->x, event->y);
2566 item = iter.peek(&iter);
2568 if (item)
2570 if (item != tip_item)
2572 tooltip_show(NULL);
2574 tip_item = item;
2575 motion_window = event->window;
2576 tooltip_prime((GtkFunction) tooltip_activate,
2577 G_OBJECT(filer_window->window));
2580 else
2582 tooltip_show(NULL);
2583 tip_item = NULL;
2586 if (motion_state != MOTION_READY_FOR_DND)
2587 return FALSE;
2589 if (!dnd_motion_moved(event))
2590 return FALSE;
2592 view_get_iter_at_point(view, &iter,
2593 event->window,
2594 event->x - (event->x_root - drag_start_x),
2595 event->y - (event->y_root - drag_start_y));
2596 item = iter.peek(&iter);
2597 if (!item)
2598 return FALSE;
2600 view_wink_item(view, NULL);
2602 if (!view_get_selected(view, &iter))
2604 if (event->state & GDK_BUTTON1_MASK)
2606 /* Select just this one */
2607 filer_window->temp_item_selected = TRUE;
2608 view_select_only(view, &iter);
2610 else
2612 if (view_count_selected(view) == 0)
2613 filer_window->temp_item_selected = TRUE;
2614 view_set_selected(view, &iter, TRUE);
2618 g_return_val_if_fail(view_count_selected(view) > 0, TRUE);
2620 if (view_count_selected(view) == 1)
2622 if (item->base_type == TYPE_UNKNOWN)
2623 item = dir_update_item(filer_window->directory,
2624 item->leafname);
2626 if (!item)
2628 report_error(_("Item no longer exists!"));
2629 return FALSE;
2632 drag_one_item(GTK_WIDGET(view), event,
2633 make_path(filer_window->sym_path, item->leafname),
2634 item, di_image(item));
2635 #if 0
2636 /* XXX: Use thumbnail */
2637 item, view ? view->image : NULL);
2638 #endif
2640 else
2642 guchar *uris;
2644 uris = filer_create_uri_list(filer_window);
2645 drag_selection(GTK_WIDGET(view), event, uris);
2646 g_free(uris);
2649 return FALSE;
2652 static void drag_end(GtkWidget *widget, GdkDragContext *context,
2653 FilerWindow *filer_window)
2655 filer_set_autoscroll(filer_window, FALSE);
2657 if (filer_window->temp_item_selected)
2659 view_clear_selection(filer_window->view);
2660 filer_window->temp_item_selected = FALSE;
2664 /* Remove highlights */
2665 static void drag_leave(GtkWidget *widget,
2666 GdkDragContext *context,
2667 guint32 time,
2668 FilerWindow *filer_window)
2670 dnd_spring_abort();
2673 /* Called during the drag when the mouse is in a widget registered
2674 * as a drop target. Returns TRUE if we can accept the drop.
2676 static gboolean drag_motion(GtkWidget *widget,
2677 GdkDragContext *context,
2678 gint x,
2679 gint y,
2680 guint time,
2681 FilerWindow *filer_window)
2683 DirItem *item;
2684 ViewIface *view = filer_window->view;
2685 ViewIter iter;
2686 GdkDragAction action = context->suggested_action;
2687 const guchar *new_path = NULL;
2688 const char *type = NULL;
2689 gboolean retval = FALSE;
2690 gboolean same_window;
2692 if ((context->actions & GDK_ACTION_ASK) && o_dnd_left_menu.int_value)
2694 guint state;
2695 gdk_window_get_pointer(NULL, NULL, NULL, &state);
2696 if (state & GDK_BUTTON1_MASK)
2697 action = GDK_ACTION_ASK;
2700 same_window = gtk_drag_get_source_widget(context) == widget;
2702 filer_set_autoscroll(filer_window, TRUE);
2704 if (filer_window->view_type == VIEW_TYPE_DETAILS)
2706 GdkWindow *bin;
2707 int bin_y;
2708 /* Correct for position of bin window */
2709 bin = gtk_tree_view_get_bin_window(GTK_TREE_VIEW(view));
2710 gdk_window_get_position(bin, NULL, &bin_y);
2711 y -= bin_y;
2714 if (o_dnd_drag_to_icons.int_value)
2716 view_get_iter_at_point(view, &iter, widget->window, x, y);
2717 item = iter.peek(&iter);
2719 else
2720 item = NULL;
2722 if (item && same_window && view_get_selected(view, &iter))
2723 type = NULL;
2724 else
2725 type = dnd_motion_item(context, &item);
2727 if (!type)
2728 item = NULL;
2730 /* Don't allow drops to non-writeable directories. BUT, still
2731 * allow drops on non-writeable SUBdirectories so that we can
2732 * do the spring-open thing.
2734 if (item && type == drop_dest_dir &&
2735 !(item->flags & ITEM_FLAG_APPDIR))
2737 dnd_spring_load(context, filer_window);
2739 else
2740 dnd_spring_abort();
2742 if (item)
2743 view_cursor_to_iter(view, &iter);
2744 else
2746 view_cursor_to_iter(view, NULL);
2748 /* Disallow background drops within a single window */
2749 if (type && same_window)
2750 type = NULL;
2753 if (type)
2755 if (item)
2756 new_path = make_path(filer_window->sym_path,
2757 item->leafname);
2758 else
2759 new_path = filer_window->sym_path;
2762 /* Don't ask about dragging to an application! */
2763 if (type == drop_dest_prog && action == GDK_ACTION_ASK)
2764 action = GDK_ACTION_COPY;
2766 g_dataset_set_data(context, "drop_dest_type", (gpointer) type);
2767 if (type)
2769 gdk_drag_status(context, action, time);
2770 g_dataset_set_data_full(context, "drop_dest_path",
2771 g_strdup(new_path), g_free);
2772 retval = TRUE;
2775 return retval;
2778 static gboolean as_timeout(FilerWindow *filer_window)
2780 gboolean retval;
2782 retval = view_auto_scroll_callback(filer_window->view);
2784 if (!retval)
2785 filer_window->auto_scroll = -1;
2787 return retval;
2790 /* When autoscroll is on, a timer keeps track of the pointer position.
2791 * While it's near the top or bottom of the window, the window scrolls.
2793 * If the mouse buttons are released, the pointer leaves the window, or
2794 * a drag-and-drop operation finishes, auto_scroll is turned off.
2796 void filer_set_autoscroll(FilerWindow *filer_window, gboolean auto_scroll)
2798 g_return_if_fail(filer_window != NULL);
2800 if (auto_scroll)
2802 if (filer_window->auto_scroll != -1)
2803 return; /* Already on! */
2805 filer_window->auto_scroll = g_timeout_add(50,
2806 (GSourceFunc) as_timeout,
2807 filer_window);
2809 else
2811 if (filer_window->auto_scroll == -1)
2812 return; /* Already off! */
2814 g_source_remove(filer_window->auto_scroll);
2815 filer_window->auto_scroll = -1;
2819 #define ZERO_MNT "/uri/0install"
2821 static void refresh_done(FilerWindow *filer_window)
2823 if (filer_exists(filer_window))
2824 filer_update_dir(filer_window, TRUE);
2827 void filer_refresh(FilerWindow *filer_window)
2829 if (!strncmp(ZERO_MNT "/", filer_window->real_path, sizeof(ZERO_MNT)))
2831 /* Try to run 0refresh */
2832 gint pid;
2833 gchar *argv[] = {"0refresh", NULL, NULL};
2834 const char *host = filer_window->real_path + sizeof(ZERO_MNT);
2835 const char *slash;
2837 slash = strchr(host, '/');
2838 if (slash)
2839 argv[1] = g_strndup(host, slash - host);
2840 else
2841 argv[1] = g_strdup(host);
2842 pid = rox_spawn(filer_window->real_path, (const char **) argv);
2843 g_free(argv[1]);
2844 if (pid)
2845 on_child_death(pid, (CallbackFn) refresh_done,
2846 filer_window);
2849 full_refresh();
2852 gboolean filer_match_filter(FilerWindow *filer_window, const gchar *filename)
2854 g_return_val_if_fail(filename != NULL, FALSE);
2856 if(filename[0]=='.' &&
2857 (!filer_window->temp_show_hidden && !filer_window->show_hidden))
2858 return FALSE;
2860 switch(filer_window->filter) {
2861 case FILER_SHOW_GLOB:
2862 return fnmatch(filer_window->filter_string,
2863 filename, 0)==0;
2865 case FILER_SHOW_REGEXP: /* Unimplemented */
2867 case FILER_SHOW_ALL:
2868 default:
2869 break;
2871 return TRUE;
2874 /* Provided to hide the implementation */
2875 void filer_set_hidden(FilerWindow *filer_window, gboolean hidden)
2877 filer_window->show_hidden=hidden;
2880 /* Set the filter type. Returns TRUE if the type has changed
2881 * (must call filer_detach_rescan).
2883 gboolean filer_set_filter(FilerWindow *filer_window, FilterType type,
2884 const gchar *filter_string)
2886 /* Is this new filter the same as the old one? */
2887 if (filer_window->filter == type)
2889 switch(filer_window->filter)
2891 case FILER_SHOW_ALL:
2892 return FALSE;
2893 case FILER_SHOW_GLOB:
2894 case FILER_SHOW_REGEXP:
2895 if (strcmp(filer_window->filter_string,
2896 filter_string) == 0)
2897 return FALSE;
2898 break;
2902 /* Clean up old filter */
2903 if (filer_window->filter_string)
2905 g_free(filer_window->filter_string);
2906 filer_window->filter_string = NULL;
2908 /* Also clean up compiled regexp when implemented */
2910 filer_window->filter = type;
2912 switch(type)
2914 case FILER_SHOW_ALL:
2915 /* No extra work */
2916 break;
2918 case FILER_SHOW_GLOB:
2919 filer_window->filter_string = g_strdup(filter_string);
2920 break;
2922 case FILER_SHOW_REGEXP:
2923 filer_window->filter_string = g_strdup(filter_string);
2924 /* Compile the pattern */
2925 break;
2927 default:
2928 /* oops */
2929 filer_window->filter = FILER_SHOW_ALL;
2930 g_warning("Impossible: filter type %d", type);
2931 break;
2934 return TRUE;
2937 /* Setting stuff */
2938 static Settings *settings_new(const char *path)
2940 Settings *set;
2942 set=g_new(Settings, 1);
2943 memset(set, 0, sizeof(Settings));
2944 if(path)
2945 set->path=g_strdup(path);
2947 return set;
2950 static void settings_free(Settings *set)
2952 g_free(set->path);
2953 if(set->filter)
2954 g_free(set->filter);
2955 g_free(set);
2958 static void store_settings(Settings *set)
2960 Settings *old;
2962 old=g_hash_table_lookup(settings_table, set->path);
2963 if(old)
2965 g_hash_table_remove(settings_table, set->path);
2966 settings_free(old);
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_xdg_path_load("Settings.xml", PROJECT, SITE);
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_xdg_path_save("Settings.xml", PROJECT, SITE, 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);