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)
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19 * Place, Suite 330, Boston, MA 02111-1307 USA
22 /* filer.c - code for handling filer windows */
32 #include <sys/param.h>
37 #include <gdk/gdkkeysyms.h>
46 #include "gui_support.h"
56 #include "minibuffer.h"
63 #include "view_iface.h"
64 #include "view_collection.h"
65 #include "view_details.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
;
95 guint flags
; /* Which parts are valid, see below */
102 GtkSortType sort_order
;
103 gboolean show_thumbs
;
105 DetailsType details_type
;
106 DisplayStyle display_style
;
108 FilterType filter_type
;
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
,
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
,
148 FilerWindow
*filer_window
);
149 static gboolean
drag_motion(GtkWidget
*widget
,
150 GdkDragContext
*context
,
154 FilerWindow
*filer_window
);
156 static void load_settings(void);
157 static void save_settings(void);
158 static void check_settings(FilerWindow
*filer_window
);
159 static char *tip_from_desktop_file(const char *full_path
);
161 static GdkCursor
*busy_cursor
= NULL
;
162 static GdkCursor
*crosshair
= NULL
;
164 /* Indicates whether the filer's display is different to the machine it
165 * is actually running on.
167 static gboolean not_local
= FALSE
;
169 static Option o_short_flag_names
;
170 static Option o_filer_view_type
;
171 Option o_filer_auto_resize
, o_unique_filer_windows
;
172 Option o_filer_size_limit
;
174 void filer_init(void)
178 gchar
*dpyhost
, *tmp
;
180 option_add_int(&o_filer_size_limit
, "filer_size_limit", 75);
181 option_add_int(&o_filer_auto_resize
, "filer_auto_resize",
183 option_add_int(&o_unique_filer_windows
, "filer_unique_windows", 0);
185 option_add_int(&o_short_flag_names
, "filer_short_flag_names", FALSE
);
187 option_add_int(&o_filer_view_type
, "filer_view_type",
188 VIEW_TYPE_COLLECTION
);
190 option_add_notify(filer_options_changed
);
192 busy_cursor
= gdk_cursor_new(GDK_WATCH
);
193 crosshair
= gdk_cursor_new(GDK_CROSSHAIR
);
195 window_with_id
= g_hash_table_new_full(g_str_hash
, g_str_equal
,
198 /* Is the display on the local machine, or are we being
199 * run remotely? See filer_set_title().
201 ohost
= our_host_name();
202 dpy
= gdk_get_display();
203 dpyhost
= g_strdup(dpy
);
204 tmp
= strchr(dpyhost
, ':');
208 if (dpyhost
[0] && strcmp(ohost
, dpyhost
) != 0)
210 /* Try the cannonical name for dpyhost (see our_host_name()
215 ent
= gethostbyname(dpyhost
);
216 if (!ent
|| strcmp(ohost
, ent
->h_name
) != 0)
225 static gboolean
if_deleted(gpointer item
, gpointer removed
)
227 int i
= ((GPtrArray
*) removed
)->len
;
228 DirItem
**r
= (DirItem
**) ((GPtrArray
*) removed
)->pdata
;
229 char *leafname
= ((DirItem
*) item
)->leafname
;
233 if (strcmp(leafname
, r
[i
]->leafname
) == 0)
240 #define DECOR_BORDER 32
242 /* Resize the filer window to w x h pixels, plus border (not clamped).
243 * If triggered by a key event, warp the pointer (for SloppyFocus users).
245 void filer_window_set_size(FilerWindow
*filer_window
, int w
, int h
)
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
))
264 GtkRequisition
*req
= &window
->requisition
;
265 GdkWindow
*gdk_window
= window
->window
;
268 w
= MAX(req
->width
, w
);
269 h
= MAX(req
->height
, h
);
270 gdk_window_get_pointer(NULL
, &x
, &y
, NULL
);
271 m
= gdk_screen_get_monitor_at_point(gdk_screen_get_default(),
273 gdk_window_get_position(gdk_window
, &x
, &y
);
275 if (x
+ w
+ DECOR_BORDER
>
276 monitor_geom
[m
].x
+ monitor_geom
[m
].width
||
277 y
+ h
+ DECOR_BORDER
>
278 monitor_geom
[m
].y
+ monitor_geom
[m
].height
)
280 if (x
+ w
+ DECOR_BORDER
>
281 monitor_geom
[m
].x
+ monitor_geom
[m
].width
)
283 x
= monitor_geom
[m
].x
+ monitor_geom
[m
].width
-
284 w
- 4 - DECOR_BORDER
;
286 if (y
+ h
+ DECOR_BORDER
>
287 monitor_geom
[m
].y
+ monitor_geom
[m
].height
)
289 y
= monitor_geom
[m
].y
+ monitor_geom
[m
].height
-
290 h
- 4 - DECOR_BORDER
;
292 gdk_window_move_resize(gdk_window
, x
, y
, w
, h
);
295 gdk_window_resize(gdk_window
, w
, h
);
297 /* If the resize was triggered by a key press, keep
298 * the pointer inside the window so that it doesn't
299 * lose focus when using pointer-follows-mouse.
301 event
= gtk_get_current_event();
302 if (event
&& event
->type
== GDK_KEY_PRESS
)
307 GdkWindow
*win
= filer_window
->window
->window
;
309 gdk_window_get_pointer(filer_window
->window
->window
,
312 nx
= CLAMP(x
, 4, w
- 4);
313 ny
= CLAMP(y
, 4, h
- 4);
315 if (nx
!= x
|| ny
!= y
)
317 XWarpPointer(gdk_x11_drawable_get_xdisplay(win
),
319 gdk_x11_drawable_get_xid(win
),
325 gdk_event_free(event
);
328 gtk_window_set_default_size(GTK_WINDOW(window
), w
, h
);
331 /* Called on a timeout while scanning or when scanning ends
332 * (whichever happens first).
334 static gint
open_filer_window(FilerWindow
*filer_window
)
336 Settings
*dir_settings
;
337 gboolean force_resize
;
339 dir_settings
= (Settings
*) g_hash_table_lookup(settings_table
,
340 filer_window
->sym_path
);
342 force_resize
= !(o_filer_auto_resize
.int_value
== RESIZE_NEVER
&&
343 dir_settings
&& dir_settings
->flags
& SET_POSITION
);
345 view_style_changed(filer_window
->view
, 0);
347 if (filer_window
->open_timeout
)
349 g_source_remove(filer_window
->open_timeout
);
350 filer_window
->open_timeout
= 0;
353 if (!GTK_WIDGET_VISIBLE(filer_window
->window
))
355 display_set_actual_size(filer_window
, force_resize
);
356 gtk_widget_show(filer_window
->window
);
362 /* Look through all items we want to display, and queue a recheck on any
365 static void queue_interesting(FilerWindow
*filer_window
)
370 view_get_iter(filer_window
->view
, &iter
, 0);
371 while ((item
= iter
.next(&iter
)))
373 if (item
->flags
& ITEM_FLAG_NEED_RESCAN_QUEUE
)
374 dir_queue_recheck(filer_window
->directory
, item
);
378 static void update_display(Directory
*dir
,
381 FilerWindow
*filer_window
)
383 ViewIface
*view
= (ViewIface
*) filer_window
->view
;
388 view_add_items(view
, items
);
389 /* Open and resize if currently hidden */
390 open_filer_window(filer_window
);
393 view_delete_if(view
, if_deleted
, items
);
394 toolbar_update_info(filer_window
);
397 set_scanning_display(filer_window
, TRUE
);
398 toolbar_update_info(filer_window
);
401 if (filer_window
->window
->window
)
402 gdk_window_set_cursor(
403 filer_window
->window
->window
,
405 set_scanning_display(filer_window
, FALSE
);
406 toolbar_update_info(filer_window
);
407 open_filer_window(filer_window
);
409 if (filer_window
->had_cursor
&&
410 !view_cursor_visible(view
))
413 view_get_iter(view
, &start
, 0);
414 if (start
.next(&start
))
415 view_cursor_to_iter(view
, &start
);
416 view_show_cursor(view
);
417 filer_window
->had_cursor
= FALSE
;
419 if (filer_window
->auto_select
)
420 display_set_autoselect(filer_window
,
421 filer_window
->auto_select
);
422 null_g_free(&filer_window
->auto_select
);
424 filer_create_thumbs(filer_window
);
426 if (filer_window
->thumb_queue
)
427 start_thumb_scanning(filer_window
);
430 view_update_items(view
, items
);
432 case DIR_ERROR_CHANGED
:
433 filer_set_title(filer_window
);
435 case DIR_QUEUE_INTERESTING
:
436 queue_interesting(filer_window
);
441 static void attach(FilerWindow
*filer_window
)
443 gdk_window_set_cursor(filer_window
->window
->window
, busy_cursor
);
444 view_clear(filer_window
->view
);
445 filer_window
->scanning
= TRUE
;
446 dir_attach(filer_window
->directory
, (DirCallback
) update_display
,
448 filer_set_title(filer_window
);
449 bookmarks_add_history(filer_window
->sym_path
);
451 if (filer_window
->directory
->error
)
453 if (spring_in_progress
)
454 g_printerr(_("Error scanning '%s':\n%s\n"),
455 filer_window
->sym_path
,
456 filer_window
->directory
->error
);
458 delayed_error(_("Error scanning '%s':\n%s"),
459 filer_window
->sym_path
,
460 filer_window
->directory
->error
);
464 static void detach(FilerWindow
*filer_window
)
466 g_return_if_fail(filer_window
->directory
!= NULL
);
468 dir_detach(filer_window
->directory
,
469 (DirCallback
) update_display
, filer_window
);
470 g_object_unref(filer_window
->directory
);
471 filer_window
->directory
= NULL
;
474 /* If 'start' was mounted by ROX-Filer, return it. Otherwise, try the
475 * parents up the tree.
476 * NULL if we're not in a user mount point.
477 * g_free() the result.
479 static char *get_ancestor_user_mount_point(const char *start
)
483 path
= strdup(start
);
489 if (mount_is_user_mounted(path
))
498 slash
= strrchr(path
+ 1, '/');
505 static void umount_dialog_response(GtkWidget
*dialog
, int response
, char *mount
)
507 if (response
== GTK_RESPONSE_OK
)
511 list
= g_list_prepend(NULL
, mount
);
512 action_mount(list
, FALSE
, FALSE
, TRUE
);
518 gtk_widget_destroy(dialog
);
523 /* 'filer_window' shows a directory under 'mount'. If no other window also
524 * shows a directory under it, display a non-modal dialog offering to
525 * unmount the directory.
526 * 'mount' is freed by this function, either directly, or after the dialog
529 static void may_offer_unmount(FilerWindow
*filer_window
, char *mount
)
531 GtkWidget
*dialog
, *button
;
537 for (next
= all_filer_windows
; next
; next
= next
->next
)
539 FilerWindow
*other
= (FilerWindow
*) next
->data
;
541 if (other
== filer_window
)
544 if (strncmp(filer_window
->real_path
, other
->real_path
,
549 filer_window
->real_path
[len
] != '/' ||
550 filer_window
->real_path
[len
] != '\0');
552 if (other
->real_path
[len
] != '/' &&
553 other
->real_path
[len
] != '\0')
556 /* Found another window. Don't offer to unmount. */
561 dialog
= gtk_message_dialog_new(NULL
, 0, GTK_MESSAGE_QUESTION
,
563 _("Do you want to unmount this device?\n\n"
564 "Unmounting a device makes it safe to remove "
565 "the disk."), mount
);
567 button
= button_new_mixed(ROX_STOCK_MOUNTED
, _("No change"));
568 GTK_WIDGET_SET_FLAGS(button
, GTK_CAN_DEFAULT
);
569 gtk_dialog_add_action_widget(GTK_DIALOG(dialog
), button
,
570 GTK_RESPONSE_CANCEL
);
571 gtk_widget_show(button
);
573 button
= button_new_mixed(ROX_STOCK_MOUNT
, _("Unmount"));
574 GTK_WIDGET_SET_FLAGS(button
, GTK_CAN_DEFAULT
);
575 gtk_dialog_add_action_widget(GTK_DIALOG(dialog
), button
,
577 gtk_widget_show(button
);
579 g_signal_connect(G_OBJECT(dialog
), "response",
580 G_CALLBACK(umount_dialog_response
), mount
);
582 gtk_dialog_set_default_response(GTK_DIALOG(dialog
),
586 gtk_widget_show(dialog
);
589 /* Returns TRUE to prevent closing the window. May offer to unmount a
592 gboolean
filer_window_delete(GtkWidget
*window
,
593 GdkEvent
*unused
, /* (may be NULL) */
594 FilerWindow
*filer_window
)
598 mount
= get_ancestor_user_mount_point(filer_window
->real_path
);
601 may_offer_unmount(filer_window
, mount
);
606 static void filer_window_destroyed(GtkWidget
*widget
, FilerWindow
*filer_window
)
608 all_filer_windows
= g_list_remove(all_filer_windows
, filer_window
);
610 g_object_set_data(G_OBJECT(widget
), "filer_window", NULL
);
612 if (window_with_primary
== filer_window
)
613 window_with_primary
= NULL
;
615 if (window_with_focus
== filer_window
)
618 window_with_focus
= NULL
;
621 if (filer_window
->directory
)
622 detach(filer_window
);
624 if (filer_window
->open_timeout
)
626 g_source_remove(filer_window
->open_timeout
);
627 filer_window
->open_timeout
= 0;
630 if (filer_window
->auto_scroll
!= -1)
632 g_source_remove(filer_window
->auto_scroll
);
633 filer_window
->auto_scroll
= -1;
636 if (filer_window
->thumb_queue
)
637 destroy_glist(&filer_window
->thumb_queue
);
641 filer_set_id(filer_window
, NULL
);
643 if(filer_window
->filter_string
)
644 g_free(filer_window
->filter_string
);
645 if(filer_window
->regexp
)
646 g_free(filer_window
->regexp
);
648 g_free(filer_window
->auto_select
);
649 g_free(filer_window
->real_path
);
650 g_free(filer_window
->sym_path
);
651 g_free(filer_window
);
656 /* Returns TRUE iff the directory still exists. */
657 static gboolean
may_rescan(FilerWindow
*filer_window
, gboolean warning
)
661 g_return_val_if_fail(filer_window
!= NULL
, FALSE
);
663 /* We do a fresh lookup (rather than update) because the inode may
666 dir
= g_fscache_lookup(dir_cache
, filer_window
->real_path
);
670 info_message(_("Directory missing/deleted"));
671 gtk_widget_destroy(filer_window
->window
);
674 if (dir
== filer_window
->directory
)
678 detach(filer_window
);
679 filer_window
->directory
= dir
;
680 attach(filer_window
);
686 /* No items are now selected. This might be because another app claimed
687 * the selection or because the user unselected all the items.
689 void filer_lost_selection(FilerWindow
*filer_window
, guint time
)
691 if (window_with_primary
== filer_window
)
693 window_with_primary
= NULL
;
694 gtk_selection_owner_set(NULL
, GDK_SELECTION_PRIMARY
, time
);
698 /* Another app has claimed the primary selection */
699 static void filer_lost_primary(GtkWidget
*window
,
700 GdkEventSelection
*event
,
703 FilerWindow
*filer_window
= (FilerWindow
*) user_data
;
705 if (window_with_primary
&& window_with_primary
== filer_window
)
707 window_with_primary
= NULL
;
708 set_selection_state(filer_window
, FALSE
);
712 /* Someone wants us to send them the selection */
713 static void selection_get(GtkWidget
*widget
,
714 GtkSelectionData
*selection_data
,
719 GString
*reply
, *header
;
720 FilerWindow
*filer_window
= (FilerWindow
*) data
;
724 reply
= g_string_new(NULL
);
725 header
= g_string_new(NULL
);
730 g_string_printf(header
, " %s",
731 make_path(filer_window
->sym_path
, ""));
733 case TARGET_URI_LIST
:
734 g_string_printf(header
, " file://%s%s",
735 our_host_name_for_dnd(),
736 make_path(filer_window
->sym_path
, ""));
740 view_get_iter(filer_window
->view
, &iter
, VIEW_ITER_SELECTED
);
742 while ((item
= iter
.next(&iter
)))
744 g_string_append(reply
, header
->str
);
745 g_string_append(reply
, item
->leafname
);
749 gtk_selection_data_set_text(selection_data
,
750 reply
->str
+ 1, reply
->len
- 1);
753 g_warning("Attempt to paste empty selection!");
754 gtk_selection_data_set_text(selection_data
, "", 0);
757 g_string_free(reply
, TRUE
);
758 g_string_free(header
, TRUE
);
761 /* Selection has been changed -- try to grab the primary selection
762 * if we don't have it. Also called when clicking on an insensitive selection
764 * Also updates toolbar info.
766 void filer_selection_changed(FilerWindow
*filer_window
, gint time
)
768 toolbar_update_info(filer_window
);
770 if (window_with_primary
== filer_window
)
771 return; /* Already got primary */
773 if (!view_count_selected(filer_window
->view
))
774 return; /* Nothing selected */
776 if (filer_window
->temp_item_selected
== FALSE
&&
777 gtk_selection_owner_set(GTK_WIDGET(filer_window
->window
),
778 GDK_SELECTION_PRIMARY
,
781 window_with_primary
= filer_window
;
782 set_selection_state(filer_window
, TRUE
);
785 set_selection_state(filer_window
, FALSE
);
788 /* Open the item (or add it to the shell command minibuffer) */
789 void filer_openitem(FilerWindow
*filer_window
, ViewIter
*iter
, OpenFlags flags
)
791 gboolean shift
= (flags
& OPEN_SHIFT
) != 0;
792 gboolean close_mini
= flags
& OPEN_FROM_MINI
;
793 gboolean close_window
= (flags
& OPEN_CLOSE_WINDOW
) != 0;
795 const guchar
*full_path
;
796 gboolean wink
= TRUE
;
799 g_return_if_fail(filer_window
!= NULL
&& iter
!= NULL
);
801 item
= iter
->peek(iter
);
803 g_return_if_fail(item
!= NULL
);
805 if (filer_window
->mini_type
== MINI_SHELL
)
807 minibuffer_add(filer_window
, item
->leafname
);
811 if (item
->base_type
== TYPE_UNKNOWN
)
812 dir_update_item(filer_window
->directory
, item
->leafname
);
814 if (item
->base_type
== TYPE_DIRECTORY
)
816 /* Never close a filer window when opening a directory
817 * (click on a dir or click on an app with shift).
819 if (shift
|| !(item
->flags
& ITEM_FLAG_APPDIR
))
820 close_window
= FALSE
;
823 full_path
= make_path(filer_window
->sym_path
, item
->leafname
);
824 if (shift
&& (item
->flags
& ITEM_FLAG_SYMLINK
))
827 old_dir
= filer_window
->directory
;
828 if (run_diritem(full_path
, item
,
829 flags
& OPEN_SAME_WINDOW
? filer_window
: NULL
,
833 if (old_dir
!= filer_window
->directory
)
837 gtk_widget_destroy(filer_window
->window
);
841 view_wink_item(filer_window
->view
, iter
);
843 minibuffer_hide(filer_window
);
848 static gint
pointer_in(GtkWidget
*widget
,
849 GdkEventCrossing
*event
,
850 FilerWindow
*filer_window
)
852 may_rescan(filer_window
, TRUE
);
856 static gint
pointer_out(GtkWidget
*widget
,
857 GdkEventCrossing
*event
,
858 FilerWindow
*filer_window
)
864 /* Move the cursor to the next selected item in direction 'dir'
867 void filer_next_selected(FilerWindow
*filer_window
, int dir
)
869 ViewIter iter
, cursor
;
870 gboolean have_cursor
;
871 ViewIface
*view
= filer_window
->view
;
873 g_return_if_fail(dir
== 1 || dir
== -1);
875 view_get_cursor(view
, &cursor
);
876 have_cursor
= cursor
.peek(&cursor
) != NULL
;
878 view_get_iter(view
, &iter
,
880 (have_cursor
? VIEW_ITER_FROM_CURSOR
: 0) |
881 (dir
< 0 ? VIEW_ITER_BACKWARDS
: 0));
883 if (have_cursor
&& view_get_selected(view
, &cursor
))
884 iter
.next(&iter
); /* Skip the cursor itself */
886 if (iter
.next(&iter
))
887 view_cursor_to_iter(view
, &iter
);
894 static void return_pressed(FilerWindow
*filer_window
, GdkEventKey
*event
)
896 TargetFunc cb
= filer_window
->target_cb
;
897 gpointer data
= filer_window
->target_data
;
901 filer_target_mode(filer_window
, NULL
, NULL
, NULL
);
903 view_get_cursor(filer_window
->view
, &iter
);
904 if (!iter
.peek(&iter
))
909 cb(filer_window
, &iter
, data
);
913 if (event
->state
& GDK_SHIFT_MASK
)
915 if (event
->state
& GDK_MOD1_MASK
)
916 flags
|= OPEN_CLOSE_WINDOW
;
918 flags
|= OPEN_SAME_WINDOW
;
920 filer_openitem(filer_window
, &iter
, flags
);
923 /* Makes sure that 'groups' is up-to-date, reloading from file if it has
924 * changed. If no groups were loaded and there is no file then initialised
925 * groups to an empty document.
926 * Return the node for the 'name' group.
928 static xmlNode
*group_find(char *name
)
933 /* Update the groups, if possible */
934 path
= choices_find_xdg_path_load("Groups.xml", PROJECT
, SITE
);
938 wrapper
= xml_cache_load(path
);
942 g_object_unref(groups
);
951 groups
= xml_new(NULL
);
952 groups
->doc
= xmlNewDoc("1.0");
954 xmlDocSetRootElement(groups
->doc
,
955 xmlNewDocNode(groups
->doc
, NULL
, "groups", NULL
));
959 node
= xmlDocGetRootElement(groups
->doc
);
961 for (node
= node
->xmlChildrenNode
; node
; node
= node
->next
)
965 gid
= xmlGetProp(node
, "name");
970 if (strcmp(name
, gid
) != 0)
981 static void group_save(FilerWindow
*filer_window
, char *name
)
988 group
= group_find(name
);
991 xmlUnlinkNode(group
);
994 group
= xmlNewChild(xmlDocGetRootElement(groups
->doc
),
995 NULL
, "group", NULL
);
996 xmlSetProp(group
, "name", name
);
998 xmlNewTextChild(group
, NULL
, "directory", filer_window
->sym_path
);
1000 view_get_iter(filer_window
->view
, &iter
, VIEW_ITER_SELECTED
);
1002 while ((item
= iter
.next(&iter
)))
1003 xmlNewTextChild(group
, NULL
, "item", item
->leafname
);
1005 save_path
= choices_find_xdg_path_save("Groups.xml", PROJECT
, SITE
,
1009 save_xml_file(groups
->doc
, save_path
);
1014 static gboolean
group_restore_cb(ViewIter
*iter
, gpointer data
)
1016 GHashTable
*in_group
= (GHashTable
*) data
;
1018 return g_hash_table_lookup(in_group
,
1019 iter
->peek(iter
)->leafname
) != NULL
;
1022 static void group_restore(FilerWindow
*filer_window
, char *name
)
1024 GHashTable
*in_group
;
1026 xmlNode
*group
, *node
;
1028 group
= group_find(name
);
1032 report_error(_("Group %s is not set. Select some files "
1033 "and press Ctrl+%s to set the group. Press %s "
1034 "on its own to reselect the files later.\n"
1035 "Make sure NumLock is on if you use the keypad."),
1040 node
= get_subnode(group
, NULL
, "directory");
1041 g_return_if_fail(node
!= NULL
);
1042 path
= xmlNodeListGetString(groups
->doc
, node
->xmlChildrenNode
, 1);
1043 g_return_if_fail(path
!= NULL
);
1045 if (strcmp(path
, filer_window
->sym_path
) != 0)
1046 filer_change_to(filer_window
, path
, NULL
);
1049 in_group
= g_hash_table_new(g_str_hash
, g_str_equal
);
1050 for (node
= group
->xmlChildrenNode
; node
; node
= node
->next
)
1053 if (node
->type
!= XML_ELEMENT_NODE
)
1055 if (strcmp(node
->name
, "item") != 0)
1058 leaf
= xmlNodeListGetString(groups
->doc
,
1059 node
->xmlChildrenNode
, 1);
1061 g_warning("Missing leafname!\n");
1063 g_hash_table_insert(in_group
, leaf
, filer_window
);
1066 view_select_if(filer_window
->view
, &group_restore_cb
, in_group
);
1068 g_hash_table_foreach(in_group
, (GHFunc
) g_free
, NULL
);
1069 g_hash_table_destroy(in_group
);
1072 static gboolean
popup_menu(GtkWidget
*widget
, FilerWindow
*filer_window
)
1077 view_get_cursor(filer_window
->view
, &iter
);
1079 event
= gtk_get_current_event();
1080 show_filer_menu(filer_window
, event
, &iter
);
1082 gdk_event_free(event
);
1087 void filer_window_toggle_cursor_item_selected(FilerWindow
*filer_window
)
1089 ViewIface
*view
= filer_window
->view
;
1092 view_get_iter(view
, &iter
, VIEW_ITER_FROM_CURSOR
);
1093 if (!iter
.next(&iter
))
1094 return; /* No cursor */
1096 if (view_get_selected(view
, &iter
))
1097 view_set_selected(view
, &iter
, FALSE
);
1099 view_set_selected(view
, &iter
, TRUE
);
1101 if (iter
.next(&iter
))
1102 view_cursor_to_iter(view
, &iter
);
1105 gint
filer_key_press_event(GtkWidget
*widget
,
1107 FilerWindow
*filer_window
)
1109 ViewIface
*view
= filer_window
->view
;
1111 GtkWidget
*focus
= GTK_WINDOW(widget
)->focus_widget
;
1112 guint key
= event
->keyval
;
1113 char group
[2] = "1";
1115 window_with_focus
= filer_window
;
1117 /* Delay setting up the keys until now to speed loading... */
1118 if (ensure_filer_menu())
1120 /* Gtk updates in an idle-handler, so force a recheck now */
1121 g_signal_emit_by_name(widget
, "keys_changed");
1124 if (focus
&& focus
== filer_window
->minibuffer
)
1125 if (gtk_widget_event(focus
, (GdkEvent
*) event
))
1126 return TRUE
; /* Handled */
1129 gtk_widget_grab_focus(GTK_WIDGET(view
));
1131 view_get_cursor(view
, &cursor
);
1132 if (!cursor
.peek(&cursor
) && (key
== GDK_Up
|| key
== GDK_Down
))
1135 view_get_iter(view
, &iter
, 0);
1136 if (iter
.next(&iter
))
1137 view_cursor_to_iter(view
, &iter
);
1138 gtk_widget_grab_focus(GTK_WIDGET(view
)); /* Needed? */
1145 filer_target_mode(filer_window
, NULL
, NULL
, NULL
);
1146 view_cursor_to_iter(filer_window
->view
, NULL
);
1147 view_clear_selection(filer_window
->view
);
1150 return_pressed(filer_window
, event
);
1152 case GDK_ISO_Left_Tab
:
1153 filer_next_selected(filer_window
, -1);
1156 filer_next_selected(filer_window
, 1);
1159 change_to_parent(filer_window
);
1167 view_get_cursor(filer_window
->view
, &iter
);
1168 show_filer_menu(filer_window
,
1169 (GdkEvent
*) event
, &iter
);
1173 filer_window_toggle_cursor_item_selected(filer_window
);
1176 if (key
>= GDK_0
&& key
<= GDK_9
)
1177 group
[0] = key
- GDK_0
+ '0';
1178 else if (key
>= GDK_KP_0
&& key
<= GDK_KP_9
)
1179 group
[0] = key
- GDK_KP_0
+ '0';
1182 if (focus
&& focus
!= widget
&&
1183 gtk_widget_get_toplevel(focus
) == widget
)
1184 if (gtk_widget_event(focus
,
1185 (GdkEvent
*) event
))
1186 return TRUE
; /* Handled */
1190 if (event
->state
& GDK_CONTROL_MASK
)
1191 group_save(filer_window
, group
);
1193 group_restore(filer_window
, group
);
1199 void filer_open_parent(FilerWindow
*filer_window
)
1202 const char *current
= filer_window
->sym_path
;
1204 if (current
[0] == '/' && current
[1] == '\0')
1205 return; /* Already in the root */
1207 dir
= g_path_get_dirname(current
);
1208 filer_opendir(dir
, filer_window
, NULL
);
1212 void change_to_parent(FilerWindow
*filer_window
)
1215 const char *current
= filer_window
->sym_path
;
1217 if (current
[0] == '/' && current
[1] == '\0')
1218 return; /* Already in the root */
1220 if (mount_is_user_mounted(filer_window
->real_path
))
1221 may_offer_unmount(filer_window
,
1222 g_strdup(filer_window
->real_path
));
1224 dir
= g_path_get_dirname(current
);
1225 filer_change_to(filer_window
, dir
, g_basename(current
));
1229 /* Removes trailing /s from path (modified in place) */
1230 static void tidy_sympath(gchar
*path
)
1234 g_return_if_fail(path
!= NULL
);
1237 while (l
> 1 && path
[l
- 1] == '/')
1244 /* Make filer_window display path. When finished, highlight item 'from', or
1245 * the first item if from is NULL. If there is currently no cursor then
1246 * simply wink 'from' (if not NULL).
1247 * If the cause was a key event and we resize, warp the pointer.
1249 void filer_change_to(FilerWindow
*filer_window
,
1250 const char *path
, const char *from
)
1253 char *sym_path
, *real_path
;
1256 g_return_if_fail(filer_window
!= NULL
);
1258 filer_cancel_thumbnails(filer_window
);
1262 sym_path
= g_strdup(path
);
1263 real_path
= pathdup(path
);
1264 new_dir
= g_fscache_lookup(dir_cache
, real_path
);
1268 delayed_error(_("Directory '%s' is not accessible"),
1275 if (o_unique_filer_windows
.int_value
&& !spring_in_progress
)
1279 fw
= find_filer_window(sym_path
, filer_window
);
1281 gtk_widget_destroy(fw
->window
);
1284 from_dup
= from
&& *from
? g_strdup(from
) : NULL
;
1286 detach(filer_window
);
1287 g_free(filer_window
->real_path
);
1288 g_free(filer_window
->sym_path
);
1289 filer_window
->real_path
= real_path
;
1290 filer_window
->sym_path
= sym_path
;
1291 tidy_sympath(filer_window
->sym_path
);
1293 filer_window
->directory
= new_dir
;
1295 g_free(filer_window
->auto_select
);
1296 filer_window
->auto_select
= from_dup
;
1298 filer_window
->had_cursor
= filer_window
->had_cursor
||
1299 view_cursor_visible(filer_window
->view
);
1301 filer_set_title(filer_window
);
1302 if (filer_window
->window
->window
)
1303 gdk_window_set_role(filer_window
->window
->window
,
1304 filer_window
->sym_path
);
1305 view_cursor_to_iter(filer_window
->view
, NULL
);
1307 attach(filer_window
);
1309 check_settings(filer_window
);
1311 display_set_actual_size(filer_window
, FALSE
);
1313 if (o_filer_auto_resize
.int_value
== RESIZE_ALWAYS
)
1314 view_autosize(filer_window
->view
);
1316 if (filer_window
->mini_type
== MINI_PATH
)
1317 g_idle_add((GSourceFunc
) minibuffer_show_cb
, filer_window
);
1320 /* Returns a list containing the full (sym) pathname of every selected item.
1321 * You must g_free() each item in the list.
1323 GList
*filer_selected_items(FilerWindow
*filer_window
)
1325 GList
*retval
= NULL
;
1326 guchar
*dir
= filer_window
->sym_path
;
1330 view_get_iter(filer_window
->view
, &iter
, VIEW_ITER_SELECTED
);
1331 while ((item
= iter
.next(&iter
)))
1333 retval
= g_list_prepend(retval
,
1334 g_strdup(make_path(dir
, item
->leafname
)));
1337 return g_list_reverse(retval
);
1340 /* Return the single selected item. Error if nothing is selected. */
1341 DirItem
*filer_selected_item(FilerWindow
*filer_window
)
1346 view_get_iter(filer_window
->view
, &iter
, VIEW_ITER_SELECTED
);
1348 item
= iter
.next(&iter
);
1349 g_return_val_if_fail(item
!= NULL
, NULL
);
1350 g_return_val_if_fail(iter
.next(&iter
) == NULL
, NULL
);
1355 /* Creates and shows a new filer window.
1356 * If src_win != NULL then display options can be taken from that source window.
1357 * Returns the new filer window, or NULL on error.
1358 * Note: if unique windows is in use, may return an existing window.
1360 FilerWindow
*filer_opendir(const char *path
, FilerWindow
*src_win
,
1361 const gchar
*wm_class
)
1363 FilerWindow
*filer_window
;
1365 DisplayStyle dstyle
;
1368 GtkSortType s_order
;
1369 Settings
*dir_settings
= NULL
;
1370 gboolean force_resize
= TRUE
;
1372 /* Get the real pathname of the directory and copy it */
1373 real_path
= pathdup(path
);
1375 if (o_unique_filer_windows
.int_value
&& !spring_in_progress
)
1377 FilerWindow
*same_dir_window
;
1379 same_dir_window
= find_filer_window(path
, NULL
);
1381 if (same_dir_window
)
1383 gtk_window_present(GTK_WINDOW(same_dir_window
->window
));
1384 return same_dir_window
;
1388 filer_window
= g_new(FilerWindow
, 1);
1389 filer_window
->message
= NULL
;
1390 filer_window
->minibuffer
= NULL
;
1391 filer_window
->minibuffer_label
= NULL
;
1392 filer_window
->minibuffer_area
= NULL
;
1393 filer_window
->temp_show_hidden
= FALSE
;
1394 filer_window
->sym_path
= g_strdup(path
);
1395 filer_window
->real_path
= real_path
;
1396 filer_window
->scanning
= FALSE
;
1397 filer_window
->had_cursor
= FALSE
;
1398 filer_window
->auto_select
= NULL
;
1399 filer_window
->toolbar_text
= NULL
;
1400 filer_window
->target_cb
= NULL
;
1401 filer_window
->mini_type
= MINI_NONE
;
1402 filer_window
->selection_state
= GTK_STATE_INSENSITIVE
;
1403 filer_window
->toolbar
= NULL
;
1404 filer_window
->toplevel_vbox
= NULL
;
1405 filer_window
->view_hbox
= NULL
;
1406 filer_window
->view
= NULL
;
1407 filer_window
->scrollbar
= NULL
;
1408 filer_window
->auto_scroll
= -1;
1409 filer_window
->window_id
= NULL
;
1411 tidy_sympath(filer_window
->sym_path
);
1413 /* Finds the entry for this directory in the dir cache, creating
1414 * a new one if needed. This does not cause a scan to start,
1415 * so if a new entry is created then it will be empty.
1417 filer_window
->directory
= g_fscache_lookup(dir_cache
, real_path
);
1418 if (!filer_window
->directory
)
1420 delayed_error(_("Directory '%s' not found."), path
);
1421 g_free(filer_window
->real_path
);
1422 g_free(filer_window
->sym_path
);
1423 g_free(filer_window
);
1427 filer_window
->temp_item_selected
= FALSE
;
1428 filer_window
->flags
= (FilerFlags
) 0;
1429 filer_window
->details_type
= DETAILS_TIMES
;
1430 filer_window
->display_style
= UNKNOWN_STYLE
;
1431 filer_window
->display_style_wanted
= UNKNOWN_STYLE
;
1432 filer_window
->thumb_queue
= NULL
;
1433 filer_window
->max_thumbs
= 0;
1434 filer_window
->sort_type
= -1;
1436 filer_window
->filter
= FILER_SHOW_ALL
;
1437 filer_window
->filter_string
= NULL
;
1438 filer_window
->regexp
= NULL
;
1440 if (src_win
&& o_display_inherit_options
.int_value
)
1442 s_type
= src_win
->sort_type
;
1443 s_order
= src_win
->sort_order
;
1444 dstyle
= src_win
->display_style_wanted
;
1445 dtype
= src_win
->details_type
;
1446 filer_window
->show_hidden
= src_win
->show_hidden
;
1447 filer_window
->show_thumbs
= src_win
->show_thumbs
;
1448 filer_window
->view_type
= src_win
->view_type
;
1450 filer_set_filter(filer_window
, src_win
->filter
,
1451 src_win
->filter_string
);
1455 s_type
= o_display_sort_by
.int_value
;
1456 s_order
= GTK_SORT_ASCENDING
;
1457 dstyle
= o_display_size
.int_value
;
1458 dtype
= o_display_details
.int_value
;
1459 filer_window
->show_hidden
= o_display_show_hidden
.int_value
;
1460 filer_window
->show_thumbs
= o_display_show_thumbs
.int_value
;
1461 filer_window
->view_type
= o_filer_view_type
.int_value
;
1464 dir_settings
= (Settings
*) g_hash_table_lookup(settings_table
,
1465 filer_window
->sym_path
);
1468 /* Override the current defaults with the per-directory
1471 if (dir_settings
->flags
& SET_HIDDEN
)
1472 filer_window
->show_hidden
= dir_settings
->show_hidden
;
1474 if (dir_settings
->flags
& SET_STYLE
)
1475 dstyle
= dir_settings
->display_style
;
1477 if (dir_settings
->flags
& SET_DETAILS
)
1479 dtype
= dir_settings
->details_type
;
1480 filer_window
->view_type
= dir_settings
->view_type
;
1483 if (dir_settings
->flags
& SET_SORT
)
1485 s_type
= dir_settings
->sort_type
;
1486 s_order
= dir_settings
->sort_order
;
1489 if (dir_settings
->flags
& SET_THUMBS
)
1490 filer_window
->show_thumbs
= dir_settings
->show_thumbs
;
1492 if (dir_settings
->flags
& SET_FILTER
)
1493 filer_set_filter(filer_window
,
1494 dir_settings
->filter_type
,
1495 dir_settings
->filter
);
1498 /* Add all the user-interface elements & realise */
1499 filer_add_widgets(filer_window
, wm_class
);
1501 gtk_window_set_position(GTK_WINDOW(filer_window
->window
),
1506 if (dir_settings
->flags
& SET_POSITION
)
1508 gtk_window_move(GTK_WINDOW(filer_window
->window
),
1509 dir_settings
->x
, dir_settings
->y
);
1511 if (dir_settings
->flags
& SET_SIZE
)
1513 filer_window_set_size(filer_window
,
1514 dir_settings
->width
,
1515 dir_settings
->height
);
1516 force_resize
= o_filer_auto_resize
.int_value
!= RESIZE_NEVER
;
1520 /* Connect to all the signal handlers */
1521 filer_add_signals(filer_window
);
1523 display_set_layout(filer_window
, dstyle
, dtype
, force_resize
);
1524 display_set_sort_type(filer_window
, s_type
, s_order
);
1526 /* Open the window after a timeout, or when scanning stops.
1527 * Do this before attaching, because attach() might tell us to
1528 * stop scanning (if a scan isn't needed).
1530 filer_window
->open_timeout
= g_timeout_add(500,
1531 (GSourceFunc
) open_filer_window
,
1534 /* The view is created empty and then attach() is called, which
1535 * links the filer window to the entry in the directory cache we
1536 * looked up / created above.
1538 * The attach() function will immediately callback to the filer window
1539 * to deliver a list of all known entries in the directory (so,
1540 * the number of items will be known after attach() returns).
1542 * If the directory was not in the cache (because it hadn't been
1543 * opened it before) then the types and icons for the entries are
1544 * not know, but the list of names is.
1547 attach(filer_window
);
1549 number_of_windows
++;
1550 all_filer_windows
= g_list_prepend(all_filer_windows
, filer_window
);
1552 return filer_window
;
1555 void filer_set_view_type(FilerWindow
*filer_window
, ViewType type
)
1557 GtkWidget
*view
= NULL
;
1558 Directory
*dir
= NULL
;
1559 GHashTable
*selected
= NULL
;
1561 g_return_if_fail(filer_window
!= NULL
);
1563 motion_window
= NULL
;
1565 if (filer_window
->view
)
1567 /* Save the current selection */
1571 selected
= g_hash_table_new(g_str_hash
, g_str_equal
);
1572 view_get_iter(filer_window
->view
, &iter
, VIEW_ITER_SELECTED
);
1573 while ((item
= iter
.next(&iter
)))
1574 g_hash_table_insert(selected
, item
->leafname
, "yes");
1576 /* Destroy the old view */
1577 gtk_widget_destroy(GTK_WIDGET(filer_window
->view
));
1578 filer_window
->view
= NULL
;
1580 dir
= filer_window
->directory
;
1582 detach(filer_window
);
1587 case VIEW_TYPE_COLLECTION
:
1588 view
= view_collection_new(filer_window
);
1590 case VIEW_TYPE_DETAILS
:
1591 view
= view_details_new(filer_window
);
1595 g_return_if_fail(view
!= NULL
);
1597 filer_window
->view
= VIEW(view
);
1598 filer_window
->view_type
= type
;
1600 gtk_box_pack_start(filer_window
->view_hbox
, view
, TRUE
, TRUE
, 0);
1601 gtk_widget_show(view
);
1603 /* Drag and drop events */
1604 make_drop_target(view
, 0);
1605 g_signal_connect(view
, "drag_motion",
1606 G_CALLBACK(drag_motion
), filer_window
);
1607 g_signal_connect(view
, "drag_leave",
1608 G_CALLBACK(drag_leave
), filer_window
);
1609 g_signal_connect(view
, "drag_end",
1610 G_CALLBACK(drag_end
), filer_window
);
1611 /* Dragging from us... */
1612 g_signal_connect(view
, "drag_data_get",
1613 GTK_SIGNAL_FUNC(drag_data_get
), NULL
);
1617 /* Only when changing type. Otherwise, will attach later. */
1618 filer_window
->directory
= dir
;
1619 attach(filer_window
);
1621 if (o_filer_auto_resize
.int_value
!= RESIZE_NEVER
)
1622 view_autosize(filer_window
->view
);
1630 view_get_iter(filer_window
->view
, &iter
, 0);
1631 while ((item
= iter
.next(&iter
)))
1633 if (g_hash_table_lookup(selected
, item
->leafname
))
1634 view_set_selected(filer_window
->view
,
1637 g_hash_table_destroy(selected
);
1641 /* This adds all the widgets to a new filer window. It is in a separate
1642 * function because filer_opendir() was getting too long...
1644 static void filer_add_widgets(FilerWindow
*filer_window
, const gchar
*wm_class
)
1646 GtkWidget
*hbox
, *vbox
;
1648 /* Create the top-level window widget */
1649 filer_window
->window
= gtk_window_new(GTK_WINDOW_TOPLEVEL
);
1650 filer_set_title(filer_window
);
1651 gtk_widget_set_name(filer_window
->window
, "rox-filer");
1654 gtk_window_set_wmclass(GTK_WINDOW(filer_window
->window
),
1657 /* This property is cleared when the window is destroyed.
1658 * You can thus ref filer_window->window and use this to see
1659 * if the window no longer exists.
1661 g_object_set_data(G_OBJECT(filer_window
->window
),
1662 "filer_window", filer_window
);
1664 /* Create this now to make the Adjustment before the View */
1665 filer_window
->scrollbar
= gtk_vscrollbar_new(NULL
);
1667 vbox
= gtk_vbox_new(FALSE
, 0);
1668 gtk_container_add(GTK_CONTAINER(filer_window
->window
), vbox
);
1670 filer_window
->toplevel_vbox
= GTK_BOX(vbox
);
1672 /* If there's a message that should be displayed in each window (eg
1673 * 'Running as root'), add it here.
1675 if (show_user_message
)
1677 filer_window
->message
= gtk_label_new(show_user_message
);
1678 gtk_box_pack_start(GTK_BOX(vbox
), filer_window
->message
,
1680 gtk_widget_show(filer_window
->message
);
1683 hbox
= gtk_hbox_new(FALSE
, 0);
1684 filer_window
->view_hbox
= GTK_BOX(hbox
);
1685 gtk_box_pack_start_defaults(GTK_BOX(vbox
), hbox
);
1686 /* Add the main View widget */
1687 filer_set_view_type(filer_window
, filer_window
->view_type
);
1688 /* Put the scrollbar next to the View */
1689 gtk_box_pack_end(GTK_BOX(hbox
),
1690 filer_window
->scrollbar
, FALSE
, TRUE
, 0);
1691 gtk_widget_show(hbox
);
1693 /* If we want a toolbar, create it now */
1694 toolbar_update_toolbar(filer_window
);
1696 /* And the minibuffer (hidden to start with) */
1697 create_minibuffer(filer_window
);
1698 gtk_box_pack_end(GTK_BOX(vbox
), filer_window
->minibuffer_area
,
1701 /* And the thumbnail progress bar (also hidden) */
1705 filer_window
->thumb_bar
= gtk_hbox_new(FALSE
, 2);
1706 gtk_box_pack_end(GTK_BOX(vbox
), filer_window
->thumb_bar
,
1709 filer_window
->thumb_progress
= gtk_progress_bar_new();
1711 gtk_box_pack_start(GTK_BOX(filer_window
->thumb_bar
),
1712 filer_window
->thumb_progress
, TRUE
, TRUE
, 0);
1714 cancel
= gtk_button_new_with_label(_("Cancel"));
1715 GTK_WIDGET_UNSET_FLAGS(cancel
, GTK_CAN_FOCUS
);
1716 gtk_box_pack_start(GTK_BOX(filer_window
->thumb_bar
),
1717 cancel
, FALSE
, TRUE
, 0);
1718 g_signal_connect_swapped(cancel
, "clicked",
1719 G_CALLBACK(filer_cancel_thumbnails
),
1723 gtk_widget_show(vbox
);
1724 gtk_widget_show(filer_window
->scrollbar
);
1726 gtk_widget_realize(filer_window
->window
);
1728 gdk_window_set_role(filer_window
->window
->window
,
1729 filer_window
->sym_path
);
1731 filer_window_set_size(filer_window
, 4, 4);
1734 static void filer_add_signals(FilerWindow
*filer_window
)
1736 GtkTargetEntry target_table
[] =
1738 {"text/uri-list", 0, TARGET_URI_LIST
},
1739 {"UTF8_STRING", 0, TARGET_STRING
},
1740 {"STRING", 0, TARGET_STRING
},
1741 {"COMPOUND_TEXT", 0, TARGET_STRING
},/* XXX: Treats as STRING */
1744 /* Events on the top-level window */
1745 gtk_widget_add_events(filer_window
->window
, GDK_ENTER_NOTIFY
);
1746 g_signal_connect(filer_window
->window
, "enter-notify-event",
1747 G_CALLBACK(pointer_in
), filer_window
);
1748 g_signal_connect(filer_window
->window
, "leave-notify-event",
1749 G_CALLBACK(pointer_out
), filer_window
);
1750 g_signal_connect(filer_window
->window
, "destroy",
1751 G_CALLBACK(filer_window_destroyed
), filer_window
);
1752 g_signal_connect(filer_window
->window
, "delete-event",
1753 G_CALLBACK(filer_window_delete
), filer_window
);
1755 g_signal_connect(filer_window
->window
, "selection_clear_event",
1756 G_CALLBACK(filer_lost_primary
), filer_window
);
1758 g_signal_connect(filer_window
->window
, "selection_get",
1759 G_CALLBACK(selection_get
), filer_window
);
1760 gtk_selection_add_targets(GTK_WIDGET(filer_window
->window
),
1761 GDK_SELECTION_PRIMARY
,
1763 sizeof(target_table
) / sizeof(*target_table
));
1765 g_signal_connect(filer_window
->window
, "popup-menu",
1766 G_CALLBACK(popup_menu
), filer_window
);
1767 g_signal_connect(filer_window
->window
, "key_press_event",
1768 G_CALLBACK(filer_key_press_event
), filer_window
);
1770 gtk_window_add_accel_group(GTK_WINDOW(filer_window
->window
),
1774 static gint
clear_scanning_display(FilerWindow
*filer_window
)
1776 if (filer_exists(filer_window
))
1777 filer_set_title(filer_window
);
1781 static void set_scanning_display(FilerWindow
*filer_window
, gboolean scanning
)
1783 if (scanning
== filer_window
->scanning
)
1785 filer_window
->scanning
= scanning
;
1788 filer_set_title(filer_window
);
1790 g_timeout_add(300, (GSourceFunc
) clear_scanning_display
,
1794 /* Note that filer_window may not exist after this call.
1795 * Returns TRUE iff the directory still exists.
1797 gboolean
filer_update_dir(FilerWindow
*filer_window
, gboolean warning
)
1799 gboolean still_exists
;
1801 still_exists
= may_rescan(filer_window
, warning
);
1804 dir_update(filer_window
->directory
, filer_window
->sym_path
);
1806 return still_exists
;
1809 void filer_update_all(void)
1811 GList
*next
= all_filer_windows
;
1815 FilerWindow
*filer_window
= (FilerWindow
*) next
->data
;
1817 /* Updating directory may remove it from list -- stop sending
1818 * patches to move this line!
1822 /* Don't trigger a refresh if we're already scanning.
1823 * Otherwise, two views of a single directory will trigger
1826 if (filer_window
->directory
&&
1827 !filer_window
->directory
->scanning
)
1828 filer_update_dir(filer_window
, TRUE
);
1832 /* Refresh the various caches even if we don't think we need to */
1833 void full_refresh(void)
1836 reread_mime_files(); /* Refreshes all windows */
1839 /* See whether a filer window with a given path already exists
1840 * and is different from diff.
1842 static FilerWindow
*find_filer_window(const char *sym_path
, FilerWindow
*diff
)
1846 for (next
= all_filer_windows
; next
; next
= next
->next
)
1848 FilerWindow
*filer_window
= (FilerWindow
*) next
->data
;
1850 if (filer_window
!= diff
&&
1851 strcmp(sym_path
, filer_window
->sym_path
) == 0)
1852 return filer_window
;
1858 /* This path has been mounted/umounted/deleted some files - update all dirs */
1859 void filer_check_mounted(const char *real_path
)
1861 GList
*next
= all_filer_windows
;
1864 gboolean resize
= o_filer_auto_resize
.int_value
== RESIZE_ALWAYS
;
1866 /* DOS disks, etc, often don't change the mtime of the root directory
1867 * on modification, so force a refresh now.
1869 g_fscache_update(dir_cache
, real_path
);
1871 len
= strlen(real_path
);
1875 FilerWindow
*filer_window
= (FilerWindow
*) next
->data
;
1879 if (strncmp(real_path
, filer_window
->real_path
, len
) == 0)
1881 char s
= filer_window
->real_path
[len
];
1883 if (s
== '/' || s
== '\0')
1885 if (filer_update_dir(filer_window
, FALSE
) &&
1887 view_autosize(filer_window
->view
);
1892 parent
= g_path_get_dirname(real_path
);
1893 refresh_dirs(parent
);
1896 icons_may_update(real_path
);
1899 /* Close all windows displaying 'path' or subdirectories of 'path' */
1900 void filer_close_recursive(const char *path
)
1902 GList
*next
= all_filer_windows
;
1906 real
= pathdup(path
);
1911 FilerWindow
*filer_window
= (FilerWindow
*) next
->data
;
1915 if (strncmp(real
, filer_window
->real_path
, len
) == 0)
1917 char s
= filer_window
->real_path
[len
];
1919 if (len
== 1 || s
== '/' || s
== '\0')
1920 gtk_widget_destroy(filer_window
->window
);
1925 /* Like minibuffer_show(), except that:
1926 * - It returns FALSE (to be used from an idle callback)
1927 * - It checks that the filer window still exists.
1929 static gboolean
minibuffer_show_cb(FilerWindow
*filer_window
)
1931 if (filer_exists(filer_window
))
1932 minibuffer_show(filer_window
, MINI_PATH
);
1936 /* TRUE iff filer_window points to an existing FilerWindow
1939 gboolean
filer_exists(FilerWindow
*filer_window
)
1943 for (next
= all_filer_windows
; next
; next
= next
->next
)
1945 FilerWindow
*fw
= (FilerWindow
*) next
->data
;
1947 if (fw
== filer_window
)
1954 FilerWindow
*filer_get_by_id(const char *id
)
1956 return g_hash_table_lookup(window_with_id
, id
);
1959 void filer_set_id(FilerWindow
*filer_window
, const char *id
)
1961 g_return_if_fail(filer_window
!= NULL
);
1963 if (filer_window
->window_id
)
1965 g_hash_table_remove(window_with_id
, filer_window
->window_id
);
1966 g_free(filer_window
->window_id
);
1967 filer_window
->window_id
= NULL
;
1972 filer_window
->window_id
= g_strdup(id
);
1973 g_hash_table_insert(window_with_id
,
1974 filer_window
->window_id
,
1979 /* Make sure the window title is up-to-date */
1980 void filer_set_title(FilerWindow
*filer_window
)
1982 gchar
*title
= NULL
;
1985 if (filer_window
->scanning
||
1986 filer_window
->filter
!= FILER_SHOW_ALL
||
1987 filer_window
->show_hidden
|| filer_window
->show_thumbs
)
1989 if (o_short_flag_names
.int_value
)
1991 const gchar
*hidden
= "";
1993 switch(filer_window
->filter
) {
1994 case FILER_SHOW_ALL
:
1995 hidden
=filer_window
->show_hidden
? _("A") : "";
1997 case FILER_SHOW_GLOB
: hidden
= _("G"); break;
2001 flags
= g_strconcat(" +",
2002 filer_window
->scanning
? _("S") : "",
2004 filer_window
->show_thumbs
? _("T") : "",
2009 gchar
*hidden
= NULL
;
2011 switch(filer_window
->filter
) {
2012 case FILER_SHOW_ALL
:
2013 hidden
= g_strdup(filer_window
->show_hidden
2016 case FILER_SHOW_GLOB
:
2017 hidden
= g_strdup_printf(_("Glob (%s), "),
2018 filer_window
->filter_string
);
2021 hidden
=g_strdup("");
2024 flags
= g_strconcat(" (",
2025 filer_window
->scanning
? _("Scanning, ") : "",
2027 filer_window
->show_thumbs
? _("Thumbs, ") : "",
2029 flags
[strlen(flags
) - 2] = ')';
2035 title
= g_strconcat("//", our_host_name(),
2036 filer_window
->sym_path
, flags
, NULL
);
2038 if (!title
&& home_dir_len
> 1 &&
2039 strncmp(filer_window
->sym_path
, home_dir
, home_dir_len
) == 0)
2041 guchar sep
= filer_window
->sym_path
[home_dir_len
];
2043 if (sep
== '\0' || sep
== '/')
2044 title
= g_strconcat("~",
2045 filer_window
->sym_path
+ home_dir_len
,
2051 title
= g_strconcat(filer_window
->sym_path
, flags
, NULL
);
2053 ensure_utf8(&title
);
2055 if (filer_window
->directory
->error
)
2058 title
= g_strconcat(old
, ": ", filer_window
->directory
->error
,
2063 gtk_window_set_title(GTK_WINDOW(filer_window
->window
), title
);
2067 if (flags
[0] != '\0')
2071 /* Reconnect to the same directory (used when the Show Hidden option is
2072 * toggled). This has the side-effect of updating the window title.
2074 void filer_detach_rescan(FilerWindow
*filer_window
)
2076 Directory
*dir
= filer_window
->directory
;
2079 detach(filer_window
);
2080 filer_window
->directory
= dir
;
2081 attach(filer_window
);
2084 /* Puts the filer window into target mode. When an item is chosen,
2085 * fn(filer_window, iter, data) is called. 'reason' will be displayed
2086 * on the toolbar while target mode is active.
2088 * Use fn == NULL to cancel target mode.
2090 void filer_target_mode(FilerWindow
*filer_window
,
2095 TargetFunc old_fn
= filer_window
->target_cb
;
2098 gdk_window_set_cursor(
2099 GTK_WIDGET(filer_window
->view
)->window
,
2100 fn
? crosshair
: NULL
);
2102 filer_window
->target_cb
= fn
;
2103 filer_window
->target_data
= data
;
2105 if (filer_window
->toolbar_text
== NULL
)
2110 GTK_LABEL(filer_window
->toolbar_text
), reason
);
2111 else if (o_toolbar_info
.int_value
)
2114 toolbar_update_info(filer_window
);
2117 gtk_label_set_text(GTK_LABEL(filer_window
->toolbar_text
), "");
2120 static void set_selection_state(FilerWindow
*filer_window
, gboolean normal
)
2122 GtkStateType old_state
= filer_window
->selection_state
;
2124 filer_window
->selection_state
= normal
2125 ? GTK_STATE_SELECTED
: GTK_STATE_INSENSITIVE
;
2127 if (old_state
!= filer_window
->selection_state
2128 && view_count_selected(filer_window
->view
))
2129 gtk_widget_queue_draw(GTK_WIDGET(filer_window
->view
));
2132 void filer_cancel_thumbnails(FilerWindow
*filer_window
)
2134 gtk_widget_hide(filer_window
->thumb_bar
);
2136 destroy_glist(&filer_window
->thumb_queue
);
2137 filer_window
->max_thumbs
= 0;
2140 /* Generate the next thumb for this window. The window object is
2141 * unref'd when there is nothing more to do.
2142 * If the window no longer has a filer window, nothing is done.
2144 static gboolean
filer_next_thumb_real(GObject
*window
)
2146 FilerWindow
*filer_window
;
2150 filer_window
= g_object_get_data(window
, "filer_window");
2154 g_object_unref(window
);
2158 if (!filer_window
->thumb_queue
)
2160 filer_cancel_thumbnails(filer_window
);
2161 g_object_unref(window
);
2165 total
= filer_window
->max_thumbs
;
2166 done
= total
- g_list_length(filer_window
->thumb_queue
);
2168 path
= (gchar
*) filer_window
->thumb_queue
->data
;
2170 pixmap_background_thumb(path
, (GFunc
) filer_next_thumb
, window
);
2172 filer_window
->thumb_queue
= g_list_remove(filer_window
->thumb_queue
,
2176 gtk_progress_bar_set_fraction(
2177 GTK_PROGRESS_BAR(filer_window
->thumb_progress
),
2178 done
/ (float) total
);
2183 /* path is the thumb just loaded, if any.
2184 * window is unref'd (eventually).
2186 static void filer_next_thumb(GObject
*window
, const gchar
*path
)
2189 dir_force_update_path(path
);
2191 g_idle_add((GSourceFunc
) filer_next_thumb_real
, window
);
2194 static void start_thumb_scanning(FilerWindow
*filer_window
)
2196 if (GTK_WIDGET_VISIBLE(filer_window
->thumb_bar
))
2197 return; /* Already scanning */
2199 gtk_widget_show_all(filer_window
->thumb_bar
);
2201 g_object_ref(G_OBJECT(filer_window
->window
));
2202 filer_next_thumb(G_OBJECT(filer_window
->window
), NULL
);
2205 /* Set this image to be loaded some time in the future */
2206 void filer_create_thumb(FilerWindow
*filer_window
, const gchar
*path
)
2208 if (g_list_find_custom(filer_window
->thumb_queue
, path
,
2209 (GCompareFunc
) strcmp
))
2212 if (!filer_window
->thumb_queue
)
2213 filer_window
->max_thumbs
=0;
2214 filer_window
->max_thumbs
++;
2216 filer_window
->thumb_queue
= g_list_append(filer_window
->thumb_queue
,
2219 if (filer_window
->scanning
)
2220 return; /* Will start when scan ends */
2222 start_thumb_scanning(filer_window
);
2225 /* If thumbnail display is on, look through all the items in this directory
2226 * and start creating or updating the thumbnails as needed.
2228 void filer_create_thumbs(FilerWindow
*filer_window
)
2233 if (!filer_window
->show_thumbs
)
2236 view_get_iter(filer_window
->view
, &iter
, 0);
2238 while ((item
= iter
.next(&iter
)))
2240 MaskedPixmap
*pixmap
;
2244 if (item
->base_type
!= TYPE_FILE
)
2247 /*if (strcmp(item->mime_type->media_type, "image") != 0)
2250 path
= make_path(filer_window
->real_path
, item
->leafname
);
2252 pixmap
= g_fscache_lookup_full(pixmap_cache
, path
,
2253 FSCACHE_LOOKUP_ONLY_NEW
, &found
);
2255 g_object_unref(pixmap
);
2257 /* If we didn't get an image, it could be because:
2259 * - We're loading the image now. found is TRUE,
2260 * and we'll update the item later.
2261 * - We tried to load the image and failed. found
2263 * - We haven't tried loading the image. found is
2264 * FALSE, and we start creating the thumb here.
2267 filer_create_thumb(filer_window
, path
);
2271 static void filer_options_changed(void)
2273 if (o_short_flag_names
.has_changed
)
2277 for (next
= all_filer_windows
; next
; next
= next
->next
)
2279 FilerWindow
*filer_window
= (FilerWindow
*) next
->data
;
2281 filer_set_title(filer_window
);
2286 /* Append interesting information to this GString */
2287 void filer_add_tip_details(FilerWindow
*filer_window
,
2288 GString
*tip
, DirItem
*item
)
2290 const guchar
*fullpath
= NULL
;
2292 fullpath
= make_path(filer_window
->real_path
, item
->leafname
);
2294 if (item
->flags
& ITEM_FLAG_SYMLINK
)
2298 target
= readlink_dup(fullpath
);
2301 ensure_utf8(&target
);
2303 g_string_append(tip
, _("Symbolic link to "));
2304 g_string_append(tip
, target
);
2305 g_string_append_c(tip
, '\n');
2310 if (item
->flags
& ITEM_FLAG_APPDIR
)
2315 info
= appinfo_get(fullpath
, item
);
2316 if (info
&& ((node
= xml_get_section(info
, NULL
, "Summary"))))
2319 str
= xmlNodeListGetString(node
->doc
,
2320 node
->xmlChildrenNode
, 1);
2323 g_string_append(tip
, str
);
2324 g_string_append_c(tip
, '\n');
2329 g_object_unref(info
);
2331 else if (item
->mime_type
== application_x_desktop
)
2334 summary
= tip_from_desktop_file(fullpath
);
2337 g_string_append(tip
, summary
);
2338 g_string_append_c(tip
, '\n');
2343 if (!g_utf8_validate(item
->leafname
, -1, NULL
))
2344 g_string_append(tip
,
2345 _("This filename is not valid UTF-8. "
2346 "You should rename it.\n"));
2349 /* Return the selection as a text/uri-list.
2350 * g_free() the result.
2352 static guchar
*filer_create_uri_list(FilerWindow
*filer_window
)
2360 g_return_val_if_fail(filer_window
!= NULL
, NULL
);
2362 string
= g_string_new(NULL
);
2364 leader
= g_string_new(filer_window
->sym_path
);
2365 if (leader
->str
[leader
->len
- 1] != '/')
2366 g_string_append_c(leader
, '/');
2368 view_get_iter(filer_window
->view
, &iter
, VIEW_ITER_SELECTED
);
2369 while ((item
= iter
.next(&iter
)))
2374 path
= g_strconcat(leader
->str
, item
->leafname
, NULL
);
2375 uri
= encode_path_as_uri(path
);
2376 g_string_append(string
, (char *) uri
);
2377 g_string_append(string
, "\r\n");
2382 g_string_free(leader
, TRUE
);
2383 retval
= string
->str
;
2384 g_string_free(string
, FALSE
);
2389 void filer_perform_action(FilerWindow
*filer_window
, GdkEventButton
*event
)
2392 ViewIface
*view
= filer_window
->view
;
2393 DirItem
*item
= NULL
;
2394 gboolean press
= event
->type
== GDK_BUTTON_PRESS
;
2396 OpenFlags flags
= 0;
2398 if (event
->button
> 3)
2401 view_get_iter_at_point(view
, &iter
, event
->window
, event
->x
, event
->y
);
2402 item
= iter
.peek(&iter
);
2404 if (item
&& view_cursor_visible(view
))
2405 view_cursor_to_iter(view
, &iter
);
2407 if (item
&& event
->button
== 1 &&
2408 view_get_selected(view
, &iter
) &&
2409 filer_window
->selection_state
== GTK_STATE_INSENSITIVE
)
2411 /* Possibly a really slow DnD operation? */
2412 filer_window
->temp_item_selected
= FALSE
;
2414 filer_selection_changed(filer_window
, event
->time
);
2418 if (filer_window
->target_cb
)
2420 dnd_motion_ungrab();
2421 if (item
&& press
&& event
->button
== 1)
2422 filer_window
->target_cb(filer_window
, &iter
,
2423 filer_window
->target_data
);
2425 filer_target_mode(filer_window
, NULL
, NULL
, NULL
);
2430 if (!o_single_click
.int_value
)
2432 /* Make sure both parts of a double-click fall on
2435 static guchar
*first_click
= NULL
;
2436 static guchar
*second_click
= NULL
;
2438 if (event
->type
== GDK_BUTTON_PRESS
)
2440 g_free(first_click
);
2441 first_click
= second_click
;
2444 second_click
= g_strdup(item
->leafname
);
2446 second_click
= NULL
;
2449 if (event
->type
== GDK_2BUTTON_PRESS
)
2451 if (first_click
&& second_click
&&
2452 strcmp(first_click
, second_click
) != 0)
2454 if ((first_click
|| second_click
) &&
2455 !(first_click
&& second_click
))
2460 action
= bind_lookup_bev(
2461 item
? BIND_DIRECTORY_ICON
: BIND_DIRECTORY
,
2466 case ACT_CLEAR_SELECTION
:
2467 view_clear_selection(view
);
2469 case ACT_TOGGLE_SELECTED
:
2470 view_set_selected(view
, &iter
,
2471 !view_get_selected(view
, &iter
));
2473 case ACT_SELECT_EXCL
:
2474 view_select_only(view
, &iter
);
2477 flags
|= OPEN_SHIFT
;
2480 if (event
->button
!= 1 || event
->state
& GDK_MOD1_MASK
)
2481 flags
|= OPEN_CLOSE_WINDOW
;
2483 flags
|= OPEN_SAME_WINDOW
;
2484 if (o_new_button_1
.int_value
)
2485 flags
^= OPEN_SAME_WINDOW
;
2486 if (event
->type
== GDK_2BUTTON_PRESS
)
2487 view_set_selected(view
, &iter
, FALSE
);
2488 dnd_motion_ungrab();
2490 filer_openitem(filer_window
, &iter
, flags
);
2492 case ACT_POPUP_MENU
:
2493 dnd_motion_ungrab();
2495 show_filer_menu(filer_window
,
2496 (GdkEvent
*) event
, &iter
);
2498 case ACT_PRIME_AND_SELECT
:
2499 if (item
&& !view_get_selected(view
, &iter
))
2500 view_select_only(view
, &iter
);
2501 dnd_motion_start(MOTION_READY_FOR_DND
);
2503 case ACT_PRIME_AND_TOGGLE
:
2504 view_set_selected(view
, &iter
,
2505 !view_get_selected(view
, &iter
));
2506 dnd_motion_start(MOTION_READY_FOR_DND
);
2508 case ACT_PRIME_FOR_DND
:
2509 dnd_motion_start(MOTION_READY_FOR_DND
);
2512 if (press
&& event
->button
< 4)
2515 view_wink_item(view
, &iter
);
2516 dnd_motion_start(MOTION_NONE
);
2519 case ACT_LASSO_CLEAR
:
2520 view_clear_selection(view
);
2522 case ACT_LASSO_MODIFY
:
2523 view_start_lasso_box(view
, event
);
2526 view_autosize(filer_window
->view
);
2529 g_warning("Unsupported action : %d\n", action
);
2534 /* It's time to make the tooltip appear. If we're not over the item any
2535 * more, or the item doesn't need a tooltip, do nothing.
2537 static gboolean
tooltip_activate(GtkWidget
*window
)
2539 FilerWindow
*filer_window
;
2543 DirItem
*item
= NULL
;
2544 GString
*tip
= NULL
;
2546 g_return_val_if_fail(tip_item
!= NULL
, 0);
2548 filer_window
= g_object_get_data(G_OBJECT(window
), "filer_window");
2550 if (!motion_window
|| !filer_window
)
2551 return FALSE
; /* Window has been destroyed */
2553 view
= filer_window
->view
;
2557 gdk_window_get_pointer(motion_window
, &x
, &y
, NULL
);
2558 view_get_iter_at_point(view
, &iter
, motion_window
, x
, y
);
2560 item
= iter
.peek(&iter
);
2561 if (item
!= tip_item
)
2562 return FALSE
; /* Not still under the pointer */
2564 /* OK, the filer window still exists and the pointer is still
2565 * over the same item. Do we need to show a tip?
2568 tip
= g_string_new(NULL
);
2570 view_extend_tip(filer_window
->view
, &iter
, tip
);
2572 filer_add_tip_details(filer_window
, tip
, tip_item
);
2576 g_string_truncate(tip
, tip
->len
- 1);
2578 tooltip_show(tip
->str
);
2581 g_string_free(tip
, TRUE
);
2586 /* Motion detected on the View widget */
2587 gint
filer_motion_notify(FilerWindow
*filer_window
, GdkEventMotion
*event
)
2589 ViewIface
*view
= filer_window
->view
;
2593 view_get_iter_at_point(view
, &iter
, event
->window
, event
->x
, event
->y
);
2594 item
= iter
.peek(&iter
);
2598 if (item
!= tip_item
)
2603 motion_window
= event
->window
;
2604 tooltip_prime((GtkFunction
) tooltip_activate
,
2605 G_OBJECT(filer_window
->window
));
2614 if (motion_state
!= MOTION_READY_FOR_DND
)
2617 if (!dnd_motion_moved(event
))
2620 view_get_iter_at_point(view
, &iter
,
2622 event
->x
- (event
->x_root
- drag_start_x
),
2623 event
->y
- (event
->y_root
- drag_start_y
));
2624 item
= iter
.peek(&iter
);
2628 view_wink_item(view
, NULL
);
2630 if (!view_get_selected(view
, &iter
))
2632 if (event
->state
& GDK_BUTTON1_MASK
)
2634 /* Select just this one */
2635 filer_window
->temp_item_selected
= TRUE
;
2636 view_select_only(view
, &iter
);
2640 if (view_count_selected(view
) == 0)
2641 filer_window
->temp_item_selected
= TRUE
;
2642 view_set_selected(view
, &iter
, TRUE
);
2646 g_return_val_if_fail(view_count_selected(view
) > 0, TRUE
);
2648 if (view_count_selected(view
) == 1)
2650 if (item
->base_type
== TYPE_UNKNOWN
)
2651 item
= dir_update_item(filer_window
->directory
,
2656 report_error(_("Item no longer exists!"));
2660 drag_one_item(GTK_WIDGET(view
), event
,
2661 make_path(filer_window
->sym_path
, item
->leafname
),
2662 item
, di_image(item
));
2664 /* XXX: Use thumbnail */
2665 item
, view
? view
->image
: NULL
);
2672 uris
= filer_create_uri_list(filer_window
);
2673 drag_selection(GTK_WIDGET(view
), event
, uris
);
2680 static void drag_end(GtkWidget
*widget
, GdkDragContext
*context
,
2681 FilerWindow
*filer_window
)
2683 filer_set_autoscroll(filer_window
, FALSE
);
2685 if (filer_window
->temp_item_selected
)
2687 view_clear_selection(filer_window
->view
);
2688 filer_window
->temp_item_selected
= FALSE
;
2692 /* Remove highlights */
2693 static void drag_leave(GtkWidget
*widget
,
2694 GdkDragContext
*context
,
2696 FilerWindow
*filer_window
)
2701 /* Called during the drag when the mouse is in a widget registered
2702 * as a drop target. Returns TRUE if we can accept the drop.
2704 static gboolean
drag_motion(GtkWidget
*widget
,
2705 GdkDragContext
*context
,
2709 FilerWindow
*filer_window
)
2712 ViewIface
*view
= filer_window
->view
;
2714 GdkDragAction action
= context
->suggested_action
;
2715 const guchar
*new_path
= NULL
;
2716 const char *type
= NULL
;
2717 gboolean retval
= FALSE
;
2718 gboolean same_window
;
2720 if ((context
->actions
& GDK_ACTION_ASK
) && o_dnd_left_menu
.int_value
)
2723 gdk_window_get_pointer(NULL
, NULL
, NULL
, &state
);
2724 if (state
& GDK_BUTTON1_MASK
)
2725 action
= GDK_ACTION_ASK
;
2728 same_window
= gtk_drag_get_source_widget(context
) == widget
;
2730 filer_set_autoscroll(filer_window
, TRUE
);
2732 if (filer_window
->view_type
== VIEW_TYPE_DETAILS
)
2736 /* Correct for position of bin window */
2737 bin
= gtk_tree_view_get_bin_window(GTK_TREE_VIEW(view
));
2738 gdk_window_get_position(bin
, NULL
, &bin_y
);
2742 if (o_dnd_drag_to_icons
.int_value
)
2744 view_get_iter_at_point(view
, &iter
, widget
->window
, x
, y
);
2745 item
= iter
.peek(&iter
);
2750 if (item
&& same_window
&& view_get_selected(view
, &iter
))
2753 type
= dnd_motion_item(context
, &item
);
2758 /* Don't allow drops to non-writeable directories. BUT, still
2759 * allow drops on non-writeable SUBdirectories so that we can
2760 * do the spring-open thing.
2762 if (item
&& type
== drop_dest_dir
&&
2763 !(item
->flags
& ITEM_FLAG_APPDIR
))
2765 dnd_spring_load(context
, filer_window
);
2771 view_cursor_to_iter(view
, &iter
);
2774 view_cursor_to_iter(view
, NULL
);
2776 /* Disallow background drops within a single window */
2777 if (type
&& same_window
)
2784 new_path
= make_path(filer_window
->sym_path
,
2787 new_path
= filer_window
->sym_path
;
2790 /* Don't ask about dragging to an application! */
2791 if (type
== drop_dest_prog
&& action
== GDK_ACTION_ASK
)
2792 action
= GDK_ACTION_COPY
;
2794 g_dataset_set_data(context
, "drop_dest_type", (gpointer
) type
);
2797 gdk_drag_status(context
, action
, time
);
2798 g_dataset_set_data_full(context
, "drop_dest_path",
2799 g_strdup(new_path
), g_free
);
2806 static gboolean
as_timeout(FilerWindow
*filer_window
)
2810 retval
= view_auto_scroll_callback(filer_window
->view
);
2813 filer_window
->auto_scroll
= -1;
2818 /* When autoscroll is on, a timer keeps track of the pointer position.
2819 * While it's near the top or bottom of the window, the window scrolls.
2821 * If the mouse buttons are released, the pointer leaves the window, or
2822 * a drag-and-drop operation finishes, auto_scroll is turned off.
2824 void filer_set_autoscroll(FilerWindow
*filer_window
, gboolean auto_scroll
)
2826 g_return_if_fail(filer_window
!= NULL
);
2830 if (filer_window
->auto_scroll
!= -1)
2831 return; /* Already on! */
2833 filer_window
->auto_scroll
= g_timeout_add(50,
2834 (GSourceFunc
) as_timeout
,
2839 if (filer_window
->auto_scroll
== -1)
2840 return; /* Already off! */
2842 g_source_remove(filer_window
->auto_scroll
);
2843 filer_window
->auto_scroll
= -1;
2847 #define ZERO_MNT "/uri/0install"
2849 static void refresh_done(FilerWindow
*filer_window
)
2851 if (filer_exists(filer_window
))
2852 filer_update_dir(filer_window
, TRUE
);
2855 void filer_refresh(FilerWindow
*filer_window
)
2857 if (!strncmp(ZERO_MNT
"/", filer_window
->real_path
, sizeof(ZERO_MNT
)))
2859 /* Try to run 0refresh */
2861 gchar
*argv
[] = {"0refresh", NULL
, NULL
};
2862 const char *host
= filer_window
->real_path
+ sizeof(ZERO_MNT
);
2865 slash
= strchr(host
, '/');
2867 argv
[1] = g_strndup(host
, slash
- host
);
2869 argv
[1] = g_strdup(host
);
2870 pid
= rox_spawn(filer_window
->real_path
, (const char **) argv
);
2873 on_child_death(pid
, (CallbackFn
) refresh_done
,
2880 gboolean
filer_match_filter(FilerWindow
*filer_window
, const gchar
*filename
)
2882 g_return_val_if_fail(filename
!= NULL
, FALSE
);
2884 if(filename
[0]=='.' &&
2885 (!filer_window
->temp_show_hidden
&& !filer_window
->show_hidden
))
2888 switch(filer_window
->filter
) {
2889 case FILER_SHOW_GLOB
:
2890 return fnmatch(filer_window
->filter_string
,
2893 case FILER_SHOW_ALL
:
2900 /* Provided to hide the implementation */
2901 void filer_set_hidden(FilerWindow
*filer_window
, gboolean hidden
)
2903 filer_window
->show_hidden
=hidden
;
2906 /* Set the filter type. Returns TRUE if the type has changed
2907 * (must call filer_detach_rescan).
2909 gboolean
filer_set_filter(FilerWindow
*filer_window
, FilterType type
,
2910 const gchar
*filter_string
)
2912 /* Is this new filter the same as the old one? */
2913 if (filer_window
->filter
== type
)
2915 switch(filer_window
->filter
)
2917 case FILER_SHOW_ALL
:
2919 case FILER_SHOW_GLOB
:
2920 if (strcmp(filer_window
->filter_string
,
2921 filter_string
) == 0)
2927 /* Clean up old filter */
2928 if (filer_window
->filter_string
)
2930 g_free(filer_window
->filter_string
);
2931 filer_window
->filter_string
= NULL
;
2933 /* Also clean up compiled regexp when implemented */
2935 filer_window
->filter
= type
;
2939 case FILER_SHOW_ALL
:
2943 case FILER_SHOW_GLOB
:
2944 filer_window
->filter_string
= g_strdup(filter_string
);
2949 filer_window
->filter
= FILER_SHOW_ALL
;
2950 g_warning("Impossible: filter type %d", type
);
2958 static Settings
*settings_new(const char *path
)
2962 set
=g_new(Settings
, 1);
2963 memset(set
, 0, sizeof(Settings
));
2965 set
->path
=g_strdup(path
);
2970 static void settings_free(Settings
*set
)
2974 g_free(set
->filter
);
2978 static void store_settings(Settings
*set
)
2982 old
=g_hash_table_lookup(settings_table
, set
->path
);
2985 g_hash_table_remove(settings_table
, set
->path
);
2989 g_hash_table_insert(settings_table
, set
->path
, set
);
2992 /* TODO: use symbolic names in the XML file where possible */
2993 static void load_from_node(Settings
*set
, xmlDocPtr doc
, xmlNodePtr node
)
2997 str
=xmlNodeListGetString(doc
, node
->xmlChildrenNode
, 1);
2999 if(strcmp(node
->name
, "X") == 0) {
3001 set
->flags
|=SET_POSITION
;
3002 } else if(strcmp(node
->name
, "Y") == 0) {
3004 set
->flags
|=SET_POSITION
;
3005 } else if(strcmp(node
->name
, "Width") == 0) {
3006 set
->width
=atoi(str
);
3007 set
->flags
|=SET_SIZE
;
3008 } else if(strcmp(node
->name
, "Height") == 0) {
3009 set
->height
=atoi(str
);
3010 set
->flags
|=SET_SIZE
;
3011 } else if(strcmp(node
->name
, "ShowHidden") == 0) {
3012 set
->show_hidden
=atoi(str
);
3013 set
->flags
|=SET_HIDDEN
;
3014 } else if(strcmp(node
->name
, "ViewType") == 0) {
3015 set
->view_type
=atoi(str
);
3016 set
->flags
|=SET_DETAILS
;
3017 } else if(strcmp(node
->name
, "DetailsType") == 0) {
3018 set
->details_type
=atoi(str
);
3019 set
->flags
|=SET_DETAILS
;
3020 } else if(strcmp(node
->name
, "SortType") == 0) {
3021 set
->sort_type
=atoi(str
);
3022 set
->flags
|=SET_SORT
;
3023 } else if(strcmp(node
->name
, "SortOrder") == 0) {
3024 set
->sort_order
=atoi(str
);
3025 set
->flags
|=SET_SORT
;
3026 } else if(strcmp(node
->name
, "DisplayStyle") == 0) {
3027 set
->display_style
=atoi(str
);
3028 set
->flags
|=SET_STYLE
;
3029 } else if(strcmp(node
->name
, "ShowThumbs") == 0) {
3030 set
->show_thumbs
=atoi(str
);
3031 set
->flags
|=SET_THUMBS
;
3032 } else if(strcmp(node
->name
, "FilterType") == 0) {
3033 set
->filter_type
=atoi(str
);
3034 set
->flags
|=SET_FILTER
;
3035 } else if(strcmp(node
->name
, "Filter") == 0) {
3036 set
->filter
=g_strdup(str
);
3037 set
->flags
|=SET_FILTER
;
3044 static void load_settings(void)
3047 XMLwrapper
*settings_doc
=NULL
;
3049 path
=choices_find_xdg_path_load("Settings.xml", PROJECT
, SITE
);
3051 settings_doc
=xml_new(path
);
3056 settings_table
=g_hash_table_new(g_str_hash
, g_str_equal
);
3059 xmlNodePtr node
, subnode
;
3061 node
= xmlDocGetRootElement(settings_doc
->doc
);
3063 for (node
= node
->xmlChildrenNode
; node
; node
= node
->next
)
3068 if (node
->type
!= XML_ELEMENT_NODE
)
3070 if (strcmp(node
->name
, "FilerWindow") != 0)
3073 path
=xmlGetProp(node
, "path");
3074 set
=settings_new(path
);
3077 for (subnode
=node
->xmlChildrenNode
; subnode
;
3078 subnode
=subnode
->next
) {
3080 if (subnode
->type
!= XML_ELEMENT_NODE
)
3082 load_from_node(set
, settings_doc
->doc
,
3086 store_settings(set
);
3088 g_object_unref(settings_doc
);
3092 static void add_nodes(gpointer key
, gpointer value
, gpointer data
)
3094 xmlNodePtr node
=(xmlNodePtr
) data
;
3096 Settings
*set
=(Settings
*) value
;
3099 sub
=xmlNewChild(node
, NULL
, "FilerWindow", NULL
);
3101 xmlSetProp(sub
, "path", set
->path
);
3103 if(set
->flags
& SET_POSITION
) {
3104 tmp
=g_strdup_printf("%d", set
->x
);
3105 xmlNewChild(sub
, NULL
, "X", tmp
);
3107 tmp
=g_strdup_printf("%d", set
->y
);
3108 xmlNewChild(sub
, NULL
, "Y", tmp
);
3111 if(set
->flags
& SET_SIZE
) {
3112 tmp
=g_strdup_printf("%d", set
->width
);
3113 xmlNewChild(sub
, NULL
, "Width", tmp
);
3115 tmp
=g_strdup_printf("%d", set
->height
);
3116 xmlNewChild(sub
, NULL
, "Height", tmp
);
3119 if(set
->flags
& SET_HIDDEN
) {
3120 tmp
=g_strdup_printf("%d", set
->show_hidden
);
3121 xmlNewChild(sub
, NULL
, "ShowHidden", tmp
);
3124 if(set
->flags
& SET_STYLE
) {
3125 tmp
=g_strdup_printf("%d", set
->display_style
);
3126 xmlNewChild(sub
, NULL
, "DisplayStyle", tmp
);
3129 if(set
->flags
& SET_SORT
) {
3130 tmp
=g_strdup_printf("%d", set
->sort_type
);
3131 xmlNewChild(sub
, NULL
, "SortType", tmp
);
3133 tmp
=g_strdup_printf("%d", set
->sort_order
);
3134 xmlNewChild(sub
, NULL
, "SortOrder", tmp
);
3137 if(set
->flags
& SET_DETAILS
) {
3138 tmp
=g_strdup_printf("%d", set
->view_type
);
3139 xmlNewChild(sub
, NULL
, "ViewType", tmp
);
3141 tmp
=g_strdup_printf("%d", set
->details_type
);
3142 xmlNewChild(sub
, NULL
, "DetailsType", tmp
);
3145 if(set
->flags
& SET_STYLE
) {
3146 tmp
=g_strdup_printf("%d", set
->show_thumbs
);
3147 xmlNewChild(sub
, NULL
, "ShowThumbs", tmp
);
3150 if(set
->flags
& SET_FILTER
) {
3151 tmp
=g_strdup_printf("%d", set
->filter_type
);
3152 xmlNewChild(sub
, NULL
, "FilterType", tmp
);
3154 if(set
->filter
&& set
->filter
[0])
3155 xmlNewChild(sub
, NULL
, "Filter", set
->filter
);
3159 static void save_settings(void)
3163 path
=choices_find_xdg_path_save("Settings.xml", PROJECT
, SITE
, TRUE
);
3165 xmlDocPtr doc
= xmlNewDoc("1.0");
3166 xmlDocSetRootElement(doc
, xmlNewDocNode(doc
, NULL
,
3169 g_hash_table_foreach(settings_table
, add_nodes
,
3170 xmlDocGetRootElement(doc
));
3172 save_xml_file(doc
, path
);
3180 static void check_settings(FilerWindow
*filer_window
)
3184 set
=(Settings
*) g_hash_table_lookup(settings_table
,
3185 filer_window
->sym_path
);
3188 if(set
->flags
& SET_POSITION
)
3189 gtk_window_move(GTK_WINDOW(filer_window
->window
),
3191 if(set
->flags
& SET_SIZE
)
3192 filer_window_set_size(filer_window
, set
->width
,
3194 if(set
->flags
& SET_HIDDEN
)
3195 filer_set_hidden(filer_window
, set
->show_hidden
);
3197 if(set
->flags
& (SET_STYLE
|SET_DETAILS
)) {
3198 DisplayStyle style
=filer_window
->display_style
;
3199 DetailsType details
=filer_window
->details_type
;
3201 if(set
->flags
& SET_STYLE
)
3202 style
=set
->display_style
;
3204 if(set
->flags
& SET_DETAILS
) {
3205 details
=set
->details_type
;
3207 filer_set_view_type(filer_window
,
3211 display_set_layout(filer_window
, style
,
3215 if(set
->flags
& SET_SORT
)
3216 display_set_sort_type(filer_window
,
3220 if(set
->flags
& SET_THUMBS
)
3221 display_set_thumbs(filer_window
,
3224 if(set
->flags
& SET_FILTER
)
3225 display_set_filter(filer_window
,
3232 typedef struct settings_window
{
3235 GtkWidget
*pos
, *size
, *hidden
, *style
, *sort
, *details
,
3242 static void settings_response(GtkWidget
*window
, gint response
,
3243 SettingsWindow
*set_win
)
3245 if(response
==GTK_RESPONSE_OK
) {
3248 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(set_win
->pos
)))
3249 flags
|=SET_POSITION
;
3250 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(set_win
->size
)))
3252 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(set_win
->hidden
)))
3254 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(set_win
->style
)))
3256 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(set_win
->sort
)))
3258 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(set_win
->details
)))
3260 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(set_win
->thumbs
)))
3262 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(set_win
->filter
)))
3265 set_win
->set
->flags
=flags
;
3266 store_settings(set_win
->set
);
3270 gtk_widget_destroy(window
);
3273 void filer_save_settings(FilerWindow
*fwin
)
3275 SettingsWindow
*set_win
;
3280 Settings
*set
=settings_new(fwin
->sym_path
);
3282 gtk_window_get_position(GTK_WINDOW(fwin
->window
),&x
, &y
);
3283 set
->flags
|=SET_POSITION
;
3287 gtk_window_get_size(GTK_WINDOW(fwin
->window
),&x
, &y
);
3288 set
->flags
|=SET_SIZE
;
3292 set
->flags
|=SET_HIDDEN
;
3293 set
->show_hidden
=fwin
->show_hidden
;
3295 set
->flags
|=SET_STYLE
;
3296 set
->display_style
=fwin
->display_style
;
3298 set
->flags
|=SET_SORT
;
3299 set
->sort_type
=fwin
->sort_type
;
3300 set
->sort_order
=fwin
->sort_order
;
3302 set
->flags
|=SET_DETAILS
;
3303 set
->view_type
=fwin
->view_type
;
3304 set
->details_type
=fwin
->details_type
;
3306 set
->flags
|=SET_THUMBS
;
3307 set
->show_thumbs
=fwin
->show_thumbs
;
3309 set
->flags
|=SET_FILTER
;
3310 set
->filter_type
=fwin
->filter
;
3311 if(fwin
->filter_string
)
3312 set
->filter
=g_strdup(fwin
->filter_string
);
3314 /* Store other parameters
3316 set_win
=g_new(SettingsWindow
, 1);
3318 set_win
->window
=gtk_dialog_new();
3319 number_of_windows
++;
3321 gtk_dialog_add_button(GTK_DIALOG(set_win
->window
),
3322 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
);
3323 gtk_dialog_add_button(GTK_DIALOG(set_win
->window
),
3324 GTK_STOCK_OK
, GTK_RESPONSE_OK
);
3326 g_signal_connect(set_win
->window
, "destroy",
3327 G_CALLBACK(one_less_window
), NULL
);
3328 g_signal_connect_swapped(set_win
->window
, "destroy",
3329 G_CALLBACK(g_free
), set_win
);
3331 gtk_window_set_title(GTK_WINDOW(set_win
->window
),
3332 _("Select display properties to save"));
3334 vbox
=GTK_DIALOG(set_win
->window
)->vbox
;
3336 path
=gtk_label_new(set
->path
);
3337 gtk_box_pack_start(GTK_BOX(vbox
), path
, FALSE
, FALSE
, 2);
3339 set_win
->pos
=gtk_check_button_new_with_label(_("Position"));
3340 gtk_box_pack_start(GTK_BOX(vbox
), set_win
->pos
, FALSE
, FALSE
, 2);
3341 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(set_win
->pos
),
3342 set
->flags
& SET_POSITION
);
3344 set_win
->size
=gtk_check_button_new_with_label(_("Size"));
3345 gtk_box_pack_start(GTK_BOX(vbox
), set_win
->size
, FALSE
, FALSE
, 2);
3346 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(set_win
->size
),
3347 set
->flags
& SET_SIZE
);
3349 set_win
->hidden
=gtk_check_button_new_with_label(_("Show hidden"));
3350 gtk_box_pack_start(GTK_BOX(vbox
), set_win
->hidden
,
3352 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(set_win
->hidden
),
3353 set
->flags
& SET_HIDDEN
);
3355 set_win
->style
=gtk_check_button_new_with_label(_("Display style"));
3356 gtk_box_pack_start(GTK_BOX(vbox
), set_win
->style
,
3358 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(set_win
->style
),
3359 set
->flags
& SET_STYLE
);
3361 set_win
->sort
=gtk_check_button_new_with_label(_("Sort type and order"));
3362 gtk_box_pack_start(GTK_BOX(vbox
), set_win
->sort
, FALSE
, FALSE
, 2);
3363 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(set_win
->sort
),
3364 set
->flags
& SET_SORT
);
3366 set_win
->details
=gtk_check_button_new_with_label(_("Details"));
3367 gtk_box_pack_start(GTK_BOX(vbox
), set_win
->details
, FALSE
, FALSE
, 2);
3368 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(set_win
->details
),
3369 set
->flags
& SET_DETAILS
);
3371 set_win
->thumbs
=gtk_check_button_new_with_label(_("Thumbnails"));
3372 gtk_box_pack_start(GTK_BOX(vbox
), set_win
->thumbs
,
3374 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(set_win
->thumbs
),
3375 set
->flags
& SET_THUMBS
);
3377 set_win
->filter
=gtk_check_button_new_with_label(_("Filter"));
3378 gtk_box_pack_start(GTK_BOX(vbox
), set_win
->filter
,
3380 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(set_win
->filter
),
3381 set
->flags
& SET_FILTER
);
3384 g_signal_connect(set_win
->window
, "response",
3385 G_CALLBACK(settings_response
), set_win
);
3387 gtk_widget_show_all(set_win
->window
);
3390 static char *tip_from_desktop_file(const char *full_path
)
3392 GError
*error
= NULL
;
3393 char *comment
= NULL
;
3395 comment
= get_value_from_desktop_file(full_path
,
3396 "Desktop Entry", "Comment", &error
);
3399 delayed_error("Failed to parse .desktop file '%s':\n%s",
3400 full_path
, error
->message
);
3406 g_error_free(error
);