"Fossies" - the Fresh Open Source Software Archive

Member "poppler-0.82.0/qt5/src/poppler-media.cc" (25 Oct 2019, 4222 Bytes) of package /linux/misc/poppler-0.82.0.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "poppler-media.cc" see the Fossies "Dox" file reference documentation.

    1 /* poppler-media.cc: qt interface to poppler
    2  * Copyright (C) 2012 Guillermo A. Amaral B. <gamaral@kde.org>
    3  * Copyright (C) 2013, 2018 Albert Astals Cid <aacid@kde.org>
    4  *
    5  * This program is free software; you can redistribute it and/or modify
    6  * it under the terms of the GNU General Public License as published by
    7  * the Free Software Foundation; either version 2, or (at your option)
    8  * any later version.
    9  *
   10  * This program is distributed in the hope that it will be useful,
   11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13  * GNU General Public License for more details.
   14  *
   15  * You should have received a copy of the GNU General Public License
   16  * along with this program; if not, write to the Free Software
   17  * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
   18  */
   19 
   20 #include "poppler-media.h"
   21 
   22 #include "Rendition.h"
   23 
   24 #include "poppler-private.h"
   25 
   26 #include <QtCore/QBuffer>
   27 
   28 #define BUFFER_MAX 4096
   29 
   30 namespace Poppler
   31 {
   32 
   33 class MediaRenditionPrivate
   34 {
   35 public:
   36 
   37   MediaRenditionPrivate(::MediaRendition *renditionA)
   38   : rendition(renditionA)
   39   {
   40   }
   41   
   42   ~MediaRenditionPrivate()
   43   {
   44     delete rendition;
   45   }
   46 
   47   MediaRenditionPrivate(const MediaRenditionPrivate &) = delete;
   48   MediaRenditionPrivate& operator=(const MediaRenditionPrivate &) = delete;
   49 
   50   ::MediaRendition *rendition;
   51 };
   52 
   53 MediaRendition::MediaRendition(::MediaRendition *rendition)
   54   : d_ptr(new MediaRenditionPrivate(rendition))
   55 {
   56 }
   57 
   58 MediaRendition::~MediaRendition()
   59 {
   60   delete d_ptr;
   61 }
   62 
   63 bool
   64 MediaRendition::isValid() const
   65 {
   66   Q_D( const MediaRendition );
   67   return d->rendition && d->rendition->isOk();
   68 }
   69 
   70 QString
   71 MediaRendition::contentType() const
   72 {
   73   Q_ASSERT(isValid() && "Invalid media rendition.");
   74   Q_D( const MediaRendition );
   75   return UnicodeParsedString(d->rendition->getContentType());
   76 }
   77 
   78 QString
   79 MediaRendition::fileName() const
   80 {
   81   Q_ASSERT(isValid() && "Invalid media rendition.");
   82   Q_D( const MediaRendition );
   83   return UnicodeParsedString(d->rendition->getFileName());
   84 }
   85 
   86 bool
   87 MediaRendition::isEmbedded() const
   88 {
   89   Q_ASSERT(isValid() && "Invalid media rendition.");
   90   Q_D( const MediaRendition );
   91   return d->rendition->getIsEmbedded();
   92 }
   93 
   94 QByteArray
   95 MediaRendition::data() const
   96 {
   97   Q_ASSERT(isValid() && "Invalid media rendition.");
   98   Q_D( const MediaRendition );
   99 
  100   Stream *s = d->rendition->getEmbbededStream();
  101   if (!s)
  102     return QByteArray();
  103 
  104   QBuffer buffer;
  105   unsigned char data[BUFFER_MAX];
  106   int bread;
  107 
  108   buffer.open(QIODevice::WriteOnly);
  109   s->reset();
  110   while ((bread = s->doGetChars(BUFFER_MAX, data)) != 0)
  111     buffer.write(reinterpret_cast<const char *>(data), bread);
  112   buffer.close();
  113 
  114   return buffer.data();
  115 }
  116 
  117 bool
  118 MediaRendition::autoPlay() const
  119 {
  120   Q_D( const MediaRendition );
  121   if (d->rendition->getBEParameters()) {
  122     return d->rendition->getBEParameters()->autoPlay;
  123   } else if (d->rendition->getMHParameters()) {
  124     return d->rendition->getMHParameters()->autoPlay;
  125   } else qDebug("No BE or MH parameters to reference!");
  126   return false;
  127 }
  128 
  129 bool
  130 MediaRendition::showControls() const
  131 {
  132   Q_D( const MediaRendition );
  133   if (d->rendition->getBEParameters()) {
  134     return d->rendition->getBEParameters()->showControls;
  135   } else if (d->rendition->getMHParameters()) {
  136     return d->rendition->getMHParameters()->showControls;
  137   } else qDebug("No BE or MH parameters to reference!");
  138   return false;
  139 }
  140 
  141 float
  142 MediaRendition::repeatCount() const
  143 {
  144   Q_D( const MediaRendition );
  145   if (d->rendition->getBEParameters()) {
  146     return d->rendition->getBEParameters()->repeatCount;
  147   } else if (d->rendition->getMHParameters()) {
  148     return d->rendition->getMHParameters()->repeatCount;
  149   } else qDebug("No BE or MH parameters to reference!");
  150   return 1.f;
  151 }
  152 
  153 QSize
  154 MediaRendition::size() const
  155 {
  156   Q_D( const MediaRendition );
  157   const MediaParameters *mp = nullptr;
  158 
  159   if (d->rendition->getBEParameters())
  160     mp = d->rendition->getBEParameters();
  161   else if (d->rendition->getMHParameters())
  162     mp = d->rendition->getMHParameters();
  163   else qDebug("No BE or MH parameters to reference!");
  164 
  165   if (mp)
  166     return QSize(mp->windowParams.width, mp->windowParams.height);
  167   return QSize();
  168 }
  169 
  170 }
  171