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(); }
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); }