Commit f04b9739 authored by Enrico Ros's avatar Enrico Ros

Follow-up to Albert's commit. DRM handling 'the right way'. Forbids

printing and copying text from protected files (avoids legal issues).

svn path=/trunk/kdegraphics/kpdf/; revision=390880
parent 9352ac52
......@@ -361,9 +361,9 @@ uint KPDFDocument::pages() const
return pages_vector.size();
}
bool KPDFDocument::okToPrint() const
bool KPDFDocument::isAllowed( int flags ) const
{
return generator ? generator->isAllowed( Generator::Print ) : false;
return generator ? generator->isAllowed( flags ) : false;
}
bool KPDFDocument::historyAtBegin() const
......
......@@ -60,6 +60,10 @@ class KPDFDocument : public QObject
void removeObserver( DocumentObserver * pObserver );
void reparseConfig();
// enum definitions
enum Permission { AllowModify = 1, AllowCopy = 2, AllowPrint = 4, AllowNotes = 8 };
enum SearchType { NextMatch, PrevMatch, AllDoc, GoogleLike };
// query methods (const ones)
bool isOpened() const;
const DocumentInfo * documentInfo() const;
......@@ -68,7 +72,7 @@ class KPDFDocument : public QObject
const DocumentViewport & viewport() const;
uint currentPage() const;
uint pages() const;
bool okToPrint() const;
bool isAllowed( int /*Document::Permisison(s)*/ ) const;
bool historyAtBegin() const;
bool historyAtEnd() const;
QString getMetaData( const QString & key, const QString & option = QString() ) const;
......@@ -80,13 +84,10 @@ class KPDFDocument : public QObject
void setNextViewport();
void requestPixmaps( const QValueList< PixmapRequest * > & requests );
void requestTextPage( uint page );
enum SearchType { NextMatch, PrevMatch, AllDoc, GoogleLike };
bool searchText( int searchID, const QString & text, bool fromStart, bool caseSensitive,
SearchType type, bool moveViewport, const QColor & color, bool noDialogs = false );
bool continueSearch( int searchID );
void resetSearch( int searchID );
void toggleBookmark( int page );
void processLink( const KPDFLink * link );
bool print( KPrinter &printer );
......
......@@ -51,8 +51,7 @@ class Generator : public QObject
virtual const DocumentSynopsis * generateDocumentSynopsis() { return 0L; }
// DRM handling
enum Permissions { Modify = 1, Copy = 2, Print = 4, AddNotes = 8 };
virtual bool isAllowed( int /*permissions*/ ) { return true; }
virtual bool isAllowed( int /*Document::Permisison(s)*/ ) { return true; }
// page contents generation
virtual bool canGeneratePixmap() = 0;
......
......@@ -212,10 +212,10 @@ const DocumentSynopsis * PDFGenerator::generateDocumentSynopsis()
bool PDFGenerator::isAllowed( int permissions )
{
bool b = true;
if (permissions & Modify) b = b && pdfdoc->okToChange();
if (permissions & Copy) b = b && pdfdoc->okToCopy();
if (permissions & Print) b = b && pdfdoc->okToPrint();
if (permissions & AddNotes) b = b && pdfdoc->okToAddNotes();
if (permissions & KPDFDocument::AllowModify) b = b && pdfdoc->okToChange();
if (permissions & KPDFDocument::AllowCopy) b = b && pdfdoc->okToCopy();
if (permissions & KPDFDocument::AllowPrint) b = b && pdfdoc->okToPrint();
if (permissions & KPDFDocument::AllowNotes) b = b && pdfdoc->okToAddNotes();
return b;
}
......
......@@ -761,7 +761,7 @@ void Part::slotPrint()
void Part::doPrint(KPrinter &printer)
{
if (!m_document->okToPrint())
if (!m_document->isAllowed(KPDFDocument::AllowPrint))
{
KMessageBox::error(widget(), i18n("Printing this document is not allowed."));
return;
......
......@@ -972,6 +972,8 @@ void PageView::contentsMouseReleaseEvent( QMouseEvent * e )
{
menu.insertTitle( i18n( "Text (1 character)", "Text (%n characters)", selectedText.length() ) );
menu.insertItem( SmallIcon("editcopy"), i18n( "Copy to Clipboard" ), 1 );
if ( !d->document->isAllowed( KPDFDocument::AllowCopy ) )
menu.setItemEnabled( 1, false );
if ( Settings::useKTTSD() )
menu.insertItem( SmallIcon("kttsd"), i18n( "Speak Text" ), 2 );
}
......
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