int main(int argc, char *argv[]) { QApplication a(argc, argv); a.setApplicationName("DoubanFM"); QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); //QResource::registerResource("icons.qrc"); QTranslator translator; QLocale locale; translator.load(QString(":/lang/") + QLocale::countryToString(locale.country()) + QString("_") + QLocale::languageToString(locale.language())); qDebug() << QString("Load Language: ") + QLocale::countryToString(locale.country()) + QString("_") + QLocale::languageToString(locale.language()); a.installTranslator(&translator); MainWidget mw; mw.show(); return a.exec(); }
GreetingPage::GreetingPage( QWidget* parent ) : QWidget( parent ) , ui( new Ui::GreetingPage ) { ui->setupUi( this ); QString defaultLocale = QLocale::system().name(); { foreach ( const QString& locale, QString( CALAMARES_TRANSLATION_LANGUAGES ).split( ';') ) { QLocale thisLocale = QLocale( locale ); QString lang = QLocale::languageToString( thisLocale.language() ); if ( QLocale::countriesForLanguage( thisLocale.language() ).count() > 2 ) lang.append( QString( " (%1)" ) .arg( QLocale::countryToString( thisLocale.country() ) ) ); ui->languageWidget->addItem( lang ); ui->languageWidget->item( ui->languageWidget->count() - 1 ) ->setData( Qt::UserRole, thisLocale ); if ( thisLocale.language() == QLocale( defaultLocale ).language() && thisLocale.country() == QLocale( defaultLocale ).country() ) ui->languageWidget->setCurrentRow( ui->languageWidget->count() - 1 ); } ui->languageWidget->sortItems(); connect( ui->languageWidget, &QListWidget::currentItemChanged, this, [ & ]( QListWidgetItem *current, QListWidgetItem *previous ) { QLocale selectedLocale = current->data( Qt::UserRole ).toLocale(); cDebug() << "Selected locale" << selectedLocale.name(); QLocale::setDefault( selectedLocale ); CalamaresUtils::installTranslator( selectedLocale.name(), qApp ); } ); connect( ui->languageWidget, &QListWidget::itemDoubleClicked, this, [] { Calamares::ViewManager::instance()->next(); } ); } ui->mainText->setAlignment( Qt::AlignCenter ); ui->mainText->setWordWrap( true ); ui->mainText->setOpenExternalLinks( true ); CALAMARES_RETRANSLATE( ui->mainText->setText( tr( "<h1>Welcome to the %1 installer.</h1><br/>" "This program will ask you some questions and " "set up %2 on your computer." ) .arg( Calamares::Branding::instance()-> string( Calamares::Branding::VersionedName ) ) .arg( Calamares::Branding::instance()-> string( Calamares::Branding::ProductName ) ) ); )
/** * Read the available language files and fill the combo box. */ void SettingsWidget::fillComboBoxLanguages() { QVariant dataEn; dataEn.setValue(Common::Language { "", QLocale("en") }); this->ui->cmbLanguages->addItem("English", dataEn); QLocale current = QLocale::system(); if (SETTINGS.isSet("language")) current = SETTINGS.get<QLocale>("language"); this->coreConnection->setCoreLanguage(current); bool exactMatchFound = false; Common::Languages langs(QCoreApplication::applicationDirPath() + "/" + Common::Constants::LANGUAGE_DIRECTORY); for (QListIterator<Common::Language> i(langs.getAvailableLanguages(Common::Languages::ExeType::GUI)); i.hasNext();) { Common::Language lang = i.next(); QVariant data; data.setValue(lang); this->ui->cmbLanguages->addItem(lang.locale.nativeLanguageName(), data); if (!exactMatchFound && lang.locale.language() == current.language()) { exactMatchFound = lang.locale.country() == current.country(); this->ui->cmbLanguages->setCurrentIndex(this->ui->cmbLanguages->count() - 1); } } }
void AcceptLangWidget::AddLocale (const QLocale& locale) { QList<QStandardItem*> items; items << new QStandardItem (QLocale::languageToString (locale.language ())); items << new QStandardItem (QLocale::countryToString (locale.country ())); items << new QStandardItem (Util::GetInternetLocaleName (locale)); Model_->appendRow (items); items.first ()->setData (locale, Roles::LocaleObj); }
QString Speller::nameForLanguage(const QString &code) const { QLocale loc = QLocale(code); QString name = QLocale::languageToString(loc.language()); if (loc.country() != QLocale::AnyCountry) { name.append(" / " + loc.nativeLanguageName()); } return name; }
void InfoWidget::localeChanged(QLocale locale) { setLocale(locale); name->setText(locale.name()); bcp47Name->setText(locale.bcp47Name()); languageName->setText(QLocale::languageToString(locale.language())); nativeLanguageName->setText(locale.nativeLanguageName()); scriptName->setText(QLocale::scriptToString(locale.script())); countryName->setText(QLocale::countryToString(locale.country())); nativeCountryName->setText(locale.nativeCountryName()); }
bool PhraseBook::load(const QString &fileName, bool *langGuessed) { QFile f(fileName); if (!f.open(QIODevice::ReadOnly)) return false; m_fileName = fileName; QXmlInputSource in(&f); QXmlSimpleReader reader; // don't click on these! reader.setFeature(QLatin1String("http://xml.org/sax/features/namespaces"), false); reader.setFeature(QLatin1String("http://xml.org/sax/features/namespace-prefixes"), true); reader.setFeature(QLatin1String("http://trolltech.com/xml/features/report-whitespace" "-only-CharData"), false); QphHandler *hand = new QphHandler(this); reader.setContentHandler(hand); reader.setErrorHandler(hand); bool ok = reader.parse(in); reader.setContentHandler(0); reader.setErrorHandler(0); Translator::languageAndCountry(hand->language(), &m_language, &m_country); *langGuessed = false; if (m_language == QLocale::C) { QLocale sys; m_language = sys.language(); m_country = sys.country(); *langGuessed = true; } QString lang = hand->sourceLanguage(); if (lang.isEmpty()) { m_sourceLanguage = QLocale::C; m_sourceCountry = QLocale::AnyCountry; } else { Translator::languageAndCountry(lang, &m_sourceLanguage, &m_sourceCountry); } delete hand; f.close(); if (!ok) { qDeleteAll(m_phrases); m_phrases.clear(); } else { emit listChanged(); } return ok; }
void SetupPluginsDialog::onCurrentLanguageChanged(int AIndex) { ui.cmbCountry->clear(); QLocale::Language lang = (QLocale::Language)ui.cmbLanguage->itemData(AIndex).toInt(); foreach (QLocale::Country country, QLocale::countriesForLanguage(lang)) ui.cmbCountry->addItem(QLocale::countryToString(country),(int)country); ui.cmbCountry->model()->sort(0, Qt::AscendingOrder); if (lang != QLocale::C) ui.cmbCountry->insertItem(0,tr("<Any Country>"), QLocale::AnyCountry); QLocale locale; if (locale.language() == lang) ui.cmbCountry->setCurrentIndex(ui.cmbCountry->findData((int)locale.country())); else ui.cmbCountry->setCurrentIndex(0); }
LocaleSelector::LocaleSelector(QWidget *parent) : QComboBox(parent) { int curIndex = -1; QLocale curLocale; for (int i = 0; i < SUPPORTED_LOCALES_COUNT; ++i) { const SupportedLocale &l = SUPPORTED_LOCALES[i]; if (l.lang == curLocale.language() && l.country == curLocale.country()) curIndex = i; QString text = QLocale::languageToString(QLocale::Language(l.lang)) + QLatin1Char('/') + QLocale::countryToString(QLocale::Country(l.country)); addItem(text, qVariantFromValue(l)); } setCurrentIndex(curIndex); connect(this, SIGNAL(activated(int)), this, SLOT(emitLocaleSelected(int))); }
MainWindow::MainWindow(QWidget *parent): QMainWindow(parent) { tc = NULL; mp3File = NULL; // icon setWindowIcon(WIN_ICON); // Qt Translator trans = new QTranslator(); QApplication::instance()->installTranslator(trans); // load default language QLocale *loc = new QLocale(); language = loc->language() == QLocale::Chinese? loc->country() == QLocale::China? ZHS: ZHT: ENG; delete loc; std::cout << "language: " << language << std::endl; // initial interface initWidget(); updateInterface(); }
int main(int argc, char *argv[]) { int Lang = 1; // language QString home = QDir::homePath(); QTranslator translator; QLocale locale; Lang = locale.country(); // 82 for Germany Lang = 100; // only for TEST dl1hbd - country outside Germany QApplication a(argc, argv); if(Lang != 82) { // every country except Germany home+="/log/qtlogDiag/qtlogaddQso_en"; translator.load(home); a.installTranslator(&translator); } addQso addDiag; addDiag.show(); return a.exec(); }
// ----------------------------- int main(int argc, char *argv[]) { int Lang; QString home = QDir::homePath(); QApplication a(argc, argv); QTranslator translator; QLocale locale; //if(translator.load("../laDiag/qtlogLaDialog_en")) qDebug()<<"Got the translation.\n"; Lang = locale.country(); Lang = 100; // TEST if(Lang != 82) { home+="/log/laDiag/qtlogLaDialog_en"; translator.load(home); a.installTranslator(&translator); } //a.installTranslator(&translator); laDiag lDiag; lDiag.show(); return a.exec(); }
AcceptLanguage::AcceptLanguage(QWidget* parent) : QDialog(parent) , ui(new Ui::AcceptLanguage) { ui->setupUi(this); Settings settings; settings.beginGroup("Language"); QStringList langs = settings.value("acceptLanguage", defaultLanguage()).toStringList(); foreach(const QString & code, langs) { QString code_ = code; QLocale loc = QLocale(code_.replace('-', '_')); QString label; if (loc.language() == QLocale::C) { label = tr("Personal [%1]").arg(code); } else { label = QString("%1/%2 [%3]").arg(loc.languageToString(loc.language()), loc.countryToString(loc.country()), code); } ui->listWidget->addItem(label); }
bool MessageModel::load(const QString &fileName) { MetaTranslator tor; bool ok = tor.load(fileName); if (ok) { if(tor.codecForTr()) m_codecForTr = tor.codecForTr()->name(); int messageCount = 0; clearContextList(); m_numFinished = 0; m_numNonobsolete = 0; TML all = tor.messages(); QHash<QString, ContextItem*> contexts; m_srcWords = 0; m_srcChars = 0; m_srcCharsSpc = 0; foreach(MetaTranslatorMessage mtm, all) { QCoreApplication::processEvents(); ContextItem *c; if (contexts.contains(QLatin1String(mtm.context()))) { c = contexts.value( QLatin1String(mtm.context())); } else { c = createContextItem(tor.toUnicode(mtm.context(), mtm.utf8()));; appendContextItem(c); contexts.insert(QLatin1String(mtm.context()), c); } if (QByteArray(mtm.sourceText()) == ContextComment) { c->appendToComment(tor.toUnicode(mtm.comment(), mtm.utf8())); } else { MessageItem *tmp = new MessageItem(mtm, tor.toUnicode(mtm.sourceText(), mtm.utf8()), tor.toUnicode(mtm.comment(), mtm.utf8()), c); if (mtm.type() != MetaTranslatorMessage::Obsolete) { m_numNonobsolete++; //if (mtm.type() == MetaTranslatorMessage::Finished) //tmp->setFinished(true); //++m_numFinished; doCharCounting(tmp->sourceText(), m_srcWords, m_srcChars, m_srcCharsSpc); } else { c->incrementObsoleteCount(); } c->appendMessageItem(tmp); ++messageCount; } } // Try to detect the correct language in the following order // 1. Look for the language attribute in the ts // if that fails // 2. Guestimate the language from the filename (expecting the qt_{en,de}.ts convention) // if that fails // 3. Retrieve the locale from the system. QString lang = tor.languageCode(); if (lang.isEmpty()) { int pos_sep = fileName.indexOf(QLatin1Char('_')); if (pos_sep != -1 && pos_sep + 3 <= fileName.length()) { lang = fileName.mid(pos_sep + 1, 2); } } QLocale::Language l; QLocale::Country c; MetaTranslator::languageAndCountry(lang, &l, &c); if (l == QLocale::C) { QLocale sys; l = sys.language(); c = sys.country(); } setLanguage(l); setCountry(c); m_numMessages = messageCount; updateAll(); setModified(false); }
bool RCCResourceLibrary::interpretResourceFile(QIODevice *inputDevice, const QString &fname, QString currentPath, bool ignoreErrors) { Q_ASSERT(m_errorDevice); const QChar slash = QLatin1Char('/'); if (!currentPath.isEmpty() && !currentPath.endsWith(slash)) currentPath += slash; QXmlStreamReader reader(inputDevice); QStack<RCCXmlTag> tokens; QString prefix; QLocale::Language language = QLocale::c().language(); QLocale::Country country = QLocale::c().country(); QString alias; int compressLevel = m_compressLevel; int compressThreshold = m_compressThreshold; while (!reader.atEnd()) { QXmlStreamReader::TokenType t = reader.readNext(); switch (t) { case QXmlStreamReader::StartElement: if (reader.name() == m_strings.TAG_RCC) { if (!tokens.isEmpty()) reader.raiseError(QLatin1String("expected <RCC> tag")); else tokens.push(RccTag); } else if (reader.name() == m_strings.TAG_RESOURCE) { if (tokens.isEmpty() || tokens.top() != RccTag) { reader.raiseError(QLatin1String("unexpected <RESOURCE> tag")); } else { tokens.push(ResourceTag); QXmlStreamAttributes attributes = reader.attributes(); language = QLocale::c().language(); country = QLocale::c().country(); if (attributes.hasAttribute(m_strings.ATTRIBUTE_LANG)) { QString attribute = attributes.value(m_strings.ATTRIBUTE_LANG).toString(); QLocale lang = QLocale(attribute); language = lang.language(); if (2 == attribute.length()) { // Language only country = QLocale::AnyCountry; } else { country = lang.country(); } } prefix.clear(); if (attributes.hasAttribute(m_strings.ATTRIBUTE_PREFIX)) prefix = attributes.value(m_strings.ATTRIBUTE_PREFIX).toString(); if (!prefix.startsWith(slash)) prefix.prepend(slash); if (!prefix.endsWith(slash)) prefix += slash; } } else if (reader.name() == m_strings.TAG_FILE) { if (tokens.isEmpty() || tokens.top() != ResourceTag) { reader.raiseError(QLatin1String("unexpected <FILE> tag")); } else { tokens.push(FileTag); QXmlStreamAttributes attributes = reader.attributes(); alias.clear(); if (attributes.hasAttribute(m_strings.ATTRIBUTE_ALIAS)) alias = attributes.value(m_strings.ATTRIBUTE_ALIAS).toString(); compressLevel = m_compressLevel; if (attributes.hasAttribute(m_strings.ATTRIBUTE_COMPRESS)) compressLevel = attributes.value(m_strings.ATTRIBUTE_COMPRESS).toString().toInt(); compressThreshold = m_compressThreshold; if (attributes.hasAttribute(m_strings.ATTRIBUTE_THRESHOLD)) compressThreshold = attributes.value(m_strings.ATTRIBUTE_THRESHOLD).toString().toInt(); // Special case for -no-compress. Overrides all other settings. if (m_compressLevel == -2) compressLevel = 0; } } else { reader.raiseError(QString(QLatin1String("unexpected tag: %1")).arg(reader.name().toString())); } break; case QXmlStreamReader::EndElement: if (reader.name() == m_strings.TAG_RCC) { if (!tokens.isEmpty() && tokens.top() == RccTag) tokens.pop(); else reader.raiseError(QLatin1String("unexpected closing tag")); } else if (reader.name() == m_strings.TAG_RESOURCE) { if (!tokens.isEmpty() && tokens.top() == ResourceTag) tokens.pop(); else reader.raiseError(QLatin1String("unexpected closing tag")); } else if (reader.name() == m_strings.TAG_FILE) { if (!tokens.isEmpty() && tokens.top() == FileTag) tokens.pop(); else reader.raiseError(QLatin1String("unexpected closing tag")); } break; case QXmlStreamReader::Characters: if (reader.isWhitespace()) break; if (tokens.isEmpty() || tokens.top() != FileTag) { reader.raiseError(QLatin1String("unexpected text")); } else { QString fileName = reader.text().toString(); if (fileName.isEmpty()) { const QString msg = QString::fromLatin1("RCC: Warning: Null node in XML of '%1'\n").arg(fname); m_errorDevice->write(msg.toUtf8()); } if (alias.isNull()) alias = fileName; alias = QDir::cleanPath(alias); while (alias.startsWith(QLatin1String("../"))) alias.remove(0, 3); alias = QDir::cleanPath(m_resourceRoot) + prefix + alias; QString absFileName = fileName; if (QDir::isRelativePath(absFileName)) absFileName.prepend(currentPath); QFileInfo file(absFileName); if (!file.exists()) { m_failedResources.push_back(absFileName); const QString msg = QString::fromLatin1("RCC: Error in '%1': Cannot find file '%2'\n").arg(fname).arg(fileName); m_errorDevice->write(msg.toUtf8()); if (ignoreErrors) continue; else return false; } else if (file.isFile()) { const bool arc = addFile(alias, RCCFileInfo(alias.section(slash, -1), file, language, country, RCCFileInfo::NoFlags, compressLevel, compressThreshold) ); if (!arc) m_failedResources.push_back(absFileName); } else { QDir dir; if (file.isDir()) { dir.setPath(file.filePath()); } else { dir.setPath(file.path()); dir.setNameFilters(QStringList(file.fileName())); if (alias.endsWith(file.fileName())) alias = alias.left(alias.length()-file.fileName().length()); } if (!alias.endsWith(slash)) alias += slash; QDirIterator it(dir, QDirIterator::FollowSymlinks|QDirIterator::Subdirectories); while (it.hasNext()) { it.next(); QFileInfo child(it.fileInfo()); if (child.fileName() != QLatin1String(".") && child.fileName() != QLatin1String("..")) { const bool arc = addFile(alias + child.fileName(), RCCFileInfo(child.fileName(), child, language, country, child.isDir() ? RCCFileInfo::Directory : RCCFileInfo::NoFlags, compressLevel, compressThreshold) ); if (!arc) m_failedResources.push_back(child.fileName()); } } } } break; default: break; } } if (reader.hasError()) { if (ignoreErrors) return true; int errorLine = reader.lineNumber(); int errorColumn = reader.columnNumber(); QString errorMessage = reader.errorString(); QString msg = QString::fromLatin1("RCC Parse Error: '%1' Line: %2 Column: %3 [%4]\n").arg(fname).arg(errorLine).arg(errorColumn).arg(errorMessage); m_errorDevice->write(msg.toUtf8()); return false; } if (m_root == 0) { const QString msg = QString::fromUtf8("RCC: Warning: No resources in '%1'.\n").arg(fname); m_errorDevice->write(msg.toUtf8()); if (!ignoreErrors && m_format == Binary) { // create dummy entry, otherwise loading with QResource will crash m_root = new RCCFileInfo(QString(), QFileInfo(), QLocale::C, QLocale::AnyCountry, RCCFileInfo::Directory); } } return true; }
int QResourceRoot::findNode(const QString &_path, const QLocale &locale) const { QString path = _path; { QString root = mappingRoot(); if(!root.isEmpty()) { if(root == path) { path = QLatin1Char('/'); } else { if(!root.endsWith(QLatin1Char('/'))) root += QLatin1Char('/'); if(path.size() >= root.size() && path.startsWith(root)) path = path.mid(root.length()-1); if(path.isEmpty()) path = QLatin1Char('/'); } } } #ifdef DEBUG_RESOURCE_MATCH qDebug() << "!!!!" << "START" << path << locale.country() << locale.language(); #endif if(path == QLatin1String("/")) return 0; //the root node is always first int child_count = (tree[6] << 24) + (tree[7] << 16) + (tree[8] << 8) + (tree[9] << 0); int child = (tree[10] << 24) + (tree[11] << 16) + (tree[12] << 8) + (tree[13] << 0); //now iterate up the tree int node = -1; QStringSplitter splitter(path); while (child_count && splitter.hasNext()) { QStringRef segment = splitter.next(); #ifdef DEBUG_RESOURCE_MATCH qDebug() << " CHILDREN" << segment; for(int j = 0; j < child_count; ++j) { qDebug() << " " << child+j << " :: " << name(child+j); } #endif const int h = qHash(segment); //do the binary search for the hash int l = 0, r = child_count-1; int sub_node = (l+r+1)/2; while(r != l) { const int sub_node_hash = hash(child+sub_node); if(h == sub_node_hash) break; else if(h < sub_node_hash) r = sub_node - 1; else l = sub_node; sub_node = (l + r + 1) / 2; } sub_node += child; //now do the "harder" compares bool found = false; if(hash(sub_node) == h) { while(sub_node > child && hash(sub_node-1) == h) //backup for collisions --sub_node; for(; sub_node < child+child_count && hash(sub_node) == h; ++sub_node) { //here we go... if(name(sub_node) == segment) { found = true; int offset = findOffset(sub_node); #ifdef DEBUG_RESOURCE_MATCH qDebug() << " TRY" << sub_node << name(sub_node) << offset; #endif offset += 4; //jump past name const short flags = (tree[offset+0] << 8) + (tree[offset+1] << 0); offset += 2; if(!splitter.hasNext()) { if(!(flags & Directory)) { const short country = (tree[offset+0] << 8) + (tree[offset+1] << 0); offset += 2; const short language = (tree[offset+0] << 8) + (tree[offset+1] << 0); offset += 2; #ifdef DEBUG_RESOURCE_MATCH qDebug() << " " << "LOCALE" << country << language; #endif if(country == locale.country() && language == locale.language()) { #ifdef DEBUG_RESOURCE_MATCH qDebug() << "!!!!" << "FINISHED" << __LINE__ << sub_node; #endif return sub_node; } else if((country == QLocale::AnyCountry && language == locale.language()) || (country == QLocale::AnyCountry && language == QLocale::C && node == -1)) { node = sub_node; } continue; } else { #ifdef DEBUG_RESOURCE_MATCH qDebug() << "!!!!" << "FINISHED" << __LINE__ << sub_node; #endif return sub_node; } } if(!(flags & Directory)) return -1; child_count = (tree[offset+0] << 24) + (tree[offset+1] << 16) + (tree[offset+2] << 8) + (tree[offset+3] << 0); offset += 4; child = (tree[offset+0] << 24) + (tree[offset+1] << 16) + (tree[offset+2] << 8) + (tree[offset+3] << 0); break; } } } if(!found) break; } #ifdef DEBUG_RESOURCE_MATCH qDebug() << "!!!!" << "FINISHED" << __LINE__ << node; #endif return node; }
void InfoLoader::run() { QFile htmlfile("://Qt_info.html"); htmlfile.open(QIODevice::ReadOnly); html = htmlfile.readAll(); // QString loadinghtml = html; // loadinghtml.replace("__SECTIONTEMPLATE__", "Please wait, reading data"); // ui->webView->setHtml(loadinghtml,QUrl("qrc:/")); QString key = "Qt version"; QString value = qVersion(); QStringList valuelist; qDebug() << key << value ; addToTemplate(key, value); #if QT_VERSION >= 0x050000 addToTemplate("Platform", qApp->platformName()); #endif emit newInfoAvailable("Checking build date..."); key = "Qt build"; value = QLibraryInfo::buildDate().toString()+ ", "; #if QT_VERSION < 0x050000 value += QLibraryInfo::buildKey() + ", "; #endif value += QLibraryInfo::licensee(); addToTemplate(key, value); emit newInfoAvailable("Checking country/language..."); key = "Country"; QLocale defaultlocale; value = QLocale::countryToString(defaultlocale.country()); addToTemplate(key, value); key = "Language"; value = QLocale::languageToString(defaultlocale.language()) + " (" + defaultlocale.name() + ")"; addToTemplate(key, value); emit newInfoAvailable("Checking Qt modules..."); key = "Qt modules"; value = ""; QStringList qtlibs; QStringList qtmobilitylibs; qtlibs << "Qt3Support"; qtlibs << "QAxContainer"; qtlibs << "QAxServer"; qtlibs << "QtCLucene"; qtlibs << "QtCore"; qtlibs << "QtDBus"; qtlibs << "QtDeclarative"; // 4.7 qtlibs << "QtDesignerComponents"; qtlibs << "QtDesigner"; qtlibs << "QtGui"; qtlibs << "QtHelp"; qtlibs << "QtMultimedia"; qtlibs << "QtMaemo5"; // 4.6 qtlibs << "phonon"; qtlibs << "QtNetwork"; // includes QtBearer starting w 4.7 qtlibs << "QtOpenGL"; qtlibs << "QtOpenVG"; // 4.6 qtlibs << "QtScript"; qtlibs << "QtScriptTools"; qtlibs << "QtSql"; qtlibs << "QtSvg"; qtlibs << "QtTest"; qtlibs << "QtUiTools"; qtlibs << "QtWebKit"; qtlibs << "QtXmlPatterns"; qtlibs << "QtXml"; qtlibs << "Qt5AndroidExtras"; // 5.2 qtlibs << "Qt5Bluetooth"; // 5.2 qtlibs << "Qt5CLucene"; qtlibs << "Qt5Concurrent"; qtlibs << "Qt5Core"; qtlibs << "Qt5Declarative"; qtlibs << "Qt5DBus"; qtlibs << "Qt5Designer"; qtlibs << "Qt5DesignerComponents"; qtlibs << "Qt5Gui"; qtlibs << "Qt5Help"; qtlibs << "Qt5MacExtras"; // 5.2 qtlibs << "Qt5Multimedia"; qtlibs << "Qt5MultimediaQuick_p"; qtlibs << "Qt5MultimediaWidgets"; qtlibs << "Qt5Network"; qtlibs << "Qt5Nfc"; // 5.2 qtlibs << "Qt5OpenGL"; qtlibs << "Qt5Positioning"; // 5.2 qtlibs << "Qt5PrintSupport"; qtlibs << "Qt5Qml"; qtlibs << "Qt5Quick"; qtlibs << "Qt5QuickParticles"; qtlibs << "Qt5QuickTest"; qtlibs << "Qt5SerialPort"; // 5.1 qtlibs << "Qt5Script"; qtlibs << "Qt5ScriptTools"; qtlibs << "Qt5Sensors"; // 5.1 qtlibs << "Qt5Sql"; qtlibs << "Qt5Svg"; qtlibs << "Qt5Test"; qtlibs << "Qt5V8"; qtlibs << "Qt5WebKit"; qtlibs << "Qt5WebKitWidgets"; qtlibs << "Qt5Widgets"; qtlibs << "Qt5WinExtras"; // 5.2 qtlibs << "Qt5X11Extras"; // 5.1 qtlibs << "Qt5Xml"; qtlibs << "Qt5XmlPatterns"; qtmobilitylibs << "QtBearer"; // 1.0.x ONLY qtmobilitylibs << "QtConnectivity"; // 1.2 qtmobilitylibs << "QtContacts"; qtmobilitylibs << "QtFeedback"; // 1.1 qtmobilitylibs << "QtGallery"; // 1.1 qtmobilitylibs << "QtLocation"; qtmobilitylibs << "QtMultimediaKit"; qtmobilitylibs << "QtSensors"; qtmobilitylibs << "QtServiceFramework"; qtmobilitylibs << "QtSystemInfo"; qtmobilitylibs << "QtOrganizer"; // 1.1 qtmobilitylibs << "QtPublishSubscribe"; qtmobilitylibs << "QtVersitOrganizer"; // 1.1 qtmobilitylibs << "QtVersit"; qtlibs.append(qtmobilitylibs); int progressTotalSteps = qtlibs.count() + 14; // 14 = number of loadInfos we're going to do later. #automateme int progressStep = 0; foreach(QString libname, qtlibs) { emit newInfoAvailable(QString("Locating %0...").arg(libname)); QString libfilename = loadLib(libname); if (!libfilename.isEmpty()) { emit newInfoAvailable(QString("Found as %0 ").arg(libfilename)); value += libname.replace("lib", "") + " "; installedlibs << libname; } else { emit newInfoAvailable(QString("Not found")); } emit progressChange((int)(++progressStep*100.0/(float)progressTotalSteps)); }
QString getLocaleCountryCode(const QLocale &locale) { switch(locale.country()) { case QLocale::Country::Afghanistan: return "AF"; case QLocale::Country::Albania: return "AL"; case QLocale::Country::Algeria: return "DZ"; case QLocale::Country::AmericanSamoa: return "AS"; case QLocale::Country::Andorra: return "AD"; case QLocale::Country::Angola: return "AO"; case QLocale::Country::Anguilla: return "AI"; case QLocale::Country::Antarctica: return "AQ"; case QLocale::Country::AntiguaAndBarbuda: return "AG"; case QLocale::Country::Argentina: return "AR"; case QLocale::Country::Armenia: return "AM"; case QLocale::Country::Aruba: return "AW"; case QLocale::Country::Australia: return "AU"; case QLocale::Country::Austria: return "AT"; case QLocale::Country::Azerbaijan: return "AZ"; case QLocale::Country::Bahamas: return "BS"; case QLocale::Country::Bahrain: return "BH"; case QLocale::Country::Bangladesh: return "BD"; case QLocale::Country::Barbados: return "BB"; case QLocale::Country::Belarus: return "BY"; case QLocale::Country::Belgium: return "BE"; case QLocale::Country::Belize: return "BZ"; case QLocale::Country::Benin: return "BJ"; case QLocale::Country::Bermuda: return "BM"; case QLocale::Country::Bhutan: return "BT"; case QLocale::Country::Bolivia: return "BO"; case QLocale::Country::BosniaAndHerzegowina: return "BA"; case QLocale::Country::Botswana: return "BW"; case QLocale::Country::BouvetIsland: return "BV"; case QLocale::Country::Brazil: return "BR"; case QLocale::Country::BritishIndianOceanTerritory: return "IO"; case QLocale::Country::Bulgaria: return "BG"; case QLocale::Country::BurkinaFaso: return "BF"; case QLocale::Country::Burundi: return "BI"; case QLocale::Country::Cambodia: return "KH"; case QLocale::Country::Cameroon: return "CM"; case QLocale::Country::Canada: return "CA"; case QLocale::Country::CaymanIslands: return "KY"; case QLocale::Country::CentralAfricanRepublic: return "CF"; case QLocale::Country::Chad: return "TD"; case QLocale::Country::Chile: return "CL"; case QLocale::Country::China: return "CN"; case QLocale::Country::ChristmasIsland: return "CX"; case QLocale::Country::CocosIslands: return "CC"; case QLocale::Country::Colombia: return "CO"; case QLocale::Country::Comoros: return "KM"; case QLocale::Country::DemocraticRepublicOfCongo: case QLocale::Country::PeoplesRepublicOfCongo: return "CD"; case QLocale::Country::CookIslands: return "CK"; case QLocale::Country::CostaRica: return "CR"; case QLocale::Country::IvoryCoast: return "CI"; case QLocale::Country::Croatia: return "HR"; case QLocale::Country::Cuba: return "CU"; case QLocale::Country::Cyprus: return "CY"; case QLocale::Country::CzechRepublic: return "CZ"; case QLocale::Country::Denmark: return "DK"; case QLocale::Country::Djibouti: return "DJ"; case QLocale::Country::Dominica: return "DM"; case QLocale::Country::DominicanRepublic: return "DO"; case QLocale::Country::EastTimor: return "TL"; case QLocale::Country::Ecuador: return "EC"; case QLocale::Country::Egypt: return "EG"; case QLocale::Country::ElSalvador: return "SV"; case QLocale::Country::EquatorialGuinea: return "GQ"; case QLocale::Country::Eritrea: return "ER"; case QLocale::Country::Estonia: return "EE"; case QLocale::Country::Ethiopia: return "ET"; case QLocale::Country::FalklandIslands: return "FK"; case QLocale::Country::FaroeIslands: return "FO"; case QLocale::Country::Finland: return "FI"; case QLocale::Country::France: return "FR"; case QLocale::Country::FrenchGuiana: return "GF"; case QLocale::Country::FrenchPolynesia: return "PF"; case QLocale::Country::FrenchSouthernTerritories: return "TF"; case QLocale::Country::Gabon: return "GA"; case QLocale::Country::Gambia: return "GM"; case QLocale::Country::Georgia: return "GE"; case QLocale::Country::Germany: return "DE"; case QLocale::Country::Ghana: return "GH"; case QLocale::Country::Gibraltar: return "GI"; case QLocale::Country::Greece: return "GR"; case QLocale::Country::Greenland: return "GL"; case QLocale::Country::Grenada: return "GD"; case QLocale::Country::Guadeloupe: return "GP"; case QLocale::Country::Guam: return "GU"; case QLocale::Country::Guatemala: return "GT"; case QLocale::Country::Guinea: return "GN"; case QLocale::Country::GuineaBissau: return "GW"; case QLocale::Country::Guyana: return "GY"; case QLocale::Country::Haiti: return "HT"; case QLocale::Country::HeardAndMcDonaldIslands: return "HM"; case QLocale::Country::Honduras: return "HN"; case QLocale::Country::HongKong: return "HK"; case QLocale::Country::Hungary: return "HU"; case QLocale::Country::Iceland: return "IS"; case QLocale::Country::India: return "IN"; case QLocale::Country::Indonesia: return "ID"; case QLocale::Country::Iran: return "IR"; case QLocale::Country::Iraq: return "IQ"; case QLocale::Country::Ireland: return "IE"; case QLocale::Country::Israel: return "IL"; case QLocale::Country::Italy: return "IT"; case QLocale::Country::Jamaica: return "JM"; case QLocale::Country::Japan: return "JP"; case QLocale::Country::Jordan: return "JO"; case QLocale::Country::Kazakhstan: return "KZ"; case QLocale::Country::Kenya: return "KE"; case QLocale::Country::Kiribati: return "KI"; case QLocale::Country::DemocraticRepublicOfKorea: return "KP"; case QLocale::Country::RepublicOfKorea: return "KR"; case QLocale::Country::Kuwait: return "KW"; case QLocale::Country::Kyrgyzstan: return "KG"; case QLocale::Country::Latvia: return "LV"; case QLocale::Country::Lebanon: return "LB"; case QLocale::Country::Lesotho: return "LS"; case QLocale::Country::Liberia: return "LR"; case QLocale::Country::Liechtenstein: return "LI"; case QLocale::Country::Lithuania: return "LT"; case QLocale::Country::Luxembourg: return "LU"; case QLocale::Country::Macau: return "MO"; case QLocale::Country::Macedonia: return "MK"; case QLocale::Country::Madagascar: return "MG"; case QLocale::Country::Malawi: return "MW"; case QLocale::Country::Malaysia: return "MY"; case QLocale::Country::Maldives: return "MV"; case QLocale::Country::Mali: return "ML"; case QLocale::Country::Malta: return "MT"; case QLocale::Country::MarshallIslands: return "MH"; case QLocale::Country::Martinique: return "MQ"; case QLocale::Country::Mauritania: return "MR"; case QLocale::Country::Mauritius: return "MU"; case QLocale::Country::Mayotte: return "YT"; case QLocale::Country::Mexico: return "MX"; case QLocale::Country::Micronesia: return "FM"; case QLocale::Country::Monaco: return "MC"; case QLocale::Country::Mongolia: return "MN"; case QLocale::Country::Montserrat: return "MS"; case QLocale::Country::Morocco: return "MA"; case QLocale::Country::Mozambique: return "MZ"; case QLocale::Country::Myanmar: return "MM"; case QLocale::Country::Namibia: return "NA"; case QLocale::Country::NauruCountry: return "NR"; case QLocale::Country::Nepal: return "NP"; case QLocale::Country::Netherlands: return "NL"; case QLocale::Country::NewCaledonia: return "NC"; case QLocale::Country::NewZealand: return "NZ"; case QLocale::Country::Nicaragua: return "NI"; case QLocale::Country::Niger: return "NE"; case QLocale::Country::Nigeria: return "NG"; case QLocale::Country::Niue: return "NU"; case QLocale::Country::NorfolkIsland: return "NF"; case QLocale::Country::NorthernMarianaIslands: return "MP"; case QLocale::Country::Norway: return "NO"; case QLocale::Country::Oman: return "OM"; case QLocale::Country::Pakistan: return "PK"; case QLocale::Country::Palau: return "PW"; case QLocale::Country::Panama: return "PA"; case QLocale::Country::PapuaNewGuinea: return "PG"; case QLocale::Country::Paraguay: return "PY"; case QLocale::Country::Peru: return "PE"; case QLocale::Country::Philippines: return "PH"; case QLocale::Country::Pitcairn: return "PN"; case QLocale::Country::Poland: return "PL"; case QLocale::Country::Portugal: return "PT"; case QLocale::Country::PuertoRico: return "PR"; case QLocale::Country::Qatar: return "QA"; case QLocale::Country::Reunion: return "RE"; case QLocale::Country::Romania: return "RO"; case QLocale::Country::RussianFederation: return "RU"; case QLocale::Country::Rwanda: return "RW"; case QLocale::Country::SaintKittsAndNevis: return "KN"; case QLocale::Country::Samoa: return "WS"; case QLocale::Country::SanMarino: return "SM"; case QLocale::Country::SaoTomeAndPrincipe: return "ST"; case QLocale::Country::SaudiArabia: return "SA"; case QLocale::Country::Senegal: return "SN"; case QLocale::Country::Seychelles: return "SC"; case QLocale::Country::SierraLeone: return "SL"; case QLocale::Country::Singapore: return "SG"; case QLocale::Country::Slovakia: return "SK"; case QLocale::Country::Slovenia: return "SI"; case QLocale::Country::SolomonIslands: return "SB"; case QLocale::Country::Somalia: return "SO"; case QLocale::Country::SouthAfrica: return "ZA"; case QLocale::Country::SouthGeorgiaAndTheSouthSandwichIslands: return "GS"; case QLocale::Country::Spain: return "ES"; case QLocale::Country::SriLanka: return "LK"; case QLocale::Country::Sudan: return "SD"; case QLocale::Country::Suriname: return "SR"; case QLocale::Country::SvalbardAndJanMayenIslands: return "SJ"; case QLocale::Country::Swaziland: return "SZ"; case QLocale::Country::Sweden: return "SE"; case QLocale::Country::Switzerland: return "CH"; case QLocale::Country::SyrianArabRepublic: return "SY"; case QLocale::Country::Taiwan: return "TW"; case QLocale::Country::Tajikistan: return "TJ"; case QLocale::Country::Tanzania: return "TZ"; case QLocale::Country::Thailand: return "TH"; case QLocale::Country::Togo: return "TG"; case QLocale::Country::Tokelau: return "TK"; case QLocale::Country::TrinidadAndTobago: return "TT"; case QLocale::Country::Tunisia: return "TN"; case QLocale::Country::Turkey: return "TR"; case QLocale::Country::Turkmenistan: return "TM"; case QLocale::Country::TurksAndCaicosIslands: return "TC"; case QLocale::Country::Tuvalu: return "TV"; case QLocale::Country::Uganda: return "UG"; case QLocale::Country::Ukraine: return "UA"; case QLocale::Country::UnitedArabEmirates: return "AE"; case QLocale::Country::UnitedKingdom: return "GB"; case QLocale::Country::UnitedStates: case QLocale::Country::AnyCountry: return "US"; case QLocale::Country::UnitedStatesMinorOutlyingIslands: return "UM"; case QLocale::Country::Uruguay: return "UY"; case QLocale::Country::Uzbekistan: return "UZ"; case QLocale::Country::Vanuatu: return "VU"; case QLocale::Country::VaticanCityState: return "VA"; case QLocale::Country::Venezuela: return "VE"; case QLocale::Country::BritishVirginIslands: return "VG"; case QLocale::Country::WallisAndFutunaIslands: return "WF"; case QLocale::Country::WesternSahara: return "EH"; case QLocale::Country::Yemen: return "YE"; case QLocale::Country::Zambia: return "ZM"; case QLocale::Country::Zimbabwe: return "ZW"; case QLocale::Country::Montenegro: return "ME"; case QLocale::Country::Serbia: return "RS"; case QLocale::Country::SaintBarthelemy: return "BL"; case QLocale::Country::SaintMartin: return "MF"; default: return QString(); } }
// Apply a simple variant type to a DOM property static bool applySimpleProperty(const QVariant &v, bool translateString, DomProperty *dom_prop) { switch (v.type()) { case QVariant::String: { DomString *str = new DomString(); str->setText(v.toString()); if (!translateString) str->setAttributeNotr(QStringLiteral("true")); dom_prop->setElementString(str); } return true; case QVariant::ByteArray: dom_prop->setElementCstring(QString::fromUtf8(v.toByteArray())); return true; case QVariant::Int: dom_prop->setElementNumber(v.toInt()); return true; case QVariant::UInt: dom_prop->setElementUInt(v.toUInt()); return true; case QVariant::LongLong: dom_prop->setElementLongLong(v.toLongLong()); return true; case QVariant::ULongLong: dom_prop->setElementULongLong(v.toULongLong()); return true; case QVariant::Double: dom_prop->setElementDouble(v.toDouble()); return true; case QVariant::Bool: dom_prop->setElementBool(v.toBool() ? QFormBuilderStrings::instance().trueValue : QFormBuilderStrings::instance().falseValue); return true; case QVariant::Char: { DomChar *ch = new DomChar(); const QChar character = v.toChar(); ch->setElementUnicode(character.unicode()); dom_prop->setElementChar(ch); } return true; case QVariant::Point: { DomPoint *pt = new DomPoint(); const QPoint point = v.toPoint(); pt->setElementX(point.x()); pt->setElementY(point.y()); dom_prop->setElementPoint(pt); } return true; case QVariant::PointF: { DomPointF *ptf = new DomPointF(); const QPointF pointf = v.toPointF(); ptf->setElementX(pointf.x()); ptf->setElementY(pointf.y()); dom_prop->setElementPointF(ptf); } return true; case QVariant::Color: { DomColor *clr = new DomColor(); const QColor color = qvariant_cast<QColor>(v); clr->setElementRed(color.red()); clr->setElementGreen(color.green()); clr->setElementBlue(color.blue()); const int alphaChannel = color.alpha(); if (alphaChannel != 255) clr->setAttributeAlpha(alphaChannel); dom_prop->setElementColor(clr); } return true; case QVariant::Size: { DomSize *sz = new DomSize(); const QSize size = v.toSize(); sz->setElementWidth(size.width()); sz->setElementHeight(size.height()); dom_prop->setElementSize(sz); } return true; case QVariant::SizeF: { DomSizeF *szf = new DomSizeF(); const QSizeF sizef = v.toSizeF(); szf->setElementWidth(sizef.width()); szf->setElementHeight(sizef.height()); dom_prop->setElementSizeF(szf); } return true; case QVariant::Rect: { DomRect *rc = new DomRect(); const QRect rect = v.toRect(); rc->setElementX(rect.x()); rc->setElementY(rect.y()); rc->setElementWidth(rect.width()); rc->setElementHeight(rect.height()); dom_prop->setElementRect(rc); } return true; case QVariant::RectF: { DomRectF *rcf = new DomRectF(); const QRectF rectf = v.toRectF(); rcf->setElementX(rectf.x()); rcf->setElementY(rectf.y()); rcf->setElementWidth(rectf.width()); rcf->setElementHeight(rectf.height()); dom_prop->setElementRectF(rcf); } return true; case QVariant::Font: { DomFont *fnt = new DomFont(); const QFont font = qvariant_cast<QFont>(v); const uint mask = font.resolve(); if (mask & QFont::WeightResolved) { fnt->setElementBold(font.bold()); fnt->setElementWeight(font.weight()); } if (mask & QFont::FamilyResolved) fnt->setElementFamily(font.family()); if (mask & QFont::StyleResolved) fnt->setElementItalic(font.italic()); if (mask & QFont::SizeResolved) fnt->setElementPointSize(font.pointSize()); if (mask & QFont::StrikeOutResolved) fnt->setElementStrikeOut(font.strikeOut()); if (mask & QFont::UnderlineResolved) fnt->setElementUnderline(font.underline()); if (mask & QFont::KerningResolved) fnt->setElementKerning(font.kerning()); if (mask & QFont::StyleStrategyResolved) { const QMetaEnum styleStrategy_enum = metaEnum<QAbstractFormBuilderGadget>("styleStrategy"); fnt->setElementStyleStrategy(QLatin1String(styleStrategy_enum.valueToKey(font.styleStrategy()))); } dom_prop->setElementFont(fnt); } return true; #ifndef QT_NO_CURSOR case QVariant::Cursor: { const QMetaEnum cursorShape_enum = metaEnum<QAbstractFormBuilderGadget>("cursorShape"); dom_prop->setElementCursorShape(QLatin1String(cursorShape_enum.valueToKey(qvariant_cast<QCursor>(v).shape()))); } return true; #endif case QVariant::KeySequence: { DomString *s = new DomString(); s->setText(qvariant_cast<QKeySequence>(v).toString(QKeySequence::PortableText)); dom_prop->setElementString(s); } return true; case QVariant::Locale: { DomLocale *dom = new DomLocale(); const QLocale locale = qvariant_cast<QLocale>(v); const QMetaEnum language_enum = metaEnum<QAbstractFormBuilderGadget>("language"); const QMetaEnum country_enum = metaEnum<QAbstractFormBuilderGadget>("country"); dom->setAttributeLanguage(QLatin1String(language_enum.valueToKey(locale.language()))); dom->setAttributeCountry(QLatin1String(country_enum.valueToKey(locale.country()))); dom_prop->setElementLocale(dom); } return true; case QVariant::SizePolicy: { DomSizePolicy *dom = new DomSizePolicy(); const QSizePolicy sizePolicy = qvariant_cast<QSizePolicy>(v); dom->setElementHorStretch(sizePolicy.horizontalStretch()); dom->setElementVerStretch(sizePolicy.verticalStretch()); const QMetaEnum sizeType_enum = metaEnum<QAbstractFormBuilderGadget>("sizeType"); dom->setAttributeHSizeType(QLatin1String(sizeType_enum.valueToKey(sizePolicy.horizontalPolicy()))); dom->setAttributeVSizeType(QLatin1String(sizeType_enum.valueToKey(sizePolicy.verticalPolicy()))); dom_prop->setElementSizePolicy(dom); } return true; case QVariant::Date: { DomDate *dom = new DomDate(); const QDate date = qvariant_cast<QDate>(v); dom->setElementYear(date.year()); dom->setElementMonth(date.month()); dom->setElementDay(date.day()); dom_prop->setElementDate(dom); } return true; case QVariant::Time: { DomTime *dom = new DomTime(); const QTime time = qvariant_cast<QTime>(v); dom->setElementHour(time.hour()); dom->setElementMinute(time.minute()); dom->setElementSecond(time.second()); dom_prop->setElementTime(dom); } return true; case QVariant::DateTime: { DomDateTime *dom = new DomDateTime(); const QDateTime dateTime = qvariant_cast<QDateTime>(v); dom->setElementHour(dateTime.time().hour()); dom->setElementMinute(dateTime.time().minute()); dom->setElementSecond(dateTime.time().second()); dom->setElementYear(dateTime.date().year()); dom->setElementMonth(dateTime.date().month()); dom->setElementDay(dateTime.date().day()); dom_prop->setElementDateTime(dom); } return true; case QVariant::Url: { DomUrl *dom = new DomUrl(); const QUrl url = v.toUrl(); DomString *str = new DomString(); str->setText(url.toString()); dom->setElementString(str); dom_prop->setElementUrl(dom); } return true; case QVariant::StringList: { DomStringList *sl = new DomStringList; sl->setElementString(qvariant_cast<QStringList>(v)); dom_prop->setElementStringList(sl); } return true; default: break; } return false; }
int main(int argc, char *argv[]) { QDir dir(QDir::homePath()); dir.mkdir(Configuration::CacheDirectory); qInstallMsgHandler(handleMessage); QApplication app(argc, argv); QLocale systemLocale = QLocale::system(); Services::initialize(); Configuration *config = Configuration::getInstance(); config->load(); QTranslator translator; translator.load(QString(":/translations/qwit_") + (config->language == "system" ? systemLocale.name() : config->language)); app.installTranslator(&translator); Configuration::TranslationsCodes.push_back("system"); Configuration::TranslationsCountries.push_back(systemLocale.name().mid(3, 2)); Configuration::TranslationsTitles.push_back(app.tr("System (%1, %2)").arg(systemLocale.languageToString(systemLocale.language())).arg(systemLocale.countryToString(systemLocale.country()))); QDir translationsDir(":/translations"); QStringList translationNames = translationsDir.entryList(QStringList("*.qm"), QDir::Files, QDir::Name); QMutableStringListIterator i(translationNames); while (i.hasNext()) { i.next(); QString languageCode = i.value().mid(5, 5); QLocale locale(languageCode); Configuration::TranslationsCodes.push_back(languageCode); Configuration::TranslationsCountries.push_back(languageCode.mid(3, 2)); Configuration::TranslationsTitles.push_back(QString("%1, %2").arg(systemLocale.languageToString(locale.language())).arg(systemLocale.countryToString(locale.country()))); } MainWindow *mainWindow = MainWindow::getInstance(); if (!config->startMinimized) mainWindow->show(); return app.exec(); }
void Preferences::init() { m_locale = s_defaultLocale; m_localeRegion = s_defaultLocaleRegion; m_phoneRegion = s_defaultPhoneRegion; // We open the preferences database and read the locale setting. // avoid waiting for the system-service to come up // and we waiting synchronously to get the locale value sqlite3* prefsDb = 0; sqlite3_stmt* statement = 0; const char* tail = 0; json_object* label = 0; json_object* json = 0; json_object* subobj = 0; std::string localeCountryCode; int ret = sqlite3_open(s_prefsDbPath, &prefsDb); if (ret) { luna_critical(s_logChannel, "Failed to open preferences db"); goto Done; } // immediately read lock timeout ret = sqlite3_prepare(prefsDb, "SELECT * FROM Preferences WHERE KEY='lockTimeout'", -1, &statement, &tail); if (ret) { luna_critical(s_logChannel, "Failed to prepare query"); goto Done; } ret = sqlite3_step(statement); if (ret == SQLITE_ROW) { m_lockTimeout = static_cast<uint32_t>( sqlite3_column_int(statement, 1) ); } else { setLockTimeout(m_lockTimeout); } sqlite3_finalize(statement); // immediately read locale ret = sqlite3_prepare(prefsDb, "SELECT * FROM Preferences WHERE KEY='locale'", -1, &statement, &tail); if (ret) { luna_critical(s_logChannel, "Failed to prepare query"); goto Done; } ret = sqlite3_step(statement); if (ret == SQLITE_ROW) { std::string languageCode, countryCode; const char* val = (const char*) sqlite3_column_text(statement, 1); if (!val) goto Done; label = 0; json = json_tokener_parse(val); if (!json || is_error(json)) goto Done; label = json_object_object_get(json, "languageCode"); if (!label || is_error(label)) goto Done; languageCode = json_object_get_string(label); label = json_object_object_get(json, "countryCode"); if (!label || is_error(label)) goto Done; countryCode = json_object_get_string(label); localeCountryCode = countryCode; m_locale = languageCode + "_" + countryCode; subobj = json_object_object_get(json, "phoneRegion"); if (subobj && !is_error(subobj)){ label = json_object_object_get(subobj, "countryCode"); if (label && !is_error(label)){ m_phoneRegion = json_object_get_string(label); } } json_object_put(json); json = 0; } sqlite3_finalize(statement); // immediately read regon ret = sqlite3_prepare(prefsDb, "SELECT * FROM Preferences WHERE KEY='region'", -1, &statement, &tail); if (ret) { luna_critical(s_logChannel, "Failed to prepare query"); goto Done; } ret = sqlite3_step(statement); if (ret == SQLITE_ROW) { const char* val = (const char*) sqlite3_column_text(statement, 1); if (!val) goto Done; label = 0; json = json_tokener_parse(val); if (!json || is_error(json)) goto Done; label = json_object_object_get(json, "countryCode"); if (!label || is_error(label)) goto Done; m_localeRegion = json_object_get_string(label); json_object_put(json); json = 0; } Done: QLocale myLocale (m_locale.c_str()); g_message ("%s: setting locale country %d language %d", __PRETTY_FUNCTION__, myLocale.country(), myLocale.language()); QLocale::setDefault (myLocale); // locale region defaults to locale country code if (m_localeRegion.empty()) m_localeRegion = localeCountryCode; if (m_phoneRegion.empty()) m_phoneRegion = m_localeRegion; if (json && !is_error(json)) json_object_put(json); if (statement) sqlite3_finalize(statement); if (prefsDb) sqlite3_close(prefsDb); }
int QResource::findNode(const QString &path) const { if(path == QLatin1String("/")) return 0; //the root node is always first int child_count = (tree[6] << 24) + (tree[7] << 16) + (tree[8] << 8) + (tree[9] << 0); int child = (tree[10] << 24) + (tree[11] << 16) + (tree[12] << 8) + (tree[13] << 0); //now iterate up the tree int node = -1; QLocale locale; QStringList segments = path.split('/', QString::SkipEmptyParts); for(int i = 0; child_count && i < segments.size(); ++i) { const QString &segment = segments[i]; const int h = qHash(segment); //do the binary search for the hash int l = 0, r = child_count-1; int sub_node = (l+r+1)/2; while(r != l) { const int sub_node_hash = hash(child+sub_node); if(h == sub_node_hash) break; else if(h < sub_node_hash) r = sub_node - 1; else l = sub_node; sub_node = (l + r + 1) / 2; } sub_node += child; //now do the "harder" compares bool found = false; if(hash(sub_node) == h) { while(sub_node > child && hash(sub_node-1) == h) //backup for collisions --sub_node; for(; sub_node < child+child_count && hash(sub_node) == h; ++sub_node) { //here we go... if(name(sub_node) == segment) { found = true; int offset = findOffset(sub_node) + 4; //jump past name const short flags = (tree[offset+0] << 8) + (tree[offset+1] << 0); offset += 2; if(i == segments.size()-1) { if(!(flags & Directory)) { const short country = (tree[offset+0] << 8) + (tree[offset+1] << 0); offset += 2; const short language = (tree[offset+0] << 8) + (tree[offset+1] << 0); offset += 2; if(country == locale.country() && language == locale.language()) return sub_node; else if((country == QLocale::AnyCountry && language == locale.language()) || (country == QLocale::AnyCountry && language == QLocale::C && node == -1)) node = sub_node; continue; } else { return sub_node; } } if(!(flags & Directory)) return -1; child_count = (tree[offset+0] << 24) + (tree[offset+1] << 16) + (tree[offset+2] << 8) + (tree[offset+3] << 0); offset += 4; child = (tree[offset+0] << 24) + (tree[offset+1] << 16) + (tree[offset+2] << 8) + (tree[offset+3] << 0); break; } } } if(!found) break; } return node; }
QString QLocaleToString (const QLocale &locale) { return QString ("%1/%2") .arg (QLocale::languageToString (locale.language())) .arg (QLocale::countryToString(locale.country())); }
QString QAndroidTimeZonePrivate::displayName(QTimeZone::TimeType timeType, QTimeZone::NameType nameType, const QLocale &locale) const { QString name; if (androidTimeZone.isValid()) { jboolean daylightTime = (timeType == QTimeZone::DaylightTime); // treat QTimeZone::GenericTime as QTimeZone::StandardTime // treat all NameTypes as java TimeZone style LONG (value 1), except of course QTimeZone::ShortName which is style SHORT (value 0); jint style = (nameType == QTimeZone::ShortName ? 0 : 1); QJNIObjectPrivate jlanguage = QJNIObjectPrivate::fromString(QLocale::languageToString(locale.language())); QJNIObjectPrivate jcountry = QJNIObjectPrivate::fromString(QLocale::countryToString(locale.country())); QJNIObjectPrivate jvariant = QJNIObjectPrivate::fromString(QLocale::scriptToString(locale.script())); QJNIObjectPrivate jlocale("java.util.Locale", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", static_cast<jstring>(jlanguage.object()), static_cast<jstring>(jcountry.object()), static_cast<jstring>(jvariant.object())); QJNIObjectPrivate jname = androidTimeZone.callObjectMethod("getDisplayName", "(ZILjava/util/Locale;)Ljava/lang/String;", daylightTime, style, jlocale.object()); name = jname.toString(); } return name; }
bool RCCResourceLibrary::interpretResourceFile(QIODevice *inputDevice, const QString &fname, QString currentPath, bool ignoreErrors) { Q_ASSERT(m_errorDevice); const QChar slash = QLatin1Char('/'); if (!currentPath.isEmpty() && !currentPath.endsWith(slash)) currentPath += slash; QDomDocument document; { QString errorMsg; int errorLine = 0; int errorColumn = 0; if (!document.setContent(inputDevice, &errorMsg, &errorLine, &errorColumn)) { if (ignoreErrors) return true; const QString msg = QString::fromUtf8("RCC Parse Error: '%1' Line: %2 Column: %3 [%4]\n").arg(fname).arg(errorLine).arg(errorColumn).arg(errorMsg); m_errorDevice->write(msg.toUtf8()); return false; } } QDomElement domRoot = document.firstChildElement(m_strings.TAG_RCC).toElement(); if (!domRoot.isNull() && domRoot.tagName() == m_strings.TAG_RCC) { for (QDomNode node = domRoot.firstChild(); !node.isNull(); node = node.nextSibling()) { if (!node.isElement()) continue; QDomElement child = node.toElement(); if (!child.isNull() && child.tagName() == m_strings.TAG_RESOURCE) { QLocale::Language language = QLocale::c().language(); QLocale::Country country = QLocale::c().country(); if (child.hasAttribute(m_strings.ATTRIBUTE_LANG)) { QString attribute = child.attribute(m_strings.ATTRIBUTE_LANG); QLocale lang = QLocale(attribute); language = lang.language(); if (2 == attribute.length()) { // Language only country = QLocale::AnyCountry; } else { country = lang.country(); } } QString prefix; if (child.hasAttribute(m_strings.ATTRIBUTE_PREFIX)) prefix = child.attribute(m_strings.ATTRIBUTE_PREFIX); if (!prefix.startsWith(slash)) prefix.prepend(slash); if (!prefix.endsWith(slash)) prefix += slash; for (QDomNode res = child.firstChild(); !res.isNull(); res = res.nextSibling()) { if (res.isElement() && res.toElement().tagName() == m_strings.TAG_FILE) { QString fileName(res.firstChild().toText().data()); if (fileName.isEmpty()) { const QString msg = QString::fromUtf8("RCC: Warning: Null node in XML of '%1'\n").arg(fname); m_errorDevice->write(msg.toUtf8()); } QString alias; if (res.toElement().hasAttribute(m_strings.ATTRIBUTE_ALIAS)) alias = res.toElement().attribute(m_strings.ATTRIBUTE_ALIAS); else alias = fileName; int compressLevel = m_compressLevel; if (res.toElement().hasAttribute(m_strings.ATTRIBUTE_COMPRESS)) compressLevel = res.toElement().attribute(m_strings.ATTRIBUTE_COMPRESS).toInt(); int compressThreshold = m_compressThreshold; if (res.toElement().hasAttribute(m_strings.ATTRIBUTE_THRESHOLD)) compressThreshold = res.toElement().attribute(m_strings.ATTRIBUTE_THRESHOLD).toInt(); // Special case for -no-compress. Overrides all other settings. if (m_compressLevel == -2) compressLevel = 0; alias = QDir::cleanPath(alias); while (alias.startsWith(QLatin1String("../"))) alias.remove(0, 3); alias = QDir::cleanPath(m_resourceRoot) + prefix + alias; QString absFileName = fileName; if (QDir::isRelativePath(absFileName)) absFileName.prepend(currentPath); QFileInfo file(absFileName); if (!file.exists()) { m_failedResources.push_back(absFileName); const QString msg = QString::fromUtf8("RCC: Error in '%1': Cannot find file '%2'\n").arg(fname).arg(fileName); m_errorDevice->write(msg.toUtf8()); if (ignoreErrors) continue; else return false; } else if (file.isFile()) { const bool arc = addFile(alias, RCCFileInfo(alias.section(slash, -1), file, language, country, RCCFileInfo::NoFlags, compressLevel, compressThreshold) ); if (!arc) m_failedResources.push_back(absFileName); } else { QDir dir; if (file.isDir()) { dir.setPath(file.filePath()); } else { dir.setPath(file.path()); dir.setNameFilters(QStringList(file.fileName())); if (alias.endsWith(file.fileName())) alias = alias.left(alias.length()-file.fileName().length()); } if (!alias.endsWith(slash)) alias += slash; QDirIterator it(dir, QDirIterator::FollowSymlinks|QDirIterator::Subdirectories); while (it.hasNext()) { it.next(); QFileInfo child(it.fileInfo()); if (child.fileName() != QLatin1String(".") && child.fileName() != QLatin1String("..")) { const bool arc = addFile(alias + child.fileName(), RCCFileInfo(child.fileName(), child, language, country, RCCFileInfo::NoFlags, compressLevel, compressThreshold) ); if (!arc) m_failedResources.push_back(child.fileName()); } } } } } } } } if (m_root == 0) { const QString msg = QString::fromUtf8("RCC: Warning: No resources in '%1'.\n").arg(fname); m_errorDevice->write(msg.toUtf8()); if (!ignoreErrors && m_format == Binary) { // create dummy entry, otherwise loading qith QResource will crash m_root = new RCCFileInfo(QString(), QFileInfo(), QLocale::C, QLocale::AnyCountry, RCCFileInfo::Directory); } } return true; }
int main(int argc, char **argv) { QApplication* app=NULL; initAppPaths(argc,argv); CmdLineArgs args; if(!args.preparse(argc,argv)) { // searches only for the -cfg parameter qCritical(CSTR(args.error())); return 1; } //Load Config QString IniFilename; if(args.configLocation().isEmpty()) { if(!QDir(HomeDir).exists()) { QDir conf(QDir::homePath()); if(!QDir().mkpath(HomeDir)) qWarning("Warning: Could not create directory '%s'", CSTR(HomeDir)); } IniFilename=HomeDir+"/config"; } else IniFilename=args.configLocation(); config = new KpxConfig(IniFilename); fileDlgHistory.load(); // PlugIns if(config->integrPlugin()!=KpxConfig::NoIntegr) { QString LibName="libkeepassx-"; if(config->integrPlugin()==KpxConfig::KDE) LibName+="kde.so"; else if(config->integrPlugin()==KpxConfig::Gnome) LibName+="gnome.so"; QString filename=findPlugin(LibName); if(filename!=QString()) { QPluginLoader plugin(filename); if(!plugin.load()) { PluginLoadError=plugin.errorString(); qWarning("Could not load desktop integration plugin:"); qWarning(CSTR(PluginLoadError)); } else { QObject *plugininstance=plugin.instance(); IFileDialog* fdlg=qobject_cast<IFileDialog*>(plugininstance); IconLoader=qobject_cast<IIconTheme*>(plugininstance); if(IconLoader==NULL) { qWarning("Error: Integration Plugin: Could not initialize IconTheme interface."); } KpxFileDialogs::setPlugin(fdlg); if(config->integrPlugin()==KpxConfig::KDE) { IKdeInit* kdeinit=qobject_cast<IKdeInit*>(plugin.instance()); app=kdeinit->getMainAppObject(argc,argv); if(!app)PluginLoadError=QObject::tr("Initialization failed."); } if(config->integrPlugin()==KpxConfig::Gnome) { IGnomeInit* ginit=qobject_cast<IGnomeInit*>(plugin.instance()); if(!ginit->init(argc,argv)) { KpxFileDialogs::setPlugin(NULL); qWarning("GtkIntegrPlugin: Gtk init failed."); PluginLoadError=QObject::tr("Initialization failed."); } } } } else { qWarning(CSTR(QString("Could not load desktop integration plugin: File '%1' not found.").arg(LibName))); PluginLoadError=QObject::tr("Could not locate library file."); } } if(!app) { #if defined(Q_WS_X11) && defined(GLOBAL_AUTOTYPE) app = new KeepassApplication(argc,argv); #else app = new QApplication(argc,argv); #endif } args.parse(QApplication::arguments()); //Internationalization QLocale loc; if(!args.language().size()) loc=QLocale::system(); else loc=QLocale(args.language()); QTranslator* translator = NULL; QTranslator* qtTranslator=NULL; translator=new QTranslator; qtTranslator=new QTranslator; if(loadTranslation(translator,"keepass-",loc.name(),QStringList() << DataDir+"/i18n/" << HomeDir)) { app->installTranslator(translator); TrActive=true; } else { if(loc.name()!="en_US") qWarning(QString("Kpx: No Translation found for '%1 (%2)' using 'English (UnitedStates)'") .arg(QLocale::languageToString(loc.language())) .arg(QLocale::countryToString(loc.country())).toAscii()); delete translator; TrActive=false; } if(TrActive) { if(loadTranslation(qtTranslator,"qt_",loc.name(),QStringList() << QLibraryInfo::location(QLibraryInfo::TranslationsPath) << DataDir+"/i18n/" << HomeDir)) app->installTranslator(qtTranslator); else { if(loc.name()!="en_US") qWarning(QString("Qt: No Translation found for '%1 (%2)' using 'English (UnitedStates)'") .arg(QLocale::languageToString(loc.language())) .arg(QLocale::countryToString(loc.country())).toAscii()); delete qtTranslator; } } DetailViewTemplate=config->detailViewTemplate(); loadImages(); KpxBookmarks::load(); initYarrow(); //init random number generator SecString::generateSessionKey(); eventListener = new EventListener(); app->installEventFilter(eventListener); QApplication::setQuitOnLastWindowClosed(false); KeepassMainWindow *mainWin = new KeepassMainWindow(args.file(), args.startMinimized(), args.startLocked()); int r=app->exec(); delete mainWin; delete eventListener; fileDlgHistory.save(); delete app; delete config; return r; }
int main (int argc, char *argv[]) { QCoreApplication::setOrganizationName ("BerndStramm"); QCoreApplication::setOrganizationDomain ("bernd-stramm.com"); QCoreApplication::setApplicationName ("loco"); deliberate::ProgramVersion pv ("Loco"); QCoreApplication::setApplicationVersion (pv.Number()); QApplication app (argc, argv); QLocale locale; QSysInfo sysInfo; QSettings settings; deliberate::InitSettings (); deliberate::SetSettings (settings); settings.setValue ("program",pv.MyName()); QStringList configMessages; deliberate::CmdOptions opts ("loco"); opts.AddSoloOption ("debug","D",QObject::tr("show Debug log window")); opts.AddStringOption ("logdebug","L",QObject::tr("write Debug log to file")); deliberate::UseMyOwnMessageHandler (); bool optsOk = opts.Parse (argc, argv); if (!optsOk) { opts.Usage (); exit(1); } if (opts.WantHelp ()) { opts.Usage (); exit (0); } pv.CLIVersion (); configMessages.append (QString ("Portions %1") .arg ("Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)")); configMessages.append (QString("Built on %1 %2") .arg (__DATE__).arg(__TIME__)); configMessages.append (QObject::tr("Build with Qt %1").arg(QT_VERSION_STR)); configMessages.append (QObject::tr("Running with Qt %1").arg(qVersion())); configMessages.append (QObject::tr("Current Country %1") .arg(QLocale::countryToString(locale.country()))); configMessages.append (QObject::tr("Current Language %1") .arg(QLocale::languageToString(locale.language()))); configMessages.append (QObject::tr("build API %1") .arg (sysInfo.buildAbi())); configMessages.append(QObject::tr("Kernel %1") .arg(sysInfo.kernelType() + " "+sysInfo.kernelVersion())); configMessages.append((QObject::tr("Product Name %1") .arg(sysInfo.prettyProductName()))); for (int cm=0; cm<configMessages.size(); cm++) { deliberate::StdOut () << configMessages[cm] << endl; } if (opts.WantVersion ()) { exit (0); } bool showDebug = opts.SeenOpt ("debug"); int result; #if DELIBERATE_DEBUG deliberate::StartDebugLog (showDebug); bool logDebug = opts.SeenOpt ("logdebug"); if (logDebug) { QString logfile ("/dev/null"); opts.SetStringOpt ("logdebug",logfile); deliberate::StartFileLog (logfile); } #endif QStringList args = opts.Arguments(); QString tour; cout << "\n\nargument count" << args.count(); if (args.count() > 0) { tour = args.at(0); } else { tour = QString(":/tour-default"); } cout << "\n\n\n\t\t" << Q_FUNC_INFO << "tour is" << tour.toStdString() << "\n\n\n"; loco::Loco loco (tour); app.setWindowIcon (loco.windowIcon()); loco.Init (app); loco.AddConfigMessages (configMessages); loco.Run (); loco.RunSlippy (); result = app.exec (); qDebug () << " QApplication exec finished " << result; return result; }