Fix starting with -c '' again.

Before c5a2039da4 (standarddir refactoring), we
only checked the commandline arguments for the config file, but not when
getting the quickmarks location (as the 'args' argument was None). This means
quickmarks were saved to the default config dir even with -c ''.

With that commit, this was "fixed" accidentally, but quickmarks couldn't handle
the filename being None.
This commit is contained in:
Florian Bruhin 2015-03-27 12:29:10 +01:00
parent 1e18ce94cf
commit d062ff5138

View File

@ -41,7 +41,8 @@ class QuickmarkManager(QObject):
Attributes: Attributes:
marks: An OrderedDict of all quickmarks. marks: An OrderedDict of all quickmarks.
_lineparser: The LineParser used for the quickmarks. _lineparser: The LineParser used for the quickmarks, or None
(when qutebrowser is started with -c '').
""" """
changed = pyqtSignal() changed = pyqtSignal()
@ -52,27 +53,32 @@ class QuickmarkManager(QObject):
self.marks = collections.OrderedDict() self.marks = collections.OrderedDict()
self._lineparser = lineparser.LineParser( if standarddir.config() is None:
standarddir.config(), 'quickmarks', parent=self) self._lineparser = None
for line in self._lineparser: else:
if not line.strip(): self._lineparser = lineparser.LineParser(
# Ignore empty or whitespace-only lines. standarddir.config(), 'quickmarks', parent=self)
continue for line in self._lineparser:
try: if not line.strip():
key, url = line.rsplit(maxsplit=1) # Ignore empty or whitespace-only lines.
except ValueError: continue
message.error(0, "Invalid quickmark '{}'".format(line)) try:
else: key, url = line.rsplit(maxsplit=1)
self.marks[key] = url except ValueError:
filename = os.path.join(standarddir.config(), 'quickmarks') message.error(0, "Invalid quickmark '{}'".format(line))
objreg.get('save-manager').add_saveable('quickmark-manager', self.save, else:
self.changed, self.marks[key] = url
filename=filename) filename = os.path.join(standarddir.config(), 'quickmarks')
objreg.get('save-manager').add_saveable(
'quickmark-manager', self.save, self.changed,
filename=filename)
def save(self): def save(self):
"""Save the quickmarks to disk.""" """Save the quickmarks to disk."""
self._lineparser.data = [' '.join(tpl) for tpl in self.marks.items()] if self._lineparser is not None:
self._lineparser.save() self._lineparser.data = [' '.join(tpl)
for tpl in self.marks.items()]
self._lineparser.save()
def prompt_save(self, win_id, url): def prompt_save(self, win_id, url):
"""Prompt for a new quickmark name to be added and add it. """Prompt for a new quickmark name to be added and add it.