28 #include <QDomDocument>
33 #include <QTranslator>
34 #include <QLibraryInfo>
63 klfDbg(
"KLFAddOnInfo: rccfpath="<<rccfpath<<
", Private has ref "<< d->ref ) ;
80 QString minrccfpath = rccfpath.
section(
"/", -1, -1, QString::SectionSkipEmpty);
83 while (
QFileInfo(mountroot =
QString(
":/klfaddon_rccmount/%1%2").arg(minrccfpath, suffix)).exists()) {
86 d->rccmountroot = mountroot;
87 klfDbg(
"Mounting resource "<<rccfpath<<
" to "<<d->rccmountroot ) ;
95 infofile.
open(QIODevice::ReadOnly);
96 rccinfodata = infofile.readAll();
105 d->title =
QObject::tr(
"(Name Not Provided)",
"[KLFAddOnInfo: add-on information XML data is invalid]");
106 d->description =
QObject::tr(
"(Invalid XML Data Provided By Add-On)",
107 "[KLFAddOnInfo: add-on information XML data is invalid]");
110 "[KLFAddOnInfo: add-on information XML data is invalid]");
117 if (xmlroot.nodeName() !=
"rccinfo") {
118 qWarning(
"Add-on file `%s' has invalid XML information.", qPrintable(rccfpath));
124 if ( e.isNull() || n.
nodeType() != QDomNode::ElementNode )
126 if ( e.nodeName() ==
"title" ) {
127 d->title = e.
text().trimmed();
129 if ( e.nodeName() ==
"author" ) {
130 d->author = e.
text().trimmed();
132 if ( e.nodeName() ==
"description" ) {
133 d->description = e.
text().trimmed();
135 if ( e.nodeName() ==
"klfminversion" ) {
136 d->klfminversion = e.
text().trimmed();
146 <<
"; os="<<i.
os<<
"; arch="<<i.
arch<<
")";
162 void KLFAddOnInfo::initPlugins()
177 for (k = 0; k < unorderedplugins.size(); ++k) {
178 d->pluginList << unorderedplugins[k];
179 d->plugins[unorderedplugins[k]] = defpinfo;
182 if (!
QFile::exists(plugdir.absoluteFilePath(
"plugindirinfo.xml"))) {
183 klfDbg(
"KLFAddOnInfo("<<d->fname<<
"): No specific plugin directories. plugdirinfo.xml="
184 <<plugdir.absoluteFilePath(
"plugindirinfo.xml") ) ;
190 plugdirinfofile.open(QIODevice::ReadOnly);
191 QByteArray plugdirinfodata = plugdirinfofile.readAll();
201 if (xmlroot.nodeName() !=
"klfplugindirs") {
202 qWarning(
"KLFAddOnInfo: Add-on plugin dir info file `%s' has invalid XML information.",
203 qPrintable(d->fpath));
209 if ( e.isNull() || n.
nodeType() != QDomNode::ElementNode )
211 if ( e.nodeName() !=
"klfplugindir" ) {
212 qWarning(
"KLFAddOnInfo(%s): plugindirinfo.xml: skipping unexpected node %s.", qPrintable(d->fpath),
213 qPrintable(e.nodeName()));
221 klfDbg(
"Node: type="<<nn.
nodeType()<<
"; name="<<ee.nodeName() ) ;
222 if ( ee.isNull() || nn.
nodeType() != QDomNode::ElementNode )
224 if ( ee.nodeName() ==
"dir" ) {
225 psi.dir = ee.
text().trimmed();
226 }
else if ( ee.nodeName() ==
"qtminversion" ) {
227 psi.qtminversion = ee.
text().trimmed();
228 }
else if ( ee.nodeName() ==
"klfminversion" ) {
229 psi.klfminversion = ee.
text().trimmed();
230 }
else if ( ee.nodeName() ==
"os" ) {
231 psi.os = ee.
text().trimmed();
232 }
else if ( ee.nodeName() ==
"arch" ) {
233 psi.arch = ee.
text().trimmed();
235 qWarning(
"KLFAddOnInfo(%s): plugindirinfo.xml: skipping unexpected node in <klfplugindirs>: %s.",
236 qPrintable(d->fpath), qPrintable(ee.nodeName()));
239 klfDbg(
"\tRead psi="<<psi ) ;
241 pdirinfos[psi.dir] = psi;
247 PluginSysInfo psi = it.value();
249 qWarning(
"KLFAddOnInfo(%s): Plugin dir '%s' given in XML info does not exist in resource!",
250 qPrintable(d->fpath), qPrintable(dir));
253 QDir plugsubdir(d->rccmountroot +
"/plugins/" + dir);
256 for (j = 0; j < plugins.size(); ++j) {
257 QString p = dir+
"/"+plugins[j];
258 morePluginsList << p;
264 fullList << d->pluginList;
265 d->pluginList = fullList;
267 klfDbg(
"Loaded plugins: list="<<d->pluginList<<
"; map="<<d->plugins ) ;
274 for (
int k = 0; k < d->pluginList.size(); ++k) {
275 if ( d->plugins[d->pluginList[k]].isCompatibleWithCurrentSystem() )
310 int firstunderscore = fn.
indexOf(
'_');
312 if (firstunderscore == -1)
313 firstunderscore = endbasename;
316 name = fn.
mid(0, firstunderscore);
317 locale = fn.
mid(firstunderscore+1, endbasename-(firstunderscore+1));
318 locale_specificity = (locale.split(
'_', QString::SkipEmptyParts)).size() ;
327 klfDbg(
"i18nfile.fpath="<<i18nfile.
fpath<<
" is translation to "<<i18nfile.
locale) ;
336 || i18nfile.
name ==
"qt" ) {
343 bool needsRegistration =
true;
344 bool needsNiceName =
true;
345 int alreadyRegisteredIndex = -1;
350 needsRegistration =
false;
351 alreadyRegisteredIndex = kk;
353 klfDbg(
"translation "<<i18nfile.
locale<<
" is already registered. needs nice name?="<< needsNiceName) ;
357 klfDbg(
"Needs registration?="<<needsRegistration<<
"; needs nice name?="<<needsNiceName) ;
358 if ( ! needsRegistration && ! needsNiceName ) {
370 struct klf_qtTrNoop3 {
const char *source;
const char *comment; };
372 = QT_TRANSLATE_NOOP3(
"QObject",
"English (US)",
373 "[[The Language (possibly with Country) you are translating to, e.g. `Deutsch']]");
374 ti.
translatedname = translator.translate(
"QObject", lang.source, lang.comment);
389 if (needsRegistration)
420 for (k = 0; k < klf_addons.
size(); ++k) {
421 i18ndirlist << klf_addons[k].rccmountroot()+
"/i18n";
423 i18ndirlist <<
":/i18n"
428 for (j = 0; j < i18ndirlist.size(); ++j) {
430 QDir i18ndir(i18ndirlist[j]);
434 for (k = 0; k < files.size(); ++k) {
438 i18nFiles[i18nfile.name][i18nfile.locale_specificity] << i18nfile;
439 names << i18nfile.name;
440 qDebug(
"Found translation %s", qPrintable(i18nfile.fpath));
460 int specificity = lcparts.size();
461 while (specificity >= 0) {
467 for (j = 0; j < list.
size(); ++j) {
468 if (list[j].locale == testlocale) {
471 translationsToLoad << list[j].fpath;
483 for (j = 0; j < translationsToLoad.size(); ++j) {
495 qWarning(
"Failed to load translator %s.", qPrintable(translationsToLoad[j]));
513 while ( k < suffixes.size() &&
515 klfDbg(
"base="<<baseFileName<<
" extn="<<extension<<
"; tried fn="<<fn ) ;
518 if (k >= suffixes.size()) {
519 qWarning()<<
KLF_FUNC_NAME<<
": Can't find good translated file for "<<qPrintable(baseFileName+extension)
520 <<
"! last try was "<<fn;
532 stream.
device()->setProperty(
"klfDataStreamAppVersion",
537 stream << headermagic
540 << (qint16)QDataStream::Qt_4_4;
554 if (!possibleHeaders.
contains(s) || stream.
status() != QDataStream::Ok) {
555 klfDbg(
"Read bad header: "<<s) ;
556 if (readHeader != NULL)
560 if (readHeader != NULL)
565 stream >> vmaj >> vmin;
566 if (stream.
status() != QDataStream::Ok) {
567 if (readCompatKLFVersion)
568 *readCompatKLFVersion =
QString();
571 klfDbg(
"read app compat version = "<<vmaj<<
"."<<vmin) ;
576 if (readCompatKLFVersion != NULL)
577 *readCompatKLFVersion = compatKLFVersion;
592 stream.
device()->setProperty(
"klfDataStreamAppVersion", QVariant::fromValue<QString>(compatKLFVersion));
QDataStream & operator<<(QDataStream &stream, const KLFLatexSymbol &s)
KLF_EXPORT void klf_reload_translations(QCoreApplication *app, const QString ¤tLocale)
QStringList translations()
registerResource(const QString &rccFileName, const QString &mapRoot=QString()
QString locale
When setting this, don't forget to call QLocale::setDefault().
QString pluginLocalSubDirName(const QString &plugin) const
#define KLF_DATA_STREAM_APP_VERSION_MAJ
'Major' version part of KLF_DATA_STREAM_APP_VERSION.
QString locale
Locale Name (e.g. "fr" or "fr_CH")
split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive)
arg(const QString &a, int fieldWidth=0, const QChar &fillChar=QLatin1Char( ' ')
KLF_EXPORT int klfVersionMin()
contains(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive)
KLF_EXPORT int klfVersionMaj()
languageToString(Language language)
#define klfDbg(streamableItems)
#define KLF_DEBUG_BLOCK(msg)
QString homeConfigDirI18n
KLFAddOnInfo(QString rccfpath, bool isFresh=false)
tr(const char *sourceText, const char *comment=0, int n=-1)
bool isCompatibleWithCurrentSystem() const
KLFI18nFile(QString filepath)
QStringList localPluginList() const
entryList(const QStringList &nameFilters, Filters filters=NoFilter, SortFlags sort=NoSort)
endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive)
void klf_add_avail_translation(KLFI18nFile i18nfile)
KLF_EXPORT QString arch()
Small minimalist structure to store basic information about available translations.
KLF_EXPORT QList< QTranslator * > klf_translators
KLF_EXPORT QList< KLFTranslationInfo > klf_avail_translations
#define KLF_DATA_STREAM_APP_VERSION
Current datastream compatibility klatexformula version.
QList< KLFPluginInfo > klf_plugins
load(const QString &filename, const QString &directory=QString()
Small structure to store information for a translation file (.qm)
installTranslator(QTranslator *translationFile)
cleanPath(const QString &path)
mid(int position, int n=-1)
unregisterResource(const QString &rccFileName, const QString &mapRoot=QString()
KLF_EXPORT QString osString(KLFSysInfo::Os sysos=os())
KLF_EXPORT int klfVersionCompare(const QString &v1, const QString &v2)
KLF_EXPORT QString klfFindTranslatedDataFile(const QString &baseFileName, const QString &extension)
QList< KLFAddOnInfo > klf_addons
absoluteFilePath(const QString &fileName)
removeTranslator(QTranslator *translationFile)
section(QChar sep, int start, int end=-1, SectionFlags flags=SectionDefault)
countryToString(Country country)
fromLatin1(const char *str, int size=-1)
KLF_EXPORT void klfDataStreamWriteHeader(QDataStream &stream, const QString headermagic)
exists(const QString &name)
bool klf_addons_canimport
#define KLF_ASSERT_CONDITION(expr, msg, failaction)
bool hasnicetranslatedname
TRUE if the translatedname was provided by translator itself.
location(LibraryLocation loc)
indexOf(const QString &str, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive)
KLF_EXPORT bool klfDataStreamReadHeader(QDataStream &stream, const QStringList possibleHeaders, QString *readHeader, QString *readCompatKLFVersion)
#define KLF_DATA_STREAM_APP_VERSION_MIN
'Minor' version part of KLF_DATA_STREAM_APP_VERSION.
QString name
Translation file base name (e.g. 'klf' for klf_fr.qm)
setContent(const QByteArray &data, bool namespaceProcessing, QString *errorMsg=0, int *errorLine=0, int *errorColumn=0)