Try rename pdf file with web page title after download finish.

master
Andy Stewart 6 years ago
parent 688de33de8
commit ac51bbf822
  1. 11
      core/browser.py
  2. 2
      core/buffer.py

@ -459,7 +459,14 @@ class BrowserBuffer(Buffer):
def notify_print_message(self, file_path, success):
if success:
self.message_to_emacs.emit("Successfully saved current webpage as '{}'.".format(file_path))
# Try to rename pdf file with title.
# Use host name if title include invalid file char.
title_path = os.path.join(os.path.expanduser(self.emacs_var_dict["eaf-browser-download-path"]), "{}.pdf".format(self.title))
try:
os.rename(file_path, title_path)
self.message_to_emacs.emit("Successfully saved current webpage as '{}'.".format(title_path))
except Exception:
self.message_to_emacs.emit("Successfully saved current webpage as '{}'.".format(file_path))
else:
self.message_to_emacs.emit("Failed to save current webpage as '{}'.".format(file_path))
@ -621,7 +628,7 @@ class BrowserBuffer(Buffer):
parsed = urlparse(self.url)
qd = parse_qs(parsed.query, keep_blank_values=True)
pdf_path = os.path.join(os.path.expanduser(self.emacs_var_dict["eaf-browser-download-path"]), "{}.pdf".format(parsed.netloc))
self.message_to_emacs.emit("Saving to " + pdf_path + "...")
self.message_to_emacs.emit("Saving as pdf...")
self.buffer_widget.web_page.printToPdf(pdf_path)
def cancel_input_message(self, result_tag):

@ -174,6 +174,7 @@ class Buffer(QGraphicsScene):
self.background_color = background_color
self.setBackgroundBrush(QBrush(self.background_color))
self.is_dark_mode = is_dark_mode
self.title = ""
self.buffer_widget = None
@ -221,6 +222,7 @@ class Buffer(QGraphicsScene):
self.buffer_widget.deleteLater()
def change_title(self, title):
self.title = title
self.update_details.emit(self.buffer_id, title, self.url)
def request_close_buffer(self):

Loading…
Cancel
Save