add errorString output argument to IFile::save()

this centralizes error reporting (in fact, in most cases it adds any in
the first place).

Task-number: QTCREATORBUG-1619
This commit is contained in:
Oswald Buddenhagen
2011-03-30 13:45:16 +02:00
parent 469199e7a5
commit f1f9904d35
36 changed files with 116 additions and 102 deletions

View File

@@ -638,9 +638,24 @@ QList<IFile *> FileManager::saveModifiedFiles(const QList<IFile *> &files,
return notSaved;
}
bool FileManager::saveFile(IFile *file, const QString &fileName)
bool FileManager::saveFile(IFile *file, const QString &fileName, bool *isReadOnly)
{
const bool success = file->save(fileName);
QString effName = fileName.isEmpty() ? file->fileName() : fileName;
QString errorString;
if (!file->save(&errorString, fileName)) {
if (isReadOnly) {
QFile ofi(effName);
// Check whether the existing file is writable
if (ofi.exists() && !ofi.open(QIODevice::ReadWrite)
&& ofi.error() == QFile::PermissionsError) {
*isReadOnly = true;
return false;
}
*isReadOnly = false;
}
QMessageBox::critical(d->m_mainWindow, tr("File Error"), errorString);
return false;
}
// We are updating the lastUpdated time to the current modification time
// in changedFile we'll compare the modification time with the last updated
@@ -655,7 +670,7 @@ bool FileManager::saveFile(IFile *file, const QString &fileName)
foreach (const QString &fileName, d->m_filesWithWatch.value(file))
updateExpectedState(fileName);
return success;
return true;
}
QString FileManager::getSaveFileName(const QString &title, const QString &pathIn,