[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kdepim-addons] plugins/messageviewer/bodypartformatter/semantic: Let ExtractorEngine pick the extra
From:       Volker Krause <null () kde ! org>
Date:       2018-09-23 17:44:14
Message-ID: E1g48QY-00032M-PE () code ! kde ! org
[Download RAW message or body]

Git commit f57f6bf4e13a9ebea944c9a281f5365997d6b06d by Volker Krause.
Committed on 23/09/2018 at 16:58.
Pushed by vkrause into branch 'master'.

Let ExtractorEngine pick the extractors

This simplifies the code here, and it enables the extractor selection
based on content found by the generic extractors.

M  +7    -28   plugins/messageviewer/bodypartformatter/semantic/semanticprocessor.cpp
M  +0    -6    plugins/messageviewer/bodypartformatter/semantic/semanticprocessor.h

https://commits.kde.org/kdepim-addons/f57f6bf4e13a9ebea944c9a281f5365997d6b06d

diff --git a/plugins/messageviewer/bodypartformatter/semantic/semanticprocessor.cpp \
b/plugins/messageviewer/bodypartformatter/semantic/semanticprocessor.cpp index \
                bcb00211..59dc8b36 100644
--- a/plugins/messageviewer/bodypartformatter/semantic/semanticprocessor.cpp
+++ b/plugins/messageviewer/bodypartformatter/semantic/semanticprocessor.cpp
@@ -36,8 +36,6 @@
 
 using namespace KItinerary;
 
-std::weak_ptr<ExtractorRepository> SemanticProcessor::s_repository;
-
 static bool isPkPassContent(KMime::Content *content)
 {
     const auto ct = content->contentType();
@@ -70,15 +68,7 @@ static bool isCalendarContent(KMime::Content *content)
     return cd && cd->filename().endsWith(QLatin1String(".ics"));
 }
 
-SemanticProcessor::SemanticProcessor()
-{
-    m_repository = s_repository.lock();
-    if (!m_repository) {
-        m_repository.reset(new ExtractorRepository);
-        s_repository = m_repository;
-    }
-}
-
+SemanticProcessor::SemanticProcessor() = default;
 SemanticProcessor::~SemanticProcessor() = default;
 
 MimeTreeParser::MessagePart::Ptr \
SemanticProcessor::process(MimeTreeParser::Interface::BodyPart &part) const @@ \
-115,27 +105,16 @@ MimeTreeParser::MessagePart::Ptr \
SemanticProcessor::process(MimeTreeParser::Inte  
     std::vector<const Extractor *> extractors;
     std::unique_ptr<KPkPass::Pass> pass;
-    if (isPkPassContent(part.content())) {
-        pass.reset(KPkPass::Pass::fromData(part.content()->decodedContent()));
-        extractors = m_repository->extractorsForPass(pass.get());
-    } else {
-        extractors = m_repository->extractorsForMessage(part.content());
-    }
-    if (extractors.empty()) {
-        qCDebug(SEMANTIC_LOG) << "Found no suitable extractors.";
-        return {};
-    }
-
     std::unique_ptr<PdfDocument> pdfDoc;
     std::unique_ptr<HtmlDocument> htmlDoc;
     KCalCore::Calendar::Ptr calendar;
 
     ExtractorEngine engine;
-    engine.setSenderDate(senderDateTime);
-    engine.setExtractors(std::move(extractors));
-    engine.setPass(pass.get());
-
-    if (part.content()->contentType()->isHTMLText()) {
+    engine.setContext(part.content());
+    if (isPkPassContent(part.content())) {
+        pass.reset(KPkPass::Pass::fromData(part.content()->decodedContent()));
+        engine.setPass(pass.get());
+    } else if (part.content()->contentType()->isHTMLText()) {
         htmlDoc.reset(HtmlDocument::fromData(part.content()->decodedContent()));
         engine.setHtmlDocument(htmlDoc.get());
     } else if (part.content()->contentType()->mimeType() == "application/pdf") {
@@ -149,7 +128,7 @@ MimeTreeParser::MessagePart::Ptr \
SemanticProcessor::process(MimeTreeParser::Inte  }
     } else if (part.content()->contentType()->isPlainText()) {
         engine.setText(part.content()->decodedText());
-    } else if (!pass) {
+    } else {
         // we have extractors but this isn't a mimetype we understand
         return {};
     }
diff --git a/plugins/messageviewer/bodypartformatter/semantic/semanticprocessor.h \
b/plugins/messageviewer/bodypartformatter/semantic/semanticprocessor.h index \
                40201ff2..f7a91554 100644
--- a/plugins/messageviewer/bodypartformatter/semantic/semanticprocessor.h
+++ b/plugins/messageviewer/bodypartformatter/semantic/semanticprocessor.h
@@ -24,8 +24,6 @@
 #include <MimeTreeParser/BodyPartFormatter>
 #include <MimeTreeParser/MessagePart>
 
-#include <KItinerary/ExtractorRepository>
-
 #include <memory>
 
 /** Processor plugin for MimeTreeParser. */
@@ -36,10 +34,6 @@ public:
     ~SemanticProcessor() override;
 
     MimeTreeParser::MessagePart::Ptr process(MimeTreeParser::Interface::BodyPart \
                &part) const override;
-
-private:
-    std::shared_ptr<KItinerary::ExtractorRepository> m_repository;
-    static std::weak_ptr<KItinerary::ExtractorRepository> s_repository;
 };
 
 #endif // SEMANTICPROCESSOR_H


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic