Skip to content

Commit

Permalink
Use XDG pictures directory as the default media path
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Nick-Hall committed Jul 30, 2023
1 parent 9ad4b2d commit 626a965
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions gramps/gen/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions gramps/gen/utils/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

#-------------------------------------------------------------------------
#
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions gramps/gen/utils/test/file_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down

0 comments on commit 626a965

Please sign in to comment.