17 #include "../../util/btassert.h"
18 #include "../config/btconfig.h"
19 #include "../keys/cswordversekey.h"
20 #include "../drivers/cswordmoduleinfo.h"
30 switch (module.
type()) {
32 type = QStringLiteral(
"Bible");
35 type = QStringLiteral(
"Commentary");
38 type = QStringLiteral(
"Lexicon");
41 type = QStringLiteral(
"Book");
47 return QStringLiteral(
"sword://%1/%2/%3").arg(type, module.
name(), key);
51 std::optional<ReferenceManager::DecodedHyperlink>
68 QStringView ref(hyperlink);
70 static auto const preferredModule =
74 #define RET_CASE(t,str) \
75 case t: typeStr = QStringLiteral("standard" str); break
84 case Unknown:
default:
return nullptr;
90 static auto const removeCaseInsensitivePrefix =
91 [](QStringView & ref, QString
const & prefix) {
92 if (ref.startsWith(prefix, Qt::CaseInsensitive)) {
93 ref = ref.mid(prefix.size() - 1);
99 if (removeCaseInsensitivePrefix(ref, QStringLiteral(
"sword://"))) {
100 if (removeCaseInsensitivePrefix(ref, QStringLiteral(
"bible/"))) {
102 }
else if (removeCaseInsensitivePrefix(ref,
103 QStringLiteral(
"commentary/")))
106 }
else if (removeCaseInsensitivePrefix(ref, QStringLiteral(
"lexicon/")))
109 }
else if (removeCaseInsensitivePrefix(ref, QStringLiteral(
"book/"))) {
116 slashPos = ref.indexOf(
'/');
123 ref.left(slashPos).toString());
128 struct {
Type hebrew;
Type greek; } types;
129 if (removeCaseInsensitivePrefix(ref, QStringLiteral(
"morph://"))) {
131 }
else if (removeCaseInsensitivePrefix(ref,
132 QStringLiteral(
"strongs://")))
140 slashPos = ref.indexOf(
'/');
143 auto const language(ref.left(slashPos).toString().toLower());
144 if (language == QStringLiteral(
"hebrew")) {
145 ret.
type = types.hebrew;
146 }
else if (language == QStringLiteral(
"greek")) {
147 ret.
type = types.greek;
154 ref = ref.mid(slashPos + 1);
157 ret.
key = ref.toString();
167 auto const *
const mod =
172 switch (mod->type()) {
175 qDebug() <<
"CReferenceManager: Only verse based modules are supported "
176 "as ref destination module";
182 bool const haveLocaleForSourceLanguage =
183 [&locale = std::as_const(sourceLanguage)]() {
184 if (locale == QStringLiteral(
"locales"))
187 return locales.find(locale.toUtf8().constData())
190 if (!haveLocaleForSourceLanguage)
191 sourceLanguage = QStringLiteral(
"en_US");
193 auto const *
const destinationLanguage =
194 haveLocaleForSourceLanguage ?
"en" :
"en_US";
197 baseKey.
setLocale(sourceLanguage.toUtf8().constData());
203 auto const oldLocaleName(
backend.booknameLanguage());
204 backend.setBooknameLanguage(sourceLanguage);
206 sword::VerseKey dummy;
207 dummy.setLocale(sourceLanguage.toUtf8().constData());
208 BT_ASSERT(!strcmp(dummy.getLocale(), sourceLanguage.toUtf8().constData()));
211 for (
auto const & ref : ref.split(
';')) {
214 auto lk(dummy.parseVerseList(ref.toUtf8().constData(),
215 baseKey.
key().toUtf8().constData(),
219 if (!lk.getCount()) {
224 for (
int i = 0; i < lk.getCount(); ++i) {
226 dynamic_cast<sword::VerseKey *
>(lk.getElement(i)))
228 k->setLocale(destinationLanguage);
229 ret.append(QStringLiteral(
"%1; ")
230 .arg(QString::fromUtf8(k->getRangeText())));
233 vk.setLocale(sourceLanguage.toUtf8().constData());
234 vk = lk.getElement(i)->getText();
235 vk.setLocale(destinationLanguage);
236 ret.append(QStringLiteral(
"%1; ")
237 .arg(QString::fromUtf8(vk.getText())));
241 backend.setBooknameLanguage(oldLocaleName);
BtConfig & btConfig()
This is a shortchand for BtConfig::getInstance().
CSwordModuleInfo * getDefaultSwordModuleByType(const QString &moduleType)
Returns default sword module info class for a given module type.
CSwordModuleInfo * findModuleByName(const QString &name) const
Searches for a module with the given name.
static CSwordBackend & instance() noexcept
QString const & name() const
CSwordKey implementation for Sword's VerseKey.
void setLocale(char const *const locale)
QString key() const final override
bool setKey(const QString &key) final override
std::unique_ptr< CSwordBackend > backend(sword::InstallSource const &is)
std::map< sword::SWBuf, sword::SWLocale * > const & internalSwordLocales()
QString parseVerseReference(QString const &ref, ParseOptions const &options)
QString encodeHyperlink(CSwordModuleInfo const &module, QString const &key)
std::optional< DecodedHyperlink > decodeHyperlink(QString const &hyperlink)
CSwordModuleInfo * module
QString refDestinationModule