forked from qt-creator/qt-creator
ADS: Remove usage of FilePath::toString
Change-Id: I88b9c4d9bc0614bed23df6f229e4ae49ccdc565f Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -774,9 +774,9 @@ namespace ADS
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Remove corresponding workspace file
|
// Remove corresponding workspace file
|
||||||
QFile fi(workspaceNameToFilePath(workspace).toString());
|
const Utils::FilePath file = workspaceNameToFilePath(workspace);
|
||||||
if (fi.exists()) {
|
if (file.exists()) {
|
||||||
if (fi.remove()) {
|
if (file.removeFile()) {
|
||||||
d->m_workspaces.removeOne(workspace);
|
d->m_workspaces.removeOne(workspace);
|
||||||
emit workspacesRemoved();
|
emit workspacesRemoved();
|
||||||
emit workspaceListChanged();
|
emit workspaceListChanged();
|
||||||
@@ -798,12 +798,13 @@ namespace ADS
|
|||||||
if (!d->m_workspaces.contains(original))
|
if (!d->m_workspaces.contains(original))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
QFile fi(workspaceNameToFilePath(original).toString());
|
const Utils::FilePath originalPath = workspaceNameToFilePath(original);
|
||||||
|
const Utils::FilePath clonePath = workspaceNameToFilePath(clone);
|
||||||
|
|
||||||
// If the file does not exist, we can still clone
|
// If the file does not exist, we can still clone
|
||||||
if (!fi.exists() || fi.copy(workspaceNameToFilePath(clone).toString())) {
|
if (!originalPath.exists() || originalPath.copyFile(clonePath)) {
|
||||||
d->m_workspaces.insert(1, clone);
|
d->m_workspaces.insert(1, clone);
|
||||||
d->m_workspaceDateTimes
|
d->m_workspaceDateTimes.insert(clone, clonePath.lastModified());
|
||||||
.insert(clone, workspaceNameToFilePath(clone).lastModified());
|
|
||||||
emit workspaceListChanged();
|
emit workspaceListChanged();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -828,12 +829,12 @@ namespace ADS
|
|||||||
|
|
||||||
Utils::FilePath fileName = workspaceNameToFilePath(workspace);
|
Utils::FilePath fileName = workspaceNameToFilePath(workspace);
|
||||||
|
|
||||||
if (!QFile::remove(fileName.toString()))
|
if (!fileName.removeFile())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
QDir presetsDir(d->m_workspacePresetsPath);
|
QDir presetsDir(d->m_workspacePresetsPath);
|
||||||
bool result = QFile::copy(presetsDir.filePath(workspaceNameToFileName(workspace)),
|
bool result = QFile::copy(presetsDir.filePath(workspaceNameToFileName(workspace)),
|
||||||
fileName.toString());
|
fileName.toFSPathString());
|
||||||
if (result)
|
if (result)
|
||||||
d->m_workspaceDateTimes.insert(workspace, QDateTime::currentDateTime());
|
d->m_workspaceDateTimes.insert(workspace, QDateTime::currentDateTime());
|
||||||
|
|
||||||
@@ -894,35 +895,36 @@ namespace ADS
|
|||||||
{
|
{
|
||||||
// If we came this far the user decided that in case the target already exists to overwrite it.
|
// If we came this far the user decided that in case the target already exists to overwrite it.
|
||||||
// We first need to remove the existing file, otherwise QFile::copy() will fail.
|
// We first need to remove the existing file, otherwise QFile::copy() will fail.
|
||||||
QFileInfo targetFileInfo(target);
|
const Utils::FilePath targetFile = Utils::FilePath::fromUserInput(target);
|
||||||
|
|
||||||
// Remove the file which supposed to be overwritten
|
// Remove the file which supposed to be overwritten
|
||||||
if (targetFileInfo.exists()) {
|
if (targetFile.exists()) {
|
||||||
QFile fi(targetFileInfo.absoluteFilePath());
|
if (!targetFile.removeFile()) {
|
||||||
if (!fi.remove()) {
|
qCInfo(adsLog) << QString("Couldn't remove '%1'").arg(targetFile.toUserOutput());
|
||||||
qCInfo(adsLog) << QString("Couldn't remove '%1'").arg(targetFileInfo.absoluteFilePath());
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the target directory exists
|
// Check if the target directory exists
|
||||||
if (!targetFileInfo.absoluteDir().exists()) {
|
if (!targetFile.parentDir().exists()) {
|
||||||
qCInfo(adsLog) << QString("Directory doesn't exist '%1'").arg(targetFileInfo.dir().dirName());
|
qCInfo(adsLog) << QString("Directory doesn't exist '%1'")
|
||||||
|
.arg(targetFile.parentDir().toUserOutput());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the workspace exists
|
// Check if the workspace exists
|
||||||
Utils::FilePath workspaceFilePath = workspaceNameToFilePath(workspace);
|
Utils::FilePath workspaceFile = workspaceNameToFilePath(workspace);
|
||||||
if (!workspaceFilePath.exists()) {
|
if (!workspaceFile.exists()) {
|
||||||
qCInfo(adsLog) << QString("Workspace doesn't exist '%1'").arg(workspaceFilePath.toString());
|
qCInfo(adsLog) << QString("Workspace doesn't exist '%1'")
|
||||||
return;
|
.arg(workspaceFile.toUserOutput());
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally copy the workspace to the target
|
// Finally copy the workspace to the target
|
||||||
QFile workspaceFile(workspaceFilePath.toString());
|
const Utils::expected_str<void> copyResult = workspaceFile.copyFile(targetFile);
|
||||||
if (!workspaceFile.copy(targetFileInfo.absoluteFilePath())) {
|
if (!copyResult) {
|
||||||
qCInfo(adsLog) << QString("Could not copy '%1' to '%2' error: %3").arg(
|
qCInfo(adsLog) << QString("Could not copy '%1' to '%2' error: %3")
|
||||||
workspace, workspaceFilePath.toString(), workspaceFile.errorString());
|
.arg(workspace, workspaceFile.toUserOutput(), copyResult.error());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -957,21 +959,25 @@ namespace ADS
|
|||||||
|
|
||||||
QByteArray DockManager::loadWorkspace(const QString &workspace) const
|
QByteArray DockManager::loadWorkspace(const QString &workspace) const
|
||||||
{
|
{
|
||||||
QByteArray data;
|
|
||||||
Utils::FilePath fileName = workspaceNameToFilePath(workspace);
|
Utils::FilePath fileName = workspaceNameToFilePath(workspace);
|
||||||
if (fileName.exists()) {
|
if (fileName.exists()) {
|
||||||
QFile file(fileName.toString());
|
const Utils::expected_str<QByteArray> data = fileName.fileContents();
|
||||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
||||||
|
if (!data) {
|
||||||
QMessageBox::warning(parentWidget(),
|
QMessageBox::warning(parentWidget(),
|
||||||
tr("Cannot Restore Workspace"),
|
tr("Cannot Restore Workspace"),
|
||||||
tr("Could not restore workspace %1")
|
tr("Could not restore workspace %1")
|
||||||
.arg(fileName.toUserOutput()));
|
.arg(fileName.toUserOutput()));
|
||||||
return data;
|
|
||||||
|
qCWarning(adsLog) << QString("Could not restore workspace %1: %2")
|
||||||
|
.arg(fileName.toUserOutput())
|
||||||
|
.arg(data.error());
|
||||||
|
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
data = file.readAll();
|
return data.value();
|
||||||
file.close();
|
|
||||||
}
|
}
|
||||||
return data;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void DockManager::syncWorkspacePresets()
|
void DockManager::syncWorkspacePresets()
|
||||||
|
Reference in New Issue
Block a user