Commit eb6cd088 authored by Fabio D'Urso's avatar Fabio D'Urso

Fix non-PDF native file extraction from document archives

parent a20afdff
......@@ -4272,6 +4272,17 @@ bool Document::saveDocumentArchive( const QString &fileName )
return true;
}
bool Document::extractArchivedFile( const QString &destFileName )
{
if ( !d->m_archiveData )
return false;
// Remove existing file, if present (QFile::copy doesn't overwrite by itself)
QFile::remove( destFileName );
return d->m_archiveData->document.copy( destFileName );
}
QPrinter::Orientation Document::orientation() const
{
double width, height;
......
......@@ -698,6 +698,15 @@ class OKULAR_EXPORT Document : public QObject
*/
bool saveDocumentArchive( const QString &fileName );
/**
* Extract the document file from the current archive.
*
* @warning This function only works if the current file is a document archive
*
* @since 0.14 (KDE 4.20)
*/
bool extractArchivedFile( const QString &destFileName );
/**
* Asks the generator to dynamically generate a SourceReference for a given
* page number and absolute X and Y position on this page.
......
......@@ -2292,42 +2292,64 @@ bool Part::saveAs( const KUrl & saveUrl, bool saveAsOkularArchive )
}
else
{
// make use of the already downloaded (in case of remote URLs) file,
// no point in downloading that again
KUrl srcUrl = KUrl::fromPath( localFilePath() );
// duh, our local file disappeared...
if ( !QFile::exists( localFilePath() ) )
// If the generators doesn't support saving changes, we will
// just copy the original file.
if ( isDocumentArchive )
{
// Special case: if the user is extracting the contents of a
// .okular archive back to the native format, we can't just copy
// the open file (which is a .okular). So let's ask to core to
// extract and give us the real file
if ( !m_document->extractArchivedFile( fileName ) )
{
KMessageBox::information( widget(), i18n("File could not be saved in '%1'. Try to save it to another location.", fileName ) );
return false;
}
copyJob = KIO::file_copy( fileName, saveUrl, -1, KIO::Overwrite );
}
else
{
if ( url().isLocalFile() )
// Otherwise just copy the open file.
// make use of the already downloaded (in case of remote URLs) file,
// no point in downloading that again
KUrl srcUrl = KUrl::fromPath( localFilePath() );
// duh, our local file disappeared...
if ( !QFile::exists( localFilePath() ) )
{
if ( url().isLocalFile() )
{
#ifdef OKULAR_KEEP_FILE_OPEN
// local file: try to get it back from the open handle on it
tempFile.reset( m_keeper->copyToTemporary() );
if ( tempFile )
srcUrl = KUrl::fromPath( tempFile->fileName() );
// local file: try to get it back from the open handle on it
tempFile.reset( m_keeper->copyToTemporary() );
if ( tempFile )
srcUrl = KUrl::fromPath( tempFile->fileName() );
#else
const QString msg = i18n( "Okular cannot copy %1 to the specified location.\n\nThe document does not exist anymore.", localFilePath() );
KMessageBox::sorry( widget(), msg );
return false;
const QString msg = i18n( "Okular cannot copy %1 to the specified location.\n\nThe document does not exist anymore.", localFilePath() );
KMessageBox::sorry( widget(), msg );
return false;
#endif
}
else
{
// we still have the original remote URL of the document,
// so copy the document from there
srcUrl = url();
}
}
if ( srcUrl != saveUrl )
{
copyJob = KIO::file_copy( srcUrl, saveUrl, -1, KIO::Overwrite );
}
else
{
// we still have the original remote URL of the document,
// so copy the document from there
srcUrl = url();
// Don't do a real copy in this case, just update the timestamps
copyJob = KIO::setModificationTime( saveUrl, QDateTime::currentDateTime() );
}
}
if ( srcUrl != saveUrl )
{
copyJob = KIO::file_copy( srcUrl, saveUrl, -1, KIO::Overwrite );
}
else
{
// Don't do a real copy in this case, just update the timestamps
copyJob = KIO::setModificationTime( saveUrl, QDateTime::currentDateTime() );
}
}
}
......
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