Show a warning if annotations will not be saved to PDF.

The only affected generator is poppler (because it's the only one with
saving support).
Since version 0.20, Poppler can save annotations to PDF. If the user is
using an older version, this patch warns him that annotations are not
saved.
This commit is contained in:
Fabio D'Urso 2012-06-13 15:33:49 +02:00
parent c13e81cccd
commit 23eb083b00
3 changed files with 74 additions and 0 deletions

View file

@ -3479,6 +3479,23 @@ bool Document::canSaveChanges() const
return saveIface->supportsOption( SaveInterface::SaveChanges );
}
bool Document::canSaveChanges( SaveCapability cap ) const
{
switch ( cap )
{
case Document::Forms:
/* Assume that if the generator supports saving, forms can be saved.
* We have no means to actually query the generator at the moment
* TODO: Add some method to query the generator in SaveInterface */
return canSaveChanges();
case Document::Annotations:
return d->canAddAnnotationsNatively();
}
return false;
}
bool Document::saveChanges( const QString &fileName )
{
QString errorText;

View file

@ -561,10 +561,34 @@ class OKULAR_EXPORT Document : public QObject
*/
const KComponentData* componentData() const;
/**
* Saving capabilities. Their availability varies according to the
* underlying generator and/or the document type.
*
* @see canSaveChanges (SaveCapability)
* @since 0.15 (KDE 4.9)
*/
enum SaveCapability
{
Forms = 1, ///< Can save form changes
Annotations = 2 ///< Can save annotation changes
};
/**
* Returns whether it's possible to save a given category of changes to
* another document.
*
* @since 0.15 (KDE 4.9)
*/
bool canSaveChanges( SaveCapability cap ) const;
/**
* Returns whether the changes to the document (modified annotations,
* values in form fields, etc) can be saved to another document.
*
* Equivalent to the logical OR of canSaveChanges(SaveCapability) for
* each capability.
*
* @since 0.7 (KDE 4.1)
*/
bool canSaveChanges() const;

View file

@ -86,6 +86,7 @@
#include "conf/preferencesdialog.h"
#include "settings.h"
#include "core/action.h"
#include "core/annotations.h"
#include "core/bookmarkmanager.h"
#include "core/document.h"
#include "core/generator.h"
@ -1946,6 +1947,38 @@ void Part::slotSaveFileAs()
if ( m_embedMode == PrintPreviewMode )
return;
/* Show a warning before saving if the generator can't save annotations,
* unless we are going to save a .okular archive. */
if ( !isDocumentArchive && !m_document->canSaveChanges( Document::Annotations ) )
{
/* Search local annotations */
bool containsLocalAnnotations = false;
const int pagecount = m_document->pages();
for ( int pageno = 0; pageno < pagecount; ++pageno )
{
const Okular::Page *page = m_document->page( pageno );
foreach ( const Okular::Annotation *ann, page->annotations() )
{
if ( !(ann->flags() & Okular::Annotation::External) )
{
containsLocalAnnotations = true;
break;
}
}
if ( containsLocalAnnotations )
break;
}
/* Don't show it if there are no local annotations */
if ( containsLocalAnnotations )
{
int res = KMessageBox::warningContinueCancel( widget(), "Your annotations will not be exported.\nYou can export the annotated document using File -> Export As -> Document Archive" );
if ( res != KMessageBox::Continue )
return; // Canceled
}
}
KUrl saveUrl = KFileDialog::getSaveUrl( KUrl("kfiledialog:///okular/" + url().fileName()),
QString(), widget(), QString(),
KFileDialog::ConfirmOverwrite );