From 101fda5997d904f96d8afaa9bdc3aa73b6a07027 Mon Sep 17 00:00:00 2001 From: hjk Date: Wed, 25 Aug 2021 09:19:38 +0200 Subject: [PATCH] BinEditor: Proliferate FilePath use Change-Id: I1676ab03257b5acdc1f67e25f419939939707d53 Reviewed-by: Christian Stenger --- src/plugins/bineditor/bineditorplugin.cpp | 2 +- src/plugins/bineditor/bineditorwidget.cpp | 21 +++++++++++---------- src/plugins/bineditor/bineditorwidget.h | 6 +++--- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/plugins/bineditor/bineditorplugin.cpp b/src/plugins/bineditor/bineditorplugin.cpp index 1ca61f0baee..2856f44c252 100644 --- a/src/plugins/bineditor/bineditorplugin.cpp +++ b/src/plugins/bineditor/bineditorplugin.cpp @@ -234,7 +234,7 @@ public: { QTC_ASSERT(!autoSave, return true); // bineditor does not support autosave - it would be a bit expensive const FilePath &fileNameToUse = filePath.isEmpty() ? this->filePath() : filePath; - if (m_widget->save(errorString, this->filePath().toString(), fileNameToUse.toString())) { + if (m_widget->save(errorString, this->filePath(), fileNameToUse)) { setFilePath(fileNameToUse); return true; } diff --git a/src/plugins/bineditor/bineditorwidget.cpp b/src/plugins/bineditor/bineditorwidget.cpp index 73b822c5c40..d2ea7b28c49 100644 --- a/src/plugins/bineditor/bineditorwidget.cpp +++ b/src/plugins/bineditor/bineditorwidget.cpp @@ -60,6 +60,7 @@ #include using namespace Core; +using namespace Utils; namespace BinEditor { namespace Internal { @@ -402,25 +403,25 @@ bool BinEditorWidget::isReadOnly() const return m_readOnly; } -bool BinEditorWidget::save(QString *errorString, const QString &oldFileName, const QString &newFileName) +bool BinEditorWidget::save(QString *errorString, const FilePath &oldFilePath, const FilePath &newFilePath) { - if (oldFileName != newFileName) { - QString tmpName; + if (oldFilePath != newFilePath) { + FilePath tmpName; { - QTemporaryFile tmp(newFileName + QLatin1String("_XXXXXX.new")); + QTemporaryFile tmp(newFilePath.toString() + QLatin1String("_XXXXXX.new")); if (!tmp.open()) return false; - tmpName = tmp.fileName(); + tmpName = FilePath::fromString(tmp.fileName()); } - if (!QFile::copy(oldFileName, tmpName)) + if (!oldFilePath.copyFile(tmpName)) return false; - if (QFile::exists(newFileName) && !QFile::remove(newFileName)) + if (newFilePath.exists() && !newFilePath.removeFile()) return false; - if (!QFile::rename(tmpName, newFileName)) + if (!tmpName.renameFile(newFilePath)) return false; } - Utils::FileSaver saver(Utils::FilePath::fromString(newFileName), - QIODevice::ReadWrite); // QtBug: WriteOnly truncates. + + FileSaver saver(newFilePath, QIODevice::ReadWrite); // QtBug: WriteOnly truncates. if (!saver.hasError()) { QFile *output = saver.file(); const qint64 size = output->size(); diff --git a/src/plugins/bineditor/bineditorwidget.h b/src/plugins/bineditor/bineditorwidget.h index 0bd217ff661..6a894454421 100644 --- a/src/plugins/bineditor/bineditorwidget.h +++ b/src/plugins/bineditor/bineditorwidget.h @@ -29,15 +29,15 @@ #include "markup.h" #include "bineditorservice.h" +#include #include +#include #include #include #include #include #include - -#include #include #include @@ -78,7 +78,7 @@ public: bool newWindowRequestAllowed() const { return m_canRequestNewWindow; } void updateContents(); - bool save(QString *errorString, const QString &oldFileName, const QString &newFileName); + bool save(QString *errorString, const Utils::FilePath &oldFilePath, const Utils::FilePath &newFilePath); void zoomF(float delta);