eric7/WebBrowser/Bookmarks/BookmarksManager.py

branch
eric7
changeset 9153
506e35e424d5
parent 8881
54e42bc2437a
equal deleted inserted replaced
9152:8a68afaf1ba2 9153:506e35e424d5
7 Module implementing the bookmarks manager. 7 Module implementing the bookmarks manager.
8 """ 8 """
9 9
10 import os 10 import os
11 import contextlib 11 import contextlib
12 import pathlib
12 13
13 from PyQt6.QtCore import ( 14 from PyQt6.QtCore import (
14 pyqtSignal, QT_TRANSLATE_NOOP, QObject, QFile, QIODevice, QXmlStreamReader, 15 pyqtSignal, QT_TRANSLATE_NOOP, QObject, QFile, QIODevice, QXmlStreamReader,
15 QDateTime, QFileInfo, QUrl, QCoreApplication 16 QDateTime, QUrl, QCoreApplication
16 ) 17 )
17 from PyQt6.QtGui import QUndoStack, QUndoCommand 18 from PyQt6.QtGui import QUndoStack, QUndoCommand
18 from PyQt6.QtWidgets import QDialog 19 from PyQt6.QtWidgets import QDialog
19 20
20 from EricWidgets import EricMessageBox, EricFileDialog 21 from EricWidgets import EricMessageBox, EricFileDialog
396 "XBEL bookmarks (*.xml);;" 397 "XBEL bookmarks (*.xml);;"
397 "HTML Bookmarks (*.html)")) 398 "HTML Bookmarks (*.html)"))
398 if not fileName: 399 if not fileName:
399 return 400 return
400 401
401 ext = QFileInfo(fileName).suffix() 402 fpath = pathlib.Path(fileName)
402 if not ext: 403 if not fpath.suffix:
403 ex = selectedFilter.split("(*")[1].split(")")[0] 404 ex = selectedFilter.split("(*")[1].split(")")[0]
404 if ex: 405 if ex:
405 fileName += ex 406 fpath = fpath.with_suffix(ex)
406 407
407 ext = QFileInfo(fileName).suffix() 408 if fpath.suffix == ".html":
408 if ext == "html":
409 from .NsHtmlWriter import NsHtmlWriter 409 from .NsHtmlWriter import NsHtmlWriter
410 writer = NsHtmlWriter() 410 writer = NsHtmlWriter()
411 else: 411 else:
412 from .XbelWriter import XbelWriter 412 from .XbelWriter import XbelWriter
413 writer = XbelWriter() 413 writer = XbelWriter()
414 if not writer.write(fileName, self.__bookmarkRootNode): 414 if not writer.write(str(fpath), self.__bookmarkRootNode):
415 EricMessageBox.critical( 415 EricMessageBox.critical(
416 None, 416 None,
417 self.tr("Exporting Bookmarks"), 417 self.tr("Exporting Bookmarks"),
418 self.tr("""Error exporting bookmarks to <b>{0}</b>.""") 418 self.tr("""Error exporting bookmarks to <b>{0}</b>.""")
419 .format(fileName)) 419 .format(fpath))
420 420
421 def faviconChanged(self, url): 421 def faviconChanged(self, url):
422 """ 422 """
423 Public slot to update the icon image for an URL. 423 Public slot to update the icon image for an URL.
424 424

eric ide

mercurial