std::string SwordPluginAPI::getModules() { /*Get all installed modules or all modules of a specific type. Set modType to e.g. "Biblical Texts" getModules() returns a JSON string */ refreshManagers(); std::stringstream modules; ModMap::iterator it; modules << "["; for (it = displayLibrary->Modules.begin(); it != displayLibrary->Modules.end(); it++) { SWModule *module = (*it).second; if (it != displayLibrary->Modules.begin()) { modules << ", "; } modules << "{\"name\": \"" << module->Name() << "\", "; modules << "\"modType\":\"" << module->Type() << "\", "; if (module->getConfigEntry("Lang")) { modules << "\"lang\": \"" << module->getConfigEntry("Lang") << "\", "; } modules << "\"dataPath\":\"" << module->getConfigEntry("DataPath") << "\", "; modules << "\"descr\": \"" << convertString(module->Description()) << "\"}"; } modules << "]"; return modules.str(); }
JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_SWMgr_getModInfoList (JNIEnv *env, jobject) { init(); int size = 0; for (sword::ModMap::iterator it = mgr->Modules.begin(); it != mgr->Modules.end(); ++it) { if ((!(it->second->getConfigEntry("CipherKey"))) || (*(it->second->getConfigEntry("CipherKey")))) size++; } SWLog::getSystemLog()->logDebug("getModInfoList returning %d length array\n", size); jclass clazzModInfo = env->FindClass("org/crosswire/android/sword/SWMgr$ModInfo"); jfieldID nameID = env->GetFieldID(clazzModInfo, "name", "Ljava/lang/String;"); jfieldID descID = env->GetFieldID(clazzModInfo, "description", "Ljava/lang/String;"); jfieldID catID = env->GetFieldID(clazzModInfo, "category", "Ljava/lang/String;"); jfieldID langID = env->GetFieldID(clazzModInfo, "language", "Ljava/lang/String;"); jfieldID versionID = env->GetFieldID(clazzModInfo, "version", "Ljava/lang/String;"); jfieldID deltaID = env->GetFieldID(clazzModInfo, "delta", "Ljava/lang/String;"); jobjectArray ret = (jobjectArray) env->NewObjectArray(size, clazzModInfo, NULL); int i = 0; for (sword::ModMap::iterator it = mgr->Modules.begin(); it != mgr->Modules.end(); ++it) { SWModule *module = it->second; if ((!(module->getConfigEntry("CipherKey"))) || (*(module->getConfigEntry("CipherKey")))) { SWBuf type = module->Type(); SWBuf cat = module->getConfigEntry("Category"); SWBuf version = module->getConfigEntry("Version"); if (cat.length() > 0) type = cat; jobject modInfo = env->AllocObject(clazzModInfo); jstring val; val = env->NewStringUTF(assureValidUTF8(module->getName())); env->SetObjectField(modInfo, nameID , val); env->DeleteLocalRef(val); val = env->NewStringUTF(assureValidUTF8(module->getDescription())); env->SetObjectField(modInfo, descID , val); env->DeleteLocalRef(val); val = env->NewStringUTF(assureValidUTF8(type.c_str())); env->SetObjectField(modInfo, catID , val); env->DeleteLocalRef(val); val = env->NewStringUTF(assureValidUTF8(module->getLanguage())); env->SetObjectField(modInfo, langID , val); env->DeleteLocalRef(val); val = env->NewStringUTF(assureValidUTF8(version.c_str())); env->SetObjectField(modInfo, versionID, val); env->DeleteLocalRef(val); val = env->NewStringUTF(assureValidUTF8("")); env->SetObjectField(modInfo, deltaID , val); env->DeleteLocalRef(val); env->SetObjectArrayElement(ret, i++, modInfo); env->DeleteLocalRef(modInfo); } } return ret; }
/* * 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) { init(); jstring retVal = 0; const char *configKey = env->GetStringUTFChars(configKeyJS, NULL); 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()); retVal = env->NewStringUTF(assuredBuf.c_str()); } env->ReleaseStringUTFChars(configKeyJS, configKey); return retVal; }
/* * Class: org_crosswire_android_sword_InstallMgr * Method: getRemoteModInfoList * 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) { SWLog::getSystemLog()->logDebug("getRemoteModInfoList\n"); init(); initInstall(); const char *sourceName = env->GetStringUTFChars(sourceNameJS, NULL); SWLog::getSystemLog()->logDebug("sourceName: %s\n", sourceName); jclass clazzModInfo = env->FindClass("org/crosswire/android/sword/SWMgr$ModInfo"); jfieldID nameID = env->GetFieldID(clazzModInfo, "name", "Ljava/lang/String;"); jfieldID descID = env->GetFieldID(clazzModInfo, "description", "Ljava/lang/String;"); jfieldID catID = env->GetFieldID(clazzModInfo, "category", "Ljava/lang/String;"); jfieldID langID = env->GetFieldID(clazzModInfo, "language", "Ljava/lang/String;"); jfieldID versionID = env->GetFieldID(clazzModInfo, "version", "Ljava/lang/String;"); jfieldID deltaID = env->GetFieldID(clazzModInfo, "delta", "Ljava/lang/String;"); InstallSourceMap::iterator source = installMgr->sources.find(sourceName); if (source == installMgr->sources.end()) { SWLog::getSystemLog()->logDebug("remoteListModules returning 0 length array\n"); return (jobjectArray) env->NewObjectArray(0, clazzModInfo, NULL); } SWLog::getSystemLog()->logDebug("found source: %s\n", sourceName); map<SWModule *, int> modStats = installMgr->getModuleStatus(*mgr, *source->second->getMgr()); int size = 0; for (map<SWModule *, int>::iterator it = modStats.begin(); it != modStats.end(); ++it) { size++; } SWLog::getSystemLog()->logDebug("remoteListModules returning %d length array\n", size); jobjectArray ret = (jobjectArray) env->NewObjectArray(size, clazzModInfo, NULL); int i = 0; for (map<SWModule *, int>::iterator it = modStats.begin(); it != modStats.end(); ++it) { SWModule *module = it->first; int status = it->second; SWBuf version = module->getConfigEntry("Version"); SWBuf statusString = " "; if (it->second & InstallMgr::MODSTAT_NEW) statusString = "*"; if (it->second & InstallMgr::MODSTAT_OLDER) statusString = "-"; if (it->second & InstallMgr::MODSTAT_UPDATED) statusString = "+"; SWBuf type = module->Type(); SWBuf cat = module->getConfigEntry("Category"); if (cat.length() > 0) type = cat; jobject modInfo = env->AllocObject(clazzModInfo); jstring val; val = env->NewStringUTF(assureValidUTF8(module->getName())); env->SetObjectField(modInfo, nameID , val); env->DeleteLocalRef(val); val = env->NewStringUTF(assureValidUTF8(module->getDescription())); env->SetObjectField(modInfo, descID , val); env->DeleteLocalRef(val); val = env->NewStringUTF(assureValidUTF8(type.c_str())); env->SetObjectField(modInfo, catID , val); env->DeleteLocalRef(val); val = env->NewStringUTF(assureValidUTF8(module->getLanguage())); env->SetObjectField(modInfo, langID , val); env->DeleteLocalRef(val); val = env->NewStringUTF(assureValidUTF8(version.c_str())); env->SetObjectField(modInfo, versionID, val); env->DeleteLocalRef(val); val = env->NewStringUTF(assureValidUTF8(statusString.c_str())); env->SetObjectField(modInfo, deltaID , val); env->DeleteLocalRef(val); env->SetObjectArrayElement(ret, i++, modInfo); env->DeleteLocalRef(modInfo); } env->ReleaseStringUTFChars(sourceNameJS, sourceName); return ret; }
void BookTreeCtrl::RefreshBookList(bool ShowLanguages) { using namespace sword; ModMap::iterator it; SWModule *curMod = 0; ModMap *Modules; Modules = m_SwordTools->GetModuleMap(); wxTreeItemId rootnode, childnode, langnode, curNode; std::map < string, wxTreeItemId > treenodes; std::map < string, wxTreeItemId > treelangnodes; string group, grouplang; wxString configEntry; rootnode = AddRoot(wxT("books")); for (it = Modules->begin(); it != Modules->end(); it++) { curMod = (*it).second; if (curMod == 0) { continue; } wxLogDebug(wxT("type %s"), (const wxChar *) wxString(curMod->Type(), wxConvUTF8)); configEntry = wxT(""); configEntry = wxString(curMod->getConfigEntry("Category"), wxConvUTF8); if (!configEntry.CompareTo(wxT(""))) { childnode = treenodes[curMod->Type()]; if (!childnode.IsOk()) { wxLogDebug(wxT("appending type")); childnode = AppendItem(rootnode, wxString(curMod->Type(), wxConvUTF8), ID_CLOSEDFOLDER_ICON, ID_CLOSEDFOLDER_ICON); treenodes[curMod->Type()] = childnode; } group = curMod->Type(); } else { childnode = treenodes[(const char *) configEntry.mb_str()]; if (!childnode.IsOk()) { childnode = AppendItem(rootnode, configEntry, ID_CLOSEDFOLDER_ICON, ID_CLOSEDFOLDER_ICON); treenodes[(const char *) configEntry.mb_str()] = childnode; } curMod->Type((const char *) configEntry.mb_str()); group = (const char *) configEntry.mb_str(); } grouplang = group; wxLogDebug(wxT("language %s"), (const wxChar *) wxString(curMod->Lang(), wxConvUTF8)); grouplang.append(curMod->Lang()); if (ShowLanguages) { langnode = treelangnodes[grouplang]; if (!langnode.IsOk()) { wxString language; wxLogDebug(wxT("appending language")); language = m_Languages.GetLanguage(wxString(curMod->Lang(), wxConvUTF8)); langnode = AppendItem(childnode, language, ID_CLOSEDFOLDER_ICON, ID_CLOSEDFOLDER_ICON); treelangnodes[grouplang] = langnode; } } else { langnode = childnode; } wxString modname = wxString(curMod->Name(), wxConvUTF8); modname += wxT(" - "); modname += wxString(curMod->Description(), wxConvUTF8); wxLogDebug(wxT("appending module %s"), (const wxChar *) modname); /** SET ICON **/ if (!strcmp(curMod->Type(), "Biblical Texts")) { curNode = AppendItem(langnode, wxString(curMod->Name(), wxConvUTF8) + wxT(" - ") + wxString(curMod->Description(), wxConvUTF8), ID_BIBLICAL_TEXT_ICON, ID_BIBLICAL_TEXT_ICON); } else if (!strcmp(curMod->Type(), "Lexicons / Dictionaries") || !strcmp(curMod->Type(), "Glossaries")) { curNode = AppendItem(langnode, wxString(curMod->Name(), wxConvUTF8) + wxT(" - ") + wxString(curMod->Description(), wxConvUTF8), ID_LEXICON_ICON, ID_LEXICON_ICON); } else if (!strcmp(curMod->Type(), "Commentaries")) { curNode = AppendItem(langnode, wxString(curMod->Name(), wxConvUTF8) + wxT(" - ") + wxString(curMod->Description(), wxConvUTF8), ID_COMMENTARY_ICON, ID_COMMENTARY_ICON); } else if (!strcmp(curMod->Type(), "Daily Devotional")) { curNode = AppendItem(langnode, wxString(curMod->Name(), wxConvUTF8) + wxT(" - ") + wxString(curMod->Description(), wxConvUTF8), ID_DEVOTIONAL_ICON, ID_DEVOTIONAL_ICON); } else { curNode = AppendItem(langnode, wxString(curMod->Name(), wxConvUTF8) + wxT(" - ") + wxString(curMod->Description(), wxConvUTF8), ID_BOOK_ICON, ID_BOOK_ICON); } /** END SET ICON **/ SetItemData(curNode, new BookTreeItemData(curMod)); SortChildren(childnode); SortChildren(langnode); } SortChildren(rootnode); }