Check if location is writable before exporting to .ubz

preferencesAboutTextFull
Craig Watson 9 years ago
parent 53aa4f4928
commit 97b8ff496b
  1. 29
      src/adaptors/UBExportDocument.cpp
  2. 2
      src/adaptors/UBExportDocument.h

@ -68,9 +68,9 @@ void UBExportDocument::persist(UBDocumentProxy* pDocumentProxy)
if (mIsVerbose) if (mIsVerbose)
UBApplication::showMessage(tr("Exporting document...")); UBApplication::showMessage(tr("Exporting document..."));
persistsDocument(pDocumentProxy, filename); bool success = persistsDocument(pDocumentProxy, filename);
if (mIsVerbose) if (mIsVerbose && success)
UBApplication::showMessage(tr("Export successful.")); UBApplication::showMessage(tr("Export successful."));
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
@ -78,14 +78,30 @@ void UBExportDocument::persist(UBDocumentProxy* pDocumentProxy)
} }
void UBExportDocument::persistsDocument(UBDocumentProxy* pDocumentProxy, QString filename) bool UBExportDocument::persistsDocument(UBDocumentProxy* pDocumentProxy, QString filename)
{ {
QFileInfo info(filename);
info.setFile(info.absolutePath());
if (!info.isWritable()) {
UBApplication::showMessage(tr("Export failed: location not writable"));
// The message is a bit discreet: also show a pop-up
QMessageBox errorBox;
errorBox.setWindowTitle(tr("Export failed"));
errorBox.setText(tr("Unable to export to the selected location. You do not have the permissions necessary to save the file."));
errorBox.setIcon(QMessageBox::Critical);
errorBox.exec();
return false;
}
QuaZip zip(filename); QuaZip zip(filename);
zip.setFileNameCodec("UTF-8"); zip.setFileNameCodec("UTF-8");
if(!zip.open(QuaZip::mdCreate)) if(!zip.open(QuaZip::mdCreate))
{ {
qWarning("Export failed. Cause: zip.open(): %d", zip.getZipError()); qWarning("Export failed. Cause: zip.open(): %d", zip.getZipError());
return; return false;
} }
QDir documentDir = QDir(pDocumentProxy->persistencePath()); QDir documentDir = QDir(pDocumentProxy->persistencePath());
@ -93,15 +109,18 @@ void UBExportDocument::persistsDocument(UBDocumentProxy* pDocumentProxy, QString
QuaZipFile outFile(&zip); QuaZipFile outFile(&zip);
UBFileSystemUtils::compressDirInZip(documentDir, "", &outFile, true, this); UBFileSystemUtils::compressDirInZip(documentDir, "", &outFile, true, this);
zip.close();
if(zip.getZipError() != 0) if(zip.getZipError() != 0)
{ {
qWarning("Export failed. Cause: zip.close(): %d", zip.getZipError()); qWarning("Export failed. Cause: zip.close(): %d", zip.getZipError());
return false;
} }
zip.close();
UBPlatformUtils::setFileType(filename, 0x5542647A /* UBdz */); UBPlatformUtils::setFileType(filename, 0x5542647A /* UBdz */);
return true;
} }

@ -49,7 +49,7 @@ class UBExportDocument : public UBExportAdaptor, public UBProcessingProgressList
virtual QString exportExtention(); virtual QString exportExtention();
virtual void persist(UBDocumentProxy* pDocument); virtual void persist(UBDocumentProxy* pDocument);
virtual void persistsDocument(UBDocumentProxy* pDocument, QString filename); virtual bool persistsDocument(UBDocumentProxy* pDocument, QString filename);
virtual void processing(const QString& pObjectName, int pCurrent, int pTotal); virtual void processing(const QString& pObjectName, int pCurrent, int pTotal);
}; };

Loading…
Cancel
Save