jboolean initInternal(JNIEnv * penv, jclass obj, jobjectArray fontArray) { CRJNIEnv env(penv); // to catch crashes and remove current cache file on crash (SIGSEGV etc.) crSetSignalHandler(); LOGI("initInternal called"); // set fatal error handler crSetFatalErrorHandler( &cr3androidFatalErrorHandler ); LOGD("Redirecting CDRLog to Android"); CRLog::setLogger( new JNICDRLogger() ); CRLog::setLogLevel( CRLog::LL_TRACE ); CRLog::info("CREngine log redirected"); CRLog::info("CRENGINE version %s %s", CR_ENGINE_VERSION, CR_ENGINE_BUILD_DATE); CRLog::info("initializing hyphenation manager"); HyphMan::initDictionaries(lString16::empty_str); //don't look for dictionaries HyphMan::activateDictionary(lString16(HYPH_DICT_ID_NONE)); CRLog::info("creating font manager"); InitFontManager(lString8::empty_str); CRLog::debug("converting fonts array: %d items", (int)env->GetArrayLength(fontArray)); lString16Collection fonts; env.fromJavaStringArray(fontArray, fonts); int len = fonts.length(); CRLog::debug("registering fonts: %d fonts in list", len); for ( int i=0; i<len; i++ ) { lString8 fontName = UnicodeToUtf8(fonts[i]); CRLog::debug("registering font %s", fontName.c_str()); if ( !fontMan->RegisterFont( fontName ) ) CRLog::error("cannot load font %s", fontName.c_str()); } CRLog::info("%d fonts registered", fontMan->GetFontCount()); return fontMan->GetFontCount() ? JNI_TRUE : JNI_FALSE; }
int main(int argc, char *argv[]) { int res = 0; { Device::instance(); // initialize device #ifndef i386 QProcess::execute("eips -c"); pTouch = new TouchScreen(); #endif lString16 exedir = LVExtractPath(LocalToUnicode(lString8(argv[0]))); LVAppendPathDelimiter(exedir); lString16 datadir = exedir + "data/"; lString16 exefontpath = exedir + "fonts"; lString16Collection fontDirs; fontDirs.add(exefontpath); #ifndef i386 fontDirs.add("/usr/java/lib/fonts"); fontDirs.add("/mnt/us/fonts"); #endif CRPropRef props = LVCreatePropsContainer(); { LVStreamRef cfg = LVOpenFileStream(UnicodeToUtf8(datadir + "cr3.ini").data(), LVOM_READ); if(!cfg.isNull()) props->loadFromStream(cfg.get()); } lString16 lang = props->getStringDef(PROP_WINDOW_LANG, ""); InitCREngineLog(props); CRLog::info("main()"); if(!InitCREngine(argv[0], fontDirs)) { printf("Cannot init CREngine - exiting\n"); return 2; } #ifndef i386 PrintString(1, 1, "crengine version: " + QString(CR_ENGINE_VERSION)); PrintString(1, 2, QString("build date: %1 %2").arg(__DATE__).arg(__TIME__)); if (!Device::isTouch()) { QString message = "Please wait while application is loading..."; int xpos = ((Device::getWidth()/12-1)-message.length())/2; int ypos = (Device::getHeight()/20-2)/2; PrintString(xpos, ypos, message); } #endif // to catch crashes and remove current cache file on crash (SIGSEGV etc.) crSetSignalHandler(); // set row count depending on device model (used in lists) int rc = props->getIntDef(PROP_WINDOW_ROW_COUNT, 0); if(!rc) { #ifndef i386 switch(Device::getModel()) { case Device::KDX: rc = 20; break; case Device::KT: case Device::KPW: rc = 8; break; default: rc = 10; } props->setInt(PROP_WINDOW_ROW_COUNT, rc); #else props->setInt(PROP_WINDOW_ROW_COUNT, 10); #endif LVStreamRef cfg = LVOpenFileStream(UnicodeToUtf8(datadir + "cr3.ini").data(), LVOM_WRITE); props->saveToStream(cfg.get()); } QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8")); MyApplication a(argc, argv); pMyApp = &a; // set app stylesheet #ifndef i386 QString style = Device::isTouch() ? "stylesheet_pw.qss" : "stylesheet_k3.qss"; QFile qss(QDir::toNativeSeparators(cr2qt(datadir)) + style); // set up full update interval for the graphics driver Device::setFullScreenUpdateEvery(props->getIntDef(PROP_DISPLAY_FULL_UPDATE_INTERVAL, 1)); #else QFile qss(QDir::toNativeSeparators(cr2qt(datadir)) + "stylesheet_k3.qss"); #endif qss.open(QFile::ReadOnly); if(qss.error() == QFile::NoError) { a.setStyleSheet(qss.readAll()); qss.close(); } QMap<QString, QString> langToCode; langToCode["Russian"] = "ru"; langToCode["French"] = "fr"; langToCode["Hungarian"] = "hu"; langToCode["Italian"] = "it"; langToCode["German"] = "de"; langToCode["Ukrainian"] = "uk"; QString translations = cr2qt(datadir) + "i18n"; QTranslator myappTranslator, qtr; if (!lang.empty() && lang.compare("English")) { QString lng = cr2qt(lang); if (myappTranslator.load(lng, translations)) { // default translator for Qt standard dialogs if (qtr.load("qt_" + langToCode[lng], translations)) { QApplication::installTranslator(&qtr); } else { qDebug() << "Failed to load Qt translation for " << lng; } // load after default to allow overriding translations QApplication::installTranslator(&myappTranslator); } else { qDebug() << "Can`t load translation file " << lng << " from dir " << translations; } } (void) signal(SIGUSR1, sigCatcher); MainWindow mainWin; a.setMainWindow(&mainWin); mainWin.showFullScreen(); mainWin.doStartupActions(); res = a.exec(); } ShutdownCREngine(); return res; }