1
0
mirror of https://gitlab.gnome.org/GNOME/nautilus synced 2024-06-30 23:46:35 +00:00

bookmark: add nautilus_bookmark_get_xdg_type()

Returns whether a bookmark is for a specific XDG directory.
This commit is contained in:
Cosimo Cecchi 2012-10-22 16:05:01 -04:00
parent 33cbf46661
commit 1dcd2d816a
3 changed files with 61 additions and 45 deletions

View File

@ -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);
}
}

View File

@ -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);

View File

@ -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);