void TestLoadingBase::initTestCase() { ChartDocument document(m_chart); QString srcdirname(KDESRCDIR); QVERIFY(!srcdirname.isEmpty()); QDir srcdir(srcdirname); QVERIFY(srcdir.exists()); bool hasDocDirInSrcDir = srcdir.cd("doc"); QVERIFY(hasDocDirInSrcDir); // Go back up, we only used the cd as a test. if (hasDocDirInSrcDir) srcdir.cd(".."); KoStore *store = KoStore::createStore(srcdir.absolutePath(), KoStore::Read); QVERIFY(store->enterDirectory("doc")); QString errorMsg; KoOdfReadStore odfReadStore(store); bool success = odfReadStore.loadAndParse(errorMsg); if (!success) qDebug() << "Error in odfReadStore.loadAndParse(): " << errorMsg; QVERIFY(success); QVERIFY(document.loadOdf(odfReadStore)); }
KoFilter::ConversionStatus HancomWordImport::convert( const QByteArray& from, const QByteArray& to ) { if ( from != "application/x-hwp" ) return KoFilter::NotImplemented; if ( to != "application/vnd.oasis.opendocument.text" ) return KoFilter::NotImplemented; d->inputFile = m_chain->inputFile(); d->outputFile = m_chain->outputFile(); d->paragraphs.clear(); POLE::Storage storage( QFile::encodeName(d->inputFile) ); if( !storage.open() ) return KoFilter::WrongFormat; POLE::Stream* stream; stream = new POLE::Stream( &storage, "/PrvText" ); if( stream->fail() || (stream->size() == 0) ) { delete stream; return KoFilter::WrongFormat; } int len = stream->size() / 2; QString plaindoc; plaindoc.reserve( len ); unsigned char* buf = new unsigned char [stream->size()]; stream->read( buf, stream->size()); for(int i = 0; i < len; i++ ) plaindoc.append( QChar((int)readU16(buf + i*2) ) ); delete[] buf; delete stream; // split into paragraphs d->paragraphs = QStringList::split( "\n", plaindoc, true ); // create output store KoStore* storeout; storeout = KoStore::createStore( d->outputFile, KoStore::Write, "application/vnd.oasis.opendocument.text", KoStore::Zip ); if ( !storeout ) { kWarning() << "Couldn't open the requested file."; return KoFilter::FileNotFound; } if ( !storeout->open( "styles.xml" ) ) { kWarning() << "Couldn't open the file 'styles.xml'."; return KoFilter::CreationError; } storeout->write( d->createStyles() ); storeout->close(); if ( !storeout->open( "content.xml" ) ) { kWarning() << "Couldn't open the file 'content.xml'."; return KoFilter::CreationError; } storeout->write( d->createContent() ); storeout->close(); // store document manifest storeout->enterDirectory( "META-INF" ); if ( !storeout->open( "manifest.xml" ) ) { kWarning() << "Couldn't open the file 'META-INF/manifest.xml'."; return KoFilter::CreationError; } storeout->write( d->createManifest() ); storeout->close(); // we are done! d->inputFile.clear(); d->outputFile.clear(); delete storeout; return KoFilter::OK; }
KoFilter::ConversionStatus WPGImport::convert( const QByteArray& from, const QByteArray& to ) { if ( from != "application/x-wpg" ) return KoFilter::NotImplemented; if ( to != "application/vnd.oasis.opendocument.graphics" ) return KoFilter::NotImplemented; WPXInputStream* input = new libwpg::WPGFileStream( m_chain->inputFile().toLocal8Bit() ); if (input->isOLEStream()) { WPXInputStream* olestream = input->getDocumentOLEStream(); if (olestream) { delete input; input = olestream; } } if (!libwpg::WPGraphics::isSupported(input)) { std::cerr << "ERROR: Unsupported file format (unsupported version) or file is encrypted!" << std::endl; delete input; return KoFilter::NotImplemented; } // do the conversion std::ostringstream tmpStringStream; FileOutputHandler tmpHandler(tmpStringStream); OdgExporter exporter(&tmpHandler); libwpg::WPGraphics::parse(input, &exporter); delete input; // create output store KoStore* storeout; storeout = KoStore::createStore( m_chain->outputFile(), KoStore::Write, "application/vnd.oasis.opendocument.graphics", KoStore::Zip ); if ( !storeout ) { kWarning() << "Couldn't open the requested file."; return KoFilter::FileNotFound; } #if 0 if ( !storeout->open( "styles.xml" ) ) { kWarning() << "Couldn't open the file 'styles.xml'."; return KoFilter::CreationError; } //storeout->write( createStyles() ); storeout->close(); #endif if ( !storeout->open( "content.xml" ) ) { kWarning() << "Couldn't open the file 'content.xml'."; return KoFilter::CreationError; } storeout->write(tmpStringStream.str().c_str()); storeout->close(); // store document manifest storeout->enterDirectory( "META-INF" ); if ( !storeout->open( "manifest.xml" ) ) { kWarning() << "Couldn't open the file 'META-INF/manifest.xml'."; return KoFilter::CreationError; } storeout->write( createManifest() ); storeout->close(); // we are done! delete storeout; return KoFilter::OK; }