Commit 10ba02cb authored by Albert Astals Cid's avatar Albert Astals Cid

in case we have a new enough poppler give a better error message when we can't...

in case we have a new enough poppler give a better error message when we can't save files with /Encrypt
BUGS: 208119

svn path=/trunk/KDE/kdegraphics/okular/; revision=1037771
parent 2fd0a012
......@@ -3190,6 +3190,12 @@ bool Document::canSaveChanges() const
}
bool Document::saveChanges( const QString &fileName )
{
QString errorText;
return saveChanges( fileName, &errorText );
}
bool Document::saveChanges( const QString &fileName, QString *errorText )
{
if ( !d->m_generator || fileName.isEmpty() )
return false;
......@@ -3201,7 +3207,7 @@ bool Document::saveChanges( const QString &fileName )
if ( !saveIface || !saveIface->supportsOption( SaveInterface::SaveChanges ) )
return false;
return saveIface->save( fileName, SaveInterface::SaveChanges );
return saveIface->save( fileName, SaveInterface::SaveChanges, errorText );
}
void Document::registerView( View *view )
......
......@@ -542,6 +542,14 @@ class OKULAR_EXPORT Document : public QObject
*/
bool saveChanges( const QString &fileName );
/**
* Save the document and the optional changes to it to the specified
* @p fileName and returns a @p errorText if fails.
*
* @since 0.10 (KDE 4.4)
*/
bool saveChanges( const QString &fileName, QString *errorText );
/**
* Register the specified @p view for the current document.
*
......
......@@ -1507,7 +1507,7 @@ bool PDFGenerator::supportsOption( SaveOption option ) const
return false;
}
bool PDFGenerator::save( const QString &fileName, SaveOptions options )
bool PDFGenerator::save( const QString &fileName, SaveOptions options, QString *errorText )
{
Poppler::PDFConverter *pdfConv = pdfdoc->pdfConverter();
......@@ -1517,6 +1517,26 @@ bool PDFGenerator::save( const QString &fileName, SaveOptions options )
QMutexLocker locker( userMutex() );
bool success = pdfConv->convert();
#ifdef HAVE_POPPLER_0_12_1
if (!success)
{
switch (pdfConv->lastError())
{
case Poppler::BaseConverter::NotSupportedInputFileError:
*errorText = i18n("Saving files with /Encrypt is not supported.");
break;
case Poppler::BaseConverter::NoError:
case Poppler::BaseConverter::FileLockedError:
// we can't get here
break;
case Poppler::BaseConverter::OpenOutputError:
// the default text message is good for this case
break;
}
}
#endif
delete pdfConv;
return success;
}
......
......@@ -97,7 +97,7 @@ class PDFGenerator : public Okular::Generator, public Okular::ConfigInterface, p
// [INHERITED] save interface
bool supportsOption( SaveOption ) const;
bool save( const QString &fileName, SaveOptions options );
bool save( const QString &fileName, SaveOptions options, QString *errorText );
protected:
bool doCloseDocument();
......
......@@ -64,12 +64,12 @@ class OKULAR_EXPORT SaveInterface
/**
* Save to the specified @p fileName with the specified @p options.
*/
virtual bool save( const QString &fileName, SaveOptions options ) = 0;
virtual bool save( const QString &fileName, SaveOptions options, QString *errorText ) = 0;
};
}
Q_DECLARE_INTERFACE( Okular::SaveInterface, "org.kde.okular.SaveInterface/0.1" )
Q_DECLARE_INTERFACE( Okular::SaveInterface, "org.kde.okular.SaveInterface/0.2" )
Q_DECLARE_OPERATORS_FOR_FLAGS( Okular::SaveInterface::SaveOptions )
#endif
......@@ -1499,9 +1499,17 @@ void Part::slotSaveFileAs()
fileName = tf.fileName();
tf.close();
if ( !m_document->saveChanges( fileName ) )
QString errorText;
if ( !m_document->saveChanges( fileName, &errorText ) )
{
KMessageBox::information( widget(), i18n("File could not be saved in '%1'. Try to save it to another location.", fileName ) );
if (errorText.isEmpty())
{
KMessageBox::information( widget(), i18n("File could not be saved in '%1'. Try to save it to another location.", fileName ) );
}
else
{
KMessageBox::information( widget(), i18n("File could not be saved in '%1'. %2", fileName, errorText ) );
}
return;
}
......
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