MojErr MojDbPropExtractor::fromObjectImpl(const MojObject& obj, const MojDbPropExtractor& defaultConfig, const MojChar* locale) { LOG_TRACE("Entering function %s", __FUNCTION__); // super MojErr err = MojDbExtractor::fromObject(obj, locale); MojErrCheck(err); // default value m_default = defaultConfig.m_default; MojObject defaultVal; if (obj.get(DefaultKey, defaultVal)) { MojObject::Type type = defaultVal.type(); MojDbKey key; if (type == MojObject::TypeArray) { // if the value is an array, act on its elements rather than the array object itself MojObject::ConstArrayIterator end = defaultVal.arrayEnd(); for (MojObject::ConstArrayIterator j = defaultVal.arrayBegin(); j != end; ++j) { err = key.assign(*j); MojErrCheck(err); err = m_default.put(key); MojErrCheck(err); } } else { err = key.assign(defaultVal); MojErrCheck(err); err = m_default.put(key); MojErrCheck(err); } } // tokenizer m_tokenizer = defaultConfig.m_tokenizer; MojString tokenize; bool found = false; err = obj.get(TokenizeKey, tokenize, found); MojErrCheck(err); if (found) { if (tokenize == AllKey || tokenize == DefaultKey) { m_tokenizer.reset(new MojDbTextTokenizer); MojAllocCheck(m_tokenizer.get()); err = m_tokenizer->init(locale); MojErrCheck(err); } else { MojErrThrow(MojErrDbInvalidTokenization); } } // collator if (m_collation == MojDbCollationInvalid) m_collation = defaultConfig.m_collation; err = updateLocale(locale); MojErrCheck(err); // set prop err = prop(m_name); MojErrCheck(err); return MojErrNone; }
QSystemLocaleData() : lc_numeric(QLocale::C) ,lc_time(QLocale::C) ,lc_monetary(QLocale::C) ,lc_messages(QLocale::C) { updateLocale(); }
/* Saving option of using custom language */ void Settings::setLocaleCustom(bool v) { if(language_custom != v) { language_custom = v; config.setValue("LanguageCustom", language_custom); if(!language_custom) { locale = locale_system; updateLocale(); } } }
/* Saving current language */ void Settings::setLocaleCurrent(const QLocale& new_locale) { if(locale_current != new_locale) { locale_current = new_locale; config.setValue("LanguageCurrent", locale_current.name()); } if(language_custom) { locale = locale_current; updateLocale(); } }
LocaleApplication(const Wt::WEnvironment& env) : WApplication(env) { messageResourceBundle().use("templates"); new Wt::WLabel("Select your time zone: ", root()); localeCombo_ = new Wt::WComboBox(root()); info_ = new Wt::WTemplate(Wt::WString::tr("info"), root()); Wt::WReadOnlyProxyModel *regions = new Wt::WReadOnlyProxyModel(this); regions->setSourceModel(&timeZones); localeCombo_->setModel(regions); localeCombo_->setCurrentIndex (timeZones.suggestedTimeZone(env.timeZoneOffset())); localeCombo_->changed().connect(this, &LocaleApplication::updateLocale); updateLocale(); }
void Settings::load() { if(config.allKeys().size()) //if exist - reading settings { notes_path = config.value("NotesPath").toString(); last_note = config.value("LastNote").toString(); hide_start = config.value("HideStart").toBool(); // dialog_geometry = config.value("DialogGeometry").toByteArray(); dialog_state = config.value("DialogState").toByteArray(); // tab_position = TabPosition(config.value("TabPosition").toInt()); show_hidden = config.value("ShowHidden").toBool(); show_extensions = config.value("ShowExtensions").toBool(); // hide_frame = config.value("HideFrame").toBool(); stay_top = config.value("StayTop").toBool(); // single_instance = config.value("SingleInstance").toBool(); copy_start_raise = config.value("CopyStartRaise").toBool(); // note_font.fromString(config.value("NoteFont").toString()); note_links_open = config.value("NoteLinksOpen").toBool(); note_paste_plaintext = config.value("NotePastePlaintext").toBool(); // int ScriptCount = config.value("ComandCount").toInt(); for(int i=0; i<ScriptCount; ++i) { script_model.append( config.value(QString("ComandName%1").arg(i)).toString(), config.value(QString("ComandFile%1").arg(i)).toString(), config.value(QString("ComandIcon%1").arg(i)).toString()); } note_highlight = config.value("NoteHighlight").toBool(); int HighlightRuleCount = config.beginReadArray("HighlightRules"); highlight_rules.resize(HighlightRuleCount); for(int i=0; i<highlight_rules.size(); ++i) { config.setArrayIndex(i); highlight_rules[i].enabled = config.value("enabled").toBool(); highlight_rules[i].regexp = config.value("regexp").toString(); highlight_rules[i].color = QColor(config.value("color").toString()); } config.endArray(); script_show_output = config.value("ScriptShowOutput").toBool(); script_copy_output = config.value("ScriptCopyOutput").toBool(); // language_custom = config.value("LanguageCustom").toBool(); locale_current = QLocale(config.value("LanguageCurrent").toString()); // if(config.contains("Toolbar/itemCount")) { tb_items.resize(config.value("Toolbar/itemCount").toInt()); for(int i=itemAdd; i<itemMax; ++i) { int pos = config.value(ToolbarAction(item_enum(i)).pref_name(), tb_items.size()).toInt(); if(pos<tb_items.size()) tb_items[pos] = i; //Item's position } } } /* * If settings don't exist - setup default settings */ //Setting default path to notes if(notes_path.isEmpty()) { #ifdef Q_WS_X11 notes_path = QDir::homePath()+"/.local/share/notes"; #elif defined(Q_WS_WIN) QSettings win_settings("Microsoft", "Windows"); QString mydocuments_path = win_settings.value("CurrentVersion/Explorer/Shell Folders/Personal", "").toString(); if(!mydocuments_path.isEmpty()) notes_path = mydocuments_path+"/Notes"; else if(!QDir::homePath().isEmpty()) notes_path = QDir::homePath()+"/Notes"; #else if(!QDir::homePath().isEmpty()) notes_path = QDir::homePath()+"\Notes"; #endif config.setValue("NotesPath", notes_path); } //Settings single instance options if(!config.contains("SingleInstance")) { single_instance = true; config.setValue("SingleInstance", single_instance); copy_start_raise = true; config.setValue("CopyStartRaise", copy_start_raise); } //Setting default note options if(!config.contains("NoteLinksOpen")) { note_links_open = true; config.setValue("NoteLinksOpen", note_links_open); } if(!config.contains("NotePastePlaintext")) { note_paste_plaintext = false; config.setValue("NotePastePlaintext", note_paste_plaintext); } //Setting default highlight rules if(!config.contains("NoteHighlight")) { if(config.contains("NoteLinksHighlight")) note_highlight = config.value("NoteLinksHighlight").toBool(); else note_highlight = true; config.setValue("NoteHighlight", note_highlight); highlight_rules.append(HighlightRule(true, "(http|https|ftp)://\\S+", QColor(Qt::blue))); highlight_rules.append(HighlightRule(false, "(\\d{1,3}\\.){3,3}\\d{1,3}(\\:\\d+)?", QColor("#500000"))); highlight_rules.append(HighlightRule(false, "(0x|)\\d+", QColor("#147E16"))); highlight_rules.append(HighlightRule(false, "#[0-9a-fA-F]{6,6}", QColor("#CEC51B"))); config.beginWriteArray("HighlightRules", highlight_rules.size()); for(int i=0; i<highlight_rules.size(); ++i) { config.setArrayIndex(i); config.setValue("enabled", highlight_rules.at(i).enabled); config.setValue("regexp", highlight_rules.at(i).regexp); config.setValue("color", highlight_rules.at(i).color); } config.endArray(); } //Setting default scripts if((script_model.rowCount()==0) && !config.contains("ComandCount")) { #ifdef unix script_model.append("Print note's content", "cat", ""); #elif defined(Q_WS_WIN) // #endif config.setValue("ComandCount", script_model.rowCount()); for(int i=0; i<script_model.rowCount(); ++i) { config.setValue(QString("ComandName%1").arg(i), script_model.getName(i)); config.setValue(QString("ComandFile%1").arg(i), script_model.getFile(i)); config.setValue(QString("ComandIcon%1").arg(i), script_model.getIcon(i)); } } //Setting default tab position if(!config.contains("TabPosition")) { tab_position = West; config.setValue("TabPosition", tab_position); } //Setting default toolbar items if((tb_items.size()==0) && !config.contains("Toolbar/itemCount")) { tb_items.append(itemAdd); tb_items.append(itemRemove); tb_items.append(itemRename); tb_items.append(itemSeparator); tb_items.append(itemPrev); tb_items.append(itemNext); tb_items.append(itemSeparator); tb_items.append(itemCopy); tb_items.append(itemSeparator); tb_items.append(itemSetup); tb_items.append(itemInfo); tb_items.append(itemSeparator); tb_items.append(itemRun); tb_items.append(itemSearch); tb_items.append(itemSeparator); tb_items.append(itemExit); config.setValue("Toolbar/itemCount", tb_items.size()); for(int i=0; i<tb_items.size(); ++i) if(tb_items[i]!=itemSeparator) config.setValue(ToolbarAction(item_enum(tb_items[i])).pref_name(), i); } // Build two dictionaries of translation files for the program: // 1) the program translation files; // 2) qt library translation files. loadLanguages(); // #ifdef unix //Fixing Qt's problem on unix systems... QString system_lang(qgetenv("LANG").constData()); system_lang.truncate(system_lang.indexOf('.')); if(system_lang.size()) locale_system = QLocale(system_lang); else locale_system = QLocale::system().language(); #else locale_system = QLocale::system().language(); #endif locale = (language_custom)?locale_current:locale_system; // Define priority locale for user interface. // Analyze only the program translation files dictionary. QMap<int, QMap<int, QString> >::const_iterator it = translations.find(locale.language()); if(it!=translations.end()) //if translation list has locale language { const QMap<int, QString>& country_list = it.value(); if(!country_list.contains(locale.country())) { QList<QLocale::Country> language_countries = QLocale::countriesForLanguage(locale.language()); if(!language_countries.empty() && country_list.contains(language_countries[0])) { QLocale::Country country = language_countries[0]; locale = QLocale(locale.language(), country); } else if(!country_list.empty()) { QLocale::Country country = QLocale::Country(country_list.begin().key()); locale = QLocale(locale.language(), country); } else locale = QLocale::c(); } } else locale = QLocale::c(); // Load files from dictionary for defined locale. updateLocale(); qApp->installTranslator(&qtranslator); qApp->installTranslator(&translator); }