No issues found
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2
3 /* nautilus-bookmark.c - implementation of individual bookmarks.
4 *
5 * Copyright (C) 1999, 2000 Eazel, Inc.
6 * Copyright (C) 2011, Red Hat, Inc.
7 *
8 * The Gnome Library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public License as
10 * published by the Free Software Foundation; either version 2 of the
11 * License, or (at your option) any later version.
12 *
13 * The Gnome Library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
17 *
18 * You should have received a copy of the GNU Library General Public
19 * License along with the Gnome Library; see the file COPYING.LIB. If not,
20 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
22 *
23 * Authors: John Sullivan <sullivan@eazel.com>
24 * Cosimo Cecchi <cosimoc@redhat.com>
25 */
26
27 #include <config.h>
28
29 #include "nautilus-bookmark.h"
30
31 #include <eel/eel-vfs-extensions.h>
32 #include <gio/gio.h>
33 #include <glib/gi18n.h>
34 #include <gtk/gtk.h>
35
36 #include <libnautilus-private/nautilus-file.h>
37 #include <libnautilus-private/nautilus-file-utilities.h>
38 #include <libnautilus-private/nautilus-icon-names.h>
39
40 #define DEBUG_FLAG NAUTILUS_DEBUG_BOOKMARKS
41 #include <libnautilus-private/nautilus-debug.h>
42
43 enum {
44 CONTENTS_CHANGED,
45 LAST_SIGNAL
46 };
47
48 enum {
49 PROP_NAME = 1,
50 PROP_CUSTOM_NAME,
51 PROP_LOCATION,
52 PROP_ICON,
53 PROP_SYMBOLIC_ICON,
54 NUM_PROPERTIES
55 };
56
57 #define ELLIPSISED_MENU_ITEM_MIN_CHARS 32
58
59 static GParamSpec* properties[NUM_PROPERTIES] = { NULL };
60 static guint signals[LAST_SIGNAL];
61
62 struct NautilusBookmarkDetails
63 {
64 char *name;
65 gboolean has_custom_name;
66 GFile *location;
67 gboolean location_gone;
68 GIcon *icon;
69 GIcon *symbolic_icon;
70 NautilusFile *file;
71
72 char *scroll_file;
73 };
74
75 static void nautilus_bookmark_disconnect_file (NautilusBookmark *file);
76
77 G_DEFINE_TYPE (NautilusBookmark, nautilus_bookmark, G_TYPE_OBJECT);
78
79 static void
80 nautilus_bookmark_set_name_internal (NautilusBookmark *bookmark,
81 const char *new_name)
82 {
83 if (g_strcmp0 (bookmark->details->name, new_name) != 0) {
84 g_free (bookmark->details->name);
85 bookmark->details->name = g_strdup (new_name);
86
87 g_object_notify_by_pspec (G_OBJECT (bookmark), properties[PROP_NAME]);
88 }
89 }
90
91 static void
92 bookmark_set_name_from_ready_file (NautilusBookmark *self,
93 NautilusFile *file)
94 {
95 gchar *display_name;
96
97 if (self->details->has_custom_name) {
98 return;
99 }
100
101 display_name = nautilus_file_get_display_name (self->details->file);
102
103 if (nautilus_file_is_home (self->details->file)) {
104 nautilus_bookmark_set_name_internal (self, _("Home"));
105 } else if (g_strcmp0 (self->details->name, display_name) != 0) {
106 nautilus_bookmark_set_name_internal (self, display_name);
107 DEBUG ("%s: name changed to %s", nautilus_bookmark_get_name (self), display_name);
108 }
109
110 g_free (display_name);
111 }
112
113 static void
114 bookmark_file_changed_callback (NautilusFile *file,
115 NautilusBookmark *bookmark)
116 {
117 GFile *location;
118
119 g_assert (file == bookmark->details->file);
120
121 DEBUG ("%s: file changed", nautilus_bookmark_get_name (bookmark));
122
123 location = nautilus_file_get_location (file);
124
125 if (!g_file_equal (bookmark->details->location, location) &&
126 !nautilus_file_is_in_trash (file)) {
127 DEBUG ("%s: file got moved", nautilus_bookmark_get_name (bookmark));
128
129 g_object_unref (bookmark->details->location);
130 bookmark->details->location = g_object_ref (location);
131
132 g_object_notify_by_pspec (G_OBJECT (bookmark), properties[PROP_LOCATION]);
133 g_signal_emit (bookmark, signals[CONTENTS_CHANGED], 0);
134 }
135
136 g_object_unref (location);
137
138 if (nautilus_file_is_gone (file) ||
139 nautilus_file_is_in_trash (file)) {
140 /* The file we were monitoring has been trashed, deleted,
141 * or moved in a way that we didn't notice. We should make
142 * a spanking new NautilusFile object for this
143 * location so if a new file appears in this place
144 * we will notice. However, we can't immediately do so
145 * because creating a new NautilusFile directly as a result
146 * of noticing a file goes away may trigger i/o on that file
147 * again, noticeing it is gone, leading to a loop.
148 * So, the new NautilusFile is created when the bookmark
149 * is used again. However, this is not really a problem, as
150 * we don't want to change the icon or anything about the
151 * bookmark just because its not there anymore.
152 */
153 DEBUG ("%s: trashed", nautilus_bookmark_get_name (bookmark));
154 bookmark->details->location_gone = TRUE;
155 nautilus_bookmark_disconnect_file (bookmark);
156 } else {
157 bookmark->details->location_gone = FALSE;
158 bookmark_set_name_from_ready_file (bookmark, file);
159 }
160 }
161
162 static void
163 apply_warning_emblem (GIcon **base,
164 gboolean symbolic)
165 {
166 GIcon *warning, *emblemed_icon;
167 GEmblem *emblem;
168
169 if (symbolic) {
170 warning = g_themed_icon_new ("dialog-warning-symbolic");
171 } else {
172 warning = g_themed_icon_new (GTK_STOCK_DIALOG_WARNING);
173 }
174
175 emblem = g_emblem_new (warning);
176 emblemed_icon = g_emblemed_icon_new (*base, emblem);
177
178 g_object_unref (emblem);
179 g_object_unref (warning);
180 g_object_unref (*base);
181
182 *base = emblemed_icon;
183 }
184
185 static GIcon *
186 get_native_icon (NautilusBookmark *bookmark,
187 gboolean symbolic)
188 {
189 gint idx;
190 GIcon *icon = NULL;
191
192 if (bookmark->details->file == NULL) {
193 goto out;
194 }
195
196 for (idx = 0; idx < G_USER_N_DIRECTORIES; idx++) {
197 if (nautilus_file_is_user_special_directory (bookmark->details->file, idx)) {
198 break;
199 }
200 }
201
202 if (idx < G_USER_N_DIRECTORIES) {
203 if (symbolic) {
204 icon = nautilus_special_directory_get_symbolic_icon (idx);
205 } else {
206 icon = nautilus_special_directory_get_icon (idx);
207 }
208 }
209
210 out:
211 if (icon == NULL) {
212 if (symbolic) {
213 icon = g_themed_icon_new (NAUTILUS_ICON_FOLDER);
214 } else {
215 icon = g_themed_icon_new (NAUTILUS_ICON_FULLCOLOR_FOLDER);
216 }
217 }
218
219 return icon;
220 }
221
222 static void
223 nautilus_bookmark_set_icon_to_default (NautilusBookmark *bookmark)
224 {
225 GIcon *icon, *symbolic_icon;
226 char *uri;
227
228 if (g_file_is_native (bookmark->details->location)) {
229 symbolic_icon = get_native_icon (bookmark, TRUE);
230 icon = get_native_icon (bookmark, FALSE);
231 } else {
232 uri = nautilus_bookmark_get_uri (bookmark);
233 if (g_str_has_prefix (uri, EEL_SEARCH_URI)) {
234 symbolic_icon = g_themed_icon_new (NAUTILUS_ICON_FOLDER_SAVED_SEARCH);
235 icon = g_themed_icon_new (NAUTILUS_ICON_FULLCOLOR_FOLDER_SAVED_SEARCH);
236 } else {
237 symbolic_icon = g_themed_icon_new (NAUTILUS_ICON_FOLDER_REMOTE);
238 icon = g_themed_icon_new (NAUTILUS_ICON_FULLCOLOR_FOLDER_REMOTE);
239 }
240 g_free (uri);
241 }
242
243 if (nautilus_bookmark_uri_known_not_to_exist (bookmark)) {
244 DEBUG ("%s: file does not exist, add emblem", nautilus_bookmark_get_name (bookmark));
245
246 apply_warning_emblem (&icon, FALSE);
247 apply_warning_emblem (&symbolic_icon, TRUE);
248 }
249
250 DEBUG ("%s: setting icon to default", nautilus_bookmark_get_name (bookmark));
251
252 g_object_set (bookmark,
253 "icon", icon,
254 "symbolic-icon", symbolic_icon,
255 NULL);
256
257 g_object_unref (icon);
258 g_object_unref (symbolic_icon);
259 }
260
261 static void
262 nautilus_bookmark_disconnect_file (NautilusBookmark *bookmark)
263 {
264 if (bookmark->details->file != NULL) {
265 DEBUG ("%s: disconnecting file",
266 nautilus_bookmark_get_name (bookmark));
267
268 g_signal_handlers_disconnect_by_func (bookmark->details->file,
269 G_CALLBACK (bookmark_file_changed_callback),
270 bookmark);
271 g_clear_object (&bookmark->details->file);
272 }
273 }
274
275 static void
276 nautilus_bookmark_connect_file (NautilusBookmark *bookmark)
277 {
278 if (bookmark->details->file != NULL) {
279 DEBUG ("%s: file already connected, returning",
280 nautilus_bookmark_get_name (bookmark));
281 return;
282 }
283
284 if (!nautilus_bookmark_uri_known_not_to_exist (bookmark)) {
285 DEBUG ("%s: creating file", nautilus_bookmark_get_name (bookmark));
286
287 bookmark->details->file = nautilus_file_get (bookmark->details->location);
288 g_assert (!nautilus_file_is_gone (bookmark->details->file));
289
290 g_signal_connect_object (bookmark->details->file, "changed",
291 G_CALLBACK (bookmark_file_changed_callback), bookmark, 0);
292 }
293
294 if (bookmark->details->icon == NULL ||
295 bookmark->details->symbolic_icon == NULL) {
296 nautilus_bookmark_set_icon_to_default (bookmark);
297 }
298
299 if (bookmark->details->file != NULL &&
300 nautilus_file_check_if_ready (bookmark->details->file, NAUTILUS_FILE_ATTRIBUTE_INFO)) {
301 bookmark_set_name_from_ready_file (bookmark, bookmark->details->file);
302 }
303
304 if (bookmark->details->name == NULL) {
305 bookmark->details->name = nautilus_compute_title_for_location (bookmark->details->location);
306 }
307 }
308
309 /* GObject methods */
310
311 static void
312 nautilus_bookmark_set_property (GObject *object,
313 guint property_id,
314 const GValue *value,
315 GParamSpec *pspec)
316 {
317 NautilusBookmark *self = NAUTILUS_BOOKMARK (object);
318 GIcon *new_icon;
319
320 switch (property_id) {
321 case PROP_ICON:
322 new_icon = g_value_get_object (value);
323
324 if (new_icon != NULL && !g_icon_equal (self->details->icon, new_icon)) {
325 g_clear_object (&self->details->icon);
326 self->details->icon = g_object_ref (new_icon);
327 }
328
329 break;
330 case PROP_SYMBOLIC_ICON:
331 new_icon = g_value_get_object (value);
332
333 if (new_icon != NULL && !g_icon_equal (self->details->symbolic_icon, new_icon)) {
334 g_clear_object (&self->details->symbolic_icon);
335 self->details->symbolic_icon = g_object_ref (new_icon);
336 }
337
338 break;
339 case PROP_LOCATION:
340 self->details->location = g_value_dup_object (value);
341 break;
342 case PROP_CUSTOM_NAME:
343 self->details->has_custom_name = g_value_get_boolean (value);
344 break;
345 case PROP_NAME:
346 nautilus_bookmark_set_name_internal (self, g_value_get_string (value));
347 break;
348 default:
349 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
350 break;
351 }
352 }
353
354 static void
355 nautilus_bookmark_get_property (GObject *object,
356 guint property_id,
357 GValue *value,
358 GParamSpec *pspec)
359 {
360 NautilusBookmark *self = NAUTILUS_BOOKMARK (object);
361
362 switch (property_id) {
363 case PROP_NAME:
364 g_value_set_string (value, self->details->name);
365 break;
366 case PROP_ICON:
367 g_value_set_object (value, self->details->icon);
368 break;
369 case PROP_SYMBOLIC_ICON:
370 g_value_set_object (value, self->details->symbolic_icon);
371 break;
372 case PROP_LOCATION:
373 g_value_set_object (value, self->details->location);
374 break;
375 case PROP_CUSTOM_NAME:
376 g_value_set_boolean (value, self->details->has_custom_name);
377 break;
378 default:
379 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
380 break;
381 }
382 }
383
384 static void
385 nautilus_bookmark_finalize (GObject *object)
386 {
387 NautilusBookmark *bookmark;
388
389 g_assert (NAUTILUS_IS_BOOKMARK (object));
390
391 bookmark = NAUTILUS_BOOKMARK (object);
392
393 nautilus_bookmark_disconnect_file (bookmark);
394
395 g_object_unref (bookmark->details->location);
396 g_clear_object (&bookmark->details->icon);
397 g_clear_object (&bookmark->details->symbolic_icon);
398
399 g_free (bookmark->details->name);
400 g_free (bookmark->details->scroll_file);
401
402 G_OBJECT_CLASS (nautilus_bookmark_parent_class)->finalize (object);
403 }
404
405 static void
406 nautilus_bookmark_constructed (GObject *obj)
407 {
408 NautilusBookmark *self = NAUTILUS_BOOKMARK (obj);
409
410 nautilus_bookmark_connect_file (self);
411 }
412
413 static void
414 nautilus_bookmark_class_init (NautilusBookmarkClass *class)
415 {
416 GObjectClass *oclass = G_OBJECT_CLASS (class);
417
418 oclass->finalize = nautilus_bookmark_finalize;
419 oclass->get_property = nautilus_bookmark_get_property;
420 oclass->set_property = nautilus_bookmark_set_property;
421 oclass->constructed = nautilus_bookmark_constructed;
422
423 signals[CONTENTS_CHANGED] =
424 g_signal_new ("contents-changed",
425 G_TYPE_FROM_CLASS (class),
426 G_SIGNAL_RUN_LAST,
427 G_STRUCT_OFFSET (NautilusBookmarkClass, contents_changed),
428 NULL, NULL,
429 g_cclosure_marshal_VOID__VOID,
430 G_TYPE_NONE, 0);
431
432 properties[PROP_NAME] =
433 g_param_spec_string ("name",
434 "Bookmark's name",
435 "The name of this bookmark",
436 NULL,
437 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT);
438
439 properties[PROP_CUSTOM_NAME] =
440 g_param_spec_boolean ("custom-name",
441 "Whether the bookmark has a custom name",
442 "Whether the bookmark has a custom name",
443 FALSE,
444 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT);
445
446 properties[PROP_LOCATION] =
447 g_param_spec_object ("location",
448 "Bookmark's location",
449 "The location of this bookmark",
450 G_TYPE_FILE,
451 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
452
453 properties[PROP_ICON] =
454 g_param_spec_object ("icon",
455 "Bookmark's icon",
456 "The icon of this bookmark",
457 G_TYPE_ICON,
458 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
459
460 properties[PROP_SYMBOLIC_ICON] =
461 g_param_spec_object ("symbolic-icon",
462 "Bookmark's symbolic icon",
463 "The symbolic icon of this bookmark",
464 G_TYPE_ICON,
465 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
466
467 g_object_class_install_properties (oclass, NUM_PROPERTIES, properties);
468
469 g_type_class_add_private (class, sizeof (NautilusBookmarkDetails));
470 }
471
472 static void
473 nautilus_bookmark_init (NautilusBookmark *bookmark)
474 {
475 bookmark->details = G_TYPE_INSTANCE_GET_PRIVATE (bookmark, NAUTILUS_TYPE_BOOKMARK,
476 NautilusBookmarkDetails);
477 }
478
479 const gchar *
480 nautilus_bookmark_get_name (NautilusBookmark *bookmark)
481 {
482 g_return_val_if_fail (NAUTILUS_IS_BOOKMARK (bookmark), NULL);
483
484 return bookmark->details->name;
485 }
486
487 gboolean
488 nautilus_bookmark_get_has_custom_name (NautilusBookmark *bookmark)
489 {
490 g_return_val_if_fail(NAUTILUS_IS_BOOKMARK (bookmark), FALSE);
491
492 return (bookmark->details->has_custom_name);
493 }
494
495 /**
496 * nautilus_bookmark_set_custom_name:
497 *
498 * Change the user-displayed name of a bookmark.
499 * @new_name: The new user-displayed name for this bookmark, mustn't be NULL.
500 *
501 **/
502 void
503 nautilus_bookmark_set_custom_name (NautilusBookmark *bookmark,
504 const char *new_name)
505 {
506 g_return_if_fail (new_name != NULL);
507 g_return_if_fail (NAUTILUS_IS_BOOKMARK (bookmark));
508
509 g_object_set (bookmark,
510 "custom-name", TRUE,
511 "name", new_name,
512 NULL);
513
514 g_signal_emit (bookmark, signals[CONTENTS_CHANGED], 0);
515 }
516
517 /**
518 * nautilus_bookmark_compare_with:
519 *
520 * Check whether two bookmarks are considered identical.
521 * @a: first NautilusBookmark*.
522 * @b: second NautilusBookmark*.
523 *
524 * Return value: 0 if @a and @b have same name and uri, 1 otherwise
525 * (GCompareFunc style)
526 **/
527 int
528 nautilus_bookmark_compare_with (gconstpointer a, gconstpointer b)
529 {
530 NautilusBookmark *bookmark_a;
531 NautilusBookmark *bookmark_b;
532
533 g_return_val_if_fail (NAUTILUS_IS_BOOKMARK (a), 1);
534 g_return_val_if_fail (NAUTILUS_IS_BOOKMARK (b), 1);
535
536 bookmark_a = NAUTILUS_BOOKMARK (a);
537 bookmark_b = NAUTILUS_BOOKMARK (b);
538
539 if (!g_file_equal (bookmark_a->details->location,
540 bookmark_b->details->location)) {
541 return 1;
542 }
543
544 if (g_strcmp0 (bookmark_a->details->name,
545 bookmark_b->details->name) != 0) {
546 return 1;
547 }
548
549 return 0;
550 }
551
552 /**
553 * nautilus_bookmark_compare_uris:
554 *
555 * Check whether the uris of two bookmarks are for the same location.
556 * @a: first NautilusBookmark*.
557 * @b: second NautilusBookmark*.
558 *
559 * Return value: 0 if @a and @b have matching uri, 1 otherwise
560 * (GCompareFunc style)
561 **/
562 int
563 nautilus_bookmark_compare_uris (gconstpointer a, gconstpointer b)
564 {
565 NautilusBookmark *bookmark_a;
566 NautilusBookmark *bookmark_b;
567
568 g_return_val_if_fail (NAUTILUS_IS_BOOKMARK (a), 1);
569 g_return_val_if_fail (NAUTILUS_IS_BOOKMARK (b), 1);
570
571 bookmark_a = NAUTILUS_BOOKMARK (a);
572 bookmark_b = NAUTILUS_BOOKMARK (b);
573
574 return !g_file_equal (bookmark_a->details->location,
575 bookmark_b->details->location);
576 }
577
578 NautilusBookmark *
579 nautilus_bookmark_copy (NautilusBookmark *bookmark)
580 {
581 NautilusBookmark *retval;
582
583 g_return_val_if_fail (NAUTILUS_IS_BOOKMARK (bookmark), NULL);
584
585 retval = nautilus_bookmark_new (bookmark->details->location,
586 bookmark->details->has_custom_name ?
587 bookmark->details->name : NULL);
588 if (bookmark->details->icon) {
589 g_object_set (retval, "icon", bookmark->details->icon, NULL);
590 }
591 if (bookmark->details->symbolic_icon) {
592 g_object_set (retval, "symbolic-icon", bookmark->details->symbolic_icon, NULL);
593 }
594
595 return retval;
596 }
597
598 GIcon *
599 nautilus_bookmark_get_symbolic_icon (NautilusBookmark *bookmark)
600 {
601 g_return_val_if_fail (NAUTILUS_IS_BOOKMARK (bookmark), NULL);
602
603 /* Try to connect a file in case file exists now but didn't earlier. */
604 nautilus_bookmark_connect_file (bookmark);
605
606 if (bookmark->details->symbolic_icon) {
607 return g_object_ref (bookmark->details->symbolic_icon);
608 }
609 return NULL;
610 }
611
612 GIcon *
613 nautilus_bookmark_get_icon (NautilusBookmark *bookmark)
614 {
615 g_return_val_if_fail (NAUTILUS_IS_BOOKMARK (bookmark), NULL);
616
617 /* Try to connect a file in case file exists now but didn't earlier. */
618 nautilus_bookmark_connect_file (bookmark);
619
620 if (bookmark->details->icon) {
621 return g_object_ref (bookmark->details->icon);
622 }
623 return NULL;
624 }
625
626 GFile *
627 nautilus_bookmark_get_location (NautilusBookmark *bookmark)
628 {
629 g_return_val_if_fail(NAUTILUS_IS_BOOKMARK (bookmark), NULL);
630
631 /* Try to connect a file in case file exists now but didn't earlier.
632 * This allows a bookmark to update its image properly in the case
633 * where a new file appears with the same URI as a previously-deleted
634 * file. Calling connect_file here means that attempts to activate the
635 * bookmark will update its image if possible.
636 */
637 nautilus_bookmark_connect_file (bookmark);
638
639 return g_object_ref (bookmark->details->location);
640 }
641
642 char *
643 nautilus_bookmark_get_uri (NautilusBookmark *bookmark)
644 {
645 GFile *file;
646 char *uri;
647
648 file = nautilus_bookmark_get_location (bookmark);
649 uri = g_file_get_uri (file);
650 g_object_unref (file);
651 return uri;
652 }
653
654 NautilusBookmark *
655 nautilus_bookmark_new (GFile *location,
656 const gchar *custom_name)
657 {
658 NautilusBookmark *new_bookmark;
659
660 new_bookmark = NAUTILUS_BOOKMARK (g_object_new (NAUTILUS_TYPE_BOOKMARK,
661 "location", location,
662 "name", custom_name,
663 "custom-name", custom_name != NULL,
664 NULL));
665
666 return new_bookmark;
667 }
668
669 static GtkWidget *
670 create_image_widget_for_bookmark (NautilusBookmark *bookmark)
671 {
672 GIcon *icon;
673 GtkWidget *widget;
674
675 icon = nautilus_bookmark_get_symbolic_icon (bookmark);
676 widget = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_MENU);
677 g_object_unref (icon);
678
679 return widget;
680 }
681
682 /**
683 * nautilus_bookmark_menu_item_new:
684 *
685 * Return a menu item representing a bookmark.
686 * @bookmark: The bookmark the menu item represents.
687 * Return value: A newly-created bookmark, not yet shown.
688 **/
689 GtkWidget *
690 nautilus_bookmark_menu_item_new (NautilusBookmark *bookmark)
691 {
692 GtkWidget *menu_item;
693 GtkWidget *image_widget;
694 GtkLabel *label;
695 const char *name;
696
697 name = nautilus_bookmark_get_name (bookmark);
698 menu_item = gtk_image_menu_item_new_with_label (name);
699 label = GTK_LABEL (gtk_bin_get_child (GTK_BIN (menu_item)));
700 gtk_label_set_use_underline (label, FALSE);
701 gtk_label_set_ellipsize (label, PANGO_ELLIPSIZE_END);
702 gtk_label_set_max_width_chars (label, ELLIPSISED_MENU_ITEM_MIN_CHARS);
703
704 image_widget = create_image_widget_for_bookmark (bookmark);
705 if (image_widget != NULL) {
706 gtk_widget_show (image_widget);
707 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item),
708 image_widget);
709 }
710
711 return menu_item;
712 }
713
714 gboolean
715 nautilus_bookmark_uri_known_not_to_exist (NautilusBookmark *bookmark)
716 {
717 char *path_name;
718 gboolean exists;
719
720 if (bookmark->details->location_gone) {
721 return TRUE;
722 }
723
724 /* Convert to a path, returning FALSE if not local. */
725 if (!g_file_is_native (bookmark->details->location)) {
726 return FALSE;
727 }
728 path_name = g_file_get_path (bookmark->details->location);
729
730 /* Now check if the file exists (sync. call OK because it is local). */
731 exists = g_file_test (path_name, G_FILE_TEST_EXISTS);
732 g_free (path_name);
733
734 return !exists;
735 }
736
737 void
738 nautilus_bookmark_set_scroll_pos (NautilusBookmark *bookmark,
739 const char *uri)
740 {
741 g_free (bookmark->details->scroll_file);
742 bookmark->details->scroll_file = g_strdup (uri);
743 }
744
745 char *
746 nautilus_bookmark_get_scroll_pos (NautilusBookmark *bookmark)
747 {
748 return g_strdup (bookmark->details->scroll_file);
749 }