From 626a96580ad28cc94dae9407cccf366098d7dd92 Mon Sep 17 00:00:00 2001 From: Nick Hall Date: Sat, 29 Jul 2023 21:12:20 +0100 Subject: [PATCH] Use XDG pictures directory as the default media path If the "Base path for relative media paths" is left empty then use the XDG pictures directory as the default rather than the home directory. This is a better default for our Flatpak distribution. Fixes #12217. --- gramps/gen/const.py | 4 ++++ gramps/gen/utils/file.py | 6 +++--- gramps/gen/utils/test/file_test.py | 4 ++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/gramps/gen/const.py b/gramps/gen/const.py index 651d0eb5847..51649ddb19b 100644 --- a/gramps/gen/const.py +++ b/gramps/gen/const.py @@ -125,6 +125,10 @@ USER_CONFIG = os.path.join(GLib.get_user_config_dir(), 'gramps') USER_CACHE = os.path.join(GLib.get_user_cache_dir(), 'gramps') +USER_PICTURES = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_PICTURES) +if not USER_PICTURES: + USER_PICTURES = HOME_DIR + VERSION_DIR_NAME = "gramps%s%s" % (VERSION_TUPLE[0], VERSION_TUPLE[1]) VERSION_DIR = os.path.join(USER_CONFIG, VERSION_DIR_NAME) USER_DATA_VERSION = os.path.join(USER_DATA, VERSION_DIR_NAME) diff --git a/gramps/gen/utils/file.py b/gramps/gen/utils/file.py index 52bcecf3268..91fc7a351e0 100644 --- a/gramps/gen/utils/file.py +++ b/gramps/gen/utils/file.py @@ -43,7 +43,7 @@ # #------------------------------------------------------------------------- from ..constfunc import win, mac, get_env_var -from ..const import USER_HOME, ENV, GRAMPS_LOCALE as glocale +from ..const import USER_HOME, USER_PICTURES, ENV, GRAMPS_LOCALE as glocale #------------------------------------------------------------------------- # @@ -182,9 +182,9 @@ def expand_media_path(mpath, db): - Convert to absolute path - Convert slashes and case (on Windows) """ - # Use home dir if no media_path specified + # Use XDG pictures diectory if no media_path specified if mpath is None: - mpath = os.path.abspath(USER_HOME) + mpath = os.path.abspath(USER_PICTURES) # Expand environment variables mpath = expand_path(mpath, False) # Relative mediapath are considered as relative to the database diff --git a/gramps/gen/utils/test/file_test.py b/gramps/gen/utils/test/file_test.py index c54992eeb74..c5a1a9e6bf4 100644 --- a/gramps/gen/utils/test/file_test.py +++ b/gramps/gen/utils/test/file_test.py @@ -39,7 +39,7 @@ # Gramps modules # #------------------------------------------------------------------------- -from ...const import USER_HOME, USER_PLUGINS, VERSION +from ...const import USER_HOME, USER_PICTURES, USER_PLUGINS, VERSION from ...utils.file import media_path from ...db.utils import make_database @@ -66,7 +66,7 @@ def test_mediapath(self): # Test without db.mediapath set self.assertEqual(media_path(db), os.path.normcase(os.path.normpath( - os.path.abspath(USER_HOME)))) + os.path.abspath(USER_PICTURES)))) self.assertTrue(os.path.exists(media_path(db))) # Test with absolute db.mediapath