bool Import_Argo::loadFromArgoFile(const KZip &zipFile, const QString &fileName) { const KArchiveFile *file = static_cast<const KArchiveFile*>(zipFile.directory()->entry(fileName)); if (!file) return false; QXmlStreamReader xml; xml.addData(file->data()); while (!xml.atEnd()) { xml.readNext(); if (xml.name() == QLatin1String("member")) { QXmlStreamAttributes attributes = xml.attributes(); QString type = attributes.value(QLatin1String("type")).toString(); QString name = attributes.value(QLatin1String("name")).toString(); if (type == QLatin1String("xmi")) loadFromXMIFile(zipFile, name); else if (type == QLatin1String("pgml")) loadFromPGMLFile(zipFile, name); else if (type == QLatin1String("todo")) loadFromTodoFile(zipFile, name); else uError() << "unknown file type" << type << "in file" << zipFile.fileName() << ":" << fileName; } } if (xml.hasError()) { reportError(xml, zipFile, fileName); return false; } return true; }
bool Import_Argo::loadFromXMIFile(const KZip &zipFile, const QString &fileName) { const KArchiveFile *file = static_cast<const KArchiveFile*>(zipFile.directory()->entry(fileName)); if (!file) return false; #if QT_VERSION >= 0x050000 QTemporaryDir tmpDir; #else KTempDir tmpDir; #endif tmpDir.setAutoRemove(true); #if QT_VERSION >= 0x050000 file->copyTo(tmpDir.path()); QFile xmiFile(tmpDir.path() + QLatin1Char('/') + file->name()); #else file->copyTo(tmpDir.name()); QFile xmiFile(tmpDir.name() + file->name()); #endif if(!xmiFile.open(QIODevice::ReadOnly)) { return false; } return UMLApp::app()->document()->loadFromXMI(xmiFile, 0); }
bool Import_Argo::loadFromTodoFile(const KZip &zipFile, const QString &fileName) { const KArchiveFile *file = static_cast<const KArchiveFile*>(zipFile.directory()->entry(fileName)); if (!file) return false; QXmlStreamReader xml; xml.addData(file->data()); while (!xml.atEnd()) { xml.readNext(); uDebug() << "unhandled tag" << xml.name() << "in file" << zipFile.fileName() << ":" << fileName; } if (xml.hasError()) { reportError(xml, zipFile, fileName); return false; } return true; }
void IndexBuilder::writeSnapshots(Reader &reader, KZip &zip) { static const qint64 SNAPSHOT_INTERVAL_MS = 1000; // snapshot interval in milliseconds static const int SNAPSHOT_MIN_ACTIONS = 200; // minimum number of actions between snapshots paintcore::LayerStack image; net::LayerListModel layermodel; canvas::StateTracker statetracker(&image, &layermodel, 1); MessageRecord msg; int snapshotCounter = 0; QElapsedTimer timer; timer.start(); while(true) { if(_abortflag.load()) return; msg = reader.readNext(); if(msg.status == MessageRecord::END_OF_RECORDING) break; else if(msg.status == MessageRecord::INVALID) continue; protocol::MessagePtr m(msg.message); if(m->isCommand()) { statetracker.receiveCommand(m); ++snapshotCounter; } // Save a snapshot every SNAPSHOT_INTERVAL or at every marker. (But no more often than SNAPSHOT_MIN_ACTIONS) // Note. We use the actual elapsed rendering time to decide when to snapshot. This means that (ideally), // the time it takes to jump to a snapshot is at most SNAPSHOT_INTERVAL milliseconds (+ the time it takes to load the snapshot) if(m_index.snapshots().isEmpty() || ((timer.hasExpired(SNAPSHOT_INTERVAL_MS) || m->type() == protocol::MSG_MARKER) && snapshotCounter>=SNAPSHOT_MIN_ACTIONS)) { qint64 streampos = reader.filePosition(); emit progress(streampos); canvas::StateSavepoint sp = statetracker.createSavepoint(-1); QBuffer buf; buf.open(QBuffer::ReadWrite); { QDataStream ds(&buf); sp.toDatastream(ds); } int snapshotIdx = m_index.m_snapshots.size(); zip.writeFile(QString("snapshot-%1").arg(snapshotIdx), buf.data()); m_index.m_snapshots.append(SnapshotEntry(streampos, reader.currentIndex())); snapshotCounter = 0; timer.restart(); } } }
static void reportError(const QXmlStreamReader &xml, const KZip &zipFile, const QString &fileName) { uError() << xml.name() << "in file" << zipFile.fileName() << ":" << fileName; }
bool KXpsPlugin::readInfo( KFileMetaInfo& info, uint /* what */) { KFileMetaInfoGroup generalGroup = appendGroup(info, "General"); KZip *xpsArchive = new KZip( info.path() ); if ( xpsArchive->open( IO_ReadOnly ) == true ) { // kdDebug(7115) << "Successful open of " << xpsArchive->fileName() << endl; } else { kDebug(7115) << "Could not open XPS archive: " << xpsArchive->fileName(); delete xpsArchive; return false; } const KZipFileEntry* relFile = static_cast<const KZipFileEntry *>(xpsArchive->directory()->entry("_rels/.rels")); if ( !relFile ) { delete xpsArchive; // this might occur if we can't read the zip directory, or it doesn't have the relationships entry return false; } if ( relFile->name().isEmpty() ) { delete xpsArchive; // this might occur if we can't read the zip directory, or it doesn't have the relationships entry return false; } QIODevice* relDevice = relFile->createDevice(); QDomDocument relDom; QString errMsg; int errLine, errCol; if ( relDom.setContent( relDevice, true, &errMsg, &errLine, &errCol ) == false ) { // parse error kDebug(7115) << "Could not parse relationship document: " << errMsg << " : " << errLine << " : " << errCol << endl; delete relDevice; delete xpsArchive; return false; } QDomElement docElem = relDom.documentElement(); QString thumbFileName; QString fixedRepresentationFileName; QString metadataFileName; QDomNode n = docElem.firstChild(); while( !n.isNull() ) { QDomElement e = n.toElement(); if( !e.isNull() ) { if ("http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail" == e.attribute("Type") ) { thumbFileName = e.attribute("Target"); } else if ("http://schemas.microsoft.com/xps/2005/06/fixedrepresentation" == e.attribute("Type") ) { fixedRepresentationFileName = e.attribute("Target"); } else if ("http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" == e.attribute("Type") ) { metadataFileName = e.attribute("Target"); } } n = n.nextSibling(); } delete relDevice; if ( fixedRepresentationFileName.isEmpty() ) { delete xpsArchive; // FixedRepresentation is a required part of the XPS document return false; } const KZipFileEntry* fixedRepFile = static_cast<const KZipFileEntry *>(xpsArchive->directory()->entry( fixedRepresentationFileName )); QIODevice* fixedRepDevice = fixedRepFile->createDevice(); QDomDocument fixedRepDom; if ( fixedRepDom.setContent( fixedRepDevice, true, &errMsg, &errLine, &errCol ) == false ) { // parse error kDebug(7115) << "Could not parse Fixed Representation document: " << errMsg << " : " << errLine << " : " << errCol << endl; delete fixedRepDevice; delete xpsArchive; return false; } docElem = fixedRepDom.documentElement(); QString firstDocumentFileName; int numDocuments = 0; // the number of Documents in this FixedDocumentSequence n = docElem.firstChild(); while( !n.isNull() ) { QDomElement e = n.toElement(); if( !e.isNull() ) { if (e.tagName() == "DocumentReference") { if (firstDocumentFileName.isEmpty()) { // we don't already have a filename, so take this one firstDocumentFileName = e.attribute("Source"); } numDocuments++; } } n = n.nextSibling(); } delete fixedRepDevice; #if 0 // This stuff is used for detailed parsing - not really required // no document? bail out here. if ( firstDocumentFileName.isEmpty() ) { return false; } KZipFileEntry* firstDocumentFile = static_cast<const KZipFileEntry *>(xpsArchive->directory()->entry( firstDocumentFileName )); QIODevice* firstDocumentDevice = firstDocumentFile->device(); QDomDocument firstDocumentDom; if ( firstDocumentDom.setContent( firstDocumentDevice, true, &errMsg, &errLine, &errCol ) == false ) { // parse error kDebug(7115) << "Could not parse first document: " << errMsg << " : " << errLine << " : " << errCol << endl; return false; } n = firstDocumentDom.documentElement().firstChild(); while( !n.isNull() ) { QDomElement e = n.toElement(); if( !e.isNull() ) { kDebug(7155) << "DOcument: " << e.tagName() << " : " << e.text(); } n = n.nextSibling(); } #endif if ( ! metadataFileName.isEmpty() ) { const KZipFileEntry* corepropsFile = static_cast<const KZipFileEntry *>(xpsArchive->directory()->entry(metadataFileName)); kDebug(7115) << "metadata file name: " << metadataFileName; QDomDocument metadataDocumentDom; QIODevice *corepropsDevice = corepropsFile->createDevice(); if ( metadataDocumentDom.setContent( corepropsDevice, true, &errMsg, &errLine, &errCol ) == false ) { // parse error kDebug(7115) << "Could not parse core properties (metadata) document: " << errMsg << " : " << errLine << " : " << errCol << endl; delete corepropsDevice; delete xpsArchive; return false; } n = metadataDocumentDom.documentElement().firstChild(); // the <coreProperties> level while( !n.isNull() ) { QDomElement e = n.toElement(); if( !e.isNull() ) { if (e.tagName() == "title") { appendItem(generalGroup, "Title", e.text() ); } else if (e.tagName() == "subject") { appendItem(generalGroup, "Subject", e.text() ); } else if (e.tagName() == "description") { appendItem(generalGroup, "Description", e.text() ); } else if (e.tagName() == "creator") { appendItem(generalGroup, "Author", e.text() ); } else if (e.tagName() == "created") { appendItem(generalGroup, "CreationDate", QDateTime::fromString( e.text(), "yyyy-MM-ddThh:mm:ssZ" ) ); } else if (e.tagName() == "modified") { appendItem(generalGroup, "ModificationDate", QDateTime::fromString( e.text(), "yyyy-MM-ddThh:mm:ssZ" ) ); } else if (e.tagName() == "keywords") { appendItem(generalGroup, "Keywords", e.text() ); } else { kDebug(7155) << "unhandled metadata tag: " << e.tagName() << " : " << e.text(); } } n = n.nextSibling(); } delete corepropsDevice; } if ( ! thumbFileName.isEmpty() ) { const KZipFileEntry* thumbFile = static_cast<const KZipFileEntry *>(xpsArchive->directory()->entry(thumbFileName)); QImage img; img.loadFromData(thumbFile->data()); appendItem( generalGroup, "Thumbnail", img); appendItem( generalGroup, "ThumbnailDimensions", QSize( img.width(), img.height() ) ); } appendItem(generalGroup, "Documents", numDocuments); delete xpsArchive; return true; }