files-view: Show starring only for indexed (by default) files

Currently the star menu item is shown for every file in the system,
however when a file is not indexed by tracker this operation fails.

We cannot set Tracker to index the file and wait for Tracker to index
it, since that happens in an idle and Tracker doesn't queue the
operation of starring.

There is no easy solution for this, so for now we will show the star
menu item for indexed (by default) locations, which are the XDG folders,
otherwise we will hide the item.

A better solution needs to be researched for 3.30, but this will do for
now.

Related https://gitlab.gnome.org/GNOME/nautilus/issues/243
This commit is contained in:
Carlos Soriano 2018-02-08 20:54:44 +01:00 committed by Carlos Soriano
parent 1a38f2edb6
commit c6657af342
3 changed files with 48 additions and 2 deletions

View file

@ -67,6 +67,38 @@ eel_uri_is_other_locations (const char *uri)
return g_str_has_prefix (uri, "other-locations:");
}
gboolean
eel_uri_is_in_xdg_dirs (const gchar *uri)
{
GUserDirectory dir;
g_autoptr (GFile) location = NULL;
gboolean has_prefix = FALSE;
location = g_file_new_for_uri (uri);
for (dir = 0; dir < G_USER_N_DIRECTORIES; dir++)
{
g_autoptr (GFile) xdg_dir_location = NULL;
const gchar *path;
path = g_get_user_special_dir (dir);
if (path == NULL)
{
continue;
}
xdg_dir_location = g_file_new_for_path (path);
has_prefix = g_file_has_prefix (location, xdg_dir_location) ||
g_file_equal (location, xdg_dir_location);
if (has_prefix)
{
break;
}
}
return has_prefix;
}
char *
eel_filename_get_extension_offset (const char *filename)
{

View file

@ -39,6 +39,7 @@ gboolean eel_uri_is_trash (const char *
gboolean eel_uri_is_search (const char *uri);
gboolean eel_uri_is_other_locations (const char *uri);
gboolean eel_uri_is_recent (const char *uri);
gboolean eel_uri_is_in_xdg_dirs (const char *uri);
char * eel_filename_strip_extension (const char *filename);
void eel_filename_get_rename_region (const char *filename,

View file

@ -7694,8 +7694,21 @@ real_update_actions_state (NautilusFilesView *view)
g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
!nautilus_files_view_is_empty (view));
show_star = (selection != NULL);
show_unstar = (selection != NULL);
GFile *current_location;
gboolean current_directory_in_xdg_folders = FALSE;
/* FIXME: We are assuming tracker indexes XDG folders and ignore the search
* setting. This should be fixed in a better way for Nautilus 3.30.
* See https://gitlab.gnome.org/GNOME/nautilus/issues/243
*/
current_location = nautilus_file_get_location (nautilus_files_view_get_directory_as_file (view));
current_directory_in_xdg_folders = eel_uri_is_in_xdg_dirs (g_file_get_uri (current_location));
show_star = (selection != NULL) &&
(current_directory_in_xdg_folders || selection_contains_starred);
show_unstar = (selection != NULL) &&
(current_directory_in_xdg_folders || selection_contains_starred);
for (l = selection; l != NULL; l = l->next)
{
file = NAUTILUS_FILE (l->data);