mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 10:19:33 +02:00
SystemInfo in plugins
This commit is contained in:
parent
8121d5c6f8
commit
cf13daad1c
46 changed files with 210 additions and 157 deletions
|
@ -25,7 +25,7 @@
|
||||||
#include "fbreader/src/formats/FormatPlugin.h"
|
#include "fbreader/src/formats/FormatPlugin.h"
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
JNIEXPORT jobjectArray JNICALL Java_org_geometerplus_fbreader_formats_PluginCollection_nativePlugins(JNIEnv* env, jobject thiz) {
|
JNIEXPORT jobjectArray JNICALL Java_org_geometerplus_fbreader_formats_PluginCollection_nativePlugins(JNIEnv* env, jobject thiz, jobject systemInfo) {
|
||||||
const std::vector<shared_ptr<FormatPlugin> > plugins = PluginCollection::Instance().plugins();
|
const std::vector<shared_ptr<FormatPlugin> > plugins = PluginCollection::Instance().plugins();
|
||||||
const std::size_t size = plugins.size();
|
const std::size_t size = plugins.size();
|
||||||
jclass cls = AndroidUtil::Class_NativeFormatPlugin.j();
|
jclass cls = AndroidUtil::Class_NativeFormatPlugin.j();
|
||||||
|
@ -34,7 +34,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_geometerplus_fbreader_formats_PluginColl
|
||||||
|
|
||||||
for (std::size_t i = 0; i < size; ++i) {
|
for (std::size_t i = 0; i < size; ++i) {
|
||||||
jstring fileType = AndroidUtil::createJavaString(env, plugins[i]->supportedFileType());
|
jstring fileType = AndroidUtil::createJavaString(env, plugins[i]->supportedFileType());
|
||||||
jobject p = AndroidUtil::StaticMethod_NativeFormatPlugin_create->call(fileType);
|
jobject p = AndroidUtil::StaticMethod_NativeFormatPlugin_create->call(systemInfo, fileType);
|
||||||
env->SetObjectArrayElement(javaPlugins, i, p);
|
env->SetObjectArrayElement(javaPlugins, i, p);
|
||||||
env->DeleteLocalRef(p);
|
env->DeleteLocalRef(p);
|
||||||
env->DeleteLocalRef(fileType);
|
env->DeleteLocalRef(fileType);
|
||||||
|
|
|
@ -92,7 +92,7 @@ public:
|
||||||
private:
|
private:
|
||||||
static PluginCollection *ourInstance;
|
static PluginCollection *ourInstance;
|
||||||
|
|
||||||
jobject myJavaInstance;
|
//jobject myJavaInstance;
|
||||||
|
|
||||||
std::vector<shared_ptr<FormatPlugin> > myPlugins;
|
std::vector<shared_ptr<FormatPlugin> > myPlugins;
|
||||||
};
|
};
|
||||||
|
|
|
@ -69,15 +69,15 @@ void PluginCollection::deleteInstance() {
|
||||||
}
|
}
|
||||||
|
|
||||||
PluginCollection::PluginCollection() {
|
PluginCollection::PluginCollection() {
|
||||||
JNIEnv *env = AndroidUtil::getEnv();
|
//JNIEnv *env = AndroidUtil::getEnv();
|
||||||
jobject instance = AndroidUtil::StaticMethod_PluginCollection_Instance->call();
|
//jobject instance = AndroidUtil::StaticMethod_PluginCollection_Instance->call();
|
||||||
myJavaInstance = env->NewGlobalRef(instance);
|
//myJavaInstance = env->NewGlobalRef(instance);
|
||||||
env->DeleteLocalRef(instance);
|
//env->DeleteLocalRef(instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
PluginCollection::~PluginCollection() {
|
PluginCollection::~PluginCollection() {
|
||||||
JNIEnv *env = AndroidUtil::getEnv();
|
//JNIEnv *env = AndroidUtil::getEnv();
|
||||||
env->DeleteGlobalRef(myJavaInstance);
|
//env->DeleteGlobalRef(myJavaInstance);
|
||||||
}
|
}
|
||||||
|
|
||||||
shared_ptr<FormatPlugin> PluginCollection::pluginByType(const std::string &fileType) const {
|
shared_ptr<FormatPlugin> PluginCollection::pluginByType(const std::string &fileType) const {
|
||||||
|
|
|
@ -75,7 +75,7 @@ shared_ptr<StringMethod> AndroidUtil::Method_ZLibrary_getVersionName;
|
||||||
shared_ptr<StaticObjectMethod> AndroidUtil::StaticMethod_NativeFormatPlugin_create;
|
shared_ptr<StaticObjectMethod> AndroidUtil::StaticMethod_NativeFormatPlugin_create;
|
||||||
shared_ptr<StringMethod> AndroidUtil::Method_NativeFormatPlugin_supportedFileType;
|
shared_ptr<StringMethod> AndroidUtil::Method_NativeFormatPlugin_supportedFileType;
|
||||||
|
|
||||||
shared_ptr<StaticObjectMethod> AndroidUtil::StaticMethod_PluginCollection_Instance;
|
//shared_ptr<StaticObjectMethod> AndroidUtil::StaticMethod_PluginCollection_Instance;
|
||||||
|
|
||||||
shared_ptr<ObjectMethod> AndroidUtil::Method_Encoding_createConverter;
|
shared_ptr<ObjectMethod> AndroidUtil::Method_Encoding_createConverter;
|
||||||
|
|
||||||
|
@ -154,10 +154,10 @@ bool AndroidUtil::init(JavaVM* jvm) {
|
||||||
StaticMethod_ZLibrary_Instance = new StaticObjectMethod(Class_ZLibrary, "Instance", Class_ZLibrary, "()");
|
StaticMethod_ZLibrary_Instance = new StaticObjectMethod(Class_ZLibrary, "Instance", Class_ZLibrary, "()");
|
||||||
Method_ZLibrary_getVersionName = new StringMethod(Class_ZLibrary, "getVersionName", "()");
|
Method_ZLibrary_getVersionName = new StringMethod(Class_ZLibrary, "getVersionName", "()");
|
||||||
|
|
||||||
StaticMethod_NativeFormatPlugin_create = new StaticObjectMethod(Class_NativeFormatPlugin, "create", Class_NativeFormatPlugin, "(Ljava/lang/String;)");
|
StaticMethod_NativeFormatPlugin_create = new StaticObjectMethod(Class_NativeFormatPlugin, "create", Class_NativeFormatPlugin, "(Lorg/geometerplus/zlibrary/core/util/SystemInfo;Ljava/lang/String;)");
|
||||||
Method_NativeFormatPlugin_supportedFileType = new StringMethod(Class_NativeFormatPlugin, "supportedFileType", "()");
|
Method_NativeFormatPlugin_supportedFileType = new StringMethod(Class_NativeFormatPlugin, "supportedFileType", "()");
|
||||||
|
|
||||||
StaticMethod_PluginCollection_Instance = new StaticObjectMethod(Class_PluginCollection, "Instance", Class_PluginCollection, "()");
|
//StaticMethod_PluginCollection_Instance = new StaticObjectMethod(Class_PluginCollection, "Instance", Class_PluginCollection, "()");
|
||||||
|
|
||||||
Method_Encoding_createConverter = new ObjectMethod(Class_Encoding, "createConverter", Class_EncodingConverter, "()");
|
Method_Encoding_createConverter = new ObjectMethod(Class_Encoding, "createConverter", Class_EncodingConverter, "()");
|
||||||
Field_EncodingConverter_Name = new ObjectField(Class_EncodingConverter, "Name", Class_java_lang_String);
|
Field_EncodingConverter_Name = new ObjectField(Class_EncodingConverter, "Name", Class_java_lang_String);
|
||||||
|
|
|
@ -127,7 +127,7 @@ public:
|
||||||
static shared_ptr<StaticObjectMethod> StaticMethod_NativeFormatPlugin_create;
|
static shared_ptr<StaticObjectMethod> StaticMethod_NativeFormatPlugin_create;
|
||||||
static shared_ptr<StringMethod> Method_NativeFormatPlugin_supportedFileType;
|
static shared_ptr<StringMethod> Method_NativeFormatPlugin_supportedFileType;
|
||||||
|
|
||||||
static shared_ptr<StaticObjectMethod> StaticMethod_PluginCollection_Instance;
|
//static shared_ptr<StaticObjectMethod> StaticMethod_PluginCollection_Instance;
|
||||||
|
|
||||||
static shared_ptr<ObjectMethod> Method_Encoding_createConverter;
|
static shared_ptr<ObjectMethod> Method_Encoding_createConverter;
|
||||||
|
|
||||||
|
|
|
@ -56,6 +56,7 @@ import org.geometerplus.fbreader.bookmodel.BookModel;
|
||||||
import org.geometerplus.fbreader.fbreader.*;
|
import org.geometerplus.fbreader.fbreader.*;
|
||||||
import org.geometerplus.fbreader.fbreader.options.CancelMenuHelper;
|
import org.geometerplus.fbreader.fbreader.options.CancelMenuHelper;
|
||||||
import org.geometerplus.fbreader.formats.ExternalFormatPlugin;
|
import org.geometerplus.fbreader.formats.ExternalFormatPlugin;
|
||||||
|
import org.geometerplus.fbreader.formats.PluginCollection;
|
||||||
import org.geometerplus.fbreader.tips.TipsManager;
|
import org.geometerplus.fbreader.tips.TipsManager;
|
||||||
|
|
||||||
import org.geometerplus.android.fbreader.api.*;
|
import org.geometerplus.android.fbreader.api.*;
|
||||||
|
@ -350,7 +351,10 @@ public final class FBReader extends FBReaderMainActivity implements ZLApplicatio
|
||||||
if (!collection.sameBook(b, myFBReaderApp.ExternalBook)) {
|
if (!collection.sameBook(b, myFBReaderApp.ExternalBook)) {
|
||||||
try {
|
try {
|
||||||
final ExternalFormatPlugin plugin =
|
final ExternalFormatPlugin plugin =
|
||||||
(ExternalFormatPlugin)BookUtil.getPlugin(myFBReaderApp.ExternalBook);
|
(ExternalFormatPlugin)BookUtil.getPlugin(
|
||||||
|
PluginCollection.Instance(Paths.systemInfo(this)),
|
||||||
|
myFBReaderApp.ExternalBook
|
||||||
|
);
|
||||||
startActivity(PluginUtil.createIntent(plugin, FBReaderIntents.Action.PLUGIN_KILL));
|
startActivity(PluginUtil.createIntent(plugin, FBReaderIntents.Action.PLUGIN_KILL));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
|
@ -33,6 +33,7 @@ import org.geometerplus.zlibrary.core.util.MimeType;
|
||||||
import org.geometerplus.zlibrary.core.util.SliceInputStream;
|
import org.geometerplus.zlibrary.core.util.SliceInputStream;
|
||||||
import org.geometerplus.zlibrary.ui.android.image.ZLBitmapImage;
|
import org.geometerplus.zlibrary.ui.android.image.ZLBitmapImage;
|
||||||
|
|
||||||
|
import org.geometerplus.fbreader.Paths;
|
||||||
import org.geometerplus.fbreader.book.CoverUtil;
|
import org.geometerplus.fbreader.book.CoverUtil;
|
||||||
import org.geometerplus.fbreader.formats.PluginCollection;
|
import org.geometerplus.fbreader.formats.PluginCollection;
|
||||||
import org.geometerplus.fbreader.formats.PluginImage;
|
import org.geometerplus.fbreader.formats.PluginImage;
|
||||||
|
@ -60,7 +61,7 @@ public class DataServer extends NanoHTTPD {
|
||||||
try {
|
try {
|
||||||
final ZLImage image = CoverUtil.getCover(
|
final ZLImage image = CoverUtil.getCover(
|
||||||
DataUtil.fileFromEncodedPath(uri.substring(7)),
|
DataUtil.fileFromEncodedPath(uri.substring(7)),
|
||||||
PluginCollection.Instance()
|
PluginCollection.Instance(Paths.systemInfo(myService))
|
||||||
);
|
);
|
||||||
if (image instanceof ZLFileImageProxy) {
|
if (image instanceof ZLFileImageProxy) {
|
||||||
final ZLFileImageProxy proxy = (ZLFileImageProxy)image;
|
final ZLFileImageProxy proxy = (ZLFileImageProxy)image;
|
||||||
|
|
|
@ -93,13 +93,16 @@ public class BookInfoActivity extends Activity implements IBookCollection.Listen
|
||||||
|
|
||||||
OrientationUtil.setOrientation(this, getIntent());
|
OrientationUtil.setOrientation(this, getIntent());
|
||||||
|
|
||||||
|
final PluginCollection pluginCollection =
|
||||||
|
PluginCollection.Instance(Paths.systemInfo(this));
|
||||||
|
|
||||||
if (myBook != null) {
|
if (myBook != null) {
|
||||||
// we force language & encoding detection
|
// we force language & encoding detection
|
||||||
BookUtil.getEncoding(myBook);
|
BookUtil.getEncoding(myBook, pluginCollection);
|
||||||
|
|
||||||
setupCover(myBook);
|
setupCover(myBook);
|
||||||
setupBookInfo(myBook);
|
setupBookInfo(myBook);
|
||||||
setupAnnotation(myBook);
|
setupAnnotation(myBook, pluginCollection);
|
||||||
setupFileInfo(myBook);
|
setupFileInfo(myBook);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,7 +126,7 @@ public class BookInfoActivity extends Activity implements IBookCollection.Listen
|
||||||
setupButton(R.id.book_info_button_reload, "reloadInfo", new View.OnClickListener() {
|
setupButton(R.id.book_info_button_reload, "reloadInfo", new View.OnClickListener() {
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
if (myBook != null) {
|
if (myBook != null) {
|
||||||
BookUtil.reloadInfoFromFile(myBook);
|
BookUtil.reloadInfoFromFile(myBook, pluginCollection);
|
||||||
setupBookInfo(myBook);
|
setupBookInfo(myBook);
|
||||||
myDontReloadBook = false;
|
myDontReloadBook = false;
|
||||||
myCollection.bindToService(BookInfoActivity.this, new Runnable() {
|
myCollection.bindToService(BookInfoActivity.this, new Runnable() {
|
||||||
|
@ -189,7 +192,7 @@ public class BookInfoActivity extends Activity implements IBookCollection.Listen
|
||||||
coverView.setVisibility(View.GONE);
|
coverView.setVisibility(View.GONE);
|
||||||
coverView.setImageDrawable(null);
|
coverView.setImageDrawable(null);
|
||||||
|
|
||||||
final ZLImage image = CoverUtil.getCover(book, PluginCollection.Instance());
|
final ZLImage image = CoverUtil.getCover(book, PluginCollection.Instance(Paths.systemInfo(this)));
|
||||||
|
|
||||||
if (image == null) {
|
if (image == null) {
|
||||||
return;
|
return;
|
||||||
|
@ -276,10 +279,10 @@ public class BookInfoActivity extends Activity implements IBookCollection.Listen
|
||||||
setupInfoPair(R.id.book_language, "language", new Language(language).Name);
|
setupInfoPair(R.id.book_language, "language", new Language(language).Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupAnnotation(Book book) {
|
private void setupAnnotation(Book book, PluginCollection pluginCollection) {
|
||||||
final TextView titleView = (TextView)findViewById(R.id.book_info_annotation_title);
|
final TextView titleView = (TextView)findViewById(R.id.book_info_annotation_title);
|
||||||
final TextView bodyView = (TextView)findViewById(R.id.book_info_annotation_body);
|
final TextView bodyView = (TextView)findViewById(R.id.book_info_annotation_body);
|
||||||
final String annotation = BookUtil.getAnnotation(book);
|
final String annotation = BookUtil.getAnnotation(book, pluginCollection);
|
||||||
if (annotation == null) {
|
if (annotation == null) {
|
||||||
titleView.setVisibility(View.GONE);
|
titleView.setVisibility(View.GONE);
|
||||||
bodyView.setVisibility(View.GONE);
|
bodyView.setVisibility(View.GONE);
|
||||||
|
|
|
@ -35,7 +35,9 @@ import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.ui.android.R;
|
import org.geometerplus.zlibrary.ui.android.R;
|
||||||
|
|
||||||
|
import org.geometerplus.fbreader.Paths;
|
||||||
import org.geometerplus.fbreader.book.*;
|
import org.geometerplus.fbreader.book.*;
|
||||||
|
import org.geometerplus.fbreader.formats.PluginCollection;
|
||||||
import org.geometerplus.fbreader.library.*;
|
import org.geometerplus.fbreader.library.*;
|
||||||
import org.geometerplus.fbreader.tree.FBTree;
|
import org.geometerplus.fbreader.tree.FBTree;
|
||||||
|
|
||||||
|
@ -68,7 +70,7 @@ public class LibraryActivity extends TreeActivity<LibraryTree> implements MenuIt
|
||||||
myCollection.bindToService(this, new Runnable() {
|
myCollection.bindToService(this, new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
setProgressBarIndeterminateVisibility(!myCollection.status().IsComplete);
|
setProgressBarIndeterminateVisibility(!myCollection.status().IsComplete);
|
||||||
myRootTree = new RootTree(myCollection);
|
myRootTree = new RootTree(myCollection, PluginCollection.Instance(Paths.systemInfo(LibraryActivity.this)));
|
||||||
myCollection.addListener(LibraryActivity.this);
|
myCollection.addListener(LibraryActivity.this);
|
||||||
init(getIntent());
|
init(getIntent());
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,7 +100,9 @@ public class LibraryService extends Service {
|
||||||
|
|
||||||
LibraryImplementation(BooksDatabase db) {
|
LibraryImplementation(BooksDatabase db) {
|
||||||
myDatabase = db;
|
myDatabase = db;
|
||||||
myCollection = new BookCollection(myDatabase, Paths.bookPath());
|
myCollection = new BookCollection(
|
||||||
|
Paths.systemInfo(LibraryService.this), myDatabase, Paths.bookPath()
|
||||||
|
);
|
||||||
reset(true);
|
reset(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,7 +126,9 @@ public class LibraryService extends Service {
|
||||||
deactivate();
|
deactivate();
|
||||||
myFileObservers.clear();
|
myFileObservers.clear();
|
||||||
|
|
||||||
myCollection = new BookCollection(myDatabase, bookDirectories);
|
myCollection = new BookCollection(
|
||||||
|
Paths.systemInfo(LibraryService.this), myDatabase, bookDirectories
|
||||||
|
);
|
||||||
for (String dir : bookDirectories) {
|
for (String dir : bookDirectories) {
|
||||||
final Observer observer = new Observer(dir, myCollection);
|
final Observer observer = new Observer(dir, myCollection);
|
||||||
observer.startWatching();
|
observer.startWatching();
|
||||||
|
@ -293,7 +297,7 @@ public class LibraryService extends Service {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDescription(String book) {
|
public String getDescription(String book) {
|
||||||
return BookUtil.getAnnotation(SerializerUtil.deserializeBook(book, myCollection));
|
return BookUtil.getAnnotation(SerializerUtil.deserializeBook(book, myCollection), myCollection.PluginCollection);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -31,9 +31,9 @@ import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.text.hyphenation.ZLTextHyphenator;
|
import org.geometerplus.zlibrary.text.hyphenation.ZLTextHyphenator;
|
||||||
|
|
||||||
|
import org.geometerplus.fbreader.Paths;
|
||||||
import org.geometerplus.fbreader.book.*;
|
import org.geometerplus.fbreader.book.*;
|
||||||
import org.geometerplus.fbreader.formats.BookReadingException;
|
import org.geometerplus.fbreader.formats.*;
|
||||||
import org.geometerplus.fbreader.formats.FormatPlugin;
|
|
||||||
|
|
||||||
import org.geometerplus.android.fbreader.api.FBReaderIntents;
|
import org.geometerplus.android.fbreader.api.FBReaderIntents;
|
||||||
import org.geometerplus.android.fbreader.libraryService.BookCollectionShadow;
|
import org.geometerplus.android.fbreader.libraryService.BookCollectionShadow;
|
||||||
|
@ -89,15 +89,17 @@ class BookLanguagePreference extends LanguagePreference {
|
||||||
}
|
}
|
||||||
|
|
||||||
class EncodingPreference extends ZLStringListPreference {
|
class EncodingPreference extends ZLStringListPreference {
|
||||||
|
private final PluginCollection myPluginCollection;
|
||||||
private final Book myBook;
|
private final Book myBook;
|
||||||
|
|
||||||
EncodingPreference(Context context, ZLResource resource, Book book) {
|
EncodingPreference(Context context, ZLResource resource, Book book) {
|
||||||
super(context, resource);
|
super(context, resource);
|
||||||
myBook = book;
|
myBook = book;
|
||||||
|
myPluginCollection = PluginCollection.Instance(Paths.systemInfo(context));
|
||||||
|
|
||||||
final FormatPlugin plugin;
|
final FormatPlugin plugin;
|
||||||
try {
|
try {
|
||||||
plugin = BookUtil.getPlugin(book);
|
plugin = BookUtil.getPlugin(myPluginCollection, book);
|
||||||
} catch (BookReadingException e) {
|
} catch (BookReadingException e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -123,7 +125,7 @@ class EncodingPreference extends ZLStringListPreference {
|
||||||
setInitialValue(codes[0]);
|
setInitialValue(codes[0]);
|
||||||
setEnabled(false);
|
setEnabled(false);
|
||||||
} else {
|
} else {
|
||||||
final String bookEncoding = BookUtil.getEncoding(book);
|
final String bookEncoding = BookUtil.getEncoding(book, myPluginCollection);
|
||||||
if (bookEncoding != null) {
|
if (bookEncoding != null) {
|
||||||
setInitialValue(bookEncoding.toLowerCase());
|
setInitialValue(bookEncoding.toLowerCase());
|
||||||
}
|
}
|
||||||
|
@ -135,7 +137,7 @@ class EncodingPreference extends ZLStringListPreference {
|
||||||
super.onDialogClosed(result);
|
super.onDialogClosed(result);
|
||||||
if (result) {
|
if (result) {
|
||||||
final String value = getValue();
|
final String value = getValue();
|
||||||
if (!value.equalsIgnoreCase(BookUtil.getEncoding(myBook))) {
|
if (!value.equalsIgnoreCase(BookUtil.getEncoding(myBook, myPluginCollection))) {
|
||||||
myBook.setEncoding(value);
|
myBook.setEncoding(value);
|
||||||
((EditBookInfoActivity)getContext()).saveBook();
|
((EditBookInfoActivity)getContext()).saveBook();
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ import java.util.*;
|
||||||
import org.geometerplus.zlibrary.core.filesystem.*;
|
import org.geometerplus.zlibrary.core.filesystem.*;
|
||||||
import org.geometerplus.zlibrary.core.image.ZLImage;
|
import org.geometerplus.zlibrary.core.image.ZLImage;
|
||||||
import org.geometerplus.zlibrary.core.util.MiscUtil;
|
import org.geometerplus.zlibrary.core.util.MiscUtil;
|
||||||
|
import org.geometerplus.zlibrary.core.util.SystemInfo;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.text.view.ZLTextFixedPosition;
|
import org.geometerplus.zlibrary.text.view.ZLTextFixedPosition;
|
||||||
import org.geometerplus.zlibrary.text.view.ZLTextPosition;
|
import org.geometerplus.zlibrary.text.view.ZLTextPosition;
|
||||||
|
@ -34,6 +35,8 @@ import org.geometerplus.fbreader.formats.*;
|
||||||
public class BookCollection extends AbstractBookCollection<DbBook> {
|
public class BookCollection extends AbstractBookCollection<DbBook> {
|
||||||
private static final String ZERO_HASH = String.format("%040d", 0);
|
private static final String ZERO_HASH = String.format("%040d", 0);
|
||||||
|
|
||||||
|
private final SystemInfo mySystemInfo;
|
||||||
|
public final PluginCollection PluginCollection;
|
||||||
private final BooksDatabase myDatabase;
|
private final BooksDatabase myDatabase;
|
||||||
public final List<String> BookDirectories;
|
public final List<String> BookDirectories;
|
||||||
private Set<String> myActiveFormats;
|
private Set<String> myActiveFormats;
|
||||||
|
@ -51,7 +54,9 @@ public class BookCollection extends AbstractBookCollection<DbBook> {
|
||||||
private final Map<Integer,HighlightingStyle> myStyles =
|
private final Map<Integer,HighlightingStyle> myStyles =
|
||||||
Collections.synchronizedMap(new TreeMap<Integer,HighlightingStyle>());
|
Collections.synchronizedMap(new TreeMap<Integer,HighlightingStyle>());
|
||||||
|
|
||||||
public BookCollection(BooksDatabase db, List<String> bookDirectories) {
|
public BookCollection(SystemInfo systemInfo, BooksDatabase db, List<String> bookDirectories) {
|
||||||
|
mySystemInfo = systemInfo;
|
||||||
|
PluginCollection = org.geometerplus.fbreader.formats.PluginCollection.Instance(systemInfo);
|
||||||
myDatabase = db;
|
myDatabase = db;
|
||||||
BookDirectories = Collections.unmodifiableList(new ArrayList<String>(bookDirectories));
|
BookDirectories = Collections.unmodifiableList(new ArrayList<String>(bookDirectories));
|
||||||
|
|
||||||
|
@ -74,7 +79,7 @@ public class BookCollection extends AbstractBookCollection<DbBook> {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return getBookByFile(bookFile, PluginCollection.Instance().getPlugin(bookFile));
|
return getBookByFile(bookFile, PluginCollection.getPlugin(bookFile));
|
||||||
}
|
}
|
||||||
|
|
||||||
private DbBook getBookByFile(ZLFile bookFile, final FormatPlugin plugin) {
|
private DbBook getBookByFile(ZLFile bookFile, final FormatPlugin plugin) {
|
||||||
|
@ -110,7 +115,7 @@ public class BookCollection extends AbstractBookCollection<DbBook> {
|
||||||
|
|
||||||
book = myDatabase.loadBookByFile(fileInfos.getId(bookFile), bookFile);
|
book = myDatabase.loadBookByFile(fileInfos.getId(bookFile), bookFile);
|
||||||
if (book != null) {
|
if (book != null) {
|
||||||
book.loadLists(myDatabase);
|
book.loadLists(myDatabase, PluginCollection);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (book != null && fileInfos.check(physicalFile, physicalFile != bookFile)) {
|
if (book != null && fileInfos.check(physicalFile, physicalFile != bookFile)) {
|
||||||
|
@ -143,7 +148,7 @@ public class BookCollection extends AbstractBookCollection<DbBook> {
|
||||||
if (book == null || book.File == null || !book.File.exists() || !isBookFormatActive(book)) {
|
if (book == null || book.File == null || !book.File.exists() || !isBookFormatActive(book)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
book.loadLists(myDatabase);
|
book.loadLists(myDatabase, PluginCollection);
|
||||||
|
|
||||||
final ZLFile bookFile = book.File;
|
final ZLFile bookFile = book.File;
|
||||||
final ZLPhysicalFile physicalFile = bookFile.getPhysicalFile();
|
final ZLPhysicalFile physicalFile = bookFile.getPhysicalFile();
|
||||||
|
@ -165,7 +170,7 @@ public class BookCollection extends AbstractBookCollection<DbBook> {
|
||||||
fileInfos.save();
|
fileInfos.save();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
BookUtil.readMetainfo(book);
|
BookUtil.readMetainfo(book, PluginCollection);
|
||||||
// loaded from db
|
// loaded from db
|
||||||
addBook(book, false);
|
addBook(book, false);
|
||||||
return book;
|
return book;
|
||||||
|
@ -560,7 +565,7 @@ public class BookCollection extends AbstractBookCollection<DbBook> {
|
||||||
}
|
}
|
||||||
if (!fileInfos.check(file, true)) {
|
if (!fileInfos.check(file, true)) {
|
||||||
try {
|
try {
|
||||||
BookUtil.readMetainfo(book);
|
BookUtil.readMetainfo(book, PluginCollection);
|
||||||
saveBook(book);
|
saveBook(book);
|
||||||
} catch (BookReadingException e) {
|
} catch (BookReadingException e) {
|
||||||
doAdd = false;
|
doAdd = false;
|
||||||
|
@ -659,7 +664,7 @@ public class BookCollection extends AbstractBookCollection<DbBook> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final FormatPlugin plugin = PluginCollection.Instance().getPlugin(file);
|
final FormatPlugin plugin = PluginCollection.getPlugin(file);
|
||||||
if (plugin != null && !isFormatActive(plugin)) {
|
if (plugin != null && !isFormatActive(plugin)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -668,7 +673,7 @@ public class BookCollection extends AbstractBookCollection<DbBook> {
|
||||||
final DbBook book = orphanedBooksByFileId.get(fileId);
|
final DbBook book = orphanedBooksByFileId.get(fileId);
|
||||||
if (book != null) {
|
if (book != null) {
|
||||||
if (doReadMetaInfo) {
|
if (doReadMetaInfo) {
|
||||||
BookUtil.readMetainfo(book);
|
BookUtil.readMetainfo(book, PluginCollection);
|
||||||
}
|
}
|
||||||
newBooks.add(book);
|
newBooks.add(book);
|
||||||
return;
|
return;
|
||||||
|
@ -834,7 +839,7 @@ public class BookCollection extends AbstractBookCollection<DbBook> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<FormatDescriptor> formats() {
|
public List<FormatDescriptor> formats() {
|
||||||
final List<FormatPlugin> plugins = PluginCollection.Instance().plugins();
|
final List<FormatPlugin> plugins = PluginCollection.plugins();
|
||||||
final List<FormatDescriptor> descriptors = new ArrayList<FormatDescriptor>(plugins.size());
|
final List<FormatDescriptor> descriptors = new ArrayList<FormatDescriptor>(plugins.size());
|
||||||
for (FormatPlugin p : plugins) {
|
for (FormatPlugin p : plugins) {
|
||||||
final FormatDescriptor d = new FormatDescriptor();
|
final FormatDescriptor d = new FormatDescriptor();
|
||||||
|
@ -863,7 +868,7 @@ public class BookCollection extends AbstractBookCollection<DbBook> {
|
||||||
|
|
||||||
private boolean isBookFormatActive(DbBook book) {
|
private boolean isBookFormatActive(DbBook book) {
|
||||||
try {
|
try {
|
||||||
return isFormatActive(BookUtil.getPlugin(book));
|
return isFormatActive(BookUtil.getPlugin(PluginCollection, book));
|
||||||
} catch (BookReadingException e) {
|
} catch (BookReadingException e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,9 +28,9 @@ import org.geometerplus.zlibrary.text.view.ZLTextPosition;
|
||||||
import org.geometerplus.fbreader.formats.BookReadingException;
|
import org.geometerplus.fbreader.formats.BookReadingException;
|
||||||
|
|
||||||
class BookMergeHelper {
|
class BookMergeHelper {
|
||||||
private final IBookCollection myCollection;
|
private final BookCollection myCollection;
|
||||||
|
|
||||||
BookMergeHelper(IBookCollection collection) {
|
BookMergeHelper(BookCollection collection) {
|
||||||
myCollection = collection;
|
myCollection = collection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ class BookMergeHelper {
|
||||||
}
|
}
|
||||||
final DbBook vanilla;
|
final DbBook vanilla;
|
||||||
try {
|
try {
|
||||||
vanilla = new DbBook(base.File, BookUtil.getPlugin(base));
|
vanilla = new DbBook(base.File, BookUtil.getPlugin(myCollection.PluginCollection, base));
|
||||||
} catch (BookReadingException e) {
|
} catch (BookReadingException e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,9 +30,9 @@ import org.geometerplus.zlibrary.core.filesystem.*;
|
||||||
import org.geometerplus.fbreader.formats.*;
|
import org.geometerplus.fbreader.formats.*;
|
||||||
|
|
||||||
public abstract class BookUtil {
|
public abstract class BookUtil {
|
||||||
public static String getAnnotation(AbstractBook book) {
|
public static String getAnnotation(AbstractBook book, PluginCollection pluginCollection) {
|
||||||
try {
|
try {
|
||||||
return getPlugin(book).readAnnotation(fileByBook(book));
|
return getPlugin(pluginCollection, book).readAnnotation(fileByBook(book));
|
||||||
} catch (BookReadingException e) {
|
} catch (BookReadingException e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -97,19 +97,19 @@ public abstract class BookUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FormatPlugin getPlugin(AbstractBook book) throws BookReadingException {
|
public static FormatPlugin getPlugin(PluginCollection pluginCollection, AbstractBook book) throws BookReadingException {
|
||||||
final ZLFile file = fileByBook(book);
|
final ZLFile file = fileByBook(book);
|
||||||
final FormatPlugin plugin = PluginCollection.Instance().getPlugin(file);
|
final FormatPlugin plugin = pluginCollection.getPlugin(file);
|
||||||
if (plugin == null) {
|
if (plugin == null) {
|
||||||
throw new BookReadingException("pluginNotFound", file);
|
throw new BookReadingException("pluginNotFound", file);
|
||||||
}
|
}
|
||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getEncoding(AbstractBook book) {
|
public static String getEncoding(AbstractBook book, PluginCollection pluginCollection) {
|
||||||
if (book.getEncodingNoDetection() == null) {
|
if (book.getEncodingNoDetection() == null) {
|
||||||
try {
|
try {
|
||||||
BookUtil.getPlugin(book).detectLanguageAndEncoding(book);
|
BookUtil.getPlugin(pluginCollection, book).detectLanguageAndEncoding(book);
|
||||||
} catch (BookReadingException e) {
|
} catch (BookReadingException e) {
|
||||||
}
|
}
|
||||||
if (book.getEncodingNoDetection() == null) {
|
if (book.getEncodingNoDetection() == null) {
|
||||||
|
@ -119,16 +119,16 @@ public abstract class BookUtil {
|
||||||
return book.getEncodingNoDetection();
|
return book.getEncodingNoDetection();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void reloadInfoFromFile(AbstractBook book) {
|
public static void reloadInfoFromFile(AbstractBook book, PluginCollection pluginCollection) {
|
||||||
try {
|
try {
|
||||||
readMetainfo(book);
|
readMetainfo(book, pluginCollection);
|
||||||
} catch (BookReadingException e) {
|
} catch (BookReadingException e) {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void readMetainfo(AbstractBook book) throws BookReadingException {
|
static void readMetainfo(AbstractBook book, PluginCollection pluginCollection) throws BookReadingException {
|
||||||
readMetainfo(book, getPlugin(book));
|
readMetainfo(book, getPlugin(pluginCollection, book));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void readMetainfo(AbstractBook book, FormatPlugin plugin) throws BookReadingException {
|
static void readMetainfo(AbstractBook book, FormatPlugin plugin) throws BookReadingException {
|
||||||
|
|
|
@ -24,8 +24,7 @@ import java.util.*;
|
||||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||||
import org.geometerplus.zlibrary.core.util.MiscUtil;
|
import org.geometerplus.zlibrary.core.util.MiscUtil;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.formats.BookReadingException;
|
import org.geometerplus.fbreader.formats.*;
|
||||||
import org.geometerplus.fbreader.formats.FormatPlugin;
|
|
||||||
|
|
||||||
public final class DbBook extends AbstractBook {
|
public final class DbBook extends AbstractBook {
|
||||||
public final ZLFile File;
|
public final ZLFile File;
|
||||||
|
@ -51,7 +50,7 @@ public final class DbBook extends AbstractBook {
|
||||||
return File.getPath();
|
return File.getPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadLists(BooksDatabase database) {
|
void loadLists(BooksDatabase database, PluginCollection pluginCollection) {
|
||||||
myAuthors = database.listAuthors(myId);
|
myAuthors = database.listAuthors(myId);
|
||||||
myTags = database.listTags(myId);
|
myTags = database.listTags(myId);
|
||||||
myLabels = database.listLabels(myId);
|
myLabels = database.listLabels(myId);
|
||||||
|
@ -62,7 +61,7 @@ public final class DbBook extends AbstractBook {
|
||||||
myIsSaved = true;
|
myIsSaved = true;
|
||||||
if (myUids == null || myUids.isEmpty()) {
|
if (myUids == null || myUids.isEmpty()) {
|
||||||
try {
|
try {
|
||||||
BookUtil.getPlugin(this).readUids(this);
|
BookUtil.getPlugin(pluginCollection, this).readUids(this);
|
||||||
save(database, false);
|
save(database, false);
|
||||||
} catch (BookReadingException e) {
|
} catch (BookReadingException e) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,12 +30,10 @@ import org.geometerplus.fbreader.book.BookUtil;
|
||||||
import org.geometerplus.fbreader.formats.*;
|
import org.geometerplus.fbreader.formats.*;
|
||||||
|
|
||||||
public final class BookModel {
|
public final class BookModel {
|
||||||
public static BookModel createModel(Book book, String cacheDir) throws BookReadingException {
|
public static BookModel createModel(Book book, FormatPlugin plugin) throws BookReadingException {
|
||||||
final FormatPlugin plugin = BookUtil.getPlugin(book);
|
|
||||||
|
|
||||||
if (plugin instanceof BuiltinFormatPlugin) {
|
if (plugin instanceof BuiltinFormatPlugin) {
|
||||||
final BookModel model = new BookModel(book);
|
final BookModel model = new BookModel(book);
|
||||||
((BuiltinFormatPlugin)plugin).readModel(model, cacheDir);
|
((BuiltinFormatPlugin)plugin).readModel(model);
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,6 +77,7 @@ public final class FBReaderApp extends ZLApplication {
|
||||||
|
|
||||||
public FBReaderApp(SystemInfo systemInfo, final IBookCollection<Book> collection) {
|
public FBReaderApp(SystemInfo systemInfo, final IBookCollection<Book> collection) {
|
||||||
super(systemInfo);
|
super(systemInfo);
|
||||||
|
System.err.println("systemInfo 0 = " + systemInfo);
|
||||||
|
|
||||||
Collection = collection;
|
Collection = collection;
|
||||||
|
|
||||||
|
@ -313,7 +314,7 @@ public final class FBReaderApp extends ZLApplication {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void openBookInternal(Book book, Bookmark bookmark, boolean force) {
|
private synchronized void openBookInternal(final Book book, Bookmark bookmark, boolean force) {
|
||||||
if (!force && Model != null && Collection.sameBook(book, Model.Book)) {
|
if (!force && Model != null && Collection.sameBook(book, Model.Book)) {
|
||||||
if (bookmark != null) {
|
if (bookmark != null) {
|
||||||
gotoBookmark(bookmark, false);
|
gotoBookmark(bookmark, false);
|
||||||
|
@ -332,9 +333,11 @@ public final class FBReaderApp extends ZLApplication {
|
||||||
System.gc();
|
System.gc();
|
||||||
System.gc();
|
System.gc();
|
||||||
|
|
||||||
|
System.err.println("systemInfo 1 = " + SystemInfo);
|
||||||
|
final PluginCollection pluginCollection = PluginCollection.Instance(SystemInfo);
|
||||||
FormatPlugin plugin = null;
|
FormatPlugin plugin = null;
|
||||||
try {
|
try {
|
||||||
plugin = BookUtil.getPlugin(book);
|
plugin = BookUtil.getPlugin(pluginCollection, book);
|
||||||
} catch (BookReadingException e) {
|
} catch (BookReadingException e) {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
|
@ -355,7 +358,8 @@ public final class FBReaderApp extends ZLApplication {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Model = BookModel.createModel(book, SystemInfo.tempDirectory());
|
System.err.println("systemInfo 2 = " + SystemInfo);
|
||||||
|
Model = BookModel.createModel(book, plugin);
|
||||||
Collection.saveBook(book);
|
Collection.saveBook(book);
|
||||||
ZLTextHyphenator.Instance().load(book.getLanguage());
|
ZLTextHyphenator.Instance().load(book.getLanguage());
|
||||||
BookTextView.setModel(Model.getTextModel());
|
BookTextView.setModel(Model.getTextModel());
|
||||||
|
@ -385,16 +389,12 @@ public final class FBReaderApp extends ZLApplication {
|
||||||
getViewWidget().reset();
|
getViewWidget().reset();
|
||||||
getViewWidget().repaint();
|
getViewWidget().repaint();
|
||||||
|
|
||||||
try {
|
for (FileEncryptionInfo info : plugin.readEncryptionInfos(book)) {
|
||||||
for (FileEncryptionInfo info : BookUtil.getPlugin(book).readEncryptionInfos(book)) {
|
|
||||||
if (info != null && !EncryptionMethod.isSupported(info.Method)) {
|
if (info != null && !EncryptionMethod.isSupported(info.Method)) {
|
||||||
showErrorMessage("unsupportedEncryptionMethod", book.getPath());
|
showErrorMessage("unsupportedEncryptionMethod", book.getPath());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (BookReadingException e) {
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Bookmark> invisibleBookmarks() {
|
private List<Bookmark> invisibleBookmarks() {
|
||||||
|
|
|
@ -19,12 +19,14 @@
|
||||||
|
|
||||||
package org.geometerplus.fbreader.formats;
|
package org.geometerplus.fbreader.formats;
|
||||||
|
|
||||||
|
import org.geometerplus.zlibrary.core.util.SystemInfo;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.bookmodel.BookModel;
|
import org.geometerplus.fbreader.bookmodel.BookModel;
|
||||||
|
|
||||||
public abstract class BuiltinFormatPlugin extends FormatPlugin {
|
public abstract class BuiltinFormatPlugin extends FormatPlugin {
|
||||||
protected BuiltinFormatPlugin(String fileType) {
|
protected BuiltinFormatPlugin(SystemInfo systemInfo, String fileType) {
|
||||||
super(fileType);
|
super(systemInfo, fileType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void readModel(BookModel model, String cacheDir) throws BookReadingException;
|
public abstract void readModel(BookModel model) throws BookReadingException;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,11 +19,13 @@
|
||||||
|
|
||||||
package org.geometerplus.fbreader.formats;
|
package org.geometerplus.fbreader.formats;
|
||||||
|
|
||||||
|
import org.geometerplus.zlibrary.core.util.SystemInfo;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.book.AbstractBook;
|
import org.geometerplus.fbreader.book.AbstractBook;
|
||||||
|
|
||||||
public class ComicBookPlugin extends ExternalFormatPlugin {
|
public class ComicBookPlugin extends ExternalFormatPlugin {
|
||||||
public ComicBookPlugin() {
|
public ComicBookPlugin(SystemInfo systemInfo) {
|
||||||
super("CBZ");
|
super(systemInfo, "CBZ");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -19,11 +19,13 @@
|
||||||
|
|
||||||
package org.geometerplus.fbreader.formats;
|
package org.geometerplus.fbreader.formats;
|
||||||
|
|
||||||
|
import org.geometerplus.zlibrary.core.util.SystemInfo;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.book.AbstractBook;
|
import org.geometerplus.fbreader.book.AbstractBook;
|
||||||
|
|
||||||
public class DjVuPlugin extends ExternalFormatPlugin {
|
public class DjVuPlugin extends ExternalFormatPlugin {
|
||||||
public DjVuPlugin() {
|
public DjVuPlugin(SystemInfo systemInfo) {
|
||||||
super("DjVu");
|
super(systemInfo, "DjVu");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -21,13 +21,14 @@ package org.geometerplus.fbreader.formats;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.encodings.AutoEncodingCollection;
|
import org.geometerplus.zlibrary.core.encodings.AutoEncodingCollection;
|
||||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||||
|
import org.geometerplus.zlibrary.core.util.SystemInfo;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.book.AbstractBook;
|
import org.geometerplus.fbreader.book.AbstractBook;
|
||||||
import org.geometerplus.fbreader.book.BookUtil;
|
import org.geometerplus.fbreader.book.BookUtil;
|
||||||
|
|
||||||
public abstract class ExternalFormatPlugin extends FormatPlugin {
|
public abstract class ExternalFormatPlugin extends FormatPlugin {
|
||||||
protected ExternalFormatPlugin(String fileType) {
|
protected ExternalFormatPlugin(SystemInfo systemInfo, String fileType) {
|
||||||
super(fileType);
|
super(systemInfo, fileType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -27,13 +27,16 @@ import org.geometerplus.zlibrary.core.encodings.EncodingCollection;
|
||||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||||
import org.geometerplus.zlibrary.core.image.ZLImage;
|
import org.geometerplus.zlibrary.core.image.ZLImage;
|
||||||
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||||
|
import org.geometerplus.zlibrary.core.util.SystemInfo;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.book.AbstractBook;
|
import org.geometerplus.fbreader.book.AbstractBook;
|
||||||
|
|
||||||
public abstract class FormatPlugin {
|
public abstract class FormatPlugin {
|
||||||
|
protected final SystemInfo SystemInfo;
|
||||||
private final String myFileType;
|
private final String myFileType;
|
||||||
|
|
||||||
protected FormatPlugin(String fileType) {
|
protected FormatPlugin(SystemInfo systemInfo, String fileType) {
|
||||||
|
SystemInfo = systemInfo;
|
||||||
myFileType = fileType;
|
myFileType = fileType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ import org.geometerplus.zlibrary.core.encodings.EncodingCollection;
|
||||||
import org.geometerplus.zlibrary.core.encodings.JavaEncodingCollection;
|
import org.geometerplus.zlibrary.core.encodings.JavaEncodingCollection;
|
||||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||||
import org.geometerplus.zlibrary.core.image.*;
|
import org.geometerplus.zlibrary.core.image.*;
|
||||||
|
import org.geometerplus.zlibrary.core.util.SystemInfo;
|
||||||
import org.geometerplus.zlibrary.text.model.CachedCharStorageException;
|
import org.geometerplus.zlibrary.text.model.CachedCharStorageException;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.book.AbstractBook;
|
import org.geometerplus.fbreader.book.AbstractBook;
|
||||||
|
@ -37,18 +38,18 @@ import org.geometerplus.fbreader.formats.oeb.OEBNativePlugin;
|
||||||
public class NativeFormatPlugin extends BuiltinFormatPlugin {
|
public class NativeFormatPlugin extends BuiltinFormatPlugin {
|
||||||
private static final Object ourNativeLock = new Object();
|
private static final Object ourNativeLock = new Object();
|
||||||
|
|
||||||
public static NativeFormatPlugin create(String fileType) {
|
public static NativeFormatPlugin create(SystemInfo systemInfo, String fileType) {
|
||||||
if ("fb2".equals(fileType)) {
|
if ("fb2".equals(fileType)) {
|
||||||
return new FB2NativePlugin();
|
return new FB2NativePlugin(systemInfo);
|
||||||
} else if ("ePub".equals(fileType)) {
|
} else if ("ePub".equals(fileType)) {
|
||||||
return new OEBNativePlugin();
|
return new OEBNativePlugin(systemInfo);
|
||||||
} else {
|
} else {
|
||||||
return new NativeFormatPlugin(fileType);
|
return new NativeFormatPlugin(systemInfo, fileType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected NativeFormatPlugin(String fileType) {
|
protected NativeFormatPlugin(SystemInfo systemInfo, String fileType) {
|
||||||
super(fileType);
|
super(systemInfo, fileType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -103,10 +104,10 @@ public class NativeFormatPlugin extends BuiltinFormatPlugin {
|
||||||
private native void detectLanguageAndEncodingNative(AbstractBook book);
|
private native void detectLanguageAndEncodingNative(AbstractBook book);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
synchronized public void readModel(BookModel model, String cacheDir) throws BookReadingException {
|
synchronized public void readModel(BookModel model) throws BookReadingException {
|
||||||
final int code;
|
final int code;
|
||||||
synchronized (ourNativeLock) {
|
synchronized (ourNativeLock) {
|
||||||
code = readModelNative(model, cacheDir);
|
code = readModelNative(model, SystemInfo.tempDirectory());
|
||||||
}
|
}
|
||||||
switch (code) {
|
switch (code) {
|
||||||
case 0:
|
case 0:
|
||||||
|
|
|
@ -23,12 +23,14 @@ import org.pdfparse.model.PDFDocInfo;
|
||||||
import org.pdfparse.model.PDFDocument;
|
import org.pdfparse.model.PDFDocument;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||||
|
import org.geometerplus.zlibrary.core.util.SystemInfo;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.book.AbstractBook;
|
import org.geometerplus.fbreader.book.AbstractBook;
|
||||||
import org.geometerplus.fbreader.book.BookUtil;
|
import org.geometerplus.fbreader.book.BookUtil;
|
||||||
|
|
||||||
public class PDFPlugin extends ExternalFormatPlugin {
|
public class PDFPlugin extends ExternalFormatPlugin {
|
||||||
public PDFPlugin() {
|
public PDFPlugin(SystemInfo systemInfo) {
|
||||||
super("PDF");
|
super(systemInfo, "PDF");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -25,6 +25,7 @@ import android.os.Build;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||||
import org.geometerplus.zlibrary.core.filetypes.*;
|
import org.geometerplus.zlibrary.core.filetypes.*;
|
||||||
|
import org.geometerplus.zlibrary.core.util.SystemInfo;
|
||||||
|
|
||||||
public class PluginCollection implements IFormatPluginCollection {
|
public class PluginCollection implements IFormatPluginCollection {
|
||||||
static {
|
static {
|
||||||
|
@ -38,20 +39,20 @@ public class PluginCollection implements IFormatPluginCollection {
|
||||||
private final List<ExternalFormatPlugin> myExternalPlugins =
|
private final List<ExternalFormatPlugin> myExternalPlugins =
|
||||||
new LinkedList<ExternalFormatPlugin>();
|
new LinkedList<ExternalFormatPlugin>();
|
||||||
|
|
||||||
public static PluginCollection Instance() {
|
public static PluginCollection Instance(SystemInfo systemInfo) {
|
||||||
if (ourInstance == null) {
|
if (ourInstance == null) {
|
||||||
createInstance();
|
createInstance(systemInfo);
|
||||||
}
|
}
|
||||||
return ourInstance;
|
return ourInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static synchronized void createInstance() {
|
private static synchronized void createInstance(SystemInfo systemInfo) {
|
||||||
if (ourInstance == null) {
|
if (ourInstance == null) {
|
||||||
ourInstance = new PluginCollection();
|
ourInstance = new PluginCollection(systemInfo);
|
||||||
|
|
||||||
// This code cannot be moved to constructor
|
// This code cannot be moved to constructor
|
||||||
// because nativePlugins() is a native method
|
// because nativePlugins() is a native method
|
||||||
for (NativeFormatPlugin p : ourInstance.nativePlugins()) {
|
for (NativeFormatPlugin p : ourInstance.nativePlugins(systemInfo)) {
|
||||||
ourInstance.myBuiltinPlugins.add(p);
|
ourInstance.myBuiltinPlugins.add(p);
|
||||||
System.err.println("native plugin: " + p);
|
System.err.println("native plugin: " + p);
|
||||||
}
|
}
|
||||||
|
@ -64,11 +65,11 @@ public class PluginCollection implements IFormatPluginCollection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private PluginCollection() {
|
private PluginCollection(SystemInfo systemInfo) {
|
||||||
if (Build.VERSION.SDK_INT >= 8) {
|
if (Build.VERSION.SDK_INT >= 8) {
|
||||||
myExternalPlugins.add(new DjVuPlugin());
|
myExternalPlugins.add(new DjVuPlugin(systemInfo));
|
||||||
myExternalPlugins.add(new PDFPlugin());
|
myExternalPlugins.add(new PDFPlugin(systemInfo));
|
||||||
myExternalPlugins.add(new ComicBookPlugin());
|
myExternalPlugins.add(new ComicBookPlugin(systemInfo));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +116,7 @@ public class PluginCollection implements IFormatPluginCollection {
|
||||||
return all;
|
return all;
|
||||||
}
|
}
|
||||||
|
|
||||||
private native NativeFormatPlugin[] nativePlugins();
|
private native NativeFormatPlugin[] nativePlugins(SystemInfo systemInfo);
|
||||||
private native void free();
|
private native void free();
|
||||||
|
|
||||||
protected void finalize() throws Throwable {
|
protected void finalize() throws Throwable {
|
||||||
|
|
|
@ -25,8 +25,8 @@ import java.util.List;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.encodings.EncodingCollection;
|
import org.geometerplus.zlibrary.core.encodings.EncodingCollection;
|
||||||
import org.geometerplus.zlibrary.core.encodings.AutoEncodingCollection;
|
import org.geometerplus.zlibrary.core.encodings.AutoEncodingCollection;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||||
|
import org.geometerplus.zlibrary.core.util.SystemInfo;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.book.AbstractBook;
|
import org.geometerplus.fbreader.book.AbstractBook;
|
||||||
import org.geometerplus.fbreader.bookmodel.BookModel;
|
import org.geometerplus.fbreader.bookmodel.BookModel;
|
||||||
|
@ -34,13 +34,15 @@ import org.geometerplus.fbreader.formats.BookReadingException;
|
||||||
import org.geometerplus.fbreader.formats.NativeFormatPlugin;
|
import org.geometerplus.fbreader.formats.NativeFormatPlugin;
|
||||||
|
|
||||||
public class FB2NativePlugin extends NativeFormatPlugin {
|
public class FB2NativePlugin extends NativeFormatPlugin {
|
||||||
public FB2NativePlugin() {
|
public FB2NativePlugin(SystemInfo systemInfo) {
|
||||||
super("fb2");
|
super(systemInfo, "fb2");
|
||||||
|
System.err.println("systemInfo fbc " + systemInfo);
|
||||||
|
new Exception("systemInfo fbc2").printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readModel(BookModel model, String cacheDir) throws BookReadingException {
|
public void readModel(BookModel model) throws BookReadingException {
|
||||||
super.readModel(model, cacheDir);
|
super.readModel(model);
|
||||||
model.setLabelResolver(new BookModel.LabelResolver() {
|
model.setLabelResolver(new BookModel.LabelResolver() {
|
||||||
public List<String> getCandidates(String id) {
|
public List<String> getCandidates(String id) {
|
||||||
final List<String> candidates = new ArrayList<String>();
|
final List<String> candidates = new ArrayList<String>();
|
||||||
|
|
|
@ -25,6 +25,7 @@ import java.util.List;
|
||||||
import org.geometerplus.zlibrary.core.encodings.EncodingCollection;
|
import org.geometerplus.zlibrary.core.encodings.EncodingCollection;
|
||||||
import org.geometerplus.zlibrary.core.encodings.AutoEncodingCollection;
|
import org.geometerplus.zlibrary.core.encodings.AutoEncodingCollection;
|
||||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||||
|
import org.geometerplus.zlibrary.core.util.SystemInfo;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.book.AbstractBook;
|
import org.geometerplus.fbreader.book.AbstractBook;
|
||||||
import org.geometerplus.fbreader.book.BookUtil;
|
import org.geometerplus.fbreader.book.BookUtil;
|
||||||
|
@ -33,16 +34,16 @@ import org.geometerplus.fbreader.formats.BookReadingException;
|
||||||
import org.geometerplus.fbreader.formats.NativeFormatPlugin;
|
import org.geometerplus.fbreader.formats.NativeFormatPlugin;
|
||||||
|
|
||||||
public class OEBNativePlugin extends NativeFormatPlugin {
|
public class OEBNativePlugin extends NativeFormatPlugin {
|
||||||
public OEBNativePlugin() {
|
public OEBNativePlugin(SystemInfo systemInfo) {
|
||||||
super("ePub");
|
super(systemInfo, "ePub");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readModel(BookModel model, String cacheDir) throws BookReadingException {
|
public void readModel(BookModel model) throws BookReadingException {
|
||||||
final ZLFile file = BookUtil.fileByBook(model.Book);
|
final ZLFile file = BookUtil.fileByBook(model.Book);
|
||||||
file.setCached(true);
|
file.setCached(true);
|
||||||
try {
|
try {
|
||||||
super.readModel(model, cacheDir);
|
super.readModel(model);
|
||||||
model.setLabelResolver(new BookModel.LabelResolver() {
|
model.setLabelResolver(new BookModel.LabelResolver() {
|
||||||
public List<String> getCandidates(String id) {
|
public List<String> getCandidates(String id) {
|
||||||
final int index = id.indexOf("#");
|
final int index = id.indexOf("#");
|
||||||
|
|
|
@ -67,7 +67,7 @@ public class AuthorListTree extends FirstLevelTree {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean createAuthorSubtree(Author author) {
|
private boolean createAuthorSubtree(Author author) {
|
||||||
final AuthorTree temp = new AuthorTree(Collection, author);
|
final AuthorTree temp = new AuthorTree(Collection, PluginCollection, author);
|
||||||
int position = Collections.binarySearch(subtrees(), temp);
|
int position = Collections.binarySearch(subtrees(), temp);
|
||||||
if (position >= 0) {
|
if (position >= 0) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -22,12 +22,13 @@ package org.geometerplus.fbreader.library;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.book.*;
|
import org.geometerplus.fbreader.book.*;
|
||||||
|
import org.geometerplus.fbreader.formats.PluginCollection;
|
||||||
|
|
||||||
public class AuthorTree extends FilteredTree {
|
public class AuthorTree extends FilteredTree {
|
||||||
public final Author Author;
|
public final Author Author;
|
||||||
|
|
||||||
AuthorTree(IBookCollection collection, Author author) {
|
AuthorTree(IBookCollection collection, PluginCollection pluginCollection, Author author) {
|
||||||
super(collection, new Filter.ByAuthor(author));
|
super(collection, pluginCollection, new Filter.ByAuthor(author));
|
||||||
Author = author;
|
Author = author;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +62,7 @@ public class AuthorTree extends FilteredTree {
|
||||||
}
|
}
|
||||||
|
|
||||||
private SeriesTree getSeriesSubtree(Series series) {
|
private SeriesTree getSeriesSubtree(Series series) {
|
||||||
final SeriesTree temp = new SeriesTree(Collection, series, Author);
|
final SeriesTree temp = new SeriesTree(Collection, PluginCollection, series, Author);
|
||||||
int position = Collections.binarySearch(subtrees(), temp);
|
int position = Collections.binarySearch(subtrees(), temp);
|
||||||
if (position >= 0) {
|
if (position >= 0) {
|
||||||
return (SeriesTree)subtrees().get(position);
|
return (SeriesTree)subtrees().get(position);
|
||||||
|
@ -77,7 +78,7 @@ public class AuthorTree extends FilteredTree {
|
||||||
return getSeriesSubtree(seriesInfo.Series).createSubtree(book);
|
return getSeriesSubtree(seriesInfo.Series).createSubtree(book);
|
||||||
}
|
}
|
||||||
|
|
||||||
final BookTree temp = new BookTree(Collection, book);
|
final BookTree temp = new BookTree(Collection, PluginCollection, book);
|
||||||
int position = Collections.binarySearch(subtrees(), temp);
|
int position = Collections.binarySearch(subtrees(), temp);
|
||||||
if (position >= 0) {
|
if (position >= 0) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -23,11 +23,12 @@ import java.math.BigDecimal;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.book.Book;
|
import org.geometerplus.fbreader.book.Book;
|
||||||
import org.geometerplus.fbreader.book.IBookCollection;
|
import org.geometerplus.fbreader.book.IBookCollection;
|
||||||
|
import org.geometerplus.fbreader.formats.PluginCollection;
|
||||||
import org.geometerplus.fbreader.tree.FBTree;
|
import org.geometerplus.fbreader.tree.FBTree;
|
||||||
|
|
||||||
public final class BookInSeriesTree extends BookTree {
|
public final class BookInSeriesTree extends BookTree {
|
||||||
BookInSeriesTree(IBookCollection collection, Book book) {
|
BookInSeriesTree(IBookCollection collection, PluginCollection pluginCollection, Book book) {
|
||||||
super(collection, book);
|
super(collection, pluginCollection, book);
|
||||||
}
|
}
|
||||||
|
|
||||||
BookInSeriesTree(LibraryTree parent, Book book, int position) {
|
BookInSeriesTree(LibraryTree parent, Book book, int position) {
|
||||||
|
|
|
@ -28,8 +28,8 @@ import org.geometerplus.fbreader.tree.FBTree;
|
||||||
public class BookTree extends LibraryTree {
|
public class BookTree extends LibraryTree {
|
||||||
public final Book Book;
|
public final Book Book;
|
||||||
|
|
||||||
BookTree(IBookCollection<Book> collection, Book book) {
|
BookTree(IBookCollection<Book> collection, PluginCollection pluginCollection, Book book) {
|
||||||
super(collection);
|
super(collection, pluginCollection);
|
||||||
Book = book;
|
Book = book;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ public class BookTree extends LibraryTree {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ZLImage createCover() {
|
protected ZLImage createCover() {
|
||||||
return CoverUtil.getCover(Book, PluginCollection.Instance());
|
return CoverUtil.getCover(Book, PluginCollection);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -20,10 +20,11 @@
|
||||||
package org.geometerplus.fbreader.library;
|
package org.geometerplus.fbreader.library;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.book.*;
|
import org.geometerplus.fbreader.book.*;
|
||||||
|
import org.geometerplus.fbreader.formats.PluginCollection;
|
||||||
|
|
||||||
public class BookWithAuthorsTree extends BookTree {
|
public class BookWithAuthorsTree extends BookTree {
|
||||||
BookWithAuthorsTree(IBookCollection collection, Book book) {
|
BookWithAuthorsTree(IBookCollection collection, PluginCollection pluginCollection, Book book) {
|
||||||
super(collection, book);
|
super(collection, pluginCollection, book);
|
||||||
}
|
}
|
||||||
|
|
||||||
BookWithAuthorsTree(LibraryTree parent, Book book) {
|
BookWithAuthorsTree(LibraryTree parent, Book book) {
|
||||||
|
|
|
@ -25,7 +25,6 @@ import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||||
import org.geometerplus.zlibrary.core.image.ZLImage;
|
import org.geometerplus.zlibrary.core.image.ZLImage;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.book.*;
|
import org.geometerplus.fbreader.book.*;
|
||||||
import org.geometerplus.fbreader.formats.PluginCollection;
|
|
||||||
import org.geometerplus.fbreader.tree.FBTree;
|
import org.geometerplus.fbreader.tree.FBTree;
|
||||||
|
|
||||||
public class FileTree extends LibraryTree {
|
public class FileTree extends LibraryTree {
|
||||||
|
@ -86,7 +85,7 @@ public class FileTree extends LibraryTree {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ZLImage createCover() {
|
public ZLImage createCover() {
|
||||||
return CoverUtil.getCover(getBook(), PluginCollection.Instance());
|
return CoverUtil.getCover(getBook(), PluginCollection);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ZLFile getFile() {
|
public ZLFile getFile() {
|
||||||
|
|
|
@ -24,12 +24,13 @@ import java.util.List;
|
||||||
import org.geometerplus.zlibrary.core.util.MiscUtil;
|
import org.geometerplus.zlibrary.core.util.MiscUtil;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.book.*;
|
import org.geometerplus.fbreader.book.*;
|
||||||
|
import org.geometerplus.fbreader.formats.PluginCollection;
|
||||||
|
|
||||||
abstract class FilteredTree extends LibraryTree {
|
abstract class FilteredTree extends LibraryTree {
|
||||||
private final Filter myFilter;
|
private final Filter myFilter;
|
||||||
|
|
||||||
FilteredTree(IBookCollection collection, Filter filter) {
|
FilteredTree(IBookCollection collection, PluginCollection pluginCollection, Filter filter) {
|
||||||
super(collection);
|
super(collection, pluginCollection);
|
||||||
myFilter = filter;
|
myFilter = filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.util.*;
|
||||||
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.book.*;
|
import org.geometerplus.fbreader.book.*;
|
||||||
|
import org.geometerplus.fbreader.formats.PluginCollection;
|
||||||
import org.geometerplus.fbreader.tree.FBTree;
|
import org.geometerplus.fbreader.tree.FBTree;
|
||||||
|
|
||||||
public abstract class LibraryTree extends FBTree {
|
public abstract class LibraryTree extends FBTree {
|
||||||
|
@ -32,6 +33,7 @@ public abstract class LibraryTree extends FBTree {
|
||||||
}
|
}
|
||||||
|
|
||||||
public final IBookCollection<Book> Collection;
|
public final IBookCollection<Book> Collection;
|
||||||
|
public final PluginCollection PluginCollection;
|
||||||
|
|
||||||
static final String ROOT_EXTERNAL_VIEW = "bookshelfView";
|
static final String ROOT_EXTERNAL_VIEW = "bookshelfView";
|
||||||
static final String ROOT_FOUND = "found";
|
static final String ROOT_FOUND = "found";
|
||||||
|
@ -44,19 +46,22 @@ public abstract class LibraryTree extends FBTree {
|
||||||
static final String ROOT_SYNC = "sync";
|
static final String ROOT_SYNC = "sync";
|
||||||
static final String ROOT_FILE = "fileTree";
|
static final String ROOT_FILE = "fileTree";
|
||||||
|
|
||||||
protected LibraryTree(IBookCollection collection) {
|
protected LibraryTree(IBookCollection collection, PluginCollection pluginCollection) {
|
||||||
super();
|
super();
|
||||||
Collection = collection;
|
Collection = collection;
|
||||||
|
PluginCollection = pluginCollection;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected LibraryTree(LibraryTree parent) {
|
protected LibraryTree(LibraryTree parent) {
|
||||||
super(parent);
|
super(parent);
|
||||||
Collection = parent.Collection;
|
Collection = parent.Collection;
|
||||||
|
PluginCollection = parent.PluginCollection;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected LibraryTree(LibraryTree parent, int position) {
|
protected LibraryTree(LibraryTree parent, int position) {
|
||||||
super(parent, position);
|
super(parent, position);
|
||||||
Collection = parent.Collection;
|
Collection = parent.Collection;
|
||||||
|
PluginCollection = parent.PluginCollection;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Book getBook() {
|
public Book getBook() {
|
||||||
|
@ -72,7 +77,7 @@ public abstract class LibraryTree extends FBTree {
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean createTagSubtree(Tag tag) {
|
boolean createTagSubtree(Tag tag) {
|
||||||
final TagTree temp = new TagTree(Collection, tag);
|
final TagTree temp = new TagTree(Collection, PluginCollection, tag);
|
||||||
int position = Collections.binarySearch(subtrees(), temp);
|
int position = Collections.binarySearch(subtrees(), temp);
|
||||||
if (position >= 0) {
|
if (position >= 0) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -83,7 +88,7 @@ public abstract class LibraryTree extends FBTree {
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean createBookWithAuthorsSubtree(Book book) {
|
boolean createBookWithAuthorsSubtree(Book book) {
|
||||||
final BookWithAuthorsTree temp = new BookWithAuthorsTree(Collection, book);
|
final BookWithAuthorsTree temp = new BookWithAuthorsTree(Collection, PluginCollection, book);
|
||||||
int position = Collections.binarySearch(subtrees(), temp);
|
int position = Collections.binarySearch(subtrees(), temp);
|
||||||
if (position >= 0) {
|
if (position >= 0) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -23,11 +23,12 @@ import java.util.List;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.book.IBookCollection;
|
import org.geometerplus.fbreader.book.IBookCollection;
|
||||||
import org.geometerplus.fbreader.fbreader.options.SyncOptions;
|
import org.geometerplus.fbreader.fbreader.options.SyncOptions;
|
||||||
|
import org.geometerplus.fbreader.formats.PluginCollection;
|
||||||
import org.geometerplus.fbreader.tree.FBTree;
|
import org.geometerplus.fbreader.tree.FBTree;
|
||||||
|
|
||||||
public class RootTree extends LibraryTree {
|
public class RootTree extends LibraryTree {
|
||||||
public RootTree(IBookCollection collection) {
|
public RootTree(IBookCollection collection, PluginCollection pluginCollection) {
|
||||||
super(collection);
|
super(collection, pluginCollection);
|
||||||
|
|
||||||
//new ExternalViewTree(this);
|
//new ExternalViewTree(this);
|
||||||
new FavoritesTree(this);
|
new FavoritesTree(this);
|
||||||
|
|
|
@ -72,7 +72,7 @@ public class SeriesListTree extends FirstLevelTree {
|
||||||
private boolean createSeriesSubtree(String seriesTitle) {
|
private boolean createSeriesSubtree(String seriesTitle) {
|
||||||
// TODO: pass series as parameter
|
// TODO: pass series as parameter
|
||||||
final Series series = new Series(seriesTitle);
|
final Series series = new Series(seriesTitle);
|
||||||
final SeriesTree temp = new SeriesTree(Collection, series, null);
|
final SeriesTree temp = new SeriesTree(Collection, PluginCollection, series, null);
|
||||||
int position = Collections.binarySearch(subtrees(), temp);
|
int position = Collections.binarySearch(subtrees(), temp);
|
||||||
if (position >= 0) {
|
if (position >= 0) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -22,6 +22,7 @@ package org.geometerplus.fbreader.library;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.book.*;
|
import org.geometerplus.fbreader.book.*;
|
||||||
|
import org.geometerplus.fbreader.formats.PluginCollection;
|
||||||
|
|
||||||
public final class SeriesTree extends FilteredTree {
|
public final class SeriesTree extends FilteredTree {
|
||||||
public final Series Series;
|
public final Series Series;
|
||||||
|
@ -31,8 +32,8 @@ public final class SeriesTree extends FilteredTree {
|
||||||
return author != null ? new Filter.And(f, new Filter.ByAuthor(author)) : f;
|
return author != null ? new Filter.And(f, new Filter.ByAuthor(author)) : f;
|
||||||
}
|
}
|
||||||
|
|
||||||
SeriesTree(IBookCollection collection, Series series, Author author) {
|
SeriesTree(IBookCollection collection, PluginCollection pluginCollection, Series series, Author author) {
|
||||||
super(collection, filter(series, author));
|
super(collection, pluginCollection, filter(series, author));
|
||||||
Series = series;
|
Series = series;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +59,7 @@ public final class SeriesTree extends FilteredTree {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean createSubtree(Book book) {
|
protected boolean createSubtree(Book book) {
|
||||||
final BookInSeriesTree temp = new BookInSeriesTree(Collection, book);
|
final BookInSeriesTree temp = new BookInSeriesTree(Collection, PluginCollection, book);
|
||||||
int position = Collections.binarySearch(subtrees(), temp);
|
int position = Collections.binarySearch(subtrees(), temp);
|
||||||
if (position >= 0) {
|
if (position >= 0) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -22,12 +22,13 @@ package org.geometerplus.fbreader.library;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.book.*;
|
import org.geometerplus.fbreader.book.*;
|
||||||
|
import org.geometerplus.fbreader.formats.PluginCollection;
|
||||||
|
|
||||||
public final class TagTree extends FilteredTree {
|
public final class TagTree extends FilteredTree {
|
||||||
public final Tag Tag;
|
public final Tag Tag;
|
||||||
|
|
||||||
TagTree(IBookCollection collection, Tag tag) {
|
TagTree(IBookCollection collection, PluginCollection pluginCollection, Tag tag) {
|
||||||
super(collection, new Filter.ByTag(tag));
|
super(collection, pluginCollection, new Filter.ByTag(tag));
|
||||||
Tag = tag;
|
Tag = tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -100,7 +100,7 @@ public class TitleListTree extends FirstLevelTree {
|
||||||
if (prefix == null) {
|
if (prefix == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final TitleTree temp = new TitleTree(Collection, prefix);
|
final TitleTree temp = new TitleTree(Collection, PluginCollection, prefix);
|
||||||
int position = Collections.binarySearch(subtrees(), temp);
|
int position = Collections.binarySearch(subtrees(), temp);
|
||||||
if (position >= 0) {
|
if (position >= 0) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -20,12 +20,13 @@
|
||||||
package org.geometerplus.fbreader.library;
|
package org.geometerplus.fbreader.library;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.book.*;
|
import org.geometerplus.fbreader.book.*;
|
||||||
|
import org.geometerplus.fbreader.formats.PluginCollection;
|
||||||
|
|
||||||
public final class TitleTree extends FilteredTree {
|
public final class TitleTree extends FilteredTree {
|
||||||
public final String Prefix;
|
public final String Prefix;
|
||||||
|
|
||||||
TitleTree(IBookCollection collection, String prefix) {
|
TitleTree(IBookCollection collection, PluginCollection pluginCollection, String prefix) {
|
||||||
super(collection, new Filter.ByTitlePrefix(prefix));
|
super(collection, pluginCollection, new Filter.ByTitlePrefix(prefix));
|
||||||
Prefix = prefix;
|
Prefix = prefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -132,11 +132,17 @@ public class OPDSBookItem extends NetworkBookItem implements OPDSConstants {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (MimeType.TEXT_HTML.equals(mime)) {
|
if (MimeType.TEXT_HTML.equals(mime)) {
|
||||||
collectReferences(urls, opdsLink, href,
|
collectReferences(
|
||||||
UrlInfo.Type.BookBuyInBrowser, price, true);
|
networkLink.Library,
|
||||||
|
urls, opdsLink, href,
|
||||||
|
UrlInfo.Type.BookBuyInBrowser, price, true
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
collectReferences(urls, opdsLink, href,
|
collectReferences(
|
||||||
UrlInfo.Type.BookBuy, price, false);
|
networkLink.Library,
|
||||||
|
urls, opdsLink, href,
|
||||||
|
UrlInfo.Type.BookBuy, price, false
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else if (referenceType == UrlInfo.Type.Related) {
|
} else if (referenceType == UrlInfo.Type.Related) {
|
||||||
urls.addInfo(new RelatedUrlInfo(referenceType, link.getTitle(), href, mime));
|
urls.addInfo(new RelatedUrlInfo(referenceType, link.getTitle(), href, mime));
|
||||||
|
@ -145,7 +151,7 @@ public class OPDSBookItem extends NetworkBookItem implements OPDSConstants {
|
||||||
} else if (referenceType == UrlInfo.Type.TOC) {
|
} else if (referenceType == UrlInfo.Type.TOC) {
|
||||||
urls.addInfo(new UrlInfo(referenceType, href, mime));
|
urls.addInfo(new UrlInfo(referenceType, href, mime));
|
||||||
} else if (referenceType != null) {
|
} else if (referenceType != null) {
|
||||||
if (BookUrlInfo.isMimeSupported(mime)) {
|
if (BookUrlInfo.isMimeSupported(mime, networkLink.Library.SystemInfo)) {
|
||||||
urls.addInfo(new BookUrlInfo(referenceType, href, mime));
|
urls.addInfo(new BookUrlInfo(referenceType, href, mime));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -176,6 +182,7 @@ public class OPDSBookItem extends NetworkBookItem implements OPDSConstants {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void collectReferences(
|
private static void collectReferences(
|
||||||
|
NetworkLibrary library,
|
||||||
UrlInfoCollection<UrlInfo> urls,
|
UrlInfoCollection<UrlInfo> urls,
|
||||||
OPDSLink opdsLink,
|
OPDSLink opdsLink,
|
||||||
String href,
|
String href,
|
||||||
|
@ -186,7 +193,7 @@ public class OPDSBookItem extends NetworkBookItem implements OPDSConstants {
|
||||||
boolean added = false;
|
boolean added = false;
|
||||||
for (String f : opdsLink.Formats) {
|
for (String f : opdsLink.Formats) {
|
||||||
final MimeType mime = MimeType.get(f);
|
final MimeType mime = MimeType.get(f);
|
||||||
if (BookUrlInfo.isMimeSupported(mime)) {
|
if (BookUrlInfo.isMimeSupported(mime, library.SystemInfo)) {
|
||||||
urls.addInfo(new BookBuyUrlInfo(type, href, mime, price));
|
urls.addInfo(new BookBuyUrlInfo(type, href, mime, price));
|
||||||
added = true;
|
added = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,7 +98,7 @@ public class OPDSCustomNetworkLink extends OPDSNetworkLink implements ICustomNet
|
||||||
@Override
|
@Override
|
||||||
public void handleStream(InputStream inputStream, int length) throws IOException, ZLNetworkException {
|
public void handleStream(InputStream inputStream, int length) throws IOException, ZLNetworkException {
|
||||||
final OPDSCatalogInfoHandler info = new OPDSCatalogInfoHandler(getURL(), OPDSCustomNetworkLink.this, opensearchDescriptionURLs);
|
final OPDSCatalogInfoHandler info = new OPDSCatalogInfoHandler(getURL(), OPDSCustomNetworkLink.this, opensearchDescriptionURLs);
|
||||||
new OPDSXMLReader(myLibrary, info, false).read(inputStream);
|
new OPDSXMLReader(Library, info, false).read(inputStream);
|
||||||
|
|
||||||
if (!info.FeedStarted) {
|
if (!info.FeedStarted) {
|
||||||
throw ZLNetworkException.forCode(NetworkException.ERROR_NOT_AN_OPDS);
|
throw ZLNetworkException.forCode(NetworkException.ERROR_NOT_AN_OPDS);
|
||||||
|
|
|
@ -124,7 +124,7 @@ class OPDSFeedHandler extends AbstractOPDSFeedHandler implements OPDSConstants {
|
||||||
if (rel == null && MimeType.APP_ATOM_XML.weakEquals(mime)) {
|
if (rel == null && MimeType.APP_ATOM_XML.weakEquals(mime)) {
|
||||||
return ZLNetworkUtil.url(myBaseURL, link.getHref());
|
return ZLNetworkUtil.url(myBaseURL, link.getHref());
|
||||||
}
|
}
|
||||||
if (!BookUrlInfo.isMimeSupported(mime)) {
|
if (!BookUrlInfo.isMimeSupported(mime, opdsLink.Library.SystemInfo)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (rel != null
|
if (rel != null
|
||||||
|
@ -176,7 +176,7 @@ class OPDSFeedHandler extends AbstractOPDSFeedHandler implements OPDSConstants {
|
||||||
final MimeType mime = MimeType.get(link.getType());
|
final MimeType mime = MimeType.get(link.getType());
|
||||||
final String rel = opdsLink.relation(link.getRel(), mime);
|
final String rel = opdsLink.relation(link.getRel(), mime);
|
||||||
if (rel == null
|
if (rel == null
|
||||||
? (BookUrlInfo.isMimeSupported(mime))
|
? (BookUrlInfo.isMimeSupported(mime, opdsLink.Library.SystemInfo))
|
||||||
: (rel.equals(REL_RELATED)
|
: (rel.equals(REL_RELATED)
|
||||||
|| rel.startsWith(REL_ACQUISITION_PREFIX)
|
|| rel.startsWith(REL_ACQUISITION_PREFIX)
|
||||||
|| rel.startsWith(REL_FBREADER_ACQUISITION_PREFIX))) {
|
|| rel.startsWith(REL_FBREADER_ACQUISITION_PREFIX))) {
|
||||||
|
|
|
@ -35,7 +35,7 @@ import org.geometerplus.fbreader.network.urlInfo.*;
|
||||||
import org.geometerplus.fbreader.network.tree.NetworkItemsLoader;
|
import org.geometerplus.fbreader.network.tree.NetworkItemsLoader;
|
||||||
|
|
||||||
public abstract class OPDSNetworkLink extends AbstractNetworkLink {
|
public abstract class OPDSNetworkLink extends AbstractNetworkLink {
|
||||||
protected final NetworkLibrary myLibrary;
|
protected final NetworkLibrary Library;
|
||||||
|
|
||||||
private TreeMap<RelationAlias,String> myRelationAliases;
|
private TreeMap<RelationAlias,String> myRelationAliases;
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ public abstract class OPDSNetworkLink extends AbstractNetworkLink {
|
||||||
OPDSNetworkLink(NetworkLibrary library, int id, String title, String summary, String language,
|
OPDSNetworkLink(NetworkLibrary library, int id, String title, String summary, String language,
|
||||||
UrlInfoCollection<UrlInfoWithDate> infos) {
|
UrlInfoCollection<UrlInfoWithDate> infos) {
|
||||||
super(id, title, summary, language, infos);
|
super(id, title, summary, language, infos);
|
||||||
myLibrary = library;
|
Library = library;
|
||||||
}
|
}
|
||||||
|
|
||||||
final void setRelationAliases(Map<RelationAlias,String> relationAliases) {
|
final void setRelationAliases(Map<RelationAlias,String> relationAliases) {
|
||||||
|
@ -202,7 +202,7 @@ public abstract class OPDSNetworkLink extends AbstractNetworkLink {
|
||||||
public BasketItem getBasketItem() {
|
public BasketItem getBasketItem() {
|
||||||
final String url = getUrl(UrlInfo.Type.ListBooks);
|
final String url = getUrl(UrlInfo.Type.ListBooks);
|
||||||
if (url != null && myBasketItem == null) {
|
if (url != null && myBasketItem == null) {
|
||||||
myBasketItem = new OPDSBasketItem(myLibrary, this);
|
myBasketItem = new OPDSBasketItem(Library, this);
|
||||||
}
|
}
|
||||||
return myBasketItem;
|
return myBasketItem;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,8 +26,7 @@ import android.net.Uri;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.filetypes.FileType;
|
import org.geometerplus.zlibrary.core.filetypes.FileType;
|
||||||
import org.geometerplus.zlibrary.core.filetypes.FileTypeCollection;
|
import org.geometerplus.zlibrary.core.filetypes.FileTypeCollection;
|
||||||
import org.geometerplus.zlibrary.core.util.MimeType;
|
import org.geometerplus.zlibrary.core.util.*;
|
||||||
import org.geometerplus.zlibrary.core.util.MiscUtil;
|
|
||||||
|
|
||||||
import org.geometerplus.fbreader.Paths;
|
import org.geometerplus.fbreader.Paths;
|
||||||
import org.geometerplus.fbreader.formats.PluginCollection;
|
import org.geometerplus.fbreader.formats.PluginCollection;
|
||||||
|
@ -43,7 +42,7 @@ public class BookUrlInfo extends UrlInfo {
|
||||||
|
|
||||||
private static final String TOESCAPE = "<>:\"|?*\\";
|
private static final String TOESCAPE = "<>:\"|?*\\";
|
||||||
|
|
||||||
public static boolean isMimeSupported(MimeType mime) {
|
public static boolean isMimeSupported(MimeType mime, SystemInfo systemInfo) {
|
||||||
if (mime == null) {
|
if (mime == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -51,7 +50,7 @@ public class BookUrlInfo extends UrlInfo {
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return PluginCollection.Instance().getPlugin(type) != null;
|
return PluginCollection.Instance(systemInfo).getPlugin(type) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int mimePriority(MimeType mime) {
|
private static int mimePriority(MimeType mime) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue