void Gui::postInit(Graphics *const graphics) { logger->log1("Initializing GUI..."); // Set graphics setGraphics(graphics); // Set input guiInput = new SDLInput; setInput(guiInput); // Set focus handler delete mFocusHandler; mFocusHandler = new FocusHandler; // Initialize top GUI widget WindowContainer *const guiTop = new WindowContainer(nullptr); guiTop->setFocusable(true); guiTop->setSize(graphics->mWidth, graphics->mHeight); guiTop->setOpaque(false); Window::setWindowContainer(guiTop); setTop(guiTop); const StringVect langs = getLang(); const bool isJapan = (!langs.empty() && langs[0].size() > 3 && langs[0].substr(0, 3) == "ja_"); const bool isChinese = (!langs.empty() && langs[0].size() > 3 && langs[0].substr(0, 3) == "zh_"); // Set global font const int fontSize = config.getIntValue("fontSize"); std::string fontFile = config.getValue("font", ""); if (isJapan) { fontFile = config.getValue("japanFont", ""); if (fontFile.empty()) fontFile = branding.getStringValue("japanFont"); } else if (isChinese) { fontFile = config.getValue("chinaFont", ""); if (fontFile.empty()) fontFile = branding.getStringValue("chinaFont"); } if (fontFile.empty()) fontFile = branding.getStringValue("font"); mGuiFont = new Font(fontFile, fontSize); // Set particle font fontFile = config.getValue("particleFont", ""); if (isJapan) { fontFile = config.getValue("japanFont", ""); if (fontFile.empty()) fontFile = branding.getStringValue("japanFont"); } else if (isChinese) { fontFile = config.getValue("chinaFont", ""); if (fontFile.empty()) fontFile = branding.getStringValue("chinaFont"); } if (fontFile.empty()) fontFile = branding.getStringValue("particleFont"); mInfoParticleFont = new Font(fontFile, fontSize, TTF_STYLE_BOLD); // Set bold font fontFile = config.getValue("boldFont", ""); if (fontFile.empty()) fontFile = branding.getStringValue("boldFont"); boldFont = new Font(fontFile, fontSize); // Set help font fontFile = config.getValue("helpFont", ""); if (fontFile.empty()) fontFile = branding.getStringValue("helpFont"); mHelpFont = new Font(fontFile, fontSize); // Set secure font fontFile = config.getValue("secureFont", ""); if (fontFile.empty()) fontFile = branding.getStringValue("secureFont"); mSecureFont = new Font(fontFile, fontSize); // Set npc font const int npcFontSize = config.getIntValue("npcfontSize"); fontFile = config.getValue("npcFont", ""); if (isJapan) { fontFile = config.getValue("japanFont", ""); if (fontFile.empty()) fontFile = branding.getStringValue("japanFont"); } else if (isChinese) { fontFile = config.getValue("chinaFont", ""); if (fontFile.empty()) fontFile = branding.getStringValue("chinaFont"); } if (fontFile.empty()) fontFile = branding.getStringValue("npcFont"); mNpcFont = new Font(fontFile, npcFontSize); Widget::setGlobalFont(mGuiFont); // Initialize mouse cursor and listen for changes to the option setUseCustomCursor(config.getBoolValue("customcursor")); setDoubleClick(config.getBoolValue("doubleClick")); config.addListener("customcursor", mConfigListener); config.addListener("doubleClick", mConfigListener); }
QString Translator::getCurrentLang() { return getLang(); }
int InitDoc(char *fileName) { static const lChar16 * css_file_name = L"fb2.css"; // fb2 CRLog::trace("InitDoc()"); #ifdef __i386__ //CRLog::setFileLogger("/root/abook/crengine.log"); CRLog::setStdoutLogger(); CRLog::setLogLevel(CRLog::LL_TRACE); #else //InitCREngineLog(NULL); #if 0 CRLog::setFileLogger("/root/abook/.cr3/cr3.log", true); CRLog::setLogLevel(CRLog::LL_TRACE); #else InitCREngineLog("/root/abook/crengine/crlog.ini"); #endif #endif CRLog::trace("creating window manager..."); CRJinkeWindowManager * wm = new CRJinkeWindowManager(600,800); CRLog::trace("loading skin..."); if ( !wm->loadSkin( lString16( L"/root/abook/crengine/skin" ) ) ) if ( !wm->loadSkin( lString16( L"/home/crengine/skin" ) ) ) wm->loadSkin( lString16( L"/root/crengine/skin" ) ); CRLog::trace("drawing progressbar 0%%..."); //wm->getScreen()->getCanvas()->Clear(0xFFFFFF); //wm->getScreen()->invalidateRect( lvRect(0, 0, 600, 800) ); //wm->showProgress(lString16("cr3_wait_icon.png"), 10); { const lChar16 * imgname = ( wm->getScreenOrientation()&1 ) ? L"cr3_logo_screen_landscape.png" : L"cr3_logo_screen.png"; LVImageSourceRef img = wm->getSkin()->getImage(imgname); if ( !img.isNull() ) { wm->getScreen()->getCanvas()->Draw(img, 0, 0, wm->getScreen()->getWidth(), wm->getScreen()->getHeight(), false ); } } lString16 bookmarkDir("/root/abook/bookmarks/"); { lString8 fn(fileName); if ( fn.startsWith(lString8("/home")) ) { strcpy( history_file_name, "/home/.cr3hist" ); bookmarkDir = lString16("/home/bookmarks/"); } CRLog::info( "History file name: %s", history_file_name ); } char manual_file[512] = ""; { const char * lang = getLang(); if ( lang && lang[0] ) { // set translator CRLog::info("Current language is %s, looking for translation file", lang); lString16 mofilename = L"/root/crengine/i18n/" + lString16(lang) + L".mo"; lString16 mofilename2 = L"/root/abook/crengine/i18n/" + lString16(lang) + L".mo"; CRMoFileTranslator * t = new CRMoFileTranslator(); if ( t->openMoFile( mofilename2 ) || t->openMoFile( mofilename ) ) { CRLog::info("translation file %s.mo found", lang); CRI18NTranslator::setTranslator( t ); } else { CRLog::info("translation file %s.mo not found", lang); delete t; } sprintf( manual_file, "/root/abook/crengine/manual/cr3-manual-%s.fb2", lang ); if ( !LVFileExists( lString16(manual_file).c_str() ) ) sprintf( manual_file, "/root/crengine/manual/cr3-manual-%s.fb2", lang ); } } const lChar16 * ini_fname = L"cr3.ini"; #ifdef SEPARATE_INI_FILES if ( strstr(fileName, ".txt")!=NULL || strstr(fileName, ".tcr")!=NULL) { ini_fname = L"cr3-txt.ini"; css_file_name = L"txt.css"; } else if ( strstr(fileName, ".rtf")!=NULL ) { ini_fname = L"cr3-rtf.ini"; css_file_name = L"rtf.css"; } else if ( strstr(fileName, ".htm")!=NULL ) { ini_fname = L"cr3-htm.ini"; css_file_name = L"htm.css"; } else if ( strstr(fileName, ".epub")!=NULL ) { ini_fname = L"cr3-epub.ini"; css_file_name = L"epub.css"; } else { ini_fname = L"cr3-fb2.ini"; css_file_name = L"fb2.css"; } #endif lString16Collection fontDirs; fontDirs.add( lString16(L"/root/abook/fonts/") ); fontDirs.add( lString16(L"/home/fonts/") ); //fontDirs.add( lString16(L"/root/crengine/fonts") ); // will be added CRLog::info("INIT..."); if ( !InitCREngine( "/root/crengine/", fontDirs ) ) return 0; #ifdef ALLOW_RUN_EXE { __pid_t pid; if( strstr(fileName, ".exe.txt") || strstr(fileName, ".exe.fb2")) { pid = fork(); if(!pid) { execve(fileName, NULL, NULL); exit(0); } else { waitpid(pid, NULL, 0); exit(0); //return 0; } } } #endif { //main_win = new V3DocViewWin( wm, lString16(CRSKIN) ); const char * keymap_locations [] = { "/root/crengine/", "/home/crengine/", "/root/abook/crengine/", NULL, }; loadKeymaps( *wm, keymap_locations ); if ( LVDirectoryExists( L"/root/abook/crengine/hyph" ) ) HyphMan::initDictionaries( lString16("/root/abook/crengine/hyph/") ); else HyphMan::initDictionaries( lString16("/root/crengine/hyph/") ); if ( !ldomDocCache::init( lString16(L"/root/abook/crengine/.cache"), 0x100000 * 64 ) ) { if ( !ldomDocCache::init( lString16(L"/home/crengine/.cache"), 0x100000 * 64 ) ) { CRLog::error("Cannot initialize swap directory"); } } CRLog::trace("creating main window..."); main_win = new CRJinkeDocView( wm, lString16(L"/root/crengine") ); CRLog::trace("setting colors..."); main_win->getDocView()->setBackgroundColor(0xFFFFFF); main_win->getDocView()->setTextColor(0x000000); main_win->getDocView()->setFontSize( 20 ); if ( manual_file[0] ) main_win->setHelpFile( lString16( manual_file ) ); if ( !main_win->loadDefaultCover( lString16( L"/root/abook/crengine/cr3_def_cover.png" ) ) ) if ( !main_win->loadDefaultCover( lString16( L"/home/crengine/cr3_def_cover.png" ) ) ) main_win->loadDefaultCover( lString16( L"/root/crengine/cr3_def_cover.png" ) ); if ( !main_win->loadCSS( lString16( L"/root/abook/crengine/" ) + lString16(css_file_name) ) ) if ( !main_win->loadCSS( lString16( L"/home/crengine/" ) + lString16(css_file_name) ) ) main_win->loadCSS( lString16( L"/root/crengine/" ) + lString16(css_file_name) ); main_win->setBookmarkDir( bookmarkDir ); CRLog::trace("choosing init file..."); static const lChar16 * dirs[] = { L"/root/abook/crengine/", L"/home/crengine/", L"/root/appdata/", NULL }; int i; CRLog::debug("Loading settings..."); lString16 ini; for ( i=0; dirs[i]; i++ ) { ini = lString16(dirs[i]) + ini_fname; if ( main_win->loadSettings( ini ) ) { break; } } CRLog::debug("settings at %s", UnicodeToUtf8(ini).c_str() ); #if USE_JINKE_USER_DATA!=1 if ( !main_win->loadHistory( lString16(history_file_name) ) ) { CRLog::error("Cannot read history file %s", history_file_name); } #endif LVDocView * _docview = main_win->getDocView(); _docview->setBatteryState( checkPowerState() ); //_docview->setBatteryState( ::getBatteryState() ); wm->activateWindow( main_win ); if ( !main_win->loadDocument( lString16(fileName) ) ) { printf("Cannot open book file %s\n", fileName); delete wm; return 0; } else { #ifdef ENABLE_LEDS postLeds( true ); #endif } } //_docview->setVisiblePageCount( 1 ); //tocDebugDump( _docview->getToc() ); return 1; }
void TranslationManager::loadCurrentLang() { delete translator; translator = loadLang(getLang(), ""); translator = loadLang(getLang(), "help/", translator); }
void UXTEditor::open( QString filename ) { std::vector< STRING_MANAGER::TStringInfo > &infos = d_ptr->infos; QString lang = getLang( filename ); infos.clear(); STRING_MANAGER::loadStringFile( filename.toUtf8().constData(), infos, false ); if( d_ptr->infos.size() == 0 ) { // The work file cannot be found, cannot proceed if( filename.endsWith( "wk.uxt" ) ) { QMessageBox::critical( this, tr( "Error opening file.." ), tr( "There was an error opening wk.uxt" ) ); return; } int l = filename.lastIndexOf( "/" ); if( l == -1 ) return; QString fn = filename.left( l ); fn += "/wk.uxt"; // The work file cannot be found, cannot proceed STRING_MANAGER::loadStringFile( fn.toUtf8().constData(), infos, true ); if( d_ptr->infos.size() == 0 ) { QMessageBox::critical( this, tr( "Error opening Uxt file" ), tr( "Neither the specified file nor wk.uxt could be opened." ) ); return; } d_ptr->loadedFromWK = true; } blockTableSignals( true ); d_ptr->t->clear(); d_ptr->t->setColumnCount( 2 ); d_ptr->t->setRowCount( infos.size() ); setHeaderText( "Id", lang.toUpper() + " Text" ); int i = 0; std::vector< STRING_MANAGER::TStringInfo >::const_iterator itr = infos.begin(); while( itr != infos.end() ) { const STRING_MANAGER::TStringInfo &info = *itr; QTableWidgetItem *name = new QTableWidgetItem( info.Identifier.c_str() ); QTableWidgetItem *text1 = new QTableWidgetItem( info.Text.toUtf8().c_str() ); d_ptr->t->setItem( i, 0, name ); d_ptr->t->setItem( i, 1, text1 ); if( ( info.HashValue != 0 ) && !d_ptr->loadedFromWK ) { markItemTranslated( name ); markItemTranslated( text1 ); } else { markItemUntranslated( name ); markItemUntranslated( text1 ); } ++itr; i++; } d_ptr->t->resizeColumnsToContents(); blockTableSignals( false ); setWidget( d_ptr->t ); current_file = filename; setWindowTitle( filename + "[*]" ); setWindowFilePath( filename ); }
void // // Loadwords: loads a file with target words for similarity measurements. // Will generate a random subsample if desired. // // LoadWords(istream& in, const int wordlistsize, vector<resultdata> &results, const bool normCase) { resultdata temp; vector<resultdata> wordlist; // bool done_reading_file = false; // cerr << "Reading in words from wordlist" << endl; string lang = getLang(); string tempstring = ""; while (in >> tempstring) { Float tempdouble = 0.0; if (tempstring.length() > MAX_WORDLEN) { cerr << "Yikes!!! This word was too long: " << tempstring << endl; throw Exception("Maximum Word Length was exceeded in your word list input file. Please remove it and try again."); } temp.ANS = 10000000; temp.InverseNcount = 0.0; if (normCase) { temp.word = downstring(tempstring,lang); } else { temp.word = tempstring; } temp.LDRT = tempdouble; wordlist.push_back(temp); if (in.fail()) { throw Exception("Error Reading Input File.. Not sure what went wrong!\n"); } } unsigned int numwords = wordlist.size(); cerr << "Got " << numwords << " from word list. " << endl ; if ( numwords< (unsigned int)wordlistsize) { results = wordlist; } else { cerr << " Only " << wordlistsize << " were desired. " << endl; cerr << "Generating random subsample of words." << endl; // Create subsample int seed = time(0); unsigned int randomnumber; srand(seed); set<int> wordset; vector<resultdata> subsamplewordlist; int i; // Generate random set of unique indicies for (i = 0; wordset.size() < (unsigned int)wordlistsize; i++) { randomnumber = (unsigned int)(rand() % numwords); wordset.insert(randomnumber); // cerr << randomnumber << " " << i <<endl; } // copy random words into new vector set<int>::iterator iter; cerr << endl << "Picked: "; for (iter = wordset.begin(); iter != wordset.end(); iter++) { subsamplewordlist.push_back(wordlist[*iter]); // cerr << *iter << endl; } results = subsamplewordlist; } }