void JamendoService::DownloadDirectoryFinished() { QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender()); Q_ASSERT(reply); app_->task_manager()->SetTaskFinished(load_database_task_id_); load_database_task_id_ = 0; // TODO: Not leak reply. QtIOCompressor* gzip = new QtIOCompressor(reply); gzip->setStreamFormat(QtIOCompressor::GzipFormat); if (!gzip->open(QIODevice::ReadOnly)) { qLog(Warning) << "Jamendo library not in gzip format"; delete gzip; return; } load_database_task_id_ = app_->task_manager()->StartTask(tr("Parsing Jamendo catalogue")); QFuture<void> future = QtConcurrent::run(this, &JamendoService::ParseDirectory, gzip); QFutureWatcher<void>* watcher = new QFutureWatcher<void>(); watcher->setFuture(future); connect(watcher, SIGNAL(finished()), SLOT(ParseDirectoryFinished())); }
GaussianFchk::GaussianFchk(const QString &filename, BasisSet* basis) { // Open the file for reading and process it QFile* file = new QFile(filename); QtIOCompressor* compressedFile = 0; if (filename.endsWith(".gz")) { compressedFile = new QtIOCompressor(file); compressedFile->setStreamFormat(QtIOCompressor::GzipFormat); compressedFile->open(QIODevice::ReadOnly); m_in = compressedFile; } else { file->open(QIODevice::ReadOnly | QIODevice::Text); m_in = file; } qDebug() << "File" << filename << "opened."; // Process the formatted checkpoint and extract all the information we need while (!m_in->atEnd()) { processLine(); } // Now it should all be loaded load it into the basis set load(basis); if (compressedFile) delete compressedFile; else delete file; }
bool ScSlaInfoReader::readInfos(const QString& fileName) { bool isScribusDocument = false; bool readInfoSuccess = false; bool firstStartElement = true; QScopedPointer<QIODevice> file; resetFileInfos(); QFile aFile; if (fileName.right(2).toLower() == "gz") { aFile.setFileName(fileName); QtIOCompressor *compressor = new QtIOCompressor(&aFile); compressor->setStreamFormat(QtIOCompressor::GzipFormat); file.reset(compressor); } else file.reset( new QFile(fileName) ); if (file.isNull() || !file->open(QIODevice::ReadOnly)) return false; QByteArray bytes = file->read(512); if (!bytes.contains("SCRIBUS") && !bytes.contains("SCRIBUSUTF8") && !bytes.contains("SCRIBUSUTF8NEW")) { file->close(); return false; } file->reset(); QXmlStreamReader reader(file.data()); while (!reader.atEnd() && !reader.hasError()) { QXmlStreamReader::TokenType ttype = reader.readNext(); if (reader.hasError()) break; if (ttype == QXmlStreamReader::StartElement) { QStringRef nodeName = reader.name(); if (firstStartElement) { if (nodeName == "SCRIBUS" || nodeName == "SCRIBUSUTF8" || nodeName == "SCRIBUSUTF8NEW") { QXmlStreamAttributes attrs = reader.attributes(); m_format = attrs.value(QLatin1String("Version")).toString(); isScribusDocument = true; } else { isScribusDocument = false; break; } } else if (nodeName == "DOCUMENT") { QXmlStreamAttributes attrs = reader.attributes(); m_title = attrs.value(QLatin1String("TITLE")).toString(); m_author = attrs.value(QLatin1String("AUTHOR")).toString(); readInfoSuccess = true; break; } firstStartElement = false; } } isScribusDocument &= !reader.hasError(); file->close(); return (isScribusDocument && readInfoSuccess); }