eric7/Network/IRC/IrcNetworkWidget.py

branch
eric7
changeset 9152
8a68afaf1ba2
parent 8881
54e42bc2437a
child 9153
506e35e424d5
--- a/eric7/Network/IRC/IrcNetworkWidget.py	Wed Jun 15 09:44:07 2022 +0200
+++ b/eric7/Network/IRC/IrcNetworkWidget.py	Thu Jun 16 18:28:59 2022 +0200
@@ -7,7 +7,9 @@
 Module implementing the network part of the IRC widget.
 """
 
-from PyQt6.QtCore import pyqtSlot, pyqtSignal, QPoint, QFileInfo, QUrl, QThread
+import pathlib
+
+from PyQt6.QtCore import pyqtSlot, pyqtSignal, QPoint, QUrl, QThread
 from PyQt6.QtGui import QDesktopServices
 from PyQt6.QtWidgets import QWidget, QApplication, QMenu
 
@@ -432,30 +434,28 @@
                 None,
                 EricFileDialog.DontConfirmOverwrite)
             if fname:
-                ext = QFileInfo(fname).suffix()
-                if not ext:
+                fpath = pathlib.Path(fname)
+                if not fpath.suffix:
                     ex = selectedFilter.split("(*")[1].split(")")[0]
                     if ex:
-                        fname += ex
-                    ext = QFileInfo(fname).suffix()
-                if QFileInfo(fname).exists():
+                        fpath = fpath.with_suffix(ex)
+                if fpath.exists():
                     res = EricMessageBox.yesNo(
                         self,
                         self.tr("Save Messages"),
                         self.tr("<p>The file <b>{0}</b> already exists."
-                                " Overwrite it?</p>").format(fname),
+                                " Overwrite it?</p>").format(str(fpath)),
                         icon=EricMessageBox.Warning)
                     if not res:
                         return
-                    fname = Utilities.toNativeSeparators(fname)
                 
                 try:
                     txt = (
                         self.messages.toHtml()
-                        if ext.lower() in ["htm", "html"] else
+                        if fpath.suffix.lower() in [".htm", ".html"] else
                         self.messages.toPlainText()
                     )
-                    with open(fname, "w", encoding="utf-8") as f:
+                    with fpath.open("w", encoding="utf-8") as f:
                         f.write(txt)
                 except OSError as err:
                     EricMessageBox.critical(
@@ -464,7 +464,7 @@
                         self.tr(
                             """<p>The messages contents could not be written"""
                             """ to <b>{0}</b></p><p>Reason: {1}</p>""")
-                        .format(fname, str(err)))
+                        .format(str(fpath), str(err)))
     
     def __initMessagesMenu(self):
         """

eric ide

mercurial