mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-03 09:49:19 +02:00
book uids (in progress)
This commit is contained in:
parent
20491d9a12
commit
9eb54b261a
30 changed files with 205 additions and 16 deletions
|
@ -142,7 +142,8 @@ LOCAL_SRC_FILES := \
|
|||
NativeFormats/fbreader/src/library/Book.cpp \
|
||||
NativeFormats/fbreader/src/library/Comparators.cpp \
|
||||
NativeFormats/fbreader/src/library/Library.cpp \
|
||||
NativeFormats/fbreader/src/library/Tag.cpp
|
||||
NativeFormats/fbreader/src/library/Tag.cpp \
|
||||
NativeFormats/fbreader/src/library/UID.cpp
|
||||
|
||||
LOCAL_C_INCLUDES := \
|
||||
$(LOCAL_PATH)/NativeFormats/util \
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "fbreader/src/library/Author.h"
|
||||
#include "fbreader/src/library/Book.h"
|
||||
#include "fbreader/src/library/Tag.h"
|
||||
#include "fbreader/src/library/UID.h"
|
||||
|
||||
static shared_ptr<FormatPlugin> findCppPlugin(jobject base) {
|
||||
const std::string fileType = AndroidUtil::Method_NativeFormatPlugin_supportedFileType->callForCppString(base);
|
||||
|
@ -37,6 +38,17 @@ static shared_ptr<FormatPlugin> findCppPlugin(jobject base) {
|
|||
return plugin;
|
||||
}
|
||||
|
||||
static void fillUids(JNIEnv* env, jobject javaBook, Book &book) {
|
||||
const UIDList &uids = book.uids();
|
||||
for (UIDList::const_iterator it = uids.begin(); it != uids.end(); ++it) {
|
||||
jstring type = AndroidUtil::createJavaString(env, (*it)->Type);
|
||||
jstring id = AndroidUtil::createJavaString(env, (*it)->Id);
|
||||
AndroidUtil::Method_Book_addUid->call(javaBook, type, id);
|
||||
env->DeleteLocalRef(id);
|
||||
env->DeleteLocalRef(type);
|
||||
}
|
||||
}
|
||||
|
||||
static void fillMetaInfo(JNIEnv* env, jobject javaBook, Book &book) {
|
||||
jstring javaString;
|
||||
|
||||
|
@ -81,6 +93,8 @@ static void fillMetaInfo(JNIEnv* env, jobject javaBook, Book &book) {
|
|||
const Tag &tag = *tags[i];
|
||||
AndroidUtil::Method_Book_addTag->call(javaBook, tag.javaTag(env));
|
||||
}
|
||||
|
||||
fillUids(env, javaBook, book);
|
||||
}
|
||||
|
||||
static void fillLanguageAndEncoding(JNIEnv* env, jobject javaBook, Book &book) {
|
||||
|
@ -116,6 +130,19 @@ JNIEXPORT jboolean JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPl
|
|||
return JNI_TRUE;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlugin_readUidsNative(JNIEnv* env, jobject thiz, jobject javaBook) {
|
||||
shared_ptr<FormatPlugin> plugin = findCppPlugin(thiz);
|
||||
if (plugin.isNull()) {
|
||||
return;
|
||||
}
|
||||
|
||||
shared_ptr<Book> book = Book::loadFromJavaBook(env, javaBook);
|
||||
|
||||
plugin->readUids(*book);
|
||||
fillUids(env, javaBook, *book);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlugin_detectLanguageAndEncodingNative(JNIEnv* env, jobject thiz, jobject javaBook) {
|
||||
shared_ptr<FormatPlugin> plugin = findCppPlugin(thiz);
|
||||
|
|
|
@ -58,6 +58,7 @@ public:
|
|||
|
||||
virtual const std::string &tryOpen(const ZLFile &file) const;
|
||||
virtual bool readMetaInfo(Book &book) const = 0;
|
||||
virtual bool readUids(Book &book) const = 0;
|
||||
virtual bool readLanguageAndEncoding(Book &book) const = 0;
|
||||
virtual bool readModel(BookModel &model) const = 0;
|
||||
virtual shared_ptr<const ZLImage> coverImage(const ZLFile &file) const;
|
||||
|
|
|
@ -62,6 +62,10 @@ bool DocPlugin::readMetaInfo(Book &book) const {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool DocPlugin::readUids(Book&) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DocPlugin::readLanguageAndEncoding(Book &/*book*/) const {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ public:
|
|||
const std::string supportedFileType() const;
|
||||
bool acceptsFile(const ZLFile &file) const;
|
||||
bool readMetaInfo(Book &book) const;
|
||||
bool readUids(Book &book) const;
|
||||
bool readLanguageAndEncoding(Book &book) const;
|
||||
bool readModel(BookModel &model) const;
|
||||
};
|
||||
|
|
|
@ -30,6 +30,7 @@ public:
|
|||
bool providesMetaInfo() const;
|
||||
const std::string supportedFileType() const;
|
||||
bool readMetaInfo(Book &book) const;
|
||||
bool readUids(Book &book) const;
|
||||
bool readLanguageAndEncoding(Book &book) const;
|
||||
bool readModel(BookModel &model) const;
|
||||
shared_ptr<const ZLImage> coverImage(const ZLFile &file) const;
|
||||
|
|
|
@ -50,6 +50,10 @@ bool HtmlPlugin::readMetaInfo(Book &book) const {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool HtmlPlugin::readUids(Book&) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool HtmlPlugin::readModel(BookModel &model) const {
|
||||
const Book& book = *model.book();
|
||||
const ZLFile &file = book.file();
|
||||
|
|
|
@ -30,6 +30,7 @@ public:
|
|||
bool providesMetaInfo() const;
|
||||
const std::string supportedFileType() const;
|
||||
bool readMetaInfo(Book &book) const;
|
||||
bool readUids(Book &book) const;
|
||||
bool readLanguageAndEncoding(Book &book) const;
|
||||
bool readModel(BookModel &model) const;
|
||||
// FormatInfoPage *createInfoPage(ZLOptionsDialog &dialog, const ZLFile &file);
|
||||
|
|
|
@ -32,6 +32,7 @@ public:
|
|||
bool providesMetaInfo() const;
|
||||
const std::string supportedFileType() const;
|
||||
bool readMetaInfo(Book &book) const;
|
||||
bool readUids(Book &book) const;
|
||||
bool readLanguageAndEncoding(Book &book) const;
|
||||
bool readModel(BookModel &model) const;
|
||||
shared_ptr<const ZLImage> coverImage(const ZLFile &file) const;
|
||||
|
|
|
@ -54,6 +54,10 @@ bool RtfPlugin::readMetaInfo(Book &book) const {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool RtfPlugin::readUids(Book&) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RtfPlugin::readModel(BookModel &model) const {
|
||||
const Book &book = *model.book();
|
||||
return RtfBookReader(model, book.encoding()).readDocument(book.file());
|
||||
|
|
|
@ -28,6 +28,7 @@ public:
|
|||
bool providesMetaInfo() const;
|
||||
const std::string supportedFileType() const;
|
||||
bool readMetaInfo(Book &book) const;
|
||||
bool readUids(Book &book) const;
|
||||
bool readLanguageAndEncoding(Book &book) const;
|
||||
bool readModel(BookModel &model) const;
|
||||
};
|
||||
|
|
|
@ -38,10 +38,14 @@ const std::string TxtPlugin::supportedFileType() const {
|
|||
return "plain text";
|
||||
}
|
||||
|
||||
bool TxtPlugin::readMetaInfo(Book &book) const {
|
||||
bool TxtPlugin::readMetaInfo(Book&) const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TxtPlugin::readUids(Book&) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TxtPlugin::readModel(BookModel &model) const {
|
||||
Book &book = *model.book();
|
||||
const ZLFile &file = book.file();
|
||||
|
|
|
@ -29,6 +29,7 @@ public:
|
|||
bool providesMetaInfo() const;
|
||||
const std::string supportedFileType() const;
|
||||
bool readMetaInfo(Book &book) const;
|
||||
bool readUids(Book &book) const;
|
||||
bool readLanguageAndEncoding(Book &book) const;
|
||||
bool readModel(BookModel &model) const;
|
||||
// FormatInfoPage *createInfoPage(ZLOptionsDialog &dialog, const ZLFile &file);
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include "Book.h"
|
||||
#include "Author.h"
|
||||
#include "Tag.h"
|
||||
#include "UID.h"
|
||||
|
||||
#include "../formats/FormatPlugin.h"
|
||||
//#include "../migration/BookInfo.h"
|
||||
|
|
|
@ -30,9 +30,6 @@
|
|||
|
||||
#include "Lists.h"
|
||||
|
||||
class Author;
|
||||
class Tag;
|
||||
|
||||
class Book {
|
||||
|
||||
public:
|
||||
|
@ -70,6 +67,7 @@ public: // unmodifiable book methods
|
|||
|
||||
const TagList &tags() const;
|
||||
const AuthorList &authors() const;
|
||||
const UIDList &uids() const;
|
||||
|
||||
public: // modifiable book methods
|
||||
void setTitle(const std::string &title);
|
||||
|
@ -105,6 +103,7 @@ private:
|
|||
std::string myIndexInSeries;
|
||||
TagList myTags;
|
||||
AuthorList myAuthors;
|
||||
UIDList myUIDs;
|
||||
|
||||
private: // disable copying
|
||||
Book(const Book &);
|
||||
|
@ -138,6 +137,7 @@ inline const std::string &Book::indexInSeries() const { return myIndexInSeries;
|
|||
|
||||
inline const TagList &Book::tags() const { return myTags; }
|
||||
inline const AuthorList &Book::authors() const { return myAuthors; }
|
||||
inline const UIDList &Book::uids() const { return myUIDs; }
|
||||
|
||||
inline int Book::bookId() const { return myBookId; }
|
||||
inline void Book::setBookId(int bookId) { myBookId = bookId; }
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
class Book;
|
||||
class Author;
|
||||
class Tag;
|
||||
class UID;
|
||||
class BookByFileNameComparator;
|
||||
|
||||
typedef std::vector<shared_ptr<Book> > BookList;
|
||||
|
@ -35,5 +36,6 @@ typedef std::set<shared_ptr<Book>,BookByFileNameComparator> BookSet;
|
|||
typedef std::vector<shared_ptr<Author> > AuthorList;
|
||||
typedef std::vector<shared_ptr<Tag> > TagList;
|
||||
typedef std::set<shared_ptr<Tag> > TagSet;
|
||||
typedef std::vector<shared_ptr<UID> > UIDList;
|
||||
|
||||
#endif /* __LISTS_H__ */
|
||||
|
|
20
jni/NativeFormats/fbreader/src/library/UID.cpp
Normal file
20
jni/NativeFormats/fbreader/src/library/UID.cpp
Normal file
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* Copyright (C) 2009-2013 Geometer Plus <contact@geometerplus.com>
|
||||
*
|
||||
* 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 of the License, 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 "UID.h"
|
39
jni/NativeFormats/fbreader/src/library/UID.h
Normal file
39
jni/NativeFormats/fbreader/src/library/UID.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright (C) 2009-2013 Geometer Plus <contact@geometerplus.com>
|
||||
*
|
||||
* 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 of the License, 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 __UID_H__
|
||||
#define __UID_H__
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "Lists.h"
|
||||
|
||||
class UID {
|
||||
|
||||
public:
|
||||
UID(const std::string &type, const std::string &id);
|
||||
bool operator == (const UID &uid) const;
|
||||
bool operator != (const UID &uid) const;
|
||||
|
||||
public:
|
||||
const std::string Type;
|
||||
const std::string Id;
|
||||
};
|
||||
|
||||
#endif /* __UID_H__ */
|
|
@ -104,6 +104,7 @@ shared_ptr<VoidMethod> AndroidUtil::Method_Book_setLanguage;
|
|||
shared_ptr<VoidMethod> AndroidUtil::Method_Book_setEncoding;
|
||||
shared_ptr<VoidMethod> AndroidUtil::Method_Book_addAuthor;
|
||||
shared_ptr<VoidMethod> AndroidUtil::Method_Book_addTag;
|
||||
shared_ptr<VoidMethod> AndroidUtil::Method_Book_addUid;
|
||||
|
||||
shared_ptr<StaticObjectMethod> AndroidUtil::StaticMethod_Tag_getTag;
|
||||
|
||||
|
@ -179,6 +180,7 @@ bool AndroidUtil::init(JavaVM* jvm) {
|
|||
Method_Book_setEncoding = new VoidMethod(Class_Book, "setEncoding", "(Ljava/lang/String;)");
|
||||
Method_Book_addAuthor = new VoidMethod(Class_Book, "addAuthor", "(Ljava/lang/String;Ljava/lang/String;)");
|
||||
Method_Book_addTag = new VoidMethod(Class_Book, "addTag", "(Lorg/geometerplus/fbreader/book/Tag;)");
|
||||
Method_Book_addTag = new VoidMethod(Class_Book, "addUid", "(Ljava/lang/String;Ljava/lang/String;)");
|
||||
|
||||
StaticMethod_Tag_getTag = new StaticObjectMethod(Class_Tag, "getTag", Class_Tag, "(Lorg/geometerplus/fbreader/book/Tag;Ljava/lang/String;)");
|
||||
|
||||
|
|
|
@ -126,6 +126,7 @@ public:
|
|||
static shared_ptr<VoidMethod> Method_Book_setEncoding;
|
||||
static shared_ptr<VoidMethod> Method_Book_addAuthor;
|
||||
static shared_ptr<VoidMethod> Method_Book_addTag;
|
||||
static shared_ptr<VoidMethod> Method_Book_addUid;
|
||||
|
||||
static shared_ptr<StaticObjectMethod> StaticMethod_Tag_getTag;
|
||||
|
||||
|
|
|
@ -80,6 +80,7 @@
|
|||
public void setEncoding(**);
|
||||
public void addAuthor(**,**);
|
||||
public void addTag(**);
|
||||
public void addUid(**);
|
||||
}
|
||||
-keep class org.geometerplus.fbreader.book.Tag
|
||||
-keepclassmembers class org.geometerplus.fbreader.book.Tag {
|
||||
|
|
|
@ -77,7 +77,7 @@ final class SQLiteBooksDatabase extends BooksDatabase {
|
|||
|
||||
private void migrate() {
|
||||
final int version = myDatabase.getVersion();
|
||||
final int currentVersion = 21;
|
||||
final int currentVersion = 22;
|
||||
if (version >= currentVersion) {
|
||||
return;
|
||||
}
|
||||
|
@ -127,6 +127,8 @@ final class SQLiteBooksDatabase extends BooksDatabase {
|
|||
updateTables19();
|
||||
case 20:
|
||||
updateTables20();
|
||||
case 21:
|
||||
updateTables21();
|
||||
}
|
||||
myDatabase.setTransactionSuccessful();
|
||||
myDatabase.setVersion(currentVersion);
|
||||
|
@ -482,15 +484,15 @@ final class SQLiteBooksDatabase extends BooksDatabase {
|
|||
protected void saveBookUid(long bookId, UID uid) {
|
||||
if (myInsertBookUidStatement == null) {
|
||||
myInsertBookUidStatement = myDatabase.compileStatement(
|
||||
"INSERT OR REPLACE INTO BookUid (book_id,type,uid) VALUES (?,?,?)"
|
||||
"INSERT OR IGNORE INTO BookUid (book_id,type,uid) VALUES (?,?,?)"
|
||||
);
|
||||
}
|
||||
|
||||
synchronized (myInsertBookUidStatement) {
|
||||
myInsertBookUidStatement.bindLong(1, bookId);
|
||||
myInsertBookUidStatement.bindString(2, uid.Type);
|
||||
myInsertBookUidStatement.bindString(2, uid.Id);
|
||||
myInsertBookAuthorStatement.execute();
|
||||
myInsertBookUidStatement.bindString(3, uid.Id);
|
||||
myInsertBookUidStatement.execute();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1373,11 +1375,6 @@ final class SQLiteBooksDatabase extends BooksDatabase {
|
|||
}
|
||||
|
||||
private void updateTables20() {
|
||||
myDatabase.execSQL(
|
||||
"CREATE TABLE IF NOT EXISTS BookUid(" +
|
||||
"book_id INTEGER NOT NULL UNIQUE REFERENCES Books(book_id)," +
|
||||
"type TEXT NOT NULL," +
|
||||
"uid TEXT NOT NULL)");
|
||||
myDatabase.execSQL(
|
||||
"CREATE TABLE IF NOT EXISTS Labels(" +
|
||||
"label_id INTEGER PRIMARY KEY," +
|
||||
|
@ -1394,4 +1391,14 @@ final class SQLiteBooksDatabase extends BooksDatabase {
|
|||
myDatabase.execSQL("INSERT INTO BookLabel (label_id,book_id) SELECT " + id + ",book_id FROM Favorites");
|
||||
myDatabase.execSQL("DROP TABLE Favorites");
|
||||
}
|
||||
|
||||
private void updateTables21() {
|
||||
myDatabase.execSQL("DROP TABLE BookUid");
|
||||
myDatabase.execSQL(
|
||||
"CREATE TABLE IF NOT EXISTS BookUid(" +
|
||||
"book_id INTEGER NOT NULL UNIQUE REFERENCES Books(book_id)," +
|
||||
"type TEXT NOT NULL," +
|
||||
"uid TEXT NOT NULL," +
|
||||
"CONSTRAINT BookUid_Unique(book_id,type,uid))");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -115,10 +115,14 @@ public class Book extends TitledEntity {
|
|||
myAuthors = null;
|
||||
myTags = null;
|
||||
mySeriesInfo = null;
|
||||
myUids = null;
|
||||
|
||||
myIsSaved = false;
|
||||
|
||||
plugin.readMetaInfo(this);
|
||||
if (myUids == null || myUids.isEmpty()) {
|
||||
plugin.readUids(this);
|
||||
}
|
||||
|
||||
if (isTitleEmpty()) {
|
||||
final String fileName = File.getShortName();
|
||||
|
@ -139,6 +143,16 @@ public class Book extends TitledEntity {
|
|||
mySeriesInfo = database.getSeriesInfo(myId);
|
||||
myUids = database.listUids(myId);
|
||||
myIsSaved = true;
|
||||
if (myUids == null || myUids.isEmpty()) {
|
||||
try {
|
||||
final FormatPlugin plugin = getPlugin();
|
||||
if (plugin != null) {
|
||||
plugin.readUids(this);
|
||||
save(database, false);
|
||||
}
|
||||
} catch (BookReadingException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<Author> authors() {
|
||||
|
@ -310,6 +324,24 @@ public class Book extends TitledEntity {
|
|||
addTag(Tag.getTag(null, tagName));
|
||||
}
|
||||
|
||||
public List<UID> uids() {
|
||||
return myUids != null ? Collections.unmodifiableList(myUids) : Collections.<UID>emptyList();
|
||||
}
|
||||
|
||||
public void addUid(String type, String id) {
|
||||
addUid(new UID(type, id));
|
||||
}
|
||||
|
||||
public void addUid(UID uid) {
|
||||
if (myUids == null) {
|
||||
myUids = new ArrayList<UID>();
|
||||
}
|
||||
if (!myUids.contains(uid)) {
|
||||
myUids.add(uid);
|
||||
myIsSaved = false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean matchesUid(UID uid) {
|
||||
return myUids.contains(uid);
|
||||
}
|
||||
|
@ -370,6 +402,10 @@ public class Book extends TitledEntity {
|
|||
database.saveBookTagInfo(myId, tag);
|
||||
}
|
||||
database.saveBookSeriesInfo(myId, mySeriesInfo);
|
||||
database.deleteAllBookUids(myId);
|
||||
for (UID uid : uids()) {
|
||||
database.saveBookUid(myId, uid);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -99,7 +99,7 @@ public abstract class BookUtil {
|
|||
for (byte b : hash.digest()) {
|
||||
f.format("%02X", b & 0xFF);
|
||||
}
|
||||
return new UID("SHA256", f.toString());
|
||||
return new UID("SHA-256", f.toString());
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
|
|
|
@ -31,7 +31,7 @@ public abstract class BooksDatabase {
|
|||
return createBook(id, infos.getFile(fileId), title, encoding, language);
|
||||
}
|
||||
protected Book createBook(long id, ZLFile file, String title, String encoding, String language) {
|
||||
return (file != null) ? new Book(id, file, title, encoding, language) : null;
|
||||
return file != null ? new Book(id, file, title, encoding, language) : null;
|
||||
}
|
||||
protected void addAuthor(Book book, Author author) {
|
||||
book.addAuthorWithNoCheck(author);
|
||||
|
|
|
@ -42,6 +42,7 @@ public abstract class FormatPlugin {
|
|||
return file;
|
||||
}
|
||||
public abstract void readMetaInfo(Book book) throws BookReadingException;
|
||||
public abstract void readUids(Book book) throws BookReadingException;
|
||||
public abstract void readModel(BookModel model) throws BookReadingException;
|
||||
public abstract void detectLanguageAndEncoding(Book book) throws BookReadingException;
|
||||
public abstract ZLImage readCover(ZLFile file);
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.geometerplus.zlibrary.core.image.*;
|
|||
import org.geometerplus.zlibrary.core.util.MimeType;
|
||||
|
||||
import org.geometerplus.fbreader.book.Book;
|
||||
import org.geometerplus.fbreader.book.BookUtil;
|
||||
import org.geometerplus.fbreader.bookmodel.BookModel;
|
||||
import org.geometerplus.fbreader.bookmodel.BookReadingException;
|
||||
import org.geometerplus.fbreader.formats.fb2.FB2NativePlugin;
|
||||
|
@ -55,6 +56,15 @@ public class NativeFormatPlugin extends FormatPlugin {
|
|||
|
||||
private native boolean readMetaInfoNative(Book book);
|
||||
|
||||
synchronized public void readUids(Book book) throws BookReadingException {
|
||||
readUidsNative(book);
|
||||
if (book.uids().isEmpty()) {
|
||||
book.addUid(BookUtil.createSHA256Uid(book.File));
|
||||
}
|
||||
}
|
||||
|
||||
private native boolean readUidsNative(Book book);
|
||||
|
||||
@Override
|
||||
public void detectLanguageAndEncoding(Book book) {
|
||||
detectLanguageAndEncodingNative(book);
|
||||
|
|
|
@ -47,6 +47,11 @@ public class FB2Plugin extends JavaFormatPlugin {
|
|||
new FB2MetaInfoReader(book).readMetaInfo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readUids(Book book) throws BookReadingException {
|
||||
// this method does nothing, we expect it will be never called
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readModel(BookModel model) throws BookReadingException {
|
||||
new FB2Reader(model).readBook();
|
||||
|
|
|
@ -61,6 +61,11 @@ public class OEBPlugin extends JavaFormatPlugin {
|
|||
new OEBMetaInfoReader(book).readMetaInfo(getOpfFile(book.File));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readUids(Book book) throws BookReadingException {
|
||||
// this method does nothing, we expect it will be never called
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readModel(BookModel model) throws BookReadingException {
|
||||
model.Book.File.setCached(true);
|
||||
|
|
|
@ -29,6 +29,7 @@ import org.geometerplus.zlibrary.core.language.ZLLanguageUtil;
|
|||
import org.geometerplus.zlibrary.core.util.MimeType;
|
||||
|
||||
import org.geometerplus.fbreader.book.Book;
|
||||
import org.geometerplus.fbreader.book.BookUtil;
|
||||
import org.geometerplus.fbreader.bookmodel.BookModel;
|
||||
import org.geometerplus.fbreader.bookmodel.BookReadingException;
|
||||
import org.geometerplus.fbreader.formats.JavaFormatPlugin;
|
||||
|
@ -122,6 +123,13 @@ public class MobipocketPlugin extends JavaFormatPlugin {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readUids(Book book) throws BookReadingException {
|
||||
if (book.uids().isEmpty()) {
|
||||
book.addUid(BookUtil.createSHA256Uid(book.File));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readModel(BookModel model) throws BookReadingException {
|
||||
try {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue