r4034: Use application_x_shellscript for scripts.
[rox-filer/translations.git] / ROX-Filer / src / filer.c
blobf913cf0056a1d2ee82d2a74378df9e8e70ae4b52
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 GtkWidget *window;
248 g_return_if_fail(filer_window != NULL);
250 if (filer_window->scrollbar)
251 w += filer_window->scrollbar->allocation.width;
253 if (o_toolbar.int_value != TOOLBAR_NONE)
254 h += filer_window->toolbar->allocation.height;
255 if (filer_window->message)
256 h += filer_window->message->allocation.height;
258 window = filer_window->window;
260 if (GTK_WIDGET_VISIBLE(window))
262 gint x, y, m;
263 GtkRequisition *req = &window->requisition;
264 GdkWindow *gdk_window = window->window;
265 GdkEvent *event;
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 /* If the resize was triggered by a key press, keep
297 * the pointer inside the window so that it doesn't
298 * lose focus when using pointer-follows-mouse.
300 event = gtk_get_current_event();
301 if (event && event->type == GDK_KEY_PRESS)
303 int x, y;
304 int nx, ny;
306 GdkWindow *win = filer_window->window->window;
308 gdk_window_get_pointer(filer_window->window->window,
309 &x, &y, NULL);
311 nx = CLAMP(x, 4, w - 4);
312 ny = CLAMP(y, 4, h - 4);
314 if (nx != x || ny != y)
316 XWarpPointer(gdk_x11_drawable_get_xdisplay(win),
317 None,
318 gdk_x11_drawable_get_xid(win),
319 0, 0, 0, 0,
320 nx, ny);
324 else
325 gtk_window_set_default_size(GTK_WINDOW(window), w, h);
328 /* Called on a timeout while scanning or when scanning ends
329 * (whichever happens first).
331 static gint open_filer_window(FilerWindow *filer_window)
333 Settings *dir_settings = (Settings *) g_hash_table_lookup(settings_table,
334 filer_window->sym_path);
335 gboolean force_resize = !(o_filer_auto_resize.int_value == RESIZE_NEVER && dir_settings && dir_settings->flags & SET_POSITION);
337 view_style_changed(filer_window->view, 0);
339 if (filer_window->open_timeout)
341 g_source_remove(filer_window->open_timeout);
342 filer_window->open_timeout = 0;
345 if (!GTK_WIDGET_VISIBLE(filer_window->window))
347 display_set_actual_size(filer_window, force_resize);
348 gtk_widget_show(filer_window->window);
351 return FALSE;
354 /* Look through all items we want to display, and queue a recheck on any
355 * that require it.
357 static void queue_interesting(FilerWindow *filer_window)
359 DirItem *item;
360 ViewIter iter;
362 view_get_iter(filer_window->view, &iter, 0);
363 while ((item = iter.next(&iter)))
365 if (item->flags & ITEM_FLAG_NEED_RESCAN_QUEUE)
366 dir_queue_recheck(filer_window->directory, item);
370 static void update_display(Directory *dir,
371 DirAction action,
372 GPtrArray *items,
373 FilerWindow *filer_window)
375 ViewIface *view = (ViewIface *) filer_window->view;
377 switch (action)
379 case DIR_ADD:
380 view_add_items(view, items);
381 /* Open and resize if currently hidden */
382 open_filer_window(filer_window);
383 break;
384 case DIR_REMOVE:
385 view_delete_if(view, if_deleted, items);
386 toolbar_update_info(filer_window);
387 break;
388 case DIR_START_SCAN:
389 set_scanning_display(filer_window, TRUE);
390 toolbar_update_info(filer_window);
391 break;
392 case DIR_END_SCAN:
393 if (filer_window->window->window)
394 gdk_window_set_cursor(
395 filer_window->window->window,
396 NULL);
397 set_scanning_display(filer_window, FALSE);
398 toolbar_update_info(filer_window);
399 open_filer_window(filer_window);
401 if (filer_window->had_cursor &&
402 !view_cursor_visible(view))
404 ViewIter start;
405 view_get_iter(view, &start, 0);
406 if (start.next(&start))
407 view_cursor_to_iter(view, &start);
408 view_show_cursor(view);
409 filer_window->had_cursor = FALSE;
411 if (filer_window->auto_select)
412 display_set_autoselect(filer_window,
413 filer_window->auto_select);
414 null_g_free(&filer_window->auto_select);
416 filer_create_thumbs(filer_window);
418 if (filer_window->thumb_queue)
419 start_thumb_scanning(filer_window);
420 break;
421 case DIR_UPDATE:
422 view_update_items(view, items);
423 break;
424 case DIR_ERROR_CHANGED:
425 filer_set_title(filer_window);
426 break;
427 case DIR_QUEUE_INTERESTING:
428 queue_interesting(filer_window);
429 break;
433 static void attach(FilerWindow *filer_window)
435 gdk_window_set_cursor(filer_window->window->window, busy_cursor);
436 view_clear(filer_window->view);
437 filer_window->scanning = TRUE;
438 dir_attach(filer_window->directory, (DirCallback) update_display,
439 filer_window);
440 filer_set_title(filer_window);
441 bookmarks_add_history(filer_window->sym_path);
443 if (filer_window->directory->error)
445 if (spring_in_progress)
446 g_printerr(_("Error scanning '%s':\n%s\n"),
447 filer_window->sym_path,
448 filer_window->directory->error);
449 else
450 delayed_error(_("Error scanning '%s':\n%s"),
451 filer_window->sym_path,
452 filer_window->directory->error);
456 static void detach(FilerWindow *filer_window)
458 g_return_if_fail(filer_window->directory != NULL);
460 dir_detach(filer_window->directory,
461 (DirCallback) update_display, filer_window);
462 g_object_unref(filer_window->directory);
463 filer_window->directory = NULL;
466 /* If 'start' was mounted by ROX-Filer, return it. Otherwise, try the
467 * parents up the tree.
468 * NULL if we're not in a user mount point.
469 * g_free() the result.
471 static char *get_ancestor_user_mount_point(const char *start)
473 char *path;
475 path = strdup(start);
477 while (1)
479 char *slash;
481 if (mount_is_user_mounted(path))
482 return path;
484 if (!path[1])
486 g_free(path);
487 return NULL;
490 slash = strrchr(path + 1, '/');
491 if (!slash)
492 slash = path + 1;
493 *slash = '\0';
497 static void umount_dialog_response(GtkWidget *dialog, int response, char *mount)
499 if (response == GTK_RESPONSE_OK)
501 GList *list;
503 list = g_list_prepend(NULL, mount);
504 action_mount(list, FALSE, FALSE, TRUE);
505 g_list_free(list);
508 g_free(mount);
510 gtk_widget_destroy(dialog);
512 one_less_window();
515 /* 'filer_window' shows a directory under 'mount'. If no other window also
516 * shows a directory under it, display a non-modal dialog offering to
517 * unmount the directory.
518 * 'mount' is freed by this function, either directly, or after the dialog
519 * closes.
521 static void may_offer_unmount(FilerWindow *filer_window, char *mount)
523 GtkWidget *dialog, *button;
524 GList *next;
525 int len;
527 len = strlen(mount);
529 for (next = all_filer_windows; next; next = next->next)
531 FilerWindow *other = (FilerWindow *) next->data;
533 if (other == filer_window)
534 continue;
536 if (strncmp(filer_window->real_path, other->real_path,
537 len) != 0)
538 continue;
540 g_return_if_fail(
541 filer_window->real_path[len] != '/' ||
542 filer_window->real_path[len] != '\0');
544 if (other->real_path[len] != '/' &&
545 other->real_path[len] != '\0')
546 continue;
548 /* Found another window. Don't offer to unmount. */
549 g_free(mount);
550 return;
553 dialog = gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_QUESTION,
554 GTK_BUTTONS_NONE,
555 _("Do you want to unmount this device?\n\n"
556 "Unmounting a device makes it safe to remove "
557 "the disk."), mount);
559 button = button_new_mixed(ROX_STOCK_MOUNTED, _("No change"));
560 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
561 gtk_dialog_add_action_widget(GTK_DIALOG(dialog), button,
562 GTK_RESPONSE_CANCEL);
563 gtk_widget_show(button);
565 button = button_new_mixed(ROX_STOCK_MOUNT, _("Unmount"));
566 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
567 gtk_dialog_add_action_widget(GTK_DIALOG(dialog), button,
568 GTK_RESPONSE_OK);
569 gtk_widget_show(button);
571 g_signal_connect(G_OBJECT(dialog), "response",
572 G_CALLBACK(umount_dialog_response), mount);
574 gtk_dialog_set_default_response(GTK_DIALOG(dialog),
575 GTK_RESPONSE_OK);
577 number_of_windows++;
578 gtk_widget_show(dialog);
581 /* Returns TRUE to prevent closing the window. May offer to unmount a
582 * device.
584 gboolean filer_window_delete(GtkWidget *window,
585 GdkEvent *unused, /* (may be NULL) */
586 FilerWindow *filer_window)
588 char *mount;
590 mount = get_ancestor_user_mount_point(filer_window->real_path);
592 if (mount)
593 may_offer_unmount(filer_window, mount);
595 return FALSE;
598 static void filer_window_destroyed(GtkWidget *widget, FilerWindow *filer_window)
600 all_filer_windows = g_list_remove(all_filer_windows, filer_window);
602 g_object_set_data(G_OBJECT(widget), "filer_window", NULL);
604 if (window_with_primary == filer_window)
605 window_with_primary = NULL;
607 if (window_with_focus == filer_window)
609 menu_popdown();
610 window_with_focus = NULL;
613 if (filer_window->directory)
614 detach(filer_window);
616 if (filer_window->open_timeout)
618 g_source_remove(filer_window->open_timeout);
619 filer_window->open_timeout = 0;
622 if (filer_window->auto_scroll != -1)
624 g_source_remove(filer_window->auto_scroll);
625 filer_window->auto_scroll = -1;
628 if (filer_window->thumb_queue)
629 destroy_glist(&filer_window->thumb_queue);
631 tooltip_show(NULL);
633 filer_set_id(filer_window, NULL);
635 if(filer_window->filter_string)
636 g_free(filer_window->filter_string);
637 if(filer_window->regexp)
638 g_free(filer_window->regexp);
640 g_free(filer_window->auto_select);
641 g_free(filer_window->real_path);
642 g_free(filer_window->sym_path);
643 g_free(filer_window);
645 one_less_window();
648 /* Returns TRUE iff the directory still exists. */
649 static gboolean may_rescan(FilerWindow *filer_window, gboolean warning)
651 Directory *dir;
653 g_return_val_if_fail(filer_window != NULL, FALSE);
655 /* We do a fresh lookup (rather than update) because the inode may
656 * have changed.
658 dir = g_fscache_lookup(dir_cache, filer_window->real_path);
659 if (!dir)
661 if (warning)
662 info_message(_("Directory missing/deleted"));
663 gtk_widget_destroy(filer_window->window);
664 return FALSE;
666 if (dir == filer_window->directory)
667 g_object_unref(dir);
668 else
670 detach(filer_window);
671 filer_window->directory = dir;
672 attach(filer_window);
675 return TRUE;
678 /* No items are now selected. This might be because another app claimed
679 * the selection or because the user unselected all the items.
681 void filer_lost_selection(FilerWindow *filer_window, guint time)
683 if (window_with_primary == filer_window)
685 window_with_primary = NULL;
686 gtk_selection_owner_set(NULL, GDK_SELECTION_PRIMARY, time);
690 /* Another app has claimed the primary selection */
691 static void filer_lost_primary(GtkWidget *window,
692 GdkEventSelection *event,
693 gpointer user_data)
695 FilerWindow *filer_window = (FilerWindow *) user_data;
697 if (window_with_primary && window_with_primary == filer_window)
699 window_with_primary = NULL;
700 set_selection_state(filer_window, FALSE);
704 /* Someone wants us to send them the selection */
705 static void selection_get(GtkWidget *widget,
706 GtkSelectionData *selection_data,
707 guint info,
708 guint time,
709 gpointer data)
711 GString *reply, *header;
712 FilerWindow *filer_window = (FilerWindow *) data;
713 ViewIter iter;
714 DirItem *item;
716 reply = g_string_new(NULL);
717 header = g_string_new(NULL);
719 switch (info)
721 case TARGET_STRING:
722 g_string_printf(header, " %s",
723 make_path(filer_window->sym_path, ""));
724 break;
725 case TARGET_URI_LIST:
726 g_string_printf(header, " file://%s%s",
727 our_host_name_for_dnd(),
728 make_path(filer_window->sym_path, ""));
729 break;
732 view_get_iter(filer_window->view, &iter, VIEW_ITER_SELECTED);
734 while ((item = iter.next(&iter)))
736 g_string_append(reply, header->str);
737 g_string_append(reply, item->leafname);
740 if (reply->len > 0)
741 gtk_selection_data_set_text(selection_data,
742 reply->str + 1, reply->len - 1);
743 else
745 g_warning("Attempt to paste empty selection!");
746 gtk_selection_data_set_text(selection_data, "", 0);
749 g_string_free(reply, TRUE);
750 g_string_free(header, TRUE);
753 /* Selection has been changed -- try to grab the primary selection
754 * if we don't have it. Also called when clicking on an insensitive selection
755 * to regain primary.
756 * Also updates toolbar info.
758 void filer_selection_changed(FilerWindow *filer_window, gint time)
760 toolbar_update_info(filer_window);
762 if (window_with_primary == filer_window)
763 return; /* Already got primary */
765 if (!view_count_selected(filer_window->view))
766 return; /* Nothing selected */
768 if (filer_window->temp_item_selected == FALSE &&
769 gtk_selection_owner_set(GTK_WIDGET(filer_window->window),
770 GDK_SELECTION_PRIMARY,
771 time))
773 window_with_primary = filer_window;
774 set_selection_state(filer_window, TRUE);
776 else
777 set_selection_state(filer_window, FALSE);
780 /* Open the item (or add it to the shell command minibuffer) */
781 void filer_openitem(FilerWindow *filer_window, ViewIter *iter, OpenFlags flags)
783 gboolean shift = (flags & OPEN_SHIFT) != 0;
784 gboolean close_mini = flags & OPEN_FROM_MINI;
785 gboolean close_window = (flags & OPEN_CLOSE_WINDOW) != 0;
786 DirItem *item;
787 const guchar *full_path;
788 gboolean wink = TRUE;
789 Directory *old_dir;
791 g_return_if_fail(filer_window != NULL && iter != NULL);
793 item = iter->peek(iter);
795 g_return_if_fail(item != NULL);
797 if (filer_window->mini_type == MINI_SHELL)
799 minibuffer_add(filer_window, item->leafname);
800 return;
803 if (item->base_type == TYPE_UNKNOWN)
804 dir_update_item(filer_window->directory, item->leafname);
806 if (item->base_type == TYPE_DIRECTORY)
808 /* Never close a filer window when opening a directory
809 * (click on a dir or click on an app with shift).
811 if (shift || !(item->flags & ITEM_FLAG_APPDIR))
812 close_window = FALSE;
815 full_path = make_path(filer_window->sym_path, item->leafname);
816 if (shift && (item->flags & ITEM_FLAG_SYMLINK))
817 wink = FALSE;
819 old_dir = filer_window->directory;
820 if (run_diritem(full_path, item,
821 flags & OPEN_SAME_WINDOW ? filer_window : NULL,
822 filer_window,
823 shift))
825 if (old_dir != filer_window->directory)
826 return;
828 if (close_window)
829 gtk_widget_destroy(filer_window->window);
830 else
832 if (wink)
833 view_wink_item(filer_window->view, iter);
834 if (close_mini)
835 minibuffer_hide(filer_window);
840 static gint pointer_in(GtkWidget *widget,
841 GdkEventCrossing *event,
842 FilerWindow *filer_window)
844 may_rescan(filer_window, TRUE);
845 return FALSE;
848 static gint pointer_out(GtkWidget *widget,
849 GdkEventCrossing *event,
850 FilerWindow *filer_window)
852 tooltip_show(NULL);
853 return FALSE;
856 /* Move the cursor to the next selected item in direction 'dir'
857 * (+1 or -1).
859 void filer_next_selected(FilerWindow *filer_window, int dir)
861 ViewIter iter, cursor;
862 gboolean have_cursor;
863 ViewIface *view = filer_window->view;
865 g_return_if_fail(dir == 1 || dir == -1);
867 view_get_cursor(view, &cursor);
868 have_cursor = cursor.peek(&cursor) != NULL;
870 view_get_iter(view, &iter,
871 VIEW_ITER_SELECTED |
872 (have_cursor ? VIEW_ITER_FROM_CURSOR : 0) |
873 (dir < 0 ? VIEW_ITER_BACKWARDS : 0));
875 if (have_cursor && view_get_selected(view, &cursor))
876 iter.next(&iter); /* Skip the cursor itself */
878 if (iter.next(&iter))
879 view_cursor_to_iter(view, &iter);
880 else
881 gdk_beep();
883 return;
886 static void return_pressed(FilerWindow *filer_window, GdkEventKey *event)
888 TargetFunc cb = filer_window->target_cb;
889 gpointer data = filer_window->target_data;
890 OpenFlags flags = 0;
891 ViewIter iter;
893 filer_target_mode(filer_window, NULL, NULL, NULL);
895 view_get_cursor(filer_window->view, &iter);
896 if (!iter.peek(&iter))
897 return;
899 if (cb)
901 cb(filer_window, &iter, data);
902 return;
905 if (event->state & GDK_SHIFT_MASK)
906 flags |= OPEN_SHIFT;
907 if (event->state & GDK_MOD1_MASK)
908 flags |= OPEN_CLOSE_WINDOW;
909 else
910 flags |= OPEN_SAME_WINDOW;
912 filer_openitem(filer_window, &iter, flags);
915 /* Makes sure that 'groups' is up-to-date, reloading from file if it has
916 * changed. If no groups were loaded and there is no file then initialised
917 * groups to an empty document.
918 * Return the node for the 'name' group.
920 static xmlNode *group_find(char *name)
922 xmlNode *node;
923 gchar *path;
925 /* Update the groups, if possible */
926 path = choices_find_xdg_path_load("Groups.xml", PROJECT, SITE);
927 if (path)
929 XMLwrapper *wrapper;
930 wrapper = xml_cache_load(path);
931 if (wrapper)
933 if (groups)
934 g_object_unref(groups);
935 groups = wrapper;
938 g_free(path);
941 if (!groups)
943 groups = xml_new(NULL);
944 groups->doc = xmlNewDoc("1.0");
946 xmlDocSetRootElement(groups->doc,
947 xmlNewDocNode(groups->doc, NULL, "groups", NULL));
948 return NULL;
951 node = xmlDocGetRootElement(groups->doc);
953 for (node = node->xmlChildrenNode; node; node = node->next)
955 guchar *gid;
957 gid = xmlGetProp(node, "name");
959 if (!gid)
960 continue;
962 if (strcmp(name, gid) != 0)
963 continue;
965 g_free(gid);
967 return node;
970 return NULL;
973 static void group_save(FilerWindow *filer_window, char *name)
975 xmlNode *group;
976 guchar *save_path;
977 DirItem *item;
978 ViewIter iter;
980 group = group_find(name);
981 if (group)
983 xmlUnlinkNode(group);
984 xmlFreeNode(group);
986 group = xmlNewChild(xmlDocGetRootElement(groups->doc),
987 NULL, "group", NULL);
988 xmlSetProp(group, "name", name);
990 xmlNewTextChild(group, NULL, "directory", filer_window->sym_path);
992 view_get_iter(filer_window->view, &iter, VIEW_ITER_SELECTED);
994 while ((item = iter.next(&iter)))
995 xmlNewTextChild(group, NULL, "item", item->leafname);
997 save_path = choices_find_xdg_path_save("Groups.xml", PROJECT, SITE,
998 TRUE);
999 if (save_path)
1001 save_xml_file(groups->doc, save_path);
1002 g_free(save_path);
1006 static gboolean group_restore_cb(ViewIter *iter, gpointer data)
1008 GHashTable *in_group = (GHashTable *) data;
1010 return g_hash_table_lookup(in_group,
1011 iter->peek(iter)->leafname) != NULL;
1014 static void group_restore(FilerWindow *filer_window, char *name)
1016 GHashTable *in_group;
1017 char *path;
1018 xmlNode *group, *node;
1020 group = group_find(name);
1022 if (!group)
1024 report_error(_("Group %s is not set. Select some files "
1025 "and press Ctrl+%s to set the group. Press %s "
1026 "on its own to reselect the files later.\n"
1027 "Make sure NumLock is on if you use the keypad."),
1028 name, name, name);
1029 return;
1032 node = get_subnode(group, NULL, "directory");
1033 g_return_if_fail(node != NULL);
1034 path = xmlNodeListGetString(groups->doc, node->xmlChildrenNode, 1);
1035 g_return_if_fail(path != NULL);
1037 if (strcmp(path, filer_window->sym_path) != 0)
1038 filer_change_to(filer_window, path, NULL);
1039 g_free(path);
1041 in_group = g_hash_table_new(g_str_hash, g_str_equal);
1042 for (node = group->xmlChildrenNode; node; node = node->next)
1044 gchar *leaf;
1045 if (node->type != XML_ELEMENT_NODE)
1046 continue;
1047 if (strcmp(node->name, "item") != 0)
1048 continue;
1050 leaf = xmlNodeListGetString(groups->doc,
1051 node->xmlChildrenNode, 1);
1052 if (!leaf)
1053 g_warning("Missing leafname!\n");
1054 else
1055 g_hash_table_insert(in_group, leaf, filer_window);
1058 view_select_if(filer_window->view, &group_restore_cb, in_group);
1060 g_hash_table_foreach(in_group, (GHFunc) g_free, NULL);
1061 g_hash_table_destroy(in_group);
1064 static gboolean popup_menu(GtkWidget *widget, FilerWindow *filer_window)
1066 ViewIter iter;
1068 view_get_cursor(filer_window->view, &iter);
1070 show_filer_menu(filer_window, NULL, &iter);
1072 return TRUE;
1075 void filer_window_toggle_cursor_item_selected(FilerWindow *filer_window)
1077 ViewIface *view = filer_window->view;
1078 ViewIter iter;
1080 view_get_iter(view, &iter, VIEW_ITER_FROM_CURSOR);
1081 if (!iter.next(&iter))
1082 return; /* No cursor */
1084 if (view_get_selected(view, &iter))
1085 view_set_selected(view, &iter, FALSE);
1086 else
1087 view_set_selected(view, &iter, TRUE);
1089 if (iter.next(&iter))
1090 view_cursor_to_iter(view, &iter);
1093 gint filer_key_press_event(GtkWidget *widget,
1094 GdkEventKey *event,
1095 FilerWindow *filer_window)
1097 ViewIface *view = filer_window->view;
1098 ViewIter cursor;
1099 GtkWidget *focus = GTK_WINDOW(widget)->focus_widget;
1100 guint key = event->keyval;
1101 char group[2] = "1";
1103 window_with_focus = filer_window;
1105 /* Delay setting up the keys until now to speed loading... */
1106 if (ensure_filer_menu())
1108 /* Gtk updates in an idle-handler, so force a recheck now */
1109 g_signal_emit_by_name(widget, "keys_changed");
1112 if (focus && focus == filer_window->minibuffer)
1113 if (gtk_widget_event(focus, (GdkEvent *) event))
1114 return TRUE; /* Handled */
1116 if (!focus)
1117 gtk_widget_grab_focus(GTK_WIDGET(view));
1119 view_get_cursor(view, &cursor);
1120 if (!cursor.peek(&cursor) && (key == GDK_Up || key == GDK_Down))
1122 ViewIter iter;
1123 view_get_iter(view, &iter, 0);
1124 if (iter.next(&iter))
1125 view_cursor_to_iter(view, &iter);
1126 gtk_widget_grab_focus(GTK_WIDGET(view)); /* Needed? */
1127 return TRUE;
1130 switch (key)
1132 case GDK_Escape:
1133 filer_target_mode(filer_window, NULL, NULL, NULL);
1134 view_cursor_to_iter(filer_window->view, NULL);
1135 view_clear_selection(filer_window->view);
1136 return FALSE;
1137 case GDK_Return:
1138 return_pressed(filer_window, event);
1139 break;
1140 case GDK_ISO_Left_Tab:
1141 filer_next_selected(filer_window, -1);
1142 break;
1143 case GDK_Tab:
1144 filer_next_selected(filer_window, 1);
1145 break;
1146 case GDK_BackSpace:
1147 change_to_parent(filer_window);
1148 break;
1149 case GDK_backslash:
1151 ViewIter iter;
1153 tooltip_show(NULL);
1155 view_get_cursor(filer_window->view, &iter);
1156 show_filer_menu(filer_window,
1157 (GdkEvent *) event, &iter);
1158 break;
1160 case ' ':
1161 filer_window_toggle_cursor_item_selected(filer_window);
1162 break;
1163 default:
1164 if (key >= GDK_0 && key <= GDK_9)
1165 group[0] = key - GDK_0 + '0';
1166 else if (key >= GDK_KP_0 && key <= GDK_KP_9)
1167 group[0] = key - GDK_KP_0 + '0';
1168 else
1170 if (focus && focus != widget &&
1171 gtk_widget_get_toplevel(focus) == widget)
1172 if (gtk_widget_event(focus,
1173 (GdkEvent *) event))
1174 return TRUE; /* Handled */
1175 return FALSE;
1178 if (event->state & GDK_CONTROL_MASK)
1179 group_save(filer_window, group);
1180 else
1181 group_restore(filer_window, group);
1184 return TRUE;
1187 void filer_open_parent(FilerWindow *filer_window)
1189 char *dir;
1190 const char *current = filer_window->sym_path;
1192 if (current[0] == '/' && current[1] == '\0')
1193 return; /* Already in the root */
1195 dir = g_path_get_dirname(current);
1196 filer_opendir(dir, filer_window, NULL);
1197 g_free(dir);
1200 void change_to_parent(FilerWindow *filer_window)
1202 char *dir;
1203 const char *current = filer_window->sym_path;
1205 if (current[0] == '/' && current[1] == '\0')
1206 return; /* Already in the root */
1208 if (mount_is_user_mounted(filer_window->real_path))
1209 may_offer_unmount(filer_window,
1210 g_strdup(filer_window->real_path));
1212 dir = g_path_get_dirname(current);
1213 filer_change_to(filer_window, dir, g_basename(current));
1214 g_free(dir);
1217 /* Removes trailing /s from path (modified in place) */
1218 static void tidy_sympath(gchar *path)
1220 int l;
1222 g_return_if_fail(path != NULL);
1224 l = strlen(path);
1225 while (l > 1 && path[l - 1] == '/')
1227 l--;
1228 path[l] = '\0';
1232 /* Make filer_window display path. When finished, highlight item 'from', or
1233 * the first item if from is NULL. If there is currently no cursor then
1234 * simply wink 'from' (if not NULL).
1235 * If the cause was a key event and we resize, warp the pointer.
1237 void filer_change_to(FilerWindow *filer_window,
1238 const char *path, const char *from)
1240 char *from_dup;
1241 char *sym_path, *real_path;
1242 Directory *new_dir;
1244 g_return_if_fail(filer_window != NULL);
1246 filer_cancel_thumbnails(filer_window);
1248 tooltip_show(NULL);
1250 sym_path = g_strdup(path);
1251 real_path = pathdup(path);
1252 new_dir = g_fscache_lookup(dir_cache, real_path);
1254 if (!new_dir)
1256 delayed_error(_("Directory '%s' is not accessible"),
1257 sym_path);
1258 g_free(real_path);
1259 g_free(sym_path);
1260 return;
1263 if (o_unique_filer_windows.int_value && !spring_in_progress)
1265 FilerWindow *fw;
1267 fw = find_filer_window(sym_path, filer_window);
1268 if (fw)
1269 gtk_widget_destroy(fw->window);
1272 from_dup = from && *from ? g_strdup(from) : NULL;
1274 detach(filer_window);
1275 g_free(filer_window->real_path);
1276 g_free(filer_window->sym_path);
1277 filer_window->real_path = real_path;
1278 filer_window->sym_path = sym_path;
1279 tidy_sympath(filer_window->sym_path);
1281 filer_window->directory = new_dir;
1283 g_free(filer_window->auto_select);
1284 filer_window->auto_select = from_dup;
1286 filer_window->had_cursor = filer_window->had_cursor ||
1287 view_cursor_visible(filer_window->view);
1289 filer_set_title(filer_window);
1290 if (filer_window->window->window)
1291 gdk_window_set_role(filer_window->window->window,
1292 filer_window->sym_path);
1293 view_cursor_to_iter(filer_window->view, NULL);
1295 attach(filer_window);
1297 check_settings(filer_window);
1299 display_set_actual_size(filer_window, FALSE);
1301 if (o_filer_auto_resize.int_value == RESIZE_ALWAYS)
1302 view_autosize(filer_window->view);
1304 if (filer_window->mini_type == MINI_PATH)
1305 g_idle_add((GSourceFunc) minibuffer_show_cb, filer_window);
1308 /* Returns a list containing the full (sym) pathname of every selected item.
1309 * You must g_free() each item in the list.
1311 GList *filer_selected_items(FilerWindow *filer_window)
1313 GList *retval = NULL;
1314 guchar *dir = filer_window->sym_path;
1315 ViewIter iter;
1316 DirItem *item;
1318 view_get_iter(filer_window->view, &iter, VIEW_ITER_SELECTED);
1319 while ((item = iter.next(&iter)))
1321 retval = g_list_prepend(retval,
1322 g_strdup(make_path(dir, item->leafname)));
1325 return g_list_reverse(retval);
1328 /* Return the single selected item. Error if nothing is selected. */
1329 DirItem *filer_selected_item(FilerWindow *filer_window)
1331 ViewIter iter;
1332 DirItem *item;
1334 view_get_iter(filer_window->view, &iter, VIEW_ITER_SELECTED);
1336 item = iter.next(&iter);
1337 g_return_val_if_fail(item != NULL, NULL);
1338 g_return_val_if_fail(iter.next(&iter) == NULL, NULL);
1340 return item;
1343 /* Creates and shows a new filer window.
1344 * If src_win != NULL then display options can be taken from that source window.
1345 * Returns the new filer window, or NULL on error.
1346 * Note: if unique windows is in use, may return an existing window.
1348 FilerWindow *filer_opendir(const char *path, FilerWindow *src_win,
1349 const gchar *wm_class)
1351 FilerWindow *filer_window;
1352 char *real_path;
1353 DisplayStyle dstyle;
1354 DetailsType dtype;
1355 SortType s_type;
1356 GtkSortType s_order;
1357 Settings *dir_settings = NULL;
1358 gboolean force_resize = TRUE;
1360 /* Get the real pathname of the directory and copy it */
1361 real_path = pathdup(path);
1363 if (o_unique_filer_windows.int_value && !spring_in_progress)
1365 FilerWindow *same_dir_window;
1367 same_dir_window = find_filer_window(path, NULL);
1369 if (same_dir_window)
1371 gtk_window_present(GTK_WINDOW(same_dir_window->window));
1372 return same_dir_window;
1376 filer_window = g_new(FilerWindow, 1);
1377 filer_window->message = NULL;
1378 filer_window->minibuffer = NULL;
1379 filer_window->minibuffer_label = NULL;
1380 filer_window->minibuffer_area = NULL;
1381 filer_window->temp_show_hidden = FALSE;
1382 filer_window->sym_path = g_strdup(path);
1383 filer_window->real_path = real_path;
1384 filer_window->scanning = FALSE;
1385 filer_window->had_cursor = FALSE;
1386 filer_window->auto_select = NULL;
1387 filer_window->toolbar_text = NULL;
1388 filer_window->target_cb = NULL;
1389 filer_window->mini_type = MINI_NONE;
1390 filer_window->selection_state = GTK_STATE_INSENSITIVE;
1391 filer_window->toolbar = NULL;
1392 filer_window->toplevel_vbox = NULL;
1393 filer_window->view_hbox = NULL;
1394 filer_window->view = NULL;
1395 filer_window->scrollbar = NULL;
1396 filer_window->auto_scroll = -1;
1397 filer_window->window_id = NULL;
1399 tidy_sympath(filer_window->sym_path);
1401 /* Finds the entry for this directory in the dir cache, creating
1402 * a new one if needed. This does not cause a scan to start,
1403 * so if a new entry is created then it will be empty.
1405 filer_window->directory = g_fscache_lookup(dir_cache, real_path);
1406 if (!filer_window->directory)
1408 delayed_error(_("Directory '%s' not found."), path);
1409 g_free(filer_window->real_path);
1410 g_free(filer_window->sym_path);
1411 g_free(filer_window);
1412 return NULL;
1415 filer_window->temp_item_selected = FALSE;
1416 filer_window->flags = (FilerFlags) 0;
1417 filer_window->details_type = DETAILS_TIMES;
1418 filer_window->display_style = UNKNOWN_STYLE;
1419 filer_window->display_style_wanted = UNKNOWN_STYLE;
1420 filer_window->thumb_queue = NULL;
1421 filer_window->max_thumbs = 0;
1422 filer_window->sort_type = -1;
1424 filer_window->filter = FILER_SHOW_ALL;
1425 filer_window->filter_string = NULL;
1426 filer_window->regexp = NULL;
1428 if (src_win && o_display_inherit_options.int_value)
1430 s_type = src_win->sort_type;
1431 s_order = src_win->sort_order;
1432 dstyle = src_win->display_style_wanted;
1433 dtype = src_win->details_type;
1434 filer_window->show_hidden = src_win->show_hidden;
1435 filer_window->show_thumbs = src_win->show_thumbs;
1436 filer_window->view_type = src_win->view_type;
1438 filer_set_filter(filer_window, src_win->filter,
1439 src_win->filter_string);
1441 else
1443 s_type = o_display_sort_by.int_value;
1444 s_order = GTK_SORT_ASCENDING;
1445 dstyle = o_display_size.int_value;
1446 dtype = o_display_details.int_value;
1447 filer_window->show_hidden = o_display_show_hidden.int_value;
1448 filer_window->show_thumbs = o_display_show_thumbs.int_value;
1449 filer_window->view_type = o_filer_view_type.int_value;
1452 dir_settings = (Settings *) g_hash_table_lookup(settings_table,
1453 filer_window->sym_path);
1454 if (dir_settings)
1456 /* Override the current defaults with the per-directory
1457 * user settings.
1459 if (dir_settings->flags & SET_HIDDEN)
1460 filer_window->show_hidden = dir_settings->show_hidden;
1462 if (dir_settings->flags & SET_STYLE)
1463 dstyle = dir_settings->display_style;
1465 if (dir_settings->flags & SET_DETAILS)
1467 dtype = dir_settings->details_type;
1468 filer_window->view_type = dir_settings->view_type;
1471 if (dir_settings->flags & SET_SORT)
1473 s_type = dir_settings->sort_type;
1474 s_order = dir_settings->sort_order;
1477 if (dir_settings->flags & SET_THUMBS)
1478 filer_window->show_thumbs = dir_settings->show_thumbs;
1480 if (dir_settings->flags & SET_FILTER)
1481 filer_set_filter(filer_window,
1482 dir_settings->filter_type,
1483 dir_settings->filter);
1486 /* Add all the user-interface elements & realise */
1487 filer_add_widgets(filer_window, wm_class);
1488 if (src_win)
1489 gtk_window_set_position(GTK_WINDOW(filer_window->window),
1490 GTK_WIN_POS_MOUSE);
1492 if (dir_settings)
1494 if (dir_settings->flags & SET_POSITION)
1496 gtk_window_move(GTK_WINDOW(filer_window->window),
1497 dir_settings->x, dir_settings->y);
1499 if (dir_settings->flags & SET_SIZE)
1501 filer_window_set_size(filer_window,
1502 dir_settings->width,
1503 dir_settings->height);
1504 force_resize = o_filer_auto_resize.int_value != RESIZE_NEVER;
1508 /* Connect to all the signal handlers */
1509 filer_add_signals(filer_window);
1511 display_set_layout(filer_window, dstyle, dtype, force_resize);
1512 display_set_sort_type(filer_window, s_type, s_order);
1514 /* Open the window after a timeout, or when scanning stops.
1515 * Do this before attaching, because attach() might tell us to
1516 * stop scanning (if a scan isn't needed).
1518 filer_window->open_timeout = g_timeout_add(500,
1519 (GSourceFunc) open_filer_window,
1520 filer_window);
1522 /* The view is created empty and then attach() is called, which
1523 * links the filer window to the entry in the directory cache we
1524 * looked up / created above.
1526 * The attach() function will immediately callback to the filer window
1527 * to deliver a list of all known entries in the directory (so,
1528 * the number of items will be known after attach() returns).
1530 * If the directory was not in the cache (because it hadn't been
1531 * opened it before) then the types and icons for the entries are
1532 * not know, but the list of names is.
1535 attach(filer_window);
1537 number_of_windows++;
1538 all_filer_windows = g_list_prepend(all_filer_windows, filer_window);
1540 return filer_window;
1543 void filer_set_view_type(FilerWindow *filer_window, ViewType type)
1545 GtkWidget *view = NULL;
1546 Directory *dir = NULL;
1547 GHashTable *selected = NULL;
1549 g_return_if_fail(filer_window != NULL);
1551 motion_window = NULL;
1553 if (filer_window->view)
1555 /* Save the current selection */
1556 ViewIter iter;
1557 DirItem *item;
1559 selected = g_hash_table_new(g_str_hash, g_str_equal);
1560 view_get_iter(filer_window->view, &iter, VIEW_ITER_SELECTED);
1561 while ((item = iter.next(&iter)))
1562 g_hash_table_insert(selected, item->leafname, "yes");
1564 /* Destroy the old view */
1565 gtk_widget_destroy(GTK_WIDGET(filer_window->view));
1566 filer_window->view = NULL;
1568 dir = filer_window->directory;
1569 g_object_ref(dir);
1570 detach(filer_window);
1573 switch (type)
1575 case VIEW_TYPE_COLLECTION:
1576 view = view_collection_new(filer_window);
1577 break;
1578 case VIEW_TYPE_DETAILS:
1579 view = view_details_new(filer_window);
1580 break;
1583 g_return_if_fail(view != NULL);
1585 filer_window->view = VIEW(view);
1586 filer_window->view_type = type;
1588 gtk_box_pack_start(filer_window->view_hbox, view, TRUE, TRUE, 0);
1589 gtk_widget_show(view);
1591 /* Drag and drop events */
1592 make_drop_target(view, 0);
1593 g_signal_connect(view, "drag_motion",
1594 G_CALLBACK(drag_motion), filer_window);
1595 g_signal_connect(view, "drag_leave",
1596 G_CALLBACK(drag_leave), filer_window);
1597 g_signal_connect(view, "drag_end",
1598 G_CALLBACK(drag_end), filer_window);
1599 /* Dragging from us... */
1600 g_signal_connect(view, "drag_data_get",
1601 GTK_SIGNAL_FUNC(drag_data_get), NULL);
1603 if (dir)
1605 /* Only when changing type. Otherwise, will attach later. */
1606 filer_window->directory = dir;
1607 attach(filer_window);
1609 if (o_filer_auto_resize.int_value != RESIZE_NEVER)
1610 view_autosize(filer_window->view);
1613 if (selected)
1615 ViewIter iter;
1616 DirItem *item;
1618 view_get_iter(filer_window->view, &iter, 0);
1619 while ((item = iter.next(&iter)))
1621 if (g_hash_table_lookup(selected, item->leafname))
1622 view_set_selected(filer_window->view,
1623 &iter, TRUE);
1625 g_hash_table_destroy(selected);
1629 /* This adds all the widgets to a new filer window. It is in a separate
1630 * function because filer_opendir() was getting too long...
1632 static void filer_add_widgets(FilerWindow *filer_window, const gchar *wm_class)
1634 GtkWidget *hbox, *vbox;
1636 /* Create the top-level window widget */
1637 filer_window->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1638 filer_set_title(filer_window);
1639 gtk_widget_set_name(filer_window->window, "rox-filer");
1641 if (wm_class)
1642 gtk_window_set_wmclass(GTK_WINDOW(filer_window->window),
1643 wm_class, PROJECT);
1645 /* This property is cleared when the window is destroyed.
1646 * You can thus ref filer_window->window and use this to see
1647 * if the window no longer exists.
1649 g_object_set_data(G_OBJECT(filer_window->window),
1650 "filer_window", filer_window);
1652 /* Create this now to make the Adjustment before the View */
1653 filer_window->scrollbar = gtk_vscrollbar_new(NULL);
1655 vbox = gtk_vbox_new(FALSE, 0);
1656 gtk_container_add(GTK_CONTAINER(filer_window->window), vbox);
1658 filer_window->toplevel_vbox = GTK_BOX(vbox);
1660 /* If there's a message that should be displayed in each window (eg
1661 * 'Running as root'), add it here.
1663 if (show_user_message)
1665 filer_window->message = gtk_label_new(show_user_message);
1666 gtk_box_pack_start(GTK_BOX(vbox), filer_window->message,
1667 FALSE, TRUE, 0);
1668 gtk_widget_show(filer_window->message);
1671 hbox = gtk_hbox_new(FALSE, 0);
1672 filer_window->view_hbox = GTK_BOX(hbox);
1673 gtk_box_pack_start_defaults(GTK_BOX(vbox), hbox);
1674 /* Add the main View widget */
1675 filer_set_view_type(filer_window, filer_window->view_type);
1676 /* Put the scrollbar next to the View */
1677 gtk_box_pack_end(GTK_BOX(hbox),
1678 filer_window->scrollbar, FALSE, TRUE, 0);
1679 gtk_widget_show(hbox);
1681 /* If we want a toolbar, create it now */
1682 toolbar_update_toolbar(filer_window);
1684 /* And the minibuffer (hidden to start with) */
1685 create_minibuffer(filer_window);
1686 gtk_box_pack_end(GTK_BOX(vbox), filer_window->minibuffer_area,
1687 FALSE, TRUE, 0);
1689 /* And the thumbnail progress bar (also hidden) */
1691 GtkWidget *cancel;
1693 filer_window->thumb_bar = gtk_hbox_new(FALSE, 2);
1694 gtk_box_pack_end(GTK_BOX(vbox), filer_window->thumb_bar,
1695 FALSE, TRUE, 0);
1697 filer_window->thumb_progress = gtk_progress_bar_new();
1699 gtk_box_pack_start(GTK_BOX(filer_window->thumb_bar),
1700 filer_window->thumb_progress, TRUE, TRUE, 0);
1702 cancel = gtk_button_new_with_label(_("Cancel"));
1703 GTK_WIDGET_UNSET_FLAGS(cancel, GTK_CAN_FOCUS);
1704 gtk_box_pack_start(GTK_BOX(filer_window->thumb_bar),
1705 cancel, FALSE, TRUE, 0);
1706 g_signal_connect_swapped(cancel, "clicked",
1707 G_CALLBACK(filer_cancel_thumbnails),
1708 filer_window);
1711 gtk_widget_show(vbox);
1712 gtk_widget_show(filer_window->scrollbar);
1714 gtk_widget_realize(filer_window->window);
1716 gdk_window_set_role(filer_window->window->window,
1717 filer_window->sym_path);
1719 filer_window_set_size(filer_window, 4, 4);
1722 static void filer_add_signals(FilerWindow *filer_window)
1724 GtkTargetEntry target_table[] =
1726 {"text/uri-list", 0, TARGET_URI_LIST},
1727 {"UTF8_STRING", 0, TARGET_STRING},
1728 {"STRING", 0, TARGET_STRING},
1729 {"COMPOUND_TEXT", 0, TARGET_STRING},/* XXX: Treats as STRING */
1732 /* Events on the top-level window */
1733 gtk_widget_add_events(filer_window->window, GDK_ENTER_NOTIFY);
1734 g_signal_connect(filer_window->window, "enter-notify-event",
1735 G_CALLBACK(pointer_in), filer_window);
1736 g_signal_connect(filer_window->window, "leave-notify-event",
1737 G_CALLBACK(pointer_out), filer_window);
1738 g_signal_connect(filer_window->window, "destroy",
1739 G_CALLBACK(filer_window_destroyed), filer_window);
1740 g_signal_connect(filer_window->window, "delete-event",
1741 G_CALLBACK(filer_window_delete), filer_window);
1743 g_signal_connect(filer_window->window, "selection_clear_event",
1744 G_CALLBACK(filer_lost_primary), filer_window);
1746 g_signal_connect(filer_window->window, "selection_get",
1747 G_CALLBACK(selection_get), filer_window);
1748 gtk_selection_add_targets(GTK_WIDGET(filer_window->window),
1749 GDK_SELECTION_PRIMARY,
1750 target_table,
1751 sizeof(target_table) / sizeof(*target_table));
1753 g_signal_connect(filer_window->window, "popup-menu",
1754 G_CALLBACK(popup_menu), filer_window);
1755 g_signal_connect(filer_window->window, "key_press_event",
1756 G_CALLBACK(filer_key_press_event), filer_window);
1758 gtk_window_add_accel_group(GTK_WINDOW(filer_window->window),
1759 filer_keys);
1762 static gint clear_scanning_display(FilerWindow *filer_window)
1764 if (filer_exists(filer_window))
1765 filer_set_title(filer_window);
1766 return FALSE;
1769 static void set_scanning_display(FilerWindow *filer_window, gboolean scanning)
1771 if (scanning == filer_window->scanning)
1772 return;
1773 filer_window->scanning = scanning;
1775 if (scanning)
1776 filer_set_title(filer_window);
1777 else
1778 g_timeout_add(300, (GSourceFunc) clear_scanning_display,
1779 filer_window);
1782 /* Note that filer_window may not exist after this call.
1783 * Returns TRUE iff the directory still exists.
1785 gboolean filer_update_dir(FilerWindow *filer_window, gboolean warning)
1787 gboolean still_exists;
1789 still_exists = may_rescan(filer_window, warning);
1791 if (still_exists)
1792 dir_update(filer_window->directory, filer_window->sym_path);
1794 return still_exists;
1797 void filer_update_all(void)
1799 GList *next = all_filer_windows;
1801 while (next)
1803 FilerWindow *filer_window = (FilerWindow *) next->data;
1805 /* Updating directory may remove it from list -- stop sending
1806 * patches to move this line!
1808 next = next->next;
1810 /* Don't trigger a refresh if we're already scanning.
1811 * Otherwise, two views of a single directory will trigger
1812 * two scans.
1814 if (filer_window->directory &&
1815 !filer_window->directory->scanning)
1816 filer_update_dir(filer_window, TRUE);
1820 /* Refresh the various caches even if we don't think we need to */
1821 void full_refresh(void)
1823 mount_update(TRUE);
1824 reread_mime_files(); /* Refreshes all windows */
1827 /* See whether a filer window with a given path already exists
1828 * and is different from diff.
1830 static FilerWindow *find_filer_window(const char *sym_path, FilerWindow *diff)
1832 GList *next;
1834 for (next = all_filer_windows; next; next = next->next)
1836 FilerWindow *filer_window = (FilerWindow *) next->data;
1838 if (filer_window != diff &&
1839 strcmp(sym_path, filer_window->sym_path) == 0)
1840 return filer_window;
1843 return NULL;
1846 /* This path has been mounted/umounted/deleted some files - update all dirs */
1847 void filer_check_mounted(const char *real_path)
1849 GList *next = all_filer_windows;
1850 gchar *parent;
1851 int len;
1852 gboolean resize = o_filer_auto_resize.int_value == RESIZE_ALWAYS;
1854 /* DOS disks, etc, often don't change the mtime of the root directory
1855 * on modification, so force a refresh now.
1857 g_fscache_update(dir_cache, real_path);
1859 len = strlen(real_path);
1861 while (next)
1863 FilerWindow *filer_window = (FilerWindow *) next->data;
1865 next = next->next;
1867 if (strncmp(real_path, filer_window->real_path, len) == 0)
1869 char s = filer_window->real_path[len];
1871 if (s == '/' || s == '\0')
1873 if (filer_update_dir(filer_window, FALSE) &&
1874 resize)
1875 view_autosize(filer_window->view);
1880 parent = g_path_get_dirname(real_path);
1881 refresh_dirs(parent);
1882 g_free(parent);
1884 icons_may_update(real_path);
1887 /* Close all windows displaying 'path' or subdirectories of 'path' */
1888 void filer_close_recursive(const char *path)
1890 GList *next = all_filer_windows;
1891 gchar *real;
1892 int len;
1894 real = pathdup(path);
1895 len = strlen(real);
1897 while (next)
1899 FilerWindow *filer_window = (FilerWindow *) next->data;
1901 next = next->next;
1903 if (strncmp(real, filer_window->real_path, len) == 0)
1905 char s = filer_window->real_path[len];
1907 if (len == 1 || s == '/' || s == '\0')
1908 gtk_widget_destroy(filer_window->window);
1913 /* Like minibuffer_show(), except that:
1914 * - It returns FALSE (to be used from an idle callback)
1915 * - It checks that the filer window still exists.
1917 static gboolean minibuffer_show_cb(FilerWindow *filer_window)
1919 if (filer_exists(filer_window))
1920 minibuffer_show(filer_window, MINI_PATH);
1921 return FALSE;
1924 /* TRUE iff filer_window points to an existing FilerWindow
1925 * structure.
1927 gboolean filer_exists(FilerWindow *filer_window)
1929 GList *next;
1931 for (next = all_filer_windows; next; next = next->next)
1933 FilerWindow *fw = (FilerWindow *) next->data;
1935 if (fw == filer_window)
1936 return TRUE;
1939 return FALSE;
1942 FilerWindow *filer_get_by_id(const char *id)
1944 return g_hash_table_lookup(window_with_id, id);
1947 void filer_set_id(FilerWindow *filer_window, const char *id)
1949 g_return_if_fail(filer_window != NULL);
1951 if (filer_window->window_id)
1953 g_hash_table_remove(window_with_id, filer_window->window_id);
1954 g_free(filer_window->window_id);
1955 filer_window->window_id = NULL;
1958 if (id)
1960 filer_window->window_id = g_strdup(id);
1961 g_hash_table_insert(window_with_id,
1962 filer_window->window_id,
1963 filer_window);
1967 /* Make sure the window title is up-to-date */
1968 void filer_set_title(FilerWindow *filer_window)
1970 gchar *title = NULL;
1971 guchar *flags = "";
1972 gchar *hidden = "";
1974 if (filer_window->scanning ||
1975 filer_window->filter != FILER_SHOW_ALL ||
1976 filer_window->show_hidden || filer_window->show_thumbs)
1978 if (o_short_flag_names.int_value)
1981 switch(filer_window->filter) {
1982 case FILER_SHOW_ALL:
1983 hidden=filer_window->show_hidden? "A": "";
1984 break;
1985 case FILER_SHOW_GLOB: hidden="G"; break;
1986 case FILER_SHOW_REGEXP: hidden="R"; break;
1987 default: break;
1990 flags = g_strconcat(" +",
1991 filer_window->scanning ? _("S") : "",
1992 hidden,
1993 filer_window->show_thumbs ? _("T") : "",
1994 NULL);
1996 else
1998 switch(filer_window->filter) {
1999 case FILER_SHOW_ALL:
2000 hidden=g_strdup(filer_window->show_hidden? "All, ": "");
2001 break;
2002 case FILER_SHOW_GLOB:
2003 hidden=g_strdup_printf("Glob (%s), ",
2004 filer_window->filter_string);
2005 break;
2006 case FILER_SHOW_REGEXP:
2007 hidden=g_strdup_printf("Regexp (%s), ",
2008 filer_window->filter_string);
2009 break;
2010 default:
2011 hidden=g_strdup("");
2012 break;
2014 flags = g_strconcat(" (",
2015 filer_window->scanning ? _("Scanning, ") : "",
2016 hidden,
2017 filer_window->show_thumbs ? _("Thumbs, ") : "",
2018 NULL);
2019 flags[strlen(flags) - 2] = ')';
2020 g_free(hidden);
2024 if (not_local)
2025 title = g_strconcat("//", our_host_name(),
2026 filer_window->sym_path, flags, NULL);
2028 if (!title && home_dir_len > 1 &&
2029 strncmp(filer_window->sym_path, home_dir, home_dir_len) == 0)
2031 guchar sep = filer_window->sym_path[home_dir_len];
2033 if (sep == '\0' || sep == '/')
2034 title = g_strconcat("~",
2035 filer_window->sym_path + home_dir_len,
2036 flags,
2037 NULL);
2040 if (!title)
2041 title = g_strconcat(filer_window->sym_path, flags, NULL);
2043 ensure_utf8(&title);
2045 if (filer_window->directory->error)
2047 gchar *old = title;
2048 title = g_strconcat(old, ": ", filer_window->directory->error,
2049 NULL);
2050 g_free(old);
2053 gtk_window_set_title(GTK_WINDOW(filer_window->window), title);
2055 g_free(title);
2057 if (flags[0] != '\0')
2058 g_free(flags);
2061 /* Reconnect to the same directory (used when the Show Hidden option is
2062 * toggled). This has the side-effect of updating the window title.
2064 void filer_detach_rescan(FilerWindow *filer_window)
2066 Directory *dir = filer_window->directory;
2068 g_object_ref(dir);
2069 detach(filer_window);
2070 filer_window->directory = dir;
2071 attach(filer_window);
2074 /* Puts the filer window into target mode. When an item is chosen,
2075 * fn(filer_window, iter, data) is called. 'reason' will be displayed
2076 * on the toolbar while target mode is active.
2078 * Use fn == NULL to cancel target mode.
2080 void filer_target_mode(FilerWindow *filer_window,
2081 TargetFunc fn,
2082 gpointer data,
2083 const char *reason)
2085 TargetFunc old_fn = filer_window->target_cb;
2087 if (fn != old_fn)
2088 gdk_window_set_cursor(
2089 GTK_WIDGET(filer_window->view)->window,
2090 fn ? crosshair : NULL);
2092 filer_window->target_cb = fn;
2093 filer_window->target_data = data;
2095 if (filer_window->toolbar_text == NULL)
2096 return;
2098 if (fn)
2099 gtk_label_set_text(
2100 GTK_LABEL(filer_window->toolbar_text), reason);
2101 else if (o_toolbar_info.int_value)
2103 if (old_fn)
2104 toolbar_update_info(filer_window);
2106 else
2107 gtk_label_set_text(GTK_LABEL(filer_window->toolbar_text), "");
2110 static void set_selection_state(FilerWindow *filer_window, gboolean normal)
2112 GtkStateType old_state = filer_window->selection_state;
2114 filer_window->selection_state = normal
2115 ? GTK_STATE_SELECTED : GTK_STATE_INSENSITIVE;
2117 if (old_state != filer_window->selection_state
2118 && view_count_selected(filer_window->view))
2119 gtk_widget_queue_draw(GTK_WIDGET(filer_window->view));
2122 void filer_cancel_thumbnails(FilerWindow *filer_window)
2124 gtk_widget_hide(filer_window->thumb_bar);
2126 destroy_glist(&filer_window->thumb_queue);
2127 filer_window->max_thumbs = 0;
2130 /* Generate the next thumb for this window. The window object is
2131 * unref'd when there is nothing more to do.
2132 * If the window no longer has a filer window, nothing is done.
2134 static gboolean filer_next_thumb_real(GObject *window)
2136 FilerWindow *filer_window;
2137 gchar *path;
2138 int done, total;
2140 filer_window = g_object_get_data(window, "filer_window");
2142 if (!filer_window)
2144 g_object_unref(window);
2145 return FALSE;
2148 if (!filer_window->thumb_queue)
2150 filer_cancel_thumbnails(filer_window);
2151 g_object_unref(window);
2152 return FALSE;
2155 total = filer_window->max_thumbs;
2156 done = total - g_list_length(filer_window->thumb_queue);
2158 path = (gchar *) filer_window->thumb_queue->data;
2160 pixmap_background_thumb(path, (GFunc) filer_next_thumb, window);
2162 filer_window->thumb_queue = g_list_remove(filer_window->thumb_queue,
2163 path);
2164 g_free(path);
2166 gtk_progress_bar_set_fraction(
2167 GTK_PROGRESS_BAR(filer_window->thumb_progress),
2168 done / (float) total);
2170 return FALSE;
2173 /* path is the thumb just loaded, if any.
2174 * window is unref'd (eventually).
2176 static void filer_next_thumb(GObject *window, const gchar *path)
2178 if (path)
2179 dir_force_update_path(path);
2181 g_idle_add((GSourceFunc) filer_next_thumb_real, window);
2184 static void start_thumb_scanning(FilerWindow *filer_window)
2186 if (GTK_WIDGET_VISIBLE(filer_window->thumb_bar))
2187 return; /* Already scanning */
2189 gtk_widget_show_all(filer_window->thumb_bar);
2191 g_object_ref(G_OBJECT(filer_window->window));
2192 filer_next_thumb(G_OBJECT(filer_window->window), NULL);
2195 /* Set this image to be loaded some time in the future */
2196 void filer_create_thumb(FilerWindow *filer_window, const gchar *path)
2198 if (g_list_find_custom(filer_window->thumb_queue, path,
2199 (GCompareFunc) strcmp))
2200 return;
2202 if (!filer_window->thumb_queue)
2203 filer_window->max_thumbs=0;
2204 filer_window->max_thumbs++;
2206 filer_window->thumb_queue = g_list_append(filer_window->thumb_queue,
2207 g_strdup(path));
2209 if (filer_window->scanning)
2210 return; /* Will start when scan ends */
2212 start_thumb_scanning(filer_window);
2215 /* If thumbnail display is on, look through all the items in this directory
2216 * and start creating or updating the thumbnails as needed.
2218 void filer_create_thumbs(FilerWindow *filer_window)
2220 DirItem *item;
2221 ViewIter iter;
2223 if (!filer_window->show_thumbs)
2224 return;
2226 view_get_iter(filer_window->view, &iter, 0);
2228 while ((item = iter.next(&iter)))
2230 MaskedPixmap *pixmap;
2231 const guchar *path;
2232 gboolean found;
2234 if (item->base_type != TYPE_FILE)
2235 continue;
2237 /*if (strcmp(item->mime_type->media_type, "image") != 0)
2238 continue;*/
2240 path = make_path(filer_window->real_path, item->leafname);
2242 pixmap = g_fscache_lookup_full(pixmap_cache, path,
2243 FSCACHE_LOOKUP_ONLY_NEW, &found);
2244 if (pixmap)
2245 g_object_unref(pixmap);
2247 /* If we didn't get an image, it could be because:
2249 * - We're loading the image now. found is TRUE,
2250 * and we'll update the item later.
2251 * - We tried to load the image and failed. found
2252 * is TRUE.
2253 * - We haven't tried loading the image. found is
2254 * FALSE, and we start creating the thumb here.
2256 if (!found)
2257 filer_create_thumb(filer_window, path);
2261 static void filer_options_changed(void)
2263 if (o_short_flag_names.has_changed)
2265 GList *next;
2267 for (next = all_filer_windows; next; next = next->next)
2269 FilerWindow *filer_window = (FilerWindow *) next->data;
2271 filer_set_title(filer_window);
2276 /* Append interesting information to this GString */
2277 void filer_add_tip_details(FilerWindow *filer_window,
2278 GString *tip, DirItem *item)
2280 const guchar *fullpath = NULL;
2282 fullpath = make_path(filer_window->real_path, item->leafname);
2284 if (item->flags & ITEM_FLAG_SYMLINK)
2286 char *target;
2288 target = readlink_dup(fullpath);
2289 if (target)
2291 ensure_utf8(&target);
2293 g_string_append(tip, _("Symbolic link to "));
2294 g_string_append(tip, target);
2295 g_string_append_c(tip, '\n');
2296 g_free(target);
2300 if (item->flags & ITEM_FLAG_APPDIR)
2302 XMLwrapper *info;
2303 xmlNode *node;
2305 info = appinfo_get(fullpath, item);
2306 if (info && ((node = xml_get_section(info, NULL, "Summary"))))
2308 guchar *str;
2309 str = xmlNodeListGetString(node->doc,
2310 node->xmlChildrenNode, 1);
2311 if (str)
2313 g_string_append(tip, str);
2314 g_string_append_c(tip, '\n');
2315 g_free(str);
2318 if (info)
2319 g_object_unref(info);
2322 if (!g_utf8_validate(item->leafname, -1, NULL))
2323 g_string_append(tip,
2324 _("This filename is not valid UTF-8. "
2325 "You should rename it.\n"));
2328 /* Return the selection as a text/uri-list.
2329 * g_free() the result.
2331 static guchar *filer_create_uri_list(FilerWindow *filer_window)
2333 GString *string;
2334 GString *leader;
2335 ViewIter iter;
2336 DirItem *item;
2337 guchar *retval;
2339 g_return_val_if_fail(filer_window != NULL, NULL);
2341 string = g_string_new(NULL);
2343 leader = g_string_new(filer_window->sym_path);
2344 if (leader->str[leader->len - 1] != '/')
2345 g_string_append_c(leader, '/');
2347 view_get_iter(filer_window->view, &iter, VIEW_ITER_SELECTED);
2348 while ((item = iter.next(&iter)))
2350 EscapedPath *uri;
2351 char *path;
2353 path = g_strconcat(leader->str, item->leafname, NULL);
2354 uri = encode_path_as_uri(path);
2355 g_string_append(string, (char *) uri);
2356 g_string_append(string, "\r\n");
2357 g_free(path);
2358 g_free(uri);
2361 g_string_free(leader, TRUE);
2362 retval = string->str;
2363 g_string_free(string, FALSE);
2365 return retval;
2368 void filer_perform_action(FilerWindow *filer_window, GdkEventButton *event)
2370 BindAction action;
2371 ViewIface *view = filer_window->view;
2372 DirItem *item = NULL;
2373 gboolean press = event->type == GDK_BUTTON_PRESS;
2374 ViewIter iter;
2375 OpenFlags flags = 0;
2377 if (event->button > 3)
2378 return;
2380 view_get_iter_at_point(view, &iter, event->window, event->x, event->y);
2381 item = iter.peek(&iter);
2383 if (item && event->button == 1 &&
2384 view_get_selected(view, &iter) &&
2385 filer_window->selection_state == GTK_STATE_INSENSITIVE)
2387 /* Possibly a really slow DnD operation? */
2388 filer_window->temp_item_selected = FALSE;
2390 filer_selection_changed(filer_window, event->time);
2391 return;
2394 if (filer_window->target_cb)
2396 dnd_motion_ungrab();
2397 if (item && press && event->button == 1)
2398 filer_window->target_cb(filer_window, &iter,
2399 filer_window->target_data);
2401 filer_target_mode(filer_window, NULL, NULL, NULL);
2403 return;
2406 if (!o_single_click.int_value)
2408 /* Make sure both parts of a double-click fall on
2409 * the same file.
2411 static guchar *first_click = NULL;
2412 static guchar *second_click = NULL;
2414 if (event->type == GDK_BUTTON_PRESS)
2416 g_free(first_click);
2417 first_click = second_click;
2419 if (item)
2420 second_click = g_strdup(item->leafname);
2421 else
2422 second_click = NULL;
2425 if (event->type == GDK_2BUTTON_PRESS)
2427 if (first_click && second_click &&
2428 strcmp(first_click, second_click) != 0)
2429 return;
2430 if ((first_click || second_click) &&
2431 !(first_click && second_click))
2432 return;
2436 action = bind_lookup_bev(
2437 item ? BIND_DIRECTORY_ICON : BIND_DIRECTORY,
2438 event);
2440 switch (action)
2442 case ACT_CLEAR_SELECTION:
2443 view_clear_selection(view);
2444 break;
2445 case ACT_TOGGLE_SELECTED:
2446 view_set_selected(view, &iter,
2447 !view_get_selected(view, &iter));
2448 break;
2449 case ACT_SELECT_EXCL:
2450 view_select_only(view, &iter);
2451 break;
2452 case ACT_EDIT_ITEM:
2453 flags |= OPEN_SHIFT;
2454 /* (no break) */
2455 case ACT_OPEN_ITEM:
2456 if (event->button != 1 || event->state & GDK_MOD1_MASK)
2457 flags |= OPEN_CLOSE_WINDOW;
2458 else
2459 flags |= OPEN_SAME_WINDOW;
2460 if (o_new_button_1.int_value)
2461 flags ^= OPEN_SAME_WINDOW;
2462 if (event->type == GDK_2BUTTON_PRESS)
2463 view_set_selected(view, &iter, FALSE);
2464 dnd_motion_ungrab();
2466 filer_openitem(filer_window, &iter, flags);
2467 break;
2468 case ACT_POPUP_MENU:
2469 dnd_motion_ungrab();
2470 tooltip_show(NULL);
2471 show_filer_menu(filer_window,
2472 (GdkEvent *) event, &iter);
2473 break;
2474 case ACT_PRIME_AND_SELECT:
2475 if (item && !view_get_selected(view, &iter))
2476 view_select_only(view, &iter);
2477 dnd_motion_start(MOTION_READY_FOR_DND);
2478 break;
2479 case ACT_PRIME_AND_TOGGLE:
2480 view_set_selected(view, &iter,
2481 !view_get_selected(view, &iter));
2482 dnd_motion_start(MOTION_READY_FOR_DND);
2483 break;
2484 case ACT_PRIME_FOR_DND:
2485 dnd_motion_start(MOTION_READY_FOR_DND);
2486 break;
2487 case ACT_IGNORE:
2488 if (press && event->button < 4)
2490 if (item)
2491 view_wink_item(view, &iter);
2492 dnd_motion_start(MOTION_NONE);
2494 break;
2495 case ACT_LASSO_CLEAR:
2496 view_clear_selection(view);
2497 /* (no break) */
2498 case ACT_LASSO_MODIFY:
2499 view_start_lasso_box(view, event);
2500 break;
2501 case ACT_RESIZE:
2502 view_autosize(filer_window->view);
2503 break;
2504 default:
2505 g_warning("Unsupported action : %d\n", action);
2506 break;
2510 /* It's time to make the tooltip appear. If we're not over the item any
2511 * more, or the item doesn't need a tooltip, do nothing.
2513 static gboolean tooltip_activate(GtkWidget *window)
2515 FilerWindow *filer_window;
2516 ViewIface *view;
2517 ViewIter iter;
2518 gint x, y;
2519 DirItem *item = NULL;
2520 GString *tip = NULL;
2522 g_return_val_if_fail(tip_item != NULL, 0);
2524 filer_window = g_object_get_data(G_OBJECT(window), "filer_window");
2526 if (!motion_window || !filer_window)
2527 return FALSE; /* Window has been destroyed */
2529 view = filer_window->view;
2531 tooltip_show(NULL);
2533 gdk_window_get_pointer(motion_window, &x, &y, NULL);
2534 view_get_iter_at_point(view, &iter, motion_window, x, y);
2536 item = iter.peek(&iter);
2537 if (item != tip_item)
2538 return FALSE; /* Not still under the pointer */
2540 /* OK, the filer window still exists and the pointer is still
2541 * over the same item. Do we need to show a tip?
2544 tip = g_string_new(NULL);
2546 view_extend_tip(filer_window->view, &iter, tip);
2548 filer_add_tip_details(filer_window, tip, tip_item);
2550 if (tip->len > 1)
2552 g_string_truncate(tip, tip->len - 1);
2554 tooltip_show(tip->str);
2557 g_string_free(tip, TRUE);
2559 return FALSE;
2562 /* Motion detected on the View widget */
2563 gint filer_motion_notify(FilerWindow *filer_window, GdkEventMotion *event)
2565 ViewIface *view = filer_window->view;
2566 ViewIter iter;
2567 DirItem *item;
2569 view_get_iter_at_point(view, &iter, event->window, event->x, event->y);
2570 item = iter.peek(&iter);
2572 if (item)
2574 if (item != tip_item)
2576 tooltip_show(NULL);
2578 tip_item = item;
2579 motion_window = event->window;
2580 tooltip_prime((GtkFunction) tooltip_activate,
2581 G_OBJECT(filer_window->window));
2584 else
2586 tooltip_show(NULL);
2587 tip_item = NULL;
2590 if (motion_state != MOTION_READY_FOR_DND)
2591 return FALSE;
2593 if (!dnd_motion_moved(event))
2594 return FALSE;
2596 view_get_iter_at_point(view, &iter,
2597 event->window,
2598 event->x - (event->x_root - drag_start_x),
2599 event->y - (event->y_root - drag_start_y));
2600 item = iter.peek(&iter);
2601 if (!item)
2602 return FALSE;
2604 view_wink_item(view, NULL);
2606 if (!view_get_selected(view, &iter))
2608 if (event->state & GDK_BUTTON1_MASK)
2610 /* Select just this one */
2611 filer_window->temp_item_selected = TRUE;
2612 view_select_only(view, &iter);
2614 else
2616 if (view_count_selected(view) == 0)
2617 filer_window->temp_item_selected = TRUE;
2618 view_set_selected(view, &iter, TRUE);
2622 g_return_val_if_fail(view_count_selected(view) > 0, TRUE);
2624 if (view_count_selected(view) == 1)
2626 if (item->base_type == TYPE_UNKNOWN)
2627 item = dir_update_item(filer_window->directory,
2628 item->leafname);
2630 if (!item)
2632 report_error(_("Item no longer exists!"));
2633 return FALSE;
2636 drag_one_item(GTK_WIDGET(view), event,
2637 make_path(filer_window->sym_path, item->leafname),
2638 item, di_image(item));
2639 #if 0
2640 /* XXX: Use thumbnail */
2641 item, view ? view->image : NULL);
2642 #endif
2644 else
2646 guchar *uris;
2648 uris = filer_create_uri_list(filer_window);
2649 drag_selection(GTK_WIDGET(view), event, uris);
2650 g_free(uris);
2653 return FALSE;
2656 static void drag_end(GtkWidget *widget, GdkDragContext *context,
2657 FilerWindow *filer_window)
2659 filer_set_autoscroll(filer_window, FALSE);
2661 if (filer_window->temp_item_selected)
2663 view_clear_selection(filer_window->view);
2664 filer_window->temp_item_selected = FALSE;
2668 /* Remove highlights */
2669 static void drag_leave(GtkWidget *widget,
2670 GdkDragContext *context,
2671 guint32 time,
2672 FilerWindow *filer_window)
2674 dnd_spring_abort();
2677 /* Called during the drag when the mouse is in a widget registered
2678 * as a drop target. Returns TRUE if we can accept the drop.
2680 static gboolean drag_motion(GtkWidget *widget,
2681 GdkDragContext *context,
2682 gint x,
2683 gint y,
2684 guint time,
2685 FilerWindow *filer_window)
2687 DirItem *item;
2688 ViewIface *view = filer_window->view;
2689 ViewIter iter;
2690 GdkDragAction action = context->suggested_action;
2691 const guchar *new_path = NULL;
2692 const char *type = NULL;
2693 gboolean retval = FALSE;
2694 gboolean same_window;
2696 if ((context->actions & GDK_ACTION_ASK) && o_dnd_left_menu.int_value)
2698 guint state;
2699 gdk_window_get_pointer(NULL, NULL, NULL, &state);
2700 if (state & GDK_BUTTON1_MASK)
2701 action = GDK_ACTION_ASK;
2704 same_window = gtk_drag_get_source_widget(context) == widget;
2706 filer_set_autoscroll(filer_window, TRUE);
2708 if (filer_window->view_type == VIEW_TYPE_DETAILS)
2710 GdkWindow *bin;
2711 int bin_y;
2712 /* Correct for position of bin window */
2713 bin = gtk_tree_view_get_bin_window(GTK_TREE_VIEW(view));
2714 gdk_window_get_position(bin, NULL, &bin_y);
2715 y -= bin_y;
2718 if (o_dnd_drag_to_icons.int_value)
2720 view_get_iter_at_point(view, &iter, widget->window, x, y);
2721 item = iter.peek(&iter);
2723 else
2724 item = NULL;
2726 if (item && same_window && view_get_selected(view, &iter))
2727 type = NULL;
2728 else
2729 type = dnd_motion_item(context, &item);
2731 if (!type)
2732 item = NULL;
2734 /* Don't allow drops to non-writeable directories. BUT, still
2735 * allow drops on non-writeable SUBdirectories so that we can
2736 * do the spring-open thing.
2738 if (item && type == drop_dest_dir &&
2739 !(item->flags & ITEM_FLAG_APPDIR))
2741 dnd_spring_load(context, filer_window);
2743 else
2744 dnd_spring_abort();
2746 if (item)
2747 view_cursor_to_iter(view, &iter);
2748 else
2750 view_cursor_to_iter(view, NULL);
2752 /* Disallow background drops within a single window */
2753 if (type && same_window)
2754 type = NULL;
2757 if (type)
2759 if (item)
2760 new_path = make_path(filer_window->sym_path,
2761 item->leafname);
2762 else
2763 new_path = filer_window->sym_path;
2766 /* Don't ask about dragging to an application! */
2767 if (type == drop_dest_prog && action == GDK_ACTION_ASK)
2768 action = GDK_ACTION_COPY;
2770 g_dataset_set_data(context, "drop_dest_type", (gpointer) type);
2771 if (type)
2773 gdk_drag_status(context, action, time);
2774 g_dataset_set_data_full(context, "drop_dest_path",
2775 g_strdup(new_path), g_free);
2776 retval = TRUE;
2779 return retval;
2782 static gboolean as_timeout(FilerWindow *filer_window)
2784 gboolean retval;
2786 retval = view_auto_scroll_callback(filer_window->view);
2788 if (!retval)
2789 filer_window->auto_scroll = -1;
2791 return retval;
2794 /* When autoscroll is on, a timer keeps track of the pointer position.
2795 * While it's near the top or bottom of the window, the window scrolls.
2797 * If the mouse buttons are released, the pointer leaves the window, or
2798 * a drag-and-drop operation finishes, auto_scroll is turned off.
2800 void filer_set_autoscroll(FilerWindow *filer_window, gboolean auto_scroll)
2802 g_return_if_fail(filer_window != NULL);
2804 if (auto_scroll)
2806 if (filer_window->auto_scroll != -1)
2807 return; /* Already on! */
2809 filer_window->auto_scroll = g_timeout_add(50,
2810 (GSourceFunc) as_timeout,
2811 filer_window);
2813 else
2815 if (filer_window->auto_scroll == -1)
2816 return; /* Already off! */
2818 g_source_remove(filer_window->auto_scroll);
2819 filer_window->auto_scroll = -1;
2823 #define ZERO_MNT "/uri/0install"
2825 static void refresh_done(FilerWindow *filer_window)
2827 if (filer_exists(filer_window))
2828 filer_update_dir(filer_window, TRUE);
2831 void filer_refresh(FilerWindow *filer_window)
2833 if (!strncmp(ZERO_MNT "/", filer_window->real_path, sizeof(ZERO_MNT)))
2835 /* Try to run 0refresh */
2836 gint pid;
2837 gchar *argv[] = {"0refresh", NULL, NULL};
2838 const char *host = filer_window->real_path + sizeof(ZERO_MNT);
2839 const char *slash;
2841 slash = strchr(host, '/');
2842 if (slash)
2843 argv[1] = g_strndup(host, slash - host);
2844 else
2845 argv[1] = g_strdup(host);
2846 pid = rox_spawn(filer_window->real_path, (const char **) argv);
2847 g_free(argv[1]);
2848 if (pid)
2849 on_child_death(pid, (CallbackFn) refresh_done,
2850 filer_window);
2853 full_refresh();
2856 gboolean filer_match_filter(FilerWindow *filer_window, const gchar *filename)
2858 g_return_val_if_fail(filename != NULL, FALSE);
2860 if(filename[0]=='.' &&
2861 (!filer_window->temp_show_hidden && !filer_window->show_hidden))
2862 return FALSE;
2864 switch(filer_window->filter) {
2865 case FILER_SHOW_GLOB:
2866 return fnmatch(filer_window->filter_string,
2867 filename, 0)==0;
2869 case FILER_SHOW_REGEXP: /* Unimplemented */
2871 case FILER_SHOW_ALL:
2872 default:
2873 break;
2875 return TRUE;
2878 /* Provided to hide the implementation */
2879 void filer_set_hidden(FilerWindow *filer_window, gboolean hidden)
2881 filer_window->show_hidden=hidden;
2884 /* Set the filter type. Returns TRUE if the type has changed
2885 * (must call filer_detach_rescan).
2887 gboolean filer_set_filter(FilerWindow *filer_window, FilterType type,
2888 const gchar *filter_string)
2890 /* Is this new filter the same as the old one? */
2891 if (filer_window->filter == type)
2893 switch(filer_window->filter)
2895 case FILER_SHOW_ALL:
2896 return FALSE;
2897 case FILER_SHOW_GLOB:
2898 case FILER_SHOW_REGEXP:
2899 if (strcmp(filer_window->filter_string,
2900 filter_string) == 0)
2901 return FALSE;
2902 break;
2906 /* Clean up old filter */
2907 if (filer_window->filter_string)
2909 g_free(filer_window->filter_string);
2910 filer_window->filter_string = NULL;
2912 /* Also clean up compiled regexp when implemented */
2914 filer_window->filter = type;
2916 switch(type)
2918 case FILER_SHOW_ALL:
2919 /* No extra work */
2920 break;
2922 case FILER_SHOW_GLOB:
2923 filer_window->filter_string = g_strdup(filter_string);
2924 break;
2926 case FILER_SHOW_REGEXP:
2927 filer_window->filter_string = g_strdup(filter_string);
2928 /* Compile the pattern */
2929 break;
2931 default:
2932 /* oops */
2933 filer_window->filter = FILER_SHOW_ALL;
2934 g_warning("Impossible: filter type %d", type);
2935 break;
2938 return TRUE;
2941 /* Setting stuff */
2942 static Settings *settings_new(const char *path)
2944 Settings *set;
2946 set=g_new(Settings, 1);
2947 memset(set, 0, sizeof(Settings));
2948 if(path)
2949 set->path=g_strdup(path);
2951 return set;
2954 static void settings_free(Settings *set)
2956 g_free(set->path);
2957 if(set->filter)
2958 g_free(set->filter);
2959 g_free(set);
2962 static void store_settings(Settings *set)
2964 Settings *old;
2966 old=g_hash_table_lookup(settings_table, set->path);
2967 if(old)
2969 g_hash_table_remove(settings_table, set->path);
2970 settings_free(old);
2973 g_hash_table_insert(settings_table, set->path, set);
2976 /* TODO: use symbolic names in the XML file where possible */
2977 static void load_from_node(Settings *set, xmlDocPtr doc, xmlNodePtr node)
2979 xmlChar *str=NULL;
2981 str=xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
2983 if(strcmp(node->name, "X") == 0) {
2984 set->x=atoi(str);
2985 set->flags|=SET_POSITION;
2986 } else if(strcmp(node->name, "Y") == 0) {
2987 set->y=atoi(str);
2988 set->flags|=SET_POSITION;
2989 } else if(strcmp(node->name, "Width") == 0) {
2990 set->width=atoi(str);
2991 set->flags|=SET_SIZE;
2992 } else if(strcmp(node->name, "Height") == 0) {
2993 set->height=atoi(str);
2994 set->flags|=SET_SIZE;
2995 } else if(strcmp(node->name, "ShowHidden") == 0) {
2996 set->show_hidden=atoi(str);
2997 set->flags|=SET_HIDDEN;
2998 } else if(strcmp(node->name, "ViewType") == 0) {
2999 set->view_type=atoi(str);
3000 set->flags|=SET_DETAILS;
3001 } else if(strcmp(node->name, "DetailsType") == 0) {
3002 set->details_type=atoi(str);
3003 set->flags|=SET_DETAILS;
3004 } else if(strcmp(node->name, "SortType") == 0) {
3005 set->sort_type=atoi(str);
3006 set->flags|=SET_SORT;
3007 } else if(strcmp(node->name, "SortOrder") == 0) {
3008 set->sort_order=atoi(str);
3009 set->flags|=SET_SORT;
3010 } else if(strcmp(node->name, "DisplayStyle") == 0) {
3011 set->display_style=atoi(str);
3012 set->flags|=SET_STYLE;
3013 } else if(strcmp(node->name, "ShowThumbs") == 0) {
3014 set->show_thumbs=atoi(str);
3015 set->flags|=SET_THUMBS;
3016 } else if(strcmp(node->name, "FilterType") == 0) {
3017 set->filter_type=atoi(str);
3018 set->flags|=SET_FILTER;
3019 } else if(strcmp(node->name, "Filter") == 0) {
3020 set->filter=g_strdup(str);
3021 set->flags|=SET_FILTER;
3024 if(str)
3025 xmlFree(str);
3028 static void load_settings(void)
3030 gchar *path;
3031 XMLwrapper *settings_doc=NULL;
3033 path=choices_find_xdg_path_load("Settings.xml", PROJECT, SITE);
3034 if(path) {
3035 settings_doc=xml_new(path);
3036 g_free(path);
3039 if(!settings_table)
3040 settings_table=g_hash_table_new(g_str_hash, g_str_equal);
3042 if(settings_doc) {
3043 xmlNodePtr node, subnode;
3045 node = xmlDocGetRootElement(settings_doc->doc);
3047 for (node = node->xmlChildrenNode; node; node = node->next)
3049 Settings *set;
3050 xmlChar *path;
3052 if (node->type != XML_ELEMENT_NODE)
3053 continue;
3054 if (strcmp(node->name, "FilerWindow") != 0)
3055 continue;
3057 path=xmlGetProp(node, "path");
3058 set=settings_new(path);
3059 xmlFree(path);
3061 for (subnode=node->xmlChildrenNode; subnode;
3062 subnode=subnode->next) {
3064 if (subnode->type != XML_ELEMENT_NODE)
3065 continue;
3066 load_from_node(set, settings_doc->doc,
3067 subnode);
3070 store_settings(set);
3072 g_object_unref(settings_doc);
3076 static void add_nodes(gpointer key, gpointer value, gpointer data)
3078 xmlNodePtr node=(xmlNodePtr) data;
3079 xmlNodePtr sub;
3080 Settings *set=(Settings *) value;
3081 char *tmp;
3083 sub=xmlNewChild(node, NULL, "FilerWindow", NULL);
3085 xmlSetProp(sub, "path", set->path);
3087 if(set->flags & SET_POSITION) {
3088 tmp=g_strdup_printf("%d", set->x);
3089 xmlNewChild(sub, NULL, "X", tmp);
3090 g_free(tmp);
3091 tmp=g_strdup_printf("%d", set->y);
3092 xmlNewChild(sub, NULL, "Y", tmp);
3093 g_free(tmp);
3095 if(set->flags & SET_SIZE) {
3096 tmp=g_strdup_printf("%d", set->width);
3097 xmlNewChild(sub, NULL, "Width", tmp);
3098 g_free(tmp);
3099 tmp=g_strdup_printf("%d", set->height);
3100 xmlNewChild(sub, NULL, "Height", tmp);
3101 g_free(tmp);
3103 if(set->flags & SET_HIDDEN) {
3104 tmp=g_strdup_printf("%d", set->show_hidden);
3105 xmlNewChild(sub, NULL, "ShowHidden", tmp);
3106 g_free(tmp);
3108 if(set->flags & SET_STYLE) {
3109 tmp=g_strdup_printf("%d", set->display_style);
3110 xmlNewChild(sub, NULL, "DisplayStyle", tmp);
3111 g_free(tmp);
3113 if(set->flags & SET_SORT) {
3114 tmp=g_strdup_printf("%d", set->sort_type);
3115 xmlNewChild(sub, NULL, "SortType", tmp);
3116 g_free(tmp);
3117 tmp=g_strdup_printf("%d", set->sort_order);
3118 xmlNewChild(sub, NULL, "SortOrder", tmp);
3119 g_free(tmp);
3121 if(set->flags & SET_DETAILS) {
3122 tmp=g_strdup_printf("%d", set->view_type);
3123 xmlNewChild(sub, NULL, "ViewType", tmp);
3124 g_free(tmp);
3125 tmp=g_strdup_printf("%d", set->details_type);
3126 xmlNewChild(sub, NULL, "DetailsType", tmp);
3127 g_free(tmp);
3129 if(set->flags & SET_STYLE) {
3130 tmp=g_strdup_printf("%d", set->show_thumbs);
3131 xmlNewChild(sub, NULL, "ShowThumbs", tmp);
3132 g_free(tmp);
3134 if(set->flags & SET_FILTER) {
3135 tmp=g_strdup_printf("%d", set->filter_type);
3136 xmlNewChild(sub, NULL, "FilterType", tmp);
3137 g_free(tmp);
3138 if(set->filter && set->filter[0])
3139 xmlNewChild(sub, NULL, "Filter", set->filter);
3143 static void save_settings(void)
3145 gchar *path;
3147 path=choices_find_xdg_path_save("Settings.xml", PROJECT, SITE, TRUE);
3148 if(path) {
3149 xmlDocPtr doc = xmlNewDoc("1.0");
3150 xmlDocSetRootElement(doc, xmlNewDocNode(doc, NULL,
3151 "Settings", NULL));
3153 g_hash_table_foreach(settings_table, add_nodes,
3154 xmlDocGetRootElement(doc));
3156 save_xml_file(doc, path);
3158 g_free(path);
3159 xmlFreeDoc(doc);
3164 static void check_settings(FilerWindow *filer_window)
3166 Settings *set;
3168 set=(Settings *) g_hash_table_lookup(settings_table,
3169 filer_window->sym_path);
3171 if(set) {
3172 if(set->flags & SET_POSITION)
3173 gtk_window_move(GTK_WINDOW(filer_window->window),
3174 set->x, set->y);
3175 if(set->flags & SET_SIZE)
3176 filer_window_set_size(filer_window, set->width,
3177 set->height);
3178 if(set->flags & SET_HIDDEN)
3179 filer_set_hidden(filer_window, set->show_hidden);
3181 if(set->flags & (SET_STYLE|SET_DETAILS)) {
3182 DisplayStyle style=filer_window->display_style;
3183 DetailsType details=filer_window->details_type;
3185 if(set->flags & SET_STYLE)
3186 style=set->display_style;
3188 if(set->flags & SET_DETAILS) {
3189 details=set->details_type;
3191 filer_set_view_type(filer_window,
3192 set->view_type);
3195 display_set_layout(filer_window, style,
3196 details, FALSE);
3199 if(set->flags & SET_SORT)
3200 display_set_sort_type(filer_window,
3201 set->sort_type,
3202 set->sort_order);
3204 if(set->flags & SET_THUMBS)
3205 display_set_thumbs(filer_window,
3206 set->show_thumbs);
3208 if(set->flags & SET_FILTER)
3209 display_set_filter(filer_window,
3210 set->filter_type,
3211 set->filter);
3216 typedef struct settings_window {
3217 GtkWidget *window;
3219 GtkWidget *pos, *size, *hidden, *style, *sort, *details,
3220 *thumbs, *filter;
3222 Settings *set;
3223 } SettingsWindow;
3226 static void settings_response(GtkWidget *window, gint response,
3227 SettingsWindow *set_win)
3229 if(response==GTK_RESPONSE_OK) {
3230 gint flags=0;
3232 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(set_win->pos)))
3233 flags|=SET_POSITION;
3234 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(set_win->size)))
3235 flags|=SET_SIZE;
3236 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(set_win->hidden)))
3237 flags|=SET_HIDDEN;
3238 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(set_win->style)))
3239 flags|=SET_STYLE;
3240 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(set_win->sort)))
3241 flags|=SET_SORT;
3242 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(set_win->details)))
3243 flags|=SET_DETAILS;
3244 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(set_win->thumbs)))
3245 flags|=SET_THUMBS;
3246 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(set_win->filter)))
3247 flags|=SET_FILTER;
3249 set_win->set->flags=flags;
3250 store_settings(set_win->set);
3251 save_settings();
3254 gtk_widget_destroy(window);
3257 void filer_save_settings(FilerWindow *fwin)
3259 SettingsWindow *set_win;
3260 GtkWidget *vbox;
3261 GtkWidget *path;
3262 gint x, y;
3264 Settings *set=settings_new(fwin->sym_path);
3266 gtk_window_get_position(GTK_WINDOW(fwin->window),&x, &y);
3267 set->flags|=SET_POSITION;
3268 set->x=x;
3269 set->y=y;
3271 gtk_window_get_size(GTK_WINDOW(fwin->window),&x, &y);
3272 set->flags|=SET_SIZE;
3273 set->width=x;
3274 set->height=y;
3276 set->flags|=SET_HIDDEN;
3277 set->show_hidden=fwin->show_hidden;
3279 set->flags|=SET_STYLE;
3280 set->display_style=fwin->display_style;
3282 set->flags|=SET_SORT;
3283 set->sort_type=fwin->sort_type;
3284 set->sort_order=fwin->sort_order;
3286 set->flags|=SET_DETAILS;
3287 set->view_type=fwin->view_type;
3288 set->details_type=fwin->details_type;
3290 set->flags|=SET_THUMBS;
3291 set->show_thumbs=fwin->show_thumbs;
3293 set->flags|=SET_FILTER;
3294 set->filter_type=fwin->filter;
3295 if(fwin->filter_string)
3296 set->filter=g_strdup(fwin->filter_string);
3298 /* Store other parameters
3300 set_win=g_new(SettingsWindow, 1);
3302 set_win->window=gtk_dialog_new();
3303 number_of_windows++;
3305 gtk_dialog_add_button(GTK_DIALOG(set_win->window),
3306 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
3307 gtk_dialog_add_button(GTK_DIALOG(set_win->window),
3308 GTK_STOCK_OK, GTK_RESPONSE_OK);
3310 g_signal_connect(set_win->window, "destroy",
3311 G_CALLBACK(one_less_window), NULL);
3312 g_signal_connect_swapped(set_win->window, "destroy",
3313 G_CALLBACK(g_free), set_win);
3315 gtk_window_set_title(GTK_WINDOW(set_win->window),
3316 _("Select display properties to save"));
3318 vbox=GTK_DIALOG(set_win->window)->vbox;
3320 path=gtk_label_new(set->path);
3321 gtk_box_pack_start(GTK_BOX(vbox), path, FALSE, FALSE, 2);
3323 set_win->pos=gtk_check_button_new_with_label(_("Position"));
3324 gtk_box_pack_start(GTK_BOX(vbox), set_win->pos, FALSE, FALSE, 2);
3325 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(set_win->pos),
3326 set->flags & SET_POSITION);
3328 set_win->size=gtk_check_button_new_with_label(_("Size"));
3329 gtk_box_pack_start(GTK_BOX(vbox), set_win->size, FALSE, FALSE, 2);
3330 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(set_win->size),
3331 set->flags & SET_SIZE);
3333 set_win->hidden=gtk_check_button_new_with_label(_("Show hidden"));
3334 gtk_box_pack_start(GTK_BOX(vbox), set_win->hidden,
3335 FALSE, FALSE, 2);
3336 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(set_win->hidden),
3337 set->flags & SET_HIDDEN);
3339 set_win->style=gtk_check_button_new_with_label(_("Display style"));
3340 gtk_box_pack_start(GTK_BOX(vbox), set_win->style,
3341 FALSE, FALSE, 2);
3342 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(set_win->style),
3343 set->flags & SET_STYLE);
3345 set_win->sort=gtk_check_button_new_with_label(_("Sort type and order"));
3346 gtk_box_pack_start(GTK_BOX(vbox), set_win->sort, FALSE, FALSE, 2);
3347 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(set_win->sort),
3348 set->flags & SET_SORT);
3350 set_win->details=gtk_check_button_new_with_label(_("Details"));
3351 gtk_box_pack_start(GTK_BOX(vbox), set_win->details, FALSE, FALSE, 2);
3352 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(set_win->details),
3353 set->flags & SET_DETAILS);
3355 set_win->thumbs=gtk_check_button_new_with_label(_("Thumbnails"));
3356 gtk_box_pack_start(GTK_BOX(vbox), set_win->thumbs,
3357 FALSE, FALSE, 2);
3358 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(set_win->thumbs),
3359 set->flags & SET_THUMBS);
3361 set_win->filter=gtk_check_button_new_with_label(_("Filter"));
3362 gtk_box_pack_start(GTK_BOX(vbox), set_win->filter,
3363 FALSE, FALSE, 2);
3364 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(set_win->filter),
3365 set->flags & SET_FILTER);
3367 set_win->set=set;
3368 g_signal_connect(set_win->window, "response",
3369 G_CALLBACK(settings_response), set_win);
3371 gtk_widget_show_all(set_win->window);