Merge pages, pageSize and extractImageFiles.

This fixes change 39fc2a471e
which does not work on archives (zip, rar, etc.).
remotes/origin/KDE/4.8
David Palacio 15 years ago
parent 63a0b4f3cb
commit 82c29939ea
  1. 89
      generators/comicbook/document.cpp
  2. 9
      generators/comicbook/document.h
  3. 12
      generators/comicbook/generator_comicbook.cpp

@ -9,6 +9,7 @@
#include "document.h"
#include <QtCore/QScopedPointer>
#include <QtGui/QImage>
#include <QtGui/QImageReader>
@ -19,6 +20,8 @@
#include <memory>
#include <core/page.h>
#include "unrar.h"
#include "directory.h"
#include "qnatsort.h"
@ -95,7 +98,7 @@ bool Document::open( const QString &fileName )
return false;
}
extractImageFiles( mUnrar->list() );
mEntries = mUnrar->list();
} else if ( mime->is( "inode/directory" ) ) {
mDirectory = new Directory();
@ -106,7 +109,7 @@ bool Document::open( const QString &fileName )
return false;
}
extractImageFiles( mDirectory->list() );
mEntries = mDirectory->list();
} else {
mLastErrorString = i18n( "Unknown ComicBook format." );
return false;
@ -129,6 +132,7 @@ void Document::close()
delete mUnrar;
mUnrar = 0;
mPageMap.clear();
mEntries.clear();
}
bool Document::processArchive() {
@ -149,30 +153,47 @@ bool Document::processArchive() {
mArchiveDir = const_cast<KArchiveDirectory*>( directory );
QStringList entries;
imagesInArchive( QString(), mArchiveDir, &entries );
imagesInArchive( QString(), mArchiveDir, &mEntries );
extractImageFiles( entries );
return true;
}
void Document::extractImageFiles( const QStringList &list )
void Document::pages( QVector<Okular::Page*> * pagesVector )
{
QStringList files( list );
qSort( files.begin(), files.end(), caseSensitiveNaturalOrderLessThen );
foreach(const QString &f, files) {
const QImageReader r(f);
qSort( mEntries.begin(), mEntries.end(), caseSensitiveNaturalOrderLessThen );
QScopedPointer< QIODevice > dev;
int count = 0;
pagesVector->clear();
pagesVector->resize( mEntries.size() );
QImageReader reader;
foreach(const QString &file, mEntries) {
if ( mArchive ) {
const KArchiveFile *entry = static_cast<const KArchiveFile*>( mArchiveDir->entry( file ) );
if ( entry ) {
dev.reset( entry->createDevice() );
}
} else if ( mDirectory ) {
dev.reset( mDirectory->createDevice( file ) );
} else {
dev.reset( mUnrar->createDevice( file ) );
}
if ( r.canRead() )
mPageMap.append(f);
if ( ! dev.isNull() ) {
reader.setDevice( dev.data() );
if ( reader.canRead() )
{
QSize pageSize = reader.size();
if ( !pageSize.isValid() ) {
pageSize = reader.read().size();
}
pagesVector->replace( count, new Okular::Page( count, pageSize.width(), pageSize.height(), Okular::Rotation0 ) );
mPageMap.append(file);
count++;
}
}
}
}
int Document::pages() const
{
return mPageMap.count();
pagesVector->resize( count );
}
QStringList Document::pageTitles() const
@ -195,36 +216,6 @@ QImage Document::pageImage( int page ) const
return QImage();
}
QSize Document::pageSize( int page ) const
{
std::auto_ptr< QIODevice > dev;
if ( mArchive ) {
const KArchiveFile *entry = static_cast<const KArchiveFile*>( mArchiveDir->entry( mPageMap[ page ] ) );
if ( entry ) {
dev.reset( entry->createDevice() );
}
} else if ( mDirectory ) {
dev.reset( mDirectory->createDevice( mPageMap[ page ] ) );
} else {
dev.reset( mUnrar->createDevice( mPageMap[ page ] ) );
}
if ( dev.get() ) {
QImageReader reader( dev.get() );
if ( reader.canRead() ) {
QSize s = reader.size();
if ( !s.isValid() ) {
s = reader.read().size();
}
return s;
}
}
return QSize();
}
QString Document::lastErrorString() const
{
return mLastErrorString;

@ -19,6 +19,10 @@ class QSize;
class Unrar;
class Directory;
namespace Okular {
class Page;
}
namespace ComicBook {
class Document
@ -30,16 +34,14 @@ class Document
bool open( const QString &fileName );
void close();
int pages() const;
void pages( QVector<Okular::Page*> * pagesVector );
QStringList pageTitles() const;
QImage pageImage( int page ) const;
QSize pageSize( int page ) const;
QString lastErrorString() const;
private:
void extractImageFiles( const QStringList& );
bool processArchive();
QStringList mPageMap;
@ -48,6 +50,7 @@ class Document
KArchive *mArchive;
KArchiveDirectory *mArchiveDir;
QString mLastErrorString;
QStringList mEntries;
};
}

@ -59,17 +59,7 @@ bool ComicBookGenerator::loadDocument( const QString & fileName, QVector<Okular:
return false;
}
int pages = mDocument.pages();
pagesVector.resize( pages );
QSize aux;
for ( int i = 0; i < pages; ++i ) {
aux = mDocument.pageSize( i );
Okular::Page * page = new Okular::Page( i, aux.width(), aux.height(), Okular::Rotation0 );
pagesVector[i] = page;
}
mDocument.pages( &pagesVector );
return true;
}

Loading…
Cancel
Save