summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCosimo Cecchi <cosimoc@gnome.org>2012-10-22 16:05:01 -0400
committerCosimo Cecchi <cosimoc@gnome.org>2012-10-22 16:39:26 -0400
commit1dcd2d816a1278f7eec1d074ec5d9134af34a803 (patch)
tree314d6ad6a4d2f7e7628e05f6d4092f7b6a0f9094
parent33cbf4666160a3ba126691a51e0fc5d022190bda (diff)
downloadnautilus-1dcd2d816a1278f7eec1d074ec5d9134af34a803.tar.gz
bookmark: add nautilus_bookmark_get_xdg_type()
Returns whether a bookmark is for a specific XDG directory.
-rw-r--r--libnautilus-private/nautilus-bookmark.c47
-rw-r--r--libnautilus-private/nautilus-bookmark.h2
-rw-r--r--src/nautilus-places-sidebar.c57
3 files changed, 61 insertions, 45 deletions
diff --git a/libnautilus-private/nautilus-bookmark.c b/libnautilus-private/nautilus-bookmark.c
index 2d0586db7..2cb8e9fee 100644
--- a/libnautilus-private/nautilus-bookmark.c
+++ b/libnautilus-private/nautilus-bookmark.c
@@ -183,28 +183,59 @@ apply_warning_emblem (GIcon **base,
*base = emblemed_icon;
}
+gboolean
+nautilus_bookmark_get_xdg_type (NautilusBookmark *bookmark,
+ GUserDirectory *directory)
+{
+ gboolean match;
+ GFile *location;
+ const gchar *path;
+ GUserDirectory dir;
+
+ match = FALSE;
+
+ for (dir = 0; dir < G_USER_N_DIRECTORIES; dir++) {
+ path = g_get_user_special_dir (dir);
+ if (!path) {
+ continue;
+ }
+
+ location = g_file_new_for_path (path);
+ match = g_file_equal (location, bookmark->details->location);
+ g_object_unref (location);
+
+ if (match) {
+ break;
+ }
+ }
+
+ if (match && directory != NULL) {
+ *directory = dir;
+ }
+
+ return match;
+}
+
static GIcon *
get_native_icon (NautilusBookmark *bookmark,
gboolean symbolic)
{
- gint idx;
+ GUserDirectory xdg_type;
GIcon *icon = NULL;
if (bookmark->details->file == NULL) {
goto out;
}
- for (idx = 0; idx < G_USER_N_DIRECTORIES; idx++) {
- if (nautilus_file_is_user_special_directory (bookmark->details->file, idx)) {
- break;
- }
+ if (!nautilus_bookmark_get_xdg_type (bookmark, &xdg_type)) {
+ goto out;
}
- if (idx < G_USER_N_DIRECTORIES) {
+ if (xdg_type < G_USER_N_DIRECTORIES) {
if (symbolic) {
- icon = nautilus_special_directory_get_symbolic_icon (idx);
+ icon = nautilus_special_directory_get_symbolic_icon (xdg_type);
} else {
- icon = nautilus_special_directory_get_icon (idx);
+ icon = nautilus_special_directory_get_icon (xdg_type);
}
}
diff --git a/libnautilus-private/nautilus-bookmark.h b/libnautilus-private/nautilus-bookmark.h
index 4284fefc7..aa62e35d9 100644
--- a/libnautilus-private/nautilus-bookmark.h
+++ b/libnautilus-private/nautilus-bookmark.h
@@ -72,6 +72,8 @@ char * nautilus_bookmark_get_uri (NautilusBookmark
GIcon * nautilus_bookmark_get_icon (NautilusBookmark *bookmark);
GIcon * nautilus_bookmark_get_symbolic_icon (NautilusBookmark *bookmark);
gboolean nautilus_bookmark_get_exists (NautilusBookmark *bookmark);
+gboolean nautilus_bookmark_get_xdg_type (NautilusBookmark *bookmark,
+ GUserDirectory *directory);
gboolean nautilus_bookmark_get_has_custom_name (NautilusBookmark *bookmark);
void nautilus_bookmark_set_custom_name (NautilusBookmark *bookmark,
const char *new_name);
diff --git a/src/nautilus-places-sidebar.c b/src/nautilus-places-sidebar.c
index a4cdebc4f..c3ac90919 100644
--- a/src/nautilus-places-sidebar.c
+++ b/src/nautilus-places-sidebar.c
@@ -204,37 +204,6 @@ static GtkListStore *nautilus_shortcuts_model_new (NautilusPlacesSidebar *sideba
G_DEFINE_TYPE (NautilusPlacesSidebar, nautilus_places_sidebar, GTK_TYPE_SCROLLED_WINDOW);
-static gboolean
-is_built_in_bookmark (NautilusFile *file)
-{
- gboolean built_in;
- gint idx;
-
- if (nautilus_file_is_home (file)) {
- return TRUE;
- }
-
- if (nautilus_file_is_desktop_directory (file) &&
- !g_settings_get_boolean (gnome_background_preferences, NAUTILUS_PREFERENCES_SHOW_DESKTOP)) {
- return FALSE;
- }
-
- built_in = FALSE;
-
- for (idx = 0; idx < G_USER_N_DIRECTORIES; idx++) {
- /* PUBLIC_SHARE and TEMPLATES are not in our built-in list */
- if (nautilus_file_is_user_special_directory (file, idx)) {
- if (idx != G_USER_DIRECTORY_PUBLIC_SHARE && idx != G_USER_DIRECTORY_TEMPLATES) {
- built_in = TRUE;
- }
-
- break;
- }
- }
-
- return built_in;
-}
-
static GtkTreeIter
add_heading (NautilusPlacesSidebar *sidebar,
SectionType section_type,
@@ -473,6 +442,25 @@ add_special_dirs (NautilusPlacesSidebar *sidebar)
g_list_free (dirs);
}
+static gboolean
+should_display_bookmark (NautilusBookmark *bookmark)
+{
+ GUserDirectory xdg_type;
+
+ /* if this is not an XDG dir, always display */
+ if (!nautilus_bookmark_get_xdg_type (bookmark, &xdg_type)) {
+ return TRUE;
+ }
+
+ /* show XDG locations which are not in our builtin list */
+ if (xdg_type == G_USER_DIRECTORY_DESKTOP &&
+ !g_settings_get_boolean (gnome_background_preferences, NAUTILUS_PREFERENCES_SHOW_DESKTOP)) {
+ return TRUE;
+ }
+
+ return (xdg_type == G_USER_DIRECTORY_TEMPLATES) || (xdg_type == G_USER_DIRECTORY_PUBLIC_SHARE);
+}
+
static void
update_places (NautilusPlacesSidebar *sidebar)
{
@@ -495,7 +483,6 @@ update_places (NautilusPlacesSidebar *sidebar)
NautilusWindowSlot *slot;
char *tooltip;
GList *network_mounts, *network_volumes;
- NautilusFile *file;
DEBUG ("Updating places sidebar");
@@ -775,14 +762,10 @@ update_places (NautilusPlacesSidebar *sidebar)
continue;
}
- file = nautilus_file_get (root);
-
- if (is_built_in_bookmark (file)) {
+ if (!should_display_bookmark (bookmark)) {
g_object_unref (root);
- nautilus_file_unref (file);
continue;
}
- nautilus_file_unref (file);
bookmark_name = nautilus_bookmark_get_name (bookmark);
icon = nautilus_bookmark_get_symbolic_icon (bookmark);