Page MenuHome

UI: Linux, use localized paths for File Browser System List
Needs RevisionPublic

Authored by Alessio Monti di Sopra (a.monti) on Wed, Feb 12, 9:10 PM.

Details

Summary

This patch would be a follow-up to a622e29a2541, after @Harley Acheson (harley) friendly challenged me to look into it.

User's folder names like "Documents" or "Downloads" are usually translated into the system language and their actual path is defined in $HOME/.config/user-dirs.dirs.

The patch adds two functions to look into that file and find the folders we need; if the file doesn't exist or the specific folder isn't defined it then tries to find the default path (ex. $HOME/Downloads/).

Diff Detail

Repository
rB Blender

Event Timeline

Campbell Barton (campbellbarton) requested changes to this revision.EditedThu, Feb 13, 12:32 AM

Nice to see this worked on.

It would be better if this decoded the user-dirs.dirs once, then looked up the results afterwards.

Suggest using BLI_ghash.h, which can be used for a key-value store, see BLI_ghash_str_new, both key & value can be allocated, then freed with
BLI_ghash_free(xdg_map, MEM_freeN, MEM_freeN)

This revision now requires changes to proceed.Thu, Feb 13, 12:32 AM

Nice to see this worked on.
It would be better if this decoded the user-dirs.dirs once, then looked up the results afterwards.
Suggest using BLI_ghash.h, which can be used for a key-value store, see BLI_ghash_str_new, both key & value can be allocated, then freed with
BLI_ghash_free(xdg_map, MEM_freeN, MEM_freeN)

Thanks for the advice!

I'm trying to understand how it works but I'm not sure where I'm making a mistake..
I managed to create the GHash and to insert the values, but I'm not sure whether I'm wrong in how I insert them, or how I try to read them.

This is inside the loop that reads the file line by line:

char _line[FILE_MAXDIR];
char _line2[FILE_MAXDIR];
...
   char *l = link_node->link;

   /* Crop the file line, keep only the actual path. */
   char *tmp_path = BLI_str_quoted_substrN(l, "_DIR=");
   char *gh_path = BLI_str_replaceN(tmp_path, "$HOME", home);
    BLI_snprintf(_line, sizeof(_line), "%s/", gh_path);

   /* Truncate the file line before the path. */
   BLI_strncpy(_line2, l, sizeof(_line2));
   char *_div = strchr(_line2, '=');
   *_div = '\0';

   BLI_ghash_insert(gh, _line2, _line);
...

This is the read part, BLI_ghash_lookup() seems to return NULL:

...
BLI_snprintf(line, sizeof(line), BLI_ghash_lookup(xdg_gh, "XDG_DESKTOP_DIR"));
if (BLI_exists(line)) {
  fsmenu_insert_entry(fsmenu,
...
  • split logic in two functions.
  • one reads and stores the values from user-dirs.dirs into a GHash; the other gets for the folder from the GHash or returns a default path if it's not there

I'm wondering whether the folder names shown in the sidebar should always be the default, as it is now, or the actual folder one @Campbell Barton (campbellbarton) @Harley Acheson (harley)

@Alessio Monti di Sopra (a.monti) - I'm wondering whether the folder names shown in the sidebar should always be the default, as it is now, or the actual folder one

There are pluses and minuses for each, but I personally like the idea of using localized names, rather than folder names.

On Windows I can change the location of my "Desktop" folder to anywhere I like, but I still want that item in the list to say "Desktop" (or the equivalent in other languages), rather than just the last part of the path. Especially for things like treating my profile root as "Home", which would just show up as "Harley" otherwise.

On Mac, unlike Linux, the directory names stay the same regardless of language selected and those are only translated when shown to users in Finder. So showing only directory name could be a confusing for other languages, since we'd be showing an English-only string the user wouldn't otherwise see.

And an unrelated question...

Does your "user-dirs.dirs" contain any items that might be only marginally useful? As in you think not important enough to be on the "System" list, but still might be useful to some users at some times? The reason I am asking is because the Mac equivalent of this patch introduces the idea of having a cached list of folders that is not displayed, needed because of the way that paths are obtained from the OS.

If you have any "minor" paths that were put on such a list, this would mean that they could be shown with special icons while browsing (in thumbnail view) or would have a special icon if you bookmark that path. But not shown in "System"

Examples of similar folders on Windows might be my profile root "3D Objects" folder (introduced with Vista and would seem a bit confusing on the main System List). Or folders for OneDrive or Dropbox. If you think this type of thing might be useful for Linux, that might be a good excuse for me to break that feature out of that Mac patch and instead treat is as a common feature for all platforms. It would then also make the Mac patch simpler and easier to review.

Does your "user-dirs.dirs" contain any items that might be only marginally useful?

No, I personally only use a couple of bookmarks that are shared across file managers, they are stored in ~.config/gtk-3.0/bookmarks

You can create as many custom folder as you like in /etc/xdg/user-dirs.defaultswith the format NAME=Folder_name, these are automatically added in $HOME and an entry is added to user-dirs.dirs where you can then specify custom path as for the other ones.
But as far as I understand, there are no standard definitions apart from the default ones. So, we might as an example assume that a user who defines a custom folder for fonts will call it XDG_FONTS_DIR instead of XDG_APPLES_DIR, but still..

This is what I understood by looking around a bit, I might be missing something, since I'm not really familiar with this though.

Edit: btw the current code already stores everything in user-dirs.dirs that is not a comment, so maaaybe we could still speculate some folder definitions, like "FONTS", "BLENDER", "DROPBOX", but it would be a pure guess

Campbell Barton (campbellbarton) requested changes to this revision.Sat, Feb 22, 12:29 AM
Campbell Barton (campbellbarton) added inline comments.
source/blender/editors/space_file/fsmenu.c
112

Using _ prefix should be reserved for special cases - macros or variables which shouldn't be accessed directly.

149–183

This function can be avoided entirely, we could pass in a default value to ED_get_xdg_user_dirs

ED_get_xdg_user_dirs(xdg_gh, "XDG_VIDEOS_DIR", home, "Videos"));
152

A destination string can be passed in, avoids need for static string and caller is copying anyway.

154

This will crash if the hash lookup returns NULL.

156

Don't think it's necessary to check if the file exists, if the value is set, it should be used.

This revision now requires changes to proceed.Sat, Feb 22, 12:29 AM