Changeset View
Changeset View
Standalone View
Standalone View
messageviewer/src/viewer/objecttreeparser.cpp
Show First 20 Lines • Show All 327 Lines • ▼ Show 20 Line(s) | 321 | for (; node; node = MessageCore::NodeHelper::nextSibling(node)) { | |||
---|---|---|---|---|---|
328 | QByteArray mediaType("text"); | 328 | QByteArray mediaType("text"); | ||
329 | QByteArray subType("plain"); | 329 | QByteArray subType("plain"); | ||
330 | if (node->contentType(false) && !node->contentType()->mediaType().isEmpty() && | 330 | if (node->contentType(false) && !node->contentType()->mediaType().isEmpty() && | ||
331 | !node->contentType()->subType().isEmpty()) { | 331 | !node->contentType()->subType().isEmpty()) { | ||
332 | mediaType = node->contentType()->mediaType(); | 332 | mediaType = node->contentType()->mediaType(); | ||
333 | subType = node->contentType()->subType(); | 333 | subType = node->contentType()->subType(); | ||
334 | } | 334 | } | ||
335 | 335 | | |||
336 | // First, try if an external plugin can handle this MIME part | 336 | bool bRendered = false; | ||
337 | if (const Interface::BodyPartFormatter * formatter | 337 | const auto sub = BodyPartFormatterFactory::instance()->subtypeRegistry(mediaType); | ||
338 | = BodyPartFormatterFactory::instance()->createFor(mediaType, subType)) { | 338 | const auto end = sub.end(); | ||
339 | auto it = sub.find(subType); | ||||
340 | if (it == end) { | ||||
341 | it = sub.find("*"); | ||||
342 | } | ||||
343 | for (; it != end; ++it) { | ||||
knauss: i cant't return sub.find(subtype), because than i have no end element, with i can test the end. | |||||
344 | const auto formatter = (*it).second; | ||||
knauss: can this break? if i return a empty iterator? | |||||
345 | if (!formatter) { | ||||
346 | continue; | ||||
347 | } | ||||
339 | PartNodeBodyPart part(this, &processResult, mTopLevelContent, node, mNodeHelper, codecFor(node)); | 348 | PartNodeBodyPart part(this, &processResult, mTopLevelContent, node, mNodeHelper, codecFor(node)); | ||
340 | // Set the default display strategy for this body part relying on the | 349 | // Set the default display strategy for this body part relying on the | ||
341 | // identity of Interface::BodyPart::Display and AttachmentStrategy::Display | 350 | // identity of Interface::BodyPart::Display and AttachmentStrategy::Display | ||
342 | part.setDefaultDisplay((Interface::BodyPart::Display) attachmentStrategy()->defaultDisplay(node)); | 351 | part.setDefaultDisplay((Interface::BodyPart::Display) attachmentStrategy()->defaultDisplay(node)); | ||
343 | 352 | | |||
344 | mNodeHelper->setNodeDisplayedEmbedded(node, true); | 353 | mNodeHelper->setNodeDisplayedEmbedded(node, true); | ||
345 | 354 | | |||
355 | const auto result = formatter->process(part); | ||||
356 | if (!result) { | ||||
357 | continue; | ||||
358 | } | ||||
359 | | ||||
360 | if (const auto mp = dynamic_cast<MessageViewer::MessagePart*>(result.data())) { | ||||
346 | AttachmentMarkBlock block(htmlWriter(), node); | 361 | AttachmentMarkBlock block(htmlWriter(), node); | ||
362 | mp->html(false); | ||||
knauss: need a better way to detect asIcon | |||||
363 | bRendered = true; | ||||
364 | break; | ||||
365 | } else if (dynamic_cast<MessageViewer::Interface::MessagePart*>(result.data())) { | ||||
347 | QObject *asyncResultObserver = allowAsync() ? mSource->sourceObject() : 0; | 366 | QObject *asyncResultObserver = allowAsync() ? mSource->sourceObject() : 0; | ||
348 | const Interface::BodyPartFormatter::Result result = formatter->format(&part, htmlWriter(), asyncResultObserver); | 367 | const auto r = formatter->format(&part, htmlWriter(), asyncResultObserver); | ||
349 | switch (result) { | 368 | if (r == Interface::BodyPartFormatter::AsIcon) { | ||
350 | case Interface::BodyPartFormatter::AsIcon: | 369 | //qDebug() << node << "asIcon"; | ||
370 | AttachmentMarkBlock block(htmlWriter(), node); | ||||
351 | processResult.setNeverDisplayInline(true); | 371 | processResult.setNeverDisplayInline(true); | ||
352 | mNodeHelper->setNodeDisplayedEmbedded(node, false); | 372 | mNodeHelper->setNodeDisplayedEmbedded(node, false); | ||
353 | // fall through: | | |||
354 | case Interface::BodyPartFormatter::Failed: | | |||
355 | { | | |||
356 | const auto mp = defaultHandling(node, processResult); | 373 | const auto mp = defaultHandling(node, processResult); | ||
357 | if (mp) { | 374 | if (mp) { | ||
358 | mp->html(false); | 375 | mp->html(false); | ||
359 | } | 376 | } | ||
377 | bRendered = true; | ||||
360 | break; | 378 | break; | ||
361 | } | 379 | } | ||
362 | case Interface::BodyPartFormatter::Ok: | 380 | continue; | ||
363 | case Interface::BodyPartFormatter::NeedContent: | 381 | } else { | ||
364 | // FIXME: incomplete content handling | 382 | continue; | ||
365 | ; | 383 | } | ||
366 | } | 384 | } | ||
367 | 385 | | |||
368 | // No external plugin can handle the MIME part, handle it internally | 386 | if (!bRendered) { | ||
369 | } else { | | |||
370 | qCCritical(MESSAGEVIEWER_LOG) << "THIS SHOULD NO LONGER HAPPEN:" << mediaType << '/' << subType; | 387 | qCCritical(MESSAGEVIEWER_LOG) << "THIS SHOULD NO LONGER HAPPEN:" << mediaType << '/' << subType; | ||
371 | AttachmentMarkBlock block(htmlWriter(), node); | 388 | AttachmentMarkBlock block(htmlWriter(), node); | ||
372 | const auto mp = defaultHandling(node, processResult); | 389 | const auto mp = defaultHandling(node, processResult); | ||
373 | if (mp) { | 390 | if (mp) { | ||
374 | mp->html(false); | 391 | mp->html(false); | ||
375 | } | 392 | } | ||
376 | } | 393 | } | ||
377 | mNodeHelper->setNodeProcessed(node, false); | 394 | mNodeHelper->setNodeProcessed(node, false); | ||
▲ Show 20 Lines • Show All 2185 Lines • Show Last 20 Lines |
i cant't return sub.find(subtype), because than i have no end element, with i can test the end.