void MainTray::readSettings() { QDir configDir(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation)); if (!configDir.exists()) { if (!configDir.mkpath(configDir.absolutePath())) return; } QFile settingsFile(configDir.absolutePath() + '/' + ConfigFileName); if (settingsFile.open(QIODevice::ReadOnly)) { QDataStream settingsReader(&settingsFile); settingsReader.setVersion(QDataStream::Qt_5_4); QTime tempTime; settingsReader >> tempTime; updateInterval(tempTime); quint64 currentID; qint32 sizeSkip; while(!settingsReader.atEnd()){ settingsReader >> currentID; for (auto i = m_taskList.begin(); i != m_taskList.end(); ++i) { if((*i)->getTaskID()==currentID){ settingsReader.device()->seek(settingsReader.device()->pos() - sizeof(quint64)); (*i)->readSettings(settingsReader); break; } if (i == m_taskList.end()-1){ // task not found, skip it settingsReader >> sizeSkip; settingsReader.skipRawData(sizeSkip); } } }
int main(int argc, char *argv[]) { Q_UNUSED(argc); Q_UNUSED(argv); SceneSettingReader settingsReader(SETTINGS_FILENAME); Scene scene(settingsReader); RayTracer rayTracer(scene); auto image = rayTracer.generateImage(); image.save(settingsReader.outputFilename()); return 0; }
KoFilter::ConversionStatus DocxImport::parseParts(KoOdfWriters *writers, MSOOXML::MsooXmlRelationships *relationships, QString& errorMessage) { writers->body->addAttribute("text:use-soft-page-breaks", "true"); // 0. parse settings.xml { DocxXmlSettingsReaderContext context(d->documentSettings); DocxXmlSettingsReader settingsReader(writers); d->colorMap = context.colorMap; RETURN_IF_ERROR( loadAndParseDocumentIfExists( MSOOXML::ContentTypes::wordSettings, &settingsReader, writers, errorMessage, &context) ) } reportProgress(5); // 1. parse font table { DocxXmlFontTableReaderContext context(*writers->mainStyles); DocxXmlFontTableReader fontTableReader(writers); RETURN_IF_ERROR( loadAndParseDocumentIfExists( MSOOXML::ContentTypes::wordFontTable, &fontTableReader, writers, errorMessage, &context) ) } QList<QByteArray> partNames = this->partNames(d->mainDocumentContentType()); if (partNames.count() != 1) { errorMessage = i18n("Unable to find part for type %1", d->mainDocumentContentType()); return KoFilter::WrongFormat; } const QString documentPathAndFile(partNames.first()); QString documentPath, documentFile; MSOOXML::Utils::splitPathAndFile(documentPathAndFile, &documentPath, &documentFile); // 2. parse theme for the document if a theme exists MSOOXML::DrawingMLTheme themes; const QString docThemePathAndFile(relationships->targetForType( documentPath, documentFile, QLatin1String(MSOOXML::Schemas::officeDocument::relationships) + "/theme")); if (!docThemePathAndFile.isEmpty()) { kDebug() << QLatin1String(MSOOXML::Schemas::officeDocument::relationships) + "/theme"; // prepare the themes-reader QString docThemePath, docThemeFile; MSOOXML::Utils::splitPathAndFile(docThemePathAndFile, &docThemePath, &docThemeFile); MSOOXML::MsooXmlThemesReader themesReader(writers); MSOOXML::MsooXmlThemesReaderContext themecontext(themes, relationships, (MSOOXML::MsooXmlImport*)this, docThemePath, docThemeFile); KoFilter::ConversionStatus status = loadAndParseDocument(&themesReader, docThemePathAndFile, errorMessage, &themecontext); kDebug() << "Reading ThemePathAndFile:" << docThemePathAndFile << "status=" << status; } reportProgress(15); // Main document context, to which we collect footnotes, endnotes, // comments, numbering, tablestyles DocxXmlDocumentReaderContext mainContext(*this, documentPath, documentFile, *relationships, &themes); // 3. parse styles { // get styles path from document's relationships, not from content // types; typically returns /word/styles.xml // // ECMA-376, 11.3.12 Style Definitions Part, p. 65 // // An instance of this part type contains the definition for a set of // styles used by this document. A package shall contain at most two // Style Definitions parts. One instance of that part shall be the // target of an implicit relationship from the Main Document (§11.3.10) // part, and the other shall be the target of an implicit relationship // in from the Glossary Document (§11.3.8) part. const QString stylesPathAndFile(relationships->targetForType(documentPath, documentFile, QLatin1String(MSOOXML::Schemas::officeDocument::relationships) + "/styles")); DocxXmlStylesReader stylesReader(writers); if (!stylesPathAndFile.isEmpty()) { QString stylesPath, stylesFile; MSOOXML::Utils::splitPathAndFile(stylesPathAndFile, &stylesPath, &stylesFile); DocxXmlDocumentReaderContext context(*this, stylesPath, stylesFile, *relationships, &themes); RETURN_IF_ERROR( loadAndParseDocumentFromFileIfExists( stylesPathAndFile, &stylesReader, writers, errorMessage, &context) ) mainContext.m_tableStyles = context.m_tableStyles; mainContext.m_namedDefaultStyles = context.m_namedDefaultStyles; mainContext.m_defaultFontSizePt = context.m_defaultFontSizePt; } } reportProgress(25); // 4. parse numbering const QString numberingPathAndFile(relationships->targetForType(documentPath, documentFile, QLatin1String(MSOOXML::Schemas::officeDocument::relationships) + "/numbering")); DocxXmlNumberingReader numberingReader(writers); QString numberingPath, numberingFile; MSOOXML::Utils::splitPathAndFile(numberingPathAndFile, &numberingPath, &numberingFile); DocxXmlDocumentReaderContext numberingContext(*this, numberingPath, numberingFile, *relationships, &themes); if (!numberingPathAndFile.isEmpty()) { RETURN_IF_ERROR( loadAndParseDocumentFromFileIfExists( numberingPathAndFile, &numberingReader, writers, errorMessage, &numberingContext) ) } mainContext.m_bulletStyles = numberingContext.m_bulletStyles; mainContext.m_abstractNumIDs = numberingContext.m_abstractNumIDs; reportProgress(30); { // 5. parse footnotes const QString footnotePathAndFile(relationships->targetForType(documentPath, documentFile, QLatin1String(MSOOXML::Schemas::officeDocument::relationships) + "/footnotes")); //! @todo use m_contentTypes.values() when multiple paths are expected, e.g. for ContentTypes::wordHeader DocxXmlFootnoteReader footnoteReader(writers); if (!footnotePathAndFile.isEmpty()) { QString footnotePath, footnoteFile; MSOOXML::Utils::splitPathAndFile(footnotePathAndFile, &footnotePath, &footnoteFile); DocxXmlDocumentReaderContext context(*this, footnotePath, footnoteFile, *relationships, &themes); context.m_tableStyles = mainContext.m_tableStyles; context.m_bulletStyles = mainContext.m_bulletStyles; context.m_namedDefaultStyles = mainContext.m_namedDefaultStyles; context.m_abstractNumIDs = mainContext.m_abstractNumIDs; RETURN_IF_ERROR( loadAndParseDocumentFromFileIfExists( footnotePathAndFile, &footnoteReader, writers, errorMessage, &context) ) mainContext.m_footnotes = context.m_footnotes; } reportProgress(35); // 6. parse comments const QString commentPathAndFile(relationships->targetForType(documentPath, documentFile, QLatin1String(MSOOXML::Schemas::officeDocument::relationships) + "/comments")); DocxXmlCommentReader commentReader(writers); if (!commentPathAndFile.isEmpty()) { QString commentPath, commentFile; MSOOXML::Utils::splitPathAndFile(commentPathAndFile, &commentPath, &commentFile); DocxXmlDocumentReaderContext context(*this, commentPath, commentFile, *relationships, &themes); context.m_tableStyles = mainContext.m_tableStyles; context.m_bulletStyles = mainContext.m_bulletStyles; //TODO: m_abstractNumIDs and m_namedDefaultStyles might be needed RETURN_IF_ERROR( loadAndParseDocumentFromFileIfExists( commentPathAndFile, &commentReader, writers, errorMessage, &context) ) mainContext.m_comments = context.m_comments; } reportProgress(40); // 7. parse endnotes const QString endnotePathAndFile(relationships->targetForType(documentPath, documentFile, QLatin1String(MSOOXML::Schemas::officeDocument::relationships) + "/endnotes")); DocxXmlEndnoteReader endnoteReader(writers); if (!endnotePathAndFile.isEmpty()) { QString endnotePath, endnoteFile; MSOOXML::Utils::splitPathAndFile(endnotePathAndFile, &endnotePath, &endnoteFile); DocxXmlDocumentReaderContext context(*this, endnotePath, endnoteFile, *relationships, &themes); context.m_tableStyles = mainContext.m_tableStyles; context.m_bulletStyles = mainContext.m_bulletStyles; context.m_namedDefaultStyles = mainContext.m_namedDefaultStyles; context.m_abstractNumIDs = mainContext.m_abstractNumIDs; RETURN_IF_ERROR( loadAndParseDocumentFromFileIfExists( endnotePathAndFile, &endnoteReader, writers, errorMessage, &context) ) mainContext.m_endnotes = context.m_endnotes; } reportProgress(45); // 8. parse document // Some of the templates MIGHT be defined in numberingreader. DocxXmlDocumentReader documentReader(writers); documentReader.m_definedShapeTypes = numberingReader.m_definedShapeTypes; RETURN_IF_ERROR( loadAndParseDocument( d->mainDocumentContentType(), &documentReader, writers, errorMessage, &mainContext) ) } reportProgress(100); return KoFilter::OK; }