fix xdg compliant download destination

main
josch 12 years ago
parent cdc674b40f
commit 37905a0fc7

@ -126,7 +126,7 @@ Possible future work
(patches welcome) (patches welcome)
- build debian package - build debian package
- add hooks to load custom javascript/css for feeds - load javascript selectively and not for every page
- i18n - i18n
- downloading (only gui code missing) - downloading (only gui code missing)
- list of unread items - list of unread items

@ -17,7 +17,6 @@
#TODO #TODO
# gettext # gettext
# custom css/javascript
# get addressbar/title/tabtitle right # get addressbar/title/tabtitle right
# no double entries for smbc # no double entries for smbc
@ -256,7 +255,7 @@ class ContentPane (Gtk.Notebook):
if title: if title:
label.set_label(title) label.set_label(title)
#view.execute_script(open("youtube_html5_everywhere.user.js", "r").read()) #view.execute_script(open("youtube_html5_everywhere.user.js", "r").read())
for path in [".", "/usr/share/pyferea")]: for path in [".", "/usr/share/pyferea"]:
if not os.path.exists(path): if not os.path.exists(path):
continue continue
for f in [os.path.join(path, p) for p in os.listdir(path)]: for f in [os.path.join(path, p) for p in os.listdir(path)]:
@ -297,14 +296,19 @@ class ContentPane (Gtk.Notebook):
web_view.connect("mime-type-policy-decision-requested", _mime_type_policy_decision_requested_cb) web_view.connect("mime-type-policy-decision-requested", _mime_type_policy_decision_requested_cb)
def _download_requested_cb(view, download): def _download_requested_cb(view, download):
download_dir = os.path.expanduser('~/Downloads') # get download directory from $XDG_DOWNLOAD_DIR, then from user-dirs.dirs
xdg_config_home = os.environ.get('XDG_CONFIG_HOME') or os.path.join(os.path.expanduser('~'), '.config') # then fall back to ~/Downloads
user_dirs = os.path.join(xdg_config_home, "user-dirs.dirs") download_dir = os.environ.get("XDG_DOWNLOAD_DIR")
if os.path.exists(user_dirs): if not download_dir:
match = re.search('XDG_DOWNLOAD_DIR="(.*?)"', open(user_dirs).read()) xdg_config_home = os.environ.get('XDG_CONFIG_HOME') or os.path.join(os.path.expanduser('~'), '.config')
if match: user_dirs = os.path.join(xdg_config_home, "user-dirs.dirs")
# TODO: what about $HOME_FOO or ${HOME}? how to parse that correctly? if os.path.exists(user_dirs):
download_dir = os.path.expanduser(match.group(1).replace('$HOME', '~')) match = re.search('XDG_DOWNLOAD_DIR="(.*?)"', open(user_dirs).read())
if match:
# TODO: what about $HOME_FOO or ${HOME}? how to parse that correctly?
download_dir = os.path.expanduser(match.group(1).replace('$HOME', '~'))
if not download_dir:
download_dir = os.path.expanduser('~/Downloads')
if not os.path.exists(download_dir): if not os.path.exists(download_dir):
os.makedirs(download_dir) os.makedirs(download_dir)
# TODO: check if destination file exists # TODO: check if destination file exists

Loading…
Cancel
Save