| 2350 | } |
| 2351 | |
| 2352 | Document::OpenResult Document::openDocument(const QString &docFile, const QUrl &url, const QMimeType &_mime, const QString &password) |
| 2353 | { |
| 2354 | QMimeDatabase db; |
| 2355 | QMimeType mime = _mime; |
| 2356 | QByteArray filedata; |
| 2357 | int fd = -1; |
| 2358 | if (url.scheme() == QLatin1String("fd")) { |
| 2359 | bool ok; |
| 2360 | fd = QStringView {url.path()}.mid(1).toInt(&ok); |
| 2361 | if (!ok) { |
| 2362 | return OpenError; |
| 2363 | } |
| 2364 | } else if (url.fileName() == QLatin1String("-")) { |
| 2365 | fd = 0; |
| 2366 | } |
| 2367 | bool triedMimeFromFileContent = false; |
| 2368 | if (fd < 0) { |
| 2369 | if (!mime.isValid()) { |
| 2370 | return OpenError; |
| 2371 | } |
| 2372 | |
| 2373 | d->m_url = url; |
| 2374 | d->m_docFileName = docFile; |
| 2375 | |
| 2376 | if (!d->updateMetadataXmlNameAndDocSize()) { |
| 2377 | return OpenError; |
| 2378 | } |
| 2379 | } else { |
| 2380 | QFile qstdin; |
| 2381 | const bool ret = qstdin.open(fd, QIODevice::ReadOnly, QFileDevice::AutoCloseHandle); |
| 2382 | if (!ret) { |
| 2383 | qWarning() << "failed to read" << url << filedata; |
| 2384 | return OpenError; |
| 2385 | } |
| 2386 | |
| 2387 | filedata = qstdin.readAll(); |
| 2388 | mime = db.mimeTypeForData(filedata); |
| 2389 | if (!mime.isValid() || mime.isDefault()) { |
| 2390 | return OpenError; |
| 2391 | } |
| 2392 | d->m_docSize = filedata.size(); |
| 2393 | triedMimeFromFileContent = true; |
| 2394 | } |
| 2395 | |
| 2396 | const bool fromFileDescriptor = fd >= 0; |
| 2397 | |
| 2398 | // 0. load Generator |
| 2399 | // request only valid non-disabled plugins suitable for the mimetype |
| 2400 | KPluginMetaData offer = DocumentPrivate::generatorForMimeType(mime, d->m_widget); |
| 2401 | if (!offer.isValid() && !triedMimeFromFileContent) { |
| 2402 | QMimeType newmime = db.mimeTypeForFile(docFile, QMimeDatabase::MatchContent); |
| 2403 | triedMimeFromFileContent = true; |
| 2404 | if (newmime != mime) { |
| 2405 | mime = newmime; |
| 2406 | offer = DocumentPrivate::generatorForMimeType(mime, d->m_widget); |
| 2407 | } |
| 2408 | if (!offer.isValid()) { |
| 2409 | // There's still no offers, do a final mime search based on the filename |
nothing calls this directly
no test coverage detected