summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabio D'Urso <[email protected]>2014-05-10 16:34:53 +0200
committerFabio D'Urso <[email protected]>2014-05-11 18:52:13 +0200
commiteb6cd088d7a046b39e7283d979960b4111ee662d (patch)
treebb723ed0eaf22c01ca46f3812a71d3621702df41
parenta20afdff7da16e85d3ec8eced66d9a8fac29dbe7 (diff)
Fix non-PDF native file extraction from document archives
-rw-r--r--core/document.cpp11
-rw-r--r--core/document.h9
-rw-r--r--part.cpp74
3 files changed, 68 insertions, 26 deletions
diff --git a/core/document.cpp b/core/document.cpp
index 504d07c..803b7cb 100644
--- a/core/document.cpp
+++ b/core/document.cpp
@@ -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;
diff --git a/core/document.h b/core/document.h
index 06bac8a..5850049 100644
--- a/core/document.h
+++ b/core/document.h
@@ -699,6 +699,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.
*
diff --git a/part.cpp b/part.cpp
index fd0a928..847406e 100644
--- a/part.cpp
+++ b/part.cpp
@@ -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() );
- }
}
}