[poppler] qt4/src

Albert Astals Cid aacid at kemper.freedesktop.org
Wed Mar 14 17:01:41 PDT 2012


 qt4/src/CMakeLists.txt                           |    3 
 qt4/src/poppler-annotation.cc                    |   66 ++++++++++
 qt4/src/poppler-annotation.h                     |   47 +++++++
 qt4/src/poppler-link.cc                          |   44 ++++++
 qt4/src/poppler-link.h                           |   38 +++++
 qt4/src/poppler-media.cc                         |  149 +++++++++++++++++++++++
 qt4/src/poppler-media.h                          |   94 ++++++++++++++
 qt4/src/poppler-page.cc                          |   32 ++++
 qt4/src/poppler-qt4.h                            |    2 
 qt4/src/poppler-streamsequentialdevice-private.h |   51 +++++++
 qt4/src/poppler-streamsequentialdevice.cc        |   56 ++++++++
 11 files changed, 579 insertions(+), 3 deletions(-)

New commits:
commit aa1e6d12d063a64a22841f7996101b45aa680ec7
Author: Guillermo Amaral <gamaral at kdab.com>
Date:   Thu Mar 15 00:35:31 2012 +0100

    Added media rendition support for Qt4

diff --git a/qt4/src/CMakeLists.txt b/qt4/src/CMakeLists.txt
index 99dce58..ae17376 100644
--- a/qt4/src/CMakeLists.txt
+++ b/qt4/src/CMakeLists.txt
@@ -25,6 +25,8 @@ set(poppler_qt4_SRCS
   poppler-sound.cc
   poppler-textbox.cc
   poppler-page-transition.cc
+  poppler-streamsequentialdevice.cc
+  poppler-media.cc
   ${CMAKE_SOURCE_DIR}/poppler/ArthurOutputDev.cc
 )
 qt4_automoc(${poppler_qt4_SRCS})
@@ -44,5 +46,6 @@ install(FILES
   poppler-optcontent.h
   poppler-export.h
   poppler-page-transition.h
+  poppler-media.h
   DESTINATION include/poppler/qt4)
 
diff --git a/qt4/src/poppler-annotation.cc b/qt4/src/poppler-annotation.cc
index 907c3ba..3faef27 100644
--- a/qt4/src/poppler-annotation.cc
+++ b/qt4/src/poppler-annotation.cc
@@ -1,6 +1,7 @@
 /* poppler-annotation.cc: qt interface to poppler
  * Copyright (C) 2006, 2009 Albert Astals Cid <aacid at kde.org>
  * Copyright (C) 2006, 2008, 2010 Pino Toscano <pino at kde.org>
+ * Copyright (C) 2012, Guillermo A. Amaral B. <gamaral at kde.org>
  * Adapting code from
  *   Copyright (C) 2004 by Enrico Ros <eros.kde at email.it>
  *
@@ -1617,6 +1618,11 @@ void LinkAnnotation::store( QDomNode & node, QDomDocument & document ) const
                 hyperlinkElement.setAttribute( "type", "Movie" );
                 break;
             }
+            case Poppler::Link::Rendition:
+            {
+                hyperlinkElement.setAttribute( "type", "Rendition" );
+                break;
+            }
             case Poppler::Link::Sound:
             {
                 // FIXME: implement me
@@ -2038,6 +2044,66 @@ void MovieAnnotation::setMovieTitle( const QString &title )
     d->title = title;
 }
 
+/** ScreenAnnotation [Annotation] */
+class ScreenAnnotationPrivate : public AnnotationPrivate
+{
+    public:
+        ScreenAnnotationPrivate();
+        ~ScreenAnnotationPrivate();
+
+        // data fields
+        LinkRendition *action;
+        QString title;
+};
+
+ScreenAnnotationPrivate::ScreenAnnotationPrivate()
+    : AnnotationPrivate(), action( 0 )
+{
+}
+
+ScreenAnnotationPrivate::~ScreenAnnotationPrivate()
+{
+    delete action;
+}
+
+ScreenAnnotation::ScreenAnnotation()
+    : Annotation( *new ScreenAnnotationPrivate() )
+{
+}
+
+ScreenAnnotation::~ScreenAnnotation()
+{
+}
+
+Annotation::SubType ScreenAnnotation::subType() const
+{
+    return AScreen;
+}
+
+LinkRendition* ScreenAnnotation::action() const
+{
+    Q_D( const ScreenAnnotation );
+    return d->action;
+}
+
+void ScreenAnnotation::setAction( LinkRendition *action )
+{
+    Q_D( ScreenAnnotation );
+    d->action = action;
+}
+
+QString ScreenAnnotation::screenTitle() const
+{
+    Q_D( const ScreenAnnotation );
+    return d->title;
+}
+
+void ScreenAnnotation::setScreenTitle( const QString &title )
+{
+    Q_D( ScreenAnnotation );
+    d->title = title;
+}
+
 //BEGIN utility annotation functions
 QColor convertAnnotColor( AnnotColor *color )
 {
diff --git a/qt4/src/poppler-annotation.h b/qt4/src/poppler-annotation.h
index 4124c74..7700c7a 100644
--- a/qt4/src/poppler-annotation.h
+++ b/qt4/src/poppler-annotation.h
@@ -4,6 +4,7 @@
  * Copyright (C) 2007, Brad Hards <bradh at frogmouth.net>
  * Copyright (C) 2010, Philip Lorenz <lorenzph+freedesktop at gmail.com>
  * Copyright (C) 2012, Tobias Koenig <tokoe at kdab.com>
+ * Copyright (C) 2012, Guillermo A. Amaral B. <gamaral at kde.org>
  * Adapting code from
  *   Copyright (C) 2004 by Enrico Ros <eros.kde at email.it>
  *
@@ -50,10 +51,12 @@ class CaretAnnotationPrivate;
 class FileAttachmentAnnotationPrivate;
 class SoundAnnotationPrivate;
 class MovieAnnotationPrivate;
+class ScreenAnnotationPrivate;
 class EmbeddedFile;
 class Link;
 class SoundObject;
 class MovieObject;
+class LinkRendition;
 
 /**
  * \short Helper class for (recursive) Annotation retrieval/storage.
@@ -102,7 +105,7 @@ class POPPLER_QT4_EXPORT Annotation
     // WARNING!!! oKular uses that very same values so if you change them notify the author!
     enum SubType { AText = 1, ALine = 2, AGeom = 3, AHighlight = 4, AStamp = 5,
                    AInk = 6, ALink = 7, ACaret = 8, AFileAttachment = 9, ASound = 10,
-                   AMovie = 11, A_BASE = 0 };
+                   AMovie = 11, AScreen = 12, A_BASE = 0 };
     enum Flag { Hidden = 1, FixedSize = 2, FixedRotation = 4, DenyPrint = 8,
                 DenyWrite = 16, DenyDelete = 32, ToggleHidingOnMouse = 64, External = 128 };
     enum LineStyle { Solid = 1, Dashed = 2, Beveled = 4, Inset = 8, Underline = 16 };
@@ -685,6 +688,48 @@ class POPPLER_QT4_EXPORT MovieAnnotation : public Annotation
     Q_DISABLE_COPY( MovieAnnotation )
 };
 
+/**
+ * \short Screen annotation.
+ *
+ * The screen annotation represents a screen to be played when activated.
+ *
+ * \since 0.20
+ */
+class POPPLER_QT4_EXPORT ScreenAnnotation : public Annotation
+{
+  public:
+    ScreenAnnotation();
+    virtual ~ScreenAnnotation();
+
+    virtual SubType subType() const;
+
+    /**
+     * Returns the LinkRendition of this annotation.
+     */
+    LinkRendition* action() const;
+
+    /**
+     * Sets a new LinkRendition for this annotation.
+     *
+     * \note ScreenAnnotation takes ownership of the object
+     */
+    void setAction( LinkRendition *action );
+
+    /**
+     * Returns the title of the screen of this annotation.
+     */
+    QString screenTitle() const;
+
+    /**
+     * Sets a new title for the screen of this annotation.
+     */
+    void setScreenTitle( const QString &title );
+
+  private:
+    Q_DECLARE_PRIVATE( ScreenAnnotation )
+    Q_DISABLE_COPY( ScreenAnnotation )
+};
+
 }
 
 #endif
diff --git a/qt4/src/poppler-link.cc b/qt4/src/poppler-link.cc
index bbfd39f..9ee01fe 100644
--- a/qt4/src/poppler-link.cc
+++ b/qt4/src/poppler-link.cc
@@ -3,6 +3,7 @@
  * Copyright (C) 2007-2008, Pino Toscano <pino at kde.org>
  * Copyright (C) 2010 Hib Eris <hib at hiberis.nl>
  * Copyright (C) 2012, Tobias Koenig <tokoe at kdab.com>
+ * Copyright (C) 2012, Guillermo A. Amaral B. <gamaral at kde.org>
  * Adapting code from
  *   Copyright (C) 2004 by Enrico Ros <eros.kde at email.it>
  *
@@ -23,12 +24,14 @@
 
 #include <poppler-qt4.h>
 #include <poppler-private.h>
+#include <poppler-media.h>
 
 #include <QtCore/QStringList>
 
 #include "poppler-annotation-private.h"
 
 #include "Link.h"
+#include "Rendition.h"
 
 bool operator==( const Ref &r1, const Ref &r2 )
 {
@@ -162,6 +165,26 @@ class LinkSoundPrivate : public LinkPrivate
 		delete sound;
 	}
 
+class LinkRenditionPrivate : public LinkPrivate
+{
+	public:
+		LinkRenditionPrivate( const QRectF &area, ::MediaRendition *rendition );
+		~LinkRenditionPrivate();
+
+		MediaRendition *rendition;
+};
+
+	LinkRenditionPrivate::LinkRenditionPrivate( const QRectF &area, ::MediaRendition *r )
+		: LinkPrivate( area )
+		, rendition( new MediaRendition( r ) )
+	{
+	}
+
+	LinkRenditionPrivate::~LinkRenditionPrivate()
+	{
+		delete rendition;
+	}
+
 class LinkJavaScriptPrivate : public LinkPrivate
 {
 	public:
@@ -554,6 +577,27 @@ class LinkMoviePrivate : public LinkPrivate
 		return d->sound;
 	}
 
+	// LinkRendition
+	LinkRendition::LinkRendition( const QRectF &linkArea, ::MediaRendition *rendition )
+		: Link( *new LinkRenditionPrivate( linkArea, rendition ) )
+	{
+	}
+	
+	LinkRendition::~LinkRendition()
+	{
+	}
+	
+	Link::LinkType LinkRendition::linkType() const
+	{
+		return Rendition;
+	}
+	
+	MediaRendition * LinkRendition::rendition() const
+	{
+		Q_D( const LinkRendition );
+		return d->rendition;
+	}
+
 	// LinkJavaScript
 	LinkJavaScript::LinkJavaScript( const QRectF &linkArea, const QString &js )
 		: Link( *new LinkJavaScriptPrivate( linkArea ) )
diff --git a/qt4/src/poppler-link.h b/qt4/src/poppler-link.h
index 37a2ef5..a2ef2d3 100644
--- a/qt4/src/poppler-link.h
+++ b/qt4/src/poppler-link.h
@@ -1,7 +1,7 @@
 /* poppler-link.h: qt interface to poppler
  * Copyright (C) 2006, Albert Astals Cid <aacid at kde.org>
  * Copyright (C) 2007-2008, 2010, Pino Toscano <pino at kde.org>
- * Copyright (C) 2010, Guillermo Amaral <gamaral at kdab.com>
+ * Copyright (C) 2010, 2012, Guillermo Amaral <gamaral at kdab.com>
  * Copyright (C) 2012, Tobias Koenig <tokoe at kdab.com>
  * Adapting code from
  *   Copyright (C) 2004 by Enrico Ros <eros.kde at email.it>
@@ -30,6 +30,7 @@
 #include "poppler-export.h"
 
 struct Ref;
+class MediaRendition;
 
 namespace Poppler {
 
@@ -43,6 +44,8 @@ class LinkJavaScriptPrivate;
 class LinkMoviePrivate;
 class LinkDestinationData;
 class LinkDestinationPrivate;
+class LinkRenditionPrivate;
+class MediaRendition;
 class SoundObject;
 
 /**
@@ -186,6 +189,7 @@ class POPPLER_QT4_EXPORT Link
 		    Action,   ///< A "standard" action to be executed in the viewer
 		    Sound,    ///< A link representing a sound to be played
 		    Movie,    ///< An action to be executed on a movie
+		    Rendition,    ///< A rendition link \since 0.20
 		    JavaScript    ///< A JavaScript code to be interpreted \since 0.10
 		};
 
@@ -443,6 +447,38 @@ class POPPLER_QT4_EXPORT LinkSound : public Link
 };
 
 /**
+ * Rendition: Rendition link.
+ *
+ * \since 0.20
+ */
+class POPPLER_QT4_EXPORT LinkRendition : public Link
+{
+	public:
+		/**
+		 * Create a new media rendition link.
+		 *
+		 * \param linkArea the active area of the link
+		 * \param rendition 
+		 */
+		LinkRendition( const QRectF &linkArea, ::MediaRendition *rendition );
+		/**
+		 * Destructor.
+		 */
+		virtual ~LinkRendition();
+
+		LinkType linkType() const;
+
+		/**
+		 * 
+		 */
+		MediaRendition *rendition() const;
+
+	private:
+		Q_DECLARE_PRIVATE( LinkRendition )
+		Q_DISABLE_COPY( LinkRendition )
+};
+
+/**
  * JavaScript: a JavaScript code to be interpreted.
  *
  * \since 0.10
diff --git a/qt4/src/poppler-media.cc b/qt4/src/poppler-media.cc
new file mode 100644
index 0000000..422aaad
--- /dev/null
+++ b/qt4/src/poppler-media.cc
@@ -0,0 +1,149 @@
+/* poppler-media.cc: qt interface to poppler
+ * Copyright (C) 2012 Guillermo A. Amaral B. <gamaral at kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "poppler-media.h"
+
+#include "Rendition.h"
+
+#include "poppler-private.h"
+#include "poppler-streamsequentialdevice-private.h"
+
+namespace Poppler
+{
+
+class MediaRenditionPrivate
+{
+public:
+
+  MediaRenditionPrivate(::MediaRendition *rendition)
+  : rendition(rendition), device(0)
+  {
+  }
+
+  ::MediaRendition *rendition;
+  QIODevice *device;
+};
+
+MediaRendition::MediaRendition(::MediaRendition *rendition)
+  : d_ptr(new MediaRenditionPrivate(rendition))
+{
+  Q_D( MediaRendition );
+
+  if (d->rendition)
+     d->device = new StreamSequentialDevice(d->rendition->getEmbbededStream());
+}
+
+MediaRendition::~MediaRendition()
+{
+  delete d_ptr->device;
+  delete d_ptr;
+}
+
+bool
+MediaRendition::isValid() const
+{
+  Q_D( const MediaRendition );
+  return d->rendition && d->rendition->isOk();
+}
+
+QString
+MediaRendition::contentType() const
+{
+  Q_ASSERT(isValid() && "Invalid media rendition.");
+  Q_D( const MediaRendition );
+  return UnicodeParsedString(d->rendition->getContentType());
+}
+
+QString
+MediaRendition::fileName() const
+{
+  Q_ASSERT(isValid() && "Invalid media rendition.");
+  Q_D( const MediaRendition );
+  return UnicodeParsedString(d->rendition->getFileName());
+}
+
+bool
+MediaRendition::isEmbedded() const
+{
+  Q_ASSERT(isValid() && "Invalid media rendition.");
+  Q_D( const MediaRendition );
+  return d->rendition->getIsEmbedded();
+}
+
+QIODevice *
+MediaRendition::streamDevice() const
+{
+  Q_D( const MediaRendition );
+  return d->device;
+}
+
+bool
+MediaRendition::autoPlay() const
+{
+  Q_D( const MediaRendition );
+  if (d->rendition->getBEParameters()) {
+    return d->rendition->getBEParameters()->autoPlay;
+  } else if (d->rendition->getMHParameters()) {
+    return d->rendition->getMHParameters()->autoPlay;
+  } else qDebug("No BE or MH paremeters to reference!");
+  return false;
+}
+
+bool
+MediaRendition::showControls() const
+{
+  Q_D( const MediaRendition );
+  if (d->rendition->getBEParameters()) {
+    return d->rendition->getBEParameters()->showControls;
+  } else if (d->rendition->getMHParameters()) {
+    return d->rendition->getMHParameters()->showControls;
+  } else qDebug("No BE or MH paremeters to reference!");
+  return false;
+}
+
+float
+MediaRendition::repeatCount() const
+{
+  Q_D( const MediaRendition );
+  if (d->rendition->getBEParameters()) {
+    return d->rendition->getBEParameters()->repeatCount;
+  } else if (d->rendition->getMHParameters()) {
+    return d->rendition->getMHParameters()->repeatCount;
+  } else qDebug("No BE or MH paremeters to reference!");
+  return 1.f;
+}
+
+QSize
+MediaRendition::size() const
+{
+  Q_D( const MediaRendition );
+  MediaParameters *mp = 0;
+
+  if (d->rendition->getBEParameters())
+    mp = d->rendition->getBEParameters();
+  else if (d->rendition->getMHParameters())
+    mp = d->rendition->getMHParameters();
+  else qDebug("No BE or MH paremeters to reference!");
+
+  if (mp)
+    return QSize(mp->windowParams.width, mp->windowParams.height);
+  return QSize();
+}
+
+}
+
diff --git a/qt4/src/poppler-media.h b/qt4/src/poppler-media.h
new file mode 100644
index 0000000..3b6f68d
--- /dev/null
+++ b/qt4/src/poppler-media.h
@@ -0,0 +1,94 @@
+/* poppler-media.h: qt interface to poppler
+ * Copyright (C) 2012 Guillermo A. Amaral B. <gamaral at kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __POPPLER_MEDIARENDITION_H__
+#define __POPPLER_MEDIARENDITION_H__
+
+#include <QtCore/QSize>
+#include <QtCore/QString>
+
+class MediaRendition;
+class QIODevice;
+
+namespace Poppler
+{
+  class MediaRenditionPrivate;
+
+  /**
+    Qt wrapper for MediaRendition.
+
+    \since 0.20
+   */
+  class MediaRendition {
+   public:
+    MediaRendition(::MediaRendition *rendition);
+    ~MediaRendition();
+
+    /**
+      Check if wrapper is holding a valid rendition object.
+     */
+    bool isValid() const;
+
+    /**
+      Returns content type.
+     */
+    QString contentType() const;
+
+    /**
+      Returns file name.
+     */
+    QString fileName() const;
+
+    /**
+      Returns true if media is embedded.
+     */
+    bool isEmbedded() const;
+
+    /**
+      Returns data stream device.
+     */
+    QIODevice *streamDevice() const;
+
+    /**
+      Convenience accessor for auto-play parameter.
+     */
+    bool autoPlay() const;
+
+    /**
+      Convenience accessor for show controls parameter.
+     */
+    bool showControls() const;
+
+    /**
+      Convenience accessor for repeat count parameter.
+     */
+    float repeatCount() const;
+
+    /**
+      Convenience accessor for size parameter.
+     */
+    QSize size() const;
+
+   private:
+    Q_DECLARE_PRIVATE( MediaRendition )
+    MediaRenditionPrivate *d_ptr;
+    Q_DISABLE_COPY( MediaRendition )
+  };
+}
+
+#endif /* __POPPLER_MEDIARENDITION_H__ */
diff --git a/qt4/src/poppler-page.cc b/qt4/src/poppler-page.cc
index 01d6787..1369e44 100644
--- a/qt4/src/poppler-page.cc
+++ b/qt4/src/poppler-page.cc
@@ -6,7 +6,7 @@
  * Copyright (C) 2006-2011, Pino Toscano <pino at kde.org>
  * Copyright (C) 2008 Carlos Garcia Campos <carlosgc at gnome.org>
  * Copyright (C) 2009 Shawn Rutledge <shawn.t.rutledge at gmail.com>
- * Copyright (C) 2010, Guillermo Amaral <gamaral at kdab.com>
+ * Copyright (C) 2010, 2012, Guillermo Amaral <gamaral at kdab.com>
  * Copyright (C) 2010 Suzuki Toshiya <mpsuzuki at hiroshima-u.ac.jp>
  * Copyright (C) 2010 Matthias Fauconneau <matthias.fauconneau at gmail.com>
  * Copyright (C) 2010 Hib Eris <hib at hiberis.nl>
@@ -45,6 +45,7 @@
 #include <Link.h>
 #include <FileSpec.h>
 #include <ArthurOutputDev.h>
+#include <Rendition.h>
 #if defined(HAVE_SPLASH)
 #include <SplashOutputDev.h>
 #include <splash/SplashBitmap.h>
@@ -57,6 +58,8 @@
 #include "poppler-annotation-helper.h"
 #include "poppler-annotation-private.h"
 #include "poppler-form.h"
+#include "poppler-media.h"
+#include "poppler-streamsequentialdevice-private.h"
 
 namespace Poppler {
 
@@ -203,6 +206,13 @@ Link* PageData::convertLinkActionToLink(::LinkAction * a, DocumentData *parentDo
     }
     break;
 
+    case actionRendition:
+    {
+      ::LinkRendition *lrn = (::LinkRendition *)a;
+      popplerLink = new LinkRendition( linkArea, lrn->getMedia() );
+    }
+    break;
+
     case actionUnknown:
     break;
   }
@@ -997,6 +1007,26 @@ QList<Annotation*> Page::annotations() const
 
                 break;
             }
+            case Annot::typeScreen:
+            {
+                AnnotScreen * screenann = static_cast< AnnotScreen * >( ann );
+
+                if (!screenann->getAction())
+                  continue;
+
+                ScreenAnnotation * s = new ScreenAnnotation();
+                annotation = s;
+
+                // -> screen
+                s->setAction( static_cast<Poppler::LinkRendition *>(m_page->convertLinkActionToLink( screenann->getAction(), QRectF() ) ) );
+
+                // -> screenTitle
+                GooString * screentitle = screenann->getTitle();
+                if ( screentitle )
+                    s->setScreenTitle( UnicodeParsedString( screentitle ) );
+
+                break;
+            }
             // special case for ignoring unknwon annotations
             case Annot::typeUnknown:
                 continue;
diff --git a/qt4/src/poppler-qt4.h b/qt4/src/poppler-qt4.h
index 4ba27ed..f721f92 100644
--- a/qt4/src/poppler-qt4.h
+++ b/qt4/src/poppler-qt4.h
@@ -9,6 +9,7 @@
  * Copyright (C) 2010 Matthias Fauconneau <matthias.fauconneau at gmail.com>
  * Copyright (C) 2011 Andreas Hartmetz <ahartmetz at gmail.com>
  * Copyright (C) 2011 Glad Deschrijver <glad.deschrijver at gmail.com>
+ * Copyright (C) 2012, Guillermo A. Amaral B. <gamaral at kde.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -42,6 +43,7 @@
 class EmbFile;
 class Sound;
 class AnnotMovie;
+class AnnotScreen;
 
 /**
    The %Poppler Qt4 binding.
diff --git a/qt4/src/poppler-streamsequentialdevice-private.h b/qt4/src/poppler-streamsequentialdevice-private.h
new file mode 100644
index 0000000..ec2dae2
--- /dev/null
+++ b/qt4/src/poppler-streamsequentialdevice-private.h
@@ -0,0 +1,51 @@
+/* poppler-streamdevice-private.h: Qt4 interface to poppler
+ * Copyright (C) 2012, Guillermo A. Amaral B. <gamaral at kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef POPPLER_STREAMSEQUENTIALDEVICE_PRIVATE_H
+#define POPPLER_STREAMSEQUENTIALDEVICE_PRIVATE_H
+
+#include <QtCore/QIODevice>
+
+class Stream;
+
+namespace Poppler {
+
+class StreamSequentialDevice : public QIODevice
+{
+  public:
+    StreamSequentialDevice(Stream *stream, QObject *parent = 0);
+    virtual ~StreamSequentialDevice();
+
+    virtual void close();
+
+    virtual bool isSequential() const
+      { return true; }
+
+  protected:
+    virtual qint64 readData(char *data, qint64 maxSize);
+    inline virtual qint64 writeData(const char *, qint64)
+      { return 0; }
+
+  private:
+    Q_DISABLE_COPY(StreamSequentialDevice);
+    Stream *m_stream;
+};
+
+}
+
+#endif
diff --git a/qt4/src/poppler-streamsequentialdevice.cc b/qt4/src/poppler-streamsequentialdevice.cc
new file mode 100644
index 0000000..fa5a064
--- /dev/null
+++ b/qt4/src/poppler-streamsequentialdevice.cc
@@ -0,0 +1,56 @@
+/* poppler-streamdevice.cc: Qt4 interface to poppler
+ * Copyright (C) 2012, Guillermo A. Amaral B. <gamaral at kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "poppler-streamsequentialdevice-private.h"
+
+#include "Object.h"
+#include "Stream.h"
+
+namespace Poppler {
+
+StreamSequentialDevice::StreamSequentialDevice(Stream *stream, QObject *parent)
+    : QIODevice(parent)
+    , m_stream(stream)
+{
+	Q_ASSERT(m_stream && "Invalid stream assigned.");
+	m_stream->incRef();
+	m_stream->reset();
+	open(QIODevice::ReadOnly);
+}
+
+StreamSequentialDevice::~StreamSequentialDevice()
+{
+	m_stream->decRef();
+	m_stream = 0;
+}
+
+void
+StreamSequentialDevice::close()
+{
+	m_stream->close();
+	QIODevice::close();
+}
+
+qint64
+StreamSequentialDevice::readData(char *data, qint64 maxSize)
+{
+	return m_stream->doGetChars(maxSize, reinterpret_cast<Guchar*>(data));
+}
+
+}
+


More information about the poppler mailing list