forked from qt-creator/qt-creator
Utils: filepathify fileutils
Change-Id: Ic9048369f64d793f5f567cdb0c715488fb5a4ff6 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -961,7 +961,7 @@ namespace ADS
|
||||
|
||||
QDir tmp;
|
||||
tmp.mkpath(fileName.toFileInfo().path());
|
||||
Utils::FileSaver fileSaver(fileName.toString(), QIODevice::Text);
|
||||
Utils::FileSaver fileSaver(fileName, QIODevice::Text);
|
||||
if (!fileSaver.hasError())
|
||||
fileSaver.write(data);
|
||||
|
||||
|
@@ -370,7 +370,7 @@ QFuture<PluginDumper::QmlTypeDescription> PluginDumper::loadQmlTypeDescription(c
|
||||
|
||||
for (const QString &p: paths) {
|
||||
Utils::FileReader reader;
|
||||
if (!reader.fetch(p, QFile::Text)) {
|
||||
if (!reader.fetch(Utils::FilePath::fromString(p), QFile::Text)) {
|
||||
result.errors += reader.errorString();
|
||||
continue;
|
||||
}
|
||||
|
@@ -450,35 +450,41 @@ QByteArray FileUtils::fileId(const FilePath &fileName)
|
||||
|
||||
QByteArray FileReader::fetchQrc(const QString &fileName)
|
||||
{
|
||||
QTC_ASSERT(fileName.startsWith(QLatin1Char(':')), return QByteArray());
|
||||
QTC_ASSERT(fileName.startsWith(':'), return QByteArray());
|
||||
QFile file(fileName);
|
||||
bool ok = file.open(QIODevice::ReadOnly);
|
||||
QTC_ASSERT(ok, qWarning() << fileName << "not there!"; return QByteArray());
|
||||
return file.readAll();
|
||||
}
|
||||
|
||||
bool FileReader::fetch(const QString &fileName, QIODevice::OpenMode mode)
|
||||
bool FileReader::fetch(const FilePath &filePath, QIODevice::OpenMode mode)
|
||||
{
|
||||
QTC_ASSERT(!(mode & ~(QIODevice::ReadOnly | QIODevice::Text)), return false);
|
||||
|
||||
QFile file(fileName);
|
||||
if (filePath.needsDevice()) {
|
||||
// TODO: add error handling to FilePath::fileContents
|
||||
m_data = filePath.fileContents();
|
||||
return true;
|
||||
}
|
||||
|
||||
QFile file(filePath.toString());
|
||||
if (!file.open(QIODevice::ReadOnly | mode)) {
|
||||
m_errorString = tr("Cannot open %1 for reading: %2").arg(
|
||||
QDir::toNativeSeparators(fileName), file.errorString());
|
||||
filePath.toUserOutput(), file.errorString());
|
||||
return false;
|
||||
}
|
||||
m_data = file.readAll();
|
||||
if (file.error() != QFile::NoError) {
|
||||
m_errorString = tr("Cannot read %1: %2").arg(
|
||||
QDir::toNativeSeparators(fileName), file.errorString());
|
||||
filePath.toUserOutput(), file.errorString());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FileReader::fetch(const QString &fileName, QIODevice::OpenMode mode, QString *errorString)
|
||||
bool FileReader::fetch(const FilePath &filePath, QIODevice::OpenMode mode, QString *errorString)
|
||||
{
|
||||
if (fetch(fileName, mode))
|
||||
if (fetch(filePath, mode))
|
||||
return true;
|
||||
if (errorString)
|
||||
*errorString = m_errorString;
|
||||
@@ -486,9 +492,9 @@ bool FileReader::fetch(const QString &fileName, QIODevice::OpenMode mode, QStrin
|
||||
}
|
||||
|
||||
#ifdef QT_GUI_LIB
|
||||
bool FileReader::fetch(const QString &fileName, QIODevice::OpenMode mode, QWidget *parent)
|
||||
bool FileReader::fetch(const FilePath &filePath, QIODevice::OpenMode mode, QWidget *parent)
|
||||
{
|
||||
if (fetch(fileName, mode))
|
||||
if (fetch(filePath, mode))
|
||||
return true;
|
||||
if (parent)
|
||||
QMessageBox::critical(parent, tr("File Error"), m_errorString);
|
||||
@@ -545,11 +551,10 @@ bool FileSaverBase::setResult(bool ok)
|
||||
{
|
||||
if (!ok && !m_hasError) {
|
||||
if (!m_file->errorString().isEmpty()) {
|
||||
m_errorString = tr("Cannot write file %1: %2").arg(
|
||||
QDir::toNativeSeparators(m_fileName), m_file->errorString());
|
||||
m_errorString = tr("Cannot write file %1: %2")
|
||||
.arg(m_filePath.toUserOutput(), m_file->errorString());
|
||||
} else {
|
||||
m_errorString = tr("Cannot write file %1. Disk full?").arg(
|
||||
QDir::toNativeSeparators(m_fileName));
|
||||
m_errorString = tr("Cannot write file %1. Disk full?").arg(m_filePath.toUserOutput());
|
||||
}
|
||||
m_hasError = true;
|
||||
}
|
||||
@@ -573,9 +578,9 @@ bool FileSaverBase::setResult(QXmlStreamWriter *stream)
|
||||
}
|
||||
|
||||
|
||||
FileSaver::FileSaver(const QString &filename, QIODevice::OpenMode mode)
|
||||
FileSaver::FileSaver(const FilePath &filePath, QIODevice::OpenMode mode)
|
||||
{
|
||||
m_fileName = filename;
|
||||
m_filePath = filePath;
|
||||
// Workaround an assert in Qt -- and provide a useful error message, too:
|
||||
if (HostOsInfo::isWindowsHost()) {
|
||||
// Taken from: https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx
|
||||
@@ -583,24 +588,25 @@ FileSaver::FileSaver(const QString &filename, QIODevice::OpenMode mode)
|
||||
= {"CON", "PRN", "AUX", "NUL",
|
||||
"COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9",
|
||||
"LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9"};
|
||||
const QString fn = QFileInfo(filename).baseName().toUpper();
|
||||
const QString fn = filePath.toFileInfo().baseName().toUpper();
|
||||
if (reservedNames.contains(fn)) {
|
||||
m_errorString = tr("%1: Is a reserved filename on Windows. Cannot save.").arg(filename);
|
||||
m_errorString = tr("%1: Is a reserved filename on Windows. Cannot save.")
|
||||
.arg(filePath.toString());
|
||||
m_hasError = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (mode & (QIODevice::ReadOnly | QIODevice::Append)) {
|
||||
m_file.reset(new QFile{filename});
|
||||
m_file.reset(new QFile{filePath.toString()});
|
||||
m_isSafe = false;
|
||||
} else {
|
||||
m_file.reset(new SaveFile{filename});
|
||||
m_file.reset(new SaveFile{filePath.toString()});
|
||||
m_isSafe = true;
|
||||
}
|
||||
if (!m_file->open(QIODevice::WriteOnly | mode)) {
|
||||
QString err = QFile::exists(filename) ?
|
||||
QString err = filePath.exists() ?
|
||||
tr("Cannot overwrite file %1: %2") : tr("Cannot create file %1: %2");
|
||||
m_errorString = err.arg(QDir::toNativeSeparators(filename), m_file->errorString());
|
||||
m_errorString = err.arg(filePath.toUserOutput(), m_file->errorString());
|
||||
m_hasError = true;
|
||||
}
|
||||
}
|
||||
@@ -634,14 +640,14 @@ TempFileSaver::TempFileSaver(const QString &templ)
|
||||
tempFile->errorString());
|
||||
m_hasError = true;
|
||||
}
|
||||
m_fileName = tempFile->fileName();
|
||||
m_filePath = FilePath::fromString(tempFile->fileName());
|
||||
}
|
||||
|
||||
TempFileSaver::~TempFileSaver()
|
||||
{
|
||||
m_file.reset();
|
||||
if (m_autoRemove)
|
||||
QFile::remove(m_fileName);
|
||||
QFile::remove(m_filePath.toString());
|
||||
}
|
||||
|
||||
/*! \class Utils::FilePath
|
||||
|
@@ -281,14 +281,14 @@ class QTCREATOR_UTILS_EXPORT FileReader
|
||||
Q_DECLARE_TR_FUNCTIONS(Utils::FileUtils) // sic!
|
||||
public:
|
||||
static QByteArray fetchQrc(const QString &fileName); // Only for internal resources
|
||||
bool fetch(const QString &fileName, QIODevice::OpenMode mode = QIODevice::NotOpen); // QIODevice::ReadOnly is implicit
|
||||
bool fetch(const QString &fileName, QIODevice::OpenMode mode, QString *errorString);
|
||||
bool fetch(const QString &fileName, QString *errorString)
|
||||
{ return fetch(fileName, QIODevice::NotOpen, errorString); }
|
||||
bool fetch(const FilePath &filePath, QIODevice::OpenMode mode = QIODevice::NotOpen); // QIODevice::ReadOnly is implicit
|
||||
bool fetch(const FilePath &filePath, QIODevice::OpenMode mode, QString *errorString);
|
||||
bool fetch(const FilePath &filePath, QString *errorString)
|
||||
{ return fetch(filePath, QIODevice::NotOpen, errorString); }
|
||||
#ifdef QT_GUI_LIB
|
||||
bool fetch(const QString &fileName, QIODevice::OpenMode mode, QWidget *parent);
|
||||
bool fetch(const QString &fileName, QWidget *parent)
|
||||
{ return fetch(fileName, QIODevice::NotOpen, parent); }
|
||||
bool fetch(const FilePath &filePath, QIODevice::OpenMode mode, QWidget *parent);
|
||||
bool fetch(const FilePath &filePath, QWidget *parent)
|
||||
{ return fetch(filePath, QIODevice::NotOpen, parent); }
|
||||
#endif // QT_GUI_LIB
|
||||
const QByteArray &data() const { return m_data; }
|
||||
const QString &errorString() const { return m_errorString; }
|
||||
@@ -304,7 +304,7 @@ public:
|
||||
FileSaverBase();
|
||||
virtual ~FileSaverBase();
|
||||
|
||||
QString fileName() const { return m_fileName; }
|
||||
FilePath filePath() const { return m_filePath; }
|
||||
bool hasError() const { return m_hasError; }
|
||||
QString errorString() const { return m_errorString; }
|
||||
virtual bool finalize();
|
||||
@@ -324,7 +324,7 @@ public:
|
||||
|
||||
protected:
|
||||
std::unique_ptr<QFile> m_file;
|
||||
QString m_fileName;
|
||||
FilePath m_filePath;
|
||||
QString m_errorString;
|
||||
bool m_hasError = false;
|
||||
|
||||
@@ -337,7 +337,7 @@ class QTCREATOR_UTILS_EXPORT FileSaver : public FileSaverBase
|
||||
Q_DECLARE_TR_FUNCTIONS(Utils::FileUtils) // sic!
|
||||
public:
|
||||
// QIODevice::WriteOnly is implicit
|
||||
explicit FileSaver(const QString &filename, QIODevice::OpenMode mode = QIODevice::NotOpen);
|
||||
explicit FileSaver(const FilePath &filePath, QIODevice::OpenMode mode = QIODevice::NotOpen);
|
||||
|
||||
bool finalize() override;
|
||||
using FileSaverBase::finalize;
|
||||
|
@@ -734,7 +734,7 @@ JsonSchema *JsonSchemaManager::schemaByName(const QString &baseName) const
|
||||
JsonSchema *JsonSchemaManager::parseSchema(const QString &schemaFileName) const
|
||||
{
|
||||
FileReader reader;
|
||||
if (reader.fetch(schemaFileName, QIODevice::Text)) {
|
||||
if (reader.fetch(FilePath::fromString(schemaFileName), QIODevice::Text)) {
|
||||
const QString &contents = QString::fromUtf8(reader.data());
|
||||
JsonValue *json = JsonValue::create(contents, &m_pool);
|
||||
if (json && json->kind() == JsonValue::Object)
|
||||
|
@@ -465,7 +465,7 @@ bool PersistentSettingsWriter::write(const QVariantMap &data, QString *errorStri
|
||||
{
|
||||
QDir tmp;
|
||||
tmp.mkpath(m_fileName.toFileInfo().path());
|
||||
FileSaver saver(m_fileName.toString(), QIODevice::Text);
|
||||
FileSaver saver(m_fileName, QIODevice::Text);
|
||||
if (!saver.hasError()) {
|
||||
const Context ctx;
|
||||
QXmlStreamWriter w(saver.file());
|
||||
|
@@ -208,7 +208,7 @@ TextFileFormat::ReadResult readTextFile(const FilePath &filePath, const QTextCod
|
||||
QByteArray data;
|
||||
try {
|
||||
FileReader reader;
|
||||
if (!reader.fetch(filePath.toString(), errorString))
|
||||
if (!reader.fetch(filePath, errorString))
|
||||
return TextFileFormat::ReadIOError;
|
||||
data = reader.data();
|
||||
} catch (const std::bad_alloc &) {
|
||||
@@ -274,7 +274,7 @@ TextFileFormat::ReadResult TextFileFormat::readFileUTF8(const FilePath &filePath
|
||||
QByteArray data;
|
||||
try {
|
||||
FileReader reader;
|
||||
if (!reader.fetch(filePath.toString(), errorString))
|
||||
if (!reader.fetch(filePath, errorString))
|
||||
return TextFileFormat::ReadIOError;
|
||||
data = reader.data();
|
||||
} catch (const std::bad_alloc &) {
|
||||
@@ -313,7 +313,7 @@ bool TextFileFormat::writeFile(const FilePath &filePath, QString plainText, QStr
|
||||
if (lineTerminationMode == CRLFLineTerminator)
|
||||
plainText.replace(QLatin1Char('\n'), QLatin1String("\r\n"));
|
||||
|
||||
FileSaver saver(filePath.toString(), fileMode);
|
||||
FileSaver saver(filePath, fileMode);
|
||||
if (!saver.hasError()) {
|
||||
if (hasUtf8Bom && codec->name() == "UTF-8")
|
||||
saver.write("\xef\xbb\xbf", 3);
|
||||
|
@@ -856,7 +856,7 @@ QVersionNumber AndroidConfig::ndkVersion(const FilePath &ndkPath) const
|
||||
const FilePath ndkReleaseTxtPath = ndkPath.pathAppended("RELEASE.TXT");
|
||||
Utils::FileReader reader;
|
||||
QString errorString;
|
||||
if (reader.fetch(ndkReleaseTxtPath.toString(), &errorString)) {
|
||||
if (reader.fetch(ndkReleaseTxtPath, &errorString)) {
|
||||
// RELEASE.TXT contains the ndk version in either of the following formats:
|
||||
// r6a
|
||||
// r10e (64 bit)
|
||||
|
@@ -692,7 +692,7 @@ void TestResultsPane::onSaveWholeTriggered()
|
||||
if (fileName.isEmpty())
|
||||
return;
|
||||
|
||||
Utils::FileSaver saver(fileName, QIODevice::Text);
|
||||
Utils::FileSaver saver(Utils::FilePath::fromString(fileName), QIODevice::Text);
|
||||
if (!saver.write(getWholeOutput().toUtf8()) || !saver.finalize()) {
|
||||
QMessageBox::critical(ICore::dialogParent(), tr("Error"),
|
||||
tr("Failed to write \"%1\".\n\n%2").arg(fileName)
|
||||
|
@@ -654,7 +654,7 @@ void BazaarPluginPrivate::showCommitWidget(const QList<VcsBaseClient::StatusItem
|
||||
return;
|
||||
}
|
||||
|
||||
IEditor *editor = EditorManager::openEditor(saver.fileName(), COMMIT_ID);
|
||||
IEditor *editor = EditorManager::openEditor(saver.filePath().toString(), COMMIT_ID);
|
||||
if (!editor) {
|
||||
VcsOutputWindow::appendError(tr("Unable to create an editor for the commit."));
|
||||
return;
|
||||
|
@@ -246,16 +246,16 @@ void AbstractSettings::save()
|
||||
continue;
|
||||
}
|
||||
|
||||
Utils::FileSaver saver(fi.absoluteFilePath());
|
||||
Utils::FileSaver saver(Utils::FilePath::fromUserInput(fi.absoluteFilePath()));
|
||||
if (saver.hasError()) {
|
||||
BeautifierPlugin::showError(tr("Cannot open file \"%1\": %2.")
|
||||
.arg(saver.fileName())
|
||||
.arg(saver.filePath().toUserOutput())
|
||||
.arg(saver.errorString()));
|
||||
} else {
|
||||
saver.write(iStyles.value().toLocal8Bit());
|
||||
if (!saver.finalize()) {
|
||||
BeautifierPlugin::showError(tr("Cannot save file \"%1\": %2.")
|
||||
.arg(saver.fileName())
|
||||
.arg(saver.filePath().toUserOutput())
|
||||
.arg(saver.errorString()));
|
||||
}
|
||||
}
|
||||
|
@@ -419,7 +419,8 @@ bool BinEditorWidget::save(QString *errorString, const QString &oldFileName, con
|
||||
if (!QFile::rename(tmpName, newFileName))
|
||||
return false;
|
||||
}
|
||||
Utils::FileSaver saver(newFileName, QIODevice::ReadWrite); // QtBug: WriteOnly truncates.
|
||||
Utils::FileSaver saver(Utils::FilePath::fromString(newFileName),
|
||||
QIODevice::ReadWrite); // QtBug: WriteOnly truncates.
|
||||
if (!saver.hasError()) {
|
||||
QFile *output = saver.file();
|
||||
const qint64 size = output->size();
|
||||
|
@@ -136,7 +136,7 @@ private:
|
||||
|
||||
Utils::FileReader reader;
|
||||
// Do not use QIODevice::Text as we have to deal with byte offsets.
|
||||
if (reader.fetch(filePath, QIODevice::ReadOnly))
|
||||
if (reader.fetch(Utils::FilePath::fromString(filePath), QIODevice::ReadOnly))
|
||||
return reader.data();
|
||||
|
||||
return {};
|
||||
|
@@ -1437,7 +1437,7 @@ void ClearCasePluginPrivate::startCheckIn(const QString &workingDir, const QStri
|
||||
VcsOutputWindow::appendError(saver.errorString());
|
||||
return;
|
||||
}
|
||||
m_checkInMessageFileName = saver.fileName();
|
||||
m_checkInMessageFileName = saver.filePath().toString();
|
||||
m_checkInView = workingDir;
|
||||
// Create a submit editor and set file list
|
||||
ClearCaseSubmitEditor *editor = openClearCaseSubmitEditor(m_checkInMessageFileName, m_viewData.isUcm);
|
||||
@@ -2603,7 +2603,7 @@ void ClearCasePlugin::testLogResolving()
|
||||
void ClearCasePlugin::initTestCase()
|
||||
{
|
||||
dd->m_tempFile = QDir::currentPath() + QLatin1String("/cc_file.cpp");
|
||||
FileSaver srcSaver(dd->m_tempFile);
|
||||
FileSaver srcSaver(Utils::FilePath::fromString(dd->m_tempFile));
|
||||
srcSaver.write(QByteArray());
|
||||
srcSaver.finalize();
|
||||
}
|
||||
@@ -2695,7 +2695,7 @@ public:
|
||||
ClearCasePluginPrivate::instance()->setFakeCleartool(true);
|
||||
VcsManager::clearVersionControlCache();
|
||||
|
||||
FileSaver srcSaver(fileName);
|
||||
FileSaver srcSaver(Utils::FilePath::fromString(fileName));
|
||||
srcSaver.write(QByteArray());
|
||||
srcSaver.finalize();
|
||||
m_editor = EditorManager::openEditor(fileName);
|
||||
|
@@ -275,7 +275,7 @@ public:
|
||||
TempFile(const QString &fileName)
|
||||
: m_fileName(fileName)
|
||||
{
|
||||
Utils::FileSaver srcSaver(fileName);
|
||||
Utils::FileSaver srcSaver(Utils::FilePath::fromString(fileName));
|
||||
srcSaver.write(QByteArray());
|
||||
srcSaver.finalize();
|
||||
|
||||
|
@@ -130,7 +130,7 @@ QMap<QString, QList<QKeySequence>> CommandsFile::importCommands() const
|
||||
|
||||
bool CommandsFile::exportCommands(const QList<ShortcutItem *> &items)
|
||||
{
|
||||
Utils::FileSaver saver(m_filename, QIODevice::Text);
|
||||
Utils::FileSaver saver(Utils::FilePath::fromString(m_filename), QIODevice::Text);
|
||||
if (!saver.hasError()) {
|
||||
const Context ctx;
|
||||
QXmlStreamWriter w(saver.file());
|
||||
|
@@ -474,7 +474,7 @@ ExternalTool * ExternalTool::createFromFile(const QString &fileName, QString *er
|
||||
{
|
||||
QString absFileName = QFileInfo(fileName).absoluteFilePath();
|
||||
FileReader reader;
|
||||
if (!reader.fetch(absFileName, errorMessage))
|
||||
if (!reader.fetch(FilePath::fromString(absFileName), errorMessage))
|
||||
return nullptr;
|
||||
ExternalTool *tool = ExternalTool::createFromXml(reader.data(), errorMessage, locale);
|
||||
if (!tool)
|
||||
@@ -500,7 +500,7 @@ bool ExternalTool::save(QString *errorMessage) const
|
||||
{
|
||||
if (m_fileName.isEmpty())
|
||||
return false;
|
||||
FileSaver saver(m_fileName);
|
||||
FileSaver saver(FilePath::fromString(m_fileName));
|
||||
if (!saver.hasError()) {
|
||||
QXmlStreamWriter out(saver.file());
|
||||
out.setAutoFormatting(true);
|
||||
|
@@ -157,7 +157,7 @@ bool GeneratedFile::write(QString *errorMessage) const
|
||||
// Write out
|
||||
if (isBinary()) {
|
||||
QIODevice::OpenMode flags = QIODevice::WriteOnly | QIODevice::Truncate;
|
||||
Utils::FileSaver saver(m_d->path, flags);
|
||||
Utils::FileSaver saver(FilePath::fromString(m_d->path), flags);
|
||||
saver.write(m_d->contents);
|
||||
return saver.finalize(errorMessage);
|
||||
}
|
||||
|
@@ -400,7 +400,7 @@ void CodePasterPluginPrivate::finishFetch(const QString &titleDescription,
|
||||
MessageManager::writeDisrupting(saver.errorString());
|
||||
return;
|
||||
}
|
||||
const QString fileName = saver.fileName();
|
||||
const QString fileName = saver.filePath().toString();
|
||||
m_fetchedSnippets.push_back(fileName);
|
||||
// Open editor with title.
|
||||
IEditor *editor = EditorManager::openEditor(fileName);
|
||||
|
@@ -209,6 +209,6 @@ void FileShareProtocol::paste(
|
||||
return;
|
||||
}
|
||||
|
||||
Core::MessageManager::writeSilently(tr("Pasted: %1").arg(saver.fileName()));
|
||||
Core::MessageManager::writeSilently(tr("Pasted: %1").arg(saver.filePath().toUserOutput()));
|
||||
}
|
||||
} // namespace CodePaster
|
||||
|
@@ -85,7 +85,7 @@ static QString makeResourcePath(const QStringList &prefixList, const QString &fi
|
||||
static QString findResourceInFile(const QString &resName, const QString &filePathName)
|
||||
{
|
||||
Utils::FileReader reader;
|
||||
if (!reader.fetch(filePathName))
|
||||
if (!reader.fetch(Utils::FilePath::fromString(filePathName)))
|
||||
return QString();
|
||||
|
||||
const QByteArray contents = reader.data();
|
||||
|
@@ -369,7 +369,7 @@ void CppFileSettingsWidget::slotEdit()
|
||||
path = QFileDialog::getSaveFileName(this, tr("Choose Location for New License Template File"));
|
||||
if (path.isEmpty())
|
||||
return;
|
||||
Utils::FileSaver saver(path, QIODevice::Text);
|
||||
Utils::FileSaver saver(Utils::FilePath::fromString(path), QIODevice::Text);
|
||||
saver.write(tr(licenseTemplateTemplate).arg(Core::Constants::IDE_DISPLAY_NAME).toUtf8());
|
||||
if (!saver.finalize(this))
|
||||
return;
|
||||
|
@@ -139,7 +139,7 @@ public:
|
||||
bool readContents(QByteArray *contents)
|
||||
{
|
||||
Utils::FileReader fileReader;
|
||||
const bool isFetchOk = fileReader.fetch(m_filePath);
|
||||
const bool isFetchOk = fileReader.fetch(Utils::FilePath::fromString(m_filePath));
|
||||
if (isFetchOk) {
|
||||
m_originalFileContents = fileReader.data();
|
||||
if (contents)
|
||||
|
@@ -242,7 +242,7 @@ bool TestCase::waitUntilProjectIsFullyOpened(Project *project, int timeOutInMs)
|
||||
|
||||
bool TestCase::writeFile(const QString &filePath, const QByteArray &contents)
|
||||
{
|
||||
Utils::FileSaver saver(filePath);
|
||||
Utils::FileSaver saver(Utils::FilePath::fromString(filePath));
|
||||
if (!saver.write(contents) || !saver.finalize()) {
|
||||
const QString warning = QLatin1String("Failed to write file to disk: ") + filePath;
|
||||
QWARN(qPrintable(warning));
|
||||
|
@@ -1010,7 +1010,7 @@ void CvsPluginPrivate::startCommit(const QString &workingDir, const QString &fil
|
||||
VcsOutputWindow::appendError(saver.errorString());
|
||||
return;
|
||||
}
|
||||
m_commitMessageFileName = saver.fileName();
|
||||
m_commitMessageFileName = saver.filePath().toString();
|
||||
// Create a submit editor and set file list
|
||||
CvsSubmitEditor *editor = openCVSSubmitEditor(m_commitMessageFileName);
|
||||
setSubmitEditor(editor);
|
||||
|
@@ -2453,7 +2453,7 @@ static CPlusPlus::Document::Ptr getParsedDocument(const QString &fileName,
|
||||
src = workingCopy.source(fileName);
|
||||
} else {
|
||||
FileReader reader;
|
||||
if (reader.fetch(fileName)) // ### FIXME error reporting
|
||||
if (reader.fetch(Utils::FilePath::fromString(fileName))) // ### FIXME error reporting
|
||||
src = QString::fromLocal8Bit(reader.data()).toUtf8();
|
||||
}
|
||||
|
||||
|
@@ -1942,7 +1942,7 @@ void DebuggerPluginPrivate::dumpLog()
|
||||
tr("Save Debugger Log"), Utils::TemporaryDirectory::masterDirectoryPath());
|
||||
if (fileName.isEmpty())
|
||||
return;
|
||||
FileSaver saver(fileName);
|
||||
FileSaver saver(Utils::FilePath::fromUserInput(fileName));
|
||||
if (!saver.hasError()) {
|
||||
QTextStream ts(saver.file());
|
||||
ts << logWindow->inputContents();
|
||||
|
@@ -95,7 +95,7 @@ static bool writeLogContents(const QPlainTextEdit *editor, QWidget *parent)
|
||||
const QString fileName = QFileDialog::getSaveFileName(parent, LogWindow::tr("Log File"));
|
||||
if (fileName.isEmpty())
|
||||
break;
|
||||
Utils::FileSaver saver(fileName, QIODevice::Text);
|
||||
Utils::FileSaver saver(Utils::FilePath::fromString(fileName), QIODevice::Text);
|
||||
saver.write(editor->toPlainText().toUtf8());
|
||||
if (saver.finalize(parent))
|
||||
success = true;
|
||||
|
@@ -409,7 +409,7 @@ static Document::Ptr getParsedDocument(const QString &fileName,
|
||||
src = workingCopy.source(fileName);
|
||||
} else {
|
||||
Utils::FileReader reader;
|
||||
if (reader.fetch(fileName)) // ### FIXME error reporting
|
||||
if (reader.fetch(Utils::FilePath::fromString(fileName))) // ### FIXME error reporting
|
||||
src = QString::fromLocal8Bit(reader.data()).toUtf8();
|
||||
}
|
||||
|
||||
|
@@ -185,7 +185,8 @@ private:
|
||||
|
||||
static bool writeFile(const QString &filePath, const QString &contents)
|
||||
{
|
||||
Utils::FileSaver saver(filePath, QIODevice::Text | QIODevice::WriteOnly);
|
||||
Utils::FileSaver saver(Utils::FilePath::fromString(filePath),
|
||||
QIODevice::Text | QIODevice::WriteOnly);
|
||||
return saver.write(contents.toUtf8()) && saver.finalize();
|
||||
}
|
||||
|
||||
@@ -303,7 +304,7 @@ bool GenericBuildSystem::saveRawList(const QStringList &rawList, const QString &
|
||||
{
|
||||
FileChangeBlocker changeGuard(fileName);
|
||||
// Make sure we can open the file for writing
|
||||
Utils::FileSaver saver(fileName, QIODevice::Text);
|
||||
Utils::FileSaver saver(Utils::FilePath::fromString(fileName), QIODevice::Text);
|
||||
if (!saver.hasError()) {
|
||||
QTextStream stream(saver.file());
|
||||
for (const QString &filePath : rawList)
|
||||
|
@@ -154,7 +154,8 @@ bool AuthenticationDialog::setupCredentials()
|
||||
}
|
||||
if (!found)
|
||||
out << "machine " << m_server->host << " login " << user << " password " << password << '\n';
|
||||
Utils::FileSaver saver(m_netrcFileName, QFile::WriteOnly | QFile::Truncate | QFile::Text);
|
||||
Utils::FileSaver saver(Utils::FilePath::fromString(m_netrcFileName),
|
||||
QFile::WriteOnly | QFile::Truncate | QFile::Text);
|
||||
saver.write(netrcContents.toUtf8());
|
||||
return saver.finalize();
|
||||
}
|
||||
|
@@ -2855,7 +2855,7 @@ bool GitClient::getCommitData(const QString &workingDirectory,
|
||||
if (templateFileInfo.isRelative())
|
||||
templateFilename = repoDirectory + '/' + templateFilename;
|
||||
FileReader reader;
|
||||
if (!reader.fetch(templateFilename, QIODevice::Text, errorMessage))
|
||||
if (!reader.fetch(Utils::FilePath::fromString(templateFilename), QIODevice::Text, errorMessage))
|
||||
return false;
|
||||
*commitTemplate = QString::fromLocal8Bit(reader.data());
|
||||
}
|
||||
|
@@ -1354,7 +1354,7 @@ void GitPluginPrivate::startCommit(CommitType commitType)
|
||||
VcsOutputWindow::appendError(saver.errorString());
|
||||
return;
|
||||
}
|
||||
m_commitMessageFileName = saver.fileName();
|
||||
m_commitMessageFileName = saver.filePath().toString();
|
||||
openSubmitEditor(m_commitMessageFileName, data);
|
||||
}
|
||||
|
||||
|
@@ -248,7 +248,7 @@ void GeneralSettingsPage::exportBookmarks()
|
||||
if (!fileName.endsWith(suffix))
|
||||
fileName.append(suffix);
|
||||
|
||||
Utils::FileSaver saver(fileName);
|
||||
Utils::FileSaver saver(Utils::FilePath::fromString(fileName));
|
||||
if (!saver.hasError()) {
|
||||
XbelWriter writer(LocalHelpManager::bookmarkManager().treeBookmarkModel());
|
||||
writer.writeToFile(saver.file());
|
||||
|
@@ -164,7 +164,7 @@ bool HelpViewer::launchWithExternalApp(const QUrl &url)
|
||||
if (!saver.hasError())
|
||||
saver.write(helpEngine.fileData(resolvedUrl));
|
||||
if (saver.finalize(Core::ICore::dialogParent()))
|
||||
QDesktopServices::openUrl(QUrl(saver.fileName()));
|
||||
QDesktopServices::openUrl(QUrl(saver.filePath().toString()));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@@ -344,7 +344,7 @@ void LspLogWidget::saveLog()
|
||||
const QString fileName = QFileDialog::getSaveFileName(this, LspInspector::tr("Log File"));
|
||||
if (fileName.isEmpty())
|
||||
return;
|
||||
Utils::FileSaver saver(fileName, QIODevice::Text);
|
||||
Utils::FileSaver saver(Utils::FilePath::fromString(fileName), QIODevice::Text);
|
||||
saver.write(contents.toUtf8());
|
||||
if (!saver.finalize(this))
|
||||
saveLog();
|
||||
|
@@ -138,7 +138,7 @@ bool Macro::loadHeader(const QString &fileName)
|
||||
|
||||
bool Macro::save(const QString &fileName, QWidget *parent)
|
||||
{
|
||||
Utils::FileSaver saver(fileName);
|
||||
Utils::FileSaver saver(Utils::FilePath::fromString(fileName));
|
||||
if (!saver.hasError()) {
|
||||
QDataStream stream(saver.file());
|
||||
stream << d->version;
|
||||
|
@@ -141,7 +141,7 @@ bool MercurialClient::synchronousClone(const QString &workingDir,
|
||||
return false;
|
||||
|
||||
// By now, there is no hgrc file -> create it
|
||||
FileSaver saver(workingDirectory.path() + QLatin1String("/.hg/hgrc"));
|
||||
FileSaver saver(Utils::FilePath::fromString(workingDirectory.path() + "/.hg/hgrc"));
|
||||
const QString hgrc = QLatin1String("[paths]\ndefault = ") + dstLocation + QLatin1Char('\n');
|
||||
saver.write(hgrc.toUtf8());
|
||||
if (!saver.finalize()) {
|
||||
|
@@ -643,7 +643,7 @@ void MercurialPluginPrivate::showCommitWidget(const QList<VcsBaseClient::StatusI
|
||||
return;
|
||||
}
|
||||
|
||||
Core::IEditor *editor = Core::EditorManager::openEditor(saver.fileName(),
|
||||
Core::IEditor *editor = Core::EditorManager::openEditor(saver.filePath().toString(),
|
||||
Constants::COMMIT_ID);
|
||||
if (!editor) {
|
||||
VcsOutputWindow::appendError(tr("Unable to create an editor for the commit."));
|
||||
|
@@ -775,7 +775,7 @@ void PerforcePluginPrivate::startSubmitProject()
|
||||
cleanCommitMessageFile();
|
||||
return;
|
||||
}
|
||||
m_commitMessageFileName = saver.fileName();
|
||||
m_commitMessageFileName = saver.filePath().toString();
|
||||
|
||||
args.clear();
|
||||
args << QLatin1String("files");
|
||||
@@ -1385,7 +1385,7 @@ PerforceResponse PerforcePluginPrivate::runP4Cmd(const QString &workingDir,
|
||||
QString errorMessage;
|
||||
QSharedPointer<TempFileSaver> tempFile = createTemporaryArgumentFile(extraArgs, &errorMessage);
|
||||
if (!tempFile.isNull()) {
|
||||
actualArgs << QLatin1String("-x") << tempFile->fileName();
|
||||
actualArgs << QLatin1String("-x") << tempFile->filePath().toString();
|
||||
} else if (!errorMessage.isEmpty()) {
|
||||
PerforceResponse tempFailResponse;
|
||||
tempFailResponse.error = true;
|
||||
@@ -1598,7 +1598,7 @@ bool PerforcePluginPrivate::submitEditorAboutToClose()
|
||||
}
|
||||
// Pipe file into p4 submit -i
|
||||
FileReader reader;
|
||||
if (!reader.fetch(m_commitMessageFileName, QIODevice::Text)) {
|
||||
if (!reader.fetch(Utils::FilePath::fromString(m_commitMessageFileName), QIODevice::Text)) {
|
||||
VcsOutputWindow::appendError(reader.errorString());
|
||||
return false;
|
||||
}
|
||||
|
@@ -198,7 +198,7 @@ static inline bool createFile(CustomWizardFile cwFile,
|
||||
const QFile::OpenMode openMode
|
||||
= cwFile.binary ? QIODevice::ReadOnly : (QIODevice::ReadOnly|QIODevice::Text);
|
||||
Utils::FileReader reader;
|
||||
if (!reader.fetch(sourcePath, openMode, errorMessage))
|
||||
if (!reader.fetch(Utils::FilePath::fromString(sourcePath), openMode, errorMessage))
|
||||
return false;
|
||||
|
||||
Core::GeneratedFile generatedFile;
|
||||
|
@@ -99,7 +99,7 @@ Core::GeneratedFile JsonWizardFileGenerator::generateFile(const File &file,
|
||||
QIODevice::ReadOnly : (QIODevice::ReadOnly|QIODevice::Text);
|
||||
|
||||
Utils::FileReader reader;
|
||||
if (!reader.fetch(file.source, openMode, errorMessage))
|
||||
if (!reader.fetch(Utils::FilePath::fromString(file.source), openMode, errorMessage))
|
||||
return Core::GeneratedFile();
|
||||
|
||||
// Generate file information:
|
||||
|
@@ -620,7 +620,7 @@ Macros MsvcToolChain::msvcPredefinedMacros(const QStringList &cxxflags,
|
||||
|
||||
if (language() == ProjectExplorer::Constants::C_LANGUAGE_ID)
|
||||
arguments << QLatin1String("/TC");
|
||||
arguments << toProcess << QLatin1String("/EP") << QDir::toNativeSeparators(saver.fileName());
|
||||
arguments << toProcess << QLatin1String("/EP") << saver.filePath().toUserOutput();
|
||||
cpp.runBlocking({binary, arguments});
|
||||
if (cpp.result() != QtcProcess::Finished || cpp.exitCode() != 0)
|
||||
return predefinedMacros;
|
||||
@@ -2016,7 +2016,7 @@ Utils::optional<QString> MsvcToolChain::generateEnvironmentSettings(const Utils:
|
||||
if (cmdPath.isEmpty())
|
||||
cmdPath = env.searchInPath(QLatin1String("cmd.exe"));
|
||||
// Windows SDK setup scripts require command line switches for environment expansion.
|
||||
CommandLine cmd(cmdPath, {"/E:ON", "/V:ON", "/c", QDir::toNativeSeparators(saver.fileName())});
|
||||
CommandLine cmd(cmdPath, {"/E:ON", "/V:ON", "/c", saver.filePath().toUserOutput()});
|
||||
if (debug)
|
||||
qDebug() << "readEnvironmentSetting: " << call << cmd.toUserOutput()
|
||||
<< " Env: " << runEnv.size();
|
||||
|
@@ -295,7 +295,7 @@ bool PythonBuildSystem::saveRawList(const QStringList &rawList, const QString &f
|
||||
|
||||
// New project file
|
||||
if (fileName.endsWith(".pyproject")) {
|
||||
FileSaver saver(fileName, QIODevice::ReadOnly | QIODevice::Text);
|
||||
FileSaver saver(FilePath::fromString(fileName), QIODevice::ReadOnly | QIODevice::Text);
|
||||
if (!saver.hasError()) {
|
||||
QString content = QTextStream(saver.file()).readAll();
|
||||
if (saver.finalize(ICore::dialogParent())) {
|
||||
@@ -306,7 +306,7 @@ bool PythonBuildSystem::saveRawList(const QStringList &rawList, const QString &f
|
||||
}
|
||||
}
|
||||
} else { // Old project file
|
||||
FileSaver saver(fileName, QIODevice::WriteOnly | QIODevice::Text);
|
||||
FileSaver saver(FilePath::fromString(fileName), QIODevice::WriteOnly | QIODevice::Text);
|
||||
if (!saver.hasError()) {
|
||||
QTextStream stream(saver.file());
|
||||
for (const QString &filePath : rawList)
|
||||
|
@@ -55,7 +55,9 @@ struct ProjectContents {
|
||||
};
|
||||
|
||||
// Create a binary icon file
|
||||
static inline Core::GeneratedFile generateIconFile(const QString &source, const QString &target, QString *errorMessage)
|
||||
static inline Core::GeneratedFile generateIconFile(const Utils::FilePath &source,
|
||||
const QString &target,
|
||||
QString *errorMessage)
|
||||
{
|
||||
// Read out source
|
||||
Utils::FileReader reader;
|
||||
@@ -270,7 +272,9 @@ QList<Core::GeneratedFile> PluginGenerator::generatePlugin(const GenerationPara
|
||||
const QFileInfo qfi(icon);
|
||||
if (qfi.dir() != slashLessBaseDir) {
|
||||
const QString newIcon = baseDir + qfi.fileName();
|
||||
const Core::GeneratedFile iconFile = generateIconFile(icon, newIcon, errorMessage);
|
||||
const Core::GeneratedFile iconFile = generateIconFile(Utils::FilePath::fromFileInfo(qfi),
|
||||
newIcon,
|
||||
errorMessage);
|
||||
if (iconFile.path().isEmpty())
|
||||
return QList<Core::GeneratedFile>();
|
||||
rc.push_back(iconFile);
|
||||
@@ -311,7 +315,7 @@ QString PluginGenerator::processTemplate(const QString &tmpl,
|
||||
QString *errorMessage)
|
||||
{
|
||||
Utils::FileReader reader;
|
||||
if (!reader.fetch(tmpl, errorMessage))
|
||||
if (!reader.fetch(Utils::FilePath::fromString(tmpl), errorMessage))
|
||||
return QString();
|
||||
|
||||
|
||||
|
@@ -276,9 +276,9 @@ void AssetExporter::preprocessQmlFile(const Utils::FilePath &path)
|
||||
// Meanwhile cache the Component UUIDs as well
|
||||
std::unique_ptr<Model> model(Model::create("Item", 2, 7));
|
||||
Utils::FileReader reader;
|
||||
if (!reader.fetch(path.toString())) {
|
||||
if (!reader.fetch(path)) {
|
||||
ExportNotification::addError(tr("Cannot preprocess file: %1. Error %2")
|
||||
.arg(path.toString()).arg(reader.errorString()));
|
||||
.arg(path.toUserOutput()).arg(reader.errorString()));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -301,11 +301,11 @@ void AssetExporter::preprocessQmlFile(const Utils::FilePath &path)
|
||||
// Some UUIDs were assigned. Rewrite the file.
|
||||
rewriterView->writeAuxiliaryData();
|
||||
const QByteArray data = textEdit.toPlainText().toUtf8();
|
||||
Utils::FileSaver saver(path.toString(), QIODevice::Text);
|
||||
Utils::FileSaver saver(path, QIODevice::Text);
|
||||
saver.write(data);
|
||||
if (!saver.finalize()) {
|
||||
ExportNotification::addError(tr("Cannot update %1.\n%2")
|
||||
.arg(path.toString()).arg(saver.errorString()));
|
||||
.arg(path.toUserOutput()).arg(saver.errorString()));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -414,7 +414,7 @@ void AssetExporter::writeMetadata() const
|
||||
return;
|
||||
}
|
||||
|
||||
Utils::FileSaver saver(path.toString(), QIODevice::Text);
|
||||
Utils::FileSaver saver(path, QIODevice::Text);
|
||||
saver.write(doc.toJson(QJsonDocument::Indented));
|
||||
if (!saver.finalize()) {
|
||||
ExportNotification::addError(tr("Writing metadata failed. %1").
|
||||
|
@@ -1458,7 +1458,7 @@ void styleMerge(const SelectionContext &selectionContext, const QString &templat
|
||||
QPlainTextEdit textEditTemplate;
|
||||
Utils::FileReader reader;
|
||||
|
||||
QTC_ASSERT(reader.fetch(templateFile), return);
|
||||
QTC_ASSERT(reader.fetch(Utils::FilePath::fromString(templateFile)), return);
|
||||
QString qmlTemplateString = QString::fromUtf8(reader.data());
|
||||
QString imports;
|
||||
|
||||
|
@@ -88,8 +88,8 @@ GraphicsView::GraphicsView(CurveEditorModel *model, QWidget *parent)
|
||||
applyZoom(m_zoomX, m_zoomY);
|
||||
update();
|
||||
|
||||
const QString css = Theme::replaceCssColors(QString::fromUtf8(
|
||||
Utils::FileReader::fetchQrc(QLatin1String(":/qmldesigner/scrollbar.css"))));
|
||||
const QString css = Theme::replaceCssColors(
|
||||
QString::fromUtf8(Utils::FileReader::fetchQrc(":/qmldesigner/scrollbar.css")));
|
||||
horizontalScrollBar()->setStyleSheet(css);
|
||||
verticalScrollBar()->setStyleSheet(css);
|
||||
}
|
||||
|
@@ -199,8 +199,10 @@ ItemLibraryWidget::ItemLibraryWidget(AsynchronousImageCache &imageCache,
|
||||
updateSearch();
|
||||
|
||||
/* style sheets */
|
||||
setStyleSheet(Theme::replaceCssColors(QString::fromUtf8(Utils::FileReader::fetchQrc(QLatin1String(":/qmldesigner/stylesheet.css")))));
|
||||
m_resourcesView->setStyleSheet(Theme::replaceCssColors(QString::fromUtf8(Utils::FileReader::fetchQrc(QLatin1String(":/qmldesigner/scrollbar.css")))));
|
||||
setStyleSheet(Theme::replaceCssColors(
|
||||
QString::fromUtf8(Utils::FileReader::fetchQrc(":/qmldesigner/stylesheet.css"))));
|
||||
m_resourcesView->setStyleSheet(Theme::replaceCssColors(
|
||||
QString::fromUtf8(Utils::FileReader::fetchQrc(":/qmldesigner/scrollbar.css"))));
|
||||
|
||||
m_qmlSourceUpdateShortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_F5), this);
|
||||
connect(m_qmlSourceUpdateShortcut, &QShortcut::activated, this, &ItemLibraryWidget::reloadQmlSource);
|
||||
|
@@ -88,7 +88,7 @@ PropertyEditorView::PropertyEditorView(QWidget *parent) :
|
||||
connect(m_updateShortcut, &QShortcut::activated, this, &PropertyEditorView::reloadQml);
|
||||
|
||||
m_stackedWidget->setStyleSheet(Theme::replaceCssColors(
|
||||
QString::fromUtf8(Utils::FileReader::fetchQrc(QStringLiteral(":/qmldesigner/stylesheet.css")))));
|
||||
QString::fromUtf8(Utils::FileReader::fetchQrc(":/qmldesigner/stylesheet.css"))));
|
||||
m_stackedWidget->setMinimumWidth(340);
|
||||
m_stackedWidget->move(0, 0);
|
||||
connect(m_stackedWidget, &PropertyEditorWidget::resized, this, &PropertyEditorView::updateSize);
|
||||
|
@@ -85,7 +85,9 @@ void TextEditorWidget::setTextEditor(TextEditor::BaseTextEditor *textEditor)
|
||||
});
|
||||
|
||||
textEditor->editorWidget()->installEventFilter(this);
|
||||
static QString styleSheet = Theme::replaceCssColors(QString::fromUtf8(Utils::FileReader::fetchQrc(QLatin1String(":/qmldesigner/scrollbar.css"))));
|
||||
static QString styleSheet = Theme::replaceCssColors(
|
||||
QString::fromUtf8(Utils::FileReader::fetchQrc(
|
||||
":/qmldesigner/scrollbar.css")));
|
||||
textEditor->editorWidget()->verticalScrollBar()->setStyleSheet(styleSheet);
|
||||
textEditor->editorWidget()->horizontalScrollBar()->setStyleSheet(styleSheet);
|
||||
}
|
||||
|
@@ -128,7 +128,7 @@ TimelineWidget::TimelineWidget(TimelineView *view)
|
||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
|
||||
const QString css = Theme::replaceCssColors(QString::fromUtf8(
|
||||
Utils::FileReader::fetchQrc(QLatin1String(":/qmldesigner/scrollbar.css"))));
|
||||
Utils::FileReader::fetchQrc(":/qmldesigner/scrollbar.css")));
|
||||
|
||||
m_scrollbar->setStyleSheet(css);
|
||||
m_scrollbar->setOrientation(Qt::Horizontal);
|
||||
|
@@ -100,8 +100,8 @@ TransitionEditorWidget::TransitionEditorWidget(TransitionEditorView *view)
|
||||
setWindowTitle(tr("Transition", "Title of transition view"));
|
||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
|
||||
const QString css = Theme::replaceCssColors(QString::fromUtf8(
|
||||
Utils::FileReader::fetchQrc(QLatin1String(":/qmldesigner/scrollbar.css"))));
|
||||
const QString css = Theme::replaceCssColors(
|
||||
QString::fromUtf8(Utils::FileReader::fetchQrc(":/qmldesigner/scrollbar.css")));
|
||||
|
||||
m_scrollbar->setStyleSheet(css);
|
||||
m_scrollbar->setOrientation(Qt::Horizontal);
|
||||
|
@@ -167,7 +167,7 @@ static QByteArray getSourceForUrl(const QString &fileURl)
|
||||
{
|
||||
Utils::FileReader fileReader;
|
||||
|
||||
if (fileReader.fetch(fileURl))
|
||||
if (fileReader.fetch(Utils::FilePath::fromString(fileURl)))
|
||||
return fileReader.data();
|
||||
else
|
||||
return Utils::FileReader::fetchQrc(fileURl);
|
||||
|
@@ -215,7 +215,7 @@ void QmlBuildSystem::parseProject(RefreshOptions options)
|
||||
= QDir(canonicalProjectDir().toString()).absoluteFilePath(mainFilePath);
|
||||
Utils::FileReader reader;
|
||||
QString errorMessage;
|
||||
if (!reader.fetch(mainFilePath, &errorMessage)) {
|
||||
if (!reader.fetch(Utils::FilePath::fromString(mainFilePath), &errorMessage)) {
|
||||
MessageManager::writeFlashing(tr("Warning while loading project file %1.")
|
||||
.arg(projectFilePath().toUserOutput()));
|
||||
MessageManager::writeSilently(errorMessage);
|
||||
|
@@ -58,7 +58,7 @@ void SshKeyDeployer::deployPublicKey(const SshConnectionParameters &sshParams,
|
||||
cleanup();
|
||||
|
||||
Utils::FileReader reader;
|
||||
if (!reader.fetch(keyFilePath)) {
|
||||
if (!reader.fetch(Utils::FilePath::fromString(keyFilePath))) {
|
||||
emit error(tr("Public key error: %1").arg(reader.errorString()));
|
||||
return;
|
||||
}
|
||||
|
@@ -199,12 +199,12 @@ bool ResourceEditorDocument::setContents(const QByteArray &contents)
|
||||
return false;
|
||||
|
||||
const QString originalFileName = m_model->fileName();
|
||||
m_model->setFileName(saver.fileName());
|
||||
m_model->setFileName(saver.filePath().toString());
|
||||
const bool success = (m_model->reload() == OpenResult::Success);
|
||||
m_model->setFileName(originalFileName);
|
||||
m_shouldAutoSave = false;
|
||||
if (debugResourceEditorW)
|
||||
qDebug() << "ResourceEditorW::createNew: " << contents << " (" << saver.fileName() << ") returns " << success;
|
||||
qDebug() << "ResourceEditorW::createNew: " << contents << " (" << saver.filePath() << ") returns " << success;
|
||||
emit loaded(success);
|
||||
return success;
|
||||
}
|
||||
|
@@ -820,7 +820,7 @@ void SubversionPluginPrivate::startCommit(const QString &workingDir, const QStri
|
||||
VcsOutputWindow::appendError(saver.errorString());
|
||||
return;
|
||||
}
|
||||
m_commitMessageFileName = saver.fileName();
|
||||
m_commitMessageFileName = saver.filePath().toString();
|
||||
// Create a submit editor and set file list
|
||||
SubversionSubmitEditor *editor = openSubversionSubmitEditor(m_commitMessageFileName);
|
||||
QTC_ASSERT(editor, return);
|
||||
|
@@ -238,7 +238,7 @@ void ColorScheme::clear()
|
||||
|
||||
bool ColorScheme::save(const QString &fileName, QWidget *parent) const
|
||||
{
|
||||
Utils::FileSaver saver(fileName);
|
||||
Utils::FileSaver saver(Utils::FilePath::fromString(fileName));
|
||||
if (!saver.hasError()) {
|
||||
QXmlStreamWriter w(saver.file());
|
||||
w.setAutoFormatting(true);
|
||||
|
@@ -81,13 +81,13 @@ static FormatTask format(FormatTask task)
|
||||
if (!sourceFile.finalize()) {
|
||||
task.error = QString(QT_TRANSLATE_NOOP("TextEditor",
|
||||
"Cannot create temporary file \"%1\": %2."))
|
||||
.arg(sourceFile.fileName(), sourceFile.errorString());
|
||||
.arg(sourceFile.filePath().toUserOutput(), sourceFile.errorString());
|
||||
return task;
|
||||
}
|
||||
|
||||
// Format temporary file
|
||||
QStringList options = task.command.options();
|
||||
options.replaceInStrings(QLatin1String("%file"), sourceFile.fileName());
|
||||
options.replaceInStrings(QLatin1String("%file"), sourceFile.filePath().toString());
|
||||
SynchronousProcess process;
|
||||
process.setTimeoutS(5);
|
||||
process.runBlocking({executable, options});
|
||||
@@ -102,9 +102,9 @@ static FormatTask format(FormatTask task)
|
||||
|
||||
// Read text back
|
||||
Utils::FileReader reader;
|
||||
if (!reader.fetch(sourceFile.fileName(), QIODevice::Text)) {
|
||||
if (!reader.fetch(sourceFile.filePath(), QIODevice::Text)) {
|
||||
task.error = QString(QT_TRANSLATE_NOOP("TextEditor", "Cannot read file \"%1\": %2."))
|
||||
.arg(sourceFile.fileName(), reader.errorString());
|
||||
.arg(sourceFile.filePath().toUserOutput(), reader.errorString());
|
||||
return task;
|
||||
}
|
||||
task.formattedData = QString::fromUtf8(reader.data());
|
||||
|
@@ -306,7 +306,7 @@ bool SnippetsCollection::synchronize(QString *errorString)
|
||||
QDir::toNativeSeparators(m_userSnippetsPath));
|
||||
return false;
|
||||
}
|
||||
Utils::FileSaver saver(m_userSnippetsPath + m_userSnippetsFile);
|
||||
Utils::FileSaver saver(Utils::FilePath::fromString(m_userSnippetsPath + m_userSnippetsFile));
|
||||
if (!saver.hasError()) {
|
||||
using GroupIndexByIdConstIt = QHash<QString, int>::ConstIterator;
|
||||
|
||||
|
@@ -193,7 +193,7 @@ void SuppressionDialog::maybeShow(MemcheckErrorView *view)
|
||||
|
||||
void SuppressionDialog::accept()
|
||||
{
|
||||
const QString path = m_fileChooser->filePath().toString();
|
||||
const Utils::FilePath path = m_fileChooser->filePath();
|
||||
QTC_ASSERT(!path.isEmpty(), return);
|
||||
QTC_ASSERT(!m_suppressionEdit->toPlainText().trimmed().isEmpty(), return);
|
||||
|
||||
@@ -207,16 +207,16 @@ void SuppressionDialog::accept()
|
||||
return;
|
||||
|
||||
// Add file to project if there is a project containing this file on the file system.
|
||||
if (!ProjectExplorer::SessionManager::projectForFile(Utils::FilePath::fromString(path))) {
|
||||
if (!ProjectExplorer::SessionManager::projectForFile(path)) {
|
||||
for (ProjectExplorer::Project *p : ProjectExplorer::SessionManager::projects()) {
|
||||
if (path.startsWith(p->projectDirectory().toString())) {
|
||||
p->rootProjectNode()->addFiles(QStringList() << path);
|
||||
p->rootProjectNode()->addFiles({path.toString()});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_settings->suppressions.addSuppressionFile(path);
|
||||
m_settings->suppressions.addSuppressionFile(path.toString());
|
||||
|
||||
QModelIndexList indices = m_view->selectionModel()->selectedRows();
|
||||
Utils::sort(indices, [](const QModelIndex &l, const QModelIndex &r) {
|
||||
|
@@ -244,7 +244,7 @@ bool NickNameDialog::populateModelFromMailCapFile(const QString &fileName,
|
||||
if (fileName.isEmpty())
|
||||
return true;
|
||||
FileReader reader;
|
||||
if (!reader.fetch(fileName, QIODevice::Text, errorMessage))
|
||||
if (!reader.fetch(Utils::FilePath::fromString(fileName), QIODevice::Text, errorMessage))
|
||||
return false;
|
||||
// Split into lines and read
|
||||
NickNameEntry entry;
|
||||
|
@@ -58,7 +58,7 @@ Core::IDocument::OpenResult SubmitEditorFile::open(QString *errorString, const Q
|
||||
return OpenResult::ReadError;
|
||||
|
||||
FileReader reader;
|
||||
if (!reader.fetch(realFileName, QIODevice::Text, errorString))
|
||||
if (!reader.fetch(Utils::FilePath::fromString(realFileName), QIODevice::Text, errorString))
|
||||
return OpenResult::ReadError;
|
||||
|
||||
const QString text = QString::fromLocal8Bit(reader.data());
|
||||
@@ -91,8 +91,7 @@ void SubmitEditorFile::setModified(bool modified)
|
||||
bool SubmitEditorFile::save(QString *errorString, const QString &fileName, bool autoSave)
|
||||
{
|
||||
const FilePath fName = fileName.isEmpty() ? filePath() : FilePath::fromString(fileName);
|
||||
FileSaver saver(fName.toString(),
|
||||
QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text);
|
||||
FileSaver saver(fName, QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text);
|
||||
saver.write(m_editor->fileContents());
|
||||
if (!saver.finalize(errorString))
|
||||
return false;
|
||||
|
@@ -274,8 +274,11 @@ static inline QStringList fieldTexts(const QString &fileContents)
|
||||
void VcsBaseSubmitEditor::createUserFields(const QString &fieldConfigFile)
|
||||
{
|
||||
FileReader reader;
|
||||
if (!reader.fetch(fieldConfigFile, QIODevice::Text, Core::ICore::dialogParent()))
|
||||
if (!reader.fetch(FilePath::fromString(fieldConfigFile),
|
||||
QIODevice::Text,
|
||||
Core::ICore::dialogParent())) {
|
||||
return;
|
||||
}
|
||||
// Parse into fields
|
||||
const QStringList fields = fieldTexts(QString::fromUtf8(reader.data()));
|
||||
if (fields.empty())
|
||||
@@ -657,7 +660,7 @@ bool VcsBaseSubmitEditor::runSubmitMessageCheckScript(const QString &checkScript
|
||||
QtcProcess checkProcess;
|
||||
if (!d->m_checkScriptWorkingDirectory.isEmpty())
|
||||
checkProcess.setWorkingDirectory(d->m_checkScriptWorkingDirectory);
|
||||
checkProcess.setCommand({checkScript, {saver.fileName()}});
|
||||
checkProcess.setCommand({checkScript, {saver.filePath().toString()}});
|
||||
checkProcess.start();
|
||||
checkProcess.closeWriteChannel();
|
||||
if (!checkProcess.waitForStarted()) {
|
||||
|
@@ -106,7 +106,7 @@ static bool generateEnvironmentSettings(Utils::Environment &env,
|
||||
const Utils::FilePath cmdPath
|
||||
= Utils::FilePath::fromString(QString::fromLocal8Bit(qgetenv("COMSPEC")));
|
||||
// Windows SDK setup scripts require command line switches for environment expansion.
|
||||
QString cmdArguments = " /E:ON /V:ON /c \"" + QDir::toNativeSeparators(saver.fileName()) + '"';
|
||||
QString cmdArguments = " /E:ON /V:ON /c \"" + saver.filePath().toUserOutput() + '"';
|
||||
run.setCommand(Utils::CommandLine(cmdPath, cmdArguments, Utils::CommandLine::Raw));
|
||||
run.start();
|
||||
|
||||
|
Reference in New Issue
Block a user