mirror of
https://invent.kde.org/graphics/okular
synced 2024-08-27 11:40:07 +00:00
QImageReader is a bit dumb and does not know how to open jpeg files with .png extension so use kmimetype that is somehow smarter
svn path=/trunk/KDE/kdegraphics/okular/; revision=1209685
This commit is contained in:
parent
870fd3ba12
commit
0fdc76180d
|
@ -10,7 +10,7 @@ set(okularGenerator_kimgio_PART_SRCS generator_kimgio.cpp )
|
||||||
|
|
||||||
kde4_add_plugin(okularGenerator_kimgio ${okularGenerator_kimgio_PART_SRCS})
|
kde4_add_plugin(okularGenerator_kimgio ${okularGenerator_kimgio_PART_SRCS})
|
||||||
|
|
||||||
target_link_libraries(okularGenerator_kimgio okularcore ${KDE4_KDEUI_LIBS} ${QT_QTXML_LIBRARY} )
|
target_link_libraries(okularGenerator_kimgio okularcore ${KDE4_KDEUI_LIBS} ${KDE4_KIO_LIBS} ${QT_QTXML_LIBRARY} )
|
||||||
|
|
||||||
install(TARGETS okularGenerator_kimgio DESTINATION ${PLUGIN_INSTALL_DIR})
|
install(TARGETS okularGenerator_kimgio DESTINATION ${PLUGIN_INSTALL_DIR})
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include <kaction.h>
|
#include <kaction.h>
|
||||||
#include <kactioncollection.h>
|
#include <kactioncollection.h>
|
||||||
#include <kicon.h>
|
#include <kicon.h>
|
||||||
|
#include <kimageio.h>
|
||||||
#include <klocale.h>
|
#include <klocale.h>
|
||||||
|
|
||||||
#include <okular/core/page.h>
|
#include <okular/core/page.h>
|
||||||
|
@ -71,12 +72,15 @@ KIMGIOGenerator::~KIMGIOGenerator()
|
||||||
|
|
||||||
bool KIMGIOGenerator::loadDocument( const QString & fileName, QVector<Okular::Page*> & pagesVector )
|
bool KIMGIOGenerator::loadDocument( const QString & fileName, QVector<Okular::Page*> & pagesVector )
|
||||||
{
|
{
|
||||||
QImageReader reader( fileName );
|
const QString mime = KMimeType::findByFileContent(fileName)->name();
|
||||||
|
const QStringList types = KImageIO::typeForMime(mime);
|
||||||
|
const QByteArray type = !types.isEmpty() ? types[0].toAscii() : QByteArray();
|
||||||
|
QImageReader reader( fileName, type );
|
||||||
if ( !reader.read( &m_img ) ) {
|
if ( !reader.read( &m_img ) ) {
|
||||||
emit error( i18n( "Unable to load document: %1", reader.errorString() ), -1 );
|
emit error( i18n( "Unable to load document: %1", reader.errorString() ), -1 );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
docInfo.set( Okular::DocumentInfo::MimeType, KMimeType::findByPath(fileName)->name() );
|
docInfo.set( Okular::DocumentInfo::MimeType, mime );
|
||||||
|
|
||||||
pagesVector.resize( 1 );
|
pagesVector.resize( 1 );
|
||||||
|
|
||||||
|
@ -88,16 +92,20 @@ bool KIMGIOGenerator::loadDocument( const QString & fileName, QVector<Okular::Pa
|
||||||
|
|
||||||
bool KIMGIOGenerator::loadDocumentFromData( const QByteArray & fileData, QVector<Okular::Page*> & pagesVector )
|
bool KIMGIOGenerator::loadDocumentFromData( const QByteArray & fileData, QVector<Okular::Page*> & pagesVector )
|
||||||
{
|
{
|
||||||
|
const QString mime = KMimeType::findByContent(fileData)->name();
|
||||||
|
const QStringList types = KImageIO::typeForMime(mime);
|
||||||
|
const QByteArray type = !types.isEmpty() ? types[0].toAscii() : QByteArray();
|
||||||
|
|
||||||
QBuffer buffer;
|
QBuffer buffer;
|
||||||
buffer.setData( fileData );
|
buffer.setData( fileData );
|
||||||
buffer.open( QIODevice::ReadOnly );
|
buffer.open( QIODevice::ReadOnly );
|
||||||
|
|
||||||
QImageReader reader( &buffer );
|
QImageReader reader( &buffer, type );
|
||||||
if ( !reader.read( &m_img ) ) {
|
if ( !reader.read( &m_img ) ) {
|
||||||
emit error( i18n( "Unable to load document: %1", reader.errorString() ), -1 );
|
emit error( i18n( "Unable to load document: %1", reader.errorString() ), -1 );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
docInfo.set( Okular::DocumentInfo::MimeType, KMimeType::findByContent(fileData)->name() );
|
docInfo.set( Okular::DocumentInfo::MimeType, mime );
|
||||||
|
|
||||||
pagesVector.resize( 1 );
|
pagesVector.resize( 1 );
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue