bool KoPAPastePage::process( const KoXmlElement & body, KoOdfReadStore & odfStore ) { KoOdfLoadingContext loadingContext( odfStore.styles(), odfStore.store(), m_doc->defaultStylesResourcePath() ); KoPALoadingContext paContext(loadingContext, m_doc->resourceManager()); QList<KoPAPageBase *> newMasterPages( m_doc->loadOdfMasterPages( odfStore.styles().masterPages(), paContext ) ); QList<KoPAPageBase *> newPages( m_doc->loadOdfPages( body, paContext ) ); // Check where to start inserting pages KoPAPageBase * insertAfterPage = 0; KoPAPageBase * insertAfterMasterPage = 0; if ( dynamic_cast<KoPAMasterPage *>( m_activePage ) || ( m_activePage == 0 && newPages.empty() ) ) { insertAfterMasterPage = m_activePage; insertAfterPage = m_doc->pages( false ).last(); } else { insertAfterPage = m_activePage; insertAfterMasterPage = m_doc->pages( true ).last(); } if ( !newPages.empty() ) { KoGenStyles mainStyles; QBuffer buffer; buffer.open( QIODevice::WriteOnly ); KoXmlWriter xmlWriter( &buffer ); KoEmbeddedDocumentSaver embeddedSaver; KoPASavingContext savingContext(xmlWriter, mainStyles, embeddedSaver, 1); savingContext.addOption( KoShapeSavingContext::UniqueMasterPages ); QList<KoPAPageBase*> emptyList; QList<KoPAPageBase*> existingMasterPages = m_doc->pages( true ); savingContext.setClearDrawIds( true ); m_doc->saveOdfPages( savingContext, emptyList, existingMasterPages ); QMap<QString, KoPAMasterPage*> masterPageNames; foreach ( KoPAPageBase * page, existingMasterPages ) { KoPAMasterPage * masterPage = dynamic_cast<KoPAMasterPage*>( page ); Q_ASSERT( masterPage ); if ( masterPage ) { QString masterPageName( savingContext.masterPageName( masterPage ) ); if ( !masterPageNames.contains( masterPageName ) ) { masterPageNames.insert( masterPageName, masterPage ); } } }
bool KoPADocument::saveOdf(SavingContext &documentContext) { KXmlWriter* contentWriter = documentContext.odfStore.contentWriter(); if (!contentWriter) return false; KOdfGenericStyles mainStyles; KXmlWriter * bodyWriter = documentContext.odfStore.bodyWriter(); KoPASavingContext paContext(*bodyWriter, mainStyles, documentContext.embeddedSaver, 1); saveOdfDocumentStyles(paContext); bodyWriter->startElement("office:body"); bodyWriter->startElement(odfTagName(true)); if (!saveOdfProlog(paContext)) { return false; } if (!saveOdfPages(paContext, d->pages, d->masterPages)) { return false; } if (! saveOdfEpilogue(paContext)) { return false; } paContext.writeConnectors(); bodyWriter->endElement(); // office:odfTagName() bodyWriter->endElement(); // office:body mainStyles.saveOdfStyles(KOdfGenericStyles::DocumentAutomaticStyles, contentWriter); documentContext.odfStore.closeContentWriter(); //add manifest line for content.xml documentContext.odfStore.manifestWriter()->addManifestEntry("content.xml", "text/xml"); if (! mainStyles.saveOdfStylesDotXml(documentContext.odfStore.store(), documentContext.odfStore.manifestWriter())) { return false; } KOdfStore * store = documentContext.odfStore.store(); if (! store->open("settings.xml")) { return false; } saveOdfSettings(store); if (! store->close()) { return false; } documentContext.odfStore.manifestWriter()->addManifestEntry("settings.xml", "text/xml"); //setModified(false); return paContext.saveDataCenter(documentContext.odfStore.store(), documentContext.odfStore.manifestWriter()); }
bool KoPADocument::loadOdf(KOdfStoreReader &odfStore) { QPointer<KoUpdater> updater; if (progressUpdater()) { updater = progressUpdater()->startSubtask(1, "KoPADocument::loadOdf"); updater->setProgress(0); } KOdfLoadingContext loadingContext(odfStore.styles(), odfStore.store(), componentData()); KoPALoadingContext paContext(loadingContext, resourceManager()); KXmlElement content = odfStore.contentDoc().documentElement(); KXmlElement realBody (KoXml::namedItemNS(content, KOdfXmlNS::office, "body")); if (realBody.isNull()) { kError(30010) << "No body tag found!" << endl; return false; } KXmlElement body = KoXml::namedItemNS(realBody, KOdfXmlNS::office, odfTagName(false)); if (body.isNull()) { kError(30010) << "No office:" << odfTagName(false) << " tag found!" << endl; return false; } // Load text styles before the corresponding text shapes try to use them! KTextSharedLoadingData * sharedData = new KTextSharedLoadingData(); paContext.addSharedData(KODFTEXT_SHARED_LOADING_ID, sharedData); KStyleManager *styleManager = resourceManager()->resource(KOdfText::StyleManager).value<KStyleManager*>(); sharedData->loadOdfStyles(paContext, styleManager); d->masterPages = loadOdfMasterPages(odfStore.styles().masterPages(), paContext); if (!loadOdfProlog(body, paContext)) { return false; } d->pages = loadOdfPages(body, paContext); // create pages if there are none if (d->masterPages.empty()) { d->masterPages.append(newMasterPage()); } if (d->pages.empty()) { d->pages.append(newPage(static_cast<KoPAMasterPage*>(d->masterPages.first()))); } if (!loadOdfEpilogue(body, paContext)) { return false; } loadOdfDocumentStyles(paContext); if (d->pages.size() > 1) { setActionEnabled(KoPAView::ActionDeletePage, false); } updatePageCount(); if (updater) updater->setProgress(100); return true; }