Changeset View
Changeset View
Standalone View
Standalone View
mimetreeparser/src/messagepart.cpp
Show First 20 Lines • Show All 458 Lines • ▼ Show 20 Line(s) | 458 | { | |||
---|---|---|---|---|---|
459 | return mIsImage; | 459 | return mIsImage; | ||
460 | } | 460 | } | ||
461 | 461 | | |||
462 | void AttachmentMessagePart::setIsImage(bool image) | 462 | void AttachmentMessagePart::setIsImage(bool image) | ||
463 | { | 463 | { | ||
464 | mIsImage = image; | 464 | mIsImage = image; | ||
465 | } | 465 | } | ||
466 | 466 | | |||
467 | IconType AttachmentMessagePart::asIcon() const | | |||
468 | { | | |||
469 | const AttachmentStrategy *const as = mOtp->attachmentStrategy(); | | |||
470 | const bool defaultHidden(as && as->defaultDisplay(content()) == AttachmentStrategy::None); | | |||
471 | const bool showOnlyOneMimePart(mOtp->showOnlyOneMimePart()); | | |||
472 | auto preferredMode = source()->preferredMode(); | | |||
473 | bool isHtmlPreferred = (preferredMode == Util::Html) || (preferredMode == Util::MultipartHtml); | | |||
474 | | ||||
475 | QByteArray mediaType("text"); | | |||
476 | if (content()->contentType(false) && !content()->contentType()->mediaType().isEmpty() | | |||
477 | && !content()->contentType()->subType().isEmpty()) { | | |||
478 | mediaType = content()->contentType()->mediaType(); | | |||
479 | } | | |||
480 | const bool isTextPart = (mediaType == QByteArrayLiteral("text")); | | |||
481 | | ||||
482 | bool defaultAsIcon = true; | | |||
483 | if (!neverDisplayInline()) { | | |||
484 | if (as) { | | |||
485 | defaultAsIcon = as->defaultDisplay(content()) == AttachmentStrategy::AsIcon; | | |||
486 | } | | |||
487 | } | | |||
488 | if (isImage() && showOnlyOneMimePart && !neverDisplayInline()) { | | |||
489 | defaultAsIcon = false; | | |||
490 | } | | |||
491 | | ||||
492 | // neither image nor text -> show as icon | | |||
493 | if (!isImage() && !isTextPart) { | | |||
494 | defaultAsIcon = true; | | |||
495 | } | | |||
496 | | ||||
497 | if (isTextPart) { | | |||
498 | if (as && as->defaultDisplay(content()) != AttachmentStrategy::Inline) { | | |||
499 | return MimeTreeParser::IconExternal; | | |||
500 | } | | |||
501 | return MimeTreeParser::NoIcon; | | |||
502 | } else { | | |||
503 | if (isImage() && isHtmlPreferred | | |||
504 | && content()->parent() && content()->parent()->contentType()->subType() == "related") { | | |||
505 | return MimeTreeParser::IconInline; | | |||
506 | } | | |||
507 | | ||||
508 | if (defaultHidden && !showOnlyOneMimePart && content()->parent()) { | | |||
509 | return MimeTreeParser::IconInline; | | |||
510 | } | | |||
511 | | ||||
512 | if (defaultAsIcon) { | | |||
513 | return MimeTreeParser::IconExternal; | | |||
514 | } else if (isImage()) { | | |||
515 | return MimeTreeParser::IconInline; | | |||
516 | } else { | | |||
517 | return MimeTreeParser::NoIcon; | | |||
518 | } | | |||
519 | } | | |||
520 | } | | |||
521 | | ||||
522 | bool AttachmentMessagePart::isHidden() const | | |||
523 | { | | |||
524 | if (mOtp->showOnlyOneMimePart()) { | | |||
525 | return false; // never hide when only showing one part, otherwise you'll see nothing | | |||
526 | } | | |||
527 | const AttachmentStrategy *const as = mOtp->attachmentStrategy(); | | |||
528 | const bool defaultHidden(as && as->defaultDisplay(content()) == AttachmentStrategy::None); | | |||
529 | auto preferredMode = source()->preferredMode(); | | |||
530 | bool isHtmlPreferred = (preferredMode == Util::Html) || (preferredMode == Util::MultipartHtml); | | |||
531 | | ||||
532 | QByteArray mediaType("text"); | | |||
533 | if (content()->contentType(false) && !content()->contentType()->mediaType().isEmpty() | | |||
534 | && !content()->contentType()->subType().isEmpty()) { | | |||
535 | mediaType = content()->contentType()->mediaType(); | | |||
536 | } | | |||
537 | const bool isTextPart = (mediaType == QByteArrayLiteral("text")); | | |||
538 | | ||||
539 | bool defaultAsIcon = true; | | |||
540 | if (!neverDisplayInline()) { | | |||
541 | if (as) { | | |||
542 | defaultAsIcon = as->defaultDisplay(content()) == AttachmentStrategy::AsIcon; | | |||
543 | } | | |||
544 | } | | |||
545 | | ||||
546 | // neither image nor text -> show as icon | | |||
547 | if (!isImage() && !isTextPart) { | | |||
548 | defaultAsIcon = true; | | |||
549 | } | | |||
550 | | ||||
551 | bool hidden(false); | | |||
552 | if (isTextPart) { | | |||
553 | hidden = defaultHidden; | | |||
554 | } else { | | |||
555 | if (isImage() && isHtmlPreferred | | |||
556 | && content()->parent() && content()->parent()->contentType()->subType() == "related") { | | |||
557 | hidden = true; | | |||
558 | } else { | | |||
559 | hidden = defaultHidden && content()->parent(); | | |||
560 | hidden |= defaultAsIcon && defaultHidden; | | |||
561 | } | | |||
562 | } | | |||
563 | mOtp->nodeHelper()->setNodeDisplayedHidden(content(), hidden); | | |||
564 | return hidden; | | |||
565 | } | | |||
566 | | ||||
567 | //-----HtmlMessageBlock---------------------- | 467 | //-----HtmlMessageBlock---------------------- | ||
568 | 468 | | |||
569 | HtmlMessagePart::HtmlMessagePart(ObjectTreeParser *otp, KMime::Content *node, Interface::ObjectTreeSource *source) | 469 | HtmlMessagePart::HtmlMessagePart(ObjectTreeParser *otp, KMime::Content *node, Interface::ObjectTreeSource *source) | ||
570 | : MessagePart(otp, QString()) | 470 | : MessagePart(otp, QString()) | ||
571 | , mSource(source) | 471 | , mSource(source) | ||
572 | { | 472 | { | ||
573 | if (!node) { | 473 | if (!node) { | ||
574 | qCWarning(MIMETREEPARSER_LOG) << "not a valid node"; | 474 | qCWarning(MIMETREEPARSER_LOG) << "not a valid node"; | ||
▲ Show 20 Lines • Show All 849 Lines • Show Last 20 Lines |