bool TableGenerator::processFile(const QString &composeFileName) { QFile composeFile(composeFileName); if (composeFile.open(QIODevice::ReadOnly)) { parseComposeFile(&composeFile); return true; } qWarning() << QString(QLatin1String("Qt Warning: Compose file: \"%1\" can't be found")) .arg(composeFile.fileName()); return false; }
void TableGenerator::findComposeFile() { bool found = false; // check if XCOMPOSEFILE points to a Compose file if (qEnvironmentVariableIsSet("XCOMPOSEFILE")) { QString composeFile(qgetenv("XCOMPOSEFILE")); if (composeFile.endsWith(QLatin1String("Compose"))) found = processFile(composeFile); else qWarning("Qt Warning: XCOMPOSEFILE doesn't point to a valid Compose file"); #ifdef DEBUG_GENERATOR if (found) qDebug() << "Using Compose file from: " << composeFile; #endif } // check if user’s home directory has a file named .XCompose if (!found && cleanState()) { QString composeFile = qgetenv("HOME") + QStringLiteral("/.XCompose"); if (QFile(composeFile).exists()) found = processFile(composeFile); #ifdef DEBUG_GENERATOR if (found) qDebug() << "Using Compose file from: " << composeFile; #endif } // check for the system provided compose files if (!found && cleanState()) { QString table = composeTableForLocale(); if (cleanState()) { if (table.isEmpty()) // no table mappings for the system's locale in the compose.dir m_state = UnsupportedLocale; else found = processFile(systemComposeDir() + QLatin1Char('/') + table); #ifdef DEBUG_GENERATOR if (found) qDebug() << "Using Compose file from: " << systemComposeDir() + QLatin1Char('/') + table; #endif } } if (found && m_composeTable.isEmpty()) m_state = EmptyTable; if (!found) m_state = MissingComposeFile; }
TableGenerator::TableGenerator() : m_state(NoErrors), m_systemComposeDir(QString()) { initPossibleLocations(); QString composeFilePath = findComposeFile(); #ifdef DEBUG_GENERATOR // don't use cache when in debug mode. if (!composeFilePath.isEmpty()) qDebug() << "Using Compose file from: " << composeFilePath; #else QComposeCacheFileHeader fileInfo = readFileMetadata(composeFilePath); if (fileInfo.fileSize != 0) m_composeTable = loadCache(fileInfo); #endif if (m_composeTable.isEmpty() && cleanState()) { if (composeFilePath.isEmpty()) { m_state = MissingComposeFile; } else { QFile composeFile(composeFilePath); composeFile.open(QIODevice::ReadOnly); parseComposeFile(&composeFile); orderComposeTable(); if (m_composeTable.isEmpty()) { m_state = EmptyTable; #ifndef DEBUG_GENERATOR // don't save cache when in debug mode } else { fileInfo.cacheVersion = SupportedCacheVersion; saveCache(fileInfo, m_composeTable); #endif } } } #ifdef DEBUG_GENERATOR printComposeTable(); #endif }