1 /***************************************************************************
2 * Copyright (C) 2007 by Tobias Koenig <tokoe@kde.org> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 ***************************************************************************/
12 #include <QtCore/QFile>
17 using namespace FictionBook;
19 Document::Document( const QString &fileName )
20 : mFileName( fileName )
26 if ( mFileName.endsWith( ".fb" ) || mFileName.endsWith( ".fb2" ) ) {
27 QFile file( mFileName );
28 if ( !file.open( QIODevice::ReadOnly ) ) {
29 setError( i18n( "Unable to open document: %1", file.errorString() ) );
34 if ( !mDocument.setContent( &file, true, &errorMsg ) ) {
35 setError( i18n( "Invalid XML document: %1", errorMsg ) );
41 KArchive zip( mFileName );
42 if ( !zip.isReadable() ) {
43 setError( i18n( "Document is not a valid ZIP archive" ) );
47 const QList<KArchiveEntry> entries = zip.list();
50 for ( int i = 0; i < entries.count(); ++i ) {
51 if ( entries[ i ].pathname.endsWith( ".fb2" ) ) {
52 documentFile = QFile::decodeName(entries[ i ].pathname);
57 if ( documentFile.isEmpty() ) {
58 setError( i18n( "No content found in the document" ) );
63 if ( !mDocument.setContent( zip.data( documentFile ), true, &errorMsg ) ) {
64 setError( i18n( "Invalid XML document: %1", errorMsg ) );
70 QDomDocument Document::content() const
75 QString Document::lastErrorString() const
80 void Document::setError( const QString &error )