2 * ROX-Filer, filer for the ROX desktop project
3 * Copyright (C) 2006, Thomas Leonard and others (see changelog for details).
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation; either version 2 of the License, or (at your option)
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
17 * Place, Suite 330, Boston, MA 02111-1307 USA
20 /* filer.c - code for handling filer windows */
30 #include <sys/param.h>
35 #include <gdk/gdkkeysyms.h>
44 #include "gui_support.h"
54 #include "minibuffer.h"
61 #include "view_iface.h"
62 #include "view_collection.h"
63 #include "view_details.h"
65 #include "bookmarks.h"
68 static XMLwrapper
*groups
= NULL
;
70 /* Item we are about to display a tooltip for */
71 static DirItem
*tip_item
= NULL
;
73 /* The window which the motion event for the tooltip came from. Use this
74 * to get the correct widget for finding the item under the pointer.
76 static GdkWindow
*motion_window
= NULL
;
78 /* This is rather badly named. It's actually the filer window which received
79 * the last key press or Menu click event.
81 FilerWindow
*window_with_focus
= NULL
;
83 GList
*all_filer_windows
= NULL
;
85 static GHashTable
*window_with_id
= NULL
;
87 static FilerWindow
*window_with_primary
= NULL
;
89 static GHashTable
*settings_table
=NULL
;
94 guint flags
; /* Which parts are valid, see below */
101 GtkSortType sort_order
;
102 gboolean show_thumbs
;
104 DetailsType details_type
;
105 DisplayStyle display_style
;
107 FilterType filter_type
;
109 gboolean filter_directories
;
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 #define ROX_RESPONSE_EJECT 99 /**< User clicked on Eject button */
176 void filer_init(void)
180 gchar
*dpyhost
, *tmp
;
182 option_add_int(&o_filer_size_limit
, "filer_size_limit", 75);
183 option_add_int(&o_filer_auto_resize
, "filer_auto_resize",
185 option_add_int(&o_unique_filer_windows
, "filer_unique_windows", 0);
187 option_add_int(&o_short_flag_names
, "filer_short_flag_names", FALSE
);
189 option_add_int(&o_filer_view_type
, "filer_view_type",
190 VIEW_TYPE_COLLECTION
);
192 option_add_notify(filer_options_changed
);
194 busy_cursor
= gdk_cursor_new(GDK_WATCH
);
195 crosshair
= gdk_cursor_new(GDK_CROSSHAIR
);
197 window_with_id
= g_hash_table_new_full(g_str_hash
, g_str_equal
,
200 /* Is the display on the local machine, or are we being
201 * run remotely? See filer_set_title().
203 ohost
= our_host_name();
204 dpy
= gdk_get_display();
205 dpyhost
= g_strdup(dpy
);
206 tmp
= strchr(dpyhost
, ':');
210 if (dpyhost
[0] && strcmp(ohost
, dpyhost
) != 0)
212 /* Try the cannonical name for dpyhost (see our_host_name()
217 ent
= gethostbyname(dpyhost
);
218 if (!ent
|| strcmp(ohost
, ent
->h_name
) != 0)
227 static gboolean
if_deleted(gpointer item
, gpointer removed
)
229 int i
= ((GPtrArray
*) removed
)->len
;
230 DirItem
**r
= (DirItem
**) ((GPtrArray
*) removed
)->pdata
;
231 char *leafname
= ((DirItem
*) item
)->leafname
;
235 if (strcmp(leafname
, r
[i
]->leafname
) == 0)
242 #define DECOR_BORDER 32
244 /* Resize the filer window to w x h pixels, plus border (not clamped).
245 * If triggered by a key event, warp the pointer (for SloppyFocus users).
247 void filer_window_set_size(FilerWindow
*filer_window
, int w
, int h
)
251 g_return_if_fail(filer_window
!= NULL
);
253 if (filer_window
->scrollbar
)
254 w
+= filer_window
->scrollbar
->allocation
.width
;
256 if (o_toolbar
.int_value
!= TOOLBAR_NONE
)
257 h
+= filer_window
->toolbar
->allocation
.height
;
258 if (filer_window
->message
)
259 h
+= filer_window
->message
->allocation
.height
;
261 window
= filer_window
->window
;
263 if (GTK_WIDGET_VISIBLE(window
))
266 GtkRequisition
*req
= &window
->requisition
;
267 GdkWindow
*gdk_window
= window
->window
;
270 w
= MAX(req
->width
, w
);
271 h
= MAX(req
->height
, h
);
272 gdk_window_get_pointer(NULL
, &x
, &y
, NULL
);
273 m
= gdk_screen_get_monitor_at_point(gdk_screen_get_default(),
275 gdk_window_get_position(gdk_window
, &x
, &y
);
277 if (x
+ w
+ DECOR_BORDER
>
278 monitor_geom
[m
].x
+ monitor_geom
[m
].width
||
279 y
+ h
+ DECOR_BORDER
>
280 monitor_geom
[m
].y
+ monitor_geom
[m
].height
)
282 if (x
+ w
+ DECOR_BORDER
>
283 monitor_geom
[m
].x
+ monitor_geom
[m
].width
)
285 x
= monitor_geom
[m
].x
+ monitor_geom
[m
].width
-
286 w
- 4 - DECOR_BORDER
;
288 if (y
+ h
+ DECOR_BORDER
>
289 monitor_geom
[m
].y
+ monitor_geom
[m
].height
)
291 y
= monitor_geom
[m
].y
+ monitor_geom
[m
].height
-
292 h
- 4 - DECOR_BORDER
;
294 gdk_window_move_resize(gdk_window
, x
, y
, w
, h
);
297 gdk_window_resize(gdk_window
, w
, h
);
299 /* If the resize was triggered by a key press, keep
300 * the pointer inside the window so that it doesn't
301 * lose focus when using pointer-follows-mouse.
303 event
= gtk_get_current_event();
304 if (event
&& event
->type
== GDK_KEY_PRESS
)
309 GdkWindow
*win
= filer_window
->window
->window
;
311 gdk_window_get_pointer(filer_window
->window
->window
,
314 nx
= CLAMP(x
, 4, w
- 4);
315 ny
= CLAMP(y
, 4, h
- 4);
317 if (nx
!= x
|| ny
!= y
)
319 XWarpPointer(gdk_x11_drawable_get_xdisplay(win
),
321 gdk_x11_drawable_get_xid(win
),
327 gdk_event_free(event
);
330 gtk_window_set_default_size(GTK_WINDOW(window
), w
, h
);
333 /* Called on a timeout while scanning or when scanning ends
334 * (whichever happens first).
336 static gint
open_filer_window(FilerWindow
*filer_window
)
338 Settings
*dir_settings
;
339 gboolean force_resize
;
341 dir_settings
= (Settings
*) g_hash_table_lookup(settings_table
,
342 filer_window
->sym_path
);
344 force_resize
= !(o_filer_auto_resize
.int_value
== RESIZE_NEVER
&&
345 dir_settings
&& dir_settings
->flags
& SET_POSITION
);
347 view_style_changed(filer_window
->view
, 0);
349 if (filer_window
->open_timeout
)
351 g_source_remove(filer_window
->open_timeout
);
352 filer_window
->open_timeout
= 0;
355 if (!GTK_WIDGET_VISIBLE(filer_window
->window
))
357 display_set_actual_size(filer_window
, force_resize
);
358 gtk_widget_show(filer_window
->window
);
364 /* Look through all items we want to display, and queue a recheck on any
367 static void queue_interesting(FilerWindow
*filer_window
)
372 view_get_iter(filer_window
->view
, &iter
, 0);
373 while ((item
= iter
.next(&iter
)))
375 if (item
->flags
& ITEM_FLAG_NEED_RESCAN_QUEUE
)
376 dir_queue_recheck(filer_window
->directory
, item
);
380 static void update_display(Directory
*dir
,
383 FilerWindow
*filer_window
)
385 ViewIface
*view
= (ViewIface
*) filer_window
->view
;
390 view_add_items(view
, items
);
391 /* Open and resize if currently hidden */
392 open_filer_window(filer_window
);
395 view_delete_if(view
, if_deleted
, items
);
396 toolbar_update_info(filer_window
);
399 set_scanning_display(filer_window
, TRUE
);
400 toolbar_update_info(filer_window
);
403 if (filer_window
->window
->window
)
404 gdk_window_set_cursor(
405 filer_window
->window
->window
,
407 set_scanning_display(filer_window
, FALSE
);
408 toolbar_update_info(filer_window
);
409 open_filer_window(filer_window
);
411 if (filer_window
->had_cursor
&&
412 !view_cursor_visible(view
))
415 view_get_iter(view
, &start
, 0);
416 if (start
.next(&start
))
417 view_cursor_to_iter(view
, &start
);
418 view_show_cursor(view
);
419 filer_window
->had_cursor
= FALSE
;
421 if (filer_window
->auto_select
)
422 display_set_autoselect(filer_window
,
423 filer_window
->auto_select
);
424 null_g_free(&filer_window
->auto_select
);
426 filer_create_thumbs(filer_window
);
428 if (filer_window
->thumb_queue
)
429 start_thumb_scanning(filer_window
);
432 view_update_items(view
, items
);
434 case DIR_ERROR_CHANGED
:
435 filer_set_title(filer_window
);
437 case DIR_QUEUE_INTERESTING
:
438 queue_interesting(filer_window
);
443 static void attach(FilerWindow
*filer_window
)
445 gdk_window_set_cursor(filer_window
->window
->window
, busy_cursor
);
446 view_clear(filer_window
->view
);
447 filer_window
->scanning
= TRUE
;
448 dir_attach(filer_window
->directory
, (DirCallback
) update_display
,
450 filer_set_title(filer_window
);
451 bookmarks_add_history(filer_window
->sym_path
);
453 if (filer_window
->directory
->error
)
455 if (spring_in_progress
)
456 g_printerr(_("Error scanning '%s':\n%s\n"),
457 filer_window
->sym_path
,
458 filer_window
->directory
->error
);
460 delayed_error(_("Error scanning '%s':\n%s"),
461 filer_window
->sym_path
,
462 filer_window
->directory
->error
);
466 static void detach(FilerWindow
*filer_window
)
468 g_return_if_fail(filer_window
->directory
!= NULL
);
470 dir_detach(filer_window
->directory
,
471 (DirCallback
) update_display
, filer_window
);
472 g_object_unref(filer_window
->directory
);
473 filer_window
->directory
= NULL
;
476 /* If 'start' was mounted by ROX-Filer, return it. Otherwise, try the
477 * parents up the tree.
478 * NULL if we're not in a user mount point.
479 * g_free() the result.
481 static char *get_ancestor_user_mount_point(const char *start
)
485 path
= strdup(start
);
491 if (mount_is_user_mounted(path
))
500 slash
= strrchr(path
+ 1, '/');
507 static void umount_dialog_response(GtkWidget
*dialog
, int response
, char *mount
)
513 case GTK_RESPONSE_OK
:
514 list
= g_list_prepend(NULL
, mount
);
515 action_mount(list
, FALSE
, FALSE
, TRUE
);
519 case ROX_RESPONSE_EJECT
:
520 list
= g_list_prepend(NULL
, mount
);
531 gtk_widget_destroy(dialog
);
536 /* 'filer_window' shows a directory under 'mount'. If no other window also
537 * shows a directory under it, display a non-modal dialog offering to
538 * unmount the directory.
539 * 'mount' is freed by this function, either directly, or after the dialog
542 static void may_offer_unmount(FilerWindow
*filer_window
, char *mount
)
544 GtkWidget
*dialog
, *button
;
550 for (next
= all_filer_windows
; next
; next
= next
->next
)
552 FilerWindow
*other
= (FilerWindow
*) next
->data
;
554 if (other
== filer_window
)
557 if (strncmp(filer_window
->real_path
, other
->real_path
,
562 filer_window
->real_path
[len
] != '/' ||
563 filer_window
->real_path
[len
] != '\0');
565 if (other
->real_path
[len
] != '/' &&
566 other
->real_path
[len
] != '\0')
569 /* Found another window. Don't offer to unmount. */
574 dialog
= gtk_message_dialog_new(NULL
, 0, GTK_MESSAGE_QUESTION
,
576 _("Do you want to unmount this device?\n\n"
577 "Unmounting a device makes it safe to remove "
580 button
= button_new_mixed(ROX_STOCK_MOUNTED
, _("No change"));
581 GTK_WIDGET_SET_FLAGS(button
, GTK_CAN_DEFAULT
);
582 gtk_dialog_add_action_widget(GTK_DIALOG(dialog
), button
,
583 GTK_RESPONSE_CANCEL
);
584 gtk_widget_show(button
);
586 button
= button_new_mixed(ROX_STOCK_MOUNT
, _("Unmount"));
587 GTK_WIDGET_SET_FLAGS(button
, GTK_CAN_DEFAULT
);
588 gtk_dialog_add_action_widget(GTK_DIALOG(dialog
), button
,
590 gtk_widget_show(button
);
592 /* We need a better icon, but I can't draw */
593 button
= button_new_mixed(GTK_STOCK_UNDO
, _("Eject"));
594 GTK_WIDGET_SET_FLAGS(button
, GTK_CAN_DEFAULT
);
595 gtk_dialog_add_action_widget(GTK_DIALOG(dialog
), button
,
597 gtk_widget_show(button
);
599 g_signal_connect(G_OBJECT(dialog
), "response",
600 G_CALLBACK(umount_dialog_response
), mount
);
602 gtk_dialog_set_default_response(GTK_DIALOG(dialog
),
606 gtk_widget_show(dialog
);
609 /* Returns TRUE to prevent closing the window. May offer to unmount a
612 gboolean
filer_window_delete(GtkWidget
*window
,
613 GdkEvent
*unused
, /* (may be NULL) */
614 FilerWindow
*filer_window
)
618 mount
= get_ancestor_user_mount_point(filer_window
->real_path
);
621 may_offer_unmount(filer_window
, mount
);
626 static void filer_window_destroyed(GtkWidget
*widget
, FilerWindow
*filer_window
)
628 all_filer_windows
= g_list_remove(all_filer_windows
, filer_window
);
630 g_object_set_data(G_OBJECT(widget
), "filer_window", NULL
);
632 if (window_with_primary
== filer_window
)
633 window_with_primary
= NULL
;
635 if (window_with_focus
== filer_window
)
638 window_with_focus
= NULL
;
641 if (filer_window
->directory
)
642 detach(filer_window
);
644 if (filer_window
->open_timeout
)
646 g_source_remove(filer_window
->open_timeout
);
647 filer_window
->open_timeout
= 0;
650 if (filer_window
->auto_scroll
!= -1)
652 g_source_remove(filer_window
->auto_scroll
);
653 filer_window
->auto_scroll
= -1;
656 if (filer_window
->thumb_queue
)
657 destroy_glist(&filer_window
->thumb_queue
);
661 filer_set_id(filer_window
, NULL
);
663 if(filer_window
->filter_string
)
664 g_free(filer_window
->filter_string
);
665 if(filer_window
->regexp
)
666 g_free(filer_window
->regexp
);
668 g_free(filer_window
->auto_select
);
669 g_free(filer_window
->real_path
);
670 g_free(filer_window
->sym_path
);
671 g_free(filer_window
);
676 /* Returns TRUE iff the directory still exists. */
677 static gboolean
may_rescan(FilerWindow
*filer_window
, gboolean warning
)
681 g_return_val_if_fail(filer_window
!= NULL
, FALSE
);
683 /* We do a fresh lookup (rather than update) because the inode may
686 dir
= g_fscache_lookup(dir_cache
, filer_window
->real_path
);
690 info_message(_("Directory missing/deleted"));
691 gtk_widget_destroy(filer_window
->window
);
694 if (dir
== filer_window
->directory
)
698 detach(filer_window
);
699 filer_window
->directory
= dir
;
700 attach(filer_window
);
706 /* No items are now selected. This might be because another app claimed
707 * the selection or because the user unselected all the items.
709 void filer_lost_selection(FilerWindow
*filer_window
, guint time
)
711 if (window_with_primary
== filer_window
)
713 window_with_primary
= NULL
;
714 gtk_selection_owner_set(NULL
, GDK_SELECTION_PRIMARY
, time
);
718 /* Another app has claimed the primary selection */
719 static void filer_lost_primary(GtkWidget
*window
,
720 GdkEventSelection
*event
,
723 FilerWindow
*filer_window
= (FilerWindow
*) user_data
;
725 if (window_with_primary
&& window_with_primary
== filer_window
)
727 window_with_primary
= NULL
;
728 set_selection_state(filer_window
, FALSE
);
732 /* Someone wants us to send them the selection */
733 static void selection_get(GtkWidget
*widget
,
734 GtkSelectionData
*selection_data
,
739 GString
*reply
, *header
;
740 FilerWindow
*filer_window
= (FilerWindow
*) data
;
744 reply
= g_string_new(NULL
);
745 header
= g_string_new(NULL
);
750 g_string_printf(header
, " %s",
751 make_path(filer_window
->sym_path
, ""));
753 case TARGET_URI_LIST
:
754 g_string_printf(header
, " file://%s%s",
755 our_host_name_for_dnd(),
756 make_path(filer_window
->sym_path
, ""));
760 view_get_iter(filer_window
->view
, &iter
, VIEW_ITER_SELECTED
);
762 while ((item
= iter
.next(&iter
)))
764 g_string_append(reply
, header
->str
);
765 g_string_append(reply
, item
->leafname
);
769 gtk_selection_data_set_text(selection_data
,
770 reply
->str
+ 1, reply
->len
- 1);
773 g_warning("Attempt to paste empty selection!");
774 gtk_selection_data_set_text(selection_data
, "", 0);
777 g_string_free(reply
, TRUE
);
778 g_string_free(header
, TRUE
);
781 /* Selection has been changed -- try to grab the primary selection
782 * if we don't have it. Also called when clicking on an insensitive selection
784 * Also updates toolbar info.
786 void filer_selection_changed(FilerWindow
*filer_window
, gint time
)
788 g_return_if_fail(filer_window
!= NULL
);
790 toolbar_update_info(filer_window
);
792 if (window_with_primary
== filer_window
)
793 return; /* Already got primary */
795 if (!view_count_selected(filer_window
->view
))
796 return; /* Nothing selected */
798 if (filer_window
->temp_item_selected
== FALSE
&&
799 gtk_selection_owner_set(GTK_WIDGET(filer_window
->window
),
800 GDK_SELECTION_PRIMARY
,
803 window_with_primary
= filer_window
;
804 set_selection_state(filer_window
, TRUE
);
807 set_selection_state(filer_window
, FALSE
);
810 /* Open the item (or add it to the shell command minibuffer) */
811 void filer_openitem(FilerWindow
*filer_window
, ViewIter
*iter
, OpenFlags flags
)
813 gboolean shift
= (flags
& OPEN_SHIFT
) != 0;
814 gboolean close_mini
= flags
& OPEN_FROM_MINI
;
815 gboolean close_window
= (flags
& OPEN_CLOSE_WINDOW
) != 0;
817 const guchar
*full_path
;
818 gboolean wink
= TRUE
;
821 g_return_if_fail(filer_window
!= NULL
&& iter
!= NULL
);
823 item
= iter
->peek(iter
);
825 g_return_if_fail(item
!= NULL
);
827 if (filer_window
->mini_type
== MINI_SHELL
)
829 minibuffer_add(filer_window
, item
->leafname
);
833 if (item
->base_type
== TYPE_UNKNOWN
)
834 dir_update_item(filer_window
->directory
, item
->leafname
);
836 if (item
->base_type
== TYPE_DIRECTORY
)
838 /* Never close a filer window when opening a directory
839 * (click on a dir or click on an app with shift).
841 if (shift
|| !(item
->flags
& ITEM_FLAG_APPDIR
))
842 close_window
= FALSE
;
845 full_path
= make_path(filer_window
->sym_path
, item
->leafname
);
846 if (shift
&& (item
->flags
& ITEM_FLAG_SYMLINK
))
849 old_dir
= filer_window
->directory
;
850 if (run_diritem(full_path
, item
,
851 flags
& OPEN_SAME_WINDOW
? filer_window
: NULL
,
855 if (old_dir
!= filer_window
->directory
)
859 gtk_widget_destroy(filer_window
->window
);
863 view_wink_item(filer_window
->view
, iter
);
865 minibuffer_hide(filer_window
);
870 static gint
pointer_in(GtkWidget
*widget
,
871 GdkEventCrossing
*event
,
872 FilerWindow
*filer_window
)
874 may_rescan(filer_window
, TRUE
);
878 static gint
pointer_out(GtkWidget
*widget
,
879 GdkEventCrossing
*event
,
880 FilerWindow
*filer_window
)
886 /* Move the cursor to the next selected item in direction 'dir'
889 void filer_next_selected(FilerWindow
*filer_window
, int dir
)
891 ViewIter iter
, cursor
;
892 gboolean have_cursor
;
893 ViewIface
*view
= filer_window
->view
;
895 g_return_if_fail(dir
== 1 || dir
== -1);
897 view_get_cursor(view
, &cursor
);
898 have_cursor
= cursor
.peek(&cursor
) != NULL
;
900 view_get_iter(view
, &iter
,
902 (have_cursor
? VIEW_ITER_FROM_CURSOR
: 0) |
903 (dir
< 0 ? VIEW_ITER_BACKWARDS
: 0));
905 if (have_cursor
&& view_get_selected(view
, &cursor
))
906 iter
.next(&iter
); /* Skip the cursor itself */
908 if (iter
.next(&iter
))
909 view_cursor_to_iter(view
, &iter
);
916 static void return_pressed(FilerWindow
*filer_window
, GdkEventKey
*event
)
918 TargetFunc cb
= filer_window
->target_cb
;
919 gpointer data
= filer_window
->target_data
;
923 filer_target_mode(filer_window
, NULL
, NULL
, NULL
);
925 view_get_cursor(filer_window
->view
, &iter
);
926 if (!iter
.peek(&iter
))
931 cb(filer_window
, &iter
, data
);
935 if (event
->state
& GDK_SHIFT_MASK
)
937 if (event
->state
& GDK_MOD1_MASK
)
938 flags
|= OPEN_CLOSE_WINDOW
;
940 flags
|= OPEN_SAME_WINDOW
;
942 filer_openitem(filer_window
, &iter
, flags
);
945 /* Makes sure that 'groups' is up-to-date, reloading from file if it has
946 * changed. If no groups were loaded and there is no file then initialised
947 * groups to an empty document.
948 * Return the node for the 'name' group.
950 static xmlNode
*group_find(char *name
)
955 /* Update the groups, if possible */
956 path
= choices_find_xdg_path_load("Groups.xml", PROJECT
, SITE
);
960 wrapper
= xml_cache_load(path
);
964 g_object_unref(groups
);
973 groups
= xml_new(NULL
);
974 groups
->doc
= xmlNewDoc("1.0");
976 xmlDocSetRootElement(groups
->doc
,
977 xmlNewDocNode(groups
->doc
, NULL
, "groups", NULL
));
981 node
= xmlDocGetRootElement(groups
->doc
);
983 for (node
= node
->xmlChildrenNode
; node
; node
= node
->next
)
987 gid
= xmlGetProp(node
, "name");
992 if (strcmp(name
, gid
) != 0)
1003 static void group_save(FilerWindow
*filer_window
, char *name
)
1010 group
= group_find(name
);
1013 xmlUnlinkNode(group
);
1016 group
= xmlNewChild(xmlDocGetRootElement(groups
->doc
),
1017 NULL
, "group", NULL
);
1018 xmlSetProp(group
, "name", name
);
1020 xmlNewTextChild(group
, NULL
, "directory", filer_window
->sym_path
);
1022 view_get_iter(filer_window
->view
, &iter
, VIEW_ITER_SELECTED
);
1024 while ((item
= iter
.next(&iter
)))
1025 xmlNewTextChild(group
, NULL
, "item", item
->leafname
);
1027 save_path
= choices_find_xdg_path_save("Groups.xml", PROJECT
, SITE
,
1031 save_xml_file(groups
->doc
, save_path
);
1036 static gboolean
group_restore_cb(ViewIter
*iter
, gpointer data
)
1038 GHashTable
*in_group
= (GHashTable
*) data
;
1040 return g_hash_table_lookup(in_group
,
1041 iter
->peek(iter
)->leafname
) != NULL
;
1044 static void group_restore(FilerWindow
*filer_window
, char *name
)
1046 GHashTable
*in_group
;
1048 xmlNode
*group
, *node
;
1050 group
= group_find(name
);
1054 report_error(_("Group %s is not set. Select some files "
1055 "and press Ctrl+%s to set the group. Press %s "
1056 "on its own to reselect the files later.\n"
1057 "Make sure NumLock is on if you use the keypad."),
1062 node
= get_subnode(group
, NULL
, "directory");
1063 g_return_if_fail(node
!= NULL
);
1064 path
= xmlNodeListGetString(groups
->doc
, node
->xmlChildrenNode
, 1);
1065 g_return_if_fail(path
!= NULL
);
1067 if (strcmp(path
, filer_window
->sym_path
) != 0)
1068 filer_change_to(filer_window
, path
, NULL
);
1071 in_group
= g_hash_table_new(g_str_hash
, g_str_equal
);
1072 for (node
= group
->xmlChildrenNode
; node
; node
= node
->next
)
1075 if (node
->type
!= XML_ELEMENT_NODE
)
1077 if (strcmp(node
->name
, "item") != 0)
1080 leaf
= xmlNodeListGetString(groups
->doc
,
1081 node
->xmlChildrenNode
, 1);
1083 g_warning("Missing leafname!\n");
1085 g_hash_table_insert(in_group
, leaf
, filer_window
);
1088 view_select_if(filer_window
->view
, &group_restore_cb
, in_group
);
1090 g_hash_table_foreach(in_group
, (GHFunc
) g_free
, NULL
);
1091 g_hash_table_destroy(in_group
);
1094 static gboolean
popup_menu(GtkWidget
*widget
, FilerWindow
*filer_window
)
1099 view_get_cursor(filer_window
->view
, &iter
);
1101 event
= gtk_get_current_event();
1102 show_filer_menu(filer_window
, event
, &iter
);
1104 gdk_event_free(event
);
1109 void filer_window_toggle_cursor_item_selected(FilerWindow
*filer_window
)
1111 ViewIface
*view
= filer_window
->view
;
1114 view_get_iter(view
, &iter
, VIEW_ITER_FROM_CURSOR
);
1115 if (!iter
.next(&iter
))
1116 return; /* No cursor */
1118 if (view_get_selected(view
, &iter
))
1119 view_set_selected(view
, &iter
, FALSE
);
1121 view_set_selected(view
, &iter
, TRUE
);
1123 if (iter
.next(&iter
))
1124 view_cursor_to_iter(view
, &iter
);
1127 gint
filer_key_press_event(GtkWidget
*widget
,
1129 FilerWindow
*filer_window
)
1131 ViewIface
*view
= filer_window
->view
;
1133 GtkWidget
*focus
= GTK_WINDOW(widget
)->focus_widget
;
1134 guint key
= event
->keyval
;
1135 char group
[2] = "1";
1137 window_with_focus
= filer_window
;
1139 /* Delay setting up the keys until now to speed loading... */
1140 if (ensure_filer_menu())
1142 /* Gtk updates in an idle-handler, so force a recheck now */
1143 g_signal_emit_by_name(widget
, "keys_changed");
1146 if (focus
&& focus
== filer_window
->minibuffer
)
1147 if (gtk_widget_event(focus
, (GdkEvent
*) event
))
1148 return TRUE
; /* Handled */
1151 gtk_widget_grab_focus(GTK_WIDGET(view
));
1153 view_get_cursor(view
, &cursor
);
1154 if (!cursor
.peek(&cursor
) && (key
== GDK_Up
|| key
== GDK_Down
))
1157 view_get_iter(view
, &iter
, 0);
1158 if (iter
.next(&iter
))
1159 view_cursor_to_iter(view
, &iter
);
1160 gtk_widget_grab_focus(GTK_WIDGET(view
)); /* Needed? */
1167 filer_target_mode(filer_window
, NULL
, NULL
, NULL
);
1168 view_cursor_to_iter(filer_window
->view
, NULL
);
1169 view_clear_selection(filer_window
->view
);
1172 return_pressed(filer_window
, event
);
1174 case GDK_ISO_Left_Tab
:
1175 filer_next_selected(filer_window
, -1);
1178 filer_next_selected(filer_window
, 1);
1181 change_to_parent(filer_window
);
1189 view_get_cursor(filer_window
->view
, &iter
);
1190 show_filer_menu(filer_window
,
1191 (GdkEvent
*) event
, &iter
);
1195 filer_window_toggle_cursor_item_selected(filer_window
);
1198 if (key
>= GDK_0
&& key
<= GDK_9
)
1199 group
[0] = key
- GDK_0
+ '0';
1200 else if (key
>= GDK_KP_0
&& key
<= GDK_KP_9
)
1201 group
[0] = key
- GDK_KP_0
+ '0';
1204 if (focus
&& focus
!= widget
&&
1205 gtk_widget_get_toplevel(focus
) == widget
)
1206 if (gtk_widget_event(focus
,
1207 (GdkEvent
*) event
))
1208 return TRUE
; /* Handled */
1212 if (event
->state
& GDK_CONTROL_MASK
)
1213 group_save(filer_window
, group
);
1215 group_restore(filer_window
, group
);
1221 void filer_open_parent(FilerWindow
*filer_window
)
1224 const char *current
= filer_window
->sym_path
;
1226 if (current
[0] == '/' && current
[1] == '\0')
1227 return; /* Already in the root */
1229 dir
= g_path_get_dirname(current
);
1230 filer_opendir(dir
, filer_window
, NULL
);
1234 void change_to_parent(FilerWindow
*filer_window
)
1237 const char *current
= filer_window
->sym_path
;
1239 if (current
[0] == '/' && current
[1] == '\0')
1240 return; /* Already in the root */
1242 if (mount_is_user_mounted(filer_window
->real_path
))
1243 may_offer_unmount(filer_window
,
1244 g_strdup(filer_window
->real_path
));
1246 dir
= g_path_get_dirname(current
);
1247 filer_change_to(filer_window
, dir
, g_basename(current
));
1251 /* Removes trailing /s from path (modified in place) */
1252 static void tidy_sympath(gchar
*path
)
1256 g_return_if_fail(path
!= NULL
);
1259 while (l
> 1 && path
[l
- 1] == '/')
1266 /* Make filer_window display path. When finished, highlight item 'from', or
1267 * the first item if from is NULL. If there is currently no cursor then
1268 * simply wink 'from' (if not NULL).
1269 * If the cause was a key event and we resize, warp the pointer.
1271 void filer_change_to(FilerWindow
*filer_window
,
1272 const char *path
, const char *from
)
1275 char *sym_path
, *real_path
;
1278 g_return_if_fail(filer_window
!= NULL
);
1280 filer_cancel_thumbnails(filer_window
);
1284 sym_path
= g_strdup(path
);
1285 real_path
= pathdup(path
);
1286 new_dir
= g_fscache_lookup(dir_cache
, real_path
);
1290 delayed_error(_("Directory '%s' is not accessible"),
1297 if (o_unique_filer_windows
.int_value
&& !spring_in_progress
)
1301 fw
= find_filer_window(sym_path
, filer_window
);
1303 gtk_widget_destroy(fw
->window
);
1306 from_dup
= from
&& *from
? g_strdup(from
) : NULL
;
1308 detach(filer_window
);
1309 g_free(filer_window
->real_path
);
1310 g_free(filer_window
->sym_path
);
1311 filer_window
->real_path
= real_path
;
1312 filer_window
->sym_path
= sym_path
;
1313 tidy_sympath(filer_window
->sym_path
);
1315 filer_window
->directory
= new_dir
;
1317 g_free(filer_window
->auto_select
);
1318 filer_window
->auto_select
= from_dup
;
1320 filer_window
->had_cursor
= filer_window
->had_cursor
||
1321 view_cursor_visible(filer_window
->view
);
1323 filer_set_title(filer_window
);
1324 if (filer_window
->window
->window
)
1325 gdk_window_set_role(filer_window
->window
->window
,
1326 filer_window
->sym_path
);
1327 view_cursor_to_iter(filer_window
->view
, NULL
);
1329 attach(filer_window
);
1331 check_settings(filer_window
);
1333 display_set_actual_size(filer_window
, FALSE
);
1335 if (o_filer_auto_resize
.int_value
== RESIZE_ALWAYS
)
1336 view_autosize(filer_window
->view
);
1338 if (filer_window
->mini_type
== MINI_PATH
)
1339 g_idle_add((GSourceFunc
) minibuffer_show_cb
, filer_window
);
1342 /* Returns a list containing the full (sym) pathname of every selected item.
1343 * You must g_free() each item in the list.
1345 GList
*filer_selected_items(FilerWindow
*filer_window
)
1347 GList
*retval
= NULL
;
1348 guchar
*dir
= filer_window
->sym_path
;
1352 view_get_iter(filer_window
->view
, &iter
, VIEW_ITER_SELECTED
);
1353 while ((item
= iter
.next(&iter
)))
1355 retval
= g_list_prepend(retval
,
1356 g_strdup(make_path(dir
, item
->leafname
)));
1359 return g_list_reverse(retval
);
1362 /* Return the single selected item. Error if nothing is selected. */
1363 DirItem
*filer_selected_item(FilerWindow
*filer_window
)
1368 view_get_iter(filer_window
->view
, &iter
, VIEW_ITER_SELECTED
);
1370 item
= iter
.next(&iter
);
1371 g_return_val_if_fail(item
!= NULL
, NULL
);
1372 g_return_val_if_fail(iter
.next(&iter
) == NULL
, NULL
);
1377 /* Creates and shows a new filer window.
1378 * If src_win != NULL then display options can be taken from that source window.
1379 * Returns the new filer window, or NULL on error.
1380 * Note: if unique windows is in use, may return an existing window.
1382 FilerWindow
*filer_opendir(const char *path
, FilerWindow
*src_win
,
1383 const gchar
*wm_class
)
1385 FilerWindow
*filer_window
;
1387 DisplayStyle dstyle
;
1390 GtkSortType s_order
;
1391 Settings
*dir_settings
= NULL
;
1392 gboolean force_resize
= TRUE
;
1394 /* Get the real pathname of the directory and copy it */
1395 real_path
= pathdup(path
);
1397 if (o_unique_filer_windows
.int_value
&& !spring_in_progress
)
1399 FilerWindow
*same_dir_window
;
1401 same_dir_window
= find_filer_window(path
, NULL
);
1403 if (same_dir_window
)
1405 gtk_window_present(GTK_WINDOW(same_dir_window
->window
));
1406 return same_dir_window
;
1410 filer_window
= g_new(FilerWindow
, 1);
1411 filer_window
->message
= NULL
;
1412 filer_window
->minibuffer
= NULL
;
1413 filer_window
->minibuffer_label
= NULL
;
1414 filer_window
->minibuffer_area
= NULL
;
1415 filer_window
->temp_show_hidden
= FALSE
;
1416 filer_window
->sym_path
= g_strdup(path
);
1417 filer_window
->real_path
= real_path
;
1418 filer_window
->scanning
= FALSE
;
1419 filer_window
->had_cursor
= FALSE
;
1420 filer_window
->auto_select
= NULL
;
1421 filer_window
->toolbar_text
= NULL
;
1422 filer_window
->target_cb
= NULL
;
1423 filer_window
->mini_type
= MINI_NONE
;
1424 filer_window
->selection_state
= GTK_STATE_INSENSITIVE
;
1425 filer_window
->toolbar
= NULL
;
1426 filer_window
->toplevel_vbox
= NULL
;
1427 filer_window
->view_hbox
= NULL
;
1428 filer_window
->view
= NULL
;
1429 filer_window
->scrollbar
= NULL
;
1430 filer_window
->auto_scroll
= -1;
1431 filer_window
->window_id
= NULL
;
1433 tidy_sympath(filer_window
->sym_path
);
1435 /* Finds the entry for this directory in the dir cache, creating
1436 * a new one if needed. This does not cause a scan to start,
1437 * so if a new entry is created then it will be empty.
1439 filer_window
->directory
= g_fscache_lookup(dir_cache
, real_path
);
1440 if (!filer_window
->directory
)
1442 delayed_error(_("Directory '%s' not found."), path
);
1443 g_free(filer_window
->real_path
);
1444 g_free(filer_window
->sym_path
);
1445 g_free(filer_window
);
1449 filer_window
->temp_item_selected
= FALSE
;
1450 filer_window
->flags
= (FilerFlags
) 0;
1451 filer_window
->details_type
= DETAILS_TIMES
;
1452 filer_window
->display_style
= UNKNOWN_STYLE
;
1453 filer_window
->display_style_wanted
= UNKNOWN_STYLE
;
1454 filer_window
->thumb_queue
= NULL
;
1455 filer_window
->max_thumbs
= 0;
1456 filer_window
->sort_type
= -1;
1458 filer_window
->filter
= FILER_SHOW_ALL
;
1459 filer_window
->filter_string
= NULL
;
1460 filer_window
->regexp
= NULL
;
1461 filer_window
->filter_directories
= FALSE
;
1463 if (src_win
&& o_display_inherit_options
.int_value
)
1465 s_type
= src_win
->sort_type
;
1466 s_order
= src_win
->sort_order
;
1467 dstyle
= src_win
->display_style_wanted
;
1468 dtype
= src_win
->details_type
;
1469 filer_window
->show_hidden
= src_win
->show_hidden
;
1470 filer_window
->show_thumbs
= src_win
->show_thumbs
;
1471 filer_window
->view_type
= src_win
->view_type
;
1473 filer_window
->filter_directories
= src_win
->filter_directories
;
1474 filer_set_filter(filer_window
, src_win
->filter
,
1475 src_win
->filter_string
);
1479 s_type
= o_display_sort_by
.int_value
;
1480 s_order
= GTK_SORT_ASCENDING
;
1481 dstyle
= o_display_size
.int_value
;
1482 dtype
= o_display_details
.int_value
;
1483 filer_window
->show_hidden
= o_display_show_hidden
.int_value
;
1484 filer_window
->show_thumbs
= o_display_show_thumbs
.int_value
;
1485 filer_window
->view_type
= o_filer_view_type
.int_value
;
1488 dir_settings
= (Settings
*) g_hash_table_lookup(settings_table
,
1489 filer_window
->sym_path
);
1492 /* Override the current defaults with the per-directory
1495 if (dir_settings
->flags
& SET_HIDDEN
)
1496 filer_window
->show_hidden
= dir_settings
->show_hidden
;
1498 if (dir_settings
->flags
& SET_STYLE
)
1499 dstyle
= dir_settings
->display_style
;
1501 if (dir_settings
->flags
& SET_DETAILS
)
1503 dtype
= dir_settings
->details_type
;
1504 filer_window
->view_type
= dir_settings
->view_type
;
1507 if (dir_settings
->flags
& SET_SORT
)
1509 s_type
= dir_settings
->sort_type
;
1510 s_order
= dir_settings
->sort_order
;
1513 if (dir_settings
->flags
& SET_THUMBS
)
1514 filer_window
->show_thumbs
= dir_settings
->show_thumbs
;
1516 if (dir_settings
->flags
& SET_FILTER
)
1518 filer_set_filter(filer_window
,
1519 dir_settings
->filter_type
,
1520 dir_settings
->filter
);
1521 filer_set_filter_directories(filer_window
,
1522 dir_settings
->filter_directories
);
1526 /* Add all the user-interface elements & realise */
1527 filer_add_widgets(filer_window
, wm_class
);
1529 gtk_window_set_position(GTK_WINDOW(filer_window
->window
),
1534 if (dir_settings
->flags
& SET_POSITION
)
1536 gtk_window_move(GTK_WINDOW(filer_window
->window
),
1537 dir_settings
->x
, dir_settings
->y
);
1539 if (dir_settings
->flags
& SET_SIZE
)
1541 filer_window_set_size(filer_window
,
1542 dir_settings
->width
,
1543 dir_settings
->height
);
1544 force_resize
= o_filer_auto_resize
.int_value
!= RESIZE_NEVER
;
1548 /* Connect to all the signal handlers */
1549 filer_add_signals(filer_window
);
1551 display_set_layout(filer_window
, dstyle
, dtype
, force_resize
);
1552 display_set_sort_type(filer_window
, s_type
, s_order
);
1554 /* Open the window after a timeout, or when scanning stops.
1555 * Do this before attaching, because attach() might tell us to
1556 * stop scanning (if a scan isn't needed).
1558 filer_window
->open_timeout
= g_timeout_add(500,
1559 (GSourceFunc
) open_filer_window
,
1562 /* The view is created empty and then attach() is called, which
1563 * links the filer window to the entry in the directory cache we
1564 * looked up / created above.
1566 * The attach() function will immediately callback to the filer window
1567 * to deliver a list of all known entries in the directory (so,
1568 * the number of items will be known after attach() returns).
1570 * If the directory was not in the cache (because it hadn't been
1571 * opened it before) then the types and icons for the entries are
1572 * not know, but the list of names is.
1575 attach(filer_window
);
1577 number_of_windows
++;
1578 all_filer_windows
= g_list_prepend(all_filer_windows
, filer_window
);
1580 return filer_window
;
1583 void filer_set_view_type(FilerWindow
*filer_window
, ViewType type
)
1585 GtkWidget
*view
= NULL
;
1586 Directory
*dir
= NULL
;
1587 GHashTable
*selected
= NULL
;
1589 g_return_if_fail(filer_window
!= NULL
);
1591 motion_window
= NULL
;
1593 if (filer_window
->view
)
1595 /* Save the current selection */
1599 selected
= g_hash_table_new(g_str_hash
, g_str_equal
);
1600 view_get_iter(filer_window
->view
, &iter
, VIEW_ITER_SELECTED
);
1601 while ((item
= iter
.next(&iter
)))
1602 g_hash_table_insert(selected
, item
->leafname
, "yes");
1604 /* Destroy the old view */
1605 gtk_widget_destroy(GTK_WIDGET(filer_window
->view
));
1606 filer_window
->view
= NULL
;
1608 dir
= filer_window
->directory
;
1610 detach(filer_window
);
1615 case VIEW_TYPE_COLLECTION
:
1616 view
= view_collection_new(filer_window
);
1618 case VIEW_TYPE_DETAILS
:
1619 view
= view_details_new(filer_window
);
1623 g_return_if_fail(view
!= NULL
);
1625 filer_window
->view
= VIEW(view
);
1626 filer_window
->view_type
= type
;
1628 gtk_box_pack_start(filer_window
->view_hbox
, view
, TRUE
, TRUE
, 0);
1629 gtk_widget_show(view
);
1631 /* Drag and drop events */
1632 make_drop_target(view
, 0);
1633 g_signal_connect(view
, "drag_motion",
1634 G_CALLBACK(drag_motion
), filer_window
);
1635 g_signal_connect(view
, "drag_leave",
1636 G_CALLBACK(drag_leave
), filer_window
);
1637 g_signal_connect(view
, "drag_end",
1638 G_CALLBACK(drag_end
), filer_window
);
1639 /* Dragging from us... */
1640 g_signal_connect(view
, "drag_data_get",
1641 GTK_SIGNAL_FUNC(drag_data_get
), NULL
);
1645 /* Only when changing type. Otherwise, will attach later. */
1646 filer_window
->directory
= dir
;
1647 attach(filer_window
);
1649 if (o_filer_auto_resize
.int_value
!= RESIZE_NEVER
)
1650 view_autosize(filer_window
->view
);
1658 view_get_iter(filer_window
->view
, &iter
, 0);
1659 while ((item
= iter
.next(&iter
)))
1661 if (g_hash_table_lookup(selected
, item
->leafname
))
1662 view_set_selected(filer_window
->view
,
1665 g_hash_table_destroy(selected
);
1669 /* This adds all the widgets to a new filer window. It is in a separate
1670 * function because filer_opendir() was getting too long...
1672 static void filer_add_widgets(FilerWindow
*filer_window
, const gchar
*wm_class
)
1674 GtkWidget
*hbox
, *vbox
;
1676 /* Create the top-level window widget */
1677 filer_window
->window
= gtk_window_new(GTK_WINDOW_TOPLEVEL
);
1678 filer_set_title(filer_window
);
1679 gtk_widget_set_name(filer_window
->window
, "rox-filer");
1682 gtk_window_set_wmclass(GTK_WINDOW(filer_window
->window
),
1685 /* This property is cleared when the window is destroyed.
1686 * You can thus ref filer_window->window and use this to see
1687 * if the window no longer exists.
1689 g_object_set_data(G_OBJECT(filer_window
->window
),
1690 "filer_window", filer_window
);
1692 /* Create this now to make the Adjustment before the View */
1693 filer_window
->scrollbar
= gtk_vscrollbar_new(NULL
);
1695 vbox
= gtk_vbox_new(FALSE
, 0);
1696 gtk_container_add(GTK_CONTAINER(filer_window
->window
), vbox
);
1698 filer_window
->toplevel_vbox
= GTK_BOX(vbox
);
1700 /* If there's a message that should be displayed in each window (eg
1701 * 'Running as root'), add it here.
1703 if (show_user_message
)
1705 filer_window
->message
= gtk_label_new(show_user_message
);
1706 gtk_box_pack_start(GTK_BOX(vbox
), filer_window
->message
,
1708 gtk_widget_show(filer_window
->message
);
1711 hbox
= gtk_hbox_new(FALSE
, 0);
1712 filer_window
->view_hbox
= GTK_BOX(hbox
);
1713 gtk_box_pack_start_defaults(GTK_BOX(vbox
), hbox
);
1714 /* Add the main View widget */
1715 filer_set_view_type(filer_window
, filer_window
->view_type
);
1716 /* Put the scrollbar next to the View */
1717 gtk_box_pack_end(GTK_BOX(hbox
),
1718 filer_window
->scrollbar
, FALSE
, TRUE
, 0);
1719 gtk_widget_show(hbox
);
1721 /* If we want a toolbar, create it now */
1722 toolbar_update_toolbar(filer_window
);
1724 /* And the minibuffer (hidden to start with) */
1725 create_minibuffer(filer_window
);
1726 gtk_box_pack_end(GTK_BOX(vbox
), filer_window
->minibuffer_area
,
1729 /* And the thumbnail progress bar (also hidden) */
1733 filer_window
->thumb_bar
= gtk_hbox_new(FALSE
, 2);
1734 gtk_box_pack_end(GTK_BOX(vbox
), filer_window
->thumb_bar
,
1737 filer_window
->thumb_progress
= gtk_progress_bar_new();
1739 gtk_box_pack_start(GTK_BOX(filer_window
->thumb_bar
),
1740 filer_window
->thumb_progress
, TRUE
, TRUE
, 0);
1742 cancel
= gtk_button_new_with_label(_("Cancel"));
1743 GTK_WIDGET_UNSET_FLAGS(cancel
, GTK_CAN_FOCUS
);
1744 gtk_box_pack_start(GTK_BOX(filer_window
->thumb_bar
),
1745 cancel
, FALSE
, TRUE
, 0);
1746 g_signal_connect_swapped(cancel
, "clicked",
1747 G_CALLBACK(filer_cancel_thumbnails
),
1751 gtk_widget_show(vbox
);
1752 gtk_widget_show(filer_window
->scrollbar
);
1754 gtk_widget_realize(filer_window
->window
);
1756 gdk_window_set_role(filer_window
->window
->window
,
1757 filer_window
->sym_path
);
1759 filer_window_set_size(filer_window
, 4, 4);
1762 static void filer_add_signals(FilerWindow
*filer_window
)
1764 GtkTargetEntry target_table
[] =
1766 {"text/uri-list", 0, TARGET_URI_LIST
},
1767 {"UTF8_STRING", 0, TARGET_STRING
},
1768 {"STRING", 0, TARGET_STRING
},
1769 {"COMPOUND_TEXT", 0, TARGET_STRING
},/* XXX: Treats as STRING */
1772 /* Events on the top-level window */
1773 gtk_widget_add_events(filer_window
->window
, GDK_ENTER_NOTIFY
);
1774 g_signal_connect(filer_window
->window
, "enter-notify-event",
1775 G_CALLBACK(pointer_in
), filer_window
);
1776 g_signal_connect(filer_window
->window
, "leave-notify-event",
1777 G_CALLBACK(pointer_out
), filer_window
);
1778 g_signal_connect(filer_window
->window
, "destroy",
1779 G_CALLBACK(filer_window_destroyed
), filer_window
);
1780 g_signal_connect(filer_window
->window
, "delete-event",
1781 G_CALLBACK(filer_window_delete
), filer_window
);
1783 g_signal_connect(filer_window
->window
, "selection_clear_event",
1784 G_CALLBACK(filer_lost_primary
), filer_window
);
1786 g_signal_connect(filer_window
->window
, "selection_get",
1787 G_CALLBACK(selection_get
), filer_window
);
1788 gtk_selection_add_targets(GTK_WIDGET(filer_window
->window
),
1789 GDK_SELECTION_PRIMARY
,
1791 sizeof(target_table
) / sizeof(*target_table
));
1793 g_signal_connect(filer_window
->window
, "popup-menu",
1794 G_CALLBACK(popup_menu
), filer_window
);
1795 g_signal_connect(filer_window
->window
, "key_press_event",
1796 G_CALLBACK(filer_key_press_event
), filer_window
);
1798 gtk_window_add_accel_group(GTK_WINDOW(filer_window
->window
),
1802 static gint
clear_scanning_display(FilerWindow
*filer_window
)
1804 if (filer_exists(filer_window
))
1805 filer_set_title(filer_window
);
1809 static void set_scanning_display(FilerWindow
*filer_window
, gboolean scanning
)
1811 if (scanning
== filer_window
->scanning
)
1813 filer_window
->scanning
= scanning
;
1816 filer_set_title(filer_window
);
1818 g_timeout_add(300, (GSourceFunc
) clear_scanning_display
,
1822 /* Note that filer_window may not exist after this call.
1823 * Returns TRUE iff the directory still exists.
1825 gboolean
filer_update_dir(FilerWindow
*filer_window
, gboolean warning
)
1827 gboolean still_exists
;
1829 still_exists
= may_rescan(filer_window
, warning
);
1832 dir_update(filer_window
->directory
, filer_window
->sym_path
);
1834 return still_exists
;
1837 void filer_update_all(void)
1839 GList
*next
= all_filer_windows
;
1843 FilerWindow
*filer_window
= (FilerWindow
*) next
->data
;
1845 /* Updating directory may remove it from list -- stop sending
1846 * patches to move this line!
1850 /* Don't trigger a refresh if we're already scanning.
1851 * Otherwise, two views of a single directory will trigger
1854 if (filer_window
->directory
&&
1855 !filer_window
->directory
->scanning
)
1856 filer_update_dir(filer_window
, TRUE
);
1860 /* Refresh the various caches even if we don't think we need to */
1861 void full_refresh(void)
1864 reread_mime_files(); /* Refreshes all windows */
1867 /* See whether a filer window with a given path already exists
1868 * and is different from diff.
1870 static FilerWindow
*find_filer_window(const char *sym_path
, FilerWindow
*diff
)
1874 for (next
= all_filer_windows
; next
; next
= next
->next
)
1876 FilerWindow
*filer_window
= (FilerWindow
*) next
->data
;
1878 if (filer_window
!= diff
&&
1879 strcmp(sym_path
, filer_window
->sym_path
) == 0)
1880 return filer_window
;
1886 /* This path has been mounted/umounted/deleted some files - update all dirs */
1887 void filer_check_mounted(const char *real_path
)
1889 GList
*next
= all_filer_windows
;
1892 gboolean resize
= o_filer_auto_resize
.int_value
== RESIZE_ALWAYS
;
1894 /* DOS disks, etc, often don't change the mtime of the root directory
1895 * on modification, so force a refresh now.
1897 g_fscache_update(dir_cache
, real_path
);
1899 len
= strlen(real_path
);
1903 FilerWindow
*filer_window
= (FilerWindow
*) next
->data
;
1907 if (strncmp(real_path
, filer_window
->real_path
, len
) == 0)
1909 char s
= filer_window
->real_path
[len
];
1911 if (s
== '/' || s
== '\0')
1913 if (filer_update_dir(filer_window
, FALSE
) &&
1915 view_autosize(filer_window
->view
);
1920 parent
= g_path_get_dirname(real_path
);
1921 refresh_dirs(parent
);
1924 icons_may_update(real_path
);
1927 /* Close all windows displaying 'path' or subdirectories of 'path' */
1928 void filer_close_recursive(const char *path
)
1930 GList
*next
= all_filer_windows
;
1934 real
= pathdup(path
);
1939 FilerWindow
*filer_window
= (FilerWindow
*) next
->data
;
1943 if (strncmp(real
, filer_window
->real_path
, len
) == 0)
1945 char s
= filer_window
->real_path
[len
];
1947 if (len
== 1 || s
== '/' || s
== '\0')
1948 gtk_widget_destroy(filer_window
->window
);
1953 /* Like minibuffer_show(), except that:
1954 * - It returns FALSE (to be used from an idle callback)
1955 * - It checks that the filer window still exists.
1957 static gboolean
minibuffer_show_cb(FilerWindow
*filer_window
)
1959 if (filer_exists(filer_window
))
1960 minibuffer_show(filer_window
, MINI_PATH
);
1964 /* TRUE iff filer_window points to an existing FilerWindow
1967 gboolean
filer_exists(FilerWindow
*filer_window
)
1971 for (next
= all_filer_windows
; next
; next
= next
->next
)
1973 FilerWindow
*fw
= (FilerWindow
*) next
->data
;
1975 if (fw
== filer_window
)
1982 FilerWindow
*filer_get_by_id(const char *id
)
1984 return g_hash_table_lookup(window_with_id
, id
);
1987 void filer_set_id(FilerWindow
*filer_window
, const char *id
)
1989 g_return_if_fail(filer_window
!= NULL
);
1991 if (filer_window
->window_id
)
1993 g_hash_table_remove(window_with_id
, filer_window
->window_id
);
1994 g_free(filer_window
->window_id
);
1995 filer_window
->window_id
= NULL
;
2000 filer_window
->window_id
= g_strdup(id
);
2001 g_hash_table_insert(window_with_id
,
2002 filer_window
->window_id
,
2007 /* Make sure the window title is up-to-date */
2008 void filer_set_title(FilerWindow
*filer_window
)
2010 gchar
*title
= NULL
;
2013 if (filer_window
->scanning
||
2014 filer_window
->filter
!= FILER_SHOW_ALL
||
2015 filer_window
->show_hidden
|| filer_window
->show_thumbs
)
2017 if (o_short_flag_names
.int_value
)
2019 const gchar
*hidden
= "";
2021 switch(filer_window
->filter
) {
2022 case FILER_SHOW_ALL
:
2023 hidden
=filer_window
->show_hidden
? _("A") : "";
2025 case FILER_SHOW_GLOB
: hidden
= _("G"); break;
2029 flags
= g_strconcat(" +",
2030 filer_window
->scanning
? _("S") : "",
2032 filer_window
->show_thumbs
? _("T") : "",
2037 gchar
*hidden
= NULL
;
2039 switch(filer_window
->filter
) {
2040 case FILER_SHOW_ALL
:
2041 hidden
= g_strdup(filer_window
->show_hidden
2044 case FILER_SHOW_GLOB
:
2045 hidden
= g_strdup_printf(_("Glob (%s), "),
2046 filer_window
->filter_string
);
2049 hidden
=g_strdup("");
2052 flags
= g_strconcat(" (",
2053 filer_window
->scanning
? _("Scanning, ") : "",
2055 filer_window
->show_thumbs
? _("Thumbs, ") : "",
2057 flags
[strlen(flags
) - 2] = ')';
2063 title
= g_strconcat("//", our_host_name(),
2064 filer_window
->sym_path
, flags
, NULL
);
2066 if (!title
&& home_dir_len
> 1 &&
2067 strncmp(filer_window
->sym_path
, home_dir
, home_dir_len
) == 0)
2069 guchar sep
= filer_window
->sym_path
[home_dir_len
];
2071 if (sep
== '\0' || sep
== '/')
2072 title
= g_strconcat("~",
2073 filer_window
->sym_path
+ home_dir_len
,
2079 title
= g_strconcat(filer_window
->sym_path
, flags
, NULL
);
2081 ensure_utf8(&title
);
2083 if (filer_window
->directory
->error
)
2086 title
= g_strconcat(old
, ": ", filer_window
->directory
->error
,
2091 gtk_window_set_title(GTK_WINDOW(filer_window
->window
), title
);
2095 if (flags
[0] != '\0')
2099 /* Reconnect to the same directory (used when the Show Hidden option is
2100 * toggled). This has the side-effect of updating the window title.
2102 void filer_detach_rescan(FilerWindow
*filer_window
)
2104 Directory
*dir
= filer_window
->directory
;
2107 detach(filer_window
);
2108 filer_window
->directory
= dir
;
2109 attach(filer_window
);
2112 /* Puts the filer window into target mode. When an item is chosen,
2113 * fn(filer_window, iter, data) is called. 'reason' will be displayed
2114 * on the toolbar while target mode is active.
2116 * Use fn == NULL to cancel target mode.
2118 void filer_target_mode(FilerWindow
*filer_window
,
2123 TargetFunc old_fn
= filer_window
->target_cb
;
2126 gdk_window_set_cursor(
2127 GTK_WIDGET(filer_window
->view
)->window
,
2128 fn
? crosshair
: NULL
);
2130 filer_window
->target_cb
= fn
;
2131 filer_window
->target_data
= data
;
2133 if (filer_window
->toolbar_text
== NULL
)
2138 GTK_LABEL(filer_window
->toolbar_text
), reason
);
2139 else if (o_toolbar_info
.int_value
)
2142 toolbar_update_info(filer_window
);
2145 gtk_label_set_text(GTK_LABEL(filer_window
->toolbar_text
), "");
2148 static void set_selection_state(FilerWindow
*filer_window
, gboolean normal
)
2150 GtkStateType old_state
= filer_window
->selection_state
;
2152 filer_window
->selection_state
= normal
2153 ? GTK_STATE_SELECTED
: GTK_STATE_INSENSITIVE
;
2155 if (old_state
!= filer_window
->selection_state
2156 && view_count_selected(filer_window
->view
))
2157 gtk_widget_queue_draw(GTK_WIDGET(filer_window
->view
));
2160 void filer_cancel_thumbnails(FilerWindow
*filer_window
)
2162 gtk_widget_hide(filer_window
->thumb_bar
);
2164 destroy_glist(&filer_window
->thumb_queue
);
2165 filer_window
->max_thumbs
= 0;
2168 /* Generate the next thumb for this window. The window object is
2169 * unref'd when there is nothing more to do.
2170 * If the window no longer has a filer window, nothing is done.
2172 static gboolean
filer_next_thumb_real(GObject
*window
)
2174 FilerWindow
*filer_window
;
2178 filer_window
= g_object_get_data(window
, "filer_window");
2182 g_object_unref(window
);
2186 if (!filer_window
->thumb_queue
)
2188 filer_cancel_thumbnails(filer_window
);
2189 g_object_unref(window
);
2193 total
= filer_window
->max_thumbs
;
2194 done
= total
- g_list_length(filer_window
->thumb_queue
);
2196 path
= (gchar
*) filer_window
->thumb_queue
->data
;
2198 pixmap_background_thumb(path
, (GFunc
) filer_next_thumb
, window
);
2200 filer_window
->thumb_queue
= g_list_remove(filer_window
->thumb_queue
,
2204 gtk_progress_bar_set_fraction(
2205 GTK_PROGRESS_BAR(filer_window
->thumb_progress
),
2206 done
/ (float) total
);
2211 /* path is the thumb just loaded, if any.
2212 * window is unref'd (eventually).
2214 static void filer_next_thumb(GObject
*window
, const gchar
*path
)
2217 dir_force_update_path(path
);
2219 g_idle_add((GSourceFunc
) filer_next_thumb_real
, window
);
2222 static void start_thumb_scanning(FilerWindow
*filer_window
)
2224 if (GTK_WIDGET_VISIBLE(filer_window
->thumb_bar
))
2225 return; /* Already scanning */
2227 gtk_widget_show_all(filer_window
->thumb_bar
);
2229 g_object_ref(G_OBJECT(filer_window
->window
));
2230 filer_next_thumb(G_OBJECT(filer_window
->window
), NULL
);
2233 /* Set this image to be loaded some time in the future */
2234 void filer_create_thumb(FilerWindow
*filer_window
, const gchar
*path
)
2236 if (g_list_find_custom(filer_window
->thumb_queue
, path
,
2237 (GCompareFunc
) strcmp
))
2240 if (!filer_window
->thumb_queue
)
2241 filer_window
->max_thumbs
=0;
2242 filer_window
->max_thumbs
++;
2244 filer_window
->thumb_queue
= g_list_append(filer_window
->thumb_queue
,
2247 if (filer_window
->scanning
)
2248 return; /* Will start when scan ends */
2250 start_thumb_scanning(filer_window
);
2253 /* If thumbnail display is on, look through all the items in this directory
2254 * and start creating or updating the thumbnails as needed.
2256 void filer_create_thumbs(FilerWindow
*filer_window
)
2261 if (!filer_window
->show_thumbs
)
2264 view_get_iter(filer_window
->view
, &iter
, 0);
2266 while ((item
= iter
.next(&iter
)))
2268 MaskedPixmap
*pixmap
;
2272 if (item
->base_type
!= TYPE_FILE
)
2275 /*if (strcmp(item->mime_type->media_type, "image") != 0)
2278 path
= make_path(filer_window
->real_path
, item
->leafname
);
2280 pixmap
= g_fscache_lookup_full(pixmap_cache
, path
,
2281 FSCACHE_LOOKUP_ONLY_NEW
, &found
);
2283 g_object_unref(pixmap
);
2285 /* If we didn't get an image, it could be because:
2287 * - We're loading the image now. found is TRUE,
2288 * and we'll update the item later.
2289 * - We tried to load the image and failed. found
2291 * - We haven't tried loading the image. found is
2292 * FALSE, and we start creating the thumb here.
2295 filer_create_thumb(filer_window
, path
);
2299 static void filer_options_changed(void)
2301 if (o_short_flag_names
.has_changed
)
2305 for (next
= all_filer_windows
; next
; next
= next
->next
)
2307 FilerWindow
*filer_window
= (FilerWindow
*) next
->data
;
2309 filer_set_title(filer_window
);
2314 /* Append interesting information to this GString */
2315 void filer_add_tip_details(FilerWindow
*filer_window
,
2316 GString
*tip
, DirItem
*item
)
2318 const guchar
*fullpath
= NULL
;
2320 fullpath
= make_path(filer_window
->real_path
, item
->leafname
);
2322 if (item
->flags
& ITEM_FLAG_SYMLINK
)
2326 target
= readlink_dup(fullpath
);
2329 ensure_utf8(&target
);
2331 g_string_append(tip
, _("Symbolic link to "));
2332 g_string_append(tip
, target
);
2333 g_string_append_c(tip
, '\n');
2338 if (item
->flags
& ITEM_FLAG_APPDIR
)
2343 info
= appinfo_get(fullpath
, item
);
2344 if (info
&& ((node
= xml_get_section(info
, NULL
, "Summary"))))
2347 str
= xmlNodeListGetString(node
->doc
,
2348 node
->xmlChildrenNode
, 1);
2351 g_string_append(tip
, str
);
2352 g_string_append_c(tip
, '\n');
2357 g_object_unref(info
);
2359 else if (item
->mime_type
== application_x_desktop
)
2362 summary
= tip_from_desktop_file(fullpath
);
2365 g_string_append(tip
, summary
);
2366 g_string_append_c(tip
, '\n');
2371 if (!g_utf8_validate(item
->leafname
, -1, NULL
))
2372 g_string_append(tip
,
2373 _("This filename is not valid UTF-8. "
2374 "You should rename it.\n"));
2377 /* Return the selection as a text/uri-list.
2378 * g_free() the result.
2380 static guchar
*filer_create_uri_list(FilerWindow
*filer_window
)
2388 g_return_val_if_fail(filer_window
!= NULL
, NULL
);
2390 string
= g_string_new(NULL
);
2392 leader
= g_string_new(filer_window
->sym_path
);
2393 if (leader
->str
[leader
->len
- 1] != '/')
2394 g_string_append_c(leader
, '/');
2396 view_get_iter(filer_window
->view
, &iter
, VIEW_ITER_SELECTED
);
2397 while ((item
= iter
.next(&iter
)))
2402 path
= g_strconcat(leader
->str
, item
->leafname
, NULL
);
2403 uri
= encode_path_as_uri(path
);
2404 g_string_append(string
, (char *) uri
);
2405 g_string_append(string
, "\r\n");
2410 g_string_free(leader
, TRUE
);
2411 retval
= string
->str
;
2412 g_string_free(string
, FALSE
);
2417 void filer_perform_action(FilerWindow
*filer_window
, GdkEventButton
*event
)
2420 ViewIface
*view
= filer_window
->view
;
2421 DirItem
*item
= NULL
;
2422 gboolean press
= event
->type
== GDK_BUTTON_PRESS
;
2424 OpenFlags flags
= 0;
2426 if (event
->button
> 3)
2429 view_get_iter_at_point(view
, &iter
, event
->window
, event
->x
, event
->y
);
2430 item
= iter
.peek(&iter
);
2432 if (item
&& view_cursor_visible(view
))
2433 view_cursor_to_iter(view
, &iter
);
2435 if (item
&& event
->button
== 1 &&
2436 view_get_selected(view
, &iter
) &&
2437 filer_window
->selection_state
== GTK_STATE_INSENSITIVE
)
2439 /* Possibly a really slow DnD operation? */
2440 filer_window
->temp_item_selected
= FALSE
;
2442 filer_selection_changed(filer_window
, event
->time
);
2446 if (filer_window
->target_cb
)
2448 dnd_motion_ungrab();
2449 if (item
&& press
&& event
->button
== 1)
2450 filer_window
->target_cb(filer_window
, &iter
,
2451 filer_window
->target_data
);
2453 filer_target_mode(filer_window
, NULL
, NULL
, NULL
);
2458 if (!o_single_click
.int_value
)
2460 /* Make sure both parts of a double-click fall on
2463 static guchar
*first_click
= NULL
;
2464 static guchar
*second_click
= NULL
;
2466 if (event
->type
== GDK_BUTTON_PRESS
)
2468 g_free(first_click
);
2469 first_click
= second_click
;
2472 second_click
= g_strdup(item
->leafname
);
2474 second_click
= NULL
;
2477 if (event
->type
== GDK_2BUTTON_PRESS
)
2479 if (first_click
&& second_click
&&
2480 strcmp(first_click
, second_click
) != 0)
2482 if ((first_click
|| second_click
) &&
2483 !(first_click
&& second_click
))
2488 action
= bind_lookup_bev(
2489 item
? BIND_DIRECTORY_ICON
: BIND_DIRECTORY
,
2494 case ACT_CLEAR_SELECTION
:
2495 view_clear_selection(view
);
2497 case ACT_TOGGLE_SELECTED
:
2498 view_set_selected(view
, &iter
,
2499 !view_get_selected(view
, &iter
));
2501 case ACT_SELECT_EXCL
:
2502 view_select_only(view
, &iter
);
2505 flags
|= OPEN_SHIFT
;
2508 if (event
->button
!= 1 || event
->state
& GDK_MOD1_MASK
)
2509 flags
|= OPEN_CLOSE_WINDOW
;
2511 flags
|= OPEN_SAME_WINDOW
;
2512 if (o_new_button_1
.int_value
)
2513 flags
^= OPEN_SAME_WINDOW
;
2514 if (event
->type
== GDK_2BUTTON_PRESS
)
2515 view_set_selected(view
, &iter
, FALSE
);
2516 dnd_motion_ungrab();
2518 filer_openitem(filer_window
, &iter
, flags
);
2520 case ACT_POPUP_MENU
:
2521 dnd_motion_ungrab();
2523 show_filer_menu(filer_window
,
2524 (GdkEvent
*) event
, &iter
);
2526 case ACT_PRIME_AND_SELECT
:
2527 if (item
&& !view_get_selected(view
, &iter
))
2528 view_select_only(view
, &iter
);
2529 dnd_motion_start(MOTION_READY_FOR_DND
);
2531 case ACT_PRIME_AND_TOGGLE
:
2532 view_set_selected(view
, &iter
,
2533 !view_get_selected(view
, &iter
));
2534 dnd_motion_start(MOTION_READY_FOR_DND
);
2536 case ACT_PRIME_FOR_DND
:
2537 dnd_motion_start(MOTION_READY_FOR_DND
);
2540 if (press
&& event
->button
< 4)
2543 view_wink_item(view
, &iter
);
2544 dnd_motion_start(MOTION_NONE
);
2547 case ACT_LASSO_CLEAR
:
2548 view_clear_selection(view
);
2550 case ACT_LASSO_MODIFY
:
2551 view_start_lasso_box(view
, event
);
2554 view_autosize(filer_window
->view
);
2557 g_warning("Unsupported action : %d\n", action
);
2562 /* It's time to make the tooltip appear. If we're not over the item any
2563 * more, or the item doesn't need a tooltip, do nothing.
2565 static gboolean
tooltip_activate(GtkWidget
*window
)
2567 FilerWindow
*filer_window
;
2571 DirItem
*item
= NULL
;
2572 GString
*tip
= NULL
;
2574 g_return_val_if_fail(tip_item
!= NULL
, 0);
2576 filer_window
= g_object_get_data(G_OBJECT(window
), "filer_window");
2578 if (!motion_window
|| !filer_window
)
2579 return FALSE
; /* Window has been destroyed */
2581 view
= filer_window
->view
;
2585 gdk_window_get_pointer(motion_window
, &x
, &y
, NULL
);
2586 view_get_iter_at_point(view
, &iter
, motion_window
, x
, y
);
2588 item
= iter
.peek(&iter
);
2589 if (item
!= tip_item
)
2590 return FALSE
; /* Not still under the pointer */
2592 /* OK, the filer window still exists and the pointer is still
2593 * over the same item. Do we need to show a tip?
2596 tip
= g_string_new(NULL
);
2598 view_extend_tip(filer_window
->view
, &iter
, tip
);
2600 filer_add_tip_details(filer_window
, tip
, tip_item
);
2604 g_string_truncate(tip
, tip
->len
- 1);
2606 tooltip_show(tip
->str
);
2609 g_string_free(tip
, TRUE
);
2614 /* Motion detected on the View widget */
2615 gint
filer_motion_notify(FilerWindow
*filer_window
, GdkEventMotion
*event
)
2617 ViewIface
*view
= filer_window
->view
;
2621 view_get_iter_at_point(view
, &iter
, event
->window
, event
->x
, event
->y
);
2622 item
= iter
.peek(&iter
);
2626 if (item
!= tip_item
)
2631 motion_window
= event
->window
;
2632 tooltip_prime((GtkFunction
) tooltip_activate
,
2633 G_OBJECT(filer_window
->window
));
2642 if (motion_state
!= MOTION_READY_FOR_DND
)
2645 if (!dnd_motion_moved(event
))
2648 view_get_iter_at_point(view
, &iter
,
2650 event
->x
- (event
->x_root
- drag_start_x
),
2651 event
->y
- (event
->y_root
- drag_start_y
));
2652 item
= iter
.peek(&iter
);
2656 view_wink_item(view
, NULL
);
2658 if (!view_get_selected(view
, &iter
))
2660 /* If we drag an unselected item, select it only.
2661 * Unless we're also holding down Ctrl, in which case
2662 * it's probably unselected only because we
2663 * mis-interpreted the click as toggle-selected.
2665 if ((event
->state
& GDK_BUTTON1_MASK
) &&
2666 !(event
->state
& GDK_CONTROL_MASK
))
2668 /* Select just this one */
2669 filer_window
->temp_item_selected
= TRUE
;
2670 view_select_only(view
, &iter
);
2674 if (view_count_selected(view
) == 0)
2675 filer_window
->temp_item_selected
= TRUE
;
2676 view_set_selected(view
, &iter
, TRUE
);
2680 g_return_val_if_fail(view_count_selected(view
) > 0, TRUE
);
2682 if (view_count_selected(view
) == 1)
2684 if (item
->base_type
== TYPE_UNKNOWN
)
2685 item
= dir_update_item(filer_window
->directory
,
2690 report_error(_("Item no longer exists!"));
2694 drag_one_item(GTK_WIDGET(view
), event
,
2695 make_path(filer_window
->sym_path
, item
->leafname
),
2696 item
, di_image(item
));
2698 /* XXX: Use thumbnail */
2699 item
, view
? view
->image
: NULL
);
2706 uris
= filer_create_uri_list(filer_window
);
2707 drag_selection(GTK_WIDGET(view
), event
, uris
);
2714 static void drag_end(GtkWidget
*widget
, GdkDragContext
*context
,
2715 FilerWindow
*filer_window
)
2717 filer_set_autoscroll(filer_window
, FALSE
);
2719 if (filer_window
->temp_item_selected
)
2721 view_clear_selection(filer_window
->view
);
2722 filer_window
->temp_item_selected
= FALSE
;
2726 /* Remove highlights */
2727 static void drag_leave(GtkWidget
*widget
,
2728 GdkDragContext
*context
,
2730 FilerWindow
*filer_window
)
2735 /* Called during the drag when the mouse is in a widget registered
2736 * as a drop target. Returns TRUE if we can accept the drop.
2738 static gboolean
drag_motion(GtkWidget
*widget
,
2739 GdkDragContext
*context
,
2743 FilerWindow
*filer_window
)
2746 ViewIface
*view
= filer_window
->view
;
2748 GdkDragAction action
= context
->suggested_action
;
2749 const guchar
*new_path
= NULL
;
2750 const char *type
= NULL
;
2751 gboolean retval
= FALSE
;
2752 gboolean same_window
;
2754 if ((context
->actions
& GDK_ACTION_ASK
) && o_dnd_left_menu
.int_value
)
2757 gdk_window_get_pointer(NULL
, NULL
, NULL
, &state
);
2758 if (state
& GDK_BUTTON1_MASK
)
2759 action
= GDK_ACTION_ASK
;
2762 same_window
= gtk_drag_get_source_widget(context
) == widget
;
2764 filer_set_autoscroll(filer_window
, TRUE
);
2766 if (filer_window
->view_type
== VIEW_TYPE_DETAILS
)
2770 /* Correct for position of bin window */
2771 bin
= gtk_tree_view_get_bin_window(GTK_TREE_VIEW(view
));
2772 gdk_window_get_position(bin
, NULL
, &bin_y
);
2776 if (o_dnd_drag_to_icons
.int_value
)
2778 view_get_iter_at_point(view
, &iter
, widget
->window
, x
, y
);
2779 item
= iter
.peek(&iter
);
2784 if (item
&& same_window
&& view_get_selected(view
, &iter
))
2787 type
= dnd_motion_item(context
, &item
);
2792 /* Don't allow drops to non-writeable directories. BUT, still
2793 * allow drops on non-writeable SUBdirectories so that we can
2794 * do the spring-open thing.
2796 if (item
&& type
== drop_dest_dir
&&
2797 !(item
->flags
& ITEM_FLAG_APPDIR
))
2799 dnd_spring_load(context
, filer_window
);
2805 view_cursor_to_iter(view
, &iter
);
2808 view_cursor_to_iter(view
, NULL
);
2810 /* Disallow background drops within a single window */
2811 if (type
&& same_window
)
2818 new_path
= make_path(filer_window
->sym_path
,
2821 new_path
= filer_window
->sym_path
;
2824 /* Don't ask about dragging to an application! */
2825 if (type
== drop_dest_prog
&& action
== GDK_ACTION_ASK
)
2826 action
= GDK_ACTION_COPY
;
2828 g_dataset_set_data(context
, "drop_dest_type", (gpointer
) type
);
2831 gdk_drag_status(context
, action
, time
);
2832 g_dataset_set_data_full(context
, "drop_dest_path",
2833 g_strdup(new_path
), g_free
);
2840 static gboolean
as_timeout(FilerWindow
*filer_window
)
2844 retval
= view_auto_scroll_callback(filer_window
->view
);
2847 filer_window
->auto_scroll
= -1;
2852 /* When autoscroll is on, a timer keeps track of the pointer position.
2853 * While it's near the top or bottom of the window, the window scrolls.
2855 * If the mouse buttons are released, the pointer leaves the window, or
2856 * a drag-and-drop operation finishes, auto_scroll is turned off.
2858 void filer_set_autoscroll(FilerWindow
*filer_window
, gboolean auto_scroll
)
2860 g_return_if_fail(filer_window
!= NULL
);
2864 if (filer_window
->auto_scroll
!= -1)
2865 return; /* Already on! */
2867 filer_window
->auto_scroll
= g_timeout_add(50,
2868 (GSourceFunc
) as_timeout
,
2873 if (filer_window
->auto_scroll
== -1)
2874 return; /* Already off! */
2876 g_source_remove(filer_window
->auto_scroll
);
2877 filer_window
->auto_scroll
= -1;
2881 #define ZERO_MNT "/uri/0install"
2883 static void refresh_done(FilerWindow
*filer_window
)
2885 if (filer_exists(filer_window
))
2886 filer_update_dir(filer_window
, TRUE
);
2889 void filer_refresh(FilerWindow
*filer_window
)
2891 if (!strncmp(ZERO_MNT
"/", filer_window
->real_path
, sizeof(ZERO_MNT
)))
2893 /* Try to run 0refresh */
2895 gchar
*argv
[] = {"0refresh", NULL
, NULL
};
2896 const char *host
= filer_window
->real_path
+ sizeof(ZERO_MNT
);
2899 slash
= strchr(host
, '/');
2901 argv
[1] = g_strndup(host
, slash
- host
);
2903 argv
[1] = g_strdup(host
);
2904 pid
= rox_spawn(filer_window
->real_path
, (const char **) argv
);
2907 on_child_death(pid
, (CallbackFn
) refresh_done
,
2914 static inline gboolean
is_hidden(const char *dir
, DirItem
*item
)
2916 /* If the leaf name starts with '.' then the item is hidden */
2917 if(item
->leafname
[0]=='.')
2920 /*** Test disabled for now. The flags aren't set on the first pass...
2923 /* Most files will not have extended attributes, so this should
2925 if(!o_xattr_ignore
.int_value
&& (item
->flags
& ITEM_FLAG_HAS_XATTR
)) {
2928 gboolean hidden
=FALSE
;
2930 path
=g_build_filename(dir
, item
->leafname
, NULL
);
2931 val
=xattr_get(path
, XATTR_HIDDEN
, &len
);
2933 hidden
=atoi(val
) || (strcmp(val
, "true")==0);
2943 /* Otherwise not hidden */
2947 gboolean
filer_match_filter(FilerWindow
*filer_window
, DirItem
*item
)
2949 g_return_val_if_fail(item
!= NULL
, FALSE
);
2951 if(is_hidden(filer_window
->real_path
, item
) &&
2952 (!filer_window
->temp_show_hidden
&& !filer_window
->show_hidden
))
2955 switch(filer_window
->filter
) {
2956 case FILER_SHOW_GLOB
:
2957 return fnmatch(filer_window
->filter_string
,
2958 item
->leafname
, 0)==0 ||
2959 (item
->base_type
==TYPE_DIRECTORY
&&
2960 !filer_window
->filter_directories
);
2962 case FILER_SHOW_ALL
:
2969 /* Provided to hide the implementation */
2970 void filer_set_hidden(FilerWindow
*filer_window
, gboolean hidden
)
2972 filer_window
->show_hidden
=hidden
;
2975 /* Provided to hide the implementation */
2976 void filer_set_filter_directories(FilerWindow
*filer_window
, gboolean filter_directories
)
2978 filer_window
->filter_directories
=filter_directories
;
2981 /* Set the filter type. Returns TRUE if the type has changed
2982 * (must call filer_detach_rescan).
2984 gboolean
filer_set_filter(FilerWindow
*filer_window
, FilterType type
,
2985 const gchar
*filter_string
)
2987 /* Is this new filter the same as the old one? */
2988 if (filer_window
->filter
== type
)
2990 switch(filer_window
->filter
)
2992 case FILER_SHOW_ALL
:
2994 case FILER_SHOW_GLOB
:
2995 if (strcmp(filer_window
->filter_string
,
2996 filter_string
) == 0)
3002 /* Clean up old filter */
3003 if (filer_window
->filter_string
)
3005 g_free(filer_window
->filter_string
);
3006 filer_window
->filter_string
= NULL
;
3008 /* Also clean up compiled regexp when implemented */
3010 filer_window
->filter
= type
;
3014 case FILER_SHOW_ALL
:
3018 case FILER_SHOW_GLOB
:
3019 filer_window
->filter_string
= g_strdup(filter_string
);
3024 filer_window
->filter
= FILER_SHOW_ALL
;
3025 g_warning("Impossible: filter type %d", type
);
3033 static Settings
*settings_new(const char *path
)
3037 set
=g_new(Settings
, 1);
3038 memset(set
, 0, sizeof(Settings
));
3040 set
->path
=g_strdup(path
);
3045 static void settings_free(Settings
*set
)
3049 g_free(set
->filter
);
3053 static void store_settings(Settings
*set
)
3057 old
=g_hash_table_lookup(settings_table
, set
->path
);
3060 g_hash_table_remove(settings_table
, set
->path
);
3064 g_hash_table_insert(settings_table
, set
->path
, set
);
3067 /* TODO: use symbolic names in the XML file where possible */
3068 static void load_from_node(Settings
*set
, xmlDocPtr doc
, xmlNodePtr node
)
3072 str
=xmlNodeListGetString(doc
, node
->xmlChildrenNode
, 1);
3074 if(strcmp(node
->name
, "X") == 0) {
3076 set
->flags
|=SET_POSITION
;
3077 } else if(strcmp(node
->name
, "Y") == 0) {
3079 set
->flags
|=SET_POSITION
;
3080 } else if(strcmp(node
->name
, "Width") == 0) {
3081 set
->width
=atoi(str
);
3082 set
->flags
|=SET_SIZE
;
3083 } else if(strcmp(node
->name
, "Height") == 0) {
3084 set
->height
=atoi(str
);
3085 set
->flags
|=SET_SIZE
;
3086 } else if(strcmp(node
->name
, "ShowHidden") == 0) {
3087 set
->show_hidden
=atoi(str
);
3088 set
->flags
|=SET_HIDDEN
;
3089 } else if(strcmp(node
->name
, "ViewType") == 0) {
3090 set
->view_type
=atoi(str
);
3091 set
->flags
|=SET_DETAILS
;
3092 } else if(strcmp(node
->name
, "DetailsType") == 0) {
3093 set
->details_type
=atoi(str
);
3094 set
->flags
|=SET_DETAILS
;
3095 } else if(strcmp(node
->name
, "SortType") == 0) {
3096 set
->sort_type
=atoi(str
);
3097 set
->flags
|=SET_SORT
;
3098 } else if(strcmp(node
->name
, "SortOrder") == 0) {
3099 set
->sort_order
=atoi(str
);
3100 set
->flags
|=SET_SORT
;
3101 } else if(strcmp(node
->name
, "DisplayStyle") == 0) {
3102 set
->display_style
=atoi(str
);
3103 set
->flags
|=SET_STYLE
;
3104 } else if(strcmp(node
->name
, "ShowThumbs") == 0) {
3105 set
->show_thumbs
=atoi(str
);
3106 set
->flags
|=SET_THUMBS
;
3107 } else if(strcmp(node
->name
, "FilterType") == 0) {
3108 set
->filter_type
=atoi(str
);
3109 set
->flags
|=SET_FILTER
;
3110 } else if(strcmp(node
->name
, "Filter") == 0) {
3111 set
->filter
=g_strdup(str
);
3112 set
->flags
|=SET_FILTER
;
3113 } else if(strcmp(node
->name
, "FilterDirectories") == 0) {
3114 set
->filter_directories
=atoi(str
);
3115 set
->flags
|=SET_FILTER
;
3122 static void load_settings(void)
3125 XMLwrapper
*settings_doc
=NULL
;
3127 path
=choices_find_xdg_path_load("Settings.xml", PROJECT
, SITE
);
3129 settings_doc
=xml_new(path
);
3134 settings_table
=g_hash_table_new(g_str_hash
, g_str_equal
);
3137 xmlNodePtr node
, subnode
;
3139 node
= xmlDocGetRootElement(settings_doc
->doc
);
3141 for (node
= node
->xmlChildrenNode
; node
; node
= node
->next
)
3146 if (node
->type
!= XML_ELEMENT_NODE
)
3148 if (strcmp(node
->name
, "FilerWindow") != 0)
3151 path
=xmlGetProp(node
, "path");
3152 set
=settings_new(path
);
3155 for (subnode
=node
->xmlChildrenNode
; subnode
;
3156 subnode
=subnode
->next
) {
3158 if (subnode
->type
!= XML_ELEMENT_NODE
)
3160 load_from_node(set
, settings_doc
->doc
,
3164 store_settings(set
);
3166 g_object_unref(settings_doc
);
3170 static void add_nodes(gpointer key
, gpointer value
, gpointer data
)
3172 xmlNodePtr node
=(xmlNodePtr
) data
;
3174 Settings
*set
=(Settings
*) value
;
3177 sub
=xmlNewChild(node
, NULL
, "FilerWindow", NULL
);
3179 xmlSetProp(sub
, "path", set
->path
);
3181 if(set
->flags
& SET_POSITION
) {
3182 tmp
=g_strdup_printf("%d", set
->x
);
3183 xmlNewChild(sub
, NULL
, "X", tmp
);
3185 tmp
=g_strdup_printf("%d", set
->y
);
3186 xmlNewChild(sub
, NULL
, "Y", tmp
);
3189 if(set
->flags
& SET_SIZE
) {
3190 tmp
=g_strdup_printf("%d", set
->width
);
3191 xmlNewChild(sub
, NULL
, "Width", tmp
);
3193 tmp
=g_strdup_printf("%d", set
->height
);
3194 xmlNewChild(sub
, NULL
, "Height", tmp
);
3197 if(set
->flags
& SET_HIDDEN
) {
3198 tmp
=g_strdup_printf("%d", set
->show_hidden
);
3199 xmlNewChild(sub
, NULL
, "ShowHidden", tmp
);
3202 if(set
->flags
& SET_STYLE
) {
3203 tmp
=g_strdup_printf("%d", set
->display_style
);
3204 xmlNewChild(sub
, NULL
, "DisplayStyle", tmp
);
3207 if(set
->flags
& SET_SORT
) {
3208 tmp
=g_strdup_printf("%d", set
->sort_type
);
3209 xmlNewChild(sub
, NULL
, "SortType", tmp
);
3211 tmp
=g_strdup_printf("%d", set
->sort_order
);
3212 xmlNewChild(sub
, NULL
, "SortOrder", tmp
);
3215 if(set
->flags
& SET_DETAILS
) {
3216 tmp
=g_strdup_printf("%d", set
->view_type
);
3217 xmlNewChild(sub
, NULL
, "ViewType", tmp
);
3219 tmp
=g_strdup_printf("%d", set
->details_type
);
3220 xmlNewChild(sub
, NULL
, "DetailsType", tmp
);
3223 if(set
->flags
& SET_STYLE
) {
3224 tmp
=g_strdup_printf("%d", set
->show_thumbs
);
3225 xmlNewChild(sub
, NULL
, "ShowThumbs", tmp
);
3228 if(set
->flags
& SET_FILTER
) {
3229 tmp
=g_strdup_printf("%d", set
->filter_type
);
3230 xmlNewChild(sub
, NULL
, "FilterType", tmp
);
3232 if(set
->filter
&& set
->filter
[0])
3233 xmlNewChild(sub
, NULL
, "Filter", set
->filter
);
3234 tmp
=g_strdup_printf("%d", set
->filter_directories
);
3235 xmlNewChild(sub
, NULL
, "FilterDirectories", tmp
);
3239 static void save_settings(void)
3243 path
=choices_find_xdg_path_save("Settings.xml", PROJECT
, SITE
, TRUE
);
3245 xmlDocPtr doc
= xmlNewDoc("1.0");
3246 xmlDocSetRootElement(doc
, xmlNewDocNode(doc
, NULL
,
3249 g_hash_table_foreach(settings_table
, add_nodes
,
3250 xmlDocGetRootElement(doc
));
3252 save_xml_file(doc
, path
);
3260 static void check_settings(FilerWindow
*filer_window
)
3264 set
=(Settings
*) g_hash_table_lookup(settings_table
,
3265 filer_window
->sym_path
);
3268 if(set
->flags
& SET_POSITION
)
3269 gtk_window_move(GTK_WINDOW(filer_window
->window
),
3271 if(set
->flags
& SET_SIZE
)
3272 filer_window_set_size(filer_window
, set
->width
,
3274 if(set
->flags
& SET_HIDDEN
)
3275 filer_set_hidden(filer_window
, set
->show_hidden
);
3277 if(set
->flags
& (SET_STYLE
|SET_DETAILS
)) {
3278 DisplayStyle style
=filer_window
->display_style
;
3279 DetailsType details
=filer_window
->details_type
;
3281 if(set
->flags
& SET_STYLE
)
3282 style
=set
->display_style
;
3284 if(set
->flags
& SET_DETAILS
) {
3285 details
=set
->details_type
;
3287 filer_set_view_type(filer_window
,
3291 display_set_layout(filer_window
, style
,
3295 if(set
->flags
& SET_SORT
)
3296 display_set_sort_type(filer_window
,
3300 if(set
->flags
& SET_THUMBS
)
3301 display_set_thumbs(filer_window
,
3304 if(set
->flags
& SET_FILTER
)
3306 display_set_filter(filer_window
,
3309 display_set_filter_directories(filer_window
,
3310 set
->filter_directories
);
3316 typedef struct settings_window
{
3319 GtkWidget
*pos
, *size
, *hidden
, *style
, *sort
, *details
,
3326 static void settings_response(GtkWidget
*window
, gint response
,
3327 SettingsWindow
*set_win
)
3329 if(response
==GTK_RESPONSE_OK
) {
3332 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(set_win
->pos
)))
3333 flags
|=SET_POSITION
;
3334 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(set_win
->size
)))
3336 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(set_win
->hidden
)))
3338 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(set_win
->style
)))
3340 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(set_win
->sort
)))
3342 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(set_win
->details
)))
3344 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(set_win
->thumbs
)))
3346 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(set_win
->filter
)))
3349 set_win
->set
->flags
=flags
;
3350 store_settings(set_win
->set
);
3354 gtk_widget_destroy(window
);
3357 void filer_save_settings(FilerWindow
*fwin
)
3359 SettingsWindow
*set_win
;
3360 GtkWidget
*vbox
, *frame
;
3361 GtkWidget
*path
, *lbl
;
3364 Settings
*set
=settings_new(fwin
->sym_path
);
3366 gtk_window_get_position(GTK_WINDOW(fwin
->window
),&x
, &y
);
3367 set
->flags
|=SET_POSITION
;
3371 gtk_window_get_size(GTK_WINDOW(fwin
->window
),&x
, &y
);
3372 set
->flags
|=SET_SIZE
;
3376 set
->flags
|=SET_HIDDEN
;
3377 set
->show_hidden
=fwin
->show_hidden
;
3379 set
->flags
|=SET_STYLE
;
3380 set
->display_style
=fwin
->display_style
;
3382 set
->flags
|=SET_SORT
;
3383 set
->sort_type
=fwin
->sort_type
;
3384 set
->sort_order
=fwin
->sort_order
;
3386 set
->flags
|=SET_DETAILS
;
3387 set
->view_type
=fwin
->view_type
;
3388 set
->details_type
=fwin
->details_type
;
3390 set
->flags
|=SET_THUMBS
;
3391 set
->show_thumbs
=fwin
->show_thumbs
;
3393 set
->flags
|=SET_FILTER
;
3394 set
->filter_type
=fwin
->filter
;
3395 if(fwin
->filter_string
)
3396 set
->filter
=g_strdup(fwin
->filter_string
);
3397 set
->filter_directories
=fwin
->filter_directories
;
3399 /* Store other parameters
3401 set_win
=g_new(SettingsWindow
, 1);
3403 set_win
->window
=gtk_dialog_new();
3404 number_of_windows
++;
3406 gtk_dialog_add_button(GTK_DIALOG(set_win
->window
),
3407 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
);
3408 gtk_dialog_add_button(GTK_DIALOG(set_win
->window
),
3409 GTK_STOCK_OK
, GTK_RESPONSE_OK
);
3411 g_signal_connect(set_win
->window
, "destroy",
3412 G_CALLBACK(one_less_window
), NULL
);
3413 g_signal_connect_swapped(set_win
->window
, "destroy",
3414 G_CALLBACK(g_free
), set_win
);
3416 gtk_window_set_title(GTK_WINDOW(set_win
->window
),
3417 _("Select display properties to save"));
3419 vbox
=GTK_DIALOG(set_win
->window
)->vbox
;
3421 lbl
=gtk_label_new(_("<b>Save display settings for directory</b>"));
3422 gtk_label_set_use_markup(GTK_LABEL(lbl
), TRUE
);
3423 gtk_box_pack_start(GTK_BOX(vbox
), lbl
, FALSE
, FALSE
, 2);
3425 path
=gtk_label_new(set
->path
);
3426 gtk_box_pack_start(GTK_BOX(vbox
), path
, FALSE
, FALSE
, 2);
3428 frame
=gtk_frame_new(_("Select settings to save"));
3429 gtk_box_pack_start(GTK_BOX(vbox
), frame
, TRUE
, TRUE
, 2);
3431 /*Make new vbox to go in the frame */
3432 vbox
=gtk_vbox_new(FALSE
, 2);
3433 gtk_container_add(GTK_CONTAINER(frame
), vbox
);
3435 set_win
->pos
=gtk_check_button_new_with_label(_("Position"));
3436 gtk_box_pack_start(GTK_BOX(vbox
), set_win
->pos
, FALSE
, FALSE
, 2);
3437 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(set_win
->pos
),
3438 set
->flags
& SET_POSITION
);
3440 set_win
->size
=gtk_check_button_new_with_label(_("Size"));
3441 gtk_box_pack_start(GTK_BOX(vbox
), set_win
->size
, FALSE
, FALSE
, 2);
3442 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(set_win
->size
),
3443 set
->flags
& SET_SIZE
);
3445 set_win
->hidden
=gtk_check_button_new_with_label(_("Show hidden"));
3446 gtk_box_pack_start(GTK_BOX(vbox
), set_win
->hidden
,
3448 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(set_win
->hidden
),
3449 set
->flags
& SET_HIDDEN
);
3451 set_win
->style
=gtk_check_button_new_with_label(_("Display style"));
3452 gtk_box_pack_start(GTK_BOX(vbox
), set_win
->style
,
3454 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(set_win
->style
),
3455 set
->flags
& SET_STYLE
);
3457 set_win
->sort
=gtk_check_button_new_with_label(_("Sort type and order"));
3458 gtk_box_pack_start(GTK_BOX(vbox
), set_win
->sort
, FALSE
, FALSE
, 2);
3459 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(set_win
->sort
),
3460 set
->flags
& SET_SORT
);
3462 set_win
->details
=gtk_check_button_new_with_label(_("Details"));
3463 gtk_box_pack_start(GTK_BOX(vbox
), set_win
->details
, FALSE
, FALSE
, 2);
3464 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(set_win
->details
),
3465 set
->flags
& SET_DETAILS
);
3467 set_win
->thumbs
=gtk_check_button_new_with_label(_("Thumbnails"));
3468 gtk_box_pack_start(GTK_BOX(vbox
), set_win
->thumbs
,
3470 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(set_win
->thumbs
),
3471 set
->flags
& SET_THUMBS
);
3473 set_win
->filter
=gtk_check_button_new_with_label(_("Filter"));
3474 gtk_box_pack_start(GTK_BOX(vbox
), set_win
->filter
,
3476 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(set_win
->filter
),
3477 set
->flags
& SET_FILTER
);
3480 g_signal_connect(set_win
->window
, "response",
3481 G_CALLBACK(settings_response
), set_win
);
3483 gtk_widget_show_all(set_win
->window
);
3486 static char *tip_from_desktop_file(const char *full_path
)
3488 GError
*error
= NULL
;
3489 char *comment
= NULL
;
3491 comment
= get_value_from_desktop_file(full_path
,
3492 "Desktop Entry", "Comment", &error
);
3495 delayed_error("Failed to parse .desktop file '%s':\n%s",
3496 full_path
, error
->message
);
3502 g_error_free(error
);