diff options
author | Teus Benschop <teusjannette@gmail.com> | 2018-11-10 21:10:09 +0700 |
---|---|---|
committer | Teus Benschop <teusjannette@gmail.com> | 2018-11-10 21:10:09 +0700 |
commit | 2a58bdf9b682f462b63be719fc441a679f7d52f3 (patch) | |
tree | 4b8fce727ab045eef1a846659bb90f18719477e6 /bindings/java-jni/jni/swordstub.cpp | |
parent | 018216c25c73b221df0810e6c909623abd46c321 (diff) | |
parent | 70090da73f95ee90e15650d853744526b5f47e68 (diff) |
Record sword (1.8.1+dfsg-7) in archive suite sid
Diffstat (limited to 'bindings/java-jni/jni/swordstub.cpp')
-rw-r--r-- | bindings/java-jni/jni/swordstub.cpp | 858 |
1 files changed, 669 insertions, 189 deletions
diff --git a/bindings/java-jni/jni/swordstub.cpp b/bindings/java-jni/jni/swordstub.cpp index 435a3f1..8a53f34 100644 --- a/bindings/java-jni/jni/swordstub.cpp +++ b/bindings/java-jni/jni/swordstub.cpp @@ -2,7 +2,7 @@ * * swordstub.cpp - JNI bindings * - * $Id: swordstub.cpp 3184 2014-04-17 04:30:54Z greg.hellings $ + * $Id: swordstub.cpp 3524 2017-11-07 03:08:49Z scribe $ * * Copyright 2009-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society @@ -37,6 +37,14 @@ #include <localemgr.h> #include <treekeyidx.h> #include <installmgr.h> +#include <remotetrans.h> +#include <rtfhtml.h> +//#include <android/native_activity.h> + + +#ifdef BIBLESYNC +#include <biblesync.hh> +#endif #include "webmgr.hpp" #include "org_crosswire_android_sword_SWMgr.h" @@ -50,10 +58,69 @@ using std::vector; using namespace sword; - +namespace { WebMgr *mgr = 0; InstallMgr *installMgr = 0; +#ifdef BIBLESYNC +BibleSync *bibleSync = 0; +using std::string; +jobject bibleSyncListener = 0; +JNIEnv *bibleSyncListenerEnv = 0; +#endif +static SWBuf STORAGE_BASE; +static char *SWORD_PATH = "/sdcard/sword"; +static char *AND_BIBLE_MODULES_PATH = "/sdcard/Android/data/net.bible.android.activity/files"; +//ANativeActivity *_activity; + +class InstallStatusReporter : public StatusReporter { +public: + JNIEnv *env; + jobject callback; + unsigned long last; + + InstallStatusReporter() : env(0), callback(0), last(0) { + } + + void init(JNIEnv *env, jobject callback) { + this->env = env; + this->callback = callback; + last = 0xffffffff; + } + + virtual void update(unsigned long totalBytes, unsigned long completedBytes) { + + // assert we have a callback + if (!callback) return; + + if (completedBytes != last) { + last = completedBytes; + jclass cls = env->GetObjectClass(callback); + jmethodID mid = env->GetMethodID(cls, "update", "(JJ)V"); + if (mid != 0) { + env->CallVoidMethod(callback, mid, (jlong)totalBytes, (jlong)completedBytes); + } + env->DeleteLocalRef(cls); + } + } + + virtual void preStatus(long totalBytes, long completedBytes, const char *message) { + + // assert we have a callback + if (!callback) return; + + jclass cls = env->GetObjectClass(callback); + jmethodID mid = env->GetMethodID(cls, "preStatus", "(JJLjava/lang/String;)V"); + if (mid != 0) { + jstring msg = env->NewStringUTF(assureValidUTF8((const char *)message)); + env->CallVoidMethod(callback, mid, (jlong)totalBytes, (jlong)completedBytes, msg); + env->DeleteLocalRef(msg); + } + env->DeleteLocalRef(cls); + } +} *installStatusReporter = 0; +bool disclaimerConfirmed = false; + class AndroidLogger : public SWLog { vector<int> levelMapping; public: @@ -73,50 +140,140 @@ public: }; -static void init() { +static void init(JNIEnv *env) { if (!mgr) { SWLog::setSystemLog(new AndroidLogger()); SWLog::getSystemLog()->setLogLevel(SWLog::LOG_DEBUG); - SWBuf baseDir = "/sdcard/sword"; +SWLog::getSystemLog()->logDebug("libsword: init() begin"); + SWBuf baseDir = SWORD_PATH; SWBuf confPath = baseDir + "/mods.d/globals.conf"; // be sure we have at least some config file already out there if (!FileMgr::existsFile(confPath.c_str())) { + SWLog::getSystemLog()->logDebug("libsword: init() sword config not found, attempting to create parent of: %s", confPath.c_str()); + FileMgr::createParent(confPath.c_str()); + remove(confPath.c_str()); + + SWLog::getSystemLog()->logDebug("libsword: init() saving basic: %s", confPath.c_str()); + SWConfig config(confPath.c_str()); + config["Globals"]["HiAndroid"] = "weeee"; + config.save(); + } + if (!FileMgr::existsFile(confPath.c_str())) { + baseDir = STORAGE_BASE; + confPath = baseDir + "/mods.d/globals.conf"; +SWLog::getSystemLog()->logDebug("libsword: init() sword config STILL not found, attempting to create parent of: %s", confPath.c_str()); FileMgr::createParent(confPath.c_str()); remove(confPath.c_str()); +SWLog::getSystemLog()->logDebug("libsword: init() saving basic: %s", confPath.c_str()); SWConfig config(confPath.c_str()); config["Globals"]["HiAndroid"] = "weeee"; - config.Save(); + config.save(); } - mgr = new WebMgr("/sdcard/sword"); + confPath = STORAGE_BASE + "/extraConfig.conf"; + bool exists = FileMgr::existsFile(confPath.c_str()); +SWLog::getSystemLog()->logDebug("libsword: extraConfig %s at path: %s", exists?"Exists":"Absent", confPath.c_str()); + +SWLog::getSystemLog()->logDebug("libsword: init() creating WebMgr using path: %s", baseDir.c_str()); + mgr = new WebMgr(baseDir, exists?confPath.c_str():0); + +SWLog::getSystemLog()->logDebug("libsword: init() augmenting modules from: %s", AND_BIBLE_MODULES_PATH); + // for And Bible modules + mgr->augmentModules(AND_BIBLE_MODULES_PATH, true); } } +static void initInstall(JNIEnv *env, jobject progressReporter = 0) { -static void initInstall() { - + if (!installStatusReporter) { + installStatusReporter = new InstallStatusReporter(); + } + installStatusReporter->init(env, progressReporter); if (!installMgr) { - SWBuf baseDir = "/sdcard/sword/InstallMgr"; +SWLog::getSystemLog()->logDebug("initInstall: installMgr is null"); + SWBuf baseDir = SWORD_PATH; + baseDir += "/InstallMgr"; SWBuf confPath = baseDir + "/InstallMgr.conf"; // be sure we have at least some config file already out there +SWLog::getSystemLog()->logDebug("initInstall: confPath: %s", confPath.c_str()); if (!FileMgr::existsFile(confPath.c_str())) { + SWLog::getSystemLog()->logDebug("initInstall: file doesn't exist: %s", confPath.c_str()); FileMgr::createParent(confPath.c_str()); - remove(confPath.c_str()); - SWConfig config(confPath.c_str()); config["General"]["PassiveFTP"] = "true"; - config.Save(); + config.save(); + } + if (!FileMgr::existsFile(confPath.c_str())) { + baseDir = STORAGE_BASE; + confPath = baseDir + "/InstallMgr.conf"; + SWLog::getSystemLog()->logDebug("initInstall: file STILL doesn't exist, attempting to create parent of: %s", confPath.c_str()); + FileMgr::createParent(confPath.c_str()); + SWConfig config(confPath.c_str()); + config["General"]["PassiveFTP"] = "true"; + config.save(); + } + installMgr = new InstallMgr(baseDir, installStatusReporter); + if (disclaimerConfirmed) installMgr->setUserDisclaimerConfirmed(true); +SWLog::getSystemLog()->logDebug("initInstall: instantiated InstallMgr with baseDir: %s", baseDir.c_str()); + } +} + +#ifdef BIBLESYNC +void bibleSyncCallback(char cmd, string bible, string ref, string alt, string group, string domain, string info, string dump) { +SWLog::getSystemLog()->logDebug("bibleSync callback msg: %c; bible: %s; ref: %s; alt: %s; group: %s; domain: %s; info: %s; dump: %s", cmd, bible.c_str(), ref.c_str(), alt.c_str(), group.c_str(), domain.c_str(), info.c_str(), dump.c_str()); + if (::bibleSyncListener) { +SWLog::getSystemLog()->logDebug("bibleSync listener is true"); + jclass cls = bibleSyncListenerEnv->GetObjectClass(::bibleSyncListener); + jmethodID mid = bibleSyncListenerEnv->GetMethodID(cls, "messageReceived", "(Ljava/lang/String;)V"); +SWLog::getSystemLog()->logDebug("bibleSync listener mid: %ld", mid); + if (mid) { +SWLog::getSystemLog()->logDebug("bibleSync listener mid is available"); + switch(cmd) { + // error + case 'E': + // mismatch + case 'M': + // new speaker + case 'S': + // dead speaker + case 'D': + // announce + case 'A': + break; + // navigation + case 'N': +SWLog::getSystemLog()->logDebug("bibleSync Nav Received: %s", ref.c_str()); + jstring msg = bibleSyncListenerEnv->NewStringUTF(ref.c_str()); + bibleSyncListenerEnv->CallVoidMethod(::bibleSyncListener, mid, msg); + bibleSyncListenerEnv->DeleteLocalRef(msg); + break; + } } - installMgr = new InstallMgr(baseDir); +SWLog::getSystemLog()->logDebug("bibleSync listener deleting local ref to cls"); + bibleSyncListenerEnv->DeleteLocalRef(cls); + } +} +#endif + + +static void initBibleSync() { +#ifdef BIBLESYNC + if (!bibleSync) { +SWLog::getSystemLog()->logDebug("bibleSync initializing c-tor"); + bibleSync = new BibleSync("SWORD", (const char *)SWVersion().currentVersion, "SwordUser"); +SWLog::getSystemLog()->logDebug("bibleSync initializing setMode"); + bibleSync->setMode(BSP_MODE_PERSONAL, bibleSyncCallback, "passphrase"); } +#endif } +} JNIEXPORT jstring JNICALL Java_org_crosswire_android_sword_SWMgr_version - (JNIEnv *env, jobject me) { + (JNIEnv *env, jobject me) { - init(); + init(env); SWVersion v; return env->NewStringUTF(v.currentVersion); @@ -129,7 +286,15 @@ JNIEXPORT jstring JNICALL Java_org_crosswire_android_sword_SWMgr_version * Signature: ()V */ JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWMgr_reInit - (JNIEnv *, jobject) { + (JNIEnv *env, jobject me) { + + jclass swmgrClass = env->GetObjectClass(me); + jmethodID getStorageBasePath = env->GetMethodID(swmgrClass, "getStorageBasePath", "()Ljava/lang/String;"); + jstring basePathJS = (jstring)env->CallObjectMethod(me, getStorageBasePath, NULL); + + const char *basePath = (basePathJS?env->GetStringUTFChars(basePathJS, NULL):0); + STORAGE_BASE = basePath; + SWLog::getSystemLog()->logDebug("setting STORAGE_BASE to: %s", STORAGE_BASE.c_str()); delete mgr; mgr = 0; @@ -137,26 +302,26 @@ JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWMgr_reInit JNIEXPORT jstring JNICALL Java_org_crosswire_android_sword_SWMgr_getPrefixPath - (JNIEnv *env, jobject me) { + (JNIEnv *env, jobject me) { - init(); + init(env); return env->NewStringUTF(mgr->prefixPath); } JNIEXPORT jstring JNICALL Java_org_crosswire_android_sword_SWMgr_getConfigPath - (JNIEnv *env, jobject me) { + (JNIEnv *env, jobject me) { - init(); + init(env); return env->NewStringUTF(mgr->configPath); } JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_SWMgr_getModInfoList - (JNIEnv *env, jobject) { + (JNIEnv *env, jobject) { - init(); + init(env); int size = 0; for (sword::ModMap::iterator it = mgr->Modules.begin(); it != mgr->Modules.end(); ++it) { @@ -211,15 +376,15 @@ SWLog::getSystemLog()->logDebug("getModInfoList returning %d length array\n", si * Signature: (Ljava/lang/String;)Lorg/crosswire/android/sword/SWModule; */ JNIEXPORT jobject JNICALL Java_org_crosswire_android_sword_SWMgr_getModuleByName - (JNIEnv *env, jobject me, jstring modNameJS) { + (JNIEnv *env, jobject me, jstring modNameJS) { - init(); + init(env); jobject retVal = 0; - const char *modName = env->GetStringUTFChars(modNameJS, NULL); + const char *modName = env->GetStringUTFChars(modNameJS, NULL); sword::SWModule *module = mgr->getModule(modName); - env->ReleaseStringUTFChars(modNameJS, modName); + env->ReleaseStringUTFChars(modNameJS, modName); if (module) { SWBuf type = module->getType(); @@ -242,17 +407,17 @@ JNIEXPORT jobject JNICALL Java_org_crosswire_android_sword_SWMgr_getModuleByName * Signature: (Ljava/lang/String;Ljava/lang/String;)V */ JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWMgr_setGlobalOption - (JNIEnv *env, jobject me, jstring optionJS, jstring valueJS) { + (JNIEnv *env, jobject me, jstring optionJS, jstring valueJS) { - init(); + init(env); - const char *option = env->GetStringUTFChars(optionJS, NULL); - const char *value = env->GetStringUTFChars(valueJS, NULL); + const char *option = env->GetStringUTFChars(optionJS, NULL); + const char *value = env->GetStringUTFChars(valueJS, NULL); mgr->setGlobalOption(option, value); - env->ReleaseStringUTFChars(valueJS, value); - env->ReleaseStringUTFChars(optionJS, option); + env->ReleaseStringUTFChars(valueJS, value); + env->ReleaseStringUTFChars(optionJS, option); } @@ -262,15 +427,15 @@ JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWMgr_setGlobalOption * Signature: (Ljava/lang/String;)Ljava/lang/String; */ JNIEXPORT jstring JNICALL Java_org_crosswire_android_sword_SWMgr_getGlobalOption - (JNIEnv *env, jobject me, jstring optionJS) { + (JNIEnv *env, jobject me, jstring optionJS) { - init(); + init(env); - const char *option = env->GetStringUTFChars(optionJS, NULL); + const char *option = env->GetStringUTFChars(optionJS, NULL); SWBuf value = mgr->getGlobalOption(option); - env->ReleaseStringUTFChars(optionJS, option); + env->ReleaseStringUTFChars(optionJS, option); return env->NewStringUTF(assureValidUTF8(value)); } @@ -282,15 +447,15 @@ JNIEXPORT jstring JNICALL Java_org_crosswire_android_sword_SWMgr_getGlobalOption * Signature: (Ljava/lang/String;)Ljava/lang/String; */ JNIEXPORT jstring JNICALL Java_org_crosswire_android_sword_SWMgr_getGlobalOptionTip - (JNIEnv *env, jobject me, jstring optionJS) { + (JNIEnv *env, jobject me, jstring optionJS) { - init(); + init(env); - const char *option = env->GetStringUTFChars(optionJS, NULL); + const char *option = env->GetStringUTFChars(optionJS, NULL); SWBuf value = mgr->getGlobalOptionTip(option); - env->ReleaseStringUTFChars(optionJS, option); + env->ReleaseStringUTFChars(optionJS, option); return env->NewStringUTF(assureValidUTF8(value)); } @@ -302,20 +467,20 @@ JNIEXPORT jstring JNICALL Java_org_crosswire_android_sword_SWMgr_getGlobalOption * Signature: (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String; */ JNIEXPORT jstring JNICALL Java_org_crosswire_android_sword_SWMgr_filterText - (JNIEnv *env, jobject me, jstring filterNameJS, jstring textJS) { + (JNIEnv *env, jobject me, jstring filterNameJS, jstring textJS) { - init(); + init(env); - const char *filterName = env->GetStringUTFChars(filterNameJS, NULL); - const char *text = env->GetStringUTFChars(textJS, NULL); + const char *filterName = env->GetStringUTFChars(filterNameJS, NULL); + const char *text = env->GetStringUTFChars(textJS, NULL); SWBuf buf = text; // hmmm, in the future, provide a param to specify filter value maybe? mgr->setGlobalOption("Greek Accents", "Off"); char errStatus = mgr->filterText(filterName, buf); - env->ReleaseStringUTFChars(textJS, text); - env->ReleaseStringUTFChars(filterNameJS, filterName); + env->ReleaseStringUTFChars(textJS, text); + env->ReleaseStringUTFChars(filterNameJS, filterName); return env->NewStringUTF(assureValidUTF8(buf)); } @@ -327,9 +492,9 @@ JNIEXPORT jstring JNICALL Java_org_crosswire_android_sword_SWMgr_filterText * Signature: ()[Ljava/lang/String; */ JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_SWMgr_getGlobalOptions - (JNIEnv *env, jobject me) { + (JNIEnv *env, jobject me) { - init(); + init(env); sword::StringList options = mgr->getGlobalOptions(); int count = 0; @@ -351,19 +516,239 @@ JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_SWMgr_getGlobalO /* * Class: org_crosswire_android_sword_SWMgr + * Method: getExtraConfigSections + * Signature: ()[Ljava/lang/String; + */ +JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_SWMgr_getExtraConfigSections + (JNIEnv *env, jobject me) { + + init(env); + + SWBuf baseDir = STORAGE_BASE; + SWBuf confPath = baseDir + "/extraConfig.conf"; + int count = 0; + bool exists = FileMgr::existsFile(confPath.c_str()); + jclass clazzString = env->FindClass("java/lang/String"); + jobjectArray ret; + SWLog::getSystemLog()->logDebug("libsword: extraConfig %s at path: %s", exists?"Exists":"Absent", confPath.c_str()); + if (exists) { + SWConfig config(confPath.c_str()); + SectionMap::const_iterator sit; + for (sit = config.getSections().begin(); sit != config.getSections().end(); ++sit) { + count++; + } + SWLog::getSystemLog()->logDebug("libsword: %d sections found in extraConfig", count); + ret = (jobjectArray) env->NewObjectArray(count, clazzString, NULL); + count = 0; + for (sit = config.getSections().begin(); sit != config.getSections().end(); ++sit) { + env->SetObjectArrayElement(ret, count++, env->NewStringUTF(assureValidUTF8(sit->first.c_str()))); + } + } + else { + ret = (jobjectArray) env->NewObjectArray(0, clazzString, NULL); + } + + return ret; +} + + +/* + * Class: org_crosswire_android_sword_SWMgr + * Method: getExtraConfigKeys + * Signature: (Ljava/lang/String;)[Ljava/lang/String; + */ +JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_SWMgr_getExtraConfigKeys + (JNIEnv *env, jobject me, jstring section) { + + init(env); + + const char *s = env->GetStringUTFChars(section, NULL); + + SWBuf mySection = s; + + env->ReleaseStringUTFChars(section, s); + + SWBuf baseDir = STORAGE_BASE; + SWBuf confPath = baseDir + "/extraConfig.conf"; + int count = 0; + bool exists = FileMgr::existsFile(confPath.c_str()); + jclass clazzString = env->FindClass("java/lang/String"); + jobjectArray ret; + if (exists) { + SWConfig config(confPath.c_str()); + SectionMap::const_iterator sit = config.getSections().find(mySection.c_str()); + if (sit != config.getSections().end()) { + ConfigEntMap::const_iterator it; + for (it = sit->second.begin(); it != sit->second.end(); ++it) { + count++; + } + ret = (jobjectArray) env->NewObjectArray(count, clazzString, NULL); + count = 0; + for (it = sit->second.begin(); it != sit->second.end(); ++it) { + env->SetObjectArrayElement(ret, count++, + env->NewStringUTF(assureValidUTF8(it->first.c_str()))); + } + } + else { + ret = (jobjectArray) env->NewObjectArray(0, clazzString, NULL); + } + } + else { + ret = (jobjectArray) env->NewObjectArray(0, clazzString, NULL); + } + + return ret; +} + + +/* + * Class: org_crosswire_android_sword_SWMgr + * Method: getExtraConfigValue + * Signature: (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_crosswire_android_sword_SWMgr_getExtraConfigValue + (JNIEnv *env, jobject me, jstring section, jstring key) { + + init(env); + + const char *s = env->GetStringUTFChars(section, NULL); + + SWBuf mySection = s; + + env->ReleaseStringUTFChars(section, s); + + const char *k = env->GetStringUTFChars(key, NULL); + + SWBuf myKey = k; + + env->ReleaseStringUTFChars(key, k); + + jstring ret = 0; + + SWBuf baseDir = STORAGE_BASE; + SWBuf confPath = baseDir + "/extraConfig.conf"; + bool exists = FileMgr::existsFile(confPath.c_str()); + if (exists) { + SWConfig config(confPath.c_str()); + SectionMap::const_iterator sit = config.getSections().find(mySection.c_str()); + if (sit != config.getSections().end()) { + ConfigEntMap::const_iterator it = sit->second.find(myKey.c_str()); + if (it != sit->second.end()) { + ret = env->NewStringUTF(assureValidUTF8(it->second.c_str())); + } + } + } + + return ret; +} + + +/* + * Class: org_crosswire_android_sword_SWMgr + * Method: setExtraConfigValue + * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWMgr_setExtraConfigValue + (JNIEnv *env, jobject me, jstring section, jstring key, jstring value) { + + init(env); + + const char *s = env->GetStringUTFChars(section, NULL); + + SWBuf mySection = s; + + env->ReleaseStringUTFChars(section, s); + + const char *k = env->GetStringUTFChars(key, NULL); + + SWBuf myKey = k; + + env->ReleaseStringUTFChars(key, k); + + const char *v = env->GetStringUTFChars(value, NULL); + + SWBuf myValue = v; + + env->ReleaseStringUTFChars(value, v); + + SWBuf baseDir = STORAGE_BASE; + SWBuf confPath = baseDir + "/extraConfig.conf"; + SWConfig config(confPath.c_str()); + config[mySection][myKey] = myValue; + config.save(); + + Java_org_crosswire_android_sword_SWMgr_reInit(env, me); + +} + + +/* + * Class: org_crosswire_android_sword_SWMgr + * Method: addExtraConfig + * Signature: (Ljava/lang/String;)[Ljava/lang/String; + */ +JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_SWMgr_addExtraConfig + (JNIEnv *env, jobject me, jstring blob) { + + init(env); + + const char *b = env->GetStringUTFChars(blob, NULL); + + SWBuf myBlob = b; + + env->ReleaseStringUTFChars(blob, b); + + jobjectArray ret; + + int count = 0; + jclass clazzString = env->FindClass("java/lang/String"); + + SWBuf baseDir = STORAGE_BASE; + SWBuf tmpConfPath = baseDir + "/tmpConfig.conf"; + FileMgr::removeFile(tmpConfPath.c_str()); + FileDesc *fd = FileMgr::getSystemFileMgr()->open(tmpConfPath.c_str(), FileMgr::CREAT|FileMgr::WRONLY, FileMgr::IREAD|FileMgr::IWRITE); + fd->getFd(); + fd->write(myBlob.c_str(), myBlob.size()); + FileMgr::getSystemFileMgr()->close(fd); + + SWConfig newConfig(tmpConfPath.c_str()); + FileMgr::removeFile(tmpConfPath.c_str()); + SectionMap::const_iterator sit; + for (sit = newConfig.getSections().begin(); sit != newConfig.getSections().end(); ++sit) { + count++; + } + ret = (jobjectArray) env->NewObjectArray(count, clazzString, NULL); + count = 0; + for (sit = newConfig.getSections().begin(); sit != newConfig.getSections().end(); ++sit) { + env->SetObjectArrayElement(ret, count++, env->NewStringUTF(assureValidUTF8(sit->first.c_str()))); + } + + SWBuf confPath = baseDir + "/extraConfig.conf"; + SWConfig config(confPath.c_str()); + config.augment(newConfig); + config.save(); + + Java_org_crosswire_android_sword_SWMgr_reInit(env, me); + + return ret; +} + + +/* + * Class: org_crosswire_android_sword_SWMgr * Method: getGlobalOptionValues * Signature: (Ljava/lang/String;)[Ljava/lang/String; */ JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_SWMgr_getGlobalOptionValues - (JNIEnv *env, jobject me, jstring optionJS) { + (JNIEnv *env, jobject me, jstring optionJS) { - init(); + init(env); - const char *option = env->GetStringUTFChars(optionJS, NULL); + const char *option = env->GetStringUTFChars(optionJS, NULL); sword::StringList options = mgr->getGlobalOptionValues(option); - env->ReleaseStringUTFChars(optionJS, option); + env->ReleaseStringUTFChars(optionJS, option); int count = 0; for (sword::StringList::iterator it = options.begin(); it != options.end(); ++it) { @@ -387,17 +772,17 @@ JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_SWMgr_getGlobalO * Signature: (Ljava/lang/String;Ljava/lang/String;)V */ JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWMgr_setCipherKey - (JNIEnv *env, jobject me , jstring modNameJS, jstring keyJS) { + (JNIEnv *env, jobject me , jstring modNameJS, jstring keyJS) { - init(); + init(env); - const char *modName = env->GetStringUTFChars(modNameJS, NULL); - const char *key = env->GetStringUTFChars(keyJS, NULL); + const char *modName = env->GetStringUTFChars(modNameJS, NULL); + const char *key = env->GetStringUTFChars(keyJS, NULL); mgr->setCipherKey(modName, key); - env->ReleaseStringUTFChars(keyJS, key); - env->ReleaseStringUTFChars(modNameJS, modName); + env->ReleaseStringUTFChars(keyJS, key); + env->ReleaseStringUTFChars(modNameJS, modName); } @@ -407,9 +792,9 @@ JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWMgr_setCipherKey * Signature: (Z)V */ JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWMgr_setJavascript - (JNIEnv *env, jobject me, jboolean val) { + (JNIEnv *env, jobject me, jboolean val) { - init(); + init(env); mgr->setJavascript(val == JNI_TRUE); } @@ -421,9 +806,9 @@ JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWMgr_setJavascript * Signature: ()[Ljava/lang/String; */ JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_SWMgr_getAvailableLocales - (JNIEnv *env, jobject me) { + (JNIEnv *env, jobject me) { - init(); + init(env); sword::StringList localeNames = LocaleMgr::getSystemLocaleMgr()->getAvailableLocales(); int count = 0; @@ -448,15 +833,15 @@ JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_SWMgr_getAvailab * Signature: (Ljava/lang/String;)V */ JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWMgr_setDefaultLocale - (JNIEnv *env, jobject me, jstring localeNameJS) { + (JNIEnv *env, jobject me, jstring localeNameJS) { - init(); + init(env); - const char *localeName = env->GetStringUTFChars(localeNameJS, NULL); + const char *localeName = env->GetStringUTFChars(localeNameJS, NULL); LocaleMgr::getSystemLocaleMgr()->setDefaultLocaleName(localeName); - env->ReleaseStringUTFChars(localeNameJS, localeName); + env->ReleaseStringUTFChars(localeNameJS, localeName); } @@ -464,9 +849,10 @@ JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWMgr_setDefaultLocale // SWModule methods ---------------------------------------------------------------------------------- -SWModule *getModule(JNIEnv *env, jobject me) { +SWModule *getModule + (JNIEnv *env, jobject me) { - init(); + init(env); SWModule *module = 0; jclass clazzSWModule = env->FindClass("org/crosswire/android/sword/SWModule"); @@ -474,10 +860,10 @@ SWModule *getModule(JNIEnv *env, jobject me) { jfieldID sourceFieldID = env->GetFieldID(clazzSWModule, "remoteSourceName", "Ljava/lang/String;"); jstring modNameJS = (jstring)env->GetObjectField(me, fieldID); jstring sourceNameJS = (jstring)env->GetObjectField(me, sourceFieldID); - const char *modName = (modNameJS?env->GetStringUTFChars(modNameJS, NULL):0); - const char *sourceName = (sourceNameJS?env->GetStringUTFChars(sourceNameJS, NULL):0); + const char *modName = (modNameJS?env->GetStringUTFChars(modNameJS, NULL):0); + const char *sourceName = (sourceNameJS?env->GetStringUTFChars(sourceNameJS, NULL):0); if (sourceName && *sourceName) { - initInstall(); + initInstall(env); InstallSourceMap::iterator source = installMgr->sources.find(sourceName); if (source == installMgr->sources.end()) { SWMgr *mgr = source->second->getMgr(); @@ -485,8 +871,8 @@ SWModule *getModule(JNIEnv *env, jobject me) { } } else module = mgr->getModule(modName); - if (modName) env->ReleaseStringUTFChars(modNameJS, modName); - if (sourceName) env->ReleaseStringUTFChars(sourceNameJS, sourceName); + if (modName) env->ReleaseStringUTFChars(modNameJS, modName); + if (sourceName) env->ReleaseStringUTFChars(sourceNameJS, sourceName); return module; } @@ -496,9 +882,9 @@ SWModule *getModule(JNIEnv *env, jobject me) { * Signature: (Ljava/lang/String;)V */ JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWModule_setKeyText - (JNIEnv *env, jobject me, jstring keyTextJS) { + (JNIEnv *env, jobject me, jstring keyTextJS) { - init(); + init(env); SWModule *module = getModule(env, me); @@ -509,7 +895,9 @@ SWLog::getSystemLog()->logDebug("setKeyText(%s, %s)", module->getName(), keyText sword::VerseKey *vkey = SWDYNAMIC_CAST(VerseKey, key); if (vkey && (*keyText=='+' ||*keyText=='-')) { if (!stricmp(keyText+1, "book")) { - vkey->setBook(vkey->getBook() + ((*keyText=='+')?1:-1)); + int newBook = vkey->getBook() + ((*keyText=='+')?1:-1); +SWLog::getSystemLog()->logDebug("setting book to %d", newBook); + vkey->setBook(newBook); env->ReleaseStringUTFChars(keyTextJS, keyText); return; } @@ -532,9 +920,9 @@ SWLog::getSystemLog()->logDebug("setKeyText(%s, %s)", module->getName(), keyText * Signature: ()Ljava/lang/String; */ JNIEXPORT jstring JNICALL Java_org_crosswire_android_sword_SWModule_getKeyText - (JNIEnv *env, jobject me) { + (JNIEnv *env, jobject me) { - init(); + init(env); SWModule *module = getModule(env, me); @@ -552,9 +940,9 @@ JNIEXPORT jstring JNICALL Java_org_crosswire_android_sword_SWModule_getKeyText * Signature: ()Ljava/lang/String; */ JNIEXPORT jstring JNICALL Java_org_crosswire_android_sword_SWModule_getRenderText - (JNIEnv *env, jobject me) { + (JNIEnv *env, jobject me) { - init(); + init(env); SWModule *module = getModule(env, me); @@ -568,13 +956,33 @@ JNIEXPORT jstring JNICALL Java_org_crosswire_android_sword_SWModule_getRenderTex /* * Class: org_crosswire_android_sword_SWModule + * Method: getRenderHeader + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_crosswire_android_sword_SWModule_getRenderHeader + (JNIEnv *env, jobject me) { + + init(env); + + SWModule *module = getModule(env, me); + + jstring retVal = 0; + if (module) { + retVal = env->NewStringUTF(assureValidUTF8(((const char *)(module->getRenderHeader() ? module->getRenderHeader():"")))); + } + return retVal; +} + + +/* + * Class: org_crosswire_android_sword_SWModule * Method: terminateSearch * Signature: ()V */ JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWModule_terminateSearch - (JNIEnv *env, jobject me) { + (JNIEnv *env, jobject me) { - init(); + init(env); SWModule *module = getModule(env, me); @@ -590,13 +998,14 @@ JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWModule_terminateSearch * Signature: ()C */ JNIEXPORT jchar JNICALL Java_org_crosswire_android_sword_SWModule_error - (JNIEnv *env, jobject me) { + (JNIEnv *env, jobject me) { - init(); + init(env); SWModule *module = getModule(env, me); - return (module) ? module->popError() : -99; + int error = (module) ? module->popError() : -99; + return error; } @@ -606,9 +1015,9 @@ JNIEXPORT jchar JNICALL Java_org_crosswire_android_sword_SWModule_error * Signature: ()J */ JNIEXPORT jlong JNICALL Java_org_crosswire_android_sword_SWModule_getEntrySize - (JNIEnv *env, jobject me) { + (JNIEnv *env, jobject me) { - init(); + init(env); SWModule *module = getModule(env, me); @@ -622,9 +1031,9 @@ JNIEXPORT jlong JNICALL Java_org_crosswire_android_sword_SWModule_getEntrySize * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Z)[Ljava/lang/String; */ JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_SWModule_getEntryAttribute - (JNIEnv *env, jobject me, jstring level1JS, jstring level2JS, jstring level3JS, jboolean filteredJS) { + (JNIEnv *env, jobject me, jstring level1JS, jstring level2JS, jstring level3JS, jboolean filteredJS) { - init(); + init(env); const char *level1 = env->GetStringUTFChars(level1JS, NULL); const char *level2 = env->GetStringUTFChars(level2JS, NULL); @@ -646,7 +1055,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_SWModule_getEntr sword::AttributeList::iterator i2Start, i2End; sword::AttributeValue::iterator i3Start, i3End; - if ((level1) && (*level1)) { + if ((level1) && (*level1) && *level1 != '-') { i1Start = entryAttribs.find(level1); i1End = i1Start; if (i1End != entryAttribs.end()) @@ -657,35 +1066,54 @@ JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_SWModule_getEntr i1End = entryAttribs.end(); } for (;i1Start != i1End; ++i1Start) { - if ((level2) && (*level2)) { - i2Start = i1Start->second.find(level2); - i2End = i2Start; - if (i2End != i1Start->second.end()) - ++i2End; + if (level1 && *level1 && *level1 == '-') { + results.push_back(i1Start->first); } else { - i2Start = i1Start->second.begin(); - i2End = i1Start->second.end(); - } - for (;i2Start != i2End; ++i2Start) { - if ((level3) && (*level3)) { - i3Start = i2Start->second.find(level3); - i3End = i3Start; - if (i3End != i2Start->second.end()) - ++i3End; + if (level2 && *level2 && *level2 != '-') { + i2Start = i1Start->second.find(level2); + i2End = i2Start; + if (i2End != i1Start->second.end()) + ++i2End; } else { - i3Start = i2Start->second.begin(); - i3End = i2Start->second.end(); + i2Start = i1Start->second.begin(); + i2End = i1Start->second.end(); } - for (;i3Start != i3End; ++i3Start) { - results.push_back(i3Start->second); + for (;i2Start != i2End; ++i2Start) { + if (level2 && *level2 && *level2 == '-') { + results.push_back(i2Start->first); + } + else { + // allow '-' to get all keys; allow '*' to get all key=value + if (level3 && *level3 && *level3 != '-' && *level3 != '*') { + i3Start = i2Start->second.find(level3); + i3End = i3Start; + if (i3End != i2Start->second.end()) + ++i3End; + } + else { + i3Start = i2Start->second.begin(); + i3End = i2Start->second.end(); + } + for (;i3Start != i3End; ++i3Start) { + if (level3 && *level3 && *level3 == '-') { + results.push_back(i3Start->first); + } + else if (level3 && *level3 && *level3 == '*') { + results.push_back(i3Start->first + "=" + i3Start->second); + } + else { + results.push_back(i3Start->second); + } + } + if (i3Start != i3End) + break; + } } - if (i3Start != i3End) + if (i2Start != i2End) break; } - if (i2Start != i2End) - break; } ret = (jobjectArray) env->NewObjectArray(results.size(), clazzString, NULL); @@ -716,9 +1144,9 @@ SWLog::getSystemLog()->logDebug("getEntryAttributes: size returned: %d", results * Signature: (Ljava/lang/String;)[Ljava/lang/String; */ JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_SWModule_parseKeyList - (JNIEnv *env, jobject me, jstring keyListTextJS) { + (JNIEnv *env, jobject me, jstring keyListTextJS) { - init(); + init(env); const char *keyListText = env->GetStringUTFChars(keyListTextJS, NULL); @@ -761,9 +1189,9 @@ JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_SWModule_parseKe * Signature: ()Z */ JNIEXPORT jboolean JNICALL Java_org_crosswire_android_sword_SWModule_hasKeyChildren - (JNIEnv *env, jobject me) { + (JNIEnv *env, jobject me) { - init(); + init(env); SWModule *module = getModule(env, me); @@ -786,9 +1214,9 @@ JNIEXPORT jboolean JNICALL Java_org_crosswire_android_sword_SWModule_hasKeyChild * Signature: ()[Ljava/lang/String; */ JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_SWModule_getKeyChildren - (JNIEnv *env, jobject me) { + (JNIEnv *env, jobject me) { - init(); + init(env); jclass clazzString = env->FindClass("java/lang/String"); @@ -802,7 +1230,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_SWModule_getKeyC sword::VerseKey *vkey = SWDYNAMIC_CAST(VerseKey, key); if (vkey) { - ret = (jobjectArray) env->NewObjectArray(7, clazzString, NULL); + ret = (jobjectArray) env->NewObjectArray(10, clazzString, NULL); SWBuf num; num.appendFormatted("%d", vkey->getTestament()); env->SetObjectArrayElement(ret, 0, env->NewStringUTF(assureValidUTF8(num.c_str()))); @@ -822,6 +1250,9 @@ JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_SWModule_getKeyC num.appendFormatted("%d", vkey->getVerseMax()); env->SetObjectArrayElement(ret, 5, env->NewStringUTF(assureValidUTF8(num.c_str()))); env->SetObjectArrayElement(ret, 6, env->NewStringUTF(assureValidUTF8(vkey->getBookName()))); + env->SetObjectArrayElement(ret, 7, env->NewStringUTF(assureValidUTF8(vkey->getOSISRef()))); + env->SetObjectArrayElement(ret, 8, env->NewStringUTF(assureValidUTF8(vkey->getShortText()))); + env->SetObjectArrayElement(ret, 9, env->NewStringUTF(assureValidUTF8(vkey->getBookAbbrev()))); } else { TreeKeyIdx *tkey = SWDYNAMIC_CAST(TreeKeyIdx, key); @@ -844,8 +1275,8 @@ JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_SWModule_getKeyC } } } - return ret; } + return ret; } @@ -855,9 +1286,9 @@ JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_SWModule_getKeyC * Signature: ()Ljava/lang/String; */ JNIEXPORT jstring JNICALL Java_org_crosswire_android_sword_SWModule_getKeyParent - (JNIEnv *env, jobject me) { + (JNIEnv *env, jobject me) { - init(); + init(env); SWBuf retVal = ""; @@ -885,9 +1316,9 @@ JNIEXPORT jstring JNICALL Java_org_crosswire_android_sword_SWModule_getKeyParent * Signature: ()V */ JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWModule_previous - (JNIEnv *env, jobject me) { + (JNIEnv *env, jobject me) { - init(); + init(env); SWModule *module = getModule(env, me); @@ -904,9 +1335,9 @@ JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWModule_previous * Signature: ()V */ JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWModule_next - (JNIEnv *env, jobject me) { + (JNIEnv *env, jobject me) { - init(); + init(env); SWModule *module = getModule(env, me); @@ -923,9 +1354,9 @@ JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWModule_next * Signature: ()V */ JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWModule_begin - (JNIEnv *env, jobject me) { + (JNIEnv *env, jobject me) { - init(); + init(env); SWModule *module = getModule(env, me); @@ -942,9 +1373,9 @@ JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWModule_begin * Signature: ()Ljava/lang/String; */ JNIEXPORT jstring JNICALL Java_org_crosswire_android_sword_SWModule_getStripText - (JNIEnv *env, jobject me) { + (JNIEnv *env, jobject me) { - init(); + init(env); SWBuf retVal = ""; @@ -965,9 +1396,9 @@ JNIEXPORT jstring JNICALL Java_org_crosswire_android_sword_SWModule_getStripText * Signature: ()Ljava/lang/String; */ JNIEXPORT jstring JNICALL Java_org_crosswire_android_sword_SWModule_getRawEntry - (JNIEnv *env, jobject me) { + (JNIEnv *env, jobject me) { - init(); + init(env); SWBuf retVal = ""; @@ -988,9 +1419,9 @@ JNIEXPORT jstring JNICALL Java_org_crosswire_android_sword_SWModule_getRawEntry * Signature: (Ljava/lang/String;)V */ JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWModule_setRawEntry - (JNIEnv *env, jobject me, jstring newEntryTextJS) { + (JNIEnv *env, jobject me, jstring newEntryTextJS) { - init(); + init(env); const char *newEntryText = env->GetStringUTFChars(newEntryTextJS, NULL); @@ -1005,34 +1436,15 @@ JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWModule_setRawEntry } -jstring newBigString(JNIEnv *env, const char *buf) { - SWBuf str = assureValidUTF8(buf); - jclass stringClass = env->FindClass("java/lang/String"); - jmethodID ctorID = env->GetMethodID(stringClass, "<init>", "([B)V"); - - jstring result; -SWLog::getSystemLog()->logDebug("newBigString: making byte array size: %d", str.size()); - jbyteArray bytes = env->NewByteArray(str.size()); -SWLog::getSystemLog()->logDebug("newBigString: setting array region"); - - env->SetByteArrayRegion(bytes, 0, str.size(), (jbyte *)str.c_str()); -SWLog::getSystemLog()->logDebug("newBigString: newing string"); - result = (jstring)env->NewObject(stringClass, ctorID, bytes); - env->DeleteLocalRef(bytes); -SWLog::getSystemLog()->logDebug("newBigString: returning"); - return result; -} - - /* * Class: org_crosswire_android_sword_SWModule * Method: getConfigEntry * Signature: (Ljava/lang/String;)Ljava/lang/String; */ JNIEXPORT jstring JNICALL Java_org_crosswire_android_sword_SWModule_getConfigEntry - (JNIEnv *env, jobject me, jstring configKeyJS) { + (JNIEnv *env, jobject me, jstring configKeyJS) { - init(); + init(env); jstring retVal = 0; @@ -1043,8 +1455,12 @@ SWLog::getSystemLog()->logDebug("getConfigEntry(%s)\n", configKey); SWModule *module = getModule(env, me); if (module) { - SWBuf about = module->getConfigEntry(configKey); - SWBuf assuredBuf = assureValidUTF8(about.c_str()); + SWBuf confValue = module->getConfigEntry(configKey); + // special processing if we're requesting About-- kindof cheese + if (!strcmp("About", configKey)) { + RTFHTML().processText(confValue); + } + SWBuf assuredBuf = assureValidUTF8(confValue.c_str()); retVal = env->NewStringUTF(assuredBuf.c_str()); } @@ -1060,9 +1476,9 @@ SWLog::getSystemLog()->logDebug("getConfigEntry(%s)\n", configKey); * Signature: ()V */ JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWModule_deleteSearchFramework - (JNIEnv *env, jobject me) { + (JNIEnv *env, jobject me) { - init(); + init(env); SWModule *module = getModule(env, me); @@ -1079,9 +1495,9 @@ JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWModule_deleteSearchFra * Signature: ()Z */ JNIEXPORT jboolean JNICALL Java_org_crosswire_android_sword_SWModule_hasSearchFramework - (JNIEnv *env, jobject me) { + (JNIEnv *env, jobject me) { - init(); + init(env); SWModule *module = getModule(env, me); @@ -1101,6 +1517,9 @@ struct pu { void percentUpdate(char percent, void *userData) { struct pu *p = (struct pu *)userData; + // assert we've actually been given a progressReporter + if (!p->progressReporter) return; + if (percent != p->last) { p->last = percent; jclass cls = p->env->GetObjectClass(p->progressReporter); @@ -1108,6 +1527,7 @@ void percentUpdate(char percent, void *userData) { if (mid != 0) { p->env->CallVoidMethod(p->progressReporter, mid, (jint)percent); } + p->env->DeleteLocalRef(cls); } } @@ -1118,14 +1538,14 @@ void percentUpdate(char percent, void *userData) { * Signature: (Ljava/lang/String;IJLjava/lang/String;Lorg/crosswire/android/sword/SWModule/SearchProgressReporter;)[Lorg/crosswire/android/sword/SWModule/SearchHit; */ JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_SWModule_search - (JNIEnv *env, jobject me, jstring expressionJS, jint srchType, jlong flags, jstring scopeJS, jobject progressReporter) { + (JNIEnv *env, jobject me, jstring expressionJS, jint srchType, jlong flags, jstring scopeJS, jobject progressReporter) { - init(); + init(env); const int MAX_RETURN_COUNT = 999999; const char *expression = env->GetStringUTFChars(expressionJS, NULL); - const char *scope = env->GetStringUTFChars(scopeJS, NULL); + const char *scope = scopeJS ? env->GetStringUTFChars(scopeJS, NULL) : 0; jclass clazzSearchHit = env->FindClass("org/crosswire/android/sword/SWModule$SearchHit"); jobjectArray ret = 0; @@ -1133,7 +1553,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_SWModule_search SWModule *module = getModule(env, me); // TODO: remove this from the stack - struct pu peeuuu(env, progressReporter); + pu *peeuuu = new pu(env, progressReporter); if (module) { sword::ListKey lscope; @@ -1148,10 +1568,12 @@ JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_SWModule_search } *parser = module->getKeyText(); lscope = parser->parseVerseList(scope, *parser, true); - result = module->search(expression, srchType, flags, &lscope, 0, &percentUpdate, &peeuuu); + result = module->search(expression, srchType, flags, &lscope, 0, &percentUpdate, peeuuu); delete parser; } - else result = module->search(expression, srchType, flags, 0, 0, &percentUpdate, &peeuuu); + else result = module->search(expression, srchType, flags, 0, 0, &percentUpdate, peeuuu); + + delete peeuuu; int count = 0; for (result = sword::TOP; !result.popError(); result++) count++; @@ -1187,7 +1609,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_SWModule_search env->DeleteLocalRef(modName); } - env->ReleaseStringUTFChars(scopeJS, scope); + if (scope) env->ReleaseStringUTFChars(scopeJS, scope); env->ReleaseStringUTFChars(expressionJS, expression); return (ret) ? ret : (jobjectArray) env->NewObjectArray(0, clazzSearchHit, NULL); @@ -1204,7 +1626,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_SWModule_search * Signature: ()V */ JNIEXPORT void JNICALL Java_org_crosswire_android_sword_InstallMgr_reInit - (JNIEnv *env, jobject me) { + (JNIEnv *env, jobject me) { delete installMgr; installMgr = 0; @@ -1217,9 +1639,9 @@ JNIEXPORT void JNICALL Java_org_crosswire_android_sword_InstallMgr_reInit * Signature: ()I */ JNIEXPORT jint JNICALL Java_org_crosswire_android_sword_InstallMgr_syncConfig - (JNIEnv *env, jobject me) { + (JNIEnv *env, jobject me) { - initInstall(); + initInstall(env); return installMgr->refreshRemoteSourceConfiguration(); } @@ -1231,10 +1653,10 @@ JNIEXPORT jint JNICALL Java_org_crosswire_android_sword_InstallMgr_syncConfig * Signature: (Ljava/lang/String;)I */ JNIEXPORT jint JNICALL Java_org_crosswire_android_sword_InstallMgr_uninstallModule - (JNIEnv *env, jobject me, jstring modNameJS) { + (JNIEnv *env, jobject me, jstring modNameJS) { - init(); - initInstall(); + init(env); + initInstall(env); const char *modName = env->GetStringUTFChars(modNameJS, NULL); @@ -1260,9 +1682,9 @@ SWLog::getSystemLog()->logDebug("uninstallModule %s\n", modName); * Signature: ()[Ljava/lang/String; */ JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_InstallMgr_getRemoteSources - (JNIEnv *env, jobject me) { + (JNIEnv *env, jobject me) { - initInstall(); + initInstall(env); jclass clazzString = env->FindClass("java/lang/String"); jobjectArray ret; @@ -1271,6 +1693,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_InstallMgr_getRe for (InstallSourceMap::iterator it = installMgr->sources.begin(); it != installMgr->sources.end(); ++it) { count++; } +SWLog::getSystemLog()->logDebug("getRemoteSources: count: %d\n", count); ret = (jobjectArray) env->NewObjectArray(count, clazzString, NULL); count = 0; for (InstallSourceMap::iterator it = installMgr->sources.begin(); it != installMgr->sources.end(); ++it) { @@ -1287,9 +1710,9 @@ JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_InstallMgr_getRe * Signature: (Ljava/lang/String;)I */ JNIEXPORT jint JNICALL Java_org_crosswire_android_sword_InstallMgr_refreshRemoteSource - (JNIEnv *env, jobject me, jstring sourceNameJS) { + (JNIEnv *env, jobject me, jstring sourceNameJS) { - initInstall(); + initInstall(env); const char *sourceName = env->GetStringUTFChars(sourceNameJS, NULL); @@ -1310,11 +1733,11 @@ JNIEXPORT jint JNICALL Java_org_crosswire_android_sword_InstallMgr_refreshRemote * Signature: (Ljava/lang/String;)[Lorg/crosswire/android/sword/SWMgr/ModInfo; */ JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_InstallMgr_getRemoteModInfoList - (JNIEnv *env, jobject me, jstring sourceNameJS) { + (JNIEnv *env, jobject me, jstring sourceNameJS) { SWLog::getSystemLog()->logDebug("getRemoteModInfoList\n"); - init(); - initInstall(); + init(env); + initInstall(env); const char *sourceName = env->GetStringUTFChars(sourceNameJS, NULL); SWLog::getSystemLog()->logDebug("sourceName: %s\n", sourceName); @@ -1378,16 +1801,16 @@ SWLog::getSystemLog()->logDebug("remoteListModules returning %d length array\n", return ret; } - /* * Class: org_crosswire_android_sword_InstallMgr * Method: remoteInstallModule * Signature: (Ljava/lang/String;Ljava/lang/String;)I */ JNIEXPORT jint JNICALL Java_org_crosswire_android_sword_InstallMgr_remoteInstallModule - (JNIEnv *env, jobject me, jstring sourceNameJS, jstring modNameJS) { + (JNIEnv *env, jobject me, jstring sourceNameJS, jstring modNameJS, jobject progressReporter) { - initInstall(); + init(env); + initInstall(env, progressReporter); const char *sourceName = env->GetStringUTFChars(sourceNameJS, NULL); SWLog::getSystemLog()->logDebug("remoteInstallModule: sourceName: %s\n", sourceName); @@ -1415,6 +1838,17 @@ SWLog::getSystemLog()->logDebug("remoteInstallModule: modName: %s\n", modName); int error = installMgr->installModule(mgr, 0, module->getName(), is); + if (progressReporter) { + jclass cls = env->GetObjectClass(progressReporter); + jmethodID mid = env->GetMethodID(cls, "preStatus", "(JJLjava/lang/String;)V"); + if (mid != 0) { + jstring msg = env->NewStringUTF("Complete"); + env->CallVoidMethod(progressReporter, mid, (jlong)0, (jlong)0, msg); + env->DeleteLocalRef(msg); + } + env->DeleteLocalRef(cls); + } + return error; } @@ -1425,11 +1859,11 @@ SWLog::getSystemLog()->logDebug("remoteInstallModule: modName: %s\n", modName); * Signature: (Ljava/lang/String;Ljava/lang/String;)Lorg/crosswire/android/sword/SWModule; */ JNIEXPORT jobject JNICALL Java_org_crosswire_android_sword_InstallMgr_getRemoteModuleByName - (JNIEnv *env, jobject me, jstring sourceNameJS, jstring modNameJS) { + (JNIEnv *env, jobject me, jstring sourceNameJS, jstring modNameJS) { jobject retVal = 0; - initInstall(); + initInstall(env); const char *sourceName = env->GetStringUTFChars(sourceNameJS, NULL); SWLog::getSystemLog()->logDebug("getRemoteModuleByName: sourceName: %s\n", sourceName); @@ -1443,9 +1877,9 @@ SWLog::getSystemLog()->logDebug("Couldn't find remote source [%s]\n", sourceName SWMgr *mgr = source->second->getMgr(); - const char *modName = env->GetStringUTFChars(modNameJS, NULL); + const char *modName = env->GetStringUTFChars(modNameJS, NULL); sword::SWModule *module = mgr->getModule(modName); - env->ReleaseStringUTFChars(modNameJS, modName); + env->ReleaseStringUTFChars(modNameJS, modName); if (module) { SWBuf type = module->getType(); @@ -1471,10 +1905,56 @@ SWLog::getSystemLog()->logDebug("Couldn't find remote source [%s]\n", sourceName * Signature: ()V */ JNIEXPORT void JNICALL Java_org_crosswire_android_sword_InstallMgr_setUserDisclaimerConfirmed - (JNIEnv *env, jobject me) { + (JNIEnv *env, jobject me) { - initInstall(); + initInstall(env); + disclaimerConfirmed = true; installMgr->setUserDisclaimerConfirmed(true); } + +/* + * Class: org_crosswire_android_sword_SWMgr + * Method: sendBibleSyncMessage + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWMgr_sendBibleSyncMessage + (JNIEnv *env, jobject me, jstring osisRefJS) { + + initBibleSync(); + const char *osisRef = env->GetStringUTFChars(osisRefJS, NULL); + +#ifdef BIBLESYNC + BibleSync_xmit_status retval = bibleSync->Transmit(BSP_SYNC, "Bible", osisRef); +#endif + + env->ReleaseStringUTFChars(osisRefJS, osisRef); +} + + +/* + * NOTE: this method blocks and should be called in a new thread + * Class: org_crosswire_android_sword_SWMgr + * Method: registerBibleSyncListener + * Signature: (Ljava/lang/Object;)V + */ +JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWMgr_registerBibleSyncListener + (JNIEnv *env, jobject me, jobject bibleSyncListener) { + +#ifdef BIBLESYNC +SWLog::getSystemLog()->logDebug("registerBibleSyncListener"); + ::bibleSyncListener = bibleSyncListener; + ::bibleSyncListenerEnv = env; +SWLog::getSystemLog()->logDebug("registerBibleSyncListener - calling init"); + initBibleSync(); +SWLog::getSystemLog()->logDebug("registerBibleSyncListener - starting while listener"); + while(::bibleSyncListener) { +SWLog::getSystemLog()->logDebug("bibleSyncListener - while loop iteration"); + BibleSync::Receive(bibleSync); +SWLog::getSystemLog()->logDebug("bibleSyncListener - sleeping for 2 seconds"); + sleep(2); + } +#endif +} + |