Changeset View
Changeset View
Standalone View
Standalone View
core/document.cpp
Show First 20 Lines • Show All 2357 Lines • ▼ Show 20 Line(s) | 2292 | { | |||
---|---|---|---|---|---|
2358 | return offers.at(hRank); | 2358 | return offers.at(hRank); | ||
2359 | } | 2359 | } | ||
2360 | 2360 | | |||
2361 | Document::OpenResult Document::openDocument(const QString & docFile, const QUrl &url, const QMimeType &_mime, const QString & password ) | 2361 | Document::OpenResult Document::openDocument(const QString & docFile, const QUrl &url, const QMimeType &_mime, const QString & password ) | ||
2362 | { | 2362 | { | ||
2363 | QMimeDatabase db; | 2363 | QMimeDatabase db; | ||
2364 | QMimeType mime = _mime; | 2364 | QMimeType mime = _mime; | ||
2365 | QByteArray filedata; | 2365 | QByteArray filedata; | ||
2366 | bool isstdin = url.fileName() == QLatin1String( "-" ); | 2366 | int fd = -1; | ||
2367 | if (url.scheme() == QLatin1String("fd")) | ||||
2368 | { | ||||
2369 | bool ok; | ||||
2370 | fd = url.path().mid(1).toInt(&ok); | ||||
2371 | if (!ok) | ||||
2372 | { | ||||
2373 | return OpenError; | ||||
2374 | } | ||||
2375 | } | ||||
2376 | else if (url.fileName() == QLatin1String( "-" )) | ||||
2377 | { | ||||
2378 | fd = 0; | ||||
2379 | } | ||||
2367 | bool triedMimeFromFileContent = false; | 2380 | bool triedMimeFromFileContent = false; | ||
2368 | if ( !isstdin ) | 2381 | if ( fd < 0 ) | ||
2369 | { | 2382 | { | ||
2370 | if ( !mime.isValid() ) | 2383 | if ( !mime.isValid() ) | ||
2371 | return OpenError; | 2384 | return OpenError; | ||
2372 | 2385 | | |||
2373 | d->m_url = url; | 2386 | d->m_url = url; | ||
2374 | d->m_docFileName = docFile; | 2387 | d->m_docFileName = docFile; | ||
2375 | 2388 | | |||
2376 | if ( !d->updateMetadataXmlNameAndDocSize() ) | 2389 | if ( !d->updateMetadataXmlNameAndDocSize() ) | ||
2377 | return OpenError; | 2390 | return OpenError; | ||
2378 | } | 2391 | } | ||
2379 | else | 2392 | else | ||
2380 | { | 2393 | { | ||
2381 | QFile qstdin; | 2394 | QFile qstdin; | ||
2382 | qstdin.open( stdin, QIODevice::ReadOnly ); | 2395 | const bool ret = qstdin.open( fd, QIODevice::ReadOnly, QFileDevice::AutoCloseHandle ); | ||
2396 | if (!ret) { | ||||
2397 | qWarning() << "failed to read" << url << filedata; | ||||
2398 | return OpenError; | ||||
2399 | } | ||||
2400 | | ||||
2383 | filedata = qstdin.readAll(); | 2401 | filedata = qstdin.readAll(); | ||
2384 | mime = db.mimeTypeForData( filedata ); | 2402 | mime = db.mimeTypeForData( filedata ); | ||
2385 | if ( !mime.isValid() || mime.isDefault() ) | 2403 | if ( !mime.isValid() || mime.isDefault() ) | ||
2386 | return OpenError; | 2404 | return OpenError; | ||
2387 | d->m_docSize = filedata.size(); | 2405 | d->m_docSize = filedata.size(); | ||
2388 | triedMimeFromFileContent = true; | 2406 | triedMimeFromFileContent = true; | ||
2389 | } | 2407 | } | ||
2390 | 2408 | | |||
2409 | const bool fromFileDescriptor = fd >= 0; | ||||
2410 | | ||||
2391 | // 0. load Generator | 2411 | // 0. load Generator | ||
2392 | // request only valid non-disabled plugins suitable for the mimetype | 2412 | // request only valid non-disabled plugins suitable for the mimetype | ||
2393 | KPluginMetaData offer = DocumentPrivate::generatorForMimeType(mime, d->m_widget); | 2413 | KPluginMetaData offer = DocumentPrivate::generatorForMimeType(mime, d->m_widget); | ||
2394 | if ( !offer.isValid() && !triedMimeFromFileContent ) | 2414 | if ( !offer.isValid() && !triedMimeFromFileContent ) | ||
2395 | { | 2415 | { | ||
2396 | QMimeType newmime = db.mimeTypeForFile(docFile, QMimeDatabase::MatchExtension); | 2416 | QMimeType newmime = db.mimeTypeForFile(docFile, QMimeDatabase::MatchExtension); | ||
2397 | triedMimeFromFileContent = true; | 2417 | triedMimeFromFileContent = true; | ||
2398 | if ( newmime != mime ) | 2418 | if ( newmime != mime ) | ||
Show All 18 Lines | |||||
2417 | if (!offer.isValid()) | 2437 | if (!offer.isValid()) | ||
2418 | { | 2438 | { | ||
2419 | emit error( i18n( "Can not find a plugin which is able to handle the document being passed." ), -1 ); | 2439 | emit error( i18n( "Can not find a plugin which is able to handle the document being passed." ), -1 ); | ||
2420 | qCWarning(OkularCoreDebug).nospace() << "No plugin for mimetype '" << mime.name() << "'."; | 2440 | qCWarning(OkularCoreDebug).nospace() << "No plugin for mimetype '" << mime.name() << "'."; | ||
2421 | return OpenError; | 2441 | return OpenError; | ||
2422 | } | 2442 | } | ||
2423 | 2443 | | |||
2424 | // 1. load Document | 2444 | // 1. load Document | ||
2425 | OpenResult openResult = d->openDocumentInternal( offer, isstdin, docFile, filedata, password ); | 2445 | OpenResult openResult = d->openDocumentInternal( offer, fromFileDescriptor, docFile, filedata, password ); | ||
2426 | if ( openResult == OpenError ) | 2446 | if ( openResult == OpenError ) | ||
2427 | { | 2447 | { | ||
2428 | QVector<KPluginMetaData> triedOffers; | 2448 | QVector<KPluginMetaData> triedOffers; | ||
2429 | triedOffers << offer; | 2449 | triedOffers << offer; | ||
2430 | offer = DocumentPrivate::generatorForMimeType(mime, d->m_widget, triedOffers); | 2450 | offer = DocumentPrivate::generatorForMimeType(mime, d->m_widget, triedOffers); | ||
2431 | 2451 | | |||
2432 | while ( offer.isValid() ) | 2452 | while ( offer.isValid() ) | ||
2433 | { | 2453 | { | ||
2434 | openResult = d->openDocumentInternal( offer, isstdin, docFile, filedata, password ); | 2454 | openResult = d->openDocumentInternal( offer, fromFileDescriptor, docFile, filedata, password ); | ||
2435 | 2455 | | |||
2436 | if ( openResult == OpenError ) | 2456 | if ( openResult == OpenError ) | ||
2437 | { | 2457 | { | ||
2438 | triedOffers << offer; | 2458 | triedOffers << offer; | ||
2439 | offer = DocumentPrivate::generatorForMimeType(mime, d->m_widget, triedOffers); | 2459 | offer = DocumentPrivate::generatorForMimeType(mime, d->m_widget, triedOffers); | ||
2440 | } | 2460 | } | ||
2441 | else break; | 2461 | else break; | ||
2442 | } | 2462 | } | ||
2443 | 2463 | | |||
2444 | if (openResult == OpenError && !triedMimeFromFileContent ) | 2464 | if (openResult == OpenError && !triedMimeFromFileContent ) | ||
2445 | { | 2465 | { | ||
2446 | QMimeType newmime = db.mimeTypeForFile(docFile, QMimeDatabase::MatchExtension); | 2466 | QMimeType newmime = db.mimeTypeForFile(docFile, QMimeDatabase::MatchExtension); | ||
2447 | triedMimeFromFileContent = true; | 2467 | triedMimeFromFileContent = true; | ||
2448 | if ( newmime != mime ) | 2468 | if ( newmime != mime ) | ||
2449 | { | 2469 | { | ||
2450 | mime = newmime; | 2470 | mime = newmime; | ||
2451 | offer = DocumentPrivate::generatorForMimeType(mime, d->m_widget, triedOffers); | 2471 | offer = DocumentPrivate::generatorForMimeType(mime, d->m_widget, triedOffers); | ||
2452 | while ( offer.isValid() ) | 2472 | while ( offer.isValid() ) | ||
2453 | { | 2473 | { | ||
2454 | openResult = d->openDocumentInternal( offer, isstdin, docFile, filedata, password ); | 2474 | openResult = d->openDocumentInternal( offer, fromFileDescriptor, docFile, filedata, password ); | ||
2455 | 2475 | | |||
2456 | if ( openResult == OpenError ) | 2476 | if ( openResult == OpenError ) | ||
2457 | { | 2477 | { | ||
2458 | triedOffers << offer; | 2478 | triedOffers << offer; | ||
2459 | offer = DocumentPrivate::generatorForMimeType(mime, d->m_widget, triedOffers); | 2479 | offer = DocumentPrivate::generatorForMimeType(mime, d->m_widget, triedOffers); | ||
2460 | } | 2480 | } | ||
2461 | else break; | 2481 | else break; | ||
2462 | } | 2482 | } | ||
▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Line(s) | |||||
2548 | const DocumentViewport nextViewport = d->nextDocumentViewport(); | 2568 | const DocumentViewport nextViewport = d->nextDocumentViewport(); | ||
2549 | if ( nextViewport.isValid() ) | 2569 | if ( nextViewport.isValid() ) | ||
2550 | { | 2570 | { | ||
2551 | setViewport( nextViewport ); | 2571 | setViewport( nextViewport ); | ||
2552 | d->m_nextDocumentViewport = DocumentViewport(); | 2572 | d->m_nextDocumentViewport = DocumentViewport(); | ||
2553 | d->m_nextDocumentDestination = QString(); | 2573 | d->m_nextDocumentDestination = QString(); | ||
2554 | } | 2574 | } | ||
2555 | 2575 | | |||
2556 | AudioPlayer::instance()->d->m_currentDocument = isstdin ? QUrl() : d->m_url; | 2576 | AudioPlayer::instance()->d->m_currentDocument = fromFileDescriptor ? QUrl() : d->m_url; | ||
2557 | 2577 | | |||
2558 | const QStringList docScripts = d->m_generator->metaData( QStringLiteral("DocumentScripts"), QStringLiteral ( "JavaScript" ) ).toStringList(); | 2578 | const QStringList docScripts = d->m_generator->metaData( QStringLiteral("DocumentScripts"), QStringLiteral ( "JavaScript" ) ).toStringList(); | ||
2559 | if ( !docScripts.isEmpty() ) | 2579 | if ( !docScripts.isEmpty() ) | ||
2560 | { | 2580 | { | ||
2561 | d->m_scripter = new Scripter( d ); | 2581 | d->m_scripter = new Scripter( d ); | ||
2562 | Q_FOREACH ( const QString &docscript, docScripts ) | 2582 | Q_FOREACH ( const QString &docscript, docScripts ) | ||
2563 | { | 2583 | { | ||
2564 | d->m_scripter->execute( JavaScript, docscript ); | 2584 | d->m_scripter->execute( JavaScript, docscript ); | ||
▲ Show 20 Lines • Show All 3029 Lines • Show Last 20 Lines |