Read dictionaries from /usr/share/qt on Qt >= 5.10
Fixes #3759 Supersedes #3762 See #2939, #4003
This commit is contained in:
parent
7b7e0c93f5
commit
663d1a4d2f
@ -87,6 +87,9 @@ Changed
|
|||||||
browsing.
|
browsing.
|
||||||
- When a prompt is opened in insert/passthrough mode, the mode is restored
|
- When a prompt is opened in insert/passthrough mode, the mode is restored
|
||||||
after closing the prompt.
|
after closing the prompt.
|
||||||
|
- On Qt 5.10 or newer, dictionaries are now read from the qutebrowser data
|
||||||
|
directory (e.g. `~/.local/share/qutebrowser`) instead of `/usr/share/qt`.
|
||||||
|
Existing dictionaries are copied over.
|
||||||
|
|
||||||
Fixed
|
Fixed
|
||||||
~~~~~
|
~~~~~
|
||||||
|
@ -22,9 +22,11 @@
|
|||||||
import glob
|
import glob
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import os.path
|
||||||
|
import shutil
|
||||||
|
|
||||||
from PyQt5.QtCore import QLibraryInfo
|
from PyQt5.QtCore import QLibraryInfo
|
||||||
from qutebrowser.utils import log, message
|
from qutebrowser.utils import log, message, standarddir, qtutils
|
||||||
|
|
||||||
dict_version_re = re.compile(r".+-(?P<version>[0-9]+-[0-9]+?)\.bdic")
|
dict_version_re = re.compile(r".+-(?P<version>[0-9]+-[0-9]+?)\.bdic")
|
||||||
|
|
||||||
@ -39,9 +41,12 @@ def version(filename):
|
|||||||
return tuple(int(n) for n in match.group('version').split('-'))
|
return tuple(int(n) for n in match.group('version').split('-'))
|
||||||
|
|
||||||
|
|
||||||
def dictionary_dir():
|
def dictionary_dir(old=False):
|
||||||
"""Return the path (str) to the QtWebEngine's dictionaries directory."""
|
"""Return the path (str) to the QtWebEngine's dictionaries directory."""
|
||||||
datapath = QLibraryInfo.location(QLibraryInfo.DataPath)
|
if qtutils.version_check('5.10', compiled=False) and not old:
|
||||||
|
datapath = standarddir.data()
|
||||||
|
else:
|
||||||
|
datapath = QLibraryInfo.location(QLibraryInfo.DataPath)
|
||||||
return os.path.join(datapath, 'qtwebengine_dictionaries')
|
return os.path.join(datapath, 'qtwebengine_dictionaries')
|
||||||
|
|
||||||
|
|
||||||
@ -73,3 +78,15 @@ def local_filename(code):
|
|||||||
"""
|
"""
|
||||||
all_installed = local_files(code)
|
all_installed = local_files(code)
|
||||||
return os.path.splitext(all_installed[0])[0] if all_installed else None
|
return os.path.splitext(all_installed[0])[0] if all_installed else None
|
||||||
|
|
||||||
|
|
||||||
|
def init():
|
||||||
|
if qtutils.version_check('5.10', compiled=False):
|
||||||
|
new_dir = dictionary_dir()
|
||||||
|
old_dir = dictionary_dir(old=True)
|
||||||
|
os.environ['QTWEBENGINE_DICTIONARIES_PATH'] = new_dir
|
||||||
|
try:
|
||||||
|
if os.path.exists(old_dir) and not os.path.exists(new_dir):
|
||||||
|
shutil.copytree(old_dir, new_dir)
|
||||||
|
except OSError:
|
||||||
|
log.misc.exception("Failed to copy old dictionaries")
|
||||||
|
@ -298,6 +298,8 @@ def init(args):
|
|||||||
not hasattr(QWebEnginePage, 'setInspectedPage')): # only Qt < 5.11
|
not hasattr(QWebEnginePage, 'setInspectedPage')): # only Qt < 5.11
|
||||||
os.environ['QTWEBENGINE_REMOTE_DEBUGGING'] = str(utils.random_port())
|
os.environ['QTWEBENGINE_REMOTE_DEBUGGING'] = str(utils.random_port())
|
||||||
|
|
||||||
|
spell.init()
|
||||||
|
|
||||||
_init_profiles()
|
_init_profiles()
|
||||||
config.instance.changed.connect(_update_settings)
|
config.instance.changed.connect(_update_settings)
|
||||||
|
|
||||||
|
@ -36,6 +36,7 @@ import attr
|
|||||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir))
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir))
|
||||||
from qutebrowser.browser.webengine import spell
|
from qutebrowser.browser.webengine import spell
|
||||||
from qutebrowser.config import configdata
|
from qutebrowser.config import configdata
|
||||||
|
from qutebrowser.utils import standarddir
|
||||||
|
|
||||||
|
|
||||||
API_URL = 'https://chromium.googlesource.com/chromium/deps/hunspell_dictionaries.git/+/master/'
|
API_URL = 'https://chromium.googlesource.com/chromium/deps/hunspell_dictionaries.git/+/master/'
|
||||||
@ -257,6 +258,8 @@ def remove_old(languages):
|
|||||||
def main():
|
def main():
|
||||||
if configdata.DATA is None:
|
if configdata.DATA is None:
|
||||||
configdata.init()
|
configdata.init()
|
||||||
|
standarddir.init(None)
|
||||||
|
|
||||||
parser = get_argparser()
|
parser = get_argparser()
|
||||||
argv = sys.argv[1:]
|
argv = sys.argv[1:]
|
||||||
args = parser.parse_args(argv)
|
args = parser.parse_args(argv)
|
||||||
|
Loading…
Reference in New Issue
Block a user