Commit 9d5105ba authored by Craig Watson's avatar Craig Watson

Check if location is writable before exporting to PDF

parent 97b8ff49
...@@ -142,8 +142,8 @@ void UBExportFullPDF::persist(UBDocumentProxy* pDocumentProxy) ...@@ -142,8 +142,8 @@ void UBExportFullPDF::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();
...@@ -151,8 +151,24 @@ void UBExportFullPDF::persist(UBDocumentProxy* pDocumentProxy) ...@@ -151,8 +151,24 @@ void UBExportFullPDF::persist(UBDocumentProxy* pDocumentProxy)
} }
void UBExportFullPDF::persistsDocument(UBDocumentProxy* pDocumentProxy, const QString& filename) bool UBExportFullPDF::persistsDocument(UBDocumentProxy* pDocumentProxy, const 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;
}
QFile file(filename); QFile file(filename);
if (file.exists()) file.remove(); if (file.exists()) file.remove();
...@@ -269,6 +285,8 @@ void UBExportFullPDF::persistsDocument(UBDocumentProxy* pDocumentProxy, const QS ...@@ -269,6 +285,8 @@ void UBExportFullPDF::persistsDocument(UBDocumentProxy* pDocumentProxy, const QS
QFile::remove(overlayName); QFile::remove(overlayName);
} }
} }
return true;
} }
......
...@@ -45,7 +45,7 @@ class UBExportFullPDF : public UBExportAdaptor ...@@ -45,7 +45,7 @@ class UBExportFullPDF : public UBExportAdaptor
virtual QString exportExtention(); virtual QString exportExtention();
virtual void persist(UBDocumentProxy* pDocument); virtual void persist(UBDocumentProxy* pDocument);
virtual void persistsDocument(UBDocumentProxy* pDocument, const QString& filename); virtual bool persistsDocument(UBDocumentProxy* pDocument, const QString& filename);
protected: protected:
void saveOverlayPdf(UBDocumentProxy* pDocumentProxy, const QString& filename); void saveOverlayPdf(UBDocumentProxy* pDocumentProxy, const QString& filename);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment