Remember the last used download directory.
Thanks to @Carpetsmoker for the original PR. Closes #745. Closes #37.
This commit is contained in:
parent
68512ce2cd
commit
d6585202fd
@ -123,6 +123,7 @@
|
|||||||
|==============
|
|==============
|
||||||
|Setting|Description
|
|Setting|Description
|
||||||
|<<storage-download-directory,download-directory>>|The directory to save downloads to. An empty value selects a sensible os-specific default. Will expand environment variables.
|
|<<storage-download-directory,download-directory>>|The directory to save downloads to. An empty value selects a sensible os-specific default. Will expand environment variables.
|
||||||
|
|<<storage-remember-download-directory,remember-download-directory>>|Whether to remember the last used download directory.
|
||||||
|<<storage-maximum-pages-in-cache,maximum-pages-in-cache>>|The maximum number of pages to hold in the global memory page cache.
|
|<<storage-maximum-pages-in-cache,maximum-pages-in-cache>>|The maximum number of pages to hold in the global memory page cache.
|
||||||
|<<storage-object-cache-capacities,object-cache-capacities>>|The capacities for the global memory cache for dead objects such as stylesheets or scripts. Syntax: cacheMinDeadCapacity, cacheMaxDead, totalCapacity.
|
|<<storage-object-cache-capacities,object-cache-capacities>>|The capacities for the global memory cache for dead objects such as stylesheets or scripts. Syntax: cacheMinDeadCapacity, cacheMaxDead, totalCapacity.
|
||||||
|<<storage-offline-storage-default-quota,offline-storage-default-quota>>|Default quota for new offline storage databases.
|
|<<storage-offline-storage-default-quota,offline-storage-default-quota>>|Default quota for new offline storage databases.
|
||||||
@ -1108,6 +1109,17 @@ The directory to save downloads to. An empty value selects a sensible os-specifi
|
|||||||
|
|
||||||
Default: empty
|
Default: empty
|
||||||
|
|
||||||
|
[[storage-remember-download-directory]]
|
||||||
|
=== remember-download-directory
|
||||||
|
Whether to remember the last used download directory.
|
||||||
|
|
||||||
|
Valid values:
|
||||||
|
|
||||||
|
* +true+
|
||||||
|
* +false+
|
||||||
|
|
||||||
|
Default: +pass:[true]+
|
||||||
|
|
||||||
[[storage-maximum-pages-in-cache]]
|
[[storage-maximum-pages-in-cache]]
|
||||||
=== maximum-pages-in-cache
|
=== maximum-pages-in-cache
|
||||||
The maximum number of pages to hold in the global memory page cache.
|
The maximum number of pages to hold in the global memory page cache.
|
||||||
|
@ -48,12 +48,20 @@ ModelRole = usertypes.enum('ModelRole', ['item'], start=Qt.UserRole,
|
|||||||
|
|
||||||
RetryInfo = collections.namedtuple('RetryInfo', ['request', 'manager'])
|
RetryInfo = collections.namedtuple('RetryInfo', ['request', 'manager'])
|
||||||
|
|
||||||
|
# Remember the last used directory
|
||||||
|
_last_used_directory = None
|
||||||
|
|
||||||
|
|
||||||
def _download_dir():
|
def _download_dir():
|
||||||
"""Get the download directory to use."""
|
"""Get the download directory to use."""
|
||||||
directory = config.get('storage', 'download-directory')
|
directory = config.get('storage', 'download-directory')
|
||||||
if directory is None:
|
remember_dir = config.get('storage', 'remember-download-directory')
|
||||||
directory = standarddir.download()
|
|
||||||
|
if remember_dir and _last_used_directory is not None:
|
||||||
|
return _last_used_directory
|
||||||
|
elif directory is None:
|
||||||
|
return standarddir.download()
|
||||||
|
else:
|
||||||
return directory
|
return directory
|
||||||
|
|
||||||
|
|
||||||
@ -433,6 +441,7 @@ class DownloadItem(QObject):
|
|||||||
filename: The full filename to save the download to.
|
filename: The full filename to save the download to.
|
||||||
None: special value to stop the download.
|
None: special value to stop the download.
|
||||||
"""
|
"""
|
||||||
|
global _last_used_directory
|
||||||
if self.fileobj is not None:
|
if self.fileobj is not None:
|
||||||
raise ValueError("fileobj was already set! filename: {}, "
|
raise ValueError("fileobj was already set! filename: {}, "
|
||||||
"existing: {}, fileobj {}".format(
|
"existing: {}, fileobj {}".format(
|
||||||
@ -448,6 +457,8 @@ class DownloadItem(QObject):
|
|||||||
# try again.
|
# try again.
|
||||||
self._create_full_filename(os.path.join(_download_dir(), filename))
|
self._create_full_filename(os.path.join(_download_dir(), filename))
|
||||||
|
|
||||||
|
_last_used_directory = os.path.dirname(self._filename)
|
||||||
|
|
||||||
log.downloads.debug("Setting filename to {}".format(filename))
|
log.downloads.debug("Setting filename to {}".format(filename))
|
||||||
if os.path.isfile(self._filename):
|
if os.path.isfile(self._filename):
|
||||||
# The file already exists, so ask the user if it should be
|
# The file already exists, so ask the user if it should be
|
||||||
|
@ -557,6 +557,10 @@ def data(readonly=False):
|
|||||||
"sensible os-specific default. Will expand environment "
|
"sensible os-specific default. Will expand environment "
|
||||||
"variables."),
|
"variables."),
|
||||||
|
|
||||||
|
('remember-download-directory',
|
||||||
|
SettingValue(typ.Bool(), 'true'),
|
||||||
|
"Whether to remember the last used download directory."),
|
||||||
|
|
||||||
('maximum-pages-in-cache',
|
('maximum-pages-in-cache',
|
||||||
SettingValue(
|
SettingValue(
|
||||||
typ.Int(none_ok=True, minval=0, maxval=MAXVALS['int']), ''),
|
typ.Int(none_ok=True, minval=0, maxval=MAXVALS['int']), ''),
|
||||||
|
Loading…
Reference in New Issue
Block a user