aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorhjk <[email protected]>2025-04-08 17:17:23 +0200
committerhjk <[email protected]>2025-04-11 09:38:34 +0000
commit9e9bbf215cb72467ec71be144b24b177e31afe0a (patch)
tree3a921f3cb8cace118182ff43ae29079b3067ead4 /src
parent133cdb8e80894b0438e441a61ada13da5694ceaa (diff)
Utils: Replace Result class by type alias to std::expected<T, QString>
... to be able to conveniently return also non-void cases without being exposed to the syntax of expected. The price for the more general approach is some uglification of the void case: The previous 'Result' is now equivalent to 'Result<>', which needs to be spelled out in function signatures, and some changes to the special cases. Change-Id: Ic5026e237ef2077a0765cdb8287122cae99d699f Reviewed-by: Marcus Tillmanns <[email protected]> Reviewed-by: Eike Ziller <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/libs/advanceddockingsystem/dockmanager.cpp16
-rw-r--r--src/libs/advanceddockingsystem/dockmanager.h2
-rw-r--r--src/libs/extensionsystem/pluginmanager.cpp16
-rw-r--r--src/libs/extensionsystem/pluginmanager.h2
-rw-r--r--src/libs/extensionsystem/pluginmanager_p.h2
-rw-r--r--src/libs/gocmdbridge/client/bridgedfileaccess.cpp76
-rw-r--r--src/libs/gocmdbridge/client/bridgedfileaccess.h16
-rw-r--r--src/libs/gocmdbridge/client/cmdbridgeclient.cpp12
-rw-r--r--src/libs/gocmdbridge/client/cmdbridgeclient.h2
-rw-r--r--src/libs/utils/devicefileaccess.cpp196
-rw-r--r--src/libs/utils/devicefileaccess.h44
-rw-r--r--src/libs/utils/deviceshell.cpp16
-rw-r--r--src/libs/utils/deviceshell.h4
-rw-r--r--src/libs/utils/filepath.cpp30
-rw-r--r--src/libs/utils/filepath.h12
-rw-r--r--src/libs/utils/fileutils.cpp28
-rw-r--r--src/libs/utils/fileutils.h6
-rw-r--r--src/libs/utils/fsengine/fsenginehandler.cpp10
-rw-r--r--src/libs/utils/persistentsettings.cpp12
-rw-r--r--src/libs/utils/persistentsettings.h7
-rw-r--r--src/libs/utils/result.cpp40
-rw-r--r--src/libs/utils/result.h33
-rw-r--r--src/libs/utils/savefile.cpp2
-rw-r--r--src/libs/utils/settingsaccessor.cpp2
-rw-r--r--src/libs/utils/textfileformat.cpp6
-rw-r--r--src/libs/utils/textfileformat.h6
-rw-r--r--src/libs/utils/unarchiver.cpp44
-rw-r--r--src/libs/utils/unarchiver.h4
-rw-r--r--src/plugins/android/androidbuildapkstep.cpp2
-rw-r--r--src/plugins/android/androidmanifesteditor.cpp4
-rw-r--r--src/plugins/android/androidpackageinstallationstep.cpp2
-rw-r--r--src/plugins/android/androidsdkdownloader.cpp2
-rw-r--r--src/plugins/android/androidsignaloperation.cpp14
-rw-r--r--src/plugins/baremetal/baremetaldebugsupport.cpp2
-rw-r--r--src/plugins/baremetal/debugservers/gdb/gdbserverprovider.cpp8
-rw-r--r--src/plugins/baremetal/debugservers/gdb/gdbserverprovider.h2
-rw-r--r--src/plugins/baremetal/debugservers/uvsc/uvscserverprovider.cpp12
-rw-r--r--src/plugins/baremetal/debugservers/uvsc/uvscserverprovider.h2
-rw-r--r--src/plugins/baremetal/idebugserverprovider.h5
-rw-r--r--src/plugins/bineditor/bineditorplugin.cpp34
-rw-r--r--src/plugins/clangcodemodel/test/clangdtests.cpp6
-rw-r--r--src/plugins/clangtools/clangfixitsrefactoringchanges.cpp2
-rw-r--r--src/plugins/clangtools/virtualfilesystemoverlay.cpp4
-rw-r--r--src/plugins/cmakeprojectmanager/fileapireader.cpp2
-rw-r--r--src/plugins/compilerexplorer/compilerexplorereditor.cpp8
-rw-r--r--src/plugins/coreplugin/basefilewizard.cpp2
-rw-r--r--src/plugins/coreplugin/basefilewizardfactory.cpp6
-rw-r--r--src/plugins/coreplugin/basefilewizardfactory.h2
-rw-r--r--src/plugins/coreplugin/documentmanager.cpp4
-rw-r--r--src/plugins/coreplugin/editormanager/editormanager.cpp4
-rw-r--r--src/plugins/coreplugin/foldernavigationwidget.cpp2
-rw-r--r--src/plugins/coreplugin/generatedfile.cpp22
-rw-r--r--src/plugins/coreplugin/generatedfile.h8
-rw-r--r--src/plugins/coreplugin/idocument.cpp18
-rw-r--r--src/plugins/coreplugin/idocument.h8
-rw-r--r--src/plugins/coreplugin/outputwindow.cpp2
-rw-r--r--src/plugins/coreplugin/plugininstallwizard.cpp16
-rw-r--r--src/plugins/coreplugin/session.cpp6
-rw-r--r--src/plugins/coreplugin/textdocument.cpp4
-rw-r--r--src/plugins/coreplugin/textdocument.h4
-rw-r--r--src/plugins/cppeditor/cppeditordocument.cpp2
-rw-r--r--src/plugins/cppeditor/cppeditordocument.h2
-rw-r--r--src/plugins/debugger/cdb/cdbengine.cpp2
-rw-r--r--src/plugins/debugger/debuggerengine.cpp10
-rw-r--r--src/plugins/debugger/debuggerengine.h4
-rw-r--r--src/plugins/debugger/debuggerplugin.cpp10
-rw-r--r--src/plugins/debugger/debuggerprotocol.cpp2
-rw-r--r--src/plugins/debugger/debuggerprotocol.h2
-rw-r--r--src/plugins/debugger/debuggerruncontrol.cpp22
-rw-r--r--src/plugins/debugger/gdb/gdbengine.cpp26
-rw-r--r--src/plugins/debugger/lldb/lldbengine.cpp2
-rw-r--r--src/plugins/debugger/loadcoredialog.cpp2
-rw-r--r--src/plugins/designer/formwindowfile.cpp20
-rw-r--r--src/plugins/designer/formwindowfile.h6
-rw-r--r--src/plugins/diffeditor/diffeditordocument.cpp14
-rw-r--r--src/plugins/diffeditor/diffeditordocument.h4
-rw-r--r--src/plugins/docker/dockercontainerthread.cpp16
-rw-r--r--src/plugins/docker/dockercontainerthread.h2
-rw-r--r--src/plugins/docker/dockerdevice.cpp6
-rw-r--r--src/plugins/docker/dockerdevice.h2
-rw-r--r--src/plugins/docker/dockerdevicewidget.cpp2
-rw-r--r--src/plugins/effectcomposer/effectcodeeditorwidget.cpp2
-rw-r--r--src/plugins/extensionmanager/remotespec.cpp12
-rw-r--r--src/plugins/extensionmanager/remotespec.h4
-rw-r--r--src/plugins/git/gitclient.cpp2
-rw-r--r--src/plugins/imageviewer/imageviewerfile.cpp6
-rw-r--r--src/plugins/imageviewer/imageviewerfile.h2
-rw-r--r--src/plugins/languageclient/languageclientutils.cpp2
-rw-r--r--src/plugins/lua/bindings/install.cpp2
-rw-r--r--src/plugins/modeleditor/modeldocument.cpp18
-rw-r--r--src/plugins/modeleditor/modeldocument.h4
-rw-r--r--src/plugins/perfprofiler/perfprofilertool.cpp2
-rw-r--r--src/plugins/projectexplorer/customwizard/customwizard.cpp14
-rw-r--r--src/plugins/projectexplorer/customwizard/customwizard.h2
-rw-r--r--src/plugins/projectexplorer/customwizard/customwizardscriptgenerator.cpp10
-rw-r--r--src/plugins/projectexplorer/customwizard/customwizardscriptgenerator.h6
-rw-r--r--src/plugins/projectexplorer/devicesupport/desktopprocesssignaloperation.cpp30
-rw-r--r--src/plugins/projectexplorer/devicesupport/desktopprocesssignaloperation.h4
-rw-r--r--src/plugins/projectexplorer/devicesupport/idevice.cpp10
-rw-r--r--src/plugins/projectexplorer/devicesupport/idevice.h6
-rw-r--r--src/plugins/projectexplorer/devicesupport/processlist.cpp2
-rw-r--r--src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp10
-rw-r--r--src/plugins/projectexplorer/jsonwizard/jsonwizardfactory.cpp2
-rw-r--r--src/plugins/projectexplorer/jsonwizard/jsonwizardfilegenerator.cpp20
-rw-r--r--src/plugins/projectexplorer/jsonwizard/jsonwizardgeneratorfactory.cpp54
-rw-r--r--src/plugins/projectexplorer/jsonwizard/jsonwizardgeneratorfactory.h28
-rw-r--r--src/plugins/projectexplorer/jsonwizard/jsonwizardscannergenerator.cpp12
-rw-r--r--src/plugins/projectexplorer/project.cpp4
-rw-r--r--src/plugins/projectexplorer/projectexplorer.cpp30
-rw-r--r--src/plugins/projectexplorer/projectexplorer.h2
-rw-r--r--src/plugins/projectexplorer/taskfile.cpp6
-rw-r--r--src/plugins/projectexplorer/taskfile.h2
-rw-r--r--src/plugins/qmakeprojectmanager/qmakeparsernodes.cpp4
-rw-r--r--src/plugins/qmakeprojectmanager/qmakeproject.cpp4
-rw-r--r--src/plugins/qmldesigner/components/assetslibrary/assetslibrarymodel.cpp2
-rw-r--r--src/plugins/qmldesigner/documentmanager.cpp2
-rw-r--r--src/plugins/qmldesigner/libs/qmldesignerutils/fileextractor.cpp4
-rw-r--r--src/plugins/qmlprofiler/qmlprofilertool.cpp2
-rw-r--r--src/plugins/qmlprojectmanager/buildsystem/qmlbuildsystem.cpp4
-rw-r--r--src/plugins/qtsupport/gettingstartedwelcomepage.cpp2
-rw-r--r--src/plugins/remotelinux/filesystemaccess_test.cpp2
-rw-r--r--src/plugins/remotelinux/genericdeploystep.cpp12
-rw-r--r--src/plugins/remotelinux/linuxdevice.cpp22
-rw-r--r--src/plugins/remotelinux/publickeydeploymentdialog.cpp8
-rw-r--r--src/plugins/remotelinux/publickeydeploymentdialog.h9
-rw-r--r--src/plugins/remotelinux/remotelinuxfiletransfer.cpp24
-rw-r--r--src/plugins/remotelinux/remotelinuxsignaloperation.cpp6
-rw-r--r--src/plugins/remotelinux/sshkeycreationdialog.cpp6
-rw-r--r--src/plugins/resourceeditor/qrceditor/resourcefile.cpp4
-rw-r--r--src/plugins/resourceeditor/resourceeditor.cpp20
-rw-r--r--src/plugins/resourceeditor/resourcenode.cpp6
-rw-r--r--src/plugins/scxmleditor/scxmleditordocument.cpp16
-rw-r--r--src/plugins/scxmleditor/scxmleditordocument.h4
-rw-r--r--src/plugins/squish/objectsmapdocument.cpp14
-rw-r--r--src/plugins/squish/objectsmapdocument.h4
-rw-r--r--src/plugins/squish/squishfilehandler.cpp2
-rw-r--r--src/plugins/squish/squishtesttreeview.cpp2
-rw-r--r--src/plugins/squish/squishwizardpages.cpp26
-rw-r--r--src/plugins/squish/suiteconf.cpp2
-rw-r--r--src/plugins/terminal/shellintegration.cpp10
-rw-r--r--src/plugins/texteditor/refactoringchanges.cpp4
-rw-r--r--src/plugins/texteditor/textdocument.cpp24
-rw-r--r--src/plugins/texteditor/textdocument.h10
-rw-r--r--src/plugins/texteditor/texteditor.cpp2
-rw-r--r--src/plugins/valgrind/callgrindtool.cpp2
-rw-r--r--src/plugins/valgrind/memchecktool.cpp6
-rw-r--r--src/plugins/valgrind/xmlprotocol/parser.cpp8
-rw-r--r--src/plugins/valgrind/xmlprotocol/parser.h8
-rw-r--r--src/plugins/vcsbase/submiteditorfile.cpp10
-rw-r--r--src/plugins/vcsbase/submiteditorfile.h2
150 files changed, 807 insertions, 825 deletions
diff --git a/src/libs/advanceddockingsystem/dockmanager.cpp b/src/libs/advanceddockingsystem/dockmanager.cpp
index e15c495f6ea..c38f1e286b4 100644
--- a/src/libs/advanceddockingsystem/dockmanager.cpp
+++ b/src/libs/advanceddockingsystem/dockmanager.cpp
@@ -1311,7 +1311,7 @@ expected_str<QString> DockManager::cloneWorkspace(const QString &originalFileNam
const FilePath clonePath = workspaceNameToFilePath(cloneName);
- const Result copyResult = originalPath.copyFile(clonePath);
+ const Result<> copyResult = originalPath.copyFile(clonePath);
if (!copyResult)
return make_unexpected(Tr::tr("Could not clone \"%1\" due to: %2")
.arg(originalPath.toUserOutput(), copyResult.error()));
@@ -1337,21 +1337,21 @@ expected_str<QString> DockManager::renameWorkspace(const QString &originalFileNa
return originalFileName;
}
-Result DockManager::resetWorkspacePreset(const QString &fileName)
+Result<> DockManager::resetWorkspacePreset(const QString &fileName)
{
qCInfo(adsLog) << "Reset workspace" << fileName;
Workspace *w = workspace(fileName);
if (!w)
- return Result::Error(Tr::tr("Workspace \"%1\" does not exist.").arg(fileName));
+ return ResultError(Tr::tr("Workspace \"%1\" does not exist.").arg(fileName));
if (!w->isPreset())
- return Result::Error(Tr::tr("Workspace \"%1\" is not a preset.").arg(fileName));
+ return ResultError(Tr::tr("Workspace \"%1\" is not a preset.").arg(fileName));
const FilePath filePath = w->filePath();
if (!filePath.removeFile())
- return Result::Error(Tr::tr("Cannot remove \"%1\".").arg(filePath.toUserOutput()));
+ return ResultError(Tr::tr("Cannot remove \"%1\".").arg(filePath.toUserOutput()));
return presetDirectory().pathAppended(fileName).copyFile(filePath);
}
@@ -1400,7 +1400,7 @@ expected_str<QString> DockManager::importWorkspace(const QString &filePath)
const FilePath targetFilePath = userDirectory().pathAppended(fileName);
- const Result copyResult = sourceFilePath.copyFile(targetFilePath);
+ const Result<> copyResult = sourceFilePath.copyFile(targetFilePath);
if (!copyResult)
return make_unexpected(
Tr::tr("Could not copy \"%1\" to \"%2\" due to: %3")
@@ -1441,7 +1441,7 @@ expected_str<QString> DockManager::exportWorkspace(const QString &targetFilePath
Tr::tr("The workspace \"%1\" does not exist ").arg(workspaceFile.toUserOutput()));
// Finally copy the workspace to the target
- const Result copyResult = workspaceFile.copyFile(targetFile);
+ const Result<> copyResult = workspaceFile.copyFile(targetFile);
if (!copyResult)
return make_unexpected(
Tr::tr("Could not copy \"%1\" to \"%2\" due to: %3")
@@ -1675,7 +1675,7 @@ void DockManager::syncWorkspacePresets()
continue;
}
- const Result copyResult = filePath.copyFile(
+ const Result<> copyResult = filePath.copyFile(
userDirectory().pathAppended(filePath.fileName()));
if (!copyResult)
qWarning() << QString("Could not copy '%1' to '%2' due to %3")
diff --git a/src/libs/advanceddockingsystem/dockmanager.h b/src/libs/advanceddockingsystem/dockmanager.h
index cb573327fe3..ffc38307c17 100644
--- a/src/libs/advanceddockingsystem/dockmanager.h
+++ b/src/libs/advanceddockingsystem/dockmanager.h
@@ -739,7 +739,7 @@ public:
Utils::expected_str<QString> renameWorkspace(const QString &originalFileName,
const QString &newName);
- Utils::Result resetWorkspacePreset(const QString &fileName);
+ Utils::Result<> resetWorkspacePreset(const QString &fileName);
/**
* \brief Save the currently active workspace.
diff --git a/src/libs/extensionsystem/pluginmanager.cpp b/src/libs/extensionsystem/pluginmanager.cpp
index 5dee658089f..6ffb8bff5de 100644
--- a/src/libs/extensionsystem/pluginmanager.cpp
+++ b/src/libs/extensionsystem/pluginmanager.cpp
@@ -357,7 +357,7 @@ void PluginManager::installPluginsAfterRestart()
d->installPluginsAfterRestart();
}
-Result PluginManager::removePluginOnRestart(const QString &id)
+Result<> PluginManager::removePluginOnRestart(const QString &id)
{
return d->removePluginOnRestart(id);
}
@@ -1971,23 +1971,23 @@ void PluginManagerPrivate::addPlugins(const PluginSpecs &specs)
static const char PLUGINS_TO_INSTALL_KEY[] = "PluginsToInstall";
static const char PLUGINS_TO_REMOVE_KEY[] = "PluginsToRemove";
-Result PluginManagerPrivate::removePluginOnRestart(const QString &pluginId)
+Result<> PluginManagerPrivate::removePluginOnRestart(const QString &pluginId)
{
const PluginSpec *pluginSpec = pluginById(pluginId);
if (!pluginSpec)
- return Result::Error(Tr::tr("Plugin not found."));
+ return ResultError(Tr::tr("Plugin not found."));
const expected_str<FilePaths> filePaths = pluginSpec->filesToUninstall();
if (!filePaths)
- return Result::Error(filePaths.error());
+ return ResultError(filePaths.error());
const QVariantList list = Utils::transform(*filePaths, &FilePath::toVariant);
settings->setValue(PLUGINS_TO_REMOVE_KEY, settings->value(PLUGINS_TO_REMOVE_KEY).toList() + list);
settings->sync();
- return Result::Ok;
+ return ResultOk;
}
static QList<QPair<FilePath, FilePath>> readPluginInstallList(QtcSettings *settings)
@@ -2028,7 +2028,7 @@ void PluginManagerPrivate::removePluginsAfterRestart()
= Utils::transform(settings->value(PLUGINS_TO_REMOVE_KEY).toList(), &FilePath::fromVariant);
for (const FilePath &path : removeList) {
- Result r = Result::Error(Tr::tr("It does not exist."));
+ Result<> r = ResultError(Tr::tr("It does not exist."));
if (path.isFile())
r = path.removeFile();
else if (path.isDir())
@@ -2060,7 +2060,7 @@ void PluginManagerPrivate::installPluginsAfterRestart()
continue;
}
} else if (dest.isFile()) {
- if (const Result result = dest.removeFile(); !result) {
+ if (const Result<> result = dest.removeFile(); !result) {
qCWarning(pluginLog()) << "Failed to remove" << dest << ":" << result.error();
continue;
}
@@ -2074,7 +2074,7 @@ void PluginManagerPrivate::installPluginsAfterRestart()
}
}
- Utils::Result result = src.isDir() ? src.copyRecursively(dest)
+ Utils::Result<> result = src.isDir() ? src.copyRecursively(dest)
: src.copyFile(dest / src.fileName());
if (!result) {
diff --git a/src/libs/extensionsystem/pluginmanager.h b/src/libs/extensionsystem/pluginmanager.h
index 43f5a7900f0..95c3fa62570 100644
--- a/src/libs/extensionsystem/pluginmanager.h
+++ b/src/libs/extensionsystem/pluginmanager.h
@@ -88,7 +88,7 @@ public:
static void reInstallPlugins();
- static Utils::Result removePluginOnRestart(const QString &id);
+ static Utils::Result<> removePluginOnRestart(const QString &id);
static void installPluginOnRestart(
const Utils::FilePath &source, const Utils::FilePath &destination);
diff --git a/src/libs/extensionsystem/pluginmanager_p.h b/src/libs/extensionsystem/pluginmanager_p.h
index b4dd2c02096..2677b9bde79 100644
--- a/src/libs/extensionsystem/pluginmanager_p.h
+++ b/src/libs/extensionsystem/pluginmanager_p.h
@@ -75,7 +75,7 @@ public:
void removePluginsAfterRestart();
void installPluginsAfterRestart();
- Utils::Result removePluginOnRestart(const QString &pluginId);
+ Utils::Result<> removePluginOnRestart(const QString &pluginId);
void installPluginOnRestart(const Utils::FilePath &src, const Utils::FilePath &dest);
class TestSpec {
diff --git a/src/libs/gocmdbridge/client/bridgedfileaccess.cpp b/src/libs/gocmdbridge/client/bridgedfileaccess.cpp
index 34e534fbf06..9348bece4ed 100644
--- a/src/libs/gocmdbridge/client/bridgedfileaccess.cpp
+++ b/src/libs/gocmdbridge/client/bridgedfileaccess.cpp
@@ -34,7 +34,7 @@ expected_str<QString> run(const CommandLine &cmdLine, const QByteArray &inputDat
return p.readAllStandardOutput().trimmed();
}
-Result FileAccess::init(
+Result<> FileAccess::init(
const FilePath &pathToBridge, const Environment &environment, bool deleteOnExit)
{
m_environment = environment;
@@ -42,26 +42,26 @@ Result FileAccess::init(
auto startResult = m_client->start(deleteOnExit);
if (!startResult)
- return Result::Error(QString("Could not start cmdbridge: %1").arg(startResult.error()));
+ return ResultError(QString("Could not start cmdbridge: %1").arg(startResult.error()));
- return Result::Ok;
+ return ResultOk;
}
-Result FileAccess::deployAndInit(
+Result<> FileAccess::deployAndInit(
const FilePath &libExecPath,
const FilePath &remoteRootPath,
const Environment &environment)
{
if (remoteRootPath.isEmpty())
- return Result::Error(Tr::tr("Remote root path is empty"));
+ return ResultError(Tr::tr("Remote root path is empty"));
if (!remoteRootPath.isAbsolutePath())
- return Result::Error(Tr::tr("Remote root path is not absolute"));
+ return ResultError(Tr::tr("Remote root path is not absolute"));
const auto whichDD = run({remoteRootPath.withNewPath("which"), {"dd"}});
if (!whichDD) // TODO: Support Windows?
- return Result::Error(Tr::tr("Could not find dd on remote host: %1").arg(whichDD.error()));
+ return ResultError(Tr::tr("Could not find dd on remote host: %1").arg(whichDD.error()));
QElapsedTimer timer;
timer.start();
@@ -73,24 +73,24 @@ Result FileAccess::deployAndInit(
const expected_str<QString> unameOs = run({remoteRootPath.withNewPath("uname"), {"-s"}});
if (!unameOs) {
- return Result::Error(
+ return ResultError(
QString("Could not determine OS on remote host: %1").arg(unameOs.error()));
}
Utils::expected_str<OsType> osType = osTypeFromString(*unameOs);
if (!osType)
- return Result::Error(osType.error());
+ return ResultError(osType.error());
qCDebug(faLog) << deco() << "Remote host OS:" << *unameOs;
const expected_str<QString> unameArch = run({remoteRootPath.withNewPath("uname"), {"-m"}});
if (!unameArch) {
- return Result::Error(
+ return ResultError(
QString("Could not determine architecture on remote host: %1").arg(unameArch.error()));
}
const Utils::expected_str<OsArch> osArch = osArchFromString(*unameArch);
if (!osArch)
- return Result::Error(osArch.error());
+ return ResultError(osArch.error());
qCDebug(faLog) << deco() << "Remote host architecture:" << *unameArch;
@@ -98,7 +98,7 @@ Result FileAccess::deployAndInit(
= Client::getCmdBridgePath(*osType, *osArch, libExecPath);
if (!cmdBridgePath) {
- return Result::Error(
+ return ResultError(
QString("Could not determine compatible cmdbridge for remote host: %1")
.arg(cmdBridgePath.error()));
}
@@ -109,7 +109,7 @@ Result FileAccess::deployAndInit(
const auto cmdBridgeFileData = cmdBridgePath->fileContents();
if (!cmdBridgeFileData) {
- return Result::Error(
+ return ResultError(
QString("Could not read cmdbridge file: %1").arg(cmdBridgeFileData.error()));
}
@@ -117,7 +117,7 @@ Result FileAccess::deployAndInit(
{remoteRootPath.withNewPath("mktemp"), {"-t", "cmdbridge.XXXXXXXXXX"}});
if (!tmpFile) {
- return Result::Error(
+ return ResultError(
QString("Could not create temporary file: %1").arg(tmpFile.error()));
}
@@ -130,7 +130,7 @@ Result FileAccess::deployAndInit(
const auto makeExecutable = run({remoteRootPath.withNewPath("chmod"), {"+x", *tmpFile}});
if (!makeExecutable) {
- return Result::Error(
+ return ResultError(
QString("Could not make temporary file executable: %1").arg(makeExecutable.error()));
}
@@ -473,38 +473,38 @@ expected_str<qint64> FileAccess::writeFileContents(const FilePath &filePath,
}
}
-Result FileAccess::removeFile(const FilePath &filePath) const
+Result<> FileAccess::removeFile(const FilePath &filePath) const
{
try {
Utils::expected_str<QFuture<void>> f = m_client->removeFile(filePath.nativePath());
if (!f)
- return Result::Error(f.error());
+ return ResultError(f.error());
f->waitForFinished();
} catch (const std::system_error &e) {
if (e.code().value() == ENOENT)
- return Result::Error(Tr::tr("File does not exist"));
+ return ResultError(Tr::tr("File does not exist"));
qCWarning(faLog) << "Error removing file:" << e.what();
- return Result::Error(
+ return ResultError(
Tr::tr("Error removing file: %1").arg(QString::fromLocal8Bit(e.what())));
} catch (const std::exception &e) {
qCWarning(faLog) << "Error removing file:" << e.what();
- return Result::Error(
+ return ResultError(
Tr::tr("Error removing file: %1").arg(QString::fromLocal8Bit(e.what())));
}
- return Result::Ok;
+ return ResultOk;
}
-Result FileAccess::removeRecursively(const Utils::FilePath &filePath) const
+Result<> FileAccess::removeRecursively(const Utils::FilePath &filePath) const
{
try {
auto f = m_client->removeRecursively(filePath.nativePath());
- QTC_ASSERT_EXPECTED(f, return Result::Error(Result::Assert));
+ QTC_ASSERT_EXPECTED(f, return ResultError(ResultAssert));
f->waitForFinished();
- return Result::Ok;
+ return ResultOk;
} catch (const std::exception &e) {
qCWarning(faLog) << "Error removing directory:" << e.what();
- return Result::Error(QString::fromLocal8Bit(e.what()));
+ return ResultError(QString::fromLocal8Bit(e.what()));
}
}
@@ -534,35 +534,35 @@ bool FileAccess::createDirectory(const Utils::FilePath &filePath) const
}
}
-Result FileAccess::copyFile(const FilePath &filePath, const FilePath &target) const
+Result<> FileAccess::copyFile(const FilePath &filePath, const FilePath &target) const
{
try {
auto f = m_client->copyFile(filePath.nativePath(), target.nativePath());
- QTC_ASSERT_EXPECTED(f, return Result::Ok);
+ QTC_ASSERT_EXPECTED(f, return ResultOk);
f->waitForFinished();
- return Result::Ok;
+ return ResultOk;
} catch (const std::exception &e) {
- return Result::Error(
+ return ResultError(
Tr::tr("Error copying file: %1").arg(QString::fromLocal8Bit(e.what())));
}
}
-Result FileAccess::renameFile(const FilePath &filePath, const FilePath &target) const
+Result<> FileAccess::renameFile(const FilePath &filePath, const FilePath &target) const
{
try {
Utils::expected_str<QFuture<void>> f
= m_client->renameFile(filePath.nativePath(), target.nativePath());
if (!f)
- return Result::Error(f.error());
+ return ResultError(f.error());
f->waitForFinished();
if (!f)
- return Result::Error(f.error());
+ return ResultError(f.error());
} catch (const std::exception &e) {
- return Result::Error(
+ return ResultError(
Tr::tr("Error renaming file: %1").arg(QString::fromLocal8Bit(e.what())));
}
- return Result::Ok;
+ return ResultOk;
}
expected_str<std::unique_ptr<FilePathWatcher>> FileAccess::watch(const FilePath &filePath) const
@@ -570,15 +570,15 @@ expected_str<std::unique_ptr<FilePathWatcher>> FileAccess::watch(const FilePath
return m_client->watch(filePath.nativePath());
}
-Result FileAccess::signalProcess(int pid, ControlSignal signal) const
+Result<> FileAccess::signalProcess(int pid, ControlSignal signal) const
{
try {
auto f = m_client->signalProcess(pid, signal);
- QTC_ASSERT_EXPECTED(f, return Result::Ok);
+ QTC_ASSERT_EXPECTED(f, return ResultOk);
f->waitForFinished();
- return Result::Ok;
+ return ResultOk;
} catch (const std::exception &e) {
- return Result::Error(
+ return ResultError(
Tr::tr("Error killing process: %1").arg(QString::fromLocal8Bit(e.what())));
};
}
diff --git a/src/libs/gocmdbridge/client/bridgedfileaccess.h b/src/libs/gocmdbridge/client/bridgedfileaccess.h
index 0b52a67d87b..13a501e8bce 100644
--- a/src/libs/gocmdbridge/client/bridgedfileaccess.h
+++ b/src/libs/gocmdbridge/client/bridgedfileaccess.h
@@ -27,22 +27,22 @@ class QTCREATOR_CMDBRIDGE_EXPORT FileAccess : public Utils::DeviceFileAccess
public:
~FileAccess() override;
- Utils::Result deployAndInit(
+ Utils::Result<> deployAndInit(
const Utils::FilePath &libExecPath,
const Utils::FilePath &remoteRootPath,
const Utils::Environment &environment);
- Utils::Result init(
+ Utils::Result<> init(
const Utils::FilePath &pathToBridge,
const Utils::Environment &environment,
bool deleteOnExit);
- Utils::Result signalProcess(int pid, Utils::ControlSignal signal) const;
+ Utils::Result<> signalProcess(int pid, Utils::ControlSignal signal) const;
Utils::Environment deviceEnvironment() const override;
protected:
- Utils::Result reinit();
+ Utils::Result<> reinit();
void iterateDirectory(const Utils::FilePath &filePath,
const Utils::FilePath::IterateDirCallback &callBack,
@@ -74,16 +74,16 @@ protected:
Utils::expected_str<qint64> writeFileContents(const Utils::FilePath &filePath,
const QByteArray &data) const override;
- Utils::Result removeFile(const Utils::FilePath &filePath) const override;
- Utils::Result removeRecursively(const Utils::FilePath &filePath) const override;
+ Utils::Result<> removeFile(const Utils::FilePath &filePath) const override;
+ Utils::Result<> removeRecursively(const Utils::FilePath &filePath) const override;
bool ensureExistingFile(const Utils::FilePath &filePath) const override;
bool createDirectory(const Utils::FilePath &filePath) const override;
- Utils::Result copyFile(const Utils::FilePath &filePath,
+ Utils::Result<> copyFile(const Utils::FilePath &filePath,
const Utils::FilePath &target) const override;
- Utils::Result renameFile(
+ Utils::Result<> renameFile(
const Utils::FilePath &filePath, const Utils::FilePath &target) const override;
Utils::expected_str<Utils::FilePath> createTempFile(const Utils::FilePath &filePath) override;
diff --git a/src/libs/gocmdbridge/client/cmdbridgeclient.cpp b/src/libs/gocmdbridge/client/cmdbridgeclient.cpp
index 21cba204db0..6247dfa0746 100644
--- a/src/libs/gocmdbridge/client/cmdbridgeclient.cpp
+++ b/src/libs/gocmdbridge/client/cmdbridgeclient.cpp
@@ -252,7 +252,7 @@ Client::~Client()
d->thread->wait(2000);
}
-Result Client::start(bool deleteOnExit)
+Result<> Client::start(bool deleteOnExit)
{
d->thread = new QThread(this);
d->thread->setObjectName("CmdBridgeClientThread");
@@ -275,11 +275,11 @@ Result Client::start(bool deleteOnExit)
});
connect(d->process, &Process::started, d->watchDogTimer, qOverload<>(&QTimer::start));
- Result result = Result::Ok;
+ Result<> result = ResultOk;
QMetaObject::invokeMethod(
d->process,
- [this, deleteOnExit]() -> Result {
+ [this, deleteOnExit]() -> Result<> {
if (deleteOnExit)
d->process->setCommand({d->remoteCmdBridgePath, {"-deleteOnExit"}});
else
@@ -395,12 +395,12 @@ Result Client::start(bool deleteOnExit)
d->process->start();
if (!d->process)
- return Result::Error(Tr::tr("Failed starting bridge process"));
+ return ResultError(Tr::tr("Failed starting bridge process"));
if (!d->process->waitForStarted())
- return Result::Error(
+ return ResultError(
Tr::tr("Failed starting bridge process: %1").arg(d->process->errorString()));
- return Result::Ok;
+ return ResultOk;
},
Qt::BlockingQueuedConnection,
&result);
diff --git a/src/libs/gocmdbridge/client/cmdbridgeclient.h b/src/libs/gocmdbridge/client/cmdbridgeclient.h
index 417c53543e4..fb0deb1855e 100644
--- a/src/libs/gocmdbridge/client/cmdbridgeclient.h
+++ b/src/libs/gocmdbridge/client/cmdbridgeclient.h
@@ -26,7 +26,7 @@ public:
Client(const Utils::FilePath &remoteCmdBridgePath, const Utils::Environment &env);
~Client();
- Utils::Result start(bool deleteOnExit = false);
+ Utils::Result<> start(bool deleteOnExit = false);
static Utils::expected_str<Utils::FilePath> getCmdBridgePath(Utils::OsType osType,
Utils::OsArch osArch,
diff --git a/src/libs/utils/devicefileaccess.cpp b/src/libs/utils/devicefileaccess.cpp
index c3dec01a4ea..2f37f0c6fb7 100644
--- a/src/libs/utils/devicefileaccess.cpp
+++ b/src/libs/utils/devicefileaccess.cpp
@@ -120,21 +120,21 @@ bool DeviceFileAccess::hasHardLinks(const FilePath &filePath) const
return false;
}
-Result DeviceFileAccess::ensureWritableDirectory(const FilePath &filePath) const
+Result<> DeviceFileAccess::ensureWritableDirectory(const FilePath &filePath) const
{
if (isWritableDirectory(filePath))
- return Result::Ok;
+ return ResultOk;
if (exists(filePath)) {
- return Result::Error(Tr::tr("Path \"%1\" exists but is not a writable directory.")
+ return ResultError(Tr::tr("Path \"%1\" exists but is not a writable directory.")
.arg(filePath.toUserOutput()));
}
const bool result = createDirectory(filePath);
if (result)
- return Result::Ok;
+ return ResultOk;
- return Result::Error(Tr::tr("Failed to create directory \"%1\".").arg(filePath.toUserOutput()));
+ return ResultError(Tr::tr("Failed to create directory \"%1\".").arg(filePath.toUserOutput()));
}
bool DeviceFileAccess::ensureExistingFile(const FilePath &filePath) const
@@ -157,31 +157,31 @@ bool DeviceFileAccess::exists(const FilePath &filePath) const
return false;
}
-Result DeviceFileAccess::removeFile(const FilePath &filePath) const
+Result<> DeviceFileAccess::removeFile(const FilePath &filePath) const
{
QTC_CHECK(false);
- return Result::Error(
+ return ResultError(
Tr::tr("removeFile is not implemented for \"%1\".").arg(filePath.toUserOutput()));
}
-Result DeviceFileAccess::removeRecursively(const FilePath &filePath) const
+Result<> DeviceFileAccess::removeRecursively(const FilePath &filePath) const
{
Q_UNUSED(filePath)
QTC_CHECK(false);
- return Result::Error(Result::Unimplemented);
+ return ResultError(ResultUnimplemented);
}
-Result DeviceFileAccess::copyFile(const FilePath &filePath, const FilePath &target) const
+Result<> DeviceFileAccess::copyFile(const FilePath &filePath, const FilePath &target) const
{
Q_UNUSED(target)
QTC_CHECK(false);
- return Result::Error(
+ return ResultError(
Tr::tr("copyFile is not implemented for \"%1\".").arg(filePath.toUserOutput()));
}
-static Result copyRecursively_fallback(const FilePath &src, const FilePath &target)
+static Result<> copyRecursively_fallback(const FilePath &src, const FilePath &target)
{
- Result result = Result::Ok;
+ Result<> result = ResultOk;
src.iterateDirectory(
[&target, &src, &result](const FilePath &path) {
const FilePath relative = path.relativePathFromDir(src);
@@ -201,15 +201,15 @@ static Result copyRecursively_fallback(const FilePath &src, const FilePath &targ
return result;
}
-Result DeviceFileAccess::copyRecursively(const FilePath &src, const FilePath &target) const
+Result<> DeviceFileAccess::copyRecursively(const FilePath &src, const FilePath &target) const
{
if (!src.isDir()) {
- return Result::Error(
+ return ResultError(
Tr::tr("Cannot copy from \"%1\", it is not a directory.").arg(src.toUserOutput()));
}
- const Result result = target.ensureWritableDir();
+ const Result<> result = target.ensureWritableDir();
if (!result) {
- return Result::Error(Tr::tr("Cannot copy \"%1\" to \"%2\": %3")
+ return ResultError(Tr::tr("Cannot copy \"%1\" to \"%2\": %3")
.arg(src.toUserOutput())
.arg(target.toUserOutput())
.arg(result.error()));
@@ -254,7 +254,7 @@ Result DeviceFileAccess::copyRecursively(const FilePath &src, const FilePath &ta
if (srcProcess.result() != ProcessResult::FinishedWithSuccess) {
targetProcess.kill();
- return Result::Error(
+ return ResultError(
Tr::tr("Failed to copy recursively from \"%1\" to \"%2\" while "
"trying to create tar archive from source: %3")
.arg(src.toUserOutput(), target.toUserOutput(), srcProcess.readAllStandardError()));
@@ -263,22 +263,22 @@ Result DeviceFileAccess::copyRecursively(const FilePath &src, const FilePath &ta
targetProcess.waitForFinished();
if (targetProcess.result() != ProcessResult::FinishedWithSuccess) {
- return Result::Error(Tr::tr("Failed to copy recursively from \"%1\" to \"%2\" while "
+ return ResultError(Tr::tr("Failed to copy recursively from \"%1\" to \"%2\" while "
"trying to extract tar archive to target: %3")
.arg(src.toUserOutput(),
target.toUserOutput(),
targetProcess.readAllStandardError()));
}
- return Result::Ok;
+ return ResultOk;
#endif
}
-Result DeviceFileAccess::renameFile(const FilePath &filePath, const FilePath &target) const
+Result<> DeviceFileAccess::renameFile(const FilePath &filePath, const FilePath &target) const
{
Q_UNUSED(target)
QTC_CHECK(false);
- return Result::Error(
+ return ResultError(
Tr::tr("renameFile is not implemented for \"%1\".").arg(filePath.toUserOutput()));
}
@@ -482,10 +482,10 @@ bool UnavailableDeviceFileAccess::hasHardLinks(const FilePath &filePath) const
return false;
}
-Result UnavailableDeviceFileAccess::ensureWritableDirectory(const FilePath &filePath) const
+Result<> UnavailableDeviceFileAccess::ensureWritableDirectory(const FilePath &filePath) const
{
Q_UNUSED(filePath);
- return Result::Error(unavailableMessage());
+ return ResultError(unavailableMessage());
}
bool UnavailableDeviceFileAccess::ensureExistingFile(const FilePath &filePath) const
@@ -506,37 +506,37 @@ bool UnavailableDeviceFileAccess::exists(const FilePath &filePath) const
return false;
}
-Result UnavailableDeviceFileAccess::removeFile(const FilePath &filePath) const
+Result<> UnavailableDeviceFileAccess::removeFile(const FilePath &filePath) const
{
Q_UNUSED(filePath)
- return Result::Error(unavailableMessage());
+ return ResultError(unavailableMessage());
}
-Result UnavailableDeviceFileAccess::removeRecursively(const FilePath &filePath) const
+Result<> UnavailableDeviceFileAccess::removeRecursively(const FilePath &filePath) const
{
Q_UNUSED(filePath)
- return Result::Error(Result::Unimplemented);
+ return ResultError(ResultUnimplemented);
}
-Result UnavailableDeviceFileAccess::copyFile(const FilePath &filePath, const FilePath &target) const
+Result<> UnavailableDeviceFileAccess::copyFile(const FilePath &filePath, const FilePath &target) const
{
Q_UNUSED(filePath)
Q_UNUSED(target)
- return Result::Error(unavailableMessage());
+ return ResultError(unavailableMessage());
}
-Result UnavailableDeviceFileAccess::copyRecursively(const FilePath &src, const FilePath &target) const
+Result<> UnavailableDeviceFileAccess::copyRecursively(const FilePath &src, const FilePath &target) const
{
Q_UNUSED(src)
Q_UNUSED(target)
- return Result::Error(unavailableMessage());
+ return ResultError(unavailableMessage());
}
-Result UnavailableDeviceFileAccess::renameFile(const FilePath &filePath, const FilePath &target) const
+Result<> UnavailableDeviceFileAccess::renameFile(const FilePath &filePath, const FilePath &target) const
{
Q_UNUSED(filePath)
Q_UNUSED(target)
- return Result::Error(unavailableMessage());
+ return ResultError(unavailableMessage());
}
FilePath UnavailableDeviceFileAccess::symLinkTarget(const FilePath &filePath) const
@@ -943,22 +943,22 @@ bool DesktopDeviceFileAccess::hasHardLinks(const FilePath &filePath) const
return false;
}
-Result DesktopDeviceFileAccess::ensureWritableDirectory(const FilePath &filePath) const
+Result<> DesktopDeviceFileAccess::ensureWritableDirectory(const FilePath &filePath) const
{
const QFileInfo fi(filePath.path());
if (fi.isDir() && fi.isWritable())
- return Result::Ok;
+ return ResultOk;
if (fi.exists()) {
- return Result::Error(Tr::tr("Path \"%1\" exists but is not a writable directory.")
+ return ResultError(Tr::tr("Path \"%1\" exists but is not a writable directory.")
.arg(filePath.toUserOutput()));
}
const bool result = QDir().mkpath(filePath.path());
if (result)
- return Result::Ok;
+ return ResultOk;
- return Result::Error(
+ return ResultError(
Tr::tr("Failed to create directory \"%1\".").arg(filePath.toUserOutput()));
}
@@ -984,92 +984,92 @@ bool DesktopDeviceFileAccess::exists(const FilePath &filePath) const
return !filePath.isEmpty() && QFileInfo::exists(filePath.path());
}
-Result DesktopDeviceFileAccess::removeFile(const FilePath &filePath) const
+Result<> DesktopDeviceFileAccess::removeFile(const FilePath &filePath) const
{
QFile f(filePath.path());
if (!f.remove())
- return Result::Error(f.errorString());
- return Result::Ok;
+ return ResultError(f.errorString());
+ return ResultOk;
}
-static Result checkToRefuseRemoveStandardLocationDirectory(const QString &dirPath,
+static Result<> checkToRefuseRemoveStandardLocationDirectory(const QString &dirPath,
QStandardPaths::StandardLocation location)
{
if (QStandardPaths::standardLocations(location).contains(dirPath))
- return Result::Error(Tr::tr("Refusing to remove the standard directory \"%1\".")
+ return ResultError(Tr::tr("Refusing to remove the standard directory \"%1\".")
.arg(QStandardPaths::displayName(location)));
- return Result::Ok;
+ return ResultOk;
}
-static Result checkToRefuseRemoveDirectory(const QDir &dir)
+static Result<> checkToRefuseRemoveDirectory(const QDir &dir)
{
if (dir.isRoot())
- return Result::Error(Tr::tr("Refusing to remove root directory."));
+ return ResultError(Tr::tr("Refusing to remove root directory."));
const QString dirPath = dir.path();
if (dirPath == QDir::home().canonicalPath())
- return Result::Error(Tr::tr("Refusing to remove your home directory."));
+ return ResultError(Tr::tr("Refusing to remove your home directory."));
- if (Result res = checkToRefuseRemoveStandardLocationDirectory(dirPath, QStandardPaths::DocumentsLocation); !res)
+ if (Result<> res = checkToRefuseRemoveStandardLocationDirectory(dirPath, QStandardPaths::DocumentsLocation); !res)
return res;
- if (Result res = checkToRefuseRemoveStandardLocationDirectory(dirPath, QStandardPaths::DownloadLocation); !res)
+ if (Result<> res = checkToRefuseRemoveStandardLocationDirectory(dirPath, QStandardPaths::DownloadLocation); !res)
return res;
- if (Result res = checkToRefuseRemoveStandardLocationDirectory(dirPath, QStandardPaths::AppDataLocation); !res)
+ if (Result<> res = checkToRefuseRemoveStandardLocationDirectory(dirPath, QStandardPaths::AppDataLocation); !res)
return res;
- if (Result res = checkToRefuseRemoveStandardLocationDirectory(dirPath, QStandardPaths::AppLocalDataLocation); !res)
+ if (Result<> res = checkToRefuseRemoveStandardLocationDirectory(dirPath, QStandardPaths::AppLocalDataLocation); !res)
return res;
- return Result::Ok;
+ return ResultOk;
}
-Result DesktopDeviceFileAccess::removeRecursively(const FilePath &filePath) const
+Result<> DesktopDeviceFileAccess::removeRecursively(const FilePath &filePath) const
{
- QTC_ASSERT(filePath.isLocal(), return Result::Error(Result::Assert));
+ QTC_ASSERT(filePath.isLocal(), return ResultError(ResultAssert));
QFileInfo fileInfo = filePath.toFileInfo();
if (!fileInfo.exists() && !fileInfo.isSymLink())
- return Result::Ok;
+ return ResultOk;
QFile::setPermissions(fileInfo.absoluteFilePath(), fileInfo.permissions() | QFile::WriteUser);
if (fileInfo.isDir()) {
QDir dir(fileInfo.absoluteFilePath());
dir.setPath(dir.canonicalPath());
- if (Result res = checkToRefuseRemoveDirectory(dir); !res)
+ if (Result<> res = checkToRefuseRemoveDirectory(dir); !res)
return res;
const QStringList fileNames = dir.entryList(QDir::Files | QDir::Hidden | QDir::System
| QDir::Dirs | QDir::NoDotAndDotDot);
for (const QString &fileName : fileNames) {
- if (Result res = removeRecursively(filePath / fileName); !res)
+ if (Result<> res = removeRecursively(filePath / fileName); !res)
return res;
}
if (!QDir::root().rmdir(dir.path()))
- return Result::Error(Tr::tr("Failed to remove directory \"%1\".").arg(filePath.toUserOutput()));
+ return ResultError(Tr::tr("Failed to remove directory \"%1\".").arg(filePath.toUserOutput()));
} else {
if (!QFile::remove(filePath.path()))
- return Result::Error(Tr::tr("Failed to remove file \"%1\".").arg(filePath.toUserOutput()));
+ return ResultError(Tr::tr("Failed to remove file \"%1\".").arg(filePath.toUserOutput()));
}
- return Result::Ok;
+ return ResultOk;
}
-Result DesktopDeviceFileAccess::copyFile(const FilePath &filePath, const FilePath &target) const
+Result<> DesktopDeviceFileAccess::copyFile(const FilePath &filePath, const FilePath &target) const
{
QFile srcFile(filePath.path());
if (srcFile.copy(target.path()))
- return Result::Ok;
- return Result::Error(
+ return ResultOk;
+ return ResultError(
Tr::tr("Failed to copy file \"%1\" to \"%2\": %3")
.arg(filePath.toUserOutput(), target.toUserOutput(), srcFile.errorString()));
}
-Result DesktopDeviceFileAccess::renameFile(
+Result<> DesktopDeviceFileAccess::renameFile(
const FilePath &filePath, const FilePath &target) const
{
QFile f(filePath.path());
if (f.rename(target.path()))
- return Result::Ok;
- return Result::Error(
+ return ResultOk;
+ return ResultError(
Tr::tr("Failed to rename file \"%1\" to \"%2\": %3")
.arg(filePath.toUserOutput(), target.toUserOutput(), f.errorString()));
}
@@ -1318,49 +1318,49 @@ QByteArray DesktopDeviceFileAccess::fileId(const FilePath &filePath) const
UnixDeviceFileAccess::~UnixDeviceFileAccess() = default;
-Result UnixDeviceFileAccess::runInShellSuccess(const CommandLine &cmdLine,
+Result<> UnixDeviceFileAccess::runInShellSuccess(const CommandLine &cmdLine,
const QByteArray &stdInData) const
{
const int retval = runInShell(cmdLine, stdInData).exitCode;
if (retval != 0)
- return Result::Error(QString("return value %1").arg(retval));
- return Result::Ok;
+ return ResultError(QString("return value %1").arg(retval));
+ return ResultOk;
}
bool UnixDeviceFileAccess::isExecutableFile(const FilePath &filePath) const
{
const QString path = filePath.path();
- return runInShellSuccess({"test", {"-x", path}, OsType::OsTypeLinux});
+ return runInShellSuccess({"test", {"-x", path}, OsType::OsTypeLinux}).has_value();
}
bool UnixDeviceFileAccess::isReadableFile(const FilePath &filePath) const
{
const QString path = filePath.path();
- return runInShellSuccess({"test", {"-r", path, "-a", "-f", path}, OsType::OsTypeLinux});
+ return runInShellSuccess({"test", {"-r", path, "-a", "-f", path}, OsType::OsTypeLinux}).has_value();
}
bool UnixDeviceFileAccess::isWritableFile(const FilePath &filePath) const
{
const QString path = filePath.path();
- return runInShellSuccess({"test", {"-w", path, "-a", "-f", path}, OsType::OsTypeLinux});
+ return runInShellSuccess({"test", {"-w", path, "-a", "-f", path}, OsType::OsTypeLinux}).has_value();
}
bool UnixDeviceFileAccess::isReadableDirectory(const FilePath &filePath) const
{
const QString path = filePath.path();
- return runInShellSuccess({"test", {"-r", path, "-a", "-d", path}, OsType::OsTypeLinux});
+ return runInShellSuccess({"test", {"-r", path, "-a", "-d", path}, OsType::OsTypeLinux}).has_value();
}
bool UnixDeviceFileAccess::isWritableDirectory(const FilePath &filePath) const
{
const QString path = filePath.path();
- return runInShellSuccess({"test", {"-w", path, "-a", "-d", path}, OsType::OsTypeLinux});
+ return runInShellSuccess({"test", {"-w", path, "-a", "-d", path}, OsType::OsTypeLinux}).has_value();
}
bool UnixDeviceFileAccess::isFile(const FilePath &filePath) const
{
const QString path = filePath.path();
- return runInShellSuccess({"test", {"-f", path}, OsType::OsTypeLinux});
+ return runInShellSuccess({"test", {"-f", path}, OsType::OsTypeLinux}).has_value();
}
bool UnixDeviceFileAccess::isDirectory(const FilePath &filePath) const
@@ -1369,13 +1369,13 @@ bool UnixDeviceFileAccess::isDirectory(const FilePath &filePath) const
return true;
const QString path = filePath.path();
- return runInShellSuccess({"test", {"-d", path}, OsType::OsTypeLinux});
+ return runInShellSuccess({"test", {"-d", path}, OsType::OsTypeLinux}).has_value();
}
bool UnixDeviceFileAccess::isSymLink(const FilePath &filePath) const
{
const QString path = filePath.path();
- return runInShellSuccess({"test", {"-h", path}, OsType::OsTypeLinux});
+ return runInShellSuccess({"test", {"-h", path}, OsType::OsTypeLinux}).has_value();
}
bool UnixDeviceFileAccess::hasHardLinks(const FilePath &filePath) const
@@ -1388,74 +1388,74 @@ bool UnixDeviceFileAccess::hasHardLinks(const FilePath &filePath) const
bool UnixDeviceFileAccess::ensureExistingFile(const FilePath &filePath) const
{
const QString path = filePath.path();
- return runInShellSuccess({"touch", {path}, OsType::OsTypeLinux});
+ return runInShellSuccess({"touch", {path}, OsType::OsTypeLinux}).has_value();
}
bool UnixDeviceFileAccess::createDirectory(const FilePath &filePath) const
{
const QString path = filePath.path();
- return runInShellSuccess({"mkdir", {"-p", path}, OsType::OsTypeLinux});
+ return runInShellSuccess({"mkdir", {"-p", path}, OsType::OsTypeLinux}).has_value();
}
bool UnixDeviceFileAccess::exists(const FilePath &filePath) const
{
const QString path = filePath.path();
- return runInShellSuccess({"test", {"-e", path}, OsType::OsTypeLinux});
+ return runInShellSuccess({"test", {"-e", path}, OsType::OsTypeLinux}).has_value();
}
-Result UnixDeviceFileAccess::removeFile(const FilePath &filePath) const
+Result<> UnixDeviceFileAccess::removeFile(const FilePath &filePath) const
{
RunResult result = runInShell({"rm", {filePath.path()}, OsType::OsTypeLinux});
if (result.exitCode != 0)
- return Result::Error(QString::fromUtf8(result.stdErr));
- return Result::Ok;
+ return ResultError(QString::fromUtf8(result.stdErr));
+ return ResultOk;
}
-Result UnixDeviceFileAccess::removeRecursively(const FilePath &filePath) const
+Result<> UnixDeviceFileAccess::removeRecursively(const FilePath &filePath) const
{
- QTC_ASSERT(filePath.path().startsWith('/'), return Result::Error(Result::Assert));
+ QTC_ASSERT(filePath.path().startsWith('/'), return ResultError(ResultAssert));
const QString path = filePath.cleanPath().path();
// We are expecting this only to be called in a context of build directories or similar.
// Chicken out in some cases that _might_ be user code errors.
- QTC_ASSERT(path.startsWith('/'), return Result::Error(Result::Assert));
+ QTC_ASSERT(path.startsWith('/'), return ResultError(ResultAssert));
int levelsNeeded = path.startsWith("/home/") ? 4 : 3;
if (path.startsWith("/tmp/"))
levelsNeeded = 2;
- QTC_ASSERT(path.count('/') >= levelsNeeded, return Result::Error(Result::Assert));
+ QTC_ASSERT(path.count('/') >= levelsNeeded, return ResultError(ResultAssert));
RunResult result = runInShell({"rm", {"-rf", "--", path}, OsType::OsTypeLinux});
if (result.exitCode != 0)
- return Result::Error(QString::fromUtf8(result.stdErr));
+ return ResultError(QString::fromUtf8(result.stdErr));
- return Result::Ok;
+ return ResultOk;
}
-Result UnixDeviceFileAccess::copyFile(const FilePath &filePath, const FilePath &target) const
+Result<> UnixDeviceFileAccess::copyFile(const FilePath &filePath, const FilePath &target) const
{
const RunResult result = runInShell(
{"cp", {filePath.path(), target.path()}, OsType::OsTypeLinux});
if (result.exitCode != 0) {
- return Result::Error(Tr::tr("Failed to copy file \"%1\" to \"%2\": %3")
+ return ResultError(Tr::tr("Failed to copy file \"%1\" to \"%2\": %3")
.arg(filePath.toUserOutput(),
target.toUserOutput(),
QString::fromUtf8(result.stdErr)));
}
- return Result::Ok;
+ return ResultOk;
}
-Result UnixDeviceFileAccess::renameFile(const FilePath &filePath, const FilePath &target) const
+Result<> UnixDeviceFileAccess::renameFile(const FilePath &filePath, const FilePath &target) const
{
RunResult result = runInShell({"mv", {filePath.path(), target.path()}, OsType::OsTypeLinux});
if (result.exitCode != 0) {
- return Result::Error(Tr::tr("Failed to rename file \"%1\" to \"%2\": %3")
+ return ResultError(Tr::tr("Failed to rename file \"%1\" to \"%2\": %3")
.arg(filePath.toUserOutput(),
target.toUserOutput(),
QString::fromUtf8(result.stdErr)));
}
- return Result::Ok;
+ return ResultOk;
}
FilePath UnixDeviceFileAccess::symLinkTarget(const FilePath &filePath) const
@@ -1518,7 +1518,7 @@ expected_str<qint64> UnixDeviceFileAccess::writeFileContents(const FilePath &fil
expected_str<FilePath> UnixDeviceFileAccess::createTempFile(const FilePath &filePath)
{
if (!m_hasMkTemp.has_value())
- m_hasMkTemp = runInShellSuccess({"which", {"mktemp"}, OsType::OsTypeLinux});
+ m_hasMkTemp = runInShellSuccess({"which", {"mktemp"}, OsType::OsTypeLinux}).has_value();
QString tmplate = filePath.path();
// Some mktemp implementations require a suffix of XXXXXX.
@@ -1648,7 +1648,7 @@ bool UnixDeviceFileAccess::setPermissions(const FilePath &filePath, QFile::Permi
{
const int flags = toUnixChmod(perms);
return runInShellSuccess(
- {"chmod", {"0" + QString::number(flags, 8), filePath.path()}, OsType::OsTypeLinux});
+ {"chmod", {"0" + QString::number(flags, 8), filePath.path()}, OsType::OsTypeLinux}).has_value();
}
qint64 UnixDeviceFileAccess::fileSize(const FilePath &filePath) const
diff --git a/src/libs/utils/devicefileaccess.h b/src/libs/utils/devicefileaccess.h
index 905345e3cb8..f0f4feb153a 100644
--- a/src/libs/utils/devicefileaccess.h
+++ b/src/libs/utils/devicefileaccess.h
@@ -43,15 +43,15 @@ protected:
virtual bool isDirectory(const FilePath &filePath) const;
virtual bool isSymLink(const FilePath &filePath) const;
virtual bool hasHardLinks(const FilePath &filePath) const;
- virtual Result ensureWritableDirectory(const FilePath &filePath) const;
+ virtual Result<> ensureWritableDirectory(const FilePath &filePath) const;
virtual bool ensureExistingFile(const FilePath &filePath) const;
virtual bool createDirectory(const FilePath &filePath) const;
virtual bool exists(const FilePath &filePath) const;
- virtual Result removeFile(const FilePath &filePath) const;
- virtual Result removeRecursively(const FilePath &filePath) const;
- virtual Result copyFile(const FilePath &filePath, const FilePath &target) const;
- virtual Result copyRecursively(const FilePath &filePath, const FilePath &target) const;
- virtual Result renameFile(const FilePath &filePath, const FilePath &target) const;
+ virtual Result<> removeFile(const FilePath &filePath) const;
+ virtual Result<> removeRecursively(const FilePath &filePath) const;
+ virtual Result<> copyFile(const FilePath &filePath, const FilePath &target) const;
+ virtual Result<> copyRecursively(const FilePath &filePath, const FilePath &target) const;
+ virtual Result<> renameFile(const FilePath &filePath, const FilePath &target) const;
virtual FilePath symLinkTarget(const FilePath &filePath) const;
virtual FilePathInfo filePathInfo(const FilePath &filePath) const;
@@ -105,15 +105,15 @@ protected:
bool isDirectory(const FilePath &filePath) const override;
bool isSymLink(const FilePath &filePath) const override;
bool hasHardLinks(const FilePath &filePath) const override;
- Result ensureWritableDirectory(const FilePath &filePath) const override;
+ Result<> ensureWritableDirectory(const FilePath &filePath) const override;
bool ensureExistingFile(const FilePath &filePath) const override;
bool createDirectory(const FilePath &filePath) const override;
bool exists(const FilePath &filePath) const override;
- Result removeFile(const FilePath &filePath) const override;
- Result removeRecursively(const FilePath &filePath) const override;
- Result copyFile(const FilePath &filePath, const FilePath &target) const override;
- Result copyRecursively(const FilePath &filePath, const FilePath &target) const override;
- Result renameFile(const FilePath &filePath, const FilePath &target) const override;
+ Result<> removeFile(const FilePath &filePath) const override;
+ Result<> removeRecursively(const FilePath &filePath) const override;
+ Result<> copyFile(const FilePath &filePath, const FilePath &target) const override;
+ Result<> copyRecursively(const FilePath &filePath, const FilePath &target) const override;
+ Result<> renameFile(const FilePath &filePath, const FilePath &target) const override;
FilePath symLinkTarget(const FilePath &filePath) const override;
FilePathInfo filePathInfo(const FilePath &filePath) const override;
@@ -163,14 +163,14 @@ protected:
bool isDirectory(const FilePath &filePath) const override;
bool isSymLink(const FilePath &filePath) const override;
bool hasHardLinks(const FilePath &filePath) const override;
- Result ensureWritableDirectory(const FilePath &filePath) const override;
+ Result<> ensureWritableDirectory(const FilePath &filePath) const override;
bool ensureExistingFile(const FilePath &filePath) const override;
bool createDirectory(const FilePath &filePath) const override;
bool exists(const FilePath &filePath) const override;
- Result removeFile(const FilePath &filePath) const override;
- Result removeRecursively(const FilePath &filePath) const override;
- Result copyFile(const FilePath &filePath, const FilePath &target) const override;
- Result renameFile(const FilePath &filePath, const FilePath &target) const override;
+ Result<> removeFile(const FilePath &filePath) const override;
+ Result<> removeRecursively(const FilePath &filePath) const override;
+ Result<> copyFile(const FilePath &filePath, const FilePath &target) const override;
+ Result<> renameFile(const FilePath &filePath, const FilePath &target) const override;
FilePath symLinkTarget(const FilePath &filePath) const override;
FilePathInfo filePathInfo(const FilePath &filePath) const override;
@@ -214,7 +214,7 @@ public:
protected:
virtual RunResult runInShell(const CommandLine &cmdLine,
const QByteArray &inputData = {}) const = 0;
- Result runInShellSuccess(const CommandLine &cmdLine, const QByteArray &stdInData = {}) const;
+ Result<> runInShellSuccess(const CommandLine &cmdLine, const QByteArray &stdInData = {}) const;
bool isExecutableFile(const FilePath &filePath) const override;
bool isReadableFile(const FilePath &filePath) const override;
@@ -228,10 +228,10 @@ protected:
bool ensureExistingFile(const FilePath &filePath) const override;
bool createDirectory(const FilePath &filePath) const override;
bool exists(const FilePath &filePath) const override;
- Result removeFile(const FilePath &filePath) const override;
- Result removeRecursively(const FilePath &filePath) const override;
- Result copyFile(const FilePath &filePath, const FilePath &target) const override;
- Result renameFile(const FilePath &filePath, const FilePath &target) const override;
+ Result<> removeFile(const FilePath &filePath) const override;
+ Result<> removeRecursively(const FilePath &filePath) const override;
+ Result<> copyFile(const FilePath &filePath, const FilePath &target) const override;
+ Result<> renameFile(const FilePath &filePath, const FilePath &target) const override;
FilePathInfo filePathInfo(const FilePath &filePath) const override;
FilePath symLinkTarget(const FilePath &filePath) const override;
diff --git a/src/libs/utils/deviceshell.cpp b/src/libs/utils/deviceshell.cpp
index 830425c39e5..37191757a42 100644
--- a/src/libs/utils/deviceshell.cpp
+++ b/src/libs/utils/deviceshell.cpp
@@ -161,7 +161,7 @@ CommandLine DeviceShell::createFallbackCommand(const CommandLine &cmd)
*
* \note You have to call this function when deriving from DeviceShell. Current implementations call the function from their constructor.
*/
-Result DeviceShell::start()
+Result<> DeviceShell::start()
{
m_shellProcess = std::make_unique<Process>();
connect(m_shellProcess.get(), &Process::done, m_shellProcess.get(),
@@ -249,11 +249,11 @@ expected_str<QByteArray> DeviceShell::checkCommand(const QByteArray &command)
return out;
}
-Result DeviceShell::installShellScript()
+Result<> DeviceShell::installShellScript()
{
if (m_forceFailScriptInstallation) {
m_shellScriptState = State::Failed;
- return Result::Error(Tr::tr("Script installation was forced to fail."));
+ return ResultError(Tr::tr("Script installation was forced to fail."));
}
static const QList<QByteArray> requiredCommands
@@ -262,7 +262,7 @@ Result DeviceShell::installShellScript()
for (const QByteArray &command : requiredCommands) {
auto checkResult = checkCommand(command);
if (!checkResult)
- return Result::Error(checkResult.error());
+ return ResultError(checkResult.error());
}
const static QByteArray shellScriptBase64 = FilePath(":/utils/scripts/deviceshell.sh")
@@ -279,16 +279,16 @@ Result DeviceShell::installShellScript()
while (m_shellScriptState == State::Unknown) {
if (!m_shellProcess->waitForReadyRead(5s))
- return Result::Error(Tr::tr("Timeout while waiting for shell script installation."));
+ return ResultError(Tr::tr("Timeout while waiting for shell script installation."));
QByteArray out = m_shellProcess->readAllRawStandardError();
if (out.contains("SCRIPT_INSTALLED") && !out.contains("ERROR_INSTALL_SCRIPT")) {
m_shellScriptState = State::Succeeded;
- return Result::Ok;
+ return ResultOk;
}
if (out.contains("ERROR_INSTALL_SCRIPT")) {
m_shellScriptState = State::Failed;
- return Result::Error(
+ return ResultError(
Tr::tr("Failed to install shell script: %1").arg(QString::fromUtf8(out)));
}
if (!out.isEmpty()) {
@@ -297,7 +297,7 @@ Result DeviceShell::installShellScript()
}
}
- return Result::Ok;
+ return ResultOk;
}
void DeviceShell::closeShellProcess()
diff --git a/src/libs/utils/deviceshell.h b/src/libs/utils/deviceshell.h
index 41aadc2624e..08f361c462b 100644
--- a/src/libs/utils/deviceshell.h
+++ b/src/libs/utils/deviceshell.h
@@ -38,7 +38,7 @@ public:
DeviceShell(bool forceFailScriptInstallation = false);
virtual ~DeviceShell();
- Result start();
+ Result<> start();
RunResult runInShell(const CommandLine &cmd, const QByteArray &stdInData = {});
@@ -58,7 +58,7 @@ private:
virtual void setupShellProcess(Process *shellProcess);
virtual CommandLine createFallbackCommand(const CommandLine &cmdLine);
- Result installShellScript();
+ Result<> installShellScript();
void closeShellProcess();
void onReadyRead();
diff --git a/src/libs/utils/filepath.cpp b/src/libs/utils/filepath.cpp
index 837dcb68aa4..2739e86cd20 100644
--- a/src/libs/utils/filepath.cpp
+++ b/src/libs/utils/filepath.cpp
@@ -621,7 +621,7 @@ void FilePath::setParts(const QStringView scheme, const QStringView host, QStrin
\sa createDir()
*/
-Result FilePath::ensureWritableDir() const
+Result<> FilePath::ensureWritableDir() const
{
return fileAccess()->ensureWritableDirectory(*this);
}
@@ -2020,7 +2020,7 @@ OsType FilePath::osType() const
return deviceFileHooks().osType(*this);
}
-Result FilePath::removeFile() const
+Result<> FilePath::removeFile() const
{
return fileAccess()->removeFile(*this);
}
@@ -2028,23 +2028,23 @@ Result FilePath::removeFile() const
/*!
Removes the directory this filePath refers too and its subdirectories recursively.
*/
-Result FilePath::removeRecursively() const
+Result<> FilePath::removeRecursively() const
{
return fileAccess()->removeRecursively(*this);
}
-Result FilePath::copyRecursively(const FilePath &target) const
+Result<> FilePath::copyRecursively(const FilePath &target) const
{
return fileAccess()->copyRecursively(*this, target);
}
-Result FilePath::copyFile(const FilePath &target) const
+Result<> FilePath::copyFile(const FilePath &target) const
{
if (!isSameDevice(target)) {
// FIXME: This does not scale.
const expected_str<QByteArray> contents = fileContents();
if (!contents) {
- return Result::Error(
+ return ResultError(
Tr::tr("Error while trying to copy file: %1").arg(contents.error()));
}
@@ -2052,37 +2052,37 @@ Result FilePath::copyFile(const FilePath &target) const
const expected_str<qint64> copyResult = target.writeFileContents(*contents);
if (!copyResult)
- return Result::Error(Tr::tr("Could not copy file: %1").arg(copyResult.error()));
+ return ResultError(Tr::tr("Could not copy file: %1").arg(copyResult.error()));
if (!target.setPermissions(perms)) {
target.removeFile();
- return Result::Error(
+ return ResultError(
Tr::tr("Could not set permissions on \"%1\"").arg(target.toUrlishString()));
}
- return Result::Ok;
+ return ResultOk;
}
return fileAccess()->copyFile(*this, target);
}
-Result FilePath::renameFile(const FilePath &target) const
+Result<> FilePath::renameFile(const FilePath &target) const
{
if (isSameDevice(target))
return fileAccess()->renameFile(*this, target);
- const Result copyResult = copyFile(target);
+ const Result<> copyResult = copyFile(target);
if (!copyResult)
return copyResult;
- const Result removeResult = removeFile();
+ const Result<> removeResult = removeFile();
if (removeResult)
- return Result::Ok;
+ return ResultOk;
// If we fail to remove the source file, we remove the target file to return to the
// original state.
- Result rmResult = target.removeFile();
+ Result<> rmResult = target.removeFile();
QTC_CHECK_EXPECTED(rmResult);
- return Result::Error(
+ return ResultError(
Tr::tr("Failed to move %1 to %2. Removing the source file failed: %3")
.arg(toUserOutput())
.arg(target.toUserOutput())
diff --git a/src/libs/utils/filepath.h b/src/libs/utils/filepath.h
index 63b0334b076..c2ca4231f1f 100644
--- a/src/libs/utils/filepath.h
+++ b/src/libs/utils/filepath.h
@@ -155,7 +155,7 @@ public:
bool isWritableDir() const;
bool isWritableFile() const;
- Result ensureWritableDir() const;
+ Result<> ensureWritableDir() const;
bool ensureExistingFile() const;
bool isExecutableFile() const;
bool isReadableFile() const;
@@ -173,11 +173,11 @@ public:
QFile::Permissions permissions() const;
bool setPermissions(QFile::Permissions permissions) const;
OsType osType() const;
- Result removeFile() const;
- Result removeRecursively() const;
- Result copyRecursively(const FilePath &target) const;
- Result copyFile(const FilePath &target) const;
- Result renameFile(const FilePath &target) const;
+ Result<> removeFile() const;
+ Result<> removeRecursively() const;
+ Result<> copyRecursively(const FilePath &target) const;
+ Result<> copyFile(const FilePath &target) const;
+ Result<> renameFile(const FilePath &target) const;
qint64 fileSize() const;
qint64 bytesAvailable() const;
bool createDir() const;
diff --git a/src/libs/utils/fileutils.cpp b/src/libs/utils/fileutils.cpp
index 513a0e4fbc8..1af77d40311 100644
--- a/src/libs/utils/fileutils.cpp
+++ b/src/libs/utils/fileutils.cpp
@@ -86,7 +86,7 @@ bool FileReader::fetch(const FilePath &filePath, QString *errorString)
// FileSaver
FileSaverBase::FileSaverBase()
- : m_result(Result::Ok)
+ : m_result(ResultOk)
{}
FileSaverBase::~FileSaverBase() = default;
@@ -96,7 +96,7 @@ bool FileSaverBase::finalize()
m_file->close();
setResult(m_file->error() == QFile::NoError);
m_file.reset();
- return m_result;
+ return m_result.has_value();
}
bool FileSaverBase::finalize(QString *errStr)
@@ -136,10 +136,10 @@ bool FileSaverBase::setResult(bool ok)
{
if (!ok && m_result) {
if (!m_file->errorString().isEmpty()) {
- m_result = Result::Error(Tr::tr("Cannot write file %1: %2")
+ m_result = ResultError(Tr::tr("Cannot write file %1: %2")
.arg(m_filePath.toUserOutput(), m_file->errorString()));
} else {
- m_result = Result::Error(Tr::tr("Cannot write file %1. Disk full?")
+ m_result = ResultError(Tr::tr("Cannot write file %1. Disk full?")
.arg(m_filePath.toUserOutput()));
}
}
@@ -210,7 +210,7 @@ FileSaver::FileSaver(const FilePath &filePath, QIODevice::OpenMode mode)
"LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9"};
const QString fn = filePath.baseName().toUpper();
if (reservedNames.contains(fn)) {
- m_result = Result::Error(Tr::tr("%1: Is a reserved filename on Windows. Cannot save.")
+ m_result = ResultError(Tr::tr("%1: Is a reserved filename on Windows. Cannot save.")
.arg(filePath.toUserOutput()));
return;
}
@@ -228,7 +228,7 @@ FileSaver::FileSaver(const FilePath &filePath, QIODevice::OpenMode mode)
if (!m_file->open(QIODevice::WriteOnly | mode)) {
QString err = filePath.exists() ?
Tr::tr("Cannot overwrite file %1: %2") : Tr::tr("Cannot create file %1: %2");
- m_result = Result::Error(err.arg(filePath.toUserOutput(), m_file->errorString()));
+ m_result = ResultError(err.arg(filePath.toUserOutput(), m_file->errorString()));
}
}
@@ -245,7 +245,7 @@ bool FileSaver::finalize()
setResult(sf->commit());
}
m_file.reset();
- return m_result;
+ return m_result.has_value();
}
TempFileSaver::TempFileSaver(const QString &templ)
@@ -261,7 +261,7 @@ void TempFileSaver::initFromString(const QString &templ)
tempFile->setFileTemplate(templ);
tempFile->setAutoRemove(false);
if (!tempFile->open()) {
- m_result = Result::Error(Tr::tr("Cannot create temporary file in %1: %2").arg(
+ m_result = ResultError(Tr::tr("Cannot create temporary file in %1: %2").arg(
QDir::toNativeSeparators(QFileInfo(tempFile->fileTemplate()).absolutePath()),
tempFile->errorString()));
}
@@ -275,14 +275,14 @@ TempFileSaver::TempFileSaver(const FilePath &templ)
} else {
expected_str<FilePath> result = templ.createTempFile();
if (!result) {
- m_result = Result::Error(Tr::tr("Cannot create temporary file %1: %2")
+ m_result = ResultError(Tr::tr("Cannot create temporary file %1: %2")
.arg(templ.toUserOutput(), result.error()));
return;
}
m_file.reset(new QFile(result->toFSPathString()));
if (!m_file->open(QIODevice::WriteOnly)) {
- m_result = Result::Error(Tr::tr("Cannot create temporary file %1: %2")
+ m_result = ResultError(Tr::tr("Cannot create temporary file %1: %2")
.arg(result->toUserOutput(), m_file->errorString()));
}
m_filePath = *result;
@@ -719,10 +719,10 @@ bool copyRecursively(const FilePath &srcFilePath,
Returns whether the operation succeeded.
*/
-Result copyIfDifferent(const FilePath &srcFilePath, const FilePath &tgtFilePath)
+Result<> copyIfDifferent(const FilePath &srcFilePath, const FilePath &tgtFilePath)
{
if (!srcFilePath.exists())
- return Result::Error(Tr::tr("File %1 does not exist.").arg(srcFilePath.toUserOutput()));
+ return ResultError(Tr::tr("File %1 does not exist.").arg(srcFilePath.toUserOutput()));
if (!srcFilePath.isLocal() || !tgtFilePath.isLocal())
return srcFilePath.copyFile(tgtFilePath);
@@ -735,10 +735,10 @@ Result copyIfDifferent(const FilePath &srcFilePath, const FilePath &tgtFilePath)
const expected_str<QByteArray> srcContents = srcFilePath.fileContents();
const expected_str<QByteArray> tgtContents = tgtFilePath.fileContents();
if (srcContents && srcContents == tgtContents)
- return Result::Ok;
+ return ResultOk;
}
- if (Result res = tgtFilePath.removeFile(); !res)
+ if (Result<> res = tgtFilePath.removeFile(); !res)
return res;
}
diff --git a/src/libs/utils/fileutils.h b/src/libs/utils/fileutils.h
index a490349e4f5..a48307bdbfe 100644
--- a/src/libs/utils/fileutils.h
+++ b/src/libs/utils/fileutils.h
@@ -55,8 +55,8 @@ QTCREATOR_UTILS_EXPORT bool copyRecursively(
QString *error,
CopyHelper helper);
-QTCREATOR_UTILS_EXPORT Result copyIfDifferent(const FilePath &srcFilePath,
- const FilePath &tgtFilePath);
+QTCREATOR_UTILS_EXPORT Result<> copyIfDifferent(const FilePath &srcFilePath,
+ const FilePath &tgtFilePath);
QTCREATOR_UTILS_EXPORT QString fileSystemFriendlyName(const QString &name);
QTCREATOR_UTILS_EXPORT int indexOfQmakeUnfriendly(const QString &name, int startpos = 0);
QTCREATOR_UTILS_EXPORT QString qmakeFriendlyName(const QString &name);
@@ -180,7 +180,7 @@ public:
protected:
std::unique_ptr<QFile> m_file;
FilePath m_filePath;
- Result m_result;
+ Result<> m_result;
private:
Q_DISABLE_COPY(FileSaverBase)
diff --git a/src/libs/utils/fsengine/fsenginehandler.cpp b/src/libs/utils/fsengine/fsenginehandler.cpp
index 8242cadc2ce..356dfd04953 100644
--- a/src/libs/utils/fsengine/fsenginehandler.cpp
+++ b/src/libs/utils/fsengine/fsenginehandler.cpp
@@ -212,15 +212,15 @@ bool FSEngineImpl::isSequential() const
bool FSEngineImpl::remove()
{
- Result result = m_filePath.removeRecursively();
+ Result<> result = m_filePath.removeRecursively();
if (!result)
setError(QFile::RemoveError, result.error());
- return result;
+ return result.has_value();
}
bool FSEngineImpl::copy(const QString &newName)
{
- Result result = m_filePath.copyFile(FilePath::fromString(newName));
+ Result<> result = m_filePath.copyFile(FilePath::fromString(newName));
if (!result)
setError(QFile::CopyError, result.error());
return bool(result);
@@ -228,7 +228,7 @@ bool FSEngineImpl::copy(const QString &newName)
bool FSEngineImpl::rename(const QString &newName)
{
- Result result = m_filePath.renameFile(FilePath::fromString(newName));
+ Result<> result = m_filePath.renameFile(FilePath::fromString(newName));
if (!result)
setError(QFile::RenameError, result.error());
return bool(result);
@@ -258,7 +258,7 @@ bool FSEngineImpl::rmdir(const QString &dirName, bool recurseParentDirectories)
if (recurseParentDirectories)
return false;
- return m_filePath.pathAppended(dirName).removeRecursively();
+ return m_filePath.pathAppended(dirName).removeRecursively().has_value();
}
bool FSEngineImpl::setSize(qint64 size)
diff --git a/src/libs/utils/persistentsettings.cpp b/src/libs/utils/persistentsettings.cpp
index 8fc57954ae1..3e4d0741528 100644
--- a/src/libs/utils/persistentsettings.cpp
+++ b/src/libs/utils/persistentsettings.cpp
@@ -382,12 +382,12 @@ PersistentSettingsWriter::PersistentSettingsWriter(const FilePath &fileName, con
m_fileName(fileName), m_docType(docType)
{ }
-Result PersistentSettingsWriter::save(const Store &data, [[maybe_unused]] bool showErrorInMessageBox) const
+Result<> PersistentSettingsWriter::save(const Store &data, [[maybe_unused]] bool showErrorInMessageBox) const
{
if (data == m_savedData)
- return Result::Ok;
+ return ResultOk;
- const Result res = write(data);
+ const Result<> res = write(data);
#ifdef QT_GUI_LIB
if (showErrorInMessageBox && !res)
@@ -406,7 +406,7 @@ void PersistentSettingsWriter::setContents(const Store &data)
m_savedData = data;
}
-Result PersistentSettingsWriter::write(const Store &data) const
+Result<> PersistentSettingsWriter::write(const Store &data) const
{
m_fileName.parentDir().ensureWritableDir();
FileSaver saver(m_fileName, QIODevice::Text);
@@ -435,11 +435,11 @@ Result PersistentSettingsWriter::write(const Store &data) const
if (!saver.finalize()) {
m_savedData.clear();
- return Result::Error(saver.errorString());
+ return ResultError(saver.errorString());
}
m_savedData = data;
- return Result::Ok;
+ return ResultOk;
}
} // namespace Utils
diff --git a/src/libs/utils/persistentsettings.h b/src/libs/utils/persistentsettings.h
index 1ebb0e8bed3..01ddafc23bf 100644
--- a/src/libs/utils/persistentsettings.h
+++ b/src/libs/utils/persistentsettings.h
@@ -6,12 +6,11 @@
#include "utils_global.h"
#include "filepath.h"
+#include "result.h"
#include "store.h"
namespace Utils {
-class Result;
-
class QTCREATOR_UTILS_EXPORT PersistentSettingsReader
{
public:
@@ -31,14 +30,14 @@ class QTCREATOR_UTILS_EXPORT PersistentSettingsWriter
public:
PersistentSettingsWriter(const FilePath &fileName, const QString &docType);
- Result save(const Store &data, bool showError = true) const;
+ Result<> save(const Store &data, bool showError = true) const;
FilePath fileName() const;
void setContents(const Store &data);
private:
- Result write(const Store &data) const;
+ Result<> write(const Store &data) const;
const FilePath m_fileName;
const QString m_docType;
diff --git a/src/libs/utils/result.cpp b/src/libs/utils/result.cpp
index 222c70bdf80..3da594431e1 100644
--- a/src/libs/utils/result.cpp
+++ b/src/libs/utils/result.cpp
@@ -7,36 +7,24 @@
namespace Utils {
-const Result Result::Ok;
+const Result<> ResultOk;
-Result::Result(bool success, const QString &errorString)
-{
- if (!success)
- m_error = errorString;
-}
-
-Result::Result(const expected_str<void> &res)
-{
- if (!res)
- m_error = res.error();
-}
-
-Result::~Result() = default;
+ResultError::ResultError(const QString &errorMessage)
+ : m_error(errorMessage)
+{}
-Result Result::Error(const QString &errorString)
-{
- return Result(errorString);
-}
+ResultError::ResultError(ResultUnimplementedType)
+ : m_error(Tr::tr("Not implemented"))
+{}
+ResultError::ResultError(ResultAssertType, const QString &errorMessage)
+ : m_error(Tr::tr("Internal error: %1").arg(errorMessage))
+{}
-Result Result::Error(SpecialError specialError)
+Result<> makeResult(bool ok, const QString &errorMessage)
{
- switch (specialError) {
- case Unimplemented:
- return Error(Tr::tr("Not implemented"));
- case Assert:
- return Error(Tr::tr("Internal error"));
- }
- return Error(Tr::tr("Internal error"));
+ if (ok)
+ return ResultOk;
+ return tl::make_unexpected(errorMessage);
}
} // Utils
diff --git a/src/libs/utils/result.h b/src/libs/utils/result.h
index 079bf2bd00a..86892592dde 100644
--- a/src/libs/utils/result.h
+++ b/src/libs/utils/result.h
@@ -11,31 +11,26 @@
namespace Utils {
-class QTCREATOR_UTILS_EXPORT Result
-{
- Result() = default;
- explicit Result(const std::optional<QString> &err) : m_error(err) {}
+template<typename T = void>
+using Result = Utils::expected<T, QString>;
-public:
- Result(bool success, const QString &errorString);
- Result(const expected_str<void> &res);
- Result(const Result &) = default;
- Result(Result &&) = default;
- ~Result();
+QTCREATOR_UTILS_EXPORT extern const Result<> ResultOk;
- Result &operator=(const Result &) = default;
- Result &operator=(Result &&) = default;
+QTCREATOR_UTILS_EXPORT Result<> makeResult(bool ok, const QString &errorMessage);
- enum SpecialError { Unimplemented, Assert };
- static const Result Ok;
- static Result Error(const QString &errorString);
- static Result Error(SpecialError specialError);
+enum ResultUnimplementedType { ResultUnimplemented };
+enum ResultAssertType { ResultAssert };
- QString error() const { return m_error ? *m_error : QString(); }
- operator bool() const { return !m_error; }
+class QTCREATOR_UTILS_EXPORT ResultError
+{
+public:
+ ResultError(const QString &errorMessage);
+ ResultError(ResultUnimplementedType);
+ ResultError(ResultAssertType, const QString &errorMessage = {});
+ template<typename T> operator Result<T>() { return tl::make_unexpected(m_error); }
private:
- std::optional<QString> m_error;
+ QString m_error;
};
#define QTC_ASSERT_AND_ERROR_OUT(cond) \
diff --git a/src/libs/utils/savefile.cpp b/src/libs/utils/savefile.cpp
index 49bc4e40560..9f67fd1f362 100644
--- a/src/libs/utils/savefile.cpp
+++ b/src/libs/utils/savefile.cpp
@@ -197,7 +197,7 @@ bool SaveFile::commit()
}
}
- Result renameResult = m_tempFile->filePath().renameFile(finalFileName);
+ Result<> renameResult = m_tempFile->filePath().renameFile(finalFileName);
if (!renameResult) {
// The case when someone else was able to create finalFileName after we've renamed it.
// Higher level call may try to save this file again but here we do nothing and
diff --git a/src/libs/utils/settingsaccessor.cpp b/src/libs/utils/settingsaccessor.cpp
index d9dda00249f..18e21fda655 100644
--- a/src/libs/utils/settingsaccessor.cpp
+++ b/src/libs/utils/settingsaccessor.cpp
@@ -145,7 +145,7 @@ std::optional<SettingsAccessor::Issue> SettingsAccessor::writeFile(const FilePat
if (!m_readOnly && (!m_writer || m_writer->fileName() != path))
m_writer = std::make_unique<PersistentSettingsWriter>(path, m_docType);
- const Result res = m_writer->save(data, false);
+ const Result<> res = m_writer->save(data, false);
if (!res)
return Issue(Tr::tr("Failed to Write File"), res.error(), Issue::Type::ERROR);
diff --git a/src/libs/utils/textfileformat.cpp b/src/libs/utils/textfileformat.cpp
index d913b921604..e363b275c43 100644
--- a/src/libs/utils/textfileformat.cpp
+++ b/src/libs/utils/textfileformat.cpp
@@ -333,9 +333,9 @@ TextFileFormat::readFile(const FilePath &filePath, const QTextCodec *defaultCode
returns an error message, \a errorString.
*/
-Result TextFileFormat::writeFile(const FilePath &filePath, QString plainText) const
+Result<> TextFileFormat::writeFile(const FilePath &filePath, QString plainText) const
{
- QTC_ASSERT(m_codec, return Result::Error("No codec"));
+ QTC_ASSERT(m_codec, return ResultError("No codec"));
// Does the user want CRLF? If that is native,
// do not let QFile do the work, because it replaces the line ending after the text was encoded,
@@ -356,7 +356,7 @@ Result TextFileFormat::writeFile(const FilePath &filePath, QString plainText) co
if (debug)
qDebug().nospace() << Q_FUNC_INFO << filePath << ' ' << *this << ' ' << plainText.size()
<< " bytes, returns " << ok;
- return ok ? Result::Ok : Result::Error(errorString);
+ return ok ? ResultOk : ResultError(errorString);
}
} // namespace Utils
diff --git a/src/libs/utils/textfileformat.h b/src/libs/utils/textfileformat.h
index ec4ef67efa5..4b83cf4f6c3 100644
--- a/src/libs/utils/textfileformat.h
+++ b/src/libs/utils/textfileformat.h
@@ -3,10 +3,11 @@
#pragma once
-#include "expected.h"
+#include "result.h"
#include "utils_global.h"
#include <QStringList>
+
#include <utility>
QT_BEGIN_NAMESPACE
@@ -17,7 +18,6 @@ QT_END_NAMESPACE
namespace Utils {
class FilePath;
-class Result;
class QTCREATOR_UTILS_EXPORT TextFileFormat
{
@@ -60,7 +60,7 @@ public:
static tl::expected<QString, std::pair<ReadResult, QString>>
readFile(const FilePath &filePath, const QTextCodec *defaultCodec);
- Utils::Result writeFile(const FilePath &filePath, QString plainText) const;
+ Utils::Result<> writeFile(const FilePath &filePath, QString plainText) const;
static QByteArray decodingErrorSample(const QByteArray &data);
diff --git a/src/libs/utils/unarchiver.cpp b/src/libs/utils/unarchiver.cpp
index f11ef33ac39..f44d317ccfe 100644
--- a/src/libs/utils/unarchiver.cpp
+++ b/src/libs/utils/unarchiver.cpp
@@ -15,7 +15,7 @@ using namespace Tasking;
namespace Utils {
-static Result copy_data(struct archive *ar, struct archive *aw, QPromise<Result> &promise)
+static Result<> copy_data(struct archive *ar, struct archive *aw, QPromise<Result<>> &promise)
{
int r;
const void *buff;
@@ -27,12 +27,12 @@ static Result copy_data(struct archive *ar, struct archive *aw, QPromise<Result>
if (r == ARCHIVE_EOF)
break;
if (r < ARCHIVE_OK)
- return Result::Error(QString::fromUtf8(archive_error_string(ar)));
+ return ResultError(QString::fromUtf8(archive_error_string(ar)));
r = archive_write_data_block(aw, buff, size, offset);
if (r < ARCHIVE_OK)
- return Result::Error(QString::fromUtf8(archive_error_string(aw)));
+ return ResultError(QString::fromUtf8(archive_error_string(aw)));
}
- return Result::Ok;
+ return ResultOk;
}
static void readFree(struct archive *a)
@@ -109,8 +109,8 @@ static int64_t _seek(struct archive *a, void *client_data, int64_t request, int
return data->file.pos();
}
-static Result unarchive(
- QPromise<Result> &promise, const Utils::FilePath &archive, const Utils::FilePath &destination)
+static Result<> unarchive(
+ QPromise<Result<>> &promise, const Utils::FilePath &archive, const Utils::FilePath &destination)
{
struct archive_entry *entry;
int flags;
@@ -128,7 +128,7 @@ static Result unarchive(
if (archive_read_support_format_all(a.get()) != ARCHIVE_OK
|| archive_read_support_format_raw(a.get()) != ARCHIVE_OK
|| archive_read_support_filter_all(a.get()) != ARCHIVE_OK) {
- return Result::Error(QString("archive_read_ setup failed: %1")
+ return ResultError(QString("archive_read_ setup failed: %1")
.arg(QString::fromUtf8(archive_error_string(a.get()))));
}
@@ -136,12 +136,12 @@ static Result unarchive(
if (archive_write_disk_set_options(ext.get(), flags) != ARCHIVE_OK
|| archive_write_disk_set_standard_lookup(ext.get()) != ARCHIVE_OK) {
- return Result::Error(QString("archive_write_disk_ setup failed: %1")
+ return ResultError(QString("archive_write_disk_ setup failed: %1")
.arg(QString::fromUtf8(archive_error_string(ext.get()))));
}
if (archive_read_append_callback_data(a.get(), &data) != (ARCHIVE_OK))
- return Result::Error(
+ return ResultError(
QString("Could not append callback data to %1").arg(archive.toUserOutput()));
if (archive_read_set_open_callback(a.get(), _open) != ARCHIVE_OK
@@ -149,12 +149,12 @@ static Result unarchive(
|| archive_read_set_skip_callback(a.get(), _skip) != ARCHIVE_OK
|| archive_read_set_seek_callback(a.get(), _seek) != ARCHIVE_OK
|| archive_read_set_close_callback(a.get(), _close)) {
- return Result::Error(QString("Could not set callbacks: %1")
+ return ResultError(QString("Could not set callbacks: %1")
.arg(QString::fromUtf8(archive_error_string(a.get()))));
}
if ((r = archive_read_open1(a.get())))
- return Result::Error(QString::fromUtf8(archive_error_string(a.get())));
+ return ResultError(QString::fromUtf8(archive_error_string(a.get())));
int fileNumber = 0;
while (!promise.isCanceled()) {
@@ -164,13 +164,13 @@ static Result unarchive(
const int filter = archive_filter_code(a.get(), 0);
if (format == ARCHIVE_FORMAT_RAW && filter == ARCHIVE_FILTER_NONE)
- return Result::Error(Tr::tr("Not an archive"));
+ return ResultError(Tr::tr("Not an archive"));
if (r == ARCHIVE_EOF)
break;
if (r < ARCHIVE_OK) {
- return Result::Error(QString::fromUtf8(archive_error_string(a.get())));
+ return ResultError(QString::fromUtf8(archive_error_string(a.get())));
}
++fileNumber;
@@ -184,27 +184,27 @@ static Result unarchive(
r = archive_write_header(ext.get(), entry);
if (r < ARCHIVE_OK) {
- return Result::Error(QString::fromUtf8(archive_error_string(ext.get())));
+ return ResultError(QString::fromUtf8(archive_error_string(ext.get())));
} else {
const struct stat *stat = archive_entry_stat(entry);
// Is regular file ? (See S_ISREG macro in stat.h)
if ((((stat->st_mode) & 0170000) == 0100000)) {
- r = copy_data(a.get(), ext.get(), promise);
+ r = copy_data(a.get(), ext.get(), promise).has_value();
if (r < ARCHIVE_OK) {
- return Result::Error(QString::fromUtf8(archive_error_string(ext.get())));
+ return ResultError(QString::fromUtf8(archive_error_string(ext.get())));
}
}
}
r = archive_write_finish_entry(ext.get());
if (r < ARCHIVE_OK) {
- return Result::Error(QString::fromUtf8(archive_error_string(ext.get())));
+ return ResultError(QString::fromUtf8(archive_error_string(ext.get())));
}
}
- return Result::Ok;
+ return ResultOk;
}
static void unarchivePromised(
- QPromise<Result> &promise, const Utils::FilePath &archive, const Utils::FilePath &destination)
+ QPromise<Result<>> &promise, const Utils::FilePath &archive, const Utils::FilePath &destination)
{
promise.addResult(unarchive(promise, archive, destination));
}
@@ -218,7 +218,7 @@ Unarchiver::Unarchiver()
emit progress(FilePath::fromString(text));
});
connect(&m_async, &AsyncBase::done, this, [this] {
- Result result = m_async.isCanceled() ? Result::Error({}) : m_async.result();
+ Result<> result = m_async.isCanceled() ? ResultError(QString()) : m_async.result();
emit done(result ? DoneResult::Success : DoneResult::Error);
});
}
@@ -229,10 +229,10 @@ void Unarchiver::start()
m_async.start();
}
-Result Unarchiver::result() const
+Result<> Unarchiver::result() const
{
if (m_async.isCanceled())
- return Result::Error(Tr::tr("Canceled"));
+ return ResultError(Tr::tr("Canceled"));
return m_async.result();
}
diff --git a/src/libs/utils/unarchiver.h b/src/libs/utils/unarchiver.h
index 5661aaa503d..5aff2407707 100644
--- a/src/libs/utils/unarchiver.h
+++ b/src/libs/utils/unarchiver.h
@@ -22,7 +22,7 @@ public:
void setArchive(const FilePath &archive);
void setDestination(const FilePath &destination);
- Result result() const;
+ Result<> result() const;
void start();
@@ -35,7 +35,7 @@ signals:
void progress(const FilePath &path);
private:
- Async<Result> m_async;
+ Async<Result<>> m_async;
FilePath m_archive;
FilePath m_destination;
diff --git a/src/plugins/android/androidbuildapkstep.cpp b/src/plugins/android/androidbuildapkstep.cpp
index 0a7a9d03c2e..5d0bf2b5d11 100644
--- a/src/plugins/android/androidbuildapkstep.cpp
+++ b/src/plugins/android/androidbuildapkstep.cpp
@@ -892,7 +892,7 @@ static bool copyFileIfNewer(const FilePath &sourceFilePath, const FilePath &dest
if (!destinationFilePath.parentDir().ensureWritableDir())
return false;
- Result result = sourceFilePath.copyFile(destinationFilePath);
+ Result<> result = sourceFilePath.copyFile(destinationFilePath);
QTC_ASSERT_EXPECTED(result, return false);
return true;
}
diff --git a/src/plugins/android/androidmanifesteditor.cpp b/src/plugins/android/androidmanifesteditor.cpp
index 15bc23eb47a..2f03b622e6f 100644
--- a/src/plugins/android/androidmanifesteditor.cpp
+++ b/src/plugins/android/androidmanifesteditor.cpp
@@ -1883,10 +1883,10 @@ private:
bool isSaveAsAllowed() const override { return false; }
- Result saveImpl(const FilePath &filePath, bool autoSave) override
+ Result<> saveImpl(const FilePath &filePath, bool autoSave) override
{
m_editorWidget->preSave();
- Result result = TextDocument::saveImpl(filePath, autoSave);
+ Result<> result = TextDocument::saveImpl(filePath, autoSave);
m_editorWidget->postSave();
return result;
}
diff --git a/src/plugins/android/androidpackageinstallationstep.cpp b/src/plugins/android/androidpackageinstallationstep.cpp
index a3672f4425a..9d3f2df2ec7 100644
--- a/src/plugins/android/androidpackageinstallationstep.cpp
+++ b/src/plugins/android/androidpackageinstallationstep.cpp
@@ -135,7 +135,7 @@ Tasking::GroupItem AndroidPackageInstallationStep::runRecipe()
const FilePath androidDir = FilePath::fromString(dir);
if (!dir.isEmpty() && androidDir.exists()) {
emit addOutput(Tr::tr("Removing directory %1").arg(dir), OutputFormat::NormalMessage);
- const Result result = androidDir.removeRecursively();
+ const Result<> result = androidDir.removeRecursively();
if (!result) {
reportWarningOrError(
Tr::tr("Failed to clean \"%1\" from the previous build, "
diff --git a/src/plugins/android/androidsdkdownloader.cpp b/src/plugins/android/androidsdkdownloader.cpp
index e113381a341..c4bae112da8 100644
--- a/src/plugins/android/androidsdkdownloader.cpp
+++ b/src/plugins/android/androidsdkdownloader.cpp
@@ -178,7 +178,7 @@ GroupItem downloadSdkRecipe()
if (result == DoneWith::Cancel)
return;
- const Result unarchiveResult = task.result();
+ const Result<> unarchiveResult = task.result();
if (!unarchiveResult) {
logError(Tr::tr("Unarchiving error: %1").arg(unarchiveResult.error()));
diff --git a/src/plugins/android/androidsignaloperation.cpp b/src/plugins/android/androidsignaloperation.cpp
index 247e90d7fb9..81d2fc1d363 100644
--- a/src/plugins/android/androidsignaloperation.cpp
+++ b/src/plugins/android/androidsignaloperation.cpp
@@ -20,7 +20,7 @@ void AndroidSignalOperation::signalOperationViaADB(qint64 pid, int signal)
struct InternalStorage {
FilePath adbPath = AndroidConfig::adbToolPath();
QString runAs = {};
- Result result = Result::Ok;
+ Result<> result = ResultOk;
};
const Storage<InternalStorage> storage;
@@ -33,15 +33,15 @@ void AndroidSignalOperation::signalOperationViaADB(qint64 pid, int signal)
storage->runAs = process.stdOut();
if (!storage->runAs.isEmpty())
return true;
- storage->result = Result::Error("Cannot find User for process: " + QString::number(pid));
+ storage->result = ResultError("Cannot find User for process: " + QString::number(pid));
} else if (result == DoneWith::Error) {
QString result = " adb process exit code: " + QString::number(process.exitCode());
const QString adbError = process.errorString();
if (!adbError.isEmpty())
result += " adb process error: " + adbError;
- storage->result = Result::Error(result);
+ storage->result = ResultError(result);
} else {
- storage->result = Result::Error("adb process timed out");
+ storage->result = ResultError("adb process timed out");
}
return false;
};
@@ -52,10 +52,10 @@ void AndroidSignalOperation::signalOperationViaADB(qint64 pid, int signal)
};
const auto onKillDone = [storage, pid](const Process &process, DoneWith result) {
if (result == DoneWith::Error) {
- storage->result = Result::Error("Cannot kill process: " + QString::number(pid)
+ storage->result = ResultError("Cannot kill process: " + QString::number(pid)
+ process.stdErr());
} else if (result == DoneWith::Cancel) {
- storage->result = Result::Error("adb process timed out");
+ storage->result = ResultError("adb process timed out");
}
};
@@ -78,7 +78,7 @@ void AndroidSignalOperation::killProcess(qint64 pid)
void AndroidSignalOperation::killProcess(const QString &filePath)
{
Q_UNUSED(filePath)
- emit finished(Result::Error("The android signal operation does not support killing by filepath."));
+ emit finished(ResultError("The android signal operation does not support killing by filepath."));
}
void AndroidSignalOperation::interruptProcess(qint64 pid)
diff --git a/src/plugins/baremetal/baremetaldebugsupport.cpp b/src/plugins/baremetal/baremetaldebugsupport.cpp
index cd021db7bc5..085e068ac68 100644
--- a/src/plugins/baremetal/baremetaldebugsupport.cpp
+++ b/src/plugins/baremetal/baremetaldebugsupport.cpp
@@ -58,7 +58,7 @@ public:
if (RunWorker *runner = p->targetRunner(runControl))
debugger->addStartDependency(runner);
- if (Result res = p->setupDebuggerRunParameters(debugger->runParameters(), runControl); !res)
+ if (Result<> res = p->setupDebuggerRunParameters(debugger->runParameters(), runControl); !res)
debugger->reportFailure(res.error()); // TODO: reportFailure won't work from RunWorker's c'tor.
return debugger;
diff --git a/src/plugins/baremetal/debugservers/gdb/gdbserverprovider.cpp b/src/plugins/baremetal/debugservers/gdb/gdbserverprovider.cpp
index 1cca5f7e6eb..cb1c2d85cbe 100644
--- a/src/plugins/baremetal/debugservers/gdb/gdbserverprovider.cpp
+++ b/src/plugins/baremetal/debugservers/gdb/gdbserverprovider.cpp
@@ -127,17 +127,17 @@ bool GdbServerProvider::isValid() const
return !channelString().isEmpty();
}
-Result GdbServerProvider::setupDebuggerRunParameters(DebuggerRunParameters &rp,
+Result<> GdbServerProvider::setupDebuggerRunParameters(DebuggerRunParameters &rp,
RunControl *runControl) const
{
Q_UNUSED(runControl)
const CommandLine cmd = rp.inferior().command;
const FilePath bin = FilePath::fromString(cmd.executable().path());
if (bin.isEmpty()) {
- return Result::Error(Tr::tr("Cannot debug: Local executable is not set."));
+ return ResultError(Tr::tr("Cannot debug: Local executable is not set."));
}
if (!bin.exists()) {
- return Result::Error(Tr::tr("Cannot debug: Could not find executable for \"%1\".")
+ return ResultError(Tr::tr("Cannot debug: Could not find executable for \"%1\".")
.arg(bin.toUserOutput()));
}
@@ -153,7 +153,7 @@ Result GdbServerProvider::setupDebuggerRunParameters(DebuggerRunParameters &rp,
rp.setUseContinueInsteadOfRun(true);
rp.setUseExtendedRemote(useExtendedRemote());
rp.setPeripheralDescriptionFile(m_peripheralDescriptionFile);
- return Result::Ok;
+ return ResultOk;
}
RunWorker *GdbServerProvider::targetRunner(RunControl *runControl) const
diff --git a/src/plugins/baremetal/debugservers/gdb/gdbserverprovider.h b/src/plugins/baremetal/debugservers/gdb/gdbserverprovider.h
index 110831a4c48..8ce041a6cc1 100644
--- a/src/plugins/baremetal/debugservers/gdb/gdbserverprovider.h
+++ b/src/plugins/baremetal/debugservers/gdb/gdbserverprovider.h
@@ -37,7 +37,7 @@ public:
virtual Utils::CommandLine command() const;
- Utils::Result setupDebuggerRunParameters(Debugger::DebuggerRunParameters &rp,
+ Utils::Result<> setupDebuggerRunParameters(Debugger::DebuggerRunParameters &rp,
ProjectExplorer::RunControl *runControl) const final;
ProjectExplorer::RunWorker *targetRunner(
ProjectExplorer::RunControl *runControl) const override;
diff --git a/src/plugins/baremetal/debugservers/uvsc/uvscserverprovider.cpp b/src/plugins/baremetal/debugservers/uvsc/uvscserverprovider.cpp
index 41a767c8649..8bc4385c628 100644
--- a/src/plugins/baremetal/debugservers/uvsc/uvscserverprovider.cpp
+++ b/src/plugins/baremetal/debugservers/uvsc/uvscserverprovider.cpp
@@ -159,25 +159,25 @@ QString UvscServerProvider::channelString() const
return m_channel.toString();
}
-Result UvscServerProvider::setupDebuggerRunParameters(DebuggerRunParameters &rp,
+Result<> UvscServerProvider::setupDebuggerRunParameters(DebuggerRunParameters &rp,
RunControl *runControl) const
{
const FilePath bin = rp.inferior().command.executable();
if (bin.isEmpty()) {
- return Result::Error(Tr::tr("Cannot debug: Local executable is not set."));
+ return ResultError(Tr::tr("Cannot debug: Local executable is not set."));
} else if (!bin.exists()) {
- return Result::Error(Tr::tr("Cannot debug: Could not find executable for \"%1\".")
+ return ResultError(Tr::tr("Cannot debug: Could not find executable for \"%1\".")
.arg(bin.toUserOutput()));
}
QString errorMessage;
const FilePath projFilePath = projectFilePath(runControl, errorMessage);
if (!projFilePath.exists())
- return Result::Error(errorMessage);
+ return ResultError(errorMessage);
const FilePath optFilePath = optionsFilePath(runControl, errorMessage);
if (!optFilePath.exists())
- return Result::Error(errorMessage);
+ return ResultError(errorMessage);
const FilePath peripheralDescriptionFile = FilePath::fromString(m_deviceSelection.svd);
@@ -192,7 +192,7 @@ Result UvscServerProvider::setupDebuggerRunParameters(DebuggerRunParameters &rp,
rp.setStartMode(AttachToRemoteServer);
rp.setRemoteChannel(channelString());
rp.setUseContinueInsteadOfRun(true);
- return Result::Ok;
+ return ResultOk;
}
ProjectExplorer::RunWorker *UvscServerProvider::targetRunner(RunControl *runControl) const
diff --git a/src/plugins/baremetal/debugservers/uvsc/uvscserverprovider.h b/src/plugins/baremetal/debugservers/uvsc/uvscserverprovider.h
index bd4a04c4183..61636cd0319 100644
--- a/src/plugins/baremetal/debugservers/uvsc/uvscserverprovider.h
+++ b/src/plugins/baremetal/debugservers/uvsc/uvscserverprovider.h
@@ -47,7 +47,7 @@ public:
void toMap(Utils::Store &map) const override;
- Utils::Result setupDebuggerRunParameters(Debugger::DebuggerRunParameters &rp,
+ Utils::Result<> setupDebuggerRunParameters(Debugger::DebuggerRunParameters &rp,
ProjectExplorer::RunControl *runControl) const final;
ProjectExplorer::RunWorker *targetRunner(ProjectExplorer::RunControl *runControl) const final;
diff --git a/src/plugins/baremetal/idebugserverprovider.h b/src/plugins/baremetal/idebugserverprovider.h
index 4f21d70d275..375e2021a35 100644
--- a/src/plugins/baremetal/idebugserverprovider.h
+++ b/src/plugins/baremetal/idebugserverprovider.h
@@ -9,6 +9,7 @@
#include <utils/filepath.h>
#include <utils/store.h>
+#include <utils/result.h>
#include <QSet>
#include <QUrl>
@@ -28,8 +29,6 @@ class RunControl;
class RunWorker;
}
-namespace Utils { class Result; }
-
namespace BareMetal::Internal {
class BareMetalDevice;
@@ -69,7 +68,7 @@ public:
virtual void toMap(Utils::Store &data) const;
virtual void fromMap(const Utils::Store &data);
- virtual Utils::Result setupDebuggerRunParameters(Debugger::DebuggerRunParameters &rp,
+ virtual Utils::Result<> setupDebuggerRunParameters(Debugger::DebuggerRunParameters &rp,
ProjectExplorer::RunControl *runControl) const = 0;
virtual ProjectExplorer::RunWorker *targetRunner(
ProjectExplorer::RunControl *runControl) const = 0;
diff --git a/src/plugins/bineditor/bineditorplugin.cpp b/src/plugins/bineditor/bineditorplugin.cpp
index b952c1e3ae3..d70aa77cdf7 100644
--- a/src/plugins/bineditor/bineditorplugin.cpp
+++ b/src/plugins/bineditor/bineditorplugin.cpp
@@ -119,8 +119,8 @@ public:
bool isSaveAsAllowed() const final { return true; }
- Utils::Result reload(ReloadFlag flag, ChangeType type) final;
- Utils::Result saveImpl(const Utils::FilePath &filePath, bool autoSave) final;
+ Utils::Result<> reload(ReloadFlag flag, ChangeType type) final;
+ Utils::Result<> saveImpl(const Utils::FilePath &filePath, bool autoSave) final;
void fetchData(quint64 address) const { if (m_fetchDataHandler) m_fetchDataHandler(address); }
void requestNewWindow(quint64 address) { if (m_newWindowRequestHandler) m_newWindowRequestHandler(address); }
@@ -156,7 +156,7 @@ public:
void addData(quint64 addr, const QByteArray &data);
void updateContents();
- Result save(const FilePath &oldFilePath, const FilePath &newFilePath);
+ Result<> save(const FilePath &oldFilePath, const FilePath &newFilePath);
void clear();
void undo();
@@ -614,7 +614,7 @@ void BinEditorDocument::setModified(bool modified)
emit changed();
}
-Result BinEditorDocument::save(const FilePath &oldFilePath, const FilePath &newFilePath)
+Result<> BinEditorDocument::save(const FilePath &oldFilePath, const FilePath &newFilePath)
{
if (oldFilePath != newFilePath) {
// Get a unique temporary file name
@@ -623,19 +623,19 @@ Result BinEditorDocument::save(const FilePath &oldFilePath, const FilePath &newF
const auto result = TemporaryFilePath::create(
newFilePath.stringAppended("_XXXXXX.new"));
if (!result)
- return Result::Error(result.error());
+ return ResultError(result.error());
tmpName = (*result)->filePath();
}
- if (Result res = oldFilePath.copyFile(tmpName); !res)
+ if (Result<> res = oldFilePath.copyFile(tmpName); !res)
return res;
if (newFilePath.exists()) {
- if (Result res = newFilePath.removeFile(); !res)
+ if (Result<> res = newFilePath.removeFile(); !res)
return res;
}
- if (Result res = tmpName.renameFile(newFilePath); !res)
+ if (Result<> res = tmpName.renameFile(newFilePath); !res)
return res;
}
@@ -661,10 +661,10 @@ Result BinEditorDocument::save(const FilePath &oldFilePath, const FilePath &newF
QString errorString;
if (!saver.finalize(&errorString))
- return Result::Error(errorString);
+ return ResultError(errorString);
setModified(false);
- return Result::Ok;
+ return ResultOk;
}
void BinEditorDocument::setSizes(quint64 startAddr, qint64 range, int blockSize)
@@ -2182,26 +2182,26 @@ bool BinEditorDocument::isModified() const
return m_undoStack.size() != m_unmodifiedState;
}
-Result BinEditorDocument::reload(ReloadFlag flag, ChangeType type)
+Result<> BinEditorDocument::reload(ReloadFlag flag, ChangeType type)
{
Q_UNUSED(type)
if (flag == FlagIgnore)
- return Result::Ok;
+ return ResultOk;
emit aboutToReload();
clear();
QString errorString;
const bool success = (openImpl(&errorString, filePath()) == OpenResult::Success);
emit reloadFinished(success);
- return Result(success, errorString);
+ return makeResult(success, errorString);
}
-Result BinEditorDocument::saveImpl(const FilePath &filePath, bool autoSave)
+Result<> BinEditorDocument::saveImpl(const FilePath &filePath, bool autoSave)
{
- QTC_ASSERT(!autoSave, return Result::Ok); // bineditor does not support autosave - it would be a bit expensive
- if (Result res = save(this->filePath(), filePath); !res)
+ QTC_ASSERT(!autoSave, return ResultOk); // bineditor does not support autosave - it would be a bit expensive
+ if (Result<> res = save(this->filePath(), filePath); !res)
return res;
setFilePath(filePath);
- return Result::Ok;
+ return ResultOk;
}
class BinEditorImpl final : public IEditor, public EditorService
diff --git a/src/plugins/clangcodemodel/test/clangdtests.cpp b/src/plugins/clangcodemodel/test/clangdtests.cpp
index 8a3072a47fd..45b4f33913e 100644
--- a/src/plugins/clangcodemodel/test/clangdtests.cpp
+++ b/src/plugins/clangcodemodel/test/clangdtests.cpp
@@ -1994,8 +1994,10 @@ void ClangdTestCompletion::testCompleteAfterProjectChange()
EditorManager::openEditor(project()->projectFilePath()));
QVERIFY(proFileEditor);
proFileEditor->insert("DEFINES += PROJECT_CONFIGURATION_1\n");
- const Result res = proFileEditor->document()->save();
- QVERIFY2(res, qPrintable(res.error()));
+ const Result<> res = proFileEditor->document()->save();
+ QVERIFY(res);
+ if (!res)
+ QVERIFY2(false, qPrintable(res.error()));
QVERIFY(waitForSignalOrTimeout(project(), &Project::anyParsingFinished, timeOutInMs()));
QVERIFY(waitForSignalOrTimeout(LanguageClientManager::instance(),
&LanguageClientManager::clientRemoved,
diff --git a/src/plugins/clangtools/clangfixitsrefactoringchanges.cpp b/src/plugins/clangtools/clangfixitsrefactoringchanges.cpp
index 7cebab6ba1a..d52f1233709 100644
--- a/src/plugins/clangtools/clangfixitsrefactoringchanges.cpp
+++ b/src/plugins/clangtools/clangfixitsrefactoringchanges.cpp
@@ -101,7 +101,7 @@ bool FixitsRefactoringFile::apply()
return false; // Error reading file
for (auto it = m_documents.begin(); it != m_documents.end(); ++it) {
- if (const Result res = m_textFileFormat.writeFile(it.key(), it.value()->toPlainText()); !res) {
+ if (const Result<> res = m_textFileFormat.writeFile(it.key(), it.value()->toPlainText()); !res) {
qCDebug(fixitsLog) << "ERROR: Could not write file" << it.key() << ":" << res.error();
return false; // Error writing file
}
diff --git a/src/plugins/clangtools/virtualfilesystemoverlay.cpp b/src/plugins/clangtools/virtualfilesystemoverlay.cpp
index f3a25f9b013..3517dfe387e 100644
--- a/src/plugins/clangtools/virtualfilesystemoverlay.cpp
+++ b/src/plugins/clangtools/virtualfilesystemoverlay.cpp
@@ -41,7 +41,7 @@ void VirtualFileSystemOverlay::update()
saved.path = m_root.filePath(doc->filePath().fileName() + ".auto");
while (saved.path.exists())
saved.path = saved.path.stringAppended(".1");
- if (Utils::Result res = doc->save(saved.path, true); !res) {
+ if (Utils::Result<> res = doc->save(saved.path, true); !res) {
qCDebug(LOG) << res.error();
continue;
}
@@ -50,7 +50,7 @@ void VirtualFileSystemOverlay::update()
}
for (const AutoSavedPath &path : std::as_const(m_saved)) {
- Utils::Result result = path.path.removeRecursively();
+ Utils::Result<> result = path.path.removeRecursively();
if (!result)
qCDebug(LOG) << result.error();
}
diff --git a/src/plugins/cmakeprojectmanager/fileapireader.cpp b/src/plugins/cmakeprojectmanager/fileapireader.cpp
index 3d668e21abb..127a3be9665 100644
--- a/src/plugins/cmakeprojectmanager/fileapireader.cpp
+++ b/src/plugins/cmakeprojectmanager/fileapireader.cpp
@@ -321,7 +321,7 @@ void FileApiReader::makeBackupConfiguration(bool store)
std::swap(cmakeCacheTxt, cmakeCacheTxtPrev);
if (cmakeCacheTxt.exists()) {
- if (Result res = FileUtils::copyIfDifferent(cmakeCacheTxt, cmakeCacheTxtPrev); !res) {
+ if (Result<> res = FileUtils::copyIfDifferent(cmakeCacheTxt, cmakeCacheTxtPrev); !res) {
Core::MessageManager::writeFlashing(addCMakePrefix(
Tr::tr("Failed to copy \"%1\" to \"%2\": %3")
.arg(cmakeCacheTxt.toUserOutput(), cmakeCacheTxtPrev.toUserOutput(), res.error())));
diff --git a/src/plugins/compilerexplorer/compilerexplorereditor.cpp b/src/plugins/compilerexplorer/compilerexplorereditor.cpp
index bf515a85b7e..97293e26c42 100644
--- a/src/plugins/compilerexplorer/compilerexplorereditor.cpp
+++ b/src/plugins/compilerexplorer/compilerexplorereditor.cpp
@@ -154,7 +154,7 @@ public:
const Utils::FilePath &filePath,
const Utils::FilePath &realFilePath) override;
- Result saveImpl(const Utils::FilePath &filePath, bool autoSave) override;
+ Result<> saveImpl(const Utils::FilePath &filePath, bool autoSave) override;
bool setContents(const QByteArray &contents) override;
@@ -408,7 +408,7 @@ Core::IDocument::OpenResult JsonSettingsDocument::open(QString *errorString,
return OpenResult::Success;
}
-Result JsonSettingsDocument::saveImpl(const FilePath &newFilePath, bool autoSave)
+Result<> JsonSettingsDocument::saveImpl(const FilePath &newFilePath, bool autoSave)
{
Store store;
@@ -434,10 +434,10 @@ Result JsonSettingsDocument::saveImpl(const FilePath &newFilePath, bool autoSave
expected_str<qint64> result = path.writeFileContents(jsonFromStore(store));
if (!result)
- return Result::Error(result.error());
+ return ResultError(result.error());
emit changed();
- return Result::Ok;
+ return ResultOk;
}
bool JsonSettingsDocument::isModified() const
diff --git a/src/plugins/coreplugin/basefilewizard.cpp b/src/plugins/coreplugin/basefilewizard.cpp
index f1a461338a8..282d0081f12 100644
--- a/src/plugins/coreplugin/basefilewizard.cpp
+++ b/src/plugins/coreplugin/basefilewizard.cpp
@@ -78,7 +78,7 @@ void BaseFileWizard::accept()
}
// Write
- if (const Result res = m_factory->writeFiles(m_files); !res) {
+ if (const Result<> res = m_factory->writeFiles(m_files); !res) {
QMessageBox::critical(parentWidget(), Tr::tr("File Generation Failure"), res.error());
reject();
return;
diff --git a/src/plugins/coreplugin/basefilewizardfactory.cpp b/src/plugins/coreplugin/basefilewizardfactory.cpp
index 3a0e823435d..7935ce53b69 100644
--- a/src/plugins/coreplugin/basefilewizardfactory.cpp
+++ b/src/plugins/coreplugin/basefilewizardfactory.cpp
@@ -124,16 +124,16 @@ Wizard *BaseFileWizardFactory::runWizardImpl(const FilePath &path, Id platform,
GeneratedFile::CustomGeneratorAttribute set.
*/
-Result BaseFileWizardFactory::writeFiles(const GeneratedFiles &files) const
+Result<> BaseFileWizardFactory::writeFiles(const GeneratedFiles &files) const
{
const GeneratedFile::Attributes noWriteAttributes
= GeneratedFile::CustomGeneratorAttribute|GeneratedFile::KeepExistingFileAttribute;
for (const GeneratedFile &generatedFile : std::as_const(files)) {
if (!(generatedFile.attributes() & noWriteAttributes ))
- if (const Result res = generatedFile.write(); !res)
+ if (const Result<> res = generatedFile.write(); !res)
return res;
}
- return Result::Ok;
+ return ResultOk;
}
/*!
diff --git a/src/plugins/coreplugin/basefilewizardfactory.h b/src/plugins/coreplugin/basefilewizardfactory.h
index 47d74bb862f..6c36ef6f065 100644
--- a/src/plugins/coreplugin/basefilewizardfactory.h
+++ b/src/plugins/coreplugin/basefilewizardfactory.h
@@ -72,7 +72,7 @@ protected:
virtual GeneratedFiles generateFiles(const QWizard *w,
QString *errorMessage) const = 0;
- virtual Utils::Result writeFiles(const GeneratedFiles &files) const;
+ virtual Utils::Result<> writeFiles(const GeneratedFiles &files) const;
virtual bool postGenerateFiles(const QWizard *w, const GeneratedFiles &l, QString *errorMessage) const;
diff --git a/src/plugins/coreplugin/documentmanager.cpp b/src/plugins/coreplugin/documentmanager.cpp
index acfbcf30b69..125d3f475ec 100644
--- a/src/plugins/coreplugin/documentmanager.cpp
+++ b/src/plugins/coreplugin/documentmanager.cpp
@@ -714,7 +714,7 @@ bool DocumentManager::saveDocument(IDocument *document,
expectFileChange(savePath); // This only matters to other IDocuments which refer to this file
bool addWatcher = removeDocument(document); // So that our own IDocument gets no notification at all
- if (const Result res = document->save(savePath, false); !res) {
+ if (const Result<> res = document->save(savePath, false); !res) {
if (isReadOnly) {
QFile ofi(savePath.toUrlishString());
// Check whether the existing file is writable
@@ -1187,7 +1187,7 @@ void DocumentManager::checkForReload()
removeFileInfo(document);
addFileInfos({document});
- Result success = Result::Ok;
+ Result<> success = ResultOk;
// we've got some modification
document->checkPermissions();
// check if it's contents or permissions:
diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp
index 83c4fe866ed..1e701cbb4ba 100644
--- a/src/plugins/coreplugin/editormanager/editormanager.cpp
+++ b/src/plugins/coreplugin/editormanager/editormanager.cpp
@@ -2386,7 +2386,7 @@ void EditorManagerPrivate::autoSave()
if (document->filePath().isEmpty()
|| !savePath.isWritableDir()) // FIXME: save them to a dedicated directory
continue;
- if (Result res = document->autoSave(saveName); !res)
+ if (Result<> res = document->autoSave(saveName); !res)
errors << res.error();
}
if (!errors.isEmpty())
@@ -2614,7 +2614,7 @@ void EditorManagerPrivate::revertToSaved(IDocument *document)
}
}
- if (Result res = document->reload(IDocument::FlagReload, IDocument::TypeContents); !res)
+ if (Result<> res = document->reload(IDocument::FlagReload, IDocument::TypeContents); !res)
QMessageBox::critical(ICore::dialogParent(), ::Core::Tr::tr("File Error"), res.error());
}
diff --git a/src/plugins/coreplugin/foldernavigationwidget.cpp b/src/plugins/coreplugin/foldernavigationwidget.cpp
index 3d94c3a8ac5..2d488c74240 100644
--- a/src/plugins/coreplugin/foldernavigationwidget.cpp
+++ b/src/plugins/coreplugin/foldernavigationwidget.cpp
@@ -731,7 +731,7 @@ void FolderNavigationWidget::contextMenuEvent(QContextMenuEvent *ev)
RemoveFileDialog dialog(filePath, ICore::dialogParent());
dialog.setDeleteFileVisible(false);
if (dialog.exec() == QDialog::Accepted) {
- Utils::Result result = filePath.removeRecursively();
+ Utils::Result<> result = filePath.removeRecursively();
if (!result)
QMessageBox::critical(ICore::dialogParent(), Tr::tr("Error"), result.error());
}
diff --git a/src/plugins/coreplugin/generatedfile.cpp b/src/plugins/coreplugin/generatedfile.cpp
index fd4508a2560..9737467d5fc 100644
--- a/src/plugins/coreplugin/generatedfile.cpp
+++ b/src/plugins/coreplugin/generatedfile.cpp
@@ -37,8 +37,8 @@ public:
GeneratedFilePrivate() = default;
explicit GeneratedFilePrivate(const FilePath &path);
- Result writeContents() const;
- Result writePermissions() const;
+ Result<> writeContents() const;
+ Result<> writePermissions() const;
FilePath path;
std::optional<QFile::Permissions> permissions;
@@ -150,7 +150,7 @@ void GeneratedFile::setEditorId(Id id)
m_d->editorId = id;
}
-Result GeneratedFilePrivate::writeContents() const
+Result<> GeneratedFilePrivate::writeContents() const
{
if (binary) {
QIODevice::OpenMode flags = QIODevice::WriteOnly | QIODevice::Truncate;
@@ -158,7 +158,7 @@ Result GeneratedFilePrivate::writeContents() const
saver.write(contents);
QString errorMessage;
const bool ok = saver.finalize(&errorMessage);
- return ok ? Result::Ok : Result::Error(errorMessage);
+ return ok ? ResultOk : ResultError(errorMessage);
}
TextFileFormat format;
@@ -167,28 +167,28 @@ Result GeneratedFilePrivate::writeContents() const
return format.writeFile(path, QString::fromUtf8(contents));
}
-Result GeneratedFilePrivate::writePermissions() const
+Result<> GeneratedFilePrivate::writePermissions() const
{
if (!permissions)
- return Result::Ok;
+ return ResultOk;
if (!path.setPermissions(*permissions))
- return Result::Error(Tr::tr("Failed to set permissions."));
- return Result::Ok;
+ return ResultError(Tr::tr("Failed to set permissions."));
+ return ResultOk;
}
-Result GeneratedFile::write() const
+Result<> GeneratedFile::write() const
{
// Ensure the directory
const FilePath parentDir = m_d->path.parentDir();
if (!parentDir.isDir()) {
if (!parentDir.createDir()) {
- return Result::Error(Tr::tr("Unable to create the directory %1.")
+ return ResultError(Tr::tr("Unable to create the directory %1.")
.arg(parentDir.toUserOutput()));
}
}
// Write out
- if (const Result res = m_d->writeContents(); !res)
+ if (const Result<> res = m_d->writeContents(); !res)
return res;
return m_d->writePermissions();
}
diff --git a/src/plugins/coreplugin/generatedfile.h b/src/plugins/coreplugin/generatedfile.h
index fda30813cf2..0772924a9c2 100644
--- a/src/plugins/coreplugin/generatedfile.h
+++ b/src/plugins/coreplugin/generatedfile.h
@@ -6,15 +6,13 @@
#include "core_global.h"
#include <utils/id.h>
+#include <utils/result.h>
#include <QFile>
#include <QList>
#include <QSharedDataPointer>
-namespace Utils {
-class FilePath;
-class Result;
-} // Utils
+namespace Utils { class FilePath; }
namespace Core {
class GeneratedFilePrivate;
@@ -66,7 +64,7 @@ public:
Utils::Id editorId() const;
void setEditorId(Utils::Id id);
- Utils::Result write() const;
+ Utils::Result<> write() const;
Attributes attributes() const;
void setAttributes(Attributes a);
diff --git a/src/plugins/coreplugin/idocument.cpp b/src/plugins/coreplugin/idocument.cpp
index f57256819fd..fe1ab0d8995 100644
--- a/src/plugins/coreplugin/idocument.cpp
+++ b/src/plugins/coreplugin/idocument.cpp
@@ -340,11 +340,11 @@ IDocument::OpenResult IDocument::open(QString *errorString, const Utils::FilePat
\sa saved()
\sa filePath()
*/
-Result IDocument::save(const FilePath &filePath, bool autoSave)
+Result<> IDocument::save(const FilePath &filePath, bool autoSave)
{
const FilePath savePath = filePath.isEmpty() ? this->filePath() : filePath;
emit aboutToSave(savePath, autoSave);
- const Result res = saveImpl(savePath, autoSave);
+ const Result<> res = saveImpl(savePath, autoSave);
if (res)
emit saved(savePath, autoSave);
return res;
@@ -361,11 +361,11 @@ Result IDocument::save(const FilePath &filePath, bool autoSave)
The default implementation does nothing and returns \c false.
*/
-Result IDocument::saveImpl(const FilePath &filePath, bool autoSave)
+Result<> IDocument::saveImpl(const FilePath &filePath, bool autoSave)
{
Q_UNUSED(filePath)
Q_UNUSED(autoSave)
- return Result::Error(Tr::tr("Not implemented"));
+ return ResultError(Tr::tr("Not implemented"));
}
/*!
@@ -461,11 +461,11 @@ IDocument::ReloadBehavior IDocument::reloadBehavior(ChangeTrigger trigger, Chang
\sa reloadFinished()
\sa changed()
*/
-Result IDocument::reload(ReloadFlag flag, ChangeType type)
+Result<> IDocument::reload(ReloadFlag flag, ChangeType type)
{
Q_UNUSED(flag)
Q_UNUSED(type)
- return Result::Ok;
+ return ResultOk;
}
/*!
@@ -641,13 +641,13 @@ void IDocument::setMimeType(const QString &mimeType)
/*!
\internal
*/
-Result IDocument::autoSave(const FilePath &filePath)
+Result<> IDocument::autoSave(const FilePath &filePath)
{
- if (const Result res = save(filePath, true); !res)
+ if (const Result<> res = save(filePath, true); !res)
return res;
d->autoSavePath = filePath;
- return Result::Ok;
+ return ResultOk;
}
static const char kRestoredAutoSave[] = "RestoredAutoSave";
diff --git a/src/plugins/coreplugin/idocument.h b/src/plugins/coreplugin/idocument.h
index cb8a095dd78..58a903464a7 100644
--- a/src/plugins/coreplugin/idocument.h
+++ b/src/plugins/coreplugin/idocument.h
@@ -68,7 +68,7 @@ public:
virtual OpenResult open(QString *errorString, const Utils::FilePath &filePath, const Utils::FilePath &realFilePath);
- Utils::Result save(const Utils::FilePath &filePath = {}, bool autoSave = false);
+ Utils::Result<> save(const Utils::FilePath &filePath = {}, bool autoSave = false);
virtual QByteArray contents() const;
virtual bool setContents(const QByteArray &contents);
@@ -100,11 +100,11 @@ public:
void setSuspendAllowed(bool value);
virtual ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const;
- virtual Utils::Result reload(ReloadFlag flag, ChangeType type);
+ virtual Utils::Result<> reload(ReloadFlag flag, ChangeType type);
void checkPermissions();
- Utils::Result autoSave(const Utils::FilePath &filePath);
+ Utils::Result<> autoSave(const Utils::FilePath &filePath);
void setRestoredFrom(const Utils::FilePath &path);
void removeAutoSaveFile();
@@ -131,7 +131,7 @@ signals:
void filePathChanged(const Utils::FilePath &oldName, const Utils::FilePath &newName);
protected:
- virtual Utils::Result saveImpl(const Utils::FilePath &filePath = {}, bool autoSave = false);
+ virtual Utils::Result<> saveImpl(const Utils::FilePath &filePath = {}, bool autoSave = false);
private:
Internal::IDocumentPrivate *d;
diff --git a/src/plugins/coreplugin/outputwindow.cpp b/src/plugins/coreplugin/outputwindow.cpp
index f982b79ad4a..8ac6e0e0b43 100644
--- a/src/plugins/coreplugin/outputwindow.cpp
+++ b/src/plugins/coreplugin/outputwindow.cpp
@@ -321,7 +321,7 @@ void OutputWindow::contextMenuEvent(QContextMenuEvent *event)
Utils::TextFileFormat format;
format.setCodecName(EditorManager::defaultTextCodecName());
format.lineTerminationMode = EditorManager::defaultLineEnding();
- if (const Result res = format.writeFile(file, toPlainText()); !res)
+ if (const Result<> res = format.writeFile(file, toPlainText()); !res)
MessageManager::writeDisrupting(res.error());
}
});
diff --git a/src/plugins/coreplugin/plugininstallwizard.cpp b/src/plugins/coreplugin/plugininstallwizard.cpp
index 8a2956d4002..2c6a48725d0 100644
--- a/src/plugins/coreplugin/plugininstallwizard.cpp
+++ b/src/plugins/coreplugin/plugininstallwizard.cpp
@@ -122,22 +122,22 @@ public:
using CheckResult = expected_str<PluginSpec *>;
-static Result checkPlugin(PluginSpec *spec, bool update)
+static Result<> checkPlugin(PluginSpec *spec, bool update)
{
const bool pluginAlreadyExists = PluginManager::specExists(spec->id());
if (!update && pluginAlreadyExists) {
- return Result::Error(
+ return ResultError(
Tr::tr("A plugin with ID \"%1\" is already installed.").arg(spec->id()));
} else if (update && !pluginAlreadyExists) {
- return Result::Error(Tr::tr("No plugin with ID \"%1\" is installed.").arg(spec->id()));
+ return ResultError(Tr::tr("No plugin with ID \"%1\" is installed.").arg(spec->id()));
}
if (!spec->resolveDependencies(PluginManager::plugins())) {
- return Result::Error(
+ return ResultError(
Tr::tr("Plugin failed to resolve dependencies:") + " " + spec->errorString());
}
- return Result::Ok;
+ return ResultOk;
}
static expected_str<std::unique_ptr<PluginSpec>> checkPlugin(
@@ -145,7 +145,7 @@ static expected_str<std::unique_ptr<PluginSpec>> checkPlugin(
{
if (!spec)
return spec;
- const Result ok = checkPlugin(spec->get(), update);
+ const Result<> ok = checkPlugin(spec->get(), update);
if (ok)
return spec;
return Utils::make_unexpected(ok.error());
@@ -166,7 +166,7 @@ void checkContents(QPromise<CheckResult> &promise, const FilePath &tempDir, bool
}
PluginSpec *plugin = plugins.front();
- const Result ok = checkPlugin(plugin, update);
+ const Result<> ok = checkPlugin(plugin, update);
if (!ok) {
promise.addResult(Utils::make_unexpected(ok.error()));
delete plugin;
@@ -512,7 +512,7 @@ InstallResult executePluginInstallWizard(const FilePath &archive, bool prepareFo
/ extensionId(data.pluginSpec.get());
if (prepareForUpdate) {
- const Result result = ExtensionSystem::PluginManager::removePluginOnRestart(
+ const Result<> result = ExtensionSystem::PluginManager::removePluginOnRestart(
data.pluginSpec->id());
if (!result) {
qWarning() << "Failed to remove plugin" << data.pluginSpec->id() << ":"
diff --git a/src/plugins/coreplugin/session.cpp b/src/plugins/coreplugin/session.cpp
index fd09d17f81d..c615fbc7e08 100644
--- a/src/plugins/coreplugin/session.cpp
+++ b/src/plugins/coreplugin/session.cpp
@@ -360,7 +360,7 @@ bool SessionManager::deleteSession(const QString &session)
FilePath sessionFile = sessionNameToFileName(session);
if (!sessionFile.exists())
return false;
- Result result = sessionFile.removeFile();
+ Result<> result = sessionFile.removeFile();
QTC_CHECK_EXPECTED(result);
return bool(result);
}
@@ -789,7 +789,7 @@ bool SessionManager::saveSession()
if (!d->m_writer || d->m_writer->fileName() != filePath)
d->m_writer.reset(new PersistentSettingsWriter(filePath, "QtCreatorSession"));
- const Result result = d->m_writer->save(data);
+ const Result<> result = d->m_writer->save(data);
if (result) {
if (!SessionManager::isDefaultVirgin())
d->m_sessionDateTimes.insert(SessionManager::activeSession(),
@@ -801,7 +801,7 @@ bool SessionManager::saveSession()
.arg(d->m_writer->fileName().toUserOutput()));
}
- return result;
+ return result.has_value();
}
} // namespace Core
diff --git a/src/plugins/coreplugin/textdocument.cpp b/src/plugins/coreplugin/textdocument.cpp
index e5897cc34b3..1dbf760150e 100644
--- a/src/plugins/coreplugin/textdocument.cpp
+++ b/src/plugins/coreplugin/textdocument.cpp
@@ -73,7 +73,7 @@ QByteArray BaseTextDocument::decodingErrorSample() const
Returns whether the operation was successful.
*/
-Result BaseTextDocument::write(const FilePath &filePath, const QString &data) const
+Result<> BaseTextDocument::write(const FilePath &filePath, const QString &data) const
{
return write(filePath, format(), data);
}
@@ -88,7 +88,7 @@ Result BaseTextDocument::write(const FilePath &filePath, const QString &data) co
Returns whether the operation was successful.
*/
-Result BaseTextDocument::write(const FilePath &filePath,
+Result<> BaseTextDocument::write(const FilePath &filePath,
const TextFileFormat &format,
const QString &data) const
{
diff --git a/src/plugins/coreplugin/textdocument.h b/src/plugins/coreplugin/textdocument.h
index 2e1b6f83159..406ed83f245 100644
--- a/src/plugins/coreplugin/textdocument.h
+++ b/src/plugins/coreplugin/textdocument.h
@@ -37,8 +37,8 @@ public:
bool hasDecodingError() const;
QByteArray decodingErrorSample() const;
- Utils::Result write(const Utils::FilePath &filePath, const QString &data) const;
- Utils::Result write(const Utils::FilePath &filePath, const Utils::TextFileFormat &format, const QString &data) const;
+ Utils::Result<> write(const Utils::FilePath &filePath, const QString &data) const;
+ Utils::Result<> write(const Utils::FilePath &filePath, const Utils::TextFileFormat &format, const QString &data) const;
void setSupportsUtf8Bom(bool value);
void setLineTerminationMode(Utils::TextFileFormat::LineTerminationMode mode);
diff --git a/src/plugins/cppeditor/cppeditordocument.cpp b/src/plugins/cppeditor/cppeditordocument.cpp
index 5a1e84645df..f31004a10e4 100644
--- a/src/plugins/cppeditor/cppeditordocument.cpp
+++ b/src/plugins/cppeditor/cppeditordocument.cpp
@@ -501,7 +501,7 @@ TextEditor::TabSettings CppEditorDocument::tabSettings() const
return indenter()->tabSettings().value_or(TextEditor::TextDocument::tabSettings());
}
-Result CppEditorDocument::saveImpl(const FilePath &filePath, bool autoSave)
+Result<> CppEditorDocument::saveImpl(const FilePath &filePath, bool autoSave)
{
if (!indenter()->formatOnSave() || autoSave)
return TextEditor::TextDocument::saveImpl(filePath, autoSave);
diff --git a/src/plugins/cppeditor/cppeditordocument.h b/src/plugins/cppeditor/cppeditordocument.h
index c259afdcc23..aba526e7872 100644
--- a/src/plugins/cppeditor/cppeditordocument.h
+++ b/src/plugins/cppeditor/cppeditordocument.h
@@ -75,7 +75,7 @@ signals:
protected:
void applyFontSettings() override;
- Utils::Result saveImpl(const Utils::FilePath &filePath, bool autoSave) override;
+ Utils::Result<> saveImpl(const Utils::FilePath &filePath, bool autoSave) override;
void slotCodeStyleSettingsChanged() override;
private:
diff --git a/src/plugins/debugger/cdb/cdbengine.cpp b/src/plugins/debugger/cdb/cdbengine.cpp
index 045d483a74a..fbc4c71875b 100644
--- a/src/plugins/debugger/cdb/cdbengine.cpp
+++ b/src/plugins/debugger/cdb/cdbengine.cpp
@@ -2081,7 +2081,7 @@ void CdbEngine::handleExtensionMessage(char t, int token, const QString &what, c
response.data.m_type = GdbMi::Tuple;
}
} else {
- response.resultClass = ResultError;
+ response.resultClass = ResultFail;
GdbMi msg;
msg.m_name = "msg";
msg.m_data = message;
diff --git a/src/plugins/debugger/debuggerengine.cpp b/src/plugins/debugger/debuggerengine.cpp
index 7b7d8faec20..538f50739bf 100644
--- a/src/plugins/debugger/debuggerengine.cpp
+++ b/src/plugins/debugger/debuggerengine.cpp
@@ -210,7 +210,7 @@ void DebuggerRunParameters::setBreakOnMainNextTime()
breakOnMainNextTime = true;
}
-Result DebuggerRunParameters::fixupParameters(ProjectExplorer::RunControl *runControl)
+Result<> DebuggerRunParameters::fixupParameters(ProjectExplorer::RunControl *runControl)
{
if (m_symbolFile.isEmpty())
m_symbolFile = m_inferior.command.executable();
@@ -227,7 +227,7 @@ Result DebuggerRunParameters::fixupParameters(ProjectExplorer::RunControl *runCo
// validate debugger if C++ debugging is enabled
if (!m_validationErrors.isEmpty())
- return Result::Error(m_validationErrors.join('\n'));
+ return ResultError(m_validationErrors.join('\n'));
if (m_isQmlDebugging) {
const auto device = runControl->device();
@@ -235,7 +235,7 @@ Result DebuggerRunParameters::fixupParameters(ProjectExplorer::RunControl *runCo
if (m_qmlServer.port() <= 0) {
m_qmlServer = Utils::urlFromLocalHostAndFreePort();
if (m_qmlServer.port() <= 0)
- return Result::Error(Tr::tr("Not enough free ports for QML debugging."));
+ return ResultError(Tr::tr("Not enough free ports for QML debugging."));
}
// Makes sure that all bindings go through the JavaScript engine, so that
// breakpoints are actually hit!
@@ -292,7 +292,7 @@ Result DebuggerRunParameters::fixupParameters(ProjectExplorer::RunControl *runCo
if (perr != ProcessArgs::SplitOk) {
// perr == BadQuoting is never returned on Windows
// FIXME? QTCREATORBUG-2809
- return Result::Error(Tr::tr("Debugging complex command lines "
+ return ResultError(Tr::tr("Debugging complex command lines "
"is currently not supported on Windows."));
}
}
@@ -303,7 +303,7 @@ Result DebuggerRunParameters::fixupParameters(ProjectExplorer::RunControl *runCo
if (settings().forceLoggingToConsole())
m_inferior.environment.set("QT_LOGGING_TO_CONSOLE", "1");
- return Result::Ok;
+ return ResultOk;
}
void DebuggerRunParameters::setStartMode(DebuggerStartMode startMode)
diff --git a/src/plugins/debugger/debuggerengine.h b/src/plugins/debugger/debuggerengine.h
index 6bd2c46129d..ac259bbdc33 100644
--- a/src/plugins/debugger/debuggerengine.h
+++ b/src/plugins/debugger/debuggerengine.h
@@ -20,6 +20,7 @@
#include <utils/outputformat.h>
#include <utils/processhandle.h>
#include <utils/processinterface.h>
+#include <utils/result.h>
QT_BEGIN_NAMESPACE
class QDebug;
@@ -34,7 +35,6 @@ namespace Utils {
class MacroExpander;
class Perspective;
class ProcessResultData;
-class Result;
} // Utils
namespace Debugger {
@@ -77,7 +77,7 @@ public:
static void setBreakOnMainNextTime();
- Utils::Result fixupParameters(ProjectExplorer::RunControl *runControl);
+ Utils::Result<> fixupParameters(ProjectExplorer::RunControl *runControl);
void setStartMode(DebuggerStartMode startMode);
DebuggerStartMode startMode() const { return m_startMode; }
diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp
index 36cf835ba7c..074b4f18ebc 100644
--- a/src/plugins/debugger/debuggerplugin.cpp
+++ b/src/plugins/debugger/debuggerplugin.cpp
@@ -1530,11 +1530,11 @@ void DebuggerPluginPrivate::updatePresetState()
if (!currentEngine) {
// No engine running -- or -- we have a running engine but it does not
// correspond to the current start up project.
- m_startAction.setEnabled(canRun);
+ m_startAction.setEnabled(canRun.has_value());
m_startAction.setIcon(startIcon(true));
m_startAction.setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
m_startAction.setVisible(true);
- m_debugWithoutDeployAction.setEnabled(canRun);
+ m_debugWithoutDeployAction.setEnabled(canRun.has_value());
m_visibleStartAction.setAction(&m_startAction);
m_hiddenStopAction.setAction(&m_undisturbableAction);
return;
@@ -1548,7 +1548,7 @@ void DebuggerPluginPrivate::updatePresetState()
m_startAction.setEnabled(false);
m_startAction.setVisible(false);
- m_debugWithoutDeployAction.setEnabled(canRun);
+ m_debugWithoutDeployAction.setEnabled(canRun.has_value());
const DebuggerState state = currentEngine->state();
@@ -1566,8 +1566,8 @@ void DebuggerPluginPrivate::updatePresetState()
m_hiddenStopAction.setAction(ActionManager::command(Constants::INTERRUPT)->action());
} else if (state == DebuggerFinished) {
// We don't want to do anything anymore.
- m_startAction.setEnabled(canRun);
- m_debugWithoutDeployAction.setEnabled(canRun);
+ m_startAction.setEnabled(canRun.has_value());
+ m_debugWithoutDeployAction.setEnabled(canRun.has_value());
m_visibleStartAction.setAction(ActionManager::command(DEBUGGER_START)->action());
m_hiddenStopAction.setAction(&m_undisturbableAction);
} else if (state == InferiorUnrunnable) {
diff --git a/src/plugins/debugger/debuggerprotocol.cpp b/src/plugins/debugger/debuggerprotocol.cpp
index 23d836f018c..4ee6590662b 100644
--- a/src/plugins/debugger/debuggerprotocol.cpp
+++ b/src/plugins/debugger/debuggerprotocol.cpp
@@ -428,7 +428,7 @@ QString DebuggerResponse::stringFromResultClass(ResultClass resultClass)
case ResultDone: return QLatin1String("done");
case ResultRunning: return QLatin1String("running");
case ResultConnected: return QLatin1String("connected");
- case ResultError: return QLatin1String("error");
+ case ResultFail: return QLatin1String("error");
case ResultExit: return QLatin1String("exit");
default: return QLatin1String("unknown");
}
diff --git a/src/plugins/debugger/debuggerprotocol.h b/src/plugins/debugger/debuggerprotocol.h
index 12b60867acb..5663b2eb1f1 100644
--- a/src/plugins/debugger/debuggerprotocol.h
+++ b/src/plugins/debugger/debuggerprotocol.h
@@ -194,7 +194,7 @@ enum ResultClass
ResultDone,
ResultRunning,
ResultConnected,
- ResultError,
+ ResultFail,
ResultExit
};
diff --git a/src/plugins/debugger/debuggerruncontrol.cpp b/src/plugins/debugger/debuggerruncontrol.cpp
index 4f02aa0e34a..048ffb52242 100644
--- a/src/plugins/debugger/debuggerruncontrol.cpp
+++ b/src/plugins/debugger/debuggerruncontrol.cpp
@@ -88,8 +88,8 @@ class EnginesDriver : public QObject
public:
~EnginesDriver() { clearEngines(); }
- Result setupEngines(RunControl *runControl, const DebuggerRunParameters &rp);
- Result checkBreakpoints() const;
+ Result<> setupEngines(RunControl *runControl, const DebuggerRunParameters &rp);
+ Result<> checkBreakpoints() const;
QString debuggerName() const
{
return Utils::transform<QStringList>(m_engines, &DebuggerEngine::objectName).join(" ");
@@ -293,7 +293,7 @@ ExecutableItem DebuggerRunToolPrivate::fixupParamsRecipe()
// return;
// }
- if (Result res = m_runParameters.fixupParameters(q->runControl()); !res) {
+ if (Result<> res = m_runParameters.fixupParameters(q->runControl()); !res) {
q->reportFailure(res.error());
return false;
}
@@ -478,11 +478,11 @@ ExecutableItem DebuggerRunToolPrivate::startEnginesRecipe(const Storage<EnginesD
const auto setupEngines = [this, driverStorage] {
EnginesDriver *driver = driverStorage.activeStorage();
RunControl *rc = q->runControl();
- if (Result res = driver->setupEngines(rc, m_runParameters); !res) {
+ if (Result<> res = driver->setupEngines(rc, m_runParameters); !res) {
q->reportFailure(res.error());
return false;
}
- if (Result res = driver->checkBreakpoints(); !res) {
+ if (Result<> res = driver->checkBreakpoints(); !res) {
driver->showMessage(res.error(), LogWarning);
if (settings().showUnsupportedBreakpointWarning()) {
bool doNotAskAgain = false;
@@ -584,13 +584,13 @@ static int newRunId()
return ++toolRunCount;
}
-Result EnginesDriver::setupEngines(RunControl *runControl, const DebuggerRunParameters &rp)
+Result<> EnginesDriver::setupEngines(RunControl *runControl, const DebuggerRunParameters &rp)
{
m_runControl = runControl;
clearEngines();
const auto engines = createEngines(runControl, rp);
if (!engines)
- return Result::Error(engines.error());
+ return ResultError(engines.error());
m_engines = *engines;
const QString runId = QString::number(newRunId());
@@ -606,10 +606,10 @@ Result EnginesDriver::setupEngines(RunControl *runControl, const DebuggerRunPara
engine->setDevice(m_runControl->device());
}
- return Result::Ok;
+ return ResultOk;
}
-Result EnginesDriver::checkBreakpoints() const
+Result<> EnginesDriver::checkBreakpoints() const
{
QStringList unhandledIds;
bool hasQmlBreakpoints = false;
@@ -626,7 +626,7 @@ Result EnginesDriver::checkBreakpoints() const
}
if (unhandledIds.isEmpty())
- return Result::Ok;
+ return ResultOk;
QString warningMessage = Tr::tr("Some breakpoints cannot be handled by the debugger "
"languages currently active, and will be ignored.<p>"
@@ -635,7 +635,7 @@ Result EnginesDriver::checkBreakpoints() const
warningMessage += "<p>" + Tr::tr("QML debugging needs to be enabled both in the Build "
"and the Run settings.");
}
- return Result::Error(warningMessage);
+ return ResultError(warningMessage);
}
void EnginesDriver::start()
diff --git a/src/plugins/debugger/gdb/gdbengine.cpp b/src/plugins/debugger/gdb/gdbengine.cpp
index 320dd504703..5268caabefe 100644
--- a/src/plugins/debugger/gdb/gdbengine.cpp
+++ b/src/plugins/debugger/gdb/gdbengine.cpp
@@ -385,7 +385,7 @@ void GdbEngine::handleResponse(const QString &buff)
else if (resultClass == u"connected")
response.resultClass = ResultConnected;
else if (resultClass == u"error")
- response.resultClass = ResultError;
+ response.resultClass = ResultFail;
else if (resultClass == u"exit")
response.resultClass = ResultExit;
else
@@ -686,7 +686,7 @@ void GdbEngine::interruptInferior()
DeviceProcessSignalOperation::Ptr signalOperation = dev->signalOperation();
QTC_ASSERT(signalOperation, notifyInferiorStopFailed(); return);
connect(signalOperation.get(), &DeviceProcessSignalOperation::finished,
- this, [this, signalOperation](const Result &result) {
+ this, [this, signalOperation](const Result<> &result) {
if (result) {
showMessage("Interrupted " + QString::number(inferiorPid()));
notifyInferiorStopOk();
@@ -720,7 +720,7 @@ void GdbEngine::runCommand(const DebuggerCommand &command)
.arg(cmd.function).arg(state()));
if (cmd.callback) {
DebuggerResponse response;
- response.resultClass = ResultError;
+ response.resultClass = ResultFail;
cmd.callback(response);
}
return;
@@ -864,7 +864,7 @@ void GdbEngine::handleResultRecord(DebuggerResponse *response)
showMessage(QString("COOKIE FOR TOKEN %1 ALREADY EATEN (%2). "
"TWO RESPONSES FOR ONE COMMAND?").arg(token).
arg(stateName(state())));
- if (response->resultClass == ResultError) {
+ if (response->resultClass == ResultFail) {
QString msg = response->data["msg"].data();
if (msg == "Cannot find new threads: generic error") {
// Handle a case known to occur on Linux/gdb 6.8 when debugging moc
@@ -955,7 +955,7 @@ void GdbEngine::handleResultRecord(DebuggerResponse *response)
}
bool isExpectedResult =
- (response->resultClass == ResultError) // Can always happen.
+ (response->resultClass == ResultFail) // Can always happen.
|| (response->resultClass == ResultRunning && (flags & RunRequest))
|| (response->resultClass == ResultExit && (flags & ExitRequest))
|| (response->resultClass == ResultDone);
@@ -1059,7 +1059,7 @@ void GdbEngine::handleExecuteJumpToLine(const DebuggerResponse &response)
// All is fine. Waiting for a *running
// and the temporary breakpoint to be hit.
notifyInferiorRunOk(); // Only needed for gdb < 7.0.
- } else if (response.resultClass == ResultError) {
+ } else if (response.resultClass == ResultFail) {
// Could be "Unreasonable jump request" or similar.
QString out = Tr::tr("Cannot jump. Stopped.");
QString msg = response.data["msg"].data();
@@ -1509,7 +1509,7 @@ void GdbEngine::handleShowVersion(const DebuggerResponse &response)
void GdbEngine::handleDumperSetup(const DebuggerResponse &response)
{
CHECK_STATE(EngineSetupRequested);
- if (response.resultClass == ResultError) {
+ if (response.resultClass == ResultFail) {
const QString msg = response.data["msg"].data();
if (property("lru_fail").toBool() && msg.contains("Error while executing Python code.")) {
AsynchronousMessageBox::critical(
@@ -4709,7 +4709,7 @@ void GdbEngine::handleLocalAttach(const DebuggerResponse &response)
}
break;
}
- case ResultError:
+ case ResultFail:
if (response.data["msg"].data() == "ptrace: Operation not permitted.") {
const QString msg = msgPtraceError(runParameters().startMode());
showStatusMessage(Tr::tr("Failed to attach to application: %1").arg(msg));
@@ -4740,7 +4740,7 @@ void GdbEngine::handleRemoteAttach(const DebuggerResponse &response)
handleInferiorPrepared();
break;
}
- case ResultError:
+ case ResultFail:
if (response.data["msg"].data() == "ptrace: Operation not permitted.") {
notifyInferiorSetupFailedHelper(msgPtraceError(runParameters().startMode()));
break;
@@ -4881,7 +4881,7 @@ void GdbEngine::handleExecRun(const DebuggerResponse &response)
void GdbEngine::handleSetTargetAsync(const DebuggerResponse &response)
{
CHECK_STATE(EngineSetupRequested);
- if (response.resultClass == ResultError)
+ if (response.resultClass == ResultFail)
qDebug() << "Adapter too old: does not support asynchronous mode.";
}
@@ -5001,7 +5001,7 @@ void GdbEngine::handleSetNtoExecutable(const DebuggerResponse &response)
handleInferiorPrepared();
break;
}
- case ResultError:
+ case ResultFail:
default:
notifyInferiorSetupFailedHelper(response.data["msg"].data());
}
@@ -5050,7 +5050,7 @@ void GdbEngine::handleStubAttached(const DebuggerResponse &response, qint64 main
// Wait for the upcoming *stopped and handle it there.
}
break;
- case ResultError:
+ case ResultFail:
if (response.data["msg"].data() == "ptrace: Operation not permitted.") {
notifyInferiorSetupFailedHelper(msgPtraceError(runParameters().startMode()));
break;
@@ -5138,7 +5138,7 @@ void GdbEngine::handleTargetCore(const DebuggerResponse &response)
CHECK_STATE(EngineRunRequested);
notifyEngineRunOkAndInferiorUnrunnable();
showMessage(Tr::tr("Attached to core."), StatusBar);
- if (response.resultClass == ResultError) {
+ if (response.resultClass == ResultFail) {
// We'll accept any kind of error e.g. &"Cannot access memory at address 0x2abc2a24\n"
// Even without the stack, the user can find interesting stuff by exploring
// the memory, globals etc.
diff --git a/src/plugins/debugger/lldb/lldbengine.cpp b/src/plugins/debugger/lldb/lldbengine.cpp
index 2ab984dda15..7daa4c12f39 100644
--- a/src/plugins/debugger/lldb/lldbengine.cpp
+++ b/src/plugins/debugger/lldb/lldbengine.cpp
@@ -391,7 +391,7 @@ void LldbEngine::continueInferior()
notifyInferiorRunRequested();
DebuggerCommand cmd("continueInferior");
cmd.callback = [this](const DebuggerResponse &response) {
- if (response.resultClass == ResultError)
+ if (response.resultClass == ResultFail)
notifyEngineIll();
};
runCommand(cmd);
diff --git a/src/plugins/debugger/loadcoredialog.cpp b/src/plugins/debugger/loadcoredialog.cpp
index 7ee9a098001..c1ef64090f6 100644
--- a/src/plugins/debugger/loadcoredialog.cpp
+++ b/src/plugins/debugger/loadcoredialog.cpp
@@ -245,7 +245,7 @@ void AttachCoreDialog::accepted()
const expected_str<FilePath> resultPath = pattern.createTempFile();
if (!resultPath)
return make_unexpected(resultPath.error());
- const Result result = srcPath.copyFile(resultPath.value());
+ const Result<> result = srcPath.copyFile(resultPath.value());
if (!result)
return make_unexpected(result.error());
diff --git a/src/plugins/designer/formwindowfile.cpp b/src/plugins/designer/formwindowfile.cpp
index 7156443f331..d238a4002a4 100644
--- a/src/plugins/designer/formwindowfile.cpp
+++ b/src/plugins/designer/formwindowfile.cpp
@@ -82,18 +82,18 @@ Core::IDocument::OpenResult FormWindowFile::open(QString *errorString,
return OpenResult::Success;
}
-Result FormWindowFile::saveImpl(const FilePath &filePath, bool autoSave)
+Result<> FormWindowFile::saveImpl(const FilePath &filePath, bool autoSave)
{
if (!m_formWindow)
- return Result::Error("ASSERT: FormWindoFile: !m_formWindow");
+ return ResultError("ASSERT: FormWindoFile: !m_formWindow");
if (filePath.isEmpty())
- return Result::Error("ASSERT: FormWindowFile: filePath.isEmpty()");
+ return ResultError("ASSERT: FormWindowFile: filePath.isEmpty()");
const QString oldFormName = m_formWindow->fileName();
if (!autoSave)
m_formWindow->setFileName(filePath.toUrlishString());
- const Result res = writeFile(filePath);
+ const Result<> res = writeFile(filePath);
m_shouldAutoSave = false;
if (autoSave)
return res;
@@ -107,7 +107,7 @@ Result FormWindowFile::saveImpl(const FilePath &filePath, bool autoSave)
setFilePath(filePath);
updateIsModified();
- return Result::Ok;
+ return ResultOk;
}
QByteArray FormWindowFile::contents() const
@@ -184,11 +184,11 @@ bool FormWindowFile::isSaveAsAllowed() const
return true;
}
-Result FormWindowFile::reload(ReloadFlag flag, ChangeType type)
+Result<> FormWindowFile::reload(ReloadFlag flag, ChangeType type)
{
if (flag == FlagIgnore) {
if (!m_formWindow || type != TypeContents)
- return Result::Ok;
+ return ResultOk;
const bool wasModified = m_formWindow->isDirty();
{
Utils::GuardLocker locker(m_modificationChangedGuard);
@@ -198,14 +198,14 @@ Result FormWindowFile::reload(ReloadFlag flag, ChangeType type)
}
if (!wasModified)
updateIsModified();
- return Result::Ok;
+ return ResultOk;
} else {
emit aboutToReload();
QString errorString;
const bool success
= (open(&errorString, filePath(), filePath()) == OpenResult::Success);
emit reloadFinished(success);
- return Result(success, errorString);
+ return makeResult(success, errorString);
}
}
@@ -227,7 +227,7 @@ bool FormWindowFile::supportsCodec(const QByteArray &codec) const
return TextEditor::TextDocument::isUtf8Codec(codec);
}
-Result FormWindowFile::writeFile(const Utils::FilePath &filePath) const
+Result<> FormWindowFile::writeFile(const Utils::FilePath &filePath) const
{
if (Designer::Constants::Internal::debug)
qDebug() << Q_FUNC_INFO << this->filePath() << filePath;
diff --git a/src/plugins/designer/formwindowfile.h b/src/plugins/designer/formwindowfile.h
index 9ec5fea5c0f..289b338cec6 100644
--- a/src/plugins/designer/formwindowfile.h
+++ b/src/plugins/designer/formwindowfile.h
@@ -33,14 +33,14 @@ public:
bool shouldAutoSave() const override;
bool isModified() const override;
bool isSaveAsAllowed() const override;
- Utils::Result reload(ReloadFlag flag, ChangeType type) override;
+ Utils::Result<> reload(ReloadFlag flag, ChangeType type) override;
QString fallbackSaveAsFileName() const override;
bool supportsCodec(const QByteArray &codec) const override;
// Internal
void setFallbackSaveAsFileName(const QString &fileName);
- Utils::Result writeFile(const Utils::FilePath &filePath) const;
+ Utils::Result<> writeFile(const Utils::FilePath &filePath) const;
QDesignerFormWindowInterface *formWindow() const;
void syncXmlFromFormWindow();
@@ -52,7 +52,7 @@ public:
void updateIsModified();
protected:
- Utils::Result saveImpl(const Utils::FilePath &filePath, bool autoSave) override;
+ Utils::Result<> saveImpl(const Utils::FilePath &filePath, bool autoSave) override;
private:
void slotFormWindowRemoved(QDesignerFormWindowInterface *w);
diff --git a/src/plugins/diffeditor/diffeditordocument.cpp b/src/plugins/diffeditor/diffeditordocument.cpp
index a41f4cf9235..62176d3618b 100644
--- a/src/plugins/diffeditor/diffeditordocument.cpp
+++ b/src/plugins/diffeditor/diffeditordocument.cpp
@@ -226,14 +226,14 @@ bool DiffEditorDocument::isSaveAsAllowed() const
return state() == LoadOK;
}
-Result DiffEditorDocument::saveImpl(const FilePath &filePath, bool autoSave)
+Result<> DiffEditorDocument::saveImpl(const FilePath &filePath, bool autoSave)
{
Q_UNUSED(autoSave)
if (state() != LoadOK)
- return Result::Error(QString());
+ return ResultError(QString());
- const Result res = write(filePath, format(), plainText());
+ const Result<> res = write(filePath, format(), plainText());
if (!res)
return res;
@@ -246,7 +246,7 @@ Result DiffEditorDocument::saveImpl(const FilePath &filePath, bool autoSave)
setPreferredDisplayName({});
emit temporaryStateChanged();
- return Result::Ok;
+ return ResultOk;
}
void DiffEditorDocument::reload()
@@ -257,14 +257,14 @@ void DiffEditorDocument::reload()
reload(Core::IDocument::FlagReload, Core::IDocument::TypeContents);
}
-Result DiffEditorDocument::reload(ReloadFlag flag, ChangeType type)
+Result<> DiffEditorDocument::reload(ReloadFlag flag, ChangeType type)
{
Q_UNUSED(type)
if (flag == FlagIgnore)
- return Result::Ok;
+ return ResultOk;
QString errorString;
bool success = open(&errorString, filePath(), filePath()) == OpenResult::Success;
- return Result(success, errorString);
+ return makeResult(success, errorString);
}
Core::IDocument::OpenResult DiffEditorDocument::open(QString *errorString, const FilePath &filePath,
diff --git a/src/plugins/diffeditor/diffeditordocument.h b/src/plugins/diffeditor/diffeditordocument.h
index 295286cfc87..7a736ff929b 100644
--- a/src/plugins/diffeditor/diffeditordocument.h
+++ b/src/plugins/diffeditor/diffeditordocument.h
@@ -61,7 +61,7 @@ public:
bool isSaveAsAllowed() const override;
void reload();
- Utils::Result reload(ReloadFlag flag, ChangeType type) override;
+ Utils::Result<> reload(ReloadFlag flag, ChangeType type) override;
OpenResult open(QString *errorString, const Utils::FilePath &filePath,
const Utils::FilePath &realFilePath) override;
bool selectEncoding();
@@ -75,7 +75,7 @@ signals:
void descriptionChanged();
protected:
- Utils::Result saveImpl(const Utils::FilePath &filePath, bool autoSave) override;
+ Utils::Result<> saveImpl(const Utils::FilePath &filePath, bool autoSave) override;
private:
void beginReload();
diff --git a/src/plugins/docker/dockercontainerthread.cpp b/src/plugins/docker/dockercontainerthread.cpp
index 298d700b019..38e3cd44570 100644
--- a/src/plugins/docker/dockercontainerthread.cpp
+++ b/src/plugins/docker/dockercontainerthread.cpp
@@ -41,7 +41,7 @@ public:
else
containerId = *create;
- if (Result start = startContainer(); !start)
+ if (Result<> start = startContainer(); !start)
return make_unexpected(start.error());
return containerId;
@@ -70,7 +70,7 @@ private:
return m_containerId;
}
- Result startContainer()
+ Result<> startContainer()
{
using namespace std::chrono_literals;
@@ -82,7 +82,7 @@ private:
m_startProcess->start();
if (!m_startProcess->waitForStarted(5s)) {
if (m_startProcess->state() == QProcess::NotRunning) {
- return Result::Error(
+ return ResultError(
Tr::tr("Failed starting Docker container. Exit code: %1, output: %2")
.arg(m_startProcess->exitCode())
.arg(m_startProcess->allOutput()));
@@ -94,7 +94,7 @@ private:
qCDebug(dockerThreadLog) << "Started container: " << m_startProcess->commandLine();
- return Result::Ok;
+ return ResultOk;
}
private:
@@ -112,15 +112,15 @@ DockerContainerThread::DockerContainerThread(Init init)
m_thread.start();
}
-Result DockerContainerThread::start()
+Result<> DockerContainerThread::start()
{
expected_str<QString> result;
QMetaObject::invokeMethod(m_internal, &Internal::start, Qt::BlockingQueuedConnection, &result);
if (result) {
m_containerId = *result;
- return Result::Ok;
+ return ResultOk;
}
- return Result::Error(result.error());
+ return ResultError(result.error());
}
DockerContainerThread::~DockerContainerThread()
@@ -138,7 +138,7 @@ expected_str<std::unique_ptr<DockerContainerThread>> DockerContainerThread::crea
{
std::unique_ptr<DockerContainerThread> thread(new DockerContainerThread(init));
- if (Result result = thread->start(); !result)
+ if (Result<> result = thread->start(); !result)
return make_unexpected(result.error());
return thread;
diff --git a/src/plugins/docker/dockercontainerthread.h b/src/plugins/docker/dockercontainerthread.h
index 215dd58c790..72c0f7d394e 100644
--- a/src/plugins/docker/dockercontainerthread.h
+++ b/src/plugins/docker/dockercontainerthread.h
@@ -29,7 +29,7 @@ public:
private:
DockerContainerThread(Init init);
- Utils::Result start();
+ Utils::Result<> start();
private:
QThread m_thread;
diff --git a/src/plugins/docker/dockerdevice.cpp b/src/plugins/docker/dockerdevice.cpp
index 0f5483a0352..8f5ac1e52ab 100644
--- a/src/plugins/docker/dockerdevice.cpp
+++ b/src/plugins/docker/dockerdevice.cpp
@@ -229,7 +229,7 @@ public:
if (auto result = updateContainerAccess(); !result)
return make_unexpected(result.error());
- Result initResult = Result::Ok;
+ Result<> initResult = ResultOk;
if (cmdBridgePath->isSameDevice(Docker::Internal::settings().dockerBinaryPath())) {
initResult = fAccess->init(
q->rootPath().withNewPath("/tmp/_qtc_cmdbridge"), q->environment(), false);
@@ -756,10 +756,10 @@ void DockerDevice::shutdown()
d->shutdown();
}
-Result DockerDevice::updateContainerAccess() const
+Result<> DockerDevice::updateContainerAccess() const
{
expected_str<QString> result = d->updateContainerAccess();
- return result ? Result::Ok : Result::Error(result.error());
+ return result ? ResultOk : ResultError(result.error());
}
expected_str<CommandLine> DockerDevicePrivate::withDockerExecCmd(
diff --git a/src/plugins/docker/dockerdevice.h b/src/plugins/docker/dockerdevice.h
index 3a3cf92115c..ed849483fc8 100644
--- a/src/plugins/docker/dockerdevice.h
+++ b/src/plugins/docker/dockerdevice.h
@@ -59,7 +59,7 @@ public:
Utils::expected_str<Utils::Environment> systemEnvironmentWithError() const override;
- Utils::Result updateContainerAccess() const;
+ Utils::Result<> updateContainerAccess() const;
void setMounts(const QStringList &mounts) const;
bool prepareForBuild(const ProjectExplorer::Target *target) override;
diff --git a/src/plugins/docker/dockerdevicewidget.cpp b/src/plugins/docker/dockerdevicewidget.cpp
index a7eaf0384b2..5dd73e66e83 100644
--- a/src/plugins/docker/dockerdevicewidget.cpp
+++ b/src/plugins/docker/dockerdevicewidget.cpp
@@ -104,7 +104,7 @@ DockerDeviceWidget::DockerDeviceWidget(const IDevice::Ptr &device)
this,
[this, logView, dockerDevice, searchPaths] {
logView->clear();
- Result startResult = dockerDevice->updateContainerAccess();
+ Result<> startResult = dockerDevice->updateContainerAccess();
if (!startResult) {
logView->append(Tr::tr("Failed to start container."));
diff --git a/src/plugins/effectcomposer/effectcodeeditorwidget.cpp b/src/plugins/effectcomposer/effectcodeeditorwidget.cpp
index bc14bea53cf..ca5ef0c6a4d 100644
--- a/src/plugins/effectcomposer/effectcodeeditorwidget.cpp
+++ b/src/plugins/effectcomposer/effectcodeeditorwidget.cpp
@@ -86,7 +86,7 @@ void EffectCodeEditorWidget::setEditorTextWithIndentation(const QString &text)
auto *doc = document();
doc->setPlainText(text);
- if (Utils::Result result = textDocument()->save(); !result)
+ if (Utils::Result<> result = textDocument()->save(); !result)
qWarning() << __FUNCTION__ << result.error();
// We don't need to indent an empty text but is also needed for safer text.length()-1 below
diff --git a/src/plugins/extensionmanager/remotespec.cpp b/src/plugins/extensionmanager/remotespec.cpp
index c8f2114b3e9..fe7294f1928 100644
--- a/src/plugins/extensionmanager/remotespec.cpp
+++ b/src/plugins/extensionmanager/remotespec.cpp
@@ -49,14 +49,14 @@ FilePath RemoteSpec::installLocation(bool inUserFolder) const
return {};
};
-Result RemoteSpec::fromJson(const QJsonObject &remoteJsonData)
+Result<> RemoteSpec::fromJson(const QJsonObject &remoteJsonData)
{
qCDebug(remoteSpec).noquote() << "Remote JSON data:"
<< QJsonDocument(remoteJsonData).toJson(QJsonDocument::Indented);
return fromJson(remoteJsonData, remoteJsonData.value("latest").toString());
}
-Utils::Result RemoteSpec::fromJson(const QJsonObject &remoteJsonData, const QString &version)
+Utils::Result<> RemoteSpec::fromJson(const QJsonObject &remoteJsonData, const QString &version)
{
m_remoteJsonData = remoteJsonData;
m_version = version;
@@ -66,15 +66,15 @@ Utils::Result RemoteSpec::fromJson(const QJsonObject &remoteJsonData, const QStr
if (!plugin.isEmpty()) {
auto res = ExtensionSystem::PluginSpec::readMetaData(plugin.value("metadata").toObject());
if (!res)
- return Result::Error(res.error());
+ return ResultError(res.error());
if (hasError())
- return Result::Error(errorString());
- return Result::Ok;
+ return ResultError(errorString());
+ return ResultOk;
}
m_isPack = true;
- return Result::Ok;
+ return ResultOk;
}
std::vector<std::unique_ptr<RemoteSpec>> RemoteSpec::versions() const
diff --git a/src/plugins/extensionmanager/remotespec.h b/src/plugins/extensionmanager/remotespec.h
index a6e274426eb..a787250f5b8 100644
--- a/src/plugins/extensionmanager/remotespec.h
+++ b/src/plugins/extensionmanager/remotespec.h
@@ -45,8 +45,8 @@ public:
ExtensionSystem::IPlugin *plugin() const override;
Utils::FilePath installLocation(bool inUserFolder) const override;
- Utils::Result fromJson(const QJsonObject &remoteJsonData);
- Utils::Result fromJson(const QJsonObject &remoteJsonData, const QString &version);
+ Utils::Result<> fromJson(const QJsonObject &remoteJsonData);
+ Utils::Result<> fromJson(const QJsonObject &remoteJsonData, const QString &version);
QString id() const override;
QString displayName() const override;
diff --git a/src/plugins/git/gitclient.cpp b/src/plugins/git/gitclient.cpp
index 27b24165d50..c1fa1d943ae 100644
--- a/src/plugins/git/gitclient.cpp
+++ b/src/plugins/git/gitclient.cpp
@@ -1593,7 +1593,7 @@ bool GitClient::synchronousAddGitignore(const FilePath &workingDirectory)
Core::GeneratedFile gitIgnoreFile(gitIgnoreDestination);
gitIgnoreFile.setBinaryContents(gitIgnoreTemplate.fileContents().value());
- if (const Result res = gitIgnoreFile.write(); !res) {
+ if (const Result<> res = gitIgnoreFile.write(); !res) {
VcsOutputWindow::appendError(res.error());
return false;
}
diff --git a/src/plugins/imageviewer/imageviewerfile.cpp b/src/plugins/imageviewer/imageviewerfile.cpp
index 177b6fa67d3..9eeee463951 100644
--- a/src/plugins/imageviewer/imageviewerfile.cpp
+++ b/src/plugins/imageviewer/imageviewerfile.cpp
@@ -146,17 +146,17 @@ Core::IDocument::ReloadBehavior ImageViewerFile::reloadBehavior(ChangeTrigger st
return BehaviorAsk;
}
-Result ImageViewerFile::reload(Core::IDocument::ReloadFlag flag,
+Result<> ImageViewerFile::reload(Core::IDocument::ReloadFlag flag,
Core::IDocument::ChangeType type)
{
Q_UNUSED(type)
if (flag == FlagIgnore)
- return Result::Ok;
+ return ResultOk;
emit aboutToReload();
QString errorString;
bool success = (openImpl(&errorString, filePath()) == OpenResult::Success);
emit reloadFinished(success);
- return Result(success, errorString);
+ return makeResult(success, errorString);
}
QMovie *ImageViewerFile::movie() const
diff --git a/src/plugins/imageviewer/imageviewerfile.h b/src/plugins/imageviewer/imageviewerfile.h
index 0936302060b..e4cc432651d 100644
--- a/src/plugins/imageviewer/imageviewerfile.h
+++ b/src/plugins/imageviewer/imageviewerfile.h
@@ -39,7 +39,7 @@ public:
const Utils::FilePath &realFilePath) override;
ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const override;
- Utils::Result reload(ReloadFlag flag, ChangeType type) override;
+ Utils::Result<> reload(ReloadFlag flag, ChangeType type) override;
QMovie *movie() const;
diff --git a/src/plugins/languageclient/languageclientutils.cpp b/src/plugins/languageclient/languageclientutils.cpp
index 9679d07769d..fdfa0b3d37c 100644
--- a/src/plugins/languageclient/languageclientutils.cpp
+++ b/src/plugins/languageclient/languageclientutils.cpp
@@ -389,7 +389,7 @@ bool applyDocumentChange(const Client *client, const DocumentChange &change)
if (!filePath.exists())
return options->ignoreIfNotExists().value_or(false);
if (filePath.isDir() && options->recursive().value_or(false))
- return filePath.removeRecursively();
+ return filePath.removeRecursively().has_value();
}
return bool(filePath.removeFile());
}
diff --git a/src/plugins/lua/bindings/install.cpp b/src/plugins/lua/bindings/install.cpp
index a5a055173f1..9f83181c030 100644
--- a/src/plugins/lua/bindings/install.cpp
+++ b/src/plugins/lua/bindings/install.cpp
@@ -168,7 +168,7 @@ static Group installRecipe(
if (result == DoneWith::Cancel)
return DoneResult::Error;
- Result r = unarchiver.result();
+ Result<> r = unarchiver.result();
if (!r)
return emitResult(r.error());
diff --git a/src/plugins/modeleditor/modeldocument.cpp b/src/plugins/modeleditor/modeldocument.cpp
index b6ffd0d7d5b..3497d597f5b 100644
--- a/src/plugins/modeleditor/modeldocument.cpp
+++ b/src/plugins/modeleditor/modeldocument.cpp
@@ -52,16 +52,16 @@ Core::IDocument::OpenResult ModelDocument::open(QString *errorString,
return result;
}
-Result ModelDocument::saveImpl(const FilePath &filePath, bool autoSave)
+Result<> ModelDocument::saveImpl(const FilePath &filePath, bool autoSave)
{
if (!d->documentController)
- return Result::Error(Tr::tr("No model loaded. Cannot save."));
+ return ResultError(Tr::tr("No model loaded. Cannot save."));
d->documentController->projectController()->setFileName(filePath);
try {
d->documentController->projectController()->save();
} catch (const qmt::Exception &ex) {
- return Result::Error(ex.errorMessage());
+ return ResultError(ex.errorMessage());
}
if (autoSave) {
@@ -71,7 +71,7 @@ Result ModelDocument::saveImpl(const FilePath &filePath, bool autoSave)
emit changed();
}
- return Result::Ok;
+ return ResultOk;
}
bool ModelDocument::shouldAutoSave() const
@@ -89,22 +89,22 @@ bool ModelDocument::isSaveAsAllowed() const
return true;
}
-Result ModelDocument::reload(Core::IDocument::ReloadFlag flag,
+Result<> ModelDocument::reload(Core::IDocument::ReloadFlag flag,
Core::IDocument::ChangeType type)
{
Q_UNUSED(type)
if (flag == FlagIgnore)
- return Result::Ok;
+ return ResultOk;
try {
d->documentController->loadProject(filePath());
} catch (const qmt::FileNotFoundException &ex) {
- return Result::Error(ex.errorMessage());
+ return ResultError(ex.errorMessage());
} catch (const qmt::Exception &ex) {
- return Result::Error(Tr::tr("Could not open \"%1\" for reading: %2.")
+ return ResultError(Tr::tr("Could not open \"%1\" for reading: %2.")
.arg(filePath().toUserOutput(), ex.errorMessage()));
}
emit contentSet();
- return Result::Ok;
+ return ResultOk;
}
ExtDocumentController *ModelDocument::documentController() const
diff --git a/src/plugins/modeleditor/modeldocument.h b/src/plugins/modeleditor/modeldocument.h
index bf70cb74f7e..f36a32db80c 100644
--- a/src/plugins/modeleditor/modeldocument.h
+++ b/src/plugins/modeleditor/modeldocument.h
@@ -33,14 +33,14 @@ public:
bool shouldAutoSave() const override;
bool isModified() const override;
bool isSaveAsAllowed() const override;
- Utils::Result reload(ReloadFlag flag, ChangeType type) override;
+ Utils::Result<> reload(ReloadFlag flag, ChangeType type) override;
ExtDocumentController *documentController() const;
OpenResult load(QString *errorString, const Utils::FilePath &fileName);
protected:
- Utils::Result saveImpl(const Utils::FilePath &filePath, bool autoSave) override;
+ Utils::Result<> saveImpl(const Utils::FilePath &filePath, bool autoSave) override;
private:
ModelDocumentPrivate *d;
diff --git a/src/plugins/perfprofiler/perfprofilertool.cpp b/src/plugins/perfprofiler/perfprofilertool.cpp
index c8e69c784ca..615ed3cb4f8 100644
--- a/src/plugins/perfprofiler/perfprofilertool.cpp
+++ b/src/plugins/perfprofiler/perfprofilertool.cpp
@@ -442,7 +442,7 @@ void PerfProfilerTool::updateRunActions()
const auto canRun = ProjectExplorerPlugin::canRunStartupProject(
ProjectExplorer::Constants::PERFPROFILER_RUN_MODE);
m_startAction->setToolTip(canRun ? Tr::tr("Start a performance analysis.") : canRun.error());
- m_startAction->setEnabled(canRun);
+ m_startAction->setEnabled(canRun.has_value());
m_loadPerfData->setEnabled(true);
m_loadTrace->setEnabled(true);
}
diff --git a/src/plugins/projectexplorer/customwizard/customwizard.cpp b/src/plugins/projectexplorer/customwizard/customwizard.cpp
index 95878735530..65abdf0528c 100644
--- a/src/plugins/projectexplorer/customwizard/customwizard.cpp
+++ b/src/plugins/projectexplorer/customwizard/customwizard.cpp
@@ -246,12 +246,12 @@ GeneratedFiles CustomWizard::generateFiles(const QWizard *dialog, QString *error
return generateWizardFiles(errorMessage);
}
-Result CustomWizard::writeFiles(const GeneratedFiles &files) const
+Result<> CustomWizard::writeFiles(const GeneratedFiles &files) const
{
- if (const Result res = BaseFileWizardFactory::writeFiles(files); !res)
+ if (const Result<> res = BaseFileWizardFactory::writeFiles(files); !res)
return res;
if (d->m_parameters->filesGeneratorScript.isEmpty())
- return Result::Ok;
+ return ResultOk;
// Prepare run of the custom script to generate. In the case of a
// project wizard that is entirely created by a script,
// the target project directory might not exist.
@@ -264,10 +264,10 @@ Result CustomWizard::writeFiles(const GeneratedFiles &files) const
if (CustomWizardPrivate::verbose)
qDebug("Creating directory %s", qPrintable(scriptWorkingDir));
if (!scriptWorkingDirDir.mkpath(scriptWorkingDir))
- return Result::Error(QString("Unable to create the target directory \"%1\"").arg(scriptWorkingDir));
+ return ResultError(QString("Unable to create the target directory \"%1\"").arg(scriptWorkingDir));
}
// Run the custom script to actually generate the files.
- const Result res = runCustomWizardGeneratorScript(scriptWorkingDir,
+ const Result<> res = runCustomWizardGeneratorScript(scriptWorkingDir,
d->m_parameters->filesGeneratorScript,
d->m_parameters->filesGeneratorScriptArguments,
ctx->replacements);
@@ -277,13 +277,13 @@ Result CustomWizard::writeFiles(const GeneratedFiles &files) const
for (const GeneratedFile &generatedFile : files) {
if (generatedFile.attributes() & GeneratedFile::CustomGeneratorAttribute) {
if (!generatedFile.filePath().isFile()) {
- return Result::Error(QString::fromLatin1("%1 failed to generate %2").
+ return ResultError(QString::fromLatin1("%1 failed to generate %2").
arg(d->m_parameters->filesGeneratorScript.back()).
arg(generatedFile.filePath().toUrlishString()));
}
}
}
- return Result::Ok;
+ return ResultOk;
}
GeneratedFiles CustomWizard::generateWizardFiles(QString *errorMessage) const
diff --git a/src/plugins/projectexplorer/customwizard/customwizard.h b/src/plugins/projectexplorer/customwizard/customwizard.h
index 50557ad9ce9..21a07f6cad3 100644
--- a/src/plugins/projectexplorer/customwizard/customwizard.h
+++ b/src/plugins/projectexplorer/customwizard/customwizard.h
@@ -83,7 +83,7 @@ protected:
Core::GeneratedFiles generateWizardFiles(QString *errorMessage) const;
// Create replacement map as static base fields + QWizard fields
FieldReplacementMap replacementMap(const QWizard *w) const;
- Utils::Result writeFiles(const Core::GeneratedFiles &files) const override;
+ Utils::Result<> writeFiles(const Core::GeneratedFiles &files) const override;
CustomWizardParametersPtr parameters() const;
CustomWizardContextPtr context() const;
diff --git a/src/plugins/projectexplorer/customwizard/customwizardscriptgenerator.cpp b/src/plugins/projectexplorer/customwizard/customwizardscriptgenerator.cpp
index b6597a99092..7c78fc17b17 100644
--- a/src/plugins/projectexplorer/customwizard/customwizardscriptgenerator.cpp
+++ b/src/plugins/projectexplorer/customwizard/customwizardscriptgenerator.cpp
@@ -55,7 +55,7 @@ QStringList fixGeneratorScript(const QString &configFile, QString binary)
}
// Helper for running the optional generation script.
-static Result
+static Result<>
runGenerationScriptHelper(const FilePath &workingDirectory,
const QStringList &script,
const QList<GeneratorScriptArgument> &argumentsIn,
@@ -101,14 +101,14 @@ static Result
errorMessage.append(QLatin1Char('\n'));
errorMessage.append(stdErr);
}
- return Result::Error(errorMessage);
+ return ResultError(errorMessage);
}
if (stdOut) {
*stdOut = process.cleanedStdOut();
if (CustomWizard::verbose())
qDebug("Output: '%s'\n", qPrintable(*stdOut));
}
- return Result::Ok;
+ return ResultOk;
}
/*!
@@ -127,7 +127,7 @@ Core::GeneratedFiles
{
// Run in temporary directory as the target path may not exist yet.
QString stdOut;
- const Result res = runGenerationScriptHelper(Utils::TemporaryDirectory::masterDirectoryFilePath(),
+ const Result<> res = runGenerationScriptHelper(Utils::TemporaryDirectory::masterDirectoryFilePath(),
script, arguments, true, fieldMap, &stdOut);
if (!res) {
*errorMessage = res.error();
@@ -207,7 +207,7 @@ Core::GeneratedFiles
\sa dryRunCustomWizardGeneratorScript, ProjectExplorer::CustomWizard
*/
-Result runCustomWizardGeneratorScript(const QString &targetPath,
+Result<> runCustomWizardGeneratorScript(const QString &targetPath,
const QStringList &script,
const QList<GeneratorScriptArgument> &arguments,
const QMap<QString, QString> &fieldMap)
diff --git a/src/plugins/projectexplorer/customwizard/customwizardscriptgenerator.h b/src/plugins/projectexplorer/customwizard/customwizardscriptgenerator.h
index c4cf2f65bbb..57854883909 100644
--- a/src/plugins/projectexplorer/customwizard/customwizardscriptgenerator.h
+++ b/src/plugins/projectexplorer/customwizard/customwizardscriptgenerator.h
@@ -3,13 +3,13 @@
#pragma once
+#include <utils/result.h>
+
#include <QMap>
#include <QStringList>
namespace Core { class GeneratedFile; }
-namespace Utils { class Result; }
-
namespace ProjectExplorer::Internal {
class GeneratorScriptArgument;
@@ -26,7 +26,7 @@ QList<Core::GeneratedFile>
QString *errorMessage);
// Step 2) Generate files
-Utils::Result runCustomWizardGeneratorScript(const QString &targetPath,
+Utils::Result<> runCustomWizardGeneratorScript(const QString &targetPath,
const QStringList &script,
const QList<GeneratorScriptArgument> &arguments,
const QMap<QString, QString> &fieldMap);
diff --git a/src/plugins/projectexplorer/devicesupport/desktopprocesssignaloperation.cpp b/src/plugins/projectexplorer/devicesupport/desktopprocesssignaloperation.cpp
index cb34028179b..8d1ebe7e5dd 100644
--- a/src/plugins/projectexplorer/devicesupport/desktopprocesssignaloperation.cpp
+++ b/src/plugins/projectexplorer/devicesupport/desktopprocesssignaloperation.cpp
@@ -34,7 +34,7 @@ void DesktopProcessSignalOperation::killProcess(qint64 pid)
void DesktopProcessSignalOperation::killProcess(const QString &filePath)
{
- Result result = Result::Ok;
+ Result<> result = ResultOk;
const QList<ProcessInfo> processInfoList = ProcessInfo::processInfoList().value_or(
QList<ProcessInfo>());
for (const ProcessInfo &processInfo : processInfoList) {
@@ -49,27 +49,29 @@ void DesktopProcessSignalOperation::interruptProcess(qint64 pid)
emit finished(interruptProcessSilently(pid));
}
-static Result cannotKillError(qint64 pid, const QString &why)
+static Result<> cannotKillError(qint64 pid, const QString &why)
{
- return Result::Error(Tr::tr("Cannot kill process with pid %1: %2").arg(pid).arg(why));
+ return ResultError(Tr::tr("Cannot kill process with pid %1: %2").arg(pid).arg(why));
}
-static Result appendCannotInterruptError(qint64 pid, const QString &why,
- const Result &previousResult = Result::Ok)
+static Result<> appendCannotInterruptError(qint64 pid, const QString &why,
+ const Result<> &previousResult = ResultOk)
{
- const QString error = Tr::tr("Cannot interrupt process with pid %1: %2").arg(pid).arg(why);
- return Result::Error(previousResult ? QStringList{previousResult, error}.join('\n') : error);
+ QString error = Tr::tr("Cannot interrupt process with pid %1: %2").arg(pid).arg(why);
+ if (previousResult.has_value())
+ error.append('\n' + previousResult.error());
+ return ResultError(error);
}
-Result DesktopProcessSignalOperation::killProcessSilently(qint64 pid)
+Result<> DesktopProcessSignalOperation::killProcessSilently(qint64 pid)
{
#ifdef Q_OS_WIN
const DWORD rights = PROCESS_QUERY_INFORMATION|PROCESS_SET_INFORMATION
|PROCESS_VM_OPERATION|PROCESS_VM_WRITE|PROCESS_VM_READ
|PROCESS_DUP_HANDLE|PROCESS_TERMINATE|PROCESS_CREATE_THREAD|PROCESS_SUSPEND_RESUME;
if (const HANDLE handle = OpenProcess(rights, FALSE, DWORD(pid))) {
- const Result result = TerminateProcess(handle, UINT(-1))
- ? Result::Ok : cannotKillError(pid, winErrorMessage(GetLastError()));
+ const Result<> result = TerminateProcess(handle, UINT(-1))
+ ? ResultOk : cannotKillError(pid, winErrorMessage(GetLastError()));
CloseHandle(handle);
return result;
} else {
@@ -80,13 +82,13 @@ Result DesktopProcessSignalOperation::killProcessSilently(qint64 pid)
return cannotKillError(pid, Tr::tr("Invalid process id."));
else if (kill(pid, SIGKILL))
return cannotKillError(pid, QString::fromLocal8Bit(strerror(errno)));
- return Result::Ok;
+ return ResultOk;
#endif // Q_OS_WIN
}
-Result DesktopProcessSignalOperation::interruptProcessSilently(qint64 pid)
+Result<> DesktopProcessSignalOperation::interruptProcessSilently(qint64 pid)
{
- Result result = Result::Ok;
+ Result<> result = ResultOk;
#ifdef Q_OS_WIN
enum SpecialInterrupt { NoSpecialInterrupt, Win32Interrupt, Win64Interrupt };
@@ -178,7 +180,7 @@ GDB 32bit | Api | Api | N/A | Win32
return appendCannotInterruptError(pid, Tr::tr("Invalid process id."));
else if (kill(pid, SIGINT))
return appendCannotInterruptError(pid, QString::fromLocal8Bit(strerror(errno)));
- return Result::Ok;
+ return ResultOk;
#endif // Q_OS_WIN
}
diff --git a/src/plugins/projectexplorer/devicesupport/desktopprocesssignaloperation.h b/src/plugins/projectexplorer/devicesupport/desktopprocesssignaloperation.h
index 2a5722796ef..aa1797547e7 100644
--- a/src/plugins/projectexplorer/devicesupport/desktopprocesssignaloperation.h
+++ b/src/plugins/projectexplorer/devicesupport/desktopprocesssignaloperation.h
@@ -18,8 +18,8 @@ public:
void interruptProcess(qint64 pid) override;
private:
- Utils::Result killProcessSilently(qint64 pid);
- Utils::Result interruptProcessSilently(qint64 pid);
+ Utils::Result<> killProcessSilently(qint64 pid);
+ Utils::Result<> interruptProcessSilently(qint64 pid);
void appendMsgCannotKill(qint64 pid, const QString &why);
void appendMsgCannotInterrupt(qint64 pid, const QString &why);
diff --git a/src/plugins/projectexplorer/devicesupport/idevice.cpp b/src/plugins/projectexplorer/devicesupport/idevice.cpp
index f017693ef1e..ad8e75d4a06 100644
--- a/src/plugins/projectexplorer/devicesupport/idevice.cpp
+++ b/src/plugins/projectexplorer/devicesupport/idevice.cpp
@@ -748,11 +748,11 @@ DeviceProcessSignalOperation::DeviceProcessSignalOperation() = default;
void DeviceProcessKiller::start()
{
m_signalOperation.reset();
- m_result = Result::Ok;
+ m_result = ResultOk;
const IDevice::ConstPtr device = DeviceManager::deviceForPath(m_processPath);
if (!device) {
- m_result = Result::Error(Tr::tr("No device for given path: \"%1\".")
+ m_result = ResultError(Tr::tr("No device for given path: \"%1\".")
.arg(m_processPath.toUserOutput()));
emit done(DoneResult::Error);
return;
@@ -760,16 +760,16 @@ void DeviceProcessKiller::start()
m_signalOperation = device->signalOperation();
if (!m_signalOperation) {
- m_result = Result::Error(Tr::tr("Device for path \"%1\" does not support killing processes.")
+ m_result = ResultError(Tr::tr("Device for path \"%1\" does not support killing processes.")
.arg(m_processPath.toUserOutput()));
emit done(DoneResult::Error);
return;
}
connect(m_signalOperation.get(), &DeviceProcessSignalOperation::finished,
- this, [this](const Result &result) {
+ this, [this](const Result<> &result) {
m_result = result;
- emit done(toDoneResult(result));
+ emit done(toDoneResult(result.has_value()));
});
m_signalOperation->killProcess(m_processPath.path());
diff --git a/src/plugins/projectexplorer/devicesupport/idevice.h b/src/plugins/projectexplorer/devicesupport/idevice.h
index 104b795aecb..56b528ac0e3 100644
--- a/src/plugins/projectexplorer/devicesupport/idevice.h
+++ b/src/plugins/projectexplorer/devicesupport/idevice.h
@@ -68,7 +68,7 @@ public:
signals:
// If the error message is empty the operation was successful
- void finished(const Utils::Result &result);
+ void finished(const Utils::Result<> &result);
protected:
explicit DeviceProcessSignalOperation();
@@ -308,7 +308,7 @@ class PROJECTEXPLORER_EXPORT DeviceProcessKiller : public QObject
public:
void setProcessPath(const Utils::FilePath &path) { m_processPath = path; }
void start();
- Utils::Result result() const { return m_result; }
+ Utils::Result<> result() const { return m_result; }
signals:
void done(Tasking::DoneResult result);
@@ -316,7 +316,7 @@ signals:
private:
Utils::FilePath m_processPath;
DeviceProcessSignalOperation::Ptr m_signalOperation;
- Utils::Result m_result = Utils::Result::Ok;
+ Utils::Result<> m_result = Utils::ResultOk;
};
using DeviceProcessKillerTask = Tasking::SimpleCustomTask<DeviceProcessKiller>;
diff --git a/src/plugins/projectexplorer/devicesupport/processlist.cpp b/src/plugins/projectexplorer/devicesupport/processlist.cpp
index 970890f0637..5282bdbf88d 100644
--- a/src/plugins/projectexplorer/devicesupport/processlist.cpp
+++ b/src/plugins/projectexplorer/devicesupport/processlist.cpp
@@ -136,7 +136,7 @@ void ProcessList::killProcess(int row)
const ProcessInfo processInfo = at(row);
d->signalOperation = d->device->signalOperation();
connect(d->signalOperation.get(), &DeviceProcessSignalOperation::finished,
- this, [this](const Result &result) {
+ this, [this](const Result<> &result) {
if (result) {
QTC_CHECK(d->state == Killing);
setFinished();
diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp b/src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp
index 51de0d19a3d..4416378154c 100644
--- a/src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp
+++ b/src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp
@@ -351,7 +351,7 @@ void JsonWizard::accept()
}
emit preFormatFiles(m_files);
- if (const Result res = JsonWizardGenerator::formatFiles(this, &m_files); !res) {
+ if (const Result<> res = JsonWizardGenerator::formatFiles(this, &m_files); !res) {
QMessageBox::warning(this, Tr::tr("Failed to Format Files"), res.error());
return;
}
@@ -365,23 +365,23 @@ void JsonWizard::accept()
Core::EditorManager::closeDocuments(documentsToClose, /*askAboutModifiedEditors=*/false);
emit preWriteFiles(m_files);
- if (const Result res = JsonWizardGenerator::writeFiles(this, &m_files); !res) {
+ if (const Result<> res = JsonWizardGenerator::writeFiles(this, &m_files); !res) {
QMessageBox::warning(this, Tr::tr("Failed to Write Files"), res.error());
return;
}
emit postProcessFiles(m_files);
- if (const Result res = JsonWizardGenerator::postWrite(this, &m_files); !res) {
+ if (const Result<> res = JsonWizardGenerator::postWrite(this, &m_files); !res) {
QMessageBox::warning(this, Tr::tr("Failed to Post-Process Files"), res.error());
return;
}
emit filesReady(m_files);
- if (const Result res = JsonWizardGenerator::polish(this, &m_files); !res) {
+ if (const Result<> res = JsonWizardGenerator::polish(this, &m_files); !res) {
QMessageBox::warning(this, Tr::tr("Failed to Polish Files"), res.error());
return;
}
emit filesPolished(m_files);
- if (const Result res = JsonWizardGenerator::allDone(this, &m_files); !res) {
+ if (const Result<> res = JsonWizardGenerator::allDone(this, &m_files); !res) {
QMessageBox::warning(this, Tr::tr("Failed to Open Files"), res.error());
return;
}
diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizardfactory.cpp b/src/plugins/projectexplorer/jsonwizard/jsonwizardfactory.cpp
index e8eccd3430f..cbc481e5952 100644
--- a/src/plugins/projectexplorer/jsonwizard/jsonwizardfactory.cpp
+++ b/src/plugins/projectexplorer/jsonwizard/jsonwizardfactory.cpp
@@ -177,7 +177,7 @@ static JsonWizardFactory::Generator parseGenerator(const QVariant &value, QStrin
}
QVariant varVal = data.value(QLatin1String(DATA_KEY));
- if (const Result res = factory->validateData(typeId, varVal); !res) {
+ if (const Result<> res = factory->validateData(typeId, varVal); !res) {
*errorMessage = res.error();
return gen;
}
diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizardfilegenerator.cpp b/src/plugins/projectexplorer/jsonwizard/jsonwizardfilegenerator.cpp
index 14cdfbeee49..d23d903456e 100644
--- a/src/plugins/projectexplorer/jsonwizard/jsonwizardfilegenerator.cpp
+++ b/src/plugins/projectexplorer/jsonwizard/jsonwizardfilegenerator.cpp
@@ -28,14 +28,14 @@ namespace ProjectExplorer::Internal {
class JsonWizardFileGenerator final : public JsonWizardGenerator
{
public:
- Utils::Result setup(const QVariant &data);
+ Utils::Result<> setup(const QVariant &data);
Core::GeneratedFiles fileList(MacroExpander *expander,
const FilePath &wizardDir,
const FilePath &projectDir,
QString *errorMessage) final;
- Utils::Result writeFile(const JsonWizard *wizard, Core::GeneratedFile *file) final;
+ Utils::Result<> writeFile(const JsonWizard *wizard, Core::GeneratedFile *file) final;
private:
class File {
@@ -70,16 +70,16 @@ private:
}
};
-Result JsonWizardFileGenerator::setup(const QVariant &data)
+Result<> JsonWizardFileGenerator::setup(const QVariant &data)
{
QString errorMessage;
const QVariantList list = JsonWizardFactory::objectOrList(data, &errorMessage);
if (list.isEmpty())
- return Result::Error(errorMessage);
+ return ResultError(errorMessage);
for (const QVariant &d : list) {
if (d.typeId() != QMetaType::QVariantMap)
- return Result::Error(Tr::tr("Files data list entry is not an object."));
+ return ResultError(Tr::tr("Files data list entry is not an object."));
File f;
@@ -95,10 +95,10 @@ Result JsonWizardFileGenerator::setup(const QVariant &data)
f.options = JsonWizard::parseOptions(tmp.value(QLatin1String("options")), &errorMessage);
if (!errorMessage.isEmpty())
- return Result::Error(errorMessage);
+ return ResultError(errorMessage);
if (f.source.isEmpty() && f.target.isEmpty())
- return Result::Error(Tr::tr("Source and target are both empty."));
+ return ResultError(Tr::tr("Source and target are both empty."));
if (f.target.isEmpty())
f.target = f.source;
@@ -106,7 +106,7 @@ Result JsonWizardFileGenerator::setup(const QVariant &data)
m_fileList << f;
}
- return Result::Ok;
+ return ResultOk;
}
Core::GeneratedFile JsonWizardFileGenerator::generateFile(const File &file,
@@ -248,11 +248,11 @@ Core::GeneratedFiles JsonWizardFileGenerator::fileList(MacroExpander *expander,
return result;
}
-Result JsonWizardFileGenerator::writeFile(const JsonWizard *wizard, Core::GeneratedFile *file)
+Result<> JsonWizardFileGenerator::writeFile(const JsonWizard *wizard, Core::GeneratedFile *file)
{
Q_UNUSED(wizard)
if (file->attributes() & Core::GeneratedFile::KeepExistingFileAttribute)
- return Result::Ok;
+ return ResultOk;
return file->write();
}
diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizardgeneratorfactory.cpp b/src/plugins/projectexplorer/jsonwizard/jsonwizardgeneratorfactory.cpp
index 552eb370e42..02e307ce405 100644
--- a/src/plugins/projectexplorer/jsonwizard/jsonwizardgeneratorfactory.cpp
+++ b/src/plugins/projectexplorer/jsonwizard/jsonwizardgeneratorfactory.cpp
@@ -57,15 +57,15 @@ static ICodeStylePreferences *codeStylePreferences(Project *project, Id language
// JsonWizardGenerator:
// --------------------------------------------------------------------
-Result JsonWizardGenerator::formatFile(const JsonWizard *wizard, GeneratedFile *file)
+Result<> JsonWizardGenerator::formatFile(const JsonWizard *wizard, GeneratedFile *file)
{
if (file->isBinary() || file->contents().isEmpty())
- return Result::Ok; // nothing to do
+ return ResultOk; // nothing to do
Id languageId = TextEditorSettings::languageId(Utils::mimeTypeForFile(file->filePath()).name());
if (!languageId.isValid())
- return Result::Ok; // don't modify files like *.ui, *.pro
+ return ResultOk; // don't modify files like *.ui, *.pro
auto baseProject = qobject_cast<Project *>(wizard->property("SelectedProject").value<QObject *>());
ICodeStylePreferencesFactory *factory = TextEditorSettings::codeStyleFactory(languageId);
@@ -96,35 +96,35 @@ Result JsonWizardGenerator::formatFile(const JsonWizard *wizard, GeneratedFile *
}
file->setContents(doc.toPlainText());
- return Result::Ok;
+ return ResultOk;
}
-Result JsonWizardGenerator::writeFile(const JsonWizard *wizard, GeneratedFile *file)
+Result<> JsonWizardGenerator::writeFile(const JsonWizard *wizard, GeneratedFile *file)
{
Q_UNUSED(wizard)
Q_UNUSED(file)
- return Result::Ok;
+ return ResultOk;
}
-Result JsonWizardGenerator::postWrite(const JsonWizard *wizard, GeneratedFile *file)
+Result<> JsonWizardGenerator::postWrite(const JsonWizard *wizard, GeneratedFile *file)
{
Q_UNUSED(wizard)
Q_UNUSED(file)
- return Result::Ok;
+ return ResultOk;
}
-Result JsonWizardGenerator::polish(const JsonWizard *wizard, GeneratedFile *file)
+Result<> JsonWizardGenerator::polish(const JsonWizard *wizard, GeneratedFile *file)
{
Q_UNUSED(wizard)
Q_UNUSED(file)
- return Result::Ok;
+ return ResultOk;
}
-Result JsonWizardGenerator::allDone(const JsonWizard *wizard, GeneratedFile *file)
+Result<> JsonWizardGenerator::allDone(const JsonWizard *wizard, GeneratedFile *file)
{
Q_UNUSED(wizard)
Q_UNUSED(file)
- return Result::Ok;
+ return ResultOk;
}
JsonWizardGenerator::OverwriteResult JsonWizardGenerator::promptForOverwrite(JsonWizard::GeneratorFiles *files,
@@ -197,49 +197,49 @@ JsonWizardGenerator::OverwriteResult JsonWizardGenerator::promptForOverwrite(Jso
return OverwriteOk;
}
-Result JsonWizardGenerator::formatFiles(const JsonWizard *wizard, JsonWizard::GeneratorFiles *files)
+Result<> JsonWizardGenerator::formatFiles(const JsonWizard *wizard, JsonWizard::GeneratorFiles *files)
{
for (auto i = files->begin(); i != files->end(); ++i) {
- if (const Result res = i->generator->formatFile(wizard, &(i->file)); !res)
+ if (const Result<> res = i->generator->formatFile(wizard, &(i->file)); !res)
return res;
}
- return Result::Ok;
+ return ResultOk;
}
-Result JsonWizardGenerator::writeFiles(const JsonWizard *wizard, JsonWizard::GeneratorFiles *files)
+Result<> JsonWizardGenerator::writeFiles(const JsonWizard *wizard, JsonWizard::GeneratorFiles *files)
{
for (auto i = files->begin(); i != files->end(); ++i) {
- if (const Result res = i->generator->writeFile(wizard, &(i->file)); !res)
+ if (const Result<> res = i->generator->writeFile(wizard, &(i->file)); !res)
return res;
}
- return Result::Ok;
+ return ResultOk;
}
-Result JsonWizardGenerator::postWrite(const JsonWizard *wizard, JsonWizard::GeneratorFiles *files)
+Result<> JsonWizardGenerator::postWrite(const JsonWizard *wizard, JsonWizard::GeneratorFiles *files)
{
for (auto i = files->begin(); i != files->end(); ++i) {
- if (const Result res = i->generator->postWrite(wizard, &(i->file)); !res)
+ if (const Result<> res = i->generator->postWrite(wizard, &(i->file)); !res)
return res;
}
- return Result::Ok;
+ return ResultOk;
}
-Result JsonWizardGenerator::polish(const JsonWizard *wizard, JsonWizard::GeneratorFiles *files)
+Result<> JsonWizardGenerator::polish(const JsonWizard *wizard, JsonWizard::GeneratorFiles *files)
{
for (auto i = files->begin(); i != files->end(); ++i) {
- if (const Result res = i->generator->polish(wizard, &(i->file)); !res)
+ if (const Result<> res = i->generator->polish(wizard, &(i->file)); !res)
return res;
}
- return Result::Ok;
+ return ResultOk;
}
-Result JsonWizardGenerator::allDone(const JsonWizard *wizard, JsonWizard::GeneratorFiles *files)
+Result<> JsonWizardGenerator::allDone(const JsonWizard *wizard, JsonWizard::GeneratorFiles *files)
{
for (auto i = files->begin(); i != files->end(); ++i) {
- if (const Result res = i->generator->allDone(wizard, &(i->file)); !res)
+ if (const Result<> res = i->generator->allDone(wizard, &(i->file)); !res)
return res;
}
- return Result::Ok;
+ return ResultOk;
}
// --------------------------------------------------------------------
diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizardgeneratorfactory.h b/src/plugins/projectexplorer/jsonwizard/jsonwizardgeneratorfactory.h
index 8b66aef450d..0dd510002f6 100644
--- a/src/plugins/projectexplorer/jsonwizard/jsonwizardgeneratorfactory.h
+++ b/src/plugins/projectexplorer/jsonwizard/jsonwizardgeneratorfactory.h
@@ -24,22 +24,22 @@ public:
virtual Core::GeneratedFiles fileList(Utils::MacroExpander *expander,
const Utils::FilePath &wizardDir, const Utils::FilePath &projectDir,
QString *errorMessage) = 0;
- virtual Utils::Result formatFile(const JsonWizard *wizard, Core::GeneratedFile *file);
- virtual Utils::Result writeFile(const JsonWizard *wizard, Core::GeneratedFile *file);
- virtual Utils::Result postWrite(const JsonWizard *wizard, Core::GeneratedFile *file);
- virtual Utils::Result polish(const JsonWizard *wizard, Core::GeneratedFile *file);
- virtual Utils::Result allDone(const JsonWizard *wizard, Core::GeneratedFile *file);
+ virtual Utils::Result<> formatFile(const JsonWizard *wizard, Core::GeneratedFile *file);
+ virtual Utils::Result<> writeFile(const JsonWizard *wizard, Core::GeneratedFile *file);
+ virtual Utils::Result<> postWrite(const JsonWizard *wizard, Core::GeneratedFile *file);
+ virtual Utils::Result<> polish(const JsonWizard *wizard, Core::GeneratedFile *file);
+ virtual Utils::Result<> allDone(const JsonWizard *wizard, Core::GeneratedFile *file);
virtual bool canKeepExistingFiles() const { return true; }
enum OverwriteResult { OverwriteOk, OverwriteError, OverwriteCanceled };
static OverwriteResult promptForOverwrite(JsonWizard::GeneratorFiles *files, QString *errorMessage);
- static Utils::Result formatFiles(const JsonWizard *wizard, QList<JsonWizard::GeneratorFile> *files);
- static Utils::Result writeFiles(const JsonWizard *wizard, JsonWizard::GeneratorFiles *files);
- static Utils::Result postWrite(const JsonWizard *wizard, JsonWizard::GeneratorFiles *files);
- static Utils::Result polish(const JsonWizard *wizard, JsonWizard::GeneratorFiles *files);
- static Utils::Result allDone(const JsonWizard *wizard, JsonWizard::GeneratorFiles *files);
+ static Utils::Result<> formatFiles(const JsonWizard *wizard, QList<JsonWizard::GeneratorFile> *files);
+ static Utils::Result<> writeFiles(const JsonWizard *wizard, JsonWizard::GeneratorFiles *files);
+ static Utils::Result<> postWrite(const JsonWizard *wizard, JsonWizard::GeneratorFiles *files);
+ static Utils::Result<> polish(const JsonWizard *wizard, JsonWizard::GeneratorFiles *files);
+ static Utils::Result<> allDone(const JsonWizard *wizard, JsonWizard::GeneratorFiles *files);
};
class PROJECTEXPLORER_EXPORT JsonWizardGeneratorFactory : public QObject
@@ -58,7 +58,7 @@ public:
const QVariantMap &variables) = 0;
// Basic syntax check for the data taken from the wizard.json file:
- virtual Utils::Result validateData(Utils::Id typeId, const QVariant &data) = 0;
+ virtual Utils::Result<> validateData(Utils::Id typeId, const QVariant &data) = 0;
protected:
// This will add "PE.Wizard.Generator." in front of the suffixes and set those as supported typeIds
@@ -85,7 +85,7 @@ public:
QTC_ASSERT(canCreate(typeId), return nullptr);
auto gen = new Generator;
- const Utils::Result res = gen->setup(data);
+ const Utils::Result<> res = gen->setup(data);
if (!res) {
qWarning() << "JsonWizardGeneratorTypedFactory for " << typeId << "setup error:"
@@ -96,9 +96,9 @@ public:
return gen;
}
- Utils::Result validateData(Utils::Id typeId, const QVariant &data) final
+ Utils::Result<> validateData(Utils::Id typeId, const QVariant &data) final
{
- QTC_ASSERT(canCreate(typeId), return Utils::Result::Error("Cannot create type"));
+ QTC_ASSERT(canCreate(typeId), return Utils::ResultError("Cannot create type"));
QScopedPointer<Generator> gen(new Generator);
return gen->setup(data);
}
diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizardscannergenerator.cpp b/src/plugins/projectexplorer/jsonwizard/jsonwizardscannergenerator.cpp
index e12ca8115f1..7c6e5aef5c1 100644
--- a/src/plugins/projectexplorer/jsonwizard/jsonwizardscannergenerator.cpp
+++ b/src/plugins/projectexplorer/jsonwizard/jsonwizardscannergenerator.cpp
@@ -25,7 +25,7 @@ namespace ProjectExplorer::Internal {
class JsonWizardScannerGenerator final : public JsonWizardGenerator
{
public:
- Result setup(const QVariant &data);
+ Result<> setup(const QVariant &data);
Core::GeneratedFiles fileList(MacroExpander *expander,
const FilePath &wizardDir,
@@ -39,13 +39,13 @@ private:
QList<QRegularExpression> m_subDirectoryExpressions;
};
-Result JsonWizardScannerGenerator::setup(const QVariant &data)
+Result<> JsonWizardScannerGenerator::setup(const QVariant &data)
{
if (data.isNull())
- return Result::Ok;
+ return ResultOk;
if (data.typeId() != QMetaType::QVariantMap)
- return Result::Error(Tr::tr("Key is not an object."));
+ return ResultError(Tr::tr("Key is not an object."));
QVariantMap gen = data.toMap();
@@ -54,11 +54,11 @@ Result JsonWizardScannerGenerator::setup(const QVariant &data)
for (const QString &pattern : patterns) {
QRegularExpression regexp(pattern);
if (!regexp.isValid())
- return Result::Error(Tr::tr("Pattern \"%1\" is no valid regular expression."));
+ return ResultError(Tr::tr("Pattern \"%1\" is no valid regular expression."));
m_subDirectoryExpressions << regexp;
}
- return Result::Ok;
+ return ResultOk;
}
Core::GeneratedFiles JsonWizardScannerGenerator::fileList(Utils::MacroExpander *expander,
diff --git a/src/plugins/projectexplorer/project.cpp b/src/plugins/projectexplorer/project.cpp
index c56279414c1..6ca51c2cedf 100644
--- a/src/plugins/projectexplorer/project.cpp
+++ b/src/plugins/projectexplorer/project.cpp
@@ -144,13 +144,13 @@ public:
return BehaviorSilent;
}
- Result reload(ReloadFlag flag, ChangeType type) final
+ Result<> reload(ReloadFlag flag, ChangeType type) final
{
Q_UNUSED(flag)
Q_UNUSED(type)
emit m_project->projectFileIsDirty(filePath());
- return Result::Ok;
+ return ResultOk;
}
private:
diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp
index a827c665658..1c369addda9 100644
--- a/src/plugins/projectexplorer/projectexplorer.cpp
+++ b/src/plugins/projectexplorer/projectexplorer.cpp
@@ -3142,32 +3142,32 @@ void ProjectExplorerPluginPrivate::updateDeployActions()
doUpdateRunActions();
}
-Result ProjectExplorerPlugin::canRunStartupProject(Utils::Id runMode)
+Result<> ProjectExplorerPlugin::canRunStartupProject(Utils::Id runMode)
{
Project *project = ProjectManager::startupProject();
if (!project)
- return Result::Error(Tr::tr("No active project."));
+ return ResultError(Tr::tr("No active project."));
if (project->needsConfiguration()) {
- return Result::Error(Tr::tr("The project \"%1\" is not configured.")
+ return ResultError(Tr::tr("The project \"%1\" is not configured.")
.arg(project->displayName()));
}
Kit *kit = project->activeKit();
if (!kit) {
- return Result::Error(Tr::tr("The project \"%1\" has no active kit.")
+ return ResultError(Tr::tr("The project \"%1\" has no active kit.")
.arg(project->displayName()));
}
RunConfiguration *activeRC = project->activeRunConfiguration();
if (!activeRC) {
- return Result::Error(
+ return ResultError(
Tr::tr("The kit \"%1\" for the project \"%2\" has no active run configuration.")
.arg(kit->displayName(), project->displayName()));
}
if (!activeRC->isEnabled(runMode))
- return Result::Error(activeRC->disabledReason(runMode));
+ return ResultError(activeRC->disabledReason(runMode));
if (projectExplorerSettings().buildBeforeDeploy != BuildBeforeRunMode::Off
&& projectExplorerSettings().deployBeforeRun
@@ -3175,28 +3175,28 @@ Result ProjectExplorerPlugin::canRunStartupProject(Utils::Id runMode)
&& hasBuildSettings(project)) {
QPair<bool, QString> buildState = dd->buildSettingsEnabled(project);
if (!buildState.first)
- return Result::Error(buildState.second);
+ return ResultError(buildState.second);
if (BuildManager::isBuilding())
- return Result::Error(Tr::tr("A build is still in progress."));
+ return ResultError(Tr::tr("A build is still in progress."));
}
// shouldn't actually be shown to the user...
if (!RunControl::canRun(runMode, RunDeviceTypeKitAspect::deviceTypeId(kit), activeRC->id()))
- return Result::Error(Tr::tr("Cannot run \"%1\".").arg(activeRC->displayName()));
+ return ResultError(Tr::tr("Cannot run \"%1\".").arg(activeRC->displayName()));
if (dd->m_delayedRunConfiguration && dd->m_delayedRunConfiguration->project() == project)
- return Result::Error(Tr::tr("A run action is already scheduled for the active project."));
+ return ResultError(Tr::tr("A run action is already scheduled for the active project."));
- return Result::Ok;
+ return ResultOk;
}
void ProjectExplorerPluginPrivate::doUpdateRunActions()
{
- const auto canRun = ProjectExplorerPlugin::canRunStartupProject(Constants::NORMAL_RUN_MODE);
- m_runAction->setEnabled(canRun);
- m_runAction->setToolTip(canRun.error());
- m_runWithoutDeployAction->setEnabled(canRun);
+ const Result<> canRun = ProjectExplorerPlugin::canRunStartupProject(Constants::NORMAL_RUN_MODE);
+ m_runAction->setEnabled(canRun.has_value());
+ m_runAction->setToolTip(canRun.has_value() ? QString() : canRun.error());
+ m_runWithoutDeployAction->setEnabled(canRun.has_value());
emit m_instance->runActionsUpdated();
}
diff --git a/src/plugins/projectexplorer/projectexplorer.h b/src/plugins/projectexplorer/projectexplorer.h
index e35dd4442b4..e23bde1c232 100644
--- a/src/plugins/projectexplorer/projectexplorer.h
+++ b/src/plugins/projectexplorer/projectexplorer.h
@@ -133,7 +133,7 @@ public:
static void renameFilesForSymbol(const QString &oldSymbolName, const QString &newSymbolName,
const Utils::FilePaths &files, bool preferLowerCaseFileNames);
- static Utils::Result canRunStartupProject(Utils::Id runMode);
+ static Utils::Result<> canRunStartupProject(Utils::Id runMode);
static void runProject(Project *pro, Utils::Id, const bool forceSkipDeploy = false);
static void runStartupProject(Utils::Id runMode, bool forceSkipDeploy = false);
static void runRunConfiguration(RunConfiguration *rc, Utils::Id runMode,
diff --git a/src/plugins/projectexplorer/taskfile.cpp b/src/plugins/projectexplorer/taskfile.cpp
index bcb06611ac2..63e766c0c77 100644
--- a/src/plugins/projectexplorer/taskfile.cpp
+++ b/src/plugins/projectexplorer/taskfile.cpp
@@ -45,17 +45,17 @@ Core::IDocument::ReloadBehavior TaskFile::reloadBehavior(ChangeTrigger state, Ch
return BehaviorSilent;
}
-Result TaskFile::reload(ReloadFlag flag, ChangeType type)
+Result<> TaskFile::reload(ReloadFlag flag, ChangeType type)
{
Q_UNUSED(flag)
if (type == TypeRemoved) {
deleteLater();
- return Result::Ok;
+ return ResultOk;
}
QString errorString;
bool success = load(&errorString, filePath());
- return Result(success, errorString);
+ return makeResult(success, errorString);
}
static Task::TaskType typeFrom(const QString &typeName)
diff --git a/src/plugins/projectexplorer/taskfile.h b/src/plugins/projectexplorer/taskfile.h
index abccdd29c5a..95c8a253d83 100644
--- a/src/plugins/projectexplorer/taskfile.h
+++ b/src/plugins/projectexplorer/taskfile.h
@@ -24,7 +24,7 @@ public:
TaskFile(QObject *parent);
ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const override;
- Utils::Result reload(ReloadFlag flag, ChangeType type) override;
+ Utils::Result<> reload(ReloadFlag flag, ChangeType type) override;
bool load(QString *errorString, const Utils::FilePath &fileName);
diff --git a/src/plugins/qmakeprojectmanager/qmakeparsernodes.cpp b/src/plugins/qmakeprojectmanager/qmakeparsernodes.cpp
index 989dd09a987..0bd032ba12f 100644
--- a/src/plugins/qmakeprojectmanager/qmakeparsernodes.cpp
+++ b/src/plugins/qmakeprojectmanager/qmakeparsernodes.cpp
@@ -916,7 +916,7 @@ void QmakePriFile::save(const QStringList &lines)
{
QTC_ASSERT(m_textFormat.codec(), return);
FileChangeBlocker changeGuard(filePath());
- if (const Result res = m_textFormat.writeFile(filePath(), lines.join('\n')); !res)
+ if (const Result<> res = m_textFormat.writeFile(filePath(), lines.join('\n')); !res)
QMessageBox::critical(Core::ICore::dialogParent(), Tr::tr("File Error"), res.error());
}
@@ -928,7 +928,7 @@ void QmakePriFile::save(const QStringList &lines)
QStringList errorStrings;
Core::IDocument *document = Core::DocumentModel::documentForFilePath(filePath());
if (document) {
- Result res = document->reload(Core::IDocument::FlagReload, Core::IDocument::TypeContents);
+ Result<> res = document->reload(Core::IDocument::FlagReload, Core::IDocument::TypeContents);
if (!res)
errorStrings << res.error();
}
diff --git a/src/plugins/qmakeprojectmanager/qmakeproject.cpp b/src/plugins/qmakeprojectmanager/qmakeproject.cpp
index 2a843ac94f0..cd60e9da6e6 100644
--- a/src/plugins/qmakeprojectmanager/qmakeproject.cpp
+++ b/src/plugins/qmakeprojectmanager/qmakeproject.cpp
@@ -103,13 +103,13 @@ public:
Q_UNUSED(type)
return BehaviorSilent;
}
- Result reload(ReloadFlag flag, ChangeType type) override
+ Result<> reload(ReloadFlag flag, ChangeType type) override
{
Q_UNUSED(flag)
Q_UNUSED(type)
if (m_priFile)
m_priFile->scheduleUpdate();
- return Result::Ok;
+ return ResultOk;
}
void setPriFile(QmakePriFile *priFile) { m_priFile = priFile; }
diff --git a/src/plugins/qmldesigner/components/assetslibrary/assetslibrarymodel.cpp b/src/plugins/qmldesigner/components/assetslibrary/assetslibrarymodel.cpp
index f68fd388d66..48e18d49b36 100644
--- a/src/plugins/qmldesigner/components/assetslibrary/assetslibrarymodel.cpp
+++ b/src/plugins/qmldesigner/components/assetslibrary/assetslibrarymodel.cpp
@@ -175,7 +175,7 @@ QString AssetsLibraryModel::addNewFolder(const QString &folderPath)
{
Utils::FilePath uniqueDirPath = Utils::FilePath::fromString(UniqueName::generatePath(folderPath));
- const Utils::Result res = uniqueDirPath.ensureWritableDir();
+ const Utils::Result<> res = uniqueDirPath.ensureWritableDir();
if (!res) {
qWarning() << __FUNCTION__ << res.error();
return {};
diff --git a/src/plugins/qmldesigner/documentmanager.cpp b/src/plugins/qmldesigner/documentmanager.cpp
index 72234568f07..14053312a70 100644
--- a/src/plugins/qmldesigner/documentmanager.cpp
+++ b/src/plugins/qmldesigner/documentmanager.cpp
@@ -317,7 +317,7 @@ bool DocumentManager::createFile(const QString &filePath, const QString &content
TextFileFormat textFileFormat;
textFileFormat.setCodecName(Core::EditorManager::defaultTextCodecName());
- return textFileFormat.writeFile(FilePath::fromString(filePath), contents);
+ return textFileFormat.writeFile(FilePath::fromString(filePath), contents).has_value();
}
void DocumentManager::addFileToVersionControl(const QString &directoryPath, const QString &newFilePath)
diff --git a/src/plugins/qmldesigner/libs/qmldesignerutils/fileextractor.cpp b/src/plugins/qmldesigner/libs/qmldesignerutils/fileextractor.cpp
index 137e266a94d..ea3dcde82ec 100644
--- a/src/plugins/qmldesigner/libs/qmldesignerutils/fileextractor.cpp
+++ b/src/plugins/qmldesigner/libs/qmldesignerutils/fileextractor.cpp
@@ -243,9 +243,9 @@ void FileExtractor::extract()
qWarning() << "Compressed size for file '" << m_sourceFile << "' is zero or invalid: " << m_compressedSize;
QObject::connect(m_unarchiver.get(), &Unarchiver::done, this, [this]() {
- Result r = m_unarchiver->result();
+ Result<> r = m_unarchiver->result();
m_unarchiver.reset();
- m_finished = r;
+ m_finished = r.has_value();
m_timer.stop();
m_progress = 100;
diff --git a/src/plugins/qmlprofiler/qmlprofilertool.cpp b/src/plugins/qmlprofiler/qmlprofilertool.cpp
index c2bf5a17f9a..5b68a3ecccf 100644
--- a/src/plugins/qmlprofiler/qmlprofilertool.cpp
+++ b/src/plugins/qmlprofiler/qmlprofilertool.cpp
@@ -347,7 +347,7 @@ void QmlProfilerTool::updateRunActions()
ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
d->m_startAction->setToolTip(canRun ? Tr::tr("Start QML Profiler analysis.")
: canRun.error());
- d->m_startAction->setEnabled(canRun);
+ d->m_startAction->setEnabled(canRun.has_value());
d->m_stopAction->setEnabled(false);
}
}
diff --git a/src/plugins/qmlprojectmanager/buildsystem/qmlbuildsystem.cpp b/src/plugins/qmlprojectmanager/buildsystem/qmlbuildsystem.cpp
index 8ff437fea85..023b18438e5 100644
--- a/src/plugins/qmlprojectmanager/buildsystem/qmlbuildsystem.cpp
+++ b/src/plugins/qmlprojectmanager/buildsystem/qmlbuildsystem.cpp
@@ -354,7 +354,7 @@ bool QmlBuildSystem::setFileSettingInProjectFile(const QString &setting,
fileContent.replace(match.capturedStart(1), match.capturedLength(1), relativePath);
}
- if (const Result res = textFileFormat.writeFile(qmlProjectFilePath, fileContent); !res)
+ if (const Result<> res = textFileFormat.writeFile(qmlProjectFilePath, fileContent); !res)
qWarning() << "Failed to write file" << qmlProjectFilePath << ":" << res.error();
refresh(RefreshOptions::Project);
@@ -503,7 +503,7 @@ bool QmlBuildSystem::setMainUiFileInMainFile(const Utils::FilePath &newMainUiFil
if (fileContent.contains(currentMain))
fileContent.replace(currentMain, newMain);
- if (const Result res = textFileFormat.writeFile(mainFilePath(), fileContent); !res)
+ if (const Result<> res = textFileFormat.writeFile(mainFilePath(), fileContent); !res)
qWarning() << "Failed to write file" << mainFilePath() << ":" << res.error();
return true;
diff --git a/src/plugins/qtsupport/gettingstartedwelcomepage.cpp b/src/plugins/qtsupport/gettingstartedwelcomepage.cpp
index d60b2fcaabd..9b6a017a702 100644
--- a/src/plugins/qtsupport/gettingstartedwelcomepage.cpp
+++ b/src/plugins/qtsupport/gettingstartedwelcomepage.cpp
@@ -140,7 +140,7 @@ static FilePath copyToAlternativeLocation(const FilePath &proFile,
QMessageBox::NoButton);
return {};
} else {
- Result result = projectDir.copyRecursively(targetDir);
+ Result<> result = projectDir.copyRecursively(targetDir);
if (result) {
// set vars to new location
diff --git a/src/plugins/remotelinux/filesystemaccess_test.cpp b/src/plugins/remotelinux/filesystemaccess_test.cpp
index 65606155422..b231ab91d83 100644
--- a/src/plugins/remotelinux/filesystemaccess_test.cpp
+++ b/src/plugins/remotelinux/filesystemaccess_test.cpp
@@ -367,7 +367,7 @@ void FileSystemAccessTest::testFileTransfer()
// Cleanup remote
const FilePath remoteDir = m_device->filePath(QString("/tmp/foo/"));
- Result removeResult = remoteDir.removeRecursively();
+ Result<> removeResult = remoteDir.removeRecursively();
QVERIFY2(removeResult, qPrintable(removeResult.error()));
}
diff --git a/src/plugins/remotelinux/genericdeploystep.cpp b/src/plugins/remotelinux/genericdeploystep.cpp
index f5090d0e496..d7d38169e1f 100644
--- a/src/plugins/remotelinux/genericdeploystep.cpp
+++ b/src/plugins/remotelinux/genericdeploystep.cpp
@@ -72,7 +72,7 @@ private:
GroupItem GenericDeployStep::mkdirTask(const Storage<FilesToTransfer> &storage)
{
- const auto onSetup = [storage](Async<Result> &async) {
+ const auto onSetup = [storage](Async<Result<>> &async) {
FilePaths remoteDirs;
for (const FileToTransfer &file : *storage)
remoteDirs << file.m_target.parentDir();
@@ -80,9 +80,9 @@ GroupItem GenericDeployStep::mkdirTask(const Storage<FilesToTransfer> &storage)
FilePath::sort(remoteDirs);
FilePath::removeDuplicates(remoteDirs);
- async.setConcurrentCallData([remoteDirs](QPromise<Result> &promise) {
+ async.setConcurrentCallData([remoteDirs](QPromise<Result<>> &promise) {
for (const FilePath &dir : remoteDirs) {
- const Result result = dir.ensureWritableDir();
+ const Result<> result = dir.ensureWritableDir();
promise.addResult(result);
if (!result)
promise.future().cancel();
@@ -90,7 +90,7 @@ GroupItem GenericDeployStep::mkdirTask(const Storage<FilesToTransfer> &storage)
});
};
- const auto onError = [this](const Async<Result> &async) {
+ const auto onError = [this](const Async<Result<>> &async) {
const int numResults = async.future().resultCount();
if (numResults == 0) {
addErrorMessage(
@@ -99,13 +99,13 @@ GroupItem GenericDeployStep::mkdirTask(const Storage<FilesToTransfer> &storage)
}
for (int i = 0; i < numResults; ++i) {
- const Result result = async.future().resultAt(i);
+ const Result<> result = async.future().resultAt(i);
if (!result)
addErrorMessage(result.error());
}
};
- return AsyncTask<Result>(onSetup, onError, CallDoneIf::Error);
+ return AsyncTask<Result<>>(onSetup, onError, CallDoneIf::Error);
}
static FileTransferMethod effectiveTransferMethodFor(const FileToTransfer &fileToTransfer,
diff --git a/src/plugins/remotelinux/linuxdevice.cpp b/src/plugins/remotelinux/linuxdevice.cpp
index f7e425ad253..396c696b19e 100644
--- a/src/plugins/remotelinux/linuxdevice.cpp
+++ b/src/plugins/remotelinux/linuxdevice.cpp
@@ -319,14 +319,14 @@ public:
void setupDisconnectedAccess();
- Result setupShell(const SshParameters &sshParameters, bool announce);
+ Result<> setupShell(const SshParameters &sshParameters, bool announce);
RunResult runInShell(const CommandLine &cmd, const QByteArray &stdInData = {});
bool tryToConnect(const SshParameters &sshParameters)
{
QMutexLocker locker(&m_scriptAccess.m_shellMutex);
- return setupShell(sshParameters, false);
+ return setupShell(sshParameters, false).has_value();
}
bool checkDisconnectedWithWarning();
@@ -903,7 +903,7 @@ public:
}
// Call me with shell mutex locked
- Result start(const SshParameters &parameters)
+ Result<> start(const SshParameters &parameters)
{
closeShell();
setSshParameters(parameters);
@@ -920,7 +920,7 @@ public:
connect(m_shell.get(), &DeviceShell::done, this, [this] {
closeShell();
});
- Result result = m_shell->start();
+ Result<> result = m_shell->start();
if (!result) {
qCDebug(linuxDeviceLog) << "Failed to start shell for:" << parameters.userAtHostAndPort()
<< ", " << result.error();
@@ -1070,7 +1070,7 @@ LinuxDevice::LinuxDevice()
});
addDeviceAction({Tr::tr("Open Remote Shell"), [](const IDevice::Ptr &device) {
- Result result = device->openTerminal(Environment(), FilePath());
+ Result<> result = device->openTerminal(Environment(), FilePath());
if (!result)
QMessageBox::warning(nullptr, Tr::tr("Error"), result.error());
@@ -1168,11 +1168,11 @@ void LinuxDevicePrivate::setupDisconnectedAccess()
}
// Call me with shell mutex locked
-Result LinuxDevicePrivate::setupShell(const SshParameters &sshParameters, bool announce)
+Result<> LinuxDevicePrivate::setupShell(const SshParameters &sshParameters, bool announce)
{
if (m_scriptAccess.m_handler->isRunning(sshParameters)) {
setupConnectedAccess();
- return Result::Ok;
+ return ResultOk;
}
invalidateEnvironmentCache();
@@ -1180,7 +1180,7 @@ Result LinuxDevicePrivate::setupShell(const SshParameters &sshParameters, bool a
if (announce)
announceConnectionAttempt();
- Result result = Result::Error("setupShell failed");
+ Result<> result = ResultError("setupShell failed");
QMetaObject::invokeMethod(m_scriptAccess.m_handler, [this, sshParameters] {
return m_scriptAccess.m_handler->start(sshParameters);
}, Qt::BlockingQueuedConnection, &result);
@@ -1198,7 +1198,7 @@ Result LinuxDevicePrivate::setupShell(const SshParameters &sshParameters, bool a
m_cmdBridgeAccess = std::make_unique<CmdBridge::FileAccess>();
// We have good shell access now, try to get bridge access, too:
- Result initResult
+ Result<> initResult
= m_cmdBridgeAccess
->deployAndInit(Core::ICore::libexecPath(), q->rootPath(), getEnvironment());
if (initResult) {
@@ -1209,7 +1209,7 @@ Result LinuxDevicePrivate::setupShell(const SshParameters &sshParameters, bool a
<< ", falling back to slow shell access";
}
- return Result::Ok; // Both are fine.
+ return ResultOk; // Both are fine.
}
RunResult LinuxDevicePrivate::runInShell(const CommandLine &cmd, const QByteArray &data)
@@ -1218,7 +1218,7 @@ RunResult LinuxDevicePrivate::runInShell(const CommandLine &cmd, const QByteArra
DEBUG(cmd.toUserOutput());
if (checkDisconnectedWithWarning())
return {};
- const bool isSetup = setupShell(q->sshParameters(), true);
+ const bool isSetup = setupShell(q->sshParameters(), true).has_value();
if (checkDisconnectedWithWarning())
return {};
QTC_ASSERT(isSetup, return {});
diff --git a/src/plugins/remotelinux/publickeydeploymentdialog.cpp b/src/plugins/remotelinux/publickeydeploymentdialog.cpp
index 18d54ea7faf..99805afa22f 100644
--- a/src/plugins/remotelinux/publickeydeploymentdialog.cpp
+++ b/src/plugins/remotelinux/publickeydeploymentdialog.cpp
@@ -56,12 +56,12 @@ PublicKeyDeploymentDialog::PublicKeyDeploymentDialog(const DeviceConstRef &devic
[this] { d->m_done ? accept() : reject(); });
connect(&d->m_process, &Process::done, this, [this] {
const bool succeeded = d->m_process.result() == ProcessResult::FinishedWithSuccess;
- Result result = Result::Ok;
+ Result<> result = ResultOk;
if (!succeeded) {
const QString errorString = d->m_process.errorString();
const QString errorMessage = errorString.isEmpty() ? d->m_process.cleanedStdErr()
: errorString;
- result = Result::Error(Utils::joinStrings({Tr::tr("Key deployment failed."),
+ result = ResultError(Utils::joinStrings({Tr::tr("Key deployment failed."),
Utils::trimBack(errorMessage, '\n')}, '\n'));
}
handleDeploymentDone(result);
@@ -69,7 +69,7 @@ PublicKeyDeploymentDialog::PublicKeyDeploymentDialog(const DeviceConstRef &devic
FileReader reader;
if (!reader.fetch(publicKeyFileName)) {
- handleDeploymentDone(Result::Error(Tr::tr("Public key error: %1").arg(reader.errorString())));
+ handleDeploymentDone(ResultError(Tr::tr("Public key error: %1").arg(reader.errorString())));
return;
}
@@ -110,7 +110,7 @@ PublicKeyDeploymentDialog::~PublicKeyDeploymentDialog()
delete d;
}
-void PublicKeyDeploymentDialog::handleDeploymentDone(const Result &result)
+void PublicKeyDeploymentDialog::handleDeploymentDone(const Result<> &result)
{
QString buttonText = result ? Tr::tr("Deployment finished successfully.") : result.error();
const QString textColor = creatorColor(
diff --git a/src/plugins/remotelinux/publickeydeploymentdialog.h b/src/plugins/remotelinux/publickeydeploymentdialog.h
index d8ebf594dab..81ce685c0b0 100644
--- a/src/plugins/remotelinux/publickeydeploymentdialog.h
+++ b/src/plugins/remotelinux/publickeydeploymentdialog.h
@@ -5,12 +5,11 @@
#include <projectexplorer/devicesupport/idevicefwd.h>
+#include <utils/result.h>
+
#include <QProgressDialog>
-namespace Utils {
-class FilePath;
-class Result;
-}
+namespace Utils { class FilePath; }
namespace RemoteLinux::Internal {
@@ -29,7 +28,7 @@ public:
~PublicKeyDeploymentDialog() override;
private:
- void handleDeploymentDone(const Utils::Result &result);
+ void handleDeploymentDone(const Utils::Result<> &result);
Internal::PublicKeyDeploymentDialogPrivate * const d;
};
diff --git a/src/plugins/remotelinux/remotelinuxfiletransfer.cpp b/src/plugins/remotelinux/remotelinuxfiletransfer.cpp
index 15d43306573..3b90dd6de9d 100644
--- a/src/plugins/remotelinux/remotelinuxfiletransfer.cpp
+++ b/src/plugins/remotelinux/remotelinuxfiletransfer.cpp
@@ -313,18 +313,18 @@ private:
QHash<FilePath, FilesToTransfer> m_batches;
};
-static void createDir(QPromise<Result> &promise, const FilePath &pathToCreate)
+static void createDir(QPromise<Result<>> &promise, const FilePath &pathToCreate)
{
- const Result result = pathToCreate.ensureWritableDir();
+ const Result<> result = pathToCreate.ensureWritableDir();
promise.addResult(result);
if (!result)
promise.future().cancel();
};
-static void copyFile(QPromise<Result> &promise, const FileToTransfer &file)
+static void copyFile(QPromise<Result<>> &promise, const FileToTransfer &file)
{
- const Result result = file.m_source.copyFile(file.m_target);
+ const Result<> result = file.m_source.copyFile(file.m_target);
promise.addResult(result);
if (!result)
@@ -352,13 +352,13 @@ private:
const LoopList iteratorParentDirs(QList(allParentDirs.cbegin(), allParentDirs.cend()));
- const auto onCreateDirSetup = [iteratorParentDirs](Async<Result> &async) {
+ const auto onCreateDirSetup = [iteratorParentDirs](Async<Result<>> &async) {
async.setConcurrentCallData(createDir, *iteratorParentDirs);
};
const auto onCreateDirDone = [this,
- iteratorParentDirs](const Async<Result> &async) {
- const Result result = async.result();
+ iteratorParentDirs](const Async<Result<>> &async) {
+ const Result<> result = async.result();
if (result)
emit progress(
Tr::tr("Created directory: \"%1\".\n").arg(iteratorParentDirs->toUserOutput()));
@@ -369,13 +369,13 @@ private:
const LoopList iterator(m_setup.m_files);
const Storage<int> counterStorage;
- const auto onCopySetup = [iterator](Async<Result> &async) {
+ const auto onCopySetup = [iterator](Async<Result<>> &async) {
async.setConcurrentCallData(copyFile, *iterator);
};
const auto onCopyDone = [this, iterator, counterStorage](
- const Async<Result> &async) {
- const Result result = async.result();
+ const Async<Result<>> &async) {
+ const Result<> result = async.result();
int &counter = *counterStorage;
++counter;
@@ -394,12 +394,12 @@ private:
const Group recipe {
For (iteratorParentDirs) >> Do {
parallelIdealThreadCountLimit,
- AsyncTask<Result>(onCreateDirSetup, onCreateDirDone),
+ AsyncTask<Result<>>(onCreateDirSetup, onCreateDirDone),
},
For (iterator) >> Do {
parallelLimit(2),
counterStorage,
- AsyncTask<Result>(onCopySetup, onCopyDone),
+ AsyncTask<Result<>>(onCopySetup, onCopyDone),
},
};
diff --git a/src/plugins/remotelinux/remotelinuxsignaloperation.cpp b/src/plugins/remotelinux/remotelinuxsignaloperation.cpp
index b48ea1f7504..0ba08f2d04e 100644
--- a/src/plugins/remotelinux/remotelinuxsignaloperation.cpp
+++ b/src/plugins/remotelinux/remotelinuxsignaloperation.cpp
@@ -77,11 +77,11 @@ void RemoteLinuxSignalOperation::interruptProcess(qint64 pid)
void RemoteLinuxSignalOperation::runnerDone()
{
- Result result = Result::Ok;
+ Result<> result = ResultOk;
if (m_process->exitStatus() != QProcess::NormalExit) {
- result = Result::Error(m_process->errorString());
+ result = ResultError(m_process->errorString());
} else if (m_process->exitCode() != 0) {
- result = Result::Error(Tr::tr("Exit code is %1. stderr:").arg(m_process->exitCode())
+ result = ResultError(Tr::tr("Exit code is %1. stderr:").arg(m_process->exitCode())
+ ' ' + QString::fromLatin1(m_process->rawStdErr()));
}
m_process.release()->deleteLater();
diff --git a/src/plugins/remotelinux/sshkeycreationdialog.cpp b/src/plugins/remotelinux/sshkeycreationdialog.cpp
index 0e08ef7f3e8..36d76bd2d1c 100644
--- a/src/plugins/remotelinux/sshkeycreationdialog.cpp
+++ b/src/plugins/remotelinux/sshkeycreationdialog.cpp
@@ -114,11 +114,11 @@ void SshKeyCreationDialog::generateKeys()
{"-t", keyTypeString, "-b", m_comboBox->currentText(), "-N", QString(), "-f",
privateKeyFilePath().path()}});
keygen.start();
- Result result = Result::Ok;
+ Result<> result = ResultOk;
if (!keygen.waitForFinished())
- result = Result::Error(keygen.errorString().isEmpty() ? Tr::tr("Unknown error") : keygen.errorString());
+ result = ResultError(keygen.errorString().isEmpty() ? Tr::tr("Unknown error") : keygen.errorString());
else if (keygen.exitCode() != 0)
- result = Result::Error(QString::fromLocal8Bit(keygen.rawStdErr()));
+ result = ResultError(QString::fromLocal8Bit(keygen.rawStdErr()));
if (!result) {
showError(Tr::tr("The ssh-keygen tool at \"%1\" failed: %2")
.arg(SshSettings::keygenFilePath().toUserOutput(), result.error()));
diff --git a/src/plugins/resourceeditor/qrceditor/resourcefile.cpp b/src/plugins/resourceeditor/qrceditor/resourcefile.cpp
index 47108adf91e..dae3bd562aa 100644
--- a/src/plugins/resourceeditor/qrceditor/resourcefile.cpp
+++ b/src/plugins/resourceeditor/qrceditor/resourcefile.cpp
@@ -223,9 +223,9 @@ bool ResourceFile::save()
return false;
}
- const Result res = m_textFileFormat.writeFile(m_filePath, contents());
+ const Result<> res = m_textFileFormat.writeFile(m_filePath, contents());
m_error_message = res.error();
- return res;
+ return res.has_value();
}
void ResourceFile::refresh()
diff --git a/src/plugins/resourceeditor/resourceeditor.cpp b/src/plugins/resourceeditor/resourceeditor.cpp
index 5b95da532db..297cf682933 100644
--- a/src/plugins/resourceeditor/resourceeditor.cpp
+++ b/src/plugins/resourceeditor/resourceeditor.cpp
@@ -56,7 +56,7 @@ public:
bool shouldAutoSave() const final { return m_shouldAutoSave; }
bool isModified() const final { return m_model.dirty(); }
bool isSaveAsAllowed() const final { return true; }
- Result reload(ReloadFlag flag, ChangeType type) final;
+ Result<> reload(ReloadFlag flag, ChangeType type) final;
void setFilePath(const FilePath &newName) final;
void setBlockDirtyChanged(bool value) { m_blockDirtyChanged = value; }
@@ -67,7 +67,7 @@ signals:
void loaded(bool success);
private:
- Result saveImpl(const FilePath &filePath, bool autoSave) final;
+ Result<> saveImpl(const FilePath &filePath, bool autoSave) final;
void dirtyChanged(bool);
RelativeResourceModel m_model;
@@ -209,20 +209,20 @@ IDocument::OpenResult ResourceEditorDocument::open(QString *errorString,
return OpenResult::Success;
}
-Result ResourceEditorDocument::saveImpl(const FilePath &filePath, bool autoSave)
+Result<> ResourceEditorDocument::saveImpl(const FilePath &filePath, bool autoSave)
{
if (debugResourceEditorW)
qDebug() << ">ResourceEditorW::saveImpl: " << filePath;
if (filePath.isEmpty())
- return Result::Error("ASSERT: ResourceEditorDocument: filePath.isEmpty()");
+ return ResultError("ASSERT: ResourceEditorDocument: filePath.isEmpty()");
m_blockDirtyChanged = true;
m_model.setFilePath(filePath);
if (!m_model.save()) {
m_model.setFilePath(this->filePath());
m_blockDirtyChanged = false;
- return Result::Error(m_model.errorMessage());
+ return ResultError(m_model.errorMessage());
}
m_shouldAutoSave = false;
@@ -230,14 +230,14 @@ Result ResourceEditorDocument::saveImpl(const FilePath &filePath, bool autoSave)
m_model.setFilePath(this->filePath());
m_model.setDirty(true);
m_blockDirtyChanged = false;
- return Result::Ok;
+ return ResultOk;
}
setFilePath(filePath);
m_blockDirtyChanged = false;
emit changed();
- return Result::Ok;
+ return ResultOk;
}
bool ResourceEditorDocument::setContents(const QByteArray &contents)
@@ -280,16 +280,16 @@ void ResourceEditorImpl::restoreState(const QByteArray &state)
m_resourceEditor->restoreState(splitterState);
}
-Result ResourceEditorDocument::reload(ReloadFlag flag, ChangeType type)
+Result<> ResourceEditorDocument::reload(ReloadFlag flag, ChangeType type)
{
Q_UNUSED(type)
if (flag == FlagIgnore)
- return Result::Ok;
+ return ResultOk;
emit aboutToReload();
QString errorString;
const bool success = (open(&errorString, filePath(), filePath()) == OpenResult::Success);
emit reloadFinished(success);
- return Result(success, errorString);
+ return makeResult(success, errorString);
}
void ResourceEditorDocument::dirtyChanged(bool dirty)
diff --git a/src/plugins/resourceeditor/resourcenode.cpp b/src/plugins/resourceeditor/resourcenode.cpp
index ab2b7b273bf..d27a7cb992c 100644
--- a/src/plugins/resourceeditor/resourcenode.cpp
+++ b/src/plugins/resourceeditor/resourcenode.cpp
@@ -47,14 +47,14 @@ public:
return BehaviorSilent;
}
- Result reload(ReloadFlag, ChangeType) final
+ Result<> reload(ReloadFlag, ChangeType) final
{
FolderNode *parent = m_node->parentFolderNode();
if (!parent)
- return Result::Error("ASSERT: !parent");
+ return ResultError("ASSERT: !parent");
parent->replaceSubtree(m_node, std::make_unique<ResourceTopLevelNode>(
m_node->filePath(), parent->filePath(), m_node->contents()));
- return Result::Ok;
+ return ResultOk;
}
private:
diff --git a/src/plugins/scxmleditor/scxmleditordocument.cpp b/src/plugins/scxmleditor/scxmleditordocument.cpp
index 81cebd280ac..3102e8008b5 100644
--- a/src/plugins/scxmleditor/scxmleditordocument.cpp
+++ b/src/plugins/scxmleditor/scxmleditordocument.cpp
@@ -57,23 +57,23 @@ Core::IDocument::OpenResult ScxmlEditorDocument::open(QString *errorString,
return OpenResult::Success;
}
-Result ScxmlEditorDocument::saveImpl(const FilePath &filePath, bool autoSave)
+Result<> ScxmlEditorDocument::saveImpl(const FilePath &filePath, bool autoSave)
{
if (filePath.isEmpty())
- return Result::Error("ASSERT: ScxmlEditorDocument: filePath.isEmpty()");
+ return ResultError("ASSERT: ScxmlEditorDocument: filePath.isEmpty()");
bool dirty = m_designWidget->isDirty();
m_designWidget->setFileName(filePath.toUrlishString());
if (!m_designWidget->save()) {
m_designWidget->setFileName(this->filePath().toUrlishString());
- return Result::Error(m_designWidget->errorMessage());
+ return ResultError(m_designWidget->errorMessage());
}
if (autoSave) {
m_designWidget->setFileName(this->filePath().toUrlishString());
m_designWidget->save();
- return Result::Ok;
+ return ResultOk;
}
setFilePath(filePath);
@@ -81,7 +81,7 @@ Result ScxmlEditorDocument::saveImpl(const FilePath &filePath, bool autoSave)
if (dirty != m_designWidget->isDirty())
emit changed();
- return Result::Ok;
+ return ResultOk;
}
void ScxmlEditorDocument::setFilePath(const FilePath &newName)
@@ -110,17 +110,17 @@ bool ScxmlEditorDocument::isModified() const
return m_designWidget && m_designWidget->isDirty();
}
-Result ScxmlEditorDocument::reload(ReloadFlag flag, ChangeType type)
+Result<> ScxmlEditorDocument::reload(ReloadFlag flag, ChangeType type)
{
Q_UNUSED(type)
if (flag == FlagIgnore)
- return Result::Ok;
+ return ResultOk;
emit aboutToReload();
QString errorString;
emit reloadRequested(&errorString, filePath().toUrlishString());
const bool success = errorString.isEmpty();
emit reloadFinished(success);
- return Result(success, errorString);
+ return makeResult(success, errorString);
}
bool ScxmlEditorDocument::supportsCodec(const QByteArray &codec) const
diff --git a/src/plugins/scxmleditor/scxmleditordocument.h b/src/plugins/scxmleditor/scxmleditordocument.h
index 631a3c6300f..ba4cfc42d6a 100644
--- a/src/plugins/scxmleditor/scxmleditordocument.h
+++ b/src/plugins/scxmleditor/scxmleditordocument.h
@@ -33,7 +33,7 @@ public:
bool shouldAutoSave() const override;
bool isSaveAsAllowed() const override;
bool isModified() const override;
- Utils::Result reload(ReloadFlag flag, ChangeType type) override;
+ Utils::Result<> reload(ReloadFlag flag, ChangeType type) override;
bool supportsCodec(const QByteArray &codec) const override;
// Internal
@@ -46,7 +46,7 @@ signals:
void reloadRequested(QString *errorString, const QString &);
protected:
- Utils::Result saveImpl(const Utils::FilePath &filePath, bool autoSave) override;
+ Utils::Result<> saveImpl(const Utils::FilePath &filePath, bool autoSave) override;
private:
QPointer<Common::MainWidget> m_designWidget;
diff --git a/src/plugins/squish/objectsmapdocument.cpp b/src/plugins/squish/objectsmapdocument.cpp
index 83816a1b64b..3475e3ee6f2 100644
--- a/src/plugins/squish/objectsmapdocument.cpp
+++ b/src/plugins/squish/objectsmapdocument.cpp
@@ -40,20 +40,20 @@ Core::IDocument::OpenResult ObjectsMapDocument::open(QString *errorString,
return result;
}
-Result ObjectsMapDocument::saveImpl(const FilePath &filePath, bool autoSave)
+Result<> ObjectsMapDocument::saveImpl(const FilePath &filePath, bool autoSave)
{
if (filePath.isEmpty())
- return Result::Error("ASSERT: ObjectsMapDocument: filePath.isEmpty()");
+ return ResultError("ASSERT: ObjectsMapDocument: filePath.isEmpty()");
const bool writeOk = writeFile(filePath);
if (!writeOk)
- return Result::Error(Tr::tr("Failed to write \"%1\"").arg(filePath.toUserOutput()));
+ return ResultError(Tr::tr("Failed to write \"%1\"").arg(filePath.toUserOutput()));
if (!autoSave) {
setModified(false);
setFilePath(filePath);
}
- return Result::Ok;
+ return ResultOk;
}
Utils::FilePath ObjectsMapDocument::fallbackSaveAsPath() const
@@ -72,19 +72,19 @@ void ObjectsMapDocument::setModified(bool modified)
emit changed();
}
-Result ObjectsMapDocument::reload(Core::IDocument::ReloadFlag flag,
+Result<> ObjectsMapDocument::reload(Core::IDocument::ReloadFlag flag,
Core::IDocument::ChangeType type)
{
Q_UNUSED(type);
if (flag == FlagIgnore)
- return Result::Ok;
+ return ResultOk;
emit aboutToReload();
QString errorString;
const bool success = (openImpl(&errorString, filePath(), filePath()) == OpenResult::Success);
if (success)
setModified(false);
emit reloadFinished(success);
- return Result(success, errorString);
+ return makeResult(success, errorString);
}
bool ObjectsMapDocument::buildObjectsMapTree(const QByteArray &contents)
diff --git a/src/plugins/squish/objectsmapdocument.h b/src/plugins/squish/objectsmapdocument.h
index 52ea97d499d..f24b47c4f61 100644
--- a/src/plugins/squish/objectsmapdocument.h
+++ b/src/plugins/squish/objectsmapdocument.h
@@ -26,7 +26,7 @@ public:
bool isModified() const override { return m_isModified; }
void setModified(bool modified);
bool isSaveAsAllowed() const override { return true; }
- Utils::Result reload(ReloadFlag flag, ChangeType type) override;
+ Utils::Result<> reload(ReloadFlag flag, ChangeType type) override;
bool shouldAutoSave() const override { return true; }
bool setContents(const QByteArray &contents) override;
@@ -34,7 +34,7 @@ public:
ObjectsMapModel *model() const { return m_contentModel; }
protected:
- Utils::Result saveImpl(const Utils::FilePath &fileName, bool autoSave) override;
+ Utils::Result<> saveImpl(const Utils::FilePath &fileName, bool autoSave) override;
private:
OpenResult openImpl(QString *error,
diff --git a/src/plugins/squish/squishfilehandler.cpp b/src/plugins/squish/squishfilehandler.cpp
index a6e7cb07118..d00ed503860 100644
--- a/src/plugins/squish/squishfilehandler.cpp
+++ b/src/plugins/squish/squishfilehandler.cpp
@@ -339,7 +339,7 @@ void SquishFileHandler::deleteTestCase(const QString &suiteName, const QString &
SuiteConf suiteConf = SuiteConf::readSuiteConf(suiteConfPath);
const Utils::FilePath testCaseDirectory = suiteConfPath.parentDir().pathAppended(testCaseName);
closeOpenedEditorsFor(testCaseDirectory, false);
- Utils::Result result = testCaseDirectory.removeRecursively();
+ Utils::Result<> result = testCaseDirectory.removeRecursively();
if (!result) {
QString detail = Tr::tr("Deletion of Test Case failed.");
detail.append('\n').append(result.error());
diff --git a/src/plugins/squish/squishtesttreeview.cpp b/src/plugins/squish/squishtesttreeview.cpp
index 6421b89593b..4021bc94e18 100644
--- a/src/plugins/squish/squishtesttreeview.cpp
+++ b/src/plugins/squish/squishtesttreeview.cpp
@@ -185,7 +185,7 @@ void SquishTestTreeItemDelegate::setEditorData(QWidget *editor, const QModelInde
static bool copyScriptTemplates(const SuiteConf &suiteConf, const Utils::FilePath &destination)
{
- Utils::Result result = destination.ensureWritableDir();
+ Utils::Result<> result = destination.ensureWritableDir();
QTC_ASSERT_EXPECTED(result, return false);
const bool scripted = suiteConf.objectMapStyle() == "script";
diff --git a/src/plugins/squish/squishwizardpages.cpp b/src/plugins/squish/squishwizardpages.cpp
index 486007a0e81..ed977b31fd4 100644
--- a/src/plugins/squish/squishwizardpages.cpp
+++ b/src/plugins/squish/squishwizardpages.cpp
@@ -300,39 +300,39 @@ public:
class SquishFileGenerator final : public JsonWizardGenerator
{
public:
- Result setup(const QVariant &data);
+ Result<> setup(const QVariant &data);
Core::GeneratedFiles fileList(MacroExpander *expander,
const FilePath &wizardDir,
const FilePath &projectDir,
QString *errorMessage) final;
- Result writeFile(const ProjectExplorer::JsonWizard *wizard, Core::GeneratedFile *file) final;
- Result allDone(const ProjectExplorer::JsonWizard *wizard, Core::GeneratedFile *file) final;
+ Result<> writeFile(const ProjectExplorer::JsonWizard *wizard, Core::GeneratedFile *file) final;
+ Result<> allDone(const ProjectExplorer::JsonWizard *wizard, Core::GeneratedFile *file) final;
private:
QString m_mode;
};
-Result SquishFileGenerator::setup(const QVariant &data)
+Result<> SquishFileGenerator::setup(const QVariant &data)
{
if (data.isNull())
- return Result::Error("No data");
+ return ResultError("No data");
if (data.typeId() != QMetaType::QVariantMap)
- return Result::Error(Tr::tr("Key is not an object."));
+ return ResultError(Tr::tr("Key is not an object."));
const QVariantMap map = data.toMap();
const QVariant modeVariant = map.value("mode");
if (!modeVariant.isValid())
- return Result::Error(Tr::tr("Key 'mode' is not set."));
+ return ResultError(Tr::tr("Key 'mode' is not set."));
m_mode = modeVariant.toString();
if (m_mode != "TestSuite") {
- const Result res = Result::Error(Tr::tr("Unsupported mode:") + ' ' + m_mode);
+ const Result<> res = ResultError(Tr::tr("Unsupported mode:") + ' ' + m_mode);
m_mode.clear();
return res;
}
- return Result::Ok;
+ return ResultOk;
}
static QString generateSuiteConf(const QString &aut, const QString &language,
@@ -386,14 +386,14 @@ Core::GeneratedFiles SquishFileGenerator::fileList(MacroExpander *expander,
return result;
}
-Result SquishFileGenerator::writeFile(const JsonWizard *, Core::GeneratedFile *file)
+Result<> SquishFileGenerator::writeFile(const JsonWizard *, Core::GeneratedFile *file)
{
if (file->attributes() & Core::GeneratedFile::CustomGeneratorAttribute)
- return Result::Ok;
+ return ResultOk;
return file->write();
}
-Result SquishFileGenerator::allDone(const JsonWizard *wizard, Core::GeneratedFile *file)
+Result<> SquishFileGenerator::allDone(const JsonWizard *wizard, Core::GeneratedFile *file)
{
Q_UNUSED(wizard)
@@ -402,7 +402,7 @@ Result SquishFileGenerator::allDone(const JsonWizard *wizard, Core::GeneratedFil
SquishFileHandler::instance()->openTestSuite(filePath);
}, Qt::QueuedConnection);
}
- return Result::Ok;
+ return ResultOk;
}
void setupSquishWizardPages()
diff --git a/src/plugins/squish/suiteconf.cpp b/src/plugins/squish/suiteconf.cpp
index 0f63f241d0c..9d94441e865 100644
--- a/src/plugins/squish/suiteconf.cpp
+++ b/src/plugins/squish/suiteconf.cpp
@@ -323,7 +323,7 @@ bool SuiteConf::ensureObjectMapExists() const
return true;
const Utils::FilePath objectMap = scripts.pathAppended("objectmap_template" + extension);
- Utils::Result result = destinationObjectMap.parentDir().ensureWritableDir();
+ Utils::Result<> result = destinationObjectMap.parentDir().ensureWritableDir();
QTC_ASSERT_EXPECTED(result, return false);
result = objectMap.copyFile(destinationObjectMap);
QTC_ASSERT_EXPECTED(result, return false);
diff --git a/src/plugins/terminal/shellintegration.cpp b/src/plugins/terminal/shellintegration.cpp
index 556035e1266..11f9dcc2c27 100644
--- a/src/plugins/terminal/shellintegration.cpp
+++ b/src/plugins/terminal/shellintegration.cpp
@@ -172,7 +172,7 @@ void ShellIntegration::prepareProcess(Utils::Process &process)
const FilePath rcPath = filesToCopy.bash.rcFile;
const FilePath tmpRc = FilePath::fromUserInput(
m_tempDir.filePath(filesToCopy.bash.rcFile.fileName()));
- const Result copyResult = rcPath.copyFile(tmpRc);
+ const Result<> copyResult = rcPath.copyFile(tmpRc);
QTC_ASSERT_EXPECTED(copyResult, return);
if (cmd.arguments() == "-l")
@@ -181,7 +181,7 @@ void ShellIntegration::prepareProcess(Utils::Process &process)
cmd = {cmd.executable(), {"--init-file", tmpRc.nativePath()}};
} else if (cmd.executable().baseName() == "zsh") {
for (const FileToCopy &file : std::as_const(filesToCopy.zsh.files)) {
- const Result copyResult = file.source.copyFile(
+ const Result<> copyResult = file.source.copyFile(
FilePath::fromUserInput(m_tempDir.filePath(file.destName)));
QTC_ASSERT_EXPECTED(copyResult, return);
}
@@ -196,7 +196,7 @@ void ShellIntegration::prepareProcess(Utils::Process &process)
const FilePath rcPath = filesToCopy.pwsh.script;
const FilePath tmpRc = FilePath::fromUserInput(
m_tempDir.filePath(filesToCopy.pwsh.script.fileName()));
- const Result copyResult = rcPath.copyFile(tmpRc);
+ const Result<> copyResult = rcPath.copyFile(tmpRc);
QTC_ASSERT_EXPECTED(copyResult, return);
cmd.addArgs(QString("-noexit -command try { . '%1' } catch {Write-Host \"Shell "
@@ -207,7 +207,7 @@ void ShellIntegration::prepareProcess(Utils::Process &process)
const FilePath rcPath = filesToCopy.clink.script;
const FilePath tmpRc = FilePath::fromUserInput(
m_tempDir.filePath(filesToCopy.clink.script.fileName()));
- const Result copyResult = rcPath.copyFile(tmpRc);
+ const Result<> copyResult = rcPath.copyFile(tmpRc);
QTC_ASSERT_EXPECTED(copyResult, return);
env.set("CLINK_HISTORY_LABEL", "QtCreator");
@@ -216,7 +216,7 @@ void ShellIntegration::prepareProcess(Utils::Process &process)
FilePath xdgDir = FilePath::fromUserInput(m_tempDir.filePath("fish_xdg_data"));
FilePath subDir = xdgDir.resolvePath(QString("fish/vendor_conf.d"));
QTC_ASSERT(subDir.createDir(), return);
- const Result copyResult = filesToCopy.fish.script.copyFile(
+ const Result<> copyResult = filesToCopy.fish.script.copyFile(
subDir.resolvePath(filesToCopy.fish.script.fileName()));
QTC_ASSERT_EXPECTED(copyResult, return);
diff --git a/src/plugins/texteditor/refactoringchanges.cpp b/src/plugins/texteditor/refactoringchanges.cpp
index 8fd14db9568..88657b2a906 100644
--- a/src/plugins/texteditor/refactoringchanges.cpp
+++ b/src/plugins/texteditor/refactoringchanges.cpp
@@ -73,7 +73,7 @@ bool RefactoringFile::create(const QString &contents, bool reindent, bool openIn
// Write the file to disk:
TextFileFormat format;
format.setCodecName(EditorManager::defaultTextCodecName());
- const Result saveOk = format.writeFile(m_filePath, m_document->toPlainText());
+ const Result<> saveOk = format.writeFile(m_filePath, m_document->toPlainText());
delete m_document;
m_document = nullptr;
if (!saveOk)
@@ -267,7 +267,7 @@ bool RefactoringFile::apply()
QTC_ASSERT(!m_filePath.isEmpty(), return false);
// suppress "file has changed" warnings if the file is open in a read-only editor
Core::FileChangeBlocker block(m_filePath);
- if (const Result res = m_textFileFormat.writeFile(m_filePath, doc->toPlainText())) {
+ if (const Result<> res = m_textFileFormat.writeFile(m_filePath, doc->toPlainText())) {
Core::DocumentManager::notifyFilesChangedInternally({m_filePath});
} else {
qWarning() << "Could not apply changes to" << m_filePath
diff --git a/src/plugins/texteditor/textdocument.cpp b/src/plugins/texteditor/textdocument.cpp
index 4af08de73ec..fc61ad6c3a3 100644
--- a/src/plugins/texteditor/textdocument.cpp
+++ b/src/plugins/texteditor/textdocument.cpp
@@ -630,7 +630,7 @@ QTextDocument *TextDocument::document() const
* If \a autoSave is true, the cursor will be restored and some signals suppressed
* and we do not clean up the text file (cleanWhitespace(), ensureFinalNewLine()).
*/
-Result TextDocument::saveImpl(const FilePath &filePath, bool autoSave)
+Result<> TextDocument::saveImpl(const FilePath &filePath, bool autoSave)
{
QTextCursor cursor(&d->m_document);
@@ -685,7 +685,7 @@ Result TextDocument::saveImpl(const FilePath &filePath, bool autoSave)
}
}
- const Result res = write(filePath, saveFormat, plainText());
+ const Result<> res = write(filePath, saveFormat, plainText());
// restore text cursor and scroll bar positions
if (autoSave && undos < d->m_document.availableUndoSteps()) {
@@ -705,13 +705,13 @@ Result TextDocument::saveImpl(const FilePath &filePath, bool autoSave)
d->m_autoSaveRevision = d->m_document.revision();
if (autoSave)
- return Result::Ok;
+ return ResultOk;
// inform about the new filename
d->m_document.setModified(false); // also triggers update of the block revisions
setFilePath(filePath.absoluteFilePath());
emit changed();
- return Result::Ok;
+ return ResultOk;
}
QByteArray TextDocument::contents() const
@@ -833,19 +833,19 @@ Core::IDocument::OpenResult TextDocument::openImpl(QString *errorString,
return OpenResult::Success;
}
-Result TextDocument::reload(const QByteArray &codec)
+Result<> TextDocument::reload(const QByteArray &codec)
{
- QTC_ASSERT(!codec.isEmpty(), return Result::Error("No codec given"));
+ QTC_ASSERT(!codec.isEmpty(), return ResultError("No codec given"));
setCodec(codec);
return reload();
}
-Result TextDocument::reload()
+Result<> TextDocument::reload()
{
return reload(filePath());
}
-Result TextDocument::reload(const FilePath &realFilePath)
+Result<> TextDocument::reload(const FilePath &realFilePath)
{
emit aboutToReload();
auto documentLayout =
@@ -861,7 +861,7 @@ Result TextDocument::reload(const FilePath &realFilePath)
documentLayout->documentReloaded(this); // re-adds text marks
emit reloadFinished(success);
- return Result(success, errorString);
+ return makeResult(success, errorString);
}
bool TextDocument::setPlainText(const QString &text)
@@ -878,11 +878,11 @@ bool TextDocument::setPlainText(const QString &text)
return true;
}
-Result TextDocument::reload(ReloadFlag flag, ChangeType type)
+Result<> TextDocument::reload(ReloadFlag flag, ChangeType type)
{
if (flag == FlagIgnore) {
if (type != TypeContents)
- return Result::Ok;
+ return ResultOk;
const bool wasModified = document()->isModified();
{
@@ -893,7 +893,7 @@ Result TextDocument::reload(ReloadFlag flag, ChangeType type)
}
if (!wasModified)
modificationChanged(true);
- return Result::Ok;
+ return ResultOk;
}
return reload();
}
diff --git a/src/plugins/texteditor/textdocument.h b/src/plugins/texteditor/textdocument.h
index 44b1469c921..3d5b8ea9baf 100644
--- a/src/plugins/texteditor/textdocument.h
+++ b/src/plugins/texteditor/textdocument.h
@@ -107,7 +107,7 @@ public:
bool shouldAutoSave() const override;
bool isModified() const override;
bool isSaveAsAllowed() const override;
- Utils::Result reload(ReloadFlag flag, ChangeType type) override;
+ Utils::Result<> reload(ReloadFlag flag, ChangeType type) override;
void setFilePath(const Utils::FilePath &newName) override;
ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const override;
@@ -119,8 +119,8 @@ public:
OpenResult open(QString *errorString, const Utils::FilePath &filePath,
const Utils::FilePath &realFilePath) override;
- virtual Utils::Result reload();
- Utils::Result reload(const Utils::FilePath &realFilePath);
+ virtual Utils::Result<> reload();
+ Utils::Result<> reload(const Utils::FilePath &realFilePath);
bool setPlainText(const QString &text);
QTextDocument *document() const;
@@ -129,7 +129,7 @@ public:
void resetSyntaxHighlighter(const SyntaxHighLighterCreator &creator);
SyntaxHighlighter *syntaxHighlighter() const;
- Utils::Result reload(const QByteArray &codec);
+ Utils::Result<> reload(const QByteArray &codec);
void cleanWhitespace(const QTextCursor &cursor);
virtual void triggerPendingUpdates();
@@ -166,7 +166,7 @@ signals:
protected:
virtual void applyFontSettings();
- Utils::Result saveImpl(const Utils::FilePath &filePath, bool autoSave) override;
+ Utils::Result<> saveImpl(const Utils::FilePath &filePath, bool autoSave) override;
virtual void slotCodeStyleSettingsChanged(); // Used in CppEditorDocumet
private:
diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp
index 35e03c5ceb4..2ad6e1f8846 100644
--- a/src/plugins/texteditor/texteditor.cpp
+++ b/src/plugins/texteditor/texteditor.cpp
@@ -2012,7 +2012,7 @@ void TextEditorWidget::selectEncoding()
const CodecSelectorResult result = Core::askForCodec(doc);
switch (result.action) {
case Core::CodecSelectorResult::Reload: {
- if (Result res = doc->reload(result.codec); !res) {
+ if (Result<> res = doc->reload(result.codec); !res) {
QMessageBox::critical(this, Tr::tr("File Error"), res.error());
break;
}
diff --git a/src/plugins/valgrind/callgrindtool.cpp b/src/plugins/valgrind/callgrindtool.cpp
index 4700091f47f..f44e15c4818 100644
--- a/src/plugins/valgrind/callgrindtool.cpp
+++ b/src/plugins/valgrind/callgrindtool.cpp
@@ -1012,7 +1012,7 @@ void CallgrindTool::updateRunActions()
const auto canRun = ProjectExplorerPlugin::canRunStartupProject(CALLGRIND_RUN_MODE);
m_startAction->setToolTip(canRun ? Tr::tr("Start a Valgrind Callgrind analysis.")
: canRun.error());
- m_startAction->setEnabled(canRun);
+ m_startAction->setEnabled(canRun.has_value());
m_stopAction->setEnabled(false);
}
}
diff --git a/src/plugins/valgrind/memchecktool.cpp b/src/plugins/valgrind/memchecktool.cpp
index ab1148a78a3..b8117cccef5 100644
--- a/src/plugins/valgrind/memchecktool.cpp
+++ b/src/plugins/valgrind/memchecktool.cpp
@@ -732,12 +732,12 @@ void MemcheckTool::updateRunActions()
const auto canRun = ProjectExplorerPlugin::canRunStartupProject(MEMCHECK_RUN_MODE);
m_startAction->setToolTip(canRun ? Tr::tr("Start a Valgrind Memcheck analysis.")
: canRun.error());
- m_startAction->setEnabled(canRun);
+ m_startAction->setEnabled(canRun.has_value());
const auto canRunGdb = ProjectExplorerPlugin::canRunStartupProject(
MEMCHECK_WITH_GDB_RUN_MODE);
m_startWithGdbAction->setToolTip(
canRunGdb ? Tr::tr("Start a Valgrind Memcheck with GDB analysis.") : canRunGdb.error());
- m_startWithGdbAction->setEnabled(canRunGdb);
+ m_startWithGdbAction->setEnabled(canRunGdb.has_value());
m_stopAction->setEnabled(false);
}
}
@@ -895,7 +895,7 @@ void MemcheckTool::loadXmlLogFile(const QString &filePath)
m_logParser.reset(new Parser);
connect(m_logParser.get(), &Parser::error, this, &MemcheckTool::parserError);
- connect(m_logParser.get(), &Parser::done, this, [this](const Result &result) {
+ connect(m_logParser.get(), &Parser::done, this, [this](const Result<> &result) {
if (!result)
internalParserError(result.error());
loadingExternalXmlLogFileFinished();
diff --git a/src/plugins/valgrind/xmlprotocol/parser.cpp b/src/plugins/valgrind/xmlprotocol/parser.cpp
index 9c8009a0822..bea5456faee 100644
--- a/src/plugins/valgrind/xmlprotocol/parser.cpp
+++ b/src/plugins/valgrind/xmlprotocol/parser.cpp
@@ -709,7 +709,7 @@ public:
m_errorString = data.m_internalError;
});
QObject::connect(m_watcher.get(), &QFutureWatcherBase::finished, q, [this] {
- emit q->done({!m_errorString, m_errorString.value_or(QString())});
+ emit q->done(makeResult(!m_errorString, m_errorString.value_or(QString())));
m_watcher.release()->deleteLater();
m_thread.reset();
m_socket.reset();
@@ -780,12 +780,12 @@ bool Parser::isRunning() const
return d->m_watcher.get();
}
-Result Parser::runBlocking()
+Result<> Parser::runBlocking()
{
- Result ok(Result::Ok);
+ Result<> ok(ResultOk);
QEventLoop loop;
- const auto finalize = [&loop, &ok](const Result &result) {
+ const auto finalize = [&loop, &ok](const Result<> &result) {
ok = result;
// Refer to the QObject::deleteLater() docs.
QMetaObject::invokeMethod(&loop, [&loop] { loop.quit(); }, Qt::QueuedConnection);
diff --git a/src/plugins/valgrind/xmlprotocol/parser.h b/src/plugins/valgrind/xmlprotocol/parser.h
index 94218ee606a..ff55b2e0eb6 100644
--- a/src/plugins/valgrind/xmlprotocol/parser.h
+++ b/src/plugins/valgrind/xmlprotocol/parser.h
@@ -39,7 +39,7 @@ public:
void start();
bool isRunning() const;
- Utils::Result runBlocking();
+ Utils::Result<> runBlocking();
signals:
void status(const Status &status);
@@ -47,7 +47,7 @@ signals:
void errorCount(qint64 unique, qint64 count);
void suppressionCount(const QString &name, qint64 count);
void announceThread(const AnnounceThread &announceThread);
- void done(const Utils::Result &result);
+ void done(const Utils::Result<> &result);
private:
std::unique_ptr<ParserPrivate> d;
@@ -58,8 +58,8 @@ class ParserTaskAdapter final : public Tasking::TaskAdapter<Parser>
public:
ParserTaskAdapter()
{
- connect(task(), &Parser::done, this, [this](const Utils::Result &result) {
- emit done(Tasking::toDoneResult(result == Utils::Result::Ok));
+ connect(task(), &Parser::done, this, [this](const Utils::Result<> &result) {
+ emit done(Tasking::toDoneResult(result == Utils::ResultOk));
});
}
void start() final { task()->start(); }
diff --git a/src/plugins/vcsbase/submiteditorfile.cpp b/src/plugins/vcsbase/submiteditorfile.cpp
index e515d01b260..ca5601a8002 100644
--- a/src/plugins/vcsbase/submiteditorfile.cpp
+++ b/src/plugins/vcsbase/submiteditorfile.cpp
@@ -64,21 +64,21 @@ void SubmitEditorFile::setModified(bool modified)
emit changed();
}
-Result SubmitEditorFile::saveImpl(const FilePath &filePath, bool autoSave)
+Result<> SubmitEditorFile::saveImpl(const FilePath &filePath, bool autoSave)
{
FileSaver saver(filePath, QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text);
saver.write(m_editor->fileContents());
QString errorString;
if (!saver.finalize(&errorString))
- return Result::Error(errorString);
+ return ResultError(errorString);
if (autoSave)
- return Result::Ok;
+ return ResultOk;
setFilePath(filePath.absoluteFilePath());
setModified(false);
if (!errorString.isEmpty())
- return Result::Error(errorString);
+ return ResultError(errorString);
emit changed();
- return Result::Ok;
+ return ResultOk;
}
IDocument::ReloadBehavior SubmitEditorFile::reloadBehavior(ChangeTrigger state, ChangeType type) const
diff --git a/src/plugins/vcsbase/submiteditorfile.h b/src/plugins/vcsbase/submiteditorfile.h
index e71516ab699..de9741a1fdf 100644
--- a/src/plugins/vcsbase/submiteditorfile.h
+++ b/src/plugins/vcsbase/submiteditorfile.h
@@ -28,7 +28,7 @@ public:
void setModified(bool modified = true);
protected:
- Utils::Result saveImpl(const Utils::FilePath &filePath, bool autoSave) override;
+ Utils::Result<> saveImpl(const Utils::FilePath &filePath, bool autoSave) override;
private:
bool m_modified;